Redline-aware extraction: DOCX tracked changes and PDF color annotations surfaced as inline markers

JonasBoury added end-to-end support for preserving review markup through the document ingest pipeline. DOCX tracked changes and reviewer comments now arrive at the LLM as inline markers rather than getting flattened; PDFs with color-based redlines (Litera/Workshare style) get a PyMuPDF extractor, with the existing pdfjs path kept as fallback.

contract-reviewdiscovery

The DOCX side adds w:ins/w:del/w:commentRangeStart walking in backend/src/lib/docxTrackedChanges.ts. Insertions become {++text++}, deletions {--text--}, comments {>>by AUTHOR: comment<<} with author names and content pulled from word/comments.xml. Documents with no tracked changes go through the existing Mammoth extraction path, unchanged.

The PDF side is a new Python script at backend/scripts/redline_extract.py, spawned via backend/src/lib/pdfRedlineExtract.ts with a 30-second timeout and fallback to pdfjs on any error. The script uses PyMuPDF to read each span's color field, decodes it to RGB, and classifies spans against three targets with a 30-unit Euclidean tolerance: blue → insertion, red → deletion, green → moved. The commit header notes this is "ported from Diff Master's browserPyMuPdfProcessor.ts (Pyodide+PyMuPDF)" - the same algorithm moved from WASM to a Node subprocess. Set PYTHON_BIN if you need a specific interpreter; it defaults to python3.

Both chatTools.SYSTEM_PROMPT and the tabular extraction prompts (Gemini and Anthropic variants) are extended with a section explaining the marker format: accept insertions, drop deletions, treat comments as marginalia, strip markers from extracted values unless the user asks for them.

One unrelated change in the same commit: forcePathStyle: true on the R2 S3 client in storage.ts. Looks like a self-hosted MinIO compatibility tweak; harmless on real R2 but worth noting if you're reviewing the commit narrowly.

So what The DOCX extraction is straightforward TypeScript, self-contained, no new runtime dependencies - worth pulling if your users work with tracked-changes documents. The PDF path is conditional on having PyMuPDF available and only activates for Litera/Workshare-style color redlines; skip it if your users don't receive that format, since it adds a Python subprocess spawn per PDF before hitting fallback. The prompt changes are required if you take either extraction path.

View this fork on GitHub →

Spotted something wrong? Or know the PR text has fresher detail than the writeup above?

Commits in this thread

1 commit from Mace-legal/mike, oldest first. Source extracted verbatim from the harvested git log.

SHA Subject Author Date
b3b5dee0 feat: add redline-aware document extraction Jonas Boury 2026-05-10 ↗ GitHub

Capture this thread into my fork

Download a single Markdown prompt that tells Claude how to port every commit above into your working tree — adapting paths and structure to match your repo. Run it via claude -p < capture-thread-228.md from inside the repo you want the changes in.

⬇ Download capture-thread-228.md