@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
package/src/deep-scan.mjs CHANGED
@@ -1,4 +1,9 @@
1
1
  // `agent-kit deep-scan`: the host-side launcher for a Deep scan (ADR 0019).
2
+ // Its harness is `--harness`'s, else the Stage setting's
3
+ // (harness/resolve.mjs): Claude Code, Codex CLI, Gemini CLI, Antigravity CLI
4
+ // or opencode, each by its adapter.
5
+ // It first refuses a harness whose Support Level for the Deep scan is below
6
+ // `tried`, unless the run is a Proving run (`--proving-run`, ADR 0028).
2
7
  // Its first stage finds the Consumer's Scan recipe at the trusted ref (the
3
8
  // default branch's tip, never the working tree) and validates it, or refuses
4
9
  // with what is wrong and a pointer to the docs. There is no fallback to a
@@ -9,7 +14,7 @@
9
14
  // process); then the choice of a sandbox runtime from the host, or its
10
15
  // refusal, with no override (ADR 0018). Then the sandbox lifecycle on that
11
16
  // runtime, from image to teardown (deep-scan/lifecycle.mjs), its agent step
12
- // the real Claude Code behind the key-injecting model proxy, every run
17
+ // the real harness behind the key-injecting model proxy, every run
13
18
  // bounded by the limits its flags set (deep-scan/limits.mjs). With
14
19
  // `--verify <file> --ref <ref>`, the run is a Verification run instead
15
20
  // (deep-scan/verify.mjs): local only, confirm-only against the finding file,
@@ -36,11 +41,21 @@ import {
36
41
  SUBSCRIPTION,
37
42
  withoutCredentials,
38
43
  } from "./deep-scan/credential.mjs";
44
+ import { textFor } from "./deep-scan/harness-text.mjs";
39
45
  import { DEFAULT_LIMITS, describeLimits, parseLimits, VERIFY_LIMITS } from "./deep-scan/limits.mjs";
40
46
  import { publicHttpsFetch } from "./deep-scan/grounding-url.mjs";
41
47
  import { runLifecycle } from "./deep-scan/lifecycle.mjs";
42
48
  import { MODEL_ID } from "./deep-scan/model-proxy.mjs";
43
- import { envFilesAtRef, envFilesCarriedFromDefault, strayTokens } from "./deep-scan/preflight.mjs";
49
+ import {
50
+ deepScanSupport,
51
+ envFilesAtRef,
52
+ envFilesCarriedFromDefault,
53
+ strayTokens,
54
+ writeRunSummary,
55
+ } from "./deep-scan/preflight.mjs";
56
+ import { adapterFor } from "./harness/adapters.mjs";
57
+ import { effortFor, harnessFacts, readHarnesses } from "./harness/facts.mjs";
58
+ import { loadHarness, modelRefusal, resolveHarness } from "./harness/resolve.mjs";
44
59
  import { RUNTIMES_DOCS_URL, selectRuntime } from "./deep-scan/runtime.mjs";
45
60
  import {
46
61
  readFindingFile,
@@ -50,13 +65,25 @@ import {
50
65
  } from "./deep-scan/verify.mjs";
51
66
  import { CLI_VERSION } from "./tags.mjs";
52
67
 
68
+ /** Each harness, as `cli/harnesses.json` describes it. */
69
+ const HARNESSES = readHarnesses().harnesses;
70
+
71
+ /** The effort levels Claude Code accepts: nothing else reaches its command line. */
72
+ export const EFFORTS = Object.freeze(HARNESSES["claude-code"].effortValues);
73
+
74
+ /** `a, b or c`. */
75
+ const either = (words) => `${words.slice(0, -1).join(", ")} or ${words.at(-1)}`;
76
+
53
77
  const CREDENTIALS_DOCS_URL = `https://github.com/mnaimfaizy/agent-kit/blob/v${CLI_VERSION}/docs/security-audit.md#credentials`;
78
+ const HARNESS_DOCS_URL = `https://github.com/mnaimfaizy/agent-kit/blob/v${CLI_VERSION}/docs/harnesses.md`;
79
+ const PROVING_DOCS_URL = `https://github.com/mnaimfaizy/agent-kit/blob/v${CLI_VERSION}/docs/harnesses.md#proving-runs`;
54
80
 
55
81
  /**
56
82
  * @param {{
57
83
  * cwd: string,
58
84
  * runner: import("./exec.mjs").Runner,
59
85
  * recipePath?: string,
86
+ * harness?: string,
60
87
  * defaultBranch?: string,
61
88
  * credential?: string,
62
89
  * credentialFrom?: string,
@@ -65,6 +92,7 @@ const CREDENTIALS_DOCS_URL = `https://github.com/mnaimfaizy/agent-kit/blob/v${CL
65
92
  * reportPath?: string,
66
93
  * verifyPath?: string,
67
94
  * ref?: string,
95
+ * provingRun?: boolean,
68
96
  * limitFlags?: Record<string, string | undefined>,
69
97
  * platform?: string,
70
98
  * env?: Record<string, string | undefined>,
@@ -78,6 +106,8 @@ const CREDENTIALS_DOCS_URL = `https://github.com/mnaimfaizy/agent-kit/blob/v${CL
78
106
  * }} opts `limitFlags` holds the limit flags' values, keyed by flag name.
79
107
  * `verifyPath` (a finding file) and `ref` go together, for a
80
108
  * Verification run.
109
+ * `provingRun` runs a harness below `tried` for the Deep scan, to record
110
+ * the evidence that raises its level; it relaxes nothing else.
81
111
  * `platform`, `env`, `fetch`, `signals` and `timers` are the host's
82
112
  * (`process.platform`, `process.env`, the public-HTTPS grounding fetch, `process`, the
83
113
  * real clock), and `reportDir` is a new private temporary folder, and
@@ -91,6 +121,7 @@ export async function runDeepScan({
91
121
  cwd,
92
122
  runner: hostRunner,
93
123
  recipePath,
124
+ harness: harnessFlag,
94
125
  defaultBranch,
95
126
  credential,
96
127
  credentialFrom,
@@ -99,6 +130,7 @@ export async function runDeepScan({
99
130
  reportPath,
100
131
  verifyPath,
101
132
  ref,
133
+ provingRun = false,
102
134
  limitFlags = {},
103
135
  platform = process.platform,
104
136
  env = process.env,
@@ -163,9 +195,38 @@ export async function runDeepScan({
163
195
  );
164
196
  return 2;
165
197
  }
166
- if (effort !== undefined && !EFFORTS.includes(effort)) {
198
+ // The harness (ADR 0022), before anything reads its facts.
199
+ const resolved = resolveHarness({ stage: "deep-scan", flag: harnessFlag, env });
200
+ if ("refused" in resolved) {
201
+ if (resolved.unknown && harnessFlag !== undefined) {
202
+ err(resolved.refused);
203
+ return 2;
204
+ }
205
+ return refuse([resolved.refused], HARNESS_DOCS_URL);
206
+ }
207
+ const { harness } = resolved;
208
+ // A Custom harness is its file on the default branch (ADR 0027).
209
+ const custom = loadHarness({
210
+ harness,
211
+ runner: withoutCredentials(hostRunner, [env, process.env]),
212
+ cwd,
213
+ defaultBranch,
214
+ flags: ["--default-branch"],
215
+ });
216
+ if (custom.refused !== undefined) return refuse(custom.refused, HARNESS_DOCS_URL);
217
+ const facts = harnessFacts(harness);
218
+ const text = textFor(harness, model);
219
+
220
+ // On opencode the model picks the provider, which needs a proxy profile.
221
+ const unrouted = modelRefusal(harness, model);
222
+ if (unrouted !== null) return refuse([unrouted], HARNESS_DOCS_URL);
223
+
224
+ // The Stage's own effort: one its harness does not accept is refused.
225
+ if (effort !== undefined && (effort === "" || "refused" in effortFor(facts, { effort }))) {
167
226
  err(
168
- `--effort must be one of ${EFFORTS.slice(0, -1).join(", ")} or ${EFFORTS.at(-1)}, got: ${JSON.stringify(effort)}`,
227
+ facts.noEffort
228
+ ? `${facts.displayName} has no effort setting: leave --effort out.`
229
+ : `--effort must be one of ${either(facts.effortValues)}, got: ${JSON.stringify(effort)}`,
169
230
  );
170
231
  return 2;
171
232
  }
@@ -200,12 +261,28 @@ export async function runDeepScan({
200
261
  return 2;
201
262
  }
202
263
  const subscription = chosen.kind === SUBSCRIPTION;
203
- const source = credentialSource(credentialFrom, chosen.kind);
264
+ if (!Object.hasOwn(adapterFor(harness)({ model }).credentials.accepted, chosen.kind)) {
265
+ const why = text.noSubscription;
266
+ err(
267
+ `--credential ${chosen.kind} is not one ${facts.displayName} takes: leave it out for its API key.${why === undefined ? "" : ` ${why}`}`,
268
+ );
269
+ return 2;
270
+ }
271
+ const source = credentialSource(credentialFrom, chosen.kind, harness, model);
204
272
  if ("error" in source) {
205
273
  err(source.error);
206
274
  return 2;
207
275
  }
208
276
 
277
+ // The Support Level (ADR 0028), before anything is read or run.
278
+ const support = deepScanSupport({ harness, provingRun });
279
+ // A refused run is named too, in the log and the run summary.
280
+ out(support.line);
281
+ const unwritten = writeRunSummary(env, support.summary);
282
+ if (unwritten !== null) err(`Could not write the run summary: ${unwritten}`);
283
+ if (support.refused !== undefined) return refuse([support.refused], PROVING_DOCS_URL);
284
+ if (support.warning !== undefined) err(`Warning: ${support.warning}`);
285
+
209
286
  // The finding file, read and checked on the host before anything runs.
210
287
  let given = null;
211
288
  if (verifying) {
@@ -331,7 +408,7 @@ export async function runDeepScan({
331
408
  [
332
409
  `${tokens.join(" and ")} ${tokens.length > 1 ? "are" : "is"} set in deep-scan's environment, and a GitHub token must never reach the sandbox.`,
333
410
  `Unset ${tokens.length > 1 ? "them" : "it"} for this run, for example:`,
334
- " env -u GH_TOKEN -u GITHUB_TOKEN npx @mnaimfaizy/agent-kit deep-scan",
411
+ ` env -u GH_TOKEN -u GITHUB_TOKEN npx @mnaimfaizy/agent-kit deep-scan${harnessFlag !== undefined ? ` --harness ${harness}` : ""}${provingRun ? " --proving-run" : ""}`,
335
412
  " In PowerShell: Remove-Item Env:GH_TOKEN, Env:GITHUB_TOKEN -ErrorAction SilentlyContinue, then run it again.",
336
413
  ],
337
414
  RUNTIMES_DOCS_URL,
@@ -411,7 +488,14 @@ export async function runDeepScan({
411
488
  }
412
489
 
413
490
  // The model credential: read once, and kept only in this process.
414
- const key = readCredential({ source, env, runner, kind: chosen.kind });
491
+ const key = readCredential({
492
+ source,
493
+ env,
494
+ runner,
495
+ kind: chosen.kind,
496
+ harness,
497
+ model,
498
+ });
415
499
  if ("refused" in key) return refuse(key.refused, CREDENTIALS_DOCS_URL);
416
500
  out(
417
501
  subscription
@@ -422,8 +506,14 @@ export async function runDeepScan({
422
506
  const choice = selectRuntime({ runner, platform });
423
507
  if ("refused" in choice) return refuse(choice.refused, RUNTIMES_DOCS_URL);
424
508
  out(`Sandbox runtime: ${choice.runtime.name}.`);
425
- out(describeLimits(limits));
509
+ out(describeLimits(limits, { turnLimit: text.turnLimit }));
510
+ if (!text.turnLimit && limitFlags["max-turns"] !== undefined) {
511
+ out(
512
+ `${facts.displayName} has no turn limit, so --max-turns is ignored: the scan wall clock and the token cap bound the run.`,
513
+ );
514
+ }
426
515
  return runLifecycle({
516
+ harness,
427
517
  limits,
428
518
  ...(model !== undefined ? { model } : {}),
429
519
  ...(effort !== undefined ? { effort } : {}),
@@ -454,12 +544,6 @@ export async function runDeepScan({
454
544
  });
455
545
  }
456
546
 
457
- /**
458
- * The effort levels Claude Code's --effort takes (2.1.328's --help), and the
459
- * static workflow's effort input: nothing else reaches the command line.
460
- */
461
- export const EFFORTS = Object.freeze(["low", "medium", "high", "xhigh", "max"]);
462
-
463
547
  /** Text with LF line ends, so a CRLF checkout of the same file compares equal. */
464
548
  const lf = (text) => text.replace(/\r\n?/g, "\n");
465
549
 
package/src/doctor.mjs CHANGED
@@ -4,7 +4,15 @@
4
4
  // skipped. A skipped check is never reported as passed.
5
5
 
6
6
  import { readWorkflows } from "./callers.mjs";
7
+ import { checkCiWorkflow } from "./checks/ci-workflow.mjs";
7
8
  import { checkClaudeApp } from "./checks/claude-app.mjs";
9
+ import {
10
+ checkGitHubApp,
11
+ checkGitHubAppInstalled,
12
+ pushingJobs,
13
+ readAppSettings,
14
+ unreadCallers,
15
+ } from "./checks/github-app.mjs";
8
16
  import { checkKitOwnedTrees } from "./checks/kit-owned-trees.mjs";
9
17
  import { checkLabels } from "./checks/labels.mjs";
10
18
  import { checkPins } from "./checks/pins.mjs";
@@ -24,6 +32,14 @@ import {
24
32
  deriveRequirements,
25
33
  deriveVariables,
26
34
  } from "./checks/secrets-and-variables.mjs";
35
+ import {
36
+ actionJobs,
37
+ checkHarnessVariables,
38
+ checkStages,
39
+ HARNESSES_PATH,
40
+ readHarnessFacts,
41
+ STAGE_CHECKS,
42
+ } from "./checks/stages.mjs";
27
43
  import { firstLine } from "./exec.mjs";
28
44
  import { createGitHub } from "./github.mjs";
29
45
  import { openKitTag, PreManifestTagError, serverFromEnv } from "./kit-tag.mjs";
@@ -49,6 +65,9 @@ export const LOCAL_ONLY_CHECKS = [
49
65
  ["ruleset-tags", "Release tags have a v* tag ruleset"],
50
66
  ["release-tag-push", "Release tags can be pushed under the tag ruleset"],
51
67
  ["review-response-mode", "Review response mode is set up"],
68
+ ["github-app", "Your GitHub App is set up"],
69
+ ["ci-workflow", "CI starts for agent pushes"],
70
+ ...STAGE_CHECKS,
52
71
  ];
53
72
 
54
73
  const skipAll = (ids, reason) => ids.map(([id, title]) => result(id, title, "skip", reason));
@@ -193,7 +212,8 @@ export function runDoctor({
193
212
  ),
194
213
  );
195
214
  } else {
196
- results.push(...localChecks({ runner, cwd, info, files, callers, snapshot }));
215
+ results.push(...localChecks({ runner, cwd, root, info, files, callers, snapshot }));
216
+ results.push(...harnessChecks({ runner, cwd, root, info, callers, snapshot }));
197
217
  }
198
218
  } finally {
199
219
  snapshot?.cleanup();
@@ -226,20 +246,23 @@ export function guarded(id, run, title = TITLES[id] ?? id) {
226
246
  }
227
247
  }
228
248
 
229
- function localChecks({ runner, cwd, info, files, callers, snapshot }) {
249
+ function localChecks({ runner, cwd, root, info, files, callers, snapshot }) {
230
250
  const github = createGitHub(runner, { cwd, hostname: info.host ?? null });
231
251
  const { repo, owner, ownerType, defaultBranch } = info;
232
252
  const raw = [];
233
253
  const out = { push: (...items) => raw.push(...items) };
234
254
 
235
255
  if (snapshot) {
256
+ // A tag that publishes its harness facts asks for each Stage's own
257
+ // credential, in the harness checks.
258
+ const perStageCredential = snapshot.readFile(HARNESSES_PATH) !== null;
236
259
  let requirements = null;
237
260
  out.push(
238
261
  guarded("secrets", () => {
239
262
  requirements = deriveRequirements(callers, (file) =>
240
263
  snapshot.readFile(`.github/workflows/${file}`),
241
264
  );
242
- return checkSecrets({ github, repo, ownerType, requirements });
265
+ return checkSecrets({ github, repo, ownerType, requirements, perStageCredential });
243
266
  }),
244
267
  );
245
268
  out.push(
@@ -285,7 +308,22 @@ function localChecks({ runner, cwd, info, files, callers, snapshot }) {
285
308
  ),
286
309
  );
287
310
 
288
- out.push(guarded("claude-app", () => checkClaudeApp({ github, repo, owner, ownerType })));
311
+ // Read once, and only if a check that uses it runs.
312
+ let onAction = null;
313
+ const actions = () => (onAction ??= actionJobs({ github, repo, ownerType, callers, snapshot }));
314
+ let onApp = null;
315
+ const appActions = () =>
316
+ (onApp ??= actionJobs({ github, repo, ownerType, callers, snapshot, app: true }));
317
+ out.push(
318
+ guarded("claude-app", () => {
319
+ // Only a Stage whose action step takes the Claude GitHub App's token
320
+ // needs it: one given the job token does not. Callers doctor could not
321
+ // read in full may hide such a Stage.
322
+ const needed =
323
+ callers.some((c) => c.parseIncomplete) || [...appActions().values()].some(Boolean);
324
+ return checkClaudeApp({ github, repo, owner, ownerType, needed });
325
+ }),
326
+ );
289
327
 
290
328
  let rulesets = null;
291
329
  let rulesetError = null;
@@ -307,9 +345,80 @@ function localChecks({ runner, cwd, info, files, callers, snapshot }) {
307
345
  checkReviewResponseMode({ github, repo, ownerType, callers }),
308
346
  ),
309
347
  );
348
+ out.push(...appChecks({ github, root, info, callers, snapshot, actions }));
310
349
  return raw;
311
350
  }
312
351
 
352
+ /** The Consumer's own GitHub App, and how CI starts without one. */
353
+ function appChecks({ github, root, info, callers, snapshot, actions }) {
354
+ const { repo, owner, ownerType } = info;
355
+ const readReusable = snapshot ? (file) => snapshot.readFile(`.github/workflows/${file}`) : null;
356
+ let settings = null;
357
+ let jobs = [];
358
+ const unread = unreadCallers(callers);
359
+ const onAction = (where) => actions().get(where) === true;
360
+ const unreadHarness = (where) => actions().get(where) === "unknown";
361
+ const results = [
362
+ guarded("github-app", () => {
363
+ jobs = pushingJobs(callers, readReusable);
364
+ settings = readAppSettings({ github, repo, ownerType });
365
+ const tag = snapshot?.tag;
366
+ return checkGitHubApp({ repo, settings, jobs, unread, tag, onAction, unreadHarness });
367
+ }),
368
+ ];
369
+ const appSet = Boolean(settings?.idSet && settings.keySet);
370
+ if (appSet) {
371
+ const installed = () => checkGitHubAppInstalled({ github, repo, owner, ownerType });
372
+ results.push(guarded("github-app-installed", installed, "Your GitHub App is installed"));
373
+ }
374
+ // Not read: a half doctor cannot see may be set.
375
+ const appUnknown = !settings || Boolean(settings.unknown);
376
+ const ciWorkflow = () =>
377
+ checkCiWorkflow({ root, jobs, unread, appSet, appUnknown, onAction, unreadHarness });
378
+ results.push(guarded("ci-workflow", ciWorkflow));
379
+ return results;
380
+ }
381
+
382
+ /** The harness checks, from the pinned tag's cli/harnesses.json. */
383
+ function harnessChecks({ runner, cwd, root, info, callers, snapshot }) {
384
+ const skipEach = (reason) => skipAll(STAGE_CHECKS, reason);
385
+ if (!snapshot) return skipEach("Needs the pinned tag's harness facts; fix the pins first.");
386
+ const github = createGitHub(runner, { cwd, hostname: info.host ?? null });
387
+ const { repo, ownerType, defaultBranch } = info;
388
+ const { tag } = snapshot;
389
+ let facts;
390
+ try {
391
+ facts = readHarnessFacts(snapshot);
392
+ } catch (err) {
393
+ const [[id, title], ...rest] = STAGE_CHECKS;
394
+ const reason = `${tag}'s ${HARNESSES_PATH} could not be read: ${firstLine(err.message)}`;
395
+ return [result(id, title, "fail", reason), ...skipAll(rest, reason)];
396
+ }
397
+ if (facts === null) {
398
+ return [
399
+ ...skipEach(`${tag} predates harness choice: it has no ${HARNESSES_PATH}.`),
400
+ ...checkHarnessVariables({ github, repo, ownerType, tag }),
401
+ ];
402
+ }
403
+ try {
404
+ return checkStages({
405
+ github,
406
+ repo,
407
+ ownerType,
408
+ callers,
409
+ facts,
410
+ snapshot,
411
+ root,
412
+ defaultBranch,
413
+ });
414
+ } catch (err) {
415
+ const crash = () => {
416
+ throw err;
417
+ };
418
+ return STAGE_CHECKS.map(([id, title]) => guarded(id, crash, title));
419
+ }
420
+ }
421
+
313
422
  function finish({ mode, modeReason, repo, tag, results, refusal, strict }) {
314
423
  const final = strict
315
424
  ? results.map((r) => (r.status === "warn" ? { ...r, status: "fail", strict: true } : r))
@@ -0,0 +1,30 @@
1
+ // The Harness adapters the kit ships (ADR 0027), by harness name: each takes a
2
+ // Stage request and returns its launch plan.
3
+
4
+ import { antigravity } from "./antigravity.mjs";
5
+ import { claudeCode } from "./claude-code.mjs";
6
+ import { codex } from "./codex.mjs";
7
+ import { cursor } from "./cursor.mjs";
8
+ import { loadedCustom } from "./custom/registry.mjs";
9
+ import { gemini } from "./gemini.mjs";
10
+ import { opencode } from "./opencode.mjs";
11
+
12
+ /** @type {Readonly<Record<string, (request?: object) => import("./claude-code.mjs").LaunchPlan>>} */
13
+ export const ADAPTERS = Object.freeze({
14
+ "claude-code": claudeCode,
15
+ codex,
16
+ gemini,
17
+ antigravity,
18
+ opencode,
19
+ cursor,
20
+ });
21
+
22
+ /**
23
+ * `harness`'s adapter: the kit's own, or a Custom harness's once its file is
24
+ * loaded from the trusted commit (harness/resolve.mjs).
25
+ * @param {string} harness
26
+ */
27
+ export const adapterFor = (harness) => loadedCustom(harness)?.adapter ?? ADAPTERS[harness];
28
+
29
+ /** The harness a Stage runs on when no setting names one (ADR 0022). */
30
+ export const DEFAULT_HARNESS = "claude-code";
@@ -0,0 +1,187 @@
1
+ // The Antigravity CLI Harness adapter (ADR 0027): one function that takes a
2
+ // Stage request and returns a launch plan, as plain data. The Launcher does
3
+ // everything with the plan; this module starts nothing and imports nothing.
4
+ //
5
+ // The CLI (`agy`): one pinned version, in `/opt/agent-kit` of the kit's Harness
6
+ // image (ADR 0029, docker/harness-images/), which is pinned by digest. The
7
+ // updater is off in the image and in the run's environment. Nothing is
8
+ // installed at run time.
9
+ //
10
+ // The launch: headless, the brief on stdin (with no `-p`, which takes the
11
+ // prompt on the command line), every tool call approved, since the Launcher's
12
+ // sandbox reaches the Guards. Everything the CLI reads and writes of its own is
13
+ // under `--gemini_dir`, in a folder of the Launcher's that it empties first, so
14
+ // nothing in the sandbox's home is read. There the Launcher writes the
15
+ // settings (`modelProvider: "gemini"`, which makes the CLI use the key in
16
+ // `GEMINI_API_KEY` with no sign-in) and one agent of its own, which the run is
17
+ // made as. No setting of the pinned version turns its web search off, and a
18
+ // permission rule naming it is dropped, so that agent lists the local tools it
19
+ // has and no other: no web search and no subagent, which could have its own.
20
+ //
21
+ // `agy` loads `.agents/`, `.agent/`, `_agents/` and `_agent/` (hooks, MCP
22
+ // servers, plugins, skills, agents) from the working directory with no trust
23
+ // asked, so the Launcher removes each from the copy, and `.gemini/` with them.
24
+ // `AGENTS.md` and `GEMINI.md` are instruction files it loads by itself.
25
+ //
26
+ // The model API's base URL is the model proxy, over plain HTTP, which the
27
+ // pinned version accepts; the live suite names that cause if a bump does not.
28
+ //
29
+ // The agent holds only the run's caller key as its `GEMINI_API_KEY`. It has no
30
+ // turn limit: the wall clock and the proxy's token cap bound the run. A CLI
31
+ // that asks for a sign-in was not given a credential it reads.
32
+ //
33
+ // The only credential is a Gemini API key. A Google sign-in is not accepted:
34
+ // the CLI's signed-in calls include one to a fixed Google host that no setting
35
+ // points at the model proxy (#578).
36
+
37
+ /** The Antigravity CLI version every sandbox runs, pinned. */
38
+ const VERSION = "1.5.20";
39
+
40
+ /**
41
+ * The Harness image that holds that version. The `harness-images` workflow
42
+ * builds it in the pull request that changes the pin or its Dockerfile, and
43
+ * fails until this holds the digest it pushed
44
+ * (`node docker/harness-images/image.mjs record antigravity`).
45
+ */
46
+ const IMAGE = "ghcr.io/mnaimfaizy/agent-kit-sandbox-antigravity";
47
+ const IMAGE_DIGEST = "sha256:db9e91a505fb28977a0d1a13af747060eba9facdf16385c0461a5a08726c06be"; // inputs-7f6aaef296738b4eb2ed3d0e2588a7b3
48
+
49
+ /**
50
+ * What a Consumer needs to know about Antigravity CLI, which
51
+ * `cli/harnesses.json` publishes per tag (ADR 0030): the kit secret it accepts,
52
+ * with where to get it; the values its `--effort` takes (each model offers some
53
+ * of them, and the CLI refuses one its model does not); and the model a Stage
54
+ * gets when none is named, which is the pinned version's own default.
55
+ */
56
+ export const FACTS = Object.freeze({
57
+ displayName: "Antigravity CLI",
58
+ secrets: Object.freeze([
59
+ {
60
+ name: "gemini_api_key",
61
+ whereToGet:
62
+ "Create an API key in Google AI Studio, in a project with its own budget: https://aistudio.google.com/apikey.",
63
+ },
64
+ ]),
65
+ effortValues: Object.freeze(["low", "medium", "high", "xhigh", "max"]),
66
+ defaultModel: "gemini-3.1-pro",
67
+ });
68
+
69
+ /** The CLI's own tools the run's agent has: all local. */
70
+ export const TOOLS = Object.freeze([
71
+ "run_command",
72
+ "read_file",
73
+ "write_file",
74
+ "edit_file",
75
+ "manage_task",
76
+ "update_steps",
77
+ ]);
78
+
79
+ /** The agent the run is made as, which only the Launcher's folder holds. */
80
+ const AGENT = "agent-kit";
81
+
82
+ const AGENT_FILE = [
83
+ "---",
84
+ `name: ${AGENT}`,
85
+ "description: The agent of an Agent-kit run.",
86
+ "mainAgent: true",
87
+ "subagent: false",
88
+ "tools:",
89
+ ...TOOLS.map((tool) => ` - ${tool}`),
90
+ "---",
91
+ "You are the agent of an Agent-kit run, working alone with no human to ask.",
92
+ "Do what the request says, with the tools you have, until it is done.",
93
+ "",
94
+ ].join("\n");
95
+
96
+ /** The credential Antigravity CLI accepts, and the placeholder the model proxy swaps. */
97
+ const CREDENTIALS = {
98
+ "api-key": {
99
+ secret: "gemini_api_key",
100
+ env: "GEMINI_API_KEY",
101
+ placeholder: "agent-kit-deep-scan-placeholder",
102
+ },
103
+ };
104
+
105
+ /** The settings every run holds. */
106
+ const SETTINGS = {
107
+ modelProvider: "gemini",
108
+ enableTelemetry: false,
109
+ permissions: { deny: ["read_url(*)"] },
110
+ };
111
+
112
+ const UPDATER_OFF = "AGY_CLI_DISABLE_AUTO_UPDATE=true";
113
+
114
+ /**
115
+ * The launch plan for `request`.
116
+ * @param {object} [request] a Stage request, as the Claude Code adapter
117
+ * describes it. `maxTurns` is ignored: Antigravity CLI has no turn limit.
118
+ * The only `credentialKind` is `api-key`.
119
+ * @returns the nine-part launch plan, in the same shape as Claude Code's.
120
+ */
121
+ export function antigravity({
122
+ model,
123
+ effort,
124
+ credentialKind = "api-key",
125
+ proxyUrl,
126
+ briefPath,
127
+ kitDir,
128
+ callerKey,
129
+ } = {}) {
130
+ if (!Object.hasOwn(CREDENTIALS, credentialKind)) {
131
+ throw new Error(`Antigravity CLI has no credential kind ${JSON.stringify(credentialKind)}`);
132
+ }
133
+ const accepted = structuredClone(CREDENTIALS);
134
+ const credential = accepted[credentialKind];
135
+ if (callerKey !== undefined) credential.placeholder = callerKey;
136
+ const home = kitDir ?? "/agent-kit";
137
+ const own = `${home}/agy`;
138
+ return {
139
+ identity: { name: "antigravity", displayName: "Antigravity CLI", version: VERSION, major: 1 },
140
+ installLayer: {
141
+ image: `${IMAGE}@${IMAGE_DIGEST}`,
142
+ env: [UPDATER_OFF],
143
+ run: ["ln -sf /opt/agent-kit/bin/agy /usr/local/bin/agy"],
144
+ },
145
+ modelRoute: { profile: "gemini-api" },
146
+ credentials: { accepted, scrub: ["GEMINI_API_KEY", "GOOGLE_API_KEY"] },
147
+ launch: {
148
+ argv: [
149
+ "agy",
150
+ `--gemini_dir=${own}`,
151
+ "--dangerously-skip-permissions",
152
+ // The brief is text to follow, never one of the CLI's own commands.
153
+ "--disable-slash-commands",
154
+ // Its answer goes to stdout, the transcript.
155
+ "--output-format",
156
+ "text",
157
+ "--agent",
158
+ AGENT,
159
+ ...(model !== undefined ? ["--model", model] : []),
160
+ ...(effort !== undefined ? ["--effort", effort] : []),
161
+ ],
162
+ stdin: briefPath !== undefined ? { file: briefPath } : null,
163
+ files: [
164
+ { path: `${own}/antigravity-cli/settings.json`, text: JSON.stringify(SETTINGS, null, 2) },
165
+ { path: `${own}/config/agents/${AGENT}.md`, text: AGENT_FILE },
166
+ ],
167
+ env: [
168
+ `${credential.env}=${credential.placeholder}`,
169
+ UPDATER_OFF,
170
+ ...(proxyUrl !== undefined ? [`GOOGLE_GEMINI_BASE_URL=${proxyUrl}`] : []),
171
+ ],
172
+ // The Launcher removes `checkoutConfig` from the copy before the launch.
173
+ removeCheckoutConfig: true,
174
+ },
175
+ checkoutConfig: [".agents", ".agent", "_agents", "_agent", ".gemini"],
176
+ instructionFiles: ["GEMINI.md", "AGENTS.md"],
177
+ stops: {
178
+ turnCap: null,
179
+ // What it says on its error output when it has no credential it reads.
180
+ credentialMissing: {
181
+ stderrPattern:
182
+ "^(error: )?authentication required|GEMINI_API_KEY environment variable is not set",
183
+ },
184
+ },
185
+ transcript: { path: `${home}/logs/agent.log` },
186
+ };
187
+ }