benignswarm 0.12.76 → 0.12.78
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 +2 -2
- package/dist/commands/watch.js +46 -12
- package/dist/commands/wu.js +70 -21
- package/dist/git.js +14 -0
- package/dist/help.js +8 -7
- package/dist/index.js +4 -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
|
@@ -2,8 +2,8 @@ import { parseArgs } from "node:util";
|
|
|
2
2
|
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
|
-
export const LIST_FLAGS = ["tags", "projects", "evidence", "statuses", "depends-on", "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", "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"];
|
|
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"];
|
|
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/commands/watch.js
CHANGED
|
@@ -92,13 +92,25 @@ export async function watch(p, out) {
|
|
|
92
92
|
if (!exec && !once)
|
|
93
93
|
throw new CliError("usage", 'watch --exec "<command>" [--interval 30] | watch --once (print and exit) | watch --exec ... --service (launchd on macOS, systemd on Linux)');
|
|
94
94
|
const log = (m) => process.stderr.write(`${new Date().toISOString()} bschat watch[${name}]: ${m}\n`);
|
|
95
|
+
let stopping = false;
|
|
96
|
+
let stoppingCode = 0;
|
|
97
|
+
let signalStop = () => { };
|
|
98
|
+
const stopped = new Promise((resolve) => { signalStop = resolve; });
|
|
99
|
+
let releaseWatchLock;
|
|
100
|
+
const finish = (code) => {
|
|
101
|
+
if (stopping)
|
|
102
|
+
return;
|
|
103
|
+
stopping = true;
|
|
104
|
+
stoppingCode = code;
|
|
105
|
+
releaseWatchLock?.();
|
|
106
|
+
signalStop();
|
|
107
|
+
};
|
|
95
108
|
if (!once) {
|
|
96
109
|
// 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));
|
|
110
|
+
releaseWatchLock = acquireWatchLock(name);
|
|
111
|
+
process.on("exit", () => releaseWatchLock?.());
|
|
112
|
+
process.once("SIGINT", () => finish(130));
|
|
113
|
+
process.once("SIGTERM", () => finish(143));
|
|
102
114
|
}
|
|
103
115
|
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
116
|
// Harness liveness: the files the harness writes while it works, found from the wake command's
|
|
@@ -122,9 +134,11 @@ export async function watch(p, out) {
|
|
|
122
134
|
let lastKeyCheck = 0;
|
|
123
135
|
const ctl = { turn: null, failedAt: 0, loggedRunning: null, pausedUntil: 0, pausedAt: 0 };
|
|
124
136
|
const probe = turn ? probeFor(turn.harness, turn.session, name) : null;
|
|
125
|
-
|
|
137
|
+
while (!stopping) {
|
|
126
138
|
if (activity && heartbeatClient)
|
|
127
139
|
lastSample = await heartbeatIfActive(heartbeatClient, activity, lastSample, interval, log);
|
|
140
|
+
if (stopping)
|
|
141
|
+
return stoppingCode;
|
|
128
142
|
if (scanCreds.project && Date.now() - lastScan > 3_600_000) {
|
|
129
143
|
lastScan = Date.now();
|
|
130
144
|
try {
|
|
@@ -183,10 +197,15 @@ export async function watch(p, out) {
|
|
|
183
197
|
await Client.forAgent(loadAgent(name), undefined, { presence: false }).call("GET", "/me");
|
|
184
198
|
}
|
|
185
199
|
catch (e) {
|
|
186
|
-
if (e.code === "unauthorized")
|
|
200
|
+
if (e.code === "unauthorized") {
|
|
187
201
|
stopRevokedWatcher(name, log);
|
|
202
|
+
finish(0);
|
|
203
|
+
return stoppingCode;
|
|
204
|
+
}
|
|
188
205
|
log(`could not check this agent's key: ${e.message}`);
|
|
189
206
|
}
|
|
207
|
+
if (stopping)
|
|
208
|
+
return stoppingCode;
|
|
190
209
|
}
|
|
191
210
|
if (!full) {
|
|
192
211
|
try {
|
|
@@ -196,16 +215,23 @@ export async function watch(p, out) {
|
|
|
196
215
|
await wakeOnce(name, exec, unackedAfter, followDelay, log, str(p.flags, "model"), once);
|
|
197
216
|
}
|
|
198
217
|
catch (e) {
|
|
199
|
-
if (e.code === "unauthorized" && !once)
|
|
218
|
+
if (e.code === "unauthorized" && !once) {
|
|
200
219
|
stopRevokedWatcher(name, log);
|
|
220
|
+
finish(0);
|
|
221
|
+
return stoppingCode;
|
|
222
|
+
}
|
|
201
223
|
throw e;
|
|
202
224
|
}
|
|
225
|
+
if (stopping)
|
|
226
|
+
return stoppingCode;
|
|
203
227
|
if (once)
|
|
204
228
|
return;
|
|
205
|
-
await
|
|
229
|
+
await waitIntervalOrStop(interval * 1000, stopped);
|
|
206
230
|
continue;
|
|
207
231
|
}
|
|
208
232
|
const u = await gatherUpdates(name, { force: true, model: str(p.flags, "model"), delivery: "watch" });
|
|
233
|
+
if (stopping)
|
|
234
|
+
return stoppingCode;
|
|
209
235
|
if (u) {
|
|
210
236
|
const total = u.counts.messages + u.counts.items + u.counts.followed + u.counts.digest;
|
|
211
237
|
const summary = u.text.split("\n")[0].replace(/^\[bschat\] (Delivered by your BenignSwarm watcher, not typed by the user\. )?/, "");
|
|
@@ -222,14 +248,23 @@ export async function watch(p, out) {
|
|
|
222
248
|
// Full mode delivers the update payload directly instead of using the wake path, so
|
|
223
249
|
// record the same actual payload bytes and kinds through the hook's existing metric call.
|
|
224
250
|
await reportDelivery(name, u.text, u.delivery.by_kind, "watch");
|
|
251
|
+
if (stopping)
|
|
252
|
+
return stoppingCode;
|
|
225
253
|
}
|
|
226
254
|
else if (once) {
|
|
227
255
|
log("nothing new");
|
|
228
256
|
}
|
|
229
257
|
if (once)
|
|
230
258
|
return;
|
|
231
|
-
await
|
|
259
|
+
await waitIntervalOrStop(interval * 1000, stopped);
|
|
232
260
|
}
|
|
261
|
+
return stoppingCode;
|
|
262
|
+
}
|
|
263
|
+
async function waitIntervalOrStop(ms, stopped) {
|
|
264
|
+
let timer;
|
|
265
|
+
await Promise.race([new Promise((resolve) => { timer = setTimeout(resolve, ms); }), stopped]);
|
|
266
|
+
if (timer)
|
|
267
|
+
clearTimeout(timer);
|
|
233
268
|
}
|
|
234
269
|
/**
|
|
235
270
|
* One numbered wake-up at a time. Each wake-up carries a sequence number and asks the agent to
|
|
@@ -387,8 +422,7 @@ function stopRevokedWatcher(name, log) {
|
|
|
387
422
|
?? 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
423
|
log(`this agent's key was revoked (moved to another machine, or retired): stopping and removing ${svc?.label ?? `${label} (no service found; exiting)`}`);
|
|
389
424
|
if (svc)
|
|
390
|
-
removeService(svc);
|
|
391
|
-
process.exit(0);
|
|
425
|
+
removeService(svc);
|
|
392
426
|
}
|
|
393
427
|
const TURN_RETRY_MS = 5 * 60_000;
|
|
394
428
|
const KEY_CHECK_MS = 5 * 60_000;
|
package/dist/commands/wu.js
CHANGED
|
@@ -7,9 +7,21 @@ import { readState } from "../state.js";
|
|
|
7
7
|
import { codexRollout, sessionsOf } from "../sessions.js";
|
|
8
8
|
import { sessionUsage } from "../usage.js";
|
|
9
9
|
import { CliError } from "../errors.js";
|
|
10
|
-
import { branchAndHead, commitAtTime, ensureReviewWorktree, ensureWorktree, fetchRef, fullSha, isAncestor, remoteHead, removeWorktreeIfClean, repoName, repoParent, worktreeForBranch } from "../git.js";
|
|
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.
|
|
@@ -42,6 +54,26 @@ export function parseEvidenceReplacement(positionals) {
|
|
|
42
54
|
throw new CliError("usage", "the replacement evidence id must differ from the old id");
|
|
43
55
|
return { unit, oldId, newId };
|
|
44
56
|
}
|
|
57
|
+
/** Changed paths are calculated from the fetched target's merge-base; a configured rule may not silently skip an unknown target. */
|
|
58
|
+
export function changedPathsAgainstTarget(target, cwd = process.cwd()) {
|
|
59
|
+
const fetched = spawnSync("git", ["fetch", "--quiet", "origin", target], { cwd, encoding: "utf8", timeout: 120_000 });
|
|
60
|
+
if (fetched.status !== 0)
|
|
61
|
+
throw new CliError("target_fetch_failed", `cannot fetch origin/${target} while finding changed paths for review rules: ${fetched.stderr?.trim() || "git fetch failed"}`, `check origin access and the target branch, then submit again`);
|
|
62
|
+
const targetRef = "FETCH_HEAD";
|
|
63
|
+
const verify = spawnSync("git", ["rev-parse", "--verify", "--quiet", `${targetRef}^{commit}`], { cwd, encoding: "utf8" });
|
|
64
|
+
if (verify.status !== 0)
|
|
65
|
+
throw new CliError("target_unavailable", `git fetch origin/${target} succeeded but FETCH_HEAD is not a commit`);
|
|
66
|
+
const base = spawnSync("git", ["merge-base", targetRef, "HEAD"], { cwd, encoding: "utf8" });
|
|
67
|
+
if (base.status !== 0 || !base.stdout.trim())
|
|
68
|
+
throw new CliError("merge_base_unavailable", `cannot find a merge-base between ${targetRef} and HEAD`);
|
|
69
|
+
const diff = spawnSync("git", ["diff", "--name-only", "-z", `${base.stdout.trim()}..HEAD`], { cwd, encoding: "utf8", maxBuffer: 16 * 1024 * 1024 });
|
|
70
|
+
if (diff.status !== 0)
|
|
71
|
+
throw new CliError("changed_paths_failed", `git diff against ${targetRef} failed: ${diff.stderr?.trim() || "unknown git error"}`);
|
|
72
|
+
return diff.stdout.split("\0").filter((path) => path.length > 0);
|
|
73
|
+
}
|
|
74
|
+
export function submitPayload(fields, hasReviewRules, target, cwd = process.cwd()) {
|
|
75
|
+
return { ...fields, changed_paths: hasReviewRules ? changedPathsAgainstTarget(target, cwd) : [] };
|
|
76
|
+
}
|
|
45
77
|
export async function wu(p, out) {
|
|
46
78
|
const sub = p.positionals[1];
|
|
47
79
|
const name = resolveAgentName(str(p.flags, "as"));
|
|
@@ -81,6 +113,7 @@ export async function wu(p, out) {
|
|
|
81
113
|
return [
|
|
82
114
|
`WU #${u.number} [${u.status}] ${tags(u)} ${u.title}${flags ? ` (${flags})` : ""}${u.requires?.length ? `\n requires: ${u.requires.join(", ")}` : ""}`,
|
|
83
115
|
` owner ${u.owner_name || "unassigned (queued)"}${reviewers ? ` · reviewers ${reviewers}` : ""}${approvals ? ` · approved by ${approvals}` : ""}${u.uncovered?.length ? ` · awaiting ${u.uncovered.map((t) => `#${t}`).join(" ")}` : ""}`,
|
|
116
|
+
Object.keys(u.tag_focus ?? {}).length ? ` review focus:\n${Object.entries(u.tag_focus).map(([tag, focus]) => ` #${tag}: ${focus}`).join("\n")}` : null,
|
|
84
117
|
u.operator_hold ? ` ON HOLD by ${u.operator_hold.by}: ${u.operator_hold.note} (no verdict and no merge until the owner resubmits or it is released)` : null,
|
|
85
118
|
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,
|
|
86
119
|
` ${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(" ")}` : ""}`,
|
|
@@ -113,7 +146,7 @@ export async function wu(p, out) {
|
|
|
113
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>]');
|
|
114
147
|
const replay = str(p.flags, "replay-of");
|
|
115
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 });
|
|
116
|
-
out.print(`${fmt(r.unit)}\n${r.unit
|
|
149
|
+
out.print(`${fmt(r.unit)}\n${assignmentDisposition(r.unit, to)}`, r);
|
|
117
150
|
return;
|
|
118
151
|
}
|
|
119
152
|
case "take": {
|
|
@@ -195,7 +228,8 @@ export async function wu(p, out) {
|
|
|
195
228
|
}
|
|
196
229
|
const pr = str(p.flags, "pr") ?? null;
|
|
197
230
|
const usage = await roundUsage(client, base, num(), name);
|
|
198
|
-
const
|
|
231
|
+
const payload = submitPayload({ evidence: evidenceIds, ...where, pr_url: pr, rebased, pushed, usage }, !!def.review_rules?.length, unitTarget);
|
|
232
|
+
const r = await client.call("POST", `${base}/${num()}/submit`, payload);
|
|
199
233
|
const u = r.unit;
|
|
200
234
|
out.print(`${fmt(u)}\n${u.status === "classifying" ? `Waiting for ${u.reviewers[0]?.name} to classify it.` : `Routed to ${u.reviewers.map((x) => `@${x.name}`).join(", ")}; you will be told in chat when it is reviewed.`}`, r);
|
|
201
235
|
return;
|
|
@@ -310,6 +344,7 @@ export async function wu(p, out) {
|
|
|
310
344
|
const merged = str(p.flags, "merged") ?? null;
|
|
311
345
|
const unit = (await client.call("GET", `${base}/${num()}`)).unit;
|
|
312
346
|
const landsIn = unit.target ?? def.merge.target_branch;
|
|
347
|
+
let verifiedRemoteTarget = null;
|
|
313
348
|
if (unit.replay_of) {
|
|
314
349
|
// A replay is an evaluation: it closes without merging (the server records it as evaluated).
|
|
315
350
|
if (merged)
|
|
@@ -317,20 +352,31 @@ export async function wu(p, out) {
|
|
|
317
352
|
}
|
|
318
353
|
else if (merged) {
|
|
319
354
|
// Where pushes are required the remote target is the truth, not this machine's copy of it.
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
355
|
+
if (def.merge.require_pushed) {
|
|
356
|
+
const target = fetchRef(landsIn) ? `origin/${landsIn}` : null;
|
|
357
|
+
if (target === null)
|
|
358
|
+
throw new CliError("no_remote", `cannot fetch origin/${landsIn}; this project requires merges to be on the remote`, "Check the remote is reachable and try again.");
|
|
359
|
+
const on = isAncestor(merged, target);
|
|
360
|
+
if (on === null)
|
|
361
|
+
throw new CliError("unknown_commit", `cannot verify ${merged} against ${target} in this repository`, `Run from the repo with ${landsIn} fetched: git fetch origin ${landsIn}:${landsIn}`);
|
|
362
|
+
if (!on)
|
|
363
|
+
throw new CliError("not_merged", `${merged} is not on ${target}`, "Merge and push the target branch first, then pass the merge commit.");
|
|
364
|
+
}
|
|
365
|
+
else {
|
|
366
|
+
const checked = verifyMergedCommit(merged, landsIn);
|
|
367
|
+
if (checked.ref === `origin/${landsIn}` && checked.on === true)
|
|
368
|
+
verifiedRemoteTarget = checked.ref;
|
|
369
|
+
if (checked.on === null)
|
|
370
|
+
throw new CliError("unknown_commit", `cannot verify ${merged} against ${checked.ref} in this repository`, `Run from the repo with ${landsIn} fetched: git fetch origin ${landsIn}:${landsIn}`);
|
|
371
|
+
if (!checked.on)
|
|
372
|
+
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).");
|
|
373
|
+
}
|
|
328
374
|
}
|
|
329
375
|
else if (def.merge.require_merge_commit) {
|
|
330
376
|
throw new CliError("usage", `this project's process requires the merge commit: bschat wu done ${num()} --merged <sha>`);
|
|
331
377
|
}
|
|
332
378
|
const r = await client.call("POST", `${base}/${num()}/done`, { note: str(p.flags, "note") ?? "", merged });
|
|
333
|
-
out.print(fmt(r.unit) + cleanupUnitWorktree(r.unit.worktree, def, !!p.flags["keep-worktree"]), r);
|
|
379
|
+
out.print(fmt(r.unit) + (verifiedRemoteTarget ? `\nverified on ${verifiedRemoteTarget}` : "") + cleanupUnitWorktree(r.unit.worktree, def, !!p.flags["keep-worktree"]), r);
|
|
334
380
|
return;
|
|
335
381
|
}
|
|
336
382
|
case "abandon": {
|
|
@@ -454,7 +500,8 @@ export async function processCmd(p, out) {
|
|
|
454
500
|
`Process v${r.process.version}${r.process.version === 0 ? " (defaults; the operator has not published one)" : ""}`,
|
|
455
501
|
`Machine capabilities: ${(d.capabilities ?? []).map((c) => `${c.name} (${c.scope}${c.min_version ? ` >= ${c.min_version}` : ""})`).join(", ") || "none"}`,
|
|
456
502
|
vocab.length ? `Tags (use them on bschat wu open --tags):` : `No tag vocabulary yet: units route to the default approver (${d.default_approver_role ?? "none"}).`,
|
|
457
|
-
...vocab.map((t) => ` #${t.name}: ${t.meaning || "(no meaning written)"}${t.require_evidence ? " · requires evidence" : ""}${t.require_rebased ? " · requires a rebased branch" : ""}${t.requires?.length ? ` · requires capabilities ${t.requires.join(", ")}` : ""} · reviewed by ${whoReviews(t.name).join(", ") || "NOBODY (the operator must qualify a role)"}`),
|
|
503
|
+
...vocab.map((t) => ` #${t.name}: ${t.meaning || "(no meaning written)"}${t.require_evidence ? " · requires evidence" : ""}${t.require_rebased ? " · requires a rebased branch" : ""}${t.requires?.length ? ` · requires capabilities ${t.requires.join(", ")}` : ""}${t.focus ? ` · reviewer focus: ${t.focus}` : ""} · reviewed by ${whoReviews(t.name).join(", ") || "NOBODY (the operator must qualify a role)"}`),
|
|
504
|
+
...(d.review_rules?.length ? [`Path review rules:`, ...d.review_rules.map((rule) => ` ${rule.paths.join(", ")} -> ${rule.add_tags.map((t) => `#${t}`).join(" ")} (${rule.reason})`)] : []),
|
|
458
505
|
`Untagged units are approved by ${d.default_approver_role ?? "nobody (set a default approver)"}.${d.classification === "classifier" ? ` A ${d.classifier_role} confirms tags before review.` : ""}`,
|
|
459
506
|
`A unit needs a title${d.require_scope ? ", a scope statement" : ""}${d.require_evidence_to_submit ? ", evidence before review" : ""}. Nothing is done until every tag is approved by someone qualified; never your own unit.`,
|
|
460
507
|
`Review SLA ${d.review_sla_minutes} min; after ${d.escalate_after_minutes} min another qualified reviewer takes over. Max ${d.max_open_per_agent} open units per agent. Announcements in #${d.channel}.`,
|
|
@@ -563,7 +610,7 @@ export async function milestones(p, out) {
|
|
|
563
610
|
*/
|
|
564
611
|
export async function milestonesWith(client, project, sub, p, out) {
|
|
565
612
|
if (sub === "export") {
|
|
566
|
-
const list = (await client.call("GET", `/projects/${project}/milestones`)).milestones.map((m) => ({ key: m.key, title: m.title, exit: m.exit, ...(m.source ? { source: m.source } : {}), depends_on: m.dependencies ?? m.depends_on, ...(m.priority !== null && m.priority !== undefined ? { priority: m.priority } : {}) }));
|
|
613
|
+
const list = (await client.call("GET", `/projects/${project}/milestones`)).milestones.map((m) => ({ key: m.key, title: m.title, exit: m.exit, ...(m.source ? { source: m.source } : {}), depends_on: m.dependencies ?? m.depends_on, default_tags: m.default_tags ?? [], ...(m.priority !== null && m.priority !== undefined ? { priority: m.priority } : {}) }));
|
|
567
614
|
const text = JSON.stringify(list, null, 2) + "\n";
|
|
568
615
|
const file = str(p.flags, "out");
|
|
569
616
|
if (file) {
|
|
@@ -627,15 +674,17 @@ export async function milestoneWith(client, project, sub, key, p, out) {
|
|
|
627
674
|
const dependencies = [...deps.map((key) => ({ key, kind: "blocks" })), ...informs.map((key) => ({ key, kind: "informs" }))];
|
|
628
675
|
const exit = str(p.flags, "exit") ?? existing?.exit ?? "";
|
|
629
676
|
const source = str(p.flags, "source") ?? existing?.source ?? "";
|
|
677
|
+
const default_tags = str(p.flags, "default-tags") !== undefined ? (str(p.flags, "default-tags") ?? "").split(",").map((s) => s.trim().replace(/^#/, "")).filter(Boolean) : existing?.default_tags ?? [];
|
|
678
|
+
// --priority <n> (higher first) or none; the steward asks for units only on the highest-priority ready slices.
|
|
630
679
|
const pr = str(p.flags, "priority");
|
|
631
680
|
if (pr !== undefined && pr !== "none" && !/^-?\d+$/.test(pr))
|
|
632
681
|
throw new CliError("usage", "--priority takes a whole number (higher first) or none");
|
|
633
682
|
const priority = pr === undefined ? existing?.priority ?? null : pr === "none" ? null : Number(pr);
|
|
634
|
-
const next = cur.map((m) => ({ key: m.key, title: m.title, exit: m.exit, source: m.source ?? "", depends_on: m.dependencies ?? m.depends_on, priority: m.priority ?? null }));
|
|
683
|
+
const next = cur.map((m) => ({ key: m.key, title: m.title, exit: m.exit, source: m.source ?? "", depends_on: m.dependencies ?? m.depends_on, default_tags: m.default_tags ?? [], priority: m.priority ?? null }));
|
|
635
684
|
if (existing)
|
|
636
|
-
Object.assign(next.find((m) => m.key === key), { title, exit, source, depends_on: dependencies, priority });
|
|
685
|
+
Object.assign(next.find((m) => m.key === key), { title, exit, source, depends_on: dependencies, default_tags, priority });
|
|
637
686
|
else
|
|
638
|
-
next.push({ key, title, exit, source, depends_on: dependencies, priority });
|
|
687
|
+
next.push({ key, title, exit, source, depends_on: dependencies, default_tags, priority });
|
|
639
688
|
const r = await client.call("PUT", `/projects/${project}/milestones`, { milestones: next });
|
|
640
689
|
const m = r.milestones.find((x) => x.key === key);
|
|
641
690
|
out.print(`${sub === "add" ? "Added" : "Updated"} milestone ${m.key}: ${m.title} [${m.ready ? "ready" : `waits on ${m.waiting_on.join(", ")}`}]${!m.exit && !m.depends_on.length ? " (container: never chased)" : ""}`, r);
|
|
@@ -645,7 +694,7 @@ export async function milestoneWith(client, project, sub, key, p, out) {
|
|
|
645
694
|
const m = (await client.call("GET", `/projects/${project}/milestones`)).milestones.find((x) => x.key === key);
|
|
646
695
|
if (!m)
|
|
647
696
|
throw new CliError("not_found", `no milestone ${key}`);
|
|
648
|
-
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 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(" ")})` : ""}` : ""}`, m);
|
|
697
|
+
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(" ")})` : ""}` : ""}`, m);
|
|
649
698
|
return;
|
|
650
699
|
}
|
|
651
700
|
if (sub === "close") {
|
|
@@ -695,15 +744,15 @@ export async function record(p, out) {
|
|
|
695
744
|
if (!project)
|
|
696
745
|
throw new CliError("no_project", `${creds.agent} is an account-scoped agent; pass --project <name>`);
|
|
697
746
|
const r = await client.call("GET", `/projects/${project}/record`);
|
|
698
|
-
const counters = (x) => ({ done: x.units, "1st-round": x.approved_first_round, changes: x.changes_requested, replays: x.replays, reviewed: x.reviewed, overturned: x.overturned, escalated: x.escalated });
|
|
747
|
+
const counters = (x) => ({ done: x.units, "1st-round": x.approved_first_round, changes: x.changes_requested, "2nd-read send-backs": x.second_read_changes ?? 0, replays: x.replays, reviewed: x.reviewed, overturned: x.overturned, escalated: x.escalated });
|
|
699
748
|
if (str(p.flags, "by") === "model") {
|
|
700
749
|
// The same counters keyed by what produced the work: model and effort setting at the time of the start or the verdict.
|
|
701
750
|
const rows = (r.by_model ?? []).map((x) => ({ model: x.model, effort: x.effort, tag: `#${x.tag}`, ...counters(x), agents: x.agents.join(",") }));
|
|
702
|
-
out.print(rows.length ? table(rows, ["model", "effort", "tag", "done", "1st-round", "changes", "replays", "reviewed", "overturned", "escalated", "agents"]) : "(no reviewed units yet)", r);
|
|
751
|
+
out.print(rows.length ? table(rows, ["model", "effort", "tag", "done", "1st-round", "changes", "2nd-read send-backs", "replays", "reviewed", "overturned", "escalated", "agents"]) : "(no reviewed units yet)", r);
|
|
703
752
|
return;
|
|
704
753
|
}
|
|
705
754
|
const rows = r.record.map((x) => ({ agent: x.agent, tag: `#${x.tag}`, ...counters(x) }));
|
|
706
|
-
out.print(rows.length ? table(rows, ["agent", "tag", "done", "1st-round", "changes", "replays", "reviewed", "overturned", "escalated"]) : "(no reviewed units yet)", r);
|
|
755
|
+
out.print(rows.length ? table(rows, ["agent", "tag", "done", "1st-round", "changes", "2nd-read send-backs", "replays", "reviewed", "overturned", "escalated"]) : "(no reviewed units yet)", r);
|
|
707
756
|
}
|
|
708
757
|
/** bschat lock <name> [--unit n] [--note ..] | bschat unlock <name> | bschat locks */
|
|
709
758
|
export async function lock(p, out) {
|
package/dist/git.js
CHANGED
|
@@ -321,6 +321,20 @@ export function fullSha(ref, cwd = process.cwd()) {
|
|
|
321
321
|
export function fetchRef(ref, remote = "origin", cwd = process.cwd()) {
|
|
322
322
|
return spawnSync("git", ["fetch", "--quiet", remote, ref], { cwd, encoding: "utf8", timeout: 120_000 }).status === 0;
|
|
323
323
|
}
|
|
324
|
+
/** Check a merge against the local target, then the freshly fetched origin target when needed. */
|
|
325
|
+
export function verifyMergedCommit(merged, target, cwd = process.cwd()) {
|
|
326
|
+
const local = isAncestor(merged, target, cwd);
|
|
327
|
+
if (local === true)
|
|
328
|
+
return { on: true, ref: target };
|
|
329
|
+
// Fetch into the remote-tracking ref explicitly. Fetching a bare branch name updates
|
|
330
|
+
// FETCH_HEAD only and leaves origin/<target> stale, which cannot verify this condition.
|
|
331
|
+
const ref = `origin/${target}`;
|
|
332
|
+
const fetched = spawnSync("git", ["fetch", "--quiet", "origin", `+refs/heads/${target}:refs/remotes/origin/${target}`], { cwd, encoding: "utf8", timeout: 120_000 }).status === 0;
|
|
333
|
+
if (!fetched)
|
|
334
|
+
return { on: local, ref: target };
|
|
335
|
+
const remote = isAncestor(merged, ref, cwd);
|
|
336
|
+
return remote === true ? { on: true, ref } : { on: remote, ref };
|
|
337
|
+
}
|
|
324
338
|
/**
|
|
325
339
|
* A worktree detached at exactly `sha`, for reading someone else's submission: made if absent,
|
|
326
340
|
* reused if it is already at that commit, refused if it is at something else or dirty.
|
package/dist/help.js
CHANGED
|
@@ -31,12 +31,13 @@ Agent commands
|
|
|
31
31
|
bschat inbox [--unread] [--after <iso-time>] [--limit n] mentions of you and replies to your messages
|
|
32
32
|
bschat follow <channel> | unfollow <channel> | following followed channels' new messages are injected by the hook;
|
|
33
33
|
other channels appear as a one-line unread digest
|
|
34
|
-
bschat process the project's process: tag vocabulary
|
|
34
|
+
bschat process the project's process: tag vocabulary and reviewer focus, machine/path requirements, slice defaults, agreements
|
|
35
35
|
bschat wu open "<title>" --scope "..." [--tags a,b] [--requires cap,cap] [--evidence id[,id...] ...] [--target <branch>] [--here] open a work unit in its own
|
|
36
36
|
worktree; tags come from the vocabulary; --target is the branch it lands in (default: the
|
|
37
37
|
process target), e.g. a lane branch; wu target <n> <branch|default> changes it before review
|
|
38
38
|
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
|
|
39
|
+
auto queues it when nobody fits and reports why candidates were passed over;
|
|
40
|
+
queue waits deliberately and says so; naming a
|
|
40
41
|
busy worker reserves it for them (theirs when free, anyone's after the takeover
|
|
41
42
|
window); --hold keeps it assigned to them however long it takes
|
|
42
43
|
bschat wu take <n> [--to <agent>] pull a queued unit for yourself (qualified by works or trial), or hand it to someone
|
|
@@ -53,8 +54,8 @@ Agent commands
|
|
|
53
54
|
bschat record --by model the same, keyed by model and effort setting (stamped on start and on each verdict)
|
|
54
55
|
bschat milestones the plan's slices: ready or waiting on which, units done/total; wu open|assign --milestone <key>
|
|
55
56
|
bschat milestones set --file plan.json define or replace the plan (assigner roles or the operator): a JSON list of
|
|
56
|
-
{key, title, exit, depends_on}; existing keys keep their status; cycles are refused
|
|
57
|
-
bschat milestone add <key> --title ".." [--exit ".."] [--source "docs/plan.md#b0"] [--depends-on a,b] [--informs c,d] [--priority n] add one slice (assigner
|
|
57
|
+
{key, title, exit, depends_on, default_tags}; existing keys keep their status; cycles are refused
|
|
58
|
+
bschat milestone add <key> --title ".." [--exit ".."] [--source "docs/plan.md#b0"] [--depends-on a,b] [--informs c,d] [--default-tags a,b] [--priority n] add one slice (assigner
|
|
58
59
|
roles or the operator); --source is where the full brief lives, read only when planning the slice;
|
|
59
60
|
no exit and no dependencies makes a container for ongoing work; milestone edit (or set) <key> amends
|
|
60
61
|
bschat milestone show <key> exit criterion, dependencies, counts; wu milestone <n> <key|none> moves a unit
|
|
@@ -94,7 +95,7 @@ Agent commands
|
|
|
94
95
|
bschat wu hold <n> --note ".." operator or assigner: no verdict and no merge until the owner resubmits;
|
|
95
96
|
wu release <n> [--note ..] lifts it earlier
|
|
96
97
|
bschat wu evidence replace <n> <old> <new> [--note ".."] owner replaces attached evidence; old id is retained in the unit history
|
|
97
|
-
bschat wu done <n> --merged <sha> [--keep-worktree] after approval; verifies
|
|
98
|
+
bschat wu done <n> --merged <sha> [--keep-worktree] after approval; verifies locally, then on origin if needed; removes the unit's clean worktree
|
|
98
99
|
bschat wu abandon <n> [--note ..] wu list [--all] / wu show <n> for state and timeline
|
|
99
100
|
bschat worktrees prune [--yes] [--archive] remove clean worktrees whose work landed or whose unit is closed (dry run without --yes);
|
|
100
101
|
--archive also saves a closed unit's uncommitted files to archive/wu<n>-leftovers and removes it
|
|
@@ -197,7 +198,7 @@ bschat-admin login (approve it in your signed-in browser); the session lasts 30
|
|
|
197
198
|
bschat-admin channel create|delete <project> <name>
|
|
198
199
|
bschat-admin keys [create | revoke <id>] list admin and agent keys; create shows a new admin key once
|
|
199
200
|
bschat-admin process show|export <project> [--out f] the process as agents are told it, or as an editable file
|
|
200
|
-
bschat-admin process set <project> --file process.json publish definition, vocabulary and agreements in one version
|
|
201
|
+
bschat-admin process set <project> --file process.json publish definition, vocabulary and agreements in one version (including capabilities, review_rules and tag focus)
|
|
201
202
|
bschat-admin process tag add|edit|remove <project> <tag> [--meaning ..] [--require-evidence yes|no] [--require-rebased yes|no] [--expert-role r|none] [--requires name,name]
|
|
202
203
|
bschat-admin process timing <project> [--sla m] [--takeover m] [--max-open n] [--max-in-progress n] [--require-scope yes|no] [--require-evidence yes|no] [--require-cited-changes yes|no] [--default-approver r|none]
|
|
203
204
|
bschat-admin process merge <project> [--target b] [--merged-by owner|approver|integrator] [--integrator-role r] [--require-rebased|--require-merge-commit|--require-pushed yes|no]
|
|
@@ -205,7 +206,7 @@ bschat-admin login (approve it in your signed-in browser); the session lasts 30
|
|
|
205
206
|
bschat-admin process charter <project> --file charter.md how the project weighs trade-offs; sent with every expert question
|
|
206
207
|
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
208
|
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
|
-
bschat-admin milestone <project> add|edit <key> --title .. [--exit ..] [--source ..] [--depends-on a,b] [--informs c,d] one slice in, the rest untouched
|
|
209
|
+
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
210
|
bschat-admin milestone <project> show|review|reopen <key> | close <key> --note .. [--abandon|--defer] | verdict <key> --met|--gaps .. | gap-units <key> --units n,m
|
|
210
211
|
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
212
|
bschat-admin needs decisions waiting on you (asks, unit questions, broken wake paths, alert failures)
|
package/dist/index.js
CHANGED
|
@@ -105,11 +105,11 @@ async function main(argv) {
|
|
|
105
105
|
if (!fn)
|
|
106
106
|
throw new CliError("usage", `unknown command ${cmd}`, "Run: bschat --help");
|
|
107
107
|
warnIfForeignCopy(cmd, CLI_VERSION);
|
|
108
|
-
await fn(p, out);
|
|
109
|
-
return 0;
|
|
108
|
+
const code = await fn(p, out);
|
|
109
|
+
return code ?? 0;
|
|
110
110
|
}
|
|
111
|
-
main(process.argv.slice(2)).then((code) => process.
|
|
111
|
+
main(process.argv.slice(2)).then((code) => { process.exitCode = code; }, (err) => {
|
|
112
112
|
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) };
|
|
113
|
+
process.exitCode = 1;
|
|
113
114
|
process.stderr.write(JSON.stringify(e) + "\n");
|
|
114
|
-
process.exit(1);
|
|
115
115
|
});
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const CLI_VERSION = "0.12.
|
|
1
|
+
export const CLI_VERSION = "0.12.78";
|