Skip to main content

Module ctx_patch

Module ctx_patch 

Source
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. 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§

PatchParams
Parameters for an anchored patch: the target file and one or more anchored edit ops, plus optional guards/evidence (mirrors EditParams where it makes sense so the registered wrapper stays uniform).

Enums§

AnchorOp
A single anchored edit. new_text="" deletes (readseek convention); a multi-line new_text expands 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 or ops[]).
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 CONFLICT is a failure signal (the view the model edited against had drifted) that arms a one-shot escalation of the next auto read to anchored — 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 CacheEffect for the caller to apply. last_mode is currently only used by record_outcome; pass "" when unknown.