benignswarm 0.12.105 → 0.12.106
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/dist/args.js +1 -1
- package/dist/capabilities.js +70 -15
- package/dist/client.js +7 -2
- package/dist/command-runner.js +1 -1
- package/dist/commands/image-admin.js +16 -3
- package/dist/commands/machine-admin.js +14 -2
- package/dist/commands/machine.js +321 -24
- package/dist/commands/measures.js +1 -1
- package/dist/commands/watch.js +25 -6
- package/dist/commands/wu.js +58 -16
- package/dist/container.js +565 -33
- package/dist/errors.js +1 -0
- package/dist/help.js +10 -6
- package/dist/output.js +9 -7
- package/dist/turn-guard.js +30 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
package/dist/args.js
CHANGED
|
@@ -32,7 +32,7 @@ export const STRING_FLAGS = [
|
|
|
32
32
|
"root", "signing-key", "catalog", "context", "context-action", "context-checkpoint-ref", "context-old-thread", "context-new-thread", "source-commit", "component", "normalized-key",
|
|
33
33
|
"drain-timeout", "on-running-turn", "extend", "ssh-config", "poll-ms",
|
|
34
34
|
"stage", "machines", "resolved-retention-days", "wont-fix-retention-days", "alert-cooldown-minutes", "alerts", "confirm-force",
|
|
35
|
-
"machine-session-id", "detail", "worktree",
|
|
35
|
+
"machine-session-id", "pool-sessions", "registry", "detail", "worktree",
|
|
36
36
|
"purpose", "storage-mode", "hosts", "arn", "version-id",
|
|
37
37
|
"mode", "weights", "quality-target", "half-life", "min-samples", "build-explore", "review-explore", "pause-build", "pause-review", "class",
|
|
38
38
|
];
|
package/dist/capabilities.js
CHANGED
|
@@ -3,6 +3,7 @@ import { mkdtempSync, rmSync } from "node:fs";
|
|
|
3
3
|
import { homedir, tmpdir } from "node:os";
|
|
4
4
|
import { join } from "node:path";
|
|
5
5
|
import { performance } from "node:perf_hooks";
|
|
6
|
+
import { assertSafeMountPath, isolatedSubprocessEnv } from "./container.js";
|
|
6
7
|
export const DEFAULT_CAPABILITY_TIMEOUT_MS = 60_000;
|
|
7
8
|
const MAX_OUTPUT_BYTES = 64 * 1024;
|
|
8
9
|
function appendLimited(chunks, capturedBytes, chunk) {
|
|
@@ -11,7 +12,7 @@ function appendLimited(chunks, capturedBytes, chunk) {
|
|
|
11
12
|
chunks.push(chunk.subarray(0, remaining));
|
|
12
13
|
return { capturedBytes: capturedBytes + Math.min(chunk.length, Math.max(remaining, 0)), exceeded: chunk.length > remaining };
|
|
13
14
|
}
|
|
14
|
-
function
|
|
15
|
+
function runProbeCommand(cmd, args, cwd, timeoutMs, env) {
|
|
15
16
|
const startedAt = performance.now();
|
|
16
17
|
const stdout = [];
|
|
17
18
|
const stderr = [];
|
|
@@ -21,8 +22,9 @@ function runProbe(command, cwd, timeoutMs) {
|
|
|
21
22
|
let spawnError = null;
|
|
22
23
|
let killError = null;
|
|
23
24
|
let timedOut = false;
|
|
24
|
-
const child = spawn(
|
|
25
|
+
const child = spawn(cmd, args, {
|
|
25
26
|
cwd,
|
|
27
|
+
...(env ? { env } : {}),
|
|
26
28
|
detached: process.platform !== "win32",
|
|
27
29
|
stdio: ["ignore", "pipe", "pipe"],
|
|
28
30
|
});
|
|
@@ -72,25 +74,78 @@ function runProbe(command, cwd, timeoutMs) {
|
|
|
72
74
|
});
|
|
73
75
|
}
|
|
74
76
|
/** Run every declaration and preserve failures as results, so dispatch can explain a missing tool. */
|
|
75
|
-
export async function probeCapabilities(definitions, projectDir) {
|
|
77
|
+
export async function probeCapabilities(definitions, projectDir, opts) {
|
|
76
78
|
const results = [];
|
|
77
79
|
for (const definition of definitions) {
|
|
78
80
|
let cwd = homedir();
|
|
79
81
|
let temporary = null;
|
|
80
82
|
try {
|
|
81
|
-
if (definition.scope === "worktree") {
|
|
82
|
-
temporary = mkdtempSync(join(tmpdir(), "bschat-capability-"));
|
|
83
|
-
const path = join(temporary, "worktree");
|
|
84
|
-
const added = spawnSync("git", ["worktree", "add", "--quiet", "--detach", path, "HEAD"], { cwd: projectDir, encoding: "utf8", timeout: 120_000 });
|
|
85
|
-
if (added.status !== 0)
|
|
86
|
-
throw new Error((added.stderr || added.stdout || "git worktree add failed").trim().split(/\r?\n/, 1)[0]);
|
|
87
|
-
const full = spawnSync("git", ["-C", path, "sparse-checkout", "disable"], { encoding: "utf8", timeout: 30_000 });
|
|
88
|
-
if (full.status !== 0)
|
|
89
|
-
throw new Error(full.error?.message ?? (full.stderr || full.stdout || "git sparse-checkout disable failed").trim());
|
|
90
|
-
cwd = path;
|
|
91
|
-
}
|
|
92
83
|
const timeoutMs = definition.timeout_ms ?? DEFAULT_CAPABILITY_TIMEOUT_MS;
|
|
93
|
-
|
|
84
|
+
let result;
|
|
85
|
+
if (definition.scope === "image") {
|
|
86
|
+
if (!opts?.container?.imageDigest) {
|
|
87
|
+
throw new Error("image capability probe requires an active pinned container image");
|
|
88
|
+
}
|
|
89
|
+
const ctx = opts.container;
|
|
90
|
+
const trimmedDir = typeof projectDir === "string" ? projectDir.trim() : "";
|
|
91
|
+
const safeWorktree = trimmedDir
|
|
92
|
+
? assertSafeMountPath(trimmedDir, "worktree", ctx.hostHome ? { hostHome: ctx.hostHome } : {})
|
|
93
|
+
: null;
|
|
94
|
+
const containerArgs = [
|
|
95
|
+
"run",
|
|
96
|
+
"--rm",
|
|
97
|
+
"--security-opt",
|
|
98
|
+
"no-new-privileges",
|
|
99
|
+
"--add-host",
|
|
100
|
+
"169.254.169.254:127.0.0.1",
|
|
101
|
+
"--add-host",
|
|
102
|
+
"metadata.google.internal:127.0.0.1",
|
|
103
|
+
...(ctx.arch ? ["--platform", ctx.arch] : []),
|
|
104
|
+
...(safeWorktree ? ["-v", `${safeWorktree}:/workspace:ro`, "-w", "/workspace"] : []),
|
|
105
|
+
ctx.imageDigest,
|
|
106
|
+
"/bin/sh",
|
|
107
|
+
"-lc",
|
|
108
|
+
definition.probe,
|
|
109
|
+
];
|
|
110
|
+
const probeHostCwd = safeWorktree ?? tmpdir();
|
|
111
|
+
if (ctx.runner) {
|
|
112
|
+
const startedAt = performance.now();
|
|
113
|
+
const res = ctx.runner(ctx.runtime, containerArgs, {
|
|
114
|
+
cwd: probeHostCwd,
|
|
115
|
+
timeout: timeoutMs,
|
|
116
|
+
env: isolatedSubprocessEnv(process.env),
|
|
117
|
+
});
|
|
118
|
+
result = {
|
|
119
|
+
status: res.status,
|
|
120
|
+
stdout: res.stdout ?? "",
|
|
121
|
+
stderr: res.stderr ?? "",
|
|
122
|
+
error: res.error ?? null,
|
|
123
|
+
killError: null,
|
|
124
|
+
timedOut: false,
|
|
125
|
+
elapsedMs: Math.round(performance.now() - startedAt),
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
else {
|
|
129
|
+
result = await runProbeCommand(ctx.runtime, containerArgs, probeHostCwd, timeoutMs, isolatedSubprocessEnv(process.env));
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
else {
|
|
133
|
+
if (definition.scope === "worktree") {
|
|
134
|
+
const wtSource = typeof projectDir === "string" ? projectDir.trim() : "";
|
|
135
|
+
if (!wtSource)
|
|
136
|
+
throw new Error("worktree capability probe requires a checked-out project directory");
|
|
137
|
+
temporary = mkdtempSync(join(tmpdir(), "bschat-capability-"));
|
|
138
|
+
const path = join(temporary, "worktree");
|
|
139
|
+
const added = spawnSync("git", ["worktree", "add", "--quiet", "--detach", path, "HEAD"], { cwd: wtSource, encoding: "utf8", timeout: 120_000 });
|
|
140
|
+
if (added.status !== 0)
|
|
141
|
+
throw new Error((added.stderr || added.stdout || "git worktree add failed").trim().split(/\r?\n/, 1)[0]);
|
|
142
|
+
const full = spawnSync("git", ["-C", path, "sparse-checkout", "disable"], { encoding: "utf8", timeout: 30_000 });
|
|
143
|
+
if (full.status !== 0)
|
|
144
|
+
throw new Error(full.error?.message ?? (full.stderr || full.stdout || "git sparse-checkout disable failed").trim());
|
|
145
|
+
cwd = path;
|
|
146
|
+
}
|
|
147
|
+
result = await runProbeCommand("/bin/sh", ["-lc", definition.probe], cwd, timeoutMs);
|
|
148
|
+
}
|
|
94
149
|
const output = `${result.stdout}${result.stderr}`.trim().split(/\r?\n/, 1)[0] ?? "";
|
|
95
150
|
const ok = result.status === 0 && !result.error && !result.timedOut;
|
|
96
151
|
const error = result.timedOut
|
package/dist/client.js
CHANGED
|
@@ -115,8 +115,13 @@ function expectedTextReceiptFields(method, path, body, response) {
|
|
|
115
115
|
required.push("replace.new");
|
|
116
116
|
return required;
|
|
117
117
|
}
|
|
118
|
-
if (action === "wait")
|
|
119
|
-
|
|
118
|
+
if (action === "wait") {
|
|
119
|
+
// A unit wait persists its note only. Review waits also persist a supplied partial verdict.
|
|
120
|
+
const required = strings("note");
|
|
121
|
+
if (response?.unit?.review_wait && typeof fields.partial === "string")
|
|
122
|
+
required.push("partial");
|
|
123
|
+
return required;
|
|
124
|
+
}
|
|
120
125
|
if (["approve", "changes", "proceed"].includes(action))
|
|
121
126
|
return strings("note", "unmet");
|
|
122
127
|
if (["park", "requeue", "decline", "classify", "tags", "reopen", "supersede", "done", "abandon", "merge", "evidence/replace", "restore", "note", "hold", "hold/release", "question/escalate"].includes(action))
|
package/dist/command-runner.js
CHANGED
|
@@ -8,7 +8,7 @@ export async function runCommandSafely(run, out) {
|
|
|
8
8
|
catch (error) {
|
|
9
9
|
if (error instanceof WrittenReceiptMismatchError) {
|
|
10
10
|
const detail = error.message.replace(/^write succeeded; receipt mismatch:\s*/, "");
|
|
11
|
-
printWrittenReceiptMismatch(out, error.response, detail);
|
|
11
|
+
printWrittenReceiptMismatch(out, error.response, detail, error.actionResult);
|
|
12
12
|
return WRITTEN_RECEIPT_MISMATCH_EXIT_CODE;
|
|
13
13
|
}
|
|
14
14
|
throw error;
|
|
@@ -20,23 +20,36 @@ export async function projectImageAdmin(rest, p, out) {
|
|
|
20
20
|
}
|
|
21
21
|
const c = Client.forAdmin(loadAdmin(resolveAdminName(str(p.flags, "admin"))));
|
|
22
22
|
if (!sub || !project) {
|
|
23
|
-
throw new CliError("usage", "project image <validate --file f | config <p> [--path f] [--arch linux/amd64|linux/arm64] [--cache name...] | show <p> | build <p> --commit <sha> --file <devcontainer.json> [--dockerfile f] [--arch a] | activate <p> <sha256:...> | rollback <p> (<sha256:...> | clear)>");
|
|
23
|
+
throw new CliError("usage", "project image <validate --file f | config <p> [--path f] [--arch linux/amd64|linux/arm64] [--cache name...] [--pool-sessions on|off] [--registry ns] | show <p> | build <p> --commit <sha> --file <devcontainer.json> [--dockerfile f] [--arch a] | activate <p> <sha256:...> | rollback <p> (<sha256:...> | clear)>");
|
|
24
24
|
}
|
|
25
25
|
switch (sub) {
|
|
26
26
|
case "config": {
|
|
27
27
|
const rawCache = str(p.flags, "caches") ?? str(p.flags, "cache");
|
|
28
28
|
const caches = rawCache ? rawCache.split(",").map((s) => s.trim()).filter(Boolean) : [];
|
|
29
|
+
const rawPoolSessions = str(p.flags, "pool-sessions");
|
|
30
|
+
let poolSessionsEnabled;
|
|
31
|
+
if (rawPoolSessions !== undefined) {
|
|
32
|
+
if (rawPoolSessions === "on" || rawPoolSessions === "true")
|
|
33
|
+
poolSessionsEnabled = true;
|
|
34
|
+
else if (rawPoolSessions === "off" || rawPoolSessions === "false")
|
|
35
|
+
poolSessionsEnabled = false;
|
|
36
|
+
else
|
|
37
|
+
throw new CliError("usage", "--pool-sessions must be on|off (or true|false)");
|
|
38
|
+
}
|
|
39
|
+
const registry = str(p.flags, "registry");
|
|
29
40
|
const r = await c.call("PUT", `/projects/${encodeURIComponent(project)}/image-config`, {
|
|
30
41
|
...(str(p.flags, "path") ? { devcontainer_path: str(p.flags, "path") } : {}),
|
|
31
42
|
...(str(p.flags, "arch") ? { target_arch: str(p.flags, "arch") } : {}),
|
|
32
43
|
...(caches.length ? { allowed_caches: caches } : {}),
|
|
44
|
+
...(poolSessionsEnabled !== undefined ? { pool_sessions_enabled: poolSessionsEnabled } : {}),
|
|
45
|
+
...(registry !== undefined ? { registry_namespace: registry } : {}),
|
|
33
46
|
});
|
|
34
|
-
out.print(`Project ${project} image namespace ${r.image.registry_namespace} (${r.image.target_arch}, ${r.image.devcontainer_path})`, r);
|
|
47
|
+
out.print(`Project ${project} image namespace ${r.image.registry_namespace} (${r.image.target_arch}, ${r.image.devcontainer_path}, pool sessions ${r.image.pool_sessions_enabled ? "enabled" : "disabled"})`, r);
|
|
35
48
|
return;
|
|
36
49
|
}
|
|
37
50
|
case "show": {
|
|
38
51
|
const r = await c.call("GET", `/projects/${encodeURIComponent(project)}/image`);
|
|
39
|
-
out.print(`Project ${project} active digest: ${r.image.active_digest ?? "(none)"}${r.image.rollback_digest ? ` (rollback pinned to ${r.image.rollback_digest})` : ""}`, r);
|
|
52
|
+
out.print(`Project ${project} active digest: ${r.image.active_digest ?? "(none)"}${r.image.rollback_digest ? ` (rollback pinned to ${r.image.rollback_digest})` : ""}; pool sessions ${r.image.pool_sessions_enabled ? "enabled" : "disabled"}`, r);
|
|
40
53
|
return;
|
|
41
54
|
}
|
|
42
55
|
case "build": {
|
|
@@ -194,6 +194,7 @@ export async function machineAdmin(action, rest, p, out) {
|
|
|
194
194
|
`${m.name}: last report ${m.last_report_at ?? "never"}; labels ${(m.labels ?? []).join(", ") || "(none)"}; slots ${m.slots ?? "auto"}; writable ${(m.writable ?? []).join(", ") || "-"}; workdir ${rep.workdir ?? m.workdir ?? "~/bschat"}${rep.workdir_free_bytes ? ` (${Math.round(rep.workdir_free_bytes / 1e9)} GB free)` : ""}; cache budget ${m.cache_budget_gb ?? 40} GB (floor ${m.cache_floor_pct ?? 15}%)`,
|
|
195
195
|
rep.os ? ` ${rep.os}/${rep.arch} ${rep.hostname} as ${rep.user}; ${rep.cpus ?? "?"} CPUs, ${rep.mem_total_bytes ? `${Math.round(rep.mem_total_bytes / 1024 ** 3)} GB RAM` : "? RAM"}; b9s ${rep.bschat?.version}; codex ${rep.codex ? `${rep.codex.version}, ${rep.codex.logged_in ? "logged in" : "NOT logged in"}, sandbox ${rep.codex.sandbox ? (rep.codex.sandbox.ok ? "ok" : `FAILS (${rep.codex.sandbox.error})`) : "?"}` : "missing"}; hooks ${rep.managed_hooks ? "managed by policy" : "user-level"}; linger ${rep.linger ?? "n/a"}; disk free ${rep.disk_free_bytes ? `${Math.round(rep.disk_free_bytes / 1e9)} GB` : "?"}` : " (no report yet: is its daemon running?)",
|
|
196
196
|
rep.os ? ` Antigravity: ${rep.antigravity ? `${rep.antigravity.version ?? "agy"}, ${rep.antigravity.available ? "available" : "unavailable"}, ${rep.antigravity.logged_in ? "logged in" : "not logged in"}, sandbox ${rep.antigravity.sandbox ? (rep.antigravity.sandbox.ok ? "ok" : `FAILS (${rep.antigravity.sandbox.error})`) : "not checked"}` : "not installed"}` : null,
|
|
197
|
+
rep.container_runtime ? ` Container runtime: ${rep.container_runtime.runtime ?? "none"} (${rep.container_runtime.rootless ? "rootless" : "daemon"}, ${rep.container_runtime.usable_without_root === false ? "NO non-root access" : "non-root ok"}, arch ${(rep.container_runtime.architectures ?? []).join(",") || rep.arch || "?"}${rep.on_ec2 ? `, EC2 container IMDS ${rep.container_imds_blocked ? "blocked" : "NOT blocked"}` : ""})` : null,
|
|
197
198
|
m.quarantined ? ` QUARANTINED: ${m.quarantine?.reason ?? "operator containment"}${m.quarantine?.at ? ` (${m.quarantine.at})` : ""}` : null,
|
|
198
199
|
];
|
|
199
200
|
const cacheLines = [];
|
|
@@ -225,11 +226,11 @@ export async function machineAdmin(action, rest, p, out) {
|
|
|
225
226
|
}
|
|
226
227
|
}
|
|
227
228
|
const capabilityLines = machineCapabilityLines(m.capabilities ?? []);
|
|
228
|
-
const rows = m.sessions.map((s) => ({ agent: s.agent, pool: s.pool ?? "-", desired: s.desired, state: s.reported?.state ?? "-", turns_per_hour: s.turns_per_hour ?? 60, coalesce_s: s.turn_coalesce_seconds ?? 180, thread: s.thread ?? "-", harness: s.harness, provider: s.provider ?? "anthropic", sandbox: s.sandbox, model: s.model ?? "-", dir: s.dir || s.reported?.dir || "(auto)", error: s.reported?.error ?? s.reported?.detail ?? "", last_turn: (s.reported?.last_turn ?? "").replace(/^\S+ b9s watch\[[^\]]+\]: /, "") }));
|
|
229
|
+
const rows = m.sessions.map((s) => ({ agent: s.agent, pool: s.pool ?? "-", desired: s.desired, state: s.reported?.state ?? "-", turns_per_hour: s.turns_per_hour ?? 60, coalesce_s: s.turn_coalesce_seconds ?? 180, thread: s.thread ?? "-", harness: s.harness, provider: s.provider ?? "anthropic", sandbox: s.sandbox, image: s.image_digest ? `${s.container_runtime ?? "container"}@${String(s.image_digest).slice(0, 19)}` : "host", model: s.model ?? "-", dir: s.dir || s.reported?.dir || "(auto)", error: s.reported?.error ?? s.reported?.detail ?? "", last_turn: (s.reported?.last_turn ?? "").replace(/^\S+ b9s watch\[[^\]]+\]: /, "") }));
|
|
229
230
|
const providers = rep.claude_code?.providers ?? {};
|
|
230
231
|
const providerLines = Object.entries(providers).map(([provider, check]) => ` Claude Code ${provider}: ${check.logged_in ? "verified" : `NOT verified (${check.reason ?? "unknown reason"})`}`);
|
|
231
232
|
const output = liveReport ? { ...r, machine: { ...m, report: rep } } : r;
|
|
232
|
-
return out.print([...head, ...machineMacLines(rep.macos), ...machineGitLines(rep.git), ...cacheLines, ...capabilityLines, ...providerLines, rows.length ? table(rows, ["agent", "pool", "desired", "state", "turns_per_hour", "coalesce_s", "thread", "harness", "provider", "sandbox", "model", "dir", "error", "last_turn"]) : " no sessions"].filter((line) => line !== null).join("\n"), output);
|
|
233
|
+
return out.print([...head, ...machineMacLines(rep.macos), ...machineGitLines(rep.git), ...cacheLines, ...capabilityLines, ...providerLines, rows.length ? table(rows, ["agent", "pool", "desired", "state", "turns_per_hour", "coalesce_s", "thread", "harness", "provider", "sandbox", "image", "model", "dir", "error", "last_turn"]) : " no sessions"].filter((line) => line !== null).join("\n"), output);
|
|
233
234
|
}
|
|
234
235
|
if (action === "maintenance") {
|
|
235
236
|
// A window on the machine: no new turns from 15 min before, its agents away until it ends.
|
|
@@ -631,6 +632,17 @@ export async function poolAdmin(action, rest, p, out, argv) {
|
|
|
631
632
|
throw new CliError("usage", "--turn-coalesce-seconds is only supported for individual machine sessions; pool settings do not support turn coalescing");
|
|
632
633
|
}
|
|
633
634
|
const c = adminClient(p);
|
|
635
|
+
if (action === "slot") {
|
|
636
|
+
const [operation, target, ...extra] = rest;
|
|
637
|
+
const parts = (target ?? "").split("/");
|
|
638
|
+
if (operation !== "stop" || parts.length !== 3 || parts.some((part) => !part) || extra.length) {
|
|
639
|
+
throw new CliError("usage", "pool slot stop <project>/<pool>/<slot> [--reason text]");
|
|
640
|
+
}
|
|
641
|
+
const [project, name, slot] = parts.map(encodeURIComponent);
|
|
642
|
+
const reason = str(p.flags, "reason");
|
|
643
|
+
const r = await c.call("POST", `/projects/${project}/pools/${name}/slots/${slot}/stop`, reason === undefined ? {} : { reason });
|
|
644
|
+
return out.print(`Suspended ${target}; its machine will stop the session.`, r);
|
|
645
|
+
}
|
|
634
646
|
const statusLines = (pool) => [
|
|
635
647
|
`${pool.project}/${pool.name}: ${pool.count} × role ${pool.role ?? "(none)"}, ${pool.sandbox}; busy cap ${pool.turns_per_hour ?? 60}/hour, unproductive fault ${pool.unproductive_per_hour ?? 6}/hour; variants ${pool.variants.map((v) => `${v.tag}=${v.harness}:${v.model ?? "default"}${v.effort ? `:${v.effort}` : ""}${v.weight > 1 ? `*${v.weight}` : ""}${v.provider && v.provider !== "anthropic" ? `@${v.provider}` : ""}`).join(", ")}${pool.needs?.labels?.length ? `; needs ${pool.needs.labels.join(", ")}` : ""}${pool.needs?.min_ram_gb ? `; min ${pool.needs.min_ram_gb} GB` : ""}`,
|
|
636
648
|
...(pool.status?.placed ?? []).map((x) => ` ${x.agent.padEnd(32)} on ${x.machine}`),
|