@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
package/src/cli.mjs CHANGED
@@ -1,18 +1,29 @@
1
1
  // Argument parsing and dispatch. Exit codes: 0 ok, 1 a check failed (or a
2
2
  // warning under --strict, the tag or the change was refused, or deep-scan
3
- // refused, or a sandbox step failed), 2 usage error (including a missing
4
- // answer when there is no terminal to ask on), 3 a deep-scan limit stopped
5
- // the run (after copying out any report and tearing the sandbox down), 130
6
- // or 143 deep-scan was interrupted by SIGINT or SIGTERM (likewise).
3
+ // refused, a sandbox step failed, or a Stage did not complete), 2 usage error
4
+ // (including a missing answer when there is no terminal to ask on), 3 a
5
+ // deep-scan or stage limit stopped the run (after copying out any report and
6
+ // tearing the sandbox down), 130 or 143 one was interrupted by SIGINT or
7
+ // SIGTERM (likewise).
7
8
 
9
+ import { readFileSync } from "node:fs";
10
+ import { homedir, hostname } from "node:os";
8
11
  import { parseArgs } from "node:util";
9
12
  import { runDeepScan } from "./deep-scan.mjs";
13
+ import { runFactoryReport } from "./factory/report/command.mjs";
14
+ import { parseDuration, runFactoryRun } from "./factory/run/command.mjs";
15
+ import { runFactorySetup } from "./factory/setup/command.mjs";
16
+ import { readLock, stateDirOf } from "./factory/engine/lockfile.mjs";
17
+ import { runFactoryStop } from "./factory/stop/command.mjs";
18
+ import { runFactorySweep } from "./factory/sweep/command.mjs";
10
19
  import { formatReport, runDoctor } from "./doctor.mjs";
20
+ import { runHarnessTest } from "./harness-test.mjs";
11
21
  import { REPO_PATTERN, sanitizeLine } from "./checks/result.mjs";
12
22
  import { runnerFor } from "./exec.mjs";
13
23
  import { askYesNo } from "./prompt.mjs";
14
24
  import { CLI_VERSION, isReleaseTag } from "./tags.mjs";
15
25
  import { runInit } from "./init.mjs";
26
+ import { runStage, STAGE_COMMANDS } from "./stage.mjs";
16
27
  import { runUpgrade } from "./upgrade.mjs";
17
28
 
18
29
  export const VERSION = CLI_VERSION;
@@ -37,12 +48,48 @@ Commands:
37
48
  chooses a sandbox runtime from the host or refuses (no
38
49
  override), then runs the sandbox: image, copy-in of the
39
50
  default branch's tip, setup with egress only to the recipe's
40
- registries, network cut, the real Claude Code behind a
51
+ registries, network cut, the real harness behind a
41
52
  key-injecting model proxy on this machine (its only route
42
53
  out), copy-out of the report only, and teardown. Every run
43
54
  is bounded by wall clocks, a turn limit and a token cap.
44
55
  With --verify <file> --ref <ref>, a local-only
45
56
  Verification run: does a fix hold for known findings?
57
+ stage Run one CI Stage in the same sandbox, as the reusable
58
+ workflows do: stage audit, the static security audit, stage
59
+ plan, the plan of an issue, stage review, the pull request
60
+ review, stage implement, the implementer, or stage
61
+ review-response, the Review responder. Copies the
62
+ checked-out commit in, hands the harness the brief it is
63
+ given, and writes the Stage result and the raw transcript to
64
+ private files. Writes nothing to GitHub.
65
+ factory factory setup: the GitHub side of adopting the Factory (after
66
+ init --factory): labels, the pinned control issue, the App and
67
+ its key, the ruleset. Asks before each write.
68
+ factory sweep: one sweep of this repository's factory issues,
69
+ the same sweep the factory-dispatcher workflow runs. With the
70
+ Kill switch AGENT_KIT_FACTORY_ENABLED exactly true, it claims each
71
+ queued, ready-for-agent issue (a Claim comment, read back), sets
72
+ factory:planning and starts that Stage's Caller; a queued issue
73
+ without ready-for-agent goes to factory:needs-decision. Otherwise
74
+ it changes nothing. The Kill switch is read from the environment,
75
+ else from the repository's variables.
76
+ factory report: how the Factory is doing, from the tracker alone
77
+ and your own gh login: merge rate, first-pass success, lead time,
78
+ escalation and revert rates and tokens per merged pull request,
79
+ by Risk tier; the Rollout phase your config matches and whether
80
+ the next bar is met. Reads only; posts nothing.
81
+ factory stop: stops the Factory at once, as gh run cancel would:
82
+ cancels every queued or running run of the Dispatcher and the
83
+ Stage Callers. Releases no Claim; never sets the Kill switch.
84
+ On a machine running factory run it also asks that engine to drain.
85
+ factory run: the Orchestrate engine (preview): the same sweep, run
86
+ from this machine in a loop, with Stages in Launcher sandboxes.
87
+ Needs AGENT_KIT_GITHUB_TOKEN (a fine-grained token for this one
88
+ repository, or an op:// reference) and a model key.
89
+ harness harness test custom:<name>: run the live probe suite on your
90
+ own Custom harness file, against a stub model, in the real
91
+ sandbox under gVisor. The first half of a Proving run. It needs
92
+ no model credential.
46
93
 
47
94
  Options for doctor:
48
95
  --ci Check only Kit-owned paths and uses: pins (no gh needed).
@@ -50,6 +97,21 @@ Options for doctor:
50
97
  --strict Treat warnings as failures.
51
98
  --repo <o/r> The GitHub repository to check (default: gh's choice for
52
99
  the current directory).
100
+ On the Orchestrate engine doctor also checks the PAT's reach and reads, through
101
+ AGENT_KIT_GITHUB_TOKEN where it holds a literal (not an op:// reference).
102
+
103
+ Options for init --factory (adopt the Factory blueprint; local files only; each answer is asked
104
+ for when missing, on a terminal; --tag and --yes and --force work as below):
105
+ --factory Write the Factory blueprint instead of the flows: the
106
+ Callers, the factory config, the risk rules, CODEOWNERS
107
+ lines, a ruleset JSON and the Kit-owned bundle.
108
+ --engine <e> workflow (default) or orchestrate (no Callers, no bundle,
109
+ nothing for the App; the steps printed name the PAT and
110
+ the host recipe, docs/factory/host.md).
111
+ --codeowners <owners> Who approves changes to the Guarded paths (@login or
112
+ @org/team, comma-separated).
113
+ --ci-checks <names> Your CI's check names, which the ruleset requires
114
+ (comma-separated; never a factory/* context).
53
115
 
54
116
  Options for init (each one is asked for when missing, on a terminal):
55
117
  --tag <vX> The Agent-kit tag to adopt.
@@ -62,44 +124,70 @@ Options for init (each one is asked for when missing, on a terminal):
62
124
  prompt, \\n separates commands.
63
125
  --preset <name|none> Inline examples/setup-presets/<name>.sh as
64
126
  setup_commands (pipeline, review-response;
65
- default none).
127
+ default none), and the sandbox_image and
128
+ setup_registries its header names into the
129
+ implement job.
130
+ --harness <name> The harness for every Stage (default claude-code);
131
+ it changes only the printed steps.
66
132
  --threat-pack-dir <d> Where the Threat pack goes (audit; default .security).
67
133
  --yes Ask nothing; every answer comes from flags.
68
134
  --force Overwrite existing Callers, Threat pack files and
69
135
  Kit-owned paths (use upgrade to change tags).
70
136
 
71
137
  Options for deep-scan:
138
+ --harness <name> The harness that scans: claude-code, codex, gemini,
139
+ antigravity, opencode or custom:<name>
140
+ (default: AGENT_KIT_DEEP_SCAN_HARNESS, then
141
+ AGENT_KIT_HARNESS, then claude-code). The run
142
+ names it and its Support Level.
72
143
  --recipe <path> The Scan recipe, relative to the repository root
73
144
  (default .security/scan-recipe.yml).
74
145
  --default-branch <b> The branch whose tip the recipe is read from
75
146
  (default: origin's HEAD, else main).
76
147
  --credential <kind> The model credential's kind: api-key (default),
77
- an Anthropic API key, or subscription, a Claude
78
- subscription token from claude setup-token, an
79
- opt-in at your own risk: it relies on
148
+ the harness's own (Anthropic's for Claude Code,
149
+ OpenAI's for Codex CLI, Gemini's for Gemini CLI and
150
+ Antigravity CLI, the model's provider's for
151
+ opencode),
152
+ or, on Claude Code alone,
153
+ subscription, a Claude subscription token from
154
+ claude setup-token, an opt-in at your own risk: it relies on
80
155
  undocumented Claude Code behaviour, has no
81
156
  refresh, and the token cap is its only spend
82
157
  lever (see docs/security-audit.md#credentials).
83
158
  --credential-from <s> Where the credential is read from: env:<NAME>
84
159
  (default env:ANTHROPIC_API_KEY, or
85
160
  env:CLAUDE_CODE_OAUTH_TOKEN with --credential
86
- subscription; op run can fill either) or an
161
+ subscription, env:OPENAI_API_KEY on Codex CLI,
162
+ env:GEMINI_API_KEY on Gemini CLI and Antigravity
163
+ CLI, or env:CURSOR_API_KEY on Cursor CLI; on opencode, the variable of its model's
164
+ provider; op run can
165
+ fill any) or an
87
166
  op:// reference, read with op read. Never the
88
167
  credential itself. It stays outside the
89
- sandbox, in the model proxy.
168
+ sandbox, in the model proxy; on Cursor CLI, which the
169
+ proxy cannot front, the key sits in the sandbox.
90
170
  --setup-minutes <n> The setup wall clock: image to agent step
91
171
  (default 20).
92
172
  --scan-minutes <n> The scan wall clock: the agent step (default 60).
93
- --max-turns <n> Claude Code's turn limit (default 200).
173
+ --max-turns <n> Claude Code's or Gemini CLI's turn limit (default
174
+ 200). Codex CLI, Antigravity CLI and opencode have
175
+ none, and ignore it.
94
176
  --max-tokens <n> The model proxy's token cap for the run, counting
95
177
  input, output and cache tokens (default 5000000).
96
178
  A limit that fires stops the run, copies out its
97
179
  report with a Stopped: line, and exits 3.
98
- --model <id> The Claude model the agent runs on, a plain id
99
- such as claude-opus-5-5 (default: Claude Code's).
100
- --effort <level> The effort level Claude Code runs at: low,
101
- medium, high, xhigh or max (default: Claude
102
- Code's). The Agent step line names the model
180
+ --model <id> The model the agent runs on, a plain id in the
181
+ harness's own words, such as claude-opus-5-5
182
+ (default: the harness's). On opencode it is
183
+ provider/model, with the provider anthropic,
184
+ openai or google.
185
+ --effort <level> The effort level the harness runs at: low,
186
+ medium, high, xhigh or max, and ultra on Codex
187
+ CLI; Gemini CLI, Cursor CLI and opencode have no effort setting,
188
+ and each Antigravity CLI model takes only some
189
+ (default: the harness's). The Agent step line
190
+ names the model
103
191
  and effort asked for, and the Model proxy line
104
192
  the model the API answered with.
105
193
  --report <path> Write the report to this new file, in a folder
@@ -125,12 +213,143 @@ Options for deep-scan:
125
213
  scan is below tried, to record the evidence that
126
214
  raises it (a Proving run, marked in the output
127
215
  and the run summary). Without it such a run is
128
- refused. It relaxes nothing else, and the
129
- reusable workflows never pass it.
216
+ refused. It relaxes nothing else. No Caller input
217
+ sets it, and the Deep scan workflow never passes it.
130
218
  In GitHub Actions (GITHUB_ACTIONS=true) deep-scan keeps the Public-log
131
- rule: it prints nothing the scan shaped (Claude Code's error output, the
219
+ rule: it prints nothing the scan shaped (the harness's error output, the
132
220
  model proxy's refusals), since the Actions log is world-readable.
133
221
 
222
+ Options for stage audit (--harness, --credential, --credential-from,
223
+ --model, --effort, --setup-minutes, --scan-minutes, --max-turns and
224
+ --max-tokens as for deep-scan; the harness also from
225
+ AGENT_KIT_SECURITY_AUDIT_HARNESS. On Claude Code a subscription token in
226
+ CLAUDE_CODE_OAUTH_TOKEN is used before an API key. Defaults: setup 10
227
+ min, scan 30 min, 100 turns, 5000000 tokens):
228
+ --proving-run Run on a harness whose Support Level for the audit
229
+ is below tried, as a Proving run. Without it such
230
+ a run is refused. No Caller input sets it: the
231
+ audit workflow passes it only in Agent-kit's own
232
+ repository.
233
+ --brief <file> The audit's brief, as the trusted step built it.
234
+ --result <file> Write the Stage result, the report, to this new
235
+ file.
236
+ --transcript <file> Write the harness's raw event stream here
237
+ (default: a new private folder). Never read.
238
+ --error-log <file> Write the harness's error output here.
239
+ --usage <file> Write the run's usage here, as JSON with two keys:
240
+ tokens (the model proxy's count) and stopped
241
+ (turns, tokens, minutes or null). Nothing the
242
+ agent wrote. Absent on a harness the proxy cannot
243
+ front.
244
+ --trusted-ref <ref> The commit the harness's instruction files come
245
+ from (default: the checked-out one). A Custom
246
+ harness's file is read from it too (without it,
247
+ from the default branch).
248
+ --untracked Copy untracked files in too, such as a
249
+ scanner's output.
250
+ Exit codes: 0 the harness exited cleanly and left a valid result, 1
251
+ refused or failed, 2 usage error, 3 a limit stopped the run.
252
+
253
+ Options for stage plan (stage audit's, without --untracked; the harness
254
+ also from AGENT_KIT_PLAN_HARNESS. It runs on a pair at documented, with
255
+ a warning. Its result is one Markdown file that opens with "## Agent
256
+ plan", and a run a limit stopped leaves nothing to publish. Defaults:
257
+ setup 10 min, scan 20 min, 60 turns, 5000000 tokens).
258
+
259
+ Options for stage review (stage audit's, without --untracked; the
260
+ harness also from AGENT_KIT_REVIEW_HARNESS. It runs on a pair at
261
+ documented, with a warning. Its result is one JSON file, and a run a
262
+ limit stopped leaves nothing to publish. Defaults: setup 10 min, scan
263
+ 30 min, 120 turns, 10000000 tokens):
264
+ --input <file> A file the trusted step prepared, such as the
265
+ diff, copied in beside the brief. Repeat it for
266
+ each.
267
+
268
+ Options for stage implement and stage review-response (stage review's; the harness also from
269
+ AGENT_KIT_IMPLEMENT_HARNESS and AGENT_KIT_REVIEW_RESPONSE_HARNESS. It runs on a pair at documented, with a
270
+ warning. The agent commits in the sandbox; the result is a JSON title
271
+ and body for implement, and replies and Verdicts for review-response, and
272
+ a run a limit stopped leaves neither. Defaults: setup 20 min, scan 60 min,
273
+ 200 turns (review-response: 150), 40000000 tokens):
274
+ --bundle <file> Where the git bundle of the agent's commits goes.
275
+ Nothing is pushed.
276
+ --sandbox-image <ref> The image the harness is layered on (default: the
277
+ kit's Harness image). A tag is accepted and the
278
+ digest it resolves to printed. It needs glibc
279
+ Linux, git and bash.
280
+ --setup-commands <file> Commands run in the sandbox before the network cut.
281
+ --setup-registries <hosts>
282
+ The hosts those commands may reach, separated by
283
+ spaces, commas or lines (default: none, so no
284
+ network).
285
+ --setup-paths <paths> Absolute paths outside the workspace that setup
286
+ may change and the agent's container takes, one
287
+ per line (default: none). Setup runs in a
288
+ container of its own; only the workspace, these
289
+ paths and .git/ from the trusted commit reach the
290
+ agent's. Harness, git, shell and system locations
291
+ are refused.
292
+ --verify-commands <file>
293
+ The verify run, with no agent: it runs the setup
294
+ commands, cuts the network, then runs these on the
295
+ checked-out commit. It takes --harness, the sandbox
296
+ and setup flags, --setup-minutes (default 20) and
297
+ --scan-minutes (default 30, the commands' limit)
298
+ alone. Exit 0 when they pass.
299
+
300
+ Options for harness test:
301
+ --trusted-ref <ref> The commit to read the Custom harness file from
302
+ (default: the default branch's tip, as this
303
+ checkout has it).
304
+ --default-branch <name> The default branch, where origin's HEAD does not
305
+ name it.
306
+ Exit codes: 0 every Guard held in every scenario, 1 refused or failed, 2
307
+ usage error.
308
+
309
+ Options for factory setup (needs a terminal and an admin gh login; refuses in CI;
310
+ asks before each write; safe to run again; never sets the Kill switch):
311
+ --repo <o/r> The repository to set up (default: gh's choice for the
312
+ current directory).
313
+ --engine <e> workflow (default: labels, the pinned control issue, the
314
+ GitHub App and its key, the ruleset) or orchestrate (labels,
315
+ control issue and ruleset; no App; prints the PAT's steps:
316
+ one repository, Contents, Issues, Pull requests and Statuses
317
+ write, Variables read).
318
+
319
+ Options for factory sweep:
320
+ --repo <o/r> The repository to sweep (default: GITHUB_REPOSITORY, else
321
+ gh's choice for the current directory).
322
+ --dry-run Read the tracker and print the actions, write nothing.
323
+ Exit codes: 0 swept or drained, 1 an action failed, 2 usage error.
324
+
325
+ Options for factory run (the Orchestrate engine, preview; one engine per repository):
326
+ --repo <o/r> The repository to run (default: GITHUB_REPOSITORY, else gh's
327
+ choice for the current directory).
328
+ --once Run one sweep, wait for the Stages it started, and exit.
329
+ --drain <dur> How long a first Ctrl-C lets running Stages finish before it
330
+ cancels them (default 10m; 90s, 10m, 2h). A second Ctrl-C
331
+ stops at once.
332
+ --poll <dur> The time between sweeps (default 60s, at least 30s).
333
+ --upload-raw Also upload each run folder to the S3 raw-folder Sink, once its
334
+ bucket's lifecycle expires raw/ (never the security Stage).
335
+ Without it nothing raw leaves the machine.
336
+ Exit codes: 0 drained or swept, 1 refused (token, lease, lock) or the lease lost
337
+ during the run, 2 usage error or a missing secret, 130 stopped at once.
338
+
339
+ Options for factory stop (cancels workflow runs only; needs a gh login with
340
+ actions write):
341
+ --repo <o/r> The repository to stop (default: GITHUB_REPOSITORY, else
342
+ gh's choice for the current directory).
343
+ Exit codes: 0 stopped (or nothing running), 1 a cancel failed, 2 usage error.
344
+
345
+ Options for factory report (reads only; never posts):
346
+ --repo <o/r> The repository to report on (default: GITHUB_REPOSITORY, else
347
+ gh's choice for the current directory).
348
+ --since <Nd> The window of tasks that reached a terminal state (default 30d).
349
+ --json Print the stable factory-report/1 JSON instead of text.
350
+ --gate Add the shadow-to-on bar per tier, from the merge gate's comments.
351
+ Exit codes: 0 reported, 1 a read failed, 2 usage error.
352
+
134
353
  Options for upgrade:
135
354
  --tag <vY> The Agent-kit tag to move to (asked for when missing).
136
355
  --from <vX> The tag you are leaving, when the pins already name <vY>
@@ -145,6 +364,19 @@ Options for upgrade:
145
364
 
146
365
  const COMMAND_OPTIONS = {
147
366
  doctor: ["ci", "strict", "repo"],
367
+ factory: [
368
+ "repo",
369
+ "dry-run",
370
+ "engine",
371
+ "since",
372
+ "json",
373
+ "gate",
374
+ "once",
375
+ "drain",
376
+ "poll",
377
+ "upload-raw",
378
+ ],
379
+ harness: ["trusted-ref", "default-branch"],
148
380
  init: [
149
381
  "tag",
150
382
  "flows",
@@ -152,12 +384,18 @@ const COMMAND_OPTIONS = {
152
384
  "default-branch",
153
385
  "verify",
154
386
  "preset",
387
+ "harness",
155
388
  "threat-pack-dir",
156
389
  "yes",
157
390
  "force",
391
+ "factory",
392
+ "engine",
393
+ "codeowners",
394
+ "ci-checks",
158
395
  ],
159
396
  upgrade: ["tag", "from", "yes", "force"],
160
397
  "deep-scan": [
398
+ "harness",
161
399
  "recipe",
162
400
  "default-branch",
163
401
  "credential",
@@ -173,6 +411,32 @@ const COMMAND_OPTIONS = {
173
411
  "ref",
174
412
  "proving-run",
175
413
  ],
414
+ stage: [
415
+ "harness",
416
+ "credential",
417
+ "credential-from",
418
+ "setup-minutes",
419
+ "scan-minutes",
420
+ "max-turns",
421
+ "max-tokens",
422
+ "model",
423
+ "effort",
424
+ "proving-run",
425
+ "brief",
426
+ "result",
427
+ "bundle",
428
+ "transcript",
429
+ "error-log",
430
+ "usage",
431
+ "trusted-ref",
432
+ "untracked",
433
+ "input",
434
+ "sandbox-image",
435
+ "setup-registries",
436
+ "setup-commands",
437
+ "setup-paths",
438
+ "verify-commands",
439
+ ],
176
440
  };
177
441
 
178
442
  /**
@@ -218,6 +482,18 @@ export async function main(argv, io) {
218
482
  ci: { type: "boolean" },
219
483
  strict: { type: "boolean" },
220
484
  repo: { type: "string" },
485
+ "dry-run": { type: "boolean" },
486
+ since: { type: "string" },
487
+ json: { type: "boolean" },
488
+ gate: { type: "boolean" },
489
+ once: { type: "boolean" },
490
+ drain: { type: "string" },
491
+ poll: { type: "string" },
492
+ "upload-raw": { type: "boolean" },
493
+ factory: { type: "boolean" },
494
+ engine: { type: "string" },
495
+ codeowners: { type: "string" },
496
+ "ci-checks": { type: "string" },
221
497
  tag: { type: "string" },
222
498
  from: { type: "string" },
223
499
  flows: { type: "string" },
@@ -226,6 +502,7 @@ export async function main(argv, io) {
226
502
  verify: { type: "string" },
227
503
  preset: { type: "string" },
228
504
  "threat-pack-dir": { type: "string" },
505
+ harness: { type: "string" },
229
506
  recipe: { type: "string" },
230
507
  credential: { type: "string" },
231
508
  "credential-from": { type: "string" },
@@ -238,6 +515,20 @@ export async function main(argv, io) {
238
515
  report: { type: "string" },
239
516
  ref: { type: "string" },
240
517
  "proving-run": { type: "boolean" },
518
+ brief: { type: "string" },
519
+ result: { type: "string" },
520
+ bundle: { type: "string" },
521
+ transcript: { type: "string" },
522
+ "error-log": { type: "string" },
523
+ usage: { type: "string" },
524
+ "trusted-ref": { type: "string" },
525
+ untracked: { type: "boolean" },
526
+ input: { type: "string", multiple: true },
527
+ "sandbox-image": { type: "string" },
528
+ "setup-registries": { type: "string" },
529
+ "setup-commands": { type: "string" },
530
+ "setup-paths": { type: "string" },
531
+ "verify-commands": { type: "string" },
241
532
  yes: { type: "boolean", short: "y" },
242
533
  force: { type: "boolean" },
243
534
  help: { type: "boolean", short: "h" },
@@ -262,7 +553,44 @@ export async function main(argv, io) {
262
553
  stderr(`Unknown command: ${command}\n\n${USAGE}`);
263
554
  return 2;
264
555
  }
265
- if (rest.length) {
556
+ // `stage` takes its Stage's name; no other command takes an argument.
557
+ if (command === "stage") {
558
+ const names = Object.keys(STAGE_COMMANDS).join(", ");
559
+ if (!rest.length) {
560
+ stderr(`stage needs a Stage name: ${names}`);
561
+ return 2;
562
+ }
563
+ if (rest.length > 1) {
564
+ stderr(`stage takes one Stage, got: ${rest.join(" ")}`);
565
+ return 2;
566
+ }
567
+ } else if (command === "factory") {
568
+ if (rest.length !== 1 || !["sweep", "setup", "report", "stop", "run"].includes(rest[0])) {
569
+ stderr(
570
+ "factory takes `sweep`, `setup`, `report`, `stop` or `run`, as in: agent-kit factory setup",
571
+ );
572
+ return 2;
573
+ }
574
+ const runOnly =
575
+ rest[0] === "run"
576
+ ? []
577
+ : ["once", "drain", "poll", "upload-raw"].filter((k) => values[k] !== undefined);
578
+ if (runOnly.length) {
579
+ stderr(`factory ${rest[0]} does not take ${runOnly.map((k) => `--${k}`).join(", ")}`);
580
+ return 2;
581
+ }
582
+ const own =
583
+ rest[0] === "report" ? [] : ["since", "json", "gate"].filter((k) => values[k] !== undefined);
584
+ if (own.length) {
585
+ stderr(`factory ${rest[0]} does not take ${own.map((k) => `--${k}`).join(", ")}`);
586
+ return 2;
587
+ }
588
+ } else if (command === "harness") {
589
+ if (rest.length !== 2 || rest[0] !== "test") {
590
+ stderr("harness takes `test custom:<name>`, as in: agent-kit harness test custom:mine");
591
+ return 2;
592
+ }
593
+ } else if (rest.length) {
266
594
  stderr(`${command} takes no arguments, got: ${rest.join(" ")}`);
267
595
  return 2;
268
596
  }
@@ -275,14 +603,48 @@ export async function main(argv, io) {
275
603
  }
276
604
  const runner =
277
605
  io.runner ??
278
- runnerFor(command, {
279
- ...(io.spawn ? { spawn: io.spawn } : {}),
280
- ...(io.spawnAsync ? { spawnAsync: io.spawnAsync } : {}),
281
- });
606
+ // `stage` and `harness test` run in the Deep scan's sandbox, on the same
607
+ // commands.
608
+ // `factory sweep` reaches only `git` and `gh`, on `doctor`'s allowlist.
609
+ runnerFor(
610
+ command === "stage" || command === "harness"
611
+ ? "deep-scan"
612
+ : command === "factory"
613
+ ? rest[0] === "run"
614
+ ? "factory-run"
615
+ : "doctor"
616
+ : command,
617
+ {
618
+ ...(io.spawn ? { spawn: io.spawn } : {}),
619
+ ...(io.spawnAsync ? { spawnAsync: io.spawnAsync } : {}),
620
+ },
621
+ );
282
622
 
283
623
  if (command === "init") {
284
624
  stdout(`agent-kit init ${VERSION}`);
625
+ const factoryOnly = ["engine", "codeowners", "ci-checks"].filter(
626
+ (k) => values[k] !== undefined,
627
+ );
628
+ if (!values.factory && factoryOnly.length) {
629
+ stderr(`${factoryOnly.map((k) => `--${k}`).join(", ")} only go with init --factory`);
630
+ return 2;
631
+ }
632
+ const flowFlags = ["flows", "actors", "verify", "preset", "harness", "threat-pack-dir"].filter(
633
+ (k) => values[k] !== undefined,
634
+ );
635
+ if (values.factory && flowFlags.length) {
636
+ stderr(`init --factory does not take ${flowFlags.map((k) => `--${k}`).join(", ")}`);
637
+ return 2;
638
+ }
285
639
  return runInit({
640
+ ...(values.factory
641
+ ? {
642
+ factory: {
643
+ engine: values.engine ?? "workflow",
644
+ flags: { codeowners: values.codeowners, ciChecks: values["ci-checks"] },
645
+ },
646
+ }
647
+ : {}),
286
648
  cwd,
287
649
  runner,
288
650
  flags: {
@@ -292,6 +654,7 @@ export async function main(argv, io) {
292
654
  defaultBranch: values["default-branch"],
293
655
  verify: values.verify,
294
656
  preset: values.preset,
657
+ harness: values.harness,
295
658
  threatPackDir: values["threat-pack-dir"],
296
659
  },
297
660
  force: Boolean(values.force),
@@ -308,6 +671,7 @@ export async function main(argv, io) {
308
671
  return runDeepScan({
309
672
  cwd,
310
673
  runner,
674
+ harness: values.harness,
311
675
  recipePath: values.recipe,
312
676
  defaultBranch: values["default-branch"],
313
677
  credential: values.credential,
@@ -318,19 +682,186 @@ export async function main(argv, io) {
318
682
  verifyPath: values.verify,
319
683
  ref: values.ref,
320
684
  provingRun: Boolean(values["proving-run"]),
321
- limitFlags: {
322
- "setup-minutes": values["setup-minutes"],
323
- "scan-minutes": values["scan-minutes"],
324
- "max-turns": values["max-turns"],
325
- "max-tokens": values["max-tokens"],
326
- },
327
- ...(io.platform !== undefined ? { platform: io.platform } : {}),
328
- ...(io.env !== undefined ? { env: io.env } : {}),
685
+ limitFlags: limitFlagsOf(values),
686
+ ...hostOf(io),
329
687
  ...(io.fetch !== undefined ? { fetch: io.fetch } : {}),
330
- ...(io.signals !== undefined ? { signals: io.signals } : {}),
331
688
  ...(io.reportDir !== undefined ? { reportDir: io.reportDir } : {}),
332
- ...(io.modelApi !== undefined ? { modelApi: io.modelApi } : {}),
333
- ...(io.timers !== undefined ? { timers: io.timers } : {}),
689
+ out: stdout,
690
+ err: stderr,
691
+ });
692
+ }
693
+ if (command === "stage") {
694
+ stdout(`agent-kit stage ${VERSION}`);
695
+ return runStage({
696
+ cwd,
697
+ runner,
698
+ stage: rest[0],
699
+ harness: values.harness,
700
+ model: values.model,
701
+ effort: values.effort,
702
+ credential: values.credential,
703
+ credentialFrom: values["credential-from"],
704
+ briefPath: values.brief,
705
+ resultPath: values.result,
706
+ bundlePath: values.bundle,
707
+ transcriptPath: values.transcript,
708
+ errorLogPath: values["error-log"],
709
+ usagePath: values.usage,
710
+ trustedRef: values["trusted-ref"],
711
+ untracked: Boolean(values.untracked),
712
+ inputPaths: values.input,
713
+ sandboxImage: values["sandbox-image"],
714
+ setupRegistries: values["setup-registries"],
715
+ setupPath: values["setup-commands"],
716
+ setupPaths: values["setup-paths"],
717
+ verifyPath: values["verify-commands"],
718
+ provingRun: Boolean(values["proving-run"]),
719
+ limitFlags: limitFlagsOf(values),
720
+ ...hostOf(io),
721
+ out: stdout,
722
+ err: stderr,
723
+ });
724
+ }
725
+ if (command === "harness") {
726
+ stdout(`agent-kit harness test ${VERSION}`);
727
+ return runHarnessTest({
728
+ cwd,
729
+ runner,
730
+ harness: rest[1],
731
+ trustedRef: values["trusted-ref"],
732
+ defaultBranch: values["default-branch"],
733
+ ...hostOf(io),
734
+ ...(io.scenarioRunner !== undefined ? { scenarioRunner: io.scenarioRunner } : {}),
735
+ out: stdout,
736
+ err: stderr,
737
+ });
738
+ }
739
+ if (command === "factory" && rest[0] === "run") {
740
+ const unfit = ["dry-run", "engine", "since", "json", "gate"].filter(
741
+ (k) => values[k] !== undefined,
742
+ );
743
+ if (unfit.length) {
744
+ stderr(`factory run does not take ${unfit.map((k) => `--${k}`).join(", ")}`);
745
+ return 2;
746
+ }
747
+ if (values.repo !== undefined && !REPO_PATTERN.test(values.repo)) {
748
+ stderr(`--repo must be owner/name, got: ${JSON.stringify(values.repo)}`);
749
+ return 2;
750
+ }
751
+ const drainMs = values.drain === undefined ? undefined : parseDuration(values.drain);
752
+ const pollMs = values.poll === undefined ? undefined : parseDuration(values.poll);
753
+ if (drainMs === null || pollMs === null) {
754
+ stderr(`${drainMs === null ? "--drain" : "--poll"} is a duration such as 90s, 10m or 2h`);
755
+ return 2;
756
+ }
757
+ stdout(`agent-kit factory run ${VERSION}`);
758
+ return runFactoryRun({
759
+ runner,
760
+ env: io.env ?? process.env,
761
+ repo: values.repo,
762
+ once: Boolean(values.once),
763
+ uploadRaw: Boolean(values["upload-raw"]),
764
+ cwd,
765
+ ...(drainMs === undefined ? {} : { drainMs }),
766
+ ...(pollMs === undefined ? {} : { pollMs }),
767
+ ...(io.clock ? { clock: io.clock } : {}),
768
+ ...(io.nonce ? { nonce: io.nonce } : {}),
769
+ ...(io.signals ? { signals: io.signals } : {}),
770
+ ...(io.platform ? { platform: io.platform } : {}),
771
+ ...(io.engineHost ?? {}),
772
+ out: stdout,
773
+ err: stderr,
774
+ });
775
+ }
776
+ if (command === "factory" && rest[0] === "report") {
777
+ const unfit = ["dry-run", "engine"].filter((k) => values[k] !== undefined);
778
+ if (unfit.length) {
779
+ stderr(`factory report does not take ${unfit.map((k) => `--${k}`).join(", ")}`);
780
+ return 2;
781
+ }
782
+ if (values.repo !== undefined && !REPO_PATTERN.test(values.repo)) {
783
+ stderr(`--repo must be owner/name, got: ${JSON.stringify(values.repo)}`);
784
+ return 2;
785
+ }
786
+ return runFactoryReport({
787
+ runner,
788
+ env: io.env ?? process.env,
789
+ repo: values.repo,
790
+ since: values.since,
791
+ json: Boolean(values.json),
792
+ gate: Boolean(values.gate),
793
+ ...(io.clock ? { clock: io.clock } : {}),
794
+ out: stdout,
795
+ err: stderr,
796
+ });
797
+ }
798
+ if (command === "factory" && rest[0] === "stop") {
799
+ const unfit = ["dry-run", "engine"].filter((k) => values[k] !== undefined);
800
+ if (unfit.length) {
801
+ stderr(`factory stop does not take ${unfit.map((k) => `--${k}`).join(", ")}`);
802
+ return 2;
803
+ }
804
+ if (values.repo !== undefined && !REPO_PATTERN.test(values.repo)) {
805
+ stderr(`--repo must be owner/name, got: ${JSON.stringify(values.repo)}`);
806
+ return 2;
807
+ }
808
+ stdout(`agent-kit factory stop ${VERSION}`);
809
+ return runFactoryStop({
810
+ gh: (args) => runner("gh", args),
811
+ env: io.env ?? process.env,
812
+ repo: values.repo,
813
+ local: io.localEngine ?? {
814
+ holder: (slug) =>
815
+ readLock({
816
+ dir: stateDirOf(homedir(), slug),
817
+ fs: { readFileSync },
818
+ }),
819
+ host: hostname(),
820
+ kill: (pid) => process.kill(pid, "SIGTERM"),
821
+ },
822
+ out: stdout,
823
+ err: stderr,
824
+ });
825
+ }
826
+ if (command === "factory" && rest[0] === "setup") {
827
+ stdout(`agent-kit factory setup ${VERSION}`);
828
+ if (values["dry-run"]) {
829
+ stderr("factory setup does not take --dry-run");
830
+ return 2;
831
+ }
832
+ if (values.repo !== undefined && !REPO_PATTERN.test(values.repo)) {
833
+ stderr(`--repo must be owner/name, got: ${JSON.stringify(values.repo)}`);
834
+ return 2;
835
+ }
836
+ return runFactorySetup({
837
+ runner,
838
+ env: io.env ?? process.env,
839
+ repo: values.repo,
840
+ engine: values.engine ?? "workflow",
841
+ cwd,
842
+ prompt,
843
+ ...(io.appFlow ? { appFlow: io.appFlow } : {}),
844
+ out: stdout,
845
+ err: stderr,
846
+ });
847
+ }
848
+ if (command === "factory") {
849
+ if (values.engine !== undefined) {
850
+ stderr("factory sweep does not take --engine");
851
+ return 2;
852
+ }
853
+ stdout(`agent-kit factory sweep ${VERSION}`);
854
+ if (values.repo !== undefined && !REPO_PATTERN.test(values.repo)) {
855
+ stderr(`--repo must be owner/name, got: ${JSON.stringify(values.repo)}`);
856
+ return 2;
857
+ }
858
+ return runFactorySweep({
859
+ runner,
860
+ env: io.env ?? process.env,
861
+ repo: values.repo,
862
+ dryRun: Boolean(values["dry-run"]),
863
+ ...(io.clock ? { clock: io.clock } : {}),
864
+ ...(io.nonce ? { nonce: io.nonce } : {}),
334
865
  out: stdout,
335
866
  err: stderr,
336
867
  });
@@ -355,6 +886,22 @@ export async function main(argv, io) {
355
886
  return report.exitCode;
356
887
  }
357
888
 
889
+ /** The limit flags' values, keyed by flag name. */
890
+ const limitFlagsOf = (values) => ({
891
+ "setup-minutes": values["setup-minutes"],
892
+ "scan-minutes": values["scan-minutes"],
893
+ "max-turns": values["max-turns"],
894
+ "max-tokens": values["max-tokens"],
895
+ });
896
+
897
+ /** The host's seams `deep-scan` and `stage` share, where `io` replaces them. */
898
+ const hostOf = (io) =>
899
+ Object.fromEntries(
900
+ ["platform", "env", "signals", "modelApi", "timers"]
901
+ .filter((name) => io[name] !== undefined)
902
+ .map((name) => [name, io[name]]),
903
+ );
904
+
358
905
  async function upgrade(values, { cwd, runner, openRepo, prompt, stdout, stderr }) {
359
906
  if (!prompt) {
360
907
  // No terminal: every answer must come from a flag.