# Document parsing

A reusable skill the "Redline the MSA before it hits your desk" recipe pulls in. Add it once and every agent on the team can use it.

Extract clause-level structure from the incoming MSA and write tracked-changes edits back into the Word file, using Anthropic's docx skill with legal-specific modifications.

## Method
1. Fetch the MSA at {{contract_path}} from Drive.
2. Convert the docx to a clause-by-clause structure, preserving section numbers and heading hierarchy.
3. Normalize clause boundaries so multi-paragraph clauses stay together during classification.
4. Pass each clause to the redline-playbook skill for classification and drafting.
5. Write every accepted edit back into the docx as a tracked change, never a silent replacement.
6. Save the redlined docx to `contracts/{{counterparty}}/{{contract_path}}-redlined.docx`.

## Rules
- Preserve the original document's formatting and numbering; do not restructure the contract.
- Every edit must appear as a visible tracked change — never auto-accept changes.
- Keep a mapping from each tracked change back to its source clause for the adversarial review pass.
- Contract length or page count that triggers a chunked parse (set on first run, then stored in memory).

## Output
A single docx file with tracked-changes edits inline, plus a clause-index list mapping each edit to its clause number and playbook citation.
