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): opt-in rich reads; pasted images render in the thread

reviewb419852c85a0
diff --git a/src/core/gemini-chat.test.ts b/src/core/gemini-chat.test.ts
index e59f14ce3..34eed7369 100644
--- a/src/core/gemini-chat.test.ts
+++ b/src/core/gemini-chat.test.ts
@@ -44,7 +44,7 @@ const msg = (id: string, type: string, content: unknown, extra: Rec = {}): Rec =
})
const jsonl = (...recs: unknown[]): string => recs.map((r) => (typeof r === 'string' ? r : JSON.stringify(r))).join('\n') + '\n'
const texts = (ms: ChatMessage[]): string[] =>
- ms.map((m) => `${m.role}:${m.parts.map((p) => (p.kind === 'tool' ? `[${p.name}|${p.arg}|${p.result ?? ''}]` : p.text)).join('+')}`)
+ ms.map((m) => `${m.role}:${m.parts.map((p) => (p.kind === 'tool' ? `[${p.name}|${p.arg}|${p.result ?? ''}]` : p.kind === 'image' ? '[image]' : p.text)).join('+')}`)
describe('chatFromGemini — the fold', () => {
it('renders a typed prompt and the model answer, stamped with their own timestamps', () => {
diff --git a/src/core/transcript-ipc.test.ts b/src/core/transcript-ipc.test.ts
index 42c3d2aa3..8f08111fd 100644
--- a/src/core/transcript-ipc.test.ts
+++ b/src/core/transcript-ipc.test.ts
@@ -345,6 +345,35 @@ describe('registerTranscriptIpc — paged chat reads', () => {
expect(without.messages.map((m) => m.parts)).toEqual([[{ kind: 'text', text: 'go' }], [{ kind: 'text', text: 'the answer' }]])
})
+ it('emits image parts only when the page asks for rich, and either flag alone keeps the other off', async () => {
+ writeTranscript(
+ lines(
+ {
+ type: 'user',
+ message: {
+ content: [
+ { type: 'text', text: 'see' },
+ { type: 'image', source: { type: 'base64', media_type: 'image/png', data: 'iVBORw0' } }
+ ]
+ }
+ },
+ thinkingLine('looking at it', 'a cat')
+ )
+ )
+ registerTranscriptIpc()
+ const parts = async (page: object) => (await paged({ maxBytes: 65536, ...page })).messages.map((m) => m.parts)
+ const image = { kind: 'image', mediaType: 'image/png', data: 'iVBORw0' }
+ const thought = { kind: 'thinking', text: 'looking at it' }
+
+ expect(await parts({ thinking: true, rich: true })).toEqual([
+ [{ kind: 'text', text: 'see' }, image],
+ [thought, { kind: 'text', text: 'a cat' }]
+ ])
+ expect(await parts({ rich: true })).toEqual([[{ kind: 'text', text: 'see' }, image], [{ kind: 'text', text: 'a cat' }]])
+ expect(await parts({ thinking: true })).toEqual([[{ kind: 'text', text: 'see' }], [thought, { kind: 'text', text: 'a cat' }]])
+ expect(await parts({})).toEqual([[{ kind: 'text', text: 'see' }], [{ kind: 'text', text: 'a cat' }]])
+ })
+
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' }] } })
diff --git a/src/core/transcript-ipc.ts b/src/core/transcript-ipc.ts
index c3cdb71ab..d458691a4 100644
--- a/src/core/transcript-ipc.ts
+++ b/src/core/transcript-ipc.ts
@@ -191,10 +191,17 @@ 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
+ // Thinking summaries and rich parts only when asked (the ⌘M panel asks; the phone does not), on
+ // BOTH legs. Neither flag set = the bare parser, so the phone's page is byte-for-byte unchanged.
+ const parse =
+ page.thinking || page.rich
+ ? (buf: Buffer, bufStart: number) =>
+ parseChatWindow(
+ buf,
+ bufStart,
+ claudeChatRecordParser({ thinking: page.thinking === true, rich: page.rich === true })
+ )
+ : parseChatWindow
const readRemotePage = deps.readRemotePage
if (readRemotePage) {
const remote = await readRemotePage(q, page)
diff --git a/src/core/transcript-reader.test.ts b/src/core/transcript-reader.test.ts
index 2e0716021..445fe0328 100644
--- a/src/core/transcript-reader.test.ts
+++ b/src/core/transcript-reader.test.ts
@@ -112,7 +112,14 @@ describe('readSessionName — remote (SSH project) sessions', () => {
// ─────────────────────────────────────────────────────────────────────────────────────────────
import os from 'os'
import path from 'path'
-import { claudeChatRecordParser, parseChatMessages, parseChatWindow, readChatWindow, SYSTEM_RESULT_MAX } from './transcript-reader'
+import {
+ CHAT_IMAGE_TYPES,
+ claudeChatRecordParser,
+ parseChatMessages,
+ parseChatWindow,
+ readChatWindow,
+ SYSTEM_RESULT_MAX
+} from './transcript-reader'
const jl = (o: object): string => JSON.stringify(o) + '\n'
const said = (role: 'user' | 'assistant', text: string): string =>
@@ -434,6 +441,83 @@ describe('thinking parts (opt-in `thinking`)', () => {
})
})
+describe('image parts (opt-in `rich`)', () => {
+ // The measured shape (CLI 2.1.314): a pasted image is a block of the user record's content array.
+ const userLine = (content: unknown[]): string => JSON.stringify({ type: 'user', message: { content } })
+ const image = (media_type: unknown, data: unknown = 'iVBORw0', sourceType: unknown = 'base64') => ({
+ type: 'image',
+ source: { type: sourceType, media_type, data }
+ })
+
+ it('rich: a pasted image becomes an image part; without rich the record keeps only its text', () => {
+ const line = userLine([{ type: 'text', text: 'see' }, image('image/png')])
+ expect(parseChatMessages([line], { rich: true })[0].parts).toEqual([
+ { kind: 'text', text: 'see' },
+ { kind: 'image', mediaType: 'image/png', data: 'iVBORw0' }
+ ])
+ expect(parseChatMessages([line])[0].parts).toEqual([{ kind: 'text', text: 'see' }])
+ expect(parseChatMessages([line], { thinking: true })[0].parts).toEqual([{ kind: 'text', text: 'see' }])
+ })
+
+ it('rich: each allowlisted media type is kept, in content order; an image-only record is a message', () => {
+ expect([...CHAT_IMAGE_TYPES]).toEqual(['image/png', 'image/jpeg', 'image/gif', 'image/webp'])
+ const line = userLine(CHAT_IMAGE_TYPES.map((t) => image(t, `d-${t}`)))
+ expect(parseChatMessages([line], { rich: true })).toEqual([
+ { role: 'user', parts: CHAT_IMAGE_TYPES.map((t) => ({ kind: 'image', mediaType: t, data: `d-${t}` })) }
+ ])
+ // Without the option the same record has nothing to show, as before.
+ expect(parseChatMessages([line])).toEqual([])
+ })
+
+ it('rich: an image of an unknown media type, a non-base64 source, or inside a tool_result yields no part', () => {
+ const refused = [
+ image('image/svg+xml'), // scriptable markup, never a data: URL in the thread
+ image('image/bmp'),
+ image('IMAGE/PNG'),
+ image(undefined),
+ image('image/png', ''),
+ image('image/png', 42),
+ { type: 'image', source: { type: 'base64', media_type: 'image/png' } }, // no data
+ image('image/png', 'iVBORw0', 'url'),
+ { type: 'image', source: { type: 'url', url: 'https://example.com/x.png' } },
+ { type: 'image' },
+ { type: 'image', source: null }
+ ]
+ const line = userLine([{ type: 'text', text: 'see' }, ...refused])
+ expect(parseChatMessages([line], { rich: true })[0].parts).toEqual([{ kind: 'text', text: 'see' }])
+
+ // An image a tool returned is tool OUTPUT: its call's result stays the text summary, as today.
+ const raw =
+ toolUse('t1', 'screenshot') +
+ jl({
+ type: 'user',
+ message: {
+ content: [
+ { type: 'tool_result', tool_use_id: 't1', content: [{ type: 'text', text: 'shot' }, image('image/png')] }
+ ]
+ }
+ })
+ expect(parseChatMessages(raw.split('\n'), { rich: true }).flatMap((m) => m.parts)).toEqual([
+ { kind: 'tool', name: 'Bash', arg: 'screenshot', result: 'shot' }
+ ])
+ })
+
+ it('rich rides the paged parser too (claudeChatRecordParser), and combines with thinking', () => {
+ const file = Buffer.from(
+ jl({ type: 'user', message: { content: [image('image/webp', 'UklGR')] } }) +
+ jl({ type: 'assistant', message: { content: [{ type: 'thinking', thinking: 'hmm', signature: 's' }] } })
+ )
+ const parts = (opts: { thinking?: boolean; rich?: boolean }) =>
+ parseChatWindow(file, 0, claudeChatRecordParser(opts)).messages.flatMap((m) => m.parts)
+ expect(parts({ thinking: true, rich: true })).toEqual([
+ { kind: 'image', mediaType: 'image/webp', data: 'UklGR' },
+ { kind: 'thinking', text: 'hmm' }
+ ])
+ expect(parts({ rich: true })).toEqual([{ kind: 'image', mediaType: 'image/webp', data: 'UklGR' }])
+ expect(parts({ thinking: true })).toEqual([{ kind: 'thinking', text: 'hmm' }])
+ })
+})
+
describe('readChatWindow — byte windows read from a real file', () => {
let dir: string
afterEach(() => {
diff --git a/src/core/transcript-reader.ts b/src/core/transcript-reader.ts
index c14672211..5300f58c6 100644
--- a/src/core/transcript-reader.ts
+++ b/src/core/transcript-reader.ts
@@ -367,6 +367,31 @@ export interface ChatParseOptions {
* how long the model thought, when the stamps can tell (see the `ChatPart` type).
*/
thinking?: boolean
+ /**
+ * Emit the parts only the desktop ⌘M panel draws. Today: an `image` part for each image block of a
+ * user record's content array — a pasted screenshot, measured (CLI 2.1.314) as
+ * `{type:'image', source:{type:'base64', media_type, data}}` — when the source is base64, its
+ * 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.
+ */
+ rich?: boolean
+}
+
+/**
+ * The image types an `image` part may carry (`ChatParseOptions.rich`): the raster formats claude
+ * accepts as a pasted image. Closed on purpose — anything else (`image/svg+xml` is scriptable markup,
+ * an unknown type is unrenderable) yields no part rather than a `data:` URL of unknown content.
+ */
+export const CHAT_IMAGE_TYPES: readonly string[] = ['image/png', 'image/jpeg', 'image/gif', 'image/webp']
+
+/** An image block of a user record, as an `image` part — or null when it is not one we draw. */
+function imagePart(source: unknown): Extract<ChatPart, { kind: 'image' }> | null {
+ if (!source || typeof source !== 'object') return null
+ const { type, media_type: mediaType, data } = source as { type?: unknown; media_type?: unknown; data?: unknown }
+ if (type !== 'base64' || typeof mediaType !== 'string' || !CHAT_IMAGE_TYPES.includes(mediaType)) return null
+ if (typeof data !== 'string' || !data) return null
+ return { kind: 'image', mediaType, data }
}
const userTextOf = (text: string, opts: ChatParseOptions | undefined): string =>
opts?.expandPastes === false ? text : expandPastedContent(text)
@@ -616,11 +641,16 @@ function parseChatRecords(
text?: string
tool_use_id?: string
content?: unknown
+ source?: unknown
}>) {
if (!c || typeof c !== 'object') continue
// A non-string `text` is passed through as before; only a string is a paste to expand.
if (c.type === 'text' && c.text) parts.push({ kind: 'text', text: typeof c.text === 'string' ? userTextOf(c.text, opts) : c.text })
- else if (c.type === 'tool_result') {
+ else if (c.type === 'image') {
+ // Opt-in (see `ChatParseOptions.rich`): without it the record keeps only its text, as before.
+ const part = opts?.rich ? imagePart(c.source) : null
+ if (part) parts.push(part)
+ } else if (c.type === 'tool_result') {
const tool = c.tool_use_id ? toolById.get(c.tool_use_id) : undefined
const s = summarizeResult(c.content)
if (tool) {
diff --git a/src/renderer/lib/chatPaging.test.ts b/src/renderer/lib/chatPaging.test.ts
index ee1b55552..aa912d5ad 100644
--- a/src/renderer/lib/chatPaging.test.ts
+++ b/src/renderer/lib/chatPaging.test.ts
@@ -26,7 +26,7 @@ const page = (
const texts = (t: ChatThread): string[] =>
t.messages.map((m) => {
const p = m.parts[0]
- return p.kind === 'tool' ? `tool:${p.id}:${p.result ?? '-'}` : p.text
+ return p.kind === 'tool' ? `tool:${p.id}:${p.result ?? '-'}` : p.kind === 'image' ? 'image' : p.text
})
describe('attachCarried', () => {
diff --git a/src/renderer/nodes/ChatImage.tsx b/src/renderer/nodes/ChatImage.tsx
new file mode 100644
index 000000000..ecd9a53e2
--- /dev/null
+++ b/src/renderer/nodes/ChatImage.tsx
@@ -0,0 +1,20 @@
+import { useState } from 'react'
+
+/**
+ * An image the user attached to a prompt, in the ⌘M thread: a height-capped thumbnail inside the
+ * bubble that a click shows at full size (and a second click shrinks back). The parser hands over
+ * only an allowlisted raster type with a base64 payload (`CHAT_IMAGE_TYPES`), so the `data:` URL is
+ * never markup. Lazy: a long thread of screenshots decodes only the ones scrolled into view.
+ */
+export function ChatImage({ mediaType, data }: { mediaType: string; data: string }): JSX.Element {
+ const [full, setFull] = useState(false)
+ return (
+ <img
+ className={`term-chat__image${full ? ' term-chat__image--full' : ''}`}
+ src={`data:${mediaType};base64,${data}`}
+ alt="Attached image"
+ loading="lazy"
+ onClick={() => setFull((f) => !f)}
+ />
+ )
+}
diff --git a/src/renderer/nodes/ChatPanel.live.test.tsx b/src/renderer/nodes/ChatPanel.live.test.tsx
index 2e6f98945..357c9a645 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, thinking: true })
+ expect(pending[1].page).toEqual({ maxBytes: CHAT_TAIL_PAGE_BYTES, background: true, thinking: true, rich: 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, thinking: true })
+ expect(pending[2].page).toEqual({ maxBytes: CHAT_TAIL_PAGE_BYTES, background: true, thinking: true, rich: 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, thinking: true })
+ expect(pending[2].page).toEqual({ maxBytes: CHAT_TAIL_PAGE_BYTES, background: true, thinking: true, rich: 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, thinking: true })
+ expect(pending[1].page).toEqual({ maxBytes: CHAT_TAIL_PAGE_BYTES, background: true, thinking: true, rich: 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 9fdef4d0d..9c4d24cfd 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, thinking: true })
+ expect(pending[0].page).toEqual({ maxBytes: CHAT_TAIL_PAGE_BYTES, thinking: true, rich: 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, thinking: true })
+ expect(pending[1].page).toEqual({ before: 1000, maxBytes: CHAT_OLDER_PAGE_BYTES, thinking: true, rich: 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, thinking: true })
+ expect(pending[2].page).toEqual({ before: 1000, maxBytes: CHAT_OLDER_PAGE_BYTES, thinking: true, rich: 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, thinking: true })
+ expect(pending[2].page).toEqual({ maxBytes: CHAT_TAIL_PAGE_BYTES, thinking: true, rich: 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, thinking: true })
+ expect(pending[1].page).toEqual({ before: 1000, maxBytes: CHAT_OLDER_PAGE_BYTES, thinking: true, rich: 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, thinking: true })
+ expect(pending[3].page).toEqual({ before: 1000, maxBytes: CHAT_OLDER_PAGE_BYTES, thinking: true, rich: 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, thinking: true })
+ expect(pending[3].page).toEqual({ before: 1000, maxBytes: CHAT_OLDER_PAGE_BYTES, thinking: true, rich: 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, thinking: true })
+ expect(pending[1].page).toEqual({ before: 5000, maxBytes: CHAT_OLDER_PAGE_BYTES, thinking: true, rich: 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, thinking: true })
+ expect(pending[2].page).toEqual({ before: 5000, maxBytes: CHAT_OLDER_PAGE_BYTES, thinking: true, rich: true })
})
it('switching session to one whose read REJECTS clears the previous session\'s thread', async () => {
diff --git a/src/renderer/nodes/ChatPanel.thread.test.tsx b/src/renderer/nodes/ChatPanel.thread.test.tsx
index aa601c5ca..038495852 100644
--- a/src/renderer/nodes/ChatPanel.thread.test.tsx
+++ b/src/renderer/nodes/ChatPanel.thread.test.tsx
@@ -14,11 +14,15 @@ import { useAgentStatus } from '../state/agentStatus'
;(globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true
const { session, reads } = vi.hoisted(() => {
- const reads: { messages: unknown[] } = { messages: [] }
+ const reads: { messages: unknown[]; lastPage?: Record<string, unknown> } = { messages: [] }
const session = {
api: {
chat: {
- readTranscript: async () => ({ messages: reads.messages, found: true, olderCursor: null, unmatchedResults: [] })
+ // The trailing `page` argument is recorded, so a test can pin what the panel asks for.
+ readTranscript: async (...args: unknown[]) => {
+ reads.lastPage = args[5] as Record<string, unknown>
+ return { messages: reads.messages, found: true, olderCursor: null, unmatchedResults: [] }
+ }
},
pty: { sendText: vi.fn(async () => true as const) }
}
@@ -56,6 +60,7 @@ afterEach(async () => {
async function mount(messages: ChatMessage[]): Promise<void> {
reads.messages = messages
+ reads.lastPage = undefined
await act(async () => {
root.render(<ChatPanel nodeId={NODE} sessionId="s1" agentId="claude" />)
})
@@ -64,6 +69,11 @@ async function mount(messages: ChatMessage[]): Promise<void> {
})
}
+const lastPageArg = (): Record<string, unknown> => {
+ expect(reads.lastPage, 'readTranscript was not called with a page').toBeTruthy()
+ return reads.lastPage!
+}
+
const now = Date.now()
const thread: ChatMessage[] = [
{ role: 'user', parts: [{ kind: 'text', text: 'fix it' }], key: 0, at: now - 10 * MIN },
@@ -228,6 +238,24 @@ describe('⌘M thread look', () => {
expect(host.querySelector('details.term-chat__thinking > summary')?.textContent).toBe('Thinking')
})
+ it('renders an image part as a thumbnail that enlarges on click', async () => {
+ await mount([{ role: 'user', parts: [{ kind: 'image', mediaType: 'image/png', data: 'AAAA' }], key: 0 }])
+ const img = host.querySelector<HTMLImageElement>('.term-chat__msg--user img.term-chat__image')!
+ expect(img.src).toBe('data:image/png;base64,AAAA')
+ expect(img.alt).toBe('Attached image')
+ expect(img.getAttribute('loading')).toBe('lazy')
+ expect(img.classList.contains('term-chat__image--full')).toBe(false)
+ await act(async () => img.click())
+ expect(img.classList.contains('term-chat__image--full')).toBe(true)
+ await act(async () => img.click())
+ expect(img.classList.contains('term-chat__image--full')).toBe(false)
+ })
+
+ it('asks the reader for rich parts', async () => {
+ await mount([])
+ expect(lastPageArg().rich).toBe(true)
+ })
+
it('a day that starts inside a folded tool run keeps its divider (drawn where the run ends)', async () => {
const midnight = new Date(now).setHours(0, 0, 0, 0)
await mount([
diff --git a/src/renderer/nodes/ChatPanel.tsx b/src/renderer/nodes/ChatPanel.tsx
index 7b77909d0..8a4f2ca0c 100644
--- a/src/renderer/nodes/ChatPanel.tsx
+++ b/src/renderer/nodes/ChatPanel.tsx
@@ -60,6 +60,7 @@ import { assistantTurnEnds, chatAbsoluteTime, chatClockTime, dayDividers } from
import { groupToolCalls, partPosition } from '../lib/chatToolGroups'
import { thinkingLabel } from '../lib/chatThinking'
import { ChatToolGroup } from './ChatToolGroup'
+import { ChatImage } from './ChatImage'
import { FALLBACK_SESSION_NOTE, transcriptReadCwd } from '../lib/transcriptSession'
import { chatPageDirection, pageChatThread } from '../lib/chatPageKeys'
@@ -444,6 +445,7 @@ export function ChatPanel({
void api.chat.readTranscript(sessionId, readCwd, accountId, nodeId, agentId, {
maxBytes: CHAT_TAIL_PAGE_BYTES,
thinking: true,
+ rich: 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 } : {})
@@ -541,7 +543,8 @@ export function ChatPanel({
void api.chat.readTranscript(sessionId, readCwd, accountId, nodeId, agentId, {
before,
maxBytes: CHAT_OLDER_PAGE_BYTES,
- thinking: true
+ thinking: true,
+ rich: true
}).then(
(res) => {
if (token !== olderReqRef.current) return
@@ -1006,6 +1009,9 @@ export function ChatPanel({
<summary>{thinkingLabel(p.ms)}</summary>
<MarkdownText text={p.text} />
</details>
+ ) : 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.
diff --git a/src/renderer/styles.chat-view.test.ts b/src/renderer/styles.chat-view.test.ts
index 501e80d9f..a41864ff9 100644
--- a/src/renderer/styles.chat-view.test.ts
+++ b/src/renderer/styles.chat-view.test.ts
@@ -97,6 +97,11 @@ describe('⌘M thread: claude.ai look', () => {
expect(ruleBody('.term-chat__thinking > summary::before')).toMatch(/transform:\s*rotate\(-45deg\);/)
expect(ruleBody('.term-chat__thinking[open] > summary::before')).toMatch(/transform:\s*rotate\(45deg\);/)
})
+
+ it('an attached image is a bounded thumbnail; enlarged, it drops the height cap', () => {
+ expect(ruleBody('.term-chat__image')).toMatch(/max-height:\s*240px;/)
+ expect(ruleBody('.term-chat__image--full')).toMatch(/max-height:\s*none;/)
+ })
})
describe('the shared .term-chat__input (plan "Revise…", question "Other") keeps a visible field', () => {
diff --git a/src/renderer/styles.css b/src/renderer/styles.css
index 46fc9585d..5c365da17 100644
--- a/src/renderer/styles.css
+++ b/src/renderer/styles.css
@@ -4204,6 +4204,20 @@ body,
.term-chat__thinking > .term-chat__text {
margin-top: 4px;
}
+/* An image the user attached to a prompt (ChatImage): a height-capped thumbnail in the bubble; a click
+ drops the cap to show it at full size, still never wider than the bubble. */
+.term-chat__image {
+ display: block;
+ max-width: 100%;
+ max-height: 240px;
+ margin: 4px 0;
+ border-radius: 8px;
+ cursor: zoom-in;
+}
+.term-chat__image--full {
+ max-height: none;
+ cursor: zoom-out;
+}
/* Transparent overlay that lets you pan across a terminal until you dwell/click. */
.term-hover-guard {
diff --git a/src/shared/chat-fixtures/README.md b/src/shared/chat-fixtures/README.md
index e81281a89..889cc5a7f 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 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.) |
+| `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, ms?}` part for each block whose `thinking` text is non-blank: `text` is capped at 16384 UTF-16 units, and `ms` is this record's timestamp minus that of the newest `user` record before it (a prompt, a `tool_result` or a hidden meta line), present only when both stamps exist and the gap is ≥ 0 — see the `ChatPart` doc in `src/shared/types.ts`. 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. |
@@ -89,6 +89,18 @@ the production paging, not a second implementation of it.
| `pasted-content` | **Pasted content**: a span between typed lines, backtick runs inside (a five-backtick fence) and the same id twice, an array text part beside an image, a pasted `<task-notification>` (stays the user's paste), a close tag with a different id inside a span (content), an empty paste, a same-id open nested inside a span (the span ends at the FIRST close), text that is not the CLI's grammar (no id, an upper-case or three- or five-digit id, a missing newline after the open or before the close: all left as typed) and an unclosed span (left as typed). |
| `queued-prompts` | **Queued prompts**: a typed prompt queued mid-turn (between a tool result and the reply), one with no `origin`, an array prompt with an image (its text block only), a paste inside one (fenced, as in a typed prompt), and six attachments that stay hidden: a task notification, a peer message (`isMeta`), a coordinator message, a non-human `origin`, a blank prompt and a non-`queued_command` attachment. |
+**`rich`** is a second desktop-only opt-in, beside `thinking`: the ⌘M panel reads with
+`page.rich: true` (`ChatParseOptions.rich`) to get the parts only it draws. The fixtures never set
+it, and neither does the phone's `chat.page` (the relay host forwards only `before` / `maxBytes`), so
+nothing above changes. What it adds:
+
+- An `{kind:"image", mediaType, data}` part for each `{type:"image", source:{type:"base64",
+ media_type, data}}` block of a user record's content array, in content order, when `media_type` is
+ one of `image/png`, `image/jpeg`, `image/gif`, `image/webp` (`CHAT_IMAGE_TYPES`) and `data` is a
+ non-empty string. Any other type (`image/svg+xml` included) or source yields no part. An image
+ inside a `tool_result` is tool output and never becomes one. An image-only record yields no
+ message without the option and a user message with it.
+
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
partial answer (two questions, one answered), an unknown label, and a tool mismatch (a plan answer
diff --git a/src/shared/chat-page.test.ts b/src/shared/chat-page.test.ts
index 3936cdd30..9d2b66eaa 100644
--- a/src/shared/chat-page.test.ts
+++ b/src/shared/chat-page.test.ts
@@ -23,6 +23,19 @@ describe('normalizeChatPage — the page arg arrives over IPC/WS and is untruste
}
})
+ it('keeps `rich` only as a literal true, beside `thinking` and independent of it', () => {
+ expect(normalizeChatPage({ rich: true })).toEqual({ before: null, maxBytes: 262144, rich: true })
+ for (const rich of [false, 'yes', 1, {}]) {
+ expect(normalizeChatPage({ rich })).not.toHaveProperty('rich')
+ }
+ expect(normalizeChatPage({ thinking: true, rich: true })).toEqual({
+ before: null,
+ maxBytes: CHAT_PAGE_DEFAULT_BYTES,
+ thinking: true,
+ rich: true
+ })
+ })
+
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 a0fbff142..ab990a40a 100644
--- a/src/shared/chat-page.ts
+++ b/src/shared/chat-page.ts
@@ -27,6 +27,10 @@ export interface ChatTranscriptPageRequest {
* `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
+ /** Also emit the parts only the desktop ⌘M panel draws: an `image` part for each image the user
+ * attached to a prompt. Opt-in for the same reason as `thinking` (the phone and the Swift ports
+ * locked to the shared fixtures never set it). Only claude's reader honours it. */
+ rich?: boolean
}
/** A validated page: `before: null` = end of file. */
@@ -37,6 +41,8 @@ export interface ChatTranscriptPage {
background?: true
/** Present (and `true`) only when the caller asked for thinking parts — see the request field. */
thinking?: true
+ /** Present (and `true`) only when the caller asked for rich parts — see the request field. */
+ rich?: true
}
/**
@@ -64,12 +70,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, thinking } = page as { background?: unknown; thinking?: unknown }
+ const { background, thinking, rich } = page as { background?: unknown; thinking?: unknown; rich?: unknown }
return {
before: b,
maxBytes: m,
...(background === true ? { background: true as const } : {}),
- ...(thinking === true ? { thinking: true as const } : {})
+ ...(thinking === true ? { thinking: true as const } : {}),
+ ...(rich === true ? { rich: true as const } : {})
}
}
diff --git a/src/shared/types.ts b/src/shared/types.ts
index 29e2bc828..5cd594bcc 100644
--- a/src/shared/types.ts
+++ b/src/shared/types.ts
@@ -3600,6 +3600,18 @@ export type ChatPart =
*/
ms?: number
}
+ | {
+ /**
+ * An image the user attached to a prompt (a pasted screenshot): `data` is the base64 payload,
+ * drawn as `data:<mediaType>;base64,<data>`. Present only on the opt-in `rich` read
+ * (`ChatParseOptions.rich`), and only for a base64 source whose `mediaType` is in
+ * `CHAT_IMAGE_TYPES` (core/transcript-reader.ts) — never `image/svg+xml`. An image a tool
+ * returned (inside a `tool_result`) is tool output and never becomes one.
+ */
+ kind: 'image'
+ mediaType: string
+ data: string
+ }
| {
kind: 'tool'
name: string