Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

KJ7LNW
Copy link
Collaborator

@KJ7LNW KJ7LNW commented Jul 22, 2025

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

  1. Use apply_diff with only one SEARCH/REPLACE block
  2. Verify that the warning message appears in the tool result
  3. Use apply_diff with multiple SEARCH/REPLACE blocks
  4. Verify that no warning appears for multi-block usage

Discord: KJ7LNW


Important

Adds a warning in applyDiffToolLegacy for single SEARCH/REPLACE blocks to encourage batching changes for efficiency.

  • Behavior:
    • Adds a warning in applyDiffToolLegacy in applyDiffTool.ts for single SEARCH/REPLACE blocks.
    • Encourages batching multiple related changes for efficiency.
    • Warning message: "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."
  • Implementation:
    • Counts SEARCH block occurrences in diffContent to detect single block usage.
    • Prepends warning to results if only one block is detected.

This description was created by Ellipsis for dd7a9d3. You can customize this summary. It will automatically update as commits are pushed.

…y_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 <roo-code@z.ewheeler.org>
@KJ7LNW KJ7LNW requested review from mrubens, cte and jr as code owners July 22, 2025 07:43
@hannesrudolph hannesrudolph added the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label Jul 22, 2025
@KJ7LNW KJ7LNW moved this from Triage to PR [Needs Prelim Review] in Roo Code Roadmap Jul 22, 2025
@hannesrudolph hannesrudolph added PR - Needs Preliminary Review and removed Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. labels Jul 22, 2025
@dosubot dosubot bot added size:XS This PR changes 0-9 lines, ignoring generated files. enhancement New feature or request labels Jul 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request PR - Needs Preliminary Review size:XS This PR changes 0-9 lines, ignoring generated files.
Projects
Status: PR [Needs Prelim Review]
Development

Successfully merging this pull request may close these issues.

2 participants