# Build a negotiation workflow with SuperDoc

Your models and playbooks decide what to propose. SuperDoc gives them a real DOCX to work on, with native tracked changes, comments, and review. Your team designs how lawyers work through an agreement. Counsel can still send it as a Word file.

Use the pattern in your own product: flag a clause against a playbook, propose a redline, let counsel decide, and send the same DOCX to outside counsel.

## Where SuperDoc fits

1. **Browser:** The SuperDoc editor renders the DOCX. Your application owns the controls and the Review panel.
2. **Your server and model:** Your application owns identity, room permissions, prompts, playbooks, storage, retention, and approvals. The model proposes wording. The application validates the exact target and current revision, then authorizes the native edit. A stale proposal goes back for review.
3. **Shared DOCX:** The visitor and separately attributed SDK collaborators join the same document. Native revisions and comments remain in the DOCX. The app can rebuild clause context from supported native anchors when the file returns.

This demo uses one app server and Hocuspocus for collaboration. Its anonymous session credentials and temporary storage are demo policies. Design the deployment, audit history, and authorization appropriate to your own users.

## How the demo is built

| Moment | What to inspect | Maintained docs |
| --- | --- | --- |
| Custom editor | App-owned review controls subscribe to native revision changes. `ui.viewport.scrollIntoView` follows an exact text range without replacing the editor. See `src/App.tsx` and `src/ReviewPanel.tsx`. | [Selection and viewport](https://docs.superdoc.dev/editor/custom-ui/selection-and-viewport/) |
| Agent redlines | The app scopes a read-only model session, validates one exact, unique match, and uses the full toolkit to dispatch a tracked `doc.replace`. The app reads back the operation and changes the score after a confirmed native decision. See `server/agent.mjs`. | [Full toolkit](https://docs.superdoc.dev/agents/build/tools/) |
| Live collaboration | The browser and separately attributed SDK handles for both players and the chair umpire join the same room. Take over stops the rally at a settled operation boundary. See `server/sessions.mjs` and `src/Document.tsx`. | [Node SDK and collaboration](https://docs.superdoc.dev/agents/automation/node-sdk/) |
| Version history | Pair a DOCX save with a native `doc.changes.snapshot({includeState:true})` and the author-attributed records through its cursor. Publish the private version only after the revision and state vector still match. See `server/versions.mjs`. | [Node SDK guide](https://docs.superdoc.dev/agents/automation/node-sdk/) |
| Word round trip | Native revisions and comments live in the DOCX. `doc.metadata` anchors clause context and `doc.customXml` stores document-level context. On reimport, unresolved or ambiguous anchors stay detached. See `server/native.mjs`. | [Application data in DOCX](https://docs.superdoc.dev/document-api/application-data/) |

The exhibition uses bounded model calls for each stage. Prepared wording is labeled in Review and passes through the same guarded native operations. For a visitor's selected-text suggestion, the app streams a provisional preview, then commits one attributed tracked change after rechecking the exact text range and room revision. Without a selection, AI shortcuts inspect the document. Custom prompts can stream answers and propose scoped, atomic batches of tracked edits. The three court reactions use the rendered document geometry and stay out of the exported DOCX.

The opening volley uses a native table on page one of the [same synthetic agreement](/exhibition.docx). The fixture builder applies the named net style through `doc.tables.setStyle`. The ball and rackets follow the table and rendered words in the live editor and settle beside the first legal edit. [Table style receipt](/volley-court.json) · [SuperDoc table style API](https://docs.superdoc.dev/document-api/table-styles/)

## Run the redline example

Download and unpack the [runnable source](/source.tar.gz), then run this from the Legal Tennis folder with Node 24 or newer:

```sh
npm ci
node scripts/evaluate-redline.mjs
```

The example uses only the synthetic agreement and requires no model key. It uses the same scoped write path as the live demo and produces three DOCX files under `evaluation-output`. Open each in Word to compare the pending redline, accepted wording, and restored original. The script captures a native version matching the pending DOCX and records its revision and change ID in the receipt. It also tries a deliberately stale decision and verifies that the document revision and text stay the same.

- [Synthetic agreement](/exhibition.docx)
- [Pending redline](/evaluation/pending.docx)
- [Accepted copy](/evaluation/accepted.docx)
- [Rejected copy](/evaluation/rejected.docx)
- [Saved-file receipt](/evaluation/receipt.json)
- [Exact installed package versions and build identity](/build-info.json)

The saved-file receipt proves the deterministic synthetic scenario. Word round trip acceptance for the live app also checks editing and saving its actual export in Word, then reopening it and inspecting comments and resolved clause context. Treat representative files as a separate compatibility check.

## Keep clause research with a Word file

Add a Research panel that jumps to the relevant heading. This demo uses the [ITF rule on first serve and ends](https://www.itftennis.com/media/7221/2026-rules-of-tennis-english.pdf#page=9), [Wimbledon’s 1937 television coverage](https://www.wimbledon.com/pdf/Wimbledon%20Compendium%202023.pdf), and [the Centre Court roof](https://www.wimbledon.com/en_GB/about/history/2000s).

Download the same [runnable source](/source.tar.gz). The example uses `doc.metadata.attach` at each live heading and `doc.customXml.parts.create` to store the association between a source and its anchor. On reimport, `doc.metadata.resolve` finds the current heading. An unresolved anchor keeps the source link readable and disables the document jump. The illustrations are original editorial art.

```sh
node scripts/research-roundtrip.mjs public/exhibition.docx research-moved.docx
# Open research-moved.docx in Word and Save As research-word-saved.docx.
node scripts/research-roundtrip.mjs research-word-saved.docx
```

Both runs print three resolved clause excerpts. The first moves the serve provision to another page. The second reads the Word-saved file and verifies the same heading text. [SuperDoc application data in DOCX](https://docs.superdoc.dev/document-api/application-data/)

The example captures the native checkpoint and the exact DOCX it describes. The optional **Version history** UI is disabled until the hosted release gate is met.

## Run the live app

Copy `.env.example` to `.env.local` and add a model key for live negotiations. Keep the key on the server. Run `npm run build` and `npm start`, then open `http://127.0.0.1:4175`. Editing and DOCX export do not require a model call.

Use the brief in Build this to give your coding agent a starting point. [Bring us a DOCX workflow you want to build](https://www.superdoc.dev/contact?source=legal-tennis).
