@mnaimfaizy/agent-kit 1.0.0-beta.14 → 1.0.0-beta.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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 +583 -36
- 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 +166 -5
- package/src/exec.mjs +14 -5
- package/src/factory/budget/budget.mjs +259 -0
- package/src/factory/build/command.mjs +321 -0
- package/src/factory/build/factory.mjs +473 -0
- package/src/factory/build/findings.mjs +55 -0
- package/src/factory/build/host.mjs +230 -0
- package/src/factory/build/notes.mjs +191 -0
- package/src/factory/build/pull-request.mjs +74 -0
- package/src/factory/bundle.mjs +146 -0
- package/src/factory/checks/allowed-paths.mjs +50 -0
- package/src/factory/checks/plan-header.mjs +296 -0
- package/src/factory/checks/qa.mjs +85 -0
- package/src/factory/checks/review.mjs +73 -0
- package/src/factory/checks/security.mjs +50 -0
- package/src/factory/checks/stage-check.mjs +89 -0
- package/src/factory/claims/command.mjs +187 -0
- package/src/factory/claims/release.mjs +111 -0
- package/src/factory/decision/answers.mjs +103 -0
- package/src/factory/decision/command.mjs +64 -0
- package/src/factory/decision/plan.mjs +99 -0
- package/src/factory/decision/request.mjs +116 -0
- package/src/factory/doctor/files.mjs +329 -0
- package/src/factory/doctor/index.mjs +56 -0
- package/src/factory/doctor/local.mjs +497 -0
- package/src/factory/doctor/orchestrate.mjs +146 -0
- package/src/factory/engine/lease.mjs +146 -0
- package/src/factory/engine/local-engine.mjs +177 -0
- package/src/factory/engine/lockfile.mjs +64 -0
- package/src/factory/engine/workflow-engine.mjs +124 -0
- package/src/factory/gate/comment.mjs +88 -0
- package/src/factory/gate/config.mjs +57 -0
- package/src/factory/gate/gate-core.mjs +250 -0
- package/src/factory/gate/guarded.mjs +17 -0
- package/src/factory/gate/reads.mjs +105 -0
- package/src/factory/gate/task.mjs +193 -0
- package/src/factory/gate/trip-reads.mjs +82 -0
- package/src/factory/gate/trip.mjs +87 -0
- package/src/factory/init/blueprint.mjs +174 -0
- package/src/factory/init/index.mjs +337 -0
- package/src/factory/labels/evidence.mjs +162 -0
- package/src/factory/labels/moves.mjs +32 -0
- package/src/factory/labels/reconcile.mjs +267 -0
- package/src/factory/labels/revert.mjs +87 -0
- package/src/factory/labels/timeline.mjs +72 -0
- package/src/factory/labels/voided.mjs +59 -0
- package/src/factory/limits/harness.mjs +39 -0
- package/src/factory/limits/limits.mjs +123 -0
- package/src/factory/merge/command.mjs +172 -0
- package/src/factory/outbox/check.mjs +240 -0
- package/src/factory/outbox/rulings.mjs +195 -0
- package/src/factory/plan/command.mjs +66 -0
- package/src/factory/plan/comment.mjs +156 -0
- package/src/factory/plan/publish.mjs +149 -0
- package/src/factory/plan/risk.mjs +153 -0
- package/src/factory/qa/command.mjs +163 -0
- package/src/factory/records/engine-record.mjs +133 -0
- package/src/factory/records/main.mjs +96 -0
- package/src/factory/records/record.mjs +226 -0
- package/src/factory/records/sink.mjs +57 -0
- package/src/factory/report/build.mjs +92 -0
- package/src/factory/report/command.mjs +80 -0
- package/src/factory/report/facts.mjs +226 -0
- package/src/factory/report/gate-section.mjs +122 -0
- package/src/factory/report/metrics.mjs +111 -0
- package/src/factory/report/reads.mjs +246 -0
- package/src/factory/report/render.mjs +121 -0
- package/src/factory/report/rollout.mjs +154 -0
- package/src/factory/review/command.mjs +182 -0
- package/src/factory/run/awake.mjs +70 -0
- package/src/factory/run/collect.mjs +77 -0
- package/src/factory/run/command.mjs +490 -0
- package/src/factory/run/gh.mjs +46 -0
- package/src/factory/run/launch.mjs +47 -0
- package/src/factory/run/pipelines.mjs +261 -0
- package/src/factory/run/raw.mjs +96 -0
- package/src/factory/run/restart.mjs +83 -0
- package/src/factory/run/s3.mjs +193 -0
- package/src/factory/run/secrets.mjs +142 -0
- package/src/factory/run/teardown.mjs +242 -0
- package/src/factory/run/token.mjs +68 -0
- package/src/factory/security/command.mjs +157 -0
- package/src/factory/setup/app.mjs +122 -0
- package/src/factory/setup/command.mjs +409 -0
- package/src/factory/setup/labels.mjs +25 -0
- package/src/factory/setup/reads.mjs +129 -0
- package/src/factory/setup/writes.mjs +126 -0
- package/src/factory/snapshot/write.mjs +176 -0
- package/src/factory/stop/command.mjs +136 -0
- package/src/factory/sweep/actions-main.mjs +117 -0
- package/src/factory/sweep/command.mjs +65 -0
- package/src/factory/sweep/knobs.mjs +78 -0
- package/src/factory/sweep/marker-version.mjs +15 -0
- package/src/factory/sweep/markers.mjs +112 -0
- package/src/factory/sweep/overlap.mjs +24 -0
- package/src/factory/sweep/run.mjs +198 -0
- package/src/factory/sweep/shell.mjs +394 -0
- package/src/factory/sweep/split.mjs +104 -0
- package/src/factory/sweep/states.mjs +87 -0
- package/src/factory/sweep/sweep-core.mjs +1781 -0
- package/src/factory/tracker/github.mjs +674 -0
- package/src/factory/tracker/operations.mjs +153 -0
- package/src/factory/upgrade/index.mjs +83 -0
- 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 +374 -36
- package/src/kit-owned-paths.mjs +1 -1
- 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 +1087 -0
- package/src/upgrade.mjs +39 -7
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.
|
|
@@ -27,8 +29,9 @@ import {
|
|
|
27
29
|
stageFileModes,
|
|
28
30
|
uncommittedChanges,
|
|
29
31
|
} from "./local-writes.mjs";
|
|
32
|
+
import { runFactoryInit } from "./factory/init/index.mjs";
|
|
30
33
|
import { caseCollisions, checkSafePath, fileDirConflicts } from "./safe-paths.mjs";
|
|
31
|
-
import { isReleaseTag } from "./tags.mjs";
|
|
34
|
+
import { CLI_VERSION, isReleaseTag } from "./tags.mjs";
|
|
32
35
|
import {
|
|
33
36
|
DEFAULT_THREAT_PACK_DIR,
|
|
34
37
|
FLOWS,
|
|
@@ -70,6 +73,32 @@ const RESPONSE_LABEL = [
|
|
|
70
73
|
"Agent-kit: answer the review on this PR",
|
|
71
74
|
];
|
|
72
75
|
|
|
76
|
+
const DEFAULT_HARNESS = "claude-code";
|
|
77
|
+
const HARNESS_NAME = /^[a-z][a-z0-9-]*$/;
|
|
78
|
+
const SECRET_INPUT = /^[a-z][a-z0-9_]*$/;
|
|
79
|
+
const HARNESS_FILE = "cli/harnesses.json";
|
|
80
|
+
/** The first tag that ships `cli/harnesses.json`: older ones run claude-code alone. */
|
|
81
|
+
const FIRST_HARNESS_TAG = "v1.0.0-beta.14"; // release:history
|
|
82
|
+
/** The page that describes the Custom harness file. */
|
|
83
|
+
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`;
|
|
84
|
+
|
|
85
|
+
/** The Stages each flow runs, and how a reason names each one. */
|
|
86
|
+
const FLOW_STAGES = {
|
|
87
|
+
pipeline: ["plan", "implement", "review"],
|
|
88
|
+
audit: ["security-audit"],
|
|
89
|
+
"review-response": ["review-response"],
|
|
90
|
+
};
|
|
91
|
+
const STAGE_NAMES = {
|
|
92
|
+
plan: "plan",
|
|
93
|
+
implement: "implement",
|
|
94
|
+
review: "review",
|
|
95
|
+
"security-audit": "static security audit",
|
|
96
|
+
"review-response": "Review response",
|
|
97
|
+
};
|
|
98
|
+
/** The Stages that need a pair at `tried` or above (ADR 0028). */
|
|
99
|
+
const SECURITY_STAGES = new Set(["security-audit"]);
|
|
100
|
+
const LEVELS = ["documented", "tried", "verified"];
|
|
101
|
+
|
|
73
102
|
/** The `init` answers, as flags name them, with what each one asks. */
|
|
74
103
|
export const QUESTIONS = [
|
|
75
104
|
{ key: "tag", flag: "--tag <vX>", ask: "Agent-kit tag to adopt (for example v1.0.0)" },
|
|
@@ -93,7 +122,7 @@ export const QUESTIONS = [
|
|
|
93
122
|
{
|
|
94
123
|
key: "preset",
|
|
95
124
|
flag: "--preset <name|none>",
|
|
96
|
-
ask: "setup_commands preset (python, node, mixed,
|
|
125
|
+
ask: "setup_commands preset (python, node, mixed, or none)",
|
|
97
126
|
only: ["pipeline", "review-response"],
|
|
98
127
|
},
|
|
99
128
|
{
|
|
@@ -102,10 +131,15 @@ export const QUESTIONS = [
|
|
|
102
131
|
ask: "Folder for the Threat pack",
|
|
103
132
|
only: ["audit"],
|
|
104
133
|
},
|
|
134
|
+
{ key: "harness", flag: "--harness <name>", ask: "Harness for every Stage" },
|
|
105
135
|
];
|
|
106
136
|
|
|
107
137
|
/** Answers with a default: asked about only on a terminal, never required. */
|
|
108
|
-
const DEFAULTS = {
|
|
138
|
+
const DEFAULTS = {
|
|
139
|
+
preset: "none",
|
|
140
|
+
threatPackDir: DEFAULT_THREAT_PACK_DIR,
|
|
141
|
+
harness: DEFAULT_HARNESS,
|
|
142
|
+
};
|
|
109
143
|
|
|
110
144
|
const split = (s) =>
|
|
111
145
|
String(s)
|
|
@@ -180,6 +214,18 @@ export function parseAnswer(key, raw, { prompted = false } = {}) {
|
|
|
180
214
|
}
|
|
181
215
|
return { value: dir };
|
|
182
216
|
}
|
|
217
|
+
case "harness":
|
|
218
|
+
// Which names exist is the tag's to say, so planInit checks that.
|
|
219
|
+
if (s.startsWith("custom:")) {
|
|
220
|
+
return {
|
|
221
|
+
error:
|
|
222
|
+
"--harness takes a built-in harness. A Custom harness is a file you write " +
|
|
223
|
+
`deliberately, so init does not set one up: see ${CUSTOM_DOCS_URL}`,
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
return HARNESS_NAME.test(s)
|
|
227
|
+
? { value: s }
|
|
228
|
+
: { error: `--harness takes a harness name, got ${JSON.stringify(s)}` };
|
|
183
229
|
default:
|
|
184
230
|
throw new Error(`unknown answer ${key}`);
|
|
185
231
|
}
|
|
@@ -249,6 +295,65 @@ function tagText(snap, path) {
|
|
|
249
295
|
return text;
|
|
250
296
|
}
|
|
251
297
|
|
|
298
|
+
/**
|
|
299
|
+
* A preset's Caller inputs (ADRs 0029 and 0047): its script as
|
|
300
|
+
* `setup_commands`, and the `sandbox_image`, `setup_registries` and, where it
|
|
301
|
+
* names any, `setup_paths` its header names, which are taken out of the
|
|
302
|
+
* script. An older tag's preset names no image or registries: null.
|
|
303
|
+
* @returns {{ script: string, sandbox: { image: string, registries: string[], paths: string[] } | null }}
|
|
304
|
+
*/
|
|
305
|
+
function presetParts(text) {
|
|
306
|
+
const named = (input) => new RegExp(`^# ${input}:(.*)\n`, "m");
|
|
307
|
+
const image = named("sandbox_image").exec(text);
|
|
308
|
+
const registries = named("setup_registries").exec(text);
|
|
309
|
+
if (!image || !registries) return { script: text, sandbox: null };
|
|
310
|
+
const paths = named("setup_paths").exec(text);
|
|
311
|
+
return {
|
|
312
|
+
script: text
|
|
313
|
+
.replace(named("sandbox_image"), "")
|
|
314
|
+
.replace(named("setup_registries"), "")
|
|
315
|
+
.replace(named("setup_paths"), ""),
|
|
316
|
+
sandbox: {
|
|
317
|
+
image: image[1].trim(),
|
|
318
|
+
registries: registries[1].split(/\s+/).filter(Boolean),
|
|
319
|
+
paths: paths ? paths[1].split(/\s+/).filter(Boolean) : [],
|
|
320
|
+
},
|
|
321
|
+
};
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
/**
|
|
325
|
+
* The Caller with the preset's `sandbox_image`, `setup_registries` and any
|
|
326
|
+
* `setup_paths` before its `setup_commands`: the implement Stage's Caller and
|
|
327
|
+
* the Review response's both take them.
|
|
328
|
+
*/
|
|
329
|
+
function withSandbox(text, sandbox, { preset, tag }) {
|
|
330
|
+
const { image, registries, paths } = sandbox;
|
|
331
|
+
// The values go into YAML as written, so their shape is checked.
|
|
332
|
+
const plain = /^[A-Za-z0-9._/:@-]*$/;
|
|
333
|
+
if (![image, ...registries].every((value) => plain.test(value))) {
|
|
334
|
+
throw new Refusal(
|
|
335
|
+
`examples/setup-presets/${preset}.sh at ${tag} names a sandbox_image or setup_registries that cannot be written into the Caller.`,
|
|
336
|
+
);
|
|
337
|
+
}
|
|
338
|
+
if (!paths.every((path) => /^(\/[A-Za-z0-9._@+-]+)+$/.test(path))) {
|
|
339
|
+
throw new Refusal(
|
|
340
|
+
`examples/setup-presets/${preset}.sh at ${tag} names setup_paths that cannot be written into the Caller.`,
|
|
341
|
+
);
|
|
342
|
+
}
|
|
343
|
+
return text.replace(/^( *)setup_commands: \|$/m, (line, indent) =>
|
|
344
|
+
[
|
|
345
|
+
`${indent}sandbox_image: "${image}"`,
|
|
346
|
+
...(registries.length
|
|
347
|
+
? [`${indent}setup_registries: |`, ...registries.map((host) => `${indent} ${host}`)]
|
|
348
|
+
: [`${indent}setup_registries: ""`]),
|
|
349
|
+
...(paths.length
|
|
350
|
+
? [`${indent}setup_paths: |`, ...paths.map((path) => `${indent} ${path}`)]
|
|
351
|
+
: []),
|
|
352
|
+
line,
|
|
353
|
+
].join("\n"),
|
|
354
|
+
);
|
|
355
|
+
}
|
|
356
|
+
|
|
252
357
|
function presetText(snap, name) {
|
|
253
358
|
const path = `examples/setup-presets/${name}.sh`;
|
|
254
359
|
const text = tagText(snap, path);
|
|
@@ -274,6 +379,190 @@ function presetText(snap, name) {
|
|
|
274
379
|
return text;
|
|
275
380
|
}
|
|
276
381
|
|
|
382
|
+
/** A line of text that prints as one line, as it is. */
|
|
383
|
+
const isLine = (v) => typeof v === "string" && v !== "" && !/[\p{Cc}\p{Zl}\p{Zp}]/u.test(v);
|
|
384
|
+
|
|
385
|
+
/** Whether init can go by a harness's entry, and print its text as it is. */
|
|
386
|
+
const readable = (h) =>
|
|
387
|
+
isLine(h?.displayName) &&
|
|
388
|
+
// It starts a printed line, which must not look like a `$` command.
|
|
389
|
+
/^[\p{L}\p{N}]/u.test(h.displayName) &&
|
|
390
|
+
Array.isArray(h.secrets) &&
|
|
391
|
+
h.secrets.length > 0 &&
|
|
392
|
+
h.secrets.every(
|
|
393
|
+
(x) => typeof x?.name === "string" && SECRET_INPUT.test(x.name) && isLine(x.whereToGet),
|
|
394
|
+
) &&
|
|
395
|
+
typeof h.supportLevels === "object" &&
|
|
396
|
+
h.supportLevels !== null;
|
|
397
|
+
|
|
398
|
+
/**
|
|
399
|
+
* The harnesses in the tag's `cli/harnesses.json`, or null for a tag from
|
|
400
|
+
* before it. The tag's file, never the installed CLI's adapters; its shape
|
|
401
|
+
* only grows, so fields this CLI does not know are ignored.
|
|
402
|
+
*/
|
|
403
|
+
function tagHarnesses(snap) {
|
|
404
|
+
const text = tagText(snap, HARNESS_FILE);
|
|
405
|
+
if (text === null) return null;
|
|
406
|
+
let harnesses;
|
|
407
|
+
try {
|
|
408
|
+
harnesses = JSON.parse(text)?.harnesses;
|
|
409
|
+
} catch {
|
|
410
|
+
// Refused below, with every other shape this CLI cannot read.
|
|
411
|
+
}
|
|
412
|
+
if (
|
|
413
|
+
!harnesses ||
|
|
414
|
+
!Object.hasOwn(harnesses, DEFAULT_HARNESS) ||
|
|
415
|
+
!Object.keys(harnesses).every((name) => HARNESS_NAME.test(name))
|
|
416
|
+
) {
|
|
417
|
+
throw unreadableHarnesses(snap);
|
|
418
|
+
}
|
|
419
|
+
return harnesses;
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
const unreadableHarnesses = (snap) =>
|
|
423
|
+
new Refusal(`${HARNESS_FILE} at ${snap.tag} is not a harness list this CLI can read.`);
|
|
424
|
+
|
|
425
|
+
/**
|
|
426
|
+
* Why `stage` cannot run on `harness` at `tag`, as sentences, or null if it
|
|
427
|
+
* can. `fallback` is the default harness, which the Stage would stay on.
|
|
428
|
+
*/
|
|
429
|
+
function cannotRun(harness, fallback, stage, tag) {
|
|
430
|
+
const { level, wired } = harness.supportLevels[stage] ?? {};
|
|
431
|
+
const name = harness.displayName;
|
|
432
|
+
if (!LEVELS.includes(level)) {
|
|
433
|
+
return `${name} has no Support Level for it at ${tag}, so it cannot run there.`;
|
|
434
|
+
}
|
|
435
|
+
// A tag whose file does not say is judged by the Support Level alone.
|
|
436
|
+
if (wired !== undefined && wired !== true) return `${tag} does not run it on ${name} yet.`;
|
|
437
|
+
if (level !== "documented" || !SECURITY_STAGES.has(stage)) return null;
|
|
438
|
+
const why = `${name} is at Support Level documented on it, and a security Stage needs tried.`;
|
|
439
|
+
// The default harness may sit below the same bar; do not imply it meets it.
|
|
440
|
+
return fallback.supportLevels[stage]?.level === "documented"
|
|
441
|
+
? `${why} ${fallback.displayName} is documented on it too, and runs it as the default harness.`
|
|
442
|
+
: why;
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
/**
|
|
446
|
+
* What the chosen harness means for the chosen flows: the Stages kept on
|
|
447
|
+
* claude-code, and the harnesses a Stage then runs on. Null for a tag with no
|
|
448
|
+
* `cli/harnesses.json`, which takes claude-code only.
|
|
449
|
+
*/
|
|
450
|
+
function planHarness(snap, { harness: chosen = DEFAULT_HARNESS, flows }) {
|
|
451
|
+
const harnesses = tagHarnesses(snap);
|
|
452
|
+
if (harnesses === null) {
|
|
453
|
+
if (chosen === DEFAULT_HARNESS) return null;
|
|
454
|
+
throw new Refusal(
|
|
455
|
+
`${snap.tag} has no ${HARNESS_FILE}: it predates harness choice, so init accepts only ` +
|
|
456
|
+
`${DEFAULT_HARNESS} with it. Harness choice starts with ${FIRST_HARNESS_TAG}.`,
|
|
457
|
+
);
|
|
458
|
+
}
|
|
459
|
+
if (!Object.hasOwn(harnesses, chosen)) {
|
|
460
|
+
throw new Refusal(
|
|
461
|
+
`${snap.tag} has no harness ${JSON.stringify(chosen)}; it has: ` +
|
|
462
|
+
`${Object.keys(harnesses).join(", ")}.`,
|
|
463
|
+
);
|
|
464
|
+
}
|
|
465
|
+
const fallback = harnesses[DEFAULT_HARNESS];
|
|
466
|
+
if (![harnesses[chosen], fallback].every(readable)) throw unreadableHarnesses(snap);
|
|
467
|
+
const stages = flows.flatMap((flow) => FLOW_STAGES[flow]);
|
|
468
|
+
const pins =
|
|
469
|
+
chosen === DEFAULT_HARNESS
|
|
470
|
+
? []
|
|
471
|
+
: stages.flatMap((stage) => {
|
|
472
|
+
const why = cannotRun(harnesses[chosen], fallback, stage, snap.tag);
|
|
473
|
+
if (!why) return [];
|
|
474
|
+
return [
|
|
475
|
+
{ stage, reason: `${STAGE_NAMES[stage]} stays on ${fallback.displayName}: ${why}` },
|
|
476
|
+
];
|
|
477
|
+
});
|
|
478
|
+
const used = [
|
|
479
|
+
...(pins.length < stages.length ? [chosen] : []),
|
|
480
|
+
...(pins.length ? [DEFAULT_HARNESS] : []),
|
|
481
|
+
];
|
|
482
|
+
return { chosen, pins, used: used.map((name) => harnesses[name]) };
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
/**
|
|
486
|
+
* The secrets of a harness a new Consumer's run reads. A harness's secrets are
|
|
487
|
+
* alternatives, but where each names a `provider` (opencode's), a run reads
|
|
488
|
+
* only the one its model's `provider/model` names, and no model variable is
|
|
489
|
+
* set yet: the default model's.
|
|
490
|
+
*/
|
|
491
|
+
function readBy({ secrets, defaultModel }) {
|
|
492
|
+
const provider = isLine(defaultModel) ? /^([^/]+)\/./.exec(defaultModel)?.[1] : undefined;
|
|
493
|
+
const matched = secrets.filter((s) => provider !== undefined && s.provider === provider);
|
|
494
|
+
return matched.length ? { secrets: matched, model: defaultModel } : { secrets };
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
/**
|
|
498
|
+
* The Secrets step's lines for one harness: its preferred credential and the
|
|
499
|
+
* alternatives, each under the repository secret the written Callers pass.
|
|
500
|
+
* Where the model picks the credential, the default model's alone.
|
|
501
|
+
*/
|
|
502
|
+
function secretLines(harness, callers) {
|
|
503
|
+
const { displayName } = harness;
|
|
504
|
+
const { secrets, model } = readBy(harness);
|
|
505
|
+
const passed = secrets.flatMap(({ name, whereToGet }) => {
|
|
506
|
+
const read = new RegExp(`^\\s*${name}:\\s*\\$\\{\\{\\s*secrets\\.([A-Za-z_]\\w*)`, "m");
|
|
507
|
+
const secret = read.exec(callers)?.[1];
|
|
508
|
+
return secret ? [{ secret, whereToGet }] : [];
|
|
509
|
+
});
|
|
510
|
+
// Callers that pass none of them: name each secret after its input.
|
|
511
|
+
const offered = passed.length
|
|
512
|
+
? passed
|
|
513
|
+
: secrets.map(({ name, whereToGet }) => ({ secret: name.toUpperCase(), whereToGet }));
|
|
514
|
+
const [preferred, ...others] = offered;
|
|
515
|
+
return [
|
|
516
|
+
{ note: `${displayName}, ${preferred.secret}: ${preferred.whereToGet}` },
|
|
517
|
+
command("gh", "secret", "set", preferred.secret),
|
|
518
|
+
...others.map((x) => ({ note: ` or set ${x.secret} instead: ${x.whereToGet}` })),
|
|
519
|
+
...(model === undefined
|
|
520
|
+
? []
|
|
521
|
+
: [
|
|
522
|
+
{
|
|
523
|
+
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.`,
|
|
524
|
+
},
|
|
525
|
+
]),
|
|
526
|
+
];
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
/**
|
|
530
|
+
* The Kit-owned paths `init` copies whole. One that already matches the tag
|
|
531
|
+
* (an earlier init, adding a flow now) is left as it is; any other existing
|
|
532
|
+
* one is an earlier adoption, replaced only with `force`. `skip` names
|
|
533
|
+
* Kit-owned paths to leave out (the Orchestrate engine carries no bundle).
|
|
534
|
+
* @returns {{ conflicts: string[], deletes: string[], writes: object[], unchanged: string[] }}
|
|
535
|
+
*/
|
|
536
|
+
export function planKitOwned({ runner, root, snap, force, skip = [] }) {
|
|
537
|
+
const conflicts = [];
|
|
538
|
+
const deletes = [];
|
|
539
|
+
const owned = snap.kitOwnedPaths.filter((p) => !skip.includes(p));
|
|
540
|
+
const exists = (rel) => lstatOrNull(join(root, rel)) !== null;
|
|
541
|
+
const existing = owned.filter((p) => {
|
|
542
|
+
checkLocalPath(root, p.replace(/\/$/, ""));
|
|
543
|
+
return exists(p.replace(/\/$/, ""));
|
|
544
|
+
});
|
|
545
|
+
const local = existing.length
|
|
546
|
+
? localTreeHashes({ runner, cwd: root, paths: existing }).hashes
|
|
547
|
+
: new Map();
|
|
548
|
+
const unchanged = existing.filter((p) => {
|
|
549
|
+
const hash = local.get(p);
|
|
550
|
+
return hash !== null && hash !== undefined && hash === snap.treeHash(p);
|
|
551
|
+
});
|
|
552
|
+
for (const p of existing.filter((x) => !unchanged.includes(x))) {
|
|
553
|
+
if (!force) conflicts.push(`${p} (Kit-owned path)`);
|
|
554
|
+
else {
|
|
555
|
+
const rel = p.replace(/\/$/, "");
|
|
556
|
+
checkDeletable(root, rel);
|
|
557
|
+
deletes.push(rel);
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
const writes = kitFileWrites({ ...snap, kitOwnedPaths: owned }).filter(
|
|
561
|
+
(w) => !unchanged.some((p) => w.path.startsWith(p)),
|
|
562
|
+
);
|
|
563
|
+
return { conflicts, deletes, writes, unchanged };
|
|
564
|
+
}
|
|
565
|
+
|
|
277
566
|
/**
|
|
278
567
|
* Work out everything init would write and throw Refusal for anything that
|
|
279
568
|
* stops it. Touches nothing on disk.
|
|
@@ -299,29 +588,11 @@ export function planInit({ runner, root, snap, answers, force }) {
|
|
|
299
588
|
return Boolean(st);
|
|
300
589
|
};
|
|
301
590
|
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
return exists(p.replace(/\/$/, ""));
|
|
308
|
-
});
|
|
309
|
-
const local = existing.length
|
|
310
|
-
? localTreeHashes({ runner, cwd: root, paths: existing }).hashes
|
|
311
|
-
: new Map();
|
|
312
|
-
const unchanged = existing.filter((p) => {
|
|
313
|
-
const hash = local.get(p);
|
|
314
|
-
return hash !== null && hash !== undefined && hash === snap.treeHash(p);
|
|
315
|
-
});
|
|
316
|
-
for (const p of existing.filter((x) => !unchanged.includes(x))) {
|
|
317
|
-
if (!force) conflicts.push(`${p} (Kit-owned path)`);
|
|
318
|
-
else {
|
|
319
|
-
const rel = p.replace(/\/$/, "");
|
|
320
|
-
checkDeletable(root, rel);
|
|
321
|
-
deletes.push(rel);
|
|
322
|
-
}
|
|
323
|
-
}
|
|
324
|
-
writes.push(...kitFileWrites(snap).filter((w) => !unchanged.some((p) => w.path.startsWith(p))));
|
|
591
|
+
const kitPlan = planKitOwned({ runner, root, snap, force });
|
|
592
|
+
const { unchanged } = kitPlan;
|
|
593
|
+
conflicts.push(...kitPlan.conflicts);
|
|
594
|
+
deletes.push(...kitPlan.deletes);
|
|
595
|
+
writes.push(...kitPlan.writes);
|
|
325
596
|
|
|
326
597
|
const dir = answers.threatPackDir ?? DEFAULT_THREAT_PACK_DIR;
|
|
327
598
|
// Case-insensitive: on Windows and macOS `.Claude/skills/x` is `.claude/skills/x`.
|
|
@@ -335,12 +606,15 @@ export function planInit({ runner, root, snap, answers, force }) {
|
|
|
335
606
|
);
|
|
336
607
|
}
|
|
337
608
|
|
|
609
|
+
const harness = planHarness(snap, answers);
|
|
610
|
+
|
|
611
|
+
const preset = answers.preset ? presetParts(presetText(snap, answers.preset)) : null;
|
|
338
612
|
const values = {
|
|
339
613
|
actors: answers.actors,
|
|
340
614
|
tag,
|
|
341
615
|
defaultBranch: answers.defaultBranch,
|
|
342
616
|
verify: answers.verify ?? "",
|
|
343
|
-
preset:
|
|
617
|
+
preset: preset?.script ?? null,
|
|
344
618
|
threatPackDir: dir,
|
|
345
619
|
};
|
|
346
620
|
for (const flow of answers.flows) {
|
|
@@ -354,6 +628,9 @@ export function planInit({ runner, root, snap, answers, force }) {
|
|
|
354
628
|
if (err instanceof TemplateError) throw new Refusal(err.message);
|
|
355
629
|
throw err;
|
|
356
630
|
}
|
|
631
|
+
if ((flow === "pipeline" || flow === "review-response") && preset?.sandbox) {
|
|
632
|
+
rendered = withSandbox(rendered, preset.sandbox, { preset: answers.preset, tag });
|
|
633
|
+
}
|
|
357
634
|
if (fileTarget(caller, "Caller")) {
|
|
358
635
|
conflicts.push(`${caller} (Caller)`);
|
|
359
636
|
overwrites.push(caller);
|
|
@@ -416,7 +693,7 @@ export function planInit({ runner, root, snap, answers, force }) {
|
|
|
416
693
|
const { changed: dirty, ignored } = replaced.length
|
|
417
694
|
? uncommittedChanges({ runner, root, paths: replaced })
|
|
418
695
|
: { changed: [], ignored: [] };
|
|
419
|
-
return { deletes, writes, conflicts, notes, dependabot, dirty, ignored, unchanged };
|
|
696
|
+
return { deletes, writes, conflicts, notes, dependabot, dirty, ignored, unchanged, harness };
|
|
420
697
|
}
|
|
421
698
|
|
|
422
699
|
/**
|
|
@@ -433,16 +710,18 @@ function variableRead(name, callers) {
|
|
|
433
710
|
/**
|
|
434
711
|
* The GitHub-side steps init does not take, as POSIX-shell commands built
|
|
435
712
|
* with checks/result.mjs `command()` (every argument fixed or allowlisted).
|
|
713
|
+
* `harness` is planInit's, or null for a tag without cli/harnesses.json.
|
|
436
714
|
*/
|
|
437
|
-
export function manualSteps({ flows, tag, kitRepo, serverUrl, callers = "" }) {
|
|
715
|
+
export function manualSteps({ flows, tag, kitRepo, serverUrl, callers = "", harness = null }) {
|
|
438
716
|
const pipeline = flows.includes("pipeline");
|
|
439
717
|
const audit = flows.includes("audit");
|
|
440
718
|
const response = flows.includes("review-response");
|
|
441
719
|
const lines = [];
|
|
442
720
|
let n = 0;
|
|
721
|
+
// A command prints after `$`; a `{ note }` prints as text between commands.
|
|
443
722
|
const step = (title, ...cmds) => {
|
|
444
723
|
lines.push(`${++n}. ${title}`);
|
|
445
|
-
for (const c of cmds) lines.push(` $ ${c}`);
|
|
724
|
+
for (const c of cmds) lines.push(typeof c === "string" ? ` $ ${c}` : ` ${c.note}`);
|
|
446
725
|
};
|
|
447
726
|
// Offered only when the Callers pass it; an older tag's do not.
|
|
448
727
|
const apiKey = /\bsecrets\.ANTHROPIC_API_KEY\b/.test(callers)
|
|
@@ -450,11 +729,38 @@ export function manualSteps({ flows, tag, kitRepo, serverUrl, callers = "" }) {
|
|
|
450
729
|
: "";
|
|
451
730
|
const setVariable = (name, value) =>
|
|
452
731
|
command("gh", "variable", "set", variableRead(name, callers), "--body", value);
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
732
|
+
if (harness && harness.chosen !== DEFAULT_HARNESS) {
|
|
733
|
+
step(
|
|
734
|
+
`Harness (repository variables; unset is ${DEFAULT_HARNESS}):`,
|
|
735
|
+
{
|
|
736
|
+
note:
|
|
737
|
+
"AGENT_KIT_HARNESS applies to every Stage of every Caller, the Deep scan and flows " +
|
|
738
|
+
"you add later included; the pins here cover only the flows of this run.",
|
|
739
|
+
},
|
|
740
|
+
setVariable("AGENT_KIT_HARNESS", harness.chosen),
|
|
741
|
+
...harness.pins.flatMap(({ stage, reason }) => [
|
|
742
|
+
{ note: reason },
|
|
743
|
+
setVariable(
|
|
744
|
+
`AGENT_KIT_${stage.toUpperCase().replaceAll("-", "_")}_HARNESS`,
|
|
745
|
+
DEFAULT_HARNESS,
|
|
746
|
+
),
|
|
747
|
+
]),
|
|
748
|
+
);
|
|
749
|
+
}
|
|
750
|
+
const advisories = audit ? [command("gh", "secret", "set", "AGENT_KIT_ADVISORIES_TOKEN")] : [];
|
|
751
|
+
if (harness) {
|
|
752
|
+
step(
|
|
753
|
+
"Secrets (gh asks for each value):",
|
|
754
|
+
...harness.used.flatMap((h) => secretLines(h, callers)),
|
|
755
|
+
...advisories,
|
|
756
|
+
);
|
|
757
|
+
} else {
|
|
758
|
+
step(
|
|
759
|
+
`Secrets (gh asks for each value; CLAUDE_CODE_OAUTH_TOKEN comes from \`claude setup-token\`${apiKey}):`,
|
|
760
|
+
command("gh", "secret", "set", "CLAUDE_CODE_OAUTH_TOKEN"),
|
|
761
|
+
...advisories,
|
|
762
|
+
);
|
|
763
|
+
}
|
|
458
764
|
const labels = [...(pipeline ? LABELS : []), ...(response ? [RESPONSE_LABEL] : [])];
|
|
459
765
|
if (labels.length) {
|
|
460
766
|
step(
|
|
@@ -467,8 +773,21 @@ export function manualSteps({ flows, tag, kitRepo, serverUrl, callers = "" }) {
|
|
|
467
773
|
if (pipeline) {
|
|
468
774
|
step("Install the Claude GitHub App on this repository: https://github.com/apps/claude");
|
|
469
775
|
}
|
|
776
|
+
// Offered only where a Caller names it: an older tag's workflows take none.
|
|
777
|
+
if ((pipeline || response) && /\bAGENT_KIT_APP_ID\b/.test(callers)) {
|
|
778
|
+
step(
|
|
779
|
+
"Optional, your own GitHub App, so CI starts on agent pushes with no approval (skip it " +
|
|
780
|
+
"to use the job token and ci_workflow): create an App with Contents and Pull requests: " +
|
|
781
|
+
"read and write (https://github.com/settings/apps/new), install it on this repository, " +
|
|
782
|
+
"uncomment app_id and app_private_key in the Callers, then set both (one without the " +
|
|
783
|
+
"other fails the run):",
|
|
784
|
+
command("gh", "variable", "set", "AGENT_KIT_APP_ID"),
|
|
785
|
+
command("gh", "secret", "set", "AGENT_KIT_APP_PRIVATE_KEY"),
|
|
786
|
+
{ note: "The secret is a file: append < path/to/your-app.private-key.pem to that command." },
|
|
787
|
+
);
|
|
788
|
+
}
|
|
470
789
|
step(
|
|
471
|
-
"Rulesets
|
|
790
|
+
"Rulesets no GitHub App can bypass: list yours, then follow " +
|
|
472
791
|
`${serverUrl}/${kitRepo}/blob/${tag}/docs/repository-hardening.md`,
|
|
473
792
|
command("gh", "api", "repos/{owner}/{repo}/rulesets"),
|
|
474
793
|
);
|
|
@@ -517,7 +836,25 @@ export async function runInit({
|
|
|
517
836
|
err,
|
|
518
837
|
openTag = openKitTag,
|
|
519
838
|
env = process.env,
|
|
839
|
+
factory = null,
|
|
520
840
|
}) {
|
|
841
|
+
if (factory) {
|
|
842
|
+
return runFactoryInit({
|
|
843
|
+
cwd,
|
|
844
|
+
runner,
|
|
845
|
+
flags: { ...factory.flags, tag: flags.tag },
|
|
846
|
+
engine: factory.engine,
|
|
847
|
+
force,
|
|
848
|
+
yes,
|
|
849
|
+
prompt,
|
|
850
|
+
confirm,
|
|
851
|
+
out,
|
|
852
|
+
err,
|
|
853
|
+
openTag,
|
|
854
|
+
env,
|
|
855
|
+
planKitOwned,
|
|
856
|
+
});
|
|
857
|
+
}
|
|
521
858
|
const refuse = (e) => reportRefusal(out, e);
|
|
522
859
|
|
|
523
860
|
const collected = await collectAnswers({
|
|
@@ -649,6 +986,7 @@ export async function runInit({
|
|
|
649
986
|
tag: answers.tag,
|
|
650
987
|
kitRepo: DEFAULT_KIT_REPO,
|
|
651
988
|
serverUrl,
|
|
989
|
+
harness: plan.harness,
|
|
652
990
|
callers: answers.flows
|
|
653
991
|
.map((flow) => FLOWS[flow].caller)
|
|
654
992
|
.map((path) => plan.writes.find((w) => w.path === path).bytes.toString("utf8"))
|
package/src/kit-owned-paths.mjs
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
// adds a new kind of Kit-owned path. Nothing is deleted on this path.
|
|
13
13
|
|
|
14
14
|
export const ALLOWED_SHAPE =
|
|
15
|
-
/^(?:\.claude\/skills\/[A-Za-z0-9._-]+\/|\.github\/(?:agent-runtime|agent-pipeline|security-audit|agent-review-response)\/)$/;
|
|
15
|
+
/^(?:\.claude\/skills\/[A-Za-z0-9._-]+\/|\.github\/(?:agent-runtime|agent-pipeline|security-audit|agent-review-response|agent-factory)\/)$/;
|
|
16
16
|
const SAFE_PATH = /^[A-Za-z0-9._-]+(?:\/[A-Za-z0-9._-]+)*\/$/;
|
|
17
17
|
|
|
18
18
|
export class ManifestError extends Error {}
|