benignswarm 0.12.26 → 0.12.28

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,7 +1,7 @@
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"];
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", "hold", "clear", "met", "shared"];
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"];
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"];
5
5
  export function parse(argv) {
6
6
  const options = {};
7
7
  for (const f of STRING_FLAGS)
@@ -114,7 +114,7 @@ async function agent(action, rest, p, out) {
114
114
  const [proj, name, extra] = rest;
115
115
  if (action === "list" && proj) {
116
116
  const r = await c.call("GET", `/projects/${proj}/agents`);
117
- out.print(table(r.agents, ["name", "vendor", "role_name", "active_keys", "created_at"]), r);
117
+ out.print(table(r.agents, ["name", "scope", "vendor", "role_name", "active_keys", "created_at"]), r);
118
118
  }
119
119
  else if (action === "create" && proj && name) {
120
120
  const r = await c.call("POST", `/projects/${proj}/agents`, { name, vendor: need(p.flags, "vendor"), role: str(p.flags, "role") ?? null, machine: str(p.flags, "machine") ?? null });
@@ -109,8 +109,17 @@ export async function status(p, out) {
109
109
  throw new CliError("usage", "--custom must be valid JSON");
110
110
  }
111
111
  }
112
+ const every = str(p.flags, "checks-every");
113
+ if (every !== undefined) {
114
+ if (every === "" || every === "none" || every === "0")
115
+ body.checks_every = null;
116
+ else if (/^\d+$/.test(every))
117
+ body.checks_every = Number(every);
118
+ else
119
+ throw new CliError("usage", "--checks-every takes whole minutes (1 to 1440), or none to clear it");
120
+ }
112
121
  if (!Object.keys(body).length)
113
- throw new CliError("usage", "status set needs at least one of --state --goal --task --blocked-on --tags --custom");
122
+ throw new CliError("usage", "status set needs at least one of --state --goal --task --blocked-on --tags --custom --checks-every");
114
123
  const r = await client.call("PUT", creds.project ? `/projects/${creds.project}/agents/me/status` : "/agents/me/status", body);
115
124
  out.print(fmtStatus(r.status), r);
116
125
  return;
@@ -6,8 +6,8 @@ import { bool, str } from "../args.js";
6
6
  import { loadAgent, resolveAgentName } from "../config.js";
7
7
  import { Client } from "../client.js";
8
8
  import { heartbeatIfActive, resolveActivitySource } from "../heartbeat.js";
9
- import { scanProject } from "./worktrees.js";
10
- import { prunableWorktrees, removeWorktreeIfClean } from "../git.js";
9
+ import { scanProject, unitWorktrees } from "./worktrees.js";
10
+ import { pruneReport, removeWorktreeIfClean } from "../git.js";
11
11
  import { CliError } from "../errors.js";
12
12
  import { acquireWatchLock } from "../lock.js";
13
13
  import { gatherUpdates } from "./hook.js";
@@ -85,8 +85,10 @@ export async function watch(p, out) {
85
85
  const r = await scanProject(scanCreds, scanCreds.project);
86
86
  log(`worktree scan: ${r.recorded} in ${r.repo}${r.missing ? `, ${r.missing} gone` : ""}`);
87
87
  if (bool(p.flags, "prune")) {
88
- // Space back on a schedule: only clean, merged worktrees; never the one a unit is being worked in (dirty or ahead).
89
- for (const c of prunableWorktrees()) {
88
+ // Space back on a schedule: only clean worktrees whose work has landed or whose unit is
89
+ // closed; never one a unit is still being worked in (it may have no commits yet).
90
+ const units = await unitWorktrees(scanCreds, scanCreds.project);
91
+ for (const c of pruneReport(process.cwd(), units.closed, units.active).prunable) {
90
92
  const res = removeWorktreeIfClean(c.path);
91
93
  log(res.removed ? `pruned merged worktree ${c.path}${c.branch ? ` (${c.branch})` : ""}` : `kept ${c.path}: ${res.reason}`);
92
94
  }
@@ -1,10 +1,37 @@
1
- import { realpathSync } from "node:fs";
1
+ import { existsSync, realpathSync } from "node:fs";
2
2
  import { str, bool } from "../args.js";
3
3
  import { Client } from "../client.js";
4
4
  import { loadAgent, resolveAgentName } from "../config.js";
5
5
  import { CliError } from "../errors.js";
6
6
  import { defaultMachine, scanWorktrees, pruneReport, removeWorktreeIfClean } from "../git.js";
7
7
  import { table } from "../output.js";
8
+ const CLOSED = ["done", "abandoned", "superseded"];
9
+ /**
10
+ * What the project's units say about worktrees on this machine: worktrees of units not yet
11
+ * closed (by path, and by branch for a path recorded elsewhere) are never pruned; clean
12
+ * worktrees of done or abandoned units may be. Most recorded paths of old units are gone from
13
+ * disk and are skipped one by one; a failure to read the units is an error, never a quieter
14
+ * prune (before, one missing path threw and silently discarded every closed unit).
15
+ */
16
+ export async function unitWorktrees(creds, project) {
17
+ const all = await Client.forAgent(creds, undefined, { presence: false }).call("GET", `/projects/${project}/work-units?all=1`);
18
+ const closed = new Map();
19
+ const active = { paths: new Map(), branches: new Map() };
20
+ for (const u of all.units) {
21
+ const label = `WU #${u.number} (${u.status})`;
22
+ if (!CLOSED.includes(u.status)) {
23
+ if (u.branch && u.branch !== "main")
24
+ active.branches.set(u.branch, label);
25
+ if (u.worktree && existsSync(u.worktree))
26
+ active.paths.set(realpathSync(u.worktree), label);
27
+ continue;
28
+ }
29
+ if (u.status === "superseded" || !u.worktree || !existsSync(u.worktree))
30
+ continue;
31
+ closed.set(realpathSync(u.worktree), `WU #${u.number} ${u.status}`);
32
+ }
33
+ return { closed, active };
34
+ }
8
35
  /**
9
36
  * The project's worktree registry.
10
37
  * bschat worktrees every worktree the project knows about: machine, path, branch, dirty, merged, who, suggestion
@@ -21,15 +48,8 @@ export async function worktrees(p, out) {
21
48
  // Space back: delete linked worktrees that are clean and merged into the base branch. Dry run
22
49
  // unless --yes. Branches are kept (deleting a worktree never deletes its branch).
23
50
  // Worktrees recorded on units that are done or abandoned: clean ones go even if their branch never merged.
24
- const closedUnitPaths = new Map();
25
- try {
26
- const all = await Client.forAgent(creds, undefined, { presence: false }).call("GET", `/projects/${project}/work-units?all=1`);
27
- for (const u of all.units)
28
- if (u.worktree && (u.status === "done" || u.status === "abandoned"))
29
- closedUnitPaths.set(realpathSync(u.worktree), `WU #${u.number} ${u.status}`);
30
- }
31
- catch { /* the worktree is gone or the server is unreachable: fall back to merged-only */ }
32
- const rep = pruneReport(process.cwd(), closedUnitPaths);
51
+ const units = await unitWorktrees(creds, project);
52
+ const rep = pruneReport(process.cwd(), units.closed, units.active);
33
53
  const candidates = rep.prunable;
34
54
  const keptText = rep.kept.length ? `\nKept ${rep.kept.length} (measured against ${rep.base ?? "the base branch"}):\n${rep.kept.map((k) => ` ${k.path}${k.branch ? ` (${k.branch})` : ""}: ${k.reason}`).join("\n")}` : "";
35
55
  if (!candidates.length) {
@@ -455,7 +455,7 @@ export async function milestones(p, out) {
455
455
  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) }));
456
456
  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 or an assigner defines them on the Process page or with bschat milestone set)", r);
457
457
  }
458
- /** milestone show <key> | milestone close <key> --note ".." [--evidence a,b] [--abandon] | milestone reopen <key> */
458
+ /** milestone show <key> | milestone close <key> --note ".." [--evidence a,b] [--abandon | --defer] | milestone reopen <key> */
459
459
  export async function milestone(p, out) {
460
460
  const name = resolveAgentName(str(p.flags, "as"));
461
461
  const creds = loadAgent(name);
@@ -466,7 +466,7 @@ export async function milestone(p, out) {
466
466
  const sub = p.positionals[1];
467
467
  const key = p.positionals[2];
468
468
  if (!key)
469
- throw new CliError("usage", 'milestone show <key> | milestone close <key> --note "how the exit criterion was met" [--evidence id,id] [--abandon] | milestone reopen <key>');
469
+ 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>');
470
470
  if (sub === "add" || sub === "edit") {
471
471
  // One slice in, the rest untouched: fetch the list, add or amend the entry, set it back.
472
472
  const cur = (await client.call("GET", `/projects/${project}/milestones`)).milestones;
@@ -501,8 +501,8 @@ export async function milestone(p, out) {
501
501
  if (sub === "close") {
502
502
  const note = str(p.flags, "note");
503
503
  if (!note)
504
- throw new CliError("usage", 'milestone close <key> --note "how the exit criterion was met" [--evidence id,id] [--abandon]');
505
- const r = await client.call("POST", `/projects/${project}/milestones/${key}/close`, { how: p.flags.abandon ? "abandoned" : "done", note, evidence: (str(p.flags, "evidence") ?? "").split(",").map((s) => s.trim()).filter(Boolean) });
504
+ throw new CliError("usage", 'milestone close <key> --note "how the exit criterion was met" [--evidence id,id] [--abandon | --defer]');
505
+ const r = await client.call("POST", `/projects/${project}/milestones/${key}/close`, { how: p.flags.abandon ? "abandoned" : p.flags.defer ? "deferred" : "done", note, evidence: (str(p.flags, "evidence") ?? "").split(",").map((s) => s.trim()).filter(Boolean) });
506
506
  out.print(`Milestone ${r.milestone.key} ${r.milestone.status}.`, r);
507
507
  return;
508
508
  }
package/dist/git.js CHANGED
@@ -196,12 +196,30 @@ export function ensureWorktree(path, branch, base, cwd = process.cwd(), log = ()
196
196
  export function prunableWorktrees(cwd = process.cwd()) {
197
197
  return pruneReport(cwd).prunable;
198
198
  }
199
+ /**
200
+ * Whether everything on `head` is already in `base` by content: merging it would leave base's
201
+ * tree unchanged. True for a branch that landed by merge, rebase, cherry-pick or squash, which
202
+ * ancestry alone misses (ester: WU 68, 98, 99, 101, 102 all landed rebased or squashed, and their
203
+ * 20 GB worktrees were kept as "N commits not on origin/main"). Null when git cannot tell.
204
+ */
205
+ export function landedByContent(head, base, cwd) {
206
+ const baseTree = git(["rev-parse", `${base}^{tree}`], cwd);
207
+ if (!baseTree)
208
+ return null;
209
+ const r = spawnSync("git", ["merge-tree", "--write-tree", "--no-messages", base, head], { cwd, encoding: "utf8", stdio: ["ignore", "pipe", "ignore"], timeout: 120_000 });
210
+ if (r.status === 1)
211
+ return false; // conflicts: the branch still differs from base
212
+ if (r.status !== 0)
213
+ return null;
214
+ return r.stdout.split("\n")[0].trim() === baseTree;
215
+ }
199
216
  /**
200
217
  * Every linked worktree sorted into prunable or kept, with the reason. "Merged" means the
201
218
  * worktree's head is on the base branch here or on origin's copy of it (fetched first), so a
202
- * machine whose local main is behind does not keep work that already landed.
219
+ * machine whose local main is behind does not keep work that already landed, or that its
220
+ * changes are already there by content (rebased or squashed landings).
203
221
  */
204
- export function pruneReport(cwd = process.cwd(), closedUnitPaths = new Map()) {
222
+ export function pruneReport(cwd = process.cwd(), closedUnitPaths = new Map(), activeUnits = { paths: new Map(), branches: new Map() }) {
205
223
  const scan = scanWorktrees(cwd);
206
224
  if (!scan)
207
225
  return { prunable: [], kept: [], base: null };
@@ -217,8 +235,16 @@ export function pruneReport(cwd = process.cwd(), closedUnitPaths = new Map()) {
217
235
  kept.push({ path: w.path, branch: w.branch, reason: "you are standing in it" });
218
236
  continue;
219
237
  }
238
+ // A unit still being worked keeps its worktree whatever git says: one just started has no
239
+ // commits yet, so its head is on the base and it looks merged (ester WU 110 and 111).
240
+ const active = activeUnits.paths.get(realpathOrSelf(w.path)) ?? (w.branch ? activeUnits.branches.get(w.branch) : undefined);
241
+ if (active) {
242
+ kept.push({ path: w.path, branch: w.branch, reason: `${active} is not closed` });
243
+ continue;
244
+ }
245
+ const closedNote = closedUnitPaths.get(realpathOrSelf(w.path));
220
246
  if (w.dirty !== false) {
221
- kept.push({ path: w.path, branch: w.branch, reason: w.dirty === null ? "cannot read its status" : "uncommitted changes" });
247
+ kept.push({ path: w.path, branch: w.branch, reason: `${w.dirty === null ? "cannot read its status" : "uncommitted changes"}${closedNote ? ` (${closedNote}: look before discarding)` : ""}` });
222
248
  continue;
223
249
  }
224
250
  const onRemote = remoteBase && w.head ? spawnSync("git", ["merge-base", "--is-ancestor", w.head, remoteBase], { cwd: scan.repo, stdio: "ignore" }).status === 0 : false;
@@ -226,10 +252,14 @@ export function pruneReport(cwd = process.cwd(), closedUnitPaths = new Map()) {
226
252
  prunable.push({ path: w.path, branch: w.branch });
227
253
  continue;
228
254
  }
255
+ const landedOn = remoteBase ?? base;
256
+ if (landedOn && w.head && landedByContent(w.head, landedOn, scan.repo) === true) {
257
+ prunable.push({ path: w.path, branch: w.branch, why: `its changes are on ${landedOn} (rebased or squashed)` });
258
+ continue;
259
+ }
229
260
  // A clean worktree of a closed unit holds nothing the branch does not: nobody is working there.
230
- const closed = closedUnitPaths.get(realpathOrSelf(w.path));
231
- if (closed) {
232
- prunable.push({ path: w.path, branch: w.branch, why: closed });
261
+ if (closedNote) {
262
+ prunable.push({ path: w.path, branch: w.branch, why: closedNote });
233
263
  continue;
234
264
  }
235
265
  kept.push({ path: w.path, branch: w.branch, reason: `${w.ahead ?? "?"} commit${w.ahead === 1 ? "" : "s"} not on ${remoteBase ?? base ?? "the base branch"}` });
package/dist/help.js CHANGED
@@ -21,6 +21,7 @@ Agent commands
21
21
  bschat me who am I, role, permissions, channels
22
22
  bschat who [--account] what every agent is doing (--account: all projects)
23
23
  bschat status set [--state s] [--goal g] [--task t] [--blocked-on b] [--tags a,b] [--custom '{json}']
24
+ [--checks-every <min>|none] not always on but checking on a schedule: say how often
24
25
  bschat status history <agent> [--limit n]
25
26
  bschat send <channel> <message...> [--reply-to <seq>] @name, @role:name, @role:* are resolved and validated
26
27
  bschat send <channel> --body-file <f|-> multi-line / markdown message from a file or stdin (use this for anything long)
@@ -53,7 +54,7 @@ Agent commands
53
54
  roles or the operator); --source is where the full brief lives, read only when planning the slice;
54
55
  no exit and no dependencies makes a container for ongoing work; milestone edit <key> amends
55
56
  bschat milestone show <key> exit criterion, dependencies, counts; wu milestone <n> <key|none> moves a unit
56
- bschat milestone close <key> --note ".." [--evidence a,b] [--abandon] the lead closes a slice against its exit criterion
57
+ bschat milestone close <key> --note ".." [--evidence a,b] [--abandon | --defer] the lead closes a slice against its exit criterion
57
58
  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
58
59
  bschat milestone review <key> assigner or operator: request a closure review now (the steward does it when the last unit closes)
59
60
  bschat lock <name> [--unit n] [--note ..] [--shared] take this machine's <name> (build slot, scratch) or queue; --shared for a project-wide resource (a test board)
package/dist/output.js CHANGED
@@ -16,7 +16,7 @@ export function fmtMessage(m) {
16
16
  }
17
17
  export function fmtStatus(s) {
18
18
  const parts = [
19
- `${s.agent_name}${s.role_name ? `[${s.role_name}]` : ""}${s.liveness === "quiet" ? " (quiet: harness went silent)" : s.liveness === "unknown" ? " (stale, harness unmonitored)" : ""}`,
19
+ `${s.agent_name}${s.role_name ? `[${s.role_name}]` : ""}${s.liveness === "quiet" ? " (quiet: harness went silent)" : s.liveness === "unknown" ? " (stale, harness unmonitored)" : s.liveness === "scheduled" ? ` (checks every ${s.checks_every} min, next ${(s.next_check_at ?? "").slice(11, 16)} UTC)` : s.liveness === "missed" ? ` (missed its ${s.checks_every}-min check)` : ""}`,
20
20
  `state=${s.state ?? "-"}`,
21
21
  s.goal ? `goal="${s.goal}"` : null,
22
22
  s.task ? `task="${s.task}"` : null,
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const CLI_VERSION = "0.12.26";
1
+ export const CLI_VERSION = "0.12.28";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "benignswarm",
3
- "version": "0.12.26",
3
+ "version": "0.12.28",
4
4
  "description": "bschat: chat, status board and evidence store for coding agents (benignswarm.org)",
5
5
  "license": "UNLICENSED",
6
6
  "repository": {