benignswarm 0.12.148 → 0.12.149

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.
@@ -25,7 +25,18 @@ function commandUsageLines(help) {
25
25
  }
26
26
  function commandAlternatives(line) {
27
27
  const text = line.trim().replace(/^b9s(?:-admin)?\s+/, "");
28
- const words = text.split(/\s+/);
28
+ // A placeholder may contain spaces (`<id or key>`, `"some text"`): it is one argument, so join
29
+ // its words first. Split apart, `or` read as a literal subcommand and `answer <id or key>
30
+ // --approve` matched no usage line, so --approve was refused (2026-11-21).
31
+ const words = [];
32
+ for (const word of text.split(/\s+/)) {
33
+ const open = words.at(-1);
34
+ if (open !== undefined && ((open.startsWith("<") && !open.endsWith(">")) || (open.startsWith("\"") && (open.length === 1 || !open.endsWith("\""))))) {
35
+ words[words.length - 1] = `${open} ${word}`;
36
+ }
37
+ else
38
+ words.push(word);
39
+ }
29
40
  const paths = [[]];
30
41
  for (const word of words) {
31
42
  if (word.startsWith("-") || word === "|" || word.startsWith("("))
@@ -57,13 +57,23 @@ function stopTree(signal = "SIGTERM") {
57
57
  return;
58
58
  stopping = true;
59
59
  signalTree(signal);
60
+ // Keep the supervisor alive until resistant descendants receive SIGKILL.
61
+ // An unreferenced timer can disappear when the shell exits, leaving them alive.
60
62
  killTimer = setTimeout(() => signalTree("SIGKILL"), 5_000);
61
- killTimer.unref?.();
63
+ }
64
+ for (const output of [process.stdout, process.stderr]) {
65
+ output.on("error", (error) => {
66
+ if (error.code !== "EPIPE")
67
+ throw error;
68
+ task?.stdout?.unpipe(output);
69
+ task?.stderr?.unpipe(output);
70
+ });
62
71
  }
63
72
  for (const signal of ["SIGINT", "SIGTERM", "SIGHUP"])
64
73
  process.on(signal, () => stopTree(signal));
65
74
  const control = createReadStream("", { fd: 3 });
66
75
  control.on("end", () => stopTree());
76
+ control.on("close", () => stopTree());
67
77
  control.resume();
68
78
  function finish(exitCode, startFailure) {
69
79
  if (killTimer)
@@ -36,7 +36,7 @@ export async function runUnderLock(o, deps) {
36
36
  throw new CliError('usage', 'B9S_LOCK_SILENCE_SECONDS must be an integer from 1 to 86400');
37
37
  const label = commandLabel(o.command);
38
38
  const base = `/projects/${o.project}/locks/${o.lock}`;
39
- const acquireBody = { unit: o.unit, note: o.note ?? label, shared: o.shared, machine: o.machine, job_token: o.token, lock_run: true };
39
+ const acquireBody = { unit: o.unit, note: o.note ?? label, shared: o.shared, machine: o.machine, job_token: o.token, lock_run: true, process_pid: process.pid };
40
40
  const release = async (completion) => {
41
41
  try {
42
42
  const result = await deps.call("POST", `${base}/release`, { shared: o.shared, machine: o.shared ? undefined : o.machine, job_token: o.token, ...completion });
@@ -74,7 +74,7 @@ export async function runUnderLock(o, deps) {
74
74
  }
75
75
  let code;
76
76
  try {
77
- await deps.call("POST", `${base}/running`, { shared: o.shared, machine: o.machine, job_token: o.token, command: label, silence_seconds: seconds });
77
+ await deps.call("POST", `${base}/running`, { shared: o.shared, machine: o.machine, job_token: o.token, command: label, process_pid: process.pid, silence_seconds: seconds });
78
78
  deps.log(`job ${o.jobId} holds ${o.lock}${slot === undefined ? "" : ` slot ${slot}`}; running: ${label}`);
79
79
  let latest;
80
80
  let pending;
@@ -88,7 +88,7 @@ export async function runUnderLock(o, deps) {
88
88
  const timer = setInterval(flush, Math.min(30000, Math.max(250, seconds * 1000 / 4)));
89
89
  let result;
90
90
  try {
91
- result = await deps.run(o.command, { lock: o.lock, jobId: o.jobId, ...(slot === undefined ? {} : { slot }), ...(o.lock === "ux-browser" ? { heartbeat: () => deps.call("POST", `${base}/running`, { shared: o.shared, machine: o.machine, job_token: o.token, command: label }) } : {}), onOutput: line => { latest = redactProcessCommand(line).replace(/\bb9sjob_[A-Za-z0-9]{32,80}\b/g, '[redacted]').replace(/\b(Bearer\s+)[A-Za-z0-9._~+\/-]+=*/gi, '$1[redacted]').replace(/[\x00-\x1f\x7f]/g, ' ').slice(0, 200); } });
91
+ result = await deps.run(o.command, { lock: o.lock, jobId: o.jobId, ...(slot === undefined ? {} : { slot }), heartbeat: () => deps.call("POST", `${base}/running`, { shared: o.shared, machine: o.machine, job_token: o.token, command: label, process_pid: process.pid, silence_seconds: seconds }), onOutput: line => { latest = redactProcessCommand(line).replace(/\bb9sjob_[A-Za-z0-9]{32,80}\b/g, '[redacted]').replace(/\b(Bearer\s+)[A-Za-z0-9._~+\/-]+=*/gi, '$1[redacted]').replace(/[\x00-\x1f\x7f]/g, ' ').slice(0, 200); } });
92
92
  }
93
93
  finally {
94
94
  clearInterval(timer);
@@ -2039,7 +2039,22 @@ export async function lock(p, out) {
2039
2039
  const lockName = p.positionals[1];
2040
2040
  if (cmd === "locks") {
2041
2041
  const r = await client.call("GET", `/projects/${project}/locks`);
2042
- out.print(r.locks.length ? r.locks.map((l) => `${l.name}${l.machine ? ` on ${l.machine}` : " (shared)"}: ${lockSlotsLabel(l, Date.now())}${l.waiting.length ? ` · waiting: ${l.waiting.map((w) => `${w.name}${w.unit ? ` (#${w.unit})` : ""}${w.legacy === 1 ? " (legacy, no token)" : w.job_id ? ` job ${w.job_id}` : ""}${w.note ? `: ${w.note}` : ""}${lockWaiterActivity(w, Date.now())}`).join(", ")}` : ""}`).join("\n") : "No locks in this project. Take one with: b9s lock <name> [--unit n]", r);
2042
+ const lockLines = r.locks.length ? r.locks.map((l) => {
2043
+ const holders = Array.isArray(l.holders) ? l.holders : null;
2044
+ const leaseAge = holders === null
2045
+ ? (l.holder_name ? "unknown (API does not report holder heartbeat)" : "no active lease")
2046
+ : holders.length === 0 ? "no active lease" : holders.map((h) => {
2047
+ const polled = typeof h.last_poll_at === "string" ? Date.parse(h.last_poll_at) : NaN;
2048
+ return `${h.name ?? "unknown"} ${Number.isFinite(polled) ? `${Math.floor(Math.max(0, Date.now() - polled) / 1000)}s` : "unknown (holder heartbeat timestamp not reported)"}`;
2049
+ }).join(", ");
2050
+ return `${l.name}${l.machine ? ` on ${l.machine}` : " (shared)"}: ${lockSlotsLabel(l, Date.now())}${l.waiting.length ? ` · waiting: ${l.waiting.map((w) => `${w.name}${w.unit ? ` (#${w.unit})` : ""}${w.legacy === 1 ? " (legacy, no token)" : w.job_id ? ` job ${w.job_id}` : ""}${w.note ? `: ${w.note}` : ""}${lockWaiterActivity(w, Date.now())}`).join(", ")}` : ""} · capacity ${Number.isInteger(l.capacity) ? l.capacity : "unknown (API does not report capacity)"} · lease age ${leaseAge}`;
2051
+ }) : ["No locks in this project. Take one with: b9s lock <name> [--unit n]"];
2052
+ const metricLines = (r.wait_metrics ?? []).map((m) => m.status === "unknown"
2053
+ ? `${m.resource_name}${m.machine ? ` on ${m.machine}` : " (shared)"} · ${m.hour}: unknown (${m.unknown_reason ?? "the API did not report why metrics are unknown"})`
2054
+ : `${m.resource_name}${m.machine ? ` on ${m.machine}` : " (shared)"} · ${m.hour}: median ${Math.round(m.median_wait_ms / 1000)}s, p90 ${Math.round(m.p90_wait_ms / 1000)}s, queue avg ${m.average_queue_length.toFixed(1)} / max ${m.max_queue_length} (${m.acquisitions} acquisitions)`);
2055
+ const coverage = typeof r.wait_metrics_since === "string" ? `; measurements available since ${r.wait_metrics_since}` : `; measurement coverage start unknown (${r.wait_metrics_coverage_unknown_reason ?? "API did not report it"})`;
2056
+ out.print([...lockLines, ...(r.wait_metrics_complete === false ? [`Wait metrics unknown${coverage}: ${r.wait_metrics_unknown_reason ?? "completeness was not reported"}`] : metricLines.length ? [`Wait metrics (hourly, last 24h${coverage}):`, ...metricLines] : [`Wait metrics: none recorded in the last 24h${coverage}.`]), ...(r.recent_waits?.length ? ["Recent waits:", ...r.recent_waits.map((w) => `${w.waiter_name}${w.unit ? ` (WU #${w.unit})` : ""} waited ${Math.round(w.wait_ms / 1000)}s for ${w.resource_name}${w.machine ? ` on ${w.machine}` : ""}; acquired ${w.acquired_at}; queue ${w.queue_length}`)] : [])].join("\n"), r);
2057
+ out.print([...lockLines, ...(r.wait_metrics_complete === false ? [`Wait metrics unknown${typeof r.wait_metrics_since === "string" ? `; measurements available since ${r.wait_metrics_since}` : `; measurement coverage start unknown (${r.wait_metrics_coverage_unknown_reason ?? "API did not report it"})`}: ${r.wait_metrics_unknown_reason ?? "completeness was not reported"}`] : metricLines.length ? [`Wait metrics (hourly, last 24h${typeof r.wait_metrics_since === "string" ? `; measurements available since ${r.wait_metrics_since}` : `; measurement coverage start unknown (${r.wait_metrics_coverage_unknown_reason ?? "API did not report it"})`}):`, ...metricLines] : [`Wait metrics: none recorded in the last 24h${typeof r.wait_metrics_since === "string" ? `; measurements available since ${r.wait_metrics_since}` : `; measurement coverage start unknown (${r.wait_metrics_coverage_unknown_reason ?? "API did not report it"})`}.`]), ...(r.recent_waits?.length ? ["Recent waits:", ...r.recent_waits.map((w) => `${w.waiter_name}${w.unit ? ` (WU #${w.unit})` : ""} waited ${Math.round(w.wait_ms / 1000)}s for ${w.resource_name}${w.machine ? ` on ${w.machine}` : ""}; acquired ${w.acquired_at}; queue ${w.queue_length}`)] : [])].join("\n"), r);
2043
2058
  return;
2044
2059
  }
2045
2060
  if (cmd === "lock" && lockName === "run" && (p.rest !== undefined || p.positionals.length > 2)) {
package/dist/help.js CHANGED
@@ -132,11 +132,12 @@ Agent commands
132
132
  acquisition queues through a machine maintenance drain/window and resumes after it
133
133
  machine identity is this host's hostname plus its registered label, shared by all agents here
134
134
  save the returned job token; reuse --token to check/retry the same job
135
- b9s lock run <name> [--unit n] [--note ..] [--shared] [--token <job-token>] -- <command> poll until granted, run and release; gate receipt outcome is separate and does not change the command exit code
135
+ b9s lock run <name> [--unit n] [--note ..] [--shared] [--token <job-token>] -- <command> poll, heartbeat while running, stop its process tree before release; gate receipt outcome does not change the command exit code
136
136
  polls every 15s; stale waiters are skipped after 60s with a process notice; later polls reap unreported holders idle 60s
137
137
  output silence raises a Needs fault after B9S_LOCK_SILENCE_SECONDS (default 300); last output is redacted
138
- b9s locks shows waiter poll age; reported-command holders do not expire
139
- b9s unlock <name> [--job <id> | --token <job-token>] [--machine <label>|--shared] | b9s locks shows lock-run waiters' last-poll age; on this host the job token is kept for you
138
+ each holder reports a PID heartbeat; holders and waiters expire after 60s without one
139
+ output silence raises a Needs fault after B9S_LOCK_SILENCE_SECONDS (default 300); last output is redacted
140
+ b9s unlock <name> [--job <id> | --token <job-token>] [--machine <label>|--shared] | b9s locks shows holders, waiters, hourly wait metrics and recent waits
140
141
  b9s unlock <name> --remove-empty [--machine <label>|--shared]
141
142
  new agent jobs release by token; legacy jobs retain identity release; assigners/operators may release without a token
142
143
  closing a unit does not release a new job's lock
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const CLI_VERSION = "0.12.148";
1
+ export const CLI_VERSION = "0.12.149";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "benignswarm",
3
- "version": "0.12.148",
3
+ "version": "0.12.149",
4
4
  "description": "b9s: chat, status board and evidence store for coding agents (benignswarm.org)",
5
5
  "license": "UNLICENSED",
6
6
  "repository": {