@mnaimfaizy/agent-kit 1.0.0-beta.12 → 1.0.0-beta.14
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 +6 -5
- package/harnesses.json +48 -0
- package/package.json +3 -2
- package/src/checks/review-response.mjs +54 -27
- package/src/checks/secrets-and-variables.mjs +198 -40
- package/src/cli.mjs +9 -0
- package/src/deep-scan/agent.mjs +77 -116
- package/src/deep-scan/credential.mjs +32 -18
- package/src/deep-scan/docker-driver.mjs +35 -13
- package/src/deep-scan/grounding-url.mjs +185 -0
- package/src/deep-scan/lifecycle.mjs +51 -31
- package/src/deep-scan/model-proxy.mjs +36 -366
- package/src/deep-scan/preflight.mjs +68 -1
- package/src/deep-scan/recipe.mjs +25 -8
- package/src/deep-scan/sbx-driver.mjs +30 -20
- package/src/deep-scan.mjs +36 -11
- package/src/harness/claude-code.mjs +229 -0
- package/src/harness/facts.mjs +120 -0
- package/src/harness/install-layer.mjs +58 -0
- package/src/harness/support-levels.mjs +49 -0
- package/src/harness-live/assess.mjs +268 -0
- package/src/harness-live/host.mjs +305 -0
- package/src/harness-live/probes.mjs +159 -0
- package/src/harness-live/run.mjs +133 -0
- package/src/harness-live/stage.mjs +151 -0
- package/src/harness-live/suite.mjs +300 -0
- package/src/init.mjs +28 -12
- package/src/model-proxy/core.mjs +549 -0
- package/src/model-proxy/profiles/anthropic.mjs +197 -0
- package/src/model-proxy/stub-dialects/anthropic.mjs +110 -0
- package/src/model-proxy/stub.mjs +174 -0
- package/src/deep-scan/claude-code.mjs +0 -25
package/README.md
CHANGED
|
@@ -8,20 +8,21 @@ npx @mnaimfaizy/agent-kit doctor # local run with your own gh
|
|
|
8
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
|
|
12
|
-
npx @mnaimfaizy/agent-kit deep-scan --verify findings.md --ref fix/x # Verification run: does the fix hold?
|
|
11
|
+
npx @mnaimfaizy/agent-kit deep-scan --proving-run # Deep scan: recipe, pre-flight, runtime, sandbox, agent
|
|
12
|
+
npx @mnaimfaizy/agent-kit deep-scan --proving-run --verify findings.md --ref fix/x # Verification run: does the fix hold?
|
|
13
13
|
```
|
|
14
14
|
|
|
15
|
+
- `--proving-run` is needed while Claude Code is below the `tried` [Support Level](../docs/harnesses.md#proving-runs) for the Deep scan, where it starts.
|
|
15
16
|
- 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 `
|
|
17
|
+
- `doctor` checks, from your Callers, every secret and repository variable they read (each flow's Kill switch, such as `AGENT_KIT_REVIEW_RESPONSE_ENABLED`, is required; a Stage switch such as `AGENT_KIT_PLAN_ENABLED` is optional), warns about a variable the kit renamed ([ADR 0009](../docs/adr/0009-stage-settings-resolve-in-the-caller.md), [ADR 0022](../docs/adr/0022-stage-settings-are-named-for-the-kit-not-the-harness.md)) that is still set under its old name, naming the new one, warns when a job has no `claude-code` credential set and fails when a Deep scan job has both, every Trigger label they use (such as `agent:address-review`), the Claude GitHub App, and the rulesets. With a Review response Caller, it reports `AGENT_KIT_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.
|
|
17
18
|
- `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.
|
|
18
19
|
- No runtime dependencies. Needs Node.js 22 or later, `git`, and (outside `--ci`) `gh` logged in with admin on the repository.
|
|
19
20
|
- 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`.
|
|
20
21
|
- `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.
|
|
21
22
|
- `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.
|
|
23
|
+
- `deep-scan` is the launcher for a Deep scan. Before anything else it goes by the [Support Level](../docs/harnesses.md#support-levels) that the shipped `harnesses.json` holds for Claude Code on the Deep scan: below `tried`, where every pair starts, it refuses, exit 1, unless run with `--proving-run`, which marks the run as a [Proving run](../docs/harnesses.md#proving-runs) and relaxes nothing else. It prints the harness, the level and whether the run is a Proving run, and in GitHub Actions adds that line to the run summary. Then 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 the run's caller key as its `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`: with no `image` or `dockerfile` in the recipe it pulls the kit's Harness image by digest and runs it; otherwise it pulls the recipe's image (or builds its Dockerfile from the default branch) and copies the pinned Claude Code onto it from the Harness image in one local build, with no npm install, refusing a musl image such as Alpine; the auto-updater is off either way; then it 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 `POST` to the Messages API's own paths, only from the caller holding the run's caller key (a random value made for each run, which the sandboxed Claude Code holds in place of a real key), with no server-side tool, `mcp_servers`, `container` or URL or file content in the body, and at most four at once, and swaps the caller 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`, the run's caller key as its `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`, copies the pinned Claude Code from the Harness image onto it (or, with no `image`, starts from the Harness image), adds a non-root `agent` user (uid 1000, home `/home/agent`, the image's `USER`), 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
24
|
- `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`).
|
|
24
25
|
|
|
25
|
-
The package version matches the Agent-kit Release line: `@mnaimfaizy/agent-kit@1.0.0-beta.
|
|
26
|
+
The package version matches the Agent-kit Release line: `@mnaimfaizy/agent-kit@1.0.0-beta.14` is published from tag `v1.0.0-beta.14`, with npm provenance.
|
|
26
27
|
|
|
27
28
|
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/harnesses.json
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$comment": "Generated by scripts/gen_harnesses.mjs from cli/src/harness/: do not edit. The shape is grow-only: a field may be added, and is never renamed or removed.",
|
|
3
|
+
"stages": ["deep-scan", "security-audit", "review", "plan", "implement", "review-response"],
|
|
4
|
+
"harnesses": {
|
|
5
|
+
"claude-code": {
|
|
6
|
+
"displayName": "Claude Code",
|
|
7
|
+
"secrets": [
|
|
8
|
+
{
|
|
9
|
+
"name": "claude_code_oauth_token",
|
|
10
|
+
"whereToGet": "Run `claude setup-token` on your machine, signed in to your Claude subscription, and paste the token."
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
"name": "anthropic_api_key",
|
|
14
|
+
"whereToGet": "Create an API key in the Anthropic Console: https://console.anthropic.com/settings/keys."
|
|
15
|
+
}
|
|
16
|
+
],
|
|
17
|
+
"effortValues": ["low", "medium", "high", "xhigh", "max"],
|
|
18
|
+
"noEffort": false,
|
|
19
|
+
"defaultModel": "claude-opus-5-5",
|
|
20
|
+
"supportLevels": {
|
|
21
|
+
"deep-scan": {
|
|
22
|
+
"level": "tried",
|
|
23
|
+
"run": "https://github.com/mnaimfaizy/agent-kit/issues/458#issuecomment-7249921732"
|
|
24
|
+
},
|
|
25
|
+
"security-audit": {
|
|
26
|
+
"level": "documented",
|
|
27
|
+
"run": null
|
|
28
|
+
},
|
|
29
|
+
"review": {
|
|
30
|
+
"level": "documented",
|
|
31
|
+
"run": null
|
|
32
|
+
},
|
|
33
|
+
"plan": {
|
|
34
|
+
"level": "documented",
|
|
35
|
+
"run": null
|
|
36
|
+
},
|
|
37
|
+
"implement": {
|
|
38
|
+
"level": "documented",
|
|
39
|
+
"run": null
|
|
40
|
+
},
|
|
41
|
+
"review-response": {
|
|
42
|
+
"level": "documented",
|
|
43
|
+
"run": null
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mnaimfaizy/agent-kit",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.14",
|
|
4
4
|
"description": "Adopt, upgrade and check Agent-kit in a Consumer repository. Reads kit files from the pinned git tag.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -9,7 +9,8 @@
|
|
|
9
9
|
},
|
|
10
10
|
"files": [
|
|
11
11
|
"bin/agent-kit.mjs",
|
|
12
|
-
"src/"
|
|
12
|
+
"src/",
|
|
13
|
+
"harnesses.json"
|
|
13
14
|
],
|
|
14
15
|
"engines": {
|
|
15
16
|
"node": ">=22"
|
|
@@ -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
|
}
|