@mnaimfaizy/agent-kit 1.0.0-beta.13 → 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.
- package/README.md +24 -5
- package/custom-harness.schema.json +243 -0
- package/harnesses.json +286 -0
- package/package.json +4 -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/review-response.mjs +54 -27
- package/src/checks/rulesets.mjs +9 -8
- package/src/checks/secrets-and-variables.mjs +220 -43
- package/src/checks/stages.mjs +705 -0
- package/src/cli.mjs +277 -31
- package/src/deep-scan/agent.mjs +145 -117
- package/src/deep-scan/credential.mjs +88 -42
- package/src/deep-scan/docker-driver.mjs +131 -49
- package/src/deep-scan/harness-text.mjs +99 -0
- package/src/deep-scan/lifecycle.mjs +92 -199
- package/src/deep-scan/limits.mjs +13 -7
- package/src/deep-scan/model-proxy.mjs +47 -602
- package/src/deep-scan/preflight.mjs +81 -1
- package/src/deep-scan/recipe.mjs +7 -7
- package/src/deep-scan/runtime.mjs +54 -6
- package/src/deep-scan/sandbox-run.mjs +232 -0
- package/src/deep-scan/sbx-driver.mjs +242 -50
- package/src/deep-scan/tar.mjs +69 -22
- package/src/deep-scan/verify.mjs +6 -1
- package/src/deep-scan.mjs +98 -14
- package/src/doctor.mjs +113 -4
- package/src/harness/adapters.mjs +30 -0
- package/src/harness/antigravity.mjs +187 -0
- package/src/harness/claude-code.mjs +236 -0
- 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 +157 -0
- package/src/harness/gemini.mjs +164 -0
- package/src/harness/install-layer.mjs +141 -0
- package/src/harness/opencode.mjs +289 -0
- package/src/harness/resolve.mjs +156 -0
- package/src/harness/support-levels.mjs +197 -0
- package/src/harness-live/assess.mjs +291 -0
- 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 +414 -0
- package/src/harness-live/opencode.mjs +289 -0
- package/src/harness-live/probes.mjs +239 -0
- package/src/harness-live/run.mjs +214 -0
- package/src/harness-live/setup.mjs +126 -0
- package/src/harness-live/stage.mjs +161 -0
- package/src/harness-live/suite.mjs +481 -0
- package/src/harness-test.mjs +116 -0
- package/src/init.mjs +339 -23
- package/src/model-proxy/core.mjs +657 -0
- package/src/model-proxy/profiles/anthropic.mjs +241 -0
- 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/anthropic.mjs +110 -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 +182 -0
- 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 +1068 -0
- package/src/deep-scan/claude-code.mjs +0 -25
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
// What the kit knows about each built-in harness (ADRs 0028 and 0030), and the
|
|
2
|
+
// two preflight rules read from it.
|
|
3
|
+
//
|
|
4
|
+
// `cli/harnesses.json` is built here from the adapters and the Support Level
|
|
5
|
+
// table, written by `node scripts/gen_harnesses.mjs` and held equal to them by
|
|
6
|
+
// a contract test. It ships with every kit tag and npm package. Its shape can
|
|
7
|
+
// only grow: a field may be added, and is never renamed or removed, because an
|
|
8
|
+
// older CLI reads a newer tag's file and a newer CLI an older one.
|
|
9
|
+
|
|
10
|
+
import { readFileSync } from "node:fs";
|
|
11
|
+
import { FACTS as antigravityFacts } from "./antigravity.mjs";
|
|
12
|
+
import { FACTS as claudeCodeFacts } from "./claude-code.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";
|
|
25
|
+
|
|
26
|
+
export { SECURITY_STAGES, STAGES, SUPPORT_LEVELS };
|
|
27
|
+
|
|
28
|
+
/** Each built-in harness that has an adapter, and its facts. */
|
|
29
|
+
const ADAPTERS = {
|
|
30
|
+
"claude-code": claudeCodeFacts,
|
|
31
|
+
codex: codexFacts,
|
|
32
|
+
gemini: geminiFacts,
|
|
33
|
+
antigravity: antigravityFacts,
|
|
34
|
+
opencode: opencodeFacts,
|
|
35
|
+
cursor: cursorFacts,
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
const COMMENT =
|
|
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.";
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* @typedef {{ level: string | null, run: string | null, wired: boolean }} Cell
|
|
43
|
+
* @typedef {{
|
|
44
|
+
* displayName: string,
|
|
45
|
+
* secrets: Array<{ name: string, whereToGet: string, provider?: string }>,
|
|
46
|
+
* effortValues: string[],
|
|
47
|
+
* noEffort: boolean,
|
|
48
|
+
* defaultModel: string,
|
|
49
|
+
* supportLevels: Record<string, Cell>,
|
|
50
|
+
* levelCap?: string,
|
|
51
|
+
* }} Harness
|
|
52
|
+
* @typedef {{ $comment: string, stages: string[], harnesses: Record<string, Harness> }} Harnesses
|
|
53
|
+
*/
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* The content of `harnesses.json`, from the adapters and the table.
|
|
57
|
+
* @returns {Harnesses}
|
|
58
|
+
*/
|
|
59
|
+
export function buildHarnesses() {
|
|
60
|
+
const harnesses = Object.entries(ADAPTERS).map(([name, facts]) => [
|
|
61
|
+
name,
|
|
62
|
+
{
|
|
63
|
+
displayName: facts.displayName,
|
|
64
|
+
secrets: facts.secrets,
|
|
65
|
+
effortValues: facts.effortValues,
|
|
66
|
+
noEffort: facts.effortValues.length === 0,
|
|
67
|
+
defaultModel: facts.defaultModel,
|
|
68
|
+
supportLevels: SUPPORT_TABLE[name],
|
|
69
|
+
...(Object.hasOwn(LEVEL_CAPS, name) ? { levelCap: LEVEL_CAPS[name] } : {}),
|
|
70
|
+
},
|
|
71
|
+
]);
|
|
72
|
+
return structuredClone({
|
|
73
|
+
$comment: COMMENT,
|
|
74
|
+
stages: STAGES,
|
|
75
|
+
harnesses: Object.fromEntries(harnesses),
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* The shipped `harnesses.json`: what preflight goes by.
|
|
81
|
+
* @returns {Harnesses}
|
|
82
|
+
*/
|
|
83
|
+
export function readHarnesses() {
|
|
84
|
+
return JSON.parse(readFileSync(new URL("../../harnesses.json", import.meta.url), "utf8"));
|
|
85
|
+
}
|
|
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
|
+
|
|
96
|
+
/** `a, b or c`. */
|
|
97
|
+
const either = (words) =>
|
|
98
|
+
words.length > 1 ? `${words.slice(0, -1).join(", ")} or ${words.at(-1)}` : words.join("");
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* The effort a Stage runs with on `harness` (ADR 0027). Its own setting must
|
|
102
|
+
* be one the harness accepts; one `inherited` from `AGENT_KIT_EFFORT` that is
|
|
103
|
+
* not is dropped, so one global does not break a mixed setup. The refused
|
|
104
|
+
* value is never repeated.
|
|
105
|
+
* @param {Pick<Harness, "displayName" | "effortValues" | "noEffort">} harness
|
|
106
|
+
* @param {{ effort?: string, inherited?: boolean }} setting
|
|
107
|
+
* @returns {{ effort: string, log?: string } | { refused: string }}
|
|
108
|
+
*/
|
|
109
|
+
export function effortFor(harness, { effort = "", inherited = false }) {
|
|
110
|
+
if (effort === "" || harness.effortValues.includes(effort)) return { effort };
|
|
111
|
+
const why = harness.noEffort
|
|
112
|
+
? `${harness.displayName} has no effort setting`
|
|
113
|
+
: `${harness.displayName} accepts ${either(harness.effortValues)}`;
|
|
114
|
+
if (inherited) {
|
|
115
|
+
return { effort: "", log: `Effort: AGENT_KIT_EFFORT is dropped for this Stage: ${why}.` };
|
|
116
|
+
}
|
|
117
|
+
return { refused: `${why}, and this Stage's effort is none of that.` };
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Whether `stage` may run on `harness` at its pair's Support Level (ADR 0028),
|
|
122
|
+
* and what the run summary says about it. A security Stage below `tried` runs
|
|
123
|
+
* only as a Proving run; any other Stage runs at `documented` with a warning;
|
|
124
|
+
* a pair with no level is refused.
|
|
125
|
+
* @param {Pick<Harness, "displayName" | "supportLevels"> & { custom?: boolean }} harness
|
|
126
|
+
* `custom` marks a Custom harness, whose levels are its file's attestation.
|
|
127
|
+
* @param {{ stage: string, provingRun?: boolean }} run
|
|
128
|
+
* @returns {{ level?: string, summary?: string, warning?: string, refused?: string }}
|
|
129
|
+
*/
|
|
130
|
+
export function supportFor(harness, { stage, provingRun = false }) {
|
|
131
|
+
const pair = `${harness.displayName} on the ${stage} Stage`;
|
|
132
|
+
const level = harness.supportLevels[stage]?.level ?? null;
|
|
133
|
+
if (level === null || !SUPPORT_LEVELS.includes(level)) {
|
|
134
|
+
return {
|
|
135
|
+
refused: `${pair} has no Support Level: a Guard probe failed on it, so the pair is refused.`,
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
const below = level === "documented";
|
|
139
|
+
if (below && SECURITY_STAGES.includes(stage) && !provingRun) {
|
|
140
|
+
return {
|
|
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
|
+
}.`,
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
return {
|
|
149
|
+
level,
|
|
150
|
+
summary: `Support Level: ${level}; Proving run: ${provingRun ? "yes" : "no"}`,
|
|
151
|
+
...(below
|
|
152
|
+
? {
|
|
153
|
+
warning: `${pair} is at Support Level documented: no run of it has been ${harness.custom ? "attested in its file" : "recorded"}.`,
|
|
154
|
+
}
|
|
155
|
+
: {}),
|
|
156
|
+
};
|
|
157
|
+
}
|