@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
@@ -16,9 +16,13 @@ import { getLiveSession, harnessOfSession } from '@/server/lib/omp/rpc/session-r
16
16
  import { knownHarness, loadHarnessSession } from '@/server/lib/harness/session-store.server';
17
17
  import { HARNESS_IDS } from '@/shared/lib/harness/catalog';
18
18
  import { loadAcpGoalState } from '@/server/lib/harness/acp/acp-goal-state.server';
19
+ import { selectValues } from '@/server/lib/harness/launch';
20
+ import type { AcpConfigOption } from '@/server/lib/harness/acp/protocol';
21
+ import type { SessionModeState } from '@/shared/lib/harness/session-modes';
19
22
  import { asHarnessSession } from '@/server/lib/harness/registry';
20
23
  import { applyHarnessMode } from '@/server/routes/agent/harness-command';
21
24
  import { emitRealtimeSignal } from '@/server/lib/realtime/signals.server';
25
+ import { archiveDependents } from '@/server/lib/sessions/lifecycle.server';
22
26
 
23
27
  /**
24
28
  * GET /api/sessions/:sessionId/modes — the plan/goal mode selection.
@@ -76,12 +80,28 @@ export async function getSessionModes({ params }: LoaderFunctionArgs) {
76
80
  if (applied.ok) plan = (applied.data as { enabled?: unknown } | null)?.enabled === true;
77
81
  }
78
82
  const active = state.record?.status === 'active';
83
+ // The agent's own mode ladder, so the composer can offer all of it. `omp-acp`
84
+ // is excluded: its selector is just default/plan, which the dedicated Plan
85
+ // toggle (with the goal exclusion) already expresses.
86
+ let mode: SessionModeState | null = null;
87
+ if (liveSession?.isAlive() && acpHarness !== 'omp-acp') {
88
+ const snapshot = await liveSession.send({ type: 'get_state' }).catch(() => null) as
89
+ | { configOptions?: AcpConfigOption[] }
90
+ | null;
91
+ const selector = Array.isArray(snapshot?.configOptions)
92
+ ? snapshot.configOptions.find((option) => option.category === 'mode')
93
+ : undefined;
94
+ if (selector && typeof selector.currentValue === 'string') {
95
+ mode = { currentValue: selector.currentValue, values: selectValues(selector) };
96
+ }
97
+ }
79
98
  acpModes = {
80
99
  plan,
81
100
  goal: active,
82
101
  goalLive: active,
83
102
  goalRecord: state.record,
84
103
  goalContinuation: state.continuation,
104
+ ...(mode ? { mode } : {}),
85
105
  };
86
106
  }
87
107
 
@@ -125,6 +145,9 @@ export async function archiveSession({ request, params }: ActionFunctionArgs) {
125
145
  'INSERT OR IGNORE INTO archived_sessions (session_id) VALUES (?)',
126
146
  [sessionId],
127
147
  );
148
+ // An owner takes its tree with it: sidebar children and cleanup dependents
149
+ // are archived and stopped; unarchiving this row does not bring them back.
150
+ await archiveDependents(sessionId);
128
151
  } else {
129
152
  await db.run('DELETE FROM archived_sessions WHERE session_id = ?', [sessionId]);
130
153
  }
@@ -0,0 +1,137 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * POST /api/sessions/spawn — create a session under a parent.
8
+ *
9
+ * Static path, registered before the `:sessionId` routes for the same reason
10
+ * `/api/sessions/batch-archive` is: a parameter route winning the match would
11
+ * answer 405 and hide the real path.
12
+ *
13
+ * The handler owns validation and status mapping only. Everything that decides
14
+ * where the child runs, what it inherits and whether the tree allows it lives in
15
+ * `spawn.server.ts`, because the agent CLI calls the same service.
16
+ */
17
+
18
+ import { json } from '@/server/lib/remix-compat';
19
+ import type { ActionFunctionArgs } from '@/server/lib/remix-compat';
20
+ import { methodNotAllowed, parseJsonBody } from '@/server/lib/route-adapter';
21
+ import { emitRealtimeSignal } from '@/server/lib/realtime/signals.server';
22
+ import { readImages, readModel, readString } from '@/server/routes/sessions/body-readers';
23
+ import { isApprovalMode } from '@/shared/lib/omp/config/access-mode';
24
+ import { isMockMode } from '@/server/mock.server';
25
+ import {
26
+ SessionSpawnError,
27
+ spawnChildSession,
28
+ } from '@/server/lib/sessions/spawn.server';
29
+ import { bearerToken, verifyAgentToken } from '@/server/lib/sessions/agent-token.server';
30
+
31
+ type Visibility = 'visible' | 'hidden';
32
+ type ParentNotifications = 'auto' | 'stuck' | 'off';
33
+
34
+ interface SpawnBody {
35
+ parentSessionId?: unknown;
36
+ /** The CLI's `--parent-self`: resolve the parent from the bearer token. */
37
+ parentSelf?: unknown;
38
+ harness?: unknown;
39
+ cwd?: unknown;
40
+ prompt?: unknown;
41
+ images?: unknown;
42
+ model?: unknown;
43
+ thinkingLevel?: unknown;
44
+ accessMode?: unknown;
45
+ lifecycleOwnerSessionId?: unknown;
46
+ visibility?: unknown;
47
+ parentNotifications?: unknown;
48
+ }
49
+
50
+ function statusFor(code: SessionSpawnError['code']): number {
51
+ switch (code) {
52
+ case 'parent_not_found':
53
+ return 404;
54
+ case 'parent_archived':
55
+ case 'parent_folder_mismatch':
56
+ return 409;
57
+ default:
58
+ return 400;
59
+ }
60
+ }
61
+
62
+ export async function spawnSession({ request }: ActionFunctionArgs) {
63
+ if (request.method !== 'POST') {
64
+ return methodNotAllowed({ request, params: {} });
65
+ }
66
+ const parsed = await parseJsonBody<SpawnBody>(request);
67
+ if (!parsed.ok) return json({ error: 'Invalid JSON body' }, { status: 400 });
68
+
69
+ // MOCK mode has no agent process to start. The client takes its simulated
70
+ // path on this CODE, exactly as it does for `POST /api/agent/new`.
71
+ if (isMockMode()) {
72
+ return json({ error: 'Mock mode runs no agent process', code: 'mock_mode' }, { status: 400 });
73
+ }
74
+
75
+ const prompt = readString(parsed.body.prompt);
76
+ if (!prompt) return json({ error: 'prompt is required' }, { status: 400 });
77
+
78
+ // An agent may only spawn under itself. The token is the identity (there is
79
+ // no cookie in a subprocess); `--parent-self` is how the CLI asks for it.
80
+ const tokenSession = verifyAgentToken(bearerToken(request));
81
+ let parentSessionId = readString(parsed.body.parentSessionId);
82
+ if (parsed.body.parentSelf === true) {
83
+ if (!tokenSession) {
84
+ return json({ error: 'parentSelf requires an agent token', code: 'agent_token_required' }, { status: 401 });
85
+ }
86
+ parentSessionId = tokenSession;
87
+ }
88
+ if (tokenSession && parentSessionId !== tokenSession) {
89
+ return json(
90
+ { error: 'An agent may only spawn under its own session', code: 'agent_scope' },
91
+ { status: 403 },
92
+ );
93
+ }
94
+
95
+ const visibility = parsed.body.visibility;
96
+ if (visibility !== undefined && visibility !== 'visible' && visibility !== 'hidden') {
97
+ return json({ error: 'visibility must be "visible" or "hidden"' }, { status: 400 });
98
+ }
99
+ const notifications = parsed.body.parentNotifications;
100
+ if (
101
+ notifications !== undefined &&
102
+ notifications !== 'auto' &&
103
+ notifications !== 'stuck' &&
104
+ notifications !== 'off'
105
+ ) {
106
+ return json({ error: 'parentNotifications must be auto, stuck or off' }, { status: 400 });
107
+ }
108
+ if (parsed.body.accessMode !== undefined && !isApprovalMode(parsed.body.accessMode)) {
109
+ return json({ error: 'accessMode is not a valid approval mode' }, { status: 400 });
110
+ }
111
+
112
+ try {
113
+ const result = await spawnChildSession({
114
+ parentSessionId,
115
+ harness: readString(parsed.body.harness),
116
+ cwd: readString(parsed.body.cwd),
117
+ prompt,
118
+ images: readImages(parsed.body.images),
119
+ model: readModel(parsed.body.model),
120
+ thinkingLevel: readString(parsed.body.thinkingLevel),
121
+ accessMode: isApprovalMode(parsed.body.accessMode) ? parsed.body.accessMode : null,
122
+ lifecycleOwnerSessionId: readString(parsed.body.lifecycleOwnerSessionId),
123
+ ...(visibility ? { visibility: visibility as Visibility } : {}),
124
+ ...(notifications ? { parentNotifications: notifications as ParentNotifications } : {}),
125
+ });
126
+ emitRealtimeSignal('sidebar-structure');
127
+ return json(result, { status: 201 });
128
+ } catch (error) {
129
+ if (error instanceof SessionSpawnError) {
130
+ return json({ error: error.message, code: error.code }, { status: statusFor(error.code) });
131
+ }
132
+ return json(
133
+ { error: error instanceof Error ? error.message : 'Could not spawn the session' },
134
+ { status: 500 },
135
+ );
136
+ }
137
+ }
@@ -31,7 +31,7 @@ import {
31
31
  writeTerminalInput,
32
32
  } from '@/server/lib/terminal/runtime.server';
33
33
  import { TerminalRuntimeError, type TerminalViewer } from '@/server/lib/terminal/session.server';
34
- import { frameAccepted } from '@/server/lib/terminal/send-result';
34
+ import { asBinaryFrame, frameAccepted } from '@/server/lib/terminal/send-result';
35
35
  import {
36
36
  decodeClientFrame,
37
37
  encodeServerFrame,
@@ -71,8 +71,8 @@ export const terminalWsRoutes = new Elysia({ prefix: '/api/terminal' }).ws('/:te
71
71
  // Only `0` is a drop; `-1` means "queued, draining". See
72
72
  // `send-result.ts` for the measured contract — reading `-1` as
73
73
  // failure closed healthy viewers at the first burst, and reading
74
- // `0` as success left xterm attached to a stream with a hole.
75
- return frameAccepted(ws.send(frame));
74
+ // `0` as success left the panel attached to a stream with a hole.
75
+ return frameAccepted(ws.send(asBinaryFrame(frame)));
76
76
  } catch {
77
77
  // Socket closed mid-send; the close handler detaches.
78
78
  return false;
@@ -1,3 +1,4 @@
1
+ import { HARNESS_CATALOG } from '@/shared/lib/harness/catalog';
1
2
  import type { AgentItem, CommandItem, ComposerPickItem, ComposerPickKind, FsFileEntry, SkillItem } from '@/shared/types';
2
3
  import { KABMO_COMMANDS } from '@/shared/lib/chat/composer/trigger';
3
4
 
@@ -38,6 +39,25 @@ export function toAgentPickItems(agents: AgentItem[]): ComposerPickItem[] {
38
39
  }));
39
40
  }
40
41
 
42
+ /**
43
+ * Map the harness catalog into `@harness:<id>` mention tokens.
44
+ *
45
+ * These rows are what turns a mention into a delegation rather than a prose
46
+ * hint: the picker inserts the namespaced token, and the send path compiles it
47
+ * into the exact `kabmo session spawn` command. The token carries no model, so
48
+ * the spawn uses that harness's configured default (or the agent's own).
49
+ */
50
+ export function toHarnessPickItems(): ComposerPickItem[] {
51
+ return Object.values(HARNESS_CATALOG).map((harness) => ({
52
+ id: `harness-${harness.id}`,
53
+ name: `harness:${harness.id}`,
54
+ description: `${harness.label} · default model · type :<model> to pin one`,
55
+ kind: 'harness',
56
+ source: 'harness',
57
+ token: `@harness:${harness.id}`,
58
+ }));
59
+ }
60
+
41
61
  /**
42
62
  * Map workspace files into `@file:<path>` mention tokens. The `file:` namespace
43
63
  * means a file token can never collide with a bare `@agent` (e.g. a root-level
@@ -211,8 +231,17 @@ export function loadComposerItems(
211
231
  ): Promise<ComposerPickItem[]> {
212
232
  if (kind === 'mention') {
213
233
  const files = loadFileItems(root ?? null);
214
- if (options.includeAgents === false) return files;
215
- return Promise.all([loadAgentItems(), files]).then(([agents, fileItems]) => [...agents, ...fileItems]);
234
+ const harnesses = toHarnessPickItems();
235
+ // Harness rows survive `includeAgents: false`: that flag exists because an
236
+ // ACP chat has no omp `@agent` vocabulary, not because it cannot delegate.
237
+ if (options.includeAgents === false) {
238
+ return files.then((fileItems) => [...harnesses, ...fileItems]);
239
+ }
240
+ return Promise.all([loadAgentItems(), files]).then(([agents, fileItems]) => [
241
+ ...agents,
242
+ ...harnesses,
243
+ ...fileItems,
244
+ ]);
216
245
  }
217
246
  return loadCommandItems(root ?? null, sessionId);
218
247
  }
@@ -0,0 +1,93 @@
1
+ import { describe, expect, test } from 'bun:test';
2
+ import {
3
+ delegationCommand,
4
+ delegationErrorText,
5
+ formatDelegationPrompt,
6
+ parseHarnessMentions,
7
+ } from '@/shared/lib/chat/composer/delegation';
8
+
9
+ describe('parseHarnessMentions', () => {
10
+ test('a bare harness mention uses the harness default model', () => {
11
+ const plan = parseHarnessMentions('@claude review src/auth');
12
+ expect(plan.errors).toEqual([]);
13
+ expect(plan.delegations).toEqual([
14
+ { harness: 'claude', model: null, task: 'review src/auth', token: '@claude' },
15
+ ]);
16
+ expect(plan.orchestratorText).toBe('');
17
+ });
18
+
19
+ test('an explicit model rides the mention', () => {
20
+ const plan = parseHarnessMentions('@harness:claude:opus review this');
21
+ expect(plan.delegations[0]).toMatchObject({
22
+ harness: 'claude',
23
+ model: 'opus',
24
+ task: 'review this',
25
+ });
26
+ });
27
+
28
+ test('one mention per paragraph, two paragraphs are two workers', () => {
29
+ const plan = parseHarnessMentions(
30
+ '@harness:claude review the diff.\n\n@harness:omp fix the tests.',
31
+ );
32
+ expect(plan.delegations.map((entry) => entry.harness)).toEqual(['claude', 'omp-rpc']);
33
+ expect(plan.delegations[0].task).toBe('review the diff.');
34
+ expect(plan.delegations[1].task).toBe('fix the tests.');
35
+ });
36
+
37
+ test('a paragraph with no mention stays with the orchestrator', () => {
38
+ const plan = parseHarnessMentions(
39
+ 'Coordinate this work.\n\n@claude review the diff.\n\nThen report back.',
40
+ );
41
+ expect(plan.delegations).toHaveLength(1);
42
+ expect(plan.orchestratorText).toBe('Coordinate this work.\n\nThen report back.');
43
+ });
44
+
45
+ test('two mentions in one paragraph are refused', () => {
46
+ const plan = parseHarnessMentions('@claude and @omp fix this', { agentNames: [] });
47
+ expect(plan.errors[0]?.code).toBe('multiple_mentions');
48
+ expect(delegationErrorText(plan)).toContain('blank line');
49
+ });
50
+
51
+ test('an unknown namespaced harness is refused', () => {
52
+ const plan = parseHarnessMentions('@harness:nope do it');
53
+ expect(plan.errors[0]?.code).toBe('unknown_harness');
54
+ expect(delegationErrorText(plan)).toContain('nope');
55
+ });
56
+
57
+ test('a known omp agent name is not a bare harness mention', () => {
58
+ const plan = parseHarnessMentions('@architect review this', { agentNames: ['architect'] });
59
+ expect(plan.delegations).toEqual([]);
60
+ expect(plan.orchestratorText).toBe('@architect review this');
61
+ });
62
+
63
+ test('@file: is not a harness mention', () => {
64
+ const plan = parseHarnessMentions('look at @file:src/a.ts', { agentNames: [] });
65
+ expect(plan.delegations).toEqual([]);
66
+ expect(plan.orchestratorText).toBe('look at @file:src/a.ts');
67
+ });
68
+
69
+ test('a mention with no task is refused', () => {
70
+ const plan = parseHarnessMentions('@claude');
71
+ expect(plan.errors[0]?.code).toBe('empty_task');
72
+ });
73
+ });
74
+
75
+ describe('delegation prompt', () => {
76
+ test('the command omits --model for a default and includes it when named', () => {
77
+ const plan = parseHarnessMentions(
78
+ '@harness:claude review.\n\n@harness:claude:opus check.',
79
+ );
80
+ expect(delegationCommand(plan.delegations[0], 0)).toContain(
81
+ '--harness claude --prompt-file -',
82
+ );
83
+ expect(delegationCommand(plan.delegations[1], 1)).toContain('--model opus');
84
+ });
85
+
86
+ test('the orchestrator prompt names the worker and the end-turn rule', () => {
87
+ const prompt = formatDelegationPrompt(parseHarnessMentions('@claude review this'));
88
+ expect(prompt).toContain('[kabmo orchestration contract]');
89
+ expect(prompt).toContain('end your turn');
90
+ expect(prompt).toContain('--harness claude');
91
+ expect(prompt.toLowerCase()).toContain('do not poll');
92
+ });
93
+ });
@@ -0,0 +1,206 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * `@harness` delegation mentions in the composer.
8
+ *
9
+ * A mention is a commitment, not a suggestion: `@harness:claude` (or bare
10
+ * `@claude`) names the agent that must do the paragraph's work, and the text of
11
+ * that paragraph is its whole brief. The parser turns a message into a
12
+ * delegation plan the orchestrator can execute with the CLI, so the model never
13
+ * has to guess a harness, a model or which words were the task.
14
+ *
15
+ * Namespaced `harness:` cannot collide with `@file:` or an omp `@agent`; a bare
16
+ * `@claude` is accepted only when the token is a known harness id and is not a
17
+ * known agent name.
18
+ */
19
+
20
+ import { HARNESS_CATALOG, HARNESS_IDS, type HarnessId } from '@/shared/lib/harness/catalog';
21
+
22
+ export interface HarnessDelegation {
23
+ harness: HarnessId;
24
+ /** The agent's own model value, or null for the harness default. */
25
+ model: string | null;
26
+ task: string;
27
+ /** The exact token the user typed, for diagnostics and display. */
28
+ token: string;
29
+ }
30
+
31
+ export type DelegationErrorCode = 'unknown_harness' | 'empty_task' | 'multiple_mentions';
32
+
33
+ export interface DelegationError {
34
+ code: DelegationErrorCode;
35
+ message: string;
36
+ paragraph: string;
37
+ }
38
+
39
+ export interface DelegationPlan {
40
+ delegations: HarnessDelegation[];
41
+ /** The paragraphs that stay with the orchestrator, mentions removed. */
42
+ orchestratorText: string;
43
+ errors: DelegationError[];
44
+ }
45
+
46
+ export interface ParseDelegationOptions {
47
+ /** Bare `@name` is an omp agent when it matches one of these. */
48
+ agentNames?: readonly string[];
49
+ }
50
+
51
+ /** `@harness:<id>[:<model>]` or bare `@<harnessId>`. */
52
+ const MENTION_RE = /(^|[\s([{])@(?:(harness):)?([a-z0-9][a-z0-9-]*)(?::([^\s#]+))?/gi;
53
+
54
+ /** The names users type that are not catalog ids. `omp` is the default RPC
55
+ * surface; `claude-code` is the vendor's name for the `claude` adapter. */
56
+ const HARNESS_ALIASES: Readonly<Record<string, HarnessId>> = {
57
+ omp: 'omp-rpc',
58
+ 'claude-code': 'claude',
59
+ };
60
+
61
+ function harnessIdFor(name: string): HarnessId | null {
62
+ return HARNESS_ALIASES[name] ?? (HARNESS_IDS.includes(name as HarnessId) ? (name as HarnessId) : null);
63
+ }
64
+
65
+ /**
66
+ * Parse one message. The error list is non-empty when the message cannot be
67
+ * delegated as written; the caller refuses the send rather than guessing.
68
+ */
69
+ export function parseHarnessMentions(
70
+ text: string,
71
+ options: ParseDelegationOptions = {},
72
+ ): DelegationPlan {
73
+ const agentNames = new Set((options.agentNames ?? []).map((name) => name.toLowerCase()));
74
+ const paragraphs = text.split(/\n\s*\n/);
75
+ const delegations: HarnessDelegation[] = [];
76
+ const kept: string[] = [];
77
+ const errors: DelegationError[] = [];
78
+
79
+ for (const paragraph of paragraphs) {
80
+ const matches: { start: number; end: number; harness: HarnessId; model: string | null; token: string }[] = [];
81
+ MENTION_RE.lastIndex = 0;
82
+ for (const match of paragraph.matchAll(MENTION_RE)) {
83
+ const namespace = match[2]?.toLowerCase();
84
+ const name = match[3]?.toLowerCase();
85
+ if (!name) continue;
86
+ const isBare = namespace === undefined;
87
+ const known = harnessIdFor(name);
88
+ if (namespace && !known) {
89
+ errors.push({
90
+ code: 'unknown_harness',
91
+ message: `Unknown harness "${name}"`,
92
+ paragraph,
93
+ });
94
+ continue;
95
+ }
96
+ if (!known) continue;
97
+ if (isBare && agentNames.has(name)) continue;
98
+ const tokenStart = (match.index ?? 0) + (match[1]?.length ?? 0);
99
+ const token = match[0].slice(match[1]?.length ?? 0);
100
+ matches.push({
101
+ start: tokenStart,
102
+ end: tokenStart + token.length,
103
+ harness: known,
104
+ model: match[4] ?? null,
105
+ token,
106
+ });
107
+ }
108
+
109
+ if (matches.length === 0) {
110
+ if (paragraph.trim()) kept.push(paragraph.trim());
111
+ continue;
112
+ }
113
+ if (matches.length > 1) {
114
+ errors.push({
115
+ code: 'multiple_mentions',
116
+ message: 'One paragraph can delegate to one harness; separate workers with a blank line',
117
+ paragraph,
118
+ });
119
+ continue;
120
+ }
121
+
122
+ const mention = matches[0];
123
+ const task = `${paragraph.slice(0, mention.start)}${paragraph.slice(mention.end)}`
124
+ .replace(/\s+/g, ' ')
125
+ .replace(/^[\s,;:-]+/, '')
126
+ .trim();
127
+ if (!task) {
128
+ errors.push({
129
+ code: 'empty_task',
130
+ message: `@${mention.token.replace(/^@/, '')} needs a task in the same paragraph`,
131
+ paragraph,
132
+ });
133
+ continue;
134
+ }
135
+ delegations.push({
136
+ harness: mention.harness,
137
+ model: mention.model,
138
+ task,
139
+ token: mention.token,
140
+ });
141
+ }
142
+
143
+ // A message that is only an unknown `@harness:` is an error, not prose.
144
+ if (errors.length > 0) {
145
+ return { delegations: [], orchestratorText: text.trim(), errors };
146
+ }
147
+ return {
148
+ delegations,
149
+ orchestratorText: kept.join('\n\n'),
150
+ errors,
151
+ };
152
+ }
153
+
154
+ /** The exact command an orchestrator runs, with the task in a heredoc. */
155
+ export function delegationCommand(delegation: HarnessDelegation, index: number): string {
156
+ const tag = `KABMO_TASK_${index + 1}`;
157
+ const model = delegation.model ? ` --model ${delegation.model}` : '';
158
+ return [
159
+ `kabmo session spawn --parent-self --harness ${delegation.harness}${model} --prompt-file - <<'${tag}'`,
160
+ delegation.task,
161
+ tag,
162
+ ].join('\n');
163
+ }
164
+
165
+ /**
166
+ * The block prepended to the orchestrator's own prompt. It names every worker,
167
+ * gives the exact spawn command, and states the one behaviour the host cannot
168
+ * enforce by itself: end the turn instead of polling.
169
+ */
170
+ export function formatDelegationPrompt(plan: DelegationPlan): string {
171
+ const lines = [
172
+ '[kabmo orchestration contract]',
173
+ 'You are the orchestrator for this message. Start each worker below with the exact command,',
174
+ 'then end your turn. A worker sees nothing of this conversation: its TASK is the whole brief.',
175
+ 'Kabmo adds the dispatched-worker preamble and sends each worker outcome back as a new',
176
+ 'message. Do not poll, do not resend the same task, and do not delegate work that is not',
177
+ 'listed here unless the user asks.',
178
+ '',
179
+ 'Workers:',
180
+ ];
181
+ plan.delegations.forEach((delegation, index) => {
182
+ const model = delegation.model ?? 'default model';
183
+ lines.push(
184
+ '',
185
+ `${index + 1}. ${HARNESS_CATALOG[delegation.harness]?.label ?? delegation.harness} · ${model}`,
186
+ delegationCommand(delegation, index),
187
+ );
188
+ });
189
+ lines.push(
190
+ '',
191
+ 'When a worker finishes, read its output with `kabmo session output <id>` and report the',
192
+ 'result to the user. Reconcile conflicting reports; do not relay one verbatim.',
193
+ '[/kabmo orchestration contract]',
194
+ );
195
+ if (plan.orchestratorText) lines.push('', plan.orchestratorText);
196
+ return lines.join('\n');
197
+ }
198
+
199
+ /** A user-facing refusal, or null when the message can be sent. */
200
+ export function delegationErrorText(plan: DelegationPlan): string | null {
201
+ if (plan.errors.length === 0) return null;
202
+ return plan.errors
203
+ .map((error) => error.message)
204
+ .filter((message, index, all) => all.indexOf(message) === index)
205
+ .join(' · ');
206
+ }
@@ -17,7 +17,7 @@
17
17
  * runs and half-block progress bars. The notice card renders markdown through
18
18
  * Shiki, which treats `\x1b[38;2;…m` as literal text, so `/context` drew 48
19
19
  * escape bytes as `38;2;107;114;128m████…`. True colour stays available in the
20
- * realtime xterm panel, which parses ANSI natively.
20
+ * realtime terminal panel, which parses ANSI natively.
21
21
  * - **`<system-notice>` wrappers.** omp tags its own notices; the tag is
22
22
  * scaffolding, not content. (The runtime-notice wrappers —
23
23
  * `<system-reminder>`, `<system-interrupt>`, `<task-result>` — are NOT
@@ -18,6 +18,7 @@ import { extractTextFromContent, toChatMessage } from '@/shared/lib/omp/session/
18
18
  import { normalizeNoticeText } from '@/shared/lib/chat/notice-text';
19
19
  import { parseModeMarker } from '@/shared/lib/omp/mode/markers';
20
20
  import { emitKabmoModeSignal } from '@/shared/lib/omp/mode/client-signal';
21
+ import { emitSessionModesChanged } from '@/shared/lib/harness/mode-signal';
21
22
  import { KABMO_GOAL_EVALUATING_MARKER } from '@/shared/lib/omp/mode/types';
22
23
  import { materializeTerminalMessages } from '@/shared/lib/chat/omp/terminal-messages';
23
24
  import { invalidateComposerCache } from '@/shared/lib/chat/composer/client';
@@ -45,6 +46,9 @@ export function foldAgentEvent(data: OmpAgentEvent, deps: OmpAgentFoldDeps): voi
45
46
  switch (data.type) {
46
47
  case 'agent_start':
47
48
  deps.setState((prev) => ({ ...prev, isGenerating: true, error: null }));
49
+ // A cold chat has no live agent when the composer first reads `/modes`;
50
+ // this is the first frame after its spawn, so re-read the mode ladder.
51
+ emitSessionModesChanged(deps.sessionId);
48
52
  deps.toolResultsRef.current?.clear();
49
53
  deps.lastToolMessageRef.current = null;
50
54
  // A fresh run restarts level tracking; the first turn relies on the
@@ -276,6 +280,13 @@ export function foldAgentEvent(data: OmpAgentEvent, deps: OmpAgentFoldDeps): voi
276
280
  callbacks?.onModelChanged?.();
277
281
  break;
278
282
 
283
+ // An ACP agent changed a config selector itself. `mode` is one of them and
284
+ // the composer's mode dropdown reads the live session, so re-read it.
285
+ case 'mode_changed':
286
+ case 'config_changed':
287
+ emitSessionModesChanged(deps.sessionId);
288
+ break;
289
+
279
290
  // The live `thinking_level_changed` frame carries the new session level
280
291
  // (e.g. { thinkingLevel: "high", configured, resolved }); null → "off".
281
292
  // Record it so subsequent assistant turns are stamped with the level that
@@ -0,0 +1,41 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ *
5
+ * A cold chat has no live agent when the composer reads `/modes`; the first
6
+ * frame after its spawn is `agent_start`, so that frame must ask the composer
7
+ * to re-read the mode ladder.
8
+ */
9
+
10
+ import { describe, expect, test } from 'bun:test';
11
+ import { foldAgentEvent, type OmpAgentFoldDeps } from '@/shared/lib/chat/omp/agent-events';
12
+ import { subscribeClientSignal } from '@/client/lib/signals';
13
+
14
+ function foldDeps(): OmpAgentFoldDeps {
15
+ const noop = () => {};
16
+ const ref = <T,>(value: T) => ({ current: value });
17
+ return {
18
+ setState: noop,
19
+ sessionId: 'acp-cold-chat',
20
+ callbacksRef: { current: {} },
21
+ toolResultsRef: ref(new Map()),
22
+ lastToolMessageRef: ref(null),
23
+ activityRef: ref(''),
24
+ providerRetryVerbRef: ref(null),
25
+ currentThinkingLevelRef: ref(undefined),
26
+ fileMutatingCallsRef: ref(new Set()),
27
+ } as unknown as OmpAgentFoldDeps;
28
+ }
29
+
30
+ describe('session-modes-changed signal', () => {
31
+ test('agent_start re-reads the live mode ladder', () => {
32
+ const seen: string[] = [];
33
+ const off = subscribeClientSignal('session-modes-changed', (payload) => seen.push(payload.sessionId));
34
+ try {
35
+ foldAgentEvent({ type: 'agent_start' } as never, foldDeps());
36
+ } finally {
37
+ off();
38
+ }
39
+ expect(seen).toEqual(['acp-cold-chat']);
40
+ });
41
+ });
@@ -93,6 +93,17 @@ describe('toolSummary — wait', () => {
93
93
  expect(summary?.line).toBe('15s · idle 15s total');
94
94
  });
95
95
 
96
+ test('the 18.18.6 hint after the window does not hide the idle chip', () => {
97
+ // omp 18.18.6: `No reply within 10s; a back-to-back wait allows up to 30s.`
98
+ const summary = toolSummary(tool({
99
+ type: 'wait',
100
+ durationMs: 10_000,
101
+ output: 'No reply within 10s; a back-to-back wait allows up to 30s.',
102
+ details: { op: 'wait', jobs: [] },
103
+ }));
104
+ expect(summary?.line).toBe('10s · idle 10s');
105
+ });
106
+
96
107
  test('an unreadable result keeps the generic fallback', () => {
97
108
  // No `details.op`, so this is not a wait result at all — the output's first
98
109
  // line is the only thing worth saying.
@@ -9,7 +9,7 @@
9
9
  * Timeline cards render with Shiki (`Bash`, `FallbackOutput`), which treats
10
10
  * raw `\x1b[…m` sequences as literal text — so escapes are dropped here
11
11
  * first and the clean text goes to the highlighter. True terminal colors
12
- * stay available in the realtime xterm panel, which parses ANSI natively.
12
+ * stay available in the realtime terminal panel, which parses ANSI natively.
13
13
  */
14
14
 
15
15
  /** Any ANSI escape: OSC hyperlink, charset select, or CSI sequence. */