@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,299 @@
|
|
|
1
|
+
// A Custom harness (ADR 0027): a Consumer's data-only file,
|
|
2
|
+
// `.agent-kit/harnesses/<name>.json`, selected as `custom:<name>`. Here are its
|
|
3
|
+
// check against the schema, its read from the trusted commit (never the
|
|
4
|
+
// checkout under review), and the adapter, facts and text built from it. It
|
|
5
|
+
// holds no command and names no host: it installs one npm package at an exact
|
|
6
|
+
// version, and its sandbox reaches the model proxy alone, through one of the
|
|
7
|
+
// three provider profiles.
|
|
8
|
+
//
|
|
9
|
+
// The file is the launch plan with four slots: `{model}`, `{effort}`,
|
|
10
|
+
// `{brief}` (the brief's path) and `{proxy_url}`. Each is replaced once, in the
|
|
11
|
+
// file's own text; a value is never searched for slots. In `argv`, a word (or a
|
|
12
|
+
// list of words) holding a slot with no value is left out whole, and so is an
|
|
13
|
+
// `env` entry; in a config file's text the slot becomes empty.
|
|
14
|
+
|
|
15
|
+
import { readFileSync } from "node:fs";
|
|
16
|
+
import { registerCustom } from "./custom/registry.mjs";
|
|
17
|
+
import { problems as schemaProblems } from "./custom/schema.mjs";
|
|
18
|
+
|
|
19
|
+
/** The repository folder the files sit in. */
|
|
20
|
+
export const CUSTOM_DIR = ".agent-kit/harnesses";
|
|
21
|
+
|
|
22
|
+
/** The schema's path in a kit tag, beside harnesses.json. */
|
|
23
|
+
export const SCHEMA_PATH = "cli/custom-harness.schema.json";
|
|
24
|
+
|
|
25
|
+
/** The largest file the kit reads. */
|
|
26
|
+
export const MAX_BYTES = 64 * 1024;
|
|
27
|
+
|
|
28
|
+
const NAME = /^custom:([A-Za-z0-9][A-Za-z0-9._-]*)$/;
|
|
29
|
+
|
|
30
|
+
/** The path `custom:<name>` is read from. */
|
|
31
|
+
export function customPath(harness) {
|
|
32
|
+
const name = NAME.exec(harness)?.[1];
|
|
33
|
+
if (name === undefined) throw new Error(`not a Custom harness: ${JSON.stringify(harness)}`);
|
|
34
|
+
return `${CUSTOM_DIR}/${name}.json`;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** The credential each provider profile takes. */
|
|
38
|
+
export const PROFILES = Object.freeze({
|
|
39
|
+
anthropic: Object.freeze({
|
|
40
|
+
displayName: "Anthropic",
|
|
41
|
+
secret: "anthropic_api_key",
|
|
42
|
+
env: "ANTHROPIC_API_KEY",
|
|
43
|
+
whereToGet:
|
|
44
|
+
"Create an API key in a dedicated Anthropic Console workspace with its own spend limit: https://console.anthropic.com/settings/keys.",
|
|
45
|
+
}),
|
|
46
|
+
openai: Object.freeze({
|
|
47
|
+
displayName: "OpenAI",
|
|
48
|
+
secret: "openai_api_key",
|
|
49
|
+
env: "OPENAI_API_KEY",
|
|
50
|
+
whereToGet:
|
|
51
|
+
"Create an API key in the OpenAI platform, in a project with its own budget: https://platform.openai.com/api-keys.",
|
|
52
|
+
}),
|
|
53
|
+
"gemini-api": Object.freeze({
|
|
54
|
+
displayName: "Gemini",
|
|
55
|
+
secret: "gemini_api_key",
|
|
56
|
+
env: "GEMINI_API_KEY",
|
|
57
|
+
whereToGet:
|
|
58
|
+
"Create an API key in Google AI Studio, in a project with its own budget: https://aistudio.google.com/apikey.",
|
|
59
|
+
}),
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
const PLACEHOLDER = "agent-kit-deep-scan-placeholder";
|
|
63
|
+
|
|
64
|
+
/** The schema this version ships. */
|
|
65
|
+
export const readSchema = () =>
|
|
66
|
+
JSON.parse(readFileSync(new URL("../../custom-harness.schema.json", import.meta.url), "utf8"));
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* The file `text` holds, or why it is not a Custom harness file.
|
|
70
|
+
* @param {string} text
|
|
71
|
+
* @param {{ schema?: object }} [opts] doctor passes the pinned tag's schema.
|
|
72
|
+
* @returns {{ file: object } | { problems: string[] }}
|
|
73
|
+
*/
|
|
74
|
+
export function parseCustomHarness(text, { schema = readSchema() } = {}) {
|
|
75
|
+
let file;
|
|
76
|
+
try {
|
|
77
|
+
file = JSON.parse(text.replace(/^/, ""));
|
|
78
|
+
} catch {
|
|
79
|
+
return { problems: ["the file: it is not JSON"] };
|
|
80
|
+
}
|
|
81
|
+
const found = schemaProblems(schema, file);
|
|
82
|
+
if (found.length) return { problems: found };
|
|
83
|
+
const { stdin, argv, files = [], env = {} } = file.launch;
|
|
84
|
+
const words = [argv.flat(), files.map((f) => f.text), Object.values(env)].flat();
|
|
85
|
+
if (stdin !== "{brief}" && !words.some((word) => word.includes("{brief}"))) {
|
|
86
|
+
return {
|
|
87
|
+
problems: [
|
|
88
|
+
'launch: the harness never takes the brief: set stdin to "{brief}", or put {brief} in argv, a file or a variable',
|
|
89
|
+
],
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
return { file };
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const SLOT = /(?<!\$)\{(model|effort|brief|proxy_url)\}/g;
|
|
96
|
+
|
|
97
|
+
/** `word` with its slots filled, or null when one of them has no value. */
|
|
98
|
+
function filled(word, values) {
|
|
99
|
+
let missing = false;
|
|
100
|
+
const text = word.replace(SLOT, (_, slot) => {
|
|
101
|
+
if (values[slot] === undefined) missing = true;
|
|
102
|
+
return values[slot] ?? "";
|
|
103
|
+
});
|
|
104
|
+
return missing ? null : text;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* The Harness adapter of a Custom harness file: it takes a Stage request, as
|
|
109
|
+
* the Claude Code adapter describes it, and returns the nine-part launch plan.
|
|
110
|
+
* `maxTurns` is ignored, since no slot carries it, and the only
|
|
111
|
+
* `credentialKind` is `api-key`.
|
|
112
|
+
* @param {string} harness `custom:<name>`
|
|
113
|
+
* @param {object} file one `parseCustomHarness` accepted
|
|
114
|
+
*/
|
|
115
|
+
export function customAdapter(harness, file) {
|
|
116
|
+
const { profile, version } = file;
|
|
117
|
+
const { secret, env: variable } = PROFILES[profile];
|
|
118
|
+
const displayName = file.display_name ?? harness;
|
|
119
|
+
return function custom({
|
|
120
|
+
model = file.default_model,
|
|
121
|
+
effort,
|
|
122
|
+
credentialKind = "api-key",
|
|
123
|
+
proxyUrl,
|
|
124
|
+
briefPath,
|
|
125
|
+
kitDir = "/agent-kit",
|
|
126
|
+
callerKey,
|
|
127
|
+
} = {}) {
|
|
128
|
+
if (credentialKind !== "api-key") {
|
|
129
|
+
throw new Error(`${displayName} has no credential kind ${JSON.stringify(credentialKind)}`);
|
|
130
|
+
}
|
|
131
|
+
const placeholder = callerKey ?? PLACEHOLDER;
|
|
132
|
+
const values = {
|
|
133
|
+
model,
|
|
134
|
+
effort: effort === "" ? undefined : effort,
|
|
135
|
+
brief: briefPath,
|
|
136
|
+
proxy_url: proxyUrl,
|
|
137
|
+
};
|
|
138
|
+
const inText = (text) => text.replace(SLOT, (_, slot) => values[slot] ?? "");
|
|
139
|
+
const argv = file.launch.argv.flatMap((item) => {
|
|
140
|
+
const group = [item].flat().map((word) => filled(word, values));
|
|
141
|
+
return group.includes(null) ? [] : group;
|
|
142
|
+
});
|
|
143
|
+
const own = Object.entries(file.launch.env ?? {}).flatMap(([name, word]) => {
|
|
144
|
+
const value = filled(word, values);
|
|
145
|
+
return value === null ? [] : [`${name}=${value}`];
|
|
146
|
+
});
|
|
147
|
+
return {
|
|
148
|
+
identity: {
|
|
149
|
+
name: harness,
|
|
150
|
+
displayName,
|
|
151
|
+
version,
|
|
152
|
+
major: Number(version.split(".")[0]),
|
|
153
|
+
},
|
|
154
|
+
// The Launcher installs this on the sandbox image, at run time.
|
|
155
|
+
installLayer: { npm: `${file.package}@${version}`, env: [], run: [] },
|
|
156
|
+
modelRoute: { profile },
|
|
157
|
+
credentials: {
|
|
158
|
+
accepted: { "api-key": { secret, env: variable, placeholder } },
|
|
159
|
+
scrub: [variable],
|
|
160
|
+
},
|
|
161
|
+
launch: {
|
|
162
|
+
argv,
|
|
163
|
+
stdin: file.launch.stdin && briefPath !== undefined ? { file: briefPath } : null,
|
|
164
|
+
files: (file.launch.files ?? []).map(({ path, text }) => ({
|
|
165
|
+
// The schema holds every file under /agent-kit/custom/.
|
|
166
|
+
path: `${kitDir}${path.slice("/agent-kit".length)}`,
|
|
167
|
+
text: inText(text),
|
|
168
|
+
})),
|
|
169
|
+
env: [
|
|
170
|
+
`${variable}=${placeholder}`,
|
|
171
|
+
...own,
|
|
172
|
+
...(proxyUrl !== undefined ? [`AGENT_KIT_MODEL_PROXY_URL=${proxyUrl}`] : []),
|
|
173
|
+
],
|
|
174
|
+
removeCheckoutConfig: true,
|
|
175
|
+
},
|
|
176
|
+
checkoutConfig: [...file.checkout_config],
|
|
177
|
+
instructionFiles: [...file.instruction_files],
|
|
178
|
+
stops: { turnCap: null },
|
|
179
|
+
transcript: { path: `${kitDir}/logs/agent.log` },
|
|
180
|
+
};
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* The file's facts, in the shape `harnesses.json` gives a built-in harness.
|
|
186
|
+
* `custom` marks the Support Levels as the Consumer's attestation: a Stage the
|
|
187
|
+
* file names none for is at `documented`.
|
|
188
|
+
* @param {string} harness
|
|
189
|
+
* @param {object} file
|
|
190
|
+
* @param {readonly string[]} stages
|
|
191
|
+
*/
|
|
192
|
+
export function customFacts(harness, file, stages) {
|
|
193
|
+
const { secret, whereToGet } = PROFILES[file.profile];
|
|
194
|
+
const effortValues = file.effort_values ?? [];
|
|
195
|
+
return {
|
|
196
|
+
displayName: file.display_name ?? harness,
|
|
197
|
+
secrets: [{ name: secret, whereToGet }],
|
|
198
|
+
effortValues,
|
|
199
|
+
noEffort: effortValues.length === 0,
|
|
200
|
+
defaultModel: file.default_model,
|
|
201
|
+
custom: true,
|
|
202
|
+
supportLevels: Object.fromEntries(
|
|
203
|
+
stages.map((stage) => [
|
|
204
|
+
stage,
|
|
205
|
+
file.support_levels?.[stage] ?? { level: "documented", run: null },
|
|
206
|
+
]),
|
|
207
|
+
),
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/** What a run says of a Custom harness (deep-scan/harness-text.mjs's shape). */
|
|
212
|
+
function customText(file) {
|
|
213
|
+
const { displayName } = PROFILES[file.profile];
|
|
214
|
+
return Object.freeze({
|
|
215
|
+
webOff:
|
|
216
|
+
"the harness's own web tools are whatever its file's launch leaves; the sandbox reaches the model proxy alone",
|
|
217
|
+
agentStep: () =>
|
|
218
|
+
"a Custom harness, a placeholder key, the checkout config its file lists removed",
|
|
219
|
+
turnLimit: false,
|
|
220
|
+
needsKey: `deep-scan on a Custom harness with the ${file.profile} profile needs the ${displayName} API key`,
|
|
221
|
+
keyRefused: `Check that the ${displayName} API key is current and its account is active`,
|
|
222
|
+
...(file.profile === "gemini-api"
|
|
223
|
+
? { refusedAs: "401, 403 or, for a key it does not know, 400" }
|
|
224
|
+
: {}),
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* The blob at `path` in `commit`, or null when the commit has no such path.
|
|
230
|
+
* Throws, in words fit for a refusal, for anything but a plain, small file.
|
|
231
|
+
*/
|
|
232
|
+
function blobAt({ runner, root, commit, path }) {
|
|
233
|
+
const git = (...args) => {
|
|
234
|
+
const r = runner("git", ["-C", root, ...args]);
|
|
235
|
+
if (r.status !== 0) throw new Error(`git could not read ${path}`);
|
|
236
|
+
return r.stdout;
|
|
237
|
+
};
|
|
238
|
+
const listed = git("ls-tree", "--full-tree", "-z", commit, "--", path);
|
|
239
|
+
const entry = listed.split("\0").find((e) => e.endsWith(`\t${path}`));
|
|
240
|
+
if (entry === undefined) return null;
|
|
241
|
+
const [mode, type, oid] = entry.slice(0, entry.indexOf("\t")).split(" ");
|
|
242
|
+
if (type !== "blob" || mode === "120000") throw new Error(`${path} is not a plain file`);
|
|
243
|
+
if (Number(git("cat-file", "-s", oid).trim()) > MAX_BYTES) {
|
|
244
|
+
throw new Error(`${path} is larger than ${MAX_BYTES / 1024} KiB`);
|
|
245
|
+
}
|
|
246
|
+
return git("cat-file", "blob", oid);
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
/**
|
|
250
|
+
* Read `harness`'s file as `commit` has it, check it, and register its
|
|
251
|
+
* adapter, facts and text under the name.
|
|
252
|
+
* @param {{
|
|
253
|
+
* harness: string,
|
|
254
|
+
* runner: import("../exec.mjs").Runner,
|
|
255
|
+
* root: string,
|
|
256
|
+
* commit: string,
|
|
257
|
+
* at: string,
|
|
258
|
+
* stages: readonly string[],
|
|
259
|
+
* }} opts `at` is what the refusals call the commit.
|
|
260
|
+
* @returns {{ file: object, text: string } | { refused: string[] }}
|
|
261
|
+
*/
|
|
262
|
+
export function loadCustomFile({ harness, runner, root, commit, at, stages }) {
|
|
263
|
+
const path = customPath(harness);
|
|
264
|
+
let text;
|
|
265
|
+
try {
|
|
266
|
+
text = blobAt({ runner, root, commit, path });
|
|
267
|
+
} catch (e) {
|
|
268
|
+
return { refused: [`Cannot read ${harness} at ${at}: ${e.message}.`] };
|
|
269
|
+
}
|
|
270
|
+
if (text === null) {
|
|
271
|
+
return {
|
|
272
|
+
refused: [
|
|
273
|
+
`${path} is not in ${at}, the trusted commit ${harness} is read from: a file in the checkout alone is never read. Commit it there (and push it), then run again.`,
|
|
274
|
+
],
|
|
275
|
+
};
|
|
276
|
+
}
|
|
277
|
+
const used = useCustomText({ harness, text, stages });
|
|
278
|
+
if ("problems" in used) {
|
|
279
|
+
return { refused: [`${path} at ${at} is invalid:`, ...used.problems.map((p) => ` - ${p}`)] };
|
|
280
|
+
}
|
|
281
|
+
return { file: used.file, text };
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
/**
|
|
285
|
+
* Check `text` and register what it builds under `harness`'s name.
|
|
286
|
+
* @param {{ harness: string, text: string, stages: readonly string[] }} opts
|
|
287
|
+
* @returns {{ file: object } | { problems: string[] }}
|
|
288
|
+
*/
|
|
289
|
+
export function useCustomText({ harness, text, stages }) {
|
|
290
|
+
const parsed = parseCustomHarness(text);
|
|
291
|
+
if ("problems" in parsed) return parsed;
|
|
292
|
+
const { file } = parsed;
|
|
293
|
+
registerCustom(harness, {
|
|
294
|
+
adapter: customAdapter(harness, file),
|
|
295
|
+
facts: customFacts(harness, file, stages),
|
|
296
|
+
text: customText(file),
|
|
297
|
+
});
|
|
298
|
+
return { file };
|
|
299
|
+
}
|
package/src/harness/facts.mjs
CHANGED
|
@@ -8,26 +8,46 @@
|
|
|
8
8
|
// older CLI reads a newer tag's file and a newer CLI an older one.
|
|
9
9
|
|
|
10
10
|
import { readFileSync } from "node:fs";
|
|
11
|
+
import { FACTS as antigravityFacts } from "./antigravity.mjs";
|
|
11
12
|
import { FACTS as claudeCodeFacts } from "./claude-code.mjs";
|
|
12
|
-
import {
|
|
13
|
+
import { FACTS as codexFacts } from "./codex.mjs";
|
|
14
|
+
import { FACTS as cursorFacts } from "./cursor.mjs";
|
|
15
|
+
import { loadedCustom } from "./custom/registry.mjs";
|
|
16
|
+
import { FACTS as geminiFacts } from "./gemini.mjs";
|
|
17
|
+
import { FACTS as opencodeFacts } from "./opencode.mjs";
|
|
18
|
+
import {
|
|
19
|
+
LEVEL_CAPS,
|
|
20
|
+
SECURITY_STAGES,
|
|
21
|
+
STAGES,
|
|
22
|
+
SUPPORT_LEVELS,
|
|
23
|
+
SUPPORT_TABLE,
|
|
24
|
+
} from "./support-levels.mjs";
|
|
13
25
|
|
|
14
26
|
export { SECURITY_STAGES, STAGES, SUPPORT_LEVELS };
|
|
15
27
|
|
|
16
28
|
/** Each built-in harness that has an adapter, and its facts. */
|
|
17
|
-
const ADAPTERS = {
|
|
29
|
+
const ADAPTERS = {
|
|
30
|
+
"claude-code": claudeCodeFacts,
|
|
31
|
+
codex: codexFacts,
|
|
32
|
+
gemini: geminiFacts,
|
|
33
|
+
antigravity: antigravityFacts,
|
|
34
|
+
opencode: opencodeFacts,
|
|
35
|
+
cursor: cursorFacts,
|
|
36
|
+
};
|
|
18
37
|
|
|
19
38
|
const COMMENT =
|
|
20
39
|
"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.";
|
|
21
40
|
|
|
22
41
|
/**
|
|
23
|
-
* @typedef {{ level: string | null, run: string | null }} Cell
|
|
42
|
+
* @typedef {{ level: string | null, run: string | null, wired: boolean }} Cell
|
|
24
43
|
* @typedef {{
|
|
25
44
|
* displayName: string,
|
|
26
|
-
* secrets: Array<{ name: string, whereToGet: string }>,
|
|
45
|
+
* secrets: Array<{ name: string, whereToGet: string, provider?: string }>,
|
|
27
46
|
* effortValues: string[],
|
|
28
47
|
* noEffort: boolean,
|
|
29
48
|
* defaultModel: string,
|
|
30
49
|
* supportLevels: Record<string, Cell>,
|
|
50
|
+
* levelCap?: string,
|
|
31
51
|
* }} Harness
|
|
32
52
|
* @typedef {{ $comment: string, stages: string[], harnesses: Record<string, Harness> }} Harnesses
|
|
33
53
|
*/
|
|
@@ -46,6 +66,7 @@ export function buildHarnesses() {
|
|
|
46
66
|
noEffort: facts.effortValues.length === 0,
|
|
47
67
|
defaultModel: facts.defaultModel,
|
|
48
68
|
supportLevels: SUPPORT_TABLE[name],
|
|
69
|
+
...(Object.hasOwn(LEVEL_CAPS, name) ? { levelCap: LEVEL_CAPS[name] } : {}),
|
|
49
70
|
},
|
|
50
71
|
]);
|
|
51
72
|
return structuredClone({
|
|
@@ -63,6 +84,15 @@ export function readHarnesses() {
|
|
|
63
84
|
return JSON.parse(readFileSync(new URL("../../harnesses.json", import.meta.url), "utf8"));
|
|
64
85
|
}
|
|
65
86
|
|
|
87
|
+
/**
|
|
88
|
+
* `harness`'s facts: its entry in `harnesses.json`, or a loaded Custom
|
|
89
|
+
* harness's, from its file, with `custom: true`.
|
|
90
|
+
* @param {string} harness
|
|
91
|
+
* @returns {Harness & { custom?: true }}
|
|
92
|
+
*/
|
|
93
|
+
export const harnessFacts = (harness) =>
|
|
94
|
+
loadedCustom(harness)?.facts ?? readHarnesses().harnesses[harness];
|
|
95
|
+
|
|
66
96
|
/** `a, b or c`. */
|
|
67
97
|
const either = (words) =>
|
|
68
98
|
words.length > 1 ? `${words.slice(0, -1).join(", ")} or ${words.at(-1)}` : words.join("");
|
|
@@ -92,7 +122,8 @@ export function effortFor(harness, { effort = "", inherited = false }) {
|
|
|
92
122
|
* and what the run summary says about it. A security Stage below `tried` runs
|
|
93
123
|
* only as a Proving run; any other Stage runs at `documented` with a warning;
|
|
94
124
|
* a pair with no level is refused.
|
|
95
|
-
* @param {Pick<Harness, "displayName" | "supportLevels">} harness
|
|
125
|
+
* @param {Pick<Harness, "displayName" | "supportLevels"> & { custom?: boolean }} harness
|
|
126
|
+
* `custom` marks a Custom harness, whose levels are its file's attestation.
|
|
96
127
|
* @param {{ stage: string, provingRun?: boolean }} run
|
|
97
128
|
* @returns {{ level?: string, summary?: string, warning?: string, refused?: string }}
|
|
98
129
|
*/
|
|
@@ -107,14 +138,20 @@ export function supportFor(harness, { stage, provingRun = false }) {
|
|
|
107
138
|
const below = level === "documented";
|
|
108
139
|
if (below && SECURITY_STAGES.includes(stage) && !provingRun) {
|
|
109
140
|
return {
|
|
110
|
-
refused: `${pair} is at Support Level documented, below tried, and a security Stage runs there only as a Proving run (--proving-run)
|
|
141
|
+
refused: `${pair} is at Support Level documented, below tried, and a security Stage runs there only as a Proving run (--proving-run)${
|
|
142
|
+
harness.custom
|
|
143
|
+
? ", or once the trusted commit's file attests tried under support_levels, citing your own Proving run"
|
|
144
|
+
: ""
|
|
145
|
+
}.`,
|
|
111
146
|
};
|
|
112
147
|
}
|
|
113
148
|
return {
|
|
114
149
|
level,
|
|
115
150
|
summary: `Support Level: ${level}; Proving run: ${provingRun ? "yes" : "no"}`,
|
|
116
151
|
...(below
|
|
117
|
-
? {
|
|
152
|
+
? {
|
|
153
|
+
warning: `${pair} is at Support Level documented: no run of it has been ${harness.custom ? "attested in its file" : "recorded"}.`,
|
|
154
|
+
}
|
|
118
155
|
: {}),
|
|
119
156
|
};
|
|
120
157
|
}
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
// The Gemini CLI Harness adapter (ADR 0027): one function that takes a Stage
|
|
2
|
+
// request and returns a launch plan, as plain data. The Launcher does
|
|
3
|
+
// everything with the plan; this module starts nothing and imports nothing.
|
|
4
|
+
//
|
|
5
|
+
// The CLI: one pinned version, in `/opt/agent-kit` of the kit's Harness image
|
|
6
|
+
// (ADR 0029, docker/harness-images/), which is pinned by digest, beside the
|
|
7
|
+
// Node it runs on. The updater is off in the system settings the image holds
|
|
8
|
+
// and in the run's own. Nothing is installed at run time.
|
|
9
|
+
//
|
|
10
|
+
// The launch: headless, the brief on stdin, every tool approved (`yolo`),
|
|
11
|
+
// since the Launcher's sandbox reaches the Guards. Gemini CLI approves tools
|
|
12
|
+
// only in a trusted folder, and a trusted folder loads the checkout's
|
|
13
|
+
// `.gemini/` (settings, `.env`, MCP servers, hooks, commands, skills), so the
|
|
14
|
+
// Launcher removes it from the copy, with `.agents/skills` and `.env`. The
|
|
15
|
+
// pins (the web tools excluded, hooks, subagents, usage statistics and the
|
|
16
|
+
// update check off, API-key sign-in) are written twice: as the image's system
|
|
17
|
+
// settings, which Gemini CLI reads only when root owns the file and which
|
|
18
|
+
// outrank a project's, so a checkout cannot disable a hook or turn a web tool
|
|
19
|
+
// back on; and as the run's user settings, under a `GEMINI_CLI_HOME` of the
|
|
20
|
+
// Launcher's own. MCP servers are limited to a name no server has, and no
|
|
21
|
+
// extension is loaded. `GEMINI.md` files are instruction files Gemini CLI
|
|
22
|
+
// loads by itself, which no setting turns off in a trusted folder.
|
|
23
|
+
//
|
|
24
|
+
// The model API's base URL is the model proxy, over plain HTTP: Gemini CLI
|
|
25
|
+
// documents HTTPS for any host but loopback and does not enforce it at the
|
|
26
|
+
// pinned version (ADR 0023). The live suite names that cause if a bump does.
|
|
27
|
+
//
|
|
28
|
+
// The agent holds only the run's caller key as its `GEMINI_API_KEY`. Its turn
|
|
29
|
+
// limit is `model.maxSessionTurns`, and a hit one is said on its error output.
|
|
30
|
+
|
|
31
|
+
/** The Gemini CLI version every sandbox runs, pinned. */
|
|
32
|
+
const VERSION = "0.71.1";
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* The Harness image that holds that version. The `harness-images` workflow
|
|
36
|
+
* builds it in the pull request that changes the pin or its Dockerfile, and
|
|
37
|
+
* fails until this holds the digest it pushed
|
|
38
|
+
* (`node docker/harness-images/image.mjs record gemini`).
|
|
39
|
+
*/
|
|
40
|
+
const IMAGE = "ghcr.io/mnaimfaizy/agent-kit-sandbox-gemini";
|
|
41
|
+
const IMAGE_DIGEST = "sha256:7fb81b5c43de8b620508936a2e77de209aa590c888a5bd0fd4c4a7133e674945"; // inputs-d7c637b35a9dafe844c8fb3316b5589d
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* What a Consumer needs to know about Gemini CLI, which `cli/harnesses.json`
|
|
45
|
+
* publishes per tag (ADR 0030): the kit secret it accepts, with where to get
|
|
46
|
+
* it; no effort values, since the pinned version has no effort setting; and
|
|
47
|
+
* the model a Stage gets when none is named, which is the pinned version's own
|
|
48
|
+
* default (`auto` picks a model for each task).
|
|
49
|
+
*/
|
|
50
|
+
export const FACTS = Object.freeze({
|
|
51
|
+
displayName: "Gemini CLI",
|
|
52
|
+
secrets: Object.freeze([
|
|
53
|
+
{
|
|
54
|
+
name: "gemini_api_key",
|
|
55
|
+
whereToGet:
|
|
56
|
+
"Create an API key in Google AI Studio, in a project with its own budget: https://aistudio.google.com/apikey.",
|
|
57
|
+
},
|
|
58
|
+
]),
|
|
59
|
+
effortValues: Object.freeze([]),
|
|
60
|
+
defaultModel: "auto",
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
/** The tools of Gemini CLI's own that reach outside the sandbox. */
|
|
64
|
+
export const WEB_TOOLS = Object.freeze(["google_web_search", "web_fetch"]);
|
|
65
|
+
|
|
66
|
+
/** An MCP server name nothing declares: only a server so named could start. */
|
|
67
|
+
const NO_MCP_SERVER = "agent-kit-none";
|
|
68
|
+
|
|
69
|
+
/** The credential Gemini CLI accepts, and the placeholder the model proxy swaps. */
|
|
70
|
+
const CREDENTIALS = {
|
|
71
|
+
"api-key": {
|
|
72
|
+
secret: "gemini_api_key",
|
|
73
|
+
env: "GEMINI_API_KEY",
|
|
74
|
+
placeholder: "agent-kit-deep-scan-placeholder",
|
|
75
|
+
},
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
/** The settings every run holds, in the image's system file and the run's own. */
|
|
79
|
+
const PINS = {
|
|
80
|
+
general: { enableAutoUpdate: false, enableAutoUpdateNotification: false },
|
|
81
|
+
privacy: { usageStatisticsEnabled: false },
|
|
82
|
+
security: { auth: { selectedType: "gemini-api-key", enforcedType: "gemini-api-key" } },
|
|
83
|
+
tools: { exclude: [...WEB_TOOLS], shell: { enableInteractiveShell: false } },
|
|
84
|
+
hooksConfig: { enabled: false },
|
|
85
|
+
experimental: { enableAgents: false },
|
|
86
|
+
advanced: { ignoreLocalEnv: true },
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* The launch plan for `request`.
|
|
91
|
+
* @param {object} [request] a Stage request, as the Claude Code adapter
|
|
92
|
+
* describes it. `effort` is ignored: Gemini CLI has no effort setting. The
|
|
93
|
+
* only `credentialKind` is `api-key`.
|
|
94
|
+
* @returns the nine-part launch plan, in the same shape as Claude Code's.
|
|
95
|
+
*/
|
|
96
|
+
export function gemini({
|
|
97
|
+
model,
|
|
98
|
+
credentialKind = "api-key",
|
|
99
|
+
proxyUrl,
|
|
100
|
+
briefPath,
|
|
101
|
+
kitDir,
|
|
102
|
+
maxTurns,
|
|
103
|
+
callerKey,
|
|
104
|
+
} = {}) {
|
|
105
|
+
if (!Object.hasOwn(CREDENTIALS, credentialKind)) {
|
|
106
|
+
throw new Error(`Gemini CLI has no credential kind ${JSON.stringify(credentialKind)}`);
|
|
107
|
+
}
|
|
108
|
+
const accepted = structuredClone(CREDENTIALS);
|
|
109
|
+
const credential = accepted[credentialKind];
|
|
110
|
+
if (callerKey !== undefined) credential.placeholder = callerKey;
|
|
111
|
+
const home = kitDir ?? "/agent-kit";
|
|
112
|
+
const settings = {
|
|
113
|
+
...PINS,
|
|
114
|
+
...(maxTurns !== undefined ? { model: { maxSessionTurns: maxTurns } } : {}),
|
|
115
|
+
};
|
|
116
|
+
return {
|
|
117
|
+
identity: { name: "gemini", displayName: "Gemini CLI", version: VERSION, major: 0 },
|
|
118
|
+
installLayer: {
|
|
119
|
+
image: `${IMAGE}@${IMAGE_DIGEST}`,
|
|
120
|
+
env: [],
|
|
121
|
+
run: [
|
|
122
|
+
"ln -sf /opt/agent-kit/bin/gemini /usr/local/bin/gemini \\",
|
|
123
|
+
" && mkdir -p /etc/gemini-cli \\",
|
|
124
|
+
` && printf '%s\\n' '${JSON.stringify(PINS)}' > /etc/gemini-cli/settings.json`,
|
|
125
|
+
],
|
|
126
|
+
},
|
|
127
|
+
modelRoute: { profile: "gemini-api" },
|
|
128
|
+
credentials: { accepted, scrub: ["GEMINI_API_KEY", "GOOGLE_API_KEY"] },
|
|
129
|
+
launch: {
|
|
130
|
+
argv: [
|
|
131
|
+
"gemini",
|
|
132
|
+
"--approval-mode",
|
|
133
|
+
"yolo",
|
|
134
|
+
// Its answer goes to stdout, the transcript, and a hit turn limit to
|
|
135
|
+
// its error output.
|
|
136
|
+
"--output-format",
|
|
137
|
+
"text",
|
|
138
|
+
"--extensions",
|
|
139
|
+
"none",
|
|
140
|
+
"--allowed-mcp-server-names",
|
|
141
|
+
NO_MCP_SERVER,
|
|
142
|
+
// The brief's folder and the report's are outside the workspace.
|
|
143
|
+
...(kitDir !== undefined ? ["--include-directories", kitDir] : []),
|
|
144
|
+
...(model !== undefined ? ["--model", model] : []),
|
|
145
|
+
],
|
|
146
|
+
stdin: briefPath !== undefined ? { file: briefPath } : null,
|
|
147
|
+
files: [{ path: `${home}/.gemini/settings.json`, text: JSON.stringify(settings, null, 2) }],
|
|
148
|
+
env: [
|
|
149
|
+
`${credential.env}=${credential.placeholder}`,
|
|
150
|
+
`GEMINI_CLI_HOME=${home}`,
|
|
151
|
+
"GEMINI_CLI_TRUST_WORKSPACE=true",
|
|
152
|
+
// No second process of its own, which a restart for memory would start.
|
|
153
|
+
"GEMINI_CLI_NO_RELAUNCH=true",
|
|
154
|
+
...(proxyUrl !== undefined ? [`GOOGLE_GEMINI_BASE_URL=${proxyUrl}`] : []),
|
|
155
|
+
],
|
|
156
|
+
// The Launcher removes `checkoutConfig` from the copy before the launch.
|
|
157
|
+
removeCheckoutConfig: true,
|
|
158
|
+
},
|
|
159
|
+
checkoutConfig: [".gemini", ".agents/skills", ".env"],
|
|
160
|
+
instructionFiles: ["GEMINI.md"],
|
|
161
|
+
stops: { turnCap: { stderrPattern: "Reached max session turns" } },
|
|
162
|
+
transcript: { path: `${home}/logs/agent.log` },
|
|
163
|
+
};
|
|
164
|
+
}
|
|
@@ -3,7 +3,11 @@
|
|
|
3
3
|
// harness on another image, by copying `/opt/agent-kit` from it. Both Deep
|
|
4
4
|
// scan drivers build that with Docker: the Docker driver as its runtime's
|
|
5
5
|
// image, the Docker Sandboxes driver as the template it loads into sbx
|
|
6
|
-
// (#375). Nothing is installed from a registry at run time
|
|
6
|
+
// (#375). Nothing is installed from a registry at run time, except a Custom
|
|
7
|
+
// harness (ADR 0029), which has no Harness image: its npm package is installed
|
|
8
|
+
// at its exact version, by the Docker driver as the image is built, and on
|
|
9
|
+
// Docker Sandboxes inside the empty sandbox, where the host's Docker neither
|
|
10
|
+
// installs nor runs it.
|
|
7
11
|
|
|
8
12
|
/** An image reference that ends in a sha256 digest, with nothing else on the line. */
|
|
9
13
|
const BY_DIGEST = /^[^\s@]+@sha256:[0-9a-f]{64}$/;
|
|
@@ -21,6 +25,82 @@ export const MUSL_MARKER = MARKER.join("-");
|
|
|
21
25
|
*/
|
|
22
26
|
const MUSL_CHECK = `RUN if ! getconf GNU_LIBC_VERSION >/dev/null 2>&1 && ls /lib/ld-musl-* >/dev/null 2>&1; then printf '%s-%s\\n' ${MARKER.join(" ")} >&2; exit 1; fi`;
|
|
23
27
|
|
|
28
|
+
/**
|
|
29
|
+
* The base a Custom harness is installed on where no image is named, pinned by
|
|
30
|
+
* digest: Node and npm. The packages add the tools a Stage and its sandbox
|
|
31
|
+
* need, as the kit's Harness images hold them.
|
|
32
|
+
*/
|
|
33
|
+
export const CUSTOM_BASE =
|
|
34
|
+
"node:24-trixie-slim@sha256:4d00acb4bcc42c454c4eb801526f7ad7f772ea3bd4fd168c5cc2e384abcbb9d4";
|
|
35
|
+
const CUSTOM_BASE_PACKAGES = "bash ca-certificates curl git python3 python3-pip python3-venv";
|
|
36
|
+
|
|
37
|
+
/** Where a Custom harness's npm package goes, off the project's own path. */
|
|
38
|
+
const CUSTOM_PREFIX = "/opt/agent-kit/custom";
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* The base a Custom harness gets on Docker Sandboxes where no image is named,
|
|
42
|
+
* pinned by digest: the full Node image, which already holds what a template
|
|
43
|
+
* needs (curl, git, CA certificates, bash and the shadow tools), so the build
|
|
44
|
+
* on the host installs nothing.
|
|
45
|
+
*/
|
|
46
|
+
export const CUSTOM_SANDBOX_BASE =
|
|
47
|
+
"node:24-trixie@sha256:2d5b3bbabeb66d5e7085875cd770003ce5f8cb1fec00843ed6f48546a22cdc85";
|
|
48
|
+
|
|
49
|
+
/** The npm registry, the one host the install inside a sandbox needs. */
|
|
50
|
+
export const NPM_REGISTRY = "registry.npmjs.org";
|
|
51
|
+
|
|
52
|
+
/** Puts the installed package's commands first on the sandbox's path. */
|
|
53
|
+
const CUSTOM_PATH = `ENV PATH="${CUSTOM_PREFIX}/bin:\${PATH}"`;
|
|
54
|
+
|
|
55
|
+
/** The npm command that installs a Custom harness's package. */
|
|
56
|
+
const npmInstall = (npm, options = "") =>
|
|
57
|
+
`npm install --global --prefix ${CUSTOM_PREFIX} --no-audit --no-fund ${options}'${npm}'`;
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* The Docker Sandboxes template layer for a Custom harness on `base`: its path
|
|
61
|
+
* alone. Nothing of the file's goes into a build on the host.
|
|
62
|
+
* @param {string} base
|
|
63
|
+
*/
|
|
64
|
+
export function sandboxNpmLayer(base) {
|
|
65
|
+
return [`FROM ${base}`, CUSTOM_PATH, ""].join("\n");
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* The script that installs a Custom harness's package inside a sandbox, from
|
|
70
|
+
* the npm registry alone.
|
|
71
|
+
* @param {{ npm: string }} installLayer
|
|
72
|
+
*/
|
|
73
|
+
export function sandboxNpmInstall({ npm }) {
|
|
74
|
+
return [
|
|
75
|
+
"command -v npm >/dev/null 2>&1 || { echo 'agent-kit: a Custom harness is installed with npm, which this image lacks: name an image with Node and npm, or none.' >&2; exit 1; }",
|
|
76
|
+
npmInstall(npm, `--registry=https://${NPM_REGISTRY}/ `),
|
|
77
|
+
].join("\n");
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** The build step that names what a recipe's image lacks for the install. */
|
|
81
|
+
const NPM_CHECK =
|
|
82
|
+
"RUN command -v npm >/dev/null 2>&1 || { echo 'agent-kit: a Custom harness is installed with npm, which this image lacks: name an image with Node and npm, or none.' >&2; exit 1; }";
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* The Dockerfile for a Custom harness (ADR 0029: it has no Harness image): its
|
|
86
|
+
* npm package at the exact version, on `base`, or on the kit's own base.
|
|
87
|
+
*/
|
|
88
|
+
function npmDockerfile(base, { npm }) {
|
|
89
|
+
return [
|
|
90
|
+
`FROM ${base ?? CUSTOM_BASE}`,
|
|
91
|
+
...(base === undefined
|
|
92
|
+
? [
|
|
93
|
+
`RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install --yes --no-install-recommends ${CUSTOM_BASE_PACKAGES} && rm -rf /var/lib/apt/lists/*`,
|
|
94
|
+
"ENV PIP_BREAK_SYSTEM_PACKAGES=1",
|
|
95
|
+
]
|
|
96
|
+
: [NPM_CHECK]),
|
|
97
|
+
`RUN ${npmInstall(npm)}`,
|
|
98
|
+
CUSTOM_PATH,
|
|
99
|
+
"WORKDIR /workspace",
|
|
100
|
+
"",
|
|
101
|
+
].join("\n");
|
|
102
|
+
}
|
|
103
|
+
|
|
24
104
|
/**
|
|
25
105
|
* The plan's Harness image. Throws unless it is named by digest: a tag alone
|
|
26
106
|
* can come to mean another image.
|
|
@@ -41,10 +121,13 @@ export function pinnedHarnessImage({ image }) {
|
|
|
41
121
|
* glibc Linux: the musl check, then `/opt/agent-kit` from the Harness image,
|
|
42
122
|
* its `bin` (the harness's CLI alone, never its Node) first on the path, so a
|
|
43
123
|
* CLI of the same name in the image never runs in the pinned one's place.
|
|
44
|
-
*
|
|
45
|
-
*
|
|
124
|
+
* A Custom harness's layer installs its npm package instead, and needs no
|
|
125
|
+
* `base`.
|
|
126
|
+
* @param {string | undefined} base
|
|
127
|
+
* @param {import("./claude-code.mjs").LaunchPlan["installLayer"] | { npm: string }} installLayer
|
|
46
128
|
*/
|
|
47
129
|
export function layerDockerfile(base, installLayer) {
|
|
130
|
+
if ("npm" in installLayer) return npmDockerfile(base, installLayer);
|
|
48
131
|
const { env, run } = installLayer;
|
|
49
132
|
return [
|
|
50
133
|
`FROM ${base}`,
|