Add Copy Draft, Markdown, and Word export for Gary's AI outputs#1
Merged
Conversation
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.
- 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
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:
.mdfile with a safe filename likecontract-review-draft-2026-05-19.md, wrapped with a short title block (matter name, Saved Legal Task name, generated date) and an attorney‑review reminder..docxvia the already‑installeddocxpackage; preserves headings, paragraphs, bullets, and simple GFM tables; ends with the short footer "Draft generated by Gary for attorney review."Buttons appear under every non‑streaming assistant message in 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. Attorney‑review framing is preserved in every export.
Files changed
frontend/src/lib/exportDraft.ts(new) — pure helpers:sanitizeFilenamePart,buildFilename,buildMarkdownHeader,wrapDraftAsMarkdown,copyDraftToClipboard,downloadDraftAsMarkdown,downloadDraftAsDocx,markdownToBasicHtml. The DOCX path uses a small Markdown → docx converter so we don't pull in extra deps.frontend/src/lib/exportDraft.test.ts(new) — focused tests for filename safety, header content, attorney‑review reminder, no API‑key/internal‑ID leakage, and clipboard failure messaging.frontend/src/app/components/assistant/AssistantMessage.tsx— replaces the icon‑only copy button with the Copy Draft / Download Markdown / Download Word Draft action row plus a polite status line.frontend/src/app/components/assistant/ChatView.tsx— threads optionalmatterNamethrough and derivestaskTitlefrom the preceding user message's workflow.frontend/src/app/(pages)/projects/[id]/assistant/chat/[chatId]/page.tsx— same wiring inside the per‑matter chat, withproject?.nameasmatterName.docs/US_LAWYER_SETUP_GUIDE.md— new "Copying or Downloading Drafts" section explaining each action and the review checklist.docs/US_TERMINOLOGY_MAP.md— added Copy Draft / Download Markdown / Download Word Draft / "Draft for attorney review" entries.Attorney‑review framing
Every exported draft (Markdown and Word) starts with:
DOCX exports also end with a centered italic footer: "Draft generated by Gary for attorney review."
Tests
bun run frontend/src/lib/exportDraft.test.ts— 11/11 pass. Covers safe filenames, header text, attorney‑review line, no leakage ofsk-,api_key,bearer,document_id,version_id,edit_id,supabase, etc., noWorkflow Templatelegacy wording, and a friendly fallback when clipboard isn't available.bun run frontend/src/app/components/workflows/builtinWorkflows.test.ts— still passes.Validation
bun run build— clean.bun run build— TypeScript compilation succeeds (Finished TypeScript in 14.0s). The build then fails during Next.js static prerendering of/account/modelswithError: supabaseUrl is required.— that's the expected codespace failure mode because no Supabase env vars are configured here, and is unrelated to these changes.bun run lint— same number of errors before and after the change (43); the new files contribute zero new lint errors or warnings.What was deferred
DraftFormatenum on the helpers, but didn't surface a picker UI yet; the goal was to keep this PR focused.Test plan
<matter>-<task>-draft-YYYY-MM-DD.mdand contents include the header block.https://claude.ai/code/session_01LNzU9cGoR4SsYXon8H7aJZ
Generated by Claude Code