moi-computer 0.6.1-next.0 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/format.ts CHANGED
@@ -58,13 +58,27 @@ export type Part =
58
58
  | { type: 'source-document'; mediaType: string; title: string; sourceId: string }
59
59
  | { type: 'data'; name: string; data: unknown }
60
60
 
61
+ // Why a synthetic turn exists. Set by adapters — from the backend's own
62
+ // synthetic flag or from lib/system-messages.ts text classification. The UI
63
+ // hides every synthetic turn; the reason is kept for debugging and future
64
+ // "show system messages" affordances.
65
+ export type SyntheticTurnReason =
66
+ | 'skill-body'
67
+ | 'system-reminder'
68
+ | 'hook-output'
69
+ | 'slash-command'
70
+ | 'interrupt'
71
+ | 'other'
72
+
61
73
  export type TurnOrigin =
62
74
  | { kind: 'user-input' }
63
75
  | { kind: 'tool-return'; toolCallId: string }
64
- | {
65
- kind: 'synthetic'
66
- reason: 'skill-body' | 'system-reminder' | 'hook-output' | 'slash-command' | 'other'
67
- }
76
+ | { kind: 'synthetic'; reason: SyntheticTurnReason }
77
+ // A backend notification (e.g. a background-task completion) rewritten to
78
+ // readable text by lib/system-messages.ts. Rendered as plain text in the
79
+ // flow for now — a dedicated notification block is planned; key it off
80
+ // this origin.
81
+ | { kind: 'notification' }
68
82
  | { kind: 'subagent-prompt'; parentToolCallId: string }
69
83
  | { kind: 'inter-session' }
70
84
  | { kind: 'replay' }
@@ -0,0 +1,241 @@
1
+ // Provider-agnostic filtering of system machinery that agent backends leave
2
+ // in user-role message text: slash-command records, interrupt markers, local
3
+ // command output, injected reminder/hook envelopes. Chat bubbles must show
4
+ // only what a person actually typed; everything else is transcript plumbing
5
+ // the backend wrote for itself.
6
+ //
7
+ // The layer is a flat rule registry over plain text — it knows nothing about
8
+ // any harness's wire types, so every adapter (and the client, if it ever
9
+ // needs to) can share it. Two granularities:
10
+ //
11
+ // - `filterSystemText` one text block → cleaned text ('' when the whole
12
+ // block is machinery)
13
+ // - `classifySystemMessage` all of a message's text blocks → a synthetic-turn
14
+ // reason when the message as a whole is machinery
15
+ //
16
+ // Adapters keep a hide-classified message's raw text and mark the turn
17
+ // `origin: { kind: 'synthetic', reason }` — the same treatment the Claude SDK's
18
+ // own `isSynthetic` injections get — so nothing renders but nothing is lost.
19
+ // A `notify`-classified message instead SURFACES: its machinery is rewritten
20
+ // to a short readable sentence and the turn lands as
21
+ // `origin: { kind: 'notification' }`, plain text in the flow (a dedicated
22
+ // notification block in the UI is planned; the origin is its hook).
23
+ //
24
+ // Adding rules: append to SYSTEM_TEXT_RULES with a `<provider>:<what>` id.
25
+ // Registry order is priority — the first matching hide/notify rule decides the
26
+ // block. `hide`/`notify` patterns must match the WHOLE block (`^…$`), and
27
+ // tag-shaped ones require every element complete (open + close), so a person
28
+ // typing a tag name, pasting an unterminated fragment, or quoting a record
29
+ // with commentary around it keeps their bubble. Prose-anchored rules (the
30
+ // caveat, the compaction summary) are prefix matches by necessity — the
31
+ // accepted tradeoff is that pasting that exact sentence at position 0 hides
32
+ // the message. Keep `hide`/`notify` regexes non-global (`.test` on a /g
33
+ // regex is stateful) and `strip` regexes global.
34
+ //
35
+ // Current rules cover Claude Code. Sources: the patterns were verified against
36
+ // the `claude` CLI binary's strings and live `~/.claude/projects/*.jsonl`
37
+ // transcripts (see harness/claude-code/NOTES.md §4). OpenClaw's inbound-meta
38
+ // stripper stays in server/harness/openclaw/strip.ts — it mirrors upstream
39
+ // code verbatim and is synced against it, so it does not fold into this
40
+ // registry.
41
+ import type { SyntheticTurnReason } from './format'
42
+
43
+ export type SystemTextRule = {
44
+ // Stable `<provider>:<what>` id, for tests and debugging.
45
+ id: string
46
+ // The synthetic-turn reason a consumed match maps onto (lib/format.ts).
47
+ reason: SyntheticTurnReason
48
+ } &
49
+ // The whole text block is machinery when `test` matches.
50
+ (
51
+ | { action: 'hide'; test: RegExp }
52
+ // Machinery embedded in otherwise-real text: remove every `pattern` match,
53
+ // keep the rest. A block left empty counts as fully consumed.
54
+ | { action: 'strip'; pattern: RegExp }
55
+ // The whole block is machinery worth SHOWING: `render` turns the raw
56
+ // payload into a short readable sentence for the chat flow.
57
+ | { action: 'notify'; test: RegExp; render: (text: string) => string }
58
+ )
59
+
60
+ function xmlField(text: string, tag: string): string | undefined {
61
+ const m = text.match(new RegExp(`<${tag}>([\\s\\S]*?)</${tag}>`))
62
+ return m?.[1].trim() || undefined
63
+ }
64
+
65
+ // `<summary>` is already a human sentence ("Background command "…" completed
66
+ // (exit code 0)"); fall back to `<status>` (completed | failed | stopped)
67
+ // when a producer omits it.
68
+ function renderTaskNotification(text: string): string {
69
+ const summary = xmlField(text, 'summary')
70
+ if (summary) return summary
71
+ const status = xmlField(text, 'status')
72
+ return status ? `Background task ${status}` : 'Background task update'
73
+ }
74
+
75
+ export const SYSTEM_TEXT_RULES: readonly SystemTextRule[] = [
76
+ // -- Claude Code: whole-message records ------------------------------------
77
+ // Slash-command invocation, e.g. `<command-name>/clear</command-name>
78
+ // <command-message>clear</command-message><command-args></command-args>`.
79
+ // Tag order varies across CLI versions; `<command-contents>` carries older
80
+ // expanded-command payloads. The block must be NOTHING BUT complete
81
+ // `<command-*>…</command-*>` elements — a typed message that merely starts
82
+ // with the tag name, or a pasted record followed by a question, keeps its
83
+ // bubble.
84
+ {
85
+ id: 'claude-code:slash-command',
86
+ reason: 'slash-command',
87
+ action: 'hide',
88
+ test: /^\s*(<command-(name|message|args|contents)>[\s\S]*?<\/command-\2>\s*)+$/
89
+ },
90
+ // Output of a local slash command, e.g. `<local-command-stdout>Compacted.
91
+ // ...</local-command-stdout>` — the other half of the invocation record.
92
+ {
93
+ id: 'claude-code:local-command-output',
94
+ reason: 'slash-command',
95
+ action: 'hide',
96
+ test: /^\s*(<local-command-(stdout|stderr)>[\s\S]*?<\/local-command-\2>\s*)+$/
97
+ },
98
+ // Marker the CLI writes when the user aborts a turn (Esc / moi's stop).
99
+ // Full-block match only: someone quoting the marker inside a longer
100
+ // message keeps their bubble.
101
+ {
102
+ id: 'claude-code:interrupt',
103
+ reason: 'interrupt',
104
+ action: 'hide',
105
+ test: /^\s*\[Request interrupted by user( for tool use)?\]\s*$/
106
+ },
107
+ // `!command` bash mode: the input echo and its captured output
108
+ // (`<bash-stdout>…</bash-stdout><bash-stderr>…</bash-stderr>` ride in one
109
+ // message).
110
+ {
111
+ id: 'claude-code:bash-mode',
112
+ reason: 'other',
113
+ action: 'hide',
114
+ test: /^\s*(<bash-(input|stdout|stderr)>[\s\S]*?<\/bash-\2>\s*)+$/
115
+ },
116
+ // `#note` memory mode.
117
+ {
118
+ id: 'claude-code:memory-input',
119
+ reason: 'other',
120
+ action: 'hide',
121
+ test: /^\s*<user-memory-input>[\s\S]*?<\/user-memory-input>\s*$/
122
+ },
123
+ // Background-task completion notices delivered as user turns — surfaced
124
+ // as readable text rather than hidden. Local CC is the bare tag block;
125
+ // cloud harnesses prepend a NOT-USER-INPUT preamble. The test requires a
126
+ // COMPLETE `<task-notification>…</task-notification>` message: a person
127
+ // typing the tag name (or an unterminated fragment) keeps their bubble.
128
+ {
129
+ id: 'claude-code:task-notification',
130
+ reason: 'other',
131
+ action: 'notify',
132
+ test: /^\s*(\[SYSTEM NOTIFICATION - NOT USER INPUT\][\s\S]*)?<task-notification>[\s\S]*<\/task-notification>\s*$/,
133
+ render: renderTaskNotification
134
+ },
135
+ // Preamble injected before replayed local-command messages. `isMeta` in
136
+ // current CLI versions (so usually pre-hidden), but older transcripts
137
+ // carry it unflagged.
138
+ {
139
+ id: 'claude-code:local-command-caveat',
140
+ reason: 'other',
141
+ action: 'hide',
142
+ test: /^\s*Caveat: The messages below were generated by the user while running local commands\./
143
+ },
144
+ // Post-compaction continuation summary. Wording after the first sentence
145
+ // differs across CLI versions; the anchor sentence is stable.
146
+ {
147
+ id: 'claude-code:compact-continuation',
148
+ reason: 'other',
149
+ action: 'hide',
150
+ test: /^\s*This session is being continued from a previous conversation that ran out of context\./
151
+ },
152
+ // -- Claude Code: envelopes embedded in real messages ----------------------
153
+ // Ambient context reminders attached to (or around) typed text. moi's own
154
+ // envelope is stripped more precisely by lib/moi-context.ts before this
155
+ // rule sees the text; this catches every other reminder.
156
+ {
157
+ id: 'claude-code:system-reminder',
158
+ reason: 'system-reminder',
159
+ action: 'strip',
160
+ pattern: /<system-reminder>[\s\S]*?<\/system-reminder>\s*/g
161
+ },
162
+ // UserPromptSubmit hook stdout, appended to the message it ran for.
163
+ {
164
+ id: 'claude-code:prompt-submit-hook',
165
+ reason: 'hook-output',
166
+ action: 'strip',
167
+ pattern: /<user-prompt-submit-hook>[\s\S]*?<\/user-prompt-submit-hook>\s*/g
168
+ }
169
+ ]
170
+
171
+ export type SystemTextFilter = {
172
+ // What remains for display — '' when the block was entirely machinery,
173
+ // the readable rendering when a `notify` rule consumed it.
174
+ text: string
175
+ // Rules that consumed the block or stripped something from it, in
176
+ // application order (first entry names the dominant reason; its `action`
177
+ // says whether the block was hidden, rewritten, or partially stripped).
178
+ matched: SystemTextRule[]
179
+ }
180
+
181
+ export function filterSystemText(
182
+ text: string,
183
+ rules: readonly SystemTextRule[] = SYSTEM_TEXT_RULES
184
+ ): SystemTextFilter {
185
+ for (const rule of rules) {
186
+ if (rule.action === 'hide' && rule.test.test(text)) return { text: '', matched: [rule] }
187
+ if (rule.action === 'notify' && rule.test.test(text)) {
188
+ return { text: rule.render(text), matched: [rule] }
189
+ }
190
+ }
191
+ let out = text
192
+ const matched: SystemTextRule[] = []
193
+ for (const rule of rules) {
194
+ if (rule.action !== 'strip') continue
195
+ const next = out.replace(rule.pattern, '')
196
+ if (next !== out) {
197
+ matched.push(rule)
198
+ out = next
199
+ }
200
+ }
201
+ // Only a touched block gets its edges trimmed — untouched user text keeps
202
+ // its exact spacing.
203
+ return { text: matched.length > 0 ? out.trim() : out, matched }
204
+ }
205
+
206
+ export type SystemMessageVerdict =
207
+ // Transcript plumbing: keep the raw parts, mark the turn synthetic, hide.
208
+ | { kind: 'hide'; reason: SyntheticTurnReason; rules: SystemTextRule[] }
209
+ // A backend notification: show `text` as an `origin: 'notification'` turn.
210
+ | { kind: 'notification'; text: string; rules: SystemTextRule[] }
211
+
212
+ /**
213
+ * Decide whether a message is, in aggregate, all machinery: every text block
214
+ * either matched a hide/notify rule or was stripped down to nothing, and at
215
+ * least one rule fired. Blocks that were already blank neither veto nor
216
+ * count. Any notify match makes the whole message a notification (its
217
+ * rendered texts joined); real surviving text makes it a normal message.
218
+ */
219
+ export function classifySystemMessage(
220
+ texts: readonly string[],
221
+ rules: readonly SystemTextRule[] = SYSTEM_TEXT_RULES
222
+ ): SystemMessageVerdict | undefined {
223
+ const matched: SystemTextRule[] = []
224
+ const rendered: string[] = []
225
+ for (const text of texts) {
226
+ const f = filterSystemText(text, rules)
227
+ if (f.matched[0]?.action === 'notify') {
228
+ if (f.text.trim()) rendered.push(f.text)
229
+ matched.push(...f.matched)
230
+ continue
231
+ }
232
+ if (f.text.trim() !== '') return undefined
233
+ matched.push(...f.matched)
234
+ }
235
+ if (rendered.length > 0) {
236
+ return { kind: 'notification', text: rendered.join('\n\n'), rules: matched }
237
+ }
238
+ return matched.length > 0
239
+ ? { kind: 'hide', reason: matched[0].reason, rules: matched }
240
+ : undefined
241
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "moi-computer",
3
- "version": "0.6.1-next.0",
3
+ "version": "0.7.0",
4
4
  "description": "Local AI workspace powered by the Claude Agent SDK, Bun, React, and Tailwind. Requires Bun.",
5
5
  "license": "Elastic-2.0",
6
6
  "type": "module",
@@ -30,6 +30,17 @@ Rules: **adapters are the only code that sees layer 1** — everything above
30
30
  speaks layers 2/3 only. `lib/format.ts` and `lib/types.ts` never move into
31
31
  this folder: the client imports them; they are the shared contract.
32
32
 
33
+ System machinery that backends leave in user-role text (slash-command
34
+ records, interrupt markers, injected reminder envelopes) is classified by
35
+ the shared rule registry in `lib/system-messages.ts` — provider-agnostic,
36
+ text-level. Adapters call it when building user turns: an all-machinery
37
+ message keeps its raw parts but lands as `origin: synthetic` (hidden by the
38
+ client), embedded envelopes strip out of real text, and notify-classified
39
+ messages (background-task notices) are rewritten to a readable sentence and
40
+ surface as `origin: notification` turns. Add new patterns there, not as
41
+ ad-hoc regexes in an adapter. (Exception: OpenClaw's inbound-meta stripper
42
+ mirrors upstream code verbatim and stays in `openclaw/strip.ts`.)
43
+
33
44
  Socket-protocol notes the layers rely on (all defined in `lib/types.ts`):
34
45
 
35
46
  - **`session_renamed`** — a new thread is created under the client's temporary
@@ -135,13 +135,14 @@ Of these the repo currently handles only `tool_result`.
135
135
 
136
136
  At the SDK wire level, **every tool result and every harness-injected prompt is a `user` message**, because Anthropic's Messages API has no dedicated role for them. Classify by content and flags, in this priority order:
137
137
 
138
- | # | Condition | What it really is | UI behavior |
139
- | --- | -------------------------------------------------------------- | ------------------------------------------------------------------------------------------------ | -------------------------------------------------------------------------------------------- |
140
- | 1 | `isReplay: true` | Replay from a resumed session; not new content | Skip (or render only once from the persisted log) |
141
- | 2 | `content[]` contains a `tool_result` block | Tool return back to the model | Route into the paired tool-use card; may carry extra metadata in top-level `tool_use_result` |
142
- | 3 | `isSynthetic: true` | Harness-injected context (skill body, slash-command expansion, `<system-reminder>`, hook output) | Transcript-only context; hide by default, expose behind a toggle |
143
- | 4 | `parent_tool_use_id !== null` AND first user turn of a subtask | The `Agent` tool's `prompt` argument being replayed as the subtask's opening user turn | Render as the subtask's prompt inside the nested view, not in the main thread |
144
- | 5 | none of the above | Actual user input typed into the chat | Render as the user bubble |
138
+ | # | Condition | What it really is | UI behavior |
139
+ | --- | -------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------- |
140
+ | 1 | `isReplay: true` | Replay from a resumed session; not new content | Skip (or render only once from the persisted log) |
141
+ | 2 | `content[]` contains a `tool_result` block | Tool return back to the model | Route into the paired tool-use card; may carry extra metadata in top-level `tool_use_result` |
142
+ | 3 | `isSynthetic: true` | Harness-injected context (skill body, slash-command expansion, `<system-reminder>`, hook output) | Transcript-only context; hide by default, expose behind a toggle |
143
+ | 4 | Text matches a `lib/system-messages.ts` rule (all blocks) | CLI machinery written **without** flags: slash-command records, `[Request interrupted by user]`, `<local-command-stdout>`, bash-mode I/O, compact continuations, task notifications, … | Hide rules: as #3 — keep raw parts, mark `origin: synthetic`. Notify rules (task notifications): rewrite to readable text, `origin: notification`, shown |
144
+ | 5 | `parent_tool_use_id !== null` AND first user turn of a subtask | The `Agent` tool's `prompt` argument being replayed as the subtask's opening user turn | Render as the subtask's prompt inside the nested view, not in the main thread |
145
+ | 6 | none of the above | Actual user input typed into the chat | Render as the user bubble (embedded `<system-reminder>`/hook envelopes strip out first) |
145
146
 
146
147
  ### On `isSynthetic` specifically — the docs don't say, the source does
147
148
 
@@ -156,6 +157,20 @@ So `isSynthetic = true` means: _this user turn was fabricated by the harness and
156
157
 
157
158
  `isSynthetic` and `parent_tool_use_id` are **orthogonal**. A sub-agent's initial prompt (observed on line 14 of the captured log) has `parent_tool_use_id` set but `isSynthetic` absent — from the subagent's frame, that IS real user input.
158
159
 
160
+ ### Machinery the CLI does NOT flag (row #4)
161
+
162
+ Several user entries the CLI writes for itself carry **no** `isMeta`/`isSynthetic`, so they'd render as user bubbles without text classification. Inventory (verified against the CLI binary's strings and live transcripts; the rules live in `lib/system-messages.ts`):
163
+
164
+ - `<command-name>/<command-message>/<command-args>` (+ legacy `<command-contents>`) — slash-command invocation records
165
+ - `<local-command-stdout>` / `<local-command-stderr>` — local command output
166
+ - `[Request interrupted by user]` / `[Request interrupted by user for tool use]` — abort markers; the tool-use variant rides next to the aborted `tool_result` block
167
+ - `<bash-input>` / `<bash-stdout>` / `<bash-stderr>` — `!command` bash mode
168
+ - `<user-memory-input>` — `#note` memory mode
169
+ - `<task-notification>` (and the cloud `[SYSTEM NOTIFICATION - NOT USER INPUT]` preamble) — background-task notices; these are the one machinery kind that SURFACES: the rule rewrites the block to its `<summary>` text and the turn lands as `origin: notification` (plain text in the flow for now, a dedicated UI block later)
170
+ - `Caveat: The messages below were generated by the user while running local commands.` — `isMeta` in current CLIs, unflagged in older transcripts
171
+ - `This session is being continued from a previous conversation that ran out of context.` — post-compaction continuation summary
172
+ - `<system-reminder>` / `<user-prompt-submit-hook>` — envelopes attached to real messages; stripped from the text rather than hiding the turn
173
+
159
174
  ---
160
175
 
161
176
  ## 5. Sub-agent invocation — the nesting mechanism
@@ -6,6 +6,7 @@ import type {
6
6
  SessionSnapshot,
7
7
  StreamEvent,
8
8
  SubagentRecord,
9
+ SyntheticTurnReason,
9
10
  SystemNotice,
10
11
  ToolCall,
11
12
  ToolCaller,
@@ -16,6 +17,7 @@ import type {
16
17
 
17
18
  import { isAttachmentOnlyPlaceholder, splitAttachmentNote } from '@/lib/attachment-note'
18
19
  import { stripMoiContext } from '@/lib/moi-context'
20
+ import { classifySystemMessage, filterSystemText } from '@/lib/system-messages'
19
21
 
20
22
  // Loose SDK message shape — we don't pull in the full SDK type tree; the
21
23
  // adapter tolerates missing fields. Reference: ./NOTES.md.
@@ -154,9 +156,9 @@ function callerFromBlockType(type: string, name: string): ToolCaller {
154
156
  return 'model'
155
157
  }
156
158
 
157
- function classifySyntheticReason(
158
- firstText: string
159
- ): Exclude<Extract<TurnOrigin, { kind: 'synthetic' }>['reason'], never> {
159
+ function classifySyntheticReason(firstText: string): SyntheticTurnReason {
160
+ const verdict = classifySystemMessage([firstText])
161
+ if (verdict?.kind === 'hide') return verdict.reason
160
162
  if (/<system-reminder>/i.test(firstText)) return 'system-reminder'
161
163
  return 'other'
162
164
  }
@@ -509,19 +511,49 @@ export class ClaudeAdapter {
509
511
  const parts: Part[] = []
510
512
  let firstText = ''
511
513
 
514
+ // A user message whose text is entirely backend machinery (see
515
+ // lib/system-messages.ts). Two fates: hide-classified messages — a
516
+ // slash-command record, an interrupt marker — keep their raw parts but
517
+ // land as synthetic turns, hidden exactly like the SDK's own isSynthetic
518
+ // injections; notify-classified messages (task notifications) surface as
519
+ // readable text below. Computed for isSynthetic entries too — local CC
520
+ // flags task notifications isMeta, and those must still surface. Replays
521
+ // stay untouched so their persisted-log counterpart renders once.
522
+ // Text-only messages qualify; real content (attachments, images) vetoes.
523
+ const systemVerdict =
524
+ msg.type === 'user' && !msg.isReplay && blocks.every(b => b.type === 'text')
525
+ ? classifySystemMessage(blocks.map(b => b.text ?? ''))
526
+ : undefined
527
+
528
+ // A notification renders as plain text in the flow: none of the bubble
529
+ // machinery (attachment notes, echo matching, skill stashing) applies.
530
+ if (systemVerdict?.kind === 'notification') {
531
+ return {
532
+ id: turnId(msg),
533
+ role: 'user',
534
+ origin: { kind: 'notification' },
535
+ parentTaskId: msg.parent_tool_use_id ?? undefined,
536
+ parts: [{ type: 'text', text: systemVerdict.text }],
537
+ timestamp: msg.timestamp
538
+ }
539
+ }
540
+
512
541
  for (const b of blocks) {
513
542
  switch (b.type) {
514
543
  case 'text':
515
544
  if (b.text) {
516
545
  let text = b.text
517
- if (msg.type === 'user' && !msg.isSynthetic) {
546
+ if (msg.type === 'user' && !msg.isSynthetic && !systemVerdict) {
518
547
  // Non-image attachments reach the agent as a temp-path note
519
548
  // appended to the user's text (see lib/attachment-note.ts). The
520
549
  // SDK persists that appended text, so fold the note back into
521
550
  // file chips here — a reloaded bubble matches the live one
522
551
  // instead of leaking temp paths into it.
523
552
  const split = splitAttachmentNote(text)
524
- text = stripMoiContext(split.text)
553
+ // moi's own context envelope strips precisely (marker-guarded);
554
+ // other embedded machinery — system reminders, hook output —
555
+ // strips by the shared rules, keeping the typed text.
556
+ text = filterSystemText(stripMoiContext(split.text)).text
525
557
  for (const f of split.files) {
526
558
  parts.push({
527
559
  type: 'file',
@@ -604,6 +636,8 @@ export class ClaudeAdapter {
604
636
  origin = { kind: 'replay' }
605
637
  } else if (msg.isSynthetic) {
606
638
  origin = { kind: 'synthetic', reason: classifySyntheticReason(firstText) }
639
+ } else if (systemVerdict) {
640
+ origin = { kind: 'synthetic', reason: systemVerdict.reason }
607
641
  } else if (msg.parent_tool_use_id) {
608
642
  origin = { kind: 'subagent-prompt', parentToolCallId: msg.parent_tool_use_id }
609
643
  } else {
@@ -76,6 +76,26 @@ function styleProps(style: ScratchStyle): Record<string, unknown> {
76
76
  }
77
77
  }
78
78
 
79
+ // Run a synchronous load with tldraw's own logging held back. On a failed
80
+ // migration `StoreSchema` prints `Error migrating store Incompatible schema?`
81
+ // itself, which reaches the `moi scratch` caller ahead of — and contradicting —
82
+ // the actionable error we throw below ("the file is intact"). Whatever it says
83
+ // is replayed if the load actually succeeds, so only the swallowed-by-a-throw
84
+ // case is lost. Safe to swap `console.error` around: `loadSnapshot` is sync.
85
+ function loadQuietly(load: () => void): void {
86
+ const original = console.error
87
+ const held: unknown[][] = []
88
+ console.error = (...args: unknown[]) => {
89
+ held.push(args)
90
+ }
91
+ try {
92
+ load()
93
+ } finally {
94
+ console.error = original
95
+ }
96
+ for (const args of held) original(...args)
97
+ }
98
+
79
99
  // A fresh headless store hydrated from the saved snapshot (or empty). The
80
100
  // snapshot shape (`{ document }`) matches what the browser PUTs and loads.
81
101
  // A failed load is inspected for version skew: tldraw has no down-migrations,
@@ -86,7 +106,9 @@ function buildStore(doc: ScratchpadDoc | null, writer: ScratchpadWriter | undefi
86
106
  const store = createTLStore({ shapeUtils: defaultShapeUtils, bindingUtils: defaultBindingUtils })
87
107
  if (doc?.store) {
88
108
  try {
89
- loadSnapshot(store, { document: doc } as unknown as Parameters<typeof loadSnapshot>[1])
109
+ loadQuietly(() =>
110
+ loadSnapshot(store, { document: doc } as unknown as Parameters<typeof loadSnapshot>[1])
111
+ )
90
112
  } catch (err) {
91
113
  const ahead = sequencesAhead(doc.schema, store.schema.serialize().sequences)
92
114
  if (ahead.length > 0) {