Expand description
ctx_patch — hash-anchored editing (epic #1008).
“Edit by reference, not by reproduction”: the model edits lines by their
(line, hash) anchor (from ctx_read(mode="anchored")) instead of quoting
the old text byte-for-byte. Each anchor is verified against the current
file; on drift the edit is rejected with fresh anchors — except a
single-line anchor (set_line/insert_after) whose content moved intact
to exactly one other line (e.g. an earlier, separate edit shifted it):
that’s resolved automatically rather than failing (#812). Multiple edits
in one call are batch-atomic — all validated against the same
preimage and applied all-or-nothing, bottom-up.
Reuses the exact ctx_edit I/O boundary (crate::tools::edit_io):
TOCTOU preimage guard, permission-preserving atomic write, read-only-roots
deny, symlink rejection. ctx_edit (str_replace) stays as the fallback.
Structs§
- Patch
Params - Parameters for an anchored patch: the target file and one or more anchored
edit ops, plus optional guards/evidence (mirrors
EditParamswhere it makes sense so the registered wrapper stays uniform).
Enums§
- Anchor
Op - A single anchored edit.
new_text=""deletes (readseek convention); a multi-linenew_textexpands one anchor into several lines.
Functions§
- handle
- Apply an anchored patch and the resulting cache effect in one shot (tests and in-process callers that hold the cache exclusively).
- parse_
ops - Parse the raw tool arguments into
AnchorOps (single op orops[]). - record_
outcome - Quality loop (#494/#1008): a clean anchored edit is a success signal for the
read mode that produced the anchors; a stale-anchor
CONFLICTis a failure signal (the view the model edited against had drifted) that arms a one-shot escalation of the next auto read toanchored— fresh line anchors to retry by reference. Structural errors say nothing about the read mode and are skipped. - run_io
- Perform the anchored patch on disk without touching the cache; returns
the
CacheEffectfor the caller to apply.last_modeis currently only used byrecord_outcome; pass""when unknown.