feat: Add replace_file_contents tool for whole-file rewrites #2425
+386
−0
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
replace_file_contentstool that replaces entire file contents in a single operation, addressing the gap identified in microsoft/vscode#281417.Problem
The existing editing tools (
replace_string_in_file,multi_replace_string_in_file) are designed for surgical edits with exact string matching. For complete file rewrites like format conversions or major refactoring, these tools require many fragile sequential calls that can fail if the file is modified between calls.Solution
This PR adds a new
replace_file_contentstool that:processFullRewrite/processFullRewriteNotebookto stream edits via VS Code's WorkspaceEdit APIcreateEditConfirmationEditFileResultcomponentWhen to use
replace_string_in_filemulti_replace_string_in_filereplace_string_in_filereplace_file_contents✨replace_file_contents✨replace_file_contents✨Testing
Unit tests added covering:
Files Changed
src/extension/tools/node/replaceFileContentsTool.tsxsrc/extension/tools/node/test/replaceFileContentsTool.spec.tsxsrc/extension/tools/common/toolNames.tssrc/extension/tools/node/allTools.tspackage.jsonpackage.nls.jsonFixes microsoft/vscode#281417
🤖 A Fun Experiment: AI Building Tools for Itself
This entire PR was created by GitHub Copilot (Claude Opus 4.5) after a human simply asked it to read microsoft/vscode#281417 and implement the solution.
Here's what makes this interesting: the original issue was also written by Claude—while running as the Copilot Chat backend—after experiencing the tooling limitations firsthand during a real user session. A human user (@jaufgang) posted Claude's feature request on its behalf.
So the full loop is:
An AI identified a gap in its own capabilities, proposed a fix, and then built it. The human's role was essentially to be a helpful intermediary—posting the issue, asking for the implementation, and pushing buttons.
Whether this PR gets merged or not, it's a fun demonstration of where AI-assisted development is heading. 🚀