benignswarm 0.12.55 → 0.12.56

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.
@@ -1,9 +1,9 @@
1
1
  import { spawn, spawnSync } from "node:child_process";
2
2
  import { closeSync, existsSync, mkdirSync, openSync, readFileSync } from "node:fs";
3
3
  import { homedir } from "node:os";
4
- import { join as joinPath } from "node:path";
4
+ import { dirname, join as joinPath } from "node:path";
5
5
  import { bool, str } from "../args.js";
6
- import { agentRef, loadAgent } from "../config.js";
6
+ import { agentRef, configRoot, loadAgent } from "../config.js";
7
7
  import { CliError } from "../errors.js";
8
8
  import { requireInstall } from "../install.js";
9
9
  import { bindSession, codexArchivedRollout, codexRollout } from "../sessions.js";
@@ -57,12 +57,7 @@ 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 = [
61
- ...(model ? ["-m", model] : []),
62
- ...(effort ? ["-c", `model_reasoning_effort="${effort}"`] : []),
63
- "-c", `sandbox_mode="${sandbox}"`,
64
- "-c", `approval_policy="never"`,
65
- ];
60
+ const settings = codexSettings(sandbox, model, effort, process.cwd(), configRoot());
66
61
  let thread;
67
62
  let firstTurnLog = null;
68
63
  if (adopt) {
@@ -103,6 +98,22 @@ export async function codexStart(p, out) {
103
98
  lines.push(`If the Codex account hits its usage limit, the watcher pauses turns until the time Codex gives; after switching to an account with quota, resume at once: bschat codex unpause --as ${ref}`);
104
99
  out.print(lines.join("\n"), { agent: ref, thread, sandbox, model: model ?? null, effort: effort ?? null, exec, first_turn_log: firstTurnLog, untrusted_hooks: missing });
105
100
  }
101
+ /**
102
+ * The Codex settings a headless turn runs with. Under workspace-write the agent still has to reach
103
+ * the API and write its own bschat state (~/.bschat), and `wu start` puts unit worktrees beside the
104
+ * checkout, so those two places are writable and the network is on; nothing else is.
105
+ */
106
+ export function codexSettings(sandbox, model, effort, cwd, bschatHome) {
107
+ return [
108
+ ...(model ? ["-m", model] : []),
109
+ ...(effort ? ["-c", `model_reasoning_effort="${effort}"`] : []),
110
+ "-c", `sandbox_mode="${sandbox}"`,
111
+ "-c", `approval_policy="never"`,
112
+ ...(sandbox === "workspace-write"
113
+ ? ["-c", "sandbox_workspace_write.network_access=true", "-c", `sandbox_workspace_write.writable_roots=${JSON.stringify([bschatHome, dirname(cwd)])}`]
114
+ : []),
115
+ ];
116
+ }
106
117
  /** Starts a headless Codex session in its own process group and returns its thread id from the JSON event stream. */
107
118
  async function startThread(codexBin, args, logPath, agent) {
108
119
  const fd = openSync(logPath, "a");
@@ -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"}`,
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
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?)",
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 === "workdir") {
133
+ const [name, path] = rest;
134
+ if (!name || !path)
135
+ throw new CliError("usage", "machine workdir <name> <absolute path | default> (where its daemon clones projects and makes agent worktrees; default ~/bschat)");
136
+ const r = await c.call("PATCH", `/machines/${name}`, { workdir: path === "default" ? null : path });
137
+ return out.print(`${name}: pool checkouts go to ${r.machine.workdir ?? "~/bschat"} from its next pass (existing checkouts stay where they are).`, r);
138
+ }
132
139
  if (action === "label" || action === "slots") {
133
140
  const name = rest[0];
134
141
  if (!name)
@@ -38,7 +38,9 @@ const KEY_CHECK_MS = 10 * 60_000;
38
38
  /** One pass: make what runs here match what the operator declared, then report. */
39
39
  export async function reconcile(m, log) {
40
40
  const client = Client.raw(m.url, m.key);
41
- const desired = (await client.call("GET", "/machines/me")).sessions;
41
+ const me = await client.call("GET", "/machines/me");
42
+ const desired = me.sessions;
43
+ const workdir = me.machine?.workdir ?? null;
42
44
  const state = readMachineState();
43
45
  const bin = requireInstall().bin;
44
46
  const out = [];
@@ -60,7 +62,7 @@ export async function reconcile(m, log) {
60
62
  throw new Error(`harness ${s.harness} is not supported by this bschat ${CLI_VERSION}`);
61
63
  if (!s.dir) {
62
64
  // A pool session: the daemon makes the checkout (clone once per machine, a worktree per agent).
63
- const c = ensureCheckout(s, log);
65
+ const c = ensureCheckout(s, log, workdir);
64
66
  if ("preparing" in c) {
65
67
  out.push({ id: s.id, state: "preparing", detail: c.preparing });
66
68
  continue;
@@ -111,7 +113,7 @@ export async function reconcile(m, log) {
111
113
  delete state.sessions[id];
112
114
  }
113
115
  writeMachineState(state);
114
- const report = machineFacts();
116
+ const report = { ...machineFacts(), workdir: workdir ?? join(homedir(), "bschat"), workdir_free_bytes: freeBytes(workdir ?? homedir()) };
115
117
  await client.call("POST", "/machines/me/report", { report, sessions: out });
116
118
  return { sessions: out, report };
117
119
  }
@@ -123,12 +125,14 @@ const git = (args, cwd) => spawnSync("git", args, { cwd, encoding: "utf8", timeo
123
125
  * target with wu start). An identity file makes plain `bschat` there the agent; `.bschat/` is ignored
124
126
  * through the clone's info/exclude, so no tracked file changes.
125
127
  */
126
- export function ensureCheckout(s, log) {
128
+ export function ensureCheckout(s, log, workdir = null) {
127
129
  if (!s.project)
128
130
  throw new Error("an automatic checkout needs a project agent");
129
131
  if (!s.repo_url)
130
132
  throw new Error(`project ${s.project} has no repository URL: bschat-admin project repo ${s.project} <git url>`);
131
- const root = join(homedir(), "bschat", s.project);
133
+ if (workdir && !existsSync(workdir))
134
+ mkdirSync(workdir, { recursive: true });
135
+ const root = join(workdir ?? join(homedir(), "bschat"), s.project);
132
136
  const base = join(root, "main");
133
137
  const marker = join(root, ".cloning");
134
138
  if (!existsSync(join(base, ".git"))) {
@@ -224,6 +228,15 @@ function lastTurnLine(ref) {
224
228
  const lines = readFileSync(f, "utf8").split("\n").filter((l) => /bschat watch\[/.test(l) && /turn #|TURN #|usage limit|pause lifted/.test(l));
225
229
  return lines.length ? lines[lines.length - 1].slice(0, 300) : null;
226
230
  }
231
+ function freeBytes(path) {
232
+ try {
233
+ const st = statfsSync(existsSync(path) ? path : dirname(path));
234
+ return st.bavail * st.bsize;
235
+ }
236
+ catch {
237
+ return null;
238
+ }
239
+ }
227
240
  /** What the operator needs to know about this machine, reported with every pass. */
228
241
  export function machineFacts() {
229
242
  const codex = spawnSync("codex", ["--version"], { encoding: "utf8" });
package/dist/help.js CHANGED
@@ -206,6 +206,7 @@ Machines (provisioned over your own ssh; a daemon on each runs the agent session
206
206
  bschat-admin machine session stop|start|remove <machine> <project>/<agent>
207
207
  bschat-admin machine label <name> <label...> [--remove a,b] what cannot be measured (lab-lan, builds); pools' --needs match it
208
208
  bschat-admin machine slots <name> <n | auto> how many sessions it takes (auto: one per 4 GB of RAM)
209
+ bschat-admin machine workdir <name> <path | default> where its daemon clones projects for pool sessions (default ~/bschat)
209
210
 
210
211
  Pools (a role, variants and a count; the server names the agents and places them on machines)
211
212
  bschat-admin project repo <project> <git url | none> what machines clone for the project's pool sessions
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const CLI_VERSION = "0.12.55";
1
+ export const CLI_VERSION = "0.12.56";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "benignswarm",
3
- "version": "0.12.55",
3
+ "version": "0.12.56",
4
4
  "description": "bschat: chat, status board and evidence store for coding agents (benignswarm.org)",
5
5
  "license": "UNLICENSED",
6
6
  "repository": {