benignswarm 0.12.77 → 0.12.79
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/admin-index.js +2 -2
- package/dist/args.js +1 -1
- package/dist/brief.js +35 -0
- package/dist/commands/admin.js +3 -3
- package/dist/commands/evidence.js +15 -3
- package/dist/commands/hook.js +16 -1
- package/dist/commands/watch.js +88 -37
- package/dist/commands/wu.js +27 -4
- package/dist/help.js +12 -7
- package/dist/index.js +6 -4
- package/dist/version.js +1 -1
- package/package.json +1 -1
package/dist/admin-index.js
CHANGED
|
@@ -27,8 +27,8 @@ async function main(argv) {
|
|
|
27
27
|
await admin({ ...p, positionals: ["admin", ...p.positionals] }, out);
|
|
28
28
|
return 0;
|
|
29
29
|
}
|
|
30
|
-
main(process.argv.slice(2)).then((code) => process.
|
|
30
|
+
main(process.argv.slice(2)).then((code) => { process.exitCode = code; }, (err) => {
|
|
31
31
|
const e = err instanceof CliError ? { error: err.code, message: err.message, hint: err.hint } : { error: "internal", message: err instanceof Error ? err.stack ?? err.message : String(err) };
|
|
32
|
+
process.exitCode = 1;
|
|
32
33
|
process.stderr.write(JSON.stringify(e) + "\n");
|
|
33
|
-
process.exit(1);
|
|
34
34
|
});
|
package/dist/args.js
CHANGED
|
@@ -3,7 +3,7 @@ import { CliError } from "./errors.js";
|
|
|
3
3
|
// These options accept comma-separated collections, so repeating them should
|
|
4
4
|
// append another collection instead of discarding earlier values.
|
|
5
5
|
export const LIST_FLAGS = ["tags", "projects", "evidence", "statuses", "depends-on", "default-tags", "units", "waits-on", "needs", "exclude", "remove", "post", "harness", "variant", "requires"];
|
|
6
|
-
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", "unacked-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", "default-tags", "source", "by", "on", "question", "ruling", "gaps", "unit", "units", "blocks", "sla", "takeover", "max-open", "max-in-progress", "require-scope", "require-evidence", "default-approver", "merged-by", "integrator-role", "require-rebased", "require-merge-commit", "require-pushed", "quiet", "summary", "meaning", "expert-role", "reviews", "works", "trials", "email", "repeat", "summary-minutes", "churn", "unmet", "require-cited-changes", "checks-every", "propose", "waits-on", "sandbox", "thread", "turn-timeout", "session", "plain", "if-yes", "if-no", "ssh", "variant", "count", "needs", "min-ram", "exclude", "carry", "from", "to-ssh", "wait", "writable", "for", "until", "reason", "at", "requires", "priority", "informs", "amend", "waive-informs", "text"];
|
|
6
|
+
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", "unacked-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", "default-tags", "source", "by", "on", "question", "ruling", "gaps", "unit", "units", "blocks", "sla", "takeover", "max-open", "max-in-progress", "require-scope", "require-evidence", "default-approver", "merged-by", "integrator-role", "require-rebased", "require-merge-commit", "require-pushed", "quiet", "summary", "meaning", "expert-role", "reviews", "works", "trials", "email", "repeat", "summary-minutes", "churn", "unmet", "require-cited-changes", "checks-every", "propose", "waits-on", "sandbox", "thread", "turn-timeout", "session", "plain", "if-yes", "if-no", "ssh", "variant", "count", "needs", "min-ram", "exclude", "carry", "from", "to-ssh", "wait", "writable", "for", "until", "reason", "at", "requires", "priority", "informs", "amend", "waive-informs", "text", "kind", "claim", "decision"];
|
|
7
7
|
export const BOOL_FLAGS = ["latest", "no-restart", "json", "follow", "account", "help", "version", "broadcast", "create-channels", "read-account-status", "replace-key", "mentions-me", "no-skill", "replace", "unread", "pending", "force", "no-hooks", "yes", "open", "bind-here", "peek", "once", "launchd", "full", "no-bind", "all", "here", "keep-worktree", "prune", "abandon", "defer", "hold", "clear", "met", "shared", "archive", "approve", "turn", "service", "print-hooks", "create", "rotate", "codex-userns", "bwrap-userns", "print-apparmor", "cancel"];
|
|
8
8
|
export function parse(argv) {
|
|
9
9
|
const options = {};
|
package/dist/brief.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Client } from "./client.js";
|
|
2
|
+
import { loadAgent, resolveAgentName } from "./config.js";
|
|
3
|
+
export async function fetchRecoveryBrief(nameOrRef) {
|
|
4
|
+
const name = resolveAgentName(nameOrRef);
|
|
5
|
+
const creds = loadAgent(name);
|
|
6
|
+
const response = await Client.forAgent(creds, undefined, { presence: false }).call("GET", "/agents/me/brief");
|
|
7
|
+
return response.brief;
|
|
8
|
+
}
|
|
9
|
+
export function formatRecoveryBrief(brief) {
|
|
10
|
+
const lines = [`[bschat] Resume brief for ${brief.agent}`, `Role: ${brief.role}`];
|
|
11
|
+
if (brief.projects.length)
|
|
12
|
+
lines.push(`Process: ${brief.projects.map((p) => `${p.name} ${p.process} (${Array.isArray(p.changed_since_last_read) ? `changed since you last read: ${p.changed_since_last_read.join("; ")}` : p.changed_since_last_read})`).join("; ")}`);
|
|
13
|
+
lines.push("Units:");
|
|
14
|
+
lines.push(...(brief.units.length ? brief.units.map((u) => ` [${u.state}] ${u.project} WU #${u.number} ${u.title} — ${u.next}`) : [" none"]));
|
|
15
|
+
lines.push("Reviews waiting on you:");
|
|
16
|
+
lines.push(...(brief.reviews.length ? brief.reviews.map((r) => ` ${r.project} ${r.slice ? `slice ${r.slice}` : `WU #${r.number}`} ${r.title} — ${r.next}`) : [" none"]));
|
|
17
|
+
lines.push("Open questions and asks:");
|
|
18
|
+
lines.push(...[...brief.questions.map((q) => ` ${q.project} WU #${q.number}: ${q.question} — ${q.next}`), ...brief.asks.map((a) => ` ${a.project} ask ${a.id}: ${a.question} (${a.blocks}) — ${a.next}`)].slice(0, 10));
|
|
19
|
+
if (!brief.questions.length && !brief.asks.length)
|
|
20
|
+
lines.push(" none");
|
|
21
|
+
lines.push("Slices:");
|
|
22
|
+
lines.push(...(brief.slices.length ? brief.slices.map((s) => ` ${s.project} ${s.key}: ${s.title} — ${s.next}`) : [" none"]));
|
|
23
|
+
lines.push("Recent decisions:");
|
|
24
|
+
lines.push(...(brief.decisions.length ? brief.decisions.map((d) => ` ${d.project} ${d.slice} WU #${d.unit} (${d.source}): ${d.ruling}`) : [" none"]));
|
|
25
|
+
return lines.join("\n");
|
|
26
|
+
}
|
|
27
|
+
export const recoveryBriefUnavailableText = "[bschat] Recovery brief unavailable after compaction. Run bschat resume to retrieve the current agent state.";
|
|
28
|
+
export function recoveryBriefWasDelivered(brief, sent) {
|
|
29
|
+
return !!brief && sent;
|
|
30
|
+
}
|
|
31
|
+
export async function resume(p, out) {
|
|
32
|
+
const name = resolveAgentName(typeof p.flags.as === "string" ? p.flags.as : undefined);
|
|
33
|
+
const brief = await fetchRecoveryBrief(name);
|
|
34
|
+
out.print(formatRecoveryBrief(brief), brief);
|
|
35
|
+
}
|
package/dist/commands/admin.js
CHANGED
|
@@ -82,10 +82,10 @@ export async function admin(p, out) {
|
|
|
82
82
|
return milestonesWith(adminClient(p), action, rest[0], p, out);
|
|
83
83
|
}
|
|
84
84
|
case "milestone": {
|
|
85
|
-
// bschat-admin milestone <project> add|edit|show|close|reopen|review|verdict|gap-units <key> ...
|
|
85
|
+
// bschat-admin milestone <project> add|edit|show|decide|close|reopen|review|verdict|gap-units <key> ...
|
|
86
86
|
if (!action)
|
|
87
|
-
throw new CliError("usage", "milestone <project> <add|edit|show|close|reopen|review|verdict|gap-units> <key> ...");
|
|
88
|
-
return milestoneWith(adminClient(p), action, rest[0], rest[1], p, out);
|
|
87
|
+
throw new CliError("usage", "milestone <project> <add|edit|show|decide|close|reopen|review|verdict|gap-units> <key> ...");
|
|
88
|
+
return milestoneWith(adminClient(p), action, rest[0], rest[1], p, out, rest.slice(2));
|
|
89
89
|
}
|
|
90
90
|
case "needs":
|
|
91
91
|
return needsAdmin(p, out);
|
|
@@ -43,6 +43,12 @@ export async function evidence(p, out) {
|
|
|
43
43
|
const label = str(p.flags, "label");
|
|
44
44
|
if (label)
|
|
45
45
|
headers["x-bschat-label"] = label;
|
|
46
|
+
const kind = str(p.flags, "kind");
|
|
47
|
+
if (kind)
|
|
48
|
+
headers["x-bschat-kind"] = kind;
|
|
49
|
+
const claim = str(p.flags, "claim");
|
|
50
|
+
if (claim)
|
|
51
|
+
headers["x-bschat-claim"] = claim;
|
|
46
52
|
const res = await fetch(`${creds.url}/projects/${project}/evidence`, { method: "POST", headers, body: new Uint8Array(bytes) });
|
|
47
53
|
const json = await res.json();
|
|
48
54
|
if (!res.ok)
|
|
@@ -51,9 +57,15 @@ export async function evidence(p, out) {
|
|
|
51
57
|
return;
|
|
52
58
|
}
|
|
53
59
|
if (sub === "list") {
|
|
54
|
-
const
|
|
55
|
-
|
|
56
|
-
|
|
60
|
+
const qs = new URLSearchParams({ limit: str(p.flags, "limit") ?? "50" });
|
|
61
|
+
for (const flag of ["unit", "kind"]) {
|
|
62
|
+
const value = str(p.flags, flag);
|
|
63
|
+
if (value !== undefined)
|
|
64
|
+
qs.set(flag, value);
|
|
65
|
+
}
|
|
66
|
+
const r = await client.call("GET", `/projects/${project}/evidence?${qs}`);
|
|
67
|
+
const rows = r.evidence.map((e) => ({ id: e.id, filename: e.filename, size: e.size, kind: e.kind, claim: e.claim, by: e.agent_name, label: e.label, sha256: e.sha256.slice(0, 12), created_at: e.created_at }));
|
|
68
|
+
out.print(table(rows, ["id", "filename", "size", "kind", "claim", "by", "label", "sha256", "created_at"]), r);
|
|
57
69
|
return;
|
|
58
70
|
}
|
|
59
71
|
if (sub === "info") {
|
package/dist/commands/hook.js
CHANGED
|
@@ -7,6 +7,7 @@ import { fmtMessage } from "../output.js";
|
|
|
7
7
|
import { readState, writeState } from "../state.js";
|
|
8
8
|
import { goalFromClaudeTranscript, modelFromClaudeTranscript } from "../model.js";
|
|
9
9
|
import { conversationAgent, sessionAgent, syncFromWatchers } from "../sessions.js";
|
|
10
|
+
import { fetchRecoveryBrief, formatRecoveryBrief, recoveryBriefUnavailableText } from "../brief.js";
|
|
10
11
|
const HEARTBEAT_MS = 60_000;
|
|
11
12
|
/** Reads the harness's hook payload from stdin without blocking when there is none. */
|
|
12
13
|
function readStdinJson() {
|
|
@@ -330,7 +331,10 @@ export async function hook(p) {
|
|
|
330
331
|
// Standing rules die with the context. On SessionStart (startup, resume, and after a compaction)
|
|
331
332
|
// re-deliver the role description and the project's process when the agent has not seen this
|
|
332
333
|
// version, and record that it was shown.
|
|
333
|
-
const
|
|
334
|
+
const compacted = input?.source === "compact";
|
|
335
|
+
const standing = harness === "claude-code" && event === "SessionStart"
|
|
336
|
+
? compacted ? await recoveryBrief(name) : await standingRules(name, false)
|
|
337
|
+
: null;
|
|
334
338
|
// The hook firing is proof the harness is working; tell the server, at most once a minute.
|
|
335
339
|
// The session goal (/goal) rides along from the transcript, and a change goes out at once.
|
|
336
340
|
if (harness === "claude-code") {
|
|
@@ -362,6 +366,17 @@ export async function hook(p) {
|
|
|
362
366
|
}
|
|
363
367
|
await acknowledgeStanding(name, standing, formatted.acknowledge);
|
|
364
368
|
}
|
|
369
|
+
/** After compaction, restore agent-specific state instead of repeating the standing agreements. */
|
|
370
|
+
export async function recoveryBrief(name) {
|
|
371
|
+
try {
|
|
372
|
+
const text = formatRecoveryBrief(await fetchRecoveryBrief(name));
|
|
373
|
+
return { text, deferredText: text, acknowledge: false, version: 0, project: null };
|
|
374
|
+
}
|
|
375
|
+
catch (e) {
|
|
376
|
+
process.stderr.write(`bschat: could not fetch recovery brief: ${e.message}\n`);
|
|
377
|
+
return { text: recoveryBriefUnavailableText, deferredText: recoveryBriefUnavailableText, acknowledge: false, version: 0, project: null };
|
|
378
|
+
}
|
|
379
|
+
}
|
|
365
380
|
/**
|
|
366
381
|
* The role and process the agent must hold after a new session or a compaction, when it has not
|
|
367
382
|
* seen this process version (or always after a compaction). Records that it was shown.
|
package/dist/commands/watch.js
CHANGED
|
@@ -20,6 +20,7 @@ import { acquireWatchLock } from "../lock.js";
|
|
|
20
20
|
import { formatUpdates, gatherUpdates, reportDelivery } from "./hook.js";
|
|
21
21
|
import { readState, writeState } from "../state.js";
|
|
22
22
|
import { probeCapabilities } from "../capabilities.js";
|
|
23
|
+
import { fetchRecoveryBrief, formatRecoveryBrief, recoveryBriefUnavailableText, recoveryBriefWasDelivered } from "../brief.js";
|
|
23
24
|
/** Reports host probes without refreshing the agent's presence; the host identity is still explicit. */
|
|
24
25
|
export async function reportWatcherCapabilities(creds, project, definitions, cwd = process.cwd()) {
|
|
25
26
|
const results = probeCapabilities(definitions, cwd);
|
|
@@ -92,13 +93,25 @@ export async function watch(p, out) {
|
|
|
92
93
|
if (!exec && !once)
|
|
93
94
|
throw new CliError("usage", 'watch --exec "<command>" [--interval 30] | watch --once (print and exit) | watch --exec ... --service (launchd on macOS, systemd on Linux)');
|
|
94
95
|
const log = (m) => process.stderr.write(`${new Date().toISOString()} bschat watch[${name}]: ${m}\n`);
|
|
96
|
+
let stopping = false;
|
|
97
|
+
let stoppingCode = 0;
|
|
98
|
+
let signalStop = () => { };
|
|
99
|
+
const stopped = new Promise((resolve) => { signalStop = resolve; });
|
|
100
|
+
let releaseWatchLock;
|
|
101
|
+
const finish = (code) => {
|
|
102
|
+
if (stopping)
|
|
103
|
+
return;
|
|
104
|
+
stopping = true;
|
|
105
|
+
stoppingCode = code;
|
|
106
|
+
releaseWatchLock?.();
|
|
107
|
+
signalStop();
|
|
108
|
+
};
|
|
95
109
|
if (!once) {
|
|
96
110
|
// Only one long-running watcher per identity on this machine; a second one exits here.
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
process.
|
|
100
|
-
process.
|
|
101
|
-
process.on("SIGTERM", () => bye(143));
|
|
111
|
+
releaseWatchLock = acquireWatchLock(name);
|
|
112
|
+
process.on("exit", () => releaseWatchLock?.());
|
|
113
|
+
process.once("SIGINT", () => finish(130));
|
|
114
|
+
process.once("SIGTERM", () => finish(143));
|
|
102
115
|
}
|
|
103
116
|
log(`watching${exec ? `, will run: ${exec}` : ""} every ${interval}s (${full ? "full text" : turnMode ? `turn mode, at most ${turnTimeout} min a turn` : "single wake-up"} mode)`);
|
|
104
117
|
// Harness liveness: the files the harness writes while it works, found from the wake command's
|
|
@@ -122,9 +135,12 @@ export async function watch(p, out) {
|
|
|
122
135
|
let lastKeyCheck = 0;
|
|
123
136
|
const ctl = { turn: null, failedAt: 0, loggedRunning: null, pausedUntil: 0, pausedAt: 0 };
|
|
124
137
|
const probe = turn ? probeFor(turn.harness, turn.session, name) : null;
|
|
125
|
-
|
|
138
|
+
let resumeBriefDelivered = false;
|
|
139
|
+
while (!stopping) {
|
|
126
140
|
if (activity && heartbeatClient)
|
|
127
141
|
lastSample = await heartbeatIfActive(heartbeatClient, activity, lastSample, interval, log);
|
|
142
|
+
if (stopping)
|
|
143
|
+
return stoppingCode;
|
|
128
144
|
if (scanCreds.project && Date.now() - lastScan > 3_600_000) {
|
|
129
145
|
lastScan = Date.now();
|
|
130
146
|
try {
|
|
@@ -183,64 +199,87 @@ export async function watch(p, out) {
|
|
|
183
199
|
await Client.forAgent(loadAgent(name), undefined, { presence: false }).call("GET", "/me");
|
|
184
200
|
}
|
|
185
201
|
catch (e) {
|
|
186
|
-
if (e.code === "unauthorized")
|
|
202
|
+
if (e.code === "unauthorized") {
|
|
187
203
|
stopRevokedWatcher(name, log);
|
|
204
|
+
finish(0);
|
|
205
|
+
return stoppingCode;
|
|
206
|
+
}
|
|
188
207
|
log(`could not check this agent's key: ${e.message}`);
|
|
189
208
|
}
|
|
209
|
+
if (stopping)
|
|
210
|
+
return stoppingCode;
|
|
190
211
|
}
|
|
191
212
|
if (!full) {
|
|
192
213
|
try {
|
|
193
214
|
if (probe)
|
|
194
|
-
await turnStep(ctl, probe, turnTimeout, log, (sink) =>
|
|
195
|
-
|
|
196
|
-
|
|
215
|
+
await turnStep(ctl, probe, turnTimeout, log, async (sink) => {
|
|
216
|
+
const result = await wakeOnce(name, exec, unackedAfter, followDelay, log, str(p.flags, "model"), once, sink, !resumeBriefDelivered);
|
|
217
|
+
resumeBriefDelivered = resumeBriefDelivered || result.recoveryBriefDelivered;
|
|
218
|
+
}, name);
|
|
219
|
+
else {
|
|
220
|
+
const result = await wakeOnce(name, exec, unackedAfter, followDelay, log, str(p.flags, "model"), once, undefined, !resumeBriefDelivered);
|
|
221
|
+
resumeBriefDelivered = resumeBriefDelivered || result.recoveryBriefDelivered;
|
|
222
|
+
}
|
|
197
223
|
}
|
|
198
224
|
catch (e) {
|
|
199
|
-
if (e.code === "unauthorized" && !once)
|
|
225
|
+
if (e.code === "unauthorized" && !once) {
|
|
200
226
|
stopRevokedWatcher(name, log);
|
|
227
|
+
finish(0);
|
|
228
|
+
return stoppingCode;
|
|
229
|
+
}
|
|
201
230
|
throw e;
|
|
202
231
|
}
|
|
232
|
+
if (stopping)
|
|
233
|
+
return stoppingCode;
|
|
203
234
|
if (once)
|
|
204
235
|
return;
|
|
205
|
-
await
|
|
236
|
+
await waitIntervalOrStop(interval * 1000, stopped);
|
|
206
237
|
continue;
|
|
207
238
|
}
|
|
208
239
|
const u = await gatherUpdates(name, { force: true, model: str(p.flags, "model"), delivery: "watch" });
|
|
240
|
+
if (stopping)
|
|
241
|
+
return stoppingCode;
|
|
209
242
|
if (u) {
|
|
210
|
-
const
|
|
211
|
-
const
|
|
243
|
+
const recovery = resumeBriefDelivered ? null : await recoveryBriefText(name, log);
|
|
244
|
+
const update = resumeBriefDelivered ? u : formatUpdates(u, [recovery ?? recoveryBriefUnavailableText]);
|
|
245
|
+
const total = update.counts.messages + update.counts.items + update.counts.followed + update.counts.digest;
|
|
246
|
+
const summary = update.text.split("\n")[0].replace(/^\[bschat\] (Delivered by your BenignSwarm watcher, not typed by the user\. )?/, "");
|
|
247
|
+
let delivered = true;
|
|
212
248
|
if (exec) {
|
|
213
|
-
const cmd = exec.replaceAll("{count}", String(total)).replaceAll("{summary}", shellQuote(summary)).replaceAll("{text}", shellQuote(
|
|
249
|
+
const cmd = exec.replaceAll("{count}", String(total)).replaceAll("{summary}", shellQuote(summary)).replaceAll("{text}", shellQuote(update.text));
|
|
214
250
|
log(`new activity (${summary}); running: ${cmd}`);
|
|
215
|
-
const code = await run(cmd,
|
|
216
|
-
if (code !== 0)
|
|
251
|
+
const code = await run(cmd, update.text, { BSCHAT_TEXT: update.text, BSCHAT_SUMMARY: summary, BSCHAT_COUNT: String(total) });
|
|
252
|
+
if (code !== 0) {
|
|
217
253
|
log(`command exited ${code}`);
|
|
254
|
+
delivered = false;
|
|
255
|
+
}
|
|
218
256
|
}
|
|
219
257
|
else {
|
|
220
|
-
process.stdout.write(
|
|
258
|
+
process.stdout.write(update.text + "\n");
|
|
221
259
|
}
|
|
222
260
|
// Full mode delivers the update payload directly instead of using the wake path, so
|
|
223
261
|
// record the same actual payload bytes and kinds through the hook's existing metric call.
|
|
224
|
-
await reportDelivery(name,
|
|
262
|
+
await reportDelivery(name, update.text, update.delivery.by_kind, "watch");
|
|
263
|
+
resumeBriefDelivered = resumeBriefDelivered || recoveryBriefWasDelivered(recovery, delivered);
|
|
264
|
+
if (stopping)
|
|
265
|
+
return stoppingCode;
|
|
225
266
|
}
|
|
226
267
|
else if (once) {
|
|
227
268
|
log("nothing new");
|
|
228
269
|
}
|
|
229
270
|
if (once)
|
|
230
271
|
return;
|
|
231
|
-
await
|
|
272
|
+
await waitIntervalOrStop(interval * 1000, stopped);
|
|
232
273
|
}
|
|
274
|
+
return stoppingCode;
|
|
233
275
|
}
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
* cursors moved because the agent was reading while it worked, not because it saw the wake-up.
|
|
242
|
-
*/
|
|
243
|
-
async function wakeOnce(name, exec, unackedAfter, followDelay, log, model, once, turnSink) {
|
|
276
|
+
async function waitIntervalOrStop(ms, stopped) {
|
|
277
|
+
let timer;
|
|
278
|
+
await Promise.race([new Promise((resolve) => { timer = setTimeout(resolve, ms); }), stopped]);
|
|
279
|
+
if (timer)
|
|
280
|
+
clearTimeout(timer);
|
|
281
|
+
}
|
|
282
|
+
async function wakeOnce(name, exec, unackedAfter, followDelay, log, model, once, turnSink, includeResumeBrief = false) {
|
|
244
283
|
const state = readState(name);
|
|
245
284
|
const pending = state.watch_pending;
|
|
246
285
|
if (pending) {
|
|
@@ -267,7 +306,7 @@ async function wakeOnce(name, exec, unackedAfter, followDelay, log, model, once,
|
|
|
267
306
|
}
|
|
268
307
|
else if (once)
|
|
269
308
|
log(`wake-up ${st.watch_pending.seq !== undefined ? `#${st.watch_pending.seq} ` : ""}queued ${Math.round(waited / 1000)}s ago and not acknowledged; not queueing another`);
|
|
270
|
-
return;
|
|
309
|
+
return { sent: false, recoveryBriefDelivered: false };
|
|
271
310
|
}
|
|
272
311
|
const u = await gatherUpdates(name, { force: true, model, delivery: "watch", dryRun: true });
|
|
273
312
|
// A process change is news too. Watched harnesses never see the Claude Code hook re-deliver the
|
|
@@ -280,7 +319,7 @@ async function wakeOnce(name, exec, unackedAfter, followDelay, log, model, once,
|
|
|
280
319
|
if (!processNews) {
|
|
281
320
|
if (once)
|
|
282
321
|
log("nothing new");
|
|
283
|
-
return;
|
|
322
|
+
return { sent: false, recoveryBriefDelivered: false };
|
|
284
323
|
}
|
|
285
324
|
}
|
|
286
325
|
else if (u.tier === "digest" && !processNews) {
|
|
@@ -288,7 +327,7 @@ async function wakeOnce(name, exec, unackedAfter, followDelay, log, model, once,
|
|
|
288
327
|
// follow delay so bursts collapse; digest-only channels never wake it on their own.
|
|
289
328
|
if (once)
|
|
290
329
|
log("only digest-level unread; not waking");
|
|
291
|
-
return;
|
|
330
|
+
return { sent: false, recoveryBriefDelivered: false };
|
|
292
331
|
}
|
|
293
332
|
else if (u.tier === "followed" && !processNews) {
|
|
294
333
|
const since = st.watch_followed_since ?? Date.now();
|
|
@@ -298,11 +337,13 @@ async function wakeOnce(name, exec, unackedAfter, followDelay, log, model, once,
|
|
|
298
337
|
if (waited < followDelay * 1000) {
|
|
299
338
|
if (once)
|
|
300
339
|
log(`followed-channel traffic only; waiting (${Math.round(waited / 1000)}/${followDelay}s) before waking`);
|
|
301
|
-
return;
|
|
340
|
+
return { sent: false, recoveryBriefDelivered: false };
|
|
302
341
|
}
|
|
303
342
|
}
|
|
304
343
|
const seq = (st.watch_seq ?? 0) + 1;
|
|
305
344
|
const operatorNew = !!u && u.latestOperatorAt !== null && u.latestOperatorAt !== (st.watch_operator_at ?? null);
|
|
345
|
+
const recovery = includeResumeBrief ? await recoveryBriefText(name, log) : null;
|
|
346
|
+
const recoveryPrompt = includeResumeBrief ? recovery ?? recoveryBriefUnavailableText : null;
|
|
306
347
|
const wakePrefix = [
|
|
307
348
|
...(turnSink
|
|
308
349
|
? [`[bschat] Turn #${seq}, started by your BenignSwarm watcher because you were idle; not typed by the user. It is already acknowledged.`]
|
|
@@ -311,6 +352,7 @@ async function wakeOnce(name, exec, unackedAfter, followDelay, log, model, once,
|
|
|
311
352
|
`First acknowledge it: bschat wake ack ${seq} (no other wake-up comes until you do). If you are in the middle of a task, acknowledge, read, then carry on with the task.`,
|
|
312
353
|
]),
|
|
313
354
|
operatorNew ? `A human operator wrote to you directly.` : null,
|
|
355
|
+
recoveryPrompt,
|
|
314
356
|
processNews ? processLine(lag) : null,
|
|
315
357
|
].filter(Boolean);
|
|
316
358
|
const wakeSuffix = [
|
|
@@ -325,7 +367,7 @@ async function wakeOnce(name, exec, unackedAfter, followDelay, log, model, once,
|
|
|
325
367
|
// the acknowledgement, operator note, process pointer, read commands, and delivery body.
|
|
326
368
|
const line = wake;
|
|
327
369
|
if (!(await deliver(name, exec, wake, line, u ? u.tier : "process", total, log, operatorNew ? "operator message; " : "", seq, turnSink, payload?.delivery.by_kind ?? u?.delivery.by_kind)))
|
|
328
|
-
return;
|
|
370
|
+
return { sent: false, recoveryBriefDelivered: false };
|
|
329
371
|
writeState(name, {
|
|
330
372
|
...readState(name),
|
|
331
373
|
watch_seq: seq,
|
|
@@ -335,6 +377,16 @@ async function wakeOnce(name, exec, unackedAfter, followDelay, log, model, once,
|
|
|
335
377
|
watch_followed_since: undefined,
|
|
336
378
|
watch_dormant_logged_at: undefined,
|
|
337
379
|
});
|
|
380
|
+
return { sent: true, recoveryBriefDelivered: recoveryBriefWasDelivered(recovery, true) };
|
|
381
|
+
}
|
|
382
|
+
async function recoveryBriefText(name, log) {
|
|
383
|
+
try {
|
|
384
|
+
return formatRecoveryBrief(await fetchRecoveryBrief(name));
|
|
385
|
+
}
|
|
386
|
+
catch (e) {
|
|
387
|
+
log(`recovery brief unavailable: ${e.message}`);
|
|
388
|
+
return null;
|
|
389
|
+
}
|
|
338
390
|
}
|
|
339
391
|
/** Runs the wake command (or prints the wake-up without one). False when the command failed: nothing was delivered. */
|
|
340
392
|
async function deliver(name, exec, wake, summary, tier, total, log, prefix, seq, turnSink, kinds = {}) {
|
|
@@ -387,8 +439,7 @@ function stopRevokedWatcher(name, log) {
|
|
|
387
439
|
?? watcherServices().find((s) => { const a = s.args ?? []; const i = a.indexOf("--as"); return a[1] === "watch" && i >= 0 && (a[i + 1] === name || a[i + 1] === bare); });
|
|
388
440
|
log(`this agent's key was revoked (moved to another machine, or retired): stopping and removing ${svc?.label ?? `${label} (no service found; exiting)`}`);
|
|
389
441
|
if (svc)
|
|
390
|
-
removeService(svc);
|
|
391
|
-
process.exit(0);
|
|
442
|
+
removeService(svc);
|
|
392
443
|
}
|
|
393
444
|
const TURN_RETRY_MS = 5 * 60_000;
|
|
394
445
|
const KEY_CHECK_MS = 5 * 60_000;
|
package/dist/commands/wu.js
CHANGED
|
@@ -10,6 +10,18 @@ import { CliError } from "../errors.js";
|
|
|
10
10
|
import { branchAndHead, commitAtTime, ensureReviewWorktree, ensureWorktree, fetchRef, fullSha, isAncestor, remoteHead, removeWorktreeIfClean, repoName, repoParent, verifyMergedCommit, worktreeForBranch } from "../git.js";
|
|
11
11
|
import { resolve } from "node:path";
|
|
12
12
|
import { table } from "../output.js";
|
|
13
|
+
export function assignmentDisposition(unit, to) {
|
|
14
|
+
if (unit.status !== "queued")
|
|
15
|
+
return `Assigned to ${unit.owner_name}; they start it with bschat wu start ${unit.number}.`;
|
|
16
|
+
if (unit.preferred_name)
|
|
17
|
+
return `Reserved for ${unit.preferred_name}, who is busy: theirs when free, open to any qualified worker after the takeover window (--hold keeps it assigned to them).`;
|
|
18
|
+
if (to === "queue")
|
|
19
|
+
return `Queued deliberately; dispatch hands it to the first qualified free worker (or bschat wu take ${unit.number} --to <agent>).`;
|
|
20
|
+
const reasons = unit.dispatch_reasons?.length
|
|
21
|
+
? `\nWhy no worker was selected:\n${unit.dispatch_reasons.map((reason) => `- ${reason}`).join("\n")}`
|
|
22
|
+
: "\nNo eligible worker candidates were found.";
|
|
23
|
+
return `Queued: nobody qualified is free; it goes to the first qualified worker with capacity (or bschat wu take ${unit.number} --to <agent>).${reasons}`;
|
|
24
|
+
}
|
|
13
25
|
/**
|
|
14
26
|
* Work units under the project's process. Work is described by tags from the project's
|
|
15
27
|
* vocabulary; reviewers are whoever is qualified to review those tags.
|
|
@@ -134,7 +146,7 @@ export async function wu(p, out) {
|
|
|
134
146
|
throw new CliError("usage", 'wu assign "<title>" --to <agent|auto|queue> --scope "<what it covers and does not>" [--tags a,b] [--evidence id] [--replay-of <n>]');
|
|
135
147
|
const replay = str(p.flags, "replay-of");
|
|
136
148
|
const r = await client.call("POST", `${base}/assign`, { to, title, scope: str(p.flags, "scope") ?? "", tags: list("tags"), requires: list("requires"), evidence: list("evidence"), replay_of: replay ? Number(replay) : null, branch: str(p.flags, "branch") ?? null, target: str(p.flags, "target") ?? null, milestone: str(p.flags, "milestone") ?? null, hold: !!p.flags.hold, force: !!p.flags.force });
|
|
137
|
-
out.print(`${fmt(r.unit)}\n${r.unit
|
|
149
|
+
out.print(`${fmt(r.unit)}\n${assignmentDisposition(r.unit, to)}`, r);
|
|
138
150
|
return;
|
|
139
151
|
}
|
|
140
152
|
case "take": {
|
|
@@ -637,15 +649,24 @@ export async function milestone(p, out) {
|
|
|
637
649
|
const project = creds.project ?? str(p.flags, "project") ?? process.env.BSCHAT_PROJECT;
|
|
638
650
|
if (!project)
|
|
639
651
|
throw new CliError("no_project", `${creds.agent} is an account-scoped agent; pass --project <name>`);
|
|
640
|
-
return milestoneWith(client, project, p.positionals[1], p.positionals[2], p, out);
|
|
652
|
+
return milestoneWith(client, project, p.positionals[1], p.positionals[2], p, out, p.positionals.slice(3));
|
|
641
653
|
}
|
|
642
654
|
/** One milestone, shared by agents (`bschat milestone`) and the operator (`bschat-admin milestone <project>`). */
|
|
643
|
-
export async function milestoneWith(client, project, sub, key, p, out) {
|
|
655
|
+
export async function milestoneWith(client, project, sub, key, p, out, decisionParts = p.positionals.slice(3)) {
|
|
644
656
|
if (!key)
|
|
645
657
|
throw new CliError("usage", 'milestone show <key> | milestone close <key> --note "how the exit criterion was met" [--evidence id,id] [--abandon | --defer] | milestone reopen <key>');
|
|
646
658
|
// "set" is "edit" (bschat milestone set <key> --priority 5): one slice changed, the rest untouched.
|
|
647
659
|
if (sub === "set")
|
|
648
660
|
sub = "edit";
|
|
661
|
+
if (sub === "decide") {
|
|
662
|
+
const decision = (decisionParts.join(" ") || str(p.flags, "decision") || "").trim();
|
|
663
|
+
const unit = str(p.flags, "unit");
|
|
664
|
+
if (!decision || !unit || !/^\d+$/.test(unit))
|
|
665
|
+
throw new CliError("usage", 'milestone decide <key> "ruling" --unit <n>');
|
|
666
|
+
const r = await client.call("POST", `/projects/${project}/milestones/${key}/decide`, { decision, unit: Number(unit) });
|
|
667
|
+
out.print(`Recorded milestone ${key} decision for WU #${unit}.`, r);
|
|
668
|
+
return;
|
|
669
|
+
}
|
|
649
670
|
if (sub === "add" || sub === "edit") {
|
|
650
671
|
// One slice in, the rest untouched: fetch the list, add or amend the entry, set it back.
|
|
651
672
|
const cur = (await client.call("GET", `/projects/${project}/milestones`)).milestones;
|
|
@@ -682,7 +703,9 @@ export async function milestoneWith(client, project, sub, key, p, out) {
|
|
|
682
703
|
const m = (await client.call("GET", `/projects/${project}/milestones`)).milestones.find((x) => x.key === key);
|
|
683
704
|
if (!m)
|
|
684
705
|
throw new CliError("not_found", `no milestone ${key}`);
|
|
685
|
-
|
|
706
|
+
const detail = await client.call("GET", `/projects/${project}/milestones/${key}`);
|
|
707
|
+
const decisions = (detail.decisions ?? []).map((d) => `\n ${d.created_at.slice(0, 16)} WU #${d.unit_number} (${d.source}, ${d.created_by}): ${d.ruling}`).join("");
|
|
708
|
+
out.print(`${m.key}: ${m.title} [${m.status}${m.status === "open" && !m.ready ? `, waits on ${m.waiting_on.join(", ")}` : ""}]${m.priority !== null && m.priority !== undefined ? `\n priority: ${m.priority}` : ""}\n depends on: ${m.depends_on.join(", ") || "-"}\n default tags: ${(m.default_tags ?? []).map((t) => `#${t}`).join(" ") || "-"}\n units: ${m.units.done} done, ${m.units.open} open, ${m.units.queued} queued of ${m.units.total}${m.review ? `\n closure review: ${m.review.reviewer_name} (${m.review.source}) since ${m.review.requested_at}` : ""}${m.last_verdict && !m.last_verdict.met ? `\n gaps (${m.last_verdict.by}, ${m.last_verdict.at.slice(0, 16)}): ${m.last_verdict.gaps}` : ""}\n exit: ${m.exit || "(not written)"}${m.source ? `\n source: ${m.source} (the full brief; read it when planning this slice)` : ""}${m.closed_at ? `\n closed ${m.closed_at} by ${m.closed_by}: ${m.closed_note}${m.evidence.length ? ` (${m.evidence.map((e) => `evidence:${e}`).join(" ")})` : ""}` : ""}\n decisions:${decisions || " (none)"}`, { ...m, decisions: detail.decisions });
|
|
686
709
|
return;
|
|
687
710
|
}
|
|
688
711
|
if (sub === "close") {
|
package/dist/help.js
CHANGED
|
@@ -19,6 +19,7 @@ Agent commands
|
|
|
19
19
|
bschat logout --as <name>
|
|
20
20
|
bschat identities list saved identities on this machine
|
|
21
21
|
bschat me who am I, role, permissions, channels
|
|
22
|
+
bschat resume compact recovery brief: your units, reviews, asks, slices, decisions and process version
|
|
22
23
|
bschat who [--account] what every agent is doing (--account: all projects)
|
|
23
24
|
bschat status set [--state s] [--goal g] [--task t] [--blocked-on b] [--tags a,b] [--custom '{json}']
|
|
24
25
|
[--checks-every <min>|none] not always on but checking on a schedule: say how often
|
|
@@ -36,7 +37,8 @@ Agent commands
|
|
|
36
37
|
worktree; tags come from the vocabulary; --target is the branch it lands in (default: the
|
|
37
38
|
process target), e.g. a lane branch; wu target <n> <branch|default> changes it before review
|
|
38
39
|
bschat wu assign "<title>" --to <agent|auto|queue> --scope ".." [--tags a,b] [--requires cap,cap] [--force] [--replay-of n] hand out a unit (assigner roles);
|
|
39
|
-
auto queues it when nobody
|
|
40
|
+
auto queues it when nobody fits and reports why candidates were passed over;
|
|
41
|
+
queue waits deliberately and says so; naming a
|
|
40
42
|
busy worker reserves it for them (theirs when free, anyone's after the takeover
|
|
41
43
|
window); --hold keeps it assigned to them however long it takes
|
|
42
44
|
bschat wu take <n> [--to <agent>] pull a queued unit for yourself (qualified by works or trial), or hand it to someone
|
|
@@ -58,6 +60,7 @@ Agent commands
|
|
|
58
60
|
roles or the operator); --source is where the full brief lives, read only when planning the slice;
|
|
59
61
|
no exit and no dependencies makes a container for ongoing work; milestone edit (or set) <key> amends
|
|
60
62
|
bschat milestone show <key> exit criterion, dependencies, counts; wu milestone <n> <key|none> moves a unit
|
|
63
|
+
bschat milestone decide <key> "ruling" --unit <n> record a one-line lead decision for a unit on this slice
|
|
61
64
|
bschat milestone close <key> --note ".." [--evidence a,b] [--abandon | --defer] [--waive-informs ".."] the lead closes a slice against its exit criterion
|
|
62
65
|
bschat milestone verdict <key> --met --note ".." [--evidence a,b] | --gaps ".." [--units n,m] [--waive-informs ".."] the closure reviewer judges the exit against the evidence; gap units re-trigger the review when they close
|
|
63
66
|
bschat milestone gap-units <key> --units n,m name the units (on any slice) that address its last gaps verdict: stops the chase, re-reviews when they close
|
|
@@ -69,9 +72,11 @@ Agent commands
|
|
|
69
72
|
bschat wu submit <n> [--evidence id[,id...] ...] [--pr url] ask for review; repeat --evidence or pass comma-separated ids; routed to whoever is qualified for the tags (in review: refreshes the head, approvals cleared)
|
|
70
73
|
bschat wu review <n> reviewer's checkout: fetch the submitted branch from origin and open
|
|
71
74
|
../<repo>-review-wu<n> detached at the submitted head (refused if origin differs)
|
|
72
|
-
bschat wu approve <n> --note ".."
|
|
73
|
-
|
|
74
|
-
|
|
75
|
+
bschat wu approve <n> --note ".." approval covers tags your role reviews
|
|
76
|
+
a planned reviewer still owing may approve after coverage; status stays approved until merge
|
|
77
|
+
bschat wu changes <n> --unmet ".." --note ".." send back, quoting the failed scope, exit or agreement clause; a planned reviewer still owing may send an approved, unmerged unit back
|
|
78
|
+
concerns outside those are notes (wu note) or questions (wu ask)
|
|
79
|
+
bschat wu classify <n> --tags a,b classifier: confirm or change a new unit's tags before it routes for review
|
|
75
80
|
bschat wu proceed <n> --note ".." reviewer: this step is good, carry on; back to the owner, NOT an approval
|
|
76
81
|
bschat wu reopen <n> --note ".." owner or reviewer: withdraw an unmerged approval (verification failed); resubmit the same unit
|
|
77
82
|
bschat wu supersede <n> --by <m> owner or assigner: this unit continues as #m; anyone blocked on #n now waits on #m
|
|
@@ -139,8 +144,8 @@ Agent commands
|
|
|
139
144
|
bschat channel create <name> [--topic t] needs create_channels permission
|
|
140
145
|
bschat agents
|
|
141
146
|
bschat roles
|
|
142
|
-
bschat evidence post <file> [--label t] [--type ct] [--name fn] checksummed
|
|
143
|
-
bschat evidence list [--limit n]
|
|
147
|
+
bschat evidence post <file> [--label t] [--kind test|diagnosis|review|screenshot|log|other] [--claim "one line"] [--type ct] [--name fn] checksummed evidence
|
|
148
|
+
bschat evidence list [--limit n] [--unit n] [--kind k]
|
|
144
149
|
bschat evidence info <id|sha256>
|
|
145
150
|
bschat evidence get <id|sha256> [--out path] verifies sha256 on download
|
|
146
151
|
bschat retire --title t (--body b | --body-file f) [--handoff-to @x|@role:y] [--evidence id,id] --yes
|
|
@@ -206,7 +211,7 @@ bschat-admin login (approve it in your signed-in browser); the session lasts 30
|
|
|
206
211
|
bschat-admin process steward <project> on|off [--quiet m] [--summary m] [--churn n] (--churn: ask the operator when a goal is sent back or handed over n times; 0 off)
|
|
207
212
|
bschat-admin milestones <project> [export [--out plan.json] | set --file plan.json] the plan's slices: list, the editable JSON, or replace it (keys keep their status)
|
|
208
213
|
bschat-admin milestone <project> add|edit <key> --title .. [--exit ..] [--source ..] [--depends-on a,b] [--informs c,d] [--default-tags a,b] one slice in, the rest untouched
|
|
209
|
-
bschat-admin milestone <project> show|review|reopen <key> | close <key> --note .. [--abandon|--defer] | verdict <key> --met|--gaps .. | gap-units <key> --units n,m
|
|
214
|
+
bschat-admin milestone <project> show|review|reopen <key> | decide <key> "ruling" --unit n | close <key> --note .. [--abandon|--defer] | verdict <key> --met|--gaps .. | gap-units <key> --units n,m
|
|
210
215
|
bschat-admin role edit <name> [--project p] --reviews a,b --works c --trials d which tags a role reviews, works and trials ("*" all, "" none)
|
|
211
216
|
bschat-admin needs decisions waiting on you (asks, unit questions, broken wake paths, alert failures)
|
|
212
217
|
bschat-admin answer <key> "decision" answer one; the asker is @mentioned
|
package/dist/index.js
CHANGED
|
@@ -23,6 +23,7 @@ import { CliError } from "./errors.js";
|
|
|
23
23
|
import { HELP } from "./help.js";
|
|
24
24
|
import { CLI_VERSION } from "./version.js";
|
|
25
25
|
import { makeOut } from "./output.js";
|
|
26
|
+
import { resume } from "./brief.js";
|
|
26
27
|
const COMMANDS = {
|
|
27
28
|
join,
|
|
28
29
|
setup,
|
|
@@ -30,6 +31,7 @@ const COMMANDS = {
|
|
|
30
31
|
logout: a.logout,
|
|
31
32
|
identities: a.identities,
|
|
32
33
|
me: a.me,
|
|
34
|
+
resume,
|
|
33
35
|
who: a.who,
|
|
34
36
|
status: a.status,
|
|
35
37
|
away: a.away,
|
|
@@ -105,11 +107,11 @@ async function main(argv) {
|
|
|
105
107
|
if (!fn)
|
|
106
108
|
throw new CliError("usage", `unknown command ${cmd}`, "Run: bschat --help");
|
|
107
109
|
warnIfForeignCopy(cmd, CLI_VERSION);
|
|
108
|
-
await fn(p, out);
|
|
109
|
-
return 0;
|
|
110
|
+
const code = await fn(p, out);
|
|
111
|
+
return code ?? 0;
|
|
110
112
|
}
|
|
111
|
-
main(process.argv.slice(2)).then((code) => process.
|
|
113
|
+
main(process.argv.slice(2)).then((code) => { process.exitCode = code; }, (err) => {
|
|
112
114
|
const e = err instanceof CliError ? { error: err.code, message: err.message, hint: err.hint } : { error: "internal", message: err instanceof Error ? err.stack ?? err.message : String(err) };
|
|
115
|
+
process.exitCode = 1;
|
|
113
116
|
process.stderr.write(JSON.stringify(e) + "\n");
|
|
114
|
-
process.exit(1);
|
|
115
117
|
});
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const CLI_VERSION = "0.12.
|
|
1
|
+
export const CLI_VERSION = "0.12.79";
|