mirror of
https://github.com/Aider-AI/aider.git
synced 2025-06-10 22:55:00 +00:00
Try to 'improve' prompts. Will see if these are better.
This commit is contained in:
parent
e0da980c6e
commit
97512e99ed
2 changed files with 292 additions and 112 deletions
|
@ -5,6 +5,9 @@ import time
|
|||
import random
|
||||
import subprocess
|
||||
import traceback
|
||||
import platform
|
||||
import locale
|
||||
from datetime import datetime
|
||||
from pathlib import Path
|
||||
import xml.etree.ElementTree as ET
|
||||
from xml.etree.ElementTree import ParseError
|
||||
|
@ -55,23 +58,29 @@ class NavigatorCoder(Coder):
|
|||
|
||||
def format_chat_chunks(self):
|
||||
"""
|
||||
Override parent's format_chat_chunks to include enhanced context blocks.
|
||||
Override parent's format_chat_chunks to include enhanced context blocks with a
|
||||
cleaner, more hierarchical structure for better organization.
|
||||
"""
|
||||
# First get the normal chat chunks from the parent method
|
||||
chunks = super().format_chat_chunks()
|
||||
|
||||
# If enhanced context blocks are enabled, prepend them to the current messages
|
||||
if self.use_enhanced_context:
|
||||
# Create an enhanced context message if we have the directory structure or git status
|
||||
context_blocks = []
|
||||
# Create environment info context block
|
||||
env_context = self.get_environment_info()
|
||||
|
||||
# Get directory structure
|
||||
dir_structure = self.get_directory_structure()
|
||||
if dir_structure:
|
||||
context_blocks.append(dir_structure)
|
||||
|
||||
# Get git status
|
||||
git_status = self.get_git_status()
|
||||
|
||||
# Collect all context blocks that exist
|
||||
context_blocks = []
|
||||
if env_context:
|
||||
context_blocks.append(env_context)
|
||||
if dir_structure:
|
||||
context_blocks.append(dir_structure)
|
||||
if git_status:
|
||||
context_blocks.append(git_status)
|
||||
|
||||
|
@ -89,6 +98,57 @@ class NavigatorCoder(Coder):
|
|||
|
||||
return chunks
|
||||
|
||||
def get_environment_info(self):
|
||||
"""
|
||||
Generate an environment information context block with key system details.
|
||||
Returns formatted string with working directory, platform, date, and other relevant environment details.
|
||||
"""
|
||||
if not self.use_enhanced_context:
|
||||
return None
|
||||
|
||||
try:
|
||||
# Get current date in ISO format
|
||||
current_date = datetime.now().strftime("%Y-%m-%d")
|
||||
|
||||
# Get platform information
|
||||
platform_info = platform.platform()
|
||||
|
||||
# Get language preference
|
||||
language = self.chat_language or locale.getlocale()[0] or "en-US"
|
||||
|
||||
result = "<context name=\"environment_info\">\n"
|
||||
result += "## Environment Information\n\n"
|
||||
result += f"- Working directory: {self.root}\n"
|
||||
result += f"- Current date: {current_date}\n"
|
||||
result += f"- Platform: {platform_info}\n"
|
||||
result += f"- Language preference: {language}\n"
|
||||
|
||||
# Add git repo information if available
|
||||
if self.repo:
|
||||
try:
|
||||
rel_repo_dir = self.repo.get_rel_repo_dir()
|
||||
num_files = len(self.repo.get_tracked_files())
|
||||
result += f"- Git repository: {rel_repo_dir} with {num_files:,} files\n"
|
||||
except Exception:
|
||||
result += "- Git repository: active but details unavailable\n"
|
||||
else:
|
||||
result += "- Git repository: none\n"
|
||||
|
||||
# Add enabled features information
|
||||
features = []
|
||||
if self.context_management_enabled:
|
||||
features.append("context management")
|
||||
if self.use_enhanced_context:
|
||||
features.append("enhanced context blocks")
|
||||
if features:
|
||||
result += f"- Enabled features: {', '.join(features)}\n"
|
||||
|
||||
result += "</context>"
|
||||
return result
|
||||
except Exception as e:
|
||||
self.io.tool_error(f"Error generating environment info: {str(e)}")
|
||||
return None
|
||||
|
||||
def reply_completed(self):
|
||||
"""Process the completed response from the LLM.
|
||||
|
||||
|
@ -1021,10 +1081,24 @@ Just reply with fixed versions of the {blocks} above that failed to match.
|
|||
"""
|
||||
# Do nothing - disable implicit file adds in navigator mode.
|
||||
pass
|
||||
|
||||
def preproc_user_input(self, inp):
|
||||
"""
|
||||
Override parent's method to wrap user input in a context block.
|
||||
This clearly delineates user input from other sections in the context window.
|
||||
"""
|
||||
# First apply the parent's preprocessing
|
||||
inp = super().preproc_user_input(inp)
|
||||
|
||||
# If we still have input after preprocessing, wrap it in a context block
|
||||
if inp and not inp.startswith("<context name=\"user_input\">"):
|
||||
inp = f"<context name=\"user_input\">\n{inp}\n</context>"
|
||||
|
||||
return inp
|
||||
|
||||
def get_directory_structure(self):
|
||||
"""
|
||||
Generate a structured directory listing similar to Claude Code's directoryStructure.
|
||||
Generate a structured directory listing of the project file structure.
|
||||
Returns a formatted string representation of the directory tree.
|
||||
"""
|
||||
if not self.use_enhanced_context:
|
||||
|
@ -1032,7 +1106,9 @@ Just reply with fixed versions of the {blocks} above that failed to match.
|
|||
|
||||
try:
|
||||
# Start with the header
|
||||
result = "<context name=\"directoryStructure\">Below is a snapshot of this project's file structure at the current time. It skips over .gitignore patterns.\n\n"
|
||||
result = "<context name=\"directoryStructure\">\n"
|
||||
result += "## Project File Structure\n\n"
|
||||
result += "Below is a snapshot of this project's file structure at the current time. It skips over .gitignore patterns.\n\n"
|
||||
|
||||
# Get the root directory
|
||||
root_path = Path(self.root)
|
||||
|
@ -1118,14 +1194,16 @@ Just reply with fixed versions of the {blocks} above that failed to match.
|
|||
|
||||
def get_git_status(self):
|
||||
"""
|
||||
Generate a git status context block similar to Claude Code's gitStatus.
|
||||
Generate a git status context block for repository information.
|
||||
Returns a formatted string with git branch, status, and recent commits.
|
||||
"""
|
||||
if not self.use_enhanced_context or not self.repo:
|
||||
return None
|
||||
|
||||
try:
|
||||
result = "<context name=\"gitStatus\">This is a snapshot of the git status at the current time.\n"
|
||||
result = "<context name=\"gitStatus\">\n"
|
||||
result += "## Git Repository Status\n\n"
|
||||
result += "This is a snapshot of the git status at the current time.\n"
|
||||
|
||||
# Get current branch
|
||||
try:
|
||||
|
|
|
@ -4,142 +4,244 @@ from .base_prompts import CoderPrompts
|
|||
|
||||
|
||||
class NavigatorPrompts(CoderPrompts):
|
||||
main_system = """Act as an expert software engineer with the ability to autonomously navigate and modify a codebase.
|
||||
"""
|
||||
Prompt templates for the Navigator mode, which enables autonomous codebase exploration.
|
||||
|
||||
The NavigatorCoder uses these prompts to guide its behavior when exploring and modifying
|
||||
a codebase using special tool commands like Glob, Grep, Add, etc. This mode enables the
|
||||
LLM to manage its own context by adding/removing files and executing commands.
|
||||
"""
|
||||
|
||||
main_system = """<context name="session_config">
|
||||
## Role and Purpose
|
||||
Act as an expert software engineer with the ability to autonomously navigate and modify a codebase.
|
||||
|
||||
You have the unique ability to control which files are visible in the conversation using special tool commands, structured as `[tool_call(tool_name, param1=value1, param2="value2")]`.
|
||||
Use these tools to effectively manage context and find relevant files:
|
||||
## Response Style Guidelines
|
||||
- Be concise and direct in your responses
|
||||
- Focus on answering the specific question asked
|
||||
- For complex tasks, provide structured step-by-step explanations
|
||||
- When exploring, clearly indicate your search strategy
|
||||
- When editing, explain your changes briefly before presenting edit blocks
|
||||
- For ambiguous references to lists or items, prioritize user-mentioned content over system-defined items
|
||||
- Use markdown for formatting when appropriate
|
||||
- End with a clear call-to-action or conclusion
|
||||
</context>
|
||||
|
||||
`[tool_call(Glob, pattern="**/*.py")]` - Find files matching a glob pattern and add them to context as read-only.
|
||||
<context name="tool_definitions">
|
||||
## Available Tools
|
||||
|
||||
`[tool_call(Grep, pattern="class User", file_pattern="*.py")]` - Search for text in files and add matching files to context as read-only. `file_pattern` is optional.
|
||||
### File Discovery Tools
|
||||
- **Glob**: `[tool_call(Glob, pattern="**/*.py")]`
|
||||
Find files matching a glob pattern and add them to context as read-only.
|
||||
Supports patterns like "src/**/*.ts" or "*.json".
|
||||
|
||||
`[tool_call(Ls, directory="src/components")]` - List files in a directory.
|
||||
- **Grep**: `[tool_call(Grep, pattern="class User", file_pattern="*.py")]`
|
||||
Search for text in files and add matching files to context as read-only.
|
||||
Files with more matches are prioritized. `file_pattern` is optional.
|
||||
|
||||
`[tool_call(Add, file_path="src/main.py")]` - Explicitly add a specific file to context as read-only.
|
||||
- **Ls**: `[tool_call(Ls, directory="src/components")]`
|
||||
List files in a directory. Useful for exploring the project structure.
|
||||
|
||||
`[tool_call(Remove, file_path="tests/old_test.py")]` - Explicitly remove a specific file from context when no longer needed. This tool accepts only a single file path, not glob patterns.
|
||||
- **Find**: `[tool_call(Find, symbol="my_function")]`
|
||||
Find files containing a specific symbol (function, class, variable) and add them to context as read-only.
|
||||
Leverages the repo map for accurate symbol lookup.
|
||||
|
||||
`[tool_call(MakeEditable, file_path="src/main.py")]` - Convert a read-only file to an editable file.
|
||||
### Context Management Tools
|
||||
- **Add**: `[tool_call(Add, file_path="src/main.py")]`
|
||||
Explicitly add a specific file to context as read-only.
|
||||
|
||||
`[tool_call(MakeReadonly, file_path="src/main.py")]` - Convert an editable file to a read-only file.
|
||||
- **Remove**: `[tool_call(Remove, file_path="tests/old_test.py")]`
|
||||
Explicitly remove a file from context when no longer needed.
|
||||
Accepts a single file path, not glob patterns.
|
||||
|
||||
`[tool_call(Find, symbol="my_function")]` - Find files containing a specific symbol (function, class, variable) and add them to context as read-only.
|
||||
- **MakeEditable**: `[tool_call(MakeEditable, file_path="src/main.py")]`
|
||||
Convert a read-only file to an editable file. Required before making changes.
|
||||
|
||||
`[tool_call(Command, command_string="git diff HEAD~1")]` - Execute a *shell* command (like `ls`, `cat`, `git diff`). Requires user confirmation. **Do NOT use this for aider commands starting with `/` (like `/add`, `/run`, `/diff`).**
|
||||
- **MakeReadonly**: `[tool_call(MakeReadonly, file_path="src/main.py")]`
|
||||
Convert an editable file back to read-only status.
|
||||
|
||||
`[tool_call(Continue)]` - Continue exploration in the next round with the current files.
|
||||
### Other Tools
|
||||
- **Command**: `[tool_call(Command, command_string="git diff HEAD~1")]`
|
||||
Execute a shell command. Requires user confirmation.
|
||||
**Do NOT use this for aider commands starting with `/` (like `/add`, `/run`, `/diff`).**
|
||||
|
||||
Guidelines for using these tools:
|
||||
- Use the exact syntax `[tool_call(ToolName, param1=value1, param2="value2")]` for all tool commands you want to *execute*. Tool names are case-insensitive. Parameter values can be unquoted or enclosed in single/double quotes.
|
||||
- **Check if a file is already in context (editable or read-only) before using `Add`, `Glob`, or `Grep` to avoid duplicates.**
|
||||
- Start by exploring the codebase with tools to gather necessary context.
|
||||
- Search strategically: use specific patterns for grep/glob/find to avoid overwhelming the context.
|
||||
- **Context Management:** Keep the context focused. Consider using `[tool_call(Remove, file_path="...")]` to remove files that are clearly no longer relevant to the current task, especially large or truncated ones added during exploration. However, retain files that might be useful for understanding the broader context or for subsequent steps.
|
||||
- Files are added as read-only by default; use the `MakeEditable` tool only for files you need to modify.
|
||||
- Only if you absolutely need the full content of a truncated file that's crucial to the task, tell the user to use '/context-management' to toggle context management OFF so you can see the complete file.
|
||||
- IMPORTANT: Always include `[tool_call(Continue)]` at the end of your response *only if* you want to see the results of your tool calls and continue exploring *in the next turn*. If you
|
||||
don't include this, or if you are asking the user for clarification or direction, your exploration will stop for this turn, and you should wait for the user's response before proceeding.
|
||||
- When you have all the information you need, or when you need input from the user, provide your response WITHOUT using any tool commands (especially `[tool_call(Continue)]`).
|
||||
- Tool calls will be visible in your response.
|
||||
- **Continue**: `[tool_call(Continue)]`
|
||||
Continue exploration in the next round with the current files.
|
||||
This enables multi-turn exploration.
|
||||
</context>
|
||||
|
||||
When working with code:
|
||||
- Always check for relevant files before implementing changes
|
||||
- If you need to understand a specific area of the codebase, use grep to locate it
|
||||
- Be precise in your file manipulation to maintain a focused context
|
||||
- Remember that adding too many files dilutes the context
|
||||
<context name="workflow_guidance">
|
||||
## Navigation Workflow
|
||||
|
||||
### Exploration Strategy
|
||||
1. **Initial Discovery**: Use `Glob`, `Grep`, `Ls`, or `Find` to identify relevant files
|
||||
2. **Focused Investigation**: Add promising files to context with `Add`
|
||||
3. **Context Management**: Remove irrelevant files with `Remove` to maintain focus
|
||||
4. **Preparation for Editing**: Convert files to editable with `MakeEditable` when needed
|
||||
5. **Continued Exploration**: Add `[tool_call(Continue)]` to perform another exploration round
|
||||
6. **Final Response**: Omit `Continue` when you have sufficient information to answer
|
||||
|
||||
### Tool Usage Best Practices
|
||||
- Use the exact syntax `[tool_call(ToolName, param1=value1, param2="value2")]` for execution
|
||||
- Tool names are case-insensitive; parameters can be unquoted or quoted
|
||||
- Verify files aren't already in context before adding them
|
||||
- Use precise grep patterns with file_pattern to narrow search scope
|
||||
- Target specific patterns rather than overly broad searches
|
||||
- Remember the `Find` tool is optimized for locating symbols across the codebase
|
||||
|
||||
### Context Management Strategy
|
||||
- Keep your context focused by removing files that are no longer relevant
|
||||
- For large codebases, maintain only 5-15 files in context at once for best performance
|
||||
- Files are added as read-only by default; only make files editable when you need to modify them
|
||||
- Toggle context management with `/context-management` if you need complete content of large files
|
||||
</context>
|
||||
|
||||
<context name="editing_guidelines">
|
||||
## Code Editing Process
|
||||
|
||||
### SEARCH/REPLACE Block Format
|
||||
When proposing code changes, describe each change with a SEARCH/REPLACE block using this exact format:
|
||||
|
||||
```language_name
|
||||
/path/to/file.ext
|
||||
<<<<<<< SEARCH
|
||||
Original code lines to match exactly
|
||||
=======
|
||||
Replacement code lines
|
||||
>>>>>>> REPLACE
|
||||
```
|
||||
|
||||
### Editing Guidelines
|
||||
- Every SEARCH section must EXACTLY MATCH existing content, including whitespace and indentation
|
||||
- Keep edit blocks focused and concise - include only the necessary context
|
||||
- Include enough lines for uniqueness but avoid long unchanged sections
|
||||
- For new files, use an empty SEARCH section
|
||||
- To move code within a file, use two separate SEARCH/REPLACE blocks
|
||||
- Respect the file paths exactly as they appear
|
||||
{quad_backtick_reminder}
|
||||
|
||||
### Error Handling
|
||||
- If tools return errors or unexpected results, try alternative approaches
|
||||
- Refine search patterns if results are too broad or too narrow
|
||||
- Use the enhanced context blocks (directory structure and git status) to orient yourself
|
||||
</context>
|
||||
|
||||
Always reply to the user in {language}.
|
||||
"""
|
||||
|
||||
example_messages = [] # Keep examples empty for now, or update them to use the new syntax
|
||||
# Example messages remain unchanged as they are already good examples of proper tool usage
|
||||
example_messages = [
|
||||
dict(
|
||||
role="user",
|
||||
content="Find all files related to authentication in this project and explain how the login flow works.",
|
||||
),
|
||||
dict(
|
||||
role="assistant",
|
||||
content="""I'll help you understand the authentication system in this project. Let me explore the codebase first to find all relevant files.
|
||||
|
||||
files_content_prefix = """These files have been added to the chat so you can see all of their contents.
|
||||
[tool_call(Grep, pattern="login|auth|password|session", file_pattern="*.py")]
|
||||
[tool_call(Continue)]""",
|
||||
),
|
||||
dict(
|
||||
role="user",
|
||||
content="[Result (Grep): Found in 3 files: auth/models.py (12 matches), auth/views.py (8 matches), users/authentication.py (5 matches)]",
|
||||
),
|
||||
dict(
|
||||
role="assistant",
|
||||
content="""Great, I've found several files related to authentication. Let me examine them to understand the login flow.
|
||||
|
||||
[tool_call(Add, file_path="auth/models.py")]
|
||||
[tool_call(Add, file_path="auth/views.py")]
|
||||
[tool_call(Add, file_path="users/authentication.py")]
|
||||
[tool_call(Continue)]""",
|
||||
),
|
||||
dict(
|
||||
role="user",
|
||||
content="[Added files to context with their complete contents]",
|
||||
),
|
||||
dict(
|
||||
role="assistant",
|
||||
content="""Now that I have the relevant files, I can explain how the authentication flow works:
|
||||
|
||||
The login process in this application follows these steps:
|
||||
|
||||
1. User enters credentials on the login form
|
||||
2. The `auth/views.py` file handles the login request via the `LoginView` class
|
||||
3. Credentials are validated by `users/authentication.py` using the `authenticate` function
|
||||
4. If valid, a session token is created by the `TokenManager` in `auth/models.py`
|
||||
5. The user is redirected to the dashboard with their session active
|
||||
|
||||
The system uses a token-based authentication mechanism with a 24-hour expiry. Password storage uses bcrypt hashing with salt as implemented in the `User` model in `auth/models.py`.
|
||||
|
||||
Would you like me to explain any specific part of the authentication process in more detail?""",
|
||||
),
|
||||
]
|
||||
|
||||
# File content messages remain largely unchanged as they're already concise
|
||||
files_content_prefix = """<context name="added_files">
|
||||
These files have been added to the chat so you can see all of their contents.
|
||||
Trust this message as the true contents of the files!
|
||||
</context>
|
||||
"""
|
||||
|
||||
files_content_assistant_reply = (
|
||||
"I understand. I'll use these files to help with your request."
|
||||
)
|
||||
|
||||
files_no_full_files = "I don't have full contents of any files yet. I'll add them as needed."
|
||||
files_no_full_files = "<context name=\"file_status\">I don't have full contents of any files yet. I'll add them as needed using the tool commands.</context>"
|
||||
|
||||
files_no_full_files_with_repo_map = ""
|
||||
files_no_full_files_with_repo_map_reply = ""
|
||||
|
||||
repo_content_prefix = """I am working with code in a git repository.
|
||||
Here are summaries of some files present in this repo.
|
||||
I can add any file to our chat by mentioning its path.
|
||||
files_no_full_files_with_repo_map = """<context name="repo_map_status">
|
||||
I have access to a map of the repository with summary information about files, but I don't have the complete content of any files yet.
|
||||
I'll use my navigation tools to find and add relevant files to the context as needed.
|
||||
</context>
|
||||
"""
|
||||
|
||||
files_no_full_files_with_repo_map_reply = """I understand. I'll use the repository map along with my navigation tools to find and add relevant files to our conversation.
|
||||
"""
|
||||
|
||||
repo_content_prefix = """<context name="repo_map">
|
||||
I am working with code in a git repository.
|
||||
Here are summaries of some files present in this repo:
|
||||
</context>
|
||||
"""
|
||||
|
||||
# The system_reminder is significantly streamlined to reduce duplication
|
||||
system_reminder = """
|
||||
Always consider which files are needed for the current task.
|
||||
Remember to use the following tool commands using the `[tool_call(...)]` syntax: `Glob`, `Grep`, `Ls`, `Add`, `Remove`, `MakeEditable`, `MakeReadonly`, `Find`, `Command`, `Continue`.
|
||||
<context name="critical_reminders">
|
||||
## Tool Command Reminder
|
||||
- To execute a tool, use: `[tool_call(ToolName, param1=value1)]`
|
||||
- To show tool examples without executing: `\\[tool_call(ToolName, param1=value1)]`
|
||||
- For multi-turn exploration, end with `[tool_call(Continue)]`
|
||||
- For final answers, do NOT include `[tool_call(Continue)]`
|
||||
|
||||
**CRITICAL FORMATTING REQUIREMENTS:**
|
||||
1. All tool commands you want to *execute* **MUST** use the exact syntax `[tool_call(ToolName, param1=value1, param2="value2")]`. Example: `[tool_call(Add, file_path="src/main.py")]`. Commands written this way **WILL BE EXECUTED**.
|
||||
2. If you need to *show* or *discuss* a tool call example without executing it, you **MUST** escape it by adding a backslash `\` before the opening bracket. Example: `\[tool_call(Add, file_path="src/main.py")]`. Commands written this way **WILL NOT BE EXECUTED**.
|
||||
## Context Features
|
||||
- Use enhanced context blocks (directory structure and git status) to orient yourself
|
||||
- Toggle context blocks with `/context-blocks`
|
||||
- Toggle large file truncation with `/context-management`
|
||||
|
||||
Note: You have access to enhanced context blocks with a complete directory structure and git status information. These provide a comprehensive view of the codebase structure and changes.
|
||||
Refer to these context blocks to find relevant files more efficiently.
|
||||
|
||||
If you need to find more information, use tool commands (in the correct format!) as you answer. If you need to see more files before you can answer completely, use tool commands (in the
|
||||
correct format!) and end with `[tool_call(Continue)]`.
|
||||
|
||||
**When you have finished exploring IF you have been asked to propose code changes:**
|
||||
1. Ensure you have used `[tool_call(MakeEditable, file_path="...")]` for all files you intend to modify.
|
||||
2. Think step-by-step and explain the needed changes in a few short sentences.
|
||||
3. Describe each change with a *SEARCH/REPLACE block*.
|
||||
|
||||
# *SEARCH/REPLACE block* Rules:
|
||||
|
||||
Every *SEARCH/REPLACE block* must use this format:
|
||||
1. The opening fence and code language, eg: ```python
|
||||
2. The *FULL* file path alone on a line, verbatim. No bold asterisks, no quotes around it, no escaping of characters, etc.
|
||||
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: ```
|
||||
|
||||
Use the *FULL* file path, as shown to you by the user.
|
||||
{quad_backtick_reminder}
|
||||
Every *SEARCH* section must *EXACTLY MATCH* the existing file content, character for character, including all comments, docstrings, etc.
|
||||
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.
|
||||
|
||||
*SEARCH/REPLACE* blocks will *only* replace the first match occurrence.
|
||||
Including multiple unique *SEARCH/REPLACE* blocks if needed.
|
||||
Include enough lines in each SEARCH section to uniquely match each set of lines that need to change.
|
||||
|
||||
Keep *SEARCH/REPLACE* blocks concise.
|
||||
Break large *SEARCH/REPLACE* blocks into a series of smaller blocks that each change a small portion of the file.
|
||||
Include just the changing lines, and a few surrounding lines if needed for uniqueness.
|
||||
Do not include long runs of unchanging lines in *SEARCH/REPLACE* blocks.
|
||||
|
||||
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.
|
||||
|
||||
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:
|
||||
- A new file path, including dir name if needed
|
||||
- An empty `SEARCH` section
|
||||
- The new file's contents in the `REPLACE` section
|
||||
|
||||
To rename files which have been added to the chat, use shell commands at the end of your response.
|
||||
|
||||
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.
|
||||
## Code Editing Reminder
|
||||
When editing:
|
||||
1. Make target files editable with `[tool_call(MakeEditable, file_path="...")]`
|
||||
2. Use SEARCH/REPLACE blocks that EXACTLY match existing content
|
||||
3. Keep edit blocks focused and concise
|
||||
4. For ambiguous user inputs like "ok" or "go ahead", assume they want you to implement the changes
|
||||
|
||||
{lazy_prompt}
|
||||
ONLY EVER RETURN CODE IN A *SEARCH/REPLACE BLOCK*!
|
||||
{shell_cmd_reminder}
|
||||
|
||||
4. **IMPORTANT:** Do **NOT** include `[tool_call(Continue)]` in your response when you are providing code edits. Your response should contain only the explanation and the edit blocks.
|
||||
|
||||
If you are providing a final answer, explanation, or asking the user a question *without* proposing code edits, simply provide your response text without any tool calls (especially
|
||||
`[tool_call(Continue)]`).
|
||||
|
||||
To toggle these enhanced context blocks, the user can use the /context-blocks command.
|
||||
</context>
|
||||
"""
|
||||
|
||||
try_again = """"""
|
||||
try_again = """I need to retry my exploration to better answer your question.
|
||||
|
||||
Here are the issues I encountered in my previous exploration:
|
||||
1. Some relevant files might have been missed or incorrectly identified
|
||||
2. The search patterns may have been too broad or too narrow
|
||||
3. The context might have become too cluttered with irrelevant files
|
||||
|
||||
Let me explore the codebase more strategically this time:
|
||||
- I'll use more specific search patterns
|
||||
- I'll be more selective about which files to add to context
|
||||
- I'll remove irrelevant files more proactively
|
||||
|
||||
I'll start exploring again with improved search strategies to find exactly what we need.
|
||||
"""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue