From 74bed8206289d14d7cc221f65ef282f577d872eb Mon Sep 17 00:00:00 2001 From: daniel-lxs Date: Thu, 20 Nov 2025 00:38:09 -0500 Subject: [PATCH] Improve apply_diff tool description with examples - Add explicit format documentation showing structure directly - Include concrete examples (single and multiple edits) - Simplify structure explanation (removed verbose 'then this, then that') - Add critical warning about single '=======' separator - Clarify start_line uses actual numbers in examples This addresses agent confusion similar to read_file improvements. --- .../prompts/tools/native-tools/apply_diff.ts | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/core/prompts/tools/native-tools/apply_diff.ts b/src/core/prompts/tools/native-tools/apply_diff.ts index 19ef8318843..c1eaff201d7 100644 --- a/src/core/prompts/tools/native-tools/apply_diff.ts +++ b/src/core/prompts/tools/native-tools/apply_diff.ts @@ -4,9 +4,13 @@ export const apply_diff_single_file = { type: "function", function: { name: "apply_diff", - description: ` -Apply precise, targeted modifications to an existing file using one or more search/replace blocks. This tool is for surgical edits only; the 'SEARCH' block must exactly match the existing content, including whitespace and indentation. To make multiple targeted changes, provide multiple SEARCH/REPLACE blocks in the 'diff' parameter. Use the 'read_file' tool first if you are not confident in the exact content to search for. -`, + description: + "Apply precise, targeted modifications to an existing file using one or more search/replace blocks. This tool is for surgical edits only; the 'SEARCH' block must exactly match the existing content, including whitespace and indentation. " + + "To make multiple targeted changes, provide multiple SEARCH/REPLACE blocks in the 'diff' parameter. Use the 'read_file' tool first if you are not confident in the exact content to search for. " + + "Structure: '<<<<<<< SEARCH\\n:start_line:N\\n-------\\nexact content\\n=======\\nreplacement\\n>>>>>>> REPLACE' where N is the actual line number. " + + "Example single change: { path: 'src/utils.ts', diff: '<<<<<<< SEARCH\\n:start_line:5\\n-------\\nfunction add(a, b) {\\n return a + b;\\n}\\n=======\\nfunction add(a: number, b: number): number {\\n return a + b;\\n}\\n>>>>>>> REPLACE' }. " + + "Example multiple changes: { path: 'src/app.ts', diff: '<<<<<<< SEARCH\\n:start_line:10\\n-------\\nold code here\\n=======\\nnew code here\\n>>>>>>> REPLACE\\n\\n<<<<<<< SEARCH\\n:start_line:25\\n-------\\nmore old code\\n=======\\nmore new code\\n>>>>>>> REPLACE' }. " + + "CRITICAL: Use exactly ONE line of '=======' between search and replace content - multiple '=======' lines will corrupt the file.", parameters: { type: "object", properties: { @@ -16,16 +20,12 @@ Apply precise, targeted modifications to an existing file using one or more sear }, diff: { type: "string", - description: ` -A string containing one or more search/replace blocks defining the changes. The ':start_line:' is required and indicates the starting line number of the original content. You must not add a start line for the replacement content. Each block must follow this format: -<<<<<<< SEARCH -:start_line:[line_number] -------- -[exact content to find] -======= -[new content to replace with] ->>>>>>> REPLACE -`, + description: + "A string containing one or more search/replace blocks defining the changes. The ':start_line:' is required and indicates the starting line number of the original content. You must not add a start line for the replacement content. " + + "Format: '<<<<<<< SEARCH\\n:start_line:5\\n-------\\nexact content\\n=======\\nreplacement\\n>>>>>>> REPLACE'. " + + "Example: '<<<<<<< SEARCH\\n:start_line:10\\n-------\\nconst x = 1;\\n=======\\nconst x = 2;\\n>>>>>>> REPLACE'. " + + "For multiple edits: separate each block with a blank line and use different start_line values. " + + "IMPORTANT: The start_line must be the actual line number (e.g., :start_line:5, not :start_line:[5]).", }, }, required: ["path", "diff"],