feat(word-addin): apply Proofread/Anonymise results to existing text as tracked redlines

↗ view on GitHub · Amalanand Muthukumaran · 2026-08-02 · 686f9cee

WHY THIS MATTERS
Until now the add-in could only make tracked changes in two narrow ways:
replacing a range the user had manually selected (Improve Writing), and
inserting brand-new paragraphs (Draft Clause / chat). Proofread and
Anonymise produced read-only prose: the user had to hunt down each issue
and retype the fix by hand. For a legal drafting tool, "the AI can see
the problem but cannot redline it" is the core missing feature - lawyers
work in tracked changes precisely so every machine-proposed edit stays
reviewable and rejectable.

WHAT IS A TRACKED REDLINE
Word's change tracking (the Review tab) records each edit as a pair of
marks - deleted text struck through, inserted text underlined - that the
reviewing lawyer can accept or reject individually. Programmatically,
Office.js exposes this via document.changeTrackingMode: any edit made
while the mode is TrackAll is recorded as if a human typed it.

HOW IT WORKS
1. The Proofread and Anonymise prompts now mandate a machine-readable
   block format (shared constant REDLINE_FORMAT):
       ORIGINAL: <verbatim snippet from the document>
       REPLACEMENT: <corrected / anonymised text>
       REASON: <one short sentence>
   The format is deliberately dual-purpose: it reads naturally while it
   streams into the result box, and it parses exactly once the stream
   completes (lib/redline.ts, tolerant of list numbering and bold).
2. A new useWordDoc.applyTrackedEdits() locates each ORIGINAL with
   Word's search API (case-sensitive, every occurrence) and replaces it
   via insertText(..., Replace) while changeTrackingMode is TrackAll,
   restoring the user's previous tracking mode afterwards.
3. Honesty over guessing: originals that are unsearchable (multi-
   paragraph, or over Word's ~255-char search limit) or no longer
   present (the user edited the document mid-stream) are counted and
   reported - "Applied 2 of 3 ... 1 skipped" - never fuzzily matched,
   because a wrong redline in a contract is worse than no redline.
4. Edits are parsed only after a clean stream finish (never mid-stream,
   which could apply a half-received replacement) and duplicate
   ORIGINALs are deduped, since the second application would fail its
   search after the first replacement already rewrote the text.

TESTING
Four new hermetic Playwright specs against the in-page Office.js shim:
tracked application of parsed corrections (asserting the exact recorded
Word calls and TrackAll mode), skip-and-report for stale text, no apply
button on "No issues found.", and tracked PII redaction. Suite: 61/61.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Repository open-legal-products/mike
Author Amalanand Muthukumaran <mamalanand3@gmail.com>
Authored
Committed
Parents 3f490983
Stats 5 files changed , +362 , -9
Part of Add a Word add-in for chat and tracked rewrites

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-686f9cee.md from inside the repo you want the change in.

⬇ Download capture-commit-686f9cee.md