@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,337 @@
|
|
|
1
|
+
// xAI's Grok Build CLI over ACP (`grok agent stdio`): its profile for the generic driver (acp.ts).
|
|
2
|
+
// What this says about Grok comes from the 1.0.62 package, run without a login and without a model
|
|
3
|
+
// call (its help, initialize, authMethods, `grok inspect --json`, `grok models`), its user guide as
|
|
4
|
+
// that binary ships it, and its public source at 1.0.45 (xai-org/grok-build@2bdd1d6a), which lags the
|
|
5
|
+
// binary. What only a signed-in run can show is marked "unverified" where it matters, and the
|
|
6
|
+
// qualification run must confirm it (docs/research/grok-1.0.62.md, "Still open"; the earlier
|
|
7
|
+
// research is docs/research/acp-google-grok.md §2 and §5).
|
|
8
|
+
import fs from "node:fs";
|
|
9
|
+
import os from "node:os";
|
|
10
|
+
import path from "node:path";
|
|
11
|
+
import { authFor, harnessHome, networkOn } from "../core/config.js";
|
|
12
|
+
import { GROK_LOGIN_STORE, GROK_MODELS } from "../targets/grok.js";
|
|
13
|
+
import { acpBackend, genericApproval } from "./acp.js";
|
|
14
|
+
import { targetLabel } from "../targets/index.js";
|
|
15
|
+
/**
|
|
16
|
+
* Where the user's own Grok login is, as Grok itself finds it, from the worker's environment
|
|
17
|
+
* (relay replaces every Grok variable in Grok's): GROK_AUTH_PATH, else auth.json in GROK_HOME, else
|
|
18
|
+
* in ~/.grok. An empty variable counts as unset, as it does for Grok.
|
|
19
|
+
*/
|
|
20
|
+
export function grokUserAuthPath(env = process.env, home = os.homedir()) {
|
|
21
|
+
if (env.GROK_AUTH_PATH)
|
|
22
|
+
return env.GROK_AUTH_PATH;
|
|
23
|
+
return path.join(env.GROK_HOME || path.join(home, ".grok"), "auth.json");
|
|
24
|
+
}
|
|
25
|
+
/** The login relay runs Grok on: auth.json in Grok's login directory, the target's login store (~/.grok). */
|
|
26
|
+
export const grokLoginPath = (home = os.homedir()) => path.join(home, GROK_LOGIN_STORE.dir, GROK_LOGIN_STORE.files[0]);
|
|
27
|
+
/**
|
|
28
|
+
* Why relay does not run Grok (`name`, its label) on this worker's login, or null. Relay runs it on
|
|
29
|
+
* the login in ~/.grok only, the one directory where its sandbox lets a turn refresh it (the
|
|
30
|
+
* target's login store, D10): a GROK_AUTH_PATH or GROK_HOME in relay's environment that puts the
|
|
31
|
+
* login elsewhere is refused rather than replaced by another login, or by none; so is a machine
|
|
32
|
+
* with no ~/.grok, where Grok has never been signed in.
|
|
33
|
+
*/
|
|
34
|
+
export function grokLoginRefusal(name, env = process.env, home = os.homedir()) {
|
|
35
|
+
const login = grokLoginPath(home);
|
|
36
|
+
const theirs = path.resolve(grokUserAuthPath(env, home));
|
|
37
|
+
if (theirs !== login) {
|
|
38
|
+
const which = env.GROK_AUTH_PATH ? "GROK_AUTH_PATH" : "GROK_HOME";
|
|
39
|
+
return `${which} in relay's environment puts Grok's login at ${theirs}, but relay runs ${name} only on the login in ${login}, the one place its sandbox lets a turn refresh it. Unset ${which} in the environment relay runs in, so that \`grok login\` keeps the login there.`;
|
|
40
|
+
}
|
|
41
|
+
if (!fs.lstatSync(path.dirname(login), { throwIfNoEntry: false }))
|
|
42
|
+
return `${name} has no login on this machine (${path.dirname(login)} does not exist). Sign in with \`grok login\`.`;
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Configuration layers outside the home relay gives Grok, which no setting of relay's outranks:
|
|
47
|
+
* the system's managed defaults and requirements (pinned keys there beat the environment and the
|
|
48
|
+
* command line), and the requirements macOS device management installs for the `ai.x.grok` domain
|
|
49
|
+
* (from 1.0.62's binary and its configuration reference). Relay does not run Grok where one exists.
|
|
50
|
+
*/
|
|
51
|
+
export const GROK_SYSTEM_LAYERS = Object.freeze([
|
|
52
|
+
"/etc/grok/managed_config.toml",
|
|
53
|
+
"/etc/grok/requirements.toml",
|
|
54
|
+
"/Library/Managed Preferences/ai.x.grok.plist",
|
|
55
|
+
]);
|
|
56
|
+
/** The first of `paths` that exists (as anything, a link included), or null. */
|
|
57
|
+
export function systemLayer(paths) {
|
|
58
|
+
return paths.find((p) => fs.lstatSync(p, { throwIfNoEntry: false })) ?? null;
|
|
59
|
+
}
|
|
60
|
+
let layersStandIn = null;
|
|
61
|
+
/**
|
|
62
|
+
* Test-only seam: the system layers relay checks for in this process (scratch files a test makes),
|
|
63
|
+
* or null for the real ones. Nothing in relay calls this; only test code does.
|
|
64
|
+
*/
|
|
65
|
+
export function setGrokSystemLayersForTests(layers) {
|
|
66
|
+
layersStandIn = layers;
|
|
67
|
+
}
|
|
68
|
+
/** Every system layer relay checks for: GROK_SYSTEM_LAYERS, and the managed-preferences file device management installs for this user. */
|
|
69
|
+
export const grokSystemLayers = () => layersStandIn ? [...layersStandIn] : [...GROK_SYSTEM_LAYERS, path.join("/Library/Managed Preferences", os.userInfo().username, "ai.x.grok.plist")];
|
|
70
|
+
/** Why relay does not run Grok (`name`, its label) on this machine, or null: the first of `layers` that exists. */
|
|
71
|
+
export function grokSystemRefusal(name, layers = grokSystemLayers()) {
|
|
72
|
+
const layer = systemLayer(layers);
|
|
73
|
+
if (!layer)
|
|
74
|
+
return null;
|
|
75
|
+
return `this machine has Grok configuration that relay cannot override (${layer}): its pinned settings outrank everything relay sets, so relay cannot tell which model would answer or keep ${name}'s own sandbox and telemetry off. It does not run ${name} here.`;
|
|
76
|
+
}
|
|
77
|
+
const COMPAT = ["CLAUDE", "CURSOR", "CODEX"].flatMap((tool) => ["SKILLS", "RULES", "AGENTS", "MCPS", "HOOKS", "SESSIONS"].map((what) => `GROK_${tool}_${what}_ENABLED`));
|
|
78
|
+
/**
|
|
79
|
+
* What relay sets in Grok's environment, beyond its home and login path: the environment outranks
|
|
80
|
+
* Grok's configuration files, the remote settings xAI can push and its rollout switches, so each
|
|
81
|
+
* setting that has a variable is set here as well as in the configuration file. Every name is in the
|
|
82
|
+
* 1.0.62 binary; the compatibility switches were seen to take effect in `grok inspect --json`.
|
|
83
|
+
*/
|
|
84
|
+
export const GROK_ENV = Object.freeze({
|
|
85
|
+
// Grok's own sandbox (whole process), and its per-command sandbox, which xAI can switch on remotely: either would nest inside relay's.
|
|
86
|
+
GROK_SANDBOX: "off",
|
|
87
|
+
GROK_SANDBOX_MODE: "off",
|
|
88
|
+
GROK_DISABLE_AUTOUPDATER: "1",
|
|
89
|
+
GROK_TELEMETRY_ENABLED: "0",
|
|
90
|
+
GROK_TELEMETRY_TRACE_UPLOAD: "0",
|
|
91
|
+
GROK_TELEMETRY_MIXPANEL_ENABLED: "0",
|
|
92
|
+
GROK_ERROR_REPORTING: "0",
|
|
93
|
+
DISABLE_ERROR_REPORTING: "1",
|
|
94
|
+
GROK_EXTERNAL_OTEL: "0",
|
|
95
|
+
GROK_CRASH_HANDLER: "0",
|
|
96
|
+
// Subagents can run other models; memory carries one session's notes into the next.
|
|
97
|
+
GROK_SUBAGENTS: "0",
|
|
98
|
+
GROK_MEMORY: "0",
|
|
99
|
+
// Patches and MCP servers xAI or an organisation can push.
|
|
100
|
+
GROK_CAMPAIGNS: "0",
|
|
101
|
+
GROK_MANAGED_MCPS_ENABLED: "0",
|
|
102
|
+
// Its own session sync with grok.com (no relation to relay).
|
|
103
|
+
GROK_RELAY_SYNC_ENABLED: "0",
|
|
104
|
+
GROK_SESSION_REGISTRY: "0",
|
|
105
|
+
// web_fetch, off by default but a rollout switch, fetches without asking: relay keeps it off, with a network grant too.
|
|
106
|
+
GROK_WEB_FETCH: "0",
|
|
107
|
+
// The skills, rules, agents, MCP servers, hooks and sessions it would import from Claude Code, Cursor and Codex.
|
|
108
|
+
...Object.fromEntries(COMPAT.map((k) => [k, "0"])),
|
|
109
|
+
});
|
|
110
|
+
/**
|
|
111
|
+
* Relay's configuration file for Grok, Grok's user layer in the home relay builds (its own
|
|
112
|
+
* `~/.grok/config.toml` is never read). Written before every turn and read-only to the agent.
|
|
113
|
+
* There is no `[model.*]` table (which could put another family's model behind any id) and no
|
|
114
|
+
* `[endpoints]` (which could send Grok elsewhere). No requirements.toml goes beside it: Grok 1.0.62
|
|
115
|
+
* reads `$GROK_HOME/requirements.toml` as a signed cache and applies nothing from one that is not
|
|
116
|
+
* signed (seen: a pinned `models.default` there was ignored), so the pins would be a pretence.
|
|
117
|
+
*
|
|
118
|
+
* `network`: whether the turn has network access (a grant, or child_network). Without it Grok's
|
|
119
|
+
* web_search is dropped: it runs on Grok's own API host (cli-chat-proxy.grok.com), which relay's
|
|
120
|
+
* proxy admits, and never asks, so the model could otherwise send what it chose in its queries and
|
|
121
|
+
* bring the web's content into the turn. `disable_web_search` also drops web_fetch (1.0.62, decoy
|
|
122
|
+
* login: 25 tools in the session, 24 with it; with GROK_WEB_FETCH=1, 26 and still 24). Its
|
|
123
|
+
* server-side ("backend") tools, which run inside the model request on that same host (backend web
|
|
124
|
+
* search, X search, the code interpreter; `features.backend_tools`, on by default), are switched off
|
|
125
|
+
* too (with GROK_BACKEND_SEARCH=0 in its environment: grokState). That a signed-in turn then shows
|
|
126
|
+
* none is unverified: the decoy login never loaded the catalog that would offer them.
|
|
127
|
+
*
|
|
128
|
+
* `keys`: whether an API key may sign Grok in (child_auth "any" for it). Otherwise Grok's own switch
|
|
129
|
+
* `auth.disable_api_key_auth` is set too (and GROK_DISABLE_API_KEY_AUTH=1: grokState). The oidc pin
|
|
130
|
+
* refuses the API-key method, not an API key Grok keeps in auth.json (its `xai::api_key` scope, which
|
|
131
|
+
* 1.0.62 loads: "auth: loaded API key from auth.json"); `cached_token` accepts a stored key unless
|
|
132
|
+
* that switch is set (1.0.45 source, manager.rs `login_policy_error`; the switch is in 1.0.62's
|
|
133
|
+
* configuration reference, "Refuse API-key auth so only the deployment IdP can log in"). That 1.0.62
|
|
134
|
+
* then refuses a stored key, and still accepts an account's login, is for the signed-in run (review
|
|
135
|
+
* r_f887dc06 C2).
|
|
136
|
+
*/
|
|
137
|
+
export function grokConfig(network = false, keys = false) {
|
|
138
|
+
const off = (keys) => keys.map((k) => `${k} = false`).join("\n");
|
|
139
|
+
const surfaces = ["agents", "hooks", "mcps", "rules", "skills", "sessions"];
|
|
140
|
+
return `# Relay's settings for Grok Build, rewritten before every turn; read-only to the agent.
|
|
141
|
+
${network ? "" : `
|
|
142
|
+
# No network grant this turn: no web_search or web_fetch, which go out through Grok's own API host and never ask.
|
|
143
|
+
disable_web_search = true
|
|
144
|
+
`}
|
|
145
|
+
# The stored login only: \`cached_token\` fails at once without one, rather than falling through to a
|
|
146
|
+
# browser sign-in or an API key (seen with 1.0.62).
|
|
147
|
+
[auth]
|
|
148
|
+
preferred_method = "oidc"
|
|
149
|
+
${keys ? "" : `# Nor an API key stored in auth.json: relay runs Grok on an account's login only (child_auth "login").
|
|
150
|
+
disable_api_key_auth = true
|
|
151
|
+
`}
|
|
152
|
+
# Grok's own sandbox would nest inside relay's.
|
|
153
|
+
[sandbox]
|
|
154
|
+
profile = "off"
|
|
155
|
+
|
|
156
|
+
[cli]
|
|
157
|
+
auto_update = false
|
|
158
|
+
use_leader = false
|
|
159
|
+
session_registry = false
|
|
160
|
+
|
|
161
|
+
[features]
|
|
162
|
+
telemetry = false
|
|
163
|
+
managed_config = false
|
|
164
|
+
campaigns = false
|
|
165
|
+
web_fetch = false
|
|
166
|
+
${network ? "" : `# No network grant this turn: no server-side tools either (backend web search, X search, the code interpreter).
|
|
167
|
+
backend_tools = false
|
|
168
|
+
`}
|
|
169
|
+
[telemetry]
|
|
170
|
+
trace_upload = false
|
|
171
|
+
otel_enabled = false
|
|
172
|
+
|
|
173
|
+
[diagnostics]
|
|
174
|
+
error_reporting = false
|
|
175
|
+
crash_handler = false
|
|
176
|
+
|
|
177
|
+
# Per-turn snapshots of the workspace and uploads of the codebase.
|
|
178
|
+
[harness]
|
|
179
|
+
disable_workspace_teleport = true
|
|
180
|
+
disable_codebase_upload = true
|
|
181
|
+
|
|
182
|
+
[relay]
|
|
183
|
+
enabled = false
|
|
184
|
+
|
|
185
|
+
[managed_mcps]
|
|
186
|
+
enabled = false
|
|
187
|
+
|
|
188
|
+
[subagents]
|
|
189
|
+
enabled = false
|
|
190
|
+
|
|
191
|
+
[memory]
|
|
192
|
+
enabled = false
|
|
193
|
+
|
|
194
|
+
[memory_v2]
|
|
195
|
+
enabled = false
|
|
196
|
+
|
|
197
|
+
[session]
|
|
198
|
+
load_envrc = false
|
|
199
|
+
|
|
200
|
+
[compat.claude]
|
|
201
|
+
${off(surfaces)}
|
|
202
|
+
|
|
203
|
+
[compat.cursor]
|
|
204
|
+
${off(surfaces)}
|
|
205
|
+
|
|
206
|
+
[compat.codex]
|
|
207
|
+
${off(["hooks", "skills", "sessions"])}
|
|
208
|
+
|
|
209
|
+
[models]
|
|
210
|
+
allowed_models = [${Object.keys(GROK_MODELS).map((m) => JSON.stringify(m)).join(", ")}]
|
|
211
|
+
|
|
212
|
+
# A marker Grok writes on first launch; written here, it has nothing to write.
|
|
213
|
+
[marketplace]
|
|
214
|
+
default_skills_installs_purged = true
|
|
215
|
+
`;
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* The Grok home a session runs with (GROK_HOME): one per relay session, under relay's harness
|
|
219
|
+
* directory, outside its control directory. It is relay's, and read-only to the agent; only two
|
|
220
|
+
* directories in it are writable:
|
|
221
|
+
*
|
|
222
|
+
* - `sessions/`: Grok's sessions (one directory per working directory, then per session id), the
|
|
223
|
+
* one thing kept from turn to turn, since resuming needs it. Relay refuses to run on it if it is
|
|
224
|
+
* anything but a plain directory (an agent could otherwise swap in a link that the next turn's
|
|
225
|
+
* sandbox would follow and open).
|
|
226
|
+
* - `turn/`: this turn's logs (`logs` in the home links there), removed with it.
|
|
227
|
+
*
|
|
228
|
+
* Before every turn relay rebuilds the rest: its own config.toml (grokConfig). Grok 1.0.62 also
|
|
229
|
+
* writes lock files, its extracted user guide and an agent id in its home on start; refused there,
|
|
230
|
+
* it carries on (seen without a login, up to session/new). Nothing of the user's Grok configuration
|
|
231
|
+
* comes along: no MCP servers, hooks, plugins, skills, rules, saved permissions or memory.
|
|
232
|
+
*
|
|
233
|
+
* The stored login stays where `grok login` puts it, ~/.grok/auth.json: GROK_AUTH_PATH points
|
|
234
|
+
* there (grokLoginPath; a worker whose own GROK_AUTH_PATH or GROK_HOME points elsewhere is refused,
|
|
235
|
+
* grokLoginRefusal), and relay never opens the file. Grok refreshes it by locking `auth.json.lock`,
|
|
236
|
+
* spending the single-use refresh token with xAI, and replacing auth.json through a temporary file
|
|
237
|
+
* and a rename; a turn that spent the refresh token and then could not save its successor would
|
|
238
|
+
* sign the user out of Grok everywhere. The target's login store (GROK_LOGIN_STORE, D10) lets a
|
|
239
|
+
* turn do exactly that in ~/.grok, and nothing else there: the sandbox layer checks the directory
|
|
240
|
+
* and every name it makes writable before the turn, and probes the same rules on a decoy store.
|
|
241
|
+
* Everything else in ~/.grok (the user's config.toml, MCP credentials) stays read-only.
|
|
242
|
+
*
|
|
243
|
+
* HOME is a temporary one (the default), which also hides ~/.claude, ~/.claude.json, ~/.cursor,
|
|
244
|
+
* ~/.codex and ~/.agents, whose MCP servers, hooks and skills Grok would otherwise import. Grok
|
|
245
|
+
* checks certificates with rustls-platform-verifier (0.6.2 in the 1.0.62 binary, which calls
|
|
246
|
+
* `SecTrustEvaluateWithError`), so the Security framework's trust daemons evaluate its API
|
|
247
|
+
* connections, and any certificate fetches for them (AIA, OCSP) go past relay's proxy. It gets the
|
|
248
|
+
* trust daemons: a stated downgrade, as for Copilot.
|
|
249
|
+
*/
|
|
250
|
+
export function grokState(spec) {
|
|
251
|
+
const home = path.join(harnessHome(), spec.markers.runId, spec.markers.nodeId, "grok");
|
|
252
|
+
fs.mkdirSync(home, { recursive: true, mode: 0o700 });
|
|
253
|
+
fs.chmodSync(home, 0o700);
|
|
254
|
+
const sessions = path.join(home, "sessions");
|
|
255
|
+
const kept = fs.lstatSync(sessions, { throwIfNoEntry: false });
|
|
256
|
+
if (kept && (kept.isSymbolicLink() || !kept.isDirectory())) {
|
|
257
|
+
throw new Error(`${targetLabel(spec.target)}'s session store for this session (${sessions}) has been replaced by something other than a directory, which relay's sandbox would follow, so relay does not run it on that directory. Start a new job.`);
|
|
258
|
+
}
|
|
259
|
+
for (const name of fs.readdirSync(home))
|
|
260
|
+
if (name !== "sessions")
|
|
261
|
+
fs.rmSync(path.join(home, name), { recursive: true, force: true });
|
|
262
|
+
fs.mkdirSync(sessions, { recursive: true, mode: 0o700 });
|
|
263
|
+
const turn = path.join(home, "turn");
|
|
264
|
+
fs.mkdirSync(path.join(turn, "logs"), { recursive: true, mode: 0o700 });
|
|
265
|
+
fs.symlinkSync(path.join(turn, "logs"), path.join(home, "logs"));
|
|
266
|
+
const network = networkOn(spec.config, spec.grant);
|
|
267
|
+
// Under child_auth "any" whatever Grok signs in with is accepted, a key stored in auth.json included.
|
|
268
|
+
const keys = authFor(spec.config, spec.target.id) === "any";
|
|
269
|
+
fs.writeFileSync(path.join(home, "config.toml"), grokConfig(network, keys), { mode: 0o600 });
|
|
270
|
+
return {
|
|
271
|
+
stateDirs: [],
|
|
272
|
+
persistent: { root: home, writable: ["sessions", "turn"] },
|
|
273
|
+
home: "temp",
|
|
274
|
+
// Without a network grant, Grok's server-side tools off by the variable too, which outranks its files and the remote settings (grokConfig).
|
|
275
|
+
// Under child_auth "login", an API key stored in auth.json refused by the variable too (grokConfig).
|
|
276
|
+
env: { ...GROK_ENV, ...(network ? {} : { GROK_BACKEND_SEARCH: "0" }), ...(keys ? {} : { GROK_DISABLE_API_KEY_AUTH: "1" }), GROK_HOME: home, GROK_AUTH_PATH: grokLoginPath() },
|
|
277
|
+
keychain: false,
|
|
278
|
+
// Very likely needed (rustls-platform-verifier, above), as Copilot's Rust core needed them (2026-10-17); a signed-in run will tell.
|
|
279
|
+
certificateTrust: true,
|
|
280
|
+
cleanup: () => fs.rmSync(turn, { recursive: true, force: true }),
|
|
281
|
+
};
|
|
282
|
+
}
|
|
283
|
+
export const grokProfile = {
|
|
284
|
+
args: (spec, model) => [
|
|
285
|
+
// Runs the version that was launched (a top-level flag Grok accepts but does not list; 1.0.62).
|
|
286
|
+
"--no-auto-update",
|
|
287
|
+
// Without a network grant, no web search (grokConfig): the flag outranks every settings file but a signed requirements pin (seen with 1.0.62's `agent stdio`).
|
|
288
|
+
...(networkOn(spec.config, spec.grant) ? [] : ["--disable-web-search"]),
|
|
289
|
+
"agent",
|
|
290
|
+
// A leader process started outside relay's sandbox would run the tools unconfined.
|
|
291
|
+
"--no-leader",
|
|
292
|
+
// Relay's sandbox is the boundary, and nothing approved lifts it (no escalation through relay's
|
|
293
|
+
// sandbox in 1.0), so Grok runs without asking, persisting nothing.
|
|
294
|
+
"--always-approve",
|
|
295
|
+
// A process per turn, so a resumed session gets it too; the session's reported model is checked against it.
|
|
296
|
+
...(model ? ["-m", model] : []),
|
|
297
|
+
...(spec.effort ? ["--reasoning-effort", spec.effort] : []),
|
|
298
|
+
"stdio",
|
|
299
|
+
],
|
|
300
|
+
// Every Grok and xAI variable is relay's to set (GROK_MODELS_BASE_URL, GROK_CONFIG, GROK_AUTH_PATH
|
|
301
|
+
// and dozens more reconfigure it, or point it elsewhere), and so are the OpenTelemetry and Sentry
|
|
302
|
+
// sinks it would report to. Its API keys go with them, whatever child_auth says: relay pins Grok to
|
|
303
|
+
// its stored login (the oidc pin refuses the API-key method), so a key would only be handed to the agent.
|
|
304
|
+
scrub: (k) => /^(GROK_|XAI_|OTEL_)/.test(k) || k === "SENTRY_DSN",
|
|
305
|
+
prepareState: grokState,
|
|
306
|
+
// Grok reports the session's effort as its `reasoning_effort` option (category thought_level), and
|
|
307
|
+
// runs an effort its model's menu lacks at "high" without a word (1.0.62, decoy login: grok-4.5
|
|
308
|
+
// offers high, medium and low, grok-4.6 xhigh too; `xhigh` on grok-4.5, `max` and `minimal` ran
|
|
309
|
+
// as "high"), so relay checks it before the prompt.
|
|
310
|
+
effortOption: "thought_level",
|
|
311
|
+
login: {
|
|
312
|
+
// With the oidc pin in relay's config.toml, Grok offers `cached_token` only when a login is
|
|
313
|
+
// stored, and authenticating with it fails at once without one ("preferred_method=oidc but no
|
|
314
|
+
// session is available"), with no browser and no API key (seen with 1.0.62). Unpinned, it falls
|
|
315
|
+
// through to a browser sign-in. It also succeeds with an expired login (seen with a decoy whose
|
|
316
|
+
// refresh could not go through), so an expired login is refreshed, through the login store, at
|
|
317
|
+
// the turn's first request, not before the prompt. That it succeeds with a real stored login,
|
|
318
|
+
// and that the refresh goes through, is unverified. Under child_auth "any" relay skips it, and
|
|
319
|
+
// 1.0.62 then opens a session with a stored login and refuses one without ("Authentication
|
|
320
|
+
// required"; decoy login).
|
|
321
|
+
reuse: ["cached_token"],
|
|
322
|
+
how: "Sign in with `grok login`. Relay uses Grok's stored login in ~/.grok (its turns may refresh it there, through Grok's own lock, temp file and rename, and change nothing else in that directory), and removes XAI_API_KEY and every other Grok variable from its environment.",
|
|
323
|
+
},
|
|
324
|
+
normalizeApproval(call, spec) {
|
|
325
|
+
const ask = genericApproval(call);
|
|
326
|
+
if (!ask)
|
|
327
|
+
return null;
|
|
328
|
+
// The directory the command would run in, as the agent gave it (relative to its own), else its own.
|
|
329
|
+
const detail = (ask.detail ?? {});
|
|
330
|
+
const cwd = path.resolve(spec.cwd, typeof detail.cwd === "string" ? detail.cwd : ".");
|
|
331
|
+
const paths = ask.paths?.map((p) => path.resolve(cwd, p));
|
|
332
|
+
// Whatever is approved, relay's sandbox stays on: say so to whoever decides.
|
|
333
|
+
return { ...ask, ...(paths ? { paths } : {}), detail: { ...detail, cwd, confined: true } };
|
|
334
|
+
},
|
|
335
|
+
refuse: (spec) => grokSystemRefusal(targetLabel(spec.target)) ?? grokLoginRefusal(targetLabel(spec.target)),
|
|
336
|
+
};
|
|
337
|
+
export const grokBackend = acpBackend(grokProfile);
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
const lazy = (load) => ({ start: async (spec) => (await load()).start(spec) });
|
|
2
|
+
export const BACKENDS = {
|
|
3
|
+
claude: lazy(async () => (await import("./claude.js")).claudeBackend),
|
|
4
|
+
codex: lazy(async () => (await import("./codex.js")).codexBackend),
|
|
5
|
+
copilot: lazy(async () => (await import("./copilot.js")).copilotBackend),
|
|
6
|
+
gemini: lazy(async () => (await import("./gemini.js")).geminiBackend),
|
|
7
|
+
grok: lazy(async () => (await import("./grok.js")).grokBackend),
|
|
8
|
+
};
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { checkNativeTempAlias, claudeTempFits, ensureNativeTempAlias, ensurePrivateRoot, nativeTempAlias, nativeTempRoot } from "../confine/private-root.js";
|
|
4
|
+
import { privateTurnTemp } from "../confine/turn.js";
|
|
5
|
+
import { getTurn, updateTurn } from "../core/db.js";
|
|
6
|
+
import { capturedRootEnvironment, selectEnvironment } from "../core/env-policy.js";
|
|
7
|
+
import { appendLog, logBytes } from "../core/storage.js";
|
|
8
|
+
import { olderVersion } from "../targets/index.js";
|
|
9
|
+
import { englishList, newest, VERIFIED } from "../targets/verified.js";
|
|
10
|
+
import { installedVersion } from "./cli-version.js";
|
|
11
|
+
const TOO_LONG = "Claude's private temporary path would exceed its 44-byte limit and fall back to shared temp";
|
|
12
|
+
/**
|
|
13
|
+
* The newest Claude Code whose temporary-directory code relay has read (VERIFIED.claudeTempLink,
|
|
14
|
+
* targets/verified.ts): each version there measures CLAUDE_CODE_TMPDIR before resolving links,
|
|
15
|
+
* which is what makes the short link keep Claude out of shared temp
|
|
16
|
+
* (docs/research/claude-temp-limit.md, which also names the versions not read). Relay's version
|
|
17
|
+
* gate is a floor, and Claude updates itself, so the link is refused for anything newer. Raise it
|
|
18
|
+
* only after re-reading that code in the newer version (scripts/release-watch does, by behaviour).
|
|
19
|
+
*/
|
|
20
|
+
export const CLAUDE_TEMP_LINK_VERIFIED_THROUGH = newest("claudeTempLink").split(".").map(Number);
|
|
21
|
+
/** What makes `have` a version whose temp code relay has not read (newer than the ceiling, or unreadable), or null. */
|
|
22
|
+
function unreadVersion(have, bin) {
|
|
23
|
+
const top = CLAUDE_TEMP_LINK_VERIFIED_THROUGH.join(".");
|
|
24
|
+
const which = !have ? `relay could not read a version from \`${bin} --version\``
|
|
25
|
+
: olderVersion(CLAUDE_TEMP_LINK_VERIFIED_THROUGH, have) ? `${bin} is Claude Code ${have.join(".")}, newer than ${top}` : null;
|
|
26
|
+
return which && `${which}, the newest version whose temporary-directory code relay has read`;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Why relay's long-home link may not be used with the Claude Code `bin` reports as `have` (null:
|
|
30
|
+
* unreadable), or null when it may: at or below CLAUDE_TEMP_LINK_VERIFIED_THROUGH, or allow_untested.
|
|
31
|
+
*/
|
|
32
|
+
export function linkVersionProblem(have, bin, allowUntested) {
|
|
33
|
+
const which = allowUntested ? null : unreadVersion(have, bin);
|
|
34
|
+
if (!which)
|
|
35
|
+
return null;
|
|
36
|
+
const top = CLAUDE_TEMP_LINK_VERIFIED_THROUGH.join(".");
|
|
37
|
+
return `${which}. This is the check on relay's long-home workaround: ` +
|
|
38
|
+
`under a home this long relay hands Claude its private temporary directory through a short link, which keeps Claude out of shared temp only while Claude measures CLAUDE_CODE_TMPDIR before resolving links, as ${englishList(VERIFIED.claudeTempLink)} do. ` +
|
|
39
|
+
`Pin Claude Code to ${top} or older (targets.claude.bin can name that version's binary), or update relay once a release has re-read that code; or set "allow_untested": true in relay's config to run anyway, unverified`;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Why Claude may not be launched with `env`, by the link's ceiling (linkVersionProblem), or null:
|
|
43
|
+
* asked with the environment Claude is launched with, beside the version gate and on the same read
|
|
44
|
+
* (run.ts launchTurn), whenever that environment names Claude's temp through relay's short link.
|
|
45
|
+
* nativeTemp asks first, before it uses the link, with the turn's selected environment, since
|
|
46
|
+
* Claude's own does not exist yet; but one launcher can report another version under the
|
|
47
|
+
* environment it runs with (review 2026-11-09, item I2), so the launch is checked by its own.
|
|
48
|
+
*/
|
|
49
|
+
export function linkLaunchProblem(config, env) {
|
|
50
|
+
if (config.allow_untested)
|
|
51
|
+
return null;
|
|
52
|
+
const link = nativeTempAlias();
|
|
53
|
+
const through = (p) => {
|
|
54
|
+
if (!p)
|
|
55
|
+
return false;
|
|
56
|
+
const rel = path.relative(link, path.resolve(p));
|
|
57
|
+
return rel === "" || (!rel.startsWith("..") && !path.isAbsolute(rel));
|
|
58
|
+
};
|
|
59
|
+
if (!through(env.CLAUDE_CODE_TMPDIR) && !through(env.TMPDIR))
|
|
60
|
+
return null;
|
|
61
|
+
const { bin } = config.targets.claude;
|
|
62
|
+
const version = linkVersionProblem(installedVersion("claude", bin, env), bin, false);
|
|
63
|
+
return version && `Claude's private temporary directory is named through relay's short link ${link} for this launch, which relay does not use here: ${version}`;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* The name Claude is given for its private directory `dir` (in `~/.rn`): `dir` itself when it fits
|
|
67
|
+
* Claude's limit, or else the same directory through relay's short link, checked on each use, when
|
|
68
|
+
* `versionProblem` (asked only then) has none. A turn makes a missing link; `create: false` (doctor's
|
|
69
|
+
* probe) only uses one already there. Refuses when neither name fits, the Claude version is not one
|
|
70
|
+
* whose temp code relay has read, or the link is missing or cannot be trusted; never shared temp.
|
|
71
|
+
*/
|
|
72
|
+
export function claudeTempPath(dir, versionProblem, o = { create: true }) {
|
|
73
|
+
if (claudeTempFits(dir))
|
|
74
|
+
return dir;
|
|
75
|
+
const link = nativeTempAlias();
|
|
76
|
+
const short = path.join(link, path.basename(dir));
|
|
77
|
+
// Nothing is made outside the home for a name that would not fit anyway (a uid over five digits),
|
|
78
|
+
// or for a Claude version the link has not been checked against.
|
|
79
|
+
if (!claudeTempFits(short))
|
|
80
|
+
throw new Error(`${TOO_LONG}, even through relay's short link ${short}; use a shorter home path before launching this turn`);
|
|
81
|
+
const version = versionProblem();
|
|
82
|
+
if (version)
|
|
83
|
+
throw new Error(`${TOO_LONG}, and relay does not use its short link ${link} here: ${version}`);
|
|
84
|
+
if (o.create) {
|
|
85
|
+
try {
|
|
86
|
+
ensureNativeTempAlias(path.dirname(dir));
|
|
87
|
+
}
|
|
88
|
+
catch (err) {
|
|
89
|
+
throw new Error(`${TOO_LONG}, and ${err.message}`);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
const found = checkNativeTempAlias(path.dirname(dir));
|
|
94
|
+
if (found.state === "missing")
|
|
95
|
+
throw new Error(`${TOO_LONG}, and relay's short link ${link} is not there yet; relay makes it on the first Claude turn`);
|
|
96
|
+
if (found.state === "stale")
|
|
97
|
+
throw new Error(`${TOO_LONG}, and relay's short link ${link} points to missing earlier private directory ${found.target}; relay repoints it on the first Claude turn`);
|
|
98
|
+
if (found.state === "refused")
|
|
99
|
+
throw new Error(`${TOO_LONG}, and ${found.problem}`);
|
|
100
|
+
}
|
|
101
|
+
const via = fs.statSync(short);
|
|
102
|
+
const real = fs.lstatSync(dir);
|
|
103
|
+
if (via.dev !== real.dev || via.ino !== real.ino)
|
|
104
|
+
throw new Error(`${TOO_LONG}, and ${short} does not lead to ${dir}`);
|
|
105
|
+
return short;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Doctor's report on the long-home link, from the checks a Claude turn makes, making nothing; null
|
|
109
|
+
* for a home short enough not to need it. `level` is how doctor says it; `usable` whether a Claude
|
|
110
|
+
* turn (and doctor's init probe) could have its private temp now. `version` is what doctor read.
|
|
111
|
+
*/
|
|
112
|
+
export function claudeLinkDoctor(version, bin, allowUntested) {
|
|
113
|
+
const root = nativeTempRoot();
|
|
114
|
+
if (claudeTempFits(path.join(root, "Ab12Cd")))
|
|
115
|
+
return null;
|
|
116
|
+
const link = nativeTempAlias();
|
|
117
|
+
const top = CLAUDE_TEMP_LINK_VERIFIED_THROUGH.join(".");
|
|
118
|
+
const refuses = (why) => ({ level: "warn", usable: false, text: `relay refuses every Claude turn here: ${why}` });
|
|
119
|
+
if (!claudeTempFits(path.join(link, "Ab12Cd"))) {
|
|
120
|
+
return refuses(`${root} is too long for Claude's 44-byte temporary-directory limit, and so is relay's short link ${link} with a uid of ${String(process.getuid?.() ?? 0).length} digits. Use an account with a shorter home path, or a shorter uid`);
|
|
121
|
+
}
|
|
122
|
+
const unread = unreadVersion(version, bin);
|
|
123
|
+
if (unread && !allowUntested)
|
|
124
|
+
return refuses(linkVersionProblem(version, bin, false));
|
|
125
|
+
const found = checkNativeTempAlias(root);
|
|
126
|
+
if (found.state === "refused")
|
|
127
|
+
return refuses(found.problem);
|
|
128
|
+
const intro = `${root} is too long for Claude's 44-byte temporary-directory limit, so Claude gets its private temp through relay's short link ${link}`;
|
|
129
|
+
const state = found.state === "missing" ? "not there yet; relay makes it on the first Claude turn"
|
|
130
|
+
: found.state === "stale" ? `points to missing earlier private directory ${found.target}; relay repoints it on the first Claude turn`
|
|
131
|
+
: "in place, yours and leading there";
|
|
132
|
+
if (unread)
|
|
133
|
+
return { level: "warn", usable: found.state === "ok", text: `${intro}: ${state}. ${unread}; allow_untested is set, so relay uses the link anyway, unverified` };
|
|
134
|
+
return { level: "line", usable: found.state === "ok", text: `${intro}: ${state}; checked against Claude Code through ${top}` };
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Each native sandbox gets only its own TMPDIR, outside the shared /tmp allowances. `start` gets the
|
|
138
|
+
* directory and the name the agent is to use for it: the same, except for a Claude turn whose
|
|
139
|
+
* directory is too long for Claude (claudeTempPath). The registry and the sweep know only the directory.
|
|
140
|
+
*/
|
|
141
|
+
export async function nativeTemp(spec, start) {
|
|
142
|
+
const dir = privateTurnTemp(ensurePrivateRoot(nativeTempRoot()), "");
|
|
143
|
+
// Descendants may still be closing files when the process group exits. Bound the retries, and
|
|
144
|
+
// keep a cleanup failure out of the worker's control flow: the registry/sweep retains this path.
|
|
145
|
+
const remove = () => {
|
|
146
|
+
try {
|
|
147
|
+
fs.rmSync(dir, { recursive: true, force: true, maxRetries: 3, retryDelay: 50 });
|
|
148
|
+
return [];
|
|
149
|
+
}
|
|
150
|
+
catch (error) {
|
|
151
|
+
const warning = `relay could not remove native turn's private temporary directory ${dir}: ${error.message}. Private temporary files may remain; relay's temp sweep can retry cleanup.`;
|
|
152
|
+
const logProblem = spec.logPath ? appendLog(spec.logPath, `[relay] ${warning}\n`, { maxBytes: logBytes(spec.config) }) : null;
|
|
153
|
+
return [warning, ...(logProblem ? [logProblem] : [])];
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
const cleanupError = (error) => {
|
|
157
|
+
const warnings = remove();
|
|
158
|
+
return warnings.length ? new Error(`${error.message} ${warnings.join(" ")}`, { cause: error }) : error;
|
|
159
|
+
};
|
|
160
|
+
try {
|
|
161
|
+
const agentDir = spec.target.id === "claude" ? claudeTempPath(dir, () => {
|
|
162
|
+
// Before the link is used, with the turn's selected environment, from the gate's cache (cli-version.ts): read again when
|
|
163
|
+
// the executable or the environment changes, and after a minute. The launch is checked again with its own (linkLaunchProblem).
|
|
164
|
+
const { bin } = spec.config.targets.claude;
|
|
165
|
+
if (spec.config.allow_untested)
|
|
166
|
+
return null;
|
|
167
|
+
return linkVersionProblem(installedVersion("claude", bin, spec.environment ?? selectEnvironment("claude", spec.config, capturedRootEnvironment).env), bin, false);
|
|
168
|
+
}) : dir;
|
|
169
|
+
const id = spec.turnId ?? spec.relay?.turnId;
|
|
170
|
+
if (id !== undefined) {
|
|
171
|
+
const turn = getTurn(id);
|
|
172
|
+
if (!turn || turn.node_id !== spec.markers.nodeId || turn.status !== "running")
|
|
173
|
+
throw new Error("cannot record temp state for an inactive turn");
|
|
174
|
+
const st = fs.lstatSync(dir);
|
|
175
|
+
updateTurn(id, { tmp_dir: dir, tmp_dev: st.dev, tmp_ino: st.ino });
|
|
176
|
+
}
|
|
177
|
+
const handle = await start(dir, agentDir);
|
|
178
|
+
const done = handle.done.then((result) => {
|
|
179
|
+
const warnings = remove();
|
|
180
|
+
return warnings.length ? { ...result, warnings: [...(result.warnings ?? []), ...warnings] } : result;
|
|
181
|
+
}, (error) => { throw cleanupError(error); });
|
|
182
|
+
return { ...handle, done, cancel: async () => { await handle.cancel(); await done; } };
|
|
183
|
+
}
|
|
184
|
+
catch (error) {
|
|
185
|
+
throw cleanupError(error);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { neverGrantProblem, neverIdentityProblem, neverProxyInputs } from "../core/never-policy.js";
|
|
2
|
+
import { networkOn } from "../core/config.js";
|
|
3
|
+
import { stage2Enabled } from "../core/stage2-switch.js";
|
|
4
|
+
import { claudeFloorVariants, NEVER_FLOOR_CONFLICT, neverFloorApplies } from "../core/never-coverage.js";
|
|
5
|
+
import { stage2Wanted } from "./codex-stage2.js";
|
|
6
|
+
/**
|
|
7
|
+
* The first never network entry a native Codex shell route cannot enforce, or null.
|
|
8
|
+
*
|
|
9
|
+
* Strict reaches none of this Mac's addresses and sends no UDP: Seatbelt lets commands reach only
|
|
10
|
+
* the proxy's two loopback ports, the proxy refuses every non-public destination, and strict is
|
|
11
|
+
* not offered at all while an address of this Mac's own is public to the proxy (codex-network.ts
|
|
12
|
+
* ownPublicAddress, checked again by the turn's own server) or a network_rule could open a local
|
|
13
|
+
* host. So it enforces every "this-machine" entry, a built-in or the person's alike, and every
|
|
14
|
+
* UDP-only one. It cannot screen hosts (or their resolved aliases), nor an "any" entry covering
|
|
15
|
+
* TCP: the proxy lets every public host and port through. The IPv6 overblocking relay's own
|
|
16
|
+
* Seatbelt adds for a "this-machine" port (refused at every IPv6 host, since Seatbelt cannot name
|
|
17
|
+
* the IPv4-mapped forms of this Mac's addresses) is a cost of that route, not part of what the
|
|
18
|
+
* entry protects, so strict not repeating it leaves nothing open.
|
|
19
|
+
*
|
|
20
|
+
* Local and unconfined open this Mac's addresses, TCP and UDP, directly: no port entry of the
|
|
21
|
+
* person's holds there, and neither does any "any" entry. The built-in service ports are open there
|
|
22
|
+
* too, as they always were: local mode's consent names them (approvals.ts LOCAL_NETWORK_EFFECT),
|
|
23
|
+
* and an allow_dangerous write turn runs without a sandbox (never-coverage.ts says so in doctor).
|
|
24
|
+
*/
|
|
25
|
+
export function nativeCodexNeverNetworkEntry(policy, route = "strict") {
|
|
26
|
+
const inputs = neverProxyInputs(policy);
|
|
27
|
+
const unenforced = route === "strict"
|
|
28
|
+
? (p) => p.destinations === "any" && p.transport !== "udp"
|
|
29
|
+
: (p) => p.destinations === "any" || p.id.startsWith("user.port:");
|
|
30
|
+
return inputs.hosts[0]?.id ?? inputs.ports.find(unenforced)?.id ?? null;
|
|
31
|
+
}
|
|
32
|
+
/** The native route a turn's shell takes, by its effective grant (codex.ts chooseNetwork). */
|
|
33
|
+
export function nativeCodexShellRoute(spec) {
|
|
34
|
+
if (spec.config.allow_dangerous && spec.access === "write")
|
|
35
|
+
return "unconfined";
|
|
36
|
+
return spec.access === "write" && spec.grant?.local_network ? "local" : "strict";
|
|
37
|
+
}
|
|
38
|
+
/** Shared by turn launch and grant/resume admission, using the effective (possibly kept) grant.
|
|
39
|
+
* Consult stage2Wanted so standing grants and child_network select the mediated route too. */
|
|
40
|
+
export function nativeCodexNeverNetworkProblem(spec) {
|
|
41
|
+
if (spec.target.id !== "codex" || !spec.neverPolicy || stage2Wanted(spec))
|
|
42
|
+
return null;
|
|
43
|
+
const route = nativeCodexShellRoute(spec);
|
|
44
|
+
const dangerous = route === "unconfined";
|
|
45
|
+
const shellNetwork = dangerous || (networkOn(spec.config, spec.grant) && (spec.access === "write" || spec.config.codex_backend !== "exec"));
|
|
46
|
+
const entry = shellNetwork ? nativeCodexNeverNetworkEntry(spec.neverPolicy, route) : null;
|
|
47
|
+
if (!entry)
|
|
48
|
+
return null;
|
|
49
|
+
// Strict network enforces what local mode or a sandbox-less turn cannot: say so where it would.
|
|
50
|
+
const strictHolds = route !== "strict" && !nativeCodexNeverNetworkEntry(spec.neverPolicy, "strict");
|
|
51
|
+
const opened = route === "local" ? "grant.local_network, which opens this Mac's loopback and local network" : "allow_dangerous, which runs the turn without a sandbox";
|
|
52
|
+
return `never ${entry}: native Codex with shell network cannot enforce this network entry${route === "strict" ? "" : ` under ${opened}`}. Remove the network grant (start a new job without it if the grant is kept)${spec.config.child_network ? ", disable child_network" : ""}${dangerous ? ", disable allow_dangerous" : ""}${route === "local" ? ", or give it without local_network" : ""}${stage2Enabled(process.env, spec.config) ? '; or use the stage-2 mediated route with codex_backend "app-server"' : ""}.${strictHolds ? " Strict shell network enforces it, since it reaches none of this Mac's addresses." : ""}`;
|
|
53
|
+
}
|
|
54
|
+
/** Always screen the captured floor; experimental harness-variant qualification is opt-in. */
|
|
55
|
+
export function neverAdapterProblem(spec) {
|
|
56
|
+
const p = spec.neverPolicy;
|
|
57
|
+
if (stage2Enabled(process.env, spec.config) && spec.target.id === "codex" && spec.access === "write"
|
|
58
|
+
&& spec.config.allow_dangerous && !stage2Wanted(spec)) {
|
|
59
|
+
return "never: Codex allow_dangerous would run this write turn without stage-2 confinement. Disable allow_dangerous or select the qualified stage-2 app-server route.";
|
|
60
|
+
}
|
|
61
|
+
if (!p)
|
|
62
|
+
return null; // Registry launches always supply the checkpoint.
|
|
63
|
+
const problem = neverIdentityProblem(p) ?? neverGrantProblem(p, spec.grant ?? {}, spec.access === "write" ? [spec.cwd] : []) ?? nativeCodexNeverNetworkProblem(spec);
|
|
64
|
+
if (problem)
|
|
65
|
+
return problem;
|
|
66
|
+
// Variant gates apply only where the floor binds the target (core/never-coverage.ts): experimental
|
|
67
|
+
// adapter qualification must not retire released harness variants that run without it.
|
|
68
|
+
// Identity, grant and unenforceable native network checks remain unconditional.
|
|
69
|
+
if (!neverFloorApplies(spec.target.id, spec.config))
|
|
70
|
+
return null;
|
|
71
|
+
// Stage-2 Codex grants use the mediated provider; stage2Wanted also selects unqualified
|
|
72
|
+
// network-on variants so launch refuses rather than falling back to native strict.
|
|
73
|
+
const conflict = NEVER_FLOOR_CONFLICT[spec.target.id];
|
|
74
|
+
if (conflict)
|
|
75
|
+
return conflict;
|
|
76
|
+
if (spec.target.id === "claude") {
|
|
77
|
+
if (spec.config.allow_dangerous && spec.access === "write")
|
|
78
|
+
return "never: Claude's unsandboxed full-access variant bypasses the floor. Disable allow_dangerous for this turn.";
|
|
79
|
+
if (claudeFloorVariants({ ...spec.config, allow_dangerous: false }).length)
|
|
80
|
+
return "never: inherited Claude settings, hooks or MCP tools can bypass the checked sandbox/tool route. Use child_settings isolated, child_hooks false and child_mcp relay-only.";
|
|
81
|
+
}
|
|
82
|
+
if (spec.target.id === "gemini" && !neverProxyInputs(p).rawAllowed && (spec.grant?.network || spec.config.child_network))
|
|
83
|
+
return "never.hosts disables raw network: Gemini's current network-on route is unmediated. Use its network-off proxy route or a qualified mediated stage2 overlay.";
|
|
84
|
+
return null;
|
|
85
|
+
}
|
|
86
|
+
export function assertNeverAdapter(spec) {
|
|
87
|
+
const problem = neverAdapterProblem(spec);
|
|
88
|
+
if (problem)
|
|
89
|
+
throw new Error(problem);
|
|
90
|
+
}
|