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): keep turn-starting isMeta prompts; confirm sent slash commands
reviewbad6518610e0
diff --git a/src/core/chat-fixtures.test.ts b/src/core/chat-fixtures.test.tsindex 772af6531..0a7d62dc5 100644--- a/src/core/chat-fixtures.test.ts+++ b/src/core/chat-fixtures.test.ts@@ -333,6 +333,8 @@ function localCommands(): string {isMeta(user(CAVEAT)),slash('/effort', ' high '),user('<local-command-stderr>Effort set to \u001b[36mhigh\u001b[39m</local-command-stderr>'),+ // An arg longer than the 200-unit cap (`CHAT_TOOL_ARG_MAX`): trimmed, then cut at 200.+ slash('/compact', ' keep the ' + 'demo '.repeat(60) + 'notes '),// A command whose stdout is empty: no result.slash('/exit'),user('<local-command-stdout></local-command-stdout>'),@@ -362,6 +364,40 @@ function bashMode(): string {])}+/** `isMeta` records that START a turn stay user messages; only the ones carrying none of+ * `promptSource` / `origin` / `turnOrigin` (the caveat, a skill body) are skipped. Shapes measured+ * (fields only — the texts here are invented). */+function metaTurns(): string {+ return jsonl([+ user('Keep an eye on the demo build.'),+ isMeta(user(CAVEAT)),+ // A peer / subagent hand-back.+ {+ ...isMeta(user('Hand-back from demo-peer: the demo build is green.')),+ promptSource: 'system',+ origin: { kind: 'peer', from: 'demo-peer', senderTaskId: 'task-demo-7', body: 'the demo build is green', handback: true },+ turnOrigin: 'peer'+ },+ assistant([text('Noted: green.')]),+ // A scheduled / loop wakeup.+ {+ ...isMeta(user('Scheduled wakeup: check the demo build again.')),+ promptSource: 'system',+ turnOrigin: 'scheduled',+ scheduledTaskId: 'sched-demo-1'+ },+ assistant([text('Still green.')]),+ // An auto-continuation.+ { ...isMeta(user('Continue from where you left off.')), promptSource: 'system', origin: { kind: 'auto-continuation' } },+ assistant([text('Continuing.')]),+ // `promptSource` alone is enough to keep it.+ { ...isMeta(user('System prompt source only.')), promptSource: 'system' },+ assistant([text('Seen.')]),+ // A skill body (isMeta, none of the three fields): still skipped.+ isMeta(user([text('Base directory for this skill: /srv/demo/skills/demo-skill')]))+ ])+}+// ── Held permission requests + the answers tried against them ────────────────────────────────────const pendingPayload = (tool_name: string, tool_input: unknown, permission_mode = 'default'): string =>JSON.stringify(@@ -471,7 +507,8 @@ const INPUTS: Record<string, string> = {'model-effort-utf16.jsonl': modelEffortUtf16(),'thinking.jsonl': thinking(),'local-commands.jsonl': localCommands(),- 'bash-mode.jsonl': bashMode()+ 'bash-mode.jsonl': bashMode(),+ 'meta-turns.jsonl': metaTurns()}// ── Plumbing ─────────────────────────────────────────────────────────────────────────────────────diff --git a/src/core/transcript-reader.test.ts b/src/core/transcript-reader.test.tsindex 0e79f00da..60024355e 100644--- a/src/core/transcript-reader.test.ts+++ b/src/core/transcript-reader.test.ts@@ -746,3 +746,63 @@ describe('parseTranscriptLines — local-command records', () => {])})})++// Review round 1: an isMeta record that STARTS a turn (a peer hand-back, a scheduled / loop wakeup,+// an auto-continuation) is claude marking where the prompt came from, not a meta record to hide —+// without it a /loop thread shows replies with no prompt between them. Measured: those carry+// `promptSource` and/or `origin` / `turnOrigin`; the caveat and skill bodies carry none of them.+describe('isMeta records that start a turn stay visible', () => {+ const peer = userStr('Peer says: the build is green.', {+ isMeta: true,+ promptSource: 'system',+ origin: { kind: 'peer', from: 'demo-peer', body: 'the build is green', handback: true },+ turnOrigin: 'peer'+ })+ const scheduled = userStr('Scheduled check: run the demo report.', {+ isMeta: true,+ promptSource: 'system',+ turnOrigin: 'scheduled',+ scheduledTaskId: 'task-demo-1'+ })+ const autoCont = userStr('Continue from where you left off.', {+ isMeta: true,+ promptSource: 'system',+ origin: { kind: 'auto-continuation' }+ })+ const onlyTurnOrigin = userStr('turn origin only', { isMeta: true, turnOrigin: 'system' })+ const onlyOrigin = userStr('origin only', { isMeta: true, origin: { kind: 'peer' } })+ 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', () => {+ 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']+ ])+ })++ 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' }+ ])+ })+})++describe('command args are capped like tool args', () => {+ it('caps a slash command arg and a `!` command at 200 characters', () => {+ const long = 'a'.repeat(250)+ expect(parseChatMessages(cmdRec('/compact', long).split('\n'))[0].parts[0]).toMatchObject({ arg: 'a'.repeat(200) })+ expect(parseChatMessages(userStr(`<bash-input>${long}</bash-input>`).split('\n'))[0].parts[0]).toMatchObject({+ name: '!',+ arg: 'a'.repeat(200)+ })+ })+})diff --git a/src/core/transcript-reader.ts b/src/core/transcript-reader.tsindex 5e367d72b..dcdd50d22 100644--- a/src/core/transcript-reader.ts+++ b/src/core/transcript-reader.ts@@ -10,6 +10,7 @@ import { linkedClaudeConfigDirFor } from './claude-config-dir'import { platform } from './platform'import { toolBody } from './chat-tool-body'import { ASK_USER_QUESTION_TOOL, readQuestions } from '../shared/agents/permission-answer'+import { BASH_COMMAND_TOOL, CHAT_TOOL_ARG_MAX } from '../shared/chat-command'// Transcript root for a managed account (its `projects` dir) or the system default// (`~/.claude/projects` when accountId is undefined — bit-for-bit the old behavior). Impure@@ -48,10 +49,9 @@ function toolArg(input: unknown): string {if (!input || typeof input !== 'object') return ''const o = input as Record<string, unknown>const v = o.command ?? o.file_path ?? o.path ?? o.pattern ?? o.description ?? o.prompt- return typeof v === 'string' ? v.slice(0, 200) : ''+ return typeof v === 'string' ? v.slice(0, CHAT_TOOL_ARG_MAX) : ''}-// 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):@@ -109,16 +109,37 @@ function outputText(tags: Map<string, string>): string {.join('\n')}+/** A command's arg: trimmed, then capped like `toolArg` (the composer's `sentCommand` agrees). */+const capArg = (v: string | undefined): string => (v ?? '').trim().slice(0, CHAT_TOOL_ARG_MAX)++/**+ * claude's own meta records — the local-command caveat, skill bodies, injected reminders — are not+ * something the user said, and are skipped. But an `isMeta` record that STARTS a turn (a peer+ * hand-back, a scheduled / loop wakeup, an auto-continuation) says where that turn's prompt came+ * from, and hiding it leaves replies with no prompt between them. Measured: those carry+ * `promptSource` and/or `origin` / `turnOrigin` (present and not null); the hidden kinds carry none.+ * Measured too: no `isMeta` record carries a tool_result, so skipping one loses nothing.+ */+export function isHiddenMetaRecord(o: {+ type?: string+ isMeta?: unknown+ promptSource?: unknown+ origin?: unknown+ turnOrigin?: unknown+}): boolean {+ return o.type === 'user' && o.isMeta === true && o.promptSource == null && o.origin == null && o.turnOrigin == null+}+export function classifyLocalCommand(content: string): LocalCommandRecord | null {const tags = tagSequence(content)if (!tags) return nullif (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() }+ return { kind: 'command', family: 'slash', name, arg: capArg(tags.get('command-args')) }}if (onlyFrom(tags, BASH_INPUT_TAGS)) {- return { kind: 'command', family: 'bash', name: '!', arg: (tags.get('bash-input') ?? '').trim() }+ return { kind: 'command', family: 'bash', name: BASH_COMMAND_TOOL, arg: capArg(tags.get('bash-input')) }}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) }@@ -128,8 +149,9 @@ 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'+// Extract 0..n searchable lines from one raw transcript JSONL line.function linesFrom(raw: string): TranscriptLine[] {- let o: { type?: string; isMeta?: unknown; message?: { content?: unknown } }+ let o: Parameters<typeof isHiddenMetaRecord>[0] & { message?: { content?: unknown } }try {o = JSON.parse(raw)} catch {@@ -137,9 +159,8 @@ 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 []+ // Same rule as the chat parser (see `isHiddenMetaRecord`).+ if (isHiddenMetaRecord(o)) return []const content = o.message?.contentconst out: TranscriptLine[] = []if (o.type === 'assistant' && Array.isArray(content)) {@@ -279,9 +300,7 @@ function parseChatRecords(}for (const { raw, offset } of records) {if (!raw.trim()) continue- let o: {- type?: string- isMeta?: unknown+ let o: Parameters<typeof isHiddenMetaRecord>[0] & {timestamp?: unknowneffort?: unknownmessage?: { content?: unknown; model?: unknown }@@ -294,9 +313,7 @@ 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) continue+ if (isHiddenMetaRecord(o)) continueat = lineTime(o.timestamp)const content = o.message?.contentif (paged && o.type === 'assistant' && o.message?.model !== SYNTHETIC_MODEL) {diff --git a/src/renderer/lib/chatPaging.test.ts b/src/renderer/lib/chatPaging.test.tsindex d9812c706..8553a4a00 100644--- a/src/renderer/lib/chatPaging.test.ts+++ b/src/renderer/lib/chatPaging.test.ts@@ -147,6 +147,57 @@ describe('applyTail — unconfirmed optimistic sends (live reads)', () => {expect(texts(out)).toEqual(['x'])})+ // A slash command / `!` line is written by claude as a command record, which the transcript+ // reader renders as an assistant tool part (`name:"/model"` / `name:"!"`) — never as the typed text.+ const cmd = (key: number, name: string, arg = ''): ChatMessage => ({+ role: 'assistant',+ key,+ parts: [{ kind: 'tool', name, arg }]+ })+ const live = (sent: string, got: ChatMessage[]): ChatThread =>+ applyTail(base([say(0, 'q'), say(undefined, sent, 'user')], 0), ID, page([say(0, 'q'), ...got], 0), {+ carryUnconfirmed: true+ })+ const sentTexts = (t: ChatThread): string[] => t.messages.filter((m) => m.key === undefined).map((m) => (m.parts[0] as { text: string }).text)++ it('a sent slash command is confirmed by a later command tool part of the same name', () => {+ expect(sentTexts(live('/model', [cmd(100, '/model')]))).toEqual([])+ expect(sentTexts(live(' /model ', [cmd(100, '/model')]))).toEqual([])+ expect(sentTexts(live('/compact foo', [cmd(100, '/compact', 'foo')]))).toEqual([])+ // Args on only one side: the name is enough.+ expect(sentTexts(live('/compact foo bar ', [cmd(100, '/compact')]))).toEqual([])+ expect(sentTexts(live('/compact', [cmd(100, '/compact', 'x')]))).toEqual([])+ })++ it('a slash command is NOT confirmed by a different name, different args, or an older record', () => {+ expect(sentTexts(live('/model', [cmd(100, '/effort')]))).toEqual(['/model'])+ expect(sentTexts(live('/compact foo', [cmd(100, '/compact', 'bar')]))).toEqual(['/compact foo'])+ expect(sentTexts(live('/model', [say(100, '/model is a command')]))).toEqual(['/model'])+ // Only a command TOOL part confirms — an assistant text that reads exactly `/model` does not.+ expect(sentTexts(live('/model', [say(100, '/model')]))).toEqual(['/model'])+ // A command record the thread already had keyed must not confirm a new send of it.+ const t = base([cmd(100, '/model'), say(undefined, '/model', 'user')], 100)+ const out = applyTail(t, ID, page([cmd(100, '/model')], 100), { carryUnconfirmed: true })+ expect(sentTexts(out)).toEqual(['/model'])+ })++ it('matches one-for-one: one command record confirms one send', () => {+ const t = base([say(0, 'q'), say(undefined, '/model', 'user'), say(undefined, '/model', 'user')], 0)+ const out = applyTail(t, ID, page([say(0, 'q'), cmd(100, '/model')], 0), { carryUnconfirmed: true })+ expect(sentTexts(out)).toEqual(['/model'])+ })++ it('a `!` send is confirmed by a "!" tool part with the same command', () => {+ expect(sentTexts(live('!ls -la', [cmd(100, '!', 'ls -la')]))).toEqual([])+ expect(sentTexts(live('! ls', [cmd(100, '!', 'ls')]))).toEqual([])+ expect(sentTexts(live('!ls', [cmd(100, '!', 'pwd')]))).toEqual(['!ls'])+ })++ it('a long argument is compared after the same 200-character cap the reader applies', () => {+ const arg = 'x'.repeat(250)+ expect(sentTexts(live(`/compact ${arg}`, [cmd(100, '/compact', arg.slice(0, 200))]))).toEqual([])+ })+it('a NON-live reload (turn end, ↻) retires any unconfirmed carry', () => {const t = base([say(0, 'q'), say(undefined, 'never matches', 'user')], 0)const out = applyTail(t, ID, page([say(0, 'q'), say(100, 'transformed prompt', 'user')], 0))diff --git a/src/renderer/lib/chatPaging.ts b/src/renderer/lib/chatPaging.tsindex bbab4bc79..959386301 100644--- a/src/renderer/lib/chatPaging.ts+++ b/src/renderer/lib/chatPaging.ts@@ -1,4 +1,5 @@import type { ChatMessage, ChatPart, ChatTranscriptResult } from '@shared/types'+import { BASH_COMMAND_TOOL, sentCommand } from '@shared/chat-command'/*** Pure paging state for the ⌘M chat panel (`nodes/ChatPanel.tsx`). The panel reads a SMALL tail@@ -127,6 +128,14 @@ const userText = (m: ChatMessage): string =>.join('').trim()+/** A command message's tool part (`/model`, `!`), as the reader renders a command record. */+function commandPart(m: ChatMessage): { name: string; arg: string } | null {+ if (m.role !== 'assistant' || m.parts.length !== 1) return null+ const p = m.parts[0]+ if (p.kind !== 'tool' || (p.name !== BASH_COMMAND_TOOL && !p.name.startsWith('/'))) return null+ return { name: p.name, arg: p.arg.trim() }+}+/*** The optimistic "just sent" bubbles a LIVE tail read must not drop. A live read fires on the very* hook event the send caused (UserPromptSubmit), racing the agent's own transcript write — so the@@ -137,7 +146,9 @@ const userText = (m: ChatMessage): string =>* unkeyed; grok's thread is unkeyed throughout, but its whole-file read contains every prompt it* rendered, so each one is matched and dropped). Each one is dropped when the new read contains a user message with* the same trimmed text, ONE-FOR-ONE, and only among messages NEWER than anything the thread had- * keyed — an older identical "yes" already on screen must not confirm a new "yes".+ * keyed — an older identical "yes" already on screen must not confirm a new "yes". A sent slash+ * command / `!` line is confirmed the same way by a command tool part (`sentCommand`): same name,+ * and the same trimmed arg when both sides have one.** A non-live reload (turn end, ↻) never carries: by then the transcript holds the prompt, and a* send whose transcript line never matches (a CLI that rewrites the prompt) must not stay duplicated.@@ -152,13 +163,22 @@ function unconfirmedSends(t: ChatThread, res: ChatTranscriptResult): ChatMessageif (trailing.length === 0) return []let newest = -Infinityfor (const m of t.messages) if (m.key !== undefined && m.key > newest) newest = m.key- const available = res.messages- .filter((m) => m.role === 'user' && (m.key === undefined || m.key > newest))- .map(userText)+ const fresh = res.messages.filter((m) => m.key === undefined || m.key > newest)+ const available = fresh.filter((m) => m.role === 'user').map(userText)+ // A slash command / `!` line is recorded as a command, which the reader renders as an assistant+ // tool part — never as the typed text — so a send of one is confirmed by that part instead.+ const commands = fresh.map(commandPart).filter((c): c is { name: string; arg: string } => c !== null)return trailing.filter((m) => {const i = available.indexOf(userText(m))- if (i < 0) return true- available.splice(i, 1)+ if (i >= 0) {+ available.splice(i, 1)+ return false+ }+ const sent = sentCommand(userText(m))+ if (!sent) return true+ const j = commands.findIndex((c) => c.name === sent.name && (!c.arg || !sent.arg || c.arg === sent.arg))+ if (j < 0) return true+ commands.splice(j, 1)return false})}diff --git a/src/shared/chat-command.ts b/src/shared/chat-command.tsnew file mode 100644index 000000000..978fca0bb--- /dev/null+++ b/src/shared/chat-command.ts@@ -0,0 +1,24 @@+// Shared between the transcript reader (core) and the ⌘M thread (renderer): how a slash command or+// a `!` bash-mode line appears in the chat. claude writes both as command RECORDS, not as the typed+// text, and the reader renders them as an assistant tool part (`name:"/model"` / `name:"!"`). The+// composer's optimistic bubble holds the TYPED text, so confirming it needs the same mapping.++/** The longest tool-part `arg` the reader emits (tool calls and local commands alike), in UTF-16+ * code units (`String.prototype.slice`). */+export const CHAT_TOOL_ARG_MAX = 200++/** The tool-part name the reader gives a `!` bash-mode command. */+export const BASH_COMMAND_TOOL = '!'++/**+ * The command a SENT text would become, or null when it is not one: `/name args` → `{name:"/name",+ * arg}`, `!cmd` → `{name:"!", arg:"cmd"}`. Text is trimmed first (JS `trim`); `arg` is trimmed and+ * capped exactly as the reader caps it, so the two compare equal.+ */+export function sentCommand(text: string): { name: string; arg: string } | null {+ const t = text.trim()+ if (t.startsWith('!')) return { name: BASH_COMMAND_TOOL, arg: t.slice(1).trim().slice(0, CHAT_TOOL_ARG_MAX) }+ const m = /^(\/\S+)(?:\s+([\s\S]*))?$/.exec(t)+ if (!m) return null+ return { name: m[1], arg: (m[2] ?? '').trim().slice(0, CHAT_TOOL_ARG_MAX) }+}diff --git a/src/shared/chat-fixtures/README.md b/src/shared/chat-fixtures/README.mdindex 246afc61a..063822cae 100644--- a/src/shared/chat-fixtures/README.md+++ b/src/shared/chat-fixtures/README.md@@ -82,8 +82,9 @@ 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). |+| `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"`) and a `promptSource`-only record stay user messages; the caveat and a skill body (none of the three fields) are skipped. |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@@ -113,7 +114,12 @@ parses, and the cap is applied by `buildPermissionDecision` (`plan-revise-too-lo`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).+1. A `type:"user"` record with `isMeta === true` is skipped entirely (no message, no `at` effect)+ **only when it carries none of `promptSource`, `origin`, `turnOrigin`** (each counts when the key+ 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).2. Only a user record whose `message.content` is a **string** is examined. It must consist ONLY ofwhole tags `<t>…</t>` (`t` matches `[a-z-]+`; content non-greedy up to the matching close tag), separated by whitespace (JS `\s`), eachtag name at most once. Anything else in it (prose, an unknown tag, a repeated tag) makes it an@@ -121,7 +127,10 @@ on the paged and unpaged paths alike:3. Tags only from {`command-name`, `command-message`, `command-args`}, any order, with a non-blanktrimmed `command-name` → **command**: an assistant message with one part`{kind:"tool", name:<command-name trimmed>, arg:<command-args trimmed, "" when absent>}`.+ Slash tags with a blank or missing `command-name` are ordinary user text.Tags only from {`bash-input`} → command with `name:"!"`, `arg:<bash-input trimmed>`.+ `arg` is capped like a tool call's arg (`toolArg`): trimmed FIRST, then its first 200 UTF-16+ units (`CHAT_TOOL_ARG_MAX`, `String.prototype.slice(0, 200)`).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, inrecord order, with ANSI escapes removed (`\x1b[` CSI `[0-?]*[ -/]*[@-~]`, then OSC@@ -131,8 +140,15 @@ on the paged and unpaged paths alike:5. A non-empty output sets `result` on the command's tool part when the **last pushed message** isa command of the **same family** that has no result yet. Otherwise it is pushed as its ownassistant 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+ ends the wait, and so does an attached output (a second output does not overwrite). A record+ that pushes nothing does NOT end it: a skipped `isMeta` record, an empty output, a metadata-only+ record, a thinking-only assistant record or a tool_result-only user record.+6. "Trimmed" everywhere in these rules means JS `String.prototype.trim`, which strips JS `\s`:+ ASCII whitespace plus U+00A0, U+FEFF, U+1680, U+2000–U+200A, U+2028, U+2029, U+202F, U+205F and+ U+3000. Swift's `.whitespacesAndNewlines` is a different set (it lacks U+FEFF and adds U+0085, for+ example), so the port needs its own predicate. The same set is the "whitespace between tags" of+ rule 2.+7. A command message carries `key` / `at` like any other message; an attached output changesneither. No new role, part kind or field: a v1 decoder reads these as ordinary tool parts.## Sizesdiff --git a/src/shared/chat-fixtures/expected/local-commands.pages.json b/src/shared/chat-fixtures/expected/local-commands.pages.jsonindex 3f43030df..59f3d21cb 100644--- a/src/shared/chat-fixtures/expected/local-commands.pages.json+++ b/src/shared/chat-fixtures/expected/local-commands.pages.json@@ -48,13 +48,25 @@"parts": [{"kind": "tool",- "name": "/exit",- "arg": ""+ "name": "/compact",+ "arg": "keep the demo demo demo demo demo demo demo demo demo demo demo demo demo demo demo demo demo demo demo demo demo demo demo demo demo demo demo demo demo demo demo demo demo demo demo demo demo demo d"}],"at": 1790362807000,"key": 2796},+ {+ "role": "assistant",+ "parts": [+ {+ "kind": "tool",+ "name": "/exit",+ "arg": ""+ }+ ],+ "at": 1790362808000,+ "key": 3497+ },{"role": "assistant","parts": [@@ -64,8 +76,8 @@"arg": ""}],- "at": 1790362809000,- "key": 3469+ "at": 1790362810000,+ "key": 4170},{"role": "assistant",@@ -75,8 +87,8 @@"text": "Using the skill."}],- "at": 1790362811000,- "key": 4151+ "at": 1790362812000,+ "key": 4852},{"role": "assistant",@@ -88,8 +100,8 @@"result": "Orphaned output second line third line"}],- "at": 1790362812000,- "key": 4550+ "at": 1790362813000,+ "key": 5251},{"role": "user",@@ -99,8 +111,8 @@"text": "Why does <command-name>/model</command-name> show up raw in the thread?"}],- "at": 1790362813000,- "key": 4901+ "at": 1790362814000,+ "key": 5602},{"role": "assistant",@@ -110,8 +122,8 @@"text": "Because it was a local command record."}],- "at": 1790362814000,- "key": 5221+ "at": 1790362815000,+ "key": 5922}],"olderCursor": null,diff --git a/src/shared/chat-fixtures/expected/meta-turns.pages.json b/src/shared/chat-fixtures/expected/meta-turns.pages.jsonnew file mode 100644index 000000000..57b644597--- /dev/null+++ b/src/shared/chat-fixtures/expected/meta-turns.pages.json@@ -0,0 +1,116 @@+[+ {+ "before": null,+ "maxBytes": 262144,+ "grownMaxBytes": 262144,+ "start": 0,+ "parse": {+ "messages": [+ {+ "role": "user",+ "parts": [+ {+ "kind": "text",+ "text": "Keep an eye on the demo build."+ }+ ],+ "at": 1790362800000,+ "key": 0+ },+ {+ "role": "user",+ "parts": [+ {+ "kind": "text",+ "text": "Hand-back from demo-peer: the demo build is green."+ }+ ],+ "at": 1790362802000,+ "key": 787+ },+ {+ "role": "assistant",+ "parts": [+ {+ "kind": "text",+ "text": "Noted: green."+ }+ ],+ "at": 1790362803000,+ "key": 1266+ },+ {+ "role": "user",+ "parts": [+ {+ "kind": "text",+ "text": "Scheduled wakeup: check the demo build again."+ }+ ],+ "at": 1790362804000,+ "key": 1662+ },+ {+ "role": "assistant",+ "parts": [+ {+ "kind": "text",+ "text": "Still green."+ }+ ],+ "at": 1790362805000,+ "key": 2052+ },+ {+ "role": "user",+ "parts": [+ {+ "kind": "text",+ "text": "Continue from where you left off."+ }+ ],+ "at": 1790362806000,+ "key": 2447+ },+ {+ "role": "assistant",+ "parts": [+ {+ "kind": "text",+ "text": "Continuing."+ }+ ],+ "at": 1790362807000,+ "key": 2805+ },+ {+ "role": "user",+ "parts": [+ {+ "kind": "text",+ "text": "System prompt source only."+ }+ ],+ "at": 1790362808000,+ "key": 3199+ },+ {+ "role": "assistant",+ "parts": [+ {+ "kind": "text",+ "text": "Seen."+ }+ ],+ "at": 1790362809000,+ "key": 3512+ }+ ],+ "olderCursor": null,+ "unmatchedResults": [],+ "model": "claude-opus-5-5",+ "effort": "high",+ "noCompleteLine": false+ }+ }+]diff --git a/src/shared/chat-fixtures/inputs/local-commands.jsonl b/src/shared/chat-fixtures/inputs/local-commands.jsonlindex 9423c90e9..034f3449f 100644--- a/src/shared/chat-fixtures/inputs/local-commands.jsonl+++ b/src/shared/chat-fixtures/inputs/local-commands.jsonl@@ -5,11 +5,12 @@{"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"}+{"type":"user","message":{"role":"user","content":"<command-name>/compact</command-name>\n <command-message>compact</command-message>\n <command-args> keep the demo demo demo demo demo demo demo demo demo demo demo demo demo demo demo demo demo demo demo demo demo demo demo demo demo demo demo demo demo demo demo demo demo demo demo demo demo demo demo demo demo demo demo demo demo demo demo demo demo demo demo demo demo demo demo demo demo demo demo demo notes </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":"<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-000000000008","timestamp":"2026-09-25T19:00:08.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-000000000009","timestamp":"2026-09-25T19:00:09.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-000000000010","timestamp":"2026-09-25T19:00:10.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-000000000011","timestamp":"2026-09-25T19:00:11.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-000000000012","timestamp":"2026-09-25T19:00:12.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-000000000013","timestamp":"2026-09-25T19:00:13.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-000000000014","timestamp":"2026-09-25T19:00:14.000Z"}+{"type":"assistant","effort":"high","message":{"id":"msg_synthetic","type":"message","role":"assistant","model":"claude-opus-5-5","content":[{"type":"text","text":"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-000000000015","timestamp":"2026-09-25T19:00:15.000Z"}diff --git a/src/shared/chat-fixtures/inputs/meta-turns.jsonl b/src/shared/chat-fixtures/inputs/meta-turns.jsonlnew file mode 100644index 000000000..8cebef7ef--- /dev/null+++ b/src/shared/chat-fixtures/inputs/meta-turns.jsonl@@ -0,0 +1,11 @@+{"type":"user","message":{"role":"user","content":"Keep an eye on the demo build."},"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":"Hand-back from demo-peer: the demo build is green."},"isMeta":true,"promptSource":"system","origin":{"kind":"peer","from":"demo-peer","senderTaskId":"task-demo-7","body":"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-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":"Noted: green."}],"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":"Scheduled wakeup: check the demo build again."},"isMeta":true,"promptSource":"system","turnOrigin":"scheduled","scheduledTaskId":"sched-demo-1","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":"Still green."}],"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":"Continue from where you left off."},"isMeta":true,"promptSource":"system","origin":{"kind":"auto-continuation"},"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":"Continuing."}],"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"}+{"type":"user","message":{"role":"user","content":"System prompt source only."},"isMeta":true,"promptSource":"system","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":"Seen."}],"stop_reason":null},"isSidechain":false,"sessionId":"5f0c2a9e-3b7d-4e61-9a24-7c1d8e0f4b32","cwd":"/srv/demo","version":"2.1.290","uuid":"00000000-0000-4000-8000-000000000009","timestamp":"2026-09-25T19:00:09.000Z"}+{"type":"user","message":{"role":"user","content":[{"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"}