@kabmo-labs/kabmo 0.24.0 → 0.26.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.
Files changed (325) hide show
  1. package/dist/client/index.html +1 -1
  2. package/dist/client/index.js +585 -512
  3. package/dist/client/static/js/{index-jcr5twtp.js → index-95b3n20k.js} +1105 -1207
  4. package/dist/client/static/js/index-p2yw9ywf.css +1 -0
  5. package/package.json +2 -4
  6. package/src/cli/lib/args.js +24 -1
  7. package/src/cli/lib/args.test.js +16 -0
  8. package/src/cli/lib/commands/session.js +233 -0
  9. package/src/cli/lib/commands/session.test.js +103 -0
  10. package/src/cli/main.js +1 -1
  11. package/src/client/components/common/ComposerPicker.tsx +3 -0
  12. package/src/client/components/common/code-surface/shiki.test.ts +82 -0
  13. package/src/client/components/common/code-surface/shiki.ts +28 -7
  14. package/src/client/components/common/session-actions-menu/index.tsx +59 -2
  15. package/src/client/components/common/session-branch/BranchGuides.tsx +93 -0
  16. package/src/client/components/common/session-branch/SubagentRow.tsx +77 -0
  17. package/src/client/components/common/session-branch/index.tsx +169 -0
  18. package/src/client/components/common/session-branch/session-branch.test.tsx +240 -0
  19. package/src/client/components/common/session-branch/style.ts +29 -0
  20. package/src/client/components/common/session-row/StatusSlot.tsx +17 -5
  21. package/src/client/components/common/session-row/index.tsx +28 -3
  22. package/src/client/components/common/session-row/session-row.test.tsx +11 -0
  23. package/src/client/components/common/session-state-provider/index.tsx +1 -1
  24. package/src/client/components/layout/desktop-layout/resizer/separator-drag.ts +3 -3
  25. package/src/client/components/layout/session-sidebar/CategoryItem.tsx +70 -61
  26. package/src/client/components/layout/session-sidebar/SessionItem.batch.test.ts +3 -3
  27. package/src/client/components/layout/session-sidebar/SessionItem.test.ts +25 -2
  28. package/src/client/components/layout/session-sidebar/SessionItem.tsx +35 -7
  29. package/src/client/components/layout/session-sidebar/about-modal/HarnessRow.tsx +261 -0
  30. package/src/client/components/layout/session-sidebar/about-modal/HarnessTable.tsx +39 -198
  31. package/src/client/components/layout/session-sidebar/about-modal/HarnessTableLog.test.tsx +114 -0
  32. package/src/client/components/layout/session-sidebar/about-modal/UpdateLogDialog.test.tsx +130 -0
  33. package/src/client/components/layout/session-sidebar/about-modal/UpdateLogDialog.tsx +128 -0
  34. package/src/client/components/layout/session-sidebar/about-modal/UpdateLogLine.tsx +56 -0
  35. package/src/client/components/layout/session-sidebar/about-modal/index.tsx +44 -36
  36. package/src/client/components/layout/session-sidebar/modern/WorkspaceSection.tsx +62 -47
  37. package/src/client/components/mobile/mobile-session-sidebar/Item.tsx +63 -50
  38. package/src/client/components/mobile/mobile-session-sidebar/SessionRow.test.ts +5 -0
  39. package/src/client/components/mobile/mobile-session-sidebar/SessionRow.tsx +37 -12
  40. package/src/client/components/settings/Sidebar.tsx +1 -1
  41. package/src/client/components/settings/categories/NotificationSettings.test.tsx +92 -0
  42. package/src/client/components/settings/categories/NotificationSettings.tsx +112 -2
  43. package/src/client/components/settings/categories/harness-settings/HarnessCard.tsx +1 -1
  44. package/src/client/components/workspace/chat-timeline/AiMessageFooter.fork.test.ts +94 -0
  45. package/src/client/components/workspace/chat-timeline/AiMessageFooter.tsx +31 -5
  46. package/src/client/components/workspace/chat-timeline/ComposerDock.tsx +64 -70
  47. package/src/client/components/workspace/chat-timeline/ComposerDockFrame.tsx +35 -0
  48. package/src/client/components/workspace/chat-timeline/EmptyWorkspacePrompt.tsx +128 -122
  49. package/src/client/components/workspace/chat-timeline/MessageItem.tsx +22 -1
  50. package/src/client/components/workspace/chat-timeline/MessageList.tsx +11 -5
  51. package/src/client/components/workspace/chat-timeline/PendingChatView.tsx +10 -0
  52. package/src/client/components/workspace/chat-timeline/RunFooter.tsx +12 -3
  53. package/src/client/components/workspace/chat-timeline/TimelineBody.tsx +3 -0
  54. package/src/client/components/workspace/chat-timeline/chat-input/AttachmentToolbar.tsx +2 -0
  55. package/src/client/components/workspace/chat-timeline/chat-input/ModeToggles.tsx +15 -1
  56. package/src/client/components/workspace/chat-timeline/chat-input/SessionModeDropdown.test.tsx +85 -0
  57. package/src/client/components/workspace/chat-timeline/chat-input/SessionModeDropdown.tsx +84 -0
  58. package/src/client/components/workspace/chat-timeline/chat-input/Toolbar.tsx +2 -0
  59. package/src/client/components/workspace/chat-timeline/chat-input/modes-props.ts +5 -0
  60. package/src/client/components/workspace/chat-timeline/composer-dock-frame.test.tsx +155 -0
  61. package/src/client/components/workspace/chat-timeline/index.tsx +11 -20
  62. package/src/client/components/workspace/chat-timeline/target-picker/DraftTargetRow.tsx +115 -0
  63. package/src/client/components/workspace/chat-timeline/target-picker/ParentSessionPicker.tsx +173 -0
  64. package/src/client/components/workspace/chat-timeline/target-picker/parent-session-options.test.ts +49 -0
  65. package/src/client/components/workspace/terminal-panel/KeyBar.tsx +10 -8
  66. package/src/client/components/workspace/terminal-panel/{RealtimeXtermView.tsx → RealtimeTerminalView.tsx} +51 -58
  67. package/src/client/components/workspace/terminal-panel/fit.test.ts +37 -0
  68. package/src/client/components/workspace/terminal-panel/fit.ts +64 -0
  69. package/src/client/components/workspace/terminal-panel/fonts.test.ts +161 -0
  70. package/src/client/components/workspace/terminal-panel/fonts.ts +164 -0
  71. package/src/client/components/workspace/terminal-panel/grid.test.ts +52 -0
  72. package/src/client/components/workspace/terminal-panel/grid.ts +118 -0
  73. package/src/client/components/workspace/terminal-panel/index.tsx +25 -21
  74. package/src/client/components/workspace/terminal-panel/mount.ts +247 -223
  75. package/src/client/components/workspace/terminal-panel/navigation.test.ts +54 -0
  76. package/src/client/components/workspace/terminal-panel/navigation.ts +47 -0
  77. package/src/client/data/settings/omp-schema.json +1 -1
  78. package/src/client/data/theme/terminal.test.ts +25 -0
  79. package/src/client/data/theme/terminal.ts +96 -79
  80. package/src/client/hooks/chat/composer/items.test.ts +31 -26
  81. package/src/client/hooks/chat/composer/pick-mapping.test.ts +42 -0
  82. package/src/client/hooks/chat/omp/folder-auto-expand.ts +1 -1
  83. package/src/client/hooks/chat/omp/pending-adoption.ts +51 -0
  84. package/src/client/hooks/chat/omp/pending-child.test.ts +73 -0
  85. package/src/client/hooks/chat/omp/pending-entry.ts +59 -0
  86. package/src/client/hooks/chat/omp/pending-rows.ts +6 -2
  87. package/src/client/hooks/chat/omp/pending-sessions.test.ts +1 -2
  88. package/src/client/hooks/chat/omp/pending-sessions.ts +45 -69
  89. package/src/client/hooks/chat/omp/pending-waiting.ts +1 -1
  90. package/src/client/hooks/chat/omp/prompt-send.test.ts +7 -7
  91. package/src/client/hooks/chat/omp/prompt-send.ts +26 -14
  92. package/src/client/hooks/chat/omp/run-switch.ts +1 -1
  93. package/src/client/hooks/chat/omp/session-list.tsx +4 -0
  94. package/src/client/hooks/chat/subagents/roster.ts +122 -0
  95. package/src/client/hooks/chat/timeline/child-spawn.test.ts +55 -0
  96. package/src/client/hooks/chat/timeline/child-spawn.ts +45 -0
  97. package/src/client/hooks/chat/timeline/fork-request.test.ts +54 -0
  98. package/src/client/hooks/chat/timeline/fork-request.ts +43 -0
  99. package/src/client/hooks/chat/timeline/mode-availability.test.ts +1 -1
  100. package/src/client/hooks/chat/timeline/mode-availability.ts +33 -0
  101. package/src/client/hooks/chat/timeline/mode-markers.ts +7 -1
  102. package/src/client/hooks/chat/timeline/mode-post.ts +15 -3
  103. package/src/client/hooks/chat/timeline/modes-contract.ts +9 -4
  104. package/src/client/hooks/chat/timeline/modes.test.ts +56 -18
  105. package/src/client/hooks/chat/timeline/modes.ts +42 -29
  106. package/src/client/hooks/chat/timeline/pending-branch.ts +205 -0
  107. package/src/client/hooks/chat/timeline/pending-dispatch.ts +253 -0
  108. package/src/client/hooks/chat/timeline/prompt-text.test.ts +34 -1
  109. package/src/client/hooks/chat/timeline/prompt-text.ts +47 -20
  110. package/src/client/hooks/chat/timeline/send-execute.test.ts +39 -0
  111. package/src/client/hooks/chat/timeline/send-helpers.ts +30 -1
  112. package/src/client/hooks/chat/timeline/send-steer.test.ts +3 -1
  113. package/src/client/hooks/chat/timeline/send.test-util.ts +7 -1
  114. package/src/client/hooks/chat/timeline/send.test.ts +3 -1
  115. package/src/client/hooks/chat/timeline/send.ts +48 -133
  116. package/src/client/hooks/chat/timeline/session-harness.ts +6 -0
  117. package/src/client/hooks/chat/timeline/stop-with-queue.ts +42 -0
  118. package/src/client/hooks/chat/timeline/use-fork-session.ts +58 -0
  119. package/src/client/hooks/models/use-harness-update.test.ts +286 -0
  120. package/src/client/hooks/models/use-harness-update.ts +250 -0
  121. package/src/client/hooks/ui/input-required-alert.ts +12 -5
  122. package/src/client/hooks/ui/notifications.ts +45 -0
  123. package/src/client/hooks/ui/run-outcome-alert.ts +48 -0
  124. package/src/client/hooks/workspace/expanded-sessions.ts +36 -7
  125. package/src/client/hooks/workspace/terminal/index.ts +17 -3
  126. package/src/client/hooks/workspace/terminal/socket.ts +9 -4
  127. package/src/client/lib/native/open-session.ts +33 -0
  128. package/src/client/lib/notifications/os.test.ts +125 -0
  129. package/src/client/lib/notifications/os.ts +130 -0
  130. package/src/client/lib/plugins/sidebar-bridge.ts +2 -20
  131. package/src/client/lib/router/open-session.test.ts +75 -0
  132. package/src/client/lib/router/open-session.ts +34 -0
  133. package/src/client/lib/session-tree.test.ts +50 -0
  134. package/src/client/lib/session-tree.ts +59 -0
  135. package/src/client/lib/signals.ts +5 -1
  136. package/src/client/main.tsx +6 -0
  137. package/src/client/tailwind.css +17 -11
  138. package/src/server/index.ts +2 -0
  139. package/src/server/lib/auth/guard.ts +10 -0
  140. package/src/server/lib/btw/session-copy.server.ts +6 -44
  141. package/src/server/lib/btw/session-copy.test.ts +2 -1
  142. package/src/server/lib/db/schema.ts +5 -0
  143. package/src/server/lib/db/seed-terminal.test.ts +1 -1
  144. package/src/server/lib/db/seed.test.ts +1 -1
  145. package/src/server/lib/harness/acp/background-work.test.ts +262 -0
  146. package/src/server/lib/harness/acp/background-work.ts +320 -0
  147. package/src/server/lib/harness/acp/calls.ts +15 -1
  148. package/src/server/lib/harness/acp/client-capabilities.test.ts +55 -0
  149. package/src/server/lib/harness/acp/client-capabilities.ts +61 -0
  150. package/src/server/lib/harness/acp/client-fs.test.ts +135 -0
  151. package/src/server/lib/harness/acp/client-fs.ts +131 -0
  152. package/src/server/lib/harness/acp/client-initialize.test.ts +70 -0
  153. package/src/server/lib/harness/acp/client-initialize.ts +84 -0
  154. package/src/server/lib/harness/acp/client.ts +33 -23
  155. package/src/server/lib/harness/acp/commands.test.ts +5 -5
  156. package/src/server/lib/harness/acp/commands.ts +14 -2
  157. package/src/server/lib/harness/acp/frames-timing.test.ts +68 -0
  158. package/src/server/lib/harness/acp/frames-v2.test.ts +85 -0
  159. package/src/server/lib/harness/acp/frames.ts +71 -158
  160. package/src/server/lib/harness/acp/gateway-env.test.ts +64 -0
  161. package/src/server/lib/harness/acp/gateway-env.ts +70 -0
  162. package/src/server/lib/harness/acp/mapper.test.ts +40 -0
  163. package/src/server/lib/harness/acp/mapper.ts +12 -0
  164. package/src/server/lib/harness/acp/permissions.ts +6 -0
  165. package/src/server/lib/harness/acp/prompt.test.ts +20 -0
  166. package/src/server/lib/harness/acp/prompt.ts +19 -3
  167. package/src/server/lib/harness/acp/protocol.ts +41 -2
  168. package/src/server/lib/harness/acp/session-background.test.ts +129 -0
  169. package/src/server/lib/harness/acp/session-exit.ts +31 -0
  170. package/src/server/lib/harness/acp/session-facts.ts +1 -1
  171. package/src/server/lib/harness/acp/session-handshake.test.ts +197 -0
  172. package/src/server/lib/harness/acp/session-handshake.ts +110 -7
  173. package/src/server/lib/harness/acp/session-idle.ts +7 -6
  174. package/src/server/lib/harness/acp/session-listeners.ts +31 -0
  175. package/src/server/lib/harness/acp/session-notifications.ts +41 -2
  176. package/src/server/lib/harness/acp/session-observers.test.ts +63 -0
  177. package/src/server/lib/harness/acp/session-permissions.test.ts +29 -0
  178. package/src/server/lib/harness/acp/session-permissions.ts +36 -0
  179. package/src/server/lib/harness/acp/session-requests.test.ts +92 -0
  180. package/src/server/lib/harness/acp/session-requests.ts +89 -0
  181. package/src/server/lib/harness/acp/session-turns.ts +28 -8
  182. package/src/server/lib/harness/acp/session-usage.ts +4 -0
  183. package/src/server/lib/harness/acp/session-web-state.ts +30 -2
  184. package/src/server/lib/harness/acp/session.test-util.ts +42 -2
  185. package/src/server/lib/harness/acp/session.ts +115 -115
  186. package/src/server/lib/harness/acp/tool-calls.ts +223 -0
  187. package/src/server/lib/harness/acp/turn.test.ts +183 -0
  188. package/src/server/lib/harness/acp/turn.ts +102 -10
  189. package/src/server/lib/harness/acp/v2.test.ts +144 -0
  190. package/src/server/lib/harness/acp/v2.ts +220 -0
  191. package/src/server/lib/harness/acp/verbs.ts +58 -8
  192. package/src/server/lib/harness/launch.test.ts +25 -0
  193. package/src/server/lib/harness/launch.ts +24 -10
  194. package/src/server/lib/harness/session.ts +3 -0
  195. package/src/server/lib/harness/spawn.server.ts +15 -2
  196. package/src/server/lib/harness/update-job-store.test.ts +151 -0
  197. package/src/server/lib/harness/update-job-store.ts +115 -0
  198. package/src/server/lib/harness/update-job.server.ts +94 -0
  199. package/src/server/lib/harness/update-queue.server.ts +292 -0
  200. package/src/server/lib/harness/update-queue.test.ts +265 -0
  201. package/src/server/lib/harness/update-spawn.server.ts +96 -0
  202. package/src/server/lib/harness/update-worker.test.ts +153 -0
  203. package/src/server/lib/harness/update-worker.ts +202 -0
  204. package/src/server/lib/lifecycle/after-listen.ts +9 -0
  205. package/src/server/lib/lifecycle/paths.ts +28 -0
  206. package/src/server/lib/omp/rpc/manager.ts +5 -5
  207. package/src/server/lib/omp/rpc/prewarm-pool.ts +12 -3
  208. package/src/server/lib/omp/rpc/run-settle.server.ts +10 -1
  209. package/src/server/lib/omp/rpc/session-registry.ts +14 -2
  210. package/src/server/lib/omp/rpc/subagent-liveness.ts +5 -5
  211. package/src/server/lib/omp/rpc/terminal-settle.ts +58 -6
  212. package/src/server/lib/omp/session/delete-flow.server.ts +48 -0
  213. package/src/server/lib/omp/session/delete.server.ts +5 -0
  214. package/src/server/lib/omp/session/rewind-file.ts +39 -21
  215. package/src/server/lib/omp/session/sidebar-data.server.ts +16 -18
  216. package/src/server/lib/omp/session/transcript-copy.ts +123 -0
  217. package/src/server/lib/sessions/agent-token.server.test.ts +64 -0
  218. package/src/server/lib/sessions/agent-token.server.ts +134 -0
  219. package/src/server/lib/sessions/answers.server.test.ts +33 -0
  220. package/src/server/lib/sessions/answers.server.ts +37 -0
  221. package/src/server/lib/sessions/dispatch.server.test.ts +143 -0
  222. package/src/server/lib/sessions/dispatch.server.ts +128 -0
  223. package/src/server/lib/sessions/fork.server.test.ts +277 -0
  224. package/src/server/lib/sessions/fork.server.ts +329 -0
  225. package/src/server/lib/sessions/lifecycle.server.test.ts +75 -0
  226. package/src/server/lib/sessions/lifecycle.server.ts +71 -0
  227. package/src/server/lib/sessions/notify.server.test.ts +112 -0
  228. package/src/server/lib/sessions/notify.server.ts +212 -0
  229. package/src/server/lib/sessions/relation-types.ts +76 -0
  230. package/src/server/lib/sessions/relations.server.test.ts +207 -0
  231. package/src/server/lib/sessions/relations.server.ts +337 -0
  232. package/src/server/lib/sessions/resolve.server.ts +106 -0
  233. package/src/server/lib/sessions/schema.server.ts +82 -0
  234. package/src/server/lib/sessions/sidebar-relations.server.test.ts +61 -0
  235. package/src/server/lib/sessions/sidebar-relations.server.ts +47 -0
  236. package/src/server/lib/sessions/spawn.server.test.ts +237 -0
  237. package/src/server/lib/sessions/spawn.server.ts +335 -0
  238. package/src/server/lib/terminal/attach-replay.test.ts +2 -2
  239. package/src/server/lib/terminal/output.test.ts +2 -2
  240. package/src/server/lib/terminal/output.ts +1 -1
  241. package/src/server/lib/terminal/resize.test.ts +99 -0
  242. package/src/server/lib/terminal/runtime.server.ts +26 -6
  243. package/src/server/lib/terminal/send-result.test.ts +18 -1
  244. package/src/server/lib/terminal/send-result.ts +26 -2
  245. package/src/server/lib/terminal/session.server.ts +6 -6
  246. package/src/server/lib/usage/new-api.test.ts +92 -0
  247. package/src/server/lib/usage/new-api.ts +131 -0
  248. package/src/server/lib/usage/provider-endpoint.test.ts +106 -0
  249. package/src/server/lib/usage/provider-key.ts +33 -0
  250. package/src/server/lib/usage/providers.server.ts +10 -3
  251. package/src/server/lib/usage/vendor-balance.server.ts +4 -53
  252. package/src/server/lib/usage/vendor-http.ts +41 -0
  253. package/src/server/lib/usage/window.ts +55 -0
  254. package/src/server/routes/agent/command.ts +14 -1
  255. package/src/server/routes/agent/harness-command.ts +12 -5
  256. package/src/server/routes/agent/new.ts +15 -0
  257. package/src/server/routes/chat/stream.ts +7 -2
  258. package/src/server/routes/harness/add-provider.test.ts +9 -1
  259. package/src/server/routes/harness/import-action.ts +4 -0
  260. package/src/server/routes/harness/import.test.ts +1 -1
  261. package/src/server/routes/harness/index.ts +5 -1
  262. package/src/server/routes/harness/update-status.ts +32 -0
  263. package/src/server/routes/harness/update.test.ts +156 -0
  264. package/src/server/routes/harness/update.ts +64 -147
  265. package/src/server/routes/sessions/answer.ts +24 -0
  266. package/src/server/routes/sessions/batch-delete.ts +11 -5
  267. package/src/server/routes/sessions/body-readers.ts +43 -0
  268. package/src/server/routes/sessions/delete.ts +4 -2
  269. package/src/server/routes/sessions/fork.ts +89 -0
  270. package/src/server/routes/sessions/index.ts +14 -0
  271. package/src/server/routes/sessions/relations.ts +85 -0
  272. package/src/server/routes/sessions/routes.test.ts +1 -2
  273. package/src/server/routes/sessions/session.ts +23 -0
  274. package/src/server/routes/sessions/spawn.ts +137 -0
  275. package/src/server/routes/terminal/ws.ts +3 -3
  276. package/src/shared/lib/chat/composer/client.ts +31 -2
  277. package/src/shared/lib/chat/composer/delegation.test.ts +93 -0
  278. package/src/shared/lib/chat/composer/delegation.ts +206 -0
  279. package/src/shared/lib/chat/notice-text.ts +1 -1
  280. package/src/shared/lib/chat/omp/agent-events.ts +11 -0
  281. package/src/shared/lib/chat/omp/session-modes-signal.test.ts +41 -0
  282. package/src/shared/lib/chat/tool/summary-wait.test.ts +11 -0
  283. package/src/shared/lib/code/ansi.ts +1 -1
  284. package/src/shared/lib/fonts/nerd-symbols.css +4 -3
  285. package/src/shared/lib/fonts/nerd-symbols.test.ts +9 -9
  286. package/src/shared/lib/harness/mode-signal.ts +20 -0
  287. package/src/shared/lib/harness/provider-facts.test.ts +27 -0
  288. package/src/shared/lib/harness/providers.ts +35 -1
  289. package/src/shared/lib/harness/session-modes.ts +24 -0
  290. package/src/shared/lib/harness/update-job.ts +80 -0
  291. package/src/shared/lib/harness/update-plan.test.ts +21 -6
  292. package/src/shared/lib/harness/update-plan.ts +12 -4
  293. package/src/shared/lib/icons/tint-hues.generated.ts +34 -34
  294. package/src/shared/lib/notifications/outcomes.test.ts +96 -0
  295. package/src/shared/lib/notifications/outcomes.ts +64 -0
  296. package/src/shared/lib/notifications/settings.test.ts +49 -0
  297. package/src/shared/lib/notifications/settings.ts +34 -0
  298. package/src/shared/lib/omp/session/default-title.ts +5 -4
  299. package/src/shared/lib/omp/session/prewarm-misc.test.ts +3 -2
  300. package/src/shared/lib/omp/session/schema-migrations.ts +4 -0
  301. package/src/shared/lib/omp/session/stream-state.server.test.ts +19 -0
  302. package/src/shared/lib/omp/session/stream-state.server.ts +24 -4
  303. package/src/shared/lib/omp/session/wait-idle.test.ts +11 -0
  304. package/src/shared/lib/omp/session/wait-idle.ts +12 -2
  305. package/src/shared/lib/settings/defaults.ts +3 -0
  306. package/src/shared/lib/theme/catalog.test.ts +13 -9
  307. package/src/shared/lib/theme/color.test.ts +2 -2
  308. package/src/shared/lib/theme/color.ts +4 -4
  309. package/src/shared/lib/theme/theme.test.ts +1 -1
  310. package/src/shared/lib/workspace/terminal/input.test.ts +27 -0
  311. package/src/shared/lib/workspace/terminal/input.ts +33 -0
  312. package/src/shared/lib/workspace/terminal/keys.test.ts +1 -1
  313. package/src/shared/lib/workspace/terminal/keys.ts +7 -7
  314. package/src/shared/types/chat.ts +1 -1
  315. package/src/shared/types/harness-update.ts +89 -0
  316. package/src/shared/types/omp/agent.ts +19 -2
  317. package/src/shared/types/realtime.ts +2 -0
  318. package/src/shared/types/settings/state.ts +10 -0
  319. package/src/shared/types/workspace.ts +8 -0
  320. package/src/test-support/fake-omp-fork.ts +16 -2
  321. package/src/test-support/harness-table.test-util.ts +31 -1
  322. package/dist/client/static/js/index-z3w7n85q.css +0 -1
  323. package/src/client/components/common/subagent-list/index.tsx +0 -165
  324. package/src/client/components/workspace/terminal-panel/webgl.test.ts +0 -75
  325. package/src/client/components/workspace/terminal-panel/webgl.ts +0 -108
@@ -42,36 +42,12 @@
42
42
  */
43
43
 
44
44
  import { useEffect, useState } from 'preact/hooks';
45
+ import { recordAdoption } from '@/client/hooks/chat/omp/pending-adoption';
46
+ import type { PendingSessionEntry } from '@/client/hooks/chat/omp/pending-entry';
45
47
  import { pendingSessionCreatedAt, sessionIdEpochMs } from '@/shared/lib/omp/session/default-title';
46
48
  import { getSessionState } from '@/shared/lib/workspace/session-state/store';
47
49
  import { hasComposerDraft } from '@/shared/lib/chat/composer/draft';
48
50
 
49
- export interface PendingSessionEntry {
50
- /** Client-side `new-<epoch>` id, or the omp UUID a spawn adopted. */
51
- id: string;
52
- /** The folder the row belongs to; null resolves from the active session. */
53
- folderId: number | string | null;
54
- /** Epoch ms the chat was started — stable across adoption and reloads, so
55
- * neither the title nor the ordering can churn on a revalidate. */
56
- createdAt: number;
57
- /** Epoch ms a prompt was dispatched for this chat, or null while it is a
58
- * draft the user has not sent in. */
59
- sentAt: number | null;
60
- /**
61
- * Set while this chat's prompt is HELD for another session to finish.
62
- *
63
- * The row is drawn exactly as it was before the send — same id, same folder —
64
- * because the session does not exist yet: what the user asked for is that the
65
- * row stays put and says what it is waiting on. `waitId` is the server row
66
- * that owns the wait, so cancelling from the row reaches it.
67
- */
68
- waiting?: {
69
- waitId: string;
70
- dependsOn: string;
71
- dependsOnTitle: string | null;
72
- };
73
- }
74
-
75
51
  /** How long a SENT entry may outlive its switch with no real row behind it.
76
52
  * Measured against omp's own write (buffered until the first assistant message
77
53
  * settles, ~17s), so it is set comfortably past that. */
@@ -81,11 +57,6 @@ export const PENDING_SETTLE_MS = 30_000;
81
57
  export const MAX_UNSENT_DRAFTS = 3;
82
58
 
83
59
  const entries = new Map<string, PendingSessionEntry>();
84
- /** `toId → fromId` for a spawn adoption, consumed by the session-state
85
- * provider so a plain switch away from a pending chat cannot be mistaken for
86
- * one. Bounded by the pending store itself: an entry is written where an
87
- * adoption happens and dropped the moment it is claimed. */
88
- const adoptions = new Map<string, string>();
89
60
  const listeners = new Set<() => void>();
90
61
 
91
62
  function emit(): void {
@@ -111,6 +82,11 @@ function upsert(entry: PendingSessionEntry): void {
111
82
  && current.folderId === entry.folderId
112
83
  && current.createdAt === entry.createdAt
113
84
  && current.sentAt === entry.sentAt
85
+ && current.parentSessionId === entry.parentSessionId
86
+ && current.harness === entry.harness
87
+ && current.title === entry.title
88
+ && current.forkSourceSessionId === entry.forkSourceSessionId
89
+ && current.forkAnchorEntryId === entry.forkAnchorEntryId
114
90
  && sameWait
115
91
  ) {
116
92
  return;
@@ -125,8 +101,22 @@ function upsert(entry: PendingSessionEntry): void {
125
101
  * The id is what the URL carries (`?sessionId=new-…`) until a spawn adopts a
126
102
  * real one, so the caller writes the returned value rather than minting its own
127
103
  * — an id the store does not know is a row nothing can draw.
104
+ *
105
+ * `options` is what makes the row a CHILD: the parent it nests under, the
106
+ * harness its mark should draw, and the title that says "New Child". A child is
107
+ * still a pending chat — same store, same lifetime rules — only its branch slot
108
+ * differs.
128
109
  */
129
- export function startPendingSession(folderId: number | string | null): string {
110
+ export function startPendingSession(
111
+ folderId: number | string | null,
112
+ options: {
113
+ parentSessionId?: string;
114
+ harness?: string;
115
+ title?: string;
116
+ forkSourceSessionId?: string;
117
+ forkAnchorEntryId?: string;
118
+ } = {},
119
+ ): string {
130
120
  // `new-<epochMs>` stays parseable by `pendingSessionCreatedAt`, which is what
131
121
  // keeps the row's title and stamp still across revalidates — so two clicks in
132
122
  // the same millisecond step the clock instead of gaining a suffix, which
@@ -134,7 +124,17 @@ export function startPendingSession(folderId: number | string | null): string {
134
124
  let epoch = Date.now();
135
125
  while (entries.has(`new-${epoch}`)) epoch += 1;
136
126
  const id = `new-${epoch}`;
137
- upsert({ id, folderId, createdAt: epoch, sentAt: null });
127
+ upsert({
128
+ id,
129
+ folderId,
130
+ createdAt: epoch,
131
+ sentAt: null,
132
+ ...(options.parentSessionId ? { parentSessionId: options.parentSessionId } : {}),
133
+ ...(options.harness ? { harness: options.harness } : {}),
134
+ ...(options.title ? { title: options.title } : {}),
135
+ ...(options.forkSourceSessionId ? { forkSourceSessionId: options.forkSourceSessionId } : {}),
136
+ ...(options.forkAnchorEntryId ? { forkAnchorEntryId: options.forkAnchorEntryId } : {}),
137
+ });
138
138
  // Repeated New Session clicks are the one way this map grows without a
139
139
  // bound: each click is a row the user may never send in. Oldest drafts go,
140
140
  // and a SENT entry is never a candidate — its transcript is on the way.
@@ -171,52 +171,23 @@ export function adoptPendingSession(
171
171
  // Recorded for the session-state provider, which must NOT carry the pending
172
172
  // slot's UI state onto just any id the URL moves to — only onto the one a
173
173
  // spawn answered with. See `consumeAdoption`.
174
- if (fromId) adoptions.set(toId, fromId);
174
+ if (fromId) recordAdoption(fromId, toId);
175
175
  upsert({
176
176
  id: toId,
177
177
  folderId: from?.folderId ?? folderId ?? null,
178
178
  createdAt: from?.createdAt ?? createdAtFor(toId),
179
179
  sentAt: from?.sentAt ?? Date.now(),
180
+ // The child stays a child (and keeps its harness and "New Child" title)
181
+ // across the id switch, so the row does not jump out of its branch or
182
+ // change its mark while the real session's own title is still on the way.
183
+ ...(from?.parentSessionId ? { parentSessionId: from.parentSessionId } : {}),
184
+ ...(from?.harness ? { harness: from.harness } : {}),
185
+ ...(from?.title ? { title: from.title } : {}),
180
186
  // The wait ended when the spawn answered: the new row is a real session
181
187
  // from this moment, and a cue left on it would say it is still held.
182
188
  });
183
189
  }
184
190
 
185
- /**
186
- * Whether `toId` is the id a spawn answered with for `fromId` — consuming the
187
- * record so one adoption is claimed once.
188
- *
189
- * The session-state provider used to treat EVERY move away from a `new-…` id as
190
- * an adoption and migrate the transient slot's whole UI state onto whatever the
191
- * URL now named. Clicking another session from a pending chat is the same
192
- * transition, so the pending chat's DRAFT was copied into that session and
193
- * persisted there (measured: a POST for the other session carrying
194
- * `chat.draft`). Only a real spawn may carry the state across.
195
- */
196
- export function consumeAdoption(fromId: string | null | undefined, toId: string): boolean {
197
- if (!fromId || adoptions.get(toId) !== fromId) return false;
198
- adoptions.delete(toId);
199
- return true;
200
- }
201
-
202
- /**
203
- * Whether `toId` is the id a spawn answered with for `fromId`, WITHOUT claiming
204
- * the record.
205
- *
206
- * The agent hook asks a different question from the session-state provider's:
207
- * not "may I carry this UI state across", but "is this the SAME conversation
208
- * under a new id". A spawn adoption is exactly that, and treating it as a
209
- * session switch threw away the run's own bookkeeping — `toolResultsRef` and
210
- * `lastToolMessageRef` — in the middle of the first turn: measured in a browser
211
- * spec, the tool-call map was cleared between two progress frames, so every
212
- * later `tool_execution_update`/`_end` had no target to pair onto and the card
213
- * froze at `running` for the rest of the session. The provider still owns the
214
- * single claim (`consumeAdoption`), so peeking here cannot steal it.
215
- */
216
- export function isSpawnAdoption(fromId: string | null | undefined, toId: string): boolean {
217
- return Boolean(fromId) && adoptions.get(toId) === fromId;
218
- }
219
-
220
191
  /**
221
192
  * Register an id the URL names but this store does not know.
222
193
  *
@@ -267,6 +238,11 @@ export function listPendingSessions(): PendingSessionEntry[] {
267
238
  return [...entries.values()];
268
239
  }
269
240
 
241
+ /** One entry by id — the send path's read of the chat's own parent. */
242
+ export function pendingEntryFor(id: string | null | undefined): PendingSessionEntry | undefined {
243
+ return id ? entries.get(id) : undefined;
244
+ }
245
+
270
246
  /** Drop the entries the authoritative list has superseded, plus stale sends. */
271
247
  export function reconcilePendingSessions(input: {
272
248
  /** Session ids the structure's own payload carries. */
@@ -13,7 +13,7 @@
13
13
  * written through the same map, the same emit and the same no-op check.
14
14
  */
15
15
 
16
- import type { PendingSessionEntry } from '@/client/hooks/chat/omp/pending-sessions';
16
+ import type { PendingSessionEntry } from '@/client/hooks/chat/omp/pending-entry';
17
17
  import { listPendingSessions, patchPendingEntry } from '@/client/hooks/chat/omp/pending-sessions';
18
18
 
19
19
  export type PendingWait = NonNullable<PendingSessionEntry['waiting']>;
@@ -222,7 +222,7 @@ describe('useOmpPromptSender.sendNewPrompt — ordering', () => {
222
222
  return false;
223
223
  });
224
224
 
225
- expect(result).toEqual({ sessionId: 'omp-5', model: null });
225
+ expect(result).toEqual({ ok: true, session: { sessionId: 'omp-5', model: null } });
226
226
  expect(order).toEqual([NEW, 'goal:omp-5', '/api/agent/omp-5']);
227
227
  expect(requests.length).toBe(2);
228
228
  });
@@ -254,7 +254,7 @@ describe('useOmpPromptSender.sendNewPrompt', () => {
254
254
  modes: { plan: true, goal: false },
255
255
  });
256
256
 
257
- expect(result).toEqual({ sessionId: 'omp-9', model: { provider: 'anthropic', modelId: 'claude' } });
257
+ expect(result).toEqual({ ok: true, session: { sessionId: 'omp-9', model: { provider: 'anthropic', modelId: 'claude' } } });
258
258
  expect(requests[0].url).toBe(NEW);
259
259
  expect(requests[0].body).toEqual({
260
260
  type: 'ensure_session',
@@ -278,21 +278,21 @@ describe('useOmpPromptSender.sendNewPrompt', () => {
278
278
 
279
279
  expect(requests[0].body).toEqual({ type: 'ensure_session', cwd: '/w' });
280
280
  expect(requests[1].body).toEqual({ type: 'prompt', message: 'first' });
281
- expect(result).toEqual({ sessionId: 'omp-1', model: null });
281
+ expect(result).toEqual({ ok: true, session: { sessionId: 'omp-1', model: null } });
282
282
  });
283
283
 
284
- test('a create failure returns null without connecting or prompting', async () => {
284
+ test('a create failure returns the server reason without connecting or prompting', async () => {
285
285
  const requests = installFetch({ [NEW]: { status: 500, body: { error: 'no workspace' } } });
286
286
  const probe = mountSender(null);
287
287
  const result = await probe.sender().sendNewPrompt('first', '/w');
288
288
 
289
- expect(result).toBeNull();
289
+ expect(result).toEqual({ ok: false, error: 'no workspace' });
290
290
  expect(requests.length).toBe(1);
291
291
  expect(probe.connected).toEqual([]);
292
292
  expect(probe.state().error).toBe('no workspace');
293
293
  });
294
294
 
295
- test('a prompt failure returns null even though the session was created', async () => {
295
+ test('a prompt failure returns the reason even though the session was created', async () => {
296
296
  const requests = installFetch({ [NEW]: { body: { success: true, sessionId: 'omp-3' } } });
297
297
  let call = 0;
298
298
  (globalThis as unknown as Record<string, unknown>).fetch = async (input: unknown, init?: { method?: string; body?: string }) => {
@@ -305,7 +305,7 @@ describe('useOmpPromptSender.sendNewPrompt', () => {
305
305
  const probe = mountSender(null);
306
306
  const result = await probe.sender().sendNewPrompt('first', '/w');
307
307
 
308
- expect(result).toBeNull();
308
+ expect(result).toEqual({ ok: false, error: 'boom' });
309
309
  expect(probe.connected).toEqual(['omp-3']);
310
310
  expect(probe.state().isGenerating).toBe(false);
311
311
  });
@@ -20,7 +20,7 @@ import { useCallback } from 'preact/hooks';
20
20
  import type { Dispatch, SetStateAction } from 'preact/compat';
21
21
  import { setSessionTitleHint } from '@/client/hooks/chat/omp/sidebar-overlay';
22
22
  import { redirectToOwningInstance, type SessionOwnerConflict } from '@/client/hooks/chat/omp/owner-redirect';
23
- import type { AgentImage, OmpAgentState, PromptDispatchResult, SpawnOptions, SpawnedSession } from '@/shared/types';
23
+ import type { AgentImage, OmpAgentState, PromptDispatchResult, SpawnOptions, SpawnPromptResult } from '@/shared/types';
24
24
  import type { ApprovalMode } from '@/shared/lib/omp/config/access-mode';
25
25
 
26
26
  export interface OmpPromptSenderDeps {
@@ -49,7 +49,7 @@ export interface OmpPromptSender {
49
49
  * the raw message after it would be a second turn asking the same thing.
50
50
  */
51
51
  beforePrompt?: (sessionId: string) => Promise<boolean>,
52
- ) => Promise<SpawnedSession | null>;
52
+ ) => Promise<SpawnPromptResult>;
53
53
  }
54
54
 
55
55
  export function useOmpPromptSender(deps: OmpPromptSenderDeps): OmpPromptSender {
@@ -114,16 +114,15 @@ export function useOmpPromptSender(deps: OmpPromptSenderDeps): OmpPromptSender {
114
114
  * the prompt through the existing session route so no agent events are
115
115
  * missed. Model/thinking picks ride the ensure_session body so omp applies
116
116
  * them BEFORE the first prompt (and their JSONL change entries are written
117
- * up front, not after the run starts). Returns the new session id on
118
- * success, or null on failure — the caller adopts the id as the active
119
- * session. */
117
+ * up front, not after the run starts). Returns the adopted session, or the
118
+ * server's refusal reason — the caller must report it, never simulate one. */
120
119
  const sendNewPrompt = useCallback(async (
121
120
  message: string,
122
121
  cwd: string,
123
122
  images?: AgentImage[],
124
123
  composerOptions?: SpawnOptions,
125
124
  beforePrompt?: (sessionId: string) => Promise<boolean>,
126
- ): Promise<SpawnedSession | null> => {
125
+ ): Promise<SpawnPromptResult> => {
127
126
  setState((prev) => ({ ...prev, isGenerating: true, error: null }));
128
127
  // The real id does not exist until `ensure_session` answers, so the mark
129
128
  // can only be armed past that point — the spawn itself is covered by the
@@ -151,10 +150,15 @@ export function useOmpPromptSender(deps: OmpPromptSenderDeps): OmpPromptSender {
151
150
  model?: { provider: string; modelId: string } | null;
152
151
  harness?: string;
153
152
  error?: string;
153
+ code?: string;
154
154
  };
155
155
  if (!created.ok || !createdBody.sessionId) {
156
- setState((prev) => ({ ...prev, isGenerating: false, error: createdBody.error ?? `HTTP ${created.status}` }));
157
- return null;
156
+ const error = createdBody.error ?? `HTTP ${created.status}`;
157
+ setState((prev) => ({ ...prev, isGenerating: false, error }));
158
+ // The CODE travels: `mock_mode` is a "there is nothing to spawn here",
159
+ // which the caller answers with the simulated stream rather than an
160
+ // error the operator cannot act on.
161
+ return { ok: false, error, ...(createdBody.code ? { code: createdBody.code } : {}) };
158
162
  }
159
163
  sid = createdBody.sessionId;
160
164
  connect(sid);
@@ -168,7 +172,10 @@ export function useOmpPromptSender(deps: OmpPromptSenderDeps): OmpPromptSender {
168
172
  // is what makes the order a fact rather than a race. An armed interview
169
173
  // answers true: it already opened the turn, so this prompt is not sent.
170
174
  if (beforePrompt && await beforePrompt(sid)) {
171
- return { sessionId: sid, model: createdBody.model ?? null, ...(createdBody.harness ? { harness: createdBody.harness } : {}) };
175
+ return {
176
+ ok: true,
177
+ session: { sessionId: sid, model: createdBody.model ?? null, ...(createdBody.harness ? { harness: createdBody.harness } : {}) },
178
+ };
172
179
  }
173
180
  const res = await fetch(`/api/agent/${encodeURIComponent(sid)}`, {
174
181
  method: 'POST',
@@ -181,13 +188,18 @@ export function useOmpPromptSender(deps: OmpPromptSenderDeps): OmpPromptSender {
181
188
  });
182
189
  const body = (await res.json().catch(() => ({}))) as { success?: boolean; error?: string };
183
190
  if (!res.ok || body.error) {
184
- setState((prev) => ({ ...prev, isGenerating: false, error: body.error ?? `HTTP ${res.status}` }));
185
- return null;
191
+ const error = body.error ?? `HTTP ${res.status}`;
192
+ setState((prev) => ({ ...prev, isGenerating: false, error }));
193
+ return { ok: false, error };
186
194
  }
187
- return { sessionId: sid, model: createdBody.model ?? null, ...(createdBody.harness ? { harness: createdBody.harness } : {}) };
195
+ return {
196
+ ok: true,
197
+ session: { sessionId: sid, model: createdBody.model ?? null, ...(createdBody.harness ? { harness: createdBody.harness } : {}) },
198
+ };
188
199
  } catch (e) {
189
- setState((prev) => ({ ...prev, isGenerating: false, error: e instanceof Error ? e.message : String(e) }));
190
- return null;
200
+ const error = e instanceof Error ? e.message : String(e);
201
+ setState((prev) => ({ ...prev, isGenerating: false, error }));
202
+ return { ok: false, error };
191
203
  }
192
204
  }, [connect, setState]);
193
205
 
@@ -33,7 +33,7 @@
33
33
  * in `wait.e2e.ts` — the settle spec read `Wait Running` for 30s).
34
34
  */
35
35
 
36
- import { isSpawnAdoption } from '@/client/hooks/chat/omp/pending-sessions';
36
+ import { isSpawnAdoption } from '@/client/hooks/chat/omp/pending-adoption';
37
37
 
38
38
  export interface RunSwitchInput {
39
39
  /** The session id this hook last prepared its refs for, or null on mount. */
@@ -29,6 +29,7 @@ import { createContext } from 'preact/compat';
29
29
  import type { ReactNode } from 'preact/compat';
30
30
  import { useRealtimeTopic } from '@/client/hooks/ui/realtime';
31
31
  import { useInputRequiredAlert } from '@/client/hooks/ui/input-required-alert';
32
+ import { useRunOutcomeAlert } from '@/client/hooks/ui/run-outcome-alert';
32
33
 
33
34
  import { realtimeClient } from '@/shared/lib/realtime/client';
34
35
  import { TOPIC_SIDEBAR, TOPIC_SIDEBAR_ACTIVITY, TOPIC_SIDEBAR_STATUS } from '@/shared/lib/realtime/protocol';
@@ -206,6 +207,9 @@ export function SidebarDataProvider({ children, initialFolders = [] }: { childre
206
207
  // Fires for ANY session, including one this tab never opened — the cue that an
207
208
  // agent is blocked on an answer must not depend on the open timeline.
208
209
  useInputRequiredAlert(folders);
210
+ // The same list, for the terminal side of a run: a session that finished
211
+ // while the operator was reading another one is exactly what a banner is for.
212
+ useRunOutcomeAlert(folders);
209
213
 
210
214
  const markSeen = useCallback((sessionId: number | string) => {
211
215
  const key = String(sessionId);
@@ -0,0 +1,122 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * The roster of subagents one session ran, as data.
8
+ *
9
+ * Split out of the list component that used to draw subagents: the tree now
10
+ * draws the rows, and it needs the same roster from the same two sources (the
11
+ * transcript history on disk, plus the live frames for the session that is
12
+ * open). Both passes are unchanged; only the consumer moved.
13
+ */
14
+
15
+ import { useEffect, useState } from 'preact/hooks';
16
+ import { isRecord } from '@/shared/lib/util/guards';
17
+ import { fetchSubagentHistory, historyEntryToSubagentInfo } from '@/shared/lib/omp/subagent/history/client';
18
+ import {
19
+ mergeSubagentRoster,
20
+ parseSubagentLifecycle,
21
+ parseSubagentRosterResponse,
22
+ readSubagentProgressFrame,
23
+ } from '@/shared/lib/omp/subagent/parse';
24
+ import { subscribeSubagentFrame, type SubagentFrame } from '@/shared/lib/chat/omp/subagent-frames';
25
+ import type { SubagentInfo, SubagentProgress } from '@/shared/types';
26
+
27
+ export interface SubagentRoster {
28
+ subagents: SubagentInfo[];
29
+ isLoading: boolean;
30
+ }
31
+
32
+ const PROGRESS_STATUS: Record<NonNullable<SubagentProgress['status']>, SubagentInfo['status']> = {
33
+ pending: 'started', running: 'started', completed: 'completed', failed: 'failed', aborted: 'aborted',
34
+ };
35
+
36
+ /** Fold one progress frame into the roster entry it names (id, else index). */
37
+ function applyProgress(roster: SubagentInfo[], progress: SubagentProgress): SubagentInfo[] {
38
+ return roster.map((entry) => {
39
+ if (progress.id !== undefined) {
40
+ if (entry.id !== progress.id) return entry;
41
+ } else if (progress.index === undefined || progress.index < 0 || entry.index !== progress.index) {
42
+ return entry;
43
+ }
44
+ const status = progress.status && entry.status === 'started'
45
+ ? PROGRESS_STATUS[progress.status] ?? entry.status
46
+ : entry.status;
47
+ return { ...entry, status, progress: { ...entry.progress, ...progress }, lastUpdate: Date.now() };
48
+ });
49
+ }
50
+
51
+ /**
52
+ * The roster for one session.
53
+ *
54
+ * `enabled` is the session's own `hasSubagents` flag: a branch opened for its
55
+ * CHILD SESSIONS must not fire a roster read (history request plus a
56
+ * `get_subagents` snapshot) that can only answer empty.
57
+ */
58
+ export function useSubagentRoster(
59
+ sessionId: string,
60
+ isActiveSession: boolean,
61
+ enabled: boolean,
62
+ ): SubagentRoster {
63
+ const [subagents, setSubagents] = useState<SubagentInfo[]>([]);
64
+ const [isLoading, setIsLoading] = useState(false);
65
+
66
+ useEffect(() => {
67
+ if (!enabled) return;
68
+ let cancelled = false;
69
+ setSubagents([]);
70
+ setIsLoading(true);
71
+ void fetchSubagentHistory(sessionId)
72
+ .then((entries) => {
73
+ if (cancelled || !entries) return;
74
+ const roster = entries.map(historyEntryToSubagentInfo);
75
+ setSubagents((prev) => mergeSubagentRoster(prev, roster));
76
+ })
77
+ .finally(() => { if (!cancelled) setIsLoading(false); });
78
+ return () => { cancelled = true; };
79
+ }, [sessionId, enabled]);
80
+
81
+ useEffect(() => {
82
+ if (!enabled || !isActiveSession) return;
83
+ let cancelled = false;
84
+ const requestedAt = Date.now();
85
+ const forThisSession = (frame: SubagentFrame) =>
86
+ frame.sessionId === sessionId ? frame.payload : null;
87
+
88
+ const unsubLifecycle = subscribeSubagentFrame('subagent_lifecycle', (frame) => {
89
+ const entry = parseSubagentLifecycle(forThisSession(frame));
90
+ if (entry) setSubagents((prev) => mergeSubagentRoster(prev, [entry]));
91
+ });
92
+ const unsubProgress = subscribeSubagentFrame('subagent_progress', (frame) => {
93
+ const progress = readSubagentProgressFrame(forThisSession(frame));
94
+ if (progress) setSubagents((prev) => applyProgress(prev, progress));
95
+ });
96
+
97
+ // Snapshot the LIVE registry. This POST is the spawn path, so the server
98
+ // refuses it (409) for a session it does not manage — an observer read must
99
+ // never boot an omp child. The history pass already covers a finished
100
+ // session from disk, so nothing is missing when this comes back empty.
101
+ fetch(`/api/agent/${encodeURIComponent(sessionId)}`, {
102
+ method: 'POST',
103
+ headers: { 'Content-Type': 'application/json' },
104
+ body: JSON.stringify({ type: 'get_subagents' }),
105
+ })
106
+ .then((res) => (res.ok ? res.json() : null))
107
+ .then((body: unknown) => {
108
+ if (cancelled || !isRecord(body)) return;
109
+ const payload = 'data' in body ? body.data : body;
110
+ setSubagents((prev) => mergeSubagentRoster(prev, parseSubagentRosterResponse(payload), requestedAt));
111
+ })
112
+ .catch(() => {});
113
+
114
+ return () => {
115
+ cancelled = true;
116
+ unsubLifecycle();
117
+ unsubProgress();
118
+ };
119
+ }, [enabled, isActiveSession, sessionId]);
120
+
121
+ return { subagents, isLoading };
122
+ }
@@ -0,0 +1,55 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * What a pending child chat sends to `/api/sessions/spawn`.
8
+ *
9
+ * The fields are OMITTED when the composer has no value: the route inherits the
10
+ * parent's harness and model when they are absent, and sending `null`/`auto`
11
+ * would override that inheritance with a value the agent never asked for.
12
+ */
13
+
14
+ import { describe, expect, test } from 'bun:test';
15
+ import { childSpawnBody } from '@/client/hooks/chat/timeline/child-spawn';
16
+
17
+ describe('childSpawnBody', () => {
18
+ test('carries the parent, prompt and every pick the composer made', () => {
19
+ expect(
20
+ childSpawnBody('parent', 'review this', {
21
+ harness: 'claude',
22
+ model: { provider: 'acme', modelId: 'big' },
23
+ thinkingLevel: 'high',
24
+ accessMode: 'yolo',
25
+ images: [{ type: 'image', data: 'aGk=', mimeType: 'image/png' }],
26
+ }),
27
+ ).toEqual({
28
+ parentSessionId: 'parent',
29
+ prompt: 'review this',
30
+ harness: 'claude',
31
+ model: { provider: 'acme', modelId: 'big' },
32
+ thinkingLevel: 'high',
33
+ accessMode: 'yolo',
34
+ images: [{ type: 'image', data: 'aGk=', mimeType: 'image/png' }],
35
+ });
36
+ });
37
+
38
+ test('leaves unknown picks out so the server inherits them', () => {
39
+ const body = childSpawnBody('parent', 'go', {
40
+ harness: null,
41
+ model: null,
42
+ thinkingLevel: 'auto',
43
+ accessMode: null,
44
+ images: [],
45
+ });
46
+ expect(body).toEqual({ parentSessionId: 'parent', prompt: 'go' });
47
+ });
48
+
49
+ test('a half-named model is not sent', () => {
50
+ const body = childSpawnBody('parent', 'go', {
51
+ model: { provider: 'acme', modelId: '' },
52
+ });
53
+ expect(body).not.toHaveProperty('model');
54
+ });
55
+ });
@@ -0,0 +1,45 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * The body of `POST /api/sessions/spawn` for a pending child chat.
8
+ *
9
+ * Split out so the payload rule can be asserted without mounting the composer:
10
+ * every field the composer does not actually have a value for must be OMITTED,
11
+ * never sent as `null` — the route treats an absent harness as "inherit the
12
+ * parent's", and an absent model as "use the parent/project default".
13
+ */
14
+
15
+ import type { AgentImage } from '@/shared/types';
16
+ import type { ApprovalMode } from '@/shared/lib/omp/config/access-mode';
17
+
18
+ export interface ChildSpawnPicks {
19
+ harness?: string | null;
20
+ model?: { provider: string; modelId: string } | null;
21
+ thinkingLevel?: string | null;
22
+ accessMode?: ApprovalMode | null;
23
+ images?: AgentImage[] | null;
24
+ }
25
+
26
+ export function childSpawnBody(
27
+ parentSessionId: string,
28
+ prompt: string,
29
+ picks: ChildSpawnPicks = {},
30
+ ): Record<string, unknown> {
31
+ const model = picks.model;
32
+ return {
33
+ parentSessionId,
34
+ prompt,
35
+ ...(picks.harness ? { harness: picks.harness } : {}),
36
+ ...(model?.provider && model.modelId ? { model } : {}),
37
+ // `auto` means "leave the agent's own level alone"; sending it would move a
38
+ // configured level to a literal the ACP handshake may not accept.
39
+ ...(picks.thinkingLevel && picks.thinkingLevel !== 'auto'
40
+ ? { thinkingLevel: picks.thinkingLevel }
41
+ : {}),
42
+ ...(picks.accessMode ? { accessMode: picks.accessMode } : {}),
43
+ ...(picks.images?.length ? { images: picks.images } : {}),
44
+ };
45
+ }
@@ -0,0 +1,54 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * What the fork composer sends to `/api/sessions/:id/fork`.
8
+ *
9
+ * Omitted fields let the fork keep the source's own model/thinking level and
10
+ * an absent message lets it branch without a first turn — both are normal.
11
+ */
12
+
13
+ import { describe, expect, test } from 'bun:test';
14
+ import { forkRequestBody } from '@/client/hooks/chat/timeline/fork-request';
15
+
16
+ describe('forkRequestBody', () => {
17
+ test('carries the anchor and every pick the composer made', () => {
18
+ expect(
19
+ forkRequestBody('u2', {
20
+ prompt: 'try another angle',
21
+ images: [{ type: 'image', data: 'aGk=', mimeType: 'image/png' }],
22
+ model: { provider: 'acme', modelId: 'big' },
23
+ thinkingLevel: 'high',
24
+ accessMode: 'write',
25
+ }),
26
+ ).toEqual({
27
+ anchorEntryId: 'u2',
28
+ prompt: 'try another angle',
29
+ images: [{ type: 'image', data: 'aGk=', mimeType: 'image/png' }],
30
+ model: { provider: 'acme', modelId: 'big' },
31
+ thinkingLevel: 'high',
32
+ accessMode: 'write',
33
+ });
34
+ });
35
+
36
+ test('a bare fork sends only the anchor', () => {
37
+ expect(forkRequestBody('a2')).toEqual({ anchorEntryId: 'a2' });
38
+ expect(
39
+ forkRequestBody('a2', {
40
+ prompt: ' ',
41
+ images: [],
42
+ model: null,
43
+ thinkingLevel: 'auto',
44
+ accessMode: null,
45
+ }),
46
+ ).toEqual({ anchorEntryId: 'a2' });
47
+ });
48
+
49
+ test('a half-named model is not sent', () => {
50
+ expect(forkRequestBody('u1', { model: { provider: '', modelId: 'x' } })).toEqual({
51
+ anchorEntryId: 'u1',
52
+ });
53
+ });
54
+ });