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.
TypeScript adhdagent-orchestrationai-agentscanvasclaude-codecodexcoding-agentsdeveloper-toolselectrongeminilinuxmacosmultiplexeropencodeparallel-agentsterminalterminal-emulatorterminal-multiplexertmuxworkspace-manager
Merge remote-tracking branch 'refs/remotes/pr/1411' into carry/pr-1411
review590299996c9b
diff --cc CLAUDE.mdindex 61744fbb8,9c98913bc..5fc4fe359--- a/CLAUDE.md+++ b/CLAUDE.md@@@ -4650,17 -4601,16 +4650,27 @@@ command-bearing opens; this does not addebounced, flushed on pagehide, and merge only this window's changes into the stored map (twoServer Edition tabs); bounded by age (30 days), count (50) and size (32,000 chars stays in memoryonly). Pruned by age, not node existence: a closed project still holds its nodes.+ **Shell mode is drawn as Claude Code's TUI draws it** (`lib/chatShellMode.ts`, claude and custom+ agents built on it; MEASURED on 2.1.319): a draft starting with `!` — typed into an empty box or at+ the start of existing text, the TUI's rule — shows its `!` in `--sys-pink` beside the textarea, not+ in it, with a pink border and the TUI's own "! for shell mode" under the box; Backspace at the very+ start leaves it. The DRAFT keeps the `!` (it is what the send types and what puts the TUI in shell+ mode); only the display changes, and the completion/highlight stand down (the caret snapshot holds+ the shown text, not the draft). The `!` slot is always rendered so the textarea is never remounted.+ A `!` command in the THREAD (`nodes/ChatShellCommand.tsx`) is the TUI's `! cmd` with its output's+ first line under a `⎿`, opening to the whole output: the reader keeps a bash-family output's lines+ (`BASH_OUTPUT_MAX`, 16384) instead of `summarizeResult`, and gives a command that printed nothing+ `result: ""` (chat-fixtures README rules 4-5).+ **A draft carries across the user's own ⌘M flip** (`lib/chatDraftCarry.ts`, claude only; core+ `putChatDraft` / `takeChatDraft`). It MOVES, never copies, so it is never sent twice: chat → terminal+ types it unsent (`sendTyped`, `submit: false`) into an EMPTY input box only; terminal → chat takes+ only what `readClaudeDraftLine` can read back exactly (one row, the `❯` prompt, no `[Pasted text…]`+ placeholder — MEASURED on 2.1.319: a wrap and an M-Enter newline draw the same, and the wrap drops+ the space at the break), clears it with Ctrl-E Ctrl-U (Ctrl-U alone keeps what is right of a moved+ cursor), and hands it over only once the box reads empty. Anything else stays put and is named+ (a note under the chat box, or a toast). Only the chord and the header toggle carry; the composer's+ own flips (`onShowTerminal`: a `/model` label, an interactive built-in) never do, a picker having+ just opened there (`chat-draft-carry-wiring.test.ts`).Fix-round rules (same day): the composer is its OWN component (`nodes/ChatComposer.tsx`) so thethread and the composer restyle independently. A label click is an explicit "go to theterminal", so the flip FOCUSES the xterm whatever its entry state wasdiff --cc src/core/pty-manager.tsindex b2af6d312,71d8d1504..dbbfe1407--- a/src/core/pty-manager.ts+++ b/src/core/pty-manager.ts@@@ -9,7 -11,7 +11,8 @@@ importclaudeScreenBlocksInput,readClaudeComposer,readClaudeDraft,+ readClaudeDraftBox,+ readClaudeDraftLine,readClaudeScreen,readClaudeSuggestion,type ChatScreenRead@@@ -6933,32 -6939,70 +6954,85 @@@ export class PtyManager}}// Stop at the first non-empty draft: ours, or text the user typed into the terminal (left alone).- const draft = await until((d) => d !== null && d !== '', INTERRUPT_RESTORE_WAIT_MS)- if (draft !== want) return false- // One Ctrl-U clears a line; at the start of a line it joins it to the one above. MEASURED (2.1.318):- // repeated Ctrl-Us empty a multi-line box, and a Ctrl-U on an empty box does nothing, so one per- // line plus spares is safe in a single write.+ let box = await until((b) => b !== null && b.draft !== '', INTERRUPT_RESTORE_WAIT_MS)+ // A prompt taller than the box shows only its end (`readClaudeDraftBox`), so the end of what was+ // sent counts as ours. Text that happens to be that end loses nothing: the whole prompt goes back.+ if (box === null || box.draft === '' || !want.endsWith(box.draft)) return false+ // MEASURED (2.1.319): one Ctrl-U clears the visual ROW the caret is on, so a long line wrapped onto+ // several rows needs one per row, and at the start of a line one more joins it to the line above.+ // Two per row on screen (never fewer than two per line sent) plus spares clears what the box shows;+ // a Ctrl-U on an empty box does nothing. A box scrolled past its height stays full height and shows+ // earlier rows, so this repeats while what is left still ends, caret and all, earlier in what was+ // sent than it did before the round.const lines = sentText.split('\n').length- const cleared = await this.sendPaneKeys(persistKey, '\x15'.repeat(2 * lines + 2))- if (!cleared.ok) return false- return (await until((d) => d === '', INTERRUPT_RESTORE_WAIT_MS)) === ''+ let end = want.length+ for (let round = 0; round < INTERRUPT_CLEAR_MAX_ROUNDS; round++) {+ const before: string = box.draft+ const cleared = await this.sendPaneKeys(persistKey, '\x15'.repeat(2 * Math.max(box.rows, lines) + 2))+ if (!cleared.ok) return false+ box = await until((b) => b === null || b.draft !== before, INTERRUPT_RESTORE_WAIT_MS)+ if (box === null || box.draft === before) return false+ if (box.draft === '') return true+ const next = endsEarlierIn(want, box.draft, end)+ if (next === null) return false+ end = next+ }+ return false}+ /**+ * ⌘M chat view → terminal: type the chat composer's draft into the agent's own input box, WITHOUT+ * submitting it, so the user can carry on in the terminal. Only into an EMPTY box (two drafts are+ * never merged) and only when no dialog owns the keyboard; typed (`sendTyped`, `submit: false`), so+ * a multi-line draft keeps its lines (M-Enter) and is not recorded as a paste. The caller empties+ * its own draft only on `put: true`. Runs inside `serializePaneWrite`. An empty capture is NOT+ * evidence of anything here: nothing is typed into a box we cannot see.+ */+ async putChatDraft(persistKey: string, agentId: string, text: string): Promise<ChatDraftPutResult> {+ if (!readsScreenDialogs(agentId) || !typesChatInput(agentId)) return { put: false, reason: 'unsupported' }+ if (text.trim() === '') return { put: false, reason: 'empty' }+ return this.serializePaneWrite(persistKey, async (): Promise<ChatDraftPutResult> => {+ const styled = await this.captureStyledScreen(persistKey)+ if (styled === '' || screenGate(styled) !== null) return { put: false, reason: 'unreadable' }+ const composer = readClaudeComposer(styled)+ if (composer === 'draft') return { put: false, reason: 'has-draft' }+ if (composer !== 'empty') return { put: false, reason: 'unreadable' }+ const typed = await this.sendTyped(persistKey, text, agentId, { submit: false })+ if (typed === null) return { put: false, reason: 'unsupported' }+ if (typed === true) return { put: true }+ return { put: false, reason: typed === false ? 'failed' : 'unconfirmed' }+ })+ }++ /**+ * Terminal → ⌘M chat view: take the draft out of the agent's own input box, for the chat+ * composer. Only a draft that can be read back EXACTLY (`readClaudeDraftLine`: one row, the+ * ordinary prompt, no collapsed paste); anything else stays where it is and the caller says why.+ * Cleared with Ctrl-E then Ctrl-U — MEASURED (2.1.319): Ctrl-U alone deletes only what is left of+ * the cursor, so a draft whose cursor the user had moved lost only part of it; Ctrl-E first clears+ * the whole row. Never Ctrl-C (see `interruptChat`). The text is handed over only once the box+ * reads empty, so it is never in both places. Runs inside `serializePaneWrite`.+ */+ async takeChatDraft(persistKey: string, agentId: string): Promise<ChatDraftTakeResult> {+ if (!readsScreenDialogs(agentId)) return { taken: false, reason: 'unsupported' }+ return this.serializePaneWrite(persistKey, async (): Promise<ChatDraftTakeResult> => {+ const readLine = async () => readClaudeDraftLine(await this.captureStyledScreen(persistKey))+ const draft = await readLine()+ if (draft === null) return { taken: false, reason: 'unreadable' }+ if (draft.kind === 'empty') return { taken: false, reason: 'empty' }+ if (draft.kind === 'refused') return { taken: false, reason: draft.reason }+ const cleared = await this.sendPaneKeys(persistKey, '\x05\x15')+ if (!cleared.ok) return { taken: false, reason: cleared.reason === 'unsupported-backend' ? 'unsupported' : 'failed' }+ const deadline = Date.now() + INTERRUPT_RESTORE_WAIT_MS+ for (;;) {+ const now = await readLine()+ if (now?.kind === 'empty') return { taken: true, text: draft.text }+ if (Date.now() >= deadline) return { taken: false, reason: 'not-cleared' }+ await new Promise((r) => setTimeout(r, INTERRUPT_RESTORE_POLL_MS))+ }+ })+ }+/** The visible screen WITH its SGR, for `readClaudeComposer`: an ssh-project node's capture already* carries `-e` (`remoteCapturePaneArgs`), everything else is `captureSnapshot`. '' on any failure. */private async captureStyledScreen(persistKey: string): Promise<string> {diff --cc src/renderer/nodes/ChatComposer.tsxindex 58fdd8f05,183db31b2..662bc0e8a--- a/src/renderer/nodes/ChatComposer.tsx+++ b/src/renderer/nodes/ChatComposer.tsx@@@ -28,14 -27,10 +28,18 @@@ import { Spinner } from '../components/import { builtinSlashCommands, sanitizeChatCatalog, type ChatCatalogEntry } from '@shared/chat-catalog'import { prepareQuickOpenFiles, type QuickOpenIndexedFile } from '../lib/quickOpenSearch'import { commandSegments, mentionsSlashToken } from '../lib/chatComposerHighlight'+import { SHELL_MODE_HINT, draftFromDisplay, isShellDraft, shellDisplayText, showsShellMode } from '../lib/chatShellMode'+import {+ KEYBOARD_STEP_PX,+ completeMenuMax,+ composerHeight,+ readComposerHeight,+ writeComposerHeight+} from '../lib/chatComposerHeight'+ import { useChatDraft } from '../state/chatDraft'++ /** How long the composer shows why a terminal draft was not carried over. */+ const CARRY_NOTE_MS = 12_000import {CATALOG_REUSE_MS,applyCompletion,@@@ -774,7 -594,11 +786,12 @@@ export function ChatComposer(rows={2}/></div>+ </div>+ {carryNote !== null && (+ <div className="term-chat__carry-note" role="status">+ {carryNote}+ </div>+ )}<div className="term-chat__toolbar">{pathsForFiles && (<>diff --cc src/shared/agents/claude-screen.tsindex f224a4612,33105caff..98916ce8a--- a/src/shared/agents/claude-screen.ts+++ b/src/shared/agents/claude-screen.ts@@@ -266,9 -256,53 +266,53 @@@ export function readClaudeDraftBox(stylconst from = i === box[0] + 1 && lines[i].startsWith('❯') ? 1 : 0draft += undimmedText(styled[i], from)}- return draft.replace(/\s/g, '')+ return { draft: draft.replace(/\s/g, ''), rows: box[1] - box[0] - 1 }}+ /**+ * Why a draft in Claude Code's input box cannot be read back EXACTLY (`readClaudeDraftLine`):+ * - `multi-line` — it takes more than one row. MEASURED (2.1.319): a line that wraps and a real+ * newline (M-Enter) look the same, a second row indented two spaces, and the wrap drops the space+ * at the break, so neither the newlines nor the spaces could be put back.+ * - `placeholder` — it holds a collapsed paste or image (`[Pasted text #1 +12 lines]`, `[Image #1]`):+ * the screen shows the placeholder, not the text behind it.+ * - `not-prompt` — the row does not start with the ordinary `❯` prompt (shell mode's `!`, say).+ */+ export type ClaudeDraftLineRefusal = 'multi-line' | 'placeholder' | 'not-prompt'++ export type ClaudeDraftLine =+ | { kind: 'empty' }+ | { kind: 'line'; text: string }+ | { kind: 'refused'; reason: ClaudeDraftLineRefusal }++ const DRAFT_PLACEHOLDER = /\[(?:Pasted text|Image) #\d+/++ /**+ * The user's draft in Claude Code's input box, read from a STYLED capture, EXACTLY: only when it is+ * one row with the ordinary prompt and no collapsed paste, so the text can be handed to the ⌘M chat+ * composer as typed (the dim placeholder and any dim inline hint are not part of it; trailing spaces+ * are lost, as tmux trims them). null when there is no live input box to read.+ */+ export function readClaudeDraftLine(styledScreen: string): ClaudeDraftLine | null {+ const composer = readClaudeComposer(styledScreen)+ if (composer === 'empty') return { kind: 'empty' }+ if (composer !== 'draft') return null+ const styled = styledScreen.split(/\r?\n/)+ const lines = styled.map((l) => l.replace(ANSI, '').trimEnd())+ const box = inputBox(lines)+ if (!box) return null+ const promptAt = box[0] + 1+ for (let i = promptAt + 1; i < box[1]; i++) {+ if (lines[i].trim() !== '') return { kind: 'refused', reason: 'multi-line' }+ }+ if (!lines[promptAt].startsWith('❯')) return { kind: 'refused', reason: 'not-prompt' }+ // The prompt is `❯` and one space; everything after it that is not dim is the draft.+ const text = undimmedText(styled[promptAt], 1).replace(/^[ \u00a0]/, '').trimEnd()+ if (text === '') return { kind: 'empty' }+ if (DRAFT_PLACEHOLDER.test(text)) return { kind: 'refused', reason: 'placeholder' }+ return { kind: 'line', text }+ }+/*** The next prompt Claude Code suggests after a turn, read from a STYLED capture: the dim text on its* prompt line while the input box holds no draft. null when there is none to offer.