@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,339 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* One ACP agent child, driven over newline-delimited JSON-RPC on stdio.
|
|
8
|
+
*
|
|
9
|
+
* Deliberately NOT built on `RpcProcess`: that class speaks omp's RPC dialect
|
|
10
|
+
* (`{type:"ready"}`, `{type:"response", command}`, protocol-v2 chunking), and a
|
|
11
|
+
* second protocol bolted into it would make every omp path answer questions
|
|
12
|
+
* about ACP. The two share only `readLines` and the kill-tree helper.
|
|
13
|
+
*
|
|
14
|
+
* Three behaviours here exist because a measured agent does them:
|
|
15
|
+
*
|
|
16
|
+
* - **non-JSON lines on stdout.** `opencode acp` prints plugin-boot logs
|
|
17
|
+
* (`[opencode-blob-office] Plugin initialization START`) before its first
|
|
18
|
+
* frame. A strict parser failed the transport; this one skips the line.
|
|
19
|
+
* - **unsolicited notifications.** `claude-agent-acp` pushes
|
|
20
|
+
* `_auth/status_update` ~3.4 s after `initialize` with nobody asking. Unknown
|
|
21
|
+
* notifications are forwarded, never treated as errors.
|
|
22
|
+
* - **agent→client requests.** `fs/read_text_file`, `terminal/*`, and
|
|
23
|
+
* `session/request_permission` are calls the AGENT makes on the CLIENT. An
|
|
24
|
+
* unanswered one hangs the turn, so every request is either answered or
|
|
25
|
+
* explicitly refused — never dropped.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
import type { Subprocess } from 'bun';
|
|
29
|
+
import { readLines } from '@/server/lib/omp/rpc/lines';
|
|
30
|
+
import { PendingCalls } from '@/server/lib/harness/acp/calls';
|
|
31
|
+
import { killProcessTree } from '@/server/lib/lifecycle/kill-tree';
|
|
32
|
+
import { stripKabmoHostEnv, withToolchainPath } from '@kabmo-labs/kabmo-sdk';
|
|
33
|
+
import * as verbs from '@/server/lib/harness/acp/verbs';
|
|
34
|
+
import type {
|
|
35
|
+
AcpId,
|
|
36
|
+
AcpInitializeResult,
|
|
37
|
+
AcpNotification,
|
|
38
|
+
AcpRequest,
|
|
39
|
+
AcpResponse,
|
|
40
|
+
} from '@/server/lib/harness/acp/protocol';
|
|
41
|
+
|
|
42
|
+
/** Called for every agent→client request this host knows how to answer. The
|
|
43
|
+
* boolean says "answered"; `false` makes the client reply with a refusal so the
|
|
44
|
+
* agent never waits on a dropped call. */
|
|
45
|
+
export type AcpClientRequestHandler = (
|
|
46
|
+
id: AcpId,
|
|
47
|
+
method: string,
|
|
48
|
+
params: Record<string, unknown>,
|
|
49
|
+
) => Promise<{ answered: true; result: unknown } | { answered: false; message: string } | { answered: false; deferred: true }>;
|
|
50
|
+
|
|
51
|
+
export interface AcpClientOptions {
|
|
52
|
+
command: string[];
|
|
53
|
+
cwd: string;
|
|
54
|
+
env?: Record<string, string>;
|
|
55
|
+
/** Frame sink: `session/update` notifications and unknown notifications. */
|
|
56
|
+
onNotification: (method: string, params: Record<string, unknown>) => void;
|
|
57
|
+
/** Agent→client request hook, before the built-in refusals. */
|
|
58
|
+
onClientRequest?: AcpClientRequestHandler;
|
|
59
|
+
onStderr?: (line: string) => void;
|
|
60
|
+
onExit?: (info: { code: number | null; signal: string | null; stderrTail: string }) => void;
|
|
61
|
+
/** How long a client→agent request may take. Every call here is a control
|
|
62
|
+
* verb; a prompt is fire-and-await-resolve at the END of the turn, so its
|
|
63
|
+
* cap is the caller's business and is passed explicitly. */
|
|
64
|
+
requestTimeoutMs?: number;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const DEFAULT_REQUEST_TIMEOUT_MS = 60_000;
|
|
68
|
+
const STDERR_TAIL_LIMIT = 8_000;
|
|
69
|
+
|
|
70
|
+
export class AcpProcess {
|
|
71
|
+
private readonly child: Subprocess<'pipe', 'pipe', 'pipe'>;
|
|
72
|
+
private readonly pending = new PendingCalls();
|
|
73
|
+
private readonly options: AcpClientOptions;
|
|
74
|
+
private nextId = 1;
|
|
75
|
+
private exited = false;
|
|
76
|
+
private stderrTail = '';
|
|
77
|
+
private writeQueue: Promise<void> = Promise.resolve();
|
|
78
|
+
/** Set once `initialize` answers, so a request sent earlier fails loudly
|
|
79
|
+
* instead of racing the handshake. */
|
|
80
|
+
private initialized = false;
|
|
81
|
+
|
|
82
|
+
constructor(options: AcpClientOptions) {
|
|
83
|
+
this.options = options;
|
|
84
|
+
const [command, ...args] = options.command;
|
|
85
|
+
if (!command) throw new Error('ACP launch command is empty');
|
|
86
|
+
const childEnv = withToolchainPath(
|
|
87
|
+
stripKabmoHostEnv({ ...Bun.env, ...options.env }, process.platform),
|
|
88
|
+
process.platform,
|
|
89
|
+
);
|
|
90
|
+
try {
|
|
91
|
+
this.child = Bun.spawn({
|
|
92
|
+
cmd: [command, ...args],
|
|
93
|
+
cwd: options.cwd,
|
|
94
|
+
env: childEnv,
|
|
95
|
+
stdin: 'pipe',
|
|
96
|
+
stdout: 'pipe',
|
|
97
|
+
stderr: 'pipe',
|
|
98
|
+
windowsHide: true,
|
|
99
|
+
// Its own process group, exactly like the omp child: an ACP adapter
|
|
100
|
+
// spawns ITS own agent binary (codex-acp runs codex, pi-acp runs pi),
|
|
101
|
+
// so killing only the adapter leaves the real agent running.
|
|
102
|
+
detached: process.platform !== 'win32',
|
|
103
|
+
});
|
|
104
|
+
} catch (error) {
|
|
105
|
+
throw new Error(
|
|
106
|
+
`Could not start ${command}: ${error instanceof Error ? error.message : String(error)}`,
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
void readLines(this.child.stdout, (line) => this.handleLine(line));
|
|
111
|
+
void readLines(this.child.stderr, (line) => {
|
|
112
|
+
this.stderrTail = `${this.stderrTail}${line}\n`.slice(-STDERR_TAIL_LIMIT);
|
|
113
|
+
this.options.onStderr?.(line);
|
|
114
|
+
});
|
|
115
|
+
void this.child.exited.then((code) => {
|
|
116
|
+
this.exited = true;
|
|
117
|
+
// The agent's own last words, when it left any: `exited (code 0)` is what
|
|
118
|
+
// a shadowed/deprecated binary prints while it explains itself on stderr,
|
|
119
|
+
// and without the tail the spawn failure names nothing actionable.
|
|
120
|
+
const detail = this.stderrTail.trim().split('\n').slice(-3).join(' · ');
|
|
121
|
+
this.rejectAll(new Error(`ACP agent exited (code ${code})${detail ? ` — ${detail}` : ''}`));
|
|
122
|
+
this.options.onExit?.({ code, signal: null, stderrTail: this.stderrTail });
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
get isAlive(): boolean {
|
|
127
|
+
return !this.exited;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
get pid(): number | undefined {
|
|
131
|
+
return this.child.pid ?? undefined;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/** `initialize`: the handshake that also publishes the agent's capabilities.
|
|
135
|
+
* Kabmo advertises NO fs and NO terminal capability by default — declaring
|
|
136
|
+
* one it cannot serve makes the agent hang on a call nobody answers. A driver
|
|
137
|
+
* that wires real bridges passes them in. */
|
|
138
|
+
async initialize(capabilities: Record<string, unknown> = {}, timeoutMs = 60_000): Promise<AcpInitializeResult> {
|
|
139
|
+
const result = await this.request<AcpInitializeResult>(
|
|
140
|
+
'initialize',
|
|
141
|
+
{
|
|
142
|
+
protocolVersion: 1,
|
|
143
|
+
clientCapabilities: capabilities,
|
|
144
|
+
clientInfo: { name: 'kabmo', title: 'Kabmo', version: '0.1' },
|
|
145
|
+
},
|
|
146
|
+
timeoutMs,
|
|
147
|
+
);
|
|
148
|
+
this.initialized = true;
|
|
149
|
+
return result;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
get hasInitialized(): boolean {
|
|
153
|
+
return this.initialized;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// ── protocol verbs ───────────────────────────────────────────────────────
|
|
157
|
+
// Thin delegates to `verbs.ts`: the transport owns framing, the verbs own the
|
|
158
|
+
// wire shape. Callers keep using `proc.newSession(...)`.
|
|
159
|
+
|
|
160
|
+
newSession(cwd: string, timeoutMs?: number) {
|
|
161
|
+
return verbs.newSession(this.call, cwd, timeoutMs);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
loadSession(sessionId: string, cwd: string, timeoutMs?: number) {
|
|
165
|
+
return verbs.loadSession(this.call, sessionId, cwd, timeoutMs);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
resumeSession(sessionId: string, cwd: string, timeoutMs?: number) {
|
|
169
|
+
return verbs.resumeSession(this.call, sessionId, cwd, timeoutMs);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
forkSession(sessionId: string, cwd: string, timeoutMs?: number) {
|
|
173
|
+
return verbs.forkSession(this.call, sessionId, cwd, timeoutMs);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
listSessions(cwd?: string, timeoutMs?: number) {
|
|
177
|
+
return verbs.listSessions(this.call, cwd, timeoutMs);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
prompt(sessionId: string, blocks: unknown[], timeoutMs?: number) {
|
|
181
|
+
return verbs.prompt(this.call, sessionId, blocks, timeoutMs);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
cancel(sessionId: string): void {
|
|
185
|
+
verbs.cancel(this.notify, sessionId);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/** Settle this session's open `session/prompt` locally, as cancelled. The
|
|
189
|
+
* rule, and why omp forces it, live in `PendingCalls.abandonPrompt`. */
|
|
190
|
+
abandonPrompt(sessionId: string): void {
|
|
191
|
+
this.pending.abandonPrompt(sessionId);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
setConfigOption(sessionId: string, configId: string, value: string | boolean, timeoutMs?: number) {
|
|
195
|
+
return verbs.setConfigOption(this.call, sessionId, configId, value, timeoutMs);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
steer(sessionId: string, blocks: unknown[], queue?: 'steering' | 'followUp', timeoutMs?: number) {
|
|
199
|
+
return verbs.steer(this.call, sessionId, blocks, queue, timeoutMs);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
closeSession(sessionId: string, timeoutMs?: number) {
|
|
203
|
+
return verbs.closeSession(this.call, sessionId, timeoutMs);
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/** The invoke seam `verbs.ts` binds to. Arrow so it survives being passed. */
|
|
207
|
+
readonly call = <T,>(method: string, params: unknown, timeoutMs: number): Promise<T> =>
|
|
208
|
+
this.request<T>(method, params, timeoutMs);
|
|
209
|
+
|
|
210
|
+
/** Answer an agent→client call this host handled out of band. */
|
|
211
|
+
respond(id: AcpId, result: unknown): void {
|
|
212
|
+
this.write({ jsonrpc: '2.0', id, result });
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
respondError(id: AcpId, message: string, code = -32603): void {
|
|
216
|
+
this.write({ jsonrpc: '2.0', id, error: { code, message } });
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* The notify seam `verbs.ts` binds to. Arrow, like `call`, and for the same
|
|
221
|
+
* measured reason: `cancel` hands this straight to `verbs.cancel`, and a
|
|
222
|
+
* method reference loses its receiver — the throw was
|
|
223
|
+
* `undefined is not an object (evaluating 'this.write')` from inside
|
|
224
|
+
* `notify`, so `session/cancel` was NEVER delivered and the Stop button
|
|
225
|
+
* answered 500 while the turn kept running.
|
|
226
|
+
*/
|
|
227
|
+
readonly notify = (method: string, params: unknown): void => {
|
|
228
|
+
this.write({ jsonrpc: '2.0', method, params });
|
|
229
|
+
};
|
|
230
|
+
|
|
231
|
+
/** Graceful then forceful shutdown of the whole process group. */
|
|
232
|
+
async dispose(gracePeriodMs = 5_000): Promise<void> {
|
|
233
|
+
if (this.exited) return;
|
|
234
|
+
const exited = this.child.exited.then(() => undefined);
|
|
235
|
+
try {
|
|
236
|
+
this.child.stdin.end();
|
|
237
|
+
} catch {
|
|
238
|
+
// Already closed.
|
|
239
|
+
}
|
|
240
|
+
const term = setTimeout(() => {
|
|
241
|
+
if (!this.exited) killProcessTree(this.child.pid, false, 'SIGTERM');
|
|
242
|
+
}, gracePeriodMs);
|
|
243
|
+
const kill = setTimeout(() => {
|
|
244
|
+
if (!this.exited) killProcessTree(this.child.pid, true, 'SIGKILL');
|
|
245
|
+
}, gracePeriodMs * 2);
|
|
246
|
+
term.unref?.();
|
|
247
|
+
kill.unref?.();
|
|
248
|
+
await exited;
|
|
249
|
+
clearTimeout(term);
|
|
250
|
+
clearTimeout(kill);
|
|
251
|
+
this.rejectAll(new Error('ACP agent disposed'));
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
/** Send a client→agent request and await its result.
|
|
255
|
+
*
|
|
256
|
+
* `timeoutMs` is the turn budget: `session/prompt` passes 0 because a coding
|
|
257
|
+
* turn legitimately runs for minutes, and every other verb takes the default
|
|
258
|
+
* cap. A cap of 0 disables the timer entirely. */
|
|
259
|
+
private request<T>(method: string, params: unknown, timeoutMs = 0): Promise<T> {
|
|
260
|
+
if (this.exited) return Promise.reject(new Error('ACP agent has exited'));
|
|
261
|
+
const budget = timeoutMs > 0
|
|
262
|
+
? timeoutMs
|
|
263
|
+
: method === 'session/prompt'
|
|
264
|
+
? 0
|
|
265
|
+
: (this.options.requestTimeoutMs ?? DEFAULT_REQUEST_TIMEOUT_MS);
|
|
266
|
+
const id = `k${this.nextId++}`;
|
|
267
|
+
const promise = this.pending.begin<T>(id, method, params, budget);
|
|
268
|
+
this.write({ jsonrpc: '2.0', id, method, params });
|
|
269
|
+
return promise;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
private rejectAll(error: Error): void {
|
|
273
|
+
this.pending.rejectAll(error);
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
private write(frame: AcpRequest | AcpNotification | AcpResponse): void {
|
|
277
|
+
if (this.exited) return;
|
|
278
|
+
const line = `${JSON.stringify(frame)}\n`;
|
|
279
|
+
this.writeQueue = this.writeQueue.then(async () => {
|
|
280
|
+
try {
|
|
281
|
+
this.child.stdin.write(line);
|
|
282
|
+
await this.child.stdin.flush();
|
|
283
|
+
} catch {
|
|
284
|
+
// A closed pipe is reported by `exited`; the writer must not throw into
|
|
285
|
+
// the queue and wedge every later frame.
|
|
286
|
+
}
|
|
287
|
+
});
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
private handleLine(line: string): void {
|
|
291
|
+
const trimmed = line.trim();
|
|
292
|
+
if (!trimmed) return;
|
|
293
|
+
let frame: unknown;
|
|
294
|
+
try {
|
|
295
|
+
frame = JSON.parse(trimmed);
|
|
296
|
+
} catch {
|
|
297
|
+
// A measured reality: `opencode acp` writes plugin-boot logs to stdout
|
|
298
|
+
// before its first frame. Skipping the line keeps the transport alive;
|
|
299
|
+
// failing here made that agent unusable.
|
|
300
|
+
return;
|
|
301
|
+
}
|
|
302
|
+
if (!frame || typeof frame !== 'object') return;
|
|
303
|
+
const record = frame as Record<string, unknown>;
|
|
304
|
+
|
|
305
|
+
if (typeof record.method === 'string') {
|
|
306
|
+
// A request has BOTH id and method; a notification has method only.
|
|
307
|
+
if (record.id !== undefined && record.id !== null) {
|
|
308
|
+
void this.handleAgentRequest(record.id as AcpId, record.method, record.params);
|
|
309
|
+
} else {
|
|
310
|
+
this.options.onNotification(record.method, (record.params ?? {}) as Record<string, unknown>);
|
|
311
|
+
}
|
|
312
|
+
return;
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
this.pending.settle(record as unknown as AcpResponse);
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
/** Answer (or refuse) a call the AGENT made on this client. */
|
|
319
|
+
private async handleAgentRequest(id: AcpId, method: string, params: unknown): Promise<void> {
|
|
320
|
+
const bag = (params ?? {}) as Record<string, unknown>;
|
|
321
|
+
try {
|
|
322
|
+
const handled = await this.options.onClientRequest?.(id, method, bag);
|
|
323
|
+
if (handled?.answered) {
|
|
324
|
+
this.respond(id, handled.result);
|
|
325
|
+
return;
|
|
326
|
+
}
|
|
327
|
+
// A deferred call is answered LATER through `respond(id, …)` — the
|
|
328
|
+
// approval dialog works this way, and sending a refusal here would answer
|
|
329
|
+
// the same request twice.
|
|
330
|
+
if (handled && 'deferred' in handled) return;
|
|
331
|
+
// A refusal is REQUIRED, not optional: an unanswered agent→client call
|
|
332
|
+
// parks the turn forever (the agent's dispatcher waits on it).
|
|
333
|
+
this.respondError(id, handled?.message ?? `Kabmo does not implement ${method}`);
|
|
334
|
+
} catch (error) {
|
|
335
|
+
this.respondError(id, error instanceof Error ? error.message : String(error));
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The ACP command vocabulary the routes send.
|
|
8
|
+
*
|
|
9
|
+
* `session/set_config_option` keys on the selector's own `id`; the CATEGORY is
|
|
10
|
+
* only how the composer classifies it. Sending the category name worked only on
|
|
11
|
+
* agents whose ids happened to match the words "model"/"thinking"/"mode".
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import { describe, expect, test } from 'bun:test';
|
|
15
|
+
import { dispatchCommand, type AcpCommandHost } from '@/server/lib/harness/acp/commands';
|
|
16
|
+
import type { AcpConfigOption } from '@/server/lib/harness/acp/protocol';
|
|
17
|
+
|
|
18
|
+
const option = (id: string, category: string, values: string[]): AcpConfigOption => ({
|
|
19
|
+
id,
|
|
20
|
+
category,
|
|
21
|
+
type: 'select',
|
|
22
|
+
currentValue: values[0],
|
|
23
|
+
options: values.map((value) => ({ value })),
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
function host(): AcpCommandHost & { writes: [string, string | boolean][]; modes: string[] } {
|
|
27
|
+
const writes: [string, string | boolean][] = [];
|
|
28
|
+
const modes: string[] = [];
|
|
29
|
+
return {
|
|
30
|
+
writes,
|
|
31
|
+
modes,
|
|
32
|
+
harness: 'claude',
|
|
33
|
+
sessionId: 's1',
|
|
34
|
+
capabilities: {
|
|
35
|
+
configModel: 1, configThinking: 1, configMode: 1, modeValues: ['default', 'plan'],
|
|
36
|
+
loadSession: false, listSessions: false, forkSession: false, deleteSession: false,
|
|
37
|
+
resumeSession: false, closeSession: false, hasUsage: false, hasPlan: false, steerMode: null,
|
|
38
|
+
},
|
|
39
|
+
configOptions: [
|
|
40
|
+
option('sel-model', 'model', ['p/m', 'p/n']),
|
|
41
|
+
option('sel-think', 'thought_level', ['low', 'high']),
|
|
42
|
+
option('sel-mode', 'mode', ['default', 'plan']),
|
|
43
|
+
],
|
|
44
|
+
agentCommands: [{ name: 'clear' }],
|
|
45
|
+
startTurn: async () => ({ agentInvoked: true }),
|
|
46
|
+
isAlive: () => true,
|
|
47
|
+
destroyAndWait: async () => {},
|
|
48
|
+
steer: async () => ({}),
|
|
49
|
+
cancelTurn: () => {},
|
|
50
|
+
setAccessMode: (mode) => {
|
|
51
|
+
modes.push(mode);
|
|
52
|
+
},
|
|
53
|
+
setConfig: async (id, value) => {
|
|
54
|
+
writes.push([id, value]);
|
|
55
|
+
return { configOptions: [] };
|
|
56
|
+
},
|
|
57
|
+
resolvePermission: () => null,
|
|
58
|
+
webState: () => ({}),
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
describe('ACP dispatchCommand', () => {
|
|
63
|
+
test('set_model / set_thinking_level / set_mode write the selector ids', async () => {
|
|
64
|
+
const stub = host();
|
|
65
|
+
await dispatchCommand(stub, { type: 'set_model', provider: 'p', modelId: 'n' });
|
|
66
|
+
await dispatchCommand(stub, { type: 'set_thinking_level', level: 'high' });
|
|
67
|
+
await dispatchCommand(stub, { type: 'set_mode', mode: 'plan' });
|
|
68
|
+
expect(stub.writes).toEqual([
|
|
69
|
+
['sel-model', 'p/n'],
|
|
70
|
+
['sel-think', 'high'],
|
|
71
|
+
['sel-mode', 'plan'],
|
|
72
|
+
]);
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
test('a model the agent does not list is refused, not written', async () => {
|
|
76
|
+
const stub = host();
|
|
77
|
+
await expect(dispatchCommand(stub, { type: 'set_model', provider: 'p', modelId: 'gone' }))
|
|
78
|
+
.rejects.toThrow('Model not offered');
|
|
79
|
+
expect(stub.writes).toEqual([]);
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
test('the access tier is adopted before the command runs', async () => {
|
|
83
|
+
const stub = host();
|
|
84
|
+
await dispatchCommand(stub, { type: 'get_state', accessMode: 'yolo' });
|
|
85
|
+
expect(stub.modes).toEqual(['yolo']);
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
test('get_commands answers the agent’s own list', async () => {
|
|
89
|
+
const stub = host();
|
|
90
|
+
expect(await dispatchCommand(stub, { type: 'get_commands' })).toEqual({ commands: [{ name: 'clear' }] });
|
|
91
|
+
});
|
|
92
|
+
});
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The command vocabulary an ACP session accepts, as ONE dispatch table.
|
|
8
|
+
*
|
|
9
|
+
* The routes already speak this vocabulary for omp (`prompt`, `steer`, `abort`,
|
|
10
|
+
* `set_model`, `get_state`, `extension_ui_response`, …), so a second table would
|
|
11
|
+
* be a place for the two transports to answer differently. What changes per
|
|
12
|
+
* harness is only what the agent can actually DO, and every branch here says so
|
|
13
|
+
* instead of pretending:
|
|
14
|
+
*
|
|
15
|
+
* - `steer`/`follow_up` refuse when the capability record says the agent has no
|
|
16
|
+
* mid-turn channel. Falling back to `session/prompt` is NOT an option: a
|
|
17
|
+
* second prompt CANCELS the running turn (measured), which would throw away
|
|
18
|
+
* the answer the user was reading.
|
|
19
|
+
* - `set_model`/`set_thinking_level`/`set_mode` throw when the agent published
|
|
20
|
+
* no such selector, naming the harness, rather than silently doing nothing.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
import { configOption, promptBlocks } from '@/server/lib/harness/acp/prompt';
|
|
24
|
+
import { acpOptionValues } from '@/server/lib/harness/acp/protocol';
|
|
25
|
+
import { notePromptTitle } from '@/server/lib/harness/session-title.server';
|
|
26
|
+
import { isApprovalMode, type ApprovalMode } from '@/shared/lib/omp/config/access-mode';
|
|
27
|
+
import type { AcpConfigOption } from '@/server/lib/harness/acp/protocol';
|
|
28
|
+
import type { HarnessCapabilities } from '@/server/lib/harness/capabilities';
|
|
29
|
+
import type { HarnessId } from '@/shared/lib/harness/catalog';
|
|
30
|
+
|
|
31
|
+
/** The slice of `AcpSession` this table drives. Narrow on purpose: the dispatch
|
|
32
|
+
* rules are testable against a stub, with no process and no protocol. */
|
|
33
|
+
export interface AcpCommandHost {
|
|
34
|
+
readonly harness: HarnessId;
|
|
35
|
+
readonly sessionId: string;
|
|
36
|
+
readonly capabilities: HarnessCapabilities;
|
|
37
|
+
readonly configOptions: AcpConfigOption[];
|
|
38
|
+
/** Dispatch one turn. Returns the ACK (`{agentInvoked:true}`), never the
|
|
39
|
+
* turn: the route's answer means "accepted", and the turn's end arrives as
|
|
40
|
+
* the session's `agent_end` frame. */
|
|
41
|
+
startTurn(message: string, images: unknown): Promise<unknown> | unknown;
|
|
42
|
+
isAlive(): boolean;
|
|
43
|
+
destroyAndWait(): Promise<void>;
|
|
44
|
+
steer(blocks: unknown[], queue: 'steering' | 'followUp'): Promise<unknown>;
|
|
45
|
+
cancelTurn(): void;
|
|
46
|
+
/** Adopt the composer's approval tier. ACP decides approvals in-process. */
|
|
47
|
+
setAccessMode(mode: ApprovalMode): void;
|
|
48
|
+
setConfig(configId: string, value: string | boolean): Promise<unknown>;
|
|
49
|
+
resolvePermission(dialogId: string, confirmed: boolean): unknown;
|
|
50
|
+
webState(): Record<string, unknown>;
|
|
51
|
+
/** The agent's own slash-command list, when it published one. */
|
|
52
|
+
agentCommands: { name: string; description?: string; inputHint?: string }[];
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** The command vocabulary the routes already use. */
|
|
56
|
+
export async function dispatchCommand(host: AcpCommandHost, command: Record<string, unknown>): Promise<unknown> {
|
|
57
|
+
if (!host.isAlive()) throw new Error('ACP session is not running');
|
|
58
|
+
const type = typeof command.type === 'string' ? command.type : '';
|
|
59
|
+
|
|
60
|
+
// The composer sends its access pick with each request (the warmup and the
|
|
61
|
+
// prompt both carry it). ACP has no spawn flag for it, so the tier is adopted
|
|
62
|
+
// here and used when `session/request_permission` arrives.
|
|
63
|
+
if (isApprovalMode(command.accessMode)) host.setAccessMode(command.accessMode);
|
|
64
|
+
|
|
65
|
+
switch (type) {
|
|
66
|
+
case 'prompt': {
|
|
67
|
+
const message = String(command.message ?? '');
|
|
68
|
+
// Name the chat here, and only here: this is the ONE place every ACP
|
|
69
|
+
// prompt goes through (a new chat's first send, a live send, a queue
|
|
70
|
+
// delivery), and the writer fills an EMPTY title only — so a steering
|
|
71
|
+
// message or a follow-up cannot rename the chat to its own text.
|
|
72
|
+
// Kabmo's goal kickoff/continuation is synthetic: naming the chat after
|
|
73
|
+
// that boilerplate is worse than leaving the objective's own title.
|
|
74
|
+
if (command.synthetic !== true) await notePromptTitle(host.sessionId, message);
|
|
75
|
+
return host.startTurn(message, command.images);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
case 'set_access_mode': {
|
|
79
|
+
const mode = command.mode;
|
|
80
|
+
if (!isApprovalMode(mode)) throw new Error(`Unknown access mode: ${String(mode)}`);
|
|
81
|
+
host.setAccessMode(mode);
|
|
82
|
+
return { mode };
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
case 'steer': {
|
|
86
|
+
const blocks = promptBlocks(String(command.message ?? ''), command.images);
|
|
87
|
+
if (host.capabilities.steerMode !== 'steer') {
|
|
88
|
+
throw new Error(`This harness has no mid-turn steering (${host.harness})`);
|
|
89
|
+
}
|
|
90
|
+
return host.steer(blocks, 'steering');
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
case 'follow_up': {
|
|
94
|
+
const blocks = promptBlocks(String(command.message ?? ''), command.images);
|
|
95
|
+
if (!host.capabilities.steerMode) throw new Error(`This harness cannot queue a follow-up (${host.harness})`);
|
|
96
|
+
return host.steer(blocks, 'followUp');
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
case 'abort':
|
|
100
|
+
// `cancelTurn` stops the agent AND closes the turn locally: the cancel
|
|
101
|
+
// is a notification, so an agent that never answers it would otherwise
|
|
102
|
+
// leave `isStreaming` up and refuse the next prompt as "already
|
|
103
|
+
// processing" (reported: Stop cleared the spinner but the next send was
|
|
104
|
+
// rejected). The terminal `agent_end` comes from that close, not from a
|
|
105
|
+
// frame emitted here — two terminal frames finalized the assistant
|
|
106
|
+
// message twice.
|
|
107
|
+
host.cancelTurn();
|
|
108
|
+
return null;
|
|
109
|
+
|
|
110
|
+
case 'force_reset':
|
|
111
|
+
await host.destroyAndWait();
|
|
112
|
+
return null;
|
|
113
|
+
|
|
114
|
+
case 'set_model': {
|
|
115
|
+
const provider = String(command.provider ?? '');
|
|
116
|
+
const modelId = String(command.modelId ?? '');
|
|
117
|
+
const model = configOption(host.configOptions, 'model');
|
|
118
|
+
if (!model) throw new Error(`This harness exposes no model selector (${host.harness})`);
|
|
119
|
+
const wanted = `${provider}/${modelId}`;
|
|
120
|
+
const values = acpOptionValues(model);
|
|
121
|
+
const match = values.find((value) => value === wanted) ?? values.find((value) => value === modelId);
|
|
122
|
+
if (!match) throw new Error(`Model not offered by this harness: ${wanted}`);
|
|
123
|
+
// The agent's own selector ID, never the category name: ACP lets an
|
|
124
|
+
// agent publish `{id:"model", category:"model"}` or any other pair, and
|
|
125
|
+
// `session/set_config_option` keys on the ID.
|
|
126
|
+
const result = await host.setConfig(model.id, match);
|
|
127
|
+
return { id: modelId, provider, data: result };
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
case 'set_thinking_level': {
|
|
131
|
+
const level = String(command.level ?? '');
|
|
132
|
+
const thinking = configOption(host.configOptions, 'thought_level');
|
|
133
|
+
if (!thinking) throw new Error(`This harness exposes no thinking selector (${host.harness})`);
|
|
134
|
+
return host.setConfig(thinking.id, level);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
case 'set_mode': {
|
|
138
|
+
const mode = String(command.mode ?? '');
|
|
139
|
+
const selector = configOption(host.configOptions, 'mode');
|
|
140
|
+
if (!selector) throw new Error(`This harness exposes no mode selector (${host.harness})`);
|
|
141
|
+
return host.setConfig(selector.id, mode);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
case 'get_state':
|
|
145
|
+
return host.webState();
|
|
146
|
+
|
|
147
|
+
case 'get_commands':
|
|
148
|
+
// The agent's own list, not an empty one: the composer's `/` pool asks
|
|
149
|
+
// the live session for it, and a transport that answered `[]` forced
|
|
150
|
+
// every ACP chat onto omp's utility catalog instead.
|
|
151
|
+
return { commands: host.agentCommands };
|
|
152
|
+
|
|
153
|
+
case 'extension_ui_response': {
|
|
154
|
+
// The approval dialog's answer, in the shape the shared gate sends. The
|
|
155
|
+
// session owns the picking (which option means "allow"), because it is
|
|
156
|
+
// also the side that rendered the options.
|
|
157
|
+
const id = typeof command.id === 'string' ? command.id : '';
|
|
158
|
+
const confirmed = command.confirmed === true || command.value === 'allow';
|
|
159
|
+
return host.resolvePermission(id, confirmed);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
default:
|
|
163
|
+
throw new Error(`Command not supported by the ACP transport: ${type}`);
|
|
164
|
+
}
|
|
165
|
+
}
|