@1agh/maude 2.2.0 → 2.3.1
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/apps/studio/acp/agents/auth.ts +241 -0
- package/apps/studio/acp/agents/catalog.ts +308 -0
- package/apps/studio/acp/agents/chat-key.ts +64 -0
- package/apps/studio/acp/agents/conformance.ts +1853 -0
- package/apps/studio/acp/agents/consent.ts +92 -0
- package/apps/studio/acp/agents/descriptor.ts +188 -0
- package/apps/studio/acp/agents/discover.ts +491 -0
- package/apps/studio/acp/agents/e2e-model.ts +58 -0
- package/apps/studio/acp/agents/health.ts +46 -0
- package/apps/studio/acp/agents/link-scan.ts +230 -0
- package/apps/studio/acp/agents/spawn.ts +164 -0
- package/apps/studio/acp/agents/state.ts +132 -0
- package/apps/studio/acp/ask-queue.ts +13 -4
- package/apps/studio/acp/bootstrap-brief.ts +16 -3
- package/apps/studio/acp/bridge.ts +709 -99
- package/apps/studio/acp/env.ts +43 -1
- package/apps/studio/acp/index.ts +428 -43
- package/apps/studio/acp/may-scope.ts +244 -21
- package/apps/studio/acp/policy/agent-home.ts +202 -0
- package/apps/studio/acp/policy/bridge-gate.ts +68 -0
- package/apps/studio/acp/policy/codex-home.ts +228 -0
- package/apps/studio/acp/policy/enforce.ts +620 -0
- package/apps/studio/acp/policy/gate-types.ts +41 -0
- package/apps/studio/acp/policy/launch-codex.ts +351 -0
- package/apps/studio/acp/policy/launch-copilot.ts +119 -0
- package/apps/studio/acp/policy/launch-gemini.ts +120 -0
- package/apps/studio/acp/policy/launch-opencode.ts +131 -0
- package/apps/studio/acp/policy/opencode-user-config.ts +240 -0
- package/apps/studio/acp/probe.ts +78 -14
- package/apps/studio/acp/transcript.ts +14 -0
- package/apps/studio/acp/write-scope.ts +62 -2
- package/apps/studio/canvas-pages-view.tsx +3 -2
- package/apps/studio/canvas-theme-pill.tsx +125 -72
- package/apps/studio/client/panels/ChatPanel.jsx +19 -4
- package/apps/studio/client/panels/PermissionPrompt.jsx +11 -6
- package/apps/studio/client/panels/acp-runtime.js +95 -7
- package/apps/studio/client/v2/ai/Advanced.jsx +4 -3
- package/apps/studio/client/v2/ai/AgentNotice.jsx +138 -0
- package/apps/studio/client/v2/ai/AgentOffer.jsx +110 -0
- package/apps/studio/client/v2/ai/AgentPicker.jsx +121 -0
- package/apps/studio/client/v2/ai/Composer.jsx +4 -0
- package/apps/studio/client/v2/ai/ConnectSheet.jsx +13 -0
- package/apps/studio/client/v2/ai/Feed.jsx +8 -0
- package/apps/studio/client/v2/ai/NeedsYouSlot.jsx +24 -1
- package/apps/studio/client/v2/ai/Suggest.jsx +5 -1
- package/apps/studio/client/v2/ai/advanced-model.js +17 -6
- package/apps/studio/client/v2/ai/agents-model.js +333 -0
- package/apps/studio/client/v2/ai/agents-store.js +223 -0
- package/apps/studio/client/v2/ai/ai.css +63 -0
- package/apps/studio/client/v2/ai/needs-you.js +1 -1
- package/apps/studio/client/v2/fold/fold-store.js +1 -0
- package/apps/studio/client/v2/left-panel/left-panel.css +8 -0
- package/apps/studio/client/v2/settings/agent-keys.js +88 -0
- package/apps/studio/client/v2/settings/agents-card.jsx +408 -0
- package/apps/studio/client/v2/settings/connections-model.js +1 -1
- package/apps/studio/client/v2/settings/connections-section.jsx +4 -0
- package/apps/studio/client/v2/settings/settings-cards.js +2 -1
- package/apps/studio/client/v2/settings/settings-model.js +1 -0
- package/apps/studio/client/v2/settings/settings.css +7 -0
- package/apps/studio/client/v2/shell/served-routes.js +1 -0
- package/apps/studio/cloud-build.ts +5 -0
- package/apps/studio/dist/client.bundle.js +604 -604
- package/apps/studio/dist/styles.css +1 -1
- package/apps/studio/ds/board/board.css +4 -78
- package/apps/studio/ds/board/ds-bar.tsx +15 -9
- package/apps/studio/generation/keys.ts +197 -11
- package/apps/studio/outbox/policy.ts +8 -2
- package/apps/studio/outbox/types.ts +5 -0
- package/apps/studio/routes/agents.ts +479 -0
- package/apps/studio/routes/index.ts +3 -0
- package/apps/studio/scripts/acp-conformance-local.ts +95 -0
- package/apps/studio/scripts/acp-e2e-local.ts +1026 -0
- package/apps/studio/server.ts +9 -0
- package/apps/studio/sync/writer-registry.ts +12 -0
- package/apps/studio/whats-new.json +19 -0
- package/apps/studio/ws.ts +3 -0
- package/cli/commands/codex.mjs +36 -2
- package/cli/lib/harness/codex-runtime.mjs +98 -11
- package/package.json +9 -8
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
// F4 (B3) — opencode's launch policy: the agent-native boundary Maude writes per session.
|
|
2
|
+
// Contract: .ai/plans/notes/universal-acp-contract.md § "Launch policies" + DDR-252.
|
|
3
|
+
//
|
|
4
|
+
// opencode has no OS sandbox; its own permission engine is the read boundary. Measured (B0,
|
|
5
|
+
// opencode-mock-extdir-nongit): under `external_directory:"deny"` opencode itself refuses outside
|
|
6
|
+
// read / write / glob and `bash cat ../x`. The boundary is the GIT ROOT, not cwd (a named gap).
|
|
7
|
+
//
|
|
8
|
+
// - `read:"allow"`: a `read:"ask"` request reaches the bridge with no path (`locations:[]`,
|
|
9
|
+
// `rawInput:{}`) and is unclassifiable, so reads are left to `external_directory`.
|
|
10
|
+
// - `edit`/`bash:"ask"`: every write and shell call reaches the bridge's gate (enforce.ts).
|
|
11
|
+
// - `webfetch`/`websearch:"deny"`: removes the tools. Stays denied when the person's "Search the web"
|
|
12
|
+
// switch is ON: Maude's web tools are separate and gated by the bridge (narrower reading; see
|
|
13
|
+
// launch-codex.ts).
|
|
14
|
+
// - The block is repeated at `agent.build.permission` and `agent.plan.permission` (B0 open q. 6): an
|
|
15
|
+
// agent-level block in the person's global config may beat the global one.
|
|
16
|
+
// - The person's own MCP servers and plugins (open q. 3) would run outside every gate. `mcp:{}` MERGES
|
|
17
|
+
// with the global opencode.json (measured, F6), so F6b names each of the person's servers
|
|
18
|
+
// `enabled:false` (opencode-user-config.ts reads them at spawn), and OPENCODE_PURE=1 skips every
|
|
19
|
+
// external plugin, config-listed or in a plugin folder (measured, F6b).
|
|
20
|
+
//
|
|
21
|
+
// Pure: no file system, no process.
|
|
22
|
+
|
|
23
|
+
import type { LaunchPolicy, PolicyCtx } from '../agents/descriptor.ts';
|
|
24
|
+
import { absPath, inside, rootPath } from './launch-codex.ts';
|
|
25
|
+
import { disabledMcp, type PersonOpencodeConfig } from './opencode-user-config.ts';
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* B0 open question 2: `external_directory` as a path map that re-allows the read roots.
|
|
29
|
+
*
|
|
30
|
+
* Measured in F4 (contract note, "F4 measurement"; opencode 1.18.30, project outside git): a map
|
|
31
|
+
* `{"*":"deny","<root>/**":"allow",…}` re-allows read / glob / `bash cat` under a root and keeps
|
|
32
|
+
* everything else refused. Rules are LAST MATCH WINS (a credential deny written before the allow
|
|
33
|
+
* was overridden), so the order in `externalDirectory` is load-bearing. `grep`/`glob` are judged by
|
|
34
|
+
* their SEARCH root only: a grep over an allowed root read a credential file inside it. Hence a
|
|
35
|
+
* root that contains (or sits in) a credential store is never re-allowed.
|
|
36
|
+
*
|
|
37
|
+
* `true` = the measured map; `false` = the string `"deny"` (B0), which leaves every read root
|
|
38
|
+
* outside the git root unreadable for opencode.
|
|
39
|
+
*/
|
|
40
|
+
export const OPENCODE_EXTERNAL_DIRECTORY_MAP = true;
|
|
41
|
+
|
|
42
|
+
/** Env flags: never the served repo's own config, never ~/.claude, no updates/sharing/downloads. */
|
|
43
|
+
export const OPENCODE_FLAGS: Readonly<Record<string, string>> = Object.freeze({
|
|
44
|
+
// the served repo is untrusted (DDR-054 / DDR-144 F2 analog)
|
|
45
|
+
OPENCODE_DISABLE_PROJECT_CONFIG: '1',
|
|
46
|
+
// don't import ~/.claude instructions/skills into a non-Claude agent
|
|
47
|
+
OPENCODE_DISABLE_CLAUDE_CODE: '1',
|
|
48
|
+
OPENCODE_DISABLE_AUTOUPDATE: '1',
|
|
49
|
+
OPENCODE_DISABLE_SHARE: '1',
|
|
50
|
+
OPENCODE_DISABLE_LSP_DOWNLOAD: '1',
|
|
51
|
+
// F6b — no external plugins at all (config `plugin` entries and plugin folders): a plugin is code
|
|
52
|
+
// that runs inside opencode's own process, outside every Maude gate.
|
|
53
|
+
OPENCODE_PURE: '1',
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
type Rule = 'allow' | 'ask' | 'deny';
|
|
57
|
+
|
|
58
|
+
/** The `external_directory` value: the map built from the read roots, or the string `"deny"`. */
|
|
59
|
+
export function externalDirectory(
|
|
60
|
+
ctx: PolicyCtx,
|
|
61
|
+
useMap: boolean = OPENCODE_EXTERNAL_DIRECTORY_MAP
|
|
62
|
+
): Rule | Record<string, Rule> {
|
|
63
|
+
const roots = ctx.readRoots.map((r) => rootPath(r, 'read root'));
|
|
64
|
+
const creds = [
|
|
65
|
+
...ctx.credentialPaths.dirs.map((d) => absPath(d, 'credential dir')),
|
|
66
|
+
...ctx.credentialPaths.files.map((f) => absPath(f, 'credential file')),
|
|
67
|
+
];
|
|
68
|
+
if (!useMap) return 'deny';
|
|
69
|
+
// A root on, in, or around a credential store is not re-allowed: grep/glob over it would reach
|
|
70
|
+
// the store's contents whatever the deny below says (measured).
|
|
71
|
+
const clear = (r: string) => !creds.some((c) => inside(r, c) || inside(c, r));
|
|
72
|
+
// Last match wins (measured): deny all, re-allow the roots, then deny the credential stores again.
|
|
73
|
+
const map: Record<string, Rule> = { '*': 'deny' };
|
|
74
|
+
for (const r of roots) if (clear(r)) map[`${r}/**`] = 'allow';
|
|
75
|
+
for (const c of creds) {
|
|
76
|
+
map[c] = 'deny';
|
|
77
|
+
map[`${c}/**`] = 'deny';
|
|
78
|
+
}
|
|
79
|
+
return map;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export function opencodePermission(
|
|
83
|
+
ctx: PolicyCtx,
|
|
84
|
+
useMap: boolean = OPENCODE_EXTERNAL_DIRECTORY_MAP
|
|
85
|
+
) {
|
|
86
|
+
return {
|
|
87
|
+
read: 'allow',
|
|
88
|
+
edit: 'ask',
|
|
89
|
+
bash: 'ask',
|
|
90
|
+
external_directory: externalDirectory(ctx, useMap),
|
|
91
|
+
webfetch: 'deny',
|
|
92
|
+
websearch: 'deny',
|
|
93
|
+
// Security review 2026-11-12 (attacker A4): no sub-agents. A `task` child runs as another opencode
|
|
94
|
+
// agent (`general`, `explore`, or one from the person's own config), whose own permission block
|
|
95
|
+
// wins over this one; Maude repeats its block only for build/plan. Measured on 1.18.30 with the
|
|
96
|
+
// conformance probe (contract note, "A4").
|
|
97
|
+
task: 'deny',
|
|
98
|
+
} as const;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** The person's config as far as the launch policy needs it: which MCP servers to switch off. */
|
|
102
|
+
export type OpencodePerson = Pick<PersonOpencodeConfig, 'mcpNames'>;
|
|
103
|
+
|
|
104
|
+
export function opencodeConfig(
|
|
105
|
+
ctx: PolicyCtx,
|
|
106
|
+
useMap: boolean = OPENCODE_EXTERNAL_DIRECTORY_MAP,
|
|
107
|
+
person: OpencodePerson = { mcpNames: [] }
|
|
108
|
+
) {
|
|
109
|
+
absPath(ctx.scopeRoot, 'scopeRoot');
|
|
110
|
+
for (const w of ctx.writeRoots) absPath(w, 'write root');
|
|
111
|
+
const permission = opencodePermission(ctx, useMap);
|
|
112
|
+
return {
|
|
113
|
+
permission,
|
|
114
|
+
agent: { build: { permission }, plan: { permission } },
|
|
115
|
+
mcp: disabledMcp(person.mcpNames),
|
|
116
|
+
plugin: [],
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export function opencodeLaunchPolicy(
|
|
121
|
+
ctx: PolicyCtx,
|
|
122
|
+
useMap: boolean = OPENCODE_EXTERNAL_DIRECTORY_MAP,
|
|
123
|
+
person: OpencodePerson = { mcpNames: [] }
|
|
124
|
+
): LaunchPolicy {
|
|
125
|
+
return {
|
|
126
|
+
env: {
|
|
127
|
+
OPENCODE_CONFIG_CONTENT: JSON.stringify(opencodeConfig(ctx, useMap, person)),
|
|
128
|
+
...OPENCODE_FLAGS,
|
|
129
|
+
},
|
|
130
|
+
};
|
|
131
|
+
}
|
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
// F6b — what of the person's own opencode config the Studio chat must switch off.
|
|
2
|
+
// Contract: .ai/plans/notes/universal-acp-contract.md § "F6b — MCP/hooks isolation and flip".
|
|
3
|
+
//
|
|
4
|
+
// opencode MERGES every config source (measured, F6): `mcp: {}` in OPENCODE_CONFIG_CONTENT leaves
|
|
5
|
+
// the person's MCP servers on, and they run outside every Maude gate. Unlike Codex, opencode keeps
|
|
6
|
+
// the person's providers and models in the same files, so the files cannot be shadowed. Instead,
|
|
7
|
+
// at every spawn, Maude reads the person's global config sources and names each MCP server there
|
|
8
|
+
// `enabled: false` in OPENCODE_CONFIG_CONTENT (applied after them, so the deep merge turns each one
|
|
9
|
+
// off; measured, F6b).
|
|
10
|
+
//
|
|
11
|
+
// Plugins and custom tools CANNOT be switched off (measured, F6b, 1.18.30): OPENCODE_PURE=1 stops a
|
|
12
|
+
// plugin from being activated, but opencode's config-plugin loader still `import()`s every module
|
|
13
|
+
// it finds — a config `plugin` entry and `{plugin,plugins}/*.{ts,js}` in each config folder — so
|
|
14
|
+
// the module's top-level code runs in opencode's own process, outside every Maude gate. That loader
|
|
15
|
+
// also reads the SERVED REPO's `.opencode/` folder (and every `.opencode` above it) although
|
|
16
|
+
// OPENCODE_DISABLE_PROJECT_CONFIG=1 is set: a planted `.opencode/plugins/x.js` ran. So, fail closed,
|
|
17
|
+
// opencode is refused when:
|
|
18
|
+
// • a global config source lists a plugin (`plugin` / `plugins`), or a global config folder holds
|
|
19
|
+
// `{plugin,plugins,tool,tools}/*.{ts,js,mjs,cjs}`;
|
|
20
|
+
// • the project folder or any folder above it (the person's home excepted: that one is a global
|
|
21
|
+
// folder, judged as above) has a `.opencode` entry at all — its agents (`agent/*.md`) can also
|
|
22
|
+
// carry their own permission blocks, which Maude's would have to out-rank.
|
|
23
|
+
//
|
|
24
|
+
// Sources read (opencode 1.18.30 `Config.loadInstanceState`; project config is already off through
|
|
25
|
+
// OPENCODE_DISABLE_PROJECT_CONFIG=1):
|
|
26
|
+
// • $XDG_CONFIG_HOME/opencode/{config.json, opencode.json, opencode.jsonc} (else ~/.config)
|
|
27
|
+
// • $OPENCODE_CONFIG (a file the person's env names)
|
|
28
|
+
// • ~/.opencode/{opencode.json, opencode.jsonc}
|
|
29
|
+
// • $OPENCODE_CONFIG_DIR/{opencode.json, opencode.jsonc}
|
|
30
|
+
// A remote "well-known" organisation config (an auth.json entry of type `wellknown`) is fetched by
|
|
31
|
+
// opencode at start and cannot be read offline, so its MCP servers cannot be named: refused.
|
|
32
|
+
//
|
|
33
|
+
// Fail closed: a source that exists but cannot be read or parsed (JSONC: comments and trailing
|
|
34
|
+
// commas are fine) refuses the spawn with a clear error. A missing file is no source.
|
|
35
|
+
|
|
36
|
+
import { existsSync, readdirSync, readFileSync } from 'node:fs';
|
|
37
|
+
import { homedir } from 'node:os';
|
|
38
|
+
import { dirname, isAbsolute, join, resolve } from 'node:path';
|
|
39
|
+
|
|
40
|
+
import { e2eSwitch, IS_RELEASE_BUILD } from '../../release-build.ts';
|
|
41
|
+
import type { HostEnv } from './codex-home.ts';
|
|
42
|
+
|
|
43
|
+
export class OpencodeConfigError extends Error {
|
|
44
|
+
constructor(message: string) {
|
|
45
|
+
super(message);
|
|
46
|
+
this.name = 'OpencodeConfigError';
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export interface PersonOpencodeConfig {
|
|
51
|
+
/** Every MCP server name the person's global config sources declare (deduplicated, in order). */
|
|
52
|
+
mcpNames: string[];
|
|
53
|
+
/** The files that were read. */
|
|
54
|
+
sources: string[];
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const REFUSE = 'Maude does not start opencode while it is there.';
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* The home the person's GLOBAL opencode sources are read under (`~/.opencode`, the `~/.config` and
|
|
61
|
+
* `~/.local/share` fallbacks). Only the universal-ACP desktop e2e lane moves it (`MAUDE_E2E_OPENCODE_HOME`,
|
|
62
|
+
* e2e sidecar builds only — release-build.ts `e2eSwitch`; a release build ignores it): the lane's fake
|
|
63
|
+
* opencode must not be refused for the developer's own opencode plugins. The project's `.opencode` chain
|
|
64
|
+
* (`projectOpencodeEntries`) always keeps the real HOME as its one exception.
|
|
65
|
+
*/
|
|
66
|
+
export function opencodePersonHome(env: HostEnv = process.env, release = IS_RELEASE_BUILD): string {
|
|
67
|
+
return abs(e2eSwitch(env, 'MAUDE_E2E_OPENCODE_HOME', release)) ?? abs(env.HOME) ?? homedir();
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** Global config folders opencode scans for plugins / tools / agents (existing or not). */
|
|
71
|
+
export function opencodeConfigDirs(env: HostEnv = process.env): string[] {
|
|
72
|
+
const home = opencodePersonHome(env);
|
|
73
|
+
const xdg = abs(env.XDG_CONFIG_HOME) ?? join(home, '.config');
|
|
74
|
+
const out = [join(xdg, 'opencode'), join(home, '.opencode')];
|
|
75
|
+
const dir = abs(env.OPENCODE_CONFIG_DIR);
|
|
76
|
+
if (dir) out.push(dir);
|
|
77
|
+
return [...new Set(out)];
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const CODE_RE = /\.(ts|js|mjs|cjs|tsx|jsx)$/i;
|
|
81
|
+
|
|
82
|
+
/** Executable code opencode would import from one config folder (`{plugin,plugins,tool,tools}/*`). */
|
|
83
|
+
export function opencodeCodeFiles(dir: string): string[] {
|
|
84
|
+
const out: string[] = [];
|
|
85
|
+
for (const sub of ['plugin', 'plugins', 'tool', 'tools']) {
|
|
86
|
+
let names: string[];
|
|
87
|
+
try {
|
|
88
|
+
names = readdirSync(join(dir, sub));
|
|
89
|
+
} catch (e) {
|
|
90
|
+
const code = (e as NodeJS.ErrnoException).code;
|
|
91
|
+
if (code === 'ENOENT' || code === 'ENOTDIR') continue;
|
|
92
|
+
throw new OpencodeConfigError(
|
|
93
|
+
`opencode's folder ${join(dir, sub)} could not be read. ${REFUSE}`
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
for (const n of names) if (CODE_RE.test(n)) out.push(join(dir, sub, n));
|
|
97
|
+
}
|
|
98
|
+
return out;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** `.opencode` entries in the project folder and every folder above it (the home folder excepted). */
|
|
102
|
+
export function projectOpencodeEntries(projectRoot: string, env: HostEnv = process.env): string[] {
|
|
103
|
+
const home = abs(env.HOME) ?? homedir();
|
|
104
|
+
const out: string[] = [];
|
|
105
|
+
let dir = resolve(projectRoot);
|
|
106
|
+
for (;;) {
|
|
107
|
+
if (dir !== home) {
|
|
108
|
+
const p = join(dir, '.opencode');
|
|
109
|
+
if (existsSync(p)) out.push(p);
|
|
110
|
+
}
|
|
111
|
+
const up = dirname(dir);
|
|
112
|
+
if (up === dir) break;
|
|
113
|
+
dir = up;
|
|
114
|
+
}
|
|
115
|
+
return out;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
const abs = (p: string | undefined) => (p && isAbsolute(p) ? resolve(p) : null);
|
|
119
|
+
|
|
120
|
+
/** The person's global opencode config files, in opencode's load order (existing or not). */
|
|
121
|
+
export function opencodeConfigSources(env: HostEnv = process.env): string[] {
|
|
122
|
+
const home = opencodePersonHome(env);
|
|
123
|
+
const xdg = abs(env.XDG_CONFIG_HOME) ?? join(home, '.config');
|
|
124
|
+
const out = ['config.json', 'opencode.json', 'opencode.jsonc'].map((f) =>
|
|
125
|
+
join(xdg, 'opencode', f)
|
|
126
|
+
);
|
|
127
|
+
const custom = abs(env.OPENCODE_CONFIG);
|
|
128
|
+
if (custom) out.push(custom);
|
|
129
|
+
for (const f of ['opencode.json', 'opencode.jsonc']) out.push(join(home, '.opencode', f));
|
|
130
|
+
const dir = abs(env.OPENCODE_CONFIG_DIR);
|
|
131
|
+
if (dir) for (const f of ['opencode.json', 'opencode.jsonc']) out.push(join(dir, f));
|
|
132
|
+
return [...new Set(out)];
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/** opencode's auth store (`$XDG_DATA_HOME/opencode/auth.json`). Only entry TYPES are looked at. */
|
|
136
|
+
export function opencodeAuthFile(env: HostEnv = process.env): string {
|
|
137
|
+
const home = opencodePersonHome(env);
|
|
138
|
+
return join(abs(env.XDG_DATA_HOME) ?? join(home, '.local', 'share'), 'opencode', 'auth.json');
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
function parseJsonc(text: string, file: string): unknown {
|
|
142
|
+
try {
|
|
143
|
+
return Bun.JSONC.parse(text);
|
|
144
|
+
} catch (e) {
|
|
145
|
+
throw new OpencodeConfigError(
|
|
146
|
+
`Your opencode config ${file} could not be read (${(e as Error).message}). Maude does not start opencode until it can see which MCP servers it must keep off.`
|
|
147
|
+
);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
const isObj = (v: unknown): v is Record<string, unknown> =>
|
|
152
|
+
typeof v === 'object' && v !== null && !Array.isArray(v);
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Read the person's global opencode config sources (and look at the project's `.opencode` chain
|
|
156
|
+
* when `projectRoot` is given). Throws OpencodeConfigError when opencode must not start (fail closed).
|
|
157
|
+
*/
|
|
158
|
+
export function readPersonOpencodeConfig(
|
|
159
|
+
env: HostEnv = process.env,
|
|
160
|
+
projectRoot?: string
|
|
161
|
+
): PersonOpencodeConfig {
|
|
162
|
+
const mcp = new Set<string>();
|
|
163
|
+
const plugins: string[] = [];
|
|
164
|
+
const sources: string[] = [];
|
|
165
|
+
for (const file of opencodeConfigSources(env)) {
|
|
166
|
+
if (!existsSync(file)) continue;
|
|
167
|
+
let text: string;
|
|
168
|
+
try {
|
|
169
|
+
text = readFileSync(file, 'utf8');
|
|
170
|
+
} catch (e) {
|
|
171
|
+
throw new OpencodeConfigError(
|
|
172
|
+
`Your opencode config ${file} could not be read (${(e as NodeJS.ErrnoException).code ?? 'error'}). Maude does not start opencode until it can see which MCP servers it must keep off.`
|
|
173
|
+
);
|
|
174
|
+
}
|
|
175
|
+
sources.push(file);
|
|
176
|
+
if (text.trim() === '') continue;
|
|
177
|
+
const cfg = parseJsonc(text, file);
|
|
178
|
+
if (!isObj(cfg)) {
|
|
179
|
+
throw new OpencodeConfigError(
|
|
180
|
+
`Your opencode config ${file} is not a JSON object. Maude does not start opencode until it can see which MCP servers it must keep off.`
|
|
181
|
+
);
|
|
182
|
+
}
|
|
183
|
+
if (cfg.mcp !== undefined) {
|
|
184
|
+
if (!isObj(cfg.mcp)) {
|
|
185
|
+
throw new OpencodeConfigError(
|
|
186
|
+
`Your opencode config ${file} has an \`mcp\` that is not an object.`
|
|
187
|
+
);
|
|
188
|
+
}
|
|
189
|
+
for (const name of Object.keys(cfg.mcp)) mcp.add(name);
|
|
190
|
+
}
|
|
191
|
+
for (const key of ['plugin', 'plugins']) {
|
|
192
|
+
const list = cfg[key];
|
|
193
|
+
if (list === undefined) continue;
|
|
194
|
+
if (!Array.isArray(list) || list.length > 0) plugins.push(`${file} (\`${key}\`)`);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
if (plugins.length) {
|
|
198
|
+
throw new OpencodeConfigError(
|
|
199
|
+
`Your opencode config lists plugins (${plugins.join(', ')}). opencode loads plugin code even when told not to, outside every limit Maude sets. ${REFUSE}`
|
|
200
|
+
);
|
|
201
|
+
}
|
|
202
|
+
for (const dir of opencodeConfigDirs(env)) {
|
|
203
|
+
const code = opencodeCodeFiles(dir);
|
|
204
|
+
if (code.length) {
|
|
205
|
+
throw new OpencodeConfigError(
|
|
206
|
+
`Your opencode folder has plugin or tool code (${code.slice(0, 3).join(', ')}${code.length > 3 ? ', …' : ''}). opencode loads it even when told not to, outside every limit Maude sets. ${REFUSE}`
|
|
207
|
+
);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
if (projectRoot) {
|
|
211
|
+
const found = projectOpencodeEntries(projectRoot, env);
|
|
212
|
+
if (found.length) {
|
|
213
|
+
throw new OpencodeConfigError(
|
|
214
|
+
`This project has an opencode folder (${found[0]}). opencode loads its plugins, tools and agents although Maude tells it to ignore project config. ${REFUSE}`
|
|
215
|
+
);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
const auth = opencodeAuthFile(env);
|
|
219
|
+
if (existsSync(auth)) {
|
|
220
|
+
let entries: unknown;
|
|
221
|
+
try {
|
|
222
|
+
entries = JSON.parse(readFileSync(auth, 'utf8'));
|
|
223
|
+
} catch {
|
|
224
|
+
throw new OpencodeConfigError(
|
|
225
|
+
`opencode's sign-in file ${auth} could not be read, so Maude cannot tell whether it names a remote organisation config. Maude does not start opencode.`
|
|
226
|
+
);
|
|
227
|
+
}
|
|
228
|
+
if (isObj(entries) && Object.values(entries).some((v) => isObj(v) && v.type === 'wellknown')) {
|
|
229
|
+
throw new OpencodeConfigError(
|
|
230
|
+
'opencode is signed in to an organisation that sends it a remote config, which may start MCP servers Maude cannot see. Maude does not start opencode.'
|
|
231
|
+
);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
return { mcpNames: [...mcp], sources };
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/** The `mcp` block that turns each named server off (an own key per name, `__proto__` included). */
|
|
238
|
+
export function disabledMcp(names: readonly string[]): Record<string, { enabled: false }> {
|
|
239
|
+
return Object.fromEntries(names.map((n) => [n, { enabled: false as const }]));
|
|
240
|
+
}
|
package/apps/studio/acp/probe.ts
CHANGED
|
@@ -10,13 +10,16 @@ import { createHash } from 'node:crypto';
|
|
|
10
10
|
import { existsSync, readFileSync, realpathSync } from 'node:fs';
|
|
11
11
|
import { dirname, join, win32 } from 'node:path';
|
|
12
12
|
|
|
13
|
+
import { claudeApiKeyOptedIn } from '../generation/keys.ts';
|
|
13
14
|
import { DEV_SERVER_ROOT, IS_COMPILED_BINARY } from '../paths.ts';
|
|
14
15
|
import { e2eSwitch, IS_RELEASE_BUILD } from '../release-build.ts';
|
|
16
|
+
import { CLAUDE } from './agents/catalog.ts';
|
|
17
|
+
import type { AgentDescriptor, AgentLaunch } from './agents/descriptor.ts';
|
|
15
18
|
import { scrubAgentEnv } from './env.ts';
|
|
16
19
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
const
|
|
20
|
+
type AdapterLaunch = Extract<AgentLaunch, { kind: 'adapter-js' }>;
|
|
21
|
+
/** Claude's adapter (`@agentclientprotocol/claude-agent-acp`, the continuation of `@zed-industries/claude-code-acp`). */
|
|
22
|
+
const CLAUDE_ADAPTER = CLAUDE.launch as AdapterLaunch;
|
|
20
23
|
|
|
21
24
|
export interface AcpAvailability {
|
|
22
25
|
/** True when both the adapter entry and a `claude` CLI are resolvable. */
|
|
@@ -25,29 +28,52 @@ export interface AcpAvailability {
|
|
|
25
28
|
reason?: string;
|
|
26
29
|
/** Absolute path to the adapter entry JS, or null. */
|
|
27
30
|
adapterEntry: string | null;
|
|
28
|
-
/** Absolute path to the `claude` CLI, or null. */
|
|
31
|
+
/** Absolute path to the `claude` CLI, or null (always null for another agent). */
|
|
29
32
|
claudePath: string | null;
|
|
33
|
+
/** F3 — which agent this answers for (the `ready` frame names it). */
|
|
34
|
+
agent?: AgentInfo;
|
|
35
|
+
/**
|
|
36
|
+
* B7 — 'api-key' when Claude runs on this profile's opted-in Anthropic API key (billed per token)
|
|
37
|
+
* instead of the Claude account; absent otherwise. The panel shows "API key" instead of the plan.
|
|
38
|
+
*/
|
|
39
|
+
billing?: 'api-key';
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** F3 — the agent as the panel names it (`ready` / `caps` frames). */
|
|
43
|
+
export interface AgentInfo {
|
|
44
|
+
id: string;
|
|
45
|
+
label: string;
|
|
46
|
+
vendor: string;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function agentInfoOf(d: AgentDescriptor): AgentInfo {
|
|
50
|
+
return { id: d.id, label: d.label, vendor: d.vendor };
|
|
30
51
|
}
|
|
31
52
|
|
|
32
53
|
/**
|
|
33
|
-
* Resolve
|
|
34
|
-
* 1. `MAUDE_ACP_ADAPTER_ENTRY` override (tests + escape hatch)
|
|
54
|
+
* Resolve an adapter's spawnable entry script (its `bin`), trying:
|
|
55
|
+
* 1. `MAUDE_ACP_ADAPTER_ENTRY` override (tests + escape hatch) — Claude's adapter only: no env
|
|
56
|
+
* var can point another agent's launch at a script of its choosing.
|
|
35
57
|
* 2. The package's own `package.json` `bin` field, joined to its dir.
|
|
36
58
|
* 3. The pnpm `.bin/<name>` symlink, dereferenced to the real file.
|
|
37
|
-
* Returns an absolute path or null.
|
|
59
|
+
* Returns an absolute path or null. Default: Claude's adapter (F3 — any `adapter-js` launch).
|
|
38
60
|
*/
|
|
39
|
-
export function resolveAdapterEntry(): string | null {
|
|
61
|
+
export function resolveAdapterEntry(launch: AdapterLaunch = CLAUDE_ADAPTER): string | null {
|
|
62
|
+
const pkgName = launch.adapterPkg;
|
|
63
|
+
const binName = launch.adapterBin;
|
|
40
64
|
const override = process.env.MAUDE_ACP_ADAPTER_ENTRY;
|
|
41
|
-
if (override
|
|
65
|
+
if (override && pkgName === CLAUDE_ADAPTER.adapterPkg) {
|
|
66
|
+
return existsSync(override) ? override : null;
|
|
67
|
+
}
|
|
42
68
|
|
|
43
69
|
// (2) Locate the installed package via its package.json, read the bin map.
|
|
44
70
|
try {
|
|
45
|
-
const pkgJsonPath = Bun.resolveSync(`${
|
|
71
|
+
const pkgJsonPath = Bun.resolveSync(`${pkgName}/package.json`, DEV_SERVER_ROOT);
|
|
46
72
|
const pkgDir = dirname(pkgJsonPath);
|
|
47
73
|
const pkg = JSON.parse(readFileSync(pkgJsonPath, 'utf8')) as {
|
|
48
74
|
bin?: string | Record<string, string>;
|
|
49
75
|
};
|
|
50
|
-
const binRel = typeof pkg.bin === 'string' ? pkg.bin : pkg.bin?.[
|
|
76
|
+
const binRel = typeof pkg.bin === 'string' ? pkg.bin : pkg.bin?.[binName];
|
|
51
77
|
if (binRel) {
|
|
52
78
|
const entry = join(pkgDir, binRel);
|
|
53
79
|
if (existsSync(entry)) return entry;
|
|
@@ -58,7 +84,7 @@ export function resolveAdapterEntry(): string | null {
|
|
|
58
84
|
|
|
59
85
|
// (3) The pnpm-linked bin symlink in the dev-server's own node_modules.
|
|
60
86
|
try {
|
|
61
|
-
const sym = join(DEV_SERVER_ROOT, 'node_modules', '.bin',
|
|
87
|
+
const sym = join(DEV_SERVER_ROOT, 'node_modules', '.bin', binName);
|
|
62
88
|
if (existsSync(sym)) return realpathSync(sym);
|
|
63
89
|
} catch {
|
|
64
90
|
/* not present */
|
|
@@ -255,7 +281,13 @@ export function resolveAgentRuntime(): { bin: string; bunBeBun: boolean } {
|
|
|
255
281
|
* `GET /_api/acp/status` and the WS `ready` frame. The actual ACP session spins
|
|
256
282
|
* up lazily on the first prompt.
|
|
257
283
|
*/
|
|
258
|
-
export function probeAcpAvailability(
|
|
284
|
+
export function probeAcpAvailability(
|
|
285
|
+
descriptor: AgentDescriptor = CLAUDE,
|
|
286
|
+
/** F3 — another agent's discovered real binary (discovery is acp/agents/discover.ts, F2). */
|
|
287
|
+
agentBin?: string | null
|
|
288
|
+
): AcpAvailability {
|
|
289
|
+
if (descriptor.id !== CLAUDE.id) return probeOtherAgent(descriptor, agentBin ?? null);
|
|
290
|
+
const agent = agentInfoOf(descriptor);
|
|
259
291
|
const adapterEntry = resolveAdapterEntry();
|
|
260
292
|
const claudePath = resolveClaudePath();
|
|
261
293
|
if (!adapterEntry) {
|
|
@@ -264,6 +296,7 @@ export function probeAcpAvailability(): AcpAvailability {
|
|
|
264
296
|
reason: 'The Claude agent bridge is not installed in this build.',
|
|
265
297
|
adapterEntry: null,
|
|
266
298
|
claudePath,
|
|
299
|
+
agent,
|
|
267
300
|
};
|
|
268
301
|
}
|
|
269
302
|
if (!claudePath) {
|
|
@@ -272,6 +305,7 @@ export function probeAcpAvailability(): AcpAvailability {
|
|
|
272
305
|
reason: "Claude Code isn't connected — run `claude` in a terminal and `/login`.",
|
|
273
306
|
adapterEntry,
|
|
274
307
|
claudePath: null,
|
|
308
|
+
agent,
|
|
275
309
|
};
|
|
276
310
|
}
|
|
277
311
|
if (!resolveAgentClaudeExecutable(claudePath)) {
|
|
@@ -281,9 +315,35 @@ export function probeAcpAvailability(): AcpAvailability {
|
|
|
281
315
|
'Claude Code was found only as an npm `claude.cmd` shim the chat cannot start. Reinstall it with the native installer (`irm https://claude.ai/install.ps1 | iex`).',
|
|
282
316
|
adapterEntry,
|
|
283
317
|
claudePath,
|
|
318
|
+
agent,
|
|
319
|
+
};
|
|
320
|
+
}
|
|
321
|
+
return { available: true, adapterEntry, claudePath, agent };
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
/** F3 — the same cheap check for an agent that is not Claude: its adapter (if any) and its binary. */
|
|
325
|
+
function probeOtherAgent(d: AgentDescriptor, agentBin: string | null): AcpAvailability {
|
|
326
|
+
const agent = agentInfoOf(d);
|
|
327
|
+
const adapterEntry = d.launch.kind === 'adapter-js' ? resolveAdapterEntry(d.launch) : null;
|
|
328
|
+
if (d.launch.kind === 'adapter-js' && !adapterEntry) {
|
|
329
|
+
return {
|
|
330
|
+
available: false,
|
|
331
|
+
reason: `The ${d.label} agent bridge is not installed in this build.`,
|
|
332
|
+
adapterEntry: null,
|
|
333
|
+
claudePath: null,
|
|
334
|
+
agent,
|
|
335
|
+
};
|
|
336
|
+
}
|
|
337
|
+
if (!agentBin || !existsSync(agentBin)) {
|
|
338
|
+
return {
|
|
339
|
+
available: false,
|
|
340
|
+
reason: `${d.label} isn't installed on this Mac — install it, sign in, then connect it in Settings.`,
|
|
341
|
+
adapterEntry,
|
|
342
|
+
claudePath: null,
|
|
343
|
+
agent,
|
|
284
344
|
};
|
|
285
345
|
}
|
|
286
|
-
return { available: true, adapterEntry, claudePath };
|
|
346
|
+
return { available: true, adapterEntry, claudePath: null, agent };
|
|
287
347
|
}
|
|
288
348
|
|
|
289
349
|
export interface ClaudeAuthStatus {
|
|
@@ -592,6 +652,10 @@ async function readAuthStatusStdout(bin: string): Promise<string> {
|
|
|
592
652
|
export async function probeAcpAvailabilityAuthed(): Promise<AcpAvailability> {
|
|
593
653
|
const base = probeAcpAvailability();
|
|
594
654
|
if (!base.available) return base;
|
|
655
|
+
// B7 (DDR-252 amends DDR-123) — this profile turned on the Advanced opt-in, so the adapter gets
|
|
656
|
+
// ANTHROPIC_API_KEY (acp/agents/chat-key.ts) and needs no Claude sign-in. Checked before the
|
|
657
|
+
// `claude auth status` subprocess: that one runs scrubbed and cannot see the key.
|
|
658
|
+
if (claudeApiKeyOptedIn()) return { ...base, billing: 'api-key' };
|
|
595
659
|
const authStatus = await getClaudeAuthStatus();
|
|
596
660
|
if (!authStatus?.loggedIn) {
|
|
597
661
|
return {
|
|
@@ -55,6 +55,11 @@ export interface ChatMeta {
|
|
|
55
55
|
archived?: boolean;
|
|
56
56
|
/** S5.7 — set while the chat is in the trash (ms since epoch). */
|
|
57
57
|
trashedAt?: number;
|
|
58
|
+
/**
|
|
59
|
+
* B3 (universal ACP) — the agent this chat runs (`codex`, `opencode` …), recorded at its first
|
|
60
|
+
* attach and kept: a chat never switches agents. Absent → Claude (every chat before this).
|
|
61
|
+
*/
|
|
62
|
+
agent?: string;
|
|
58
63
|
}
|
|
59
64
|
|
|
60
65
|
export interface ChatMessagePart {
|
|
@@ -84,6 +89,9 @@ function chatDir(designRoot: string): string {
|
|
|
84
89
|
return join(designRoot, '_chat');
|
|
85
90
|
}
|
|
86
91
|
|
|
92
|
+
/** An agent id as the catalog spells one (`codex`, `custom:x`) — anything else is not an agent. */
|
|
93
|
+
const AGENT_ID_RE = /^[a-z][a-z0-9-]{0,31}(?::[A-Za-z0-9_-]{1,64})?$/;
|
|
94
|
+
|
|
87
95
|
function metaPath(designRoot: string, chatId: string): string {
|
|
88
96
|
return join(chatDir(designRoot), `${chatId}.meta.json`);
|
|
89
97
|
}
|
|
@@ -110,6 +118,7 @@ export function readChatMeta(designRoot: string, chatId: string): ChatMeta {
|
|
|
110
118
|
if (typeof r.archived === 'boolean') meta.archived = r.archived;
|
|
111
119
|
if (typeof r.trashedAt === 'number' && Number.isFinite(r.trashedAt))
|
|
112
120
|
meta.trashedAt = r.trashedAt;
|
|
121
|
+
if (typeof r.agent === 'string' && AGENT_ID_RE.test(r.agent)) meta.agent = r.agent;
|
|
113
122
|
return meta;
|
|
114
123
|
} catch {
|
|
115
124
|
return {};
|
|
@@ -190,6 +199,8 @@ export function writeChatMeta(
|
|
|
190
199
|
canvas?: string | null;
|
|
191
200
|
/** S5.18 (G5) — the artboards of its latest scoped ask (`null` clears). */
|
|
192
201
|
artboards?: string[] | null;
|
|
202
|
+
/** B3 — the chat's agent (set once at first attach; a non-id is not stored). */
|
|
203
|
+
agent?: string;
|
|
193
204
|
}
|
|
194
205
|
): ChatMeta {
|
|
195
206
|
const dir = chatDir(designRoot);
|
|
@@ -214,6 +225,9 @@ export function writeChatMeta(
|
|
|
214
225
|
if (c) next.canvas = c;
|
|
215
226
|
else delete next.canvas;
|
|
216
227
|
}
|
|
228
|
+
if ('agent' in patch && typeof patch.agent === 'string' && AGENT_ID_RE.test(patch.agent)) {
|
|
229
|
+
next.agent = patch.agent;
|
|
230
|
+
}
|
|
217
231
|
if ('artboards' in patch) {
|
|
218
232
|
const a = plainArtboardIds(patch.artboards);
|
|
219
233
|
if (a) next.artboards = a;
|