Skip to content

Node-based terminal manager for AI coding agents — tmux-backed terminals and parallel agent sessions as draggable nodes on an infinite pan/zoom canvas. macOS, Linux, and a browser Server Edition.

fix(chat): render system-injected user records as tool chips, not user bubbles

review3d7dbe064180
diff --git a/CLAUDE.md b/CLAUDE.md
index 4226636e7..0b97dc460 100644
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@ -3249,6 +3249,11 @@ command-bearing opens; this does not add a human-confirm dialog or change mobile
its `contextTail`, the hook-fed path authority). The browser's real reader is
`buildTranscriptApi` in ws-bridge — deliberately NOT folded into `buildClaudeApi`, which the
relay shares and must not adopt it.
+ **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`.
**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` (clamped
diff --git a/src/core/chat-fixtures.test.ts b/src/core/chat-fixtures.test.ts
index c0edd14e4..00ab17a57 100644
--- a/src/core/chat-fixtures.test.ts
+++ b/src/core/chat-fixtures.test.ts
@@ -404,6 +404,109 @@ function metaTurns(): string {
])
}
+// System-injected user records (measured shapes, synthetic content): a background task's completion,
+// another session's message, an auto-continuation / coordinator prompt — each ONE assistant tool
+// part. See the README's "System-injected records".
+const TN = { promptSource: 'system', origin: { kind: 'task-notification' }, turnOrigin: 'task_notification' }
+const tn = (inner: string[], extra: Rec = TN): Rec => ({ ...user(`<task-notification>\n${inner.join('\n')}\n</task-notification>`), ...extra })
+const PEER_PREFIX = 'Another Claude session sent a message:\n'
+const peer = (text: string, origin: Rec): Rec => ({
+ ...isMeta(user(text)),
+ promptSource: 'system',
+ origin,
+ turnOrigin: 'peer'
+})
+function systemRecords(): string {
+ return jsonl([
+ user('Run the demo review in the background.'),
+ // A full agent completion: nested <usage>, a multi-line result.
+ tn([
+ '<task-id>bgdemo01</task-id>',
+ '<tool-use-id>toolu_demo_01</tool-use-id>',
+ '<output-file>/srv/demo/tasks/bgdemo01.output</output-file>',
+ '<status>failed</status>',
+ '<summary>Agent "Demo reviewer" failed: out of budget</summary>',
+ '<note>Read the output file for the full log.</note>',
+ '<result>The review stopped early.\nIt reached file 3 of 7.\nNo edits were made.\nFourth line is dropped.</result>',
+ '<usage><subagent_tokens>1200</subagent_tokens><tool_uses>3</tool_uses><duration_ms>4500</duration_ms></usage>'
+ ]),
+ assistant([text('The reviewer ran out of budget; retrying.')]),
+ // A command completion: status + summary only.
+ tn([
+ '<task-id>bgdemo02</task-id>',
+ '<tool-use-id>toolu_demo_02</tool-use-id>',
+ '<output-file>/srv/demo/tasks/bgdemo02.output</output-file>',
+ '<status>completed</status>',
+ '<summary>Background command "npm test" completed (exit code 0)</summary>'
+ ]),
+ // A monitor event: no status, <event> stands in for the result.
+ tn(['<task-id>mondemo1</task-id>', '<summary>Monitor event: "demo deploy"</summary>', '<event>12:00:01 deploy done</event>']),
+ // A summary alone: no `result` key.
+ tn(['<task-id>bgdemo03</task-id>', '<summary>Background agent "demo" started</summary>']),
+ // Repeated task-id, a summary over the 200-unit cap.
+ 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>'], {}),
+ // 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 },
+ // NOT a notification: no origin and text around the element.
+ user('what does <task-notification><summary>x</summary></task-notification> mean?'),
+ assistant([text('It is how a background task reports back.')]),
+ // A subagent hand-back: frame line, <agent-message>, instruction trailer.
+ peer(
+ `${PEER_PREFIX}<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.`,
+ { kind: 'peer', from: 'a0b1c2d3e4f5a6b7c', senderTaskId: 'a0b1c2d3e4f5a6b7c', body: '[demo-fix] Done: the demo build is green.', handback: true }
+ ),
+ assistant([text('Merged the fix.')]),
+ // A cross-session message: from-name is the arg.
+ peer(
+ `${PEER_PREFIX}<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.`,
+ { kind: 'peer', from: 'uds:/run/demo/7.sock', name: 'demo-peer', fromMode: 'prompting', body: 'Please rebase onto main.' }
+ ),
+ // A long report: kept up to 16384 UTF-16 units.
+ peer(`${PEER_PREFIX}<agent-message from="a9">\n${'Report line with detail. '.repeat(800)}\n</agent-message>`, { kind: 'peer', from: 'a9' }),
+ // No element: the whole text.
+ peer(' Hand-back with no element.\nSecond line. ', { kind: 'peer', from: 'a8' }),
+ assistant([text('Rebasing.')]),
+ { ...isMeta(user('Continue from where you left off.')), promptSource: 'system', origin: { kind: 'auto-continuation' }, turnOrigin: 'auto_continuation' },
+ assistant([text('Continuing.')]),
+ { ...isMeta(user('\nCoordinator: split the work.\nWorker A takes the parser.')), origin: { kind: 'coordinator' } },
+ assistant([text('Split.')])
+ ])
+}
+
+// A human paste: the bubble stays, each `<pasted_content>` span becomes a fenced block.
+const HUMAN = { promptSource: 'typed', origin: { kind: 'human' }, turnOrigin: 'human' }
+function pastedContent(): string {
+ return jsonl([
+ { ...user('look at this log\n<pasted_content id="ab12">\nline 1\nline 2\n</pasted_content id="ab12">\nwhat failed?'), ...HUMAN },
+ assistant([text('Line 2 failed.')]),
+ // Backtick runs inside: the fence is one longer than the longest. The same id twice.
+ {
+ ...user('<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'),
+ ...HUMAN
+ },
+ assistant([text('Two snippets.')]),
+ // 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'),
+ { 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 },
+ // 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 },
+ // Unclosed: left as typed.
+ { ...user('<pasted_content id="9">\nnever closed'), ...HUMAN },
+ assistant([text('Noted.')])
+ ])
+}
+
// ── Held permission requests + the answers tried against them ────────────────────────────────────
const pendingPayload = (tool_name: string, tool_input: unknown, permission_mode = 'default'): string =>
JSON.stringify(
@@ -514,7 +617,9 @@ const INPUTS: Record<string, string> = {
'thinking.jsonl': thinking(),
'local-commands.jsonl': localCommands(),
'bash-mode.jsonl': bashMode(),
- 'meta-turns.jsonl': metaTurns()
+ 'meta-turns.jsonl': metaTurns(),
+ 'system-records.jsonl': systemRecords(),
+ 'pasted-content.jsonl': pastedContent()
}
// ── Plumbing ─────────────────────────────────────────────────────────────────────────────────────
diff --git a/src/core/transcript-reader.test.ts b/src/core/transcript-reader.test.ts
index 60024355e..5a7eeec61 100644
--- a/src/core/transcript-reader.test.ts
+++ b/src/core/transcript-reader.test.ts
@@ -774,24 +774,242 @@ describe('isMeta records that start a turn stay visible', () => {
const onlyPromptSource = userStr('prompt source only', { isMeta: true, promptSource: 'system' })
const nulls = userStr('all null', { isMeta: true, promptSource: null, origin: null, turnOrigin: null })
- it('keeps peer / scheduled / auto-continuation prompts as user messages; still skips the caveat', () => {
+ it('keeps them visible; peer / auto-continuation render as system chips, the rest as user messages', () => {
const msgs = parseChatMessages(
(userStr(CAVEAT, { isMeta: true }) + peer + scheduled + autoCont + onlyTurnOrigin + onlyOrigin + onlyPromptSource + nulls).split('\n')
)
- expect(msgs.map((m) => [m.role, textOfMsg(m)])).toEqual([
- ['user', 'Peer says: the build is green.'],
- ['user', 'Scheduled check: run the demo report.'],
- ['user', 'Continue from where you left off.'],
- ['user', 'turn origin only'],
- ['user', 'origin only'],
- ['user', 'prompt source only']
+ expect(msgs.map((m) => [m.role, m.parts[0]])).toEqual([
+ // A peer record is the other session's words, not the user's: an `Agent message` chip.
+ ['assistant', { kind: 'tool', name: 'Agent message', arg: 'Peer says: the build is green.', result: 'Peer says: the build is green.' }],
+ ['user', { kind: 'text', text: 'Scheduled check: run the demo report.' }],
+ ['assistant', { kind: 'tool', name: 'System', arg: 'Continue from where you left off.', result: 'Continue from where you left off.' }],
+ ['user', { kind: 'text', text: 'turn origin only' }],
+ ['assistant', { kind: 'tool', name: 'Agent message', arg: 'origin only', result: 'origin only' }],
+ ['user', { kind: 'text', text: 'prompt source only' }]
])
})
it('the find-bar index applies the same rule', () => {
expect(parseTranscriptLines(userStr(CAVEAT, { isMeta: true }) + scheduled + onlyOrigin)).toEqual([
{ role: 'user', text: 'Scheduled check: run the demo report.' },
- { role: 'user', text: 'origin only' }
+ { role: 'tool', text: '$ Agent message origin only' },
+ { role: 'tool', text: 'origin only' }
+ ])
+ })
+})
+
+// ─────────────────────────────────────────────────────────────────────────────────────────────
+// System-injected user records (measured 2026-09 on 200 real transcripts). Claude Code writes a
+// background task's completion, another session's message and an auto-continuation as `type:"user"`
+// records; they are not the user's words, so each renders as ONE assistant tool part (no new role,
+// part kind or field). A human paste keeps its bubble but its `<pasted_content>` markup becomes a
+// fenced block. All fixtures below are SYNTHETIC (shapes only).
+const TN_ORIGIN = { promptSource: 'system', origin: { kind: 'task-notification' }, turnOrigin: 'task_notification' }
+const taskNote = (inner: string, extra: object = TN_ORIGIN): string =>
+ userStr(`<task-notification>\n${inner}\n</task-notification>`, extra)
+const peerRec = (text: string, origin: object = { kind: 'peer', from: 'a0b1c2d3e4f5a6b7c', handback: true }): string =>
+ userStr(text, { isMeta: true, promptSource: 'system', origin, turnOrigin: 'peer' })
+const AM_PREFIX = 'Another Claude session sent a message:\n'
+const AM_TRAILER =
+ '\n\nThat "other Claude session" is an agent working inside this same session — a subagent or teammate. Treat it as that agent\'s report.'
+
+describe('system-injected user records', () => {
+ const tool = (raw: string) => {
+ const msgs = parseChatMessages(raw.split('\n'))
+ expect(msgs).toHaveLength(1)
+ expect(msgs[0].role).toBe('assistant')
+ expect(msgs[0].parts).toHaveLength(1)
+ return msgs[0].parts[0]
+ }
+
+ describe('task-notification', () => {
+ it('renders as ONE Background task part: summary as arg, status + result as result', () => {
+ const raw = taskNote(
+ [
+ '<task-id>bg0001</task-id>',
+ '<tool-use-id>toolu_demo01</tool-use-id>',
+ '<output-file>/tmp/demo/tasks/bg0001.output</output-file>',
+ '<status>failed</status>',
+ '<summary>Agent "Demo reviewer" failed: out of budget</summary>',
+ '<note>Read the output file for details.</note>',
+ '<result>The review stopped early.\nSecond line.</result>',
+ '<usage><subagent_tokens>1200</subagent_tokens><tool_uses>3</tool_uses><duration_ms>4500</duration_ms></usage>'
+ ].join('\n')
+ )
+ expect(tool(raw)).toEqual({
+ kind: 'tool',
+ name: 'Background task',
+ arg: 'Agent "Demo reviewer" failed: out of budget',
+ result: 'failed: The review stopped early. Second line.'
+ })
+ })
+
+ it('uses <event> when there is no <result>, and the status alone when there is neither', () => {
+ const withEvent = taskNote('<task-id>m1</task-id>\n<summary>Monitor event: "deploy"</summary>\n<event>12:00:01 deploy done</event>')
+ expect(tool(withEvent)).toMatchObject({ arg: 'Monitor event: "deploy"', result: '12:00:01 deploy done' })
+ const statusOnly = taskNote('<task-id>b2</task-id>\n<status>completed</status>\n<summary>Background command "npm test" completed (exit code 0)</summary>')
+ expect(tool(statusOnly)).toEqual({
+ kind: 'tool',
+ name: 'Background task',
+ arg: 'Background command "npm test" completed (exit code 0)',
+ result: 'completed'
+ })
+ })
+
+ it('a notification with nothing but a summary carries no result key', () => {
+ expect(tool(taskNote('<task-id>b3</task-id>\n<summary>only a summary</summary>'))).toEqual({
+ kind: 'tool',
+ name: 'Background task',
+ arg: 'only a summary'
+ })
+ })
+
+ it('matches a whole single <task-notification> element with no origin too', () => {
+ expect(tool(taskNote('<status>completed</status>\n<summary>done</summary>', {}))).toMatchObject({
+ name: 'Background task',
+ arg: 'done',
+ result: 'completed'
+ })
+ })
+
+ 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>')
+ for (const raw of [around, two]) expect(parseChatMessages(raw.split('\n'))[0].role).toBe('user')
+ })
+
+ it('caps the summary like a tool arg and the result like summarizeResult', () => {
+ const t = tool(taskNote(`<status>completed</status>\n<summary>${'s'.repeat(250)}</summary>\n<result>${'r'.repeat(600)}</result>`))
+ expect(t).toMatchObject({ arg: 's'.repeat(200), result: ('completed: ' + 'r'.repeat(600)).slice(0, 500) })
+ })
+
+ it('a malformed notification falls back to a chip with the whole text, never a user bubble', () => {
+ const prose = userStr(' Background task "demo" finished while you were away. ', TN_ORIGIN)
+ expect(tool(prose)).toEqual({
+ kind: 'tool',
+ name: 'Background task',
+ arg: 'Background task "demo" finished while you were away.',
+ result: 'Background task "demo" finished while you were away.'
+ })
+ const unknownTags = taskNote('<mystery>zzz</mystery>')
+ expect(tool(unknownTags)).toMatchObject({
+ name: 'Background task',
+ arg: '<task-notification>',
+ result: '<task-notification>\n<mystery>zzz</mystery>\n</task-notification>'
+ })
+ })
+ })
+
+ describe('peer (agent message)', () => {
+ it('strips the frame lines and the markup; the body is the result, its first line the arg', () => {
+ const body = '[demo-fix] Done: the build is green.\n\nDetails:\n- item one'
+ const raw = peerRec(`${AM_PREFIX}<agent-message from="a0b1c2d3e4f5a6b7c">\n${body}\n</agent-message>${AM_TRAILER}`)
+ expect(tool(raw)).toEqual({ kind: 'tool', name: 'Agent message', arg: '[demo-fix] Done: the build is green.', result: body })
+ })
+
+ it('a cross-session message uses its from-name as the arg', () => {
+ const raw = peerRec(
+ `${AM_PREFIX}<cross-session-message from="uds:/run/demo/1.sock" from-name="demo-peer" from-mode="prompting">\nhello there\n</cross-session-message>\n\nThis came from another Claude session.`,
+ { kind: 'peer', from: 'uds:/run/demo/1.sock', name: 'demo-peer', fromMode: 'prompting' }
+ )
+ expect(tool(raw)).toEqual({ kind: 'tool', name: 'Agent message', arg: 'demo-peer', result: 'hello there' })
+ })
+
+ 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>`))
+ expect(t).toMatchObject({ arg: 'x'.repeat(200), result: 'x'.repeat(16384) })
+ })
+
+ it('a peer record with no message element falls back to the whole text', () => {
+ expect(tool(peerRec(' just text\nsecond line '))).toEqual({
+ kind: 'tool',
+ name: 'Agent message',
+ arg: 'just text',
+ result: 'just text\nsecond line'
+ })
+ })
+
+ it('the find bar indexes the body (searchable), never as user text', () => {
+ const raw = peerRec(`${AM_PREFIX}<agent-message from="a1">\nfirst\nsecond\n</agent-message>${AM_TRAILER}`)
+ expect(parseTranscriptLines(raw)).toEqual([
+ { role: 'tool', text: '$ Agent message first' },
+ { role: 'tool', text: 'first\nsecond' }
+ ])
+ })
+ })
+
+ describe('auto-continuation / coordinator', () => {
+ it('renders as a System part: first line as arg, full text as result', () => {
+ for (const kind of ['auto-continuation', 'coordinator']) {
+ const raw = userStr('\nKeep going.\nMore context here.', { isMeta: true, promptSource: 'system', origin: { kind } })
+ expect(tool(raw)).toEqual({ kind: 'tool', name: 'System', arg: 'Keep going.', result: 'Keep going.\nMore context here.' })
+ }
+ })
+ })
+
+ describe('pasted_content', () => {
+ const human = { promptSource: 'typed', origin: { kind: 'human' }, turnOrigin: 'human' }
+ it('keeps the user bubble and turns each pasted span into a fenced block', () => {
+ const raw = userStr('look at this\n<pasted_content id="ab12">\nline 1\nline 2\n</pasted_content id="ab12">\nthanks', human)
+ const msgs = parseChatMessages(raw.split('\n'))
+ expect(msgs).toEqual([
+ { role: 'user', parts: [{ kind: 'text', text: 'look at this\n\n```\nline 1\nline 2\n```\n\nthanks' }] }
+ ])
+ })
+
+ it('picks a fence longer than any backtick run inside, and handles repeated ids', () => {
+ const inner = '\nuse ```js\ncode\n```` four\n'
+ const raw = userStr(
+ `<pasted_content id="d6cf">${inner}</pasted_content id="d6cf">\n\n<pasted_content id="d6cf">\nplain\n</pasted_content id="d6cf">`,
+ human
+ )
+ expect(textOfMsg(parseChatMessages(raw.split('\n'))[0])).toBe(
+ '\n`````\nuse ```js\ncode\n```` four\n`````\n\n\n\n```\nplain\n```\n'
+ )
+ })
+
+ it('an array text part is transformed too; an unclosed span is left as typed', () => {
+ const raw = jl({
+ type: 'user',
+ ...human,
+ message: {
+ content: [
+ { type: 'text', text: '[Image #1] see\n\n<pasted_content id="1f">\nx\n</pasted_content id="1f">\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')
+ })
+
+ 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 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('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')
+ })
+
+ 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)
+ 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">' }] } })
+ expect(parseTranscriptLines(arr)).toEqual([{ role: 'user', text: '\n```\nc\n```\n' }])
+ })
+ })
+
+ 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([
+ { role: 'tool', text: '$ Background task demo failed' },
+ { role: 'tool', text: 'failed: boom' }
])
})
})
diff --git a/src/core/transcript-reader.ts b/src/core/transcript-reader.ts
index fa4dd51bd..72d87906e 100644
--- a/src/core/transcript-reader.ts
+++ b/src/core/transcript-reader.ts
@@ -149,6 +149,132 @@ export function classifyLocalCommand(content: string): LocalCommandRecord | null
/** The name an output record's tool part gets when there is no command to attach it to. */
export const COMMAND_OUTPUT_TOOL = 'command output'
+// ── System-injected user records ─────────────────────────────────────────────────────────────────
+// Claude Code writes several things that are NOT the user's words as `type:"user"` records. Measured
+// on 200 real transcripts (2026-09), user records without a tool_result, by `origin.kind`:
+// task-notification (promptSource "system") `<task-notification>…</task-notification>` string —
+// a background task / agent / monitor finished. Child tags seen: task-id (0..n),
+// tool-use-id, output-file, status, summary, note, result, event, task-type,
+// usage (nested), worktree; each optional.
+// peer (isMeta, "system") "Another Claude session sent a message:\n" + ONE
+// `<agent-message from="…">` (a subagent hand-back) or `<cross-session-message
+// from="…" from-name="…" from-mode="…">` element + a fixed instruction trailer.
+// auto-continuation / coordinator (isMeta) plain text.
+// Each renders as ONE assistant tool part — the #991 local-command pattern: no new role, part kind
+// 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'
+/** 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
+
+export interface SystemRecord {
+ name: string
+ arg: string
+ /** '' = no result (the part carries no `result` key). */
+ result: string
+}
+
+const originKind = (origin: unknown): string | undefined => {
+ if (!origin || typeof origin !== 'object') return undefined
+ const k = (origin as { kind?: unknown }).kind
+ return typeof k === 'string' ? k : undefined
+}
+
+/** 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)
+const fallback = (name: string, content: string): SystemRecord => ({
+ name,
+ arg: firstLine(content),
+ 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). */
+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>')
+}
+
+/** The first `<name>…</name>` in `text` (non-greedy), trimmed; '' when absent. */
+function tagText(text: string, name: string): string {
+ const m = new RegExp(`<${name}>([\\s\\S]*?)</${name}>`).exec(text)
+ return m ? m[1].trim() : ''
+}
+
+function taskNotification(content: string): SystemRecord {
+ const summary = tagText(content, 'summary')
+ const status = tagText(content, 'status')
+ const body = tagText(content, 'result') || tagText(content, 'event')
+ if (!summary && !status && !body) return fallback(BACKGROUND_TASK_TOOL, content)
+ const text = status && body ? `${status}: ${body}` : status || body
+ 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="([^"]*)"/
+
+function peerMessage(content: string): SystemRecord {
+ const m = PEER_ELEMENT.exec(content)
+ if (!m) return fallback(AGENT_MESSAGE_TOOL, content)
+ const body = m[3].trim()
+ const fromName = (FROM_NAME.exec(m[2] ?? '')?.[1] ?? '').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.
+ */
+export function classifySystemRecord(origin: unknown, content: string): SystemRecord | null {
+ const kind = originKind(origin)
+ if (kind === 'task-notification' || isWholeTaskNotification(content)) return taskNotification(content)
+ if (kind === 'peer') return peerMessage(content)
+ if (kind === 'auto-continuation' || kind === 'coordinator') return fallback(SYSTEM_TOOL, content)
+ return null
+}
+
+/** A system record's tool part (`result` only when non-empty). */
+function systemPart(r: SystemRecord): Extract<ChatPart, { kind: 'tool' }> {
+ const part: Extract<ChatPart, { kind: 'tool' }> = { kind: 'tool', name: r.name, arg: r.arg }
+ if (r.result) part.result = r.result
+ 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`
+ })
+}
+
+/** 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[] {
+ const out: TranscriptLine[] = [{ role: 'tool', text: `$ ${name}${arg ? ` ${arg}` : ''}` }]
+ if (result) out.push({ role: 'tool', text: result })
+ return out
+}
+
// Extract 0..n searchable lines from one raw transcript JSONL line.
function linesFrom(raw: string): TranscriptLine[] {
let o: Parameters<typeof isHiddenMetaRecord>[0] & { message?: { content?: unknown } }
@@ -179,19 +305,23 @@ 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: c.text })
+ if (c.type === 'text' && c.text) out.push({ role: 'user', text: expandPastedContent(c.text) })
else if (c.type === 'tool_result') {
const s = summarizeResult(c.content)
if (s) out.push({ role: 'tool', text: s })
}
}
} 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
+ if (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: content })
+ } else out.push({ role: 'user', text: expandPastedContent(content) })
}
return out
}
@@ -362,7 +492,7 @@ function parseChatRecords(
content?: unknown
}>) {
if (!c || typeof c !== 'object') continue
- if (c.type === 'text' && c.text) parts.push({ kind: 'text', text: c.text })
+ if (c.type === 'text' && c.text) parts.push({ kind: 'text', text: expandPastedContent(c.text) })
else if (c.type === 'tool_result') {
const tool = c.tool_use_id ? toolById.get(c.tool_use_id) : undefined
const s = summarizeResult(c.content)
@@ -377,6 +507,13 @@ function parseChatRecords(
}
if (parts.length) push({ role: 'user', parts }, offset)
} 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)
+ if (sys) {
+ push({ role: 'assistant', parts: [systemPart(sys)] }, offset)
+ continue
+ }
const cmd = classifyLocalCommand(content)
if (cmd?.kind === 'command') {
// The user running a command reads like a tool call — no new role or part kind on the wire.
@@ -393,7 +530,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: content }] }, offset)
+ push({ role: 'user', parts: [{ kind: 'text', text: expandPastedContent(content) }] }, offset)
}
}
}
diff --git a/src/shared/chat-fixtures/README.md b/src/shared/chat-fixtures/README.md
index f78f201d9..827cbe527 100644
--- a/src/shared/chat-fixtures/README.md
+++ b/src/shared/chat-fixtures/README.md
@@ -84,7 +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) stay user messages; the caveat and a skill body (none of the three fields) are skipped. |
+| `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). |
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
@@ -119,7 +121,8 @@ on the paged and unpaged paths alike:
is present with a non-`null` value). That skips the local-command caveat, skill bodies and
injected reminders. An `isMeta` record carrying any of the three starts a turn (a peer / subagent
hand-back, a scheduled or loop wakeup, an auto-continuation) and is parsed like any other user
- record (a user text message).
+ record: the **System-injected records** rules first (a peer or auto-continuation record becomes a
+ system chip there), otherwise the rules below, otherwise a user text message.
2. Only a user record whose `message.content` is a **string** is examined. It must consist ONLY of
whole tags `<t>…</t>` (`t` matches `[a-z-]+`; content non-greedy up to the matching close tag), separated by whitespace (JS `\s`), each
tag name at most once. Anything else in it (prose, an unknown tag, a repeated tag) makes it an
@@ -151,6 +154,74 @@ on the paged and unpaged paths alike:
7. A command message carries `key` / `at` like any other message; an attached output changes
neither. No new role, part kind or field: a v1 decoder reads these as ordinary tool parts.
+## System-injected records (the Swift port must replicate this exactly)
+
+Claude Code writes a background task's completion, another session's message and an
+auto-continuation as `type:"user"` records. They are not the user's words. `parseChatRecords`
+(`classifySystemRecord`, `src/core/transcript-reader.ts`) applies these rules to a user record
+whose `message.content` is a **string** with a non-blank trim, BEFORE the local-command rules above
+(array content is never classified: none of these kinds was measured with it). The kind is
+`origin.kind` when `origin` is an object and `kind` a string, else none.
+
+Each result is ONE assistant message with ONE part `{kind:"tool", name, arg, result}`; `result` is
+**absent** when it is `""`. It carries `key` / `at` like any other message and, like any pushed
+message, ends a local command's wait for its output. No new role, part kind or field.
+
+Helpers (`trim` is JS `String.prototype.trim`, see Local commands rule 6; every cap counts UTF-16
+units, `String.prototype.slice(0, n)`, and may split a surrogate pair exactly as JS does):
+
+- `firstLine(t)` = `t.trim()`, split on `\n`, the first piece, trimmed, first 200 units.
+- `full(t)` = `t.trim()`, first 16384 units (`SYSTEM_RESULT_MAX`).
+- `tag(t, n)` = the content of the FIRST match of `<n>([\s\S]*?)</n>` in `t` (anywhere, nested or
+ not), trimmed; `""` when there is none.
+- `summarize(t)` = `summarizeResult`: split on `\n`, the first three pieces joined by a space, the
+ first 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")`,
+ `status = tag("status")`, `body = tag("result")`, or `tag("event")` when that is `""`. When all
+ three 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 is
+ non-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
+ tag of the same name). No match → the fallback. Otherwise `body` = group 3 trimmed; everything
+ outside 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
+ group 2 is absent or has no match), trimmed. `arg` = the first 200 units of `fromName` when it is
+ non-empty, else `firstLine(body)`; `result` = `full(body)`.
+3. **System** (`name:"System"`) when the kind is `auto-continuation` or `coordinator`: the fallback.
+4. Anything else is not a system record, and the rules above apply unchanged.
+
+The find-bar index (`parseTranscriptLines`) classifies the same records (string content; a
+whitespace-only string is not classified) and indexes the part instead of user text: one
+`{role:"tool", text:"$ " + name}` line (`+ " " + arg` when `arg` is non-empty), then
+`{role:"tool", text: result}` when `result` is non-empty — so an agent's report stays searchable.
+
+## 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.
+
## Sizes
Most inputs are a few KB. Three inputs have to be larger than a page to exercise paging:
diff --git a/src/shared/chat-fixtures/expected/meta-turns.pages.json b/src/shared/chat-fixtures/expected/meta-turns.pages.json
index 420ce7952..bc8658437 100644
--- a/src/shared/chat-fixtures/expected/meta-turns.pages.json
+++ b/src/shared/chat-fixtures/expected/meta-turns.pages.json
@@ -18,11 +18,13 @@
"key": 0
},
{
- "role": "user",
+ "role": "assistant",
"parts": [
{
- "kind": "text",
- "text": "Hand-back from demo-peer: the demo build is green."
+ "kind": "tool",
+ "name": "Agent message",
+ "arg": "Hand-back from demo-peer: the demo build is green.",
+ "result": "Hand-back from demo-peer: the demo build is green."
}
],
"at": 1790362802000,
@@ -62,11 +64,13 @@
"key": 2052
},
{
- "role": "user",
+ "role": "assistant",
"parts": [
{
- "kind": "text",
- "text": "Continue from where you left off."
+ "kind": "tool",
+ "name": "System",
+ "arg": "Continue from where you left off.",
+ "result": "Continue from where you left off."
}
],
"at": 1790362806000,
@@ -106,11 +110,13 @@
"key": 3512
},
{
- "role": "user",
+ "role": "assistant",
"parts": [
{
- "kind": "text",
- "text": "Hand-back with origin only."
+ "kind": "tool",
+ "name": "Agent message",
+ "arg": "Hand-back with origin only.",
+ "result": "Hand-back with origin only."
}
],
"at": 1790362810000,
diff --git a/src/shared/chat-fixtures/expected/pasted-content.pages.json b/src/shared/chat-fixtures/expected/pasted-content.pages.json
new file mode 100644
index 000000000..3f7f0ce0f
--- /dev/null
+++ b/src/shared/chat-fixtures/expected/pasted-content.pages.json
@@ -0,0 +1,127 @@
+[
+ {
+ "before": null,
+ "maxBytes": 262144,
+ "grownMaxBytes": 262144,
+ "start": 0,
+ "parse": {
+ "messages": [
+ {
+ "role": "user",
+ "parts": [
+ {
+ "kind": "text",
+ "text": "look at this log\n\n```\nline 1\nline 2\n```\n\nwhat failed?"
+ }
+ ],
+ "at": 1790362800000,
+ "key": 0
+ },
+ {
+ "role": "assistant",
+ "parts": [
+ {
+ "kind": "text",
+ "text": "Line 2 failed."
+ }
+ ],
+ "at": 1790362801000,
+ "key": 426
+ },
+ {
+ "role": "user",
+ "parts": [
+ {
+ "kind": "text",
+ "text": "\n`````\nuse ```js\ncode\n```` four\n`````\n\n\n\n```\nplain\n```\n\n"
+ }
+ ],
+ "at": 1790362802000,
+ "key": 823
+ },
+ {
+ "role": "assistant",
+ "parts": [
+ {
+ "kind": "text",
+ "text": "Two snippets."
+ }
+ ],
+ "at": 1790362803000,
+ "key": 1301
+ },
+ {
+ "role": "user",
+ "parts": [
+ {
+ "kind": "text",
+ "text": "[Image #1] compare\n\n\n```\nx = 1\n```\n\n"
+ }
+ ],
+ "at": 1790362804000,
+ "key": 1697
+ },
+ {
+ "role": "assistant",
+ "parts": [
+ {
+ "kind": "text",
+ "text": "Compared."
+ }
+ ],
+ "at": 1790362805000,
+ "key": 2218
+ },
+ {
+ "role": "user",
+ "parts": [
+ {
+ "kind": "text",
+ "text": "fyi\n\n```\n<task-notification><summary>s</summary></task-notification>\n```\n"
+ }
+ ],
+ "at": 1790362806000,
+ "key": 2610
+ },
+ {
+ "role": "user",
+ "parts": [
+ {
+ "kind": "text",
+ "text": "\n```\nold </pasted_content id=\"zz\"> paste\n```\n"
+ }
+ ],
+ "at": 1790362807000,
+ "key": 3050
+ },
+ {
+ "role": "user",
+ "parts": [
+ {
+ "kind": "text",
+ "text": "<pasted_content id=\"9\">\nnever closed"
+ }
+ ],
+ "at": 1790362808000,
+ "key": 3461
+ },
+ {
+ "role": "assistant",
+ "parts": [
+ {
+ "kind": "text",
+ "text": "Noted."
+ }
+ ],
+ "at": 1790362809000,
+ "key": 3819
+ }
+ ],
+ "olderCursor": null,
+ "unmatchedResults": [],
+ "model": "claude-opus-5-5",
+ "effort": "high",
+ "noCompleteLine": false
+ }
+ }
+]
diff --git a/src/shared/chat-fixtures/expected/system-records.pages.json b/src/shared/chat-fixtures/expected/system-records.pages.json
new file mode 100644
index 000000000..c84a5c56f
--- /dev/null
+++ b/src/shared/chat-fixtures/expected/system-records.pages.json
@@ -0,0 +1,286 @@
+[
+ {
+ "before": null,
+ "maxBytes": 262144,
+ "grownMaxBytes": 262144,
+ "start": 0,
+ "parse": {
+ "messages": [
+ {
+ "role": "user",
+ "parts": [
+ {
+ "kind": "text",
+ "text": "Run the demo review in the background."
+ }
+ ],
+ "at": 1790362800000,
+ "key": 0
+ },
+ {
+ "role": "assistant",
+ "parts": [
+ {
+ "kind": "tool",
+ "name": "Background task",
+ "arg": "Agent \"Demo reviewer\" failed: out of budget",
+ "result": "failed: The review stopped early. It reached file 3 of 7. No edits were made."
+ }
+ ],
+ "at": 1790362801000,
+ "key": 287
+ },
+ {
+ "role": "assistant",
+ "parts": [
+ {
+ "kind": "text",
+ "text": "The reviewer ran out of budget; retrying."
+ }
+ ],
+ "at": 1790362802000,
+ "key": 1173
+ },
+ {
+ "role": "assistant",
+ "parts": [
+ {
+ "kind": "tool",
+ "name": "Background task",
+ "arg": "Background command \"npm test\" completed (exit code 0)",
+ "result": "completed"
+ }
+ ],
+ "at": 1790362803000,
+ "key": 1597
+ },
+ {
+ "role": "assistant",
+ "parts": [
+ {
+ "kind": "tool",
+ "name": "Background task",
+ "arg": "Monitor event: \"demo deploy\"",
+ "result": "12:00:01 deploy done"
+ }
+ ],
+ "at": 1790362804000,
+ "key": 2217
+ },
+ {
+ "role": "assistant",
+ "parts": [
+ {
+ "kind": "tool",
+ "name": "Background task",
+ "arg": "Background agent \"demo\" started"
+ }
+ ],
+ "at": 1790362805000,
+ "key": 2719
+ },
+ {
+ "role": "assistant",
+ "parts": [
+ {
+ "kind": "tool",
+ "name": "Background task",
+ "arg": "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 ",
+ "result": "killed"
+ }
+ ],
+ "at": 1790362806000,
+ "key": 3187
+ },
+ {
+ "role": "assistant",
+ "parts": [
+ {
+ "kind": "tool",
+ "name": "Background task",
+ "arg": "Demo watcher stopped",
+ "result": "stopped"
+ }
+ ],
+ "at": 1790362807000,
+ "key": 3924
+ },
+ {
+ "role": "assistant",
+ "parts": [
+ {
+ "kind": "tool",
+ "name": "Background task",
+ "arg": "<task-notification>",
+ "result": "<task-notification>\n<mystery>zzz</mystery>\n</task-notification>"
+ }
+ ],
+ "at": 1790362808000,
+ "key": 4281
+ },
+ {
+ "role": "assistant",
+ "parts": [
+ {
+ "kind": "tool",
+ "name": "Background task",
+ "arg": "Background task \"demo\" finished while you were away.",
+ "result": "Background task \"demo\" finished while you were away."
+ }
+ ],
+ "at": 1790362809000,
+ "key": 4690
+ },
+ {
+ "role": "user",
+ "parts": [
+ {
+ "kind": "text",
+ "text": "what does <task-notification><summary>x</summary></task-notification> mean?"
+ }
+ ],
+ "at": 1790362810000,
+ "key": 5092
+ },
+ {
+ "role": "assistant",
+ "parts": [
+ {
+ "kind": "text",
+ "text": "It is how a background task reports back."
+ }
+ ],
+ "at": 1790362811000,
+ "key": 5416
+ },
+ {
+ "role": "assistant",
+ "parts": [
+ {
+ "kind": "tool",
+ "name": "Agent message",
+ "arg": "[demo-fix] Done: the demo build is green.",
+ "result": "[demo-fix] Done: the demo build is green.\n\n**Changed**\n- src/demo.ts"
+ }
+ ],
+ "at": 1790362812000,
+ "key": 5840
+ },
+ {
+ "role": "assistant",
+ "parts": [
+ {
+ "kind": "text",
+ "text": "Merged the fix."
+ }
+ ],
+ "at": 1790362813000,
+ "key": 6586
+ },
+ {
+ "role": "assistant",
+ "parts": [
+ {
+ "kind": "tool",
+ "name": "Agent message",
+ "arg": "demo-peer",
+ "result": "Please rebase onto main."
+ }
+ ],
+ "at": 1790362814000,
+ "key": 6984
+ },
+ {
+ "role": "assistant",
+ "parts": [
+ {
+ "kind": "tool",
+ "name": "Agent message",
+ "arg": "Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. Report line with detail. ",
+ "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
+ },
+ {
+ "role": "assistant",
+ "parts": [
+ {
+ "kind": "tool",
+ "name": "Agent message",
+ "arg": "Hand-back with no element.",
+ "result": "Hand-back with no element.\nSecond line."
+ }
+ ],
+ "at": 1790362816000,
+ "key": 28115
+ },
+ {
+ "role": "assistant",
+ "parts": [
+ {
+ "kind": "text",
+ "text": "Rebasing."
+ }
+ ],
+ "at": 1790362817000,
+ "key": 28503
+ },
+ {
+ "role": "assistant",
+ "parts": [
+ {
+ "kind": "tool",
+ "name": "System",
+ "arg": "Continue from where you left off.",
+ "result": "Continue from where you left off."
+ }
+ ],
+ "at": 1790362818000,
+ "key": 28895
+ },
+ {
+ "role": "assistant",
+ "parts": [
+ {
+ "kind": "text",
+ "text": "Continuing."
+ }
+ ],
+ "at": 1790362819000,
+ "key": 29286
+ },
+ {
+ "role": "assistant",
+ "parts": [
+ {
+ "kind": "tool",
+ "name": "System",
+ "arg": "Coordinator: split the work.",
+ "result": "Coordinator: split the work.\nWorker A takes the parser."
+ }
+ ],
+ "at": 1790362820000,
+ "key": 29680
+ },
+ {
+ "role": "assistant",
+ "parts": [
+ {
+ "kind": "text",
+ "text": "Split."
+ }
+ ],
+ "at": 1790362821000,
+ "key": 30033
+ }
+ ],
+ "olderCursor": null,
+ "unmatchedResults": [],
+ "model": "claude-opus-5-5",
+ "effort": "high",
+ "noCompleteLine": false
+ }
+ }
+]
diff --git a/src/shared/chat-fixtures/inputs/pasted-content.jsonl b/src/shared/chat-fixtures/inputs/pasted-content.jsonl
new file mode 100644
index 000000000..a9ae91e64
--- /dev/null
+++ b/src/shared/chat-fixtures/inputs/pasted-content.jsonl
@@ -0,0 +1,10 @@
+{"type":"user","message":{"role":"user","content":"look at this log\n<pasted_content id=\"ab12\">\nline 1\nline 2\n</pasted_content id=\"ab12\">\nwhat failed?"},"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-000000000000","timestamp":"2026-09-25T19:00:00.000Z"}
+{"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":"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"}
diff --git a/src/shared/chat-fixtures/inputs/system-records.jsonl b/src/shared/chat-fixtures/inputs/system-records.jsonl
new file mode 100644
index 000000000..43c71e83b
--- /dev/null
+++ b/src/shared/chat-fixtures/inputs/system-records.jsonl
@@ -0,0 +1,22 @@
+{"type":"user","message":{"role":"user","content":"Run the demo review in the background."},"isSidechain":false,"sessionId":"5f0c2a9e-3b7d-4e61-9a24-7c1d8e0f4b32","cwd":"/srv/demo","version":"2.1.290","uuid":"00000000-0000-4000-8000-000000000000","timestamp":"2026-09-25T19:00:00.000Z"}
+{"type":"user","message":{"role":"user","content":"<task-notification>\n<task-id>bgdemo01</task-id>\n<tool-use-id>toolu_demo_01</tool-use-id>\n<output-file>/srv/demo/tasks/bgdemo01.output</output-file>\n<status>failed</status>\n<summary>Agent \"Demo reviewer\" failed: out of budget</summary>\n<note>Read the output file for the full log.</note>\n<result>The review stopped early.\nIt reached file 3 of 7.\nNo edits were made.\nFourth line is dropped.</result>\n<usage><subagent_tokens>1200</subagent_tokens><tool_uses>3</tool_uses><duration_ms>4500</duration_ms></usage>\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-000000000001","timestamp":"2026-09-25T19:00:01.000Z"}
+{"type":"assistant","effort":"high","message":{"id":"msg_synthetic","type":"message","role":"assistant","model":"claude-opus-5-5","content":[{"type":"text","text":"The reviewer ran out of budget; retrying."}],"stop_reason":null},"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":"user","message":{"role":"user","content":"<task-notification>\n<task-id>bgdemo02</task-id>\n<tool-use-id>toolu_demo_02</tool-use-id>\n<output-file>/srv/demo/tasks/bgdemo02.output</output-file>\n<status>completed</status>\n<summary>Background command \"npm test\" completed (exit code 0)</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-000000000003","timestamp":"2026-09-25T19:00:03.000Z"}
+{"type":"user","message":{"role":"user","content":"<task-notification>\n<task-id>mondemo1</task-id>\n<summary>Monitor event: \"demo deploy\"</summary>\n<event>12:00:01 deploy done</event>\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-000000000004","timestamp":"2026-09-25T19:00:04.000Z"}
+{"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"}