Skip to content

Conversation

@hannesrudolph
Copy link
Collaborator

@hannesrudolph hannesrudolph commented Dec 10, 2025

Summary

Implements a new edit_file tool that provides a simple and intuitive interface for file editing operations, based on the gemini-cli's replace tool pattern. This tool supports both modifying existing files through literal string replacement and creating new files.

Changes

  • Add edit_file to toolNames in packages/types/src/tool.ts
  • Add tool type definitions to src/shared/tools.ts (NativeToolArgs, TOOL_DISPLAY_NAMES, TOOL_GROUPS)
  • Create src/core/prompts/tools/native-tools/edit_file.ts - OpenAI function calling schema
  • Create src/core/tools/EditFileTool.ts - Full implementation with:
    • countOccurrences() - Count non-overlapping substring matches
    • safeLiteralReplace() - Handles $ escape sequences properly
    • applyReplacement() - Core replacement logic supporting new file creation
    • File creation when old_string is empty and file doesn't exist
    • Occurrence count validation against expected_replacements parameter
    • Line ending normalization (CRLF → LF)
    • Integration with DiffViewProvider, checkpoints, and approval flow
  • Register tool in src/core/prompts/tools/native-tools/index.ts
  • Add partial streaming and final parsing support in src/core/assistant-message/NativeToolCallParser.ts
  • Add handler case in src/core/assistant-message/presentAssistantMessage.ts
  • Create comprehensive test suite (22 tests) in src/core/tools/__tests__/editFileTool.spec.ts

Key Features

  • Empty old_string creates new file with new_string as content
  • Line ending normalization (CRLF → LF)
  • Multiple replacements via expected_replacements parameter
  • No-op detection (fails if old_string equals new_string or content unchanged)
  • Safe literal replacement handling $ escape sequences
  • Validation of occurrence count against expected_replacements

Important

Introduces edit_file tool for file editing, supporting string replacement and new file creation, with comprehensive testing and integration.

  • Behavior:
    • Adds edit_file tool for file editing, supporting string replacement and new file creation.
    • Handles $ escape sequences, line ending normalization, and occurrence count validation.
    • Integrated with DiffViewProvider, checkpoints, and approval flow.
  • Implementation:
    • Adds edit_file to toolNames in tool.ts.
    • Implements EditFileTool in EditFileTool.ts with functions like countOccurrences() and safeLiteralReplace().
    • Registers tool in index.ts and presentAssistantMessage.ts.
  • Testing:
    • Comprehensive test suite in editFileTool.spec.ts with 22 tests covering various scenarios.

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

Implements a new edit_file tool based on gemini-cli's replace tool pattern:
- Literal string replacement with expected_replacements validation
- File creation when old_string is empty and file doesn't exist
- Safe $ escape handling in replacement strings
- CRLF to LF normalization
- Comprehensive test coverage (22 tests)
@dosubot dosubot bot added size:XL This PR changes 500-999 lines, ignoring generated files. Enhancement New feature or request labels Dec 10, 2025
@roomote
Copy link
Contributor

roomote bot commented Dec 10, 2025

Oroocle Clock   Follow along on Roo Cloud

Reviewing your PR now. Feedback will be posted shortly!

- Remove unreachable check for new_string === undefined (always a string
  due to parseLegacy coercion and native parser requirements)
- Simplify applyReplacement function by combining unreachable code path
  with existing empty oldString check
@hannesrudolph hannesrudolph added the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label Dec 10, 2025
@hannesrudolph hannesrudolph marked this pull request as draft December 11, 2025 23:56
@hannesrudolph hannesrudolph moved this from Triage to PR [Draft / In Progress] in Roo Code Roadmap Dec 12, 2025
@hannesrudolph hannesrudolph added PR - Draft / In Progress and removed Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. labels Dec 12, 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 - Draft / In Progress size:XL This PR changes 500-999 lines, ignoring generated files.

Projects

Status: PR [Draft / In Progress]

Development

Successfully merging this pull request may close these issues.

2 participants