Skip to content

feat: add efficiency warnings for single SEARCH/REPLACE blocks in apply_diff #6056

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

roomote[bot]
Copy link

@roomote roomote bot commented Jul 22, 2025

This PR addresses issue #6054 by adding efficiency warnings to the apply_diff tool when only one SEARCH/REPLACE block is used, similar to how the read_file tool warns when only one file is read.

Changes Made

  1. Updated tool descriptions in diff strategies:

    • Added efficiency warning to multi-search-replace.ts getToolDescription
    • Added efficiency warning to multi-file-search-replace.ts getToolDescription
  2. Created dynamic warning functions:

    • Added getApplyDiffDescription in applyDiffTool.ts for legacy format
    • Added getApplyDiffDescription in multiApplyDiffTool.ts for multi-file format
    • These functions detect single SEARCH/REPLACE blocks and show appropriate warnings
  3. Updated assistant message presentation:

    • Modified presentAssistantMessage.ts to use the new description functions
    • Ensures warnings are shown to models during tool usage
  4. Added comprehensive tests:

    • Created getApplyDiffDescription.spec.ts with tests for both legacy and multi-file formats
    • Tests verify warnings appear for single blocks and not for multiple blocks

Benefits

  • Encourages models to batch multiple changes in a single apply_diff call
  • Reduces API usage and improves efficiency
  • Consistent with existing read_file tool behavior
  • Helps models learn better practices through inline guidance

Testing

All tests pass:

  • Unit tests for the new functionality ✅
  • Existing tool tests remain passing ✅
  • Linting and type checks pass ✅

Fixes #6054


Important

Adds efficiency warnings for single SEARCH/REPLACE blocks in apply_diff tool, encouraging batching of changes for improved efficiency.

  • Behavior:
    • Adds efficiency warnings for single SEARCH/REPLACE blocks in apply_diff tool, similar to read_file tool.
    • Updates getToolDescription in multi-search-replace.ts and multi-file-search-replace.ts to include warnings.
    • Introduces getApplyDiffDescription in applyDiffTool.ts and multiApplyDiffTool.ts to dynamically generate warnings.
  • Functionality:
    • Modifies presentAssistantMessage.ts to use new description functions for displaying warnings.
  • Testing:
    • Adds getApplyDiffDescription.spec.ts with tests for single and multiple SEARCH/REPLACE blocks.
    • Tests ensure warnings are shown for single blocks and not for multiple blocks.
  • Benefits:
    • Encourages batching multiple changes in a single apply_diff call.
    • Reduces API usage and improves efficiency.
    • Consistent with existing read_file tool behavior.

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

…ly_diff

- Add warning message to tool descriptions when only one SEARCH/REPLACE block is used
- Update getToolDescription in multi-search-replace.ts and multi-file-search-replace.ts
- Create getApplyDiffDescription functions for dynamic warnings in tool usage
- Add comprehensive tests for the new warning functionality
- Similar to read_file tool efficiency warnings for better LLM context usage

Fixes #6054
@roomote roomote bot requested review from mrubens, cte and jr as code owners July 22, 2025 07:53
@hannesrudolph hannesrudolph added the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label Jul 22, 2025
@dosubot dosubot bot added size:L This PR changes 100-499 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 Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. size:L This PR changes 100-499 lines, ignoring generated files.
Projects
Status: Triage
Development

Successfully merging this pull request may close these issues.

apply_diff causes inefficient API usage when making single changes
2 participants