@kabmo-labs/kabmo 0.22.0 → 0.24.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 (446) hide show
  1. package/README.md +1 -1
  2. package/dist/client/index.html +1 -1
  3. package/dist/client/index.js +873 -524
  4. package/dist/client/static/js/{index-297dck9a.js → index-jcr5twtp.js} +799 -795
  5. package/dist/client/static/js/index-z3w7n85q.css +1 -0
  6. package/marketplace/plugins/stats/package.json +2 -2
  7. package/marketplace/plugins/stats/src/groups.test.ts +14 -0
  8. package/marketplace/plugins/stats/src/groups.ts +20 -0
  9. package/marketplace/plugins/stats/src/labels.test.ts +9 -0
  10. package/marketplace/plugins/stats/src/labels.ts +7 -0
  11. package/marketplace/plugins/stats/src/server.ts +1 -1
  12. package/package.json +1 -1
  13. package/src/client/App.tsx +20 -19
  14. package/src/client/components/common/ComposerTextarea.tsx +10 -1
  15. package/src/client/components/common/Modal.tsx +2 -6
  16. package/src/client/components/common/PWAInstallButton.tsx +3 -2
  17. package/src/client/components/common/Toast.test.tsx +298 -0
  18. package/src/client/components/common/Toast.tsx +103 -37
  19. package/src/client/components/common/ToastStack.tsx +33 -12
  20. package/src/client/components/common/ViewportSelector.tsx +122 -114
  21. package/src/client/components/common/context-usage-button/Ring.tsx +38 -1
  22. package/src/client/components/common/context-usage-button/index.test.tsx +19 -3
  23. package/src/client/components/common/context-usage-button/index.tsx +5 -2
  24. package/src/client/components/common/harness-glyph/brands.ts +65 -0
  25. package/src/client/components/common/harness-glyph/harness-glyph.test.ts +185 -0
  26. package/src/client/components/common/harness-glyph/index.tsx +131 -0
  27. package/src/client/components/common/header-controls/MoreMenu.tsx +2 -1
  28. package/src/client/components/common/header-controls/index.tsx +16 -8
  29. package/src/client/components/common/header-panel-buttons/index.tsx +4 -3
  30. package/src/client/components/common/panel-mark/index.test.tsx +2 -2
  31. package/src/client/components/common/panel-mark/index.tsx +11 -2
  32. package/src/client/components/common/search-select/index.tsx +305 -0
  33. package/src/client/components/common/search-select/search-select.test.tsx +217 -0
  34. package/src/client/components/common/server-control/index.tsx +3 -2
  35. package/src/client/components/common/session-row/index.tsx +18 -1
  36. package/src/client/components/common/toolbar-row/index.tsx +57 -20
  37. package/src/client/components/layout/desktop-layout/LeftColumn.tsx +1 -3
  38. package/src/client/components/layout/desktop-layout/TopNavbar.tsx +3 -2
  39. package/src/client/components/layout/desktop-layout/WorkspacePanels.tsx +7 -1
  40. package/src/client/components/layout/desktop-layout/index.tsx +1 -3
  41. package/src/client/components/layout/session-sidebar/CategoryItem.tsx +1 -0
  42. package/src/client/components/layout/session-sidebar/SessionItem.tsx +18 -1
  43. package/src/client/components/layout/session-sidebar/SessionsView.tsx +1 -3
  44. package/src/client/components/layout/session-sidebar/about-modal/HarnessTable.test.tsx +332 -0
  45. package/src/client/components/layout/session-sidebar/about-modal/HarnessTable.tsx +310 -0
  46. package/src/client/components/layout/session-sidebar/about-modal/SocialLinks.tsx +63 -51
  47. package/src/client/components/layout/session-sidebar/about-modal/UpdateSection.tsx +4 -2
  48. package/src/client/components/layout/session-sidebar/about-modal/index.test.tsx +122 -0
  49. package/src/client/components/layout/session-sidebar/about-modal/index.tsx +136 -35
  50. package/src/client/components/layout/session-sidebar/harness-mark.test.tsx +126 -0
  51. package/src/client/components/layout/session-sidebar/modern/ActionRow.tsx +4 -3
  52. package/src/client/components/layout/session-sidebar/modern/WorkspaceSection.tsx +1 -0
  53. package/src/client/components/mobile/LayoutWrapper.tsx +1 -7
  54. package/src/client/components/mobile/SessionSidebar.tsx +1 -3
  55. package/src/client/components/mobile/mobile-main-view/Header.tsx +3 -2
  56. package/src/client/components/mobile/mobile-session-sidebar/Dialogs.tsx +0 -8
  57. package/src/client/components/mobile/mobile-session-sidebar/Item.tsx +1 -0
  58. package/src/client/components/mobile/mobile-session-sidebar/SessionRow.tsx +17 -1
  59. package/src/client/components/settings/Modal.tsx +26 -22
  60. package/src/client/components/settings/Sidebar.tsx +45 -5
  61. package/src/client/components/settings/categories/HarnessSettings.tsx +207 -0
  62. package/src/client/components/settings/categories/ProjectSettings.tsx +1 -3
  63. package/src/client/components/settings/categories/ProviderSettings.tsx +0 -4
  64. package/src/client/components/settings/categories/SkillCatalogSettings.tsx +13 -23
  65. package/src/client/components/settings/categories/agent-settings/ModelPicker.tsx +23 -30
  66. package/src/client/components/settings/categories/appearance-settings/IconStyleSection.tsx +20 -11
  67. package/src/client/components/settings/categories/chat-settings/GoalSection.tsx +16 -16
  68. package/src/client/components/settings/categories/harness-settings/AddProviderForm.tsx +219 -0
  69. package/src/client/components/settings/categories/harness-settings/ConfigForm.tsx +268 -0
  70. package/src/client/components/settings/categories/harness-settings/EnvProviderForm.tsx +146 -0
  71. package/src/client/components/settings/categories/harness-settings/HarnessCard.tsx +278 -0
  72. package/src/client/components/settings/categories/harness-settings/ImportSection.tsx +195 -0
  73. package/src/client/components/settings/categories/harness-settings/ProviderPanel.tsx +152 -0
  74. package/src/client/components/settings/categories/harness-settings/ToggleList.tsx +147 -0
  75. package/src/client/components/settings/categories/harness-settings/parts.test.tsx +97 -0
  76. package/src/client/components/settings/categories/harness-settings/parts.tsx +84 -0
  77. package/src/client/components/settings/categories/harness-settings/provider-panel.test.tsx +313 -0
  78. package/src/client/components/settings/categories/omp-settings/RoleEditor.test.ts +60 -39
  79. package/src/client/components/settings/categories/omp-settings/RoleRow.tsx +32 -41
  80. package/src/client/components/settings/categories/omp-settings/role-picker.test-util.ts +45 -0
  81. package/src/client/components/settings/categories/panel-plugins/PluginMark.test.ts +1 -1
  82. package/src/client/components/settings/categories/panel-plugins/PluginMark.tsx +11 -4
  83. package/src/client/components/settings/groups.test.tsx +160 -0
  84. package/src/client/components/settings/harness-icons.test.tsx +134 -0
  85. package/src/client/components/workspace/browser-panel/AddressBar.tsx +3 -13
  86. package/src/client/components/workspace/browser-toolbar/clusters.tsx +237 -0
  87. package/src/client/components/workspace/browser-toolbar/index.test.tsx +167 -0
  88. package/src/client/components/workspace/browser-toolbar/index.tsx +99 -100
  89. package/src/client/components/workspace/btw-panel/Messages.tsx +4 -1
  90. package/src/client/components/workspace/btw-panel/index.tsx +2 -0
  91. package/src/client/components/workspace/chat-timeline/AiMessageFooter.tsx +11 -7
  92. package/src/client/components/workspace/chat-timeline/ChatOverlays.tsx +5 -2
  93. package/src/client/components/workspace/chat-timeline/ComposerDock.tsx +13 -0
  94. package/src/client/components/workspace/chat-timeline/EmptyWorkspacePrompt.tsx +13 -0
  95. package/src/client/components/workspace/chat-timeline/GeneratingIndicator.test.ts +41 -0
  96. package/src/client/components/workspace/chat-timeline/GeneratingIndicator.tsx +19 -14
  97. package/src/client/components/workspace/chat-timeline/MessageList.test.ts +14 -0
  98. package/src/client/components/workspace/chat-timeline/MessageList.tsx +6 -0
  99. package/src/client/components/workspace/chat-timeline/PendingChatView.tsx +14 -0
  100. package/src/client/components/workspace/chat-timeline/RunFooter.tsx +4 -0
  101. package/src/client/components/workspace/chat-timeline/RunMark.tsx +58 -0
  102. package/src/client/components/workspace/chat-timeline/SubagentView.tsx +4 -1
  103. package/src/client/components/workspace/chat-timeline/TimelineBody.tsx +4 -0
  104. package/src/client/components/workspace/chat-timeline/chat-input/AttachmentToolbar.tsx +1 -0
  105. package/src/client/components/workspace/chat-timeline/chat-input/ComposerRows.tsx +11 -0
  106. package/src/client/components/workspace/chat-timeline/chat-input/ModeToggles.test.ts +13 -0
  107. package/src/client/components/workspace/chat-timeline/chat-input/ModeToggles.tsx +8 -1
  108. package/src/client/components/workspace/chat-timeline/chat-input/Toolbar.test.ts +27 -1
  109. package/src/client/components/workspace/chat-timeline/chat-input/Toolbar.tsx +48 -23
  110. package/src/client/components/workspace/chat-timeline/chat-input/composer-portal.test.tsx +1 -0
  111. package/src/client/components/workspace/chat-timeline/chat-input/index.tsx +21 -1
  112. package/src/client/components/workspace/chat-timeline/chat-input/modes-props.ts +7 -0
  113. package/src/client/components/workspace/chat-timeline/chat-input/props.ts +13 -0
  114. package/src/client/components/workspace/chat-timeline/chat-input/selection.ts +11 -2
  115. package/src/client/components/workspace/chat-timeline/chat-input/styles.test.tsx +1 -0
  116. package/src/client/components/workspace/chat-timeline/index.tsx +17 -15
  117. package/src/client/components/workspace/chat-timeline/pending-harness.test.tsx +157 -0
  118. package/src/client/components/workspace/chat-timeline/run-mark.test.ts +104 -0
  119. package/src/client/components/workspace/chat-timeline/tool-renderers/ask-panel/FrameControl.tsx +11 -20
  120. package/src/client/components/workspace/chat-timeline/tool-renderers/ask-panel/GroupedAsk.tsx +1 -1
  121. package/src/client/components/workspace/chat-timeline/tool-renderers/ask-panel/QuestionBlock.tsx +1 -1
  122. package/src/client/components/workspace/chat-timeline/tool-renderers/ask-panel/drafts.ts +1 -1
  123. package/src/client/components/workspace/chat-timeline/tool-renderers/ask-panel/index.tsx +2 -1
  124. package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Bash.test.ts +31 -3
  125. package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Bash.tsx +5 -1
  126. package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Wait.test.ts +56 -45
  127. package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Wait.tsx +38 -94
  128. package/src/client/components/workspace/chat-timeline/tool-renderers/panels/wait-parts.tsx +76 -0
  129. package/src/client/components/workspace/chat-timeline/tool-renderers/shared/card-header.ts +2 -1
  130. package/src/client/components/workspace/file-explorer/index.test.ts +25 -0
  131. package/src/client/components/workspace/file-explorer/index.tsx +10 -6
  132. package/src/client/components/workspace/git-panel/index.test.ts +13 -3
  133. package/src/client/components/workspace/git-panel/index.tsx +1 -3
  134. package/src/client/components/workspace/model-dropdown/Fullscreen.tsx +92 -0
  135. package/src/client/components/workspace/model-dropdown/HarnessTabs.tsx +290 -0
  136. package/src/client/components/workspace/model-dropdown/Item.tsx +11 -0
  137. package/src/client/components/workspace/model-dropdown/Panel.tsx +119 -8
  138. package/src/client/components/workspace/model-dropdown/Section.tsx +4 -0
  139. package/src/client/components/workspace/model-dropdown/fullscreen-picker.ts +51 -0
  140. package/src/client/components/workspace/model-dropdown/harness-models.test.ts +177 -0
  141. package/src/client/components/workspace/model-dropdown/harness-models.ts +148 -0
  142. package/src/client/components/workspace/model-dropdown/harness-tabs.test.tsx +336 -0
  143. package/src/client/components/workspace/model-dropdown/index.tsx +114 -85
  144. package/src/client/components/workspace/model-dropdown/placement.test.tsx +127 -0
  145. package/src/client/components/workspace/model-dropdown/popover-metrics.test.ts +107 -0
  146. package/src/client/components/workspace/model-dropdown/popover-metrics.ts +118 -0
  147. package/src/client/components/workspace/model-dropdown/row-mutations.ts +106 -0
  148. package/src/client/components/workspace/model-dropdown/trigger.test.ts +22 -2
  149. package/src/client/components/workspace/model-dropdown/use-popover-size.ts +89 -0
  150. package/src/client/data/settings/omp-schema.json +224 -17
  151. package/src/client/hooks/chat/composer/index.ts +11 -2
  152. package/src/client/hooks/chat/composer/items.test.ts +11 -0
  153. package/src/client/hooks/chat/composer/items.ts +4 -2
  154. package/src/client/hooks/chat/composer/model-selection.test.ts +110 -0
  155. package/src/client/hooks/chat/composer/model-selection.ts +45 -4
  156. package/src/client/hooks/chat/omp/prompt-send.ts +4 -2
  157. package/src/client/hooks/chat/timeline/actions.ts +10 -5
  158. package/src/client/hooks/chat/timeline/ask-frames.ts +5 -4
  159. package/src/client/hooks/chat/timeline/composer-local-actions.test.ts +19 -81
  160. package/src/client/hooks/chat/timeline/composer-modes.ts +11 -2
  161. package/src/client/hooks/chat/timeline/composer-refs.ts +16 -1
  162. package/src/client/hooks/chat/timeline/index.ts +27 -35
  163. package/src/client/hooks/chat/timeline/mode-availability.test.ts +51 -0
  164. package/src/client/hooks/chat/timeline/modes-contract.ts +6 -0
  165. package/src/client/hooks/chat/timeline/modes.ts +41 -2
  166. package/src/client/hooks/chat/timeline/new-chat-open.test.ts +86 -0
  167. package/src/client/hooks/chat/timeline/new-chat-open.ts +23 -5
  168. package/src/client/hooks/chat/timeline/new-chat.test.ts +32 -4
  169. package/src/client/hooks/chat/timeline/new-chat.ts +18 -6
  170. package/src/client/hooks/chat/timeline/prompt-text.test.ts +7 -0
  171. package/src/client/hooks/chat/timeline/prompt-text.ts +15 -6
  172. package/src/client/hooks/chat/timeline/rewind-actions.test.ts +51 -1
  173. package/src/client/hooks/chat/timeline/rewind-actions.ts +23 -1
  174. package/src/client/hooks/chat/timeline/run-identity.test.ts +52 -0
  175. package/src/client/hooks/chat/timeline/run-identity.ts +23 -11
  176. package/src/client/hooks/chat/timeline/send-execute.test.ts +55 -0
  177. package/src/client/hooks/chat/timeline/send-props.ts +11 -3
  178. package/src/client/hooks/chat/timeline/send-steer.test.ts +2 -3
  179. package/src/client/hooks/chat/timeline/send.test-util.ts +3 -2
  180. package/src/client/hooks/chat/timeline/send.test.ts +2 -3
  181. package/src/client/hooks/chat/timeline/send.ts +34 -8
  182. package/src/client/hooks/chat/timeline/session-harness.test.ts +163 -0
  183. package/src/client/hooks/chat/timeline/session-harness.ts +164 -0
  184. package/src/client/hooks/chat/timeline/session-load.test-util.ts +6 -2
  185. package/src/client/hooks/chat/timeline/session-load.test.ts +31 -0
  186. package/src/client/hooks/chat/timeline/session-load.ts +6 -14
  187. package/src/client/hooks/chat/timeline/session-shapes.ts +32 -0
  188. package/src/client/hooks/chat/timeline/spawn-harness.ts +41 -0
  189. package/src/client/hooks/chat/timeline/timeline-running.ts +55 -0
  190. package/src/client/hooks/chat/timeline/tui-only-guard.ts +9 -0
  191. package/src/client/hooks/chat/timeline/undo-confirmation.test.ts +131 -0
  192. package/src/client/hooks/models/harness-catalog.ts +114 -0
  193. package/src/client/hooks/models/provider-writes.test.ts +81 -0
  194. package/src/client/hooks/models/provider-writes.ts +144 -0
  195. package/src/client/hooks/models/use-harness-versions.test.ts +152 -0
  196. package/src/client/hooks/models/use-harness-versions.ts +136 -0
  197. package/src/client/hooks/models/use-harnesses-controller.ts +57 -0
  198. package/src/client/hooks/models/use-harnesses-signal.test.ts +128 -0
  199. package/src/client/hooks/models/use-harnesses.test.ts +187 -0
  200. package/src/client/hooks/models/use-harnesses.ts +215 -0
  201. package/src/client/hooks/settings/providers/index.ts +1 -3
  202. package/src/client/hooks/ui/editor-error-toast.ts +10 -3
  203. package/src/client/hooks/ui/icon-style.ts +28 -0
  204. package/src/client/hooks/ui/on-click-outside.test.ts +104 -0
  205. package/src/client/hooks/ui/on-click-outside.ts +14 -2
  206. package/src/client/hooks/ui/theme.ts +6 -0
  207. package/src/client/hooks/ui/toast-queue.test.ts +126 -0
  208. package/src/client/hooks/ui/toasts.ts +132 -27
  209. package/src/client/hooks/ui/ui-feedback.test.ts +4 -91
  210. package/src/client/lib/ui/control-plate.test.ts +76 -0
  211. package/src/client/lib/ui/control-plate.ts +65 -0
  212. package/src/client/tailwind.css +47 -1
  213. package/src/server/lib/assets/shell-attributes.server.ts +9 -2
  214. package/src/server/lib/assets/shell-attributes.test.ts +22 -6
  215. package/src/server/lib/db/schema.ts +4 -0
  216. package/src/server/lib/harness/acp/acp-audit.server.ts +107 -0
  217. package/src/server/lib/harness/acp/acp-goal-driver.server.ts +153 -0
  218. package/src/server/lib/harness/acp/acp-goal-state.server.ts +136 -0
  219. package/src/server/lib/harness/acp/acp-goal.server.ts +273 -0
  220. package/src/server/lib/harness/acp/acp-goal.test.ts +229 -0
  221. package/src/server/lib/harness/acp/acp-telemetry.server.ts +133 -0
  222. package/src/server/lib/harness/acp/acp-telemetry.test.ts +85 -0
  223. package/src/server/lib/harness/acp/acp-todos.server.ts +45 -0
  224. package/src/server/lib/harness/acp/acp-todos.test.ts +43 -0
  225. package/src/server/lib/harness/acp/activation.test.ts +81 -0
  226. package/src/server/lib/harness/acp/activation.ts +72 -0
  227. package/src/server/lib/harness/acp/calls.ts +97 -0
  228. package/src/server/lib/harness/acp/client.test.ts +73 -0
  229. package/src/server/lib/harness/acp/client.ts +339 -0
  230. package/src/server/lib/harness/acp/commands.test.ts +92 -0
  231. package/src/server/lib/harness/acp/commands.ts +165 -0
  232. package/src/server/lib/harness/acp/frames.test.ts +315 -0
  233. package/src/server/lib/harness/acp/frames.ts +349 -0
  234. package/src/server/lib/harness/acp/mapper.ts +204 -0
  235. package/src/server/lib/harness/acp/permissions.test.ts +66 -0
  236. package/src/server/lib/harness/acp/permissions.ts +155 -0
  237. package/src/server/lib/harness/acp/prompt.test.ts +130 -0
  238. package/src/server/lib/harness/acp/prompt.ts +134 -0
  239. package/src/server/lib/harness/acp/protocol.ts +162 -0
  240. package/src/server/lib/harness/acp/session-config.test.ts +73 -0
  241. package/src/server/lib/harness/acp/session-config.ts +148 -0
  242. package/src/server/lib/harness/acp/session-facts.ts +71 -0
  243. package/src/server/lib/harness/acp/session-handshake.ts +89 -0
  244. package/src/server/lib/harness/acp/session-idle.ts +51 -0
  245. package/src/server/lib/harness/acp/session-notifications.ts +95 -0
  246. package/src/server/lib/harness/acp/session-observers.test.ts +193 -0
  247. package/src/server/lib/harness/acp/session-options.ts +33 -0
  248. package/src/server/lib/harness/acp/session-permissions.test.ts +105 -0
  249. package/src/server/lib/harness/acp/session-permissions.ts +74 -0
  250. package/src/server/lib/harness/acp/session-reaper.test.ts +96 -0
  251. package/src/server/lib/harness/acp/session-turns.ts +95 -0
  252. package/src/server/lib/harness/acp/session-usage.ts +60 -0
  253. package/src/server/lib/harness/acp/session-web-state.ts +61 -0
  254. package/src/server/lib/harness/acp/session.test-util.ts +160 -0
  255. package/src/server/lib/harness/acp/session.test.ts +233 -0
  256. package/src/server/lib/harness/acp/session.ts +350 -0
  257. package/src/server/lib/harness/acp/turn.ts +199 -0
  258. package/src/server/lib/harness/acp/verbs.ts +87 -0
  259. package/src/server/lib/harness/auto-probe.server.test.ts +121 -0
  260. package/src/server/lib/harness/auto-probe.server.ts +178 -0
  261. package/src/server/lib/harness/capabilities.ts +67 -0
  262. package/src/server/lib/harness/config-invalidation.test.ts +91 -0
  263. package/src/server/lib/harness/config.server.test.ts +105 -0
  264. package/src/server/lib/harness/config.server.ts +98 -0
  265. package/src/server/lib/harness/enabled.server.test.ts +87 -0
  266. package/src/server/lib/harness/enabled.server.ts +61 -0
  267. package/src/server/lib/harness/launch-table.ts +195 -0
  268. package/src/server/lib/harness/launch.test.ts +220 -0
  269. package/src/server/lib/harness/launch.ts +216 -0
  270. package/src/server/lib/harness/probe-cache.server.test.ts +154 -0
  271. package/src/server/lib/harness/probe-cache.server.ts +177 -0
  272. package/src/server/lib/harness/provider-entry.ts +212 -0
  273. package/src/server/lib/harness/provider-file.server.ts +67 -0
  274. package/src/server/lib/harness/provider-import.test.ts +191 -0
  275. package/src/server/lib/harness/provider-probe.server.ts +123 -0
  276. package/src/server/lib/harness/provider-sources.server.test.ts +45 -0
  277. package/src/server/lib/harness/provider-sources.server.ts +308 -0
  278. package/src/server/lib/harness/provider-write-error.ts +19 -0
  279. package/src/server/lib/harness/provider-write.server.test.ts +308 -0
  280. package/src/server/lib/harness/provider-write.server.ts +339 -0
  281. package/src/server/lib/harness/provider-zcode.server.test.ts +270 -0
  282. package/src/server/lib/harness/provider-zcode.server.ts +324 -0
  283. package/src/server/lib/harness/register.server.ts +36 -0
  284. package/src/server/lib/harness/registry.ts +58 -0
  285. package/src/server/lib/harness/schema.server.ts +129 -0
  286. package/src/server/lib/harness/session-store.server.test.ts +175 -0
  287. package/src/server/lib/harness/session-store.server.ts +206 -0
  288. package/src/server/lib/harness/session-title.server.test.ts +109 -0
  289. package/src/server/lib/harness/session-title.server.ts +70 -0
  290. package/src/server/lib/harness/session.ts +74 -0
  291. package/src/server/lib/harness/spawn.server.ts +133 -0
  292. package/src/server/lib/harness/update-state.server.ts +185 -0
  293. package/src/server/lib/lifecycle/after-listen.ts +7 -0
  294. package/src/server/lib/models/provider-items.server.ts +1 -1
  295. package/src/server/lib/models/registry-refresh.server.test.ts +87 -0
  296. package/src/server/lib/models/registry-refresh.server.ts +98 -0
  297. package/src/server/lib/omp/config/models-config.ts +4 -0
  298. package/src/server/lib/omp/core/cli.ts +13 -0
  299. package/src/server/lib/omp/core/host-resolution.test.ts +6 -3
  300. package/src/server/lib/omp/rpc/child-config.ts +5 -4
  301. package/src/server/lib/omp/rpc/constants.test.ts +2 -1
  302. package/src/server/lib/omp/rpc/event-fanout.ts +9 -0
  303. package/src/server/lib/omp/rpc/forked-resume.test.ts +14 -3
  304. package/src/server/lib/omp/rpc/rpc-primitives.test.ts +11 -0
  305. package/src/server/lib/omp/rpc/session-registration.ts +7 -2
  306. package/src/server/lib/omp/rpc/session-registry.test.ts +2 -1
  307. package/src/server/lib/omp/rpc/session-registry.ts +74 -5
  308. package/src/server/lib/omp/session/acp-rows.server.ts +79 -0
  309. package/src/server/lib/omp/session/delete-flow.server.ts +15 -8
  310. package/src/server/lib/omp/session/delete.server.ts +12 -0
  311. package/src/server/lib/omp/session/sidebar-data.harness.test.ts +247 -0
  312. package/src/server/lib/omp/session/sidebar-data.server.ts +56 -3
  313. package/src/server/lib/queue/delivery.server.test.ts +4 -2
  314. package/src/server/lib/queue/payload.test.ts +67 -0
  315. package/src/server/lib/queue/payload.ts +9 -3
  316. package/src/server/lib/realtime/signals.server.test.ts +99 -0
  317. package/src/server/lib/realtime/signals.server.ts +25 -5
  318. package/src/server/lib/realtime/topics/session-data.server.ts +29 -0
  319. package/src/server/lib/realtime/topics/session.server.ts +3 -3
  320. package/src/server/routes/agent/command-resume.test.ts +77 -0
  321. package/src/server/routes/agent/command.test.ts +243 -2
  322. package/src/server/routes/agent/command.ts +78 -15
  323. package/src/server/routes/agent/harness-command.ts +133 -0
  324. package/src/server/routes/agent/new.ts +63 -1
  325. package/src/server/routes/chat/rewind.test.ts +147 -0
  326. package/src/server/routes/chat/rewind.ts +29 -7
  327. package/src/server/routes/chat/session.test.ts +240 -0
  328. package/src/server/routes/chat/session.ts +96 -4
  329. package/src/server/routes/harness/add-provider.test.ts +233 -0
  330. package/src/server/routes/harness/import-action.ts +272 -0
  331. package/src/server/routes/harness/import.test.ts +196 -0
  332. package/src/server/routes/harness/index.ts +13 -0
  333. package/src/server/routes/harness/root.ts +280 -0
  334. package/src/server/routes/harness/toggle.test.ts +127 -0
  335. package/src/server/routes/harness/update.ts +259 -0
  336. package/src/server/routes/harness/versions.test.ts +148 -0
  337. package/src/server/routes/harness/versions.ts +105 -0
  338. package/src/server/routes/index.ts +2 -0
  339. package/src/server/routes/sessions/delete-acp.test.ts +227 -0
  340. package/src/server/routes/sessions/queue.ts +7 -2
  341. package/src/server/routes/sessions/routes-queue.test.ts +52 -0
  342. package/src/server/routes/sessions/routes.test.ts +47 -13
  343. package/src/server/routes/sessions/session.ts +35 -0
  344. package/src/server/routes/settings/commands-harness.test.ts +92 -0
  345. package/src/server/routes/settings/commands.ts +26 -0
  346. package/src/server/routes/settings/model-override.ts +5 -2
  347. package/src/server/routes/settings/provider-entry.ts +2 -2
  348. package/src/server/routes/settings/provider-model.ts +2 -2
  349. package/src/server/routes/settings/provider-models.ts +2 -2
  350. package/src/server/routes/settings/provider-refresh.ts +6 -4
  351. package/src/server/routes/settings/providers.ts +3 -1
  352. package/src/server/routes/settings/settings-config-routes.test.ts +10 -2
  353. package/src/server/routes/settings/skills.ts +12 -0
  354. package/src/shared/lib/chat/ask-form/fields.ts +76 -0
  355. package/src/shared/lib/chat/ask-form/index.ts +323 -0
  356. package/src/shared/lib/chat/ask-form/tokens.ts +199 -0
  357. package/src/shared/lib/chat/ask-form/types.ts +43 -0
  358. package/src/shared/lib/chat/ask-form.test.ts +137 -0
  359. package/src/shared/lib/chat/ask-questions.test.ts +65 -1
  360. package/src/shared/lib/chat/ask-questions.ts +51 -145
  361. package/src/shared/lib/chat/ask-results.ts +198 -0
  362. package/src/shared/lib/chat/composer/client.ts +20 -8
  363. package/src/shared/lib/chat/context/usage.test.ts +8 -4
  364. package/src/shared/lib/chat/context/usage.ts +17 -3
  365. package/src/shared/lib/chat/omp/abort.test.ts +61 -0
  366. package/src/shared/lib/chat/omp/abort.ts +8 -2
  367. package/src/shared/lib/chat/omp/tool-frames.test.ts +23 -0
  368. package/src/shared/lib/chat/omp/tool-frames.ts +12 -2
  369. package/src/shared/lib/chat/timeline/omp-callbacks.ts +13 -1
  370. package/src/shared/lib/chat/timeline/prompt-error.test.ts +146 -0
  371. package/src/shared/lib/chat/timeline/prompt-error.ts +88 -0
  372. package/src/shared/lib/chat/tool/summary-wait.test.ts +18 -8
  373. package/src/shared/lib/chat/tool/wait-facts.ts +14 -8
  374. package/src/shared/lib/harness/brand-color.test.ts +66 -0
  375. package/src/shared/lib/harness/brand-color.ts +96 -0
  376. package/src/shared/lib/harness/catalog.test.ts +88 -0
  377. package/src/shared/lib/harness/catalog.ts +169 -0
  378. package/src/shared/lib/harness/config-fields.test.ts +139 -0
  379. package/src/shared/lib/harness/config-fields.ts +168 -0
  380. package/src/shared/lib/harness/config.test.ts +153 -0
  381. package/src/shared/lib/harness/config.ts +206 -0
  382. package/src/shared/lib/harness/dialects.test.ts +140 -0
  383. package/src/shared/lib/harness/dialects.ts +249 -0
  384. package/src/shared/lib/harness/enabled.test.ts +79 -0
  385. package/src/shared/lib/harness/enabled.ts +72 -0
  386. package/src/shared/lib/harness/menu.test.ts +94 -0
  387. package/src/shared/lib/harness/menu.ts +88 -0
  388. package/src/shared/lib/harness/provider-facts.test.ts +199 -0
  389. package/src/shared/lib/harness/provider-facts.ts +349 -0
  390. package/src/shared/lib/harness/provider-slug.ts +46 -0
  391. package/src/shared/lib/harness/providers.ts +175 -0
  392. package/src/shared/lib/harness/rewind.ts +24 -0
  393. package/src/shared/lib/harness/status.test.ts +158 -0
  394. package/src/shared/lib/harness/status.ts +112 -0
  395. package/src/shared/lib/harness/update-plan.test.ts +163 -0
  396. package/src/shared/lib/harness/update-plan.ts +140 -0
  397. package/src/shared/lib/harness/updates.test.ts +106 -0
  398. package/src/shared/lib/harness/updates.ts +177 -0
  399. package/src/shared/lib/icons/icon-paint-authority.test.ts +16 -4
  400. package/src/shared/lib/icons/icon-paint-authority.ts +57 -12
  401. package/src/shared/lib/icons/icon-paint-bucket.test.ts +84 -0
  402. package/src/shared/lib/icons/icon-paint-css.test.ts +23 -25
  403. package/src/shared/lib/icons/icon-paint-css.ts +69 -55
  404. package/src/shared/lib/icons/icon-paint-harness.test.ts +73 -0
  405. package/src/shared/lib/icons/icon-paint-harness.ts +75 -0
  406. package/src/shared/lib/icons/icon-paint-ink.ts +108 -0
  407. package/src/shared/lib/icons/icon-paint-panel.ts +19 -4
  408. package/src/shared/lib/icons/icon-paint-weight.ts +21 -2
  409. package/src/shared/lib/icons/icon-tone.ts +118 -21
  410. package/src/shared/lib/icons/tint-hues.generated.ts +100 -284
  411. package/src/shared/lib/icons/tint-tones.test.ts +79 -25
  412. package/src/shared/lib/icons/tint.ts +66 -6
  413. package/src/shared/lib/models/client.ts +10 -1
  414. package/src/shared/lib/models/provider/vendors.ts +72 -0
  415. package/src/shared/lib/omp/config/schema.test.ts +36 -0
  416. package/src/shared/lib/omp/dialog-methods.ts +4 -3
  417. package/src/shared/lib/omp/session/messages-map-trace.test.ts +42 -0
  418. package/src/shared/lib/omp/session/messages-map.ts +6 -1
  419. package/src/shared/lib/omp/session/parse-message-blocks-toolcall.test.ts +8 -0
  420. package/src/shared/lib/omp/session/parse-message-blocks.ts +6 -1
  421. package/src/shared/lib/omp/session/shell-trace.test.ts +69 -0
  422. package/src/shared/lib/omp/session/shell-trace.ts +63 -0
  423. package/src/shared/lib/omp/session/sidebar.ts +37 -10
  424. package/src/shared/lib/omp/session/wait-idle.test.ts +47 -0
  425. package/src/shared/lib/omp/session/wait-idle.ts +93 -0
  426. package/src/shared/lib/omp/session/wait.test.ts +34 -33
  427. package/src/shared/lib/omp/session/wait.ts +25 -39
  428. package/src/shared/lib/settings/sections.ts +24 -0
  429. package/src/shared/lib/theme/css.ts +2 -0
  430. package/src/shared/lib/theme/ink-scale.ts +21 -1
  431. package/src/shared/lib/theme/theme.test.ts +25 -9
  432. package/src/shared/lib/ui/safe-area.test.ts +28 -0
  433. package/src/shared/lib/ui/safe-area.ts +42 -0
  434. package/src/shared/lib/ui/toast-duration.test.ts +74 -0
  435. package/src/shared/lib/ui/toast-duration.ts +70 -0
  436. package/src/shared/types/harness-version.ts +59 -0
  437. package/src/shared/types/harness.ts +201 -0
  438. package/src/shared/types/index.ts +2 -0
  439. package/src/shared/types/omp/agent.ts +13 -0
  440. package/src/shared/types/settings/state.ts +10 -1
  441. package/src/shared/types/workspace.ts +10 -0
  442. package/src/test-support/env.ts +38 -0
  443. package/src/test-support/file-explorer-render.test-util.ts +37 -0
  444. package/src/test-support/file-explorer.test-util.ts +20 -18
  445. package/src/test-support/harness-table.test-util.ts +108 -0
  446. package/dist/client/static/js/index-7ppta1pb.css +0 -1
@@ -0,0 +1,134 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * The ACP prompt/approval payload helpers.
8
+ *
9
+ * Split out of `session.ts` so the driver holds only the session state machine.
10
+ * Both functions here encode a wire decision that is easy to get wrong:
11
+ *
12
+ * - a prompt is `ContentBlock[]`, images FIRST so the text is the final block
13
+ * the model reads (a trailing image is what some agents truncate);
14
+ * - the approval dialog's text prefers the tool's own `rawInput.command`, since
15
+ * a shell approval whose body is only a title gives the reader nothing to
16
+ * approve.
17
+ */
18
+
19
+ import { acpOptionValues, type AcpConfigOption } from '@/server/lib/harness/acp/protocol';
20
+
21
+ /** The selector in a `configOptions` list for one ACP category. */
22
+ export function configOption(options: AcpConfigOption[], category: string): AcpConfigOption | undefined {
23
+ return options.find((option) => option.category === category);
24
+ }
25
+
26
+ /**
27
+ * The provider/model a `model` selector names, read off its `currentValue`.
28
+ *
29
+ * ACP publishes the model as `provider/modelId`, and the FIRST slash is the
30
+ * separator because a model id may contain one. A value with no slash names no
31
+ * provider, so `fallbackProvider` stands in for it — the same fallback
32
+ * `setConfig` has always used, kept here so the session's start-up seed, its
33
+ * config writes and `webState()` cannot disagree about what a selector says.
34
+ */
35
+ export function modelFromOption(
36
+ option: AcpConfigOption | undefined,
37
+ fallbackProvider: string,
38
+ ): { provider: string; modelId: string } | null {
39
+ const current = option?.currentValue;
40
+ if (typeof current !== 'string' || current.length === 0) return null;
41
+ // deepseek-harness-acp publishes the model as a stringified `[provider, id]`
42
+ // array (measured: `["deepseek-official","deepseek-v4-flash"]`), so the run
43
+ // indicator would otherwise name the harness as the provider and print the
44
+ // array as the model. The LIST keeps the agent's own value — that is what a
45
+ // selection must write back — only the reported identity is normalised.
46
+ const pair = parseModelPair(current);
47
+ if (pair) return pair;
48
+ const slash = current.indexOf('/');
49
+ return slash > 0
50
+ ? { provider: current.slice(0, slash), modelId: current.slice(slash + 1) }
51
+ : { provider: fallbackProvider, modelId: current };
52
+ }
53
+
54
+ /** `[provider, id]` as JSON text, or null for any other spelling. */
55
+ function parseModelPair(value: string): { provider: string; modelId: string } | null {
56
+ const trimmed = value.trim();
57
+ if (!trimmed.startsWith('[')) return null;
58
+ try {
59
+ const parsed: unknown = JSON.parse(trimmed);
60
+ if (Array.isArray(parsed) && parsed.length === 2 && parsed.every((part) => typeof part === 'string')) {
61
+ return { provider: String(parsed[0]), modelId: String(parsed[1]) };
62
+ }
63
+ } catch {
64
+ // Not JSON: the agent's own string is the truth.
65
+ }
66
+ return null;
67
+ }
68
+
69
+ /** A prompt in ACP content-block form. */
70
+ export function promptBlocks(message: string, images: unknown): unknown[] {
71
+ const blocks: unknown[] = [];
72
+ if (Array.isArray(images)) {
73
+ for (const image of images) {
74
+ if (!image || typeof image !== 'object') continue;
75
+ if (!('data' in image) || typeof image.data !== 'string') continue;
76
+ const mimeType = 'mimeType' in image && typeof image.mimeType === 'string' ? image.mimeType : 'image/png';
77
+ blocks.push({ type: 'image', data: image.data, mimeType });
78
+ }
79
+ }
80
+ blocks.push({ type: 'text', text: message });
81
+ return blocks;
82
+ }
83
+
84
+ /** What the approval dialog says, from the tool call the agent reported. */
85
+ export function permissionText(toolCall: Record<string, unknown> | undefined): string {
86
+ const rawInput = toolCall?.rawInput;
87
+ if (rawInput && typeof rawInput === 'object' && 'command' in rawInput && typeof rawInput.command === 'string') {
88
+ return `$ ${rawInput.command}`;
89
+ }
90
+ const title = toolCall?.title;
91
+ return typeof title === 'string' ? title : 'This action needs your approval';
92
+ }
93
+
94
+ /** What a session may write into the agent's config selectors. */
95
+ export interface ConfigSelections {
96
+ model: { provider: string; modelId: string } | null;
97
+ thinking: string | null;
98
+ mode: string | null;
99
+ }
100
+
101
+ /** The subset of a session the selection writes need. */
102
+ export interface ConfigSelectionHost {
103
+ configOptions: AcpConfigOption[];
104
+ runModel: { provider: string; modelId: string } | null;
105
+ setConfig(configId: string, value: string | boolean): Promise<unknown>;
106
+ }
107
+
108
+ /**
109
+ * Apply the model/thinking/mode picks with one config write each.
110
+ *
111
+ * A selector the agent does not publish is SKIPPED, never guessed: an agent with
112
+ * 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
+ */
116
+ export async function applySelections(host: ConfigSelectionHost, wanted: ConfigSelections): Promise<void> {
117
+ const model = configOption(host.configOptions, 'model');
118
+ if (model && wanted.model) {
119
+ const exact = `${wanted.model.provider}/${wanted.model.modelId}`;
120
+ const values = acpOptionValues(model);
121
+ const match = values.find((value) => value === exact) ?? values.find((value) => value === wanted.model?.modelId);
122
+ // `session/set_config_option` keys on the selector's ID, which an agent may
123
+ // name anything; the category only says what the selector MEANS.
124
+ if (match) await host.setConfig(model.id, match).catch(() => {});
125
+ }
126
+ const thinking = configOption(host.configOptions, 'thought_level');
127
+ if (thinking && wanted.thinking && acpOptionValues(thinking).includes(wanted.thinking)) {
128
+ await host.setConfig(thinking.id, wanted.thinking).catch(() => {});
129
+ }
130
+ const mode = configOption(host.configOptions, 'mode');
131
+ if (mode && wanted.mode && acpOptionValues(mode).includes(wanted.mode)) {
132
+ await host.setConfig(mode.id, wanted.mode).catch(() => {});
133
+ }
134
+ }
@@ -0,0 +1,162 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * The Agent Client Protocol wire shapes this host sends and reads.
8
+ *
9
+ * ONLY the fields Kabmo uses are typed. ACP is an open protocol with `_meta`
10
+ * escape hatches and per-agent extras; typing the full schema would make every
11
+ * adapter's newest field a compile error here, and the whole point of the
12
+ * transport is that a new agent works without touching this file.
13
+ *
14
+ * Two rules the types encode, both measured against real agents:
15
+ *
16
+ * - `session/update` is the ONLY stream of events. There is no `message_end`
17
+ * and no per-turn event envelope, so `messageId` is what delimits messages.
18
+ * - `tool_call_update` is a PATCH. Every field but `toolCallId` is optional and
19
+ * an omitted field means "unchanged", never "cleared".
20
+ */
21
+
22
+ /** A JSON-RPC id. ACP forbids `null`, and replies echo whatever was sent. */
23
+ export type AcpId = string | number;
24
+
25
+ export interface AcpRequest {
26
+ jsonrpc: '2.0';
27
+ id: AcpId;
28
+ method: string;
29
+ params?: unknown;
30
+ }
31
+
32
+ export interface AcpNotification {
33
+ jsonrpc: '2.0';
34
+ method: string;
35
+ params?: unknown;
36
+ }
37
+
38
+ export interface AcpError {
39
+ code: number;
40
+ message: string;
41
+ data?: unknown;
42
+ }
43
+
44
+ export interface AcpResponse {
45
+ jsonrpc: '2.0';
46
+ id: AcpId;
47
+ result?: unknown;
48
+ error?: AcpError;
49
+ }
50
+
51
+ /** ACP `ToolKind`. The presentation category, and the mapper's renderer key. */
52
+ export type AcpToolKind =
53
+ | 'read'
54
+ | 'edit'
55
+ | 'delete'
56
+ | 'move'
57
+ | 'search'
58
+ | 'execute'
59
+ | 'think'
60
+ | 'fetch'
61
+ | 'switch_mode'
62
+ | 'other';
63
+
64
+ export type AcpToolStatus = 'pending' | 'in_progress' | 'completed' | 'failed';
65
+
66
+ export interface AcpToolLocation {
67
+ path: string;
68
+ line?: number;
69
+ }
70
+
71
+ /** One `tool_call` / `tool_call_update` payload. */
72
+ export interface AcpToolCallUpdate {
73
+ sessionUpdate: 'tool_call' | 'tool_call_update';
74
+ toolCallId: string;
75
+ title?: string;
76
+ name?: string;
77
+ kind?: AcpToolKind;
78
+ status?: AcpToolStatus;
79
+ content?: unknown[];
80
+ locations?: AcpToolLocation[];
81
+ rawInput?: unknown;
82
+ rawOutput?: unknown;
83
+ }
84
+
85
+ export interface AcpContentBlock {
86
+ type: 'text' | 'image' | 'audio' | 'resource' | 'resource_link';
87
+ text?: string;
88
+ data?: string;
89
+ mimeType?: string;
90
+ }
91
+
92
+ /** `session/update` variants. Unknown variants arrive as `{ sessionUpdate: string }`. */
93
+ export interface AcpSessionUpdate {
94
+ sessionUpdate: string;
95
+ [key: string]: unknown;
96
+ }
97
+
98
+ export interface AcpSessionsUpdate extends AcpSessionUpdate {
99
+ sessionUpdate: 'available_commands_update';
100
+ availableCommands?: { name?: string; description?: string; input?: { hint?: string } | null }[];
101
+ }
102
+
103
+ export interface AcpConfigOption {
104
+ id: string;
105
+ name?: string;
106
+ category?: string;
107
+ type?: string;
108
+ currentValue?: string | boolean;
109
+ options?: ({ value: string; name?: string; description?: string } | { group: string; name?: string; options: { value: string; name?: string }[] })[];
110
+ }
111
+
112
+ export interface AcpSessionNewResult {
113
+ sessionId: string;
114
+ configOptions?: AcpConfigOption[];
115
+ modes?: unknown;
116
+ }
117
+
118
+ export interface AcpInitializeResult {
119
+ protocolVersion: number;
120
+ agentInfo?: { name?: string; title?: string; version?: string };
121
+ agentCapabilities?: {
122
+ loadSession?: boolean;
123
+ promptCapabilities?: { image?: boolean; audio?: boolean; embeddedContext?: boolean };
124
+ mcpCapabilities?: { http?: boolean; sse?: boolean };
125
+ sessionCapabilities?: Record<string, unknown>;
126
+ _meta?: Record<string, unknown>;
127
+ };
128
+ authMethods?: { id: string; name: string; description?: string; type?: string }[];
129
+ _meta?: Record<string, unknown>;
130
+ }
131
+
132
+ export interface AcpSessionInfo {
133
+ sessionId: string;
134
+ cwd: string;
135
+ title?: string;
136
+ updatedAt?: string;
137
+ _meta?: Record<string, unknown>;
138
+ }
139
+
140
+ /** `session/request_permission` — the approval gate's wire form. */
141
+ export interface AcpPermissionRequest {
142
+ sessionId: string;
143
+ toolCall?: { toolCallId?: string; title?: string; kind?: AcpToolKind; status?: AcpToolStatus; rawInput?: unknown; content?: unknown[] };
144
+ options: { optionId: string; name?: string; kind?: string }[];
145
+ }
146
+
147
+ /** Flatten a select option list into values, ignoring groups. */
148
+ export function acpOptionValues(option: AcpConfigOption): string[] {
149
+ const values: string[] = [];
150
+ for (const entry of option.options ?? []) {
151
+ if ('value' in entry) values.push(entry.value);
152
+ else for (const nested of entry.options) values.push(nested.value);
153
+ }
154
+ return values;
155
+ }
156
+
157
+ /** The text of one content block, or '' for a non-text block. */
158
+ export function acpBlockText(block: unknown): string {
159
+ if (!block || typeof block !== 'object') return '';
160
+ const candidate = block as { type?: unknown; text?: unknown };
161
+ return candidate.type === 'text' && typeof candidate.text === 'string' ? candidate.text : '';
162
+ }
@@ -0,0 +1,73 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * A config write must leave the session naming the model the agent is actually
8
+ * serving.
9
+ *
10
+ * The protocol says `session/set_config_option` replies with the complete list,
11
+ * and the agent's `currentValue` is authoritative (an alias or fallback may
12
+ * differ from the request). This suite pins the fallback for a harness that
13
+ * answers `{}` — the shape that left a chat's footer and sidebar row on the
14
+ * model from `session/new` for the rest of its life.
15
+ */
16
+
17
+ import { describe, expect, test } from 'bun:test';
18
+ import { adoptConfigAnswer, adoptConfigList, publishConfigChange } from '@/server/lib/harness/acp/session-config';
19
+ import type { AcpConfigOption } from '@/server/lib/harness/acp/protocol';
20
+
21
+ const option = (id: string, category: string, currentValue: string, values: string[]): AcpConfigOption => ({
22
+ id,
23
+ category,
24
+ type: 'select',
25
+ currentValue,
26
+ options: values.map((value) => ({ value })),
27
+ });
28
+
29
+ const target = () => ({
30
+ harness: 'claude' as const,
31
+ configOptions: [option('sel-model', 'model', 'p/old', ['p/old', 'p/new'])],
32
+ runModel: { provider: 'p', modelId: 'old' },
33
+ });
34
+
35
+ describe('ACP config adoption', () => {
36
+ test('a reply that omits the list adopts the value that was written', () => {
37
+ const session = target();
38
+ adoptConfigAnswer(session, {}, { configId: 'sel-model', value: 'p/new' });
39
+ expect(session.configOptions[0]?.currentValue).toBe('p/new');
40
+ expect(session.runModel).toEqual({ provider: 'p', modelId: 'new' });
41
+ });
42
+
43
+ test('the agent’s resolved list wins over the request', () => {
44
+ const session = target();
45
+ adoptConfigAnswer(
46
+ session,
47
+ { configOptions: [option('sel-model', 'model', 'p/resolved', ['p/old', 'p/new', 'p/resolved'])] },
48
+ { configId: 'sel-model', value: 'p/new' },
49
+ );
50
+ expect(session.runModel).toEqual({ provider: 'p', modelId: 'resolved' });
51
+ });
52
+
53
+ test('the array-shaped value some harnesses publish keeps its provider', () => {
54
+ const session = target();
55
+ adoptConfigList(session, [option('sel-model', 'model', '["kenari","deepseek-v4-flash"]', ['["kenari","deepseek-v4-flash"]'])]);
56
+ expect(session.runModel).toEqual({ provider: 'kenari', modelId: 'deepseek-v4-flash' });
57
+ });
58
+
59
+ test('a pushed list announces the identity the client must re-read', () => {
60
+ const emitted: Array<Record<string, unknown> & { type: string }> = [];
61
+ const session = {
62
+ ...target(),
63
+ sessionId: 's1',
64
+ isStreaming: false,
65
+ emit: (event: Record<string, unknown> & { type: string }) => {
66
+ emitted.push(event);
67
+ },
68
+ };
69
+ adoptConfigList(session, [option('sel-model', 'model', 'p/new', ['p/new'])]);
70
+ publishConfigChange(session);
71
+ expect(emitted).toContainEqual({ type: 'model_changed' });
72
+ });
73
+ });
@@ -0,0 +1,148 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * The two config/approval writes an ACP session makes on someone else's behalf,
8
+ * split out of the session because neither needs its state: one adopts the
9
+ * agent's answer to a config write, the other answers a parked approval dialog.
10
+ *
11
+ * ## Why the config answer is adopted rather than assumed
12
+ *
13
+ * `session/set_config_option` replies with the WHOLE config list, and the model
14
+ * selector's `currentValue` is the model the agent RESOLVED — an alias or a
15
+ * fallback can differ from what was asked for. The run indicator names the model
16
+ * from this field, so a session that kept its own request would announce a model
17
+ * the answer did not come from.
18
+ *
19
+ * A harness that answers with no list is the exception: the write succeeded, so
20
+ * the requested value is adopted and a later `config_option_update` corrects it.
21
+ * Leaving the session on its `session/new` model made the footer and the sidebar
22
+ * row name the first model the chat ever picked for the rest of its life.
23
+ *
24
+ * ## Why every approval exit answers
25
+ *
26
+ * The agent is PARKED on `session/request_permission` until it hears back: a
27
+ * chosen option becomes `{outcome:"selected"}`, and a dialog id nobody knows
28
+ * becomes `cancelled`. Returning silently would hang the turn — the failure this
29
+ * module exists to make impossible.
30
+ */
31
+
32
+ import { configOption, modelFromOption } from '@/server/lib/harness/acp/prompt';
33
+ import type { AcpConfigOption } from '@/server/lib/harness/acp/protocol';
34
+ import type { PendingPermissions } from '@/server/lib/harness/acp/permissions';
35
+ import { markStreamModel } from '@/shared/lib/omp/session/stream-state.server';
36
+ import type { HarnessId } from '@/shared/lib/harness/catalog';
37
+ import type { AgentEvent } from '@/server/lib/omp/rpc/constants';
38
+
39
+ /** The fields a config answer rewrites. */
40
+ export interface AcpConfigTarget {
41
+ readonly harness: HarnessId;
42
+ configOptions: AcpConfigOption[];
43
+ runModel: { provider: string; modelId: string } | null;
44
+ }
45
+
46
+ /** The target plus what publishing a change needs: a live run row to rename and
47
+ * a frame stream the client folds. */
48
+ export interface AcpConfigNotice extends AcpConfigTarget {
49
+ readonly sessionId: string;
50
+ readonly isStreaming: boolean;
51
+ emit(event: Record<string, unknown> & { type: string }): void;
52
+ }
53
+
54
+ /** Write the agent's COMPLETE config list into the session. */
55
+ export function adoptConfigList(target: AcpConfigTarget, options: AcpConfigOption[]): void {
56
+ target.configOptions = options;
57
+ const resolved = modelFromOption(configOption(options, 'model'), target.harness);
58
+ if (resolved) target.runModel = resolved;
59
+ }
60
+
61
+ /** Adopt `session/set_config_option`'s reply when it carries a config list. */
62
+ export function adoptConfigOptions(target: AcpConfigTarget, result: unknown): boolean {
63
+ if (!result || typeof result !== 'object' || !('configOptions' in result) || !Array.isArray(result.configOptions)) {
64
+ return false;
65
+ }
66
+ adoptConfigList(target, result.configOptions as AcpConfigOption[]);
67
+ return true;
68
+ }
69
+
70
+ /**
71
+ * Adopt a config WRITE even when the agent omitted the reply list.
72
+ *
73
+ * The protocol says the reply MUST carry the complete list, and every measured
74
+ * adapter does — but a harness that answers `{}` left the session naming the
75
+ * model from `session/new`, so the run footer and the sidebar row reported the
76
+ * first model the chat ever picked for the rest of its life. The write itself
77
+ * succeeded, so the requested value is the best state we have; a later
78
+ * `config_option_update` (or the next reply) replaces it with the agent's own.
79
+ */
80
+ export function adoptConfigAnswer(
81
+ target: AcpConfigTarget,
82
+ result: unknown,
83
+ requested: { configId: string; value: string | boolean },
84
+ ): void {
85
+ if (adoptConfigOptions(target, result)) return;
86
+ if (!target.configOptions.some((option) => option.id === requested.configId)) return;
87
+ adoptConfigList(
88
+ target,
89
+ target.configOptions.map((option) =>
90
+ option.id === requested.configId ? { ...option, currentValue: requested.value } : option,
91
+ ),
92
+ );
93
+ }
94
+
95
+ /**
96
+ * Announce a written config option on the session's own frame stream — the
97
+ * vocabulary omp already uses, so the client's existing `model_changed`
98
+ * handler refreshes the session metadata (and thus the footer/composer) with
99
+ * no second path. A live run row is renamed here too: a `set_model` can land
100
+ * while a turn is streaming, and the sidebar/indicator read that row, not
101
+ * `get_state`.
102
+ */
103
+ export function publishConfigChange(target: AcpConfigNotice, configId?: string): void {
104
+ if (target.runModel && target.isStreaming) {
105
+ void markStreamModel(target.sessionId, target.runModel).catch(() => {});
106
+ }
107
+ const written = configId ? target.configOptions.find((option) => option.id === configId) : null;
108
+ // No id means the agent pushed a fresh list (`config_option_update`): any of
109
+ // its selectors may have moved, so name both known identities.
110
+ if (!written || written.category === 'model') {
111
+ if (target.runModel) target.emit({ type: 'model_changed' });
112
+ }
113
+ const thinking = configOption(target.configOptions, 'thought_level');
114
+ if ((!written || written.category === 'thought_level') && typeof thinking?.currentValue === 'string') {
115
+ target.emit({ type: 'thinking_level_changed', thinkingLevel: thinking.currentValue });
116
+ }
117
+ }
118
+
119
+ /** The model fields the footer/indicator read, or the frame unchanged. */
120
+ export function stampMessageModel(event: AgentEvent, model: { provider: string; modelId: string } | null): AgentEvent {
121
+ if (!model) return event;
122
+ if (event.type !== 'message_update' && event.type !== 'message_end') return event;
123
+ if (!event.message || typeof event.message !== 'object') return event;
124
+ return {
125
+ ...event,
126
+ message: { ...event.message, model: model.modelId, provider: model.provider },
127
+ };
128
+ }
129
+
130
+ /** The process slice answering a dialog needs; `AcpProcess` satisfies it. */
131
+ export interface AcpResponder {
132
+ respond(id: string | number, result: unknown): void;
133
+ }
134
+
135
+ /** Answer one parked approval dialog. Unknown ids are ignored, never guessed. */
136
+ export function settlePermissionDialog(
137
+ permissions: PendingPermissions,
138
+ responder: AcpResponder,
139
+ dialogId: string,
140
+ confirmed: boolean,
141
+ ): void {
142
+ const entry = permissions.take(dialogId);
143
+ if (!entry) return;
144
+ const chosen = permissions.optionFor(entry, confirmed);
145
+ responder.respond(entry.id, {
146
+ outcome: chosen ? { outcome: 'selected', optionId: chosen.optionId } : { outcome: 'cancelled' },
147
+ });
148
+ }
@@ -0,0 +1,71 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * The session FACTS an ACP agent publishes about itself, parsed.
8
+ *
9
+ * These are the pieces of `session/update` that arrive BETWEEN turns —
10
+ * `available_commands_update`, `usage_update` and `plan` — and they are the
11
+ * reason the turn gate in `AcpSession.onNotification` cannot simply drop
12
+ * everything while no turn is open: applying it to these made the composer's `/`
13
+ * pool and the context panel describe a different agent entirely (measured: no
14
+ * commands at all, and a context panel that never learned the agent reports
15
+ * usage).
16
+ *
17
+ * Pure, and separate from the session, because each is a rule about ACP's wire
18
+ * shape rather than about Kabmo's state: `parseAgentCommands` turns the
19
+ * agent's own list into the shape the composer already reads, and
20
+ * `metadataCapabilities` records what the agent's own frames PROVE it supports
21
+ * instead of assuming a capability table.
22
+ */
23
+
24
+ import type { HarnessCapabilities } from '@/server/lib/harness/capabilities';
25
+
26
+ /** One command an agent publishes, in Kabmo's command shape. */
27
+ export interface AgentCommand {
28
+ name: string;
29
+ description?: string;
30
+ inputHint?: string;
31
+ }
32
+
33
+ /**
34
+ * The agent's own `/` pool, from one `available_commands_update`.
35
+ *
36
+ * Entries without a usable name are dropped rather than rendered as a blank row,
37
+ * and an absent `input.hint` stays absent: a command that takes no argument must
38
+ * not claim to.
39
+ */
40
+ export function parseAgentCommands(update: Record<string, unknown>): AgentCommand[] {
41
+ const published = Array.isArray(update.availableCommands) ? update.availableCommands : [];
42
+ return published.flatMap((entry) => {
43
+ if (!entry || typeof entry !== 'object') return [];
44
+ const command = entry as Record<string, unknown>;
45
+ const name = typeof command.name === 'string' ? command.name : '';
46
+ if (!name) return [];
47
+ const input = command.input && typeof command.input === 'object' ? command.input as Record<string, unknown> : undefined;
48
+ const hint = typeof input?.hint === 'string' ? input.hint : undefined;
49
+ return [{
50
+ name,
51
+ ...(typeof command.description === 'string' ? { description: command.description } : {}),
52
+ ...(hint ? { inputHint: hint } : {}),
53
+ }];
54
+ });
55
+ }
56
+
57
+ /**
58
+ * The capability flag a metadata frame PROVES, or the record unchanged.
59
+ *
60
+ * Returning the same object keeps an identity check meaningful at the call site,
61
+ * and it is also the honest answer: a frame Kabmo does not recognise adds no
62
+ * capability.
63
+ */
64
+ export function metadataCapabilities(
65
+ capabilities: HarnessCapabilities,
66
+ kind: string,
67
+ ): HarnessCapabilities {
68
+ if (kind === 'usage_update') return { ...capabilities, hasUsage: true };
69
+ if (kind === 'plan') return { ...capabilities, hasPlan: true };
70
+ return capabilities;
71
+ }
@@ -0,0 +1,89 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * The ACP handshake: `initialize`, then `session/new` (or `session/load` when a
8
+ * chat is being restored), then the selections the composer asked for.
9
+ *
10
+ * Split out of `AcpSession` because none of it needs the session's own state: it
11
+ * needs the process, the four fields it seeds, and the picks — so it takes those
12
+ * as arguments and writes them back on the target it is given.
13
+ *
14
+ * Two details are load-bearing and were each a bug:
15
+ *
16
+ * - `session/load` REPLAYS the transcript as `session/update` frames, which the
17
+ * mapper has already turned into rows. The reply carries the (possibly
18
+ * unchanged) config list, and a load that answers no list still knows its
19
+ * session id — hence the `reloaded ?? { sessionId }` fallback.
20
+ * - the run's model is SEEDED from the selector the agent already reports.
21
+ * Nothing has been written yet at this point, so without the seed `runModel`
22
+ * stayed null until some later config write, and `get_state` then answered
23
+ * `provider: 'omp-acp'` (the harness id) with the whole `provider/model`
24
+ * string as the model id — which is what the generating indicator names.
25
+ */
26
+
27
+ import { newSessionAfterActivation } from '@/server/lib/harness/acp/activation';
28
+ import { applySelections, configOption, modelFromOption } from '@/server/lib/harness/acp/prompt';
29
+ import { capabilitiesFrom } from '@/server/lib/harness/launch';
30
+ import type {
31
+ AcpConfigOption,
32
+ AcpInitializeResult,
33
+ AcpSessionNewResult,
34
+ } from '@/server/lib/harness/acp/protocol';
35
+ import type { HarnessCapabilities } from '@/server/lib/harness/capabilities';
36
+ import type { HarnessId } from '@/shared/lib/harness/catalog';
37
+
38
+ /** The process slice a handshake drives; `AcpProcess` satisfies it as-is. */
39
+ export interface AcpHandshakeProcess {
40
+ initialize(params: Record<string, unknown>, timeoutMs?: number): Promise<AcpInitializeResult>;
41
+ loadSession(sessionId: string, cwd: string, timeoutMs?: number): Promise<unknown>;
42
+ newSession(cwd: string, timeoutMs?: number): Promise<AcpSessionNewResult>;
43
+ }
44
+
45
+ /** The session fields a handshake seeds. */
46
+ export interface AcpHandshakeTarget {
47
+ readonly cwd: string;
48
+ readonly harness: HarnessId;
49
+ sessionId: string;
50
+ configOptions: AcpConfigOption[];
51
+ runModel: { provider: string; modelId: string } | null;
52
+ capabilities: HarnessCapabilities;
53
+ setConfig(configId: string, value: string | boolean): Promise<unknown>;
54
+ }
55
+
56
+ /** The picks the composer sent for a brand-new session. */
57
+ export interface AcpHandshakeSelections {
58
+ model: { provider: string; modelId: string } | null;
59
+ thinking: string | null;
60
+ mode: string | null;
61
+ }
62
+
63
+ export async function handshakeAcpSession(
64
+ target: AcpHandshakeTarget,
65
+ proc: AcpHandshakeProcess,
66
+ wanted: AcpHandshakeSelections,
67
+ sessionIdToLoad?: string,
68
+ ): Promise<void> {
69
+ const init = await proc.initialize({}, 60_000);
70
+ /** opencode's plugin activation gate: the first `session/new`s refuse with
71
+ * `ServiceUnavailableError` until the agent's plugins finish booting. */
72
+ const newSession = (cwd: string, timeoutMs?: number) =>
73
+ newSessionAfterActivation(target.harness, cwd, (dir, ms) => proc.newSession(dir, ms), {
74
+ ...(timeoutMs !== undefined ? { perAttemptMs: timeoutMs } : {}),
75
+ });
76
+ let session: AcpSessionNewResult;
77
+ if (sessionIdToLoad) {
78
+ await proc.loadSession(sessionIdToLoad, target.cwd, 120_000);
79
+ const reloaded = await newSession(target.cwd).catch(() => null);
80
+ session = reloaded ?? { sessionId: sessionIdToLoad };
81
+ } else {
82
+ session = await newSession(target.cwd, 120_000);
83
+ }
84
+ target.sessionId = session.sessionId || sessionIdToLoad || '';
85
+ target.configOptions = session.configOptions ?? [];
86
+ target.runModel = modelFromOption(configOption(target.configOptions, 'model'), target.harness);
87
+ target.capabilities = capabilitiesFrom(init, target.configOptions, { usage: false, plan: false });
88
+ await applySelections(target, wanted);
89
+ }