fix(chat): make the Word document field snake_case and single-nonce

↗ view on GitHub · Amal · 2026-08-04 · 5d1d0301

Two contract fixes surfaced by comparing the add-in endpoint against the
rest of POST /chat:

- The wire field becomes `document_context`, matching every other
  multiword field on this route (chat_id, displayed_doc,
  attached_documents). The old `documentContext` spelling is still
  accepted as a deprecated alias because shipped add-in builds send it;
  new clients should use the snake_case form.

- buildWordDocumentContextPrompt now takes the per-request nonce instead
  of minting its own. The system prompt tells the model to distrust any
  fence tag WITHOUT the current nonce, so a request must carry exactly
  one nonce - a second fence nonce made the Word document block fail the
  model's own verification rule.

Tests follow the route's conventions: the new integration cases assert
the 400 shape, the alias, and - via the buildMessages call - that the
document fence carries the same nonce as the rest of the request. The
spotlight test files move from lib/chat/__tests__ into the flat
lib/__tests__ directory where every other lib test (including this
feature's own documentContext.test.ts) already lives.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Repository open-legal-products/mike
Author Amal <mamalanand3@gmail.com>
Authored
Committed
Parents 08f53486
Stats 6 files changed , +84 , -24
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-5d1d0301.md from inside the repo you want the change in.

⬇ Download capture-commit-5d1d0301.md