@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
package/README.md
CHANGED
|
@@ -36,11 +36,12 @@ npx @mnaimfaizy/agent-kit harness test custom:<name>
|
|
|
36
36
|
- `stage audit` is the Launcher's path for the static security audit, which the [security audit workflow](../docs/security-audit.md#the-audit-through-the-launcher) calls for `codex`. It takes the brief and writes the report to `--result`, the raw transcript to `--transcript` and the error output to `--error-log`, each a new file. The harness is `--harness`'s, else `AGENT_KIT_SECURITY_AUDIT_HARNESS`, else `AGENT_KIT_HARNESS`, else `claude-code`, and it takes `deep-scan`'s `--credential`, `--credential-from`, `--model`, `--effort`, limit flags and `--proving-run`; a pair below `tried` is refused without that flag. It copies the checked-out commit into the same sandbox on an accepted runtime, without the harness's own config, with its instruction files from `--trusted-ref` (default the checked-out commit), and with untracked files only under `--untracked`. It exits 0 only when the harness exited cleanly and left an audit report, 3 when a limit stopped it. It refuses a GitHub token in its environment and writes nothing to GitHub.
|
|
37
37
|
- `stage plan` is the Launcher's path for the plan, which the [plan workflow](../docs/plan-implement-review.md#the-plan-through-the-launcher) calls for [every harness but `claude-code`](../docs/harnesses.md#which-harness-runs-each-stage) (on `cursor` the key sits in the sandbox, in the weaker form: [Cursor CLI](../docs/harnesses.md#cursor-cli)). It takes `stage audit`'s flags except `--untracked`, which it refuses, with the harness else from `AGENT_KIT_PLAN_HARNESS`, and runs a pair at `documented` with a warning. It exits 0 only when the harness exited cleanly and left a plan, a Markdown file that opens with `## Agent plan`, at most 256 KiB; 3 when a limit stopped it. It writes nothing to GitHub: the workflow's trusted step posts the plan.
|
|
38
38
|
- `stage review` is the Launcher's path for the review, which the [review workflow](../docs/plan-implement-review.md#the-review-through-the-launcher) calls for [every harness but `claude-code`](../docs/harnesses.md#which-harness-runs-each-stage) (on `cursor` the key sits in the sandbox, in the weaker form: [Cursor CLI](../docs/harnesses.md#cursor-cli)). It takes `stage audit`'s flags except `--untracked`, which it refuses, with the harness else from `AGENT_KIT_REVIEW_HARNESS`, runs a pair at `documented` with a warning, and takes `--input <file>`, repeatable, to copy a prepared file such as the diff in beside the brief. It exits 0 only when the harness exited cleanly and left a JSON result of the review's shape, at most 256 KiB; 3 when a limit stopped it. It writes nothing to GitHub: the workflow's trusted step posts the result.
|
|
39
|
+
- `stage build` is not a shell command: the Orchestrate engine runs it in process (the Chief of Staff in factory mode, with its Snapshot and Outbox folders), and it has no flags for them ([the build Stage](../docs/factory/orchestrate.md)).
|
|
39
40
|
- `stage implement` is the Launcher's path for the implementer, which the [implement workflow](../docs/plan-implement-review.md#the-implementer-through-the-launcher) calls for [every harness but `claude-code`](../docs/harnesses.md#which-harness-runs-each-stage) (on `cursor` the key sits in the sandbox, in the weaker form: [Cursor CLI](../docs/harnesses.md#cursor-cli)). It takes `stage review`'s flags, with the harness else from `AGENT_KIT_IMPLEMENT_HARNESS`, and `--bundle <file>`. `--sandbox-image <ref>` names the image the harness is layered on, glibc Linux with git and bash (default: the kit's Harness image; a tag is accepted and its digest printed); `--setup-commands <file>` runs in a setup container of its own, reaching the `--setup-registries <hosts>` alone (none: no network); the agent then runs, with the network cut, in a fresh container from the same image that takes only the workspace, `.git/` and the checkout from the trusted commit, and the absolute paths `--setup-paths <paths>` names, one per line (default: none; the harness's files, shell and git config, `/etc`, `/tmp` and the image's program and library folders are refused; ADR 0047). With `--verify-commands <file>` it is the verify run instead: no agent, brief or credential; it runs the setup the same way, and those commands with no network in the fresh container, on the checked-out commit, exiting 0 when they pass ([the sandbox image and setup](../docs/plan-implement-review.md#the-sandbox-image-and-setup)). The sandbox's copy is a git repository holding the checked-out commit alone, and the agent commits there. It exits 0 only when the harness exited cleanly and left both a JSON `title` and `body`, at most 64 KiB, and a git bundle of at least one commit; a run a limit stopped (exit 3) writes neither. It pushes nothing and writes nothing to GitHub: the workflow's trusted jobs validate the bundle, push it and open the draft pull request.
|
|
40
41
|
- `stage review-response` is the Launcher's path for the Review responder, which the [Review response workflow](../docs/review-response.md#the-responder-through-the-launcher) calls for [every harness but `claude-code`](../docs/harnesses.md#which-harness-runs-each-stage). It takes `stage implement`'s flags (the sandbox, setup and `--bundle`, not `--input` or `--verify-commands`), with the harness else from `AGENT_KIT_REVIEW_RESPONSE_HARNESS`. The agent commits in the same one-commit repository, and the result is a JSON object whose one key, `findings`, holds a reply and Verdict for each thread: at most 150 KB and 20 entries, each with a `thread_id`, a `verdict` (`fixed`, `addressed` or `declined`), a `reply`, and a full `commit` sha for `fixed` alone. A round with no commit is a whole round: it writes the result and no bundle. The workflow's trusted jobs check every thread against a Work list publish rebuilds from GitHub (a reviewer thread resolved since is dropped with a note; any other unknown thread fails the run), validate the bundle, push it and post the replies; nothing here does.
|
|
41
42
|
- `harness test custom:<name>` runs the live probe suite on a [Custom harness](../docs/harnesses.md#custom-harness) file, `.agent-kit/harnesses/<name>.json`, as the default branch (or `--trusted-ref`) holds it, against a stub model under gVisor, with no model credential. It is the first half of a Proving run. `deep-scan` and `stage` take the same `custom:<name>`, reading the file from the same trusted commit, and `doctor` checks it.
|
|
42
43
|
- `deep-scan --verify <file> --ref <ref>` is a [Verification run](../docs/security-audit.md#verification-run): it re-attempts the Reproduction of the findings in `<file>` (each a `###` section with `- **Concept id:**`, `- **Location:**` and `- **Observation:**`, as a deep report gives them) on `<ref>`, a local branch, tag or commit such as your fix branch, exported as committed, never the working tree. The recipe, the skill and the Threat pack still come from the default branch. It is confirm-only (no `full` walk, no exploration, no new findings): the agent gets the Verification-run procedure, not the full deep procedure, and the finding file goes in with its brief after the network cut. Its defaults are scan 15 min, 50 turns and the same token cap. Each flag needs the other, and `--report` is not taken with them (usage errors, exit 2). A finding file that is missing, unreadable or out of shape, or a ref that is not a local commit, is refused, exit 1, before any runtime starts. The report goes only to a new private folder; `deep-scan` prints each finding's `Reproduced: yes` (the fix does not hold) or `no` (it holds), exits 1 if the report misses one, and files or posts nothing. It is local only: refused, exit 1, in GitHub Actions (`GITHUB_ACTIONS=true`).
|
|
43
44
|
|
|
44
|
-
The package version matches the Agent-kit Release line: `@mnaimfaizy/agent-kit@1.0.0-beta.
|
|
45
|
+
The package version matches the Agent-kit Release line: `@mnaimfaizy/agent-kit@1.0.0-beta.17` is published from tag `v1.0.0-beta.17`, with npm provenance.
|
|
45
46
|
|
|
46
47
|
Full documentation: [Getting started](https://github.com/mnaimfaizy/agent-kit/blob/main/docs/getting-started.md) and [Adopt](https://github.com/mnaimfaizy/agent-kit/blob/main/docs/adopt.md#check-an-adoption-with-doctor).
|
package/package.json
CHANGED
package/src/cli.mjs
CHANGED
|
@@ -12,7 +12,7 @@ import { parseArgs } from "node:util";
|
|
|
12
12
|
import { runDeepScan } from "./deep-scan.mjs";
|
|
13
13
|
import { runFactoryReport } from "./factory/report/command.mjs";
|
|
14
14
|
import { parseDuration, runFactoryRun } from "./factory/run/command.mjs";
|
|
15
|
-
import { runFactorySetup } from "./factory/setup/command.mjs";
|
|
15
|
+
import { patPermissionsSummary, runFactorySetup } from "./factory/setup/command.mjs";
|
|
16
16
|
import { readLock, stateDirOf } from "./factory/engine/lockfile.mjs";
|
|
17
17
|
import { runFactoryStop } from "./factory/stop/command.mjs";
|
|
18
18
|
import { runFactorySweep } from "./factory/sweep/command.mjs";
|
|
@@ -28,6 +28,20 @@ import { runUpgrade } from "./upgrade.mjs";
|
|
|
28
28
|
|
|
29
29
|
export const VERSION = CLI_VERSION;
|
|
30
30
|
|
|
31
|
+
/** Wrap `text` to `width` columns; lines after the first start with `indent` spaces. */
|
|
32
|
+
function wrapHelp(text, indent, width) {
|
|
33
|
+
const lines = [];
|
|
34
|
+
let line = "";
|
|
35
|
+
for (const word of text.split(" ")) {
|
|
36
|
+
if (line && line.length + 1 + word.length > width - 0) {
|
|
37
|
+
lines.push(line);
|
|
38
|
+
line = word;
|
|
39
|
+
} else line = line ? `${line} ${word}` : word;
|
|
40
|
+
}
|
|
41
|
+
lines.push(line);
|
|
42
|
+
return lines.join(`\n${" ".repeat(indent)}`);
|
|
43
|
+
}
|
|
44
|
+
|
|
31
45
|
const USAGE = `Usage: agent-kit <command> [options]
|
|
32
46
|
|
|
33
47
|
Commands:
|
|
@@ -63,7 +77,7 @@ Commands:
|
|
|
63
77
|
given, and writes the Stage result and the raw transcript to
|
|
64
78
|
private files. Writes nothing to GitHub.
|
|
65
79
|
factory factory setup: the GitHub side of adopting the Factory (after
|
|
66
|
-
init --factory): labels, the pinned control issue, the App and
|
|
80
|
+
init --factory): labels, the pinned and locked control issue, the App and
|
|
67
81
|
its key, the ruleset. Asks before each write.
|
|
68
82
|
factory sweep: one sweep of this repository's factory issues,
|
|
69
83
|
the same sweep the factory-dispatcher workflow runs. With the
|
|
@@ -310,11 +324,10 @@ Options for factory setup (needs a terminal and an admin gh login; refuses in CI
|
|
|
310
324
|
asks before each write; safe to run again; never sets the Kill switch):
|
|
311
325
|
--repo <o/r> The repository to set up (default: gh's choice for the
|
|
312
326
|
current directory).
|
|
313
|
-
--engine <e> workflow (default: labels, the pinned control issue, the
|
|
327
|
+
--engine <e> workflow (default: labels, the pinned and locked control issue, the
|
|
314
328
|
GitHub App and its key, the ruleset) or orchestrate (labels,
|
|
315
329
|
control issue and ruleset; no App; prints the PAT's steps:
|
|
316
|
-
one repository,
|
|
317
|
-
write, Variables read).
|
|
330
|
+
one repository, ${wrapHelp(patPermissionsSummary(), 18, 62)}).
|
|
318
331
|
|
|
319
332
|
Options for factory sweep:
|
|
320
333
|
--repo <o/r> The repository to sweep (default: GITHUB_REPOSITORY, else
|
|
@@ -555,7 +568,11 @@ export async function main(argv, io) {
|
|
|
555
568
|
}
|
|
556
569
|
// `stage` takes its Stage's name; no other command takes an argument.
|
|
557
570
|
if (command === "stage") {
|
|
558
|
-
|
|
571
|
+
// `build` runs in process, from the engine (it has no flags for its folders): not a shell Stage.
|
|
572
|
+
const names = Object.entries(STAGE_COMMANDS)
|
|
573
|
+
.filter(([, definition]) => !definition.FACTORY)
|
|
574
|
+
.map(([name]) => name)
|
|
575
|
+
.join(", ");
|
|
559
576
|
if (!rest.length) {
|
|
560
577
|
stderr(`stage needs a Stage name: ${names}`);
|
|
561
578
|
return 2;
|
|
@@ -47,6 +47,40 @@ import {
|
|
|
47
47
|
import { failed, must, StepFailed, ENDS_HERE } from "./steps.mjs";
|
|
48
48
|
import { singleFileOf } from "./tar.mjs";
|
|
49
49
|
|
|
50
|
+
/**
|
|
51
|
+
* The user every step runs as in a sandbox that asks for it (`runtime.agentUser`, set for the
|
|
52
|
+
* factory-mode build Stage alone): uid 1000, gid 1000, home /home/agent, as in a Docker Sandboxes
|
|
53
|
+
* template (sbx-driver.mjs). A user that is not root is what lets that Stage's Snapshot stay
|
|
54
|
+
* read-only to the agent (ADR 0039). Every other Stage runs as the image's user, root.
|
|
55
|
+
*/
|
|
56
|
+
const AGENT_USER = "1000:1000";
|
|
57
|
+
const AGENT_HOME = "/home/agent";
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Run as root once the sandbox is up: give uid 1000 a passwd entry (a harness may ask the
|
|
61
|
+
* system for its own user) and its home, whatever image the sandbox runs. An image that has
|
|
62
|
+
* a uid 1000 account (`node`) keeps it and its home; the others get /home/agent. `docker exec
|
|
63
|
+
* --user` takes HOME from the passwd entry, so no step sets it.
|
|
64
|
+
*/
|
|
65
|
+
const MAKE_AGENT_HOME = [
|
|
66
|
+
"getent passwd 1000 >/dev/null 2>&1 || {",
|
|
67
|
+
" getent group 1000 >/dev/null 2>&1 || groupadd -g 1000 agent >/dev/null 2>&1 || echo 'agent:x:1000:' >> /etc/group;",
|
|
68
|
+
` useradd -u 1000 -g 1000 -M -d ${AGENT_HOME} -s /bin/bash agent >/dev/null 2>&1 || echo 'agent:x:1000:1000::${AGENT_HOME}:/bin/sh' >> /etc/passwd;`,
|
|
69
|
+
"};",
|
|
70
|
+
'home="$(getent passwd 1000 | cut -d: -f6)"; [ -n "$home" ] || home=' +
|
|
71
|
+
AGENT_HOME +
|
|
72
|
+
'; mkdir -p "$home" && chown 1000:1000 "$home"',
|
|
73
|
+
].join(" ");
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* What `copyIn` runs, as root, after it unpacks: the sandbox's own user may write in /workspace
|
|
77
|
+
* and /agent-kit, except the factory-mode Stage's Snapshot (read-only to it) and Outbox (its own
|
|
78
|
+
* mode). /agent-kit itself is never loosened (-mindepth 1): 0777 without the sticky bit would
|
|
79
|
+
* let the agent swap the Snapshot link. As the Docker Sandboxes driver does.
|
|
80
|
+
*/
|
|
81
|
+
const LOOSEN =
|
|
82
|
+
"chmod -R a+rwX /workspace 2>/dev/null; find /agent-kit -mindepth 1 \\( -path /agent-kit/snapshots -o -path /agent-kit/snapshot -o -path /agent-kit/outbox \\) -prune -o ! -type l -exec chmod a+rwX {} + 2>/dev/null; true";
|
|
83
|
+
|
|
50
84
|
/** The label every sandbox resource carries, so a stray one can be found. */
|
|
51
85
|
export const LABEL = "agent-kit.deep-scan";
|
|
52
86
|
|
|
@@ -90,6 +124,8 @@ export function envArgs(env, secret, flag) {
|
|
|
90
124
|
* @returns {import("./lifecycle.mjs").Driver}
|
|
91
125
|
*/
|
|
92
126
|
export function dockerDriver({ runtime, id, call, plan }) {
|
|
127
|
+
/** True when every step runs as uid 1000 unless it names a user: the build Stage's sandbox. */
|
|
128
|
+
const asAgent = runtime.agentUser === true;
|
|
93
129
|
const { displayName } = plan.identity;
|
|
94
130
|
const name = `agent-kit-deep-${id}`;
|
|
95
131
|
const label = `${LABEL}=${id}`;
|
|
@@ -211,13 +247,18 @@ export function dockerDriver({ runtime, id, call, plan }) {
|
|
|
211
247
|
* writes into a running container is hidden from the sandbox once the
|
|
212
248
|
* sandbox has looked up that path (#404).
|
|
213
249
|
*/
|
|
214
|
-
async copyIn(tar, what) {
|
|
250
|
+
async copyIn(tar, what, { loosen = true } = {}) {
|
|
215
251
|
must(
|
|
216
252
|
await docker(["exec", "-i", "--user", "0:0", name, "tar", "-x", "-f", "-", "-C", "/"], {
|
|
217
253
|
stdin: tar,
|
|
218
254
|
}),
|
|
219
255
|
what,
|
|
220
256
|
);
|
|
257
|
+
// A copy made while the agent runs only unpacks: the loosening walks the tree as root, and
|
|
258
|
+
// a link the agent swaps in between `find` and `chmod` would make root chmod its target.
|
|
259
|
+
if (loosen && asAgent) {
|
|
260
|
+
await docker(["exec", "--user", "0:0", "--workdir", "/", name, "sh", "-c", LOOSEN]);
|
|
261
|
+
}
|
|
221
262
|
},
|
|
222
263
|
|
|
223
264
|
/** The harness is already in the image. */
|
|
@@ -265,10 +306,20 @@ export function dockerDriver({ runtime, id, call, plan }) {
|
|
|
265
306
|
|
|
266
307
|
refused: () => proxy?.refused ?? [],
|
|
267
308
|
|
|
268
|
-
exec: (script, { env = [], workdir = "/workspace" } = {}) => {
|
|
309
|
+
exec: (script, { env = [], workdir = "/workspace", user } = {}) => {
|
|
269
310
|
const { args, childEnv } = envArgs(env, plan.launch?.secretEnv ?? [], "--env");
|
|
311
|
+
const runAs = user ?? (asAgent ? AGENT_USER : null);
|
|
270
312
|
return docker(
|
|
271
|
-
[
|
|
313
|
+
[
|
|
314
|
+
"exec",
|
|
315
|
+
...(runAs ? ["--user", runAs] : []),
|
|
316
|
+
...args,
|
|
317
|
+
...(workdir ? ["--workdir", workdir] : []),
|
|
318
|
+
name,
|
|
319
|
+
"sh",
|
|
320
|
+
"-c",
|
|
321
|
+
script,
|
|
322
|
+
],
|
|
272
323
|
{ env: childEnv },
|
|
273
324
|
);
|
|
274
325
|
},
|
|
@@ -426,6 +477,22 @@ export function dockerDriver({ runtime, id, call, plan }) {
|
|
|
426
477
|
]),
|
|
427
478
|
what,
|
|
428
479
|
);
|
|
480
|
+
if (asAgent) {
|
|
481
|
+
must(
|
|
482
|
+
await docker([
|
|
483
|
+
"exec",
|
|
484
|
+
"--user",
|
|
485
|
+
"0:0",
|
|
486
|
+
"--workdir",
|
|
487
|
+
"/",
|
|
488
|
+
name,
|
|
489
|
+
"sh",
|
|
490
|
+
"-c",
|
|
491
|
+
MAKE_AGENT_HOME,
|
|
492
|
+
]),
|
|
493
|
+
"making the agent's home",
|
|
494
|
+
);
|
|
495
|
+
}
|
|
429
496
|
}
|
|
430
497
|
|
|
431
498
|
async function closeProxy() {
|
|
@@ -99,13 +99,13 @@ const SETUP_ORDER = ["setup", "start", "ready", "seed"];
|
|
|
99
99
|
* container: string,
|
|
100
100
|
* prepare: (steps: object, ctx: { archive: Function, out: Function, branch: string, short: string }) => Promise<void>,
|
|
101
101
|
* start: (steps: object) => Promise<{ isolation?: string } | void>,
|
|
102
|
-
* copyIn: (tar: Buffer, what: string) => Promise<void>,
|
|
102
|
+
* copyIn: (tar: Buffer, what: string, opts?: { loosen?: boolean }) => Promise<void>,
|
|
103
103
|
* installAgent: (out: Function) => Promise<void>,
|
|
104
104
|
* carryOut: (script: string, opts: { maxBytes: number }) => Promise<{ data: Buffer } | { error: string }>,
|
|
105
105
|
* renew: () => Promise<void>,
|
|
106
106
|
* openSetupEgress: (registries: string[]) => Promise<{ env: string[], note: string }>,
|
|
107
107
|
* refused: () => string[],
|
|
108
|
-
* exec: (script: string, opts?: { env?: string[], workdir?: string | null }) => Promise<import("../exec.mjs").StartResult>,
|
|
108
|
+
* exec: (script: string, opts?: { env?: string[], workdir?: string | null, user?: string }) => Promise<import("../exec.mjs").StartResult>,
|
|
109
109
|
* cutEgress: () => Promise<void>,
|
|
110
110
|
* egressLeft: () => Promise<string | null>,
|
|
111
111
|
* openModelRoute: (startProxy: (bind: string) => Promise<{ port: number, close: () => Promise<void> }>) => Promise<{ url: string, note: string, isolation?: string }>,
|
|
@@ -31,9 +31,9 @@
|
|
|
31
31
|
// (986-987), removed with `sbx policy rm network --sandbox --resource` for
|
|
32
32
|
// the cut (1148, 1179-1180); `sbx policy ls <sandbox> --json` (812, 822)
|
|
33
33
|
// then shows, from the host, that no network allow is left.
|
|
34
|
-
// - Files move
|
|
35
|
-
//
|
|
36
|
-
// report is copied into a private host folder and checked there.
|
|
34
|
+
// - Files move in over `sbx exec -i` (a tar streamed to `tar -x` as root, no
|
|
35
|
+
// file the sandbox's user can reach), and out with `sbx cp`, whose host side
|
|
36
|
+
// is a path: the report is copied into a private host folder and checked there.
|
|
37
37
|
// - The model route (#370): the key-injecting model proxy listens on the
|
|
38
38
|
// host's 127.0.0.1, which the sandbox calls as host.docker.internal:<its
|
|
39
39
|
// port>, and one per-sandbox rule allows only that, which sbx's policy
|
|
@@ -239,7 +239,6 @@ export function sbxDriver({ id, call, plan }) {
|
|
|
239
239
|
/** The per-sandbox allow rules in place, as their resource lists. */
|
|
240
240
|
const allowed = [];
|
|
241
241
|
let host = null; // a private host folder for the files sbx cp moves
|
|
242
|
-
let copies = 0;
|
|
243
242
|
let modelRoute = null; // the one allow rule the scan may have
|
|
244
243
|
let modelProxy = null;
|
|
245
244
|
|
|
@@ -257,11 +256,12 @@ export function sbxDriver({ id, call, plan }) {
|
|
|
257
256
|
);
|
|
258
257
|
allowed.splice(allowed.indexOf(list), 1);
|
|
259
258
|
};
|
|
260
|
-
const exec = (script, { env = [], workdir = "/workspace", user } = {}) => {
|
|
259
|
+
const exec = (script, { env = [], workdir = "/workspace", user, stdin, maxOutput } = {}) => {
|
|
261
260
|
const { args, childEnv } = envArgs(env, plan.launch?.secretEnv ?? [], "-e");
|
|
262
261
|
return sbx(
|
|
263
262
|
[
|
|
264
263
|
"exec",
|
|
264
|
+
...(stdin === undefined ? [] : ["-i"]),
|
|
265
265
|
...(user ? ["-u", user] : []),
|
|
266
266
|
...args,
|
|
267
267
|
...(workdir ? ["-w", workdir] : []),
|
|
@@ -270,7 +270,11 @@ export function sbxDriver({ id, call, plan }) {
|
|
|
270
270
|
"-c",
|
|
271
271
|
script,
|
|
272
272
|
],
|
|
273
|
-
{
|
|
273
|
+
{
|
|
274
|
+
env: childEnv,
|
|
275
|
+
...(stdin === undefined ? {} : { stdin }),
|
|
276
|
+
...(maxOutput === undefined ? {} : { maxOutput }),
|
|
277
|
+
},
|
|
274
278
|
);
|
|
275
279
|
};
|
|
276
280
|
|
|
@@ -373,24 +377,24 @@ export function sbxDriver({ id, call, plan }) {
|
|
|
373
377
|
await create("creating the sandbox");
|
|
374
378
|
},
|
|
375
379
|
|
|
376
|
-
async copyIn(tar, what) {
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
must(await sbx(["cp", file, `${name}:${inside}`], { cwd: hostDir() }), what);
|
|
384
|
-
} finally {
|
|
385
|
-
rmSync(join(hostDir(), file), { force: true });
|
|
386
|
-
}
|
|
380
|
+
async copyIn(tar, what, { loosen = true } = {}) {
|
|
381
|
+
// `loosen: false` (a copy made while the agent runs) only unpacks: the loosening below
|
|
382
|
+
// walks the tree as root, and a link the agent swaps in between `find` and `chmod` would
|
|
383
|
+
// make root chmod its target.
|
|
384
|
+
// Streamed to `tar -x` as root over `sbx exec -i`, as the docker driver does: no file the
|
|
385
|
+
// sandbox's own user can reach (a predictable /tmp name it could pre-create or link) is
|
|
386
|
+
// ever involved, so a copy made while the agent runs cannot be swapped under root.
|
|
387
387
|
must(
|
|
388
388
|
await exec(
|
|
389
|
-
//
|
|
390
|
-
|
|
391
|
-
|
|
389
|
+
// Then the sandbox's own user may write there, except the factory-mode Stage's Snapshot
|
|
390
|
+
// (read-only to it) and Outbox (its own mode). /agent-kit itself is never loosened
|
|
391
|
+
// (-mindepth 1): 0777 without the sticky bit would let the agent swap the Snapshot link.
|
|
392
|
+
loosen
|
|
393
|
+
? `tar -x -f - -C / && { chmod -R a+rwX /workspace 2>/dev/null; find /agent-kit -mindepth 1 \( -path /agent-kit/snapshots -o -path /agent-kit/snapshot -o -path /agent-kit/outbox \) -prune -o ! -type l -exec chmod a+rwX {} + 2>/dev/null; true; }`
|
|
394
|
+
: "tar -x -f - -C /",
|
|
395
|
+
{ user: "root", workdir: null, stdin: tar },
|
|
392
396
|
),
|
|
393
|
-
|
|
397
|
+
what,
|
|
394
398
|
{ showOutput: true },
|
|
395
399
|
);
|
|
396
400
|
},
|
|
@@ -399,37 +403,20 @@ export function sbxDriver({ id, call, plan }) {
|
|
|
399
403
|
async installAgent() {},
|
|
400
404
|
|
|
401
405
|
/**
|
|
402
|
-
* The archive `script` writes, run as root in the sandbox
|
|
403
|
-
*
|
|
404
|
-
*
|
|
406
|
+
* The archive `script` writes, run as root in the sandbox and streamed out on `sbx exec`'s
|
|
407
|
+
* stdout, as the docker driver does (ADR 0047): no file in the sandbox is involved, so
|
|
408
|
+
* nothing the sandbox's own user can reach (a link, a file it owns, a folder, a FIFO at a
|
|
409
|
+
* fixed /tmp path) is ever written or read by root.
|
|
405
410
|
*/
|
|
406
411
|
async carryOut(script, { maxBytes }) {
|
|
407
|
-
const
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
{ user: "root", workdir: null },
|
|
411
|
-
);
|
|
412
|
-
if (made.status === 5) return { error: `it is larger than ${maxBytes / 1024 ** 3} GiB` };
|
|
413
|
-
if (made.status !== 0) {
|
|
412
|
+
const r = await exec(script, { user: "root", workdir: null, maxOutput: maxBytes });
|
|
413
|
+
if (r.truncated) return { error: `it is larger than ${maxBytes / 1024 ** 3} GiB` };
|
|
414
|
+
if (r.status !== 0) {
|
|
414
415
|
return {
|
|
415
|
-
error: `tar exited ${
|
|
416
|
+
error: `tar exited ${r.status ?? "abnormally"}: ${firstLine(r.stderr) || "no output"}`,
|
|
416
417
|
};
|
|
417
418
|
}
|
|
418
|
-
|
|
419
|
-
try {
|
|
420
|
-
const r = await sbx(["cp", `${name}:${inside}`, "."], { cwd: into });
|
|
421
|
-
if (r.status !== 0)
|
|
422
|
-
return { error: `sbx cp failed: ${firstLine(r.stderr) || `exit ${r.status}`}` };
|
|
423
|
-
const entries = readdirSync(into);
|
|
424
|
-
const file = entries.length === 1 ? join(into, entries[0]) : null;
|
|
425
|
-
if (file === null || !lstatSync(file).isFile()) return { error: "sbx cp gave no one file" };
|
|
426
|
-
if (lstatSync(file).size > maxBytes) {
|
|
427
|
-
return { error: `it is larger than ${maxBytes / 1024 ** 3} GiB` };
|
|
428
|
-
}
|
|
429
|
-
return { data: readFileSync(file) };
|
|
430
|
-
} finally {
|
|
431
|
-
rmSync(into, { recursive: true, force: true });
|
|
432
|
-
}
|
|
419
|
+
return { data: r.stdout };
|
|
433
420
|
},
|
|
434
421
|
|
|
435
422
|
/**
|
package/src/exec.mjs
CHANGED
|
@@ -4,7 +4,8 @@
|
|
|
4
4
|
// `init`, `upgrade` and `doctor` reach only `git` and `gh`; `deep-scan` and
|
|
5
5
|
// `factory-run` add the accepted sandbox runtimes' CLIs and the 1Password CLI, which
|
|
6
6
|
// reads the model credential (ADR 0019), and `factory-run` adds `gh` beside them and the
|
|
7
|
-
// host's keep-awake tools (`caffeinate`, `systemd-inhibit`)
|
|
7
|
+
// host's keep-awake tools (`caffeinate`, `systemd-inhibit`) and the running Node
|
|
8
|
+
// binary (`process.execPath`, for its trusted child scripts). There is no
|
|
8
9
|
// second runner that bypasses this. Every module takes a runner as a
|
|
9
10
|
// parameter; tests inject a fake one, or a fake spawn behind the real
|
|
10
11
|
// allowlist. A runner also has `start`, the same command run without
|
|
@@ -37,6 +38,9 @@ const ALLOWLISTS = Object.freeze({
|
|
|
37
38
|
...RUNTIME_CLIS,
|
|
38
39
|
"caffeinate",
|
|
39
40
|
"systemd-inhibit",
|
|
41
|
+
// The running Node binary, for the engine's trusted child scripts (the review
|
|
42
|
+
// publish). Exactly this path: not `node` from PATH.
|
|
43
|
+
process.execPath,
|
|
40
44
|
]),
|
|
41
45
|
});
|
|
42
46
|
|
|
@@ -8,7 +8,8 @@
|
|
|
8
8
|
// UTC; a total that is missing, unknown or edited counts at
|
|
9
9
|
// the Stage's full cap, and so does a Claim written today that
|
|
10
10
|
// left no release comment
|
|
11
|
-
// reserved = the full cap of every Stage still running
|
|
11
|
+
// reserved = the full cap of every Stage still running, once per Stage; QA counts 0,
|
|
12
|
+
// and so does a Stage the engine does not run
|
|
12
13
|
// a Stage starts only if spent + reserved + its own cap <= the cap
|
|
13
14
|
//
|
|
14
15
|
// A value that cannot be read never loosens the cap: an invalid override, an
|
|
@@ -20,6 +20,7 @@ import { GUARDED_PATHS } from "../gate/guarded.mjs";
|
|
|
20
20
|
import { mergeFromConfig } from "../gate/config.mjs";
|
|
21
21
|
import { CONFIG_PATH, RISK_RULES_PATH } from "../init/blueprint.mjs";
|
|
22
22
|
import { LIMIT_STAGES, stageLimits, TASK_SIZES } from "../limits/limits.mjs";
|
|
23
|
+
import { qaAppPathsFromConfig } from "../qa/decide.mjs";
|
|
23
24
|
import { parseRiskRules, riskTier } from "../plan/risk.mjs";
|
|
24
25
|
|
|
25
26
|
export const FACTORY_FILE_CHECKS = Object.freeze([
|
|
@@ -45,9 +46,18 @@ export const FACTORY_CALLERS = Object.freeze([
|
|
|
45
46
|
const WORKFLOWS_DIR = ".github/workflows";
|
|
46
47
|
const FACTORY_DIR = ".github/factory";
|
|
47
48
|
|
|
48
|
-
const TOP_KEYS = [
|
|
49
|
+
const TOP_KEYS = [
|
|
50
|
+
"max_running",
|
|
51
|
+
"max_attempts",
|
|
52
|
+
"plan_approval",
|
|
53
|
+
"limits",
|
|
54
|
+
"budget",
|
|
55
|
+
"merge",
|
|
56
|
+
"qa",
|
|
57
|
+
];
|
|
49
58
|
const BUDGET_KEYS = ["daily_tokens", "notify"];
|
|
50
59
|
const MERGE_KEYS = ["mode", "auto_tiers", "method"];
|
|
60
|
+
const QA_KEYS = ["app_paths"];
|
|
51
61
|
const isObject = (v) => v !== null && typeof v === "object" && !Array.isArray(v);
|
|
52
62
|
const whole = (v) => Number.isSafeInteger(v) && v >= 1;
|
|
53
63
|
|
|
@@ -136,6 +146,16 @@ export function configProblems(text) {
|
|
|
136
146
|
if (merge.problem) problems.push(`${merge.problem}.`);
|
|
137
147
|
}
|
|
138
148
|
}
|
|
149
|
+
if ("qa" in data) {
|
|
150
|
+
// The QA path rule: a list of non-empty globs (a missing rule holds every QA Report).
|
|
151
|
+
if (isObject(data.qa)) {
|
|
152
|
+
for (const key of Object.keys(data.qa)) {
|
|
153
|
+
if (!QA_KEYS.includes(key)) problems.push(`qa.${key} is not a qa key.`);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
const rule = qaAppPathsFromConfig(text);
|
|
157
|
+
if (rule.problem) problems.push(`${rule.problem}.`);
|
|
158
|
+
}
|
|
139
159
|
return [...new Set(problems)];
|
|
140
160
|
}
|
|
141
161
|
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
// In CI mode `doctor` lists these checks as skipped; a skipped check is never a pass.
|
|
6
6
|
//
|
|
7
7
|
// factory-labels the labels `factory setup` creates exist
|
|
8
|
-
// factory-control the control issue exists and is pinned; a live Engine lease is shown
|
|
8
|
+
// factory-control the control issue exists and is pinned (warns when it is not locked); a live Engine lease is shown
|
|
9
9
|
// factory-app the App is installed on only this repository with exactly Contents and
|
|
10
10
|
// Pull requests write (Workflow engine)
|
|
11
11
|
// factory-environment the `factory-publish` environment and the App key secret
|
|
@@ -78,11 +78,12 @@ export function readPinnedNumbers({ runner, cwd, repo, host }) {
|
|
|
78
78
|
function readControl(github, repo) {
|
|
79
79
|
const issues = github.getLines(
|
|
80
80
|
`repos/${repo}/issues?state=open&per_page=100`,
|
|
81
|
-
'.[] | select(.pull_request == null) | [.number, (.body // "")] | @json',
|
|
81
|
+
'.[] | select(.pull_request == null) | [.number, (.body // ""), .locked] | @json',
|
|
82
82
|
);
|
|
83
83
|
for (const line of issues) {
|
|
84
|
-
const [number, body] = JSON.parse(line);
|
|
85
|
-
|
|
84
|
+
const [number, body, locked] = JSON.parse(line);
|
|
85
|
+
// `locked` is a boolean from GitHub; a read that lacks it is "unknown", never "unlocked".
|
|
86
|
+
if (isControlBody(body)) return { number, locked: typeof locked === "boolean" ? locked : null };
|
|
86
87
|
}
|
|
87
88
|
return null;
|
|
88
89
|
}
|
|
@@ -128,8 +129,8 @@ function checkLabels({ github, repo }) {
|
|
|
128
129
|
}
|
|
129
130
|
|
|
130
131
|
function checkControl({ github, runner, cwd, repo, host, now }) {
|
|
131
|
-
const
|
|
132
|
-
if (
|
|
132
|
+
const control = readControl(github, repo);
|
|
133
|
+
if (control === null) {
|
|
133
134
|
return make(
|
|
134
135
|
"factory-control",
|
|
135
136
|
"fail",
|
|
@@ -140,8 +141,13 @@ function checkControl({ github, runner, cwd, repo, host, now }) {
|
|
|
140
141
|
},
|
|
141
142
|
);
|
|
142
143
|
}
|
|
144
|
+
const { number, locked } = control;
|
|
143
145
|
const pinned = readPinnedNumbers({ runner, cwd, repo, host });
|
|
144
146
|
const details = [];
|
|
147
|
+
// On a public repository anyone can comment on the issue that holds the lease and the trip
|
|
148
|
+
// marker; locked, only people with write access can.
|
|
149
|
+
const lockFix = `gh api --method PUT repos/${repo}/issues/${number}/lock`;
|
|
150
|
+
const lockNote = `The control issue #${number} is not locked: on a public repository anyone can comment on it. Run \`agent-kit factory setup\`, or \`${lockFix}\`.`;
|
|
145
151
|
// `doctor` does not know the Orchestrate engine's identity, so it counts a lease only when its
|
|
146
152
|
// author has write access to the repository, and says who wrote it.
|
|
147
153
|
const comments = readComments(github, repo, number);
|
|
@@ -159,10 +165,20 @@ function checkControl({ github, runner, cwd, repo, host, now }) {
|
|
|
159
165
|
else details.push("No live Engine lease.");
|
|
160
166
|
if (!pinned.includes(number)) {
|
|
161
167
|
return make("factory-control", "fail", `The control issue #${number} is not pinned.`, {
|
|
162
|
-
details: [
|
|
168
|
+
details: [
|
|
169
|
+
...details,
|
|
170
|
+
"Pin it from the issue's sidebar, or run `agent-kit factory setup`.",
|
|
171
|
+
...(locked === false ? [lockNote] : []),
|
|
172
|
+
],
|
|
163
173
|
fix: ["agent-kit factory setup"],
|
|
164
174
|
});
|
|
165
175
|
}
|
|
176
|
+
if (locked === false) {
|
|
177
|
+
return make("factory-control", "warn", `The control issue #${number} is not locked.`, {
|
|
178
|
+
details: [...details, lockNote],
|
|
179
|
+
fix: ["agent-kit factory setup", lockFix],
|
|
180
|
+
});
|
|
181
|
+
}
|
|
166
182
|
return make("factory-control", "pass", `The control issue #${number} is open and pinned.`, {
|
|
167
183
|
details,
|
|
168
184
|
});
|
|
@@ -291,7 +307,7 @@ function checkEnvironment({ github, repo, ownerType, engine }) {
|
|
|
291
307
|
if (!environment.deployment_branch_policy) {
|
|
292
308
|
status = "warn";
|
|
293
309
|
details.push(
|
|
294
|
-
`${ENVIRONMENT} is open to every branch: limit its deployment branches to the default branch.`,
|
|
310
|
+
`${ENVIRONMENT} is open to every branch, and a Factory run may have created ${ENVIRONMENT} (GitHub creates an environment the first time a job names it): limit its deployment branches to the default branch (Settings > Environments > ${ENVIRONMENT} > Deployment branches and tags).`,
|
|
295
311
|
);
|
|
296
312
|
}
|
|
297
313
|
return make("factory-environment", status, `${ENVIRONMENT} exists and ${APP_SECRET} is set.`, {
|
|
@@ -7,16 +7,17 @@
|
|
|
7
7
|
// The token is never printed. Docs: docs/factory/doctor.md.
|
|
8
8
|
//
|
|
9
9
|
// factory-token the token is fine-grained and reaches this repository only
|
|
10
|
-
// factory-token-reads the token can read
|
|
11
|
-
//
|
|
10
|
+
// factory-token-reads the token can read each permission of PAT_PERMISSIONS
|
|
11
|
+
// (setup/command.mjs) on this repository
|
|
12
12
|
//
|
|
13
13
|
// A write permission cannot be tested without writing, so a read that works shows the
|
|
14
|
-
// permission is there at least to read;
|
|
14
|
+
// permission is there at least to read; the variables read, the one with no public
|
|
15
15
|
// fallback, is the one that proves itself.
|
|
16
16
|
|
|
17
17
|
import { result } from "../../checks/result.mjs";
|
|
18
18
|
import { firstLine } from "../../exec.mjs";
|
|
19
19
|
import { checkToken } from "../run/token.mjs";
|
|
20
|
+
import { PAT_PERMISSIONS, nameList, patPermissionsSummary } from "../setup/command.mjs";
|
|
20
21
|
import { TOKEN_VAR } from "../run/secrets.mjs";
|
|
21
22
|
|
|
22
23
|
export const ORCHESTRATE_LOCAL_CHECKS = Object.freeze([
|
|
@@ -75,13 +76,12 @@ function checkReach({ gh, repo, read }) {
|
|
|
75
76
|
);
|
|
76
77
|
}
|
|
77
78
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
[
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
];
|
|
79
|
+
/** One read per permission of the token, from PAT_PERMISSIONS. */
|
|
80
|
+
export const readsFor = (repo, branch, permissions = PAT_PERMISSIONS) =>
|
|
81
|
+
permissions.map(([name, , path]) => [
|
|
82
|
+
name,
|
|
83
|
+
path.replace("{repo}", repo).replace("{branch}", branch),
|
|
84
|
+
]);
|
|
85
85
|
|
|
86
86
|
function checkReads({ gh, repo, defaultBranch, host, read, reach }) {
|
|
87
87
|
if (!read.token || reach.status !== "pass") {
|
|
@@ -92,7 +92,7 @@ function checkReads({ gh, repo, defaultBranch, host, read, reach }) {
|
|
|
92
92
|
}
|
|
93
93
|
const hostArgs = host && host !== "github.com" ? ["--hostname", host] : [];
|
|
94
94
|
const lacking = [];
|
|
95
|
-
for (const [name, endpoint] of
|
|
95
|
+
for (const [name, endpoint] of readsFor(repo, defaultBranch)) {
|
|
96
96
|
const r = gh(["api", ...hostArgs, "--method", "GET", endpoint]);
|
|
97
97
|
if (r.status === 0) continue;
|
|
98
98
|
const text = `${r.stderr}\n${r.stdout}`;
|
|
@@ -106,7 +106,7 @@ function checkReads({ gh, repo, defaultBranch, host, read, reach }) {
|
|
|
106
106
|
`The token cannot read ${lacking.join(", ")} on ${repo}.`,
|
|
107
107
|
{
|
|
108
108
|
details: [
|
|
109
|
-
|
|
109
|
+
`It needs ${patPermissionsSummary()}.`,
|
|
110
110
|
"Edit the token's repository permissions on GitHub, or make a new one.",
|
|
111
111
|
],
|
|
112
112
|
},
|
|
@@ -115,10 +115,10 @@ function checkReads({ gh, repo, defaultBranch, host, read, reach }) {
|
|
|
115
115
|
return make(
|
|
116
116
|
"factory-token-reads",
|
|
117
117
|
"pass",
|
|
118
|
-
`The token reads ${repo}'s
|
|
118
|
+
`The token reads ${repo}'s ${nameList(PAT_PERMISSIONS.map(([name]) => name))}.`,
|
|
119
119
|
{
|
|
120
120
|
details: [
|
|
121
|
-
"A write permission cannot be tested without writing. On a public repository GitHub lets any token read all but
|
|
121
|
+
"A write permission cannot be tested without writing. On a public repository GitHub lets any token read all but the repository variables.",
|
|
122
122
|
],
|
|
123
123
|
},
|
|
124
124
|
);
|
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
// Nothing here touches the disk or GitHub. The files are the Consumer's after
|
|
4
4
|
// the first copy; the Kit-owned bundle is copied by init's own Kit-owned step.
|
|
5
5
|
|
|
6
|
+
import { qaAppPathsFromConfig } from "../qa/decide.mjs";
|
|
7
|
+
|
|
6
8
|
export const FACTORY_DIR = ".github/factory";
|
|
7
9
|
export const CONFIG_PATH = `${FACTORY_DIR}/config.json`;
|
|
8
10
|
export const RISK_RULES_PATH = `${FACTORY_DIR}/risk-rules.json`;
|
|
@@ -25,8 +27,7 @@ export class BlueprintError extends Error {}
|
|
|
25
27
|
|
|
26
28
|
/**
|
|
27
29
|
* A Caller's text with every `uses:` pin of the kit's reusable workflows moved
|
|
28
|
-
* to `tag`. A Caller that calls none
|
|
29
|
-
* nothing to pin and is copied as it is.
|
|
30
|
+
* to `tag`. A Caller that calls none has nothing to pin and is copied as it is.
|
|
30
31
|
*/
|
|
31
32
|
export function pinCaller(text, tag) {
|
|
32
33
|
return text.replace(KIT_PIN, (_, path) => `${path}@${tag}`);
|
|
@@ -48,6 +49,12 @@ export function renderConfig(text, { notify }) {
|
|
|
48
49
|
if (config === null || typeof config !== "object" || Array.isArray(config) || !config.budget) {
|
|
49
50
|
throw new BlueprintError(`${CONFIG_EXAMPLE} is not a factory config.`);
|
|
50
51
|
}
|
|
52
|
+
// The QA path rule (`qa.app_paths`, ADR 0048): without it every QA Report is held for a
|
|
53
|
+
// person, so the blueprint always carries one. `["**"]` makes every path an app path;
|
|
54
|
+
// the maintainers narrow it to say which paths a person must review.
|
|
55
|
+
if (qaAppPathsFromConfig(text).value === null) {
|
|
56
|
+
throw new BlueprintError(`${CONFIG_EXAMPLE} has no \`qa.app_paths\` list of path globs.`);
|
|
57
|
+
}
|
|
51
58
|
config.budget.notify = notify;
|
|
52
59
|
return `${JSON.stringify(config, null, 2)}\n`;
|
|
53
60
|
}
|