benignswarm 0.12.33 → 0.12.35

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", "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"];
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", "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"];
4
4
  export const BOOL_FLAGS = ["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"];
5
5
  export function parse(argv) {
6
6
  const options = {};
@@ -241,7 +241,7 @@ export async function needsAdmin(p, out) {
241
241
  const r = await adminClient(p).call("GET", "/account/needs");
242
242
  if (!r.needs.length)
243
243
  return out.print("Nothing is waiting on you.", r);
244
- out.print(r.needs.map((n, i) => `${i + 1}. [${n.project}] ${n.kind === "unit_question" ? `WU #${n.unit}` : n.kind === "wake_broken" ? "wake path" : n.kind === "notifier" ? "your alerts" : "ask"} · ${n.asked_by} · since ${n.since.slice(0, 16).replace("T", " ")} UTC${n.blocks ? ` · waiting: ${n.blocks}` : ""}\n ${n.text.replace(/\n/g, "\n ")}${n.proposal ? `\n Proposed: ${n.proposal.replace(/\n/g, "\n ")}` : ""}\n key: ${n.key}`).join("\n\n") + `\n\nAnswer with: bschat-admin answer <key> "decision", or bschat-admin answer <key> --approve [--note ".."] to accept a proposal`, r);
244
+ out.print(r.needs.map((n, i) => `${i + 1}. [${n.project}] ${n.kind === "unit_question" ? `WU #${n.unit}` : n.kind === "wake_broken" ? "wake path" : n.kind === "notifier" ? "your alerts" : "ask"} · ${n.asked_by} · since ${n.since.slice(0, 16).replace("T", " ")} UTC${n.blocks ? ` · waiting: ${n.blocks}` : ""}\n ${n.text.replace(/\n/g, "\n ")}${n.proposal ? `\n Proposed by ${n.proposed_by}: ${n.proposal.replace(/\n/g, "\n ")}` : ""}\n key: ${n.key}`).join("\n\n") + `\n\nAnswer with: bschat-admin answer <key> "decision", or bschat-admin answer <key> --approve [--note ".."] to accept a proposal`, r);
245
245
  }
246
246
  export async function answerAdmin(rest, p, out) {
247
247
  const [key, ...words] = rest;
@@ -7,7 +7,7 @@ import { loadAgent, resolveAgentName } from "../config.js";
7
7
  import { Client } from "../client.js";
8
8
  import { heartbeatIfActive, resolveActivitySource } from "../heartbeat.js";
9
9
  import { scanProject, unitWorktrees } from "./worktrees.js";
10
- import { pruneReport, removePrunable } from "../git.js";
10
+ import { formatBytes, freeSpaceProbe, pruneReport, removePrunable } from "../git.js";
11
11
  import { CliError } from "../errors.js";
12
12
  import { acquireWatchLock } from "../lock.js";
13
13
  import { gatherUpdates } from "./hook.js";
@@ -88,10 +88,18 @@ export async function watch(p, out) {
88
88
  // Space back on a schedule: only clean worktrees whose work has landed or whose unit is
89
89
  // closed; never one a unit is still being worked in (it may have no commits yet).
90
90
  const units = await unitWorktrees(scanCreds, scanCreds.project);
91
- for (const c of pruneReport(process.cwd(), units.closed, units.active).prunable) {
91
+ const prunable = pruneReport(process.cwd(), units.closed, units.active).prunable;
92
+ const probe = freeSpaceProbe(prunable.map((c) => c.path));
93
+ let pruned = 0;
94
+ for (const c of prunable) {
92
95
  const res = removePrunable(c);
96
+ if (res.removed)
97
+ pruned++;
93
98
  log(res.removed ? `pruned merged worktree ${c.path}${c.branch ? ` (${c.branch})` : ""}` : `kept ${c.path}: ${res.reason}`);
94
99
  }
100
+ if (pruned)
101
+ for (const v of probe.after())
102
+ log(`prune freed ${formatBytes(v.freedBytes)} on the volume of ${v.volume} (${formatBytes(v.freeBytes)} free now)`);
95
103
  }
96
104
  }
97
105
  catch (e) {
@@ -4,7 +4,7 @@ import { Client } from "../client.js";
4
4
  import { loadAgent, resolveAgentName } from "../config.js";
5
5
  import { CliError } from "../errors.js";
6
6
  import { spawnSync } from "node:child_process";
7
- import { archiveWorktreeChanges, defaultMachine, scanWorktrees, pruneReport, removePrunable } from "../git.js";
7
+ import { archiveWorktreeChanges, defaultMachine, formatBytes, freeSpaceProbe, scanWorktrees, pruneReport, removePrunable } from "../git.js";
8
8
  import { table } from "../output.js";
9
9
  const CLOSED = ["done", "abandoned", "superseded"];
10
10
  /**
@@ -55,12 +55,17 @@ export async function worktrees(p, out) {
55
55
  // --archive: a closed unit's worktree with uncommitted files is saved to archive/wu<n>-leftovers
56
56
  // and then removed. Never for a unit still open, never for a worktree whose status is unreadable.
57
57
  const archive = bool(p.flags, "archive") ? rep.kept.filter((k) => k.archivable) : [];
58
+ const freedText = (probe) => {
59
+ const vols = probe.after();
60
+ return vols.length ? `\nFree space: ${vols.map((v) => `${formatBytes(v.freedBytes)} freed on the volume of ${v.volume} (${formatBytes(v.freeBytes)} free now)`).join("; ")}` : "";
61
+ };
58
62
  if (archive.length) {
59
63
  const text = archive.map((k) => ` ${k.path}${k.branch ? ` (${k.branch})` : ""}: ${k.archivable}`).join("\n");
60
64
  if (!bool(p.flags, "yes"))
61
65
  out.print(`${archive.length} closed unit worktree(s) with uncommitted files would be archived to a branch and removed (run again with --yes):\n${text}`, { archive });
62
66
  else {
63
67
  const done = [];
68
+ const probe = freeSpaceProbe(archive.map((k) => k.path));
64
69
  for (const k of archive) {
65
70
  const n = /WU #(\d+)/.exec(k.archivable)?.[1] ?? "unit";
66
71
  const branch = archiveWorktreeChanges(k.path, `wu${n}-leftovers`, `Leftover uncommitted files from WU #${n} worktree, archived ${new Date().toISOString().slice(0, 10)} before removal`);
@@ -69,7 +74,7 @@ export async function worktrees(p, out) {
69
74
  throw new CliError("git", `archived ${k.path} to ${branch} but could not remove it: ${(r.stderr || r.stdout).trim()}`);
70
75
  done.push(` ${k.path} -> ${branch}`);
71
76
  }
72
- out.print(`Archived and removed ${done.length} worktree(s):\n${done.join("\n")}`, { archived: done });
77
+ out.print(`Archived and removed ${done.length} worktree(s):\n${done.join("\n")}${freedText(probe)}`, { archived: done, free_space: probe.after() });
73
78
  }
74
79
  }
75
80
  const archived = new Set(bool(p.flags, "yes") ? archive.map((k) => k.path) : []);
@@ -86,6 +91,7 @@ export async function worktrees(p, out) {
86
91
  }
87
92
  const removed = [];
88
93
  const kept = [];
94
+ const probe = freeSpaceProbe(candidates.map((c) => c.path));
89
95
  for (const c of candidates) {
90
96
  const r = removePrunable(c);
91
97
  if (r.removed)
@@ -97,7 +103,7 @@ export async function worktrees(p, out) {
97
103
  await scanProject(creds, project);
98
104
  }
99
105
  catch { /* the registry catches up on the next scan */ }
100
- out.print(`Removed ${removed.length} worktree(s)${removed.length ? `:\n${removed.map((r) => ` ${r}`).join("\n")}` : ""}${kept.length ? `\nKept ${kept.length}: ${kept.map((k) => `${k.path} (${k.reason})`).join("; ")}` : ""}`, { removed, kept, candidates });
106
+ out.print(`Removed ${removed.length} worktree(s)${removed.length ? `:\n${removed.map((r) => ` ${r}`).join("\n")}` : ""}${kept.length ? `\nKept ${kept.length}: ${kept.map((k) => `${k.path} (${k.reason})`).join("; ")}` : ""}${removed.length ? freedText(probe) : ""}`, { removed, kept, candidates, free_space: probe.after() });
101
107
  return;
102
108
  }
103
109
  if (sub === "scan") {
@@ -125,8 +125,9 @@ export async function wu(p, out) {
125
125
  case "decline": {
126
126
  const note = str(p.flags, "note");
127
127
  if (!note)
128
- throw new CliError("usage", 'wu decline <n> --note "why"');
129
- const r = await client.call("POST", `${base}/${num()}/decline`, { note });
128
+ throw new CliError("usage", 'wu decline <n> --note "why" [--waits-on <milestone,...> | --defer] (a planning unit needs one of them)');
129
+ const waits = str(p.flags, "waits-on");
130
+ const r = await client.call("POST", `${base}/${num()}/decline`, { note, ...(waits ? { waits_on: waits.split(",").map((k) => k.trim()).filter(Boolean) } : {}), ...(bool(p.flags, "defer") ? { defer: true } : {}) });
130
131
  out.print(fmt(r.unit), r);
131
132
  return;
132
133
  }
package/dist/git.js CHANGED
@@ -1,7 +1,7 @@
1
- import { copyFileSync, existsSync, readdirSync, realpathSync, rmSync } from "node:fs";
1
+ import { copyFileSync, existsSync, readdirSync, realpathSync, rmSync, statSync, statfsSync } from "node:fs";
2
2
  import { spawnSync } from "node:child_process";
3
3
  import { hostname } from "node:os";
4
- import { join } from "node:path";
4
+ import { dirname, join } from "node:path";
5
5
  function git(args, cwd) {
6
6
  // Large enough for `git status` on a big repo with every file changed (ester: 226k files, 25 MB);
7
7
  // the 1 MB default made such a worktree unreadable rather than dirty.
@@ -345,6 +345,31 @@ export function archiveWorktreeChanges(path, name, message) {
345
345
  rmSync(tmp.startsWith("/") ? tmp : join(path, tmp), { force: true });
346
346
  }
347
347
  }
348
+ /**
349
+ * Free space on the volumes holding these paths, read before removing them; `after()` reports
350
+ * how much each volume gained. Measured from the file system (statfs), not by walking the trees,
351
+ * which takes minutes on a large checkout; anything else writing meanwhile is counted too, and
352
+ * APFS can release space a little after the delete, so the figure is what the volume shows now.
353
+ */
354
+ export function freeSpaceProbe(paths) {
355
+ const free = (p) => { const s = statfsSync(p); return Number(s.bavail) * Number(s.bsize); };
356
+ const byDev = new Map();
357
+ for (const p of paths) {
358
+ if (!existsSync(p))
359
+ continue;
360
+ const dev = statSync(p).dev;
361
+ if (byDev.has(dev))
362
+ continue;
363
+ const probe = dirname(p); // the parent survives the removal
364
+ byDev.set(dev, { probe, before: free(probe) });
365
+ }
366
+ return { after: () => [...byDev.values()].map((v) => { const now = free(v.probe); return { volume: v.probe, freedBytes: now - v.before, freeBytes: now }; }) };
367
+ }
368
+ export function formatBytes(n) {
369
+ const a = Math.abs(n);
370
+ const s = a >= 1024 ** 3 ? `${(a / 1024 ** 3).toFixed(1)} GB` : a >= 1024 ** 2 ? `${(a / 1024 ** 2).toFixed(0)} MB` : `${Math.round(a / 1024)} KB`;
371
+ return n < 0 ? `-${s}` : s;
372
+ }
348
373
  /** Removes a prune candidate: an empty checkout (re-checked here) by force, anything else only when clean. */
349
374
  export function removePrunable(c, cwd = process.cwd()) {
350
375
  if (!c.empty)
package/dist/help.js CHANGED
@@ -39,6 +39,8 @@ Agent commands
39
39
  window); --hold keeps it assigned to them however long it takes
40
40
  bschat wu take <n> [--to <agent>] pull a queued unit for yourself (qualified by works or trial), or hand it to someone
41
41
  bschat wu next take the oldest queued unit you qualify for
42
+ bschat wu decline <n> --note "why" [--waits-on <milestone,...> | --defer] decline an assignment; a steward planning unit
43
+ ("Advance milestone X") needs the plan decision: what X waits on, or defer X
42
44
  --to auto picks the active worker qualified for the tags with the lightest load;
43
45
  it exists on the board as assigned and the sweep chases it; wu decline <n> --note
44
46
  bschat wu start <n> [--branch b | --here] take it up: makes ../<repo>-wu<n> on branch wu/<n>-<slug> (replays: from the
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const CLI_VERSION = "0.12.33";
1
+ export const CLI_VERSION = "0.12.35";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "benignswarm",
3
- "version": "0.12.33",
3
+ "version": "0.12.35",
4
4
  "description": "bschat: chat, status board and evidence store for coding agents (benignswarm.org)",
5
5
  "license": "UNLICENSED",
6
6
  "repository": {