@mnaimfaizy/agent-kit 1.0.0-beta.14 → 1.0.0-beta.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +22 -4
- package/custom-harness.schema.json +243 -0
- package/harnesses.json +244 -6
- package/package.json +3 -2
- package/src/checks/ci-workflow.mjs +105 -0
- package/src/checks/claude-app.mjs +11 -2
- package/src/checks/custom-harness.mjs +157 -0
- package/src/checks/github-app.mjs +214 -0
- package/src/checks/rulesets.mjs +9 -8
- package/src/checks/secrets-and-variables.mjs +27 -8
- package/src/checks/stages.mjs +705 -0
- package/src/cli.mjs +583 -36
- package/src/deep-scan/agent.mjs +88 -21
- package/src/deep-scan/credential.mjs +81 -32
- package/src/deep-scan/docker-driver.mjs +105 -42
- package/src/deep-scan/harness-text.mjs +99 -0
- package/src/deep-scan/lifecycle.mjs +68 -178
- package/src/deep-scan/limits.mjs +13 -7
- package/src/deep-scan/model-proxy.mjs +21 -10
- package/src/deep-scan/preflight.mjs +19 -6
- package/src/deep-scan/recipe.mjs +4 -0
- package/src/deep-scan/runtime.mjs +54 -6
- package/src/deep-scan/sandbox-run.mjs +232 -0
- package/src/deep-scan/sbx-driver.mjs +224 -39
- package/src/deep-scan/tar.mjs +69 -22
- package/src/deep-scan/verify.mjs +6 -1
- package/src/deep-scan.mjs +73 -13
- package/src/doctor.mjs +166 -5
- package/src/exec.mjs +14 -5
- package/src/factory/budget/budget.mjs +259 -0
- package/src/factory/build/command.mjs +321 -0
- package/src/factory/build/factory.mjs +473 -0
- package/src/factory/build/findings.mjs +55 -0
- package/src/factory/build/host.mjs +230 -0
- package/src/factory/build/notes.mjs +191 -0
- package/src/factory/build/pull-request.mjs +74 -0
- package/src/factory/bundle.mjs +146 -0
- package/src/factory/checks/allowed-paths.mjs +50 -0
- package/src/factory/checks/plan-header.mjs +296 -0
- package/src/factory/checks/qa.mjs +85 -0
- package/src/factory/checks/review.mjs +73 -0
- package/src/factory/checks/security.mjs +50 -0
- package/src/factory/checks/stage-check.mjs +89 -0
- package/src/factory/claims/command.mjs +187 -0
- package/src/factory/claims/release.mjs +111 -0
- package/src/factory/decision/answers.mjs +103 -0
- package/src/factory/decision/command.mjs +64 -0
- package/src/factory/decision/plan.mjs +99 -0
- package/src/factory/decision/request.mjs +116 -0
- package/src/factory/doctor/files.mjs +329 -0
- package/src/factory/doctor/index.mjs +56 -0
- package/src/factory/doctor/local.mjs +497 -0
- package/src/factory/doctor/orchestrate.mjs +146 -0
- package/src/factory/engine/lease.mjs +146 -0
- package/src/factory/engine/local-engine.mjs +177 -0
- package/src/factory/engine/lockfile.mjs +64 -0
- package/src/factory/engine/workflow-engine.mjs +124 -0
- package/src/factory/gate/comment.mjs +88 -0
- package/src/factory/gate/config.mjs +57 -0
- package/src/factory/gate/gate-core.mjs +250 -0
- package/src/factory/gate/guarded.mjs +17 -0
- package/src/factory/gate/reads.mjs +105 -0
- package/src/factory/gate/task.mjs +193 -0
- package/src/factory/gate/trip-reads.mjs +82 -0
- package/src/factory/gate/trip.mjs +87 -0
- package/src/factory/init/blueprint.mjs +174 -0
- package/src/factory/init/index.mjs +337 -0
- package/src/factory/labels/evidence.mjs +162 -0
- package/src/factory/labels/moves.mjs +32 -0
- package/src/factory/labels/reconcile.mjs +267 -0
- package/src/factory/labels/revert.mjs +87 -0
- package/src/factory/labels/timeline.mjs +72 -0
- package/src/factory/labels/voided.mjs +59 -0
- package/src/factory/limits/harness.mjs +39 -0
- package/src/factory/limits/limits.mjs +123 -0
- package/src/factory/merge/command.mjs +172 -0
- package/src/factory/outbox/check.mjs +240 -0
- package/src/factory/outbox/rulings.mjs +195 -0
- package/src/factory/plan/command.mjs +66 -0
- package/src/factory/plan/comment.mjs +156 -0
- package/src/factory/plan/publish.mjs +149 -0
- package/src/factory/plan/risk.mjs +153 -0
- package/src/factory/qa/command.mjs +163 -0
- package/src/factory/records/engine-record.mjs +133 -0
- package/src/factory/records/main.mjs +96 -0
- package/src/factory/records/record.mjs +226 -0
- package/src/factory/records/sink.mjs +57 -0
- package/src/factory/report/build.mjs +92 -0
- package/src/factory/report/command.mjs +80 -0
- package/src/factory/report/facts.mjs +226 -0
- package/src/factory/report/gate-section.mjs +122 -0
- package/src/factory/report/metrics.mjs +111 -0
- package/src/factory/report/reads.mjs +246 -0
- package/src/factory/report/render.mjs +121 -0
- package/src/factory/report/rollout.mjs +154 -0
- package/src/factory/review/command.mjs +182 -0
- package/src/factory/run/awake.mjs +70 -0
- package/src/factory/run/collect.mjs +77 -0
- package/src/factory/run/command.mjs +490 -0
- package/src/factory/run/gh.mjs +46 -0
- package/src/factory/run/launch.mjs +47 -0
- package/src/factory/run/pipelines.mjs +261 -0
- package/src/factory/run/raw.mjs +96 -0
- package/src/factory/run/restart.mjs +83 -0
- package/src/factory/run/s3.mjs +193 -0
- package/src/factory/run/secrets.mjs +142 -0
- package/src/factory/run/teardown.mjs +242 -0
- package/src/factory/run/token.mjs +68 -0
- package/src/factory/security/command.mjs +157 -0
- package/src/factory/setup/app.mjs +122 -0
- package/src/factory/setup/command.mjs +409 -0
- package/src/factory/setup/labels.mjs +25 -0
- package/src/factory/setup/reads.mjs +129 -0
- package/src/factory/setup/writes.mjs +126 -0
- package/src/factory/snapshot/write.mjs +176 -0
- package/src/factory/stop/command.mjs +136 -0
- package/src/factory/sweep/actions-main.mjs +117 -0
- package/src/factory/sweep/command.mjs +65 -0
- package/src/factory/sweep/knobs.mjs +78 -0
- package/src/factory/sweep/marker-version.mjs +15 -0
- package/src/factory/sweep/markers.mjs +112 -0
- package/src/factory/sweep/overlap.mjs +24 -0
- package/src/factory/sweep/run.mjs +198 -0
- package/src/factory/sweep/shell.mjs +394 -0
- package/src/factory/sweep/split.mjs +104 -0
- package/src/factory/sweep/states.mjs +87 -0
- package/src/factory/sweep/sweep-core.mjs +1781 -0
- package/src/factory/tracker/github.mjs +674 -0
- package/src/factory/tracker/operations.mjs +153 -0
- package/src/factory/upgrade/index.mjs +83 -0
- package/src/harness/adapters.mjs +30 -0
- package/src/harness/antigravity.mjs +187 -0
- package/src/harness/claude-code.mjs +8 -1
- package/src/harness/codex.mjs +219 -0
- package/src/harness/cursor.mjs +199 -0
- package/src/harness/custom/registry.mjs +21 -0
- package/src/harness/custom/schema.mjs +90 -0
- package/src/harness/custom.mjs +299 -0
- package/src/harness/facts.mjs +44 -7
- package/src/harness/gemini.mjs +164 -0
- package/src/harness/install-layer.mjs +86 -3
- package/src/harness/opencode.mjs +289 -0
- package/src/harness/resolve.mjs +156 -0
- package/src/harness/support-levels.mjs +151 -3
- package/src/harness-live/assess.mjs +29 -6
- package/src/harness-live/cursor-real.mjs +146 -0
- package/src/harness-live/cursor-version.mjs +70 -0
- package/src/harness-live/cursor.mjs +80 -0
- package/src/harness-live/custom.mjs +91 -0
- package/src/harness-live/fixture-harness.mjs +45 -0
- package/src/harness-live/harnesses.mjs +263 -0
- package/src/harness-live/host.mjs +113 -4
- package/src/harness-live/opencode.mjs +289 -0
- package/src/harness-live/probes.mjs +87 -7
- package/src/harness-live/run.mjs +101 -20
- package/src/harness-live/setup.mjs +126 -0
- package/src/harness-live/stage.mjs +25 -15
- package/src/harness-live/suite.mjs +276 -95
- package/src/harness-test.mjs +116 -0
- package/src/init.mjs +374 -36
- package/src/kit-owned-paths.mjs +1 -1
- package/src/model-proxy/core.mjs +128 -20
- package/src/model-proxy/profiles/anthropic.mjs +54 -10
- package/src/model-proxy/profiles/gemini-api.mjs +311 -0
- package/src/model-proxy/profiles/openai.mjs +327 -0
- package/src/model-proxy/stub-dialects/gemini-api.mjs +178 -0
- package/src/model-proxy/stub-dialects/openai.mjs +173 -0
- package/src/model-proxy/stub.mjs +9 -1
- package/src/stage/audit.mjs +79 -0
- package/src/stage/egress-route.mjs +207 -0
- package/src/stage/implement/carry.mjs +308 -0
- package/src/stage/implement/sandbox.mjs +271 -0
- package/src/stage/implement/verify.mjs +70 -0
- package/src/stage/implement.mjs +218 -0
- package/src/stage/plan.mjs +115 -0
- package/src/stage/review-response.mjs +172 -0
- package/src/stage/review.mjs +185 -0
- package/src/stage/workspace.mjs +274 -0
- package/src/stage.mjs +1087 -0
- package/src/upgrade.mjs +39 -7
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
// What a Deep scan says that differs by harness: in the brief, in its output
|
|
2
|
+
// and in its refusals. Everything else comes from the harness's launch plan
|
|
3
|
+
// (ADR 0027) and `cli/harnesses.json`.
|
|
4
|
+
|
|
5
|
+
import { TEXT as cursorText } from "../harness/cursor.mjs";
|
|
6
|
+
import { loadedCustom } from "../harness/custom/registry.mjs";
|
|
7
|
+
import { PROVIDERS, providerOf } from "../harness/opencode.mjs";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @typedef {{
|
|
11
|
+
* webOff: string,
|
|
12
|
+
* agentStep: (kind: string) => string,
|
|
13
|
+
* turnLimit: boolean,
|
|
14
|
+
* needsKey: string,
|
|
15
|
+
* keyRefused: string,
|
|
16
|
+
* refusedAs?: string,
|
|
17
|
+
* noSubscription?: string,
|
|
18
|
+
* }} HarnessText `webOff` says that what of the harness's own reaches the web
|
|
19
|
+
* is off. `agentStep` is what the agent step's line says the harness runs
|
|
20
|
+
* with. `turnLimit` is whether it takes a turn limit. `needsKey` is what a
|
|
21
|
+
* run with no API key is told it needs, and `keyRefused` what to check when
|
|
22
|
+
* the model API refuses the key. `refusedAs` names the statuses its API
|
|
23
|
+
* refuses one with, where they are not 401 and 403. `noSubscription` says why
|
|
24
|
+
* `--credential subscription` is refused, where there is more to say than
|
|
25
|
+
* that the harness takes none.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
/** @type {Readonly<Record<string, Readonly<HarnessText>>>} */
|
|
29
|
+
export const HARNESS_TEXT = Object.freeze({
|
|
30
|
+
"claude-code": Object.freeze({
|
|
31
|
+
webOff: "the web tools (WebFetch, WebSearch) are off",
|
|
32
|
+
agentStep: (kind) =>
|
|
33
|
+
`${kind === "subscription" ? "no --bare: the subscription path, with a placeholder token; project settings and MCP servers not loaded" : "--bare, a placeholder key"}, web tools off`,
|
|
34
|
+
turnLimit: true,
|
|
35
|
+
needsKey: "deep-scan needs an Anthropic API key",
|
|
36
|
+
keyRefused: "Check that the key is current and its Anthropic Console workspace is active",
|
|
37
|
+
}),
|
|
38
|
+
codex: Object.freeze({
|
|
39
|
+
webOff: "Codex CLI's web search is off",
|
|
40
|
+
agentStep: () =>
|
|
41
|
+
"a placeholder key, web search off, the checkout's Codex config removed and no AGENTS.md loaded",
|
|
42
|
+
turnLimit: false,
|
|
43
|
+
needsKey: "deep-scan on Codex CLI needs an OpenAI API key",
|
|
44
|
+
keyRefused: "Check that the key is current and its OpenAI project is active",
|
|
45
|
+
}),
|
|
46
|
+
gemini: Object.freeze({
|
|
47
|
+
webOff: "Gemini CLI's web search and web fetch tools are off",
|
|
48
|
+
agentStep: () => "a placeholder key, web tools off, the checkout's Gemini config removed",
|
|
49
|
+
turnLimit: true,
|
|
50
|
+
needsKey: "deep-scan on Gemini CLI needs a Gemini API key",
|
|
51
|
+
keyRefused: "Check that the key is current and its Google Cloud project is active",
|
|
52
|
+
refusedAs: "401, 403 or, for a key it does not know, 400",
|
|
53
|
+
}),
|
|
54
|
+
antigravity: Object.freeze({
|
|
55
|
+
webOff: "Antigravity CLI's web search tool is off",
|
|
56
|
+
agentStep: () =>
|
|
57
|
+
"a placeholder key, an agent with local tools alone, the checkout's Antigravity config removed",
|
|
58
|
+
turnLimit: false,
|
|
59
|
+
needsKey: "deep-scan on Antigravity CLI needs a Gemini API key",
|
|
60
|
+
noSubscription:
|
|
61
|
+
"A Google sign-in cannot stay outside the sandbox: signed in, Antigravity CLI calls a Google host the model proxy cannot front, and Google's Antigravity terms bar access through third-party software.",
|
|
62
|
+
keyRefused: "Check that the key is current and its Google Cloud project is active",
|
|
63
|
+
refusedAs: "401, 403 or, for a key it does not know, 400",
|
|
64
|
+
}),
|
|
65
|
+
opencode: Object.freeze({
|
|
66
|
+
webOff: "opencode's web search, web fetch, image and video tools are off",
|
|
67
|
+
agentStep: () => "a placeholder key, web tools off, the checkout's opencode config removed",
|
|
68
|
+
turnLimit: false,
|
|
69
|
+
// textFor names the provider the run's model picks.
|
|
70
|
+
needsKey: "deep-scan on opencode needs the API key of its model's provider",
|
|
71
|
+
keyRefused: "Check that the key is current and its provider's account is active",
|
|
72
|
+
}),
|
|
73
|
+
cursor: cursorText,
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* `harness`'s text for a run on `model`: on opencode, whose model picks the
|
|
78
|
+
* provider, the key it names is that provider's, and so are the statuses its
|
|
79
|
+
* API refuses a key with.
|
|
80
|
+
* @param {string} harness
|
|
81
|
+
* @param {string} [model]
|
|
82
|
+
* @returns {Readonly<HarnessText>}
|
|
83
|
+
*/
|
|
84
|
+
export function textFor(harness, model) {
|
|
85
|
+
const text = loadedCustom(harness)?.text ?? HARNESS_TEXT[harness];
|
|
86
|
+
if (harness !== "opencode") return text;
|
|
87
|
+
const chosen = providerOf(model);
|
|
88
|
+
if ("refused" in chosen) return text;
|
|
89
|
+
const { displayName } = PROVIDERS[chosen.provider];
|
|
90
|
+
return {
|
|
91
|
+
...text,
|
|
92
|
+
needsKey: `deep-scan on opencode needs the ${displayName} API key its ${chosen.provider}/ model runs on`,
|
|
93
|
+
keyRefused: `Check that the ${displayName} API key is current and its account is active`,
|
|
94
|
+
// The Gemini API refuses a key it does not know with a 400 too.
|
|
95
|
+
...(chosen.provider === "google"
|
|
96
|
+
? { refusedAs: "401, 403 or, for a key the Gemini API does not know, 400" }
|
|
97
|
+
: {}),
|
|
98
|
+
};
|
|
99
|
+
}
|
|
@@ -1,21 +1,22 @@
|
|
|
1
1
|
// The Deep scan sandbox lifecycle (#369), from image to teardown, on the
|
|
2
2
|
// runtime `selectRuntime` chose. In order: prepare the image (the Harness
|
|
3
|
-
// image, or the recipe's with the harness copied from it, ADR 0029:
|
|
4
|
-
//
|
|
3
|
+
// image, or the recipe's with the harness copied from it, ADR 0029: the pinned
|
|
4
|
+
// harness, its updater off); start the sandbox with no mount; copy
|
|
5
5
|
// in an export of the trusted ref (never the working tree) and the grounding
|
|
6
6
|
// files, and nothing else; run the setup phase (`setup`, `start`, `ready`,
|
|
7
7
|
// `seed`) with no agent and no model credential, its egress limited to the
|
|
8
8
|
// recipe's `registries`; cut the network and check from the host that it is
|
|
9
9
|
// cut; open the model route (the key-injecting model proxy on the host, the
|
|
10
10
|
// scan's only way out) and check from the host that nothing else is open;
|
|
11
|
-
// hand the agent its brief and run the real
|
|
11
|
+
// hand the agent its brief and run the real harness (#370); copy out the
|
|
12
12
|
// one report file; and destroy the sandbox on every exit path, an interrupt
|
|
13
13
|
// included. The real model credential reaches only the model proxy, in this
|
|
14
14
|
// process: the sandbox gets a placeholder.
|
|
15
15
|
//
|
|
16
16
|
// Every run is bounded from out here (#371): the setup wall clock runs from
|
|
17
17
|
// the image step until the agent step starts, the scan wall clock over the
|
|
18
|
-
// agent step,
|
|
18
|
+
// agent step, the harness takes the launcher's `--max-turns` where it has a
|
|
19
|
+
// turn limit, and the
|
|
19
20
|
// model proxy refuses requests past the token cap. A limit that fires stops
|
|
20
21
|
// the running step through the same seam an interrupt does, then the report
|
|
21
22
|
// it left is copied out with the launcher's `Stopped:` line, and the sandbox
|
|
@@ -25,27 +26,24 @@
|
|
|
25
26
|
// Kata, Firecracker on Docker Engine) and sbx-driver.mjs (Docker
|
|
26
27
|
// Sandboxes). This module owns the order, the output and every refusal.
|
|
27
28
|
|
|
28
|
-
import { randomBytes } from "node:crypto";
|
|
29
29
|
import { mkdtempSync, writeFileSync } from "node:fs";
|
|
30
30
|
import { tmpdir } from "node:os";
|
|
31
31
|
import { join } from "node:path";
|
|
32
32
|
import { firstLine } from "../exec.mjs";
|
|
33
|
-
import { agentBrief, agentPlan, agentScript, BRIEF_PATH, turnsMarker } from "./agent.mjs";
|
|
34
|
-
import { callerKeyFor } from "./credential.mjs";
|
|
35
|
-
import { dockerDriver, LABEL } from "./docker-driver.mjs";
|
|
36
|
-
import { groundingUrlProblem, isGroundingUrl } from "./grounding-url.mjs";
|
|
37
33
|
import {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
} from "./
|
|
46
|
-
import {
|
|
47
|
-
import {
|
|
48
|
-
import {
|
|
34
|
+
agentBrief,
|
|
35
|
+
agentPlan,
|
|
36
|
+
agentScript,
|
|
37
|
+
BRIEF_PATH,
|
|
38
|
+
credentialMarker,
|
|
39
|
+
turnsMarker,
|
|
40
|
+
} from "./agent.mjs";
|
|
41
|
+
import { LABEL } from "./docker-driver.mjs";
|
|
42
|
+
import { textFor } from "./harness-text.mjs";
|
|
43
|
+
import { groundingUrlProblem, isGroundingUrl } from "./grounding-url.mjs";
|
|
44
|
+
import { LimitReached, STOPPED_EXIT, stoppedStatus, TURNS, withStopped } from "./limits.mjs";
|
|
45
|
+
import { cutNetwork, openModelRoute, runInSandbox } from "./sandbox-run.mjs";
|
|
46
|
+
import { ENDS_HERE, indent, outputLines, StepFailed } from "./steps.mjs";
|
|
49
47
|
import { tarOf } from "./tar.mjs";
|
|
50
48
|
import { checkVerificationReport, FINDINGS_PATH, verificationBrief } from "./verify.mjs";
|
|
51
49
|
|
|
@@ -70,18 +68,22 @@ const GROUNDING_TIMEOUT_MS = 60_000;
|
|
|
70
68
|
const PUBLIC_LOG = "the Public-log rule: this log is world-readable in GitHub Actions";
|
|
71
69
|
|
|
72
70
|
/**
|
|
73
|
-
* The line a run prints when the model API
|
|
74
|
-
* 401 or 403
|
|
75
|
-
*
|
|
71
|
+
* The line a run prints when the model API refused the credential in every
|
|
72
|
+
* answer (a 401 or 403, or what the harness's API answers beside them): the
|
|
73
|
+
* credential's kind and where it came from (a variable's name, or
|
|
74
|
+
* 1Password), never its value.
|
|
76
75
|
* @param {"api-key" | "subscription"} kind
|
|
77
76
|
* @param {string} from
|
|
77
|
+
* @param {string} harness
|
|
78
|
+
* @param {string} [model]
|
|
78
79
|
*/
|
|
79
|
-
function credentialRefusedLine(kind, from) {
|
|
80
|
+
function credentialRefusedLine(kind, from, harness, model) {
|
|
81
|
+
const text = textFor(harness, model);
|
|
80
82
|
const what =
|
|
81
83
|
kind === "subscription"
|
|
82
84
|
? `the Claude subscription token from ${from} was not accepted (its value is not shown). Make a fresh one with claude setup-token, then run deep-scan again.`
|
|
83
|
-
: `the API key from ${from} was not accepted (its value is not shown).
|
|
84
|
-
return `The model API refused the credential: every answer was 401 or 403, so ${what}`;
|
|
85
|
+
: `the API key from ${from} was not accepted (its value is not shown). ${text.keyRefused}, then run deep-scan again.`;
|
|
86
|
+
return `The model API refused the credential: every answer was ${text.refusedAs ?? "401 or 403"}, so ${what}`;
|
|
85
87
|
}
|
|
86
88
|
|
|
87
89
|
/** How many lines of the harness's error output a failed agent step shows. */
|
|
@@ -99,6 +101,8 @@ const SETUP_ORDER = ["setup", "start", "ready", "seed"];
|
|
|
99
101
|
* start: (steps: object) => Promise<{ isolation?: string } | void>,
|
|
100
102
|
* copyIn: (tar: Buffer, what: string) => Promise<void>,
|
|
101
103
|
* installAgent: (out: Function) => Promise<void>,
|
|
104
|
+
* carryOut: (script: string, opts: { maxBytes: number }) => Promise<{ data: Buffer } | { error: string }>,
|
|
105
|
+
* renew: () => Promise<void>,
|
|
102
106
|
* openSetupEgress: (registries: string[]) => Promise<{ env: string[], note: string }>,
|
|
103
107
|
* refused: () => string[],
|
|
104
108
|
* exec: (script: string, opts?: { env?: string[], workdir?: string | null }) => Promise<import("../exec.mjs").StartResult>,
|
|
@@ -130,6 +134,7 @@ const SETUP_ORDER = ["setup", "start", "ready", "seed"];
|
|
|
130
134
|
* credential: string,
|
|
131
135
|
* credentialKind?: "api-key" | "subscription",
|
|
132
136
|
* credentialFrom?: string,
|
|
137
|
+
* harness?: string,
|
|
133
138
|
* limits: import("./limits.mjs").Limits,
|
|
134
139
|
* model?: string,
|
|
135
140
|
* effort?: string,
|
|
@@ -157,103 +162,15 @@ const SETUP_ORDER = ["setup", "start", "ready", "seed"];
|
|
|
157
162
|
* }} Verification
|
|
158
163
|
*/
|
|
159
164
|
export async function runLifecycle(opts) {
|
|
160
|
-
const { runner, runtime, out, err, signals } = opts;
|
|
161
|
-
const controller = new AbortController();
|
|
162
|
-
const { signal } = controller;
|
|
163
|
-
const handlers = Object.fromEntries(
|
|
164
|
-
["SIGINT", "SIGTERM"].map((sig) => [
|
|
165
|
-
sig,
|
|
166
|
-
() => {
|
|
167
|
-
if (signal.aborted) return;
|
|
168
|
-
err(`Interrupted (${sig}): stopping the current step and destroying the sandbox.`);
|
|
169
|
-
controller.abort(sig);
|
|
170
|
-
},
|
|
171
|
-
]),
|
|
172
|
-
);
|
|
173
|
-
for (const [sig, handler] of Object.entries(handlers)) signals.on(sig, handler);
|
|
174
|
-
|
|
175
|
-
const interrupted = () => new Interrupted(String(signal.reason ?? "SIGINT"));
|
|
176
|
-
|
|
177
|
-
// The phase clocks. A limit aborts only the phase's own controller, so the
|
|
178
|
-
// steps after it (the copy-out, the teardown) still run.
|
|
179
|
-
const { timers, limits } = opts;
|
|
180
|
-
/** @type {{ controller: AbortController, timer: unknown } | null} */
|
|
181
|
-
let phase = null;
|
|
182
|
-
/** @type {{ limit: string, detail: string } | null} */
|
|
183
|
-
let stopped = null;
|
|
184
|
-
const stop = (limit, detail) => {
|
|
185
|
-
if (stopped || signal.aborted) return;
|
|
186
|
-
stopped = { limit, detail };
|
|
187
|
-
err(`${stoppedStatus(stopped)} Stopping the current step.`);
|
|
188
|
-
phase?.controller.abort(stopped);
|
|
189
|
-
};
|
|
190
|
-
const clocks = {
|
|
191
|
-
begin(name, minutes) {
|
|
192
|
-
const controller = new AbortController();
|
|
193
|
-
const timer = timers.setTimeout(
|
|
194
|
-
() => stop(WALL_CLOCK, `the ${name} phase's ${minutes}-minute limit`),
|
|
195
|
-
minutes * 60_000,
|
|
196
|
-
);
|
|
197
|
-
phase = { controller, timer };
|
|
198
|
-
if (stopped) controller.abort(stopped);
|
|
199
|
-
},
|
|
200
|
-
end() {
|
|
201
|
-
if (phase) timers.clearTimeout(phase.timer);
|
|
202
|
-
phase = null;
|
|
203
|
-
},
|
|
204
|
-
stop,
|
|
205
|
-
stopped: () => stopped,
|
|
206
|
-
/** The signal a step stops on: an interrupt, or its phase's limit. */
|
|
207
|
-
signal: () => (phase ? AbortSignal.any([signal, phase.controller.signal]) : signal),
|
|
208
|
-
/** What a step stopped by `clocks.signal()` throws. */
|
|
209
|
-
reason: () => (signal.aborted ? interrupted() : new LimitReached(stopped)),
|
|
210
|
-
};
|
|
211
|
-
|
|
212
|
-
/** @type {import("./docker-driver.mjs").Call} */
|
|
213
|
-
const call = async (cmd, args, { stdin, cwd, maxOutput } = {}) => {
|
|
214
|
-
const stepSignal = clocks.signal();
|
|
215
|
-
if (stepSignal.aborted) throw clocks.reason();
|
|
216
|
-
const r = await runner.start(cmd, args, { stdin, cwd, maxOutput, signal: stepSignal });
|
|
217
|
-
if (r.aborted || stepSignal.aborted) throw clocks.reason();
|
|
218
|
-
if (r.truncated) return r;
|
|
219
|
-
// Ctrl+C in a terminal reaches the runtime's child too, and can end it
|
|
220
|
-
// before the handler above runs: that is an interrupt, not a failure.
|
|
221
|
-
if (r.signal === "SIGINT" || r.signal === "SIGTERM") throw new Interrupted(r.signal);
|
|
222
|
-
return r;
|
|
223
|
-
};
|
|
224
|
-
const id = randomBytes(6).toString("hex");
|
|
225
165
|
// The harness's launch plan: the drivers put its install layer on the image.
|
|
226
|
-
const plan = agentPlan({
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
try {
|
|
235
|
-
code = await lifecycle({ ...opts, driver, clocks });
|
|
236
|
-
} catch (e) {
|
|
237
|
-
if (e instanceof LimitReached) {
|
|
238
|
-
// A limit before the agent step: there is no report to deliver.
|
|
239
|
-
out(`${stoppedStatus(e.stop)} No report came out: nothing was written, filed or posted.`);
|
|
240
|
-
code = STOPPED_EXIT;
|
|
241
|
-
} else if (e instanceof Interrupted) {
|
|
242
|
-
code = e.signal === "SIGTERM" ? 143 : 130;
|
|
243
|
-
} else if (e instanceof StepFailed) {
|
|
244
|
-
err(e.lines.join("\n"));
|
|
245
|
-
code = 1;
|
|
246
|
-
} else {
|
|
247
|
-
thrown = e;
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
clocks.end();
|
|
251
|
-
await driver.close();
|
|
252
|
-
const tornDown = teardown(runner, driver.teardown(), out, err);
|
|
253
|
-
driver.cleanup?.();
|
|
254
|
-
for (const [sig, handler] of Object.entries(handlers)) signals.off(sig, handler);
|
|
255
|
-
if (thrown) throw thrown;
|
|
256
|
-
return (code === 0 || code === STOPPED_EXIT) && !tornDown ? 1 : code;
|
|
166
|
+
const plan = agentPlan({
|
|
167
|
+
harness: opts.harness,
|
|
168
|
+
kind: opts.credentialKind,
|
|
169
|
+
model: opts.model,
|
|
170
|
+
});
|
|
171
|
+
return runInSandbox({ ...opts, plan }, ({ driver, clocks }) =>
|
|
172
|
+
lifecycle({ ...opts, driver, clocks }),
|
|
173
|
+
);
|
|
257
174
|
}
|
|
258
175
|
|
|
259
176
|
async function lifecycle({
|
|
@@ -269,6 +186,7 @@ async function lifecycle({
|
|
|
269
186
|
credential,
|
|
270
187
|
credentialKind = "api-key",
|
|
271
188
|
credentialFrom = "its source",
|
|
189
|
+
harness = "claude-code",
|
|
272
190
|
limits,
|
|
273
191
|
model,
|
|
274
192
|
effort,
|
|
@@ -414,35 +332,20 @@ async function lifecycle({
|
|
|
414
332
|
}
|
|
415
333
|
|
|
416
334
|
// 5. Cut the network, and check from the host that it is cut.
|
|
417
|
-
await driver
|
|
418
|
-
const left = await driver.egressLeft();
|
|
419
|
-
if (left !== null) {
|
|
420
|
-
throw new StepFailed([`FAILED the network is not cut: ${left}.`, ENDS_HERE]);
|
|
421
|
-
}
|
|
422
|
-
out("Network: cut (checked from the host); the agent step has no network.");
|
|
335
|
+
await cutNetwork(driver, out);
|
|
423
336
|
|
|
424
337
|
// 6. The model route: the key-injecting model proxy on this machine, the
|
|
425
338
|
// scan's only way out, and the check from the host that nothing else is.
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
callerKey,
|
|
436
|
-
maxTokens: limits.tokens,
|
|
437
|
-
onCap: () => clocks.stop(TOKENS, `the run's ${limits.tokens}-token cap`),
|
|
438
|
-
...(modelApi !== undefined ? { upstream: modelApi } : {}),
|
|
439
|
-
});
|
|
440
|
-
return proxy;
|
|
339
|
+
const { callerKey, route, proxy } = await openModelRoute({
|
|
340
|
+
driver,
|
|
341
|
+
clocks,
|
|
342
|
+
harness,
|
|
343
|
+
model,
|
|
344
|
+
credential,
|
|
345
|
+
credentialKind,
|
|
346
|
+
maxTokens: limits.tokens,
|
|
347
|
+
modelApi,
|
|
441
348
|
});
|
|
442
|
-
const extra = await driver.egressLeft();
|
|
443
|
-
if (extra !== null) {
|
|
444
|
-
throw new StepFailed([`FAILED more than the model route is open: ${extra}.`, ENDS_HERE]);
|
|
445
|
-
}
|
|
446
349
|
if (route.isolation) out(route.isolation);
|
|
447
350
|
out(
|
|
448
351
|
`Model route: only the model proxy on your machine (${route.note}), which forwards to the model API alone, with your ${credentialKind === "subscription" ? "token as its bearer value" : "key"}; checked from the host.`,
|
|
@@ -466,8 +369,10 @@ async function lifecycle({
|
|
|
466
369
|
grounding,
|
|
467
370
|
paths,
|
|
468
371
|
discovers: subscription,
|
|
372
|
+
harness,
|
|
469
373
|
})
|
|
470
374
|
: agentBrief({
|
|
375
|
+
harness,
|
|
471
376
|
branch,
|
|
472
377
|
short,
|
|
473
378
|
recipePath,
|
|
@@ -489,6 +394,7 @@ async function lifecycle({
|
|
|
489
394
|
: "copying the launcher's brief in",
|
|
490
395
|
);
|
|
491
396
|
const plan = agentPlan({
|
|
397
|
+
harness,
|
|
492
398
|
baseUrl: route.url,
|
|
493
399
|
maxTurns: limits.turns,
|
|
494
400
|
model,
|
|
@@ -499,8 +405,10 @@ async function lifecycle({
|
|
|
499
405
|
const { displayName, version } = plan.identity;
|
|
500
406
|
/** What the line says for a model or effort not asked for. */
|
|
501
407
|
const unasked = `${displayName}'s default`;
|
|
408
|
+
const text = textFor(harness, model);
|
|
409
|
+
const turnCap = text.turnLimit ? `at most ${limits.turns} turns` : "no turn limit";
|
|
502
410
|
out(
|
|
503
|
-
`Agent step: ${displayName} ${version} (${
|
|
411
|
+
`Agent step: ${displayName} ${version} (${text.agentStep(credentialKind)}, ${turnCap}; requested model: ${model ?? unasked}, effort: ${effort ?? unasked}), handed ${verification ? "the Verification-run procedure, the finding file" : "the deep procedure"}, the Threat pack and the Scan recipe.`,
|
|
504
412
|
);
|
|
505
413
|
clocks.end();
|
|
506
414
|
// The scan wall clock: the agent step alone.
|
|
@@ -528,11 +436,21 @@ async function lifecycle({
|
|
|
528
436
|
? `Model proxy: ${proxy ? "closed" : "not started"} (${PUBLIC_LOG}).`
|
|
529
437
|
: `Model proxy: ${proxy?.summary() ?? "not started"}.`,
|
|
530
438
|
);
|
|
531
|
-
//
|
|
439
|
+
// The harness said it has no credential it reads: the script's fixed line.
|
|
440
|
+
if (
|
|
441
|
+
agent &&
|
|
442
|
+
agent.status !== 0 &&
|
|
443
|
+
agent.stdout.toString("utf8").split(/\r?\n/).includes(credentialMarker(plan))
|
|
444
|
+
) {
|
|
445
|
+
err(
|
|
446
|
+
`No model credential: ${displayName} said authentication is required, so it read no API key in the sandbox and asked for a sign-in, which deep-scan never gives it. This is a fault of the harness's launch, not of your key: report it with this line.`,
|
|
447
|
+
);
|
|
448
|
+
}
|
|
449
|
+
// Every answer a refusal: say plainly that the credential was refused,
|
|
532
450
|
// its kind and where it came from, never its value. Locally only: a public
|
|
533
451
|
// log gets none of the model API's answers.
|
|
534
452
|
if (!publicLog && proxy?.credentialRefused())
|
|
535
|
-
err(credentialRefusedLine(credentialKind, credentialFrom));
|
|
453
|
+
err(credentialRefusedLine(credentialKind, credentialFrom, harness, model));
|
|
536
454
|
const stopped = clocks.stopped();
|
|
537
455
|
if (stopped) {
|
|
538
456
|
out(`${stoppedStatus(stopped)} Copying out what report the agent left.`);
|
|
@@ -628,34 +546,6 @@ async function lifecycle({
|
|
|
628
546
|
return agent?.status === 0 ? 0 : 1;
|
|
629
547
|
}
|
|
630
548
|
|
|
631
|
-
/**
|
|
632
|
-
* Run each teardown command, whatever happened before. Synchronous, so it
|
|
633
|
-
* finishes even while an interrupt is pending.
|
|
634
|
-
* @returns {boolean} whether nothing was left behind
|
|
635
|
-
*/
|
|
636
|
-
function teardown(runner, commands, out, err) {
|
|
637
|
-
if (!commands.length) return true;
|
|
638
|
-
const left = [];
|
|
639
|
-
for (const { what, cmd, args } of commands) {
|
|
640
|
-
const r = runner(cmd, args);
|
|
641
|
-
if (r.status !== 0 && !/no such|not found/i.test(r.stderr)) {
|
|
642
|
-
left.push(`${what}: ${firstLine(r.stderr) || `exit ${r.status}`}`);
|
|
643
|
-
}
|
|
644
|
-
}
|
|
645
|
-
if (left.length) {
|
|
646
|
-
err(
|
|
647
|
-
[
|
|
648
|
-
"TEARDOWN could not remove:",
|
|
649
|
-
...left.map((l) => ` - ${l}`),
|
|
650
|
-
`Remove them by hand; every Docker resource carries the label ${LABEL}, and every sandbox's name starts with agent-kit-deep-.`,
|
|
651
|
-
].join("\n"),
|
|
652
|
-
);
|
|
653
|
-
return false;
|
|
654
|
-
}
|
|
655
|
-
out(`Teardown: removed ${commands.map((c) => c.what).join(", ")}.`);
|
|
656
|
-
return true;
|
|
657
|
-
}
|
|
658
|
-
|
|
659
549
|
async function fetchGrounding(fetch, url, where, clocks) {
|
|
660
550
|
const fail = (why) =>
|
|
661
551
|
new StepFailed([`FAILED ${where}: could not fetch ${url}: ${why}`, ENDS_HERE]);
|
package/src/deep-scan/limits.mjs
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
// The limits that bound every Deep scan (#371), all enforced from outside
|
|
2
2
|
// the sandbox: the setup and scan wall clocks by the launcher, the turns by
|
|
3
|
-
// the launcher's own `--max-turns` on the claude command line
|
|
4
|
-
//
|
|
3
|
+
// the launcher's own `--max-turns` on the claude command line (a harness with
|
|
4
|
+
// no turn limit, such as Codex CLI, has none), and the token cap by the model
|
|
5
|
+
// proxy, which counts the model API's returned `usage`.
|
|
5
6
|
// Limits come from launcher flags only (and, in CI, workflow inputs): the
|
|
6
7
|
// Scan recipe never sets them (recipe.mjs refuses a limit field), so a
|
|
7
8
|
// merged recipe change cannot raise a run's spend.
|
|
@@ -73,12 +74,17 @@ export function parseLimits(values, defaults = DEFAULT_LIMITS) {
|
|
|
73
74
|
return { limits };
|
|
74
75
|
}
|
|
75
76
|
|
|
76
|
-
/**
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
77
|
+
/**
|
|
78
|
+
* The limits as one line of the launcher's output. A harness with no turn
|
|
79
|
+
* limit (`turnLimit: false`) names none.
|
|
80
|
+
*/
|
|
81
|
+
export function describeLimits(limits, { turnLimit = true } = {}) {
|
|
82
|
+
const flags = Object.entries(LIMIT_FLAGS)
|
|
83
|
+
.filter(([key]) => turnLimit || key !== "turns")
|
|
84
|
+
.map(([, f]) => `--${f.flag}`)
|
|
80
85
|
.join(", ");
|
|
81
|
-
|
|
86
|
+
const turns = turnLimit ? `${limits.turns} turns, ` : "";
|
|
87
|
+
return `Limits: setup ${limits.setupMinutes} min, scan ${limits.scanMinutes} min, ${turns}${limits.tokens} tokens (raise them with ${flags}).`;
|
|
82
88
|
}
|
|
83
89
|
|
|
84
90
|
/** A run stopped by a limit: what fired, said for a person. */
|
|
@@ -1,12 +1,18 @@
|
|
|
1
1
|
// The scan phase's only route out (#370): the model proxy's core
|
|
2
2
|
// (../model-proxy/core.mjs), which runs in the launcher, on the host, outside
|
|
3
|
-
// the sandbox, with the
|
|
4
|
-
//
|
|
5
|
-
//
|
|
6
|
-
// goes in. Node core only
|
|
3
|
+
// the sandbox, with the provider profile the harness's launch plan names
|
|
4
|
+
// (ADR 0023): `anthropic`, `openai` or `gemini-api`. The core's header says what is
|
|
5
|
+
// forwarded and how the run's token cap (#371) holds; each profile's says what
|
|
6
|
+
// of its API passes, and how the real credential goes in. Node core only
|
|
7
|
+
// (ADR 0001).
|
|
7
8
|
|
|
8
9
|
import { startProxy } from "../model-proxy/core.mjs";
|
|
9
10
|
import { anthropic } from "../model-proxy/profiles/anthropic.mjs";
|
|
11
|
+
import { geminiApi } from "../model-proxy/profiles/gemini-api.mjs";
|
|
12
|
+
import { openai } from "../model-proxy/profiles/openai.mjs";
|
|
13
|
+
|
|
14
|
+
/** The provider profiles a launch plan's model route may name. */
|
|
15
|
+
export const PROFILES = Object.freeze({ anthropic, openai, "gemini-api": geminiApi });
|
|
10
16
|
|
|
11
17
|
export { MAX_IN_FLIGHT, MODEL_ID } from "../model-proxy/core.mjs";
|
|
12
18
|
export {
|
|
@@ -20,13 +26,15 @@ export {
|
|
|
20
26
|
/**
|
|
21
27
|
* Start the Deep scan's model proxy on `bind`. See startProxy in the core for
|
|
22
28
|
* every option and for what it returns.
|
|
23
|
-
* @param {{ credential: string, kind?: "api-key" | "subscription", bind: string, upstream?: string, maxTokens?: number, onCap?: () => void, callerKey?: string }} opts
|
|
24
|
-
* `
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
29
|
+
* @param {{ profile?: string, credential: string, kind?: "api-key" | "subscription", bind: string, upstream?: string, maxTokens?: number, onCap?: () => void, callerKey?: string }} opts
|
|
30
|
+
* `profile` names one of PROFILES (default `anthropic`). `kind` is the
|
|
31
|
+
* credential's (default an API key). `upstream` is the model API; only
|
|
32
|
+
* tests pass another. `callerKey`, when given, is the only value accepted
|
|
33
|
+
* as the caller's key, in the profile's key headers or as a bearer value;
|
|
34
|
+
* the launcher always gives one.
|
|
28
35
|
*/
|
|
29
36
|
export async function startModelProxy({
|
|
37
|
+
profile = "anthropic",
|
|
30
38
|
credential,
|
|
31
39
|
kind = "api-key",
|
|
32
40
|
bind,
|
|
@@ -35,7 +43,10 @@ export async function startModelProxy({
|
|
|
35
43
|
onCap,
|
|
36
44
|
callerKey,
|
|
37
45
|
}) {
|
|
38
|
-
|
|
46
|
+
if (!Object.hasOwn(PROFILES, profile)) {
|
|
47
|
+
throw new Error(`the model proxy has no provider profile ${JSON.stringify(profile)}`);
|
|
48
|
+
}
|
|
49
|
+
return startProxy(PROFILES[profile], {
|
|
39
50
|
credential,
|
|
40
51
|
kind,
|
|
41
52
|
bind,
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
|
|
10
10
|
import { appendFileSync } from "node:fs";
|
|
11
11
|
import { firstLine } from "../exec.mjs";
|
|
12
|
-
import {
|
|
12
|
+
import { harnessFacts, supportFor } from "../harness/facts.mjs";
|
|
13
13
|
import { MUSL_MARKER } from "../harness/install-layer.mjs";
|
|
14
14
|
import { ENDS_HERE, outputLines, StepFailed } from "./steps.mjs";
|
|
15
15
|
|
|
@@ -44,13 +44,26 @@ export function refuseMusl(r, { image, dockerfile }) {
|
|
|
44
44
|
* @returns {{ line: string, summary: string, refused?: string, warning?: string }}
|
|
45
45
|
*/
|
|
46
46
|
export function deepScanSupport({ harness = "claude-code", provingRun = false }) {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
47
|
+
return stageSupport({ harness, stage: "deep-scan", provingRun });
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* The same for any Stage the Launcher runs (`security-audit`, `deep-scan`).
|
|
52
|
+
* A Custom harness is marked "custom, attested" where its file attests the
|
|
53
|
+
* pair's level, which the kit cannot check (ADR 0028).
|
|
54
|
+
* @param {{ harness: string, stage: string, provingRun?: boolean }} run
|
|
55
|
+
* @returns {{ line: string, summary: string, refused?: string, warning?: string }}
|
|
56
|
+
*/
|
|
57
|
+
export function stageSupport({ harness, stage, provingRun = false }) {
|
|
58
|
+
const facts = harnessFacts(harness);
|
|
59
|
+
const found = supportFor(facts, { stage, provingRun });
|
|
60
|
+
const level = facts.supportLevels[stage]?.level ?? "none";
|
|
50
61
|
const proving = provingRun ? "yes" : "no";
|
|
62
|
+
const attested = level === "documented" ? "no attestation" : "attested";
|
|
63
|
+
const custom = facts.custom ? ` (custom, ${attested})` : "";
|
|
51
64
|
return {
|
|
52
|
-
line: `Harness: ${harness}; Support Level: ${level}; Proving run: ${proving}`,
|
|
53
|
-
summary: `Harness: \`${harness}
|
|
65
|
+
line: `Harness: ${harness}${custom}; Support Level: ${level}; Proving run: ${proving}`,
|
|
66
|
+
summary: `Harness: \`${harness}\`${custom} · Support Level: \`${level}\` · Proving run: ${proving}`,
|
|
54
67
|
...(found.refused !== undefined ? { refused: found.refused } : {}),
|
|
55
68
|
...(found.warning !== undefined ? { warning: found.warning } : {}),
|
|
56
69
|
};
|
package/src/deep-scan/recipe.mjs
CHANGED
|
@@ -56,6 +56,10 @@ const CREDENTIALS = [
|
|
|
56
56
|
[/\bgh[pousr]_[A-Za-z0-9]{20,}/, "a GitHub token"],
|
|
57
57
|
[/\bgithub_pat_[A-Za-z0-9_]{20,}/, "a GitHub token"],
|
|
58
58
|
[/\bsk-ant-[A-Za-z0-9_-]{10,}/, "an Anthropic API key"],
|
|
59
|
+
[/\bsk-(?:proj|svcacct|admin)-[A-Za-z0-9_-]{10,}/, "an OpenAI API key"],
|
|
60
|
+
// A legacy user key, by the marker inside it.
|
|
61
|
+
[/\bsk-[A-Za-z0-9_-]{0,100}T3BlbkFJ/, "an OpenAI API key"],
|
|
62
|
+
[/\bAIza[0-9A-Za-z_-]{35}/, "a Google API key"],
|
|
59
63
|
[/\bAKIA[0-9A-Z]{16}\b/, "an AWS access key"],
|
|
60
64
|
[/\bxox[abposr]-[A-Za-z0-9-]{10,}/, "a Slack token"],
|
|
61
65
|
[/-----BEGIN [A-Z ]*PRIVATE KEY-----/, "a private key"],
|