benignswarm 0.12.73 → 0.12.75

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
@@ -3,8 +3,8 @@ import { CliError } from "./errors.js";
3
3
  // These options accept comma-separated collections, so repeating them should
4
4
  // append another collection instead of discarding earlier values.
5
5
  export const LIST_FLAGS = ["tags", "projects", "evidence", "statuses", "depends-on", "units", "waits-on", "needs", "exclude", "remove", "post", "harness", "variant"];
6
- 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", "session", "plain", "if-yes", "if-no", "ssh", "variant", "count", "needs", "min-ram", "exclude", "carry", "from", "to-ssh", "wait", "writable", "for", "until", "reason"];
7
- 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", "bwrap-userns", "print-apparmor"];
6
+ 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", "session", "plain", "if-yes", "if-no", "ssh", "variant", "count", "needs", "min-ram", "exclude", "carry", "from", "to-ssh", "wait", "writable", "for", "until", "reason", "at", "priority"];
7
+ 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", "bwrap-userns", "print-apparmor", "cancel"];
8
8
  export function parse(argv) {
9
9
  const options = {};
10
10
  for (const f of STRING_FLAGS)
@@ -134,6 +134,22 @@ export async function machineAdmin(action, rest, p, out) {
134
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\[[^\]]+\]: /, "") }));
135
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);
136
136
  }
137
+ if (action === "maintenance") {
138
+ // A window on the machine: no new turns from 15 min before, its agents away until it ends.
139
+ const name = rest[0];
140
+ const usage = "machine maintenance <name> --at <ISO time | HH:MM local> --for <minutes | 30m | 2h> | --cancel";
141
+ if (!name)
142
+ throw new CliError("usage", usage);
143
+ if (bool(p.flags, "cancel"))
144
+ return out.print(`${name}: maintenance cancelled; its agents are back and turns start again.`, await c.call("DELETE", `/machines/${name}/maintenance`));
145
+ const at = str(p.flags, "at");
146
+ const len = str(p.flags, "for");
147
+ if (!at || !len)
148
+ throw new CliError("usage", usage);
149
+ const r = await c.call("PUT", `/machines/${name}/maintenance`, { start: maintenanceStart(at).toISOString(), minutes: durationMinutes(len) });
150
+ const w = r.maintenance;
151
+ return out.print(`${name}: maintenance ${w.start.slice(0, 16).replace("T", " ")} to ${w.end.slice(11, 16)} UTC (${w.phase}). No new turns start there from 15 min before; its agents are away until it ends, which happens when the machine reports after booting or at the end time. Projects with agents there were told.`, r);
152
+ }
137
153
  if (action === "writable") {
138
154
  const name = rest[0];
139
155
  if (!name || rest.length < 2)
@@ -431,3 +447,29 @@ export async function agentMove(rest, p, out) {
431
447
  `Follow it: bschat-admin machine show ${to}`,
432
448
  ].filter(Boolean).join("\n"), r);
433
449
  }
450
+ /** --at: an ISO timestamp, or HH:MM in this machine's local time (today, or tomorrow when past). */
451
+ export function maintenanceStart(at, nowMs = Date.now()) {
452
+ const hm = /^(\d{1,2}):(\d{2})$/.exec(at);
453
+ if (hm) {
454
+ const d = new Date(nowMs);
455
+ d.setHours(Number(hm[1]), Number(hm[2]), 0, 0);
456
+ if (d.getTime() < nowMs - 60_000)
457
+ d.setDate(d.getDate() + 1);
458
+ return d;
459
+ }
460
+ if (at === "now")
461
+ return new Date(nowMs);
462
+ const t = Date.parse(at);
463
+ if (Number.isNaN(t))
464
+ throw new CliError("usage", `--at ${at}: an ISO timestamp, HH:MM (local time) or now`);
465
+ return new Date(t);
466
+ }
467
+ /** --for: minutes as a number, or 30m / 2h / 1h30m. */
468
+ export function durationMinutes(v) {
469
+ if (/^\d+$/.test(v))
470
+ return Number(v);
471
+ const m = /^(?:(\d+)h)?(?:(\d+)m)?$/.exec(v);
472
+ if (!m || (!m[1] && !m[2]))
473
+ throw new CliError("usage", `--for ${v}: minutes, or a duration like 30m, 2h, 1h30m`);
474
+ return Number(m[1] ?? 0) * 60 + Number(m[2] ?? 0);
475
+ }
@@ -1,6 +1,6 @@
1
1
  import { spawn, spawnSync } from "node:child_process";
2
2
  import { closeSync, existsSync, mkdirSync, openSync, readFileSync, readSync, statSync, statfsSync, writeFileSync } from "node:fs";
3
- import { arch, cpus, freemem, homedir, hostname, loadavg, platform, totalmem, userInfo } from "node:os";
3
+ import { arch, cpus, freemem, homedir, hostname, loadavg, platform, totalmem, uptime, userInfo } from "node:os";
4
4
  import { dirname, join } from "node:path";
5
5
  import { str } from "../args.js";
6
6
  import { Client } from "../client.js";
@@ -8,6 +8,7 @@ import { configRoot, loadAgent, saveAgent } from "../config.js";
8
8
  import { CliError } from "../errors.js";
9
9
  import { BWRAP_APPARMOR_PATH, bwrapAppArmorProfile, CODEX_APPARMOR_PATH, CODEX_MANAGED_DIR, CODEX_MANAGED_MARK, codexAppArmorProfile, codexManagedHooks } from "../harness.js";
10
10
  import { applySparse } from "../git.js";
11
+ import { drainingUntil, writeMaintenance } from "../maintenance.js";
11
12
  import { TURN_HARNESSES, claudeFacts, claudeSandbox, probeFor, sessionProcesses } from "../harnesses.js";
12
13
  import { readState, writeState } from "../state.js";
13
14
  import { installService, lingerEnabled, MACHINE_LABEL, removeService, requireInstall, restartWatcher, serviceActive, WATCH_LABEL_PREFIX, watcherServices } from "../install.js";
@@ -34,6 +35,20 @@ function writeMachineState(s) {
34
35
  const START_REV = 3;
35
36
  export const sessionFingerprint = (s, writable = []) => JSON.stringify([s.harness, s.dir, s.sandbox, s.model, s.effort, s.turn_timeout, ...(writable.length ? [writable] : []), ...(START_REV > 1 ? [`rev${START_REV}`] : [])]);
36
37
  export const watchLabelOf = (ref) => `${WATCH_LABEL_PREFIX}${ref.replace("/", ".")}`;
38
+ /**
39
+ * During a maintenance drain or window, a session that would be started fresh (no known thread, so
40
+ * `bschat start` runs its first turn at once, past the watchers' check) waits; adopting a known
41
+ * thread starts no turn and proceeds. Returns the session's report while it waits, else null.
42
+ */
43
+ export function deferredByMaintenance(s, thread, drain) {
44
+ if (!drain || thread)
45
+ return null;
46
+ return { id: s.id, state: "preparing", dir: s.dir, detail: `maintenance until ${drain.end.slice(11, 16)} UTC: its first turn starts after it` };
47
+ }
48
+ /** The daemon's confirmation that it holds new turns back, with the turns still running. */
49
+ export function maintenanceReport(drain, sessions) {
50
+ return drain ? { draining: true, until: drain.end, turns_running: sessions.filter((o) => o.turn?.running).length } : null;
51
+ }
37
52
  /** The `bschat start` arguments that bring a session up (adopting its thread or session when known). */
38
53
  export function startArgs(s, thread, writable = []) {
39
54
  return [
@@ -52,6 +67,9 @@ export async function reconcile(m, log) {
52
67
  const desired = me.sessions;
53
68
  const workdir = me.machine?.workdir ?? null;
54
69
  const writable = me.machine?.writable ?? [];
70
+ // The maintenance window, for the watchers: they start no new turns while it drains or runs.
71
+ const mw = me.machine?.maintenance;
72
+ writeMaintenance(mw ? { start: mw.start, end: mw.end } : null);
55
73
  const state = readMachineState();
56
74
  const bin = requireInstall().bin;
57
75
  const out = [];
@@ -88,6 +106,15 @@ export async function reconcile(m, log) {
88
106
  const thread = s.thread ?? local?.thread ?? null;
89
107
  const threadChanged = !!local?.thread && !!s.thread && s.thread !== local.thread;
90
108
  if (!svc() || !local || local.fingerprint !== fp || threadChanged) {
109
+ // A new session's start runs its first turn at once, past the watchers' check: during a
110
+ // maintenance window it waits. (Adopting a known thread starts no turn, so that proceeds.)
111
+ // The phase is read at the launch decision itself: credential checks and checkouts before
112
+ // it can take long enough to cross the drain point (sol-reviewer's boundary probe).
113
+ const held = deferredByMaintenance(s, thread, drainingUntil());
114
+ if (held) {
115
+ out.push(held);
116
+ continue;
117
+ }
91
118
  const r = spawnSync(bin, startArgs(s, thread, writable), { cwd: s.dir, encoding: "utf8", timeout: 180_000 });
92
119
  if (r.status !== 0)
93
120
  throw new Error(`bschat start failed: ${errorText(r.stderr || r.stdout)}`);
@@ -139,7 +166,11 @@ export async function reconcile(m, log) {
139
166
  }
140
167
  writeMachineState(state);
141
168
  const clones = refreshClones(workdir, [...new Set(desired.filter((s) => !s.dir && s.project && s.desired === "running").map((s) => s.project))], log);
142
- const report = { ...machineFacts(), workdir: workdir ?? join(homedir(), "bschat"), workdir_free_bytes: freeBytes(workdir ?? homedir()), clones };
169
+ const report = {
170
+ ...machineFacts(), workdir: workdir ?? join(homedir(), "bschat"), workdir_free_bytes: freeBytes(workdir ?? homedir()), clones,
171
+ // The daemon's own confirmation that it is holding turns back, and how many are still running.
172
+ maintenance: maintenanceReport(drainingUntil(), out),
173
+ };
143
174
  await client.call("POST", "/machines/me/report", { report, sessions: out });
144
175
  return { sessions: out, report };
145
176
  }
@@ -427,6 +458,8 @@ export function machineFacts() {
427
458
  return {
428
459
  os: platform(), arch: arch(), hostname: hostname(), user: userInfo().username, cpus: cpus().length, mem_total_bytes: totalmem(),
429
460
  load: loadavg().map((x) => Math.round(x * 100) / 100), mem_available_bytes: memAvailable(),
461
+ // When this machine last booted: the server ends a maintenance window once the machine is back.
462
+ booted_at: new Date(Math.floor((Date.now() - uptime() * 1000) / 60_000) * 60_000).toISOString(),
430
463
  bschat: { version: CLI_VERSION, bin: requireInstall().bin },
431
464
  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,
432
465
  "claude-code": claudeReport(),
@@ -1,6 +1,7 @@
1
1
  import { spawn, spawnSync } from "node:child_process";
2
2
  import { bindSession, sessionOfExec, threadOfExec } from "../sessions.js";
3
3
  import { startTurn, stopTurn } from "../turn.js";
4
+ import { drainingUntil } from "../maintenance.js";
4
5
  import { probeFor, turnHarness } from "../harnesses.js";
5
6
  import { applyAck } from "./wake.js";
6
7
  import { lingerEnabled, loadSystemdUnit, reloadLaunchAgent, removeService, requireInstall, systemdUnit, systemdUserDir, WATCH_LABEL_PREFIX, watcherServices } from "../install.js";
@@ -470,6 +471,14 @@ async function turnStep(ctl, probe, timeoutMin, log, wake, name) {
470
471
  log(`the turn started at ${ph.startedAt} has written nothing for ${Math.round(quietMs / 60_000)} min (over the ${timeoutMin}-min limit); treating it as dead`);
471
472
  ctl.loggedRunning = ph.startedAt;
472
473
  }
474
+ // A maintenance window on this machine: no new turn from 15 min before it until it ends.
475
+ const maint = drainingUntil();
476
+ if (maint) {
477
+ if (ctl.loggedRunning !== `maint:${maint.start}`)
478
+ log(`maintenance on this machine ${maint.start.slice(0, 16)} to ${maint.end.slice(11, 16)} UTC: starting no new turns until it ends`);
479
+ ctl.loggedRunning = `maint:${maint.start}`;
480
+ return;
481
+ }
473
482
  const st = readState(name);
474
483
  if (st.watch_pending) {
475
484
  // Queued by a queue-mode watcher and never delivered, or failed: no turn is running, so the agent is not going to answer it.
@@ -81,6 +81,7 @@ export async function wu(p, out) {
81
81
  return [
82
82
  `WU #${u.number} [${u.status}] ${tags(u)} ${u.title}${flags ? ` (${flags})` : ""}`,
83
83
  ` owner ${u.owner_name || "unassigned (queued)"}${reviewers ? ` · reviewers ${reviewers}` : ""}${approvals ? ` · approved by ${approvals}` : ""}${u.uncovered?.length ? ` · awaiting ${u.uncovered.map((t) => `#${t}`).join(" ")}` : ""}`,
84
+ u.operator_hold ? ` ON HOLD by ${u.operator_hold.by}: ${u.operator_hold.note} (no verdict and no merge until the owner resubmits or it is released)` : null,
84
85
  u.question ? ` QUESTION for ${u.question.level === "expert" ? `a ${u.question.roles.join(" or ")}` : "the operator"} (asked by ${u.question.asked_by}${u.question.passed_by ? `, passed up by ${u.question.passed_by}` : ""}): ${u.question.text}` : null,
85
86
  ` ${u.branch ? `${u.branch}${u.head ? ` @ ${u.head}` : ""}` : "no branch recorded"}${u.worktree ? ` in ${u.worktree.replace(/^\/(Users|home)\/[^/]+\//, "~/")}` : ""}${u.pr_url ? ` · ${u.pr_url}` : ""}${u.merged_sha ? ` · merged ${u.merged_sha}` : ""}${u.evidence.length ? ` · evidence ${u.evidence.map((e) => `evidence:${e}`).join(" ")}` : ""}`,
86
87
  u.scope ? ` scope: ${u.scope}` : null,
@@ -233,6 +234,20 @@ export async function wu(p, out) {
233
234
  out.print(fmt(r.unit), r);
234
235
  return;
235
236
  }
237
+ case "hold": {
238
+ // Operator or assigner: no verdict and no merge until the owner resubmits or the hold is released.
239
+ const note = str(p.flags, "note");
240
+ if (!note)
241
+ throw new CliError("usage", 'wu hold <n> --note "what must happen before it moves on" (operator or assigner)');
242
+ const r = await client.call("POST", `${base}/${num()}/hold`, { note });
243
+ out.print(`${fmt(r.unit)}\nOn hold: verdicts and done are refused until ${r.unit.owner_name} resubmits or you run bschat wu release ${num()}.`, r);
244
+ return;
245
+ }
246
+ case "release": {
247
+ const r = await client.call("POST", `${base}/${num()}/hold/release`, { note: str(p.flags, "note") ?? "" });
248
+ out.print(`${fmt(r.unit)}\nHold released.`, r);
249
+ return;
250
+ }
236
251
  case "scope": {
237
252
  const scope = str(p.flags, "scope");
238
253
  const note = str(p.flags, "note");
@@ -523,7 +538,7 @@ export async function milestones(p, out) {
523
538
  */
524
539
  export async function milestonesWith(client, project, sub, p, out) {
525
540
  if (sub === "export") {
526
- const list = (await client.call("GET", `/projects/${project}/milestones`)).milestones.map((m) => ({ key: m.key, title: m.title, exit: m.exit, ...(m.source ? { source: m.source } : {}), depends_on: m.depends_on }));
541
+ const list = (await client.call("GET", `/projects/${project}/milestones`)).milestones.map((m) => ({ key: m.key, title: m.title, exit: m.exit, ...(m.source ? { source: m.source } : {}), depends_on: m.depends_on, ...(m.priority !== null && m.priority !== undefined ? { priority: m.priority } : {}) }));
527
542
  const text = JSON.stringify(list, null, 2) + "\n";
528
543
  const file = str(p.flags, "out");
529
544
  if (file) {
@@ -551,8 +566,8 @@ export async function milestonesWith(client, project, sub, p, out) {
551
566
  return;
552
567
  }
553
568
  const r = await client.call("GET", `/projects/${project}/milestones`);
554
- const rows = r.milestones.map((m) => ({ key: m.key, status: m.status === "open" ? (m.ready ? "ready" : `waits on ${m.waiting_on.join(",")}`) : m.status, units: `${m.units.done}/${m.units.total}${m.units.queued ? ` (+${m.units.queued} queued)` : ""}`, "depends on": m.depends_on.join(",") || "-", title: m.title.slice(0, 50) }));
555
- out.print(rows.length ? `${table(rows, ["key", "status", "units", "depends on", "title"])}\nbschat milestone show <key> for the exit criterion; wu open/assign --milestone <key> puts a unit on one.` : "(no milestones defined; the operator defines them on the Process page or with bschat-admin milestones <project> set --file plan.json, an assigner with bschat milestones set --file plan.json)", r);
569
+ const rows = r.milestones.map((m) => ({ key: m.key, priority: m.priority ?? "-", status: m.status === "open" ? (m.ready ? "ready" : `waits on ${m.waiting_on.join(",")}`) : m.status, units: `${m.units.done}/${m.units.total}${m.units.queued ? ` (+${m.units.queued} queued)` : ""}`, "depends on": m.depends_on.join(",") || "-", title: m.title.slice(0, 50) }));
570
+ out.print(rows.length ? `${table(rows, ["key", "priority", "status", "units", "depends on", "title"])}\nbschat milestone show <key> for the exit criterion; wu open/assign --milestone <key> puts a unit on one.` : "(no milestones defined; the operator defines them on the Process page or with bschat-admin milestones <project> set --file plan.json, an assigner with bschat milestones set --file plan.json)", r);
556
571
  }
557
572
  /** milestone show <key> | milestone close <key> --note ".." [--evidence a,b] [--abandon | --defer] | milestone reopen <key> */
558
573
  export async function milestone(p, out) {
@@ -568,6 +583,9 @@ export async function milestone(p, out) {
568
583
  export async function milestoneWith(client, project, sub, key, p, out) {
569
584
  if (!key)
570
585
  throw new CliError("usage", 'milestone show <key> | milestone close <key> --note "how the exit criterion was met" [--evidence id,id] [--abandon | --defer] | milestone reopen <key>');
586
+ // "set" is "edit" (bschat milestone set <key> --priority 5): one slice changed, the rest untouched.
587
+ if (sub === "set")
588
+ sub = "edit";
571
589
  if (sub === "add" || sub === "edit") {
572
590
  // One slice in, the rest untouched: fetch the list, add or amend the entry, set it back.
573
591
  const cur = (await client.call("GET", `/projects/${project}/milestones`)).milestones;
@@ -578,15 +596,20 @@ export async function milestoneWith(client, project, sub, key, p, out) {
578
596
  throw new CliError("not_found", `no milestone ${key}; use milestone add ${key} --title "..."`);
579
597
  const title = str(p.flags, "title") ?? existing?.title;
580
598
  if (!title)
581
- throw new CliError("usage", 'milestone add <key> --title "..." [--exit "what done means"] [--source "docs/plan.md#section"] [--depends-on a,b] (no exit and no dependencies = a container for ongoing work)');
599
+ throw new CliError("usage", 'milestone add <key> --title "..." [--exit "what done means"] [--source "docs/plan.md#section"] [--depends-on a,b] [--priority n|none] (no exit and no dependencies = a container for ongoing work)');
582
600
  const deps = str(p.flags, "depends-on") !== undefined ? (str(p.flags, "depends-on") ?? "").split(",").map((s) => s.trim()).filter(Boolean) : existing?.depends_on ?? [];
583
601
  const exit = str(p.flags, "exit") ?? existing?.exit ?? "";
584
602
  const source = str(p.flags, "source") ?? existing?.source ?? "";
585
- const next = cur.map((m) => ({ key: m.key, title: m.title, exit: m.exit, source: m.source ?? "", depends_on: m.depends_on }));
603
+ // --priority <n> (higher first) or none; the steward asks for units only on the highest-priority ready slices.
604
+ const pr = str(p.flags, "priority");
605
+ if (pr !== undefined && pr !== "none" && !/^-?\d+$/.test(pr))
606
+ throw new CliError("usage", "--priority takes a whole number (higher first) or none");
607
+ const priority = pr === undefined ? existing?.priority ?? null : pr === "none" ? null : Number(pr);
608
+ const next = cur.map((m) => ({ key: m.key, title: m.title, exit: m.exit, source: m.source ?? "", depends_on: m.depends_on, priority: m.priority ?? null }));
586
609
  if (existing)
587
- Object.assign(next.find((m) => m.key === key), { title, exit, source, depends_on: deps });
610
+ Object.assign(next.find((m) => m.key === key), { title, exit, source, depends_on: deps, priority });
588
611
  else
589
- next.push({ key, title, exit, source, depends_on: deps });
612
+ next.push({ key, title, exit, source, depends_on: deps, priority });
590
613
  const r = await client.call("PUT", `/projects/${project}/milestones`, { milestones: next });
591
614
  const m = r.milestones.find((x) => x.key === key);
592
615
  out.print(`${sub === "add" ? "Added" : "Updated"} milestone ${m.key}: ${m.title} [${m.ready ? "ready" : `waits on ${m.waiting_on.join(", ")}`}]${!m.exit && !m.depends_on.length ? " (container: never chased)" : ""}`, r);
@@ -596,7 +619,7 @@ export async function milestoneWith(client, project, sub, key, p, out) {
596
619
  const m = (await client.call("GET", `/projects/${project}/milestones`)).milestones.find((x) => x.key === key);
597
620
  if (!m)
598
621
  throw new CliError("not_found", `no milestone ${key}`);
599
- out.print(`${m.key}: ${m.title} [${m.status}${m.status === "open" && !m.ready ? `, waits on ${m.waiting_on.join(", ")}` : ""}]\n depends on: ${m.depends_on.join(", ") || "-"}\n units: ${m.units.done} done, ${m.units.open} open, ${m.units.queued} queued of ${m.units.total}${m.review ? `\n closure review: ${m.review.reviewer_name} (${m.review.source}) since ${m.review.requested_at}` : ""}${m.last_verdict && !m.last_verdict.met ? `\n gaps (${m.last_verdict.by}, ${m.last_verdict.at.slice(0, 16)}): ${m.last_verdict.gaps}` : ""}\n exit: ${m.exit || "(not written)"}${m.source ? `\n source: ${m.source} (the full brief; read it when planning this slice)` : ""}${m.closed_at ? `\n closed ${m.closed_at} by ${m.closed_by}: ${m.closed_note}${m.evidence.length ? ` (${m.evidence.map((e) => `evidence:${e}`).join(" ")})` : ""}` : ""}`, m);
622
+ out.print(`${m.key}: ${m.title} [${m.status}${m.status === "open" && !m.ready ? `, waits on ${m.waiting_on.join(", ")}` : ""}]${m.priority !== null && m.priority !== undefined ? `\n priority: ${m.priority}` : ""}\n depends on: ${m.depends_on.join(", ") || "-"}\n units: ${m.units.done} done, ${m.units.open} open, ${m.units.queued} queued of ${m.units.total}${m.review ? `\n closure review: ${m.review.reviewer_name} (${m.review.source}) since ${m.review.requested_at}` : ""}${m.last_verdict && !m.last_verdict.met ? `\n gaps (${m.last_verdict.by}, ${m.last_verdict.at.slice(0, 16)}): ${m.last_verdict.gaps}` : ""}\n exit: ${m.exit || "(not written)"}${m.source ? `\n source: ${m.source} (the full brief; read it when planning this slice)` : ""}${m.closed_at ? `\n closed ${m.closed_at} by ${m.closed_by}: ${m.closed_note}${m.evidence.length ? ` (${m.evidence.map((e) => `evidence:${e}`).join(" ")})` : ""}` : ""}`, m);
600
623
  return;
601
624
  }
602
625
  if (sub === "close") {
@@ -681,9 +704,11 @@ export async function lock(p, out) {
681
704
  const unit = str(p.flags, "unit");
682
705
  // Scoped to this machine unless --shared: the resource is this box's CPU and disk.
683
706
  const r = await client.call("POST", `/projects/${project}/locks/${lockName}/acquire`, { unit: unit ? Number(unit) : null, note: str(p.flags, "note") ?? "", shared: bool(p.flags, "shared") });
684
- out.print(r.acquired
685
- ? `You hold ${lockName}${r.lock.machine ? ` on ${r.lock.machine}` : " (shared)"}${unit ? ` for WU #${unit}` : ""}. Release it when done: bschat unlock ${lockName}`
686
- : `${lockName} is held by ${r.lock.holder_name}${r.lock.unit ? ` (WU #${r.lock.unit})` : ""}; you are ${r.position === 1 ? "next" : `#${r.position} in line`}. You will be @mentioned when it is yours; do not poll. Leave the queue: bschat unlock ${lockName}`, r);
707
+ out.print(r.maintenance
708
+ ? `${lockName} is not handed out now: ${r.maintenance}. You are #${r.position} in line and will be @mentioned when it is yours after the window; do not poll. Leave the queue: bschat unlock ${lockName}`
709
+ : r.acquired
710
+ ? `You hold ${lockName}${r.lock.machine ? ` on ${r.lock.machine}` : " (shared)"}${unit ? ` for WU #${unit}` : ""}. Release it when done: bschat unlock ${lockName}`
711
+ : `${lockName} is held by ${r.lock.holder_name}${r.lock.unit ? ` (WU #${r.lock.unit})` : ""}; you are ${r.position === 1 ? "next" : `#${r.position} in line`}. You will be @mentioned when it is yours; do not poll. Leave the queue: bschat unlock ${lockName}`, r);
687
712
  }
688
713
  /**
689
714
  * bschat ask-operator "what you need from them" --plain ".." --blocks ".." --if-yes ".." --if-no ".." [--propose ".."]:
package/dist/help.js CHANGED
@@ -54,9 +54,9 @@ Agent commands
54
54
  bschat milestones the plan's slices: ready or waiting on which, units done/total; wu open|assign --milestone <key>
55
55
  bschat milestones set --file plan.json define or replace the plan (assigner roles or the operator): a JSON list of
56
56
  {key, title, exit, depends_on}; existing keys keep their status; cycles are refused
57
- bschat milestone add <key> --title ".." [--exit ".."] [--source "docs/plan.md#b0"] [--depends-on a,b] add one slice (assigner
57
+ bschat milestone add <key> --title ".." [--exit ".."] [--source "docs/plan.md#b0"] [--depends-on a,b] [--priority n] add one slice (assigner
58
58
  roles or the operator); --source is where the full brief lives, read only when planning the slice;
59
- no exit and no dependencies makes a container for ongoing work; milestone edit <key> amends
59
+ no exit and no dependencies makes a container for ongoing work; milestone edit (or set) <key> amends
60
60
  bschat milestone show <key> exit criterion, dependencies, counts; wu milestone <n> <key|none> moves a unit
61
61
  bschat milestone close <key> --note ".." [--evidence a,b] [--abandon | --defer] the lead closes a slice against its exit criterion
62
62
  bschat milestone verdict <key> --met --note ".." [--evidence a,b] | --gaps ".." [--units n,m] the closure reviewer judges the exit against the evidence; gap units re-trigger the review when they close
@@ -89,6 +89,8 @@ Agent commands
89
89
  bschat wu explain <n> "..." the same for a unit's question waiting on the operator
90
90
  --propose: your recommended answer, phrased so they can approve it as written
91
91
  bschat wu tags <n> --add a --remove b retag (owner before review, a reviewer during it; may add a reviewer)
92
+ bschat wu hold <n> --note ".." operator or assigner: no verdict and no merge until the owner resubmits;
93
+ wu release <n> [--note ..] lifts it earlier
92
94
  bschat wu evidence replace <n> <old> <new> [--note ".."] owner replaces attached evidence; old id is retained in the unit history
93
95
  bschat wu done <n> --merged <sha> [--keep-worktree] after approval; verifies the sha is on the target; removes the unit's clean worktree
94
96
  bschat wu abandon <n> [--note ..] wu list [--all] / wu show <n> for state and timeline
@@ -219,6 +221,8 @@ Machines (provisioned over your own ssh; a daemon on each runs the agent session
219
221
  Codex-only AppArmor profile so sandboxed agents can run; --bwrap-userns: the same
220
222
  for /usr/bin/bwrap (Claude Code's sandbox; broader: any local user may use it)
221
223
  bschat-admin machine list | show <name> | remove <name>
224
+ bschat-admin machine maintenance <name> --at <ISO | HH:MM> --for <30m | 2h> | --cancel a window: no new turns from
225
+ 15 min before, its agents away until the machine reports back after booting
222
226
  bschat-admin machine session add <machine> <project>/<agent> --dir <checkout> --sandbox <read-only|workspace-write|danger-full-access>
223
227
  [--create --role <role>] [--model m] [--effort e] [--thread <id>] [--turn-timeout min]
224
228
  bschat-admin machine session stop|start|remove <machine> <project>/<agent>
@@ -0,0 +1,23 @@
1
+ import { existsSync, mkdirSync, readFileSync, renameSync, rmSync, writeFileSync } from "node:fs";
2
+ import { dirname, join } from "node:path";
3
+ import { configRoot } from "./config.js";
4
+ export const DRAIN_MS = 15 * 60_000;
5
+ const file = () => join(configRoot(), "state", "maintenance.json");
6
+ export function writeMaintenance(w) {
7
+ if (!w) {
8
+ rmSync(file(), { force: true });
9
+ return;
10
+ }
11
+ mkdirSync(dirname(file()), { recursive: true });
12
+ const tmp = `${file()}.${process.pid}.tmp`;
13
+ writeFileSync(tmp, JSON.stringify(w) + "\n");
14
+ renameSync(tmp, file());
15
+ }
16
+ /** The window holding turns back now, or null. */
17
+ export function drainingUntil(nowMs = Date.now(), text) {
18
+ const raw = text ?? (existsSync(file()) ? readFileSync(file(), "utf8") : null);
19
+ if (!raw)
20
+ return null;
21
+ const w = JSON.parse(raw);
22
+ return nowMs >= Date.parse(w.start) - DRAIN_MS && nowMs < Date.parse(w.end) ? w : null;
23
+ }
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const CLI_VERSION = "0.12.73";
1
+ export const CLI_VERSION = "0.12.75";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "benignswarm",
3
- "version": "0.12.73",
3
+ "version": "0.12.75",
4
4
  "description": "bschat: chat, status board and evidence store for coding agents (benignswarm.org)",
5
5
  "license": "UNLICENSED",
6
6
  "repository": {