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): show Claude's thinking summaries in the ⌘M chat view

Paul Robertson66b6b9811cb1
diff --git a/src/core/transcript-ipc.test.ts b/src/core/transcript-ipc.test.ts
index 7e002fa27..42c3d2aa3 100644
--- a/src/core/transcript-ipc.test.ts
+++ b/src/core/transcript-ipc.test.ts
@@ -277,6 +277,16 @@ describe('registerTranscriptIpc — transcript presence', () => {
// Paged chat reads — the trailing optional `page` argument. Absent = the legacy read (every test
// above), present = one byte window plus the paging fields.
// ─────────────────────────────────────────────────────────────────────────────────────────────
+const thinkingLine = (thinking: string, text?: string) => ({
+ type: 'assistant',
+ message: {
+ content: [
+ { type: 'thinking', thinking, signature: 'EqQBCkgIBhABGAIiQL' },
+ ...(text ? [{ type: 'text', text }] : [])
+ ]
+ }
+})
+
describe('registerTranscriptIpc — paged chat reads', () => {
const paged = (page: unknown, nodeId?: string, agentId?: string) =>
f.handlers[IPC.chatReadTranscript](
@@ -313,6 +323,28 @@ describe('registerTranscriptIpc — paged chat reads', () => {
expect(pagedRes.effort).toBe('xhigh')
})
+ it('emits thinking summaries only when the page asks for them', async () => {
+ writeTranscript(
+ lines(
+ userLine('go'),
+ thinkingLine('So far nothing is flagged.'),
+ thinkingLine('', 'the answer'),
+ { type: 'assistant', message: { content: [{ type: 'redacted_thinking', data: 'c2VjcmV0' }] } }
+ )
+ )
+ registerTranscriptIpc()
+
+ const withThinking = await paged({ maxBytes: 65536, thinking: true })
+ const without = await paged({ maxBytes: 65536 })
+
+ expect(withThinking.messages.map((m) => m.parts)).toEqual([
+ [{ kind: 'text', text: 'go' }],
+ [{ kind: 'thinking', text: 'So far nothing is flagged.' }],
+ [{ kind: 'text', text: 'the answer' }]
+ ])
+ expect(without.messages.map((m) => m.parts)).toEqual([[{ kind: 'text', text: 'go' }], [{ kind: 'text', text: 'the answer' }]])
+ })
+
it('the legacy (unpaged) result gains no model/effort keys', async () => {
writeTranscript(
lines({ type: 'assistant', effort: 'high', message: { model: 'claude-opus-5', content: [{ type: 'text', text: 'x' }] } })
@@ -439,6 +471,18 @@ describe('registerTranscriptIpc — paged chat reads', () => {
expect(res.olderCursor).toBe(body.indexOf(0x0a) + 1)
})
+ it('honours the thinking flag on the host window too', async () => {
+ const body = Buffer.from(lines(thinkingLine('checking the host'), assistantLine('done')))
+ registerTranscriptIpc({ readRemotePage: async () => ({ ok: true, data: body, start: 0 }) })
+
+ const res = await paged({ maxBytes: 70000, thinking: true }, 'nt-1')
+
+ expect(res.messages.map((m) => m.parts[0])).toEqual([
+ { kind: 'thinking', text: 'checking the host' },
+ { kind: 'text', text: 'done' }
+ ])
+ })
+
it('a failed host read is not-found — never an empty conversation, never the local disk', async () => {
writeTranscript(lines(assistantLine('the LOCAL machine')))
registerTranscriptIpc({ readRemotePage: async () => ({ ok: false }) })
diff --git a/src/core/transcript-ipc.ts b/src/core/transcript-ipc.ts
index 273badfed..c3cdb71ab 100644
--- a/src/core/transcript-ipc.ts
+++ b/src/core/transcript-ipc.ts
@@ -32,6 +32,7 @@ import { capabilityAgentId } from '../shared/agents/config'
import {
parseChatMessages,
parseChatWindow,
+ claudeChatRecordParser,
parseTranscriptLines,
type ChatWindowParse,
readChatWindow,
@@ -190,6 +191,10 @@ async function readChatPage(
page: ChatTranscriptPage,
deps: TranscriptIpcDeps
): Promise<ChatTranscriptResult> {
+ // Thinking summaries only when asked (the ⌘M panel asks; the phone does not), on BOTH legs.
+ const parse = page.thinking
+ ? (buf: Buffer, bufStart: number) => parseChatWindow(buf, bufStart, claudeChatRecordParser({ thinking: true }))
+ : parseChatWindow
const readRemotePage = deps.readRemotePage
if (readRemotePage) {
const remote = await readRemotePage(q, page)
@@ -197,10 +202,15 @@ async function readChatPage(
if (!remote.ok) return remote.absent ? notFoundPage() : unreadablePage()
// A growth re-read that suddenly says "not remote" (null) is a failed read too — never a
// reason to go read THIS machine's disk halfway through a remote page.
- return parseGrowingWindow(page, remote, async (p) => {
- const r = await readRemotePage(q, p)
- return r && r.ok ? r : null
- })
+ return parseGrowingWindow(
+ page,
+ remote,
+ async (p) => {
+ const r = await readRemotePage(q, p)
+ return r && r.ok ? r : null
+ },
+ parse
+ )
}
}
// A node its caller KNOWS is remote (an SSH project's node, whether or not a pty is attached):
@@ -212,7 +222,7 @@ async function readChatPage(
const w = await readChatWindow(p, page)
// Resolved but unreadable (deleted between resolve and read): not-found, like a failed remote.
if (!w) return notFoundPage()
- return parseGrowingWindow(page, w, async (pg) => (await readChatWindow(p, pg)) ?? null)
+ return parseGrowingWindow(page, w, async (pg) => (await readChatWindow(p, pg)) ?? null, parse)
}
/**
diff --git a/src/core/transcript-reader.ts b/src/core/transcript-reader.ts
index e3e76984c..7b302fce0 100644
--- a/src/core/transcript-reader.ts
+++ b/src/core/transcript-reader.ts
@@ -361,6 +361,14 @@ function systemPart(r: SystemRecord): Extract<ChatPart, { kind: 'tool' }> {
* a TITLE (recent conversations, the transcript index), where a code fence has no place. */
export interface ChatParseOptions {
expandPastes?: boolean
+ /**
+ * Emit a `thinking` part for each thinking block that carries readable text — the summaries
+ * claude's TUI prints between tool calls. Most thinking blocks carry only an encrypted
+ * `signature` and an empty `thinking` (measured: 137 of 913 on one machine had text); those, and
+ * every `redacted_thinking`, yield nothing either way. Off by default: the shared golden fixtures
+ * (`thinking.pages.json`) and the phone's `chat.page` keep dropping them.
+ */
+ thinking?: boolean
}
const userTextOf = (text: string, opts: ChatParseOptions | undefined): string =>
opts?.expandPastes === false ? text : expandPastedContent(text)
@@ -561,12 +569,18 @@ function parseChatRecords(
for (const c of content as Array<{
type?: string
text?: string
+ thinking?: unknown
name?: string
id?: string
input?: unknown
}>) {
if (!c || typeof c !== 'object') continue
if (c.type === 'text' && c.text) parts.push({ kind: 'text', text: c.text })
+ else if (c.type === 'thinking') {
+ if (opts?.thinking && typeof c.thinking === 'string' && c.thinking.trim()) {
+ parts.push({ kind: 'thinking', text: c.thinking })
+ }
+ }
else if (c.type === 'tool_use') {
const part: Extract<ChatPart, { kind: 'tool' }> = {
kind: 'tool',
@@ -658,6 +672,13 @@ export function parseChatMessages(rawLines: string[], opts?: ChatParseOptions):
).messages
}
+/** Claude's record parser with parse options bound — `parseChatWindow`'s third argument. */
+export function claudeChatRecordParser(
+ opts: ChatParseOptions
+): (records: Iterable<{ raw: string; offset: number }>, paged: true) => ChatRecordsOut {
+ return (records, paged) => parseChatRecords(records, paged, opts)
+}
+
/** A paged chat read's answer, minus `found` (the caller knows whether anything resolved). */
export interface ChatWindowParse {
messages: ChatMessage[]
diff --git a/src/renderer/nodes/ChatPanel.live.test.tsx b/src/renderer/nodes/ChatPanel.live.test.tsx
index f85a63573..2e6f98945 100644
--- a/src/renderer/nodes/ChatPanel.live.test.tsx
+++ b/src/renderer/nodes/ChatPanel.live.test.tsx
@@ -147,7 +147,7 @@ describe('ChatPanel live progress', () => {
expect(pending).toHaveLength(1)
await advance(CHAT_LIVE_RELOAD_MIN_MS)
expect(pending).toHaveLength(2)
- expect(pending[1].page).toEqual({ maxBytes: CHAT_TAIL_PAGE_BYTES, background: true })
+ expect(pending[1].page).toEqual({ maxBytes: CHAT_TAIL_PAGE_BYTES, background: true, thinking: true })
// A burst while that read is in flight: held, never overlapped…
await hook('working')
@@ -185,7 +185,7 @@ describe('ChatPanel live progress', () => {
await settle(1, { messages: [say(0, 'older')], olderCursor: null })
expect(bubbles()).toEqual(['older', 'tail'])
expect(pending).toHaveLength(3) // …then served once it landed
- expect(pending[2].page).toEqual({ maxBytes: CHAT_TAIL_PAGE_BYTES, background: true })
+ expect(pending[2].page).toEqual({ maxBytes: CHAT_TAIL_PAGE_BYTES, background: true, thinking: true })
})
it('the live read the send itself triggers does not erase the prompt the transcript lacks yet', async () => {
@@ -232,7 +232,7 @@ describe('ChatPanel live progress', () => {
await hook('working')
await advance(CHAT_LIVE_RELOAD_MIN_MS)
expect(pending).toHaveLength(3)
- expect(pending[2].page).toEqual({ maxBytes: CHAT_TAIL_PAGE_BYTES, background: true })
+ expect(pending[2].page).toEqual({ maxBytes: CHAT_TAIL_PAGE_BYTES, background: true, thinking: true })
expect(host.querySelector('.term-chat__older--error')).not.toBeNull()
await settle(2, { messages: [say(1000, 'tail'), say(2000, 'more')], olderCursor: 1000 })
expect(host.querySelector('.term-chat__older--error')).not.toBeNull()
@@ -437,7 +437,7 @@ describe('ChatPanel — a sent local command', () => {
expect(pending.length).toBe(1)
await advance(1)
expect(pending.length).toBe(2)
- expect(pending[1].page).toEqual({ maxBytes: CHAT_TAIL_PAGE_BYTES, background: true })
+ expect(pending[1].page).toEqual({ maxBytes: CHAT_TAIL_PAGE_BYTES, background: true, thinking: true })
await settle(1, { messages: [say(0, 'hello'), cmd(100, '/model')], olderCursor: 0 })
expect(activity()).toBeNull()
// Exactly one read: nothing else is scheduled.
diff --git a/src/renderer/nodes/ChatPanel.paging.test.tsx b/src/renderer/nodes/ChatPanel.paging.test.tsx
index 416164f06..ce2670147 100644
--- a/src/renderer/nodes/ChatPanel.paging.test.tsx
+++ b/src/renderer/nodes/ChatPanel.paging.test.tsx
@@ -155,7 +155,7 @@ describe('ChatPanel progressive loading', () => {
it('reads only a small tail window first', async () => {
await render()
- expect(pending[0].page).toEqual({ maxBytes: CHAT_TAIL_PAGE_BYTES })
+ expect(pending[0].page).toEqual({ maxBytes: CHAT_TAIL_PAGE_BYTES, thinking: true })
})
it('pages back on scroll-up, prepends, and keeps the viewport on the same content', async () => {
@@ -167,7 +167,7 @@ describe('ChatPanel progressive loading', () => {
await scrollTo(50)
expect(pending).toHaveLength(2)
- expect(pending[1].page).toEqual({ before: 1000, maxBytes: CHAT_OLDER_PAGE_BYTES })
+ expect(pending[1].page).toEqual({ before: 1000, maxBytes: CHAT_OLDER_PAGE_BYTES, thinking: true })
expect(host.querySelector('.term-chat__older')?.textContent).toContain('Loading earlier messages…')
// The app's one spinner, inside the row that is the status region.
expect(host.querySelector('.term-chat__older[role="status"] .nt-spinner')).not.toBeNull()
@@ -205,7 +205,7 @@ describe('ChatPanel progressive loading', () => {
expect(pending).toHaveLength(2)
await act(async () => row.querySelector('button')!.click())
expect(pending).toHaveLength(3)
- expect(pending[2].page).toEqual({ before: 1000, maxBytes: CHAT_OLDER_PAGE_BYTES })
+ expect(pending[2].page).toEqual({ before: 1000, maxBytes: CHAT_OLDER_PAGE_BYTES, thinking: true })
await settle(2, { messages: [say(0, 'older')], olderCursor: null })
expect(bubbles()).toEqual(['older', 'tail'])
})
@@ -231,7 +231,7 @@ describe('ChatPanel progressive loading', () => {
useAgentStatus.setState((s) => ({ byId: { ...s.byId, [NODE]: { state: 'done' } as never } }))
})
expect(pending).toHaveLength(3)
- expect(pending[2].page).toEqual({ maxBytes: CHAT_TAIL_PAGE_BYTES })
+ expect(pending[2].page).toEqual({ maxBytes: CHAT_TAIL_PAGE_BYTES, thinking: true })
await settle(2, { messages: [say(1000, 'm1000'), say(2000, 'm2000')], olderCursor: 1000 })
expect(bubbles()).toEqual(['m0', 'm1000', 'm2000'])
})
@@ -256,7 +256,7 @@ describe('ChatPanel progressive loading', () => {
await render()
await settle(0, { messages: [say(1000, 'short')], olderCursor: 1000 })
expect(pending).toHaveLength(2)
- expect(pending[1].page).toEqual({ before: 1000, maxBytes: CHAT_OLDER_PAGE_BYTES })
+ expect(pending[1].page).toEqual({ before: 1000, maxBytes: CHAT_OLDER_PAGE_BYTES, thinking: true })
})
it('a HIDDEN panel (collapsed node, display:none: every metric 0) never pages in the background', async () => {
@@ -303,7 +303,7 @@ describe('ChatPanel progressive loading', () => {
expect(bubbles()).toEqual(['tail'])
await scrollTo(0)
expect(pending).toHaveLength(4)
- expect(pending[3].page).toEqual({ before: 1000, maxBytes: CHAT_OLDER_PAGE_BYTES })
+ expect(pending[3].page).toEqual({ before: 1000, maxBytes: CHAT_OLDER_PAGE_BYTES, thinking: true })
})
it('switching session while an older page is in flight drops that page and starts clean', async () => {
@@ -332,7 +332,7 @@ describe('ChatPanel progressive loading', () => {
expect(pending).toHaveLength(3)
await settle(2, { messages: [say(1000, 'tail')], olderCursor: 1000 })
expect(pending).toHaveLength(4)
- expect(pending[3].page).toEqual({ before: 1000, maxBytes: CHAT_OLDER_PAGE_BYTES })
+ expect(pending[3].page).toEqual({ before: 1000, maxBytes: CHAT_OLDER_PAGE_BYTES, thinking: true })
})
// A tail window can hold no message at all and still have history behind it (its records were
// all metadata, or — before core grew such windows — one line bigger than the page). That is
@@ -343,7 +343,7 @@ describe('ChatPanel progressive loading', () => {
expect(host.textContent).not.toContain('No conversation yet.')
expect(host.querySelector('[role="status"]')?.textContent).toContain('Loading conversation…')
expect(pending).toHaveLength(2) // it paged back on its own
- expect(pending[1].page).toEqual({ before: 5000, maxBytes: CHAT_OLDER_PAGE_BYTES })
+ expect(pending[1].page).toEqual({ before: 5000, maxBytes: CHAT_OLDER_PAGE_BYTES, thinking: true })
await settle(1, { messages: [say(0, 'older')], olderCursor: null })
expect(bubbles()).toEqual(['older'])
expect(host.textContent).not.toContain('Loading conversation…')
@@ -357,7 +357,7 @@ describe('ChatPanel progressive loading', () => {
expect(host.textContent).toContain("Couldn't load earlier messages.")
await act(async () => host.querySelector<HTMLButtonElement>('.term-chat__older .term-chat__retry')!.click())
expect(pending).toHaveLength(3)
- expect(pending[2].page).toEqual({ before: 5000, maxBytes: CHAT_OLDER_PAGE_BYTES })
+ expect(pending[2].page).toEqual({ before: 5000, maxBytes: CHAT_OLDER_PAGE_BYTES, thinking: true })
})
it('switching session to one whose read REJECTS clears the previous session\'s thread', async () => {
diff --git a/src/renderer/nodes/ChatPanel.tsx b/src/renderer/nodes/ChatPanel.tsx
index 1164862d4..25a8556ff 100644
--- a/src/renderer/nodes/ChatPanel.tsx
+++ b/src/renderer/nodes/ChatPanel.tsx
@@ -419,6 +419,7 @@ export function ChatPanel({
// history pages in on scroll-up, and a reload merges by key instead of discarding it.
void api.chat.readTranscript(sessionId, readCwd, accountId, nodeId, agentId, {
maxBytes: CHAT_TAIL_PAGE_BYTES,
+ thinking: true,
// A hook-driven refresh the user did not ask for: an expensive reader (opencode's export) may
// space these out. An open, ↻, Retry or a held-request rebind is never marked.
...(live && !rebind ? { background: true } : {})
@@ -515,7 +516,8 @@ export function ChatPanel({
}
void api.chat.readTranscript(sessionId, readCwd, accountId, nodeId, agentId, {
before,
- maxBytes: CHAT_OLDER_PAGE_BYTES
+ maxBytes: CHAT_OLDER_PAGE_BYTES,
+ thinking: true
}).then(
(res) => {
if (token !== olderReqRef.current) return
@@ -1009,11 +1011,11 @@ export function ChatPanel({
p.kind === 'text' ? (
<MarkdownText key={j} text={p.text} />
) : p.kind === 'thinking' ? (
- // Reasoning, not the answer: collapsed by default so it cannot be mistaken for it.
- <details key={j} className="term-chat__thinking">
- <summary>Thinking</summary>
+ // Claude's thinking summary — the "thinking out loud" line its TUI prints between
+ // tool calls. Shown inline like the TUI does, dimmed so it never reads as the answer.
+ <div key={j} className="term-chat__thinking">
<MarkdownText text={p.text} />
- </details>
+ </div>
) : 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.
diff --git a/src/renderer/nodes/ChatPanel.ux.test.tsx b/src/renderer/nodes/ChatPanel.ux.test.tsx
index 1f5be8baa..b97884178 100644
--- a/src/renderer/nodes/ChatPanel.ux.test.tsx
+++ b/src/renderer/nodes/ChatPanel.ux.test.tsx
@@ -185,19 +185,27 @@ describe('ChatPanel rendering', () => {
expect(card.querySelector('.term-chat__tool-result')).toBeNull()
})
- it('renders a thinking part as a collapsed "Thinking" disclosure, not as answer text', async () => {
+ it('renders a thinking summary inline and dimmed, apart from the answer text', async () => {
await render()
+
await resolveAt(0, [{ role: 'assistant', parts: [{ kind: 'thinking', text: 'pondering' }, { kind: 'text', text: 'answer' }] }])
- const d = host.querySelector('details.term-chat__thinking') as HTMLDetailsElement
- expect(d).not.toBeNull()
- expect(d.open).toBe(false)
- expect(d.querySelector('summary')?.textContent).toBe('Thinking')
- expect(d.textContent).toContain('pondering')
- // The answer stays ordinary text, outside the disclosure.
+
+ const thinking = host.querySelector('.term-chat__thinking')
+ expect(thinking?.textContent).toContain('pondering')
+ expect(host.querySelector('details.term-chat__thinking')).toBeNull()
+ // The answer stays ordinary text, outside the thinking block.
const answers = [...host.querySelectorAll('.term-chat__msg > .term-chat__text')].map((e) => e.textContent?.trim())
expect(answers).toEqual(['answer'])
})
+ it('asks for thinking summaries on the tail read', async () => {
+ await render()
+
+ const page = (readTranscript.mock.calls[0] as unknown[] | undefined)?.[5] as { thinking?: boolean } | undefined
+
+ expect(page?.thinking).toBe(true)
+ })
+
it('names the node agent in the composer, not Claude', async () => {
await render({ agentId: 'grok' })
await resolveAt(0, [])
diff --git a/src/renderer/styles.css b/src/renderer/styles.css
index 657eb3e36..c5f5d6f36 100644
--- a/src/renderer/styles.css
+++ b/src/renderer/styles.css
@@ -4008,20 +4008,11 @@ body,
.term-chat__refresh:hover {
background: rgba(var(--tint-rgb), 0.1);
}
-/* Reasoning, collapsed by default and dimmed so it never reads as the answer. */
+/* Claude's thinking summary between tool calls: inline like the TUI, dimmed so it never reads as
+ the answer. */
.term-chat__thinking {
margin: 4px 0;
- font-size: 12px;
- color: rgba(var(--tint-rgb), 0.6);
-}
-.term-chat__thinking summary {
- cursor: pointer;
- font-style: italic;
-}
-.term-chat__thinking .term-chat__text {
- margin-top: 4px;
- padding-left: 8px;
- border-left: 2px solid rgba(var(--tint-rgb), 0.15);
+ color: var(--muted);
}
/* Transparent overlay that lets you pan across a terminal until you dwell/click. */
diff --git a/src/shared/chat-fixtures/README.md b/src/shared/chat-fixtures/README.md
index 1563b9102..6251a8d3d 100644
--- a/src/shared/chat-fixtures/README.md
+++ b/src/shared/chat-fixtures/README.md
@@ -81,7 +81,7 @@ the production paging, not a second implementation of it.
| `model-effort-no-carry` | ONE record answers both fields. The newest record states no `effort`, so the key is absent, and an older record's value is never carried forward (same rule as `parseLatestUsage`). |
| `model-effort-synthetic` | A `<synthetic>` record (an API error or interrupt, with no effort) is skipped entirely, so both fields come from the real record before it. |
| `model-effort-utf16` | The 100-character cap counts **UTF-16 code units** (Swift `utf16.count`), not bytes or scalars. A model of 50 × U+1F9EA (100 units) is kept, and an effort of 101 units is absent. |
-| `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. |
+| `thinking` | Thinking blocks (`thinking`, `redacted_thinking`). The reader **drops** them by default: a thinking-only record yields no message, and a mixed record keeps only its text. The port must match this. (The desktop ⌘M panel opts in with `page.thinking: true` and then gets a `{kind:"thinking", text}` part for each block whose `thinking` text is non-blank; the phone's `chat.page` never sets it, so these fixtures are unchanged.) |
| `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"`), 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) are all KEPT; the caveat and a skill body (none of the three fields) are skipped. Three of the kept records then render as system chips (see **System-injected records**): BOTH `origin.kind:"peer"` records — the hand-back and the `origin`-only one — as `Agent message`, and the auto-continuation as `System`; the others stay user messages. |
diff --git a/src/shared/chat-page.test.ts b/src/shared/chat-page.test.ts
index cb53f6119..3936cdd30 100644
--- a/src/shared/chat-page.test.ts
+++ b/src/shared/chat-page.test.ts
@@ -16,6 +16,13 @@ describe('normalizeChatPage — the page arg arrives over IPC/WS and is untruste
expect(normalizeChatPage({})).toEqual({ before: null, maxBytes: CHAT_PAGE_DEFAULT_BYTES })
})
+ it('keeps `thinking` only as a literal true', () => {
+ expect(normalizeChatPage({ thinking: true })).toEqual({ before: null, maxBytes: CHAT_PAGE_DEFAULT_BYTES, thinking: true })
+ for (const thinking of [false, 'true', 1, {}]) {
+ expect(normalizeChatPage({ thinking })).not.toHaveProperty('thinking')
+ }
+ })
+
it('clamps maxBytes into [MIN, MAX] and floors fractions', () => {
expect(normalizeChatPage({ maxBytes: 1 })!.maxBytes).toBe(CHAT_PAGE_MIN_BYTES)
expect(normalizeChatPage({ maxBytes: 1e12 })!.maxBytes).toBe(CHAT_PAGE_MAX_BYTES)
diff --git a/src/shared/chat-page.ts b/src/shared/chat-page.ts
index 79e986a40..a0fbff142 100644
--- a/src/shared/chat-page.ts
+++ b/src/shared/chat-page.ts
@@ -22,6 +22,11 @@ export interface ChatTranscriptPageRequest {
* asked for. Readers whose read is expensive (opencode's `export`) may space these out; a
* reader that ignores it answers exactly as before. */
background?: boolean
+ /** Also emit `thinking` parts for claude's readable thinking summaries (the "thinking out loud"
+ * lines its TUI prints between tool calls). Opt-in so every other caller — the phone's
+ * `chat.page`, and the Swift ports locked to the shared fixtures — gets the same parts as before.
+ * Only claude's reader honours it. */
+ thinking?: boolean
}
/** A validated page: `before: null` = end of file. */
@@ -30,6 +35,8 @@ export interface ChatTranscriptPage {
maxBytes: number
/** Present (and `true`) only for a background live refresh — see the request field. */
background?: true
+ /** Present (and `true`) only when the caller asked for thinking parts — see the request field. */
+ thinking?: true
}
/**
@@ -57,8 +64,13 @@ export function normalizeChatPage(page: unknown): ChatTranscriptPage | null {
if (typeof maxBytes === 'number' && Number.isFinite(maxBytes)) {
m = Math.min(CHAT_PAGE_MAX_BYTES, Math.max(CHAT_PAGE_MIN_BYTES, Math.floor(maxBytes)))
}
- const { background } = page as { background?: unknown }
- return background === true ? { before: b, maxBytes: m, background: true } : { before: b, maxBytes: m }
+ const { background, thinking } = page as { background?: unknown; thinking?: unknown }
+ return {
+ before: b,
+ maxBytes: m,
+ ...(background === true ? { background: true as const } : {}),
+ ...(thinking === true ? { thinking: true as const } : {})
+ }
}
/**