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
fix(chat): keep the composer usable while the agent works, and queue for Claude
Paul Robertsonea54913e315a
diff --git a/CLAUDE.md b/CLAUDE.mdindex cb49604f9..89f314468 100644--- a/CLAUDE.md+++ b/CLAUDE.md@@ -3399,7 +3399,13 @@ command-bearing opens; this does not add a human-confirm dialog or change mobileclips, so it can never add a line to the row (a height flip would refit xterm and SIGWINCHtmux). It is not on the kanban card modal: that header already carries the ⌘M toggle.**The composer sends only in `done` or an unknown state** (`canSendFromChat`,- `renderer/lib/chatSendGate.ts`) — never in `waiting`/`blocked`, not just never in `working`:+ `renderer/lib/chatSendGate.ts`), with ONE exception: `working` for an agent in+ `INPUT_QUEUE_CAPABLE` (claude — measured: a prompt submitted mid-turn waits in Claude Code's own+ queue and reaches the model at the next tool boundary), where Enter QUEUES (`chatSendMode`) and+ the bubble reads "Queued" until the transcript has it. Only a plain prompt queues (`canQueue`):+ a slash command or `!` line mid-turn is unmeasured and waits. While the agent works the textarea+ stays editable for every agent (`composerStandsDown`) — only sending is gated. Never in+ `waiting`/`blocked`:PermissionRequest and AskUserQuestion both normalize to `waiting`, the pane then holds a TUIselect dialog this view does not show, and `sendText`'s Enter would ANSWER it ("Yes" is thedefault highlight). It also refuses any node whose CLI has left the pane — hibernated, paused,diff --git a/src/renderer/lib/chatSendGate.test.ts b/src/renderer/lib/chatSendGate.test.tsindex babc6567b..039c1fd0f 100644--- a/src/renderer/lib/chatSendGate.test.ts+++ b/src/renderer/lib/chatSendGate.test.ts@@ -1,6 +1,14 @@import { describe, expect, it } from 'vitest'import { agentProcessInPane } from '../terminal/live-work'-import { canSendFromChat, chatComposerPlaceholder, chatSendRefusal, screenBlockedSentence } from './chatSendGate'+import {+ canQueue,+ canSendFromChat,+ chatComposerPlaceholder,+ chatSendMode,+ chatSendRefusal,+ composerStandsDown,+ screenBlockedSentence+} from './chatSendGate'describe('chatSendRefusal / canSendFromChat', () => {it('allows a finished turn and an unknown state (no hook knowledge keeps the historical behavior)', () => {@@ -58,6 +66,16 @@ describe('chatSendRefusal / canSendFromChat', () => {describe('chatComposerPlaceholder', () => {const base = { readonly: false, agentLabel: 'Grok', chip: '⌘M' }+ it('says what Enter will do mid-turn when the COMPOSER asks (it passes its send mode)', () => {+ expect(chatComposerPlaceholder({ ...base, agentLabel: 'Claude Code', refusal: 'working', sendMode: 'queue' })).toBe(+ 'Claude Code is working — Enter queues your message'+ )+ expect(chatComposerPlaceholder({ ...base, refusal: 'working', sendMode: null })).toBe(+ 'Grok is working — you can type; send once the reply finishes'+ )+ expect(chatComposerPlaceholder({ ...base, refusal: 'working' })).toBe('Grok is working…')+ })+it('names the node agent in the sendable copy', () => {expect(chatComposerPlaceholder({ ...base, refusal: null })).toBe('Message Grok… (Enter to send, Shift+Enter for a new line)'@@ -136,3 +154,42 @@ describe('screenBlockedSentence — the agent\'s own dialog is on screen', () =>expect(chatComposerPlaceholder({ ...base, readonly: true })).toBe("Can't write to this session")})})++describe('chatSendMode — what Enter does', () => {+ it('sends when idle, for any agent', () => {+ expect(chatSendMode('claude', { state: 'done' })).toBe('send')+ expect(chatSendMode('grok', { state: 'done' })).toBe('send')+ })++ it('queues mid-turn only for a CLI measured to queue input', () => {+ expect(chatSendMode('claude', { state: 'working' })).toBe('queue')+ expect(chatSendMode('grok', { state: 'working' })).toBeNull()+ })++ it('never lifts any other refusal: a dialog would be ANSWERED, a shell would EXECUTE the text', () => {+ expect(chatSendMode('claude', { state: 'waiting' })).toBeNull()+ expect(chatSendMode('claude', { state: 'blocked' })).toBeNull()+ expect(chatSendMode('claude', { state: 'working', hibernated: true })).toBeNull()+ expect(chatSendMode('claude', { state: undefined, sessionEnded: true })).toBeNull()+ })+})++describe('canQueue — only a plain prompt was measured to queue', () => {+ it('queues prose, not a slash command or a `!` line', () => {+ expect(canQueue('and then run the tests')).toBe(true)+ expect(canQueue('/model')).toBe(false)+ expect(canQueue(' /compact keep notes')).toBe(false)+ expect(canQueue('!ls')).toBe(false)+ })+})++describe('composerStandsDown — is the whole composer disabled?', () => {+ it('not while the agent merely works: the draft stays editable', () => {+ expect(composerStandsDown('working')).toBe(false)+ expect(composerStandsDown(null)).toBe(false)+ })++ it('for a dialog or a shell-owned pane', () => {+ for (const r of ['dialog', 'asleep', 'paused', 'dropped', 'exited'] as const) expect(composerStandsDown(r)).toBe(true)+ })+})diff --git a/src/renderer/lib/chatSendGate.ts b/src/renderer/lib/chatSendGate.tsindex 1c8e604e7..bcfb13899 100644--- a/src/renderer/lib/chatSendGate.ts+++ b/src/renderer/lib/chatSendGate.ts@@ -1,4 +1,6 @@import type { AgentState } from '@shared/agents/normalize'+import { queuesInputWhileWorking } from '@shared/agents/config'+import { sentCommand } from '@shared/chat-command'import { agentProcessInPane } from '../terminal/live-work'/** The slice of a node's agent status the composer gate reads (`AgentNodeStatus` fits it). */@@ -55,6 +57,43 @@ export function canSendFromChat(agentId: string, s: ChatGateStatus): boolean {return chatSendRefusal(agentId, s) === null}+/**+ * What Enter in the composer does right now: `send` a new prompt, `queue` it behind the running+ * turn, or nothing (`null`).+ *+ * `queue` is the one refusal that is lifted: the agent is `working` and its CLI is known to QUEUE a+ * prompt submitted mid-turn instead of reading it as input to whatever is on screen+ * (`INPUT_QUEUE_CAPABLE` — measured for claude: the prompt waits in Claude Code's own queue and is+ * delivered at the next tool boundary as a `queued_command`). Every other refusal still refuses.+ */+export type ChatSendMode = 'send' | 'queue' | null++export function chatSendMode(agentId: string, s: ChatGateStatus): ChatSendMode {+ const refusal = chatSendRefusal(agentId, s)+ if (refusal === null) return 'send'+ if (refusal === 'working' && queuesInputWhileWorking(agentId)) return 'queue'+ return null+}++/**+ * May this text be queued mid-turn? Only a plain prompt was measured to queue. A slash command or a+ * `!` line typed while the agent works was not — and an interactive one (`/model`, `/rewind`) would+ * open its picker in the middle of the turn — so those still wait for the reply.+ */+export function canQueue(text: string): boolean {+ return sentCommand(text) === null+}++/**+ * Does the whole composer stand down (textarea included)? Not while the agent merely works: a+ * disabled textarea drops focus, so the user could not even type their next message while a reply+ * was being written. Only SENDING is gated then (`chatSendMode`). A dialog or a shell-owned pane+ * still stands it down — there the placeholder is the explanation, and it must be visible.+ */+export function composerStandsDown(refusal: ChatSendRefusal): boolean {+ return refusal !== null && refusal !== 'working'+}+/*** The composer's placeholder — the one place the user learns WHY it is disabled, naming the* node's own agent (the panel serves grok and base-claude custom agents too, not only Claude).@@ -77,7 +116,8 @@ export function chatComposerPlaceholder({agentLabel,chip,answerOnCard = false,- screen = null+ screen = null,+ sendMode}: {readonly: booleanrefusal: ChatSendRefusal@@ -86,11 +126,16 @@ export function chatComposerPlaceholder({answerOnCard?: boolean/** The pane's SCREEN says the agent's own UI owns the keyboard (`screenBlockedSentence`). */screen?: ScreenBlock | null+ /** The COMPOSER's placeholder passes it (the draft is editable mid-turn, so it says what Enter+ * will do); the thread's status row does not, and keeps the plain "is working…". */+ sendMode?: ChatSendMode}): string {if (readonly) return "Can't write to this session"if (screen !== null) return screenBlockedSentence(screen, agentLabel, chip)switch (refusal) {case 'working':+ if (sendMode === 'queue') return `${agentLabel} is working — Enter queues your message`+ if (sendMode === null) return `${agentLabel} is working — you can type; send once the reply finishes`return `${agentLabel} is working…`case 'dialog':if (answerOnCard) {diff --git a/src/renderer/nodes/ChatComposer.tsx b/src/renderer/nodes/ChatComposer.tsxindex 218ddd2d5..6854b4e62 100644--- a/src/renderer/nodes/ChatComposer.tsx+++ b/src/renderer/nodes/ChatComposer.tsx@@ -45,8 +45,15 @@ export interface ChatComposerProps {/** Enter (not Shift+Enter, not an IME commit). ChatPanel's send re-checks the gate itself. */onSend: () => voidplaceholder: string- /** Read-only session or a send-gate refusal: the whole composer stands down with the textarea. */+ /** Read-only session or a send-gate refusal: the whole composer stands down with the textarea.+ * Not while the agent merely works — see `agentBusy`. */disabled: boolean+ /**+ * The agent is mid-turn. The draft stays editable (a disabled textarea drops focus, and the user+ * could not type their next message while a reply was being written) and Enter is ChatPanel's to+ * gate (it may queue). The picker labels stand down: a `/model` typed now would land in the turn.+ */+ agentBusy?: boolean/** A picker command the pane refused outright (`sendText` → false): the session is not writable. */onWriteRefused: () => void/**@@ -86,6 +93,7 @@ export function ChatComposer({onSend,placeholder,disabled,+ agentBusy = false,onWriteRefused,sendUnconfirmed = false,pathsForFiles,@@ -397,7 +405,7 @@ export function ChatComposer({onSend()}- const labelDisabled = disabled || pickerBusy || sendUnconfirmed+ const labelDisabled = disabled || agentBusy || pickerBusy || sendUnconfirmedreturn (<div className="term-chat__compose">diff --git a/src/renderer/nodes/ChatPanel.live.test.tsx b/src/renderer/nodes/ChatPanel.live.test.tsxindex a6574750b..f85a63573 100644--- a/src/renderer/nodes/ChatPanel.live.test.tsx+++ b/src/renderer/nodes/ChatPanel.live.test.tsx@@ -482,8 +482,10 @@ describe('ChatPanel — a sent local command', () => {}expect(pending.length).toBeGreaterThan(1)expect(activity()?.textContent).toBe('Claude Code is working…')- // The composer still refuses while the turn runs.- expect((host.querySelector('textarea') as HTMLTextAreaElement).disabled).toBe(true)+ // The draft stays editable while the turn runs; for claude, Enter queues (chatSendMode).+ const ta = host.querySelector('textarea') as HTMLTextAreaElement+ expect(ta.disabled).toBe(false)+ expect(ta.placeholder).toBe('Claude Code is working — Enter queues your message')})it('a tail read already in flight defers the command read instead of cancelling it', async () => {diff --git a/src/renderer/nodes/ChatPanel.sendGate.test.tsx b/src/renderer/nodes/ChatPanel.sendGate.test.tsxindex b3206e664..c9aa9b652 100644--- a/src/renderer/nodes/ChatPanel.sendGate.test.tsx+++ b/src/renderer/nodes/ChatPanel.sendGate.test.tsx@@ -142,4 +142,63 @@ describe('ChatPanel send gate', () => {})expect(sendChatPrompt).not.toHaveBeenCalled()})++ it('keeps the draft editable while Claude works, and Enter queues it as a "Queued" bubble', async () => {+ setAgentState('working')+ const ta = await mount()+ expect(ta.disabled).toBe(false)+ expect(ta.placeholder).toBe('Claude Code is working — Enter queues your message')+ await act(async () => type(ta, 'and then this'))++ await act(async () => enter(ta))++ expect(sendChatPrompt).toHaveBeenCalledWith(NODE, 'and then this', 'claude')+ const queued = host.querySelector('.term-chat__msg--queued')+ expect(queued?.textContent).toContain('and then this')+ expect(queued?.querySelector('.term-chat__queued-label')?.textContent).toBe('Queued')+ })++ it('a prompt sent while idle is not marked queued', async () => {+ setAgentState('done')+ const ta = await mount()+ await act(async () => type(ta, 'hello'))++ await act(async () => enter(ta))++ expect(host.querySelector('.term-chat__msg--queued')).toBeNull()+ })++ it('does not queue a command mid-turn: the draft stays and a toast says to wait', async () => {+ const toasts: string[] = []+ const onToast = (e: Event): void => {+ toasts.push((e as CustomEvent<{ message: string }>).detail.message)+ }+ window.addEventListener('nodeterm:toast', onToast)+ setAgentState('working')+ const ta = await mount()+ await act(async () => type(ta, '/model'))++ await act(async () => enter(ta))++ window.removeEventListener('nodeterm:toast', onToast)+ expect(sendChatPrompt).not.toHaveBeenCalled()+ expect(ta.value).toBe('/model')+ expect(toasts).toEqual(['Claude Code is working — send commands once the reply finishes.'])+ })++ it('keeps the draft editable while an agent with unmeasured mid-turn input works, but sends nothing', async () => {+ setAgentState('working')+ await act(async () => {+ root.render(<ChatPanel nodeId={NODE} sessionId="s1" agentId="grok" />)+ })+ const ta = host.querySelector('textarea') as HTMLTextAreaElement+ expect(ta.disabled).toBe(false)+ await act(async () => type(ta, 'later'))++ await act(async () => enter(ta))++ expect(sendChatPrompt).not.toHaveBeenCalled()+ expect(ta.value).toBe('later')+ expect(ta.placeholder).toMatch(/send once the reply finishes/)+ })})diff --git a/src/renderer/nodes/ChatPanel.tsx b/src/renderer/nodes/ChatPanel.tsxindex 83fc38b88..6d7d7cab9 100644--- a/src/renderer/nodes/ChatPanel.tsx+++ b/src/renderer/nodes/ChatPanel.tsx@@ -5,7 +5,16 @@ import { renderMarkdown } from '../lib/markdown'import { useAgentStatus } from '../state/agentStatus'import { useSession } from '../session/session'import { chipFor } from '../lib/keybindingOverrides'-import { chatComposerPlaceholder, chatSendRefusal, screenBlockedSentence, type ScreenBlock } from '../lib/chatSendGate'+import {+ canQueue,+ chatComposerPlaceholder,+ chatSendMode,+ chatSendRefusal,+ composerStandsDown,+ screenBlockedSentence,+ type ScreenBlock+} from '../lib/chatSendGate'+import type { ChatMessage } from '@shared/types'import { chatPaneRefusal, chatPaneRefusalToast } from '../lib/chatPaneGate'import { chatAgentLabel, isNearBottom, shouldFollowOnLoad, toolCardTitle } from '../lib/chatPanel'import { useSettings } from '../state/settings'@@ -231,6 +240,8 @@ export function ChatPanel({// Not just `working`: a TUI dialog (`waiting`/`blocked`) would be ANSWERED by sendText's Enter,// and a pane whose CLI is gone (hibernated/paused/dropped/exited) is a SHELL that would execute it.const refusal = chatSendRefusal(agentId, { state, hibernated, paused, dropped, sessionEnded })+ // What Enter does now — `queue` lifts the `working` refusal for a CLI that queues mid-turn input.+ const sendMode = chatSendMode(agentId, { state, hibernated, paused, dropped, sessionEnded })// The agent's OWN dialog on the pane's screen (folder trust, /model, setup questions): no hook// reports those, so the state gate above cannot see them. Found by the poll (local panes, `live`// — the poll also clears it) or by a send core refused before writing (`live: false` — it then@@ -753,11 +764,22 @@ export function ChatPanel({maybeLoadOlder()}+ // The optimistic bubbles sent into the CLI's queue mid-turn, drawn as "Queued" until the transcript+ // has them. Object identity is enough: `applyTail` carries an unconfirmed send as the same object.+ const queuedRef = useRef(new WeakSet<ChatMessage>())+const send = useCallback(async () => {const text = input.trim()+ if (!text) return// Read the store at SEND time, not the render-time values: a PermissionRequest (or an Eco// hibernation) that landed between the last render and this keypress must still block.- if (!text || chatSendRefusal(agentId, useAgentStatus.getState().byId[nodeId] ?? {}) !== null) return+ const mode = chatSendMode(agentId, useAgentStatus.getState().byId[nodeId] ?? {})+ if (mode === null) return+ if (mode === 'queue' && !canQueue(text)) {+ const message = `${chatAgentLabel(agentId, useSettings.getState().settings.customAgents)} is working — send commands once the reply finishes.`+ window.dispatchEvent(new CustomEvent('nodeterm:toast', { detail: { kind: 'error', message } }))+ return+ }// The kernel's say (chatPaneGate.ts): an agent that announces no quit (codex) may have left a// SHELL in the pane while the store still reads `done` — typed there, the message would run.const pane = await chatPaneRefusal(agentId, nodeId, {@@ -790,7 +812,9 @@ export function ChatPanel({// (`carryUnconfirmed`); the turn-end reload / ↻ reconcile from the transcript outright.setScreenBlock(null)justSentRef.current = true- setThread((t) => ({ ...t, messages: [...t.messages, { role: 'user', parts: [{ kind: 'text', text }] }] }))+ const sent: ChatMessage = { role: 'user', parts: [{ kind: 'text', text }] }+ if (mode === 'queue') queuedRef.current.add(sent)+ setThread((t) => ({ ...t, messages: [...t.messages, sent] }))setOptimistic(true)setInput('')// A built-in that opens a dialog in the TUI (`/rewind`, `/resume`, `/model`, …) is now on screen@@ -934,7 +958,9 @@ export function ChatPanel({// bubble) fall back to their position.<divkey={m.key !== undefined ? `k${m.key}` : `i${i}`}- className={`term-chat__msg term-chat__msg--${m.role}${m.role === 'user' ? ' term-chat__bubble' : ''}`}+ className={`term-chat__msg term-chat__msg--${m.role}${m.role === 'user' ? ' term-chat__bubble' : ''}${+ queuedRef.current.has(m) ? ' term-chat__msg--queued' : ''+ }`}>{m.parts.map((p, j) =>p.kind === 'text' ? (@@ -986,6 +1012,7 @@ export function ChatPanel({</details>))}+ {queuedRef.current.has(m) && <div className="term-chat__queued-label">Queued</div>}{turnEnds.has(i) && (<ChatTurnActionscopyText={turnEnds.get(i)!.copyText}@@ -1035,11 +1062,13 @@ export function ChatPanel({agentLabel,chip: mdChip,answerOnCard: answerCard !== null,+ sendMode,screen: screenBlock?.live === true ? screenBlock.kind : null})}// A dialog the POLL found is also cleared by it; one a refused send found is not (a remote// pane is never polled), so that one leaves the draft editable for the resend.- disabled={readonly || refusal !== null || screenBlock?.live === true}+ disabled={readonly || composerStandsDown(refusal) || screenBlock?.live === true}+ agentBusy={refusal === 'working'}onWriteRefused={onWriteRefused}sendUnconfirmed={optimistic}pathsForFiles={pathsForFiles}diff --git a/src/renderer/styles.css b/src/renderer/styles.cssindex 937600e7d..d6141f854 100644--- a/src/renderer/styles.css+++ b/src/renderer/styles.css@@ -3326,6 +3326,18 @@ body,background: rgba(var(--tint-rgb), 0.09);color: var(--text-strong);}+/* Sent while the agent was working: it sits in the CLI's own queue until the transcript shows it+ (ChatPanel's queuedRef). A dashed outline on the same bubble, dimmed, with a "Queued" caption. */+.term-chat__msg--queued {+ background: none;+ border: 1px dashed rgba(var(--tint-rgb), 0.35);+ color: var(--muted);+}+.term-chat__queued-label {+ margin-top: 4px;+ font-size: 11px;+ color: var(--muted);+}.term-chat__msg--assistant {align-self: stretch;max-width: none;diff --git a/src/shared/agents/config.capabilities.test.ts b/src/shared/agents/config.capabilities.test.tsindex dbf099e32..883563a2e 100644--- a/src/shared/agents/config.capabilities.test.ts+++ b/src/shared/agents/config.capabilities.test.ts@@ -27,6 +27,7 @@ import {resumeCommand,hasHooksOverSsh,readsScreenDialogs,+ queuesInputWhileWorking,LOCAL_ONLY_HOOK_AGENTS,reportsSessionEnd} from './config'@@ -463,3 +464,10 @@ describe('readsScreenDialogs — whose own dialogs the chat view can see on screfor (const id of BUILTIN_AGENT_IDS.filter((a) => a !== 'claude')) expect(readsScreenDialogs(id)).toBe(false)})})++describe('queuesInputWhileWorking — who may be sent to mid-turn from the chat view', () => {+ it('is claude only: every other CLI\'s mid-turn input is unmeasured and may answer what is on screen', () => {+ expect(queuesInputWhileWorking('claude')).toBe(true)+ for (const id of BUILTIN_AGENT_IDS.filter((a) => a !== 'claude')) expect(queuesInputWhileWorking(id)).toBe(false)+ })+})diff --git a/src/shared/agents/config.ts b/src/shared/agents/config.tsindex c740810cc..8c4021f33 100644--- a/src/shared/agents/config.ts+++ b/src/shared/agents/config.ts@@ -332,6 +332,13 @@ export const CLAUDE_TRANSCRIPT_READABLE = ['claude'] as const// claude's screen layout (MEASURED on 2.1.283); another CLI's layout would read as a permanent// dialog and lock its chat view, so each agent needs its own measured reader.export const SCREEN_DIALOG_READABLE = ['claude'] as const+// Agents whose CLI QUEUES a prompt submitted while a turn is running, instead of treating it as+// input to whatever is on screen. The chat view (⌘M) sends into the pane exactly as typing would, so+// only for these may it send while the agent is `working`. MEASURED for claude (2.1.281, 2026-09-23):+// a prompt submitted mid-turn (pasted or typed) shows "Press up to edit queued messages" and is+// delivered at the next tool boundary of the SAME turn (a `queued_command` transcript attachment, not+// a new user turn). Every other chat-capable agent is unmeasured and keeps "wait for the reply".+export const INPUT_QUEUE_CAPABLE = ['claude'] as const// Agents whose native transcript we can read + render for cross-agent transfer.export const TRANSFER_SOURCE_CAPABLE = ['claude', 'codex', 'gemini', 'grok'] as const// Agents whose hooks announce that a session ENDED — i.e. whose orderly `/exit` we will hear about.@@ -545,6 +552,7 @@ export const hasUsage = (id: AgentId): boolean => includes(USAGE_CAPABLE, id)export const canChat = (id: AgentId): boolean => includes(CHAT_CAPABLE, id)export const chatReadsLocalOnly = (id: AgentId): boolean => includes(CHAT_LOCAL_ONLY, id)export const readsScreenDialogs = (id: AgentId): boolean => includes(SCREEN_DIALOG_READABLE, id)+export const queuesInputWhileWorking = (id: AgentId): boolean => includes(INPUT_QUEUE_CAPABLE, id)/** Can CLAUDE's transcript resolver locate and parse this agent's conversation? Never widen this* to mean "can we read this agent" — see CLAUDE_TRANSCRIPT_READABLE. */export const readsClaudeShapedTranscript = (id: AgentId): boolean =>