@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
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { ApprovalMode } from '@/shared/lib/omp/config/access-mode';
|
|
2
|
+
import { isOmpHarness } from '@/shared/lib/omp/config/access-mode';
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
|
-
* Composer labels for
|
|
5
|
+
* Composer labels for the tool-approval tiers (see ApprovalMode).
|
|
5
6
|
*
|
|
6
7
|
* The `yolo` copy is deliberately not "Everything runs without asking": omp
|
|
7
8
|
* 18.13.1 added `tools.restrictedFolders`, and a folder on that list asks in
|
|
@@ -21,3 +22,40 @@ export const ACCESS_LEVEL_DESCRIPTIONS: Record<ApprovalMode, string> = {
|
|
|
21
22
|
write: 'Reads and edits run automatically; shell commands ask first.',
|
|
22
23
|
yolo: 'Everything runs without asking — except a restricted folder, which always asks.',
|
|
23
24
|
};
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* The same three tiers on an agent that is NOT omp.
|
|
28
|
+
*
|
|
29
|
+
* There the tier is not a gate: the agent decides which calls it asks about
|
|
30
|
+
* (`session/request_permission`), and Kabmo only decides which of those arrive
|
|
31
|
+
* as a dialog. It can loosen the agent's own policy and never tighten it, and
|
|
32
|
+
* omp's `tools.restrictedFolders` rule does not exist — so the omp copy would
|
|
33
|
+
* promise a gate this transport cannot raise.
|
|
34
|
+
*/
|
|
35
|
+
const ACP_ACCESS_LEVEL_DESCRIPTIONS: Record<ApprovalMode, string> = {
|
|
36
|
+
'always-ask': 'Read-only calls are approved automatically; the agent’s writes and commands come to you.',
|
|
37
|
+
write: 'Reads and edits are approved automatically; the agent’s commands come to you.',
|
|
38
|
+
yolo: 'Every approval the agent asks for is granted automatically.',
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
export interface AccessLevelCopy {
|
|
42
|
+
labels: Record<ApprovalMode, string>;
|
|
43
|
+
descriptions: Record<ApprovalMode, string>;
|
|
44
|
+
/**
|
|
45
|
+
* What this transport's tier can and cannot decide, shown under the list.
|
|
46
|
+
* Absent for omp, whose tier IS the gate.
|
|
47
|
+
*/
|
|
48
|
+
note?: string;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** The copy for the harness the composer is about to run (or is running). */
|
|
52
|
+
export function accessLevelCopy(harness?: string | null): AccessLevelCopy {
|
|
53
|
+
if (isOmpHarness(harness)) {
|
|
54
|
+
return { labels: ACCESS_LEVEL_LABELS, descriptions: ACCESS_LEVEL_DESCRIPTIONS };
|
|
55
|
+
}
|
|
56
|
+
return {
|
|
57
|
+
labels: ACCESS_LEVEL_LABELS,
|
|
58
|
+
descriptions: ACP_ACCESS_LEVEL_DESCRIPTIONS,
|
|
59
|
+
note: 'This agent decides which calls it asks about; the pick answers those requests.',
|
|
60
|
+
};
|
|
61
|
+
}
|
|
@@ -133,14 +133,20 @@ describe('Eval — gutter aligns with the code', () => {
|
|
|
133
133
|
// The pretty-printed result draws its own gutter, and it had the same
|
|
134
134
|
// mismatch (plus a `py-2` against the code's `p-2.5`).
|
|
135
135
|
const root = mount(evalTool({ output: '{"a": 1, "b": [2, 3]}', status: 'success' }));
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
136
|
+
// Located by CONTENT, not by index: `querySelectorAll(...)[1]` compared two
|
|
137
|
+
// unrelated columns on the Ubuntu gate, where the card drew one more
|
|
138
|
+
// `aria-hidden` decoration than this file assumed — and a comparison of the
|
|
139
|
+
// SCRIPT's box against the RESULT's number fails for a reason that has
|
|
140
|
+
// nothing to do with alignment.
|
|
141
|
+
const code = [...root.querySelectorAll('div.shiki')].find((el) =>
|
|
142
|
+
(el.textContent ?? '').includes('"b"'),
|
|
143
|
+
);
|
|
144
|
+
expect(code).toBeDefined();
|
|
145
|
+
const jsonGutter = code!.previousElementSibling as Element;
|
|
146
|
+
expect(jsonGutter?.getAttribute('aria-hidden')).toBe('true');
|
|
147
|
+
expect(boxOf(jsonGutter)).toEqual(boxOf(code!));
|
|
142
148
|
// `{"a": 1, "b": [2, 3]}` pretty-prints to 7 lines.
|
|
143
149
|
expect(jsonGutter.children).toHaveLength(7);
|
|
144
|
-
expect(code
|
|
150
|
+
expect(code!.children).toHaveLength(7);
|
|
145
151
|
});
|
|
146
152
|
});
|
|
@@ -25,7 +25,7 @@ import { h, render } from 'preact';
|
|
|
25
25
|
import { act } from 'preact/test-utils';
|
|
26
26
|
import { EditorPluginRail } from '@/client/components/workspace/editor/PluginRail';
|
|
27
27
|
import type { ResolvedPluginPanel } from '@/client/components/workspace/plugin-panel/resolve';
|
|
28
|
-
import { installDomGlobals } from '@/test-support/pristine-globals';
|
|
28
|
+
import { installDomGlobals, restoreDomGlobals } from '@/test-support/pristine-globals';
|
|
29
29
|
|
|
30
30
|
let container: HTMLElement | null = null;
|
|
31
31
|
|
|
@@ -77,6 +77,11 @@ afterEach(() => {
|
|
|
77
77
|
container.remove();
|
|
78
78
|
container = null;
|
|
79
79
|
}
|
|
80
|
+
// The window installed for THIS case is put back with it. Left in place, a
|
|
81
|
+
// happy-dom `Event` reached the next file that dispatched an event at a
|
|
82
|
+
// native `EventTarget` and threw `Argument 1 ('event') … must be an instance
|
|
83
|
+
// of Event` in a suite that names neither this file nor this component.
|
|
84
|
+
restoreDomGlobals();
|
|
80
85
|
});
|
|
81
86
|
|
|
82
87
|
describe('editor plugin rail', () => {
|
|
@@ -22,6 +22,21 @@ import {
|
|
|
22
22
|
watchPointerPress,
|
|
23
23
|
type HoldableViewport,
|
|
24
24
|
} from '@/client/components/workspace/terminal-panel/scroll-hold';
|
|
25
|
+
import { pristineDomGlobals } from '@/test-support/pristine-globals';
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* The runner's own `Event`/`EventTarget`, as a PAIR.
|
|
29
|
+
*
|
|
30
|
+
* This file dispatches synthetic events at a target it creates itself, so both
|
|
31
|
+
* have to come from one realm. Reading the globals at call time made the suite
|
|
32
|
+
* fail before it asserted anything whenever an earlier file had left a
|
|
33
|
+
* happy-dom window installed: `new Event(…)` was happy-dom's constructor and
|
|
34
|
+
* `new EventTarget()` the runner's, and `dispatchEvent` refused the event. The
|
|
35
|
+
* captured values are the runner's own (see `pristine-globals.ts`), with the
|
|
36
|
+
* live globals as the fallback for a run where no suite installed a window yet.
|
|
37
|
+
*/
|
|
38
|
+
const EventCtor = (pristineDomGlobals.Event ?? globalThis.Event) as typeof Event;
|
|
39
|
+
const EventTargetCtor = (pristineDomGlobals.EventTarget ?? globalThis.EventTarget) as typeof EventTarget;
|
|
25
40
|
|
|
26
41
|
/** A viewport whose scrollback grows by `appended` lines on every write. */
|
|
27
42
|
function fakeViewport(options: { scrollback: number; viewportY: number; appended: number; hasSelection?: boolean }) {
|
|
@@ -126,15 +141,15 @@ describe('holdAcrossWrite', () => {
|
|
|
126
141
|
|
|
127
142
|
describe('watchPointerPress', () => {
|
|
128
143
|
/** A container that is an event target but not a DOM element — all the watcher touches. */
|
|
129
|
-
const container = () => new
|
|
144
|
+
const container = () => new EventTargetCtor() as unknown as HTMLElement;
|
|
130
145
|
|
|
131
146
|
test('holds from the press and lets go on release', () => {
|
|
132
147
|
const element = container();
|
|
133
148
|
const watch = watchPointerPress(element);
|
|
134
149
|
expect(watch.pointerHeld).toBe(false);
|
|
135
|
-
element.dispatchEvent(new
|
|
150
|
+
element.dispatchEvent(new EventCtor('pointerdown'));
|
|
136
151
|
expect(watch.pointerHeld).toBe(true);
|
|
137
|
-
globalThis.dispatchEvent(new
|
|
152
|
+
globalThis.dispatchEvent(new EventCtor('pointerup'));
|
|
138
153
|
expect(watch.pointerHeld).toBe(false);
|
|
139
154
|
watch.stop();
|
|
140
155
|
});
|
|
@@ -142,8 +157,8 @@ describe('watchPointerPress', () => {
|
|
|
142
157
|
test('a cancelled gesture ends the hold, not a stuck viewport', () => {
|
|
143
158
|
const element = container();
|
|
144
159
|
const watch = watchPointerPress(element);
|
|
145
|
-
element.dispatchEvent(new
|
|
146
|
-
globalThis.dispatchEvent(new
|
|
160
|
+
element.dispatchEvent(new EventCtor('pointerdown'));
|
|
161
|
+
globalThis.dispatchEvent(new EventCtor('pointercancel'));
|
|
147
162
|
expect(watch.pointerHeld).toBe(false);
|
|
148
163
|
watch.stop();
|
|
149
164
|
});
|
|
@@ -6,9 +6,10 @@ export const DEFAULT_MCP_SERVERS: McpServerItem[] = [
|
|
|
6
6
|
name: 'codegraph',
|
|
7
7
|
scope: 'every-project',
|
|
8
8
|
enabled: true,
|
|
9
|
-
|
|
9
|
+
transport: 'stdio',
|
|
10
10
|
commandArgs: ['codegraph', 'serve', '--mcp'],
|
|
11
11
|
envVars: [],
|
|
12
|
+
headers: [],
|
|
12
13
|
status: 'active',
|
|
13
14
|
},
|
|
14
15
|
{
|
|
@@ -16,13 +17,14 @@ export const DEFAULT_MCP_SERVERS: McpServerItem[] = [
|
|
|
16
17
|
name: 'needmcp',
|
|
17
18
|
scope: 'every-project',
|
|
18
19
|
enabled: true,
|
|
19
|
-
|
|
20
|
+
transport: 'http',
|
|
20
21
|
commandArgs: [],
|
|
21
22
|
linkUrl: 'https://needmcp.com/mcp',
|
|
22
23
|
envVars: [
|
|
23
24
|
{ id: 'env-1', key: 'NEEDMCP_API_KEY', value: 'nm_live_89f02c91b4e672' },
|
|
24
25
|
{ id: 'env-2', key: 'DEFAULT_TIMEOUT_MS', value: '5000' },
|
|
25
26
|
],
|
|
27
|
+
headers: [],
|
|
26
28
|
status: 'active',
|
|
27
29
|
},
|
|
28
30
|
];
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"source": "@oh-my-pi/pi-coding-agent 10 tabs /
|
|
2
|
+
"source": "@oh-my-pi/pi-coding-agent 10 tabs / 615 settings",
|
|
3
3
|
"tabs": [
|
|
4
4
|
{
|
|
5
5
|
"id": "appearance",
|
|
@@ -90,6 +90,7 @@
|
|
|
90
90
|
"Available Tools",
|
|
91
91
|
"Todos",
|
|
92
92
|
"Grep & Browser",
|
|
93
|
+
"Find",
|
|
93
94
|
"Computer",
|
|
94
95
|
"Execution",
|
|
95
96
|
"GitHub",
|
|
@@ -2028,7 +2029,7 @@
|
|
|
2028
2029
|
"tab": "model",
|
|
2029
2030
|
"group": "Thinking",
|
|
2030
2031
|
"label": "Tool-Call Loop Exempt Tools",
|
|
2031
|
-
"description": "Tool names that may repeat consecutively without triggering the cross-turn loop guard"
|
|
2032
|
+
"description": "Tool names, or xd:// device names of write dispatches (for example mcp__peers_wait), that may repeat consecutively without triggering the cross-turn loop guard"
|
|
2032
2033
|
}
|
|
2033
2034
|
},
|
|
2034
2035
|
"inlineToolDescriptors": {
|
|
@@ -2083,6 +2084,16 @@
|
|
|
2083
2084
|
"description": "Render the workspace directory tree in the system prompt. WARNING: This can bust prompt caching across sessions when files are modified."
|
|
2084
2085
|
}
|
|
2085
2086
|
},
|
|
2087
|
+
"encourageEdits": {
|
|
2088
|
+
"type": "boolean",
|
|
2089
|
+
"default": true,
|
|
2090
|
+
"ui": {
|
|
2091
|
+
"tab": "model",
|
|
2092
|
+
"group": "Prompt",
|
|
2093
|
+
"label": "Encourage Edits",
|
|
2094
|
+
"description": "Require the edit tool for file edits and forbid sed/perl/python edits"
|
|
2095
|
+
}
|
|
2096
|
+
},
|
|
2086
2097
|
"skillful": {
|
|
2087
2098
|
"type": "boolean",
|
|
2088
2099
|
"default": true,
|
|
@@ -6506,6 +6517,15 @@
|
|
|
6506
6517
|
"description": "Enable the ast_edit tool for structural AST rewrites"
|
|
6507
6518
|
}
|
|
6508
6519
|
},
|
|
6520
|
+
"find.verifyModel": {
|
|
6521
|
+
"type": "string",
|
|
6522
|
+
"ui": {
|
|
6523
|
+
"tab": "tools",
|
|
6524
|
+
"group": "Find",
|
|
6525
|
+
"label": "Find Verification Model",
|
|
6526
|
+
"description": "Model selector (e.g. openrouter/liquid/d1-ultra) tried first for find's passage verification, before the judge role; filename and sketch ranking stay on the judge role. Unset: the judge role verifies too"
|
|
6527
|
+
}
|
|
6528
|
+
},
|
|
6509
6529
|
"find.enabled": {
|
|
6510
6530
|
"type": "enum",
|
|
6511
6531
|
"default": "auto",
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The Browser Agent panel's engine probe: which engine the agent will use, and
|
|
8
|
+
* the one write that makes the panel able to mirror it.
|
|
9
|
+
*
|
|
10
|
+
* The panel mirrors Chromium over CDP; omp's WebKit engine has no CDP endpoint.
|
|
11
|
+
* So the panel asks `/api/browser/engine` before it explains an empty view, and
|
|
12
|
+
* its button sets `browser.webkit = false` through the same route. The write
|
|
13
|
+
* takes effect for the NEXT open (omp reads the key at open time), which is why
|
|
14
|
+
* the caller reconnects the stream after a successful switch.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { useCallback, useEffect, useState } from 'preact/hooks';
|
|
18
|
+
import type { BrowserEnginePayload } from '@/shared/types';
|
|
19
|
+
|
|
20
|
+
export interface BrowserEngineController {
|
|
21
|
+
/** The last answer, or null until the first one lands. */
|
|
22
|
+
state: BrowserEnginePayload | null;
|
|
23
|
+
loading: boolean;
|
|
24
|
+
/** A switch to Chromium is in flight. */
|
|
25
|
+
saving: boolean;
|
|
26
|
+
/** The server's own refusal, or a transport failure. */
|
|
27
|
+
error: string | null;
|
|
28
|
+
refresh: () => void;
|
|
29
|
+
/** Set `browser.webkit = false`; resolves true when the server accepted it. */
|
|
30
|
+
useChromium: () => Promise<boolean>;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function readError(data: unknown): string | null {
|
|
34
|
+
if (typeof data !== 'object' || data === null || !('error' in data)) return null;
|
|
35
|
+
return typeof data.error === 'string' ? data.error : null;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function useBrowserEngine(): BrowserEngineController {
|
|
39
|
+
const [state, setState] = useState<BrowserEnginePayload | null>(null);
|
|
40
|
+
const [loading, setLoading] = useState(true);
|
|
41
|
+
const [saving, setSaving] = useState(false);
|
|
42
|
+
const [error, setError] = useState<string | null>(null);
|
|
43
|
+
const [nonce, setNonce] = useState(0);
|
|
44
|
+
|
|
45
|
+
useEffect(() => {
|
|
46
|
+
let cancelled = false;
|
|
47
|
+
setLoading(true);
|
|
48
|
+
fetch('/api/browser/engine')
|
|
49
|
+
.then((res) => res.json())
|
|
50
|
+
.then((data: unknown) => {
|
|
51
|
+
if (cancelled) return;
|
|
52
|
+
const failure = readError(data);
|
|
53
|
+
if (failure) {
|
|
54
|
+
setError(failure);
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
setState(data as BrowserEnginePayload);
|
|
58
|
+
setError(null);
|
|
59
|
+
})
|
|
60
|
+
.catch((err) => {
|
|
61
|
+
if (!cancelled) setError(err instanceof Error ? err.message : String(err));
|
|
62
|
+
})
|
|
63
|
+
.finally(() => {
|
|
64
|
+
if (!cancelled) setLoading(false);
|
|
65
|
+
});
|
|
66
|
+
return () => {
|
|
67
|
+
cancelled = true;
|
|
68
|
+
};
|
|
69
|
+
}, [nonce]);
|
|
70
|
+
|
|
71
|
+
const refresh = useCallback(() => setNonce((value) => value + 1), []);
|
|
72
|
+
|
|
73
|
+
const useChromium = useCallback(async (): Promise<boolean> => {
|
|
74
|
+
setSaving(true);
|
|
75
|
+
setError(null);
|
|
76
|
+
try {
|
|
77
|
+
const res = await fetch('/api/browser/engine', {
|
|
78
|
+
method: 'POST',
|
|
79
|
+
headers: { 'Content-Type': 'application/json' },
|
|
80
|
+
body: JSON.stringify({ webkit: false }),
|
|
81
|
+
});
|
|
82
|
+
const data: unknown = await res.json().catch(() => null);
|
|
83
|
+
const failure = readError(data) ?? (res.ok ? null : `The write answered ${res.status}`);
|
|
84
|
+
if (failure) {
|
|
85
|
+
setError(failure);
|
|
86
|
+
return false;
|
|
87
|
+
}
|
|
88
|
+
setState(data as BrowserEnginePayload);
|
|
89
|
+
return true;
|
|
90
|
+
} catch (err) {
|
|
91
|
+
setError(err instanceof Error ? err.message : String(err));
|
|
92
|
+
return false;
|
|
93
|
+
} finally {
|
|
94
|
+
setSaving(false);
|
|
95
|
+
}
|
|
96
|
+
}, []);
|
|
97
|
+
|
|
98
|
+
return { state, loading, saving, error, refresh, useChromium };
|
|
99
|
+
}
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The MCP servers the open session has, the switch that changes them for that
|
|
8
|
+
* session only, and the on-demand connection probe behind the status icon.
|
|
9
|
+
*
|
|
10
|
+
* The list is read from the server, not derived in the browser: the merge
|
|
11
|
+
* (user file, project file, app-local rows, plugins) and the session's own
|
|
12
|
+
* overrides live in one place, and a second derivation here would drift from
|
|
13
|
+
* what the spawn path actually delivered.
|
|
14
|
+
*
|
|
15
|
+
* A toggle is optimistic only in the sense that the response carries the new
|
|
16
|
+
* list: the server answers with the state it persisted, so a refused write
|
|
17
|
+
* leaves the checkbox where it was instead of showing a change that did not
|
|
18
|
+
* happen. A probe is explicit — it starts a second instance of the server — so
|
|
19
|
+
* it runs when the info control is pressed, never on mount.
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
import { useCallback, useEffect, useState } from 'preact/hooks';
|
|
23
|
+
import type { McpProbeResult, SessionMcpPayload, SessionMcpServer } from '@/shared/types';
|
|
24
|
+
|
|
25
|
+
export interface SessionMcpState {
|
|
26
|
+
servers: SessionMcpServer[];
|
|
27
|
+
delivery: SessionMcpPayload['delivery'];
|
|
28
|
+
live: boolean;
|
|
29
|
+
loading: boolean;
|
|
30
|
+
error: string | null;
|
|
31
|
+
/** The server name whose toggle is in flight, if any. */
|
|
32
|
+
pending: string | null;
|
|
33
|
+
/** The server name whose handshake is in flight, if any. */
|
|
34
|
+
checking: string | null;
|
|
35
|
+
toggle: (name: string, enabled: boolean) => Promise<void>;
|
|
36
|
+
probe: (name: string) => Promise<void>;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function useSessionMcp(sessionId: string | null): SessionMcpState {
|
|
40
|
+
const [payload, setPayload] = useState<SessionMcpPayload | null>(null);
|
|
41
|
+
const [loading, setLoading] = useState(false);
|
|
42
|
+
const [error, setError] = useState<string | null>(null);
|
|
43
|
+
const [pending, setPending] = useState<string | null>(null);
|
|
44
|
+
const [checking, setChecking] = useState<string | null>(null);
|
|
45
|
+
|
|
46
|
+
useEffect(() => {
|
|
47
|
+
// Dropped on a session change so the previous chat's servers cannot be
|
|
48
|
+
// drawn under the new title while the read is in flight.
|
|
49
|
+
setPayload(null);
|
|
50
|
+
setError(null);
|
|
51
|
+
if (!sessionId) return;
|
|
52
|
+
let cancelled = false;
|
|
53
|
+
setLoading(true);
|
|
54
|
+
fetch(`/api/sessions/${encodeURIComponent(sessionId)}/mcp`)
|
|
55
|
+
.then(async (response) => {
|
|
56
|
+
const data: unknown = await response.json().catch(() => null);
|
|
57
|
+
if (!response.ok) {
|
|
58
|
+
const message = data && typeof data === 'object' && 'error' in data ? String(data.error) : `HTTP ${response.status}`;
|
|
59
|
+
throw new Error(message);
|
|
60
|
+
}
|
|
61
|
+
return data as SessionMcpPayload;
|
|
62
|
+
})
|
|
63
|
+
.then((data) => {
|
|
64
|
+
if (!cancelled) setPayload(data);
|
|
65
|
+
})
|
|
66
|
+
.catch((cause: unknown) => {
|
|
67
|
+
if (!cancelled) setError(cause instanceof Error ? cause.message : String(cause));
|
|
68
|
+
})
|
|
69
|
+
.finally(() => {
|
|
70
|
+
if (!cancelled) setLoading(false);
|
|
71
|
+
});
|
|
72
|
+
return () => {
|
|
73
|
+
cancelled = true;
|
|
74
|
+
};
|
|
75
|
+
}, [sessionId]);
|
|
76
|
+
|
|
77
|
+
const toggle = useCallback(
|
|
78
|
+
async (name: string, enabled: boolean) => {
|
|
79
|
+
if (!sessionId) return;
|
|
80
|
+
setPending(name);
|
|
81
|
+
setError(null);
|
|
82
|
+
try {
|
|
83
|
+
const response = await fetch(`/api/sessions/${encodeURIComponent(sessionId)}/mcp`, {
|
|
84
|
+
method: 'POST',
|
|
85
|
+
headers: { 'Content-Type': 'application/json' },
|
|
86
|
+
body: JSON.stringify({ name, enabled }),
|
|
87
|
+
});
|
|
88
|
+
const data: unknown = await response.json().catch(() => null);
|
|
89
|
+
if (!response.ok) {
|
|
90
|
+
const message = data && typeof data === 'object' && 'error' in data ? String(data.error) : `HTTP ${response.status}`;
|
|
91
|
+
throw new Error(message);
|
|
92
|
+
}
|
|
93
|
+
const next = data as { servers?: SessionMcpServer[]; overrides?: Record<string, boolean> };
|
|
94
|
+
setPayload((previous) =>
|
|
95
|
+
previous
|
|
96
|
+
? {
|
|
97
|
+
...previous,
|
|
98
|
+
servers: next.servers ?? previous.servers,
|
|
99
|
+
overrides: next.overrides ?? previous.overrides,
|
|
100
|
+
}
|
|
101
|
+
: previous,
|
|
102
|
+
);
|
|
103
|
+
} catch (cause) {
|
|
104
|
+
setError(cause instanceof Error ? cause.message : String(cause));
|
|
105
|
+
} finally {
|
|
106
|
+
setPending(null);
|
|
107
|
+
}
|
|
108
|
+
},
|
|
109
|
+
[sessionId],
|
|
110
|
+
);
|
|
111
|
+
|
|
112
|
+
const probe = useCallback(
|
|
113
|
+
async (name: string) => {
|
|
114
|
+
if (!sessionId) return;
|
|
115
|
+
setChecking(name);
|
|
116
|
+
setError(null);
|
|
117
|
+
try {
|
|
118
|
+
const response = await fetch(`/api/sessions/${encodeURIComponent(sessionId)}/mcp/probe`, {
|
|
119
|
+
method: 'POST',
|
|
120
|
+
headers: { 'Content-Type': 'application/json' },
|
|
121
|
+
body: JSON.stringify({ name }),
|
|
122
|
+
});
|
|
123
|
+
const data: unknown = await response.json().catch(() => null);
|
|
124
|
+
if (!response.ok) {
|
|
125
|
+
const message = data && typeof data === 'object' && 'error' in data ? String(data.error) : `HTTP ${response.status}`;
|
|
126
|
+
throw new Error(message);
|
|
127
|
+
}
|
|
128
|
+
const result = data as McpProbeResult;
|
|
129
|
+
setPayload((previous) =>
|
|
130
|
+
previous
|
|
131
|
+
? {
|
|
132
|
+
...previous,
|
|
133
|
+
servers: previous.servers.map((server) =>
|
|
134
|
+
server.name === name ? { ...server, probe: result } : server,
|
|
135
|
+
),
|
|
136
|
+
}
|
|
137
|
+
: previous,
|
|
138
|
+
);
|
|
139
|
+
} catch (cause) {
|
|
140
|
+
setError(cause instanceof Error ? cause.message : String(cause));
|
|
141
|
+
} finally {
|
|
142
|
+
setChecking(null);
|
|
143
|
+
}
|
|
144
|
+
},
|
|
145
|
+
[sessionId],
|
|
146
|
+
);
|
|
147
|
+
|
|
148
|
+
return {
|
|
149
|
+
servers: payload?.servers ?? [],
|
|
150
|
+
delivery: payload?.delivery ?? null,
|
|
151
|
+
live: payload?.live ?? false,
|
|
152
|
+
loading,
|
|
153
|
+
error,
|
|
154
|
+
pending,
|
|
155
|
+
checking,
|
|
156
|
+
toggle,
|
|
157
|
+
probe,
|
|
158
|
+
};
|
|
159
|
+
}
|
|
@@ -4,15 +4,29 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
|
-
* Access-control (approval) mode for the composer
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
7
|
+
* Access-control (approval) mode for the composer.
|
|
8
|
+
*
|
|
9
|
+
* omp's transports use this as omp's own approval gate (a spawn flag over RPC,
|
|
10
|
+
* omp's `tools.approvalMode` over ACP). Every other harness only gets Kabmo's
|
|
11
|
+
* tier as the answer policy for `session/request_permission`, so the pick is
|
|
12
|
+
* kept PER HARNESS: switching the composer's harness tab must never carry a
|
|
13
|
+
* `yolo` chosen for omp onto an agent that never granted it. omp's own pick is
|
|
14
|
+
* mirrored into the global `omp_access_mode` key, which the server reads as its
|
|
15
|
+
* spawn-time default for the paths that carry no explicit selection.
|
|
16
|
+
*
|
|
17
|
+
* The value is mirrored into a ref so the send path reads the latest one
|
|
18
|
+
* without re-creating `executeSend`. Extracted from useChatTimeline so that
|
|
19
|
+
* hook stays under the repo's per-file size ceiling.
|
|
12
20
|
*/
|
|
13
21
|
|
|
14
22
|
import { useCallback, useRef, useState } from 'preact/hooks';
|
|
15
|
-
import {
|
|
23
|
+
import {
|
|
24
|
+
ACCESS_MODE_SETTING_KEY,
|
|
25
|
+
HARNESS_ACCESS_MODES_SETTING_KEY,
|
|
26
|
+
accessModeForHarness,
|
|
27
|
+
isOmpHarness,
|
|
28
|
+
readAccessModePicks,
|
|
29
|
+
} from '@/shared/lib/omp/config/access-mode';
|
|
16
30
|
import type { ApprovalMode } from '@/shared/lib/omp/config/access-mode';
|
|
17
31
|
import { writeSetting } from '@/shared/lib/settings/client';
|
|
18
32
|
|
|
@@ -23,19 +37,35 @@ export interface ChatTimelineAccessMode {
|
|
|
23
37
|
setAccessMode: (mode: ApprovalMode) => void;
|
|
24
38
|
}
|
|
25
39
|
|
|
26
|
-
export function useChatTimelineAccessMode(
|
|
27
|
-
|
|
40
|
+
export function useChatTimelineAccessMode(
|
|
41
|
+
appSettings: Record<string, any>,
|
|
42
|
+
harness?: string | null,
|
|
43
|
+
): ChatTimelineAccessMode {
|
|
44
|
+
const [picks, setPicks] = useState<Record<string, ApprovalMode>>({});
|
|
45
|
+
const picksRef = useRef(picks);
|
|
46
|
+
picksRef.current = picks;
|
|
47
|
+
const settingsRef = useRef(appSettings);
|
|
48
|
+
settingsRef.current = appSettings;
|
|
49
|
+
// The stored map is read on every render rather than captured at mount: the
|
|
50
|
+
// timeline can mount before `/api/settings` lands, and a captured copy left
|
|
51
|
+
// the composer on `always-ask` after the operator's own pick was on disk.
|
|
52
|
+
const stored = readAccessModePicks(appSettings);
|
|
53
|
+
// Derived, never stored: the harness can change under a pending chat (the
|
|
54
|
+
// tab strip), and this hook is the one place that turns that into a tier.
|
|
55
|
+
const accessMode = accessModeForHarness(harness, { ...stored, ...picks }, appSettings);
|
|
28
56
|
const accessModeRef = useRef<ApprovalMode>(accessMode);
|
|
29
57
|
accessModeRef.current = accessMode;
|
|
30
58
|
|
|
31
59
|
const setAccessMode = useCallback((mode: ApprovalMode) => {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
60
|
+
const key = harness ?? 'omp-rpc';
|
|
61
|
+
const next = { ...readAccessModePicks(settingsRef.current), ...picksRef.current, [key]: mode };
|
|
62
|
+
picksRef.current = next;
|
|
63
|
+
setPicks(next);
|
|
64
|
+
writeSetting(HARNESS_ACCESS_MODES_SETTING_KEY, next);
|
|
65
|
+
// The global key stays omp's spawn-time default (a scheduled task, a child
|
|
66
|
+
// spawn, a held prompt). Another harness reads its own entry, never this.
|
|
67
|
+
if (isOmpHarness(harness)) writeSetting(ACCESS_MODE_SETTING_KEY, mode);
|
|
68
|
+
}, [harness]);
|
|
39
69
|
|
|
40
70
|
return { accessMode, accessModeRef, setAccessMode };
|
|
41
71
|
}
|
|
@@ -138,9 +138,6 @@ export function useChatTimeline({
|
|
|
138
138
|
const { pendingComposerModelRef, pendingThinkingLevelRef, composerModelRef, deferredComposerPickRef, pendingHarnessRef } =
|
|
139
139
|
useComposerRefs(sessionId);
|
|
140
140
|
|
|
141
|
-
// Access control is a GLOBAL persisted preference, unlike per-session picks.
|
|
142
|
-
const { accessMode, accessModeRef, setAccessMode: handleAccessModeChange } = useChatTimelineAccessMode(appSettings);
|
|
143
|
-
|
|
144
141
|
// "Wait for session": the pick (first prompt or a NEXT one) and the ref the
|
|
145
142
|
// send reads. It is per-session UI state, so each chat keeps its own.
|
|
146
143
|
const waitingDependency = useWaitingDependencyChoice();
|
|
@@ -207,6 +204,13 @@ export function useChatTimeline({
|
|
|
207
204
|
);
|
|
208
205
|
const { modes, planReview } = useComposerModes(sessionId, chatHarness);
|
|
209
206
|
|
|
207
|
+
// Access control, remembered PER HARNESS: omp's transports carry omp's own
|
|
208
|
+
// approval gate, while another agent only receives Kabmo's tier as the answer
|
|
209
|
+
// policy for the approvals it raises — so a pick made for one agent must not
|
|
210
|
+
// follow the operator onto another.
|
|
211
|
+
const { accessMode, accessModeRef, setAccessMode: handleAccessModeChange } =
|
|
212
|
+
useChatTimelineAccessMode(appSettings, chatHarness);
|
|
213
|
+
|
|
210
214
|
const { steerOmpAgent, executeSend } = useChatTimelineSend({
|
|
211
215
|
folders,
|
|
212
216
|
selectedFolderId,
|
|
@@ -228,8 +228,8 @@ describe('useModeMarkers', () => {
|
|
|
228
228
|
});
|
|
229
229
|
|
|
230
230
|
describe('useChatTimelineAccessMode', () => {
|
|
231
|
-
function AccessProbe({ appSettings }: { appSettings: Record<string, any
|
|
232
|
-
const { accessMode, accessModeRef, setAccessMode } = useChatTimelineAccessMode(appSettings);
|
|
231
|
+
function AccessProbe({ appSettings, harness }: { appSettings: Record<string, any>; harness?: string }) {
|
|
232
|
+
const { accessMode, accessModeRef, setAccessMode } = useChatTimelineAccessMode(appSettings, harness);
|
|
233
233
|
return h(
|
|
234
234
|
'div',
|
|
235
235
|
null,
|
|
@@ -239,9 +239,9 @@ describe('useChatTimelineAccessMode', () => {
|
|
|
239
239
|
);
|
|
240
240
|
}
|
|
241
241
|
|
|
242
|
-
function paint(appSettings: Record<string, any
|
|
242
|
+
function paint(appSettings: Record<string, any>, harness?: string): HTMLElement {
|
|
243
243
|
container ??= document.body.appendChild(document.createElement('div'));
|
|
244
|
-
render(h(AccessProbe, { appSettings }), container as HTMLElement);
|
|
244
|
+
render(h(AccessProbe, { appSettings, ...(harness ? { harness } : {}) }), container as HTMLElement);
|
|
245
245
|
return container;
|
|
246
246
|
}
|
|
247
247
|
|
|
@@ -272,6 +272,35 @@ describe('useChatTimelineAccessMode', () => {
|
|
|
272
272
|
await drain();
|
|
273
273
|
expect(settingsPosts).toContain(JSON.stringify({ omp_access_mode: 'yolo' }));
|
|
274
274
|
});
|
|
275
|
+
|
|
276
|
+
test("another harness does not inherit omp's pick", () => {
|
|
277
|
+
// Measured shape of the defect: `Full bypass` picked on omp followed the
|
|
278
|
+
// operator to `claude`, whose auto-answered approvals were a grant nobody
|
|
279
|
+
// made for that agent.
|
|
280
|
+
expect(paint({ omp_access_mode: 'yolo' }, 'claude').querySelector('#mode')?.textContent).toBe('always-ask');
|
|
281
|
+
});
|
|
282
|
+
|
|
283
|
+
test("a pick on another harness is stored for that harness alone", async () => {
|
|
284
|
+
const el = paint({ omp_access_mode: 'always-ask' }, 'claude');
|
|
285
|
+
await act(async () => { (el.querySelector('#yolo') as HTMLButtonElement).click(); });
|
|
286
|
+
await drain();
|
|
287
|
+
expect(settingsPosts).toContain(JSON.stringify({ harness_access_modes: { claude: 'yolo' } }));
|
|
288
|
+
// omp's global key is the SERVER's spawn default and must not move here.
|
|
289
|
+
expect(settingsPosts.some((body) => body.includes('omp_access_mode'))).toBe(false);
|
|
290
|
+
});
|
|
291
|
+
|
|
292
|
+
test('switching the harness tab swaps in that harness’s own pick', async () => {
|
|
293
|
+
const el = paint({ harness_access_modes: { claude: 'write' }, omp_access_mode: 'yolo' }, 'omp-rpc');
|
|
294
|
+
expect(el.querySelector('#mode')?.textContent).toBe('yolo');
|
|
295
|
+
await act(async () => {
|
|
296
|
+
render(
|
|
297
|
+
h(AccessProbe, { appSettings: { harness_access_modes: { claude: 'write' }, omp_access_mode: 'yolo' }, harness: 'claude' }),
|
|
298
|
+
el,
|
|
299
|
+
);
|
|
300
|
+
});
|
|
301
|
+
expect(el.querySelector('#mode')?.textContent).toBe('write');
|
|
302
|
+
expect(el.querySelector('#ref')?.textContent).toBe('write');
|
|
303
|
+
});
|
|
275
304
|
});
|
|
276
305
|
|
|
277
306
|
describe('useComposerModes', () => {
|