Node-based terminal manager for AI coding agents — tmux-backed terminals and parallel agent sessions as draggable nodes on an infinite pan/zoom canvas. macOS, Linux, and a browser Server Edition.
TypeScript adhdagent-orchestrationai-agentscanvasclaude-codecodexcoding-agentsdeveloper-toolselectrongeminilinuxmacosmultiplexeropencodeparallel-agentsterminalterminal-emulatorterminal-multiplexertmuxworkspace-manager
fix(chat): review fixes for system-record chips (#1079)
reviewb0c8b9aa76f6
diff --git a/CLAUDE.md b/CLAUDE.mdindex 0b97dc460..3866a0434 100644--- a/CLAUDE.md+++ b/CLAUDE.md@@ -3252,8 +3252,10 @@ command-bearing opens; this does not add a human-confirm dialog or change mobile**System-injected user records are not the user's words** — a `<task-notification>`, a peer`<agent-message>`/`<cross-session-message>`, an auto-continuation/coordinator prompt — so`parseChatRecords` (and the find-bar index) renders each as ONE assistant tool part- (`classifySystemRecord`: "Background task" / "Agent message" / "System", no wire change) and- fences a human paste's `<pasted_content>` span; exact rules in `src/shared/chat-fixtures/README.md`.+ (`classifySystemRecord`: "Background task" / "Agent message" / "System", no wire change; each is+ a turn boundary in `assistantTurnEnds`) and fences a human paste's `<pasted_content>` span (the+ CLI's own 4-hex-id grammar only; titles keep the raw text) — all `indexOf` scans, never a+ backtracking regex (quadratic on unclosed tags); exact rules in `src/shared/chat-fixtures/README.md`.**Paged reads (2026-09).** `chat.readTranscript` takes a trailing optional `page`(`{before?, maxBytes?}`, `shared/chat-page.ts`). Absent = the legacy 5 MB-tail read, byte for byte(result is exactly `{messages, found}`). Present = ONE window of at most `maxBytes` (clampeddiff --git a/src/core/chat-fixtures.test.ts b/src/core/chat-fixtures.test.tsindex 00ab17a57..ffb688df7 100644--- a/src/core/chat-fixtures.test.ts+++ b/src/core/chat-fixtures.test.ts@@ -447,6 +447,10 @@ function systemRecords(): string {tn(['<task-id>a1</task-id>', '<task-id>a2</task-id>', '<status>killed</status>', `<summary>${'Long summary '.repeat(20)}</summary>`]),// A whole element with NO origin: matched by content.tn(['<status>stopped</status>', '<summary>Demo watcher stopped</summary>'], {}),+ // The same whole element sent by a HUMAN (typed or pasted unwrapped): stays a user message,+ // whether the record says so by origin or only by promptSource.+ tn(['<status>completed</status>', '<summary>pasted by hand</summary>'], { promptSource: 'typed', origin: { kind: 'human' }, turnOrigin: 'human' }),+ tn(['<status>completed</status>', '<summary>typed, no origin</summary>'], { promptSource: 'typed' }),// Malformed: origin says task-notification, no known tag → whole text as the chip.tn(['<mystery>zzz</mystery>']),{ ...user(' Background task "demo" finished while you were away. '), ...TN },@@ -491,18 +495,27 @@ function pastedContent(): string {// Array content: an image beside the typed text.{...user([- text('[Image #1] compare\n\n<pasted_content id="1f">\nx = 1\n</pasted_content id="1f">\n'),+ text('[Image #1] compare\n\n<pasted_content id="001f">\nx = 1\n</pasted_content id="001f">\n'),{ type: 'image', source: { type: 'base64', media_type: 'image/png', data: 'iVBORw0KGgo=' } }]),...HUMAN},assistant([text('Compared.')]),// A pasted task-notification is the user's own paste, not a notification.- { ...user('fyi\n<pasted_content id="1c">\n<task-notification><summary>s</summary></task-notification>\n</pasted_content id="1c">'), ...HUMAN },+ { ...user('fyi\n<pasted_content id="001c">\n<task-notification><summary>s</summary></task-notification>\n</pasted_content id="001c">'), ...HUMAN },// A close tag with another id inside a span is content: the span ends at ITS OWN id.- { ...user('<pasted_content id="a">\nold </pasted_content id="zz"> paste\n</pasted_content id="a">'), ...HUMAN },+ { ...user('<pasted_content id="000a">\nold </pasted_content id="00ff"> paste\n</pasted_content id="000a">'), ...HUMAN },+ // An empty paste; a same-id open nested inside a span (the span ends at the FIRST close).+ { ...user('<pasted_content id="abcd">\n\n</pasted_content id="abcd">'), ...HUMAN },+ { ...user('<pasted_content id="aaaa">\nx\n<pasted_content id="aaaa">\ny\n</pasted_content id="aaaa">\nz\n</pasted_content id="aaaa">'), ...HUMAN },+ // Not the CLI's grammar: each is left exactly as typed.+ { ...user('<pasted_content>\nno id\n</pasted_content>'), ...HUMAN },+ { ...user('<pasted_content id="AB12">\nupper case\n</pasted_content id="AB12">'), ...HUMAN },+ { ...user('<pasted_content id="ab123">\nfive digits\n</pasted_content id="ab123">'), ...HUMAN },+ { ...user('<pasted_content id="ab12">no newline after the open\n</pasted_content id="ab12">'), ...HUMAN },+ { ...user('<pasted_content id="ab12">\nno newline before the close</pasted_content id="ab12">'), ...HUMAN },// Unclosed: left as typed.- { ...user('<pasted_content id="9">\nnever closed'), ...HUMAN },+ { ...user('<pasted_content id="0009">\nnever closed'), ...HUMAN },assistant([text('Noted.')])])}diff --git a/src/core/recent-conversations.test.ts b/src/core/recent-conversations.test.tsindex a61e16d99..b22204d20 100644--- a/src/core/recent-conversations.test.ts+++ b/src/core/recent-conversations.test.ts@@ -203,6 +203,17 @@ describe('hostile titles', () => {expect(row).toMatchObject({ title: 'rm -rf / ; echo pwned', titleSource: 'name' })})+ it('a first prompt that STARTS with a paste is skipped for the title, as before (no fences)', async () => {+ const recs = [+ { type: 'user', message: { role: 'user', content: '<pasted_content id="ab12">\nTypeError: boom\n</pasted_content id="ab12">\nwhy?' }, sessionId: CLAUDE_ID, cwd: '/srv/demo' },+ { type: 'assistant', message: { role: 'assistant', content: [{ type: 'text', text: 'Because.' }] }, sessionId: CLAUDE_ID, cwd: '/srv/demo' },+ { type: 'user', message: { role: 'user', content: 'Fix the null check' }, sessionId: CLAUDE_ID, cwd: '/srv/demo' }+ ]+ write(path.join(roots.claude[0].root, '-srv-demo', `${CLAUDE_ID}.jsonl`), jl(...recs), 1_000)+ const items = await listRecentConversations(roots)+ expect(items.find((i) => i.agentId === 'claude')).toMatchObject({ title: 'Fix the null check', titleSource: 'prompt' })+ })+it('a harness wrapper is not a prompt', () => {expect(firstPrompt([{ role: 'user', parts: [{ kind: 'text', text: '<command-name>/clear</command-name>' }] }, { role: 'user', parts: [{ kind: 'text', text: 'real' }] }])).toBe('real')})diff --git a/src/core/recent-conversations.ts b/src/core/recent-conversations.tsindex 12451cdcf..e09002e0c 100644--- a/src/core/recent-conversations.ts+++ b/src/core/recent-conversations.ts@@ -278,7 +278,9 @@ async function parseClaude(c: Candidate): Promise<Parsed> {cwd = safeCwd(o.cwd)if (cwd) break}- const prompt = firstPrompt(parseChatMessages(lines))+ // Pastes stay as recorded: a prompt that STARTS with one begins with `<` and is skipped below,+ // and a title never carries a code fence.+ const prompt = firstPrompt(parseChatMessages(lines, { expandPastes: false }))const name = pickSessionName(await tailText(c, TITLE_TAIL_BYTES))const t = titled(name, prompt)// No prompt and no name: a transcript holding only bookkeeping (a `/clear` stub, a session thatdiff --git a/src/core/transcript-index-core.test.ts b/src/core/transcript-index-core.test.tsindex c0c158dcc..25782d4b4 100644--- a/src/core/transcript-index-core.test.ts+++ b/src/core/transcript-index-core.test.ts@@ -33,6 +33,11 @@ describe('extractEntryFields', () => {expect(f.text.length).toBeLessThanOrEqual(INDEX_TEXT_CAP_BYTES)})+ it('a paste in the first prompt adds no code fences to the title', () => {+ const r = JSON.stringify({ type: 'user', cwd: '/c', message: { content: 'see <pasted_content id="ab12">\nboom\n</pasted_content id="ab12">' } })+ expect(extractEntryFields(r).title).not.toContain('```')+ })+it('returns empty fields for unparseable input', () => {expect(extractEntryFields('garbage\n{bad json')).toEqual({ cwd: '', title: '', text: '' })})diff --git a/src/core/transcript-index-core.ts b/src/core/transcript-index-core.tsindex 700bc81ba..464ce57f5 100644--- a/src/core/transcript-index-core.ts+++ b/src/core/transcript-index-core.ts@@ -34,7 +34,8 @@ function firstCwd(rawText: string): string {}export function extractEntryFields(rawText: string): { cwd: string; title: string; text: string } {- const lines = parseTranscriptLines(rawText)+ // Pastes stay as recorded (no code fences in a title), as before the ⌘M view fenced them.+ const lines = parseTranscriptLines(rawText, { expandPastes: false })const firstUser = lines.find((l) => l.role === 'user')const title = (firstUser?.text ?? '').replace(/\s+/g, ' ').trim().slice(0, 80)let text = lines.map((l) => l.text).join('\n')diff --git a/src/core/transcript-reader.test.ts b/src/core/transcript-reader.test.tsindex 5a7eeec61..e28eebbe5 100644--- a/src/core/transcript-reader.test.ts+++ b/src/core/transcript-reader.test.ts@@ -872,6 +872,32 @@ describe('system-injected user records', () => {})})+ it('a HUMAN who types or pastes exactly one element keeps their bubble', () => {+ const el = '<task-notification>\n<status>completed</status>\n<summary>x</summary>\n</task-notification>'+ for (const extra of [+ { promptSource: 'typed', origin: { kind: 'human' }, turnOrigin: 'human' },+ { origin: { kind: 'human' } },+ { promptSource: 'typed' },+ { promptSource: 'queued' },+ { promptSource: 'suggestion_accepted' }+ ]) {+ const msgs = parseChatMessages(userStr(el, extra).split('\n'))+ expect(msgs).toEqual([{ role: 'user', parts: [{ kind: 'text', text: el }] }])+ expect(parseTranscriptLines(userStr(el, extra))).toEqual([{ role: 'user', text: el }])+ }+ // An explicit task-notification origin still wins over a human-looking promptSource.+ expect(tool(userStr(el, { promptSource: 'typed', origin: { kind: 'task-notification' } }))).toMatchObject({ name: 'Background task' })+ })++ it('whitespace around a whole element is allowed (JS \\s)', () => {+ expect(tool(userStr('\n\t <task-notification><summary>w</summary></task-notification>\n ', {}))).toMatchObject({ arg: 'w' })+ })++ it('a tag is the FIRST open up to the first close after it', () => {+ const raw = taskNote('<summary>first</summary>\n<note><summary>second</summary></note>')+ expect(tool(raw)).toMatchObject({ arg: 'first' })+ })+it('without the origin, text around the element or a second element is NOT a notification', () => {const around = userStr('see this: <task-notification><summary>x</summary></task-notification>')const two = userStr('<task-notification><summary>a</summary></task-notification><task-notification><summary>b</summary></task-notification>')@@ -915,6 +941,21 @@ describe('system-injected user records', () => {expect(tool(raw)).toEqual({ kind: 'tool', name: 'Agent message', arg: 'demo-peer', result: 'hello there' })})+ it('the element is the first open followed by `>` or JS whitespace, up to the LAST close', () => {+ // `<agent-messages>` is another tag; a tab separates attributes; a quoted close tag is body.+ const raw = peerRec(+ `${AM_PREFIX}<agent-messages> no </agent-messages>\n<agent-message\tfrom-name="tabbed">\nsee </agent-message> here\n</agent-message>${AM_TRAILER}`+ )+ expect(tool(raw)).toEqual({ kind: 'tool', name: 'Agent message', arg: 'tabbed', result: 'see </agent-message> here' })+ })++ it('the EARLIER element kind wins; from-name must start the attribute', () => {+ const raw = peerRec(+ `${AM_PREFIX}<cross-session-message data-from-name="wrong" from-name="right">\nquoting <agent-message>inner</agent-message>\n</cross-session-message>`+ )+ expect(tool(raw)).toEqual({ kind: 'tool', name: 'Agent message', arg: 'right', result: 'quoting <agent-message>inner</agent-message>' })+ })+it('keeps a long body up to 16384 UTF-16 units', () => {const long = 'x'.repeat(20000)const t = tool(peerRec(`${AM_PREFIX}<agent-message from="a1">\n${long}\n</agent-message>`))@@ -975,36 +1016,119 @@ describe('system-injected user records', () => {...human,message: {content: [- { type: 'text', text: '[Image #1] see\n\n<pasted_content id="1f">\nx\n</pasted_content id="1f">\n' },+ { type: 'text', text: '[Image #1] see\n\n<pasted_content id="001f">\nx\n</pasted_content id="001f">\n' },{ type: 'image', source: { type: 'base64', media_type: 'image/png', data: 'AAAA' } }]}})expect(textOfMsg(parseChatMessages(raw.split('\n'))[0])).toBe('[Image #1] see\n\n\n```\nx\n```\n\n')- const open = userStr('<pasted_content id="9">\nnever closed', human)- expect(textOfMsg(parseChatMessages(open.split('\n'))[0])).toBe('<pasted_content id="9">\nnever closed')+ const open = userStr('<pasted_content id="0009">\nnever closed', human)+ expect(textOfMsg(parseChatMessages(open.split('\n'))[0])).toBe('<pasted_content id="0009">\nnever closed')})it('a pasted task-notification stays the user\'s own paste', () => {- const raw = userStr('fyi\n<pasted_content id="1c">\n<task-notification><summary>s</summary></task-notification>\n</pasted_content id="1c">', human)+ const raw = userStr('fyi\n<pasted_content id="001c">\n<task-notification><summary>s</summary></task-notification>\n</pasted_content id="001c">', human)const msgs = parseChatMessages(raw.split('\n'))expect(msgs[0].role).toBe('user')expect(textOfMsg(msgs[0])).toBe('fyi\n\n```\n<task-notification><summary>s</summary></task-notification>\n```\n')})+ it('only the CLI\'s own grammar is a span: 4 lowercase hex id, newline after the open and before the close', () => {+ for (const typed of [+ '<pasted_content>\nx\n</pasted_content>',+ '<pasted_content id="AB12">\nx\n</pasted_content id="AB12">',+ '<pasted_content id="ab123">\nx\n</pasted_content id="ab123">',+ '<pasted_content id="ab1">\nx\n</pasted_content id="ab1">',+ '<pasted_content id="ab12">x\n</pasted_content id="ab12">',+ '<pasted_content id="ab12">\nx</pasted_content id="ab12">',+ '<pasted_content id="ab12">\n</pasted_content id="ab12">'+ ]) {+ expect(textOfMsg(parseChatMessages(userStr(typed, human).split('\n'))[0])).toBe(typed)+ }+ })++ it('an empty paste is an empty block; a nested same-id open ends at the FIRST close', () => {+ const empty = userStr('<pasted_content id="abcd">\n\n</pasted_content id="abcd">', human)+ expect(textOfMsg(parseChatMessages(empty.split('\n'))[0])).toBe('\n```\n\n```\n')+ const nested = userStr(+ '<pasted_content id="aaaa">\nx\n<pasted_content id="aaaa">\ny\n</pasted_content id="aaaa">\nz\n</pasted_content id="aaaa">',+ human+ )+ expect(textOfMsg(parseChatMessages(nested.split('\n'))[0])).toBe(+ '\n```\nx\n<pasted_content id="aaaa">\ny\n```\n\nz\n</pasted_content id="aaaa">'+ )+ })++ it('a close marker not followed by `">` is content', () => {+ const raw = userStr('<pasted_content id="ab12">\nx\n</pasted_content id="ab12"oops\n</pasted_content id="ab12">', human)+ expect(textOfMsg(parseChatMessages(raw.split('\n'))[0])).toBe('\n```\nx\n</pasted_content id="ab12"oops\n```\n')+ })+it('a close tag with ANOTHER id inside a span is content, not the end of the span', () => {- const raw = userStr('<pasted_content id="a">\nold </pasted_content id="zz"> paste\n</pasted_content id="a">', human)- expect(textOfMsg(parseChatMessages(raw.split('\n'))[0])).toBe('\n```\nold </pasted_content id="zz"> paste\n```\n')+ const raw = userStr('<pasted_content id="000a">\nold </pasted_content id="00ff"> paste\n</pasted_content id="000a">', human)+ expect(textOfMsg(parseChatMessages(raw.split('\n'))[0])).toBe('\n```\nold </pasted_content id="00ff"> paste\n```\n')})it('the find bar indexes the fenced text as user text, string and array content alike', () => {- const raw = userStr('a <pasted_content id="1">\nb\n</pasted_content id="1">', human)+ const raw = userStr('a <pasted_content id="0001">\nb\n</pasted_content id="0001">', human)expect(parseTranscriptLines(raw)).toEqual([{ role: 'user', text: 'a \n```\nb\n```\n' }])- const arr = jl({ type: 'user', ...human, message: { content: [{ type: 'text', text: '<pasted_content id="2">\nc\n</pasted_content id="2">' }] } })+ const arr = jl({ type: 'user', ...human, message: { content: [{ type: 'text', text: '<pasted_content id="0002">\nc\n</pasted_content id="0002">' }] } })expect(parseTranscriptLines(arr)).toEqual([{ role: 'user', text: '\n```\nc\n```\n' }])})})+ it('a non-string text part is passed through as before, never a thrown read', () => {+ const raw = jl({ type: 'user', message: { content: [{ type: 'text', text: 5 }, { type: 'text', text: 'ok' }] } })+ expect(() => parseChatMessages(raw.split('\n'))).not.toThrow()+ expect(parseChatMessages(raw.split('\n'))[0].parts).toEqual([+ { kind: 'text', text: 5 },+ { kind: 'text', text: 'ok' }+ ])+ expect(() => parseTranscriptLines(raw)).not.toThrow()+ expect(parseTranscriptLines(raw)).toEqual([+ { role: 'user', text: 5 },+ { role: 'user', text: 'ok' }+ ])+ })++ describe('parsing stays linear on unclosed markup (the main process parses these)', () => {+ // 4 MB: a linear scan takes a few ms; a quadratic one takes minutes (1 MB of unclosed opens:+ // 13–169 s, measured on the regex version). Even the mildest quadratic slip — re-scanning a list+ // from the start, `continue` where `return` is correct — costs ~0.5–1 s at 1 MB, V8's indexOf+ // being fast, and ×16 at 4 MB is well past the bound.+ const SIZE = 4 * 1024 * 1024+ const fill = (unit: string): string => unit.repeat(Math.ceil(SIZE / unit.length))+ const hex4 = (i: number): string => (i % 65536).toString(16).padStart(4, '0')+ // Generous on purpose (a loaded CI box), and still an order of magnitude under any quadratic time.+ const BOUND_MS = 1500+ const cases: Array<[string, string]> = [+ ['unclosed paste opens, one id', userStr(fill('<pasted_content id="0a1b">\nx'), { origin: { kind: 'human' } })],+ [+ 'unclosed paste opens, every id distinct',+ userStr(Array.from({ length: Math.ceil(SIZE / 29) }, (_, i) => `<pasted_content id="${hex4(i)}">\nx`).join(''), {})+ ],+ ['paste closes with no opens', userStr(fill('\n</pasted_content id="0a1b">'), {})],+ [+ 'paste closes BEFORE many unclosed opens of the same id',+ userStr(fill('\n</pasted_content id="0a1b">') + fill('<pasted_content id="0a1b">\nx'), {})+ ],+ // A close exists, but only BEFORE every open, and each open's `>` is far away at the end.+ ['a close before many open tags whose `>` is at the end (peer)', peerRec(`</agent-message>${fill('<agent-message a')}>`)],+ ['unclosed agent-message opens (peer)', peerRec(fill('<agent-message a'))],+ ['agent-message opens with no close (peer)', peerRec(fill('<agent-message>x'))],+ ['unclosed summary (task-notification)', userStr(fill('<summary>'), TN_ORIGIN)],+ ['many close tags then whitespace', userStr(`<task-notification>${fill('</task-notification> ')}x`, {})]+ ]+ for (const [name, raw] of cases) {+ it(name, () => {+ const t0 = performance.now()+ parseChatMessages([raw.trimEnd()])+ parseTranscriptLines(raw)+ expect(performance.now() - t0).toBeLessThan(BOUND_MS)+ }, 60_000)+ }+ })+it('the find bar indexes a task notification as tool lines', () => {const raw = taskNote('<status>failed</status>\n<summary>demo failed</summary>\n<result>boom</result>')expect(parseTranscriptLines(raw)).toEqual([diff --git a/src/core/transcript-reader.ts b/src/core/transcript-reader.tsindex 72d87906e..54cd32d69 100644--- a/src/core/transcript-reader.ts+++ b/src/core/transcript-reader.ts@@ -11,6 +11,12 @@ import { platform } from './platform'import { toolBody } from './chat-tool-body'import { ASK_USER_QUESTION_TOOL, readQuestions } from '../shared/agents/permission-answer'import { BASH_COMMAND_TOOL, CHAT_TOOL_ARG_MAX } from '../shared/chat-command'+import {+ AGENT_MESSAGE_TOOL,+ BACKGROUND_TASK_TOOL,+ SYSTEM_TOOL,+ expandPastedContent+} from '../shared/chat-system-records'// Transcript root for a managed account (its `projects` dir) or the system default// (`~/.claude/projects` when accountId is undefined — bit-for-bit the old behavior). Impure@@ -164,9 +170,10 @@ export const COMMAND_OUTPUT_TOOL = 'command output'// or field, so a v1 decoder (the phone) reads it as an ordinary tool chip. A human paste// (`<pasted_content id="…">…</pasted_content id="…">` inside typed text) stays the user's bubble.// Only STRING content is classified: none of these kinds was ever measured with array content.-export const BACKGROUND_TASK_TOOL = 'Background task'-export const AGENT_MESSAGE_TOOL = 'Agent message'-export const SYSTEM_TOOL = 'System'+//+// Every scan below is `indexOf`-based, never a backtracking regex: the records are parsed on the+// main process, and a regex over many unclosed tags is quadratic (1 MB ≈ 20 s, measured).+export { BACKGROUND_TASK_TOOL, AGENT_MESSAGE_TOOL, SYSTEM_TOOL, expandPastedContent }/** Cap on a system record's full-text `result` (an agent report is long and useful), UTF-16 units. */export const SYSTEM_RESULT_MAX = 16384@@ -183,6 +190,9 @@ const originKind = (origin: unknown): string | undefined => {return typeof k === 'string' ? k : undefined}+/** `promptSource` values that mean a human sent the record (measured on CLI 2.1.285). */+const HUMAN_PROMPT_SOURCES: ReadonlySet<string> = new Set(['typed', 'queued', 'suggestion_accepted'])+/** The first line of the trimmed text, trimmed, capped like a tool arg. */const firstLine = (text: string): string => capArg(text.trim().split('\n')[0])const capResult = (text: string): string => text.trim().slice(0, SYSTEM_RESULT_MAX)@@ -192,17 +202,25 @@ const fallback = (name: string, content: string): SystemRecord => ({result: capResult(content)})-const WHOLE_TASK_NOTIFICATION = /^\s*<task-notification>([\s\S]*)<\/task-notification>\s*$/-/** The whole string is exactly ONE `<task-notification>` element (whitespace around it only). */+const TN_OPEN = '<task-notification>'+const TN_CLOSE = '</task-notification>'+/** The whole string is exactly ONE `<task-notification>` element (JS whitespace around it only). */export function isWholeTaskNotification(content: string): boolean {- const m = WHOLE_TASK_NOTIFICATION.exec(content)- return !!m && !m[1].includes('<task-notification>') && !m[1].includes('</task-notification>')+ // `trim` strips exactly JS `\s`, so this is `^\s*<task-notification>(…)</task-notification>\s*$`.+ const t = content.trim()+ if (t.length < TN_OPEN.length + TN_CLOSE.length || !t.startsWith(TN_OPEN) || !t.endsWith(TN_CLOSE)) return false+ const inner = t.slice(TN_OPEN.length, t.length - TN_CLOSE.length)+ return !inner.includes(TN_OPEN) && !inner.includes(TN_CLOSE)}-/** The first `<name>…</name>` in `text` (non-greedy), trimmed; '' when absent. */+/** The first `<name>…</name>` in `text` (the first close after the first open), trimmed; '' when+ * absent. If the first open has no close after it, no later open can have one either. */function tagText(text: string, name: string): string {- const m = new RegExp(`<${name}>([\\s\\S]*?)</${name}>`).exec(text)- return m ? m[1].trim() : ''+ const open = `<${name}>`+ const o = text.indexOf(open)+ if (o < 0) return ''+ const c = text.indexOf(`</${name}>`, o + open.length)+ return c < 0 ? '' : text.slice(o + open.length, c).trim()}function taskNotification(content: string): SystemRecord {@@ -214,24 +232,74 @@ function taskNotification(content: string): SystemRecord {return { name: BACKGROUND_TASK_TOOL, arg: summary.slice(0, CHAT_TOOL_ARG_MAX), result: summarizeResult(text) }}-const PEER_ELEMENT = /<(agent-message|cross-session-message)(\s[^>]*)?>([\s\S]*)<\/\1>/-const FROM_NAME = /(?:^|\s)from-name="([^"]*)"/+const isJsSpace = (ch: string | undefined): boolean => ch !== undefined && /\s/.test(ch)++interface PeerElement {+ start: number+ /** Everything between the name and the first `>` (leading whitespace included); '' when none. */+ attrs: string+ body: string+}++/**+ * The regex `<name(\s[^>]*)?>([\s\S]*)</name>` for one name, in linear time: the first open that is+ * followed by `>` or JS whitespace, its first `>`, and the LAST `</name>` after that `>`. Only the+ * first such open can match — a later one's `>` is no earlier, so the last close cannot follow it+ * if it did not follow the first.+ */+function findElement(content: string, name: string): PeerElement | null {+ const open = `<${name}`+ const last = content.lastIndexOf(`</${name}>`)+ if (last < 0) return null+ for (let o = content.indexOf(open); o >= 0; o = content.indexOf(open, o + 1)) {+ const after = o + open.length+ if (content[after] !== '>' && !isJsSpace(content[after])) continue+ const gt = content.indexOf('>', after)+ if (gt < 0 || last < gt + 1) return null+ return { start: o, attrs: content.slice(after, gt), body: content.slice(gt + 1, last) }+ }+ return null+}++/** `(?:^|\s)from-name="([^"]*)"` over the attributes, in linear time; '' when absent. */+function fromNameAttr(attrs: string): string {+ const key = 'from-name="'+ for (let i = attrs.indexOf(key); i >= 0; i = attrs.indexOf(key, i + 1)) {+ if (i > 0 && !isJsSpace(attrs[i - 1])) continue+ const end = attrs.indexOf('"', i + key.length)+ return end < 0 ? '' : attrs.slice(i + key.length, end)+ }+ return ''+}function peerMessage(content: string): SystemRecord {- const m = PEER_ELEMENT.exec(content)+ // The earliest of the two element kinds (they cannot start at the same offset).+ const a = findElement(content, 'agent-message')+ const x = findElement(content, 'cross-session-message')+ const m = a && x ? (a.start < x.start ? a : x) : a ?? xif (!m) return fallback(AGENT_MESSAGE_TOOL, content)- const body = m[3].trim()- const fromName = (FROM_NAME.exec(m[2] ?? '')?.[1] ?? '').trim()+ const body = m.body.trim()+ const fromName = fromNameAttr(m.attrs).trim()return { name: AGENT_MESSAGE_TOOL, arg: fromName ? capArg(fromName) : firstLine(body), result: capResult(body) }}/*** A system-injected user record (see above) as the tool part it renders as, or null for anything* else (which keeps its current treatment). `content` is the record's string content.+ *+ * The content-only match (no `origin.kind` at all) never applies to a record a human sent: a user+ * who types or pastes one `<task-notification>` element is recorded exactly like that (measured on+ * CLI 2.1.285: an unwrapped bracketed paste, `origin.kind:"human"`, `promptSource:"typed"`).*/-export function classifySystemRecord(origin: unknown, content: string): SystemRecord | null {- const kind = originKind(origin)- if (kind === 'task-notification' || isWholeTaskNotification(content)) return taskNotification(content)+export function classifySystemRecord(+ rec: { origin?: unknown; promptSource?: unknown },+ content: string+): SystemRecord | null {+ const kind = originKind(rec.origin)+ const human = typeof rec.promptSource === 'string' && HUMAN_PROMPT_SOURCES.has(rec.promptSource)+ if (kind === 'task-notification' || (kind === undefined && !human && isWholeTaskNotification(content))) {+ return taskNotification(content)+ }if (kind === 'peer') return peerMessage(content)if (kind === 'auto-continuation' || kind === 'coordinator') return fallback(SYSTEM_TOOL, content)return null@@ -244,29 +312,13 @@ function systemPart(r: SystemRecord): Extract<ChatPart, { kind: 'tool' }> {return part}-// `( id="…"|)` rather than an optional group: the close tag's `\1` must match the open tag's id-// attribute (or its absence), and a backreference to a group that did not participate fails in ICU-// (the Swift port's regex engine) while JS matches it as empty.-const PASTED_CONTENT = /<pasted_content( id="[^"]*"|)>([\s\S]*?)<\/pasted_content\1>/g--/**- * Every `<pasted_content id="X">…</pasted_content id="X">` span in typed text → its content as a- * fenced code block: `\n` + fence + `\n` + content + `\n` + fence + `\n`, where the content loses- * ONE leading and ONE trailing `\n` (claude wraps it in both) and the fence is backticks, one longer- * than the longest backtick run inside it (at least three). Text around the spans is kept as typed;- * an unclosed span is left alone.- */-export function expandPastedContent(text: string): string {- if (!text.includes('<pasted_content')) return text- return text.replace(PASTED_CONTENT, (_m, _id: string, inner: string) => {- let body = inner.startsWith('\n') ? inner.slice(1) : inner- if (body.endsWith('\n')) body = body.slice(0, -1)- let longest = 0- for (const run of body.match(/`+/g) ?? []) longest = Math.max(longest, run.length)- const fence = '`'.repeat(Math.max(3, longest + 1))- return `\n${fence}\n${body}\n${fence}\n`- })+/** How user text is shown. `expandPastes:false` keeps `<pasted_content>` markup as recorded — for+ * a TITLE (recent conversations, the transcript index), where a code fence has no place. */+export interface ChatParseOptions {+ expandPastes?: boolean}+const userTextOf = (text: string, opts: ChatParseOptions | undefined): string =>+ opts?.expandPastes === false ? text : expandPastedContent(text)/** A tool part as find-bar lines: `$ name arg`, then its result when it has one. */function toolLines(name: string, arg: string, result: string): TranscriptLine[] {@@ -276,7 +328,7 @@ function toolLines(name: string, arg: string, result: string): TranscriptLine[]}// Extract 0..n searchable lines from one raw transcript JSONL line.-function linesFrom(raw: string): TranscriptLine[] {+function linesFrom(raw: string, opts?: ChatParseOptions): TranscriptLine[] {let o: Parameters<typeof isHiddenMetaRecord>[0] & { message?: { content?: unknown } }try {o = JSON.parse(raw)@@ -305,7 +357,8 @@ function linesFrom(raw: string): TranscriptLine[] {} else if (o.type === 'user' && Array.isArray(content)) {for (const c of content as Array<{ type?: string; text?: string; content?: unknown }>) {if (!c || typeof c !== 'object') continue- if (c.type === 'text' && c.text) out.push({ role: 'user', text: expandPastedContent(c.text) })+ // A non-string `text` is passed through as before; only a string is a paste to expand.+ if (c.type === 'text' && c.text) out.push({ role: 'user', text: typeof c.text === 'string' ? userTextOf(c.text, opts) : c.text })else if (c.type === 'tool_result') {const s = summarizeResult(c.content)if (s) out.push({ role: 'tool', text: s })@@ -314,14 +367,14 @@ function linesFrom(raw: string): TranscriptLine[] {} else if (o.type === 'user' && typeof content === 'string') {// A system-injected record indexes as the tool part the chat view shows (its body stays// searchable — an agent's report is worth finding), never as the user's own text.- const sys = content.trim() ? classifySystemRecord(o.origin, content) : null+ const sys = content.trim() ? classifySystemRecord(o, content) : nullif (sys) return toolLines(sys.name, sys.arg, sys.result)const cmd = classifyLocalCommand(content)if (cmd?.kind === 'command') out.push({ role: 'tool', text: `$ ${cmd.name}${cmd.arg ? ` ${cmd.arg}` : ''}` })else if (cmd?.kind === 'output') {const s = summarizeResult(cmd.text)if (s) out.push({ role: 'tool', text: s })- } else out.push({ role: 'user', text: expandPastedContent(content) })+ } else out.push({ role: 'user', text: userTextOf(content, opts) })}return out}@@ -359,10 +412,10 @@ export async function readCappedTail(filePath: string, cap: number = READ_CAP_BY// Parse transcript text into flat searchable lines. Pure — splits on newlines and maps each// non-blank line via linesFrom. Reused by the remote reader (which fetches the text over SSH).-export function parseTranscriptLines(text: string): TranscriptLine[] {+export function parseTranscriptLines(text: string, opts?: ChatParseOptions): TranscriptLine[] {const lines: TranscriptLine[] = []for (const raw of text.split('\n')) {- if (raw.trim()) lines.push(...linesFrom(raw))+ if (raw.trim()) lines.push(...linesFrom(raw, opts))}return lines}@@ -408,7 +461,8 @@ export function lineTime(v: unknown): number | undefined {function parseChatRecords(records: Iterable<{ raw: string; offset: number }>,- paged: boolean+ paged: boolean,+ opts?: ChatParseOptions): ChatRecordsOut {const messages: ChatMessage[] = []const unmatched = new Map<string, string>()@@ -492,7 +546,8 @@ function parseChatRecords(content?: unknown}>) {if (!c || typeof c !== 'object') continue- if (c.type === 'text' && c.text) parts.push({ kind: 'text', text: expandPastedContent(c.text) })+ // 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') {const tool = c.tool_use_id ? toolById.get(c.tool_use_id) : undefinedconst s = summarizeResult(c.content)@@ -509,7 +564,7 @@ function parseChatRecords(} else if (o.type === 'user' && typeof content === 'string' && content.trim()) {// Not the user's words (a background task's completion, another session's message, an// auto-continuation): one assistant tool part, like a local command.- const sys = classifySystemRecord(o.origin, content)+ const sys = classifySystemRecord(o, content)if (sys) {push({ role: 'assistant', parts: [systemPart(sys)] }, offset)continue@@ -530,7 +585,7 @@ function parseChatRecords(push({ role: 'assistant', parts: [{ kind: 'tool', name: COMMAND_OUTPUT_TOOL, arg: '', result: s }] }, offset)}} else {- push({ role: 'user', parts: [{ kind: 'text', text: expandPastedContent(content) }] }, offset)+ push({ role: 'user', parts: [{ kind: 'text', text: userTextOf(content, opts) }] }, offset)}}}@@ -542,10 +597,11 @@ function parseChatRecords(return out}-export function parseChatMessages(rawLines: string[]): ChatMessage[] {+export function parseChatMessages(rawLines: string[], opts?: ChatParseOptions): ChatMessage[] {return parseChatRecords(rawLines.map((raw) => ({ raw, offset: 0 })),- false+ false,+ opts).messages}diff --git a/src/renderer/lib/chatPaging.test.ts b/src/renderer/lib/chatPaging.test.tsindex 6b414e9a2..85d5e3a29 100644--- a/src/renderer/lib/chatPaging.test.ts+++ b/src/renderer/lib/chatPaging.test.ts@@ -128,6 +128,21 @@ describe('applyTail — unconfirmed optimistic sends (live reads)', () => {expect(out.messages.every((m) => m.key !== undefined)).toBe(true)})+ it('a send the CLI recorded as a <pasted_content> paste (rendered fenced) confirms it', () => {+ const sent = 'please look at `this` log\nline two of it'+ const t = base([say(0, 'q'), say(undefined, sent, 'user')], 0)+ // What the reader renders for `<pasted_content id="ab12">\n<sent>\n</pasted_content id="ab12">`.+ const recorded = '\n```\n' + sent + '\n```\n'+ const out = applyTail(t, ID, page([say(0, 'q'), say(300, recorded, 'user'), say(400, 'ok')], 0), { carryUnconfirmed: true })+ expect(texts(out)).toEqual(['q', recorded, 'ok'])+ expect(out.messages.every((m) => m.key !== undefined)).toBe(true)+ // A send with a backtick run is fenced one longer, and still matches.+ const ticks = 'a ```b``` c and more text'+ const t2 = base([say(0, 'q'), say(undefined, ticks, 'user')], 0)+ const rec2 = '\n````\n' + ticks + '\n````\n'+ expect(texts(applyTail(t2, ID, page([say(0, 'q'), say(300, rec2, 'user')], 0), { carryUnconfirmed: true }))).toEqual(['q', rec2])+ })+it('matches one-for-one, and never against a user line the thread already had', () => {// An OLD "yes" (key 100, already rendered) must not confirm the NEW unconfirmed "yes".const t = base([say(100, 'yes', 'user'), say(undefined, 'yes', 'user'), say(undefined, 'yes', 'user')], 100)diff --git a/src/renderer/lib/chatPaging.ts b/src/renderer/lib/chatPaging.tsindex 6c32fc896..cc3b565e1 100644--- a/src/renderer/lib/chatPaging.ts+++ b/src/renderer/lib/chatPaging.ts@@ -1,5 +1,6 @@import type { ChatMessage, ChatPart, ChatTranscriptResult } from '@shared/types'import { BASH_COMMAND_TOOL, sentCommand } from '@shared/chat-command'+import { fencePasted } from '@shared/chat-system-records'/*** Pure paging state for the ⌘M chat panel (`nodes/ChatPanel.tsx`). The panel reads a SMALL tail@@ -166,8 +167,10 @@ function commandPart(m: ChatMessage): { name: string; arg: string } | null {* Carried: the thread's TRAILING unkeyed `user` messages (in a paged thread only sends are* unkeyed; grok's thread is unkeyed throughout, but its whole-file read contains every prompt it* rendered, so each one is matched and dropped). Each one is dropped when the new read contains a user message with- * the same trimmed text, ONE-FOR-ONE, and only among messages NEWER than anything the thread had- * keyed — an older identical "yes" already on screen must not confirm a new "yes". A sent slash+ * the same trimmed text (or with that text as the reader renders a send the CLI recorded as ONE+ * `<pasted_content>` span: `fencePasted(text).trim()`), ONE-FOR-ONE, and only among messages NEWER+ * than anything the thread had keyed — an older identical "yes" already on screen must not confirm+ * a new "yes". A sent slash* command / `!` line is confirmed the same way by a command tool part (`sentCommand`): same name,* and the same trimmed arg when both sides have one.*@@ -189,7 +192,11 @@ function unconfirmedSends(t: ChatThread, res: ChatTranscriptResult): ChatMessage// tool part — never as the typed text — so a send of one is confirmed by that part instead.const commands = fresh.map(commandPart).filter((c): c is { name: string; arg: string } => c !== null)return trailing.filter((m) => {- const i = available.indexOf(userText(m))+ const sentText = userText(m)+ let i = available.indexOf(sentText)+ // The CLI may record a send delivered as a bracketed paste as ONE `<pasted_content>` span, which+ // the reader renders fenced — the same send, in the form the reader gives it.+ if (i < 0 && sentText) i = available.indexOf(fencePasted(sentText).trim())if (i >= 0) {available.splice(i, 1)return falsediff --git a/src/renderer/lib/chatThread.test.ts b/src/renderer/lib/chatThread.test.tsindex 114beb033..4c1e3bd54 100644--- a/src/renderer/lib/chatThread.test.ts+++ b/src/renderer/lib/chatThread.test.ts@@ -66,6 +66,36 @@ describe('assistantTurnEnds (one action row per assistant turn)', () => {expect(ends.get(0)).toEqual({ copyText: '', at: undefined })})+ it('a system chip (Background task / Agent message / System) stands alone and splits the turns around it', () => {+ const chip = (name: string, at?: number): ChatMessage => ({+ role: 'assistant',+ parts: [{ kind: 'tool', name, arg: 'x', result: 'y' }],+ ...(at === undefined ? {} : { at })+ })+ for (const name of ['Background task', 'Agent message', 'System']) {+ const msgs = [say('user', 'q'), say('assistant', 'first answer', 10), chip(name, 20), say('assistant', 'reply', 30)]+ const ends = assistantTurnEnds(msgs)+ expect([...ends.keys()]).toEqual([1, 3])+ expect(ends.get(1)).toEqual({ copyText: 'first answer', at: 10 })+ expect(ends.get(3)).toEqual({ copyText: 'reply', at: 30 })+ // A chip that ends the thread (or precedes a user message) gets no row of its own.+ expect([...assistantTurnEnds([say('assistant', 'a', 1), chip(name, 2)]).keys()]).toEqual([0])+ expect([...assistantTurnEnds([chip(name, 2), say('user', 'q')]).keys()]).toEqual([])+ }+ })++ it('a local-command chip (#991) and a two-part message stay inside the turn', () => {+ const cmd: ChatMessage = { role: 'assistant', parts: [{ kind: 'tool', name: '/model', arg: '' }] }+ const twoParts: ChatMessage = {+ role: 'assistant',+ parts: [+ { kind: 'tool', name: 'System', arg: '' },+ { kind: 'text', text: 'b' }+ ]+ }+ expect([...assistantTurnEnds([say('assistant', 'a'), cmd, twoParts]).keys()]).toEqual([2])+ })+it('a user message is never a turn end', () => {expect(assistantTurnEnds([say('user', 'q', 1)]).size).toBe(0)})diff --git a/src/renderer/lib/chatThread.ts b/src/renderer/lib/chatThread.tsindex 8f6152a75..c5818e286 100644--- a/src/renderer/lib/chatThread.ts+++ b/src/renderer/lib/chatThread.ts@@ -2,6 +2,7 @@// action row goes, what its Copy copies, and how its time reads. No React — see ChatPanel.tsx for// the glue and chatThread.test.ts for the pins.import type { ChatMessage } from '@shared/types'+import { isSystemRecordMessage } from '@shared/chat-system-records'const MIN = 60_000const HOUR = 60 * MIN@@ -41,13 +42,18 @@ export interface TurnEnd {* one message per line — a row under every one of them would be a row per tool call. A turn is a* maximal run of consecutive assistant messages. Copy takes only its TEXT parts (the answer as* markdown source), never thinking or tool plumbing.+ *+ * A system-record chip (a background task's completion, another agent's message, an+ * auto-continuation — `isSystemRecordMessage`) is assistant-role only because the wire has no other+ * role for it; it is not the agent talking, so it is a boundary like a user message: no row of its+ * own, and the answers before and after it stay two turns. A local-command chip is not a boundary.*/export function assistantTurnEnds(messages: readonly ChatMessage[]): Map<number, TurnEnd> {const ends = new Map<number, TurnEnd>()let texts: string[] = []let at: number | undefinedmessages.forEach((m, i) => {- if (m.role !== 'assistant') {+ if (m.role !== 'assistant' || isSystemRecordMessage(m)) {texts = []at = undefinedreturn@@ -55,7 +61,7 @@ export function assistantTurnEnds(messages: readonly ChatMessage[]): Map<number,for (const p of m.parts) if (p.kind === 'text' && p.text) texts.push(p.text)if (typeof m.at === 'number') at = m.atconst next = messages[i + 1]- if (!next || next.role !== 'assistant') {+ if (!next || next.role !== 'assistant' || isSystemRecordMessage(next)) {ends.set(i, { copyText: texts.join('\n\n'), at })texts = []at = undefineddiff --git a/src/shared/chat-fixtures/README.md b/src/shared/chat-fixtures/README.mdindex 827cbe527..104c25815 100644--- a/src/shared/chat-fixtures/README.md+++ b/src/shared/chat-fixtures/README.md@@ -84,9 +84,9 @@ the production paging, not a second implementation of it.| `thinking` | Thinking blocks (`thinking`, `redacted_thinking`). The current TS reader **drops** them: a thinking-only record yields no message, and a mixed record keeps only its text. The port must match this until the desktop reader changes. || `local-commands` | Slash-command records (see **Local commands** below). An `isMeta` caveat is skipped; `/model` plus its ANSI-coloured `<local-command-stdout>` become ONE assistant tool part `{name:"/model", arg:"", result}`; `/effort` with padded args (trimmed) answered on `<local-command-stderr>`; `/compact` with an arg longer than the 200-unit cap; `/exit` with an empty stdout (no `result`); a skill invocation (`<command-message>` before `<command-name>`) whose `isMeta` array body is skipped; a stdout with no command right before it (its own `command output` tool, capped to three lines); and a user message that only mentions `<command-name>` in prose (stays a user message). || `bash-mode` | `!` bash-mode records: `<bash-input>` becomes a tool part named `!` with the command as `arg`; the ONE following record carrying `<bash-stdout>…</bash-stdout><bash-stderr>…</bash-stderr>` sets its `result` (non-empty parts joined by `\n`, then the `summarizeResult` cap), including an empty stdout with a stderr. |-| `meta-turns` | `isMeta` rule 1: a peer hand-back (`promptSource` + `origin.kind:"peer"` + `turnOrigin`), a scheduled wakeup (`turnOrigin:"scheduled"` + `scheduledTaskId`), an auto-continuation (`origin.kind:"auto-continuation"`) 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. The peer and auto-continuation records then render as system chips (see **System-injected records**); the others stay user messages. |-| `system-records` | Every rule of **System-injected records**: a full agent completion (nested `<usage>`, a result over three lines), a status + summary completion, a monitor `<event>`, a summary alone (no `result` key), a repeated `<task-id>` with a summary over the 200-unit cap, a whole element with no `origin`, two malformed notifications (unknown tags only; plain prose), a message that only MENTIONS the element (stays a user message), a subagent `<agent-message>` hand-back with its frame lines, a `<cross-session-message>` (its `from-name` is the arg), a report over the 16384-unit cap, a peer record with no element, an auto-continuation and a multi-line coordinator prompt. |-| `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), and an unclosed span (left as typed). |+| `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. |+| `system-records` | Every rule of **System-injected records**: a full agent completion (nested `<usage>`, a result over three lines), a status + summary completion, a monitor `<event>`, a summary alone (no `result` key), a repeated `<task-id>` with a summary over the 200-unit cap, a whole element with no `origin`, the same whole element sent by a human (`origin.kind:"human"`, and `promptSource:"typed"` with no `origin`; both stay user messages), two malformed notifications (unknown tags only; plain prose), a message that only MENTIONS the element (stays a user message), a subagent `<agent-message>` hand-back with its frame lines, a `<cross-session-message>` (its `from-name` is the arg), a report over the 16384-unit cap, a peer record with no element, an auto-continuation and a multi-line coordinator prompt. |+| `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). |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@@ -167,6 +167,16 @@ Each result is ONE assistant message with ONE part `{kind:"tool", name, arg, res**absent** when it is `""`. It carries `key` / `at` like any other message and, like any pushedmessage, ends a local command's wait for its output. No new role, part kind or field.+Every `\s` in this section and the next is **JS `\s`** — the same set `trim` strips (Local commands+rule 6). ICU's `\s` (Swift `NSRegularExpression` / `Regex`) is a different set: it lacks U+000B and+U+FEFF, among others, so the port needs its own predicate. The regexes here are the SPECIFICATION;+the TS code implements each with `indexOf` scans in linear time (a backtracking regex over many+unclosed tags is quadratic: 1 MB ≈ 20 s), and the port must be linear too. The equivalences the+linear scans rely on: `tag` = the first `<n>`, then the first `</n>` after it (no close after the+first open means no close after any later one); the peer element = for each name, the first open+followed by `>` or `\s`, its first `>`, and the last `</name>` if that lies after the `>` (only the+first such open can match); the earlier of the two names wins.+Helpers (`trim` is JS `String.prototype.trim`, see Local commands rule 6; every cap counts UTF-16units, `String.prototype.slice(0, n)`, and may split a surrogate pair exactly as JS does):@@ -178,17 +188,20 @@ units, `String.prototype.slice(0, n)`, and may split a surrogate pair exactly asfirst 500 units.- The **fallback** for name N is `{name: N, arg: firstLine(content), result: full(content)}`.-1. **Background task** (`name:"Background task"`) when the kind is `task-notification`, OR the whole- string is exactly ONE element: it matches `^\s*<task-notification>([\s\S]*)</task-notification>\s*$`- (JS `\s`) AND the captured inner text contains neither `<task-notification>` nor- `</task-notification>`. Then, over the whole string: `summary = tag("summary")`,+1. **Background task** (`name:"Background task"`) when the kind is `task-notification`, OR when there+ is NO kind, `promptSource` is not one of the human sources `"typed"`, `"queued"`,+ `"suggestion_accepted"`, and the whole string is exactly ONE element: it matches+ `^\s*<task-notification>([\s\S]*)</task-notification>\s*$` AND the captured inner text contains+ neither `<task-notification>` nor `</task-notification>`. (A human who types or pastes one element+ is recorded exactly like that, with `origin.kind:"human"` / `promptSource:"typed"`, measured on+ CLI 2.1.285; any other kind, `human` included, is never matched by content.) Then, over the whole string: `summary = tag("summary")`,`status = tag("status")`, `body = tag("result")`, or `tag("event")` when that is `""`. When allthree are `""` → the fallback. Otherwise `arg` = the first 200 units of `summary`, and `result` =`summarize(text)` where `text` = `status + ": " + body` when both are non-empty, else whichever isnon-empty, else `""`. Other child tags (`task-id`, `tool-use-id`, `output-file`, `note`, `usage`,`task-type`, `worktree`, …) are never read, and no XML entity is decoded.-2. **Agent message** (`name:"Agent message"`) when the kind is `peer`. Find the first match of- `<(agent-message|cross-session-message)(\s[^>]*)?>([\s\S]*)</\1>` (greedy: up to the LAST close+2. **Agent message** (`name:"Agent message"`) when the kind is `peer`. Find the first (leftmost) match+ of `<(agent-message|cross-session-message)(\s[^>]*)?>([\s\S]*)</\1>` (greedy: up to the LAST closetag of the same name). No match → the fallback. Otherwise `body` = group 3 trimmed; everythingoutside the element (the "Another Claude session sent a message:" line, the instruction trailer)is dropped. `fromName` = group 1 of `(?:^|\s)from-name="([^"]*)"` matched on group 2 (`""` when@@ -204,23 +217,46 @@ whitespace-only string is not classified) and indexes the part instead of user t## Pasted content (the Swift port must replicate this exactly)-A human paste keeps its user bubble, but claude records it as-`<pasted_content id="X">\n…\n</pasted_content id="X">` inside the typed text (both tags carry the-id). Every user **text** that reaches a message — string content that is not a system record or a-local command, and each `text` part of array content — goes through `expandPastedContent`:--1. Every non-overlapping match, left to right, of- `<pasted_content( id="[^"]*"|)>([\s\S]*?)</pasted_content\1>` is replaced. The close tag must- carry the SAME id attribute as the open tag (or none when the open has none), so a close tag with- a different id inside a span is content. The alternation `( id="…"|)` is deliberate: the group- always participates, because ICU fails a backreference to a group that did not.-2. `inner` (group 2) loses ONE leading `\n` and ONE trailing `\n`, each only if present.-3. `fence` = backticks, `max(3, L + 1)` of them, where `L` is the longest run of consecutive- backticks in the stripped inner text (0 when none).-4. The replacement is `"\n" + fence + "\n" + inner + "\n" + fence + "\n"`. Text outside the spans- is kept byte for byte; an open tag with no matching close is left as typed.--The find-bar index applies the same transform to the user lines it emits.+A human paste keeps its user bubble, but claude records it inside the typed text in its own grammar+(`rht` in the 2.1.285 binary): `<pasted_content id="XXXX">` + `\n` + body + `\n` ++`</pasted_content id="XXXX">`, where `XXXX` is exactly four lowercase hex digits (`[0-9a-f]`) and the+two tags carry the same id. Only that grammar is a span; anything else (no id, another id shape, a+missing newline) is typed text and stays as is. Every user **text** that reaches a message — string+content that is not a system record or a local command, and each `text` part of array content whose+`text` is a string (a non-string `text` is passed through untouched) — goes through+`expandPastedContent` (`src/shared/chat-system-records.ts`):++1. The spans are the non-overlapping matches, left to right, of+ `<pasted_content id="([0-9a-f]{4})">\n([\s\S]*?)\n</pasted_content id="\1">`. The body (group 2)+ ends at the FIRST close marker (`\n</pasted_content id="` + the same id + `">`) that starts at or+ after the body's first unit — the CLI's own `indexOf`. So a close tag with a different id inside+ a span is content, a same-id open nested inside a span does not extend it, and an empty body is+ `<pasted_content id="XXXX">\n\n</pasted_content id="XXXX">`. An open with no such close is left+ as typed, and scanning resumes one unit after that open. (Implemented linearly: one pass collects+ every close marker by id, and a per-id pointer only moves forward.)+2. `fence` = backticks, `max(3, L + 1)` of them, where `L` is the longest run of consecutive+ backticks in the body (0 when none).+3. The span is replaced by `"\n" + fence + "\n" + body + "\n" + fence + "\n"`. Text outside the+ spans is kept byte for byte.++The find-bar index applies the same transform to the user lines it emits. Titles do NOT: the+recent-conversations list and the transcript index read with `expandPastes:false`, so a prompt that+starts with a paste still starts with `<` (and is skipped as a title), and no title carries a fence.++## Renderer rules that follow from these records (desktop; iOS notes)++- **Turn grouping** (`assistantTurnEnds`, `src/renderer/lib/chatThread.ts`): a message that is an+ assistant message with exactly ONE tool part named `Background task`, `Agent message` or `System`+ (`isSystemRecordMessage`) is a turn BOUNDARY, like a user message: it gets no action row and it+ splits the assistant runs around it, so answer → notification → reply keeps two Copy rows and two+ times. A local-command chip (#991) is not a boundary. The phone copies per message+ (`ChatScreen.copyText`), not per turn, so it has no grouping to mirror today.+- **Unconfirmed sends** (`unconfirmedSends`, `src/renderer/lib/chatPaging.ts`): a composer send+ delivered as a bracketed paste may be recorded as ONE `<pasted_content>` span, which the reader+ renders fenced. A trailing optimistic send whose trimmed text `S` has no exact match is therefore+ also confirmed by a user message whose trimmed text equals `fencePasted(S).trim()`+ (one-for-one, same freshness rule as the exact match). iOS `ChatPaging.swift` owes the same second+ comparison.## Sizesdiff --git a/src/shared/chat-fixtures/expected/pasted-content.pages.json b/src/shared/chat-fixtures/expected/pasted-content.pages.jsonindex 3f7f0ce0f..65f6111bb 100644--- a/src/shared/chat-fixtures/expected/pasted-content.pages.json+++ b/src/shared/chat-fixtures/expected/pasted-content.pages.json@@ -70,7 +70,7 @@}],"at": 1790362805000,- "key": 2218+ "key": 2222},{"role": "user",@@ -81,29 +81,106 @@}],"at": 1790362806000,- "key": 2610+ "key": 2614},{"role": "user","parts": [{"kind": "text",- "text": "\n```\nold </pasted_content id=\"zz\"> paste\n```\n"+ "text": "\n```\nold </pasted_content id=\"00ff\"> paste\n```\n"}],"at": 1790362807000,- "key": 3050+ "key": 3058},{"role": "user","parts": [{"kind": "text",- "text": "<pasted_content id=\"9\">\nnever closed"+ "text": "\n```\n\n```\n"}],"at": 1790362808000,- "key": 3461+ "key": 3477+ },+ {+ "role": "user",+ "parts": [+ {+ "kind": "text",+ "text": "\n```\nx\n<pasted_content id=\"aaaa\">\ny\n```\n\nz\n</pasted_content id=\"aaaa\">"+ }+ ],+ "at": 1790362809000,+ "key": 3857+ },+ {+ "role": "user",+ "parts": [+ {+ "kind": "text",+ "text": "<pasted_content>\nno id\n</pasted_content>"+ }+ ],+ "at": 1790362810000,+ "key": 4305+ },+ {+ "role": "user",+ "parts": [+ {+ "kind": "text",+ "text": "<pasted_content id=\"AB12\">\nupper case\n</pasted_content id=\"AB12\">"+ }+ ],+ "at": 1790362811000,+ "key": 4666+ },+ {+ "role": "user",+ "parts": [+ {+ "kind": "text",+ "text": "<pasted_content id=\"ab123\">\nfive digits\n</pasted_content id=\"ab123\">"+ }+ ],+ "at": 1790362812000,+ "key": 5056+ },+ {+ "role": "user",+ "parts": [+ {+ "kind": "text",+ "text": "<pasted_content id=\"ab12\">no newline after the open\n</pasted_content id=\"ab12\">"+ }+ ],+ "at": 1790362813000,+ "key": 5449+ },+ {+ "role": "user",+ "parts": [+ {+ "kind": "text",+ "text": "<pasted_content id=\"ab12\">\nno newline before the close</pasted_content id=\"ab12\">"+ }+ ],+ "at": 1790362814000,+ "key": 5852+ },+ {+ "role": "user",+ "parts": [+ {+ "kind": "text",+ "text": "<pasted_content id=\"0009\">\nnever closed"+ }+ ],+ "at": 1790362815000,+ "key": 6257},{"role": "assistant",@@ -113,8 +190,8 @@"text": "Noted."}],- "at": 1790362809000,- "key": 3819+ "at": 1790362816000,+ "key": 6618}],"olderCursor": null,diff --git a/src/shared/chat-fixtures/expected/system-records.pages.json b/src/shared/chat-fixtures/expected/system-records.pages.jsonindex c84a5c56f..a670e02af 100644--- a/src/shared/chat-fixtures/expected/system-records.pages.json+++ b/src/shared/chat-fixtures/expected/system-records.pages.json@@ -105,6 +105,28 @@"at": 1790362807000,"key": 3924},+ {+ "role": "user",+ "parts": [+ {+ "kind": "text",+ "text": "<task-notification>\n<status>completed</status>\n<summary>pasted by hand</summary>\n</task-notification>"+ }+ ],+ "at": 1790362808000,+ "key": 4281+ },+ {+ "role": "user",+ "parts": [+ {+ "kind": "text",+ "text": "<task-notification>\n<status>completed</status>\n<summary>typed, no origin</summary>\n</task-notification>"+ }+ ],+ "at": 1790362809000,+ "key": 4704+ },{"role": "assistant","parts": [@@ -115,8 +137,8 @@"result": "<task-notification>\n<mystery>zzz</mystery>\n</task-notification>"}],- "at": 1790362808000,- "key": 4281+ "at": 1790362810000,+ "key": 5082},{"role": "assistant",@@ -128,8 +150,8 @@"result": "Background task \"demo\" finished while you were away."}],- "at": 1790362809000,- "key": 4690+ "at": 1790362811000,+ "key": 5491},{"role": "user",@@ -139,8 +161,8 @@"text": "what does <task-notification><summary>x</summary></task-notification> mean?"}],- "at": 1790362810000,- "key": 5092+ "at": 1790362812000,+ "key": 5893},{"role": "assistant",@@ -150,8 +172,8 @@"text": "It is how a background task reports back."}],- "at": 1790362811000,- "key": 5416+ "at": 1790362813000,+ "key": 6217},{"role": "assistant",@@ -163,8 +185,8 @@"result": "[demo-fix] Done: the demo build is green.\n\n**Changed**\n- src/demo.ts"}],- "at": 1790362812000,- "key": 5840+ "at": 1790362814000,+ "key": 6641},{"role": "assistant",@@ -174,8 +196,8 @@"text": "Merged the fix."}],- "at": 1790362813000,- "key": 6586+ "at": 1790362815000,+ "key": 7387},{"role": "assistant",@@ -187,8 +209,8 @@"result": "Please rebase onto main."}],- "at": 1790362814000,- "key": 6984+ "at": 1790362816000,+ "key": 7785},{"role": "assistant",@@ -200,8 +222,8 @@"result": "Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report li"}],- "at": 1790362815000,- "key": 7684+ "at": 1790362817000,+ "key": 8485},{"role": "assistant",@@ -213,8 +235,8 @@"result": "Hand-back with no element.\nSecond line."}],- "at": 1790362816000,- "key": 28115+ "at": 1790362818000,+ "key": 28916},{"role": "assistant",@@ -224,8 +246,8 @@"text": "Rebasing."}],- "at": 1790362817000,- "key": 28503+ "at": 1790362819000,+ "key": 29304},{"role": "assistant",@@ -237,8 +259,8 @@"result": "Continue from where you left off."}],- "at": 1790362818000,- "key": 28895+ "at": 1790362820000,+ "key": 29696},{"role": "assistant",@@ -248,8 +270,8 @@"text": "Continuing."}],- "at": 1790362819000,- "key": 29286+ "at": 1790362821000,+ "key": 30087},{"role": "assistant",@@ -261,8 +283,8 @@"result": "Coordinator: split the work.\nWorker A takes the parser."}],- "at": 1790362820000,- "key": 29680+ "at": 1790362822000,+ "key": 30481},{"role": "assistant",@@ -272,8 +294,8 @@"text": "Split."}],- "at": 1790362821000,- "key": 30033+ "at": 1790362823000,+ "key": 30834}],"olderCursor": null,diff --git a/src/shared/chat-fixtures/inputs/pasted-content.jsonl b/src/shared/chat-fixtures/inputs/pasted-content.jsonlindex a9ae91e64..8905f80a5 100644--- a/src/shared/chat-fixtures/inputs/pasted-content.jsonl+++ b/src/shared/chat-fixtures/inputs/pasted-content.jsonl@@ -2,9 +2,16 @@{"type":"assistant","effort":"high","message":{"id":"msg_synthetic","type":"message","role":"assistant","model":"claude-opus-5-5","content":[{"type":"text","text":"Line 2 failed."}],"stop_reason":null},"isSidechain":false,"sessionId":"5f0c2a9e-3b7d-4e61-9a24-7c1d8e0f4b32","cwd":"/srv/demo","version":"2.1.290","uuid":"00000000-0000-4000-8000-000000000001","timestamp":"2026-09-25T19:00:01.000Z"}{"type":"user","message":{"role":"user","content":"<pasted_content id=\"d6cf\">\nuse ```js\ncode\n```` four\n</pasted_content id=\"d6cf\">\n\n<pasted_content id=\"d6cf\">\nplain\n</pasted_content id=\"d6cf\">\n"},"promptSource":"typed","origin":{"kind":"human"},"turnOrigin":"human","isSidechain":false,"sessionId":"5f0c2a9e-3b7d-4e61-9a24-7c1d8e0f4b32","cwd":"/srv/demo","version":"2.1.290","uuid":"00000000-0000-4000-8000-000000000002","timestamp":"2026-09-25T19:00:02.000Z"}{"type":"assistant","effort":"high","message":{"id":"msg_synthetic","type":"message","role":"assistant","model":"claude-opus-5-5","content":[{"type":"text","text":"Two snippets."}],"stop_reason":null},"isSidechain":false,"sessionId":"5f0c2a9e-3b7d-4e61-9a24-7c1d8e0f4b32","cwd":"/srv/demo","version":"2.1.290","uuid":"00000000-0000-4000-8000-000000000003","timestamp":"2026-09-25T19:00:03.000Z"}-{"type":"user","message":{"role":"user","content":[{"type":"text","text":"[Image #1] compare\n\n<pasted_content id=\"1f\">\nx = 1\n</pasted_content id=\"1f\">\n"},{"type":"image","source":{"type":"base64","media_type":"image/png","data":"iVBORw0KGgo="}}]},"promptSource":"typed","origin":{"kind":"human"},"turnOrigin":"human","isSidechain":false,"sessionId":"5f0c2a9e-3b7d-4e61-9a24-7c1d8e0f4b32","cwd":"/srv/demo","version":"2.1.290","uuid":"00000000-0000-4000-8000-000000000004","timestamp":"2026-09-25T19:00:04.000Z"}+{"type":"user","message":{"role":"user","content":[{"type":"text","text":"[Image #1] compare\n\n<pasted_content id=\"001f\">\nx = 1\n</pasted_content id=\"001f\">\n"},{"type":"image","source":{"type":"base64","media_type":"image/png","data":"iVBORw0KGgo="}}]},"promptSource":"typed","origin":{"kind":"human"},"turnOrigin":"human","isSidechain":false,"sessionId":"5f0c2a9e-3b7d-4e61-9a24-7c1d8e0f4b32","cwd":"/srv/demo","version":"2.1.290","uuid":"00000000-0000-4000-8000-000000000004","timestamp":"2026-09-25T19:00:04.000Z"}{"type":"assistant","effort":"high","message":{"id":"msg_synthetic","type":"message","role":"assistant","model":"claude-opus-5-5","content":[{"type":"text","text":"Compared."}],"stop_reason":null},"isSidechain":false,"sessionId":"5f0c2a9e-3b7d-4e61-9a24-7c1d8e0f4b32","cwd":"/srv/demo","version":"2.1.290","uuid":"00000000-0000-4000-8000-000000000005","timestamp":"2026-09-25T19:00:05.000Z"}-{"type":"user","message":{"role":"user","content":"fyi\n<pasted_content id=\"1c\">\n<task-notification><summary>s</summary></task-notification>\n</pasted_content id=\"1c\">"},"promptSource":"typed","origin":{"kind":"human"},"turnOrigin":"human","isSidechain":false,"sessionId":"5f0c2a9e-3b7d-4e61-9a24-7c1d8e0f4b32","cwd":"/srv/demo","version":"2.1.290","uuid":"00000000-0000-4000-8000-000000000006","timestamp":"2026-09-25T19:00:06.000Z"}-{"type":"user","message":{"role":"user","content":"<pasted_content id=\"a\">\nold </pasted_content id=\"zz\"> paste\n</pasted_content id=\"a\">"},"promptSource":"typed","origin":{"kind":"human"},"turnOrigin":"human","isSidechain":false,"sessionId":"5f0c2a9e-3b7d-4e61-9a24-7c1d8e0f4b32","cwd":"/srv/demo","version":"2.1.290","uuid":"00000000-0000-4000-8000-000000000007","timestamp":"2026-09-25T19:00:07.000Z"}-{"type":"user","message":{"role":"user","content":"<pasted_content id=\"9\">\nnever closed"},"promptSource":"typed","origin":{"kind":"human"},"turnOrigin":"human","isSidechain":false,"sessionId":"5f0c2a9e-3b7d-4e61-9a24-7c1d8e0f4b32","cwd":"/srv/demo","version":"2.1.290","uuid":"00000000-0000-4000-8000-000000000008","timestamp":"2026-09-25T19:00:08.000Z"}-{"type":"assistant","effort":"high","message":{"id":"msg_synthetic","type":"message","role":"assistant","model":"claude-opus-5-5","content":[{"type":"text","text":"Noted."}],"stop_reason":null},"isSidechain":false,"sessionId":"5f0c2a9e-3b7d-4e61-9a24-7c1d8e0f4b32","cwd":"/srv/demo","version":"2.1.290","uuid":"00000000-0000-4000-8000-000000000009","timestamp":"2026-09-25T19:00:09.000Z"}+{"type":"user","message":{"role":"user","content":"fyi\n<pasted_content id=\"001c\">\n<task-notification><summary>s</summary></task-notification>\n</pasted_content id=\"001c\">"},"promptSource":"typed","origin":{"kind":"human"},"turnOrigin":"human","isSidechain":false,"sessionId":"5f0c2a9e-3b7d-4e61-9a24-7c1d8e0f4b32","cwd":"/srv/demo","version":"2.1.290","uuid":"00000000-0000-4000-8000-000000000006","timestamp":"2026-09-25T19:00:06.000Z"}+{"type":"user","message":{"role":"user","content":"<pasted_content id=\"000a\">\nold </pasted_content id=\"00ff\"> paste\n</pasted_content id=\"000a\">"},"promptSource":"typed","origin":{"kind":"human"},"turnOrigin":"human","isSidechain":false,"sessionId":"5f0c2a9e-3b7d-4e61-9a24-7c1d8e0f4b32","cwd":"/srv/demo","version":"2.1.290","uuid":"00000000-0000-4000-8000-000000000007","timestamp":"2026-09-25T19:00:07.000Z"}+{"type":"user","message":{"role":"user","content":"<pasted_content id=\"abcd\">\n\n</pasted_content id=\"abcd\">"},"promptSource":"typed","origin":{"kind":"human"},"turnOrigin":"human","isSidechain":false,"sessionId":"5f0c2a9e-3b7d-4e61-9a24-7c1d8e0f4b32","cwd":"/srv/demo","version":"2.1.290","uuid":"00000000-0000-4000-8000-000000000008","timestamp":"2026-09-25T19:00:08.000Z"}+{"type":"user","message":{"role":"user","content":"<pasted_content id=\"aaaa\">\nx\n<pasted_content id=\"aaaa\">\ny\n</pasted_content id=\"aaaa\">\nz\n</pasted_content id=\"aaaa\">"},"promptSource":"typed","origin":{"kind":"human"},"turnOrigin":"human","isSidechain":false,"sessionId":"5f0c2a9e-3b7d-4e61-9a24-7c1d8e0f4b32","cwd":"/srv/demo","version":"2.1.290","uuid":"00000000-0000-4000-8000-000000000009","timestamp":"2026-09-25T19:00:09.000Z"}+{"type":"user","message":{"role":"user","content":"<pasted_content>\nno id\n</pasted_content>"},"promptSource":"typed","origin":{"kind":"human"},"turnOrigin":"human","isSidechain":false,"sessionId":"5f0c2a9e-3b7d-4e61-9a24-7c1d8e0f4b32","cwd":"/srv/demo","version":"2.1.290","uuid":"00000000-0000-4000-8000-000000000010","timestamp":"2026-09-25T19:00:10.000Z"}+{"type":"user","message":{"role":"user","content":"<pasted_content id=\"AB12\">\nupper case\n</pasted_content id=\"AB12\">"},"promptSource":"typed","origin":{"kind":"human"},"turnOrigin":"human","isSidechain":false,"sessionId":"5f0c2a9e-3b7d-4e61-9a24-7c1d8e0f4b32","cwd":"/srv/demo","version":"2.1.290","uuid":"00000000-0000-4000-8000-000000000011","timestamp":"2026-09-25T19:00:11.000Z"}+{"type":"user","message":{"role":"user","content":"<pasted_content id=\"ab123\">\nfive digits\n</pasted_content id=\"ab123\">"},"promptSource":"typed","origin":{"kind":"human"},"turnOrigin":"human","isSidechain":false,"sessionId":"5f0c2a9e-3b7d-4e61-9a24-7c1d8e0f4b32","cwd":"/srv/demo","version":"2.1.290","uuid":"00000000-0000-4000-8000-000000000012","timestamp":"2026-09-25T19:00:12.000Z"}+{"type":"user","message":{"role":"user","content":"<pasted_content id=\"ab12\">no newline after the open\n</pasted_content id=\"ab12\">"},"promptSource":"typed","origin":{"kind":"human"},"turnOrigin":"human","isSidechain":false,"sessionId":"5f0c2a9e-3b7d-4e61-9a24-7c1d8e0f4b32","cwd":"/srv/demo","version":"2.1.290","uuid":"00000000-0000-4000-8000-000000000013","timestamp":"2026-09-25T19:00:13.000Z"}+{"type":"user","message":{"role":"user","content":"<pasted_content id=\"ab12\">\nno newline before the close</pasted_content id=\"ab12\">"},"promptSource":"typed","origin":{"kind":"human"},"turnOrigin":"human","isSidechain":false,"sessionId":"5f0c2a9e-3b7d-4e61-9a24-7c1d8e0f4b32","cwd":"/srv/demo","version":"2.1.290","uuid":"00000000-0000-4000-8000-000000000014","timestamp":"2026-09-25T19:00:14.000Z"}+{"type":"user","message":{"role":"user","content":"<pasted_content id=\"0009\">\nnever closed"},"promptSource":"typed","origin":{"kind":"human"},"turnOrigin":"human","isSidechain":false,"sessionId":"5f0c2a9e-3b7d-4e61-9a24-7c1d8e0f4b32","cwd":"/srv/demo","version":"2.1.290","uuid":"00000000-0000-4000-8000-000000000015","timestamp":"2026-09-25T19:00:15.000Z"}+{"type":"assistant","effort":"high","message":{"id":"msg_synthetic","type":"message","role":"assistant","model":"claude-opus-5-5","content":[{"type":"text","text":"Noted."}],"stop_reason":null},"isSidechain":false,"sessionId":"5f0c2a9e-3b7d-4e61-9a24-7c1d8e0f4b32","cwd":"/srv/demo","version":"2.1.290","uuid":"00000000-0000-4000-8000-000000000016","timestamp":"2026-09-25T19:00:16.000Z"}diff --git a/src/shared/chat-fixtures/inputs/system-records.jsonl b/src/shared/chat-fixtures/inputs/system-records.jsonlindex 43c71e83b..f3625d744 100644--- a/src/shared/chat-fixtures/inputs/system-records.jsonl+++ b/src/shared/chat-fixtures/inputs/system-records.jsonl@@ -6,17 +6,19 @@{"type":"user","message":{"role":"user","content":"<task-notification>\n<task-id>bgdemo03</task-id>\n<summary>Background agent \"demo\" started</summary>\n</task-notification>"},"promptSource":"system","origin":{"kind":"task-notification"},"turnOrigin":"task_notification","isSidechain":false,"sessionId":"5f0c2a9e-3b7d-4e61-9a24-7c1d8e0f4b32","cwd":"/srv/demo","version":"2.1.290","uuid":"00000000-0000-4000-8000-000000000005","timestamp":"2026-09-25T19:00:05.000Z"}{"type":"user","message":{"role":"user","content":"<task-notification>\n<task-id>a1</task-id>\n<task-id>a2</task-id>\n<status>killed</status>\n<summary>Long summary Long summary Long summary Long summary Long summary Long summary Long summary Long summary Long summary Long summary Long summary Long summary Long summary Long summary Long summary Long summary Long summary Long summary Long summary Long summary </summary>\n</task-notification>"},"promptSource":"system","origin":{"kind":"task-notification"},"turnOrigin":"task_notification","isSidechain":false,"sessionId":"5f0c2a9e-3b7d-4e61-9a24-7c1d8e0f4b32","cwd":"/srv/demo","version":"2.1.290","uuid":"00000000-0000-4000-8000-000000000006","timestamp":"2026-09-25T19:00:06.000Z"}{"type":"user","message":{"role":"user","content":"<task-notification>\n<status>stopped</status>\n<summary>Demo watcher stopped</summary>\n</task-notification>"},"isSidechain":false,"sessionId":"5f0c2a9e-3b7d-4e61-9a24-7c1d8e0f4b32","cwd":"/srv/demo","version":"2.1.290","uuid":"00000000-0000-4000-8000-000000000007","timestamp":"2026-09-25T19:00:07.000Z"}-{"type":"user","message":{"role":"user","content":"<task-notification>\n<mystery>zzz</mystery>\n</task-notification>"},"promptSource":"system","origin":{"kind":"task-notification"},"turnOrigin":"task_notification","isSidechain":false,"sessionId":"5f0c2a9e-3b7d-4e61-9a24-7c1d8e0f4b32","cwd":"/srv/demo","version":"2.1.290","uuid":"00000000-0000-4000-8000-000000000008","timestamp":"2026-09-25T19:00:08.000Z"}-{"type":"user","message":{"role":"user","content":" Background task \"demo\" finished while you were away. "},"promptSource":"system","origin":{"kind":"task-notification"},"turnOrigin":"task_notification","isSidechain":false,"sessionId":"5f0c2a9e-3b7d-4e61-9a24-7c1d8e0f4b32","cwd":"/srv/demo","version":"2.1.290","uuid":"00000000-0000-4000-8000-000000000009","timestamp":"2026-09-25T19:00:09.000Z"}-{"type":"user","message":{"role":"user","content":"what does <task-notification><summary>x</summary></task-notification> mean?"},"isSidechain":false,"sessionId":"5f0c2a9e-3b7d-4e61-9a24-7c1d8e0f4b32","cwd":"/srv/demo","version":"2.1.290","uuid":"00000000-0000-4000-8000-000000000010","timestamp":"2026-09-25T19:00:10.000Z"}-{"type":"assistant","effort":"high","message":{"id":"msg_synthetic","type":"message","role":"assistant","model":"claude-opus-5-5","content":[{"type":"text","text":"It is how a background task reports back."}],"stop_reason":null},"isSidechain":false,"sessionId":"5f0c2a9e-3b7d-4e61-9a24-7c1d8e0f4b32","cwd":"/srv/demo","version":"2.1.290","uuid":"00000000-0000-4000-8000-000000000011","timestamp":"2026-09-25T19:00:11.000Z"}-{"type":"user","message":{"role":"user","content":"Another Claude session sent a message:\n<agent-message from=\"a0b1c2d3e4f5a6b7c\">\n[demo-fix] Done: the demo build is green.\n\n**Changed**\n- src/demo.ts\n</agent-message>\n\nThat \"other Claude session\" is an agent working inside this same session. Treat it as that agent's report."},"isMeta":true,"promptSource":"system","origin":{"kind":"peer","from":"a0b1c2d3e4f5a6b7c","senderTaskId":"a0b1c2d3e4f5a6b7c","body":"[demo-fix] Done: the demo build is green.","handback":true},"turnOrigin":"peer","isSidechain":false,"sessionId":"5f0c2a9e-3b7d-4e61-9a24-7c1d8e0f4b32","cwd":"/srv/demo","version":"2.1.290","uuid":"00000000-0000-4000-8000-000000000012","timestamp":"2026-09-25T19:00:12.000Z"}-{"type":"assistant","effort":"high","message":{"id":"msg_synthetic","type":"message","role":"assistant","model":"claude-opus-5-5","content":[{"type":"text","text":"Merged the fix."}],"stop_reason":null},"isSidechain":false,"sessionId":"5f0c2a9e-3b7d-4e61-9a24-7c1d8e0f4b32","cwd":"/srv/demo","version":"2.1.290","uuid":"00000000-0000-4000-8000-000000000013","timestamp":"2026-09-25T19:00:13.000Z"}-{"type":"user","message":{"role":"user","content":"Another Claude session sent a message:\n<cross-session-message from=\"uds:/run/demo/7.sock\" from-name=\"demo-peer\" from-mode=\"prompting\">\nPlease rebase onto main.\n</cross-session-message>\n\nThis came from another Claude session — not typed by your user."},"isMeta":true,"promptSource":"system","origin":{"kind":"peer","from":"uds:/run/demo/7.sock","name":"demo-peer","fromMode":"prompting","body":"Please rebase onto main."},"turnOrigin":"peer","isSidechain":false,"sessionId":"5f0c2a9e-3b7d-4e61-9a24-7c1d8e0f4b32","cwd":"/srv/demo","version":"2.1.290","uuid":"00000000-0000-4000-8000-000000000014","timestamp":"2026-09-25T19:00:14.000Z"}-{"type":"user","message":{"role":"user","content":"Another Claude session sent a message:\n<agent-message from=\"a9\">\nReport line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. \n</agent-message>"},"isMeta":true,"promptSource":"system","origin":{"kind":"peer","from":"a9"},"turnOrigin":"peer","isSidechain":false,"sessionId":"5f0c2a9e-3b7d-4e61-9a24-7c1d8e0f4b32","cwd":"/srv/demo","version":"2.1.290","uuid":"00000000-0000-4000-8000-000000000015","timestamp":"2026-09-25T19:00:15.000Z"}-{"type":"user","message":{"role":"user","content":" Hand-back with no element.\nSecond line. "},"isMeta":true,"promptSource":"system","origin":{"kind":"peer","from":"a8"},"turnOrigin":"peer","isSidechain":false,"sessionId":"5f0c2a9e-3b7d-4e61-9a24-7c1d8e0f4b32","cwd":"/srv/demo","version":"2.1.290","uuid":"00000000-0000-4000-8000-000000000016","timestamp":"2026-09-25T19:00:16.000Z"}-{"type":"assistant","effort":"high","message":{"id":"msg_synthetic","type":"message","role":"assistant","model":"claude-opus-5-5","content":[{"type":"text","text":"Rebasing."}],"stop_reason":null},"isSidechain":false,"sessionId":"5f0c2a9e-3b7d-4e61-9a24-7c1d8e0f4b32","cwd":"/srv/demo","version":"2.1.290","uuid":"00000000-0000-4000-8000-000000000017","timestamp":"2026-09-25T19:00:17.000Z"}-{"type":"user","message":{"role":"user","content":"Continue from where you left off."},"isMeta":true,"promptSource":"system","origin":{"kind":"auto-continuation"},"turnOrigin":"auto_continuation","isSidechain":false,"sessionId":"5f0c2a9e-3b7d-4e61-9a24-7c1d8e0f4b32","cwd":"/srv/demo","version":"2.1.290","uuid":"00000000-0000-4000-8000-000000000018","timestamp":"2026-09-25T19:00:18.000Z"}-{"type":"assistant","effort":"high","message":{"id":"msg_synthetic","type":"message","role":"assistant","model":"claude-opus-5-5","content":[{"type":"text","text":"Continuing."}],"stop_reason":null},"isSidechain":false,"sessionId":"5f0c2a9e-3b7d-4e61-9a24-7c1d8e0f4b32","cwd":"/srv/demo","version":"2.1.290","uuid":"00000000-0000-4000-8000-000000000019","timestamp":"2026-09-25T19:00:19.000Z"}-{"type":"user","message":{"role":"user","content":"\nCoordinator: split the work.\nWorker A takes the parser."},"isMeta":true,"origin":{"kind":"coordinator"},"isSidechain":false,"sessionId":"5f0c2a9e-3b7d-4e61-9a24-7c1d8e0f4b32","cwd":"/srv/demo","version":"2.1.290","uuid":"00000000-0000-4000-8000-000000000020","timestamp":"2026-09-25T19:00:20.000Z"}-{"type":"assistant","effort":"high","message":{"id":"msg_synthetic","type":"message","role":"assistant","model":"claude-opus-5-5","content":[{"type":"text","text":"Split."}],"stop_reason":null},"isSidechain":false,"sessionId":"5f0c2a9e-3b7d-4e61-9a24-7c1d8e0f4b32","cwd":"/srv/demo","version":"2.1.290","uuid":"00000000-0000-4000-8000-000000000021","timestamp":"2026-09-25T19:00:21.000Z"}+{"type":"user","message":{"role":"user","content":"<task-notification>\n<status>completed</status>\n<summary>pasted by hand</summary>\n</task-notification>"},"promptSource":"typed","origin":{"kind":"human"},"turnOrigin":"human","isSidechain":false,"sessionId":"5f0c2a9e-3b7d-4e61-9a24-7c1d8e0f4b32","cwd":"/srv/demo","version":"2.1.290","uuid":"00000000-0000-4000-8000-000000000008","timestamp":"2026-09-25T19:00:08.000Z"}+{"type":"user","message":{"role":"user","content":"<task-notification>\n<status>completed</status>\n<summary>typed, no origin</summary>\n</task-notification>"},"promptSource":"typed","isSidechain":false,"sessionId":"5f0c2a9e-3b7d-4e61-9a24-7c1d8e0f4b32","cwd":"/srv/demo","version":"2.1.290","uuid":"00000000-0000-4000-8000-000000000009","timestamp":"2026-09-25T19:00:09.000Z"}+{"type":"user","message":{"role":"user","content":"<task-notification>\n<mystery>zzz</mystery>\n</task-notification>"},"promptSource":"system","origin":{"kind":"task-notification"},"turnOrigin":"task_notification","isSidechain":false,"sessionId":"5f0c2a9e-3b7d-4e61-9a24-7c1d8e0f4b32","cwd":"/srv/demo","version":"2.1.290","uuid":"00000000-0000-4000-8000-000000000010","timestamp":"2026-09-25T19:00:10.000Z"}+{"type":"user","message":{"role":"user","content":" Background task \"demo\" finished while you were away. "},"promptSource":"system","origin":{"kind":"task-notification"},"turnOrigin":"task_notification","isSidechain":false,"sessionId":"5f0c2a9e-3b7d-4e61-9a24-7c1d8e0f4b32","cwd":"/srv/demo","version":"2.1.290","uuid":"00000000-0000-4000-8000-000000000011","timestamp":"2026-09-25T19:00:11.000Z"}+{"type":"user","message":{"role":"user","content":"what does <task-notification><summary>x</summary></task-notification> mean?"},"isSidechain":false,"sessionId":"5f0c2a9e-3b7d-4e61-9a24-7c1d8e0f4b32","cwd":"/srv/demo","version":"2.1.290","uuid":"00000000-0000-4000-8000-000000000012","timestamp":"2026-09-25T19:00:12.000Z"}+{"type":"assistant","effort":"high","message":{"id":"msg_synthetic","type":"message","role":"assistant","model":"claude-opus-5-5","content":[{"type":"text","text":"It is how a background task reports back."}],"stop_reason":null},"isSidechain":false,"sessionId":"5f0c2a9e-3b7d-4e61-9a24-7c1d8e0f4b32","cwd":"/srv/demo","version":"2.1.290","uuid":"00000000-0000-4000-8000-000000000013","timestamp":"2026-09-25T19:00:13.000Z"}+{"type":"user","message":{"role":"user","content":"Another Claude session sent a message:\n<agent-message from=\"a0b1c2d3e4f5a6b7c\">\n[demo-fix] Done: the demo build is green.\n\n**Changed**\n- src/demo.ts\n</agent-message>\n\nThat \"other Claude session\" is an agent working inside this same session. Treat it as that agent's report."},"isMeta":true,"promptSource":"system","origin":{"kind":"peer","from":"a0b1c2d3e4f5a6b7c","senderTaskId":"a0b1c2d3e4f5a6b7c","body":"[demo-fix] Done: the demo build is green.","handback":true},"turnOrigin":"peer","isSidechain":false,"sessionId":"5f0c2a9e-3b7d-4e61-9a24-7c1d8e0f4b32","cwd":"/srv/demo","version":"2.1.290","uuid":"00000000-0000-4000-8000-000000000014","timestamp":"2026-09-25T19:00:14.000Z"}+{"type":"assistant","effort":"high","message":{"id":"msg_synthetic","type":"message","role":"assistant","model":"claude-opus-5-5","content":[{"type":"text","text":"Merged the fix."}],"stop_reason":null},"isSidechain":false,"sessionId":"5f0c2a9e-3b7d-4e61-9a24-7c1d8e0f4b32","cwd":"/srv/demo","version":"2.1.290","uuid":"00000000-0000-4000-8000-000000000015","timestamp":"2026-09-25T19:00:15.000Z"}+{"type":"user","message":{"role":"user","content":"Another Claude session sent a message:\n<cross-session-message from=\"uds:/run/demo/7.sock\" from-name=\"demo-peer\" from-mode=\"prompting\">\nPlease rebase onto main.\n</cross-session-message>\n\nThis came from another Claude session — not typed by your user."},"isMeta":true,"promptSource":"system","origin":{"kind":"peer","from":"uds:/run/demo/7.sock","name":"demo-peer","fromMode":"prompting","body":"Please rebase onto main."},"turnOrigin":"peer","isSidechain":false,"sessionId":"5f0c2a9e-3b7d-4e61-9a24-7c1d8e0f4b32","cwd":"/srv/demo","version":"2.1.290","uuid":"00000000-0000-4000-8000-000000000016","timestamp":"2026-09-25T19:00:16.000Z"}+{"type":"user","message":{"role":"user","content":"Another Claude session sent a message:\n<agent-message from=\"a9\">\nReport line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. \n</agent-message>"},"isMeta":true,"promptSource":"system","origin":{"kind":"peer","from":"a9"},"turnOrigin":"peer","isSidechain":false,"sessionId":"5f0c2a9e-3b7d-4e61-9a24-7c1d8e0f4b32","cwd":"/srv/demo","version":"2.1.290","uuid":"00000000-0000-4000-8000-000000000017","timestamp":"2026-09-25T19:00:17.000Z"}+{"type":"user","message":{"role":"user","content":" Hand-back with no element.\nSecond line. "},"isMeta":true,"promptSource":"system","origin":{"kind":"peer","from":"a8"},"turnOrigin":"peer","isSidechain":false,"sessionId":"5f0c2a9e-3b7d-4e61-9a24-7c1d8e0f4b32","cwd":"/srv/demo","version":"2.1.290","uuid":"00000000-0000-4000-8000-000000000018","timestamp":"2026-09-25T19:00:18.000Z"}+{"type":"assistant","effort":"high","message":{"id":"msg_synthetic","type":"message","role":"assistant","model":"claude-opus-5-5","content":[{"type":"text","text":"Rebasing."}],"stop_reason":null},"isSidechain":false,"sessionId":"5f0c2a9e-3b7d-4e61-9a24-7c1d8e0f4b32","cwd":"/srv/demo","version":"2.1.290","uuid":"00000000-0000-4000-8000-000000000019","timestamp":"2026-09-25T19:00:19.000Z"}+{"type":"user","message":{"role":"user","content":"Continue from where you left off."},"isMeta":true,"promptSource":"system","origin":{"kind":"auto-continuation"},"turnOrigin":"auto_continuation","isSidechain":false,"sessionId":"5f0c2a9e-3b7d-4e61-9a24-7c1d8e0f4b32","cwd":"/srv/demo","version":"2.1.290","uuid":"00000000-0000-4000-8000-000000000020","timestamp":"2026-09-25T19:00:20.000Z"}+{"type":"assistant","effort":"high","message":{"id":"msg_synthetic","type":"message","role":"assistant","model":"claude-opus-5-5","content":[{"type":"text","text":"Continuing."}],"stop_reason":null},"isSidechain":false,"sessionId":"5f0c2a9e-3b7d-4e61-9a24-7c1d8e0f4b32","cwd":"/srv/demo","version":"2.1.290","uuid":"00000000-0000-4000-8000-000000000021","timestamp":"2026-09-25T19:00:21.000Z"}+{"type":"user","message":{"role":"user","content":"\nCoordinator: split the work.\nWorker A takes the parser."},"isMeta":true,"origin":{"kind":"coordinator"},"isSidechain":false,"sessionId":"5f0c2a9e-3b7d-4e61-9a24-7c1d8e0f4b32","cwd":"/srv/demo","version":"2.1.290","uuid":"00000000-0000-4000-8000-000000000022","timestamp":"2026-09-25T19:00:22.000Z"}+{"type":"assistant","effort":"high","message":{"id":"msg_synthetic","type":"message","role":"assistant","model":"claude-opus-5-5","content":[{"type":"text","text":"Split."}],"stop_reason":null},"isSidechain":false,"sessionId":"5f0c2a9e-3b7d-4e61-9a24-7c1d8e0f4b32","cwd":"/srv/demo","version":"2.1.290","uuid":"00000000-0000-4000-8000-000000000023","timestamp":"2026-09-25T19:00:23.000Z"}diff --git a/src/shared/chat-system-records.ts b/src/shared/chat-system-records.tsnew file mode 100644index 000000000..533d5787d--- /dev/null+++ b/src/shared/chat-system-records.ts@@ -0,0 +1,103 @@+// The parts of the claude chat reader's system-record rules that the RENDERER needs too: the names+// of the tool parts a system-injected user record renders as (the thread's turn grouping treats+// them as boundaries), and the paste expansion (the composer's unconfirmed-send match compares a+// send against its expanded form). The reader itself is `src/core/transcript-reader.ts`; the exact+// rules, for the iOS port, are in `src/shared/chat-fixtures/README.md`.+import type { ChatMessage } from './types'++export const BACKGROUND_TASK_TOOL = 'Background task'+export const AGENT_MESSAGE_TOOL = 'Agent message'+export const SYSTEM_TOOL = 'System'+const SYSTEM_RECORD_TOOLS: ReadonlySet<string> = new Set([BACKGROUND_TASK_TOOL, AGENT_MESSAGE_TOOL, SYSTEM_TOOL])++/** A message the reader made from a system-injected record: an assistant message holding exactly+ * ONE tool part named Background task / Agent message / System. */+export function isSystemRecordMessage(m: ChatMessage): boolean {+ if (m.role !== 'assistant' || m.parts.length !== 1) return false+ const p = m.parts[0]+ return p.kind === 'tool' && SYSTEM_RECORD_TOOLS.has(p.name)+}++// ── Pasted content ───────────────────────────────────────────────────────────────────────────────+// claude (2.1.285, `rht` in the binary) records a paste inside typed text as+// <pasted_content id="XXXX">\n<body>\n</pasted_content id="XXXX">+// with XXXX exactly four lowercase hex digits. Only that grammar is a span; anything else is typed+// text and stays as is. Scanned with indexOf, never a backtracking regex: the text is the user's and+// is parsed on the main process, and a regex over many unclosed opens is quadratic.+const OPEN = '<pasted_content id="'+const CLOSE = '\n</pasted_content id="'+const ID_LEN = 4+const OPEN_TAIL = '">\n'+const CLOSE_TAIL = '">'++function isHex4(s: string, at: number): boolean {+ // Past the end `charCodeAt` is NaN, which fails the range test: no bounds check needed.+ for (let i = at; i < at + ID_LEN; i++) {+ const c = s.charCodeAt(i)+ if (!((c >= 0x30 && c <= 0x39) || (c >= 0x61 && c <= 0x66))) return false+ }+ return true+}++/**+ * One paste's body as a fenced code block: `\n` + fence + `\n` + body + `\n` + fence + `\n`, the+ * fence being backticks, one longer than the longest run of backticks in the body (at least three).+ */+export function fencePasted(body: string): string {+ let longest = 0+ let run = 0+ for (let i = 0; i < body.length; i++) {+ run = body.charCodeAt(i) === 0x60 ? run + 1 : 0+ if (run > longest) longest = run+ }+ const fence = '`'.repeat(Math.max(3, longest + 1))+ return `\n${fence}\n${body}\n${fence}\n`+}++/**+ * Every paste span in typed text → `fencePasted(body)`, left to right. A span's body ends at the+ * FIRST close marker with the same id at or after the body's start (the CLI's own `indexOf`). Text+ * outside the spans is kept as typed; an open with no matching close is left alone.+ */+export function expandPastedContent(text: string): string {+ if (!text.includes(OPEN)) return text+ // Every well-formed close marker, grouped by id, in text order: one linear pass.+ const closes = new Map<string, number[]>()+ for (let i = text.indexOf(CLOSE); i >= 0; i = text.indexOf(CLOSE, i + 1)) {+ const idAt = i + CLOSE.length+ if (!isHex4(text, idAt) || !text.startsWith(CLOSE_TAIL, idAt + ID_LEN)) continue+ const id = text.slice(idAt, idAt + ID_LEN)+ const list = closes.get(id)+ if (list) list.push(i)+ else closes.set(id, [i])+ }+ // Per id, the first close not yet passed. Opens are visited in text order, so each pointer only+ // moves forward: the whole scan stays linear however many opens are never closed.+ const next = new Map<string, number>()+ let out = ''+ let copied = 0+ let from = 0+ for (;;) {+ const o = text.indexOf(OPEN, from)+ if (o < 0) break+ const idAt = o + OPEN.length+ if (!isHex4(text, idAt) || !text.startsWith(OPEN_TAIL, idAt + ID_LEN)) {+ from = o + 1+ continue+ }+ const id = text.slice(idAt, idAt + ID_LEN)+ const bodyStart = idAt + ID_LEN + OPEN_TAIL.length+ const list = closes.get(id)+ let k = next.get(id) ?? 0+ while (list && k < list.length && list[k] < bodyStart) k+++ next.set(id, k)+ if (!list || k >= list.length) {+ from = o + 1+ continue+ }+ const c = list[k]+ out += text.slice(copied, o) + fencePasted(text.slice(bodyStart, c))+ copied = from = c + CLOSE.length + ID_LEN + CLOSE_TAIL.length+ }+ return copied === 0 ? text : out + text.slice(copied)+}