Skip to content

feat(tui): /export and /copy (#463) - #568

Merged
ajianaz merged 4 commits into
developfrom
feat/463-export-copy
Nov 11, 2026
Merged

ajianaz merged 4 commits into
developfrom
feat/463-export-copy

Conversation

@ajianaz

@ajianaz ajianaz commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

What

Part 1 of #463 (later TUI polish): the TUI commands /export [path] (HTML or JSONL) and /copy (last answer). Part of #463; the issue stays open for themes and keybindings (/fork and /tree merged in #567).

Why

A terminal session should be able to hand its transcript or its last answer to the user without a native clipboard dependency (the TUI has none, decision of #560) and without weakening the guarantees that provider text never reaches the terminal as escape sequences and that the session log is append-only.

Changes

  • /copy: the host returns the last assistant answer (HostCmd::LastAnswer -> HostReply::Answer(Option<String>), newest non-empty assistant message in the log). The TUI sends it as one OSC 52 sequence, ESC ] 52 ; c ; <base64> BEL, built in clipboard::osc52 and written in clipboard::emit only. The payload is base64 only, so answer text cannot inject escape bytes. Cap: 64 KiB of raw answer; above it the note points to /export. With no answer, nothing is sent. The note says what was attempted (sent N characters to the terminal clipboard; needs OSC 52 support, tmux needs set -g set-clipboard on) and never that it worked.
  • /export [path] (HostCmd::Export -> HostReply::Path, new tole-cli/src/export.rs): format by extension. .jsonl is the entries exactly as stored, one JSON object per line, read from the in-memory replay (the session file is not touched). .html is a self-contained page: all text escaped, no script, no external resource, <meta http-equiv="Content-Security-Policy" content="default-src 'none'; style-src 'unsafe-inline'">, light and dark. Other extensions are refused with the supported list. Default path: <workspace>/.tole/exports/<session id>.html (only that directory is created, level by level with a jail check each time).
  • Path safety: the parent is canonicalized and must be inside the workspace (.., outside absolute paths and symlinked directories refused); the file is opened with create_new, so an existing file or a symlink at the target (dangling or not) is never overwritten or followed; created 0600 on Unix.
  • Behavior during a turn: both commands are ignored while a turn runs, like /image and the other commands (one rule for every command; /export could read safely during a turn but would be the only command that did).
  • TuiSession::with_workspace (wired from the resolved workspace root in tui_command), last_answer, export.
  • Docs: docs/tui.md (commands table, new section including the secrets warning, Not implemented, host seam), CHANGELOG Unreleased, README status line, docs/epics.md, and a short docs/threat-model.md section.
  • OSC 52 sources, checked on 2026-11-11 and recorded in the clipboard.rs header: the Ghostty and foot documentation both give ESC ] 52 ; Pc ; Pd ST, with c for the clipboard and Pd as base64. Ghostty documents that a Pd that is not valid base64 clears the clipboard, which is why an empty or invalid payload is never sent. xterm's own ctlseqs page was not read directly (its host is outside the session network allowlist); the xterm side rests on search excerpts of that document and on the charmbracelet x/ansi docs, which list both the ST and the BEL terminator. BEL is kept for the widest compatibility, and the e2e test pins the exact bytes.
  • Rebased onto develop after feat(tui): /fork and /tree over session forks (#463) #567 merged. Both PRs had raised the COMMANDS table in menu.rs from 9 to 11 entries, so the merged table has 13; git could not flag that as a conflict and the build failed until the last commit (fix(tui): size the command table ...) corrected the length. The other conflicts (tui_e2e.rs, CHANGELOG, README status line, docs/epics.md) kept the entries of both PRs.

Testing

  • After the rebase, on top of develop at 05fd947: cargo fmt --all -- --check, cargo clippy --workspace --all-targets -- -D warnings and cargo check -p tole-cli --no-default-features clean; cargo test --workspace: 1282 passed, 0 failed.
  • New unit tests: OSC 52 payload (RFC 4648 vectors, exact bytes, hostile ESC/BEL/]52; text cannot break out), size cap (at cap allowed, over refused), command parsing and notes with a fake host, HTML escaping (<script>alert(1)</script>, "onload="), CSP meta, no <script, JSONL equals the stored entries, overwrite refusal, jail refusals (../x.html, outside absolute, symlinked dir, file symlink target, .tole symlink), unknown extension, host-level test that the session file is unchanged.
  • New pty e2e in crates/tole-cli/tests/tui_e2e.rs: /copy (the OSC 52 sequence with the right base64, also for an answer containing ESC/CR, no raw bytes on the pty, no claim of success) and /export (file written, refused on the second run, ../escape.html refused, .jsonl export). The existing tui_never_passes_escape_sequences_from_provider_text still passes.
  • Mutation checks (each made tests fail, then restored): removing HTML escaping (3 tests failed), removing the jail checks (2 failed), replacing create_new with create+truncate (4 failed), emitting raw text instead of base64 (3 clipboard unit tests failed).
  • cora is not available in this environment, so the staged diff was reviewed by hand (escape injection, path handling, error paths); the CI Cora Review is the gate.

@github-actions

Copy link
Copy Markdown

🔍 Cora AI Code Review

✅ No issues found. Code looks good!


Review powered by cora-code · BYOK · MIT

Part of #463. /copy sends the last assistant answer as an OSC 52 sequence (base64 payload only, 64 KiB cap); /export writes the transcript as .html or .jsonl under the workspace (jailed, never overwrites).
Replace the note that the format was written from memory with the sources
read on 2026-11-11 (Ghostty and foot documentation) and say plainly that
xterm's own ctlseqs page was not read directly. Also record that a payload
that is not valid base64 clears the clipboard in some terminals, which is why
the module never sends an empty or invalid one.
/fork and /tree (#567) and /export and /copy (#568) each raised the length of
the COMMANDS table from 9 to 11. Merged, the table has 13 entries, which git
could not flag as a conflict because the changed lines differ.
@ajianaz
ajianaz force-pushed the feat/463-export-copy branch from 60032c9 to de81d04 Compare November 11, 2026 07:34
@ajianaz
ajianaz merged commit 56173f3 into develop Nov 11, 2026
19 of 20 checks passed
ajianaz added a commit that referenced this pull request Nov 11, 2026
[tui.keys] in the user config rebinds ten convenience actions (tool output, reasoning, model picker, cycle model, cycle thinking, newline, queue follow-up, pop queue, history) to a key spec or a list; the default keymap is the keys the TUI always had. y, n, Esc, Ctrl+C, Enter, Backspace, Tab and every bare character are never rebindable, and at an approval prompt only y, n, Esc and Ctrl+C act whatever the keymap says. A project config cannot set keys (ignored with a warning), and an invalid keymap falls back to the default with one startup note. Closes #463 with #567, #568 and #569.
@ajianaz
ajianaz deleted the feat/463-export-copy branch November 20, 2026 08:35
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.

2 participants