fix(edit): create new files when oldText is empty#63
Conversation
relaywash__Edit now accepts an empty oldText against a nonexistent path as a file creation request. Parent directories are created automatically. The Write block reason is updated to explain the recipe, and 6 new unit tests cover creation, nested dirs, batched create+edit, syntax rollback, and both error paths. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
📝 WalkthroughWalkthrough
ChangesEdit tool file creation
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
@copilot resolve the merge conflicts in this pull request |
There was a problem hiding this comment.
🧹 Nitpick comments (2)
crates/wash/src/tools/edit.rs (1)
15-15: ⚡ Quick winAlign the description text with actual batch behavior.
The description says “single edit”, but this implementation (and tests) supports “first edit creates, later edits continue in the same batch.” Wording this as “first edit” will avoid misleading clients.
Suggested wording tweak
-const DESCRIPTION: &str = "Batched multi-file edit with fuzzy matching and post-edit syntax check. Pass an array of edits and they apply atomically per-file. Whitespace and visually-equivalent Unicode differences in `oldText` are tolerated for matching only. To create a new file, pass a single edit with empty oldText and the full contents as newText."; +const DESCRIPTION: &str = "Batched multi-file edit with fuzzy matching and post-edit syntax check. Pass an array of edits and they apply atomically per-file. Whitespace and visually-equivalent Unicode differences in `oldText` are tolerated for matching only. To create a new file, make the first edit for that path use empty oldText and put full contents in newText.";🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@crates/wash/src/tools/edit.rs` at line 15, The DESCRIPTION constant in the edit.rs file describes the behavior for creating a new file using only "single edit" wording, but the actual implementation supports multiple edits in a batch where the first edit can create the file and subsequent edits continue within the same batch. Update the wording in the DESCRIPTION constant to replace "single edit" with "first edit" to accurately reflect that it is the first edit in a batch that creates a new file, not necessarily the only edit in the request.crates/wash/src/hooks/builtin_block.rs (1)
25-32: ⚡ Quick winAdd regression tests for the new
Write/NotebookEditreason branch.This new branch is behaviorally important and currently unpinned in the shown tests; please assert that both tools include the create-file guidance to prevent silent message drift.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@crates/wash/src/hooks/builtin_block.rs` around lines 25 - 32, Add regression tests that verify the conditional branch for "Write" and "NotebookEdit" tools in the reason formatting logic. The tests should explicitly assert that both the "Write" and "NotebookEdit" tools produce the longer reason message that includes the create-file guidance text "(create files by passing an edit with empty oldText)", while also verifying that other tools use the shorter message format without this guidance. This will prevent unintended silent drift in the message content for these behaviorally important tool cases.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@crates/wash/src/hooks/builtin_block.rs`:
- Around line 25-32: Add regression tests that verify the conditional branch for
"Write" and "NotebookEdit" tools in the reason formatting logic. The tests
should explicitly assert that both the "Write" and "NotebookEdit" tools produce
the longer reason message that includes the create-file guidance text "(create
files by passing an edit with empty oldText)", while also verifying that other
tools use the shorter message format without this guidance. This will prevent
unintended silent drift in the message content for these behaviorally important
tool cases.
In `@crates/wash/src/tools/edit.rs`:
- Line 15: The DESCRIPTION constant in the edit.rs file describes the behavior
for creating a new file using only "single edit" wording, but the actual
implementation supports multiple edits in a batch where the first edit can
create the file and subsequent edits continue within the same batch. Update the
wording in the DESCRIPTION constant to replace "single edit" with "first edit"
to accurately reflect that it is the first edit in a batch that creates a new
file, not necessarily the only edit in the request.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: e5dae408-5301-49f5-93f6-9fbffd9dccde
📒 Files selected for processing (4)
CHANGELOG.mdcrates/wash/src/hooks/builtin_block.rscrates/wash/src/tools/edit.rsmemory/workspace/.relay/state.json
Problem
relaywash blocks the built-in
Writetool and redirects agents torelaywash__Edit(builtin_block.rs:21) — but Edit hard-fails on nonexistent paths. An agent following the plugin's own guidance has no sanctioned way to create a file and must fall back to Bash heredocs, which the nudge hooks discourage and which bypass savings attribution.Fix
oldTextagainst a nonexistent path creates the file withnewTextas its contents (parent directories created as needed).oldText→"file does not exist (to create it, pass an edit with empty oldText)"; existing file + emptyoldText→"oldText must be non-empty for existing files".Write/NotebookEditblock message now teaches the recipe at the moment of redirect.input_schemais unchanged (no new properties — cache-stable); only the description string was extended.Tests
Six new unit tests in
edit.rs(create, nested dirs, create+edit batch, syntax-check rollback leaves no file, both error messages). Full suite: 167 unit + 5 integration tests pass, includingtools_list_is_byte_stable_across_profiles.Notes for review
cargo fmt --checkfails at main (~1900 diff lines, pre-existing); the files touched here are fmt-clean apart from one pre-existing import brace atedit.rs:6.Implements
plans/001-edit-create-file.mdfrom the 2026-06-10 codebase audit.🤖 Generated with Claude Code