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.

feat(chat): Focus view and a todo-list card

review9ce0a0d3d86a
diff --git a/src/core/chat-tool-body.test.ts b/src/core/chat-tool-body.test.ts
index 5aae2d506..9002a570f 100644
--- a/src/core/chat-tool-body.test.ts
+++ b/src/core/chat-tool-body.test.ts
@@ -136,3 +136,59 @@ describe('toolBody — hardening', () => {
expect(body.endsWith('y' + TOOL_BODY_TRUNCATED)).toBe(true)
})
})
+
+// The TodoWrite input as the tool's schema states it: `{todos: [{content, status, activeForm?}]}`,
+// status one of pending / in_progress / completed. No TodoWrite record exists on this server to
+// measure (its CLIs, 2.1.209–2.1.316, write TaskCreate / TaskUpdate instead), so anything else
+// degrades to no body — the plain chip.
+describe('toolBody — TodoWrite (rich only)', () => {
+ const input = {
+ todos: [
+ { content: 'Read the parser', status: 'completed', activeForm: 'Reading the parser' },
+ { content: 'Write the card', status: 'in_progress', activeForm: 'Writing the card' },
+ { content: 'Ship it', status: 'pending', activeForm: 'Shipping it' }
+ ]
+ }
+
+ it('renders one checklist line per todo, the one in progress in bold', () => {
+ expect(toolBody('TodoWrite', input, { rich: true })).toBe(
+ '- [x] Read the parser\n- [ ] **Write the card** _(in progress)_\n- [ ] Ship it'
+ )
+ })
+
+ it('has no body without rich (the golden fixtures and the phone stay the chip)', () => {
+ expect(toolBody('TodoWrite', input)).toBeUndefined()
+ expect(toolBody('TodoWrite', input, {})).toBeUndefined()
+ expect(toolBody('TodoWrite', input, { rich: false })).toBeUndefined()
+ })
+
+ it('degrades to no body for missing or non-array todos, and skips malformed items', () => {
+ expect(toolBody('TodoWrite', {}, { rich: true })).toBeUndefined()
+ expect(toolBody('TodoWrite', { todos: 'x' }, { rich: true })).toBeUndefined()
+ expect(toolBody('TodoWrite', { todos: {} }, { rich: true })).toBeUndefined()
+ expect(toolBody('TodoWrite', { todos: [] }, { rich: true })).toBeUndefined()
+ expect(toolBody('TodoWrite', { todos: [null, 3, { status: 'pending' }, { content: ' ' }] }, { rich: true })).toBeUndefined()
+ expect(toolBody('TodoWrite', { todos: [null, { content: 'Only me', status: 'blocked' }] }, { rich: true })).toBe(
+ '- [ ] Only me'
+ )
+ })
+
+ it('keeps each todo on its own line and escapes emphasis inside it', () => {
+ const tricky = { todos: [{ content: 'fix *ptr\n- [x] injected', status: 'in_progress' }, { content: 'a_b', status: 'completed' }] }
+ expect(toolBody('TodoWrite', tricky, { rich: true })).toBe(
+ '- [ ] **fix \\*ptr - [x] injected** _(in progress)_\n- [x] a\\_b'
+ )
+ })
+
+ it('caps an oversized list', () => {
+ const big = { todos: Array.from({ length: 4000 }, (_, k) => ({ content: `task ${k} ${'x'.repeat(20)}`, status: 'pending' })) }
+ const body = toolBody('TodoWrite', big, { rich: true })!
+ expect(body.endsWith(TOOL_BODY_TRUNCATED)).toBe(true)
+ expect(body.length).toBe(TOOL_BODY_CAP + TOOL_BODY_TRUNCATED.length)
+ })
+
+ it('rich changes nothing for the other tools', () => {
+ expect(toolBody('ExitPlanMode', { plan: 'p' }, { rich: true })).toBe('p')
+ expect(toolBody('Bash', { command: 'ls' }, { rich: true })).toBeUndefined()
+ })
+})
diff --git a/src/core/chat-tool-body.ts b/src/core/chat-tool-body.ts
index 4abe7f20d..1870b3485 100644
--- a/src/core/chat-tool-body.ts
+++ b/src/core/chat-tool-body.ts
@@ -9,6 +9,12 @@ import { isRecord } from '../shared/is-record'
// 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.
+//
+// `TodoWrite` (the agent's todo list) gets a body only on the opt-in `rich` read, so the golden
+// fixtures and the phone's `chat.page` keep its chip. Its shape is the tool's own schema —
+// TodoWrite → {"todos": [{"content", "status": "pending" | "in_progress" | "completed", "activeForm"?}]}
+// — NOT a measurement: no TodoWrite record exists on this server's transcripts (2026-11-02; its CLIs,
+// 2.1.209–2.1.316, write `TaskCreate` / `TaskUpdate` instead). The same no-guess rule covers that gap.
/** The body crosses IPC/WS with every chat read; a plan is prose, and 64K characters (UTF-16 code
* units, i.e. `String.length`) is far past any real one. */
@@ -66,10 +72,37 @@ function questionsBody(input: Record<string, unknown>): string | undefined {
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 {
+// One checklist line per readable todo: done ticked, the one in progress in bold and named so, any
+// other status (pending, or one the schema does not know) an open box.
+function todosBody(input: Record<string, unknown>): string | undefined {
+ if (!Array.isArray(input.todos)) return undefined
+ const lines: string[] = []
+ for (const t of input.todos) {
+ if (!isRecord(t) || !nonBlank(t.content)) continue
+ const content = escapeEmphasis(oneLine(t.content))
+ lines.push(
+ t.status === 'completed'
+ ? `- [x] ${content}`
+ : t.status === 'in_progress'
+ ? `- [ ] **${content}** _(in progress)_`
+ : `- [ ] ${content}`
+ )
+ }
+ return lines.length ? lines.join('\n') : undefined
+}
+
+/** Markdown body for a tool call worth reading in full, or undefined (render the plain chip).
+ * `opts.rich` adds the bodies only the desktop ⌘M panel draws (`ChatParseOptions.rich`): today
+ * the `TodoWrite` checklist. */
+export function toolBody(name: string, input: unknown, opts?: { rich?: boolean }): string | undefined {
if (!isRecord(input)) return undefined
const body =
- name === 'ExitPlanMode' ? planBody(input) : name === 'AskUserQuestion' ? questionsBody(input) : undefined
+ name === 'ExitPlanMode'
+ ? planBody(input)
+ : name === 'AskUserQuestion'
+ ? questionsBody(input)
+ : name === 'TodoWrite' && opts?.rich === true
+ ? todosBody(input)
+ : undefined
return body === undefined ? undefined : capBody(body)
}
diff --git a/src/core/transcript-reader.test.ts b/src/core/transcript-reader.test.ts
index 853c31b2e..ffe0af4af 100644
--- a/src/core/transcript-reader.test.ts
+++ b/src/core/transcript-reader.test.ts
@@ -603,6 +603,38 @@ describe('Edit / Write diffs (opt-in `rich`)', () => {
})
})
+describe('TodoWrite checklist (opt-in `rich`)', () => {
+ // The tool's schema (no TodoWrite record exists on this server to measure — chat-tool-body.ts).
+ const raw = jl({
+ type: 'assistant',
+ message: {
+ content: [
+ {
+ type: 'tool_use',
+ id: 't1',
+ name: 'TodoWrite',
+ input: { todos: [{ content: 'a', status: 'completed', activeForm: 'A-ing' }, { content: 'b', status: 'pending' }] }
+ }
+ ]
+ }
+ })
+
+ it('rich: the call carries the checklist body; without rich it is the same chip as before', () => {
+ const part = (opts?: { rich?: boolean; thinking?: boolean }) => parseChatMessages(raw.split('\n'), opts)[0].parts
+ expect(part({ rich: true })).toEqual([{ kind: 'tool', name: 'TodoWrite', arg: '', body: '- [x] a\n- [ ] b' }])
+ expect(part()).toEqual([{ kind: 'tool', name: 'TodoWrite', arg: '' }])
+ expect(part({ thinking: true })).toEqual([{ kind: 'tool', name: 'TodoWrite', arg: '' }])
+ })
+
+ it('rich rides the paged parser too', () => {
+ const file = Buffer.from(raw)
+ expect(parseChatWindow(file, 0, claudeChatRecordParser({ rich: true })).messages[0].parts).toEqual([
+ { kind: 'tool', name: 'TodoWrite', arg: '', body: '- [x] a\n- [ ] b', id: 't1' }
+ ])
+ expect(parseChatWindow(file, 0).messages[0].parts).toEqual([{ kind: 'tool', name: 'TodoWrite', arg: '', id: 't1' }])
+ })
+})
+
describe('Compaction chip (opt-in `rich`)', () => {
// The measured records (CLI 2.1.314): the boundary is a `system` record, and the summary the model
// continues from is a `user` record flagged `isCompactSummary` — the model's text, not the user's.
diff --git a/src/core/transcript-reader.ts b/src/core/transcript-reader.ts
index 965c124ed..857d90295 100644
--- a/src/core/transcript-reader.ts
+++ b/src/core/transcript-reader.ts
@@ -376,9 +376,10 @@ export interface ChatParseOptions {
* media type is in `CHAT_IMAGE_TYPES` and `data` is a non-empty string. An image inside a
* `tool_result` is tool output and stays out (`summarizeResult` ignores it, as before). Off by
* default, like `thinking`: the golden fixtures and the phone's `chat.page` never set it.
- * Also: a `diff` on each `Edit` / `Write` tool part whose input reads (`toolDiff`), and a
+ * Also: a `diff` on each `Edit` / `Write` tool part whose input reads (`toolDiff`), a
* `Compaction` chip for each context compaction (`compactionPart`) in place of the long summary
- * record the model continues from, which is skipped.
+ * record the model continues from, which is skipped, and a checklist `body` on each `TodoWrite`
+ * tool part whose `todos` read (`toolBody`).
*/
rich?: boolean
}
@@ -682,7 +683,7 @@ function parseChatRecords(
name: c.name ?? 'tool',
arg: toolArg(c.input)
}
- const body = toolBody(part.name, c.input)
+ const body = toolBody(part.name, c.input, { rich: opts?.rich === true })
if (body) part.body = body
// Opt-in (see `ChatParseOptions.rich`): without it an Edit is the plain chip, as before.
const diff = opts?.rich ? toolDiff(part.name, c.input) : undefined
diff --git a/src/renderer/lib/chatFocus.test.ts b/src/renderer/lib/chatFocus.test.ts
new file mode 100644
index 000000000..888cd4465
--- /dev/null
+++ b/src/renderer/lib/chatFocus.test.ts
@@ -0,0 +1,58 @@
+import { describe, expect, it } from 'vitest'
+import type { ChatMessage, ChatPart } from '@shared/types'
+import { focusHides, latestTodoIndex, staleTodo } from './chatFocus'
+
+const todo = (body?: string): ChatPart => ({ kind: 'tool', name: 'TodoWrite', arg: '', ...(body ? { body } : {}) })
+const msg = (...parts: ChatPart[]): ChatMessage => ({ role: 'assistant', parts })
+
+describe('latestTodoIndex', () => {
+ it('is the LAST message holding a TodoWrite card, else -1', () => {
+ expect(latestTodoIndex([])).toBe(-1)
+ expect(latestTodoIndex([msg({ kind: 'text', text: 'hi' })])).toBe(-1)
+ expect(
+ latestTodoIndex([
+ msg(todo('- [ ] a')),
+ msg({ kind: 'text', text: 'x' }),
+ msg({ kind: 'tool', name: 'Bash', arg: 'ls' }, todo('- [x] a')),
+ msg({ kind: 'text', text: 'done' })
+ ])
+ ).toBe(2)
+ })
+
+ it('ignores a TodoWrite without a body (a plain read, or an input that did not parse)', () => {
+ expect(latestTodoIndex([msg(todo('- [ ] a')), msg(todo())])).toBe(0)
+ expect(latestTodoIndex([msg(todo())])).toBe(-1)
+ })
+})
+
+describe('staleTodo', () => {
+ it('is a TodoWrite card that is not the latest one', () => {
+ expect(staleTodo(todo('- [ ] a'), 0, 3)).toBe(true)
+ expect(staleTodo(todo('- [ ] a'), 3, 3)).toBe(false)
+ expect(staleTodo({ kind: 'tool', name: 'ExitPlanMode', arg: '', body: 'plan' }, 0, 3)).toBe(false)
+ expect(staleTodo({ kind: 'text', text: 'TodoWrite' }, 0, 3)).toBe(false)
+ })
+})
+
+describe('focusHides', () => {
+ const LATEST = 4
+ it.each<[string, ChatPart, number, boolean]>([
+ ['text', { kind: 'text', text: 'answer' }, 0, false],
+ ['an image', { kind: 'image', mediaType: 'image/png', data: 'AAAA' }, 0, false],
+ ['thinking', { kind: 'thinking', text: 'hmm', ms: 1000 }, 0, true],
+ ['a plain tool chip', { kind: 'tool', name: 'Bash', arg: 'ls', result: 'a' }, 0, true],
+ [
+ 'an Edit diff chip',
+ { kind: 'tool', name: 'Edit', arg: '/a', diff: { filePath: '/a', oldText: 'a', newText: 'b' } },
+ 0,
+ true
+ ],
+ ['a plan card', { kind: 'tool', name: 'ExitPlanMode', arg: '', body: '# Plan' }, 0, false],
+ ['a question card', { kind: 'tool', name: 'AskUserQuestion', arg: '', body: 'Q?', questions: [] }, 0, false],
+ ['the latest todo card', todo('- [ ] a'), LATEST, false],
+ ['an older todo card', todo('- [ ] a'), 1, true],
+ ['a todo without a body', todo(), LATEST, true]
+ ])('%s → %s', (_label, part, at, hidden) => {
+ expect(focusHides(part, at, LATEST)).toBe(hidden)
+ })
+})
diff --git a/src/renderer/lib/chatFocus.ts b/src/renderer/lib/chatFocus.ts
new file mode 100644
index 000000000..00c7fdf4a
--- /dev/null
+++ b/src/renderer/lib/chatFocus.ts
@@ -0,0 +1,34 @@
+// The ⌘M thread's Focus view (`settings.chatFocusView`) and its todo-list rule. No React — see
+// ChatPanel.tsx for the glue and chatFocus.test.ts for the pins.
+//
+// Focus view keeps what a person reads — the prompts, the answers, the images, the cards that ask
+// something of them — and drops the agent's plumbing: tool chips (diff chips included) and thinking.
+// A plan / question card is never plumbing: it carries the answer controls of a held request, and
+// hiding it would leave the composer pointing at a card that is not there.
+import type { ChatMessage, ChatPart } from '@shared/types'
+
+/** The agent's todo-list tool (claude's `TodoWrite`). */
+export const TODO_WRITE_TOOL = 'TodoWrite'
+
+/** The index of the LAST message holding a `TodoWrite` card (a part with a `body` — the opt-in
+ * `rich` read), else -1. Only that list is current: each call rewrites the whole list. */
+export function latestTodoIndex(messages: readonly ChatMessage[]): number {
+ for (let i = messages.length - 1; i >= 0; i--) {
+ if (messages[i].parts.some((p) => p.kind === 'tool' && p.name === TODO_WRITE_TOOL && p.body !== undefined)) return i
+ }
+ return -1
+}
+
+/** A `TodoWrite` part that is not in the latest todo message: a superseded list, which the thread
+ * draws as the plain chip in both views (a dozen full lists in one turn is the wall Focus removes). */
+export function staleTodo(p: ChatPart, messageIndex: number, latestTodo: number): boolean {
+ return p.kind === 'tool' && p.name === TODO_WRITE_TOOL && messageIndex !== latestTodo
+}
+
+/** Whether Focus view leaves this part out: thinking, a tool call without a `body` (the chip), and a
+ * superseded todo list. Text, an image and every other card stay. */
+export function focusHides(p: ChatPart, messageIndex: number, latestTodo: number): boolean {
+ if (p.kind === 'thinking') return true
+ if (p.kind !== 'tool') return false
+ return p.body === undefined || staleTodo(p, messageIndex, latestTodo)
+}
diff --git a/src/renderer/lib/chatPanel.test.ts b/src/renderer/lib/chatPanel.test.ts
index 676f00d2d..02f77197f 100644
--- a/src/renderer/lib/chatPanel.test.ts
+++ b/src/renderer/lib/chatPanel.test.ts
@@ -68,9 +68,10 @@ describe('chatAgentLabel', () => {
})
describe('toolCardTitle', () => {
- it('names a plan and a question for what they are, anything else by its tool name', () => {
+ it('names a plan, a question and a todo list for what they are, anything else by its tool name', () => {
expect(toolCardTitle('ExitPlanMode')).toBe('Plan')
expect(toolCardTitle('AskUserQuestion')).toBe('Question')
+ expect(toolCardTitle('TodoWrite')).toBe('Todo list')
expect(toolCardTitle('SomeFutureTool')).toBe('SomeFutureTool')
})
})
diff --git a/src/renderer/lib/chatPanel.ts b/src/renderer/lib/chatPanel.ts
index 0be634ff1..f9e14e116 100644
--- a/src/renderer/lib/chatPanel.ts
+++ b/src/renderer/lib/chatPanel.ts
@@ -76,5 +76,6 @@ export function chatAgentLabel(
export function toolCardTitle(name: string): string {
if (name === 'ExitPlanMode') return 'Plan'
if (name === 'AskUserQuestion') return 'Question'
+ if (name === 'TodoWrite') return 'Todo list'
return name
}
diff --git a/src/renderer/nodes/ChatPanel.answers.test.tsx b/src/renderer/nodes/ChatPanel.answers.test.tsx
index 7040a41fc..8ecc9e43b 100644
--- a/src/renderer/nodes/ChatPanel.answers.test.tsx
+++ b/src/renderer/nodes/ChatPanel.answers.test.tsx
@@ -5,6 +5,7 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import type { ChatMessage, ChatTranscriptResult } from '@shared/types'
import type { AnswerPermissionPayload, ChatQuestion, HeldPermission } from '@shared/agents/permission-answer'
import { useAgentStatus } from '../state/agentStatus'
+import { useSettings } from '../state/settings'
/**
* Answer controls on the ⌘M Plan / Question card (pure mapping: `lib/chatAnswer.test.ts`). Pins the
@@ -320,6 +321,28 @@ describe('question card', () => {
expect(cards()[0].textContent).toContain('User answered: B')
})
+ it('Focus view hides the tool calls around a held question, never the card or its controls', async () => {
+ useSettings.setState((s) => ({ settings: { ...s.settings, chatFocusView: true } }))
+ try {
+ await hold('waiting', held(['Pick one?']))
+ await mount([
+ { role: 'assistant', key: 0, parts: [{ kind: 'tool', name: 'Bash', arg: 'ls' }] },
+ askMsg(10, [SINGLE])
+ ])
+ expect(host.querySelector('details.term-chat__tool')).toBeNull()
+ expect(cards()).toHaveLength(1)
+ await click(radio('B'))
+ await click(button(cards()[0], 'Submit'))
+ expect(sent()).toEqual({
+ nodeId: NODE,
+ pendingId: 'n-q-1',
+ answer: { kind: 'question', answers: { 'Pick one?': 'B' } }
+ })
+ } finally {
+ useSettings.setState((s) => ({ settings: { ...s.settings, chatFocusView: false } }))
+ }
+ })
+
it('a read-only transcript (closed node) never shows controls', async () => {
await hold('waiting', held(['Pick one?']))
reads.messages = [askMsg(0, [SINGLE])]
diff --git a/src/renderer/nodes/ChatPanel.thread.test.tsx b/src/renderer/nodes/ChatPanel.thread.test.tsx
index 0b4e7c865..25fa243fc 100644
--- a/src/renderer/nodes/ChatPanel.thread.test.tsx
+++ b/src/renderer/nodes/ChatPanel.thread.test.tsx
@@ -4,6 +4,7 @@ import { createRoot, type Root } from 'react-dom/client'
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import type { ChatMessage } from '@shared/types'
import { useAgentStatus } from '../state/agentStatus'
+import { useSettings } from '../state/settings'
/**
* The claude.ai thread look (pure half: lib/chatThread.ts). Pins the glue: the user message is a
@@ -39,10 +40,13 @@ const MIN = 60_000
let host: HTMLDivElement
let root: Root
const writeText = vi.fn()
+// The Focus toggle persists through `useSettings.update`, whose coalesced save reaches this.
+const saveSettings = vi.fn(async (_s: unknown) => undefined)
beforeEach(() => {
writeText.mockClear()
- ;(window as unknown as { nodeTerminal: unknown }).nodeTerminal = { clipboard: { writeText } }
+ saveSettings.mockClear()
+ ;(window as unknown as { nodeTerminal: unknown }).nodeTerminal = { clipboard: { writeText }, settings: { save: saveSettings } }
useAgentStatus.setState((s) => ({ byId: { ...s.byId, [NODE]: { state: 'done' } as (typeof s.byId)[string] } }))
host = document.createElement('div')
document.body.appendChild(host)
@@ -51,6 +55,7 @@ beforeEach(() => {
afterEach(async () => {
await act(async () => root.unmount())
host.remove()
+ useSettings.setState((s) => ({ settings: { ...s.settings, chatFocusView: false } }))
useAgentStatus.setState((s) => {
const byId = { ...s.byId }
delete byId[NODE]
@@ -341,3 +346,113 @@ describe('⌘M thread look', () => {
expect(days[1].nextElementSibling?.textContent).toContain('Done.')
})
})
+
+describe('⌘M Focus view and the todo-list card', () => {
+ const todo = (key: number, body: string): ChatMessage => ({
+ role: 'assistant',
+ parts: [{ kind: 'tool', name: 'TodoWrite', arg: '', body }],
+ key
+ })
+ const focusOn = (): void => useSettings.setState((s) => ({ settings: { ...s.settings, chatFocusView: true } }))
+
+ it('only the latest todo list is a card; an older one is the plain chip (Focus off too)', async () => {
+ await mount([
+ { role: 'user', parts: [{ kind: 'text', text: 'q' }], key: 0 },
+ todo(10, '- [ ] a\n- [ ] b'),
+ { role: 'assistant', parts: [{ kind: 'text', text: 'working' }], key: 20 },
+ todo(30, '- [x] a\n- [ ] **b** _(in progress)_')
+ ])
+ const cards = [...host.querySelectorAll('.term-chat__tool-card')]
+ expect(cards).toHaveLength(1)
+ expect(cards[0].classList.contains('term-chat__todo')).toBe(true)
+ expect(cards[0].querySelector('.term-chat__tool-card-title')?.textContent).toBe('Todo list')
+ const boxes = [...cards[0].querySelectorAll<HTMLInputElement>('input[type="checkbox"]')]
+ expect(boxes.map((b) => [b.checked, b.disabled])).toEqual([
+ [true, true],
+ [false, true]
+ ])
+ expect(cards[0].querySelector('strong')?.textContent).toBe('b')
+ const chips = [...host.querySelectorAll('details.term-chat__tool')]
+ expect(chips).toHaveLength(1)
+ expect(chips[0].querySelector('.term-chat__tool-name')?.textContent).toBe('TodoWrite')
+ expect(host.querySelector('.term-chat__focus')?.getAttribute('aria-pressed')).toBe('false')
+ })
+
+ it('Focus hides chips, groups and thinking; keeps text, the latest todo card and a question card', async () => {
+ focusOn()
+ await mount([
+ { role: 'user', parts: [{ kind: 'text', text: 'q' }], key: 0 },
+ { role: 'assistant', parts: [{ kind: 'tool', name: 'Bash', arg: 'ls' }], key: 10 },
+ { role: 'assistant', parts: [{ kind: 'tool', name: 'Read', arg: '/a' }], key: 20 },
+ { role: 'assistant', parts: [{ kind: 'thinking', text: 'hmm', ms: 2000 }], key: 30 },
+ { role: 'assistant', parts: [{ kind: 'text', text: 'answer' }], key: 40 },
+ todo(50, '- [ ] old'),
+ todo(60, '- [ ] latest'),
+ {
+ role: 'assistant',
+ parts: [
+ {
+ kind: 'tool',
+ name: 'AskUserQuestion',
+ arg: '',
+ body: 'Pick one?',
+ questions: [{ question: 'Pick one?', multiSelect: false, options: [{ label: 'A' }] }]
+ }
+ ],
+ key: 70
+ }
+ ])
+ expect(host.querySelector('.term-chat__tool-group')).toBeNull()
+ expect(host.querySelector('details.term-chat__thinking')).toBeNull()
+ expect(host.querySelector('details.term-chat__tool')).toBeNull()
+ const cards = [...host.querySelectorAll('.term-chat__tool-card')]
+ expect(cards.map((c) => c.querySelector('.term-chat__tool-card-title')?.textContent)).toEqual(['Todo list', 'Question'])
+ expect(cards[0].textContent).toContain('latest')
+ // A message with nothing left to draw is not drawn at all: the answer, the todo card, the question.
+ expect(host.querySelectorAll('.term-chat__msg--assistant')).toHaveLength(3)
+ expect(host.querySelector('.term-chat__msg--assistant')?.textContent).toContain('answer')
+ expect(host.querySelector('.term-chat__focus')?.getAttribute('aria-pressed')).toBe('true')
+ })
+
+ it('in Focus, a turn that ends on a hidden call keeps its action row (the folded wrapper)', async () => {
+ focusOn()
+ await mount([
+ { role: 'user', parts: [{ kind: 'text', text: 'q' }], key: 0, at: now - 3 * MIN },
+ { role: 'assistant', parts: [{ kind: 'text', text: 'ok' }], key: 10, at: now - 2 * MIN },
+ { role: 'assistant', parts: [{ kind: 'tool', name: 'Bash', arg: 'ls' }], key: 20, at: now - MIN }
+ ])
+ const last = [...host.querySelectorAll('.term-chat__msg--assistant')].at(-1)!
+ expect(last.classList.contains('term-chat__msg--folded')).toBe(true)
+ expect(last.childElementCount).toBe(1)
+ expect(last.querySelector('.term-chat__actions time')?.textContent).toBe('1 min ago')
+ expect(host.querySelector('.term-chat__tool')).toBeNull()
+ })
+
+ it('the bar toggle flips the view and persists the setting', async () => {
+ await mount([
+ { role: 'user', parts: [{ kind: 'text', text: 'q' }], key: 0 },
+ { role: 'assistant', parts: [{ kind: 'thinking', text: 'hmm' }], key: 10 },
+ { role: 'assistant', parts: [{ kind: 'text', text: 'ok' }], key: 20 }
+ ])
+ const toggle = host.querySelector<HTMLButtonElement>('button.term-chat__focus')!
+ expect(toggle.textContent).toBe('Focus')
+ expect(toggle.title).toBe('Focus view: hide tool calls and thinking')
+ expect(toggle.getAttribute('aria-pressed')).toBe('false')
+ expect(host.querySelector('details.term-chat__thinking')).not.toBeNull()
+
+ await act(async () => toggle.click())
+ expect(toggle.getAttribute('aria-pressed')).toBe('true')
+ expect(host.querySelector('details.term-chat__thinking')).toBeNull()
+ expect(useSettings.getState().settings.chatFocusView).toBe(true)
+ // The store's coalesced save (300 ms) writes it to disk.
+ await act(async () => {
+ await new Promise((r) => setTimeout(r, 350))
+ })
+ expect(saveSettings.mock.calls.at(-1)?.[0]).toMatchObject({ chatFocusView: true })
+
+ await act(async () => toggle.click())
+ expect(toggle.getAttribute('aria-pressed')).toBe('false')
+ expect(host.querySelector('details.term-chat__thinking')).not.toBeNull()
+ expect(useSettings.getState().settings.chatFocusView).toBe(false)
+ })
+})
diff --git a/src/renderer/nodes/ChatPanel.tsx b/src/renderer/nodes/ChatPanel.tsx
index b2c8e53b7..6fa6b8712 100644
--- a/src/renderer/nodes/ChatPanel.tsx
+++ b/src/renderer/nodes/ChatPanel.tsx
@@ -59,6 +59,7 @@ import { useCodeHighlight } from './CodeHighlight'
import { assistantTurnEnds, chatAbsoluteTime, chatClockTime, dayDividers } from '../lib/chatThread'
import { groupToolCalls, partPosition } from '../lib/chatToolGroups'
import { thinkingLabel } from '../lib/chatThinking'
+import { TODO_WRITE_TOOL, focusHides, latestTodoIndex, staleTodo } from '../lib/chatFocus'
import { ChatToolGroup } from './ChatToolGroup'
import { ChatImage } from './ChatImage'
import { ChatToolDiff } from './ChatToolDiff'
@@ -995,6 +996,23 @@ export function ChatPanel({
}, [])
// A divider at the first message of each local day; the same `now`, so Today rolls to Yesterday.
const days = useMemo(() => dayDividers(messages, now), [messages, now])
+ // Focus view (the bar toggle; lib/chatFocus.ts): tool chips and thinking are left out. Strict, as
+ // the setting is hand-editable. Only the latest todo list is a card, in both views.
+ const focusView = useSettings((s) => s.settings.chatFocusView === true)
+ const latestTodo = useMemo(() => latestTodoIndex(messages), [messages])
+ // Whether the part at (i, j) draws anything at its own place: not when an earlier tool block holds
+ // it, nor in Focus view when it is hidden — or, for a block's first member, when its every member is.
+ const drawsAt = (i: number, j: number): boolean => {
+ const at = partPosition(i, j)
+ if (toolGroups.absorbed.has(at)) return false
+ if (!focusView) return true
+ const group = toolGroups.groupAt.get(at)
+ if (!group) return !focusHides(messages[i].parts[j], i, latestTodo)
+ return group.members.some((mb) => {
+ const p = messages[mb.message]?.parts[mb.part]
+ return p !== undefined && !focusHides(p, mb.message, latestTodo)
+ })
+ }
// One part of a message, as the thread draws it. Also used for the members of a folded tool block,
// which are drawn inside the block instead of at their own place (lib/chatToolGroups.ts).
@@ -1013,10 +1031,11 @@ export function ChatPanel({
) : p.kind === 'image' ? (
// An image the user attached to the prompt (the opt-in `rich` read): a thumbnail, click to enlarge.
<ChatImage key={key} mediaType={p.mediaType} data={p.data} />
- ) : 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={key} className="term-chat__tool-card">
+ ) : p.body && !staleTodo(p, i, latestTodo) ? (
+ // A plan / question / the latest todo list is the content itself, not plumbing: shown
+ // expanded, in full, flowing with the thread (no inner scroll box). The answer stays under it.
+ // A superseded todo list falls through to the plain chip.
+ <div key={key} className={`term-chat__tool-card${p.name === TODO_WRITE_TOOL ? ' term-chat__todo' : ''}`}>
<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>}
@@ -1075,6 +1094,15 @@ export function ChatPanel({
<div className="term-chat__bar">
<span>{title ?? 'Chat'}</span>
<span className="term-chat__bar-end">
+ <button
+ type="button"
+ className="term-chat__focus"
+ aria-pressed={focusView}
+ onClick={() => useSettings.getState().update({ chatFocusView: !focusView })}
+ title="Focus view: hide tool calls and thinking"
+ >
+ Focus
+ </button>
<button
className="term-chat__refresh"
onClick={() => load()}
@@ -1129,11 +1157,11 @@ export function ChatPanel({
</div>
)}
{messages.map((m, i) => {
- // A message whose every part is drawn inside an earlier message's tool block has nothing of
- // its own to draw, unless it ends a turn: then it draws that turn's action row and nothing
- // else — bar a day divider (below). (Only assistant parts fold, so a queued message — the
- // user's — never does.)
- const folded = m.parts.length > 0 && m.parts.every((_, j) => toolGroups.absorbed.has(partPosition(i, j)))
+ // A message whose every part is drawn inside an earlier message's tool block (or, in Focus
+ // view, hidden) has nothing of its own to draw, unless it ends a turn: then it draws that
+ // turn's action row and nothing else — bar a day divider (below). (Only assistant parts
+ // fold or hide, so a queued message — the user's — never does.)
+ const folded = m.parts.length > 0 && m.parts.every((_, j) => !drawsAt(i, j))
const turnEnd = turnEnds.get(i)
// Keyed by the source line's byte offset: a prepended page does not re-key (and so does
// not re-render) a single existing bubble. Unkeyed ones (grok, the optimistic sent
@@ -1170,10 +1198,9 @@ export function ChatPanel({
}`}
>
{m.parts.map((p, j) => {
- const at = partPosition(i, j)
- const group = toolGroups.groupAt.get(at)
+ if (!drawsAt(i, j)) return null
+ const group = toolGroups.groupAt.get(partPosition(i, j))
if (group) return <ChatToolGroup key={group.key} messages={messages} group={group} renderPart={renderPart} />
- if (toolGroups.absorbed.has(at)) return null
return renderPart(p, i, j)
})}
{m.role === 'user' && m.at !== undefined && (
diff --git a/src/renderer/styles.chat-view.test.ts b/src/renderer/styles.chat-view.test.ts
index 99bbbc9df..ac3eb608d 100644
--- a/src/renderer/styles.chat-view.test.ts
+++ b/src/renderer/styles.chat-view.test.ts
@@ -144,3 +144,13 @@ describe('⌘M code block syntax colors', () => {
expect(ruleBody('.term-chat__text pre code[data-highlighted]')).toMatch(/white-space:\s*pre;/)
})
})
+
+describe('⌘M Focus view toggle and the todo-list card', () => {
+ it('the pressed Focus toggle is filled, so the bar says the view is filtered', () => {
+ expect(ruleBody(".term-chat__focus[aria-pressed='true']")).toMatch(/background:\s*[^;]+;/)
+ })
+
+ it('a todo list drops the bullets: its checkboxes are the markers', () => {
+ expect(ruleBody('.term-chat__todo ul')).toMatch(/list-style:\s*none;/)
+ })
+})
diff --git a/src/renderer/styles.css b/src/renderer/styles.css
index 90e7b3799..c9b3ef151 100644
--- a/src/renderer/styles.css
+++ b/src/renderer/styles.css
@@ -4205,6 +4205,40 @@ body,
.term-chat__refresh:hover {
background: rgba(var(--tint-rgb), 0.1);
}
+/* The Focus toggle (ChatPanel; settings.chatFocusView): a quiet text button beside ↻ that is FILLED
+ while pressed, so the bar itself says the thread is filtered. */
+.term-chat__focus {
+ padding: 1px 6px;
+ font-size: 11px;
+ line-height: 1.3;
+ color: inherit;
+ background: none;
+ border: 1px solid rgba(var(--tint-rgb), 0.14);
+ border-radius: 4px;
+ cursor: pointer;
+}
+.term-chat__focus:hover {
+ background: rgba(var(--tint-rgb), 0.1);
+}
+.term-chat__focus[aria-pressed='true'] {
+ color: var(--accent-text);
+ background: color-mix(in srgb, var(--accent) 16%, transparent);
+ border-color: var(--accent);
+}
+/* The latest todo list (a TodoWrite card): its disabled checkboxes are the markers, so no bullets. */
+.term-chat__todo ul {
+ list-style: none;
+ padding-left: 0;
+ margin: 0;
+}
+.term-chat__todo li {
+ margin: 2px 0;
+}
+.term-chat__todo input[type='checkbox'] {
+ margin: 0 6px 0 0;
+ vertical-align: -1px;
+ accent-color: var(--accent);
+}
/* Claude's thinking summary between tool calls (a <details>, closed by default): a dimmed line —
chevron + "Thought for 12s" — so it never reads as the answer; open, the text stays dimmed too. */
.term-chat__thinking {
diff --git a/src/shared/chat-fixtures/README.md b/src/shared/chat-fixtures/README.md
index 7c90fd24a..2b11564f5 100644
--- a/src/shared/chat-fixtures/README.md
+++ b/src/shared/chat-fixtures/README.md
@@ -111,6 +111,8 @@ nothing above changes. What it adds:
`"<preTokens> → <postTokens> tokens"` (plain digits, U+2192) only when both are finite numbers. It
is a system record (a turn boundary, never folded). The `type:"user"` record with
`isCompactSummary: true` (the summary the model continues from) is skipped.
+- A `body` on a `TodoWrite` tool part: one line per `todos` item with a non-blank `content` (`- [x] …`
+ completed, `- [ ] **…** _(in progress)_` in progress, else `- [ ] …`), capped like any tool `body`.
Decision cases: plan `restore` / `acceptEdits` / `manual` / `revise` (the revise text is trimmed),
question single / multi (labels joined with `, `) / free text (trimmed), and three refusals: a
diff --git a/src/shared/types.ts b/src/shared/types.ts
index 3046b4225..27cff76ce 100644
--- a/src/shared/types.ts
+++ b/src/shared/types.ts
@@ -2001,6 +2001,11 @@ export interface Settings {
/** Body size (CSS px) of the same views; headings scale from it, code is 0.92 of it. Read
* through `resolveMarkdownFontSize`, which clamps to 8–28 and answers 13 for garbage. */
markdownFontSize: number
+ /** The ⌘M chat view's Focus toggle (its bar's `Focus` button): the thread leaves out tool calls
+ * and thinking, and keeps the prompts, answers, images and the cards that ask something (a plan,
+ * a question — with their answer controls — and the latest todo list). Default OFF; read
+ * strictly (`=== true`), since the file is hand-editable. Machine-local, like the fonts above. */
+ chatFocusView: boolean
/** Default size (px) for NEW terminal/agent nodes on the canvas. Existing nodes keep
* whatever size they were saved with; other node kinds keep their own defaults. */
defaultNodeWidth: number
@@ -2530,6 +2535,7 @@ export const DEFAULT_SETTINGS: Settings = {
groupFrameBacking: 0,
markdownFontFamily: DEFAULT_MARKDOWN_FONT_FAMILY,
markdownFontSize: DEFAULT_MARKDOWN_FONT_SIZE,
+ chatFocusView: false,
defaultNodeWidth: 640,
defaultNodeHeight: 440,
defaultNodeSizes: {},
@@ -3619,8 +3625,9 @@ export type ChatPart =
result?: string
summary?: 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 64K characters. */
+ * its options, and on the opt-in `rich` read a `TodoWrite` checklist — `core/chat-tool-body.ts`).
+ * Present = the renderer shows an expanded card instead of the collapsed chip (a superseded
+ * todo list excepted: `lib/chatFocus.ts`). Capped at 64K characters. */
body?: string
/** `AskUserQuestion` only: the questions read for the answer controls (`readQuestions`) —
* the SAME reader the held request's texts come from, so a surface can match the card to the