@kabmo-labs/kabmo 0.30.1 → 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-bwhhehnh.js → index-r3bhgvkt.js} +772 -773
- 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/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
|
@@ -6,35 +6,35 @@
|
|
|
6
6
|
/**
|
|
7
7
|
* Native OMP MCP config access — faithful adaptation of omp-web/lib/omp/mcp-config.ts.
|
|
8
8
|
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
9
|
+
* The file is omp's own `mcp.json` (user: `~/.omp/agent/mcp.json`, project:
|
|
10
|
+
* `.omp/mcp.json` and its candidates). Every field the schema defines is
|
|
11
|
+
* carried through: transport (`type`), `command`/`args`/`env`/`cwd` for stdio,
|
|
12
|
+
* `url`/`headers` for http and sse, plus `timeout`, `requestIdFormat`,
|
|
13
|
+
* `instructions`, `auth` and `oauth`.
|
|
13
14
|
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
15
|
+
* Enablement is omp's own model, not a Kabmo invention:
|
|
16
|
+
* - `disabledServers` (user file) is the highest-precedence denylist;
|
|
17
|
+
* - `enabledServers` (user file) overrides a source's `enabled: false`;
|
|
18
|
+
* - a server entry's own `enabled: false` disables it.
|
|
19
|
+
* The writer (`mcp-write.ts`) records all three; this module only reads them.
|
|
17
20
|
*/
|
|
18
21
|
|
|
19
|
-
import { join, resolve } from 'path';
|
|
20
|
-
import {
|
|
21
|
-
import {
|
|
22
|
-
import {
|
|
22
|
+
import { dirname, join, resolve } from 'path';
|
|
23
|
+
import { pathExists } from '@/server/lib/omp/core/paths';
|
|
24
|
+
import { getOmpConfigPath } from '@/server/lib/omp/config/yaml';
|
|
25
|
+
import type { McpAuthConfig, McpOAuthConfig, McpServerItem, McpTransport } from '@/shared/types';
|
|
23
26
|
import { isRecord } from '@/shared/lib/util/guards';
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
const SERVER_NAME = /^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/;
|
|
27
|
+
import { REDACTED_SENTINEL, recordToRows } from '@/shared/lib/mcp/key-value';
|
|
28
|
+
import { MAX_MCP_CONFIG_BYTES, stringsIn, userMcpConfigPath, type McpFile, type McpServer } from '@/server/lib/omp/config/mcp-shared';
|
|
27
29
|
|
|
28
30
|
/** Project-level config candidates, in omp preference order. */
|
|
29
31
|
export const MCP_FILENAMES = [join('.omp', 'mcp.json'), join('.omp', '.mcp.json'), 'mcp.json', '.mcp.json'];
|
|
30
32
|
|
|
31
|
-
export type McpServer = Record<string, unknown>;
|
|
32
|
-
export type McpFile = Record<string, unknown> & { mcpServers?: Record<string, McpServer> };
|
|
33
|
-
|
|
34
33
|
export interface McpUserConfig {
|
|
35
34
|
path: string;
|
|
36
35
|
servers: Array<{ name: string; config: McpServer }>;
|
|
37
36
|
disabledServers: string[];
|
|
37
|
+
enabledServers: string[];
|
|
38
38
|
error?: string;
|
|
39
39
|
}
|
|
40
40
|
|
|
@@ -45,7 +45,9 @@ function serverEntries(config: McpFile): Array<{ name: string; config: McpServer
|
|
|
45
45
|
}
|
|
46
46
|
|
|
47
47
|
async function readMcpFile(path: string): Promise<McpUserConfig> {
|
|
48
|
-
if (!(await Bun.file(path).exists()))
|
|
48
|
+
if (!(await Bun.file(path).exists())) {
|
|
49
|
+
return { path, servers: [], disabledServers: [], enabledServers: [] };
|
|
50
|
+
}
|
|
49
51
|
try {
|
|
50
52
|
const file = Bun.file(path);
|
|
51
53
|
if ((await file.stat()).size > MAX_MCP_CONFIG_BYTES) throw new Error('configuration is too large to inspect');
|
|
@@ -55,18 +57,42 @@ async function readMcpFile(path: string): Promise<McpUserConfig> {
|
|
|
55
57
|
return {
|
|
56
58
|
path,
|
|
57
59
|
servers: serverEntries(parsed as McpFile),
|
|
58
|
-
disabledServers:
|
|
59
|
-
|
|
60
|
-
: [],
|
|
60
|
+
disabledServers: stringsIn(parsed.disabledServers),
|
|
61
|
+
enabledServers: stringsIn(parsed.enabledServers),
|
|
61
62
|
};
|
|
62
63
|
} catch (error) {
|
|
63
|
-
return {
|
|
64
|
+
return {
|
|
65
|
+
path,
|
|
66
|
+
servers: [],
|
|
67
|
+
disabledServers: [],
|
|
68
|
+
enabledServers: [],
|
|
69
|
+
error: error instanceof Error ? error.message : String(error),
|
|
70
|
+
};
|
|
64
71
|
}
|
|
65
72
|
}
|
|
66
73
|
|
|
67
|
-
/**
|
|
68
|
-
|
|
69
|
-
|
|
74
|
+
/**
|
|
75
|
+
* Read the user scope. omp discovers BOTH `~/.omp/agent/mcp.json` and
|
|
76
|
+
* `~/.omp/agent/.mcp.json`, so a server declared only in the dot-file is live
|
|
77
|
+
* for a session and must be visible here too; `mcp.json` wins on a name clash,
|
|
78
|
+
* and the two enablement lists are unioned. A malformed file is reported on the
|
|
79
|
+
* result rather than hiding the other file's servers.
|
|
80
|
+
*/
|
|
81
|
+
export async function readUserMcpConfig(path = userMcpConfigPath()): Promise<McpUserConfig> {
|
|
82
|
+
const primary = await readMcpFile(path);
|
|
83
|
+
const secondaryPath = join(dirname(path), '.mcp.json');
|
|
84
|
+
if (secondaryPath === path || !(await Bun.file(secondaryPath).exists())) return primary;
|
|
85
|
+
const secondary = await readMcpFile(secondaryPath);
|
|
86
|
+
const names = new Set(primary.servers.map((entry) => entry.name));
|
|
87
|
+
return {
|
|
88
|
+
path,
|
|
89
|
+
servers: [...primary.servers, ...secondary.servers.filter((entry) => !names.has(entry.name))].sort((a, b) =>
|
|
90
|
+
a.name.localeCompare(b.name),
|
|
91
|
+
),
|
|
92
|
+
disabledServers: [...new Set([...primary.disabledServers, ...secondary.disabledServers])],
|
|
93
|
+
enabledServers: [...new Set([...primary.enabledServers, ...secondary.enabledServers])],
|
|
94
|
+
...(primary.error ?? secondary.error ? { error: primary.error ?? secondary.error } : {}),
|
|
95
|
+
};
|
|
70
96
|
}
|
|
71
97
|
|
|
72
98
|
/** Resolve a project's config file: first existing candidate, else `.omp/mcp.json`.
|
|
@@ -81,89 +107,60 @@ export async function resolveProjectMcpConfig(projectRoot: string): Promise<{ ro
|
|
|
81
107
|
return { root, path: join(root, MCP_FILENAMES[0]) };
|
|
82
108
|
}
|
|
83
109
|
|
|
84
|
-
/**
|
|
110
|
+
/**
|
|
111
|
+
* Read the project scope as omp does: every candidate that exists, in
|
|
112
|
+
* preference order, first name wins. `resolveProjectMcpConfig` stays the WRITE
|
|
113
|
+
* target (the first existing candidate), because a write has to pick one file.
|
|
114
|
+
*/
|
|
85
115
|
export async function readProjectMcpConfig(projectRoot: string): Promise<McpUserConfig> {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
const servers = { ...(config.mcpServers ?? {}) };
|
|
105
|
-
// Capture the old entry before any rename: a rename must retain
|
|
106
|
-
// credentials the browser intentionally redacts from its payload.
|
|
107
|
-
const previous = servers[previousName ?? name];
|
|
108
|
-
if (previousName && previousName !== name) delete servers[previousName];
|
|
109
|
-
// The browser never receives existing credentials. Preserve them when an
|
|
110
|
-
// edited server omits those fields, rather than deleting them on save.
|
|
111
|
-
servers[name] = {
|
|
112
|
-
...server,
|
|
113
|
-
...(previous?.env !== undefined && server.env === undefined ? { env: previous.env } : {}),
|
|
114
|
-
...(previous?.headers !== undefined && server.headers === undefined ? { headers: previous.headers } : {}),
|
|
115
|
-
};
|
|
116
|
-
await writeConfigFile(path, { ...config, mcpServers: servers });
|
|
117
|
-
return { path };
|
|
118
|
-
});
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
async function deleteServerAt(path: string, name: string): Promise<{ path: string }> {
|
|
122
|
-
if (!(await Bun.file(path).exists())) throw new Error('MCP server was not found');
|
|
123
|
-
return withConfigLock(path, async () => {
|
|
124
|
-
const config = await readConfigFile(path);
|
|
125
|
-
const servers = { ...(config.mcpServers ?? {}) };
|
|
126
|
-
if (!(name in servers)) throw new Error('MCP server was not found');
|
|
127
|
-
delete servers[name];
|
|
128
|
-
await writeConfigFile(path, { ...config, mcpServers: servers });
|
|
129
|
-
return { path };
|
|
130
|
-
});
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
/** Atomic read-modify-write of one server entry in the user mcp.json. */
|
|
134
|
-
export async function writeUserMcpServer(
|
|
135
|
-
name: string,
|
|
136
|
-
server: McpServer,
|
|
137
|
-
path = join(getAgentDir(), 'mcp.json'),
|
|
138
|
-
previousName?: string,
|
|
139
|
-
): Promise<{ path: string }> {
|
|
140
|
-
if (!SERVER_NAME.test(name)) throw new Error('Invalid server name');
|
|
141
|
-
if (!isRecord(server)) throw new Error('Server configuration must be an object');
|
|
142
|
-
return writeServerAt(path, name, server, previousName);
|
|
116
|
+
const { root, path } = await resolveProjectMcpConfig(projectRoot);
|
|
117
|
+
const merged = await readMcpFile(path);
|
|
118
|
+
const names = new Set(merged.servers.map((entry) => entry.name));
|
|
119
|
+
for (const filename of MCP_FILENAMES.slice(1)) {
|
|
120
|
+
const candidate = join(root, filename);
|
|
121
|
+
if (candidate === path || !(await pathExists(candidate))) continue;
|
|
122
|
+
const extra = await readMcpFile(candidate);
|
|
123
|
+
for (const entry of extra.servers) {
|
|
124
|
+
if (names.has(entry.name)) continue;
|
|
125
|
+
names.add(entry.name);
|
|
126
|
+
merged.servers.push(entry);
|
|
127
|
+
}
|
|
128
|
+
merged.disabledServers.push(...extra.disabledServers);
|
|
129
|
+
merged.enabledServers.push(...extra.enabledServers);
|
|
130
|
+
if (!merged.error && extra.error) merged.error = extra.error;
|
|
131
|
+
}
|
|
132
|
+
merged.servers.sort((a, b) => a.name.localeCompare(b.name));
|
|
133
|
+
return merged;
|
|
143
134
|
}
|
|
144
135
|
|
|
145
|
-
/**
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
136
|
+
/**
|
|
137
|
+
* omp's `mcp.enableProjectConfig` (default true) — the switch that decides
|
|
138
|
+
* whether a project's `mcp.json` is discovered at all. Read from
|
|
139
|
+
* `~/.omp/agent/config.yml`; an unreadable file keeps the default rather than
|
|
140
|
+
* silently dropping every project server.
|
|
141
|
+
*/
|
|
142
|
+
export async function isProjectMcpConfigEnabled(): Promise<boolean> {
|
|
143
|
+
try {
|
|
144
|
+
const file = Bun.file(getOmpConfigPath());
|
|
145
|
+
if (!(await file.exists())) return true;
|
|
146
|
+
const parsed: unknown = Bun.YAML.parse(await file.text());
|
|
147
|
+
if (!isRecord(parsed) || !isRecord(parsed.mcp)) return true;
|
|
148
|
+
return parsed.mcp.enableProjectConfig !== false;
|
|
149
|
+
} catch {
|
|
150
|
+
return true;
|
|
151
|
+
}
|
|
149
152
|
}
|
|
150
153
|
|
|
151
|
-
/**
|
|
152
|
-
export
|
|
153
|
-
projectRoot: string,
|
|
154
|
+
/** omp's enablement precedence: denylist, then the entry's own flag, then the allowlist. */
|
|
155
|
+
export function isServerEnabled(
|
|
154
156
|
name: string,
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
if (
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
/** Atomic removal of one server entry from a project's mcp.json. */
|
|
164
|
-
export async function deleteProjectMcpServer(projectRoot: string, name: string): Promise<{ path: string }> {
|
|
165
|
-
if (!SERVER_NAME.test(name)) throw new Error('Invalid server name');
|
|
166
|
-
return deleteServerAt((await resolveProjectMcpConfig(projectRoot)).path, name);
|
|
157
|
+
config: McpServer,
|
|
158
|
+
disabledServers: readonly string[],
|
|
159
|
+
enabledServers: readonly string[],
|
|
160
|
+
): boolean {
|
|
161
|
+
if (disabledServers.includes(name)) return false;
|
|
162
|
+
if (config.enabled === false) return enabledServers.includes(name);
|
|
163
|
+
return true;
|
|
167
164
|
}
|
|
168
165
|
|
|
169
166
|
/** Convert a native omp server config into Kabmo McpServerItem shape.
|
|
@@ -174,32 +171,55 @@ export function nativeToServerItem(
|
|
|
174
171
|
index: number,
|
|
175
172
|
enabled: boolean,
|
|
176
173
|
project?: { path: string },
|
|
177
|
-
) {
|
|
178
|
-
const
|
|
179
|
-
|
|
180
|
-
|
|
174
|
+
): McpServerItem {
|
|
175
|
+
const transport: McpTransport = config.type === 'sse'
|
|
176
|
+
? 'sse'
|
|
177
|
+
: typeof config.url === 'string'
|
|
178
|
+
? 'http'
|
|
179
|
+
: 'stdio';
|
|
180
|
+
const isLink = transport !== 'stdio';
|
|
181
|
+
const args = Array.isArray(config.args) ? config.args.map(String) : [];
|
|
182
|
+
const item: McpServerItem = {
|
|
181
183
|
id: `${project ? 'omp-project' : 'omp-user'}-${name}`,
|
|
182
184
|
name,
|
|
183
|
-
scope: project ?
|
|
185
|
+
scope: project ? 'this-project' : 'every-project',
|
|
184
186
|
...(project ? { projectPath: project.path } : {}),
|
|
185
187
|
enabled,
|
|
186
|
-
|
|
187
|
-
commandArgs:
|
|
188
|
+
transport,
|
|
189
|
+
commandArgs: isLink
|
|
188
190
|
? [String(config.url)]
|
|
189
|
-
: [String(config.command ?? ''), ...
|
|
190
|
-
linkUrl:
|
|
191
|
-
envVars:
|
|
192
|
-
|
|
193
|
-
key,
|
|
194
|
-
value: typeof value === 'string' ? value : String(value),
|
|
195
|
-
})),
|
|
191
|
+
: [String(config.command ?? ''), ...args].filter(Boolean),
|
|
192
|
+
linkUrl: isLink ? String(config.url) : undefined,
|
|
193
|
+
envVars: recordToRows(isRecord(config.env) ? config.env : {}, `env-${index}`),
|
|
194
|
+
headers: recordToRows(isRecord(config.headers) ? config.headers : {}, `header-${index}`),
|
|
196
195
|
status: undefined,
|
|
197
196
|
};
|
|
197
|
+
if (typeof config.cwd === 'string') item.cwd = config.cwd;
|
|
198
|
+
if (typeof config.timeout === 'number') item.timeout = config.timeout;
|
|
199
|
+
if (config.requestIdFormat === 'string' || config.requestIdFormat === 'number') {
|
|
200
|
+
item.requestIdFormat = config.requestIdFormat;
|
|
201
|
+
}
|
|
202
|
+
if (typeof config.instructions === 'boolean') item.instructions = config.instructions;
|
|
203
|
+
if (isRecord(config.auth)) item.auth = config.auth as unknown as McpAuthConfig;
|
|
204
|
+
if (isRecord(config.oauth)) item.oauth = config.oauth as unknown as McpOAuthConfig;
|
|
205
|
+
return item;
|
|
198
206
|
}
|
|
199
207
|
|
|
200
|
-
const SENSITIVE_KEY = /(key|token|secret|password|credential)/i;
|
|
208
|
+
const SENSITIVE_KEY = /(key|token|secret|password|credential|auth|cookie)/i;
|
|
201
209
|
|
|
202
210
|
/** Redact env var values for display — the browser never sees raw credentials. */
|
|
203
211
|
export function redactEnvVars<T extends { key: string; value: string }>(envVars: T[]): T[] {
|
|
204
|
-
return envVars.map((item) => (SENSITIVE_KEY.test(item.key) ? { ...item, value:
|
|
212
|
+
return envVars.map((item) => (SENSITIVE_KEY.test(item.key) ? { ...item, value: REDACTED_SENTINEL } : item));
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/** Redact every credential-bearing field of a server row before it leaves the server. */
|
|
216
|
+
export function redactServerItem(item: McpServerItem): McpServerItem {
|
|
217
|
+
const redacted: McpServerItem = {
|
|
218
|
+
...item,
|
|
219
|
+
envVars: redactEnvVars(item.envVars ?? []),
|
|
220
|
+
headers: redactEnvVars(item.headers ?? []),
|
|
221
|
+
};
|
|
222
|
+
if (item.auth?.clientSecret) redacted.auth = { ...item.auth, clientSecret: REDACTED_SENTINEL };
|
|
223
|
+
if (item.oauth?.clientSecret) redacted.oauth = { ...item.oauth, clientSecret: REDACTED_SENTINEL };
|
|
224
|
+
return redacted;
|
|
205
225
|
}
|
|
@@ -13,8 +13,7 @@
|
|
|
13
13
|
*/
|
|
14
14
|
|
|
15
15
|
import { existsSync } from 'fs';
|
|
16
|
-
import {
|
|
17
|
-
import { delimiter, join } from 'path';
|
|
16
|
+
import { whichOnToolchainPath } from '@/server/lib/fs/toolchain-path';
|
|
18
17
|
|
|
19
18
|
let cachedBin: string | null = null;
|
|
20
19
|
let binMissAt = 0;
|
|
@@ -41,18 +40,9 @@ function probeOmpBin(): string | null {
|
|
|
41
40
|
const override = Bun.env.KABMO_OMP_BIN ?? Bun.env.OMPCHAMBER_OMP_BIN;
|
|
42
41
|
if (override) return existsSync(override) ? override : null;
|
|
43
42
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
// GUI-launched processes often miss homebrew/bun dirs in PATH; probe the
|
|
48
|
-
// usual install locations before giving up.
|
|
49
|
-
const fallbackPath = [
|
|
50
|
-
'/opt/homebrew/bin',
|
|
51
|
-
'/usr/local/bin',
|
|
52
|
-
join(homedir(), '.bun', 'bin'),
|
|
53
|
-
join(homedir(), '.local', 'bin'),
|
|
54
|
-
].join(delimiter);
|
|
55
|
-
return Bun.which(BIN_NAME, { PATH: fallbackPath });
|
|
43
|
+
// The inherited PATH, repaired: a login-entry launch (launchd, XDG autostart)
|
|
44
|
+
// never had homebrew or `~/.bun/bin`, which is where omp actually lives.
|
|
45
|
+
return whichOnToolchainPath(BIN_NAME);
|
|
56
46
|
}
|
|
57
47
|
|
|
58
48
|
/** Resolve the omp binary: KABMO_OMP_BIN override, then PATH lookup. Returns
|
|
@@ -4,15 +4,12 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
|
-
* Session RPC manager for Kabmo — the analog of omp-web's
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* abort_and_prompt, set_model, set_thinking_level, get_state, and the
|
|
11
|
-
* passthrough set. Event frames (agent_start/agent_end/message_update/...)
|
|
12
|
-
* are forwarded to SSE subscribers via onEvent.
|
|
7
|
+
* Session RPC manager for Kabmo — the analog of omp-web's lib/rpc-manager.ts.
|
|
8
|
+
* Wraps one spawned `omp --mode rpc-ui` process per session with the command
|
|
9
|
+
* surface Kabmo chat needs, and forwards event frames to subscribers.
|
|
13
10
|
*
|
|
14
|
-
* Scoped down from omp-web: host tools, URI schemes, extension widgets
|
|
15
|
-
*
|
|
11
|
+
* Scoped down from omp-web: host tools, URI schemes, extension widgets and
|
|
12
|
+
* branch/fork are omitted.
|
|
16
13
|
*/
|
|
17
14
|
|
|
18
15
|
import { RpcProcess, type RpcFrame } from '@/server/lib/omp/rpc/process';
|
|
@@ -40,8 +37,7 @@ export type {
|
|
|
40
37
|
} from '@/server/lib/omp/rpc/constants';
|
|
41
38
|
export { WebRpcError, resolveSpawnCwd } from '@/server/lib/omp/rpc/constants';
|
|
42
39
|
|
|
43
|
-
/** Overrides for the wrapper's own timers
|
|
44
|
-
* constant; tests shrink the window so the lifecycle rules stay fast. */
|
|
40
|
+
/** Overrides for the wrapper's own timers; tests shrink the idle window. */
|
|
45
41
|
export interface AgentSessionWrapperOptions {
|
|
46
42
|
/** Idle window before an unused process is reclaimed. */
|
|
47
43
|
idleDestroyMs?: number;
|
|
@@ -111,6 +107,8 @@ export class AgentSessionWrapper {
|
|
|
111
107
|
proc: RpcProcess;
|
|
112
108
|
readonly cwd: string;
|
|
113
109
|
private readonly recordedCwd: string | null;
|
|
110
|
+
/** The per-session agent dir this child was spawned with, when it has MCP overrides. */
|
|
111
|
+
mcpOverlay?: { dir: string; configPath: string };
|
|
114
112
|
|
|
115
113
|
constructor(proc: RpcProcess, cwd: string, recordedCwd?: string | null, options: AgentSessionWrapperOptions = {}) {
|
|
116
114
|
this.proc = proc;
|
|
@@ -210,17 +208,14 @@ export class AgentSessionWrapper {
|
|
|
210
208
|
}
|
|
211
209
|
|
|
212
210
|
private applyIdentity(state: RpcSessionState): void {
|
|
213
|
-
this.
|
|
214
|
-
this._sessionFile = state.sessionFile ?? '';
|
|
211
|
+
this.adoptSessionIdentity(state);
|
|
215
212
|
this.streaming = state.isStreaming;
|
|
216
213
|
this.compacting = state.isCompacting;
|
|
217
214
|
this.fastModeEnabled = state.fastModeEnabled ?? state.fastMode ?? this.fastModeEnabled;
|
|
218
|
-
if (state.model) this.runModel = { provider: state.model.provider, modelId: state.model.id };
|
|
219
215
|
// omp reports the messages it restored, so a child spawned for an EXISTING
|
|
220
|
-
// conversation
|
|
221
|
-
// from the
|
|
222
|
-
//
|
|
223
|
-
// messages at all is eligible, which is exactly the fresh-spawn case.
|
|
216
|
+
// conversation already has a first turn behind it — it must never be titled
|
|
217
|
+
// from whatever the operator asks next. Only a conversation with no messages
|
|
218
|
+
// at all is eligible, which is exactly the fresh-spawn case.
|
|
224
219
|
this.autoTitlePending = state.messageCount === 0;
|
|
225
220
|
}
|
|
226
221
|
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Ask one live omp child to re-read its MCP configuration.
|
|
8
|
+
*
|
|
9
|
+
* `/mcp reload` is a text-mode builtin: measured on 18.20.0 over RPC, it
|
|
10
|
+
* answers `agentInvoked: false` in a few milliseconds, emits one
|
|
11
|
+
* `command_output` frame, and opens no turn — the same contract
|
|
12
|
+
* `/reload-plugins` has. It re-runs `discoverAndConnect`, so a per-session
|
|
13
|
+
* agent dir whose `mcp.json` was just rewritten is picked up without a respawn.
|
|
14
|
+
*
|
|
15
|
+
* Deliberately NOT routed through `dispatchSessionCommand`: that path owns the
|
|
16
|
+
* turn state machine, and a reload must not flip a busy session to "starting a
|
|
17
|
+
* run".
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
import type { RpcProcess } from '@/server/lib/omp/rpc/process';
|
|
21
|
+
import type { IdleReaper } from '@/server/lib/omp/rpc/idle-reaper';
|
|
22
|
+
import { RELOAD_PLUGINS_TIMEOUT_MS } from '@/server/lib/omp/rpc/constants';
|
|
23
|
+
|
|
24
|
+
/** Child state a reload touches. Not a turn, but still work: keep the reaper off. */
|
|
25
|
+
export interface ReloadMcpHost {
|
|
26
|
+
isAlive(): boolean;
|
|
27
|
+
readonly idle: IdleReaper;
|
|
28
|
+
readonly proc: RpcProcess;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export async function reloadChildMcp(host: ReloadMcpHost): Promise<boolean> {
|
|
32
|
+
if (!host.isAlive()) return false;
|
|
33
|
+
host.idle.reset();
|
|
34
|
+
const ack = await host.proc.sendCommand<{ agentInvoked?: boolean } | undefined>(
|
|
35
|
+
{ type: 'prompt', message: '/mcp reload' },
|
|
36
|
+
RELOAD_PLUGINS_TIMEOUT_MS,
|
|
37
|
+
);
|
|
38
|
+
return ack?.agentInvoked !== true;
|
|
39
|
+
}
|
|
@@ -22,6 +22,7 @@ import { registerSpawnedSession } from '@/server/lib/omp/rpc/session-registratio
|
|
|
22
22
|
import { resolveSessionOwnership, SessionOwnedElsewhereError } from '@/server/lib/omp/session/ownership.server';
|
|
23
23
|
import { claimPrewarmedSession } from '@/server/lib/omp/rpc/prewarm-pool';
|
|
24
24
|
import { mintAgentEnvironment, rememberAgentToken } from '@/server/lib/sessions/agent-token.server';
|
|
25
|
+
import { sessionMcpSpawn } from '@/server/lib/omp/rpc/spawn-mcp';
|
|
25
26
|
import { isUnrestorableModelFailure, resolveResumableModel } from '@/server/lib/omp/session/resumable-model.server';
|
|
26
27
|
import { DEFAULT_APPROVAL_MODE, type ApprovalMode } from '@/shared/lib/omp/config/access-mode';
|
|
27
28
|
import type { SelectedModel } from '@/shared/types/models';
|
|
@@ -240,13 +241,16 @@ async function spawnOnce(
|
|
|
240
241
|
): Promise<{ session: AgentSessionWrapper; realSessionId: string }> {
|
|
241
242
|
const registry = getRegistry();
|
|
242
243
|
const holder: { wrapper?: AgentSessionWrapper } = {};
|
|
244
|
+
// MCP is a SPAWN property for omp: it reads `mcp.json` once (see `spawn-mcp.ts`).
|
|
245
|
+
const mcp = await sessionMcpSpawn(sessionId, cwd, modeEnv);
|
|
243
246
|
const proc = new RpcProcess({
|
|
244
247
|
cwd,
|
|
245
|
-
extraArgs: buildSessionSpawnArgs(sessionFile, approvalMode, resumeModel),
|
|
246
|
-
env:
|
|
248
|
+
extraArgs: [...buildSessionSpawnArgs(sessionFile, approvalMode, resumeModel), ...mcp.extraArgs],
|
|
249
|
+
env: mcp.env,
|
|
247
250
|
onExit: ({ stderrTail }) => holder.wrapper?.handleProcessExit(stderrTail),
|
|
248
251
|
});
|
|
249
252
|
const created = new AgentSessionWrapper(proc, cwd, recordedCwd);
|
|
253
|
+
created.mcpOverlay = mcp.overlay;
|
|
250
254
|
recordSpawnProvenance(created, approvalMode, modeEnv);
|
|
251
255
|
holder.wrapper = created;
|
|
252
256
|
created.start();
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The MCP half of an omp session spawn.
|
|
8
|
+
*
|
|
9
|
+
* omp reads `mcp.json` once at start, so a session that overrode a server needs
|
|
10
|
+
* its own agent dir (`PI_CODING_AGENT_DIR`) and a `--config` overlay that keeps
|
|
11
|
+
* the project's own file out of the child. A session with no overrides gets
|
|
12
|
+
* neither, and reads the real config exactly as before.
|
|
13
|
+
*
|
|
14
|
+
* Split out of `session-registry.ts` so the spawn plumbing stays under the
|
|
15
|
+
* repo's per-file ceiling and the MCP rule reads as one unit.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import { readSessionMcpOverrides } from '@/server/lib/mcp/session-state.server';
|
|
19
|
+
import { ensureSessionMcpOverlay, type SessionMcpOverlay } from '@/server/lib/mcp/session-overlay.server';
|
|
20
|
+
|
|
21
|
+
export interface SessionMcpSpawn {
|
|
22
|
+
/** Extra CLI args for the child (`--config <overlay>`). */
|
|
23
|
+
extraArgs: string[];
|
|
24
|
+
/** The child's environment, with `PI_CODING_AGENT_DIR` when it has an overlay. */
|
|
25
|
+
env?: Record<string, string>;
|
|
26
|
+
/** The overlay the child was spawned with, for a live `/mcp reload`. */
|
|
27
|
+
overlay?: SessionMcpOverlay;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export async function sessionMcpSpawn(
|
|
31
|
+
sessionId: string,
|
|
32
|
+
cwd: string,
|
|
33
|
+
modeEnv: Record<string, string> | undefined,
|
|
34
|
+
): Promise<SessionMcpSpawn> {
|
|
35
|
+
const overrides = await readSessionMcpOverrides(sessionId);
|
|
36
|
+
const overlay = await ensureSessionMcpOverlay(sessionId, cwd, overrides);
|
|
37
|
+
if (!overlay) return { extraArgs: [], env: modeEnv };
|
|
38
|
+
return {
|
|
39
|
+
extraArgs: ['--config', overlay.configPath],
|
|
40
|
+
env: { ...(modeEnv ?? {}), PI_CODING_AGENT_DIR: overlay.dir },
|
|
41
|
+
overlay,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
@@ -42,6 +42,7 @@ import { failWaitingOn } from '@/server/lib/waiting/store.server';
|
|
|
42
42
|
import { siblingDirForSession } from '@/server/lib/omp/subagent/history/paths';
|
|
43
43
|
import { isSinglePathSegment } from '@/server/lib/fs/path-segment';
|
|
44
44
|
import { deleteSessionRelations } from '@/server/lib/sessions/relations.server';
|
|
45
|
+
import { removeSessionMcpOverlay } from '@/server/lib/mcp/session-overlay.server';
|
|
45
46
|
|
|
46
47
|
export interface SessionPurgeResult {
|
|
47
48
|
/** Something keyed to this id existed — a transcript, a mock session row, or
|
|
@@ -76,6 +77,9 @@ const SESSION_ROW_DELETES: readonly (readonly [string, string])[] = [
|
|
|
76
77
|
['harness_sessions', 'session_id'],
|
|
77
78
|
['harness_goal_state', 'session_id'],
|
|
78
79
|
['harness_usage_state', 'session_id'],
|
|
80
|
+
// The per-session MCP overrides and the agent-dir overlay they build. The
|
|
81
|
+
// row is keyed to the id; the directory is removed below.
|
|
82
|
+
['session_mcp_state', 'session_id'],
|
|
79
83
|
];
|
|
80
84
|
|
|
81
85
|
async function purgeKabmoRows(db: DbClient, sessionId: string): Promise<number> {
|
|
@@ -140,6 +144,9 @@ export async function purgeSessionData(sessionId: string): Promise<SessionPurgeR
|
|
|
140
144
|
|
|
141
145
|
const db = await getDb();
|
|
142
146
|
const rowChanges = await purgeKabmoRows(db, sessionId);
|
|
147
|
+
// The overlay is a temp directory, not a row: a deleted session must not
|
|
148
|
+
// leave one behind for a future id to inherit.
|
|
149
|
+
await removeSessionMcpOverlay(sessionId);
|
|
143
150
|
|
|
144
151
|
// A prompt waiting on this session will never be released: the dependency is
|
|
145
152
|
// gone. Fail it BY NAME rather than letting it wait for a session that no
|
|
@@ -49,8 +49,8 @@ function isStringRecord(value: unknown): value is Record<string, string> {
|
|
|
49
49
|
function validate(pluginId: string, server: PluginMcpServer): RegisteredPluginMcpServer {
|
|
50
50
|
if (!server || typeof server !== 'object') throw new Error('mcp.register expects a server object');
|
|
51
51
|
if (typeof server.id !== 'string' || !server.id.trim()) throw new Error('mcp.register: "id" is required');
|
|
52
|
-
if (server.transport !== 'stdio' && server.transport !== 'http') {
|
|
53
|
-
throw new Error(`mcp.register "${server.id}": transport must be "stdio" or "
|
|
52
|
+
if (server.transport !== 'stdio' && server.transport !== 'http' && server.transport !== 'sse') {
|
|
53
|
+
throw new Error(`mcp.register "${server.id}": transport must be "stdio", "http" or "sse"`);
|
|
54
54
|
}
|
|
55
55
|
if (server.transport === 'stdio') {
|
|
56
56
|
if (typeof server.command !== 'string' || !server.command.trim()) {
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The `fs:` topic's default root, and its agreement with the HTTP route.
|
|
8
|
+
*
|
|
9
|
+
* The Files panel renders the topic's payload, while every `/api/fs/*` route
|
|
10
|
+
* resolves the same tree through `getDefaultFsRoot(isMockMode())`. The topic
|
|
11
|
+
* hardcoded `false`, so a MOCK capture listed the app's own checkout while the
|
|
12
|
+
* HTTP path listed the bundled `examples` tree — the panel showed the developer's
|
|
13
|
+
* repository in a demo screenshot. Both paths must answer the same root.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import { afterAll, beforeAll, describe, expect, test } from 'bun:test';
|
|
17
|
+
import { basename } from 'node:path';
|
|
18
|
+
|
|
19
|
+
import { workspaceDescriptor } from '@/server/lib/realtime/topics/workspace.server';
|
|
20
|
+
|
|
21
|
+
const originalMock = Bun.env.MOCK;
|
|
22
|
+
|
|
23
|
+
beforeAll(() => {
|
|
24
|
+
Bun.env.MOCK = 'true';
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
afterAll(() => {
|
|
28
|
+
if (originalMock === undefined) delete Bun.env.MOCK;
|
|
29
|
+
else Bun.env.MOCK = originalMock;
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
describe('workspace fs topic', () => {
|
|
33
|
+
test('mock mode lists the bundled examples tree, like the HTTP route', async () => {
|
|
34
|
+
const payload = (await workspaceDescriptor('fs')('').resolve('fs:')) as {
|
|
35
|
+
root: string;
|
|
36
|
+
files: { name: string }[];
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
// `basename`, not `endsWith('/examples')`: the root is a host path, and the
|
|
40
|
+
// Windows gate answers `…\examples`.
|
|
41
|
+
expect(basename(payload.root)).toBe('examples');
|
|
42
|
+
expect(payload.files.map((file) => file.name)).toContain('index.js');
|
|
43
|
+
});
|
|
44
|
+
});
|
|
@@ -18,6 +18,7 @@
|
|
|
18
18
|
|
|
19
19
|
import { type TopicDescriptor } from '@/server/lib/realtime/hub.server';
|
|
20
20
|
import { getDefaultFsRoot, resolveRoot, resolveWithinRoot } from '@/server/lib/fs/root';
|
|
21
|
+
import { isMockMode } from '@/server/mock.server';
|
|
21
22
|
import { readGitStatus } from '@/server/lib/fs/git-status-read';
|
|
22
23
|
import { listDirectoryEntries } from '@/server/lib/fs/listing';
|
|
23
24
|
import { discoveredRepos, startRepoScan } from '@/server/lib/fs/git-repos';
|
|
@@ -34,7 +35,7 @@ async function resolveScope(scope: string): Promise<{ root: string; repo: string
|
|
|
34
35
|
const separator = scope.indexOf('\u0000');
|
|
35
36
|
const rootPart = separator === -1 ? scope : scope.slice(0, separator);
|
|
36
37
|
const repo = (separator === -1 ? '.' : scope.slice(separator + 1)) || '.';
|
|
37
|
-
const root = await resolveRoot(rootPart || null, await getDefaultFsRoot(
|
|
38
|
+
const root = await resolveRoot(rootPart || null, await getDefaultFsRoot(isMockMode()));
|
|
38
39
|
if (!root) return null;
|
|
39
40
|
return { root, repo };
|
|
40
41
|
}
|
|
@@ -72,7 +73,7 @@ async function fsResolve(scope: string): Promise<unknown> {
|
|
|
72
73
|
|
|
73
74
|
/** One workspace root's nested repositories, and whether discovery is running. */
|
|
74
75
|
async function reposResolve(scope: string): Promise<unknown> {
|
|
75
|
-
const root = await resolveRoot(scope || null, await getDefaultFsRoot(
|
|
76
|
+
const root = await resolveRoot(scope || null, await getDefaultFsRoot(isMockMode()));
|
|
76
77
|
if (!root) return null;
|
|
77
78
|
startRepoScan(root);
|
|
78
79
|
const { repos, pending } = discoveredRepos(root);
|