@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
@@ -31,6 +31,8 @@ import {
31
31
  ICON_STYLE_ATTRIBUTE,
32
32
  resolveIconStyle,
33
33
  } from '@/shared/lib/theme/icon-style';
34
+ import { ICON_PAPER_ATTRIBUTE } from '@/shared/lib/icons/tint';
35
+ import { paperBucketOf } from '@/shared/lib/icons/icon-tone';
34
36
  import {
35
37
  DEFAULT_SURFACE_STYLE,
36
38
  SURFACE_ATTRIBUTE,
@@ -53,12 +55,17 @@ const TEMPLATE_VARIANT = 'data-theme-variant="light"';
53
55
  const TEMPLATE_META = '<meta name="theme-color" content="#faf8f3" />';
54
56
 
55
57
  /** The extra `<html>` attributes for the stored presentation styles. */
56
- export function styleAttributes(surfaceStyle: unknown, iconStyle: unknown): string {
58
+ export function styleAttributes(surfaceStyle: unknown, iconStyle: unknown, palette?: ThemePalette): string {
57
59
  const surface = resolveSurfaceStyle(surfaceStyle);
58
60
  const icon = resolveIconStyle(iconStyle);
59
61
  const parts: string[] = [];
60
62
  if (surface !== DEFAULT_SURFACE_STYLE) parts.push(`${SURFACE_ATTRIBUTE}="${surface}"`);
61
63
  if (icon !== DEFAULT_ICON_STYLE) parts.push(`${ICON_STYLE_ATTRIBUTE}="${icon}"`);
64
+ // The paper bucket is written for EVERY light palette, including the default
65
+ // one, because it is not a preference: without it the first frame paints the
66
+ // `deep` icon table on a `mid` paper — one step darker than the palette allows,
67
+ // which is the exact flash the client's `applyIconPaper` then corrects.
68
+ if (palette && palette.variant === 'light') parts.push(`${ICON_PAPER_ATTRIBUTE}="${paperBucketOf(palette.paper)}"`);
62
69
  return parts.length > 0 ? ` ${parts.join(' ')}` : '';
63
70
  }
64
71
 
@@ -73,7 +80,7 @@ export function applyShellDocumentFacts(html: string, facts: ShellDocumentFacts)
73
80
  return html
74
81
  .replace(
75
82
  TEMPLATE_THEME,
76
- `data-theme="${facts.palette.id}"${styleAttributes(facts.surfaceStyle, facts.iconStyle)}`,
83
+ `data-theme="${facts.palette.id}"${styleAttributes(facts.surfaceStyle, facts.iconStyle, facts.palette)}`,
77
84
  )
78
85
  .replace(TEMPLATE_VARIANT, `data-theme-variant="${facts.palette.variant}"`)
79
86
  .replace(TEMPLATE_META, `<meta name="theme-color" content="${facts.chromeColor}" />`);
@@ -20,6 +20,7 @@ import {
20
20
  styleAttributes,
21
21
  } from '@/server/lib/assets/shell-attributes.server';
22
22
  import { KABMO_PALETTES } from '@/shared/lib/theme/palettes/kabmo';
23
+ import { THEMES } from '@/shared/lib/theme/catalog';
23
24
 
24
25
  const TEMPLATE = `<html lang="en" data-theme="paper" data-theme-variant="light">
25
26
  <head>
@@ -27,7 +28,11 @@ const TEMPLATE = `<html lang="en" data-theme="paper" data-theme-variant="light">
27
28
  </head>
28
29
  </html>`;
29
30
 
30
- const dark = KABMO_PALETTES[0];
31
+ // `KABMO_PALETTES[0]` is `paper`, which is LIGHT — the earlier name said
32
+ // "dark" and every assertion below was written as if a light palette added no
33
+ // attributes at all. It does now: its icon paper bucket.
34
+ const light = KABMO_PALETTES[0];
35
+ const dark = THEMES.find((theme) => theme.variant === 'dark')!;
31
36
 
32
37
  describe('styleAttributes', () => {
33
38
  test('the defaults add nothing at all', () => {
@@ -41,18 +46,29 @@ describe('styleAttributes', () => {
41
46
  expect(styleAttributes('classic', 'color')).toBe(' data-icon-style="color"');
42
47
  expect(styleAttributes('glass', 'color')).toBe(' data-surface="glass" data-icon-style="color"');
43
48
  });
49
+
50
+ test('a light palette carries its icon paper bucket, even at the default styles', () => {
51
+ // Not a preference: without it the first frame paints the `deep` tone table
52
+ // on a `mid` paper, one step darker than the palette allows, and the client's
53
+ // `applyIconPaper` then visibly corrects it.
54
+ expect(styleAttributes('classic', 'monochrome', light)).toBe(' data-icon-paper="mid"');
55
+ // A dark palette has one band, so it states nothing.
56
+ expect(styleAttributes('classic', 'monochrome', dark)).toBe('');
57
+ });
44
58
  });
45
59
 
46
60
  describe('applyShellDocumentFacts', () => {
47
61
  test('writes the palette and the chrome colour, and nothing else by default', () => {
48
62
  const html = applyShellDocumentFacts(TEMPLATE, {
49
- palette: dark,
63
+ palette: light,
50
64
  surfaceStyle: undefined,
51
65
  iconStyle: undefined,
52
66
  chromeColor: '#123456',
53
67
  });
54
68
 
55
- expect(html).toContain(`<html lang="en" data-theme="${dark.id}" data-theme-variant="${dark.variant}">`);
69
+ expect(html).toContain(
70
+ `<html lang="en" data-theme="${light.id}" data-icon-paper="mid" data-theme-variant="${light.variant}">`,
71
+ );
56
72
  expect(html).toContain('<meta name="theme-color" content="#123456" />');
57
73
  expect(html).not.toContain('data-surface');
58
74
  expect(html).not.toContain('data-icon-style');
@@ -60,14 +76,14 @@ describe('applyShellDocumentFacts', () => {
60
76
 
61
77
  test('a stored glass style lands on the FIRST frame, not after hydration', () => {
62
78
  const html = applyShellDocumentFacts(TEMPLATE, {
63
- palette: dark,
79
+ palette: light,
64
80
  surfaceStyle: 'glass',
65
81
  iconStyle: 'color',
66
82
  chromeColor: '#123456',
67
83
  });
68
84
 
69
85
  expect(html).toContain(
70
- `<html lang="en" data-theme="${dark.id}" data-surface="glass" data-icon-style="color" data-theme-variant="${dark.variant}">`,
86
+ `<html lang="en" data-theme="${light.id}" data-surface="glass" data-icon-style="color" data-icon-paper="mid" data-theme-variant="${light.variant}">`,
71
87
  );
72
88
  });
73
89
 
@@ -76,7 +92,7 @@ describe('applyShellDocumentFacts', () => {
76
92
 
77
93
  expect(
78
94
  applyShellDocumentFacts(stale, {
79
- palette: dark,
95
+ palette: light,
80
96
  surfaceStyle: 'glass',
81
97
  iconStyle: 'color',
82
98
  chromeColor: '#123456',
@@ -22,6 +22,7 @@ import { ensureProviderIconSchema } from '@/server/lib/models/provider-icon-stor
22
22
  import { ensureUsageIndexSchema } from '@/server/lib/usage/index-schema.server';
23
23
  import { ensureWorktreeSchema } from '@/server/lib/db/worktree-registry.server';
24
24
  import { ensureReviewSchema } from '@/server/lib/review/schema.server';
25
+ import { ensureHarnessSchema } from '@/server/lib/harness/schema.server';
25
26
  import { migrateWorkspaceFolderColumns } from '@/shared/lib/workspace/schema-migrations';
26
27
  import { migrateSessionStreamStateColumns } from '@/shared/lib/omp/session/schema-migrations';
27
28
 
@@ -137,6 +138,9 @@ export async function initSchema(db: DbClient): Promise<void> {
137
138
  // Review annotations on a rendered markdown document (per block, per file).
138
139
  await ensureReviewSchema(db);
139
140
 
141
+ // Harness ownership per session: the sidebar's mark needs it, and it has to
142
+ // outlive the process that spawned the child (a restart, a second instance).
143
+ await ensureHarnessSchema(db);
140
144
  await db.exec(`
141
145
  CREATE TABLE IF NOT EXISTS files (
142
146
  id INTEGER PRIMARY KEY AUTOINCREMENT,
@@ -0,0 +1,107 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * The goal auditor for an ACP chat, run through the SAME harness.
8
+ *
9
+ * `runGoalAudit` spawns `omp -p` with an omp model, which is the wrong agent for
10
+ * an ACP chat: the model name (`claude/opus`) is not one omp resolves, and the
11
+ * verdict would come from a different agent than the one doing the work. This
12
+ * opens a one-shot ACP session on the chat's harness, applies the chat's own
13
+ * model, asks the same classification prompt, and reads the reply. The harness's
14
+ * own config/env (and therefore its own tools and MCP setup) is what runs — no
15
+ * omp RPC child is involved.
16
+ *
17
+ * The session is disposable: no registry entry, no stream row, no title, no
18
+ * goal driver. Only the assistant text is kept.
19
+ */
20
+
21
+ import { AcpSession } from '@/server/lib/harness/acp/session';
22
+ import { loadHarnessConfig, resolveLaunch } from '@/server/lib/harness/config.server';
23
+ import { sessionLaunchCommand } from '@/server/lib/harness/launch';
24
+ import {
25
+ buildGoalAuditPrompt,
26
+ readGoalAuditAnswers,
27
+ type GoalAuditAnswers,
28
+ } from '@/server/lib/omp/session/goal-auditor.server';
29
+ import { extractTextFromContent } from '@/shared/lib/omp/session/mapper';
30
+ import type { HarnessId } from '@/shared/lib/harness/catalog';
31
+ import type { AgentEvent } from '@/server/lib/omp/rpc/constants';
32
+
33
+ export interface AcpGoalAuditRequest {
34
+ harness: HarnessId;
35
+ cwd: string;
36
+ /** The chat's own model, as the agent resolved it. */
37
+ model: { provider: string; modelId: string } | null;
38
+ objective: string;
39
+ answer: string;
40
+ timeoutMs?: number;
41
+ }
42
+
43
+ /** How long one audit may take. The harness may be slower than print mode. */
44
+ const DEFAULT_TIMEOUT_MS = 90_000;
45
+
46
+ /**
47
+ * Ask the ACP agent to classify the last turn's report.
48
+ *
49
+ * Null means the check could not be taken (launch failure, timeout, no usable
50
+ * reply); the driver treats that the same way it treats an omp audit failure.
51
+ */
52
+ export async function runAcpGoalAudit(request: AcpGoalAuditRequest): Promise<GoalAuditAnswers | null> {
53
+ let launch;
54
+ try {
55
+ const configured = await loadHarnessConfig(request.harness);
56
+ launch = resolveLaunch(request.harness, configured);
57
+ } catch {
58
+ return null;
59
+ }
60
+
61
+ const session = new AcpSession(
62
+ {
63
+ harness: request.harness,
64
+ command: sessionLaunchCommand(request.harness, launch.command),
65
+ ...(launch.env ? { env: launch.env } : {}),
66
+ model: request.model,
67
+ // A classification, not a task: the cheapest level the agent offers.
68
+ thinkingLevel: 'off',
69
+ accessMode: 'yolo',
70
+ },
71
+ request.cwd,
72
+ );
73
+ // A disposable reader: no stream row, no turn settle, no queue, no title.
74
+ session.markStream = () => {};
75
+ session.onTurnEnded = () => {};
76
+
77
+ const events: AgentEvent[] = [];
78
+ session.onEvent((event) => events.push(event));
79
+ const ended = Promise.withResolvers<void>();
80
+ const stop = session.onEvent((event) => {
81
+ if (event.type === 'agent_end') ended.resolve();
82
+ });
83
+ const timer = setTimeout(() => {
84
+ void session.destroyAndWait();
85
+ ended.resolve();
86
+ }, request.timeoutMs ?? DEFAULT_TIMEOUT_MS);
87
+
88
+ try {
89
+ await session.start();
90
+ // `synthetic` keeps the audit prompt from becoming this session's title.
91
+ await session.send({
92
+ type: 'prompt',
93
+ message: buildGoalAuditPrompt(request.objective, request.answer),
94
+ synthetic: true,
95
+ });
96
+ await ended.promise;
97
+ const message = [...events].reverse().find((event) => event.type === 'message_end')?.message;
98
+ if (!message || typeof message !== 'object' || !('content' in message)) return null;
99
+ return readGoalAuditAnswers(extractTextFromContent((message as { content: unknown }).content));
100
+ } catch {
101
+ return null;
102
+ } finally {
103
+ clearTimeout(timer);
104
+ stop();
105
+ await session.destroyAndWait().catch(() => {});
106
+ }
107
+ }
@@ -0,0 +1,153 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * The goal loop for an ACP chat.
8
+ *
9
+ * The RPC driver obeys a `/kabmo-mode goal continue` answered by the child's
10
+ * extension; ACP has no such extension, so this driver opens the next turn
11
+ * itself after auditing the last one. The DECISION is shared with the RPC path
12
+ * (`decideGoalProgress`, `runGoalAudit`, `readGoalSettings`), because a goal
13
+ * must not mean two different things depending on the transport.
14
+ *
15
+ * It runs from the ACP turn's terminal settle — the only moment that knows the
16
+ * answer is complete. A turn that is already busy (a queued follow-up, an
17
+ * approval dialog) is left alone: the next turn end drives again, so a skip is
18
+ * a delay, not a stopped goal.
19
+ */
20
+
21
+ import {
22
+ AUDIT_FAILURE_LIMIT,
23
+ BLOCKED_STRIKE_LIMIT,
24
+ lastAssistantText,
25
+ } from '@/server/lib/omp/session/goal-driver.server';
26
+ import { decideGoalProgress, type GoalAuditAnswers } from '@/server/lib/omp/session/goal-auditor.server';
27
+ import { readGoalSettings } from '@/server/lib/omp/session/goal-settings.server';
28
+ import { runAcpGoalAudit, type AcpGoalAuditRequest } from '@/server/lib/harness/acp/acp-audit.server';
29
+ import type { GoalContinuationStop } from '@/shared/lib/omp/mode/types';
30
+ import {
31
+ continueAcpGoal,
32
+ finishAcpGoal,
33
+ type AcpGoalHost,
34
+ } from '@/server/lib/harness/acp/acp-goal.server';
35
+ import { hasAcpGoalSession, loadAcpGoalState } from '@/server/lib/harness/acp/acp-goal-state.server';
36
+
37
+ interface DriverState {
38
+ goalId: string;
39
+ strikes: number;
40
+ failures: number;
41
+ running: boolean;
42
+ }
43
+
44
+ function store(): Map<string, DriverState> {
45
+ const global = globalThis as unknown as { __kabmoAcpGoalDriver?: Map<string, DriverState> };
46
+ global.__kabmoAcpGoalDriver ??= new Map();
47
+ return global.__kabmoAcpGoalDriver;
48
+ }
49
+
50
+ /** An explicit Resume is a fresh audit record. */
51
+ export function resetAcpGoalDriver(sessionId: string): void {
52
+ store().delete(sessionId);
53
+ }
54
+
55
+ function evaluating(host: AcpGoalHost, on: boolean): void {
56
+ host.emit({ type: 'goal_evaluating', evaluating: on });
57
+ }
58
+
59
+ export interface AcpGoalDriverDeps {
60
+ audit?: (request: AcpGoalAuditRequest) => Promise<GoalAuditAnswers | null>;
61
+ settings?: typeof readGoalSettings;
62
+ }
63
+
64
+ /**
65
+ * One decision after one completed ACP turn.
66
+ *
67
+ * `message` is the assistant message the mapper closed. A cancelled turn has no
68
+ * report to audit and must not spend a model call, so callers pass the stop
69
+ * reason and this returns early for it.
70
+ */
71
+ export async function driveAcpGoalAfterTurn(
72
+ host: AcpGoalHost,
73
+ message: unknown,
74
+ options: { cancelled?: boolean; deps?: AcpGoalDriverDeps } = {},
75
+ ): Promise<void> {
76
+ if (options.cancelled) return;
77
+ if (!host.isAlive()) return;
78
+ // The common case: this chat never had a goal, so no DB read is needed.
79
+ if (!hasAcpGoalSession(host.sessionId)) return;
80
+ const state = await loadAcpGoalState(host.sessionId);
81
+ if (!state.record || state.record.status !== 'active') {
82
+ store().delete(host.sessionId);
83
+ return;
84
+ }
85
+ if (state.continuation?.stopped) return;
86
+ const used = host.usageTokens ?? state.record.tokensUsed;
87
+ if (state.record.tokenBudget !== undefined && used >= state.record.tokenBudget) {
88
+ await finishAcpGoal(host, 'budget');
89
+ return;
90
+ }
91
+
92
+ const settings = await (options.deps?.settings ?? readGoalSettings)();
93
+ if (!settings.auditEnabled) return;
94
+
95
+ const answer = lastAssistantText([message]);
96
+ if (!answer) return;
97
+
98
+ const states = store();
99
+ const previous = states.get(host.sessionId);
100
+ const driver: DriverState = previous && previous.goalId === state.record.id
101
+ ? previous
102
+ : { goalId: state.record.id, strikes: 0, failures: 0, running: false };
103
+ states.set(host.sessionId, driver);
104
+ if (driver.running) return;
105
+
106
+ const audit = options.deps?.audit ?? runAcpGoalAudit;
107
+
108
+ driver.running = true;
109
+ evaluating(host, true);
110
+ let answers: GoalAuditAnswers | null;
111
+ try {
112
+ answers = await audit({
113
+ harness: host.harness,
114
+ cwd: host.cwd,
115
+ model: host.runModel,
116
+ objective: state.record.objective,
117
+ answer,
118
+ });
119
+ } finally {
120
+ driver.running = false;
121
+ evaluating(host, false);
122
+ }
123
+
124
+ const stop = (reason: GoalContinuationStop) => finishAcpGoal(host, reason);
125
+
126
+ if (!answers) {
127
+ driver.failures += 1;
128
+ if (driver.failures >= AUDIT_FAILURE_LIMIT) {
129
+ await stop('audit-failed');
130
+ return;
131
+ }
132
+ await continueAcpGoal(host);
133
+ return;
134
+ }
135
+
136
+ driver.failures = 0;
137
+ const verdict = decideGoalProgress(answers);
138
+ if (verdict === 'complete') {
139
+ await stop('complete');
140
+ return;
141
+ }
142
+ if (verdict === 'blocked') {
143
+ driver.strikes += 1;
144
+ if (driver.strikes >= BLOCKED_STRIKE_LIMIT) {
145
+ await stop('blocked');
146
+ return;
147
+ }
148
+ await continueAcpGoal(host);
149
+ return;
150
+ }
151
+ driver.strikes = 0;
152
+ await continueAcpGoal(host);
153
+ }
@@ -0,0 +1,136 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * The persisted goal record for an ACP chat.
8
+ *
9
+ * A non-omp ACP agent has no `/kabmo-mode` extension and no transcript Kabmo
10
+ * can read, so the composer's goal actions write this row and the driver reads
11
+ * it after every turn. The shape is omp's `GoalRecord`, which lets the existing
12
+ * strip, markers and reload logic work unchanged.
13
+ */
14
+
15
+ import { getDb } from '@/server/db.server';
16
+ import type { GoalContinuation, GoalRecord } from '@/shared/lib/omp/mode/types';
17
+
18
+ /** The row, as the composer and the driver read it. */
19
+ export interface AcpGoalState {
20
+ record: GoalRecord | null;
21
+ continuation: GoalContinuation | null;
22
+ /** Mirrored plan mode, for a session whose agent is no longer live. */
23
+ plan: boolean;
24
+ maxTurns: number | null;
25
+ /** Automatic turns taken for the CURRENT goal. */
26
+ turns: number;
27
+ }
28
+
29
+ const EMPTY: AcpGoalState = { record: null, continuation: null, plan: false, maxTurns: null, turns: 0 };
30
+
31
+ /**
32
+ * Sessions this process has SEEN with a goal row. It gates the turn-end driver
33
+ * so an ordinary ACP turn does not open the database at all — the common case —
34
+ * and a test that never created a goal never touches the developer's real DB.
35
+ * A restart repopulates it when the chat's modes are read on open.
36
+ */
37
+ function goalSessions(): Set<string> {
38
+ const global = globalThis as unknown as { __kabmoAcpGoalSessions?: Set<string> };
39
+ global.__kabmoAcpGoalSessions ??= new Set();
40
+ return global.__kabmoAcpGoalSessions;
41
+ }
42
+
43
+ export function noteAcpGoalSession(sessionId: string): void {
44
+ goalSessions().add(sessionId);
45
+ }
46
+
47
+ export function hasAcpGoalSession(sessionId: string): boolean {
48
+ return goalSessions().has(sessionId);
49
+ }
50
+
51
+ /** The default ceiling the extension uses when none is stored. */
52
+ export const DEFAULT_GOAL_MAX_TURNS = 25;
53
+
54
+ function parseRecord(raw: unknown): GoalRecord | null {
55
+ if (typeof raw !== 'string' || !raw) return null;
56
+ try {
57
+ const value: unknown = JSON.parse(raw);
58
+ if (!value || typeof value !== 'object' || Array.isArray(value)) return null;
59
+ const record = value as Record<string, unknown>;
60
+ if (typeof record.id !== 'string' || typeof record.objective !== 'string') return null;
61
+ return record as unknown as GoalRecord;
62
+ } catch {
63
+ return null;
64
+ }
65
+ }
66
+
67
+ function parseContinuation(raw: unknown): GoalContinuation | null {
68
+ if (typeof raw !== 'string' || !raw) return null;
69
+ try {
70
+ const value: unknown = JSON.parse(raw);
71
+ if (!value || typeof value !== 'object' || Array.isArray(value)) return null;
72
+ const entry = value as Record<string, unknown>;
73
+ if (!Number.isInteger(entry.turn) || !Number.isInteger(entry.maxTurns)) return null;
74
+ return entry as unknown as GoalContinuation;
75
+ } catch {
76
+ return null;
77
+ }
78
+ }
79
+
80
+ export async function loadAcpGoalState(sessionId: string): Promise<AcpGoalState> {
81
+ try {
82
+ const db = await getDb();
83
+ const row = await db.get(
84
+ 'SELECT record, continuation, plan, max_turns, turns FROM harness_goal_state WHERE session_id = ?',
85
+ [sessionId],
86
+ );
87
+ if (!row) return { ...EMPTY };
88
+ const record = parseRecord(row.record);
89
+ if (record) noteAcpGoalSession(sessionId);
90
+ return {
91
+ record,
92
+ continuation: parseContinuation(row.continuation),
93
+ plan: row.plan === 1,
94
+ maxTurns: typeof row.max_turns === 'number' ? row.max_turns : null,
95
+ turns: typeof row.turns === 'number' ? row.turns : 0,
96
+ };
97
+ } catch {
98
+ return { ...EMPTY };
99
+ }
100
+ }
101
+
102
+ export async function saveAcpGoalState(sessionId: string, state: AcpGoalState): Promise<void> {
103
+ if (state.record) noteAcpGoalSession(sessionId);
104
+ try {
105
+ const db = await getDb();
106
+ await db.run(
107
+ `INSERT INTO harness_goal_state
108
+ (session_id, record, continuation, plan, max_turns, turns, updated_at)
109
+ VALUES (?, ?, ?, ?, ?, ?, ?)
110
+ ON CONFLICT(session_id) DO UPDATE SET
111
+ record = excluded.record,
112
+ continuation = excluded.continuation,
113
+ plan = excluded.plan,
114
+ max_turns = excluded.max_turns,
115
+ turns = excluded.turns,
116
+ updated_at = excluded.updated_at`,
117
+ [
118
+ sessionId,
119
+ state.record ? JSON.stringify(state.record) : null,
120
+ state.continuation ? JSON.stringify(state.continuation) : null,
121
+ state.plan ? 1 : 0,
122
+ state.maxTurns,
123
+ state.turns,
124
+ Date.now(),
125
+ ],
126
+ );
127
+ } catch {
128
+ // Mode state is best-effort here; the live process still answers.
129
+ }
130
+ }
131
+
132
+ /** Persist only the mirrored plan flag (a live selector remains authoritative). */
133
+ export async function saveAcpPlanState(sessionId: string, plan: boolean): Promise<void> {
134
+ const state = await loadAcpGoalState(sessionId);
135
+ await saveAcpGoalState(sessionId, { ...state, plan });
136
+ }