Three export actions below every Gary response: clipboard, Markdown, Word

zgbrenner added Copy Draft, Download Markdown, and Download Word Draft buttons beneath completed assistant responses. The feature ships with a 677-line export module, a 317-line test suite, and a deliberate design constraint: the wrapper never redacts or scrubs AI content, but also never injects credential-shaped tokens into the exported file.

draftingworkflow

The three actions appeared in b4345deb and were refined in 347a4240. Copy Draft writes both an HTML payload and a Markdown payload to the clipboard simultaneously, so pasting into Word preserves headings and bullet structure without a format-conversion step. Download Markdown generates a .md file with a dated, slug-sanitized filename like contract-review-draft-2026-05-19.md, opening with a header block that names the matter, task, and date alongside an attorney-review reminder. Download Word Draft runs the Markdown through a converter using the docx package already in the project - headings, paragraphs, bullets, and simple GFM tables survive the conversion.

The core logic lives in frontend/src/lib/exportDraft.ts. The module is pure helpers: filename sanitization, header construction, a Markdown wrapper, the clipboard write, and the Markdown-to-docx converter. It's shared between the standalone assistant chat and the per-matter chat view; the per-matter chat threads the matter name and the derived task title through so exported files carry context.

347a4240 added two refinements. The export row now hides on replies under 200 characters - the threshold is documented as deliberately conservative, preferring false positives (showing buttons on borderline short answers) over false negatives (hiding them on a real one-paragraph memo). The no-scrub invariant was also made explicit: wrapDraftAsMarkdown preserves AI content verbatim. A test confirms that legal analysis mentioning "API key" or "Bearer token" (legitimate contract language) survives unchanged. The credential-leak tests check the wrapper's own additions, not the AI's prose.

The action row renders only after streaming completes. Task title lookup walks back through the message array to find the most recent prior user message that carried a workflow title, so exports from per-matter chats correctly identify which Saved Legal Task generated the response.

So what Worth a look if you need to get AI-generated legal drafts into Word without copy-paste friction. `exportDraft.ts` is isolated, reuses `docx`, and ships with tests covering filename edge cases and header content. The 200-char gating and the verbatim-preservation invariant are details that show the implementation was thought through rather than bolted on. The per-matter task-title threading requires some adaptation if your message schema differs.

View this fork on GitHub →

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

Commits in this thread

2 commits from zgbrenner/gary, oldest first. Source extracted verbatim from the harvested git log.

SHA Subject Author Date
b4345deb feat: add Copy Draft, Markdown, and Word export for AI outputs Claude 2026-05-19 ↗ GitHub
commit body
Adds three export actions below every Gary assistant response so U.S.
lawyers can move drafts into Word, email, or their own templates in one
click:

- "Copy Draft" - clipboard copy with HTML + Markdown payloads so paste
  into Word preserves headings and bullets; plain-English status text.
- "Download Markdown" - `.md` file with safe filename like
  `contract-review-draft-2026-05-19.md`, wrapped with a short title
  block (matter, Saved Legal Task, date) and an attorney-review
  reminder.
- "Download Word Draft" - `.docx` via the already-installed `docx`
  package; preserves headings, paragraphs, bullets, and simple GFM
  tables; ends with a short footer note.

Helpers live in `frontend/src/lib/exportDraft.ts` and are reused by both
the standalone assistant chat and the per-matter chat. Exports include
only the assistant's prose - internal events, tool calls, IDs, and
annotations are intentionally excluded.

Adds focused tests in `exportDraft.test.ts` covering filename safety,
header content, attorney-review reminder, no API-key/internal-ID
leakage, and clipboard failure messaging.

Updates the U.S. lawyer setup guide with a "Copying or Downloading
Drafts" section, and extends the terminology map.
347a4240 fix: hide export row on very short replies; clarify no-scrub invariant Claude 2026-05-19 ↗ GitHub
commit body
- AssistantMessage: only render Copy Draft / Download Markdown /
  Download Word Draft when the assistant's prose is at least 200
  characters. Tiny conversational replies like "Done." or
  "I need more information." stay uncluttered.
- exportDraft: document explicitly that the wrapper preserves AI
  content verbatim and never scrubs or redacts. The invariant we
  guard is the inverse - nothing the wrapper adds should introduce
  credential-shaped tokens.
- exportDraft.test: add a positive test confirming that legitimate
  legal text discussing "API key" rotation or "Bearer token"
  authentication is preserved unchanged in the export.

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-575.md from inside the repo you want the changes in.

⬇ Download capture-thread-575.md