@kabmo-labs/kabmo 0.24.0 → 0.26.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (325) hide show
  1. package/dist/client/index.html +1 -1
  2. package/dist/client/index.js +585 -512
  3. package/dist/client/static/js/{index-jcr5twtp.js → index-95b3n20k.js} +1105 -1207
  4. package/dist/client/static/js/index-p2yw9ywf.css +1 -0
  5. package/package.json +2 -4
  6. package/src/cli/lib/args.js +24 -1
  7. package/src/cli/lib/args.test.js +16 -0
  8. package/src/cli/lib/commands/session.js +233 -0
  9. package/src/cli/lib/commands/session.test.js +103 -0
  10. package/src/cli/main.js +1 -1
  11. package/src/client/components/common/ComposerPicker.tsx +3 -0
  12. package/src/client/components/common/code-surface/shiki.test.ts +82 -0
  13. package/src/client/components/common/code-surface/shiki.ts +28 -7
  14. package/src/client/components/common/session-actions-menu/index.tsx +59 -2
  15. package/src/client/components/common/session-branch/BranchGuides.tsx +93 -0
  16. package/src/client/components/common/session-branch/SubagentRow.tsx +77 -0
  17. package/src/client/components/common/session-branch/index.tsx +169 -0
  18. package/src/client/components/common/session-branch/session-branch.test.tsx +240 -0
  19. package/src/client/components/common/session-branch/style.ts +29 -0
  20. package/src/client/components/common/session-row/StatusSlot.tsx +17 -5
  21. package/src/client/components/common/session-row/index.tsx +28 -3
  22. package/src/client/components/common/session-row/session-row.test.tsx +11 -0
  23. package/src/client/components/common/session-state-provider/index.tsx +1 -1
  24. package/src/client/components/layout/desktop-layout/resizer/separator-drag.ts +3 -3
  25. package/src/client/components/layout/session-sidebar/CategoryItem.tsx +70 -61
  26. package/src/client/components/layout/session-sidebar/SessionItem.batch.test.ts +3 -3
  27. package/src/client/components/layout/session-sidebar/SessionItem.test.ts +25 -2
  28. package/src/client/components/layout/session-sidebar/SessionItem.tsx +35 -7
  29. package/src/client/components/layout/session-sidebar/about-modal/HarnessRow.tsx +261 -0
  30. package/src/client/components/layout/session-sidebar/about-modal/HarnessTable.tsx +39 -198
  31. package/src/client/components/layout/session-sidebar/about-modal/HarnessTableLog.test.tsx +114 -0
  32. package/src/client/components/layout/session-sidebar/about-modal/UpdateLogDialog.test.tsx +130 -0
  33. package/src/client/components/layout/session-sidebar/about-modal/UpdateLogDialog.tsx +128 -0
  34. package/src/client/components/layout/session-sidebar/about-modal/UpdateLogLine.tsx +56 -0
  35. package/src/client/components/layout/session-sidebar/about-modal/index.tsx +44 -36
  36. package/src/client/components/layout/session-sidebar/modern/WorkspaceSection.tsx +62 -47
  37. package/src/client/components/mobile/mobile-session-sidebar/Item.tsx +63 -50
  38. package/src/client/components/mobile/mobile-session-sidebar/SessionRow.test.ts +5 -0
  39. package/src/client/components/mobile/mobile-session-sidebar/SessionRow.tsx +37 -12
  40. package/src/client/components/settings/Sidebar.tsx +1 -1
  41. package/src/client/components/settings/categories/NotificationSettings.test.tsx +92 -0
  42. package/src/client/components/settings/categories/NotificationSettings.tsx +112 -2
  43. package/src/client/components/settings/categories/harness-settings/HarnessCard.tsx +1 -1
  44. package/src/client/components/workspace/chat-timeline/AiMessageFooter.fork.test.ts +94 -0
  45. package/src/client/components/workspace/chat-timeline/AiMessageFooter.tsx +31 -5
  46. package/src/client/components/workspace/chat-timeline/ComposerDock.tsx +64 -70
  47. package/src/client/components/workspace/chat-timeline/ComposerDockFrame.tsx +35 -0
  48. package/src/client/components/workspace/chat-timeline/EmptyWorkspacePrompt.tsx +128 -122
  49. package/src/client/components/workspace/chat-timeline/MessageItem.tsx +22 -1
  50. package/src/client/components/workspace/chat-timeline/MessageList.tsx +11 -5
  51. package/src/client/components/workspace/chat-timeline/PendingChatView.tsx +10 -0
  52. package/src/client/components/workspace/chat-timeline/RunFooter.tsx +12 -3
  53. package/src/client/components/workspace/chat-timeline/TimelineBody.tsx +3 -0
  54. package/src/client/components/workspace/chat-timeline/chat-input/AttachmentToolbar.tsx +2 -0
  55. package/src/client/components/workspace/chat-timeline/chat-input/ModeToggles.tsx +15 -1
  56. package/src/client/components/workspace/chat-timeline/chat-input/SessionModeDropdown.test.tsx +85 -0
  57. package/src/client/components/workspace/chat-timeline/chat-input/SessionModeDropdown.tsx +84 -0
  58. package/src/client/components/workspace/chat-timeline/chat-input/Toolbar.tsx +2 -0
  59. package/src/client/components/workspace/chat-timeline/chat-input/modes-props.ts +5 -0
  60. package/src/client/components/workspace/chat-timeline/composer-dock-frame.test.tsx +155 -0
  61. package/src/client/components/workspace/chat-timeline/index.tsx +11 -20
  62. package/src/client/components/workspace/chat-timeline/target-picker/DraftTargetRow.tsx +115 -0
  63. package/src/client/components/workspace/chat-timeline/target-picker/ParentSessionPicker.tsx +173 -0
  64. package/src/client/components/workspace/chat-timeline/target-picker/parent-session-options.test.ts +49 -0
  65. package/src/client/components/workspace/terminal-panel/KeyBar.tsx +10 -8
  66. package/src/client/components/workspace/terminal-panel/{RealtimeXtermView.tsx → RealtimeTerminalView.tsx} +51 -58
  67. package/src/client/components/workspace/terminal-panel/fit.test.ts +37 -0
  68. package/src/client/components/workspace/terminal-panel/fit.ts +64 -0
  69. package/src/client/components/workspace/terminal-panel/fonts.test.ts +161 -0
  70. package/src/client/components/workspace/terminal-panel/fonts.ts +164 -0
  71. package/src/client/components/workspace/terminal-panel/grid.test.ts +52 -0
  72. package/src/client/components/workspace/terminal-panel/grid.ts +118 -0
  73. package/src/client/components/workspace/terminal-panel/index.tsx +25 -21
  74. package/src/client/components/workspace/terminal-panel/mount.ts +247 -223
  75. package/src/client/components/workspace/terminal-panel/navigation.test.ts +54 -0
  76. package/src/client/components/workspace/terminal-panel/navigation.ts +47 -0
  77. package/src/client/data/settings/omp-schema.json +1 -1
  78. package/src/client/data/theme/terminal.test.ts +25 -0
  79. package/src/client/data/theme/terminal.ts +96 -79
  80. package/src/client/hooks/chat/composer/items.test.ts +31 -26
  81. package/src/client/hooks/chat/composer/pick-mapping.test.ts +42 -0
  82. package/src/client/hooks/chat/omp/folder-auto-expand.ts +1 -1
  83. package/src/client/hooks/chat/omp/pending-adoption.ts +51 -0
  84. package/src/client/hooks/chat/omp/pending-child.test.ts +73 -0
  85. package/src/client/hooks/chat/omp/pending-entry.ts +59 -0
  86. package/src/client/hooks/chat/omp/pending-rows.ts +6 -2
  87. package/src/client/hooks/chat/omp/pending-sessions.test.ts +1 -2
  88. package/src/client/hooks/chat/omp/pending-sessions.ts +45 -69
  89. package/src/client/hooks/chat/omp/pending-waiting.ts +1 -1
  90. package/src/client/hooks/chat/omp/prompt-send.test.ts +7 -7
  91. package/src/client/hooks/chat/omp/prompt-send.ts +26 -14
  92. package/src/client/hooks/chat/omp/run-switch.ts +1 -1
  93. package/src/client/hooks/chat/omp/session-list.tsx +4 -0
  94. package/src/client/hooks/chat/subagents/roster.ts +122 -0
  95. package/src/client/hooks/chat/timeline/child-spawn.test.ts +55 -0
  96. package/src/client/hooks/chat/timeline/child-spawn.ts +45 -0
  97. package/src/client/hooks/chat/timeline/fork-request.test.ts +54 -0
  98. package/src/client/hooks/chat/timeline/fork-request.ts +43 -0
  99. package/src/client/hooks/chat/timeline/mode-availability.test.ts +1 -1
  100. package/src/client/hooks/chat/timeline/mode-availability.ts +33 -0
  101. package/src/client/hooks/chat/timeline/mode-markers.ts +7 -1
  102. package/src/client/hooks/chat/timeline/mode-post.ts +15 -3
  103. package/src/client/hooks/chat/timeline/modes-contract.ts +9 -4
  104. package/src/client/hooks/chat/timeline/modes.test.ts +56 -18
  105. package/src/client/hooks/chat/timeline/modes.ts +42 -29
  106. package/src/client/hooks/chat/timeline/pending-branch.ts +205 -0
  107. package/src/client/hooks/chat/timeline/pending-dispatch.ts +253 -0
  108. package/src/client/hooks/chat/timeline/prompt-text.test.ts +34 -1
  109. package/src/client/hooks/chat/timeline/prompt-text.ts +47 -20
  110. package/src/client/hooks/chat/timeline/send-execute.test.ts +39 -0
  111. package/src/client/hooks/chat/timeline/send-helpers.ts +30 -1
  112. package/src/client/hooks/chat/timeline/send-steer.test.ts +3 -1
  113. package/src/client/hooks/chat/timeline/send.test-util.ts +7 -1
  114. package/src/client/hooks/chat/timeline/send.test.ts +3 -1
  115. package/src/client/hooks/chat/timeline/send.ts +48 -133
  116. package/src/client/hooks/chat/timeline/session-harness.ts +6 -0
  117. package/src/client/hooks/chat/timeline/stop-with-queue.ts +42 -0
  118. package/src/client/hooks/chat/timeline/use-fork-session.ts +58 -0
  119. package/src/client/hooks/models/use-harness-update.test.ts +286 -0
  120. package/src/client/hooks/models/use-harness-update.ts +250 -0
  121. package/src/client/hooks/ui/input-required-alert.ts +12 -5
  122. package/src/client/hooks/ui/notifications.ts +45 -0
  123. package/src/client/hooks/ui/run-outcome-alert.ts +48 -0
  124. package/src/client/hooks/workspace/expanded-sessions.ts +36 -7
  125. package/src/client/hooks/workspace/terminal/index.ts +17 -3
  126. package/src/client/hooks/workspace/terminal/socket.ts +9 -4
  127. package/src/client/lib/native/open-session.ts +33 -0
  128. package/src/client/lib/notifications/os.test.ts +125 -0
  129. package/src/client/lib/notifications/os.ts +130 -0
  130. package/src/client/lib/plugins/sidebar-bridge.ts +2 -20
  131. package/src/client/lib/router/open-session.test.ts +75 -0
  132. package/src/client/lib/router/open-session.ts +34 -0
  133. package/src/client/lib/session-tree.test.ts +50 -0
  134. package/src/client/lib/session-tree.ts +59 -0
  135. package/src/client/lib/signals.ts +5 -1
  136. package/src/client/main.tsx +6 -0
  137. package/src/client/tailwind.css +17 -11
  138. package/src/server/index.ts +2 -0
  139. package/src/server/lib/auth/guard.ts +10 -0
  140. package/src/server/lib/btw/session-copy.server.ts +6 -44
  141. package/src/server/lib/btw/session-copy.test.ts +2 -1
  142. package/src/server/lib/db/schema.ts +5 -0
  143. package/src/server/lib/db/seed-terminal.test.ts +1 -1
  144. package/src/server/lib/db/seed.test.ts +1 -1
  145. package/src/server/lib/harness/acp/background-work.test.ts +262 -0
  146. package/src/server/lib/harness/acp/background-work.ts +320 -0
  147. package/src/server/lib/harness/acp/calls.ts +15 -1
  148. package/src/server/lib/harness/acp/client-capabilities.test.ts +55 -0
  149. package/src/server/lib/harness/acp/client-capabilities.ts +61 -0
  150. package/src/server/lib/harness/acp/client-fs.test.ts +135 -0
  151. package/src/server/lib/harness/acp/client-fs.ts +131 -0
  152. package/src/server/lib/harness/acp/client-initialize.test.ts +70 -0
  153. package/src/server/lib/harness/acp/client-initialize.ts +84 -0
  154. package/src/server/lib/harness/acp/client.ts +33 -23
  155. package/src/server/lib/harness/acp/commands.test.ts +5 -5
  156. package/src/server/lib/harness/acp/commands.ts +14 -2
  157. package/src/server/lib/harness/acp/frames-timing.test.ts +68 -0
  158. package/src/server/lib/harness/acp/frames-v2.test.ts +85 -0
  159. package/src/server/lib/harness/acp/frames.ts +71 -158
  160. package/src/server/lib/harness/acp/gateway-env.test.ts +64 -0
  161. package/src/server/lib/harness/acp/gateway-env.ts +70 -0
  162. package/src/server/lib/harness/acp/mapper.test.ts +40 -0
  163. package/src/server/lib/harness/acp/mapper.ts +12 -0
  164. package/src/server/lib/harness/acp/permissions.ts +6 -0
  165. package/src/server/lib/harness/acp/prompt.test.ts +20 -0
  166. package/src/server/lib/harness/acp/prompt.ts +19 -3
  167. package/src/server/lib/harness/acp/protocol.ts +41 -2
  168. package/src/server/lib/harness/acp/session-background.test.ts +129 -0
  169. package/src/server/lib/harness/acp/session-exit.ts +31 -0
  170. package/src/server/lib/harness/acp/session-facts.ts +1 -1
  171. package/src/server/lib/harness/acp/session-handshake.test.ts +197 -0
  172. package/src/server/lib/harness/acp/session-handshake.ts +110 -7
  173. package/src/server/lib/harness/acp/session-idle.ts +7 -6
  174. package/src/server/lib/harness/acp/session-listeners.ts +31 -0
  175. package/src/server/lib/harness/acp/session-notifications.ts +41 -2
  176. package/src/server/lib/harness/acp/session-observers.test.ts +63 -0
  177. package/src/server/lib/harness/acp/session-permissions.test.ts +29 -0
  178. package/src/server/lib/harness/acp/session-permissions.ts +36 -0
  179. package/src/server/lib/harness/acp/session-requests.test.ts +92 -0
  180. package/src/server/lib/harness/acp/session-requests.ts +89 -0
  181. package/src/server/lib/harness/acp/session-turns.ts +28 -8
  182. package/src/server/lib/harness/acp/session-usage.ts +4 -0
  183. package/src/server/lib/harness/acp/session-web-state.ts +30 -2
  184. package/src/server/lib/harness/acp/session.test-util.ts +42 -2
  185. package/src/server/lib/harness/acp/session.ts +115 -115
  186. package/src/server/lib/harness/acp/tool-calls.ts +223 -0
  187. package/src/server/lib/harness/acp/turn.test.ts +183 -0
  188. package/src/server/lib/harness/acp/turn.ts +102 -10
  189. package/src/server/lib/harness/acp/v2.test.ts +144 -0
  190. package/src/server/lib/harness/acp/v2.ts +220 -0
  191. package/src/server/lib/harness/acp/verbs.ts +58 -8
  192. package/src/server/lib/harness/launch.test.ts +25 -0
  193. package/src/server/lib/harness/launch.ts +24 -10
  194. package/src/server/lib/harness/session.ts +3 -0
  195. package/src/server/lib/harness/spawn.server.ts +15 -2
  196. package/src/server/lib/harness/update-job-store.test.ts +151 -0
  197. package/src/server/lib/harness/update-job-store.ts +115 -0
  198. package/src/server/lib/harness/update-job.server.ts +94 -0
  199. package/src/server/lib/harness/update-queue.server.ts +292 -0
  200. package/src/server/lib/harness/update-queue.test.ts +265 -0
  201. package/src/server/lib/harness/update-spawn.server.ts +96 -0
  202. package/src/server/lib/harness/update-worker.test.ts +153 -0
  203. package/src/server/lib/harness/update-worker.ts +202 -0
  204. package/src/server/lib/lifecycle/after-listen.ts +9 -0
  205. package/src/server/lib/lifecycle/paths.ts +28 -0
  206. package/src/server/lib/omp/rpc/manager.ts +5 -5
  207. package/src/server/lib/omp/rpc/prewarm-pool.ts +12 -3
  208. package/src/server/lib/omp/rpc/run-settle.server.ts +10 -1
  209. package/src/server/lib/omp/rpc/session-registry.ts +14 -2
  210. package/src/server/lib/omp/rpc/subagent-liveness.ts +5 -5
  211. package/src/server/lib/omp/rpc/terminal-settle.ts +58 -6
  212. package/src/server/lib/omp/session/delete-flow.server.ts +48 -0
  213. package/src/server/lib/omp/session/delete.server.ts +5 -0
  214. package/src/server/lib/omp/session/rewind-file.ts +39 -21
  215. package/src/server/lib/omp/session/sidebar-data.server.ts +16 -18
  216. package/src/server/lib/omp/session/transcript-copy.ts +123 -0
  217. package/src/server/lib/sessions/agent-token.server.test.ts +64 -0
  218. package/src/server/lib/sessions/agent-token.server.ts +134 -0
  219. package/src/server/lib/sessions/answers.server.test.ts +33 -0
  220. package/src/server/lib/sessions/answers.server.ts +37 -0
  221. package/src/server/lib/sessions/dispatch.server.test.ts +143 -0
  222. package/src/server/lib/sessions/dispatch.server.ts +128 -0
  223. package/src/server/lib/sessions/fork.server.test.ts +277 -0
  224. package/src/server/lib/sessions/fork.server.ts +329 -0
  225. package/src/server/lib/sessions/lifecycle.server.test.ts +75 -0
  226. package/src/server/lib/sessions/lifecycle.server.ts +71 -0
  227. package/src/server/lib/sessions/notify.server.test.ts +112 -0
  228. package/src/server/lib/sessions/notify.server.ts +212 -0
  229. package/src/server/lib/sessions/relation-types.ts +76 -0
  230. package/src/server/lib/sessions/relations.server.test.ts +207 -0
  231. package/src/server/lib/sessions/relations.server.ts +337 -0
  232. package/src/server/lib/sessions/resolve.server.ts +106 -0
  233. package/src/server/lib/sessions/schema.server.ts +82 -0
  234. package/src/server/lib/sessions/sidebar-relations.server.test.ts +61 -0
  235. package/src/server/lib/sessions/sidebar-relations.server.ts +47 -0
  236. package/src/server/lib/sessions/spawn.server.test.ts +237 -0
  237. package/src/server/lib/sessions/spawn.server.ts +335 -0
  238. package/src/server/lib/terminal/attach-replay.test.ts +2 -2
  239. package/src/server/lib/terminal/output.test.ts +2 -2
  240. package/src/server/lib/terminal/output.ts +1 -1
  241. package/src/server/lib/terminal/resize.test.ts +99 -0
  242. package/src/server/lib/terminal/runtime.server.ts +26 -6
  243. package/src/server/lib/terminal/send-result.test.ts +18 -1
  244. package/src/server/lib/terminal/send-result.ts +26 -2
  245. package/src/server/lib/terminal/session.server.ts +6 -6
  246. package/src/server/lib/usage/new-api.test.ts +92 -0
  247. package/src/server/lib/usage/new-api.ts +131 -0
  248. package/src/server/lib/usage/provider-endpoint.test.ts +106 -0
  249. package/src/server/lib/usage/provider-key.ts +33 -0
  250. package/src/server/lib/usage/providers.server.ts +10 -3
  251. package/src/server/lib/usage/vendor-balance.server.ts +4 -53
  252. package/src/server/lib/usage/vendor-http.ts +41 -0
  253. package/src/server/lib/usage/window.ts +55 -0
  254. package/src/server/routes/agent/command.ts +14 -1
  255. package/src/server/routes/agent/harness-command.ts +12 -5
  256. package/src/server/routes/agent/new.ts +15 -0
  257. package/src/server/routes/chat/stream.ts +7 -2
  258. package/src/server/routes/harness/add-provider.test.ts +9 -1
  259. package/src/server/routes/harness/import-action.ts +4 -0
  260. package/src/server/routes/harness/import.test.ts +1 -1
  261. package/src/server/routes/harness/index.ts +5 -1
  262. package/src/server/routes/harness/update-status.ts +32 -0
  263. package/src/server/routes/harness/update.test.ts +156 -0
  264. package/src/server/routes/harness/update.ts +64 -147
  265. package/src/server/routes/sessions/answer.ts +24 -0
  266. package/src/server/routes/sessions/batch-delete.ts +11 -5
  267. package/src/server/routes/sessions/body-readers.ts +43 -0
  268. package/src/server/routes/sessions/delete.ts +4 -2
  269. package/src/server/routes/sessions/fork.ts +89 -0
  270. package/src/server/routes/sessions/index.ts +14 -0
  271. package/src/server/routes/sessions/relations.ts +85 -0
  272. package/src/server/routes/sessions/routes.test.ts +1 -2
  273. package/src/server/routes/sessions/session.ts +23 -0
  274. package/src/server/routes/sessions/spawn.ts +137 -0
  275. package/src/server/routes/terminal/ws.ts +3 -3
  276. package/src/shared/lib/chat/composer/client.ts +31 -2
  277. package/src/shared/lib/chat/composer/delegation.test.ts +93 -0
  278. package/src/shared/lib/chat/composer/delegation.ts +206 -0
  279. package/src/shared/lib/chat/notice-text.ts +1 -1
  280. package/src/shared/lib/chat/omp/agent-events.ts +11 -0
  281. package/src/shared/lib/chat/omp/session-modes-signal.test.ts +41 -0
  282. package/src/shared/lib/chat/tool/summary-wait.test.ts +11 -0
  283. package/src/shared/lib/code/ansi.ts +1 -1
  284. package/src/shared/lib/fonts/nerd-symbols.css +4 -3
  285. package/src/shared/lib/fonts/nerd-symbols.test.ts +9 -9
  286. package/src/shared/lib/harness/mode-signal.ts +20 -0
  287. package/src/shared/lib/harness/provider-facts.test.ts +27 -0
  288. package/src/shared/lib/harness/providers.ts +35 -1
  289. package/src/shared/lib/harness/session-modes.ts +24 -0
  290. package/src/shared/lib/harness/update-job.ts +80 -0
  291. package/src/shared/lib/harness/update-plan.test.ts +21 -6
  292. package/src/shared/lib/harness/update-plan.ts +12 -4
  293. package/src/shared/lib/icons/tint-hues.generated.ts +34 -34
  294. package/src/shared/lib/notifications/outcomes.test.ts +96 -0
  295. package/src/shared/lib/notifications/outcomes.ts +64 -0
  296. package/src/shared/lib/notifications/settings.test.ts +49 -0
  297. package/src/shared/lib/notifications/settings.ts +34 -0
  298. package/src/shared/lib/omp/session/default-title.ts +5 -4
  299. package/src/shared/lib/omp/session/prewarm-misc.test.ts +3 -2
  300. package/src/shared/lib/omp/session/schema-migrations.ts +4 -0
  301. package/src/shared/lib/omp/session/stream-state.server.test.ts +19 -0
  302. package/src/shared/lib/omp/session/stream-state.server.ts +24 -4
  303. package/src/shared/lib/omp/session/wait-idle.test.ts +11 -0
  304. package/src/shared/lib/omp/session/wait-idle.ts +12 -2
  305. package/src/shared/lib/settings/defaults.ts +3 -0
  306. package/src/shared/lib/theme/catalog.test.ts +13 -9
  307. package/src/shared/lib/theme/color.test.ts +2 -2
  308. package/src/shared/lib/theme/color.ts +4 -4
  309. package/src/shared/lib/theme/theme.test.ts +1 -1
  310. package/src/shared/lib/workspace/terminal/input.test.ts +27 -0
  311. package/src/shared/lib/workspace/terminal/input.ts +33 -0
  312. package/src/shared/lib/workspace/terminal/keys.test.ts +1 -1
  313. package/src/shared/lib/workspace/terminal/keys.ts +7 -7
  314. package/src/shared/types/chat.ts +1 -1
  315. package/src/shared/types/harness-update.ts +89 -0
  316. package/src/shared/types/omp/agent.ts +19 -2
  317. package/src/shared/types/realtime.ts +2 -0
  318. package/src/shared/types/settings/state.ts +10 -0
  319. package/src/shared/types/workspace.ts +8 -0
  320. package/src/test-support/fake-omp-fork.ts +16 -2
  321. package/src/test-support/harness-table.test-util.ts +31 -1
  322. package/dist/client/static/js/index-z3w7n85q.css +0 -1
  323. package/src/client/components/common/subagent-list/index.tsx +0 -165
  324. package/src/client/components/workspace/terminal-panel/webgl.test.ts +0 -75
  325. package/src/client/components/workspace/terminal-panel/webgl.ts +0 -108
@@ -33,55 +33,42 @@
33
33
  */
34
34
 
35
35
  import type { AgentEvent } from '@/server/lib/omp/rpc/constants';
36
- import {
37
- acpContentDetails,
38
- acpContentText,
39
- acpToolDetails,
40
- acpToolOutput,
41
- acpToolTarget,
42
- isKnownToolName,
43
- toolTypeFor,
44
- } from '@/server/lib/harness/acp/mapper';
45
- import type { AcpToolKind, AcpToolStatus } from '@/server/lib/harness/acp/protocol';
36
+ import { acpContentText } from '@/server/lib/harness/acp/mapper';
37
+ import { planEntries } from '@/server/lib/harness/acp/v2';
38
+ import { AcpToolCalls, type ToolCallBlock } from '@/server/lib/harness/acp/tool-calls';
46
39
 
47
40
  /** One block of the accumulated assistant message, in `parseMessageBlocks` shape. */
48
41
  type MessageBlock =
49
42
  | { type: 'text'; text: string }
50
43
  | { type: 'thinking'; thinking: string }
51
- | { type: 'toolCall'; id: string; name: string; arguments?: Record<string, unknown>; toolKind?: AcpToolKind; toolType?: string };
52
-
53
- interface OpenTool {
54
- id: string;
55
- name: string;
56
- kind?: AcpToolKind;
57
- title?: string;
58
- status: AcpToolStatus;
59
- rawOutput?: unknown;
60
- /** `tool_call(Update).content` — where some agents put the diff/output. */
61
- content?: unknown;
62
- locations?: unknown;
63
- startedAt: number;
64
- }
44
+ | ToolCallBlock;
65
45
 
66
46
  /** Per-session accumulator; one instance per live ACP session. */
67
47
  export class AcpFrameMapper {
68
48
  private blocks: MessageBlock[] = [];
69
49
  private messageId: string | null = null;
70
- private readonly open = new Map<string, OpenTool>();
50
+ /** When the turn was dispatched, the base for its duration. */
51
+ private turnStartedAt: number | null = null;
52
+ /** When the open message's first frame arrived, its timeline stamp. */
53
+ private openedAt: number | null = null;
54
+ private readonly tools = new AcpToolCalls({
55
+ pushBlock: (block) => this.blocks.push(block),
56
+ snapshot: () => this.snapshot(),
57
+ });
71
58
 
72
- /** Forget per-turn state (an aborted run, a fresh load). */
73
- reset(): void {
59
+ /** Forget per-turn state (an aborted run, a fresh load) and start its clock. */
60
+ reset(startedAt: number = Date.now()): void {
74
61
  this.blocks = [];
75
62
  this.messageId = null;
76
- this.open.clear();
63
+ this.openedAt = null;
64
+ this.turnStartedAt = startedAt;
65
+ this.tools.reset();
77
66
  }
78
67
 
79
68
  /** Tool calls still running — the driver closes them if the agent exits
80
69
  * mid-turn, so no card is left spinning forever. */
81
70
  openCalls(): string[] {
82
- return [...this.open.values()]
83
- .filter((call) => call.status === 'pending' || call.status === 'in_progress')
84
- .map((call) => call.id);
71
+ return this.tools.openCalls();
85
72
  }
86
73
 
87
74
  /**
@@ -97,14 +84,29 @@ export class AcpFrameMapper {
97
84
  return this.appendChunk(update, 'text');
98
85
  case 'agent_thought_chunk':
99
86
  return this.appendChunk(update, 'thinking');
87
+ // v2 whole-message upserts: replace that message's content, keep tool blocks.
88
+ case 'agent_message':
89
+ return this.upsertMessage(update, 'text');
90
+ case 'agent_thought':
91
+ return this.upsertMessage(update, 'thinking');
92
+ case 'user_message':
100
93
  case 'user_message_chunk':
101
94
  // Live user chunks only arrive on replay/steering; the composer already
102
95
  // drew the optimistic bubble, so this is a receipt, not a new row.
103
96
  return [];
104
97
  case 'tool_call':
105
- return this.openTool(update);
98
+ return this.tools.open(update);
106
99
  case 'tool_call_update':
107
- return this.patchTool(update);
100
+ return this.tools.patch(update);
101
+ case 'tool_call_content_chunk':
102
+ return this.tools.appendContent(update);
103
+ // v2's turn boundary is handled by `AcpTurns.onStateUpdate`, not mapped.
104
+ case 'state_update':
105
+ case 'terminal_update':
106
+ case 'terminal_output_chunk':
107
+ case 'compaction_update':
108
+ case 'compaction_summary_chunk':
109
+ return [];
108
110
  case 'usage_update':
109
111
  return this.usage(update);
110
112
  case 'available_commands_update':
@@ -123,6 +125,9 @@ export class AcpFrameMapper {
123
125
  // The spec defines it; no measured agent sends it. Forwarded so a future
124
126
  // adapter lights the panel with no change here.
125
127
  return [{ type: 'plan_updated', entries: update.entries ?? [] }];
128
+ case 'plan_update':
129
+ // v2 keyed plans; Kabmo's Todos panel renders one list.
130
+ return [{ type: 'plan_updated', entries: planEntries(update) }];
126
131
  case 'notice':
127
132
  return [{
128
133
  type: 'notice',
@@ -140,9 +145,16 @@ export class AcpFrameMapper {
140
145
  /** Close the open assistant row (turn end, abort, disconnect). */
141
146
  closeMessage(): AgentEvent[] {
142
147
  if (!this.messageId && this.blocks.length === 0) return [];
148
+ const completedAt = Date.now();
143
149
  const message = this.snapshot();
150
+ const startedAt = this.turnStartedAt ?? this.openedAt;
151
+ if (startedAt !== null) {
152
+ message.completedAt = completedAt;
153
+ message.duration = Math.max(0, completedAt - startedAt);
154
+ }
144
155
  this.blocks = [];
145
156
  this.messageId = null;
157
+ this.openedAt = null;
146
158
  return [{ type: 'message_end', message }];
147
159
  }
148
160
 
@@ -158,9 +170,11 @@ export class AcpFrameMapper {
158
170
  */
159
171
  private snapshot(): Record<string, unknown> {
160
172
  const id = this.messageId ??= `acp-${crypto.randomUUID()}`;
173
+ const timestamp = this.openedAt ??= Date.now();
161
174
  return {
162
175
  role: 'assistant',
163
176
  id,
177
+ timestamp,
164
178
  content: this.blocks.map((block) => ({ ...block })),
165
179
  };
166
180
  }
@@ -194,134 +208,33 @@ export class AcpFrameMapper {
194
208
  return frames;
195
209
  }
196
210
 
197
- private openTool(update: Record<string, unknown>): AgentEvent[] {
198
- const toolCallId = typeof update.toolCallId === 'string' ? update.toolCallId : '';
199
- if (!toolCallId) return [];
200
- const name = typeof update.name === 'string' && update.name
201
- ? update.name
202
- : typeof update.title === 'string' && update.title
203
- ? update.title
204
- : 'tool';
205
- const kind = typeof update.kind === 'string' ? (update.kind as AcpToolKind) : undefined;
206
- const status = typeof update.status === 'string' ? (update.status as AcpToolStatus) : 'pending';
207
- // A specific kind is authoritative. `other`/absent is only an explicit type
208
- // when the name is one the renderers know; otherwise the shared parser's
209
- // own inference from the name is better informed than a forced `read`.
210
- const toolType = kind !== undefined && kind !== 'other'
211
- ? toolTypeFor(kind, name)
212
- : isKnownToolName(name) ? toolTypeFor(kind, name) : undefined;
213
- const rawInput = update.rawInput;
214
- const args = rawInput && typeof rawInput === 'object' && !Array.isArray(rawInput)
215
- ? Object.fromEntries(Object.entries(rawInput))
216
- : undefined;
217
-
218
- // The card is drawn from the message block, so opening a call means adding
219
- // the block and re-emitting the message — not emitting a separate card row.
220
- // `toolType` travels with the block: the shared parser's name inference
221
- // cannot know that ACP `kind:"execute"` means bash when the name is `Shell`.
222
- this.blocks.push({
223
- type: 'toolCall',
224
- id: toolCallId,
225
- name,
226
- ...(args ? { arguments: args } : {}),
227
- ...(kind ? { toolKind: kind } : {}),
228
- ...(toolType ? { toolType } : {}),
229
- });
230
-
231
- const frames: AgentEvent[] = [
232
- { type: 'message_update', message: this.snapshot(), assistantMessageEvent: { type: 'toolcall_start' } },
233
- {
234
- type: 'tool_execution_start',
235
- toolCallId,
236
- toolName: name,
237
- ...(toolType ? { toolType } : {}),
238
- ...(args ? { args } : {}),
239
- ...(typeof update.title === 'string' ? { intent: update.title } : {}),
240
- ...(acpToolTarget(update.locations, rawInput) ? { target: acpToolTarget(update.locations, rawInput) } : {}),
241
- },
242
- ];
243
-
244
- // Some agents announce a call ONLY once it is finished (`tool_call` with
245
- // `status:"completed"` and no later update). Leaving it in the open map
246
- // meant the turn's cleanup closed it as an ERROR, overwriting a success.
247
- if (status === 'completed' || status === 'failed') {
248
- frames.push({
249
- type: 'tool_execution_end',
250
- toolCallId,
251
- toolName: name,
252
- result: update.rawOutput ?? (update.content === undefined ? undefined : { content: update.content }),
253
- isError: status === 'failed',
254
- details: acpToolDetails(update.rawOutput) ?? acpContentDetails(update.content),
255
- output: acpToolOutput(update.rawOutput) || acpContentText(update.content),
256
- });
257
- } else {
258
- this.open.set(toolCallId, {
259
- id: toolCallId,
260
- name,
261
- kind,
262
- title: typeof update.title === 'string' ? update.title : undefined,
263
- status,
264
- rawOutput: update.rawOutput,
265
- content: update.content,
266
- locations: update.locations,
267
- startedAt: Date.now(),
268
- });
269
- }
270
- return frames;
271
- }
272
-
273
211
  /**
274
- * `tool_call_update` is a PATCH: every field but `toolCallId` is optional and
275
- * an omitted one means UNCHANGED. Merging is what keeps a completed card's
276
- * body — measured, the completion update carries only `status` and
277
- * `rawOutput.details`.
212
+ * v2 whole-message upsert: replace that message's blocks of one kind.
213
+ *
214
+ * Tool-call blocks are entities of their own in v2; they stay in place, and
215
+ * the text/thinking content for the message is replaced wholesale.
278
216
  */
279
- private patchTool(update: Record<string, unknown>): AgentEvent[] {
280
- const toolCallId = typeof update.toolCallId === 'string' ? update.toolCallId : '';
281
- if (!toolCallId) return [];
282
- const existing = this.open.get(toolCallId);
283
- // An update for a call this mapper never saw (a replay window, a resumed
284
- // session): treat it as an opening call rather than dropping the work.
285
- if (!existing) return this.openTool(update);
286
-
287
- if (update.rawOutput !== undefined) existing.rawOutput = update.rawOutput;
288
- if (update.content !== undefined) existing.content = update.content;
289
- if (update.locations !== undefined) existing.locations = update.locations;
290
- if (typeof update.title === 'string') existing.title = update.title;
291
- const status = typeof update.status === 'string' ? (update.status as AcpToolStatus) : existing.status;
292
- existing.status = status;
293
-
294
- // Some agents report the result as `content` blocks instead of `rawOutput`;
295
- // the diff block only becomes visible through the details bridge.
296
- const result = existing.rawOutput ?? (existing.content === undefined ? undefined : { content: existing.content });
297
- const output = acpToolOutput(existing.rawOutput) || acpContentText(existing.content);
298
- const details = acpToolDetails(existing.rawOutput) ?? acpContentDetails(existing.content);
299
-
300
- if (status === 'completed' || status === 'failed') {
301
- const failed = status === 'failed';
302
- this.open.delete(toolCallId);
303
- return [{
304
- type: 'tool_execution_end',
305
- toolCallId,
306
- toolName: existing.name,
307
- result,
308
- isError: failed,
309
- details,
310
- durationMs: Math.max(0, Date.now() - existing.startedAt),
311
- output,
312
- }];
217
+ private upsertMessage(update: Record<string, unknown>, kind: 'text' | 'thinking'): AgentEvent[] {
218
+ const messageId = typeof update.messageId === 'string' ? update.messageId : '';
219
+ if (!messageId || !('content' in update)) return [];
220
+ const frames: AgentEvent[] = [];
221
+ if (this.messageId && this.messageId !== messageId) frames.push(...this.closeMessage());
222
+ this.messageId = messageId;
223
+ const raw = update.content;
224
+ const text = raw === null || (Array.isArray(raw) && raw.length === 0) ? '' : acpContentText(raw);
225
+ this.blocks = this.blocks.filter((block) => block.type !== kind);
226
+ if (text) {
227
+ this.blocks.push(kind === 'text' ? { type: 'text', text } : { type: 'thinking', thinking: text });
313
228
  }
314
-
315
- return [{
316
- type: 'tool_execution_update',
317
- toolCallId,
318
- toolName: existing.name,
319
- partialResult: result,
320
- // The ACP output shape may nest text (`{type:"content", content:{…}}`),
321
- // which `toolResultText` does not walk. The flattened read travels with
322
- // the raw result so the card is not blank while the call is running.
323
- output,
324
- }];
229
+ frames.push({
230
+ type: 'message_update',
231
+ message: this.snapshot(),
232
+ assistantMessageEvent: {
233
+ type: kind === 'text' ? 'text_delta' : 'thinking_delta',
234
+ delta: text,
235
+ },
236
+ });
237
+ return frames;
325
238
  }
326
239
 
327
240
  private usage(update: Record<string, unknown>): AgentEvent[] {
@@ -0,0 +1,64 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * The one body field that broke every Claude turn against a strict gateway.
8
+ *
9
+ * Measured on kenari.id: any `/v1/messages` carrying `metadata.user_id` — the
10
+ * attribution object Claude Code adds — answered `400 the model's provider
11
+ * rejected the request. check the model id and request fields`, while the same
12
+ * body without it, or with `metadata: {}`, completed. `CLAUDE_CODE_EXTRA_BODY`
13
+ * is the documented top-level merge, so it is the one place that can empty the
14
+ * field without touching thinking, context management or tools.
15
+ */
16
+
17
+ import { describe, expect, test } from 'bun:test';
18
+ import { withGatewayCompatibility } from '@/server/lib/harness/acp/gateway-env';
19
+
20
+ describe('withGatewayCompatibility', () => {
21
+ test('a custom Claude base URL gets an empty metadata object', () => {
22
+ const env = withGatewayCompatibility('claude', {
23
+ ANTHROPIC_BASE_URL: 'https://kenari.id',
24
+ ANTHROPIC_AUTH_TOKEN: 'kn',
25
+ });
26
+ expect(JSON.parse(env?.CLAUDE_CODE_EXTRA_BODY ?? '{}')).toEqual({ metadata: {} });
27
+ expect(env?.ANTHROPIC_BASE_URL).toBe('https://kenari.id');
28
+ });
29
+
30
+ test('a direct Anthropic connection keeps its attribution', () => {
31
+ const env = { ANTHROPIC_BASE_URL: 'https://api.anthropic.com' };
32
+ expect(withGatewayCompatibility('claude', env)).toBe(env);
33
+ });
34
+
35
+ test('another harness is untouched', () => {
36
+ const env = { ANTHROPIC_BASE_URL: 'https://kenari.id' };
37
+ expect(withGatewayCompatibility('omp-acp', env)).toBe(env);
38
+ expect(withGatewayCompatibility('claude', undefined)).toBeUndefined();
39
+ });
40
+
41
+ test('an existing extra body is preserved, and its own metadata wins', () => {
42
+ const kept = withGatewayCompatibility('claude', {
43
+ ANTHROPIC_BASE_URL: 'https://gw',
44
+ CLAUDE_CODE_EXTRA_BODY: JSON.stringify({ temperature: 0.2 }),
45
+ });
46
+ expect(JSON.parse(kept?.CLAUDE_CODE_EXTRA_BODY ?? '{}')).toEqual({ temperature: 0.2, metadata: {} });
47
+
48
+ const own = withGatewayCompatibility('claude', {
49
+ ANTHROPIC_BASE_URL: 'https://gw',
50
+ CLAUDE_CODE_EXTRA_BODY: JSON.stringify({ metadata: { user_id: 'tenant' } }),
51
+ });
52
+ expect(JSON.parse(own?.CLAUDE_CODE_EXTRA_BODY ?? '{}')).toEqual({ metadata: { user_id: 'tenant' } });
53
+ });
54
+
55
+ test('a malformed extra body is left for the user to fix', () => {
56
+ const env = { ANTHROPIC_BASE_URL: 'https://gw', CLAUDE_CODE_EXTRA_BODY: '{oops' };
57
+ expect(withGatewayCompatibility('claude', env)).toBe(env);
58
+ });
59
+
60
+ test('a malformed base URL is not guessed at', () => {
61
+ const env = { ANTHROPIC_BASE_URL: 'not a url' };
62
+ expect(withGatewayCompatibility('claude', env)).toBe(env);
63
+ });
64
+ });
@@ -0,0 +1,70 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * Env a Claude Code gateway needs to accept its requests.
8
+ *
9
+ * Claude Code puts an attribution string in the request body's
10
+ * `metadata.user_id` (`{"device_id":…,"account_uuid":…,"session_id":…}`). The
11
+ * Anthropic API accepts it, but a strict gateway rejects the whole turn:
12
+ * measured against kenari.id, every `/v1/messages` body carrying ANY
13
+ * `metadata.user_id` answered
14
+ *
15
+ * ```
16
+ * 400 the model's provider rejected the request. check the model id and request fields
17
+ * ```
18
+ *
19
+ * while the same body without the field — and the same body with
20
+ * `metadata: {}` — completed. `CLAUDE_CODE_EXTRA_BODY` is merged into the top
21
+ * level of the request, so an empty metadata object replaces the attribution
22
+ * one without touching anything else (thinking, context management, tools).
23
+ *
24
+ * Only a CUSTOM base URL gets this: a direct Anthropic connection is welcome
25
+ * to the attribution. A body the user already controls is respected — an
26
+ * existing `metadata` or a non-object `CLAUDE_CODE_EXTRA_BODY` is left alone
27
+ * rather than overwritten.
28
+ */
29
+
30
+ import type { HarnessId } from '@/shared/lib/harness/catalog';
31
+
32
+ /** Anthropic's own host. Everything else under `ANTHROPIC_BASE_URL` is a gateway. */
33
+ const ANTHROPIC_HOST = 'api.anthropic.com';
34
+
35
+ /** The env a spawn should use, with the gateway compatibility applied. */
36
+ export function withGatewayCompatibility(
37
+ harness: HarnessId,
38
+ env: Record<string, string> | undefined,
39
+ ): Record<string, string> | undefined {
40
+ if (harness !== 'claude' || !env) return env;
41
+ const baseUrl = env.ANTHROPIC_BASE_URL?.trim();
42
+ if (!baseUrl) return env;
43
+ let host: string;
44
+ try {
45
+ host = new URL(baseUrl).host;
46
+ } catch {
47
+ // A malformed URL is already a spawn failure the agent reports; guessing
48
+ // at its meaning here would only hide that message.
49
+ return env;
50
+ }
51
+ if (host === ANTHROPIC_HOST) return env;
52
+
53
+ let extra: Record<string, unknown> = {};
54
+ const existing = env.CLAUDE_CODE_EXTRA_BODY?.trim();
55
+ if (existing) {
56
+ try {
57
+ const parsed: unknown = JSON.parse(existing);
58
+ if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) return env;
59
+ // The user's own metadata is deliberate; an empty object is the only
60
+ // value this module may substitute.
61
+ if ('metadata' in parsed) return env;
62
+ extra = parsed as Record<string, unknown>;
63
+ } catch {
64
+ // Not JSON: the agent would ignore it, and replacing it would discard a
65
+ // value the user is still editing.
66
+ return env;
67
+ }
68
+ }
69
+ return { ...env, CLAUDE_CODE_EXTRA_BODY: JSON.stringify({ ...extra, metadata: {} }) };
70
+ }
@@ -0,0 +1,40 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * The pure ACP content helpers the mapper feeds the renderers with.
8
+ *
9
+ * Split from `frames.test.ts` when the v2 cases pushed that file past the line
10
+ * ceiling; these cases do not need the accumulator.
11
+ */
12
+
13
+ import { describe, expect, test } from 'bun:test';
14
+ import { acpContentText, acpToolOutput, acpToolTarget } from '@/server/lib/harness/acp/mapper';
15
+
16
+ describe('acp mapper helpers', () => {
17
+ test('both measured content shapes yield text', () => {
18
+ expect(acpContentText([{ type: 'text', text: 'a' }, { type: 'text', text: 'b' }])).toBe('a\nb');
19
+ expect(acpContentText([{ type: 'content', content: { type: 'text', text: 'wrapped' } }])).toBe('wrapped');
20
+ expect(acpContentText('plain')).toBe('plain');
21
+ // MCP-style tool output: the embedded text is readable, a link is named.
22
+ expect(acpContentText([{ type: 'resource', resource: { uri: 'file:///a.txt', text: 'hello' } }])).toBe('hello');
23
+ expect(acpContentText([{ type: 'resource', resource: { uri: 'file:///a.bin', blob: 'AA==' } }]))
24
+ .toBe('[binary resource file:///a.bin]');
25
+ expect(acpContentText([{ type: 'resource_link', uri: 'file:///a.md', name: 'a.md' }]))
26
+ .toBe('a.md (file:///a.md)');
27
+ });
28
+
29
+ test('rawOutput keeps omp-shaped fallbacks', () => {
30
+ expect(acpToolOutput({ content: [{ type: 'text', text: 'x' }] })).toBe('x');
31
+ expect(acpToolOutput({ output: 'y' })).toBe('y');
32
+ expect(acpToolOutput(null)).toBe('');
33
+ });
34
+
35
+ test('target prefers locations, then the input bag', () => {
36
+ expect(acpToolTarget([{ path: '/a' }], { path: 'b' })).toBe('/a');
37
+ expect(acpToolTarget(undefined, { command: 'ls -la' })).toBe('ls -la');
38
+ expect(acpToolTarget(undefined, undefined)).toBeUndefined();
39
+ });
40
+ });
@@ -80,6 +80,18 @@ function entryText(entry: unknown): string {
80
80
  if (!('type' in entry)) return '';
81
81
  if (entry.type === 'text' && 'text' in entry && typeof entry.text === 'string') return entry.text;
82
82
  if (entry.type === 'content' && 'content' in entry) return entryText(entry.content);
83
+ // MCP tool output commonly carries complete resources. The text form is
84
+ // readable; a blob has no text, so the card names it rather than showing
85
+ // nothing at all.
86
+ if (entry.type === 'resource' && 'resource' in entry && entry.resource && typeof entry.resource === 'object') {
87
+ if ('text' in entry.resource && typeof entry.resource.text === 'string') return entry.resource.text;
88
+ const uri = 'uri' in entry.resource && typeof entry.resource.uri === 'string' ? entry.resource.uri : '';
89
+ return uri ? `[binary resource ${uri}]` : '';
90
+ }
91
+ if (entry.type === 'resource_link' && 'uri' in entry && typeof entry.uri === 'string') {
92
+ const name = 'name' in entry && typeof entry.name === 'string' ? entry.name : entry.uri;
93
+ return `${name} (${entry.uri})`;
94
+ }
83
95
  return '';
84
96
  }
85
97
 
@@ -109,6 +109,12 @@ export class PendingPermissions {
109
109
  this.entries.length = 0;
110
110
  }
111
111
 
112
+ /** Remove and return every pending request, for a caller that must answer
113
+ * each one (a cancelled turn answers them all with `cancelled`). */
114
+ drain(): PendingPermission[] {
115
+ return this.entries.splice(0, this.entries.length);
116
+ }
117
+
112
118
  size(): number {
113
119
  return this.entries.length;
114
120
  }
@@ -127,4 +127,24 @@ describe('applySelections', () => {
127
127
  );
128
128
  expect(writes).toEqual([]);
129
129
  });
130
+
131
+ test('a matched model the agent refuses fails the spawn with its reason', async () => {
132
+ // dsh answered `unknown model option` when its configured provider was no
133
+ // longer in the live list. Swallowing it ran the turn on the agent's own
134
+ // default provider, and the first prompt's error named neither the model nor
135
+ // the refused write.
136
+ await expect(applySelections(
137
+ {
138
+ harness: 'dsh',
139
+ configOptions: [option('sel-model', 'model', ['["kenari","qwen3-8-27b:free"]'])],
140
+ runModel: null,
141
+ setConfig: async () => {
142
+ throw new Error('Invalid params: unknown model option');
143
+ },
144
+ },
145
+ // dsh stores its selector as a stringified pair, so the configured
146
+ // default is a provider-less id. That is the spelling this write uses.
147
+ { model: { provider: '', modelId: '["kenari","qwen3-8-27b:free"]' }, thinking: null, mode: null },
148
+ )).rejects.toThrow('dsh refused model "["kenari","qwen3-8-27b:free"]"');
149
+ });
130
150
  });
@@ -103,6 +103,8 @@ export interface ConfigSelectionHost {
103
103
  configOptions: AcpConfigOption[];
104
104
  runModel: { provider: string; modelId: string } | null;
105
105
  setConfig(configId: string, value: string | boolean): Promise<unknown>;
106
+ /** The harness id, so a refused write names the agent instead of "it". */
107
+ readonly harness?: string;
106
108
  }
107
109
 
108
110
  /**
@@ -110,8 +112,13 @@ export interface ConfigSelectionHost {
110
112
  *
111
113
  * A selector the agent does not publish is SKIPPED, never guessed: an agent with
112
114
  * no thinking ladder must not have a level invented for it, and a model the
113
- * agent does not list is not written. Every write is best-effort — a spawn that
114
- * fails because an optional knob was rejected would be worse than the default.
115
+ * agent does not list is not written. That skip is about an OPTIONAL knob.
116
+ *
117
+ * The MODEL write is not optional: a chat whose model could not be applied runs
118
+ * on the agent's default provider. On dsh that was a silent switch to
119
+ * `deepseek-official` with no key, so the first prompt failed with a message
120
+ * that named neither the model nor the refused write. A matched model write
121
+ * that the agent rejects now fails the spawn with its own words.
115
122
  */
116
123
  export async function applySelections(host: ConfigSelectionHost, wanted: ConfigSelections): Promise<void> {
117
124
  const model = configOption(host.configOptions, 'model');
@@ -121,7 +128,16 @@ export async function applySelections(host: ConfigSelectionHost, wanted: ConfigS
121
128
  const match = values.find((value) => value === exact) ?? values.find((value) => value === wanted.model?.modelId);
122
129
  // `session/set_config_option` keys on the selector's ID, which an agent may
123
130
  // name anything; the category only says what the selector MEANS.
124
- if (match) await host.setConfig(model.id, match).catch(() => {});
131
+ if (match) {
132
+ try {
133
+ await host.setConfig(model.id, match);
134
+ } catch (error) {
135
+ throw new Error(
136
+ `${host.harness ?? 'The agent'} refused model "${match}": `
137
+ + `${error instanceof Error ? error.message : String(error)}`,
138
+ );
139
+ }
140
+ }
125
141
  }
126
142
  const thinking = configOption(host.configOptions, 'thought_level');
127
143
  if (thinking && wanted.thinking && acpOptionValues(thinking).includes(wanted.thinking)) {
@@ -22,6 +22,25 @@
22
22
  /** A JSON-RPC id. ACP forbids `null`, and replies echo whatever was sent. */
23
23
  export type AcpId = string | number;
24
24
 
25
+ /**
26
+ * The JSON-RPC/ACP error codes Kabmo answers with.
27
+ *
28
+ * A refusal is not "internal error": an agent decides whether to fall back, retry
29
+ * or give up from the code, so `-32601` for a method this client does not
30
+ * implement and `-32002` for a missing file are part of the contract rather than
31
+ * cosmetic detail.
32
+ */
33
+ export const ACP_ERROR = {
34
+ parse: -32700,
35
+ invalidRequest: -32600,
36
+ methodNotFound: -32601,
37
+ invalidParams: -32602,
38
+ internal: -32603,
39
+ cancelled: -32800,
40
+ authRequired: -32000,
41
+ notFound: -32002,
42
+ } as const;
43
+
25
44
  export interface AcpRequest {
26
45
  jsonrpc: '2.0';
27
46
  id: AcpId;
@@ -61,7 +80,17 @@ export type AcpToolKind =
61
80
  | 'switch_mode'
62
81
  | 'other';
63
82
 
64
- export type AcpToolStatus = 'pending' | 'in_progress' | 'completed' | 'failed';
83
+ export type AcpToolStatus = 'pending' | 'in_progress' | 'paused' | 'completed' | 'failed' | 'cancelled';
84
+
85
+ /** A protocol major this client can speak. */
86
+ export type AcpProtocolVersion = 1 | 2;
87
+
88
+ /** One slash command, in the shape the composer consumes. */
89
+ export interface AcpAgentCommand {
90
+ name: string;
91
+ description?: string;
92
+ inputHint?: string;
93
+ }
65
94
 
66
95
  export interface AcpToolLocation {
67
96
  path: string;
@@ -112,7 +141,17 @@ export interface AcpConfigOption {
112
141
  export interface AcpSessionNewResult {
113
142
  sessionId: string;
114
143
  configOptions?: AcpConfigOption[];
115
- modes?: unknown;
144
+ /** The older Session Modes API. A client that understands `configOptions`
145
+ * SHOULD ignore this; Kabmo falls back to it when no `mode` selector exists. */
146
+ modes?: AcpSessionModeState;
147
+ /** v2 setup responses may advertise the initial slash commands. */
148
+ availableCommands?: AcpAgentCommand[];
149
+ }
150
+
151
+ /** `session/new|load|resume`'s legacy mode state, and `session/set_mode`. */
152
+ export interface AcpSessionModeState {
153
+ currentModeId: string;
154
+ availableModes: { id: string; name: string; description?: string }[];
116
155
  }
117
156
 
118
157
  export interface AcpInitializeResult {