@mnaimfaizy/agent-kit 1.0.0-beta.14 → 1.0.0-beta.15

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.
Files changed (76) hide show
  1. package/README.md +22 -4
  2. package/custom-harness.schema.json +243 -0
  3. package/harnesses.json +244 -6
  4. package/package.json +3 -2
  5. package/src/checks/ci-workflow.mjs +105 -0
  6. package/src/checks/claude-app.mjs +11 -2
  7. package/src/checks/custom-harness.mjs +157 -0
  8. package/src/checks/github-app.mjs +214 -0
  9. package/src/checks/rulesets.mjs +9 -8
  10. package/src/checks/secrets-and-variables.mjs +27 -8
  11. package/src/checks/stages.mjs +705 -0
  12. package/src/cli.mjs +270 -33
  13. package/src/deep-scan/agent.mjs +88 -21
  14. package/src/deep-scan/credential.mjs +81 -32
  15. package/src/deep-scan/docker-driver.mjs +105 -42
  16. package/src/deep-scan/harness-text.mjs +99 -0
  17. package/src/deep-scan/lifecycle.mjs +68 -178
  18. package/src/deep-scan/limits.mjs +13 -7
  19. package/src/deep-scan/model-proxy.mjs +21 -10
  20. package/src/deep-scan/preflight.mjs +19 -6
  21. package/src/deep-scan/recipe.mjs +4 -0
  22. package/src/deep-scan/runtime.mjs +54 -6
  23. package/src/deep-scan/sandbox-run.mjs +232 -0
  24. package/src/deep-scan/sbx-driver.mjs +224 -39
  25. package/src/deep-scan/tar.mjs +69 -22
  26. package/src/deep-scan/verify.mjs +6 -1
  27. package/src/deep-scan.mjs +73 -13
  28. package/src/doctor.mjs +113 -4
  29. package/src/harness/adapters.mjs +30 -0
  30. package/src/harness/antigravity.mjs +187 -0
  31. package/src/harness/claude-code.mjs +8 -1
  32. package/src/harness/codex.mjs +219 -0
  33. package/src/harness/cursor.mjs +199 -0
  34. package/src/harness/custom/registry.mjs +21 -0
  35. package/src/harness/custom/schema.mjs +90 -0
  36. package/src/harness/custom.mjs +299 -0
  37. package/src/harness/facts.mjs +44 -7
  38. package/src/harness/gemini.mjs +164 -0
  39. package/src/harness/install-layer.mjs +86 -3
  40. package/src/harness/opencode.mjs +289 -0
  41. package/src/harness/resolve.mjs +156 -0
  42. package/src/harness/support-levels.mjs +151 -3
  43. package/src/harness-live/assess.mjs +29 -6
  44. package/src/harness-live/cursor-real.mjs +146 -0
  45. package/src/harness-live/cursor-version.mjs +70 -0
  46. package/src/harness-live/cursor.mjs +80 -0
  47. package/src/harness-live/custom.mjs +91 -0
  48. package/src/harness-live/fixture-harness.mjs +45 -0
  49. package/src/harness-live/harnesses.mjs +263 -0
  50. package/src/harness-live/host.mjs +113 -4
  51. package/src/harness-live/opencode.mjs +289 -0
  52. package/src/harness-live/probes.mjs +87 -7
  53. package/src/harness-live/run.mjs +101 -20
  54. package/src/harness-live/setup.mjs +126 -0
  55. package/src/harness-live/stage.mjs +25 -15
  56. package/src/harness-live/suite.mjs +276 -95
  57. package/src/harness-test.mjs +116 -0
  58. package/src/init.mjs +313 -13
  59. package/src/model-proxy/core.mjs +128 -20
  60. package/src/model-proxy/profiles/anthropic.mjs +54 -10
  61. package/src/model-proxy/profiles/gemini-api.mjs +311 -0
  62. package/src/model-proxy/profiles/openai.mjs +327 -0
  63. package/src/model-proxy/stub-dialects/gemini-api.mjs +178 -0
  64. package/src/model-proxy/stub-dialects/openai.mjs +173 -0
  65. package/src/model-proxy/stub.mjs +9 -1
  66. package/src/stage/audit.mjs +79 -0
  67. package/src/stage/egress-route.mjs +207 -0
  68. package/src/stage/implement/carry.mjs +308 -0
  69. package/src/stage/implement/sandbox.mjs +271 -0
  70. package/src/stage/implement/verify.mjs +70 -0
  71. package/src/stage/implement.mjs +218 -0
  72. package/src/stage/plan.mjs +115 -0
  73. package/src/stage/review-response.mjs +172 -0
  74. package/src/stage/review.mjs +185 -0
  75. package/src/stage/workspace.mjs +274 -0
  76. package/src/stage.mjs +1068 -0
@@ -0,0 +1,90 @@
1
+ // The JSON Schema keywords the Custom harness schema uses, and no others: the
2
+ // CLI has no dependencies. `doctor` validates against the pinned tag's schema,
3
+ // so a keyword this version does not know throws and never passes unseen.
4
+ // `errorMessage` replaces what a failing subschema says.
5
+
6
+ const KNOWN = new Set([
7
+ "$schema",
8
+ "title",
9
+ "description",
10
+ "errorMessage",
11
+ "type",
12
+ "enum",
13
+ "pattern",
14
+ "maxLength",
15
+ "minItems",
16
+ "items",
17
+ "properties",
18
+ "required",
19
+ "additionalProperties",
20
+ "propertyNames",
21
+ "anyOf",
22
+ "not",
23
+ ]);
24
+
25
+ const typeOf = (value) => (value === null ? "null" : Array.isArray(value) ? "array" : typeof value);
26
+
27
+ const at = (path, key) => (path === "" ? key : `${path}.${key}`);
28
+
29
+ /**
30
+ * Why `value` does not match `schema`, one line per problem, each naming where.
31
+ * @param {object} schema
32
+ * @param {unknown} value
33
+ * @param {string} [path]
34
+ * @returns {string[]}
35
+ */
36
+ export function problems(schema, value, path = "") {
37
+ const unknown = Object.keys(schema).find((keyword) => !KNOWN.has(keyword));
38
+ if (unknown !== undefined) {
39
+ throw new Error(`the Custom harness schema uses ${unknown}, which this version cannot check`);
40
+ }
41
+ const where = path === "" ? "the file" : path;
42
+ const own = (said) => [`${where}: ${schema.errorMessage ?? said}`];
43
+ if (schema.not !== undefined && problems(schema.not, value, path).length === 0) {
44
+ return own("is not allowed");
45
+ }
46
+ if (schema.type !== undefined && typeOf(value) !== schema.type) {
47
+ return own(`must be of type ${schema.type}`);
48
+ }
49
+ if (schema.enum !== undefined && !schema.enum.includes(value)) {
50
+ return own(`must be one of ${schema.enum.join(", ")}`);
51
+ }
52
+ if (schema.anyOf !== undefined && !schema.anyOf.some((s) => !problems(s, value, path).length)) {
53
+ return own("matches none of the forms it may take");
54
+ }
55
+ const found = [];
56
+ if (typeof value === "string") {
57
+ if (schema.maxLength !== undefined && value.length > schema.maxLength) {
58
+ return own(`is longer than ${schema.maxLength} characters`);
59
+ }
60
+ if (schema.pattern !== undefined && !new RegExp(schema.pattern, "u").test(value)) {
61
+ return own(`must match ${schema.pattern}`);
62
+ }
63
+ }
64
+ if (Array.isArray(value)) {
65
+ if (schema.minItems !== undefined && value.length < schema.minItems) {
66
+ return own(`needs at least ${schema.minItems} item(s)`);
67
+ }
68
+ if (schema.items !== undefined) {
69
+ value.forEach((item, i) => found.push(...problems(schema.items, item, `${path}[${i}]`)));
70
+ }
71
+ }
72
+ if (typeOf(value) === "object") {
73
+ for (const name of schema.required ?? []) {
74
+ if (!Object.hasOwn(value, name)) found.push(`${where}: the ${name} key is missing`);
75
+ }
76
+ for (const [key, item] of Object.entries(value)) {
77
+ if (schema.propertyNames !== undefined) {
78
+ found.push(...problems(schema.propertyNames, key, at(path, key)));
79
+ }
80
+ if (Object.hasOwn(schema.properties ?? {}, key)) {
81
+ found.push(...problems(schema.properties[key], item, at(path, key)));
82
+ } else if (schema.additionalProperties === false) {
83
+ found.push(`${where}: unknown key ${JSON.stringify(key)}`);
84
+ } else if (schema.additionalProperties !== undefined) {
85
+ found.push(...problems(schema.additionalProperties, item, at(path, key)));
86
+ }
87
+ }
88
+ }
89
+ return found;
90
+ }
@@ -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
+ }
@@ -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 { SECURITY_STAGES, STAGES, SUPPORT_LEVELS, SUPPORT_TABLE } from "./support-levels.mjs";
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 = { "claude-code": claudeCodeFacts };
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
- ? { warning: `${pair} is at Support Level documented: no run of it has been recorded.` }
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
+ }