@mnaimfaizy/agent-kit 1.0.0-beta.13 → 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 +16 -19
- package/src/deep-scan/docker-driver.mjs +32 -13
- package/src/deep-scan/lifecycle.mjs +32 -29
- package/src/deep-scan/model-proxy.mjs +31 -597
- package/src/deep-scan/preflight.mjs +68 -1
- package/src/deep-scan/recipe.mjs +3 -7
- package/src/deep-scan/sbx-driver.mjs +28 -21
- package/src/deep-scan.mjs +33 -9
- 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
|
@@ -12,23 +12,26 @@
|
|
|
12
12
|
|
|
13
13
|
import { randomBytes } from "node:crypto";
|
|
14
14
|
import { firstLine } from "../exec.mjs";
|
|
15
|
+
import { claudeCode } from "../harness/claude-code.mjs";
|
|
15
16
|
import { GITHUB_TOKEN_VARS } from "./preflight.mjs";
|
|
16
17
|
|
|
17
|
-
/**
|
|
18
|
-
|
|
18
|
+
/**
|
|
19
|
+
* The credentials the harness accepts, from its launch plan: each kind's
|
|
20
|
+
* variable is also the one it is read from by default.
|
|
21
|
+
*/
|
|
22
|
+
const { accepted, scrub } = claudeCode().credentials;
|
|
19
23
|
|
|
20
24
|
/**
|
|
21
|
-
* The start of the key the sandboxed
|
|
22
|
-
*
|
|
25
|
+
* The start of the key the sandboxed agent holds in place of a real one;
|
|
26
|
+
* the proxy swaps it for the real key.
|
|
23
27
|
*/
|
|
24
|
-
export const PLACEHOLDER_API_KEY = "
|
|
28
|
+
export const PLACEHOLDER_API_KEY = accepted["api-key"].placeholder;
|
|
25
29
|
|
|
26
30
|
/**
|
|
27
|
-
* The start of the token the sandboxed
|
|
28
|
-
*
|
|
29
|
-
* like a token, in case Claude Code checks the prefix.
|
|
31
|
+
* The start of the token the sandboxed agent holds on the subscription
|
|
32
|
+
* path; the proxy swaps the bearer value it sends.
|
|
30
33
|
*/
|
|
31
|
-
export const PLACEHOLDER_OAUTH_TOKEN =
|
|
34
|
+
export const PLACEHOLDER_OAUTH_TOKEN = accepted.subscription.placeholder;
|
|
32
35
|
|
|
33
36
|
/**
|
|
34
37
|
* The run's caller key: a placeholder with 24 random bytes added, made once
|
|
@@ -49,14 +52,8 @@ export const SUBSCRIPTION = "subscription";
|
|
|
49
52
|
const CREDENTIAL_KINDS = Object.freeze([API_KEY, SUBSCRIPTION]);
|
|
50
53
|
|
|
51
54
|
/** Model credential variables, removed from every command the launcher runs. */
|
|
52
|
-
export const CREDENTIAL_VARS = Object.freeze(
|
|
53
|
-
|
|
54
|
-
"ANTHROPIC_AUTH_TOKEN",
|
|
55
|
-
"CLAUDE_CODE_OAUTH_TOKEN",
|
|
56
|
-
]);
|
|
57
|
-
|
|
58
|
-
/** The variable Claude Code reads a subscription (OAuth) token from. */
|
|
59
|
-
const OAUTH_TOKEN_VAR = "CLAUDE_CODE_OAUTH_TOKEN";
|
|
55
|
+
export const CREDENTIAL_VARS = Object.freeze(scrub);
|
|
56
|
+
|
|
60
57
|
/** How a Claude subscription (OAuth) token starts; an API key starts sk-ant-api. */
|
|
61
58
|
const OAUTH_TOKEN_PREFIX = "sk-ant-oat";
|
|
62
59
|
|
|
@@ -89,7 +86,7 @@ export function credentialKind(value) {
|
|
|
89
86
|
*/
|
|
90
87
|
export function credentialSource(value, kind = API_KEY) {
|
|
91
88
|
if (value === undefined) {
|
|
92
|
-
return { kind: "env", name: kind
|
|
89
|
+
return { kind: "env", name: accepted[kind].env };
|
|
93
90
|
}
|
|
94
91
|
if (value.startsWith("env:")) {
|
|
95
92
|
const name = value.slice(4);
|
|
@@ -136,7 +133,7 @@ export function readCredential({ source, env, runner, kind = API_KEY }) {
|
|
|
136
133
|
);
|
|
137
134
|
}
|
|
138
135
|
const { name } = source;
|
|
139
|
-
if (!token && name.toUpperCase() ===
|
|
136
|
+
if (!token && name.toUpperCase() === accepted[SUBSCRIPTION].env) return notAnApiKey(name);
|
|
140
137
|
const command = `npx @mnaimfaizy/agent-kit deep-scan${token ? " --credential subscription" : ""}`;
|
|
141
138
|
const value = valueOf(env, name);
|
|
142
139
|
if (!value) {
|
|
@@ -32,8 +32,9 @@
|
|
|
32
32
|
// scan's only route to the internet.
|
|
33
33
|
|
|
34
34
|
import { isIPv4 } from "node:net";
|
|
35
|
-
import { layerDockerfile } from "
|
|
35
|
+
import { layerDockerfile, pinnedHarnessImage } from "../harness/install-layer.mjs";
|
|
36
36
|
import { startEgressProxy } from "./egress.mjs";
|
|
37
|
+
import { refuseMusl } from "./preflight.mjs";
|
|
37
38
|
import { imageDigestNote } from "./recipe.mjs";
|
|
38
39
|
import {
|
|
39
40
|
OTHER_HOST_PORT,
|
|
@@ -61,10 +62,12 @@ export const ISOLATED_OPTIONS = Object.freeze([
|
|
|
61
62
|
]);
|
|
62
63
|
|
|
63
64
|
/**
|
|
64
|
-
* @param {{ runtime: import("./runtime.mjs").Runtime, id: string, call: Call }} opts
|
|
65
|
+
* @param {{ runtime: import("./runtime.mjs").Runtime, id: string, call: Call, plan: import("../harness/claude-code.mjs").LaunchPlan }} opts
|
|
66
|
+
* `plan` is the harness's launch plan: its install layer goes on the image.
|
|
65
67
|
* @returns {import("./lifecycle.mjs").Driver}
|
|
66
68
|
*/
|
|
67
|
-
export function dockerDriver({ runtime, id, call }) {
|
|
69
|
+
export function dockerDriver({ runtime, id, call, plan }) {
|
|
70
|
+
const { displayName } = plan.identity;
|
|
68
71
|
const name = `agent-kit-deep-${id}`;
|
|
69
72
|
const label = `${LABEL}=${id}`;
|
|
70
73
|
const docker = (args, opts) => call("docker", args, opts);
|
|
@@ -91,11 +94,26 @@ export function dockerDriver({ runtime, id, call }) {
|
|
|
91
94
|
let hostGateway = null;
|
|
92
95
|
/** The relay image, once built. */
|
|
93
96
|
let relayImage = null;
|
|
97
|
+
/** What the sandbox runs: the Harness image, or the run's layered image. */
|
|
98
|
+
let sandboxImage = null;
|
|
94
99
|
|
|
95
100
|
return {
|
|
96
101
|
container: name,
|
|
97
102
|
|
|
98
103
|
async prepare(steps, { archive, out, branch, short }) {
|
|
104
|
+
const harness = pinnedHarnessImage(plan.installLayer);
|
|
105
|
+
// No image of the recipe's: the sandbox runs the Harness image, which
|
|
106
|
+
// is not this run's to remove.
|
|
107
|
+
if (steps.dockerfile === undefined && steps.image === undefined) {
|
|
108
|
+
out(
|
|
109
|
+
`Image: pulling the Harness image ${harness}, which holds the pinned ${displayName}; the recipe names no image.`,
|
|
110
|
+
);
|
|
111
|
+
must(await docker(["pull", harness]), `pulling the Harness image ${harness}`, {
|
|
112
|
+
showOutput: true,
|
|
113
|
+
});
|
|
114
|
+
sandboxImage = harness;
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
99
117
|
let base;
|
|
100
118
|
if (steps.dockerfile !== undefined) {
|
|
101
119
|
out(`Image: building ${steps.dockerfile} from ${branch} (${short}).`);
|
|
@@ -117,15 +135,16 @@ export function dockerDriver({ runtime, id, call }) {
|
|
|
117
135
|
if (note) out(note);
|
|
118
136
|
must(await docker(["pull", base]), `pulling ${base}`, { showOutput: true });
|
|
119
137
|
}
|
|
120
|
-
out(
|
|
121
|
-
|
|
122
|
-
must(
|
|
123
|
-
await docker(["build", "--label", label, "--tag", name, "-"], {
|
|
124
|
-
stdin: layerDockerfile(base),
|
|
125
|
-
}),
|
|
126
|
-
`layering Claude Code on ${base}`,
|
|
127
|
-
{ showOutput: true },
|
|
138
|
+
out(
|
|
139
|
+
`Image: layering the pinned ${displayName}, auto-updater off, from the Harness image ${harness}.`,
|
|
128
140
|
);
|
|
141
|
+
resources.push(["image", name]);
|
|
142
|
+
const layered = await docker(["build", "--label", label, "--tag", name, "-"], {
|
|
143
|
+
stdin: layerDockerfile(base, plan.installLayer),
|
|
144
|
+
});
|
|
145
|
+
refuseMusl(layered, steps);
|
|
146
|
+
must(layered, `layering ${displayName} on ${base}`, { showOutput: true });
|
|
147
|
+
sandboxImage = name;
|
|
129
148
|
},
|
|
130
149
|
|
|
131
150
|
/**
|
|
@@ -164,7 +183,7 @@ export function dockerDriver({ runtime, id, call }) {
|
|
|
164
183
|
"/workspace",
|
|
165
184
|
"--entrypoint",
|
|
166
185
|
"tail",
|
|
167
|
-
|
|
186
|
+
sandboxImage,
|
|
168
187
|
"-f",
|
|
169
188
|
"/dev/null",
|
|
170
189
|
]),
|
|
@@ -193,7 +212,7 @@ export function dockerDriver({ runtime, id, call }) {
|
|
|
193
212
|
);
|
|
194
213
|
},
|
|
195
214
|
|
|
196
|
-
/**
|
|
215
|
+
/** The harness is already in the image. */
|
|
197
216
|
async installAgent() {},
|
|
198
217
|
|
|
199
218
|
/** The setup egress was opened with the network: the proxy's variables. */
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// The Deep scan sandbox lifecycle (#369), from image to teardown, on the
|
|
2
|
-
// runtime `selectRuntime` chose. In order: prepare the image (
|
|
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: a pinned
|
|
3
4
|
// Claude Code, its auto-updater off); start the sandbox with no mount; copy
|
|
4
5
|
// in an export of the trusted ref (never the working tree) and the grounding
|
|
5
6
|
// files, and nothing else; run the setup phase (`setup`, `start`, `ready`,
|
|
@@ -29,8 +30,7 @@ import { mkdtempSync, writeFileSync } from "node:fs";
|
|
|
29
30
|
import { tmpdir } from "node:os";
|
|
30
31
|
import { join } from "node:path";
|
|
31
32
|
import { firstLine } from "../exec.mjs";
|
|
32
|
-
import { agentBrief,
|
|
33
|
-
import { CLAUDE_CODE_VERSION, layerDockerfile } from "./claude-code.mjs";
|
|
33
|
+
import { agentBrief, agentPlan, agentScript, BRIEF_PATH, turnsMarker } from "./agent.mjs";
|
|
34
34
|
import { callerKeyFor } from "./credential.mjs";
|
|
35
35
|
import { dockerDriver, LABEL } from "./docker-driver.mjs";
|
|
36
36
|
import { groundingUrlProblem, isGroundingUrl } from "./grounding-url.mjs";
|
|
@@ -49,7 +49,7 @@ import { ENDS_HERE, indent, Interrupted, outputLines, StepFailed } from "./steps
|
|
|
49
49
|
import { tarOf } from "./tar.mjs";
|
|
50
50
|
import { checkVerificationReport, FINDINGS_PATH, verificationBrief } from "./verify.mjs";
|
|
51
51
|
|
|
52
|
-
export {
|
|
52
|
+
export { LABEL };
|
|
53
53
|
|
|
54
54
|
/** Where the sandbox holds the repository, the grounding and the report. */
|
|
55
55
|
export const WORKSPACE = "/workspace";
|
|
@@ -66,9 +66,6 @@ export const MAX_GROUNDING_BYTES = 10 * 1024 * 1024;
|
|
|
66
66
|
export const MAX_EXPORT_BYTES = 1024 * 1024 * 1024;
|
|
67
67
|
const GROUNDING_TIMEOUT_MS = 60_000;
|
|
68
68
|
|
|
69
|
-
/** What the Agent step line says for a model or effort not asked for. */
|
|
70
|
-
const CLAUDE_DEFAULT = "Claude Code's default";
|
|
71
|
-
|
|
72
69
|
/** Why a line is withheld from a world-readable log. */
|
|
73
70
|
const PUBLIC_LOG = "the Public-log rule: this log is world-readable in GitHub Actions";
|
|
74
71
|
|
|
@@ -87,7 +84,7 @@ function credentialRefusedLine(kind, from) {
|
|
|
87
84
|
return `The model API refused the credential: every answer was 401 or 403, so ${what}`;
|
|
88
85
|
}
|
|
89
86
|
|
|
90
|
-
/** How many lines of
|
|
87
|
+
/** How many lines of the harness's error output a failed agent step shows. */
|
|
91
88
|
const AGENT_ERROR_LINES = 20;
|
|
92
89
|
|
|
93
90
|
/** The setup phase's fields, in the order they run: services before seeding. */
|
|
@@ -225,8 +222,12 @@ export async function runLifecycle(opts) {
|
|
|
225
222
|
return r;
|
|
226
223
|
};
|
|
227
224
|
const id = randomBytes(6).toString("hex");
|
|
225
|
+
// The harness's launch plan: the drivers put its install layer on the image.
|
|
226
|
+
const plan = agentPlan({ kind: opts.credentialKind });
|
|
228
227
|
const driver =
|
|
229
|
-
runtime.id === "sbx"
|
|
228
|
+
runtime.id === "sbx"
|
|
229
|
+
? sbxDriver({ id, call, plan })
|
|
230
|
+
: dockerDriver({ runtime, id, call, plan });
|
|
230
231
|
|
|
231
232
|
let code;
|
|
232
233
|
let thrown = null;
|
|
@@ -318,7 +319,7 @@ async function lifecycle({
|
|
|
318
319
|
return r.stdout;
|
|
319
320
|
};
|
|
320
321
|
|
|
321
|
-
// 1. Image, and its pinned
|
|
322
|
+
// 1. Image, and its pinned harness (or the runtime's refusal).
|
|
322
323
|
await driver.prepare(steps, { archive, out, branch, short });
|
|
323
324
|
|
|
324
325
|
// 2. The sandbox: no mount, no host environment, no Docker socket.
|
|
@@ -447,7 +448,7 @@ async function lifecycle({
|
|
|
447
448
|
`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.`,
|
|
448
449
|
);
|
|
449
450
|
|
|
450
|
-
// 7. The agent step:
|
|
451
|
+
// 7. The agent step: the harness with a placeholder key, handed its brief.
|
|
451
452
|
// A Verification run's finding file goes in with it, after the setup phase
|
|
452
453
|
// and the cut, so no setup step, which has registry egress, can read it.
|
|
453
454
|
const paths = { workspace: WORKSPACE, grounding: GROUNDING_DIR, report: REPORT_PATH };
|
|
@@ -487,8 +488,19 @@ async function lifecycle({
|
|
|
487
488
|
? "copying the launcher's brief and the finding file in"
|
|
488
489
|
: "copying the launcher's brief in",
|
|
489
490
|
);
|
|
491
|
+
const plan = agentPlan({
|
|
492
|
+
baseUrl: route.url,
|
|
493
|
+
maxTurns: limits.turns,
|
|
494
|
+
model,
|
|
495
|
+
effort,
|
|
496
|
+
kind: credentialKind,
|
|
497
|
+
callerKey,
|
|
498
|
+
});
|
|
499
|
+
const { displayName, version } = plan.identity;
|
|
500
|
+
/** What the line says for a model or effort not asked for. */
|
|
501
|
+
const unasked = `${displayName}'s default`;
|
|
490
502
|
out(
|
|
491
|
-
`Agent step:
|
|
503
|
+
`Agent step: ${displayName} ${version} (${subscription ? "no --bare: the subscription path, with a placeholder token; project settings and MCP servers not loaded" : "--bare, a placeholder key"}, web tools off, at most ${limits.turns} turns; 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.`,
|
|
492
504
|
);
|
|
493
505
|
clocks.end();
|
|
494
506
|
// The scan wall clock: the agent step alone.
|
|
@@ -496,25 +508,16 @@ async function lifecycle({
|
|
|
496
508
|
/** @type {import("../exec.mjs").StartResult | null} null when a limit stopped it */
|
|
497
509
|
let agent = null;
|
|
498
510
|
try {
|
|
499
|
-
agent = await driver.exec(
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
report: REPORT_PATH,
|
|
503
|
-
workspace: WORKSPACE,
|
|
504
|
-
maxTurns: limits.turns,
|
|
505
|
-
...(model !== undefined ? { model } : {}),
|
|
506
|
-
...(effort !== undefined ? { effort } : {}),
|
|
507
|
-
kind: credentialKind,
|
|
508
|
-
}),
|
|
509
|
-
{ env: agentEnv(credentialKind, callerKey) },
|
|
510
|
-
);
|
|
511
|
+
agent = await driver.exec(agentScript({ plan, report: REPORT_PATH, workspace: WORKSPACE }), {
|
|
512
|
+
env: plan.launch.env,
|
|
513
|
+
});
|
|
511
514
|
} catch (e) {
|
|
512
515
|
if (!(e instanceof LimitReached)) throw e;
|
|
513
516
|
}
|
|
514
517
|
clocks.end();
|
|
515
|
-
//
|
|
516
|
-
if (agent && agent.stdout.toString("utf8").split(/\r?\n/).includes(
|
|
517
|
-
clocks.stop(TURNS,
|
|
518
|
+
// The harness's own turn limit ended it: the script's fixed marker says so.
|
|
519
|
+
if (agent && agent.stdout.toString("utf8").split(/\r?\n/).includes(turnsMarker(plan))) {
|
|
520
|
+
clocks.stop(TURNS, `${displayName}'s ${limits.turns}-turn limit`);
|
|
518
521
|
}
|
|
519
522
|
// The scan is over: no route out is left open while the report comes out.
|
|
520
523
|
await driver.close();
|
|
@@ -535,7 +538,7 @@ async function lifecycle({
|
|
|
535
538
|
out(`${stoppedStatus(stopped)} Copying out what report the agent left.`);
|
|
536
539
|
} else if (agent && agent.status !== 0 && publicLog) {
|
|
537
540
|
err(
|
|
538
|
-
`The agent step exited ${agent.status ?? "abnormally"}; copying out what report it left.
|
|
541
|
+
`The agent step exited ${agent.status ?? "abnormally"}; copying out what report it left. ${displayName}'s error output stays in the sandbox (${PUBLIC_LOG}); run deep-scan locally to see it.`,
|
|
539
542
|
);
|
|
540
543
|
} else if (agent && agent.status !== 0) {
|
|
541
544
|
const lines = agent.stderr
|
|
@@ -547,7 +550,7 @@ async function lifecycle({
|
|
|
547
550
|
`The agent step exited ${agent.status ?? "abnormally"}; copying out what report it left.`,
|
|
548
551
|
...(lines.length
|
|
549
552
|
? [
|
|
550
|
-
|
|
553
|
+
`${displayName}'s error output (its last ${AGENT_ERROR_LINES} lines at most; the rest of its output stays in the sandbox):`,
|
|
551
554
|
...indent(lines.slice(-AGENT_ERROR_LINES).join("\n")),
|
|
552
555
|
]
|
|
553
556
|
: []),
|