@mnaimfaizy/agent-kit 1.0.0-beta.14 → 1.0.0-beta.16

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 (180) 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 +583 -36
  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 +166 -5
  29. package/src/exec.mjs +14 -5
  30. package/src/factory/budget/budget.mjs +259 -0
  31. package/src/factory/build/command.mjs +321 -0
  32. package/src/factory/build/factory.mjs +473 -0
  33. package/src/factory/build/findings.mjs +55 -0
  34. package/src/factory/build/host.mjs +230 -0
  35. package/src/factory/build/notes.mjs +191 -0
  36. package/src/factory/build/pull-request.mjs +74 -0
  37. package/src/factory/bundle.mjs +146 -0
  38. package/src/factory/checks/allowed-paths.mjs +50 -0
  39. package/src/factory/checks/plan-header.mjs +296 -0
  40. package/src/factory/checks/qa.mjs +85 -0
  41. package/src/factory/checks/review.mjs +73 -0
  42. package/src/factory/checks/security.mjs +50 -0
  43. package/src/factory/checks/stage-check.mjs +89 -0
  44. package/src/factory/claims/command.mjs +187 -0
  45. package/src/factory/claims/release.mjs +111 -0
  46. package/src/factory/decision/answers.mjs +103 -0
  47. package/src/factory/decision/command.mjs +64 -0
  48. package/src/factory/decision/plan.mjs +99 -0
  49. package/src/factory/decision/request.mjs +116 -0
  50. package/src/factory/doctor/files.mjs +329 -0
  51. package/src/factory/doctor/index.mjs +56 -0
  52. package/src/factory/doctor/local.mjs +497 -0
  53. package/src/factory/doctor/orchestrate.mjs +146 -0
  54. package/src/factory/engine/lease.mjs +146 -0
  55. package/src/factory/engine/local-engine.mjs +177 -0
  56. package/src/factory/engine/lockfile.mjs +64 -0
  57. package/src/factory/engine/workflow-engine.mjs +124 -0
  58. package/src/factory/gate/comment.mjs +88 -0
  59. package/src/factory/gate/config.mjs +57 -0
  60. package/src/factory/gate/gate-core.mjs +250 -0
  61. package/src/factory/gate/guarded.mjs +17 -0
  62. package/src/factory/gate/reads.mjs +105 -0
  63. package/src/factory/gate/task.mjs +193 -0
  64. package/src/factory/gate/trip-reads.mjs +82 -0
  65. package/src/factory/gate/trip.mjs +87 -0
  66. package/src/factory/init/blueprint.mjs +174 -0
  67. package/src/factory/init/index.mjs +337 -0
  68. package/src/factory/labels/evidence.mjs +162 -0
  69. package/src/factory/labels/moves.mjs +32 -0
  70. package/src/factory/labels/reconcile.mjs +267 -0
  71. package/src/factory/labels/revert.mjs +87 -0
  72. package/src/factory/labels/timeline.mjs +72 -0
  73. package/src/factory/labels/voided.mjs +59 -0
  74. package/src/factory/limits/harness.mjs +39 -0
  75. package/src/factory/limits/limits.mjs +123 -0
  76. package/src/factory/merge/command.mjs +172 -0
  77. package/src/factory/outbox/check.mjs +240 -0
  78. package/src/factory/outbox/rulings.mjs +195 -0
  79. package/src/factory/plan/command.mjs +66 -0
  80. package/src/factory/plan/comment.mjs +156 -0
  81. package/src/factory/plan/publish.mjs +149 -0
  82. package/src/factory/plan/risk.mjs +153 -0
  83. package/src/factory/qa/command.mjs +163 -0
  84. package/src/factory/records/engine-record.mjs +133 -0
  85. package/src/factory/records/main.mjs +96 -0
  86. package/src/factory/records/record.mjs +226 -0
  87. package/src/factory/records/sink.mjs +57 -0
  88. package/src/factory/report/build.mjs +92 -0
  89. package/src/factory/report/command.mjs +80 -0
  90. package/src/factory/report/facts.mjs +226 -0
  91. package/src/factory/report/gate-section.mjs +122 -0
  92. package/src/factory/report/metrics.mjs +111 -0
  93. package/src/factory/report/reads.mjs +246 -0
  94. package/src/factory/report/render.mjs +121 -0
  95. package/src/factory/report/rollout.mjs +154 -0
  96. package/src/factory/review/command.mjs +182 -0
  97. package/src/factory/run/awake.mjs +70 -0
  98. package/src/factory/run/collect.mjs +77 -0
  99. package/src/factory/run/command.mjs +490 -0
  100. package/src/factory/run/gh.mjs +46 -0
  101. package/src/factory/run/launch.mjs +47 -0
  102. package/src/factory/run/pipelines.mjs +261 -0
  103. package/src/factory/run/raw.mjs +96 -0
  104. package/src/factory/run/restart.mjs +83 -0
  105. package/src/factory/run/s3.mjs +193 -0
  106. package/src/factory/run/secrets.mjs +142 -0
  107. package/src/factory/run/teardown.mjs +242 -0
  108. package/src/factory/run/token.mjs +68 -0
  109. package/src/factory/security/command.mjs +157 -0
  110. package/src/factory/setup/app.mjs +122 -0
  111. package/src/factory/setup/command.mjs +409 -0
  112. package/src/factory/setup/labels.mjs +25 -0
  113. package/src/factory/setup/reads.mjs +129 -0
  114. package/src/factory/setup/writes.mjs +126 -0
  115. package/src/factory/snapshot/write.mjs +176 -0
  116. package/src/factory/stop/command.mjs +136 -0
  117. package/src/factory/sweep/actions-main.mjs +117 -0
  118. package/src/factory/sweep/command.mjs +65 -0
  119. package/src/factory/sweep/knobs.mjs +78 -0
  120. package/src/factory/sweep/marker-version.mjs +15 -0
  121. package/src/factory/sweep/markers.mjs +112 -0
  122. package/src/factory/sweep/overlap.mjs +24 -0
  123. package/src/factory/sweep/run.mjs +198 -0
  124. package/src/factory/sweep/shell.mjs +394 -0
  125. package/src/factory/sweep/split.mjs +104 -0
  126. package/src/factory/sweep/states.mjs +87 -0
  127. package/src/factory/sweep/sweep-core.mjs +1781 -0
  128. package/src/factory/tracker/github.mjs +674 -0
  129. package/src/factory/tracker/operations.mjs +153 -0
  130. package/src/factory/upgrade/index.mjs +83 -0
  131. package/src/harness/adapters.mjs +30 -0
  132. package/src/harness/antigravity.mjs +187 -0
  133. package/src/harness/claude-code.mjs +8 -1
  134. package/src/harness/codex.mjs +219 -0
  135. package/src/harness/cursor.mjs +199 -0
  136. package/src/harness/custom/registry.mjs +21 -0
  137. package/src/harness/custom/schema.mjs +90 -0
  138. package/src/harness/custom.mjs +299 -0
  139. package/src/harness/facts.mjs +44 -7
  140. package/src/harness/gemini.mjs +164 -0
  141. package/src/harness/install-layer.mjs +86 -3
  142. package/src/harness/opencode.mjs +289 -0
  143. package/src/harness/resolve.mjs +156 -0
  144. package/src/harness/support-levels.mjs +151 -3
  145. package/src/harness-live/assess.mjs +29 -6
  146. package/src/harness-live/cursor-real.mjs +146 -0
  147. package/src/harness-live/cursor-version.mjs +70 -0
  148. package/src/harness-live/cursor.mjs +80 -0
  149. package/src/harness-live/custom.mjs +91 -0
  150. package/src/harness-live/fixture-harness.mjs +45 -0
  151. package/src/harness-live/harnesses.mjs +263 -0
  152. package/src/harness-live/host.mjs +113 -4
  153. package/src/harness-live/opencode.mjs +289 -0
  154. package/src/harness-live/probes.mjs +87 -7
  155. package/src/harness-live/run.mjs +101 -20
  156. package/src/harness-live/setup.mjs +126 -0
  157. package/src/harness-live/stage.mjs +25 -15
  158. package/src/harness-live/suite.mjs +276 -95
  159. package/src/harness-test.mjs +116 -0
  160. package/src/init.mjs +374 -36
  161. package/src/kit-owned-paths.mjs +1 -1
  162. package/src/model-proxy/core.mjs +128 -20
  163. package/src/model-proxy/profiles/anthropic.mjs +54 -10
  164. package/src/model-proxy/profiles/gemini-api.mjs +311 -0
  165. package/src/model-proxy/profiles/openai.mjs +327 -0
  166. package/src/model-proxy/stub-dialects/gemini-api.mjs +178 -0
  167. package/src/model-proxy/stub-dialects/openai.mjs +173 -0
  168. package/src/model-proxy/stub.mjs +9 -1
  169. package/src/stage/audit.mjs +79 -0
  170. package/src/stage/egress-route.mjs +207 -0
  171. package/src/stage/implement/carry.mjs +308 -0
  172. package/src/stage/implement/sandbox.mjs +271 -0
  173. package/src/stage/implement/verify.mjs +70 -0
  174. package/src/stage/implement.mjs +218 -0
  175. package/src/stage/plan.mjs +115 -0
  176. package/src/stage/review-response.mjs +172 -0
  177. package/src/stage/review.mjs +185 -0
  178. package/src/stage/workspace.mjs +274 -0
  179. package/src/stage.mjs +1087 -0
  180. package/src/upgrade.mjs +39 -7
@@ -1,44 +1,91 @@
1
- // The tar streams the Deep scan launcher moves across the sandbox boundary,
2
- // in Node core (ADR 0001). In: a ustar archive of files the launcher wrote
3
- // itself (the grounding it fetched). Out: the one report file, read from the
1
+ // The tar streams the Launcher moves across the sandbox boundary,
2
+ // in Node core (ADR 0001). In: a ustar archive the launcher builds itself
3
+ // (the grounding it fetched, a brief, a CI Stage's copy of the checkout). Out: the one report file, read from the
4
4
  // archive `tar -c` writes from the sandbox through `docker exec`, refusing anything that is
5
5
  // not exactly one regular file.
6
6
 
7
7
  const BLOCK = 512;
8
8
 
9
9
  /**
10
- * A ustar archive of `entries`, each a folder (`dir: true`) or a file with
11
- * its bytes. Paths are relative, use `/`, and fit in 100 bytes.
12
- * @param {Array<{ path: string, dir?: boolean, data?: Buffer }>} entries
10
+ * A ustar archive of `entries`, each a folder (`dir: true`), a symbolic link
11
+ * (`link`, its target) or a file with its bytes. Paths are relative and use
12
+ * `/`; a path or link target past ustar's 100 bytes goes in a PAX header.
13
+ * @param {Array<{ path: string, dir?: boolean, link?: string, executable?: boolean, data?: Buffer }>} entries
13
14
  * @returns {Buffer}
14
15
  */
15
16
  export function tarOf(entries) {
16
17
  const parts = [];
17
18
  for (const entry of entries) {
18
19
  const name = entry.dir ? `${entry.path.replace(/\/$/, "")}/` : entry.path;
19
- if (Buffer.byteLength(name) > 100 || name.startsWith("/") || name.split("/").includes("..")) {
20
+ if (name.startsWith("/") || name.split("/").includes("..") || name.includes("\0")) {
20
21
  throw new Error(`tar entry name not allowed: ${JSON.stringify(name)}`);
21
22
  }
22
- const data = entry.dir ? Buffer.alloc(0) : (entry.data ?? Buffer.alloc(0));
23
- const header = Buffer.alloc(BLOCK);
24
- header.write(name, 0, 100, "utf8");
25
- header.write(octal(entry.dir ? 0o755 : 0o644, 8), 100, "ascii");
26
- header.write(octal(0, 8), 108, "ascii");
27
- header.write(octal(0, 8), 116, "ascii");
28
- header.write(octal(data.length, 12), 124, "ascii");
29
- header.write(octal(0, 12), 136, "ascii");
30
- header.write(" ", 148, "ascii");
31
- header.write(entry.dir ? "5" : "0", 156, "ascii");
32
- header.write("ustar\u000000", 257, "binary");
33
- let sum = 0;
34
- for (const byte of header) sum += byte;
35
- header.write(`${sum.toString(8).padStart(6, "0")}\u0000 `, 148, "binary");
36
- parts.push(header, data, Buffer.alloc(padding(data.length)));
23
+ const data =
24
+ entry.dir || entry.link !== undefined ? Buffer.alloc(0) : (entry.data ?? Buffer.alloc(0));
25
+ const long = [
26
+ ...(Buffer.byteLength(name) > NAME_BYTES ? [["path", name]] : []),
27
+ ...(Buffer.byteLength(entry.link ?? "") > NAME_BYTES ? [["linkpath", entry.link]] : []),
28
+ ];
29
+ if (long.length) {
30
+ const records = Buffer.from(
31
+ long.map(([key, value]) => paxRecord(key, value)).join(""),
32
+ "utf8",
33
+ );
34
+ parts.push(
35
+ headerOf({ name: "PaxHeader", type: "x", mode: 0o644, size: records.length }),
36
+ records,
37
+ Buffer.alloc(padding(records.length)),
38
+ );
39
+ }
40
+ parts.push(
41
+ headerOf({
42
+ name,
43
+ type: entry.dir ? "5" : entry.link !== undefined ? "2" : "0",
44
+ mode: entry.dir || entry.executable ? 0o755 : 0o644,
45
+ size: data.length,
46
+ link: entry.link,
47
+ }),
48
+ data,
49
+ Buffer.alloc(padding(data.length)),
50
+ );
37
51
  }
38
52
  parts.push(Buffer.alloc(BLOCK * 2));
39
53
  return Buffer.concat(parts);
40
54
  }
41
55
 
56
+ /** The longest name or link target a ustar header holds. */
57
+ const NAME_BYTES = 100;
58
+
59
+ /** One 512-byte ustar header. A name too long for it is cut: its PAX header holds it. */
60
+ function headerOf({ name, type, mode, size, link }) {
61
+ const header = Buffer.alloc(BLOCK);
62
+ header.write(name, 0, NAME_BYTES, "utf8");
63
+ header.write(octal(mode, 8), 100, "ascii");
64
+ header.write(octal(0, 8), 108, "ascii");
65
+ header.write(octal(0, 8), 116, "ascii");
66
+ header.write(octal(size, 12), 124, "ascii");
67
+ header.write(octal(0, 12), 136, "ascii");
68
+ header.write(" ", 148, "ascii");
69
+ header.write(type, 156, "ascii");
70
+ if (link !== undefined) header.write(link, 157, NAME_BYTES, "utf8");
71
+ header.write("ustar\u000000", 257, "binary");
72
+ let sum = 0;
73
+ for (const byte of header) sum += byte;
74
+ header.write(`${sum.toString(8).padStart(6, "0")}\0 `, 148, "binary");
75
+ return header;
76
+ }
77
+
78
+ /** A PAX record, `<length> <key>=<value>
79
+ `, its length counting itself. */
80
+ function paxRecord(key, value) {
81
+ const body = ` ${key}=${value}
82
+ `;
83
+ const bytes = Buffer.byteLength(body);
84
+ let length = bytes + String(bytes).length;
85
+ if (String(length).length !== String(bytes).length) length = bytes + String(length).length;
86
+ return `${length}${body}`;
87
+ }
88
+
42
89
  /**
43
90
  * The one regular file in a tar archive, or why there is not exactly one.
44
91
  * PAX extended headers are skipped; a folder, a link or a second file is
@@ -16,10 +16,12 @@ import {
16
16
  DISCOVERED,
17
17
  fence,
18
18
  groundingLines,
19
+ removedLines,
19
20
  SETUP_DONE,
20
21
  SKILL_DIR,
21
22
  threatPackAndRecipe,
22
23
  } from "./agent.mjs";
24
+ import { textFor } from "./harness-text.mjs";
23
25
 
24
26
  export const VERIFY_DOCS_URL = `https://github.com/mnaimfaizy/agent-kit/blob/v${CLI_VERSION}/docs/security-audit.md#verification-run`;
25
27
 
@@ -197,10 +199,12 @@ const lfOf = (text) => text.replace(/\r\n?/g, "\n");
197
199
  * grounding: Array<{ source: string, at: string }>,
198
200
  * paths: { workspace: string, grounding: string, report: string },
199
201
  * discovers?: boolean,
202
+ * harness?: string,
200
203
  * }} opts `discovers`: Claude Code runs without `--bare` (the
201
204
  * subscription path), so the brief says what it discovers.
202
205
  */
203
206
  export function verificationBrief({
207
+ harness = "claude-code",
204
208
  ref,
205
209
  short,
206
210
  findings,
@@ -215,7 +219,7 @@ export function verificationBrief({
215
219
  return [
216
220
  "# Verification run brief, from the agent-kit deep-scan launcher",
217
221
  "",
218
- "This is the launcher's brief. You are running inside the closed, disposable sandbox that `agent-kit deep-scan --verify` started for a Verification run: re-attempt the Reproduction of each finding in the finding file, by the Verification-run procedure below, and nothing more. Your only network route is the launcher's model proxy, and the web tools (WebFetch, WebSearch) are off.",
222
+ `This is the launcher's brief. You are running inside the closed, disposable sandbox that \`agent-kit deep-scan --verify\` started for a Verification run: re-attempt the Reproduction of each finding in the finding file, by the Verification-run procedure below, and nothing more. Your only network route is the launcher's model proxy, and ${textFor(harness).webOff}.`,
219
223
  "",
220
224
  "## Where things are",
221
225
  "",
@@ -224,6 +228,7 @@ export function verificationBrief({
224
228
  ...findings.map((f) => ` - \`${f.conceptId}\` at ${f.location}`),
225
229
  ...groundingLines(grounding, paths),
226
230
  `- The report: write it to \`${paths.report}\`, in the Verification-run variant of the report format below, early, and update it as each answer lands. It is the only file that leaves the sandbox.`,
231
+ ...removedLines(harness, paths),
227
232
  SETUP_DONE,
228
233
  ...(discovers ? [DISCOVERED] : []),
229
234
  "",
package/src/deep-scan.mjs CHANGED
@@ -1,4 +1,7 @@
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.
2
5
  // It first refuses a harness whose Support Level for the Deep scan is below
3
6
  // `tried`, unless the run is a Proving run (`--proving-run`, ADR 0028).
4
7
  // Its first stage finds the Consumer's Scan recipe at the trusted ref (the
@@ -11,7 +14,7 @@
11
14
  // process); then the choice of a sandbox runtime from the host, or its
12
15
  // refusal, with no override (ADR 0018). Then the sandbox lifecycle on that
13
16
  // runtime, from image to teardown (deep-scan/lifecycle.mjs), its agent step
14
- // the real Claude Code behind the key-injecting model proxy, every run
17
+ // the real harness behind the key-injecting model proxy, every run
15
18
  // bounded by the limits its flags set (deep-scan/limits.mjs). With
16
19
  // `--verify <file> --ref <ref>`, the run is a Verification run instead
17
20
  // (deep-scan/verify.mjs): local only, confirm-only against the finding file,
@@ -38,6 +41,7 @@ import {
38
41
  SUBSCRIPTION,
39
42
  withoutCredentials,
40
43
  } from "./deep-scan/credential.mjs";
44
+ import { textFor } from "./deep-scan/harness-text.mjs";
41
45
  import { DEFAULT_LIMITS, describeLimits, parseLimits, VERIFY_LIMITS } from "./deep-scan/limits.mjs";
42
46
  import { publicHttpsFetch } from "./deep-scan/grounding-url.mjs";
43
47
  import { runLifecycle } from "./deep-scan/lifecycle.mjs";
@@ -49,7 +53,9 @@ import {
49
53
  strayTokens,
50
54
  writeRunSummary,
51
55
  } from "./deep-scan/preflight.mjs";
52
- import { effortFor, readHarnesses } from "./harness/facts.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";
53
59
  import { RUNTIMES_DOCS_URL, selectRuntime } from "./deep-scan/runtime.mjs";
54
60
  import {
55
61
  readFindingFile,
@@ -59,13 +65,17 @@ import {
59
65
  } from "./deep-scan/verify.mjs";
60
66
  import { CLI_VERSION } from "./tags.mjs";
61
67
 
62
- /** The Deep scan's harness, as `cli/harnesses.json` describes it. */
63
- const HARNESS = readHarnesses().harnesses["claude-code"];
68
+ /** Each harness, as `cli/harnesses.json` describes it. */
69
+ const HARNESSES = readHarnesses().harnesses;
64
70
 
65
- /** The effort levels it accepts: nothing else reaches the command line. */
66
- export const EFFORTS = Object.freeze(HARNESS.effortValues);
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)}`;
67
76
 
68
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`;
69
79
  const PROVING_DOCS_URL = `https://github.com/mnaimfaizy/agent-kit/blob/v${CLI_VERSION}/docs/harnesses.md#proving-runs`;
70
80
 
71
81
  /**
@@ -73,6 +83,7 @@ const PROVING_DOCS_URL = `https://github.com/mnaimfaizy/agent-kit/blob/v${CLI_VE
73
83
  * cwd: string,
74
84
  * runner: import("./exec.mjs").Runner,
75
85
  * recipePath?: string,
86
+ * harness?: string,
76
87
  * defaultBranch?: string,
77
88
  * credential?: string,
78
89
  * credentialFrom?: string,
@@ -110,6 +121,7 @@ export async function runDeepScan({
110
121
  cwd,
111
122
  runner: hostRunner,
112
123
  recipePath,
124
+ harness: harnessFlag,
113
125
  defaultBranch,
114
126
  credential,
115
127
  credentialFrom,
@@ -183,10 +195,38 @@ export async function runDeepScan({
183
195
  );
184
196
  return 2;
185
197
  }
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
+
186
224
  // The Stage's own effort: one its harness does not accept is refused.
187
- if (effort !== undefined && (effort === "" || "refused" in effortFor(HARNESS, { effort }))) {
225
+ if (effort !== undefined && (effort === "" || "refused" in effortFor(facts, { effort }))) {
188
226
  err(
189
- `--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)}`,
190
230
  );
191
231
  return 2;
192
232
  }
@@ -221,14 +261,21 @@ export async function runDeepScan({
221
261
  return 2;
222
262
  }
223
263
  const subscription = chosen.kind === SUBSCRIPTION;
224
- 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);
225
272
  if ("error" in source) {
226
273
  err(source.error);
227
274
  return 2;
228
275
  }
229
276
 
230
277
  // The Support Level (ADR 0028), before anything is read or run.
231
- const support = deepScanSupport({ provingRun });
278
+ const support = deepScanSupport({ harness, provingRun });
232
279
  // A refused run is named too, in the log and the run summary.
233
280
  out(support.line);
234
281
  const unwritten = writeRunSummary(env, support.summary);
@@ -361,7 +408,7 @@ export async function runDeepScan({
361
408
  [
362
409
  `${tokens.join(" and ")} ${tokens.length > 1 ? "are" : "is"} set in deep-scan's environment, and a GitHub token must never reach the sandbox.`,
363
410
  `Unset ${tokens.length > 1 ? "them" : "it"} for this run, for example:`,
364
- ` env -u GH_TOKEN -u GITHUB_TOKEN npx @mnaimfaizy/agent-kit deep-scan${provingRun ? " --proving-run" : ""}`,
411
+ ` env -u GH_TOKEN -u GITHUB_TOKEN npx @mnaimfaizy/agent-kit deep-scan${harnessFlag !== undefined ? ` --harness ${harness}` : ""}${provingRun ? " --proving-run" : ""}`,
365
412
  " In PowerShell: Remove-Item Env:GH_TOKEN, Env:GITHUB_TOKEN -ErrorAction SilentlyContinue, then run it again.",
366
413
  ],
367
414
  RUNTIMES_DOCS_URL,
@@ -441,7 +488,14 @@ export async function runDeepScan({
441
488
  }
442
489
 
443
490
  // The model credential: read once, and kept only in this process.
444
- 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
+ });
445
499
  if ("refused" in key) return refuse(key.refused, CREDENTIALS_DOCS_URL);
446
500
  out(
447
501
  subscription
@@ -452,8 +506,14 @@ export async function runDeepScan({
452
506
  const choice = selectRuntime({ runner, platform });
453
507
  if ("refused" in choice) return refuse(choice.refused, RUNTIMES_DOCS_URL);
454
508
  out(`Sandbox runtime: ${choice.runtime.name}.`);
455
- 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
+ }
456
515
  return runLifecycle({
516
+ harness,
457
517
  limits,
458
518
  ...(model !== undefined ? { model } : {}),
459
519
  ...(effort !== undefined ? { effort } : {}),
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,7 +32,24 @@ 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";
44
+ import {
45
+ engineOf,
46
+ FACTORY_FILE_CHECKS,
47
+ FACTORY_LOCAL_CHECKS,
48
+ factoryFileResults,
49
+ factoryLocalChecks,
50
+ diskReads,
51
+ hasFactory,
52
+ } from "./factory/doctor/index.mjs";
28
53
  import { createGitHub } from "./github.mjs";
29
54
  import { openKitTag, PreManifestTagError, serverFromEnv } from "./kit-tag.mjs";
30
55
 
@@ -49,6 +74,9 @@ export const LOCAL_ONLY_CHECKS = [
49
74
  ["ruleset-tags", "Release tags have a v* tag ruleset"],
50
75
  ["release-tag-push", "Release tags can be pushed under the tag ruleset"],
51
76
  ["review-response-mode", "Review response mode is set up"],
77
+ ["github-app", "Your GitHub App is set up"],
78
+ ["ci-workflow", "CI starts for agent pushes"],
79
+ ...STAGE_CHECKS,
52
80
  ];
53
81
 
54
82
  const skipAll = (ids, reason) => ids.map(([id, title]) => result(id, title, "skip", reason));
@@ -62,6 +90,7 @@ const skipAll = (ids, reason) => ids.map(([id, title]) => result(id, title, "ski
62
90
  * repo?: string,
63
91
  * openTag?: typeof openKitTag,
64
92
  * env?: NodeJS.ProcessEnv,
93
+ * now?: () => number,
65
94
  * }} opts
66
95
  * @returns {{ mode: "local" | "ci", modeReason: string | null, repo: string | null, tag: string | null, results: object[], refusal: string | null, exitCode: number }}
67
96
  */
@@ -73,6 +102,7 @@ export function runDoctor({
73
102
  repo: repoArg,
74
103
  openTag = openKitTag,
75
104
  env = process.env,
105
+ now = Date.now,
76
106
  }) {
77
107
  const results = [];
78
108
  let mode = ci ? "ci" : "local";
@@ -185,6 +215,10 @@ export function runDoctor({
185
215
 
186
216
  results.push(guarded("scan-recipe", () => checkScanRecipe({ root }), "Scan recipe"));
187
217
 
218
+ // A checkout with no Factory is checked exactly as before.
219
+ const factory = hasFactory(root);
220
+ if (factory) results.push(...guardedFactoryFiles({ root, tag: pins.tag }));
221
+
188
222
  if (mode === "ci") {
189
223
  results.push(
190
224
  ...skipAll(
@@ -192,8 +226,31 @@ export function runDoctor({
192
226
  `CI mode (${modeReason}): needs a local run with an admin gh login.`,
193
227
  ),
194
228
  );
229
+ if (factory) {
230
+ results.push(
231
+ ...skipAll(
232
+ FACTORY_LOCAL_CHECKS,
233
+ `CI mode (${modeReason}): needs a local run with an admin gh login.`,
234
+ ),
235
+ );
236
+ }
195
237
  } else {
196
- results.push(...localChecks({ runner, cwd, info, files, callers, snapshot }));
238
+ results.push(...localChecks({ runner, cwd, root, info, files, callers, snapshot }));
239
+ results.push(...harnessChecks({ runner, cwd, root, info, callers, snapshot }));
240
+ if (factory) {
241
+ const github = createGitHub(runner, { cwd, hostname: info.host ?? null });
242
+ results.push(
243
+ ...factoryLocalChecks({
244
+ github,
245
+ runner,
246
+ cwd,
247
+ info,
248
+ engine: engineOf(diskReads(root)),
249
+ guard: guarded,
250
+ now,
251
+ }),
252
+ );
253
+ }
197
254
  }
198
255
  } finally {
199
256
  snapshot?.cleanup();
@@ -209,6 +266,19 @@ export function runDoctor({
209
266
  });
210
267
  }
211
268
 
269
+ /** The Factory's file checks; a crash becomes one failed check, never a silent pass. */
270
+ function guardedFactoryFiles({ root, tag }) {
271
+ try {
272
+ return factoryFileResults({ root, tag });
273
+ } catch (err) {
274
+ return FACTORY_FILE_CHECKS.map(([id, title]) =>
275
+ result(id, title, "fail", `Check crashed: ${firstLine(err?.message ?? err)}`, {
276
+ details: ["This is a bug in doctor; the other checks still ran."],
277
+ }),
278
+ );
279
+ }
280
+ }
281
+
212
282
  function repoInfo(github, repoArg) {
213
283
  return github.repoInfo(repoArg);
214
284
  }
@@ -226,20 +296,23 @@ export function guarded(id, run, title = TITLES[id] ?? id) {
226
296
  }
227
297
  }
228
298
 
229
- function localChecks({ runner, cwd, info, files, callers, snapshot }) {
299
+ function localChecks({ runner, cwd, root, info, files, callers, snapshot }) {
230
300
  const github = createGitHub(runner, { cwd, hostname: info.host ?? null });
231
301
  const { repo, owner, ownerType, defaultBranch } = info;
232
302
  const raw = [];
233
303
  const out = { push: (...items) => raw.push(...items) };
234
304
 
235
305
  if (snapshot) {
306
+ // A tag that publishes its harness facts asks for each Stage's own
307
+ // credential, in the harness checks.
308
+ const perStageCredential = snapshot.readFile(HARNESSES_PATH) !== null;
236
309
  let requirements = null;
237
310
  out.push(
238
311
  guarded("secrets", () => {
239
312
  requirements = deriveRequirements(callers, (file) =>
240
313
  snapshot.readFile(`.github/workflows/${file}`),
241
314
  );
242
- return checkSecrets({ github, repo, ownerType, requirements });
315
+ return checkSecrets({ github, repo, ownerType, requirements, perStageCredential });
243
316
  }),
244
317
  );
245
318
  out.push(
@@ -285,7 +358,22 @@ function localChecks({ runner, cwd, info, files, callers, snapshot }) {
285
358
  ),
286
359
  );
287
360
 
288
- out.push(guarded("claude-app", () => checkClaudeApp({ github, repo, owner, ownerType })));
361
+ // Read once, and only if a check that uses it runs.
362
+ let onAction = null;
363
+ const actions = () => (onAction ??= actionJobs({ github, repo, ownerType, callers, snapshot }));
364
+ let onApp = null;
365
+ const appActions = () =>
366
+ (onApp ??= actionJobs({ github, repo, ownerType, callers, snapshot, app: true }));
367
+ out.push(
368
+ guarded("claude-app", () => {
369
+ // Only a Stage whose action step takes the Claude GitHub App's token
370
+ // needs it: one given the job token does not. Callers doctor could not
371
+ // read in full may hide such a Stage.
372
+ const needed =
373
+ callers.some((c) => c.parseIncomplete) || [...appActions().values()].some(Boolean);
374
+ return checkClaudeApp({ github, repo, owner, ownerType, needed });
375
+ }),
376
+ );
289
377
 
290
378
  let rulesets = null;
291
379
  let rulesetError = null;
@@ -307,9 +395,80 @@ function localChecks({ runner, cwd, info, files, callers, snapshot }) {
307
395
  checkReviewResponseMode({ github, repo, ownerType, callers }),
308
396
  ),
309
397
  );
398
+ out.push(...appChecks({ github, root, info, callers, snapshot, actions }));
310
399
  return raw;
311
400
  }
312
401
 
402
+ /** The Consumer's own GitHub App, and how CI starts without one. */
403
+ function appChecks({ github, root, info, callers, snapshot, actions }) {
404
+ const { repo, owner, ownerType } = info;
405
+ const readReusable = snapshot ? (file) => snapshot.readFile(`.github/workflows/${file}`) : null;
406
+ let settings = null;
407
+ let jobs = [];
408
+ const unread = unreadCallers(callers);
409
+ const onAction = (where) => actions().get(where) === true;
410
+ const unreadHarness = (where) => actions().get(where) === "unknown";
411
+ const results = [
412
+ guarded("github-app", () => {
413
+ jobs = pushingJobs(callers, readReusable);
414
+ settings = readAppSettings({ github, repo, ownerType });
415
+ const tag = snapshot?.tag;
416
+ return checkGitHubApp({ repo, settings, jobs, unread, tag, onAction, unreadHarness });
417
+ }),
418
+ ];
419
+ const appSet = Boolean(settings?.idSet && settings.keySet);
420
+ if (appSet) {
421
+ const installed = () => checkGitHubAppInstalled({ github, repo, owner, ownerType });
422
+ results.push(guarded("github-app-installed", installed, "Your GitHub App is installed"));
423
+ }
424
+ // Not read: a half doctor cannot see may be set.
425
+ const appUnknown = !settings || Boolean(settings.unknown);
426
+ const ciWorkflow = () =>
427
+ checkCiWorkflow({ root, jobs, unread, appSet, appUnknown, onAction, unreadHarness });
428
+ results.push(guarded("ci-workflow", ciWorkflow));
429
+ return results;
430
+ }
431
+
432
+ /** The harness checks, from the pinned tag's cli/harnesses.json. */
433
+ function harnessChecks({ runner, cwd, root, info, callers, snapshot }) {
434
+ const skipEach = (reason) => skipAll(STAGE_CHECKS, reason);
435
+ if (!snapshot) return skipEach("Needs the pinned tag's harness facts; fix the pins first.");
436
+ const github = createGitHub(runner, { cwd, hostname: info.host ?? null });
437
+ const { repo, ownerType, defaultBranch } = info;
438
+ const { tag } = snapshot;
439
+ let facts;
440
+ try {
441
+ facts = readHarnessFacts(snapshot);
442
+ } catch (err) {
443
+ const [[id, title], ...rest] = STAGE_CHECKS;
444
+ const reason = `${tag}'s ${HARNESSES_PATH} could not be read: ${firstLine(err.message)}`;
445
+ return [result(id, title, "fail", reason), ...skipAll(rest, reason)];
446
+ }
447
+ if (facts === null) {
448
+ return [
449
+ ...skipEach(`${tag} predates harness choice: it has no ${HARNESSES_PATH}.`),
450
+ ...checkHarnessVariables({ github, repo, ownerType, tag }),
451
+ ];
452
+ }
453
+ try {
454
+ return checkStages({
455
+ github,
456
+ repo,
457
+ ownerType,
458
+ callers,
459
+ facts,
460
+ snapshot,
461
+ root,
462
+ defaultBranch,
463
+ });
464
+ } catch (err) {
465
+ const crash = () => {
466
+ throw err;
467
+ };
468
+ return STAGE_CHECKS.map(([id, title]) => guarded(id, crash, title));
469
+ }
470
+ }
471
+
313
472
  function finish({ mode, modeReason, repo, tag, results, refusal, strict }) {
314
473
  const final = strict
315
474
  ? results.map((r) => (r.status === "warn" ? { ...r, status: "fail", strict: true } : r))
@@ -369,7 +528,7 @@ export function formatResult(r) {
369
528
  }
370
529
 
371
530
  /** doctor --ci's pin and Kit-owned path checks, against an already-fetched tag. */
372
- export function fileAndPinChecks({ runner, root, snap }) {
531
+ export function fileAndPinChecks({ runner, root, snap, factory = false }) {
373
532
  let pins;
374
533
  try {
375
534
  pins = checkPins(readWorkflows(root).files);
@@ -395,6 +554,8 @@ export function fileAndPinChecks({ runner, root, snap }) {
395
554
  result("kit-owned-trees", "Kit-owned paths match the pinned tag", "fail", err.message),
396
555
  );
397
556
  }
557
+ // `upgrade` asks for the Factory's file checks too, when the checkout has a Factory.
558
+ if (factory) results.push(...guardedFactoryFiles({ root, tag: snap.tag }));
398
559
  return results;
399
560
  }
400
561
 
package/src/exec.mjs CHANGED
@@ -1,9 +1,10 @@
1
1
  // Runs commands as argument arrays, never through a shell, so no string from a
2
2
  // Consumer file or a GitHub response is ever parsed as shell syntax. Each
3
3
  // subcommand gets a runner that runs only the commands on its own allowlist:
4
- // `init`, `upgrade` and `doctor` reach only `git` and `gh`, and `deep-scan`
5
- // alone adds the accepted sandbox runtimes' CLIs and the 1Password CLI, which
6
- // reads its model credential (ADR 0019). There is no
4
+ // `init`, `upgrade` and `doctor` reach only `git` and `gh`; `deep-scan` and
5
+ // `factory-run` add the accepted sandbox runtimes' CLIs and the 1Password CLI, which
6
+ // reads the model credential (ADR 0019), and `factory-run` adds `gh` beside them and the
7
+ // host's keep-awake tools (`caffeinate`, `systemd-inhibit`). There is no
7
8
  // second runner that bypasses this. Every module takes a runner as a
8
9
  // parameter; tests inject a fake one, or a fake spawn behind the real
9
10
  // allowlist. A runner also has `start`, the same command run without
@@ -12,7 +13,7 @@
12
13
 
13
14
  import { spawn as spawnChild, spawnSync } from "node:child_process";
14
15
 
15
- /** The sandbox runtimes' command-line tools, which only `deep-scan` may run. */
16
+ /** The sandbox runtimes' command-line tools, which only `deep-scan` and `factory-run` may run. */
16
17
  export const RUNTIME_CLIS = Object.freeze([
17
18
  "sbx",
18
19
  "docker",
@@ -21,7 +22,7 @@ export const RUNTIME_CLIS = Object.freeze([
21
22
  "firecracker",
22
23
  ]);
23
24
 
24
- /** The secret managers' command-line tools, which only `deep-scan` may run. */
25
+ /** The secret managers' command-line tools, which only `deep-scan` and `factory-run` may run. */
25
26
  export const SECRET_MANAGER_CLIS = Object.freeze(["op"]);
26
27
 
27
28
  const ALLOWLISTS = Object.freeze({
@@ -29,6 +30,14 @@ const ALLOWLISTS = Object.freeze({
29
30
  upgrade: Object.freeze(["git", "gh"]),
30
31
  doctor: Object.freeze(["git", "gh"]),
31
32
  "deep-scan": Object.freeze(["git", ...RUNTIME_CLIS, ...SECRET_MANAGER_CLIS]),
33
+ "factory-run": Object.freeze([
34
+ "git",
35
+ "gh",
36
+ ...SECRET_MANAGER_CLIS,
37
+ ...RUNTIME_CLIS,
38
+ "caffeinate",
39
+ "systemd-inhibit",
40
+ ]),
32
41
  });
33
42
 
34
43
  /**