Node-based terminal manager for AI coding agents — tmux-backed terminals and parallel agent sessions as draggable nodes on an infinite pan/zoom canvas. macOS, Linux, and a browser Server Edition.
TypeScript adhdagent-orchestrationai-agentscanvasclaude-codecodexcoding-agentsdeveloper-toolselectrongeminilinuxmacosmultiplexeropencodeparallel-agentsterminalterminal-emulatorterminal-multiplexertmuxworkspace-manager
fix(chat): render local-command records as tool parts, not raw user bubbles
review56d81ebdd403
diff --git a/src/core/chat-fixtures.test.ts b/src/core/chat-fixtures.test.tsindex dc2577ec1..772af6531 100644--- a/src/core/chat-fixtures.test.ts+++ b/src/core/chat-fixtures.test.ts@@ -310,6 +310,58 @@ function thinking(): string {])}+// ── Local commands (`/model`, `!ls`) ────────────────────────────────────────────────────────────+// Measured shapes: each is a `type:"user"` record with STRING content; the caveat carries+// `isMeta:true`; a slash command's three tags are separated by `\n` + 12 spaces; a skill invocation+// puts `<command-message>` first; a bash output is ONE record with both tags, either may be empty.+const isMeta = (r: Rec): Rec => ({ ...r, isMeta: true })+const CAVEAT =+ '<local-command-caveat>Caveat: The messages below were generated by the user while running local commands. DO NOT respond to these messages or otherwise consider them in your response unless the user explicitly asks you to.</local-command-caveat>'+const slash = (name: string, args = ''): Rec =>+ user(+ `<command-name>${name}</command-name>\n <command-message>${name.slice(1)}</command-message>\n <command-args>${args}</command-args>`+ )++function localCommands(): string {+ return jsonl([+ user('Switch to the bigger model, please.'),+ // caveat (meta, skipped) + /model + its stdout with ANSI bold → ONE tool part with the result.+ isMeta(user(CAVEAT)),+ slash('/model'),+ user('<local-command-stdout>Set model to \u001b[1mDemo Model (1M context)\u001b[22m and saved as your default for new sessions</local-command-stdout>'),+ // A command with args, answered on stderr.+ isMeta(user(CAVEAT)),+ slash('/effort', ' high '),+ user('<local-command-stderr>Effort set to \u001b[36mhigh\u001b[39m</local-command-stderr>'),+ // A command whose stdout is empty: no result.+ slash('/exit'),+ user('<local-command-stdout></local-command-stdout>'),+ // A skill invocation: message before name, no args; its body is a meta record (skipped).+ user('<command-message>demo-skill</command-message>\n<command-name>/demo-skill</command-name>'),+ isMeta(user([text('Base directory for this skill: /srv/demo/skills/demo-skill')])),+ assistant([text('Using the skill.')]),+ // A stdout with no command right before it: its own "command output" tool, never a user bubble.+ // Four lines: capped to three, joined by spaces (the summarizeResult rule).+ user('<local-command-stdout>\nOrphaned output\nsecond line\nthird line\nfourth line\n</local-command-stdout>'),+ // A message that merely MENTIONS the tags inside prose stays a user message.+ user('Why does <command-name>/model</command-name> show up raw in the thread?'),+ assistant([text('Because it was a local command record.')])+ ])+}++function bashMode(): string {+ return jsonl([+ isMeta(user(CAVEAT)),+ user('<bash-input>ls /srv/demo</bash-input>'),+ user('<bash-stdout>a.txt\nb.txt\n</bash-stdout><bash-stderr>ls: warning: demo</bash-stderr>'),+ isMeta(user(CAVEAT)),+ user('<bash-input>cat missing.txt</bash-input>'),+ user('<bash-stdout></bash-stdout><bash-stderr>cat: missing.txt: No such file or directory</bash-stderr>'),+ user('What was in a.txt?'),+ assistant([text('Twelve bytes of demo text.')])+ ])+}+// ── Held permission requests + the answers tried against them ────────────────────────────────────const pendingPayload = (tool_name: string, tool_input: unknown, permission_mode = 'default'): string =>JSON.stringify(@@ -417,7 +469,9 @@ const INPUTS: Record<string, string> = {'model-effort-no-carry.jsonl': modelEffortNoCarry(),'model-effort-synthetic.jsonl': modelEffortSynthetic(),'model-effort-utf16.jsonl': modelEffortUtf16(),- 'thinking.jsonl': thinking()+ 'thinking.jsonl': thinking(),+ 'local-commands.jsonl': localCommands(),+ 'bash-mode.jsonl': bashMode()}// ── Plumbing ─────────────────────────────────────────────────────────────────────────────────────diff --git a/src/core/transcript-reader.test.ts b/src/core/transcript-reader.test.tsindex b3ae007cc..0e79f00da 100644--- a/src/core/transcript-reader.test.ts+++ b/src/core/transcript-reader.test.ts@@ -579,3 +579,170 @@ describe('parseTranscriptLines — the find-bar index skips a null record / elemexpect(parseTranscriptLines(text)).toEqual([{ role: 'assistant', text: 'found' }])})})++// ─────────────────────────────────────────────────────────────────────────────────────────────+// Local-command records. Claude writes a slash command (`/model`) and a `!` bash-mode line as+// `type:"user"` records whose content is a STRING of XML-ish tags, preceded by an `isMeta` caveat.+// Rendered as user bubbles they read as raw markup; they are the user running a command, and its+// output — the same shape as a tool call. All fixtures below are SYNTHETIC.+const userStr = (content: string, extra: object = {}): string =>+ jl({ type: 'user', ...extra, message: { role: 'user', content } })+const CAVEAT =+ '<local-command-caveat>Caveat: The messages below were generated by the user while running local commands. DO NOT respond to these messages or otherwise consider them in your response unless the user explicitly asks you to.</local-command-caveat>'+const cmdRec = (name: string, args = ''): string =>+ userStr(+ `<command-name>${name}</command-name>\n <command-message>${name.slice(1)}</command-message>\n <command-args>${args}</command-args>`+ )++describe('parseChatMessages — local-command records', () => {+ it('skips an isMeta user record, drops the caveat and folds /model + its stdout into one tool part', () => {+ const msgs = parseChatMessages(+ (+ userStr(CAVEAT, { isMeta: true }) ++ cmdRec('/model') ++ userStr('<local-command-stdout>Set model to \u001b[1mDemo Model\u001b[22m and saved</local-command-stdout>') ++ said('user', 'hi')+ ).split('\n')+ )+ expect(msgs).toEqual([+ { role: 'assistant', parts: [{ kind: 'tool', name: '/model', arg: '', result: 'Set model to Demo Model and saved' }] },+ { role: 'user', parts: [{ kind: 'text', text: 'hi' }] }+ ])+ })++ it('an isMeta user record with array content is skipped too', () => {+ const msgs = parseChatMessages(+ jl({ type: 'user', isMeta: true, message: { content: [{ type: 'text', text: 'skill body' }] } }).split('\n')+ )+ expect(msgs).toEqual([])+ })++ it('carries trimmed args, and the name/message order does not matter', () => {+ const a = parseChatMessages(cmdRec('/resume', ' abc-123 ').split('\n'))+ expect(a).toEqual([{ role: 'assistant', parts: [{ kind: 'tool', name: '/resume', arg: 'abc-123' }] }])+ const b = parseChatMessages(userStr('<command-message>plan</command-message>\n<command-name>/plan</command-name>').split('\n'))+ expect(b).toEqual([{ role: 'assistant', parts: [{ kind: 'tool', name: '/plan', arg: '' }] }])+ })++ it('stderr attaches like stdout; an empty stdout attaches nothing', () => {+ const e = parseChatMessages((cmdRec('/mcp') + userStr('<local-command-stderr>boom</local-command-stderr>')).split('\n'))+ expect(e[0].parts[0]).toEqual({ kind: 'tool', name: '/mcp', arg: '', result: 'boom' })+ const empty = parseChatMessages((cmdRec('/exit') + userStr('<local-command-stdout></local-command-stdout>')).split('\n'))+ expect(empty).toEqual([{ role: 'assistant', parts: [{ kind: 'tool', name: '/exit', arg: '' }] }])+ })++ it('caps a long stdout the way tool results are capped', () => {+ const out = ['l1', 'l2', 'l3', 'l4'].join('\n')+ const m = parseChatMessages((cmdRec('/x') + userStr(`<local-command-stdout>\n${out}\n</local-command-stdout>`)).split('\n'))+ expect(m[0].parts[0]).toMatchObject({ result: 'l1 l2 l3' })+ const long = parseChatMessages((cmdRec('/x') + userStr(`<local-command-stdout>${'y'.repeat(900)}</local-command-stdout>`)).split('\n'))+ expect((long[0].parts[0] as { result: string }).result.length).toBe(500)+ })++ it('a stdout with no command before it is its own "command output" tool, never a user bubble', () => {+ const msgs = parseChatMessages(+ (said('user', 'q') + userStr('<local-command-stdout>orphan</local-command-stdout>')).split('\n')+ )+ expect(msgs[1]).toEqual({ role: 'assistant', parts: [{ kind: 'tool', name: 'command output', arg: '', result: 'orphan' }] })+ })++ it('a stdout attaches only to the message right before it — another message in between orphans it', () => {+ const msgs = parseChatMessages(+ (cmdRec('/model') + said('user', 'meanwhile') + userStr('<local-command-stdout>late</local-command-stdout>')).split('\n')+ )+ expect(msgs[0].parts[0]).toEqual({ kind: 'tool', name: '/model', arg: '' })+ expect(msgs[2]).toEqual({ role: 'assistant', parts: [{ kind: 'tool', name: 'command output', arg: '', result: 'late' }] })+ })++ it('a stdout after a command that already has a result does not overwrite it', () => {+ const msgs = parseChatMessages(+ (+ cmdRec('/model') ++ userStr('<local-command-stdout>first</local-command-stdout>') ++ userStr('<local-command-stdout>second</local-command-stdout>')+ ).split('\n')+ )+ expect(msgs).toEqual([+ { role: 'assistant', parts: [{ kind: 'tool', name: '/model', arg: '', result: 'first' }] },+ { role: 'assistant', parts: [{ kind: 'tool', name: 'command output', arg: '', result: 'second' }] }+ ])+ })++ it('bash mode: input is a "!" tool, and the combined stdout/stderr record is its result', () => {+ const msgs = parseChatMessages(+ (+ userStr('<bash-input>ls -la</bash-input>') ++ userStr('<bash-stdout>a.txt\nb.txt</bash-stdout><bash-stderr>warn</bash-stderr>') ++ userStr('<bash-input>false</bash-input>') ++ userStr('<bash-stdout></bash-stdout><bash-stderr>failed</bash-stderr>')+ ).split('\n')+ )+ expect(msgs).toEqual([+ { role: 'assistant', parts: [{ kind: 'tool', name: '!', arg: 'ls -la', result: 'a.txt b.txt warn' }] },+ { role: 'assistant', parts: [{ kind: 'tool', name: '!', arg: 'false', result: 'failed' }] }+ ])+ })++ it('bash output never attaches to a slash command (and vice versa)', () => {+ const msgs = parseChatMessages((cmdRec('/model') + userStr('<bash-stdout>x</bash-stdout><bash-stderr></bash-stderr>')).split('\n'))+ expect(msgs[0].parts[0]).toEqual({ kind: 'tool', name: '/model', arg: '' })+ expect(msgs[1]).toEqual({ role: 'assistant', parts: [{ kind: 'tool', name: 'command output', arg: '', result: 'x' }] })+ })++ it('a record that merely MENTIONS the tags inside prose stays a user message', () => {+ const prose = 'Why does <command-name>/model</command-name> show up raw?'+ const trailing = '<command-name>/model</command-name> and then some prose'+ const stdoutProse = 'see <local-command-stdout>x</local-command-stdout>'+ const msgs = parseChatMessages((userStr(prose) + userStr(trailing) + userStr(stdoutProse)).split('\n'))+ expect(msgs.map((m) => [m.role, textOfMsg(m)])).toEqual([+ ['user', prose],+ ['user', trailing],+ ['user', stdoutProse]+ ])+ })++ it('a record with a repeated or unknown tag, or no command name, is not a command', () => {+ const dup = '<command-name>/a</command-name><command-name>/b</command-name>'+ const unknown = '<command-name>/a</command-name><command-foo>x</command-foo>'+ const noName = '<command-message>a</command-message><command-args>x</command-args>'+ const emptyName = '<command-name> </command-name>'+ const msgs = parseChatMessages((userStr(dup) + userStr(unknown) + userStr(noName) + userStr(emptyName)).split('\n'))+ expect(msgs.map((m) => m.role)).toEqual(['user', 'user', 'user', 'user'])+ })++ it('paged: the command message carries its own key and at', () => {+ const buf = Buffer.from(+ userStr(CAVEAT, { isMeta: true }) ++ jl({+ type: 'user',+ timestamp: '2026-09-25T19:00:00.000Z',+ message: { content: '<command-name>/model</command-name><command-args></command-args>' }+ }) ++ userStr('<local-command-stdout>ok</local-command-stdout>')+ )+ const r = parseChatWindow(buf, 0)+ const off = Buffer.byteLength(userStr(CAVEAT, { isMeta: true }))+ expect(r.messages).toEqual([+ { role: 'assistant', parts: [{ kind: 'tool', name: '/model', arg: '', result: 'ok' }], at: Date.parse('2026-09-25T19:00:00.000Z'), key: off }+ ])+ })+})++describe('parseTranscriptLines — local-command records', () => {+ it('indexes commands as tool lines and never as raw tagged user text; skips isMeta', () => {+ const text =+ userStr(CAVEAT, { isMeta: true }) ++ cmdRec('/model', 'opus') ++ userStr('<local-command-stdout>Set \u001b[1mX\u001b[22m</local-command-stdout>') ++ userStr('<bash-input>ls</bash-input>') ++ userStr('<bash-stdout>a</bash-stdout><bash-stderr></bash-stderr>') ++ userStr('real question')+ expect(parseTranscriptLines(text)).toEqual([+ { role: 'tool', text: '$ /model opus' },+ { role: 'tool', text: 'Set X' },+ { role: 'tool', text: '$ ! ls' },+ { role: 'tool', text: 'a' },+ { role: 'user', text: 'real question' }+ ])+ })+})diff --git a/src/core/transcript-reader.ts b/src/core/transcript-reader.tsindex b17c33f25..5e367d72b 100644--- a/src/core/transcript-reader.ts+++ b/src/core/transcript-reader.ts@@ -52,8 +52,84 @@ function toolArg(input: unknown): string {}// Extract 0..n searchable lines from one raw transcript JSONL line.+// ── Local-command records ────────────────────────────────────────────────────────────────────────+// A slash command (`/model`) and a `!` bash-mode line are written by claude as `type:"user"` records+// whose content is a STRING of tags — measured on real transcripts (2026-09):+// <command-name>/model</command-name>\n <command-message>model</command-message>\n <command-args></command-args>+// <local-command-stdout>Set model to \x1b[1m…\x1b[22m</local-command-stdout>+// <bash-input>ls</bash-input>+// <bash-stdout>…</bash-stdout><bash-stderr>…</bash-stderr> (ONE record, either may be empty)+// preceded by an `isMeta:true` `<local-command-caveat>` record. A skill invocation writes+// `<command-message>` BEFORE `<command-name>` (no args), so order is free. Only a record that is+// EXACTLY such a tag sequence (whitespace between tags) is one; a record that merely mentions a tag+// inside prose is a normal user message. Never seen as an array text part, so only string content+// is matched.+export type LocalCommandRecord =+ | { kind: 'command'; family: 'slash' | 'bash'; name: string; arg: string }+ | { kind: 'output'; family: 'slash' | 'bash'; text: string }++const TAG_RE = /<([a-z-]+)>([\s\S]*?)<\/\1>/y+const SLASH_TAGS = new Set(['command-name', 'command-message', 'command-args'])+const BASH_INPUT_TAGS = new Set(['bash-input'])+const SLASH_OUT_TAGS = new Set(['local-command-stdout', 'local-command-stderr'])+const BASH_OUT_TAGS = new Set(['bash-stdout', 'bash-stderr'])++/** The record as a sequence of whole tags, each at most once; null if anything else is in it. */+function tagSequence(content: string): Map<string, string> | null {+ const tags = new Map<string, string>()+ let i = 0+ for (;;) {+ while (i < content.length && /\s/.test(content[i])) i+++ if (i >= content.length) break+ TAG_RE.lastIndex = i+ const m = TAG_RE.exec(content)+ if (!m || tags.has(m[1])) return null+ tags.set(m[1], m[2])+ i = TAG_RE.lastIndex+ }+ return tags.size ? tags : null+}++const onlyFrom = (tags: Map<string, string>, allowed: Set<string>): boolean =>+ [...tags.keys()].every((k) => allowed.has(k))++/** CSI (`ESC [ … final`), OSC (`ESC ] … BEL|ESC \\`) and two-byte `ESC x` escapes. */+export function stripAnsi(s: string): string {+ return s+ .replace(/\x1b\[[0-?]*[ -/]*[@-~]/g, '')+ .replace(/\x1b\][^\x07\x1b]*(?:\x07|\x1b\\)/g, '')+ .replace(/\x1b[@-_]/g, '')+}++/** Output tags → one text: each non-empty part ANSI-stripped + trimmed, joined by `\n`. */+function outputText(tags: Map<string, string>): string {+ return [...tags.values()]+ .map((v) => stripAnsi(v).trim())+ .filter(Boolean)+ .join('\n')+}++export function classifyLocalCommand(content: string): LocalCommandRecord | null {+ const tags = tagSequence(content)+ if (!tags) return null+ if (onlyFrom(tags, SLASH_TAGS)) {+ const name = (tags.get('command-name') ?? '').trim()+ if (!name) return null+ return { kind: 'command', family: 'slash', name, arg: (tags.get('command-args') ?? '').trim() }+ }+ if (onlyFrom(tags, BASH_INPUT_TAGS)) {+ return { kind: 'command', family: 'bash', name: '!', arg: (tags.get('bash-input') ?? '').trim() }+ }+ if (onlyFrom(tags, SLASH_OUT_TAGS)) return { kind: 'output', family: 'slash', text: outputText(tags) }+ if (onlyFrom(tags, BASH_OUT_TAGS)) return { kind: 'output', family: 'bash', text: outputText(tags) }+ return 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'+function linesFrom(raw: string): TranscriptLine[] {- let o: { type?: string; message?: { content?: unknown } }+ let o: { type?: string; isMeta?: unknown; message?: { content?: unknown } }try {o = JSON.parse(raw)} catch {@@ -61,6 +137,9 @@ function linesFrom(raw: string): TranscriptLine[] {}// Same rule as the chat parser: a `null` / scalar line is one skipped line, never a failed read.if (!o || typeof o !== 'object' || Array.isArray(o)) return []+ // Same rule as the chat parser: claude's own meta records (the local-command caveat, skill bodies,+ // injected reminders) are not something the user said.+ if (o.type === 'user' && o.isMeta === true) return []const content = o.message?.contentconst out: TranscriptLine[] = []if (o.type === 'assistant' && Array.isArray(content)) {@@ -86,7 +165,12 @@ function linesFrom(raw: string): TranscriptLine[] {}}} else if (o.type === 'user' && typeof content === 'string') {- out.push({ role: 'user', text: content })+ 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 })}return out}@@ -182,7 +266,12 @@ function parseChatRecords(// with no `effort`) are claude's own, not a model turn, so they are skipped entirely.let model: string | undefinedlet effort: string | undefined+ // The tool part of the LAST pushed message when that message is a local command still waiting for+ // its output record (cleared by any other push, so output attaches only to the record right+ // before it).+ let awaitingOutput: { family: 'slash' | 'bash'; part: Extract<ChatPart, { kind: 'tool' }> } | null = nullconst push = (m: ChatMessage, offset: number): void => {+ awaitingOutput = null// `at` rides BOTH paths (additive): the time the line was written, for the thread's relative// timestamp. Absent when the line states none — never a made-up time.const withAt = at === undefined ? m : { ...m, at }@@ -190,7 +279,13 @@ function parseChatRecords(}for (const { raw, offset } of records) {if (!raw.trim()) continue- let o: { type?: string; timestamp?: unknown; effort?: unknown; message?: { content?: unknown; model?: unknown } }+ let o: {+ type?: string+ isMeta?: unknown+ timestamp?: unknown+ effort?: unknown+ message?: { content?: unknown; model?: unknown }+ }try {o = JSON.parse(raw)} catch {@@ -199,6 +294,9 @@ function parseChatRecords(// `null` / a number / a string parse fine and would throw on the reads below, failing the whole// page over one line another program wrote. One bad line costs one line (the Swift port agrees).if (!o || typeof o !== 'object' || Array.isArray(o)) continue+ // claude's own meta records (the local-command caveat, skill bodies, injected reminders): never+ // something the user said. Measured: none carries a tool_result, so nothing is lost by skipping.+ if (o.type === 'user' && o.isMeta === true) continueat = lineTime(o.timestamp)const content = o.message?.contentif (paged && o.type === 'assistant' && o.message?.model !== SYNTHETIC_MODEL) {@@ -258,7 +356,24 @@ function parseChatRecords(}if (parts.length) push({ role: 'user', parts }, offset)} else if (o.type === 'user' && typeof content === 'string' && content.trim()) {- push({ role: 'user', parts: [{ kind: 'text', text: content }] }, offset)+ 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.+ const part: Extract<ChatPart, { kind: 'tool' }> = { kind: 'tool', name: cmd.name, arg: cmd.arg }+ push({ role: 'assistant', parts: [part] }, offset)+ awaitingOutput = { family: cmd.family, part }+ } else if (cmd?.kind === 'output') {+ const s = summarizeResult(cmd.text)+ if (!s) continue+ if (awaitingOutput && awaitingOutput.family === cmd.family) {+ awaitingOutput.part.result = s+ awaitingOutput = null+ } else {+ push({ role: 'assistant', parts: [{ kind: 'tool', name: COMMAND_OUTPUT_TOOL, arg: '', result: s }] }, offset)+ }+ } else {+ push({ role: 'user', parts: [{ kind: 'text', text: content }] }, offset)+ }}}const out: ChatRecordsOut = { messages, unmatched }diff --git a/src/shared/chat-fixtures/README.md b/src/shared/chat-fixtures/README.mdindex eff3f5d2f..246afc61a 100644--- a/src/shared/chat-fixtures/README.md+++ b/src/shared/chat-fixtures/README.md@@ -82,6 +82,8 @@ the production paging, not a second implementation of it.| `model-effort-synthetic` | A `<synthetic>` record (an API error or interrupt, with no effort) is skipped entirely, so both fields come from the real record before it. || `model-effort-utf16` | The 100-character cap counts **UTF-16 code units** (Swift `utf16.count`), not bytes or scalars. A model of 50 × U+1F9EA (100 units) is kept, and an effort of 101 units is absent. || `thinking` | Thinking blocks (`thinking`, `redacted_thinking`). The current TS reader **drops** them: a thinking-only record yields no message, and a mixed record keeps only its text. The port must match this until the desktop reader changes. |+| `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>`; `/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. |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@@ -106,6 +108,33 @@ parses, and the cap is applied by `buildPermissionDecision` (`plan-revise-too-lo`question-free-text-too-long-refused`). Text of exactly 8000 units is accepted (`plan-revise-at-cap`,`question-free-text-at-cap`), so a port with a lower cap fails too.+## Local commands (the Swift port must replicate this exactly)++`parseChatRecords` (`src/core/transcript-reader.ts`, `classifyLocalCommand`) applies these rules,+on the paged and unpaged paths alike:++1. A `type:"user"` record with `isMeta === true` is skipped entirely (no message, no `at` effect).+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+ ordinary user text message.+3. Tags only from {`command-name`, `command-message`, `command-args`}, any order, with a non-blank+ trimmed `command-name` → **command**: an assistant message with one part+ `{kind:"tool", name:<command-name trimmed>, arg:<command-args trimmed, "" when absent>}`.+ Tags only from {`bash-input`} → command with `name:"!"`, `arg:<bash-input trimmed>`.+4. Tags only from {`local-command-stdout`, `local-command-stderr`} (slash family) or only from+ {`bash-stdout`, `bash-stderr`} (bash family) → **output**. Its text is each tag's content, in+ record order, with ANSI escapes removed (`\x1b[` CSI `[0-?]*[ -/]*[@-~]`, then OSC+ `\x1b][^\x07\x1b]*(\x07|\x1b\\)`, then two-byte `\x1b[@-_]`), trimmed, empty parts dropped,+ joined by `\n`, then capped like a tool result (first three lines joined by a space, first 500+ UTF-16 units). An empty text produces nothing.+5. A non-empty output sets `result` on the command's tool part when the **last pushed message** is+ a command of the **same family** that has no result yet. Otherwise it is pushed as its own+ assistant message `{kind:"tool", name:"command output", arg:"", result}`. Any pushed message+ ends the wait, and so does an attached output (a second output does not overwrite).+6. 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.+## SizesMost 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/bash-mode.pages.json b/src/shared/chat-fixtures/expected/bash-mode.pages.jsonnew file mode 100644index 000000000..2986aa3f4--- /dev/null+++ b/src/shared/chat-fixtures/expected/bash-mode.pages.json@@ -0,0 +1,65 @@+[+ {+ "before": null,+ "maxBytes": 262144,+ "grownMaxBytes": 262144,+ "start": 0,+ "parse": {+ "messages": [+ {+ "role": "assistant",+ "parts": [+ {+ "kind": "tool",+ "name": "!",+ "arg": "ls /srv/demo",+ "result": "a.txt b.txt ls: warning: demo"+ }+ ],+ "at": 1790362801000,+ "key": 508+ },+ {+ "role": "assistant",+ "parts": [+ {+ "kind": "tool",+ "name": "!",+ "arg": "cat missing.txt",+ "result": "cat: missing.txt: No such file or directory"+ }+ ],+ "at": 1790362804000,+ "key": 1636+ },+ {+ "role": "user",+ "parts": [+ {+ "kind": "text",+ "text": "What was in a.txt?"+ }+ ],+ "at": 1790362806000,+ "key": 2271+ },+ {+ "role": "assistant",+ "parts": [+ {+ "kind": "text",+ "text": "Twelve bytes of demo text."+ }+ ],+ "at": 1790362807000,+ "key": 2538+ }+ ],+ "olderCursor": null,+ "unmatchedResults": [],+ "model": "claude-opus-5-5",+ "effort": "high",+ "noCompleteLine": false+ }+ }+]diff --git a/src/shared/chat-fixtures/expected/local-commands.pages.json b/src/shared/chat-fixtures/expected/local-commands.pages.jsonnew file mode 100644index 000000000..3f43030df--- /dev/null+++ b/src/shared/chat-fixtures/expected/local-commands.pages.json@@ -0,0 +1,124 @@+[+ {+ "before": null,+ "maxBytes": 262144,+ "grownMaxBytes": 262144,+ "start": 0,+ "parse": {+ "messages": [+ {+ "role": "user",+ "parts": [+ {+ "kind": "text",+ "text": "Switch to the bigger model, please."+ }+ ],+ "at": 1790362800000,+ "key": 0+ },+ {+ "role": "assistant",+ "parts": [+ {+ "kind": "tool",+ "name": "/model",+ "arg": "",+ "result": "Set model to Demo Model (1M context) and saved as your default for new sessions"+ }+ ],+ "at": 1790362802000,+ "key": 792+ },+ {+ "role": "assistant",+ "parts": [+ {+ "kind": "tool",+ "name": "/effort",+ "arg": "high",+ "result": "Effort set to high"+ }+ ],+ "at": 1790362805000,+ "key": 2073+ },+ {+ "role": "assistant",+ "parts": [+ {+ "kind": "tool",+ "name": "/exit",+ "arg": ""+ }+ ],+ "at": 1790362807000,+ "key": 2796+ },+ {+ "role": "assistant",+ "parts": [+ {+ "kind": "tool",+ "name": "/demo-skill",+ "arg": ""+ }+ ],+ "at": 1790362809000,+ "key": 3469+ },+ {+ "role": "assistant",+ "parts": [+ {+ "kind": "text",+ "text": "Using the skill."+ }+ ],+ "at": 1790362811000,+ "key": 4151+ },+ {+ "role": "assistant",+ "parts": [+ {+ "kind": "tool",+ "name": "command output",+ "arg": "",+ "result": "Orphaned output second line third line"+ }+ ],+ "at": 1790362812000,+ "key": 4550+ },+ {+ "role": "user",+ "parts": [+ {+ "kind": "text",+ "text": "Why does <command-name>/model</command-name> show up raw in the thread?"+ }+ ],+ "at": 1790362813000,+ "key": 4901+ },+ {+ "role": "assistant",+ "parts": [+ {+ "kind": "text",+ "text": "Because it was a local command record."+ }+ ],+ "at": 1790362814000,+ "key": 5221+ }+ ],+ "olderCursor": null,+ "unmatchedResults": [],+ "model": "claude-opus-5-5",+ "effort": "high",+ "noCompleteLine": false+ }+ }+]diff --git a/src/shared/chat-fixtures/inputs/bash-mode.jsonl b/src/shared/chat-fixtures/inputs/bash-mode.jsonlnew file mode 100644index 000000000..d0dfc2b6f--- /dev/null+++ b/src/shared/chat-fixtures/inputs/bash-mode.jsonl@@ -0,0 +1,8 @@+{"type":"user","message":{"role":"user","content":"<local-command-caveat>Caveat: The messages below were generated by the user while running local commands. DO NOT respond to these messages or otherwise consider them in your response unless the user explicitly asks you to.</local-command-caveat>"},"isMeta":true,"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":"<bash-input>ls /srv/demo</bash-input>"},"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":"<bash-stdout>a.txt\nb.txt\n</bash-stdout><bash-stderr>ls: warning: demo</bash-stderr>"},"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":"<local-command-caveat>Caveat: The messages below were generated by the user while running local commands. DO NOT respond to these messages or otherwise consider them in your response unless the user explicitly asks you to.</local-command-caveat>"},"isMeta":true,"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":"<bash-input>cat missing.txt</bash-input>"},"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":"<bash-stdout></bash-stdout><bash-stderr>cat: missing.txt: No such file or directory</bash-stderr>"},"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":"What was in a.txt?"},"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":"assistant","effort":"high","message":{"id":"msg_synthetic","type":"message","role":"assistant","model":"claude-opus-5-5","content":[{"type":"text","text":"Twelve bytes of demo text."}],"stop_reason":null},"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"}diff --git a/src/shared/chat-fixtures/inputs/local-commands.jsonl b/src/shared/chat-fixtures/inputs/local-commands.jsonlnew file mode 100644index 000000000..9423c90e9--- /dev/null+++ b/src/shared/chat-fixtures/inputs/local-commands.jsonl@@ -0,0 +1,15 @@+{"type":"user","message":{"role":"user","content":"Switch to the bigger model, please."},"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":"<local-command-caveat>Caveat: The messages below were generated by the user while running local commands. DO NOT respond to these messages or otherwise consider them in your response unless the user explicitly asks you to.</local-command-caveat>"},"isMeta":true,"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":"<command-name>/model</command-name>\n <command-message>model</command-message>\n <command-args></command-args>"},"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":"<local-command-stdout>Set model to \u001b[1mDemo Model (1M context)\u001b[22m and saved as your default for new sessions</local-command-stdout>"},"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":"<local-command-caveat>Caveat: The messages below were generated by the user while running local commands. DO NOT respond to these messages or otherwise consider them in your response unless the user explicitly asks you to.</local-command-caveat>"},"isMeta":true,"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":"<command-name>/effort</command-name>\n <command-message>effort</command-message>\n <command-args> high </command-args>"},"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":"<local-command-stderr>Effort set to \u001b[36mhigh\u001b[39m</local-command-stderr>"},"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":"<command-name>/exit</command-name>\n <command-message>exit</command-message>\n <command-args></command-args>"},"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":"<local-command-stdout></local-command-stdout>"},"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":"<command-message>demo-skill</command-message>\n<command-name>/demo-skill</command-name>"},"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":[{"type":"text","text":"Base directory for this skill: /srv/demo/skills/demo-skill"}]},"isMeta":true,"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":"Using the skill."}],"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":"<local-command-stdout>\nOrphaned output\nsecond line\nthird line\nfourth line\n</local-command-stdout>"},"isSidechain":false,"sessionId":"5f0c2a9e-3b7d-4e61-9a24-7c1d8e0f4b32","cwd":"/srv/demo","version":"2.1.290","uuid":"00000000-0000-4000-8000-000000000012","timestamp":"2026-09-25T19:00:12.000Z"}+{"type":"user","message":{"role":"user","content":"Why does <command-name>/model</command-name> show up raw in the thread?"},"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":"assistant","effort":"high","message":{"id":"msg_synthetic","type":"message","role":"assistant","model":"claude-opus-5-5","content":[{"type":"text","text":"Because it was a local command record."}],"stop_reason":null},"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"}