From 25857a4809c81a91b39e734ce63dd98fcb441ffe Mon Sep 17 00:00:00 2001 From: KJ7LNW <93454819+KJ7LNW@users.noreply.github.com> Date: Thu, 24 Jul 2025 21:40:43 -0700 Subject: [PATCH] feat: add efficiency warning for single SEARCH/REPLACE blocks in apply_diff (#6055) Co-authored-by: Eric Wheeler Co-authored-by: Daniel Riccio --- src/core/tools/applyDiffTool.ts | 11 +++++++++-- src/core/tools/multiApplyDiffTool.ts | 16 +++++++++++++++- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/core/tools/applyDiffTool.ts b/src/core/tools/applyDiffTool.ts index ad4bb0590f..f046ba67d2 100644 --- a/src/core/tools/applyDiffTool.ts +++ b/src/core/tools/applyDiffTool.ts @@ -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 + ? "\nMaking 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." + : "" + if (partFailHint) { - pushToolResult(partFailHint + message) + pushToolResult(partFailHint + message + singleBlockNotice) } else { - pushToolResult(message) + pushToolResult(message + singleBlockNotice) } await cline.diffViewProvider.reset() diff --git a/src/core/tools/multiApplyDiffTool.ts b/src/core/tools/multiApplyDiffTool.ts index 4ddef4880b..ec8c77a63b 100644 --- a/src/core/tools/multiApplyDiffTool.ts +++ b/src/core/tools/multiApplyDiffTool.ts @@ -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 + ? "\nMaking 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." + : "" + // 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)