benignswarm 0.12.60 → 0.12.61

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 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
- const settings = codexSettings(sandbox, model, effort, process.cwd(), configRoot());
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
  }
@@ -123,12 +123,19 @@ export async function machineAdmin(action, rest, p, out) {
123
123
  const m = r.machine;
124
124
  const rep = m.report ?? {};
125
125
  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)` : ""}`,
126
+ `${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
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);
131
131
  }
132
+ if (action === "writable") {
133
+ const name = rest[0];
134
+ if (!name || rest.length < 2)
135
+ throw new CliError("usage", "machine writable <name> <path...> | none (folders sandboxed agents there may also write: toolchains, job runners; ~/ is the machine's home)");
136
+ const r = await c.call("PATCH", `/machines/${name}`, { writable: rest[1] === "none" ? [] : rest.slice(1) });
137
+ 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);
138
+ }
132
139
  if (action === "workdir") {
133
140
  const [name, path] = rest;
134
141
  if (!name || !path)
@@ -272,6 +279,22 @@ export async function projectRepoAdmin(rest, p, out) {
272
279
  export function threadFileCommand(thread) {
273
280
  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
281
  }
282
+ /** The model and effort of a Codex thread's latest turn (its last `turn_context` line). */
283
+ export function lastTurnSettings(rollout) {
284
+ const lines = rollout.split("\n");
285
+ for (let i = lines.length - 1; i >= 0; i--) {
286
+ if (!lines[i].includes('"turn_context"'))
287
+ continue;
288
+ try {
289
+ const p = JSON.parse(lines[i]).payload ?? {};
290
+ return { model: p.model ?? null, effort: p.effort ?? null };
291
+ }
292
+ catch {
293
+ continue;
294
+ }
295
+ }
296
+ return { model: null, effort: null };
297
+ }
275
298
  /** Runs a shell command on `host` ("local" runs it here). */
276
299
  function on(host, command, input) {
277
300
  if (host === "local") {
@@ -331,8 +354,11 @@ export async function agentMove(rest, p, out) {
331
354
  }
332
355
  if (problems.length && !bool(p.flags, "force"))
333
356
  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.
357
+ // 2. Its context, and the model it runs: a resumed thread without -m takes the new machine's
358
+ // default (fabricbios coordinator and luna-worker came up on ronald as gpt-6.1-terra low).
335
359
  let thread = str(p.flags, "thread") ?? null;
360
+ let model = str(p.flags, "model");
361
+ let effort = str(p.flags, "effort");
336
362
  if (carry === "thread") {
337
363
  if (!thread) {
338
364
  const map = on(from, "cat ~/.bschat/codex.json 2>/dev/null");
@@ -351,6 +377,9 @@ export async function agentMove(rest, p, out) {
351
377
  throw new CliError("no_thread", `${from} has no session file for thread ${thread}`);
352
378
  const nl = src.stdout.indexOf("\n");
353
379
  const rel = src.stdout.slice(0, nl);
380
+ const last = lastTurnSettings(src.stdout.slice(nl + 1));
381
+ model ??= last.model ?? undefined;
382
+ effort ??= last.effort ?? undefined;
354
383
  const toHost = str(p.flags, "to-ssh") ?? to;
355
384
  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
385
  if (put.status !== 0)
@@ -371,11 +400,20 @@ export async function agentMove(rest, p, out) {
371
400
  say(note ? ` resume note saved: ${note.title}` : ` no resume note within ${wait} min; it starts from its units, status and chat`);
372
401
  }
373
402
  }
403
+ if (!model || !effort) {
404
+ const st = ((await c.call("GET", `/projects/${project}/agents/status`)).statuses ?? []).find((s) => s.agent_name === agent);
405
+ if (!model && st?.model && st.model !== "unknown")
406
+ model = st.model;
407
+ if (!effort && st?.effort && st.effort !== "unknown")
408
+ effort = st.effort;
409
+ }
410
+ if (!model)
411
+ say(` no model known for ${ref}: it runs with the new machine's Codex default (pass --model to choose)`);
374
412
  // 3. The new machine runs it; every other key stops working.
375
413
  const turnTimeout = str(p.flags, "turn-timeout");
376
414
  const r = await c.call("POST", `/machines/${to}/sessions`, {
377
415
  project, agent, move: true, harness: str(p.flags, "harness") ?? "codex", dir: str(p.flags, "dir") ?? "auto", sandbox,
378
- model: str(p.flags, "model"), effort: str(p.flags, "effort"), ...(thread ? { thread } : {}), ...(turnTimeout ? { turn_timeout: Number(turnTimeout) } : {}),
416
+ model, effort, ...(thread ? { thread } : {}), ...(turnTimeout ? { turn_timeout: Number(turnTimeout) } : {}),
379
417
  });
380
418
  return out.print([
381
419
  `${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.`,
@@ -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.60";
1
+ export const CLI_VERSION = "0.12.61";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "benignswarm",
3
- "version": "0.12.60",
3
+ "version": "0.12.61",
4
4
  "description": "bschat: chat, status board and evidence store for coding agents (benignswarm.org)",
5
5
  "license": "UNLICENSED",
6
6
  "repository": {