|
|
@@ -5,11 +5,16 @@ import * as path from "path"
|
|
|
|
|
|
function getEditingInstructions(diffStrategy?: DiffStrategy, experiments?: Record<string, boolean>): string {
|
|
|
const instructions: string[] = []
|
|
|
- const availableTools: string[] = ["write_to_file (for creating new files or complete file rewrites)"]
|
|
|
+ const availableTools: string[] = []
|
|
|
|
|
|
// Collect available editing tools
|
|
|
if (diffStrategy) {
|
|
|
- availableTools.push("apply_diff (for replacing lines in existing files)")
|
|
|
+ availableTools.push(
|
|
|
+ "apply_diff (for replacing lines in existing files)",
|
|
|
+ "write_to_file (for creating new files or complete file rewrites)",
|
|
|
+ )
|
|
|
+ } else {
|
|
|
+ availableTools.push("write_to_file (for creating new files or complete file rewrites)")
|
|
|
}
|
|
|
if (experiments?.["insert_content"]) {
|
|
|
availableTools.push("insert_content (for adding lines to existing files)")
|
|
|
@@ -36,16 +41,16 @@ function getEditingInstructions(diffStrategy?: DiffStrategy, experiments?: Recor
|
|
|
)
|
|
|
}
|
|
|
|
|
|
- instructions.push(
|
|
|
- "- When using the write_to_file tool to modify a file, use the tool directly with the desired content. You do not need to display the content before using the tool. ALWAYS provide the COMPLETE file content in your response. This is NON-NEGOTIABLE. Partial updates or placeholders like '// rest of code unchanged' are STRICTLY FORBIDDEN. You MUST include ALL parts of the file, even if they haven't been modified. Failure to do so will result in incomplete or broken code, severely impacting the user's project.",
|
|
|
- )
|
|
|
-
|
|
|
if (availableTools.length > 1) {
|
|
|
instructions.push(
|
|
|
"- You should always prefer using other editing tools over write_to_file when making changes to existing files since write_to_file is much slower and cannot handle large files.",
|
|
|
)
|
|
|
}
|
|
|
|
|
|
+ instructions.push(
|
|
|
+ "- When using the write_to_file tool to modify a file, use the tool directly with the desired content. You do not need to display the content before using the tool. ALWAYS provide the COMPLETE file content in your response. This is NON-NEGOTIABLE. Partial updates or placeholders like '// rest of code unchanged' are STRICTLY FORBIDDEN. You MUST include ALL parts of the file, even if they haven't been modified. Failure to do so will result in incomplete or broken code, severely impacting the user's project.",
|
|
|
+ )
|
|
|
+
|
|
|
return instructions.join("\n")
|
|
|
}
|
|
|
|
|
|
@@ -63,7 +68,7 @@ RULES
|
|
|
- You cannot \`cd\` into a different directory to complete a task. You are stuck operating from '${cwd.toPosix()}', so be sure to pass in the correct 'path' parameter when using tools that require a path.
|
|
|
- Do not use the ~ character or $HOME to refer to the home directory.
|
|
|
- Before using the execute_command tool, you must first think about the SYSTEM INFORMATION context provided to understand the user's environment and tailor your commands to ensure they are compatible with their system. You must also consider if the command you need to run should be executed in a specific directory outside of the current working directory '${cwd.toPosix()}', and if so prepend with \`cd\`'ing into that directory && then executing the command (as one command since you are stuck operating from '${cwd.toPosix()}'). For example, if you needed to run \`npm install\` in a project outside of '${cwd.toPosix()}', you would need to prepend with a \`cd\` i.e. pseudocode for this would be \`cd (path to project) && (command, in this case npm install)\`.
|
|
|
-- When using the search_files tool, craft your regex patterns carefully to balance specificity and flexibility. Based on the user's task you may use it to find code patterns, TODO comments, function definitions, or any text-based information across the project. The results include context, so analyze the surrounding code to better understand the matches. Leverage the search_files tool in combination with other tools for more comprehensive analysis. For example, use it to find specific code patterns, then use read_file to examine the full context of interesting matches before using write_to_file to make informed changes.
|
|
|
+- When using the search_files tool, craft your regex patterns carefully to balance specificity and flexibility. Based on the user's task you may use it to find code patterns, TODO comments, function definitions, or any text-based information across the project. The results include context, so analyze the surrounding code to better understand the matches. Leverage the search_files tool in combination with other tools for more comprehensive analysis. For example, use it to find specific code patterns, then use read_file to examine the full context of interesting matches before using ${diffStrategy ? "apply_diff or write_to_file" : "write_to_file"} to make informed changes.
|
|
|
- When creating a new project (such as an app, website, or any software project), organize all new files within a dedicated project directory unless the user specifies otherwise. Use appropriate file paths when writing files, as the write_to_file tool will automatically create any necessary directories. Structure the project logically, adhering to best practices for the specific type of project being created. Unless otherwise specified, new projects should be easily run without additional setup, for example most projects can be built in HTML, CSS, and JavaScript - which you can open in a browser.
|
|
|
${getEditingInstructions(diffStrategy, experiments)}
|
|
|
- Some modes have restrictions on which files they can edit. If you attempt to edit a restricted file, the operation will be rejected with a FileRestrictionError that will specify which file patterns are allowed for the current mode.
|