From bdba0ca1c5af08099f0bc7983c19757b937c967e Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Thu, 1 May 2025 17:31:22 -0700 Subject: [PATCH] refactor: Move shell command prompts to shell.py, add final reminders --- aider/coders/base_prompts.py | 4 ++- aider/coders/editblock_fenced_prompts.py | 2 +- aider/coders/editblock_prompts.py | 45 ++++-------------------- aider/coders/editor_editblock_prompts.py | 2 +- aider/coders/editor_whole_prompts.py | 2 +- aider/coders/patch_prompts.py | 4 +-- aider/coders/udiff_prompts.py | 9 +++-- aider/coders/udiff_simple_prompts.py | 4 +-- aider/coders/wholefile_prompts.py | 4 +-- aider/watch.py | 1 + 10 files changed, 26 insertions(+), 51 deletions(-) diff --git a/aider/coders/base_prompts.py b/aider/coders/base_prompts.py index 464212031..36f991f1e 100644 --- a/aider/coders/base_prompts.py +++ b/aider/coders/base_prompts.py @@ -15,7 +15,9 @@ You always COMPLETELY IMPLEMENT the needed code! """ overeager_prompt = """Pay careful attention to the scope of the user's request. -Do what they ask, but no more.""" +Do what they ask, but no more. +Do not improve, comment, fix or modify unrelated parts of the code in any way! +""" example_messages = [] diff --git a/aider/coders/editblock_fenced_prompts.py b/aider/coders/editblock_fenced_prompts.py index 74f647f93..79fa179d9 100644 --- a/aider/coders/editblock_fenced_prompts.py +++ b/aider/coders/editblock_fenced_prompts.py @@ -137,7 +137,7 @@ To rename files which have been added to the chat, use shell commands at the end If the user just says something like "ok" or "go ahead" or "do that" they probably want you to make SEARCH/REPLACE blocks for the code changes you just proposed. The user will say when they've applied your edits. If they haven't explicitly confirmed the edits have been applied, they probably want proper SEARCH/REPLACE blocks. -{lazy_prompt} +{final_reminders} ONLY EVER RETURN CODE IN A *SEARCH/REPLACE BLOCK*! {shell_cmd_reminder} """ diff --git a/aider/coders/editblock_prompts.py b/aider/coders/editblock_prompts.py index 1457e021e..f6baaeb5f 100644 --- a/aider/coders/editblock_prompts.py +++ b/aider/coders/editblock_prompts.py @@ -1,5 +1,6 @@ # flake8: noqa: E501 +from . import shell from .base_prompts import CoderPrompts @@ -7,7 +8,7 @@ class EditBlockPrompts(CoderPrompts): main_system = """Act as an expert software developer. Always use best practices when coding. Respect and use existing conventions, libraries, etc that are already present in the code base. -{lazy_prompt} +{final_reminders} Take requests for changes to the supplied code. If the request is ambiguous, ask questions. @@ -28,32 +29,6 @@ You can keep asking if you then decide you need to edit more files. All changes to files must use this *SEARCH/REPLACE block* format. ONLY EVER RETURN CODE IN A *SEARCH/REPLACE BLOCK*! {shell_cmd_prompt} -""" - - shell_cmd_prompt = """ -4. *Concisely* suggest any shell commands the user might want to run in ```bash blocks. - -Just suggest shell commands this way, not example code. -Only suggest complete shell commands that are ready to execute, without placeholders. -Only suggest at most a few shell commands at a time, not more than 1-3, one per line. -Do not suggest multi-line shell commands. -All shell commands will run from the root directory of the user's project. - -Use the appropriate shell based on the user's system info: -{platform} -Examples of when to suggest shell commands: - -- If you changed a self-contained html file, suggest an OS-appropriate command to open a browser to view it to see the updated content. -- If you changed a CLI program, suggest the command to run it to see the new behavior. -- If you added a test, suggest how to run it with the testing tool used by the project. -- Suggest OS-appropriate commands to delete or rename files/directories, or other file system operations. -- If your code changes add new dependencies, suggest the command to install them. -- Etc. -""" - - no_shell_cmd_prompt = """ -Keep in mind these details about the user's platform and environment: -{platform} """ example_messages = [ dict( @@ -181,7 +156,7 @@ If you want to put code in a new file, use a *SEARCH/REPLACE block* with: - 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*! +{rename_with_shell}{go_ahead_tip}{final_reminders}ONLY EVER RETURN CODE IN A *SEARCH/REPLACE BLOCK*! {shell_cmd_reminder} """ @@ -194,14 +169,6 @@ The user will say when they've applied your edits. If they haven't explicitly co """ - shell_cmd_reminder = """ -Examples of when to suggest shell commands: - -- If you changed a self-contained html file, suggest an OS-appropriate command to open a browser to view it to see the updated content. -- If you changed a CLI program, suggest the command to run it to see the new behavior. -- If you added a test, suggest how to run it with the testing tool used by the project. -- Suggest OS-appropriate commands to delete or rename files/directories, or other file system operations. -- If your code changes add new dependencies, suggest the command to install them. -- Etc. - -""" + shell_cmd_prompt = shell.shell_cmd_prompt + no_shell_cmd_prompt = shell.no_shell_cmd_prompt + shell_cmd_reminder = shell.shell_cmd_reminder diff --git a/aider/coders/editor_editblock_prompts.py b/aider/coders/editor_editblock_prompts.py index 463075e2c..0ec36b47f 100644 --- a/aider/coders/editor_editblock_prompts.py +++ b/aider/coders/editor_editblock_prompts.py @@ -5,7 +5,7 @@ from .editblock_prompts import EditBlockPrompts class EditorEditBlockPrompts(EditBlockPrompts): main_system = """Act as an expert software developer who edits source code. -{lazy_prompt} +{final_reminders} Describe each change with a *SEARCH/REPLACE block* per the examples below. All changes to files must use this *SEARCH/REPLACE block* format. ONLY EVER RETURN CODE IN A *SEARCH/REPLACE BLOCK*! diff --git a/aider/coders/editor_whole_prompts.py b/aider/coders/editor_whole_prompts.py index 7abd0ee53..39bc38f64 100644 --- a/aider/coders/editor_whole_prompts.py +++ b/aider/coders/editor_whole_prompts.py @@ -5,6 +5,6 @@ from .wholefile_prompts import WholeFilePrompts class EditorWholeFilePrompts(WholeFilePrompts): main_system = """Act as an expert software developer and make changes to source code. -{lazy_prompt} +{final_reminders} Output a copy of each file that needs changes. """ diff --git a/aider/coders/patch_prompts.py b/aider/coders/patch_prompts.py index 830a04f2b..690a08884 100644 --- a/aider/coders/patch_prompts.py +++ b/aider/coders/patch_prompts.py @@ -11,7 +11,7 @@ class PatchPrompts(EditBlockPrompts): main_system = """Act as an expert software developer. Always use best practices when coding. Respect and use existing conventions, libraries, etc that are already present in the code base. -{lazy_prompt} +{final_reminders} Take requests for changes to the supplied code. If the request is ambiguous, ask questions. @@ -156,6 +156,6 @@ For `Add` actions, use the `*** Add File: [path/to/new/file]` marker, followed b 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! +{rename_with_shell}{go_ahead_tip}{final_reminders}ONLY EVER RETURN CODE IN THE SPECIFIED V4A DIFF FORMAT! {shell_cmd_reminder} """ diff --git a/aider/coders/udiff_prompts.py b/aider/coders/udiff_prompts.py index 5e7ca2c13..5201b8d89 100644 --- a/aider/coders/udiff_prompts.py +++ b/aider/coders/udiff_prompts.py @@ -1,11 +1,12 @@ # flake8: noqa: E501 +from . import shell from .base_prompts import CoderPrompts class UnifiedDiffPrompts(CoderPrompts): main_system = """Act as an expert software developer. -{lazy_prompt} +{final_reminders} Always use best practices when coding. Respect and use existing conventions, libraries, etc that are already present in the code base. @@ -106,5 +107,9 @@ To move code within a file, use 2 hunks: 1 to delete it from its current locatio To make a new file, show a diff from `--- /dev/null` to `+++ path/to/new/file.ext`. -{lazy_prompt} +{final_reminders} """ + + shell_cmd_prompt = shell.shell_cmd_prompt + no_shell_cmd_prompt = shell.no_shell_cmd_prompt + shell_cmd_reminder = shell.shell_cmd_reminder diff --git a/aider/coders/udiff_simple_prompts.py b/aider/coders/udiff_simple_prompts.py index 706bb1026..ea98164cf 100644 --- a/aider/coders/udiff_simple_prompts.py +++ b/aider/coders/udiff_simple_prompts.py @@ -21,5 +21,5 @@ Don't leave out any lines or the diff patch won't apply correctly. To make a new file, show a diff from `--- /dev/null` to `+++ path/to/new/file.ext`. -{lazy_prompt} -""" +{final_reminders} +""" # noqa diff --git a/aider/coders/wholefile_prompts.py b/aider/coders/wholefile_prompts.py index 95a4bb87b..6b6795833 100644 --- a/aider/coders/wholefile_prompts.py +++ b/aider/coders/wholefile_prompts.py @@ -10,7 +10,7 @@ If the request is ambiguous, ask questions. Always reply to the user in {language}. -{lazy_prompt} +{final_reminders} Once you understand the request you MUST: 1. Determine if any code changes are needed. 2. Explain any needed changes. @@ -61,7 +61,7 @@ To suggest changes to a file you MUST return a *file listing* that contains the *NEVER* skip, omit or elide content from a *file listing* using "..." or by adding comments like "... rest of code..."! Create a new file you MUST return a *file listing* which includes an appropriate filename, including any appropriate path. -{lazy_prompt} +{final_reminders} """ redacted_edit_message = "No changes are needed." diff --git a/aider/watch.py b/aider/watch.py index 8f84f6006..5d0e95a4f 100644 --- a/aider/watch.py +++ b/aider/watch.py @@ -35,6 +35,7 @@ def load_gitignores(gitignore_paths: list[Path]) -> Optional[PathSpec]: ".DS_Store", # macOS metadata "Thumbs.db", # Windows thumbnail cache "*.svg", + "*.pdf", # IDE files ".idea/", # JetBrains IDEs ".vscode/", # VS Code