@mnaimfaizy/agent-kit 1.0.0-beta.13 → 1.0.0-beta.15
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/README.md +24 -5
- package/custom-harness.schema.json +243 -0
- package/harnesses.json +286 -0
- package/package.json +4 -2
- package/src/checks/ci-workflow.mjs +105 -0
- package/src/checks/claude-app.mjs +11 -2
- package/src/checks/custom-harness.mjs +157 -0
- package/src/checks/github-app.mjs +214 -0
- package/src/checks/review-response.mjs +54 -27
- package/src/checks/rulesets.mjs +9 -8
- package/src/checks/secrets-and-variables.mjs +220 -43
- package/src/checks/stages.mjs +705 -0
- package/src/cli.mjs +277 -31
- package/src/deep-scan/agent.mjs +145 -117
- package/src/deep-scan/credential.mjs +88 -42
- package/src/deep-scan/docker-driver.mjs +131 -49
- package/src/deep-scan/harness-text.mjs +99 -0
- package/src/deep-scan/lifecycle.mjs +92 -199
- package/src/deep-scan/limits.mjs +13 -7
- package/src/deep-scan/model-proxy.mjs +47 -602
- package/src/deep-scan/preflight.mjs +81 -1
- package/src/deep-scan/recipe.mjs +7 -7
- package/src/deep-scan/runtime.mjs +54 -6
- package/src/deep-scan/sandbox-run.mjs +232 -0
- package/src/deep-scan/sbx-driver.mjs +242 -50
- package/src/deep-scan/tar.mjs +69 -22
- package/src/deep-scan/verify.mjs +6 -1
- package/src/deep-scan.mjs +98 -14
- package/src/doctor.mjs +113 -4
- package/src/harness/adapters.mjs +30 -0
- package/src/harness/antigravity.mjs +187 -0
- package/src/harness/claude-code.mjs +236 -0
- package/src/harness/codex.mjs +219 -0
- package/src/harness/cursor.mjs +199 -0
- package/src/harness/custom/registry.mjs +21 -0
- package/src/harness/custom/schema.mjs +90 -0
- package/src/harness/custom.mjs +299 -0
- package/src/harness/facts.mjs +157 -0
- package/src/harness/gemini.mjs +164 -0
- package/src/harness/install-layer.mjs +141 -0
- package/src/harness/opencode.mjs +289 -0
- package/src/harness/resolve.mjs +156 -0
- package/src/harness/support-levels.mjs +197 -0
- package/src/harness-live/assess.mjs +291 -0
- package/src/harness-live/cursor-real.mjs +146 -0
- package/src/harness-live/cursor-version.mjs +70 -0
- package/src/harness-live/cursor.mjs +80 -0
- package/src/harness-live/custom.mjs +91 -0
- package/src/harness-live/fixture-harness.mjs +45 -0
- package/src/harness-live/harnesses.mjs +263 -0
- package/src/harness-live/host.mjs +414 -0
- package/src/harness-live/opencode.mjs +289 -0
- package/src/harness-live/probes.mjs +239 -0
- package/src/harness-live/run.mjs +214 -0
- package/src/harness-live/setup.mjs +126 -0
- package/src/harness-live/stage.mjs +161 -0
- package/src/harness-live/suite.mjs +481 -0
- package/src/harness-test.mjs +116 -0
- package/src/init.mjs +339 -23
- package/src/model-proxy/core.mjs +657 -0
- package/src/model-proxy/profiles/anthropic.mjs +241 -0
- package/src/model-proxy/profiles/gemini-api.mjs +311 -0
- package/src/model-proxy/profiles/openai.mjs +327 -0
- package/src/model-proxy/stub-dialects/anthropic.mjs +110 -0
- package/src/model-proxy/stub-dialects/gemini-api.mjs +178 -0
- package/src/model-proxy/stub-dialects/openai.mjs +173 -0
- package/src/model-proxy/stub.mjs +182 -0
- package/src/stage/audit.mjs +79 -0
- package/src/stage/egress-route.mjs +207 -0
- package/src/stage/implement/carry.mjs +308 -0
- package/src/stage/implement/sandbox.mjs +271 -0
- package/src/stage/implement/verify.mjs +70 -0
- package/src/stage/implement.mjs +218 -0
- package/src/stage/plan.mjs +115 -0
- package/src/stage/review-response.mjs +172 -0
- package/src/stage/review.mjs +185 -0
- package/src/stage/workspace.mjs +274 -0
- package/src/stage.mjs +1068 -0
- package/src/deep-scan/claude-code.mjs +0 -25
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
// What the live suite knows about each harness it proves (ADR 0031): the stub
|
|
2
|
+
// model's dialect and the credential kinds it is run on, the header the proxy
|
|
3
|
+
// writes the real key in, the variable that names the model proxy in the
|
|
4
|
+
// sandbox, and the control for the checkout-config probe: the harness started
|
|
5
|
+
// again in the same sandbox with the checkout's config loaded on purpose, so a
|
|
6
|
+
// run in which none of it left a marker is known to have been able to.
|
|
7
|
+
|
|
8
|
+
import { antigravity } from "../harness/antigravity.mjs";
|
|
9
|
+
import { claudeCode, TOOLS } from "../harness/claude-code.mjs";
|
|
10
|
+
import { codex } from "../harness/codex.mjs";
|
|
11
|
+
import { gemini } from "../harness/gemini.mjs";
|
|
12
|
+
import { anthropicDialect } from "../model-proxy/stub-dialects/anthropic.mjs";
|
|
13
|
+
import { geminiApiDialect } from "../model-proxy/stub-dialects/gemini-api.mjs";
|
|
14
|
+
import { openaiDialect } from "../model-proxy/stub-dialects/openai.mjs";
|
|
15
|
+
import { canary, FAKE_CREDENTIAL, plantedConfig, plantedEnvFiles } from "./host.mjs";
|
|
16
|
+
import { liveOpencode } from "./opencode.mjs";
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* @typedef {{
|
|
20
|
+
* adapter: (request?: object) => import("../harness/claude-code.mjs").LaunchPlan,
|
|
21
|
+
* dialect: import("../model-proxy/stub.mjs").StubDialect,
|
|
22
|
+
* credential: (kind: string) => string,
|
|
23
|
+
* upstreamAuth: (kind: string, credential: string) => [string, string],
|
|
24
|
+
* baseUrlVariable: string,
|
|
25
|
+
* removed: readonly string[],
|
|
26
|
+
* harmlessVariables: readonly string[],
|
|
27
|
+
* configControl: readonly string[],
|
|
28
|
+
* assertions?: ReadonlyArray<NamedAssertion>,
|
|
29
|
+
* control: (launch: { plan: import("../harness/claude-code.mjs").LaunchPlan, url: string }) =>
|
|
30
|
+
* { argv: string[], stdin: string },
|
|
31
|
+
* model?: string,
|
|
32
|
+
* shellTool?: string,
|
|
33
|
+
* committed?: Record<string, string>,
|
|
34
|
+
* profiles?: Readonly<Record<string, Partial<LiveHarness>>>,
|
|
35
|
+
* before?: Function,
|
|
36
|
+
* after?: Function,
|
|
37
|
+
* }} LiveHarness `removed` are the checkout paths the Launcher must have
|
|
38
|
+
* removed from the sandbox's copy. `configControl` holds the start of each
|
|
39
|
+
* marker's name the control run must leave. `harmlessVariables` are the
|
|
40
|
+
* `NAME=value` pairs with a GitHub prefix that the harness itself sets.
|
|
41
|
+
* `assertions` are the harness's own, beside the Guards. `profiles` are the
|
|
42
|
+
* model providers a harness is proven on, one run of every scenario each,
|
|
43
|
+
* with what differs by provider (the `model` named among it). `before` and
|
|
44
|
+
* `after` run in a read-only Stage's sandbox around its agent step, and what
|
|
45
|
+
* `after` returns joins the evidence. `control` is missing for a Custom
|
|
46
|
+
* harness, whose own config the suite cannot know how to load; `shellTool`
|
|
47
|
+
* is its file's `probe_shell_tool`, and `committed` its file, planted on
|
|
48
|
+
* the fixture repository's default branch.
|
|
49
|
+
*
|
|
50
|
+
* @typedef {{
|
|
51
|
+
* name: string,
|
|
52
|
+
* check: (evidence: {
|
|
53
|
+
* requests: ReadonlyArray<{ method: string, path: string, body: string }>,
|
|
54
|
+
* transcript: string | null,
|
|
55
|
+
* launcherOutput: string,
|
|
56
|
+
* stage: boolean,
|
|
57
|
+
* decoy?: { registered: boolean, attachedByStage: boolean, attachedWithout: boolean },
|
|
58
|
+
* egress?: { logging: boolean, lines: string[] },
|
|
59
|
+
* }) => string | null,
|
|
60
|
+
* }} NamedAssertion What a run must show of one harness, by name, so that a pin
|
|
61
|
+
* bump that breaks it says why (ADR 0031): `check` gives why it failed, or
|
|
62
|
+
* null.
|
|
63
|
+
*/
|
|
64
|
+
|
|
65
|
+
/** A word quoted for `sh`. */
|
|
66
|
+
const quote = (s) => `'${String(s).replace(/'/g, `'\\''`)}'`;
|
|
67
|
+
|
|
68
|
+
const DONE = "Say that you are done.";
|
|
69
|
+
|
|
70
|
+
/** The removed paths of a plan whose launch removes the checkout's config. */
|
|
71
|
+
const removedBy = ({ launch, checkoutConfig }) =>
|
|
72
|
+
launch.removeCheckoutConfig ? [...checkoutConfig] : [];
|
|
73
|
+
|
|
74
|
+
/** What a harness says when it will not send a model request over plain HTTP. */
|
|
75
|
+
const PLAIN_HTTP_REFUSED =
|
|
76
|
+
/(base[ _]?url.*\bhttps\b|\bmust use https\b|\bhttps is required\b|insecure.*\burl\b|plain[ -]http)/i;
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Gemini CLI documents HTTPS for any base URL but a loopback one, and the
|
|
80
|
+
* pinned version does not enforce it (ADR 0023): the proxy is plain HTTP, and
|
|
81
|
+
* not loopback from the sandbox.
|
|
82
|
+
* @type {Readonly<NamedAssertion>}
|
|
83
|
+
*/
|
|
84
|
+
const PLAIN_HTTP = Object.freeze({
|
|
85
|
+
name: "gemini-plain-http-base-url",
|
|
86
|
+
check({ requests, transcript, launcherOutput }) {
|
|
87
|
+
if (requests.length > 0) return null;
|
|
88
|
+
const said = `${transcript ?? ""}\n${launcherOutput}`
|
|
89
|
+
.split("\n")
|
|
90
|
+
.find((line) => PLAIN_HTTP_REFUSED.test(line));
|
|
91
|
+
return said === undefined
|
|
92
|
+
? "no request of Gemini CLI's reached the model API, so the plain-HTTP base URL is not shown accepted: read the agent step's output."
|
|
93
|
+
: `Gemini CLI ${gemini().identity.version} refused the plain-HTTP base URL of the model proxy (ADR 0023), so it needs the in-sandbox loopback forwarder before this pin ships. It said: ${said.trim()}`;
|
|
94
|
+
},
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Antigravity CLI, in API-key mode, takes the model proxy's plain-HTTP base
|
|
99
|
+
* URL at the pinned version (ADR 0023, #578).
|
|
100
|
+
* @type {Readonly<NamedAssertion>}
|
|
101
|
+
*/
|
|
102
|
+
const ANTIGRAVITY_PLAIN_HTTP = Object.freeze({
|
|
103
|
+
name: "antigravity-plain-http-base-url",
|
|
104
|
+
check({ requests, transcript, launcherOutput }) {
|
|
105
|
+
if (requests.length > 0) return null;
|
|
106
|
+
const said = `${transcript ?? ""}\n${launcherOutput}`
|
|
107
|
+
.split("\n")
|
|
108
|
+
.find((line) => PLAIN_HTTP_REFUSED.test(line));
|
|
109
|
+
return said === undefined
|
|
110
|
+
? "no request of Antigravity CLI's reached the model API, so the plain-HTTP base URL is not shown accepted: read the agent step's output."
|
|
111
|
+
: `Antigravity CLI ${antigravity().identity.version} refused the plain-HTTP base URL of the model proxy (ADR 0023), so it needs an in-sandbox loopback forwarder before this pin ships. It said: ${said.trim()}`;
|
|
112
|
+
},
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* What the suite knows for one scenario: its harness's entry, with its
|
|
117
|
+
* provider's own over it.
|
|
118
|
+
* @param {{ harness: string, profile?: string }} scenario
|
|
119
|
+
* @returns {Readonly<LiveHarness>}
|
|
120
|
+
*/
|
|
121
|
+
export function liveFor({ harness, profile }) {
|
|
122
|
+
const entry = LIVE_HARNESSES[harness];
|
|
123
|
+
return profile === undefined ? entry : { ...entry, ...entry.profiles[profile] };
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/** @type {Readonly<Record<string, Readonly<LiveHarness>>>} */
|
|
127
|
+
export const LIVE_HARNESSES = Object.freeze({
|
|
128
|
+
"claude-code": Object.freeze({
|
|
129
|
+
adapter: claudeCode,
|
|
130
|
+
dialect: anthropicDialect,
|
|
131
|
+
credential: (kind) => FAKE_CREDENTIAL[kind](),
|
|
132
|
+
upstreamAuth: (kind, credential) =>
|
|
133
|
+
kind === "api-key" ? ["x-api-key", credential] : ["authorization", `Bearer ${credential}`],
|
|
134
|
+
baseUrlVariable: "ANTHROPIC_BASE_URL",
|
|
135
|
+
removed: removedBy(claudeCode()),
|
|
136
|
+
harmlessVariables: Object.freeze([]),
|
|
137
|
+
configControl: Object.freeze(["settings-", "local-", "mcp-server"]),
|
|
138
|
+
control: ({ url }) => ({
|
|
139
|
+
argv: [
|
|
140
|
+
"claude",
|
|
141
|
+
"--print",
|
|
142
|
+
"--setting-sources",
|
|
143
|
+
"user,project,local",
|
|
144
|
+
"--settings",
|
|
145
|
+
JSON.stringify({ env: { ANTHROPIC_BASE_URL: url } }),
|
|
146
|
+
"--tools",
|
|
147
|
+
TOOLS.join(","),
|
|
148
|
+
"--permission-mode",
|
|
149
|
+
"dontAsk",
|
|
150
|
+
"--no-session-persistence",
|
|
151
|
+
"--max-turns",
|
|
152
|
+
"2",
|
|
153
|
+
],
|
|
154
|
+
stdin: DONE,
|
|
155
|
+
}),
|
|
156
|
+
}),
|
|
157
|
+
codex: Object.freeze({
|
|
158
|
+
adapter: codex,
|
|
159
|
+
dialect: openaiDialect,
|
|
160
|
+
credential: () => `sk-proj-${canary()}`,
|
|
161
|
+
upstreamAuth: (_kind, credential) => ["authorization", `Bearer ${credential}`],
|
|
162
|
+
baseUrlVariable: "OPENAI_BASE_URL",
|
|
163
|
+
removed: removedBy(codex()),
|
|
164
|
+
// Codex CLI names `cat` as its shell's pager, GitHub's CLI's among them.
|
|
165
|
+
harmlessVariables: Object.freeze(["GH_PAGER=cat"]),
|
|
166
|
+
configControl: Object.freeze(["codex-hook-", "codex-mcp-server"]),
|
|
167
|
+
// The removed config is put back, the project marked trusted, hooks
|
|
168
|
+
// turned on and their trust check skipped, in the Launcher's own config.
|
|
169
|
+
control({ plan }) {
|
|
170
|
+
const planted = Object.entries(plantedConfig()).filter(([path]) =>
|
|
171
|
+
path.startsWith(".codex/"),
|
|
172
|
+
);
|
|
173
|
+
const [config] = plan.launch.files;
|
|
174
|
+
const loading = config.text
|
|
175
|
+
.replace('trust_level = "untrusted"', 'trust_level = "trusted"')
|
|
176
|
+
.replace("\nhooks = false\n", "\nhooks = true\n");
|
|
177
|
+
const argv = [...plan.launch.argv.slice(0, -1), "--dangerously-bypass-hook-trust", "-"];
|
|
178
|
+
const script = [
|
|
179
|
+
"set -eu",
|
|
180
|
+
"mkdir -p /workspace/.codex",
|
|
181
|
+
...planted.map(
|
|
182
|
+
([path, text]) => `printf '%s' ${quote(text)} > ${quote(`/workspace/${path}`)}`,
|
|
183
|
+
),
|
|
184
|
+
`printf '%s' ${quote(loading)} > ${quote(config.path)}`,
|
|
185
|
+
`exec ${argv.map(quote).join(" ")}`,
|
|
186
|
+
].join("\n");
|
|
187
|
+
return { argv: ["sh", "-c", script], stdin: DONE };
|
|
188
|
+
},
|
|
189
|
+
}),
|
|
190
|
+
gemini: Object.freeze({
|
|
191
|
+
adapter: gemini,
|
|
192
|
+
dialect: geminiApiDialect,
|
|
193
|
+
credential: () => `AIza-${canary()}`,
|
|
194
|
+
upstreamAuth: (_kind, credential) => ["x-goog-api-key", credential],
|
|
195
|
+
baseUrlVariable: "GOOGLE_GEMINI_BASE_URL",
|
|
196
|
+
removed: removedBy(gemini()),
|
|
197
|
+
// Gemini CLI tells GitHub's CLI in its shell not to prompt.
|
|
198
|
+
harmlessVariables: Object.freeze(["GH_PROMPT_DISABLED=1"]),
|
|
199
|
+
configControl: Object.freeze(["gemini-hook-", "gemini-mcp-server"]),
|
|
200
|
+
assertions: Object.freeze([PLAIN_HTTP]),
|
|
201
|
+
// The removed config is put back, hooks turned on and the checkout's
|
|
202
|
+
// `.env` read in the Launcher's own settings, the image's system settings
|
|
203
|
+
// left unread, and no limit on which MCP server may start.
|
|
204
|
+
control({ plan }) {
|
|
205
|
+
const planted = [
|
|
206
|
+
...Object.entries(plantedConfig()).filter(([path]) => path.startsWith(".gemini/")),
|
|
207
|
+
...Object.entries(plantedEnvFiles()),
|
|
208
|
+
];
|
|
209
|
+
const [config] = plan.launch.files;
|
|
210
|
+
const loading = JSON.stringify(
|
|
211
|
+
{
|
|
212
|
+
...JSON.parse(config.text),
|
|
213
|
+
hooksConfig: { enabled: true },
|
|
214
|
+
advanced: { ignoreLocalEnv: false },
|
|
215
|
+
},
|
|
216
|
+
null,
|
|
217
|
+
2,
|
|
218
|
+
);
|
|
219
|
+
const argv = [...plan.launch.argv];
|
|
220
|
+
argv.splice(argv.indexOf("--allowed-mcp-server-names"), 2);
|
|
221
|
+
const script = [
|
|
222
|
+
"set -eu",
|
|
223
|
+
"mkdir -p /workspace/.gemini",
|
|
224
|
+
...planted.map(
|
|
225
|
+
([path, text]) => `printf '%s' ${quote(text)} > ${quote(`/workspace/${path}`)}`,
|
|
226
|
+
),
|
|
227
|
+
`printf '%s' ${quote(loading)} > ${quote(config.path)}`,
|
|
228
|
+
"export GEMINI_CLI_SYSTEM_SETTINGS_PATH=/tmp/agent-kit-no-system-settings.json",
|
|
229
|
+
`exec ${argv.map(quote).join(" ")}`,
|
|
230
|
+
].join("\n");
|
|
231
|
+
return { argv: ["sh", "-c", script], stdin: DONE };
|
|
232
|
+
},
|
|
233
|
+
}),
|
|
234
|
+
antigravity: Object.freeze({
|
|
235
|
+
adapter: antigravity,
|
|
236
|
+
dialect: geminiApiDialect,
|
|
237
|
+
credential: () => `AIza-${canary()}`,
|
|
238
|
+
upstreamAuth: (_kind, credential) => ["x-goog-api-key", credential],
|
|
239
|
+
baseUrlVariable: "GOOGLE_GEMINI_BASE_URL",
|
|
240
|
+
removed: removedBy(antigravity()),
|
|
241
|
+
harmlessVariables: Object.freeze([]),
|
|
242
|
+
configControl: Object.freeze(["agy-hook-", "agy-mcp-server"]),
|
|
243
|
+
assertions: Object.freeze([ANTIGRAVITY_PLAIN_HTTP]),
|
|
244
|
+
// The removed config is put back: Antigravity CLI loads it from the
|
|
245
|
+
// working directory with no trust asked, so the Launcher's own launch is
|
|
246
|
+
// the one that loads it.
|
|
247
|
+
control({ plan }) {
|
|
248
|
+
const planted = Object.entries(plantedConfig()).filter(([path]) =>
|
|
249
|
+
/^[._]agents?\//.test(path),
|
|
250
|
+
);
|
|
251
|
+
const script = [
|
|
252
|
+
"set -eu",
|
|
253
|
+
...planted.flatMap(([path, text]) => [
|
|
254
|
+
`mkdir -p ${quote(`/workspace/${path.slice(0, path.lastIndexOf("/"))}`)}`,
|
|
255
|
+
`printf '%s' ${quote(text)} > ${quote(`/workspace/${path}`)}`,
|
|
256
|
+
]),
|
|
257
|
+
`exec ${plan.launch.argv.map(quote).join(" ")}`,
|
|
258
|
+
].join("\n");
|
|
259
|
+
return { argv: ["sh", "-c", script], stdin: DONE };
|
|
260
|
+
},
|
|
261
|
+
}),
|
|
262
|
+
opencode: liveOpencode,
|
|
263
|
+
});
|
|
@@ -0,0 +1,414 @@
|
|
|
1
|
+
// The host's side of a live run (ADR 0031): what it plants before the harness
|
|
2
|
+
// starts (a repository to copy in, with executable harness config in it;
|
|
3
|
+
// canary files outside it; canary secrets in the runner's environment; a
|
|
4
|
+
// listener the sandbox must not reach) and what it reads itself afterwards
|
|
5
|
+
// (the sandbox's settings, markers and transcript, and its own repository and
|
|
6
|
+
// files). Every value is made up for the run. Node core only (ADR 0001).
|
|
7
|
+
|
|
8
|
+
import { randomBytes } from "node:crypto";
|
|
9
|
+
import { mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
10
|
+
import { connect, createServer } from "node:net";
|
|
11
|
+
import { homedir, networkInterfaces, tmpdir } from "node:os";
|
|
12
|
+
import { dirname, join } from "node:path";
|
|
13
|
+
import { CONTROL_FILE, MARKER_DIR, PLANTED_ENV } from "./probes.mjs";
|
|
14
|
+
|
|
15
|
+
/** The runner variables that must never enter a sandbox, each given a canary. */
|
|
16
|
+
export const GITHUB_VARIABLES = Object.freeze([
|
|
17
|
+
"GITHUB_TOKEN",
|
|
18
|
+
"GH_TOKEN",
|
|
19
|
+
"ACTIONS_ID_TOKEN_REQUEST_TOKEN",
|
|
20
|
+
"ACTIONS_ID_TOKEN_REQUEST_URL",
|
|
21
|
+
"ACTIONS_RUNTIME_TOKEN",
|
|
22
|
+
]);
|
|
23
|
+
|
|
24
|
+
/** The outside targets the sandbox must not reach, tried from the host as the control. */
|
|
25
|
+
const OUTSIDE_URLS = Object.freeze(["https://example.com/", "https://1.1.1.1/"]);
|
|
26
|
+
|
|
27
|
+
/** How often the control tries each, so one dropped connection blocks no release. */
|
|
28
|
+
const OUTSIDE_TRIES = 3;
|
|
29
|
+
|
|
30
|
+
/** The workspace's file holding the sweep's control. */
|
|
31
|
+
const SWEEP_CONTROL_FILE = "agent-kit-sweep-control.txt";
|
|
32
|
+
|
|
33
|
+
const id = () => randomBytes(16).toString("hex");
|
|
34
|
+
|
|
35
|
+
/** A value that must appear nowhere: the probes look for the pattern. */
|
|
36
|
+
export const canary = () => `AKCANARY-${id()}`;
|
|
37
|
+
|
|
38
|
+
/** Fake credentials of each kind, shaped like real ones, each a canary. */
|
|
39
|
+
export const FAKE_CREDENTIAL = Object.freeze({
|
|
40
|
+
"api-key": () => `sk-ant-api03-${canary()}`,
|
|
41
|
+
subscription: () => `sk-ant-oat01-${canary()}`,
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
/** A shell command that leaves the marker `name`, for a planted config to run. */
|
|
45
|
+
const mark = (name) => `mkdir -p ${MARKER_DIR} && touch ${MARKER_DIR}/${name}`;
|
|
46
|
+
|
|
47
|
+
/** Hooks, in the shape Claude Code and Codex CLI share, that each leave a marker, prefixed `from`. */
|
|
48
|
+
const hooks = (from) =>
|
|
49
|
+
Object.fromEntries(
|
|
50
|
+
["SessionStart", "UserPromptSubmit", "PreToolUse", "Stop"].map((event) => [
|
|
51
|
+
event,
|
|
52
|
+
[{ hooks: [{ type: "command", command: mark(`${from}-${event}`) }] }],
|
|
53
|
+
]),
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
/** Hooks in Gemini CLI's own events, each leaving a marker. */
|
|
57
|
+
const geminiHooks = () =>
|
|
58
|
+
Object.fromEntries(
|
|
59
|
+
["SessionStart", "BeforeAgent", "BeforeTool", "AfterAgent"].map((event) => [
|
|
60
|
+
event,
|
|
61
|
+
[{ hooks: [{ type: "command", command: mark(`gemini-hook-${event}`) }] }],
|
|
62
|
+
]),
|
|
63
|
+
);
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Hooks in Antigravity CLI's shape, one folder's, each leaving a marker: a
|
|
67
|
+
* named hook with its events' commands.
|
|
68
|
+
*/
|
|
69
|
+
const antigravityHooks = (folder) => ({
|
|
70
|
+
planted: Object.fromEntries(
|
|
71
|
+
["SessionStart", "PreInvocation"].map((event) => [
|
|
72
|
+
event,
|
|
73
|
+
[{ type: "command", command: mark(`agy-hook-${folder}-${event}`) }],
|
|
74
|
+
]),
|
|
75
|
+
),
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
/** The folders of a checkout Antigravity CLI loads config from, beside `.gemini/`. */
|
|
79
|
+
const ANTIGRAVITY_FOLDERS = [".agents", ".agent", "_agents", "_agent"];
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* The executable harness config planted in the checkout, by path: each entry
|
|
83
|
+
* runs a command, or sets a variable, if the harness loads it.
|
|
84
|
+
*/
|
|
85
|
+
export function plantedConfig() {
|
|
86
|
+
return {
|
|
87
|
+
".claude/settings.json": JSON.stringify({
|
|
88
|
+
env: { [PLANTED_ENV]: "1" },
|
|
89
|
+
enableAllProjectMcpServers: true,
|
|
90
|
+
apiKeyHelper: `${mark("settings-apiKeyHelper")}; echo planted`,
|
|
91
|
+
hooks: hooks("settings"),
|
|
92
|
+
}),
|
|
93
|
+
".claude/settings.local.json": JSON.stringify({ hooks: hooks("local") }),
|
|
94
|
+
".mcp.json": JSON.stringify({
|
|
95
|
+
mcpServers: { planted: { command: "sh", args: ["-c", mark("mcp-server")] } },
|
|
96
|
+
}),
|
|
97
|
+
// Codex CLI's own: what it loads from a project it trusts.
|
|
98
|
+
".codex/config.toml": [
|
|
99
|
+
"[shell_environment_policy]",
|
|
100
|
+
`set = { ${PLANTED_ENV} = "1" }`,
|
|
101
|
+
"",
|
|
102
|
+
"[mcp_servers.planted]",
|
|
103
|
+
'command = "sh"',
|
|
104
|
+
`args = ["-c", ${JSON.stringify(mark("codex-mcp-server"))}]`,
|
|
105
|
+
"",
|
|
106
|
+
].join("\n"),
|
|
107
|
+
".codex/hooks.json": JSON.stringify({ hooks: hooks("codex-hook") }),
|
|
108
|
+
".agents/plugins/marketplace.json": JSON.stringify({ name: "planted", plugins: [] }),
|
|
109
|
+
".agents/skills/planted/SKILL.md":
|
|
110
|
+
"---\nname: planted\ndescription: A planted skill.\n---\n\nNothing here is real.\n",
|
|
111
|
+
// Antigravity CLI's own: hooks and MCP servers, from each of its folders,
|
|
112
|
+
// with no trust asked.
|
|
113
|
+
...Object.fromEntries(
|
|
114
|
+
ANTIGRAVITY_FOLDERS.flatMap((folder) => [
|
|
115
|
+
[`${folder}/hooks.json`, JSON.stringify(antigravityHooks(folder))],
|
|
116
|
+
[
|
|
117
|
+
`${folder}/mcp_config.json`,
|
|
118
|
+
JSON.stringify({
|
|
119
|
+
mcpServers: {
|
|
120
|
+
planted: { command: "sh", args: ["-c", mark(`agy-mcp-server-${folder}`)] },
|
|
121
|
+
},
|
|
122
|
+
}),
|
|
123
|
+
],
|
|
124
|
+
]),
|
|
125
|
+
),
|
|
126
|
+
// opencode's own: its project config, at the root and in `.opencode/`.
|
|
127
|
+
...Object.fromEntries(
|
|
128
|
+
[
|
|
129
|
+
["opencode.json", "opencode-mcp-server"],
|
|
130
|
+
["opencode.jsonc", "opencode-mcp-server-jsonc"],
|
|
131
|
+
[".opencode/opencode.json", "opencode-dir-mcp-server"],
|
|
132
|
+
].map(([path, name]) => [
|
|
133
|
+
path,
|
|
134
|
+
JSON.stringify({
|
|
135
|
+
mcp: {
|
|
136
|
+
servers: {
|
|
137
|
+
[name]: { type: "local", command: ["sh", "-c", mark(name)] },
|
|
138
|
+
},
|
|
139
|
+
},
|
|
140
|
+
}),
|
|
141
|
+
]),
|
|
142
|
+
),
|
|
143
|
+
// Gemini CLI's own: what it loads from a folder it trusts. A checkout can
|
|
144
|
+
// also turn a system hook off by name, since those lists merge.
|
|
145
|
+
".gemini/settings.json": JSON.stringify({
|
|
146
|
+
hooks: geminiHooks(),
|
|
147
|
+
hooksConfig: { disabled: ["planted-system-hook"] },
|
|
148
|
+
mcpServers: { planted: { command: "sh", args: ["-c", mark("gemini-mcp-server")] } },
|
|
149
|
+
}),
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Environment files that set a variable if the harness loads them, by path.
|
|
155
|
+
* Apart from the rest of the planted config: a Deep scan refuses a repository
|
|
156
|
+
* with a committed `.env` before anything runs.
|
|
157
|
+
*/
|
|
158
|
+
export function plantedEnvFiles() {
|
|
159
|
+
return { ".env": `${PLANTED_ENV}=1\n`, ".gemini/.env": `${PLANTED_ENV}=1\n` };
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/** The fixture repository's own files: what a Deep scan reads at the trusted ref. */
|
|
163
|
+
function fixtureFiles(control) {
|
|
164
|
+
const note = "A fixture for the live suite; nothing here is real.\n";
|
|
165
|
+
return {
|
|
166
|
+
"README.md": `# Live suite fixture\n\n${note}`,
|
|
167
|
+
[CONTROL_FILE]: `${control}\n`,
|
|
168
|
+
"CLAUDE.md": note,
|
|
169
|
+
".security/scan-recipe.yml": [
|
|
170
|
+
"setup: []",
|
|
171
|
+
"registries: []",
|
|
172
|
+
"entry_points:",
|
|
173
|
+
" - command: true",
|
|
174
|
+
" note: A command that does nothing.",
|
|
175
|
+
"fixtures: []",
|
|
176
|
+
"notes:",
|
|
177
|
+
" - Nothing here is real.",
|
|
178
|
+
"",
|
|
179
|
+
].join("\n"),
|
|
180
|
+
".security/threat-model.md": `# Threat model\n\n${note}`,
|
|
181
|
+
".security/findings-ledger.md": `# Findings ledger\n\n${note}`,
|
|
182
|
+
".claude/skills/security-audit/SKILL.md": `# security-audit\n\n${note}`,
|
|
183
|
+
".claude/skills/security-audit/DEEP.md": `# Deep\n\n${note}`,
|
|
184
|
+
".claude/skills/security-audit/report-format.md": `# Report format\n\n${note}`,
|
|
185
|
+
...plantedConfig(),
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* Plant a run's fixtures on the host: the repository (its config committed, an
|
|
191
|
+
* untracked canary file and a canary in its .git/config, neither of which the
|
|
192
|
+
* copy-in carries), canary files in the temporary and home folders, and
|
|
193
|
+
* canaries in the runner's GitHub variables. The launcher's own canary is on
|
|
194
|
+
* its process's command line, where the workflow puts it.
|
|
195
|
+
* @param {{ runner: import("../exec.mjs").Runner, launcherCanary: string, envFiles?: boolean,
|
|
196
|
+
* committed?: Record<string, string>, configPaths?: readonly string[] }} opts
|
|
197
|
+
* `envFiles` commits the planted environment files too. `committed` are files
|
|
198
|
+
* more to commit on `main`. Each of `configPaths`, a harness's checkout
|
|
199
|
+
* config, is planted unless a planted file already sits at it or under it,
|
|
200
|
+
* so its removal is seen.
|
|
201
|
+
*/
|
|
202
|
+
export function plant({
|
|
203
|
+
runner,
|
|
204
|
+
launcherCanary,
|
|
205
|
+
envFiles = false,
|
|
206
|
+
committed = {},
|
|
207
|
+
configPaths = [],
|
|
208
|
+
}) {
|
|
209
|
+
const root = mkdtempSync(join(tmpdir(), "agent-kit-live-repo-"));
|
|
210
|
+
const control = `AKCONTROL-${id()}`;
|
|
211
|
+
const write = (path, text) => {
|
|
212
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
213
|
+
writeFileSync(path, text);
|
|
214
|
+
};
|
|
215
|
+
const files = {
|
|
216
|
+
...fixtureFiles(control),
|
|
217
|
+
...(envFiles ? plantedEnvFiles() : {}),
|
|
218
|
+
...committed,
|
|
219
|
+
};
|
|
220
|
+
const overlaps = (a, b) => a === b || a.startsWith(`${b}/`) || b.startsWith(`${a}/`);
|
|
221
|
+
for (const path of configPaths) {
|
|
222
|
+
if (!Object.keys(files).some((file) => overlaps(file, path))) {
|
|
223
|
+
files[path] = "# Planted by the live suite: the checkout's harness config.\n";
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
for (const [path, text] of Object.entries(files)) write(join(root, path), text);
|
|
227
|
+
const git = (...args) => {
|
|
228
|
+
const r = runner("git", [
|
|
229
|
+
"-C",
|
|
230
|
+
root,
|
|
231
|
+
"-c",
|
|
232
|
+
"user.name=agent-kit",
|
|
233
|
+
"-c",
|
|
234
|
+
"user.email=agent-kit@example.invalid",
|
|
235
|
+
"-c",
|
|
236
|
+
"commit.gpgsign=false",
|
|
237
|
+
...args,
|
|
238
|
+
]);
|
|
239
|
+
if (r.status !== 0) throw new Error(`git ${args[0]} failed: ${r.stderr}`);
|
|
240
|
+
return r.stdout.trim();
|
|
241
|
+
};
|
|
242
|
+
git("init", "--quiet", "--initial-branch=main");
|
|
243
|
+
git("add", "--all", "--force");
|
|
244
|
+
git("commit", "--quiet", "-m", "fixture");
|
|
245
|
+
|
|
246
|
+
// A canary-shaped value the filesystem sweep in the sandbox must find.
|
|
247
|
+
const sweepControl = canary();
|
|
248
|
+
write(join(root, SWEEP_CONTROL_FILE), `${sweepControl}\n`);
|
|
249
|
+
git("add", "--all", "--force", "--", SWEEP_CONTROL_FILE);
|
|
250
|
+
git("commit", "--quiet", "-m", "sweep control");
|
|
251
|
+
|
|
252
|
+
const canaries = { reads: [], github: [], launcher: [launcherCanary] };
|
|
253
|
+
const fresh = (kind) => {
|
|
254
|
+
const value = canary();
|
|
255
|
+
canaries[kind].push(value);
|
|
256
|
+
return value;
|
|
257
|
+
};
|
|
258
|
+
git("config", "http.https://github.com/.extraheader", `AUTHORIZATION: ${fresh("github")}`);
|
|
259
|
+
const name = `agent-kit-canary-${id()}`;
|
|
260
|
+
const hostFiles = [join(tmpdir(), name), join(homedir(), `.${name}`), join(root, name)];
|
|
261
|
+
for (const file of hostFiles) write(file, `${fresh("reads")}\n`);
|
|
262
|
+
|
|
263
|
+
const saved = Object.fromEntries(GITHUB_VARIABLES.map((v) => [v, process.env[v]]));
|
|
264
|
+
const variables = Object.fromEntries(GITHUB_VARIABLES.map((v) => [v, fresh("github")]));
|
|
265
|
+
Object.assign(process.env, variables);
|
|
266
|
+
|
|
267
|
+
/** Everything of the repository and the canary files that must not change. */
|
|
268
|
+
const state = () => ({
|
|
269
|
+
repo: [
|
|
270
|
+
git("rev-parse", "HEAD"),
|
|
271
|
+
git("status", "--porcelain", "--untracked-files=all"),
|
|
272
|
+
readFileSync(join(root, ".git", "config"), "utf8"),
|
|
273
|
+
readFileSync(join(root, "README.md"), "utf8"),
|
|
274
|
+
].join("\0"),
|
|
275
|
+
files: hostFiles.map((f) => readFileSync(f, "utf8")).join("\0"),
|
|
276
|
+
});
|
|
277
|
+
const before = state();
|
|
278
|
+
|
|
279
|
+
return {
|
|
280
|
+
root,
|
|
281
|
+
commit: git("rev-parse", "HEAD"),
|
|
282
|
+
control,
|
|
283
|
+
sweepControl,
|
|
284
|
+
canaries,
|
|
285
|
+
/** The planted GitHub variables, as the runner's environment holds them. */
|
|
286
|
+
variables,
|
|
287
|
+
hostFiles,
|
|
288
|
+
unchanged() {
|
|
289
|
+
const same = (part) => {
|
|
290
|
+
try {
|
|
291
|
+
return state()[part] === before[part];
|
|
292
|
+
} catch {
|
|
293
|
+
// What can no longer be read has changed.
|
|
294
|
+
return false;
|
|
295
|
+
}
|
|
296
|
+
};
|
|
297
|
+
return { repo: same("repo"), files: same("files") };
|
|
298
|
+
},
|
|
299
|
+
remove() {
|
|
300
|
+
for (const [v, value] of Object.entries(saved)) {
|
|
301
|
+
if (value === undefined) delete process.env[v];
|
|
302
|
+
else process.env[v] = value;
|
|
303
|
+
}
|
|
304
|
+
for (const file of hostFiles) rmSync(file, { force: true });
|
|
305
|
+
rmSync(root, { recursive: true, force: true });
|
|
306
|
+
},
|
|
307
|
+
};
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
/** The host's own IPv4 addresses, apart from loopback. */
|
|
311
|
+
export function hostAddresses() {
|
|
312
|
+
return Object.values(networkInterfaces())
|
|
313
|
+
.flat()
|
|
314
|
+
.filter((i) => i && !i.internal && i.family === "IPv4")
|
|
315
|
+
.map((i) => i.address);
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
/**
|
|
319
|
+
* A listener on every address of the host, which counts what connects: the
|
|
320
|
+
* sandbox must never. `check` is the control, run before the sandbox exists:
|
|
321
|
+
* each address answers the host itself.
|
|
322
|
+
*/
|
|
323
|
+
export async function listen(addresses = hostAddresses()) {
|
|
324
|
+
let hits = 0;
|
|
325
|
+
const server = createServer((socket) => {
|
|
326
|
+
hits += 1;
|
|
327
|
+
socket.on("error", () => {});
|
|
328
|
+
socket.destroy();
|
|
329
|
+
});
|
|
330
|
+
await new Promise((resolve, reject) => {
|
|
331
|
+
server.once("error", reject);
|
|
332
|
+
server.listen(0, "0.0.0.0", () => resolve(undefined));
|
|
333
|
+
});
|
|
334
|
+
const { port } = /** @type {import("node:net").AddressInfo} */ (server.address());
|
|
335
|
+
const reaches = (host) =>
|
|
336
|
+
new Promise((resolve) => {
|
|
337
|
+
const socket = connect({ host, port });
|
|
338
|
+
const done = (ok) => {
|
|
339
|
+
socket.destroy();
|
|
340
|
+
resolve(ok);
|
|
341
|
+
};
|
|
342
|
+
socket.setTimeout(3000, () => done(false));
|
|
343
|
+
// The server's end of it closes once counted.
|
|
344
|
+
socket.once("close", () => done(true));
|
|
345
|
+
socket.once("error", () => done(false));
|
|
346
|
+
socket.resume();
|
|
347
|
+
});
|
|
348
|
+
return {
|
|
349
|
+
targets: addresses.map((host) => ({ host, port })),
|
|
350
|
+
async check() {
|
|
351
|
+
const answered = await Promise.all(addresses.map(reaches));
|
|
352
|
+
hits = 0;
|
|
353
|
+
return addresses.length > 0 && answered.every(Boolean);
|
|
354
|
+
},
|
|
355
|
+
hits: () => hits,
|
|
356
|
+
close: () => new Promise((resolve) => server.close(() => resolve(undefined))),
|
|
357
|
+
};
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
/** Whether the host reaches every outside target the sandbox must not: the control. */
|
|
361
|
+
export async function hostReachesOutside(fetch = globalThis.fetch) {
|
|
362
|
+
const reaches = async (url) => {
|
|
363
|
+
for (let i = 0; i < OUTSIDE_TRIES; i += 1) {
|
|
364
|
+
try {
|
|
365
|
+
await fetch(url, { signal: AbortSignal.timeout(15_000), redirect: "manual" });
|
|
366
|
+
return true;
|
|
367
|
+
} catch {
|
|
368
|
+
// Tried again.
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
return false;
|
|
372
|
+
};
|
|
373
|
+
return (await Promise.all(OUTSIDE_URLS.map(reaches))).every(Boolean);
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
/**
|
|
377
|
+
* What the host reads of a running sandbox, before it is destroyed: its
|
|
378
|
+
* settings as `docker inspect` shows them, the markers a planted config left,
|
|
379
|
+
* and the harness's own output.
|
|
380
|
+
* @param {import("../exec.mjs").Runner} runner
|
|
381
|
+
* @param {string} container
|
|
382
|
+
*/
|
|
383
|
+
export function inspectSandbox(runner, container) {
|
|
384
|
+
const exec = (script) => runner("docker", ["exec", container, "sh", "-c", script]);
|
|
385
|
+
const inspected = runner("docker", ["container", "inspect", "--format", "{{json .}}", container]);
|
|
386
|
+
let sandbox = null;
|
|
387
|
+
if (inspected.status === 0) {
|
|
388
|
+
const info = JSON.parse(inspected.stdout);
|
|
389
|
+
sandbox = {
|
|
390
|
+
runtime: String(info.HostConfig?.Runtime ?? ""),
|
|
391
|
+
privileged: info.HostConfig?.Privileged !== false,
|
|
392
|
+
mounts: info.Mounts ?? [],
|
|
393
|
+
env: info.Config?.Env ?? [],
|
|
394
|
+
};
|
|
395
|
+
}
|
|
396
|
+
const output = exec("cat /agent-kit/logs/agent.log /agent-kit/logs/agent.err");
|
|
397
|
+
return {
|
|
398
|
+
sandbox,
|
|
399
|
+
markers: markersIn(runner, container),
|
|
400
|
+
transcript: output.status === 0 ? output.stdout : null,
|
|
401
|
+
};
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
/** The markers in the sandbox, or null when they could not be listed. */
|
|
405
|
+
export function markersIn(runner, container) {
|
|
406
|
+
const r = runner("docker", [
|
|
407
|
+
"exec",
|
|
408
|
+
container,
|
|
409
|
+
"sh",
|
|
410
|
+
"-c",
|
|
411
|
+
`if [ -d ${MARKER_DIR} ]; then ls -1 ${MARKER_DIR}; fi`,
|
|
412
|
+
]);
|
|
413
|
+
return r.status === 0 ? r.stdout.split("\n").filter(Boolean) : null;
|
|
414
|
+
}
|