@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
@@ -12,13 +12,63 @@
12
12
  * (or, after a restart, the last run's stream row) is the only truthful source.
13
13
  */
14
14
 
15
- import { afterEach, beforeEach, describe, expect, test } from 'bun:test';
15
+ import { afterAll, afterEach, beforeEach, describe, expect, test } from 'bun:test';
16
+ import fs from 'node:fs';
17
+ import { tmpdir } from 'node:os';
18
+ import { join } from 'node:path';
16
19
  import { isolateDb, releaseDb } from '@/test-support/isolated-db';
17
20
  import { loader } from '@/server/routes/chat/session';
18
21
  import { registerAcpSession } from '@/server/lib/harness/register.server';
19
22
  import { claimHarness } from '@/server/lib/harness/registry';
23
+ import { clearSessionFileCaches } from '@/server/lib/omp/session/files';
20
24
  import type { HarnessSession } from '@/server/lib/harness/session';
21
25
 
26
+ /** The temp agent dir an on-disk transcript needs, since `findSessionFileById`
27
+ * resolves through the real sessions root. */
28
+ const previousAgentDir = Bun.env.PI_CODING_AGENT_DIR;
29
+ const previousXdg = Bun.env.XDG_DATA_HOME;
30
+ let agentRoot = '';
31
+ let sessionsRoot = '';
32
+
33
+ beforeEach(async () => {
34
+ agentRoot = await fs.promises.mkdtemp(join(tmpdir(), 'kabmo-acp-session-'));
35
+ sessionsRoot = join(agentRoot, 'sessions');
36
+ await fs.promises.mkdir(sessionsRoot, { recursive: true });
37
+ Bun.env.PI_CODING_AGENT_DIR = agentRoot;
38
+ // An existing XDG root redirects the sessions dir away from the temp one.
39
+ delete Bun.env.XDG_DATA_HOME;
40
+ clearSessionFileCaches();
41
+ delete Bun.env.MOCK;
42
+ await isolateDb();
43
+ });
44
+
45
+ afterEach(async () => {
46
+ clearSessionFileCaches();
47
+ await fs.promises.rm(agentRoot, { recursive: true, force: true });
48
+ await releaseDb();
49
+ });
50
+
51
+ afterAll(() => {
52
+ if (previousAgentDir === undefined) delete Bun.env.PI_CODING_AGENT_DIR;
53
+ else Bun.env.PI_CODING_AGENT_DIR = previousAgentDir;
54
+ if (previousXdg === undefined) delete Bun.env.XDG_DATA_HOME;
55
+ else Bun.env.XDG_DATA_HOME = previousXdg;
56
+ });
57
+
58
+ /** Write `<id>.jsonl` under the sessions root, with omp's own header line. */
59
+ async function writeSessionFile(id: string, entries: Array<Record<string, unknown>>): Promise<string> {
60
+ const dir = join(sessionsRoot, 'project');
61
+ await fs.promises.mkdir(dir, { recursive: true });
62
+ const path = join(dir, `${id}.jsonl`);
63
+ const lines = [
64
+ JSON.stringify({ type: 'session', id, cwd: '/work', timestamp: '2026-11-09T00:00:00.000Z' }),
65
+ ...entries.map((entry) => JSON.stringify(entry)),
66
+ ];
67
+ await Bun.write(path, `${lines.join('\n')}\n`);
68
+ clearSessionFileCaches();
69
+ return path;
70
+ }
71
+
22
72
  function registerAgent(id: string, state: Record<string, unknown>): () => void {
23
73
  let release: (() => void) | null = null;
24
74
  const session = {
@@ -57,15 +107,6 @@ function load(sessionId: string): Promise<Response> {
57
107
  } as never) as Promise<Response>;
58
108
  }
59
109
 
60
- beforeEach(async () => {
61
- delete Bun.env.MOCK;
62
- await isolateDb();
63
- });
64
-
65
- afterEach(async () => {
66
- await releaseDb();
67
- });
68
-
69
110
  describe('chat session loader on a live ACP chat', () => {
70
111
  test('reports the session model and thinking level from get_state', async () => {
71
112
  const release = registerAgent('acp-live-chat', {
@@ -82,4 +123,118 @@ describe('chat session loader on a live ACP chat', () => {
82
123
  release();
83
124
  }
84
125
  });
126
+
127
+ test('reports the selectors the LIVE session published, not a probe', async () => {
128
+ // codex refuses a probe spawn while a chat is already running, yet that chat
129
+ // offers its models — so the session's own lists are the only honest ones.
130
+ const release = registerAgent('acp-live-selectors', {
131
+ model: { provider: 'openai', id: 'gpt-5' },
132
+ thinkingLevel: 'medium',
133
+ configOptions: [
134
+ {
135
+ id: 'model',
136
+ name: 'Model',
137
+ category: 'model',
138
+ currentValue: 'gpt-5',
139
+ options: [
140
+ { value: 'gpt-5', name: 'GPT-5' },
141
+ { value: 'gpt-5-mini', name: 'GPT-5 mini' },
142
+ ],
143
+ },
144
+ {
145
+ id: 'thought_level',
146
+ name: 'Thinking',
147
+ category: 'thought_level',
148
+ currentValue: 'medium',
149
+ options: [{ value: 'medium', name: 'Medium' }],
150
+ },
151
+ ],
152
+ });
153
+ try {
154
+ const body = (await (await load('acp-live-selectors')).json()) as {
155
+ session: {
156
+ harness?: string;
157
+ liveModels?: {
158
+ models: { value: string; name: string }[];
159
+ thinking?: { value: string; name: string }[];
160
+ };
161
+ };
162
+ };
163
+ expect(body.session.harness).toBe('claude');
164
+ expect(body.session.liveModels).toEqual({
165
+ models: [
166
+ { value: 'gpt-5', name: 'GPT-5' },
167
+ { value: 'gpt-5-mini', name: 'GPT-5 mini' },
168
+ ],
169
+ thinking: [{ value: 'medium', name: 'Medium' }],
170
+ });
171
+ } finally {
172
+ release();
173
+ }
174
+ });
175
+
176
+ /**
177
+ * An ACP harness can own an on-disk transcript: omp's own ACP server writes
178
+ * the same JSONL omp RPC does. The file branch used to return without the live
179
+ * session's fields, so that tab published NO selectors — the picker for it
180
+ * could only ever list a probe snapshot instead of the list the running agent
181
+ * offers, and the composer named whatever model the file last recorded.
182
+ */
183
+ test('a live ACP chat with an on-disk transcript still publishes its own selectors', async () => {
184
+ const id = 'acp-live-on-disk';
185
+ const release = registerAgent(id, {
186
+ model: { provider: 'claude', id: 'opus' },
187
+ thinkingLevel: 'high',
188
+ configOptions: [
189
+ {
190
+ id: 'model',
191
+ name: 'Model',
192
+ category: 'model',
193
+ currentValue: 'opus',
194
+ options: [{ value: 'opus', name: 'Opus 5.5' }],
195
+ },
196
+ ],
197
+ });
198
+ try {
199
+ await writeSessionFile(id, [
200
+ { id: 'm1', parentId: null, type: 'model_change', model: 'omp/deepseek-v4.1-flash' },
201
+ { id: 'm2', parentId: 'm1', type: 'thinking_level_change', thinkingLevel: 'low' },
202
+ { id: 'm3', parentId: 'm2', type: 'message', message: { role: 'user', content: 'halo' } },
203
+ ]);
204
+
205
+ const body = (await (await load(id)).json()) as {
206
+ session: {
207
+ harness?: string;
208
+ model?: { provider: string; modelId: string };
209
+ thinkingLevel?: string;
210
+ liveModels?: { models: { value: string; name: string }[] };
211
+ };
212
+ source?: string;
213
+ };
214
+
215
+ // The file-backed branch, and the live halves still win over the file's.
216
+ expect(body.source).toBe('omp-jsonl');
217
+ expect(body.session.harness).toBe('claude');
218
+ expect(body.session.model).toEqual({ provider: 'claude', modelId: 'opus' });
219
+ expect(body.session.thinkingLevel).toBe('high');
220
+ expect(body.session.liveModels?.models).toEqual([{ value: 'opus', name: 'Opus 5.5' }]);
221
+ } finally {
222
+ release();
223
+ }
224
+ });
225
+
226
+ test('once the live session is gone the file answers for it', async () => {
227
+ const id = 'acp-dead-on-disk';
228
+ await writeSessionFile(id, [
229
+ { id: 'm1', parentId: null, type: 'model_change', model: 'claude/sonnet' },
230
+ { id: 'm2', parentId: 'm1', type: 'thinking_level_change', thinkingLevel: 'medium' },
231
+ ]);
232
+
233
+ const body = (await (await load(id)).json()) as {
234
+ session: { harness?: string; model?: { provider: string; modelId: string }; liveModels?: unknown };
235
+ };
236
+ expect(body.session.harness).toBeUndefined();
237
+ expect(body.session.liveModels).toBeUndefined();
238
+ expect(body.session.model).toEqual({ provider: 'claude', modelId: 'sonnet' });
239
+ });
85
240
  });
@@ -11,6 +11,9 @@ import { readRawHeaderLine } from '@/server/lib/omp/session/files';
11
11
  import { formatNewSessionTitle } from '@/shared/lib/omp/session/default-title';
12
12
  import { getLiveRunSessionIds, getLiveSession, harnessOfSession } from '@/server/lib/omp/rpc/session-registry';
13
13
  import { loadStreamStates } from '@/shared/lib/omp/session/stream-state.server';
14
+ import { configByCategory, selectValues } from '@/server/lib/harness/launch';
15
+ import type { AcpConfigOption } from '@/server/lib/harness/acp/protocol';
16
+ import type { LiveHarnessModels } from '@/shared/types/harness';
14
17
 
15
18
  /** Newest-message window served by default for omp JSONL sessions; the client
16
19
  * pages further back via `?before=` when the user scrolls to the top. Large
@@ -36,6 +39,33 @@ function windowMessages<T>(
36
39
  return { messages: messages.slice(start, end), total, hasMore: start > 0, oldestIndex: start };
37
40
  }
38
41
 
42
+ /** What a LIVE non-omp session adds to the session payload: its resolved model,
43
+ * its thinking level, and the selector lists it published. */
44
+ interface LiveSessionMeta {
45
+ model?: { provider: string; modelId: string };
46
+ thinkingLevel?: string;
47
+ harness?: string;
48
+ liveModels?: LiveHarnessModels;
49
+ }
50
+
51
+ /** Spread into the `session` payload so every branch states these fields once.
52
+ * `recorded` is the last run's model from `session_stream_state`, used only
53
+ * when no live session can answer. */
54
+ function liveMetaFields(
55
+ liveMeta: LiveSessionMeta | null,
56
+ recorded?: { provider: string; modelId: string },
57
+ recordedThinkingLevel?: string,
58
+ ): Record<string, unknown> {
59
+ const model = liveMeta?.model ?? recorded;
60
+ const thinkingLevel = liveMeta?.thinkingLevel ?? recordedThinkingLevel;
61
+ return {
62
+ ...(model ? { model } : {}),
63
+ ...(thinkingLevel ? { thinkingLevel } : {}),
64
+ ...(liveMeta?.harness ? { harness: liveMeta.harness } : {}),
65
+ ...(liveMeta?.liveModels?.models.length ? { liveModels: liveMeta.liveModels } : {}),
66
+ };
67
+ }
68
+
39
69
  export async function loader({ params, request }: LoaderFunctionArgs) {
40
70
  const { sessionId } = params;
41
71
  if (!sessionId) {
@@ -64,21 +94,36 @@ export async function loader({ params, request }: LoaderFunctionArgs) {
64
94
  // omp's catalog and name a model the agent never ran. The LIVE session's
65
95
  // own selector is the only honest source — and `get_state` on the ACP
66
96
  // driver is an in-process read, not a round trip to the agent.
67
- let liveMeta: { model?: { provider: string; modelId: string }; thinkingLevel?: string } | null = null;
97
+ let liveMeta: LiveSessionMeta | null = null;
68
98
  if (!mock) {
69
99
  const live = getLiveSession(sessionId);
70
100
  if (live?.isAlive() && harnessOfSession(live) !== 'omp-rpc') {
101
+ const harness = harnessOfSession(live);
71
102
  const state = (await live.send({ type: 'get_state' }).catch(() => null)) as {
72
103
  model?: { provider?: unknown; id?: unknown };
73
104
  thinkingLevel?: unknown;
105
+ configOptions?: unknown;
74
106
  } | null;
75
107
  const provider = typeof state?.model?.provider === 'string' ? state.model.provider : '';
76
108
  const modelId = typeof state?.model?.id === 'string' ? state.model.id : '';
109
+ const selectors: AcpConfigOption[] = Array.isArray(state?.configOptions)
110
+ ? (state.configOptions as AcpConfigOption[])
111
+ : [];
112
+ // The session's OWN selector lists, so the picker lists exactly what
113
+ // this agent offers — a probe is one throwaway spawn that a chat already
114
+ // running can contradict (codex refuses the probe while offering models).
115
+ const models = selectValues(configByCategory(selectors, 'model'));
116
+ const thinking = selectValues(configByCategory(selectors, 'thought_level'));
77
117
  liveMeta = {
78
118
  ...(provider && modelId ? { model: { provider, modelId } } : {}),
79
119
  ...(typeof state?.thinkingLevel === 'string' && state.thinkingLevel
80
120
  ? { thinkingLevel: state.thinkingLevel }
81
121
  : {}),
122
+ harness,
123
+ liveModels: {
124
+ models,
125
+ ...(thinking.length > 0 ? { thinking } : {}),
126
+ },
82
127
  };
83
128
  }
84
129
  }
@@ -117,13 +162,23 @@ export async function loader({ params, request }: LoaderFunctionArgs) {
117
162
  || (headerTimestamp ? formatNewSessionTitle(new Date(headerTimestamp)) : undefined)
118
163
  || `Session ${sessionId}`;
119
164
  const win = windowMessages(overlaid, limit, before);
165
+ // An ACP harness can own an on-disk transcript too — omp's own ACP server
166
+ // writes the same JSONL — and this branch used to return without the live
167
+ // session's own fields. The tab then published no selectors at all, so the
168
+ // picker for that harness could only ever list a probe snapshot instead of
169
+ // the list the RUNNING agent offers (`get_state` → `configOptions`), and
170
+ // the composer named the file's model rather than the one in force. The
171
+ // live halves win; the file answers once the session is gone.
120
172
  return json({
121
173
  session: {
122
174
  id: sessionId,
123
175
  title,
124
176
  messages: win.messages,
125
- model: await loadSessionModel(filePath),
126
- thinkingLevel: await loadSessionThinkingLevel(filePath),
177
+ ...liveMetaFields(
178
+ liveMeta,
179
+ await loadSessionModel(filePath),
180
+ await loadSessionThinkingLevel(filePath),
181
+ ),
127
182
  },
128
183
  isMock: false,
129
184
  source: 'omp-jsonl',
@@ -172,8 +227,7 @@ export async function loader({ params, request }: LoaderFunctionArgs) {
172
227
  id: existing.session_id,
173
228
  title: (hasDefaultTitle && firstUserContent ? firstUserContent.slice(0, 120) : existing.title) || `Session ${sessionId}`,
174
229
  messages: parsedMessages,
175
- ...((liveMeta?.model ?? recordedModel) ? { model: liveMeta?.model ?? recordedModel } : {}),
176
- ...(liveMeta?.thinkingLevel ? { thinkingLevel: liveMeta.thinkingLevel } : {}),
230
+ ...liveMetaFields(liveMeta, recordedModel),
177
231
  },
178
232
  isMock: mock,
179
233
  });
@@ -194,8 +248,7 @@ export async function loader({ params, request }: LoaderFunctionArgs) {
194
248
  return json({
195
249
  session: {
196
250
  ...initial,
197
- ...((liveMeta?.model ?? recordedModel) ? { model: liveMeta?.model ?? recordedModel } : {}),
198
- ...(liveMeta?.thinkingLevel ? { thinkingLevel: liveMeta.thinkingLevel } : {}),
251
+ ...liveMetaFields(liveMeta, recordedModel),
199
252
  },
200
253
  isMock: mock,
201
254
  });
@@ -198,11 +198,19 @@ describe('adding a provider to an environment harness', () => {
198
198
  }));
199
199
  const payload = await response.json() as { config?: { env: string }; envWritten?: string[]; error?: string };
200
200
  expect(payload.error).toBeUndefined();
201
- expect(payload.envWritten).toEqual(['ANTHROPIC_BASE_URL', 'ANTHROPIC_AUTH_TOKEN', 'ANTHROPIC_MODEL']);
201
+ expect(payload.envWritten).toEqual([
202
+ 'ANTHROPIC_BASE_URL',
203
+ 'ANTHROPIC_AUTH_TOKEN',
204
+ 'ANTHROPIC_MODEL',
205
+ 'ANTHROPIC_DEFAULT_SONNET_MODEL',
206
+ ]);
202
207
  // `/v1` stripped: the SDK appends `/v1/messages` itself.
203
208
  expect(payload.config?.env).toContain(`ANTHROPIC_BASE_URL=${baseUrl.replace(/\/v1$/, '')}`);
204
209
  expect(payload.config?.env).toContain('ANTHROPIC_AUTH_TOKEN=sk-claude');
205
210
  expect(payload.config?.env).toContain('ANTHROPIC_MODEL=claude-sonnet-5');
211
+ // The picker's `sonnet` alias now resolves to the id this endpoint serves;
212
+ // unpinned it would send the literal alias and answer 400.
213
+ expect(payload.config?.env).toContain('ANTHROPIC_DEFAULT_SONNET_MODEL=claude-sonnet-5');
206
214
  });
207
215
 
208
216
  test('no name is refused before anything is written', async () => {
@@ -34,7 +34,8 @@ import { loadHarnessConfig, saveHarnessConfig } from '@/server/lib/harness/confi
34
34
  import { forgetProbe } from '@/server/lib/harness/probe-cache.server';
35
35
  import { probeEndpointProtocols, type EndpointProbe } from '@/server/lib/harness/provider-probe.server';
36
36
  import { writeProvider, type ListedProvider, type ProviderDraft } from '@/server/lib/harness/provider-write.server';
37
- import { readProviderKey } from '@/server/lib/harness/provider-sources.server';
37
+ import { readProviderKey, harnessesSharingRegistry } from '@/server/lib/harness/provider-sources.server';
38
+ import { refreshModelRegistryAfterWrite } from '@/server/lib/models/registry-refresh.server';
38
39
 
39
40
  /** A provider about to be written, from any source. */
40
41
  interface Candidate extends ListedProvider {
@@ -142,13 +143,24 @@ export async function applyProvider(target: HarnessId, candidate: Candidate, sou
142
143
  try {
143
144
  const written = await writeProvider(target, draft);
144
145
  // A variable-name format (codex's `env_key`) stores ONLY the name, so the
145
- // value is saved into the harness env — where the spawn reads it — and the
146
- // probe is dropped because the env is part of what it measured.
146
+ // value is saved into the harness env — where the spawn reads it.
147
147
  let config = null;
148
148
  if (Object.keys(written.env).length > 0) {
149
149
  config = withEnvValues(await loadHarnessConfig(target), written.env);
150
150
  await saveHarnessConfig(target, config);
151
- await forgetProbe(target);
151
+ }
152
+ // WHICH harnesses read this file, not just the one the card named:
153
+ // omp-rpc and omp-acp are two transports over one models.yml, so an add
154
+ // made on either tab has to invalidate both pickers.
155
+ const sharing = harnessesSharingRegistry(written.path);
156
+ const invalidated = sharing.length > 0 ? sharing : [target];
157
+ if (sharing.includes('omp-rpc') || sharing.includes('omp-acp')) {
158
+ // The omp registry is read by the pooled RPC child AND by every ACP
159
+ // probe. Recycle the child and drop the stale probe records here; the
160
+ // browser re-probes the tabs it reads (the response names them).
161
+ await refreshModelRegistryAfterWrite({ path: written.path, probes: true, reprobe: false });
162
+ } else {
163
+ for (const id of invalidated) await forgetProbe(id);
152
164
  }
153
165
  return json({
154
166
  imported: written,
@@ -156,6 +168,7 @@ export async function applyProvider(target: HarnessId, candidate: Candidate, sou
156
168
  target: registryLabel(target),
157
169
  protocol: planned,
158
170
  probe,
171
+ probeInvalidated: invalidated,
159
172
  ...(config ? { config } : {}),
160
173
  });
161
174
  } catch (cause) {
@@ -172,6 +185,10 @@ export async function applyProvider(target: HarnessId, candidate: Candidate, sou
172
185
  baseUrl: adaptBaseUrl(draft.baseUrl ?? '', 'root'),
173
186
  apiKey: draft.apiKey ?? '',
174
187
  ...(pinnedModel(planned, draft.models) ? { model: pinnedModel(planned, draft.models)! } : {}),
188
+ // The endpoint's own listing decides what each picker alias resolves to.
189
+ // Without it Claude Code sends the literal alias as the model id and the
190
+ // gateway answers 400.
191
+ models: draft.models,
175
192
  });
176
193
  if (Object.keys(env).length === 0) {
177
194
  return json({ error: `Nothing to write: "${candidate.id}" has no endpoint or key.` }, { status: 400 });
@@ -186,6 +203,7 @@ export async function applyProvider(target: HarnessId, candidate: Candidate, sou
186
203
  protocol: planned,
187
204
  probe,
188
205
  provider: candidate.id,
206
+ probeInvalidated: [target],
189
207
  });
190
208
  }
191
209
 
@@ -132,7 +132,7 @@ describe('importing a custom provider into claude', () => {
132
132
  // even though the source declares openai-completions.
133
133
  expect(payload.protocol).toBe('anthropic-messages');
134
134
  expect(payload.envWritten).toEqual(
135
- ['ANTHROPIC_BASE_URL', 'ANTHROPIC_AUTH_TOKEN', 'ANTHROPIC_MODEL'],
135
+ ['ANTHROPIC_BASE_URL', 'ANTHROPIC_AUTH_TOKEN', 'ANTHROPIC_MODEL', 'ANTHROPIC_DEFAULT_SONNET_MODEL'],
136
136
  );
137
137
  // The stub's `/v1` is stripped: the SDK appends `/v1/messages` itself.
138
138
  expect(payload.config?.env).toContain(`ANTHROPIC_BASE_URL=${baseUrl.replace(/\/v1$/, '')}`);
@@ -1,6 +1,7 @@
1
- import { actionBindings, type HandlerBinding } from '@/server/lib/route-adapter';
1
+ import { actionBindings, bindingsFor, type HandlerBinding } from '@/server/lib/route-adapter';
2
2
  import * as harnessRoot from '@/server/routes/harness/root';
3
3
  import * as harnessUpdate from '@/server/routes/harness/update';
4
+ import * as harnessUpdateStatus from '@/server/routes/harness/update-status';
4
5
  import * as harnessVersions from '@/server/routes/harness/versions';
5
6
 
6
7
  export const harnessBindings: HandlerBinding[] = [
@@ -8,6 +9,9 @@ export const harnessBindings: HandlerBinding[] = [
8
9
  // Static paths registered as their own routes. A `/api/harness/:id` parameter
9
10
  // route sharing this position is the shape that makes the parameter win the
10
11
  // match and hide the real handler behind a 405.
12
+ // The update's BACKGROUND progress is its own GET: `/api/harness/update` keeps
13
+ // answering the version rows for compatibility.
14
+ ...bindingsFor(harnessUpdateStatus, '/api/harness/update/status'),
11
15
  ...actionBindings(harnessUpdate.action, '/api/harness/update', harnessVersions.loader),
12
16
  ...actionBindings(harnessRoot.action, '/api/harness/versions', harnessVersions.loader),
13
17
  ];
@@ -19,12 +19,13 @@ import { json } from '@/server/lib/remix-compat';
19
19
  import type { ActionFunctionArgs, LoaderFunctionArgs } from '@/server/lib/remix-compat';
20
20
  import { methodNotAllowed } from '@/server/lib/route-adapter';
21
21
  import { HARNESS_IDS, harnessDescriptor, type HarnessId } from '@/shared/lib/harness/catalog';
22
- import { HARNESS_LAUNCH, blockedProbe, probeHarness } from '@/server/lib/harness/launch';
22
+ import { HARNESS_LAUNCH } from '@/server/lib/harness/launch-table';
23
23
  import type { HarnessProbe } from '@/server/lib/harness/capabilities';
24
24
  import { forgetProbe, loadProbes, rememberProbe } from '@/server/lib/harness/probe-cache.server';
25
25
  import { loadDisabledHarnesses, saveHarnessEnabled } from '@/server/lib/harness/enabled.server';
26
26
  import { harnessEnabled } from '@/shared/lib/harness/enabled';
27
- import { launchFromConfig, loadHarnessConfig, probeInvalidatedBy, resolveLaunch, saveHarnessConfig } from '@/server/lib/harness/config.server';
27
+ import { commandAvailable, probeWithConfig } from '@/server/lib/harness/auto-probe.server';
28
+ import { loadHarnessConfig, probeInvalidatedBy, saveHarnessConfig } from '@/server/lib/harness/config.server';
28
29
  import { importableProvidersFor, readRegistryProviders } from '@/server/lib/harness/provider-sources.server';
29
30
  import { addProviderAction, importProviderAction, importSourceOf, isImportBody } from '@/server/routes/harness/import-action';
30
31
  import { supportedProtocols } from '@/shared/lib/harness/dialects';
@@ -36,7 +37,6 @@ import {
36
37
  import { providerFacts } from '@/shared/lib/harness/provider-facts';
37
38
  import type { HarnessProviderSupport } from '@/shared/types/harness';
38
39
  import { parseHarnessConfig, type HarnessConfig } from '@/shared/lib/harness/config';
39
- import { resolveOmpBin } from '@/server/lib/omp/core/cli';
40
40
 
41
41
  /**
42
42
  * The probe cache lives in `probe-cache.server.ts`: the SPAWN reads it too, to
@@ -61,33 +61,6 @@ export interface HarnessSummary {
61
61
  unavailable?: string;
62
62
  }
63
63
 
64
- /**
65
- * Is a launch command first-token resolvable? The omp binary has its own
66
- * resolver (KABMO_OMP_BIN, then PATH) and is never "missing" through PATH alone.
67
- *
68
- * The USER's command override decides this, not the build's table: a harness
69
- * whose binary lives behind a wrapper, a container (`docker run … agy acp`) or an
70
- * absolute path read as "not installed" and could not even be switched on, while
71
- * a spawn of that same configured command worked.
72
- */
73
- function commandAvailable(id: HarnessId, config?: HarnessConfig): boolean {
74
- if (id === 'omp-acp') return Boolean(resolveOmpBin());
75
- let command = HARNESS_LAUNCH[id]?.command;
76
- if (config) {
77
- try {
78
- const configured = launchFromConfig(id, config);
79
- if (configured?.command.length) command = configured.command;
80
- } catch {
81
- // An unusable env line is reported by the probe; availability falls back
82
- // to the build's table rather than claiming "not installed".
83
- }
84
- }
85
- const [binary] = command ?? [];
86
- if (!binary) return false;
87
- if (binary === 'npx') return Boolean(Bun.which('npx') ?? Bun.which('node'));
88
- return Boolean(Bun.which(binary));
89
- }
90
-
91
64
  export async function listHarnesses(): Promise<HarnessSummary[]> {
92
65
  // ONE read for the whole catalog, from disk when memory is cold: the probe
93
66
  // cache used to be process-only, so every restart — every `bun --hot` reload —
@@ -121,29 +94,15 @@ export async function listHarnesses(): Promise<HarnessSummary[]> {
121
94
  ...(launch?.install ? { install: launch.install } : {}),
122
95
  ...(launch?.note ? { note: launch.note } : {}),
123
96
  probe: fresh,
124
- ...(available ? {} : { unavailable: `\`${launch?.command[0] ?? id}\` is not installed` }),
97
+ ...(available ? {} : {
98
+ unavailable: launch?.requires
99
+ ? `${launch.requires.label} is not installed`
100
+ : `\`${launch?.command[0] ?? id}\` is not installed`,
101
+ }),
125
102
  };
126
103
  });
127
104
  }
128
105
 
129
- /**
130
- * Probe a harness the way a SPAWN would launch it: the user's command and env
131
- * override are part of what is being measured.
132
- *
133
- * Without this, a harness that only works with its configured env — `CODEX_HOME`,
134
- * a provider base URL, a wrapper that logs in — probed as "Authentication
135
- * required" in Settings while its chats ran fine. A launch line that cannot even
136
- * be resolved (an invalid env line) answers a `blocked` record instead of a 500.
137
- */
138
- async function probeWithConfig(id: HarnessId, cwd: string): Promise<HarnessProbe> {
139
- try {
140
- const configured = await loadHarnessConfig(id);
141
- return await probeHarness(id, cwd, resolveLaunch(id, configured));
142
- } catch (cause) {
143
- return blockedProbe(id, cause instanceof Error ? cause.message : String(cause));
144
- }
145
- }
146
-
147
106
  export async function loader({ request }: LoaderFunctionArgs) {
148
107
  const url = new URL(request.url);
149
108
  const target = url.searchParams.get('probe');
@@ -20,6 +20,9 @@
20
20
  */
21
21
 
22
22
  import { afterAll, afterEach, beforeEach, describe, expect, test } from 'bun:test';
23
+ import { mkdtempSync, rmSync } from 'node:fs';
24
+ import { tmpdir } from 'node:os';
25
+ import { join } from 'node:path';
23
26
  import { isolateDb, releaseDb } from '@/test-support/isolated-db';
24
27
  import { probes } from '@/server/lib/harness/probe-cache.server';
25
28
  import { loadDisabledHarnesses } from '@/server/lib/harness/enabled.server';
@@ -39,7 +42,21 @@ function toggle(id: string, enabled: boolean): Request {
39
42
  });
40
43
  }
41
44
 
45
+ /**
46
+ * The probe below is REAL: when `omp` is installed, enabling `omp-acp` spawns
47
+ * `omp acp`, and that child writes a session file into the agent directory it
48
+ * resolves — `~/.omp/agent/sessions/-projects-kabmo/` when this suite runs from
49
+ * the repo. The file has no title, so Kabmo's sidebar draws it as
50
+ * `New Session - <timestamp>`: every `bun test` left one more row behind in the
51
+ * developer's own install (observed at 11:47 and 11:50, matching this suite's
52
+ * `acp` spawns in the process table). Point the child's agent dir at a throwaway
53
+ * tree so the probe still measures the real binary without touching real state.
54
+ */
55
+ const AGENT_DIR = mkdtempSync(join(tmpdir(), 'kabmo-toggle-agent-'));
56
+ const savedAgentDir = Bun.env.PI_CODING_AGENT_DIR;
57
+
42
58
  beforeEach(async () => {
59
+ Bun.env.PI_CODING_AGENT_DIR = AGENT_DIR;
43
60
  await isolateDb();
44
61
  probes().clear();
45
62
  });
@@ -51,6 +68,9 @@ afterEach(async () => {
51
68
 
52
69
  afterAll(async () => {
53
70
  await releaseDb();
71
+ if (savedAgentDir === undefined) delete Bun.env.PI_CODING_AGENT_DIR;
72
+ else Bun.env.PI_CODING_AGENT_DIR = savedAgentDir;
73
+ rmSync(AGENT_DIR, { recursive: true, force: true });
54
74
  });
55
75
 
56
76
  describe('switching a harness on', () => {
@@ -0,0 +1,26 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * `GET /api/harness/update/status` — the background update the POST started.
8
+ *
9
+ * The POST answers `202` in milliseconds and the install keeps running in a
10
+ * detached worker, so this is how the dialog learns where it is and whether it
11
+ * finished. A poll is also where the SERVER applies the post-install side
12
+ * effects (`finalizeUpdateJob`): the caches and the launch line live in this
13
+ * process, not in the worker.
14
+ *
15
+ * `null` is a real answer — no update has ever run — and it must not be a 404:
16
+ * the About card asks this on every open, and a "not found" would read as a
17
+ * broken route rather than "nothing is running".
18
+ */
19
+
20
+ import { json, NO_STORE_HEADERS } from '@/server/lib/remix-compat';
21
+ import { finalizeUpdateJob } from '@/server/lib/harness/update-job.server';
22
+
23
+ export async function loader() {
24
+ const job = await finalizeUpdateJob();
25
+ return json({ job }, { headers: NO_STORE_HEADERS });
26
+ }