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.

Merge origin/main into feat/chat-prompt-suggestions

review49cecc0ed8df
diff --cc CLAUDE.md
index d17365e80,49b6f5129..a9e45e489
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@@ -4454,21 -4474,11 +4474,26 @@@ command-bearing opens; this does not ad
re-reads at once; unknown focus polls), to disable the composer and show the dialog's lines; SSH and relay panes are not polled (a round trip per read) and rely
on the send-time check. Another CLI's layout would read as a permanent dialog, so an agent joins
the list only with its own measured reader.
+ The live box must end within `BOX_TAIL_LINES` (8) non-blank lines of the bottom, so an old box in
+ the history is not taken for it; the agent list Claude Code draws under its status lines while
+ background agents or teammates run (`● main`, `○ <name> …` rows, `↓ N more`; measured on 2.1.319)
+ does not count toward those lines (`isAgentListLine`). Before that, five agents were enough for the
+ view to say the input box was not on screen.
+ **Claude's suggested next prompt is the composer's placeholder** (`readClaudeSuggestion`,
+ `pty.readChatScreen`). A few seconds after a turn ends, and only when there is an obvious next
+ step, Claude draws a suggestion as plain DIM text on its prompt line (MEASURED on 2.1.318); → in
+ its TUI accepts it, and → in an EMPTY composer does the same here: it fills the draft with the
+ caret at the end, and nothing is sent. The poll now makes ONE styled read for both the dialog
+ check and the suggestion (a styled capture is the only way to tell dim text from a draft; a pane
+ with no styled capture still gets the dialog check from the plain one). Two other dim texts sit
+ in the same place and are refused: the fresh-session tips (always `Try "…"`) and `Press up to
+ edit queued messages`. Shown only while a message could be sent and no dialog is on screen;
+ cleared on every state change and on send. Claude draws it 1.1-2.2 s after the turn ends
+ (measured, 5 turns), and the 2 s poll added up to 2 s more, which read as a lag; so after a turn
+ ends a local pane is read every 300 ms for up to 5 s, stopping at the first suggestion
+ (`SUGGESTION_BURST_MS`, at most ~15 extra reads per turn). An SSH node is never polled, so it is
+ read twice after each turn (`REMOTE_SUGGESTION_READ_DELAYS_MS`, 2.5 s and 6 s); relay tabs offer
+ none.
**Live progress (2026-09).** While the agent works, a `role=status` row closes the thread (the ONE
spinner + the placeholder's own "<agent> is working…"/"waiting for an answer" sentence; optimistic
right after a send, bounded by `CHAT_OPTIMISTIC_WORKING_MS`), and every hook event re-reads the
diff --cc src/core/pty-manager.ts
index fe4e99a3d,803f83b8e..8d197ef6e
--- a/src/core/pty-manager.ts
+++ b/src/core/pty-manager.ts
@@@ -1,12 -1,11 +1,18 @@@
- import type { ChatPromptBlocked, ChatPromptResult, EmptyPromptResult, TextDeliveryResult } from '../shared/text-delivery'
+ import type {
+ ChatInterruptResult,
+ ChatPromptBlocked,
+ ChatPromptResult,
+ EmptyPromptResult,
+ TextDeliveryResult
+ } from '../shared/text-delivery'
-import { claudeScreenBlocksInput, readClaudeComposer, readClaudeDraft, readClaudeScreen } from '../shared/agents/claude-screen'
+import {
+ claudeScreenBlocksInput,
+ readClaudeComposer,
+ readClaudeDraft,
+ readClaudeScreen,
+ readClaudeSuggestion,
+ type ChatScreenRead
+} from '../shared/agents/claude-screen'
import os from 'os'
import fs from 'fs'
import path from 'path'
@@@ -2290,10 -2296,15 +2303,19 @@@ export class PtyManager
// Like `agentId` above: it only picks the composer reader, and a non-string picks none.
this.sendToEmptyPrompt(persistKey, text, typeof agentId === 'string' ? agentId : '')
)
+ platform().handle(IPC.ptyReadChatScreen, (persistKey: string, agentId: unknown) =>
+ // Like the chat-prompt handler: `agentId` only picks the screen reader, and a non-string picks none.
+ this.readChatScreen(persistKey, typeof agentId === 'string' ? agentId : '')
+ )
+ platform().handle(IPC.ptyInterruptChat, (persistKey: string, agentId: unknown, sentText: unknown) =>
+ // `agentId` only picks the capability (a non-string picks none: `unsupported`), and `sentText`
+ // is only compared with what the agent put back in its own input box.
+ this.interruptChat(
+ persistKey,
+ typeof agentId === 'string' ? agentId : '',
+ typeof sentText === 'string' ? sentText : undefined
+ )
+ )
platform().handle(IPC.ptyTmuxStatus, () => this.tmuxStatus())
platform().handle(IPC.ptyPaneCommand, (persistKey: string, opts?: { resolveUnmounted?: boolean }) =>
this.paneCommand(persistKey, opts?.resolveUnmounted === true ? { resolveUnmounted: true } : undefined)
@@@ -6838,19 -6849,62 +6860,75 @@@
})
}
+ /**
+ * One read of the pane for the ⌘M chat view's screen poll: the dialog check the poll always made,
+ * plus the prompt the agent suggests next. A STYLED capture, because only the styling tells
+ * Claude's dim suggestion from typed text (`readClaudeSuggestion`). Where no styled capture exists
+ * (a native Windows pane), the plain capture still answers the dialog check, with no suggestion.
+ */
+ async readChatScreen(persistKey: string, agentId: string): Promise<ChatScreenRead> {
+ if (!readsScreenDialogs(agentId)) return { screen: { kind: 'unknown' }, suggestion: null }
+ const styled = await this.captureStyledScreen(persistKey)
+ if (styled === '') return { screen: readClaudeScreen(await this.captureSession(persistKey)), suggestion: null }
+ return { screen: readClaudeScreen(styled), suggestion: readClaudeSuggestion(styled) }
+ }
+
+ /**
+ * Esc from the ⌘M chat view: interrupt the running turn as Esc typed in the terminal would. Only
+ * for an agent whose interrupt and screen are measured (`interruptsFromChat`, claude), and refused
+ * before anything is written when the agent's own dialog owns the keyboard or no input box is on
+ * screen: Esc there would cancel the dialog. An empty capture is not evidence of a dialog (the
+ * `sendChatPrompt` rule). The Esc goes through `sendPaneKeys`, so it reaches the pane by node id
+ * with no mounted terminal, local or over the project's ControlMaster.
+ *
+ * MEASURED on Claude Code 2.1.318: an Esc before the reply's first token puts the prompt back into
+ * Claude's own input box, where the chat view cannot see it, and the next chat send would be typed
+ * after it. So when `sentText` (the chat view's last send) is given and the box comes to hold
+ * exactly that text, it is cleared and handed back as `restored`. Any other text in the box is the
+ * user's and is left alone. Cleared with Ctrl-U, never Ctrl-C: Ctrl-C clears it too but then
+ * shows "Press Ctrl-C again to exit" for a few seconds, and a Ctrl-C the user presses in that window
+ * would quit Claude. Runs inside `serializePaneWrite`, so a chat send cannot land between the Esc
+ * and the read.
+ */
+ async interruptChat(persistKey: string, agentId: string, sentText?: string): Promise<ChatInterruptResult> {
+ if (!interruptsFromChat(agentId) || !readsScreenDialogs(agentId)) return { sent: false, reason: 'unsupported' }
+ return this.serializePaneWrite(persistKey, async (): Promise<ChatInterruptResult> => {
+ const screen = await this.captureSession(persistKey)
+ const gate = screen === '' ? null : screenGate(screen)
+ if (gate !== null) return { sent: false, reason: 'dialog', dialog: gate.dialog }
+ const esc = await this.sendPaneKeys(persistKey, '\x1b')
+ if (!esc.ok) return { sent: false, reason: esc.reason }
+ const want = sentText === undefined ? '' : sentText.replace(/\s/g, '')
+ if (want === '') return { sent: true, restored: null }
+ const took = await this.takeBackInterruptedPrompt(persistKey, sentText ?? '', want)
+ return { sent: true, restored: took ? (sentText ?? null) : null }
+ })
+ }
+
+ /** After an interrupt: wait briefly for Claude to put `want` (whitespace removed) back in its input
+ * box, then clear it. true only when the box held exactly that text and reads empty afterwards. */
+ private async takeBackInterruptedPrompt(persistKey: string, sentText: string, want: string): Promise<boolean> {
+ const readDraft = async (): Promise<string | null> => readClaudeDraft(await this.captureStyledScreen(persistKey))
+ const until = async (done: (draft: string | null) => boolean, ms: number): Promise<string | null> => {
+ const deadline = Date.now() + ms
+ for (;;) {
+ const draft = await readDraft()
+ if (done(draft) || Date.now() >= deadline) return draft
+ await new Promise((r) => setTimeout(r, INTERRUPT_RESTORE_POLL_MS))
+ }
+ }
+ // 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.
+ 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)) === ''
+ }
+
/** 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/core/relay/access-policy.ts
index 55f8f9d43,6619184c7..7ef35e173
--- a/src/core/relay/access-policy.ts
+++ b/src/core/relay/access-policy.ts
@@@ -344,8 -344,7 +344,9 @@@ export const EDITOR_ONLY: ReadonlySet<s
IPC.ptySendText,
IPC.ptySendChatPrompt,
IPC.ptySendToEmptyPrompt,
+ // The composer's screen poll; only an editor has a composer.
+ IPC.ptyReadChatScreen,
+ IPC.ptyInterruptChat,
IPC.ptyPaneOwner,
// A host filesystem path, not a view of the terminal — a viewer's file links keep the node cwd.
IPC.ptyPaneCwd,
diff --cc src/core/relay/scoped-guest-policy.ts
index ac3147e36,2fc671ec5..ee20a9688
--- a/src/core/relay/scoped-guest-policy.ts
+++ b/src/core/relay/scoped-guest-policy.ts
@@@ -389,7 -389,7 +389,8 @@@ export const SCOPED: Readonly<Record<st
[IPC.ptySendText]: nodeArg0,
[IPC.ptySendChatPrompt]: nodeArg0,
[IPC.ptySendToEmptyPrompt]: nodeArg0,
+ [IPC.ptyReadChatScreen]: nodeArg0,
+ [IPC.ptyInterruptChat]: nodeArg0,
[IPC.ptyTmuxStatus]: pass,
[IPC.ptyPaneCommand]: nodeArg0,
[IPC.ptyPaneCwd]: nodeArg0,
diff --cc src/preload/index.ts
index 30f36c601,af1e56ebf..24c85842a
--- a/src/preload/index.ts
+++ b/src/preload/index.ts
@@@ -115,7 -115,8 +115,9 @@@ const api: NodeTerminalApi =
ipcRenderer.invoke(IPC.ptySendChatPrompt, persistKey, text, agentId),
sendToEmptyPrompt: (persistKey, text, agentId) =>
ipcRenderer.invoke(IPC.ptySendToEmptyPrompt, persistKey, text, agentId),
+ readChatScreen: (persistKey, agentId) => ipcRenderer.invoke(IPC.ptyReadChatScreen, persistKey, agentId),
+ interruptChat: (persistKey, agentId, sentText) =>
+ ipcRenderer.invoke(IPC.ptyInterruptChat, persistKey, agentId, sentText),
tmuxStatus: () => ipcRenderer.invoke(IPC.ptyTmuxStatus),
paneCommand: (persistKey, opts) => ipcRenderer.invoke(IPC.ptyPaneCommand, persistKey, opts),
paneCwd: (persistKey) => ipcRenderer.invoke(IPC.ptyPaneCwd, persistKey),
diff --cc src/renderer/bridge/ws-bridge.ts
index 344d1a31e,71bb880f6..54306b08e
--- a/src/renderer/bridge/ws-bridge.ts
+++ b/src/renderer/bridge/ws-bridge.ts
@@@ -28,8 -28,7 +28,8 @@@ import
type RpcMessage
} from '../../shared/rpc'
import { IPC } from '../../shared/ipc'
- import type { ChatPromptResult, EmptyPromptResult } from '../../shared/text-delivery'
+ import type { ChatInterruptResult, ChatPromptResult, EmptyPromptResult } from '../../shared/text-delivery'
+import type { ChatScreenRead } from '../../shared/agents/claude-screen'
import type { GitHubControlApi, GitHubIssuesApi } from '../../shared/github-issues'
import {
UNKNOWN_CLAUDE_CLI_CAPS,
@@@ -304,11 -303,11 +304,16 @@@ export function buildRealApi
client.request(IPC.ptySendChatPrompt, persistKey, text, agentId) as Promise<ChatPromptResult>,
sendToEmptyPrompt: (persistKey, text, agentId) =>
client.request(IPC.ptySendToEmptyPrompt, persistKey, text, agentId) as Promise<EmptyPromptResult>,
+ // Real: core registers it. A failed read is "could not tell", never a dialog.
+ readChatScreen: (persistKey, agentId) =>
+ client
+ .request(IPC.ptyReadChatScreen, persistKey, agentId)
+ .catch(() => ({ screen: { kind: 'unknown' }, suggestion: null })) as Promise<ChatScreenRead>,
+ // Real: core registers it. A failed request (a relay host refusing a non-editor) is `failed`.
+ interruptChat: (persistKey, agentId, sentText) =>
+ client
+ .request(IPC.ptyInterruptChat, persistKey, agentId, sentText)
+ .catch(() => ({ sent: false, reason: 'failed' })) as Promise<ChatInterruptResult>,
// A failed read is unknown, never evidence that persistence is available.
tmuxStatus: () =>
client
diff --cc src/renderer/nodes/ChatPanel.tsx
index 54c7d0898,f10effab0..bcf585b3c
--- a/src/renderer/nodes/ChatPanel.tsx
+++ b/src/renderer/nodes/ChatPanel.tsx
@@@ -1,8 -1,8 +1,8 @@@
import { TEXT_NOT_SUBMITTED, isChatPromptBlocked } from '@shared/text-delivery'
-import { claudeScreenBlocksInput, readClaudeScreen } from '@shared/agents/claude-screen'
+import { claudeScreenBlocksInput, type ChatScreenRead } from '@shared/agents/claude-screen'
import { Fragment, memo, useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState, type KeyboardEvent } from 'react'
import { renderMarkdown } from '../lib/markdown'
- import { useAgentStatus } from '../state/agentStatus'
+ import { inferInterruptAfterSettle, useAgentStatus } from '../state/agentStatus'
import { useSession } from '../session/session'
import { chipFor } from '../lib/keybindingOverrides'
import {
@@@ -972,8 -940,8 +1013,9 @@@ export function ChatPanel(
// Optimistic: show the prompt immediately. A live read keeps it until the transcript carries it
// (`carryUnconfirmed`); the turn-end reload / ↻ reconcile from the transcript outright.
setScreenBlock(null)
+ setSuggestion(null)
justSentRef.current = true
+ lastSentRef.current = text
const sent: ChatMessage = { role: 'user', parts: [{ kind: 'text', text }] }
if (mode === 'queue') queuedRef.current.add(sent)
setThread((t) => ({ ...t, messages: [...t.messages, sent] }))
diff --cc src/shared/ipc.ts
index b28e2f5f8,fe370bdc7..4ae58e9f1
--- a/src/shared/ipc.ts
+++ b/src/shared/ipc.ts
@@@ -30,7 -30,7 +30,8 @@@ export const IPC =
ptySendText: 'pty:send-text',
ptySendChatPrompt: 'pty:send-chat-prompt',
ptySendToEmptyPrompt: 'pty:send-to-empty-prompt',
+ ptyReadChatScreen: 'pty:read-chat-screen',
+ ptyInterruptChat: 'pty:interrupt-chat',
ptyTmuxStatus: 'pty:tmux-status',
/** The foreground command of a node's tmux pane (`#{pane_current_command}`) — how the in-place
* agent restart sees that the CLI has exited and a shell owns the pane again. */
diff --cc src/shared/types.ts
index 23ffbe77a,b2ca9e1b0..c49b05075
--- a/src/shared/types.ts
+++ b/src/shared/types.ts
@@@ -1,5 -1,4 +1,5 @@@
- import type { ChatPromptResult, EmptyPromptResult, TextDeliveryResult } from './text-delivery'
+ import type { ChatInterruptResult, ChatPromptResult, EmptyPromptResult, TextDeliveryResult } from './text-delivery'
+import type { ChatScreenRead } from './agents/claude-screen'
import type { PushWebhookMinted, PushWebhookResult, PushWebhookTokenInfo } from './push-webhook'
import type { IdentitySeedEntry } from './agent-identity-seed'
import type { AgentStatusSnapshotEntry } from './agent-status-snapshot'
@@@ -1424,10 -1423,11 +1424,15 @@@ export interface PtyApi
* (issue #1144 — the app's own link notes). Refused, with the reason, before anything is written
* when the composer holds a draft, a dialog owns the keyboard, or emptiness cannot be proven. */
sendToEmptyPrompt(persistKey: string, text: string, agentId: string): Promise<EmptyPromptResult>
+ /** One read of an agent's screen for the ⌘M chat view's poll: who owns the keyboard, and the
+ * prompt the agent suggests next (claude: `readClaudeSuggestion`). An agent with no measured
+ * reader, or a pane that could not be read, answers `{ screen: { kind: 'unknown' }, suggestion: null }`. */
+ readChatScreen(persistKey: string, agentId: string): Promise<ChatScreenRead>
+ /** Esc from the ⌘M chat view: interrupt a running turn, for an agent whose interrupt is measured
+ * (claude). Refused before writing when the agent's own dialog owns the keyboard. `sentText` (the
+ * chat view's last send) lets core take it back out of the agent's input box when the Esc landed
+ * before the reply started; it comes back as `restored`. Never rejects on the desktop. */
+ interruptChat(persistKey: string, agentId: string, sentText?: string): Promise<ChatInterruptResult>
/** Is tmux available on this host (else the silent plain-shell fallback), plus a suggested
* install command for the "tmux not found" banner. */
tmuxStatus(): Promise<TmuxStatus>