moi-computer 0.3.0-next.1 → 0.3.0-next.3

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.
Files changed (206) hide show
  1. package/README.md +1 -1
  2. package/bunfig.toml +5 -1
  3. package/client/AGENTS.md +17 -2
  4. package/client/accept-hmr-dependencies.ts +22 -0
  5. package/client/api/http.ts +31 -0
  6. package/client/api/query-options.ts +6 -0
  7. package/client/api/workspace-keys.ts +18 -0
  8. package/client/app/AppRouter.tsx +44 -0
  9. package/client/app/routes/HomeRoute.tsx +13 -0
  10. package/client/app/routes/WorkspaceRoute.tsx +95 -0
  11. package/client/app/shell/SidebarLayout.tsx +196 -0
  12. package/client/assets/openai.svg +3 -0
  13. package/client/assets.d.ts +9 -0
  14. package/client/components/{BottomPanel.tsx → shared/BottomPanel.tsx} +2 -2
  15. package/client/components/shared/PanelHeader.tsx +9 -0
  16. package/client/components/shared/ReorderableList.tsx +199 -0
  17. package/client/components/ui/button.tsx +11 -7
  18. package/client/components/ui/collapsible.tsx +15 -0
  19. package/client/components/ui/dialog.tsx +2 -2
  20. package/client/components/ui/dropdown-menu.tsx +5 -5
  21. package/client/components/ui/hover-card.tsx +1 -1
  22. package/client/components/ui/input.tsx +1 -1
  23. package/client/components/ui/popover.tsx +1 -1
  24. package/client/components/ui/skeleton.tsx +13 -0
  25. package/client/components/ui/tooltip.tsx +1 -1
  26. package/client/externalize-react.ts +7 -1
  27. package/client/features/applets/AppletMount.tsx +44 -0
  28. package/client/{components → features/applets}/WidgetErrorBoundary.tsx +1 -1
  29. package/client/{components → features/applets}/WidgetShell.tsx +5 -2
  30. package/client/{lib → features/applets}/applet-cache.ts +8 -0
  31. package/client/features/applets/applet-styles.ts +61 -0
  32. package/client/{hooks → features/applets}/useApplet.ts +6 -7
  33. package/client/{components/ChatInput.tsx → features/chat/ChatComposer.tsx} +30 -24
  34. package/client/features/chat/ChatPanel.tsx +171 -0
  35. package/client/{components → features/chat}/ChatPopup.tsx +24 -13
  36. package/client/{components/ThreadSelector.tsx → features/chat/ChatSelector.tsx} +15 -13
  37. package/client/{components → features/chat}/MarkdownContent.tsx +1 -1
  38. package/client/{components → features/chat}/ModelPicker.tsx +68 -17
  39. package/client/{components → features/chat}/TurnView.tsx +17 -11
  40. package/client/features/chat/api.ts +78 -0
  41. package/client/features/chat/chat-connection.ts +107 -0
  42. package/client/features/chat/chat-frames.ts +131 -0
  43. package/client/features/chat/chat-send.ts +57 -0
  44. package/client/{lib → features/chat}/preview-turn.ts +1 -1
  45. package/client/{components → features/chat}/tool-group/ReadImagePreview.tsx +1 -1
  46. package/client/{components → features/chat}/tool-group/SubagentCard.tsx +12 -10
  47. package/client/{components → features/chat}/tool-group/TimelineRow.tsx +5 -5
  48. package/client/{components → features/chat}/tool-group/ToolCallGroup.tsx +14 -5
  49. package/client/{components → features/chat}/tool-group/ToolOutput.tsx +12 -18
  50. package/client/{components → features/chat}/tool-group/format.ts +117 -0
  51. package/client/{hooks → features/chat}/useChat.ts +16 -44
  52. package/client/features/connectors/ConnectorsPage.tsx +92 -0
  53. package/client/features/connectors/McpMenu.tsx +145 -0
  54. package/client/features/connectors/api.ts +28 -0
  55. package/client/features/dev/DevRoutes.tsx +18 -0
  56. package/client/features/dev/HarnessDebugPage.tsx +468 -0
  57. package/client/{components/playground → features/dev}/PixelPainter.tsx +10 -21
  58. package/client/{components/playground → features/dev}/PlaygroundPage.tsx +10 -12
  59. package/client/{components/playground → features/dev}/ToolCallsPage.tsx +9 -11
  60. package/client/features/home/CreateWorkspaceDialog.tsx +130 -0
  61. package/client/features/home/CreateWorkspaceDialogSteps.tsx +234 -0
  62. package/client/features/home/HomeLogo.tsx +344 -0
  63. package/client/features/home/HomePage.tsx +214 -0
  64. package/client/{components → features/home}/WorkspacePreview.tsx +4 -4
  65. package/client/features/home/api.ts +156 -0
  66. package/client/features/home/workspace-presentation.tsx +44 -0
  67. package/client/features/scratchpad/Scratchpad.tsx +312 -0
  68. package/client/features/scratchpad/ScratchpadControls.tsx +503 -0
  69. package/client/features/scratchpad/useScratchpadSnapshot.tsx +115 -0
  70. package/client/features/settings/EnvironmentSettings.tsx +149 -0
  71. package/client/features/settings/GeneralSettings.tsx +90 -0
  72. package/client/{components → features}/settings/IconPicker.tsx +76 -224
  73. package/client/features/settings/SettingsLayout.tsx +53 -0
  74. package/client/{components → features}/settings/WorkspaceSettings.tsx +12 -16
  75. package/client/features/settings/api.ts +88 -0
  76. package/client/features/settings/icon-picker-options.ts +30 -0
  77. package/client/{hooks → features/settings}/useEnvVars.ts +4 -4
  78. package/client/features/views/ViewBuilderTab.tsx +153 -0
  79. package/client/features/views/api.ts +124 -0
  80. package/client/features/views/useViewBuilderActions.ts +72 -0
  81. package/client/{components → features/widgets}/HiddenPanel.tsx +3 -3
  82. package/client/{components → features/widgets}/WidgetFrame.tsx +3 -8
  83. package/client/{components → features/widgets}/WidgetGrid.tsx +38 -29
  84. package/client/features/widgets/Widgets.tsx +265 -0
  85. package/client/{lib/grid-pack.ts → features/widgets/grid.ts} +7 -1
  86. package/client/{hooks → features/widgets}/useGridReconcile.ts +1 -1
  87. package/client/{components → features/workspace}/CustomizePanel.tsx +5 -6
  88. package/client/{lib → features/workspace}/WorkspaceLayoutContext.tsx +16 -15
  89. package/client/features/workspace/WorkspaceScreen.tsx +675 -0
  90. package/client/features/workspace/WorkspaceTabs.tsx +205 -0
  91. package/client/features/workspace/api.ts +56 -0
  92. package/client/features/workspace/useFitsSplitLayout.ts +37 -0
  93. package/client/global.d.ts +5 -0
  94. package/client/index.css +6 -45
  95. package/client/index.html +2 -2
  96. package/client/index.tsx +14 -31
  97. package/client/lib/app-icon-registry.ts +145 -0
  98. package/client/main.tsx +2 -2
  99. package/client/runtime/hmr-watchdog.ts +39 -0
  100. package/client/{hooks/useMeiEvents.ts → runtime/useWorkspaceEvents.ts} +12 -7
  101. package/client/store/ui.ts +5 -1
  102. package/client/theme.css +1 -3
  103. package/dist/chunk-11cab5dq.css +1 -0
  104. package/dist/chunk-4vf1t6v1.js +10 -0
  105. package/dist/chunk-6c24yndg.js +61 -0
  106. package/dist/chunk-6c8cwpzc.js +1 -0
  107. package/dist/chunk-b4b276wx.js +15 -0
  108. package/dist/chunk-cs8vbert.js +546 -0
  109. package/dist/chunk-cwqmay73.css +1 -0
  110. package/dist/chunk-kxmvv1ax.js +48 -0
  111. package/dist/chunk-pcnahct1.js +5 -0
  112. package/dist/chunk-rq0ar7vp.js +1 -0
  113. package/dist/chunk-tqd3pkg8.css +1 -0
  114. package/dist/chunk-vkvb3hjm.js +2 -0
  115. package/dist/chunk-zpxrb1ce.js +2 -0
  116. package/dist/index.html +3 -3
  117. package/dist/openai-h13pza4b.svg +3 -0
  118. package/lib/format.ts +2 -2
  119. package/lib/types.ts +56 -9
  120. package/lib/view-builder-meta.ts +35 -0
  121. package/lib/workspace-layout.ts +14 -0
  122. package/lib/workspace-name.ts +14 -0
  123. package/package.json +4 -2
  124. package/server/AGENTS.md +3 -3
  125. package/server/api.ts +279 -60
  126. package/server/applets.ts +1 -1
  127. package/server/bundle-queue.ts +19 -0
  128. package/server/bundler/applet-css.ts +50 -0
  129. package/server/{build-applet.ts → bundler/build-applet.ts} +36 -26
  130. package/server/cli.ts +90 -7
  131. package/server/control.ts +106 -8
  132. package/server/env-apply.ts +2 -2
  133. package/server/harness/README.md +228 -0
  134. package/server/harness/claude-code/NOTES.md +578 -0
  135. package/{lib/claude-adapter.ts → server/harness/claude-code/adapter.ts} +67 -5
  136. package/server/harness/claude-code/index.ts +124 -0
  137. package/server/{mcp.ts → harness/claude-code/mcp.ts} +73 -16
  138. package/server/{cc-session.ts → harness/claude-code/session.ts} +42 -14
  139. package/server/harness/claude-code/sessions.ts +42 -0
  140. package/server/harness/codex/NOTES.md +239 -0
  141. package/server/harness/codex/adapter.ts +414 -0
  142. package/server/harness/codex/client.ts +343 -0
  143. package/server/harness/codex/index.ts +68 -0
  144. package/server/harness/codex/probe.ts +186 -0
  145. package/server/harness/codex/session.ts +617 -0
  146. package/server/harness/debug.ts +57 -0
  147. package/server/harness/openclaw/NOTES.md +316 -0
  148. package/server/{openclaw-adapter.ts → harness/openclaw/adapter.ts} +2 -2
  149. package/server/harness/openclaw/index.ts +93 -0
  150. package/server/{openclaw-session.ts → harness/openclaw/session.ts} +44 -9
  151. package/server/{openclaw-strip.ts → harness/openclaw/strip.ts} +3 -1
  152. package/server/harness/registry.ts +36 -0
  153. package/server/harness/types.ts +87 -0
  154. package/server/layout.ts +36 -11
  155. package/server/moi-scaffold.ts +56 -11
  156. package/server/registry.ts +30 -52
  157. package/server/state.ts +5 -38
  158. package/server/status.ts +7 -46
  159. package/server/vendor.ts +1 -1
  160. package/server/view-builders.ts +428 -0
  161. package/server/views.ts +0 -0
  162. package/server/web.ts +19 -40
  163. package/server/workspace-init.ts +11 -25
  164. package/tsconfig.json +1 -1
  165. package/workspace/.claude/skills/moi-workspace/DESIGN.md +2 -1
  166. package/workspace/.claude/skills/moi-workspace/SKILL.md +28 -7
  167. package/workspace/.claude/skills/moi-workspace/VIEW-DESIGN.md +1 -1
  168. package/client/api/workspaces.ts +0 -427
  169. package/client/assets/hermes-nous.png +0 -0
  170. package/client/components/App.tsx +0 -41
  171. package/client/components/ChatPanel.tsx +0 -275
  172. package/client/components/HomePage.tsx +0 -17
  173. package/client/components/McpMenu.tsx +0 -125
  174. package/client/components/Scratchpad.tsx +0 -935
  175. package/client/components/Widgets.tsx +0 -132
  176. package/client/components/WorkspacesPage.tsx +0 -245
  177. package/client/components/layout/SidebarLayout.tsx +0 -258
  178. package/client/components/routes/workspace/[id].tsx +0 -675
  179. package/client/components/routes/workspace/create.tsx +0 -155
  180. package/client/components/settings/SettingsPages.tsx +0 -255
  181. package/client/hooks/useFitsSidebar.ts +0 -34
  182. package/client/hooks/useScrollFade.ts +0 -38
  183. package/client/lib/connection.ts +0 -238
  184. package/dist/chunk-07qf2tv1.css +0 -1
  185. package/dist/chunk-w18801vn.js +0 -672
  186. package/dist/hermes-nous-pznd63x9.png +0 -0
  187. /package/client/components/{playground → shared}/LedLogo.tsx +0 -0
  188. /package/client/{components → features/chat}/ShimmerText.tsx +0 -0
  189. /package/client/{store/live.ts → features/chat/chat-store.ts} +0 -0
  190. /package/client/{lib → features/chat}/group-turns.ts +0 -0
  191. /package/client/{components → features/chat}/tool-group/CodeBlock.tsx +0 -0
  192. /package/client/{components → features/chat}/tool-group/Collapse.tsx +0 -0
  193. /package/client/{components → features/chat}/tool-group/detect.ts +0 -0
  194. /package/client/{components → features/chat}/tool-group/fixtures.ts +0 -0
  195. /package/client/{components → features/chat}/tool-group/index.ts +0 -0
  196. /package/client/{lib → features/chat}/uploads.ts +0 -0
  197. /package/client/{hooks → features/chat}/useStickToBottom.ts +0 -0
  198. /package/client/{components → features/connectors}/IconMcp.tsx +0 -0
  199. /package/client/{lib → features/connectors}/mcp-icons.ts +0 -0
  200. /package/client/{lib → features/scratchpad}/scratch-executor.ts +0 -0
  201. /package/client/{lib → features/settings}/render-icon.ts +0 -0
  202. /package/client/{lib → features/workspace}/WorkspaceContext.tsx +0 -0
  203. /package/client/{hooks → features/workspace}/useWorkspaceTheme.ts +0 -0
  204. /package/server/{agent.ts → harness/claude-code/models.ts} +0 -0
  205. /package/server/{openclaw.ts → harness/openclaw/discovery.ts} +0 -0
  206. /package/server/{openclaw-gateway.ts → harness/openclaw/gateway.ts} +0 -0
@@ -0,0 +1,578 @@
1
+ # Claude Code (Agent SDK) — message spec & UI-abstraction notes
2
+
3
+ The wire format the Claude Code harness emits and how it maps onto our
4
+ display abstraction (`lib/format.ts`, implemented by `adapter.ts` here).
5
+ Originally research for the message-display abstraction; kept as the reference
6
+ spec for the CC adapter.
7
+
8
+ > **Status note.** The SDK wire-format sections (message kinds, content
9
+ > blocks, subagent/skill mechanics) remain the reference. But the "current
10
+ > implementation" critiques and §14's migration plan describe the
11
+ > **pre-refactor** code and have since shipped: chat moved from
12
+ > `models.ts` to `session.ts` (both in this folder), `state.ts`'s
13
+ > `transformMessage` and the 7-variant `Message` union were replaced by
14
+ > `StreamEvent`/`Turn`/`Part` in `lib/format.ts` (built by
15
+ > `adapter.ts`), and `MessageBlock.tsx` was replaced by
16
+ > `client/components/TurnView.tsx`. Read those sections as historical
17
+ > context, not as descriptions of today's code.
18
+
19
+ Evidence drawn from:
20
+
21
+ - Upstream types: `node_modules/@anthropic-ai/claude-agent-sdk/sdk.d.ts`
22
+ - Upstream nested content types: `node_modules/@anthropic-ai/sdk/resources/beta/messages/messages.d.ts`
23
+ - SDK bundled source: `sdk.mjs` (for undocumented behavior around `isSynthetic` / `isReplay`)
24
+ - Official docs: <https://code.claude.com/docs/en/agent-sdk/typescript>
25
+ - Repo code: `server/agent.ts`, `server/state.ts`, `lib/types.ts`, `client/components/MessageBlock.tsx`
26
+ - Captured live: `workspace/raw-sdk-messages.jsonl` (skill load + sub-agent run)
27
+
28
+ ---
29
+
30
+ ## 1. Three layers
31
+
32
+ ```
33
+ Layer 1 — SDK wire ──► Layer 2 — Repo `Message` (lib/types.ts) ──► Layer 3 — UI render
34
+ (21 message kinds (7 flattened variants (MessageBlock switch)
35
+ + 15 content blocks) stripped of nesting metadata)
36
+ ```
37
+
38
+ Two filters between L1 and L2 are responsible for everything the UI currently can't show:
39
+
40
+ - `server/agent.ts:73-86` — forwards only `assistant | user | result`. Drops every `system/*`, `tool_progress`, `stream_event`, `tool_use_summary`, `auth_status`, `rate_limit_event`, `prompt_suggestion`.
41
+ - `server/state.ts:93-132` `transformMessage` — inside an assistant/user message, keeps only `text | tool_use | tool_result` content blocks and strips `parent_tool_use_id`, `isSynthetic`, `tool_use_result`, etc.
42
+
43
+ ---
44
+
45
+ ## 2. Layer 1 — Full `SDKMessage` union (21 variants)
46
+
47
+ Discriminated primarily by `type`, then `subtype` for `'system'` and `'result'`.
48
+
49
+ ```
50
+ SDKMessage
51
+ ├── type:'assistant' → SDKAssistantMessage { message:BetaMessage, parent_tool_use_id, uuid, session_id, error? }
52
+ ├── type:'user' → SDKUserMessage { message:MessageParam, parent_tool_use_id, isSynthetic?, tool_use_result?, priority?, timestamp?, shouldQuery? }
53
+ ├── type:'user' + isReplay:true → SDKUserMessageReplay (resume-replay variant; also file_attachments?)
54
+ ├── type:'stream_event' → SDKPartialAssistantMessage { event:BetaRawMessageStreamEvent } ← raw token deltas
55
+ │
56
+ ├── type:'result'
57
+ │ ├── subtype:'success' SDKResultSuccess { duration_ms, num_turns, result, stop_reason, total_cost_usd, usage, modelUsage, permission_denials, fast_mode_state }
58
+ │ └── subtype:'error_during_execution' | 'error_max_turns'
59
+ │ | 'error_max_budget_usd' | 'error_max_structured_output_retries'
60
+ │
61
+ ├── type:'system'
62
+ │ ├── subtype:'init' tools[], mcp_servers[], model, permissionMode, cwd, plugins[], skills[], slash_commands[], agents[], fast_mode_state, claude_code_version, output_style, apiKeySource
63
+ │ ├── subtype:'status' { status:SDKStatus, permissionMode? }
64
+ │ ├── subtype:'session_state_changed'{ state:'idle'|'running'|'requires_action' }
65
+ │ ├── subtype:'compact_boundary' { compact_metadata }
66
+ │ ├── subtype:'api_retry' { attempt, max_retries, retry_delay_ms, error_status, error }
67
+ │ ├── subtype:'hook_started' { hook_id, hook_name, hook_event }
68
+ │ ├── subtype:'hook_progress' { …, stdout, stderr, output }
69
+ │ ├── subtype:'hook_response' { …, exit_code?, outcome:'success'|'error'|'cancelled' }
70
+ │ ├── subtype:'local_command_output' { content }
71
+ │ ├── subtype:'task_started' { task_id, tool_use_id?, description, task_type?, workflow_name?, prompt? }
72
+ │ ├── subtype:'task_progress' { task_id, tool_use_id?, description, usage, last_tool_name?, summary? }
73
+ │ ├── subtype:'task_notification' { task_id, status:'completed'|'failed'|'stopped', output_file, summary }
74
+ │ ├── subtype:'files_persisted' { files[], failed[], processed_at }
75
+ │ └── subtype:'elicitation_complete' { mcp_server_name, elicitation_id }
76
+ │
77
+ ├── type:'tool_progress' → SDKToolProgressMessage { tool_use_id, tool_name, parent_tool_use_id, elapsed_time_seconds, task_id? }
78
+ ├── type:'tool_use_summary' → SDKToolUseSummaryMessage { summary, preceding_tool_use_ids[] }
79
+ ├── type:'auth_status' → SDKAuthStatusMessage { isAuthenticating, output[], error? }
80
+ ├── type:'rate_limit_event' → SDKRateLimitEvent { rate_limit_info }
81
+ └── type:'prompt_suggestion' → SDKPromptSuggestionMessage { suggestion }
82
+ ```
83
+
84
+ ---
85
+
86
+ ## 3. Layer 1 — Content blocks (inside `SDKAssistantMessage.message.content` and `SDKUserMessage.message.content`)
87
+
88
+ Anthropic Messages-API shape; same discriminator pattern (`type`).
89
+
90
+ ### Assistant-side blocks
91
+
92
+ ```
93
+ BetaContentBlock
94
+ ├── 'text' { text, citations }
95
+ ├── 'thinking' { thinking, signature }
96
+ ├── 'redacted_thinking' { data }
97
+ ├── 'tool_use' { id, name, input, caller? }
98
+ ├── 'server_tool_use' { id, name:'web_search'|'web_fetch'|'code_execution'|'bash_code_execution'|'text_editor_code_execution'|'tool_search_tool_regex'|'tool_search_tool_bm25', input, caller? }
99
+ ├── 'mcp_tool_use' { server_name, name, input }
100
+ ├── 'web_search_tool_result' results | error
101
+ ├── 'web_fetch_tool_result' content | error
102
+ ├── 'code_execution_tool_result' stdout/stderr/return_code | error
103
+ ├── 'bash_code_execution_tool_result' stdout/stderr/return_code | error
104
+ ├── 'text_editor_code_execution_tool_result' view / create / str_replace results
105
+ ├── 'tool_search_tool_result'
106
+ ├── 'mcp_tool_result'
107
+ ├── 'container_upload' { file_id }
108
+ └── 'compaction' summary of prior turns
109
+ ```
110
+
111
+ ### User-side blocks (`MessageParam.content`)
112
+
113
+ ```
114
+ 'text' | 'image' | 'document' | 'tool_result' | 'tool_use' | 'thinking' | 'search_result' | 'container_upload'
115
+ ```
116
+
117
+ Of these the repo currently handles only `tool_result`.
118
+
119
+ ---
120
+
121
+ ## 4. Semantic classification of `SDKUserMessage` (the envelope lies)
122
+
123
+ 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:
124
+
125
+ | # | Condition | What it really is | UI behavior |
126
+ | --- | -------------------------------------------------------------- | ------------------------------------------------------------------------------------------------ | -------------------------------------------------------------------------------------------- |
127
+ | 1 | `isReplay: true` | Replay from a resumed session; not new content | Skip (or render only once from the persisted log) |
128
+ | 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` |
129
+ | 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 |
130
+ | 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 |
131
+ | 5 | none of the above | Actual user input typed into the chat | Render as the user bubble |
132
+
133
+ ### On `isSynthetic` specifically — the docs don't say, the source does
134
+
135
+ Public docs ([typescript reference](https://code.claude.com/docs/en/agent-sdk/typescript)) list the field in the type but never explain it. Nothing in the CHANGELOG either. The bundled SDK source reveals it's derived:
136
+
137
+ ```js
138
+ isSynthetic: K.isMeta || K.isVisibleInTranscriptOnly
139
+ if (isSynthetic || q.isReplay) return // early-exit in an internal processing loop
140
+ ```
141
+
142
+ So `isSynthetic = true` means: _this user turn was fabricated by the harness and exists only so the model can see it in the transcript; don't treat it as a real utterance._ Practically, it covers skill bodies, slash-command expansions, system reminders, hook outputs, and similar injections.
143
+
144
+ `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.
145
+
146
+ ---
147
+
148
+ ## 5. Sub-agent invocation — the nesting mechanism
149
+
150
+ Observed live for an `Agent` tool call (`workspace/raw-sdk-messages.jsonl` lines 10–31). Four distinct mechanisms co-operate.
151
+
152
+ ### Event sequence
153
+
154
+ ```
155
+ 12 assistant [tool_use:Agent] tool_use_id=toolu_017X… ← parent thread
156
+ 13 system/task_started task_id=a9ef… tool_use_id=toolu_017X… description="Check widgets folder contents"
157
+ 14 user [text] parent=toolu_017X… ← subagent's initial prompt
158
+ 15 rate_limit_event
159
+ 16 system/task_progress description="Running ls -la …"
160
+ 17 assistant [tool_use:Bash] parent=toolu_017X… ← inside the subtask
161
+ 18 user [tool_result] parent=toolu_017X…
162
+ 19 system/task_progress description="Running find …"
163
+ 20 assistant [tool_use:Bash] parent=toolu_017X…
164
+ 21 user [tool_result] parent=toolu_017X…
165
+ 22 system/task_progress description="Reading .widgets/package.json"
166
+ 23 assistant [tool_use:Read] parent=toolu_017X…
167
+ 24 user [tool_result] parent=toolu_017X…
168
+ 25 system/task_progress description="Running ls -lh …"
169
+ 26 assistant [tool_use:Bash] parent=toolu_017X…
170
+ 27 user [tool_result] parent=toolu_017X…
171
+ 28 system/task_notification status=completed task_id=a9ef… tool_use_id=toolu_017X…
172
+ 29 user [tool_result] ← Agent tool's return to parent
173
+ 30 assistant [text] ← parent thread resumes
174
+ 31 result/success
175
+ ```
176
+
177
+ ### Roles of the four mechanisms
178
+
179
+ | Mechanism | Purpose | Use in UI |
180
+ | ------------------------------------------------------ | --------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------- |
181
+ | `parent_tool_use_id` on nested assistant/user messages | THE discriminator for "this message is inside the subtask, not the main thread" | Group nested turns into an expandable sub-thread under the Agent tool card |
182
+ | `system/task_started` | Harness announces subtask begin (carries `task_id`, `tool_use_id`, `description`) | Initial "starting" label on the Agent card |
183
+ | `system/task_progress` | Out-of-band status per tool call the subagent makes (e.g. `"Running ls -la …"`) | Live status line on the collapsed Agent card — avoids rendering the full nested transcript for the common case |
184
+ | `system/task_notification` | Terminal event, `status: 'completed' \| 'failed' \| 'stopped'` | Finalize the Agent card |
185
+
186
+ ### Three identifiers — don't conflate
187
+
188
+ - `tool_use_id` (`toolu_017X…`) — the assistant's tool-call UUID from the `tool_use` block. Matches the final parent-thread `tool_result` (line 29).
189
+ - `task_id` (`a9efdb…`) — harness-generated short hash; present on every `system/task_*` event. Useful when subtasks run in parallel.
190
+ - `parent_tool_use_id` — set on messages that _belong to_ a subtask. The one the UI tree should be keyed on.
191
+
192
+ ### Current repo bug
193
+
194
+ `state.ts`'s `transformMessage` strips `parent_tool_use_id` when converting to the repo's `Message` type, so the nested subagent turns that DO make it through (since their envelope is `assistant`/`user`) render flat in the main transcript, indistinguishable from the parent thread. All four `system/task_*` events are dropped entirely by `agent.ts`, so the progress line and completion status never reach the client.
195
+
196
+ ---
197
+
198
+ ## 6. Skill loading — observed shape
199
+
200
+ Skills are not a dedicated message type. Captured live (log lines 1–9):
201
+
202
+ 1. `system/init` advertises skills as a string array: `skills: ["widgets", "loop", …]`, plus a generic `Skill` entry in `tools[]` and mirrored `slash_commands[]`.
203
+ 2. Assistant emits a `thinking` block ("There's a skill available called 'widgets'…").
204
+ 3. Assistant emits a regular `tool_use` — `{ name: "Skill", input: { skill: "widgets" }, caller: { type: "direct" } }`.
205
+ 4. Two user messages arrive in sequence:
206
+ - normal `tool_result` ack (`"Launching skill: widgets"`) with extra top-level `tool_use_result: { success: true, commandName: "widgets" }` on the envelope;
207
+ - **synthetic** user message (`isSynthetic: true`) whose content is a single `text` block carrying the full SKILL.md body — this is how the skill's instructions enter the conversation.
208
+ 5. Assistant resumes with thinking + text; `result/success` terminates.
209
+
210
+ UI implication: render `tool_use.name === "Skill"` with a special icon/label, consume `tool_use_result.commandName` for success state, and route the synthetic text block into the "injected context" lane (not the user bubble).
211
+
212
+ ---
213
+
214
+ ## 7. Layer 2 — repo's current `Message` union
215
+
216
+ `lib/types.ts`:
217
+
218
+ ```
219
+ Message
220
+ ├── 'user' { content: string } ← loses parent_tool_use_id, isSynthetic, timestamp, priority, tool_use_result
221
+ ├── 'assistant' { content: string } ← loses parent_tool_use_id, loses all thinking/server-tool blocks
222
+ ├── 'tool_use' { id, name, input } ← loses caller, loses parent_tool_use_id context
223
+ ├── 'tool_result' { tool_use_id, content, is_error }
224
+ ├── 'done' { cost, turns, session_id } ← from result/success only
225
+ ├── 'error' { content } ← from result/error_*
226
+ └── 'stopped' {}
227
+ ```
228
+
229
+ ---
230
+
231
+ ## 8. Layer 3 — current UI handling
232
+
233
+ `client/components/MessageBlock.tsx`:
234
+
235
+ | Repo type | Rendered as | Notes |
236
+ | ------------- | --------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- |
237
+ | `user` | Right-aligned plain text | No distinction between typed input, tool return, or synthetic content (but tool_result and synthetic never reach here because state.ts rewrites them) |
238
+ | `assistant` | Markdown | |
239
+ | `tool_use` | `<details>` with name + JSON input preview, paired with preceding sibling's tool_result | No special-casing for `Agent`, `Skill`, `Bash`, etc. |
240
+ | `tool_result` | Nothing (consumed by preceding tool_use) | |
241
+ | `done` | Hidden | |
242
+ | `stopped` | Hidden | |
243
+ | `error` | Red box | |
244
+ | anything else | Switch has NO default — renders crash | |
245
+
246
+ ---
247
+
248
+ ## 9. What's missing today vs. what the SDK emits
249
+
250
+ Known blind spots the abstraction should close:
251
+
252
+ - **Thinking blocks** — SDK emits them; `transformMessage` drops them. Would require a new repo-level block type.
253
+ - **Server tool use** (`web_search`, `web_fetch`, `code_execution`, etc.) — completely invisible. An assistant using `WebSearch` currently looks like a silent gap between user turn and final answer.
254
+ - **MCP tool calls proper** (`mcp_tool_use` / `mcp_tool_result` blocks) — dropped. Regular `Task`/`Bash` MCP tools happen to survive because they wear the plain `tool_use` shape.
255
+ - **Streaming** — `stream_event` dropped, so assistant text lands in one block per turn, not token-by-token.
256
+ - **Session lifecycle signals** — `system/init`, `system/session_state_changed`, `system/status` dropped. UI can't display model name, current tools, permission mode, "thinking…", "awaiting permission".
257
+ - **Sub-agent nesting** — subagent turns survive structurally but lose `parent_tool_use_id`, so they render flat. All `task_*` events dropped.
258
+ - **Hooks / tasks / rate limits / api_retry** — all invisible.
259
+ - **MessageBlock switch exhaustiveness** — any future repo-level type crashes render.
260
+
261
+ ---
262
+
263
+ ## 10. Recommended abstraction — three stages
264
+
265
+ ```
266
+ Stage 1 — Raw SDK event (vendor-shaped, lossless)
267
+ │
268
+ ▼ per-agent adapter
269
+ Stage 2 — Normalized event (agent-agnostic, flat, stream-grained)
270
+ │ kinds: user_text, assistant_text_delta, thinking_delta,
271
+ │ tool_started, tool_progress, tool_finished,
272
+ │ subtask_started, subtask_progress, subtask_finished,
273
+ │ session_init, session_status, rate_limit,
274
+ │ result, error, cost_update
275
+ ▼ event fold
276
+ Stage 3 — Display item tree (what the UI lays out)
277
+ Turn { id, role, parentTaskId, blocks[], children[] }
278
+ Task { toolUseId, taskId, description, progress[], status }
279
+ ```
280
+
281
+ ### Rules the abstraction should enforce
282
+
283
+ - Every SDK message must map to exactly one normalized event (or be explicitly ignored); no silent drops.
284
+ - Turns are keyed by `uuid`; nested by `parent_tool_use_id`; the UI descends the tree to render sub-agent transcripts.
285
+ - `Task` lives on its own lane keyed by `tool_use_id`; the Agent tool-use card renders description + progress + "show nested transcript" expander that reveals the sub-turn tree.
286
+ - Classification of user envelopes: run the 5-priority table from §4 at the adapter boundary; downstream code receives already-classified items.
287
+ - `Block` union is exhaustive and the UI switch has a `_: never` default, so adding a new block is a compile error, not a render crash.
288
+
289
+ ### Why three stages, not two
290
+
291
+ Stage 2 is what lets us support non-Claude agents later. Different SDKs map onto the same normalized event stream with different adapters; Stage 3 doesn't care whose agent produced the events. Stage 1 stays lossless so debugging/replay tooling (and this research) keeps working.
292
+
293
+ ---
294
+
295
+ ## 11. Field reference — undocumented / under-documented items
296
+
297
+ Worth recording because the official docs list the field but don't describe it:
298
+
299
+ - `SDKUserMessage.isSynthetic?: boolean` — harness-injected transcript-only content (see §4).
300
+ - `SDKUserMessage.tool_use_result?: unknown` — extra envelope-level metadata attached by the harness when a user message carries a `tool_result` block. Example seen: `{ success: true, commandName: "widgets" }` for a skill tool. Not the same as the inner `tool_result` block's `content`.
301
+ - `SDKUserMessage.priority?: 'now' | 'next' | 'later'` — queueing hint; no semantics documented.
302
+ - `SDKUserMessage.timestamp?: string` — ISO time the message was created on the originating process. Older emitters omit it; consumers should fall back to receive time.
303
+ - `SDKUserMessage.shouldQuery?: boolean` — docs list it, don't describe it. Likely controls whether the harness re-queries the model after this message.
304
+ - `SDKUserMessageReplay.isReplay: true` + `file_attachments?: unknown[]` — emitted when resuming a session; the SDK short-circuits further processing on these.
305
+ - `BetaToolUseBlock.caller?: BetaDirectCaller | BetaServerToolCaller` — observed as `{ type: "direct" }` in captured logs; distinguishes direct model calls from server-tool-chained calls.
306
+
307
+ ---
308
+
309
+ ## 12. Captured-log inventory
310
+
311
+ Log: `workspace/raw-sdk-messages.jsonl`, produced by `appendRawLog` added in `server/agent.ts`.
312
+
313
+ Counts from the two runs captured so far (skill-load + sub-agent):
314
+
315
+ ```
316
+ 11 assistant
317
+ 2 rate_limit_event
318
+ 2 result/success
319
+ 2 system/init
320
+ 1 system/task_notification
321
+ 4 system/task_progress
322
+ 1 system/task_started
323
+ 8 user (mix of tool_result, text, synthetic)
324
+ ```
325
+
326
+ To grow coverage of rarer variants (`hook_*`, `session_state_changed`, `compact_boundary`, `stream_event`, `api_retry`, `auth_status`, `prompt_suggestion`, `tool_use_summary`, `local_command_output`, `files_persisted`, `elicitation_complete`), drive runs that exercise hooks, long sessions that trigger compaction, streaming mode, and MCP-authenticated tools.
327
+
328
+ ## 13. Vercel AI SDK `UIMessage` — reference and gap analysis
329
+
330
+ Canonical AI SDK `UIMessage` shape ([ui-messages.ts](https://github.com/vercel/ai/blob/main/packages/ai/src/ui/ui-messages.ts)):
331
+
332
+ ```ts
333
+ interface UIMessage<METADATA, DATA_PARTS, TOOLS> {
334
+ id: string
335
+ role: 'system' | 'user' | 'assistant'
336
+ metadata?: METADATA
337
+ parts: UIMessagePart<DATA_PARTS, TOOLS>[]
338
+ }
339
+
340
+ type UIMessagePart =
341
+ | TextUIPart // { type: 'text', text, state?: 'streaming'|'done' }
342
+ | ReasoningUIPart // same shape, type: 'reasoning'
343
+ | ReasoningFileUIPart // non-text reasoning artifacts
344
+ | ToolUIPart<TOOLS> // type: `tool-${name}`, one part whose state evolves
345
+ | DynamicToolUIPart // type: 'dynamic-tool' — schema-less (MCP lands here)
346
+ | SourceUrlUIPart // citations (web)
347
+ | SourceDocumentUIPart // citations (documents)
348
+ | FileUIPart // attached file, data:/remote URL
349
+ | DataUIPart<DATA_PARTS> // user-typed custom parts: `data-${NAME}`
350
+ | CustomContentUIPart // provider-specific escape hatch
351
+ | StepStartUIPart // marker-only, delimits multi-step
352
+ ```
353
+
354
+ Tool lifecycle collapses `tool_use` + `tool_result` into one evolving part:
355
+
356
+ ```
357
+ input-streaming → input-available →
358
+ [ approval-requested → approval-responded ] →
359
+ output-available | output-error | output-denied
360
+ ```
361
+
362
+ `input`, `output`, `errorText`, and three separate metadata slots (`providerMetadata`, `callProviderMetadata`, `resultProviderMetadata`) all sit on the same part. `preliminary: true` on `output-available` is how sub-agents stream progress — same part, updated output, then a final non-preliminary output.
363
+
364
+ ### Feature gap vs. Claude Agent SDK
365
+
366
+ Comparing AI SDK's `UIMessage` against the Claude features catalogued in §2–§6 of this doc:
367
+
368
+ | Claude feature | AI SDK | Notes |
369
+ | ------------------------------------------------------------------------------------------------------------ | ------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------- |
370
+ | Synthetic user messages (`isSynthetic`) | **Nothing** | Skill bodies, system reminders, hook output — no place to put them. `role` is only `user/assistant/system`. |
371
+ | Session init (tools, mcp_servers, model, permissionMode, cwd, plugins, skills, slash_commands) | **Nothing** | `UIMessage` is message-scoped. No inventory of what's available. |
372
+ | Sub-agent nesting | **Partial** | Pattern is "tool's `output` is itself a `UIMessage`"; recurse into `output.parts`. No `parent_tool_use_id`, no `task_started/progress/notification`. |
373
+ | Skills | **Partial** | Skill invocation = generic `tool-*` part. The synthetic SKILL.md follow-up has no home. |
374
+ | Server tool variants (web_search, code_execution, text_editor, …) | **Partial** | Collapsed into `providerExecuted: true`. Rich structured outputs (stdout/stderr/return_code, search results) must be reconstructed from `output: unknown`. |
375
+ | Reasoning / thinking | **Direct match** | `reasoning` part + `reasoning-file`; redacted/signed thinking goes in `providerMetadata`. |
376
+ | MCP | **Not first-class** | MCP tools are just `dynamic-tool` parts. No `server_name`, no elicitation. |
377
+ | Hooks, rate limits, api_retry, compact_boundary, local_command_output, files_persisted, elicitation_complete | **Nothing** | Opaque `error` chunks only; everything else would be custom `data-*` parts. |
378
+ | `tool_use_result` envelope sidecar | **Partial** | Fits in `resultProviderMetadata` or message `metadata`, but semantically meant for provider fields. |
379
+ | Caller info (direct vs server_tool vs MCP vs subagent) | **Partial** | Only a boolean (`providerExecuted`). Chain origin is lost. |
380
+
381
+ **Short version:** AI SDK cleanly covers "what the model emitted in one response." It has almost no vocabulary for harness/session/subagent lifecycle signals — exactly the layer where Claude is richest.
382
+
383
+ ### Worth stealing from AI SDK
384
+
385
+ 1. **`parts: Part[]` discriminated-union** instead of `content: string`.
386
+ 2. **One tool call = one part whose `state` evolves** — kills the `tool_use` / `tool_result` sibling-pair hack.
387
+ 3. **Human-in-the-loop as explicit states** (`approval-requested`, `output-denied`) rather than flags.
388
+ 4. **Three named metadata slots** (part-level, call-level, result-level) avoid collisions.
389
+ 5. **`preliminary: true` for sub-agent progress** — same part, updated output.
390
+ 6. **`step-start` as a marker part** — multi-step stays linear in `parts`.
391
+ 7. **Type-parameterized `DATA_PARTS`** — custom content without forking the core union.
392
+ 8. **`dynamic-tool` fallback** — graceful degradation when a schema isn't known.
393
+
394
+ ## 14. Proposed intermediate display format
395
+
396
+ Display-only. No streaming, no tool-arg streaming. MCP, sub-agents, skills first-class. Built once at ingest from the SDK stream and held in memory / persisted as-is.
397
+
398
+ ### Three-track conversation model
399
+
400
+ Most UIs treat a chat as a flat list of turns. Claude's stream has three distinct concerns that each deserve their own lane:
401
+
402
+ ```ts
403
+ type ConversationEvent =
404
+ | Turn // transcript entries (render as bubbles / tool cards)
405
+ | SystemNotice // chrome strip / toast (rate limits, hooks, retries, results)
406
+ | SessionSnapshot // inventory panel (model, tools, MCP status, permission mode)
407
+ ```
408
+
409
+ ### Turn — one transcript entry
410
+
411
+ ```ts
412
+ type Turn = {
413
+ id: string
414
+ role: 'user' | 'assistant'
415
+ origin: TurnOrigin // why this turn exists (replaces AI SDK's flat role)
416
+ parentTaskId?: string // set when turn belongs inside a subtask
417
+ parts: Part[]
418
+ metadata?: Record<string, unknown>
419
+ timestamp?: string
420
+ }
421
+
422
+ type TurnOrigin =
423
+ | { kind: 'user-input' } // typed in the chat box
424
+ | { kind: 'tool-return'; toolCallId: string } // Claude's user envelope wrapping a tool_result
425
+ | {
426
+ kind: 'synthetic'
427
+ reason: // Claude's isSynthetic
428
+ 'skill-body' | 'system-reminder' | 'hook-output' | 'slash-command' | 'other'
429
+ }
430
+ | { kind: 'subagent-prompt'; parentToolCallId: string } // the Agent tool's prompt arg
431
+ | { kind: 'replay' } // resumed session playback
432
+ ```
433
+
434
+ The `TurnOrigin` tag is what tells the renderer whether to draw a user bubble, route to a tool card, hide behind a "show context" toggle, or skip entirely. This is the missing piece in AI SDK's `UIMessage`.
435
+
436
+ ### Part — the AI SDK shape, widened for Claude
437
+
438
+ ```ts
439
+ type Part =
440
+ | { type: 'text'; text: string; citations?: Citation[] }
441
+ | { type: 'reasoning'; text: string; redacted?: boolean; signature?: string }
442
+ | { type: 'tool-call'; call: ToolCall }
443
+ | { type: 'file'; mediaType: string; url: string; filename?: string }
444
+ | { type: 'source-url'; url: string; title?: string; sourceId: string }
445
+ | { type: 'source-document'; mediaType: string; title: string; sourceId: string }
446
+ | { type: 'data'; name: string; data: unknown } // escape hatch
447
+
448
+ type Citation = { url?: string; title?: string; quote?: string }
449
+ ```
450
+
451
+ ### ToolCall — one evolving entity (AI SDK's key idea)
452
+
453
+ No more `tool_use` + `tool_result` sibling-pair hack. One `ToolCall` record owns the entire call:
454
+
455
+ ```ts
456
+ type ToolCall = {
457
+ toolCallId: string
458
+ name: string
459
+ caller: 'model' | 'server-tool' | 'mcp' | 'subagent' // widens AI SDK's providerExecuted: boolean
460
+ mcpServer?: string // only when caller === 'mcp'
461
+ state: ToolState
462
+ input: unknown
463
+ output?: unknown
464
+ errorText?: string
465
+ sidecar?: Record<string, unknown> // Claude's tool_use_result envelope
466
+ subagent?: SubagentRecord // only when caller === 'subagent'
467
+ skill?: { skillName: string; body?: string } // only when name === 'Skill'
468
+ }
469
+
470
+ type ToolState =
471
+ | 'pending' // input known, not yet executed (rare for display)
472
+ | 'approval-pending'
473
+ | 'approval-denied'
474
+ | 'running'
475
+ | 'success'
476
+ | 'error'
477
+ ```
478
+
479
+ ### SubagentRecord — enables the "one-line + modal" UX
480
+
481
+ ```ts
482
+ type SubagentRecord = {
483
+ taskId: string // from system/task_started
484
+ description: string // one-line label
485
+ progress: string[] // each task_progress.description
486
+ status: 'running' | 'completed' | 'failed' | 'stopped'
487
+ usage?: { totalTokens: number; toolUses: number; durationMs: number }
488
+ transcript: Turn[] // nested turns (parent_tool_use_id === toolCallId)
489
+ }
490
+ ```
491
+
492
+ **One-line render** in the main transcript uses `description` + `status` + optionally `progress[-1]`.
493
+ **Modal** recursively renders `transcript` with the same `TurnList` component, nested sub-agents included.
494
+
495
+ ### SessionSnapshot — inventory (AI SDK has nothing here)
496
+
497
+ ```ts
498
+ type SessionSnapshot = {
499
+ id: string
500
+ sessionId: string
501
+ model: string // e.g. 'claude-sonnet-4-6'
502
+ cwd: string
503
+ permissionMode: string // 'bypassPermissions' | 'default' | ...
504
+ tools: string[]
505
+ mcpServers: { name: string; status: string }[] // status: 'connected'|'needs-auth'|'failed'|'disabled'|'pending'
506
+ plugins: { name: string; path: string }[]
507
+ skills: string[]
508
+ slashCommands: string[]
509
+ agents: string[]
510
+ updatedAt: string
511
+ }
512
+ ```
513
+
514
+ Drives the chrome: model badge, MCP server status dots, permission mode pill, slash-command picker, skill menu.
515
+
516
+ ### SystemNotice — banners / toasts / chrome transients
517
+
518
+ ```ts
519
+ type SystemNotice =
520
+ | { kind: 'rate-limit'; at: string; info: unknown }
521
+ | { kind: 'api-retry'; attempt: number; max: number; delayMs: number; error?: string }
522
+ | { kind: 'compact'; metadata: unknown }
523
+ | {
524
+ kind: 'hook'
525
+ hookName: string
526
+ event: string
527
+ status: 'started' | 'progress' | 'response'
528
+ output?: string
529
+ exitCode?: number
530
+ outcome?: string
531
+ }
532
+ | { kind: 'session-state'; state: 'idle' | 'running' | 'requires-action' }
533
+ | { kind: 'status'; status: string }
534
+ | { kind: 'files-persisted'; files: string[]; failed: { filename: string; error: string }[] }
535
+ | { kind: 'elicitation'; server: string; id: string }
536
+ | {
537
+ kind: 'result'
538
+ subtype:
539
+ | 'success'
540
+ | 'error_during_execution'
541
+ | 'error_max_turns'
542
+ | 'error_max_budget_usd'
543
+ | 'error_max_structured_output_retries'
544
+ cost?: number
545
+ turns?: number
546
+ }
547
+ ```
548
+
549
+ None of these belong in the main scroll of turns. They're ephemeral UI: status bars, toasts, footer cost line.
550
+
551
+ ### Ingest pipeline — how to build this from the SDK stream
552
+
553
+ 1. `system/init` → open a `SessionSnapshot`; refresh on every subsequent `init`.
554
+ 2. `system/task_started` → open a `SubagentRecord` inside the `ToolCall` whose `toolCallId` matches `tool_use_id`; set `description`, `status: 'running'`.
555
+ 3. `system/task_progress` → push `description` onto the owning `SubagentRecord.progress`; update `usage`.
556
+ 4. `system/task_notification` → flip `SubagentRecord.status` and freeze.
557
+ 5. Assistant / user messages with `parent_tool_use_id` set → append to the matching `SubagentRecord.transcript` rather than the main turn list.
558
+ 6. User messages carrying a `tool_result` block → classify as `TurnOrigin.kind = 'tool-return'`; merge the result into the owning `ToolCall` (flip `state`, set `output` / `errorText`), don't render as a standalone turn.
559
+ 7. User messages with `isSynthetic: true` → classify as `TurnOrigin.kind = 'synthetic'`, inferring `reason` from context (skill body if it followed a `Skill` tool, system-reminder if it contains a `<system-reminder>` tag, etc.).
560
+ 8. User messages with `isReplay: true` → classify as `TurnOrigin.kind = 'replay'`.
561
+ 9. Everything else → `SystemNotice` by subtype, or ignored (`stream_event`, `tool_progress`).
562
+
563
+ ### What this gives us
564
+
565
+ - **Exhaustive renderer**: `switch (part.type)` with a `_: never` default — future block types fail at compile time, not at runtime.
566
+ - **No sibling-lookup hacks**: tool card reads everything from its own `ToolCall`.
567
+ - **Sub-agent UX**: one-line label with live progress, click to open modal that recursively renders the nested transcript.
568
+ - **Skill handling**: a `Skill` tool-call renders its name with a small icon; the synthetic SKILL.md body lives hidden in `skill.body` (or on a matching synthetic turn) and is never shown in the scroll unless the user expands it.
569
+ - **MCP**: tool calls carry `caller: 'mcp'` + `mcpServer`, so the renderer can badge them differently without parsing the tool name.
570
+ - **Session chrome**: `SessionSnapshot` drives a sidebar/header, not the scroll.
571
+ - **Future agents**: a different agent's adapter emits the same three tracks; the renderer doesn't know which SDK produced the events.
572
+
573
+ ### Repo changes required
574
+
575
+ - `server/agent.ts:73-86` — stop filtering out `system/*`, `rate_limit_event`, `tool_progress`. Route them to `SessionSnapshot` / `SystemNotice` / owning `SubagentRecord`.
576
+ - `server/state.ts:93-132` — rewrite `transformMessage` as a classifier per §4's priority table. Preserve `parent_tool_use_id`, `isSynthetic`, `tool_use_result`.
577
+ - `lib/types.ts` — replace the 7-variant flat union with the three-track model above.
578
+ - `client/components/MessageBlock.tsx` — `switch (part.type)` with exhaustive `never` default; new `SubagentCard`, `SkillCard`, `ServerToolCard` components.