@jbkjr/relay 0.0.0-stage → 1.2.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/LICENSE +21 -0
- package/LICENSES/Apache-2.0.txt +201 -0
- package/LICENSES/README.md +19 -0
- package/LICENSES/codex-NOTICE.txt +6 -0
- package/README.md +393 -2
- package/SECURITY.md +145 -0
- package/adapters/briefs/claude.md +43 -0
- package/adapters/briefs/codex.md +56 -0
- package/adapters/briefs/models.json +33 -0
- package/adapters/build.mjs +8 -0
- package/adapters/claude/.claude-plugin/marketplace.json +13 -0
- package/adapters/claude/relay/.claude-plugin/plugin.json +5 -0
- package/adapters/claude/relay/agents/codex.md +21 -0
- package/adapters/claude/relay/agents/operator.md +21 -0
- package/adapters/claude/relay/skills/ask/SKILL.md +20 -0
- package/adapters/claude/relay/skills/chat/SKILL.md +13 -0
- package/adapters/claude/relay/skills/delegate/SKILL.md +21 -0
- package/adapters/claude/relay/skills/discuss/SKILL.md +19 -0
- package/adapters/claude/relay/skills/review/SKILL.md +21 -0
- package/adapters/claude/relay/skills/tree/SKILL.md +10 -0
- package/adapters/claude/relay/skills/write-for-codex/SKILL.md +78 -0
- package/adapters/codex/.agents/plugins/marketplace.json +20 -0
- package/adapters/codex/AGENTS.snippet.md +5 -0
- package/adapters/codex/relay/.codex-plugin/plugin.json +6 -0
- package/adapters/codex/relay/skills/relay-ask/SKILL.md +20 -0
- package/adapters/codex/relay/skills/relay-chat/SKILL.md +13 -0
- package/adapters/codex/relay/skills/relay-delegate/SKILL.md +21 -0
- package/adapters/codex/relay/skills/relay-discuss/SKILL.md +19 -0
- package/adapters/codex/relay/skills/relay-review/SKILL.md +21 -0
- package/adapters/codex/relay/skills/relay-tree/SKILL.md +10 -0
- package/adapters/codex/relay/skills/relay-write-for-claude/SKILL.md +66 -0
- package/adapters/generate.mjs +124 -0
- package/bin/relay +59 -0
- package/codex-pin.json +12 -0
- package/dist/backends/acp.js +1424 -0
- package/dist/backends/claude.js +890 -0
- package/dist/backends/cli-version.js +112 -0
- package/dist/backends/codex-app.js +1539 -0
- package/dist/backends/codex-daybreak.js +75 -0
- package/dist/backends/codex-env.js +656 -0
- package/dist/backends/codex-network.js +304 -0
- package/dist/backends/codex-pin.js +345 -0
- package/dist/backends/codex-shell-policy.js +182 -0
- package/dist/backends/codex-stage2.js +998 -0
- package/dist/backends/codex-subagents.js +47 -0
- package/dist/backends/codex.js +641 -0
- package/dist/backends/copilot.js +246 -0
- package/dist/backends/env.js +147 -0
- package/dist/backends/gemini.js +607 -0
- package/dist/backends/grok.js +337 -0
- package/dist/backends/index.js +8 -0
- package/dist/backends/native-temp.js +187 -0
- package/dist/backends/never-admission.js +90 -0
- package/dist/backends/run.js +67 -0
- package/dist/backends/stream.js +230 -0
- package/dist/backends/tool-discovery.js +15 -0
- package/dist/backends/types.js +264 -0
- package/dist/build-info.json +5 -0
- package/dist/cli.js +344 -0
- package/dist/confine/bridge.js +113 -0
- package/dist/confine/broker-core.js +76 -0
- package/dist/confine/broker-http.js +650 -0
- package/dist/confine/broker-names.js +9 -0
- package/dist/confine/broker.js +258 -0
- package/dist/confine/canary.js +380 -0
- package/dist/confine/diagnostics.js +122 -0
- package/dist/confine/gemini-tools-main.js +8 -0
- package/dist/confine/gemini-tools.js +181 -0
- package/dist/confine/hardlinks.js +58 -0
- package/dist/confine/harness-config.js +16 -0
- package/dist/confine/index.js +117 -0
- package/dist/confine/leases.js +217 -0
- package/dist/confine/paths.js +6 -0
- package/dist/confine/peer.js +115 -0
- package/dist/confine/port-policy.js +8 -0
- package/dist/confine/ports.js +365 -0
- package/dist/confine/private-root.js +208 -0
- package/dist/confine/probe-stage2.js +501 -0
- package/dist/confine/probe.js +1109 -0
- package/dist/confine/proxy.js +783 -0
- package/dist/confine/sbcheck.js +208 -0
- package/dist/confine/seatbelt-never.js +41 -0
- package/dist/confine/seatbelt-stage2.js +139 -0
- package/dist/confine/seatbelt.js +1129 -0
- package/dist/confine/sockets.js +36 -0
- package/dist/confine/turn-probe.js +19 -0
- package/dist/confine/turn.js +86 -0
- package/dist/core/adoption.js +124 -0
- package/dist/core/api-keys.js +423 -0
- package/dist/core/approvals.js +740 -0
- package/dist/core/build-identity.js +248 -0
- package/dist/core/caller.js +749 -0
- package/dist/core/calls.js +102 -0
- package/dist/core/claude-settings.js +1045 -0
- package/dist/core/config.js +453 -0
- package/dist/core/context.js +186 -0
- package/dist/core/db.js +753 -0
- package/dist/core/dispatch.js +110 -0
- package/dist/core/env-broker.js +505 -0
- package/dist/core/env-policy.js +182 -0
- package/dist/core/escalation-authority.js +76 -0
- package/dist/core/escalation-contract.js +13 -0
- package/dist/core/escalation-person-path.js +131 -0
- package/dist/core/escalation-policy.js +79 -0
- package/dist/core/escalation-runtime.js +135 -0
- package/dist/core/escalation-state.js +42 -0
- package/dist/core/escalations.js +191 -0
- package/dist/core/events.js +235 -0
- package/dist/core/executables.js +147 -0
- package/dist/core/extensions.js +645 -0
- package/dist/core/families.js +204 -0
- package/dist/core/git.js +657 -0
- package/dist/core/identity.js +113 -0
- package/dist/core/liveness.js +68 -0
- package/dist/core/mediated-network-provider.js +81 -0
- package/dist/core/never-checkpoint.js +76 -0
- package/dist/core/never-coverage.js +97 -0
- package/dist/core/never-network.js +49 -0
- package/dist/core/never-policy.js +302 -0
- package/dist/core/never-proxy-policy.js +109 -0
- package/dist/core/never-schema.js +61 -0
- package/dist/core/never-tools.js +56 -0
- package/dist/core/notices.js +48 -0
- package/dist/core/ops.js +959 -0
- package/dist/core/outcome.js +224 -0
- package/dist/core/params.js +32 -0
- package/dist/core/presence.js +174 -0
- package/dist/core/procs.js +546 -0
- package/dist/core/prompts.js +363 -0
- package/dist/core/protected-config.js +238 -0
- package/dist/core/raw-network.js +192 -0
- package/dist/core/redact.js +152 -0
- package/dist/core/refusal.js +33 -0
- package/dist/core/relay-command.js +310 -0
- package/dist/core/reported.js +3 -0
- package/dist/core/restart-overlay.js +651 -0
- package/dist/core/retention.js +1135 -0
- package/dist/core/secrets.js +329 -0
- package/dist/core/session-token.js +175 -0
- package/dist/core/session.js +744 -0
- package/dist/core/shell.js +2 -0
- package/dist/core/shipped-pin.js +47 -0
- package/dist/core/shown.js +42 -0
- package/dist/core/slots.js +67 -0
- package/dist/core/stage2-executors.js +453 -0
- package/dist/core/stage2-switch.js +5 -0
- package/dist/core/steering.js +149 -0
- package/dist/core/storage.js +358 -0
- package/dist/core/toml.js +175 -0
- package/dist/core/views.js +324 -0
- package/dist/core/wait.js +114 -0
- package/dist/core/wake.js +207 -0
- package/dist/core/watch.js +247 -0
- package/dist/core/worktree.js +213 -0
- package/dist/hosts/claude-desktop.js +274 -0
- package/dist/hosts/claude.js +249 -0
- package/dist/hosts/codex.js +345 -0
- package/dist/hosts/desktop-shared.js +20 -0
- package/dist/hosts/index.js +11 -0
- package/dist/hosts/types.js +4 -0
- package/dist/install/basics.js +18 -0
- package/dist/install/claude-init.js +133 -0
- package/dist/install/common.js +655 -0
- package/dist/install/doctor.js +635 -0
- package/dist/install/qualify-codex.js +205 -0
- package/dist/install.js +524 -0
- package/dist/mcp/elicit.js +209 -0
- package/dist/mcp/gateway.js +218 -0
- package/dist/mcp/host.js +253 -0
- package/dist/mcp/server.js +1124 -0
- package/dist/mcp/stdio.js +37 -0
- package/dist/modes/discussion.js +393 -0
- package/dist/modes/review.js +722 -0
- package/dist/native/relay-sbcheck +0 -0
- package/dist/targets/briefs.js +86 -0
- package/dist/targets/claude.js +94 -0
- package/dist/targets/codex.js +66 -0
- package/dist/targets/copilot.js +93 -0
- package/dist/targets/gemini.js +119 -0
- package/dist/targets/grok.js +126 -0
- package/dist/targets/index.js +192 -0
- package/dist/targets/types.js +18 -0
- package/dist/targets/verified.js +35 -0
- package/dist/worker.js +113 -0
- package/docs/UPGRADING.md +1518 -0
- package/docs/pinned-codex.md +333 -0
- package/experiments/stage2-redteam/lib/oracles.mjs +214 -0
- package/experiments/stage2-redteam/lib/report.mjs +35 -0
- package/npm-shrinkwrap.json +1632 -0
- package/package.json +82 -4
- package/scripts/codex-qualify/codex-pin-store.mjs +353 -0
- package/scripts/codex-qualify/codex-qualifier-process.mjs +265 -0
- package/scripts/codex-qualify/codex-qualifier.example.json +5 -0
- package/scripts/codex-qualify/codex-qualifier.mjs +281 -0
- package/scripts/codex-qualify/codex-shipped-pin.mjs +158 -0
- package/scripts/codex-qualify/codex-stage2-pin.mjs +48 -0
- package/scripts/codex-qualify/codex-stage2.mjs +2381 -0
- package/scripts/codex-qualify/install-codex-qualifier.mjs +98 -0
- package/scripts/codex-qualify/main-module.mjs +14 -0
- package/scripts/codex-qualify/relay-codex-qualifier.plist +37 -0
- package/scripts/codex-qualify/scratch-env.mjs +31 -0
- package/scripts/codex-qualify/session.mjs +96 -0
- package/scripts/codex-qualify/stage2-escalation-cases.mjs +125 -0
- package/test/codex-permissions.test.ts +875 -0
- package/test/fixtures/boundary-probes.mjs +17 -0
- package/test/fixtures/denial-stream-host.mjs +7 -0
- package/test/fixtures/families.json +246 -0
- package/test/fixtures/install-snapshots/claude-desktop-foreign.txt +158 -0
- package/test/fixtures/install-snapshots/claude-desktop-fresh.txt +101 -0
- package/test/fixtures/install-snapshots/claude-desktop-installed.txt +161 -0
- package/test/fixtures/install-snapshots/claude-foreign.txt +133 -0
- package/test/fixtures/install-snapshots/claude-fresh.txt +77 -0
- package/test/fixtures/install-snapshots/claude-installed.txt +133 -0
- package/test/fixtures/install-snapshots/codex-foreign.txt +159 -0
- package/test/fixtures/install-snapshots/codex-fresh.txt +107 -0
- package/test/fixtures/install-snapshots/codex-installed.txt +161 -0
- package/test/fixtures/link-parent.mjs +6 -0
- package/test/fixtures/mediated-command.cjs +72 -0
- package/test/fixtures/native-skill-isolation.json +280 -0
- package/test/fixtures/pinned-codex-app-server.mjs +25 -0
- package/test/fixtures/qualified-ext-adapters.mjs +36 -0
- package/test/fixtures/refusals/README.md +52 -0
- package/test/fixtures/refusals/claude-source-result.json +7 -0
- package/test/fixtures/refusals/openai-app-capacity.json +24 -0
- package/test/fixtures/refusals/openai-app-cyberPolicy.json +24 -0
- package/test/fixtures/refusals/openai-gpt-6-astra-max.json +12 -0
- package/test/fixtures/refusals/openai-gpt-6.1-sol-xhigh.json +12 -0
- package/test/fixtures/refusals/openai-review-capacity.json +24 -0
- package/test/fixtures/relay-0.2.0.sql +57 -0
- package/test/fixtures/relay-0.9.1.gen.mjs +212 -0
- package/test/fixtures/relay-0.9.1.sql +340 -0
- package/test/fixtures/slow-boundary-probes.mjs +37 -0
- package/test/fixtures/stable-surfaces/config.json +1122 -0
- package/test/fixtures/stable-surfaces/escalation.json +128 -0
- package/test/fixtures/stable-surfaces/events.json +37 -0
- package/test/fixtures/stable-surfaces/gemini-native-resume.json +4 -0
- package/test/fixtures/stable-surfaces/inbox.jsonl +2 -0
- package/test/fixtures/stable-surfaces/notice.txt +1 -0
- package/test/fixtures/stable-surfaces/refusal-item.json +28 -0
- package/test/fixtures/stable-surfaces/refusal-review.json +23 -0
- package/test/fixtures/stable-surfaces/registry.json +49 -0
- package/test/fixtures/stable-surfaces/tools-desktop.json +575 -0
- package/test/fixtures/stable-surfaces/tools.json +716 -0
- package/test/fixtures/stable-surfaces/usage.txt +46 -0
- package/test/fixtures/stage2-acp-native.mjs +138 -0
- package/test/fixtures/stage2-app-server.mjs +23 -0
- package/test/fixtures/stage2-catalog.json +91 -0
- package/test/fixtures/stage2-hostile-web.mjs +35 -0
- package/test/fixtures/stage2-native-network.mjs +62 -0
- package/test/fixtures/stage2-worker.ts +87 -0
- package/test/fixtures/status-views/expected.json +7825 -0
- package/test/fixtures/status-views/registries.json +1 -0
- package/test/fixtures/steering.json +209 -0
- package/test/helpers.ts +740 -0
- package/test/host-env.ts +7 -0
- package/test/keychain-decoy.ts +197 -0
- package/test/live-scope.ts +44 -0
- package/test/mediated-network.test.ts +192 -0
- package/test/mediated-proxy.test.ts +264 -0
- package/test/native-temp-alias.ts +10 -0
- package/test/never-policy.test.ts +629 -0
- package/test/never-tools.test.ts +136 -0
- package/test/process-home.ts +18 -0
- package/test/proxy.test.ts +531 -0
- package/test/restart-overlay-live.test.ts +85 -0
- package/test/restart-overlay-profile.test.ts +66 -0
- package/test/restart-overlay.test.ts +416 -0
- package/test/stable-surfaces.test.ts +249 -0
- package/test/stage2-escalation-live.test.ts +544 -0
- package/test/stage2-escalation-qualification.test.ts +170 -0
- package/test/stage2-escalation.test.ts +747 -0
- package/test/stage2-executor.test.ts +849 -0
- package/test/stage2-grant.test.ts +603 -0
- package/test/stage2-native-live.test.ts +647 -0
- package/test/stage2-network-decisions.test.ts +70 -0
- package/test/stage2-probe.test.ts +845 -0
- package/test/stage2-standing-live.test.ts +203 -0
- package/test/stubs/broker-host.mjs +59 -0
- package/test/stubs/broker-peer.mjs +20 -0
- package/test/stubs/confined-harness.mjs +91 -0
- package/test/stubs/ext-broken-server.mjs +2 -0
- package/test/stubs/ext-odd-server.mjs +21 -0
- package/test/stubs/ext-server.mjs +31 -0
- package/test/stubs/fake-host-cli.mjs +218 -0
- package/test/stubs/procargs.mjs +30 -0
- package/test/stubs/stub-acp +4 -0
- package/test/stubs/stub-agent.mjs +322 -0
- package/test/stubs/stub-claude +4 -0
- package/test/stubs/stub-codex +4 -0
- package/test/stubs/targets/acp.mjs +307 -0
- package/test/stubs/targets/claude.mjs +149 -0
- package/test/stubs/targets/codex.mjs +479 -0
- package/test/stubs/targets/gemini.mjs +604 -0
- package/test/temp-root.ts +11 -0
- package/test/wp4-adapters.test.ts +353 -0
- package/test/wp4-interlock.test.ts +136 -0
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
relay — delegation, consultation, discussion and review across families of coding agent
|
|
2
|
+
(targets: claude, codex, copilot (experimental), gemini, grok (experimental); hosts: claude, codex, claude-desktop)
|
|
3
|
+
|
|
4
|
+
relay mcp [--host <target>] [--desktop] [--context <file>]
|
|
5
|
+
run the stdio MCP server (hosts start this, as install
|
|
6
|
+
registers it): --host names the family of the host's
|
|
7
|
+
sessions, --desktop marks the Claude desktop app's shared entry
|
|
8
|
+
relay bridge <socket> a confined agent's MCP server: forwards stdio to its turn's socket
|
|
9
|
+
relay gemini-tools <dir> --list|<tool>
|
|
10
|
+
a confined Gemini agent's relay tools, through its tool discovery
|
|
11
|
+
relay tree [run_id] [--watch] jobs, threads, discussions and reviews as one tree
|
|
12
|
+
relay chat <discussion_id> tail a discussion; type a line to send it to both participants
|
|
13
|
+
[--say "message"] [--print] one-shot forms: inject a message / print the transcript and exit
|
|
14
|
+
relay approvals approval requests waiting for a decision
|
|
15
|
+
relay adopt <id> --to <fingerprint> explicitly authorize takeover by the connection named in status
|
|
16
|
+
relay approve <request_id> [--job] [note] let a launched agent do what it asked: needs an
|
|
17
|
+
interactive terminal and a one-time code you type back, and
|
|
18
|
+
refuses inside relay-launched process trees it can detect (not a
|
|
19
|
+
security boundary; see README). --job: for the rest of that job.
|
|
20
|
+
Not a request marked person_only, which only you can allow in your session
|
|
21
|
+
relay deny <request_id> [reason] refuse it (from anywhere)
|
|
22
|
+
relay cancel <id | run_id> cancel an item and everything under it, or a whole run
|
|
23
|
+
relay clean [run_id] remove finished runs' worktrees and merged relay/* branches
|
|
24
|
+
(all finished runs if no id; unmerged branches are kept),
|
|
25
|
+
relay's leftover temporary directories, and, if
|
|
26
|
+
keep_records_days is set, records of runs with no
|
|
27
|
+
activity for that many days
|
|
28
|
+
relay clean --forget <run_id> [--write]
|
|
29
|
+
forget a finished run kept because its repository is gone:
|
|
30
|
+
its records and relay's own files for it; prints what it
|
|
31
|
+
would do, and changes nothing without --write
|
|
32
|
+
relay install <claude|codex|claude-desktop> [--write] [--force] [--no-link]
|
|
33
|
+
register relay with a host; prints what it would do, and
|
|
34
|
+
changes nothing without --write
|
|
35
|
+
relay uninstall <claude|codex|claude-desktop> [--write] [--force] [--remove-link]
|
|
36
|
+
take relay's own entries out of a host again
|
|
37
|
+
relay doctor check this machine against what relay needs
|
|
38
|
+
relay qualify-codex [--version X.Y.Z] [--force]
|
|
39
|
+
qualify a Codex release and make it the pin relay runs
|
|
40
|
+
(relay refuses Codex without one), from your desktop
|
|
41
|
+
login; it takes about an hour and a half. Without
|
|
42
|
+
--version, npm's latest. A release that ships a pin needs
|
|
43
|
+
this only for other versions: install codex puts it in place
|
|
44
|
+
relay qualify-codex --shipped switch to this release's shipped pin from one qualified here
|
|
45
|
+
relay --version
|
|
46
|
+
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// A deterministic ACP-v1 agent for host qualification of relay's generic adapter. It has no
|
|
3
|
+
// provider, model or credentials: its prompt is a fixed probe plan, and every operation is made
|
|
4
|
+
// by this process inside relay's production ACP confinement.
|
|
5
|
+
import fs from "node:fs";
|
|
6
|
+
import net from "node:net";
|
|
7
|
+
import readline from "node:readline";
|
|
8
|
+
|
|
9
|
+
const send = (message) => process.stdout.write(JSON.stringify({ jsonrpc: "2.0", ...message }) + "\n");
|
|
10
|
+
let sessionId = "stage2-acp-native";
|
|
11
|
+
|
|
12
|
+
const errorCode = (error) => String(error?.code ?? error?.message ?? error);
|
|
13
|
+
const direct = (host, port, payload = "probe\n") => new Promise((resolve) => {
|
|
14
|
+
const socket = net.connect({ host, port });
|
|
15
|
+
let data = "", settled = false;
|
|
16
|
+
const done = (answer) => {
|
|
17
|
+
if (settled) return;
|
|
18
|
+
settled = true;
|
|
19
|
+
socket.destroy();
|
|
20
|
+
resolve(answer);
|
|
21
|
+
};
|
|
22
|
+
socket.setTimeout(3000, () => done({ ok: false, code: "ETIMEDOUT" }));
|
|
23
|
+
socket.once("connect", () => socket.write(payload));
|
|
24
|
+
socket.on("data", (chunk) => {
|
|
25
|
+
data += chunk;
|
|
26
|
+
if (data.includes("\n") || data.includes("ALLOWED")) done({ ok: true, data: data.slice(0, 120) });
|
|
27
|
+
});
|
|
28
|
+
socket.once("error", (error) => done({ ok: false, code: errorCode(error) }));
|
|
29
|
+
socket.once("close", () => done(data ? { ok: true, data: data.slice(0, 120) } : { ok: false, code: "ECONNCLOSED" }));
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
// ACP's network-off route gives the harness an authenticated HTTP proxy. Use CONNECT directly so
|
|
33
|
+
// the fixture neither prints the credential nor depends on a library's environment-proxy support.
|
|
34
|
+
const tunnel = (host, port, payload = "probe\n") => new Promise((resolve) => {
|
|
35
|
+
const raw = process.env.HTTPS_PROXY || process.env.https_proxy;
|
|
36
|
+
if (!raw) return resolve({ ok: false, code: "NO_PROXY" });
|
|
37
|
+
const proxy = new URL(raw);
|
|
38
|
+
const auth = Buffer.from(`${decodeURIComponent(proxy.username)}:${decodeURIComponent(proxy.password)}`).toString("base64");
|
|
39
|
+
const socket = net.connect({ host: proxy.hostname, port: Number(proxy.port) });
|
|
40
|
+
let data = "", established = false, settled = false;
|
|
41
|
+
const done = (answer) => {
|
|
42
|
+
if (settled) return;
|
|
43
|
+
settled = true;
|
|
44
|
+
socket.destroy();
|
|
45
|
+
resolve(answer);
|
|
46
|
+
};
|
|
47
|
+
socket.setTimeout(3000, () => done({ ok: false, code: "ETIMEDOUT" }));
|
|
48
|
+
socket.once("connect", () => socket.write(
|
|
49
|
+
`CONNECT ${host}:${port} HTTP/1.1\r\nHost: ${host}:${port}\r\nProxy-Authorization: Basic ${auth}\r\nConnection: close\r\n\r\n`,
|
|
50
|
+
));
|
|
51
|
+
socket.on("data", (chunk) => {
|
|
52
|
+
data += chunk;
|
|
53
|
+
if (!established) {
|
|
54
|
+
const end = data.indexOf("\r\n\r\n");
|
|
55
|
+
if (end < 0) return;
|
|
56
|
+
const head = data.slice(0, end);
|
|
57
|
+
data = data.slice(end + 4);
|
|
58
|
+
if (!/^HTTP\/1\.[01] 200\b/.test(head)) return done({ ok: false, code: /^HTTP\/1\.[01] (\d+)/.exec(head)?.[1] ?? "BAD_PROXY_REPLY" });
|
|
59
|
+
established = true;
|
|
60
|
+
socket.write(payload);
|
|
61
|
+
}
|
|
62
|
+
if (established && (data.includes("\n") || data.includes("ALLOWED"))) done({ ok: true, data: data.slice(0, 120) });
|
|
63
|
+
});
|
|
64
|
+
socket.once("error", (error) => done({ ok: false, code: errorCode(error) }));
|
|
65
|
+
socket.once("close", () => done(established && data ? { ok: true, data: data.slice(0, 120) } : { ok: false, code: established ? "ECONNCLOSED" : "NO_PROXY_REPLY" }));
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
const connectOnly = (host, port) => new Promise((resolve) => {
|
|
69
|
+
const socket = net.connect({ host, port });
|
|
70
|
+
const done = (answer) => { socket.destroy(); resolve(answer); };
|
|
71
|
+
socket.setTimeout(5000, () => done({ ok: false, code: "ETIMEDOUT" }));
|
|
72
|
+
socket.once("connect", () => done({ ok: true }));
|
|
73
|
+
socket.once("error", (error) => done({ ok: false, code: errorCode(error) }));
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
async function probe(plan) {
|
|
77
|
+
const evidence = { mode: plan.mode, files: {}, allowed: null, services: [] };
|
|
78
|
+
try { evidence.files.allowedRead = fs.readFileSync(plan.allowedFile, "utf8"); }
|
|
79
|
+
catch (error) { evidence.files.allowedRead = `ERROR:${errorCode(error)}`; }
|
|
80
|
+
try { evidence.files.forbiddenRead = fs.readFileSync(plan.forbiddenFile, "utf8"); }
|
|
81
|
+
catch (error) { evidence.files.forbiddenRead = `ERROR:${errorCode(error)}`; }
|
|
82
|
+
try { fs.writeFileSync(plan.forbiddenFile, "changed by ACP fixture\n"); evidence.files.forbiddenWrite = "WROTE"; }
|
|
83
|
+
catch (error) { evidence.files.forbiddenWrite = `ERROR:${errorCode(error)}`; }
|
|
84
|
+
try { fs.writeFileSync(plan.allowedWrite, "ACP_ALLOWED_WRITE\n"); evidence.files.allowedWrite = "WROTE"; }
|
|
85
|
+
catch (error) { evidence.files.allowedWrite = `ERROR:${errorCode(error)}`; }
|
|
86
|
+
|
|
87
|
+
if (plan.mode === "proxy") {
|
|
88
|
+
evidence.allowed = await tunnel(plan.allowedHost, 443, "ACP_PROXY_PING\n");
|
|
89
|
+
// The adapter's allowlist proxy is 443-only. Owned high-port direct attempts are safe canaries
|
|
90
|
+
// for its exact outer profile; built-in ports are never contacted directly.
|
|
91
|
+
for (const port of plan.neverPorts) evidence.services.push({ port, direct: await direct("127.0.0.1", port, "") });
|
|
92
|
+
} else {
|
|
93
|
+
// NETWORK_ON allows outbound IPv4 and denies all of this Mac's own addresses, whatever is
|
|
94
|
+
// listening and whenever it started (seatbelt.ts). So loopback is pinned as refused both for a
|
|
95
|
+
// listener older than the profile and for one opened after this ready marker, and the positive
|
|
96
|
+
// control is a connect-only dial to a public address that sends nothing. Built-in service
|
|
97
|
+
// ports are never contacted from this fixture.
|
|
98
|
+
evidence.publicControl = await connectOnly(plan.publicControlHost, plan.publicControlPort);
|
|
99
|
+
evidence.allowed = await direct("127.0.0.1", plan.allowedPort, "");
|
|
100
|
+
fs.writeFileSync(plan.readyFile, "ready\n");
|
|
101
|
+
let control;
|
|
102
|
+
for (const deadline = Date.now() + 60_000; Date.now() < deadline;) {
|
|
103
|
+
try { control = JSON.parse(fs.readFileSync(plan.goFile, "utf8")); break; }
|
|
104
|
+
catch (error) { if (error?.code !== "ENOENT") throw error; }
|
|
105
|
+
await new Promise(resolve => setTimeout(resolve, 25));
|
|
106
|
+
}
|
|
107
|
+
if (!Number.isInteger(control?.port)) throw new Error("parent did not supply the post-start loopback control port");
|
|
108
|
+
evidence.lateLoopback = { port: control.port, ...await direct("127.0.0.1", control.port, "ACP_LATE_LOOPBACK_PING\n") };
|
|
109
|
+
for (const port of plan.neverPorts) evidence.services.push({ port, direct: await direct("127.0.0.1", port, "") });
|
|
110
|
+
}
|
|
111
|
+
return evidence;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
const lines = readline.createInterface({ input: process.stdin });
|
|
115
|
+
lines.on("line", async (line) => {
|
|
116
|
+
let message;
|
|
117
|
+
try { message = JSON.parse(line); } catch { return; }
|
|
118
|
+
const params = message.params ?? {};
|
|
119
|
+
if (message.method === "initialize") {
|
|
120
|
+
send({ id: message.id, result: { protocolVersion: 1, agentCapabilities: { promptCapabilities: {}, mcpCapabilities: {} }, authMethods: [], agentInfo: { name: "stage2-scripted-acp", version: "1" } } });
|
|
121
|
+
} else if (message.method === "session/new") {
|
|
122
|
+
sessionId = "stage2-acp-native";
|
|
123
|
+
send({ id: message.id, result: { sessionId } });
|
|
124
|
+
} else if (message.method === "session/prompt") {
|
|
125
|
+
try {
|
|
126
|
+
const text = (params.prompt ?? []).map((part) => part?.text ?? "").join("");
|
|
127
|
+
const evidence = await probe(JSON.parse(text));
|
|
128
|
+
send({ method: "session/update", params: { sessionId, update: { sessionUpdate: "agent_message_chunk", content: { type: "text", text: JSON.stringify(evidence) } } } });
|
|
129
|
+
send({ id: message.id, result: { stopReason: "end_turn" } });
|
|
130
|
+
} catch (error) {
|
|
131
|
+
send({ id: message.id, error: { code: -32000, message: errorCode(error) } });
|
|
132
|
+
}
|
|
133
|
+
} else if (message.method === "session/cancel") {
|
|
134
|
+
send({ id: message.id, result: {} });
|
|
135
|
+
} else if (message.id !== undefined) {
|
|
136
|
+
send({ id: message.id, error: { code: -32601, message: `unsupported ${message.method}` } });
|
|
137
|
+
}
|
|
138
|
+
});
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// Model-free stdio app server for BB lifecycle unit tests. No listeners or child processes.
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import readline from "node:readline";
|
|
4
|
+
const send = (m) => process.stdout.write(JSON.stringify(m) + "\n");
|
|
5
|
+
const note = (method, params) => send({ method, params });
|
|
6
|
+
for await (const line of readline.createInterface({ input: process.stdin })) {
|
|
7
|
+
const m = JSON.parse(line);
|
|
8
|
+
if (m.id === undefined) continue;
|
|
9
|
+
fs.appendFileSync(process.env.BB_EVENTS, m.method + "\n");
|
|
10
|
+
let result = {};
|
|
11
|
+
if (m.method === "config/read") result = { config: JSON.parse(process.env.BB_CONFIG) };
|
|
12
|
+
if (m.method === "configRequirements/read") result = { requirements: null };
|
|
13
|
+
if (m.method === "thread/start" || m.method === "thread/resume") {
|
|
14
|
+
if (process.env.BB_SELF_START) note("turn/started", { threadId: "thread", turn: { id: "self" } });
|
|
15
|
+
result = { thread: { id: "thread" }, activePermissionProfile: { id: ":danger-full-access" }, sandbox: { type: "dangerFullAccess" } };
|
|
16
|
+
}
|
|
17
|
+
if (m.method === "turn/start") {
|
|
18
|
+
note("turn/started", { threadId: "thread", turn: { id: "turn" } });
|
|
19
|
+
result = { turn: { id: "turn" } };
|
|
20
|
+
}
|
|
21
|
+
if (m.method === "bb/complete") note("turn/completed", { threadId: "thread", turn: { id: "turn", status: "completed" } });
|
|
22
|
+
send({ id: m.id, result });
|
|
23
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
{
|
|
2
|
+
"models": [
|
|
3
|
+
{
|
|
4
|
+
"slug": "mock-model",
|
|
5
|
+
"display_name": "Mock",
|
|
6
|
+
"description": "Fake model for relay stage-2 tests",
|
|
7
|
+
"default_reasoning_level": "low",
|
|
8
|
+
"supported_reasoning_levels": [
|
|
9
|
+
{
|
|
10
|
+
"effort": "low",
|
|
11
|
+
"description": "Fast responses with lighter reasoning"
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
"effort": "medium",
|
|
15
|
+
"description": "Balances speed and reasoning depth for everyday tasks"
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
"effort": "high",
|
|
19
|
+
"description": "Greater reasoning depth for complex problems"
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
"effort": "xhigh",
|
|
23
|
+
"description": "Extra high reasoning depth for complex problems"
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
"effort": "max",
|
|
27
|
+
"description": "Maximum reasoning depth for the hardest problems"
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
"effort": "ultra",
|
|
31
|
+
"description": "Maximum reasoning with automatic task delegation"
|
|
32
|
+
}
|
|
33
|
+
],
|
|
34
|
+
"shell_type": "unified_exec",
|
|
35
|
+
"visibility": "list",
|
|
36
|
+
"supported_in_api": true,
|
|
37
|
+
"priority": 1,
|
|
38
|
+
"additional_speed_tiers": [
|
|
39
|
+
"fast"
|
|
40
|
+
],
|
|
41
|
+
"service_tiers": [
|
|
42
|
+
{
|
|
43
|
+
"id": "priority",
|
|
44
|
+
"name": "Fast",
|
|
45
|
+
"description": "2x speed, increased usage"
|
|
46
|
+
}
|
|
47
|
+
],
|
|
48
|
+
"available_access_programs": {
|
|
49
|
+
"cyber": [
|
|
50
|
+
"standard"
|
|
51
|
+
]
|
|
52
|
+
},
|
|
53
|
+
"upgrade": null,
|
|
54
|
+
"include_skills_usage_instructions": false,
|
|
55
|
+
"include_plugin_usage_instructions": false,
|
|
56
|
+
"include_apps_usage_instructions": false,
|
|
57
|
+
"default_reasoning_summary": "none",
|
|
58
|
+
"support_verbosity": true,
|
|
59
|
+
"default_verbosity": "low",
|
|
60
|
+
"apply_patch_tool_type": "freeform",
|
|
61
|
+
"web_search_tool_type": "text_and_image",
|
|
62
|
+
"truncation_policy": {
|
|
63
|
+
"mode": "tokens",
|
|
64
|
+
"limit": 10000
|
|
65
|
+
},
|
|
66
|
+
"supports_image_detail_original": true,
|
|
67
|
+
"context_window": 500000,
|
|
68
|
+
"max_context_window": 872000,
|
|
69
|
+
"comp_hash": "3000",
|
|
70
|
+
"effective_context_window_percent": 95,
|
|
71
|
+
"experimental_supported_tools": [
|
|
72
|
+
"send_user_message_async",
|
|
73
|
+
"clock"
|
|
74
|
+
],
|
|
75
|
+
"input_modalities": [
|
|
76
|
+
"text",
|
|
77
|
+
"image"
|
|
78
|
+
],
|
|
79
|
+
"supports_search_tool": true,
|
|
80
|
+
"supports_experimental_context": false,
|
|
81
|
+
"use_responses_lite": true,
|
|
82
|
+
"supports_reasoning_effort_updates": true,
|
|
83
|
+
"node_repl_auto_review_required": true,
|
|
84
|
+
"node_repl_disabled": false,
|
|
85
|
+
"tool_mode": "code_mode_only",
|
|
86
|
+
"multi_agent_version": "v2",
|
|
87
|
+
"multi_agent_reasoning_effort": "xhigh",
|
|
88
|
+
"base_instructions": "You are a fake model for relay tests."
|
|
89
|
+
}
|
|
90
|
+
]
|
|
91
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// Scripted model calls shared by the standing/resume and worker/overlay live harnesses.
|
|
2
|
+
// No call here talks to a real provider. The URL and model endpoint are owned decoys.
|
|
3
|
+
import assert from "node:assert/strict";
|
|
4
|
+
import { offeredTools } from "../../scripts/codex-qualify/codex-stage2.mjs";
|
|
5
|
+
|
|
6
|
+
export const codeCall = input => ({ type: "custom_tool_call", name: "exec", input });
|
|
7
|
+
export function modelStubRequestKind(req) {
|
|
8
|
+
if (req.method === "POST" && req.url === "/v1/responses") return "response";
|
|
9
|
+
if (req.method === "GET" && req.url === "/v1/responses"
|
|
10
|
+
&& typeof req.headers?.upgrade === "string" && req.headers.upgrade.trim().toLowerCase() === "websocket") return "websocket";
|
|
11
|
+
return "unexpected";
|
|
12
|
+
}
|
|
13
|
+
export function hostileWebCalls(surface, url) {
|
|
14
|
+
const attempts = [
|
|
15
|
+
{ name: "web_search", args: { query: url } },
|
|
16
|
+
{ namespace: "web", name: "run", args: { open: [{ ref_id: url }], open_page: [{ url }] } },
|
|
17
|
+
];
|
|
18
|
+
return attempts.map(({ namespace, name, args }) => surface === "code"
|
|
19
|
+
? codeCall(`try { const r = await tools[${JSON.stringify(namespace ? `${namespace}__${name}` : name)}](${JSON.stringify(args)}); text("HOSTILE_RETURNED:" + JSON.stringify(r)); } catch (e) { text("HOSTILE_REFUSED:" + String(e)); }`)
|
|
20
|
+
: { type: "function_call", ...(namespace ? { namespace } : {}), name, arguments: JSON.stringify(args) });
|
|
21
|
+
}
|
|
22
|
+
export function assertHostileWebEvidence(surface, bodies, outputs) {
|
|
23
|
+
assert.ok(bodies.length > 0, "real Codex reached the scripted model");
|
|
24
|
+
for (const body of bodies) {
|
|
25
|
+
const names = offeredTools(body);
|
|
26
|
+
assert.ok(names.length > 0, "Codex advertised its tools");
|
|
27
|
+
assert.equal(names.some(n => ["web", "web_search", "web__run"].includes(n)), false, `hosted web offered: ${names}`);
|
|
28
|
+
}
|
|
29
|
+
assert.equal(outputs.length, 2, "both hostile calls returned to the model");
|
|
30
|
+
for (const out of outputs) {
|
|
31
|
+
if (surface === "code") assert.match(out, /HOSTILE_REFUSED:/, out);
|
|
32
|
+
assert.match(out, /not found|unknown|unrecognized|unsupported|not available|disabled|not a function|undefined/i, out);
|
|
33
|
+
assert.doesNotMatch(out, /HOSTILE_RETURNED:/);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Fixed network probe used by the installed-Claude Bash route. Built-in service ports are sent
|
|
3
|
+
// only as CONNECT targets to relay's proxy. Direct connects are limited to owned high-port decoys.
|
|
4
|
+
import net from "node:net";
|
|
5
|
+
|
|
6
|
+
const plan = JSON.parse(process.argv[2]);
|
|
7
|
+
const errorCode = error => String(error?.code ?? error?.message ?? error);
|
|
8
|
+
|
|
9
|
+
const direct = (port) => new Promise(resolve => {
|
|
10
|
+
const socket = net.connect({ host: "127.0.0.1", port });
|
|
11
|
+
let settled = false;
|
|
12
|
+
const done = answer => { if (!settled) { settled = true; socket.destroy(); resolve(answer); } };
|
|
13
|
+
socket.setTimeout(3000, () => done({ ok: false, code: "ETIMEDOUT" }));
|
|
14
|
+
socket.once("connect", () => done({ ok: true }));
|
|
15
|
+
socket.once("error", error => done({ ok: false, code: errorCode(error) }));
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
const credentials = raw => {
|
|
19
|
+
const proxy = new URL(raw);
|
|
20
|
+
return { proxy, auth: Buffer.from(`${decodeURIComponent(proxy.username)}:${decodeURIComponent(proxy.password)}`).toString("base64") };
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
// Reach the owned qualification proxy only through Claude's production proxy: the outer CONNECT
|
|
24
|
+
// names a public carrier address whose final dial the test redirects to the owned proxy. The inner
|
|
25
|
+
// CONNECT is the built-in/user-never request whose exact reason the owned proxy records.
|
|
26
|
+
const nestedTunnel = (host, port, payload = "") => new Promise(resolve => {
|
|
27
|
+
const outerRaw = process.env.HTTPS_PROXY || process.env.https_proxy;
|
|
28
|
+
const innerRaw = process.env.STAGE2_CLAUDE_NESTED_PROXY;
|
|
29
|
+
if (!outerRaw || !innerRaw) return resolve({ ok: false, code: "NO_PROXY" });
|
|
30
|
+
const outer = credentials(outerRaw), inner = credentials(innerRaw);
|
|
31
|
+
const socket = net.connect({ host: outer.proxy.hostname, port: Number(outer.proxy.port) });
|
|
32
|
+
let data = "", stage = "outer", settled = false;
|
|
33
|
+
const done = answer => { if (!settled) { settled = true; socket.destroy(); resolve(answer); } };
|
|
34
|
+
socket.setTimeout(3000, () => done({ ok: false, code: "ETIMEDOUT" }));
|
|
35
|
+
socket.once("connect", () => socket.write(
|
|
36
|
+
`CONNECT ${plan.carrierHost}:${plan.carrierPort} HTTP/1.1\r\nHost: ${plan.carrierHost}:${plan.carrierPort}\r\nProxy-Authorization: Basic ${outer.auth}\r\n\r\n`,
|
|
37
|
+
));
|
|
38
|
+
socket.on("data", chunk => {
|
|
39
|
+
data += chunk;
|
|
40
|
+
for (;;) {
|
|
41
|
+
const end = data.indexOf("\r\n\r\n");
|
|
42
|
+
if (end < 0) break;
|
|
43
|
+
const head = data.slice(0, end); data = data.slice(end + 4);
|
|
44
|
+
if (!/^HTTP\/1\.[01] 200\b/.test(head)) return done({ ok: false, stage, code: /^HTTP\/1\.[01] (\d+)/.exec(head)?.[1] ?? "BAD_PROXY_REPLY" });
|
|
45
|
+
if (stage === "outer") {
|
|
46
|
+
stage = "inner";
|
|
47
|
+
socket.write(`CONNECT ${host}:${port} HTTP/1.1\r\nHost: ${host}:${port}\r\nProxy-Authorization: Basic ${inner.auth}\r\nConnection: close\r\n\r\n`);
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
50
|
+
stage = "payload";
|
|
51
|
+
if (payload) socket.write(payload); else return done({ ok: true });
|
|
52
|
+
}
|
|
53
|
+
if (stage === "payload" && (data.includes("\n") || data.includes("ALLOWED"))) done({ ok: true, data: data.slice(0, 120) });
|
|
54
|
+
});
|
|
55
|
+
socket.once("error", error => done({ ok: false, code: errorCode(error) }));
|
|
56
|
+
socket.once("close", () => done({ ok: false, stage, code: "ECONNCLOSED" }));
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
const evidence = { allowed: await nestedTunnel(plan.publicHost, plan.allowedPort, "CLAUDE_PROXY_PING\n"), services: [], neverPorts: [] };
|
|
60
|
+
for (const port of plan.servicePorts) evidence.services.push({ port, proxy: await nestedTunnel("127.0.0.1", port) });
|
|
61
|
+
for (const port of plan.neverPorts) evidence.neverPorts.push({ port, proxy: await nestedTunnel("127.0.0.1", port), direct: await direct(port) });
|
|
62
|
+
process.stdout.write(`STAGE2_NATIVE_NETWORK:${JSON.stringify(evidence)}\n`);
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
// Test-only stand-in for a relay worker running one stage-2 Codex turn (stage2-executor-live.test.ts):
|
|
2
|
+
// codexBackend.start with stage 2 on (config targets.codex.stage2), a fake Responses-API model on
|
|
3
|
+
// loopback, and every package as relay runs it (D's admission and checks, B's probes, A's lease),
|
|
4
|
+
// the lease on a scratch range (setLeaseOptionsForTests). The model's first tool call starts what a
|
|
5
|
+
// turn leaves behind (a setsid listener on the block's first port) and then blocks. Once those run,
|
|
6
|
+
// it prints one JSON line (pids and ports) and waits; the test then kills it or cancels its node.
|
|
7
|
+
// The model never answers after that (unless STAGE2_WORKER_ANSWER is set), so the turn stays in progress.
|
|
8
|
+
// SIGTERM is ignored, as by a worker stuck in teardown: cancel must then kill it.
|
|
9
|
+
// Usage: node stage2-worker.ts '<json: { codex, root, runId, nodeId, turnId (a running turn of the node), range: { first, count } }>'
|
|
10
|
+
import { spawnSync } from "node:child_process";
|
|
11
|
+
import fs from "node:fs";
|
|
12
|
+
import http from "node:http";
|
|
13
|
+
import net from "node:net";
|
|
14
|
+
import path from "node:path";
|
|
15
|
+
import { codexBackend } from "../../dist/backends/codex.js";
|
|
16
|
+
import { setCodexHomeConfigForTests } from "../../dist/backends/codex-pin.js";
|
|
17
|
+
import { setLeaseOptionsForTests } from "../../dist/backends/codex-env.js";
|
|
18
|
+
import { withTurnSecrets } from "../../dist/core/secrets.js";
|
|
19
|
+
import { withDefaults } from "../../dist/core/config.js";
|
|
20
|
+
import { updateNode } from "../../dist/core/db.js";
|
|
21
|
+
import { targetDef } from "../../dist/targets/index.js";
|
|
22
|
+
import type { TurnSpec } from "../../dist/backends/types.js";
|
|
23
|
+
|
|
24
|
+
const o = JSON.parse(process.argv[2]) as { codex: string; root: string; runId: string; nodeId: string; turnId: number; range: { first: number; count: number } };
|
|
25
|
+
process.on("SIGTERM", () => {});
|
|
26
|
+
|
|
27
|
+
const cwd = path.join(o.root, "w"), appHome = path.join(o.root, "apphome");
|
|
28
|
+
for (const d of [cwd, appHome]) fs.mkdirSync(d, { recursive: true });
|
|
29
|
+
// A git repository, as a real job's cwd is (Codex writes a new thread's rollout late there: stage2TurnReadback).
|
|
30
|
+
spawnSync("git", ["init", "-q", cwd], { stdio: "ignore", env: { PATH: "/usr/bin:/bin:/opt/homebrew/bin", HOME: process.env.HOME, GIT_CONFIG_NOSYSTEM: "1" } });
|
|
31
|
+
const usage = { input_tokens: 0, input_tokens_details: null, output_tokens: 0, output_tokens_details: null, total_tokens: 0 };
|
|
32
|
+
const sse = (evs: unknown[]) => evs.map((e) => `event: ${(e as { type: string }).type}\ndata: ${JSON.stringify(e)}\n\n`).join("");
|
|
33
|
+
const cmd = [
|
|
34
|
+
`/usr/bin/perl -MPOSIX -MIO::Socket::INET -e 'exit 0 if fork; POSIX::setsid(); my $s = IO::Socket::INET->new(LocalAddr => "127.0.0.1", LocalPort => $ENV{PORT}, Listen => 5, ReuseAddr => 1) or die; open(F, ">", "pid_listen"); print F $$; close F; while (my $c = $s->accept) { print $c "hi"; close $c }'`,
|
|
35
|
+
"/bin/sleep 4312",
|
|
36
|
+
].join("; ");
|
|
37
|
+
let asked = 0;
|
|
38
|
+
const server = http.createServer((q, s) => {
|
|
39
|
+
let b = "";
|
|
40
|
+
q.on("data", (d) => (b += d));
|
|
41
|
+
q.on("end", () => {
|
|
42
|
+
if (q.method !== "POST" || !q.url?.includes("/responses")) { s.writeHead(404); s.end("{}"); return; }
|
|
43
|
+
s.writeHead(200, { "content-type": "text/event-stream" });
|
|
44
|
+
if (asked++ === 0) {
|
|
45
|
+
const call = { type: "function_call", name: "exec_command", arguments: JSON.stringify({ cmd, login: false, timeout_ms: 600000, yield_time_ms: 600000 }) };
|
|
46
|
+
s.end(sse([{ type: "response.created", response: { id: "r1" } }, { type: "response.output_item.done", item: { ...call, call_id: "c1", id: "i1" } }, { type: "response.completed", response: { id: "r1", usage } }]));
|
|
47
|
+
} else if (process.env.STAGE2_WORKER_ANSWER) {
|
|
48
|
+
s.end(sse([{ type: "response.created", response: { id: "rz" } }, { type: "response.output_item.done", item: { type: "message", role: "assistant", id: "mz", content: [{ type: "output_text", text: "done" }] } }, { type: "response.completed", response: { id: "rz", usage } }]));
|
|
49
|
+
} else {
|
|
50
|
+
// The model thinks forever: the turn stays in progress until the test kills or cancels the worker.
|
|
51
|
+
s.write(sse([{ type: "response.created", response: { id: "rz" } }]));
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
await new Promise<void>((r) => server.listen(0, "127.0.0.1", () => r()));
|
|
56
|
+
const modelPort = (server.address() as net.AddressInfo).port;
|
|
57
|
+
fs.copyFileSync(path.join(import.meta.dirname, "stage2-catalog.json"), path.join(o.root, "catalog.json"));
|
|
58
|
+
fs.writeFileSync(path.join(appHome, "config.toml"), ['model = "mock-model"', `openai_base_url = "http://127.0.0.1:${modelPort}/v1"`, `model_catalog_json = ${JSON.stringify(path.join(o.root, "catalog.json"))}`, ""].join("\n"));
|
|
59
|
+
setCodexHomeConfigForTests((home) => home === appHome ? fs.readFileSync(path.join(appHome, "config.toml"), "utf8") : undefined);
|
|
60
|
+
fs.writeFileSync(path.join(appHome, "auth.json"), JSON.stringify({ OPENAI_API_KEY: "sk-relay-stage2-fake-model" }));
|
|
61
|
+
setLeaseOptionsForTests({ range: o.range });
|
|
62
|
+
const spec = {
|
|
63
|
+
target: targetDef("codex"), prompt: "go", cwd, dir: o.root, logPath: path.join(o.root, "agent.log"), access: "write", relay: null, turnId: o.turnId,
|
|
64
|
+
config: withDefaults({ codex_backend: "app-server", child_auth: "any", codex_endpoint_override: "accept", child_mcp: "relay-only", cancel_grace_ms: 2000, targets: { codex: { bin: o.codex, stage2: true, home: appHome, pinned: false } } }),
|
|
65
|
+
environment: { PATH: "/usr/bin:/bin:/usr/sbin:/sbin", HOME: process.env.HOME, CODEX_HOME: appHome, SHELL: "/bin/zsh" },
|
|
66
|
+
markers: { runId: o.runId, nodeId: o.nodeId, depth: 1 },
|
|
67
|
+
grant: { network: true, raw_network: true },
|
|
68
|
+
onApproval: async () => ({ decision: "deny" }),
|
|
69
|
+
} as unknown as TurnSpec;
|
|
70
|
+
await withTurnSecrets(async () => {
|
|
71
|
+
const handle = await codexBackend.start(spec);
|
|
72
|
+
// Publish before waiting for command pid files: a startup failure/timeout must let the parent
|
|
73
|
+
// reap the app server before its executor, even if the first info line never arrives.
|
|
74
|
+
updateNode(o.nodeId, { agent_pid: handle.pid, agent_pgid: handle.pgid, agent_start: handle.startedAt });
|
|
75
|
+
const pidIn = (name: string) => {
|
|
76
|
+
try { return Number(fs.readFileSync(path.join(cwd, name), "utf8").trim()) || 0; } catch { return 0; }
|
|
77
|
+
};
|
|
78
|
+
for (let i = 0; i < 600 && !pidIn("pid_listen"); i++) await new Promise((r) => setTimeout(r, 50));
|
|
79
|
+
// This worker's executor (its child): its port from argv, the job's block from its environment.
|
|
80
|
+
const executor = Number(spawnSync("/usr/bin/pgrep", ["-P", String(process.pid), "-f", "exec-server --listen ws://127.0.0.1:"], { encoding: "utf8" }).stdout.trim().split("\n")[0] || 0);
|
|
81
|
+
const ps = executor ? spawnSync("/bin/ps", ["eww", "-o", "command=", "-p", String(executor)], { encoding: "utf8" }).stdout : "";
|
|
82
|
+
const l = { exec: Number(/--listen ws:\/\/127\.0\.0\.1:(\d+) /.exec(ps)?.[1] ?? 0), block: (/PORTS=([\d,]+)/.exec(ps)?.[1] ?? "").split(",").filter(Boolean).map(Number) };
|
|
83
|
+
const sleeper = Number(spawnSync("/usr/bin/pgrep", ["-f", "^/bin/sleep 4312$"], { encoding: "utf8" }).stdout.trim().split("\n")[0] || 0);
|
|
84
|
+
process.stdout.write(`${JSON.stringify({ app: handle.pid, appPgid: handle.pgid, appStart: handle.startedAt, executor, exec: l.exec, block: l.block, listen: pidIn("pid_listen"), sleeper })}\n`);
|
|
85
|
+
await handle.done;
|
|
86
|
+
process.stdout.write(`${JSON.stringify({ done: true })}\n`);
|
|
87
|
+
});
|