benignswarm 0.12.57 → 0.12.58
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/commands/machine-admin.js +4 -4
- package/dist/commands/machine.js +35 -4
- package/dist/harness.js +23 -0
- package/dist/help.js +4 -2
- package/dist/version.js +1 -1
- package/package.json +1 -1
package/dist/args.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { parseArgs } from "node:util";
|
|
2
2
|
import { CliError } from "./errors.js";
|
|
3
3
|
export const STRING_FLAGS = ["as", "admin", "key", "url", "label", "model", "since", "limit", "after", "topic", "goal", "task", "state", "blocked-on", "tags", "custom", "vendor", "role", "description", "permissions", "cardinality", "machine", "dir", "confirm", "type", "name", "out", "token", "prefix", "uses", "expires-hours", "skill-dir", "harness", "reply-to", "event", "project", "projects", "post", "title", "body", "body-file", "handoff-to", "evidence", "agent", "parent", "parent-item", "channel", "statuses", "assign", "if-status", "status", "exec", "interval", "requeue-after", "unacked-after", "category", "command", "follow-delay", "env", "scope", "pr", "note", "add", "remove", "merged", "tag", "activity", "max-unanswered", "to", "replay-of", "branch", "effort", "by", "target", "milestone", "file", "exit", "depends-on", "source", "by", "on", "question", "ruling", "gaps", "unit", "units", "blocks", "sla", "takeover", "max-open", "max-in-progress", "require-scope", "require-evidence", "default-approver", "merged-by", "integrator-role", "require-rebased", "require-merge-commit", "require-pushed", "quiet", "summary", "meaning", "expert-role", "reviews", "works", "trials", "email", "repeat", "summary-minutes", "churn", "unmet", "require-cited-changes", "checks-every", "propose", "waits-on", "sandbox", "thread", "turn-timeout", "ssh", "variant", "count", "needs", "min-ram", "exclude"];
|
|
4
|
-
export const BOOL_FLAGS = ["latest", "no-restart", "json", "follow", "account", "help", "version", "broadcast", "create-channels", "read-account-status", "replace-key", "mentions-me", "no-skill", "replace", "unread", "force", "no-hooks", "yes", "open", "bind-here", "peek", "once", "launchd", "full", "no-bind", "all", "here", "keep-worktree", "prune", "abandon", "defer", "hold", "clear", "met", "shared", "archive", "approve", "turn", "service", "print-hooks", "create", "rotate"];
|
|
4
|
+
export const BOOL_FLAGS = ["latest", "no-restart", "json", "follow", "account", "help", "version", "broadcast", "create-channels", "read-account-status", "replace-key", "mentions-me", "no-skill", "replace", "unread", "force", "no-hooks", "yes", "open", "bind-here", "peek", "once", "launchd", "full", "no-bind", "all", "here", "keep-worktree", "prune", "abandon", "defer", "hold", "clear", "met", "shared", "archive", "approve", "turn", "service", "print-hooks", "create", "rotate", "codex-userns", "print-apparmor"];
|
|
5
5
|
export function parse(argv) {
|
|
6
6
|
const options = {};
|
|
7
7
|
for (const f of STRING_FLAGS)
|
|
@@ -10,7 +10,7 @@ import { CLI_VERSION } from "../version.js";
|
|
|
10
10
|
* sessions they run (docs/REMOTE-MACHINES.md). The server never sees an ssh credential: every ssh
|
|
11
11
|
* call here runs in the operator's terminal, and the machine key reaches the machine on ssh's stdin.
|
|
12
12
|
*
|
|
13
|
-
* machine add <name> --ssh <host> [--rotate]
|
|
13
|
+
* machine add <name> --ssh <host> [--rotate] [--codex-userns]
|
|
14
14
|
* machine list | show <name> | remove <name>
|
|
15
15
|
* machine session add <machine> <project>/<agent> --dir <path> --sandbox <mode> [--create --role r] [--model m] [--effort e] [--thread id] [--turn-timeout min]
|
|
16
16
|
* machine session stop|start|remove <machine> <project>/<agent>
|
|
@@ -65,7 +65,7 @@ export async function machineAdmin(action, rest, p, out) {
|
|
|
65
65
|
const name = rest[0];
|
|
66
66
|
const host = str(p.flags, "ssh");
|
|
67
67
|
if (!name || !host)
|
|
68
|
-
throw new CliError("usage", "machine add <name> --ssh <host> (the host as your ssh knows it: an alias, user@host)");
|
|
68
|
+
throw new CliError("usage", "machine add <name> --ssh <host> [--rotate] [--codex-userns] (the host as your ssh knows it: an alias, user@host)");
|
|
69
69
|
const lines = [];
|
|
70
70
|
const say = (l) => { lines.push(l); if (!out.json)
|
|
71
71
|
process.stderr.write(`${l}\n`); };
|
|
@@ -77,7 +77,7 @@ export async function machineAdmin(action, rest, p, out) {
|
|
|
77
77
|
if (boot.status !== 0)
|
|
78
78
|
throw new CliError("provision_failed", `bootstrapping ${host} failed${steps.length ? `: ${steps[steps.length - 1]}` : `: ${boot.stderr.trim().slice(-300)}`}`);
|
|
79
79
|
// 2. Linger, Codex, managed hooks: checked and fixed on the machine itself.
|
|
80
|
-
const prep = remoteBschat(host,
|
|
80
|
+
const prep = remoteBschat(host, `machine prepare --json${bool(p.flags, "codex-userns") ? " --codex-userns" : ""}`);
|
|
81
81
|
if (prep.status !== 0)
|
|
82
82
|
throw new CliError("provision_failed", `bschat machine prepare on ${host} failed: ${prep.stderr.trim().slice(-300)}`);
|
|
83
83
|
const prepared = JSON.parse(prep.stdout).steps;
|
|
@@ -124,7 +124,7 @@ export async function machineAdmin(action, rest, p, out) {
|
|
|
124
124
|
const rep = m.report ?? {};
|
|
125
125
|
const head = [
|
|
126
126
|
`${m.name}: last report ${m.last_report_at ?? "never"}; labels ${(m.labels ?? []).join(", ") || "(none)"}; slots ${m.slots ?? "auto"}; workdir ${rep.workdir ?? m.workdir ?? "~/bschat"}${rep.workdir_free_bytes ? ` (${Math.round(rep.workdir_free_bytes / 1e9)} GB free)` : ""}`,
|
|
127
|
-
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"}; bschat ${rep.bschat?.version}; codex ${rep.codex ? `${rep.codex.version}, ${rep.codex.logged_in ? "logged in" : "NOT logged in"}` : "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?)",
|
|
127
|
+
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"}; bschat ${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?)",
|
|
128
128
|
];
|
|
129
129
|
const rows = m.sessions.map((s) => ({ agent: s.agent, pool: s.pool ?? "-", desired: s.desired, state: s.reported?.state ?? "-", thread: s.thread ?? "-", 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+ bschat watch\[[^\]]+\]: /, "") }));
|
|
130
130
|
return out.print([...head, rows.length ? table(rows, ["agent", "pool", "desired", "state", "thread", "sandbox", "model", "dir", "error", "last_turn"]) : " no sessions"].join("\n"), r);
|
package/dist/commands/machine.js
CHANGED
|
@@ -6,7 +6,7 @@ import { str } from "../args.js";
|
|
|
6
6
|
import { Client } from "../client.js";
|
|
7
7
|
import { configRoot, loadAgent, saveAgent } from "../config.js";
|
|
8
8
|
import { CliError } from "../errors.js";
|
|
9
|
-
import { CODEX_MANAGED_DIR, CODEX_MANAGED_MARK, codexManagedHooks } from "../harness.js";
|
|
9
|
+
import { CODEX_APPARMOR_PATH, CODEX_MANAGED_DIR, CODEX_MANAGED_MARK, codexAppArmorProfile, codexManagedHooks } from "../harness.js";
|
|
10
10
|
import { applySparse } from "../git.js";
|
|
11
11
|
import { installService, lingerEnabled, MACHINE_LABEL, removeService, requireInstall, restartWatcher, serviceActive, WATCH_LABEL_PREFIX, watcherServices } from "../install.js";
|
|
12
12
|
import { CLI_VERSION } from "../version.js";
|
|
@@ -241,6 +241,16 @@ function freeBytes(path) {
|
|
|
241
241
|
return null;
|
|
242
242
|
}
|
|
243
243
|
}
|
|
244
|
+
/** Whether Codex's own sandbox runs here (`codex sandbox -- true`), with its error; checked at most every 10 min. */
|
|
245
|
+
let sandboxCache = null;
|
|
246
|
+
export function codexSandbox(force = false) {
|
|
247
|
+
if (!force && sandboxCache && Date.now() - sandboxCache.at < 10 * 60_000)
|
|
248
|
+
return sandboxCache.result;
|
|
249
|
+
const r = spawnSync("codex", ["sandbox", "--", "true"], { encoding: "utf8", timeout: 60_000 });
|
|
250
|
+
const result = r.status === 0 ? { ok: true, error: null } : { ok: false, error: `${r.stderr ?? ""}${r.stdout ?? ""}`.trim().split("\n")[0].slice(0, 300) || `exit ${r.status}` };
|
|
251
|
+
sandboxCache = { at: Date.now(), result };
|
|
252
|
+
return result;
|
|
253
|
+
}
|
|
244
254
|
/** What the operator needs to know about this machine, reported with every pass. */
|
|
245
255
|
export function machineFacts() {
|
|
246
256
|
const codex = spawnSync("codex", ["--version"], { encoding: "utf8" });
|
|
@@ -257,7 +267,7 @@ export function machineFacts() {
|
|
|
257
267
|
return {
|
|
258
268
|
os: platform(), arch: arch(), hostname: hostname(), user: userInfo().username, cpus: cpus().length, mem_total_bytes: totalmem(),
|
|
259
269
|
bschat: { version: CLI_VERSION, bin: requireInstall().bin },
|
|
260
|
-
codex: codex.status === 0 ? { version: codex.stdout.trim(), logged_in: login?.status === 0 && /logged in/i.test(`${login.stdout}${login.stderr}`), login: `${login?.stdout ?? ""}${login?.stderr ?? ""}`.trim().slice(0, 200) } : null,
|
|
270
|
+
codex: codex.status === 0 ? { version: codex.stdout.trim(), logged_in: login?.status === 0 && /logged in/i.test(`${login.stdout}${login.stderr}`), login: `${login?.stdout ?? ""}${login?.stderr ?? ""}`.trim().slice(0, 200), sandbox: codexSandbox() } : null,
|
|
261
271
|
managed_hooks: existsSync(req) && readFileSync(req, "utf8").includes(CODEX_MANAGED_MARK),
|
|
262
272
|
linger: platform() === "linux" ? lingerEnabled() : null,
|
|
263
273
|
disk_free_bytes: diskFree,
|
|
@@ -269,7 +279,7 @@ export function machineFacts() {
|
|
|
269
279
|
* Linux, Codex present and logged in, and bschat's hooks in Codex's administrator layer when sudo
|
|
270
280
|
* works without a password. Each step reports ok, done, skipped or failed; nothing is hidden.
|
|
271
281
|
*/
|
|
272
|
-
export function prepare() {
|
|
282
|
+
export function prepare(opts = {}) {
|
|
273
283
|
const steps = [];
|
|
274
284
|
const sudo = spawnSync("sudo", ["-n", "true"], { stdio: "ignore" }).status === 0;
|
|
275
285
|
if (platform() === "linux") {
|
|
@@ -290,6 +300,25 @@ export function prepare() {
|
|
|
290
300
|
const ok = login.status === 0 && /logged in/i.test(`${login.stdout}${login.stderr}`);
|
|
291
301
|
steps.push({ step: "codex", result: ok ? "ok" : "failed", detail: ok ? `${codex.stdout.trim()}, ${`${login.stdout}${login.stderr}`.trim()}` : `${codex.stdout.trim()} is not logged in: run codex login --device-auth on this machine` });
|
|
292
302
|
}
|
|
303
|
+
if (codex.status === 0) {
|
|
304
|
+
let sb = codexSandbox(true);
|
|
305
|
+
if (sb.ok)
|
|
306
|
+
steps.push({ step: "codex sandbox", result: "ok", detail: "sandboxed (read-only, workspace-write) agents can run here" });
|
|
307
|
+
else if (platform() !== "linux" || !/userns|uid map|RTM_NEWADDR|Operation not permitted|Permission denied/i.test(sb.error ?? ""))
|
|
308
|
+
steps.push({ step: "codex sandbox", result: "failed", detail: `${sb.error}; only danger-full-access agents can run here` });
|
|
309
|
+
else if (!opts.codexUserns)
|
|
310
|
+
steps.push({ step: "codex sandbox", result: "failed", detail: `${sb.error}: this system restricts the user namespaces Codex's sandbox needs. Re-run machine add with --codex-userns to install a Codex-only AppArmor profile (${CODEX_APPARMOR_PATH}), or use danger-full-access pools here` });
|
|
311
|
+
else if (!sudo)
|
|
312
|
+
steps.push({ step: "codex sandbox", result: "failed", detail: `--codex-userns needs passwordless sudo; install ${CODEX_APPARMOR_PATH} by hand (bschat machine prepare --print-apparmor shows it) and run sudo apparmor_parser -r on it` });
|
|
313
|
+
else {
|
|
314
|
+
const t = spawnSync("sudo", ["-n", "tee", CODEX_APPARMOR_PATH], { input: codexAppArmorProfile(), stdio: ["pipe", "ignore", "pipe"], encoding: "utf8" });
|
|
315
|
+
const l = t.status === 0 ? spawnSync("sudo", ["-n", "apparmor_parser", "-r", CODEX_APPARMOR_PATH], { encoding: "utf8" }) : t;
|
|
316
|
+
sb = codexSandbox(true);
|
|
317
|
+
steps.push(l.status === 0 && sb.ok
|
|
318
|
+
? { step: "codex sandbox", result: "done", detail: `installed ${CODEX_APPARMOR_PATH} (Codex only); the sandbox works` }
|
|
319
|
+
: { step: "codex sandbox", result: "failed", detail: l.status !== 0 ? `installing ${CODEX_APPARMOR_PATH}: ${(l.stderr ?? "").trim()}` : `profile installed but the sandbox still fails: ${sb.error}` });
|
|
320
|
+
}
|
|
321
|
+
}
|
|
293
322
|
const req = "/etc/codex/requirements.toml";
|
|
294
323
|
const { requirements, wrapper } = codexManagedHooks(requireInstall().bin);
|
|
295
324
|
const current = existsSync(req) ? readFileSync(req, "utf8") : null;
|
|
@@ -330,7 +359,9 @@ export async function machine(p, out) {
|
|
|
330
359
|
if (sub === "prepare") {
|
|
331
360
|
if (p.flags["print-hooks"])
|
|
332
361
|
return out.print(codexManagedHooks(requireInstall().bin).requirements, codexManagedHooks(requireInstall().bin));
|
|
333
|
-
|
|
362
|
+
if (p.flags["print-apparmor"])
|
|
363
|
+
return out.print(codexAppArmorProfile(), { path: CODEX_APPARMOR_PATH, profile: codexAppArmorProfile() });
|
|
364
|
+
const steps = prepare({ codexUserns: p.flags["codex-userns"] === true });
|
|
334
365
|
return out.print(steps.map((s) => `${s.result.padEnd(8)} ${s.step}: ${s.detail}`).join("\n"), { steps });
|
|
335
366
|
}
|
|
336
367
|
if (sub === "service") {
|
package/dist/harness.js
CHANGED
|
@@ -301,3 +301,26 @@ export function codexManagedHooks(bin) {
|
|
|
301
301
|
].join("\n");
|
|
302
302
|
return { requirements, wrapper };
|
|
303
303
|
}
|
|
304
|
+
export const CODEX_APPARMOR_PATH = "/etc/apparmor.d/bschat-codex";
|
|
305
|
+
/**
|
|
306
|
+
* An AppArmor profile that lets only Codex's own binary create user namespaces, which its Linux
|
|
307
|
+
* sandbox (bubblewrap, built into the binary) needs. Ubuntu 24.04+ restricts unprivileged user
|
|
308
|
+
* namespaces (kernel.apparmor_restrict_unprivileged_userns = 1), so without it every sandboxed
|
|
309
|
+
* command fails with "bwrap: setting up uid map: Permission denied". Unconfined apart from that,
|
|
310
|
+
* as Ubuntu's own profiles for browsers are; installed only when the operator opts in.
|
|
311
|
+
*/
|
|
312
|
+
export function codexAppArmorProfile() {
|
|
313
|
+
return [
|
|
314
|
+
`# bschat: let Codex create the user namespaces its Linux sandbox needs (Ubuntu 24.04+ restricts them).`,
|
|
315
|
+
`# Codex only. Written by bschat machine prepare --codex-userns; remove this file and run`,
|
|
316
|
+
`# apparmor_parser -R on it to undo.`,
|
|
317
|
+
`abi <abi/4.0>,`,
|
|
318
|
+
`include <tunables/global>`,
|
|
319
|
+
``,
|
|
320
|
+
`profile bschat-codex /home/*/.codex/packages/standalone/releases/*/bin/codex flags=(unconfined) {`,
|
|
321
|
+
` userns,`,
|
|
322
|
+
` include if exists <local/bschat-codex>`,
|
|
323
|
+
`}`,
|
|
324
|
+
``,
|
|
325
|
+
].join("\n");
|
|
326
|
+
}
|
package/dist/help.js
CHANGED
|
@@ -198,8 +198,10 @@ bschat-admin login (approve it in your signed-in browser); the session lasts 30
|
|
|
198
198
|
bschat-admin worktree forget <project> <id> delete a stale worktree record (never the directory)
|
|
199
199
|
|
|
200
200
|
Machines (provisioned over your own ssh; a daemon on each runs the agent sessions you declare)
|
|
201
|
-
bschat-admin machine add <name> --ssh <host> [--rotate] install Node and bschat (no sudo), linger, Codex check,
|
|
202
|
-
bschat's Codex hooks in /etc/codex (passwordless sudo only), register, start the daemon
|
|
201
|
+
bschat-admin machine add <name> --ssh <host> [--rotate] [--codex-userns] install Node and bschat (no sudo), linger, Codex check,
|
|
202
|
+
bschat's Codex hooks in /etc/codex (passwordless sudo only), register, start the daemon;
|
|
203
|
+
--codex-userns: where Linux restricts user namespaces (Ubuntu 24.04+), install a
|
|
204
|
+
Codex-only AppArmor profile so sandboxed agents can run
|
|
203
205
|
bschat-admin machine list | show <name> | remove <name>
|
|
204
206
|
bschat-admin machine session add <machine> <project>/<agent> --dir <checkout> --sandbox <read-only|workspace-write|danger-full-access>
|
|
205
207
|
[--create --role <role>] [--model m] [--effort e] [--thread <id>] [--turn-timeout min]
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const CLI_VERSION = "0.12.
|
|
1
|
+
export const CLI_VERSION = "0.12.58";
|