Skip to content

Export a chat to PDF from the terminal, and /export in the TUI (ATO-1054) - #1715

Draft
sosidudku1 wants to merge 1 commit into
mainfrom
fix/ato-1054-chat-export-pdf
Draft

sosidudku1 wants to merge 1 commit into
mainfrom
fix/ato-1054-chat-export-pdf

Conversation

@sosidudku1

Copy link
Copy Markdown
Collaborator

What the user gets

  • PDF from the terminal, no browser. atomic-agent export --last --format pdf writes a PDF named after the chat (or to --out). The export route takes format=pdf too (base64, like DOCX).
  • /export in the TUI. It saves the open chat with the same exporter and prints the saved path in the chat:
    • /export writes Markdown named after the chat into the folder the terminal was started in. It never writes over an earlier file: the second one is Trip plan (2).md.
    • /export md|docx|pdf|html [path] picks the format; the path may hold spaces or quotes, ~ works, a folder gets the chat's file name, a name with no extension gets the format's.
    • /export notes.pdf picks the format from the extension.
    • A named path is overwritten, as Claude Code's /export <file> and our --out do.
    • It is in the palette (after /rewind) and in the menu under Session as "Export chat".

Copied from Claude Code: /export <filename> writes the conversation to that file and says where. Claude Code's bare /export opens a copy-or-save dialog; here bare /export saves Markdown straight away and shows the path, with no clipboard step.

What changed

  • src/session/chat-export-pdf.ts (new): Markdown to PDF with Node only (zlib for the page streams). Text pages in the four standard PDF fonts (Helvetica, Bold, Oblique, Courier), so nothing is embedded. Real AFM widths for wrapping, A4, headings, bold/italic/code, lists with hanging markers, task boxes, block quotes with a bar, shaded code blocks, tables as A | B rows, rules, Page n of N footer, UTF-16 title in the document info.
  • Font limit, stated in the file: the standard fonts use WinAnsi (English and Western European). Cyrillic is transliterated (Привет becomes Privet), accents outside Latin-1 drop to the base letter, arrows and similar become ->, <=, and everything else (CJK, emoji) becomes ?. When anything changed, the PDF ends with a note saying how many characters changed and that Markdown and Word keep them all; the TUI line says so too. No font file is in the repo, so none is embedded.
  • src/session/chat-export.ts, chat-export-render.ts, index.ts: pdf is a format (application/pdf, .pdf).
  • src/cli/export-command.ts: --format pdf, help text updated.
  • src/http/route-session-export.ts: accepts pdf; the desktop still prints its own PDF from html.
  • src/tui/commands/export-command.ts (new): argument parsing, path resolution, writing. Wired through slash-command-handler.ts (chatExport), submit-handler.ts, TuiAppCallbacks.onChatExportRequested, tui-command.ts and ChatOrchestrator.exportOpenChat.
  • src/tui/menu/menu-registry.ts: the session.export node with the /export slash entry.

Tests

  • src/session/chat-export-pdf.test.ts (new): header, every xref offset points at its object, trailer and startxref, fonts and WinAnsi, title and date; page count in the page tree matches the streams for a long chat and the footer counts them; wrapping and PDF string escaping; WinAnsi mapping, transliteration, ? and the closing note (only when needed); lists, task boxes, quotes, code and tables.
  • src/tui/commands/export-command.test.ts (new): argument parsing, path resolution, numbered default names, overwrite of a named path, PDF bytes, the font note, nothing to export, missing folder.
  • slash-command-handler.test.ts, submit-handler.test.ts: /export dispatch and the callback.
  • menu-registry.test.ts: palette snapshot gains /export.
  • Existing tests updated where pdf used to be the rejected format (now rtf), and the route test checks a base64 PDF.

Not done, and why

  • No tests or type check were run on this Mac (team rule: checks run on the second Mac). The PDF writer was run once with plain Node on a sample chat and the result opened as a clean five-page PDF.
  • No embedded font, so no full Unicode in the PDF: no font file ships with the agent and no new dependency is allowed. Markdown and Word keep every character, and the PDF says so when it matters.
  • No copy-to-clipboard option for /export.
  • Desktop untouched (the desktop share PR Desktop: Share chat… as a redacted file, secret gist only after a confirm (ATO-581) #1663 is separate).

Part of ATO-1512.

Not yet checked on the second Mac.

…O-1054)

The core exporter gains a PDF writer built with Node alone: text pages
in the standard PDF fonts with WinAnsi encoding, so no browser and no
new dependency. Text outside Western European scripts is transliterated
or shown as ?, and the PDF ends with a note saying how many characters
changed. atomic-agent export and the export route accept --format pdf.

The TUI gets /export [md|docx|pdf|html] [path], registered in the menu
registry and the palette, writing the open chat with the same exporter
and showing the saved path.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant