@mnaimfaizy/agent-kit 1.0.0-beta.1 → 1.0.0-beta.10
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 +8 -3
- package/package.json +1 -1
- package/src/callers.mjs +35 -10
- package/src/checks/kit-owned-trees.mjs +45 -2
- package/src/checks/review-response.mjs +205 -0
- package/src/checks/rulesets.mjs +7 -2
- package/src/checks/scan-recipe.mjs +56 -0
- package/src/checks/secrets-and-variables.mjs +65 -15
- package/src/cli.mjs +163 -8
- package/src/deep-scan/agent.mjs +410 -0
- package/src/deep-scan/claude-code.mjs +25 -0
- package/src/deep-scan/credential.mjs +215 -0
- package/src/deep-scan/docker-driver.mjs +696 -0
- package/src/deep-scan/egress.mjs +150 -0
- package/src/deep-scan/lifecycle.mjs +703 -0
- package/src/deep-scan/limits.mjs +126 -0
- package/src/deep-scan/model-proxy.mjs +378 -0
- package/src/deep-scan/preflight.mjs +78 -0
- package/src/deep-scan/recipe.mjs +447 -0
- package/src/deep-scan/relay-script.mjs +98 -0
- package/src/deep-scan/relay.mjs +130 -0
- package/src/deep-scan/runtime.mjs +181 -0
- package/src/deep-scan/sbx-driver.mjs +501 -0
- package/src/deep-scan/steps.mjs +47 -0
- package/src/deep-scan/tar.mjs +84 -0
- package/src/deep-scan/verify.mjs +272 -0
- package/src/deep-scan.mjs +474 -0
- package/src/doctor.mjs +14 -10
- package/src/exec.mjs +222 -33
- package/src/init.mjs +35 -9
- package/src/kit-owned-paths.mjs +5 -3
- package/src/kit-tag.mjs +12 -3
- package/src/local-tree.mjs +69 -4
- package/src/local-writes.mjs +4 -33
- package/src/templates.mjs +12 -8
- package/src/workflow-call.mjs +3 -5
- package/src/yaml-subset.mjs +134 -24
package/README.md
CHANGED
|
@@ -5,18 +5,23 @@ The command-line companion to [Agent-kit](https://github.com/mnaimfaizy/agent-ki
|
|
|
5
5
|
```bash
|
|
6
6
|
npx @mnaimfaizy/agent-kit init --tag <tag> # first adoption (asks first)
|
|
7
7
|
npx @mnaimfaizy/agent-kit doctor # local run with your own gh login
|
|
8
|
-
npx @mnaimfaizy/agent-kit doctor --ci # Kit-owned paths and
|
|
8
|
+
npx @mnaimfaizy/agent-kit doctor --ci # Kit-owned paths, pins and the Scan recipe only
|
|
9
9
|
npx @mnaimfaizy/agent-kit doctor --strict # warnings fail too
|
|
10
10
|
npx @mnaimfaizy/agent-kit upgrade --tag <new-tag> # move to another tag (asks first)
|
|
11
|
+
npx @mnaimfaizy/agent-kit deep-scan # Deep scan: recipe, pre-flight, runtime, sandbox, agent
|
|
12
|
+
npx @mnaimfaizy/agent-kit deep-scan --verify findings.md --ref fix/x # Verification run: does the fix hold?
|
|
11
13
|
```
|
|
12
14
|
|
|
13
15
|
- The package holds only code. Kit files are read from the git tag your `uses:` pins name, never bundled.
|
|
16
|
+
- `doctor` checks, from your Callers, every secret and repository variable they read (each flow's Kill switch, such as `CLAUDE_REVIEW_RESPONSE_ENABLED`, is required; a Stage switch such as `CLAUDE_PLAN_ENABLED` is optional), and warns about a variable [ADR 0009](../docs/adr/0009-stage-settings-resolve-in-the-caller.md) renamed that is still set under its old name, naming the new one, every Trigger label they use (such as `agent:address-review`), the Claude GitHub App, and the rulesets. With a Review response Caller, it reports `CLAUDE_REVIEW_RESPONSE_MODE`: unset or `manual` passes as manual, any other value but `auto` warns, and `auto` fails unless the review Caller passes `response_mode` and a `response_workflow` naming a Review response Caller that passes `response_mode` and has a `workflow_dispatch` trigger with a `pr_number` input.
|
|
14
17
|
- `doctor` is read-only. It runs git in your checkout without hooks or configured filter commands, never changes files or GitHub settings, and for anything to fix prints a POSIX-shell `gh` command for you to run.
|
|
15
18
|
- No runtime dependencies. Needs Node.js 22 or later, `git`, and (outside `--ci`) `gh` logged in with admin on the repository.
|
|
16
19
|
- Tags before `v1.0.0-alpha.11` have no `kit-owned-paths.txt`, and the CLI refuses them: adopt those by hand with that tag's `docs/adopt.md`.
|
|
17
20
|
- `upgrade --tag <vY>` reads the current tag from your Agent-kit `uses:` pins (they must agree), replaces each Kit-owned path vY lists (delete, then copy), deletes paths only the old tag listed, rewrites only the `@<tag>` of those pins, prints the `examples/` diff between the two tags for you to apply by hand, and then runs the `doctor --ci` checks. Every refusal is checked before anything is written. It refuses a path with uncommitted changes unless `--force`, refuses symbolic links in or above a Kit-owned path, and copies only regular and executable files from the tag. Ignored files inside a replaced path are deleted with it, and listed first. After a Dependabot pin bump, when the pins already name vY, add `--from <vX>` to also delete paths only vX listed and see the `examples/` diff. It asks before writing; pass `--yes` when there is no terminal. It writes only local files and commits nothing; where `core.fileMode` is off (Windows), it stages each copied file with the tag's mode (`git add --chmod=+x` or `-x`), so the executable bit is neither lost nor kept by mistake.
|
|
18
|
-
- `init --tag <vX>` copies the Kit-owned paths, writes `.github/workflows/agent-pipeline.yml` and/or `
|
|
21
|
+
- `init --tag <vX>` copies the Kit-owned paths, writes `.github/workflows/agent-pipeline.yml`, `security-audit.yml` and/or `agent-review-response.yml` from the tag's `examples/` with your answers filled in (`--flows pipeline,audit,review-response`, `--actors`, `--default-branch`, `--verify`, `--preset`), writes the Threat pack skeleton to `.security/` (or `--threat-pack-dir`) and `.github/dependabot.yml` if there is none, and prints the GitHub-side steps as `gh` commands. It refuses to overwrite an existing Caller or Kit-owned path without `--force`, never overwrites an existing Threat pack file, and leaves Kit-owned paths that already match the tag alone (so `init --flows audit` later adds that flow); use `upgrade` to change tags. `--yes` asks nothing.
|
|
22
|
+
- `deep-scan` is the launcher for a Deep scan. First it reads the Scan recipe (`.security/scan-recipe.yml`, or `--recipe <path>` relative to the repository root) as committed on the default branch (origin's HEAD, else `main`, or `--default-branch <b>`), never from the working tree, and validates it. With no recipe or an invalid one it refuses, lists every problem with its field, points to [the recipe format](../docs/security-audit.md#scan-recipe), and exits 1; it never falls back to a `full` audit. Then the pre-flight refusals: it refuses, exit 1, when `GH_TOKEN` or `GITHUB_TOKEN` is set in its environment, or when the default branch has a committed `.env` (or `.env.<name>`, templates aside) that the copy-in would forward wholesale. It also refuses, exit 1, when the default branch has no security-audit `DEEP.md` or no Threat pack, or when it has no model credential: an Anthropic API key from `ANTHROPIC_API_KEY`, or with `--credential-from env:<NAME>` another variable, or `--credential-from op://<vault>/<item>/<field>` 1Password through `op read` (see [Credentials](../docs/security-audit.md#credentials)). `--credential-from` never takes the key itself (a usage error, exit 2, that never prints it), and the key never reaches any command the launcher runs. With `--credential subscription` it runs instead on a Claude subscription token (from `claude setup-token`; read from `CLAUDE_CODE_OAUTH_TOKEN` by default, or `--credential-from` as for a key), an opt-in at your own risk: it relies on undocumented behaviour and may break with any Claude Code release, has no refresh, so you rotate the token by hand, leaves the terms question to you, and the proxy's token cap is the only spend lever. On that path the sandbox holds a placeholder `CLAUDE_CODE_OAUTH_TOKEN`, Claude Code runs without `--bare` (so it discovers the scanned repository's `CLAUDE.md` and skills, which the brief marks as content, not instructions) and with `--strict-mcp-config`, and the proxy swaps only the `Authorization: Bearer` value, never sending `x-api-key`. A subscription token without `--credential subscription`, or anything but one with it, is refused, exit 1, without printing it ([the subscription path](../docs/security-audit.md#the-subscription-path-opt-in)). Then it chooses a [sandbox runtime](../docs/security-audit.md#sandbox-runtimes) from the host, in this order: Docker Sandboxes (`sbx`), Kata Containers or Firecracker on Linux, gVisor (`runsc`) on Linux, the last two on Docker Engine 28.0 or later; a Mac uses Docker Sandboxes. It refuses, exit 1, plain Docker on Linux, Docker Engine older than 28.0 (naming the version found and the minimum), Docker Desktop on Windows with WSL 2, Docker Desktop on macOS (naming Docker Sandboxes), and anything else, naming the accepted runtimes and the CI path; there is no override flag. Those checks run only read-only `git` commands and read-only probes of the runtimes' CLIs (`sbx version`, `docker info`, `<cli> --version`). Then it runs [the sandbox](../docs/security-audit.md#what-goes-into-and-out-of-the-sandbox) on the chosen runtime, through `docker`: it pulls the recipe's image (or builds its Dockerfile from the default branch) and layers a pinned Claude Code with the auto-updater off; starts the sandbox with no mount; copies in a `git archive` of the default branch's tip and the recipe's grounding; runs `setup`, `start`, `ready` and `seed` with egress only to the recipe's `registries`, through a proxy it runs on the host (a failing step ends the run, exit 1, with its output); cuts setup's egress (stops its proxy and removes its relay) and checks from the host that nothing is left to reach; opens the model route, a key-injecting proxy on the host that forwards only to the model API and swaps the sandbox's placeholder key for the real one, through its own relay, and checks from the host that the sandbox reaches that relay alone; runs the real Claude Code with `--bare`, a placeholder `ANTHROPIC_API_KEY`, `ANTHROPIC_BASE_URL` pinned by its own `--settings` (project settings are not loaded) and no web tools, handing it the deep procedure, the Threat pack and the recipe; copies out the one report file to a new private folder and prints its path (nothing is filed or posted); and removes the sandbox, relays, probes, networks and images on every exit path, Ctrl+C and `SIGTERM` included (exit 130 or 143). It exits 0 when the report came out. On Docker Engine the sandbox has one network, attached at `docker run` and never connected or disconnected after (a running gVisor sandbox would not see it), `--internal` and in Docker's `isolated` gateway mode, so the host has no address on it; it reaches each proxy only through a relay container on it, built on stdin from an official `node` image pinned by digest and a digest-checked Node-core script, which forwards the proxy's one port. The host checks the network's mode and that the sandbox is on it alone, and a probe container, run under the sandbox's own runtime, checks the routes before the target starts, after the cut and before the agent step. Copy-in unpacks with the sandbox's own `tar`, so a hostile setup step could alter the brief on its way in; the target already controls the sandbox. Every run is bounded by [limits](../docs/security-audit.md#limits), all enforced outside the sandbox and never set by the recipe: a setup wall clock (`--setup-minutes <n>`, default 20), a scan wall clock (`--scan-minutes <n>`, default 60), Claude Code's turn limit (`--max-turns <n>`, default 200) and the model proxy's token cap for the run (`--max-tokens <n>`, default 5000000, counting input, output and cache tokens from the model API's `usage`). A value that is not a positive number is a usage error, exit 2. A limit that fires stops the running step, copies out the report so far with a `Stopped: wall clock | turns | tokens` line added after `Finding count`, tears down and exits 3; with no report, it writes nothing and prints only `Stopped:` and the limit's name. On Docker Sandboxes it does the same through `sbx`: it first refuses, exit 1, unless your global sbx network policy is deny-all (read with `sbx policy ls --json`, never changed), builds its template with Docker on the host (Docker Desktop on Windows): it pulls the recipe's `image`, layers the pinned Claude Code and a non-root `agent` user (uid 1000, home `/home/agent`, the image's `USER`) on it, as Docker's docs require of a template, after checking it has curl, git, CA certificates and bash (sbx starts only an sbx-ready image), and loads it with `sbx template load` (a `dockerfile` is refused); then it creates the sandbox mountless from that template, opens setup egress with per-sandbox `sbx policy` rules that it removes for the cut; the model route is one more per-sandbox rule, for the model proxy alone (`host.docker.internal:<port>` from the sandbox, which sbx's policy names `localhost:<port>`), and teardown also removes the template and the layered image. Its process allowlist is `git`, `sbx`, `docker`, `runsc`, `kata-runtime`, `firecracker` and the 1Password CLI `op`; `init`, `upgrade` and `doctor` still run only `git` and `gh`. `doctor` reports whether the recipe is at its default path and valid. `--model <id>` names the model the agent runs on (a plain id; Claude Code's default without it), `--effort <level>` its effort level (`low`, `medium`, `high`, `xhigh` or `max`, passed to Claude Code as `--effort`; Claude Code's default without it, and anything else is a usage error, exit 2), the `Agent step:` line names the model and effort asked for, the `Model proxy:` line names the model id the API answered with, `--report <path>` writes the report to that new file in a folder that exists, and in GitHub Actions (`GITHUB_ACTIONS=true`) `deep-scan` keeps the Public-log rule, printing none of Claude Code's error output, the model proxy's refusals and answers (the answered model ids included), or copy-out error detail (see [Deep scan in CI](../docs/security-audit.md#deep-scan-in-ci)).
|
|
23
|
+
- `deep-scan --verify <file> --ref <ref>` is a [Verification run](../docs/security-audit.md#verification-run): it re-attempts the Reproduction of the findings in `<file>` (each a `###` section with `- **Concept id:**`, `- **Location:**` and `- **Observation:**`, as a deep report gives them) on `<ref>`, a local branch, tag or commit such as your fix branch, exported as committed, never the working tree. The recipe, the skill and the Threat pack still come from the default branch. It is confirm-only (no `full` walk, no exploration, no new findings): the agent gets the Verification-run procedure, not the full deep procedure, and the finding file goes in with its brief after the network cut. Its defaults are scan 15 min, 50 turns and the same token cap. Each flag needs the other, and `--report` is not taken with them (usage errors, exit 2). A finding file that is missing, unreadable or out of shape, or a ref that is not a local commit, is refused, exit 1, before any runtime starts. The report goes only to a new private folder; `deep-scan` prints each finding's `Reproduced: yes` (the fix does not hold) or `no` (it holds), exits 1 if the report misses one, and files or posts nothing. It is local only: refused, exit 1, in GitHub Actions (`GITHUB_ACTIONS=true`).
|
|
19
24
|
|
|
20
|
-
The package version matches the Agent-kit Release line: `@mnaimfaizy/agent-kit@1.0.0-beta.
|
|
25
|
+
The package version matches the Agent-kit Release line: `@mnaimfaizy/agent-kit@1.0.0-beta.10` is published from tag `v1.0.0-beta.10`, with npm provenance.
|
|
21
26
|
|
|
22
27
|
Full documentation: [Getting started](https://github.com/mnaimfaizy/agent-kit/blob/main/docs/getting-started.md) and [Adopt](https://github.com/mnaimfaizy/agent-kit/blob/main/docs/adopt.md#check-an-adoption-with-doctor).
|
package/package.json
CHANGED
package/src/callers.mjs
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
import { existsSync, readdirSync, readFileSync, statSync } from "node:fs";
|
|
6
6
|
import { join } from "node:path";
|
|
7
|
-
import { parseScalar, parseYamlSubset, stripBom, stripComment } from "./yaml-subset.mjs";
|
|
7
|
+
import { isMapping, parseScalar, parseYamlSubset, stripBom, stripComment } from "./yaml-subset.mjs";
|
|
8
8
|
|
|
9
9
|
export const KIT_REPO_NAME = "agent-kit";
|
|
10
10
|
export const DEFAULT_KIT_REPO = "mnaimfaizy/agent-kit";
|
|
@@ -111,14 +111,17 @@ export function secretNames(value) {
|
|
|
111
111
|
|
|
112
112
|
/**
|
|
113
113
|
* Every `vars.X` a file reads. A variable is optional when every read of it
|
|
114
|
-
* falls back with `||` (as the model variables do)
|
|
115
|
-
* (
|
|
116
|
-
*
|
|
117
|
-
* expression.
|
|
114
|
+
* falls back with `||` (as the model variables do) or only tests `== 'false'`
|
|
115
|
+
* (a Stage switch: unset means on); otherwise it is required (the Kill switch
|
|
116
|
+
* variables: unset means the flow never runs). The `||` may follow closing
|
|
117
|
+
* parentheses, and may sit on the next line of a multi-line expression.
|
|
118
118
|
*/
|
|
119
119
|
export function variableRefs(text) {
|
|
120
120
|
const refs = new Map();
|
|
121
|
-
const re = new RegExp(
|
|
121
|
+
const re = new RegExp(
|
|
122
|
+
`vars\\.(${NAME})((?:\\s*\\))*\\s*\\|\\||\\s*==\\s*'false'(?![\\w']))?`,
|
|
123
|
+
"g",
|
|
124
|
+
);
|
|
122
125
|
for (const m of lines(text).join("\n").matchAll(re)) {
|
|
123
126
|
const optional = Boolean(m[2]);
|
|
124
127
|
const prev = refs.get(m[1]);
|
|
@@ -140,11 +143,27 @@ function unsupportedSecrets(value) {
|
|
|
140
143
|
if (value.startsWith("&")) return "`secrets:` uses a YAML anchor";
|
|
141
144
|
return `\`secrets:\` is ${JSON.stringify(value)}`;
|
|
142
145
|
}
|
|
143
|
-
if (value
|
|
146
|
+
if (Array.isArray(value)) return "`secrets:` is a list";
|
|
144
147
|
if ("<<" in value) return "`secrets:` uses a YAML merge key (<<)";
|
|
145
148
|
return null;
|
|
146
149
|
}
|
|
147
150
|
|
|
151
|
+
/**
|
|
152
|
+
* The input names of a workflow's `workflow_dispatch` trigger: [] when it
|
|
153
|
+
* takes none, null when the workflow has no such trigger. `on:` may be a
|
|
154
|
+
* mapping, one event name, or a list of names.
|
|
155
|
+
*/
|
|
156
|
+
function dispatchInputs(on) {
|
|
157
|
+
const named = (text) => /(?:^|[\s,[])workflow_dispatch(?:$|[\s,\]])/.test(text);
|
|
158
|
+
if (typeof on === "string") return named(on) ? [] : null;
|
|
159
|
+
if (!on || typeof on !== "object") return null;
|
|
160
|
+
if (Array.isArray(on)) return on.some((event) => named(String(event))) ? [] : null;
|
|
161
|
+
if (!("workflow_dispatch" in on)) return null;
|
|
162
|
+
const trigger = on.workflow_dispatch;
|
|
163
|
+
const inputs = isMapping(trigger) ? trigger.inputs : null;
|
|
164
|
+
return isMapping(inputs) ? Object.keys(inputs) : [];
|
|
165
|
+
}
|
|
166
|
+
|
|
148
167
|
/**
|
|
149
168
|
* The jobs of one workflow file that call an Agent-kit reusable workflow.
|
|
150
169
|
* `parseIncomplete` is set when the file has more Agent-kit pins than jobs
|
|
@@ -154,12 +173,12 @@ function unsupportedSecrets(value) {
|
|
|
154
173
|
export function parseCaller(text) {
|
|
155
174
|
const doc = parseYamlSubset(text);
|
|
156
175
|
const jobs = [];
|
|
157
|
-
const jobMap = doc.jobs
|
|
176
|
+
const jobMap = isMapping(doc.jobs) ? doc.jobs : {};
|
|
158
177
|
for (const [name, job] of Object.entries(jobMap)) {
|
|
159
178
|
if (!job || typeof job !== "object" || typeof job.uses !== "string") continue;
|
|
160
179
|
const uses = parseKitUses(job.uses);
|
|
161
180
|
if (!uses) continue;
|
|
162
|
-
const withBlock = job.with
|
|
181
|
+
const withBlock = isMapping(job.with) ? job.with : {};
|
|
163
182
|
const secretsUnsupported = unsupportedSecrets(job.secrets);
|
|
164
183
|
let secrets = {};
|
|
165
184
|
if (job.secrets === "inherit") secrets = "inherit";
|
|
@@ -174,7 +193,13 @@ export function parseCaller(text) {
|
|
|
174
193
|
? `${pins.length} Agent-kit pin(s) but only ${jobs.length} job(s) doctor could read; ` +
|
|
175
194
|
"the rest were not checked"
|
|
176
195
|
: null;
|
|
177
|
-
return {
|
|
196
|
+
return {
|
|
197
|
+
jobs,
|
|
198
|
+
pins,
|
|
199
|
+
variables: variableRefs(text),
|
|
200
|
+
dispatchInputs: dispatchInputs(doc.on),
|
|
201
|
+
parseIncomplete,
|
|
202
|
+
};
|
|
178
203
|
}
|
|
179
204
|
|
|
180
205
|
/** Workflow files in .github/workflows/ (relative paths, sorted). */
|
|
@@ -9,6 +9,8 @@ import { result } from "./result.mjs";
|
|
|
9
9
|
|
|
10
10
|
const ID = "kit-owned-trees";
|
|
11
11
|
const TITLE = "Kit-owned paths match the pinned tag";
|
|
12
|
+
/** A Kit-owned skill folder, capturing the skill's name. */
|
|
13
|
+
const SKILL_DIR = /^\.claude\/skills\/([^/]+)\/$/;
|
|
12
14
|
|
|
13
15
|
/**
|
|
14
16
|
* @param {{ runner: import("../exec.mjs").Runner, cwd: string, snapshot: { tag: string, kitOwnedPaths: string[], treeHash: (p: string) => string | null } }} opts
|
|
@@ -16,11 +18,24 @@ const TITLE = "Kit-owned paths match the pinned tag";
|
|
|
16
18
|
export function checkKitOwnedTrees({ runner, cwd, snapshot }) {
|
|
17
19
|
const { tag, kitOwnedPaths } = snapshot;
|
|
18
20
|
const repo = snapshot.repo ?? DEFAULT_KIT_REPO;
|
|
19
|
-
const { hashes, skipped, notes } = localTreeHashes({ runner, cwd, paths: kitOwnedPaths });
|
|
21
|
+
const { hashes, skipped, notes, links } = localTreeHashes({ runner, cwd, paths: kitOwnedPaths });
|
|
20
22
|
const serverUrl = snapshot.serverUrl ?? "https://github.com";
|
|
21
23
|
const bad = [];
|
|
22
24
|
const notChecked = [];
|
|
25
|
+
const linkedSkills = [];
|
|
23
26
|
for (const path of kitOwnedPaths) {
|
|
27
|
+
if (links.has(path)) {
|
|
28
|
+
const link = links.get(path);
|
|
29
|
+
// npx skills links the skill folder itself. A link inside it, or above it
|
|
30
|
+
// (a shared .claude/skills, say), is the Consumer's own, so no hint to remove it.
|
|
31
|
+
const skill = link === path.replace(/\/$/, "") ? SKILL_DIR.exec(path)?.[1] : undefined;
|
|
32
|
+
bad.push(
|
|
33
|
+
`${path}: ${link} is a symbolic link or junction, where the tag ships plain files` +
|
|
34
|
+
(skill ? ` (installing the skill with \`npx skills\` does this)` : ""),
|
|
35
|
+
);
|
|
36
|
+
if (skill) linkedSkills.push({ skill, link });
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
24
39
|
if (skipped.has(path)) {
|
|
25
40
|
notChecked.push(`${path}: not checked, ${skipped.get(path)}`);
|
|
26
41
|
continue;
|
|
@@ -36,6 +51,16 @@ export function checkKitOwnedTrees({ runner, cwd, snapshot }) {
|
|
|
36
51
|
}
|
|
37
52
|
}
|
|
38
53
|
const howCompared = [...notes].map(([path, note]) => `${path}: ${note}`);
|
|
54
|
+
// A link at or inside a Kit-owned path goes when upgrade replaces the path whole
|
|
55
|
+
// (with --force, since its files then show as deleted). One above every Kit-owned
|
|
56
|
+
// path (a linked .claude/skills, say) is the Consumer's to sort out.
|
|
57
|
+
const linked = [...links].map(([path, link]) => ({ folder: path.replace(/\/$/, ""), link }));
|
|
58
|
+
const unique = (list) => [...new Set(list.map(({ link }) => link))];
|
|
59
|
+
const linksAtOrInside = unique(
|
|
60
|
+
linked.filter(({ folder, link }) => link === folder || link.startsWith(`${folder}/`)),
|
|
61
|
+
);
|
|
62
|
+
const linksAbove = unique(linked.filter(({ folder, link }) => folder.startsWith(`${link}/`)));
|
|
63
|
+
const named = (list) => (list.length === 1 ? `${list[0]} is` : `${list.join(", ")} are`);
|
|
39
64
|
const checked = kitOwnedPaths.length - notChecked.length;
|
|
40
65
|
if (bad.length === 0 && notChecked.length === 0) {
|
|
41
66
|
return result(ID, TITLE, "pass", `All ${kitOwnedPaths.length} Kit-owned paths match ${tag}.`, {
|
|
@@ -62,12 +87,30 @@ export function checkKitOwnedTrees({ runner, cwd, snapshot }) {
|
|
|
62
87
|
...bad,
|
|
63
88
|
...notChecked,
|
|
64
89
|
...howCompared,
|
|
90
|
+
...linkedSkills.map(
|
|
91
|
+
({ skill, link }) =>
|
|
92
|
+
`To restore ${skill}, remove the link ${link} (and the copy npx skills made at ` +
|
|
93
|
+
`.agents/skills/${skill}/), then run the command below: a Consumer gets Kit-owned ` +
|
|
94
|
+
`skills from the tag, not from npx skills.`,
|
|
95
|
+
),
|
|
96
|
+
...(linksAtOrInside.length
|
|
97
|
+
? [
|
|
98
|
+
`--force: once ${named(linksAtOrInside)} gone, the files show as deleted, which upgrade ` +
|
|
99
|
+
`otherwise refuses as uncommitted changes. It discards changes in Kit-owned paths only.`,
|
|
100
|
+
]
|
|
101
|
+
: []),
|
|
102
|
+
...linksAbove.map(
|
|
103
|
+
(link) =>
|
|
104
|
+
`${link} is a link: Kit-owned paths must be real folders in the repository, not reached ` +
|
|
105
|
+
`through a link to somewhere else. Whether to replace it (and keep what it points to) ` +
|
|
106
|
+
`is your call; upgrade refuses to write through it, with or without --force.`,
|
|
107
|
+
),
|
|
65
108
|
`Kit-owned paths are replaced whole from the tag your pins name, never edited.`,
|
|
66
109
|
`If a pin bump (for example from Dependabot) moved the pins to ${tag}, re-copy them on the same branch.`,
|
|
67
110
|
`Run the command below, or delete and re-copy each path by hand as ` +
|
|
68
111
|
`${manualCopyUrl(repo, tag, serverUrl)} describes.`,
|
|
69
112
|
],
|
|
70
|
-
fix: [upgradeCommand(tag)],
|
|
113
|
+
fix: [linksAtOrInside.length ? `${upgradeCommand(tag)} --force` : upgradeCommand(tag)],
|
|
71
114
|
},
|
|
72
115
|
);
|
|
73
116
|
}
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
// Review response mode: what CLAUDE_REVIEW_RESPONSE_MODE is set to, and, in
|
|
2
|
+
// auto mode, whether the Callers carry what the Handoff needs. The Trigger
|
|
3
|
+
// label and the Kill switch variable are covered by the trigger-labels and
|
|
4
|
+
// variables checks, which read them from the Callers like any other flow's.
|
|
5
|
+
//
|
|
6
|
+
// Auto mode needs both ends wired: the review Caller passes `response_mode`
|
|
7
|
+
// and names the Review response Caller in `response_workflow`, and that
|
|
8
|
+
// Caller passes `response_mode` and takes a `workflow_dispatch` with a
|
|
9
|
+
// `pr_number` input. Anything short of that never starts a round, without an
|
|
10
|
+
// error anywhere a Consumer would look.
|
|
11
|
+
|
|
12
|
+
import { result } from "./result.mjs";
|
|
13
|
+
|
|
14
|
+
const ID = "review-response-mode";
|
|
15
|
+
const TITLE = "Review response mode is set up";
|
|
16
|
+
export const MODE_VARIABLE = "CLAUDE_REVIEW_RESPONSE_MODE";
|
|
17
|
+
const RESPONSE_REUSABLE = "agent-review-response-reusable.yml";
|
|
18
|
+
const REVIEW_REUSABLE = "agent-review-reusable.yml";
|
|
19
|
+
/** What the review workflow's handoff accepts as `response_workflow`. */
|
|
20
|
+
const WORKFLOW_PATH = /^\.github\/workflows\/[A-Za-z0-9_-][A-Za-z0-9._-]*\.ya?ml$/;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* The variable's value as a workflow run sees it: the repository's, else the
|
|
24
|
+
* organization's. null when neither sets it. Throws when it cannot be read.
|
|
25
|
+
*/
|
|
26
|
+
export function readMode(github, repo, ownerType) {
|
|
27
|
+
try {
|
|
28
|
+
return String(github.getJson(`repos/${repo}/actions/variables/${MODE_VARIABLE}`).value ?? "");
|
|
29
|
+
} catch (err) {
|
|
30
|
+
if (err?.httpStatus !== 404) throw err;
|
|
31
|
+
}
|
|
32
|
+
if (ownerType !== "Organization") return null;
|
|
33
|
+
const lines = github.getLines(
|
|
34
|
+
`repos/${repo}/actions/organization-variables`,
|
|
35
|
+
`.variables[] | select(.name == "${MODE_VARIABLE}") | .value`,
|
|
36
|
+
);
|
|
37
|
+
return lines.length ? lines[0] : null;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const jobsUsing = (callers, file) =>
|
|
41
|
+
callers.flatMap((caller) =>
|
|
42
|
+
caller.jobs
|
|
43
|
+
.filter((job) => job.uses.file === file)
|
|
44
|
+
.map((job) => ({ caller, job, where: `${caller.path}:${job.name}` })),
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
const passes = (job, input) =>
|
|
48
|
+
typeof job.with?.[input] === "string" && job.with[input].trim() !== "";
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Where a job's `response_mode` comes from: "auto" (the literal), "variable"
|
|
52
|
+
* (an expression reading the mode variable), "other" (anything else), or
|
|
53
|
+
* null when the job does not pass it.
|
|
54
|
+
*/
|
|
55
|
+
export function modeSource(job) {
|
|
56
|
+
if (!passes(job, "response_mode")) return null;
|
|
57
|
+
const value = job.with.response_mode.trim();
|
|
58
|
+
if (value === "auto") return "auto";
|
|
59
|
+
// An expression that reads the variable: `${{ vars.CLAUDE_REVIEW_RESPONSE_MODE || 'manual' }}`.
|
|
60
|
+
if (/^\$\{\{.*\bvars\.CLAUDE_REVIEW_RESPONSE_MODE\b.*\}\}$/i.test(value)) return "variable";
|
|
61
|
+
return "other";
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** Does any Caller hardcode `response_mode: auto`, whatever the variable says? */
|
|
65
|
+
const hardcodesAuto = (callers) =>
|
|
66
|
+
[...jobsUsing(callers, RESPONSE_REUSABLE), ...jobsUsing(callers, REVIEW_REUSABLE)].some(
|
|
67
|
+
({ job }) => modeSource(job) === "auto",
|
|
68
|
+
);
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Why a job would not see `auto` as its `response_mode`, given the
|
|
72
|
+
* variable's value; null when it would.
|
|
73
|
+
*/
|
|
74
|
+
function notAuto(job, mode, consequence) {
|
|
75
|
+
const source = modeSource(job);
|
|
76
|
+
if (source === null) {
|
|
77
|
+
return `does not pass response_mode (vars.${MODE_VARIABLE}), so ${consequence}.`;
|
|
78
|
+
}
|
|
79
|
+
if (source === "other") {
|
|
80
|
+
return (
|
|
81
|
+
`passes response_mode ${JSON.stringify(job.with.response_mode.trim())}, which neither ` +
|
|
82
|
+
`reads vars.${MODE_VARIABLE} nor is auto, so ${consequence}.`
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
if (source === "variable" && mode !== "auto") {
|
|
86
|
+
return `reads response_mode from vars.${MODE_VARIABLE}, which is not auto, so ${consequence}.`;
|
|
87
|
+
}
|
|
88
|
+
return null;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Why auto mode would never start a round from these Callers; empty when it
|
|
93
|
+
* would. `mode` is the variable's value (null when unset).
|
|
94
|
+
*/
|
|
95
|
+
export function autoModeProblems(callers, mode = "auto") {
|
|
96
|
+
const problems = [];
|
|
97
|
+
const responders = jobsUsing(callers, RESPONSE_REUSABLE);
|
|
98
|
+
// A responder file whose trigger is wrong is reported once, here, not again
|
|
99
|
+
// for every review Caller that names it.
|
|
100
|
+
const responderFiles = new Set(responders.map((r) => r.caller.path));
|
|
101
|
+
for (const caller of new Set(responders.map((r) => r.caller))) {
|
|
102
|
+
if (caller.dispatchInputs === null) {
|
|
103
|
+
problems.push(
|
|
104
|
+
`${caller.path}: has no workflow_dispatch trigger, so the review handoff cannot start it.`,
|
|
105
|
+
);
|
|
106
|
+
} else if (!caller.dispatchInputs.includes("pr_number")) {
|
|
107
|
+
problems.push(
|
|
108
|
+
`${caller.path}: its workflow_dispatch trigger has no pr_number input, so GitHub refuses the review handoff's dispatch.`,
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
for (const { job, where } of responders) {
|
|
113
|
+
const why = notAuto(job, mode, "its gate refuses every dispatched round");
|
|
114
|
+
if (why) problems.push(`${where}: ${why}`);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
const reviewers = jobsUsing(callers, REVIEW_REUSABLE);
|
|
118
|
+
if (reviewers.length === 0) {
|
|
119
|
+
problems.push(
|
|
120
|
+
`No Caller uses ${REVIEW_REUSABLE}, so no review hands off: auto mode never starts a round.`,
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
for (const { job, where } of reviewers) {
|
|
124
|
+
const why = notAuto(job, mode, "its reviews never hand off");
|
|
125
|
+
if (why) problems.push(`${where}: ${why}`);
|
|
126
|
+
const target = passes(job, "response_workflow") ? job.with.response_workflow.trim() : "";
|
|
127
|
+
if (!target) {
|
|
128
|
+
problems.push(
|
|
129
|
+
`${where}: does not pass response_workflow, your Review response Caller as .github/workflows/<file>.yml.`,
|
|
130
|
+
);
|
|
131
|
+
} else if (target.includes("${{")) {
|
|
132
|
+
problems.push(`${where}: response_workflow is an expression, which doctor cannot check.`);
|
|
133
|
+
} else if (!WORKFLOW_PATH.test(target)) {
|
|
134
|
+
problems.push(
|
|
135
|
+
`${where}: response_workflow ${JSON.stringify(target)} is not a file directly under .github/workflows/.`,
|
|
136
|
+
);
|
|
137
|
+
} else if (!responderFiles.has(target)) {
|
|
138
|
+
problems.push(
|
|
139
|
+
`${where}: response_workflow ${JSON.stringify(target)} is not a Review response Caller here ` +
|
|
140
|
+
`(a workflow whose job uses ${RESPONSE_REUSABLE}).`,
|
|
141
|
+
);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
return problems;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export function checkReviewResponseMode({ github, repo, ownerType, callers }) {
|
|
148
|
+
if (jobsUsing(callers, RESPONSE_REUSABLE).length === 0) {
|
|
149
|
+
return result(ID, TITLE, "pass", "No Caller uses the Review response flow.");
|
|
150
|
+
}
|
|
151
|
+
let mode;
|
|
152
|
+
try {
|
|
153
|
+
mode = readMode(github, repo, ownerType);
|
|
154
|
+
} catch (err) {
|
|
155
|
+
return result(ID, TITLE, "skip", `Could not read ${MODE_VARIABLE}: ${err.message}`);
|
|
156
|
+
}
|
|
157
|
+
// A Caller that hardcodes `response_mode: auto` is in auto mode whatever
|
|
158
|
+
// the variable says, so its wiring is checked too.
|
|
159
|
+
if (mode !== "auto" && hardcodesAuto(callers)) {
|
|
160
|
+
const problems = autoModeProblems(callers, mode);
|
|
161
|
+
if (problems.length) {
|
|
162
|
+
return result(
|
|
163
|
+
ID,
|
|
164
|
+
TITLE,
|
|
165
|
+
"fail",
|
|
166
|
+
`A Caller passes response_mode: auto, but ${problems.length} problem(s) keep the handoff from starting a round.`,
|
|
167
|
+
{ details: problems },
|
|
168
|
+
);
|
|
169
|
+
}
|
|
170
|
+
return result(
|
|
171
|
+
ID,
|
|
172
|
+
TITLE,
|
|
173
|
+
"pass",
|
|
174
|
+
"Auto (response_mode: auto in the Callers): a finished review that left findings starts a round.",
|
|
175
|
+
);
|
|
176
|
+
}
|
|
177
|
+
if (mode === null || mode === "" || mode === "manual") {
|
|
178
|
+
return result(
|
|
179
|
+
ID,
|
|
180
|
+
TITLE,
|
|
181
|
+
"pass",
|
|
182
|
+
`Manual: ${MODE_VARIABLE} is ${mode === null ? "not set" : JSON.stringify(mode)}, so only the Trigger label starts a round.`,
|
|
183
|
+
);
|
|
184
|
+
}
|
|
185
|
+
if (mode !== "auto") {
|
|
186
|
+
return result(
|
|
187
|
+
ID,
|
|
188
|
+
TITLE,
|
|
189
|
+
"warn",
|
|
190
|
+
`${MODE_VARIABLE} is ${JSON.stringify(mode)}, which is not exactly auto, so Review response stays manual.`,
|
|
191
|
+
{ details: ["Set it to auto for auto mode, or to manual (or delete it) for manual mode."] },
|
|
192
|
+
);
|
|
193
|
+
}
|
|
194
|
+
const problems = autoModeProblems(callers, mode);
|
|
195
|
+
if (problems.length) {
|
|
196
|
+
return result(
|
|
197
|
+
ID,
|
|
198
|
+
TITLE,
|
|
199
|
+
"fail",
|
|
200
|
+
`${MODE_VARIABLE} is auto, but ${problems.length} problem(s) keep the handoff from starting a round.`,
|
|
201
|
+
{ details: problems },
|
|
202
|
+
);
|
|
203
|
+
}
|
|
204
|
+
return result(ID, TITLE, "pass", "Auto: a finished review that left findings starts a round.");
|
|
205
|
+
}
|
package/src/checks/rulesets.mjs
CHANGED
|
@@ -291,7 +291,8 @@ export function checkTagRuleset(rulesets) {
|
|
|
291
291
|
|
|
292
292
|
/**
|
|
293
293
|
* Workflows that push tags with GITHUB_TOKEN: a `git push` of tags, with no
|
|
294
|
-
* SSH deploy key in the same file
|
|
294
|
+
* SSH deploy key in the same file (a GIT_SSH_COMMAND, an SSH remote, or an
|
|
295
|
+
* actions/checkout `ssh-key:` input with a value).
|
|
295
296
|
*/
|
|
296
297
|
export function workflowsPushingTagsWithToken(files) {
|
|
297
298
|
return files
|
|
@@ -310,7 +311,11 @@ export function workflowsPushingTagsWithToken(files) {
|
|
|
310
311
|
/--tags|--follow-tags|refs\/tags\/|\bTAG\b|\btag\b/i.test(l),
|
|
311
312
|
);
|
|
312
313
|
const tagged = /\bgit\b[^\n]*\btag\b/.test(body) && /\bgit\b[^\n]*\bpush\b/.test(body);
|
|
313
|
-
|
|
314
|
+
// actions/checkout's `ssh-key:` input sets origin to the SSH URL and
|
|
315
|
+
// core.sshCommand to the key, so a later `git push origin` uses it.
|
|
316
|
+
const checkoutKey =
|
|
317
|
+
/^[ \t]*(?:-[ \t]+)?ssh-key:[ \t]*(?!(?:''|""|~|null|Null|NULL)[ \t]*$)\S/m.test(body);
|
|
318
|
+
const ssh = checkoutKey || /GIT_SSH_COMMAND|git@github\.com:|ssh:\/\//.test(body);
|
|
314
319
|
return (pushes || tagged) && !ssh;
|
|
315
320
|
})
|
|
316
321
|
.map((f) => f.path);
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
// Is there a Scan recipe at its default path, and is it valid? A recipe is
|
|
2
|
+
// needed only for a Deep scan, so having none passes. This reads the working
|
|
3
|
+
// tree like doctor's other file checks; `agent-kit deep-scan` itself reads the
|
|
4
|
+
// copy committed on the default branch.
|
|
5
|
+
|
|
6
|
+
import { lstatSync, readFileSync } from "node:fs";
|
|
7
|
+
import { join } from "node:path";
|
|
8
|
+
import {
|
|
9
|
+
DEFAULT_RECIPE_PATH,
|
|
10
|
+
MAX_RECIPE_BYTES,
|
|
11
|
+
RECIPE_DOCS_URL,
|
|
12
|
+
validateRecipe,
|
|
13
|
+
} from "../deep-scan/recipe.mjs";
|
|
14
|
+
import { result } from "./result.mjs";
|
|
15
|
+
|
|
16
|
+
const ID = "scan-recipe";
|
|
17
|
+
const TITLE = "Scan recipe";
|
|
18
|
+
|
|
19
|
+
/** @param {{ root: string }} opts */
|
|
20
|
+
export function checkScanRecipe({ root }) {
|
|
21
|
+
const path = DEFAULT_RECIPE_PATH;
|
|
22
|
+
let stat;
|
|
23
|
+
try {
|
|
24
|
+
stat = lstatSync(join(root, path));
|
|
25
|
+
} catch (err) {
|
|
26
|
+
if (err?.code === "ENOENT" || err?.code === "ENOTDIR") {
|
|
27
|
+
return result(
|
|
28
|
+
ID,
|
|
29
|
+
TITLE,
|
|
30
|
+
"pass",
|
|
31
|
+
`No Scan recipe at ${path}; only a Deep scan needs one (agent-kit deep-scan refuses without it).`,
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
throw err;
|
|
35
|
+
}
|
|
36
|
+
if (!stat.isFile()) {
|
|
37
|
+
return result(ID, TITLE, "warn", `${path} is not a regular file, so deep-scan cannot use it.`, {
|
|
38
|
+
details: [`Recipe format: ${RECIPE_DOCS_URL}`],
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
if (stat.size > MAX_RECIPE_BYTES) {
|
|
42
|
+
return result(ID, TITLE, "warn", `${path} is larger than ${MAX_RECIPE_BYTES / 1024} KiB.`);
|
|
43
|
+
}
|
|
44
|
+
const problems = validateRecipe(readFileSync(join(root, path), "utf8"));
|
|
45
|
+
if (problems.length) {
|
|
46
|
+
return result(ID, TITLE, "warn", `${path} is invalid, so deep-scan will refuse it.`, {
|
|
47
|
+
details: [...problems, `Recipe format: ${RECIPE_DOCS_URL}`],
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
return result(
|
|
51
|
+
ID,
|
|
52
|
+
TITLE,
|
|
53
|
+
"pass",
|
|
54
|
+
`${path} is present and valid (deep-scan reads the copy committed on the default branch).`,
|
|
55
|
+
);
|
|
56
|
+
}
|
|
@@ -218,6 +218,21 @@ export function checkSecrets({ github, repo, ownerType, requirements }) {
|
|
|
218
218
|
);
|
|
219
219
|
}
|
|
220
220
|
|
|
221
|
+
/**
|
|
222
|
+
* Variables ADR 0009 renamed, old name to new. The Callers have no fallback to
|
|
223
|
+
* an old name, so one still set does nothing once the Caller reads the new one.
|
|
224
|
+
*/
|
|
225
|
+
export const RENAMED_VARIABLES = {
|
|
226
|
+
CLAUDE_PIPELINE_ENABLED: "CLAUDE_AGENT_FLOW_ENABLED",
|
|
227
|
+
CLAUDE_MODEL_PLAN: "CLAUDE_PLAN_MODEL",
|
|
228
|
+
CLAUDE_MODEL_IMPLEMENT: "CLAUDE_IMPLEMENT_MODEL",
|
|
229
|
+
CLAUDE_MODEL_REVIEW: "CLAUDE_REVIEW_MODEL",
|
|
230
|
+
CLAUDE_MODEL_REVIEW_RESPONSE: "CLAUDE_REVIEW_RESPONSE_MODEL",
|
|
231
|
+
CLAUDE_MODEL_AUDIT: "CLAUDE_SECURITY_AUDIT_MODEL",
|
|
232
|
+
};
|
|
233
|
+
|
|
234
|
+
const killSwitch = (name) => /_ENABLED$/.test(name);
|
|
235
|
+
|
|
221
236
|
export function checkVariables({ github, repo, ownerType, requirements }) {
|
|
222
237
|
const ID = "variables";
|
|
223
238
|
const TITLE = "Repository variables the Callers read are set";
|
|
@@ -227,26 +242,61 @@ export function checkVariables({ github, repo, ownerType, requirements }) {
|
|
|
227
242
|
} catch (err) {
|
|
228
243
|
return result(ID, TITLE, "skip", `Could not list repository variables: ${err.message}`);
|
|
229
244
|
}
|
|
245
|
+
const isSet = (name) => listed.names.has(name.toUpperCase());
|
|
230
246
|
const required = requirements.variables.filter((v) => !v.optional && !isProvided(v.name));
|
|
231
|
-
const missing = required.filter((v) => !
|
|
232
|
-
|
|
247
|
+
const missing = required.filter((v) => !isSet(v.name));
|
|
248
|
+
// An old name still set while a Caller reads its replacement: the value is ignored.
|
|
249
|
+
const read = new Map(requirements.variables.map((v) => [v.name.toUpperCase(), v]));
|
|
250
|
+
const renamed = Object.entries(RENAMED_VARIABLES)
|
|
251
|
+
.filter(([oldName, newName]) => isSet(oldName) && read.has(newName))
|
|
252
|
+
.map(([oldName, newName]) => ({ oldName, newName, v: read.get(newName) }));
|
|
253
|
+
if (missing.length === 0 && renamed.length === 0) {
|
|
233
254
|
return result(ID, TITLE, "pass", `All ${required.length} required variable(s) are set.`);
|
|
234
255
|
}
|
|
235
|
-
const
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
256
|
+
const details = [
|
|
257
|
+
...missing.map(
|
|
258
|
+
(v) =>
|
|
259
|
+
`not set: ${v.name} (${v.where.join(", ")})` +
|
|
260
|
+
(killSwitch(v.name)
|
|
261
|
+
? " — the Kill switch: the flow never runs until it is set to true"
|
|
262
|
+
: ""),
|
|
263
|
+
),
|
|
264
|
+
...renamed.map(
|
|
265
|
+
({ oldName, newName, v }) =>
|
|
266
|
+
`renamed: ${oldName} is still set, but the Callers read ${newName} (${v.where.join(", ")}). ` +
|
|
267
|
+
`${oldName} is ignored: ` +
|
|
268
|
+
(isSet(newName)
|
|
269
|
+
? `${newName} is set too, so delete ${oldName}.`
|
|
270
|
+
: `set ${newName} to its value, then delete ${oldName}.`),
|
|
271
|
+
),
|
|
272
|
+
];
|
|
273
|
+
if (listed.orgNote && missing.length) details.push(listed.orgNote);
|
|
242
274
|
// The Kill switch takes true; for anything else, gh prompts for the value.
|
|
275
|
+
const toSet = [
|
|
276
|
+
...missing.map((v) => v.name),
|
|
277
|
+
...renamed.filter((r) => !isSet(r.newName)).map((r) => r.newName),
|
|
278
|
+
].filter((name, i, all) => all.indexOf(name) === i);
|
|
243
279
|
const { fix, notes } = splitFixes(
|
|
244
|
-
|
|
245
|
-
setCommand("variable",
|
|
280
|
+
toSet.map((name) =>
|
|
281
|
+
setCommand("variable", name, repo, killSwitch(name) ? ["--body", "true"] : []),
|
|
246
282
|
),
|
|
247
283
|
);
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
284
|
+
// Each old name goes last, once its replacement has a value: deleting first
|
|
285
|
+
// would lose the value before it is copied. The old names are the kit's own.
|
|
286
|
+
for (const { oldName } of renamed) {
|
|
287
|
+
fix.push(command("gh", "variable", "delete", oldName, "--repo", repo));
|
|
288
|
+
}
|
|
289
|
+
if (missing.length) {
|
|
290
|
+
return result(ID, TITLE, "fail", `${missing.length} required variable(s) missing.`, {
|
|
291
|
+
details: [...details, ...notes],
|
|
292
|
+
fix,
|
|
293
|
+
});
|
|
294
|
+
}
|
|
295
|
+
return result(
|
|
296
|
+
ID,
|
|
297
|
+
TITLE,
|
|
298
|
+
"warn",
|
|
299
|
+
`${renamed.length} renamed variable(s) still set under the old name.`,
|
|
300
|
+
{ details: [...details, ...notes], fix },
|
|
301
|
+
);
|
|
252
302
|
}
|