@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,129 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * A turn that spawns a subagent is not over when `session/prompt` resolves:
8
+ * antigravity holds the subagent's completion until the next request, so the
9
+ * session probes `session/load` and delivers the delayed answer as a follow-up
10
+ * run. This suite drives that wiring through the real probe and the session's
11
+ * own notification seam.
12
+ */
13
+
14
+ import { afterEach, beforeEach, describe, expect, test } from 'bun:test';
15
+ import { isolateDb, releaseDb } from '@/test-support/isolated-db';
16
+ import { mountSession, notify } from '@/server/lib/harness/acp/session.test-util';
17
+ import { AcpBackgroundProbe, deliverBackgroundNotice } from '@/server/lib/harness/acp/background-work';
18
+ import { extractTextFromContent } from '@/shared/lib/omp/session/mapper';
19
+
20
+ interface FakeTimer {
21
+ fn: () => void;
22
+ }
23
+
24
+ async function settle(): Promise<void> {
25
+ for (let i = 0; i < 8; i += 1) await Promise.resolve();
26
+ }
27
+
28
+ describe('ACP background subagent notice', () => {
29
+ beforeEach(async () => {
30
+ await isolateDb();
31
+ });
32
+
33
+ afterEach(async () => {
34
+ await releaseDb();
35
+ });
36
+
37
+ test('a session/load replay delivers the answer past the holding message', async () => {
38
+ const { session, events, turn, setBackground } = mountSession();
39
+ const scheduled: FakeTimer[] = [];
40
+ const delivered: string[] = [];
41
+ const probe = new AcpBackgroundProbe({
42
+ load: async () => {
43
+ notify(session, { sessionUpdate: 'user_message_chunk', content: { type: 'text', text: 'buat gambar' } });
44
+ notify(session, {
45
+ sessionUpdate: 'agent_message_chunk',
46
+ content: { type: 'text', text: 'Sedang membuat gambar…' },
47
+ });
48
+ notify(session, {
49
+ sessionUpdate: 'agent_message_chunk',
50
+ content: { type: 'text', text: 'Berikut adalah gambar gunung.' },
51
+ });
52
+ return {};
53
+ },
54
+ resetIdle: () => {},
55
+ emit: (text) => {
56
+ delivered.push(text);
57
+ deliverBackgroundNotice(session, text);
58
+ },
59
+ firstDelayMs: 10,
60
+ schedule: (fn) => {
61
+ const timer: FakeTimer = { fn };
62
+ scheduled.push(timer);
63
+ return timer;
64
+ },
65
+ cancel: () => {},
66
+ });
67
+ setBackground(probe);
68
+
69
+ await session.send({ type: 'prompt', message: 'buat gambar' });
70
+ await turn.started;
71
+ notify(session, {
72
+ sessionUpdate: 'tool_call',
73
+ toolCallId: 'sub-1',
74
+ name: 'invoke_subagent',
75
+ title: 'Run invoke_subagent',
76
+ status: 'in_progress',
77
+ rawInput: { Prompt: 'gambar gunung' },
78
+ });
79
+ notify(session, {
80
+ sessionUpdate: 'agent_message_chunk',
81
+ content: { type: 'text', text: 'Sedang membuat gambar…' },
82
+ });
83
+ turn.finish({ stopReason: 'end_turn' });
84
+ await settle();
85
+
86
+ expect(scheduled).toHaveLength(1);
87
+ scheduled[0]?.fn();
88
+ await settle();
89
+ // A first sighting is only a prefix; a repeated replay completes it.
90
+ expect(delivered).toEqual([]);
91
+ expect(scheduled).toHaveLength(2);
92
+ scheduled[1]?.fn();
93
+ await settle();
94
+
95
+ // The replay's holding message is swallowed; only its continuation lands.
96
+ expect(delivered).toEqual(['Berikut adalah gambar gunung.']);
97
+ const ends = events.filter((event) => event.type === 'message_end');
98
+ const texts = ends.map((event) => {
99
+ const message = event.message;
100
+ if (!message || typeof message !== 'object' || !('content' in message)) return '';
101
+ return extractTextFromContent(message.content);
102
+ });
103
+ expect(texts.filter((text) => text === 'Sedang membuat gambar…')).toHaveLength(1);
104
+ expect(texts).toContain('Berikut adalah gambar gunung.');
105
+ // The delayed answer arrives as a complete run of its own.
106
+ expect(events.filter((event) => event.type === 'agent_end')).toHaveLength(2);
107
+ });
108
+
109
+ test('a new prompt stops the probe before the agent flushes the notice itself', async () => {
110
+ const { session, turn, setBackground } = mountSession();
111
+ let stopped = 0;
112
+ setBackground({
113
+ start: () => {},
114
+ stop: () => {
115
+ stopped += 1;
116
+ },
117
+ consume: () => false,
118
+ });
119
+
120
+ await session.send({ type: 'prompt', message: 'satu' });
121
+ await turn.started;
122
+ turn.finish({ stopReason: 'end_turn' });
123
+ await settle();
124
+
125
+ const stopsBefore = stopped;
126
+ await session.send({ type: 'prompt', message: 'dua' });
127
+ expect(stopped).toBe(stopsBefore + 1);
128
+ });
129
+ });
@@ -0,0 +1,31 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * What a session emits when its agent process exits without Kabmo asking.
8
+ *
9
+ * The exit is a failure the operator must see, but only when the session was
10
+ * still wanted; a process Kabmo is tearing down reports through the destroy
11
+ * hook instead of a `prompt_error` for a stop the user asked for.
12
+ */
13
+
14
+ import type { AgentEvent } from '@/server/lib/omp/rpc/constants';
15
+ import type { HarnessId } from '@/shared/lib/harness/catalog';
16
+
17
+ export interface AcpExitInfo {
18
+ code: number | null;
19
+ stderrTail: string;
20
+ }
21
+
22
+ export function acpExitFailureFrames(harness: HarnessId, info: AcpExitInfo): AgentEvent[] {
23
+ const detail = info.stderrTail.trim().split('\n').slice(-3).join(' · ');
24
+ return [
25
+ {
26
+ type: 'prompt_error',
27
+ errorMessage: detail || `The ${harness} agent exited (code ${info.code ?? 'signal'})`,
28
+ },
29
+ { type: 'agent_end', isTerminal: true },
30
+ ];
31
+ }
@@ -66,6 +66,6 @@ export function metadataCapabilities(
66
66
  kind: string,
67
67
  ): HarnessCapabilities {
68
68
  if (kind === 'usage_update') return { ...capabilities, hasUsage: true };
69
- if (kind === 'plan') return { ...capabilities, hasPlan: true };
69
+ if (kind === 'plan' || kind === 'plan_update') return { ...capabilities, hasPlan: true };
70
70
  return capabilities;
71
71
  }
@@ -0,0 +1,197 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * The three handshake shapes: new, load, fork.
8
+ *
9
+ * The fork branch is the one that must never fall back: a harness that cannot
10
+ * fork has to refuse, not open an empty session under the fork's name.
11
+ */
12
+
13
+ import { describe, expect, test } from 'bun:test';
14
+ import { handshakeAcpSession, type AcpHandshakeTarget } from '@/server/lib/harness/acp/session-handshake';
15
+ import type { AcpConfigOption } from '@/server/lib/harness/acp/protocol';
16
+
17
+ function target(): AcpHandshakeTarget {
18
+ return {
19
+ cwd: '/tmp/project',
20
+ harness: 'claude',
21
+ sessionId: '',
22
+ configOptions: [] as AcpConfigOption[],
23
+ runModel: null,
24
+ capabilities: {
25
+ configModel: 0,
26
+ configThinking: 0,
27
+ configMode: 0,
28
+ modeValues: [],
29
+ loadSession: false,
30
+ listSessions: false,
31
+ forkSession: false,
32
+ deleteSession: false,
33
+ resumeSession: false,
34
+ closeSession: false,
35
+ hasUsage: false,
36
+ hasPlan: false,
37
+ steerMode: null,
38
+ },
39
+ async setConfig() {
40
+ return {};
41
+ },
42
+ };
43
+ }
44
+
45
+ function processDouble(overrides: Record<string, unknown> = {}) {
46
+ const calls: string[] = [];
47
+ return {
48
+ calls,
49
+ async initialize() {
50
+ // `session/load` is capability-gated on the AGENT's answer, so the double
51
+ // advertises it unless a case replaces the whole method.
52
+ return { protocolVersion: 1, agentCapabilities: { loadSession: true } };
53
+ },
54
+ async loadSession() {
55
+ calls.push('load');
56
+ },
57
+ async newSession() {
58
+ calls.push('new');
59
+ return { sessionId: 'new-id' };
60
+ },
61
+ ...overrides,
62
+ };
63
+ }
64
+
65
+ describe('handshakeAcpSession', () => {
66
+ test('new starts a new agent session', async () => {
67
+ const proc = processDouble();
68
+ await handshakeAcpSession(target(), proc, { model: null, thinking: null, mode: null });
69
+ expect(proc.calls).toEqual(['new']);
70
+ });
71
+
72
+ test('load restores and then starts the replacement session', async () => {
73
+ const proc = processDouble();
74
+ await handshakeAcpSession(target(), proc, { model: null, thinking: null, mode: null }, 'agent-1');
75
+ expect(proc.calls).toEqual(['load', 'new']);
76
+ });
77
+
78
+ test('an agent with no loadSession but sessionCapabilities.resume resumes in place', async () => {
79
+ const proc = processDouble({
80
+ async initialize() {
81
+ return {
82
+ protocolVersion: 1,
83
+ agentCapabilities: { loadSession: false, sessionCapabilities: { resume: {} } },
84
+ };
85
+ },
86
+ async resumeSession(sessionId: string) {
87
+ proc.calls.push(`resume:${sessionId}`);
88
+ return { configOptions: [{ id: 'model', category: 'model', type: 'select', currentValue: 'a/b' }] };
89
+ },
90
+ });
91
+ const session = target();
92
+ await handshakeAcpSession(session, proc, { model: null, thinking: null, mode: null }, 'agent-1');
93
+ // A resume replays nothing and creates nothing: no replacement session.
94
+ expect(proc.calls).toEqual(['resume:agent-1']);
95
+ expect(session.sessionId).toBe('agent-1');
96
+ expect(session.runModel).toEqual({ provider: 'a', modelId: 'b' });
97
+ });
98
+
99
+ test('a legacy modes list applies the requested mode through session/set_mode', async () => {
100
+ const proc = processDouble({
101
+ async newSession() {
102
+ proc.calls.push('new');
103
+ return {
104
+ sessionId: 'new-id',
105
+ modes: {
106
+ currentModeId: 'code',
107
+ availableModes: [{ id: 'code', name: 'Code' }, { id: 'plan', name: 'Plan' }],
108
+ },
109
+ };
110
+ },
111
+ });
112
+ const session = target();
113
+ const applied: string[] = [];
114
+ session.setMode = async (mode) => {
115
+ applied.push(mode);
116
+ return {};
117
+ };
118
+ await handshakeAcpSession(session, proc, { model: null, thinking: null, mode: 'plan' });
119
+ expect(applied).toEqual(['plan']);
120
+ expect(session.modes?.availableModes.map((entry) => entry.id)).toEqual(['code', 'plan']);
121
+ expect(session.capabilities.configMode).toBe(2);
122
+ });
123
+
124
+ test('v2 resumes in place with resume, never session/load', async () => {
125
+ const proc = processDouble({
126
+ protocolVersion: 2,
127
+ async initialize() {
128
+ return {
129
+ protocolVersion: 2,
130
+ agentCapabilities: {
131
+ loadSession: false,
132
+ sessionCapabilities: { list: {}, resume: {}, close: {} },
133
+ },
134
+ };
135
+ },
136
+ async resumeSession(sessionId: string) {
137
+ proc.calls.push(`resume:${sessionId}`);
138
+ return {
139
+ configOptions: [{ id: 'model', category: 'model', currentValue: 'a/b' }],
140
+ availableCommands: [{ name: 'test', description: 'Run tests' }],
141
+ };
142
+ },
143
+ });
144
+ const session = target();
145
+ await handshakeAcpSession(session, proc, { model: null, thinking: null, mode: null }, 'agent-1');
146
+ expect(proc.calls).toEqual(['resume:agent-1']);
147
+ expect(session.sessionId).toBe('agent-1');
148
+ expect(session.runModel).toEqual({ provider: 'a', modelId: 'b' });
149
+ expect(session.agentCommands).toEqual([{ name: 'test', description: 'Run tests' }]);
150
+ expect(session.capabilities.resumeSession).toBe(true);
151
+ });
152
+
153
+ test('neither load nor resume is refused instead of calling an unadvertised method', async () => {
154
+ const proc = processDouble({
155
+ async initialize() {
156
+ return { protocolVersion: 1, agentCapabilities: {} };
157
+ },
158
+ });
159
+ await expect(
160
+ handshakeAcpSession(target(), proc, { model: null, thinking: null, mode: null }, 'agent-1'),
161
+ ).rejects.toThrow('neither session/load nor session/resume');
162
+ expect(proc.calls).toEqual([]);
163
+ });
164
+
165
+ test('fork asks the agent for session/fork and uses the returned id', async () => {
166
+ const proc = processDouble({
167
+ async forkSession(sessionId: string) {
168
+ proc.calls.push(`fork:${sessionId}`);
169
+ return { sessionId: 'forked-id' };
170
+ },
171
+ });
172
+ const session = target();
173
+ await handshakeAcpSession(
174
+ session,
175
+ proc,
176
+ { model: null, thinking: null, mode: null },
177
+ undefined,
178
+ 'agent-1',
179
+ );
180
+ expect(proc.calls).toEqual(['fork:agent-1']);
181
+ expect(session.sessionId).toBe('forked-id');
182
+ });
183
+
184
+ test('a process with no fork verb refuses instead of creating an empty session', async () => {
185
+ const proc = processDouble();
186
+ await expect(
187
+ handshakeAcpSession(
188
+ target(),
189
+ proc,
190
+ { model: null, thinking: null, mode: null },
191
+ undefined,
192
+ 'agent-1',
193
+ ),
194
+ ).rejects.toThrow('cannot fork');
195
+ expect(proc.calls).toEqual([]);
196
+ });
197
+ });
@@ -28,8 +28,11 @@ import { newSessionAfterActivation } from '@/server/lib/harness/acp/activation';
28
28
  import { applySelections, configOption, modelFromOption } from '@/server/lib/harness/acp/prompt';
29
29
  import { capabilitiesFrom } from '@/server/lib/harness/launch';
30
30
  import type {
31
+ AcpAgentCommand,
31
32
  AcpConfigOption,
32
33
  AcpInitializeResult,
34
+ AcpProtocolVersion,
35
+ AcpSessionModeState,
33
36
  AcpSessionNewResult,
34
37
  } from '@/server/lib/harness/acp/protocol';
35
38
  import type { HarnessCapabilities } from '@/server/lib/harness/capabilities';
@@ -37,9 +40,20 @@ import type { HarnessId } from '@/shared/lib/harness/catalog';
37
40
 
38
41
  /** The process slice a handshake drives; `AcpProcess` satisfies it as-is. */
39
42
  export interface AcpHandshakeProcess {
40
- initialize(params: Record<string, unknown>, timeoutMs?: number): Promise<AcpInitializeResult>;
43
+ initialize(params?: Record<string, unknown>, timeoutMs?: number): Promise<AcpInitializeResult>;
41
44
  loadSession(sessionId: string, cwd: string, timeoutMs?: number): Promise<unknown>;
42
45
  newSession(cwd: string, timeoutMs?: number): Promise<AcpSessionNewResult>;
46
+ /** The negotiated major; absent on a test double, which is a v1 double. */
47
+ readonly protocolVersion?: AcpProtocolVersion;
48
+ /** `session/resume`; absent on a process double used by older tests. */
49
+ resumeSession?(sessionId: string, cwd: string, timeoutMs?: number): Promise<unknown>;
50
+ /** `session/fork`; absent on a process double used by older tests. */
51
+ forkSession?(
52
+ sessionId: string,
53
+ cwd: string,
54
+ timeoutMs?: number,
55
+ target?: Record<string, unknown>,
56
+ ): Promise<AcpSessionNewResult>;
43
57
  }
44
58
 
45
59
  /** The session fields a handshake seeds. */
@@ -48,9 +62,20 @@ export interface AcpHandshakeTarget {
48
62
  readonly harness: HarnessId;
49
63
  sessionId: string;
50
64
  configOptions: AcpConfigOption[];
65
+ /** The older Session Modes API, when the agent publishes no `mode` selector. */
66
+ modes?: AcpSessionModeState | null;
51
67
  runModel: { provider: string; modelId: string } | null;
52
68
  capabilities: HarnessCapabilities;
53
69
  setConfig(configId: string, value: string | boolean): Promise<unknown>;
70
+ /** `session/set_mode`; absent on a target that only speaks config options. */
71
+ setMode?(modeId: string): Promise<unknown>;
72
+ /** Whether prompts may carry image blocks; the agent advertised `image`. */
73
+ acceptsImages?: boolean;
74
+ /** Initial slash commands from a v2 setup response. */
75
+ agentCommands?: AcpAgentCommand[];
76
+ /** Called as soon as `initialize` answers, before any session request, so a
77
+ * v2 resume snapshot can open a turn. */
78
+ onProtocol?(version: AcpProtocolVersion): void;
54
79
  }
55
80
 
56
81
  /** The picks the composer sent for a brand-new session. */
@@ -65,8 +90,10 @@ export async function handshakeAcpSession(
65
90
  proc: AcpHandshakeProcess,
66
91
  wanted: AcpHandshakeSelections,
67
92
  sessionIdToLoad?: string,
93
+ forkFromSessionId?: string,
68
94
  ): Promise<void> {
69
- const init = await proc.initialize({}, 60_000);
95
+ const init = await proc.initialize(undefined, 60_000);
96
+ target.onProtocol?.(init.protocolVersion === 2 ? 2 : 1);
70
97
  /** opencode's plugin activation gate: the first `session/new`s refuse with
71
98
  * `ServiceUnavailableError` until the agent's plugins finish booting. */
72
99
  const newSession = (cwd: string, timeoutMs?: number) =>
@@ -74,16 +101,92 @@ export async function handshakeAcpSession(
74
101
  ...(timeoutMs !== undefined ? { perAttemptMs: timeoutMs } : {}),
75
102
  });
76
103
  let session: AcpSessionNewResult;
77
- if (sessionIdToLoad) {
78
- await proc.loadSession(sessionIdToLoad, target.cwd, 120_000);
79
- const reloaded = await newSession(target.cwd).catch(() => null);
80
- session = reloaded ?? { sessionId: sessionIdToLoad };
104
+ if (forkFromSessionId) {
105
+ // A fork is a NEW agent session that inherits the source's context; the
106
+ // returned id is the child's own. Refusing here is deliberate: silently
107
+ // falling back to `session/new` would start an empty chat under a fork's
108
+ // name, which is the substitution this feature exists to prevent.
109
+ if (!proc.forkSession) {
110
+ throw new Error(`${target.harness} cannot fork a session`);
111
+ }
112
+ session = await proc.forkSession(
113
+ forkFromSessionId,
114
+ target.cwd,
115
+ 120_000,
116
+ // zcode's fork is checkpoint-scoped; its schema defaults `target` but
117
+ // the ACP call needs it stated or the runtime answers "sessionId is
118
+ // required" for a request it cannot place. Other harnesses reject an
119
+ // unknown `target`, so it is sent only where it is understood.
120
+ target.harness === 'zcode' ? { kind: 'latestCheckpoint' } : undefined,
121
+ );
122
+ } else if (sessionIdToLoad) {
123
+ // ACP gates restoration on the AGENT's advertised capability: `loadSession`
124
+ // replays history, `sessionCapabilities.resume` restores without replay, and
125
+ // an agent that advertises neither must be refused in words. Calling
126
+ // `session/load` anyway asked a non-supporting agent for a method it had not
127
+ // advertised and surfaced its `-32601` as a spawn failure.
128
+ const caps = init.agentCapabilities ?? {};
129
+ const restored = proc.protocolVersion === 2
130
+ // v2 removed `session/load`; `session/resume` is baseline and replays
131
+ // nothing unless `replayFrom` asks, which is exactly what Kabmo wants —
132
+ // its own transcript is already on screen.
133
+ ? await (proc.resumeSession
134
+ ? proc.resumeSession(sessionIdToLoad, target.cwd, 120_000)
135
+ : Promise.reject(new Error(`${target.harness} cannot resume a session`)))
136
+ : caps.loadSession === true
137
+ ? await loadReplacement(proc, newSession, sessionIdToLoad, target.cwd)
138
+ : caps.sessionCapabilities?.resume != null
139
+ ? await (proc.resumeSession
140
+ ? proc.resumeSession(sessionIdToLoad, target.cwd, 120_000)
141
+ : Promise.reject(new Error(`${target.harness} cannot resume a session`)))
142
+ : null;
143
+ if (restored === null) {
144
+ throw new Error(
145
+ `${target.harness} cannot restore this chat: it supports neither session/load nor session/resume`,
146
+ );
147
+ }
148
+ const state = restored && typeof restored === 'object'
149
+ ? (restored as Partial<AcpSessionNewResult>)
150
+ : {};
151
+ // `session/resume` replays NOTHING and creates nothing: the id stays the
152
+ // caller's, and only the config/mode state the reply carries is adopted.
153
+ session = { ...state, sessionId: sessionIdToLoad };
81
154
  } else {
82
155
  session = await newSession(target.cwd, 120_000);
83
156
  }
84
157
  target.sessionId = session.sessionId || sessionIdToLoad || '';
85
158
  target.configOptions = session.configOptions ?? [];
159
+ target.modes = session.modes ?? null;
160
+ target.acceptsImages = init.agentCapabilities?.promptCapabilities?.image === true;
161
+ if (session.availableCommands) target.agentCommands = session.availableCommands;
86
162
  target.runModel = modelFromOption(configOption(target.configOptions, 'model'), target.harness);
87
- target.capabilities = capabilitiesFrom(init, target.configOptions, { usage: false, plan: false });
163
+ target.capabilities = capabilitiesFrom(init, target.configOptions, { usage: false, plan: false }, target.modes);
88
164
  await applySelections(target, wanted);
165
+ // A mode the composer asked for, on an agent that publishes only the older
166
+ // `modes` list: `session/set_mode` is the only way to apply it.
167
+ if (
168
+ wanted.mode
169
+ && !configOption(target.configOptions, 'mode')
170
+ && target.modes?.availableModes.some((entry) => entry.id === wanted.mode)
171
+ && target.setMode
172
+ ) {
173
+ await target.setMode(wanted.mode).catch(() => {});
174
+ }
175
+ }
176
+
177
+ /**
178
+ * The v1 load path: replay the agent's history into the mapper, then continue on
179
+ * a fresh agent session.
180
+ *
181
+ * Deliberate: measured on omp, a load answers a FORKED id, and continuing on it
182
+ * would write a second sidebar row for one chat.
183
+ */
184
+ async function loadReplacement(
185
+ proc: AcpHandshakeProcess,
186
+ create: (cwd: string, timeoutMs?: number) => Promise<AcpSessionNewResult>,
187
+ sessionId: string,
188
+ cwd: string,
189
+ ): Promise<unknown> {
190
+ await proc.loadSession(sessionId, cwd, 120_000);
191
+ return (await create(cwd).catch(() => null)) ?? { sessionId };
89
192
  }
@@ -33,15 +33,16 @@ export interface AcpIdleHost {
33
33
  * the user's question with it), and the answer is `false` so `IdleReaper`
34
34
  * re-arms instead of waiting for a frame that a parked dialog will not send.
35
35
  *
36
- * A child that cannot be restored is also left alone: a non-`session/load`
37
- * agent has no way back, and `resumeRecordedHarnessSession` refuses to spawn a
38
- * fresh agent under a chat's id, so reclaiming one would leave a chat that can
39
- * never take another prompt. `omp-acp` is the exception — it writes a session
40
- * file, so the chat is restored over RPC.
36
+ * A child that cannot be restored is also left alone: an agent with neither
37
+ * `session/load` nor `session/resume` has no way back, and
38
+ * `resumeRecordedHarnessSession` refuses to spawn a fresh agent under a chat's
39
+ * id, so reclaiming one would leave a chat that can never take another prompt.
40
+ * `omp-acp` is the exception — it writes a session file, so the chat is restored
41
+ * over RPC.
41
42
  */
42
43
  export function reclaimIdleAcpSession(host: AcpIdleHost): boolean {
43
44
  if (host.isBusy()) return false;
44
- if (!host.capabilities.loadSession && host.harness !== 'omp-acp') return true;
45
+ if (!host.capabilities.loadSession && !host.capabilities.resumeSession && host.harness !== 'omp-acp') return true;
45
46
  host.destroy();
46
47
  return true;
47
48
  }
@@ -0,0 +1,31 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * The session's subscriber set, split out of `AcpSession` because it is a
8
+ * transport-neutral detail: every adapter emits frames to the same listeners,
9
+ * and one throwing subscriber must not starve the others.
10
+ */
11
+
12
+ import type { AgentEvent } from '@/server/lib/omp/rpc/constants';
13
+
14
+ export class SessionListeners {
15
+ private readonly listeners = new Set<(event: AgentEvent) => void>();
16
+
17
+ add(listener: (event: AgentEvent) => void): () => void {
18
+ this.listeners.add(listener);
19
+ return () => this.listeners.delete(listener);
20
+ }
21
+
22
+ emit(event: AgentEvent): void {
23
+ for (const listener of this.listeners) {
24
+ try {
25
+ listener(event);
26
+ } catch {
27
+ // One throwing subscriber must not starve the others.
28
+ }
29
+ }
30
+ }
31
+ }
@@ -26,18 +26,26 @@ import {
26
26
  stampMessageModel,
27
27
  type AcpConfigNotice,
28
28
  } from '@/server/lib/harness/acp/session-config';
29
- import type { AcpConfigOption } from '@/server/lib/harness/acp/protocol';
29
+ import type { AcpConfigOption, AcpProtocolVersion, AcpSessionModeState } from '@/server/lib/harness/acp/protocol';
30
30
  import type { HarnessId } from '@/shared/lib/harness/catalog';
31
+ import { saveAcpPlanState } from '@/server/lib/harness/acp/acp-goal-state.server';
32
+ import { normalizeConfigOptions, planEntries } from '@/server/lib/harness/acp/v2';
31
33
 
32
34
  export interface AcpNotificationHost extends AcpConfigNotice {
33
35
  readonly harness: HarnessId;
36
+ /** The negotiated major; v2 renamed a few update payloads. */
37
+ readonly protocol: AcpProtocolVersion;
34
38
  agentCommands: AgentCommand[];
35
39
  planEntries: unknown[];
40
+ /** The older Session Modes API; updated when the agent switches itself. */
41
+ modes: AcpSessionModeState | null;
36
42
  capabilities: HarnessCapabilities;
37
43
  messageCount: number;
38
44
  assistantCount: number;
39
45
  absorbUsage(update: Record<string, unknown>): void;
40
46
  acceptingFrames(): boolean;
47
+ /** v2's turn boundary; a no-op on v1 and when no turn is open. */
48
+ onStateUpdate(update: Record<string, unknown>): void;
41
49
  mapUpdate(update: Record<string, unknown>): AgentEvent[];
42
50
  emit(event: AgentEvent): void;
43
51
  }
@@ -61,7 +69,14 @@ export function handleSessionNotification(
61
69
  // capability flags entirely.
62
70
  if (kind === 'available_commands_update') host.agentCommands = parseAgentCommands(record);
63
71
  if (kind === 'plan') host.planEntries = Array.isArray(record.entries) ? record.entries : [];
72
+ if (kind === 'plan_update') host.planEntries = planEntries(record);
64
73
  if (kind === 'usage_update') host.absorbUsage(record);
74
+ // v2's foreground lifecycle. `idle` closes the turn; it must reach the turn
75
+ // machine even when the mapper has nothing to draw.
76
+ if (kind === 'state_update') {
77
+ host.onStateUpdate(record);
78
+ return;
79
+ }
65
80
  const absorbed = metadataCapabilities(host.capabilities, kind);
66
81
  if (absorbed !== host.capabilities) host.capabilities = absorbed;
67
82
  // The agent's own name for this chat arrives BETWEEN turns (measured on
@@ -76,8 +91,32 @@ export function handleSessionNotification(
76
91
  // is adopted BEFORE the turn gate below — the session, telemetry and the goal
77
92
  // audit must read the same model the client's `config_option_update` names.
78
93
  if (kind === 'config_option_update' && Array.isArray(record.configOptions)) {
79
- adoptConfigList(host, record.configOptions as AcpConfigOption[]);
94
+ const options = host.protocol === 2
95
+ ? normalizeConfigOptions(record.configOptions)
96
+ : (record.configOptions as AcpConfigOption[]);
97
+ adoptConfigList(host, options);
80
98
  publishConfigChange(host);
99
+ // v2 removed `current_mode_update`; a mode change arrives here. The
100
+ // composer's Plan control reads the persisted flag, so mirror it.
101
+ const mode = options.find((option) => option.category === 'mode');
102
+ if (typeof mode?.currentValue === 'string') {
103
+ void saveAcpPlanState(host.sessionId, mode.currentValue === 'plan').catch(() => {});
104
+ }
105
+ }
106
+ // The agent moved its own mode (a plan-mode exit tool, a fallback). The
107
+ // composer's Plan control reads the persisted flag rather than the frame
108
+ // stream, so mirroring it here is what keeps the toggle truthful.
109
+ if (kind === 'current_mode_update' && typeof record.currentModeId === 'string') {
110
+ if (host.modes) host.modes = { ...host.modes, currentModeId: record.currentModeId };
111
+ void saveAcpPlanState(host.sessionId, record.currentModeId === 'plan').catch(() => {});
112
+ }
113
+ // A notice is a LIVE user-facing event, not conversation output: the spec
114
+ // allows it at any point while a session exists, and it requires the
115
+ // `session.notices` capability this client now advertises. Applying the turn
116
+ // gate below would have dropped exactly the notices that arrive between turns.
117
+ if (kind === 'notice') {
118
+ for (const event of host.mapUpdate(record)) host.emit(event);
119
+ return;
81
120
  }
82
121
 
83
122
  // No turn open: the user stopped it (or one is still queued), and anything