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): show ExitPlanMode plans and AskUserQuestion questions in the ⌘M view
review18adca9478bb
diff --git a/CLAUDE.md b/CLAUDE.mdindex 8c001ad3a..12d6d4026 100644--- a/CLAUDE.md+++ b/CLAUDE.md@@ -2438,6 +2438,14 @@ command-bearing opens; this does not add a human-confirm dialog or change mobilestore at send time, not only at render. Same trap as the in-place restart's `/exit`. The bar's ↻reloads on demand (beside the empty state's Retry), since a session whose hooks never report`working` never takes the turn-finish reload.+ **Plan and question bodies (2026-09).** A tool call is normally a collapsed chip (`name` + a+ ≤200-char `arg`), which left an `ExitPlanMode` plan — the full markdown the terminal shows as+ "Here is Claude's plan" — and an `AskUserQuestion` question + options unreadable in ⌘M, the one+ place meant for reading them. `core/chat-tool-body.ts` (pure) fills the tool part's optional+ `body` for exactly those two tools (`input.plan`; the questions rendered as markdown), capped at+ 64 KB, degrading to no body (the old chip) on any other shape; ChatPanel shows a part with a+ body as an expanded "Plan"/"Question" card through `MarkdownText` with its result under it, and+ the find-bar index (`linesFrom`) indexes the body in full like assistant text.- **Subagent visualization** (agents in `SUBAGENT_CAPABLE`) — `subagent-start`/`subagent-end`normalized events (from Claude's `PreToolUse`/`PostToolUse` on tool `Agent`/`Task`, correlatedby `tool_use_id`) drive a transient `state/agentNodes.ts` store. Claude launches subagentsdiff --git a/src/core/chat-tool-body.test.ts b/src/core/chat-tool-body.test.tsnew file mode 100644index 000000000..ba5710a06--- /dev/null+++ b/src/core/chat-tool-body.test.ts@@ -0,0 +1,99 @@+import { describe, expect, it } from 'vitest'+import { TOOL_BODY_CAP, TOOL_BODY_TRUNCATED, toolBody } from './chat-tool-body'++// Input shapes measured on this server's transcripts (2026-09-26):+// ExitPlanMode → {"plan": "<full markdown plan>"}+// AskUserQuestion → {"questions": [{"question", "header", "multiSelect", "options": [{"label", "description"?}]}]}++describe('toolBody — ExitPlanMode', () => {+ it('returns the plan markdown verbatim', () => {+ const plan = '# Fix the chat view\n\n1. Parse the plan\n2. Render it'+ expect(toolBody('ExitPlanMode', { plan })).toBe(plan)+ })++ it('degrades to no body for a missing, non-string or blank plan', () => {+ expect(toolBody('ExitPlanMode', {})).toBeUndefined()+ expect(toolBody('ExitPlanMode', { plan: 42 })).toBeUndefined()+ expect(toolBody('ExitPlanMode', { plan: ['a'] })).toBeUndefined()+ expect(toolBody('ExitPlanMode', { plan: ' \n ' })).toBeUndefined()+ expect(toolBody('ExitPlanMode', null)).toBeUndefined()+ expect(toolBody('ExitPlanMode', 'plan')).toBeUndefined()+ })++ it('caps an oversized plan with a truncation marker', () => {+ const body = toolBody('ExitPlanMode', { plan: 'x'.repeat(TOOL_BODY_CAP + 500) })!+ expect(body.startsWith('x'.repeat(100))).toBe(true)+ expect(body.endsWith(TOOL_BODY_TRUNCATED)).toBe(true)+ expect(body.length).toBe(TOOL_BODY_CAP + TOOL_BODY_TRUNCATED.length)+ })++ it('never splits a surrogate pair at the cap', () => {+ const plan = 'a'.repeat(TOOL_BODY_CAP - 1) + '😀' + 'tail'+ const body = toolBody('ExitPlanMode', { plan })!+ const kept = body.slice(0, body.length - TOOL_BODY_TRUNCATED.length)+ expect(kept).toBe('a'.repeat(TOOL_BODY_CAP - 1))+ })++ it('leaves a plan exactly at the cap untouched', () => {+ const plan = 'y'.repeat(TOOL_BODY_CAP)+ expect(toolBody('ExitPlanMode', { plan })).toBe(plan)+ })+})++describe('toolBody — AskUserQuestion', () => {+ it('renders header, question and options with descriptions', () => {+ const input = {+ questions: [+ {+ question: 'Which database should we use?',+ header: 'Database',+ multiSelect: false,+ options: [+ { label: 'Postgres', description: 'Relational, battle-tested' },+ { label: 'SQLite' }+ ]+ }+ ]+ }+ expect(toolBody('AskUserQuestion', input)).toBe(+ '**Database**\n\nWhich database should we use?\n\n- **Postgres** — Relational, battle-tested\n- **SQLite**'+ )+ })++ it('notes multiple choice and separates several questions', () => {+ const input = {+ questions: [+ { question: 'Pick features', header: 'Scope', multiSelect: true, options: [{ label: 'A' }, { label: 'B' }] },+ { question: 'Ship today?', options: [{ label: 'Yes' }] }+ ]+ }+ expect(toolBody('AskUserQuestion', input)).toBe(+ '**Scope**\n\nPick features _(multiple choice)_\n\n- **A**\n- **B**\n\nShip today?\n\n- **Yes**'+ )+ })++ it('skips malformed questions and options, and degrades to no body when nothing is left', () => {+ expect(toolBody('AskUserQuestion', {})).toBeUndefined()+ expect(toolBody('AskUserQuestion', { questions: 'x' })).toBeUndefined()+ expect(toolBody('AskUserQuestion', { questions: [] })).toBeUndefined()+ expect(toolBody('AskUserQuestion', { questions: [null, 3, { header: 'H' }, { question: 7 }] })).toBeUndefined()+ const input = {+ questions: [+ null,+ { question: 'Q?', header: 5, multiSelect: 'yes', options: [null, { label: 3 }, { label: 'ok', description: 9 }] }+ ]+ }+ expect(toolBody('AskUserQuestion', input)).toBe('Q?\n\n- **ok**')+ })++ it('renders a question with no options as just the question', () => {+ expect(toolBody('AskUserQuestion', { questions: [{ question: 'Anything else?' }] })).toBe('Anything else?')+ })+})++describe('toolBody — every other tool', () => {+ it('has no body (it stays a collapsed chip)', () => {+ expect(toolBody('Bash', { command: 'ls', plan: 'not a plan' })).toBeUndefined()+ expect(toolBody('ToolSearch', { query: 'x' })).toBeUndefined()+ })+})diff --git a/src/core/chat-tool-body.ts b/src/core/chat-tool-body.tsnew file mode 100644index 000000000..25cd6faf4--- /dev/null+++ b/src/core/chat-tool-body.ts@@ -0,0 +1,57 @@+// The readable body of a tool call in the ⌘M chat view. Most tool calls are plumbing — a one-line+// chip (`Bash ls`) says all there is to say. Two are not: `ExitPlanMode` carries the full plan the+// user is being asked to approve, and `AskUserQuestion` carries the question and its options. The+// terminal shows both in full ("Ready to code? Here is Claude's plan: …"); the chat view showed a+// bare `ExitPlanMode` chip, so the one thing ⌘M exists for — reading it properly — was missing.+//+// PURE. Input shapes measured on real transcripts (2026-09-26):+// ExitPlanMode → {"plan": "<full markdown plan>"}+// AskUserQuestion → {"questions": [{"question", "header", "multiSelect", "options": [{"label", "description"?}]}]}+// Anything that does not match degrades to NO body (today's chip) — never a half-rendered guess.++/** The body crosses IPC/WS with every chat read; a plan is prose, and 64 KB is far past any real one. */+export const TOOL_BODY_CAP = 64 * 1024+export const TOOL_BODY_TRUNCATED = '\n\n… (truncated)'++function capBody(s: string): string {+ if (s.length <= TOOL_BODY_CAP) return s+ let end = TOOL_BODY_CAP+ // Do not leave half a surrogate pair (an emoji) dangling at the cut.+ const last = s.charCodeAt(end - 1)+ if (last >= 0xd800 && last <= 0xdbff) end -= 1+ return s.slice(0, end) + TOOL_BODY_TRUNCATED+}++const isObj = (v: unknown): v is Record<string, unknown> => !!v && typeof v === 'object' && !Array.isArray(v)+const nonBlank = (v: unknown): v is string => typeof v === 'string' && v.trim() !== ''++function planBody(input: Record<string, unknown>): string | undefined {+ return nonBlank(input.plan) ? input.plan : undefined+}++function questionsBody(input: Record<string, unknown>): string | undefined {+ if (!Array.isArray(input.questions)) return undefined+ const blocks: string[] = []+ for (const q of input.questions) {+ if (!isObj(q) || !nonBlank(q.question)) continue+ const lines: string[] = []+ if (nonBlank(q.header)) lines.push(`**${q.header}**`, '')+ lines.push(q.multiSelect === true ? `${q.question} _(multiple choice)_` : q.question)+ const options = Array.isArray(q.options)+ ? q.options+ .filter((o): o is Record<string, unknown> => isObj(o) && nonBlank(o.label))+ .map((o) => `- **${o.label}**${nonBlank(o.description) ? ` — ${o.description}` : ''}`)+ : []+ if (options.length) lines.push('', ...options)+ blocks.push(lines.join('\n'))+ }+ return blocks.length ? blocks.join('\n\n') : undefined+}++/** Markdown body for a tool call worth reading in full, or undefined (render the plain chip). */+export function toolBody(name: string, input: unknown): string | undefined {+ if (!isObj(input)) return undefined+ const body =+ name === 'ExitPlanMode' ? planBody(input) : name === 'AskUserQuestion' ? questionsBody(input) : undefined+ return body === undefined ? undefined : capBody(body)+}diff --git a/src/core/transcript-reader.test.ts b/src/core/transcript-reader.test.tsindex 3d8d2e588..4c25194f8 100644--- a/src/core/transcript-reader.test.ts+++ b/src/core/transcript-reader.test.ts@@ -312,3 +312,57 @@ describe('readChatWindow — byte windows read from a real file', () => {expect(await readChatWindow('/nonexistent/nt/x.jsonl', { before: null, maxBytes: 65536 })).toBeUndefined()})})++// ─────────────────────────────────────────────────────────────────────────────────────────────+// Tool bodies: a plan (ExitPlanMode) or a question (AskUserQuestion) is the content the user needs+// to read, not a chip. Must ride BOTH the legacy and the paged parse, keys/carried results unchanged.+// ─────────────────────────────────────────────────────────────────────────────────────────────+const PLAN = '# Plan\n\n1. Read the plan\n2. Render it'+const planUse = (id: string): string =>+ jl({+ type: 'assistant',+ message: { content: [{ type: 'tool_use', id, name: 'ExitPlanMode', input: { plan: PLAN } }] }+ })++describe('tool bodies in the chat parse', () => {+ it('the legacy parser attaches the plan as the tool body (and nothing else changes)', () => {+ const msgs = parseChatMessages((planUse('p1') + toolResult('p1', 'User approved')).split('\n'))+ expect(msgs).toEqual([+ { role: 'assistant', parts: [{ kind: 'tool', name: 'ExitPlanMode', arg: '', body: PLAN, result: 'User approved' }] }+ ])+ })++ it('the paged parser attaches the same body, keeps the id and the key', () => {+ const r = parseChatWindow(Buffer.from(planUse('p1') + toolResult('p1', 'User approved')), 0)+ expect(r.messages).toEqual([+ {+ role: 'assistant',+ key: 0,+ parts: [{ kind: 'tool', name: 'ExitPlanMode', arg: '', body: PLAN, id: 'p1', result: 'User approved' }]+ }+ ])+ })++ it('a plan whose answer lands in a newer page still carries its result by id', () => {+ const older = planUse('p2')+ const file = Buffer.from(older + toolResult('p2', 'User rejected'))+ const split = Buffer.byteLength(older)+ const newest = parseChatWindow(file.subarray(split - 1), split - 1)+ expect(newest.unmatchedResults).toEqual([{ id: 'p2', result: 'User rejected' }])+ const olderPage = parseChatWindow(file.subarray(0, split), 0)+ expect(olderPage.messages[0].parts[0]).toMatchObject({ kind: 'tool', id: 'p2', body: PLAN })+ })++ it('a tool with no body keeps today\'s shape exactly (no body key)', () => {+ const msgs = parseChatMessages(toolUse('t1', 'ls').split('\n'))+ expect(msgs[0].parts[0]).toEqual({ kind: 'tool', name: 'Bash', arg: 'ls' })+ })++ it('the search index includes the plan text so the find bar can find it', () => {+ const lines = parseTranscriptLines(planUse('p1'))+ expect(lines).toEqual([+ { role: 'tool', text: '$ ExitPlanMode' },+ { role: 'tool', text: PLAN }+ ])+ })+})diff --git a/src/core/transcript-reader.ts b/src/core/transcript-reader.tsindex b18d64ce8..69016d144 100644--- a/src/core/transcript-reader.ts+++ b/src/core/transcript-reader.ts@@ -8,6 +8,7 @@ import type { TranscriptLine, ChatMessage, ChatPart, ChatCarriedToolResult } froimport { transcriptRootFor } from './claude-accounts-core'import { linkedClaudeConfigDirFor } from './claude-config-dir'import { platform } from './platform'+import { toolBody } from './chat-tool-body'// Transcript root for a managed account (its `projects` dir) or the system default// (`~/.claude/projects` when accountId is undefined — bit-for-bit the old behavior). Impure@@ -65,6 +66,10 @@ function linesFrom(raw: string): TranscriptLine[] {else if (c.type === 'tool_use') {const arg = toolArg(c.input)out.push({ role: 'tool', text: `$ ${c.name ?? 'tool'}${arg ? ` ${arg}` : ''}` })+ // A plan / question is prose the user reads in full in the ⌘M view, so it is indexed in+ // full too — the same treatment an assistant text block gets (the find bar splits lines).+ const body = toolBody(c.name ?? '', c.input)+ if (body) out.push({ role: 'tool', text: body })}}} else if (o.type === 'user' && Array.isArray(content)) {@@ -171,6 +176,8 @@ function parseChatRecords(name: c.name ?? 'tool',arg: toolArg(c.input)}+ const body = toolBody(part.name, c.input)+ if (body) part.body = bodyif (paged && typeof c.id === 'string' && c.id) part.id = c.idparts.push(part)if (c.id) toolById.set(c.id, part)diff --git a/src/renderer/lib/chatPanel.test.ts b/src/renderer/lib/chatPanel.test.tsindex 3e9d1e83a..4f8a22a49 100644--- a/src/renderer/lib/chatPanel.test.ts+++ b/src/renderer/lib/chatPanel.test.ts@@ -1,5 +1,5 @@import { describe, expect, it } from 'vitest'-import { CHAT_FOLLOW_THRESHOLD_PX, chatAgentLabel, chatKeyAction, isNearBottom, shouldFollowOnLoad } from './chatPanel'+import { CHAT_FOLLOW_THRESHOLD_PX, chatAgentLabel, chatKeyAction, isNearBottom, shouldFollowOnLoad, toolCardTitle } from './chatPanel'describe('chatKeyAction', () => {it('Enter sends', () => {@@ -57,3 +57,11 @@ describe('chatAgentLabel', () => {expect(chatAgentLabel('custom:blank', [{ id: 'custom:blank', label: ' ' }])).toBe('Agent')})})++describe('toolCardTitle', () => {+ it('names a plan and a question for what they are, anything else by its tool name', () => {+ expect(toolCardTitle('ExitPlanMode')).toBe('Plan')+ expect(toolCardTitle('AskUserQuestion')).toBe('Question')+ expect(toolCardTitle('SomeFutureTool')).toBe('SomeFutureTool')+ })+})diff --git a/src/renderer/lib/chatPanel.ts b/src/renderer/lib/chatPanel.tsindex acc312b4c..1532a6672 100644--- a/src/renderer/lib/chatPanel.ts+++ b/src/renderer/lib/chatPanel.ts@@ -53,3 +53,14 @@ export function chatAgentLabel(const custom = customAgents.find((c) => c.id === agentId)?.label?.trim()return custom || 'Agent'}++/**+ * The caption of an expanded tool card (a tool part that carries a readable `body` — see+ * `core/chat-tool-body.ts`). Named for what the user is reading, not for the plumbing that carried+ * it; an unknown tool with a body falls back to its own name.+ */+export function toolCardTitle(name: string): string {+ if (name === 'ExitPlanMode') return 'Plan'+ if (name === 'AskUserQuestion') return 'Question'+ return name+}diff --git a/src/renderer/nodes/ChatPanel.tsx b/src/renderer/nodes/ChatPanel.tsxindex d82f8ee9f..a4838afe3 100644--- a/src/renderer/nodes/ChatPanel.tsx+++ b/src/renderer/nodes/ChatPanel.tsx@@ -5,7 +5,7 @@ import { useAgentStatus } from '../state/agentStatus'import { useSession } from '../session/session'import { chipFor } from '../lib/keybindingOverrides'import { chatComposerPlaceholder, chatSendRefusal } from '../lib/chatSendGate'-import { chatAgentLabel, chatKeyAction, isNearBottom, shouldFollowOnLoad } from '../lib/chatPanel'+import { chatAgentLabel, chatKeyAction, isNearBottom, shouldFollowOnLoad, toolCardTitle } from '../lib/chatPanel'import { useSettings } from '../state/settings'import {CHAT_OLDER_PAGE_BYTES,@@ -462,6 +462,14 @@ export function ChatPanel({<summary>Thinking</summary><MarkdownText text={p.text} /></details>+ ) : p.body ? (+ // A plan / question is the content itself, not plumbing: shown expanded, in full,+ // flowing with the thread (no inner scroll box). The answer stays under it.+ <div key={j} className="term-chat__tool-card">+ <div className="term-chat__tool-card-title">{toolCardTitle(p.name)}</div>+ <MarkdownText text={p.body} />+ {p.result && <pre className="term-chat__tool-result">{p.result}</pre>}+ </div>) : (<details key={j} className="term-chat__tool"><summary>diff --git a/src/renderer/nodes/ChatPanel.ux.test.tsx b/src/renderer/nodes/ChatPanel.ux.test.tsxindex 7ed8a7157..a3fe14198 100644--- a/src/renderer/nodes/ChatPanel.ux.test.tsx+++ b/src/renderer/nodes/ChatPanel.ux.test.tsx@@ -127,6 +127,62 @@ describe('ChatPanel composer keys', () => {})describe('ChatPanel rendering', () => {+ it('renders an ExitPlanMode plan as an expanded card with the markdown plan and the answer', async () => {+ await render()+ await resolveAt(0, [+ {+ role: 'assistant',+ parts: [+ { kind: 'tool', name: 'ToolSearch', arg: '' },+ {+ kind: 'tool',+ name: 'ExitPlanMode',+ arg: '',+ body: '# Fix the chat\n\n1. Parse **the plan**\n2. Render it',+ result: 'User approved the plan'+ }+ ]+ }+ ])+ const card = host.querySelector('.term-chat__tool-card') as HTMLElement+ expect(card).not.toBeNull()+ // Expanded, not a collapsed disclosure.+ expect(card.tagName).not.toBe('DETAILS')+ expect(card.closest('details')).toBeNull()+ expect(card.querySelector('.term-chat__tool-card-title')?.textContent).toBe('Plan')+ const md = card.querySelector('.term-chat__text') as HTMLElement+ expect(md.querySelector('h1')?.textContent).toBe('Fix the chat')+ expect(md.querySelector('strong')?.textContent).toBe('the plan')+ expect([...md.querySelectorAll('ol > li')].length).toBe(2)+ expect(card.querySelector('.term-chat__tool-result')?.textContent).toBe('User approved the plan')+ // A tool with no body is still today's collapsed chip.+ const chip = host.querySelector('details.term-chat__tool') as HTMLDetailsElement+ expect(chip.querySelector('.term-chat__tool-name')?.textContent).toBe('ToolSearch')+ expect(host.querySelectorAll('details.term-chat__tool').length).toBe(1)+ })++ it('renders an AskUserQuestion question with its options as an expanded "Question" card', async () => {+ await render()+ await resolveAt(0, [+ {+ role: 'assistant',+ parts: [+ {+ kind: 'tool',+ name: 'AskUserQuestion',+ arg: '',+ body: '**Database**\n\nWhich database?\n\n- **Postgres** — Relational\n- **SQLite**'+ }+ ]+ }+ ])+ const card = host.querySelector('.term-chat__tool-card') as HTMLElement+ expect(card.querySelector('.term-chat__tool-card-title')?.textContent).toBe('Question')+ const items = [...card.querySelectorAll('.term-chat__text li')].map((li) => li.textContent)+ expect(items).toEqual(['Postgres — Relational', 'SQLite'])+ expect(card.querySelector('.term-chat__tool-result')).toBeNull()+ })+it('renders a thinking part as a collapsed "Thinking" disclosure, not as answer text', async () => {await render()await resolveAt(0, [{ role: 'assistant', parts: [{ kind: 'thinking', text: 'pondering' }, { kind: 'text', text: 'answer' }] }])diff --git a/src/renderer/styles.css b/src/renderer/styles.cssindex 34bec6b49..b6aec8459 100644--- a/src/renderer/styles.css+++ b/src/renderer/styles.css@@ -3248,6 +3248,29 @@ body,font-size: 11px;opacity: 0.85;}+/* An expanded tool card: a tool part with a readable `body` (an ExitPlanMode plan, an+ AskUserQuestion question). Same tint as the chip so it still reads as "the agent's tool call",+ but open and full-width; no max-height, so a long plan scrolls with the thread. */+.term-chat__tool-card {+ margin: 6px 0;+ padding: 8px 10px;+ background: rgba(0, 0, 0, 0.25);+ border-left: 2px solid var(--accent);+ border-radius: 6px;+ min-width: 0;+}+.term-chat__tool-card-title {+ margin-bottom: 6px;+ font-size: 11px;+ font-weight: 600;+ letter-spacing: 0.04em;+ text-transform: uppercase;+ color: var(--accent);+}+.term-chat__tool-card .term-chat__tool-result {+ padding-top: 6px;+ border-top: 1px solid rgba(var(--tint-rgb), 0.1);+}/* Shared loading spinner (`components/Spinner.tsx`). CSS-only: a ring with one transparentquarter, rotated. It inherits `currentColor` and scales with the surrounding font size, so thesame element sits beside 11px bar text and 12px placeholder text without per-site sizing.diff --git a/src/shared/types.ts b/src/shared/types.tsindex d63bfe02c..377231c9f 100644--- a/src/shared/types.ts+++ b/src/shared/types.ts@@ -2775,6 +2775,10 @@ export type ChatPart =arg: stringresult?: stringsummary?: ChatToolSummary+ /** Markdown worth reading in full (an `ExitPlanMode` plan, an `AskUserQuestion` question and+ * its options — `core/chat-tool-body.ts`). Present = the renderer shows an expanded card+ * instead of the collapsed chip. Capped at 64 KB. */+ body?: string/** The transcript's `tool_use` id. Set only by a PAGED read (`ChatTranscriptResult.olderCursor`* present): a result carried across a page boundary (`unmatchedResults`) is attached by it. */id?: string