@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.
Files changed (79) hide show
  1. package/README.md +24 -5
  2. package/custom-harness.schema.json +243 -0
  3. package/harnesses.json +286 -0
  4. package/package.json +4 -2
  5. package/src/checks/ci-workflow.mjs +105 -0
  6. package/src/checks/claude-app.mjs +11 -2
  7. package/src/checks/custom-harness.mjs +157 -0
  8. package/src/checks/github-app.mjs +214 -0
  9. package/src/checks/review-response.mjs +54 -27
  10. package/src/checks/rulesets.mjs +9 -8
  11. package/src/checks/secrets-and-variables.mjs +220 -43
  12. package/src/checks/stages.mjs +705 -0
  13. package/src/cli.mjs +277 -31
  14. package/src/deep-scan/agent.mjs +145 -117
  15. package/src/deep-scan/credential.mjs +88 -42
  16. package/src/deep-scan/docker-driver.mjs +131 -49
  17. package/src/deep-scan/harness-text.mjs +99 -0
  18. package/src/deep-scan/lifecycle.mjs +92 -199
  19. package/src/deep-scan/limits.mjs +13 -7
  20. package/src/deep-scan/model-proxy.mjs +47 -602
  21. package/src/deep-scan/preflight.mjs +81 -1
  22. package/src/deep-scan/recipe.mjs +7 -7
  23. package/src/deep-scan/runtime.mjs +54 -6
  24. package/src/deep-scan/sandbox-run.mjs +232 -0
  25. package/src/deep-scan/sbx-driver.mjs +242 -50
  26. package/src/deep-scan/tar.mjs +69 -22
  27. package/src/deep-scan/verify.mjs +6 -1
  28. package/src/deep-scan.mjs +98 -14
  29. package/src/doctor.mjs +113 -4
  30. package/src/harness/adapters.mjs +30 -0
  31. package/src/harness/antigravity.mjs +187 -0
  32. package/src/harness/claude-code.mjs +236 -0
  33. package/src/harness/codex.mjs +219 -0
  34. package/src/harness/cursor.mjs +199 -0
  35. package/src/harness/custom/registry.mjs +21 -0
  36. package/src/harness/custom/schema.mjs +90 -0
  37. package/src/harness/custom.mjs +299 -0
  38. package/src/harness/facts.mjs +157 -0
  39. package/src/harness/gemini.mjs +164 -0
  40. package/src/harness/install-layer.mjs +141 -0
  41. package/src/harness/opencode.mjs +289 -0
  42. package/src/harness/resolve.mjs +156 -0
  43. package/src/harness/support-levels.mjs +197 -0
  44. package/src/harness-live/assess.mjs +291 -0
  45. package/src/harness-live/cursor-real.mjs +146 -0
  46. package/src/harness-live/cursor-version.mjs +70 -0
  47. package/src/harness-live/cursor.mjs +80 -0
  48. package/src/harness-live/custom.mjs +91 -0
  49. package/src/harness-live/fixture-harness.mjs +45 -0
  50. package/src/harness-live/harnesses.mjs +263 -0
  51. package/src/harness-live/host.mjs +414 -0
  52. package/src/harness-live/opencode.mjs +289 -0
  53. package/src/harness-live/probes.mjs +239 -0
  54. package/src/harness-live/run.mjs +214 -0
  55. package/src/harness-live/setup.mjs +126 -0
  56. package/src/harness-live/stage.mjs +161 -0
  57. package/src/harness-live/suite.mjs +481 -0
  58. package/src/harness-test.mjs +116 -0
  59. package/src/init.mjs +339 -23
  60. package/src/model-proxy/core.mjs +657 -0
  61. package/src/model-proxy/profiles/anthropic.mjs +241 -0
  62. package/src/model-proxy/profiles/gemini-api.mjs +311 -0
  63. package/src/model-proxy/profiles/openai.mjs +327 -0
  64. package/src/model-proxy/stub-dialects/anthropic.mjs +110 -0
  65. package/src/model-proxy/stub-dialects/gemini-api.mjs +178 -0
  66. package/src/model-proxy/stub-dialects/openai.mjs +173 -0
  67. package/src/model-proxy/stub.mjs +182 -0
  68. package/src/stage/audit.mjs +79 -0
  69. package/src/stage/egress-route.mjs +207 -0
  70. package/src/stage/implement/carry.mjs +308 -0
  71. package/src/stage/implement/sandbox.mjs +271 -0
  72. package/src/stage/implement/verify.mjs +70 -0
  73. package/src/stage/implement.mjs +218 -0
  74. package/src/stage/plan.mjs +115 -0
  75. package/src/stage/review-response.mjs +172 -0
  76. package/src/stage/review.mjs +185 -0
  77. package/src/stage/workspace.mjs +274 -0
  78. package/src/stage.mjs +1068 -0
  79. package/src/deep-scan/claude-code.mjs +0 -25
@@ -32,8 +32,10 @@
32
32
  // scan's only route to the internet.
33
33
 
34
34
  import { isIPv4 } from "node:net";
35
- import { layerDockerfile } from "./claude-code.mjs";
35
+ import { firstLine } from "../exec.mjs";
36
+ import { layerDockerfile, pinnedHarnessImage } from "../harness/install-layer.mjs";
36
37
  import { startEgressProxy } from "./egress.mjs";
38
+ import { refuseMusl } from "./preflight.mjs";
37
39
  import { imageDigestNote } from "./recipe.mjs";
38
40
  import {
39
41
  OTHER_HOST_PORT,
@@ -50,7 +52,7 @@ export const LABEL = "agent-kit.deep-scan";
50
52
 
51
53
  /**
52
54
  * @typedef {import("../exec.mjs").StartResult} StartResult
53
- * @typedef {(cmd: string, args: string[], opts?: { stdin?: Buffer | string, cwd?: string, maxOutput?: number }) => Promise<StartResult>} Call
55
+ * @typedef {(cmd: string, args: string[], opts?: { stdin?: Buffer | string, cwd?: string, maxOutput?: number, env?: Record<string, string> }) => Promise<StartResult>} Call
54
56
  * Runs a command without blocking; throws Interrupted when the run is.
55
57
  */
56
58
 
@@ -61,10 +63,34 @@ export const ISOLATED_OPTIONS = Object.freeze([
61
63
  ]);
62
64
 
63
65
  /**
64
- * @param {{ runtime: import("./runtime.mjs").Runtime, id: string, call: Call }} opts
66
+ * Split an exec's `NAME=value` entries for the runtime CLI's command line: a
67
+ * variable the harness scrubs (its model credential) goes as `NAME` alone, its
68
+ * value in that one child's environment, so no argv holds it.
69
+ * @param {string[]} env
70
+ * @param {string[]} secret the plan's `launch.secretEnv`: variables whose value is a real credential
71
+ * @param {string} flag
72
+ */
73
+ export function envArgs(env, secret, flag) {
74
+ const args = [];
75
+ const childEnv = {};
76
+ for (const entry of env) {
77
+ const eq = entry.indexOf("=");
78
+ const name = eq < 0 ? entry : entry.slice(0, eq);
79
+ if (eq >= 0 && secret.includes(name)) {
80
+ childEnv[name] = entry.slice(eq + 1);
81
+ args.push(flag, name);
82
+ } else args.push(flag, entry);
83
+ }
84
+ return { args, childEnv };
85
+ }
86
+
87
+ /**
88
+ * @param {{ runtime: import("./runtime.mjs").Runtime, id: string, call: Call, plan: import("../harness/claude-code.mjs").LaunchPlan }} opts
89
+ * `plan` is the harness's launch plan: its install layer goes on the image.
65
90
  * @returns {import("./lifecycle.mjs").Driver}
66
91
  */
67
- export function dockerDriver({ runtime, id, call }) {
92
+ export function dockerDriver({ runtime, id, call, plan }) {
93
+ const { displayName } = plan.identity;
68
94
  const name = `agent-kit-deep-${id}`;
69
95
  const label = `${LABEL}=${id}`;
70
96
  const docker = (args, opts) => call("docker", args, opts);
@@ -91,11 +117,30 @@ export function dockerDriver({ runtime, id, call }) {
91
117
  let hostGateway = null;
92
118
  /** The relay image, once built. */
93
119
  let relayImage = null;
120
+ /** What the sandbox runs: the Harness image, or the run's layered image. */
121
+ let sandboxImage = null;
94
122
 
95
123
  return {
96
124
  container: name,
97
125
 
98
- async prepare(steps, { archive, out, branch, short }) {
126
+ async prepare(steps, { archive, out, branch, short, why = "the recipe names no image" }) {
127
+ // A Custom harness has no Harness image: its npm package is layered on
128
+ // the recipe's image, or on the kit's base.
129
+ const { npm } = plan.installLayer;
130
+ const harness = npm === undefined ? pinnedHarnessImage(plan.installLayer) : null;
131
+ const named = steps.dockerfile !== undefined || steps.image !== undefined;
132
+ // No image of the recipe's: the sandbox runs the Harness image, which
133
+ // is not this run's to remove.
134
+ if (!named && harness !== null) {
135
+ out(
136
+ `Image: pulling the Harness image ${harness}, which holds the pinned ${displayName}; ${why}.`,
137
+ );
138
+ must(await docker(["pull", harness]), `pulling the Harness image ${harness}`, {
139
+ showOutput: true,
140
+ });
141
+ sandboxImage = harness;
142
+ return;
143
+ }
99
144
  let base;
100
145
  if (steps.dockerfile !== undefined) {
101
146
  out(`Image: building ${steps.dockerfile} from ${branch} (${short}).`);
@@ -110,22 +155,27 @@ export function dockerDriver({ runtime, id, call }) {
110
155
  `building ${steps.dockerfile}`,
111
156
  { showOutput: true },
112
157
  );
113
- } else {
158
+ } else if (steps.image !== undefined) {
114
159
  base = steps.image;
115
160
  out(`Image: pulling ${base}.`);
116
161
  const note = imageDigestNote(base);
117
162
  if (note) out(note);
118
163
  must(await docker(["pull", base]), `pulling ${base}`, { showOutput: true });
119
164
  }
120
- out("Image: layering the pinned Claude Code, auto-updater off.");
121
- resources.push(["image", name]);
122
- must(
123
- await docker(["build", "--label", label, "--tag", name, "-"], {
124
- stdin: layerDockerfile(base),
125
- }),
126
- `layering Claude Code on ${base}`,
127
- { showOutput: true },
165
+ out(
166
+ npm === undefined
167
+ ? `Image: layering the pinned ${displayName}, auto-updater off, from the Harness image ${harness}.`
168
+ : `Image: installing ${npm} from npm for ${displayName}, on ${named ? "that image" : `the kit's base image; ${why}`}.`,
128
169
  );
170
+ resources.push(["image", name]);
171
+ const layered = await docker(["build", "--label", label, "--tag", name, "-"], {
172
+ stdin: layerDockerfile(base, plan.installLayer),
173
+ });
174
+ refuseMusl(layered, steps);
175
+ must(layered, `layering ${displayName} on ${base ?? "the kit's base image"}`, {
176
+ showOutput: true,
177
+ });
178
+ sandboxImage = name;
129
179
  },
130
180
 
131
181
  /**
@@ -146,30 +196,7 @@ export function dockerDriver({ runtime, id, call }) {
146
196
  throw new StepFailed([`FAILED the setup network is not isolated: ${why}.`, ENDS_HERE]);
147
197
  }
148
198
  resources.push(["container", name]);
149
- must(
150
- await docker([
151
- "run",
152
- "--detach",
153
- "--init",
154
- "--name",
155
- name,
156
- "--label",
157
- label,
158
- ...(runtime.dockerRuntime ? ["--runtime", runtime.dockerRuntime] : []),
159
- "--network",
160
- network,
161
- "--security-opt",
162
- "no-new-privileges",
163
- "--workdir",
164
- "/workspace",
165
- "--entrypoint",
166
- "tail",
167
- name,
168
- "-f",
169
- "/dev/null",
170
- ]),
171
- "starting the sandbox",
172
- );
199
+ await runSandbox("starting the sandbox");
173
200
  await onAlone(network, "the setup network");
174
201
  return {
175
202
  isolation: setupRelay
@@ -193,9 +220,39 @@ export function dockerDriver({ runtime, id, call }) {
193
220
  );
194
221
  },
195
222
 
196
- /** Claude Code is already in the image. */
223
+ /** The harness is already in the image. */
197
224
  async installAgent() {},
198
225
 
226
+ /**
227
+ * The archive `script` writes to its output, run as root in the sandbox
228
+ * (ADR 0047). Through `docker exec`, never `docker cp`, which under gVisor
229
+ * cannot read what the sandbox wrote (#404).
230
+ */
231
+ async carryOut(script, { maxBytes }) {
232
+ const r = await docker(
233
+ ["exec", "--user", "0:0", "--workdir", "/", name, "sh", "-c", script],
234
+ { maxOutput: maxBytes },
235
+ );
236
+ if (r.truncated) return { error: `it is larger than ${maxBytes / 1024 ** 3} GiB` };
237
+ if (r.status !== 0) {
238
+ return {
239
+ error: `tar exited ${r.status ?? "abnormally"}: ${firstLine(r.stderr) || "no output"}`,
240
+ };
241
+ }
242
+ return { data: r.stdout };
243
+ },
244
+
245
+ /**
246
+ * Remove the sandbox, and every process in it, and start a fresh one from
247
+ * the same image on the same network, which the cut left with nothing to
248
+ * reach (ADR 0047). It keeps the sandbox's name.
249
+ */
250
+ async renew() {
251
+ must(await docker(["rm", "--force", name]), "removing the setup container");
252
+ await runSandbox("starting the agent's container");
253
+ await onAlone(network, "its network");
254
+ },
255
+
199
256
  /** The setup egress was opened with the network: the proxy's variables. */
200
257
  async openSetupEgress(registries) {
201
258
  return registries.length
@@ -208,16 +265,13 @@ export function dockerDriver({ runtime, id, call }) {
208
265
 
209
266
  refused: () => proxy?.refused ?? [],
210
267
 
211
- exec: (script, { env = [], workdir = "/workspace" } = {}) =>
212
- docker([
213
- "exec",
214
- ...env.flatMap((v) => ["--env", v]),
215
- ...(workdir ? ["--workdir", workdir] : []),
216
- name,
217
- "sh",
218
- "-c",
219
- script,
220
- ]),
268
+ exec: (script, { env = [], workdir = "/workspace" } = {}) => {
269
+ const { args, childEnv } = envArgs(env, plan.launch?.secretEnv ?? [], "--env");
270
+ return docker(
271
+ ["exec", ...args, ...(workdir ? ["--workdir", workdir] : []), name, "sh", "-c", script],
272
+ { env: childEnv },
273
+ );
274
+ },
221
275
 
222
276
  /**
223
277
  * The cut: stop the egress proxy and remove the setup relay. Nothing is
@@ -346,6 +400,34 @@ export function dockerDriver({ runtime, id, call }) {
346
400
  },
347
401
  };
348
402
 
403
+ /** `docker run` of the sandbox, on its one network, idle until a step execs. */
404
+ async function runSandbox(what) {
405
+ must(
406
+ await docker([
407
+ "run",
408
+ "--detach",
409
+ "--init",
410
+ "--name",
411
+ name,
412
+ "--label",
413
+ label,
414
+ ...(runtime.dockerRuntime ? ["--runtime", runtime.dockerRuntime] : []),
415
+ "--network",
416
+ network,
417
+ "--security-opt",
418
+ "no-new-privileges",
419
+ "--workdir",
420
+ "/workspace",
421
+ "--entrypoint",
422
+ "tail",
423
+ sandboxImage,
424
+ "-f",
425
+ "/dev/null",
426
+ ]),
427
+ what,
428
+ );
429
+ }
430
+
349
431
  async function closeProxy() {
350
432
  if (proxy) {
351
433
  const p = proxy;
@@ -0,0 +1,99 @@
1
+ // What a Deep scan says that differs by harness: in the brief, in its output
2
+ // and in its refusals. Everything else comes from the harness's launch plan
3
+ // (ADR 0027) and `cli/harnesses.json`.
4
+
5
+ import { TEXT as cursorText } from "../harness/cursor.mjs";
6
+ import { loadedCustom } from "../harness/custom/registry.mjs";
7
+ import { PROVIDERS, providerOf } from "../harness/opencode.mjs";
8
+
9
+ /**
10
+ * @typedef {{
11
+ * webOff: string,
12
+ * agentStep: (kind: string) => string,
13
+ * turnLimit: boolean,
14
+ * needsKey: string,
15
+ * keyRefused: string,
16
+ * refusedAs?: string,
17
+ * noSubscription?: string,
18
+ * }} HarnessText `webOff` says that what of the harness's own reaches the web
19
+ * is off. `agentStep` is what the agent step's line says the harness runs
20
+ * with. `turnLimit` is whether it takes a turn limit. `needsKey` is what a
21
+ * run with no API key is told it needs, and `keyRefused` what to check when
22
+ * the model API refuses the key. `refusedAs` names the statuses its API
23
+ * refuses one with, where they are not 401 and 403. `noSubscription` says why
24
+ * `--credential subscription` is refused, where there is more to say than
25
+ * that the harness takes none.
26
+ */
27
+
28
+ /** @type {Readonly<Record<string, Readonly<HarnessText>>>} */
29
+ export const HARNESS_TEXT = Object.freeze({
30
+ "claude-code": Object.freeze({
31
+ webOff: "the web tools (WebFetch, WebSearch) are off",
32
+ agentStep: (kind) =>
33
+ `${kind === "subscription" ? "no --bare: the subscription path, with a placeholder token; project settings and MCP servers not loaded" : "--bare, a placeholder key"}, web tools off`,
34
+ turnLimit: true,
35
+ needsKey: "deep-scan needs an Anthropic API key",
36
+ keyRefused: "Check that the key is current and its Anthropic Console workspace is active",
37
+ }),
38
+ codex: Object.freeze({
39
+ webOff: "Codex CLI's web search is off",
40
+ agentStep: () =>
41
+ "a placeholder key, web search off, the checkout's Codex config removed and no AGENTS.md loaded",
42
+ turnLimit: false,
43
+ needsKey: "deep-scan on Codex CLI needs an OpenAI API key",
44
+ keyRefused: "Check that the key is current and its OpenAI project is active",
45
+ }),
46
+ gemini: Object.freeze({
47
+ webOff: "Gemini CLI's web search and web fetch tools are off",
48
+ agentStep: () => "a placeholder key, web tools off, the checkout's Gemini config removed",
49
+ turnLimit: true,
50
+ needsKey: "deep-scan on Gemini CLI needs a Gemini API key",
51
+ keyRefused: "Check that the key is current and its Google Cloud project is active",
52
+ refusedAs: "401, 403 or, for a key it does not know, 400",
53
+ }),
54
+ antigravity: Object.freeze({
55
+ webOff: "Antigravity CLI's web search tool is off",
56
+ agentStep: () =>
57
+ "a placeholder key, an agent with local tools alone, the checkout's Antigravity config removed",
58
+ turnLimit: false,
59
+ needsKey: "deep-scan on Antigravity CLI needs a Gemini API key",
60
+ noSubscription:
61
+ "A Google sign-in cannot stay outside the sandbox: signed in, Antigravity CLI calls a Google host the model proxy cannot front, and Google's Antigravity terms bar access through third-party software.",
62
+ keyRefused: "Check that the key is current and its Google Cloud project is active",
63
+ refusedAs: "401, 403 or, for a key it does not know, 400",
64
+ }),
65
+ opencode: Object.freeze({
66
+ webOff: "opencode's web search, web fetch, image and video tools are off",
67
+ agentStep: () => "a placeholder key, web tools off, the checkout's opencode config removed",
68
+ turnLimit: false,
69
+ // textFor names the provider the run's model picks.
70
+ needsKey: "deep-scan on opencode needs the API key of its model's provider",
71
+ keyRefused: "Check that the key is current and its provider's account is active",
72
+ }),
73
+ cursor: cursorText,
74
+ });
75
+
76
+ /**
77
+ * `harness`'s text for a run on `model`: on opencode, whose model picks the
78
+ * provider, the key it names is that provider's, and so are the statuses its
79
+ * API refuses a key with.
80
+ * @param {string} harness
81
+ * @param {string} [model]
82
+ * @returns {Readonly<HarnessText>}
83
+ */
84
+ export function textFor(harness, model) {
85
+ const text = loadedCustom(harness)?.text ?? HARNESS_TEXT[harness];
86
+ if (harness !== "opencode") return text;
87
+ const chosen = providerOf(model);
88
+ if ("refused" in chosen) return text;
89
+ const { displayName } = PROVIDERS[chosen.provider];
90
+ return {
91
+ ...text,
92
+ needsKey: `deep-scan on opencode needs the ${displayName} API key its ${chosen.provider}/ model runs on`,
93
+ keyRefused: `Check that the ${displayName} API key is current and its account is active`,
94
+ // The Gemini API refuses a key it does not know with a 400 too.
95
+ ...(chosen.provider === "google"
96
+ ? { refusedAs: "401, 403 or, for a key the Gemini API does not know, 400" }
97
+ : {}),
98
+ };
99
+ }