Skip to content

Node-based terminal manager for AI coding agents — tmux-backed terminals and parallel agent sessions as draggable nodes on an infinite pan/zoom canvas. macOS, Linux, and a browser Server Edition.

feat(terminal): pure copy-feedback decision module

enesf9f702bac51d
diff --git a/src/renderer/terminal/copy-feedback.test.ts b/src/renderer/terminal/copy-feedback.test.ts
new file mode 100644
index 000000000..870e12bc8
--- /dev/null
+++ b/src/renderer/terminal/copy-feedback.test.ts
@@ -0,0 +1,51 @@
+import { describe, expect, it } from 'vitest'
+import { DRAG_MIN_PX, copiedLabel, decideDragOutcome } from './copy-feedback'
+
+describe('copiedLabel', () => {
+ it('counts characters for a single line', () => {
+ expect(copiedLabel('hello')).toBe('Copied 5 chars')
+ })
+ it('singularizes one character', () => {
+ expect(copiedLabel('x')).toBe('Copied 1 char')
+ })
+ it('counts lines for multi-line text', () => {
+ expect(copiedLabel('a\nb\nc')).toBe('Copied 3 lines')
+ })
+ it('does not count a trailing newline as an extra line', () => {
+ expect(copiedLabel('a\nb\n')).toBe('Copied 2 lines')
+ })
+ it('returns null for empty text — nothing was copied, so no pill', () => {
+ expect(copiedLabel('')).toBeNull()
+ })
+})
+
+describe('decideDragOutcome', () => {
+ const base = {
+ movedPx: 40,
+ sawOsc52: false,
+ hasXtermSelection: false,
+ hintSeen: false,
+ isMac: true
+ }
+ it('hints when a real drag produced neither a copy nor a selection', () => {
+ expect(decideDragOutcome(base)).toEqual({ kind: 'hint', label: 'Hold ⌥ to select text' })
+ })
+ it('says Shift off macOS', () => {
+ expect(decideDragOutcome({ ...base, isMac: false })).toEqual({
+ kind: 'hint',
+ label: 'Hold Shift to select text'
+ })
+ })
+ it('stays silent below the drag threshold — a click is not a drag', () => {
+ expect(decideDragOutcome({ ...base, movedPx: DRAG_MIN_PX - 1 })).toBeNull()
+ })
+ it('stays silent when an OSC 52 landed — the handler already put its pill up', () => {
+ expect(decideDragOutcome({ ...base, sawOsc52: true })).toBeNull()
+ })
+ it('never nags the user who already held the modifier', () => {
+ expect(decideDragOutcome({ ...base, hasXtermSelection: true })).toBeNull()
+ })
+ it('fires at most once per installation', () => {
+ expect(decideDragOutcome({ ...base, hintSeen: true })).toBeNull()
+ })
+})
diff --git a/src/renderer/terminal/copy-feedback.ts b/src/renderer/terminal/copy-feedback.ts
new file mode 100644
index 000000000..037f8da2b
--- /dev/null
+++ b/src/renderer/terminal/copy-feedback.ts
@@ -0,0 +1,57 @@
+// What a terminal says right after a copy — and, once per installation, what to do when a drag
+// produced nothing at all.
+//
+// Measured background (spec: docs/superpowers/specs/2026-08-09-terminal-copy-feedback-design.md):
+// a codex pane leaves the mouse to tmux, so a drag is a copy-mode selection that `copy-pipe-and-
+// cancel` copies via OSC 52 on RELEASE — clearing the highlight at the same instant, which reads
+// as "the copy failed". A claude pane captures the mouse, so a plain drag produces nothing at all
+// and only ⌥/Shift (xterm's own selection) works. Neither state had any on-screen evidence.
+//
+// This module is the decision alone: no DOM, no React, no storage. `useCopyFeedback` is the glue.
+
+/** What the header pill is showing. */
+export type CopyFeedback = { kind: 'copied' | 'hint'; label: string } | null
+
+/** A click is not a drag. Same intent as `GUARD_CLICK_SLOP` in TerminalNode: a few pixels of
+ * travel between press and release is a hand, not an intent — and a plain click inside a
+ * mouse-capturing pane is the single most common interaction there, so it must stay silent. */
+export const DRAG_MIN_PX = 8
+/** How long after mouse-up an OSC 52 still counts as THIS drag's copy. tmux copies on release, so
+ * the sequence is always in flight at decision time. Sized for an SSH round-trip; a local tmux
+ * answers in well under 50 ms. */
+export const OSC52_GRACE_MS = 600
+export const COPIED_DWELL_MS = 1600
+export const HINT_DWELL_MS = 5000
+/** Once per installation — same convention as `seenShortcuts`. */
+export const HINT_STORAGE_KEY = 'nodeterm.seenSelectHint'
+
+/**
+ * The `copied` pill's label. Lines for multi-line text, characters for one line — the two numbers
+ * a user checks when unsure the right thing was copied. Empty text yields null: nothing was
+ * copied, so nothing is claimed.
+ */
+export function copiedLabel(text: string): string | null {
+ if (!text) return null
+ const lines = text.replace(/\n$/, '').split('\n').length
+ if (lines > 1) return `Copied ${lines} lines`
+ return `Copied ${text.length} char${text.length === 1 ? '' : 's'}`
+}
+
+/**
+ * The drag's ONLY possible contribution: the one-time hint, or nothing. The `copied` pill has a
+ * different owner (the OSC 52 handler), so it is deliberately not returned here — one pill, one
+ * owner, no race for the header slot.
+ */
+export function decideDragOutcome(input: {
+ movedPx: number
+ sawOsc52: boolean
+ hasXtermSelection: boolean
+ hintSeen: boolean
+ isMac: boolean
+}): { kind: 'hint'; label: string } | null {
+ const { movedPx, sawOsc52, hasXtermSelection, hintSeen, isMac } = input
+ if (movedPx < DRAG_MIN_PX) return null
+ // A copy happened (tmux copy-mode) or the user already knows the modifier — nothing to teach.
+ if (sawOsc52 || hasXtermSelection || hintSeen) return null
+ return { kind: 'hint', label: `Hold ${isMac ? '⌥' : 'Shift'} to select text` }
+}