From fb80377d18af5c535e46d2b635cd027047f208ed Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Wed, 9 Aug 2023 16:16:43 -0300 Subject: [PATCH] ORIGINAL/UPDATED -> HEAD/updated --- aider/coders/editblock_coder.py | 30 ++++++++++++++---------------- aider/coders/editblock_prompts.py | 16 ++++++++-------- 2 files changed, 22 insertions(+), 24 deletions(-) diff --git a/aider/coders/editblock_coder.py b/aider/coders/editblock_coder.py index 4d6bdfea2..622b17043 100644 --- a/aider/coders/editblock_coder.py +++ b/aider/coders/editblock_coder.py @@ -32,10 +32,10 @@ class EditBlockCoder(Coder): continue raise ValueError(f"""InvalidEditBlock: edit failed! -{path} does not contain the *exact sequence* of ORIGINAL lines you specified. +{path} does not contain the *exact sequence* of HEAD lines you specified. Try again. DO NOT skip blank lines, comments, docstrings, etc! -The ORIGINAL block needs to be EXACTLY the same as the lines in {path} with nothing missing! +The HEAD block needs to be EXACTLY the same as the lines in {path} with nothing missing! {path} does not contain these {len(original.splitlines())} exact lines in a row: ``` @@ -304,11 +304,11 @@ def do_replace(fname, content, before_text, after_text, fence=None): return new_content -ORIGINAL = "<<<<<<< ORIGINAL" +HEAD = "<<<<<<< HEAD" DIVIDER = "=======" -UPDATED = ">>>>>>> UPDATED" +UPDATED = ">>>>>>> updated" -separators = "|".join([ORIGINAL, DIVIDER, UPDATED]) +separators = "|".join([HEAD, DIVIDER, UPDATED]) split_re = re.compile(r"^((?:" + separators + r")[ ]*\n)", re.MULTILINE | re.DOTALL) @@ -334,7 +334,7 @@ def find_original_update_blocks(content): processed.append(cur) raise ValueError(f"Unexpected {cur}") - if cur.strip() != ORIGINAL: + if cur.strip() != HEAD: processed.append(cur) continue @@ -348,14 +348,12 @@ def find_original_update_blocks(content): if current_filename: filename = current_filename else: - raise ValueError( - f"Bad/missing filename. It should go right above {ORIGINAL}" - ) + raise ValueError(f"Bad/missing filename. It should go right above {HEAD}") except IndexError: if current_filename: filename = current_filename else: - raise ValueError(f"Bad/missing filename. It should go right above {ORIGINAL}") + raise ValueError(f"Bad/missing filename. It should go right above {HEAD}") current_filename = filename @@ -365,7 +363,7 @@ def find_original_update_blocks(content): divider_marker = pieces.pop() processed.append(divider_marker) if divider_marker.strip() != DIVIDER: - raise ValueError(f"Expected {DIVIDER}") + raise ValueError(f"Expected `{DIVIDER}` not {divider_marker.strip()}") updated_text = pieces.pop() processed.append(updated_text) @@ -373,7 +371,7 @@ def find_original_update_blocks(content): updated_marker = pieces.pop() processed.append(updated_marker) if updated_marker.strip() != UPDATED: - raise ValueError(f"Expected {UPDATED}") + raise ValueError(f"Expected `{UPDATED}` not `{updated_marker.strip()}") yield filename, original_text, updated_text except ValueError as e: @@ -382,10 +380,10 @@ def find_original_update_blocks(content): raise ValueError(f"{processed}\n^^^ {err}") except IndexError: processed = "".join(processed) - raise ValueError(f"{processed}\n^^^ Incomplete ORIGINAL/UPDATED block.") + raise ValueError(f"{processed}\n^^^ Incomplete HEAD/updated block.") except Exception: processed = "".join(processed) - raise ValueError(f"{processed}\n^^^ Error parsing ORIGINAL/UPDATED block.") + raise ValueError(f"{processed}\n^^^ Error parsing HEAD/updated block.") if __name__ == "__main__": @@ -394,11 +392,11 @@ Here's the change: ```text foo.txt -<<<<<<< ORIGINAL +<<<<<<< HEAD Two ======= Tooooo ->>>>>>> UPDATED +>>>>>>> updated ``` Hope you like it! diff --git a/aider/coders/editblock_prompts.py b/aider/coders/editblock_prompts.py index 58f1fa73c..3874cf232 100644 --- a/aider/coders/editblock_prompts.py +++ b/aider/coders/editblock_prompts.py @@ -21,7 +21,7 @@ Once you understand the request you MUST: {fence[0]}python some/dir/example.py -<<<<<<< ORIGINAL +<<<<<<< HEAD # some comment # Func to multiply def mul(a,b) @@ -29,26 +29,26 @@ some/dir/example.py # updated comment # Function to add def add(a,b): ->>>>>>> UPDATED +>>>>>>> updated {fence[1]} -A program will parse the edit blocks you generate and replace the ORIGINAL lines with the UPDATED lines. +A program will parse the edit blocks you generate and replace the HEAD lines with the `updated` lines. So edit blocks must be precise and unambiguous! Every *edit block* must be fenced with {fence[0]}...{fence[1]} with the correct code language. Every *edit block* must start with the full path! *NEVER* propose edit blocks for *read-only* files. -The ORIGINAL section must be an *exact set of sequential lines* from the file! -NEVER SKIP LINES in the ORIGINAL section! +The HEAD section must be an *exact set of sequential lines* from the file! +NEVER SKIP LINES in the HEAD section! NEVER ELIDE LINES AND REPLACE THEM WITH A COMMENT! -NEVER OMIT ANY WHITESPACE in the ORIGINAL section! +NEVER OMIT ANY WHITESPACE in the HEAD section! Edits to different parts of a file each need their own *edit block*. If you want to put code in a new file, use an edit block with: - A new file path, including dir name if needed -- An empty ORIGINAL section -- The new file's contents in the UPDATED section +- An empty HEAD section +- The new file's contents in the `updated` section """ files_content_prefix = "These are the *read-write* files:\n"