Skip to content

feat(harness): /copy puts the last response on the clipboard, clean#27

Merged
mike-diff merged 2 commits into
mainfrom
copy-command
Jun 16, 2026
Merged

feat(harness): /copy puts the last response on the clipboard, clean#27
mike-diff merged 2 commits into
mainfrom
copy-command

Conversation

@mike-diff

Copy link
Copy Markdown
Owner

What

A new /copy command copies the last assistant response to the system clipboard as its raw markdown source.

A mouse-selected copy of the rendered transcript carries baggage: the terminal's hard line-wrapping, the renderer's > / indentation on tool and diff lines, and footer dividers if the selection overlaps them. /copy sidesteps all of it by copying the source straight from session history, so it is clean by construction.

How

Two independent write paths, so the text lands whether sesh is local or over SSH and whether or not the terminal allows programmatic clipboard writes:

  • OSC 52 terminal escape (the same OSC family sesh already uses for the title): works across an SSH hop; some terminals and a default tmux drop it.
  • A local clipboard tool when one is on PATH (wl-copy, xclip, xsel, pbcopy, clip.exe): reliable locally and through tmux, which is the common case.

/copy reports which path(s) ran, and prints an actionable error when none can. Zero dependencies.

Why not reformat a mouse selection

Considered and rejected. A native mouse selection belongs to the terminal; sesh sees nothing unless it seizes mouse control, which would break the native scrollback, search, and tmux copy-mode that the footer design exists to preserve, and even then could not reliably reverse the terminal's soft-wraps. Copying the source is strictly cleaner and keeps the core belief intact.

Tests

  • TestLastAssistantText — reaches past trailing tool/user turns and a tool-call-only (textless) assistant turn to the response the user actually saw; empty history yields nothing. Breaker: walk history forward, or drop the non-empty check.
  • TestOSC52 — pins the clipboard escape to the wire format terminals expect (ESC ] 52 ; c ; <base64> BEL), a real external contract.

/copy is registered in the single slashCommands table, so it tab-completes and appears in /help and sesh -help automatically. gofmt/vet clean, full suite green.

Note

Independent of #24 (the input editor). Branches off main.

mike-diff and others added 2 commits June 15, 2026 19:46
A mouse-selected copy carries the terminal's line wrapping, the renderer's
indentation, and footer dividers. /copy sidesteps all of it by copying the
last assistant turn's raw markdown source straight from history: clean by
construction. It writes by two independent paths so the text lands locally or
over SSH: the OSC 52 terminal sequence, plus a local clipboard tool
(wl-copy/xclip/xsel/pbcopy/clip.exe) when one is on PATH, which is what makes
it reliable through tmux. Reports which path ran, and says so when none can.

Deliberately does not touch mouse selection: seizing mouse control would
break the native scrollback, search, and tmux copy-mode the footer design
preserves, and still could not reverse the terminal's soft-wraps.
@mike-diff mike-diff merged commit 2ee4da0 into main Jun 16, 2026
2 checks passed
@mike-diff mike-diff deleted the copy-command branch June 16, 2026 02:53
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