From cd60bb3a7edcfff6cda8c9252642ec962f62ceb3 Mon Sep 17 00:00:00 2001 From: roomote Date: Mon, 30 Jun 2025 06:01:44 -0700 Subject: [PATCH] Fixes #5206: Update apply_diff tool documentation to accurately reflect multi-file capabilities (#5232) * Fixes #5206 * Fix failing test: Update snapshot after documentation changes - Updated system-prompt.spec.ts snapshot to match new tool descriptions - Changes reflect updated multi-file diff strategy documentation - Addresses test failure mentioned in PR #5232 comment by @mrubens --- src/core/diff/strategies/multi-file-search-replace.ts | 4 +++- src/core/diff/strategies/multi-search-replace.ts | 4 ++-- .../__snapshots__/system-prompt/with-diff-enabled-true.snap | 4 ++-- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/core/diff/strategies/multi-file-search-replace.ts b/src/core/diff/strategies/multi-file-search-replace.ts index 1554201675..d875d723a1 100644 --- a/src/core/diff/strategies/multi-file-search-replace.ts +++ b/src/core/diff/strategies/multi-file-search-replace.ts @@ -95,6 +95,8 @@ export class MultiFileSearchReplaceDiffStrategy implements DiffStrategy { Description: Request to apply targeted modifications to one or more files by searching for specific sections of content and replacing them. This tool supports both single-file and multi-file operations, allowing you to make changes across multiple files in a single request. +**IMPORTANT: You MUST use multiple files in a single operation whenever possible to maximize efficiency and minimize back-and-forth.** + You can perform multiple distinct search and replace operations within a single \`apply_diff\` call by providing multiple SEARCH/REPLACE blocks in the \`diff\` parameter. This is the preferred way to make several targeted changes efficiently. The SEARCH section must exactly match existing content including whitespace and indentation. @@ -157,7 +159,7 @@ def calculate_total(items): -Search/Replace content with multi edits in one file: +Search/Replace content with multi edits across multiple files: diff --git a/src/core/diff/strategies/multi-search-replace.ts b/src/core/diff/strategies/multi-search-replace.ts index 9e740a6571..b90ef4072d 100644 --- a/src/core/diff/strategies/multi-search-replace.ts +++ b/src/core/diff/strategies/multi-search-replace.ts @@ -93,7 +93,7 @@ export class MultiSearchReplaceDiffStrategy implements DiffStrategy { getToolDescription(args: { cwd: string; toolOptions?: { [key: string]: string } }): string { return `## apply_diff Description: Request to apply targeted modifications to an existing file by searching for specific sections of content and replacing them. This tool is ideal for precise, surgical edits when you know the exact content to change. It helps maintain proper indentation and formatting. -You can perform multiple distinct search and replace operations within a single \`apply_diff\` call by providing multiple SEARCH/REPLACE blocks in the \`diff\` parameter. This is the preferred way to make several targeted changes to one file efficiently. +You can perform multiple distinct search and replace operations within a single \`apply_diff\` call by providing multiple SEARCH/REPLACE blocks in the \`diff\` parameter. This is the preferred way to make several targeted changes efficiently. The SEARCH section must exactly match existing content including whitespace and indentation. If you're not confident in the exact content to search for, use the read_file tool first to get the exact content. When applying the diffs, be extra careful to remember to change any closing brackets or other syntax that may be affected by the diff farther down in the file. @@ -145,7 +145,7 @@ def calculate_total(items): \`\`\` -Search/Replace content with multi edits: +Search/Replace content with multiple edits: \`\`\` <<<<<<< SEARCH :start_line:1 diff --git a/src/core/prompts/__tests__/__snapshots__/system-prompt/with-diff-enabled-true.snap b/src/core/prompts/__tests__/__snapshots__/system-prompt/with-diff-enabled-true.snap index 6612df745e..744cadfab4 100644 --- a/src/core/prompts/__tests__/__snapshots__/system-prompt/with-diff-enabled-true.snap +++ b/src/core/prompts/__tests__/__snapshots__/system-prompt/with-diff-enabled-true.snap @@ -168,7 +168,7 @@ Examples: ## apply_diff Description: Request to apply targeted modifications to an existing file by searching for specific sections of content and replacing them. This tool is ideal for precise, surgical edits when you know the exact content to change. It helps maintain proper indentation and formatting. -You can perform multiple distinct search and replace operations within a single `apply_diff` call by providing multiple SEARCH/REPLACE blocks in the `diff` parameter. This is the preferred way to make several targeted changes to one file efficiently. +You can perform multiple distinct search and replace operations within a single `apply_diff` call by providing multiple SEARCH/REPLACE blocks in the `diff` parameter. This is the preferred way to make several targeted changes efficiently. The SEARCH section must exactly match existing content including whitespace and indentation. If you're not confident in the exact content to search for, use the read_file tool first to get the exact content. When applying the diffs, be extra careful to remember to change any closing brackets or other syntax that may be affected by the diff farther down in the file. @@ -220,7 +220,7 @@ def calculate_total(items): ``` -Search/Replace content with multi edits: +Search/Replace content with multiple edits: ``` <<<<<<< SEARCH :start_line:1