From dd7a9d352ef09e6883405769f65c5f34d512302c Mon Sep 17 00:00:00 2001 From: Eric Wheeler Date: Tue, 22 Jul 2025 00:41:23 -0700 Subject: [PATCH 1/2] 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 --- src/core/tools/applyDiffTool.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/core/tools/applyDiffTool.ts b/src/core/tools/applyDiffTool.ts index f5b4ab7dd3d..cbad06ea340 100644 --- a/src/core/tools/applyDiffTool.ts +++ b/src/core/tools/applyDiffTool.ts @@ -188,10 +188,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 singleBlockWarning = + searchBlocks === 1 + ? "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" + : "" + if (partFailHint) { pushToolResult(partFailHint + message) } else { - pushToolResult(message) + pushToolResult(singleBlockWarning + message) } await cline.diffViewProvider.reset() From 1d799eafdd27f91e6edc85cedaf3470280778be1 Mon Sep 17 00:00:00 2001 From: Daniel Riccio Date: Thu, 24 Jul 2025 15:57:39 -0500 Subject: [PATCH 2/2] refactor: move single block warning to notice section and make more concise - Move warning from prepended text to notice tag format - Remove 'for the LLM' phrase to make message more concise - Add same warning logic to multiApplyDiffTool for consistency - Warning now appears as a notice after the main result message --- src/core/tools/applyDiffTool.ts | 8 ++++---- src/core/tools/multiApplyDiffTool.ts | 16 +++++++++++++++- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/core/tools/applyDiffTool.ts b/src/core/tools/applyDiffTool.ts index cbad06ea340..41b0d77559d 100644 --- a/src/core/tools/applyDiffTool.ts +++ b/src/core/tools/applyDiffTool.ts @@ -190,15 +190,15 @@ export async function applyDiffToolLegacy( // Check for single SEARCH/REPLACE block warning const searchBlocks = (diffContent.match(/<<<<<<< SEARCH/g) || []).length - const singleBlockWarning = + const singleBlockNotice = searchBlocks === 1 - ? "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" + ? "\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(singleBlockWarning + message) + pushToolResult(message + singleBlockNotice) } await cline.diffViewProvider.reset() diff --git a/src/core/tools/multiApplyDiffTool.ts b/src/core/tools/multiApplyDiffTool.ts index 8057f779495..d679eac3321 100644 --- a/src/core/tools/multiApplyDiffTool.ts +++ b/src/core/tools/multiApplyDiffTool.ts @@ -596,8 +596,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)