A failed edit anchor answers in the document's own words
A missed anchor was the most expensive event in a drafting turn: the model
was told "Could not locate find=..., re-read the document" and could only
guess again at the same wording. Aider's harness measures this directly --
removing flexible hunk application and its "did you mean these actual
lines?" reports cost them a 9x increase in editing errors -- and our
matcher already had the flexible half (four-stage context cascade, smart
quote and whitespace normalization) without the teaching half.
applyTrackedEdits now diagnoses every miss against the document:
ambiguous -> the real context_before / context_after at each of up to
three occurrence sites, verbatim, so the retry is a copy
rather than a guess
divergent -> the longest matching prefix AND suffix, found by binary
search over a seed-shortlisted set of paragraphs, quoted
with the document's actual wording spanning the point the
quote stops matching (this is what catches "5:00 pm" vs
"5:00 p.m." and "The Buyer" vs "The Purchaser")
applied -> replacement text already present, find absent: typed as an
edit that looks already applied rather than a mystery miss
absent -> names the parts tracked-change editing cannot reach
(header, footer, footnote, text box)
The probes are bounded so diagnosis runs unconditionally: occurrence
counting stops at 20, the divergence probe seeds on the same 12 characters
that are already the reportability threshold and binary-searches at most 8
candidate paragraphs per side, so it costs a couple of passes over the
document rather than a similarity scan of every paragraph.
One matcher serves the production edit path, the local library path and
docxTextOps, so all three surfaces improve together. runEditDocument now
reports every failed edit's diagnosis instead of only the first, matching
how docxFieldValues already batches its complaints.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018bhP89cYSdEEjHNPnxacns
| Repository | eliziff/Beaver |
|---|---|
| Author | Eli Ziff <eliasziff@gmail.com> |
| Authored | |
| Parents | 453c14eb |
| Stats | 3 files changed , +287 , -12 |
| Part of | Deterministic legal-text tools ("SLA audit organs") |
Capture this commit into my fork
Download a Markdown prompt that tells Claude how to port this
exact commit into your working tree. Run it via
claude -p < capture-commit-dc862033.md
from inside the repo you want the change in.