Skip to content

Commit dd7a9d3

Browse files
author
Eric Wheeler
committed
feat: add efficiency warning for single SEARCH/REPLACE blocks in apply_diff
When apply_diff is used with only one SEARCH/REPLACE block, models now receive a warning encouraging them to batch multiple related changes in a single operation for better LLM context efficiency. - Added single block detection by counting <<<<<<< SEARCH occurrences - Warning message promotes batching related changes for improved efficiency - Follows same pattern as read_file tool which warns for single file operations - Improves API usage patterns by encouraging consolidated changes Fixes: #6054 Signed-off-by: Eric Wheeler <[email protected]>
1 parent 2f4d833 commit dd7a9d3

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/core/tools/applyDiffTool.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,10 +188,17 @@ export async function applyDiffToolLegacy(
188188
// Get the formatted response message
189189
const message = await cline.diffViewProvider.pushToolWriteResult(cline, cline.cwd, !fileExists)
190190

191+
// Check for single SEARCH/REPLACE block warning
192+
const searchBlocks = (diffContent.match(/<<<<<<< SEARCH/g) || []).length
193+
const singleBlockWarning =
194+
searchBlocks === 1
195+
? "Making multiple related changes in a single apply_diff is more efficient for the LLM. If other changes are needed in this file, please include them as additional SEARCH/REPLACE blocks.\n\n"
196+
: ""
197+
191198
if (partFailHint) {
192199
pushToolResult(partFailHint + message)
193200
} else {
194-
pushToolResult(message)
201+
pushToolResult(singleBlockWarning + message)
195202
}
196203

197204
await cline.diffViewProvider.reset()

0 commit comments

Comments
 (0)