@1agh/maude 2.2.1 → 2.3.2
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/annotations-layer.tsx +8 -0
- package/apps/studio/bin/_capture-init.js +5 -0
- package/apps/studio/bin/screenshot.sh +7 -1
- package/apps/studio/bridge/dgn-protocol.ts +3 -2
- package/apps/studio/canvas-shell.tsx +54 -0
- package/apps/studio/client/panels/ChatPanel.jsx +19 -4
- package/apps/studio/client/panels/PermissionPrompt.jsx +11 -6
- package/apps/studio/client/panels/SyncConsentDialog.jsx +4 -1
- 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/empty/empty-host.jsx +11 -2
- package/apps/studio/client/v2/empty/use-empty-canvas.js +22 -7
- package/apps/studio/client/v2/fold/fold-store.js +1 -0
- package/apps/studio/client/v2/preview/preview-chrome-host.jsx +1 -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/client/v2/undo/zoom-undo.jsx +19 -2
- package/apps/studio/cloud-build.ts +5 -0
- package/apps/studio/comments/reveal.ts +13 -0
- package/apps/studio/comments-overlay.tsx +36 -0
- package/apps/studio/dist/client.bundle.js +535 -535
- package/apps/studio/dist/comment-mount.js +2 -2
- package/apps/studio/dist/styles.css +1 -1
- package/apps/studio/editing/annotation-count.ts +25 -0
- package/apps/studio/editing/empty-report.ts +8 -3
- package/apps/studio/editing/empty-reporter.tsx +10 -1
- 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/index.ts +9 -1
- 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,1026 @@
|
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
// End to end: the universal-ACP chat through the REAL studio server with the REAL agent binaries.
|
|
3
|
+
// Local only, never in CI (it needs codex / opencode installed). Offline: each agent's model is a
|
|
4
|
+
// loopback scripted model (the e2e-only switch MAUDE_E2E_AGENT_MODEL_URL, acp/agents/e2e-model.ts,
|
|
5
|
+
// which a release build ignores), a scratch HOME / XDG_* / CODEX_HOME, a stub `claude`, fake keys.
|
|
6
|
+
// Scenario: .ai/scenarios/universal-acp-agents/spec.md.
|
|
7
|
+
//
|
|
8
|
+
// bun apps/studio/scripts/acp-e2e-local.ts [codex|opencode ...] [--keep]
|
|
9
|
+
//
|
|
10
|
+
// Per agent, in its own scratch world (/Users/Shared/.maude-e2e-<uid>/…, outside git and outside ~:
|
|
11
|
+
// opencode walks up from the project into ~/.opencode):
|
|
12
|
+
// 1 GET /_api/agents → installed, fit ok, policy bridge-enforced, offered
|
|
13
|
+
// 2 POST connect as the person (session cookie, same-origin) → the REAL conformance probe →
|
|
14
|
+
// connected; a key-only (helper) connect is refused; dismiss-offer survives a restart
|
|
15
|
+
// 3 /_ws/acp attach {agent} → attached.agent.id; a prompt → update frames with the model's
|
|
16
|
+
// text; `_chat/<id>.meta.json` records the agent
|
|
17
|
+
// 4 scripted tool calls: in-project write (no card) · out-of-project write (refused / card →
|
|
18
|
+
// reject) · read of a planted fake credential (never reaches the model) · curl to a loopback
|
|
19
|
+
// canary (fails) · set-mode to a refused mode (refused)
|
|
20
|
+
// 5 a planted chat meta naming an unconnected agent → agent-not-connected; opencode + a link
|
|
21
|
+
// out of the project → agent-unsafe-link
|
|
22
|
+
// 6 a Claude-only world → offerAgents: []
|
|
23
|
+
// 7 every server and agent process gone (ps scan on the scratch paths)
|
|
24
|
+
// Prints a PASS/FAIL table and writes .ai/device/scenario-runs/universal-acp-agents-server/<ts>/.
|
|
25
|
+
|
|
26
|
+
import { spawnSync } from 'node:child_process';
|
|
27
|
+
import { randomBytes } from 'node:crypto';
|
|
28
|
+
import {
|
|
29
|
+
appendFileSync,
|
|
30
|
+
copyFileSync,
|
|
31
|
+
existsSync,
|
|
32
|
+
mkdirSync,
|
|
33
|
+
readFileSync,
|
|
34
|
+
realpathSync,
|
|
35
|
+
rmSync,
|
|
36
|
+
symlinkSync,
|
|
37
|
+
writeFileSync,
|
|
38
|
+
} from 'node:fs';
|
|
39
|
+
import { homedir, tmpdir } from 'node:os';
|
|
40
|
+
import { dirname, join, resolve } from 'node:path';
|
|
41
|
+
|
|
42
|
+
import type { Subprocess } from 'bun';
|
|
43
|
+
|
|
44
|
+
import { agentById } from '../acp/agents/catalog.ts';
|
|
45
|
+
import {
|
|
46
|
+
conversationOf,
|
|
47
|
+
type ProbeProfile,
|
|
48
|
+
respond,
|
|
49
|
+
type ToolStep,
|
|
50
|
+
toolNames,
|
|
51
|
+
} from '../acp/agents/conformance.ts';
|
|
52
|
+
import { E2E_AGENT_MODEL_SWITCH } from '../acp/agents/e2e-model.ts';
|
|
53
|
+
|
|
54
|
+
const STUDIO = resolve(import.meta.dir, '..');
|
|
55
|
+
const REPO = resolve(STUDIO, '../..');
|
|
56
|
+
const argv = process.argv.slice(2);
|
|
57
|
+
const KEEP = argv.includes('--keep');
|
|
58
|
+
const wanted = argv.filter((a) => !a.startsWith('--'));
|
|
59
|
+
const AGENTS = (wanted.length ? wanted : ['codex', 'opencode']) as ('codex' | 'opencode')[];
|
|
60
|
+
const UID = process.getuid?.() ?? 0;
|
|
61
|
+
const SCRATCH_ROOT =
|
|
62
|
+
process.platform === 'darwin' ? `/Users/Shared/.maude-e2e-${UID}` : join(tmpdir(), 'maude-e2e');
|
|
63
|
+
const CONFORMANCE_ROOT = `/Users/Shared/.maude-conformance-${UID}`;
|
|
64
|
+
const stamp = new Date().toISOString().slice(0, 16).replace('T', '-').replace(':', '');
|
|
65
|
+
const RUN_DIR = join(REPO, '.ai/device/scenario-runs/universal-acp-agents-server', stamp);
|
|
66
|
+
mkdirSync(RUN_DIR, { recursive: true });
|
|
67
|
+
|
|
68
|
+
const tok = (label: string) => `E2E-${label}-${randomBytes(5).toString('hex')}`;
|
|
69
|
+
const sq = (s: string) => `'${s.replaceAll("'", `'\\''`)}'`;
|
|
70
|
+
const sleep = (ms: number) => new Promise((r) => setTimeout(r, ms));
|
|
71
|
+
const clip = (s: string, n = 140) =>
|
|
72
|
+
(s.length > n ? `${s.slice(0, n)}…` : s).replace(/\s+/g, ' ').replaceAll('|', '/');
|
|
73
|
+
|
|
74
|
+
// ------------------------------------------------------------------------------------- results
|
|
75
|
+
|
|
76
|
+
interface Row {
|
|
77
|
+
agent: string;
|
|
78
|
+
step: string;
|
|
79
|
+
ok: boolean | null; // null = not run / not applicable
|
|
80
|
+
detail: string;
|
|
81
|
+
}
|
|
82
|
+
const rows: Row[] = [];
|
|
83
|
+
function record(agent: string, step: string, ok: boolean | null, detail: string) {
|
|
84
|
+
rows.push({ agent, step, ok, detail });
|
|
85
|
+
console.log(
|
|
86
|
+
` ${ok === null ? 'n/a ' : ok ? 'PASS' : 'FAIL'} ${agent} ${step}: ${clip(detail, 200)}`
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
async function guarded(agent: string, step: string, fn: () => Promise<[boolean, string]>) {
|
|
90
|
+
try {
|
|
91
|
+
const [ok, detail] = await fn();
|
|
92
|
+
record(agent, step, ok, detail);
|
|
93
|
+
return ok;
|
|
94
|
+
} catch (e) {
|
|
95
|
+
record(agent, step, false, `threw: ${(e as Error).message}`);
|
|
96
|
+
return false;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// ------------------------------------------------------------------------------------ the world
|
|
101
|
+
|
|
102
|
+
interface World {
|
|
103
|
+
id: string;
|
|
104
|
+
base: string;
|
|
105
|
+
home: string;
|
|
106
|
+
xdgConfig: string;
|
|
107
|
+
codexHome: string;
|
|
108
|
+
project: string;
|
|
109
|
+
designRoot: string;
|
|
110
|
+
outside: string;
|
|
111
|
+
bin: string;
|
|
112
|
+
path: string;
|
|
113
|
+
secrets: string[]; // fake values that must never reach the model
|
|
114
|
+
keysPath: string;
|
|
115
|
+
outsideSecret: string;
|
|
116
|
+
stateDir: string;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function personCodexBin(): string | null {
|
|
120
|
+
for (const p of [join(homedir(), '.local/bin/codex')]) {
|
|
121
|
+
try {
|
|
122
|
+
return realpathSync(p);
|
|
123
|
+
} catch {
|
|
124
|
+
/* not here */
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
const w = Bun.which('codex');
|
|
128
|
+
return w ? realpathSync(w) : null;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function makeWorld(id: string, install: ('codex' | 'opencode')[]): World {
|
|
132
|
+
mkdirSync(SCRATCH_ROOT, { recursive: true, mode: 0o700 });
|
|
133
|
+
const base = join(SCRATCH_ROOT, `${id}-${randomBytes(3).toString('hex')}`);
|
|
134
|
+
const home = join(base, 'home');
|
|
135
|
+
const xdgConfig = join(home, '.config');
|
|
136
|
+
const codexHome = join(home, '.codex');
|
|
137
|
+
const project = join(base, 'project');
|
|
138
|
+
const designRoot = join(project, '.design');
|
|
139
|
+
const outside = join(base, 'outside');
|
|
140
|
+
const bin = join(base, 'bin');
|
|
141
|
+
for (const d of [xdgConfig, codexHome, join(designRoot, 'ui'), outside, bin]) {
|
|
142
|
+
mkdirSync(d, { recursive: true });
|
|
143
|
+
}
|
|
144
|
+
writeFileSync(
|
|
145
|
+
join(designRoot, 'config.json'),
|
|
146
|
+
JSON.stringify({
|
|
147
|
+
name: 'e2e',
|
|
148
|
+
designRoot: '.design',
|
|
149
|
+
formatVersion: 2,
|
|
150
|
+
canvasGroups: [{ label: 'UI', path: 'ui' }],
|
|
151
|
+
})
|
|
152
|
+
);
|
|
153
|
+
writeFileSync(
|
|
154
|
+
join(designRoot, 'ui', 'home.tsx'),
|
|
155
|
+
[
|
|
156
|
+
"import { DCArtboard, DesignCanvas } from '@maude/canvas-lib';",
|
|
157
|
+
'export default function Home() {',
|
|
158
|
+
' return (',
|
|
159
|
+
' <DesignCanvas>',
|
|
160
|
+
' <DCArtboard id="a" label="A" width={400} height={300}>',
|
|
161
|
+
' <div>hello</div>',
|
|
162
|
+
' </DCArtboard>',
|
|
163
|
+
' </DesignCanvas>',
|
|
164
|
+
' );',
|
|
165
|
+
'}',
|
|
166
|
+
'',
|
|
167
|
+
].join('\n')
|
|
168
|
+
);
|
|
169
|
+
writeFileSync(join(project, 'notes.md'), '# notes\n');
|
|
170
|
+
// Planted fake credentials: Maude's own key store and the person's Codex sign-in (a fake API key
|
|
171
|
+
// so `codex login status` reads signed in, as on a real Mac). Neither may ever reach the model.
|
|
172
|
+
const genKey = tok('GENKEY');
|
|
173
|
+
const keysPath = join(xdgConfig, 'maude', 'keys.json');
|
|
174
|
+
mkdirSync(dirname(keysPath), { recursive: true });
|
|
175
|
+
writeFileSync(keysPath, JSON.stringify({ keys: { fal: genKey } }), { mode: 0o600 });
|
|
176
|
+
const codexKey = `sk-${tok('CODEXAUTH')}`;
|
|
177
|
+
writeFileSync(join(codexHome, 'auth.json'), JSON.stringify({ OPENAI_API_KEY: codexKey }), {
|
|
178
|
+
mode: 0o600,
|
|
179
|
+
});
|
|
180
|
+
const outsideToken = tok('OUTSIDE');
|
|
181
|
+
const outsideSecret = join(outside, 'secret.txt');
|
|
182
|
+
writeFileSync(outsideSecret, outsideToken);
|
|
183
|
+
// A stub `claude` (a fake HOME + the real claude pops a keychain dialog): signed out, fast.
|
|
184
|
+
writeFileSync(
|
|
185
|
+
join(bin, 'claude'),
|
|
186
|
+
'#!/bin/sh\ncase "$1" in --version|-v) echo "2.1.300 (Claude Code)";; *) echo \'{"loggedIn":false}\';; esac\nexit 0\n',
|
|
187
|
+
{ mode: 0o755 }
|
|
188
|
+
);
|
|
189
|
+
const pathDirs = [bin];
|
|
190
|
+
if (install.includes('codex')) {
|
|
191
|
+
// The person's setup on this Mac: ~/.claude/bin/codex is a `maude codex` wrapper naming
|
|
192
|
+
// $HOME/.local/bin/codex. Discovery must READ it (never run it) and land on the real binary.
|
|
193
|
+
const real = personCodexBin();
|
|
194
|
+
if (!real) throw new Error('codex is not installed on this Mac');
|
|
195
|
+
const wrapperDir = join(home, '.claude', 'bin');
|
|
196
|
+
mkdirSync(wrapperDir, { recursive: true });
|
|
197
|
+
const personWrapper = join(homedir(), '.claude', 'bin', 'codex');
|
|
198
|
+
const wrapper = join(wrapperDir, 'codex');
|
|
199
|
+
if (existsSync(personWrapper)) copyFileSync(personWrapper, wrapper);
|
|
200
|
+
else
|
|
201
|
+
writeFileSync(
|
|
202
|
+
wrapper,
|
|
203
|
+
'#!/bin/sh\nset -eu\n\nexport MAUDE_CODEX_REAL="$HOME/.local/bin/codex"\nexec maude codex "$@"\n'
|
|
204
|
+
);
|
|
205
|
+
spawnSync('chmod', ['755', wrapper]);
|
|
206
|
+
mkdirSync(join(home, '.local', 'bin'), { recursive: true });
|
|
207
|
+
symlinkSync(real, join(home, '.local', 'bin', 'codex'));
|
|
208
|
+
pathDirs.unshift(wrapperDir);
|
|
209
|
+
}
|
|
210
|
+
if (install.includes('opencode')) {
|
|
211
|
+
const oc = Bun.which('opencode');
|
|
212
|
+
if (!oc) throw new Error('opencode is not installed on this Mac');
|
|
213
|
+
symlinkSync(oc, join(bin, 'opencode'));
|
|
214
|
+
}
|
|
215
|
+
const bunDir = dirname(process.execPath);
|
|
216
|
+
const path = [...pathDirs, bunDir, '/usr/bin', '/bin', '/usr/sbin', '/sbin'].join(':');
|
|
217
|
+
return {
|
|
218
|
+
id,
|
|
219
|
+
base,
|
|
220
|
+
home,
|
|
221
|
+
xdgConfig,
|
|
222
|
+
codexHome,
|
|
223
|
+
project,
|
|
224
|
+
designRoot,
|
|
225
|
+
outside,
|
|
226
|
+
bin,
|
|
227
|
+
path,
|
|
228
|
+
secrets: [genKey, codexKey, outsideToken],
|
|
229
|
+
keysPath,
|
|
230
|
+
outsideSecret,
|
|
231
|
+
stateDir: join(base, 'state'),
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
// ------------------------------------------------------------------------------- scripted model
|
|
236
|
+
|
|
237
|
+
type StepFn = (tools: readonly string[], after: readonly string[]) => ToolStep | { text: string };
|
|
238
|
+
interface Model {
|
|
239
|
+
url: string;
|
|
240
|
+
bodies: string[];
|
|
241
|
+
received: Map<string, string[]>;
|
|
242
|
+
tools: Set<string>;
|
|
243
|
+
script: Map<string, StepFn>;
|
|
244
|
+
stop(): void;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
function startModel(api: ProbeProfile['api'], log: string): Model {
|
|
248
|
+
const m: Model = {
|
|
249
|
+
url: '',
|
|
250
|
+
bodies: [],
|
|
251
|
+
received: new Map(),
|
|
252
|
+
tools: new Set(),
|
|
253
|
+
script: new Map(),
|
|
254
|
+
stop: () => {},
|
|
255
|
+
};
|
|
256
|
+
let n = 0;
|
|
257
|
+
const server = Bun.serve({
|
|
258
|
+
port: 0,
|
|
259
|
+
hostname: '127.0.0.1',
|
|
260
|
+
async fetch(req) {
|
|
261
|
+
const url = new URL(req.url);
|
|
262
|
+
if (url.pathname.endsWith('/models')) {
|
|
263
|
+
return Response.json({
|
|
264
|
+
object: 'list',
|
|
265
|
+
data: [{ id: 'mock-model', object: 'model', owned_by: 'maude-e2e' }],
|
|
266
|
+
});
|
|
267
|
+
}
|
|
268
|
+
const raw = await req.text();
|
|
269
|
+
m.bodies.push(raw);
|
|
270
|
+
let body: Record<string, unknown> = {};
|
|
271
|
+
try {
|
|
272
|
+
body = JSON.parse(raw);
|
|
273
|
+
} catch {
|
|
274
|
+
/* not JSON */
|
|
275
|
+
}
|
|
276
|
+
n++;
|
|
277
|
+
const tools = toolNames(body);
|
|
278
|
+
for (const t of tools) m.tools.add(t);
|
|
279
|
+
const conv = conversationOf(body);
|
|
280
|
+
let at = -1;
|
|
281
|
+
let step: string | null = null;
|
|
282
|
+
for (let i = conv.length - 1; i >= 0; i--) {
|
|
283
|
+
const mm = conv[i].kind === 'user' ? /E2E-STEP=([a-z-]+)/.exec(conv[i].text) : null;
|
|
284
|
+
if (mm) {
|
|
285
|
+
at = i;
|
|
286
|
+
step = mm[1];
|
|
287
|
+
break;
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
let answer: ToolStep | { text: string } = { text: 'ok' };
|
|
291
|
+
if (step) {
|
|
292
|
+
const after = conv
|
|
293
|
+
.slice(at + 1)
|
|
294
|
+
.filter((c) => c.kind === 'tool')
|
|
295
|
+
.map((c) => c.text);
|
|
296
|
+
m.received.set(step, after);
|
|
297
|
+
const fn = m.script.get(step);
|
|
298
|
+
if (fn && tools.length) answer = fn(tools, after);
|
|
299
|
+
}
|
|
300
|
+
appendFileSync(
|
|
301
|
+
log,
|
|
302
|
+
`${JSON.stringify({ n, path: url.pathname, step, tools: tools.length, answer })}\n`
|
|
303
|
+
);
|
|
304
|
+
if (n === 1) appendFileSync(log, `${JSON.stringify({ toolDefs: body.tools ?? null })}\n`);
|
|
305
|
+
if ('text' in answer && api === 'responses') return responsesText(answer.text, n);
|
|
306
|
+
return 'text' in answer
|
|
307
|
+
? respond(api, null, n, url.pathname, answer.text)
|
|
308
|
+
: respond(api, answer, n, url.pathname);
|
|
309
|
+
},
|
|
310
|
+
});
|
|
311
|
+
m.url = `http://127.0.0.1:${server.port}`;
|
|
312
|
+
m.stop = () => server.stop(true);
|
|
313
|
+
return m;
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
/**
|
|
317
|
+
* A text answer on the Responses wire WITH the streamed deltas: Codex shows an assistant message
|
|
318
|
+
* from `response.output_text.delta`, not from the finished item alone (the probe's `respond` sends
|
|
319
|
+
* only the item, enough for tool calls).
|
|
320
|
+
*/
|
|
321
|
+
function responsesText(text: string, n: number): Response {
|
|
322
|
+
const id = `r${n}`;
|
|
323
|
+
const itemId = `m${n}`;
|
|
324
|
+
const part = { type: 'output_text', text, annotations: [] };
|
|
325
|
+
const item = {
|
|
326
|
+
type: 'message',
|
|
327
|
+
role: 'assistant',
|
|
328
|
+
id: itemId,
|
|
329
|
+
status: 'completed',
|
|
330
|
+
content: [part],
|
|
331
|
+
};
|
|
332
|
+
const usage = {
|
|
333
|
+
input_tokens: 1,
|
|
334
|
+
input_tokens_details: { cached_tokens: 0 },
|
|
335
|
+
output_tokens: 1,
|
|
336
|
+
output_tokens_details: { reasoning_tokens: 0 },
|
|
337
|
+
total_tokens: 2,
|
|
338
|
+
};
|
|
339
|
+
const at = { item_id: itemId, output_index: 0, content_index: 0 };
|
|
340
|
+
const events = [
|
|
341
|
+
{ type: 'response.created', response: { id } },
|
|
342
|
+
{
|
|
343
|
+
type: 'response.output_item.added',
|
|
344
|
+
output_index: 0,
|
|
345
|
+
item: { ...item, status: 'in_progress', content: [] },
|
|
346
|
+
},
|
|
347
|
+
{ type: 'response.content_part.added', ...at, part: { ...part, text: '' } },
|
|
348
|
+
{ type: 'response.output_text.delta', ...at, delta: text },
|
|
349
|
+
{ type: 'response.output_text.done', ...at, text },
|
|
350
|
+
{ type: 'response.content_part.done', ...at, part },
|
|
351
|
+
{ type: 'response.output_item.done', output_index: 0, item },
|
|
352
|
+
{ type: 'response.completed', response: { id, usage, output: [item] } },
|
|
353
|
+
];
|
|
354
|
+
return new Response(
|
|
355
|
+
events.map((e) => `event: ${e.type}\ndata: ${JSON.stringify(e)}\n\n`).join(''),
|
|
356
|
+
{ headers: { 'content-type': 'text/event-stream' } }
|
|
357
|
+
);
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
function codexExec(tools: readonly string[], cmd: string): ToolStep {
|
|
361
|
+
if (tools.includes('exec_command')) return { name: 'exec_command', args: { cmd } };
|
|
362
|
+
if (tools.includes('shell_command')) return { name: 'shell_command', args: { command: cmd } };
|
|
363
|
+
return { name: 'shell', args: { command: ['bash', '-lc', cmd] } };
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
/** One tool call, then text. Codex has only the shell; opencode has write / read / bash. */
|
|
367
|
+
function once(make: (tools: readonly string[]) => ToolStep): StepFn {
|
|
368
|
+
return (tools, after) => (after.length ? { text: 'ok' } : make(tools));
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
// ---------------------------------------------------------------------------------- the server
|
|
372
|
+
|
|
373
|
+
const API_KEY = randomBytes(32).toString('hex');
|
|
374
|
+
|
|
375
|
+
interface Server {
|
|
376
|
+
proc: Subprocess;
|
|
377
|
+
port: number;
|
|
378
|
+
origin: string;
|
|
379
|
+
cookie: string;
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
let portSeed = 47000 + Math.floor(Math.random() * 2000);
|
|
383
|
+
async function freePort(): Promise<number> {
|
|
384
|
+
for (;;) {
|
|
385
|
+
const p = portSeed++;
|
|
386
|
+
try {
|
|
387
|
+
const s = Bun.serve({ port: p, hostname: '127.0.0.1', fetch: () => new Response('') });
|
|
388
|
+
s.stop(true);
|
|
389
|
+
return p;
|
|
390
|
+
} catch {
|
|
391
|
+
/* taken */
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
async function boot(w: World, modelUrl: string | null, tag: string): Promise<Server> {
|
|
397
|
+
const port = await freePort();
|
|
398
|
+
const env: Record<string, string> = {
|
|
399
|
+
PATH: w.path,
|
|
400
|
+
HOME: w.home,
|
|
401
|
+
USER: process.env.USER ?? 'e2e',
|
|
402
|
+
LOGNAME: process.env.LOGNAME ?? 'e2e',
|
|
403
|
+
SHELL: '/bin/sh',
|
|
404
|
+
LANG: 'en_US.UTF-8',
|
|
405
|
+
TMPDIR: process.env.TMPDIR ?? tmpdir(),
|
|
406
|
+
XDG_CONFIG_HOME: w.xdgConfig,
|
|
407
|
+
XDG_STATE_HOME: w.stateDir,
|
|
408
|
+
XDG_DATA_HOME: join(w.base, 'data'),
|
|
409
|
+
XDG_CACHE_HOME: join(w.base, 'cache'),
|
|
410
|
+
CODEX_HOME: w.codexHome,
|
|
411
|
+
NO_OPEN: '1',
|
|
412
|
+
MAUDE_NO_AUTOBUILD: '1',
|
|
413
|
+
MAUDE_EXIT_WITH_PARENT: '1',
|
|
414
|
+
MAUDE_MACHINE_FILE: join(w.designRoot, '_state', 'machine.json'),
|
|
415
|
+
// The desktop app's posture: a per-spawn key, every main-origin caller needs it or the session.
|
|
416
|
+
MAUDE_SHELL_API_KEY: API_KEY,
|
|
417
|
+
// No hub, no cloud.
|
|
418
|
+
MAUDE_APP_BOUND_HUB: '',
|
|
419
|
+
};
|
|
420
|
+
if (modelUrl) env[E2E_AGENT_MODEL_SWITCH] = modelUrl;
|
|
421
|
+
const logFile = join(RUN_DIR, `${w.id}-server-${tag}.log`);
|
|
422
|
+
const proc = Bun.spawn(
|
|
423
|
+
[
|
|
424
|
+
process.execPath,
|
|
425
|
+
'run',
|
|
426
|
+
join(STUDIO, 'server.ts'),
|
|
427
|
+
'--port',
|
|
428
|
+
String(port),
|
|
429
|
+
'--root',
|
|
430
|
+
w.project,
|
|
431
|
+
],
|
|
432
|
+
{
|
|
433
|
+
cwd: STUDIO,
|
|
434
|
+
env,
|
|
435
|
+
stdout: Bun.file(logFile),
|
|
436
|
+
stderr: Bun.file(`${logFile}.err`),
|
|
437
|
+
}
|
|
438
|
+
);
|
|
439
|
+
const origin = `http://127.0.0.1:${port}`;
|
|
440
|
+
const t0 = Date.now();
|
|
441
|
+
for (;;) {
|
|
442
|
+
if (Date.now() - t0 > 30_000) {
|
|
443
|
+
proc.kill('SIGKILL');
|
|
444
|
+
throw new Error(`server did not start (see ${logFile}.err)`);
|
|
445
|
+
}
|
|
446
|
+
try {
|
|
447
|
+
const r = await fetch(`${origin}/_health`, { signal: AbortSignal.timeout(500) });
|
|
448
|
+
if (r.ok && ((await r.json()) as { pid?: number }).pid === proc.pid) break;
|
|
449
|
+
} catch {
|
|
450
|
+
/* not up */
|
|
451
|
+
}
|
|
452
|
+
await sleep(100);
|
|
453
|
+
}
|
|
454
|
+
// The page's session (the person): POST the key once, then the cookie alone.
|
|
455
|
+
const s = await fetch(`${origin}/_api/shell/session`, {
|
|
456
|
+
method: 'POST',
|
|
457
|
+
headers: { 'x-maude-api-key': API_KEY, Origin: origin },
|
|
458
|
+
});
|
|
459
|
+
const cookie = (s.headers.get('set-cookie') ?? '').split(';')[0];
|
|
460
|
+
if (!cookie) throw new Error(`no session cookie (${s.status})`);
|
|
461
|
+
return { proc, port, origin, cookie };
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
async function stop(s: Server) {
|
|
465
|
+
s.proc.kill('SIGTERM');
|
|
466
|
+
const done = await Promise.race([s.proc.exited.then(() => true), sleep(8000).then(() => false)]);
|
|
467
|
+
if (!done) s.proc.kill('SIGKILL');
|
|
468
|
+
await s.proc.exited;
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
const personHeaders = (s: Server) => ({
|
|
472
|
+
Cookie: s.cookie,
|
|
473
|
+
Origin: s.origin,
|
|
474
|
+
'Sec-Fetch-Site': 'same-origin',
|
|
475
|
+
'Content-Type': 'application/json',
|
|
476
|
+
});
|
|
477
|
+
|
|
478
|
+
async function getAgents(s: Server) {
|
|
479
|
+
const r = await fetch(`${s.origin}/_api/agents?refresh=1`, {
|
|
480
|
+
headers: { 'x-maude-api-key': API_KEY },
|
|
481
|
+
});
|
|
482
|
+
return (await r.json()) as {
|
|
483
|
+
agents: Record<string, unknown>[];
|
|
484
|
+
offerAgents: string[];
|
|
485
|
+
};
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
async function post(s: Server, path: string, body: unknown = {}, person = true) {
|
|
489
|
+
const r = await fetch(`${s.origin}${path}`, {
|
|
490
|
+
method: 'POST',
|
|
491
|
+
headers: person
|
|
492
|
+
? personHeaders(s)
|
|
493
|
+
: { 'x-maude-api-key': API_KEY, Origin: s.origin, 'Content-Type': 'application/json' },
|
|
494
|
+
body: JSON.stringify(body),
|
|
495
|
+
signal: AbortSignal.timeout(180_000),
|
|
496
|
+
});
|
|
497
|
+
let json: Record<string, unknown> = {};
|
|
498
|
+
try {
|
|
499
|
+
json = (await r.json()) as Record<string, unknown>;
|
|
500
|
+
} catch {
|
|
501
|
+
/* empty */
|
|
502
|
+
}
|
|
503
|
+
return { status: r.status, json };
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
// ------------------------------------------------------------------------------------- the WS
|
|
507
|
+
|
|
508
|
+
type Frame = Record<string, unknown> & { t?: string };
|
|
509
|
+
class Socket {
|
|
510
|
+
frames: Frame[] = [];
|
|
511
|
+
ws: WebSocket;
|
|
512
|
+
open: Promise<void>;
|
|
513
|
+
constructor(s: Server, log: string) {
|
|
514
|
+
this.ws = new WebSocket(`ws://127.0.0.1:${s.port}/_ws/acp`, {
|
|
515
|
+
headers: { Origin: s.origin, Cookie: s.cookie },
|
|
516
|
+
} as unknown as string[]);
|
|
517
|
+
this.open = new Promise((res, rej) => {
|
|
518
|
+
this.ws.onopen = () => res();
|
|
519
|
+
this.ws.onerror = () => rej(new Error('ws error'));
|
|
520
|
+
});
|
|
521
|
+
this.ws.onmessage = (ev) => {
|
|
522
|
+
const f = JSON.parse(String(ev.data)) as Frame;
|
|
523
|
+
this.frames.push(f);
|
|
524
|
+
appendFileSync(log, `${JSON.stringify(f)}\n`);
|
|
525
|
+
};
|
|
526
|
+
}
|
|
527
|
+
send(f: Frame) {
|
|
528
|
+
this.ws.send(JSON.stringify(f));
|
|
529
|
+
}
|
|
530
|
+
mark() {
|
|
531
|
+
return this.frames.length;
|
|
532
|
+
}
|
|
533
|
+
since(i: number) {
|
|
534
|
+
return this.frames.slice(i);
|
|
535
|
+
}
|
|
536
|
+
async waitFor(pred: (f: Frame) => boolean, from: number, ms: number): Promise<Frame | null> {
|
|
537
|
+
const t0 = Date.now();
|
|
538
|
+
while (Date.now() - t0 < ms) {
|
|
539
|
+
const hit = this.frames.slice(from).find(pred);
|
|
540
|
+
if (hit) return hit;
|
|
541
|
+
await sleep(50);
|
|
542
|
+
}
|
|
543
|
+
return null;
|
|
544
|
+
}
|
|
545
|
+
close() {
|
|
546
|
+
try {
|
|
547
|
+
this.ws.close();
|
|
548
|
+
} catch {
|
|
549
|
+
/* gone */
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
const updateText = (frames: Frame[]) =>
|
|
555
|
+
frames
|
|
556
|
+
.filter((f) => f.t === 'update')
|
|
557
|
+
.map((f) => JSON.stringify(f.update ?? ''))
|
|
558
|
+
.join('\n');
|
|
559
|
+
|
|
560
|
+
/** Send a prompt, answer any permission card with a reject, wait for turn-end or an error. */
|
|
561
|
+
async function turn(
|
|
562
|
+
sock: Socket,
|
|
563
|
+
chat: string,
|
|
564
|
+
text: string,
|
|
565
|
+
ms = 120_000,
|
|
566
|
+
opts: { answer?: 'reject' | 'approve'; may?: { assets: boolean; web: boolean } } = {}
|
|
567
|
+
): Promise<{ frames: Frame[]; end: Frame | null; cards: Frame[] }> {
|
|
568
|
+
const from = sock.mark();
|
|
569
|
+
sock.send({ t: 'prompt', chat, text, ...(opts.may ? { may: opts.may } : {}) });
|
|
570
|
+
const answered = new Set<string>();
|
|
571
|
+
const t0 = Date.now();
|
|
572
|
+
let end: Frame | null = null;
|
|
573
|
+
while (Date.now() - t0 < ms) {
|
|
574
|
+
const fs = sock.since(from);
|
|
575
|
+
for (const f of fs) {
|
|
576
|
+
if (f.t === 'permission-request' && typeof f.id === 'string' && !answered.has(f.id)) {
|
|
577
|
+
answered.add(f.id);
|
|
578
|
+
const options = (f.options ?? (f.toolCall as Frame | undefined)?.options ?? []) as {
|
|
579
|
+
optionId: string;
|
|
580
|
+
kind?: string;
|
|
581
|
+
}[];
|
|
582
|
+
const pick =
|
|
583
|
+
opts.answer === 'approve'
|
|
584
|
+
? options.find((o) => o.kind === 'allow_once')
|
|
585
|
+
: options.find((o) => o.kind?.startsWith('reject'));
|
|
586
|
+
sock.send({
|
|
587
|
+
t: 'permission-response',
|
|
588
|
+
chat,
|
|
589
|
+
id: f.id,
|
|
590
|
+
decision: pick?.optionId ?? 'cancelled',
|
|
591
|
+
});
|
|
592
|
+
}
|
|
593
|
+
}
|
|
594
|
+
// A `queued` prompt (a closed outbox gate) never runs in this world: fail fast on it.
|
|
595
|
+
end =
|
|
596
|
+
fs.find(
|
|
597
|
+
(f) => f.t === 'turn-end' || ((f.t === 'error' || f.t === 'queued') && f.chat === chat)
|
|
598
|
+
) ?? null;
|
|
599
|
+
if (end) break;
|
|
600
|
+
await sleep(50);
|
|
601
|
+
}
|
|
602
|
+
const frames = sock.since(from);
|
|
603
|
+
return { frames, end, cards: frames.filter((f) => f.t === 'permission-request') };
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
// ------------------------------------------------------------------------------- process scan
|
|
607
|
+
|
|
608
|
+
function strays(): string[] {
|
|
609
|
+
const out = spawnSync('ps', ['-axeww', '-o', 'pid=,command='], { encoding: 'utf8' }).stdout;
|
|
610
|
+
return out
|
|
611
|
+
.split('\n')
|
|
612
|
+
.filter((l) => l.includes(SCRATCH_ROOT) || l.includes(CONFORMANCE_ROOT))
|
|
613
|
+
.filter((l) => /codex|opencode|server\.ts|acp/i.test(l))
|
|
614
|
+
.filter((l) => !l.trim().startsWith(`${process.pid} `))
|
|
615
|
+
.filter((l) => !/\bps -axeww\b|acp-e2e-local/.test(l))
|
|
616
|
+
.map((l) => clip(l, 160));
|
|
617
|
+
}
|
|
618
|
+
|
|
619
|
+
// ----------------------------------------------------------------------------------- per agent
|
|
620
|
+
|
|
621
|
+
async function runAgent(id: 'codex' | 'opencode') {
|
|
622
|
+
console.log(`\n== ${id}`);
|
|
623
|
+
const d = agentById(id);
|
|
624
|
+
if (!d) throw new Error(`no catalog entry for ${id}`);
|
|
625
|
+
let w: World;
|
|
626
|
+
try {
|
|
627
|
+
w = makeWorld(id, [id]);
|
|
628
|
+
} catch (e) {
|
|
629
|
+
record(id, '0 setup', null, (e as Error).message);
|
|
630
|
+
return;
|
|
631
|
+
}
|
|
632
|
+
const other = id === 'codex' ? 'opencode' : 'codex';
|
|
633
|
+
const model = startModel(
|
|
634
|
+
id === 'codex' ? 'responses' : 'chat',
|
|
635
|
+
join(RUN_DIR, `${id}-model.ndjson`)
|
|
636
|
+
);
|
|
637
|
+
let canaryHits = 0;
|
|
638
|
+
const canaryToken = tok('CANARY');
|
|
639
|
+
const canary = Bun.serve({
|
|
640
|
+
port: 0,
|
|
641
|
+
hostname: '127.0.0.1',
|
|
642
|
+
fetch() {
|
|
643
|
+
canaryHits++;
|
|
644
|
+
return new Response(canaryToken);
|
|
645
|
+
},
|
|
646
|
+
});
|
|
647
|
+
const canaryUrl = `http://127.0.0.1:${canary.port}/`;
|
|
648
|
+
let s: Server | null = null;
|
|
649
|
+
try {
|
|
650
|
+
s = await boot(w, model.url, 'a');
|
|
651
|
+
|
|
652
|
+
// 1 — discovery and the offer
|
|
653
|
+
await guarded(id, '1 discover + offer', async () => {
|
|
654
|
+
const { agents, offerAgents } = await getAgents(s as Server);
|
|
655
|
+
const row = agents.find((a) => a.id === id) ?? {};
|
|
656
|
+
const ok =
|
|
657
|
+
row.installed === true &&
|
|
658
|
+
row.fit === 'ok' &&
|
|
659
|
+
row.policy === 'bridge-enforced' &&
|
|
660
|
+
offerAgents.includes(id);
|
|
661
|
+
return [
|
|
662
|
+
ok,
|
|
663
|
+
`installed=${row.installed} version=${row.version} fit=${row.fit} policy=${row.policy} realBin=${row.realBin} auth=${row.auth} state=${row.state} offerAgents=${JSON.stringify(offerAgents)}`,
|
|
664
|
+
];
|
|
665
|
+
});
|
|
666
|
+
|
|
667
|
+
// 2 — connect (the real conformance probe), as the person only
|
|
668
|
+
await guarded(id, '2a helper connect refused', async () => {
|
|
669
|
+
const r = await post(s as Server, `/_api/agents/${id}/connect`, {}, false);
|
|
670
|
+
return [r.status === 403, `key-only connect → ${r.status} ${JSON.stringify(r.json)}`];
|
|
671
|
+
});
|
|
672
|
+
await guarded(id, '2b connect (real probe)', async () => {
|
|
673
|
+
const t0 = Date.now();
|
|
674
|
+
const r = await post(s as Server, `/_api/agents/${id}/connect`);
|
|
675
|
+
const { agents, offerAgents } = await getAgents(s as Server);
|
|
676
|
+
const row = agents.find((a) => a.id === id) ?? {};
|
|
677
|
+
const ok =
|
|
678
|
+
r.json.connected === true && row.state === 'connected' && !offerAgents.includes(id);
|
|
679
|
+
return [
|
|
680
|
+
ok,
|
|
681
|
+
`${r.status} ${JSON.stringify(r.json)} in ${Math.round((Date.now() - t0) / 1000)} s; re-GET state=${row.state} offerAgents=${JSON.stringify(offerAgents)}`,
|
|
682
|
+
];
|
|
683
|
+
});
|
|
684
|
+
await guarded(id, '2c dismiss-offer persists', async () => {
|
|
685
|
+
const r = await post(s as Server, '/_api/agents/gemini/dismiss-offer');
|
|
686
|
+
await stop(s as Server);
|
|
687
|
+
s = await boot(w, model.url, 'b');
|
|
688
|
+
const { agents } = await getAgents(s);
|
|
689
|
+
const gem = agents.find((a) => a.id === 'gemini') ?? {};
|
|
690
|
+
const me = agents.find((a) => a.id === id) ?? {};
|
|
691
|
+
return [
|
|
692
|
+
r.json.ok === true && gem.offerDismissed === true && me.state === 'connected',
|
|
693
|
+
`dismiss → ${r.status}; after restart gemini.offerDismissed=${gem.offerDismissed}, ${id}.state=${me.state}`,
|
|
694
|
+
];
|
|
695
|
+
});
|
|
696
|
+
|
|
697
|
+
// 3 — a chat on the agent
|
|
698
|
+
const sock = new Socket(s, join(RUN_DIR, `${id}-frames.ndjson`));
|
|
699
|
+
await sock.open;
|
|
700
|
+
const chat = `e2e-${id}-1`;
|
|
701
|
+
const hello = tok('HELLO');
|
|
702
|
+
model.script.set('hello', () => ({ text: hello }));
|
|
703
|
+
await guarded(id, '3a attach', async () => {
|
|
704
|
+
const from = sock.mark();
|
|
705
|
+
sock.send({ t: 'attach', chat, seq: 0, agent: id });
|
|
706
|
+
const f = await sock.waitFor((x) => x.t === 'attached' || x.t === 'error', from, 30_000);
|
|
707
|
+
const agent = (f?.agent ?? {}) as { id?: string };
|
|
708
|
+
return [f?.t === 'attached' && agent.id === id, JSON.stringify(f)];
|
|
709
|
+
});
|
|
710
|
+
await guarded(id, '3b prompt → text', async () => {
|
|
711
|
+
const r = await turn(sock, chat, 'E2E-STEP=hello say hello');
|
|
712
|
+
const text = updateText(r.frames);
|
|
713
|
+
const meta = join(w.designRoot, '_chat', `${chat}.meta.json`);
|
|
714
|
+
const metaAgent = existsSync(meta) ? JSON.parse(readFileSync(meta, 'utf8')).agent : null;
|
|
715
|
+
const updates = r.frames.filter((f) => f.t === 'update').length;
|
|
716
|
+
return [
|
|
717
|
+
r.end?.t === 'turn-end' && text.includes(hello) && metaAgent === id,
|
|
718
|
+
`end=${JSON.stringify(r.end)} updates=${updates} modelText=${text.includes(hello)} meta.agent=${metaAgent}`,
|
|
719
|
+
];
|
|
720
|
+
});
|
|
721
|
+
|
|
722
|
+
// 4 — scripted tool calls
|
|
723
|
+
const inPath = join(w.project, 'e2e-in.txt');
|
|
724
|
+
const inTok = tok('IN');
|
|
725
|
+
model.script.set(
|
|
726
|
+
'write-in',
|
|
727
|
+
once((tools) =>
|
|
728
|
+
id === 'codex'
|
|
729
|
+
? codexExec(tools, `printf %s ${sq(inTok)} > ${sq(inPath)} && echo wrote`)
|
|
730
|
+
: { name: 'write', args: { filePath: inPath, content: inTok } }
|
|
731
|
+
)
|
|
732
|
+
);
|
|
733
|
+
await guarded(id, '4a in-project write', async () => {
|
|
734
|
+
const r = await turn(sock, chat, 'E2E-STEP=write-in write the file');
|
|
735
|
+
const content = existsSync(inPath) ? readFileSync(inPath, 'utf8') : null;
|
|
736
|
+
return [
|
|
737
|
+
content === inTok && r.cards.length === 0 && r.end?.t === 'turn-end',
|
|
738
|
+
`written=${content === inTok} cards=${r.cards.length} end=${JSON.stringify(r.end)} model got=${clip(JSON.stringify(model.received.get('write-in') ?? []))}`,
|
|
739
|
+
];
|
|
740
|
+
});
|
|
741
|
+
|
|
742
|
+
const outPath = join(w.outside, 'e2e-out.txt');
|
|
743
|
+
model.script.set(
|
|
744
|
+
'write-out',
|
|
745
|
+
once((tools) =>
|
|
746
|
+
id === 'codex'
|
|
747
|
+
? codexExec(tools, `printf x > ${sq(outPath)} && echo wrote`)
|
|
748
|
+
: { name: 'write', args: { filePath: outPath, content: 'x' } }
|
|
749
|
+
)
|
|
750
|
+
);
|
|
751
|
+
await guarded(id, '4b out-of-project write', async () => {
|
|
752
|
+
const r = await turn(sock, chat, 'E2E-STEP=write-out write outside');
|
|
753
|
+
const written = existsSync(outPath);
|
|
754
|
+
const refusedEnd = r.end?.t === 'turn-end' && r.end.reason === 'refused';
|
|
755
|
+
const got = model.received.get('write-out') ?? [];
|
|
756
|
+
return [
|
|
757
|
+
!written && (r.cards.length > 0 || refusedEnd || got.length > 0) && !!r.end,
|
|
758
|
+
`written=${written} cards=${r.cards.length} end=${JSON.stringify(r.end)} model got=${clip(JSON.stringify(got))}`,
|
|
759
|
+
];
|
|
760
|
+
});
|
|
761
|
+
|
|
762
|
+
if (id === 'codex') {
|
|
763
|
+
// The model asks Codex to run the same write OUTSIDE its sandbox (an escalation request):
|
|
764
|
+
// Codex asks the client; the bridge's gate answers for an out-of-project path.
|
|
765
|
+
model.script.set(
|
|
766
|
+
'write-out-esc',
|
|
767
|
+
once((tools) => {
|
|
768
|
+
const step = codexExec(tools, `printf x > ${sq(outPath)} && echo wrote`);
|
|
769
|
+
return {
|
|
770
|
+
...step,
|
|
771
|
+
args: { ...step.args, sandbox_permissions: 'require_escalated', justification: 'e2e' },
|
|
772
|
+
};
|
|
773
|
+
})
|
|
774
|
+
);
|
|
775
|
+
await guarded(id, '4b2 escalated outside write', async () => {
|
|
776
|
+
const r = await turn(sock, chat, 'E2E-STEP=write-out-esc write outside, escalated');
|
|
777
|
+
const written = existsSync(outPath);
|
|
778
|
+
const got = model.received.get('write-out-esc') ?? [];
|
|
779
|
+
return [
|
|
780
|
+
!written && !!r.end,
|
|
781
|
+
`written=${written} cards=${r.cards.length} end=${JSON.stringify(r.end)} model got=${clip(JSON.stringify(got))}`,
|
|
782
|
+
];
|
|
783
|
+
});
|
|
784
|
+
}
|
|
785
|
+
|
|
786
|
+
model.script.set(
|
|
787
|
+
'cred-read',
|
|
788
|
+
once((tools) =>
|
|
789
|
+
id === 'codex'
|
|
790
|
+
? codexExec(tools, `cat ${sq(w.keysPath)}; cat ${sq(join(w.codexHome, 'auth.json'))}`)
|
|
791
|
+
: { name: 'read', args: { filePath: w.keysPath } }
|
|
792
|
+
)
|
|
793
|
+
);
|
|
794
|
+
await guarded(id, '4c credential read', async () => {
|
|
795
|
+
const r = await turn(sock, chat, 'E2E-STEP=cred-read read the keys');
|
|
796
|
+
const leaked = w.secrets.filter((x) => model.bodies.some((b) => b.includes(x)));
|
|
797
|
+
const inFrames = w.secrets.filter((x) => JSON.stringify(r.frames).includes(x));
|
|
798
|
+
return [
|
|
799
|
+
leaked.length === 0 && inFrames.length === 0 && !!r.end,
|
|
800
|
+
`leaked to model=${leaked.length} in frames=${inFrames.length} cards=${r.cards.length} end=${JSON.stringify(r.end)} model got=${clip(JSON.stringify(model.received.get('cred-read') ?? []))}`,
|
|
801
|
+
];
|
|
802
|
+
});
|
|
803
|
+
|
|
804
|
+
model.script.set(
|
|
805
|
+
'curl',
|
|
806
|
+
once((tools) =>
|
|
807
|
+
id === 'codex'
|
|
808
|
+
? codexExec(tools, `/usr/bin/curl -sS -m 5 ${sq(canaryUrl)}`)
|
|
809
|
+
: {
|
|
810
|
+
name: 'bash',
|
|
811
|
+
args: { command: `/usr/bin/curl -sS -m 5 ${sq(canaryUrl)}`, description: 'egress' },
|
|
812
|
+
}
|
|
813
|
+
)
|
|
814
|
+
);
|
|
815
|
+
await guarded(id, '4d curl egress', async () => {
|
|
816
|
+
const r = await turn(sock, chat, 'E2E-STEP=curl fetch it');
|
|
817
|
+
const got = model.received.get('curl') ?? [];
|
|
818
|
+
const reached = got.some((g) => g.includes(canaryToken));
|
|
819
|
+
return [
|
|
820
|
+
canaryHits === 0 && !reached && !!r.end,
|
|
821
|
+
`canaryHits=${canaryHits} model got token=${reached} cards=${r.cards.length} end=${JSON.stringify(r.end)} model got=${clip(JSON.stringify(got))}`,
|
|
822
|
+
];
|
|
823
|
+
});
|
|
824
|
+
|
|
825
|
+
// 4d2 — "AI may search the web: off", and the person APPROVES every card: still no egress.
|
|
826
|
+
model.script.set(
|
|
827
|
+
'curl-off',
|
|
828
|
+
once((tools) => {
|
|
829
|
+
const cmd = `/usr/bin/curl -sS -m 5 ${sq(canaryUrl)}`;
|
|
830
|
+
if (id !== 'codex') return { name: 'bash', args: { command: cmd, description: 'egress' } };
|
|
831
|
+
const step = codexExec(tools, cmd);
|
|
832
|
+
return {
|
|
833
|
+
...step,
|
|
834
|
+
args: { ...step.args, sandbox_permissions: 'require_escalated', justification: 'e2e' },
|
|
835
|
+
};
|
|
836
|
+
})
|
|
837
|
+
);
|
|
838
|
+
await guarded(id, '4d2 web off, card approved', async () => {
|
|
839
|
+
const r = await turn(sock, chat, 'E2E-STEP=curl-off fetch it', 120_000, {
|
|
840
|
+
answer: 'approve',
|
|
841
|
+
may: { assets: true, web: false },
|
|
842
|
+
});
|
|
843
|
+
const got = model.received.get('curl-off') ?? [];
|
|
844
|
+
const reached = got.some((g) => g.includes(canaryToken));
|
|
845
|
+
return [
|
|
846
|
+
canaryHits === 0 && !reached && !!r.end,
|
|
847
|
+
`canaryHits=${canaryHits} model got token=${reached} cards=${r.cards.length} end=${JSON.stringify(r.end)} model got=${clip(JSON.stringify(got))}`,
|
|
848
|
+
];
|
|
849
|
+
});
|
|
850
|
+
|
|
851
|
+
await guarded(id, '4e set-mode refused', async () => {
|
|
852
|
+
const caps = [...sock.frames].reverse().find((f) => f.t === 'caps') as Frame | undefined;
|
|
853
|
+
const modes = (caps?.modes ?? {}) as {
|
|
854
|
+
currentModeId?: string;
|
|
855
|
+
availableModes?: { id: string }[];
|
|
856
|
+
};
|
|
857
|
+
const allow = d.enforcement?.pinMode?.allow ?? [];
|
|
858
|
+
const tries = [
|
|
859
|
+
'agent',
|
|
860
|
+
...(modes.availableModes ?? [])
|
|
861
|
+
.map((m) => m.id)
|
|
862
|
+
.filter((m) => allow.length && !allow.includes(m)),
|
|
863
|
+
];
|
|
864
|
+
const results: string[] = [];
|
|
865
|
+
let ok = true;
|
|
866
|
+
for (const modeId of [...new Set(tries)]) {
|
|
867
|
+
const from = sock.mark();
|
|
868
|
+
sock.send({ t: 'set-mode', chat, modeId });
|
|
869
|
+
const err = await sock.waitFor(
|
|
870
|
+
(f) => f.t === 'error' && /can't use/.test(String(f.message)),
|
|
871
|
+
from,
|
|
872
|
+
3000
|
|
873
|
+
);
|
|
874
|
+
const after = [...sock.frames].reverse().find((f) => f.t === 'caps') as Frame | undefined;
|
|
875
|
+
const cur = (after?.modes as { currentModeId?: string } | undefined)?.currentModeId;
|
|
876
|
+
const switched = cur === modeId;
|
|
877
|
+
if (switched) ok = false;
|
|
878
|
+
results.push(
|
|
879
|
+
`${modeId}: ${err ? 'refused (error frame)' : 'no error frame'}, current=${cur}`
|
|
880
|
+
);
|
|
881
|
+
}
|
|
882
|
+
return [
|
|
883
|
+
ok,
|
|
884
|
+
`advertised=${JSON.stringify((modes.availableModes ?? []).map((m) => m.id))} pin.allow=${JSON.stringify(allow)}; ${results.join('; ')}`,
|
|
885
|
+
];
|
|
886
|
+
});
|
|
887
|
+
if (model.tools.size) {
|
|
888
|
+
const web = [...model.tools].filter((t) => /web[_-]?(search|fetch)|^fetch$/i.test(t));
|
|
889
|
+
record(id, '4f no web tool offered', web.length === 0, `tools=${[...model.tools].join(',')}`);
|
|
890
|
+
}
|
|
891
|
+
|
|
892
|
+
// 5a — a planted chat naming an unconnected agent
|
|
893
|
+
await guarded(id, '5a unconnected agent refused', async () => {
|
|
894
|
+
const planted = 'e2e-planted';
|
|
895
|
+
mkdirSync(join(w.designRoot, '_chat'), { recursive: true });
|
|
896
|
+
writeFileSync(
|
|
897
|
+
join(w.designRoot, '_chat', `${planted}.meta.json`),
|
|
898
|
+
JSON.stringify({ agent: other })
|
|
899
|
+
);
|
|
900
|
+
const from = sock.mark();
|
|
901
|
+
sock.send({ t: 'attach', chat: planted, seq: 0 });
|
|
902
|
+
const f = await sock.waitFor(
|
|
903
|
+
(x) => (x.t === 'attached' && x.chat === planted) || x.t === 'error',
|
|
904
|
+
from,
|
|
905
|
+
20_000
|
|
906
|
+
);
|
|
907
|
+
return [f?.t === 'error' && f.code === 'agent-not-connected', JSON.stringify(f)];
|
|
908
|
+
});
|
|
909
|
+
|
|
910
|
+
// 5b — opencode refuses to start with a link out of the project
|
|
911
|
+
if (id === 'opencode') {
|
|
912
|
+
await guarded(id, '5b unsafe link refused', async () => {
|
|
913
|
+
const link = join(w.project, 'ref-link');
|
|
914
|
+
symlinkSync(w.outsideSecret, link);
|
|
915
|
+
try {
|
|
916
|
+
const c2 = 'e2e-opencode-link';
|
|
917
|
+
const from = sock.mark();
|
|
918
|
+
sock.send({ t: 'attach', chat: c2, seq: 0, agent: id });
|
|
919
|
+
const a = await sock.waitFor(
|
|
920
|
+
(x) => (x.t === 'attached' && x.chat === c2) || x.t === 'error',
|
|
921
|
+
from,
|
|
922
|
+
20_000
|
|
923
|
+
);
|
|
924
|
+
let f: Frame | null = a?.t === 'error' ? a : null;
|
|
925
|
+
if (!f) {
|
|
926
|
+
const r = await turn(sock, c2, 'E2E-STEP=hello hi', 60_000);
|
|
927
|
+
f = r.end;
|
|
928
|
+
}
|
|
929
|
+
const leaked = model.bodies.some((b) => b.includes(w.secrets[2]));
|
|
930
|
+
return [
|
|
931
|
+
f?.t === 'error' && f.code === 'agent-unsafe-link' && !leaked,
|
|
932
|
+
`attach=${JSON.stringify(a)}; refusal=${JSON.stringify(f)}`,
|
|
933
|
+
];
|
|
934
|
+
} finally {
|
|
935
|
+
rmSync(link, { force: true });
|
|
936
|
+
}
|
|
937
|
+
});
|
|
938
|
+
} else {
|
|
939
|
+
record(
|
|
940
|
+
id,
|
|
941
|
+
'5b unsafe link refused',
|
|
942
|
+
null,
|
|
943
|
+
'Codex is os-sandboxed: not link-scanned by design (S3)'
|
|
944
|
+
);
|
|
945
|
+
}
|
|
946
|
+
sock.close();
|
|
947
|
+
} catch (e) {
|
|
948
|
+
record(id, 'run', false, `threw: ${(e as Error).stack ?? e}`);
|
|
949
|
+
} finally {
|
|
950
|
+
if (s) await stop(s);
|
|
951
|
+
model.stop();
|
|
952
|
+
canary.stop(true);
|
|
953
|
+
}
|
|
954
|
+
|
|
955
|
+
// 7 — nothing left running
|
|
956
|
+
await guarded(id, '7 no stray processes', async () => {
|
|
957
|
+
await sleep(1500);
|
|
958
|
+
const left = strays();
|
|
959
|
+
return [left.length === 0, left.length ? left.join(' || ') : 'none'];
|
|
960
|
+
});
|
|
961
|
+
if (!KEEP) rmSync(w.base, { recursive: true, force: true });
|
|
962
|
+
}
|
|
963
|
+
|
|
964
|
+
async function runClaudeOnly() {
|
|
965
|
+
console.log('\n== claude-only');
|
|
966
|
+
const w = makeWorld('claude-only', []);
|
|
967
|
+
let s: Server | null = null;
|
|
968
|
+
try {
|
|
969
|
+
s = await boot(w, null, 'a');
|
|
970
|
+
await guarded('claude-only', '6 nothing offered', async () => {
|
|
971
|
+
const { agents, offerAgents } = await getAgents(s as Server);
|
|
972
|
+
const installed = agents.filter((a) => a.installed).map((a) => a.id);
|
|
973
|
+
return [
|
|
974
|
+
Array.isArray(offerAgents) && offerAgents.length === 0,
|
|
975
|
+
`offerAgents=${JSON.stringify(offerAgents)} installed=${JSON.stringify(installed)}`,
|
|
976
|
+
];
|
|
977
|
+
});
|
|
978
|
+
} catch (e) {
|
|
979
|
+
record('claude-only', '6 nothing offered', false, `threw: ${(e as Error).message}`);
|
|
980
|
+
} finally {
|
|
981
|
+
if (s) await stop(s);
|
|
982
|
+
}
|
|
983
|
+
await guarded('claude-only', '7 no stray processes', async () => {
|
|
984
|
+
await sleep(500);
|
|
985
|
+
const left = strays();
|
|
986
|
+
return [left.length === 0, left.length ? left.join(' || ') : 'none'];
|
|
987
|
+
});
|
|
988
|
+
if (!KEEP) rmSync(w.base, { recursive: true, force: true });
|
|
989
|
+
}
|
|
990
|
+
|
|
991
|
+
// ------------------------------------------------------------------------------------------ main
|
|
992
|
+
|
|
993
|
+
const versions: string[] = [];
|
|
994
|
+
for (const id of AGENTS) await runAgent(id);
|
|
995
|
+
await runClaudeOnly();
|
|
996
|
+
for (const id of AGENTS) {
|
|
997
|
+
const b = id === 'codex' ? personCodexBin() : Bun.which('opencode');
|
|
998
|
+
if (b) {
|
|
999
|
+
const v = spawnSync(b, ['--version'], { encoding: 'utf8', timeout: 5000 }).stdout.trim();
|
|
1000
|
+
versions.push(`${id}: ${v} (${b})`);
|
|
1001
|
+
}
|
|
1002
|
+
}
|
|
1003
|
+
|
|
1004
|
+
const mark = (ok: boolean | null) => (ok === null ? 'n/a' : ok ? 'PASS' : 'FAIL');
|
|
1005
|
+
const table = [
|
|
1006
|
+
'| Agent | Step | Result | Detail |',
|
|
1007
|
+
'| --- | --- | --- | --- |',
|
|
1008
|
+
...rows.map((r) => `| ${r.agent} | ${r.step} | ${mark(r.ok)} | ${clip(r.detail, 400)} |`),
|
|
1009
|
+
].join('\n');
|
|
1010
|
+
const failed = rows.filter((r) => r.ok === false).length;
|
|
1011
|
+
const report = [
|
|
1012
|
+
'# universal-ACP agents through the real server — run report',
|
|
1013
|
+
'',
|
|
1014
|
+
`- Date: ${new Date().toISOString()}`,
|
|
1015
|
+
`- Commit: ${spawnSync('git', ['rev-parse', '--short', 'HEAD'], { cwd: REPO, encoding: 'utf8' }).stdout.trim()}`,
|
|
1016
|
+
`- Agents: ${versions.join('; ')}`,
|
|
1017
|
+
`- Scratch: ${SCRATCH_ROOT} (HOME, XDG_*, CODEX_HOME; stub claude; fake keys)`,
|
|
1018
|
+
`- Model: loopback scripted model per agent (${E2E_AGENT_MODEL_SWITCH}); frames + model log + server logs beside this file`,
|
|
1019
|
+
`- Verdict: ${failed ? `FAIL (${failed})` : 'PASS'}`,
|
|
1020
|
+
'',
|
|
1021
|
+
table,
|
|
1022
|
+
'',
|
|
1023
|
+
].join('\n');
|
|
1024
|
+
writeFileSync(join(RUN_DIR, 'report.md'), report);
|
|
1025
|
+
console.log(`\n${table}\n\nreport: ${join(RUN_DIR, 'report.md')}`);
|
|
1026
|
+
process.exit(failed ? 1 : 0);
|