@mnaimfaizy/agent-kit 1.0.0-beta.16 → 1.0.0-beta.17
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 +2 -1
- package/package.json +1 -1
- package/src/cli.mjs +23 -6
- package/src/deep-scan/docker-driver.mjs +70 -3
- package/src/deep-scan/lifecycle.mjs +2 -2
- package/src/deep-scan/sbx-driver.mjs +34 -47
- package/src/exec.mjs +5 -1
- package/src/factory/budget/budget.mjs +2 -1
- package/src/factory/doctor/files.mjs +21 -1
- package/src/factory/doctor/local.mjs +24 -8
- package/src/factory/doctor/orchestrate.mjs +14 -14
- package/src/factory/init/blueprint.mjs +9 -2
- package/src/factory/init/index.mjs +4 -3
- package/src/factory/limits/limits.mjs +8 -0
- package/src/factory/qa/command.mjs +139 -1
- package/src/factory/qa/decide.mjs +86 -0
- package/src/factory/qa/report.mjs +50 -0
- package/src/factory/review/brief.mjs +195 -0
- package/src/factory/run/command.mjs +90 -24
- package/src/factory/run/launch.mjs +25 -6
- package/src/factory/run/pipelines.mjs +467 -34
- package/src/factory/run/token.mjs +5 -3
- package/src/factory/run/worktree.mjs +160 -0
- package/src/factory/security/audit.mjs +353 -0
- package/src/factory/setup/command.mjs +80 -17
- package/src/factory/setup/reads.mjs +30 -0
- package/src/factory/setup/writes.mjs +12 -0
- package/src/factory/sweep/actions-main.mjs +5 -3
- package/src/factory/sweep/shell.mjs +7 -3
- package/src/factory/sweep/sweep-core.mjs +240 -12
- package/src/factory/tracker/github.mjs +57 -18
- package/src/stage/build.mjs +100 -0
- package/src/stage/factory-live.mjs +288 -0
- package/src/stage.mjs +81 -4
|
@@ -43,6 +43,7 @@ import { moveBack, releaseOwnClaims, removeSandboxes } from "./restart.mjs";
|
|
|
43
43
|
import { readSecrets, readSinks } from "./secrets.mjs";
|
|
44
44
|
import { createTeardown } from "./teardown.mjs";
|
|
45
45
|
import { checkToken } from "./token.mjs";
|
|
46
|
+
import { createCheckouts } from "./worktree.mjs";
|
|
46
47
|
|
|
47
48
|
export const DEFAULT_POLL_MS = 60_000;
|
|
48
49
|
export const MIN_POLL_MS = 30_000;
|
|
@@ -50,7 +51,8 @@ export const DEFAULT_DRAIN_MS = 10 * 60_000;
|
|
|
50
51
|
export const PREVIEW = "preview";
|
|
51
52
|
export const TEARDOWN_FETCH_MS = 20_000;
|
|
52
53
|
|
|
53
|
-
const STAGE_SETTING =
|
|
54
|
+
const STAGE_SETTING =
|
|
55
|
+
/^AGENT_KIT_(?:(?:PLAN|REVIEW|QA|SECURITY(?:_AUDIT)?|BUILD)_)?(?:HARNESS|MODEL|EFFORT)$/;
|
|
54
56
|
const SLUG = /^[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+$/;
|
|
55
57
|
|
|
56
58
|
/** `90s`, `10m`, `2h` or a bare number of seconds, in milliseconds; null when it is not one. */
|
|
@@ -186,7 +188,7 @@ async function runEngine(
|
|
|
186
188
|
ctl,
|
|
187
189
|
) {
|
|
188
190
|
out(
|
|
189
|
-
`Orchestrate engine (${PREVIEW}): not yet proven on a second Consumer
|
|
191
|
+
`Orchestrate engine (${PREVIEW}): not yet proven on a second Consumer (docs/factory/engine.md).`,
|
|
190
192
|
);
|
|
191
193
|
if (!Number.isFinite(pollMs) || pollMs < MIN_POLL_MS) {
|
|
192
194
|
err(`factory run: the poll interval is at least ${MIN_POLL_MS / 1000} seconds`);
|
|
@@ -311,28 +313,92 @@ async function runEngine(
|
|
|
311
313
|
const engine = createLocalEngine({
|
|
312
314
|
identity,
|
|
313
315
|
pipelines: stagePipelines,
|
|
314
|
-
context: () =>
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
316
|
+
context: () => {
|
|
317
|
+
// One Stage run, one fetched commit: the first trusted read fetches the default branch's
|
|
318
|
+
// remote head, the rest reuse it. A fetch that fails throws before the Launcher is called.
|
|
319
|
+
let trustedCommit;
|
|
320
|
+
const trustedRoot = () => {
|
|
321
|
+
if (trustedCommit) return trustedCommit;
|
|
322
|
+
const branch = tracker.defaultBranch();
|
|
323
|
+
if (!branch) throw new Error("the repository's default branch could not be resolved");
|
|
324
|
+
// The repository is the tracker's, by URL, never the checkout's `origin` (a fork, or none).
|
|
325
|
+
// The token rides in the child's environment (`GIT_CONFIG_*`), never in the repository's
|
|
326
|
+
// config. The fetch adds objects and moves no ref but FETCH_HEAD (`--refmap=` turns off the
|
|
327
|
+
// remote-tracking update), and never touches the checkout, the index or the working tree.
|
|
328
|
+
const fetched = runner(
|
|
329
|
+
"git",
|
|
330
|
+
[
|
|
331
|
+
"fetch",
|
|
332
|
+
"--no-tags",
|
|
333
|
+
"--quiet",
|
|
334
|
+
"--refmap=",
|
|
335
|
+
`https://github.com/${slug}.git`,
|
|
336
|
+
`refs/heads/${branch}`,
|
|
337
|
+
],
|
|
338
|
+
{ cwd, env: gitPushEnv(secrets.token) },
|
|
339
|
+
);
|
|
340
|
+
if (fetched.status !== 0) {
|
|
341
|
+
throw new Error(
|
|
342
|
+
`could not fetch the default branch ${branch}: ${String(fetched.stderr || "git fetch failed").trim()}`,
|
|
343
|
+
);
|
|
344
|
+
}
|
|
345
|
+
const sha = runner("git", ["rev-parse", "--verify", "FETCH_HEAD^{commit}"], { cwd });
|
|
346
|
+
const commit = String(sha.stdout ?? "").trim();
|
|
347
|
+
if (sha.status !== 0 || !commit) {
|
|
348
|
+
throw new Error(`could not resolve the fetched default branch ${branch}`);
|
|
349
|
+
}
|
|
350
|
+
trustedCommit = { branch, commit };
|
|
351
|
+
return trustedCommit;
|
|
352
|
+
};
|
|
353
|
+
return {
|
|
354
|
+
repo: slug,
|
|
355
|
+
identity,
|
|
356
|
+
gh,
|
|
357
|
+
tracker,
|
|
358
|
+
env: stageEnv,
|
|
359
|
+
launch: realLaunch,
|
|
360
|
+
git: (args, opts = {}) =>
|
|
361
|
+
runner("git", args, { cwd, ...(opts.push ? { env: gitPushEnv(secrets.token) } : {}) }),
|
|
362
|
+
// A detached worktree at one commit, for a Stage that judges a pull request's code.
|
|
363
|
+
checkout: createCheckouts({
|
|
364
|
+
runner,
|
|
365
|
+
cwd,
|
|
366
|
+
tmpDir: stateDir,
|
|
367
|
+
fetchUrl: `https://github.com/${slug}.git`,
|
|
368
|
+
fetchEnv: gitPushEnv(secrets.token),
|
|
369
|
+
fs,
|
|
370
|
+
}),
|
|
371
|
+
tmpDir: stateDir,
|
|
372
|
+
now: clock,
|
|
373
|
+
sleep,
|
|
374
|
+
runDir: (name) => join(runsDir, String(name).replace(/[^A-Za-z0-9._-]/g, "_")),
|
|
375
|
+
trustedCommit: () => trustedRoot().commit,
|
|
376
|
+
readTrusted: (path) => {
|
|
377
|
+
const { branch, commit } = trustedRoot();
|
|
378
|
+
const shown = runner("git", ["show", `${commit}:${path}`], { cwd });
|
|
379
|
+
if (shown.status !== 0) {
|
|
380
|
+
throw new Error(
|
|
381
|
+
`${path} is not on the default branch (${branch}): run init --factory --engine orchestrate and merge it`,
|
|
382
|
+
);
|
|
383
|
+
}
|
|
384
|
+
return shown.stdout;
|
|
385
|
+
},
|
|
386
|
+
writeFile: (path, text, { mode = 0o600 } = {}) => {
|
|
387
|
+
fs.rmSync?.(path, { force: true });
|
|
388
|
+
fs.writeFileSync(path, text, { mode });
|
|
389
|
+
},
|
|
390
|
+
// A Kit script from the default branch, run as a child of this process with the engine's
|
|
391
|
+
// token in the child's environment only (never an argument, a file or a log): the review's
|
|
392
|
+
// publish (`review-threads.mjs`), which shares its code with the Workflow engine's.
|
|
393
|
+
runScript: (file, args, extraEnv = {}) =>
|
|
394
|
+
runner(process.execPath, [file, ...args], {
|
|
395
|
+
cwd,
|
|
396
|
+
env: { GH_TOKEN: secrets.token, GH_PROMPT_DISABLED: "1", ...extraEnv },
|
|
397
|
+
}),
|
|
398
|
+
runId: () => clock(),
|
|
399
|
+
log,
|
|
400
|
+
};
|
|
401
|
+
},
|
|
336
402
|
merge: ({ issue, pull, head, method }) => {
|
|
337
403
|
const args = [
|
|
338
404
|
"--repo",
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
// where the Launcher listens for an interrupt, so it stops its step and destroys its
|
|
5
5
|
// sandbox as it does for a Ctrl-C.
|
|
6
6
|
|
|
7
|
+
import { selectRuntime } from "../../deep-scan/runtime.mjs";
|
|
7
8
|
import { runStage } from "../../stage.mjs";
|
|
8
9
|
|
|
9
10
|
/** An object with `on` and `off` that fires its SIGINT/SIGTERM listeners when `signal` aborts. */
|
|
@@ -23,15 +24,32 @@ export function signalsOf(signal) {
|
|
|
23
24
|
};
|
|
24
25
|
}
|
|
25
26
|
|
|
27
|
+
/**
|
|
28
|
+
* True when the runtime this host would pick runs the harness as a user that is not root: sbx
|
|
29
|
+
* (a template whose user is `agent`) and the Docker drivers (gVisor, Kata, Firecracker), which
|
|
30
|
+
* run the build Stage's steps as uid 1000 (`runtime.agentUser`, set in stage.mjs for the factory-mode
|
|
31
|
+
* Stage alone). False when no runtime is accepted.
|
|
32
|
+
*/
|
|
33
|
+
function canRunNonRootHarness({ runner, platform }) {
|
|
34
|
+
try {
|
|
35
|
+
const choice = selectRuntime({ runner, platform });
|
|
36
|
+
return "runtime" in choice;
|
|
37
|
+
} catch {
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
26
42
|
/**
|
|
27
43
|
* @param {{ runner: Function, env: Record<string, string>, cwd: string, platform?: string, log: (line: string) => void }} deps
|
|
28
44
|
* @returns {(opts: object) => Promise<number>} runs one Stage; resolves to the Launcher's exit code
|
|
29
45
|
*/
|
|
30
46
|
export function createLauncher({ runner, env, cwd, platform = process.platform, log }) {
|
|
31
|
-
|
|
47
|
+
// `opts.cwd` is the checkout for this one call (a detached worktree at the pull request's head);
|
|
48
|
+
// without it the Launcher runs on the host's checkout.
|
|
49
|
+
const launch = ({ signal, cwd: checkout, ...opts }) =>
|
|
32
50
|
runStage({
|
|
33
51
|
...opts,
|
|
34
|
-
cwd,
|
|
52
|
+
cwd: checkout ?? cwd,
|
|
35
53
|
runner,
|
|
36
54
|
env,
|
|
37
55
|
platform,
|
|
@@ -39,9 +57,10 @@ export function createLauncher({ runner, env, cwd, platform = process.platform,
|
|
|
39
57
|
out: (line) => log(`launcher: ${line}`),
|
|
40
58
|
err: (line) => log(`launcher: ${line}`),
|
|
41
59
|
});
|
|
42
|
-
//
|
|
43
|
-
// read-only, an Outbox
|
|
44
|
-
//
|
|
45
|
-
|
|
60
|
+
// `agent-kit stage build` runs a factory-mode Chief of Staff (stage/build.mjs: a Snapshot
|
|
61
|
+
// copied in read-only, an Outbox copied out live) and refuses a harness that runs as root.
|
|
62
|
+
// Both drivers run the build Stage's harness as a user that is not root, so the engine offers
|
|
63
|
+
// build on either.
|
|
64
|
+
launch.factory = canRunNonRootHarness({ runner, platform });
|
|
46
65
|
return launch;
|
|
47
66
|
}
|