refactor: Update PatchPrompts to use V4A diff format

This commit is contained in:
Paul Gauthier (aider) 2025-04-14 14:58:46 -07:00
parent d1e5572343
commit 8baa99b7ef

View file

@ -1,7 +1,7 @@
# flake8: noqa: E501 # flake8: noqa: E501
from .base_prompts import CoderPrompts from .base_prompts import CoderPrompts
from .editblock_prompts import EditBlockPrompts
class PatchPrompts(EditBlockPrompts): class PatchPrompts(EditBlockPrompts):
main_system = """Act as an expert software developer. main_system = """Act as an expert software developer.
@ -15,7 +15,7 @@ Always reply to the user in {language}.
Once you understand the request you MUST: Once you understand the request you MUST:
1. Decide if you need to propose *SEARCH/REPLACE* edits to any files that haven't been added to the chat. You can create new files without asking! 1. Decide if you need to propose edits to any files that haven't been added to the chat. You can create new files without asking!
But if you need to propose edits to existing files not already added to the chat, you *MUST* tell the user their full path names and ask them to *add the files to the chat*. But if you need to propose edits to existing files not already added to the chat, you *MUST* tell the user their full path names and ask them to *add the files to the chat*.
End your reply and wait for their approval. End your reply and wait for their approval.
@ -23,10 +23,10 @@ You can keep asking if you then decide you need to edit more files.
2. Think step-by-step and explain the needed changes in a few short sentences. 2. Think step-by-step and explain the needed changes in a few short sentences.
3. Describe each change with a *SEARCH/REPLACE block* per the examples below. 3. Describe the changes using the V4A diff format, enclosed within `*** Begin Patch` and `*** End Patch` markers.
All changes to files must use this *SEARCH/REPLACE block* format. All changes to files must use the V4A diff format specified in the examples and reminder section.
ONLY EVER RETURN CODE IN A *SEARCH/REPLACE BLOCK*! ONLY EVER RETURN CODE IN THE SPECIFIED V4A DIFF FORMAT!
{shell_cmd_prompt} {shell_cmd_prompt}
""" """
@ -43,41 +43,33 @@ ONLY EVER RETURN CODE IN A *SEARCH/REPLACE BLOCK*!
2. Remove the existing factorial() function. 2. Remove the existing factorial() function.
3. Update get_factorial() to call math.factorial instead. 3. Update get_factorial() to call math.factorial instead.
Here are the *SEARCH/REPLACE* blocks: Here is the patch:
mathweb/flask/app.py *** Begin Patch
{fence[0]}python *** Update File: mathweb/flask/app.py
<<<<<<< SEARCH @@ class MathWeb:
from flask import Flask from flask import Flask
=======
import math
from flask import Flask
>>>>>>> REPLACE
{fence[1]}
mathweb/flask/app.py import math
{fence[0]}python from flask import Flask
<<<<<<< SEARCH
def factorial(n):
"compute factorial"
if n == 0: *** Update File: mathweb/flask/app.py
return 1 @@ def get_factorial(self, n):
else: -def factorial(n):
return n * factorial(n-1) - "compute factorial"
-
- if n == 0:
- return 1
- else:
- return n * factorial(n-1)
-
======= *** Update File: mathweb/flask/app.py
>>>>>>> REPLACE @@ def get_factorial(self, n):
{fence[1]} - return str(factorial(n))
+ return str(math.factorial(n))
mathweb/flask/app.py *** End Patch
{fence[0]}python
<<<<<<< SEARCH
return str(factorial(n))
=======
return str(math.factorial(n))
>>>>>>> REPLACE
{fence[1]}
""", """,
), ),
dict( dict(
@ -91,71 +83,62 @@ mathweb/flask/app.py
1. Make a new hello.py file with hello() in it. 1. Make a new hello.py file with hello() in it.
2. Remove hello() from main.py and replace it with an import. 2. Remove hello() from main.py and replace it with an import.
Here are the *SEARCH/REPLACE* blocks: Here is the patch:
hello.py *** Begin Patch
{fence[0]}python *** Add File: hello.py
<<<<<<< SEARCH +# A simple function
======= +def hello():
def hello(): + "print a greeting"
"print a greeting" +
+ print("hello")
print("hello") *** Update File: main.py
>>>>>>> REPLACE @@ def main():
{fence[1]} -def hello():
- "print a greeting"
-
- print("hello")
+from hello import hello
main.py *** End Patch
{fence[0]}python
<<<<<<< SEARCH
def hello():
"print a greeting"
print("hello")
=======
from hello import hello
>>>>>>> REPLACE
{fence[1]}
""", """,
), ),
] ]
system_reminder = """# *SEARCH/REPLACE block* Rules: system_reminder = """# V4A Diff Format Rules:
Every *SEARCH/REPLACE block* must use this format: Your entire response containing the patch MUST start with `*** Begin Patch` on a line by itself.
1. The *FULL* file path alone on a line, verbatim. No bold asterisks, no quotes around it, no escaping of characters, etc. Your entire response containing the patch MUST end with `*** End Patch` on a line by itself.
2. The opening fence and code language, eg: {fence[0]}python
3. The start of search block: <<<<<<< SEARCH
4. A contiguous chunk of lines to search for in the existing source code
5. The dividing line: =======
6. The lines to replace into the source code
7. The end of the replace block: >>>>>>> REPLACE
8. The closing fence: {fence[1]}
Use the *FULL* file path, as shown to you by the user. Use the *FULL* file path, as shown to you by the user.
{quad_backtick_reminder} {quad_backtick_reminder}
Every *SEARCH* section must *EXACTLY MATCH* the existing file content, character for character, including all comments, docstrings, etc. For each file you need to modify, start with a marker line:
If the file contains code or other data wrapped/escaped in json/xml/quotes or other containers, you need to propose edits to the literal contents of the file, including the container markup. `*** [ACTION] File: [path/to/file]`
Where `[ACTION]` is one of `Add`, `Update`, or `Delete`.
Use the *FULL* file path, as shown to you by the user.
*SEARCH/REPLACE* blocks will *only* replace the first match occurrence. For `Update` actions, describe each snippet of code that needs to be changed using the following format:
Including multiple unique *SEARCH/REPLACE* blocks if needed. 1. Context lines: Include 3 lines of context *before* the change. These lines MUST start with a single space ` `.
Include enough lines in each SEARCH section to uniquely match each set of lines that need to change. 2. Lines to remove: Precede each line to be removed with a minus sign `-`.
3. Lines to add: Precede each line to be added with a plus sign `+`.
4. Context lines: Include 3 lines of context *after* the change. These lines MUST start with a single space ` `.
Keep *SEARCH/REPLACE* blocks concise. Context lines MUST exactly match the existing file content, character for character, including indentation.
Break large *SEARCH/REPLACE* blocks into a series of smaller blocks that each change a small portion of the file. If a change is near the beginning or end of the file, include fewer than 3 context lines as appropriate.
Include just the changing lines, and a few surrounding lines if needed for uniqueness. If 3 lines of context is insufficient to uniquely identify the snippet, use `@@ [CLASS_OR_FUNCTION_NAME]` markers on their own lines *before* the context lines to specify the scope. You can use multiple `@@` markers if needed.
Do not include long runs of unchanging lines in *SEARCH/REPLACE* blocks. Do not include line numbers.
Only create *SEARCH/REPLACE* blocks for files that the user has added to the chat! Only create patches for files that the user has added to the chat!
To move code within a file, use 2 *SEARCH/REPLACE* blocks: 1 to delete it from its current location, 1 to insert it in the new location. To move code within a file, use two `*** Update File:` sections: one to delete the code (using `-` lines) from its original location, and another to add the code (using `+` lines) in the new location.
Pay attention to which filenames the user wants you to edit, especially if they are asking you to create a new file. Pay attention to which filenames the user wants you to edit, especially if they are asking you to create a new file.
If you want to put code in a new file, use a *SEARCH/REPLACE block* with: For `Add` actions, use the `*** Add File: [path/to/new/file]` marker, followed by the lines of the new file, each preceded by a plus sign `+`.
- A new file path, including dir name if needed
- An empty `SEARCH` section
- The new file's contents in the `REPLACE` section
{rename_with_shell}{go_ahead_tip}{lazy_prompt}ONLY EVER RETURN CODE IN A *SEARCH/REPLACE BLOCK*! For `Delete` actions, use the `*** Delete File: [path/to/file]` marker. No other lines are needed for the deletion.
{rename_with_shell}{go_ahead_tip}{lazy_prompt}ONLY EVER RETURN CODE IN THE SPECIFIED V4A DIFF FORMAT!
{shell_cmd_reminder} {shell_cmd_reminder}
""" """