@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.
Files changed (110) hide show
  1. package/README.md +79 -21
  2. package/dist/client/index.html +1 -1
  3. package/dist/client/index.js +481 -462
  4. package/dist/client/static/js/{index-5vjbp04s.js → index-r3bhgvkt.js} +882 -883
  5. package/marketplace/plugins/stats/package.json +2 -2
  6. package/marketplace/plugins/stats/src/format.test.ts +7 -1
  7. package/package.json +2 -2
  8. package/src/client/components/common/context-usage-button/McpSection.tsx +133 -0
  9. package/src/client/components/common/context-usage-button/Ring.tsx +12 -6
  10. package/src/client/components/common/context-usage-button/index.test.tsx +24 -13
  11. package/src/client/components/common/context-usage-button/index.tsx +32 -34
  12. package/src/client/components/common/session-row/TrailingSlot.tsx +6 -2
  13. package/src/client/components/common/session-row/session-row.test.tsx +13 -0
  14. package/src/client/components/layout/desktop-layout/index.tsx +5 -1
  15. package/src/client/components/mobile/RightSidebar.tsx +2 -1
  16. package/src/client/components/settings/categories/McpSettings.tsx +10 -3
  17. package/src/client/components/settings/categories/mcp-settings/AdvancedSection.tsx +244 -0
  18. package/src/client/components/settings/categories/mcp-settings/ConnectionTest.tsx +3 -3
  19. package/src/client/components/settings/categories/mcp-settings/DetailPane.tsx +55 -97
  20. package/src/client/components/settings/categories/mcp-settings/ImportModal.tsx +12 -64
  21. package/src/client/components/settings/categories/mcp-settings/{EnvVarsSection.tsx → KeyValueSection.tsx} +42 -24
  22. package/src/client/components/settings/categories/mcp-settings/SidebarList.tsx +1 -1
  23. package/src/client/components/settings/categories/mcp-settings/TransportSection.tsx +101 -0
  24. package/src/client/components/workspace/browser-panel/EngineNotice.test.tsx +109 -0
  25. package/src/client/components/workspace/browser-panel/EngineNotice.tsx +112 -0
  26. package/src/client/components/workspace/browser-panel/index.tsx +45 -12
  27. package/src/client/components/workspace/chat-timeline/chat-input/AccessDropdown.test.ts +63 -0
  28. package/src/client/components/workspace/chat-timeline/chat-input/AccessDropdown.tsx +18 -6
  29. package/src/client/components/workspace/chat-timeline/chat-input/Toolbar.tsx +3 -1
  30. package/src/client/components/workspace/chat-timeline/chat-input/access-levels.ts +39 -1
  31. package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Eval.test.tsx +13 -7
  32. package/src/client/components/workspace/editor/plugin-rail.test.tsx +6 -1
  33. package/src/client/components/workspace/terminal-panel/scroll-hold.test.ts +20 -5
  34. package/src/client/data/settings/mcp.ts +4 -2
  35. package/src/client/data/settings/omp-schema.json +22 -2
  36. package/src/client/hooks/browser/use-browser-engine.ts +99 -0
  37. package/src/client/hooks/chat/context/mcp.ts +159 -0
  38. package/src/client/hooks/chat/timeline/access-mode.ts +45 -15
  39. package/src/client/hooks/chat/timeline/index.ts +7 -3
  40. package/src/client/hooks/chat/timeline/timeline-mode-state.test.ts +33 -4
  41. package/src/client/hooks/ui/ui-listeners.test.ts +13 -18
  42. package/src/server/lib/browser/engine.test.ts +118 -0
  43. package/src/server/lib/browser/engine.ts +102 -0
  44. package/src/server/lib/db/schema.ts +4 -0
  45. package/src/server/lib/fs/toolchain-path.test.ts +87 -0
  46. package/src/server/lib/fs/toolchain-path.ts +49 -0
  47. package/src/server/lib/harness/acp/protocol.ts +9 -1
  48. package/src/server/lib/harness/auto-probe.server.ts +3 -2
  49. package/src/server/lib/harness/launch-table.ts +3 -2
  50. package/src/server/lib/harness/spawn.server.ts +5 -1
  51. package/src/server/lib/harness/update-queue.server.ts +2 -1
  52. package/src/server/lib/harness/update-state.server.ts +6 -2
  53. package/src/server/lib/mcp/probe.server.ts +71 -0
  54. package/src/server/lib/mcp/registry.server.ts +195 -46
  55. package/src/server/lib/mcp/registry.test.ts +76 -4
  56. package/src/server/lib/mcp/schema.server.ts +35 -0
  57. package/src/server/lib/mcp/session-mcp.test.ts +164 -0
  58. package/src/server/lib/mcp/session-overlay.server.ts +152 -0
  59. package/src/server/lib/mcp/session-state.server.ts +75 -0
  60. package/src/server/lib/mcp/store.server.ts +6 -1
  61. package/src/server/lib/omp/config/config-cli.ts +4 -0
  62. package/src/server/lib/omp/config/mcp-and-cli.test.ts +12 -183
  63. package/src/server/lib/omp/config/mcp-config.test.ts +277 -0
  64. package/src/server/lib/omp/config/mcp-shared.ts +36 -0
  65. package/src/server/lib/omp/config/mcp-test-protocol.ts +89 -0
  66. package/src/server/lib/omp/config/mcp-test-remote.ts +167 -0
  67. package/src/server/lib/omp/config/mcp-test.ts +21 -123
  68. package/src/server/lib/omp/config/mcp-write.ts +179 -0
  69. package/src/server/lib/omp/config/mcp.ts +138 -118
  70. package/src/server/lib/omp/core/cli.ts +4 -14
  71. package/src/server/lib/omp/rpc/manager.ts +12 -17
  72. package/src/server/lib/omp/rpc/reload-mcp.ts +39 -0
  73. package/src/server/lib/omp/rpc/session-registry.ts +6 -2
  74. package/src/server/lib/omp/rpc/spawn-mcp.ts +43 -0
  75. package/src/server/lib/omp/session/delete.server.ts +7 -0
  76. package/src/server/lib/plugins/mcp.server.ts +2 -2
  77. package/src/server/lib/realtime/topics/workspace.server.test.ts +44 -0
  78. package/src/server/lib/realtime/topics/workspace.server.ts +3 -2
  79. package/src/server/routes/browser/engine.test.ts +70 -0
  80. package/src/server/routes/browser/engine.ts +51 -0
  81. package/src/server/routes/browser/index.ts +5 -0
  82. package/src/server/routes/fs/git.ts +4 -3
  83. package/src/server/routes/harness/versions.test.ts +5 -0
  84. package/src/server/routes/sessions/index.ts +7 -0
  85. package/src/server/routes/sessions/mcp.test.ts +154 -0
  86. package/src/server/routes/sessions/mcp.ts +202 -0
  87. package/src/server/routes/settings/mcp-test.ts +5 -4
  88. package/src/server/routes/settings/mcp.test.ts +42 -1
  89. package/src/server/routes/settings/mcp.ts +80 -24
  90. package/src/shared/lib/code/highlight-memo.test.ts +18 -0
  91. package/src/shared/lib/code/highlight-memo.ts +46 -17
  92. package/src/shared/lib/fonts/nerd-symbols.css +14 -0
  93. package/src/shared/lib/fonts/nerd-symbols.test.ts +86 -0
  94. package/src/shared/lib/fonts/symbols-nerd-font-mono.woff2 +0 -0
  95. package/src/shared/lib/mcp/import.ts +112 -0
  96. package/src/shared/lib/mcp/item.ts +61 -0
  97. package/src/shared/lib/mcp/key-value.ts +37 -0
  98. package/src/shared/lib/mcp/mcp-lib.test.ts +119 -0
  99. package/src/shared/lib/mcp/status.test.ts +36 -0
  100. package/src/shared/lib/mcp/status.ts +38 -0
  101. package/src/shared/lib/models/client.ts +27 -6
  102. package/src/shared/lib/models/provider/models.test.ts +31 -0
  103. package/src/shared/lib/omp/config/access-mode.test.ts +73 -0
  104. package/src/shared/lib/omp/config/access-mode.ts +49 -0
  105. package/src/shared/lib/workspace/right-panels.ts +13 -0
  106. package/src/shared/lib/workspace/workspace-modules.test.ts +3 -1
  107. package/src/shared/types/browser.ts +21 -0
  108. package/src/shared/types/settings/mcp.ts +73 -4
  109. package/src/test-support/pristine-globals.test.ts +53 -0
  110. package/src/test-support/pristine-globals.ts +6 -1
@@ -0,0 +1,119 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * Import + normalizer contracts.
8
+ *
9
+ * The import parser decides what a pasted snippet becomes, and every other tool
10
+ * writes a different envelope: keeping only the first server, or dropping a
11
+ * remote entry's `type`, is the difference between a working import and one the
12
+ * user has to repair by hand. The normalizer is the read boundary for rows
13
+ * written before `transport` existed.
14
+ */
15
+
16
+ import { describe, expect, test } from 'bun:test';
17
+ import { parseMcpImport } from '@/shared/lib/mcp/import';
18
+ import { normalizeMcpItem } from '@/shared/lib/mcp/item';
19
+ import { recordToRows, rowsToRecord } from '@/shared/lib/mcp/key-value';
20
+
21
+ describe('parseMcpImport', () => {
22
+ test('every server in an mcpServers block is imported', () => {
23
+ const servers = parseMcpImport(JSON.stringify({
24
+ mcpServers: {
25
+ one: { command: 'a', args: ['x'] },
26
+ two: { command: 'b' },
27
+ },
28
+ }));
29
+ expect(servers.map((server) => server.name)).toEqual(['one', 'two']);
30
+ expect(servers[0]).toMatchObject({ transport: 'stdio', commandArgs: ['a', 'x'] });
31
+ });
32
+
33
+ test('VS Code `.vscode/mcp.json` (`servers`, typed transports) is understood', () => {
34
+ const servers = parseMcpImport(JSON.stringify({
35
+ servers: {
36
+ local: { type: 'stdio', command: 'npx', args: ['-y', 'x'], env: { K: 'V' } },
37
+ remote: { type: 'http', url: 'https://x/mcp', headers: { Authorization: 'Bearer t' } },
38
+ legacy: { type: 'sse', url: 'https://y/sse' },
39
+ },
40
+ }));
41
+ expect(servers.map((server) => server.transport)).toEqual(['stdio', 'http', 'sse']);
42
+ expect(servers[1]).toMatchObject({
43
+ linkUrl: 'https://x/mcp',
44
+ headers: [{ id: 'header-1-0', key: 'Authorization', value: 'Bearer t' }],
45
+ });
46
+ });
47
+
48
+ test('OpenCode (`mcp`, `type: local|remote`, command array, environment) is understood', () => {
49
+ const servers = parseMcpImport(JSON.stringify({
50
+ mcp: {
51
+ local: { type: 'local', command: ['bunx', 'server'], environment: { TOKEN: 't' } },
52
+ remote: { type: 'remote', url: 'https://z/mcp' },
53
+ },
54
+ }));
55
+ expect(servers[0]).toMatchObject({
56
+ transport: 'stdio',
57
+ commandArgs: ['bunx', 'server'],
58
+ envVars: [{ id: 'env-0-0', key: 'TOKEN', value: 't' }],
59
+ });
60
+ expect(servers[1]).toMatchObject({ transport: 'http', linkUrl: 'https://z/mcp' });
61
+ });
62
+
63
+ test('Gemini `httpUrl` is read as a remote URL', () => {
64
+ const servers = parseMcpImport(JSON.stringify({
65
+ mcpServers: { g: { httpUrl: 'https://gemini/mcp' } },
66
+ }));
67
+ expect(servers[0]).toMatchObject({ transport: 'http', linkUrl: 'https://gemini/mcp' });
68
+ });
69
+
70
+ test('a bare definition is one server; a blank envelope and bad JSON are errors', () => {
71
+ expect(parseMcpImport(JSON.stringify({ name: 'solo', command: 'x' }))).toHaveLength(1);
72
+ expect(() => parseMcpImport(JSON.stringify({ mcpServers: {} }))).toThrow('No server definitions found');
73
+ expect(() => parseMcpImport('{nope')).toThrow('That is not valid JSON.');
74
+ expect(() => parseMcpImport('[1]')).toThrow('Paste a JSON object');
75
+ });
76
+ });
77
+
78
+ describe('normalizeMcpItem', () => {
79
+ test('a legacy reachType row becomes an explicit transport with empty lists', () => {
80
+ expect(normalizeMcpItem({ id: 'a', name: 'a', scope: 'every-project', reachType: 'link', linkUrl: 'https://x' }))
81
+ .toMatchObject({ transport: 'http', enabled: true, headers: [], envVars: [], commandArgs: [] });
82
+ expect(normalizeMcpItem({ id: 'b', name: 'b', reachType: 'command' })).toMatchObject({ transport: 'stdio' });
83
+ });
84
+
85
+ test('a malformed row is dropped rather than guessed at', () => {
86
+ expect(normalizeMcpItem({ name: 'x' })).toBeNull();
87
+ expect(normalizeMcpItem({ id: 'x' })).toBeNull();
88
+ expect(normalizeMcpItem(null)).toBeNull();
89
+ });
90
+
91
+ test('credential blocks and schema fields survive normalization', () => {
92
+ expect(normalizeMcpItem({
93
+ id: 'c',
94
+ name: 'c',
95
+ transport: 'sse',
96
+ timeout: 10,
97
+ instructions: false,
98
+ auth: { type: 'oauth' },
99
+ })).toMatchObject({ transport: 'sse', timeout: 10, instructions: false, auth: { type: 'oauth' } });
100
+ });
101
+ });
102
+
103
+ describe('key/value rows', () => {
104
+ test('blank keys and the redaction sentinel are never written', () => {
105
+ expect(rowsToRecord([
106
+ { id: '1', key: ' ', value: 'x' },
107
+ { id: '2', key: 'TOKEN', value: '••••••••' },
108
+ { id: '3', key: 'OK', value: 'v' },
109
+ ])).toEqual({ OK: 'v' });
110
+ expect(rowsToRecord([])).toBeUndefined();
111
+ });
112
+
113
+ test('a native record becomes rows with stable ids', () => {
114
+ expect(recordToRows({ A: 1, B: 'two' }, 'env-0')).toEqual([
115
+ { id: 'env-0-0', key: 'A', value: '1' },
116
+ { id: 'env-0-1', key: 'B', value: 'two' },
117
+ ]);
118
+ });
119
+ });
@@ -0,0 +1,36 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * The MCP status rule: a probe result, never a guess from `enabled`.
8
+ *
9
+ * The bug this pins: omp publishes no MCP state over RPC, so a status derived
10
+ * from the checkbox would paint a green dot over a server that never answered.
11
+ */
12
+
13
+ import { describe, expect, test } from 'bun:test';
14
+ import { mcpServerStatus } from '@/shared/lib/mcp/status';
15
+
16
+ describe('mcpServerStatus', () => {
17
+ test('a disabled server is disabled regardless of the probe', () => {
18
+ expect(mcpServerStatus({ enabled: false, checking: false, probe: { ok: true } })).toBe('disabled');
19
+ });
20
+
21
+ test('an in-flight probe is checking', () => {
22
+ expect(mcpServerStatus({ enabled: true, checking: true, probe: null })).toBe('checking');
23
+ });
24
+
25
+ test('a successful handshake is active', () => {
26
+ expect(mcpServerStatus({ enabled: true, checking: false, probe: { ok: true } })).toBe('active');
27
+ });
28
+
29
+ test('a failed handshake is an error', () => {
30
+ expect(mcpServerStatus({ enabled: true, checking: false, probe: { ok: false } })).toBe('error');
31
+ });
32
+
33
+ test('a server never probed is unknown, not active', () => {
34
+ expect(mcpServerStatus({ enabled: true, checking: false, probe: null })).toBe('unknown');
35
+ });
36
+ });
@@ -0,0 +1,38 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * The status shown beside one MCP server, from the only signal Kabmo has: a
8
+ * real handshake (`probe.server.ts`).
9
+ *
10
+ * omp publishes no MCP state over RPC — `mcp:connection-status` is an internal
11
+ * TUI event bus, `/mcp list` over RPC prints the configured state, and
12
+ * `get_state.dumpTools` carries only the built-in tools (measured on 18.20.0:
13
+ * a live codegraph server mounted no `mcp__` entry there). So the status is
14
+ * "did the handshake succeed", never a guess from `enabled`:
15
+ *
16
+ * - `active` — the handshake answered and listed tools;
17
+ * - `error` — the handshake failed (the reason is in the probe);
18
+ * - `checking` — a probe is in flight;
19
+ * - `disabled` — turned off for this session;
20
+ * - `unknown` — not probed yet.
21
+ */
22
+
23
+ export type McpServerStatus = 'active' | 'error' | 'checking' | 'disabled' | 'unknown';
24
+
25
+ export interface McpProbeLike {
26
+ ok: boolean;
27
+ }
28
+
29
+ export function mcpServerStatus(input: {
30
+ enabled: boolean;
31
+ checking: boolean;
32
+ probe: McpProbeLike | null | undefined;
33
+ }): McpServerStatus {
34
+ if (!input.enabled) return 'disabled';
35
+ if (input.checking) return 'checking';
36
+ if (!input.probe) return 'unknown';
37
+ return input.probe.ok ? 'active' : 'error';
38
+ }
@@ -20,26 +20,47 @@ export type ModelsResponse = ModelsData & { selectedModel?: AIModelOption };
20
20
 
21
21
  let inFlight: Promise<ModelsResponse> | null = null;
22
22
  let cached: { data: ModelsResponse; expiresAt: number } | null = null;
23
+ /** Bumped by every invalidation, so a read that began earlier cannot answer it. */
24
+ let generation = 0;
23
25
 
24
26
  export function fetchModelsData(): Promise<ModelsResponse> {
25
27
  if (cached && cached.expiresAt > Date.now()) return Promise.resolve(cached.data);
26
28
  if (inFlight) return inFlight;
27
29
 
28
- inFlight = fetch('/api/models')
30
+ const startedAt = generation;
31
+ const request = fetch('/api/models')
29
32
  .then((res) => (res.ok ? res.json() : Promise.reject(new Error(`GET /api/models failed: ${res.status}`))))
30
33
  .then((data: ModelsResponse) => {
31
- cached = { data, expiresAt: Date.now() + CACHE_TTL_MS };
34
+ // A read that began BEFORE an invalidation describes the catalog that
35
+ // invalidation retired. Caching it would serve the pre-write list for
36
+ // another minute — the stale-picker bug itself — so only a read from the
37
+ // current generation may write the cache.
38
+ if (startedAt === generation) cached = { data, expiresAt: Date.now() + CACHE_TTL_MS };
32
39
  return data;
33
40
  })
34
41
  .finally(() => {
35
- inFlight = null;
42
+ // Identity, not a flag: a newer read may already own `inFlight`.
43
+ if (inFlight === request) inFlight = null;
36
44
  });
37
-
38
- return inFlight;
45
+ inFlight = request;
46
+ return request;
39
47
  }
40
48
 
49
+ /**
50
+ * Drop the local cache, and any read that started before the drop.
51
+ *
52
+ * The in-flight half matters twice. `inFlight` is module state shared by every
53
+ * consumer, so a read started against the previous catalog would otherwise be
54
+ * handed to a caller that invalidated on purpose — and a read that never
55
+ * settles (a stub, a hung socket, a request the page abandoned) would leave
56
+ * every later caller waiting on that same promise forever. Measured on the
57
+ * Ubuntu gate: the picker suites timed out at the runner's 5 s budget, one
58
+ * file after another, with a healthy stub installed and never consulted.
59
+ */
41
60
  export function invalidateModelsCache(): void {
42
61
  cached = null;
62
+ generation += 1;
63
+ inFlight = null;
43
64
  }
44
65
 
45
66
  /**
@@ -50,7 +71,7 @@ export function invalidateModelsCache(): void {
50
71
  * re-reads from one signal rather than from a local event.
51
72
  */
52
73
  export function notifyModelsUpdated(): void {
53
- cached = null;
74
+ invalidateModelsCache();
54
75
  }
55
76
 
56
77
  /**
@@ -189,6 +189,37 @@ describe('notifyModelsUpdated', () => {
189
189
  await fetchModelsData();
190
190
  expect(reads).toBe(1);
191
191
  });
192
+
193
+ test('an invalidation also retires a read that is still in flight', async () => {
194
+ // `inFlight` is module state shared by every consumer: a slot reserved by a
195
+ // read against the PREVIOUS catalog was handed to a caller that invalidated
196
+ // on purpose, and a read that never settled (an abandoned request, a socket
197
+ // that died mid-flight) then owned the slot forever — measured on the Ubuntu
198
+ // gate as picker suites timing out at 5 s with a healthy stub installed and
199
+ // never consulted.
200
+ const hung = Promise.withResolvers<Response>();
201
+ let reads = 0;
202
+ // A cache left by the case above would answer this read without a fetch.
203
+ notifyModelsUpdated();
204
+ globalThis.fetch = (async (input: RequestInfo | URL) => {
205
+ const url = typeof input === 'string' ? input : input.toString();
206
+ if (url.includes('/api/models')) reads += 1;
207
+ return hung.promise;
208
+ }) as typeof fetch;
209
+
210
+ void fetchModelsData().catch(() => null);
211
+ await Promise.resolve();
212
+ expect(reads).toBe(1);
213
+
214
+ notifyModelsUpdated();
215
+ globalThis.fetch = (async () => jsonResponse({ models: {}, providers: {} })) as unknown as typeof fetch;
216
+ expect(await fetchModelsData()).toMatchObject({ models: {}, providers: {} });
217
+
218
+ // The abandoned read answering late must not overwrite the fresh answer.
219
+ hung.resolve(jsonResponse({ models: { stale: 'Stale' }, providers: {} }));
220
+ await Promise.resolve();
221
+ expect(await fetchModelsData()).toMatchObject({ models: {}, providers: {} });
222
+ });
192
223
  });
193
224
 
194
225
  describe('addProviderModel', () => {
@@ -0,0 +1,73 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * The access tier is remembered PER HARNESS, and the two transports mean
8
+ * different things by the same three words: omp's transports carry omp's own
9
+ * approval gate, while an ACP agent decides which calls it asks about and
10
+ * Kabmo's tier only answers those requests. So a `yolo` chosen for omp must
11
+ * never become another agent's auto-approval just because the operator switched
12
+ * the composer's tab.
13
+ */
14
+
15
+ import { describe, expect, test } from 'bun:test';
16
+ import {
17
+ HARNESS_ACCESS_MODES_SETTING_KEY,
18
+ accessModeForHarness,
19
+ isOmpHarness,
20
+ readAccessModePicks,
21
+ } from '@/shared/lib/omp/config/access-mode';
22
+
23
+ describe('isOmpHarness', () => {
24
+ test('both omp transports, and an unresolved harness, are omp', () => {
25
+ expect(isOmpHarness('omp-rpc')).toBe(true);
26
+ expect(isOmpHarness('omp-acp')).toBe(true);
27
+ expect(isOmpHarness(undefined)).toBe(true);
28
+ expect(isOmpHarness(null)).toBe(true);
29
+ });
30
+
31
+ test('every other agent is not', () => {
32
+ expect(isOmpHarness('claude')).toBe(false);
33
+ expect(isOmpHarness('codex')).toBe(false);
34
+ });
35
+ });
36
+
37
+ describe('readAccessModePicks', () => {
38
+ test('keeps only the values that are approval modes', () => {
39
+ expect(
40
+ readAccessModePicks({ [HARNESS_ACCESS_MODES_SETTING_KEY]: { claude: 'yolo', codex: 'sudo', omp: 7 } }),
41
+ ).toEqual({ claude: 'yolo' });
42
+ });
43
+
44
+ test('a missing or malformed map reads as no picks', () => {
45
+ expect(readAccessModePicks({})).toEqual({});
46
+ expect(readAccessModePicks({ [HARNESS_ACCESS_MODES_SETTING_KEY]: 'yolo' })).toEqual({});
47
+ expect(readAccessModePicks(undefined)).toEqual({});
48
+ });
49
+ });
50
+
51
+ describe('accessModeForHarness', () => {
52
+ test('omp falls back to the global spawn-time pick', () => {
53
+ expect(accessModeForHarness('omp-rpc', {}, { omp_access_mode: 'write' })).toBe('write');
54
+ // An unresolved harness is the default agent, so it reads the same value.
55
+ expect(accessModeForHarness(undefined, {}, { omp_access_mode: 'write' })).toBe('write');
56
+ });
57
+
58
+ test("omp's own pick outranks the global one", () => {
59
+ expect(accessModeForHarness('omp-rpc', { 'omp-rpc': 'always-ask' }, { omp_access_mode: 'yolo' })).toBe(
60
+ 'always-ask',
61
+ );
62
+ });
63
+
64
+ test('another harness does NOT inherit omp’s global pick', () => {
65
+ // The defect this guards: `yolo` chosen on omp silently auto-approved every
66
+ // approval the next agent raised, a grant the operator never gave it.
67
+ expect(accessModeForHarness('claude', {}, { omp_access_mode: 'yolo' })).toBe('always-ask');
68
+ });
69
+
70
+ test('a harness with its own pick shows that pick', () => {
71
+ expect(accessModeForHarness('claude', { claude: 'write' }, { omp_access_mode: 'yolo' })).toBe('write');
72
+ });
73
+ });
@@ -11,8 +11,16 @@
11
11
  * omp's contract (pi-coding-agent ApprovalMode): `always-ask` auto-runs
12
12
  * read-tier tools and prompts for write+exec, `write` auto-runs read+write and
13
13
  * prompts for exec, `yolo` auto-runs everything.
14
+ *
15
+ * The SAME three words mean something narrower on an ACP harness: there the
16
+ * agent decides which calls it asks about, and Kabmo's tier only decides which
17
+ * of those arrive as a dialog (`acp/permissions.ts`). It can loosen an agent's
18
+ * own gate and never tighten it — so the pick is remembered PER HARNESS, and a
19
+ * `yolo` chosen for omp never silently becomes another agent's auto-approval.
14
20
  */
15
21
 
22
+ import { isRecord } from '@/shared/lib/util/guards';
23
+
16
24
  export type ApprovalMode = 'always-ask' | 'write' | 'yolo';
17
25
 
18
26
  export const DEFAULT_APPROVAL_MODE: ApprovalMode = 'always-ask';
@@ -22,6 +30,9 @@ export const APPROVAL_MODES: readonly ApprovalMode[] = ['always-ask', 'write', '
22
30
  /** `app_settings` key the composer persists its pick under. */
23
31
  export const ACCESS_MODE_SETTING_KEY = 'omp_access_mode';
24
32
 
33
+ /** `app_settings` key holding the composer's pick for every OTHER harness. */
34
+ export const HARNESS_ACCESS_MODES_SETTING_KEY = 'harness_access_modes';
35
+
25
36
  export function isApprovalMode(value: unknown): value is ApprovalMode {
26
37
  return typeof value === 'string' && APPROVAL_MODES.some((mode) => mode === value);
27
38
  }
@@ -29,3 +40,41 @@ export function isApprovalMode(value: unknown): value is ApprovalMode {
29
40
  export function normalizeApprovalMode(value: unknown): ApprovalMode {
30
41
  return isApprovalMode(value) ? value : DEFAULT_APPROVAL_MODE;
31
42
  }
43
+
44
+ /**
45
+ * omp's own two transports. Their tier IS omp's approval gate — the spawn flag
46
+ * over RPC, omp's own `tools.approvalMode` over ACP — so they share the global
47
+ * pick the server also reads as its spawn-time default.
48
+ */
49
+ export function isOmpHarness(harness: string | null | undefined): boolean {
50
+ return !harness || harness === 'omp-rpc' || harness === 'omp-acp';
51
+ }
52
+
53
+ /** The per-harness picks stored in `app_settings`; an unknown shape reads as none. */
54
+ export function readAccessModePicks(settings: Record<string, unknown> | undefined): Record<string, ApprovalMode> {
55
+ const raw = settings?.[HARNESS_ACCESS_MODES_SETTING_KEY];
56
+ if (!isRecord(raw)) return {};
57
+ const picks: Record<string, ApprovalMode> = {};
58
+ for (const [harness, mode] of Object.entries(raw)) {
59
+ if (isApprovalMode(mode)) picks[harness] = mode;
60
+ }
61
+ return picks;
62
+ }
63
+
64
+ /**
65
+ * The tier to show for `harness`.
66
+ *
67
+ * omp's transports fall back to the global pick (`omp_access_mode`), which is
68
+ * also the server's spawn default. Every other harness starts at `always-ask`
69
+ * until the operator picks one FOR IT: carrying omp's `yolo` across a harness
70
+ * switch would auto-approve an agent the operator never granted that.
71
+ */
72
+ export function accessModeForHarness(
73
+ harness: string | null | undefined,
74
+ picks: Record<string, ApprovalMode>,
75
+ settings?: Record<string, unknown>,
76
+ ): ApprovalMode {
77
+ const picked = picks[harness ?? 'omp-rpc'];
78
+ if (isApprovalMode(picked)) return picked;
79
+ return isOmpHarness(harness) ? normalizeApprovalMode(settings?.[ACCESS_MODE_SETTING_KEY]) : DEFAULT_APPROVAL_MODE;
80
+ }
@@ -55,6 +55,19 @@ export const PANEL_MARK_SIZE = 16;
55
55
  */
56
56
  export const DEFAULT_RIGHT_PANEL_FRACTION = 0.3;
57
57
 
58
+ /**
59
+ * The view a session that has never picked one opens on.
60
+ *
61
+ * Not read from `app_settings`. Builds that carried a GLOBAL `activeRightPanel`
62
+ * row (the pre-per-session layout wrote that key on every rail click) still have
63
+ * it in `app_settings`, and seeding the per-session slot from it made every NEW
64
+ * chat open whatever panel was last selected anywhere — measured on this
65
+ * machine's database, `activeRightPanel = browser`, so a fresh session drew the
66
+ * Browser Agent instead of Files. A new session starts from this constant; the
67
+ * per-session slot then remembers what the user picks.
68
+ */
69
+ export const DEFAULT_RIGHT_PANEL_TYPE: RightPanelType = 'files';
70
+
58
71
  /**
59
72
  * Width (px) a view opens at before the group's area has been measured. Kept at
60
73
  * the values these views shipped with, so the first paint is unchanged and a
@@ -23,7 +23,7 @@ import { afterAll, afterEach, describe, expect, test } from 'bun:test';
23
23
  import { activeProjectForSession, composerRootFor, effectiveRootFor } from '@/shared/lib/workspace/active-project';
24
24
  import { diffTabId, diffTabName, fileTabId } from '@/shared/lib/workspace/file-tab-id';
25
25
  import {
26
- DEFAULT_RIGHT_PANEL_FRACTION,
26
+ DEFAULT_RIGHT_PANEL_FRACTION, DEFAULT_RIGHT_PANEL_TYPE,
27
27
  DEFAULT_RIGHT_PANEL_WIDTHS,
28
28
  MIN_RIGHT_PANEL_WIDTHS,
29
29
  RIGHT_PANEL_TYPES,
@@ -90,6 +90,8 @@ describe('right-panels catalog', () => {
90
90
  expect(DEFAULT_RIGHT_PANEL_WIDTHS.terminal).toBe(640);
91
91
  expect(MIN_RIGHT_PANEL_WIDTHS.files).toBe(200);
92
92
  expect(MIN_RIGHT_PANEL_WIDTHS.terminal).toBe(320);
93
+ // A new session opens Files, never the stale global `activeRightPanel` row.
94
+ expect(DEFAULT_RIGHT_PANEL_TYPE).toBe('files');
93
95
  });
94
96
 
95
97
  test('isRightPanelType accepts only catalog members', () => {
@@ -23,6 +23,27 @@ export interface BrowserViewState {
23
23
  tabs: BrowserTabInfo[];
24
24
  }
25
25
 
26
+ /**
27
+ * Which engine the session's omp agent will use for its next `browser.open`.
28
+ *
29
+ * The panel mirrors the project-shared Chromium over CDP. omp's own WebKit
30
+ * engine (ABKit) has no CDP endpoint and no frame stream, so a session on
31
+ * WebKit can never appear here — the panel says so instead of waiting.
32
+ */
33
+ export interface BrowserEngineState {
34
+ /** `browser.webkit` as omp reads it; absent means the default, `true`. */
35
+ webkit: boolean;
36
+ /** Whether the ABKit host executable exists on this machine. */
37
+ engineInstalled: boolean;
38
+ /** What the next open will use, after the install check. */
39
+ effective: 'webkit' | 'chromium';
40
+ }
41
+
42
+ /** The engine state plus the server's mode, so the panel can stay quiet in MOCK. */
43
+ export interface BrowserEnginePayload extends BrowserEngineState {
44
+ mock: boolean;
45
+ }
46
+
26
47
  /** One screencast frame (base64 JPEG) for the currently viewed tab. */
27
48
  export interface BrowserViewFrame {
28
49
  data: string;
@@ -1,12 +1,35 @@
1
- export type McpReachType = 'command' | 'link';
1
+ /** The three transports omp's `mcp.json` schema accepts. */
2
+ export type McpTransport = 'stdio' | 'http' | 'sse';
2
3
  export type McpScope = 'every-project' | 'this-project';
3
4
 
4
- export interface McpEnvVar {
5
+ /** One key/value row: an env var, an HTTP header, or an OAuth field. */
6
+ export interface McpKeyValue {
5
7
  id: string;
6
8
  key: string;
7
9
  value: string;
8
10
  }
9
11
 
12
+ /** omp's `auth` block: the credential strategy for a remote server. */
13
+ export interface McpAuthConfig {
14
+ type: 'oauth' | 'apikey';
15
+ credentialId?: string;
16
+ tokenUrl?: string;
17
+ clientId?: string;
18
+ clientSecret?: string;
19
+ resource?: string;
20
+ }
21
+
22
+ /** omp's `oauth` block: explicit OAuth client settings for `/mcp reauth`. */
23
+ export interface McpOAuthConfig {
24
+ clientId?: string;
25
+ clientSecret?: string;
26
+ scope?: string;
27
+ redirectUri?: string;
28
+ callbackPort?: number;
29
+ callbackPath?: string;
30
+ prompt?: string;
31
+ }
32
+
10
33
  export interface McpServerItem {
11
34
  id: string;
12
35
  name: string;
@@ -14,9 +37,55 @@ export interface McpServerItem {
14
37
  /** Absolute omp project root — meaningful only when scope is 'this-project'. */
15
38
  projectPath?: string;
16
39
  enabled: boolean;
17
- reachType: McpReachType;
40
+ transport: McpTransport;
18
41
  commandArgs: string[];
19
42
  linkUrl?: string;
20
- envVars: McpEnvVar[];
43
+ envVars: McpKeyValue[];
44
+ /** HTTP/SSE request headers. */
45
+ headers: McpKeyValue[];
46
+ /** Working directory for a stdio server. */
47
+ cwd?: string;
48
+ /** Per-request timeout in milliseconds; 0 disables client-side timeouts. */
49
+ timeout?: number;
50
+ requestIdFormat?: 'string' | 'number';
51
+ /** Include the server's own instructions in the system prompt. */
52
+ instructions?: boolean;
53
+ auth?: McpAuthConfig;
54
+ oauth?: McpOAuthConfig;
21
55
  status?: 'active' | 'inactive' | 'error';
22
56
  }
57
+
58
+ /** Where a session's server was declared. */
59
+ export type McpServerSource = 'user' | 'project' | 'custom' | 'plugin';
60
+
61
+ /** The answer of a real MCP handshake, cached for a minute server-side. */
62
+ export interface McpProbeResult {
63
+ ok: boolean;
64
+ error?: string;
65
+ toolCount: number;
66
+ durationMs: number;
67
+ /** Epoch ms of the handshake, so the UI can say how old the answer is. */
68
+ checkedAt: number;
69
+ }
70
+
71
+ /** One server as a SESSION sees it, with that session's override applied. */
72
+ export interface SessionMcpServer {
73
+ name: string;
74
+ transport: McpTransport;
75
+ source: McpServerSource;
76
+ enabled: boolean;
77
+ /** The last handshake, or null when this server was never probed. */
78
+ probe: McpProbeResult | null;
79
+ }
80
+
81
+ /** `GET /api/sessions/:sessionId/mcp` — the list and the switch behind it. */
82
+ export interface SessionMcpPayload {
83
+ sessionId: string;
84
+ harness: string | null;
85
+ /** How this harness receives MCP: a handshake argument or omp's config file. */
86
+ delivery: 'acp' | 'omp-config' | null;
87
+ live: boolean;
88
+ servers: SessionMcpServer[];
89
+ /** Only the names that differ from the configured state. */
90
+ overrides: Record<string, boolean>;
91
+ }
@@ -0,0 +1,53 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * The installer every DOM suite shares has to be a PAIR-wise swap.
8
+ *
9
+ * `installDomGlobals` exists because a suite that keeps its own save-and-restore
10
+ * loop captures whatever the previous file left behind and then restores the
11
+ * leak. The property that makes a dispatch work is narrower still: `Event` and
12
+ * `EventTarget` are one realm. Installing the constructor without the target it
13
+ * belongs to is what made the Ubuntu gate throw
14
+ * `Argument 1 ('event') to EventTarget.dispatchEvent must be an instance of
15
+ * Event` in a suite that names neither the installer nor the component.
16
+ */
17
+
18
+ import { afterAll, describe, expect, test } from 'bun:test';
19
+ import { Window } from 'happy-dom';
20
+
21
+ import { installDomGlobals, restoreDomGlobals } from '@/test-support/pristine-globals';
22
+
23
+ const nativeEvent = globalThis.Event;
24
+ const nativeEventTarget = globalThis.EventTarget;
25
+
26
+ afterAll(() => {
27
+ restoreDomGlobals();
28
+ });
29
+
30
+ describe('installDomGlobals', () => {
31
+ test('installs Event and EventTarget from the same window, so a dispatch works', () => {
32
+ const win = new Window({ url: 'http://localhost' });
33
+ installDomGlobals(win);
34
+
35
+ expect(globalThis.Event).toBe(win.Event as unknown as typeof Event);
36
+ expect(globalThis.EventTarget).toBe(win.EventTarget as unknown as typeof EventTarget);
37
+ // The point of the pair: the runner's target would refuse this event.
38
+ expect(() => {
39
+ new EventTarget().dispatchEvent(new Event('probe'));
40
+ }).not.toThrow();
41
+ });
42
+
43
+ test('restores the runner’s own constructors, never deletes them', () => {
44
+ installDomGlobals(new Window({ url: 'http://localhost' }));
45
+ restoreDomGlobals();
46
+
47
+ expect(globalThis.Event).toBe(nativeEvent);
48
+ expect(globalThis.EventTarget).toBe(nativeEventTarget);
49
+ expect(() => {
50
+ new EventTarget().dispatchEvent(new Event('probe'));
51
+ }).not.toThrow();
52
+ });
53
+ });
@@ -29,7 +29,12 @@ export const pristineWebSocket = globalThis.WebSocket;
29
29
  */
30
30
  export const DOM_TEST_GLOBALS = [
31
31
  'window', 'document', 'navigator', 'Node', 'Element', 'HTMLElement',
32
- 'Event', 'CustomEvent', 'WebSocket', 'EventSource',
32
+ // `EventTarget` travels WITH `Event`: the two are a single realm, and a
33
+ // suite that installed only the constructor made `target.dispatchEvent(new
34
+ // Event(...))` throw `Argument 1 ('event') … must be an instance of Event`
35
+ // for every later file that used a native target — measured on the Ubuntu
36
+ // gate, in a suite that names neither the installer nor the component.
37
+ 'Event', 'EventTarget', 'CustomEvent', 'WebSocket', 'EventSource',
33
38
  // The frame callbacks a component reads off `globalThis`, not off `window`.
34
39
  // `Toast` schedules its fade-in through a bare `requestAnimationFrame`, which
35
40
  // is the browser's own global — Bun defines neither, so a suite that mounts a