benignswarm 0.12.29 → 0.12.31

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.
@@ -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, removeWorktreeIfClean } from "../git.js";
10
+ import { 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";
@@ -89,7 +89,7 @@ export async function watch(p, out) {
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
91
  for (const c of pruneReport(process.cwd(), units.closed, units.active).prunable) {
92
- const res = removeWorktreeIfClean(c.path);
92
+ const res = removePrunable(c);
93
93
  log(res.removed ? `pruned merged worktree ${c.path}${c.branch ? ` (${c.branch})` : ""}` : `kept ${c.path}: ${res.reason}`);
94
94
  }
95
95
  }
@@ -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, removeWorktreeIfClean } from "../git.js";
7
+ import { archiveWorktreeChanges, defaultMachine, scanWorktrees, pruneReport, removePrunable } from "../git.js";
8
8
  import { table } from "../output.js";
9
9
  const CLOSED = ["done", "abandoned", "superseded"];
10
10
  /**
@@ -87,7 +87,7 @@ export async function worktrees(p, out) {
87
87
  const removed = [];
88
88
  const kept = [];
89
89
  for (const c of candidates) {
90
- const r = removeWorktreeIfClean(c.path);
90
+ const r = removePrunable(c);
91
91
  if (r.removed)
92
92
  removed.push(c.path);
93
93
  else
package/dist/git.js CHANGED
@@ -1,9 +1,11 @@
1
- import { copyFileSync, existsSync, realpathSync, rmSync } from "node:fs";
1
+ import { copyFileSync, existsSync, readdirSync, realpathSync, rmSync } from "node:fs";
2
2
  import { spawnSync } from "node:child_process";
3
3
  import { hostname } from "node:os";
4
4
  import { join } from "node:path";
5
5
  function git(args, cwd) {
6
- const r = spawnSync("git", args, { cwd, encoding: "utf8", stdio: ["ignore", "pipe", "ignore"] });
6
+ // Large enough for `git status` on a big repo with every file changed (ester: 226k files, 25 MB);
7
+ // the 1 MB default made such a worktree unreadable rather than dirty.
8
+ const r = spawnSync("git", args, { cwd, encoding: "utf8", stdio: ["ignore", "pipe", "ignore"], maxBuffer: 512 * 1024 * 1024 });
7
9
  if (r.status !== 0)
8
10
  return null;
9
11
  return r.stdout.trim();
@@ -53,7 +55,8 @@ export function scanWorktrees(cwd = process.cwd()) {
53
55
  const head = git(["rev-parse", "--short", "HEAD"], p);
54
56
  const status = git(["status", "--porcelain"], p);
55
57
  const f = head ? mergeFacts(p, p) : { base: null, merged: null, ahead: null };
56
- return { path: p, branch, head, dirty: status === null ? null : status.length > 0, base: f.base, merged: f.merged, ahead: f.ahead };
58
+ const empty = existsSync(p) && readdirSync(p).every((e) => e === ".git");
59
+ return { path: p, branch, head, dirty: status === null ? null : status.length > 0, base: f.base, merged: f.merged, ahead: f.ahead, empty };
57
60
  });
58
61
  return { repo, worktrees };
59
62
  }
@@ -244,6 +247,12 @@ export function pruneReport(cwd = process.cwd(), closedUnitPaths = new Map(), ac
244
247
  continue;
245
248
  }
246
249
  const closedNote = closedUnitPaths.get(realpathOrSelf(w.path));
250
+ // Nothing but .git: a checkout that never happened. There are no files to lose, and archiving
251
+ // it would record "every file deleted". The branch is untouched.
252
+ if (w.empty) {
253
+ prunable.push({ path: w.path, branch: w.branch, empty: true, why: `empty checkout (an interrupted git worktree add)${closedNote ? `, ${closedNote}` : ""}` });
254
+ continue;
255
+ }
247
256
  if (w.dirty !== false) {
248
257
  kept.push({ path: w.path, branch: w.branch, reason: `${w.dirty === null ? "cannot read its status" : "uncommitted changes"}${closedNote ? ` (${closedNote}${w.dirty ? "; --archive saves them to a branch and removes it" : ""})` : ""}`, ...(closedNote && w.dirty === true ? { archivable: closedNote } : {}) });
249
258
  continue;
@@ -336,6 +345,15 @@ export function archiveWorktreeChanges(path, name, message) {
336
345
  rmSync(tmp.startsWith("/") ? tmp : join(path, tmp), { force: true });
337
346
  }
338
347
  }
348
+ /** Removes a prune candidate: an empty checkout (re-checked here) by force, anything else only when clean. */
349
+ export function removePrunable(c, cwd = process.cwd()) {
350
+ if (!c.empty)
351
+ return removeWorktreeIfClean(c.path, cwd);
352
+ if (!existsSync(c.path) || !readdirSync(c.path).every((e) => e === ".git"))
353
+ return { removed: false, reason: "no longer an empty checkout" };
354
+ const r = spawnSync("git", ["worktree", "remove", "--force", c.path], { cwd, encoding: "utf8" });
355
+ return r.status === 0 ? { removed: true } : { removed: false, reason: (r.stderr || r.stdout).trim() };
356
+ }
339
357
  export function removeWorktreeIfClean(path, cwd = process.cwd()) {
340
358
  const status = git(["status", "--porcelain"], path);
341
359
  if (status === null)
package/dist/output.js CHANGED
@@ -27,6 +27,7 @@ export function fmtStatus(s) {
27
27
  s.worktree ? `worktree=${s.worktree}` : null,
28
28
  `seen=${s.last_seen}`,
29
29
  s.harness ? `harness_active=${s.harness.active_at}` : null,
30
+ s.declaration_outdated ? `(possibly outdated: ${s.declaration_outdated})` : null,
30
31
  ].filter(Boolean);
31
32
  return parts.join(" ");
32
33
  }
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const CLI_VERSION = "0.12.29";
1
+ export const CLI_VERSION = "0.12.31";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "benignswarm",
3
- "version": "0.12.29",
3
+ "version": "0.12.31",
4
4
  "description": "bschat: chat, status board and evidence store for coding agents (benignswarm.org)",
5
5
  "license": "UNLICENSED",
6
6
  "repository": {