@mnaimfaizy/agent-kit 1.0.0-beta.13 → 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 +24 -5
- package/custom-harness.schema.json +243 -0
- package/harnesses.json +286 -0
- package/package.json +4 -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/review-response.mjs +54 -27
- package/src/checks/rulesets.mjs +9 -8
- package/src/checks/secrets-and-variables.mjs +220 -43
- package/src/checks/stages.mjs +705 -0
- package/src/cli.mjs +277 -31
- package/src/deep-scan/agent.mjs +145 -117
- package/src/deep-scan/credential.mjs +88 -42
- package/src/deep-scan/docker-driver.mjs +131 -49
- package/src/deep-scan/harness-text.mjs +99 -0
- package/src/deep-scan/lifecycle.mjs +92 -199
- package/src/deep-scan/limits.mjs +13 -7
- package/src/deep-scan/model-proxy.mjs +47 -602
- package/src/deep-scan/preflight.mjs +81 -1
- package/src/deep-scan/recipe.mjs +7 -7
- package/src/deep-scan/runtime.mjs +54 -6
- package/src/deep-scan/sandbox-run.mjs +232 -0
- package/src/deep-scan/sbx-driver.mjs +242 -50
- package/src/deep-scan/tar.mjs +69 -22
- package/src/deep-scan/verify.mjs +6 -1
- package/src/deep-scan.mjs +98 -14
- 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 +236 -0
- 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 +157 -0
- package/src/harness/gemini.mjs +164 -0
- package/src/harness/install-layer.mjs +141 -0
- package/src/harness/opencode.mjs +289 -0
- package/src/harness/resolve.mjs +156 -0
- package/src/harness/support-levels.mjs +197 -0
- package/src/harness-live/assess.mjs +291 -0
- 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 +414 -0
- package/src/harness-live/opencode.mjs +289 -0
- package/src/harness-live/probes.mjs +239 -0
- package/src/harness-live/run.mjs +214 -0
- package/src/harness-live/setup.mjs +126 -0
- package/src/harness-live/stage.mjs +161 -0
- package/src/harness-live/suite.mjs +481 -0
- package/src/harness-test.mjs +116 -0
- package/src/init.mjs +339 -23
- package/src/model-proxy/core.mjs +657 -0
- package/src/model-proxy/profiles/anthropic.mjs +241 -0
- 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/anthropic.mjs +110 -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 +182 -0
- 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/claude-code.mjs +0 -25
package/src/init.mjs
CHANGED
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
// examples/ with its placeholders filled in, writes the Threat pack skeleton
|
|
4
4
|
// and (if there is none) .github/dependabot.yml, then prints the GitHub-side
|
|
5
5
|
// steps as `gh` commands for the Consumer to run. It writes only local files.
|
|
6
|
+
// The steps for the chosen harness come from the tag's cli/harnesses.json
|
|
7
|
+
// (ADR 0030); nothing about a harness is written into a Caller.
|
|
6
8
|
//
|
|
7
9
|
// Plan first, then write: every file is read and every refusal checked
|
|
8
10
|
// before anything on disk changes.
|
|
@@ -10,6 +12,7 @@
|
|
|
10
12
|
import { join } from "node:path";
|
|
11
13
|
import { DEFAULT_KIT_REPO } from "./callers.mjs";
|
|
12
14
|
import { command } from "./checks/result.mjs";
|
|
15
|
+
import { RENAMED_VARIABLES } from "./checks/secrets-and-variables.mjs";
|
|
13
16
|
import { fileAndPinChecks, printFileAndPinChecks } from "./doctor.mjs";
|
|
14
17
|
import { firstLine } from "./exec.mjs";
|
|
15
18
|
import { openKitTag, PreManifestTagError, serverFromEnv } from "./kit-tag.mjs";
|
|
@@ -27,7 +30,7 @@ import {
|
|
|
27
30
|
uncommittedChanges,
|
|
28
31
|
} from "./local-writes.mjs";
|
|
29
32
|
import { caseCollisions, checkSafePath, fileDirConflicts } from "./safe-paths.mjs";
|
|
30
|
-
import { isReleaseTag } from "./tags.mjs";
|
|
33
|
+
import { CLI_VERSION, isReleaseTag } from "./tags.mjs";
|
|
31
34
|
import {
|
|
32
35
|
DEFAULT_THREAT_PACK_DIR,
|
|
33
36
|
FLOWS,
|
|
@@ -69,6 +72,32 @@ const RESPONSE_LABEL = [
|
|
|
69
72
|
"Agent-kit: answer the review on this PR",
|
|
70
73
|
];
|
|
71
74
|
|
|
75
|
+
const DEFAULT_HARNESS = "claude-code";
|
|
76
|
+
const HARNESS_NAME = /^[a-z][a-z0-9-]*$/;
|
|
77
|
+
const SECRET_INPUT = /^[a-z][a-z0-9_]*$/;
|
|
78
|
+
const HARNESS_FILE = "cli/harnesses.json";
|
|
79
|
+
/** The first tag that ships `cli/harnesses.json`: older ones run claude-code alone. */
|
|
80
|
+
const FIRST_HARNESS_TAG = "v1.0.0-beta.14";
|
|
81
|
+
/** The page that describes the Custom harness file. */
|
|
82
|
+
const CUSTOM_DOCS_URL = `https://github.com/${DEFAULT_KIT_REPO}/blob/v${CLI_VERSION}/docs/adr/0027-a-harness-adapter-returns-a-launch-plan-as-data.md`;
|
|
83
|
+
|
|
84
|
+
/** The Stages each flow runs, and how a reason names each one. */
|
|
85
|
+
const FLOW_STAGES = {
|
|
86
|
+
pipeline: ["plan", "implement", "review"],
|
|
87
|
+
audit: ["security-audit"],
|
|
88
|
+
"review-response": ["review-response"],
|
|
89
|
+
};
|
|
90
|
+
const STAGE_NAMES = {
|
|
91
|
+
plan: "plan",
|
|
92
|
+
implement: "implement",
|
|
93
|
+
review: "review",
|
|
94
|
+
"security-audit": "static security audit",
|
|
95
|
+
"review-response": "Review response",
|
|
96
|
+
};
|
|
97
|
+
/** The Stages that need a pair at `tried` or above (ADR 0028). */
|
|
98
|
+
const SECURITY_STAGES = new Set(["security-audit"]);
|
|
99
|
+
const LEVELS = ["documented", "tried", "verified"];
|
|
100
|
+
|
|
72
101
|
/** The `init` answers, as flags name them, with what each one asks. */
|
|
73
102
|
export const QUESTIONS = [
|
|
74
103
|
{ key: "tag", flag: "--tag <vX>", ask: "Agent-kit tag to adopt (for example v1.0.0)" },
|
|
@@ -92,7 +121,7 @@ export const QUESTIONS = [
|
|
|
92
121
|
{
|
|
93
122
|
key: "preset",
|
|
94
123
|
flag: "--preset <name|none>",
|
|
95
|
-
ask: "setup_commands preset (python, node, mixed,
|
|
124
|
+
ask: "setup_commands preset (python, node, mixed, or none)",
|
|
96
125
|
only: ["pipeline", "review-response"],
|
|
97
126
|
},
|
|
98
127
|
{
|
|
@@ -101,10 +130,15 @@ export const QUESTIONS = [
|
|
|
101
130
|
ask: "Folder for the Threat pack",
|
|
102
131
|
only: ["audit"],
|
|
103
132
|
},
|
|
133
|
+
{ key: "harness", flag: "--harness <name>", ask: "Harness for every Stage" },
|
|
104
134
|
];
|
|
105
135
|
|
|
106
136
|
/** Answers with a default: asked about only on a terminal, never required. */
|
|
107
|
-
const DEFAULTS = {
|
|
137
|
+
const DEFAULTS = {
|
|
138
|
+
preset: "none",
|
|
139
|
+
threatPackDir: DEFAULT_THREAT_PACK_DIR,
|
|
140
|
+
harness: DEFAULT_HARNESS,
|
|
141
|
+
};
|
|
108
142
|
|
|
109
143
|
const split = (s) =>
|
|
110
144
|
String(s)
|
|
@@ -179,6 +213,18 @@ export function parseAnswer(key, raw, { prompted = false } = {}) {
|
|
|
179
213
|
}
|
|
180
214
|
return { value: dir };
|
|
181
215
|
}
|
|
216
|
+
case "harness":
|
|
217
|
+
// Which names exist is the tag's to say, so planInit checks that.
|
|
218
|
+
if (s.startsWith("custom:")) {
|
|
219
|
+
return {
|
|
220
|
+
error:
|
|
221
|
+
"--harness takes a built-in harness. A Custom harness is a file you write " +
|
|
222
|
+
`deliberately, so init does not set one up: see ${CUSTOM_DOCS_URL}`,
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
return HARNESS_NAME.test(s)
|
|
226
|
+
? { value: s }
|
|
227
|
+
: { error: `--harness takes a harness name, got ${JSON.stringify(s)}` };
|
|
182
228
|
default:
|
|
183
229
|
throw new Error(`unknown answer ${key}`);
|
|
184
230
|
}
|
|
@@ -248,6 +294,65 @@ function tagText(snap, path) {
|
|
|
248
294
|
return text;
|
|
249
295
|
}
|
|
250
296
|
|
|
297
|
+
/**
|
|
298
|
+
* A preset's Caller inputs (ADRs 0029 and 0047): its script as
|
|
299
|
+
* `setup_commands`, and the `sandbox_image`, `setup_registries` and, where it
|
|
300
|
+
* names any, `setup_paths` its header names, which are taken out of the
|
|
301
|
+
* script. An older tag's preset names no image or registries: null.
|
|
302
|
+
* @returns {{ script: string, sandbox: { image: string, registries: string[], paths: string[] } | null }}
|
|
303
|
+
*/
|
|
304
|
+
function presetParts(text) {
|
|
305
|
+
const named = (input) => new RegExp(`^# ${input}:(.*)\n`, "m");
|
|
306
|
+
const image = named("sandbox_image").exec(text);
|
|
307
|
+
const registries = named("setup_registries").exec(text);
|
|
308
|
+
if (!image || !registries) return { script: text, sandbox: null };
|
|
309
|
+
const paths = named("setup_paths").exec(text);
|
|
310
|
+
return {
|
|
311
|
+
script: text
|
|
312
|
+
.replace(named("sandbox_image"), "")
|
|
313
|
+
.replace(named("setup_registries"), "")
|
|
314
|
+
.replace(named("setup_paths"), ""),
|
|
315
|
+
sandbox: {
|
|
316
|
+
image: image[1].trim(),
|
|
317
|
+
registries: registries[1].split(/\s+/).filter(Boolean),
|
|
318
|
+
paths: paths ? paths[1].split(/\s+/).filter(Boolean) : [],
|
|
319
|
+
},
|
|
320
|
+
};
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
/**
|
|
324
|
+
* The Caller with the preset's `sandbox_image`, `setup_registries` and any
|
|
325
|
+
* `setup_paths` before its `setup_commands`: the implement Stage's Caller and
|
|
326
|
+
* the Review response's both take them.
|
|
327
|
+
*/
|
|
328
|
+
function withSandbox(text, sandbox, { preset, tag }) {
|
|
329
|
+
const { image, registries, paths } = sandbox;
|
|
330
|
+
// The values go into YAML as written, so their shape is checked.
|
|
331
|
+
const plain = /^[A-Za-z0-9._/:@-]*$/;
|
|
332
|
+
if (![image, ...registries].every((value) => plain.test(value))) {
|
|
333
|
+
throw new Refusal(
|
|
334
|
+
`examples/setup-presets/${preset}.sh at ${tag} names a sandbox_image or setup_registries that cannot be written into the Caller.`,
|
|
335
|
+
);
|
|
336
|
+
}
|
|
337
|
+
if (!paths.every((path) => /^(\/[A-Za-z0-9._@+-]+)+$/.test(path))) {
|
|
338
|
+
throw new Refusal(
|
|
339
|
+
`examples/setup-presets/${preset}.sh at ${tag} names setup_paths that cannot be written into the Caller.`,
|
|
340
|
+
);
|
|
341
|
+
}
|
|
342
|
+
return text.replace(/^( *)setup_commands: \|$/m, (line, indent) =>
|
|
343
|
+
[
|
|
344
|
+
`${indent}sandbox_image: "${image}"`,
|
|
345
|
+
...(registries.length
|
|
346
|
+
? [`${indent}setup_registries: |`, ...registries.map((host) => `${indent} ${host}`)]
|
|
347
|
+
: [`${indent}setup_registries: ""`]),
|
|
348
|
+
...(paths.length
|
|
349
|
+
? [`${indent}setup_paths: |`, ...paths.map((path) => `${indent} ${path}`)]
|
|
350
|
+
: []),
|
|
351
|
+
line,
|
|
352
|
+
].join("\n"),
|
|
353
|
+
);
|
|
354
|
+
}
|
|
355
|
+
|
|
251
356
|
function presetText(snap, name) {
|
|
252
357
|
const path = `examples/setup-presets/${name}.sh`;
|
|
253
358
|
const text = tagText(snap, path);
|
|
@@ -273,6 +378,153 @@ function presetText(snap, name) {
|
|
|
273
378
|
return text;
|
|
274
379
|
}
|
|
275
380
|
|
|
381
|
+
/** A line of text that prints as one line, as it is. */
|
|
382
|
+
const isLine = (v) => typeof v === "string" && v !== "" && !/[\p{Cc}\p{Zl}\p{Zp}]/u.test(v);
|
|
383
|
+
|
|
384
|
+
/** Whether init can go by a harness's entry, and print its text as it is. */
|
|
385
|
+
const readable = (h) =>
|
|
386
|
+
isLine(h?.displayName) &&
|
|
387
|
+
// It starts a printed line, which must not look like a `$` command.
|
|
388
|
+
/^[\p{L}\p{N}]/u.test(h.displayName) &&
|
|
389
|
+
Array.isArray(h.secrets) &&
|
|
390
|
+
h.secrets.length > 0 &&
|
|
391
|
+
h.secrets.every(
|
|
392
|
+
(x) => typeof x?.name === "string" && SECRET_INPUT.test(x.name) && isLine(x.whereToGet),
|
|
393
|
+
) &&
|
|
394
|
+
typeof h.supportLevels === "object" &&
|
|
395
|
+
h.supportLevels !== null;
|
|
396
|
+
|
|
397
|
+
/**
|
|
398
|
+
* The harnesses in the tag's `cli/harnesses.json`, or null for a tag from
|
|
399
|
+
* before it. The tag's file, never the installed CLI's adapters; its shape
|
|
400
|
+
* only grows, so fields this CLI does not know are ignored.
|
|
401
|
+
*/
|
|
402
|
+
function tagHarnesses(snap) {
|
|
403
|
+
const text = tagText(snap, HARNESS_FILE);
|
|
404
|
+
if (text === null) return null;
|
|
405
|
+
let harnesses;
|
|
406
|
+
try {
|
|
407
|
+
harnesses = JSON.parse(text)?.harnesses;
|
|
408
|
+
} catch {
|
|
409
|
+
// Refused below, with every other shape this CLI cannot read.
|
|
410
|
+
}
|
|
411
|
+
if (
|
|
412
|
+
!harnesses ||
|
|
413
|
+
!Object.hasOwn(harnesses, DEFAULT_HARNESS) ||
|
|
414
|
+
!Object.keys(harnesses).every((name) => HARNESS_NAME.test(name))
|
|
415
|
+
) {
|
|
416
|
+
throw unreadableHarnesses(snap);
|
|
417
|
+
}
|
|
418
|
+
return harnesses;
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
const unreadableHarnesses = (snap) =>
|
|
422
|
+
new Refusal(`${HARNESS_FILE} at ${snap.tag} is not a harness list this CLI can read.`);
|
|
423
|
+
|
|
424
|
+
/**
|
|
425
|
+
* Why `stage` cannot run on `harness` at `tag`, as sentences, or null if it
|
|
426
|
+
* can. `fallback` is the default harness, which the Stage would stay on.
|
|
427
|
+
*/
|
|
428
|
+
function cannotRun(harness, fallback, stage, tag) {
|
|
429
|
+
const { level, wired } = harness.supportLevels[stage] ?? {};
|
|
430
|
+
const name = harness.displayName;
|
|
431
|
+
if (!LEVELS.includes(level)) {
|
|
432
|
+
return `${name} has no Support Level for it at ${tag}, so it cannot run there.`;
|
|
433
|
+
}
|
|
434
|
+
// A tag whose file does not say is judged by the Support Level alone.
|
|
435
|
+
if (wired !== undefined && wired !== true) return `${tag} does not run it on ${name} yet.`;
|
|
436
|
+
if (level !== "documented" || !SECURITY_STAGES.has(stage)) return null;
|
|
437
|
+
const why = `${name} is at Support Level documented on it, and a security Stage needs tried.`;
|
|
438
|
+
// The default harness may sit below the same bar; do not imply it meets it.
|
|
439
|
+
return fallback.supportLevels[stage]?.level === "documented"
|
|
440
|
+
? `${why} ${fallback.displayName} is documented on it too, and runs it as the default harness.`
|
|
441
|
+
: why;
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
/**
|
|
445
|
+
* What the chosen harness means for the chosen flows: the Stages kept on
|
|
446
|
+
* claude-code, and the harnesses a Stage then runs on. Null for a tag with no
|
|
447
|
+
* `cli/harnesses.json`, which takes claude-code only.
|
|
448
|
+
*/
|
|
449
|
+
function planHarness(snap, { harness: chosen = DEFAULT_HARNESS, flows }) {
|
|
450
|
+
const harnesses = tagHarnesses(snap);
|
|
451
|
+
if (harnesses === null) {
|
|
452
|
+
if (chosen === DEFAULT_HARNESS) return null;
|
|
453
|
+
throw new Refusal(
|
|
454
|
+
`${snap.tag} has no ${HARNESS_FILE}: it predates harness choice, so init accepts only ` +
|
|
455
|
+
`${DEFAULT_HARNESS} with it. Harness choice starts with ${FIRST_HARNESS_TAG}.`,
|
|
456
|
+
);
|
|
457
|
+
}
|
|
458
|
+
if (!Object.hasOwn(harnesses, chosen)) {
|
|
459
|
+
throw new Refusal(
|
|
460
|
+
`${snap.tag} has no harness ${JSON.stringify(chosen)}; it has: ` +
|
|
461
|
+
`${Object.keys(harnesses).join(", ")}.`,
|
|
462
|
+
);
|
|
463
|
+
}
|
|
464
|
+
const fallback = harnesses[DEFAULT_HARNESS];
|
|
465
|
+
if (![harnesses[chosen], fallback].every(readable)) throw unreadableHarnesses(snap);
|
|
466
|
+
const stages = flows.flatMap((flow) => FLOW_STAGES[flow]);
|
|
467
|
+
const pins =
|
|
468
|
+
chosen === DEFAULT_HARNESS
|
|
469
|
+
? []
|
|
470
|
+
: stages.flatMap((stage) => {
|
|
471
|
+
const why = cannotRun(harnesses[chosen], fallback, stage, snap.tag);
|
|
472
|
+
if (!why) return [];
|
|
473
|
+
return [
|
|
474
|
+
{ stage, reason: `${STAGE_NAMES[stage]} stays on ${fallback.displayName}: ${why}` },
|
|
475
|
+
];
|
|
476
|
+
});
|
|
477
|
+
const used = [
|
|
478
|
+
...(pins.length < stages.length ? [chosen] : []),
|
|
479
|
+
...(pins.length ? [DEFAULT_HARNESS] : []),
|
|
480
|
+
];
|
|
481
|
+
return { chosen, pins, used: used.map((name) => harnesses[name]) };
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
/**
|
|
485
|
+
* The secrets of a harness a new Consumer's run reads. A harness's secrets are
|
|
486
|
+
* alternatives, but where each names a `provider` (opencode's), a run reads
|
|
487
|
+
* only the one its model's `provider/model` names, and no model variable is
|
|
488
|
+
* set yet: the default model's.
|
|
489
|
+
*/
|
|
490
|
+
function readBy({ secrets, defaultModel }) {
|
|
491
|
+
const provider = isLine(defaultModel) ? /^([^/]+)\/./.exec(defaultModel)?.[1] : undefined;
|
|
492
|
+
const matched = secrets.filter((s) => provider !== undefined && s.provider === provider);
|
|
493
|
+
return matched.length ? { secrets: matched, model: defaultModel } : { secrets };
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
/**
|
|
497
|
+
* The Secrets step's lines for one harness: its preferred credential and the
|
|
498
|
+
* alternatives, each under the repository secret the written Callers pass.
|
|
499
|
+
* Where the model picks the credential, the default model's alone.
|
|
500
|
+
*/
|
|
501
|
+
function secretLines(harness, callers) {
|
|
502
|
+
const { displayName } = harness;
|
|
503
|
+
const { secrets, model } = readBy(harness);
|
|
504
|
+
const passed = secrets.flatMap(({ name, whereToGet }) => {
|
|
505
|
+
const read = new RegExp(`^\\s*${name}:\\s*\\$\\{\\{\\s*secrets\\.([A-Za-z_]\\w*)`, "m");
|
|
506
|
+
const secret = read.exec(callers)?.[1];
|
|
507
|
+
return secret ? [{ secret, whereToGet }] : [];
|
|
508
|
+
});
|
|
509
|
+
// Callers that pass none of them: name each secret after its input.
|
|
510
|
+
const offered = passed.length
|
|
511
|
+
? passed
|
|
512
|
+
: secrets.map(({ name, whereToGet }) => ({ secret: name.toUpperCase(), whereToGet }));
|
|
513
|
+
const [preferred, ...others] = offered;
|
|
514
|
+
return [
|
|
515
|
+
{ note: `${displayName}, ${preferred.secret}: ${preferred.whereToGet}` },
|
|
516
|
+
command("gh", "secret", "set", preferred.secret),
|
|
517
|
+
...others.map((x) => ({ note: ` or set ${x.secret} instead: ${x.whereToGet}` })),
|
|
518
|
+
...(model === undefined
|
|
519
|
+
? []
|
|
520
|
+
: [
|
|
521
|
+
{
|
|
522
|
+
note: ` Its default model is ${model}. For another provider's model, set AGENT_KIT_MODEL to it, as provider/model, and set that provider's secret instead.`,
|
|
523
|
+
},
|
|
524
|
+
]),
|
|
525
|
+
];
|
|
526
|
+
}
|
|
527
|
+
|
|
276
528
|
/**
|
|
277
529
|
* Work out everything init would write and throw Refusal for anything that
|
|
278
530
|
* stops it. Touches nothing on disk.
|
|
@@ -334,12 +586,15 @@ export function planInit({ runner, root, snap, answers, force }) {
|
|
|
334
586
|
);
|
|
335
587
|
}
|
|
336
588
|
|
|
589
|
+
const harness = planHarness(snap, answers);
|
|
590
|
+
|
|
591
|
+
const preset = answers.preset ? presetParts(presetText(snap, answers.preset)) : null;
|
|
337
592
|
const values = {
|
|
338
593
|
actors: answers.actors,
|
|
339
594
|
tag,
|
|
340
595
|
defaultBranch: answers.defaultBranch,
|
|
341
596
|
verify: answers.verify ?? "",
|
|
342
|
-
preset:
|
|
597
|
+
preset: preset?.script ?? null,
|
|
343
598
|
threatPackDir: dir,
|
|
344
599
|
};
|
|
345
600
|
for (const flow of answers.flows) {
|
|
@@ -353,6 +608,9 @@ export function planInit({ runner, root, snap, answers, force }) {
|
|
|
353
608
|
if (err instanceof TemplateError) throw new Refusal(err.message);
|
|
354
609
|
throw err;
|
|
355
610
|
}
|
|
611
|
+
if ((flow === "pipeline" || flow === "review-response") && preset?.sandbox) {
|
|
612
|
+
rendered = withSandbox(rendered, preset.sandbox, { preset: answers.preset, tag });
|
|
613
|
+
}
|
|
356
614
|
if (fileTarget(caller, "Caller")) {
|
|
357
615
|
conflicts.push(`${caller} (Caller)`);
|
|
358
616
|
overwrites.push(caller);
|
|
@@ -415,28 +673,74 @@ export function planInit({ runner, root, snap, answers, force }) {
|
|
|
415
673
|
const { changed: dirty, ignored } = replaced.length
|
|
416
674
|
? uncommittedChanges({ runner, root, paths: replaced })
|
|
417
675
|
: { changed: [], ignored: [] };
|
|
418
|
-
return { deletes, writes, conflicts, notes, dependabot, dirty, ignored, unchanged };
|
|
676
|
+
return { deletes, writes, conflicts, notes, dependabot, dirty, ignored, unchanged, harness };
|
|
677
|
+
}
|
|
678
|
+
|
|
679
|
+
/**
|
|
680
|
+
* The variable the written Callers read for `name`: an older tag's Callers read
|
|
681
|
+
* the name it replaced, and setting the newer one would turn nothing on.
|
|
682
|
+
*/
|
|
683
|
+
function variableRead(name, callers) {
|
|
684
|
+
const reads = (n) => new RegExp(`\\bvars\\.${n}\\b`).test(callers);
|
|
685
|
+
if (reads(name)) return name;
|
|
686
|
+
const old = Object.keys(RENAMED_VARIABLES).find((n) => RENAMED_VARIABLES[n] === name && reads(n));
|
|
687
|
+
return old ?? name;
|
|
419
688
|
}
|
|
420
689
|
|
|
421
690
|
/**
|
|
422
691
|
* The GitHub-side steps init does not take, as POSIX-shell commands built
|
|
423
692
|
* with checks/result.mjs `command()` (every argument fixed or allowlisted).
|
|
693
|
+
* `harness` is planInit's, or null for a tag without cli/harnesses.json.
|
|
424
694
|
*/
|
|
425
|
-
export function manualSteps({ flows, tag, kitRepo, serverUrl }) {
|
|
695
|
+
export function manualSteps({ flows, tag, kitRepo, serverUrl, callers = "", harness = null }) {
|
|
426
696
|
const pipeline = flows.includes("pipeline");
|
|
427
697
|
const audit = flows.includes("audit");
|
|
428
698
|
const response = flows.includes("review-response");
|
|
429
699
|
const lines = [];
|
|
430
700
|
let n = 0;
|
|
701
|
+
// A command prints after `$`; a `{ note }` prints as text between commands.
|
|
431
702
|
const step = (title, ...cmds) => {
|
|
432
703
|
lines.push(`${++n}. ${title}`);
|
|
433
|
-
for (const c of cmds) lines.push(` $ ${c}`);
|
|
704
|
+
for (const c of cmds) lines.push(typeof c === "string" ? ` $ ${c}` : ` ${c.note}`);
|
|
434
705
|
};
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
)
|
|
706
|
+
// Offered only when the Callers pass it; an older tag's do not.
|
|
707
|
+
const apiKey = /\bsecrets\.ANTHROPIC_API_KEY\b/.test(callers)
|
|
708
|
+
? ", or set ANTHROPIC_API_KEY instead"
|
|
709
|
+
: "";
|
|
710
|
+
const setVariable = (name, value) =>
|
|
711
|
+
command("gh", "variable", "set", variableRead(name, callers), "--body", value);
|
|
712
|
+
if (harness && harness.chosen !== DEFAULT_HARNESS) {
|
|
713
|
+
step(
|
|
714
|
+
`Harness (repository variables; unset is ${DEFAULT_HARNESS}):`,
|
|
715
|
+
{
|
|
716
|
+
note:
|
|
717
|
+
"AGENT_KIT_HARNESS applies to every Stage of every Caller, the Deep scan and flows " +
|
|
718
|
+
"you add later included; the pins here cover only the flows of this run.",
|
|
719
|
+
},
|
|
720
|
+
setVariable("AGENT_KIT_HARNESS", harness.chosen),
|
|
721
|
+
...harness.pins.flatMap(({ stage, reason }) => [
|
|
722
|
+
{ note: reason },
|
|
723
|
+
setVariable(
|
|
724
|
+
`AGENT_KIT_${stage.toUpperCase().replaceAll("-", "_")}_HARNESS`,
|
|
725
|
+
DEFAULT_HARNESS,
|
|
726
|
+
),
|
|
727
|
+
]),
|
|
728
|
+
);
|
|
729
|
+
}
|
|
730
|
+
const advisories = audit ? [command("gh", "secret", "set", "AGENT_KIT_ADVISORIES_TOKEN")] : [];
|
|
731
|
+
if (harness) {
|
|
732
|
+
step(
|
|
733
|
+
"Secrets (gh asks for each value):",
|
|
734
|
+
...harness.used.flatMap((h) => secretLines(h, callers)),
|
|
735
|
+
...advisories,
|
|
736
|
+
);
|
|
737
|
+
} else {
|
|
738
|
+
step(
|
|
739
|
+
`Secrets (gh asks for each value; CLAUDE_CODE_OAUTH_TOKEN comes from \`claude setup-token\`${apiKey}):`,
|
|
740
|
+
command("gh", "secret", "set", "CLAUDE_CODE_OAUTH_TOKEN"),
|
|
741
|
+
...advisories,
|
|
742
|
+
);
|
|
743
|
+
}
|
|
440
744
|
const labels = [...(pipeline ? LABELS : []), ...(response ? [RESPONSE_LABEL] : [])];
|
|
441
745
|
if (labels.length) {
|
|
442
746
|
step(
|
|
@@ -449,29 +753,36 @@ export function manualSteps({ flows, tag, kitRepo, serverUrl }) {
|
|
|
449
753
|
if (pipeline) {
|
|
450
754
|
step("Install the Claude GitHub App on this repository: https://github.com/apps/claude");
|
|
451
755
|
}
|
|
756
|
+
// Offered only where a Caller names it: an older tag's workflows take none.
|
|
757
|
+
if ((pipeline || response) && /\bAGENT_KIT_APP_ID\b/.test(callers)) {
|
|
758
|
+
step(
|
|
759
|
+
"Optional, your own GitHub App, so CI starts on agent pushes with no approval (skip it " +
|
|
760
|
+
"to use the job token and ci_workflow): create an App with Contents and Pull requests: " +
|
|
761
|
+
"read and write (https://github.com/settings/apps/new), install it on this repository, " +
|
|
762
|
+
"uncomment app_id and app_private_key in the Callers, then set both (one without the " +
|
|
763
|
+
"other fails the run):",
|
|
764
|
+
command("gh", "variable", "set", "AGENT_KIT_APP_ID"),
|
|
765
|
+
command("gh", "secret", "set", "AGENT_KIT_APP_PRIVATE_KEY"),
|
|
766
|
+
{ note: "The secret is a file: append < path/to/your-app.private-key.pem to that command." },
|
|
767
|
+
);
|
|
768
|
+
}
|
|
452
769
|
step(
|
|
453
|
-
"Rulesets
|
|
770
|
+
"Rulesets no GitHub App can bypass: list yours, then follow " +
|
|
454
771
|
`${serverUrl}/${kitRepo}/blob/${tag}/docs/repository-hardening.md`,
|
|
455
772
|
command("gh", "api", "repos/{owner}/{repo}/rulesets"),
|
|
456
773
|
);
|
|
457
774
|
step(
|
|
458
775
|
"Last, after you have reviewed and pushed the Callers, turn the flows on (Kill switch variables):",
|
|
459
|
-
...(pipeline
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
...(audit
|
|
463
|
-
? [command("gh", "variable", "set", "CLAUDE_SECURITY_AUDIT_ENABLED", "--body", "true")]
|
|
464
|
-
: []),
|
|
465
|
-
...(response
|
|
466
|
-
? [command("gh", "variable", "set", "CLAUDE_REVIEW_RESPONSE_ENABLED", "--body", "true")]
|
|
467
|
-
: []),
|
|
776
|
+
...(pipeline ? [setVariable("AGENT_KIT_AGENT_FLOW_ENABLED", "true")] : []),
|
|
777
|
+
...(audit ? [setVariable("AGENT_KIT_SECURITY_AUDIT_ENABLED", "true")] : []),
|
|
778
|
+
...(response ? [setVariable("AGENT_KIT_REVIEW_RESPONSE_ENABLED", "true")] : []),
|
|
468
779
|
);
|
|
469
780
|
if (response) {
|
|
470
781
|
step(
|
|
471
782
|
"Optional, Review response auto mode (a finished review starts a round): first give your " +
|
|
472
783
|
"review Caller response_mode and response_workflow, as " +
|
|
473
784
|
`${serverUrl}/${kitRepo}/blob/${tag}/docs/review-response.md#auto-mode says, then:`,
|
|
474
|
-
|
|
785
|
+
setVariable("AGENT_KIT_REVIEW_RESPONSE_MODE", "auto"),
|
|
475
786
|
);
|
|
476
787
|
}
|
|
477
788
|
return lines;
|
|
@@ -637,6 +948,11 @@ export async function runInit({
|
|
|
637
948
|
tag: answers.tag,
|
|
638
949
|
kitRepo: DEFAULT_KIT_REPO,
|
|
639
950
|
serverUrl,
|
|
951
|
+
harness: plan.harness,
|
|
952
|
+
callers: answers.flows
|
|
953
|
+
.map((flow) => FLOWS[flow].caller)
|
|
954
|
+
.map((path) => plan.writes.find((w) => w.path === path).bytes.toString("utf8"))
|
|
955
|
+
.join("\n"),
|
|
640
956
|
})) {
|
|
641
957
|
out(line);
|
|
642
958
|
}
|