Skip to content

Commit 1835aa4

Browse files
committed
feat: add prompt instruction to break large edits into smaller apply_diff operations
- Updated MultiSearchReplaceDiffStrategy tool description - Updated MultiFileSearchReplaceDiffStrategy tool description - Added best practices section emphasizing smaller, focused changes - Updated test snapshots to reflect new tool descriptions This enhancement improves apply_diff success rates by encouraging users to break large modifications into smaller, more manageable chunks as suggested in issue #7289
1 parent 6fd261d commit 1835aa4

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

src/core/diff/strategies/multi-file-search-replace.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,18 @@ export class MultiFileSearchReplaceDiffStrategy implements DiffStrategy {
9595
9696
Description: Request to apply PRECISE, TARGETED modifications to one or more files by searching for specific sections of content and replacing them. This tool is for SURGICAL EDITS ONLY - specific changes to existing code. This tool supports both single-file and multi-file operations, allowing you to make changes across multiple files in a single request.
9797
98+
**IMPORTANT: When modifying large blocks of content, break the changes into multiple small \`apply_diff\` operations instead of attempting to modify everything at once. Make one small change at a time to improve success rate.**
99+
98100
**IMPORTANT: You MUST use multiple files in a single operation whenever possible to maximize efficiency and minimize back-and-forth.**
99101
100102
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.
101103
104+
**Best Practices:**
105+
- For large modifications: Break them into smaller, logical chunks (e.g., modify one function at a time, one section at a time)
106+
- Keep each SEARCH block focused and minimal - target specific lines rather than large blocks
107+
- Small diffs match more reliably and are easier to debug if they fail
108+
- Multiple small operations are better than one large operation
109+
102110
The SEARCH section must exactly match existing content including whitespace and indentation.
103111
If you're not confident in the exact content to search for, use the read_file tool first to get the exact content.
104112
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.

src/core/diff/strategies/multi-search-replace.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,17 @@ export class MultiSearchReplaceDiffStrategy implements DiffStrategy {
9393
getToolDescription(args: { cwd: string; toolOptions?: { [key: string]: string } }): string {
9494
return `## apply_diff
9595
Description: Request to apply PRECISE, TARGETED modifications to an existing file by searching for specific sections of content and replacing them. This tool is for SURGICAL EDITS ONLY - specific changes to existing code.
96+
97+
**IMPORTANT: When modifying large blocks of content, break the changes into multiple small \`apply_diff\` operations instead of attempting to modify everything at once. Make one small change at a time to improve success rate.**
98+
9699
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.
100+
101+
**Best Practices:**
102+
- For large modifications: Break them into smaller, logical chunks (e.g., modify one function at a time, one section at a time)
103+
- Keep each SEARCH block focused and minimal - target specific lines rather than large blocks
104+
- Small diffs match more reliably and are easier to debug if they fail
105+
- Multiple small operations are better than one large operation
106+
97107
The SEARCH section must exactly match existing content including whitespace and indentation.
98108
If you're not confident in the exact content to search for, use the read_file tool first to get the exact content.
99109
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.

src/core/prompts/__tests__/__snapshots__/system-prompt/with-diff-enabled-true.snap

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)