@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,289 @@
|
|
|
1
|
+
// What the live suite knows about opencode (ADR 0031): one entry that runs it
|
|
2
|
+
// through each model proxy profile, the control that loads the checkout's
|
|
3
|
+
// config on purpose, and its four named assertions (ADR 0027), with what it
|
|
4
|
+
// does in the sandbox to judge two of them:
|
|
5
|
+
//
|
|
6
|
+
// - a decoy shared server, started before the agent step with a model of its
|
|
7
|
+
// own, which `--standalone` must leave alone; and, as its control, the same
|
|
8
|
+
// run without `--standalone`, which must attach to it;
|
|
9
|
+
// - a denied-egress log: opencode run again with its HTTP proxy variables
|
|
10
|
+
// pointed at a listener in the sandbox that logs every request and refuses
|
|
11
|
+
// it, so an update check, or model traffic past the model proxy, is written
|
|
12
|
+
// down. The sandbox has no route out, and an attempt that dies on its name
|
|
13
|
+
// would otherwise leave no trace.
|
|
14
|
+
//
|
|
15
|
+
// The stub model's canary names a model no catalogue knows, so it reaches the
|
|
16
|
+
// stub only if opencode read the Launcher's config.
|
|
17
|
+
|
|
18
|
+
import { randomBytes } from "node:crypto";
|
|
19
|
+
import { opencode, PROVIDERS } from "../harness/opencode.mjs";
|
|
20
|
+
import { anthropicDialect } from "../model-proxy/stub-dialects/anthropic.mjs";
|
|
21
|
+
import { geminiApiDialect } from "../model-proxy/stub-dialects/gemini-api.mjs";
|
|
22
|
+
import { openaiDialect } from "../model-proxy/stub-dialects/openai.mjs";
|
|
23
|
+
import { canary, plantedConfig } from "./host.mjs";
|
|
24
|
+
|
|
25
|
+
/** A made-up model id, which no canary search looks for. */
|
|
26
|
+
const madeUp = (prefix) => `${prefix}-${randomBytes(8).toString("hex")}`;
|
|
27
|
+
|
|
28
|
+
/** The model each run names, and the one the decoy server runs on. */
|
|
29
|
+
const MODEL = madeUp("akmodel");
|
|
30
|
+
const DECOY = madeUp("akdecoy");
|
|
31
|
+
|
|
32
|
+
/** Where the decoy server and the egress listener keep their files in the sandbox. */
|
|
33
|
+
const DECOY_DIR = "/agent-kit/decoy";
|
|
34
|
+
const EGRESS_DIR = "/agent-kit/egress";
|
|
35
|
+
const EGRESS_PORT = 18090;
|
|
36
|
+
|
|
37
|
+
/** The name the egress listener's own control asks for. */
|
|
38
|
+
const EGRESS_CONTROL = "egress-control.invalid";
|
|
39
|
+
|
|
40
|
+
/** Where opencode looks for a release, or fetches one from. */
|
|
41
|
+
const UPDATE_HOSTS = /\b(opencode\.ai|registry\.npmjs\.org|github\.com|formulae\.brew\.sh)\b/i;
|
|
42
|
+
|
|
43
|
+
/** The model APIs' own hosts, which only the model proxy may reach. */
|
|
44
|
+
const MODEL_HOSTS =
|
|
45
|
+
/\b(api\.anthropic\.com|api\.openai\.com|generativelanguage\.googleapis\.com|chatgpt\.com)\b/i;
|
|
46
|
+
|
|
47
|
+
const DONE = "Say that you are done.";
|
|
48
|
+
|
|
49
|
+
/** The longest one of these runs of opencode may take. */
|
|
50
|
+
const RUN_MS = 120_000;
|
|
51
|
+
|
|
52
|
+
/** A word quoted for `sh`. */
|
|
53
|
+
const quote = (s) => `'${String(s).replace(/'/g, `'\\''`)}'`;
|
|
54
|
+
|
|
55
|
+
/** Whether a request that reached the stub asks for the model `id`. */
|
|
56
|
+
export function namesModel({ path, body }, id) {
|
|
57
|
+
if (path.includes(`/models/${id}:`)) return true;
|
|
58
|
+
try {
|
|
59
|
+
return JSON.parse(body).model === id;
|
|
60
|
+
} catch {
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** The decoy server's config: the run's own, on the decoy's model. */
|
|
66
|
+
function decoyConfig(plan) {
|
|
67
|
+
const config = JSON.parse(plan.launch.files[0].text);
|
|
68
|
+
const [provider] = config.model.split("/");
|
|
69
|
+
config.model = `${provider}/${DECOY}`;
|
|
70
|
+
config.providers[provider].models = { [DECOY]: {} };
|
|
71
|
+
return JSON.stringify(config);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** The listener: it logs each connection's first line, and refuses it. */
|
|
75
|
+
const LISTENER = [
|
|
76
|
+
'const fs = require("node:fs");',
|
|
77
|
+
'require("node:net").createServer((socket) => {',
|
|
78
|
+
' socket.on("error", () => {});',
|
|
79
|
+
' socket.once("data", (data) => {',
|
|
80
|
+
` fs.appendFileSync("${EGRESS_DIR}/log", String(data).split("\\r\\n")[0] + "\\n");`,
|
|
81
|
+
' socket.end("HTTP/1.1 403 Forbidden\\r\\nContent-Length: 0\\r\\nConnection: close\\r\\n\\r\\n");',
|
|
82
|
+
" });",
|
|
83
|
+
`}).listen(${EGRESS_PORT}, "127.0.0.1");`,
|
|
84
|
+
].join("\n");
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* @typedef {(argv: string[], opts?: { env?: string[], stdin?: string, detach?: boolean }) =>
|
|
88
|
+
* Promise<{ status: number | null, stdout: string }>} SandboxExec runs a
|
|
89
|
+
* command in the sandbox's workspace, with the launch's environment and
|
|
90
|
+
* `env` over it.
|
|
91
|
+
*/
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Before the agent step: a shared server, as a user's machine would have one
|
|
95
|
+
* running, registered where opencode looks for it.
|
|
96
|
+
* @param {{ exec: SandboxExec, plan: import("../harness/claude-code.mjs").LaunchPlan }} sandbox
|
|
97
|
+
*/
|
|
98
|
+
async function startDecoy({ exec, plan }) {
|
|
99
|
+
const env = [`OPENCODE_CONFIG=${DECOY_DIR}/opencode.json`, `XDG_CONFIG_HOME=${DECOY_DIR}/config`];
|
|
100
|
+
await exec([
|
|
101
|
+
"sh",
|
|
102
|
+
"-c",
|
|
103
|
+
`mkdir -p ${DECOY_DIR} && printf '%s' ${quote(decoyConfig(plan))} > ${DECOY_DIR}/opencode.json`,
|
|
104
|
+
]);
|
|
105
|
+
await exec(["sh", "-c", `exec opencode serve --service > ${DECOY_DIR}/log 2>&1`], {
|
|
106
|
+
env,
|
|
107
|
+
detach: true,
|
|
108
|
+
});
|
|
109
|
+
const registered = await exec([
|
|
110
|
+
"sh",
|
|
111
|
+
"-c",
|
|
112
|
+
'i=0; while [ "$i" -lt 60 ]; do ls "$XDG_STATE_HOME"/opencode/service*.json && exit 0; i=$((i + 1)); sleep 1; done; exit 1',
|
|
113
|
+
]);
|
|
114
|
+
return { registered: registered.status === 0 };
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* After the agent step: the two runs that show what the sandbox's run did not.
|
|
119
|
+
* @param {{
|
|
120
|
+
* exec: SandboxExec,
|
|
121
|
+
* plan: import("../harness/claude-code.mjs").LaunchPlan,
|
|
122
|
+
* url: string,
|
|
123
|
+
* requests: () => ReadonlyArray<{ path: string, body: string }>,
|
|
124
|
+
* state: { registered: boolean },
|
|
125
|
+
* }} sandbox
|
|
126
|
+
*/
|
|
127
|
+
async function afterAgent({ exec, plan, url, requests, state }) {
|
|
128
|
+
const run = (argv, env = []) => exec(argv, { env, stdin: DONE });
|
|
129
|
+
const before = requests().length;
|
|
130
|
+
const asked = (list) => list.some((r) => namesModel(r, DECOY));
|
|
131
|
+
const attachedByStage = asked(requests().slice(0, before));
|
|
132
|
+
await run(plan.launch.argv.filter((arg) => arg !== "--standalone"));
|
|
133
|
+
const decoy = {
|
|
134
|
+
registered: state.registered,
|
|
135
|
+
attachedByStage,
|
|
136
|
+
attachedWithout: asked(requests().slice(before)),
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
await exec([
|
|
140
|
+
"sh",
|
|
141
|
+
"-c",
|
|
142
|
+
`mkdir -p ${EGRESS_DIR} && printf '%s' ${quote(LISTENER)} > ${EGRESS_DIR}/listen.js && : > ${EGRESS_DIR}/log`,
|
|
143
|
+
]);
|
|
144
|
+
await exec(["node", `${EGRESS_DIR}/listen.js`], { detach: true });
|
|
145
|
+
const proxy = `http://127.0.0.1:${EGRESS_PORT}`;
|
|
146
|
+
const direct = `127.0.0.1,localhost,${new URL(url).hostname}`;
|
|
147
|
+
await exec([
|
|
148
|
+
"sh",
|
|
149
|
+
"-c",
|
|
150
|
+
`curl -s --retry 10 --retry-delay 1 --retry-connrefused -o /dev/null -x ${proxy} http://${EGRESS_CONTROL}/ || true`,
|
|
151
|
+
]);
|
|
152
|
+
await run(plan.launch.argv, [
|
|
153
|
+
...["HTTP_PROXY", "HTTPS_PROXY", "http_proxy", "https_proxy"].map((v) => `${v}=${proxy}`),
|
|
154
|
+
`NO_PROXY=${direct}`,
|
|
155
|
+
`no_proxy=${direct}`,
|
|
156
|
+
]);
|
|
157
|
+
const log = await exec(["cat", `${EGRESS_DIR}/log`]);
|
|
158
|
+
const lines = log.stdout.split("\n").filter(Boolean);
|
|
159
|
+
return {
|
|
160
|
+
decoy,
|
|
161
|
+
egress: {
|
|
162
|
+
logging: lines.some((line) => line.includes(EGRESS_CONTROL)),
|
|
163
|
+
lines: lines.filter((line) => !line.includes(EGRESS_CONTROL)),
|
|
164
|
+
},
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* The four named assertions. `stage` says the run was the read-only Stage, the
|
|
170
|
+
* one that runs the decoy server and the egress log.
|
|
171
|
+
* @type {ReadonlyArray<import("./harnesses.mjs").NamedAssertion>}
|
|
172
|
+
*/
|
|
173
|
+
const ASSERTIONS = Object.freeze([
|
|
174
|
+
{
|
|
175
|
+
name: "opencode-standalone-ignores-shared-server",
|
|
176
|
+
check({ stage, decoy }) {
|
|
177
|
+
if (!stage) return null;
|
|
178
|
+
if (!decoy?.registered) {
|
|
179
|
+
return "the decoy shared server did not register, so nothing shows it was left alone: read its log.";
|
|
180
|
+
}
|
|
181
|
+
if (decoy.attachedByStage) {
|
|
182
|
+
return "the agent step asked for the decoy server's model: it attached to the shared server despite --standalone.";
|
|
183
|
+
}
|
|
184
|
+
return decoy.attachedWithout
|
|
185
|
+
? null
|
|
186
|
+
: "the control, the same run without --standalone, did not attach to the decoy server, so leaving it alone shows nothing.";
|
|
187
|
+
},
|
|
188
|
+
},
|
|
189
|
+
{
|
|
190
|
+
name: "opencode-reads-launcher-config",
|
|
191
|
+
check({ requests }) {
|
|
192
|
+
return requests.some((r) => namesModel(r, MODEL))
|
|
193
|
+
? null
|
|
194
|
+
: "no request asked for the canary model, which only the Launcher-written OPENCODE_CONFIG names: opencode did not read it.";
|
|
195
|
+
},
|
|
196
|
+
},
|
|
197
|
+
{
|
|
198
|
+
name: "opencode-no-update-attempt",
|
|
199
|
+
check({ stage, egress }) {
|
|
200
|
+
if (!stage) return null;
|
|
201
|
+
if (!egress?.logging) {
|
|
202
|
+
return "the denied-egress log did not record its control, so its silence shows nothing.";
|
|
203
|
+
}
|
|
204
|
+
const attempt = egress.lines.find((line) => UPDATE_HOSTS.test(line));
|
|
205
|
+
return attempt === undefined
|
|
206
|
+
? null
|
|
207
|
+
: `an update attempt is in the denied-egress log, though OPENCODE_DISABLE_AUTOUPDATE is set: ${attempt}`;
|
|
208
|
+
},
|
|
209
|
+
},
|
|
210
|
+
{
|
|
211
|
+
name: "opencode-transport-http",
|
|
212
|
+
check({ stage, requests, egress, launcherOutput }) {
|
|
213
|
+
if (requests.length === 0) return "no model request reached the model API through the proxy.";
|
|
214
|
+
const other = requests.find((r) => r.method !== "POST");
|
|
215
|
+
if (other !== undefined) {
|
|
216
|
+
return `a ${other.method} request reached the model API: only HTTP POSTs are expected with transport "http".`;
|
|
217
|
+
}
|
|
218
|
+
// A WebSocket opens with a GET, which the proxy refuses and names.
|
|
219
|
+
const socket = /^Model proxy: .*refused \d+ \([^)]*\bGET \/v1\/responses\b/m.exec(
|
|
220
|
+
launcherOutput,
|
|
221
|
+
);
|
|
222
|
+
if (socket) return `the model proxy refused a WebSocket's request: ${socket[0]}`;
|
|
223
|
+
if (!stage) return null;
|
|
224
|
+
if (!egress?.logging) {
|
|
225
|
+
return "the denied-egress log did not record its control, so its silence shows nothing.";
|
|
226
|
+
}
|
|
227
|
+
const past = egress.lines.find((line) => MODEL_HOSTS.test(line));
|
|
228
|
+
return past === undefined ? null : `model traffic went past the proxy: ${past}`;
|
|
229
|
+
},
|
|
230
|
+
},
|
|
231
|
+
]);
|
|
232
|
+
|
|
233
|
+
/** What differs by the provider: the stub's dialect and the credential's header. */
|
|
234
|
+
const BY_PROVIDER = {
|
|
235
|
+
anthropic: {
|
|
236
|
+
dialect: anthropicDialect,
|
|
237
|
+
credential: () => `sk-ant-api03-${canary()}`,
|
|
238
|
+
upstreamAuth: (_kind, credential) => ["x-api-key", credential],
|
|
239
|
+
},
|
|
240
|
+
openai: {
|
|
241
|
+
dialect: openaiDialect,
|
|
242
|
+
credential: () => `sk-proj-${canary()}`,
|
|
243
|
+
upstreamAuth: (_kind, credential) => ["authorization", `Bearer ${credential}`],
|
|
244
|
+
},
|
|
245
|
+
google: {
|
|
246
|
+
dialect: geminiApiDialect,
|
|
247
|
+
credential: () => `AIza-${canary()}`,
|
|
248
|
+
upstreamAuth: (_kind, credential) => ["x-goog-api-key", credential],
|
|
249
|
+
},
|
|
250
|
+
};
|
|
251
|
+
|
|
252
|
+
const removed = opencode().checkoutConfig;
|
|
253
|
+
|
|
254
|
+
/** @type {Readonly<import("./harnesses.mjs").LiveHarness>} */
|
|
255
|
+
export const liveOpencode = Object.freeze({
|
|
256
|
+
adapter: opencode,
|
|
257
|
+
// One run of every scenario for each provider, so each profile is proven.
|
|
258
|
+
profiles: Object.freeze(
|
|
259
|
+
Object.fromEntries(
|
|
260
|
+
Object.keys(PROVIDERS).map((provider) => [
|
|
261
|
+
provider,
|
|
262
|
+
Object.freeze({ ...BY_PROVIDER[provider], model: `${provider}/${MODEL}` }),
|
|
263
|
+
]),
|
|
264
|
+
),
|
|
265
|
+
),
|
|
266
|
+
baseUrlVariable: "AGENT_KIT_MODEL_PROXY_URL",
|
|
267
|
+
removed: Object.freeze([...removed]),
|
|
268
|
+
harmlessVariables: Object.freeze([]),
|
|
269
|
+
configControl: Object.freeze(["opencode-mcp-server", "opencode-dir-mcp-server"]),
|
|
270
|
+
assertions: ASSERTIONS,
|
|
271
|
+
before: startDecoy,
|
|
272
|
+
after: afterAgent,
|
|
273
|
+
// The removed config is put back, and project config turned on again.
|
|
274
|
+
control({ plan }) {
|
|
275
|
+
const planted = Object.entries(plantedConfig()).filter(
|
|
276
|
+
([path]) => path.startsWith("opencode.json") || path.startsWith(".opencode/"),
|
|
277
|
+
);
|
|
278
|
+
const script = [
|
|
279
|
+
"set -eu",
|
|
280
|
+
"mkdir -p /workspace/.opencode",
|
|
281
|
+
...planted.map(
|
|
282
|
+
([path, text]) => `printf '%s' ${quote(text)} > ${quote(`/workspace/${path}`)}`,
|
|
283
|
+
),
|
|
284
|
+
"unset OPENCODE_DISABLE_PROJECT_CONFIG",
|
|
285
|
+
`exec timeout ${RUN_MS / 1000} ${plan.launch.argv.map(quote).join(" ")}`,
|
|
286
|
+
].join("\n");
|
|
287
|
+
return { argv: ["sh", "-c", script], stdin: DONE };
|
|
288
|
+
},
|
|
289
|
+
});
|
|
@@ -27,6 +27,46 @@ const LOG = "/tmp/agent-kit-probes.log";
|
|
|
27
27
|
/** The longest a probe waits on one connection, in seconds. */
|
|
28
28
|
const CONNECT_SECONDS = 5;
|
|
29
29
|
|
|
30
|
+
/**
|
|
31
|
+
* Python that writes a review Stage result holding its input as one note, cut so
|
|
32
|
+
* the file stays under the result's size cap.
|
|
33
|
+
*/
|
|
34
|
+
const REVIEW_RESULT = [
|
|
35
|
+
"import json, sys",
|
|
36
|
+
'note = sys.stdin.buffer.read().decode("utf-8", "replace")[:100000] or "no output"',
|
|
37
|
+
'print(json.dumps({"entries": [], "fixed": {}, "checked": {"correctness": [note]}, "replies": []}, ensure_ascii=False))',
|
|
38
|
+
].join("\n");
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* The probes' output as a plan Stage result: the heading, then the output, with
|
|
42
|
+
* nothing in it the result may not hold and no more than fits its size cap.
|
|
43
|
+
*/
|
|
44
|
+
const PLAN_RESULT = [
|
|
45
|
+
"import re, sys",
|
|
46
|
+
'log = sys.stdin.buffer.read().decode("utf-8", "replace")',
|
|
47
|
+
'log = re.sub(r"[\\x00-\\x08\\x0b-\\x1f\\x7f]", "?", log)[:60000] or "no output"',
|
|
48
|
+
'sys.stdout.buffer.write(("## Agent plan\\n\\n" + log + "\\n").encode("utf-8"))',
|
|
49
|
+
].join("\n");
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Python that writes an implement Stage result holding its input as the body,
|
|
53
|
+
* cut until the file is under the result's size cap.
|
|
54
|
+
*/
|
|
55
|
+
const IMPLEMENT_RESULT = [
|
|
56
|
+
"import json, sys",
|
|
57
|
+
'note = sys.stdin.buffer.read().decode("utf-8", "replace")[:60000] or "no output"',
|
|
58
|
+
'text = lambda: json.dumps({"title": "probe", "body": note}, ensure_ascii=False)',
|
|
59
|
+
"while len(text().encode()) > 60000: note = note[: len(note) * 3 // 4]",
|
|
60
|
+
"print(text())",
|
|
61
|
+
].join("\n");
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Python that writes a Review response Stage result: no findings, which the
|
|
65
|
+
* schema holds as a round with nothing to answer. The probes' output stays in
|
|
66
|
+
* the stub model's tool results.
|
|
67
|
+
*/
|
|
68
|
+
const RESPONSE_RESULT = `print('{"findings": []}')`;
|
|
69
|
+
|
|
30
70
|
/** A word quoted for `sh`. */
|
|
31
71
|
const quote = (s) => `'${String(s).replace(/'/g, `'\\''`)}'`;
|
|
32
72
|
|
|
@@ -91,14 +131,19 @@ function key() {
|
|
|
91
131
|
];
|
|
92
132
|
}
|
|
93
133
|
|
|
94
|
-
function config() {
|
|
134
|
+
function config({ removed = [] }) {
|
|
95
135
|
return [
|
|
96
136
|
`ls ${MARKER_DIR} 2>/dev/null | sed 's/^/PROBE|config|marker|/'`,
|
|
97
137
|
`echo "PROBE|config|planted-env|\${${PLANTED_ENV}:-unset}"`,
|
|
138
|
+
// What the Launcher removes from the copy must not be there.
|
|
139
|
+
...removed.map(
|
|
140
|
+
(path) =>
|
|
141
|
+
`if [ -e ${quote(`/workspace/${path}`)} ]; then echo "PROBE|config|present|${path}"; else echo "PROBE|config|absent|${path}"; fi`,
|
|
142
|
+
),
|
|
98
143
|
];
|
|
99
144
|
}
|
|
100
145
|
|
|
101
|
-
function network({ hostTargets }) {
|
|
146
|
+
function network({ hostTargets, baseUrlVariable = "ANTHROPIC_BASE_URL" }) {
|
|
102
147
|
const attempt = (name, ...args) => `attempt ${name} ${args.map(quote).join(" ")}`;
|
|
103
148
|
return [
|
|
104
149
|
// curl's exit code, the HTTP status, the seconds to connect (0 when it never
|
|
@@ -122,9 +167,11 @@ function network({ hostTargets }) {
|
|
|
122
167
|
'if ! command -v getent >/dev/null; then echo "PROBE|network|dns|notool"; elif getent hosts example.com >/dev/null 2>&1; then echo "PROBE|network|dns|resolved"; else echo "PROBE|network|dns|unresolved"; fi',
|
|
123
168
|
// The one route there is, and what it refuses: a path outside the model
|
|
124
169
|
// API, and being used as a proxy to anywhere else.
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
'attempt proxy
|
|
170
|
+
// The proxy's origin: the variable may name the API's base, ending /v1.
|
|
171
|
+
`proxy=\${${baseUrlVariable}%/v1}`,
|
|
172
|
+
'attempt proxy "$proxy/agent-kit-probe"',
|
|
173
|
+
'attempt proxy-forward -x "$proxy" http://example.com/',
|
|
174
|
+
'attempt proxy-connect -x "$proxy" https://example.com/',
|
|
128
175
|
];
|
|
129
176
|
}
|
|
130
177
|
|
|
@@ -137,9 +184,24 @@ const PROBES = Object.freeze({ reads, writes, github, key, config, network });
|
|
|
137
184
|
* hostFiles: string[],
|
|
138
185
|
* hostTargets: Array<{ host: string, port: number }>,
|
|
139
186
|
* resultPath: string,
|
|
187
|
+
* baseUrlVariable?: string,
|
|
188
|
+
* removed?: readonly string[],
|
|
189
|
+
* resultHeading?: string,
|
|
190
|
+
* resultAsReview?: boolean,
|
|
191
|
+
* resultAsPlan?: boolean,
|
|
192
|
+
* resultAsImplement?: boolean,
|
|
193
|
+
* resultAsReviewResponse?: boolean,
|
|
194
|
+
* extra?: Readonly<Record<string, string>>,
|
|
140
195
|
* }} opts `hostFiles` are canary files on the host, outside the sandbox, and
|
|
141
196
|
* `hostTargets` the addresses the host listens on, which the sandbox must
|
|
142
|
-
* not reach.
|
|
197
|
+
* not reach. `baseUrlVariable` names the model proxy in the sandbox, and
|
|
198
|
+
* `removed` are the checkout paths the Launcher removes from the copy.
|
|
199
|
+
* `resultHeading` is written as the result's first line, where the run's
|
|
200
|
+
* result is valid only with it. With `resultAsReview`, the result is a review
|
|
201
|
+
* Stage result whose one note holds the probes' output, with `resultAsPlan`
|
|
202
|
+
* a plan that holds it, and with `resultAsImplement` an implement result
|
|
203
|
+
* whose body does. `extra` adds a scenario's own probes, by name, after the
|
|
204
|
+
* Guards' and before the result is written.
|
|
143
205
|
* @returns {Array<{ guard: string, script: string }>}
|
|
144
206
|
*/
|
|
145
207
|
export function probeScripts(opts) {
|
|
@@ -148,12 +210,30 @@ export function probeScripts(opts) {
|
|
|
148
210
|
// In a subshell, so a probe's `cd` and functions are its own.
|
|
149
211
|
script: ["(", ...lines(opts), `echo "PROBE|${guard}|end"`, `) 2>&1 | tee -a ${LOG}`].join("\n"),
|
|
150
212
|
}));
|
|
213
|
+
for (const [guard, script] of Object.entries(opts.extra ?? {})) {
|
|
214
|
+
probes.push({ guard, script: ["(", script, `) 2>&1 | tee -a ${LOG}`].join("\n") });
|
|
215
|
+
}
|
|
151
216
|
const folder = opts.resultPath.slice(0, opts.resultPath.lastIndexOf("/"));
|
|
217
|
+
// With a heading, the result opens with it, before every probe's output.
|
|
218
|
+
const encoder = opts.resultAsReview
|
|
219
|
+
? REVIEW_RESULT
|
|
220
|
+
: opts.resultAsPlan
|
|
221
|
+
? PLAN_RESULT
|
|
222
|
+
: opts.resultAsImplement
|
|
223
|
+
? IMPLEMENT_RESULT
|
|
224
|
+
: opts.resultAsReviewResponse
|
|
225
|
+
? RESPONSE_RESULT
|
|
226
|
+
: null;
|
|
227
|
+
const written = encoder
|
|
228
|
+
? `python3 -c ${quote(encoder)} < ${LOG} > ${opts.resultPath}`
|
|
229
|
+
: opts.resultHeading
|
|
230
|
+
? `{ echo ${quote(opts.resultHeading)}; cat ${LOG}; } > ${opts.resultPath}`
|
|
231
|
+
: `cp ${LOG} ${opts.resultPath}`;
|
|
152
232
|
return [
|
|
153
233
|
...probes,
|
|
154
234
|
{
|
|
155
235
|
guard: "result",
|
|
156
|
-
script: `mkdir -p ${folder} &&
|
|
236
|
+
script: `mkdir -p ${folder} && ${written} && echo "PROBE|result|end"`,
|
|
157
237
|
},
|
|
158
238
|
];
|
|
159
239
|
}
|
package/src/harness-live/run.mjs
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
// The live suite's entry, as .github/workflows/harness-live.yml runs it:
|
|
2
2
|
//
|
|
3
|
-
// node cli/src/harness-live/run.mjs <launcher canary>
|
|
3
|
+
// node cli/src/harness-live/run.mjs <launcher canary> [leg]
|
|
4
|
+
//
|
|
5
|
+
// `leg` names one harness (`claude-code`, `codex`, ...) or `custom` (the fixture
|
|
6
|
+
// Custom harness) and runs only its scenarios, so the workflow can run the
|
|
7
|
+
// legs in parallel; without it every scenario runs.
|
|
4
8
|
//
|
|
5
9
|
// The argument is a made-up value, `AKCANARY-` and 32 hex digits, which puts a
|
|
6
10
|
// secret of the launcher's on its own command line: no sandbox may see it.
|
|
@@ -17,6 +21,8 @@ import { appendFileSync } from "node:fs";
|
|
|
17
21
|
import { pathToFileURL } from "node:url";
|
|
18
22
|
import { runnerFor } from "../exec.mjs";
|
|
19
23
|
import { selectRuntime } from "../deep-scan/runtime.mjs";
|
|
24
|
+
import { cursorRefusals } from "./cursor.mjs";
|
|
25
|
+
import { fixtureScenarios } from "./custom.mjs";
|
|
20
26
|
import { runScenario, SCENARIOS } from "./suite.mjs";
|
|
21
27
|
|
|
22
28
|
/** A scenario's name as an output holds it: no space or bracket. */
|
|
@@ -46,6 +52,9 @@ export function report(results) {
|
|
|
46
52
|
return `| ${r.name} | ${r.verdict} | ${bad.map((f) => `${f.guard} (${f.status})`).join(", ") || "none"} |`;
|
|
47
53
|
}),
|
|
48
54
|
"",
|
|
55
|
+
...results.flatMap((r) =>
|
|
56
|
+
(r.failedAssertions ?? []).map(({ name }) => `- ${r.name}: the ${name} assertion failed.`),
|
|
57
|
+
),
|
|
49
58
|
].join("\n");
|
|
50
59
|
return {
|
|
51
60
|
exit: results.length > 0 && results.every((r) => r.verdict === "pass") ? 0 : 1,
|
|
@@ -55,9 +64,10 @@ export function report(results) {
|
|
|
55
64
|
}
|
|
56
65
|
|
|
57
66
|
/** One scenario's findings and, when it did not pass, everything to debug it with. */
|
|
58
|
-
function describe(result) {
|
|
67
|
+
export function describe(result) {
|
|
59
68
|
const lines = [
|
|
60
69
|
`::group::${result.name}: ${result.verdict} (exit ${result.exit})`,
|
|
70
|
+
...(result.failedAssertions ?? []).map(({ name, why }) => `${name}: failed\n - ${why}`),
|
|
61
71
|
...result.findings.map(
|
|
62
72
|
(f) => `${f.guard}: ${f.status}${f.reasons.map((r) => `\n - ${r}`).join("")}`,
|
|
63
73
|
),
|
|
@@ -76,11 +86,43 @@ function describe(result) {
|
|
|
76
86
|
/** A launcher canary, as the workflow makes it. */
|
|
77
87
|
const LAUNCHER_CANARY = /^AKCANARY-[0-9a-f]{32}$/;
|
|
78
88
|
|
|
79
|
-
|
|
89
|
+
/** The scenarios of `leg`, or all of them. A harness's own scenarios, or the Custom harness's. */
|
|
90
|
+
export function scenariosOf(scenarios, leg) {
|
|
91
|
+
if (leg === undefined) return scenarios;
|
|
92
|
+
return scenarios.filter((s) =>
|
|
93
|
+
leg === "custom" ? s.harness.startsWith("custom:") : s.harness === leg,
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/** The outputs and summary of `leg`'s results, written where the workflow reads them. */
|
|
98
|
+
function finish(results, leg) {
|
|
99
|
+
if (process.env.GITHUB_OUTPUT) {
|
|
100
|
+
const { outputs } = report(results);
|
|
101
|
+
const named = leg ? outputs.replace(/^(guard_failed|failed)=/gm, `$1_${leg}=`) : outputs;
|
|
102
|
+
appendFileSync(
|
|
103
|
+
process.env.GITHUB_OUTPUT,
|
|
104
|
+
`${named}
|
|
105
|
+
`,
|
|
106
|
+
);
|
|
107
|
+
}
|
|
108
|
+
const { exit, summary } = report(results);
|
|
109
|
+
console.log(summary);
|
|
110
|
+
if (process.env.GITHUB_STEP_SUMMARY) appendFileSync(process.env.GITHUB_STEP_SUMMARY, summary);
|
|
111
|
+
return exit;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
async function suite(launcherCanary, leg) {
|
|
80
115
|
if (!LAUNCHER_CANARY.test(launcherCanary ?? "")) {
|
|
81
116
|
console.error("usage: run.mjs AKCANARY-<32 hex digits>, a value made up for this run.");
|
|
82
117
|
return 2;
|
|
83
118
|
}
|
|
119
|
+
// Cursor CLI cannot be fronted by the stub model: its leg runs the refusals,
|
|
120
|
+
// which start no sandbox (cursor.mjs).
|
|
121
|
+
if (leg === "cursor") {
|
|
122
|
+
const results = await cursorRefusals();
|
|
123
|
+
for (const r of results) console.log(describe(r));
|
|
124
|
+
return finish(results, leg);
|
|
125
|
+
}
|
|
84
126
|
const runner = runnerFor("deep-scan");
|
|
85
127
|
const choice = selectRuntime({ runner, platform: process.platform });
|
|
86
128
|
if ("refused" in choice || choice.runtime.id !== "gvisor") {
|
|
@@ -92,16 +134,63 @@ async function suite(launcherCanary) {
|
|
|
92
134
|
);
|
|
93
135
|
return 1;
|
|
94
136
|
}
|
|
137
|
+
const scenarios = scenariosOf([...SCENARIOS, ...fixtureScenarios()], leg);
|
|
138
|
+
if (scenarios.length === 0) {
|
|
139
|
+
console.error(`No scenario belongs to the leg "${leg}".`);
|
|
140
|
+
return 2;
|
|
141
|
+
}
|
|
142
|
+
const results = await runScenarios(scenarios, {
|
|
143
|
+
runner,
|
|
144
|
+
runtime: choice.runtime,
|
|
145
|
+
launcherCanary,
|
|
146
|
+
out: console.log,
|
|
147
|
+
// The last value written for an output wins.
|
|
148
|
+
after(results) {
|
|
149
|
+
if (process.env.GITHUB_OUTPUT) {
|
|
150
|
+
const { outputs } = report(results);
|
|
151
|
+
// A leg's outputs carry its name, so the matrix's legs do not overwrite each other.
|
|
152
|
+
const named = leg ? outputs.replace(/^(guard_failed|failed)=/gm, `$1_${leg}=`) : outputs;
|
|
153
|
+
appendFileSync(process.env.GITHUB_OUTPUT, `${named}\n`);
|
|
154
|
+
}
|
|
155
|
+
},
|
|
156
|
+
});
|
|
157
|
+
const { exit, summary } = report(results);
|
|
158
|
+
console.log(summary);
|
|
159
|
+
if (process.env.GITHUB_STEP_SUMMARY) {
|
|
160
|
+
appendFileSync(process.env.GITHUB_STEP_SUMMARY, summary);
|
|
161
|
+
}
|
|
162
|
+
return exit;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* Every scenario in turn, printing what each showed. A scenario that throws is
|
|
167
|
+
* an `error` result.
|
|
168
|
+
* @param {ReadonlyArray<Parameters<typeof runScenario>[0]>} scenarios
|
|
169
|
+
* @param {{
|
|
170
|
+
* runner: import("../exec.mjs").Runner,
|
|
171
|
+
* runtime: import("../deep-scan/runtime.mjs").Runtime,
|
|
172
|
+
* launcherCanary: string,
|
|
173
|
+
* out: (s: string) => void,
|
|
174
|
+
* after?: (results: object[]) => void,
|
|
175
|
+
* platform?: string,
|
|
176
|
+
* scenarioRunner?: typeof runScenario,
|
|
177
|
+
* }} opts
|
|
178
|
+
*/
|
|
179
|
+
export async function runScenarios(
|
|
180
|
+
scenarios,
|
|
181
|
+
{ runner, runtime, launcherCanary, out, after, platform, scenarioRunner = runScenario },
|
|
182
|
+
) {
|
|
95
183
|
const results = [];
|
|
96
|
-
for (const scenario of
|
|
97
|
-
|
|
184
|
+
for (const scenario of scenarios) {
|
|
185
|
+
out(`Running ${scenario.name} ...`);
|
|
98
186
|
let result;
|
|
99
187
|
try {
|
|
100
|
-
result = await
|
|
188
|
+
result = await scenarioRunner(scenario, {
|
|
101
189
|
runner,
|
|
102
190
|
launcherCanary,
|
|
103
|
-
runtime
|
|
104
|
-
expectedRuntime:
|
|
191
|
+
runtime,
|
|
192
|
+
expectedRuntime: runtime.dockerRuntime,
|
|
193
|
+
...(platform === undefined ? {} : { platform }),
|
|
105
194
|
});
|
|
106
195
|
} catch (e) {
|
|
107
196
|
result = {
|
|
@@ -114,20 +203,12 @@ async function suite(launcherCanary) {
|
|
|
114
203
|
};
|
|
115
204
|
}
|
|
116
205
|
results.push(result);
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
if (process.env.GITHUB_OUTPUT) {
|
|
120
|
-
appendFileSync(process.env.GITHUB_OUTPUT, `${report(results).outputs}\n`);
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
const { exit, summary } = report(results);
|
|
124
|
-
console.log(summary);
|
|
125
|
-
if (process.env.GITHUB_STEP_SUMMARY) {
|
|
126
|
-
appendFileSync(process.env.GITHUB_STEP_SUMMARY, summary);
|
|
206
|
+
out(describe(result));
|
|
207
|
+
after?.(results);
|
|
127
208
|
}
|
|
128
|
-
return
|
|
209
|
+
return results;
|
|
129
210
|
}
|
|
130
211
|
|
|
131
212
|
if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) {
|
|
132
|
-
process.exitCode = await suite(process.argv[2]);
|
|
213
|
+
process.exitCode = await suite(process.argv[2], process.argv[3]);
|
|
133
214
|
}
|