benignswarm 0.12.145 → 0.12.146

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.
@@ -97,15 +97,28 @@ export async function me(p, out) {
97
97
  }
98
98
  export async function who(p, out) {
99
99
  const { client, creds } = agentClient(p);
100
+ const projectStalls = async (project) => {
101
+ const response = await client.call("GET", `/projects/${encodeURIComponent(project)}/work-units?all=1`);
102
+ return (response.units ?? []).filter((unit) => unit.stalled).map((unit) => ({ number: unit.number, owner_name: unit.owner_name, age_minutes: unit.stalled.age_minutes, reason: unit.stalled.reason }));
103
+ };
104
+ const statusLines = (statuses, stalled) => statuses.map((status) => {
105
+ const owned = stalled.filter((unit) => unit.owner_name === status.agent_name);
106
+ return `${fmtStatus(status)}${owned.length ? `\n stalled work: ${owned.map((unit) => `WU #${unit.number} · ${unit.age_minutes} min · ${unit.reason}`).join("; ")}` : ""}`;
107
+ });
100
108
  if (bool(p.flags, "account") || (!creds.project && !str(p.flags, "project") && !process.env.BSCHAT_PROJECT)) {
101
109
  const r = await client.call("GET", "/account/agents/status");
102
110
  const acct = r.account.statuses.length ? `## account-wide agents\n${r.account.statuses.map(fmtStatus).join("\n")}\n\n` : "";
103
- const text = acct + r.projects.map((pr) => `## ${pr.project}\n${pr.statuses.length ? pr.statuses.map(fmtStatus).join("\n") : "(no agents have reported)"}`).join("\n\n");
104
- out.print(text, r);
111
+ const projects = await Promise.all(r.projects.map(async (pr) => {
112
+ const stalled = await projectStalls(pr.project);
113
+ return { ...pr, stalled_units: stalled, text: `## ${pr.project}\n${pr.statuses.length ? statusLines(pr.statuses, stalled).join("\n") : "(no agents have reported)"}` };
114
+ }));
115
+ const text = acct + projects.map((pr) => pr.text).join("\n\n");
116
+ out.print(text, { ...r, projects });
105
117
  return;
106
118
  }
107
119
  const r = await client.call("GET", `/projects/${projectOf(p, creds)}/agents/status`);
108
- out.print(r.statuses.length ? r.statuses.map(fmtStatus).join("\n") : "(no agents have reported status yet)", r);
120
+ const stalled = await projectStalls(projectOf(p, creds));
121
+ out.print(r.statuses.length ? statusLines(r.statuses, stalled).join("\n") : "(no agents have reported status yet)", { ...r, stalled_units: stalled });
109
122
  }
110
123
  export async function status(p, out) {
111
124
  const sub = p.positionals[1];
@@ -225,9 +225,38 @@ export async function gatherUpdates(name, opts) {
225
225
  const followed = [];
226
226
  const readCommands = [];
227
227
  const pendingReads = new Map();
228
+ const stalledLines = [];
229
+ const stalledNext = { ...(state.stalled_work_delivered ?? {}) };
230
+ const stalledRemoved = new Set();
228
231
  try {
229
232
  const projects = creds.project ? [creds.project] : ((await client.call("GET", "/me")).projects ?? []).map((x) => x.name);
230
233
  for (const project of projects) {
234
+ try {
235
+ const work = await client.call("GET", `/projects/${encodeURIComponent(project)}/work-units?agent=${encodeURIComponent(creds.agent)}`);
236
+ const activeStalls = new Set();
237
+ for (const unit of (work.units ?? []).filter((item) => item.owner_name === creds.agent && item.stalled)) {
238
+ const key = `${project}/${unit.number}`;
239
+ activeStalls.add(key);
240
+ const episode = unit.stalled.since;
241
+ if (typeof episode !== "string" || !episode) {
242
+ process.stderr.write(`b9s: stalled work status for ${project} WU #${unit.number} has no episode timestamp\n`);
243
+ continue;
244
+ }
245
+ if (stalledNext[key] !== episode) {
246
+ stalledLines.push(` ${creds.project ? "" : `[${project}] `}WU #${unit.number}: stalled ${unit.stalled.age_minutes} min · ${unit.stalled.reason} — b9s wu show ${creds.project ? "" : `--project ${project} `}${unit.number}`);
247
+ stalledNext[key] = episode;
248
+ }
249
+ }
250
+ for (const key of Object.keys(stalledNext)) {
251
+ if (key.startsWith(`${project}/`) && !activeStalls.has(key)) {
252
+ delete stalledNext[key];
253
+ stalledRemoved.add(key);
254
+ }
255
+ }
256
+ }
257
+ catch (error) {
258
+ process.stderr.write(`b9s: stalled work status for ${project}: ${error.message}\n`);
259
+ }
231
260
  const since = Object.fromEntries(Object.entries(channelRead).filter(([k]) => k.startsWith(`${project}/`)).map(([k, v]) => [k.slice(project.length + 1), v]));
232
261
  const sinceQuery = Object.keys(since).length ? `?since=${encodeURIComponent(JSON.stringify(since))}` : "";
233
262
  const { cursors } = await client.call("GET", `/projects/${project}/channels/cursors${sinceQuery}`);
@@ -311,13 +340,21 @@ export async function gatherUpdates(name, opts) {
311
340
  // Never backwards: another reader may have surfaced later messages meanwhile.
312
341
  ...(newest && (!onDisk[cursorField] || onDisk[cursorField] < newest) ? { [cursorField]: newest } : {}),
313
342
  ...(nextMeasureState !== null ? { measure_state: nextMeasureState } : {}),
343
+ ...(!opts.dryRun ? { stalled_work_delivered: stalledNext } : {}),
314
344
  channel_read: { ...(onDisk.channel_read ?? {}), ...Object.fromEntries(moved) },
315
345
  ...(pending ? { pending_reads: pending } : {}),
316
346
  ...(noticeChanges ? { notice_state: noticeChanges.next } : {}),
317
347
  };
318
348
  });
319
349
  }
320
- if (!messages.length && !questions.length && !items.length && !digest.length && !followed.length && !noticeLines.length && !measureLines.length)
350
+ if (opts.dryRun && stalledRemoved.size)
351
+ updateState(name, (onDisk) => {
352
+ const delivered = { ...(onDisk.stalled_work_delivered ?? {}) };
353
+ for (const key of stalledRemoved)
354
+ delete delivered[key];
355
+ return { ...onDisk, stalled_work_delivered: delivered };
356
+ });
357
+ if (!messages.length && !questions.length && !items.length && !digest.length && !followed.length && !noticeLines.length && !measureLines.length && !stalledLines.length)
321
358
  return null;
322
359
  const lines = messages.map((m) => `${creds.project ? "" : `[${m.project}] `}${fmtMessage(m)}${m.reply_to_seq ? ` (reply to #${m.reply_to_seq})` : ""}`);
323
360
  const questionLines = questions.slice(0, 4).map((q) => ` ${q.project} #${q.channel} seq ${q.seq} from ${q.from} (${q.age_minutes} min ago): ${q.question} — ${q.next}`);
@@ -335,6 +372,7 @@ export async function gatherUpdates(name, opts) {
335
372
  followed.length ? `new messages in followed channels` : null,
336
373
  digest.length ? `unread channels` : null,
337
374
  noticeLines.length ? `${noticeLines.length} notice change${noticeLines.length === 1 ? "" : "s"}` : null,
375
+ stalledLines.length ? `${stalledLines.length} stalled work unit${stalledLines.length === 1 ? "" : "s"}` : null,
338
376
  measureLines.length ? `${measureLines.length} outcome measure change${measureLines.length === 1 ? "" : "s"}` : null,
339
377
  ].filter(Boolean).join(", ");
340
378
  const proj = creds.project ? "" : "--project <project> ";
@@ -359,7 +397,8 @@ export async function gatherUpdates(name, opts) {
359
397
  const directPointer = firstDeferred ? inboxPointer : "b9s inbox --unread";
360
398
  const itemPointer = firstItemDeferred ? inboxPointer : "b9s inbox --unread";
361
399
  const followedPointer = pendingReads.size ? "b9s read --pending" : readCommands.join("; ") || "b9s read --pending";
362
- const parts = { header, protectedDirect: [...(questionBlock ? [questionBlock] : []), ...protectedDirect, ...(noticeBlock ? [noticeBlock] : []), ...measureLines], direct: directLines, direct_ids: messages.flatMap((message) => message.role_name === "human" ? [] : [String(message.id)]), directPointer, itemPointer, followedPointer, digestPointer: digestCommands.length ? "b9s read --pending" : "b9s inbox --unread", items: itemLines, followed, digest, footer, readCommand: `b9s read <channel> --since <seq>`, budget };
400
+ const stalledBlock = stalledLines.length ? [`Your stalled work units; see their wait and next actor:`, ...stalledLines] : [];
401
+ const parts = { header, protectedDirect: [...(questionBlock ? [questionBlock] : []), ...protectedDirect, ...stalledBlock, ...(noticeBlock ? [noticeBlock] : []), ...measureLines], direct: directLines, direct_ids: messages.flatMap((message) => message.role_name === "human" ? [] : [String(message.id)]), directPointer, itemPointer, followedPointer, digestPointer: digestCommands.length ? "b9s read --pending" : "b9s inbox --unread", items: itemLines, followed, digest, footer, readCommand: `b9s read <channel> --since <seq>`, budget };
363
402
  const delivery = budgetDelivery(parts);
364
403
  const operator = messages.filter((m) => m.role_name === "human").map((m) => m.created_at).sort().pop() ?? null;
365
404
  const visibleReadCommands = readCommands.slice(0, 8);
@@ -368,7 +407,7 @@ export async function gatherUpdates(name, opts) {
368
407
  const cmds = [...(messages.length || questions.length || items.length ? ["b9s inbox --unread"] : []), ...visibleReadCommands];
369
408
  const escapedAgent = creds.agent.replace(/[-_]/g, "\\$&");
370
409
  const isDirectMessage = (message) => message.role_name === "human" || !!message.reply_to_seq || message.mentions?.includes(creds.agent) || new RegExp(`(^|[^\\w@])@${escapedAgent}(?![\\w-])`).test(message.body);
371
- const direct = questions.length > 0 || items.length > 0 || noticeLines.length > 0 || measureLines.length > 0 || messages.some(isDirectMessage);
410
+ const direct = questions.length > 0 || items.length > 0 || noticeLines.length > 0 || measureLines.length > 0 || stalledLines.length > 0 || messages.some(isDirectMessage);
372
411
  const tier = direct ? "direct" : messages.length ? "role" : followed.length ? "followed" : "digest";
373
412
  const turnBindingCandidates = tier === "direct" ? messages.map((message, index) => ({
374
413
  id: String(message.id),
@@ -386,7 +425,7 @@ export async function gatherUpdates(name, opts) {
386
425
  const firstDirectAt = directTimes.sort()[0] ?? null;
387
426
  const urgent = messages.some((message) => message.urgent === true || message.priority === "urgent")
388
427
  || items.some((item) => item.urgent === true || item.priority === "urgent");
389
- return { text: delivery.text, counts: { messages: messages.length, questions: questions.length, items: items.length, followed: followed.length, digest: digest.length, notices: noticeLines.length }, noticeLines, noticeNext, measureSnapshot: nextMeasureState ?? undefined, latestOperatorAt: operator, readCommands: cmds, tier, firstDirectAt, urgent, turn_binding_candidates: turnBindingCandidates, ...(opts.watchCursor && messages.length ? { watchCursorAfter: messages[messages.length - 1].created_at } : {}), delivery: { bytes: delivery.bytes, by_kind: delivery.by_kind }, parts };
428
+ return { text: delivery.text, counts: { messages: messages.length, questions: questions.length, items: items.length, followed: followed.length, digest: digest.length, notices: noticeLines.length }, noticeLines, noticeNext, stalledNext, measureSnapshot: nextMeasureState ?? undefined, latestOperatorAt: operator, readCommands: cmds, tier, firstDirectAt, urgent, turn_binding_candidates: turnBindingCandidates, ...(opts.watchCursor && messages.length ? { watchCursorAfter: messages[messages.length - 1].created_at } : {}), delivery: { bytes: delivery.bytes, by_kind: delivery.by_kind }, parts };
390
429
  }
391
430
  /** Command patterns warn without blocking; errors remain visible to the caller. */
392
431
  export async function commandWarnings(name, command) {
@@ -415,7 +415,7 @@ export async function watch(p, out, dependencies = {}) {
415
415
  // record the same actual payload bytes and kinds through the hook's existing metric call.
416
416
  await reportDelivery(name, update.text, update.delivery.by_kind, "watch");
417
417
  if (delivered)
418
- updateState(name, (onDisk) => ({ ...onDisk, ...(update.noticeNext ? { notice_state: update.noticeNext } : {}), ...(update.measureSnapshot ? { measure_state: update.measureSnapshot } : {}) }));
418
+ updateState(name, (onDisk) => ({ ...onDisk, ...(update.stalledNext ? { stalled_work_delivered: update.stalledNext } : {}), ...(update.noticeNext ? { notice_state: update.noticeNext } : {}), ...(update.measureSnapshot ? { measure_state: update.measureSnapshot } : {}) }));
419
419
  resumeBriefDelivered = resumeBriefDelivered || recoveryBriefWasDelivered(recovery, delivered);
420
420
  if (stopping)
421
421
  return stoppingCode;
@@ -903,6 +903,7 @@ export async function wakeOnce(name, exec, unackedAfter, followDelay, log, model
903
903
  ...(processNews ? { watch_process_woken: lag.version } : {}),
904
904
  watch_pending: { seq, at: queuedAt, inbox_after: st.inbox_after, channel_read: st.channel_read ?? {} },
905
905
  watch_operator_at: u?.latestOperatorAt ?? st.watch_operator_at,
906
+ ...(u?.stalledNext ? { stalled_work_delivered: u.stalledNext } : {}),
906
907
  ...(u ? { notice_state: u.noticeNext } : {}),
907
908
  ...(u?.measureSnapshot ? { measure_state: u.measureSnapshot } : {}),
908
909
  watch_followed_since: undefined,
@@ -583,7 +583,7 @@ export async function wu(p, out) {
583
583
  const reviewers = u.reviewers.map((r) => `${r.name}${r.tags.length ? ` for ${r.tags.map((t) => `#${t}`).join(" ")}` : ""}`).join(", ");
584
584
  const approvals = u.approvals.map((a) => a.name).join(", ");
585
585
  return [
586
- `WU #${u.number} [${u.status}] ${tags(u)} ${u.title}${flags ? ` (${flags})` : ""}${u.requires?.length ? `\n requires: ${u.requires.join(", ")}` : ""}`,
586
+ `WU #${u.number} [${u.status}]${u.stalled ? ` STALLED ${u.stalled.age_minutes}m · ${u.stalled.reason}` : ""} ${tags(u)} ${u.title}${flags ? ` (${flags})` : ""}${u.requires?.length ? `\n requires: ${u.requires.join(", ")}` : ""}`,
587
587
  u.candidate_record?.tags?.length ? ` ${u.candidate_record.agent} first-round approval: ${u.candidate_record.tags.map((x) => `#${x.tag} ${x.approved_first_round}/${x.units} (${Math.round(x.rate * 100)}%)`).join(", ")}` : null,
588
588
  ` owner ${u.owner_name || "unassigned (queued)"}${reviewers ? ` · reviewers ${reviewers}` : ""}${approvals ? ` · approved by ${approvals}` : ""}${u.uncovered?.length ? ` · awaiting ${u.uncovered.map((t) => `#${t}`).join(" ")}` : ""}`,
589
589
  Object.keys(u.tag_focus ?? {}).length ? ` review focus:\n${Object.entries(u.tag_focus).map(([tag, focus]) => ` #${tag}: ${focus}`).join("\n")}` : null,
@@ -826,7 +826,11 @@ export async function wu(p, out) {
826
826
  pushed = check.remoteBranch ? true : check.checked ? false : null;
827
827
  if (check.remoteBranch) {
828
828
  remoteCommitBranch = check.remoteBranch;
829
- where.branch = check.remoteBranch.replace(/^origin\//, "");
829
+ const containingBranch = check.remoteBranch.replace(/^origin\//, "");
830
+ where.branch = containingBranch;
831
+ if (submitUnit.owner_name === creds.agent && submitUnit.branch === localBranch && containingBranch === localBranch && where.head) {
832
+ await client.call("POST", `${base}/${num()}/activity`, { source: "branch_push", branch: localBranch, head: where.head });
833
+ }
830
834
  }
831
835
  else if (def.merge.require_pushed) {
832
836
  const message = formatRemoteCommitFailure(localBranch, check.checkedRef, check.reason ?? "no containing origin branch was found");
@@ -1296,7 +1300,8 @@ export async function wu(p, out) {
1296
1300
  return;
1297
1301
  }
1298
1302
  case "show": {
1299
- const r = await client.call("GET", `${base}/${num()}`);
1303
+ const number = num();
1304
+ const r = await client.call("GET", `${base}/${number}`);
1300
1305
  const onlyScope = scopeOnlyOutput(r.unit, bool(p.flags, "scope-only"));
1301
1306
  if (onlyScope !== null) {
1302
1307
  out.print(onlyScope, { scope: onlyScope });
@@ -1321,12 +1326,21 @@ export async function wu(p, out) {
1321
1326
  if (str(p.flags, k))
1322
1327
  qs.set(k, str(p.flags, k));
1323
1328
  const r = await client.call("GET", `${base}${qs.size ? `?${qs}` : ""}`);
1324
- const rows = r.units.map((u) => ({ n: `#${u.number}`, status: u.status, tags: u.tags.map((t) => `#${t}`).join(" "), owner: u.owner_name, reviewers: u.reviewers.map((x) => x.name).join(",") || "-", awaiting: (u.uncovered ?? []).map((t) => `#${t}`).join(" ") || "-", base: u.lands_with ? `#${u.lands_with}` : "-", title: u.title.slice(0, 50) }));
1329
+ const rows = r.units.map((u) => ({ n: `#${u.number}`, status: u.stalled ? `STALLED ${u.stalled.age_minutes}m · ${u.stalled.reason} · ${u.status}` : u.status, tags: u.tags.map((t) => `#${t}`).join(" "), owner: u.owner_name, reviewers: u.reviewers.map((x) => x.name).join(",") || "-", awaiting: (u.uncovered ?? []).map((t) => `#${t}`).join(" ") || "-", base: u.lands_with ? `#${u.lands_with}` : "-", title: u.title.slice(0, 50) }));
1325
1330
  out.print(rows.length ? table(rows, ["n", "status", "tags", "owner", "reviewers", "awaiting", "base", "title"]) : "(no open work units; b9s wu list --all for closed ones)", r);
1326
1331
  return;
1327
1332
  }
1333
+ case "stalled": {
1334
+ const response = await client.call("GET", `${base}?all=1`);
1335
+ const units = response.units.filter((unit) => unit.stalled);
1336
+ const rows = units.map((unit) => ({ n: `#${unit.number}`, age: `${unit.stalled.age_minutes} min`, status: unit.status, owner: unit.owner_name || "unassigned", reason: unit.stalled.reason, title: unit.title }));
1337
+ out.print(rows.length ? table(rows, ["n", "age", "status", "owner", "reason", "title"]) : "(no stalled work units)", { project, units });
1338
+ if (rows.length)
1339
+ process.exitCode = 1;
1340
+ return;
1341
+ }
1328
1342
  default:
1329
- throw new CliError("usage", "wu open|assign|lands-with|start [--branch b|--here]|decline|submit|approve|changes|classify|tags|merge <n>|merge status <n>|done [--keep-worktree]|abandon|note|ask|rule|propose|show|list");
1343
+ throw new CliError("usage", "wu open|assign|lands-with|start [--branch b|--here]|decline|submit|approve|changes|classify|tags|merge <n>|merge status <n>|done [--keep-worktree]|abandon|note|ask|rule|propose|show|list|stalled");
1330
1344
  }
1331
1345
  }
1332
1346
  /** Queued units have no owner; ask the API to reject before any local worktree is made. */
package/dist/help.js CHANGED
@@ -199,6 +199,7 @@ Machine placement enforces configured session slots and reports machine pressure
199
199
  b9s wu recovery restore <n> next owner: verify and restore the restricted recovery bundle into the unit worktree
200
200
  b9s wu abandon <n> [--note ..] wu list [--all] [--json] for state and timeline (JSON keeps complete titles)
201
201
  b9s wu list [--all] [--status s] [--tag t] [--agent name] list visible work units; --all includes closed units
202
+ b9s wu stalled list stalled units with age and reason; exits 1 when any are stalled
202
203
  b9s worktrees prune [--yes] [--archive] remove clean, fully pushed worktrees whose work landed or whose unit is closed (dry run without --yes);
203
204
  --archive also saves a closed unit's uncommitted files to archive/wu<n>-leftovers and removes it;
204
205
  refused in Antigravity workspace-write: watcher processes queued wu done worktrees at turn finalization; prune retained or abandoned worktrees from an unrestricted checkout
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const CLI_VERSION = "0.12.145";
1
+ export const CLI_VERSION = "0.12.146";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "benignswarm",
3
- "version": "0.12.145",
3
+ "version": "0.12.146",
4
4
  "description": "b9s: chat, status board and evidence store for coding agents (benignswarm.org)",
5
5
  "license": "UNLICENSED",
6
6
  "repository": {