Skip to content

Conversation

@hannesrudolph
Copy link
Collaborator

@hannesrudolph hannesrudolph commented Dec 15, 2025

Summary

Adds support for multi-file apply_diff batching when using native protocol (OpenAI-style function calling), controlled by the MULTI_FILE_APPLY_DIFF experiment flag.

Problem

The apply_diff tool currently only supports multi-file batching with XML protocol. When native protocol is enabled, it bypasses multi-file logic and uses single-file ApplyDiffTool only.

Solution

Two separate schemas are swapped based on the MULTI_FILE_APPLY_DIFF experiment flag:

  • Single-file schema (apply_diff.ts): { path: string, diff: string }
  • Multi-file schema (multi_apply_diff.ts): { files: [{ path, diff }] }

A factory function createApplyDiffTool(multiFileEnabled) selects the appropriate schema.

Files Modified

  1. src/core/prompts/tools/native-tools/multi_apply_diff.ts - NEW: Multi-file schema definition
  2. src/core/prompts/tools/native-tools/apply_diff.ts - Added factory function
  3. src/core/prompts/tools/native-tools/index.ts - Updated getNativeTools() to accept experiment flag
  4. src/core/task/build-tools.ts - Pass experiment flag to getNativeTools()
  5. src/shared/tools.ts - Updated NativeToolArgs.apply_diff to union type
  6. src/core/assistant-message/NativeToolCallParser.ts - Handle both formats in parsing
  7. src/core/assistant-message/presentAssistantMessage.ts - Routing based on nativeArgs format
  8. src/core/tools/MultiApplyDiffTool.ts - Handle nativeArgs.files format

Test Coverage

  • 8 new tests added to NativeToolCallParser.spec.ts for both native formats
  • Updated applyDiffTool.experiment.spec.ts to reflect new routing architecture

Testing

All 4,728 tests pass.


Important

Adds multi-file apply_diff support for native protocol with schema selection and routing based on nativeArgs, controlled by an experiment flag.

  • Behavior:
    • Adds multi-file apply_diff support for native protocol, controlled by MULTI_FILE_APPLY_DIFF flag.
    • Uses createApplyDiffTool() to select between single-file and multi-file schemas.
    • Updates presentAssistantMessage() to route based on nativeArgs format.
  • Schemas:
    • Defines multi-file schema in multi_apply_diff.ts.
    • Updates apply_diff.ts to include factory function for schema selection.
  • Files Modified:
    • NativeToolCallParser.ts: Parses both single-file and multi-file formats.
    • build-tools.ts: Passes experiment flag to getNativeTools().
    • validateToolUse.ts: Validates file restrictions for both formats.
  • Tests:
    • Adds tests in NativeToolCallParser.spec.ts for both formats.
    • Updates applyDiffTool.experiment.spec.ts for new routing logic.
  • Misc:
    • Updates NativeToolArgs.apply_diff to a union type in tools.ts.

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

- Create multi_apply_diff.ts schema with files array parameter
- Add createApplyDiffTool factory function to swap schemas based on experiment flag
- Update getNativeTools to accept multiFileApplyDiffEnabled parameter
- Update NativeToolCallParser to handle both single-file and multi-file formats
- Update presentAssistantMessage to route based on nativeArgs format
- Update MultiApplyDiffTool to handle nativeArgs.files array
- Update NativeToolArgs type to union type supporting both formats
- Add 8 tests for apply_diff parsing in both formats
@dosubot dosubot bot added size:XL This PR changes 500-999 lines, ignoring generated files. Enhancement New feature or request labels Dec 15, 2025
@roomote
Copy link
Contributor

roomote bot commented Dec 15, 2025

Oroocle Clock   See task on Roo Cloud

Re-review complete. Native multi-file apply_diff now enforces mode fileRegex restrictions.

  • Ensure multi-file native apply_diff (nativeArgs.files) cannot bypass mode fileRegex restrictions; validate each file path in nativeArgs during tool validation or normalize params before validation.
Previous reviews

Mention @roomote in a comment to request specific changes to this pull request or fix all unresolved issues.

@hannesrudolph hannesrudolph added the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label Dec 15, 2025
| { path: string; diff: string }
| undefined

if (nativeArgs && "files" in nativeArgs && Array.isArray(nativeArgs.files)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In native mode, multi-file apply_diff routes via nativeArgs.files, but the mode fileRegex restrictions are currently enforced via validateToolUse(block.params). Since params may not include a single path (and validateToolUse does not parse the JSON-encoded params.files), this can bypass file restrictions for multi-file native apply_diff. Consider validating each entry in nativeArgs.files (or passing a normalized {path/args} into validation) before dispatching to MultiApplyDiffTool.

Fix it with Roo Code or mention @roomote and request a fix.

…pply_diff

Addresses review feedback to ensure multi-file native apply_diff (nativeArgs.files)
cannot bypass mode fileRegex restrictions.

Changes:
- Added nativeArgs parameter to validateToolUse and isToolAllowedForMode
- Added validation for nativeArgs.files (multi-file format) paths
- Added validation for nativeArgs.path (single-file format) paths
- Pass block.nativeArgs to validateToolUse in presentAssistantMessage
- Added comprehensive test coverage for native protocol file restrictions
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:XL This PR changes 500-999 lines, ignoring generated files.

Projects

Status: Triage

Development

Successfully merging this pull request may close these issues.

1 participant