@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,187 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * The harness catalog is ONE store, shared by every surface that reads it.
8
+ *
9
+ * Two mounted surfaces ask `GET /api/harness` at the same time — the composer's
10
+ * tab strip and Settings → Harnesses — and each used to hold its own
11
+ * `useState`. The probes therefore lived in whichever instance ran them:
12
+ * pressing **Check status** on `opencode` wrote its model list into the SETTINGS
13
+ * copy and the picker went on saying "This harness has not reported its models
14
+ * yet". Measured in a browser: probe in Settings, switch to the composer, zero
15
+ * rows; reload the page, 96 rows — the answer only LOOKED fresh because the
16
+ * server had cached it and the reload re-read the cache.
17
+ *
18
+ * So the assertions are about SHARING, not about fetching:
19
+ *
20
+ * - a probe made from one mount is visible from another, with no reload;
21
+ * - one catalog read serves every mount (one request, not one per hook call);
22
+ * - a mount that arrives after the read still sees the catalog.
23
+ */
24
+
25
+ import { afterEach, beforeEach, describe, expect, test } from 'bun:test';
26
+ import { Window } from 'happy-dom';
27
+ import { h, render } from 'preact';
28
+ import { act } from 'preact/test-utils';
29
+
30
+ import { resetHarnessesStore } from '@/client/hooks/models/harness-catalog';
31
+ import { useHarnesses } from '@/client/hooks/models/use-harnesses';
32
+ import { installDomGlobals, restoreDomGlobals } from '@/test-support/pristine-globals';
33
+
34
+ const OPENCODE_UNPROBED = {
35
+ id: 'opencode',
36
+ label: 'opencode',
37
+ transport: 'acp',
38
+ canLaunch: true,
39
+ probe: null,
40
+ };
41
+
42
+ const OPENCODE_PROBED = {
43
+ harness: 'opencode',
44
+ capabilities: {
45
+ configModel: 96, configThinking: 6, configMode: 4, modeValues: ['build', 'plan'],
46
+ loadSession: true, listSessions: true, forkSession: true, deleteSession: true,
47
+ resumeSession: true, closeSession: true, hasUsage: false, hasPlan: false, steerMode: null,
48
+ },
49
+ models: [{ value: 'command-code/deepseek/deepseek-v4-flash', name: 'DeepSeek V4 Flash' }],
50
+ thinking: [],
51
+ modes: [],
52
+ probedAt: Date.now(),
53
+ };
54
+
55
+ /** The runner's own `fetch`, captured at module load — before this file's first
56
+ * stub exists — so teardown puts back the real one. `Bun.fetch` is the stable
57
+ * handle; a local `const` would capture whatever the PREVIOUS suite left. */
58
+ const realFetch = Bun.fetch;
59
+
60
+ let container: HTMLElement;
61
+ let calls: string[] = [];
62
+
63
+ beforeEach(() => {
64
+ installDomGlobals(new Window({ url: 'http://localhost' }));
65
+ // The store is module state on purpose (that is the fix); a test file starts
66
+ // it cold so each case states its own preconditions.
67
+ resetHarnessesStore();
68
+ container = document.createElement('div');
69
+ document.body.append(container);
70
+ calls = [];
71
+ });
72
+
73
+ afterEach(() => {
74
+ render(null, container);
75
+ container.remove();
76
+ restoreDomGlobals();
77
+ (globalThis as unknown as Record<string, unknown>).fetch = realFetch;
78
+ });
79
+
80
+ /** A `fetch` that answers the catalog and records every request. */
81
+ function stubFetch(): void {
82
+ (globalThis as unknown as Record<string, unknown>).fetch = async (input: unknown, init?: { method?: string }) => {
83
+ const url = String(input);
84
+ calls.push(`${init?.method ?? 'GET'} ${url}`);
85
+ if (init?.method === 'POST') {
86
+ return new Response(JSON.stringify({ probe: OPENCODE_PROBED }), { status: 200 });
87
+ }
88
+ return new Response(JSON.stringify({ harnesses: [OPENCODE_UNPROBED] }), { status: 200 });
89
+ };
90
+ }
91
+
92
+ /**
93
+ * Mount one `useHarnesses()` consumer and hand back the value it last RENDERED.
94
+ *
95
+ * Read from render output, not from a call: a hook can only be called while a
96
+ * component is rendering, and the store's whole job is to make that render run
97
+ * again when a probe lands.
98
+ */
99
+ function mountConsumer(): { read: () => ReturnType<typeof useHarnesses> } {
100
+ const box = { latest: null as ReturnType<typeof useHarnesses> | null };
101
+ function Consumer() {
102
+ box.latest = useHarnesses();
103
+ return null;
104
+ }
105
+ const host = document.createElement('div');
106
+ container.appendChild(host);
107
+ // Inside `act`: the hook's effect fires the stub `fetch`, and Preact needs the
108
+ // scheduler flushed for the resulting state to reach a render.
109
+ act(() => render(h(Consumer, {}), host));
110
+ return {
111
+ read: () => {
112
+ if (!box.latest) throw new Error('consumer did not render');
113
+ return box.latest;
114
+ },
115
+ };
116
+ }
117
+
118
+ /**
119
+ * Let the stub's promises settle.
120
+ *
121
+ * Awaiting a resolved promise, not a timer: the store's `fetch` stub answers
122
+ * immediately, so the pending work IS the microtask queue. A sleep here would
123
+ * buy the same result at a fixed latency on every run and hide which condition
124
+ * the case actually waited for.
125
+ */
126
+ async function flush(): Promise<void> {
127
+ // `act` with an async callback drains the microtask queue between renders, so
128
+ // the stub's promise chain (fetch → json → emit → setState) lands before the
129
+ // assertions read. No timer: nothing here waits on wall-clock time.
130
+ await act(async () => {
131
+ await Promise.resolve();
132
+ await Promise.resolve();
133
+ await Promise.resolve();
134
+ });
135
+ }
136
+
137
+ describe('useHarnesses is one shared store', () => {
138
+ test('two mounts share ONE catalog read', async () => {
139
+ stubFetch();
140
+ const first = mountConsumer();
141
+ const second = mountConsumer();
142
+ await flush();
143
+
144
+ expect(first.read().harnesses).toHaveLength(1);
145
+ expect(second.read().harnesses).toHaveLength(1);
146
+ // The second mount joined the in-flight read rather than firing its own.
147
+ expect(calls.filter((call) => call.startsWith('GET'))).toHaveLength(1);
148
+ });
149
+
150
+ test('a probe from one mount is visible from the other, with no reload', async () => {
151
+ // This is the bug, exactly: Settings probed, the picker never learned.
152
+ stubFetch();
153
+ const settings = mountConsumer();
154
+ const picker = mountConsumer();
155
+ await flush();
156
+ expect(picker.read().harnesses[0].probe).toBeNull();
157
+
158
+ await act(async () => {
159
+ await settings.read().probe('opencode');
160
+ });
161
+
162
+ // Both surfaces see the 96 models, and the picker did not re-fetch to get
163
+ // them — the store pushes them.
164
+ expect(picker.read().harnesses[0].probe?.capabilities.configModel).toBe(96);
165
+ expect(settings.read().harnesses[0].probe?.capabilities.configModel).toBe(96);
166
+ });
167
+
168
+ test('a mount that arrives AFTER the read still sees the catalog', async () => {
169
+ stubFetch();
170
+ const early = mountConsumer();
171
+ await flush();
172
+
173
+ const late = mountConsumer();
174
+ await flush();
175
+ expect(late.read().harnesses).toHaveLength(1);
176
+ expect(early.read().error).toBeNull();
177
+ });
178
+
179
+ test('a failed read is reported, never papered over with an empty list claim', async () => {
180
+ (globalThis as unknown as Record<string, unknown>).fetch = async () => new Response('nope', { status: 500 });
181
+ const consumer = mountConsumer();
182
+ await flush();
183
+ expect(consumer.read().error).toContain('500');
184
+ // A failed read REPORTS; it does not claim "no harnesses installed".
185
+ expect(consumer.read().isLoading).toBe(false);
186
+ });
187
+ });
@@ -0,0 +1,215 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * The harness catalog as ONE shared store, not one store per hook call.
8
+ *
9
+ * `GET /api/harness` is read by two mounted surfaces at once — the composer's
10
+ * tab strip and Settings → Harnesses — and they used to hold a `useState` each.
11
+ * Probes then lived in whichever instance ran them: pressing **Check status** on
12
+ * `opencode2` wrote the 96 models into the SETTINGS copy, and the picker went on
13
+ * showing "This harness has not reported its models yet" until the page was
14
+ * reloaded. Measured in a browser: probe in Settings, switch to the composer,
15
+ * zero rows; reload, 96 rows. The answer only looked fresh because the SERVER
16
+ * cached it and the new page load re-read the cache.
17
+ *
18
+ * The store is module state for the reason the rest of this codebase states: it
19
+ * is a property of the installed agents, shared by every surface on the page.
20
+ * `probe()` therefore notifies every subscriber instead of returning a value one
21
+ * caller happens to keep.
22
+ */
23
+
24
+ import { useEffect, useState } from 'preact/hooks';
25
+ import type { HarnessConfig, HarnessSummary, LiveHarnessModels } from '@/shared/types/harness';
26
+ import type { HarnessesController } from '@/client/hooks/models/use-harnesses-controller';
27
+ import {
28
+ emit, invalidateCatalog, listeners, loadCatalog, store,
29
+ } from '@/client/hooks/models/harness-catalog';
30
+ import { addProvider, importProvider } from '@/client/hooks/models/provider-writes';
31
+ import { subscribeModelsUpdated } from '@/shared/lib/models/client';
32
+
33
+ /**
34
+ * Record the selectors a LIVE chat published for its harness.
35
+ *
36
+ * Called by the session loader on every session read, so the guard matters: an
37
+ * unchanged list must not notify every picker subscriber (the metadata refresh
38
+ * runs a few times per chat).
39
+ */
40
+ export function publishLiveModels(id: string, live: LiveHarnessModels): void {
41
+ if (!id || live.models.length === 0) return;
42
+ const current = store.liveModels[id];
43
+ if (current && sameSelectors(current, live)) return;
44
+ emit({ liveModels: { ...store.liveModels, [id]: live } });
45
+ }
46
+
47
+ function sameSelectors(a: LiveHarnessModels, b: LiveHarnessModels): boolean {
48
+ const keys = (list?: readonly { value: string; name: string }[]) =>
49
+ (list ?? []).map((entry) => `${entry.value}\u0000${entry.name}`).join('\u0001');
50
+ return a.models.length === b.models.length
51
+ && keys(a.models) === keys(b.models)
52
+ && keys(a.thinking) === keys(b.thinking);
53
+ }
54
+
55
+ /** Fold a landed provider write back into the store and re-read the catalog. */
56
+ function announceProviderWrite(
57
+ id: string,
58
+ config?: HarnessConfig,
59
+ probeInvalidated?: readonly string[],
60
+ ): void {
61
+ if (config) emit({ configs: { ...store.configs, [id]: config } });
62
+ // The write landed in a FILE, which is the only thing that proves it, so the
63
+ // list is re-read rather than patched: a card that kept the previous list would
64
+ // show "nothing added" after a successful add. The store caches its first
65
+ // answer on purpose, so the re-read has to clear it.
66
+ void invalidateCatalog().then(() => {
67
+ // The server names every tab whose probe measured the OLD file. Ask each
68
+ // launchable one to answer now, so the picker offers the new models without
69
+ // a manual "Check status". The built-in transport has no agent to probe.
70
+ for (const target of probeInvalidated ?? []) {
71
+ const entry = store.harnesses.find((harness) => harness.id === target);
72
+ if (!entry || entry.builtIn || entry.unavailable) continue;
73
+ void probeHarness(target);
74
+ }
75
+ });
76
+ }
77
+
78
+ /** One probe, shared: the settings page's "check status" and the tab strip's
79
+ * click on a blocked harness both land here. Returns the agent's own refusal,
80
+ * or null on success. */
81
+ async function probeHarness(id: string, cwd?: string): Promise<string | null> {
82
+ try {
83
+ const response = await fetch('/api/harness', {
84
+ method: 'POST',
85
+ headers: { 'Content-Type': 'application/json' },
86
+ body: JSON.stringify({ probe: id, ...(cwd ? { cwd } : {}) }),
87
+ });
88
+ const payload = (await response.json()) as { probe?: HarnessSummary['probe']; error?: string };
89
+ if (!response.ok || !payload.probe) return payload.error ?? `Probe failed (HTTP ${response.status})`;
90
+ const probed = payload.probe;
91
+ emit({
92
+ harnesses: store.harnesses.map((entry) => (entry.id === id ? { ...entry, probe: probed } : entry)),
93
+ });
94
+ return probed.capabilities.blocked ?? null;
95
+ } catch (cause) {
96
+ return cause instanceof Error ? cause.message : 'Probe failed';
97
+ }
98
+ }
99
+
100
+ /**
101
+ * Save one harness's config and fold the server's answer back in.
102
+ *
103
+ * The server's shape, not the draft's: a value it normalised (or refused) must
104
+ * be what the card shows next, or the form and the spawn disagree.
105
+ */
106
+ async function saveHarnessConfig(id: string, config: HarnessConfig): Promise<string | null> {
107
+ try {
108
+ const response = await fetch('/api/harness', {
109
+ method: 'POST',
110
+ headers: { 'Content-Type': 'application/json' },
111
+ body: JSON.stringify({ probe: id, config }),
112
+ });
113
+ const payload = (await response.json()) as {
114
+ config?: HarnessConfig;
115
+ probeInvalidated?: boolean;
116
+ error?: string;
117
+ };
118
+ if (!response.ok || !payload.config) return payload.error ?? `Save failed (HTTP ${response.status})`;
119
+ emit({ configs: { ...store.configs, [id]: payload.config } });
120
+ // The SERVER decides whether the last probe still describes this harness —
121
+ // only a changed command or env does not. Nulling it on every save collapsed
122
+ // the provider/model pickers into free-text fields the moment a default was
123
+ // stored.
124
+ if (payload.probeInvalidated) {
125
+ emit({ harnesses: store.harnesses.map((entry) => (entry.id === id ? { ...entry, probe: null } : entry)) });
126
+ }
127
+ return null;
128
+ } catch (cause) {
129
+ return cause instanceof Error ? cause.message : 'Save failed';
130
+ }
131
+ }
132
+
133
+ /**
134
+ * Switch one harness on or off.
135
+ *
136
+ * The server owns the roster (it is the only writer of `omp_harness_disabled`),
137
+ * so its answer is folded back in rather than the draft: a refusal has to leave
138
+ * the switch where the server actually has it.
139
+ *
140
+ * The switch SUCCEEDS for an agent that is not installed — that is a roster
141
+ * decision, and the user may want the tab before they install the binary. A
142
+ * probe rides the same response only when the server could actually run one, so
143
+ * an absent `probe` means "nothing new was measured", never "the switch failed".
144
+ */
145
+ async function setHarnessEnabled(id: string, enabled: boolean): Promise<string | null> {
146
+ try {
147
+ const response = await fetch('/api/harness', {
148
+ method: 'POST',
149
+ headers: { 'Content-Type': 'application/json' },
150
+ body: JSON.stringify({ probe: id, enabled }),
151
+ });
152
+ const payload = (await response.json()) as {
153
+ enabled?: boolean;
154
+ probe?: HarnessSummary['probe'];
155
+ error?: string;
156
+ };
157
+ if (!response.ok || typeof payload.enabled !== 'boolean') {
158
+ return payload.error ?? `Switch failed (HTTP ${response.status})`;
159
+ }
160
+ emit({
161
+ harnesses: store.harnesses.map((entry) => {
162
+ if (entry.id !== id) return entry;
163
+ const next = { ...entry, enabled: payload.enabled as boolean };
164
+ // An absent probe means the server measured nothing: either this was a
165
+ // switch OFF, or the binary is not installed so it did not spawn one.
166
+ // Neither says anything about what the agent can do, so the stored
167
+ // record stays exactly as it was.
168
+ return payload.probe === undefined ? next : { ...next, probe: payload.probe };
169
+ }),
170
+ });
171
+ return null;
172
+ } catch (cause) {
173
+ return cause instanceof Error ? cause.message : 'Switch failed';
174
+ }
175
+ }
176
+
177
+ export function useHarnesses(): HarnessesController {
178
+ const [snapshot, setSnapshot] = useState(() => ({ ...store }));
179
+
180
+ useEffect(() => {
181
+ const sync = () => setSnapshot({ ...store });
182
+ listeners.add(sync);
183
+ // A subscriber that arrives after the first read has to see the catalog the
184
+ // first one already loaded, or the second surface renders empty forever.
185
+ sync();
186
+ void loadCatalog();
187
+ // A provider/model write republishes the `models` topic. The ACP pickers read
188
+ // PROBES, which the server refreshed on the same write, so the cached
189
+ // catalog is stale in exactly the same way the model list is.
190
+ const offModels = subscribeModelsUpdated(() => {
191
+ void invalidateCatalog();
192
+ });
193
+ return () => {
194
+ listeners.delete(sync);
195
+ offModels();
196
+ };
197
+ }, []);
198
+
199
+ return {
200
+ harnesses: snapshot.harnesses,
201
+ configs: snapshot.configs,
202
+ saveConfig: saveHarnessConfig,
203
+ providerSupport: snapshot.providerSupport,
204
+ liveModels: snapshot.liveModels,
205
+ importProvider: (id, sourceId, entry) => importProvider(id, sourceId, entry, announceProviderWrite),
206
+ addProvider: (id, input) => addProvider(id, input, announceProviderWrite),
207
+ isLoading: snapshot.isLoading,
208
+ error: snapshot.error,
209
+ reload: () => {
210
+ void invalidateCatalog();
211
+ },
212
+ probe: probeHarness,
213
+ setEnabled: setHarnessEnabled,
214
+ };
215
+ }
@@ -45,7 +45,7 @@ export function useProviderSettings({
45
45
  const [isRefreshingList, setIsRefreshingList] = useState(false);
46
46
  const [isFetchingModels, setIsFetchingModels] = useState(false);
47
47
  const [isRefreshingIcon, setIsRefreshingIcon] = useState(false);
48
- const { toasts, pushToast, dismissToast } = useToasts();
48
+ const { pushToast } = useToasts();
49
49
 
50
50
  const [isAddModalOpen, setIsAddModalOpen] = useState(autoOpenAdd);
51
51
  const [isAddModelModalOpen, setIsAddModelModalOpen] = useState(false);
@@ -237,9 +237,7 @@ export function useProviderSettings({
237
237
  isFetchingModels,
238
238
  isRefreshingIcon,
239
239
  handleRefreshIcon,
240
- toasts,
241
240
  pushToast,
242
- dismissToast,
243
241
  isAddModelModalOpen,
244
242
  setIsAddModelModalOpen,
245
243
  handleModelAdded,
@@ -26,10 +26,17 @@ import { useKabmoEvent } from '@/client/hooks/ui/window-event';
26
26
  import { EDITOR_ERROR_EVENT } from '@/client/lib/editor-errors';
27
27
 
28
28
  /** What `pushToast` accepts, named so this hook does not import the toast host. */
29
- type PushToast = (message: string, type?: 'success' | 'error', options?: { duration?: number }) => void;
29
+ type PushToast = (
30
+ message: string,
31
+ type?: 'success' | 'error',
32
+ options?: { duration?: number | null },
33
+ ) => void;
30
34
 
31
- /** Longer than a normal toast: the message is a bug report, not a confirmation. */
32
- const EDITOR_ERROR_TOAST_MS = 8000;
35
+ /**
36
+ * Longer than the policy would give it: the message is a bug report, and the
37
+ * name of a CodeMirror extension plus a stack message is read twice.
38
+ */
39
+ const EDITOR_ERROR_TOAST_MS = 10_000;
33
40
 
34
41
  /** Events already shown by one listener. Weak, so a dispatched event is not retained. */
35
42
  const claimed = new WeakSet<Event>();
@@ -24,6 +24,31 @@ import {
24
24
  ICON_PAINT_STYLE_ELEMENT_ID,
25
25
  iconPaintStyleSheet,
26
26
  } from '@/shared/lib/icons/icon-paint-css';
27
+ import { ICON_PAPER_ATTRIBUTE } from '@/shared/lib/icons/tint';
28
+ import { paperBucketOf } from '@/shared/lib/icons/icon-tone';
29
+ import { resolveTheme } from '@/shared/lib/theme/catalog';
30
+
31
+ /**
32
+ * Point the document at the paper bucket of the palette it is painting.
33
+ *
34
+ * One `ICON_TONES` table had to clear the floor on the DARKEST light paper in
35
+ * the catalog, so a palette with a brighter paper painted every icon at
36
+ * lightness it did not need: measured on the default palette, mean L 0.582 where
37
+ * that paper allows 0.640, against dark's 0.782 — the reported "light mode
38
+ * kusam". The bucket is an ATTRIBUTE rather than a resolved colour so a theme
39
+ * switch only moves one attribute instead of re-stamping every mark on screen.
40
+ */
41
+ export function applyIconPaper(theme?: string): void {
42
+ if (typeof document === 'undefined') return;
43
+ // The palette id is read from the document rather than from `theme.ts`, whose
44
+ // `applyDocumentTheme` is what CALLS this: importing its `currentThemeId`
45
+ // would close a module cycle and leave the export undefined at load.
46
+ const id = theme ?? document.documentElement.dataset.theme ?? '';
47
+ const palette = resolveTheme(id);
48
+ const root = document.documentElement;
49
+ if (palette.variant === 'dark') root.removeAttribute(ICON_PAPER_ATTRIBUTE);
50
+ else root.setAttribute(ICON_PAPER_ATTRIBUTE, paperBucketOf(palette.paper));
51
+ }
27
52
 
28
53
  /**
29
54
  * Point the document at `style`.
@@ -37,6 +62,9 @@ export function applyIconStyle(style: unknown): void {
37
62
  const resolved = resolveIconStyle(style);
38
63
  if (resolved === DEFAULT_ICON_STYLE) root.removeAttribute(ICON_STYLE_ATTRIBUTE);
39
64
  else root.setAttribute(ICON_STYLE_ATTRIBUTE, resolved);
65
+ // The bucket belongs to the same writer: a document that states one style
66
+ // without the other paints a `mid` palette with the `deep` table.
67
+ applyIconPaper();
40
68
  }
41
69
 
42
70
  /**
@@ -0,0 +1,104 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * `useOnClickOutside` must be able to stand DOWN, not just decline to act.
8
+ *
9
+ * The model picker's phone placement portals its overlay to `<body>`, so the
10
+ * overlay is outside the picker's `containerRef` by construction: an armed
11
+ * listener sees the press that was meant to choose a model as an outside press
12
+ * and closes the picker on `mousedown` — before `click` reaches the row. That is
13
+ * the measured "tap a model on a phone and nothing happens".
14
+ *
15
+ * Both directions are pinned here because the flag has to keep working for the
16
+ * nineteen other call sites: armed closes on an outside press and ignores an
17
+ * inside one; disabled ignores both.
18
+ */
19
+
20
+ import { afterEach, beforeEach, describe, expect, test } from 'bun:test';
21
+ import { h, render } from 'preact';
22
+ import { act } from 'preact/test-utils';
23
+ import { Window } from 'happy-dom';
24
+
25
+ import { useOnClickOutside } from '@/client/hooks/ui/on-click-outside';
26
+ import { installDomGlobals, restoreDomGlobals } from '@/test-support/pristine-globals';
27
+
28
+ let container: HTMLElement;
29
+ /** The window under test. `MouseEvent`/`TouchEvent` are not in the installed
30
+ * global list, so the constructors are taken from here — a bare `new MouseEvent`
31
+ * reads the RUNNER's global, which Bun does not define, and dies with
32
+ * `ReferenceError` inside `act()`. */
33
+ let win: Window;
34
+
35
+ beforeEach(() => {
36
+ win = new Window({ url: 'http://localhost' });
37
+ installDomGlobals(win);
38
+ container = document.createElement('div');
39
+ document.body.appendChild(container);
40
+ });
41
+
42
+ afterEach(() => {
43
+ render(null, container);
44
+ container.remove();
45
+ restoreDomGlobals();
46
+ });
47
+
48
+ /** Mounts a box that owns the hook and returns the outside-press counter. */
49
+ function mountBox(enabled: boolean): { outside: () => number; box: HTMLElement } {
50
+ const state = { count: 0 };
51
+ const box = document.createElement('div');
52
+ function Box() {
53
+ const ref = { current: box };
54
+ useOnClickOutside(ref, () => { state.count += 1; }, enabled);
55
+ return h('div', { 'data-testid': 'box' }, 'inside');
56
+ }
57
+ // The ref must point at the element the listener tests membership against, so
58
+ // the component renders INTO it rather than into the harness container.
59
+ document.body.appendChild(box);
60
+ act(() => render(h(Box, {}), box));
61
+ return { outside: () => state.count, box };
62
+ }
63
+
64
+ /**
65
+ * Dispatch a press of one of the two types the hook listens for.
66
+ *
67
+ * Built from the WINDOW UNDER TEST, not the runner's globals: Bun defines
68
+ * neither `MouseEvent` nor `TouchEvent`, so a bare constructor throws
69
+ * `ReferenceError` from inside `act()` and the failure names Preact rather than
70
+ * the test.
71
+ */
72
+ function press(target: Element, type: 'mousedown' | 'touchstart'): void {
73
+ const view = win as unknown as { MouseEvent: new (t: string, i?: unknown) => globalThis.Event;
74
+ TouchEvent: new (t: string, i?: unknown) => globalThis.Event };
75
+ const Ctor = type === 'mousedown' ? view.MouseEvent : view.TouchEvent;
76
+ target.dispatchEvent(new Ctor(type, { bubbles: true }));
77
+ }
78
+
79
+ describe('useOnClickOutside', () => {
80
+ test('armed: an outside press fires it, an inside press does not', () => {
81
+ const { outside } = mountBox(true);
82
+
83
+ act(() => { press(document.body, 'mousedown'); });
84
+ expect(outside()).toBe(1);
85
+
86
+ const inner = document.querySelector('[data-testid="box"]') as HTMLElement;
87
+ act(() => { press(inner, 'mousedown'); });
88
+ expect(outside()).toBe(1);
89
+ });
90
+
91
+ test('disabled: no listener at all, in either direction', () => {
92
+ const { outside } = mountBox(false);
93
+
94
+ act(() => { press(document.body, 'mousedown'); });
95
+ act(() => { press(document.body, 'touchstart'); });
96
+ expect(outside()).toBe(0);
97
+ });
98
+
99
+ test('it listens to touch as well, which is what a phone actually sends', () => {
100
+ const { outside } = mountBox(true);
101
+ act(() => { press(document.body, 'touchstart'); });
102
+ expect(outside()).toBe(1);
103
+ });
104
+ });
@@ -1,11 +1,23 @@
1
1
  import { useEffect } from 'preact/hooks';
2
2
  import type { RefObject } from 'preact/compat';
3
3
 
4
+ /**
5
+ * Run `handler` when a pointer goes down outside `ref`.
6
+ *
7
+ * `enabled: false` detaches the listener entirely rather than letting the
8
+ * handler return early: a surface rendered in a PORTAL is outside `ref` by
9
+ * construction, so every press inside it reads as "outside" and the handler
10
+ * would close the very overlay the press belongs to — measured as a model row
11
+ * that could not be chosen on a phone, because `mousedown` closed the picker
12
+ * before `click` reached the row.
13
+ */
4
14
  export function useOnClickOutside(
5
15
  ref: RefObject<any>,
6
- handler: (event: globalThis.MouseEvent | globalThis.TouchEvent) => void
16
+ handler: (event: globalThis.MouseEvent | globalThis.TouchEvent) => void,
17
+ enabled = true,
7
18
  ) {
8
19
  useEffect(() => {
20
+ if (!enabled) return;
9
21
  const listener = (event: globalThis.MouseEvent | globalThis.TouchEvent) => {
10
22
  if (!ref.current || ref.current.contains(event.target as Node)) {
11
23
  return;
@@ -18,5 +30,5 @@ export function useOnClickOutside(
18
30
  document.removeEventListener('mousedown', listener);
19
31
  document.removeEventListener('touchstart', listener);
20
32
  };
21
- }, [ref, handler]);
33
+ }, [ref, handler, enabled]);
22
34
  }
@@ -20,6 +20,7 @@
20
20
  import { useCallback, useEffect, useState } from 'preact/hooks';
21
21
  import { useKabmoSettingsWriter } from '@/client/hooks/settings/use-kabmo-setting';
22
22
  import { applyWindowChrome } from '@/client/hooks/ui/window-chrome';
23
+ import { applyIconPaper } from '@/client/hooks/ui/icon-style';
23
24
  import { DEFAULT_THEME_ID, resolveTheme } from '@/shared/lib/theme/catalog';
24
25
  import { THEME_STYLE_ELEMENT_ID, themeStyleSheet } from '@/shared/lib/theme/css';
25
26
  import { FIRST_FRAME_STYLE_ELEMENT_ID, firstFrameStyle } from '@/shared/lib/theme/first-frame';
@@ -79,6 +80,11 @@ export function applyDocumentTheme(theme: string): void {
79
80
  const root = document.documentElement;
80
81
  root.dataset.theme = palette.id;
81
82
  root.dataset.themeVariant = palette.variant;
83
+ // The icon tone table is keyed by how bright the paper is, so a palette change
84
+ // has to move this attribute too — otherwise a switch from a deep paper to a
85
+ // bright one keeps the darker table, which is the "light mode kusam" the split
86
+ // exists to remove.
87
+ applyIconPaper(palette.id);
82
88
  // The inline first-frame rule is UNLAYERED, so it outranks `body` in the
83
89
  // bundle at any specificity — which is why it is still the winner after a
84
90
  // runtime switch, and why it has to be rewritten here. Measured: choosing a