You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix: clarify apply_diff is for surgical edits only, not full file rewrites
- Updated apply_diff tool description to emphasize it is for SURGICAL EDITS ONLY
- Added CRITICAL warning that apply_diff is NOT for rewriting entire files
- Added clear examples of GOOD use (single line change) vs BAD use (entire file rewrite)
- Updated rules section to emphasize using apply_diff for small, targeted changes
- Applied same improvements to both single-file and multi-file diff strategies
- Fixed ESLint warning by removing unused directive
This should help prevent models from misusing apply_diff to rewrite entire files
when they should be using write_to_file instead.
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.
96
+
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 - small, 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.
97
+
98
+
**CRITICAL: This tool is NOT for rewriting entire files or making large-scale changes. Use write_to_file for that purpose.**
97
99
98
100
**IMPORTANT: You MUST use multiple files in a single operation whenever possible to maximize efficiency and minimize back-and-forth.**
99
101
102
+
Key characteristics:
103
+
- Ideal for changing specific lines, functions, or small code blocks
104
+
- Preserves the rest of the file unchanged
105
+
- Requires exact matching of existing content (including whitespace)
106
+
- Can perform multiple small edits in one operation across multiple files
107
+
100
108
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.
101
109
102
110
The SEARCH section must exactly match existing content including whitespace and indentation.
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.
93
+
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 - small, specific changes to existing code.
94
+
95
+
**CRITICAL: This tool is NOT for rewriting entire files or making large-scale changes. Use write_to_file for that purpose.**
96
+
97
+
Key characteristics:
98
+
- Ideal for changing specific lines, functions, or small code blocks
99
+
- Preserves the rest of the file unchanged
100
+
- Requires exact matching of existing content (including whitespace)
101
+
- Can perform multiple small edits in one operation
102
+
96
103
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.
97
-
The SEARCH section must exactly match existing content including whitespace and indentation.
98
-
If you're not confident in the exact content to search for, use the read_file tool first to get the exact content.
104
+
105
+
IMPORTANT: 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.
106
+
99
107
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.
108
+
100
109
ALWAYS make as many changes in a single 'apply_diff' request as possible using multiple SEARCH/REPLACE blocks
101
110
102
111
Parameters:
@@ -116,7 +125,7 @@ Diff format:
116
125
\`\`\`
117
126
118
127
119
-
Example:
128
+
Example of GOOD use (surgical edit - changing a single line):
120
129
121
130
Original file:
122
131
\`\`\`
@@ -129,43 +138,53 @@ Original file:
129
138
130
139
Search/Replace content:
131
140
\`\`\`
132
-
<<<<<<< SEARCH
141
+
\\<<<<<<< SEARCH
142
+
:start_line:2
143
+
-------
144
+
total = 0
145
+
\\=======
146
+
total = 0 # Initialize sum
147
+
\\>>>>>>> REPLACE
148
+
\`\`\`
149
+
150
+
Example of BAD use (trying to rewrite entire file - use write_to_file instead):
151
+
\`\`\`
152
+
\\<<<<<<< SEARCH
133
153
:start_line:1
134
154
-------
135
155
def calculate_total(items):
136
156
total = 0
137
157
for item in items:
138
158
total += item
139
159
return total
140
-
=======
160
+
\\=======
141
161
def calculate_total(items):
142
162
"""Calculate total with 10% markup"""
143
163
return sum(item * 1.1 for item in items)
144
-
>>>>>>> REPLACE
145
-
164
+
\\>>>>>>> REPLACE
146
165
\`\`\`
147
166
148
-
Search/Replace content with multiple edits:
167
+
Example with multiple surgical edits:
149
168
\`\`\`
150
-
<<<<<<< SEARCH
169
+
\\<<<<<<< SEARCH
151
170
:start_line:1
152
171
-------
153
172
def calculate_total(items):
154
173
sum = 0
155
-
=======
174
+
\\=======
156
175
def calculate_sum(items):
157
176
sum = 0
158
-
>>>>>>> REPLACE
177
+
\\>>>>>>> REPLACE
159
178
160
-
<<<<<<< SEARCH
179
+
\\<<<<<<< SEARCH
161
180
:start_line:4
162
181
-------
163
182
total += item
164
183
return total
165
-
=======
184
+
\\=======
166
185
sum += item
167
186
return sum
168
-
>>>>>>> REPLACE
187
+
\\>>>>>>> REPLACE
169
188
\`\`\`
170
189
171
190
@@ -349,31 +368,31 @@ Only use a single line of '=======' between search and replacement content, beca
349
368
Regex parts:
350
369
351
370
1. (?:^|\n)
352
-
Ensures the first marker starts at the beginning of the file or right after a newline.
371
+
Ensures the first marker starts at the beginning of the file or right after a newline.
353
372
354
373
2. (?<!\\)<<<<<<< SEARCH\s*\n
355
-
Matches the line “<<<<<<< SEARCH” (ignoring any trailing spaces) – the negative lookbehind makes sure it isn’t escaped.
374
+
Matches the line "<<<<<<< SEARCH" (ignoring any trailing spaces) – the negative lookbehind makes sure it isn't escaped.
356
375
357
376
3. ((?:\:start_line:\s*(\d+)\s*\n))?
358
-
Optionally matches a “:start_line:” line. The outer capturing group is group1 and the inner (\d+) is group2.
377
+
Optionally matches a ":start_line:" line. The outer capturing group is group1 and the inner (\d+) is group2.
359
378
360
379
4. ((?:\:end_line:\s*(\d+)\s*\n))?
361
-
Optionally matches a “:end_line:” line. Group3 is the whole match and group4 is the digits.
380
+
Optionally matches a ":end_line:" line. Group3 is the whole match and group4 is the digits.
362
381
363
382
5. ((?<!\\)-------\s*\n)?
364
-
Optionally matches the “-------” marker line (group5).
383
+
Optionally matches the "-------" marker line (group5).
365
384
366
385
6. ([\s\S]*?)(?:\n)?
367
-
Non‐greedy match for the “search content” (group6) up to the next marker.
386
+
Non‐greedy match for the "search content" (group6) up to the next marker.
368
387
369
388
7. (?:(?<=\n)(?<!\\)=======\s*\n)
370
-
Matches the “=======” marker on its own line.
389
+
Matches the "=======" marker on its own line.
371
390
372
391
8. ([\s\S]*?)(?:\n)?
373
-
Non‐greedy match for the “replace content” (group7).
392
+
Non‐greedy match for the "replace content" (group7).
374
393
375
394
9. (?:(?<=\n)(?<!\\)>>>>>>> REPLACE)(?=\n|$)
376
-
Matches the final “>>>>>>> REPLACE” marker on its own line (and requires a following newline or the end of file).
395
+
Matches the final ">>>>>>> REPLACE" marker on its own line (and requires a following newline or the end of file).
Copy file name to clipboardExpand all lines: src/core/prompts/sections/rules.ts
+3-2Lines changed: 3 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -8,7 +8,7 @@ function getEditingInstructions(diffStrategy?: DiffStrategy): string {
8
8
// Collect available editing tools
9
9
if(diffStrategy){
10
10
availableTools.push(
11
-
"apply_diff (for replacing lines in existing files)",
11
+
"apply_diff (for surgical edits - small, targeted changes to specific lines or functions)",
12
12
"write_to_file (for creating new files or complete file rewrites)",
13
13
)
14
14
}else{
@@ -34,7 +34,8 @@ function getEditingInstructions(diffStrategy?: DiffStrategy): string {
34
34
35
35
if(availableTools.length>1){
36
36
instructions.push(
37
-
"- 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.",
37
+
"- CRITICAL: Use apply_diff for small, surgical edits to existing files. Do NOT use apply_diff to rewrite entire files - use write_to_file for that purpose.",
38
+
"- You should always prefer using apply_diff, insert_content, or search_and_replace over write_to_file when making changes to existing files since write_to_file is much slower and cannot handle large files.",
0 commit comments