@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.
- package/README.md +1 -1
- package/dist/client/index.html +1 -1
- package/dist/client/index.js +873 -524
- package/dist/client/static/js/{index-297dck9a.js → index-jcr5twtp.js} +799 -795
- package/dist/client/static/js/index-z3w7n85q.css +1 -0
- package/marketplace/plugins/stats/package.json +2 -2
- package/marketplace/plugins/stats/src/groups.test.ts +14 -0
- package/marketplace/plugins/stats/src/groups.ts +20 -0
- package/marketplace/plugins/stats/src/labels.test.ts +9 -0
- package/marketplace/plugins/stats/src/labels.ts +7 -0
- package/marketplace/plugins/stats/src/server.ts +1 -1
- package/package.json +1 -1
- package/src/client/App.tsx +20 -19
- package/src/client/components/common/ComposerTextarea.tsx +10 -1
- package/src/client/components/common/Modal.tsx +2 -6
- package/src/client/components/common/PWAInstallButton.tsx +3 -2
- package/src/client/components/common/Toast.test.tsx +298 -0
- package/src/client/components/common/Toast.tsx +103 -37
- package/src/client/components/common/ToastStack.tsx +33 -12
- package/src/client/components/common/ViewportSelector.tsx +122 -114
- package/src/client/components/common/context-usage-button/Ring.tsx +38 -1
- package/src/client/components/common/context-usage-button/index.test.tsx +19 -3
- package/src/client/components/common/context-usage-button/index.tsx +5 -2
- package/src/client/components/common/harness-glyph/brands.ts +65 -0
- package/src/client/components/common/harness-glyph/harness-glyph.test.ts +185 -0
- package/src/client/components/common/harness-glyph/index.tsx +131 -0
- package/src/client/components/common/header-controls/MoreMenu.tsx +2 -1
- package/src/client/components/common/header-controls/index.tsx +16 -8
- package/src/client/components/common/header-panel-buttons/index.tsx +4 -3
- package/src/client/components/common/panel-mark/index.test.tsx +2 -2
- package/src/client/components/common/panel-mark/index.tsx +11 -2
- package/src/client/components/common/search-select/index.tsx +305 -0
- package/src/client/components/common/search-select/search-select.test.tsx +217 -0
- package/src/client/components/common/server-control/index.tsx +3 -2
- package/src/client/components/common/session-row/index.tsx +18 -1
- package/src/client/components/common/toolbar-row/index.tsx +57 -20
- package/src/client/components/layout/desktop-layout/LeftColumn.tsx +1 -3
- package/src/client/components/layout/desktop-layout/TopNavbar.tsx +3 -2
- package/src/client/components/layout/desktop-layout/WorkspacePanels.tsx +7 -1
- package/src/client/components/layout/desktop-layout/index.tsx +1 -3
- package/src/client/components/layout/session-sidebar/CategoryItem.tsx +1 -0
- package/src/client/components/layout/session-sidebar/SessionItem.tsx +18 -1
- package/src/client/components/layout/session-sidebar/SessionsView.tsx +1 -3
- package/src/client/components/layout/session-sidebar/about-modal/HarnessTable.test.tsx +332 -0
- package/src/client/components/layout/session-sidebar/about-modal/HarnessTable.tsx +310 -0
- package/src/client/components/layout/session-sidebar/about-modal/SocialLinks.tsx +63 -51
- package/src/client/components/layout/session-sidebar/about-modal/UpdateSection.tsx +4 -2
- package/src/client/components/layout/session-sidebar/about-modal/index.test.tsx +122 -0
- package/src/client/components/layout/session-sidebar/about-modal/index.tsx +136 -35
- package/src/client/components/layout/session-sidebar/harness-mark.test.tsx +126 -0
- package/src/client/components/layout/session-sidebar/modern/ActionRow.tsx +4 -3
- package/src/client/components/layout/session-sidebar/modern/WorkspaceSection.tsx +1 -0
- package/src/client/components/mobile/LayoutWrapper.tsx +1 -7
- package/src/client/components/mobile/SessionSidebar.tsx +1 -3
- package/src/client/components/mobile/mobile-main-view/Header.tsx +3 -2
- package/src/client/components/mobile/mobile-session-sidebar/Dialogs.tsx +0 -8
- package/src/client/components/mobile/mobile-session-sidebar/Item.tsx +1 -0
- package/src/client/components/mobile/mobile-session-sidebar/SessionRow.tsx +17 -1
- package/src/client/components/settings/Modal.tsx +26 -22
- package/src/client/components/settings/Sidebar.tsx +45 -5
- package/src/client/components/settings/categories/HarnessSettings.tsx +207 -0
- package/src/client/components/settings/categories/ProjectSettings.tsx +1 -3
- package/src/client/components/settings/categories/ProviderSettings.tsx +0 -4
- package/src/client/components/settings/categories/SkillCatalogSettings.tsx +13 -23
- package/src/client/components/settings/categories/agent-settings/ModelPicker.tsx +23 -30
- package/src/client/components/settings/categories/appearance-settings/IconStyleSection.tsx +20 -11
- package/src/client/components/settings/categories/chat-settings/GoalSection.tsx +16 -16
- package/src/client/components/settings/categories/harness-settings/AddProviderForm.tsx +219 -0
- package/src/client/components/settings/categories/harness-settings/ConfigForm.tsx +268 -0
- package/src/client/components/settings/categories/harness-settings/EnvProviderForm.tsx +146 -0
- package/src/client/components/settings/categories/harness-settings/HarnessCard.tsx +278 -0
- package/src/client/components/settings/categories/harness-settings/ImportSection.tsx +195 -0
- package/src/client/components/settings/categories/harness-settings/ProviderPanel.tsx +152 -0
- package/src/client/components/settings/categories/harness-settings/ToggleList.tsx +147 -0
- package/src/client/components/settings/categories/harness-settings/parts.test.tsx +97 -0
- package/src/client/components/settings/categories/harness-settings/parts.tsx +84 -0
- package/src/client/components/settings/categories/harness-settings/provider-panel.test.tsx +313 -0
- package/src/client/components/settings/categories/omp-settings/RoleEditor.test.ts +60 -39
- package/src/client/components/settings/categories/omp-settings/RoleRow.tsx +32 -41
- package/src/client/components/settings/categories/omp-settings/role-picker.test-util.ts +45 -0
- package/src/client/components/settings/categories/panel-plugins/PluginMark.test.ts +1 -1
- package/src/client/components/settings/categories/panel-plugins/PluginMark.tsx +11 -4
- package/src/client/components/settings/groups.test.tsx +160 -0
- package/src/client/components/settings/harness-icons.test.tsx +134 -0
- package/src/client/components/workspace/browser-panel/AddressBar.tsx +3 -13
- package/src/client/components/workspace/browser-toolbar/clusters.tsx +237 -0
- package/src/client/components/workspace/browser-toolbar/index.test.tsx +167 -0
- package/src/client/components/workspace/browser-toolbar/index.tsx +99 -100
- package/src/client/components/workspace/btw-panel/Messages.tsx +4 -1
- package/src/client/components/workspace/btw-panel/index.tsx +2 -0
- package/src/client/components/workspace/chat-timeline/AiMessageFooter.tsx +11 -7
- package/src/client/components/workspace/chat-timeline/ChatOverlays.tsx +5 -2
- package/src/client/components/workspace/chat-timeline/ComposerDock.tsx +13 -0
- package/src/client/components/workspace/chat-timeline/EmptyWorkspacePrompt.tsx +13 -0
- package/src/client/components/workspace/chat-timeline/GeneratingIndicator.test.ts +41 -0
- package/src/client/components/workspace/chat-timeline/GeneratingIndicator.tsx +19 -14
- package/src/client/components/workspace/chat-timeline/MessageList.test.ts +14 -0
- package/src/client/components/workspace/chat-timeline/MessageList.tsx +6 -0
- package/src/client/components/workspace/chat-timeline/PendingChatView.tsx +14 -0
- package/src/client/components/workspace/chat-timeline/RunFooter.tsx +4 -0
- package/src/client/components/workspace/chat-timeline/RunMark.tsx +58 -0
- package/src/client/components/workspace/chat-timeline/SubagentView.tsx +4 -1
- package/src/client/components/workspace/chat-timeline/TimelineBody.tsx +4 -0
- package/src/client/components/workspace/chat-timeline/chat-input/AttachmentToolbar.tsx +1 -0
- package/src/client/components/workspace/chat-timeline/chat-input/ComposerRows.tsx +11 -0
- package/src/client/components/workspace/chat-timeline/chat-input/ModeToggles.test.ts +13 -0
- package/src/client/components/workspace/chat-timeline/chat-input/ModeToggles.tsx +8 -1
- package/src/client/components/workspace/chat-timeline/chat-input/Toolbar.test.ts +27 -1
- package/src/client/components/workspace/chat-timeline/chat-input/Toolbar.tsx +48 -23
- package/src/client/components/workspace/chat-timeline/chat-input/composer-portal.test.tsx +1 -0
- package/src/client/components/workspace/chat-timeline/chat-input/index.tsx +21 -1
- package/src/client/components/workspace/chat-timeline/chat-input/modes-props.ts +7 -0
- package/src/client/components/workspace/chat-timeline/chat-input/props.ts +13 -0
- package/src/client/components/workspace/chat-timeline/chat-input/selection.ts +11 -2
- package/src/client/components/workspace/chat-timeline/chat-input/styles.test.tsx +1 -0
- package/src/client/components/workspace/chat-timeline/index.tsx +17 -15
- package/src/client/components/workspace/chat-timeline/pending-harness.test.tsx +157 -0
- package/src/client/components/workspace/chat-timeline/run-mark.test.ts +104 -0
- package/src/client/components/workspace/chat-timeline/tool-renderers/ask-panel/FrameControl.tsx +11 -20
- package/src/client/components/workspace/chat-timeline/tool-renderers/ask-panel/GroupedAsk.tsx +1 -1
- package/src/client/components/workspace/chat-timeline/tool-renderers/ask-panel/QuestionBlock.tsx +1 -1
- package/src/client/components/workspace/chat-timeline/tool-renderers/ask-panel/drafts.ts +1 -1
- package/src/client/components/workspace/chat-timeline/tool-renderers/ask-panel/index.tsx +2 -1
- package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Bash.test.ts +31 -3
- package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Bash.tsx +5 -1
- package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Wait.test.ts +56 -45
- package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Wait.tsx +38 -94
- package/src/client/components/workspace/chat-timeline/tool-renderers/panels/wait-parts.tsx +76 -0
- package/src/client/components/workspace/chat-timeline/tool-renderers/shared/card-header.ts +2 -1
- package/src/client/components/workspace/file-explorer/index.test.ts +25 -0
- package/src/client/components/workspace/file-explorer/index.tsx +10 -6
- package/src/client/components/workspace/git-panel/index.test.ts +13 -3
- package/src/client/components/workspace/git-panel/index.tsx +1 -3
- package/src/client/components/workspace/model-dropdown/Fullscreen.tsx +92 -0
- package/src/client/components/workspace/model-dropdown/HarnessTabs.tsx +290 -0
- package/src/client/components/workspace/model-dropdown/Item.tsx +11 -0
- package/src/client/components/workspace/model-dropdown/Panel.tsx +119 -8
- package/src/client/components/workspace/model-dropdown/Section.tsx +4 -0
- package/src/client/components/workspace/model-dropdown/fullscreen-picker.ts +51 -0
- package/src/client/components/workspace/model-dropdown/harness-models.test.ts +177 -0
- package/src/client/components/workspace/model-dropdown/harness-models.ts +148 -0
- package/src/client/components/workspace/model-dropdown/harness-tabs.test.tsx +336 -0
- package/src/client/components/workspace/model-dropdown/index.tsx +114 -85
- package/src/client/components/workspace/model-dropdown/placement.test.tsx +127 -0
- package/src/client/components/workspace/model-dropdown/popover-metrics.test.ts +107 -0
- package/src/client/components/workspace/model-dropdown/popover-metrics.ts +118 -0
- package/src/client/components/workspace/model-dropdown/row-mutations.ts +106 -0
- package/src/client/components/workspace/model-dropdown/trigger.test.ts +22 -2
- package/src/client/components/workspace/model-dropdown/use-popover-size.ts +89 -0
- package/src/client/data/settings/omp-schema.json +224 -17
- package/src/client/hooks/chat/composer/index.ts +11 -2
- package/src/client/hooks/chat/composer/items.test.ts +11 -0
- package/src/client/hooks/chat/composer/items.ts +4 -2
- package/src/client/hooks/chat/composer/model-selection.test.ts +110 -0
- package/src/client/hooks/chat/composer/model-selection.ts +45 -4
- package/src/client/hooks/chat/omp/prompt-send.ts +4 -2
- package/src/client/hooks/chat/timeline/actions.ts +10 -5
- package/src/client/hooks/chat/timeline/ask-frames.ts +5 -4
- package/src/client/hooks/chat/timeline/composer-local-actions.test.ts +19 -81
- package/src/client/hooks/chat/timeline/composer-modes.ts +11 -2
- package/src/client/hooks/chat/timeline/composer-refs.ts +16 -1
- package/src/client/hooks/chat/timeline/index.ts +27 -35
- package/src/client/hooks/chat/timeline/mode-availability.test.ts +51 -0
- package/src/client/hooks/chat/timeline/modes-contract.ts +6 -0
- package/src/client/hooks/chat/timeline/modes.ts +41 -2
- package/src/client/hooks/chat/timeline/new-chat-open.test.ts +86 -0
- package/src/client/hooks/chat/timeline/new-chat-open.ts +23 -5
- package/src/client/hooks/chat/timeline/new-chat.test.ts +32 -4
- package/src/client/hooks/chat/timeline/new-chat.ts +18 -6
- package/src/client/hooks/chat/timeline/prompt-text.test.ts +7 -0
- package/src/client/hooks/chat/timeline/prompt-text.ts +15 -6
- package/src/client/hooks/chat/timeline/rewind-actions.test.ts +51 -1
- package/src/client/hooks/chat/timeline/rewind-actions.ts +23 -1
- package/src/client/hooks/chat/timeline/run-identity.test.ts +52 -0
- package/src/client/hooks/chat/timeline/run-identity.ts +23 -11
- package/src/client/hooks/chat/timeline/send-execute.test.ts +55 -0
- package/src/client/hooks/chat/timeline/send-props.ts +11 -3
- package/src/client/hooks/chat/timeline/send-steer.test.ts +2 -3
- package/src/client/hooks/chat/timeline/send.test-util.ts +3 -2
- package/src/client/hooks/chat/timeline/send.test.ts +2 -3
- package/src/client/hooks/chat/timeline/send.ts +34 -8
- package/src/client/hooks/chat/timeline/session-harness.test.ts +163 -0
- package/src/client/hooks/chat/timeline/session-harness.ts +164 -0
- package/src/client/hooks/chat/timeline/session-load.test-util.ts +6 -2
- package/src/client/hooks/chat/timeline/session-load.test.ts +31 -0
- package/src/client/hooks/chat/timeline/session-load.ts +6 -14
- package/src/client/hooks/chat/timeline/session-shapes.ts +32 -0
- package/src/client/hooks/chat/timeline/spawn-harness.ts +41 -0
- package/src/client/hooks/chat/timeline/timeline-running.ts +55 -0
- package/src/client/hooks/chat/timeline/tui-only-guard.ts +9 -0
- package/src/client/hooks/chat/timeline/undo-confirmation.test.ts +131 -0
- package/src/client/hooks/models/harness-catalog.ts +114 -0
- package/src/client/hooks/models/provider-writes.test.ts +81 -0
- package/src/client/hooks/models/provider-writes.ts +144 -0
- package/src/client/hooks/models/use-harness-versions.test.ts +152 -0
- package/src/client/hooks/models/use-harness-versions.ts +136 -0
- package/src/client/hooks/models/use-harnesses-controller.ts +57 -0
- package/src/client/hooks/models/use-harnesses-signal.test.ts +128 -0
- package/src/client/hooks/models/use-harnesses.test.ts +187 -0
- package/src/client/hooks/models/use-harnesses.ts +215 -0
- package/src/client/hooks/settings/providers/index.ts +1 -3
- package/src/client/hooks/ui/editor-error-toast.ts +10 -3
- package/src/client/hooks/ui/icon-style.ts +28 -0
- package/src/client/hooks/ui/on-click-outside.test.ts +104 -0
- package/src/client/hooks/ui/on-click-outside.ts +14 -2
- package/src/client/hooks/ui/theme.ts +6 -0
- package/src/client/hooks/ui/toast-queue.test.ts +126 -0
- package/src/client/hooks/ui/toasts.ts +132 -27
- package/src/client/hooks/ui/ui-feedback.test.ts +4 -91
- package/src/client/lib/ui/control-plate.test.ts +76 -0
- package/src/client/lib/ui/control-plate.ts +65 -0
- package/src/client/tailwind.css +47 -1
- package/src/server/lib/assets/shell-attributes.server.ts +9 -2
- package/src/server/lib/assets/shell-attributes.test.ts +22 -6
- package/src/server/lib/db/schema.ts +4 -0
- package/src/server/lib/harness/acp/acp-audit.server.ts +107 -0
- package/src/server/lib/harness/acp/acp-goal-driver.server.ts +153 -0
- package/src/server/lib/harness/acp/acp-goal-state.server.ts +136 -0
- package/src/server/lib/harness/acp/acp-goal.server.ts +273 -0
- package/src/server/lib/harness/acp/acp-goal.test.ts +229 -0
- package/src/server/lib/harness/acp/acp-telemetry.server.ts +133 -0
- package/src/server/lib/harness/acp/acp-telemetry.test.ts +85 -0
- package/src/server/lib/harness/acp/acp-todos.server.ts +45 -0
- package/src/server/lib/harness/acp/acp-todos.test.ts +43 -0
- package/src/server/lib/harness/acp/activation.test.ts +81 -0
- package/src/server/lib/harness/acp/activation.ts +72 -0
- package/src/server/lib/harness/acp/calls.ts +97 -0
- package/src/server/lib/harness/acp/client.test.ts +73 -0
- package/src/server/lib/harness/acp/client.ts +339 -0
- package/src/server/lib/harness/acp/commands.test.ts +92 -0
- package/src/server/lib/harness/acp/commands.ts +165 -0
- package/src/server/lib/harness/acp/frames.test.ts +315 -0
- package/src/server/lib/harness/acp/frames.ts +349 -0
- package/src/server/lib/harness/acp/mapper.ts +204 -0
- package/src/server/lib/harness/acp/permissions.test.ts +66 -0
- package/src/server/lib/harness/acp/permissions.ts +155 -0
- package/src/server/lib/harness/acp/prompt.test.ts +130 -0
- package/src/server/lib/harness/acp/prompt.ts +134 -0
- package/src/server/lib/harness/acp/protocol.ts +162 -0
- package/src/server/lib/harness/acp/session-config.test.ts +73 -0
- package/src/server/lib/harness/acp/session-config.ts +148 -0
- package/src/server/lib/harness/acp/session-facts.ts +71 -0
- package/src/server/lib/harness/acp/session-handshake.ts +89 -0
- package/src/server/lib/harness/acp/session-idle.ts +51 -0
- package/src/server/lib/harness/acp/session-notifications.ts +95 -0
- package/src/server/lib/harness/acp/session-observers.test.ts +193 -0
- package/src/server/lib/harness/acp/session-options.ts +33 -0
- package/src/server/lib/harness/acp/session-permissions.test.ts +105 -0
- package/src/server/lib/harness/acp/session-permissions.ts +74 -0
- package/src/server/lib/harness/acp/session-reaper.test.ts +96 -0
- package/src/server/lib/harness/acp/session-turns.ts +95 -0
- package/src/server/lib/harness/acp/session-usage.ts +60 -0
- package/src/server/lib/harness/acp/session-web-state.ts +61 -0
- package/src/server/lib/harness/acp/session.test-util.ts +160 -0
- package/src/server/lib/harness/acp/session.test.ts +233 -0
- package/src/server/lib/harness/acp/session.ts +350 -0
- package/src/server/lib/harness/acp/turn.ts +199 -0
- package/src/server/lib/harness/acp/verbs.ts +87 -0
- package/src/server/lib/harness/auto-probe.server.test.ts +121 -0
- package/src/server/lib/harness/auto-probe.server.ts +178 -0
- package/src/server/lib/harness/capabilities.ts +67 -0
- package/src/server/lib/harness/config-invalidation.test.ts +91 -0
- package/src/server/lib/harness/config.server.test.ts +105 -0
- package/src/server/lib/harness/config.server.ts +98 -0
- package/src/server/lib/harness/enabled.server.test.ts +87 -0
- package/src/server/lib/harness/enabled.server.ts +61 -0
- package/src/server/lib/harness/launch-table.ts +195 -0
- package/src/server/lib/harness/launch.test.ts +220 -0
- package/src/server/lib/harness/launch.ts +216 -0
- package/src/server/lib/harness/probe-cache.server.test.ts +154 -0
- package/src/server/lib/harness/probe-cache.server.ts +177 -0
- package/src/server/lib/harness/provider-entry.ts +212 -0
- package/src/server/lib/harness/provider-file.server.ts +67 -0
- package/src/server/lib/harness/provider-import.test.ts +191 -0
- package/src/server/lib/harness/provider-probe.server.ts +123 -0
- package/src/server/lib/harness/provider-sources.server.test.ts +45 -0
- package/src/server/lib/harness/provider-sources.server.ts +308 -0
- package/src/server/lib/harness/provider-write-error.ts +19 -0
- package/src/server/lib/harness/provider-write.server.test.ts +308 -0
- package/src/server/lib/harness/provider-write.server.ts +339 -0
- package/src/server/lib/harness/provider-zcode.server.test.ts +270 -0
- package/src/server/lib/harness/provider-zcode.server.ts +324 -0
- package/src/server/lib/harness/register.server.ts +36 -0
- package/src/server/lib/harness/registry.ts +58 -0
- package/src/server/lib/harness/schema.server.ts +129 -0
- package/src/server/lib/harness/session-store.server.test.ts +175 -0
- package/src/server/lib/harness/session-store.server.ts +206 -0
- package/src/server/lib/harness/session-title.server.test.ts +109 -0
- package/src/server/lib/harness/session-title.server.ts +70 -0
- package/src/server/lib/harness/session.ts +74 -0
- package/src/server/lib/harness/spawn.server.ts +133 -0
- package/src/server/lib/harness/update-state.server.ts +185 -0
- package/src/server/lib/lifecycle/after-listen.ts +7 -0
- package/src/server/lib/models/provider-items.server.ts +1 -1
- package/src/server/lib/models/registry-refresh.server.test.ts +87 -0
- package/src/server/lib/models/registry-refresh.server.ts +98 -0
- package/src/server/lib/omp/config/models-config.ts +4 -0
- package/src/server/lib/omp/core/cli.ts +13 -0
- package/src/server/lib/omp/core/host-resolution.test.ts +6 -3
- package/src/server/lib/omp/rpc/child-config.ts +5 -4
- package/src/server/lib/omp/rpc/constants.test.ts +2 -1
- package/src/server/lib/omp/rpc/event-fanout.ts +9 -0
- package/src/server/lib/omp/rpc/forked-resume.test.ts +14 -3
- package/src/server/lib/omp/rpc/rpc-primitives.test.ts +11 -0
- package/src/server/lib/omp/rpc/session-registration.ts +7 -2
- package/src/server/lib/omp/rpc/session-registry.test.ts +2 -1
- package/src/server/lib/omp/rpc/session-registry.ts +74 -5
- package/src/server/lib/omp/session/acp-rows.server.ts +79 -0
- package/src/server/lib/omp/session/delete-flow.server.ts +15 -8
- package/src/server/lib/omp/session/delete.server.ts +12 -0
- package/src/server/lib/omp/session/sidebar-data.harness.test.ts +247 -0
- package/src/server/lib/omp/session/sidebar-data.server.ts +56 -3
- package/src/server/lib/queue/delivery.server.test.ts +4 -2
- package/src/server/lib/queue/payload.test.ts +67 -0
- package/src/server/lib/queue/payload.ts +9 -3
- package/src/server/lib/realtime/signals.server.test.ts +99 -0
- package/src/server/lib/realtime/signals.server.ts +25 -5
- package/src/server/lib/realtime/topics/session-data.server.ts +29 -0
- package/src/server/lib/realtime/topics/session.server.ts +3 -3
- package/src/server/routes/agent/command-resume.test.ts +77 -0
- package/src/server/routes/agent/command.test.ts +243 -2
- package/src/server/routes/agent/command.ts +78 -15
- package/src/server/routes/agent/harness-command.ts +133 -0
- package/src/server/routes/agent/new.ts +63 -1
- package/src/server/routes/chat/rewind.test.ts +147 -0
- package/src/server/routes/chat/rewind.ts +29 -7
- package/src/server/routes/chat/session.test.ts +240 -0
- package/src/server/routes/chat/session.ts +96 -4
- package/src/server/routes/harness/add-provider.test.ts +233 -0
- package/src/server/routes/harness/import-action.ts +272 -0
- package/src/server/routes/harness/import.test.ts +196 -0
- package/src/server/routes/harness/index.ts +13 -0
- package/src/server/routes/harness/root.ts +280 -0
- package/src/server/routes/harness/toggle.test.ts +127 -0
- package/src/server/routes/harness/update.ts +259 -0
- package/src/server/routes/harness/versions.test.ts +148 -0
- package/src/server/routes/harness/versions.ts +105 -0
- package/src/server/routes/index.ts +2 -0
- package/src/server/routes/sessions/delete-acp.test.ts +227 -0
- package/src/server/routes/sessions/queue.ts +7 -2
- package/src/server/routes/sessions/routes-queue.test.ts +52 -0
- package/src/server/routes/sessions/routes.test.ts +47 -13
- package/src/server/routes/sessions/session.ts +35 -0
- package/src/server/routes/settings/commands-harness.test.ts +92 -0
- package/src/server/routes/settings/commands.ts +26 -0
- package/src/server/routes/settings/model-override.ts +5 -2
- package/src/server/routes/settings/provider-entry.ts +2 -2
- package/src/server/routes/settings/provider-model.ts +2 -2
- package/src/server/routes/settings/provider-models.ts +2 -2
- package/src/server/routes/settings/provider-refresh.ts +6 -4
- package/src/server/routes/settings/providers.ts +3 -1
- package/src/server/routes/settings/settings-config-routes.test.ts +10 -2
- package/src/server/routes/settings/skills.ts +12 -0
- package/src/shared/lib/chat/ask-form/fields.ts +76 -0
- package/src/shared/lib/chat/ask-form/index.ts +323 -0
- package/src/shared/lib/chat/ask-form/tokens.ts +199 -0
- package/src/shared/lib/chat/ask-form/types.ts +43 -0
- package/src/shared/lib/chat/ask-form.test.ts +137 -0
- package/src/shared/lib/chat/ask-questions.test.ts +65 -1
- package/src/shared/lib/chat/ask-questions.ts +51 -145
- package/src/shared/lib/chat/ask-results.ts +198 -0
- package/src/shared/lib/chat/composer/client.ts +20 -8
- package/src/shared/lib/chat/context/usage.test.ts +8 -4
- package/src/shared/lib/chat/context/usage.ts +17 -3
- package/src/shared/lib/chat/omp/abort.test.ts +61 -0
- package/src/shared/lib/chat/omp/abort.ts +8 -2
- package/src/shared/lib/chat/omp/tool-frames.test.ts +23 -0
- package/src/shared/lib/chat/omp/tool-frames.ts +12 -2
- package/src/shared/lib/chat/timeline/omp-callbacks.ts +13 -1
- package/src/shared/lib/chat/timeline/prompt-error.test.ts +146 -0
- package/src/shared/lib/chat/timeline/prompt-error.ts +88 -0
- package/src/shared/lib/chat/tool/summary-wait.test.ts +18 -8
- package/src/shared/lib/chat/tool/wait-facts.ts +14 -8
- package/src/shared/lib/harness/brand-color.test.ts +66 -0
- package/src/shared/lib/harness/brand-color.ts +96 -0
- package/src/shared/lib/harness/catalog.test.ts +88 -0
- package/src/shared/lib/harness/catalog.ts +169 -0
- package/src/shared/lib/harness/config-fields.test.ts +139 -0
- package/src/shared/lib/harness/config-fields.ts +168 -0
- package/src/shared/lib/harness/config.test.ts +153 -0
- package/src/shared/lib/harness/config.ts +206 -0
- package/src/shared/lib/harness/dialects.test.ts +140 -0
- package/src/shared/lib/harness/dialects.ts +249 -0
- package/src/shared/lib/harness/enabled.test.ts +79 -0
- package/src/shared/lib/harness/enabled.ts +72 -0
- package/src/shared/lib/harness/menu.test.ts +94 -0
- package/src/shared/lib/harness/menu.ts +88 -0
- package/src/shared/lib/harness/provider-facts.test.ts +199 -0
- package/src/shared/lib/harness/provider-facts.ts +349 -0
- package/src/shared/lib/harness/provider-slug.ts +46 -0
- package/src/shared/lib/harness/providers.ts +175 -0
- package/src/shared/lib/harness/rewind.ts +24 -0
- package/src/shared/lib/harness/status.test.ts +158 -0
- package/src/shared/lib/harness/status.ts +112 -0
- package/src/shared/lib/harness/update-plan.test.ts +163 -0
- package/src/shared/lib/harness/update-plan.ts +140 -0
- package/src/shared/lib/harness/updates.test.ts +106 -0
- package/src/shared/lib/harness/updates.ts +177 -0
- package/src/shared/lib/icons/icon-paint-authority.test.ts +16 -4
- package/src/shared/lib/icons/icon-paint-authority.ts +57 -12
- package/src/shared/lib/icons/icon-paint-bucket.test.ts +84 -0
- package/src/shared/lib/icons/icon-paint-css.test.ts +23 -25
- package/src/shared/lib/icons/icon-paint-css.ts +69 -55
- package/src/shared/lib/icons/icon-paint-harness.test.ts +73 -0
- package/src/shared/lib/icons/icon-paint-harness.ts +75 -0
- package/src/shared/lib/icons/icon-paint-ink.ts +108 -0
- package/src/shared/lib/icons/icon-paint-panel.ts +19 -4
- package/src/shared/lib/icons/icon-paint-weight.ts +21 -2
- package/src/shared/lib/icons/icon-tone.ts +118 -21
- package/src/shared/lib/icons/tint-hues.generated.ts +100 -284
- package/src/shared/lib/icons/tint-tones.test.ts +79 -25
- package/src/shared/lib/icons/tint.ts +66 -6
- package/src/shared/lib/models/client.ts +10 -1
- package/src/shared/lib/models/provider/vendors.ts +72 -0
- package/src/shared/lib/omp/config/schema.test.ts +36 -0
- package/src/shared/lib/omp/dialog-methods.ts +4 -3
- package/src/shared/lib/omp/session/messages-map-trace.test.ts +42 -0
- package/src/shared/lib/omp/session/messages-map.ts +6 -1
- package/src/shared/lib/omp/session/parse-message-blocks-toolcall.test.ts +8 -0
- package/src/shared/lib/omp/session/parse-message-blocks.ts +6 -1
- package/src/shared/lib/omp/session/shell-trace.test.ts +69 -0
- package/src/shared/lib/omp/session/shell-trace.ts +63 -0
- package/src/shared/lib/omp/session/sidebar.ts +37 -10
- package/src/shared/lib/omp/session/wait-idle.test.ts +47 -0
- package/src/shared/lib/omp/session/wait-idle.ts +93 -0
- package/src/shared/lib/omp/session/wait.test.ts +34 -33
- package/src/shared/lib/omp/session/wait.ts +25 -39
- package/src/shared/lib/settings/sections.ts +24 -0
- package/src/shared/lib/theme/css.ts +2 -0
- package/src/shared/lib/theme/ink-scale.ts +21 -1
- package/src/shared/lib/theme/theme.test.ts +25 -9
- package/src/shared/lib/ui/safe-area.test.ts +28 -0
- package/src/shared/lib/ui/safe-area.ts +42 -0
- package/src/shared/lib/ui/toast-duration.test.ts +74 -0
- package/src/shared/lib/ui/toast-duration.ts +70 -0
- package/src/shared/types/harness-version.ts +59 -0
- package/src/shared/types/harness.ts +201 -0
- package/src/shared/types/index.ts +2 -0
- package/src/shared/types/omp/agent.ts +13 -0
- package/src/shared/types/settings/state.ts +10 -1
- package/src/shared/types/workspace.ts +10 -0
- package/src/test-support/env.ts +38 -0
- package/src/test-support/file-explorer-render.test-util.ts +37 -0
- package/src/test-support/file-explorer.test-util.ts +20 -18
- package/src/test-support/harness-table.test-util.ts +108 -0
- package/dist/client/static/js/index-7ppta1pb.css +0 -1
|
@@ -0,0 +1,324 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* ZCode's personal providers: `~/.zcode/v2/provider_config.json` (3.12+).
|
|
8
|
+
*
|
|
9
|
+
* The shape is a RULE GRAPH, not the map every other registry uses:
|
|
10
|
+
*
|
|
11
|
+
* ```json
|
|
12
|
+
* { "schemaVersion": 1,
|
|
13
|
+
* "config": {
|
|
14
|
+
* "providerConfigRules": { "providerRules": [ { "providerId", "providerName", "config": {
|
|
15
|
+
* "access": { "type": "api-key", "apiKey" },
|
|
16
|
+
* "api": { "type": "openai-chat-completions", "baseUrl" } } } ] },
|
|
17
|
+
* "modelConfigRules": {
|
|
18
|
+
* "providerModelRules": [ { "providerId", "modelId", "config": { "enabled": true } } ],
|
|
19
|
+
* "manualProviderModelRules": [] } } }
|
|
20
|
+
* ```
|
|
21
|
+
*
|
|
22
|
+
* Two measured reasons the file is written carefully:
|
|
23
|
+
*
|
|
24
|
+
* - **A provider alone serves nothing.** The bridge builds its dropdown from
|
|
25
|
+
* the MODEL rules (`loadPersonalModels` reads `modelConfigRules` only), so a
|
|
26
|
+
* provider rule without a model rule is invisible. The writer therefore emits
|
|
27
|
+
* one rule per model id, beside the provider.
|
|
28
|
+
* - **The top level is strict.** `schemaVersion` and `config` are the only keys
|
|
29
|
+
* the backend accepts; everything inside `config` is carried through
|
|
30
|
+
* untouched. This writer merges exactly what it owns and preserves the rest,
|
|
31
|
+
* including manual model rules and the user's own headers.
|
|
32
|
+
*
|
|
33
|
+
* `~/.zcode/v2/config.json` is deliberately NOT touched: it is the desktop app's
|
|
34
|
+
* legacy provider map and its credentials. Personal providers belong in the file
|
|
35
|
+
* this module owns.
|
|
36
|
+
*/
|
|
37
|
+
|
|
38
|
+
import { withConfigLock } from '@/server/lib/fs/config-lock';
|
|
39
|
+
import { writeFileAtomic } from '@/server/lib/fs/atomic-write';
|
|
40
|
+
import { asRecord, type ProviderDraft } from '@/server/lib/harness/provider-entry';
|
|
41
|
+
import { ProviderWriteError } from '@/server/lib/harness/provider-write-error';
|
|
42
|
+
import { protocolOfSourceDialect } from '@/shared/lib/harness/dialects';
|
|
43
|
+
import type { ImportableProvider } from '@/server/lib/harness/provider-sources.server';
|
|
44
|
+
import type { ProviderWriteResult } from '@/server/lib/harness/provider-write.server';
|
|
45
|
+
|
|
46
|
+
function stringList(value: unknown): string[] {
|
|
47
|
+
return Array.isArray(value) ? value.filter((entry): entry is string => typeof entry === 'string' && entry.length > 0) : [];
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function ruleProviderId(rule: Record<string, unknown>): string {
|
|
51
|
+
return typeof rule.providerId === 'string' ? rule.providerId : '';
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** The provider rules and both model-rule arrays, created when absent. */
|
|
55
|
+
function ruleTables(doc: Record<string, unknown>): {
|
|
56
|
+
providers: unknown[];
|
|
57
|
+
smart: unknown[];
|
|
58
|
+
manual: unknown[];
|
|
59
|
+
} {
|
|
60
|
+
const config = asRecord(doc.config);
|
|
61
|
+
doc.config = config;
|
|
62
|
+
const providerConfigRules = asRecord(config.providerConfigRules);
|
|
63
|
+
config.providerConfigRules = providerConfigRules;
|
|
64
|
+
const modelConfigRules = asRecord(config.modelConfigRules);
|
|
65
|
+
config.modelConfigRules = modelConfigRules;
|
|
66
|
+
const providers = Array.isArray(providerConfigRules.providerRules) ? providerConfigRules.providerRules : [];
|
|
67
|
+
providerConfigRules.providerRules = providers;
|
|
68
|
+
const smart = Array.isArray(modelConfigRules.providerModelRules) ? modelConfigRules.providerModelRules : [];
|
|
69
|
+
modelConfigRules.providerModelRules = smart;
|
|
70
|
+
const manual = Array.isArray(modelConfigRules.manualProviderModelRules) ? modelConfigRules.manualProviderModelRules : [];
|
|
71
|
+
modelConfigRules.manualProviderModelRules = manual;
|
|
72
|
+
return { providers, smart, manual };
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** Model ids declared by BOTH rule arrays for one provider, in file order. */
|
|
76
|
+
function ruleModelIds(doc: Record<string, unknown>, providerId: string): string[] {
|
|
77
|
+
const { smart, manual } = ruleTables(doc);
|
|
78
|
+
const out: string[] = [];
|
|
79
|
+
for (const rule of [...smart, ...manual]) {
|
|
80
|
+
const entry = asRecord(rule);
|
|
81
|
+
if (ruleProviderId(entry) !== providerId) continue;
|
|
82
|
+
const modelId = typeof entry.modelId === 'string' ? entry.modelId : '';
|
|
83
|
+
if (!modelId || asRecord(entry.config).enabled === false) continue;
|
|
84
|
+
if (!out.includes(modelId)) out.push(modelId);
|
|
85
|
+
}
|
|
86
|
+
return out;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** Context windows a smart/manual model rule declares. */
|
|
90
|
+
function ruleContextWindows(doc: Record<string, unknown>): Record<string, number> {
|
|
91
|
+
const { smart, manual } = ruleTables(doc);
|
|
92
|
+
const out: Record<string, number> = {};
|
|
93
|
+
for (const rule of [...smart, ...manual]) {
|
|
94
|
+
const entry = asRecord(rule);
|
|
95
|
+
const providerId = ruleProviderId(entry);
|
|
96
|
+
const modelId = typeof entry.modelId === 'string' ? entry.modelId : '';
|
|
97
|
+
const size = asRecord(asRecord(entry.config).properties).contextWindow;
|
|
98
|
+
if (providerId && modelId && typeof size === 'number' && size > 0) out[`${providerId}/${modelId}`] = size;
|
|
99
|
+
}
|
|
100
|
+
return out;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Every custom provider the file holds, credential-free.
|
|
105
|
+
*
|
|
106
|
+
* A malformed document yields nothing: this reader feeds a settings card, and
|
|
107
|
+
* refusing to draw the page over the agent's own broken file would hide the only
|
|
108
|
+
* place that can explain it.
|
|
109
|
+
*/
|
|
110
|
+
export function readZcodeProviders(text: string | null, source: ImportableProvider['source']): ImportableProvider[] {
|
|
111
|
+
if (!text) return [];
|
|
112
|
+
let doc: Record<string, unknown>;
|
|
113
|
+
try {
|
|
114
|
+
const parsed: unknown = JSON.parse(text);
|
|
115
|
+
if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) return [];
|
|
116
|
+
doc = parsed as Record<string, unknown>;
|
|
117
|
+
} catch {
|
|
118
|
+
return [];
|
|
119
|
+
}
|
|
120
|
+
const { providers } = ruleTables(doc);
|
|
121
|
+
const windows = ruleContextWindows(doc);
|
|
122
|
+
const out: ImportableProvider[] = [];
|
|
123
|
+
for (const raw of providers) {
|
|
124
|
+
const rule = asRecord(raw);
|
|
125
|
+
const id = ruleProviderId(rule);
|
|
126
|
+
if (!id || id.startsWith('builtin:') || id.startsWith('account:')) continue;
|
|
127
|
+
const config = asRecord(rule.config);
|
|
128
|
+
const access = asRecord(config.access);
|
|
129
|
+
const api = asRecord(config.api);
|
|
130
|
+
const dialect = typeof api.type === 'string' ? api.type : undefined;
|
|
131
|
+
const protocol = protocolOfSourceDialect(dialect);
|
|
132
|
+
const models = [...ruleModelIds(doc, id)];
|
|
133
|
+
for (const declared of stringList(config.personalModelIds)) {
|
|
134
|
+
if (!models.includes(declared)) models.push(declared);
|
|
135
|
+
}
|
|
136
|
+
const contextWindow = Object.fromEntries(
|
|
137
|
+
models.flatMap((modelId) => {
|
|
138
|
+
const size = windows[`${id}/${modelId}`];
|
|
139
|
+
return size ? [[modelId, size]] : [];
|
|
140
|
+
}),
|
|
141
|
+
);
|
|
142
|
+
out.push({
|
|
143
|
+
id,
|
|
144
|
+
name: typeof rule.providerName === 'string' && rule.providerName.trim() ? rule.providerName : id,
|
|
145
|
+
...(typeof api.baseUrl === 'string' && api.baseUrl ? { baseUrl: api.baseUrl } : {}),
|
|
146
|
+
...(dialect ? { dialect } : {}),
|
|
147
|
+
...(protocol ? { protocol } : {}),
|
|
148
|
+
models,
|
|
149
|
+
...(Object.keys(contextWindow).length > 0 ? { contextWindow } : {}),
|
|
150
|
+
source,
|
|
151
|
+
hasKey: typeof access.apiKey === 'string' && access.apiKey.length > 0,
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
return out;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/** One provider's credential, read only by the request that writes a target. */
|
|
158
|
+
export function readZcodeProviderKey(text: string | null, providerId: string): string | null {
|
|
159
|
+
if (!text) return null;
|
|
160
|
+
try {
|
|
161
|
+
const parsed: unknown = JSON.parse(text);
|
|
162
|
+
if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) return null;
|
|
163
|
+
const { providers } = ruleTables(parsed as Record<string, unknown>);
|
|
164
|
+
const rule = providers.map(asRecord).find((entry) => ruleProviderId(entry) === providerId);
|
|
165
|
+
const key = asRecord(asRecord(rule?.config).access).apiKey;
|
|
166
|
+
return typeof key === 'string' && key.length > 0 ? key : null;
|
|
167
|
+
} catch {
|
|
168
|
+
return null;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/** An empty document in the file's canonical shape. */
|
|
173
|
+
function emptyDocument(): Record<string, unknown> {
|
|
174
|
+
const doc: Record<string, unknown> = { schemaVersion: 1 };
|
|
175
|
+
ruleTables(doc);
|
|
176
|
+
return doc;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
function union(first: string[], second: string[]): string[] {
|
|
180
|
+
const out = [...first];
|
|
181
|
+
for (const entry of second) if (entry && !out.includes(entry)) out.push(entry);
|
|
182
|
+
return out;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* Merge ONE provider (and its model rules) into the personal provider file.
|
|
187
|
+
*
|
|
188
|
+
* Fields this writer does not own survive: headers, `apiKeyManagementUrl`,
|
|
189
|
+
* `logo`, `templateId`, a manual model rule's capability block, `providerOrder`
|
|
190
|
+
* and `defaultModelSelection`. A stored credential is kept when the draft brings
|
|
191
|
+
* none, the same rule every other writer follows.
|
|
192
|
+
*/
|
|
193
|
+
export async function writeZcodeProvider(input: {
|
|
194
|
+
path: string;
|
|
195
|
+
id: string;
|
|
196
|
+
draft: ProviderDraft;
|
|
197
|
+
dialect: string;
|
|
198
|
+
}): Promise<ProviderWriteResult> {
|
|
199
|
+
const { path, id, draft, dialect } = input;
|
|
200
|
+
// The runtime's own writer locks a DIRECTORY at `${path}.lock` (its
|
|
201
|
+
// `file-lock.ts`), so a file at that exact path would look like a lock it
|
|
202
|
+
// must reclaim. Kabmo serialises its own writers on a distinct lease and the
|
|
203
|
+
// final rename stays atomic; the app's poll picks the write up.
|
|
204
|
+
return withConfigLock(`${path}.kabmo`, async () => {
|
|
205
|
+
const file = Bun.file(path);
|
|
206
|
+
const raw = (await file.exists()) ? await file.text() : '';
|
|
207
|
+
let doc: Record<string, unknown>;
|
|
208
|
+
if (raw.trim()) {
|
|
209
|
+
try {
|
|
210
|
+
const parsed: unknown = JSON.parse(raw);
|
|
211
|
+
if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) throw new Error('not a document');
|
|
212
|
+
doc = parsed as Record<string, unknown>;
|
|
213
|
+
} catch (cause) {
|
|
214
|
+
throw new ProviderWriteError(`${path} could not be parsed, so it was left untouched: ${String(cause)}`);
|
|
215
|
+
}
|
|
216
|
+
} else {
|
|
217
|
+
doc = emptyDocument();
|
|
218
|
+
}
|
|
219
|
+
if (typeof doc.schemaVersion !== 'number') doc.schemaVersion = 1;
|
|
220
|
+
|
|
221
|
+
const { providers, smart, manual } = ruleTables(doc);
|
|
222
|
+
const index = providers.findIndex((rule) => ruleProviderId(asRecord(rule)) === id);
|
|
223
|
+
const existing = index >= 0 ? asRecord(providers[index]) : {};
|
|
224
|
+
const existingConfig = asRecord(existing.config);
|
|
225
|
+
const existingAccess = asRecord(existingConfig.access);
|
|
226
|
+
const existingApi = asRecord(existingConfig.api);
|
|
227
|
+
const baseUrl = draft.baseUrl?.trim() || (typeof existingApi.baseUrl === 'string' ? existingApi.baseUrl : '');
|
|
228
|
+
if (!baseUrl) {
|
|
229
|
+
throw new ProviderWriteError(
|
|
230
|
+
`ZCode needs a base URL for "${id}": a standalone personal provider has no inherited endpoint.`,
|
|
231
|
+
);
|
|
232
|
+
}
|
|
233
|
+
const apiKey = draft.apiKey?.trim();
|
|
234
|
+
const models = union(stringList(existingConfig.personalModelIds), draft.models);
|
|
235
|
+
const rule = {
|
|
236
|
+
...existing,
|
|
237
|
+
providerId: id,
|
|
238
|
+
providerName: draft.name || (typeof existing.providerName === 'string' ? existing.providerName : id),
|
|
239
|
+
enabled: true,
|
|
240
|
+
config: {
|
|
241
|
+
...existingConfig,
|
|
242
|
+
group: typeof existingConfig.group === 'string' ? existingConfig.group : 'standard-personal',
|
|
243
|
+
visibility: 'visible',
|
|
244
|
+
access: {
|
|
245
|
+
...existingAccess,
|
|
246
|
+
type: apiKey ? 'api-key' : (typeof existingAccess.type === 'string' ? existingAccess.type : 'api-key'),
|
|
247
|
+
...(apiKey ? { apiKey } : {}),
|
|
248
|
+
},
|
|
249
|
+
api: { ...existingApi, type: dialect, baseUrl },
|
|
250
|
+
personalModelIds: models,
|
|
251
|
+
modelOrder: union(stringList(existingConfig.modelOrder), models),
|
|
252
|
+
},
|
|
253
|
+
};
|
|
254
|
+
if (index >= 0) providers[index] = rule;
|
|
255
|
+
else providers.push(rule);
|
|
256
|
+
|
|
257
|
+
// One model rule per id: a provider rule with no model rule is invisible to
|
|
258
|
+
// the dropdown (see the module header). Existing rules are updated in place,
|
|
259
|
+
// and a MANUAL rule stays manual — moving it would drop the capability block
|
|
260
|
+
// the user configured by hand.
|
|
261
|
+
let addedRules = 0;
|
|
262
|
+
for (const modelId of models) {
|
|
263
|
+
const contextWindow = draft.contextWindow?.[modelId];
|
|
264
|
+
const manualIndex = manual.findIndex((entry) => {
|
|
265
|
+
const row = asRecord(entry);
|
|
266
|
+
return ruleProviderId(row) === id && row.modelId === modelId;
|
|
267
|
+
});
|
|
268
|
+
const smartIndex = smart.findIndex((entry) => {
|
|
269
|
+
const row = asRecord(entry);
|
|
270
|
+
return ruleProviderId(row) === id && row.modelId === modelId;
|
|
271
|
+
});
|
|
272
|
+
const target = manualIndex >= 0 ? manual : smartIndex >= 0 ? smart : null;
|
|
273
|
+
const at = manualIndex >= 0 ? manualIndex : smartIndex;
|
|
274
|
+
if (target) {
|
|
275
|
+
const row = asRecord(target[at]);
|
|
276
|
+
const config = asRecord(row.config);
|
|
277
|
+
const properties = asRecord(config.properties);
|
|
278
|
+
target[at] = {
|
|
279
|
+
...row,
|
|
280
|
+
config: {
|
|
281
|
+
...config,
|
|
282
|
+
enabled: true,
|
|
283
|
+
...(contextWindow && typeof properties.contextWindow !== 'number'
|
|
284
|
+
? { properties: { ...properties, contextWindow } }
|
|
285
|
+
: {}),
|
|
286
|
+
},
|
|
287
|
+
};
|
|
288
|
+
continue;
|
|
289
|
+
}
|
|
290
|
+
smart.push({
|
|
291
|
+
providerId: id,
|
|
292
|
+
modelId,
|
|
293
|
+
config: {
|
|
294
|
+
enabled: true,
|
|
295
|
+
...(contextWindow ? { properties: { contextWindow } } : {}),
|
|
296
|
+
// A custom model has no catalog entry, so WITHOUT an explicit map the
|
|
297
|
+
// runtime inherits a family rule (measured: a `qwen3-…` id inherited
|
|
298
|
+
// `enable_thinking` + `thinking` + `reasoning_effort`, and the gateway
|
|
299
|
+
// answered 400 for every turn). The catalog's own generic rule maps no
|
|
300
|
+
// reasoning parameters; copying it keeps an unknown endpoint usable and
|
|
301
|
+
// never sends a field the endpoint did not advertise.
|
|
302
|
+
optionSpecs: { reasoningLevel: { values: ['disabled', 'enabled'], map: '{}' } },
|
|
303
|
+
},
|
|
304
|
+
});
|
|
305
|
+
addedRules += 1;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
const text = JSON.stringify(doc, null, 2);
|
|
309
|
+
await writeFileAtomic(path, text, { createMode: 0o600 });
|
|
310
|
+
const notes: string[] = [
|
|
311
|
+
`Wrote ${models.length} model rule${models.length === 1 ? '' : 's'} into provider_config.json — ZCode lists a custom provider’s models from that table, not from the provider rule alone.`,
|
|
312
|
+
];
|
|
313
|
+
if (draft.models.length === 0) {
|
|
314
|
+
notes.push('No model ids were given, so this provider serves nothing until one is added.');
|
|
315
|
+
}
|
|
316
|
+
if (addedRules > 0) {
|
|
317
|
+
notes.push('New model rules map NO reasoning parameters: the runtime otherwise inherits a catalog family mapping (measured: `enable_thinking`), which a custom endpoint can reject with 400. An existing rule keeps its own mapping.');
|
|
318
|
+
}
|
|
319
|
+
if (!apiKey && typeof existingAccess.apiKey === 'string' && existingAccess.apiKey) {
|
|
320
|
+
notes.push('Kept the stored API key — the draft carried none.');
|
|
321
|
+
}
|
|
322
|
+
return { id, replaced: index >= 0, path, dialect, env: {}, notes };
|
|
323
|
+
});
|
|
324
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Register an ACP session in the shared registry.
|
|
8
|
+
*
|
|
9
|
+
* The two-key rule is omp's, and it matters here for the same reason: an agent
|
|
10
|
+
* may answer a DIFFERENT id than the one asked for (a `session/load` that forks,
|
|
11
|
+
* a first `session/new` on a placeholder). The client keeps posting to the id it
|
|
12
|
+
* holds — its URL, its topic subscription — so the registry must answer for
|
|
13
|
+
* both, and the alias must be removed when the session dies or a dead wrapper
|
|
14
|
+
* answers for a live id.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import type { HarnessSession } from '@/server/lib/harness/session';
|
|
18
|
+
|
|
19
|
+
/** Pulled from the omp registry module so there is one map, not two. */
|
|
20
|
+
export function registerAcpSession(session: HarnessSession, requestedId: string): void {
|
|
21
|
+
// Imported lazily: `session-registry` imports the omp manager, which imports
|
|
22
|
+
// this file's neighbours, and a top-level import would close that cycle.
|
|
23
|
+
const registry = liveRegistry();
|
|
24
|
+
registry.set(session.sessionId, session);
|
|
25
|
+
if (requestedId && requestedId !== session.sessionId) registry.set(requestedId, session);
|
|
26
|
+
session.onDestroy(() => {
|
|
27
|
+
if (registry.get(session.sessionId) === session) registry.delete(session.sessionId);
|
|
28
|
+
if (registry.get(requestedId) === session) registry.delete(requestedId);
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function liveRegistry(): Map<string, HarnessSession> {
|
|
33
|
+
const bag = globalThis as unknown as { __ompSessions?: Map<string, HarnessSession> };
|
|
34
|
+
if (!bag.__ompSessions) bag.__ompSessions = new Map();
|
|
35
|
+
return bag.__ompSessions;
|
|
36
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The ONE registry of live sessions, whichever harness runs them.
|
|
8
|
+
*
|
|
9
|
+
* omp sessions have lived in a `Map<string, AgentSessionWrapper>` on
|
|
10
|
+
* `globalThis` since before harnesses existed; this module keeps that map as the
|
|
11
|
+
* single source and adds an ACP driver that registers into it. Two maps would
|
|
12
|
+
* mean two answers to "is this session live", and the sidebar, the realtime
|
|
13
|
+
* topic and the queue all ask that question.
|
|
14
|
+
*
|
|
15
|
+
* `globalThis` for the documented reason: `bun --hot` re-evaluates a module
|
|
16
|
+
* while the child processes it describes keep running.
|
|
17
|
+
*
|
|
18
|
+
* The harness id travels WITH the session (a `WeakMap`, so a session that dies
|
|
19
|
+
* cannot leak), because `HarnessSession` has no `harness` accessor on the omp
|
|
20
|
+
* wrapper — adding one there would make an omp-only class answer a question
|
|
21
|
+
* about a driver it does not have.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
import type { AgentSessionWrapper } from '@/server/lib/omp/rpc/manager';
|
|
25
|
+
import type { HarnessId } from '@/shared/lib/harness/catalog';
|
|
26
|
+
import type { HarnessSession } from '@/server/lib/harness/session';
|
|
27
|
+
|
|
28
|
+
type AnySession = AgentSessionWrapper | HarnessSession;
|
|
29
|
+
|
|
30
|
+
declare global {
|
|
31
|
+
// eslint-disable-next-line no-var
|
|
32
|
+
var __kabmoHarnessOf: WeakMap<object, HarnessId> | undefined;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function harnessMap(): WeakMap<object, HarnessId> {
|
|
36
|
+
globalThis.__kabmoHarnessOf ??= new WeakMap();
|
|
37
|
+
return globalThis.__kabmoHarnessOf;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** Record which harness owns a session object. Called once, at spawn. */
|
|
41
|
+
export function claimHarness(session: AnySession, harness: HarnessId): void {
|
|
42
|
+
harnessMap().set(session as object, harness);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* The harness behind a live session. Absent means omp RPC: every session that
|
|
47
|
+
* predates this registry is one, and a default here is what keeps a live omp
|
|
48
|
+
* chat from being reported as `unknown`.
|
|
49
|
+
*/
|
|
50
|
+
export function harnessOf(session: AnySession): HarnessId {
|
|
51
|
+
return harnessMap().get(session as object) ?? 'omp-rpc';
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** Narrow a live session to the transport contract, for callers that only need
|
|
55
|
+
* the shared surface. */
|
|
56
|
+
export function asHarnessSession(session: AnySession): HarnessSession {
|
|
57
|
+
return session as unknown as HarnessSession;
|
|
58
|
+
}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Which harness owns a session, persisted.
|
|
8
|
+
*
|
|
9
|
+
* The live registry (`registry.ts`) answers this for a session THIS process is
|
|
10
|
+
* running, in a `WeakMap` keyed by the session object. That is the right answer
|
|
11
|
+
* for "is it live" and the wrong one for "which agent produced this chat": a
|
|
12
|
+
* closed tab, a restart, or a second Kabmo instance on the same database all lose
|
|
13
|
+
* the map, and the sidebar then has nothing to draw.
|
|
14
|
+
*
|
|
15
|
+
* So a spawn writes one row here, and the sidebar reads it. Without it EVERY row
|
|
16
|
+
* was reported as `omp-rpc` (`sidebar-data.server.ts` filled the field from
|
|
17
|
+
* `DEFAULT_HARNESS_ID`), which is indistinguishable from "not tracked" — the
|
|
18
|
+
* mark beside a session name told the reader `omp` no matter which agent ran it.
|
|
19
|
+
*
|
|
20
|
+
* The agent's own session id is stored beside ours because ACP can answer a
|
|
21
|
+
* DIFFERENT id than the one asked for (a `session/load` that forks), and resuming
|
|
22
|
+
* a chat has to send the AGENT's id, not Kabmo's.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
import type { DbClient } from '@/server/lib/db/client';
|
|
26
|
+
|
|
27
|
+
const HARNESS_SESSIONS_SQL = `
|
|
28
|
+
CREATE TABLE IF NOT EXISTS harness_sessions (
|
|
29
|
+
session_id TEXT PRIMARY KEY,
|
|
30
|
+
harness TEXT NOT NULL,
|
|
31
|
+
-- The id the AGENT reported. Empty for omp's RPC sessions, whose id is
|
|
32
|
+
-- Kabmo's own (omp generates it and both sides use it).
|
|
33
|
+
agent_session_id TEXT NOT NULL DEFAULT '',
|
|
34
|
+
cwd TEXT NOT NULL DEFAULT '',
|
|
35
|
+
-- What the chat is CALLED. An ACP agent writes no session file, so omp's
|
|
36
|
+
-- JSONL discovery — the thing that names every omp row — has nothing to
|
|
37
|
+
-- read, and every recorded chat drew "Untitled" forever while the user's own
|
|
38
|
+
-- first line sat unused. Holds the agent's own title when it published one,
|
|
39
|
+
-- else the first prompt; see harness/session-title.server.ts.
|
|
40
|
+
title TEXT NOT NULL DEFAULT '',
|
|
41
|
+
created_at INTEGER NOT NULL,
|
|
42
|
+
updated_at INTEGER NOT NULL
|
|
43
|
+
);
|
|
44
|
+
CREATE INDEX IF NOT EXISTS idx_harness_sessions_harness
|
|
45
|
+
ON harness_sessions (harness);
|
|
46
|
+
`;
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* The additive column for a database created before `title` existed.
|
|
50
|
+
*
|
|
51
|
+
* `CREATE TABLE IF NOT EXISTS` leaves an existing table alone, so a row written
|
|
52
|
+
* by an older build would miss the column and every read of it would fail —
|
|
53
|
+
* including the sidebar's, which selects the whole table.
|
|
54
|
+
*/
|
|
55
|
+
const HARNESS_SESSIONS_MIGRATIONS = `
|
|
56
|
+
ALTER TABLE harness_sessions ADD COLUMN title TEXT NOT NULL DEFAULT '';
|
|
57
|
+
`;
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* What each agent reported, persisted.
|
|
61
|
+
*
|
|
62
|
+
* The probe cache lived only in memory for the process lifetime, so EVERY server
|
|
63
|
+
* restart — including a `bun --hot` reload — emptied it and every harness went
|
|
64
|
+
* back to `not probed` even though the user had pressed Check status a minute
|
|
65
|
+
* earlier. The answer is a property of the INSTALLED BINARY, not of the process,
|
|
66
|
+
* so it belongs on disk; `probed_at` is what keeps the TTL meaningful (the file
|
|
67
|
+
* it describes can still change under an update).
|
|
68
|
+
*
|
|
69
|
+
* One row per harness: a probe REPLACES the previous one, and the whole payload
|
|
70
|
+
* is a single JSON document because nothing queries into it.
|
|
71
|
+
*/
|
|
72
|
+
const HARNESS_PROBES_SQL = `
|
|
73
|
+
CREATE TABLE IF NOT EXISTS harness_probes (
|
|
74
|
+
harness TEXT PRIMARY KEY,
|
|
75
|
+
payload TEXT NOT NULL,
|
|
76
|
+
probed_at INTEGER NOT NULL
|
|
77
|
+
);
|
|
78
|
+
`;
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Goal mode on a transport that has no `/kabmo-mode` extension.
|
|
82
|
+
*
|
|
83
|
+
* An ACP agent other than omp carries no extension, so the goal record cannot
|
|
84
|
+
* live in a transcript. Kabmo owns it here: the composer's actions write this
|
|
85
|
+
* row, the goal driver reads it after every turn, and the modes route answers
|
|
86
|
+
* from it on reload. `plan` is mirrored too, because a dead ACP session has no
|
|
87
|
+
* selector left to ask.
|
|
88
|
+
*/
|
|
89
|
+
const HARNESS_GOAL_STATE_SQL = `
|
|
90
|
+
CREATE TABLE IF NOT EXISTS harness_goal_state (
|
|
91
|
+
session_id TEXT PRIMARY KEY,
|
|
92
|
+
record TEXT,
|
|
93
|
+
continuation TEXT,
|
|
94
|
+
plan INTEGER NOT NULL DEFAULT 0,
|
|
95
|
+
max_turns INTEGER,
|
|
96
|
+
turns INTEGER NOT NULL DEFAULT 0,
|
|
97
|
+
updated_at INTEGER NOT NULL
|
|
98
|
+
);
|
|
99
|
+
`;
|
|
100
|
+
|
|
101
|
+
/** The last usage an ACP agent reported, so the Context ring survives a reload
|
|
102
|
+
* of a chat whose process is gone (omp has its JSONL to re-read; this doesn't). */
|
|
103
|
+
const HARNESS_USAGE_STATE_SQL = `
|
|
104
|
+
CREATE TABLE IF NOT EXISTS harness_usage_state (
|
|
105
|
+
session_id TEXT PRIMARY KEY,
|
|
106
|
+
used INTEGER NOT NULL DEFAULT 0,
|
|
107
|
+
size INTEGER NOT NULL DEFAULT 0,
|
|
108
|
+
cost REAL NOT NULL DEFAULT 0,
|
|
109
|
+
messages INTEGER NOT NULL DEFAULT 0,
|
|
110
|
+
prompts INTEGER NOT NULL DEFAULT 0,
|
|
111
|
+
assistants INTEGER NOT NULL DEFAULT 0,
|
|
112
|
+
model_provider TEXT NOT NULL DEFAULT '',
|
|
113
|
+
model_id TEXT NOT NULL DEFAULT '',
|
|
114
|
+
updated_at INTEGER NOT NULL
|
|
115
|
+
);
|
|
116
|
+
`;
|
|
117
|
+
|
|
118
|
+
/** Idempotent: created on every database open, like every other feature table. */
|
|
119
|
+
export async function ensureHarnessSchema(db: DbClient): Promise<void> {
|
|
120
|
+
await db.exec(HARNESS_SESSIONS_SQL);
|
|
121
|
+
await db.exec(HARNESS_PROBES_SQL);
|
|
122
|
+
await db.exec(HARNESS_GOAL_STATE_SQL);
|
|
123
|
+
await db.exec(HARNESS_USAGE_STATE_SQL);
|
|
124
|
+
try {
|
|
125
|
+
await db.exec(HARNESS_SESSIONS_MIGRATIONS);
|
|
126
|
+
} catch {
|
|
127
|
+
// Already present — a fresh install gets the column from the DDL above.
|
|
128
|
+
}
|
|
129
|
+
}
|