feat: add efficiency warning for single SEARCH/REPLACE blocks in apply_diff #6055
+8
−1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Context
The apply_diff tool was missing efficiency guidance similar to what the read_file tool provides. When models use only one SEARCH/REPLACE block, they miss opportunities to batch multiple related changes in a single operation, leading to inefficient API usage patterns.
Implementation
Added single block detection by counting
<<<<<<< SEARCH
occurrences in the diff content. When only one block is detected, the tool now includes a warning message encouraging models to batch multiple related changes for better efficiency.The warning message is prepended to successful results: "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."
This follows the same pattern established by the read_file tool, which warns models when only one file is read to encourage reading multiple files simultaneously for better LLM context efficiency.
How to Test
Discord: KJ7LNW
Important
Adds a warning in
applyDiffToolLegacy
for singleSEARCH/REPLACE
blocks to encourage batching changes for efficiency.applyDiffToolLegacy
inapplyDiffTool.ts
for singleSEARCH/REPLACE
blocks.SEARCH
block occurrences indiffContent
to detect single block usage.This description was created by
for dd7a9d3. You can customize this summary. It will automatically update as commits are pushed.