mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-31 17:55:01 +00:00
ORIGINAL/UPDATED -> HEAD/updated
This commit is contained in:
parent
fa2da0ef70
commit
fb80377d18
2 changed files with 22 additions and 24 deletions
|
@ -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!
|
||||
|
|
|
@ -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"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue