feat: add efficiency warning for single SEARCH/REPLACE blocks in apply_diff (#6055)

Co-authored-by: Eric Wheeler <roo-code@z.ewheeler.org>
Co-authored-by: Daniel Riccio <ricciodaniel98@gmail.com>
This commit is contained in:
KJ7LNW 2025-07-24 21:40:43 -07:00 committed by GitHub
parent 02118c5e7f
commit 25857a4809
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 24 additions and 3 deletions

View file

@ -193,10 +193,17 @@ export async function applyDiffToolLegacy(
// Get the formatted response message
const message = await cline.diffViewProvider.pushToolWriteResult(cline, cline.cwd, !fileExists)
// Check for single SEARCH/REPLACE block warning
const searchBlocks = (diffContent.match(/<<<<<<< SEARCH/g) || []).length
const singleBlockNotice =
searchBlocks === 1
? "\n<notice>Making multiple related changes in a single apply_diff is more efficient. If other changes are needed in this file, please include them as additional SEARCH/REPLACE blocks.</notice>"
: ""
if (partFailHint) {
pushToolResult(partFailHint + message)
pushToolResult(partFailHint + message + singleBlockNotice)
} else {
pushToolResult(message)
pushToolResult(message + singleBlockNotice)
}
await cline.diffViewProvider.reset()

View file

@ -601,8 +601,22 @@ ${errorDetails ? `\nTechnical details:\n${errorDetails}\n` : ""}
await cline.say("diff_error", allDiffErrors.join("\n"))
}
// Check for single SEARCH/REPLACE block warning
let totalSearchBlocks = 0
for (const operation of operations) {
for (const diffItem of operation.diff) {
const searchBlocks = (diffItem.content.match(/<<<<<<< SEARCH/g) || []).length
totalSearchBlocks += searchBlocks
}
}
const singleBlockNotice =
totalSearchBlocks === 1
? "\n<notice>Making multiple related changes in a single apply_diff is more efficient. If other changes are needed in this file, please include them as additional SEARCH/REPLACE blocks.</notice>"
: ""
// Push the final result combining all operation results
pushToolResult(results.join("\n\n"))
pushToolResult(results.join("\n\n") + singleBlockNotice)
return
} catch (error) {
await handleError("applying diff", error)