@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.
Files changed (79) hide show
  1. package/apps/studio/acp/agents/auth.ts +241 -0
  2. package/apps/studio/acp/agents/catalog.ts +308 -0
  3. package/apps/studio/acp/agents/chat-key.ts +64 -0
  4. package/apps/studio/acp/agents/conformance.ts +1853 -0
  5. package/apps/studio/acp/agents/consent.ts +92 -0
  6. package/apps/studio/acp/agents/descriptor.ts +188 -0
  7. package/apps/studio/acp/agents/discover.ts +491 -0
  8. package/apps/studio/acp/agents/e2e-model.ts +58 -0
  9. package/apps/studio/acp/agents/health.ts +46 -0
  10. package/apps/studio/acp/agents/link-scan.ts +230 -0
  11. package/apps/studio/acp/agents/spawn.ts +164 -0
  12. package/apps/studio/acp/agents/state.ts +132 -0
  13. package/apps/studio/acp/ask-queue.ts +13 -4
  14. package/apps/studio/acp/bootstrap-brief.ts +16 -3
  15. package/apps/studio/acp/bridge.ts +709 -99
  16. package/apps/studio/acp/env.ts +43 -1
  17. package/apps/studio/acp/index.ts +428 -43
  18. package/apps/studio/acp/may-scope.ts +244 -21
  19. package/apps/studio/acp/policy/agent-home.ts +202 -0
  20. package/apps/studio/acp/policy/bridge-gate.ts +68 -0
  21. package/apps/studio/acp/policy/codex-home.ts +228 -0
  22. package/apps/studio/acp/policy/enforce.ts +620 -0
  23. package/apps/studio/acp/policy/gate-types.ts +41 -0
  24. package/apps/studio/acp/policy/launch-codex.ts +351 -0
  25. package/apps/studio/acp/policy/launch-copilot.ts +119 -0
  26. package/apps/studio/acp/policy/launch-gemini.ts +120 -0
  27. package/apps/studio/acp/policy/launch-opencode.ts +131 -0
  28. package/apps/studio/acp/policy/opencode-user-config.ts +240 -0
  29. package/apps/studio/acp/probe.ts +78 -14
  30. package/apps/studio/acp/transcript.ts +14 -0
  31. package/apps/studio/acp/write-scope.ts +62 -2
  32. package/apps/studio/canvas-pages-view.tsx +3 -2
  33. package/apps/studio/canvas-theme-pill.tsx +125 -72
  34. package/apps/studio/client/panels/ChatPanel.jsx +19 -4
  35. package/apps/studio/client/panels/PermissionPrompt.jsx +11 -6
  36. package/apps/studio/client/panels/acp-runtime.js +95 -7
  37. package/apps/studio/client/v2/ai/Advanced.jsx +4 -3
  38. package/apps/studio/client/v2/ai/AgentNotice.jsx +138 -0
  39. package/apps/studio/client/v2/ai/AgentOffer.jsx +110 -0
  40. package/apps/studio/client/v2/ai/AgentPicker.jsx +121 -0
  41. package/apps/studio/client/v2/ai/Composer.jsx +4 -0
  42. package/apps/studio/client/v2/ai/ConnectSheet.jsx +13 -0
  43. package/apps/studio/client/v2/ai/Feed.jsx +8 -0
  44. package/apps/studio/client/v2/ai/NeedsYouSlot.jsx +24 -1
  45. package/apps/studio/client/v2/ai/Suggest.jsx +5 -1
  46. package/apps/studio/client/v2/ai/advanced-model.js +17 -6
  47. package/apps/studio/client/v2/ai/agents-model.js +333 -0
  48. package/apps/studio/client/v2/ai/agents-store.js +223 -0
  49. package/apps/studio/client/v2/ai/ai.css +63 -0
  50. package/apps/studio/client/v2/ai/needs-you.js +1 -1
  51. package/apps/studio/client/v2/fold/fold-store.js +1 -0
  52. package/apps/studio/client/v2/left-panel/left-panel.css +8 -0
  53. package/apps/studio/client/v2/settings/agent-keys.js +88 -0
  54. package/apps/studio/client/v2/settings/agents-card.jsx +408 -0
  55. package/apps/studio/client/v2/settings/connections-model.js +1 -1
  56. package/apps/studio/client/v2/settings/connections-section.jsx +4 -0
  57. package/apps/studio/client/v2/settings/settings-cards.js +2 -1
  58. package/apps/studio/client/v2/settings/settings-model.js +1 -0
  59. package/apps/studio/client/v2/settings/settings.css +7 -0
  60. package/apps/studio/client/v2/shell/served-routes.js +1 -0
  61. package/apps/studio/cloud-build.ts +5 -0
  62. package/apps/studio/dist/client.bundle.js +604 -604
  63. package/apps/studio/dist/styles.css +1 -1
  64. package/apps/studio/ds/board/board.css +4 -78
  65. package/apps/studio/ds/board/ds-bar.tsx +15 -9
  66. package/apps/studio/generation/keys.ts +197 -11
  67. package/apps/studio/outbox/policy.ts +8 -2
  68. package/apps/studio/outbox/types.ts +5 -0
  69. package/apps/studio/routes/agents.ts +479 -0
  70. package/apps/studio/routes/index.ts +3 -0
  71. package/apps/studio/scripts/acp-conformance-local.ts +95 -0
  72. package/apps/studio/scripts/acp-e2e-local.ts +1026 -0
  73. package/apps/studio/server.ts +9 -0
  74. package/apps/studio/sync/writer-registry.ts +12 -0
  75. package/apps/studio/whats-new.json +19 -0
  76. package/apps/studio/ws.ts +3 -0
  77. package/cli/commands/codex.mjs +36 -2
  78. package/cli/lib/harness/codex-runtime.mjs +98 -11
  79. package/package.json +9 -8
@@ -0,0 +1,92 @@
1
+ // Per-project consent to run an 'unrestricted' agent (universal ACP, plan Decision 2, DDR-252).
2
+ //
3
+ // An agent Maude cannot confine (policy 'unrestricted': no launch policy that passed the
4
+ // conformance probe) only starts in a project after the person said yes to it there. The answer
5
+ // is this machine's, about this project: it lives OUTSIDE the project, next to the project's
6
+ // folder grants (`ai/attach-grants.ts` `grantsFileFor`) in the app's own index folder
7
+ // (`~/.maude/index/v1/projects/<pid>/agent-consent.json`), so a cloned or synced project can
8
+ // never ship a yes. A file that would resolve inside the project is ignored (reads say no,
9
+ // writes throw).
10
+
11
+ import { randomUUID } from 'node:crypto';
12
+ import { existsSync, mkdirSync, readFileSync, renameSync, writeFileSync } from 'node:fs';
13
+ import { dirname, join, sep } from 'node:path';
14
+
15
+ import { pidOf, projectDir } from '../../index/snapshot.ts';
16
+ import { isInsideRoot, resolveRealPath } from '../write-scope.ts';
17
+ import type { AgentId } from './descriptor.ts';
18
+
19
+ interface ConsentFile {
20
+ v: 1;
21
+ agents: Record<string, { grantedAt: number }>;
22
+ }
23
+
24
+ /** This machine's consent file for one project: outside the project tree. */
25
+ export function agentConsentFileFor(projectRoot: string): string {
26
+ return join(projectDir(pidOf(projectRoot)), 'agent-consent.json');
27
+ }
28
+
29
+ function misplaced(file: string, projectRoot: string): boolean {
30
+ const f = resolveRealPath(file, sep);
31
+ const root = resolveRealPath(projectRoot, sep);
32
+ return f === root || isInsideRoot(f, root);
33
+ }
34
+
35
+ function read(file: string): ConsentFile {
36
+ const empty: ConsentFile = { v: 1, agents: {} };
37
+ if (!existsSync(file)) return empty;
38
+ try {
39
+ const raw = JSON.parse(readFileSync(file, 'utf8')) as Partial<ConsentFile> | null;
40
+ if (raw?.v !== 1 || !raw.agents || typeof raw.agents !== 'object') return empty;
41
+ const agents: ConsentFile['agents'] = {};
42
+ for (const [id, v] of Object.entries(raw.agents)) {
43
+ const at = (v as { grantedAt?: unknown } | null)?.grantedAt;
44
+ if (typeof at === 'number' && Number.isFinite(at)) agents[id] = { grantedAt: at };
45
+ }
46
+ return { v: 1, agents };
47
+ } catch {
48
+ return empty;
49
+ }
50
+ }
51
+
52
+ export interface ConsentPlace {
53
+ projectRoot: string;
54
+ /** Tests only — default `agentConsentFileFor(projectRoot)`. */
55
+ file?: string;
56
+ }
57
+
58
+ export function hasAgentConsent(place: ConsentPlace, id: AgentId): boolean {
59
+ const file = place.file ?? agentConsentFileFor(place.projectRoot);
60
+ if (misplaced(file, place.projectRoot)) return false;
61
+ return Object.hasOwn(read(file).agents, id);
62
+ }
63
+
64
+ /**
65
+ * Security review 2026-11-12 — a random temp name opened exclusively (`wx`): a same-user process
66
+ * cannot pre-plant a symlink at a predictable name for this write to follow.
67
+ */
68
+ function writeAtomic(file: string, doc: unknown): void {
69
+ const tmp = `${file}.${randomUUID()}.tmp`;
70
+ writeFileSync(tmp, `${JSON.stringify(doc, null, 2)}\n`, { mode: 0o600, flag: 'wx' });
71
+ renameSync(tmp, file);
72
+ }
73
+
74
+ export function recordAgentConsent(place: ConsentPlace, id: AgentId, now = Date.now()): void {
75
+ const file = place.file ?? agentConsentFileFor(place.projectRoot);
76
+ if (misplaced(file, place.projectRoot))
77
+ throw new Error('agent consent store is inside the project');
78
+ const next = read(file);
79
+ next.agents[id] = { grantedAt: now };
80
+ mkdirSync(dirname(file), { recursive: true, mode: 0o700 });
81
+ writeAtomic(file, next);
82
+ }
83
+
84
+ export function revokeAgentConsent(place: ConsentPlace, id: AgentId): void {
85
+ const file = place.file ?? agentConsentFileFor(place.projectRoot);
86
+ if (misplaced(file, place.projectRoot)) return;
87
+ const next = read(file);
88
+ if (!Object.hasOwn(next.agents, id)) return;
89
+ delete next.agents[id];
90
+ mkdirSync(dirname(file), { recursive: true, mode: 0o700 });
91
+ writeAtomic(file, next);
92
+ }
@@ -0,0 +1,188 @@
1
+ // The agent descriptor: what the Studio chat needs to know to find, launch, sign in and confine
2
+ // one ACP agent. Contract: .ai/plans/notes/universal-acp-contract.md (B0) + DDR-252.
3
+ //
4
+ // Claude is descriptor `claude` with policy 'claude-meta': its least-privilege policy keeps
5
+ // riding `_meta.claudeCode.options` exactly as before (newSessionParams stays byte-identical).
6
+ // Every other agent is 'bridge-enforced' (an agent-native launch policy Maude writes per session,
7
+ // the bridge's permission gate, and a conformance probe) or 'unrestricted' (Advanced only, a
8
+ // per-project consent card, never offered).
9
+
10
+ import type { AiMay, CredentialPaths } from '../may-scope.ts';
11
+
12
+ export type BuiltinAgentId =
13
+ | 'claude'
14
+ | 'codex'
15
+ | 'opencode'
16
+ | 'gemini'
17
+ | 'copilot'
18
+ | 'goose'
19
+ | 'cursor';
20
+ export type AgentId = BuiltinAgentId | `custom:${string}`;
21
+
22
+ export type AgentPolicy = 'claude-meta' | 'bridge-enforced' | 'unrestricted';
23
+
24
+ export interface AgentDetect {
25
+ /** Command names looked up on the login-shell PATH; wrappers are resolved by READING them. */
26
+ bins: string[];
27
+ /** Arguments that print the version (run with a 5 s timeout, off the boot path, cached). */
28
+ versionArgs: string[];
29
+ /** First capture group = the semver. */
30
+ versionRe: RegExp;
31
+ /** Below this the agent is not offered. */
32
+ minVersion: string;
33
+ /** Inclusive upper bound of what passed the conformance probe; above it → "Untested version". */
34
+ testedMax: string;
35
+ }
36
+
37
+ export type AgentLaunch =
38
+ | {
39
+ kind: 'adapter-js';
40
+ /** Bundled adapter package (pinned in apps/studio/package.json). */
41
+ adapterPkg: string;
42
+ /** The adapter's bin name inside that package. */
43
+ adapterBin: string;
44
+ /** Env var that tells the adapter where the user's own agent binary is. */
45
+ agentBinEnv?: string;
46
+ }
47
+ | {
48
+ kind: 'native-acp';
49
+ /** Arguments that put the user's own binary into ACP mode. */
50
+ args: string[];
51
+ };
52
+
53
+ export interface AgentAuth {
54
+ /** 'session-new': session/new fails until signed in. 'none': works with no account. */
55
+ gate: 'session-new' | 'none';
56
+ /** argv (after the binary) that reports sign-in state; exit 0 = signed in. */
57
+ statusArgs?: string[];
58
+ /** argv (after the binary) that starts the vendor's own sign-in. */
59
+ loginArgs?: string[];
60
+ /** Env names a BYOK key for this agent is injected as (B7) — into THIS agent's env only. */
61
+ apiKeyEnv?: string[];
62
+ }
63
+
64
+ export interface PolicyCtx {
65
+ /** pinScopeRoot(repoRoot) */
66
+ scopeRoot: string;
67
+ /** readBoundaryRoots(...) */
68
+ readRoots: readonly string[];
69
+ /** scopeRoot (+ the chat scratch dir) */
70
+ writeRoots: readonly string[];
71
+ credentialPaths: CredentialPaths;
72
+ may: AiMay;
73
+ /** Design roots whose runtime state the agent must not write. */
74
+ designRoots: readonly string[];
75
+ /** The discovered real binary of the agent (realpath). */
76
+ agentBin: string;
77
+ /**
78
+ * F6b — the env the agent's OWN home and config are found from (HOME, CODEX_HOME,
79
+ * XDG_CONFIG_HOME, OPENCODE_CONFIG, MAUDE_PROFILE_ID …). Default `process.env` (the bridge); the
80
+ * conformance probe passes its scratch world so a probe never touches the person's real files.
81
+ */
82
+ hostEnv?: Readonly<Record<string, string | undefined>>;
83
+ /**
84
+ * S1 (M2) — whether a stored chat API key rides this spawn (chat-key.ts). Absent → read from the
85
+ * key store; the conformance probe says false (it never passes a stored key).
86
+ */
87
+ chatKeyStored?: boolean;
88
+ }
89
+
90
+ export interface LaunchPolicy {
91
+ env: Record<string, string>;
92
+ args?: string[];
93
+ }
94
+
95
+ export interface Enforcement {
96
+ /** Agent-native launch policy built from the session scope: the real read/write/network boundary. */
97
+ launchPolicy(ctx: PolicyCtx): LaunchPolicy;
98
+ readGate: 'os-sandbox' | 'agent-permission-engine';
99
+ shellGate: 'os-sandbox' | 'command-text';
100
+ /**
101
+ * Mode pinned after session/new. An ALLOWLIST (S1, attacker A6): the bridge refuses a switch to
102
+ * any mode not in `allow` and never lists one, so a mode a future adapter adds is refused until
103
+ * someone reads it and lists it here. `allow` must contain `modeId`.
104
+ */
105
+ pinMode?: { modeId: string; allow: string[] };
106
+ /**
107
+ * Config options pinned the same way (S1, Copilot's `allow_all`): configId → the values the bridge
108
+ * may set or list. Any other value is refused when the panel asks for it, dropped from the options
109
+ * the panel sees, and a session that starts on one is moved to `allow[0]`. A boolean option is
110
+ * judged by `"true"` / `"false"`.
111
+ */
112
+ pinConfig?: Record<string, { allow: string[] }>;
113
+ /** A refusal ends the whole turn (Codex). The panel says why instead of showing an error. */
114
+ rejectEndsTurn: boolean;
115
+ /** rawInput keys a request may carry a path in (normalised through acp/agent-path.ts). */
116
+ targetKeys: string[];
117
+ }
118
+
119
+ export interface AgentDescriptor {
120
+ id: AgentId;
121
+ label: string;
122
+ /** Vendor shown on the reply badge and in "<label> reported: …". */
123
+ vendor: string;
124
+ /** Vendor status page linked from attributed errors. */
125
+ statusUrl?: string;
126
+ detect: AgentDetect;
127
+ launch: AgentLaunch;
128
+ auth: AgentAuth;
129
+ /** Env names added back on top of the shared scrub. */
130
+ envAllow: string[];
131
+ policy: AgentPolicy;
132
+ /** Required when policy === 'bridge-enforced'. */
133
+ enforcement?: Enforcement;
134
+ plugins: 'claude-meta' | 'harness:codex' | 'harness:opencode' | 'none';
135
+ /** Shown in Settings when the connect step must say where prompts go (opencode's hosted model). */
136
+ connectNote?: string;
137
+ }
138
+
139
+ /** Compare dotted numeric versions; non-numeric parts compare as 0. */
140
+ export function compareVersions(a: string, b: string): number {
141
+ const pa = a.split(/[.+-]/).map((n) => Number.parseInt(n, 10) || 0);
142
+ const pb = b.split(/[.+-]/).map((n) => Number.parseInt(n, 10) || 0);
143
+ for (let i = 0; i < Math.max(pa.length, pb.length, 3); i++) {
144
+ const d = (pa[i] ?? 0) - (pb[i] ?? 0);
145
+ if (d !== 0) return d < 0 ? -1 : 1;
146
+ }
147
+ return 0;
148
+ }
149
+
150
+ export type VersionFit = 'ok' | 'too-old' | 'untested';
151
+
152
+ export function versionFit(d: AgentDescriptor, version: string): VersionFit {
153
+ if (compareVersions(version, d.detect.minVersion) < 0) return 'too-old';
154
+ if (compareVersions(version, d.detect.testedMax) > 0) return 'untested';
155
+ return 'ok';
156
+ }
157
+
158
+ /**
159
+ * S1 — true when `value` of config option `configId` is outside the descriptor's `pinConfig`
160
+ * allowlist. Options the descriptor does not pin are not judged here (`mode` is: rule 10 goes through
161
+ * `isRefusedMode`).
162
+ */
163
+ export function isRefusedConfigValue(
164
+ d: AgentDescriptor,
165
+ configId: string,
166
+ value: string | boolean
167
+ ): boolean {
168
+ const pin = d.enforcement?.pinConfig?.[configId];
169
+ return !!pin && !pin.allow.includes(String(value));
170
+ }
171
+
172
+ /** Bridge-enforced descriptors must carry their enforcement; fail loud at load, not at a prompt. */
173
+ export function assertDescriptor(d: AgentDescriptor): AgentDescriptor {
174
+ if (d.policy === 'bridge-enforced' && !d.enforcement) {
175
+ throw new Error(`agent ${d.id}: policy bridge-enforced needs an enforcement block`);
176
+ }
177
+ const pin = d.enforcement?.pinMode;
178
+ if (pin && !pin.allow.includes(pin.modeId)) {
179
+ throw new Error(`agent ${d.id}: the pinned mode ${pin.modeId} is not in its allow list`);
180
+ }
181
+ for (const [id, c] of Object.entries(d.enforcement?.pinConfig ?? {})) {
182
+ if (c.allow.length === 0) throw new Error(`agent ${d.id}: config ${id} allows no value`);
183
+ }
184
+ if (d.policy !== 'claude-meta' && d.plugins === 'claude-meta') {
185
+ throw new Error(`agent ${d.id}: only the claude-meta policy can carry plugins over _meta`);
186
+ }
187
+ return d;
188
+ }