fix(core): stop write tool from overwriting existing files with empty content#33091
Open
anisches wants to merge 2 commits into
Open
fix(core): stop write tool from overwriting existing files with empty content#33091anisches wants to merge 2 commits into
anisches wants to merge 2 commits into
Conversation
Contributor
|
Thanks for your contribution! This PR doesn't have a linked issue. All PRs must reference an existing issue. Please:
See CONTRIBUTING.md for details. |
Contributor
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
… content Move the empty-content check out of the schema and into the tool's execute step. Empty or whitespace-only content is now refused only when the target already exists with real content; creating a new empty file (e.g. __init__.py, .gitkeep) still works, and deleting via rm is unaffected. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
write tool from accepting empty strings and overwriting files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Issue for this PR
Closes #33078
Type of change
What does this PR do?
The
writetool would overwrite an existing file when the model passed empty (or whitespace-only) content, silently destroying the file. Nowwriterefuses that case when the file already has content, while still allowing empty new files (e.g.__init__.py,.gitkeep). Deleting a file is unaffected — that still goes throughrm.My first attempt just made the schema
NonEmptyString, but that also blocked creating empty files and missed whitespace-only content, so I moved the check into the tool's execute step instead.How did you verify your code works?
packages/core/test/tool-write.test.ts: creating a new empty file succeeds; overwriting a non-empty file with""or whitespace is refused and the original content is left intact.bun test packages/core/test/tool-write.test.tsandbun run typecheckpass.To reproduce: write
{ path: "existing.txt", content: "" }to a non-empty file — before, it wiped the file; now it returns an error and the file is untouched.Checklist