@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,212 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * What a provider ENTRY looks like in each registry format.
8
+ *
9
+ * Split from the writer so the shape of six formats sits in one readable table
10
+ * instead of inside a 370-line file. The writer owns the read-modify-write; this
11
+ * module owns "what does an entry look like here", and the two concerns do not
12
+ * need to share a file to agree — `providerEntryFor` is pure.
13
+ *
14
+ * The dialect translation is the subtle half. A source names its wire format in
15
+ * ITS vocabulary (omp's `api`, opencode's `npm` package, kimi's `type`), and the
16
+ * target accepts a different spelling of the same fact. A draft therefore carries
17
+ * the CANONICAL protocol (`dialects.ts`), never the source's word: passing one
18
+ * through blind writes a value the target rejects, and guessing a mapping is how
19
+ * a provider lands in a file the agent then ignores. Measured reasons for the
20
+ * rows below:
21
+ *
22
+ * - codex now accepts `wire_api = "responses"` ONLY. A single `"chat"` entry
23
+ * makes every codex command fail at config load, so a Chat-Completions source
24
+ * is REFUSED here rather than relabelled.
25
+ * - kimi-code's types are `kimi|anthropic|openai|openai_responses|google-genai|
26
+ * vertexai`; the retired CLI's `openai_legacy`/`gemini` spellings are gone.
27
+ * - qwen routes by protocol BUCKET and stores a VARIABLE NAME (`envKey`), so the
28
+ * value has to be injected into `env` or all imported models answer 401.
29
+ */
30
+
31
+ import type { ProviderRegistryKind } from '@/shared/lib/harness/provider-facts';
32
+ import type { CanonicalProtocol } from '@/shared/lib/harness/dialects';
33
+ import { dialectFor, wireApiFor } from '@/shared/lib/harness/dialects';
34
+ import { ProviderWriteError } from '@/server/lib/harness/provider-write-error';
35
+
36
+ /** What an import brings into a target registry. */
37
+ export interface ProviderDraft {
38
+ id: string;
39
+ name: string;
40
+ baseUrl?: string;
41
+ /** The CANONICAL wire protocol, already planned against the target. */
42
+ protocol?: CanonicalProtocol;
43
+ models: string[];
44
+ /** Read from the source at import time; never sent by the browser. */
45
+ apiKey?: string;
46
+ /**
47
+ * Context window per model id, when the source declared one. kimi REQUIRES
48
+ * `max_context_size`, so an import without it cannot produce a usable alias.
49
+ */
50
+ contextWindow?: Record<string, number>;
51
+ }
52
+
53
+ /** A record, or an empty one. Imported documents are untrusted. */
54
+ export function asRecord(value: unknown): Record<string, unknown> {
55
+ return value && typeof value === 'object' && !Array.isArray(value) ? (value as Record<string, unknown>) : {};
56
+ }
57
+
58
+ /** The dialect value a target writes for this draft, or a refusal naming both. */
59
+ function requireDialect(kind: ProviderRegistryKind, draft: ProviderDraft, target: string): string {
60
+ const protocol = draft.protocol;
61
+ if (!protocol) {
62
+ throw new ProviderWriteError(
63
+ `Cannot copy "${draft.id}" into ${target}: the source declares no wire protocol Kabmo can verify, `
64
+ + 'and guessing one writes a provider the agent will fail every request against.',
65
+ );
66
+ }
67
+ const dialect = dialectFor(kind, protocol);
68
+ if (dialect === null) {
69
+ throw new ProviderWriteError(
70
+ `${target} cannot speak ${protocol}: it stores no such dialect. `
71
+ + 'Pick a provider whose endpoint speaks one of the protocols this agent accepts, or keep it in its own agent.',
72
+ );
73
+ }
74
+ return dialect;
75
+ }
76
+
77
+ /**
78
+ * The fields of an EXISTING entry that the import must not overwrite.
79
+ *
80
+ * A stored credential is the one that matters: an import brings an endpoint, and
81
+ * replacing a key the user set by hand is not what asking to copy a provider
82
+ * meant. `npm`/`type`/`wire_api` (the dialect) are kept too — they describe how
83
+ * that provider already works, and the source's dialect is a guess about a
84
+ * different agent.
85
+ *
86
+ * Lives here with the entry builders it mirrors, so the writer is read-modify-
87
+ * write and this module is "what does an entry look like".
88
+ */
89
+ export function pickExisting(existing: Record<string, unknown>, incoming: Record<string, unknown>): Record<string, unknown> {
90
+ const keep: Record<string, unknown> = {};
91
+ const scalarKeys = ['npm', 'type', 'wire_api', 'api', 'name'];
92
+ for (const key of scalarKeys) {
93
+ if (existing[key] !== undefined && incoming[key] !== undefined) keep[key] = existing[key];
94
+ }
95
+ // Credentials, in each format's spelling: a top-level apiKey/api_key, or one
96
+ // nested inside opencode's `options`.
97
+ if (typeof existing.apiKey === 'string' && existing.apiKey) keep.apiKey = existing.apiKey;
98
+ if (typeof existing.api_key === 'string' && existing.api_key) keep.api_key = existing.api_key;
99
+ const existingOptions = asRecord(existing.options);
100
+ const incomingOptions = asRecord(incoming.options);
101
+ if (Object.keys(incomingOptions).length > 0) {
102
+ // `options` is merged key by key, so an endpoint arrives while a stored key
103
+ // and any hand-written option stay.
104
+ keep.options = { ...incomingOptions, ...existingOptions };
105
+ }
106
+ return keep;
107
+ }
108
+
109
+ /** kimi requires a context window per alias; 128k is the documented fallback. */
110
+ const DEFAULT_CONTEXT_WINDOW = 128_000;
111
+
112
+ /**
113
+ * The provider entry in the TARGET format, before merging over what exists.
114
+ *
115
+ * `target` appears only in the refusal messages, so a user reading one knows
116
+ * which agent said no.
117
+ */
118
+ export function providerEntryFor(
119
+ kind: ProviderRegistryKind,
120
+ draft: ProviderDraft,
121
+ target = 'this agent',
122
+ ): Record<string, unknown> {
123
+ const name = draft.name || draft.id;
124
+ switch (kind) {
125
+ case 'yaml-providers':
126
+ return {
127
+ // omp keys the entry by slug and prints the slug; its docs and `omp models`
128
+ // both accept a `name`, so the display name a user typed survives the
129
+ // write instead of being replaced by `my-gateway` in every picker.
130
+ ...(name && name !== draft.id ? { name } : {}),
131
+ baseUrl: draft.baseUrl ?? '',
132
+ ...(draft.apiKey ? { apiKey: draft.apiKey } : {}),
133
+ api: requireDialect(kind, draft, target),
134
+ models: draft.models.map((id) => ({ id })),
135
+ };
136
+ case 'json-provider':
137
+ return {
138
+ npm: requireDialect(kind, draft, target),
139
+ name,
140
+ options: {
141
+ ...(draft.baseUrl ? { baseURL: draft.baseUrl } : {}),
142
+ ...(draft.apiKey ? { apiKey: draft.apiKey } : {}),
143
+ },
144
+ models: Object.fromEntries(draft.models.map((id) => [id, {}])),
145
+ };
146
+ case 'toml-model-providers':
147
+ return {
148
+ name,
149
+ base_url: draft.baseUrl ?? '',
150
+ // codex reads a VARIABLE NAME here, never the key itself. Storing the
151
+ // secret in config.toml would put it in a file its own docs keep out of;
152
+ // the writer injects the value into the harness env instead. The name is
153
+ // per PROVIDER for the same reason it is on qwen: one shared name means
154
+ // the second provider added re-points the first at another key.
155
+ ...(draft.apiKey ? { env_key: `${draft.id.toUpperCase().replace(/[^A-Z0-9]+/g, '_')}_API_KEY` } : {}),
156
+ wire_api: requireDialect(kind, draft, target),
157
+ };
158
+ case 'json-providers':
159
+ return {
160
+ name,
161
+ baseUrl: draft.baseUrl ?? '',
162
+ api: requireDialect(kind, draft, target),
163
+ ...(draft.apiKey ? { apiKey: draft.apiKey } : {}),
164
+ models: draft.models.map((id) => ({ id })),
165
+ };
166
+ case 'toml-providers':
167
+ return {
168
+ type: requireDialect(kind, draft, target),
169
+ base_url: draft.baseUrl ?? '',
170
+ ...(draft.apiKey ? { api_key: draft.apiKey } : {}),
171
+ };
172
+ case 'json-model-providers':
173
+ // qwen's rows ARE models, and the credential is a variable name.
174
+ return {
175
+ id: draft.models[0] ?? draft.id,
176
+ name,
177
+ ...(draft.baseUrl ? { baseUrl: draft.baseUrl } : {}),
178
+ ...(wireApiFor(draft.protocol ?? 'openai-chat') ? { wireApi: wireApiFor(draft.protocol ?? 'openai-chat') } : {}),
179
+ // ONE variable per provider: a fixed name made the second provider added
180
+ // to qwen silently re-point the first at its own key.
181
+ envKey: `${draft.id.toUpperCase().replace(/[^A-Z0-9]+/g, '_')}_API_KEY`,
182
+ };
183
+ default:
184
+ throw new ProviderWriteError('This harness has no provider registry Kabmo writes');
185
+ }
186
+ }
187
+
188
+ /**
189
+ * The `[models.<alias>]` rows a provider needs to serve anything.
190
+ *
191
+ * kimi-code selects models by ALIAS, and an alias requires `provider`, `model`
192
+ * and `max_context_size` — a provider written without them is invisible to the
193
+ * agent's model picker, which is what an import looked like before this existed.
194
+ * The alias is prefixed with the provider id so two providers serving the same
195
+ * model id do not collide, the same way kimi's own imports name them.
196
+ */
197
+ export function modelRowsFor(
198
+ kind: ProviderRegistryKind,
199
+ draft: ProviderDraft,
200
+ ): Record<string, Record<string, unknown>> {
201
+ if (kind !== 'toml-providers' || !draft.models.length) return {};
202
+ const rows: Record<string, Record<string, unknown>> = {};
203
+ for (const modelId of draft.models) {
204
+ const alias = `${draft.id}/${modelId}`;
205
+ rows[alias] = {
206
+ provider: draft.id,
207
+ model: modelId,
208
+ max_context_size: draft.contextWindow?.[modelId] ?? DEFAULT_CONTEXT_WINDOW,
209
+ };
210
+ }
211
+ return rows;
212
+ }
@@ -0,0 +1,67 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * Reading and rewriting a registry FILE, in the format that file is written in.
8
+ *
9
+ * Split from the writer so the write path reads as decisions (which format,
10
+ * which protocol, what must not be overwritten) instead of parse/serialise
11
+ * plumbing. The two concerns do not need one file to agree: `serialise` and
12
+ * `parseDocument` are dispatch tables over `ProviderRegistryKind`, and the
13
+ * writer is their only caller.
14
+ *
15
+ * A file that will not parse is REFUSED rather than replaced: these documents
16
+ * also hold plugins, agents, MCP servers and approval policy, and rewriting one
17
+ * from a value Kabmo failed to read is how a working agent loses its config.
18
+ */
19
+
20
+ import YAML from 'yaml';
21
+ import { parse as parseToml, stringify as stringifyToml } from 'smol-toml';
22
+
23
+ import type { ProviderRegistryKind } from '@/shared/lib/harness/provider-facts';
24
+ import { asRecord } from '@/server/lib/harness/provider-entry';
25
+ import { ProviderWriteError } from '@/server/lib/harness/provider-write-error';
26
+
27
+ /** Serialise a document back in its own format. */
28
+ export function serialise(kind: ProviderRegistryKind, doc: Record<string, unknown>): string {
29
+ switch (kind) {
30
+ case 'yaml-providers': return YAML.stringify(doc);
31
+ case 'toml-model-providers':
32
+ case 'toml-providers': return `${stringifyToml(doc)}\n`;
33
+ // The desktop's own writer emits two-space JSON with NO trailing newline;
34
+ // a non-canonical file is read fine but rewritten on the app's next save.
35
+ case 'zcode-provider-rules': return JSON.stringify(doc, null, 2);
36
+ default: return `${JSON.stringify(doc, null, 2)}\n`;
37
+ }
38
+ }
39
+
40
+ /** Parse a document in its own format, or throw with the reason. */
41
+ export function parseDocument(kind: ProviderRegistryKind, text: string, path: string): Record<string, unknown> {
42
+ try {
43
+ const parsed = kind === 'yaml-providers'
44
+ ? YAML.parse(text)
45
+ : kind === 'toml-model-providers' || kind === 'toml-providers'
46
+ ? parseToml(text)
47
+ : JSON.parse(text);
48
+ if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) {
49
+ throw new ProviderWriteError(`${path} is not a document, so it was left untouched`);
50
+ }
51
+ return parsed as Record<string, unknown>;
52
+ } catch (cause) {
53
+ if (cause instanceof ProviderWriteError) throw cause;
54
+ throw new ProviderWriteError(`${path} could not be parsed, so it was left untouched: ${String(cause)}`);
55
+ }
56
+ }
57
+
58
+ /** The map a provider node lives in, created when absent and refused when wrong. */
59
+ export function providerMap(doc: Record<string, unknown>, pointer: string, path: string): Record<string, unknown> {
60
+ const head = pointer.split('.')[0];
61
+ if (doc[head] !== undefined && (typeof doc[head] !== 'object' || Array.isArray(doc[head]))) {
62
+ throw new ProviderWriteError(`${path}: "${head}" is not an object, so it was left untouched`);
63
+ }
64
+ const map = asRecord(doc[head]);
65
+ doc[head] = map;
66
+ return map;
67
+ }
@@ -0,0 +1,191 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * Importing a provider into another harness — the rule that makes it safe.
8
+ *
9
+ * The user asked for exactly one shape: "claude uses kenari, imported from omp".
10
+ * Two facts decide whether that is an honest write or a silent breakage:
11
+ *
12
+ * - **kenari is custom, `anthropic` is not.** A vendor id copied across would
13
+ * override the TARGET's own built-in provider, so the list filters it and the
14
+ * writer refuses it.
15
+ * - **kenari speaks Anthropic Messages even though omp calls it
16
+ * `openai-completions`.** Measured on the live host: `POST /v1/messages`
17
+ * answers, `/v1beta/models` is a 404 HTML page. Claude Code only speaks
18
+ * Anthropic Messages, so the import has to pick that protocol — and the probe
19
+ * is what measures it instead of trusting the source's declaration.
20
+ */
21
+
22
+ import { afterAll, beforeAll, describe, expect, test } from 'bun:test';
23
+ import { mkdtempSync, mkdirSync, rmSync } from 'node:fs';
24
+ import { tmpdir } from 'node:os';
25
+ import { join } from 'node:path';
26
+
27
+ import { customProviderIds, isVendorProviderId } from '@/shared/lib/models/provider/vendors';
28
+ import { restoreEnv } from '@/test-support/env';
29
+ import { importableProvidersFor, readRegistryProviders } from '@/server/lib/harness/provider-sources.server';
30
+ import { providerEnv } from '@/shared/lib/harness/providers';
31
+ import { EMPTY_HARNESS_CONFIG, parseEnvLines, withEnvValues } from '@/shared/lib/harness/config';
32
+ import { probeEndpointProtocols } from '@/server/lib/harness/provider-probe.server';
33
+ import { writeProvider } from '@/server/lib/harness/provider-write.server';
34
+
35
+ let root = '';
36
+ const savedHome = Bun.env.HOME;
37
+
38
+ /** A models.yml shaped like the developer's real one: custom rows only. */
39
+ const MODELS_YML = `providers:
40
+ kenari:
41
+ baseUrl: https://kenari.id/v1
42
+ apiKey: kn-test
43
+ api: openai-completions
44
+ models:
45
+ - id: claude-sonnet-5
46
+ contextWindow: 1000000
47
+ - id: deepseek-v4-1-flash
48
+ anthropic:
49
+ baseUrl: https://proxy.example/v1
50
+ api: anthropic-messages
51
+ models: []
52
+ `;
53
+
54
+ beforeAll(async () => {
55
+ root = mkdtempSync(join(tmpdir(), 'kabmo-import-'));
56
+ Bun.env.HOME = root;
57
+ mkdirSync(join(root, '.omp/agent'), { recursive: true });
58
+ await Bun.write(join(root, '.omp/agent/models.yml'), MODELS_YML);
59
+ });
60
+
61
+ afterAll(() => {
62
+ restoreEnv('HOME', savedHome);
63
+ rmSync(root, { recursive: true, force: true });
64
+ });
65
+
66
+ describe('the vendor census', () => {
67
+ test('a provider the agent ships is not "custom"', () => {
68
+ // This is the difference the user's rule turns on.
69
+ expect(isVendorProviderId('anthropic')).toBe(true);
70
+ expect(isVendorProviderId('openai')).toBe(true);
71
+ expect(isVendorProviderId('github-copilot')).toBe(true);
72
+ // A gateway a user registered yesterday is.
73
+ expect(isVendorProviderId('kenari')).toBe(false);
74
+ expect(isVendorProviderId('my-gateway')).toBe(false);
75
+ });
76
+
77
+ test('spelling differences fold before the comparison', () => {
78
+ expect(isVendorProviderId('Google-Vertex')).toBe(true);
79
+ expect(isVendorProviderId('llama.cpp')).toBe(true);
80
+ expect(isVendorProviderId('LLAMA_CPP')).toBe(true);
81
+ });
82
+
83
+ test('a registry’s own reserved ids count as vendor ids for it', () => {
84
+ // codex reserves these, so writing one would collide with its built-in.
85
+ expect(isVendorProviderId('gcp', ['gcp'])).toBe(true);
86
+ expect(customProviderIds(['kenari', 'anthropic', 'sumopod'])).toEqual(['kenari', 'sumopod']);
87
+ });
88
+ });
89
+
90
+ describe('reading a source registry', () => {
91
+ test('only CUSTOM entries come back, with the protocol each declares', async () => {
92
+ const rows = await readRegistryProviders('omp-rpc');
93
+ expect(rows.map((row) => row.id)).toEqual(['kenari']);
94
+ const kenari = rows[0]!;
95
+ expect(kenari.source).toBe('omp-rpc');
96
+ expect(kenari.baseUrl).toBe('https://kenari.id/v1');
97
+ expect(kenari.protocol).toBe('openai-chat');
98
+ expect(kenari.hasKey).toBe(true);
99
+ expect(kenari.models).toEqual(['claude-sonnet-5', 'deepseek-v4-1-flash']);
100
+ // The context window travels so a target that REQUIRES one can write it.
101
+ expect(kenari.contextWindow?.['claude-sonnet-5']).toBe(1_000_000);
102
+ });
103
+
104
+ test('the credential is not part of a row', async () => {
105
+ const rows = await readRegistryProviders('omp-rpc');
106
+ expect(JSON.stringify(rows)).not.toContain('kn-test');
107
+ });
108
+
109
+ test('an importable list for claude keeps the custom row', async () => {
110
+ const rows = await importableProvidersFor('claude');
111
+ expect(rows.some((row) => row.id === 'kenari')).toBe(true);
112
+ });
113
+ });
114
+
115
+ describe('importing into an environment harness', () => {
116
+ test('claude has no registry file, so the write refuses and names the surface', async () => {
117
+ // The import for an environment harness is the ROUTE's env flattening, not a
118
+ // file write; a draft that reaches the registry writer has to say so.
119
+ await expect(writeProvider('claude', {
120
+ id: 'kenari',
121
+ name: 'Kenari',
122
+ baseUrl: 'https://kenari.id/v1',
123
+ protocol: 'anthropic-messages',
124
+ models: ['claude-sonnet-5'],
125
+ apiKey: 'kn-test',
126
+ })).rejects.toThrow(/no provider registry/);
127
+ });
128
+
129
+ test('the flattened env is the vendor’s own variables, at the host root', () => {
130
+ const env = providerEnv('claude', { baseUrl: 'https://kenari.id', apiKey: 'kn-test', model: 'claude-sonnet-5' });
131
+ expect(env).toEqual({
132
+ ANTHROPIC_BASE_URL: 'https://kenari.id',
133
+ ANTHROPIC_AUTH_TOKEN: 'kn-test',
134
+ ANTHROPIC_MODEL: 'claude-sonnet-5',
135
+ });
136
+ });
137
+
138
+ test('an import REPLACES an existing variable instead of duplicating it', () => {
139
+ const before = { ...EMPTY_HARNESS_CONFIG, env: 'ANTHROPIC_AUTH_TOKEN=old\nKEEP_ME=1' };
140
+ const after = withEnvValues(before, { ANTHROPIC_AUTH_TOKEN: 'new' });
141
+ expect(after.env).toBe('ANTHROPIC_AUTH_TOKEN=new\nKEEP_ME=1');
142
+ // Parsed back by the SAME parser the spawn reads, so what the form shows is
143
+ // what the agent gets.
144
+ expect(parseEnvLines(after.env).env).toEqual({ ANTHROPIC_AUTH_TOKEN: 'new', KEEP_ME: '1' });
145
+ });
146
+ });
147
+
148
+ describe('probeEndpointProtocols', () => {
149
+ test('an empty endpoint is reported, not probed', async () => {
150
+ const probe = await probeEndpointProtocols('');
151
+ expect(probe.protocols).toEqual([]);
152
+ expect(probe.error).toBeTruthy();
153
+ });
154
+
155
+ test('a host that answers nothing yields no protocols and no false positive', async () => {
156
+ // Port 1 is closed on every sane host: this is the "cannot reach" path.
157
+ const probe = await probeEndpointProtocols('http://127.0.0.1:1');
158
+ expect(probe.protocols).toEqual([]);
159
+ expect(probe.error).toBeTruthy();
160
+ });
161
+
162
+ test('a host that answers Anthropic and OpenAI Chat is measured as exactly that', async () => {
163
+ // The stub mirrors the measured shape of kenari.id: `/v1/messages` and
164
+ // `/v1/chat/completions` exist, `/v1/responses` and the Gemini listing do not.
165
+ const server = Bun.serve({
166
+ port: 0,
167
+ fetch(request) {
168
+ const path = new URL(request.url).pathname;
169
+ if (path === '/v1/messages') {
170
+ return Response.json({ error: { message: 'invalid Anthropic request JSON: missing field `model`' } }, { status: 400 });
171
+ }
172
+ if (path === '/v1/chat/completions') {
173
+ return Response.json({ error: { message: 'invalid JSON: missing field `model`' } }, { status: 400 });
174
+ }
175
+ // The site's own 404 page, as HTML — a route that is NOT there.
176
+ return new Response('<!DOCTYPE html><html></html>', {
177
+ status: 400,
178
+ headers: { 'content-type': 'text/html' },
179
+ });
180
+ },
181
+ });
182
+ try {
183
+ const probe = await probeEndpointProtocols(`http://127.0.0.1:${server.port}/v1`);
184
+ expect(probe.protocols).toEqual(['openai-chat', 'anthropic-messages']);
185
+ // The probe asks the HOST, never with a credential.
186
+ expect(probe.root).toBe(`http://127.0.0.1:${server.port}`);
187
+ } finally {
188
+ server.stop(true);
189
+ }
190
+ });
191
+ });
@@ -0,0 +1,123 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * Which wire protocols an ENDPOINT actually speaks — measured, not assumed.
8
+ *
9
+ * An import's hardest question is not "which file" but "which API does this host
10
+ * answer". A provider's own declaration is only about the agent it was written
11
+ * for: measured on `kenari`, whose omp entry says `openai-completions` while the
12
+ * host also answers Anthropic Messages on `/v1/messages` — which is what makes
13
+ * "import kenari from omp into Claude Code" work at all, and what makes writing
14
+ * its declared dialect there fail every request.
15
+ *
16
+ * So the import probes. One unauthenticated `POST` with an empty JSON body per
17
+ * protocol is enough, because every one of these APIs rejects a body it cannot
18
+ * parse BEFORE it looks at a credential:
19
+ *
20
+ * | Route | Empty body answers | Meaning |
21
+ * |---|---|---|
22
+ * | `POST {root}/v1/messages` | 400 `invalid Anthropic request JSON` | Anthropic Messages |
23
+ * | `POST {root}/v1/chat/completions` | 400 `invalid JSON: missing field model` | OpenAI Chat |
24
+ * | `POST {root}/v1/responses` | 400 (same shape) | OpenAI Responses |
25
+ * | `GET {root}/v1beta/models` | 200 JSON list | Google GenAI |
26
+ *
27
+ * 404/405 (and an HTML error page) mean the route is not there. A 401/403 means
28
+ * the route IS there and wants a key — also a yes. The probe therefore sends NO
29
+ * credential: it answers a question about the HOST, and it must be safe to run
30
+ * for a provider whose key is unset or rotated.
31
+ *
32
+ * Measured against kenari.id: `/v1/messages` and `/v1/responses` answer (200 with
33
+ * a key, 400 on an empty body), `/messages` answers 405, `/v1beta/models` answers
34
+ * a 404 HTML page.
35
+ *
36
+ * Server-only: it performs outbound HTTP the settings page must not.
37
+ */
38
+
39
+ import { CANONICAL_PROTOCOLS, type CanonicalProtocol } from '@/shared/lib/harness/dialects';
40
+
41
+ /** Bounded because the caller is a settings card and the host is a stranger. */
42
+ const PROBE_TIMEOUT_MS = 6_000;
43
+ const PROBE_BODY = '{}';
44
+
45
+ /** The one request that answers "is this route here" for a protocol. */
46
+ function routeFor(root: string, protocol: CanonicalProtocol): { url: string; init: RequestInit } {
47
+ const json = { 'content-type': 'application/json' };
48
+ switch (protocol) {
49
+ case 'anthropic-messages':
50
+ return {
51
+ url: `${root}/v1/messages`,
52
+ init: { method: 'POST', headers: { ...json, 'anthropic-version': '2023-06-01' }, body: PROBE_BODY },
53
+ };
54
+ case 'openai-chat':
55
+ return { url: `${root}/v1/chat/completions`, init: { method: 'POST', headers: json, body: PROBE_BODY } };
56
+ case 'openai-responses':
57
+ return { url: `${root}/v1/responses`, init: { method: 'POST', headers: json, body: PROBE_BODY } };
58
+ case 'google-genai':
59
+ case 'vertex-ai':
60
+ // Vertex answers the same listing under a different host shape; a probe of
61
+ // the Gemini route proves the SDK's presence, which is the fact an import
62
+ // needs. A vertex-only host simply does not answer and is not offered.
63
+ return { url: `${root}/v1beta/models`, init: { method: 'GET' } };
64
+ }
65
+ }
66
+
67
+ /** True when a status proves the route EXISTS — it parsed or authenticated nothing. */
68
+ function routeExists(status: number, contentType: string): boolean {
69
+ if (status === 404 || status === 405 || status === 410 || status === 501) return false;
70
+ // A 2xx/4xx proves the router knew the path. A 5xx from an HTML page is an
71
+ // error wall in front of the whole site, not a route.
72
+ if (status >= 500) return false;
73
+ // An error page served as HTML is the site's 404 page dressed as a 400.
74
+ if (contentType.includes('text/html')) return false;
75
+ return true;
76
+ }
77
+
78
+ export interface EndpointProbe {
79
+ /** The host root the probe used (version segment stripped). */
80
+ root: string;
81
+ /** Protocols whose route answered, in probe order. */
82
+ protocols: CanonicalProtocol[];
83
+ /** One line per protocol tried, for the card to show as evidence. */
84
+ findings: Array<{ protocol: CanonicalProtocol; status: number | null; present: boolean }>;
85
+ /** Set when the host could not be reached at all. */
86
+ error?: string;
87
+ }
88
+
89
+ /**
90
+ * Probe one endpoint for every portable protocol.
91
+ *
92
+ * All five run in parallel: they are independent GET/POSTs to one host, and a
93
+ * settings card waits on the slowest. A network failure marks the whole probe
94
+ * errored rather than reporting five false negatives — "cannot reach" and "does
95
+ * not speak this" are different answers.
96
+ */
97
+ export async function probeEndpointProtocols(baseUrl: string): Promise<EndpointProbe> {
98
+ const root = baseUrl.trim().replace(/\/+$/, '').replace(/\/v1(beta|alpha)?$/i, '');
99
+ if (!root) return { root, protocols: [], findings: [], error: 'No endpoint to probe' };
100
+
101
+ let networkError: string | null = null;
102
+ const findings = await Promise.all(CANONICAL_PROTOCOLS.map(async (protocol) => {
103
+ const { url, init } = routeFor(root, protocol);
104
+ try {
105
+ const response = await fetch(url, { ...init, signal: AbortSignal.timeout(PROBE_TIMEOUT_MS) });
106
+ const contentType = response.headers.get('content-type') ?? '';
107
+ // Drain the body: an unread response keeps the connection alive and Bun
108
+ // will hold the socket until the timeout.
109
+ await response.text().catch(() => '');
110
+ return { protocol, status: response.status, present: routeExists(response.status, contentType) };
111
+ } catch (cause) {
112
+ networkError ??= cause instanceof Error ? cause.message : 'request failed';
113
+ return { protocol, status: null, present: false };
114
+ }
115
+ }));
116
+
117
+ return {
118
+ root,
119
+ protocols: findings.filter((finding) => finding.present).map((finding) => finding.protocol),
120
+ findings,
121
+ ...(networkError ? { error: networkError } : {}),
122
+ };
123
+ }
@@ -0,0 +1,45 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * Which harnesses read the same registry file.
8
+ *
9
+ * The bug this pins: a provider added on the `omp-acp` tab was written to the
10
+ * one `models.yml` both transports read, but only the clicked tab's probe was
11
+ * dropped — so the other picker kept serving the pre-write catalog until its
12
+ * TTL expired. The relation therefore has to be derived from the FILE the
13
+ * harness reads, not from a hand-written pair that a third transport would miss.
14
+ */
15
+
16
+ import { describe, expect, test } from 'bun:test';
17
+ import { registryFilePath, harnessesSharingRegistry } from '@/server/lib/harness/provider-sources.server';
18
+
19
+ describe('harnesses that share a registry file', () => {
20
+ test('both omp transports read the same models.yml', () => {
21
+ const modelsYml = registryFilePath('omp-rpc');
22
+ expect(modelsYml).not.toBeNull();
23
+ // Measured on the real facts table: omp-acp reads the same file omp-rpc does.
24
+ expect(registryFilePath('omp-acp')).toBe(modelsYml);
25
+ expect(harnessesSharingRegistry(modelsYml!).sort()).toEqual(['omp-acp', 'omp-rpc']);
26
+ });
27
+
28
+ test('a harness with its own file names only itself', () => {
29
+ const codex = registryFilePath('codex');
30
+ expect(codex).not.toBeNull();
31
+ expect(harnessesSharingRegistry(codex!)).toEqual(['codex']);
32
+ });
33
+
34
+ test('a path no harness reads invalidates nothing', () => {
35
+ // A caller that wrote some other file must not blank an unrelated picker.
36
+ expect(harnessesSharingRegistry(`${registryFilePath('omp-rpc')}.bak`)).toEqual([]);
37
+ });
38
+
39
+ test('harnesses without a registry never appear', () => {
40
+ // `minimax` has no file (`registry.file === null`); it must not match the
41
+ // home directory merely because both strings are empty.
42
+ expect(registryFilePath('minimax')).toBeNull();
43
+ expect(harnessesSharingRegistry('')).toEqual([]);
44
+ });
45
+ });