@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,350 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * One live ACP session: the bridge between `AcpProcess` + `AcpFrameMapper` and
8
+ * the `HarnessSession` contract every route already speaks.
9
+ *
10
+ * It owns the session's own state — the id, the config selectors, the resolved
11
+ * model, the run flags the sidebar spinner and the queue's delivery gate read,
12
+ * the agent's command list, and the approval queue a reloaded tab replays. The
13
+ * RULES for each of those live beside it, one module per concern:
14
+ * `session-handshake.ts` (initialize/new/load + the picks), `session-turns.ts`
15
+ * (the ACK contract and turn-end bookkeeping), `session-config.ts` (adopting a
16
+ * config answer, answering a parked dialog), `session-permissions.ts` (the
17
+ * tier that answers before a dialog exists), `session-facts.ts` (the metadata an
18
+ * agent publishes about itself between turns) and `session-web-state.ts`
19
+ * (`get_state`, in the shape the omp transport reports it).
20
+ *
21
+ * `send()` accepts the SAME command vocabulary the routes already send omp, so
22
+ * `routes/agent/command.ts` needs no second dispatch table.
23
+ */
24
+
25
+ import { AcpProcess } from '@/server/lib/harness/acp/client';
26
+ import { AcpTurns } from '@/server/lib/harness/acp/turn';
27
+ import { AcpFrameMapper } from '@/server/lib/harness/acp/frames';
28
+ import type { AcpConfigOption, AcpId } from '@/server/lib/harness/acp/protocol';
29
+ import { promptBlocks } from '@/server/lib/harness/acp/prompt';
30
+ import { adoptConfigAnswer, publishConfigChange, settlePermissionDialog, stampMessageModel } from '@/server/lib/harness/acp/session-config';
31
+ import { beginAcpTurn, settleAcpTurn } from '@/server/lib/harness/acp/session-turns';
32
+ import { driveAcpGoalAfterTurn } from '@/server/lib/harness/acp/acp-goal-driver.server';
33
+ import { handshakeAcpSession } from '@/server/lib/harness/acp/session-handshake';
34
+ import { capabilitiesFrom } from '@/server/lib/harness/launch';
35
+ import { PendingPermissions } from '@/server/lib/harness/acp/permissions';
36
+ import { handleSessionNotification } from '@/server/lib/harness/acp/session-notifications';
37
+ import { AcpUsageMeter, type AcpContextUsage } from '@/server/lib/harness/acp/session-usage';
38
+ import { answerPermissionRequest } from '@/server/lib/harness/acp/session-permissions';
39
+ import { acpWebState } from '@/server/lib/harness/acp/session-web-state';
40
+ import { acpIdleReaper } from '@/server/lib/harness/acp/session-idle';
41
+ import { DEFAULT_APPROVAL_MODE, isApprovalMode, type ApprovalMode } from '@/shared/lib/omp/config/access-mode';
42
+ import { dispatchCommand, type AcpCommandHost } from '@/server/lib/harness/acp/commands';
43
+ import { markStreamStatus } from '@/shared/lib/omp/session/stream-state.server';
44
+ import type { AcpSessionOptions } from '@/server/lib/harness/acp/session-options';
45
+ import type { HarnessCapabilities } from '@/server/lib/harness/capabilities';
46
+ import type { HarnessSession } from '@/server/lib/harness/session';
47
+ import type { HarnessId } from '@/shared/lib/harness/catalog';
48
+ import type { AgentEvent } from '@/server/lib/omp/rpc/constants';
49
+ import type { IdleReaper } from '@/server/lib/omp/rpc/idle-reaper';
50
+
51
+ export class AcpSession implements HarnessSession, AcpCommandHost {
52
+ readonly harness: HarnessId;
53
+ readonly cwd: string;
54
+ readonly sessionFile = '';
55
+ sessionId = '';
56
+ /** The turn in flight — the only one whose frames are accepted. */
57
+ private readonly turns: AcpTurns;
58
+ runModel: { provider: string; modelId: string } | null = null;
59
+ /** The agent's own slash-command list, from `available_commands_update`; the
60
+ * composer's `/` pool reads it for this session (omp's utility child answers
61
+ * that question for the RPC transport). */
62
+ agentCommands: { name: string; description?: string; inputHint?: string }[] = [];
63
+ /** The agent's plan entries from `session/update plan`, as published. The
64
+ * Todos panel renders them through the same payload omp's transcript
65
+ * snapshot produces. */
66
+ planEntries: unknown[] = [];
67
+ /** Messages this session has moved: prompts sent plus assistant messages the
68
+ * mapper closed. omp reports the same quantity from its transcript. */
69
+ messageCount = 0;
70
+ /** Prompts this session dispatched — the telemetry panel's user count. */
71
+ promptCount = 0;
72
+ /** Assistant messages the mapper closed, for the same panel. */
73
+ assistantCount = 0;
74
+ /** The last `usage_update` the agent reported, or null when it never did. */
75
+ private readonly usage = new AcpUsageMeter();
76
+
77
+ get contextUsage(): AcpContextUsage | null {
78
+ return this.usage.contextUsage;
79
+ }
80
+
81
+ get totalCost(): number {
82
+ return this.usage.totalCost;
83
+ }
84
+
85
+ get usageTokens(): number {
86
+ return this.usage.usageTokens;
87
+ }
88
+ /** The composer's approval tier. Answered in-process by {@link onClientRequest}. */
89
+ accessMode: ApprovalMode = DEFAULT_APPROVAL_MODE;
90
+ capabilities: HarnessCapabilities = capabilitiesFrom({ protocolVersion: 1 }, [], { usage: false, plan: false });
91
+ configOptions: AcpConfigOption[] = [];
92
+ private readonly proc: AcpProcess;
93
+ /** The quiet-window reclaim; the rules live in `session-idle.ts`. */
94
+ readonly idle: IdleReaper;
95
+ private readonly mapper = new AcpFrameMapper();
96
+ private readonly listeners = new Set<(event: AgentEvent) => void>();
97
+ private readonly permissions = new PendingPermissions();
98
+ private destroyHook: (() => void) | null = null;
99
+ private destroyed = false;
100
+ /** Set when Kabmo is the one ending the process, so the exit is not reported
101
+ * as an agent failure. `force_reset` is the Stop button's escalation, and the
102
+ * user must not get an "agent exited" error for a stop they asked for. */
103
+ private closing = false;
104
+
105
+ constructor(options: AcpSessionOptions, cwd: string) {
106
+ this.harness = options.harness;
107
+ this.cwd = cwd;
108
+ this.proc = new AcpProcess({
109
+ command: options.command,
110
+ cwd,
111
+ ...(options.env ? { env: options.env } : {}),
112
+ onNotification: (method, params) => this.onNotification(method, params),
113
+ onClientRequest: (id, method, params) => this.onClientRequest(id, method, params),
114
+ onExit: (info) => this.onExit(info),
115
+ });
116
+ this.idle = acpIdleReaper(this, options.idleDestroyMs);
117
+ this.turns = new AcpTurns({
118
+ emit: (event) => this.emit(event),
119
+ prompt: (message, images) =>
120
+ this.proc.prompt(this.sessionId, promptBlocks(message, images), 0) as Promise<{ stopReason?: string } | undefined>,
121
+ cancelAgent: () => this.proc.cancel(this.sessionId),
122
+ abandonPrompt: () => this.proc.abandonPrompt(this.sessionId),
123
+ resetMapper: () => this.mapper.reset(),
124
+ closeMessage: () => this.mapper.closeMessage().map((event) => stampMessageModel(event, this.runModel)),
125
+ openCalls: () => this.mapper.openCalls(),
126
+ // The follow-up queue is armed from the turn's END, exactly as the omp
127
+ // wrapper arms it from its own terminal settle. Without this an ACP chat's
128
+ // queued follow-up stayed in `queued_messages` forever: nothing on this
129
+ // transport scheduled a delivery, and the client's nudge route only knew
130
+ // omp's wrapper.
131
+ onTurnEnd: (info) => this.onTurnEnded(info),
132
+ });
133
+ this.requestedModel = options.model ?? null;
134
+ this.requestedThinking = options.thinkingLevel ?? null;
135
+ this.requestedMode = options.mode ?? null;
136
+ this.accessMode = isApprovalMode(options.accessMode) ? options.accessMode : DEFAULT_APPROVAL_MODE;
137
+ }
138
+
139
+ private readonly requestedModel: { provider: string; modelId: string } | null;
140
+ private readonly requestedThinking: string | null;
141
+ private readonly requestedMode: string | null;
142
+
143
+ /** `initialize` + `session/new|load|resume`, then the requested selections. */
144
+ async start(sessionIdToLoad?: string): Promise<{ sessionId: string }> {
145
+ await handshakeAcpSession(
146
+ this,
147
+ this.proc,
148
+ { model: this.requestedModel, thinking: this.requestedThinking, mode: this.requestedMode },
149
+ sessionIdToLoad,
150
+ );
151
+ // A slow handshake is not idleness: the window starts once it is usable.
152
+ this.idle.reset(true);
153
+ return { sessionId: this.sessionId };
154
+ }
155
+
156
+ isAlive(): boolean {
157
+ return !this.destroyed && this.proc.isAlive;
158
+ }
159
+
160
+ get isStreaming(): boolean {
161
+ return this.turns.isStreaming;
162
+ }
163
+
164
+ get isPromptRunning(): boolean {
165
+ return this.turns.isPromptRunning;
166
+ }
167
+
168
+ isRunning(): boolean {
169
+ return this.isAlive() && (this.turns.isPromptRunning || this.turns.isStreaming);
170
+ }
171
+
172
+ isBusy(): boolean {
173
+ return this.isRunning() || this.permissions.size() > 0;
174
+ }
175
+
176
+ onEvent(listener: (event: AgentEvent) => void): () => void {
177
+ this.listeners.add(listener);
178
+ return () => this.listeners.delete(listener);
179
+ }
180
+
181
+ emit(event: AgentEvent): void {
182
+ for (const listener of this.listeners) {
183
+ try {
184
+ listener(event);
185
+ } catch {
186
+ // One throwing subscriber must not starve the others.
187
+ }
188
+ }
189
+ }
190
+
191
+ getPendingUiDialogs(): Record<string, unknown>[] {
192
+ // Widened for the shared `HarnessSession` contract, which predates the
193
+ // dialog shape; every field the client reads is present.
194
+ return this.permissions.pendingDialogs() as unknown as Record<string, unknown>[];
195
+ }
196
+
197
+ resolvePendingUiDialog(id: string): void {
198
+ // A dialog the client dismissed is a REFUSAL, not a no-answer.
199
+ this.resolvePermission(id, false);
200
+ }
201
+
202
+ onDestroy(callback: () => void): void {
203
+ this.destroyHook = callback;
204
+ }
205
+
206
+ async send(command: Record<string, unknown>): Promise<unknown> {
207
+ // A command is the clearest sign the session is still wanted.
208
+ this.idle.reset();
209
+ return dispatchCommand(this, command);
210
+ }
211
+
212
+ /** Dispatcher seam: one steering send. */
213
+ steer(blocks: unknown[], queue: 'steering' | 'followUp'): Promise<unknown> {
214
+ return this.proc.steer(this.sessionId, blocks, queue);
215
+ }
216
+
217
+ /**
218
+ * The durable run marker (`session_stream_state`), the row the sidebar's
219
+ * spinner and a reattaching tab's "still running" answer read. A field so a
220
+ * unit test can stub it: the default writes the same row omp's dispatch writes.
221
+ */
222
+ markStream: (status: 'stream' | 'finish' | 'abort') => void = (status) => {
223
+ if (!this.sessionId) return;
224
+ void markStreamStatus(this.sessionId, status, status === 'stream' ? this.runModel : undefined).catch(() => {});
225
+ };
226
+
227
+ /** Turn-end bookkeeping the panels read — see `session-turns.ts`. A cancelled
228
+ * turn closes the marker as an `abort` badge, every other ending a `finish`.
229
+ * The goal driver then audits the closed message and may open the next turn. */
230
+ onTurnEnded(info: { stopReason?: string; closedMessage: boolean; message?: unknown; cancelled?: boolean }): void {
231
+ if (info.closedMessage) this.assistantCount += 1;
232
+ this.usage.endTurn();
233
+ settleAcpTurn(this, info);
234
+ void driveAcpGoalAfterTurn(this, info.message, { cancelled: info.cancelled === true }).catch(() => {});
235
+ }
236
+
237
+ /** Dispatcher seam: stop the turn. The rules live in `AcpTurns.cancel`. */
238
+ cancelTurn(): void {
239
+ this.turns.cancel();
240
+ }
241
+
242
+ /** Dispatcher seam: adopt the composer's access pick. ACP answers approvals
243
+ * in-process, so this needs no respawn — unlike omp's spawn-time flag. */
244
+ setAccessMode(mode: ApprovalMode): void {
245
+ this.accessMode = mode;
246
+ }
247
+
248
+ /** Dispatcher seam: write one config selector and adopt the answer — see
249
+ * `session-config.ts` for why the AGENT's resolved value is what is kept. */
250
+ async setConfig(configId: string, value: string | boolean): Promise<unknown> {
251
+ const result = await this.proc.setConfigOption(this.sessionId, configId, value);
252
+ adoptConfigAnswer(this, result, { configId, value });
253
+ publishConfigChange(this, configId);
254
+ return result;
255
+ }
256
+
257
+ /** Dispatcher seam: answer a pending approval dialog. Every exit answers the
258
+ * agent — a silent return would hang it (see `session-config.ts`). */
259
+ resolvePermission(dialogId: string, confirmed: boolean): unknown {
260
+ settlePermissionDialog(this.permissions, this.proc, dialogId, confirmed);
261
+ return null;
262
+ }
263
+
264
+ webState(): Record<string, unknown> {
265
+ return acpWebState({
266
+ sessionId: this.sessionId,
267
+ isStreaming: this.isStreaming,
268
+ isPromptRunning: this.isPromptRunning,
269
+ messageCount: this.messageCount,
270
+ promptCount: this.promptCount,
271
+ assistantCount: this.assistantCount,
272
+ contextUsage: this.contextUsage,
273
+ totalCost: this.totalCost,
274
+ runModel: this.runModel,
275
+ configOptions: this.configOptions,
276
+ harness: this.harness,
277
+ });
278
+ }
279
+
280
+ /** Run one turn. The promise IS the turn: ACP resolves `session/prompt` when
281
+ * the agent is done, so the reply is awaited for its whole duration. The ACK,
282
+ * the refusal of a second prompt and the end bookkeeping are stated in
283
+ * `session-turns.ts`.
284
+ */
285
+ startTurn(message: string, images: unknown): unknown {
286
+ this.promptCount += 1;
287
+ this.usage.beginTurn();
288
+ return beginAcpTurn(this, this.turns, message, images);
289
+ }
290
+
291
+ private onNotification(method: string, params: Record<string, unknown>): void {
292
+ // A long turn emits no commands but plenty of `session/update` frames.
293
+ this.idle.reset();
294
+ handleSessionNotification(this, method, params);
295
+ }
296
+
297
+ absorbUsage(update: Record<string, unknown>): void { this.usage.absorb(update); }
298
+ resetUsageTokens(): void { this.usage.reset(); }
299
+ acceptingFrames(): boolean { return this.turns.acceptingFrames(); }
300
+
301
+ mapUpdate(update: Record<string, unknown>): AgentEvent[] { return this.mapper.mapUpdate(update); }
302
+
303
+ /** Agent→client requests: every branch answers or refuses — an unanswered call parks the turn. */
304
+ private onClientRequest(
305
+ id: AcpId,
306
+ method: string,
307
+ params: Record<string, unknown>,
308
+ ): Promise<{ answered: true; result: unknown } | { answered: false; message: string } | { answered: false; deferred: true }> {
309
+ this.idle.reset();
310
+ if (method === 'session/request_permission') {
311
+ return answerPermissionRequest({
312
+ sessionId: this.sessionId,
313
+ accessMode: this.accessMode,
314
+ permissions: this.permissions,
315
+ emit: (event) => this.emit(event),
316
+ }, id, params);
317
+ }
318
+ return Promise.resolve({ answered: false, message: `Kabmo does not implement ${method}` });
319
+ }
320
+
321
+ private onExit(info: { code: number | null; stderrTail: string }): void {
322
+ this.destroyed = true;
323
+ this.idle.stop();
324
+ if (this.closing) {
325
+ this.destroyHook?.();
326
+ return;
327
+ }
328
+ const detail = info.stderrTail.trim().split('\n').slice(-3).join(' · ');
329
+ this.emit({
330
+ type: 'prompt_error',
331
+ errorMessage: detail || `The ${this.harness} agent exited (code ${info.code ?? 'signal'})`,
332
+ });
333
+ this.emit({ type: 'agent_end', isTerminal: true });
334
+ this.destroyHook?.();
335
+ }
336
+
337
+ destroy(): void {
338
+ void this.destroyAndWait();
339
+ }
340
+
341
+ async destroyAndWait(): Promise<void> {
342
+ if (this.destroyed) return;
343
+ this.destroyed = true;
344
+ this.closing = true;
345
+ this.idle.stop();
346
+ this.permissions.clear();
347
+ await this.proc.dispose().catch(() => {});
348
+ this.destroyHook?.();
349
+ }
350
+ }
@@ -0,0 +1,199 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * The life of an ACP turn: one prompt, its frames, and how it ends.
8
+ *
9
+ * Split out of `AcpSession` because the rules here are the ones that took a bug
10
+ * each to learn, and a session that also owns spawning, config selectors and
11
+ * client requests buried them:
12
+ *
13
+ * - **a prompt is CHAINED, never raced.** ACP has no queue: a second
14
+ * `session/prompt` while one is open CANCELS the first (measured, twice).
15
+ * - **a cancelled turn is closed HERE**, not by waiting for the agent.
16
+ * `session/cancel` is a notification and the answer is not guaranteed.
17
+ * - **frames are accepted only while a turn is open**, so abandoned output
18
+ * cannot reach a client that already finalized the message.
19
+ */
20
+
21
+ import type { AgentEvent } from '@/server/lib/omp/rpc/constants';
22
+ import { turnEndFrame } from '@/server/lib/harness/acp/frames';
23
+
24
+ export interface AcpTurnSeams {
25
+ /** Push one frame at the session's listeners. */
26
+ emit: (event: AgentEvent) => void;
27
+ /** Send `session/prompt` and resolve when the AGENT ends the turn. */
28
+ prompt: (message: string, images: unknown) => Promise<{ stopReason?: string } | undefined>;
29
+ /** Send `session/cancel` — a notification the agent may never answer. */
30
+ cancelAgent: () => void;
31
+ /** Settle the outstanding request locally, as cancelled. */
32
+ abandonPrompt: () => void;
33
+ /** Start a clean mapper, so the previous turn cannot leak into this one. */
34
+ resetMapper: () => void;
35
+ /** Flush the message the turn left open. */
36
+ closeMessage: () => AgentEvent[];
37
+ /** Tool calls the turn abandoned, by id. */
38
+ openCalls: () => string[];
39
+ /**
40
+ * The turn is over (finished, failed or cancelled), with the agent's own stop
41
+ * reason, the assistant message the mapper closed (the goal driver audits it),
42
+ * and whether the turn was cancelled (a stop must not be audited).
43
+ */
44
+ onTurnEnd: (info: { stopReason?: string; closedMessage: boolean; message?: unknown; cancelled?: boolean }) => void;
45
+ }
46
+
47
+ export class AcpTurns {
48
+ isStreaming = false;
49
+ isPromptRunning = false;
50
+ /** The turn whose frames are accepted, null when none is open. */
51
+ private open: number | null = null;
52
+ /** Identity of the last turn started; only ever grows, so a late reply can be
53
+ * matched to the turn that produced it. */
54
+ private seq = 0;
55
+ /** The outstanding `session/prompt` request — the chain the next turn waits on. */
56
+ private request: Promise<unknown> | null = null;
57
+ /** The prompt text of the turn being opened, for the silent-turn verdict. */
58
+ private promptText = '';
59
+
60
+ constructor(private readonly seams: AcpTurnSeams) {}
61
+
62
+ /** The same field omp puts on its ack, so a client that inspects it reads one
63
+ * vocabulary whichever transport served the chat. */
64
+ start(message: string, images: unknown): { agentInvoked: true } {
65
+ if (this.isPromptRunning || this.isStreaming) {
66
+ throw new Error('Agent is already processing. Use steer() or followUp() to queue messages, or wait for completion.');
67
+ }
68
+ this.seq += 1;
69
+ const turnId = this.seq;
70
+ this.promptText = message;
71
+ this.isPromptRunning = true;
72
+ this.isStreaming = true;
73
+ this.seams.emit({ type: 'agent_start' });
74
+ this.seams.emit({ type: 'turn_start' });
75
+
76
+ const request = (this.request ?? Promise.resolve())
77
+ .catch(() => undefined)
78
+ .then(() => {
79
+ this.open = turnId;
80
+ this.seams.resetMapper();
81
+ return this.seams.prompt(message, images);
82
+ });
83
+ this.request = request;
84
+ void request
85
+ .then(
86
+ (result) => this.settle(turnId, () => this.finish(result)),
87
+ (error: unknown) =>
88
+ this.settle(turnId, () => {
89
+ this.seams.emit({
90
+ type: 'prompt_error',
91
+ errorMessage: error instanceof Error ? error.message : String(error),
92
+ });
93
+ // The agent's own error is the reason. `finish` must not append its
94
+ // generic "no answer" verdict on top of it — the second frame lands
95
+ // last on the client and replaced the useful message.
96
+ this.finish(undefined, true);
97
+ }),
98
+ )
99
+ .finally(() => {
100
+ if (this.request === request) this.request = null;
101
+ });
102
+
103
+ return { agentInvoked: true };
104
+ }
105
+
106
+ /**
107
+ * Stop the turn AND close it here.
108
+ *
109
+ * Nothing guarantees the agent answers the cancel, and a session whose agent
110
+ * never does stayed `isStreaming` forever: the spinner cleared, and the NEXT
111
+ * prompt was refused with "Agent is already processing". The agent's own
112
+ * prompt request is settled locally for the same reason — it is what the next
113
+ * turn is chained behind.
114
+ */
115
+ cancel(): void {
116
+ if (this.open === null) {
117
+ // Nothing dispatched yet, but a turn may be queued behind the previous
118
+ // request: clear its flags too, or Stop leaves the session permanently
119
+ // "processing".
120
+ this.isPromptRunning = false;
121
+ this.isStreaming = false;
122
+ return;
123
+ }
124
+ this.open = null;
125
+ this.seams.cancelAgent();
126
+ this.seams.abandonPrompt();
127
+ this.finish({ stopReason: 'cancelled' });
128
+ }
129
+
130
+ /** Is a turn accepting the agent's frames right now? */
131
+ acceptingFrames(): boolean {
132
+ return this.open !== null;
133
+ }
134
+
135
+ /** Close a turn, unless it was cancelled first: a cancelled turn's late reply
136
+ * must not close the one the user is now watching. */
137
+ private settle(turnId: number, close: () => void): void {
138
+ if (this.open !== turnId) return;
139
+ this.open = null;
140
+ close();
141
+ }
142
+
143
+ /** Flush the open message, fail abandoned cards, emit the terminal frame. A
144
+ * call left open by a cancelled turn would spin forever — the agent is never
145
+ * going to report an end for work it abandoned. `reported` says the caller
146
+ * already emitted the failure reason, so only this module's generic silent
147
+ * verdict is suppressed. */
148
+ private finish(result: { stopReason?: string } | undefined, reported = false): void {
149
+ const flushed = this.seams.closeMessage();
150
+ for (const event of flushed) this.seams.emit(event);
151
+ const closed = flushed.find((event) => event.type === 'message_end')?.message;
152
+ const abandoned = this.seams.openCalls();
153
+ for (const toolCallId of abandoned) {
154
+ this.seams.emit({ type: 'tool_execution_end', toolCallId, isError: true, result: { output: 'Cancelled' } });
155
+ }
156
+ // A prompt that ends with no message and no tool call is a SILENT failure on
157
+ // most agents (measured on pi-acp: it answers `session/prompt` with `{}` and
158
+ // sends no frames at all when its provider call fails). Reporting it beats
159
+ // leaving an empty bubble that reads as "the agent had nothing to say".
160
+ // Whitespace-only chunks are the same failure with a frame attached: the
161
+ // row renders no text, so the operator still sees nothing. Slash commands
162
+ // are exempt: an extension command is answered locally and correctly
163
+ // produces nothing, and a user's Stop is not a failure either.
164
+ const answered = hasRenderableAnswer(closed) || abandoned.length > 0;
165
+ const cancelled = result?.stopReason === 'cancelled';
166
+ if (!answered && !cancelled && !reported && !this.promptText.trimStart().startsWith('/')) {
167
+ this.seams.emit({
168
+ type: 'prompt_error',
169
+ errorMessage: 'The agent ended the turn without sending an answer',
170
+ });
171
+ }
172
+ this.isPromptRunning = false;
173
+ this.isStreaming = false;
174
+ this.seams.emit(turnEndFrame(result));
175
+ this.seams.onTurnEnd({
176
+ ...(result?.stopReason ? { stopReason: result.stopReason } : {}),
177
+ closedMessage: flushed.some((event) => event.type === 'message_end'),
178
+ ...(closed ? { message: closed } : {}),
179
+ ...(cancelled ? { cancelled: true } : {}),
180
+ });
181
+ }
182
+ }
183
+
184
+ /** Does the closed message carry anything the timeline draws? A whitespace-only
185
+ * chunk (or one that carried only an empty text block) opens a message row
186
+ * that renders nothing, which is the same operator-visible failure as no frame
187
+ * at all. Thinking and tool calls are content: they render as their own
188
+ * blocks. */
189
+ function hasRenderableAnswer(message: unknown): boolean {
190
+ if (!message || typeof message !== 'object' || !('content' in message)) return false;
191
+ const content = message.content;
192
+ if (!Array.isArray(content)) return false;
193
+ return content.some((block) => {
194
+ if (!block || typeof block !== 'object') return false;
195
+ if ('text' in block && typeof block.text === 'string') return block.text.trim().length > 0;
196
+ if ('thinking' in block && typeof block.thinking === 'string') return block.thinking.trim().length > 0;
197
+ return 'type' in block && block.type === 'toolCall';
198
+ });
199
+ }
@@ -0,0 +1,87 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * The ACP session verbs, as free functions over an `invoke` seam.
8
+ *
9
+ * They live outside `client.ts` because that file owns the TRANSPORT (spawn,
10
+ * framing, pending replies, agent->client requests) and this one owns the
11
+ * PROTOCOL above it. Keeping them apart is what lets the transport be tested
12
+ * with a fake invoke, and what keeps both files under the repo's line ceiling.
13
+ *
14
+ * `cancel` is the odd one: ACP defines `session/cancel` as a NOTIFICATION, so
15
+ * there is no reply to await and the turn ends through the in-flight
16
+ * `session/prompt` answer (`stopReason: "cancelled"`).
17
+ */
18
+
19
+ import type { AcpSessionInfo, AcpSessionNewResult } from '@/server/lib/harness/acp/protocol';
20
+
21
+ /** One request/response round trip against an ACP agent. Implemented by
22
+ * `AcpProcess.call`; a test supplies its own. */
23
+ export type AcpInvoke = <T>(method: string, params: unknown, timeoutMs: number) => Promise<T>;
24
+ /** Fire-and-forget frame (notifications only). */
25
+ export type AcpNotify = (method: string, params: unknown) => void;
26
+
27
+ export async function newSession(invoke: AcpInvoke, cwd: string, timeoutMs = 120_000): Promise<AcpSessionNewResult> {
28
+ return invoke<AcpSessionNewResult>('session/new', { cwd, mcpServers: [] }, timeoutMs);
29
+ }
30
+
31
+ export async function loadSession(invoke: AcpInvoke, sessionId: string, cwd: string, timeoutMs = 120_000): Promise<unknown> {
32
+ return invoke('session/load', { sessionId, cwd, mcpServers: [] }, timeoutMs);
33
+ }
34
+
35
+ export async function resumeSession(invoke: AcpInvoke, sessionId: string, cwd: string, timeoutMs = 120_000): Promise<unknown> {
36
+ return invoke('session/resume', { sessionId, cwd, mcpServers: [] }, timeoutMs);
37
+ }
38
+
39
+ export async function forkSession(invoke: AcpInvoke, sessionId: string, cwd: string, timeoutMs = 120_000): Promise<AcpSessionNewResult> {
40
+ return invoke<AcpSessionNewResult>('session/fork', { sessionId, cwd, mcpServers: [] }, timeoutMs);
41
+ }
42
+
43
+ export async function listSessions(invoke: AcpInvoke, cwd?: string, timeoutMs = 60_000): Promise<AcpSessionInfo[]> {
44
+ const result = await invoke<{ sessions?: AcpSessionInfo[] }>('session/list', cwd ? { cwd } : {}, timeoutMs);
45
+ return Array.isArray(result?.sessions) ? result.sessions : [];
46
+ }
47
+
48
+ /** One prompt turn. Resolves when the agent answers `session/prompt`, which is
49
+ * the END of the turn in ACP (the agent streams via notifications meanwhile),
50
+ * so the cap is the caller's: a long coding turn legitimately takes minutes. */
51
+ export async function prompt(
52
+ invoke: AcpInvoke,
53
+ sessionId: string,
54
+ blocks: unknown[],
55
+ timeoutMs = 0,
56
+ ): Promise<{ stopReason?: string; usage?: unknown }> {
57
+ return invoke('session/prompt', { sessionId, prompt: blocks }, timeoutMs);
58
+ }
59
+
60
+ export function cancel(notify: AcpNotify, sessionId: string): void {
61
+ notify('session/cancel', { sessionId });
62
+ }
63
+
64
+ export async function setConfigOption(
65
+ invoke: AcpInvoke,
66
+ sessionId: string,
67
+ configId: string,
68
+ value: string | boolean,
69
+ timeoutMs = 30_000,
70
+ ): Promise<unknown> {
71
+ return invoke('session/set_config_option', { sessionId, configId, value }, timeoutMs);
72
+ }
73
+
74
+ /** omp's steering extension (advertised as `_meta.steering.supported`). */
75
+ export async function steer(
76
+ invoke: AcpInvoke,
77
+ sessionId: string,
78
+ blocks: unknown[],
79
+ queue: 'steering' | 'followUp' = 'steering',
80
+ timeoutMs = 30_000,
81
+ ): Promise<{ outcome?: string; queue?: string }> {
82
+ return invoke('_session/steering', { sessionId, prompt: blocks, _meta: { steering: { queue } } }, timeoutMs);
83
+ }
84
+
85
+ export async function closeSession(invoke: AcpInvoke, sessionId: string, timeoutMs = 30_000): Promise<unknown> {
86
+ return invoke('session/close', { sessionId }, timeoutMs);
87
+ }