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): a sent local command retires the working row once confirmed
review4b409344f61c
diff --git a/src/core/chat-fixtures.test.ts b/src/core/chat-fixtures.test.tsindex 0a7d62dc5..c0edd14e4 100644--- a/src/core/chat-fixtures.test.ts+++ b/src/core/chat-fixtures.test.ts@@ -393,6 +393,12 @@ function metaTurns(): string {// `promptSource` alone is enough to keep it.{ ...isMeta(user('System prompt source only.')), promptSource: 'system' },assistant([text('Seen.')]),+ // `origin` alone (no promptSource): kept — a port checking only promptSource fails here.+ { ...isMeta(user('Hand-back with origin only.')), origin: { kind: 'peer', from: 'demo-peer' } },+ assistant([text('Seen too.')]),+ // `turnOrigin` alone (no promptSource): kept.+ { ...isMeta(user('Wakeup with turnOrigin only.')), turnOrigin: 'scheduled' },+ assistant([text('Awake.')]),// A skill body (isMeta, none of the three fields): still skipped.isMeta(user([text('Base directory for this skill: /srv/demo/skills/demo-skill')]))])diff --git a/src/renderer/lib/chatPaging.test.ts b/src/renderer/lib/chatPaging.test.tsindex 8553a4a00..6b414e9a2 100644--- a/src/renderer/lib/chatPaging.test.ts+++ b/src/renderer/lib/chatPaging.test.ts@@ -4,6 +4,7 @@ import {anchoredScrollTop,applyOlder,applyTail,+ tailConfirmsSends,attachCarried,emptyThread,shouldFetchOlder,@@ -198,6 +199,19 @@ describe('applyTail — unconfirmed optimistic sends (live reads)', () => {expect(sentTexts(live(`/compact ${arg}`, [cmd(100, '/compact', arg.slice(0, 200))]))).toEqual([])})+ it('tailConfirmsSends: true only when the read confirms every trailing optimistic send', () => {+ const t = base([say(0, 'q'), say(undefined, '/model', 'user')], 0)+ expect(tailConfirmsSends(t, ID, page([say(0, 'q'), cmd(100, '/model')], 0))).toBe(true)+ expect(tailConfirmsSends(t, ID, page([say(0, 'q')], 0))).toBe(false)+ // Nothing was waiting: nothing to confirm.+ expect(tailConfirmsSends(base([say(0, 'q')], 0), ID, page([say(0, 'q'), cmd(100, '/model')], 0))).toBe(false)+ // Another transcript never confirms this one's sends.+ expect(tailConfirmsSends(t, 'other', page([cmd(100, '/model')], 0))).toBe(false)+ // Two sends, one confirmed: still waiting.+ const two = base([say(0, 'q'), say(undefined, '/model', 'user'), say(undefined, '/model', 'user')], 0)+ expect(tailConfirmsSends(two, ID, page([say(0, 'q'), cmd(100, '/model')], 0))).toBe(false)+ })+it('a NON-live reload (turn end, ↻) retires any unconfirmed carry', () => {const t = base([say(0, 'q'), say(undefined, 'never matches', 'user')], 0)const out = applyTail(t, ID, page([say(0, 'q'), say(100, 'transformed prompt', 'user')], 0))diff --git a/src/renderer/lib/chatPaging.ts b/src/renderer/lib/chatPaging.tsindex 959386301..6c32fc896 100644--- a/src/renderer/lib/chatPaging.ts+++ b/src/renderer/lib/chatPaging.ts@@ -128,6 +128,27 @@ const userText = (m: ChatMessage): string =>.join('').trim()+/** The thread's TRAILING unkeyed user messages — the optimistic sends a live read may still carry. */+function trailingSends(t: ChatThread): ChatMessage[] {+ const trailing: ChatMessage[] = []+ for (let i = t.messages.length - 1; i >= 0; i--) {+ const m = t.messages[i]+ if (m.key !== undefined || m.role !== 'user') break+ trailing.unshift(m)+ }+ return trailing+}++/**+ * Would a LIVE read (`applyTail` with `carryUnconfirmed`) confirm every optimistic send the thread+ * is waiting on? False when nothing was waiting, or for another transcript. The panel uses it to+ * retire its optimistic working row when no hook will: a local command (`/model`, `!ls`) is+ * confirmed only by its command record, and fires no state change.+ */+export function tailConfirmsSends(t: ChatThread, identity: string, res: ChatTranscriptResult): boolean {+ return t.identity === identity && trailingSends(t).length > 0 && unconfirmedSends(t, res).length === 0+}+/** A command message's tool part (`/model`, `!`), as the reader renders a command record. */function commandPart(m: ChatMessage): { name: string; arg: string } | null {if (m.role !== 'assistant' || m.parts.length !== 1) return null@@ -154,15 +175,14 @@ function commandPart(m: ChatMessage): { name: string; arg: string } | null {* send whose transcript line never matches (a CLI that rewrites the prompt) must not stay duplicated.*/function unconfirmedSends(t: ChatThread, res: ChatTranscriptResult): ChatMessage[] {- const trailing: ChatMessage[] = []- for (let i = t.messages.length - 1; i >= 0; i--) {- const m = t.messages[i]- if (m.key !== undefined || m.role !== 'user') break- trailing.unshift(m)- }+ const trailing = trailingSends(t)if (trailing.length === 0) return []let newest = -Infinityfor (const m of t.messages) if (m.key !== undefined && m.key > newest) newest = m.key+ // Known limitation: "newer than anything keyed" is all this can know. A line written after the+ // last read by someone ELSE — the same command (or, on the exact-text path, the same text) typed+ // in the TERMINAL — is indistinguishable from the composer's own send and confirms it early. The+ // transcript records no sender to tell them apart.const fresh = res.messages.filter((m) => m.key === undefined || m.key > newest)const available = fresh.filter((m) => m.role === 'user').map(userText)// A slash command / `!` line is recorded as a command, which the reader renders as an assistantdiff --git a/src/renderer/nodes/ChatPanel.live.test.tsx b/src/renderer/nodes/ChatPanel.live.test.tsxindex 0ab776847..3711a1108 100644--- a/src/renderer/nodes/ChatPanel.live.test.tsx+++ b/src/renderer/nodes/ChatPanel.live.test.tsx@@ -334,3 +334,130 @@ describe('ChatPanel live progress', () => {}})})++// A local command (`/model`, `!ls`) fires NO hook: the state never changes, so nothing would retire+// the optimistic working row but its 15 s timeout, and no live read runs (the agent is not working).+// A command send therefore schedules ONE tail read, and a read that confirms the send retires the row.+describe('ChatPanel — a sent local command', () => {+ const cmd = (key: number, name: string, arg = ''): ChatMessage => ({+ role: 'assistant',+ key,+ parts: [{ kind: 'tool', name, arg }]+ })+ async function type(text: string): Promise<void> {+ const ta = host.querySelector('textarea') as HTMLTextAreaElement+ await act(async () => {+ Object.getOwnPropertyDescriptor(HTMLTextAreaElement.prototype, 'value')!.set!.call(ta, text)+ ta.dispatchEvent(new Event('input', { bubbles: true }))+ })+ await act(async () => {+ ta.dispatchEvent(new KeyboardEvent('keydown', { key: 'Enter', bubbles: true, cancelable: true }))+ })+ }++ it('/model: one tail read after the throttle interval confirms it and retires the working row', async () => {+ await hook('done')+ await render()+ await settle(0, { messages: [say(0, 'hello')], olderCursor: 0 })+ await type('/model')+ expect(activity()).not.toBeNull()+ await advance(CHAT_LIVE_RELOAD_MIN_MS - 1)+ expect(pending.length).toBe(1)+ await advance(1)+ expect(pending.length).toBe(2)+ expect(pending[1].page).toEqual({ maxBytes: CHAT_TAIL_PAGE_BYTES })+ await settle(1, { messages: [say(0, 'hello'), cmd(100, '/model')], olderCursor: 0 })+ expect(activity()).toBeNull()+ // Exactly one read: nothing else is scheduled.+ await advance(CHAT_OPTIMISTIC_WORKING_MS)+ expect(pending.length).toBe(2)+ })++ it('`!ls` is a command send too', async () => {+ await hook('done')+ await render()+ await settle(0, { messages: [say(0, 'hello')], olderCursor: 0 })+ await type('!ls')+ await advance(CHAT_LIVE_RELOAD_MIN_MS)+ expect(pending.length).toBe(2)+ await settle(1, { messages: [say(0, 'hello'), cmd(100, '!', 'ls')], olderCursor: 0 })+ expect(activity()).toBeNull()+ })++ it('a read that does NOT confirm the command leaves the row to its timeout', async () => {+ await hook('done')+ await render()+ await settle(0, { messages: [say(0, 'hello')], olderCursor: 0 })+ await type('/model')+ await advance(CHAT_LIVE_RELOAD_MIN_MS)+ await settle(1, { messages: [say(0, 'hello')], olderCursor: 0 })+ expect(activity()).not.toBeNull()+ // A LIVE read: the unconfirmed send stays on screen (a non-live read would drop it).+ expect(bubbles().some((b) => b.includes('/model'))).toBe(true)+ })++ it('a command that starts a real turn (/compact) keeps the working row through its working state', async () => {+ await hook('done')+ await render()+ await settle(0, { messages: [say(0, 'hello')], olderCursor: 0 })+ await type('/compact keep notes')+ await hook('working', true)+ // Settle every read (the hook's live read and the command read), each confirming the command.+ for (let i = 0; i < 4; i++) {+ await advance(CHAT_LIVE_RELOAD_MIN_MS)+ for (let j = 1; j < pending.length; j++)+ await settle(j, { messages: [say(0, 'hello'), cmd(100, '/compact', 'keep notes')], olderCursor: 0 })+ }+ 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)+ })++ it('a tail read already in flight defers the command read instead of cancelling it', async () => {+ await hook('done')+ await render()+ await settle(0, { messages: [say(0, 'hello')], olderCursor: 0 })+ await type('/model')+ await act(async () => (host.querySelector('.term-chat__bar .term-chat__refresh') as HTMLButtonElement).click())+ expect(pending.length).toBe(2) // ↻, in flight+ await advance(CHAT_LIVE_RELOAD_MIN_MS)+ expect(pending.length).toBe(2) // deferred, not started over it+ await settle(1, { messages: [say(0, 'hello')], olderCursor: 0 })+ await advance(CHAT_LIVE_RELOAD_MIN_MS)+ expect(pending.length).toBe(3)+ })++ it('a plain text send schedules no read', async () => {+ await hook('done')+ await render()+ await settle(0, { messages: [say(0, 'hello')], olderCursor: 0 })+ await type('just a question')+ await advance(CHAT_LIVE_RELOAD_MIN_MS * 3)+ expect(pending.length).toBe(1)+ })++ it('the scheduled read is cancelled on unmount', async () => {+ await hook('done')+ await render()+ await settle(0, { messages: [say(0, 'hello')], olderCursor: 0 })+ await type('/model')+ await act(async () => root.unmount())+ await advance(CHAT_LIVE_RELOAD_MIN_MS * 3)+ expect(pending.length).toBe(1)+ root = createRoot(host) // afterEach unmounts again+ })++ it('the scheduled read is cancelled when the transcript identity changes', async () => {+ await hook('done')+ await render()+ await settle(0, { messages: [say(0, 'hello')], olderCursor: 0 })+ await type('/model')+ await act(async () => {+ root.render(<ChatPanel nodeId={NODE} sessionId="s2" agentId="claude" />)+ })+ const after = pending.length // the new session's own initial read+ await advance(CHAT_LIVE_RELOAD_MIN_MS * 3)+ expect(pending.length).toBe(after)+ })+})diff --git a/src/renderer/nodes/ChatPanel.tsx b/src/renderer/nodes/ChatPanel.tsxindex 863a827a8..2bc3a415b 100644--- a/src/renderer/nodes/ChatPanel.tsx+++ b/src/renderer/nodes/ChatPanel.tsx@@ -13,13 +13,15 @@ import {anchoredScrollTop,applyOlder,applyTail,+ tailConfirmsSends,emptyThread,shouldFetchOlder,type ChatThread} from '../lib/chatPaging'import { E_UNSUPPORTED } from '@shared/rpc'import { Spinner } from '../components/Spinner'-import { CHAT_OPTIMISTIC_WORKING_MS, chatActivity, planLiveReload } from '../lib/chatLive'+import { CHAT_LIVE_RELOAD_MIN_MS, CHAT_OPTIMISTIC_WORKING_MS, chatActivity, planLiveReload } from '../lib/chatLive'+import { sentCommand } from '@shared/chat-command'import { ChatLoadingStatus } from './ChatPanelFallback'import { answerCardState, answerRebindPending, rebindRetryDelay, type BoundAnswerCard } from '../lib/chatAnswer'import { AnswerControlsUpdating, PlanAnswerControls, QuestionAnswerControls } from './ChatAnswerControls'@@ -267,6 +269,9 @@ export function ChatPanel({// (single-flight, like the live reads) — never dropped, since the read in flight started under the// PREVIOUS request and cannot bind the new one. Any read that STARTS later satisfies it.const heldReloadQueuedRef = useRef(false)+ // The ONE tail read a sent local command schedules (see `send`): `/model` or `!ls` fires no hook,+ // so neither a state change nor a live read would ever confirm it.+ const commandReadTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null)const loadRef = useRef<(live?: boolean, rebind?: boolean) => void>(() => {})const requestHeldReloadRef = useRef<() => void>(() => {})@@ -338,6 +343,10 @@ export function ChatPanel({settleHeldReload(heldAtStart)return}+ // A read that confirms every optimistic send retires the working row: for a local+ // command it is the ONLY signal (no hook fires). A command that starts a real turn is+ // still covered — its `working` state keeps the row (and the send refusal) on its own.+ if (tailConfirmsSends(threadRef.current, identity, res)) setOptimistic(false)setThread((t) => applyTail(t, identity, res, { carryUnconfirmed: live || rebind }))setLoadState('ok')setHeldRead({ identity, pendingId: heldAtStart })@@ -639,8 +648,32 @@ export function ChatPanel({setThread((t) => ({ ...t, messages: [...t.messages, { role: 'user', parts: [{ kind: 'text', text }] }] }))setOptimistic(true)setInput('')+ // A local command (`/model`, `!ls`) fires no hook: schedule ONE live tail read, one throttle+ // interval out (claude writes the command record once the command ran), so its confirmation+ // retires the working row instead of the 15 s timeout. A read already in flight defers it.+ if (sentCommand(text)) {+ if (commandReadTimerRef.current !== null) clearTimeout(commandReadTimerRef.current)+ const fire = () => {+ if (tailInFlightRef.current || olderInFlightRef.current) {+ commandReadTimerRef.current = setTimeout(fire, CHAT_LIVE_RELOAD_MIN_MS)+ return+ }+ commandReadTimerRef.current = null+ loadRef.current(true)+ }+ commandReadTimerRef.current = setTimeout(fire, CHAT_LIVE_RELOAD_MIN_MS)+ }}, [api, input, nodeId, agentId])+ // The scheduled command read belongs to THIS transcript and this mount.+ useEffect(+ () => () => {+ if (commandReadTimerRef.current !== null) clearTimeout(commandReadTimerRef.current)+ commandReadTimerRef.current = null+ },+ [identity]+ )+const onWriteRefused = useCallback(() => setReadonly(true), [])// Answer the held request through core, which validates the answer against the pending requestdiff --git a/src/shared/chat-fixtures/README.md b/src/shared/chat-fixtures/README.mdindex 063822cae..f324b2f15 100644--- a/src/shared/chat-fixtures/README.md+++ b/src/shared/chat-fixtures/README.md@@ -84,7 +84,7 @@ the production paging, not a second implementation of it.| `thinking` | Thinking blocks (`thinking`, `redacted_thinking`). The current TS reader **drops** them: a thinking-only record yields no message, and a mixed record keeps only its text. The port must match this until the desktop reader changes. || `local-commands` | Slash-command records (see **Local commands** below). An `isMeta` caveat is skipped; `/model` plus its ANSI-coloured `<local-command-stdout>` become ONE assistant tool part `{name:"/model", arg:"", result}`; `/effort` with padded args (trimmed) answered on `<local-command-stderr>`; `/compact` with an arg longer than the 200-unit cap; `/exit` with an empty stdout (no `result`); a skill invocation (`<command-message>` before `<command-name>`) whose `isMeta` array body is skipped; a stdout with no command right before it (its own `command output` tool, capped to three lines); and a user message that only mentions `<command-name>` in prose (stays a user message). || `bash-mode` | `!` bash-mode records: `<bash-input>` becomes a tool part named `!` with the command as `arg`; the ONE following record carrying `<bash-stdout>…</bash-stdout><bash-stderr>…</bash-stderr>` sets its `result` (non-empty parts joined by `\n`, then the `summarizeResult` cap), including an empty stdout with a stderr. |-| `meta-turns` | `isMeta` rule 1: a peer hand-back (`promptSource` + `origin.kind:"peer"` + `turnOrigin`), a scheduled wakeup (`turnOrigin:"scheduled"` + `scheduledTaskId`), an auto-continuation (`origin.kind:"auto-continuation"`) and a `promptSource`-only record stay user messages; the caveat and a skill body (none of the three fields) are skipped. |+| `meta-turns` | `isMeta` rule 1: a peer hand-back (`promptSource` + `origin.kind:"peer"` + `turnOrigin`), a scheduled wakeup (`turnOrigin:"scheduled"` + `scheduledTaskId`), an auto-continuation (`origin.kind:"auto-continuation"`) a `promptSource`-only, an `origin`-only and a `turnOrigin`-only record (the last two with no `promptSource`, so each field is pinned on its own) stay user messages; the caveat and a skill body (none of the three fields) are skipped. |Decision cases: plan `restore` / `acceptEdits` / `manual` / `revise` (the revise text is trimmed),question single / multi (labels joined with `, `) / free text (trimmed), and three refusals: adiff --git a/src/shared/chat-fixtures/expected/meta-turns.pages.json b/src/shared/chat-fixtures/expected/meta-turns.pages.jsonindex 57b644597..420ce7952 100644--- a/src/shared/chat-fixtures/expected/meta-turns.pages.json+++ b/src/shared/chat-fixtures/expected/meta-turns.pages.json@@ -104,6 +104,50 @@],"at": 1790362809000,"key": 3512+ },+ {+ "role": "user",+ "parts": [+ {+ "kind": "text",+ "text": "Hand-back with origin only."+ }+ ],+ "at": 1790362810000,+ "key": 3900+ },+ {+ "role": "assistant",+ "parts": [+ {+ "kind": "text",+ "text": "Seen too."+ }+ ],+ "at": 1790362811000,+ "key": 4234+ },+ {+ "role": "user",+ "parts": [+ {+ "kind": "text",+ "text": "Wakeup with turnOrigin only."+ }+ ],+ "at": 1790362812000,+ "key": 4626+ },+ {+ "role": "assistant",+ "parts": [+ {+ "kind": "text",+ "text": "Awake."+ }+ ],+ "at": 1790362813000,+ "key": 4942}],"olderCursor": null,diff --git a/src/shared/chat-fixtures/inputs/meta-turns.jsonl b/src/shared/chat-fixtures/inputs/meta-turns.jsonlindex 8cebef7ef..381ce2680 100644--- a/src/shared/chat-fixtures/inputs/meta-turns.jsonl+++ b/src/shared/chat-fixtures/inputs/meta-turns.jsonl@@ -8,4 +8,8 @@{"type":"assistant","effort":"high","message":{"id":"msg_synthetic","type":"message","role":"assistant","model":"claude-opus-5-5","content":[{"type":"text","text":"Continuing."}],"stop_reason":null},"isSidechain":false,"sessionId":"5f0c2a9e-3b7d-4e61-9a24-7c1d8e0f4b32","cwd":"/srv/demo","version":"2.1.290","uuid":"00000000-0000-4000-8000-000000000007","timestamp":"2026-09-25T19:00:07.000Z"}{"type":"user","message":{"role":"user","content":"System prompt source only."},"isMeta":true,"promptSource":"system","isSidechain":false,"sessionId":"5f0c2a9e-3b7d-4e61-9a24-7c1d8e0f4b32","cwd":"/srv/demo","version":"2.1.290","uuid":"00000000-0000-4000-8000-000000000008","timestamp":"2026-09-25T19:00:08.000Z"}{"type":"assistant","effort":"high","message":{"id":"msg_synthetic","type":"message","role":"assistant","model":"claude-opus-5-5","content":[{"type":"text","text":"Seen."}],"stop_reason":null},"isSidechain":false,"sessionId":"5f0c2a9e-3b7d-4e61-9a24-7c1d8e0f4b32","cwd":"/srv/demo","version":"2.1.290","uuid":"00000000-0000-4000-8000-000000000009","timestamp":"2026-09-25T19:00:09.000Z"}-{"type":"user","message":{"role":"user","content":[{"type":"text","text":"Base directory for this skill: /srv/demo/skills/demo-skill"}]},"isMeta":true,"isSidechain":false,"sessionId":"5f0c2a9e-3b7d-4e61-9a24-7c1d8e0f4b32","cwd":"/srv/demo","version":"2.1.290","uuid":"00000000-0000-4000-8000-000000000010","timestamp":"2026-09-25T19:00:10.000Z"}+{"type":"user","message":{"role":"user","content":"Hand-back with origin only."},"isMeta":true,"origin":{"kind":"peer","from":"demo-peer"},"isSidechain":false,"sessionId":"5f0c2a9e-3b7d-4e61-9a24-7c1d8e0f4b32","cwd":"/srv/demo","version":"2.1.290","uuid":"00000000-0000-4000-8000-000000000010","timestamp":"2026-09-25T19:00:10.000Z"}+{"type":"assistant","effort":"high","message":{"id":"msg_synthetic","type":"message","role":"assistant","model":"claude-opus-5-5","content":[{"type":"text","text":"Seen too."}],"stop_reason":null},"isSidechain":false,"sessionId":"5f0c2a9e-3b7d-4e61-9a24-7c1d8e0f4b32","cwd":"/srv/demo","version":"2.1.290","uuid":"00000000-0000-4000-8000-000000000011","timestamp":"2026-09-25T19:00:11.000Z"}+{"type":"user","message":{"role":"user","content":"Wakeup with turnOrigin only."},"isMeta":true,"turnOrigin":"scheduled","isSidechain":false,"sessionId":"5f0c2a9e-3b7d-4e61-9a24-7c1d8e0f4b32","cwd":"/srv/demo","version":"2.1.290","uuid":"00000000-0000-4000-8000-000000000012","timestamp":"2026-09-25T19:00:12.000Z"}+{"type":"assistant","effort":"high","message":{"id":"msg_synthetic","type":"message","role":"assistant","model":"claude-opus-5-5","content":[{"type":"text","text":"Awake."}],"stop_reason":null},"isSidechain":false,"sessionId":"5f0c2a9e-3b7d-4e61-9a24-7c1d8e0f4b32","cwd":"/srv/demo","version":"2.1.290","uuid":"00000000-0000-4000-8000-000000000013","timestamp":"2026-09-25T19:00:13.000Z"}+{"type":"user","message":{"role":"user","content":[{"type":"text","text":"Base directory for this skill: /srv/demo/skills/demo-skill"}]},"isMeta":true,"isSidechain":false,"sessionId":"5f0c2a9e-3b7d-4e61-9a24-7c1d8e0f4b32","cwd":"/srv/demo","version":"2.1.290","uuid":"00000000-0000-4000-8000-000000000014","timestamp":"2026-09-25T19:00:14.000Z"}