benignswarm 0.12.140 → 0.12.142

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.
@@ -553,6 +553,19 @@ async function role(action, rest, p, out) {
553
553
  throw new CliError("usage", "admin role create|edit|list|delete <name> [--project p] [--projects a,b|*] [--post ch1,ch2] [--broadcast] [--create-channels] [--read-account-status] [--assign-outside-qualifications yes|no] [--judges yes|no] [--description d] [--cardinality one|many]");
554
554
  }
555
555
  async function workUnitAdmin(action, rest, p, out) {
556
+ if (action === "merged-sha" && rest[0] && /^\d+$/.test(rest[1] ?? "")) {
557
+ const project = rest[0];
558
+ const number = Number(rest[1]);
559
+ const sha = str(p.flags, "sha");
560
+ const reason = str(p.flags, "reason");
561
+ if (!sha || !/^[0-9a-f]{40}$/.test(sha))
562
+ throw new CliError("usage", "b9s-admin wu merged-sha <project> <n> --sha <full-40-character-lowercase-sha> --reason \"why\"");
563
+ if (!reason?.trim())
564
+ throw new CliError("usage", "b9s-admin wu merged-sha <project> <n> --sha <full-40-character-lowercase-sha> --reason \"why\"");
565
+ const result = await adminClient(p).call("POST", `/projects/${encodeURIComponent(project)}/work-units/${number}/merged-sha`, { sha, reason });
566
+ out.print(`WU #${number} recorded merged SHA corrected to ${sha}.`, result);
567
+ return;
568
+ }
556
569
  if (action === "done" && rest[0] && /^\d+$/.test(rest[1] ?? "")) {
557
570
  const project = rest[0];
558
571
  const number = Number(rest[1]);
@@ -584,7 +597,7 @@ async function workUnitAdmin(action, rest, p, out) {
584
597
  return runRequiredClassUpdate(adminClient(p), rest[0], Number(rest[1]), p, out);
585
598
  }
586
599
  if (action !== "assign" || !rest[0] || !/^\d+$/.test(rest[1] ?? ""))
587
- throw new CliError("usage", 'b9s-admin wu assign <project> <n> --to <agent> [--reason "why"] | b9s-admin wu done <project> <n> --merged <sha> [--gate-override-note "why"] | b9s-admin wu required-class <project> <n> (--class p/h/m/e | --clear) --reason "why"');
600
+ throw new CliError("usage", 'b9s-admin wu assign <project> <n> --to <agent> [--reason "why"] | b9s-admin wu done <project> <n> --merged <sha> [--gate-override-note "why"] | b9s-admin wu merged-sha <project> <n> --sha <full-sha> --reason "why" | b9s-admin wu required-class <project> <n> (--class p/h/m/e | --clear) --reason "why"');
588
601
  const to = str(p.flags, "to");
589
602
  if (!to)
590
603
  throw new CliError("usage", 'b9s-admin wu assign <project> <n> --to <agent> [--reason "why"]');
@@ -248,6 +248,7 @@ export async function machineAdmin(action, rest, p, out) {
248
248
  rep.os ? ` Antigravity: ${rep.antigravity ? `${rep.antigravity.version ?? "agy"}, ${rep.antigravity.available ? "available" : "unavailable"}, ${rep.antigravity.logged_in ? "logged in" : "not logged in"}, sandbox ${rep.antigravity.sandbox ? (rep.antigravity.sandbox.ok ? "ok" : `FAILS (${rep.antigravity.sandbox.error})`) : "not checked"}` : "not installed"}` : null,
249
249
  rep.container_runtime ? ` Container runtime: ${rep.container_runtime.runtime ?? "none"} (${rep.container_runtime.rootless ? "rootless" : "daemon"}, ${rep.container_runtime.usable_without_root === false ? "NO non-root access" : "non-root ok"}, arch ${(rep.container_runtime.architectures ?? []).join(",") || rep.arch || "?"}${rep.on_ec2 ? `, EC2 container IMDS ${rep.container_imds_blocked ? "blocked" : "NOT blocked"}` : ""})` : null,
250
250
  rep.launchd ? ` launchd: ${rep.launchd.session === "headless" ? "headless Mac (no desktop session)" : "desktop session"}; daemon ${rep.launchd.daemon_domain ?? "not installed"}; watchers ${Object.entries(rep.launchd.watchers ?? {}).map(([d, n]) => `${n} in ${d}`).join(", ") || "none"}` : null,
251
+ m.parked ? ` PARKED: ${m.parked_at ?? "operator"}` : null,
251
252
  m.quarantined ? ` QUARANTINED: ${m.quarantine?.reason ?? "operator containment"}${m.quarantine?.at ? ` (${m.quarantine.at})` : ""}` : null,
252
253
  ];
253
254
  const cacheLines = [];
@@ -558,6 +559,13 @@ export async function machineAdmin(action, rest, p, out) {
558
559
  return out.print(`Removed ${ref} from ${machineName}; the agent and its thread stay.`, { removed: ref });
559
560
  }
560
561
  }
562
+ if (action === "park" || action === "unpark") {
563
+ const name = rest[0];
564
+ if (!name)
565
+ throw new CliError("usage", `machine ${action} <name>`);
566
+ const result = await c.call(action === "park" ? "PUT" : "DELETE", `/machines/${encodeURIComponent(name)}/park`);
567
+ return out.print(`Machine ${name} ${action === "park" ? "parked" : "unparked"}`, result);
568
+ }
561
569
  if (action === "quarantine") {
562
570
  const name = rest[0];
563
571
  if (!name)
@@ -1035,8 +1035,14 @@ export async function wu(p, out) {
1035
1035
  case "done": {
1036
1036
  if (str(p.flags, "gate-override-note") !== undefined)
1037
1037
  throw new CliError("forbidden", "only the operator can override a missing gate receipt; use b9s-admin wu done with --gate-override-note");
1038
- const def = await processDef();
1039
1038
  let merged = str(p.flags, "merged") ?? null;
1039
+ if (merged) {
1040
+ const canonical = fullSha(merged);
1041
+ if (!canonical)
1042
+ throw new CliError("unknown_commit", `cannot resolve ${merged} to a full commit SHA`, "Fetch the merged commit and retry.");
1043
+ merged = canonical;
1044
+ }
1045
+ const def = await processDef();
1040
1046
  const noSource = bool(p.flags, "no-source");
1041
1047
  const evidence = list("evidence");
1042
1048
  if (noSource && merged)
@@ -1059,7 +1065,7 @@ export async function wu(p, out) {
1059
1065
  if (unit.branch) {
1060
1066
  const check = verifyNoCommitsBeyondTarget(unit.branch, landsIn, process.cwd(), def.merge.require_pushed);
1061
1067
  if (check.on === null)
1062
- throw new CliError("unknown_commit", `cannot verify ${unit.branch} against ${check.ref}`, `Fetch the branch and ${landsIn} in the project repository, then retry`);
1068
+ throw new CliError("unknown_commit", check.reason ?? `cannot verify ${unit.branch} against ${check.ref}`, `Fetch the branch and ${landsIn} in the project repository, then retry`);
1063
1069
  if (!check.on)
1064
1070
  throw new CliError("has_commits", `${unit.branch} has commits not contained by ${check.ref}; --no-source is only for work with no commits beyond its target`);
1065
1071
  noCommitsBeyondTarget = true;
@@ -1086,14 +1092,6 @@ export async function wu(p, out) {
1086
1092
  if (!checked.on)
1087
1093
  throw new CliError("not_merged", `${merged} is not on ${checked.ref}`, "Merge first, then pass the merge commit (or the branch head once it is on the target).");
1088
1094
  }
1089
- // Receipts are keyed by the full commit identity. Keep abbreviated input convenient while
1090
- // ensuring the server checks the same SHA the complete gate records.
1091
- if (def.merge.require_gate_receipt) {
1092
- const canonical = fullSha(merged);
1093
- if (!canonical)
1094
- throw new CliError("unknown_commit", `cannot resolve ${merged} to a full commit SHA`, "Fetch the merged commit and retry.");
1095
- merged = canonical;
1096
- }
1097
1095
  }
1098
1096
  else if (def.merge.require_merge_commit) {
1099
1097
  throw new CliError("usage", `this project's process requires the merge commit: b9s wu done ${num()} --merged <sha>`);
@@ -1390,6 +1388,15 @@ function assertNotShaBranch(branch, flag = "--branch") {
1390
1388
  }
1391
1389
  }
1392
1390
  export function prepareWorktreeForWatcher(n, unit, def, exclude = []) {
1391
+ if (unit.branch && isShaBranchName(unit.branch))
1392
+ throw new CliError("no_branch", `recorded branch ${unit.branch} is a commit identifier, not a branch`, "Record and push the unit branch before retrying.");
1393
+ if (unit.branch && !worktreeForBranch(unit.branch) && fullSha(`refs/heads/${unit.branch}`)) {
1394
+ const remote = fetchRemoteBranch(unit.branch);
1395
+ if (!remote.ok)
1396
+ throw new CliError("no_branch", `cannot fetch recorded branch ${unit.branch} from origin: ${remote.reason}`, "Push the unit branch from the original checkout and retry.");
1397
+ if (fullSha(`refs/heads/${unit.branch}`) !== fullSha(remote.ref))
1398
+ throw new CliError("no_branch", `local ${unit.branch} differs from the pushed branch`, "Inspect the local branch and resolve the difference before retrying.");
1399
+ }
1393
1400
  const home = resolve(process.cwd());
1394
1401
  const samePath = (a, b) => {
1395
1402
  try {
@@ -1512,12 +1519,17 @@ function prepareWorktree(n, unit, def, p, exclude = [], baseRefOverride) {
1512
1519
  // Check local branch refs explicitly: fullSha(pinned) would also resolve bare SHAs or tags.
1513
1520
  let branchCreated = !existing && fullSha(`refs/heads/${pinned}`) === null;
1514
1521
  // Continuing someone else's branch from another machine: take origin's copy of it when we have none.
1515
- if (!existing && fullSha(`refs/heads/${pinned}`) === null && fetchRemoteBranch(pinned).ok) {
1516
- const r = spawnSync("git", ["branch", "--track", pinned, `origin/${pinned}`], { cwd: process.cwd(), encoding: "utf8" });
1517
- if (r.status !== 0)
1518
- throw new CliError("no_branch", `cannot create ${pinned} from origin: ${(r.stderr || r.stdout).trim()}`);
1519
- branchCreated = true;
1520
- log(`created ${pinned} from origin/${pinned}`);
1522
+ if (!existing && fullSha(`refs/heads/${pinned}`) === null) {
1523
+ const remoteBranch = fetchRemoteBranch(pinned);
1524
+ if (!remoteBranch.ok && !explicitBranch)
1525
+ throw new CliError("no_branch", `cannot fetch recorded branch ${pinned} from origin: ${remoteBranch.reason}`, "Push the unit branch from the original checkout and retry.");
1526
+ if (remoteBranch.ok) {
1527
+ const r = spawnSync("git", ["branch", "--track", pinned, `origin/${pinned}`], { cwd: process.cwd(), encoding: "utf8" });
1528
+ if (r.status !== 0)
1529
+ throw new CliError("no_branch", `cannot create ${pinned} from origin: ${(r.stderr || r.stdout).trim()}`);
1530
+ branchCreated = true;
1531
+ log(`created ${pinned} from origin/${pinned}`);
1532
+ }
1521
1533
  }
1522
1534
  const result = !existing ? ensureUnitWorktree(path, pinned, baseRef, log, exclude) : { created: false, repaired: false };
1523
1535
  return { mode: "branch", path, branch: pinned, created: result.created, branchCreated };
package/dist/git.js CHANGED
@@ -185,22 +185,59 @@ export function isAncestor(ancestor, ref, cwd = process.cwd()) {
185
185
  }
186
186
  /** Confirm an evidence-only unit branch contains no commits missing from its configured target. */
187
187
  export function verifyNoCommitsBeyondTarget(branch, target, cwd = process.cwd(), requirePushed = false) {
188
- if (requirePushed) {
189
- const ref = `origin/${target}`;
190
- const fetched = spawnSync("git", ["fetch", "--quiet", "origin", `+refs/heads/${target}:refs/remotes/origin/${target}`], { cwd, encoding: "utf8", timeout: 120_000 }).status === 0;
191
- if (!fetched)
192
- return { on: null, ref };
193
- return { on: isAncestor(branch, ref, cwd), ref };
194
- }
195
- const local = isAncestor(branch, target, cwd);
196
- if (local === true)
197
- return { on: true, ref: target };
188
+ const localBranch = `refs/heads/${branch}`;
198
189
  const ref = `origin/${target}`;
199
- const fetched = spawnSync("git", ["fetch", "--quiet", "origin", `+refs/heads/${target}:refs/remotes/origin/${target}`], { cwd, encoding: "utf8", timeout: 120_000 }).status === 0;
200
- if (!fetched)
201
- return { on: local, ref: target };
202
- const remote = isAncestor(branch, ref, cwd);
203
- return remote === true ? { on: true, ref } : { on: remote, ref };
190
+ const fetchTarget = spawnSync("git", ["fetch", "--quiet", "origin", `+refs/heads/${target}:refs/remotes/origin/${target}`], { cwd, encoding: "utf8", timeout: 120_000 });
191
+ if (fetchTarget.status !== 0) {
192
+ const detail = fetchTarget.error?.message || fetchTarget.stderr?.trim() || fetchTarget.stdout?.trim() || `git fetch exited ${fetchTarget.status ?? "without a status"}`;
193
+ return { on: null, ref, reason: `git fetch origin ${target} failed: ${detail}` };
194
+ }
195
+ // Check every extant unit-branch tip. A local branch at target must not hide newer source work
196
+ // on its remote counterpart, and the remote may have been deleted while a local copy remains.
197
+ const candidates = [];
198
+ if (fullSha(localBranch, cwd)) {
199
+ const targets = [ref];
200
+ if (!requirePushed && fullSha(`refs/heads/${target}`, cwd))
201
+ targets.push(target);
202
+ candidates.push({ branch: localBranch, targets });
203
+ }
204
+ const remoteBranchRef = `refs/heads/${branch}`;
205
+ const listed = spawnSync("git", ["ls-remote", "--exit-code", "--heads", "origin", remoteBranchRef], { cwd, encoding: "utf8", timeout: 120_000 });
206
+ if (listed.status === 0 && listed.stdout?.trim()) {
207
+ const remoteTracking = `refs/remotes/origin/${branch}`;
208
+ const fetchBranch = spawnSync("git", ["fetch", "--quiet", "origin", `+${remoteBranchRef}:${remoteTracking}`], { cwd, encoding: "utf8", timeout: 120_000 });
209
+ if (fetchBranch.status !== 0) {
210
+ const detail = fetchBranch.error?.message || fetchBranch.stderr?.trim() || fetchBranch.stdout?.trim() || `git fetch exited ${fetchBranch.status ?? "without a status"}`;
211
+ return { on: null, ref, reason: `git fetch origin ${branch} failed: ${detail}` };
212
+ }
213
+ candidates.push({ branch: remoteTracking, targets: [ref] });
214
+ }
215
+ else if (listed.status !== 2) {
216
+ const detail = listed.error?.message || listed.stderr?.trim() || listed.stdout?.trim() || `git ls-remote exited ${listed.status ?? "without a status"}`;
217
+ return { on: null, ref, reason: `git ls-remote origin ${branch} failed: ${detail}` };
218
+ }
219
+ if (!candidates.length)
220
+ return { on: true, ref };
221
+ for (const candidate of candidates) {
222
+ let contained = false;
223
+ let unknownTarget;
224
+ for (const candidateTarget of candidate.targets) {
225
+ const result = isAncestor(candidate.branch, candidateTarget, cwd);
226
+ if (result === true) {
227
+ contained = true;
228
+ break;
229
+ }
230
+ if (result === null)
231
+ unknownTarget = candidateTarget;
232
+ }
233
+ if (!contained && unknownTarget)
234
+ return { on: null, ref, reason: `cannot verify ${candidate.branch} against ${unknownTarget}` };
235
+ if (!contained)
236
+ return { on: false, ref };
237
+ }
238
+ // Local-only policy accepts containment in either local target or freshly fetched origin/target.
239
+ // Pushed policy only accepts origin/target. Every existing local and remote unit tip is checked.
240
+ return { on: true, ref: !requirePushed && fullSha(`refs/heads/${target}`, cwd) ? target : ref };
204
241
  }
205
242
  /** Branch and short head of the worktree at cwd, or nulls outside a repo. */
206
243
  export function branchAndHead(cwd = process.cwd()) {
@@ -575,24 +612,40 @@ export function remoteHead(branch, remote = "origin", cwd = process.cwd()) {
575
612
  const line = r.stdout.split("\n").find((l) => l.trim().endsWith(`refs/heads/${branch}`));
576
613
  return line ? line.split(/\s+/)[0] : null;
577
614
  }
615
+ /** Verify ancestry against the immutable advertised tip, after proving its object is fetched. */
616
+ export function remoteTrackingRefContainsCommit(branch, advertisedTip, sha, cwd = process.cwd()) {
617
+ if (fullSha(`refs/remotes/${branch}`, cwd) !== advertisedTip)
618
+ return false;
619
+ return isAncestor(sha, advertisedTip, cwd) === true;
620
+ }
578
621
  /** Fetch origin, then report a remote branch containing the submitted commit. */
579
622
  export function findRemoteCommitBranch(sha, localBranch, cwd = process.cwd(), remote = "origin") {
580
623
  const checkedRef = `${remote}/${localBranch}`;
581
- const fetched = spawnSync("git", ["fetch", "--prune", remote], { cwd, encoding: "utf8", timeout: 120_000 });
624
+ // Submission only needs current remote-tracking refs. Force pruning off even when user/repo
625
+ // config enables it: pruning stale refs takes .git/packed-refs.lock in the shared Git dir.
626
+ const fetched = spawnSync("git", ["-c", "fetch.prune=false", "-c", `remote.${remote}.prune=false`, "fetch", remote], { cwd, encoding: "utf8", timeout: 120_000 });
582
627
  if (fetched.status !== 0) {
583
628
  const detail = (fetched.stderr || fetched.stdout || `git fetch ${remote} exited with status ${fetched.status ?? "unknown"}`).trim();
584
629
  return { remoteBranch: null, checkedRef, checked: false, reason: `git fetch ${remote} failed: ${detail}` };
585
630
  }
586
- const listed = spawnSync("git", ["branch", "-r", "--contains", sha, "--format=%(refname:short)"], { cwd, encoding: "utf8" });
587
- if (listed.status !== 0) {
588
- const detail = (listed.stderr || listed.stdout || `git branch -r --contains ${sha} exited with status ${listed.status ?? "unknown"}`).trim();
589
- return { remoteBranch: null, checkedRef, checked: true, reason: `git branch -r --contains ${sha} failed: ${detail}` };
631
+ const advertised = spawnSync("git", ["ls-remote", "--heads", remote], { cwd, encoding: "utf8", timeout: 30_000 });
632
+ if (advertised.status !== 0) {
633
+ const detail = (advertised.stderr || advertised.stdout || `git ls-remote ${remote} exited with status ${advertised.status ?? "unknown"}`).trim();
634
+ return { remoteBranch: null, checkedRef, checked: false, reason: `git ls-remote ${remote} failed: ${detail}` };
635
+ }
636
+ const advertisedTips = new Map();
637
+ for (const line of advertised.stdout.split("\n")) {
638
+ const [tip, ref] = line.trim().split(/\s+/);
639
+ if (ref?.startsWith("refs/heads/") && tip)
640
+ advertisedTips.set(`${remote}/${ref.slice("refs/heads/".length)}`, tip);
590
641
  }
591
- const branches = listed.stdout.split("\n").map((line) => line.trim()).filter((line) => line.startsWith(`${remote}/`) && line !== `${remote}/HEAD`).sort();
642
+ // Check ancestry against the advertised object ID, not a mutable tracking ref. A concurrent
643
+ // fetch can move that ref between checking its tip and asking Git about containment.
644
+ const branches = [...advertisedTips].filter(([branch, tip]) => branch !== `${remote}/HEAD` && remoteTrackingRefContainsCommit(branch, tip, sha, cwd)).map(([branch]) => branch).sort();
592
645
  const remoteBranch = branches.includes(checkedRef) ? checkedRef : branches[0] ?? null;
593
646
  return remoteBranch
594
647
  ? { remoteBranch, checkedRef, checked: true, reason: null }
595
- : { remoteBranch: null, checkedRef, checked: true, reason: `git branch -r --contains ${sha} found no ${remote} branch containing the submitted commit` };
648
+ : { remoteBranch: null, checkedRef, checked: true, reason: `no advertised ${remote} branch contains the submitted commit ${sha}` };
596
649
  }
597
650
  export function formatRemoteCommitFailure(localBranch, checkedRef, reason) {
598
651
  return `Could not verify the submitted commit for local branch ${localBranch}: checked ${checkedRef} and other origin branches; ${reason}`;
package/dist/help.js CHANGED
@@ -401,6 +401,7 @@ Use --admin <nickname> to select one of this machine's saved operator identities
401
401
  b9s-admin wu assign <project> <n> --to <agent> [--reason "why"] operator: reassign a unit in place
402
402
  b9s-admin wu done <project> <n> --merged <sha> [--gate-override-note "why"] [--note "context"] operator: close approved work; missing receipt override requires a recorded reason
403
403
  b9s-admin wu done <project> <n> --no-source --evidence id[,id...] --no-commits-beyond-target [--gate-override-note "why"] operator: close evidence-only work after confirming no commits beyond target
404
+ b9s-admin wu merged-sha <project> <n> --sha <full-40-character-lowercase-sha> --reason "why" operator: correct a legacy abbreviated merged SHA with an audited reason
404
405
  b9s-admin wu required-class <project> <n> (--class <p/h/m/e> | --clear) --reason "why" set or clear an operator hard routing-class lock
405
406
  b9s-admin routing show <project> [--mode build|review] [--tag <tag>] inspect confidence matrix, exploration spend, and recent decisions
406
407
  b9s-admin routing policy <project> [--weights q,t,c] [--quality-target <0..100|none>] [--half-life <days>] [--min-samples <n>] [--build-explore <0..20>] [--review-explore <0..20>] [--pause-build yes|no] [--pause-review yes|no] [--reason "why"]
@@ -480,6 +481,7 @@ Machines (provisioned over your own ssh; a daemon on each runs the agent session
480
481
  b9s-admin machine resize <name> --type <t> [--instance-id <id>] [--drain-timeout 5m] [--yes] [--on-running-turn wait|proceed|abort] [--extend 5m] [--ssh <host>] [--poll-ms <ms>] [--no-wait-verify] [--ssh-config <path>]
481
482
  preflight (AZ offering, arch, ENA/NVMe + root UUID/PARTUUID, quota, hourly/daily cap delta), drain with deadline, stop/modify/start via AWS role, verify cores/RAM + resumed session threads, update BYO SSH config without opening SSH, and audit every step
482
483
  b9s-admin machine quarantine <name> --reason <text> [--evidence <json>]
484
+ b9s-admin machine park|unpark <name> exclude or restore a host for new placement; retain its records
483
485
  b9s-admin machine unquarantine <name> [--reason <text>]
484
486
  exclude a host from scheduler/pool placement and preserve containment across scale-down; only unquarantine clears it
485
487
  b9s-admin machine session add <machine> <project>/<agent> --dir <checkout> --sandbox <read-only|workspace-write|danger-full-access> [--harness codex|claude-code|dsh|antigravity] [--provider anthropic|deepseek]
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const CLI_VERSION = "0.12.140";
1
+ export const CLI_VERSION = "0.12.142";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "benignswarm",
3
- "version": "0.12.140",
3
+ "version": "0.12.142",
4
4
  "description": "b9s: chat, status board and evidence store for coding agents (benignswarm.org)",
5
5
  "license": "UNLICENSED",
6
6
  "repository": {