@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/deep-scan/tar.mjs
CHANGED
|
@@ -1,44 +1,91 @@
|
|
|
1
|
-
// The tar streams the
|
|
2
|
-
// in Node core (ADR 0001). In: a ustar archive
|
|
3
|
-
//
|
|
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`)
|
|
11
|
-
* its bytes. Paths are relative
|
|
12
|
-
*
|
|
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 (
|
|
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 =
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
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
|
package/src/deep-scan/verify.mjs
CHANGED
|
@@ -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
|
-
|
|
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
|
|
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 {
|
|
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
|
-
/**
|
|
63
|
-
const
|
|
68
|
+
/** Each harness, as `cli/harnesses.json` describes it. */
|
|
69
|
+
const HARNESSES = readHarnesses().harnesses;
|
|
64
70
|
|
|
65
|
-
/** The effort levels
|
|
66
|
-
export const EFFORTS = Object.freeze(
|
|
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(
|
|
225
|
+
if (effort !== undefined && (effort === "" || "refused" in effortFor(facts, { effort }))) {
|
|
188
226
|
err(
|
|
189
|
-
|
|
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
|
-
|
|
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({
|
|
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,6 +32,14 @@ import {
|
|
|
24
32
|
deriveRequirements,
|
|
25
33
|
deriveVariables,
|
|
26
34
|
} from "./checks/secrets-and-variables.mjs";
|
|
35
|
+
import {
|
|
36
|
+
actionJobs,
|
|
37
|
+
checkHarnessVariables,
|
|
38
|
+
checkStages,
|
|
39
|
+
HARNESSES_PATH,
|
|
40
|
+
readHarnessFacts,
|
|
41
|
+
STAGE_CHECKS,
|
|
42
|
+
} from "./checks/stages.mjs";
|
|
27
43
|
import { firstLine } from "./exec.mjs";
|
|
28
44
|
import { createGitHub } from "./github.mjs";
|
|
29
45
|
import { openKitTag, PreManifestTagError, serverFromEnv } from "./kit-tag.mjs";
|
|
@@ -49,6 +65,9 @@ export const LOCAL_ONLY_CHECKS = [
|
|
|
49
65
|
["ruleset-tags", "Release tags have a v* tag ruleset"],
|
|
50
66
|
["release-tag-push", "Release tags can be pushed under the tag ruleset"],
|
|
51
67
|
["review-response-mode", "Review response mode is set up"],
|
|
68
|
+
["github-app", "Your GitHub App is set up"],
|
|
69
|
+
["ci-workflow", "CI starts for agent pushes"],
|
|
70
|
+
...STAGE_CHECKS,
|
|
52
71
|
];
|
|
53
72
|
|
|
54
73
|
const skipAll = (ids, reason) => ids.map(([id, title]) => result(id, title, "skip", reason));
|
|
@@ -193,7 +212,8 @@ export function runDoctor({
|
|
|
193
212
|
),
|
|
194
213
|
);
|
|
195
214
|
} else {
|
|
196
|
-
results.push(...localChecks({ runner, cwd, info, files, callers, snapshot }));
|
|
215
|
+
results.push(...localChecks({ runner, cwd, root, info, files, callers, snapshot }));
|
|
216
|
+
results.push(...harnessChecks({ runner, cwd, root, info, callers, snapshot }));
|
|
197
217
|
}
|
|
198
218
|
} finally {
|
|
199
219
|
snapshot?.cleanup();
|
|
@@ -226,20 +246,23 @@ export function guarded(id, run, title = TITLES[id] ?? id) {
|
|
|
226
246
|
}
|
|
227
247
|
}
|
|
228
248
|
|
|
229
|
-
function localChecks({ runner, cwd, info, files, callers, snapshot }) {
|
|
249
|
+
function localChecks({ runner, cwd, root, info, files, callers, snapshot }) {
|
|
230
250
|
const github = createGitHub(runner, { cwd, hostname: info.host ?? null });
|
|
231
251
|
const { repo, owner, ownerType, defaultBranch } = info;
|
|
232
252
|
const raw = [];
|
|
233
253
|
const out = { push: (...items) => raw.push(...items) };
|
|
234
254
|
|
|
235
255
|
if (snapshot) {
|
|
256
|
+
// A tag that publishes its harness facts asks for each Stage's own
|
|
257
|
+
// credential, in the harness checks.
|
|
258
|
+
const perStageCredential = snapshot.readFile(HARNESSES_PATH) !== null;
|
|
236
259
|
let requirements = null;
|
|
237
260
|
out.push(
|
|
238
261
|
guarded("secrets", () => {
|
|
239
262
|
requirements = deriveRequirements(callers, (file) =>
|
|
240
263
|
snapshot.readFile(`.github/workflows/${file}`),
|
|
241
264
|
);
|
|
242
|
-
return checkSecrets({ github, repo, ownerType, requirements });
|
|
265
|
+
return checkSecrets({ github, repo, ownerType, requirements, perStageCredential });
|
|
243
266
|
}),
|
|
244
267
|
);
|
|
245
268
|
out.push(
|
|
@@ -285,7 +308,22 @@ function localChecks({ runner, cwd, info, files, callers, snapshot }) {
|
|
|
285
308
|
),
|
|
286
309
|
);
|
|
287
310
|
|
|
288
|
-
|
|
311
|
+
// Read once, and only if a check that uses it runs.
|
|
312
|
+
let onAction = null;
|
|
313
|
+
const actions = () => (onAction ??= actionJobs({ github, repo, ownerType, callers, snapshot }));
|
|
314
|
+
let onApp = null;
|
|
315
|
+
const appActions = () =>
|
|
316
|
+
(onApp ??= actionJobs({ github, repo, ownerType, callers, snapshot, app: true }));
|
|
317
|
+
out.push(
|
|
318
|
+
guarded("claude-app", () => {
|
|
319
|
+
// Only a Stage whose action step takes the Claude GitHub App's token
|
|
320
|
+
// needs it: one given the job token does not. Callers doctor could not
|
|
321
|
+
// read in full may hide such a Stage.
|
|
322
|
+
const needed =
|
|
323
|
+
callers.some((c) => c.parseIncomplete) || [...appActions().values()].some(Boolean);
|
|
324
|
+
return checkClaudeApp({ github, repo, owner, ownerType, needed });
|
|
325
|
+
}),
|
|
326
|
+
);
|
|
289
327
|
|
|
290
328
|
let rulesets = null;
|
|
291
329
|
let rulesetError = null;
|
|
@@ -307,9 +345,80 @@ function localChecks({ runner, cwd, info, files, callers, snapshot }) {
|
|
|
307
345
|
checkReviewResponseMode({ github, repo, ownerType, callers }),
|
|
308
346
|
),
|
|
309
347
|
);
|
|
348
|
+
out.push(...appChecks({ github, root, info, callers, snapshot, actions }));
|
|
310
349
|
return raw;
|
|
311
350
|
}
|
|
312
351
|
|
|
352
|
+
/** The Consumer's own GitHub App, and how CI starts without one. */
|
|
353
|
+
function appChecks({ github, root, info, callers, snapshot, actions }) {
|
|
354
|
+
const { repo, owner, ownerType } = info;
|
|
355
|
+
const readReusable = snapshot ? (file) => snapshot.readFile(`.github/workflows/${file}`) : null;
|
|
356
|
+
let settings = null;
|
|
357
|
+
let jobs = [];
|
|
358
|
+
const unread = unreadCallers(callers);
|
|
359
|
+
const onAction = (where) => actions().get(where) === true;
|
|
360
|
+
const unreadHarness = (where) => actions().get(where) === "unknown";
|
|
361
|
+
const results = [
|
|
362
|
+
guarded("github-app", () => {
|
|
363
|
+
jobs = pushingJobs(callers, readReusable);
|
|
364
|
+
settings = readAppSettings({ github, repo, ownerType });
|
|
365
|
+
const tag = snapshot?.tag;
|
|
366
|
+
return checkGitHubApp({ repo, settings, jobs, unread, tag, onAction, unreadHarness });
|
|
367
|
+
}),
|
|
368
|
+
];
|
|
369
|
+
const appSet = Boolean(settings?.idSet && settings.keySet);
|
|
370
|
+
if (appSet) {
|
|
371
|
+
const installed = () => checkGitHubAppInstalled({ github, repo, owner, ownerType });
|
|
372
|
+
results.push(guarded("github-app-installed", installed, "Your GitHub App is installed"));
|
|
373
|
+
}
|
|
374
|
+
// Not read: a half doctor cannot see may be set.
|
|
375
|
+
const appUnknown = !settings || Boolean(settings.unknown);
|
|
376
|
+
const ciWorkflow = () =>
|
|
377
|
+
checkCiWorkflow({ root, jobs, unread, appSet, appUnknown, onAction, unreadHarness });
|
|
378
|
+
results.push(guarded("ci-workflow", ciWorkflow));
|
|
379
|
+
return results;
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
/** The harness checks, from the pinned tag's cli/harnesses.json. */
|
|
383
|
+
function harnessChecks({ runner, cwd, root, info, callers, snapshot }) {
|
|
384
|
+
const skipEach = (reason) => skipAll(STAGE_CHECKS, reason);
|
|
385
|
+
if (!snapshot) return skipEach("Needs the pinned tag's harness facts; fix the pins first.");
|
|
386
|
+
const github = createGitHub(runner, { cwd, hostname: info.host ?? null });
|
|
387
|
+
const { repo, ownerType, defaultBranch } = info;
|
|
388
|
+
const { tag } = snapshot;
|
|
389
|
+
let facts;
|
|
390
|
+
try {
|
|
391
|
+
facts = readHarnessFacts(snapshot);
|
|
392
|
+
} catch (err) {
|
|
393
|
+
const [[id, title], ...rest] = STAGE_CHECKS;
|
|
394
|
+
const reason = `${tag}'s ${HARNESSES_PATH} could not be read: ${firstLine(err.message)}`;
|
|
395
|
+
return [result(id, title, "fail", reason), ...skipAll(rest, reason)];
|
|
396
|
+
}
|
|
397
|
+
if (facts === null) {
|
|
398
|
+
return [
|
|
399
|
+
...skipEach(`${tag} predates harness choice: it has no ${HARNESSES_PATH}.`),
|
|
400
|
+
...checkHarnessVariables({ github, repo, ownerType, tag }),
|
|
401
|
+
];
|
|
402
|
+
}
|
|
403
|
+
try {
|
|
404
|
+
return checkStages({
|
|
405
|
+
github,
|
|
406
|
+
repo,
|
|
407
|
+
ownerType,
|
|
408
|
+
callers,
|
|
409
|
+
facts,
|
|
410
|
+
snapshot,
|
|
411
|
+
root,
|
|
412
|
+
defaultBranch,
|
|
413
|
+
});
|
|
414
|
+
} catch (err) {
|
|
415
|
+
const crash = () => {
|
|
416
|
+
throw err;
|
|
417
|
+
};
|
|
418
|
+
return STAGE_CHECKS.map(([id, title]) => guarded(id, crash, title));
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
|
|
313
422
|
function finish({ mode, modeReason, repo, tag, results, refusal, strict }) {
|
|
314
423
|
const final = strict
|
|
315
424
|
? results.map((r) => (r.status === "warn" ? { ...r, status: "fail", strict: true } : r))
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// The Harness adapters the kit ships (ADR 0027), by harness name: each takes a
|
|
2
|
+
// Stage request and returns its launch plan.
|
|
3
|
+
|
|
4
|
+
import { antigravity } from "./antigravity.mjs";
|
|
5
|
+
import { claudeCode } from "./claude-code.mjs";
|
|
6
|
+
import { codex } from "./codex.mjs";
|
|
7
|
+
import { cursor } from "./cursor.mjs";
|
|
8
|
+
import { loadedCustom } from "./custom/registry.mjs";
|
|
9
|
+
import { gemini } from "./gemini.mjs";
|
|
10
|
+
import { opencode } from "./opencode.mjs";
|
|
11
|
+
|
|
12
|
+
/** @type {Readonly<Record<string, (request?: object) => import("./claude-code.mjs").LaunchPlan>>} */
|
|
13
|
+
export const ADAPTERS = Object.freeze({
|
|
14
|
+
"claude-code": claudeCode,
|
|
15
|
+
codex,
|
|
16
|
+
gemini,
|
|
17
|
+
antigravity,
|
|
18
|
+
opencode,
|
|
19
|
+
cursor,
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* `harness`'s adapter: the kit's own, or a Custom harness's once its file is
|
|
24
|
+
* loaded from the trusted commit (harness/resolve.mjs).
|
|
25
|
+
* @param {string} harness
|
|
26
|
+
*/
|
|
27
|
+
export const adapterFor = (harness) => loadedCustom(harness)?.adapter ?? ADAPTERS[harness];
|
|
28
|
+
|
|
29
|
+
/** The harness a Stage runs on when no setting names one (ADR 0022). */
|
|
30
|
+
export const DEFAULT_HARNESS = "claude-code";
|