@mnaimfaizy/agent-kit 1.0.0-beta.14 → 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 (76) hide show
  1. package/README.md +22 -4
  2. package/custom-harness.schema.json +243 -0
  3. package/harnesses.json +244 -6
  4. package/package.json +3 -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/rulesets.mjs +9 -8
  10. package/src/checks/secrets-and-variables.mjs +27 -8
  11. package/src/checks/stages.mjs +705 -0
  12. package/src/cli.mjs +270 -33
  13. package/src/deep-scan/agent.mjs +88 -21
  14. package/src/deep-scan/credential.mjs +81 -32
  15. package/src/deep-scan/docker-driver.mjs +105 -42
  16. package/src/deep-scan/harness-text.mjs +99 -0
  17. package/src/deep-scan/lifecycle.mjs +68 -178
  18. package/src/deep-scan/limits.mjs +13 -7
  19. package/src/deep-scan/model-proxy.mjs +21 -10
  20. package/src/deep-scan/preflight.mjs +19 -6
  21. package/src/deep-scan/recipe.mjs +4 -0
  22. package/src/deep-scan/runtime.mjs +54 -6
  23. package/src/deep-scan/sandbox-run.mjs +232 -0
  24. package/src/deep-scan/sbx-driver.mjs +224 -39
  25. package/src/deep-scan/tar.mjs +69 -22
  26. package/src/deep-scan/verify.mjs +6 -1
  27. package/src/deep-scan.mjs +73 -13
  28. package/src/doctor.mjs +113 -4
  29. package/src/harness/adapters.mjs +30 -0
  30. package/src/harness/antigravity.mjs +187 -0
  31. package/src/harness/claude-code.mjs +8 -1
  32. package/src/harness/codex.mjs +219 -0
  33. package/src/harness/cursor.mjs +199 -0
  34. package/src/harness/custom/registry.mjs +21 -0
  35. package/src/harness/custom/schema.mjs +90 -0
  36. package/src/harness/custom.mjs +299 -0
  37. package/src/harness/facts.mjs +44 -7
  38. package/src/harness/gemini.mjs +164 -0
  39. package/src/harness/install-layer.mjs +86 -3
  40. package/src/harness/opencode.mjs +289 -0
  41. package/src/harness/resolve.mjs +156 -0
  42. package/src/harness/support-levels.mjs +151 -3
  43. package/src/harness-live/assess.mjs +29 -6
  44. package/src/harness-live/cursor-real.mjs +146 -0
  45. package/src/harness-live/cursor-version.mjs +70 -0
  46. package/src/harness-live/cursor.mjs +80 -0
  47. package/src/harness-live/custom.mjs +91 -0
  48. package/src/harness-live/fixture-harness.mjs +45 -0
  49. package/src/harness-live/harnesses.mjs +263 -0
  50. package/src/harness-live/host.mjs +113 -4
  51. package/src/harness-live/opencode.mjs +289 -0
  52. package/src/harness-live/probes.mjs +87 -7
  53. package/src/harness-live/run.mjs +101 -20
  54. package/src/harness-live/setup.mjs +126 -0
  55. package/src/harness-live/stage.mjs +25 -15
  56. package/src/harness-live/suite.mjs +276 -95
  57. package/src/harness-test.mjs +116 -0
  58. package/src/init.mjs +313 -13
  59. package/src/model-proxy/core.mjs +128 -20
  60. package/src/model-proxy/profiles/anthropic.mjs +54 -10
  61. package/src/model-proxy/profiles/gemini-api.mjs +311 -0
  62. package/src/model-proxy/profiles/openai.mjs +327 -0
  63. package/src/model-proxy/stub-dialects/gemini-api.mjs +178 -0
  64. package/src/model-proxy/stub-dialects/openai.mjs +173 -0
  65. package/src/model-proxy/stub.mjs +9 -1
  66. package/src/stage/audit.mjs +79 -0
  67. package/src/stage/egress-route.mjs +207 -0
  68. package/src/stage/implement/carry.mjs +308 -0
  69. package/src/stage/implement/sandbox.mjs +271 -0
  70. package/src/stage/implement/verify.mjs +70 -0
  71. package/src/stage/implement.mjs +218 -0
  72. package/src/stage/plan.mjs +115 -0
  73. package/src/stage/review-response.mjs +172 -0
  74. package/src/stage/review.mjs +185 -0
  75. package/src/stage/workspace.mjs +274 -0
  76. package/src/stage.mjs +1068 -0
@@ -1,21 +1,22 @@
1
1
  // The Deep scan sandbox lifecycle (#369), from image to teardown, on the
2
2
  // runtime `selectRuntime` chose. In order: prepare the image (the Harness
3
- // image, or the recipe's with the harness copied from it, ADR 0029: a pinned
4
- // Claude Code, its auto-updater off); start the sandbox with no mount; copy
3
+ // image, or the recipe's with the harness copied from it, ADR 0029: the pinned
4
+ // harness, its updater off); start the sandbox with no mount; copy
5
5
  // in an export of the trusted ref (never the working tree) and the grounding
6
6
  // files, and nothing else; run the setup phase (`setup`, `start`, `ready`,
7
7
  // `seed`) with no agent and no model credential, its egress limited to the
8
8
  // recipe's `registries`; cut the network and check from the host that it is
9
9
  // cut; open the model route (the key-injecting model proxy on the host, the
10
10
  // scan's only way out) and check from the host that nothing else is open;
11
- // hand the agent its brief and run the real Claude Code (#370); copy out the
11
+ // hand the agent its brief and run the real harness (#370); copy out the
12
12
  // one report file; and destroy the sandbox on every exit path, an interrupt
13
13
  // included. The real model credential reaches only the model proxy, in this
14
14
  // process: the sandbox gets a placeholder.
15
15
  //
16
16
  // Every run is bounded from out here (#371): the setup wall clock runs from
17
17
  // the image step until the agent step starts, the scan wall clock over the
18
- // agent step, Claude Code runs with the launcher's `--max-turns`, and the
18
+ // agent step, the harness takes the launcher's `--max-turns` where it has a
19
+ // turn limit, and the
19
20
  // model proxy refuses requests past the token cap. A limit that fires stops
20
21
  // the running step through the same seam an interrupt does, then the report
21
22
  // it left is copied out with the launcher's `Stopped:` line, and the sandbox
@@ -25,27 +26,24 @@
25
26
  // Kata, Firecracker on Docker Engine) and sbx-driver.mjs (Docker
26
27
  // Sandboxes). This module owns the order, the output and every refusal.
27
28
 
28
- import { randomBytes } from "node:crypto";
29
29
  import { mkdtempSync, writeFileSync } from "node:fs";
30
30
  import { tmpdir } from "node:os";
31
31
  import { join } from "node:path";
32
32
  import { firstLine } from "../exec.mjs";
33
- import { agentBrief, agentPlan, agentScript, BRIEF_PATH, turnsMarker } from "./agent.mjs";
34
- import { callerKeyFor } from "./credential.mjs";
35
- import { dockerDriver, LABEL } from "./docker-driver.mjs";
36
- import { groundingUrlProblem, isGroundingUrl } from "./grounding-url.mjs";
37
33
  import {
38
- LimitReached,
39
- STOPPED_EXIT,
40
- stoppedStatus,
41
- TOKENS,
42
- TURNS,
43
- WALL_CLOCK,
44
- withStopped,
45
- } from "./limits.mjs";
46
- import { startModelProxy } from "./model-proxy.mjs";
47
- import { sbxDriver } from "./sbx-driver.mjs";
48
- import { ENDS_HERE, indent, Interrupted, outputLines, StepFailed } from "./steps.mjs";
34
+ agentBrief,
35
+ agentPlan,
36
+ agentScript,
37
+ BRIEF_PATH,
38
+ credentialMarker,
39
+ turnsMarker,
40
+ } from "./agent.mjs";
41
+ import { LABEL } from "./docker-driver.mjs";
42
+ import { textFor } from "./harness-text.mjs";
43
+ import { groundingUrlProblem, isGroundingUrl } from "./grounding-url.mjs";
44
+ import { LimitReached, STOPPED_EXIT, stoppedStatus, TURNS, withStopped } from "./limits.mjs";
45
+ import { cutNetwork, openModelRoute, runInSandbox } from "./sandbox-run.mjs";
46
+ import { ENDS_HERE, indent, outputLines, StepFailed } from "./steps.mjs";
49
47
  import { tarOf } from "./tar.mjs";
50
48
  import { checkVerificationReport, FINDINGS_PATH, verificationBrief } from "./verify.mjs";
51
49
 
@@ -70,18 +68,22 @@ const GROUNDING_TIMEOUT_MS = 60_000;
70
68
  const PUBLIC_LOG = "the Public-log rule: this log is world-readable in GitHub Actions";
71
69
 
72
70
  /**
73
- * The line a run prints when the model API answered every request with a
74
- * 401 or 403: the credential's kind and where it came from (a variable's
75
- * name, or 1Password), never its value.
71
+ * The line a run prints when the model API refused the credential in every
72
+ * answer (a 401 or 403, or what the harness's API answers beside them): the
73
+ * credential's kind and where it came from (a variable's name, or
74
+ * 1Password), never its value.
76
75
  * @param {"api-key" | "subscription"} kind
77
76
  * @param {string} from
77
+ * @param {string} harness
78
+ * @param {string} [model]
78
79
  */
79
- function credentialRefusedLine(kind, from) {
80
+ function credentialRefusedLine(kind, from, harness, model) {
81
+ const text = textFor(harness, model);
80
82
  const what =
81
83
  kind === "subscription"
82
84
  ? `the Claude subscription token from ${from} was not accepted (its value is not shown). Make a fresh one with claude setup-token, then run deep-scan again.`
83
- : `the API key from ${from} was not accepted (its value is not shown). Check that the key is current and its Anthropic Console workspace is active, then run deep-scan again.`;
84
- return `The model API refused the credential: every answer was 401 or 403, so ${what}`;
85
+ : `the API key from ${from} was not accepted (its value is not shown). ${text.keyRefused}, then run deep-scan again.`;
86
+ return `The model API refused the credential: every answer was ${text.refusedAs ?? "401 or 403"}, so ${what}`;
85
87
  }
86
88
 
87
89
  /** How many lines of the harness's error output a failed agent step shows. */
@@ -99,6 +101,8 @@ const SETUP_ORDER = ["setup", "start", "ready", "seed"];
99
101
  * start: (steps: object) => Promise<{ isolation?: string } | void>,
100
102
  * copyIn: (tar: Buffer, what: string) => Promise<void>,
101
103
  * installAgent: (out: Function) => Promise<void>,
104
+ * carryOut: (script: string, opts: { maxBytes: number }) => Promise<{ data: Buffer } | { error: string }>,
105
+ * renew: () => Promise<void>,
102
106
  * openSetupEgress: (registries: string[]) => Promise<{ env: string[], note: string }>,
103
107
  * refused: () => string[],
104
108
  * exec: (script: string, opts?: { env?: string[], workdir?: string | null }) => Promise<import("../exec.mjs").StartResult>,
@@ -130,6 +134,7 @@ const SETUP_ORDER = ["setup", "start", "ready", "seed"];
130
134
  * credential: string,
131
135
  * credentialKind?: "api-key" | "subscription",
132
136
  * credentialFrom?: string,
137
+ * harness?: string,
133
138
  * limits: import("./limits.mjs").Limits,
134
139
  * model?: string,
135
140
  * effort?: string,
@@ -157,103 +162,15 @@ const SETUP_ORDER = ["setup", "start", "ready", "seed"];
157
162
  * }} Verification
158
163
  */
159
164
  export async function runLifecycle(opts) {
160
- const { runner, runtime, out, err, signals } = opts;
161
- const controller = new AbortController();
162
- const { signal } = controller;
163
- const handlers = Object.fromEntries(
164
- ["SIGINT", "SIGTERM"].map((sig) => [
165
- sig,
166
- () => {
167
- if (signal.aborted) return;
168
- err(`Interrupted (${sig}): stopping the current step and destroying the sandbox.`);
169
- controller.abort(sig);
170
- },
171
- ]),
172
- );
173
- for (const [sig, handler] of Object.entries(handlers)) signals.on(sig, handler);
174
-
175
- const interrupted = () => new Interrupted(String(signal.reason ?? "SIGINT"));
176
-
177
- // The phase clocks. A limit aborts only the phase's own controller, so the
178
- // steps after it (the copy-out, the teardown) still run.
179
- const { timers, limits } = opts;
180
- /** @type {{ controller: AbortController, timer: unknown } | null} */
181
- let phase = null;
182
- /** @type {{ limit: string, detail: string } | null} */
183
- let stopped = null;
184
- const stop = (limit, detail) => {
185
- if (stopped || signal.aborted) return;
186
- stopped = { limit, detail };
187
- err(`${stoppedStatus(stopped)} Stopping the current step.`);
188
- phase?.controller.abort(stopped);
189
- };
190
- const clocks = {
191
- begin(name, minutes) {
192
- const controller = new AbortController();
193
- const timer = timers.setTimeout(
194
- () => stop(WALL_CLOCK, `the ${name} phase's ${minutes}-minute limit`),
195
- minutes * 60_000,
196
- );
197
- phase = { controller, timer };
198
- if (stopped) controller.abort(stopped);
199
- },
200
- end() {
201
- if (phase) timers.clearTimeout(phase.timer);
202
- phase = null;
203
- },
204
- stop,
205
- stopped: () => stopped,
206
- /** The signal a step stops on: an interrupt, or its phase's limit. */
207
- signal: () => (phase ? AbortSignal.any([signal, phase.controller.signal]) : signal),
208
- /** What a step stopped by `clocks.signal()` throws. */
209
- reason: () => (signal.aborted ? interrupted() : new LimitReached(stopped)),
210
- };
211
-
212
- /** @type {import("./docker-driver.mjs").Call} */
213
- const call = async (cmd, args, { stdin, cwd, maxOutput } = {}) => {
214
- const stepSignal = clocks.signal();
215
- if (stepSignal.aborted) throw clocks.reason();
216
- const r = await runner.start(cmd, args, { stdin, cwd, maxOutput, signal: stepSignal });
217
- if (r.aborted || stepSignal.aborted) throw clocks.reason();
218
- if (r.truncated) return r;
219
- // Ctrl+C in a terminal reaches the runtime's child too, and can end it
220
- // before the handler above runs: that is an interrupt, not a failure.
221
- if (r.signal === "SIGINT" || r.signal === "SIGTERM") throw new Interrupted(r.signal);
222
- return r;
223
- };
224
- const id = randomBytes(6).toString("hex");
225
165
  // The harness's launch plan: the drivers put its install layer on the image.
226
- const plan = agentPlan({ kind: opts.credentialKind });
227
- const driver =
228
- runtime.id === "sbx"
229
- ? sbxDriver({ id, call, plan })
230
- : dockerDriver({ runtime, id, call, plan });
231
-
232
- let code;
233
- let thrown = null;
234
- try {
235
- code = await lifecycle({ ...opts, driver, clocks });
236
- } catch (e) {
237
- if (e instanceof LimitReached) {
238
- // A limit before the agent step: there is no report to deliver.
239
- out(`${stoppedStatus(e.stop)} No report came out: nothing was written, filed or posted.`);
240
- code = STOPPED_EXIT;
241
- } else if (e instanceof Interrupted) {
242
- code = e.signal === "SIGTERM" ? 143 : 130;
243
- } else if (e instanceof StepFailed) {
244
- err(e.lines.join("\n"));
245
- code = 1;
246
- } else {
247
- thrown = e;
248
- }
249
- }
250
- clocks.end();
251
- await driver.close();
252
- const tornDown = teardown(runner, driver.teardown(), out, err);
253
- driver.cleanup?.();
254
- for (const [sig, handler] of Object.entries(handlers)) signals.off(sig, handler);
255
- if (thrown) throw thrown;
256
- return (code === 0 || code === STOPPED_EXIT) && !tornDown ? 1 : code;
166
+ const plan = agentPlan({
167
+ harness: opts.harness,
168
+ kind: opts.credentialKind,
169
+ model: opts.model,
170
+ });
171
+ return runInSandbox({ ...opts, plan }, ({ driver, clocks }) =>
172
+ lifecycle({ ...opts, driver, clocks }),
173
+ );
257
174
  }
258
175
 
259
176
  async function lifecycle({
@@ -269,6 +186,7 @@ async function lifecycle({
269
186
  credential,
270
187
  credentialKind = "api-key",
271
188
  credentialFrom = "its source",
189
+ harness = "claude-code",
272
190
  limits,
273
191
  model,
274
192
  effort,
@@ -414,35 +332,20 @@ async function lifecycle({
414
332
  }
415
333
 
416
334
  // 5. Cut the network, and check from the host that it is cut.
417
- await driver.cutEgress();
418
- const left = await driver.egressLeft();
419
- if (left !== null) {
420
- throw new StepFailed([`FAILED the network is not cut: ${left}.`, ENDS_HERE]);
421
- }
422
- out("Network: cut (checked from the host); the agent step has no network.");
335
+ await cutNetwork(driver, out);
423
336
 
424
337
  // 6. The model route: the key-injecting model proxy on this machine, the
425
338
  // scan's only way out, and the check from the host that nothing else is.
426
- // The run's caller key: the sandboxed Claude Code holds it, and the proxy
427
- // forwards only a request that carries it.
428
- const callerKey = callerKeyFor(credentialKind);
429
- let proxy = null;
430
- const route = await driver.openModelRoute(async (bind) => {
431
- proxy = await startModelProxy({
432
- credential,
433
- kind: credentialKind,
434
- bind,
435
- callerKey,
436
- maxTokens: limits.tokens,
437
- onCap: () => clocks.stop(TOKENS, `the run's ${limits.tokens}-token cap`),
438
- ...(modelApi !== undefined ? { upstream: modelApi } : {}),
439
- });
440
- return proxy;
339
+ const { callerKey, route, proxy } = await openModelRoute({
340
+ driver,
341
+ clocks,
342
+ harness,
343
+ model,
344
+ credential,
345
+ credentialKind,
346
+ maxTokens: limits.tokens,
347
+ modelApi,
441
348
  });
442
- const extra = await driver.egressLeft();
443
- if (extra !== null) {
444
- throw new StepFailed([`FAILED more than the model route is open: ${extra}.`, ENDS_HERE]);
445
- }
446
349
  if (route.isolation) out(route.isolation);
447
350
  out(
448
351
  `Model route: only the model proxy on your machine (${route.note}), which forwards to the model API alone, with your ${credentialKind === "subscription" ? "token as its bearer value" : "key"}; checked from the host.`,
@@ -466,8 +369,10 @@ async function lifecycle({
466
369
  grounding,
467
370
  paths,
468
371
  discovers: subscription,
372
+ harness,
469
373
  })
470
374
  : agentBrief({
375
+ harness,
471
376
  branch,
472
377
  short,
473
378
  recipePath,
@@ -489,6 +394,7 @@ async function lifecycle({
489
394
  : "copying the launcher's brief in",
490
395
  );
491
396
  const plan = agentPlan({
397
+ harness,
492
398
  baseUrl: route.url,
493
399
  maxTurns: limits.turns,
494
400
  model,
@@ -499,8 +405,10 @@ async function lifecycle({
499
405
  const { displayName, version } = plan.identity;
500
406
  /** What the line says for a model or effort not asked for. */
501
407
  const unasked = `${displayName}'s default`;
408
+ const text = textFor(harness, model);
409
+ const turnCap = text.turnLimit ? `at most ${limits.turns} turns` : "no turn limit";
502
410
  out(
503
- `Agent step: ${displayName} ${version} (${subscription ? "no --bare: the subscription path, with a placeholder token; project settings and MCP servers not loaded" : "--bare, a placeholder key"}, web tools off, at most ${limits.turns} turns; requested model: ${model ?? unasked}, effort: ${effort ?? unasked}), handed ${verification ? "the Verification-run procedure, the finding file" : "the deep procedure"}, the Threat pack and the Scan recipe.`,
411
+ `Agent step: ${displayName} ${version} (${text.agentStep(credentialKind)}, ${turnCap}; requested model: ${model ?? unasked}, effort: ${effort ?? unasked}), handed ${verification ? "the Verification-run procedure, the finding file" : "the deep procedure"}, the Threat pack and the Scan recipe.`,
504
412
  );
505
413
  clocks.end();
506
414
  // The scan wall clock: the agent step alone.
@@ -528,11 +436,21 @@ async function lifecycle({
528
436
  ? `Model proxy: ${proxy ? "closed" : "not started"} (${PUBLIC_LOG}).`
529
437
  : `Model proxy: ${proxy?.summary() ?? "not started"}.`,
530
438
  );
531
- // Every answer a 401 or 403: say plainly that the credential was refused,
439
+ // The harness said it has no credential it reads: the script's fixed line.
440
+ if (
441
+ agent &&
442
+ agent.status !== 0 &&
443
+ agent.stdout.toString("utf8").split(/\r?\n/).includes(credentialMarker(plan))
444
+ ) {
445
+ err(
446
+ `No model credential: ${displayName} said authentication is required, so it read no API key in the sandbox and asked for a sign-in, which deep-scan never gives it. This is a fault of the harness's launch, not of your key: report it with this line.`,
447
+ );
448
+ }
449
+ // Every answer a refusal: say plainly that the credential was refused,
532
450
  // its kind and where it came from, never its value. Locally only: a public
533
451
  // log gets none of the model API's answers.
534
452
  if (!publicLog && proxy?.credentialRefused())
535
- err(credentialRefusedLine(credentialKind, credentialFrom));
453
+ err(credentialRefusedLine(credentialKind, credentialFrom, harness, model));
536
454
  const stopped = clocks.stopped();
537
455
  if (stopped) {
538
456
  out(`${stoppedStatus(stopped)} Copying out what report the agent left.`);
@@ -628,34 +546,6 @@ async function lifecycle({
628
546
  return agent?.status === 0 ? 0 : 1;
629
547
  }
630
548
 
631
- /**
632
- * Run each teardown command, whatever happened before. Synchronous, so it
633
- * finishes even while an interrupt is pending.
634
- * @returns {boolean} whether nothing was left behind
635
- */
636
- function teardown(runner, commands, out, err) {
637
- if (!commands.length) return true;
638
- const left = [];
639
- for (const { what, cmd, args } of commands) {
640
- const r = runner(cmd, args);
641
- if (r.status !== 0 && !/no such|not found/i.test(r.stderr)) {
642
- left.push(`${what}: ${firstLine(r.stderr) || `exit ${r.status}`}`);
643
- }
644
- }
645
- if (left.length) {
646
- err(
647
- [
648
- "TEARDOWN could not remove:",
649
- ...left.map((l) => ` - ${l}`),
650
- `Remove them by hand; every Docker resource carries the label ${LABEL}, and every sandbox's name starts with agent-kit-deep-.`,
651
- ].join("\n"),
652
- );
653
- return false;
654
- }
655
- out(`Teardown: removed ${commands.map((c) => c.what).join(", ")}.`);
656
- return true;
657
- }
658
-
659
549
  async function fetchGrounding(fetch, url, where, clocks) {
660
550
  const fail = (why) =>
661
551
  new StepFailed([`FAILED ${where}: could not fetch ${url}: ${why}`, ENDS_HERE]);
@@ -1,7 +1,8 @@
1
1
  // The limits that bound every Deep scan (#371), all enforced from outside
2
2
  // the sandbox: the setup and scan wall clocks by the launcher, the turns by
3
- // the launcher's own `--max-turns` on the claude command line, and the token
4
- // cap by the model proxy, which counts the model API's returned `usage`.
3
+ // the launcher's own `--max-turns` on the claude command line (a harness with
4
+ // no turn limit, such as Codex CLI, has none), and the token cap by the model
5
+ // proxy, which counts the model API's returned `usage`.
5
6
  // Limits come from launcher flags only (and, in CI, workflow inputs): the
6
7
  // Scan recipe never sets them (recipe.mjs refuses a limit field), so a
7
8
  // merged recipe change cannot raise a run's spend.
@@ -73,12 +74,17 @@ export function parseLimits(values, defaults = DEFAULT_LIMITS) {
73
74
  return { limits };
74
75
  }
75
76
 
76
- /** The limits as one line of the launcher's output. */
77
- export function describeLimits(limits) {
78
- const flags = Object.values(LIMIT_FLAGS)
79
- .map((f) => `--${f.flag}`)
77
+ /**
78
+ * The limits as one line of the launcher's output. A harness with no turn
79
+ * limit (`turnLimit: false`) names none.
80
+ */
81
+ export function describeLimits(limits, { turnLimit = true } = {}) {
82
+ const flags = Object.entries(LIMIT_FLAGS)
83
+ .filter(([key]) => turnLimit || key !== "turns")
84
+ .map(([, f]) => `--${f.flag}`)
80
85
  .join(", ");
81
- return `Limits: setup ${limits.setupMinutes} min, scan ${limits.scanMinutes} min, ${limits.turns} turns, ${limits.tokens} tokens (raise them with ${flags}).`;
86
+ const turns = turnLimit ? `${limits.turns} turns, ` : "";
87
+ return `Limits: setup ${limits.setupMinutes} min, scan ${limits.scanMinutes} min, ${turns}${limits.tokens} tokens (raise them with ${flags}).`;
82
88
  }
83
89
 
84
90
  /** A run stopped by a limit: what fired, said for a person. */
@@ -1,12 +1,18 @@
1
1
  // The scan phase's only route out (#370): the model proxy's core
2
2
  // (../model-proxy/core.mjs), which runs in the launcher, on the host, outside
3
- // the sandbox, with the `anthropic` provider profile (ADR 0023). The core's
4
- // header says what is forwarded and how the run's token cap (#371) holds; the
5
- // profile's says what of the Messages API passes, and how the real credential
6
- // goes in. Node core only (ADR 0001).
3
+ // the sandbox, with the provider profile the harness's launch plan names
4
+ // (ADR 0023): `anthropic`, `openai` or `gemini-api`. The core's header says what is
5
+ // forwarded and how the run's token cap (#371) holds; each profile's says what
6
+ // of its API passes, and how the real credential goes in. Node core only
7
+ // (ADR 0001).
7
8
 
8
9
  import { startProxy } from "../model-proxy/core.mjs";
9
10
  import { anthropic } from "../model-proxy/profiles/anthropic.mjs";
11
+ import { geminiApi } from "../model-proxy/profiles/gemini-api.mjs";
12
+ import { openai } from "../model-proxy/profiles/openai.mjs";
13
+
14
+ /** The provider profiles a launch plan's model route may name. */
15
+ export const PROFILES = Object.freeze({ anthropic, openai, "gemini-api": geminiApi });
10
16
 
11
17
  export { MAX_IN_FLIGHT, MODEL_ID } from "../model-proxy/core.mjs";
12
18
  export {
@@ -20,13 +26,15 @@ export {
20
26
  /**
21
27
  * Start the Deep scan's model proxy on `bind`. See startProxy in the core for
22
28
  * every option and for what it returns.
23
- * @param {{ credential: string, kind?: "api-key" | "subscription", bind: string, upstream?: string, maxTokens?: number, onCap?: () => void, callerKey?: string }} opts
24
- * `kind` is the credential's (default an API key). `upstream` is the
25
- * model API; only tests pass another. `callerKey`, when given, is the
26
- * only value accepted as the caller's `x-api-key` or `Authorization`
27
- * bearer value; the launcher always gives one.
29
+ * @param {{ profile?: string, credential: string, kind?: "api-key" | "subscription", bind: string, upstream?: string, maxTokens?: number, onCap?: () => void, callerKey?: string }} opts
30
+ * `profile` names one of PROFILES (default `anthropic`). `kind` is the
31
+ * credential's (default an API key). `upstream` is the model API; only
32
+ * tests pass another. `callerKey`, when given, is the only value accepted
33
+ * as the caller's key, in the profile's key headers or as a bearer value;
34
+ * the launcher always gives one.
28
35
  */
29
36
  export async function startModelProxy({
37
+ profile = "anthropic",
30
38
  credential,
31
39
  kind = "api-key",
32
40
  bind,
@@ -35,7 +43,10 @@ export async function startModelProxy({
35
43
  onCap,
36
44
  callerKey,
37
45
  }) {
38
- return startProxy(anthropic, {
46
+ if (!Object.hasOwn(PROFILES, profile)) {
47
+ throw new Error(`the model proxy has no provider profile ${JSON.stringify(profile)}`);
48
+ }
49
+ return startProxy(PROFILES[profile], {
39
50
  credential,
40
51
  kind,
41
52
  bind,
@@ -9,7 +9,7 @@
9
9
 
10
10
  import { appendFileSync } from "node:fs";
11
11
  import { firstLine } from "../exec.mjs";
12
- import { readHarnesses, supportFor } from "../harness/facts.mjs";
12
+ import { harnessFacts, supportFor } from "../harness/facts.mjs";
13
13
  import { MUSL_MARKER } from "../harness/install-layer.mjs";
14
14
  import { ENDS_HERE, outputLines, StepFailed } from "./steps.mjs";
15
15
 
@@ -44,13 +44,26 @@ export function refuseMusl(r, { image, dockerfile }) {
44
44
  * @returns {{ line: string, summary: string, refused?: string, warning?: string }}
45
45
  */
46
46
  export function deepScanSupport({ harness = "claude-code", provingRun = false }) {
47
- const facts = readHarnesses().harnesses[harness];
48
- const found = supportFor(facts, { stage: "deep-scan", provingRun });
49
- const level = facts.supportLevels["deep-scan"]?.level ?? "none";
47
+ return stageSupport({ harness, stage: "deep-scan", provingRun });
48
+ }
49
+
50
+ /**
51
+ * The same for any Stage the Launcher runs (`security-audit`, `deep-scan`).
52
+ * A Custom harness is marked "custom, attested" where its file attests the
53
+ * pair's level, which the kit cannot check (ADR 0028).
54
+ * @param {{ harness: string, stage: string, provingRun?: boolean }} run
55
+ * @returns {{ line: string, summary: string, refused?: string, warning?: string }}
56
+ */
57
+ export function stageSupport({ harness, stage, provingRun = false }) {
58
+ const facts = harnessFacts(harness);
59
+ const found = supportFor(facts, { stage, provingRun });
60
+ const level = facts.supportLevels[stage]?.level ?? "none";
50
61
  const proving = provingRun ? "yes" : "no";
62
+ const attested = level === "documented" ? "no attestation" : "attested";
63
+ const custom = facts.custom ? ` (custom, ${attested})` : "";
51
64
  return {
52
- line: `Harness: ${harness}; Support Level: ${level}; Proving run: ${proving}`,
53
- summary: `Harness: \`${harness}\` · Support Level: \`${level}\` · Proving run: ${proving}`,
65
+ line: `Harness: ${harness}${custom}; Support Level: ${level}; Proving run: ${proving}`,
66
+ summary: `Harness: \`${harness}\`${custom} · Support Level: \`${level}\` · Proving run: ${proving}`,
54
67
  ...(found.refused !== undefined ? { refused: found.refused } : {}),
55
68
  ...(found.warning !== undefined ? { warning: found.warning } : {}),
56
69
  };
@@ -56,6 +56,10 @@ const CREDENTIALS = [
56
56
  [/\bgh[pousr]_[A-Za-z0-9]{20,}/, "a GitHub token"],
57
57
  [/\bgithub_pat_[A-Za-z0-9_]{20,}/, "a GitHub token"],
58
58
  [/\bsk-ant-[A-Za-z0-9_-]{10,}/, "an Anthropic API key"],
59
+ [/\bsk-(?:proj|svcacct|admin)-[A-Za-z0-9_-]{10,}/, "an OpenAI API key"],
60
+ // A legacy user key, by the marker inside it.
61
+ [/\bsk-[A-Za-z0-9_-]{0,100}T3BlbkFJ/, "an OpenAI API key"],
62
+ [/\bAIza[0-9A-Za-z_-]{35}/, "a Google API key"],
59
63
  [/\bAKIA[0-9A-Z]{16}\b/, "an AWS access key"],
60
64
  [/\bxox[abposr]-[A-Za-z0-9-]{10,}/, "a Slack token"],
61
65
  [/-----BEGIN [A-Z ]*PRIVATE KEY-----/, "a private key"],
@@ -3,7 +3,7 @@
3
3
  // maintainer's other environments. The launcher chooses the runtime itself,
4
4
  // from checks made on the host (the runtimes' own CLIs and Docker's runtime
5
5
  // registry), never from a check inside the sandbox, which the target could
6
- // fake. Preference: Docker Sandboxes, then Kata or Firecracker (Linux), then
6
+ // fake. Preference: Docker Sandboxes (0.55.0 or later), then Kata or Firecracker (Linux), then
7
7
  // gVisor (Linux), the last two on Docker Engine 28.0 or later, whose
8
8
  // isolated gateway mode leaves the host no address on a sandbox network
9
9
  // (#404). A Mac uses Docker Sandboxes: Docker Desktop for macOS has no way
@@ -17,13 +17,53 @@ export const RUNTIMES_DOCS_URL = `https://github.com/mnaimfaizy/agent-kit/blob/v
17
17
 
18
18
  /** The lines every runtime refusal ends with: what is accepted, and the CI path. */
19
19
  export const ACCEPTED_LINES = Object.freeze([
20
- "Accepted runtimes: Docker Sandboxes (sbx); Kata Containers or Firecracker on Linux; gVisor (runsc) on Linux; the last two on Docker Engine 28.0 or later.",
20
+ "Accepted runtimes: Docker Sandboxes (sbx) 0.55.0 or later; Kata Containers or Firecracker on Linux; gVisor (runsc) on Linux; the last two on Docker Engine 28.0 or later.",
21
21
  "There is no override: on a host without one of them, use the CI path.",
22
22
  "CI path: the deep-scan reusable workflow runs the scan in a gVisor container on an ephemeral GitHub-hosted runner.",
23
23
  ]);
24
24
 
25
25
  const PLATFORMS = { linux: "Linux", darwin: "macOS", win32: "Windows" };
26
26
 
27
+ /**
28
+ * The oldest Docker Sandboxes deep-scan runs on. Before 0.55.0, sbx's host-side
29
+ * key injection sent a stored API key to the domains a third-party kit named,
30
+ * not the ones the developer approved (CVE-2026-136998).
31
+ */
32
+ export const MIN_SBX = Object.freeze({ major: 0, minor: 55, patch: 0 });
33
+ const MIN_SBX_TEXT = `${MIN_SBX.major}.${MIN_SBX.minor}.${MIN_SBX.patch}`;
34
+
35
+ /**
36
+ * Refusal lines when `sbx version`'s output names a version older than
37
+ * MIN_SBX or none that can be read (as in "sbx version v0.54.0 4bec4a5c"),
38
+ * else null.
39
+ * @param {string} text
40
+ * @returns {string[] | null}
41
+ */
42
+ export function sbxProblem(text) {
43
+ const m = /(?:^|\s)v?(\d+)\.(\d+)\.(\d+)(-[0-9A-Za-z.-]+)?/.exec(text);
44
+ const upgrade = `Upgrade Docker Sandboxes (sbx) to ${MIN_SBX_TEXT} or later, then run deep-scan again.`;
45
+ if (!m) {
46
+ return [
47
+ `Could not read the Docker Sandboxes version from \`sbx version\` (${JSON.stringify(firstLine(text))}); deep-scan runs it only on ${MIN_SBX_TEXT} or later (CVE-2026-136998).`,
48
+ upgrade,
49
+ ];
50
+ }
51
+ const [major, minor, patch] = [Number(m[1]), Number(m[2]), Number(m[3])];
52
+ // A pre-release of the minimum (0.55.0-rc.1) sorts before it (semver).
53
+ const pre = m[4];
54
+ const ok =
55
+ major !== MIN_SBX.major
56
+ ? major > MIN_SBX.major
57
+ : minor !== MIN_SBX.minor
58
+ ? minor > MIN_SBX.minor
59
+ : patch > MIN_SBX.patch || (patch === MIN_SBX.patch && !pre);
60
+ if (ok) return null;
61
+ return [
62
+ `Docker Sandboxes (sbx) ${major}.${minor}.${patch}${pre ?? ""} is older than ${MIN_SBX_TEXT}, the oldest deep-scan runs on: before ${MIN_SBX_TEXT} sbx could send a stored API key to domains the developer never approved (CVE-2026-136998).`,
63
+ upgrade,
64
+ ];
65
+ }
66
+
27
67
  /** The oldest Docker Engine deep-scan runs Kata, Firecracker or gVisor on. */
28
68
  export const MIN_DOCKER_ENGINE = Object.freeze({ major: 28, minor: 0 });
29
69
 
@@ -41,19 +81,23 @@ export function selectRuntime({ runner, platform }) {
41
81
  const host = PLATFORMS[platform] ?? platform;
42
82
  const succeeds = (cmd, args) => runner(cmd, args).status === 0;
43
83
 
44
- if (succeeds("sbx", ["version"])) {
45
- return { runtime: { id: "sbx", name: "Docker Sandboxes (sbx)" } };
84
+ const sbxVersion = runner("sbx", ["version"]);
85
+ let sbxNote = [];
86
+ if (sbxVersion.status === 0) {
87
+ const old = sbxProblem(sbxVersion.stdout.toString("utf8"));
88
+ if (old === null) return { runtime: { id: "sbx", name: "Docker Sandboxes (sbx)" } };
89
+ sbxNote = old;
46
90
  }
47
91
 
48
92
  const info = dockerInfo(runner);
49
93
  // A Mac's one accepted runtime is Docker Sandboxes: say so in every refusal.
50
94
  const mac =
51
- platform === "darwin"
95
+ platform === "darwin" && sbxNote.length === 0
52
96
  ? [
53
97
  "On macOS, deep-scan runs on Docker Sandboxes (sbx), whose per-sandbox policy lets the sandbox reach the model proxy's port alone: install it. Docker Desktop for macOS has no way to keep a container from your machine's other services.",
54
98
  ]
55
99
  : [];
56
- const refuse = (...lines) => ({ refused: [...lines, ...mac, ...ACCEPTED_LINES] });
100
+ const refuse = (...lines) => ({ refused: [...sbxNote, ...lines, ...mac, ...ACCEPTED_LINES] });
57
101
 
58
102
  if (platform === "linux" && info.ok) {
59
103
  const viaDocker = (id, label, pattern, cli) => {
@@ -77,6 +121,8 @@ export function selectRuntime({ runner, platform }) {
77
121
  `Upgrade Docker Engine to ${MIN} or later, or use Docker Sandboxes (sbx).`,
78
122
  );
79
123
  }
124
+ // An old sbx is installed: say to upgrade it, not to install one.
125
+ if (sbxNote.length) return refuse();
80
126
  const install =
81
127
  "Install one of: gVisor (runsc), Kata Containers or Firecracker, each registered as a Docker runtime, or Docker Sandboxes (sbx).";
82
128
  if (info.os === "Docker Desktop") {
@@ -91,6 +137,8 @@ export function selectRuntime({ runner, platform }) {
91
137
  );
92
138
  }
93
139
 
140
+ if (sbxNote.length) return refuse();
141
+
94
142
  if (
95
143
  platform === "win32" &&
96
144
  info.ok &&