Expand description
edit tool — per-model edit-format selection (#2068).
Why: Agents that iteratively refine code need a surgical replace-in-place
primitive that is safer than re-writing the whole file from memory. Before
#2068 the only supported wire format was exact-unique SEARCH/REPLACE,
mirroring the Claude Code Edit tool contract. Aider’s A/B data shows edit
success rate varies by model family and format (see
tools::fs::edit_format’s module docs for the matrix): some models
reliably reproduce an exact substring, others do much better with a
unified diff or a full-file rewrite. EditTool now accepts any of the
three formats in one call and applies them in the calling model’s
preferred order via edit_format::select_and_apply.
What: EditTool reads the file, builds an EditPayload for each format
present in the tool-call arguments (old_string+new_string, diff, or
content), and delegates to edit_format::select_and_apply to pick and
apply the best-fit format, then writes the result back. All paths are
scoped to the working directory.
Test: See #[cfg(test)] below — covers each format, zero/ambiguous
SEARCH/REPLACE errors, malformed-diff errors, and path traversal.
Structs§
- Edit
Tool ToolExecutorthat applies an edit using whichever wire format(s) the caller supplied, in the calling model’s preferred order.