@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,203 @@
|
|
|
1
|
+
// Host-only qualification: real Codex executor/app-server, production stage-2 admission,
|
|
2
|
+
// probes, proxy and teardown. All model/upstream traffic terminates at our owned listener.
|
|
3
|
+
import "./helpers.ts";
|
|
4
|
+
import assert from "node:assert/strict";
|
|
5
|
+
import { execFileSync } from "node:child_process";
|
|
6
|
+
import dgram from "node:dgram";
|
|
7
|
+
import fs from "node:fs";
|
|
8
|
+
import http from "node:http";
|
|
9
|
+
import net from "node:net";
|
|
10
|
+
import os from "node:os";
|
|
11
|
+
import path from "node:path";
|
|
12
|
+
import { test } from "node:test";
|
|
13
|
+
import { LiveScope } from "./live-scope.ts";
|
|
14
|
+
import { hostileWebCalls, assertHostileWebEvidence, modelStubRequestKind } from "./fixtures/stage2-hostile-web.mjs";
|
|
15
|
+
import { codexBackend } from "../dist/backends/codex.js";
|
|
16
|
+
import { setLeaseOptionsForTests } from "../dist/backends/codex-env.js";
|
|
17
|
+
import { setCodexHomeConfigForTests } from "../dist/backends/codex-pin.js";
|
|
18
|
+
import type { TurnSpec, TurnHandle, TurnResult } from "../dist/backends/types.js";
|
|
19
|
+
import { busyPorts } from "../dist/confine/ports.js";
|
|
20
|
+
import { openProxy } from "../dist/confine/proxy.js";
|
|
21
|
+
import { targetDef } from "../dist/targets/index.js";
|
|
22
|
+
import { withDefaults } from "../dist/core/config.js";
|
|
23
|
+
import { closeDbForTests, createRun, insertNode, insertTurn, updateTurn } from "../dist/core/db.js";
|
|
24
|
+
import { checkpointNever } from "../dist/core/never-checkpoint.js";
|
|
25
|
+
import { createMediatedNetworkProvider, setMediatedNetworkProviderForTests } from "../dist/core/mediated-network-provider.js";
|
|
26
|
+
import { executorRecords, sweepOrphanedExecutors } from "../dist/core/stage2-executors.js";
|
|
27
|
+
import { withTurnSecrets } from "../dist/core/secrets.js";
|
|
28
|
+
|
|
29
|
+
const skip = process.env.RELAY_TEST_STANDING_LIVE !== "1" ? "host only: RELAY_TEST_STANDING_LIVE=1"
|
|
30
|
+
: process.platform !== "darwin" ? "macOS only" : false;
|
|
31
|
+
const usage = { input_tokens: 0, input_tokens_details: null, output_tokens: 0, output_tokens_details: null, total_tokens: 0 };
|
|
32
|
+
|
|
33
|
+
const cases = [
|
|
34
|
+
...(["write", "read"] as const).flatMap(access => [false, true].map(childNetwork => ({ access, childNetwork, surface: "" }))),
|
|
35
|
+
...["direct", "code"].map(surface => ({ access: "write" as const, childNetwork: false, surface })),
|
|
36
|
+
];
|
|
37
|
+
for (const { access, childNetwork, surface } of cases) {
|
|
38
|
+
test(`${surface ? "hostile web live: " + surface : "standing mediated live: " + (childNetwork ? "child_network" : "grant.network") + " " + access} fresh and kept resume`, { skip, timeout: 180_000 }, async t => {
|
|
39
|
+
const scope = new LiveScope();
|
|
40
|
+
const abort = () => scope.controller.abort(new Error("standing live test cancelled"));
|
|
41
|
+
t.signal.addEventListener("abort", abort, { once: true });
|
|
42
|
+
const deadline = setTimeout(() => scope.controller.abort(new Error("standing live test deadline")), 150_000);
|
|
43
|
+
const home = fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(), "s2-standing-")));
|
|
44
|
+
const saved = { RELAY_HOME: process.env.RELAY_HOME, RELAY_CONFIG: process.env.RELAY_CONFIG };
|
|
45
|
+
const cwd = path.join(home, "work"), appHome = path.join(home, "app");
|
|
46
|
+
fs.mkdirSync(cwd); fs.mkdirSync(appHome);
|
|
47
|
+
process.env.RELAY_HOME = path.join(home, "registry"); process.env.RELAY_CONFIG = path.join(home, "config.json");
|
|
48
|
+
let epoch = 0, command = "", output = "", udpSeen = 0, upstreamRequests = 0, unexpectedRequests = 0, responsesWebSocketUpgrades = 0;
|
|
49
|
+
let hostile: any[] = [], bodies: any[] = [];
|
|
50
|
+
const hostileOutputs = new Map<string, string>();
|
|
51
|
+
const upstreamSockets = new Set<net.Socket>();
|
|
52
|
+
const model = http.createServer((req, res) => {
|
|
53
|
+
if (req.url === "/mediated-upstream" || req.url === "/mediated-hold") {
|
|
54
|
+
upstreamRequests++;
|
|
55
|
+
upstreamSockets.add(req.socket); req.socket.once("close", () => upstreamSockets.delete(req.socket));
|
|
56
|
+
if (req.url === "/mediated-upstream") res.end("MEDIATED_UPSTREAM_OK");
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
let raw = ""; req.on("data", b => raw += b);
|
|
60
|
+
req.on("end", () => {
|
|
61
|
+
const kind = modelStubRequestKind(req);
|
|
62
|
+
if (kind === "websocket") { responsesWebSocketUpgrades++; res.writeHead(404); res.end("{}"); return; }
|
|
63
|
+
if (kind === "unexpected") { unexpectedRequests++; res.writeHead(404); res.end("{}"); return; }
|
|
64
|
+
const body = JSON.parse(raw); bodies.push(body);
|
|
65
|
+
const id = `standing-${epoch}`;
|
|
66
|
+
const outputs = (body.input ?? []).filter((i: any) => /_call_output$/.test(i.type ?? ""));
|
|
67
|
+
for (let k = 0; k < hostile.length; k++) {
|
|
68
|
+
const got = outputs.find((i: any) => i.call_id === `hostile-${epoch}-${k}`);
|
|
69
|
+
if (got) hostileOutputs.set(got.call_id, typeof got.output === "string" ? got.output : JSON.stringify(got.output));
|
|
70
|
+
}
|
|
71
|
+
const next = hostile.findIndex((_, k) => !hostileOutputs.has(`hostile-${epoch}-${k}`));
|
|
72
|
+
const got = outputs.find((i: any) => i.call_id === id);
|
|
73
|
+
if (got) output = typeof got.output === "string" ? got.output : JSON.stringify(got.output);
|
|
74
|
+
const item = next >= 0 ? { ...hostile[next], call_id: `hostile-${epoch}-${next}` }
|
|
75
|
+
: got ? { type: "message", role: "assistant", content: [{ type: "output_text", text: "standing proxy checks complete" }] }
|
|
76
|
+
: { type: "function_call", name: "exec_command", call_id: id, arguments: JSON.stringify({ login: false, cmd: command, timeout_ms: 30000 }) };
|
|
77
|
+
const events = [{ type: "response.created", response: { id: `r-${id}` } },
|
|
78
|
+
{ type: "response.output_item.done", item: { ...item, id: `i-${id}` } },
|
|
79
|
+
{ type: "response.completed", response: { id: `r-${id}`, usage } }];
|
|
80
|
+
res.writeHead(200, { "content-type": "text/event-stream" });
|
|
81
|
+
res.end(events.map(e => `event: ${e.type}\ndata: ${JSON.stringify(e)}\n\n`).join(""));
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
const udp = dgram.createSocket("udp4"); udp.on("message", () => udpSeen++);
|
|
85
|
+
scope.defer(async () => {
|
|
86
|
+
for (const socket of upstreamSockets) socket.destroy(); model.closeAllConnections();
|
|
87
|
+
await new Promise<void>(ok => model.close(() => ok()));
|
|
88
|
+
}, -20);
|
|
89
|
+
try {
|
|
90
|
+
const bin = process.env.RELAY_TEST_CODEX ?? "/opt/homebrew/bin/codex";
|
|
91
|
+
assert.match(execFileSync(bin, ["--version"], { encoding: "utf8" }), /codex-cli/);
|
|
92
|
+
await scope.wait(new Promise<void>((ok, fail) => { model.once("error", fail); model.listen(0, "127.0.0.1", ok); }));
|
|
93
|
+
const port = (model.address() as net.AddressInfo).port;
|
|
94
|
+
assert.ok(port > 10000);
|
|
95
|
+
await scope.wait(new Promise<void>((ok, fail) => { udp.once("error", fail); udp.bind(port, "127.0.0.1", ok); }));
|
|
96
|
+
scope.defer(() => new Promise<void>(ok => udp.close(() => ok())), -20);
|
|
97
|
+
const gitEnv = { PATH: "/usr/bin:/bin:/opt/homebrew/bin", HOME: os.homedir(), GIT_CONFIG_NOSYSTEM: "1" };
|
|
98
|
+
const git = (...args: string[]) => execFileSync("git", ["-c", "user.name=relay test", "-c", "user.email=relay@test.invalid", ...args], { cwd, env: gitEnv, stdio: "pipe" });
|
|
99
|
+
git("init", "-q", "-b", "main"); fs.writeFileSync(path.join(cwd, "README.md"), "standing mediated fixture\n");
|
|
100
|
+
git("add", "README.md"); git("commit", "-qm", "fixture");
|
|
101
|
+
const script = path.join(cwd, "mediated-command.cjs");
|
|
102
|
+
fs.copyFileSync(path.join(import.meta.dirname, "fixtures/mediated-command.cjs"), script);
|
|
103
|
+
fs.copyFileSync(path.join(import.meta.dirname, "fixtures/stage2-catalog.json"), path.join(home, "catalog.json"));
|
|
104
|
+
if (surface === "direct") {
|
|
105
|
+
const catalog = JSON.parse(fs.readFileSync(path.join(home, "catalog.json"), "utf8"));
|
|
106
|
+
catalog.models[0].tool_mode = "direct";
|
|
107
|
+
fs.writeFileSync(path.join(home, "catalog.json"), JSON.stringify(catalog));
|
|
108
|
+
}
|
|
109
|
+
const appConfig = `cli_auth_credentials_store="file"\nmodel="mock-model"\nopenai_base_url="http://127.0.0.1:${port}/v1"\nmodel_catalog_json=${JSON.stringify(path.join(home, "catalog.json"))}\n`;
|
|
110
|
+
fs.writeFileSync(path.join(appHome, "config.toml"), appConfig);
|
|
111
|
+
fs.writeFileSync(path.join(appHome, "auth.json"), JSON.stringify({ OPENAI_API_KEY: "sk-owned-standing-model" }));
|
|
112
|
+
setCodexHomeConfigForTests(h => h === appHome ? appConfig : undefined);
|
|
113
|
+
let range: { first: number; count: number } | undefined;
|
|
114
|
+
for (let n = 0; n < 100; n++) {
|
|
115
|
+
const first = 50000 + 16 * Math.floor(Math.random() * 600);
|
|
116
|
+
if (!busyPorts(Array.from({ length: 16 }, (_, k) => first + k)).size) { range = { first, count: 16 }; break; }
|
|
117
|
+
}
|
|
118
|
+
assert.ok(range, "owned free executor range"); setLeaseOptionsForTests({ range });
|
|
119
|
+
// DNS is deterministic and entirely in-process. Redirect only the final, already screened
|
|
120
|
+
// public-IP dial to our owned upstream. The command process has no such fixture override.
|
|
121
|
+
const realConnect = net.connect;
|
|
122
|
+
t.mock.method(net, "connect", function(...args: any[]) {
|
|
123
|
+
const options = args[0];
|
|
124
|
+
if (options && typeof options === "object" && options.host === "8.8.8.8" && options.port === port)
|
|
125
|
+
return realConnect.call(net, { ...options, host: "127.0.0.1" }, ...args.slice(1));
|
|
126
|
+
return realConnect.apply(net, args as any);
|
|
127
|
+
});
|
|
128
|
+
setMediatedNetworkProviderForTests(createMediatedNetworkProvider({
|
|
129
|
+
lookup: async host => {
|
|
130
|
+
if (!["forbidden.test", "forbidden-alias.test", "owned-upstream.test"].includes(host)) throw new Error(`unexpected fixture DNS authority: ${host}`);
|
|
131
|
+
return { addresses: [host === "forbidden.test" || host === "forbidden-alias.test" ? "9.9.9.9" : "8.8.8.8"], cnames: host === "forbidden-alias.test" ? ["forbidden.test"] : [] };
|
|
132
|
+
},
|
|
133
|
+
open: async options => openProxy({ ...options, testing: { upstreamPort: port } }),
|
|
134
|
+
}));
|
|
135
|
+
const config = withDefaults({ codex_backend: "app-server", child_network: childNetwork, escalation: false,
|
|
136
|
+
child_auth: "any", codex_endpoint_override: "accept", child_mcp: "relay-only", cancel_grace_ms: 1000,
|
|
137
|
+
never: { hosts: ["forbidden.test"], ports: [{ port: 49444, destinations: "any" }] },
|
|
138
|
+
targets: { codex: { bin, stage2: true, home: appHome, pinned: false } } });
|
|
139
|
+
fs.writeFileSync(process.env.RELAY_CONFIG!, JSON.stringify(config));
|
|
140
|
+
const run = createRun(cwd, config, "standing-live-root"), nodeId = "j_standing";
|
|
141
|
+
const grant = childNetwork ? undefined : { network: true };
|
|
142
|
+
insertNode({ id: nodeId, run_id: run, kind: "job", target: "codex", mode: access, depth: 1, task: "owned standing mediated test", cwd, status: "running", params_json: JSON.stringify({ grant }) });
|
|
143
|
+
let sessionId: string | undefined;
|
|
144
|
+
const proxyPorts: number[] = [];
|
|
145
|
+
for (const resumed of [false, true]) {
|
|
146
|
+
epoch++; output = ""; bodies = []; hostileOutputs.clear();
|
|
147
|
+
hostile = surface ? hostileWebCalls(surface, `http://forbidden.test:${port}/owned-never-page`) : [];
|
|
148
|
+
command = `${JSON.stringify(process.execPath)} ${JSON.stringify(script)} ${port} standing "$TMPDIR/standing-held-${epoch}"`;
|
|
149
|
+
const notes: string[] = [];
|
|
150
|
+
const turnId = insertTurn(nodeId, "test", resumed ? "kept resume" : "fresh", access, "running");
|
|
151
|
+
updateTurn(turnId, { grant_json: grant ? JSON.stringify(grant) : null });
|
|
152
|
+
const spec: TurnSpec = { target: targetDef("codex"), config, cwd, access, grant, sessionId,
|
|
153
|
+
prompt: `standing mediated epoch ${epoch}`, dir: home, logPath: path.join(home, `turn-${epoch}.log`), relay: null,
|
|
154
|
+
markers: { runId: run, nodeId, depth: 1 }, turnId, neverPolicy: checkpointNever(run, "launch"),
|
|
155
|
+
environment: { PATH: "/usr/bin:/bin:/usr/sbin:/sbin", HOME: os.homedir(), CODEX_HOME: appHome, SHELL: "/bin/zsh" },
|
|
156
|
+
signal: scope.signal, onNote: note => notes.push(note), onApproval: async () => { throw new Error("standing grant must need no escalation"); } };
|
|
157
|
+
let handle: TurnHandle | undefined, result: TurnResult | undefined;
|
|
158
|
+
await withTurnSecrets(async () => {
|
|
159
|
+
const starting = codexBackend.start(spec);
|
|
160
|
+
const stop = scope.defer(async () => { const h = await starting.catch(() => null); if (h) { if (!result) await h.cancel(); await h.done; } }, 10);
|
|
161
|
+
try { handle = await scope.wait(starting); result = await scope.wait(handle.done); }
|
|
162
|
+
finally { await stop(); }
|
|
163
|
+
});
|
|
164
|
+
updateTurn(turnId, { status: result!.status === "ok" ? "done" : "failed" });
|
|
165
|
+
assert.equal(result!.status, "ok", JSON.stringify({ result, output, notes }));
|
|
166
|
+
if (surface) {
|
|
167
|
+
assertHostileWebEvidence(surface, bodies, [...hostileOutputs.values()]);
|
|
168
|
+
t.diagnostic(`model stub observed ${responsesWebSocketUpgrades} exact Responses websocket upgrade attempt(s)`);
|
|
169
|
+
assert.equal(unexpectedRequests, 0, "no non-model request, including the decoy page, reached the model stub");
|
|
170
|
+
}
|
|
171
|
+
const matched = /MEDIATED_RESULT:(\{[^\r\n]+\})/.exec(output);
|
|
172
|
+
assert.ok(matched, output);
|
|
173
|
+
const evidence = JSON.parse(matched[1]);
|
|
174
|
+
assert.equal(evidence.direct, "EPERM"); assert.equal(evidence.udp, "EPERM"); assert.equal(evidence.held, true);
|
|
175
|
+
assert.ok(notes.some(n => /stage-2 mediated/.test(n) && /Go\/Swift TLS.*Release B/.test(n)), notes.join("\n"));
|
|
176
|
+
assert.equal(udpSeen, 0, "direct DNS/UDP never reached our owned sink");
|
|
177
|
+
assert.equal(upstreamSockets.size, 0, "all owned upstream tunnels closed at turn teardown");
|
|
178
|
+
assert.deepEqual(executorRecords().records, [], "executor teardown completed");
|
|
179
|
+
const proxyPort = Number(evidence.port); assert.ok(proxyPort > 1024); proxyPorts.push(proxyPort);
|
|
180
|
+
await scope.wait(new Promise<void>((ok, fail) => {
|
|
181
|
+
const c = net.connect(proxyPort, "127.0.0.1");
|
|
182
|
+
c.setTimeout(3000, () => { c.destroy(); fail(new Error("proxy teardown check timed out")); });
|
|
183
|
+
c.once("connect", () => { c.destroy(); fail(new Error("proxy still accepts after turn")); });
|
|
184
|
+
c.once("error", e => e.code === "ECONNREFUSED" ? ok() : fail(e));
|
|
185
|
+
}));
|
|
186
|
+
assert.ok(result!.sessionId, "real Codex thread id");
|
|
187
|
+
if (resumed) assert.equal(result!.sessionId, sessionId, "kept grant resumes the same thread");
|
|
188
|
+
sessionId = result!.sessionId;
|
|
189
|
+
}
|
|
190
|
+
assert.equal(proxyPorts.length, 2); assert.equal(upstreamRequests, 4, "each fresh/resumed turn used the mediated provider for request and held tunnel");
|
|
191
|
+
} finally {
|
|
192
|
+
clearTimeout(deadline);
|
|
193
|
+
try { await scope.close(); }
|
|
194
|
+
finally {
|
|
195
|
+
t.signal.removeEventListener("abort", abort);
|
|
196
|
+
sweepOrphanedExecutors(); setLeaseOptionsForTests(null); setCodexHomeConfigForTests(null); setMediatedNetworkProviderForTests(null);
|
|
197
|
+
closeDbForTests();
|
|
198
|
+
for (const [key, value] of Object.entries(saved)) if (value === undefined) delete process.env[key]; else process.env[key] = value;
|
|
199
|
+
fs.rmSync(home, { recursive: true, force: true });
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
});
|
|
203
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
// Stands in for a worker serving one confined turn: opens the turn's broker, prints where it is,
|
|
2
|
+
// and closes it when told ("close" on stdin) or when stdin ends, as a worker does when the turn ends.
|
|
3
|
+
// usage: node broker-host.mjs '<{"nodeId","turnId","mayDelegate","mayAsk"}>'
|
|
4
|
+
import { openBroker } from "../../dist/confine/broker.js";
|
|
5
|
+
import { socketPeer } from "../../dist/confine/peer.js";
|
|
6
|
+
|
|
7
|
+
let broker;
|
|
8
|
+
const refusals = [];
|
|
9
|
+
const opts = JSON.parse(process.argv[3] ?? "{}");
|
|
10
|
+
try {
|
|
11
|
+
broker = await openBroker(JSON.parse(process.argv[2]), {
|
|
12
|
+
onRefusal: (reason) => refusals.push(reason),
|
|
13
|
+
...(opts.unknownPeer ? { peerIdentity: async () => { throw new Error("test: peer pid unavailable"); } } : {}),
|
|
14
|
+
...(opts.wrongUid || opts.stalePeer ? { peerIdentity: async (socket) => {
|
|
15
|
+
const peer = await socketPeer(socket);
|
|
16
|
+
return opts.wrongUid ? { ...peer, uid: peer.uid + 1 } : { ...peer, start: "an earlier occupant of this pid" };
|
|
17
|
+
} } : {}),
|
|
18
|
+
});
|
|
19
|
+
} catch (err) {
|
|
20
|
+
process.stdout.write(JSON.stringify({ error: err.message }) + "\n");
|
|
21
|
+
process.exit(1);
|
|
22
|
+
}
|
|
23
|
+
process.stdout.write(JSON.stringify({ socketPath: broker.socketPath, dir: broker.dir, bridge: broker.bridgeCommand }) + "\n");
|
|
24
|
+
process.stdin.setEncoding("utf8");
|
|
25
|
+
process.stdin.on("data", async (d) => {
|
|
26
|
+
if (d.trim().startsWith("{")) {
|
|
27
|
+
const cmd = JSON.parse(d);
|
|
28
|
+
if (cmd.bind) {
|
|
29
|
+
try {
|
|
30
|
+
broker.bindHarness(cmd.bind);
|
|
31
|
+
process.stdout.write(JSON.stringify({ bound: true }) + "\n");
|
|
32
|
+
} catch (err) {
|
|
33
|
+
process.stdout.write(JSON.stringify({ bound: false, error: err.message }) + "\n");
|
|
34
|
+
}
|
|
35
|
+
} else if (cmd.refusals) process.stdout.write(JSON.stringify({ refusals }) + "\n");
|
|
36
|
+
else if (cmd.secretFile) {
|
|
37
|
+
try {
|
|
38
|
+
process.stdout.write(JSON.stringify({ file: broker.secretFile() }) + "\n");
|
|
39
|
+
} catch (err) {
|
|
40
|
+
process.stdout.write(JSON.stringify({ error: err.message }) + "\n");
|
|
41
|
+
}
|
|
42
|
+
} else if (cmd.list) {
|
|
43
|
+
// What a harness that discovers relay's tools is given (backends/gemini.ts writeGeminiToolFiles).
|
|
44
|
+
try {
|
|
45
|
+
process.stdout.write(JSON.stringify({ tools: await broker.listTools() }) + "\n");
|
|
46
|
+
} catch (err) {
|
|
47
|
+
process.stdout.write(JSON.stringify({ error: err.message }) + "\n");
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
if (!d.includes("close")) return;
|
|
53
|
+
await broker.close();
|
|
54
|
+
process.stdout.write(JSON.stringify({ closed: true }) + "\n");
|
|
55
|
+
});
|
|
56
|
+
process.stdin.on("end", async () => {
|
|
57
|
+
await broker.close();
|
|
58
|
+
process.exit(0);
|
|
59
|
+
});
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// An unrelated peer deliberately given a turn's exact bearer secret. It reports successful
|
|
2
|
+
// connect separately from any reply, so a sandbox denial cannot masquerade as broker rejection.
|
|
3
|
+
import net from "node:net";
|
|
4
|
+
const out = (r) => process.stdout.write(JSON.stringify(r) + "\n");
|
|
5
|
+
out({ ready: true, pid: process.pid });
|
|
6
|
+
process.stdin.once("data", () => {
|
|
7
|
+
const socket = net.connect(process.argv[2]);
|
|
8
|
+
let data = "", connected = false, error;
|
|
9
|
+
const timer = setTimeout(() => socket.destroy(), 4000);
|
|
10
|
+
socket.on("connect", () => {
|
|
11
|
+
connected = true;
|
|
12
|
+
socket.write(JSON.stringify({ relay_bridge_secret: process.argv[3] }) + "\n");
|
|
13
|
+
socket.write(JSON.stringify({ jsonrpc: "2.0", id: 1, method: "initialize", params: {
|
|
14
|
+
protocolVersion: "2025-06-18", capabilities: {}, clientInfo: { name: "outsider", version: "0" },
|
|
15
|
+
} }) + "\n");
|
|
16
|
+
});
|
|
17
|
+
socket.on("data", (chunk) => { data += chunk; if (data.includes("\n")) socket.destroy(); });
|
|
18
|
+
socket.on("error", (err) => { error = err.code; });
|
|
19
|
+
socket.on("close", () => { clearTimeout(timer); out({ connected, data, error }); });
|
|
20
|
+
});
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
// A stand-in for a harness run under relay's sandbox. Its MCP server is the bridge command it is
|
|
2
|
+
// given; it takes one JSON command per stdin line and answers each with one JSON line:
|
|
3
|
+
// {"op":"call","tool":..,"args":..} call a relay tool over the bridge it started with
|
|
4
|
+
// {"op":"fresh","tool":..,"args":..} the same through a newly spawned bridge
|
|
5
|
+
// {"op":"probe","probes":{name:[kind, path]}} try things the sandbox should allow or deny
|
|
6
|
+
// usage: node confined-harness.mjs '<{"bridge":{command,args}}>'
|
|
7
|
+
import fs from "node:fs";
|
|
8
|
+
import net from "node:net";
|
|
9
|
+
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
|
10
|
+
import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js";
|
|
11
|
+
|
|
12
|
+
const plan = JSON.parse(process.argv[2]);
|
|
13
|
+
const out = (o) => process.stdout.write(JSON.stringify(o) + "\n");
|
|
14
|
+
|
|
15
|
+
async function connect() {
|
|
16
|
+
const client = new Client({ name: "confined-harness", version: "0" });
|
|
17
|
+
// The bridge's environment is the entry's own (the turn's secret) plus what a harness's MCP child inherits.
|
|
18
|
+
await client.connect(new StdioClientTransport({ command: plan.bridge.command, args: plan.bridge.args, env: { PATH: process.env.PATH, TMPDIR: process.env.TMPDIR, ...(plan.bridge.env ?? {}) }, stderr: "ignore" }));
|
|
19
|
+
return client;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
async function call(client, tool, args) {
|
|
23
|
+
try {
|
|
24
|
+
const res = await client.callTool({ name: tool, arguments: args ?? {} }, undefined, { timeout: 60000 });
|
|
25
|
+
return JSON.parse(res.content[0].text);
|
|
26
|
+
} catch (err) {
|
|
27
|
+
return { rpc_error: err.message, code: err.code };
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const probes = {
|
|
32
|
+
write: (p) => fs.appendFileSync(p, "x"),
|
|
33
|
+
read: (p) => fs.readFileSync(p),
|
|
34
|
+
list: (p) => fs.readdirSync(p),
|
|
35
|
+
sqlite: async (p) => {
|
|
36
|
+
const { DatabaseSync } = await import("node:sqlite");
|
|
37
|
+
new DatabaseSync(p).prepare("SELECT count(*) FROM nodes").get();
|
|
38
|
+
},
|
|
39
|
+
connect: (p) => new Promise((resolve, reject) => {
|
|
40
|
+
const s = net.connect(p);
|
|
41
|
+
s.on("connect", () => { s.destroy(); resolve(); });
|
|
42
|
+
s.on("error", reject);
|
|
43
|
+
}),
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
let first;
|
|
47
|
+
// The broker test pins this harness after spawn, before the harness opens its bridge.
|
|
48
|
+
if (plan.waitForStart) await new Promise((resolve) => process.stdin.once("data", resolve));
|
|
49
|
+
try {
|
|
50
|
+
first = await connect();
|
|
51
|
+
} catch (err) {
|
|
52
|
+
out({ error: `could not start the bridge: ${err.message}` });
|
|
53
|
+
process.exit(1);
|
|
54
|
+
}
|
|
55
|
+
out({ ready: true, pid: process.pid });
|
|
56
|
+
|
|
57
|
+
let buf = "";
|
|
58
|
+
process.stdin.setEncoding("utf8");
|
|
59
|
+
process.stdin.on("data", async (chunk) => {
|
|
60
|
+
buf += chunk;
|
|
61
|
+
for (let i = buf.indexOf("\n"); i >= 0; i = buf.indexOf("\n")) {
|
|
62
|
+
const cmd = JSON.parse(buf.slice(0, i));
|
|
63
|
+
buf = buf.slice(i + 1);
|
|
64
|
+
if (cmd.op === "call") out(await call(first, cmd.tool, cmd.args));
|
|
65
|
+
else if (cmd.op === "tools") out({ tools: (await first.listTools()).tools.map((t) => t.name).sort() });
|
|
66
|
+
else if (cmd.op === "fresh") {
|
|
67
|
+
try {
|
|
68
|
+
const c = await connect();
|
|
69
|
+
out(await call(c, cmd.tool, cmd.args));
|
|
70
|
+
await c.close();
|
|
71
|
+
} catch (err) {
|
|
72
|
+
out({ rpc_error: err.message, code: err.code });
|
|
73
|
+
}
|
|
74
|
+
} else if (cmd.op === "probe") {
|
|
75
|
+
const r = {};
|
|
76
|
+
for (const [name, [kind, p]] of Object.entries(cmd.probes)) {
|
|
77
|
+
try {
|
|
78
|
+
await probes[kind](p);
|
|
79
|
+
r[name] = "allowed";
|
|
80
|
+
} catch (err) {
|
|
81
|
+
r[name] = err.code ?? err.message;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
out(r);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
process.stdin.on("end", async () => {
|
|
89
|
+
await first.close().catch(() => {});
|
|
90
|
+
process.exit(0);
|
|
91
|
+
});
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// A stand-in MCP server whose tool list holds what relay's gateway must not offer as given: a tool
|
|
2
|
+
// listed twice, a name too long for either harness, an input schema relay reads as something other
|
|
3
|
+
// than an object (a union), and one relay cannot read at all (a reference to nothing). Each is valid
|
|
4
|
+
// MCP, so the client takes the list. Next to them, one tool relay can offer (ok).
|
|
5
|
+
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
|
|
6
|
+
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
7
|
+
import { CallToolRequestSchema, ListToolsRequestSchema } from "@modelcontextprotocol/sdk/types.js";
|
|
8
|
+
|
|
9
|
+
const object = { type: "object", properties: { text: { type: "string" } } };
|
|
10
|
+
const server = new Server({ name: "odd", version: "0" }, { capabilities: { tools: {} } });
|
|
11
|
+
server.setRequestHandler(ListToolsRequestSchema, async () => ({
|
|
12
|
+
tools: [
|
|
13
|
+
{ name: "ok", description: "A tool relay can offer.", inputSchema: object },
|
|
14
|
+
{ name: "ok", description: "The same name again.", inputSchema: object },
|
|
15
|
+
{ name: "x".repeat(70), description: "A name too long.", inputSchema: object },
|
|
16
|
+
{ name: "union", description: "One of two shapes.", inputSchema: { type: "object", oneOf: [{ properties: { a: { type: "string" } } }, { properties: { b: { type: "number" } } }] } },
|
|
17
|
+
{ name: "dangling", description: "A reference to nothing.", inputSchema: { type: "object", properties: { a: { $ref: "#/$defs/nope" } } } },
|
|
18
|
+
],
|
|
19
|
+
}));
|
|
20
|
+
server.setRequestHandler(CallToolRequestSchema, async (req) => ({ content: [{ type: "text", text: JSON.stringify({ called: req.params.name }) }] }));
|
|
21
|
+
await server.connect(new StdioServerTransport());
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// A stand-in for an MCP server the person allows launched agents to use (an extension, relay's
|
|
2
|
+
// mcp.json). It records every call it is sent in $EXT_LOG, so that a test can tell exactly what
|
|
3
|
+
// reached it, and when: relay must forward nothing before the person allows it.
|
|
4
|
+
import fs from "node:fs";
|
|
5
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
6
|
+
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
7
|
+
import { z } from "zod";
|
|
8
|
+
|
|
9
|
+
const record = (entry) => {
|
|
10
|
+
if (process.env.EXT_LOG) fs.appendFileSync(process.env.EXT_LOG, JSON.stringify({ t: Date.now(), ...entry }) + "\n");
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
const server = new McpServer({ name: "ext", version: "0" });
|
|
14
|
+
server.registerTool("echo", {
|
|
15
|
+
description: "Echoes the text back.",
|
|
16
|
+
inputSchema: { text: z.string().describe("What to echo") },
|
|
17
|
+
annotations: { readOnlyHint: true },
|
|
18
|
+
}, async ({ text }) => {
|
|
19
|
+
record({ tool: "echo", args: { text } });
|
|
20
|
+
return { content: [{ type: "text", text: JSON.stringify({ echoed: text }) }] };
|
|
21
|
+
});
|
|
22
|
+
server.registerTool("send", {
|
|
23
|
+
description: "Sends a message to someone.",
|
|
24
|
+
inputSchema: { to: z.string(), body: z.string(), urgent: z.boolean().optional() },
|
|
25
|
+
}, async (args) => {
|
|
26
|
+
record({ tool: "send", args });
|
|
27
|
+
return { content: [{ type: "text", text: JSON.stringify({ sent_to: args.to }) }] };
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
record({ started: true, secret: process.env.EXT_SECRET ?? null, relay_vars: Object.keys(process.env).filter((k) => k.startsWith("RELAY_")) });
|
|
31
|
+
await server.connect(new StdioServerTransport());
|