@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.
- package/README.md +22 -4
- package/custom-harness.schema.json +243 -0
- package/harnesses.json +244 -6
- package/package.json +3 -2
- package/src/checks/ci-workflow.mjs +105 -0
- package/src/checks/claude-app.mjs +11 -2
- package/src/checks/custom-harness.mjs +157 -0
- package/src/checks/github-app.mjs +214 -0
- package/src/checks/rulesets.mjs +9 -8
- package/src/checks/secrets-and-variables.mjs +27 -8
- package/src/checks/stages.mjs +705 -0
- package/src/cli.mjs +270 -33
- package/src/deep-scan/agent.mjs +88 -21
- package/src/deep-scan/credential.mjs +81 -32
- package/src/deep-scan/docker-driver.mjs +105 -42
- package/src/deep-scan/harness-text.mjs +99 -0
- package/src/deep-scan/lifecycle.mjs +68 -178
- package/src/deep-scan/limits.mjs +13 -7
- package/src/deep-scan/model-proxy.mjs +21 -10
- package/src/deep-scan/preflight.mjs +19 -6
- package/src/deep-scan/recipe.mjs +4 -0
- package/src/deep-scan/runtime.mjs +54 -6
- package/src/deep-scan/sandbox-run.mjs +232 -0
- package/src/deep-scan/sbx-driver.mjs +224 -39
- package/src/deep-scan/tar.mjs +69 -22
- package/src/deep-scan/verify.mjs +6 -1
- package/src/deep-scan.mjs +73 -13
- package/src/doctor.mjs +113 -4
- package/src/harness/adapters.mjs +30 -0
- package/src/harness/antigravity.mjs +187 -0
- package/src/harness/claude-code.mjs +8 -1
- package/src/harness/codex.mjs +219 -0
- package/src/harness/cursor.mjs +199 -0
- package/src/harness/custom/registry.mjs +21 -0
- package/src/harness/custom/schema.mjs +90 -0
- package/src/harness/custom.mjs +299 -0
- package/src/harness/facts.mjs +44 -7
- package/src/harness/gemini.mjs +164 -0
- package/src/harness/install-layer.mjs +86 -3
- package/src/harness/opencode.mjs +289 -0
- package/src/harness/resolve.mjs +156 -0
- package/src/harness/support-levels.mjs +151 -3
- package/src/harness-live/assess.mjs +29 -6
- package/src/harness-live/cursor-real.mjs +146 -0
- package/src/harness-live/cursor-version.mjs +70 -0
- package/src/harness-live/cursor.mjs +80 -0
- package/src/harness-live/custom.mjs +91 -0
- package/src/harness-live/fixture-harness.mjs +45 -0
- package/src/harness-live/harnesses.mjs +263 -0
- package/src/harness-live/host.mjs +113 -4
- package/src/harness-live/opencode.mjs +289 -0
- package/src/harness-live/probes.mjs +87 -7
- package/src/harness-live/run.mjs +101 -20
- package/src/harness-live/setup.mjs +126 -0
- package/src/harness-live/stage.mjs +25 -15
- package/src/harness-live/suite.mjs +276 -95
- package/src/harness-test.mjs +116 -0
- package/src/init.mjs +313 -13
- package/src/model-proxy/core.mjs +128 -20
- package/src/model-proxy/profiles/anthropic.mjs +54 -10
- package/src/model-proxy/profiles/gemini-api.mjs +311 -0
- package/src/model-proxy/profiles/openai.mjs +327 -0
- package/src/model-proxy/stub-dialects/gemini-api.mjs +178 -0
- package/src/model-proxy/stub-dialects/openai.mjs +173 -0
- package/src/model-proxy/stub.mjs +9 -1
- package/src/stage/audit.mjs +79 -0
- package/src/stage/egress-route.mjs +207 -0
- package/src/stage/implement/carry.mjs +308 -0
- package/src/stage/implement/sandbox.mjs +271 -0
- package/src/stage/implement/verify.mjs +70 -0
- package/src/stage/implement.mjs +218 -0
- package/src/stage/plan.mjs +115 -0
- package/src/stage/review-response.mjs +172 -0
- package/src/stage/review.mjs +185 -0
- package/src/stage/workspace.mjs +274 -0
- package/src/stage.mjs +1068 -0
package/src/cli.mjs
CHANGED
|
@@ -1,18 +1,21 @@
|
|
|
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,
|
|
4
|
-
// answer when there is no terminal to ask on), 3 a
|
|
5
|
-
// the run (after copying out any report and
|
|
6
|
-
// or 143
|
|
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
|
|
|
8
9
|
import { parseArgs } from "node:util";
|
|
9
10
|
import { runDeepScan } from "./deep-scan.mjs";
|
|
10
11
|
import { formatReport, runDoctor } from "./doctor.mjs";
|
|
12
|
+
import { runHarnessTest } from "./harness-test.mjs";
|
|
11
13
|
import { REPO_PATTERN, sanitizeLine } from "./checks/result.mjs";
|
|
12
14
|
import { runnerFor } from "./exec.mjs";
|
|
13
15
|
import { askYesNo } from "./prompt.mjs";
|
|
14
16
|
import { CLI_VERSION, isReleaseTag } from "./tags.mjs";
|
|
15
17
|
import { runInit } from "./init.mjs";
|
|
18
|
+
import { runStage, STAGE_COMMANDS } from "./stage.mjs";
|
|
16
19
|
import { runUpgrade } from "./upgrade.mjs";
|
|
17
20
|
|
|
18
21
|
export const VERSION = CLI_VERSION;
|
|
@@ -37,12 +40,24 @@ Commands:
|
|
|
37
40
|
chooses a sandbox runtime from the host or refuses (no
|
|
38
41
|
override), then runs the sandbox: image, copy-in of the
|
|
39
42
|
default branch's tip, setup with egress only to the recipe's
|
|
40
|
-
registries, network cut, the real
|
|
43
|
+
registries, network cut, the real harness behind a
|
|
41
44
|
key-injecting model proxy on this machine (its only route
|
|
42
45
|
out), copy-out of the report only, and teardown. Every run
|
|
43
46
|
is bounded by wall clocks, a turn limit and a token cap.
|
|
44
47
|
With --verify <file> --ref <ref>, a local-only
|
|
45
48
|
Verification run: does a fix hold for known findings?
|
|
49
|
+
stage Run one CI Stage in the same sandbox, as the reusable
|
|
50
|
+
workflows do: stage audit, the static security audit, stage
|
|
51
|
+
plan, the plan of an issue, stage review, the pull request
|
|
52
|
+
review, stage implement, the implementer, or stage
|
|
53
|
+
review-response, the Review responder. Copies the
|
|
54
|
+
checked-out commit in, hands the harness the brief it is
|
|
55
|
+
given, and writes the Stage result and the raw transcript to
|
|
56
|
+
private files. Writes nothing to GitHub.
|
|
57
|
+
harness harness test custom:<name>: run the live probe suite on your
|
|
58
|
+
own Custom harness file, against a stub model, in the real
|
|
59
|
+
sandbox under gVisor. The first half of a Proving run. It needs
|
|
60
|
+
no model credential.
|
|
46
61
|
|
|
47
62
|
Options for doctor:
|
|
48
63
|
--ci Check only Kit-owned paths and uses: pins (no gh needed).
|
|
@@ -62,44 +77,70 @@ Options for init (each one is asked for when missing, on a terminal):
|
|
|
62
77
|
prompt, \\n separates commands.
|
|
63
78
|
--preset <name|none> Inline examples/setup-presets/<name>.sh as
|
|
64
79
|
setup_commands (pipeline, review-response;
|
|
65
|
-
default none)
|
|
80
|
+
default none), and the sandbox_image and
|
|
81
|
+
setup_registries its header names into the
|
|
82
|
+
implement job.
|
|
83
|
+
--harness <name> The harness for every Stage (default claude-code);
|
|
84
|
+
it changes only the printed steps.
|
|
66
85
|
--threat-pack-dir <d> Where the Threat pack goes (audit; default .security).
|
|
67
86
|
--yes Ask nothing; every answer comes from flags.
|
|
68
87
|
--force Overwrite existing Callers, Threat pack files and
|
|
69
88
|
Kit-owned paths (use upgrade to change tags).
|
|
70
89
|
|
|
71
90
|
Options for deep-scan:
|
|
91
|
+
--harness <name> The harness that scans: claude-code, codex, gemini,
|
|
92
|
+
antigravity, opencode or custom:<name>
|
|
93
|
+
(default: AGENT_KIT_DEEP_SCAN_HARNESS, then
|
|
94
|
+
AGENT_KIT_HARNESS, then claude-code). The run
|
|
95
|
+
names it and its Support Level.
|
|
72
96
|
--recipe <path> The Scan recipe, relative to the repository root
|
|
73
97
|
(default .security/scan-recipe.yml).
|
|
74
98
|
--default-branch <b> The branch whose tip the recipe is read from
|
|
75
99
|
(default: origin's HEAD, else main).
|
|
76
100
|
--credential <kind> The model credential's kind: api-key (default),
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
101
|
+
the harness's own (Anthropic's for Claude Code,
|
|
102
|
+
OpenAI's for Codex CLI, Gemini's for Gemini CLI and
|
|
103
|
+
Antigravity CLI, the model's provider's for
|
|
104
|
+
opencode),
|
|
105
|
+
or, on Claude Code alone,
|
|
106
|
+
subscription, a Claude subscription token from
|
|
107
|
+
claude setup-token, an opt-in at your own risk: it relies on
|
|
80
108
|
undocumented Claude Code behaviour, has no
|
|
81
109
|
refresh, and the token cap is its only spend
|
|
82
110
|
lever (see docs/security-audit.md#credentials).
|
|
83
111
|
--credential-from <s> Where the credential is read from: env:<NAME>
|
|
84
112
|
(default env:ANTHROPIC_API_KEY, or
|
|
85
113
|
env:CLAUDE_CODE_OAUTH_TOKEN with --credential
|
|
86
|
-
subscription
|
|
114
|
+
subscription, env:OPENAI_API_KEY on Codex CLI,
|
|
115
|
+
env:GEMINI_API_KEY on Gemini CLI and Antigravity
|
|
116
|
+
CLI, or env:CURSOR_API_KEY on Cursor CLI; on opencode, the variable of its model's
|
|
117
|
+
provider; op run can
|
|
118
|
+
fill any) or an
|
|
87
119
|
op:// reference, read with op read. Never the
|
|
88
120
|
credential itself. It stays outside the
|
|
89
|
-
sandbox, in the model proxy
|
|
121
|
+
sandbox, in the model proxy; on Cursor CLI, which the
|
|
122
|
+
proxy cannot front, the key sits in the sandbox.
|
|
90
123
|
--setup-minutes <n> The setup wall clock: image to agent step
|
|
91
124
|
(default 20).
|
|
92
125
|
--scan-minutes <n> The scan wall clock: the agent step (default 60).
|
|
93
|
-
--max-turns <n> Claude Code's turn limit (default
|
|
126
|
+
--max-turns <n> Claude Code's or Gemini CLI's turn limit (default
|
|
127
|
+
200). Codex CLI, Antigravity CLI and opencode have
|
|
128
|
+
none, and ignore it.
|
|
94
129
|
--max-tokens <n> The model proxy's token cap for the run, counting
|
|
95
130
|
input, output and cache tokens (default 5000000).
|
|
96
131
|
A limit that fires stops the run, copies out its
|
|
97
132
|
report with a Stopped: line, and exits 3.
|
|
98
|
-
--model <id> The
|
|
99
|
-
such as claude-opus-5-5
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
133
|
+
--model <id> The model the agent runs on, a plain id in the
|
|
134
|
+
harness's own words, such as claude-opus-5-5
|
|
135
|
+
(default: the harness's). On opencode it is
|
|
136
|
+
provider/model, with the provider anthropic,
|
|
137
|
+
openai or google.
|
|
138
|
+
--effort <level> The effort level the harness runs at: low,
|
|
139
|
+
medium, high, xhigh or max, and ultra on Codex
|
|
140
|
+
CLI; Gemini CLI, Cursor CLI and opencode have no effort setting,
|
|
141
|
+
and each Antigravity CLI model takes only some
|
|
142
|
+
(default: the harness's). The Agent step line
|
|
143
|
+
names the model
|
|
103
144
|
and effort asked for, and the Model proxy line
|
|
104
145
|
the model the API answered with.
|
|
105
146
|
--report <path> Write the report to this new file, in a folder
|
|
@@ -125,12 +166,94 @@ Options for deep-scan:
|
|
|
125
166
|
scan is below tried, to record the evidence that
|
|
126
167
|
raises it (a Proving run, marked in the output
|
|
127
168
|
and the run summary). Without it such a run is
|
|
128
|
-
refused. It relaxes nothing else
|
|
129
|
-
|
|
169
|
+
refused. It relaxes nothing else. No Caller input
|
|
170
|
+
sets it, and the Deep scan workflow never passes it.
|
|
130
171
|
In GitHub Actions (GITHUB_ACTIONS=true) deep-scan keeps the Public-log
|
|
131
|
-
rule: it prints nothing the scan shaped (
|
|
172
|
+
rule: it prints nothing the scan shaped (the harness's error output, the
|
|
132
173
|
model proxy's refusals), since the Actions log is world-readable.
|
|
133
174
|
|
|
175
|
+
Options for stage audit (--harness, --credential, --credential-from,
|
|
176
|
+
--model, --effort, --setup-minutes, --scan-minutes, --max-turns and
|
|
177
|
+
--max-tokens as for deep-scan; the harness also from
|
|
178
|
+
AGENT_KIT_SECURITY_AUDIT_HARNESS. On Claude Code a subscription token in
|
|
179
|
+
CLAUDE_CODE_OAUTH_TOKEN is used before an API key. Defaults: setup 10
|
|
180
|
+
min, scan 30 min, 100 turns, 5000000 tokens):
|
|
181
|
+
--proving-run Run on a harness whose Support Level for the audit
|
|
182
|
+
is below tried, as a Proving run. Without it such
|
|
183
|
+
a run is refused. No Caller input sets it: the
|
|
184
|
+
audit workflow passes it only in Agent-kit's own
|
|
185
|
+
repository.
|
|
186
|
+
--brief <file> The audit's brief, as the trusted step built it.
|
|
187
|
+
--result <file> Write the Stage result, the report, to this new
|
|
188
|
+
file.
|
|
189
|
+
--transcript <file> Write the harness's raw event stream here
|
|
190
|
+
(default: a new private folder). Never read.
|
|
191
|
+
--error-log <file> Write the harness's error output here.
|
|
192
|
+
--trusted-ref <ref> The commit the harness's instruction files come
|
|
193
|
+
from (default: the checked-out one). A Custom
|
|
194
|
+
harness's file is read from it too (without it,
|
|
195
|
+
from the default branch).
|
|
196
|
+
--untracked Copy untracked files in too, such as a
|
|
197
|
+
scanner's output.
|
|
198
|
+
Exit codes: 0 the harness exited cleanly and left a valid result, 1
|
|
199
|
+
refused or failed, 2 usage error, 3 a limit stopped the run.
|
|
200
|
+
|
|
201
|
+
Options for stage plan (stage audit's, without --untracked; the harness
|
|
202
|
+
also from AGENT_KIT_PLAN_HARNESS. It runs on a pair at documented, with
|
|
203
|
+
a warning. Its result is one Markdown file that opens with "## Agent
|
|
204
|
+
plan", and a run a limit stopped leaves nothing to publish. Defaults:
|
|
205
|
+
setup 10 min, scan 20 min, 60 turns, 5000000 tokens).
|
|
206
|
+
|
|
207
|
+
Options for stage review (stage audit's, without --untracked; the
|
|
208
|
+
harness also from AGENT_KIT_REVIEW_HARNESS. It runs on a pair at
|
|
209
|
+
documented, with a warning. Its result is one JSON file, and a run a
|
|
210
|
+
limit stopped leaves nothing to publish. Defaults: setup 10 min, scan
|
|
211
|
+
30 min, 120 turns, 10000000 tokens):
|
|
212
|
+
--input <file> A file the trusted step prepared, such as the
|
|
213
|
+
diff, copied in beside the brief. Repeat it for
|
|
214
|
+
each.
|
|
215
|
+
|
|
216
|
+
Options for stage implement and stage review-response (stage review's; the harness also from
|
|
217
|
+
AGENT_KIT_IMPLEMENT_HARNESS and AGENT_KIT_REVIEW_RESPONSE_HARNESS. It runs on a pair at documented, with a
|
|
218
|
+
warning. The agent commits in the sandbox; the result is a JSON title
|
|
219
|
+
and body for implement, and replies and Verdicts for review-response, and
|
|
220
|
+
a run a limit stopped leaves neither. Defaults: setup 20 min, scan 60 min,
|
|
221
|
+
200 turns (review-response: 150), 40000000 tokens):
|
|
222
|
+
--bundle <file> Where the git bundle of the agent's commits goes.
|
|
223
|
+
Nothing is pushed.
|
|
224
|
+
--sandbox-image <ref> The image the harness is layered on (default: the
|
|
225
|
+
kit's Harness image). A tag is accepted and the
|
|
226
|
+
digest it resolves to printed. It needs glibc
|
|
227
|
+
Linux, git and bash.
|
|
228
|
+
--setup-commands <file> Commands run in the sandbox before the network cut.
|
|
229
|
+
--setup-registries <hosts>
|
|
230
|
+
The hosts those commands may reach, separated by
|
|
231
|
+
spaces, commas or lines (default: none, so no
|
|
232
|
+
network).
|
|
233
|
+
--setup-paths <paths> Absolute paths outside the workspace that setup
|
|
234
|
+
may change and the agent's container takes, one
|
|
235
|
+
per line (default: none). Setup runs in a
|
|
236
|
+
container of its own; only the workspace, these
|
|
237
|
+
paths and .git/ from the trusted commit reach the
|
|
238
|
+
agent's. Harness, git, shell and system locations
|
|
239
|
+
are refused.
|
|
240
|
+
--verify-commands <file>
|
|
241
|
+
The verify run, with no agent: it runs the setup
|
|
242
|
+
commands, cuts the network, then runs these on the
|
|
243
|
+
checked-out commit. It takes --harness, the sandbox
|
|
244
|
+
and setup flags, --setup-minutes (default 20) and
|
|
245
|
+
--scan-minutes (default 30, the commands' limit)
|
|
246
|
+
alone. Exit 0 when they pass.
|
|
247
|
+
|
|
248
|
+
Options for harness test:
|
|
249
|
+
--trusted-ref <ref> The commit to read the Custom harness file from
|
|
250
|
+
(default: the default branch's tip, as this
|
|
251
|
+
checkout has it).
|
|
252
|
+
--default-branch <name> The default branch, where origin's HEAD does not
|
|
253
|
+
name it.
|
|
254
|
+
Exit codes: 0 every Guard held in every scenario, 1 refused or failed, 2
|
|
255
|
+
usage error.
|
|
256
|
+
|
|
134
257
|
Options for upgrade:
|
|
135
258
|
--tag <vY> The Agent-kit tag to move to (asked for when missing).
|
|
136
259
|
--from <vX> The tag you are leaving, when the pins already name <vY>
|
|
@@ -145,6 +268,7 @@ Options for upgrade:
|
|
|
145
268
|
|
|
146
269
|
const COMMAND_OPTIONS = {
|
|
147
270
|
doctor: ["ci", "strict", "repo"],
|
|
271
|
+
harness: ["trusted-ref", "default-branch"],
|
|
148
272
|
init: [
|
|
149
273
|
"tag",
|
|
150
274
|
"flows",
|
|
@@ -152,12 +276,14 @@ const COMMAND_OPTIONS = {
|
|
|
152
276
|
"default-branch",
|
|
153
277
|
"verify",
|
|
154
278
|
"preset",
|
|
279
|
+
"harness",
|
|
155
280
|
"threat-pack-dir",
|
|
156
281
|
"yes",
|
|
157
282
|
"force",
|
|
158
283
|
],
|
|
159
284
|
upgrade: ["tag", "from", "yes", "force"],
|
|
160
285
|
"deep-scan": [
|
|
286
|
+
"harness",
|
|
161
287
|
"recipe",
|
|
162
288
|
"default-branch",
|
|
163
289
|
"credential",
|
|
@@ -173,6 +299,31 @@ const COMMAND_OPTIONS = {
|
|
|
173
299
|
"ref",
|
|
174
300
|
"proving-run",
|
|
175
301
|
],
|
|
302
|
+
stage: [
|
|
303
|
+
"harness",
|
|
304
|
+
"credential",
|
|
305
|
+
"credential-from",
|
|
306
|
+
"setup-minutes",
|
|
307
|
+
"scan-minutes",
|
|
308
|
+
"max-turns",
|
|
309
|
+
"max-tokens",
|
|
310
|
+
"model",
|
|
311
|
+
"effort",
|
|
312
|
+
"proving-run",
|
|
313
|
+
"brief",
|
|
314
|
+
"result",
|
|
315
|
+
"bundle",
|
|
316
|
+
"transcript",
|
|
317
|
+
"error-log",
|
|
318
|
+
"trusted-ref",
|
|
319
|
+
"untracked",
|
|
320
|
+
"input",
|
|
321
|
+
"sandbox-image",
|
|
322
|
+
"setup-registries",
|
|
323
|
+
"setup-commands",
|
|
324
|
+
"setup-paths",
|
|
325
|
+
"verify-commands",
|
|
326
|
+
],
|
|
176
327
|
};
|
|
177
328
|
|
|
178
329
|
/**
|
|
@@ -226,6 +377,7 @@ export async function main(argv, io) {
|
|
|
226
377
|
verify: { type: "string" },
|
|
227
378
|
preset: { type: "string" },
|
|
228
379
|
"threat-pack-dir": { type: "string" },
|
|
380
|
+
harness: { type: "string" },
|
|
229
381
|
recipe: { type: "string" },
|
|
230
382
|
credential: { type: "string" },
|
|
231
383
|
"credential-from": { type: "string" },
|
|
@@ -238,6 +390,19 @@ export async function main(argv, io) {
|
|
|
238
390
|
report: { type: "string" },
|
|
239
391
|
ref: { type: "string" },
|
|
240
392
|
"proving-run": { type: "boolean" },
|
|
393
|
+
brief: { type: "string" },
|
|
394
|
+
result: { type: "string" },
|
|
395
|
+
bundle: { type: "string" },
|
|
396
|
+
transcript: { type: "string" },
|
|
397
|
+
"error-log": { type: "string" },
|
|
398
|
+
"trusted-ref": { type: "string" },
|
|
399
|
+
untracked: { type: "boolean" },
|
|
400
|
+
input: { type: "string", multiple: true },
|
|
401
|
+
"sandbox-image": { type: "string" },
|
|
402
|
+
"setup-registries": { type: "string" },
|
|
403
|
+
"setup-commands": { type: "string" },
|
|
404
|
+
"setup-paths": { type: "string" },
|
|
405
|
+
"verify-commands": { type: "string" },
|
|
241
406
|
yes: { type: "boolean", short: "y" },
|
|
242
407
|
force: { type: "boolean" },
|
|
243
408
|
help: { type: "boolean", short: "h" },
|
|
@@ -262,7 +427,23 @@ export async function main(argv, io) {
|
|
|
262
427
|
stderr(`Unknown command: ${command}\n\n${USAGE}`);
|
|
263
428
|
return 2;
|
|
264
429
|
}
|
|
265
|
-
|
|
430
|
+
// `stage` takes its Stage's name; no other command takes an argument.
|
|
431
|
+
if (command === "stage") {
|
|
432
|
+
const names = Object.keys(STAGE_COMMANDS).join(", ");
|
|
433
|
+
if (!rest.length) {
|
|
434
|
+
stderr(`stage needs a Stage name: ${names}`);
|
|
435
|
+
return 2;
|
|
436
|
+
}
|
|
437
|
+
if (rest.length > 1) {
|
|
438
|
+
stderr(`stage takes one Stage, got: ${rest.join(" ")}`);
|
|
439
|
+
return 2;
|
|
440
|
+
}
|
|
441
|
+
} else if (command === "harness") {
|
|
442
|
+
if (rest.length !== 2 || rest[0] !== "test") {
|
|
443
|
+
stderr("harness takes `test custom:<name>`, as in: agent-kit harness test custom:mine");
|
|
444
|
+
return 2;
|
|
445
|
+
}
|
|
446
|
+
} else if (rest.length) {
|
|
266
447
|
stderr(`${command} takes no arguments, got: ${rest.join(" ")}`);
|
|
267
448
|
return 2;
|
|
268
449
|
}
|
|
@@ -275,7 +456,9 @@ export async function main(argv, io) {
|
|
|
275
456
|
}
|
|
276
457
|
const runner =
|
|
277
458
|
io.runner ??
|
|
278
|
-
|
|
459
|
+
// `stage` and `harness test` run in the Deep scan's sandbox, on the same
|
|
460
|
+
// commands.
|
|
461
|
+
runnerFor(command === "stage" || command === "harness" ? "deep-scan" : command, {
|
|
279
462
|
...(io.spawn ? { spawn: io.spawn } : {}),
|
|
280
463
|
...(io.spawnAsync ? { spawnAsync: io.spawnAsync } : {}),
|
|
281
464
|
});
|
|
@@ -292,6 +475,7 @@ export async function main(argv, io) {
|
|
|
292
475
|
defaultBranch: values["default-branch"],
|
|
293
476
|
verify: values.verify,
|
|
294
477
|
preset: values.preset,
|
|
478
|
+
harness: values.harness,
|
|
295
479
|
threatPackDir: values["threat-pack-dir"],
|
|
296
480
|
},
|
|
297
481
|
force: Boolean(values.force),
|
|
@@ -308,6 +492,7 @@ export async function main(argv, io) {
|
|
|
308
492
|
return runDeepScan({
|
|
309
493
|
cwd,
|
|
310
494
|
runner,
|
|
495
|
+
harness: values.harness,
|
|
311
496
|
recipePath: values.recipe,
|
|
312
497
|
defaultBranch: values["default-branch"],
|
|
313
498
|
credential: values.credential,
|
|
@@ -318,19 +503,55 @@ export async function main(argv, io) {
|
|
|
318
503
|
verifyPath: values.verify,
|
|
319
504
|
ref: values.ref,
|
|
320
505
|
provingRun: Boolean(values["proving-run"]),
|
|
321
|
-
limitFlags:
|
|
322
|
-
|
|
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 } : {}),
|
|
506
|
+
limitFlags: limitFlagsOf(values),
|
|
507
|
+
...hostOf(io),
|
|
329
508
|
...(io.fetch !== undefined ? { fetch: io.fetch } : {}),
|
|
330
|
-
...(io.signals !== undefined ? { signals: io.signals } : {}),
|
|
331
509
|
...(io.reportDir !== undefined ? { reportDir: io.reportDir } : {}),
|
|
332
|
-
|
|
333
|
-
|
|
510
|
+
out: stdout,
|
|
511
|
+
err: stderr,
|
|
512
|
+
});
|
|
513
|
+
}
|
|
514
|
+
if (command === "stage") {
|
|
515
|
+
stdout(`agent-kit stage ${VERSION}`);
|
|
516
|
+
return runStage({
|
|
517
|
+
cwd,
|
|
518
|
+
runner,
|
|
519
|
+
stage: rest[0],
|
|
520
|
+
harness: values.harness,
|
|
521
|
+
model: values.model,
|
|
522
|
+
effort: values.effort,
|
|
523
|
+
credential: values.credential,
|
|
524
|
+
credentialFrom: values["credential-from"],
|
|
525
|
+
briefPath: values.brief,
|
|
526
|
+
resultPath: values.result,
|
|
527
|
+
bundlePath: values.bundle,
|
|
528
|
+
transcriptPath: values.transcript,
|
|
529
|
+
errorLogPath: values["error-log"],
|
|
530
|
+
trustedRef: values["trusted-ref"],
|
|
531
|
+
untracked: Boolean(values.untracked),
|
|
532
|
+
inputPaths: values.input,
|
|
533
|
+
sandboxImage: values["sandbox-image"],
|
|
534
|
+
setupRegistries: values["setup-registries"],
|
|
535
|
+
setupPath: values["setup-commands"],
|
|
536
|
+
setupPaths: values["setup-paths"],
|
|
537
|
+
verifyPath: values["verify-commands"],
|
|
538
|
+
provingRun: Boolean(values["proving-run"]),
|
|
539
|
+
limitFlags: limitFlagsOf(values),
|
|
540
|
+
...hostOf(io),
|
|
541
|
+
out: stdout,
|
|
542
|
+
err: stderr,
|
|
543
|
+
});
|
|
544
|
+
}
|
|
545
|
+
if (command === "harness") {
|
|
546
|
+
stdout(`agent-kit harness test ${VERSION}`);
|
|
547
|
+
return runHarnessTest({
|
|
548
|
+
cwd,
|
|
549
|
+
runner,
|
|
550
|
+
harness: rest[1],
|
|
551
|
+
trustedRef: values["trusted-ref"],
|
|
552
|
+
defaultBranch: values["default-branch"],
|
|
553
|
+
...hostOf(io),
|
|
554
|
+
...(io.scenarioRunner !== undefined ? { scenarioRunner: io.scenarioRunner } : {}),
|
|
334
555
|
out: stdout,
|
|
335
556
|
err: stderr,
|
|
336
557
|
});
|
|
@@ -355,6 +576,22 @@ export async function main(argv, io) {
|
|
|
355
576
|
return report.exitCode;
|
|
356
577
|
}
|
|
357
578
|
|
|
579
|
+
/** The limit flags' values, keyed by flag name. */
|
|
580
|
+
const limitFlagsOf = (values) => ({
|
|
581
|
+
"setup-minutes": values["setup-minutes"],
|
|
582
|
+
"scan-minutes": values["scan-minutes"],
|
|
583
|
+
"max-turns": values["max-turns"],
|
|
584
|
+
"max-tokens": values["max-tokens"],
|
|
585
|
+
});
|
|
586
|
+
|
|
587
|
+
/** The host's seams `deep-scan` and `stage` share, where `io` replaces them. */
|
|
588
|
+
const hostOf = (io) =>
|
|
589
|
+
Object.fromEntries(
|
|
590
|
+
["platform", "env", "signals", "modelApi", "timers"]
|
|
591
|
+
.filter((name) => io[name] !== undefined)
|
|
592
|
+
.map((name) => [name, io[name]]),
|
|
593
|
+
);
|
|
594
|
+
|
|
358
595
|
async function upgrade(values, { cwd, runner, openRepo, prompt, stdout, stderr }) {
|
|
359
596
|
if (!prompt) {
|
|
360
597
|
// No terminal: every answer must come from a flag.
|
package/src/deep-scan/agent.mjs
CHANGED
|
@@ -6,13 +6,14 @@
|
|
|
6
6
|
// report-format.md, which it builds on), the Threat pack and the Scan recipe,
|
|
7
7
|
// all read at the trusted ref, and the sandbox's paths. How the harness is
|
|
8
8
|
// started, what it holds and how it says it hit its turn limit come from its
|
|
9
|
-
// Harness adapter's launch plan (../harness
|
|
10
|
-
//
|
|
9
|
+
// Harness adapter's launch plan (../harness/, ADR 0027); this module runs
|
|
10
|
+
// that plan.
|
|
11
11
|
|
|
12
12
|
import { firstLine } from "../exec.mjs";
|
|
13
|
-
import {
|
|
13
|
+
import { adapterFor, DEFAULT_HARNESS } from "../harness/adapters.mjs";
|
|
14
14
|
import { checkSafePath, UnsafePathError } from "../safe-paths.mjs";
|
|
15
15
|
import { isMapping, parseYamlSubset, stripBom } from "../yaml-subset.mjs";
|
|
16
|
+
import { textFor } from "./harness-text.mjs";
|
|
16
17
|
|
|
17
18
|
/** Where a Consumer's security-audit skill lives, as Agent-kit installs it. */
|
|
18
19
|
export const SKILL_DIR = ".claude/skills/security-audit";
|
|
@@ -33,20 +34,31 @@ export const BRIEF_PATH = "/agent-kit/in/brief.md";
|
|
|
33
34
|
|
|
34
35
|
/** The launcher's own folder in the sandbox, outside /workspace. */
|
|
35
36
|
const KIT_DIR = "/agent-kit";
|
|
36
|
-
|
|
37
|
+
|
|
38
|
+
/** Folders of the launcher's that a plan's config file may not sit in: each is emptied first. */
|
|
39
|
+
const OWN_FOLDERS = Object.freeze(["grounding", "in", "logs", "out"]);
|
|
37
40
|
|
|
38
41
|
/**
|
|
39
42
|
* The harness's launch plan for a Deep scan. Without a `baseUrl` (before the
|
|
40
43
|
* model route is open) its launch is not yet one to run; its identity and
|
|
41
44
|
* install layer are.
|
|
42
|
-
* @param {{ baseUrl?: string, maxTurns?: number, model?: string, effort?: string, kind?: "api-key" | "subscription", callerKey?: string }} [opts]
|
|
45
|
+
* @param {{ harness?: string, baseUrl?: string, maxTurns?: number, model?: string, effort?: string, kind?: "api-key" | "subscription", callerKey?: string }} [opts]
|
|
46
|
+
* `harness` is one the kit has an adapter for (default Claude Code).
|
|
43
47
|
* `model` is a plain model id and `effort` an effort level, both checked by
|
|
44
48
|
* the launcher. `kind` is the credential's (default an API key).
|
|
45
49
|
* `callerKey` is the run's (callerKeyFor): the agent holds it in place of
|
|
46
50
|
* the credential.
|
|
47
51
|
*/
|
|
48
|
-
export function agentPlan({
|
|
49
|
-
|
|
52
|
+
export function agentPlan({
|
|
53
|
+
harness = DEFAULT_HARNESS,
|
|
54
|
+
baseUrl,
|
|
55
|
+
maxTurns,
|
|
56
|
+
model,
|
|
57
|
+
effort,
|
|
58
|
+
kind,
|
|
59
|
+
callerKey,
|
|
60
|
+
} = {}) {
|
|
61
|
+
return adapterFor(harness)({
|
|
50
62
|
stage: "deep-scan",
|
|
51
63
|
proxyUrl: baseUrl,
|
|
52
64
|
briefPath: BRIEF_PATH,
|
|
@@ -69,6 +81,15 @@ export function agentPlan({ baseUrl, maxTurns, model, effort, kind, callerKey }
|
|
|
69
81
|
export const turnsMarker = (plan) =>
|
|
70
82
|
`agent-kit-deep-scan: ${plan.identity.displayName} reached its turn limit`;
|
|
71
83
|
|
|
84
|
+
/**
|
|
85
|
+
* What the agent step's script prints when the harness said it has no
|
|
86
|
+
* credential it reads (Antigravity CLI asks for a sign-in): a fixed line, as
|
|
87
|
+
* `turnsMarker`'s, printed on the plan's marker in the harness's error output.
|
|
88
|
+
* @param {import("../harness/claude-code.mjs").LaunchPlan} plan
|
|
89
|
+
*/
|
|
90
|
+
export const credentialMarker = (plan) =>
|
|
91
|
+
`agent-kit-deep-scan: ${plan.identity.displayName} found no model credential`;
|
|
92
|
+
|
|
72
93
|
/** The Claude Code plan's line. */
|
|
73
94
|
export const TURNS_MARKER = turnsMarker(agentPlan());
|
|
74
95
|
|
|
@@ -228,10 +249,12 @@ function plainPath(value) {
|
|
|
228
249
|
* grounding: Array<{ source: string, at: string }>,
|
|
229
250
|
* paths: { workspace: string, grounding: string, report: string },
|
|
230
251
|
* discovers?: boolean,
|
|
252
|
+
* harness?: string,
|
|
231
253
|
* }} opts `discovers`: Claude Code runs without `--bare` (the
|
|
232
254
|
* subscription path), so the brief says what it discovers.
|
|
233
255
|
*/
|
|
234
256
|
export function agentBrief({
|
|
257
|
+
harness = DEFAULT_HARNESS,
|
|
235
258
|
branch,
|
|
236
259
|
short,
|
|
237
260
|
recipePath,
|
|
@@ -244,13 +267,14 @@ export function agentBrief({
|
|
|
244
267
|
return [
|
|
245
268
|
"# Deep scan brief, from the agent-kit deep-scan launcher",
|
|
246
269
|
"",
|
|
247
|
-
|
|
270
|
+
`This is the launcher's brief. You are running inside the closed, disposable sandbox that \`agent-kit deep-scan\` started for a Deep scan: run the security-audit skill in \`deep\` mode, by the procedure below. Your only network route is the launcher's model proxy, and ${textFor(harness).webOff}.`,
|
|
248
271
|
"",
|
|
249
272
|
"## Where things are",
|
|
250
273
|
"",
|
|
251
274
|
`- The repository: \`${paths.workspace}\`, an export of \`${branch}\` at ${short} (the trusted ref). Scan the whole repository.`,
|
|
252
275
|
...groundingLines(grounding, paths),
|
|
253
276
|
`- The report: write it to \`${paths.report}\`, early, and update it as each finding lands. It is the only file that leaves the sandbox.`,
|
|
277
|
+
...removedLines(harness, paths),
|
|
254
278
|
SETUP_DONE,
|
|
255
279
|
...(discovers ? [DISCOVERED] : []),
|
|
256
280
|
"",
|
|
@@ -272,6 +296,22 @@ export function agentBrief({
|
|
|
272
296
|
].join("\n");
|
|
273
297
|
}
|
|
274
298
|
|
|
299
|
+
/**
|
|
300
|
+
* A brief's line on what the launcher removes from the copy before the
|
|
301
|
+
* harness starts, where its launch plan says it does.
|
|
302
|
+
* @param {string} harness
|
|
303
|
+
* @param {{ workspace: string }} paths
|
|
304
|
+
* @returns {string[]}
|
|
305
|
+
*/
|
|
306
|
+
export function removedLines(harness, paths) {
|
|
307
|
+
const { launch, checkoutConfig } = adapterFor(harness)();
|
|
308
|
+
if (!launch.removeCheckoutConfig) return [];
|
|
309
|
+
const removed = checkoutConfig.map((path) => `\`${path}\``).join(", ");
|
|
310
|
+
return [
|
|
311
|
+
`- The harness's own config was removed from \`${paths.workspace}\` before you started (${removed}), so none of it could configure you: it is not part of this scan, and its absence is no finding.`,
|
|
312
|
+
];
|
|
313
|
+
}
|
|
314
|
+
|
|
275
315
|
/** A brief's line on the setup phase, which the launcher already ran. */
|
|
276
316
|
export const SETUP_DONE =
|
|
277
317
|
"- The launcher already ran the Scan recipe's `setup`, `start`, `ready` and `seed`: the services it starts are running. Do not run them again.";
|
|
@@ -324,23 +364,36 @@ export function threatPackAndRecipe({ handIn, recipePath, recipeText }) {
|
|
|
324
364
|
}
|
|
325
365
|
|
|
326
366
|
/**
|
|
327
|
-
* The agent step's script, run with `sh -c` in the sandbox
|
|
328
|
-
*
|
|
329
|
-
*
|
|
330
|
-
*
|
|
367
|
+
* The agent step's script, run with `sh -c` in the sandbox. It first removes
|
|
368
|
+
* the checkout's harness config from the workspace, where the plan's launch
|
|
369
|
+
* says so, and writes the plan's config files, each one's folder under the
|
|
370
|
+
* launcher's emptied first, so nothing a setup step left there is read. Then
|
|
371
|
+
* the plan's command, its stdin the plan's file, its own output kept in the
|
|
372
|
+
* plan's transcript (its error output is passed on too), `turnsMarker` when the
|
|
373
|
+
* plan's turn-cap marker is in that error output, and `credentialMarker` when
|
|
374
|
+
* its missing-credential marker is. The plan's environment is
|
|
331
375
|
* the caller's to set.
|
|
332
|
-
* @param {{ report: string, workspace: string, plan?: import("../harness/claude-code.mjs").LaunchPlan } & Parameters<typeof agentPlan>[0]} opts
|
|
333
|
-
* Without a `plan`, the rest are `agentPlan`'s, which makes one.
|
|
376
|
+
* @param {{ report: string, workspace: string, kitDir?: string, plan?: import("../harness/claude-code.mjs").LaunchPlan } & Parameters<typeof agentPlan>[0]} opts
|
|
377
|
+
* Without a `plan`, the rest are `agentPlan`'s, which makes one. `kitDir`
|
|
378
|
+
* is the launcher's folder; only tests pass another.
|
|
334
379
|
*/
|
|
335
|
-
export function agentScript({ report, workspace, plan, ...request }) {
|
|
380
|
+
export function agentScript({ report, workspace, kitDir = KIT_DIR, plan, ...request }) {
|
|
336
381
|
const launched = plan ?? agentPlan(request);
|
|
337
|
-
const { launch, stops, transcript } = launched;
|
|
338
|
-
|
|
339
|
-
// No adapter has one yet: refused, rather than launched without them.
|
|
340
|
-
throw new Error("the launcher does not write a launch plan's config files yet");
|
|
341
|
-
}
|
|
342
|
-
const logs = LOGS_DIR;
|
|
382
|
+
const { launch, stops, transcript, checkoutConfig } = launched;
|
|
383
|
+
const logs = `${kitDir}/logs`;
|
|
343
384
|
const folderOf = (path) => path.slice(0, path.lastIndexOf("/"));
|
|
385
|
+
const owned = new Map();
|
|
386
|
+
for (const { path } of launch.files) {
|
|
387
|
+
// Only under a folder of its own, right under the launcher's, since the
|
|
388
|
+
// script empties that folder.
|
|
389
|
+
const parts = path.startsWith(`${kitDir}/`) ? path.slice(kitDir.length + 1).split("/") : [];
|
|
390
|
+
const plain = parts.length > 1 && parts.every((part) => part && !/^\.{1,2}$/.test(part));
|
|
391
|
+
if (!plain || OWN_FOLDERS.includes(parts[0])) {
|
|
392
|
+
throw new Error(`a launch plan's config file must sit in a folder of its own: ${path}`);
|
|
393
|
+
}
|
|
394
|
+
const own = `${kitDir}/${parts[0]}`;
|
|
395
|
+
owned.set(own, (owned.get(own) ?? new Set()).add(folderOf(path)));
|
|
396
|
+
}
|
|
344
397
|
const folders = [...new Set([folderOf(report), logs, folderOf(transcript.path)])];
|
|
345
398
|
const stdin = launch.stdin ? ` < ${shQuote(launch.stdin.file)}` : "";
|
|
346
399
|
// The harness's error output reaches the launcher through a pipe, as it
|
|
@@ -351,6 +404,15 @@ export function agentScript({ report, workspace, plan, ...request }) {
|
|
|
351
404
|
"set -eu",
|
|
352
405
|
`mkdir -p ${folders.join(" ")}`,
|
|
353
406
|
`cd ${workspace}`,
|
|
407
|
+
...(launch.removeCheckoutConfig
|
|
408
|
+
? [`rm -rf -- ${checkoutConfig.map((path) => shQuote(`./${path}`)).join(" ")}`]
|
|
409
|
+
: []),
|
|
410
|
+
// Each on a line of its own, so a failure of either ends the script.
|
|
411
|
+
...[...owned].flatMap(([own, parents]) => [
|
|
412
|
+
`rm -rf -- ${shQuote(own)}`,
|
|
413
|
+
...[...parents].map((folder) => `mkdir -p ${shQuote(folder)}`),
|
|
414
|
+
]),
|
|
415
|
+
...launch.files.map(({ path, text }) => `printf '%s' ${shQuote(text)} > ${shQuote(path)}`),
|
|
354
416
|
`rm -f ${logs}/agent.status`,
|
|
355
417
|
`{ ${launch.argv.map(shQuote).join(" ")}${stdin} 2>&1 > ${shQuote(transcript.path)} || echo "$?" > ${logs}/agent.status; } | tee ${logs}/agent.err >&2`,
|
|
356
418
|
"status=0",
|
|
@@ -361,6 +423,11 @@ export function agentScript({ report, workspace, plan, ...request }) {
|
|
|
361
423
|
`if grep -q ${shQuote(stops.turnCap.stderrPattern)} ${logs}/agent.err; then echo ${shQuote(turnsMarker(launched))}; fi`,
|
|
362
424
|
]
|
|
363
425
|
: []),
|
|
426
|
+
...(stops.credentialMissing
|
|
427
|
+
? [
|
|
428
|
+
`if grep -qiE ${shQuote(stops.credentialMissing.stderrPattern)} ${logs}/agent.err; then echo ${shQuote(credentialMarker(launched))}; fi`,
|
|
429
|
+
]
|
|
430
|
+
: []),
|
|
364
431
|
'exit "$status"',
|
|
365
432
|
].join("\n");
|
|
366
433
|
}
|