@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
@@ -0,0 +1,253 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * The first send of a pending chat that has no omp session yet.
8
+ *
9
+ * Two shapes, one decision: a chat started from "New child session" has a
10
+ * `parentSessionId` in the pending store and is created through
11
+ * `/api/sessions/spawn`; every other pending chat is a top-level session and
12
+ * goes through `POST /api/agent/new`. Both adopt the id the server answers
13
+ * with, keep the optimistic rows, and are the ONLY place a pending id becomes
14
+ * a real one.
15
+ *
16
+ * Split from `send.ts` for the per-file ceiling; it owns no rendering.
17
+ */
18
+
19
+ import type { Attachment, ChatMessageData, PromptDispatchResult } from '@/shared/types';
20
+ import type { ArmedGoal } from '@/shared/lib/omp/mode/actions';
21
+ import type { ChatTimelineSendDeps } from '@/client/hooks/chat/timeline/send-props';
22
+ import { adoptPendingSession, pendingEntryFor } from '@/client/hooks/chat/omp/pending-sessions';
23
+ import { recordSpawnHarness } from '@/client/hooks/chat/timeline/spawn-harness';
24
+ import { childSpawnBody } from '@/client/hooks/chat/timeline/child-spawn';
25
+ import { forkRequestBody } from '@/client/hooks/chat/timeline/fork-request';
26
+ import { collectImages } from '@/client/hooks/chat/timeline/send-helpers';
27
+
28
+ type PendingDispatchDeps = Pick<
29
+ ChatTimelineSendDeps,
30
+ | 'folders'
31
+ | 'selectedFolderId'
32
+ | 'sessionId'
33
+ | 'ompAgent'
34
+ | 'setLocalMessages'
35
+ | 'setGenerating'
36
+ | 'aiPlaceholderIdRef'
37
+ | 'adoptedSessionIdRef'
38
+ | 'optimisticUserIdRef'
39
+ | 'seedSession'
40
+ | 'pendingComposerModelRef'
41
+ | 'pendingThinkingLevelRef'
42
+ | 'pendingHarnessRef'
43
+ | 'accessModeRef'
44
+ | 'spawnSelectionRef'
45
+ | 'goalArmRef'
46
+ | 'spawnWorktreeRef'
47
+ | 'reportActionError'
48
+ | 'setSearchParams'
49
+ >;
50
+
51
+ export interface PendingDispatchInput {
52
+ text: string;
53
+ attachments: Attachment[];
54
+ /** The assembled prompt: text attachments inlined, `@agent` translated. */
55
+ promptText: string;
56
+ userMsgId: string;
57
+ aiPlaceholderId: string;
58
+ newUserMsg: ChatMessageData;
59
+ /** A New Chat card's inherited harness, which outranks a stale pending pick. */
60
+ options?: { harness?: string | null };
61
+ startArmedGoal: (sessionId: string, armed: ArmedGoal, promptText: string) => Promise<boolean>;
62
+ }
63
+
64
+ /** Roll the optimistic turn back after a refused dispatch. */
65
+ function rollback(
66
+ deps: PendingDispatchDeps,
67
+ userMsgId: string,
68
+ aiPlaceholderId: string,
69
+ error: string,
70
+ ): PromptDispatchResult {
71
+ deps.setLocalMessages((prev) => prev.filter((m) => m.id !== userMsgId && m.id !== aiPlaceholderId));
72
+ deps.aiPlaceholderIdRef.current = null;
73
+ deps.optimisticUserIdRef.current = null;
74
+ deps.setGenerating(false);
75
+ deps.reportActionError(`Prompt not sent: ${error}`);
76
+ return { ok: false, busy: false, error };
77
+ }
78
+
79
+ /** Persist the user's turn for a session omp has not scanned yet. */
80
+ function persistUserTurn(sessionId: string, newUserMsg: ChatMessageData): void {
81
+ fetch(`/api/chat/${encodeURIComponent(sessionId)}`, {
82
+ method: 'POST',
83
+ headers: { 'Content-Type': 'application/json' },
84
+ body: JSON.stringify({ messages: [newUserMsg] }),
85
+ }).catch((err) => console.error('Error persisting spawned user turn:', err));
86
+ }
87
+
88
+ export async function dispatchPendingChat(
89
+ deps: PendingDispatchDeps,
90
+ input: PendingDispatchInput,
91
+ ): Promise<PromptDispatchResult | null> {
92
+ const currentFolder = deps.folders.find((f) => String(f.id) === String(deps.selectedFolderId));
93
+ // A worktree pick wins: the chat is BORN there, so no relocation is ever
94
+ // needed and the child's cwd is right for its whole life.
95
+ const cwd = deps.spawnWorktreeRef.current || currentFolder?.project_path || currentFolder?.name;
96
+ if (!cwd) return null;
97
+
98
+ const images = collectImages(input.attachments);
99
+ deps.optimisticUserIdRef.current = input.userMsgId;
100
+ const composerModel = deps.pendingComposerModelRef.current;
101
+ const composerThinking = deps.pendingThinkingLevelRef.current;
102
+ const entry = pendingEntryFor(deps.sessionId);
103
+ const parentSessionId = entry?.parentSessionId ?? null;
104
+
105
+ if (entry?.forkSourceSessionId) {
106
+ const response = await fetch(
107
+ `/api/sessions/${encodeURIComponent(entry.forkSourceSessionId)}/fork`,
108
+ {
109
+ method: 'POST',
110
+ headers: { 'content-type': 'application/json' },
111
+ body: JSON.stringify(
112
+ forkRequestBody(entry.forkAnchorEntryId ?? null, {
113
+ prompt: input.promptText,
114
+ images,
115
+ model: composerModel,
116
+ thinkingLevel: composerThinking,
117
+ accessMode: deps.accessModeRef.current,
118
+ }),
119
+ ),
120
+ },
121
+ );
122
+ const body = (await response.json().catch(() => null)) as {
123
+ sessionId?: string;
124
+ error?: string;
125
+ code?: string;
126
+ } | null;
127
+ if (!response.ok || !body?.sessionId) {
128
+ if (body?.code === 'mock_mode') return null;
129
+ return rollback(deps, input.userMsgId, input.aiPlaceholderId, body?.error ?? `HTTP ${response.status}`);
130
+ }
131
+
132
+ // A fork keeps the source's agent; the source row's harness was carried
133
+ // into the pending entry when the Fork button opened this chat.
134
+ recordSpawnHarness(body.sessionId, entry.harness ?? 'omp-rpc');
135
+ deps.adoptedSessionIdRef.current = body.sessionId;
136
+ adoptPendingSession(deps.sessionId, body.sessionId, currentFolder?.id ?? null);
137
+ if (composerModel) deps.seedSession({ model: composerModel });
138
+ deps.pendingComposerModelRef.current = null;
139
+ deps.pendingThinkingLevelRef.current = null;
140
+ deps.pendingHarnessRef.current = null;
141
+ persistUserTurn(body.sessionId, input.newUserMsg);
142
+ deps.setSearchParams((prev) => {
143
+ const next = new URLSearchParams(prev);
144
+ next.set('sessionId', body.sessionId!);
145
+ next.delete('forkFrom');
146
+ next.delete('forkAt');
147
+ next.delete('parentSessionId');
148
+ return next;
149
+ }, { replace: true });
150
+ return { ok: true, busy: false };
151
+ }
152
+
153
+ if (parentSessionId) {
154
+ const response = await fetch('/api/sessions/spawn', {
155
+ method: 'POST',
156
+ headers: { 'content-type': 'application/json' },
157
+ body: JSON.stringify(
158
+ childSpawnBody(parentSessionId, input.promptText, {
159
+ harness: input.options?.harness ?? deps.pendingHarnessRef.current,
160
+ model: composerModel,
161
+ thinkingLevel: composerThinking,
162
+ accessMode: deps.accessModeRef.current,
163
+ images,
164
+ }),
165
+ ),
166
+ });
167
+ const body = (await response.json().catch(() => null)) as {
168
+ sessionId?: string;
169
+ harness?: string;
170
+ model?: { provider: string; modelId: string } | null;
171
+ error?: string;
172
+ code?: string;
173
+ } | null;
174
+ if (!response.ok || !body?.sessionId) {
175
+ // MOCK mode has no agent process BY DESIGN; the simulated stream below
176
+ // answers the demo shell instead of reporting a failure.
177
+ if (body?.code === 'mock_mode') return null;
178
+ return rollback(deps, input.userMsgId, input.aiPlaceholderId, body?.error ?? `HTTP ${response.status}`);
179
+ }
180
+
181
+ recordSpawnHarness(body.sessionId, body.harness ?? 'omp-rpc');
182
+ deps.adoptedSessionIdRef.current = body.sessionId;
183
+ adoptPendingSession(deps.sessionId, body.sessionId, currentFolder?.id ?? null);
184
+ // The child's resolved model is the one its first turn runs on; seed it so
185
+ // the composer replacing the pending view reports it before omp's JSONL
186
+ // carries a model_change entry.
187
+ deps.seedSession({
188
+ ...(body.model ? { model: body.model } : {}),
189
+ ...(composerThinking ? { thinkingLevel: composerThinking } : {}),
190
+ });
191
+ deps.pendingComposerModelRef.current = null;
192
+ deps.pendingThinkingLevelRef.current = null;
193
+ deps.pendingHarnessRef.current = null;
194
+ persistUserTurn(body.sessionId, input.newUserMsg);
195
+ deps.setSearchParams((prev) => {
196
+ const next = new URLSearchParams(prev);
197
+ next.set('sessionId', body.sessionId!);
198
+ // The parameter belonged to the pending chat; a real session's URL must
199
+ // not keep a stale parent hint for a later pending chat.
200
+ next.delete('parentSessionId');
201
+ return next;
202
+ }, { replace: true });
203
+ return { ok: true, busy: false };
204
+ }
205
+
206
+ // Top-level pending chat: the existing `/api/agent/new` spawn.
207
+ const spawnModes = deps.spawnSelectionRef.current;
208
+ const armed = deps.goalArmRef.current;
209
+ const spawned = await deps.ompAgent.sendNewPrompt(
210
+ input.promptText,
211
+ cwd,
212
+ images,
213
+ {
214
+ model: composerModel,
215
+ thinkingLevel: composerThinking,
216
+ accessMode: deps.accessModeRef.current,
217
+ modes: spawnModes,
218
+ ...((input.options?.harness ?? deps.pendingHarnessRef.current)
219
+ ? { harness: input.options?.harness ?? deps.pendingHarnessRef.current }
220
+ : {}),
221
+ },
222
+ armed ? (id) => input.startArmedGoal(id, armed, input.promptText) : undefined,
223
+ );
224
+ if (spawned.ok) {
225
+ const { session } = spawned;
226
+ // The harness the SERVER answered with: `new.ts` reports it for an ACP
227
+ // spawn and omits it for the RPC branch, which means omp. Read rather than
228
+ // replayed from the request, so a pick the server did not honour cannot be
229
+ // reported as the agent running the chat.
230
+ recordSpawnHarness(session.sessionId, session.harness ?? 'omp-rpc');
231
+ deps.spawnSelectionRef.current = null;
232
+ deps.adoptedSessionIdRef.current = session.sessionId;
233
+ // The pending row moves with the id; without this it vanished the moment
234
+ // the URL stopped naming the pending id.
235
+ adoptPendingSession(deps.sessionId, session.sessionId, currentFolder?.id ?? null);
236
+ deps.seedSession({ model: session.model, thinkingLevel: composerThinking });
237
+ deps.pendingComposerModelRef.current = null;
238
+ deps.pendingThinkingLevelRef.current = null;
239
+ deps.pendingHarnessRef.current = null;
240
+ persistUserTurn(session.sessionId, input.newUserMsg);
241
+ deps.setSearchParams((prev) => {
242
+ const next = new URLSearchParams(prev);
243
+ next.set('sessionId', session.sessionId);
244
+ next.delete('parentSessionId');
245
+ return next;
246
+ }, { replace: true });
247
+ return { ok: true, busy: false };
248
+ }
249
+ if (spawned.code !== 'mock_mode') {
250
+ return rollback(deps, input.userMsgId, input.aiPlaceholderId, spawned.error);
251
+ }
252
+ return null;
253
+ }
@@ -20,7 +20,7 @@
20
20
  */
21
21
 
22
22
  import { afterAll, afterEach, beforeEach, describe, expect, test } from 'bun:test';
23
- import { buildPromptText } from '@/client/hooks/chat/timeline/prompt-text';
23
+ import { buildPromptText, DelegationPromptError } from '@/client/hooks/chat/timeline/prompt-text';
24
24
  import { invalidateComposerCache } from '@/shared/lib/chat/composer/client';
25
25
 
26
26
  type TextFile = Parameters<typeof buildPromptText>[1][number] & { missing?: boolean };
@@ -60,6 +60,39 @@ function file(name: string, content: string): TextFile {
60
60
  return { name, mimeType: 'text/plain', content, size: content.length };
61
61
  }
62
62
 
63
+ describe('buildPromptText harness delegation', () => {
64
+ test('a bare harness mention compiles to a default-model spawn command', async () => {
65
+ const prompt = await buildPromptText('@claude review src/auth', []);
66
+ expect(prompt).toContain('[kabmo orchestration contract]');
67
+ expect(prompt).toContain('--harness claude --prompt-file -');
68
+ expect(prompt).not.toContain('--model');
69
+ expect(prompt).toContain('review src/auth');
70
+ });
71
+
72
+ test('an explicit model rides the command', async () => {
73
+ const prompt = await buildPromptText('@harness:claude:opus review this', []);
74
+ expect(prompt).toContain('--harness claude --model opus');
75
+ });
76
+
77
+ test('an omp agent mention still becomes a task directive', async () => {
78
+ const prompt = await buildPromptText('fix @architect the bug', []);
79
+ expect(prompt.startsWith('Use the task tool')).toBe(true);
80
+ expect(prompt).not.toContain('[kabmo orchestration contract]');
81
+ });
82
+
83
+ test('two harnesses in one paragraph are refused before sending', async () => {
84
+ await expect(buildPromptText('@claude and @codex review', [])).rejects.toBeInstanceOf(
85
+ DelegationPromptError,
86
+ );
87
+ });
88
+
89
+ test('an unknown namespaced harness is refused', async () => {
90
+ await expect(buildPromptText('@harness:nope do it', [])).rejects.toBeInstanceOf(
91
+ DelegationPromptError,
92
+ );
93
+ });
94
+ });
95
+
63
96
  describe('buildPromptText mentions', () => {
64
97
  test('an agent mention becomes a task-tool delegation directive', async () => {
65
98
  const result = await buildPromptText('fix @architect the bug', []);
@@ -4,26 +4,43 @@
4
4
  */
5
5
 
6
6
  /**
7
- * Prompt assembly for Kabmo composer: rewrite composer-level mentions
8
- * into what oh-my-pi actually receives, then inline the text attachments the
9
- * user dropped in. Extracted from the send path so that hook stays under the
10
- * repo's per-file size ceiling.
7
+ * Prompt assembly for Kabmo composer: rewrite composer-level mentions into what
8
+ * the agent actually receives, then inline the text attachments the user
9
+ * dropped in. Extracted from the send path so that hook stays under the repo's
10
+ * per-file size ceiling.
11
11
  */
12
12
 
13
13
  import { composeMessageWithTextAttachments } from '@/shared/lib/chat/attachments';
14
14
  import { loadAgentNames } from '@/shared/lib/chat/composer/client';
15
+ import {
16
+ delegationErrorText,
17
+ formatDelegationPrompt,
18
+ parseHarnessMentions,
19
+ } from '@/shared/lib/chat/composer/delegation';
15
20
  import { translateAgentMentions, translateFileMentions } from '@/shared/lib/chat/composer/translate';
16
21
 
17
22
  type TextFileAttachment = Parameters<typeof composeMessageWithTextAttachments>[1][number];
18
23
 
24
+ /** A mention the composer cannot send, with the sentence the user needs. */
25
+ export class DelegationPromptError extends Error {
26
+ constructor(readonly reason: string) {
27
+ super(reason);
28
+ this.name = 'DelegationPromptError';
29
+ }
30
+ }
31
+
19
32
  /**
20
- * Build the outgoing prompt. `@agent` mentions are rewritten into an explicit
21
- * task-tool delegation directive at send time (oh-my-pi has no `@agent`
22
- * syntax); translation failures fall back to the raw prompt.
33
+ * Build the outgoing prompt.
23
34
  *
24
- * A file whose bytes could not be read is left OUT rather than inlined empty:
25
- * an empty fenced block tells the model the file exists and says nothing, which
26
- * is worse than not mentioning it. The composer reports the omission.
35
+ * `@harness` mentions are compiled into an orchestrator contract plus one exact
36
+ * `kabmo session spawn` command per worker; the paragraph's own words become
37
+ * that worker's TASK. A bare `@claude` carries no model, so the spawn uses the
38
+ * harness's configured default (or the agent's own).
39
+ *
40
+ * `@agent` mentions are omp's subagent syntax and are rewritten only for the
41
+ * harnesses that have it. A file whose bytes could not be read is left OUT
42
+ * rather than inlined empty: an empty fenced block tells the model the file
43
+ * exists and says nothing, which is worse than not mentioning it.
27
44
  */
28
45
  export async function buildPromptText(
29
46
  text: string,
@@ -31,16 +48,26 @@ export async function buildPromptText(
31
48
  options: { includeAgents?: boolean } = {},
32
49
  ): Promise<string> {
33
50
  const readable = textFiles.filter((file) => !('missing' in file && file.missing));
34
- let translated = text;
35
- // `@agent` is omp's subagent syntax and the rewrite names omp's `task` tool.
36
- // An ACP agent has neither, so the mention is left as the user typed it
37
- // rather than turned into an instruction it cannot follow.
38
- if (options.includeAgents !== false) {
39
- try {
40
- const names = await loadAgentNames();
41
- if (names.length > 0) translated = translateAgentMentions(text, names).text;
42
- } catch {
43
- // keep the raw prompt
51
+ const names = options.includeAgents === false
52
+ ? []
53
+ : await loadAgentNames().catch(() => []);
54
+ const plan = parseHarnessMentions(text, { agentNames: names });
55
+ const refusal = delegationErrorText(plan);
56
+ if (refusal) throw new DelegationPromptError(refusal);
57
+
58
+ let translated: string;
59
+ if (plan.delegations.length > 0) {
60
+ // The orchestrator's own paragraphs still get omp's agent rewrite; a
61
+ // worker task does not, because that text is read by a different harness
62
+ // and `task` is not its vocabulary.
63
+ if (options.includeAgents !== false && names.length > 0) {
64
+ plan.orchestratorText = translateAgentMentions(plan.orchestratorText, names).text;
65
+ }
66
+ translated = formatDelegationPrompt(plan);
67
+ } else {
68
+ translated = text;
69
+ if (options.includeAgents !== false && names.length > 0) {
70
+ translated = translateAgentMentions(translated, names).text;
44
71
  }
45
72
  }
46
73
  // File mentions are namespaced (`@file:`) by the picker; strip the namespace
@@ -142,6 +142,45 @@ describe('executeSend', () => {
142
142
  expect(h1.params).toEqual(['sessionId=uuid-9']);
143
143
  });
144
144
 
145
+ test('a failed spawn reports the server reason and never simulates a reply', async () => {
146
+ const h1 = makeSendHarness({
147
+ isOmpSession: false,
148
+ sessionId: 'new-1',
149
+ folders: [{ id: 4, name: 'demo', project_path: '/tmp/demo' }],
150
+ selectedFolderId: 4,
151
+ agent: { spawnResult: null, spawnError: 'Cannot start dsh: deepseek-harness refused model "m"' },
152
+ });
153
+ await act(async () => {
154
+ const result = await h1.sends.executeSend('first prompt', []);
155
+ expect(result.ok).toBe(false);
156
+ expect(result.error).toContain('deepseek-harness refused model');
157
+ });
158
+ // Nothing may be left on screen for a turn the agent never took, and the
159
+ // failure may not fall through to the simulated stream — that is what made
160
+ // a refused ACP spawn look like a slow chat that then "answered".
161
+ expect(h1.state.messages).toEqual([]);
162
+ expect(h1.reported).toEqual(['Prompt not sent: Cannot start dsh: deepseek-harness refused model "m"']);
163
+ expect(h1.generating).toEqual([true, false]);
164
+ });
165
+
166
+ test('mock mode falls through to the simulated stream instead of reporting', async () => {
167
+ // Mock has no agent process BY DESIGN, so there is no failure to report —
168
+ // the demo shell answers from the simulated stream. Measured on the CI E2E
169
+ // legs: `POST /api/agent/new` answered 400 (no `omp` on the runner) and the
170
+ // landing composer did nothing at all, so no chat ever opened.
171
+ const h1 = makeSendHarness({
172
+ isOmpSession: false,
173
+ sessionId: 'new-1',
174
+ folders: [{ id: 4, name: 'demo', project_path: '/tmp/demo' }],
175
+ selectedFolderId: 4,
176
+ agent: { spawnResult: null, spawnError: 'Mock mode runs no agent process', spawnCode: 'mock_mode' },
177
+ });
178
+ await act(async () => {
179
+ await h1.sends.executeSend('first prompt', []);
180
+ });
181
+ expect(h1.reported).not.toContainEqual(expect.stringContaining('Prompt not sent'));
182
+ });
183
+
145
184
  test('a harness picked on the pending view rides the spawn body', async () => {
146
185
  const h1 = makeSendHarness({
147
186
  isOmpSession: false,
@@ -12,8 +12,9 @@
12
12
  import type { Dispatch, SetStateAction } from 'preact/compat';
13
13
  import type { AgentImage, Attachment, ChatMessageData, PromptDispatchResult } from '@/shared/types';
14
14
  import { streamChatResponse } from '@/client/hooks/chat/stream';
15
+ import { buildPromptText } from '@/client/hooks/chat/timeline/prompt-text';
15
16
  import { createMockStreamCallbacks } from '@/shared/lib/chat/timeline/stream-callbacks';
16
- import { attachmentImage, attachmentName, attachmentSize, attachmentType } from '@/shared/lib/chat/attachments';
17
+ import { readTextAttachments, attachmentImage, attachmentName, attachmentSize, attachmentType, type ReadTextAttachment } from '@/shared/lib/chat/attachments';
17
18
 
18
19
  /** The image payload of a delivery: the attachments that carry real bytes. A
19
20
  * replayed attachment has no live `File`, so it is dropped unless the data
@@ -62,6 +63,34 @@ export function buildOptimisticRows(args: {
62
63
  };
63
64
  }
64
65
 
66
+ /** What the send path needs from a prompt, before it decides which transport runs it. */
67
+ export type PromptAssembly =
68
+ | { ok: true; textFiles: ReadTextAttachment[]; promptText: string }
69
+ | { ok: false; error: string };
70
+
71
+ /**
72
+ * Read attachments and assemble the outgoing prompt once.
73
+ *
74
+ * A delegation refusal (two harnesses in one paragraph, an unknown harness, an
75
+ * empty task) is a send-time failure, not a prompt to send anyway: the caller
76
+ * reports it before any optimistic bubble exists.
77
+ */
78
+ export async function assemblePrompt(
79
+ text: string,
80
+ attachments: Attachment[],
81
+ includeAgents: boolean,
82
+ ): Promise<PromptAssembly> {
83
+ const textFiles = await readTextAttachments(attachments);
84
+ try {
85
+ return { ok: true, textFiles, promptText: await buildPromptText(text, textFiles, { includeAgents }) };
86
+ } catch (error) {
87
+ return {
88
+ ok: false,
89
+ error: error instanceof Error ? error.message : 'Prompt could not be assembled',
90
+ };
91
+ }
92
+ }
93
+
65
94
  /** The simulated SSE path, taken by a Kabmo-created session and as the
66
95
  * fallback when a real spawn is impossible (MOCK mode, no workspace cwd). */
67
96
  export async function streamMockFallback(args: {
@@ -99,7 +99,9 @@ function makeAgent(overrides: Partial<AgentCalls> = {}): AgentRecorder {
99
99
  },
100
100
  sendNewPrompt: async (text: string, cwd: string, _images: unknown, options: unknown) => {
101
101
  calls.newPrompts.push({ text, cwd, options });
102
- return calls.spawnResult;
102
+ return calls.spawnResult
103
+ ? { ok: true as const, session: calls.spawnResult }
104
+ : { ok: false as const, error: 'spawn failed' };
103
105
  },
104
106
  steerOmpRun: async (text: string, images: unknown) => {
105
107
  calls.steers.push({ text, images });
@@ -130,6 +130,10 @@ export interface AgentCalls {
130
130
  sendPromptBusy: boolean;
131
131
  /** The server-supplied reason, when the send was refused. */
132
132
  sendPromptError: string | undefined;
133
+ /** The reason a fresh spawn failed, when `spawnResult` is null. */
134
+ spawnError?: string;
135
+ /** The server's discriminator, e.g. `mock_mode`. */
136
+ spawnCode?: string;
133
137
  spawnResult: { sessionId: string; model?: { provider: string; modelId: string }; harness?: string } | null;
134
138
  }
135
139
 
@@ -158,7 +162,9 @@ export function makeAgent(overrides: Partial<AgentCalls> = {}): AgentRecorder {
158
162
  },
159
163
  sendNewPrompt: async (text: string, cwd: string, _images: unknown, options: unknown) => {
160
164
  calls.newPrompts.push({ text, cwd, options });
161
- return calls.spawnResult;
165
+ return calls.spawnResult
166
+ ? { ok: true as const, session: calls.spawnResult }
167
+ : { ok: false as const, error: calls.spawnError ?? 'spawn failed', ...(calls.spawnCode ? { code: calls.spawnCode } : {}) };
162
168
  },
163
169
  steerOmpRun: async (text: string, images: unknown) => {
164
170
  calls.interrupts.push({ text, images });
@@ -99,7 +99,9 @@ function makeAgent(overrides: Partial<AgentCalls> = {}): AgentRecorder {
99
99
  },
100
100
  sendNewPrompt: async (text: string, cwd: string, _images: unknown, options: unknown) => {
101
101
  calls.newPrompts.push({ text, cwd, options });
102
- return calls.spawnResult;
102
+ return calls.spawnResult
103
+ ? { ok: true as const, session: calls.spawnResult }
104
+ : { ok: false as const, error: 'spawn failed' };
103
105
  },
104
106
  steerOmpRun: async (text: string, images: unknown) => {
105
107
  calls.interrupts.push({ text, images });