From 0dde77009e5a86f9aef5e90db8b3d4c7cb7aaf33 Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Wed, 5 Feb 2025 12:50:02 -0800 Subject: [PATCH] re-enabled quad-backticks, but allow triple-backticks as fences when searching for filenames #2879 --- aider/coders/base_coder.py | 2 +- aider/coders/editblock_coder.py | 7 +++++-- aider/main.py | 3 +++ 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/aider/coders/base_coder.py b/aider/coders/base_coder.py index b96e36510..c8afd69a1 100755 --- a/aider/coders/base_coder.py +++ b/aider/coders/base_coder.py @@ -60,7 +60,7 @@ def wrap_fence(name): all_fences = [ ("`" * 3, "`" * 3), - # ("`" * 4, "`" * 4), # LLMs ignore and revert to triple-backtick, causing #2879 + ("`" * 4, "`" * 4), # LLMs ignore and revert to triple-backtick, causing #2879 wrap_fence("source"), wrap_fence("code"), wrap_fence("pre"), diff --git a/aider/coders/editblock_coder.py b/aider/coders/editblock_coder.py index ecd94e47a..321a6a921 100644 --- a/aider/coders/editblock_coder.py +++ b/aider/coders/editblock_coder.py @@ -401,6 +401,9 @@ missing_filename_err = ( " {fence[0]}" ) +# Always be willing to treat triple-backticks as a fence when searching for filenames +triple_backticks = "`" * 3 + def strip_filename(filename, fence): filename = filename.strip() @@ -409,7 +412,7 @@ def strip_filename(filename, fence): return start_fence = fence[0] - if filename.startswith(start_fence): + if filename.startswith(start_fence) or filename.startswith(triple_backticks): return filename = filename.rstrip(":") @@ -546,7 +549,7 @@ def find_filename(lines, fence, valid_fnames): filenames.append(filename) # Only continue as long as we keep seeing fences - if not line.startswith(fence[0]): + if not line.startswith(fence[0]) and not line.startswith(triple_backticks): break if not filenames: diff --git a/aider/main.py b/aider/main.py index a4b5dd0b8..ead3c127f 100644 --- a/aider/main.py +++ b/aider/main.py @@ -991,6 +991,9 @@ def main(argv=None, input=None, output=None, force_git_root=None, return_coder=F analytics.event("exit", reason="Failed to read apply content") return coder.partial_response_content = content + # For testing #2879 + # from aider.coders.base_coder import all_fences + # coder.fence = all_fences[1] coder.apply_updates() analytics.event("exit", reason="Applied updates") return