Expand description
patch — an edit, not a rewrite.
write_file replaces a whole file, which is fine for a file the agent is creating and a bad
idea for one it is changing: the model has to reproduce every untouched line from memory, so
a 200-line file with a one-line change costs 200 lines of output and carries 200 chances to
drop something. patch takes the text to replace and the text to put there instead, and
writes back only if it found exactly one place that matches.
Two rules make it safe to hand a model:
- Ambiguity is an error, not a guess. If the old text appears twice the call fails and
says where.
replace_allis the caller saying it meant every one; nothing does that implicitly. - The file is written only when a match was found. A patch that cannot find its text leaves the file exactly as it was, so there is no half-applied edit to recover from.
The one relaxation: when the text is not found verbatim it is looked for line by line with indentation and trailing spaces ignored, because a model re-indenting a block it quoted from a read is the commonest near miss. The text that lands in the file is the caller’s own, and the result says the match was relaxed — a wrong-but-similar edit should be visible, not silent.
[hits] and [splice] are pub(crate) because skill_manage patch is the same operation
over a skill’s file: one matcher, so the two tools cannot end up forgiving different things.