feat: add edit_file tool for search/replace file editing #9983
+951
−4
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.
Summary
Implements a new
edit_filetool 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
edit_filetotoolNamesinpackages/types/src/tool.tssrc/shared/tools.ts(NativeToolArgs, TOOL_DISPLAY_NAMES, TOOL_GROUPS)src/core/prompts/tools/native-tools/edit_file.ts- OpenAI function calling schemasrc/core/tools/EditFileTool.ts- Full implementation with:countOccurrences()- Count non-overlapping substring matchessafeLiteralReplace()- Handles $ escape sequences properlyapplyReplacement()- Core replacement logic supporting new file creationold_stringis empty and file doesn't existexpected_replacementsparametersrc/core/prompts/tools/native-tools/index.tssrc/core/assistant-message/NativeToolCallParser.tssrc/core/assistant-message/presentAssistantMessage.tssrc/core/tools/__tests__/editFileTool.spec.tsKey Features
old_stringcreates new file withnew_stringas contentexpected_replacementsparameterImportant
Introduces
edit_filetool for file editing, supporting string replacement and new file creation, with comprehensive testing and integration.edit_filetool for file editing, supporting string replacement and new file creation.DiffViewProvider, checkpoints, and approval flow.edit_filetotoolNamesintool.ts.EditFileToolinEditFileTool.tswith functions likecountOccurrences()andsafeLiteralReplace().index.tsandpresentAssistantMessage.ts.editFileTool.spec.tswith 22 tests covering various scenarios.This description was created by
for 33188bc. You can customize this summary. It will automatically update as commits are pushed.