@kabmo-labs/kabmo 0.30.0 → 0.31.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 +79 -21
- package/dist/client/index.html +1 -1
- package/dist/client/index.js +481 -462
- package/dist/client/static/js/{index-5vjbp04s.js → index-r3bhgvkt.js} +882 -883
- package/marketplace/plugins/stats/package.json +2 -2
- package/marketplace/plugins/stats/src/format.test.ts +7 -1
- package/package.json +2 -2
- package/src/client/components/common/context-usage-button/McpSection.tsx +133 -0
- package/src/client/components/common/context-usage-button/Ring.tsx +12 -6
- package/src/client/components/common/context-usage-button/index.test.tsx +24 -13
- package/src/client/components/common/context-usage-button/index.tsx +32 -34
- package/src/client/components/common/session-row/TrailingSlot.tsx +6 -2
- package/src/client/components/common/session-row/session-row.test.tsx +13 -0
- package/src/client/components/layout/desktop-layout/index.tsx +5 -1
- package/src/client/components/mobile/RightSidebar.tsx +2 -1
- package/src/client/components/settings/categories/McpSettings.tsx +10 -3
- package/src/client/components/settings/categories/mcp-settings/AdvancedSection.tsx +244 -0
- package/src/client/components/settings/categories/mcp-settings/ConnectionTest.tsx +3 -3
- package/src/client/components/settings/categories/mcp-settings/DetailPane.tsx +55 -97
- package/src/client/components/settings/categories/mcp-settings/ImportModal.tsx +12 -64
- package/src/client/components/settings/categories/mcp-settings/{EnvVarsSection.tsx → KeyValueSection.tsx} +42 -24
- package/src/client/components/settings/categories/mcp-settings/SidebarList.tsx +1 -1
- package/src/client/components/settings/categories/mcp-settings/TransportSection.tsx +101 -0
- package/src/client/components/workspace/browser-panel/EngineNotice.test.tsx +109 -0
- package/src/client/components/workspace/browser-panel/EngineNotice.tsx +112 -0
- package/src/client/components/workspace/browser-panel/index.tsx +45 -12
- package/src/client/components/workspace/chat-timeline/chat-input/AccessDropdown.test.ts +63 -0
- package/src/client/components/workspace/chat-timeline/chat-input/AccessDropdown.tsx +18 -6
- package/src/client/components/workspace/chat-timeline/chat-input/Toolbar.tsx +3 -1
- package/src/client/components/workspace/chat-timeline/chat-input/access-levels.ts +39 -1
- package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Eval.test.tsx +13 -7
- package/src/client/components/workspace/editor/plugin-rail.test.tsx +6 -1
- package/src/client/components/workspace/terminal-panel/scroll-hold.test.ts +20 -5
- package/src/client/data/settings/mcp.ts +4 -2
- package/src/client/data/settings/omp-schema.json +22 -2
- package/src/client/hooks/browser/use-browser-engine.ts +99 -0
- package/src/client/hooks/chat/context/mcp.ts +159 -0
- package/src/client/hooks/chat/timeline/access-mode.ts +45 -15
- package/src/client/hooks/chat/timeline/index.ts +7 -3
- package/src/client/hooks/chat/timeline/timeline-mode-state.test.ts +33 -4
- package/src/client/hooks/ui/ui-listeners.test.ts +13 -18
- package/src/server/lib/browser/engine.test.ts +118 -0
- package/src/server/lib/browser/engine.ts +102 -0
- package/src/server/lib/db/schema.ts +4 -0
- package/src/server/lib/fs/toolchain-path.test.ts +87 -0
- package/src/server/lib/fs/toolchain-path.ts +49 -0
- package/src/server/lib/harness/acp/protocol.ts +9 -1
- package/src/server/lib/harness/auto-probe.server.ts +3 -2
- package/src/server/lib/harness/launch-table.ts +3 -2
- package/src/server/lib/harness/spawn.server.ts +5 -1
- package/src/server/lib/harness/update-queue.server.ts +2 -1
- package/src/server/lib/harness/update-state.server.ts +6 -2
- package/src/server/lib/mcp/probe.server.ts +71 -0
- package/src/server/lib/mcp/registry.server.ts +195 -46
- package/src/server/lib/mcp/registry.test.ts +76 -4
- package/src/server/lib/mcp/schema.server.ts +35 -0
- package/src/server/lib/mcp/session-mcp.test.ts +164 -0
- package/src/server/lib/mcp/session-overlay.server.ts +152 -0
- package/src/server/lib/mcp/session-state.server.ts +75 -0
- package/src/server/lib/mcp/store.server.ts +6 -1
- package/src/server/lib/omp/config/config-cli.ts +4 -0
- package/src/server/lib/omp/config/mcp-and-cli.test.ts +12 -183
- package/src/server/lib/omp/config/mcp-config.test.ts +277 -0
- package/src/server/lib/omp/config/mcp-shared.ts +36 -0
- package/src/server/lib/omp/config/mcp-test-protocol.ts +89 -0
- package/src/server/lib/omp/config/mcp-test-remote.ts +167 -0
- package/src/server/lib/omp/config/mcp-test.ts +21 -123
- package/src/server/lib/omp/config/mcp-write.ts +179 -0
- package/src/server/lib/omp/config/mcp.ts +138 -118
- package/src/server/lib/omp/core/cli.ts +4 -14
- package/src/server/lib/omp/rpc/manager.ts +12 -17
- package/src/server/lib/omp/rpc/reload-mcp.ts +39 -0
- package/src/server/lib/omp/rpc/session-registry.ts +6 -2
- package/src/server/lib/omp/rpc/spawn-mcp.ts +43 -0
- package/src/server/lib/omp/session/delete.server.ts +7 -0
- package/src/server/lib/plugins/mcp.server.ts +2 -2
- package/src/server/lib/realtime/topics/workspace.server.test.ts +44 -0
- package/src/server/lib/realtime/topics/workspace.server.ts +3 -2
- package/src/server/routes/browser/engine.test.ts +70 -0
- package/src/server/routes/browser/engine.ts +51 -0
- package/src/server/routes/browser/index.ts +5 -0
- package/src/server/routes/fs/git.ts +4 -3
- package/src/server/routes/harness/versions.test.ts +5 -0
- package/src/server/routes/sessions/index.ts +7 -0
- package/src/server/routes/sessions/mcp.test.ts +154 -0
- package/src/server/routes/sessions/mcp.ts +202 -0
- package/src/server/routes/settings/mcp-test.ts +5 -4
- package/src/server/routes/settings/mcp.test.ts +42 -1
- package/src/server/routes/settings/mcp.ts +80 -24
- package/src/shared/lib/code/highlight-memo.test.ts +18 -0
- package/src/shared/lib/code/highlight-memo.ts +46 -17
- package/src/shared/lib/fonts/nerd-symbols.css +14 -0
- package/src/shared/lib/fonts/nerd-symbols.test.ts +86 -0
- package/src/shared/lib/fonts/symbols-nerd-font-mono.woff2 +0 -0
- package/src/shared/lib/mcp/import.ts +112 -0
- package/src/shared/lib/mcp/item.ts +61 -0
- package/src/shared/lib/mcp/key-value.ts +37 -0
- package/src/shared/lib/mcp/mcp-lib.test.ts +119 -0
- package/src/shared/lib/mcp/status.test.ts +36 -0
- package/src/shared/lib/mcp/status.ts +38 -0
- package/src/shared/lib/models/client.ts +27 -6
- package/src/shared/lib/models/provider/models.test.ts +31 -0
- package/src/shared/lib/omp/config/access-mode.test.ts +73 -0
- package/src/shared/lib/omp/config/access-mode.ts +49 -0
- package/src/shared/lib/workspace/right-panels.ts +13 -0
- package/src/shared/lib/workspace/workspace-modules.test.ts +3 -1
- package/src/shared/types/browser.ts +21 -0
- package/src/shared/types/settings/mcp.ts +73 -4
- package/src/test-support/pristine-globals.test.ts +53 -0
- package/src/test-support/pristine-globals.ts +6 -1
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
* which is the only reason the hook subscribes at all.
|
|
26
26
|
*/
|
|
27
27
|
|
|
28
|
-
import { afterEach, beforeAll, describe, expect, test } from 'bun:test';
|
|
28
|
+
import { afterAll, afterEach, beforeAll, describe, expect, test } from 'bun:test';
|
|
29
29
|
import { Window } from 'happy-dom';
|
|
30
30
|
import { h, render } from 'preact';
|
|
31
31
|
import { act } from 'preact/test-utils';
|
|
@@ -33,13 +33,7 @@ import { act } from 'preact/test-utils';
|
|
|
33
33
|
import { useOnClickOutside } from '@/client/hooks/ui/on-click-outside';
|
|
34
34
|
import { useTouchDevice } from '@/client/hooks/ui/touch-device';
|
|
35
35
|
import { useWindowEvent } from '@/client/hooks/ui/window-event';
|
|
36
|
-
|
|
37
|
-
const NativeEvent = globalThis.Event;
|
|
38
|
-
const NativeCustomEvent = globalThis.CustomEvent;
|
|
39
|
-
|
|
40
|
-
const DOM_GLOBALS = ['window', 'document', 'navigator', 'Node', 'Element', 'HTMLElement', 'Event', 'CustomEvent'] as const;
|
|
41
|
-
/** The runner's own globals, restored on teardown (see the matching afterAll at the end of this file) so later files still see native Event/CustomEvent/window. */
|
|
42
|
-
const nativeGlobals: Partial<Record<(typeof DOM_GLOBALS)[number], unknown>> = {};
|
|
36
|
+
import { installDomGlobals, restoreDomGlobals } from '@/test-support/pristine-globals';
|
|
43
37
|
|
|
44
38
|
let win: Window;
|
|
45
39
|
let container: HTMLElement;
|
|
@@ -50,11 +44,10 @@ const queryListeners = new Map<string, Set<() => void>>();
|
|
|
50
44
|
|
|
51
45
|
beforeAll(() => {
|
|
52
46
|
win = new Window({ url: 'http://localhost' });
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
}
|
|
47
|
+
// The shared helper, not a local save-and-restore loop: a loop that captures
|
|
48
|
+
// the runner's globals on first use captures whatever the PREVIOUS file left
|
|
49
|
+
// behind when that file leaked, and then faithfully restores the leak.
|
|
50
|
+
installDomGlobals(win);
|
|
58
51
|
win.matchMedia = ((query: string) => {
|
|
59
52
|
const listeners = queryListeners.get(query) ?? new Set<() => void>();
|
|
60
53
|
queryListeners.set(query, listeners);
|
|
@@ -76,16 +69,18 @@ beforeAll(() => {
|
|
|
76
69
|
afterEach(() => {
|
|
77
70
|
if (container) render(null, container);
|
|
78
71
|
container?.remove();
|
|
79
|
-
// The native target below rejects a foreign event: never leave a
|
|
80
|
-
// happy-dom constructor behind for the files that run after this one.
|
|
81
|
-
// (Bun's own constructors are captured at import, before any beforeAll.)
|
|
82
|
-
globalThis.Event = NativeEvent;
|
|
83
|
-
globalThis.CustomEvent = NativeCustomEvent;
|
|
84
72
|
queryMatches.clear();
|
|
85
73
|
for (const listeners of queryListeners.values()) listeners.clear();
|
|
86
74
|
Object.defineProperty(win.navigator, 'maxTouchPoints', { configurable: true, value: 0 });
|
|
87
75
|
});
|
|
88
76
|
|
|
77
|
+
// The window installed above is a REAL happy-dom one, and its `Event` is not
|
|
78
|
+
// the runner's: leaving it behind is what made a later suite dispatch a foreign
|
|
79
|
+
// event at a native `EventTarget` and throw before it asserted anything.
|
|
80
|
+
afterAll(() => {
|
|
81
|
+
restoreDomGlobals();
|
|
82
|
+
});
|
|
83
|
+
|
|
89
84
|
/** The event the DOM nodes under test accept: the global `Event` and
|
|
90
85
|
* happy-dom's runtime one are different objects, and reading the parameter
|
|
91
86
|
* off the target keeps both sides honest. */
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The engine probe behind the Browser Agent panel's notice.
|
|
8
|
+
*
|
|
9
|
+
* The panel can only mirror Chromium, so this answer decides whether it shows
|
|
10
|
+
* a live view or an explanation. The cases pin the two ways it could lie:
|
|
11
|
+
* claiming Chromium when omp will open WebKit (the panel then waits forever),
|
|
12
|
+
* and claiming WebKit when the engine is not installed (omp falls back to
|
|
13
|
+
* Chromium and the panel would refuse a view it can actually show).
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import { describe, expect, test } from 'bun:test';
|
|
17
|
+
import { readBrowserEngineState, webkitHostCandidates } from '@/server/lib/browser/engine';
|
|
18
|
+
|
|
19
|
+
const HOME = '/home/tester';
|
|
20
|
+
const DEFAULT_HOST = `${HOME}/.o2/lib/abkit/ABHost`;
|
|
21
|
+
|
|
22
|
+
function deps(config: Record<string, unknown>, files: string[]) {
|
|
23
|
+
return {
|
|
24
|
+
readConfig: async (key: string) => config[key],
|
|
25
|
+
exists: async (file: string) => files.includes(file),
|
|
26
|
+
home: HOME,
|
|
27
|
+
platform: 'darwin' as const,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
describe('webkitHostCandidates', () => {
|
|
32
|
+
test('defaults to the ABKit host under the home directory', () => {
|
|
33
|
+
expect(webkitHostCandidates(undefined, HOME, 'darwin')).toEqual([DEFAULT_HOST]);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
test('a configured engine directory also offers the host inside it', () => {
|
|
37
|
+
expect(webkitHostCandidates('/opt/abkit', HOME, 'darwin')).toEqual([
|
|
38
|
+
'/opt/abkit',
|
|
39
|
+
'/opt/abkit/ABHost',
|
|
40
|
+
]);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
test('a configured executable is offered as-is', () => {
|
|
44
|
+
expect(webkitHostCandidates('/opt/abkit/ABHost', HOME, 'darwin')).toEqual([
|
|
45
|
+
'/opt/abkit/ABHost',
|
|
46
|
+
'/opt/abkit/ABHost/ABHost',
|
|
47
|
+
]);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
test('windows names the host ABHost.exe', () => {
|
|
51
|
+
expect(webkitHostCandidates(undefined, 'C:\\Users\\t', 'win32')).toEqual([
|
|
52
|
+
'C:\\Users\\t\\.o2\\lib\\abkit\\ABHost.exe',
|
|
53
|
+
]);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
test('~ expands against the given home, never the real one', () => {
|
|
57
|
+
expect(webkitHostCandidates('~/engines/abkit', HOME, 'darwin')).toEqual([
|
|
58
|
+
`${HOME}/engines/abkit`,
|
|
59
|
+
`${HOME}/engines/abkit/ABHost`,
|
|
60
|
+
]);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
test('~ expands with the TARGET platform separators, not the host’s', () => {
|
|
64
|
+
// Measured on the Windows gate: the expansion used the host's `path.join`,
|
|
65
|
+
// so a `darwin` request answered `\home\tester\engines\abkit` — a path that
|
|
66
|
+
// exists on no Mac. The assertion is host-independent precisely because the
|
|
67
|
+
// function takes the platform it is answering for.
|
|
68
|
+
expect(webkitHostCandidates('~/engines/abkit', HOME, 'darwin')[0]).toBe('/home/tester/engines/abkit');
|
|
69
|
+
expect(webkitHostCandidates('~/engines/abkit', 'C:\\Users\\t', 'win32')).toEqual([
|
|
70
|
+
'C:\\Users\\t\\engines\\abkit',
|
|
71
|
+
'C:\\Users\\t\\engines\\abkit\\ABHost.exe',
|
|
72
|
+
]);
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
describe('readBrowserEngineState', () => {
|
|
77
|
+
test('WebKit is the default when the engine is installed', async () => {
|
|
78
|
+
expect(await readBrowserEngineState(deps({}, [DEFAULT_HOST]))).toEqual({
|
|
79
|
+
webkit: true,
|
|
80
|
+
engineInstalled: true,
|
|
81
|
+
effective: 'webkit',
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
test('browser.webkit false selects Chromium even with the engine installed', async () => {
|
|
86
|
+
const state = await readBrowserEngineState(
|
|
87
|
+
deps({ 'browser.webkit': false }, [DEFAULT_HOST]),
|
|
88
|
+
);
|
|
89
|
+
expect(state).toEqual({ webkit: false, engineInstalled: true, effective: 'chromium' });
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
test('a missing engine falls back to Chromium', async () => {
|
|
93
|
+
expect(await readBrowserEngineState(deps({}, []))).toEqual({
|
|
94
|
+
webkit: true,
|
|
95
|
+
engineInstalled: false,
|
|
96
|
+
effective: 'chromium',
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
test('a configured engine directory is honoured', async () => {
|
|
101
|
+
const state = await readBrowserEngineState(
|
|
102
|
+
deps({ 'browser.webkitPath': '/opt/abkit' }, ['/opt/abkit/ABHost']),
|
|
103
|
+
);
|
|
104
|
+
expect(state.effective).toBe('webkit');
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
test('a config read failure keeps the documented default instead of promising Chromium', async () => {
|
|
108
|
+
const state = await readBrowserEngineState({
|
|
109
|
+
readConfig: async () => {
|
|
110
|
+
throw new Error('omp binary not found');
|
|
111
|
+
},
|
|
112
|
+
exists: async () => true,
|
|
113
|
+
home: HOME,
|
|
114
|
+
platform: 'darwin',
|
|
115
|
+
});
|
|
116
|
+
expect(state).toEqual({ webkit: true, engineInstalled: true, effective: 'webkit' });
|
|
117
|
+
});
|
|
118
|
+
});
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Which browser engine the session's omp agent will use, and whether the
|
|
8
|
+
* Browser Agent panel can mirror it.
|
|
9
|
+
*
|
|
10
|
+
* omp opens tabs in its own WebKit engine (ABKit) by default when that engine
|
|
11
|
+
* is installed, and only falls back to the managed Chromium daemon otherwise.
|
|
12
|
+
* The panel mirrors Chromium over CDP; WebKit has no CDP endpoint and no frame
|
|
13
|
+
* stream, so a WebKit session is invisible to it. This module answers the one
|
|
14
|
+
* question the panel needs before it can explain that: is the next open going
|
|
15
|
+
* to be WebKit?
|
|
16
|
+
*
|
|
17
|
+
* The answer is read from omp's own config (`browser.webkit`, default `true`)
|
|
18
|
+
* plus the presence of the host executable, because a setting that names an
|
|
19
|
+
* engine which is not installed does not select it — omp falls back to
|
|
20
|
+
* Chromium and the panel works.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
import { homedir } from 'node:os';
|
|
24
|
+
import * as path from 'node:path';
|
|
25
|
+
import { getOmpConfigValue } from '@/server/lib/omp/config/config-cli';
|
|
26
|
+
import type { BrowserEngineState } from '@/shared/types';
|
|
27
|
+
|
|
28
|
+
/** Where omp installs ABKit when `browser.webkitPath` is unset. */
|
|
29
|
+
const DEFAULT_ENGINE_DIR = ['.o2', 'lib', 'abkit'] as const;
|
|
30
|
+
|
|
31
|
+
export interface BrowserEngineDeps {
|
|
32
|
+
/** Read one omp config key; defaults to the real `omp config get`. */
|
|
33
|
+
readConfig?: (key: string) => Promise<unknown>;
|
|
34
|
+
/** Whether a file exists; defaults to `Bun.file(...).exists()`. */
|
|
35
|
+
exists?: (file: string) => Promise<boolean>;
|
|
36
|
+
home?: string;
|
|
37
|
+
platform?: NodeJS.Platform;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* `~` and `~/…` against the given home, so a test never reads the real one.
|
|
42
|
+
*
|
|
43
|
+
* Joined with the TARGET platform's rules, not the host's: this module answers
|
|
44
|
+
* for the machine the browser runs on, and the Windows gate caught the host
|
|
45
|
+
* version of it — `path.join` turned a POSIX `~/engines/abkit` into
|
|
46
|
+
* `\home\tester\engines\abkit` while the caller had asked for `darwin`.
|
|
47
|
+
*/
|
|
48
|
+
function expandHome(value: string, home: string, platform: NodeJS.Platform): string {
|
|
49
|
+
if (value === '~') return home;
|
|
50
|
+
if (!value.startsWith('~/') && !value.startsWith('~\\')) return value;
|
|
51
|
+
const join = platform === 'win32' ? path.win32.join : path.posix.join;
|
|
52
|
+
return join(home, value.slice(2));
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* The paths that could hold the ABKit host.
|
|
57
|
+
*
|
|
58
|
+
* `browser.webkitPath` names either the host executable or an ABKit engine
|
|
59
|
+
* directory that holds it as `ABHost` (`ABHost.exe` on Windows), so both
|
|
60
|
+
* readings are offered and the caller accepts the first that exists.
|
|
61
|
+
*/
|
|
62
|
+
export function webkitHostCandidates(
|
|
63
|
+
configured: unknown,
|
|
64
|
+
home: string,
|
|
65
|
+
platform: NodeJS.Platform,
|
|
66
|
+
): string[] {
|
|
67
|
+
const join = platform === 'win32' ? path.win32.join : path.posix.join;
|
|
68
|
+
const exe = platform === 'win32' ? 'ABHost.exe' : 'ABHost';
|
|
69
|
+
if (typeof configured === 'string' && configured.trim()) {
|
|
70
|
+
const expanded = expandHome(configured.trim(), home, platform);
|
|
71
|
+
return [expanded, join(expanded, exe)];
|
|
72
|
+
}
|
|
73
|
+
return [join(home, ...DEFAULT_ENGINE_DIR, exe)];
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* The engine the next `browser.open` will use.
|
|
78
|
+
*
|
|
79
|
+
* A config read that fails is NOT treated as "Chromium": the panel would then
|
|
80
|
+
* promise a mirror it cannot deliver. It keeps the documented default (WebKit
|
|
81
|
+
* on) and lets the install check decide.
|
|
82
|
+
*/
|
|
83
|
+
export async function readBrowserEngineState(
|
|
84
|
+
deps: BrowserEngineDeps = {},
|
|
85
|
+
): Promise<BrowserEngineState> {
|
|
86
|
+
const readConfig = deps.readConfig ?? getOmpConfigValue;
|
|
87
|
+
const exists = deps.exists ?? ((file: string) => Bun.file(file).exists());
|
|
88
|
+
const home = deps.home ?? homedir();
|
|
89
|
+
const platform = deps.platform ?? process.platform;
|
|
90
|
+
|
|
91
|
+
const [webkitValue, pathValue] = await Promise.all([
|
|
92
|
+
readConfig('browser.webkit').catch(() => undefined),
|
|
93
|
+
readConfig('browser.webkitPath').catch(() => undefined),
|
|
94
|
+
]);
|
|
95
|
+
const webkit = webkitValue !== false;
|
|
96
|
+
const candidates = webkitHostCandidates(pathValue, home, platform);
|
|
97
|
+
const installed = (
|
|
98
|
+
await Promise.all(candidates.map((file) => exists(file).catch(() => false)))
|
|
99
|
+
).some(Boolean);
|
|
100
|
+
|
|
101
|
+
return { webkit, engineInstalled: installed, effective: webkit && installed ? 'webkit' : 'chromium' };
|
|
102
|
+
}
|
|
@@ -25,6 +25,7 @@ import { ensureReviewSchema } from '@/server/lib/review/schema.server';
|
|
|
25
25
|
import { ensureHarnessSchema } from '@/server/lib/harness/schema.server';
|
|
26
26
|
import { ensureSessionRelationsSchema } from '@/server/lib/sessions/schema.server';
|
|
27
27
|
import { ensurePromptHistorySchema } from '@/server/lib/chat/schema.server';
|
|
28
|
+
import { ensureSessionMcpSchema } from '@/server/lib/mcp/schema.server';
|
|
28
29
|
import { migrateWorkspaceFolderColumns } from '@/shared/lib/workspace/schema-migrations';
|
|
29
30
|
import { migrateSessionStreamStateColumns } from '@/shared/lib/omp/session/schema-migrations';
|
|
30
31
|
|
|
@@ -149,6 +150,9 @@ export async function initSchema(db: DbClient): Promise<void> {
|
|
|
149
150
|
await ensureSessionRelationsSchema(db);
|
|
150
151
|
// The composer's ArrowUp recall: one row per prompt the operator sent.
|
|
151
152
|
await ensurePromptHistorySchema(db);
|
|
153
|
+
// Per-session MCP enablement: read by the spawn path, so it cannot live in
|
|
154
|
+
// the client-owned `session_ui_state` blob.
|
|
155
|
+
await ensureSessionMcpSchema(db);
|
|
152
156
|
await db.exec(`
|
|
153
157
|
CREATE TABLE IF NOT EXISTS files (
|
|
154
158
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The lookup a login-entry launch needs.
|
|
8
|
+
*
|
|
9
|
+
* The bug this pins: launchd starts the server with
|
|
10
|
+
* `/usr/bin:/bin:/usr/sbin:/sbin` (measured — the `dev.kabmo.tray` plist carries
|
|
11
|
+
* no `EnvironmentVariables`), so `Bun.which('npx')` answered null while
|
|
12
|
+
* `/opt/homebrew/bin/npx` was installed. Every `npx`-launched harness read "not
|
|
13
|
+
* installed" on the first boot after login and `ready` after a terminal start.
|
|
14
|
+
*
|
|
15
|
+
* The cases below hand in the environment rather than mutating `Bun.env`, so the
|
|
16
|
+
* suite measures the repair itself and not the runner's PATH.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
import { afterAll, describe, expect, test } from 'bun:test';
|
|
20
|
+
import fs from 'node:fs';
|
|
21
|
+
import os from 'node:os';
|
|
22
|
+
import { join } from 'node:path';
|
|
23
|
+
|
|
24
|
+
import { toolchainPath, whichOnToolchainPath } from '@/server/lib/fs/toolchain-path';
|
|
25
|
+
|
|
26
|
+
const home = fs.mkdtempSync(join(os.tmpdir(), 'kabmo-toolchain-'));
|
|
27
|
+
const bunBin = join(home, '.bun', 'bin');
|
|
28
|
+
fs.mkdirSync(bunBin, { recursive: true });
|
|
29
|
+
const fakeTool = join(bunBin, 'kabmo-fake-tool');
|
|
30
|
+
fs.writeFileSync(fakeTool, '#!/bin/sh\nexit 0\n', { mode: 0o755 });
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* A POSIX home for the string-shape cases.
|
|
34
|
+
*
|
|
35
|
+
* They ask for a `linux` PATH, so the home they hand in has to be a POSIX one:
|
|
36
|
+
* `os.tmpdir()` is `C:\Users\…` on the Windows gate, and comparing the answer
|
|
37
|
+
* against a host-joined expectation there measured the runner's separators
|
|
38
|
+
* rather than the repair.
|
|
39
|
+
*/
|
|
40
|
+
const POSIX_HOME = '/home/tester';
|
|
41
|
+
|
|
42
|
+
afterAll(() => {
|
|
43
|
+
fs.rmSync(home, { recursive: true, force: true });
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
describe('toolchainPath', () => {
|
|
47
|
+
test('keeps the inherited order and appends what a GUI launch never had', () => {
|
|
48
|
+
const path = toolchainPath({ PATH: '/usr/bin:/bin', HOME: POSIX_HOME }, 'linux');
|
|
49
|
+
const entries = path.split(':');
|
|
50
|
+
expect(entries.slice(0, 2)).toEqual(['/usr/bin', '/bin']);
|
|
51
|
+
expect(entries).toContain('/home/tester/.bun/bin');
|
|
52
|
+
expect(entries).toContain('/opt/homebrew/bin');
|
|
53
|
+
expect(entries).toContain('/usr/local/bin');
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
test('does not append an entry the inherited PATH already names', () => {
|
|
57
|
+
const path = toolchainPath({ PATH: '/opt/homebrew/bin:/usr/bin', HOME: POSIX_HOME }, 'linux');
|
|
58
|
+
expect(path.split(':').filter((entry) => entry === '/opt/homebrew/bin')).toHaveLength(1);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
test('a missing PATH becomes the fallback list, not an empty search path', () => {
|
|
62
|
+
const path = toolchainPath({ HOME: POSIX_HOME }, 'linux');
|
|
63
|
+
expect(path.split(':')).toContain('/home/tester/.bun/bin');
|
|
64
|
+
expect(path.split(':')).toContain('/usr/bin');
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
test('Windows is left alone: a GUI launch there inherits the user environment', () => {
|
|
68
|
+
expect(toolchainPath({ PATH: 'C:\\Windows\\system32' }, 'win32')).toBe('C:\\Windows\\system32');
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
describe('whichOnToolchainPath', () => {
|
|
73
|
+
test.skipIf(process.platform === 'win32')(
|
|
74
|
+
'finds a binary that only exists in a toolchain directory',
|
|
75
|
+
() => {
|
|
76
|
+
// The launchd shape: the inherited PATH cannot see `~/.bun/bin`.
|
|
77
|
+
const env = { PATH: '/usr/bin:/bin', HOME: home };
|
|
78
|
+
expect(Bun.which('kabmo-fake-tool', { PATH: env.PATH })).toBeNull();
|
|
79
|
+
expect(whichOnToolchainPath('kabmo-fake-tool', env, 'linux')).toBe(fakeTool);
|
|
80
|
+
},
|
|
81
|
+
);
|
|
82
|
+
|
|
83
|
+
test('a binary nowhere the user shell would look is still null', () => {
|
|
84
|
+
expect(whichOnToolchainPath('kabmo-definitely-missing-xyz', { PATH: '/usr/bin:/bin', HOME: home }, 'linux'))
|
|
85
|
+
.toBeNull();
|
|
86
|
+
});
|
|
87
|
+
});
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Looking a binary up the way a SPAWN will find it.
|
|
8
|
+
*
|
|
9
|
+
* A login-entry launch hands the server a minimal PATH. Measured on this
|
|
10
|
+
* machine: `~/Library/LaunchAgents/dev.kabmo.tray.plist` carries no
|
|
11
|
+
* `EnvironmentVariables`, so launchd's default `/usr/bin:/bin:/usr/sbin:/sbin`
|
|
12
|
+
* is what the server searched — `Bun.which('npx')` answered null while
|
|
13
|
+
* `/opt/homebrew/bin/npx` and `~/.bun/bin/omp` were installed. Every harness
|
|
14
|
+
* whose launch line starts with `npx` therefore read "not installed" on the
|
|
15
|
+
* first boot after login, and the same build answered `ready` when Kabmo was
|
|
16
|
+
* started from a terminal (which inherits the shell's PATH). A restart spawned
|
|
17
|
+
* BY that server inherited the same minimal PATH, so it did not repair it.
|
|
18
|
+
*
|
|
19
|
+
* The spawn side already repairs this (`withToolchainPath`, used by the ACP
|
|
20
|
+
* stdio transport), which is why "not installed" and "runs fine" could both be
|
|
21
|
+
* true. This is the same repair for the RESOLUTION side, so a lookup here
|
|
22
|
+
* answers what `Bun.which` answers in the user's own shell.
|
|
23
|
+
*
|
|
24
|
+
* `env`/`platform` are parameters for the reason `childEnv` takes them: the
|
|
25
|
+
* repair is only testable if a suite can hand in a PATH that lacks the
|
|
26
|
+
* toolchain directories.
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
import { withToolchainPath } from '@kabmo-labs/kabmo-sdk';
|
|
30
|
+
|
|
31
|
+
/** The PATH a lookup (and a child) should search: the inherited one, repaired. */
|
|
32
|
+
export function toolchainPath(
|
|
33
|
+
env: Record<string, string | undefined> = Bun.env,
|
|
34
|
+
platform: string = process.platform,
|
|
35
|
+
): string {
|
|
36
|
+
return withToolchainPath(env, platform).PATH ?? '';
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* `Bun.which` over the repaired PATH. Null when the binary is nowhere the
|
|
41
|
+
* user's shell would look either.
|
|
42
|
+
*/
|
|
43
|
+
export function whichOnToolchainPath(
|
|
44
|
+
binary: string,
|
|
45
|
+
env: Record<string, string | undefined> = Bun.env,
|
|
46
|
+
platform: string = process.platform,
|
|
47
|
+
): string | null {
|
|
48
|
+
return Bun.which(binary, { PATH: toolchainPath(env, platform) });
|
|
49
|
+
}
|
|
@@ -159,7 +159,15 @@ export interface AcpMcpServerHttp {
|
|
|
159
159
|
headers: Array<{ name: string; value: string }>;
|
|
160
160
|
}
|
|
161
161
|
|
|
162
|
-
|
|
162
|
+
/** Legacy SSE transport; ACP carries it as its own typed variant. */
|
|
163
|
+
export interface AcpMcpServerSse {
|
|
164
|
+
type: 'sse';
|
|
165
|
+
name: string;
|
|
166
|
+
url: string;
|
|
167
|
+
headers: Array<{ name: string; value: string }>;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
export type AcpMcpServer = AcpMcpServerStdio | AcpMcpServerHttp | AcpMcpServerSse;
|
|
163
171
|
|
|
164
172
|
export interface AcpSessionNewResult {
|
|
165
173
|
sessionId: string;
|
|
@@ -45,6 +45,7 @@ import { blockedProbe, probeHarness } from '@/server/lib/harness/launch';
|
|
|
45
45
|
import { HARNESS_LAUNCH, harnessRequirementMet, type HarnessLaunch } from '@/server/lib/harness/launch-table';
|
|
46
46
|
import { customLaunch } from '@/server/lib/harness/custom.server';
|
|
47
47
|
import { resolveOmpBin } from '@/server/lib/omp/core/cli';
|
|
48
|
+
import { whichOnToolchainPath } from '@/server/lib/fs/toolchain-path';
|
|
48
49
|
import { rememberProbe } from '@/server/lib/harness/probe-cache.server';
|
|
49
50
|
import { harnessDescriptor, harnessIds, type HarnessId } from '@/shared/lib/harness/catalog';
|
|
50
51
|
import { harnessEnabled } from '@/shared/lib/harness/enabled';
|
|
@@ -80,8 +81,8 @@ export function commandAvailable(id: HarnessId, config?: HarnessConfig): boolean
|
|
|
80
81
|
// An adapter can need a binary it SPAWNS rather than execs: the zcode bridge
|
|
81
82
|
// starts `zcode app-server --stdio`, so `npx` being present says nothing.
|
|
82
83
|
if (!harnessRequirementMet(launch?.requires, launch?.env)) return false;
|
|
83
|
-
if (binary === 'npx') return Boolean(
|
|
84
|
-
return Boolean(
|
|
84
|
+
if (binary === 'npx') return Boolean(whichOnToolchainPath('npx') ?? whichOnToolchainPath('node'));
|
|
85
|
+
return Boolean(whichOnToolchainPath(binary));
|
|
85
86
|
}
|
|
86
87
|
|
|
87
88
|
/**
|
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
|
|
15
15
|
import { existsSync } from 'node:fs';
|
|
16
16
|
import { homedir } from 'node:os';
|
|
17
|
+
import { whichOnToolchainPath } from '@/server/lib/fs/toolchain-path';
|
|
17
18
|
import type { HarnessId } from '@/shared/lib/harness/catalog';
|
|
18
19
|
|
|
19
20
|
/** One harness's launch configuration. */
|
|
@@ -54,7 +55,7 @@ function resolvable(value: string): boolean {
|
|
|
54
55
|
if (trimmed.includes('/') || trimmed.includes('\\')) {
|
|
55
56
|
return existsSync(trimmed.replace(/^~(?=[/\\])/, homedir()));
|
|
56
57
|
}
|
|
57
|
-
return Boolean(
|
|
58
|
+
return Boolean(whichOnToolchainPath(trimmed));
|
|
58
59
|
}
|
|
59
60
|
|
|
60
61
|
/**
|
|
@@ -76,7 +77,7 @@ export function harnessRequirementMet(
|
|
|
76
77
|
? (env?.[requirement.env] ?? Bun.env[requirement.env] ?? '').trim()
|
|
77
78
|
: '';
|
|
78
79
|
if (explicit) return resolvable(explicit);
|
|
79
|
-
if (
|
|
80
|
+
if (whichOnToolchainPath(requirement.binary)) return true;
|
|
80
81
|
return (requirement.bundled ?? []).some(resolvable);
|
|
81
82
|
}
|
|
82
83
|
|
|
@@ -35,6 +35,7 @@ import { emitRealtimeSignal } from '@/server/lib/realtime/signals.server';
|
|
|
35
35
|
import { harnessDescriptor, type HarnessId } from '@/shared/lib/harness/catalog';
|
|
36
36
|
import { mcpDelivery } from '@/shared/lib/harness/mcp-facts';
|
|
37
37
|
import { mcpServersFor, toAcpMcpServers } from '@/server/lib/mcp/registry.server';
|
|
38
|
+
import { readSessionMcpOverrides } from '@/server/lib/mcp/session-state.server';
|
|
38
39
|
import { ensureCustomHarnesses } from '@/server/lib/harness/custom.server';
|
|
39
40
|
import type { HarnessConfig } from '@/shared/lib/harness/config';
|
|
40
41
|
import type { AcpProcess } from '@/server/lib/harness/acp/client';
|
|
@@ -130,8 +131,11 @@ export async function openAcpSession(
|
|
|
130
131
|
// The MCP list is read per SPAWN, not cached: a server added in Settings must
|
|
131
132
|
// reach the next chat without a restart. A harness whose delivery is a file
|
|
132
133
|
// (omp's RPC mode) is not an ACP session, so this branch is the ACP contract.
|
|
134
|
+
// The session's own overrides are applied here, which is what makes a toggle
|
|
135
|
+
// per-session: the list is an argument to `session/new|load`, not a file.
|
|
136
|
+
const overrides = await readSessionMcpOverrides(request.sessionId);
|
|
133
137
|
const mcpServers = mcpDelivery(request.harness) === 'acp'
|
|
134
|
-
? toAcpMcpServers(await mcpServersFor(request.cwd))
|
|
138
|
+
? toAcpMcpServers(await mcpServersFor(request.cwd, { overrides }))
|
|
135
139
|
: [];
|
|
136
140
|
// Built here rather than behind a factory in the session module: this is the
|
|
137
141
|
// only place a session is constructed, and the handshake it runs (load vs
|
|
@@ -28,6 +28,7 @@
|
|
|
28
28
|
*/
|
|
29
29
|
|
|
30
30
|
import { probeWithConfig } from '@/server/lib/harness/auto-probe.server';
|
|
31
|
+
import { whichOnToolchainPath } from '@/server/lib/fs/toolchain-path';
|
|
31
32
|
import { forgetProbe, rememberProbe } from '@/server/lib/harness/probe-cache.server';
|
|
32
33
|
import { forgetCliVersion } from '@/server/lib/harness/update-state.server';
|
|
33
34
|
import { loadHarnessConfig, saveHarnessConfig } from '@/server/lib/harness/config.server';
|
|
@@ -95,7 +96,7 @@ async function pointAtInstalledAdapter(
|
|
|
95
96
|
facts,
|
|
96
97
|
steps,
|
|
97
98
|
config.command,
|
|
98
|
-
facts.agentBin ? Boolean(
|
|
99
|
+
facts.agentBin ? Boolean(whichOnToolchainPath(facts.agentBin)) : false,
|
|
99
100
|
);
|
|
100
101
|
if (!bin) return null;
|
|
101
102
|
await saveHarnessConfig(harness, { ...config, command: bin });
|
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
*/
|
|
24
24
|
|
|
25
25
|
import { commandAvailable } from '@/server/lib/harness/auto-probe.server';
|
|
26
|
+
import { whichOnToolchainPath } from '@/server/lib/fs/toolchain-path';
|
|
26
27
|
import { loadHarnessConfig } from '@/server/lib/harness/config.server';
|
|
27
28
|
import { fetchNpmLatest } from '@/server/lib/updates/npm';
|
|
28
29
|
import type { HarnessId } from '@/shared/lib/harness/catalog';
|
|
@@ -99,8 +100,11 @@ export async function cliVersion(bin: string): Promise<string | null> {
|
|
|
99
100
|
if (cached && Date.now() - cached.at < CLI_VERSION_TTL_MS) return cached.version;
|
|
100
101
|
let version: string | null = null;
|
|
101
102
|
try {
|
|
102
|
-
|
|
103
|
-
|
|
103
|
+
// Resolved, then executed by its absolute path: a login-entry launch has a
|
|
104
|
+
// minimal PATH, so a bare name passes this check and fails the spawn.
|
|
105
|
+
const resolved = whichOnToolchainPath(bin);
|
|
106
|
+
if (resolved) {
|
|
107
|
+
const proc = Bun.spawn({ cmd: [resolved, '--version'], stdout: 'pipe', stderr: 'pipe', timeout: 5000 });
|
|
104
108
|
const text = (await new Response(proc.stdout).text()) + (await new Response(proc.stderr).text());
|
|
105
109
|
await proc.exited;
|
|
106
110
|
// The first version-shaped token: `2.1.318 (Claude Code)`, `codex-cli 0.166.0`.
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* A real connection probe for one session's MCP server, cached briefly.
|
|
8
|
+
*
|
|
9
|
+
* omp publishes no MCP state over RPC: `mcp:connection-status` is an internal
|
|
10
|
+
* TUI event bus, `/mcp list` over RPC prints the configured state, and
|
|
11
|
+
* `get_state.dumpTools` carries only the built-in tools (measured on 18.20.0 —
|
|
12
|
+
* a live codegraph server mounted no `mcp__` entry there). The one honest
|
|
13
|
+
* signal is a handshake, which Kabmo already implements for the settings pane
|
|
14
|
+
* (`testMcpServer`): spawn the configured command (or POST the endpoint), run
|
|
15
|
+
* `initialize` → `tools/list`, and report what came back.
|
|
16
|
+
*
|
|
17
|
+
* The probe is ON DEMAND — the navbar's info control — because it starts a
|
|
18
|
+
* second instance of the server. Results are cached per session+server for a
|
|
19
|
+
* minute so reopening the popover does not spawn it again.
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
import { nativeToServerItem } from '@/server/lib/omp/config/mcp';
|
|
23
|
+
import { testMcpServer } from '@/server/lib/omp/config/mcp-test';
|
|
24
|
+
import type { McpServerEntry } from '@/server/lib/mcp/registry.server';
|
|
25
|
+
import type { McpProbeResult } from '@/shared/types';
|
|
26
|
+
|
|
27
|
+
const CACHE_TTL_MS = 60_000;
|
|
28
|
+
const cache = new Map<string, McpProbeResult>();
|
|
29
|
+
|
|
30
|
+
function cacheKey(sessionId: string, name: string): string {
|
|
31
|
+
return `${sessionId}\u0000${name}`;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** The cached answer for this session+server, or undefined when stale/absent. */
|
|
35
|
+
export function cachedMcpProbe(sessionId: string, name: string): McpProbeResult | undefined {
|
|
36
|
+
const key = cacheKey(sessionId, name);
|
|
37
|
+
const hit = cache.get(key);
|
|
38
|
+
if (!hit) return undefined;
|
|
39
|
+
if (Date.now() - hit.checkedAt > CACHE_TTL_MS) {
|
|
40
|
+
cache.delete(key);
|
|
41
|
+
return undefined;
|
|
42
|
+
}
|
|
43
|
+
return hit;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** Run a real handshake and cache the answer. */
|
|
47
|
+
export async function probeMcpServer(
|
|
48
|
+
sessionId: string,
|
|
49
|
+
entry: McpServerEntry,
|
|
50
|
+
cwd: string,
|
|
51
|
+
): Promise<McpProbeResult> {
|
|
52
|
+
const item = nativeToServerItem(entry.name, entry.config, 0, true);
|
|
53
|
+
// A spawn failure (ENOENT, a refused endpoint) is a RESULT, not a 500: the
|
|
54
|
+
// status icon has to say "failed" with the reason.
|
|
55
|
+
const result = await testMcpServer({ server: item, cwd }).catch((cause: unknown) => ({
|
|
56
|
+
ok: false,
|
|
57
|
+
transport: item.transport,
|
|
58
|
+
toolCount: 0,
|
|
59
|
+
durationMs: 0,
|
|
60
|
+
error: cause instanceof Error ? cause.message : String(cause),
|
|
61
|
+
}));
|
|
62
|
+
const probe: McpProbeResult = {
|
|
63
|
+
ok: result.ok,
|
|
64
|
+
...(result.error ? { error: result.error } : {}),
|
|
65
|
+
toolCount: result.toolCount ?? 0,
|
|
66
|
+
durationMs: result.durationMs,
|
|
67
|
+
checkedAt: Date.now(),
|
|
68
|
+
};
|
|
69
|
+
cache.set(cacheKey(sessionId, entry.name), probe);
|
|
70
|
+
return probe;
|
|
71
|
+
}
|