benignswarm 0.12.60 → 0.12.62
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/codex-start.js +7 -3
- package/dist/commands/machine-admin.js +48 -4
- package/dist/commands/machine.js +6 -4
- package/dist/help.js +1 -0
- package/dist/version.js +1 -1
- package/package.json +1 -1
package/dist/args.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { parseArgs } from "node:util";
|
|
2
2
|
import { CliError } from "./errors.js";
|
|
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", "carry", "from", "to-ssh", "wait"];
|
|
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", "carry", "from", "to-ssh", "wait", "writable"];
|
|
4
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 = {};
|
|
@@ -57,7 +57,11 @@ export async function codexStart(p, out) {
|
|
|
57
57
|
const ref = agentRef(creds);
|
|
58
58
|
requireInstall();
|
|
59
59
|
// 2. Its thread: adopt one, or start one headless with an onboarding turn.
|
|
60
|
-
|
|
60
|
+
// The machine's toolchain and job folders a sandboxed agent may also write (bschat-admin machine writable).
|
|
61
|
+
const writable = (str(p.flags, "writable") ?? "").split(",").map((w) => w.trim()).filter(Boolean).map((w) => (w.startsWith("~/") ? joinPath(homedir(), w.slice(2)) : w));
|
|
62
|
+
if (writable.some((w) => !w.startsWith("/")))
|
|
63
|
+
throw new CliError("usage", "--writable takes absolute or ~/ paths, comma separated");
|
|
64
|
+
const settings = codexSettings(sandbox, model, effort, process.cwd(), configRoot(), writable);
|
|
61
65
|
let thread;
|
|
62
66
|
let firstTurnLog = null;
|
|
63
67
|
if (adopt) {
|
|
@@ -104,14 +108,14 @@ export async function codexStart(p, out) {
|
|
|
104
108
|
* the API and write its own bschat state (~/.bschat), and `wu start` puts unit worktrees beside the
|
|
105
109
|
* checkout, so those two places are writable and the network is on; nothing else is.
|
|
106
110
|
*/
|
|
107
|
-
export function codexSettings(sandbox, model, effort, cwd, bschatHome) {
|
|
111
|
+
export function codexSettings(sandbox, model, effort, cwd, bschatHome, extraWritable = []) {
|
|
108
112
|
return [
|
|
109
113
|
...(model ? ["-m", model] : []),
|
|
110
114
|
...(effort ? ["-c", `model_reasoning_effort="${effort}"`] : []),
|
|
111
115
|
"-c", `sandbox_mode="${sandbox}"`,
|
|
112
116
|
"-c", `approval_policy="never"`,
|
|
113
117
|
...(sandbox === "workspace-write"
|
|
114
|
-
? ["-c", "sandbox_workspace_write.network_access=true", "-c", `sandbox_workspace_write.writable_roots=${JSON.stringify([bschatHome, dirname(cwd)])}`]
|
|
118
|
+
? ["-c", "sandbox_workspace_write.network_access=true", "-c", `sandbox_workspace_write.writable_roots=${JSON.stringify([bschatHome, dirname(cwd), ...extraWritable])}`]
|
|
115
119
|
: []),
|
|
116
120
|
];
|
|
117
121
|
}
|
|
@@ -51,8 +51,13 @@ for b in bschat bschat-admin; do [ -e "$HOME/.local/bin/$b" ] || ln -sf "$(dirna
|
|
|
51
51
|
step bschat ok "$("$bin" --version) $bin"
|
|
52
52
|
`;
|
|
53
53
|
}
|
|
54
|
+
/**
|
|
55
|
+
* Runs `command` on `host` with /bin/sh, whatever the account's login shell: zsh aborts a command
|
|
56
|
+
* whose glob matches nothing (mini1: the archived-sessions pattern of a thread lookup). Output may be
|
|
57
|
+
* a whole Codex thread (ester's sol-reviewer: 87 MB).
|
|
58
|
+
*/
|
|
54
59
|
function ssh(host, command, input) {
|
|
55
|
-
const r = spawnSync("ssh", ["-o", "BatchMode=yes", host, command], { input, encoding: "utf8", timeout: 600_000, maxBuffer:
|
|
60
|
+
const r = spawnSync("ssh", ["-o", "BatchMode=yes", host, `/bin/sh -c ${shellSingle(command)}`], { input, encoding: "utf8", timeout: 600_000, maxBuffer: 512 * 1024 * 1024 });
|
|
56
61
|
if (r.error)
|
|
57
62
|
throw new CliError("ssh_failed", `ssh ${host}: ${r.error.message}`);
|
|
58
63
|
return { status: r.status ?? 255, stdout: r.stdout ?? "", stderr: r.stderr ?? "" };
|
|
@@ -123,12 +128,19 @@ export async function machineAdmin(action, rest, p, out) {
|
|
|
123
128
|
const m = r.machine;
|
|
124
129
|
const rep = m.report ?? {};
|
|
125
130
|
const head = [
|
|
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)` : ""}`,
|
|
131
|
+
`${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)` : ""}`,
|
|
127
132
|
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
133
|
];
|
|
129
134
|
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
135
|
return out.print([...head, rows.length ? table(rows, ["agent", "pool", "desired", "state", "thread", "sandbox", "model", "dir", "error", "last_turn"]) : " no sessions"].join("\n"), r);
|
|
131
136
|
}
|
|
137
|
+
if (action === "writable") {
|
|
138
|
+
const name = rest[0];
|
|
139
|
+
if (!name || rest.length < 2)
|
|
140
|
+
throw new CliError("usage", "machine writable <name> <path...> | none (folders sandboxed agents there may also write: toolchains, job runners; ~/ is the machine's home)");
|
|
141
|
+
const r = await c.call("PATCH", `/machines/${name}`, { writable: rest[1] === "none" ? [] : rest.slice(1) });
|
|
142
|
+
return out.print(`${name}: sandboxed agents may also write ${r.machine.writable.join(", ") || "(nothing extra)"}; its daemon restarts their watchers with it within 30 s.`, r);
|
|
143
|
+
}
|
|
132
144
|
if (action === "workdir") {
|
|
133
145
|
const [name, path] = rest;
|
|
134
146
|
if (!name || !path)
|
|
@@ -272,6 +284,23 @@ export async function projectRepoAdmin(rest, p, out) {
|
|
|
272
284
|
export function threadFileCommand(thread) {
|
|
273
285
|
return `f=$(ls ~/.codex/sessions/*/*/*/rollout-*${thread}.jsonl 2>/dev/null | head -1); [ -n "$f" ] || f=$(ls ~/.codex/archived_sessions/rollout-*${thread}.jsonl 2>/dev/null | head -1); [ -n "$f" ] || exit 4; b=$(basename "$f"); d=$(echo "$b" | sed -E 's#^rollout-([0-9]{4})-([0-9]{2})-([0-9]{2}).*#\\1/\\2/\\3#'); echo "$d/$b"; cat "$f"`;
|
|
274
286
|
}
|
|
287
|
+
/** The model and effort of a Codex thread's latest turn (its last `turn_context` line). */
|
|
288
|
+
export function lastTurnSettings(rollout) {
|
|
289
|
+
const lines = rollout.split("\n");
|
|
290
|
+
for (let i = lines.length - 1; i >= 0; i--) {
|
|
291
|
+
if (!lines[i].includes('"turn_context"'))
|
|
292
|
+
continue;
|
|
293
|
+
try {
|
|
294
|
+
const p = JSON.parse(lines[i]).payload ?? {};
|
|
295
|
+
return { model: p.model ?? null, effort: p.effort ?? null };
|
|
296
|
+
}
|
|
297
|
+
catch {
|
|
298
|
+
continue;
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
return { model: null, effort: null };
|
|
302
|
+
}
|
|
303
|
+
export const shellSingle = (s) => `'${s.replace(/'/g, `'\\''`)}'`;
|
|
275
304
|
/** Runs a shell command on `host` ("local" runs it here). */
|
|
276
305
|
function on(host, command, input) {
|
|
277
306
|
if (host === "local") {
|
|
@@ -331,8 +360,11 @@ export async function agentMove(rest, p, out) {
|
|
|
331
360
|
}
|
|
332
361
|
if (problems.length && !bool(p.flags, "force"))
|
|
333
362
|
throw new CliError("unpushed_work", `${ref} has work only on ${from}:\n ${problems.join("\n ")}`, "Have the agent push it (or commit and push), then move it; --force moves anyway and leaves that work there");
|
|
334
|
-
// 2. Its context
|
|
363
|
+
// 2. Its context, and the model it runs: a resumed thread without -m takes the new machine's
|
|
364
|
+
// default (fabricbios coordinator and luna-worker came up on ronald as gpt-6.1-terra low).
|
|
335
365
|
let thread = str(p.flags, "thread") ?? null;
|
|
366
|
+
let model = str(p.flags, "model");
|
|
367
|
+
let effort = str(p.flags, "effort");
|
|
336
368
|
if (carry === "thread") {
|
|
337
369
|
if (!thread) {
|
|
338
370
|
const map = on(from, "cat ~/.bschat/codex.json 2>/dev/null");
|
|
@@ -351,6 +383,9 @@ export async function agentMove(rest, p, out) {
|
|
|
351
383
|
throw new CliError("no_thread", `${from} has no session file for thread ${thread}`);
|
|
352
384
|
const nl = src.stdout.indexOf("\n");
|
|
353
385
|
const rel = src.stdout.slice(0, nl);
|
|
386
|
+
const last = lastTurnSettings(src.stdout.slice(nl + 1));
|
|
387
|
+
model ??= last.model ?? undefined;
|
|
388
|
+
effort ??= last.effort ?? undefined;
|
|
354
389
|
const toHost = str(p.flags, "to-ssh") ?? to;
|
|
355
390
|
const put = ssh(toHost, `mkdir -p ~/.codex/sessions/${JSON.stringify(rel.slice(0, rel.lastIndexOf("/")))} && cat > ~/.codex/sessions/${JSON.stringify(rel)}`, src.stdout.slice(nl + 1));
|
|
356
391
|
if (put.status !== 0)
|
|
@@ -371,11 +406,20 @@ export async function agentMove(rest, p, out) {
|
|
|
371
406
|
say(note ? ` resume note saved: ${note.title}` : ` no resume note within ${wait} min; it starts from its units, status and chat`);
|
|
372
407
|
}
|
|
373
408
|
}
|
|
409
|
+
if (!model || !effort) {
|
|
410
|
+
const st = ((await c.call("GET", `/projects/${project}/agents/status`)).statuses ?? []).find((s) => s.agent_name === agent);
|
|
411
|
+
if (!model && st?.model && st.model !== "unknown")
|
|
412
|
+
model = st.model;
|
|
413
|
+
if (!effort && st?.effort && st.effort !== "unknown")
|
|
414
|
+
effort = st.effort;
|
|
415
|
+
}
|
|
416
|
+
if (!model)
|
|
417
|
+
say(` no model known for ${ref}: it runs with the new machine's Codex default (pass --model to choose)`);
|
|
374
418
|
// 3. The new machine runs it; every other key stops working.
|
|
375
419
|
const turnTimeout = str(p.flags, "turn-timeout");
|
|
376
420
|
const r = await c.call("POST", `/machines/${to}/sessions`, {
|
|
377
421
|
project, agent, move: true, harness: str(p.flags, "harness") ?? "codex", dir: str(p.flags, "dir") ?? "auto", sandbox,
|
|
378
|
-
model
|
|
422
|
+
model, effort, ...(thread ? { thread } : {}), ...(turnTimeout ? { turn_timeout: Number(turnTimeout) } : {}),
|
|
379
423
|
});
|
|
380
424
|
return out.print([
|
|
381
425
|
`${ref} now runs on ${to} (${r.session.sandbox}, ${r.session.dir || "automatic checkout"}${thread ? `, thread ${thread}` : ", a fresh thread"}); its daemon starts it within 30 s.`,
|
package/dist/commands/machine.js
CHANGED
|
@@ -24,15 +24,16 @@ function writeMachineState(s) {
|
|
|
24
24
|
writeFileSync(stateFile(), JSON.stringify(s, null, 2) + "\n");
|
|
25
25
|
}
|
|
26
26
|
/** What a session's watcher is started with; a change means re-running codex start. The thread is compared separately. */
|
|
27
|
-
export const sessionFingerprint = (s) => JSON.stringify([s.harness, s.dir, s.sandbox, s.model, s.effort, s.turn_timeout]);
|
|
27
|
+
export const sessionFingerprint = (s, writable = []) => JSON.stringify([s.harness, s.dir, s.sandbox, s.model, s.effort, s.turn_timeout, ...(writable.length ? [writable] : [])]);
|
|
28
28
|
export const watchLabelOf = (ref) => `${WATCH_LABEL_PREFIX}${ref.replace("/", ".")}`;
|
|
29
29
|
/** The `bschat codex start` arguments that bring a session up (adopting its thread when known). */
|
|
30
|
-
export function startArgs(s, thread) {
|
|
30
|
+
export function startArgs(s, thread, writable = []) {
|
|
31
31
|
return [
|
|
32
32
|
"codex", "start", "--as", s.agent, "--sandbox", s.sandbox, "--turn-timeout", String(s.turn_timeout), "--json",
|
|
33
33
|
...(s.model ? ["--model", s.model] : []),
|
|
34
34
|
...(s.effort ? ["--effort", s.effort] : []),
|
|
35
35
|
...(thread ? ["--thread", thread] : []),
|
|
36
|
+
...(writable.length && s.sandbox === "workspace-write" ? ["--writable", writable.join(",")] : []),
|
|
36
37
|
];
|
|
37
38
|
}
|
|
38
39
|
const KEY_CHECK_MS = 10 * 60_000;
|
|
@@ -42,6 +43,7 @@ export async function reconcile(m, log) {
|
|
|
42
43
|
const me = await client.call("GET", "/machines/me");
|
|
43
44
|
const desired = me.sessions;
|
|
44
45
|
const workdir = me.machine?.workdir ?? null;
|
|
46
|
+
const writable = me.machine?.writable ?? [];
|
|
45
47
|
const state = readMachineState();
|
|
46
48
|
const bin = requireInstall().bin;
|
|
47
49
|
const out = [];
|
|
@@ -74,11 +76,11 @@ export async function reconcile(m, log) {
|
|
|
74
76
|
throw new Error(`checkout ${s.dir} does not exist on this machine`);
|
|
75
77
|
const local = state.sessions[s.id];
|
|
76
78
|
await ensureCredentials(client, m, s, local, log);
|
|
77
|
-
const fp = sessionFingerprint(s);
|
|
79
|
+
const fp = sessionFingerprint(s, s.sandbox === "workspace-write" ? writable : []);
|
|
78
80
|
const thread = s.thread ?? local?.thread ?? null;
|
|
79
81
|
const threadChanged = !!local?.thread && !!s.thread && s.thread !== local.thread;
|
|
80
82
|
if (!svc() || !local || local.fingerprint !== fp || threadChanged) {
|
|
81
|
-
const r = spawnSync(bin, startArgs(s, thread), { cwd: s.dir, encoding: "utf8", timeout: 180_000 });
|
|
83
|
+
const r = spawnSync(bin, startArgs(s, thread, writable), { cwd: s.dir, encoding: "utf8", timeout: 180_000 });
|
|
82
84
|
if (r.status !== 0)
|
|
83
85
|
throw new Error(`codex start failed: ${errorText(r.stderr || r.stdout)}`);
|
|
84
86
|
const started = JSON.parse(r.stdout);
|
package/dist/help.js
CHANGED
|
@@ -215,6 +215,7 @@ Machines (provisioned over your own ssh; a daemon on each runs the agent session
|
|
|
215
215
|
--from), carries its context as a resume note or its Codex thread, revokes other keys
|
|
216
216
|
bschat-admin machine label <name> <label...> [--remove a,b] what cannot be measured (lab-lan, builds); pools' --needs match it
|
|
217
217
|
bschat-admin machine slots <name> <n | auto> how many sessions it takes (auto: one per 4 GB of RAM)
|
|
218
|
+
bschat-admin machine writable <name> <path...> | none folders workspace-write agents there may also write (~/.cargo, ~/.ester)
|
|
218
219
|
bschat-admin machine workdir <name> <path | default> where its daemon clones projects for pool sessions (default ~/bschat)
|
|
219
220
|
|
|
220
221
|
Pools (a role, variants and a count; the server names the agents and places them on machines)
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const CLI_VERSION = "0.12.
|
|
1
|
+
export const CLI_VERSION = "0.12.62";
|