@kabmo-labs/kabmo 0.27.0 → 0.28.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/dist/client/index.html +1 -1
- package/dist/client/index.js +495 -467
- package/dist/client/static/js/index-81f7berm.css +1 -0
- package/dist/client/static/js/{index-e3qh2yps.js → index-xzvyrxya.js} +795 -795
- package/marketplace/plugins/command-runner/package.json +3 -17
- package/marketplace/plugins/command-runner/settings-schema.json +14 -0
- package/marketplace/plugins/git-forge/README.md +17 -7
- package/marketplace/plugins/git-forge/package.json +4 -30
- package/marketplace/plugins/git-forge/panel.css +16 -0
- package/marketplace/plugins/git-forge/settings-schema.json +27 -0
- package/marketplace/plugins/git-forge/src/panel/Badge.tsx +35 -22
- package/marketplace/plugins/git-forge/src/panel/Change.tsx +20 -24
- package/marketplace/plugins/git-forge/src/panel/CiBadge.tsx +16 -7
- package/marketplace/plugins/git-forge/src/panel/Credential.tsx +31 -26
- package/marketplace/plugins/git-forge/src/panel/Glyph.tsx +18 -2
- package/marketplace/plugins/git-forge/src/panel/Header.tsx +160 -96
- package/marketplace/plugins/git-forge/src/panel/ItemView.tsx +60 -44
- package/marketplace/plugins/git-forge/src/panel/List.tsx +150 -22
- package/marketplace/plugins/git-forge/src/panel/Row.tsx +11 -5
- package/marketplace/plugins/git-forge/src/panel/Sidebar.tsx +17 -15
- package/marketplace/plugins/git-forge/src/panel/Write.tsx +84 -61
- package/marketplace/plugins/git-forge/src/panel/format.test.ts +99 -0
- package/marketplace/plugins/git-forge/src/panel/format.ts +59 -16
- package/marketplace/plugins/git-forge/src/panel/index.test.tsx +109 -5
- package/marketplace/plugins/git-forge/src/panel/index.tsx +37 -4
- package/marketplace/plugins/git-forge/src/panel/use-forge.ts +17 -0
- package/marketplace/plugins/git-forge/src/panel/write.test.tsx +31 -0
- package/marketplace/plugins/session-info/package.json +2 -10
- package/marketplace/plugins/session-info/settings-schema.json +8 -0
- package/marketplace/plugins/stats/README.md +17 -5
- package/marketplace/plugins/stats/package.json +3 -23
- package/marketplace/plugins/stats/settings-schema.json +20 -0
- package/marketplace/plugins/stats/src/app.tsx +1 -1
- package/marketplace/plugins/stats/src/groups.test.ts +46 -1
- package/marketplace/plugins/stats/src/groups.ts +22 -11
- package/marketplace/plugins/stats/src/harness-leases.test.ts +84 -0
- package/marketplace/plugins/stats/src/harness-leases.ts +132 -0
- package/marketplace/plugins/stats/src/labels.test.ts +54 -1
- package/marketplace/plugins/stats/src/labels.ts +33 -7
- package/marketplace/plugins/stats/src/sampler.test.ts +61 -0
- package/marketplace/plugins/stats/src/sampler.ts +39 -5
- package/marketplace/plugins/stats/src/snapshot.ts +6 -0
- package/package.json +2 -2
- package/src/client/components/common/harness-glyph/index.tsx +18 -1
- package/src/client/components/common/session-actions-menu/index.test.tsx +106 -0
- package/src/client/components/common/session-actions-menu/index.tsx +43 -1
- package/src/client/components/common/session-row/TrailingSlot.tsx +9 -4
- package/src/client/components/common/session-row/index.tsx +4 -0
- package/src/client/components/common/session-row/session-row.test.tsx +6 -0
- package/src/client/components/layout/session-sidebar/CategoryItem.tsx +2 -1
- package/src/client/components/layout/session-sidebar/SessionItem.tsx +9 -1
- package/src/client/components/layout/session-sidebar/modern/WorkspaceSection.tsx +2 -1
- package/src/client/components/layout/session-sidebar/scheduler-modal/ModelFields.tsx +202 -0
- package/src/client/components/layout/session-sidebar/scheduler-modal/TaskForm.tsx +80 -19
- package/src/client/components/layout/session-sidebar/scheduler-modal/TaskList.tsx +23 -3
- package/src/client/components/layout/session-sidebar/scheduler-modal/index.tsx +3 -0
- package/src/client/components/mobile/mobile-right-sidebar/EditorSurface.tsx +156 -0
- package/src/client/components/mobile/mobile-right-sidebar/FullEditor.tsx +41 -86
- package/src/client/components/mobile/mobile-session-sidebar/Item.tsx +2 -1
- package/src/client/components/mobile/mobile-session-sidebar/SessionRow.test.ts +6 -0
- package/src/client/components/mobile/mobile-session-sidebar/SessionRow.tsx +9 -1
- package/src/client/components/settings/Modal.tsx +6 -2
- package/src/client/components/settings/Sidebar.tsx +30 -3
- package/src/client/components/settings/categories/HarnessSettings.tsx +11 -7
- package/src/client/components/settings/categories/NotificationSettings.test.tsx +40 -15
- package/src/client/components/settings/categories/NotificationSettings.tsx +142 -64
- package/src/client/components/settings/categories/PanelPluginSettings.tsx +1 -1
- package/src/client/components/settings/categories/harness-settings/CustomHarnessForm.tsx +186 -0
- package/src/client/components/settings/categories/panel-plugins/InstalledList.tsx +11 -0
- package/src/client/components/settings/categories/panel-plugins/PluginCard.test.tsx +1 -0
- package/src/client/components/settings/categories/panel-plugins/PluginCard.tsx +15 -1
- package/src/client/components/settings/categories/panel-plugins/SettingsModal.test.tsx +165 -0
- package/src/client/components/settings/categories/panel-plugins/SettingsModal.tsx +260 -0
- package/src/client/components/workspace/chat-timeline/AiMessageFooter.fork.test.ts +24 -0
- package/src/client/components/workspace/chat-timeline/AiMessageFooter.tsx +8 -4
- package/src/client/components/workspace/chat-timeline/ComposerDock.tsx +34 -0
- package/src/client/components/workspace/chat-timeline/EmptyWorkspacePrompt.tsx +3 -2
- package/src/client/components/workspace/chat-timeline/MessageItem.fork.test.ts +80 -0
- package/src/client/components/workspace/chat-timeline/MessageItem.tsx +9 -3
- package/src/client/components/workspace/chat-timeline/MessageList.tsx +3 -1
- package/src/client/components/workspace/chat-timeline/RunFooter.tsx +2 -1
- package/src/client/components/workspace/chat-timeline/TimelineBody.tsx +2 -1
- package/src/client/components/workspace/chat-timeline/chat-input/ComposerRows.tsx +8 -0
- package/src/client/components/workspace/chat-timeline/chat-input/SessionModeDropdown.test.tsx +9 -0
- package/src/client/components/workspace/chat-timeline/chat-input/SessionModeDropdown.tsx +4 -1
- package/src/client/components/workspace/chat-timeline/chat-input/Toolbar.tsx +24 -0
- package/src/client/components/workspace/chat-timeline/chat-input/WaitingDependencyPicker.tsx +13 -20
- package/src/client/components/workspace/chat-timeline/chat-input/index.tsx +2 -0
- package/src/client/components/workspace/chat-timeline/chat-input/props.ts +5 -5
- package/src/client/components/workspace/chat-timeline/index.tsx +11 -5
- package/src/client/components/workspace/chat-timeline/target-picker/DraftTargetRow.tsx +1 -9
- package/src/client/components/workspace/chat-timeline/target-picker/ParentSessionPicker.test.tsx +101 -0
- package/src/client/components/workspace/chat-timeline/target-picker/ParentSessionPicker.tsx +2 -2
- package/src/client/components/workspace/editor/FilePane.tsx +9 -4
- package/src/client/components/workspace/editor/Notices.tsx +2 -2
- package/src/client/components/workspace/editor/Pane.tsx +2 -2
- package/src/client/components/workspace/editor/Toolbar.tsx +16 -10
- package/src/client/components/workspace/editor/index.tsx +6 -10
- package/src/client/components/workspace/editor/toolbar-clusters.test.ts +4 -3
- package/src/client/components/workspace/editor/toolbar-clusters.tsx +23 -14
- package/src/client/components/workspace/terminal-panel/RealtimeTerminalView.tsx +9 -1
- package/src/client/components/workspace/terminal-panel/focus.test.ts +70 -0
- package/src/client/components/workspace/terminal-panel/focus.ts +46 -0
- package/src/client/components/workspace/terminal-panel/index.tsx +14 -1
- package/src/client/components/workspace/terminal-panel/mount.ts +17 -9
- package/src/client/components/workspace/terminal-panel/scroll-hold.test.ts +158 -0
- package/src/client/components/workspace/terminal-panel/scroll-hold.ts +136 -0
- package/src/client/hooks/chat/composer/use-draft.ts +45 -1
- package/src/client/hooks/chat/omp/pending-sessions.waiting.test.ts +11 -10
- package/src/client/hooks/chat/omp/pending-waiting.ts +15 -7
- package/src/client/hooks/chat/omp/prompt-send.test.ts +11 -0
- package/src/client/hooks/chat/omp/prompt-send.ts +3 -0
- package/src/client/hooks/chat/timeline/actions.ts +4 -4
- package/src/client/hooks/chat/timeline/composer-modes.ts +13 -2
- package/src/client/hooks/chat/timeline/fork-open.ts +52 -0
- package/src/client/hooks/chat/timeline/index.ts +5 -2
- package/src/client/hooks/chat/timeline/mode-availability.ts +7 -0
- package/src/client/hooks/chat/timeline/modes-contract.ts +6 -0
- package/src/client/hooks/chat/timeline/modes-hydrate.ts +93 -0
- package/src/client/hooks/chat/timeline/modes.ts +32 -52
- package/src/client/hooks/chat/timeline/new-chat-open.ts +7 -6
- package/src/client/hooks/chat/timeline/new-chat.ts +10 -1
- package/src/client/hooks/chat/timeline/pending-dispatch.ts +4 -0
- package/src/client/hooks/chat/timeline/pending-session-mode.test.ts +136 -0
- package/src/client/hooks/chat/timeline/pending-session-mode.ts +69 -0
- package/src/client/hooks/chat/timeline/pending-warmup.test.ts +147 -0
- package/src/client/hooks/chat/timeline/pending-warmup.ts +62 -0
- package/src/client/hooks/chat/timeline/run-identity.test.ts +12 -0
- package/src/client/hooks/chat/timeline/run-identity.ts +4 -1
- package/src/client/hooks/chat/timeline/send-props.ts +2 -0
- package/src/client/hooks/chat/timeline/send-steer.test.ts +1 -0
- package/src/client/hooks/chat/timeline/send.test-util.ts +1 -0
- package/src/client/hooks/chat/timeline/send.test.ts +1 -0
- package/src/client/hooks/chat/timeline/session-harness.ts +4 -0
- package/src/client/hooks/chat/timeline/use-fork-session.ts +9 -22
- package/src/client/hooks/chat/waiting/cancel.ts +13 -6
- package/src/client/hooks/chat/waiting/choice.ts +13 -16
- package/src/client/hooks/chat/waiting/composer-wait.ts +70 -0
- package/src/client/hooks/chat/waiting/dispatch.ts +48 -28
- package/src/client/hooks/chat/waiting/held.ts +37 -13
- package/src/client/hooks/chat/waiting/hold.test.ts +22 -0
- package/src/client/hooks/chat/waiting/hold.ts +20 -11
- package/src/client/hooks/chat/waiting/restore.test.ts +69 -0
- package/src/client/hooks/chat/waiting/restore.ts +34 -0
- package/src/client/hooks/chat/waiting/store.ts +9 -3
- package/src/client/hooks/editor/file-editor-types.ts +21 -12
- package/src/client/hooks/editor/save-file.test.ts +1 -1
- package/src/client/hooks/editor/save-file.ts +35 -8
- package/src/client/hooks/editor/target-key.ts +17 -0
- package/src/client/hooks/editor/use-disk-digest.test.ts +82 -0
- package/src/client/hooks/editor/use-disk-digest.ts +164 -0
- package/src/client/hooks/editor/use-disk-sync.ts +212 -0
- package/src/client/hooks/editor/use-file-cache.ts +113 -0
- package/src/client/hooks/editor/use-file-editor.test.ts +90 -0
- package/src/client/hooks/editor/use-file-editor.ts +90 -52
- package/src/client/hooks/editor/use-file-read.ts +24 -10
- package/src/client/hooks/editor/use-file-writes.ts +4 -4
- package/src/client/hooks/models/harness-catalog.ts +15 -0
- package/src/client/hooks/ui/notifications.ts +17 -8
- package/src/client/hooks/workspace/panel-registry.ts +1 -1
- package/src/client/hooks/workspace/scheduled-tasks.ts +26 -11
- package/src/client/lib/notifications/os.test.ts +1 -30
- package/src/client/lib/notifications/os.ts +0 -15
- package/src/client/lib/notifications/platform.test.ts +68 -0
- package/src/client/lib/notifications/platform.ts +36 -0
- package/src/server/index.ts +7 -0
- package/src/server/lib/harness/acp/client.ts +81 -87
- package/src/server/lib/harness/acp/prewarm.server.ts +237 -0
- package/src/server/lib/harness/acp/prewarm.test.ts +171 -0
- package/src/server/lib/harness/acp/prompt.test.ts +70 -1
- package/src/server/lib/harness/acp/prompt.ts +32 -1
- package/src/server/lib/harness/acp/protocol.ts +23 -0
- package/src/server/lib/harness/acp/session-handshake.test.ts +26 -0
- package/src/server/lib/harness/acp/session-handshake.ts +22 -20
- package/src/server/lib/harness/acp/session-options.ts +16 -0
- package/src/server/lib/harness/acp/session-process.ts +43 -0
- package/src/server/lib/harness/acp/session.ts +11 -12
- package/src/server/lib/harness/acp/stdio.ts +129 -0
- package/src/server/lib/harness/acp/verbs.test.ts +97 -0
- package/src/server/lib/harness/acp/verbs.ts +16 -6
- package/src/server/lib/harness/auto-probe.server.ts +4 -3
- package/src/server/lib/harness/capabilities.ts +8 -0
- package/src/server/lib/harness/config.server.ts +3 -2
- package/src/server/lib/harness/custom.server.ts +209 -0
- package/src/server/lib/harness/launch.ts +6 -1
- package/src/server/lib/harness/register.server.ts +8 -1
- package/src/server/lib/harness/schema.server.ts +21 -0
- package/src/server/lib/harness/session-lease.server.test.ts +99 -0
- package/src/server/lib/harness/session-lease.server.ts +193 -0
- package/src/server/lib/harness/session-store.server.test.ts +8 -8
- package/src/server/lib/harness/session-store.server.ts +25 -4
- package/src/server/lib/harness/session-title.server.ts +12 -2
- package/src/server/lib/harness/spawn.server.ts +123 -20
- package/src/server/lib/harness/update-queue.server.ts +3 -3
- package/src/server/lib/lifecycle/after-listen.ts +12 -1
- package/src/server/lib/lifecycle/paths.ts +19 -1
- package/src/server/lib/mcp/registry.server.ts +155 -0
- package/src/server/lib/mcp/registry.test.ts +169 -0
- package/src/server/lib/mcp/store.server.ts +38 -0
- package/src/server/lib/omp/rpc/frame-fold-contract.ts +59 -0
- package/src/server/lib/omp/rpc/frame-fold-frames.test.ts +64 -1
- package/src/server/lib/omp/rpc/frame-fold-host.test-util.ts +2 -1
- package/src/server/lib/omp/rpc/frame-fold.test.ts +2 -1
- package/src/server/lib/omp/rpc/frame-fold.ts +6 -45
- package/src/server/lib/omp/rpc/prewarm-pool.ts +19 -5
- package/src/server/lib/omp/rpc/run-model.test.ts +116 -0
- package/src/server/lib/omp/rpc/run-model.ts +4 -2
- package/src/server/lib/omp/session/sidebar-data.harness.test.ts +6 -3
- package/src/server/lib/omp/session/standby.server.ts +13 -2
- package/src/server/lib/panels/manifest.test.ts +47 -1
- package/src/server/lib/panels/manifest.ts +19 -0
- package/src/server/lib/panels/registry.server.ts +19 -2
- package/src/server/lib/panels/scan.server.ts +26 -2
- package/src/server/lib/panels/settings-schema.server.ts +72 -0
- package/src/server/lib/plugins/background.server.ts +21 -3
- package/src/server/lib/plugins/background.test.ts +13 -0
- package/src/server/lib/plugins/loader.server.ts +35 -51
- package/src/server/lib/plugins/mcp.server.ts +100 -0
- package/src/server/lib/plugins/mcp.test.ts +75 -0
- package/src/server/lib/plugins/schedule-runner.server.ts +153 -0
- package/src/server/lib/plugins/schedule-runner.test.ts +186 -0
- package/src/server/lib/plugins/schedule-store.server.ts +107 -0
- package/src/server/lib/plugins/schema.server.ts +8 -0
- package/src/server/lib/plugins/settings.server.ts +56 -19
- package/src/server/lib/plugins/shutdown.server.ts +58 -0
- package/src/server/lib/plugins/shutdown.test.ts +28 -3
- package/src/server/lib/realtime/topics/global.server.ts +5 -1
- package/src/server/lib/schedule/rows.server.ts +9 -0
- package/src/server/lib/schedule/runtime.server.test.ts +91 -0
- package/src/server/lib/schedule/runtime.server.ts +101 -23
- package/src/server/lib/schedule/schema.server.ts +15 -0
- package/src/server/lib/schedule/store.server.test.ts +34 -0
- package/src/server/lib/schedule/store.server.ts +33 -9
- package/src/server/lib/sessions/fork.server.test.ts +47 -0
- package/src/server/lib/sessions/fork.server.ts +17 -1
- package/src/server/lib/sessions/spawn.server.ts +2 -2
- package/src/server/lib/waiting/runtime.server.test.ts +48 -0
- package/src/server/lib/waiting/runtime.server.ts +22 -0
- package/src/server/lib/waiting/schema.server.ts +8 -0
- package/src/server/lib/waiting/store.server.test.ts +14 -0
- package/src/server/lib/waiting/store.server.ts +6 -2
- package/src/server/routes/agent/command-resume.test.ts +9 -4
- package/src/server/routes/agent/new-mode.test.ts +40 -0
- package/src/server/routes/agent/new.ts +31 -10
- package/src/server/routes/agent/prewarm.ts +48 -7
- package/src/server/routes/fs/action.ts +9 -1
- package/src/server/routes/fs/digest.test.ts +100 -0
- package/src/server/routes/fs/digest.ts +106 -0
- package/src/server/routes/fs/index.ts +2 -0
- package/src/server/routes/fs/read.ts +6 -1
- package/src/server/routes/harness/custom.test.ts +131 -0
- package/src/server/routes/harness/import-action.ts +2 -2
- package/src/server/routes/harness/root.ts +41 -8
- package/src/server/routes/harness/update.ts +2 -2
- package/src/server/routes/panels/bindings.ts +2 -0
- package/src/server/routes/panels/settings.test.ts +165 -0
- package/src/server/routes/panels/settings.ts +106 -0
- package/src/server/routes/schedule/body.ts +14 -0
- package/src/server/routes/schedule/index.ts +28 -4
- package/src/server/routes/settings/mcp.ts +9 -26
- package/src/server/routes/waiting/index.ts +21 -2
- package/src/server/routes/waiting/routes.test.ts +21 -0
- package/src/shared/lib/chat/composer/delegation.ts +3 -3
- package/src/shared/lib/chat/timeline/fork-anchor.test.ts +97 -0
- package/src/shared/lib/chat/timeline/fork-anchor.ts +47 -0
- package/src/shared/lib/fs/content-hash.ts +29 -0
- package/src/shared/lib/harness/catalog.ts +48 -6
- package/src/shared/lib/harness/fork.ts +60 -0
- package/src/shared/lib/harness/mcp-facts.test.ts +30 -0
- package/src/shared/lib/harness/mcp-facts.ts +65 -0
- package/src/shared/lib/harness/menu.test.ts +16 -1
- package/src/shared/lib/harness/menu.ts +2 -2
- package/src/shared/lib/harness/rewind.ts +6 -6
- package/src/shared/lib/harness/session-modes.ts +31 -0
- package/src/shared/lib/harness/transcript.test.ts +29 -0
- package/src/shared/lib/harness/transcript.ts +19 -0
- package/src/shared/lib/notifications/settings.test.ts +21 -0
- package/src/shared/lib/notifications/settings.ts +24 -0
- package/src/shared/lib/omp/session/prewarm.test.ts +28 -4
- package/src/shared/lib/omp/session/prewarm.ts +25 -6
- package/src/shared/lib/omp/session/stream-state.server.test.ts +25 -0
- package/src/shared/lib/omp/session/stream-state.server.ts +8 -4
- package/src/shared/lib/panels/capabilities.test.ts +1 -1
- package/src/shared/lib/panels/capabilities.ts +3 -0
- package/src/shared/lib/plugins/settings.ts +22 -0
- package/src/shared/lib/schedule/parse.test.ts +48 -0
- package/src/shared/lib/schedule/parse.ts +69 -45
- package/src/shared/lib/schedule/timezone.ts +128 -0
- package/src/shared/lib/settings/defaults.ts +2 -0
- package/src/shared/lib/workspace/refresh-cadence.test.ts +25 -1
- package/src/shared/lib/workspace/relative-time.ts +16 -0
- package/src/shared/types/harness.ts +7 -0
- package/src/shared/types/omp/agent.ts +6 -0
- package/src/shared/types/panels-registry.ts +3 -3
- package/src/shared/types/panels.ts +4 -2
- package/src/shared/types/schedule.ts +13 -0
- package/src/shared/types/settings/state.ts +12 -1
- package/src/shared/types/waiting.ts +9 -0
- package/src/test-support/file-editor.test-util.ts +70 -5
- package/dist/client/static/js/index-32rpkj6b.css +0 -1
- package/src/client/hooks/editor/use-external-change-notice.ts +0 -71
- package/src/client/hooks/editor/use-external-change.test.ts +0 -88
- package/src/client/hooks/editor/use-external-change.ts +0 -146
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The MCP servers a session should receive, from every source that can declare
|
|
8
|
+
* one.
|
|
9
|
+
*
|
|
10
|
+
* One list, because the alternative is what shipped before: the settings pane
|
|
11
|
+
* read omp's `mcp.json`, the ACP spawn passed `mcpServers: []`, and a plugin had
|
|
12
|
+
* no way to contribute at all. A server the user configured therefore reached
|
|
13
|
+
* exactly one harness — the one that happened to read the same file.
|
|
14
|
+
*
|
|
15
|
+
* Precedence is by NAME, first wins: native user config, then the project's
|
|
16
|
+
* config, then the app-local rows, then plugin contributions. That is the same
|
|
17
|
+
* rule the settings pane merges with, so the list a user sees and the list a
|
|
18
|
+
* session receives cannot disagree about which entry is live.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
import { getDb } from '@/server/db.server';
|
|
22
|
+
import { readProjectMcpConfig, readUserMcpConfig, type McpServer } from '@/server/lib/omp/config/mcp';
|
|
23
|
+
import { readCustomMcpServers } from '@/server/lib/mcp/store.server';
|
|
24
|
+
import { pluginMcpServers } from '@/server/lib/plugins/mcp.server';
|
|
25
|
+
import type { McpServerItem } from '@/shared/types';
|
|
26
|
+
import type { AcpMcpServer } from '@/server/lib/harness/acp/protocol';
|
|
27
|
+
|
|
28
|
+
/** One server, in the transport-neutral shape both deliveries read. */
|
|
29
|
+
export interface McpServerDefinition {
|
|
30
|
+
name: string;
|
|
31
|
+
transport: 'stdio' | 'http';
|
|
32
|
+
command?: string;
|
|
33
|
+
args?: string[];
|
|
34
|
+
env?: Record<string, string>;
|
|
35
|
+
url?: string;
|
|
36
|
+
headers?: Record<string, string>;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function stringRecord(value: unknown): Record<string, string> | undefined {
|
|
40
|
+
if (!value || typeof value !== 'object' || Array.isArray(value)) return undefined;
|
|
41
|
+
const entries = Object.entries(value).filter((entry): entry is [string, string] => typeof entry[1] === 'string');
|
|
42
|
+
return entries.length > 0 ? Object.fromEntries(entries) : undefined;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** A native `mcp.json` entry, or null when it names neither a command nor a URL. */
|
|
46
|
+
export function definitionFromNative(name: string, config: McpServer): McpServerDefinition | null {
|
|
47
|
+
if (typeof config.url === 'string' && config.url.trim()) {
|
|
48
|
+
const headers = stringRecord(config.headers);
|
|
49
|
+
return { name, transport: 'http', url: config.url.trim(), ...(headers ? { headers } : {}) };
|
|
50
|
+
}
|
|
51
|
+
if (typeof config.command === 'string' && config.command.trim()) {
|
|
52
|
+
const args = Array.isArray(config.args) ? config.args.filter((arg): arg is string => typeof arg === 'string') : [];
|
|
53
|
+
const env = stringRecord(config.env);
|
|
54
|
+
return {
|
|
55
|
+
name,
|
|
56
|
+
transport: 'stdio',
|
|
57
|
+
command: config.command.trim(),
|
|
58
|
+
...(args.length > 0 ? { args } : {}),
|
|
59
|
+
...(env ? { env } : {}),
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** An app-local settings row, or null when it is disabled or malformed. */
|
|
66
|
+
export function definitionFromItem(item: McpServerItem): McpServerDefinition | null {
|
|
67
|
+
if (!item.enabled) return null;
|
|
68
|
+
if (item.reachType === 'link' || item.linkUrl) {
|
|
69
|
+
const url = (item.linkUrl ?? item.commandArgs[0] ?? '').trim();
|
|
70
|
+
return url ? { name: item.name, transport: 'http', url } : null;
|
|
71
|
+
}
|
|
72
|
+
const [command, ...args] = item.commandArgs;
|
|
73
|
+
if (!command?.trim()) return null;
|
|
74
|
+
const env: Record<string, string> = {};
|
|
75
|
+
for (const entry of item.envVars ?? []) {
|
|
76
|
+
// A masked value is a display placeholder, never a credential: injecting it
|
|
77
|
+
// would hand the agent the literal dots.
|
|
78
|
+
if (entry?.key && entry.value && entry.value !== '••••••••') env[entry.key] = entry.value;
|
|
79
|
+
}
|
|
80
|
+
return {
|
|
81
|
+
name: item.name,
|
|
82
|
+
transport: 'stdio',
|
|
83
|
+
command: command.trim(),
|
|
84
|
+
...(args.length > 0 ? { args } : {}),
|
|
85
|
+
...(Object.keys(env).length > 0 ? { env } : {}),
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Every enabled server a session in `cwd` should receive.
|
|
91
|
+
*
|
|
92
|
+
* A read that fails is reported and skipped: one unreadable config must not
|
|
93
|
+
* stop a chat from starting, and the settings pane is where the user can see
|
|
94
|
+
* the reason.
|
|
95
|
+
*/
|
|
96
|
+
export async function mcpServersFor(cwd: string): Promise<McpServerDefinition[]> {
|
|
97
|
+
const definitions: McpServerDefinition[] = [];
|
|
98
|
+
const seen = new Set<string>();
|
|
99
|
+
const add = (definition: McpServerDefinition | null) => {
|
|
100
|
+
if (!definition) return;
|
|
101
|
+
const key = definition.name.toLowerCase();
|
|
102
|
+
if (seen.has(key)) return;
|
|
103
|
+
seen.add(key);
|
|
104
|
+
definitions.push(definition);
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
const user = await readUserMcpConfig();
|
|
108
|
+
if (user.error) console.error(`[mcp] user config skipped: ${user.error}`);
|
|
109
|
+
for (const entry of user.servers) {
|
|
110
|
+
if (user.disabledServers.includes(entry.name)) continue;
|
|
111
|
+
add(definitionFromNative(entry.name, entry.config));
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
if (cwd) {
|
|
115
|
+
const project = await readProjectMcpConfig(cwd);
|
|
116
|
+
if (project.error) console.error(`[mcp] project config skipped: ${project.error}`);
|
|
117
|
+
for (const entry of project.servers) {
|
|
118
|
+
if (project.disabledServers.includes(entry.name)) continue;
|
|
119
|
+
add(definitionFromNative(entry.name, entry.config));
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
const custom = await readCustomMcpServers(await getDb());
|
|
124
|
+
for (const item of custom) {
|
|
125
|
+
if (item.scope === 'this-project' && item.projectPath !== cwd) continue;
|
|
126
|
+
add(definitionFromItem(item));
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
for (const entry of pluginMcpServers()) {
|
|
130
|
+
// `id` is the plugin's own key, not part of the transport-neutral shape.
|
|
131
|
+
const { id: _id, name: _name, ...server } = entry.server;
|
|
132
|
+
add({ ...server, name: entry.name });
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
return definitions;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/** The ACP wire shape: stdio is the baseline, `http` is the typed variant. */
|
|
139
|
+
export function toAcpMcpServers(definitions: readonly McpServerDefinition[]): AcpMcpServer[] {
|
|
140
|
+
return definitions.map((definition) =>
|
|
141
|
+
definition.transport === 'http'
|
|
142
|
+
? {
|
|
143
|
+
type: 'http' as const,
|
|
144
|
+
name: definition.name,
|
|
145
|
+
url: definition.url ?? '',
|
|
146
|
+
headers: Object.entries(definition.headers ?? {}).map(([name, value]) => ({ name, value })),
|
|
147
|
+
}
|
|
148
|
+
: {
|
|
149
|
+
name: definition.name,
|
|
150
|
+
command: definition.command ?? '',
|
|
151
|
+
args: definition.args ?? [],
|
|
152
|
+
env: Object.entries(definition.env ?? {}).map(([name, value]) => ({ name, value })),
|
|
153
|
+
},
|
|
154
|
+
);
|
|
155
|
+
}
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The MCP list a session receives.
|
|
8
|
+
*
|
|
9
|
+
* The bug this pins: the settings pane read omp's `mcp.json`, the ACP spawn
|
|
10
|
+
* passed `mcpServers: []`, and a plugin had no way to contribute — so a server
|
|
11
|
+
* the user configured reached exactly one harness. These tests drive the merge
|
|
12
|
+
* over a temp agent dir, a temp project and an isolated database.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import { afterAll, beforeAll, describe, expect, test } from 'bun:test';
|
|
16
|
+
import { mkdir, mkdtemp, rm, writeFile } from 'fs/promises';
|
|
17
|
+
import { tmpdir } from 'os';
|
|
18
|
+
import { join } from 'path';
|
|
19
|
+
import { isolateDb, releaseDb } from '@/test-support/isolated-db';
|
|
20
|
+
import {
|
|
21
|
+
definitionFromItem,
|
|
22
|
+
definitionFromNative,
|
|
23
|
+
mcpServersFor,
|
|
24
|
+
toAcpMcpServers,
|
|
25
|
+
} from '@/server/lib/mcp/registry.server';
|
|
26
|
+
import { writeCustomMcpServers } from '@/server/lib/mcp/store.server';
|
|
27
|
+
import { clearPluginMcp, createPluginMcp } from '@/server/lib/plugins/mcp.server';
|
|
28
|
+
import { getDb } from '@/server/db.server';
|
|
29
|
+
import type { McpServerItem } from '@/shared/types';
|
|
30
|
+
|
|
31
|
+
let root = '';
|
|
32
|
+
let agentDir = '';
|
|
33
|
+
let project = '';
|
|
34
|
+
const previousAgentDir = Bun.env.PI_CODING_AGENT_DIR;
|
|
35
|
+
|
|
36
|
+
beforeAll(async () => {
|
|
37
|
+
root = await mkdtemp(join(tmpdir(), 'kabmo-mcp-registry-'));
|
|
38
|
+
agentDir = join(root, 'agent');
|
|
39
|
+
project = join(root, 'project');
|
|
40
|
+
await mkdir(agentDir, { recursive: true });
|
|
41
|
+
await mkdir(join(project, '.omp'), { recursive: true });
|
|
42
|
+
Bun.env.PI_CODING_AGENT_DIR = agentDir;
|
|
43
|
+
await isolateDb();
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
afterAll(async () => {
|
|
47
|
+
await releaseDb();
|
|
48
|
+
if (previousAgentDir === undefined) delete Bun.env.PI_CODING_AGENT_DIR;
|
|
49
|
+
else Bun.env.PI_CODING_AGENT_DIR = previousAgentDir;
|
|
50
|
+
await rm(root, { recursive: true, force: true });
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
function item(overrides: Partial<McpServerItem> = {}): McpServerItem {
|
|
54
|
+
return {
|
|
55
|
+
id: 'custom-1',
|
|
56
|
+
name: 'custom',
|
|
57
|
+
scope: 'every-project',
|
|
58
|
+
enabled: true,
|
|
59
|
+
reachType: 'command',
|
|
60
|
+
commandArgs: ['npx', '-y', 'custom-mcp'],
|
|
61
|
+
envVars: [],
|
|
62
|
+
...overrides,
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
describe('definitionFromNative', () => {
|
|
67
|
+
test('a command entry becomes a stdio server', () => {
|
|
68
|
+
expect(definitionFromNative('notes', { command: 'npx', args: ['-y', 'notes'], env: { TOKEN: 'x' } })).toEqual({
|
|
69
|
+
name: 'notes',
|
|
70
|
+
transport: 'stdio',
|
|
71
|
+
command: 'npx',
|
|
72
|
+
args: ['-y', 'notes'],
|
|
73
|
+
env: { TOKEN: 'x' },
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
test('a url entry becomes an http server', () => {
|
|
78
|
+
expect(definitionFromNative('remote', { url: 'https://mcp.example/sse', headers: { Authorization: 'Bearer x' } })).toEqual({
|
|
79
|
+
name: 'remote',
|
|
80
|
+
transport: 'http',
|
|
81
|
+
url: 'https://mcp.example/sse',
|
|
82
|
+
headers: { Authorization: 'Bearer x' },
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
test('an entry naming neither is dropped, not guessed at', () => {
|
|
87
|
+
expect(definitionFromNative('broken', {})).toBeNull();
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
describe('definitionFromItem', () => {
|
|
92
|
+
test('a disabled row is not injected', () => {
|
|
93
|
+
expect(definitionFromItem(item({ enabled: false }))).toBeNull();
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
test('a masked credential is never injected as the literal dots', () => {
|
|
97
|
+
const definition = definitionFromItem(
|
|
98
|
+
item({ envVars: [{ id: '1', key: 'TOKEN', value: '••••••••' }, { id: '2', key: 'MODE', value: 'fast' }] }),
|
|
99
|
+
);
|
|
100
|
+
expect(definition?.env).toEqual({ MODE: 'fast' });
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
test('a link row becomes an http server', () => {
|
|
104
|
+
expect(definitionFromItem(item({ reachType: 'link', linkUrl: 'https://mcp.example' }))).toEqual({
|
|
105
|
+
name: 'custom',
|
|
106
|
+
transport: 'http',
|
|
107
|
+
url: 'https://mcp.example',
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
describe('toAcpMcpServers', () => {
|
|
113
|
+
test('maps both transports to the wire shape', () => {
|
|
114
|
+
expect(
|
|
115
|
+
toAcpMcpServers([
|
|
116
|
+
{ name: 'a', transport: 'stdio', command: 'npx', args: ['x'], env: { K: 'V' } },
|
|
117
|
+
{ name: 'b', transport: 'http', url: 'https://x', headers: { H: '1' } },
|
|
118
|
+
]),
|
|
119
|
+
).toEqual([
|
|
120
|
+
{ name: 'a', command: 'npx', args: ['x'], env: [{ name: 'K', value: 'V' }] },
|
|
121
|
+
{ type: 'http', name: 'b', url: 'https://x', headers: [{ name: 'H', value: '1' }] },
|
|
122
|
+
]);
|
|
123
|
+
});
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
describe('mcpServersFor', () => {
|
|
127
|
+
test('merges user, project, app-local and plugin servers, first name wins', async () => {
|
|
128
|
+
await writeFile(
|
|
129
|
+
join(agentDir, 'mcp.json'),
|
|
130
|
+
JSON.stringify({
|
|
131
|
+
mcpServers: {
|
|
132
|
+
shared: { command: 'user-command' },
|
|
133
|
+
off: { command: 'disabled-command' },
|
|
134
|
+
},
|
|
135
|
+
disabledServers: ['off'],
|
|
136
|
+
}),
|
|
137
|
+
);
|
|
138
|
+
await writeFile(
|
|
139
|
+
join(project, '.omp', 'mcp.json'),
|
|
140
|
+
JSON.stringify({ mcpServers: { project: { command: 'project-command' } } }),
|
|
141
|
+
);
|
|
142
|
+
await writeCustomMcpServers(await getDb(), [
|
|
143
|
+
item({ id: 'shared', name: 'shared', commandArgs: ['custom-command'] }),
|
|
144
|
+
item({ id: 'local', name: 'local', commandArgs: ['local-command'] }),
|
|
145
|
+
]);
|
|
146
|
+
const plugin = createPluginMcp('demo');
|
|
147
|
+
plugin.register({ id: 'tools', transport: 'stdio', command: 'plugin-command' });
|
|
148
|
+
|
|
149
|
+
try {
|
|
150
|
+
const servers = await mcpServersFor(project);
|
|
151
|
+
expect(servers.map((server) => server.name)).toEqual(['shared', 'project', 'local', 'demo:tools']);
|
|
152
|
+
// The user's entry wins over the app-local row of the same name.
|
|
153
|
+
expect(servers[0]?.command).toBe('user-command');
|
|
154
|
+
expect(servers.some((server) => server.name === 'off')).toBe(false);
|
|
155
|
+
} finally {
|
|
156
|
+
clearPluginMcp('demo');
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
test('a project-scoped row is only injected into its own project', async () => {
|
|
161
|
+
await writeCustomMcpServers(await getDb(), [
|
|
162
|
+
item({ id: 'scoped', name: 'scoped', scope: 'this-project', projectPath: project }),
|
|
163
|
+
]);
|
|
164
|
+
const elsewhere = join(root, 'elsewhere');
|
|
165
|
+
await mkdir(elsewhere, { recursive: true });
|
|
166
|
+
expect((await mcpServersFor(project)).some((server) => server.name === 'scoped')).toBe(true);
|
|
167
|
+
expect((await mcpServersFor(elsewhere)).some((server) => server.name === 'scoped')).toBe(false);
|
|
168
|
+
});
|
|
169
|
+
});
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The MCP settings rows, in one place.
|
|
8
|
+
*
|
|
9
|
+
* Split out of the settings route so the SPAWN path can read the same list: an
|
|
10
|
+
* ACP session injects the enabled servers into `session/new`, and a second
|
|
11
|
+
* reader that re-derived the key or the mock default would drift from the pane
|
|
12
|
+
* the user actually edited.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import { DEFAULT_MCP_SERVERS } from '@/client/data/settings/mcp';
|
|
16
|
+
import { createSettingsListStore } from '@/server/lib/db/settings-store';
|
|
17
|
+
import { isMockMode } from '@/server/mock.server';
|
|
18
|
+
import type { DbClient } from '@/server/lib/db/client';
|
|
19
|
+
import type { McpServerItem } from '@/shared/types';
|
|
20
|
+
|
|
21
|
+
export const MCP_SETTINGS_KEY = 'omp_mcp_servers';
|
|
22
|
+
|
|
23
|
+
export const mcpStore = createSettingsListStore<McpServerItem>({
|
|
24
|
+
key: MCP_SETTINGS_KEY,
|
|
25
|
+
mockDefaults: DEFAULT_MCP_SERVERS,
|
|
26
|
+
idOf: (server) => server.id,
|
|
27
|
+
singular: 'server',
|
|
28
|
+
plural: 'servers',
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
/** The app-local rows, with the mock default only in mock mode. */
|
|
32
|
+
export async function readCustomMcpServers(db: DbClient): Promise<McpServerItem[]> {
|
|
33
|
+
return mcpStore.readStored(db, { absent: isMockMode() ? DEFAULT_MCP_SERVERS : [] });
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export async function writeCustomMcpServers(db: DbClient, servers: McpServerItem[]): Promise<void> {
|
|
37
|
+
await mcpStore.write(db, servers);
|
|
38
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The contract between the frame fold and the session wrapper it folds into.
|
|
8
|
+
* Types only, split out to keep `frame-fold.ts` under the size ceiling.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import type { AutoTitleHost } from '@/server/lib/omp/session/auto-title.server';
|
|
12
|
+
import type { QueueDeliveryHost } from '@/server/lib/queue/delivery.server';
|
|
13
|
+
import type { AgentEvent } from '@/server/lib/omp/rpc/constants';
|
|
14
|
+
import type { ModeMirror } from '@/server/lib/omp/rpc/mode-mirror';
|
|
15
|
+
import type { SessionRunModel } from '@/shared/lib/omp/session/stream-state.server';
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Wrapper surface the fold reads and writes. Every field is owned by the
|
|
19
|
+
* wrapper; the fold mutates them in place exactly as the inline switch did.
|
|
20
|
+
* Composes the two host contracts the settle path hands the wrapper to
|
|
21
|
+
* (auto-title, queue delivery) so the wrapper itself satisfies this whole type.
|
|
22
|
+
*/
|
|
23
|
+
export interface SessionFrameHost extends AutoTitleHost, QueueDeliveryHost {
|
|
24
|
+
promptRunning: boolean;
|
|
25
|
+
streaming: boolean;
|
|
26
|
+
compacting: boolean;
|
|
27
|
+
/** Abort verdict of the current run — see `endedAborted` in `terminal-settle.ts`. */
|
|
28
|
+
runAborted: boolean;
|
|
29
|
+
awaitingAgentStart: boolean;
|
|
30
|
+
awaitingAgentStartDeadline: number;
|
|
31
|
+
continuationGraceUntil: number;
|
|
32
|
+
emit(event: AgentEvent): void;
|
|
33
|
+
/** Remember a blocking ask/approval dialog so a reattaching client can answer it. */
|
|
34
|
+
trackUiDialog(frame: AgentEvent): void;
|
|
35
|
+
/** Mirror of omp's plan/goal mode, fed by the frames this fold sees. */
|
|
36
|
+
modeMirror: ModeMirror;
|
|
37
|
+
/**
|
|
38
|
+
* The model the child is serving with, as the wrapper last reconciled it.
|
|
39
|
+
* The `stream` row this fold writes carries it.
|
|
40
|
+
*/
|
|
41
|
+
runModel: SessionRunModel | null;
|
|
42
|
+
/** Fold a subagent frame into the liveness roster. */
|
|
43
|
+
observeSubagent(frame: AgentEvent, now: number): void;
|
|
44
|
+
/**
|
|
45
|
+
* Re-read the model the child is actually serving with and rename the live run
|
|
46
|
+
* row to match — omp's payload-less `model_changed`, e.g. a fallback-chain
|
|
47
|
+
* retry that swapped the model mid-run.
|
|
48
|
+
*/
|
|
49
|
+
syncRunModel(): void;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** What the caller must do after the fold. */
|
|
53
|
+
export interface FrameFoldResult {
|
|
54
|
+
/** The fold already handled this frame's user-visible effect and the caller
|
|
55
|
+
* must NOT forward it: a failed `prompt` response has emitted its own
|
|
56
|
+
* `prompt_error`, and a `command_output` belonging to Kabmo's own
|
|
57
|
+
* background rename must stay out of the timeline. */
|
|
58
|
+
suppressForward: boolean;
|
|
59
|
+
}
|
|
@@ -14,11 +14,19 @@
|
|
|
14
14
|
* idle-looking session in the middle of a compaction.
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
|
-
import { describe, expect, test } from 'bun:test';
|
|
17
|
+
import { afterEach, beforeEach, describe, expect, test } from 'bun:test';
|
|
18
18
|
|
|
19
19
|
import { foldSessionFrame } from '@/server/lib/omp/rpc/frame-fold';
|
|
20
20
|
import { releasesStreamRowOnPromptResult } from '@/shared/lib/omp/session/stream-heal.server';
|
|
21
21
|
import { makeHost } from '@/server/lib/omp/rpc/frame-fold-host.test-util';
|
|
22
|
+
import type { AgentEvent } from '@/server/lib/omp/rpc/constants';
|
|
23
|
+
import { onRealtimeSignal } from '@/server/lib/realtime/signals.server';
|
|
24
|
+
import { isolateDb, releaseDb } from '@/test-support/isolated-db';
|
|
25
|
+
import {
|
|
26
|
+
loadStreamStates,
|
|
27
|
+
markStreamStatus,
|
|
28
|
+
type SessionRunModel,
|
|
29
|
+
} from '@/shared/lib/omp/session/stream-state.server';
|
|
22
30
|
|
|
23
31
|
/**
|
|
24
32
|
* The `prompt_result` frame is where omp reports `agentInvoked`, and the
|
|
@@ -129,3 +137,58 @@ describe('compaction frames', () => {
|
|
|
129
137
|
});
|
|
130
138
|
|
|
131
139
|
});
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* The `stream` row a frame opens must name the model the run is served by.
|
|
143
|
+
*
|
|
144
|
+
* `agent_start`/`turn_start`/`message_start` are the only writers for a run
|
|
145
|
+
* whose prompt never went through the dispatcher, and they wrote the status
|
|
146
|
+
* alone: the sidebar's `runModel` was then empty and the docked indicator read
|
|
147
|
+
* `Loading…` for the whole answer.
|
|
148
|
+
*/
|
|
149
|
+
describe('the stream row names the run model', () => {
|
|
150
|
+
beforeEach(async () => {
|
|
151
|
+
// The row writes resolve the database; isolated so the real `~/.kabmo` is
|
|
152
|
+
// never opened. Same helper the stream-state suite uses.
|
|
153
|
+
await isolateDb();
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
afterEach(async () => {
|
|
157
|
+
await releaseDb();
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
/** Fold one frame and wait for its fire-and-forget write via `stream-status`. */
|
|
161
|
+
async function foldAndReadRow(
|
|
162
|
+
sessionId: string,
|
|
163
|
+
frame: AgentEvent,
|
|
164
|
+
runModel: SessionRunModel | null,
|
|
165
|
+
) {
|
|
166
|
+
const { promise, resolve } = Promise.withResolvers<void>();
|
|
167
|
+
const off = onRealtimeSignal((event) => {
|
|
168
|
+
if (event.signal === 'stream-status') resolve();
|
|
169
|
+
});
|
|
170
|
+
try {
|
|
171
|
+
foldSessionFrame(makeHost({ sessionId, runModel }), frame);
|
|
172
|
+
await promise;
|
|
173
|
+
} finally {
|
|
174
|
+
off();
|
|
175
|
+
}
|
|
176
|
+
return (await loadStreamStates())[sessionId];
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
test('agent_start writes the host model into the row it opens', async () => {
|
|
180
|
+
expect(await foldAndReadRow('s1', { type: 'agent_start' }, { provider: 'anthropic', modelId: 'claude' })).toEqual({
|
|
181
|
+
status: 'stream',
|
|
182
|
+
model: { provider: 'anthropic', modelId: 'claude' },
|
|
183
|
+
});
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
test('a later frame with no reconciled model keeps a pair the dispatch stored', async () => {
|
|
187
|
+
await markStreamStatus('s1', 'stream', { provider: 'openai', modelId: 'gpt-5' });
|
|
188
|
+
|
|
189
|
+
expect(await foldAndReadRow('s1', { type: 'turn_start' }, null)).toEqual({
|
|
190
|
+
status: 'stream',
|
|
191
|
+
model: { provider: 'openai', modelId: 'gpt-5' },
|
|
192
|
+
});
|
|
193
|
+
});
|
|
194
|
+
});
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
* returns first and the tests stay pure.
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
|
-
import type { SessionFrameHost } from '@/server/lib/omp/rpc/frame-fold';
|
|
18
|
+
import type { SessionFrameHost } from '@/server/lib/omp/rpc/frame-fold-contract';
|
|
19
19
|
import { ModeMirror } from '@/server/lib/omp/rpc/mode-mirror';
|
|
20
20
|
|
|
21
21
|
export function makeHost(overrides: Partial<SessionFrameHost> = {}): SessionFrameHost {
|
|
@@ -34,6 +34,7 @@ export function makeHost(overrides: Partial<SessionFrameHost> = {}): SessionFram
|
|
|
34
34
|
awaitingAgentStartDeadline: 0,
|
|
35
35
|
continuationGraceUntil: 0,
|
|
36
36
|
proc: { sendCommand: async () => undefined as never },
|
|
37
|
+
runModel: null,
|
|
37
38
|
emit() {},
|
|
38
39
|
trackUiDialog() {},
|
|
39
40
|
observeSubagent() {},
|
|
@@ -19,7 +19,8 @@
|
|
|
19
19
|
|
|
20
20
|
import { describe, expect, test } from 'bun:test';
|
|
21
21
|
|
|
22
|
-
import { foldSessionFrame
|
|
22
|
+
import { foldSessionFrame } from '@/server/lib/omp/rpc/frame-fold';
|
|
23
|
+
import type { SessionFrameHost } from '@/server/lib/omp/rpc/frame-fold-contract';
|
|
23
24
|
import type { AgentEvent } from '@/server/lib/omp/rpc/constants';
|
|
24
25
|
import { makeHost } from '@/server/lib/omp/rpc/frame-fold-host.test-util';
|
|
25
26
|
|
|
@@ -23,9 +23,7 @@ import { clearSessionFileCaches } from '@/server/lib/omp/session/files';
|
|
|
23
23
|
import {
|
|
24
24
|
consumeAutoTitleOutput,
|
|
25
25
|
triggerAutoSessionTitle,
|
|
26
|
-
type AutoTitleHost,
|
|
27
26
|
} from '@/server/lib/omp/session/auto-title.server';
|
|
28
|
-
import { type QueueDeliveryHost } from '@/server/lib/queue/delivery.server';
|
|
29
27
|
import { clearStreamStatus, markStreamStatus } from '@/shared/lib/omp/session/stream-state.server';
|
|
30
28
|
import { releasesStreamRowOnPromptResult } from '@/shared/lib/omp/session/stream-heal.server';
|
|
31
29
|
import { emitRealtimeSignal } from '@/server/lib/realtime/signals.server';
|
|
@@ -34,46 +32,7 @@ import { NON_TERMINAL_CONTINUATION_GRACE_MS, type AgentEvent } from '@/server/li
|
|
|
34
32
|
import { settleTerminalRun } from '@/server/lib/omp/rpc/terminal-settle';
|
|
35
33
|
import { parseModeMarker } from '@/shared/lib/omp/mode/markers';
|
|
36
34
|
import { SKILL_PROMPT_CUSTOM_TYPE } from '@/shared/lib/omp/session/operator-title';
|
|
37
|
-
import type {
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Wrapper surface the fold reads and writes. Every field is owned by the
|
|
41
|
-
* wrapper; the fold mutates them in place exactly as the inline switch did.
|
|
42
|
-
* Composes the two host contracts the settle path hands the wrapper to
|
|
43
|
-
* (auto-title, queue delivery) so the wrapper itself satisfies this whole type.
|
|
44
|
-
*/
|
|
45
|
-
export interface SessionFrameHost extends AutoTitleHost, QueueDeliveryHost {
|
|
46
|
-
promptRunning: boolean;
|
|
47
|
-
streaming: boolean;
|
|
48
|
-
compacting: boolean;
|
|
49
|
-
/** Abort verdict of the current run — see `endedAborted` in `terminal-settle.ts`. */
|
|
50
|
-
runAborted: boolean;
|
|
51
|
-
awaitingAgentStart: boolean;
|
|
52
|
-
awaitingAgentStartDeadline: number;
|
|
53
|
-
continuationGraceUntil: number;
|
|
54
|
-
emit(event: AgentEvent): void;
|
|
55
|
-
/** Remember a blocking ask/approval dialog so a reattaching client can answer it. */
|
|
56
|
-
trackUiDialog(frame: AgentEvent): void;
|
|
57
|
-
/** Mirror of omp's plan/goal mode, fed by the frames this fold sees. */
|
|
58
|
-
modeMirror: ModeMirror;
|
|
59
|
-
/** Fold a subagent frame into the liveness roster. */
|
|
60
|
-
observeSubagent(frame: AgentEvent, now: number): void;
|
|
61
|
-
/**
|
|
62
|
-
* Re-read the model the child is actually serving with and rename the live run
|
|
63
|
-
* row to match — omp's payload-less `model_changed`, e.g. a fallback-chain
|
|
64
|
-
* retry that swapped the model mid-run.
|
|
65
|
-
*/
|
|
66
|
-
syncRunModel(): void;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
/** What the caller must do after the fold. */
|
|
70
|
-
export interface FrameFoldResult {
|
|
71
|
-
/** The fold already handled this frame's user-visible effect and the caller
|
|
72
|
-
* must NOT forward it: a failed `prompt` response has emitted its own
|
|
73
|
-
* `prompt_error`, and a `command_output` belonging to Kabmo's own
|
|
74
|
-
* background rename must stay out of the timeline. */
|
|
75
|
-
suppressForward: boolean;
|
|
76
|
-
}
|
|
35
|
+
import type { FrameFoldResult, SessionFrameHost } from '@/server/lib/omp/rpc/frame-fold-contract';
|
|
77
36
|
|
|
78
37
|
/**
|
|
79
38
|
* The `message_end` branch: the one place a title can be derived from the
|
|
@@ -201,7 +160,9 @@ export function foldSessionFrame(host: SessionFrameHost, event: AgentEvent): Fra
|
|
|
201
160
|
// what bounds this to the conversation's first run.
|
|
202
161
|
host.autoTitleRequested = false;
|
|
203
162
|
clearSessionFileCaches();
|
|
204
|
-
|
|
163
|
+
// The row carries the model the wrapper reconciled; a run whose dispatch
|
|
164
|
+
// stored none would otherwise name no provider/model. COALESCE keeps a pair.
|
|
165
|
+
if (host.sessionId) void markStreamStatus(host.sessionId, 'stream', host.runModel);
|
|
205
166
|
// Belt for a switch omp did not announce: a fallback that landed between
|
|
206
167
|
// runs leaves `runModel` (and the row the indicator names the run by) on
|
|
207
168
|
// the pre-fallback model. `model_changed` covers the switches omp reports;
|
|
@@ -213,13 +174,13 @@ export function foldSessionFrame(host: SessionFrameHost, event: AgentEvent): Fra
|
|
|
213
174
|
// Redundant with agent_start in the happy path, but the run-level
|
|
214
175
|
// counterpart can be missed (e.g. the state was cleared by a command
|
|
215
176
|
// between frames). The turn is proof enough the session is live.
|
|
216
|
-
if (host.sessionId) void markStreamStatus(host.sessionId, 'stream');
|
|
177
|
+
if (host.sessionId) void markStreamStatus(host.sessionId, 'stream', host.runModel);
|
|
217
178
|
break;
|
|
218
179
|
case 'message_start':
|
|
219
180
|
// Same recovery as turn_start: a message frame is only emitted inside a
|
|
220
181
|
// live run, so its arrival re-arms the `stream` row no matter what stale
|
|
221
182
|
// status sits there (upsert overwrites any terminal badge).
|
|
222
|
-
if (host.sessionId) void markStreamStatus(host.sessionId, 'stream');
|
|
183
|
+
if (host.sessionId) void markStreamStatus(host.sessionId, 'stream', host.runModel);
|
|
223
184
|
break;
|
|
224
185
|
case 'message_end':
|
|
225
186
|
handleMessageEnd(host, event);
|
|
@@ -43,14 +43,28 @@ export function getPrewarmed(): Map<string, PrewarmedEntry> {
|
|
|
43
43
|
return globalThis.__ompPrewarmed;
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
+
/** The same selection spellings the claim compares, so the two cannot drift. */
|
|
47
|
+
function modesOf(env?: Record<string, string>): string {
|
|
48
|
+
return env?.KABMO_MODES ?? env?.CHAMBER_MODES ?? '';
|
|
49
|
+
}
|
|
50
|
+
|
|
46
51
|
/** Spawn (at most one) idle omp process for `cwd` so the next new-session
|
|
47
52
|
* send starts instantly. Fire-and-forget; a failed spawn just clears itself.
|
|
48
|
-
* Safe to call repeatedly — an existing live or in-flight entry wins
|
|
53
|
+
* Safe to call repeatedly — an existing live or in-flight entry wins, unless it
|
|
54
|
+
* was warmed for a DIFFERENT selection: that child can never serve this chat
|
|
55
|
+
* (the extension reads the mode env once, at start), so it is recycled here
|
|
56
|
+
* instead of being killed by the claim and paid for twice. */
|
|
49
57
|
export function prewarmRpcSession(cwd: string, approvalMode?: ApprovalMode, modeEnv?: Record<string, string>): void {
|
|
50
58
|
const pool = getPrewarmed();
|
|
51
|
-
const existing = pool.get(cwd);
|
|
52
|
-
if (existing) return;
|
|
53
59
|
const mode = approvalMode ?? DEFAULT_APPROVAL_MODE;
|
|
60
|
+
const existing = pool.get(cwd);
|
|
61
|
+
if (existing) {
|
|
62
|
+
if (existing.claimed) return;
|
|
63
|
+
if (existing.approvalMode === mode && modesOf(existing.modeEnv) === modesOf(modeEnv)) return;
|
|
64
|
+
existing.claimed = true;
|
|
65
|
+
pool.delete(cwd);
|
|
66
|
+
void existing.ready.then((wrapper) => wrapper.destroyAndWait()).catch(() => {});
|
|
67
|
+
}
|
|
54
68
|
// The prewarmed child is a session host with a real id, so it gets its own
|
|
55
69
|
// callback credential now; the claim path must not replace it, because the
|
|
56
70
|
// child's environment already carries this value.
|
|
@@ -146,8 +160,8 @@ export async function claimPrewarmedSession(
|
|
|
146
160
|
// time, so a MODE selection that differs from its own can no longer be served
|
|
147
161
|
// by it — the extension reads the mode env once, at session start. Treated
|
|
148
162
|
// exactly like a mode mismatch: claim and kill, then spawn cold.
|
|
149
|
-
const entryModes = entry.modeEnv
|
|
150
|
-
const wantedModes = modeEnv
|
|
163
|
+
const entryModes = modesOf(entry.modeEnv);
|
|
164
|
+
const wantedModes = modesOf(modeEnv);
|
|
151
165
|
const usable = !entry.claimed && entry.approvalMode === approvalMode && entryModes === wantedModes;
|
|
152
166
|
|
|
153
167
|
if (usable) {
|