@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
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Review response mode: what
|
|
1
|
+
// Review response mode: what AGENT_KIT_REVIEW_RESPONSE_MODE is set to, and, in
|
|
2
2
|
// auto mode, whether the Callers carry what the Handoff needs. The Trigger
|
|
3
3
|
// label and the Kill switch variable are covered by the trigger-labels and
|
|
4
4
|
// variables checks, which read them from the Callers like any other flow's.
|
|
@@ -10,10 +10,16 @@
|
|
|
10
10
|
// error anywhere a Consumer would look.
|
|
11
11
|
|
|
12
12
|
import { result } from "./result.mjs";
|
|
13
|
+
import { RENAMED_VARIABLES } from "./secrets-and-variables.mjs";
|
|
13
14
|
|
|
14
15
|
const ID = "review-response-mode";
|
|
15
16
|
const TITLE = "Review response mode is set up";
|
|
16
|
-
export const MODE_VARIABLE = "
|
|
17
|
+
export const MODE_VARIABLE = "AGENT_KIT_REVIEW_RESPONSE_MODE";
|
|
18
|
+
/** The mode variable, and the names it replaced: a Caller from an older tag reads one. */
|
|
19
|
+
const MODE_VARIABLES = [
|
|
20
|
+
MODE_VARIABLE,
|
|
21
|
+
...Object.keys(RENAMED_VARIABLES).filter((old) => RENAMED_VARIABLES[old] === MODE_VARIABLE),
|
|
22
|
+
];
|
|
17
23
|
const RESPONSE_REUSABLE = "agent-review-response-reusable.yml";
|
|
18
24
|
const REVIEW_REUSABLE = "agent-review-reusable.yml";
|
|
19
25
|
/** What the review workflow's handoff accepts as `response_workflow`. */
|
|
@@ -23,16 +29,16 @@ const WORKFLOW_PATH = /^\.github\/workflows\/[A-Za-z0-9_-][A-Za-z0-9._-]*\.ya?ml
|
|
|
23
29
|
* The variable's value as a workflow run sees it: the repository's, else the
|
|
24
30
|
* organization's. null when neither sets it. Throws when it cannot be read.
|
|
25
31
|
*/
|
|
26
|
-
export function readMode(github, repo, ownerType) {
|
|
32
|
+
export function readMode(github, repo, ownerType, variable = MODE_VARIABLE) {
|
|
27
33
|
try {
|
|
28
|
-
return String(github.getJson(`repos/${repo}/actions/variables/${
|
|
34
|
+
return String(github.getJson(`repos/${repo}/actions/variables/${variable}`).value ?? "");
|
|
29
35
|
} catch (err) {
|
|
30
36
|
if (err?.httpStatus !== 404) throw err;
|
|
31
37
|
}
|
|
32
38
|
if (ownerType !== "Organization") return null;
|
|
33
39
|
const lines = github.getLines(
|
|
34
40
|
`repos/${repo}/actions/organization-variables`,
|
|
35
|
-
`.variables[] | select(.name == "${
|
|
41
|
+
`.variables[] | select(.name == "${variable}") | .value`,
|
|
36
42
|
);
|
|
37
43
|
return lines.length ? lines[0] : null;
|
|
38
44
|
}
|
|
@@ -47,6 +53,15 @@ const jobsUsing = (callers, file) =>
|
|
|
47
53
|
const passes = (job, input) =>
|
|
48
54
|
typeof job.with?.[input] === "string" && job.with[input].trim() !== "";
|
|
49
55
|
|
|
56
|
+
/** The mode variable a job's `response_mode` expression reads, or null. */
|
|
57
|
+
export function modeVariable(job) {
|
|
58
|
+
const value = passes(job, "response_mode") ? job.with.response_mode.trim() : "";
|
|
59
|
+
// An expression: `${{ vars.AGENT_KIT_REVIEW_RESPONSE_MODE || 'manual' }}`.
|
|
60
|
+
if (!/^\$\{\{.*\}\}$/.test(value)) return null;
|
|
61
|
+
const read = (name) => new RegExp(`\\bvars\\.${name}\\b`, "i").test(value);
|
|
62
|
+
return MODE_VARIABLES.find(read) ?? null;
|
|
63
|
+
}
|
|
64
|
+
|
|
50
65
|
/**
|
|
51
66
|
* Where a job's `response_mode` comes from: "auto" (the literal), "variable"
|
|
52
67
|
* (an expression reading the mode variable), "other" (anything else), or
|
|
@@ -56,9 +71,7 @@ export function modeSource(job) {
|
|
|
56
71
|
if (!passes(job, "response_mode")) return null;
|
|
57
72
|
const value = job.with.response_mode.trim();
|
|
58
73
|
if (value === "auto") return "auto";
|
|
59
|
-
|
|
60
|
-
if (/^\$\{\{.*\bvars\.CLAUDE_REVIEW_RESPONSE_MODE\b.*\}\}$/i.test(value)) return "variable";
|
|
61
|
-
return "other";
|
|
74
|
+
return modeVariable(job) ? "variable" : "other";
|
|
62
75
|
}
|
|
63
76
|
|
|
64
77
|
/** Does any Caller hardcode `response_mode: auto`, whatever the variable says? */
|
|
@@ -68,11 +81,12 @@ const hardcodesAuto = (callers) =>
|
|
|
68
81
|
);
|
|
69
82
|
|
|
70
83
|
/**
|
|
71
|
-
* Why a job would not see `auto` as its `response_mode`, given the
|
|
72
|
-
* variable
|
|
84
|
+
* Why a job would not see `auto` as its `response_mode`, given `modeOf`, the
|
|
85
|
+
* value of each mode variable; null when it would.
|
|
73
86
|
*/
|
|
74
|
-
function notAuto(job,
|
|
87
|
+
function notAuto(job, modeOf, consequence) {
|
|
75
88
|
const source = modeSource(job);
|
|
89
|
+
const variable = modeVariable(job) ?? MODE_VARIABLE;
|
|
76
90
|
if (source === null) {
|
|
77
91
|
return `does not pass response_mode (vars.${MODE_VARIABLE}), so ${consequence}.`;
|
|
78
92
|
}
|
|
@@ -82,17 +96,17 @@ function notAuto(job, mode, consequence) {
|
|
|
82
96
|
`reads vars.${MODE_VARIABLE} nor is auto, so ${consequence}.`
|
|
83
97
|
);
|
|
84
98
|
}
|
|
85
|
-
if (source === "variable" &&
|
|
86
|
-
return `reads response_mode from vars.${
|
|
99
|
+
if (source === "variable" && modeOf(variable) !== "auto") {
|
|
100
|
+
return `reads response_mode from vars.${variable}, which is not auto, so ${consequence}.`;
|
|
87
101
|
}
|
|
88
102
|
return null;
|
|
89
103
|
}
|
|
90
104
|
|
|
91
105
|
/**
|
|
92
106
|
* Why auto mode would never start a round from these Callers; empty when it
|
|
93
|
-
* would. `
|
|
107
|
+
* would. `modeOf` gives a mode variable's value (null when unset).
|
|
94
108
|
*/
|
|
95
|
-
export function autoModeProblems(callers,
|
|
109
|
+
export function autoModeProblems(callers, modeOf = () => "auto") {
|
|
96
110
|
const problems = [];
|
|
97
111
|
const responders = jobsUsing(callers, RESPONSE_REUSABLE);
|
|
98
112
|
// A responder file whose trigger is wrong is reported once, here, not again
|
|
@@ -110,7 +124,7 @@ export function autoModeProblems(callers, mode = "auto") {
|
|
|
110
124
|
}
|
|
111
125
|
}
|
|
112
126
|
for (const { job, where } of responders) {
|
|
113
|
-
const why = notAuto(job,
|
|
127
|
+
const why = notAuto(job, modeOf, "its gate refuses every dispatched round");
|
|
114
128
|
if (why) problems.push(`${where}: ${why}`);
|
|
115
129
|
}
|
|
116
130
|
|
|
@@ -121,7 +135,7 @@ export function autoModeProblems(callers, mode = "auto") {
|
|
|
121
135
|
);
|
|
122
136
|
}
|
|
123
137
|
for (const { job, where } of reviewers) {
|
|
124
|
-
const why = notAuto(job,
|
|
138
|
+
const why = notAuto(job, modeOf, "its reviews never hand off");
|
|
125
139
|
if (why) problems.push(`${where}: ${why}`);
|
|
126
140
|
const target = passes(job, "response_workflow") ? job.with.response_workflow.trim() : "";
|
|
127
141
|
if (!target) {
|
|
@@ -148,16 +162,29 @@ export function checkReviewResponseMode({ github, repo, ownerType, callers }) {
|
|
|
148
162
|
if (jobsUsing(callers, RESPONSE_REUSABLE).length === 0) {
|
|
149
163
|
return result(ID, TITLE, "pass", "No Caller uses the Review response flow.");
|
|
150
164
|
}
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
165
|
+
// The variable each Caller reads: more than one only part-way through an upgrade.
|
|
166
|
+
const jobs = [...jobsUsing(callers, RESPONSE_REUSABLE), ...jobsUsing(callers, REVIEW_REUSABLE)];
|
|
167
|
+
const read = [...new Set(jobs.map(({ job }) => modeVariable(job)).filter(Boolean))];
|
|
168
|
+
if (read.length === 0) read.push(MODE_VARIABLE);
|
|
169
|
+
const values = new Map();
|
|
170
|
+
for (const variable of read) {
|
|
171
|
+
try {
|
|
172
|
+
values.set(variable, readMode(github, repo, ownerType, variable));
|
|
173
|
+
} catch (err) {
|
|
174
|
+
return result(ID, TITLE, "skip", `Could not read ${variable}: ${err.message}`);
|
|
175
|
+
}
|
|
156
176
|
}
|
|
177
|
+
const modeOf = (variable) => values.get(variable) ?? null;
|
|
178
|
+
// The variable to report: the one that turns auto mode on, else the newest read.
|
|
179
|
+
const name =
|
|
180
|
+
read.find((v) => modeOf(v) === "auto") ??
|
|
181
|
+
MODE_VARIABLES.find((v) => read.includes(v)) ??
|
|
182
|
+
MODE_VARIABLE;
|
|
183
|
+
const mode = modeOf(name);
|
|
157
184
|
// A Caller that hardcodes `response_mode: auto` is in auto mode whatever
|
|
158
185
|
// the variable says, so its wiring is checked too.
|
|
159
186
|
if (mode !== "auto" && hardcodesAuto(callers)) {
|
|
160
|
-
const problems = autoModeProblems(callers,
|
|
187
|
+
const problems = autoModeProblems(callers, modeOf);
|
|
161
188
|
if (problems.length) {
|
|
162
189
|
return result(
|
|
163
190
|
ID,
|
|
@@ -179,7 +206,7 @@ export function checkReviewResponseMode({ github, repo, ownerType, callers }) {
|
|
|
179
206
|
ID,
|
|
180
207
|
TITLE,
|
|
181
208
|
"pass",
|
|
182
|
-
`Manual: ${
|
|
209
|
+
`Manual: ${name} is ${mode === null ? "not set" : JSON.stringify(mode)}, so only the Trigger label starts a round.`,
|
|
183
210
|
);
|
|
184
211
|
}
|
|
185
212
|
if (mode !== "auto") {
|
|
@@ -187,17 +214,17 @@ export function checkReviewResponseMode({ github, repo, ownerType, callers }) {
|
|
|
187
214
|
ID,
|
|
188
215
|
TITLE,
|
|
189
216
|
"warn",
|
|
190
|
-
`${
|
|
217
|
+
`${name} is ${JSON.stringify(mode)}, which is not exactly auto, so Review response stays manual.`,
|
|
191
218
|
{ details: ["Set it to auto for auto mode, or to manual (or delete it) for manual mode."] },
|
|
192
219
|
);
|
|
193
220
|
}
|
|
194
|
-
const problems = autoModeProblems(callers,
|
|
221
|
+
const problems = autoModeProblems(callers, modeOf);
|
|
195
222
|
if (problems.length) {
|
|
196
223
|
return result(
|
|
197
224
|
ID,
|
|
198
225
|
TITLE,
|
|
199
226
|
"fail",
|
|
200
|
-
`${
|
|
227
|
+
`${name} is auto, but ${problems.length} problem(s) keep the handoff from starting a round.`,
|
|
201
228
|
{ details: problems },
|
|
202
229
|
);
|
|
203
230
|
}
|
package/src/checks/rulesets.mjs
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
// The rulesets docs/repository-hardening.md sets up, which keep
|
|
2
|
-
//
|
|
3
|
-
// release tags. Each gap is a warning: the flows
|
|
1
|
+
// The rulesets docs/repository-hardening.md sets up, which keep a GitHub App's
|
|
2
|
+
// token (the Claude App's, or the Consumer's own) away from the default
|
|
3
|
+
// branch, release branches and release tags. Each gap is a warning: the flows
|
|
4
|
+
// still run without them.
|
|
4
5
|
//
|
|
5
|
-
// A rule only counts when no one
|
|
6
|
+
// A rule only counts when no one an App can act as is on the ruleset's
|
|
6
7
|
// bypass list: rulesets stack, so an actor on one ruleset's bypass list is
|
|
7
8
|
// still held by any other ruleset with the same rule that does not list it.
|
|
8
9
|
|
|
@@ -125,8 +126,8 @@ const MAINTAIN_ROLE = 2;
|
|
|
125
126
|
const ROLE_NAMES = { 1: "Read", 2: "Maintain", 3: "Triage", 4: "Write", 5: "Admin" };
|
|
126
127
|
|
|
127
128
|
/**
|
|
128
|
-
* Bypass actors that undo the ruleset's protection against
|
|
129
|
-
* any GitHub App (
|
|
129
|
+
* Bypass actors that undo the ruleset's protection against an agent's token:
|
|
130
|
+
* any GitHub App (each is an `Integration`), any repository role
|
|
130
131
|
* below Maintain (the Write role, or a custom role), and, on a branch
|
|
131
132
|
* ruleset, deploy keys. Admin, Maintain, teams and organization admins are
|
|
132
133
|
* the intended bypass list; a DeployKey bypass on a tag ruleset is the
|
|
@@ -168,7 +169,7 @@ function ruleStatus(covering, type) {
|
|
|
168
169
|
}
|
|
169
170
|
|
|
170
171
|
const BYPASS_ADVICE =
|
|
171
|
-
"Keep the bypass list to Admin and Maintain: never
|
|
172
|
+
"Keep the bypass list to Admin and Maintain: never any GitHub App, the Write role, or a team an App acts through.";
|
|
172
173
|
|
|
173
174
|
function updateRule(rulesets, { defaultBranch }) {
|
|
174
175
|
const ID = "ruleset-update";
|
|
@@ -187,7 +188,7 @@ function updateRule(rulesets, { defaultBranch }) {
|
|
|
187
188
|
}
|
|
188
189
|
return result(ID, TITLE, "warn", `No active update rule on ${defaultBranch}.`, {
|
|
189
190
|
details: [
|
|
190
|
-
"A required pull request with zero approvals does not stop the Claude App merging its own pull request; an update rule does.",
|
|
191
|
+
"A required pull request with zero approvals does not stop any GitHub App (the Claude App, or yours) merging its own pull request; an update rule does.",
|
|
191
192
|
recipe,
|
|
192
193
|
],
|
|
193
194
|
});
|
|
@@ -1,12 +1,34 @@
|
|
|
1
1
|
// Secrets and repository variables, worked out from the Consumer's Callers.
|
|
2
2
|
// A secret is required when the reusable workflow at the pinned tag declares
|
|
3
3
|
// the secret it is passed to as `required: true`; otherwise it is optional.
|
|
4
|
+
// The model credentials are optional there, because only the chosen harness
|
|
5
|
+
// needs one (ADR 0030), so they are asked for as a group.
|
|
4
6
|
// A variable is optional when every read of it falls back with `||`.
|
|
5
7
|
|
|
6
8
|
import { secretNames } from "../callers.mjs";
|
|
7
9
|
import { parseWorkflowCallSecrets } from "../workflow-call.mjs";
|
|
8
10
|
import { byHand, command, NAME_PATTERN, result } from "./result.mjs";
|
|
9
11
|
|
|
12
|
+
/** The secret inputs `claude-code` accepts, the preferred one first (ADR 0024). */
|
|
13
|
+
const CLAUDE_CODE_INPUTS = ["claude_code_oauth_token", "anthropic_api_key"];
|
|
14
|
+
/**
|
|
15
|
+
* The Deep scan takes exactly one of the two (its first step fails on both),
|
|
16
|
+
* and the API key is its supported one.
|
|
17
|
+
*/
|
|
18
|
+
const DEEP_SCAN_REUSABLE = "deep-scan-reusable.yml";
|
|
19
|
+
const preferred = (file) =>
|
|
20
|
+
file === DEEP_SCAN_REUSABLE ? [...CLAUDE_CODE_INPUTS].reverse() : CLAUDE_CODE_INPUTS;
|
|
21
|
+
/** Every model credential input: the others belong to harnesses no Stage runs yet. */
|
|
22
|
+
const MODEL_INPUTS = new Set([
|
|
23
|
+
...CLAUDE_CODE_INPUTS,
|
|
24
|
+
"openai_api_key",
|
|
25
|
+
"gemini_api_key",
|
|
26
|
+
"cursor_api_key",
|
|
27
|
+
]);
|
|
28
|
+
|
|
29
|
+
/** The Consumer's own GitHub App's key: optional, and the `github-app` check judges it. */
|
|
30
|
+
const APP_INPUT = "app_private_key";
|
|
31
|
+
|
|
10
32
|
/** GitHub provides `secrets.GITHUB_TOKEN`; no `GITHUB_*` secret can be set by hand. */
|
|
11
33
|
const isProvided = (name) => /^github_/i.test(name);
|
|
12
34
|
|
|
@@ -49,6 +71,7 @@ export function deriveVariables(callers) {
|
|
|
49
71
|
export function deriveRequirements(callers, readReusable) {
|
|
50
72
|
const secrets = new Map();
|
|
51
73
|
const problems = [];
|
|
74
|
+
const noCredential = [];
|
|
52
75
|
const specs = new Map();
|
|
53
76
|
const specFor = (file) => {
|
|
54
77
|
if (!specs.has(file)) {
|
|
@@ -57,7 +80,8 @@ export function deriveRequirements(callers, readReusable) {
|
|
|
57
80
|
}
|
|
58
81
|
return specs.get(file);
|
|
59
82
|
};
|
|
60
|
-
|
|
83
|
+
// `shown` is false under `secrets: inherit`, where the Caller writes no input.
|
|
84
|
+
const addSecret = (names, required, job, file, input, shown = true) => {
|
|
61
85
|
// A GITHUB_* secret is always set, so an expression that falls back to one is too.
|
|
62
86
|
if (names.some(isProvided)) return;
|
|
63
87
|
const key = names.join(" || ");
|
|
@@ -65,7 +89,9 @@ export function deriveRequirements(callers, readReusable) {
|
|
|
65
89
|
secrets.set(key, {
|
|
66
90
|
names,
|
|
67
91
|
required: Boolean(prev?.required || required),
|
|
68
|
-
where: [...(prev?.where ?? []),
|
|
92
|
+
where: [...(prev?.where ?? []), shown ? `${job} (${input})` : job],
|
|
93
|
+
// The job, the reusable workflow it calls and the secret input each use fills.
|
|
94
|
+
uses: [...(prev?.uses ?? []), { job, file, input: input.toLowerCase() }],
|
|
69
95
|
});
|
|
70
96
|
};
|
|
71
97
|
|
|
@@ -80,7 +106,8 @@ export function deriveRequirements(callers, readReusable) {
|
|
|
80
106
|
}
|
|
81
107
|
if (job.secrets === "inherit") {
|
|
82
108
|
for (const { name, required } of spec.values()) {
|
|
83
|
-
|
|
109
|
+
// Inherited, the secret's name is the input's.
|
|
110
|
+
addSecret([name.toUpperCase()], required, where, job.uses.file, name, false);
|
|
84
111
|
}
|
|
85
112
|
continue;
|
|
86
113
|
}
|
|
@@ -95,7 +122,18 @@ export function deriveRequirements(callers, readReusable) {
|
|
|
95
122
|
);
|
|
96
123
|
continue;
|
|
97
124
|
}
|
|
98
|
-
addSecret(names, declared.required,
|
|
125
|
+
addSecret(names, declared.required, where, job.uses.file, input);
|
|
126
|
+
}
|
|
127
|
+
// Optional in the workflow, so nothing refuses a job without either.
|
|
128
|
+
const accepted = CLAUDE_CODE_INPUTS.filter((input) => spec.has(input));
|
|
129
|
+
if (
|
|
130
|
+
accepted.length &&
|
|
131
|
+
accepted.every((input) => !spec.get(input).required && !passed.has(input))
|
|
132
|
+
) {
|
|
133
|
+
noCredential.push(
|
|
134
|
+
`${where} passes neither ${CLAUDE_CODE_INPUTS.join(" nor ")} to ${job.uses.file}; ` +
|
|
135
|
+
"the run fails without one",
|
|
136
|
+
);
|
|
99
137
|
}
|
|
100
138
|
for (const { name, required } of spec.values()) {
|
|
101
139
|
if (required && !passed.has(name.toLowerCase())) {
|
|
@@ -110,11 +148,12 @@ export function deriveRequirements(callers, readReusable) {
|
|
|
110
148
|
secrets: [...secrets.values()],
|
|
111
149
|
variables: deriveVariables(callers),
|
|
112
150
|
problems,
|
|
151
|
+
noCredential,
|
|
113
152
|
unsupported: unreadable(callers),
|
|
114
153
|
};
|
|
115
154
|
}
|
|
116
155
|
|
|
117
|
-
function listNames(github, repo, kind, ownerType) {
|
|
156
|
+
export function listNames(github, repo, kind, ownerType) {
|
|
118
157
|
const key = kind === "secret" ? "secrets" : "variables";
|
|
119
158
|
const names = new Set(github.getLines(`repos/${repo}/actions/${key}`, `.${key}[].name`));
|
|
120
159
|
let orgNote = null;
|
|
@@ -133,8 +172,64 @@ function listNames(github, repo, kind, ownerType) {
|
|
|
133
172
|
return { names: new Set([...names].map((n) => n.toUpperCase())), orgNote };
|
|
134
173
|
}
|
|
135
174
|
|
|
175
|
+
const isModelCredential = (x) =>
|
|
176
|
+
!x.required && x.uses.every(({ input }) => MODEL_INPUTS.has(input));
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* Each job that passes a Claude Code secret, with what it passes, the preferred
|
|
180
|
+
* input of its workflow first.
|
|
181
|
+
*/
|
|
182
|
+
function claudeCodeJobs(secrets) {
|
|
183
|
+
const jobs = new Map();
|
|
184
|
+
for (const secret of secrets) {
|
|
185
|
+
for (const { job, file, input } of secret.uses) {
|
|
186
|
+
if (!CLAUDE_CODE_INPUTS.includes(input)) continue;
|
|
187
|
+
if (!jobs.has(job)) jobs.set(job, { file, passed: [] });
|
|
188
|
+
jobs.get(job).passed.push({ secret, rank: preferred(file).indexOf(input) });
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
for (const { passed } of jobs.values()) passed.sort((a, b) => a.rank - b.rank);
|
|
192
|
+
return jobs;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/** Jobs grouped under the secrets a message names: those that need the same ones together. */
|
|
196
|
+
function byNames(entries, joiner) {
|
|
197
|
+
const groups = new Map();
|
|
198
|
+
for (const { job, secrets } of entries) {
|
|
199
|
+
const names = secrets.map((x) => x.names.join(" or ")).join(joiner);
|
|
200
|
+
if (!groups.has(names)) groups.set(names, { names, first: secrets[0], where: [] });
|
|
201
|
+
groups.get(names).where.push(job);
|
|
202
|
+
}
|
|
203
|
+
return [...groups.values()];
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* The jobs left with no model credential: for each, the secrets that would give
|
|
208
|
+
* `claude-code`, the one harness that runs a Stage, its credential.
|
|
209
|
+
*/
|
|
210
|
+
function jobsWithoutCredential(jobs, isSet) {
|
|
211
|
+
const missing = [];
|
|
212
|
+
for (const [job, { passed }] of jobs) {
|
|
213
|
+
// A required one is reported as missing on its own.
|
|
214
|
+
if (passed.some(({ secret }) => secret.required || isSet(secret))) continue;
|
|
215
|
+
missing.push({ job, secrets: passed.map((x) => x.secret) });
|
|
216
|
+
}
|
|
217
|
+
return byNames(missing, " or ");
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/** The Deep scan jobs with more than one model credential set, which fail every run. */
|
|
221
|
+
function jobsWithTwoCredentials(jobs, isSet) {
|
|
222
|
+
const doubled = [];
|
|
223
|
+
for (const [job, { file, passed }] of jobs) {
|
|
224
|
+
if (file !== DEEP_SCAN_REUSABLE) continue;
|
|
225
|
+
const set = passed.map((x) => x.secret).filter(isSet);
|
|
226
|
+
if (set.length > 1) doubled.push({ job, secrets: set });
|
|
227
|
+
}
|
|
228
|
+
return byNames(doubled, " and ");
|
|
229
|
+
}
|
|
230
|
+
|
|
136
231
|
/** `gh secret set` / `gh variable set` for a valid name, or a by-hand note. */
|
|
137
|
-
function setCommand(kind, name, repo, extra = []) {
|
|
232
|
+
export function setCommand(kind, name, repo, extra = []) {
|
|
138
233
|
if (!NAME_PATTERN.test(name)) return { note: byHand(`${kind} named`, name) };
|
|
139
234
|
return { cmd: command("gh", kind, "set", name, "--repo", repo, ...extra) };
|
|
140
235
|
}
|
|
@@ -146,10 +241,21 @@ function splitFixes(items) {
|
|
|
146
241
|
};
|
|
147
242
|
}
|
|
148
243
|
|
|
149
|
-
|
|
244
|
+
/**
|
|
245
|
+
* `perStageCredential`: the pinned tag publishes its harness facts, so the
|
|
246
|
+
* `stage-credential` check judges each Stage's model credential by its harness
|
|
247
|
+
* (a missing one, or a Deep scan with two), and this one judges none.
|
|
248
|
+
*/
|
|
249
|
+
export function checkSecrets({
|
|
250
|
+
github,
|
|
251
|
+
repo,
|
|
252
|
+
ownerType,
|
|
253
|
+
requirements,
|
|
254
|
+
perStageCredential = false,
|
|
255
|
+
}) {
|
|
150
256
|
const ID = "secrets";
|
|
151
257
|
const TITLE = "Secrets the Callers pass are set";
|
|
152
|
-
const { problems, unsupported = [] } = requirements;
|
|
258
|
+
const { problems, noCredential = [], unsupported = [] } = requirements;
|
|
153
259
|
let listed;
|
|
154
260
|
try {
|
|
155
261
|
listed = listNames(github, repo, "secret", ownerType);
|
|
@@ -170,36 +276,63 @@ export function checkSecrets({ github, repo, ownerType, requirements }) {
|
|
|
170
276
|
}
|
|
171
277
|
const isSet = (x) => x.names.some((n) => listed.names.has(n.toUpperCase()));
|
|
172
278
|
const missingRequired = requirements.secrets.filter((x) => x.required && !isSet(x));
|
|
173
|
-
const missingOptional = requirements.secrets.filter(
|
|
279
|
+
const missingOptional = requirements.secrets.filter(
|
|
280
|
+
(x) =>
|
|
281
|
+
!x.required &&
|
|
282
|
+
!isModelCredential(x) &&
|
|
283
|
+
!x.uses.every(({ input }) => input === APP_INPUT) &&
|
|
284
|
+
!isSet(x),
|
|
285
|
+
);
|
|
286
|
+
const claudeCode = claudeCodeJobs(requirements.secrets);
|
|
287
|
+
const uncredentialed = perStageCredential ? [] : jobsWithoutCredential(claudeCode, isSet);
|
|
288
|
+
const doubled = perStageCredential ? [] : jobsWithTwoCredentials(claudeCode, isSet);
|
|
289
|
+
const unpassed = perStageCredential ? [] : noCredential;
|
|
174
290
|
const describe = (x) => `${x.names.join(" or ")} (${x.where.join(", ")})`;
|
|
175
291
|
// No --body: gh prompts for the value, so it never lands in shell history.
|
|
292
|
+
const wanted = [...missingRequired, ...uncredentialed.map((x) => x.first), ...missingOptional];
|
|
176
293
|
const { fix, notes } = splitFixes(
|
|
177
|
-
[...
|
|
294
|
+
[...new Set(wanted.map((x) => x.names[0]))].map((name) => setCommand("secret", name, repo)),
|
|
178
295
|
);
|
|
179
296
|
const details = [
|
|
180
297
|
...problems,
|
|
298
|
+
...doubled.map(
|
|
299
|
+
(x) =>
|
|
300
|
+
`two model credentials set: ${x.names} (${x.where.join(", ")}); every run fails. ` +
|
|
301
|
+
"Delete one: the API key is the supported path.",
|
|
302
|
+
),
|
|
181
303
|
...missingRequired.map((x) => `required, not set: ${describe(x)}`),
|
|
304
|
+
...uncredentialed.map(
|
|
305
|
+
(x) =>
|
|
306
|
+
`no model credential set: ${x.names} (${x.where.join(", ")}); the run fails without one`,
|
|
307
|
+
),
|
|
182
308
|
...missingOptional.map((x) => `optional, not set: ${describe(x)}`),
|
|
309
|
+
...unpassed,
|
|
183
310
|
...unsupported,
|
|
184
311
|
...notes,
|
|
185
312
|
];
|
|
186
|
-
if (listed.orgNote &&
|
|
313
|
+
if (listed.orgNote && wanted.length) {
|
|
187
314
|
details.push(listed.orgNote);
|
|
188
315
|
}
|
|
189
|
-
if (missingRequired.length || problems.length) {
|
|
190
|
-
const summary =
|
|
191
|
-
|
|
192
|
-
|
|
316
|
+
if (missingRequired.length || problems.length || doubled.length) {
|
|
317
|
+
const summary = [
|
|
318
|
+
missingRequired.length && `${missingRequired.length} required secret(s) missing.`,
|
|
319
|
+
doubled.length && "Two model credentials are set for the Deep scan.",
|
|
320
|
+
problems.length && `${problems.length} Caller problem(s) with secrets.`,
|
|
321
|
+
]
|
|
322
|
+
.filter(Boolean)
|
|
323
|
+
.join(" ");
|
|
193
324
|
return result(ID, TITLE, "fail", summary, { details, fix });
|
|
194
325
|
}
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
326
|
+
const bare = uncredentialed.length + unpassed.length;
|
|
327
|
+
if (bare || missingOptional.length) {
|
|
328
|
+
const summary = [
|
|
329
|
+
bare && "Some jobs have no model credential.",
|
|
330
|
+
missingOptional.length &&
|
|
331
|
+
`${missingOptional.length} optional secret(s) referenced but not set.`,
|
|
332
|
+
]
|
|
333
|
+
.filter(Boolean)
|
|
334
|
+
.join(" ");
|
|
335
|
+
return result(ID, TITLE, "warn", summary, { details, fix });
|
|
203
336
|
}
|
|
204
337
|
if (unsupported.length) {
|
|
205
338
|
return result(
|
|
@@ -210,17 +343,14 @@ export function checkSecrets({ github, repo, ownerType, requirements }) {
|
|
|
210
343
|
{ details: unsupported },
|
|
211
344
|
);
|
|
212
345
|
}
|
|
213
|
-
return result(
|
|
214
|
-
ID,
|
|
215
|
-
TITLE,
|
|
216
|
-
"pass",
|
|
217
|
-
`All ${requirements.secrets.length} secret(s) the Callers pass are set.`,
|
|
218
|
-
);
|
|
346
|
+
return result(ID, TITLE, "pass", "Every secret the Callers need is set.");
|
|
219
347
|
}
|
|
220
348
|
|
|
221
349
|
/**
|
|
222
|
-
* Variables ADR 0009
|
|
223
|
-
*
|
|
350
|
+
* Variables the kit renamed (ADR 0009, then ADR 0022), old name to new: the
|
|
351
|
+
* Deprecation register's variable entries. A replacement may be an old name
|
|
352
|
+
* itself. The Callers have no fallback to an old name, so one still set does
|
|
353
|
+
* nothing once the Caller reads a newer one.
|
|
224
354
|
*/
|
|
225
355
|
export const RENAMED_VARIABLES = {
|
|
226
356
|
CLAUDE_PIPELINE_ENABLED: "CLAUDE_AGENT_FLOW_ENABLED",
|
|
@@ -229,8 +359,37 @@ export const RENAMED_VARIABLES = {
|
|
|
229
359
|
CLAUDE_MODEL_REVIEW: "CLAUDE_REVIEW_MODEL",
|
|
230
360
|
CLAUDE_MODEL_REVIEW_RESPONSE: "CLAUDE_REVIEW_RESPONSE_MODEL",
|
|
231
361
|
CLAUDE_MODEL_AUDIT: "CLAUDE_SECURITY_AUDIT_MODEL",
|
|
362
|
+
CLAUDE_AGENT_FLOW_ENABLED: "AGENT_KIT_AGENT_FLOW_ENABLED",
|
|
363
|
+
CLAUDE_SECURITY_AUDIT_ENABLED: "AGENT_KIT_SECURITY_AUDIT_ENABLED",
|
|
364
|
+
CLAUDE_REVIEW_RESPONSE_ENABLED: "AGENT_KIT_REVIEW_RESPONSE_ENABLED",
|
|
365
|
+
CLAUDE_DEEP_SCAN_ENABLED: "AGENT_KIT_DEEP_SCAN_ENABLED",
|
|
366
|
+
CLAUDE_PLAN_ENABLED: "AGENT_KIT_PLAN_ENABLED",
|
|
367
|
+
CLAUDE_IMPLEMENT_ENABLED: "AGENT_KIT_IMPLEMENT_ENABLED",
|
|
368
|
+
CLAUDE_REVIEW_ENABLED: "AGENT_KIT_REVIEW_ENABLED",
|
|
369
|
+
CLAUDE_MODEL: "AGENT_KIT_MODEL",
|
|
370
|
+
CLAUDE_EFFORT: "AGENT_KIT_EFFORT",
|
|
371
|
+
CLAUDE_PLAN_MODEL: "AGENT_KIT_PLAN_MODEL",
|
|
372
|
+
CLAUDE_PLAN_EFFORT: "AGENT_KIT_PLAN_EFFORT",
|
|
373
|
+
CLAUDE_IMPLEMENT_MODEL: "AGENT_KIT_IMPLEMENT_MODEL",
|
|
374
|
+
CLAUDE_IMPLEMENT_EFFORT: "AGENT_KIT_IMPLEMENT_EFFORT",
|
|
375
|
+
CLAUDE_REVIEW_MODEL: "AGENT_KIT_REVIEW_MODEL",
|
|
376
|
+
CLAUDE_REVIEW_EFFORT: "AGENT_KIT_REVIEW_EFFORT",
|
|
377
|
+
CLAUDE_REVIEW_RESPONSE_MODEL: "AGENT_KIT_REVIEW_RESPONSE_MODEL",
|
|
378
|
+
CLAUDE_REVIEW_RESPONSE_EFFORT: "AGENT_KIT_REVIEW_RESPONSE_EFFORT",
|
|
379
|
+
CLAUDE_SECURITY_AUDIT_MODEL: "AGENT_KIT_SECURITY_AUDIT_MODEL",
|
|
380
|
+
CLAUDE_SECURITY_AUDIT_EFFORT: "AGENT_KIT_SECURITY_AUDIT_EFFORT",
|
|
381
|
+
CLAUDE_DEEP_SCAN_MODEL: "AGENT_KIT_DEEP_SCAN_MODEL",
|
|
382
|
+
CLAUDE_DEEP_SCAN_EFFORT: "AGENT_KIT_DEEP_SCAN_EFFORT",
|
|
383
|
+
CLAUDE_REVIEW_RESPONSE_MODE: "AGENT_KIT_REVIEW_RESPONSE_MODE",
|
|
232
384
|
};
|
|
233
385
|
|
|
386
|
+
/** The first name `read` holds among those `oldName` was renamed to, or null. */
|
|
387
|
+
function replacementRead(oldName, read) {
|
|
388
|
+
let name = RENAMED_VARIABLES[oldName];
|
|
389
|
+
while (name && !read.has(name)) name = RENAMED_VARIABLES[name];
|
|
390
|
+
return name ?? null;
|
|
391
|
+
}
|
|
392
|
+
|
|
234
393
|
const killSwitch = (name) => /_ENABLED$/.test(name);
|
|
235
394
|
|
|
236
395
|
export function checkVariables({ github, repo, ownerType, requirements }) {
|
|
@@ -247,9 +406,11 @@ export function checkVariables({ github, repo, ownerType, requirements }) {
|
|
|
247
406
|
const missing = required.filter((v) => !isSet(v.name));
|
|
248
407
|
// An old name still set while a Caller reads its replacement: the value is ignored.
|
|
249
408
|
const read = new Map(requirements.variables.map((v) => [v.name.toUpperCase(), v]));
|
|
250
|
-
const renamed = Object.
|
|
251
|
-
.filter(
|
|
252
|
-
.map((
|
|
409
|
+
const renamed = Object.keys(RENAMED_VARIABLES)
|
|
410
|
+
.filter(isSet)
|
|
411
|
+
.map((oldName) => ({ oldName, newName: replacementRead(oldName, read) }))
|
|
412
|
+
.filter(({ newName }) => newName)
|
|
413
|
+
.map((r) => ({ ...r, v: read.get(r.newName), stillRead: read.get(r.oldName) }));
|
|
253
414
|
if (missing.length === 0 && renamed.length === 0) {
|
|
254
415
|
return result(ID, TITLE, "pass", `All ${required.length} required variable(s) are set.`);
|
|
255
416
|
}
|
|
@@ -261,29 +422,45 @@ export function checkVariables({ github, repo, ownerType, requirements }) {
|
|
|
261
422
|
? " — the Kill switch: the flow never runs until it is set to true"
|
|
262
423
|
: ""),
|
|
263
424
|
),
|
|
264
|
-
...renamed.map(
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
425
|
+
...renamed.map(({ oldName, newName, v, stillRead }) => {
|
|
426
|
+
const start = `renamed: ${oldName} is still set, but ${newName} replaces it (${v.where.join(", ")}). `;
|
|
427
|
+
// Callers part-way through an upgrade: the old name still does something.
|
|
428
|
+
if (stillRead) {
|
|
429
|
+
return (
|
|
430
|
+
`${start}${oldName} is still read by ${stillRead.where.join(", ")}: ` +
|
|
431
|
+
(isSet(newName) ? "" : `set ${newName} to its value, and `) +
|
|
432
|
+
`delete ${oldName} once no Caller reads it.`
|
|
433
|
+
);
|
|
434
|
+
}
|
|
435
|
+
return (
|
|
436
|
+
`${start}${oldName} is ignored: ` +
|
|
268
437
|
(isSet(newName)
|
|
269
438
|
? `${newName} is set too, so delete ${oldName}.`
|
|
270
|
-
: `set ${newName} to its value, then delete ${oldName}.`)
|
|
271
|
-
|
|
439
|
+
: `set ${newName} to its value, then delete ${oldName}.`)
|
|
440
|
+
);
|
|
441
|
+
}),
|
|
272
442
|
];
|
|
273
443
|
if (listed.orgNote && missing.length) details.push(listed.orgNote);
|
|
274
|
-
//
|
|
444
|
+
// A missing Kill switch takes true; for anything else, gh prompts for the
|
|
445
|
+
// value: a renamed Stage switch may have been set to false.
|
|
446
|
+
const turnsOn = new Set(missing.map((v) => v.name));
|
|
275
447
|
const toSet = [
|
|
276
448
|
...missing.map((v) => v.name),
|
|
277
449
|
...renamed.filter((r) => !isSet(r.newName)).map((r) => r.newName),
|
|
278
450
|
].filter((name, i, all) => all.indexOf(name) === i);
|
|
279
451
|
const { fix, notes } = splitFixes(
|
|
280
452
|
toSet.map((name) =>
|
|
281
|
-
setCommand(
|
|
453
|
+
setCommand(
|
|
454
|
+
"variable",
|
|
455
|
+
name,
|
|
456
|
+
repo,
|
|
457
|
+
turnsOn.has(name) && killSwitch(name) ? ["--body", "true"] : [],
|
|
458
|
+
),
|
|
282
459
|
),
|
|
283
460
|
);
|
|
284
461
|
// Each old name goes last, once its replacement has a value: deleting first
|
|
285
462
|
// would lose the value before it is copied. The old names are the kit's own.
|
|
286
|
-
for (const { oldName } of renamed) {
|
|
463
|
+
for (const { oldName } of renamed.filter((r) => !r.stillRead)) {
|
|
287
464
|
fix.push(command("gh", "variable", "delete", oldName, "--repo", repo));
|
|
288
465
|
}
|
|
289
466
|
if (missing.length) {
|