@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,246 @@
|
|
|
1
|
+
// GitHub Copilot CLI over ACP: its profile for the generic driver (acp.ts). What this says about
|
|
2
|
+
// Copilot comes from its documentation and the 1.0.98 package (docs.github.com Copilot CLI
|
|
3
|
+
// reference, ACP server and configuration pages; the bundled CLI), checked in signed-in runs on
|
|
4
|
+
// 2026-10-17 (docs/qualification/copilot-1.0.98.md); what those runs could not settle is marked
|
|
5
|
+
// "unverified".
|
|
6
|
+
import fs from "node:fs";
|
|
7
|
+
import os from "node:os";
|
|
8
|
+
import path from "node:path";
|
|
9
|
+
import { harnessHome } from "../core/config.js";
|
|
10
|
+
import { acpBackend, genericApproval } from "./acp.js";
|
|
11
|
+
import { targetLabel } from "../targets/index.js";
|
|
12
|
+
/** Copilot's default ACP mode: ordinary prompting. Its modes are URLs. */
|
|
13
|
+
const COPILOT_AGENT_MODE = "https://agentclientprotocol.com/protocol/session-modes#agent";
|
|
14
|
+
/** Copilot's built-in subagents, which run models of their own choosing (explore, research, task; rubber-duck picks the other family on purpose). */
|
|
15
|
+
const SUBAGENTS = ["explore", "research", "task", "rubber-duck", "code-review", "general-purpose"];
|
|
16
|
+
/**
|
|
17
|
+
* Tools that start or drive Copilot's subagents and background agents, which run models of their
|
|
18
|
+
* own choosing: taken away from the model (--excluded-tools, which 1.0.98 applies over ACP). `task`
|
|
19
|
+
* from its documentation; the rest are what a signed-in 1.0.98 session listed as its tools.
|
|
20
|
+
*/
|
|
21
|
+
export const SUBAGENT_TOOLS = ["task", "search_code_subagent", "run_dynamic_workflow", "dynamic_workflows_manage", "read_agent", "list_agents", "write_agent"];
|
|
22
|
+
/** The project directories of Claude Code's skills, agents and commands, which Copilot would otherwise load. */
|
|
23
|
+
const CLAUDE_DIRS = [".claude/skills", ".claude/agents", ".claude/commands"];
|
|
24
|
+
/** Where the user's own Copilot state is, from the worker's environment (relay replaces it in Copilot's). */
|
|
25
|
+
const userHome = () => process.env.COPILOT_HOME || path.join(os.homedir(), ".copilot");
|
|
26
|
+
/**
|
|
27
|
+
* The Copilot home a session runs with: one per relay session, under relay's harness directory,
|
|
28
|
+
* outside its control directory. It is relay's, and read-only to the agent; only two directories
|
|
29
|
+
* in it are writable:
|
|
30
|
+
*
|
|
31
|
+
* - `session-state/`: Copilot's sessions, the one thing kept from turn to turn, since resuming
|
|
32
|
+
* needs it. Relay makes it, and refuses to run on it if it is anything but a plain directory (an
|
|
33
|
+
* agent could otherwise swap in a link that the next turn's sandbox would follow and open).
|
|
34
|
+
* - `turn/`: logs and caches for this turn only (`logs` in the home links there), removed with it.
|
|
35
|
+
*
|
|
36
|
+
* Before every turn relay rebuilds the rest: its own settings file (Copilot's sandbox off, since it
|
|
37
|
+
* would nest inside relay's; hooks off; skill, agent and command directories of Claude Code
|
|
38
|
+
* ignored, by absolute path, since 1.0.98 ignores relative entries; subagents, which run other
|
|
39
|
+
* models, off; no switch to automatic model choice) and a link named config.json to the user's
|
|
40
|
+
* own, through which Copilot finds its stored login. Relay never opens that file (GitHub documents
|
|
41
|
+
* that it can hold a token in plain text); the link only lets Copilot read it, as it could anyway,
|
|
42
|
+
* and the sandbox keeps it unwritable. Nothing else of the user's Copilot configuration comes
|
|
43
|
+
* along: no MCP servers, saved approvals or hooks.
|
|
44
|
+
*
|
|
45
|
+
* Seen in signed-in runs (1.0.98): Copilot reads every key of this settings file (`copilot config
|
|
46
|
+
* --list` under this home shows each, with no problems), finds its keychain login through the
|
|
47
|
+
* linked config.json (reading the item with /usr/bin/security), and tries to write two things in
|
|
48
|
+
* the home outside the writable directories, both refused and neither needed: a new config.json
|
|
49
|
+
* (to record the last logged-in user) and an `installed-plugins` directory. Without a stored login
|
|
50
|
+
* it cannot start in this read-only home at all (it exits before ACP's initialize).
|
|
51
|
+
*
|
|
52
|
+
* The home is given to relay's sandbox as relay-owned persistent state (src/confine,
|
|
53
|
+
* `HarnessState.persistent`): read-only but for `session-state/` and `turn/`, and checked again by the
|
|
54
|
+
* sandbox layer before every turn, so a link in place of either stops the turn there too. HOME stays
|
|
55
|
+
* the person's own (read-only): the keychain, where Copilot's login is, finds its search list
|
|
56
|
+
* through HOME, so a temporary HOME would hide the login keychain.
|
|
57
|
+
*/
|
|
58
|
+
export function copilotState(spec) {
|
|
59
|
+
const home = path.join(harnessHome(), spec.markers.runId, spec.markers.nodeId, "copilot");
|
|
60
|
+
fs.mkdirSync(home, { recursive: true, mode: 0o700 });
|
|
61
|
+
fs.chmodSync(home, 0o700);
|
|
62
|
+
const sessions = path.join(home, "session-state");
|
|
63
|
+
const kept = fs.lstatSync(sessions, { throwIfNoEntry: false });
|
|
64
|
+
if (kept && (kept.isSymbolicLink() || !kept.isDirectory())) {
|
|
65
|
+
throw new Error(`${targetLabel(spec.target)}'s session state 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.`);
|
|
66
|
+
}
|
|
67
|
+
for (const name of fs.readdirSync(home))
|
|
68
|
+
if (name !== "session-state")
|
|
69
|
+
fs.rmSync(path.join(home, name), { recursive: true, force: true });
|
|
70
|
+
fs.mkdirSync(sessions, { recursive: true, mode: 0o700 });
|
|
71
|
+
const turn = path.join(home, "turn");
|
|
72
|
+
fs.mkdirSync(path.join(turn, "logs"), { recursive: true, mode: 0o700 });
|
|
73
|
+
fs.mkdirSync(path.join(turn, "cache"), { recursive: true });
|
|
74
|
+
fs.symlinkSync(path.join(turn, "logs"), path.join(home, "logs"));
|
|
75
|
+
// Absolute paths: 1.0.98 ignores relative entries (`copilot skill list` still listed a skill in
|
|
76
|
+
// .claude/skills with them; it did not with the same directory named in full).
|
|
77
|
+
const roots = [...new Set([path.resolve(spec.cwd), repoRoot(spec.cwd)].filter((d) => d !== null))];
|
|
78
|
+
const settings = {
|
|
79
|
+
sandbox: { enabled: false },
|
|
80
|
+
disableAllHooks: true,
|
|
81
|
+
ignoredSkillsLocations: roots.flatMap((r) => CLAUDE_DIRS.map((d) => path.join(r, d))),
|
|
82
|
+
subagents: { disabledSubagents: SUBAGENTS },
|
|
83
|
+
continueOnAutoMode: false,
|
|
84
|
+
autoUpdate: false,
|
|
85
|
+
};
|
|
86
|
+
fs.writeFileSync(path.join(home, "settings.json"), JSON.stringify(settings, null, 2), { mode: 0o600 });
|
|
87
|
+
// A link, not a copy: relay does not read the user's Copilot config. Without one, Copilot reports that it is not signed in, and relay says so.
|
|
88
|
+
const user = path.join(userHome(), "config.json");
|
|
89
|
+
if (fs.lstatSync(user, { throwIfNoEntry: false }))
|
|
90
|
+
fs.symlinkSync(user, path.join(home, "config.json"));
|
|
91
|
+
return {
|
|
92
|
+
stateDirs: [],
|
|
93
|
+
persistent: { root: home, writable: ["session-state", "turn"] },
|
|
94
|
+
home: "real",
|
|
95
|
+
env: { COPILOT_HOME: home, COPILOT_CACHE_HOME: path.join(turn, "cache"), COPILOT_AUTO_UPDATE: "false" },
|
|
96
|
+
// The stored login's token is in the keychain (service "copilot-cli"), which Copilot reads
|
|
97
|
+
// through /usr/bin/security: a stated downgrade.
|
|
98
|
+
keychain: true,
|
|
99
|
+
// Copilot's Rust core checks certificates through the system (trustd); without the daemons it
|
|
100
|
+
// cannot verify GitHub's (seen 2026-10-17: "failed to copy trust settings", then no login). A
|
|
101
|
+
// stated downgrade: they fetch from URLs their caller supplies.
|
|
102
|
+
certificateTrust: true,
|
|
103
|
+
cleanup: () => fs.rmSync(turn, { recursive: true, force: true }),
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
/** The repository root above a directory, or null. */
|
|
107
|
+
function repoRoot(dir) {
|
|
108
|
+
for (let d = path.resolve(dir);; d = path.dirname(d)) {
|
|
109
|
+
if (fs.existsSync(path.join(d, ".git")))
|
|
110
|
+
return d;
|
|
111
|
+
if (path.dirname(d) === d)
|
|
112
|
+
return null;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* The title of Copilot's own check of a path outside the directories it trusts, as 1.0.98 sends it
|
|
117
|
+
* over ACP (session/request_permission). Seen in a signed-in run (2026-10-17, j_a7963b11) for an
|
|
118
|
+
* `apply_patch` that added a file outside the worktree: announced first as a tool call of kind
|
|
119
|
+
* "edit" (its raw input the patch), then this request under the same tool call id, of kind "read"
|
|
120
|
+
* whatever the call would do, with the path in `rawInput.path` and in `locations`, offering
|
|
121
|
+
* allow_once, allow_always and reject_once. `--allow-all-tools` covers Copilot's tools, not its
|
|
122
|
+
* paths: GitHub documents the path check as separate, for shell commands, file operations and search
|
|
123
|
+
* tools, turned off by `--allow-all-paths` (docs.github.com, configuring Copilot CLI and its command
|
|
124
|
+
* reference, read 2026-10-21), which relay does not pass. So under relay's flags these are the
|
|
125
|
+
* requests Copilot sends. Signed in on 2026-10-23 (the record's "Check 7 signed in"): its file viewer
|
|
126
|
+
* and file finder send the same request (announced as "read"), and so does its grep (announced as
|
|
127
|
+
* "other"); in those runs a call touching several paths asked once per path, in turn, not several
|
|
128
|
+
* in one request, and shell commands sent none, whatever paths they named; once allowed, Copilot
|
|
129
|
+
* went on and relay's sandbox decided; and once refused, Copilot ended its turn with no reply.
|
|
130
|
+
*/
|
|
131
|
+
export const PATH_CHECK_TITLE = "Access paths outside trusted directories";
|
|
132
|
+
/** The kinds of tool call that change files (ACP's edit, delete and move). */
|
|
133
|
+
const WRITES = new Set(["edit", "delete", "move"]);
|
|
134
|
+
/**
|
|
135
|
+
* Whether a path check is for reading or writing, from the tool call it is about: its request says
|
|
136
|
+
* "read" either way. Writing when the call announced, or the request, is a change; reading when the
|
|
137
|
+
* call announced is a read (Copilot's file viewer and file finder); otherwise relay cannot tell (a
|
|
138
|
+
* command, a search, or no call announced), which is taken as writing where that matters.
|
|
139
|
+
*/
|
|
140
|
+
function pathAccess(call, announced) {
|
|
141
|
+
if (WRITES.has(String(call.kind)) || WRITES.has(String(announced?.kind)))
|
|
142
|
+
return "write";
|
|
143
|
+
return announced?.kind === "read" ? "read" : "read or write";
|
|
144
|
+
}
|
|
145
|
+
/** The deepest directory holding every path (a path holds itself): one path is shown as it is. */
|
|
146
|
+
function commonDir(paths) {
|
|
147
|
+
let dir = paths[0];
|
|
148
|
+
while (!paths.every((p) => p === dir || p.startsWith(dir.endsWith(path.sep) ? dir : dir + path.sep)))
|
|
149
|
+
dir = path.dirname(dir);
|
|
150
|
+
return dir;
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Copilot's check of a path outside its trusted directories, as an approval request of kind "path":
|
|
154
|
+
* what it carries (the path, resolved against the agent's directory) and what relay can tell of the
|
|
155
|
+
* access (pathAccess). The person sees the access and the path as `wants` ("write /x/y.txt"), the
|
|
156
|
+
* path as `in_directory`, and an effect that says allowing it lets Copilot proceed while relay's
|
|
157
|
+
* sandbox still decides what it can touch. Null, so refused unasked, when it names no path.
|
|
158
|
+
*/
|
|
159
|
+
export function copilotPathCheck(call, spec, announced) {
|
|
160
|
+
const input = call.rawInput && typeof call.rawInput === "object" && !Array.isArray(call.rawInput) ? call.rawInput : {};
|
|
161
|
+
const named = [input.path, ...(Array.isArray(input.paths) ? input.paths : []), ...(call.locations ?? []).map((l) => l?.path)];
|
|
162
|
+
const paths = [...new Set(named.filter((p) => typeof p === "string" && p.trim() !== "").map((p) => path.resolve(spec.cwd, p)))];
|
|
163
|
+
if (!paths.length)
|
|
164
|
+
return null;
|
|
165
|
+
const access = pathAccess(call, announced);
|
|
166
|
+
const command = announced?.kind === "execute" && announced.rawInput && typeof announced.rawInput === "object" ? announced.rawInput.command : undefined;
|
|
167
|
+
const title = typeof announced?.title === "string" && announced.title.trim() ? announced.title : undefined;
|
|
168
|
+
const about = typeof command === "string" && command.trim() ? `its command: ${command}`
|
|
169
|
+
: title ? `its tool call: ${title}${announced?.kind ? ` (${announced.kind})` : ""}`
|
|
170
|
+
: "a tool call it did not describe";
|
|
171
|
+
return {
|
|
172
|
+
kind: "path",
|
|
173
|
+
summary: `${access} ${paths.join(", ")}`,
|
|
174
|
+
reason: `Copilot's own check of paths outside its trusted directories, for ${about}`,
|
|
175
|
+
paths,
|
|
176
|
+
// Whatever is approved, relay's sandbox stays on and unchanged: say so to whoever decides.
|
|
177
|
+
detail: { cwd: commonDir(paths), path_access: access, tool_call: call.toolCallId, ...(announced?.kind ? { announced_kind: announced.kind } : {}), confined: true },
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
export const copilotProfile = {
|
|
181
|
+
args: (spec, model) => [
|
|
182
|
+
// stdio is the default transport; --stdio says so.
|
|
183
|
+
"--acp", "--stdio",
|
|
184
|
+
// Runs the version that was launched, not a newer one it downloaded earlier.
|
|
185
|
+
"--no-auto-update",
|
|
186
|
+
// Its own sandbox would nest inside relay's. Off by default; this flag is not applied on the
|
|
187
|
+
// ACP path (1.0.98), so the settings file above turns it off too.
|
|
188
|
+
"--no-sandbox",
|
|
189
|
+
// The built-in GitHub MCP server would act with the user's GitHub token.
|
|
190
|
+
"--disable-builtin-mcps",
|
|
191
|
+
// Not applied on the ACP path either (1.0.98), so instructions files in the repository
|
|
192
|
+
// (AGENTS.md, CLAUDE.md, .claude/rules) still load: they are the project's, as for Codex.
|
|
193
|
+
"--no-custom-instructions",
|
|
194
|
+
// Tools that start subagents, which run other models (the settings file disables the
|
|
195
|
+
// subagents as well). Applied over ACP: Copilot says so in a notice ("Info: Disabled tools").
|
|
196
|
+
`--excluded-tools=${SUBAGENT_TOOLS.join(",")}`,
|
|
197
|
+
// Relay's sandbox is the boundary, and nothing approved lifts it (no escalation through relay's
|
|
198
|
+
// sandbox in 1.0), so Copilot runs in its most permissive mode that persists nothing: allowed
|
|
199
|
+
// for this process only, never saved. Its own check of paths outside its trusted directories
|
|
200
|
+
// still asks (relay does not pass --allow-all-paths), and relay puts those requests to the root
|
|
201
|
+
// (copilotPathCheck), its sandbox unchanged whatever is decided.
|
|
202
|
+
"--allow-all-tools",
|
|
203
|
+
// Applies to every session of this process; the session's reported model is checked against it.
|
|
204
|
+
...(model ? ["--model", model] : []),
|
|
205
|
+
// Copilot's documented reasoning-effort flag. A process per turn, so a resumed session gets it
|
|
206
|
+
// too. Unverified that the ACP server applies it (its own ACP option for this is thought_level).
|
|
207
|
+
...(spec.effort ? ["--reasoning-effort", spec.effort] : []),
|
|
208
|
+
],
|
|
209
|
+
// Every Copilot variable is relay's to set (COPILOT_ALLOW_ALL=true, say, would trust the
|
|
210
|
+
// directory and load its hooks and MCP servers). Its token is handled with the credentials.
|
|
211
|
+
scrub: (k) => /^(COPILOT_|GITHUB_COPILOT_)/.test(k) && k !== "COPILOT_GITHUB_TOKEN",
|
|
212
|
+
prepareState: copilotState,
|
|
213
|
+
login: {
|
|
214
|
+
// Copilot's ACP server offers "copilot-login", which succeeds only when already signed in
|
|
215
|
+
// (changelog 1.0.69) and does not start a login. Unverified at runtime.
|
|
216
|
+
reuse: ["copilot-login"],
|
|
217
|
+
how: "Sign in with `copilot login`. Relay uses Copilot's stored login and removes COPILOT_GITHUB_TOKEN, GH_TOKEN and GITHUB_TOKEN from its environment, since they would silently take its place.",
|
|
218
|
+
},
|
|
219
|
+
mode: () => COPILOT_AGENT_MODE,
|
|
220
|
+
normalizeApproval(call, spec, announced) {
|
|
221
|
+
// Its own check of a path outside its trusted directories, under --allow-all-tools its only request.
|
|
222
|
+
if (call.title === PATH_CHECK_TITLE)
|
|
223
|
+
return copilotPathCheck(call, spec, announced);
|
|
224
|
+
const ask = genericApproval(call);
|
|
225
|
+
if (!ask)
|
|
226
|
+
return null;
|
|
227
|
+
// The directory the command would run in, as the agent gave it (relative to its own), else its own.
|
|
228
|
+
const detail = (ask.detail ?? {});
|
|
229
|
+
const cwd = path.resolve(spec.cwd, typeof detail.cwd === "string" ? detail.cwd : ".");
|
|
230
|
+
const paths = ask.paths?.map((p) => path.resolve(cwd, p));
|
|
231
|
+
// Whatever is approved, relay's sandbox stays on: say so to whoever decides.
|
|
232
|
+
return { ...ask, ...(paths ? { paths } : {}), detail: { ...detail, cwd, confined: true } };
|
|
233
|
+
},
|
|
234
|
+
// Copilot says which tools --excluded-tools took away, as a message chunk of its own ahead of the
|
|
235
|
+
// reply (1.0.98: "Info: Disabled tools: task"); it is not the agent's answer.
|
|
236
|
+
notice: (text) => /^Info: Disabled tools: [\w, .-]+$/.test(text),
|
|
237
|
+
refuse(spec) {
|
|
238
|
+
// A repository can make Copilot fall back to another model than the one asked for.
|
|
239
|
+
const root = repoRoot(spec.cwd);
|
|
240
|
+
if ((spec.config.same_family === "refuse" || (spec.model && spec.model !== spec.target.autoModel)) && root && fs.existsSync(path.join(root, ".github", "allowed_models.txt"))) {
|
|
241
|
+
return `the repository has .github/allowed_models.txt, which can make ${targetLabel(spec.target)} fall back to another model than the one relay asked for, so relay cannot tell which family would answer. It does not run it here.`;
|
|
242
|
+
}
|
|
243
|
+
return null;
|
|
244
|
+
},
|
|
245
|
+
};
|
|
246
|
+
export const copilotBackend = acpBackend(copilotProfile);
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
// The environment a launched agent gets: relay's own variables set afresh, credentials removed as
|
|
2
|
+
// the target signs in, the host session's own variables kept out, and an endpoint that would send
|
|
3
|
+
// the CLI elsewhere refused. Built once per turn, checked, in the backend's prepare (agentEnv).
|
|
4
|
+
import { authFor, relayHome, worktreesHome } from "../core/config.js";
|
|
5
|
+
import { CREDENTIALS, TARGETS, targetDef, targetLabel } from "../targets/index.js";
|
|
6
|
+
import { backendEnvironmentRoots, capturedRootEnvironment, effectiveChildEnv, mandatoryEnvironmentReason, selectEnvironment } from "../core/env-policy.js";
|
|
7
|
+
import { registerReleasedEnvironment } from "../core/secrets.js";
|
|
8
|
+
/**
|
|
9
|
+
* The credential variables removed from a target's environment, or null for none.
|
|
10
|
+
* - Signing in with its login (child_auth "login", the default): every vendor's credentials,
|
|
11
|
+
* its own included, so that the CLI uses its stored login and no agent is handed another
|
|
12
|
+
* vendor's keys.
|
|
13
|
+
* - child_auth "any", global or target-local: every other vendor's credentials; only its own
|
|
14
|
+
* may pass, and still require selection by child_env. The old global exception ended in 1.0.
|
|
15
|
+
*/
|
|
16
|
+
export function scrubbedCredentials(target, config) {
|
|
17
|
+
const own = config.targets[target]?.child_auth;
|
|
18
|
+
if ((own ?? config.child_auth) === "login")
|
|
19
|
+
return CREDENTIALS;
|
|
20
|
+
// Another family's target, or one whose family is per model (not this target's own family either way).
|
|
21
|
+
const def = targetDef(target);
|
|
22
|
+
const others = TARGETS.filter((t) => t.id !== target && (t.vendor === null || def.vendor === null || t.vendor !== def.vendor));
|
|
23
|
+
return others.length ? new RegExp(others.map((t) => `(?:${t.credentialEnv.source})`).join("|")) : null;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* What Claude Code's desktop app and other Agent SDK hosts put in the environment of the MCP
|
|
27
|
+
* servers they start, relay's included: markers that say such a host is running, and the endpoint
|
|
28
|
+
* of the host's own session (ANTHROPIC_BASE_URL), which is the host's connection, not the user's
|
|
29
|
+
* choice of endpoint for agents relay launches (experiments/answers.md, Claude desktop app).
|
|
30
|
+
*/
|
|
31
|
+
const HOST_SESSION_MARKERS = ["CLAUDE_CODE_DESKTOP_APP_VERSION", "CLAUDE_AGENT_SDK_VERSION"];
|
|
32
|
+
/** Whether relay runs under the Claude desktop app or another Agent SDK host (an empty marker does not count). */
|
|
33
|
+
export const hostSession = (env = capturedRootEnvironment) => HOST_SESSION_MARKERS.some((m) => Boolean(env[m]));
|
|
34
|
+
/**
|
|
35
|
+
* Whether `key` belongs to the host session relay runs in and is kept from every launched agent:
|
|
36
|
+
* the markers always, and Anthropic's endpoint variables when relay runs under such a host and
|
|
37
|
+
* Claude signs in with its login ("child_auth" "login" for Claude). Under that setting the
|
|
38
|
+
* credentials that go with an endpoint are removed too, so the agent goes to Anthropic on its own
|
|
39
|
+
* login, which the init check verifies along with the model. Where Claude may sign in with a key,
|
|
40
|
+
* removing the endpoint would send the key meant for it to Anthropic (or to a nested agent that
|
|
41
|
+
* would), so the endpoint stays and Claude's endpoint check refuses it, as it does without a host:
|
|
42
|
+
* there the person set the variable, and relay does not quietly undo that.
|
|
43
|
+
*/
|
|
44
|
+
function hostSessionVariable(key, config, env = capturedRootEnvironment) {
|
|
45
|
+
// Codex lets an embedding app override clientInfo's originator with this variable. A relay
|
|
46
|
+
// child must identify as relay, not inherit the root's T3 identity (or another app's).
|
|
47
|
+
if (key === "CODEX_INTERNAL_ORIGINATOR_OVERRIDE")
|
|
48
|
+
return true;
|
|
49
|
+
if (HOST_SESSION_MARKERS.includes(key))
|
|
50
|
+
return true;
|
|
51
|
+
return hostSession(env) && authFor(config, "claude") === "login" && targetDef("claude").endpointEnv.test(key);
|
|
52
|
+
}
|
|
53
|
+
/** The released names each environment childEnv built actually carries, by that environment. */
|
|
54
|
+
const releasedNames = new WeakMap();
|
|
55
|
+
/**
|
|
56
|
+
* The names relay released to a turn (a standing child_env.pass, a person-approved grant.env) that
|
|
57
|
+
* the agent environment childEnv (or agentEnv) built for it carries, sorted: names only. Empty for
|
|
58
|
+
* an environment childEnv did not build. A backend reads it straight after building the
|
|
59
|
+
* environment, for a note about what the harness then does with those names (codex-shell-policy.ts).
|
|
60
|
+
*/
|
|
61
|
+
export function releasedIn(env) {
|
|
62
|
+
return releasedNames.get(env) ?? [];
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Environment for the agent process. Credentials are removed as scrubbedCredentials says, and the
|
|
66
|
+
* host session's own variables as hostSessionVariable says; the backend removes what identifies
|
|
67
|
+
* the parent session. Relay's own variables are set afresh.
|
|
68
|
+
*/
|
|
69
|
+
export function childEnv(spec, scrub) {
|
|
70
|
+
const env = {};
|
|
71
|
+
/** What the loop below copied from the selection: a released name is delivered only if it was. */
|
|
72
|
+
const copied = new Set();
|
|
73
|
+
const selected = spec.environment !== undefined ? { env: spec.environment, releasedNames: spec.environmentReleased ?? effectiveChildEnv(spec.config, spec.target.id).pass } : selectEnvironment(spec.target.id, spec.config, capturedRootEnvironment);
|
|
74
|
+
const credentials = scrubbedCredentials(spec.target.id, spec.config);
|
|
75
|
+
// What else would take the place of this target's stored login, when it signs in with that login.
|
|
76
|
+
const login = authFor(spec.config, spec.target.id) === "login" ? spec.target.loginEnv : undefined;
|
|
77
|
+
for (const [k, v] of Object.entries(selected.env)) {
|
|
78
|
+
if (v === undefined)
|
|
79
|
+
continue;
|
|
80
|
+
if (mandatoryEnvironmentReason(spec.target.id, spec.config, k, capturedRootEnvironment))
|
|
81
|
+
continue;
|
|
82
|
+
if (k.startsWith("RELAY_") && k !== "RELAY_CONFIG")
|
|
83
|
+
continue;
|
|
84
|
+
if (credentials?.test(k))
|
|
85
|
+
continue;
|
|
86
|
+
if (hostSessionVariable(k, spec.config))
|
|
87
|
+
continue;
|
|
88
|
+
// Another family's CLI needs none of Claude's session/launch variables. Keep its config
|
|
89
|
+
// directory (nested Claude turns need the user's deny rules), but no parent identity or mode.
|
|
90
|
+
// Claude's own backend handles its auth/provider exceptions when Claude is the child.
|
|
91
|
+
if (spec.target.id !== "claude" && (k === "CLAUDECODE" || k.startsWith("CLAUDE_CODE_")))
|
|
92
|
+
continue;
|
|
93
|
+
// The root session's inbox, so that an agent does not find it by inheritance. Not a gate: on
|
|
94
|
+
// macOS the token is optional, and a session that prompts for permissions takes an unverified
|
|
95
|
+
// message from any process of the user's that reaches the socket (answers.md P-d).
|
|
96
|
+
if (k === "CLAUDE_CODE_MESSAGING_SOCKET" || k === "CLAUDE_CODE_MESSAGING_TOKEN")
|
|
97
|
+
continue;
|
|
98
|
+
if (login?.test(k))
|
|
99
|
+
continue;
|
|
100
|
+
if (scrub(k))
|
|
101
|
+
continue;
|
|
102
|
+
env[k] = v;
|
|
103
|
+
copied.add(k);
|
|
104
|
+
}
|
|
105
|
+
registerReleasedEnvironment(env, selected.releasedNames);
|
|
106
|
+
// Relay's own variables, set below, are backend-owned and never released (mandatoryEnvironmentReason).
|
|
107
|
+
releasedNames.set(env, [...new Set(selected.releasedNames)].filter((n) => copied.has(n)).sort());
|
|
108
|
+
Object.assign(env, backendEnvironmentRoots(spec.target.id, spec.environment ?? capturedRootEnvironment));
|
|
109
|
+
// pnpm hard-links packages from its store into node_modules; relay refuses a write turn whose
|
|
110
|
+
// worktree holds a file linked to one outside it (src/confine/hardlinks.ts), so it copies instead.
|
|
111
|
+
// This is pnpm's own variable (pnpm_config_<kebab setting>), which pnpm reads from version 11 on;
|
|
112
|
+
// an older pnpm ignores it and keeps hard-linking, and its job's next write turn may then be refused
|
|
113
|
+
// by the hard-link check (pnpm 10 users can set package-import-method=copy in their own pnpm
|
|
114
|
+
// config). The npm_config_ form is npm's, which has no such setting.
|
|
115
|
+
env.pnpm_config_package_import_method = "copy";
|
|
116
|
+
env.RELAY_HOME = relayHome();
|
|
117
|
+
// Passed down so that a nested job's worktree lands where the root's does.
|
|
118
|
+
env.RELAY_WORKTREES = worktreesHome();
|
|
119
|
+
env.RELAY_RUN_ID = spec.markers.runId;
|
|
120
|
+
env.RELAY_NODE_ID = spec.markers.nodeId;
|
|
121
|
+
env.RELAY_DEPTH = String(spec.markers.depth);
|
|
122
|
+
return env;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Why a target must not be launched with this environment, or null: it carries a variable that
|
|
126
|
+
* points the CLI at another endpoint, so that relay could not tell which model family answers.
|
|
127
|
+
*/
|
|
128
|
+
export function endpointProblem(target, env) {
|
|
129
|
+
const def = targetDef(target);
|
|
130
|
+
const set = Object.keys(env).filter((k) => def.endpointEnv.test(k)).sort();
|
|
131
|
+
if (!set.length)
|
|
132
|
+
return null;
|
|
133
|
+
return `the environment relay would give ${targetLabel(def)} sets ${set.join(", ")}, which sends ${def.product} to another endpoint than its vendor's, where relay cannot tell which family of model answers. ` +
|
|
134
|
+
"Relay reaches other families only, so it does not launch it this way. Unset it in the environment relay runs in";
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* The agent's environment for a turn (childEnv), checked: it throws the endpoint problem, with
|
|
138
|
+
* `hint` after it, rather than return an environment relay must not launch with. A backend builds
|
|
139
|
+
* it once, first thing in its prepare, before its other refusals (review C6), and uses that one.
|
|
140
|
+
*/
|
|
141
|
+
export function agentEnv(spec, scrub, hint = "") {
|
|
142
|
+
const env = childEnv(spec, scrub);
|
|
143
|
+
const endpoint = endpointProblem(spec.target.id, env);
|
|
144
|
+
if (endpoint)
|
|
145
|
+
throw new Error(`${endpoint}.${hint}`);
|
|
146
|
+
return env;
|
|
147
|
+
}
|