@kabmo-labs/kabmo 0.23.0 → 0.25.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 +805 -736
  3. package/dist/client/static/js/index-bc9aa4mx.css +1 -0
  4. package/dist/client/static/js/{index-ph0q59rs.js → index-ga8cbpt4.js} +1071 -1171
  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/Modal.tsx +2 -6
  13. package/src/client/components/common/code-surface/shiki.test.ts +82 -0
  14. package/src/client/components/common/code-surface/shiki.ts +28 -7
  15. package/src/client/components/common/session-actions-menu/NewChildSessionDialog.tsx +113 -0
  16. package/src/client/components/common/session-actions-menu/index.tsx +33 -2
  17. package/src/client/components/common/session-row/StatusSlot.tsx +4 -4
  18. package/src/client/components/common/session-row/index.tsx +27 -1
  19. package/src/client/components/layout/desktop-layout/WorkspacePanels.tsx +7 -1
  20. package/src/client/components/layout/desktop-layout/resizer/separator-drag.ts +3 -3
  21. package/src/client/components/layout/session-sidebar/CategoryItem.tsx +25 -12
  22. package/src/client/components/layout/session-sidebar/ChildSessionList.tsx +66 -0
  23. package/src/client/components/layout/session-sidebar/SessionItem.tsx +28 -3
  24. package/src/client/components/layout/session-sidebar/about-modal/HarnessTable.test.tsx +20 -0
  25. package/src/client/components/layout/session-sidebar/about-modal/HarnessTable.tsx +59 -12
  26. package/src/client/components/layout/session-sidebar/about-modal/HarnessTableLog.test.tsx +94 -0
  27. package/src/client/components/layout/session-sidebar/about-modal/UpdateLogDialog.test.tsx +130 -0
  28. package/src/client/components/layout/session-sidebar/about-modal/UpdateLogDialog.tsx +120 -0
  29. package/src/client/components/layout/session-sidebar/about-modal/UpdateLogLine.tsx +47 -0
  30. package/src/client/components/layout/session-sidebar/about-modal/index.test.tsx +122 -0
  31. package/src/client/components/layout/session-sidebar/about-modal/index.tsx +55 -46
  32. package/src/client/components/layout/session-sidebar/modern/WorkspaceSection.tsx +18 -5
  33. package/src/client/components/mobile/mobile-session-sidebar/Item.tsx +21 -4
  34. package/src/client/components/mobile/mobile-session-sidebar/SessionRow.tsx +27 -5
  35. package/src/client/components/settings/categories/harness-settings/EnvProviderForm.tsx +31 -0
  36. package/src/client/components/settings/categories/harness-settings/provider-panel.test.tsx +49 -0
  37. package/src/client/components/workspace/chat-timeline/ChatOverlays.tsx +5 -2
  38. package/src/client/components/workspace/chat-timeline/ComposerDock.tsx +64 -70
  39. package/src/client/components/workspace/chat-timeline/ComposerDockFrame.tsx +35 -0
  40. package/src/client/components/workspace/chat-timeline/EmptyWorkspacePrompt.tsx +135 -118
  41. package/src/client/components/workspace/chat-timeline/MessageItem.tsx +22 -1
  42. package/src/client/components/workspace/chat-timeline/MessageList.test.ts +14 -0
  43. package/src/client/components/workspace/chat-timeline/MessageList.tsx +4 -0
  44. package/src/client/components/workspace/chat-timeline/TimelineBody.tsx +3 -0
  45. package/src/client/components/workspace/chat-timeline/chat-input/index.tsx +4 -3
  46. package/src/client/components/workspace/chat-timeline/composer-dock-frame.test.tsx +155 -0
  47. package/src/client/components/workspace/chat-timeline/index.tsx +5 -2
  48. package/src/client/components/workspace/chat-timeline/pending-harness.test.tsx +1 -1
  49. package/src/client/components/workspace/chat-timeline/tool-renderers/ask-panel/FrameControl.tsx +11 -20
  50. package/src/client/components/workspace/chat-timeline/tool-renderers/ask-panel/GroupedAsk.tsx +1 -1
  51. package/src/client/components/workspace/chat-timeline/tool-renderers/ask-panel/QuestionBlock.tsx +1 -1
  52. package/src/client/components/workspace/chat-timeline/tool-renderers/ask-panel/drafts.ts +1 -1
  53. package/src/client/components/workspace/chat-timeline/tool-renderers/ask-panel/index.tsx +2 -1
  54. package/src/client/components/workspace/file-explorer/index.test.ts +25 -0
  55. package/src/client/components/workspace/file-explorer/index.tsx +9 -3
  56. package/src/client/components/workspace/model-dropdown/harness-models.test.ts +17 -0
  57. package/src/client/components/workspace/model-dropdown/harness-models.ts +33 -18
  58. package/src/client/components/workspace/model-dropdown/index.tsx +3 -3
  59. package/src/client/components/workspace/model-dropdown/popover-metrics.ts +4 -1
  60. package/src/client/components/workspace/terminal-panel/KeyBar.tsx +10 -8
  61. package/src/client/components/workspace/terminal-panel/{RealtimeXtermView.tsx → RealtimeTerminalView.tsx} +51 -58
  62. package/src/client/components/workspace/terminal-panel/fit.test.ts +37 -0
  63. package/src/client/components/workspace/terminal-panel/fit.ts +64 -0
  64. package/src/client/components/workspace/terminal-panel/fonts.test.ts +161 -0
  65. package/src/client/components/workspace/terminal-panel/fonts.ts +164 -0
  66. package/src/client/components/workspace/terminal-panel/grid.test.ts +52 -0
  67. package/src/client/components/workspace/terminal-panel/grid.ts +118 -0
  68. package/src/client/components/workspace/terminal-panel/index.tsx +25 -21
  69. package/src/client/components/workspace/terminal-panel/mount.ts +247 -223
  70. package/src/client/components/workspace/terminal-panel/navigation.test.ts +54 -0
  71. package/src/client/components/workspace/terminal-panel/navigation.ts +47 -0
  72. package/src/client/data/settings/omp-schema.json +5 -5
  73. package/src/client/data/theme/terminal.test.ts +25 -0
  74. package/src/client/data/theme/terminal.ts +96 -79
  75. package/src/client/hooks/chat/composer/items.test.ts +12 -26
  76. package/src/client/hooks/chat/composer/pick-mapping.test.ts +42 -0
  77. package/src/client/hooks/chat/omp/prompt-send.test.ts +7 -7
  78. package/src/client/hooks/chat/omp/prompt-send.ts +26 -14
  79. package/src/client/hooks/chat/timeline/actions.ts +2 -2
  80. package/src/client/hooks/chat/timeline/ask-frames.ts +5 -4
  81. package/src/client/hooks/chat/timeline/new-chat-open.test.ts +86 -0
  82. package/src/client/hooks/chat/timeline/new-chat-open.ts +23 -5
  83. package/src/client/hooks/chat/timeline/new-chat.test.ts +32 -4
  84. package/src/client/hooks/chat/timeline/new-chat.ts +18 -6
  85. package/src/client/hooks/chat/timeline/prompt-text.test.ts +34 -1
  86. package/src/client/hooks/chat/timeline/prompt-text.ts +47 -20
  87. package/src/client/hooks/chat/timeline/rewind-actions.test.ts +24 -1
  88. package/src/client/hooks/chat/timeline/rewind-actions.ts +15 -11
  89. package/src/client/hooks/chat/timeline/run-identity.test.ts +52 -0
  90. package/src/client/hooks/chat/timeline/run-identity.ts +23 -11
  91. package/src/client/hooks/chat/timeline/send-execute.test.ts +56 -0
  92. package/src/client/hooks/chat/timeline/send-helpers.ts +30 -1
  93. package/src/client/hooks/chat/timeline/send-props.ts +5 -3
  94. package/src/client/hooks/chat/timeline/send-steer.test.ts +4 -4
  95. package/src/client/hooks/chat/timeline/send.test-util.ts +8 -2
  96. package/src/client/hooks/chat/timeline/send.test.ts +4 -4
  97. package/src/client/hooks/chat/timeline/send.ts +59 -53
  98. package/src/client/hooks/chat/timeline/session-load.test-util.ts +6 -2
  99. package/src/client/hooks/chat/timeline/session-load.test.ts +31 -0
  100. package/src/client/hooks/chat/timeline/session-load.ts +6 -14
  101. package/src/client/hooks/chat/timeline/session-shapes.ts +32 -0
  102. package/src/client/hooks/chat/timeline/use-fork-session.ts +49 -0
  103. package/src/client/hooks/models/harness-catalog.ts +114 -0
  104. package/src/client/hooks/models/provider-writes.test.ts +81 -0
  105. package/src/client/hooks/models/provider-writes.ts +10 -3
  106. package/src/client/hooks/models/use-harness-update.test.ts +193 -0
  107. package/src/client/hooks/models/use-harness-update.ts +202 -0
  108. package/src/client/hooks/models/use-harnesses-controller.ts +57 -0
  109. package/src/client/hooks/models/use-harnesses-signal.test.ts +128 -0
  110. package/src/client/hooks/models/use-harnesses.test.ts +2 -1
  111. package/src/client/hooks/models/use-harnesses.ts +48 -114
  112. package/src/client/hooks/workspace/child-expansion.ts +33 -0
  113. package/src/client/hooks/workspace/terminal/index.ts +17 -3
  114. package/src/client/hooks/workspace/terminal/socket.ts +9 -4
  115. package/src/client/lib/session-tree.test.ts +50 -0
  116. package/src/client/lib/session-tree.ts +59 -0
  117. package/src/client/tailwind.css +26 -12
  118. package/src/server/index.ts +2 -0
  119. package/src/server/lib/auth/guard.ts +10 -0
  120. package/src/server/lib/btw/session-copy.server.ts +6 -44
  121. package/src/server/lib/btw/session-copy.test.ts +2 -1
  122. package/src/server/lib/db/schema.ts +4 -0
  123. package/src/server/lib/db/seed-terminal.test.ts +1 -1
  124. package/src/server/lib/db/seed.test.ts +1 -1
  125. package/src/server/lib/harness/acp/activation.test.ts +81 -0
  126. package/src/server/lib/harness/acp/activation.ts +72 -0
  127. package/src/server/lib/harness/acp/background-work.test.ts +262 -0
  128. package/src/server/lib/harness/acp/background-work.ts +320 -0
  129. package/src/server/lib/harness/acp/client.ts +2 -2
  130. package/src/server/lib/harness/acp/frames.test.ts +50 -1
  131. package/src/server/lib/harness/acp/frames.ts +17 -5
  132. package/src/server/lib/harness/acp/gateway-env.test.ts +64 -0
  133. package/src/server/lib/harness/acp/gateway-env.ts +70 -0
  134. package/src/server/lib/harness/acp/mapper.ts +6 -4
  135. package/src/server/lib/harness/acp/prompt.test.ts +20 -0
  136. package/src/server/lib/harness/acp/prompt.ts +19 -3
  137. package/src/server/lib/harness/acp/session-background.test.ts +129 -0
  138. package/src/server/lib/harness/acp/session-config.test.ts +73 -0
  139. package/src/server/lib/harness/acp/session-config.ts +87 -6
  140. package/src/server/lib/harness/acp/session-exit.ts +31 -0
  141. package/src/server/lib/harness/acp/session-handshake.test.ts +108 -0
  142. package/src/server/lib/harness/acp/session-handshake.ts +36 -3
  143. package/src/server/lib/harness/acp/session-idle.ts +51 -0
  144. package/src/server/lib/harness/acp/session-listeners.ts +31 -0
  145. package/src/server/lib/harness/acp/session-notifications.ts +19 -3
  146. package/src/server/lib/harness/acp/session-observers.test.ts +9 -0
  147. package/src/server/lib/harness/acp/session-options.ts +33 -0
  148. package/src/server/lib/harness/acp/session-reaper.test.ts +96 -0
  149. package/src/server/lib/harness/acp/session-requests.ts +47 -0
  150. package/src/server/lib/harness/acp/session-turns.ts +20 -5
  151. package/src/server/lib/harness/acp/session.test-util.ts +54 -3
  152. package/src/server/lib/harness/acp/session.test.ts +65 -3
  153. package/src/server/lib/harness/acp/session.ts +79 -79
  154. package/src/server/lib/harness/acp/turn.test.ts +81 -0
  155. package/src/server/lib/harness/acp/turn.ts +54 -13
  156. package/src/server/lib/harness/acp/verbs.ts +12 -2
  157. package/src/server/lib/harness/auto-probe.server.test.ts +121 -0
  158. package/src/server/lib/harness/auto-probe.server.ts +178 -0
  159. package/src/server/lib/harness/config.server.test.ts +1 -1
  160. package/src/server/lib/harness/config.server.ts +1 -1
  161. package/src/server/lib/harness/launch-table.ts +195 -0
  162. package/src/server/lib/harness/launch.test.ts +37 -0
  163. package/src/server/lib/harness/launch.ts +16 -116
  164. package/src/server/lib/harness/provider-entry.ts +32 -0
  165. package/src/server/lib/harness/provider-file.server.ts +3 -0
  166. package/src/server/lib/harness/provider-sources.server.test.ts +45 -0
  167. package/src/server/lib/harness/provider-sources.server.ts +26 -2
  168. package/src/server/lib/harness/provider-write.server.ts +21 -32
  169. package/src/server/lib/harness/provider-zcode.server.test.ts +270 -0
  170. package/src/server/lib/harness/provider-zcode.server.ts +324 -0
  171. package/src/server/lib/harness/spawn.server.ts +15 -2
  172. package/src/server/lib/harness/update-job-store.test.ts +126 -0
  173. package/src/server/lib/harness/update-job-store.ts +109 -0
  174. package/src/server/lib/harness/update-job.server.ts +203 -0
  175. package/src/server/lib/harness/update-state.server.ts +15 -20
  176. package/src/server/lib/harness/update-worker.test.ts +153 -0
  177. package/src/server/lib/harness/update-worker.ts +197 -0
  178. package/src/server/lib/lifecycle/after-listen.ts +7 -0
  179. package/src/server/lib/lifecycle/paths.ts +23 -0
  180. package/src/server/lib/models/registry-refresh.server.test.ts +87 -0
  181. package/src/server/lib/models/registry-refresh.server.ts +98 -0
  182. package/src/server/lib/omp/rpc/child-config.ts +5 -4
  183. package/src/server/lib/omp/rpc/constants.test.ts +2 -1
  184. package/src/server/lib/omp/rpc/forked-resume.test.ts +14 -3
  185. package/src/server/lib/omp/rpc/manager.ts +5 -5
  186. package/src/server/lib/omp/rpc/prewarm-pool.ts +12 -3
  187. package/src/server/lib/omp/rpc/session-registry.ts +14 -2
  188. package/src/server/lib/omp/rpc/terminal-settle.ts +53 -5
  189. package/src/server/lib/omp/session/delete-flow.server.ts +62 -8
  190. package/src/server/lib/omp/session/delete.server.ts +17 -0
  191. package/src/server/lib/omp/session/rewind-file.ts +39 -21
  192. package/src/server/lib/omp/session/sidebar-data.server.ts +6 -6
  193. package/src/server/lib/omp/session/transcript-copy.ts +123 -0
  194. package/src/server/lib/sessions/agent-token.server.test.ts +64 -0
  195. package/src/server/lib/sessions/agent-token.server.ts +134 -0
  196. package/src/server/lib/sessions/answers.server.test.ts +33 -0
  197. package/src/server/lib/sessions/answers.server.ts +37 -0
  198. package/src/server/lib/sessions/dispatch.server.test.ts +143 -0
  199. package/src/server/lib/sessions/dispatch.server.ts +128 -0
  200. package/src/server/lib/sessions/fork.server.test.ts +209 -0
  201. package/src/server/lib/sessions/fork.server.ts +304 -0
  202. package/src/server/lib/sessions/lifecycle.server.test.ts +75 -0
  203. package/src/server/lib/sessions/lifecycle.server.ts +71 -0
  204. package/src/server/lib/sessions/notify.server.test.ts +112 -0
  205. package/src/server/lib/sessions/notify.server.ts +212 -0
  206. package/src/server/lib/sessions/relation-types.ts +76 -0
  207. package/src/server/lib/sessions/relations.server.test.ts +207 -0
  208. package/src/server/lib/sessions/relations.server.ts +337 -0
  209. package/src/server/lib/sessions/resolve.server.ts +106 -0
  210. package/src/server/lib/sessions/schema.server.ts +82 -0
  211. package/src/server/lib/sessions/sidebar-relations.server.test.ts +61 -0
  212. package/src/server/lib/sessions/sidebar-relations.server.ts +47 -0
  213. package/src/server/lib/sessions/spawn.server.test.ts +196 -0
  214. package/src/server/lib/sessions/spawn.server.ts +310 -0
  215. package/src/server/lib/terminal/attach-replay.test.ts +2 -2
  216. package/src/server/lib/terminal/output.test.ts +2 -2
  217. package/src/server/lib/terminal/output.ts +1 -1
  218. package/src/server/lib/terminal/resize.test.ts +99 -0
  219. package/src/server/lib/terminal/runtime.server.ts +26 -6
  220. package/src/server/lib/terminal/send-result.test.ts +18 -1
  221. package/src/server/lib/terminal/send-result.ts +26 -2
  222. package/src/server/lib/terminal/session.server.ts +6 -6
  223. package/src/server/lib/usage/new-api.test.ts +92 -0
  224. package/src/server/lib/usage/new-api.ts +131 -0
  225. package/src/server/lib/usage/provider-endpoint.test.ts +106 -0
  226. package/src/server/lib/usage/provider-key.ts +33 -0
  227. package/src/server/lib/usage/providers.server.ts +10 -3
  228. package/src/server/lib/usage/vendor-balance.server.ts +4 -53
  229. package/src/server/lib/usage/vendor-http.ts +41 -0
  230. package/src/server/lib/usage/window.ts +55 -0
  231. package/src/server/routes/agent/command.ts +14 -1
  232. package/src/server/routes/agent/harness-command.ts +6 -0
  233. package/src/server/routes/agent/new.ts +15 -0
  234. package/src/server/routes/chat/rewind.test.ts +147 -0
  235. package/src/server/routes/chat/rewind.ts +29 -7
  236. package/src/server/routes/chat/session.test.ts +165 -10
  237. package/src/server/routes/chat/session.ts +60 -7
  238. package/src/server/routes/harness/add-provider.test.ts +9 -1
  239. package/src/server/routes/harness/import-action.ts +22 -4
  240. package/src/server/routes/harness/import.test.ts +1 -1
  241. package/src/server/routes/harness/index.ts +5 -1
  242. package/src/server/routes/harness/root.ts +8 -49
  243. package/src/server/routes/harness/toggle.test.ts +20 -0
  244. package/src/server/routes/harness/update-status.ts +26 -0
  245. package/src/server/routes/harness/update.test.ts +119 -0
  246. package/src/server/routes/harness/update.ts +67 -113
  247. package/src/server/routes/harness/versions.ts +5 -1
  248. package/src/server/routes/sessions/answer.ts +24 -0
  249. package/src/server/routes/sessions/batch-delete.ts +11 -5
  250. package/src/server/routes/sessions/delete-acp.test.ts +227 -0
  251. package/src/server/routes/sessions/delete.ts +4 -2
  252. package/src/server/routes/sessions/fork.ts +74 -0
  253. package/src/server/routes/sessions/index.ts +14 -0
  254. package/src/server/routes/sessions/relations.ts +85 -0
  255. package/src/server/routes/sessions/session.ts +4 -0
  256. package/src/server/routes/sessions/spawn.ts +134 -0
  257. package/src/server/routes/settings/model-override.ts +5 -2
  258. package/src/server/routes/settings/provider-entry.ts +2 -2
  259. package/src/server/routes/settings/provider-model.ts +2 -2
  260. package/src/server/routes/settings/provider-models.ts +2 -2
  261. package/src/server/routes/settings/provider-refresh.ts +6 -4
  262. package/src/server/routes/settings/providers.ts +3 -1
  263. package/src/server/routes/settings/settings-config-routes.test.ts +10 -2
  264. package/src/server/routes/terminal/ws.ts +3 -3
  265. package/src/shared/lib/chat/ask-form/fields.ts +76 -0
  266. package/src/shared/lib/chat/ask-form/index.ts +323 -0
  267. package/src/shared/lib/chat/ask-form/tokens.ts +199 -0
  268. package/src/shared/lib/chat/ask-form/types.ts +43 -0
  269. package/src/shared/lib/chat/ask-form.test.ts +137 -0
  270. package/src/shared/lib/chat/ask-questions.test.ts +65 -1
  271. package/src/shared/lib/chat/ask-questions.ts +51 -145
  272. package/src/shared/lib/chat/ask-results.ts +198 -0
  273. package/src/shared/lib/chat/composer/client.ts +31 -2
  274. package/src/shared/lib/chat/composer/delegation.test.ts +93 -0
  275. package/src/shared/lib/chat/composer/delegation.ts +206 -0
  276. package/src/shared/lib/chat/notice-text.ts +1 -1
  277. package/src/shared/lib/chat/timeline/omp-callbacks.ts +13 -1
  278. package/src/shared/lib/chat/timeline/prompt-error.test.ts +146 -0
  279. package/src/shared/lib/chat/timeline/prompt-error.ts +88 -0
  280. package/src/shared/lib/chat/tool/summary-wait.test.ts +11 -0
  281. package/src/shared/lib/code/ansi.ts +1 -1
  282. package/src/shared/lib/fonts/nerd-symbols.css +4 -3
  283. package/src/shared/lib/fonts/nerd-symbols.test.ts +9 -9
  284. package/src/shared/lib/harness/catalog.test.ts +1 -1
  285. package/src/shared/lib/harness/config-fields.test.ts +4 -0
  286. package/src/shared/lib/harness/config-fields.ts +19 -4
  287. package/src/shared/lib/harness/dialects.test.ts +8 -0
  288. package/src/shared/lib/harness/dialects.ts +12 -0
  289. package/src/shared/lib/harness/provider-facts.test.ts +59 -8
  290. package/src/shared/lib/harness/provider-facts.ts +46 -11
  291. package/src/shared/lib/harness/providers.ts +44 -1
  292. package/src/shared/lib/harness/rewind.ts +24 -0
  293. package/src/shared/lib/harness/update-job.ts +33 -0
  294. package/src/shared/lib/harness/update-plan.test.ts +69 -4
  295. package/src/shared/lib/harness/update-plan.ts +57 -9
  296. package/src/shared/lib/harness/updates.test.ts +22 -0
  297. package/src/shared/lib/harness/updates.ts +24 -1
  298. package/src/shared/lib/models/client.ts +10 -1
  299. package/src/shared/lib/omp/dialog-methods.ts +4 -3
  300. package/src/shared/lib/omp/session/wait-idle.test.ts +11 -0
  301. package/src/shared/lib/omp/session/wait-idle.ts +12 -2
  302. package/src/shared/lib/theme/catalog.test.ts +13 -9
  303. package/src/shared/lib/theme/color.test.ts +2 -2
  304. package/src/shared/lib/theme/color.ts +4 -4
  305. package/src/shared/lib/theme/css.ts +2 -0
  306. package/src/shared/lib/theme/ink-scale.ts +21 -1
  307. package/src/shared/lib/theme/theme.test.ts +26 -10
  308. package/src/shared/lib/ui/safe-area.test.ts +28 -0
  309. package/src/shared/lib/ui/safe-area.ts +42 -0
  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 +65 -0
  316. package/src/shared/types/harness.ts +30 -4
  317. package/src/shared/types/omp/agent.ts +19 -2
  318. package/src/shared/types/workspace.ts +4 -0
  319. package/src/test-support/fake-omp-fork.ts +16 -2
  320. package/src/test-support/file-explorer-render.test-util.ts +37 -0
  321. package/src/test-support/file-explorer.test-util.ts +20 -18
  322. package/src/test-support/harness-table.test-util.ts +21 -4
  323. package/dist/client/static/js/index-jhmg4w91.css +0 -1
  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,73 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * A config write must leave the session naming the model the agent is actually
8
+ * serving.
9
+ *
10
+ * The protocol says `session/set_config_option` replies with the complete list,
11
+ * and the agent's `currentValue` is authoritative (an alias or fallback may
12
+ * differ from the request). This suite pins the fallback for a harness that
13
+ * answers `{}` — the shape that left a chat's footer and sidebar row on the
14
+ * model from `session/new` for the rest of its life.
15
+ */
16
+
17
+ import { describe, expect, test } from 'bun:test';
18
+ import { adoptConfigAnswer, adoptConfigList, publishConfigChange } from '@/server/lib/harness/acp/session-config';
19
+ import type { AcpConfigOption } from '@/server/lib/harness/acp/protocol';
20
+
21
+ const option = (id: string, category: string, currentValue: string, values: string[]): AcpConfigOption => ({
22
+ id,
23
+ category,
24
+ type: 'select',
25
+ currentValue,
26
+ options: values.map((value) => ({ value })),
27
+ });
28
+
29
+ const target = () => ({
30
+ harness: 'claude' as const,
31
+ configOptions: [option('sel-model', 'model', 'p/old', ['p/old', 'p/new'])],
32
+ runModel: { provider: 'p', modelId: 'old' },
33
+ });
34
+
35
+ describe('ACP config adoption', () => {
36
+ test('a reply that omits the list adopts the value that was written', () => {
37
+ const session = target();
38
+ adoptConfigAnswer(session, {}, { configId: 'sel-model', value: 'p/new' });
39
+ expect(session.configOptions[0]?.currentValue).toBe('p/new');
40
+ expect(session.runModel).toEqual({ provider: 'p', modelId: 'new' });
41
+ });
42
+
43
+ test('the agent’s resolved list wins over the request', () => {
44
+ const session = target();
45
+ adoptConfigAnswer(
46
+ session,
47
+ { configOptions: [option('sel-model', 'model', 'p/resolved', ['p/old', 'p/new', 'p/resolved'])] },
48
+ { configId: 'sel-model', value: 'p/new' },
49
+ );
50
+ expect(session.runModel).toEqual({ provider: 'p', modelId: 'resolved' });
51
+ });
52
+
53
+ test('the array-shaped value some harnesses publish keeps its provider', () => {
54
+ const session = target();
55
+ adoptConfigList(session, [option('sel-model', 'model', '["kenari","deepseek-v4-flash"]', ['["kenari","deepseek-v4-flash"]'])]);
56
+ expect(session.runModel).toEqual({ provider: 'kenari', modelId: 'deepseek-v4-flash' });
57
+ });
58
+
59
+ test('a pushed list announces the identity the client must re-read', () => {
60
+ const emitted: Array<Record<string, unknown> & { type: string }> = [];
61
+ const session = {
62
+ ...target(),
63
+ sessionId: 's1',
64
+ isStreaming: false,
65
+ emit: (event: Record<string, unknown> & { type: string }) => {
66
+ emitted.push(event);
67
+ },
68
+ };
69
+ adoptConfigList(session, [option('sel-model', 'model', 'p/new', ['p/new'])]);
70
+ publishConfigChange(session);
71
+ expect(emitted).toContainEqual({ type: 'model_changed' });
72
+ });
73
+ });
@@ -16,6 +16,11 @@
16
16
  * from this field, so a session that kept its own request would announce a model
17
17
  * the answer did not come from.
18
18
  *
19
+ * A harness that answers with no list is the exception: the write succeeded, so
20
+ * the requested value is adopted and a later `config_option_update` corrects it.
21
+ * Leaving the session on its `session/new` model made the footer and the sidebar
22
+ * row name the first model the chat ever picked for the rest of its life.
23
+ *
19
24
  * ## Why every approval exit answers
20
25
  *
21
26
  * The agent is PARKED on `session/request_permission` until it hears back: a
@@ -27,7 +32,9 @@
27
32
  import { configOption, modelFromOption } from '@/server/lib/harness/acp/prompt';
28
33
  import type { AcpConfigOption } from '@/server/lib/harness/acp/protocol';
29
34
  import type { PendingPermissions } from '@/server/lib/harness/acp/permissions';
35
+ import { markStreamModel } from '@/shared/lib/omp/session/stream-state.server';
30
36
  import type { HarnessId } from '@/shared/lib/harness/catalog';
37
+ import type { AgentEvent } from '@/server/lib/omp/rpc/constants';
31
38
 
32
39
  /** The fields a config answer rewrites. */
33
40
  export interface AcpConfigTarget {
@@ -36,14 +43,88 @@ export interface AcpConfigTarget {
36
43
  runModel: { provider: string; modelId: string } | null;
37
44
  }
38
45
 
39
- /** Adopt `session/set_config_option`'s reply, when it carries a config list. */
40
- export function adoptConfigOptions(target: AcpConfigTarget, result: unknown): void {
46
+ /** The target plus what publishing a change needs: a live run row to rename and
47
+ * a frame stream the client folds. */
48
+ export interface AcpConfigNotice extends AcpConfigTarget {
49
+ readonly sessionId: string;
50
+ readonly isStreaming: boolean;
51
+ emit(event: Record<string, unknown> & { type: string }): void;
52
+ }
53
+
54
+ /** Write the agent's COMPLETE config list into the session. */
55
+ export function adoptConfigList(target: AcpConfigTarget, options: AcpConfigOption[]): void {
56
+ target.configOptions = options;
57
+ const resolved = modelFromOption(configOption(options, 'model'), target.harness);
58
+ if (resolved) target.runModel = resolved;
59
+ }
60
+
61
+ /** Adopt `session/set_config_option`'s reply when it carries a config list. */
62
+ export function adoptConfigOptions(target: AcpConfigTarget, result: unknown): boolean {
41
63
  if (!result || typeof result !== 'object' || !('configOptions' in result) || !Array.isArray(result.configOptions)) {
42
- return;
64
+ return false;
43
65
  }
44
- target.configOptions = result.configOptions as AcpConfigOption[];
45
- const resolved = modelFromOption(configOption(target.configOptions, 'model'), target.harness);
46
- if (resolved) target.runModel = resolved;
66
+ adoptConfigList(target, result.configOptions as AcpConfigOption[]);
67
+ return true;
68
+ }
69
+
70
+ /**
71
+ * Adopt a config WRITE even when the agent omitted the reply list.
72
+ *
73
+ * The protocol says the reply MUST carry the complete list, and every measured
74
+ * adapter does — but a harness that answers `{}` left the session naming the
75
+ * model from `session/new`, so the run footer and the sidebar row reported the
76
+ * first model the chat ever picked for the rest of its life. The write itself
77
+ * succeeded, so the requested value is the best state we have; a later
78
+ * `config_option_update` (or the next reply) replaces it with the agent's own.
79
+ */
80
+ export function adoptConfigAnswer(
81
+ target: AcpConfigTarget,
82
+ result: unknown,
83
+ requested: { configId: string; value: string | boolean },
84
+ ): void {
85
+ if (adoptConfigOptions(target, result)) return;
86
+ if (!target.configOptions.some((option) => option.id === requested.configId)) return;
87
+ adoptConfigList(
88
+ target,
89
+ target.configOptions.map((option) =>
90
+ option.id === requested.configId ? { ...option, currentValue: requested.value } : option,
91
+ ),
92
+ );
93
+ }
94
+
95
+ /**
96
+ * Announce a written config option on the session's own frame stream — the
97
+ * vocabulary omp already uses, so the client's existing `model_changed`
98
+ * handler refreshes the session metadata (and thus the footer/composer) with
99
+ * no second path. A live run row is renamed here too: a `set_model` can land
100
+ * while a turn is streaming, and the sidebar/indicator read that row, not
101
+ * `get_state`.
102
+ */
103
+ export function publishConfigChange(target: AcpConfigNotice, configId?: string): void {
104
+ if (target.runModel && target.isStreaming) {
105
+ void markStreamModel(target.sessionId, target.runModel).catch(() => {});
106
+ }
107
+ const written = configId ? target.configOptions.find((option) => option.id === configId) : null;
108
+ // No id means the agent pushed a fresh list (`config_option_update`): any of
109
+ // its selectors may have moved, so name both known identities.
110
+ if (!written || written.category === 'model') {
111
+ if (target.runModel) target.emit({ type: 'model_changed' });
112
+ }
113
+ const thinking = configOption(target.configOptions, 'thought_level');
114
+ if ((!written || written.category === 'thought_level') && typeof thinking?.currentValue === 'string') {
115
+ target.emit({ type: 'thinking_level_changed', thinkingLevel: thinking.currentValue });
116
+ }
117
+ }
118
+
119
+ /** The model fields the footer/indicator read, or the frame unchanged. */
120
+ export function stampMessageModel(event: AgentEvent, model: { provider: string; modelId: string } | null): AgentEvent {
121
+ if (!model) return event;
122
+ if (event.type !== 'message_update' && event.type !== 'message_end') return event;
123
+ if (!event.message || typeof event.message !== 'object') return event;
124
+ return {
125
+ ...event,
126
+ message: { ...event.message, model: model.modelId, provider: model.provider },
127
+ };
47
128
  }
48
129
 
49
130
  /** The process slice answering a dialog needs; `AcpProcess` satisfies it. */
@@ -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
+ }
@@ -0,0 +1,108 @@
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
+ return { protocolVersion: 1, agentCapabilities: {} };
51
+ },
52
+ async loadSession() {
53
+ calls.push('load');
54
+ },
55
+ async newSession() {
56
+ calls.push('new');
57
+ return { sessionId: 'new-id' };
58
+ },
59
+ ...overrides,
60
+ };
61
+ }
62
+
63
+ describe('handshakeAcpSession', () => {
64
+ test('new starts a new agent session', async () => {
65
+ const proc = processDouble();
66
+ await handshakeAcpSession(target(), proc, { model: null, thinking: null, mode: null });
67
+ expect(proc.calls).toEqual(['new']);
68
+ });
69
+
70
+ test('load restores and then starts the replacement session', async () => {
71
+ const proc = processDouble();
72
+ await handshakeAcpSession(target(), proc, { model: null, thinking: null, mode: null }, 'agent-1');
73
+ expect(proc.calls).toEqual(['load', 'new']);
74
+ });
75
+
76
+ test('fork asks the agent for session/fork and uses the returned id', async () => {
77
+ const proc = processDouble({
78
+ async forkSession(sessionId: string) {
79
+ proc.calls.push(`fork:${sessionId}`);
80
+ return { sessionId: 'forked-id' };
81
+ },
82
+ });
83
+ const session = target();
84
+ await handshakeAcpSession(
85
+ session,
86
+ proc,
87
+ { model: null, thinking: null, mode: null },
88
+ undefined,
89
+ 'agent-1',
90
+ );
91
+ expect(proc.calls).toEqual(['fork:agent-1']);
92
+ expect(session.sessionId).toBe('forked-id');
93
+ });
94
+
95
+ test('a process with no fork verb refuses instead of creating an empty session', async () => {
96
+ const proc = processDouble();
97
+ await expect(
98
+ handshakeAcpSession(
99
+ target(),
100
+ proc,
101
+ { model: null, thinking: null, mode: null },
102
+ undefined,
103
+ 'agent-1',
104
+ ),
105
+ ).rejects.toThrow('cannot fork');
106
+ expect(proc.calls).toEqual([]);
107
+ });
108
+ });
@@ -24,6 +24,7 @@
24
24
  * string as the model id — which is what the generating indicator names.
25
25
  */
26
26
 
27
+ import { newSessionAfterActivation } from '@/server/lib/harness/acp/activation';
27
28
  import { applySelections, configOption, modelFromOption } from '@/server/lib/harness/acp/prompt';
28
29
  import { capabilitiesFrom } from '@/server/lib/harness/launch';
29
30
  import type {
@@ -39,6 +40,13 @@ export interface AcpHandshakeProcess {
39
40
  initialize(params: Record<string, unknown>, timeoutMs?: number): Promise<AcpInitializeResult>;
40
41
  loadSession(sessionId: string, cwd: string, timeoutMs?: number): Promise<unknown>;
41
42
  newSession(cwd: string, timeoutMs?: number): Promise<AcpSessionNewResult>;
43
+ /** `session/fork`; absent on a process double used by older tests. */
44
+ forkSession?(
45
+ sessionId: string,
46
+ cwd: string,
47
+ timeoutMs?: number,
48
+ target?: Record<string, unknown>,
49
+ ): Promise<AcpSessionNewResult>;
42
50
  }
43
51
 
44
52
  /** The session fields a handshake seeds. */
@@ -64,15 +72,40 @@ export async function handshakeAcpSession(
64
72
  proc: AcpHandshakeProcess,
65
73
  wanted: AcpHandshakeSelections,
66
74
  sessionIdToLoad?: string,
75
+ forkFromSessionId?: string,
67
76
  ): Promise<void> {
68
77
  const init = await proc.initialize({}, 60_000);
78
+ /** opencode's plugin activation gate: the first `session/new`s refuse with
79
+ * `ServiceUnavailableError` until the agent's plugins finish booting. */
80
+ const newSession = (cwd: string, timeoutMs?: number) =>
81
+ newSessionAfterActivation(target.harness, cwd, (dir, ms) => proc.newSession(dir, ms), {
82
+ ...(timeoutMs !== undefined ? { perAttemptMs: timeoutMs } : {}),
83
+ });
69
84
  let session: AcpSessionNewResult;
70
- if (sessionIdToLoad) {
85
+ if (forkFromSessionId) {
86
+ // A fork is a NEW agent session that inherits the source's context; the
87
+ // returned id is the child's own. Refusing here is deliberate: silently
88
+ // falling back to `session/new` would start an empty chat under a fork's
89
+ // name, which is the substitution this feature exists to prevent.
90
+ if (!proc.forkSession) {
91
+ throw new Error(`${target.harness} cannot fork a session`);
92
+ }
93
+ session = await proc.forkSession(
94
+ forkFromSessionId,
95
+ target.cwd,
96
+ 120_000,
97
+ // zcode's fork is checkpoint-scoped; its schema defaults `target` but
98
+ // the ACP call needs it stated or the runtime answers "sessionId is
99
+ // required" for a request it cannot place. Other harnesses reject an
100
+ // unknown `target`, so it is sent only where it is understood.
101
+ target.harness === 'zcode' ? { kind: 'latestCheckpoint' } : undefined,
102
+ );
103
+ } else if (sessionIdToLoad) {
71
104
  await proc.loadSession(sessionIdToLoad, target.cwd, 120_000);
72
- const reloaded = await proc.newSession(target.cwd).catch(() => null);
105
+ const reloaded = await newSession(target.cwd).catch(() => null);
73
106
  session = reloaded ?? { sessionId: sessionIdToLoad };
74
107
  } else {
75
- session = await proc.newSession(target.cwd, 120_000);
108
+ session = await newSession(target.cwd, 120_000);
76
109
  }
77
110
  target.sessionId = session.sessionId || sessionIdToLoad || '';
78
111
  target.configOptions = session.configOptions ?? [];
@@ -0,0 +1,51 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * The idle reclaim for one ACP child.
8
+ *
9
+ * The omp wrapper has always reclaimed an idle `omp --mode rpc-ui` child; this
10
+ * transport had no clock at all, so an `omp acp` (or any ACP adapter) outlived
11
+ * the tab that spawned it by hours — measured: a live `omp acp` from a chat the
12
+ * user had not touched since the morning. The clock itself is `IdleReaper`,
13
+ * shared so both transports release an idle agent after the same window, and
14
+ * the decision is here because only the session can answer "is this still
15
+ * wanted?".
16
+ */
17
+
18
+ import { IdleReaper } from '@/server/lib/omp/rpc/idle-reaper';
19
+ import { IDLE_REAP_MS } from '@/server/lib/omp/rpc/constants';
20
+ import type { HarnessCapabilities } from '@/server/lib/harness/capabilities';
21
+ import type { HarnessId } from '@/shared/lib/harness/catalog';
22
+
23
+ /** What the reclaim decision reads; `AcpSession` satisfies it as-is. */
24
+ export interface AcpIdleHost {
25
+ readonly harness: HarnessId;
26
+ readonly capabilities: HarnessCapabilities;
27
+ isBusy(): boolean;
28
+ destroy(): void;
29
+ }
30
+
31
+ /**
32
+ * A working or dialog-blocked session is never reclaimed (the child would take
33
+ * the user's question with it), and the answer is `false` so `IdleReaper`
34
+ * re-arms instead of waiting for a frame that a parked dialog will not send.
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.
41
+ */
42
+ export function reclaimIdleAcpSession(host: AcpIdleHost): boolean {
43
+ if (host.isBusy()) return false;
44
+ if (!host.capabilities.loadSession && host.harness !== 'omp-acp') return true;
45
+ host.destroy();
46
+ return true;
47
+ }
48
+
49
+ export function acpIdleReaper(host: AcpIdleHost, timeoutMs?: number): IdleReaper {
50
+ return new IdleReaper(timeoutMs ?? IDLE_REAP_MS, () => reclaimIdleAcpSession(host));
51
+ }
@@ -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
+ }
@@ -20,9 +20,17 @@ import type { AgentEvent } from '@/server/lib/omp/rpc/constants';
20
20
  import type { HarnessCapabilities } from '@/server/lib/harness/capabilities';
21
21
  import { noteAgentTitle } from '@/server/lib/harness/session-title.server';
22
22
  import { metadataCapabilities, parseAgentCommands, type AgentCommand } from '@/server/lib/harness/acp/session-facts';
23
+ import {
24
+ adoptConfigList,
25
+ publishConfigChange,
26
+ stampMessageModel,
27
+ type AcpConfigNotice,
28
+ } from '@/server/lib/harness/acp/session-config';
29
+ import type { AcpConfigOption } from '@/server/lib/harness/acp/protocol';
30
+ import type { HarnessId } from '@/shared/lib/harness/catalog';
23
31
 
24
- export interface AcpNotificationHost {
25
- readonly sessionId: string;
32
+ export interface AcpNotificationHost extends AcpConfigNotice {
33
+ readonly harness: HarnessId;
26
34
  agentCommands: AgentCommand[];
27
35
  planEntries: unknown[];
28
36
  capabilities: HarnessCapabilities;
@@ -63,6 +71,14 @@ export function handleSessionNotification(
63
71
  if (kind === 'session_info_update' && typeof record.title === 'string' && host.sessionId) {
64
72
  void noteAgentTitle(host.sessionId, record.title);
65
73
  }
74
+ // The agent can move a selector itself (a fallback, a dependent option after a
75
+ // model switch). Its list is authoritative and arrives between turns, so it
76
+ // is adopted BEFORE the turn gate below — the session, telemetry and the goal
77
+ // audit must read the same model the client's `config_option_update` names.
78
+ if (kind === 'config_option_update' && Array.isArray(record.configOptions)) {
79
+ adoptConfigList(host, record.configOptions as AcpConfigOption[]);
80
+ publishConfigChange(host);
81
+ }
66
82
 
67
83
  // No turn open: the user stopped it (or one is still queued), and anything
68
84
  // the agent keeps emitting belongs to work nobody is watching. Forwarding it
@@ -70,7 +86,7 @@ export function handleSessionNotification(
70
86
  // a transcript the client had already finalized.
71
87
  if (!host.acceptingFrames()) return;
72
88
  for (const event of host.mapUpdate(record)) {
73
- host.emit(event);
89
+ host.emit(stampMessageModel(event, host.runModel));
74
90
  if (event.type === 'message_end') {
75
91
  host.messageCount += 1;
76
92
  host.assistantCount += 1;
@@ -53,6 +53,15 @@ describe('ACP silent turn', () => {
53
53
  expect(error).toMatchObject({ errorMessage: 'The agent ended the turn without sending an answer' });
54
54
  });
55
55
 
56
+ test('a whitespace-only chunk is the same silent failure', async () => {
57
+ // The row renders no text, so a frame that carries only spaces looks exactly
58
+ // like an empty bubble — reporting it is the only way the operator learns
59
+ // the turn failed.
60
+ const events = await finishWith('Say DUMMY_OK', ' \n ');
61
+ const error = events.find((event) => event.type === 'prompt_error');
62
+ expect(error).toMatchObject({ errorMessage: 'The agent ended the turn without sending an answer' });
63
+ });
64
+
56
65
  test('an answered turn reports no error', async () => {
57
66
  const events = await finishWith('Say DUMMY_OK', 'DUMMY_OK');
58
67
  expect(events.some((event) => event.type === 'prompt_error')).toBe(false);