@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
@@ -0,0 +1,705 @@
1
+ // The harness checks: each Stage a Caller runs, checked the way its run's
2
+ // preflight does (ADRs 0027, 0028 and 0030). A Stage's harness, model and
3
+ // effort are what the Caller job's `with:` resolves to from the repository
4
+ // variables. The harness facts are the pinned tag's cli/harnesses.json, read
5
+ // as data: doctor never runs code it fetched from a tag. The effort and
6
+ // Support Level rules are preflight's own.
7
+
8
+ import { secretNames } from "../callers.mjs";
9
+ import { effortFor, supportFor } from "../harness/facts.mjs";
10
+ import { isMapping, parseYamlSubset } from "../yaml-subset.mjs";
11
+ import { checkCustomHarness, harnessVariableValues } from "./custom-harness.mjs";
12
+ import { command, NAME_PATTERN, result } from "./result.mjs";
13
+ import { listNames, setCommand } from "./secrets-and-variables.mjs";
14
+
15
+ /** Where every kit tag with harness choice publishes its harness facts. */
16
+ export const HARNESSES_PATH = "cli/harnesses.json";
17
+
18
+ /** The checks that need the pinned tag's harness facts. */
19
+ export const STAGE_CHECKS = [
20
+ ["stage-harness", "Each Stage's harness, model and effort"],
21
+ ["stage-credential", "Each Stage's harness has its credential"],
22
+ ["stage-effort", "Each Stage's effort is one its harness accepts"],
23
+ ["stage-model", "The global model stays on the global harness"],
24
+ ["stage-support", "Each Stage may run on its harness"],
25
+ ];
26
+ const TITLES = Object.fromEntries(STAGE_CHECKS);
27
+
28
+ /** The reusable workflow each Stage runs in. */
29
+ const STAGE_OF = {
30
+ "agent-plan-reusable.yml": "plan",
31
+ "agent-implement-reusable.yml": "implement",
32
+ "agent-review-reusable.yml": "review",
33
+ "agent-review-response-reusable.yml": "review-response",
34
+ "security-audit-reusable.yml": "security-audit",
35
+ "deep-scan-reusable.yml": "deep-scan",
36
+ };
37
+
38
+ // The accepted names, as every reusable workflow's first step checks them.
39
+ const HARNESS_NAMES = ["claude-code", "codex", "gemini", "antigravity", "opencode", "cursor"];
40
+ const CUSTOM_NAME = /^custom:[A-Za-z0-9][A-Za-z0-9._-]*$/;
41
+ const DEFAULT_HARNESS = "claude-code";
42
+ /** Cursor CLI's weaker form is offered on these Stages only (ADR 0025). */
43
+ const CURSOR_STAGES = ["plan", "implement", "review"];
44
+
45
+ // A `uses:` of the action, not a comment that names it.
46
+ const ACTION_STEP = /^\s*(?:-\s+)?uses:\s*anthropics\/claude-code-action@/m;
47
+
48
+ /**
49
+ * Whether the tag's static security audit still has a claude-code-action step:
50
+ * its default harness runs there rather than on the Launcher, so until it
51
+ * moves that run is not refused below `tried`, and doctor says no more than the
52
+ * run does. Any other harness the audit runs is on the Launcher, which refuses.
53
+ */
54
+ const auditOnAction = (snapshot) =>
55
+ ACTION_STEP.test(snapshot.readFile(".github/workflows/security-audit-reusable.yml") ?? "");
56
+
57
+ // The first step of a reusable workflow that runs one harness names it so.
58
+ const WIRED = /^\s*wired=([a-z0-9-]+)\s*$/m;
59
+
60
+ /**
61
+ * The one harness the tag's reusable workflow for `stage` runs, or null when it
62
+ * names none and the tag's facts decide. harnesses.json lists a harness as soon
63
+ * as any Stage runs it, so a Stage not yet wired for it still refuses the run.
64
+ */
65
+ function wiredHarness(snapshot, stage) {
66
+ const file = Object.keys(STAGE_OF).find((name) => STAGE_OF[name] === stage);
67
+ return WIRED.exec(snapshot.readFile(`.github/workflows/${file}`) ?? "")?.[1] ?? null;
68
+ }
69
+
70
+ const isHarnessName = (name) => HARNESS_NAMES.includes(name) || CUSTOM_NAME.test(name);
71
+
72
+ /** `REVIEW_RESPONSE` in `AGENT_KIT_REVIEW_RESPONSE_MODEL`. */
73
+ const stageVariable = (stage, setting) =>
74
+ `AGENT_KIT_${stage.replaceAll("-", "_").toUpperCase()}_${setting}`;
75
+
76
+ /**
77
+ * The pinned tag's harness facts, or null when the tag has no harnesses.json,
78
+ * which means it predates harness choice. Throws when the file is not what
79
+ * doctor can read. Its shape only grows, so unknown fields are ignored.
80
+ */
81
+ export function readHarnessFacts(snapshot) {
82
+ const text = snapshot.readFile(HARNESSES_PATH);
83
+ if (text === null) return null;
84
+ const data = JSON.parse(text);
85
+ const readable = (h) =>
86
+ isMapping(h) &&
87
+ typeof h.displayName === "string" &&
88
+ Array.isArray(h.secrets) &&
89
+ h.secrets.every((s) => typeof s?.name === "string") &&
90
+ Array.isArray(h.effortValues) &&
91
+ typeof h.defaultModel === "string" &&
92
+ isMapping(h.supportLevels);
93
+ if (!isMapping(data?.harnesses) || !Object.values(data.harnesses).every(readable)) {
94
+ throw new Error("a harness entry lacks a field doctor reads");
95
+ }
96
+ return data;
97
+ }
98
+
99
+ /**
100
+ * Every repository variable's value as a workflow run sees it, by upper-case
101
+ * name: the repository's, else the organization's.
102
+ */
103
+ function listValues(github, repo, ownerType) {
104
+ const values = new Map();
105
+ const add = (endpoint, scope) => {
106
+ for (const line of github.getLines(endpoint, ".variables[] | [.name, .value] | @json")) {
107
+ const [name, value] = JSON.parse(line);
108
+ values.set(String(name).toUpperCase(), { value: String(value), scope });
109
+ }
110
+ };
111
+ let orgNote = null;
112
+ if (ownerType === "Organization") {
113
+ try {
114
+ add(`repos/${repo}/actions/organization-variables`, "organization");
115
+ } catch {
116
+ orgNote =
117
+ "Organization variables could not be read; a setting shown here may be set at the organization.";
118
+ }
119
+ }
120
+ add(`repos/${repo}/actions/variables`, "repository");
121
+ return { values, orgNote };
122
+ }
123
+
124
+ // One operand of an `a || b` chain: `vars.NAME` or a quoted string.
125
+ const OPERAND = /\s*(?:vars\.([A-Za-z_][A-Za-z0-9_]*)|'((?:[^']|'')*)')\s*(\|\||$)/y;
126
+
127
+ /**
128
+ * What a Caller's `with:` value resolves to. It evaluates the form the example
129
+ * Callers use, a chain of variables and quoted strings; anything else is
130
+ * `unreadable`, never guessed at.
131
+ * @returns {{ value: string, variable?: string, scope?: string, passed: boolean, reads: string[] } |
132
+ * { unreadable: string, why?: string }}
133
+ */
134
+ function evaluate(raw, values) {
135
+ if (raw === undefined || raw === null) return { value: "", passed: false, reads: [] };
136
+ if (typeof raw !== "string") return { unreadable: JSON.stringify(raw) };
137
+ const text = raw.trim();
138
+ // A YAML alias or anchor, which the reader leaves unresolved.
139
+ if (/^[*&]/.test(text)) return { unreadable: text };
140
+ if (!text.includes("${{")) return { value: text, passed: true, reads: [] };
141
+ const expression = /^\$\{\{([\s\S]*)\}\}$/.exec(text)?.[1].trim();
142
+ if (!expression) return { unreadable: text };
143
+ const operands = [];
144
+ OPERAND.lastIndex = 0;
145
+ let more = true;
146
+ while (more) {
147
+ const m = OPERAND.exec(expression);
148
+ if (!m) return { unreadable: text };
149
+ operands.push(m);
150
+ more = m[3] === "||";
151
+ }
152
+ const reads = operands.filter((m) => m[1]).map((m) => m[1].toUpperCase());
153
+ for (const [, variable, literal] of operands) {
154
+ if (variable) {
155
+ const set = values.get(variable.toUpperCase());
156
+ if (set?.value) {
157
+ return {
158
+ value: set.value,
159
+ variable: variable.toUpperCase(),
160
+ scope: set.scope,
161
+ passed: true,
162
+ reads,
163
+ };
164
+ }
165
+ } else if (literal) {
166
+ return { value: literal.replaceAll("''", "'"), passed: true, reads };
167
+ }
168
+ }
169
+ return { value: "", passed: true, reads };
170
+ }
171
+
172
+ const from = (setting) =>
173
+ setting.variable
174
+ ? `${setting.scope} variable ${setting.variable}`
175
+ : // A literal, the last part of the chain or the whole value.
176
+ setting.reads.length
177
+ ? "the Caller's default"
178
+ : "written in the Caller";
179
+
180
+ /**
181
+ * Why a job's `with:`, as written, hides what it passes from doctor's reader,
182
+ * or null. Read as "no inputs", it would check the job against claude-code.
183
+ */
184
+ export function hiddenInputs(written) {
185
+ const block = written?.with;
186
+ if (block === undefined || block === null || block === "") {
187
+ return written && "<<" in written
188
+ ? "the job uses a merge key (<<), which may hold its `with:`"
189
+ : null;
190
+ }
191
+ if (!isMapping(block)) {
192
+ return `\`with:\` is not a block mapping doctor can read: ${JSON.stringify(block)}`;
193
+ }
194
+ return "<<" in block ? "`with:` uses a merge key (<<)" : null;
195
+ }
196
+
197
+ /** Each Caller job that runs a Stage, with its settings resolved. */
198
+ function stageJobs(callers, values, facts) {
199
+ const jobs = [];
200
+ for (const caller of callers) {
201
+ // The jobs as written: `caller.jobs` reads an unparsed `with:` as empty.
202
+ const written = parseYamlSubset(caller.text).jobs;
203
+ for (const job of caller.jobs) {
204
+ const stage = STAGE_OF[job.uses.file];
205
+ if (!stage) continue;
206
+ const hidden = hiddenInputs(written?.[job.name]);
207
+ const input = (name) =>
208
+ hidden ? { unreadable: name, why: hidden } : evaluate(job.with[name], values);
209
+ const harness = input("harness");
210
+ // The reusable workflow reads an empty harness as claude-code.
211
+ const name = "unreadable" in harness ? null : harness.value || DEFAULT_HARNESS;
212
+ const valid = name !== null && isHarnessName(name);
213
+ jobs.push({
214
+ stage,
215
+ job,
216
+ label: `${stage} (${caller.path}:${job.name})`,
217
+ harness,
218
+ model: input("model"),
219
+ effort: input("effort"),
220
+ name,
221
+ valid,
222
+ entry: valid && Object.hasOwn(facts.harnesses, name) ? facts.harnesses[name] : null,
223
+ });
224
+ }
225
+ }
226
+ return jobs;
227
+ }
228
+
229
+ /** One check's result: a failure outranks a warning, which outranks a part left unchecked. */
230
+ function verdict(
231
+ id,
232
+ { failed = [], warned = [], unchecked = [], notes = [], fix = [] },
233
+ summaries,
234
+ ) {
235
+ const status = failed.length
236
+ ? "fail"
237
+ : warned.length
238
+ ? "warn"
239
+ : unchecked.length
240
+ ? "skip"
241
+ : "pass";
242
+ const count = { fail: failed, warn: warned, skip: unchecked, pass: [] }[status].length;
243
+ const summary = status === "pass" ? summaries.pass : summaries[status](count);
244
+ return result(id, TITLES[id], status, summary, {
245
+ details: [...failed, ...warned, ...unchecked, ...notes],
246
+ fix: [...new Set(fix)],
247
+ });
248
+ }
249
+
250
+ const unreadableNote = (setting, what) =>
251
+ `${what} unknown: ` +
252
+ (setting.why ?? `doctor cannot evaluate ${JSON.stringify(setting.unreadable)}`);
253
+
254
+ function checkHarness(jobs) {
255
+ const failed = [];
256
+ const unchecked = [];
257
+ const notes = [];
258
+ for (const { label, harness, model, effort, name, valid, entry } of jobs) {
259
+ let shownHarness;
260
+ if ("unreadable" in harness) shownHarness = unreadableNote(harness, "harness");
261
+ else {
262
+ let source = harness.value ? from(harness) : "the reusable workflow's default";
263
+ if (!harness.passed) {
264
+ source = "default: the Caller passes no harness input, so no variable changes it";
265
+ }
266
+ shownHarness = `harness ${name} (${source})`;
267
+ }
268
+ let shownModel;
269
+ if ("unreadable" in model) shownModel = unreadableNote(model, "model");
270
+ else if (model.value) shownModel = `model ${model.value} (${from(model)})`;
271
+ else if (entry) shownModel = `model ${entry.defaultModel} (${name}'s default model)`;
272
+ else shownModel = "model empty (the harness's default)";
273
+ let shownEffort;
274
+ if ("unreadable" in effort) shownEffort = unreadableNote(effort, "effort");
275
+ else if (effort.value) shownEffort = `effort ${effort.value} (${from(effort)})`;
276
+ else shownEffort = "effort none (the model's own default)";
277
+ const line = `${label}: ${shownHarness}; ${shownModel}; ${shownEffort}`;
278
+ if (name !== null && !valid) {
279
+ const accepted = `${HARNESS_NAMES.join(", ")} or custom:<name>`;
280
+ failed.push(`${line} — not a harness: use ${accepted}`);
281
+ } else if ([harness, model, effort].some((s) => "unreadable" in s)) unchecked.push(line);
282
+ else notes.push(line);
283
+ }
284
+ return verdict(
285
+ "stage-harness",
286
+ { failed, unchecked, notes },
287
+ {
288
+ pass: `${jobs.length} Stage job(s) resolved.`,
289
+ fail: (n) => `${n} Stage job(s) name an unknown harness.`,
290
+ skip: (n) => `${n} Stage job(s) have a setting doctor could not resolve.`,
291
+ },
292
+ );
293
+ }
294
+
295
+ /** Why a job's harness has no facts to check it against. */
296
+ const noFacts = ({ label, name }) =>
297
+ `${label}: not checked, as ${
298
+ name === null ? "its harness could not be resolved" : `there are no facts for harness ${name}`
299
+ }`;
300
+
301
+ /** The provider a `provider/model` id names, or undefined. */
302
+ const providerNamed = (model) => /^([^/]+)\/./.exec(model)?.[1];
303
+
304
+ /**
305
+ * The secrets a Stage job's run reads. A harness's secrets are alternatives,
306
+ * but where each names a `provider` (opencode's), the run reads only the one
307
+ * the model's `provider/model` names: the Stage's model as the Caller
308
+ * resolves it, else the harness's default. As the Deep scan workflow does, an
309
+ * inherited AGENT_KIT_MODEL that names none of those providers gives way to
310
+ * the default.
311
+ * @returns {{ secrets: object[], provider?: string } | { unread: object } | { refused: string }}
312
+ */
313
+ function secretsFor({ stage, model, entry }, values) {
314
+ if (!entry.secrets.some((s) => typeof s.provider === "string")) return { secrets: entry.secrets };
315
+ if ("unreadable" in model) return { unread: model };
316
+ const of = (id) => {
317
+ const provider = providerNamed(id);
318
+ return { provider, secrets: entry.secrets.filter((s) => s.provider === provider) };
319
+ };
320
+ const found = of(model.value || entry.defaultModel);
321
+ if (found.secrets.length) return found;
322
+ const inherited =
323
+ !values.get(stageVariable(stage, "MODEL"))?.value &&
324
+ model.value.toLowerCase() === values.get("AGENT_KIT_MODEL")?.value.toLowerCase();
325
+ const fallback = inherited ? of(entry.defaultModel) : found;
326
+ if (fallback.secrets.length) return fallback;
327
+ return {
328
+ refused: `its model names no provider ${entry.displayName} runs on, so the run is refused`,
329
+ };
330
+ }
331
+
332
+ /** The names of `secrets`, the one to set first leading. */
333
+ function preferredSecrets(stage, secrets) {
334
+ const names = secrets.map((s) => s.name);
335
+ // The Deep scan's supported path is the API key, not a subscription token.
336
+ if (stage !== "deep-scan") return names;
337
+ return [...names].sort(
338
+ (a, b) => Number(b === "anthropic_api_key") - Number(a === "anthropic_api_key"),
339
+ );
340
+ }
341
+
342
+ function checkCredential({ jobs, values, github, repo, ownerType }) {
343
+ const ID = "stage-credential";
344
+ let listed;
345
+ try {
346
+ listed = listNames(github, repo, "secret", ownerType);
347
+ } catch (err) {
348
+ return result(ID, TITLES[ID], "skip", `Could not list repository secrets: ${err.message}`);
349
+ }
350
+ const isSet = (name) => listed.names.has(name.toUpperCase());
351
+ const failed = [];
352
+ const unchecked = [];
353
+ const fix = [];
354
+ const notes = [];
355
+ for (const item of jobs) {
356
+ const { stage, label, job, name, entry } = item;
357
+ if (!entry) {
358
+ unchecked.push(noFacts(item));
359
+ continue;
360
+ }
361
+ if (job.secretsUnsupported) {
362
+ unchecked.push(`${label}: not checked: ${job.secretsUnsupported}`);
363
+ continue;
364
+ }
365
+ const read = secretsFor(item, values);
366
+ if ("unread" in read) {
367
+ unchecked.push(`${label}: not checked: ${unreadableNote(read.unread, "model")}`);
368
+ continue;
369
+ }
370
+ if ("refused" in read) {
371
+ failed.push(`${label}: ${read.refused}`);
372
+ continue;
373
+ }
374
+ const accepted = preferredSecrets(stage, read.secrets);
375
+ // Each accepted input the job passes, with the secrets that fill it.
376
+ const passed = accepted.flatMap((input) => {
377
+ if (job.secrets === "inherit") return [{ input, names: [input.toUpperCase()] }];
378
+ const key = Object.keys(job.secrets).find((k) => k.toLowerCase() === input.toLowerCase());
379
+ const names = key === undefined ? [] : secretNames(job.secrets[key]);
380
+ return names.length ? [{ input, names }] : [];
381
+ });
382
+ const set = passed.flatMap((p) => p.names.find(isSet) ?? []);
383
+ // The Deep scan on claude-code takes exactly one of its two credentials.
384
+ if (stage === "deep-scan" && name === "claude-code" && set.length > 1) {
385
+ failed.push(
386
+ `${label}: two model credentials set: ${set.join(" and ")}; every run fails. ` +
387
+ "Delete one: the API key is the supported path.",
388
+ );
389
+ continue;
390
+ }
391
+ if (set.length) continue;
392
+ // What it passes may be set where doctor could not look.
393
+ if (passed.length && listed.orgNote) {
394
+ const names = passed.flatMap((p) => p.names).join(" or ");
395
+ unchecked.push(`${label}: not checked: ${names} is not among the secrets doctor could list`);
396
+ continue;
397
+ }
398
+ const secret = passed[0]?.names[0] ?? accepted[0].toUpperCase();
399
+ failed.push(
400
+ `${label}: harness ${name}${read.provider ? ` on a ${read.provider}/ model` : ""} needs ` +
401
+ `${accepted.join(" or ")}, passed by the Caller job and set` +
402
+ (passed.length
403
+ ? ""
404
+ : `; pass it in the Caller job: ${accepted[0]}: \${{ secrets.${secret} }}`),
405
+ );
406
+ for (const s of read.secrets) {
407
+ if (typeof s.whereToGet === "string") notes.push(`${s.name}: ${s.whereToGet}`);
408
+ }
409
+ // No --body: gh prompts for the value, so it never lands in shell history.
410
+ const wanted = setCommand("secret", secret, repo);
411
+ if (wanted.cmd) fix.push(wanted.cmd);
412
+ else notes.push(wanted.note);
413
+ }
414
+ if ((failed.length || unchecked.length) && listed.orgNote) notes.push(listed.orgNote);
415
+ return verdict(
416
+ ID,
417
+ { failed, unchecked, notes: [...new Set(notes)], fix },
418
+ {
419
+ pass: "Each Stage job passes a secret its harness accepts, and it is set.",
420
+ fail: (n) => `${n} Stage job(s) fail on their model credential.`,
421
+ skip: (n) => `${n} Stage job(s) were not checked.`,
422
+ },
423
+ );
424
+ }
425
+
426
+ function checkEffort(jobs, values) {
427
+ const failed = [];
428
+ const warned = [];
429
+ const unchecked = [];
430
+ const global = values.get("AGENT_KIT_EFFORT")?.value ?? "";
431
+ for (const item of jobs) {
432
+ const { stage, label, effort, entry } = item;
433
+ if (!entry) {
434
+ unchecked.push(noFacts(item));
435
+ continue;
436
+ }
437
+ if ("unreadable" in effort) {
438
+ unchecked.push(`${label}: ${unreadableNote(effort, "effort")}`);
439
+ continue;
440
+ }
441
+ // As the reusable workflows tell it: the Stage has no effort variable of
442
+ // its own, and what it got is AGENT_KIT_EFFORT (`==` ignores case).
443
+ const inherited =
444
+ !values.get(stageVariable(stage, "EFFORT"))?.value &&
445
+ effort.value.toLowerCase() === global.toLowerCase();
446
+ const found = effortFor(entry, { effort: effort.value, inherited });
447
+ if ("refused" in found) failed.push(`${label}: ${found.refused}`);
448
+ else if (found.log) warned.push(`${label}: ${found.log}`);
449
+ }
450
+ return verdict(
451
+ "stage-effort",
452
+ { failed, warned, unchecked },
453
+ {
454
+ pass: "Every Stage's effort is accepted.",
455
+ fail: (n) => `${n} Stage job(s) set an effort their harness does not accept.`,
456
+ warn: (n) => `${n} Stage job(s) drop the inherited AGENT_KIT_EFFORT.`,
457
+ skip: (n) => `${n} Stage job(s) were not checked.`,
458
+ },
459
+ );
460
+ }
461
+
462
+ function checkModel(jobs, values, repo) {
463
+ const warned = [];
464
+ const unchecked = [];
465
+ const fix = [];
466
+ const global = values.get("AGENT_KIT_HARNESS")?.value || DEFAULT_HARNESS;
467
+ for (const { stage, label, model, name, valid } of jobs) {
468
+ if (!valid || "unreadable" in model) {
469
+ unchecked.push(`${label}: not checked, as its harness or model could not be resolved`);
470
+ continue;
471
+ }
472
+ const own = stageVariable(stage, "MODEL");
473
+ if (model.variable !== "AGENT_KIT_MODEL" || values.get(own)?.value || name === global) continue;
474
+ warned.push(
475
+ `${label}: AGENT_KIT_MODEL reaches this Stage on ${name}, while the global harness is ` +
476
+ `${global}: set ${own} to a ${name} model`,
477
+ );
478
+ if (NAME_PATTERN.test(own)) fix.push(command("gh", "variable", "set", own, "--repo", repo));
479
+ }
480
+ return verdict(
481
+ "stage-model",
482
+ { warned, unchecked, fix },
483
+ {
484
+ pass: "AGENT_KIT_MODEL reaches no Stage on another harness.",
485
+ warn: (n) => `AGENT_KIT_MODEL reaches ${n} Stage job(s) on another harness.`,
486
+ skip: (n) => `${n} Stage job(s) were not checked.`,
487
+ },
488
+ );
489
+ }
490
+
491
+ function checkSupport(jobs, snapshot) {
492
+ const { tag } = snapshot;
493
+ const failed = [];
494
+ const unchecked = [];
495
+ const notes = [];
496
+ for (const item of jobs) {
497
+ const { stage, label, name, valid, entry } = item;
498
+ if (!valid) {
499
+ unchecked.push(noFacts(item));
500
+ continue;
501
+ }
502
+ if (name === "cursor" && !CURSOR_STAGES.includes(stage)) {
503
+ failed.push(`${label}: Cursor CLI runs only plan, implement and review`);
504
+ continue;
505
+ }
506
+ if (!entry && name.startsWith("custom:")) {
507
+ failed.push(
508
+ `${label}: ${tag} runs no ${name} harness: its reusable workflows run no Custom harness, so the run is refused: ` +
509
+ "run it with agent-kit stage or agent-kit deep-scan, in your own step or by hand",
510
+ );
511
+ continue;
512
+ }
513
+ if (!entry) {
514
+ failed.push(`${label}: ${tag} runs no ${name} harness, so the run is refused`);
515
+ continue;
516
+ }
517
+ const wired = wiredHarness(snapshot, stage);
518
+ // A pair with no level keeps its own reason, below.
519
+ if (wired !== null && wired !== name && entry.supportLevels[stage]?.level) {
520
+ failed.push(`${label}: ${tag}'s ${stage} Stage runs only ${wired}, so the run is refused`);
521
+ continue;
522
+ }
523
+ // A tag whose workflow names no one harness says per pair which it runs.
524
+ if (
525
+ wired === null &&
526
+ entry.supportLevels[stage]?.level &&
527
+ entry.supportLevels[stage].wired === false
528
+ ) {
529
+ failed.push(`${label}: ${tag}'s ${stage} Stage does not run ${name}, so the run is refused`);
530
+ continue;
531
+ }
532
+ if (
533
+ stage === "security-audit" &&
534
+ name === DEFAULT_HARNESS &&
535
+ entry.supportLevels[stage]?.level === "documented" &&
536
+ auditOnAction(snapshot)
537
+ ) {
538
+ notes.push(
539
+ `${label}: ${entry.displayName} on the ${stage} Stage is at Support Level documented, ` +
540
+ `below tried: the run is refused once the audit moves to the Launcher, and ${tag}'s has not`,
541
+ );
542
+ continue;
543
+ }
544
+ const found = supportFor(entry, { stage });
545
+ if (found.refused !== undefined) failed.push(`${label}: ${found.refused}`);
546
+ else if (found.warning !== undefined) notes.push(`${label}: ${found.warning}`);
547
+ }
548
+ return verdict(
549
+ "stage-support",
550
+ { failed, unchecked, notes },
551
+ {
552
+ pass: "Every Stage may run on its harness.",
553
+ fail: (n) => `${n} Stage job(s) are refused on their harness.`,
554
+ skip: (n) => `${n} Stage job(s) were not checked.`,
555
+ },
556
+ );
557
+ }
558
+
559
+ /**
560
+ * Whether the workflow's claude-code-action step takes the Claude GitHub App's
561
+ * token: it does unless the step is given a `github_token` of its own (the job
562
+ * token), without which the action exchanges OIDC for the App's. Text that
563
+ * cannot be read is assumed to.
564
+ * @param {string | null} text
565
+ */
566
+ export function actionUsesClaudeApp(text) {
567
+ if (text === null) return true;
568
+ const start = text.search(/^[ \t]*(?:-[ \t]+)?uses:[ \t]*anthropics\/claude-code-action@/m);
569
+ if (start === -1) return true;
570
+ const lines = text.slice(start).split("\n");
571
+ const indentOf = (line) => /^(\s*)/.exec(line)[1].length;
572
+ // The step's own lines: up to the next line at or left of its list dash.
573
+ const first = lines[0];
574
+ const dash = first.trimStart().startsWith("- ") ? indentOf(first) : indentOf(first) - 2;
575
+ const own = [first];
576
+ for (const line of lines.slice(1)) {
577
+ if (line.trim() !== "" && indentOf(line) <= dash) break;
578
+ own.push(line);
579
+ }
580
+ return !/^\s+github_token:/m.test(own.join("\n"));
581
+ }
582
+
583
+ /**
584
+ * Which Stage jobs run on claude-code-action, by `<path>:<job>`: those on
585
+ * claude-code, or on a harness doctor cannot resolve, whose workflow at the
586
+ * pinned tag has an action step. What cannot be read is assumed to. With
587
+ * `app`, only those whose action step takes the Claude GitHub App's token.
588
+ * @returns {Map<string, boolean | "unknown">} "unknown" (truthy) where the harness
589
+ * could not be read
590
+ */
591
+ export function actionJobs({ github, repo, ownerType, callers, snapshot, app = false }) {
592
+ let values = null;
593
+ try {
594
+ values = listValues(github, repo, ownerType).values;
595
+ } catch {
596
+ // Every harness stays unresolved.
597
+ }
598
+ const found = new Map();
599
+ for (const caller of callers) {
600
+ const written = parseYamlSubset(caller.text).jobs;
601
+ for (const job of caller.jobs) {
602
+ if (!STAGE_OF[job.uses.file]) continue;
603
+ const harness =
604
+ values === null || hiddenInputs(written?.[job.name])
605
+ ? { unreadable: "harness" }
606
+ : evaluate(job.with.harness, values);
607
+ const claude = "unreadable" in harness || [DEFAULT_HARNESS, ""].includes(harness.value);
608
+ const text = snapshot?.readFile(`.github/workflows/${job.uses.file}`) ?? null;
609
+ const action =
610
+ claude && (text === null || ACTION_STEP.test(text)) && (!app || actionUsesClaudeApp(text));
611
+ // "unknown": the harness could not be read, so the job may be on either path.
612
+ const unread = "unreadable" in harness;
613
+ found.set(`${caller.path}:${job.name}`, action && unread ? "unknown" : action);
614
+ }
615
+ }
616
+ return found;
617
+ }
618
+
619
+ /**
620
+ * The five harness checks against the pinned tag's facts, and the Custom
621
+ * harness check where the repository names or holds one.
622
+ * @param {{ github: object, repo: string, ownerType: string, callers: object[], facts: object,
623
+ * snapshot: { tag: string, readFile: (path: string) => string | null },
624
+ * root: string, defaultBranch: string }} opts
625
+ * @returns {object[]}
626
+ */
627
+ export function checkStages({
628
+ github,
629
+ repo,
630
+ ownerType,
631
+ callers,
632
+ facts,
633
+ snapshot,
634
+ root,
635
+ defaultBranch,
636
+ }) {
637
+ const skipEach = (reason, details = []) =>
638
+ STAGE_CHECKS.map(([id, title]) => result(id, title, "skip", reason, { details }));
639
+ let listed;
640
+ try {
641
+ listed = listValues(github, repo, ownerType);
642
+ } catch (err) {
643
+ return skipEach(`Could not list repository variables: ${err.message}`);
644
+ }
645
+ const { values, orgNote } = listed;
646
+ const jobs = stageJobs(callers, values, facts);
647
+ const unread = callers
648
+ .filter((c) => c.parseIncomplete)
649
+ .map((c) => `${c.path}: ${c.parseIncomplete}`);
650
+ const custom = checkCustomHarness({
651
+ github,
652
+ repo,
653
+ root,
654
+ defaultBranch,
655
+ named: [...jobs.map((j) => j.name ?? ""), ...harnessVariableValues(values)],
656
+ snapshot,
657
+ });
658
+ if (jobs.length === 0) return [...skipEach("No Caller job runs a Stage.", unread), ...custom];
659
+ const results = [
660
+ checkHarness(jobs),
661
+ checkCredential({ jobs, values, github, repo, ownerType }),
662
+ checkEffort(jobs, values),
663
+ checkModel(jobs, values, repo),
664
+ checkSupport(jobs, snapshot),
665
+ ...custom,
666
+ ];
667
+ // A pass is never reported for what doctor could not read: part of a Caller,
668
+ // or organization variables that may change what a Stage resolves to.
669
+ const extra = [...unread, ...(orgNote ? [orgNote] : [])];
670
+ if (!extra.length) return results;
671
+ return results.map((r) => ({
672
+ ...r,
673
+ ...(r.status === "pass"
674
+ ? { status: "skip", summary: "Some Callers or variables could not be read." }
675
+ : {}),
676
+ details: [...r.details, ...extra],
677
+ }));
678
+ }
679
+
680
+ /**
681
+ * For a tag from before harness choice: warn about every harness variable that
682
+ * is set, since nothing at the tag reads it.
683
+ * @returns {object[]} none when no harness variable is set
684
+ */
685
+ export function checkHarnessVariables({ github, repo, ownerType, tag }) {
686
+ const ID = "harness-variables";
687
+ const TITLE = "Harness variables are read by the pinned tag";
688
+ let listed;
689
+ try {
690
+ listed = listNames(github, repo, "variable", ownerType);
691
+ } catch (err) {
692
+ return [result(ID, TITLE, "skip", `Could not list repository variables: ${err.message}`)];
693
+ }
694
+ const set = [...listed.names].filter((n) => /^AGENT_KIT_(?:[A-Z_]+_)?HARNESS$/.test(n)).sort();
695
+ if (set.length === 0) {
696
+ return listed.orgNote ? [result(ID, TITLE, "skip", listed.orgNote)] : [];
697
+ }
698
+ return [
699
+ result(ID, TITLE, "warn", `${set.length} harness variable(s) set, which ${tag} ignores.`, {
700
+ details: set.map(
701
+ (name) => `${name} is ignored by ${tag}, which runs every Stage on claude-code`,
702
+ ),
703
+ }),
704
+ ];
705
+ }