@jbkjr/relay 0.0.0-stage → 1.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/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 +386 -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 +1525 -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 +320 -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 +637 -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 +329 -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 +629 -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 +1502 -0
- package/docs/pinned-codex.md +321 -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,98 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Dry run by default. Writes a LaunchAgent only with --install; never loads/bootstraps it.
|
|
3
|
+
import fs from "node:fs";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import os from "node:os";
|
|
6
|
+
import { pathToFileURL } from "node:url";
|
|
7
|
+
import { atomicJson } from "./codex-pin-store.mjs";
|
|
8
|
+
import { validateConfig } from "./codex-qualifier.mjs";
|
|
9
|
+
import { isMain } from "./main-module.mjs";
|
|
10
|
+
|
|
11
|
+
const xml = (text) => String(text).replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">").replaceAll('"', """).replaceAll("'", "'");
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* A launchd label: dot-separated words of letters, digits and hyphens, at least two of them. It
|
|
15
|
+
* names the plist file too, so it can hold no slash, no `..` and nothing to escape.
|
|
16
|
+
*/
|
|
17
|
+
const LABEL = /^[A-Za-z0-9](?:[A-Za-z0-9-]*[A-Za-z0-9])?(?:\.[A-Za-z0-9](?:[A-Za-z0-9-]*[A-Za-z0-9])?)+$/;
|
|
18
|
+
|
|
19
|
+
/** The default label, from this user's login name: local.<user>.relay-codex-qualifier. */
|
|
20
|
+
export function defaultLabel(user = os.userInfo().username) {
|
|
21
|
+
const word = String(user).toLowerCase().replace(/[^a-z0-9-]+/g, "-").replace(/^-+|-+$/g, "") || "user";
|
|
22
|
+
return `local.${word}.relay-codex-qualifier`;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function validLabel(label) {
|
|
26
|
+
if (typeof label !== "string" || label.length > 200 || !LABEL.test(label)) throw new Error("--label must be a launchd label: dot-separated words of letters, digits and hyphens, such as local.you.relay-codex-qualifier");
|
|
27
|
+
return label;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function renderPlist({ node, runner, config, repo, logs, label = defaultLabel() }, template = fs.readFileSync(path.join(import.meta.dirname, "relay-codex-qualifier.plist"), "utf8")) {
|
|
31
|
+
template = template.replaceAll("__LABEL__", validLabel(label));
|
|
32
|
+
const values = { NODE_ABSOLUTE_PATH: node, RUNNER_ABSOLUTE_PATH: runner, CONFIG_ABSOLUTE_PATH: config, REPO_ABSOLUTE_PATH: repo, LOG_DIRECTORY: logs, NODE_BIN_DIRECTORY: path.dirname(node) };
|
|
33
|
+
for (const [name, value] of Object.entries(values)) {
|
|
34
|
+
if (!path.isAbsolute(value ?? "") || /[\0\r\n]/.test(value)) throw new Error(`${name} must be an absolute single-line path`);
|
|
35
|
+
if (name === "NODE_ABSOLUTE_PATH" && value.includes("fnm_multishells")) throw new Error("Node must use a stable installation path");
|
|
36
|
+
template = template.replaceAll(`__${name}__`, xml(value));
|
|
37
|
+
}
|
|
38
|
+
if (/__[A-Z_]+__/.test(template)) throw new Error("unresolved plist placeholder");
|
|
39
|
+
return template;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Whether `text` is a qualifier LaunchAgent: its program runs a relay checkout's codex-qualifier.mjs
|
|
44
|
+
* (scripts/codex-qualify, or scripts/release-watch before the move) with a config and --run.
|
|
45
|
+
*/
|
|
46
|
+
export function isQualifierAgent(text) {
|
|
47
|
+
return /<string>[^<]*\/scripts\/(?:codex-qualify|release-watch)\/codex-qualifier\.mjs<\/string>\s*<string>[^<]*<\/string>\s*<string>--run<\/string>/.test(String(text));
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function installQualifier({ config, node = process.execPath, home = os.homedir(), logs, label = defaultLabel(), install = false }) {
|
|
51
|
+
validLabel(label);
|
|
52
|
+
if (!path.isAbsolute(config ?? "")) throw new Error("--config must be absolute");
|
|
53
|
+
const cfg = validateConfig(JSON.parse(fs.readFileSync(config, "utf8")));
|
|
54
|
+
if (!path.isAbsolute(node)) throw new Error("--node must be absolute");
|
|
55
|
+
// Resolve a transient fnm shell link to the installed Node version. Homebrew's Cellar is stable
|
|
56
|
+
// too, but after removing an old Node version, rerun this installer.
|
|
57
|
+
node = fs.realpathSync(node);
|
|
58
|
+
fs.accessSync(node, fs.constants.X_OK);
|
|
59
|
+
const runner = path.join(cfg.repo, "scripts/codex-qualify/codex-qualifier.mjs");
|
|
60
|
+
fs.accessSync(runner, fs.constants.R_OK);
|
|
61
|
+
logs ??= path.join(home, "Library/Logs/relay-codex-qualifier");
|
|
62
|
+
const content = renderPlist({ node, runner, config, repo: cfg.repo, logs, label });
|
|
63
|
+
const plist = path.join(home, "Library/LaunchAgents", `${label}.plist`);
|
|
64
|
+
// A label is the person's to choose, so it can name another agent's file: replace only a qualifier agent.
|
|
65
|
+
let existing = null;
|
|
66
|
+
try { existing = fs.lstatSync(plist); } catch (e) { if (e.code !== "ENOENT") throw e; }
|
|
67
|
+
if (existing && (!existing.isFile() || !isQualifierAgent(fs.readFileSync(plist, "utf8")))) {
|
|
68
|
+
throw new Error(`${plist} exists and is not a relay Codex qualifier agent; the installer will not replace it. Choose another --label.`);
|
|
69
|
+
}
|
|
70
|
+
if (install) {
|
|
71
|
+
process.umask(0o077);
|
|
72
|
+
for (const dir of [cfg.store, logs, path.dirname(plist)]) fs.mkdirSync(dir, { recursive: true, mode: 0o700 });
|
|
73
|
+
// Rewrite only to persist validated defaults; this file must never contain credentials.
|
|
74
|
+
atomicJson(config, cfg);
|
|
75
|
+
const temp = `${plist}.${process.pid}.tmp`;
|
|
76
|
+
try { fs.writeFileSync(temp, content, { flag: "wx", mode: 0o600 }); fs.renameSync(temp, plist); }
|
|
77
|
+
finally { fs.rmSync(temp, { force: true }); }
|
|
78
|
+
}
|
|
79
|
+
return { plist, content, installed: install, node, label };
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
if (isMain(import.meta.url)) {
|
|
83
|
+
try {
|
|
84
|
+
const options = {};
|
|
85
|
+
const args = process.argv.slice(2);
|
|
86
|
+
for (let i = 0; i < args.length; i++) {
|
|
87
|
+
const flag = args[i];
|
|
88
|
+
if (flag === "--install") options.install = true;
|
|
89
|
+
else if (["--config", "--node", "--logs", "--label"].includes(flag) && args[i + 1] && !args[i + 1].startsWith("--")) options[flag.slice(2)] = args[++i];
|
|
90
|
+
else throw new Error("Usage: node install-codex-qualifier.mjs --config /absolute/qualifier.json [--node /stable/node] [--logs /absolute/logs] [--label local.you.relay-codex-qualifier] [--install]");
|
|
91
|
+
}
|
|
92
|
+
const result = installQualifier(options);
|
|
93
|
+
console.log(result.content);
|
|
94
|
+
console.log(`${result.installed ? "Installed" : "Dry run; would install"}: ${result.plist}`);
|
|
95
|
+
const domain = `gui/${process.getuid?.() ?? "$(id -u)"}`;
|
|
96
|
+
console.log(`Node: ${result.node}\nNot loaded. After reviewing the configuration, load it in your login session with:\n launchctl bootstrap ${domain} ${JSON.stringify(result.plist)}\nand stop it with:\n launchctl bootout ${domain}/${result.label}`);
|
|
97
|
+
} catch (e) { console.error(e.message); process.exitCode = 1; }
|
|
98
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// Whether a script module is the one node was started with.
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import { pathToFileURL } from "node:url";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* True when `metaUrl` (the caller's import.meta.url) is the script node was started with, by any
|
|
7
|
+
* path. Node gives import.meta.url as the file's real path, so argv[1] is compared by its realpath:
|
|
8
|
+
* started through a symlinked path (macOS's /tmp included), a plain comparison is false and the
|
|
9
|
+
* script exits 0 having done nothing; `file://${argv[1]}` also misses a path with a space.
|
|
10
|
+
*/
|
|
11
|
+
export function isMain(metaUrl, argv1 = process.argv[1]) {
|
|
12
|
+
if (!argv1) return false;
|
|
13
|
+
try { return metaUrl === pathToFileURL(fs.realpathSync(argv1)).href; } catch { return false; }
|
|
14
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
3
|
+
<plist version="1.0">
|
|
4
|
+
<dict>
|
|
5
|
+
<key>Label</key><string>__LABEL__</string>
|
|
6
|
+
<key>ProgramArguments</key>
|
|
7
|
+
<array>
|
|
8
|
+
<string>__NODE_ABSOLUTE_PATH__</string>
|
|
9
|
+
<string>__RUNNER_ABSOLUTE_PATH__</string>
|
|
10
|
+
<string>__CONFIG_ABSOLUTE_PATH__</string>
|
|
11
|
+
<string>--run</string>
|
|
12
|
+
</array>
|
|
13
|
+
<key>WorkingDirectory</key><string>__REPO_ABSOLUTE_PATH__</string>
|
|
14
|
+
<key>LimitLoadToSessionType</key><string>Aqua</string>
|
|
15
|
+
<!-- Standard, not Background: Background clamps the run and every descendant to the background
|
|
16
|
+
QoS band (priority 4, efficiency cores, throttled I/O). On a laptop with two efficiency
|
|
17
|
+
cores and a busy desktop, the watchdog's ps then took 5-30 s and failed qualifications. -->
|
|
18
|
+
<key>ProcessType</key><string>Standard</string>
|
|
19
|
+
<key>StartCalendarInterval</key>
|
|
20
|
+
<array>
|
|
21
|
+
<dict><key>Hour</key><integer>2</integer><key>Minute</key><integer>15</integer></dict>
|
|
22
|
+
<dict><key>Hour</key><integer>6</integer><key>Minute</key><integer>15</integer></dict>
|
|
23
|
+
<dict><key>Hour</key><integer>10</integer><key>Minute</key><integer>15</integer></dict>
|
|
24
|
+
<dict><key>Hour</key><integer>14</integer><key>Minute</key><integer>15</integer></dict>
|
|
25
|
+
<dict><key>Hour</key><integer>18</integer><key>Minute</key><integer>15</integer></dict>
|
|
26
|
+
<dict><key>Hour</key><integer>22</integer><key>Minute</key><integer>15</integer></dict>
|
|
27
|
+
</array>
|
|
28
|
+
<key>RunAtLoad</key><true/>
|
|
29
|
+
<key>KeepAlive</key><false/>
|
|
30
|
+
<key>ExitTimeOut</key><integer>120</integer>
|
|
31
|
+
<key>Umask</key><integer>63</integer>
|
|
32
|
+
<key>EnvironmentVariables</key>
|
|
33
|
+
<dict><key>PATH</key><string>__NODE_BIN_DIRECTORY__:/opt/homebrew/bin:/usr/bin:/bin:/usr/sbin:/sbin</string></dict>
|
|
34
|
+
<key>StandardOutPath</key><string>__LOG_DIRECTORY__/stdout.log</string>
|
|
35
|
+
<key>StandardErrorPath</key><string>__LOG_DIRECTORY__/stderr.log</string>
|
|
36
|
+
</dict>
|
|
37
|
+
</plist>
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// Child processes in the model-free qualifier never inherit a person's home or credentials.
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
|
|
5
|
+
export const SYSTEM_PATH = `${path.dirname(process.execPath)}:/opt/homebrew/bin:/usr/bin:/bin:/usr/sbin:/sbin`;
|
|
6
|
+
|
|
7
|
+
/** Construct, and validate even overridden paths against, this run's scratch root. */
|
|
8
|
+
export function scratchEnv(root, extra = {}) {
|
|
9
|
+
if (!root || !path.isAbsolute(root)) throw new Error("an absolute scratch root is required");
|
|
10
|
+
root = fs.realpathSync(root);
|
|
11
|
+
const env = {
|
|
12
|
+
PATH: SYSTEM_PATH, HOME: path.join(root, "home"), CODEX_HOME: path.join(root, "codex-home"),
|
|
13
|
+
TMPDIR: path.join(root, "tmp"), RELAY_HOME: path.join(root, "relay-home"),
|
|
14
|
+
RELAY_CONFIG: path.join(root, "relay-config.json"), ...extra,
|
|
15
|
+
};
|
|
16
|
+
for (const key of ["HOME", "CODEX_HOME", "TMPDIR", "RELAY_HOME"]) {
|
|
17
|
+
const value = env[key];
|
|
18
|
+
if (typeof value !== "string" || !path.isAbsolute(value)) throw new Error(`${key} must be an absolute scratch path`);
|
|
19
|
+
// Check existing ancestors too: a symlink must not redirect scratch state outside the run.
|
|
20
|
+
let ancestor = path.resolve(value);
|
|
21
|
+
while (!fs.existsSync(ancestor)) {
|
|
22
|
+
const parent = path.dirname(ancestor);
|
|
23
|
+
if (parent === ancestor) throw new Error(`${key} has no existing ancestor`);
|
|
24
|
+
ancestor = parent;
|
|
25
|
+
}
|
|
26
|
+
const inside = (p) => p === root || p.startsWith(`${root}${path.sep}`);
|
|
27
|
+
if (!inside(path.resolve(value)) || !inside(fs.realpathSync(ancestor))) throw new Error(`${key} escapes scratch root`);
|
|
28
|
+
fs.mkdirSync(value, { recursive: true, mode: 0o700 });
|
|
29
|
+
}
|
|
30
|
+
return env;
|
|
31
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
// Whether this process has no login session, in which relay's own sandbox cannot show that it
|
|
2
|
+
// refuses Apple Events, so that relay refuses every harness it confines itself. Under a launchd
|
|
3
|
+
// daemon (no Aqua session) that is the case; under a desktop login it is not. The stage-2 driver
|
|
4
|
+
// (codex-stage2.mjs) asks this so that what the gap stops is reported as "not run: no login
|
|
5
|
+
// session", and nothing else is. It is decided from relay's own probes run unchanged.
|
|
6
|
+
// The release watcher's lane logic built on it lives in scripts/release-watch/lanes.mjs.
|
|
7
|
+
import { spawnSync } from "node:child_process";
|
|
8
|
+
import fs from "node:fs";
|
|
9
|
+
import path from "node:path";
|
|
10
|
+
|
|
11
|
+
/** Runs a command without a shell: { ok, status, stdout, stderr }, never throwing. */
|
|
12
|
+
function tryRun(cmd, args, opts = {}) {
|
|
13
|
+
const r = spawnSync(cmd, args, { encoding: "utf8", maxBuffer: 64 << 20, ...opts });
|
|
14
|
+
return { ok: !r.error && r.status === 0, status: r.status, stdout: r.stdout ?? "", stderr: r.stderr ?? (r.error?.message ?? "") };
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** What relay says when its apple-events probe fails for want of a login session: osascript cannot get its sandbox extensions. */
|
|
18
|
+
export const NO_SESSION_REFUSAL = /boundary probe apple-events was not shown to be refused by the sandbox \(exit [1-9]\d*: sandbox_extension_issue_file failed/;
|
|
19
|
+
/**
|
|
20
|
+
* The same failure as a test sees it: relay's refusal above; the probe's own result, osascript
|
|
21
|
+
* failing to get a sandbox extension for its preferences (test/probe.test.ts reads it directly); or
|
|
22
|
+
* relay naming the apple-events probe as the one that refused where a test expected another (the
|
|
23
|
+
* first probe to fail is that one here), as an equality diff or as the stage-2 negative controls'
|
|
24
|
+
* own message ("<rule>: refused on apple-events", test/stage2-probe.test.ts).
|
|
25
|
+
*/
|
|
26
|
+
export const NO_SESSION_EVIDENCE = new RegExp(`${NO_SESSION_REFUSAL.source}|exit [1-9]\\d*: sandbox_extension_issue_file failed for \\S*/Library/Preferences/com\\.apple\\.osascript\\.plist|\\+ 'apple-events'\\s+- '[\\w-]+'|: refused on apple-events(?![\\w-])`);
|
|
27
|
+
|
|
28
|
+
/** The launchd session this process runs in: "Aqua" in a login session, "System" under a LaunchDaemon, "Background" or another. */
|
|
29
|
+
export function sessionManager() {
|
|
30
|
+
const r = tryRun("launchctl", ["managername"]);
|
|
31
|
+
return r.ok ? r.stdout.trim() : null;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Whether relay-enforced confinement launches here, as relay itself decides it before a launch:
|
|
36
|
+
* relay's `prepareLaunch` (dist/confine/index.js, unchanged) with its boundary probes, for a read
|
|
37
|
+
* turn of a scratch harness script in a scratch tree, in a child process whose HOME and RELAY_HOME are
|
|
38
|
+
* scratch too. Nothing is launched. Returns { ok } or { ok: false, check, message }.
|
|
39
|
+
*/
|
|
40
|
+
export function confinedLaunch(checkout) {
|
|
41
|
+
// Short paths under /tmp: the probes listen on Unix sockets, whose paths must stay under 104 bytes.
|
|
42
|
+
const root = fs.realpathSync(fs.mkdtempSync("/tmp/rwc-"));
|
|
43
|
+
try {
|
|
44
|
+
const tmp = path.join(root, "t");
|
|
45
|
+
fs.mkdirSync(tmp);
|
|
46
|
+
const r = tryRun(process.execPath, ["--input-type=module", "-e", CHILD, path.join(checkout, "dist", "confine", "index.js"), root], {
|
|
47
|
+
env: { PATH: process.env.PATH, HOME: path.join(root, "home"), RELAY_HOME: path.join(root, "control"), TMPDIR: tmp }, timeout: 120_000,
|
|
48
|
+
});
|
|
49
|
+
try { return JSON.parse(r.stdout.trim().split("\n").at(-1)); } catch { return { ok: false, check: "none", message: `relay's confinement check gave no answer (exit ${r.status}): ${r.stderr.slice(-300)}` }; }
|
|
50
|
+
} finally {
|
|
51
|
+
fs.rmSync(root, { recursive: true, force: true });
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const CHILD = `
|
|
56
|
+
import fs from "node:fs";
|
|
57
|
+
import path from "node:path";
|
|
58
|
+
|
|
59
|
+
/** Runs a command without a shell: { ok, status, stdout, stderr }, never throwing. */
|
|
60
|
+
function tryRun(cmd, args, opts = {}) {
|
|
61
|
+
const r = spawnSync(cmd, args, { encoding: "utf8", maxBuffer: 64 << 20, ...opts });
|
|
62
|
+
return { ok: !r.error && r.status === 0, status: r.status, stdout: r.stdout ?? "", stderr: r.stderr ?? (r.error?.message ?? "") };
|
|
63
|
+
}
|
|
64
|
+
const [indexJs, root] = process.argv.slice(1);
|
|
65
|
+
const { confinement, prepareLaunch } = await import(indexJs);
|
|
66
|
+
const wt = path.join(root, "wt"), tmp = path.join(root, "tmp"), control = path.join(root, "control"), home = path.join(root, "home"), bin = path.join(root, "bin");
|
|
67
|
+
for (const d of [wt, tmp, control, home, bin]) fs.mkdirSync(d, { recursive: true });
|
|
68
|
+
fs.writeFileSync(path.join(wt, ".git"), "gitdir: /nowhere\\n");
|
|
69
|
+
const harness = path.join(bin, "harness");
|
|
70
|
+
fs.writeFileSync(harness, "#!/bin/sh\\nexit 0\\n", { mode: 0o755 });
|
|
71
|
+
const found = confinement();
|
|
72
|
+
if (!found.mechanism) { console.log(JSON.stringify({ ok: false, check: "mechanism", message: found.reason })); process.exit(0); }
|
|
73
|
+
try {
|
|
74
|
+
await prepareLaunch(found.mechanism, { worktree: wt, worktreeWritable: false, tmpDir: tmp, denied: [control], network: { mode: "off-except-proxy", proxyPort: 9, proxyToken: "p".repeat(32) } }, harness, []);
|
|
75
|
+
console.log(JSON.stringify({ ok: true }));
|
|
76
|
+
} catch (err) {
|
|
77
|
+
console.log(JSON.stringify({ ok: false, check: err.check ?? "error", message: String(err.message).slice(0, 600) }));
|
|
78
|
+
}
|
|
79
|
+
`;
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Whether this process has the gap: no login session (launchctl), and relay's own apple-events probe
|
|
83
|
+
* refused for want of one (NO_SESSION_REFUSAL). Both must hold; anything else is not this gap.
|
|
84
|
+
*/
|
|
85
|
+
export function noLoginSession(checkout) {
|
|
86
|
+
const manager = sessionManager();
|
|
87
|
+
if (manager === "Aqua") return { gap: false, manager, why: "a login session (launchctl managername: Aqua)" };
|
|
88
|
+
const probe = confinedLaunch(checkout);
|
|
89
|
+
const gap = !probe.ok && probe.check === "apple-events" && NO_SESSION_REFUSAL.test(probe.message);
|
|
90
|
+
return {
|
|
91
|
+
gap, manager, probe,
|
|
92
|
+
why: gap
|
|
93
|
+
? `launchctl managername: ${manager}, and relay's own boundary probe refuses for want of one: ${probe.message.slice(0, 300)}`
|
|
94
|
+
: `launchctl managername: ${manager}; relay's confinement check: ${probe.ok ? "launches" : `${probe.check}: ${probe.message.slice(0, 300)}`}`,
|
|
95
|
+
};
|
|
96
|
+
}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
// WP6 shares these suites between release qualification and the red-team runner.
|
|
2
|
+
// Existing Node tests are the probes; no second lifecycle/proxy implementation lives here.
|
|
3
|
+
import fs from "node:fs";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import { spawn } from "node:child_process";
|
|
6
|
+
|
|
7
|
+
export const ESCALATION_CASES = {
|
|
8
|
+
23: { name: "out-of-profile hosted/open-page and extension screening, distinguishing exact model websocket upgrades", parts: {
|
|
9
|
+
unit: { files: ["never-tools", "stage2-escalation-qualification"], min: 10 },
|
|
10
|
+
surfaces: { files: ["stable-surfaces"], pattern: "registered MCP tools", min: 1 },
|
|
11
|
+
freshResume: { files: ["stage2-standing-live"], pattern: "^hostile web live:", min: 2, host: true, timeoutMs: 500_000, env: { RELAY_TEST_STANDING_LIVE: "1" } },
|
|
12
|
+
overlay: { files: ["stage2-escalation-live"], pattern: "live worker:.*hostile-(direct|code) result", min: 2, host: true, timeoutMs: 400_000, env: { RELAY_TEST_STAGE2_LIVE: "1" } },
|
|
13
|
+
} },
|
|
14
|
+
24: { name: "restart receipt, first call, replay, cancellation and handoff loss", parts: {
|
|
15
|
+
unit: { files: ["stage2-escalation"], min: 40 },
|
|
16
|
+
worker: { files: ["stage2-escalation-live"], pattern: "live worker:.*port0 result", min: 1, host: true, env: { RELAY_TEST_STAGE2_LIVE: "1" } },
|
|
17
|
+
cancel: { files: ["stage2-escalation-live"], pattern: "live worker:.*cancel result", min: 1, host: true, env: { RELAY_TEST_STAGE2_LIVE: "1" } },
|
|
18
|
+
http: { files: ["stage2-escalation-live"], pattern: "^WP3 live HTTP", min: 1, host: true, env: { RELAY_TEST_ESCALATION_HTTP: "1" } },
|
|
19
|
+
code: { files: ["stage2-escalation-live"], pattern: "live worker:.*(port0-code|cancel-code) result", min: 2, host: true, timeoutMs: 400_000, env: { RELAY_TEST_STAGE2_LIVE: "1" } },
|
|
20
|
+
mismatch: { files: ["stage2-escalation-live"], pattern: "live worker:.*(identity|readback)-mismatch result", min: 2, host: true, timeoutMs: 400_000, env: { RELAY_TEST_STAGE2_LIVE: "1" } },
|
|
21
|
+
} },
|
|
22
|
+
25: { name: "authenticated authority adversaries and consume isolation", parts: {
|
|
23
|
+
unit: { files: ["stage2-escalation", "restart-overlay"], min: 70 },
|
|
24
|
+
} },
|
|
25
|
+
26: { name: "finite deadline, worker-death/reap and monotonic floor races", parts: {
|
|
26
|
+
unit: { files: ["restart-overlay", "never-policy"], skipPattern: "grant admission rechecks kept|stale native temp alias repair|X1 never refusals preserve", min: 40 },
|
|
27
|
+
hostRoots: { files: ["never-policy"], pattern: "^grant admission rechecks kept|^stale native temp alias repair|^X1 never refusals preserve", min: 3, host: true },
|
|
28
|
+
crash: { files: ["stage2-escalation-live"], pattern: "live worker:.*mediated-crash result", min: 1, host: true, timeoutMs: 300_000, env: { RELAY_TEST_MEDIATED_LIVE: "1" } },
|
|
29
|
+
} },
|
|
30
|
+
27: { name: "overlay decoy profiles, exact listen, outside roots and raw-host refusal", parts: {
|
|
31
|
+
unit: { files: ["restart-overlay-profile", "restart-overlay"], min: 35 },
|
|
32
|
+
planner: { files: ["stage2-probe"], pattern: "^stage-2 overlay expectation|^stage-2 overlay probe plan:|^stage-2 decoy network:", min: 3 },
|
|
33
|
+
kernel: { files: ["stage2-probe"], pattern: "^stage-2 overlay live controls:", min: 1, host: true },
|
|
34
|
+
profiles: { files: ["stage2-escalation-live"], pattern: "live worker:.*(port0|listen|connect|write) result", min: 4, host: true, timeoutMs: 650_000, env: { RELAY_TEST_STAGE2_LIVE: "1" } },
|
|
35
|
+
} },
|
|
36
|
+
28: { name: "mediated DNS, aliases, teardown, bypass and credentials", parts: {
|
|
37
|
+
unit: { files: ["mediated-network", "mediated-proxy"], min: 23 },
|
|
38
|
+
addresses: { files: ["proxy"], pattern: "^proxy: address and host-name checks|^proxy: the on-link check|^proxy: a name resolving to one of this machine", min: 3 },
|
|
39
|
+
worker: { files: ["stage2-escalation-live"], pattern: "live worker:.*mediated result", min: 1, host: true, env: { RELAY_TEST_MEDIATED_LIVE: "1" } },
|
|
40
|
+
public: { files: ["stage2-escalation-live"], pattern: "live worker:.*mediated-public result", min: 1, host: true, optIn: "RELAY_TEST_PUBLIC_NET" },
|
|
41
|
+
crossJobCrash: { files: ["stage2-escalation-live"], pattern: "live worker:.*mediated-crash result", min: 1, host: true, timeoutMs: 300_000, env: { RELAY_TEST_MEDIATED_LIVE: "1" } },
|
|
42
|
+
} },
|
|
43
|
+
29: { name: "local refusal, interlock and Claude/ACP never proxies", parts: {
|
|
44
|
+
unit: { files: ["wp4-interlock", "wp4-adapters", "mediated-proxy"], min: 25 },
|
|
45
|
+
decisions: { files: ["stage2-network-decisions"], min: 2 },
|
|
46
|
+
local: { files: ["stage2-grant"], pattern: "^local-mode interlock|^local mode while stage 2 is switched on:|^raw network grant:", min: 3 },
|
|
47
|
+
// The installed Claude case with stage 2 on, and the ACP case. Its stage-2-off variant is the
|
|
48
|
+
// claude-floor release check below, not a Codex pin requirement.
|
|
49
|
+
nativeProfiles: { files: ["stage2-native-live"], pattern: "^stage2 native live:", skipPattern: "\\(stage 2 off\\)", min: 2, host: true, timeoutMs: 500_000, env: { RELAY_TEST_STAGE2_NATIVE_LIVE: "1" } },
|
|
50
|
+
} },
|
|
51
|
+
31: { name: "standing network: stage2 routing, never hosts, proxy variables, refusal and resume", parts: {
|
|
52
|
+
unit: { files: ["stage2-network-decisions", "mediated-network"], min: 14 },
|
|
53
|
+
executor: { files: ["stage2-executor"], pattern: "^BB: open order", min: 1 },
|
|
54
|
+
live: { files: ["stage2-standing-live"], pattern: "^standing mediated live:", min: 4, host: true, timeoutMs: 1_000_000, env: { RELAY_TEST_STANDING_LIVE: "1" } },
|
|
55
|
+
} },
|
|
56
|
+
32: { name: "IPv4 localhost connect: disclosed LAN/tailnet scope, never and other-port denial", parts: {
|
|
57
|
+
unit: { files: ["stage2-network-decisions", "restart-overlay-profile"], min: 12 },
|
|
58
|
+
accounting: { files: ["stage2-escalation"], pattern: "^localhost connect (discloses|refuses)", min: 2 },
|
|
59
|
+
planner: { files: ["stage2-probe"], pattern: "^stage-2 overlay probe plan:|^stage-2 decoy network:", min: 2 },
|
|
60
|
+
kernel: { files: ["restart-overlay-live"], min: 1, host: true, env: { RELAY_TEST_STAGE2_LIVE: "1" } },
|
|
61
|
+
worker: { files: ["stage2-escalation-live"], pattern: "live worker:.*connect result", min: 1, host: true, env: { RELAY_TEST_STAGE2_LIVE: "1" } },
|
|
62
|
+
} },
|
|
63
|
+
// The keychain under the never floor: the floor denies the keychain files, and only relay's own
|
|
64
|
+
// Seatbelt denies the security daemons too. Reading an item in a file-based keychain needs both.
|
|
65
|
+
// A decoy keychain item is tried from native Codex turns, two for each network state: floored
|
|
66
|
+
// (its directory in never.paths, as the keychains are) it must be refused on every turn; the
|
|
67
|
+
// control, without that entry, must match doctor's documented keychain IPC (core/never-coverage.ts
|
|
68
|
+
// neverKeychainIpc). Network on (IPC open) the control retrieves the item, which shows the floored
|
|
69
|
+
// refusal comes from the file deny; network off (IPC closed) both are refused, a consistency check
|
|
70
|
+
// only. A new Codex version can change its seatbelt policy, so this belongs to the pin. Claude's
|
|
71
|
+
// side is the claude-floor release check.
|
|
72
|
+
33: { name: "the keychain under the never floor: a decoy keychain item is refused to floored native Codex turns, and its control without the file deny matches doctor's documented keychain IPC", parts: {
|
|
73
|
+
codex: { files: ["codex-permissions"], pattern: "^keychain decoy live \\(codex", min: 4, host: true, timeoutMs: 300_000, env: { RELAY_TEST_KEYCHAIN_LIVE: "1", RELAY_REQUIRE_REAL_CODEX: "1" } },
|
|
74
|
+
} },
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
// Release checks: run with the release gates and the red team, never by the Codex pin qualifier
|
|
78
|
+
// (codex-stage2.mjs takes ESCALATION_CASES only), so they add no pin dependency. Item 29's
|
|
79
|
+
// nativeProfiles still runs the installed Claude CLI (stage 2 on), as before.
|
|
80
|
+
export const RELEASE_CHECK_CASES = {
|
|
81
|
+
// Claude takes the never floor whatever stage 2 says (core/never-coverage.ts).
|
|
82
|
+
"claude-floor": { name: "Claude under the never floor with stage 2 off: installed CLI settings and native tools, and a decoy keychain item refused to a floored turn, with its control matching doctor's keychain IPC", parts: {
|
|
83
|
+
nativeStage2Off: { files: ["stage2-native-live"], pattern: "^stage2 native live: installed Claude.*\\(stage 2 off\\)", min: 1, host: true, timeoutMs: 400_000, env: { RELAY_TEST_STAGE2_NATIVE_LIVE: "1" } },
|
|
84
|
+
keychainDecoy: { files: ["stage2-native-live"], pattern: "^keychain decoy live \\(claude", min: 2, host: true, timeoutMs: 400_000, env: { RELAY_TEST_KEYCHAIN_LIVE: "1" } },
|
|
85
|
+
} },
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
// Node TAP summaries are evidence, unlike an exit code from a test filter matching nothing.
|
|
89
|
+
export function judgeTestRun({ output, code, signal, error }, minimum = 1) {
|
|
90
|
+
const count = key => Number(new RegExp(`^# ${key} (\\d+)$`, "m").exec(output ?? "")?.[1] ?? NaN);
|
|
91
|
+
const counts = Object.fromEntries(["tests", "pass", "fail", "cancelled", "skipped", "todo"].map(k => [k, count(k)]));
|
|
92
|
+
const why = [];
|
|
93
|
+
if (error || signal || code !== 0) why.push(error ?? `test process exit ${code}, signal ${signal ?? "none"}`);
|
|
94
|
+
if (!Number.isSafeInteger(counts.tests) || counts.pass < minimum || counts.pass !== counts.tests || counts.fail !== 0 || counts.cancelled !== 0 || counts.skipped !== 0 || counts.todo !== 0) why.push(`incomplete test evidence: ${JSON.stringify(counts)}, require at least ${minimum} passes and no skips`);
|
|
95
|
+
return { state: why.length ? "failed" : "passed", why: why.join("; "), counts };
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export async function runEscalationSuite({ checkout, dir, bin, id, name, spec, timeoutMs = spec.timeoutMs ?? 180_000 }) {
|
|
99
|
+
if (spec.host && process.platform !== "darwin") return { state: "not run", why: "requires a macOS host" };
|
|
100
|
+
if (spec.optIn && process.env[spec.optIn] !== "1") return { state: "not run", why: `opt in with ${spec.optIn}=1` };
|
|
101
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
102
|
+
const log = path.join(dir, `escalation-${id}-${name}.tap`);
|
|
103
|
+
const args = ["--test", "--test-reporter=tap", "--test-concurrency=1", "--test-timeout=150000", ...(spec.pattern ? [`--test-name-pattern=${spec.pattern}`] : []), ...(spec.skipPattern ? [`--test-skip-pattern=${spec.skipPattern}`] : []), ...spec.files.map(f => `test/${f}.test.ts`)];
|
|
104
|
+
const result = await new Promise(resolve => {
|
|
105
|
+
// The live harness creates all homes, roots, credentials and ports itself.
|
|
106
|
+
const child = spawn(process.execPath, args, { cwd: checkout, env: { ...process.env, ...spec.env, RELAY_TEST_CODEX: bin }, stdio: ["ignore", "pipe", "pipe"] });
|
|
107
|
+
let output = "", error;
|
|
108
|
+
const sink = fs.createWriteStream(log, { mode: 0o600 });
|
|
109
|
+
for (const stream of [child.stdout, child.stderr]) stream.on("data", b => { sink.write(b); output = (output + b).slice(-128 * 1024); });
|
|
110
|
+
const timer = setTimeout(() => { error = `suite exceeded ${timeoutMs} ms`; child.kill("SIGTERM"); }, timeoutMs);
|
|
111
|
+
// Node's own test timeout aborts the live harness first; its finally stops workers/executors.
|
|
112
|
+
child.once("error", e => { error = String(e); });
|
|
113
|
+
child.once("close", (code, signal) => { clearTimeout(timer); sink.end(() => resolve({ output, code, signal, error })); });
|
|
114
|
+
});
|
|
115
|
+
return { ...judgeTestRun(result, spec.min), log };
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export async function runEscalationItem(ctx, id, cases = ESCALATION_CASES) {
|
|
119
|
+
const c = cases[id];
|
|
120
|
+
const parts = {};
|
|
121
|
+
for (const [name, spec] of Object.entries(c.parts)) parts[name] = await runEscalationSuite({ ...ctx, id, name, spec });
|
|
122
|
+
// Known missing integrated evidence cannot accidentally qualify a release.
|
|
123
|
+
if (c.gap) parts.coverage = { state: "pending integration", why: c.gap };
|
|
124
|
+
return parts;
|
|
125
|
+
}
|