benignswarm 0.12.18 → 0.12.19

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"];
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"];
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"];
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"];
5
5
  export function parse(argv) {
6
6
  const options = {};
7
7
  for (const f of STRING_FLAGS)
@@ -139,9 +139,22 @@ async function wakeOnce(name, exec, requeueAfter, followDelay, maxUnanswered, lo
139
139
  }
140
140
  const u = await gatherUpdates(name, { force: true, model, delivery: "watch", dryRun: true });
141
141
  const st = readState(name);
142
+ // A process change is news too. Watched harnesses never see the Claude Code hook re-deliver the
143
+ // standing rules, so the watcher compares the version the agent last read with the current one.
144
+ const idleLag = u ? null : await processLag(name, st, false, log);
142
145
  if (!u) {
143
146
  if (st.watch_followed_since)
144
147
  writeState(name, { ...st, watch_followed_since: undefined });
148
+ if (idleLag && st.watch_process_woken !== idleLag.version && !st.watch_pending) {
149
+ const lag = idleLag;
150
+ // Not recorded as pending: reading the process moves no cursor, and a pending wake-up would
151
+ // hold back the next real one until the requeue timeout.
152
+ const summary = `process changed to v${lag.version}; read it: bschat process`;
153
+ const wake = [`[bschat] Wake-up from your BenignSwarm watcher, not typed by the user.`, processLine(lag), `Nothing else is new. Reply in chat with bschat send, not here.`].join("\n");
154
+ if (await deliver(name, exec, wake, summary, "process", 0, log, ""))
155
+ writeState(name, { ...readState(name), watch_process_woken: lag.version });
156
+ return;
157
+ }
145
158
  if (once)
146
159
  log("nothing new");
147
160
  return;
@@ -183,39 +196,23 @@ async function wakeOnce(name, exec, requeueAfter, followDelay, maxUnanswered, lo
183
196
  return;
184
197
  }
185
198
  }
199
+ const lag = await processLag(name, readState(name), true, log);
186
200
  const summary = u.text.split("\n")[0].replace(/^\[bschat\] (Delivered by your BenignSwarm watcher, not typed by the user\. )?/, "");
187
201
  const wake = [
188
202
  `[bschat] Wake-up from your BenignSwarm watcher, not typed by the user.`,
189
203
  operatorNew ? `A human operator wrote to you directly.` : null,
204
+ lag ? processLine(lag) : null,
190
205
  `New since you last looked: ${summary}`,
191
206
  `Run these, in order, to read it all:`,
192
207
  ...u.readCommands.map((c) => ` ${c}`),
193
208
  `Reply in chat with bschat send, not here. Your role and the project's process: bschat me, bschat process.`,
194
209
  ].filter(Boolean).join("\n");
195
- if (exec) {
196
- const total = u.counts.messages + u.counts.items + u.counts.followed + u.counts.digest;
197
- const cmd = exec.replaceAll("{count}", String(total)).replaceAll("{summary}", shellQuote(summary)).replaceAll("{text}", shellQuote(wake));
198
- log(`${operatorNew ? "operator message; " : stale ? "re-waking after timeout; " : ""}[${u.tier}] queueing wake-up: ${summary}`);
199
- const code = await run(cmd, wake, { BSCHAT_TEXT: wake, BSCHAT_SUMMARY: summary, BSCHAT_COUNT: String(total) });
200
- if (code !== 0) {
201
- // The agent was NOT woken. Leave nothing pending so the next poll tries again.
202
- log(`wake command exited ${code}; will retry next poll. If this repeats, the harness needs environment the LaunchAgent lacks (see --env).`);
203
- return;
204
- }
205
- // Tell the server a wake-up was queued, so it can tell a busy agent from a broken wake path
206
- // (no harness activity long after). Best effort: a failure here must not block waking.
207
- try {
208
- await Client.forAgent(loadAgent(name), undefined, { presence: false }).call("POST", "/agents/me/wake", { queued_at: new Date().toISOString(), reason: summary.slice(0, 300), tier: u.tier });
209
- }
210
- catch (e) {
211
- log(`could not report the wake-up to the server: ${e.message}`);
212
- }
213
- }
214
- else {
215
- process.stdout.write(wake + "\n");
216
- }
210
+ const total = u.counts.messages + u.counts.items + u.counts.followed + u.counts.digest;
211
+ if (!(await deliver(name, exec, wake, summary, u.tier, total, log, operatorNew ? "operator message; " : stale ? "re-waking after timeout; " : "")))
212
+ return;
217
213
  writeState(name, {
218
214
  ...readState(name),
215
+ ...(lag ? { watch_process_woken: lag.version } : {}),
219
216
  watch_pending: { at: Date.now(), inbox_after: st.inbox_after, channel_read: st.channel_read ?? {} },
220
217
  watch_operator_at: u.latestOperatorAt ?? st.watch_operator_at,
221
218
  watch_followed_since: undefined,
@@ -224,6 +221,53 @@ async function wakeOnce(name, exec, requeueAfter, followDelay, maxUnanswered, lo
224
221
  if (stale && unanswered + 1 >= maxUnanswered)
225
222
  log(`${unanswered + 1} consecutive wake-ups unanswered; one more timeout and this watcher goes dormant until the agent reads`);
226
223
  }
224
+ /** Runs the wake command (or prints the wake-up without one). False when the command failed: nothing was delivered. */
225
+ async function deliver(name, exec, wake, summary, tier, total, log, prefix) {
226
+ if (!exec) {
227
+ process.stdout.write(wake + "\n");
228
+ return true;
229
+ }
230
+ const cmd = exec.replaceAll("{count}", String(total)).replaceAll("{summary}", shellQuote(summary)).replaceAll("{text}", shellQuote(wake));
231
+ log(`${prefix}[${tier}] queueing wake-up: ${summary}`);
232
+ const code = await run(cmd, wake, { BSCHAT_TEXT: wake, BSCHAT_SUMMARY: summary, BSCHAT_COUNT: String(total) });
233
+ if (code !== 0) {
234
+ // The agent was NOT woken. Leave nothing pending so the next poll tries again.
235
+ log(`wake command exited ${code}; will retry next poll. If this repeats, the harness needs environment the LaunchAgent lacks (see --env).`);
236
+ return false;
237
+ }
238
+ // Tell the server a wake-up was queued, so it can tell a busy agent from a broken wake path
239
+ // (no harness activity long after). A failure here is logged; the agent was woken regardless.
240
+ try {
241
+ await Client.forAgent(loadAgent(name), undefined, { presence: false }).call("POST", "/agents/me/wake", { queued_at: new Date().toISOString(), reason: summary.slice(0, 300), tier });
242
+ }
243
+ catch (e) {
244
+ log(`could not report the wake-up to the server: ${e.message}`);
245
+ }
246
+ return true;
247
+ }
248
+ const processLine = (lag) => `The project process changed: it is version ${lag.version} now and ${lag.seen ? `you last read version ${lag.seen}` : "you have not read it"}. Read it first: bschat process`;
249
+ const PROCESS_CHECK_MS = 5 * 60_000;
250
+ /**
251
+ * The current process version and the one this agent last read (GET /me), when the agent is
252
+ * behind. Checked at most every five minutes, and fresh whenever a wake-up is about to go out.
253
+ * Account-scoped agents have no project process and are never behind.
254
+ */
255
+ async function processLag(name, st, fresh, log) {
256
+ let p = st.watch_process;
257
+ if (fresh || !p || Date.now() - p.checked_at > PROCESS_CHECK_MS) {
258
+ try {
259
+ const me = await Client.forAgent(loadAgent(name), undefined, { presence: false }).call("GET", "/me");
260
+ const proc = me.process;
261
+ p = proc ? { version: proc.version, seen: proc.seen_version, checked_at: Date.now() } : { version: 0, seen: null, checked_at: Date.now() };
262
+ writeState(name, { ...readState(name), watch_process: p });
263
+ }
264
+ catch (e) {
265
+ log(`could not check the process version: ${e.message}`);
266
+ return null;
267
+ }
268
+ }
269
+ return p.version > 0 && (p.seen ?? 0) < p.version ? { version: p.version, seen: p.seen } : null;
270
+ }
227
271
  function shellQuote(s) {
228
272
  return `'${s.replace(/'/g, `'\\''`)}'`;
229
273
  }
@@ -1,6 +1,6 @@
1
1
  import { spawnSync } from "node:child_process";
2
2
  import { readFileSync } from "node:fs";
3
- import { str } from "../args.js";
3
+ import { bool, str } from "../args.js";
4
4
  import { Client } from "../client.js";
5
5
  import { loadAgent, resolveAgentName, resolveModel } from "../config.js";
6
6
  import { CliError } from "../errors.js";
@@ -42,12 +42,13 @@ export async function wu(p, out) {
42
42
  };
43
43
  const tags = (u) => (u.tags.length ? u.tags.map((t) => `#${t}`).join(" ") : "(untagged)");
44
44
  const fmt = (u) => {
45
- const flags = [u.assigned_by ? `assigned by ${u.assigned_by}` : null, u.preferred_name ? `reserved for ${u.preferred_name}` : null, u.hold ? "held" : null, u.milestone ? `milestone ${u.milestone}` : null, u.target ? `lands in ${u.target}` : null, u.replay_of ? "REPLAY" : null, u.trial_tags?.length ? `trial on ${u.trial_tags.map((t) => `#${t}`).join(" ")}` : null].filter(Boolean).join(" · ");
45
+ const flags = [u.assigned_by ? `assigned by ${u.assigned_by}` : null, u.preferred_name ? `reserved for ${u.preferred_name}` : null, u.hold && u.status === "assigned" ? "held" : null, u.waiting_on ? `waits on #${u.waiting_on}` : null, u.milestone ? `milestone ${u.milestone}` : null, u.target ? `lands in ${u.target}` : null, u.replay_of ? "REPLAY" : null, u.trial_tags?.length ? `trial on ${u.trial_tags.map((t) => `#${t}`).join(" ")}` : null].filter(Boolean).join(" · ");
46
46
  const reviewers = u.reviewers.map((r) => `${r.name}${r.tags.length ? ` for ${r.tags.map((t) => `#${t}`).join(" ")}` : ""}`).join(", ");
47
47
  const approvals = u.approvals.map((a) => a.name).join(", ");
48
48
  return [
49
49
  `WU #${u.number} [${u.status}] ${tags(u)} ${u.title}${flags ? ` (${flags})` : ""}`,
50
50
  ` owner ${u.owner_name || "unassigned (queued)"}${reviewers ? ` · reviewers ${reviewers}` : ""}${approvals ? ` · approved by ${approvals}` : ""}${u.uncovered?.length ? ` · awaiting ${u.uncovered.map((t) => `#${t}`).join(" ")}` : ""}`,
51
+ u.question ? ` QUESTION for ${u.question.level === "expert" ? `a ${u.question.roles.join(" or ")}` : "the operator"} (asked by ${u.question.asked_by}${u.question.passed_by ? `, passed up by ${u.question.passed_by}` : ""}): ${u.question.text}` : null,
51
52
  ` ${u.branch ? `${u.branch}${u.head ? ` @ ${u.head}` : ""}` : "no branch recorded"}${u.worktree ? ` in ${u.worktree.replace(/^\/(Users|home)\/[^/]+\//, "~/")}` : ""}${u.pr_url ? ` · ${u.pr_url}` : ""}${u.merged_sha ? ` · merged ${u.merged_sha}` : ""}${u.evidence.length ? ` · evidence ${u.evidence.map((e) => `evidence:${e}`).join(" ")}` : ""}`,
52
53
  u.scope ? ` scope: ${u.scope}` : null,
53
54
  ].filter(Boolean).join("\n");
@@ -149,6 +150,29 @@ export async function wu(p, out) {
149
150
  out.print(`${fmt(r.unit)}\nReopened: continue on the same branch and resubmit this unit.`, r);
150
151
  return;
151
152
  }
153
+ case "ask":
154
+ case "rule": {
155
+ const text = (p.positionals.slice(3).join(" ") || str(p.flags, sub === "ask" ? "question" : "ruling") || "").trim();
156
+ if (!text)
157
+ throw new CliError("usage", sub === "ask" ? 'wu ask <n> "the decision this unit cannot move without"' : 'wu rule <n> "what was decided"');
158
+ const r = await client.call("POST", `${base}/${num()}/${sub}`, sub === "ask" ? { question: text } : { ruling: text });
159
+ const q = r.unit.question;
160
+ out.print(`${fmt(r.unit)}\n${sub === "rule" ? "Ruled; the asker, owner and reviewers were told." : q.level === "expert" ? `Asked a ${q.roles.join(" or ")}; it goes to the operator if nobody rules in time.` : "Asked the operator."}`, r);
161
+ return;
162
+ }
163
+ case "escalate": {
164
+ const r = await client.call("POST", `${base}/${num()}/question/escalate`, { note: str(p.flags, "note") ?? "" });
165
+ out.print(`${fmt(r.unit)}\nPassed to the operator.`, r);
166
+ return;
167
+ }
168
+ case "wait": {
169
+ const on = str(p.flags, "on");
170
+ if (!on && !bool(p.flags, "clear"))
171
+ throw new CliError("usage", 'wu wait <n> --on <m> [--note ".."] (or --clear)');
172
+ const r = await client.call("POST", `${base}/${num()}/wait`, { on: on ? Number(on) : null, note: str(p.flags, "note") ?? "" });
173
+ out.print(fmt(r.unit), r);
174
+ return;
175
+ }
152
176
  case "supersede": {
153
177
  const by = str(p.flags, "by");
154
178
  if (!by)
package/dist/help.js CHANGED
@@ -63,6 +63,10 @@ Agent commands
63
63
  bschat wu proceed <n> --note ".." reviewer: this step is good, carry on; back to the owner, NOT an approval
64
64
  bschat wu reopen <n> --note ".." owner or reviewer: withdraw an unmerged approval (verification failed); resubmit the same unit
65
65
  bschat wu supersede <n> --by <m> owner or assigner: this unit continues as #m; anyone blocked on #n now waits on #m
66
+ bschat wu ask <n> "question" owner, reviewer or assigner: a decision this unit cannot move without (tag expert first, then the operator)
67
+ bschat wu rule <n> "decision" the tag's expert: answer an open question (operator questions are answered in the console)
68
+ bschat wu escalate <n> [--note ..] the tag's expert: pass the question to the operator
69
+ bschat wu wait <n> --on <m> | --clear owner or assigner: this unit cannot move until #m closes; reminders pause meanwhile
66
70
  bschat wu tags <n> --add a --remove b retag (owner before review, a reviewer during it; may add a reviewer)
67
71
  bschat wu done <n> --merged <sha> [--keep-worktree] after approval; verifies the sha is on the target; removes the unit's clean worktree
68
72
  bschat wu abandon <n> [--note ..] wu list [--all] / wu show <n> for state and timeline
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const CLI_VERSION = "0.12.18";
1
+ export const CLI_VERSION = "0.12.19";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "benignswarm",
3
- "version": "0.12.18",
3
+ "version": "0.12.19",
4
4
  "description": "bschat: chat, status board and evidence store for coding agents (benignswarm.org)",
5
5
  "license": "UNLICENSED",
6
6
  "repository": {