Editing tools
Disabled in M11. Kept for reference.
write_file,edit_file, anddelete_fileare not registered; the shell is the editing interface. The code below still runs behind theedit-toolsCargo feature. Because a shell command is opaque, no automatic baseline or checkpoint is recorded:git diffis the verification and git is the undo. See shell-tool.md, checkpoints.md, and feature-switches.md.
This page settles D5 and defines the three write tools. It is the design for F4.1 in the roadmap. The session baseline those writes record is checkpoints.md. Path rules are in read-tools.md. The approval card the loop already shows is in chat-ui.md.
What this page does not cover
| Topic | Where it belongs |
|---|---|
| Putting a hunk back, and the review window | docs/src/design/review/code-review.md (M6) |
| The shell sandbox | docs/src/design/tools/shell-tool.md (M4) |
| A saved allow for the rest of the session | grant, in read-tools.md |
Refusing a compressed shell marker in old_string, new_string, or content | shell-output.md |
Problem
The model has to change files, and a wrong change has to be visible and
reversible. A unified diff the model authors looks like a review, but it
applies to the wrong place when the file has drifted, and models emit
malformed patches. A fuzzy match has the same failure in a quieter form: the
write succeeds when old_string was not the bytes in the file.
Decision
Three tools, write_file, edit_file, and delete_file, live in
crates/robi/src/agent/tools/. Each call resolves its path the same way a read
does. All three are Exclusive.
The model edits with exact text. edit_file replaces old_string with new_string. It
does not accept a patch. write_file creates a file or replaces its whole
body. delete_file removes one file. After a successful change, the tool
returns a file diff of that change: the workspace-relative path, a unified
patch, additions, deletions, and added, deleted, or modified. The
patch tells the model what landed. It is not the edit instruction.
old_string is matched exactly, after the model’s \n is converted to the file’s
line ending (\n or \r\n). A UTF-8 BOM already on the file is kept.
replace_all defaults to false. Set, it replaces every exact match. Unset,
more than one match is an error. old_string and new_string must differ. An empty old_string
is an error that names write_file.
A path allows_write accepts runs immediately. A path the filter denies
returns NeedsApproval. That includes a built-in deny such as .env or
.git, and a path outside the workspace. The loop pauses and the existing
approval card shows Write or Delete with the path. A pending edit_file
shows the same diff card as a finished edit, from old_string and new_string, with the
same line cap. Approval is for
this call. It does not append an allow rule. The next write to that path
asks again. A lasting exception stays on grant.
execute does not receive the decision. The loop calls it only after
approval, or immediately when the filter allows the path. The write then
proceeds even though the filter still denies the path. Every other check
still applies. An argument that does not parse, or a path that does not
resolve, returns AllowImmediately so execute reports the error and the
user is not prompted.
A process-wide lock, keyed by the canonical path, is held for the whole read-modify-write. The session actor already serializes one session. The lock covers two sessions editing one file. The bytes are written to a temporary file in the same directory, then renamed.
| Tool | Arguments | Behavior |
|---|---|---|
write_file | path, content | Create the file, or replace its whole body. Parent directories under the resolved path are created |
edit_file | path, old_string, new_string, optional replace_all | Replace one exact occurrence, or every occurrence when replace_all is true |
delete_file | path | Remove one file. A directory is refused. Parent directories stay |
Rejected alternatives
- A unified diff as the edit instruction. The review preview is computed from the session baseline. The model does not have to author it. A patch applies to the wrong place when the context has drifted.
- Fuzzy replacement. Trimmed lines, folded whitespace, flexible
indentation, and similarity scoring all succeed when
old_stringwas not the bytes in the file. A miss stays an error. When the text matches only after trimming each line, the error says so. - One tool that both creates and edits. An empty
old_stringis how a model accidentally overwrites a file. Creation and full replacement arewrite_file. - Refusing a denied path with no prompt. The user can allow one write
without saving a session rule.
grantremains the way to keep the path allowed. - Saving an allow when the user approves a write. That would make one
approval a lasting exception. The next call asks again unless the model
calls
grant.
Failure modes
- An argument object that does not parse names the keys it received and any
required keys that were absent. The values stay out of the message. Every
tool uses that parser. For
edit_filethe required keys arepath,old_string, andnew_string. An emptynew_stringis a deletion and is valid; omitting the key is not. old_stringandnew_stringare identical:old_string and new_string are identical.old_stringis empty:old_string is empty; use write_file to create or replace the file.old_stringmatches nothing:old_string was not found, and a second sentence when the text matches only after trimming each line.old_stringmatches more than once andreplace_allis false:old_string matched N times.- A missing file on
edit_fileordelete_fileisfile not found. A directory ispath is a directory. A non-UTF-8 file isfile is not utf-8. - A path that resolves fails before any write, with the argument the model
passed.
$HOMEunset makes a~/argument fail the same way. - Cancellation before the read returns
cancelledand does not write. - Rejecting the approval card does not call
execute. The file stays as it was.