benignswarm 0.12.81 → 0.12.83
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 +6 -2
- package/dist/args.js +3 -3
- package/dist/brief.js +42 -8
- package/dist/client.js +4 -4
- package/dist/commands/admin.js +55 -16
- package/dist/commands/agent.js +33 -9
- package/dist/commands/antigravity.js +2 -2
- package/dist/commands/codex-start.js +17 -17
- package/dist/commands/codex.js +6 -6
- package/dist/commands/evidence.js +16 -1
- package/dist/commands/goal.js +5 -5
- package/dist/commands/hook.js +125 -57
- package/dist/commands/install.js +34 -28
- package/dist/commands/join.js +15 -14
- package/dist/commands/lists.js +2 -2
- package/dist/commands/machine-admin.js +56 -28
- package/dist/commands/machine.js +53 -29
- package/dist/commands/measures.js +191 -0
- package/dist/commands/notices.js +53 -0
- package/dist/commands/operator.js +75 -27
- package/dist/commands/retire.js +2 -2
- package/dist/commands/wake.js +4 -4
- package/dist/commands/watch.js +75 -28
- package/dist/commands/worktrees.js +4 -4
- package/dist/commands/wu.js +179 -63
- package/dist/config.js +11 -11
- package/dist/directories.js +83 -0
- package/dist/env-aliases.js +10 -0
- package/dist/git.js +2 -2
- package/dist/harness.js +91 -37
- package/dist/harnesses.js +5 -4
- package/dist/help.js +209 -182
- package/dist/index.js +37 -3
- package/dist/install.js +27 -19
- package/dist/legacy-alias.js +32 -0
- package/dist/notices.js +107 -0
- package/dist/output.js +2 -1
- package/dist/sessions.js +1 -1
- package/dist/update.js +1 -1
- package/dist/version.js +1 -1
- package/package.json +5 -3
package/dist/commands/wu.js
CHANGED
|
@@ -37,33 +37,38 @@ export function scopeOnlyOutput(unit, only) {
|
|
|
37
37
|
}
|
|
38
38
|
export function assignmentDisposition(unit, to) {
|
|
39
39
|
if (unit.status !== "queued")
|
|
40
|
-
return `Assigned to ${unit.owner_name}; they start it with
|
|
40
|
+
return `Assigned to ${unit.owner_name}; they start it with b9s wu start ${unit.number}.`;
|
|
41
41
|
if (unit.preferred_name)
|
|
42
42
|
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).`;
|
|
43
43
|
if (to === "queue")
|
|
44
|
-
return `Queued deliberately; dispatch hands it to the first qualified free worker (or
|
|
44
|
+
return `Queued deliberately; dispatch hands it to the first qualified free worker (or b9s wu take ${unit.number} --to <agent>).`;
|
|
45
45
|
const reasons = unit.dispatch_reasons?.length
|
|
46
46
|
? `\nWhy no worker was selected:\n${unit.dispatch_reasons.map((reason) => `- ${reason}`).join("\n")}`
|
|
47
47
|
: "\nNo eligible worker candidates were found.";
|
|
48
|
-
return `Queued: nobody qualified is free; it goes to the first qualified worker with capacity (or
|
|
48
|
+
return `Queued: nobody qualified is free; it goes to the first qualified worker with capacity (or b9s wu take ${unit.number} --to <agent>).${reasons}`;
|
|
49
|
+
}
|
|
50
|
+
/** Keeps the former numeric --on unit request shape while allowing named review blockers. */
|
|
51
|
+
export function waitPayload(on, clear, note, partial = "") {
|
|
52
|
+
const value = on === undefined ? null : /^\d{1,6}$/.test(on) ? Number(on) : on;
|
|
53
|
+
return { on: value, clear, note, partial };
|
|
49
54
|
}
|
|
50
55
|
/**
|
|
51
56
|
* Work units under the project's process. Work is described by tags from the project's
|
|
52
57
|
* vocabulary; reviewers are whoever is qualified to review those tags.
|
|
53
58
|
*
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
*
|
|
65
|
-
*
|
|
66
|
-
*
|
|
59
|
+
* b9s wu open "<title>" --scope "<what it covers and does not>" [--tags ui,embedded] [--evidence id,id]
|
|
60
|
+
* b9s wu submit <n> [--evidence id,id] [--pr url] ask for review; routed by the unit's tags
|
|
61
|
+
* b9s wu approve <n> --note "..." covers the tags you are qualified for
|
|
62
|
+
* b9s wu changes <n> --note "..."
|
|
63
|
+
* b9s wu classify <n> --tags a,b [--note ...] classifier role only, when the process has that step
|
|
64
|
+
* b9s wu tags <n> --add a,b --remove c [--note ...] owner before review, a reviewer during it
|
|
65
|
+
* b9s wu done <n> --merged <sha> after approval; the sha is checked against the target branch
|
|
66
|
+
* b9s wu abandon <n> [--note ...]
|
|
67
|
+
* b9s wu note <n> --note "..." [--evidence id]
|
|
68
|
+
* b9s wu evidence replace <n> <old> <new> [--note "why"]
|
|
69
|
+
* b9s wu list [--all] [--status s] [--tag t] [--agent name]
|
|
70
|
+
* b9s wu show <n>
|
|
71
|
+
* b9s process vocabulary, who reviews what, requirements, agreements
|
|
67
72
|
*/
|
|
68
73
|
export function parseEvidenceReplacement(positionals) {
|
|
69
74
|
if (positionals[2] !== "replace")
|
|
@@ -74,7 +79,7 @@ export function parseEvidenceReplacement(positionals) {
|
|
|
74
79
|
if (!Number.isInteger(unit) || unit < 1 || !oldId || !newId)
|
|
75
80
|
throw new CliError("usage", "wu evidence replace <n> <old> <new> [--note \"why\"]");
|
|
76
81
|
if (!/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(newId))
|
|
77
|
-
throw new CliError("usage", `${JSON.stringify(newId)} is not a replacement evidence id (expected the uuid from
|
|
82
|
+
throw new CliError("usage", `${JSON.stringify(newId)} is not a replacement evidence id (expected the uuid from b9s evidence post)`);
|
|
78
83
|
if (oldId === newId)
|
|
79
84
|
throw new CliError("usage", "the replacement evidence id must differ from the old id");
|
|
80
85
|
return { unit, oldId, newId };
|
|
@@ -99,6 +104,34 @@ export function changedPathsAgainstTarget(target, cwd = process.cwd()) {
|
|
|
99
104
|
export function submitPayload(fields, hasReviewRules, target, cwd = process.cwd()) {
|
|
100
105
|
return { ...fields, changed_paths: hasReviewRules ? changedPathsAgainstTarget(target, cwd) : [] };
|
|
101
106
|
}
|
|
107
|
+
export function branchValueIdsAtHead(values, head) {
|
|
108
|
+
if (!head)
|
|
109
|
+
return [];
|
|
110
|
+
return values.filter((value) => value.tested_sha === head).map((value) => value.id);
|
|
111
|
+
}
|
|
112
|
+
export function measureContextOutput(context, expectedEffect, measuredEffects) {
|
|
113
|
+
const expectedLines = expectedEffect ? [` expected effect: ${expectedEffect}`] : [];
|
|
114
|
+
const measured = measuredEffects ?? context?.measured_effect ?? [];
|
|
115
|
+
const measures = context?.measures ?? [];
|
|
116
|
+
const omittedFromContext = Number.isFinite(context?.omitted) ? Math.max(0, Math.floor(context.omitted)) : 0;
|
|
117
|
+
const reserveSummary = omittedFromContext > 0 || expectedLines.length + measured.length + measures.length > 6;
|
|
118
|
+
let capacity = Math.max(0, 6 - expectedLines.length - (reserveSummary ? 1 : 0));
|
|
119
|
+
const shownMeasured = measured.slice(0, capacity);
|
|
120
|
+
capacity -= shownMeasured.length;
|
|
121
|
+
const shownMeasures = measures.slice(0, capacity);
|
|
122
|
+
const lines = [...expectedLines];
|
|
123
|
+
for (const effect of shownMeasured) {
|
|
124
|
+
const baseline = effect.baseline ? `vs target ${effect.baseline.value}${effect.baseline.unit ? ` ${effect.baseline.unit}` : ""} at ${effect.baseline.tested_sha}` : "no good target baseline";
|
|
125
|
+
lines.push(` measured effect: ${effect.measure} ${effect.value}${effect.unit ? ` ${effect.unit}` : ""}; ${baseline}; ${effect.effect?.status ?? "unknown"}${effect.effect?.reasons?.length ? ` (${effect.effect.reasons.join(", ")})` : ""}`);
|
|
126
|
+
}
|
|
127
|
+
for (const m of shownMeasures) {
|
|
128
|
+
lines.push(` measure ${m.name}: ${m.value ?? "no value"}${m.unit ? ` ${m.unit}` : ""}; definition v${m.definition_version}; tested ${m.tested_sha ?? "-"}; merges since ${m.merges_since ?? "-"}; guard ${m.guard_result == null ? "-" : JSON.stringify(m.guard_result)}; evidence ${m.evidence_id ?? "-"}${m.suspect_range ? `; suspect ${JSON.stringify(m.suspect_range)}` : ""}`);
|
|
129
|
+
}
|
|
130
|
+
const omitted = omittedFromContext + (measured.length - shownMeasured.length) + (measures.length - shownMeasures.length);
|
|
131
|
+
if (omitted)
|
|
132
|
+
lines.push(` ${omitted} additional measures omitted`);
|
|
133
|
+
return lines.join("\n");
|
|
134
|
+
}
|
|
102
135
|
export async function wu(p, out) {
|
|
103
136
|
const sub = p.positionals[1];
|
|
104
137
|
const name = resolveAgentName(str(p.flags, "as"));
|
|
@@ -115,10 +148,10 @@ export async function wu(p, out) {
|
|
|
115
148
|
// ester #57: a submission arrived with blank evidence ids after the shell swallowed backticks;
|
|
116
149
|
// three messages were spent recovering it. Refuse anything that is not an evidence id.
|
|
117
150
|
if (raw !== undefined && !items.length)
|
|
118
|
-
throw new CliError("usage", "--evidence was given but holds no id; pass the ids printed by
|
|
151
|
+
throw new CliError("usage", "--evidence was given but holds no id; pass the ids printed by b9s evidence post, comma separated");
|
|
119
152
|
return items.map((x) => x.replace(/^evidence:/, "")).map((x) => {
|
|
120
153
|
if (!/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(x))
|
|
121
|
-
throw new CliError("usage", `${JSON.stringify(x)} is not an evidence id (expected the uuid from
|
|
154
|
+
throw new CliError("usage", `${JSON.stringify(x)} is not an evidence id (expected the uuid from b9s evidence post; check for shell interpolation of backticks)`);
|
|
122
155
|
return x;
|
|
123
156
|
});
|
|
124
157
|
}
|
|
@@ -132,53 +165,108 @@ export async function wu(p, out) {
|
|
|
132
165
|
};
|
|
133
166
|
const tags = (u) => (u.tags.length ? u.tags.map((t) => `#${t}`).join(" ") : "(untagged)");
|
|
134
167
|
const fmt = (u) => {
|
|
135
|
-
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(" · ");
|
|
168
|
+
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.review_wait ? `waiting on ${u.review_wait.type === "unit" ? `WU #${u.review_wait.target}` : u.review_wait.type === "ask" ? `ask ${u.review_wait.target}` : u.review_wait.type === "machine" ? `machine ${u.review_wait.target}` : u.review_wait.type === "text" ? u.review_wait.target : "evidence"} for ${Math.max(0, Math.round((Date.now() - Date.parse(u.review_wait.started_at)) / 60000))} min` : 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(" · ");
|
|
136
169
|
const reviewers = u.reviewers.map((r) => `${r.name}${r.tags.length ? ` for ${r.tags.map((t) => `#${t}`).join(" ")}` : ""}`).join(", ");
|
|
137
170
|
const approvals = u.approvals.map((a) => a.name).join(", ");
|
|
138
171
|
return [
|
|
139
|
-
`WU #${u.number} [${u.status}] ${tags(u)} ${u.title}${flags ? ` (${flags})` : ""}${u.requires?.length ? `\n requires: ${u.requires.join(", ")}` : ""}`,
|
|
172
|
+
`WU #${u.number} [${u.status}] ${tags(u)} ${u.title}${flags ? ` (${flags})` : ""}\n minimum tier: ${u.min_tier ?? "routine"}${u.requires?.length ? `\n requires: ${u.requires.join(", ")}` : ""}`,
|
|
173
|
+
u.candidate_record?.tags?.length ? ` ${u.candidate_record.agent} first-round approval: ${u.candidate_record.tags.map((x) => `#${x.tag} ${x.approved_first_round}/${x.units} (${Math.round(x.rate * 100)}%)`).join(", ")}` : null,
|
|
140
174
|
` owner ${u.owner_name || "unassigned (queued)"}${reviewers ? ` · reviewers ${reviewers}` : ""}${approvals ? ` · approved by ${approvals}` : ""}${u.uncovered?.length ? ` · awaiting ${u.uncovered.map((t) => `#${t}`).join(" ")}` : ""}`,
|
|
141
175
|
Object.keys(u.tag_focus ?? {}).length ? ` review focus:\n${Object.entries(u.tag_focus).map(([tag, focus]) => ` #${tag}: ${focus}`).join("\n")}` : null,
|
|
142
176
|
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,
|
|
143
177
|
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,
|
|
178
|
+
u.evidence_claims?.total ? ` evidence claims: ${u.evidence_claims.confirmed} confirmed / ${u.evidence_claims.refuted} refuted / ${u.evidence_claims.unchecked} unchecked\n${u.evidence_claims.items.map((claim) => ` [${claim.state}] ${claim.filename}: ${claim.claim}${claim.verifier_name ? ` — ${claim.verifier_name}${claim.note ? `: ${claim.note}` : ""}` : ""}`).join("\n")}` : null,
|
|
144
179
|
` ${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(" ")}` : ""}`,
|
|
145
180
|
u.scope ? ` scope: ${u.scope}` : null,
|
|
146
181
|
].filter(Boolean).join("\n");
|
|
147
182
|
};
|
|
148
183
|
const processDef = async () => (await client.call("GET", `/projects/${project}/process`)).process.definition;
|
|
149
|
-
|
|
184
|
+
const scopeText = async () => {
|
|
185
|
+
const file = str(p.flags, "scope-file");
|
|
186
|
+
const from = str(p.flags, "scope-from");
|
|
187
|
+
const inlineFlag = str(p.flags, "scope");
|
|
188
|
+
const inline = inlineFlag ?? "";
|
|
189
|
+
if (file && from)
|
|
190
|
+
throw new CliError("usage", "use either --scope-file or --scope-from, not both");
|
|
191
|
+
let baseScope = "";
|
|
192
|
+
if (file) {
|
|
193
|
+
try {
|
|
194
|
+
baseScope = readFileSync(resolve(file), "utf8");
|
|
195
|
+
}
|
|
196
|
+
catch (e) {
|
|
197
|
+
throw new CliError("scope_file", `cannot read scope file ${file}: ${e.message}`);
|
|
198
|
+
}
|
|
199
|
+
if (inlineFlag !== undefined)
|
|
200
|
+
throw new CliError("usage", "--scope-file supplies the complete scope; do not combine it with --scope");
|
|
201
|
+
}
|
|
202
|
+
else if (from) {
|
|
203
|
+
const sourceNo = Number(from);
|
|
204
|
+
if (!Number.isInteger(sourceNo) || sourceNo < 1)
|
|
205
|
+
throw new CliError("usage", "--scope-from must be a work unit number");
|
|
206
|
+
const source = await client.call("GET", `${base}/${sourceNo}`);
|
|
207
|
+
baseScope = source.unit.scope;
|
|
208
|
+
}
|
|
209
|
+
const scope = [baseScope, inline].filter(Boolean).join("\n\n");
|
|
210
|
+
// The server owns the project's scope policy. In particular, an empty scope is valid
|
|
211
|
+
// when require_scope is off and no tagged template requires sections.
|
|
212
|
+
return scope;
|
|
213
|
+
};
|
|
214
|
+
// The project's sparse-checkout exclusions (b9s-admin project checkout), for new worktrees.
|
|
150
215
|
const checkoutExclude = async () => (await client.call("GET", `/projects/${project}/process`)).checkout?.exclude ?? [];
|
|
151
216
|
switch (sub) {
|
|
152
217
|
case "open": {
|
|
153
218
|
const title = p.positionals.slice(2).join(" ").trim();
|
|
154
219
|
if (!title)
|
|
155
|
-
throw new CliError("usage", 'wu open "<title>" --scope "<what it covers and does not>" [--tags a,b] [--evidence id]');
|
|
220
|
+
throw new CliError("usage", 'wu open "<title>" --scope "<what it covers and does not>" [--scope-file <path> | --scope-from <n>] [--tags a,b] [--tier routine|careful|expert] [--evidence id]');
|
|
221
|
+
const unitTags = list("tags");
|
|
222
|
+
const scope = await scopeText();
|
|
156
223
|
// The unit exists first (it needs its number for the branch name), then its worktree is made
|
|
157
224
|
// and recorded exactly as `wu start` would; --here keeps the current checkout.
|
|
158
|
-
const r = await client.call("POST", base, { title, scope:
|
|
225
|
+
const r = await client.call("POST", base, { title, scope, tags: unitTags, requires: list("requires"), evidence: list("evidence"), min_tier: str(p.flags, "tier"), force: bool(p.flags, "force"), ...branchAndHead(), worktree: process.cwd(), target: str(p.flags, "target") ?? null, milestone: str(p.flags, "milestone") ?? null });
|
|
159
226
|
const n = r.unit.number;
|
|
160
227
|
const { path, branch, mode } = prepareWorktree(n, r.unit, await processDef(), p, await checkoutExclude());
|
|
161
228
|
const where = branchAndHead(path);
|
|
162
229
|
const s = await client.call("POST", `${base}/${n}/start`, { branch: branch ?? where.branch, head: where.head, worktree: path, mode });
|
|
163
|
-
out.print(`${fmt(s.unit)}\n${mode === "here" ? "Working in this checkout." : `Your worktree: ${path} (branch ${branch})\n cd ${path}\nWork there.`}\nSubmit for review when ready:
|
|
230
|
+
out.print(`${fmt(s.unit)}\n${mode === "here" ? "Working in this checkout." : `Your worktree: ${path} (branch ${branch})\n cd ${path}\nWork there.`}\nSubmit for review when ready: b9s wu submit ${n} --evidence <id>`, { ...s, worktree: path, branch, mode });
|
|
164
231
|
return;
|
|
165
232
|
}
|
|
166
233
|
case "assign": {
|
|
167
234
|
// Dispatch as state: the unit exists from now, the worker is mentioned, the sweep chases it.
|
|
168
|
-
const
|
|
235
|
+
const unitTags = list("tags");
|
|
236
|
+
if (bool(p.flags, "template")) {
|
|
237
|
+
if (!unitTags.length)
|
|
238
|
+
throw new CliError("usage", "wu assign --template requires --tags <tag,...>");
|
|
239
|
+
const templates = (await processDef()).scope_templates ?? {};
|
|
240
|
+
const sections = unitTags.flatMap((tag) => templates[tag]?.sections ?? []);
|
|
241
|
+
if (!sections.length)
|
|
242
|
+
throw new CliError("no_template", `no scope template is configured for ${unitTags.map((tag) => `#${tag}`).join(" ")}`);
|
|
243
|
+
const uniqueSections = [...new Map(sections.map((section) => [section.name.toLowerCase(), section])).values()];
|
|
244
|
+
out.print(uniqueSections.map((section) => `${section.name}:\n${section.hint ? ` ${section.hint}\n` : ""}`).join("\n").trim(), { tags: unitTags, sections: uniqueSections });
|
|
245
|
+
return;
|
|
246
|
+
}
|
|
169
247
|
const to = str(p.flags, "to");
|
|
170
|
-
if (!
|
|
171
|
-
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>]');
|
|
248
|
+
if (!to)
|
|
249
|
+
throw new CliError("usage", 'wu assign "<title>" --to <agent|auto|queue> --scope "<what it covers and does not>" [--scope-file <path> | --scope-from <n>] [--tags a,b] [--tier routine|careful|expert] [--evidence id] [--replay-of <n>]');
|
|
250
|
+
const existingNumber = Number(p.positionals[2]);
|
|
251
|
+
if (Number.isInteger(existingNumber) && existingNumber > 0 && p.positionals.length === 3) {
|
|
252
|
+
const r = await client.call("POST", `${base}/${existingNumber}/assign`, { to });
|
|
253
|
+
out.print(fmt(r.unit), r);
|
|
254
|
+
return;
|
|
255
|
+
}
|
|
256
|
+
const title = p.positionals.slice(2).join(" ").trim();
|
|
257
|
+
if (!title)
|
|
258
|
+
throw new CliError("usage", 'wu assign "<title>" --to <agent|auto|queue> --scope "<what it covers and does not>" [--scope-file <path> | --scope-from <n>] [--tags a,b] [--tier routine|careful|expert] [--evidence id] [--replay-of <n>]');
|
|
259
|
+
const scope = await scopeText();
|
|
172
260
|
const replay = str(p.flags, "replay-of");
|
|
173
|
-
const r = await client.call("POST", `${base}/assign`, { to, title, scope
|
|
174
|
-
out.print(`${fmt(r.unit)}\n${assignmentDisposition(r.unit, to)}`, r);
|
|
261
|
+
const r = await client.call("POST", `${base}/assign`, { to, title, scope, tags: unitTags, 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, min_tier: str(p.flags, "tier"), hold: !!p.flags.hold, force: bool(p.flags, "force") });
|
|
262
|
+
out.print(`${fmt(r.unit)}\n${assignmentDisposition(r.unit, to)}${r.warnings?.length ? `\nScope warnings:\n${r.warnings.map((w) => `- ${w}`).join("\n")}` : ""}`, r);
|
|
175
263
|
return;
|
|
176
264
|
}
|
|
177
265
|
case "take": {
|
|
178
266
|
// Pull a queued unit: for yourself (qualified by works or trial), or for someone with --to (assigners).
|
|
179
267
|
const to = str(p.flags, "to") ?? null;
|
|
180
268
|
const r = await client.call("POST", `${base}/${num()}/take`, { to });
|
|
181
|
-
out.print(`${fmt(r.unit)}\n${to ? `Handed to ${r.unit.owner_name}.` : `Yours. Start it:
|
|
269
|
+
out.print(`${fmt(r.unit)}\n${to ? `Handed to ${r.unit.owner_name}.` : `Yours. Start it: b9s wu start ${r.unit.number}`}`, r);
|
|
182
270
|
return;
|
|
183
271
|
}
|
|
184
272
|
case "next": {
|
|
@@ -187,7 +275,7 @@ export async function wu(p, out) {
|
|
|
187
275
|
out.print("(nothing queued that you qualify for)", { unit: null });
|
|
188
276
|
return;
|
|
189
277
|
}
|
|
190
|
-
out.print(`${fmt(r.unit)}\nYours. Start it:
|
|
278
|
+
out.print(`${fmt(r.unit)}\nYours. Start it: b9s wu start ${r.unit.number}`, r);
|
|
191
279
|
return;
|
|
192
280
|
}
|
|
193
281
|
case "start": {
|
|
@@ -213,7 +301,7 @@ export async function wu(p, out) {
|
|
|
213
301
|
}
|
|
214
302
|
throw error;
|
|
215
303
|
}
|
|
216
|
-
out.print(`${fmt(r.unit)}\nYour worktree: ${path}${mode === "fresh" ? ` (new branch ${branch} from ${target}${unit.replay ? " as of the original" : ""})` : mode === "branch" ? ` (branch ${branch})` : " (this checkout)"}\n cd ${path}\nWork there. Submit when ready:
|
|
304
|
+
out.print(`${fmt(r.unit)}\nYour worktree: ${path}${mode === "fresh" ? ` (new branch ${branch} from ${target}${unit.replay ? " as of the original" : ""})` : mode === "branch" ? ` (branch ${branch})` : " (this checkout)"}\n cd ${path}\nWork there. Submit when ready: b9s wu submit ${n} --evidence <id>`, { ...r, worktree: path, branch, mode });
|
|
217
305
|
return;
|
|
218
306
|
}
|
|
219
307
|
case "decline": {
|
|
@@ -247,19 +335,30 @@ export async function wu(p, out) {
|
|
|
247
335
|
}
|
|
248
336
|
else if (def.merge.require_pushed) {
|
|
249
337
|
const message = formatRemoteCommitFailure(localBranch, check.checkedRef, check.reason ?? "no containing origin branch was found");
|
|
250
|
-
throw new CliError(check.checked ? "not_pushed" : "remote_unavailable", message, check.checked ? `git push -u origin ${localBranch}, then submit again` : "Check that origin is reachable, then rerun
|
|
338
|
+
throw new CliError(check.checked ? "not_pushed" : "remote_unavailable", message, check.checked ? `git push -u origin ${localBranch}, then submit again` : "Check that origin is reachable, then rerun b9s wu submit");
|
|
251
339
|
}
|
|
252
340
|
else if (pushed !== true) {
|
|
253
|
-
process.stderr.write(`
|
|
341
|
+
process.stderr.write(`b9s: ${formatRemoteCommitFailure(localBranch, check.checkedRef, check.reason ?? "no containing origin branch was found")}\n`);
|
|
254
342
|
}
|
|
255
343
|
}
|
|
256
344
|
else if (def.merge.require_pushed) {
|
|
257
|
-
throw new CliError("remote_unavailable", formatRemoteCommitFailure("(detached HEAD)", "origin/<branch>", "the current checkout has no local branch name"), "Check out the unit branch and rerun
|
|
345
|
+
throw new CliError("remote_unavailable", formatRemoteCommitFailure("(detached HEAD)", "origin/<branch>", "the current checkout has no local branch name"), "Check out the unit branch and rerun b9s wu submit");
|
|
258
346
|
}
|
|
259
347
|
}
|
|
260
348
|
const pr = str(p.flags, "pr") ?? null;
|
|
261
349
|
const usage = await roundUsage(client, base, num(), name);
|
|
262
|
-
|
|
350
|
+
let branchValueIds = [];
|
|
351
|
+
if (where.head) {
|
|
352
|
+
try {
|
|
353
|
+
const found = await client.call("GET", `/projects/${project}/measures/branch-values?head=${encodeURIComponent(where.head)}`);
|
|
354
|
+
branchValueIds = branchValueIdsAtHead(Array.isArray(found.values) ? found.values : [], where.head);
|
|
355
|
+
}
|
|
356
|
+
catch (error) {
|
|
357
|
+
// Branch values are context only: an unavailable measure service must never prevent submit.
|
|
358
|
+
process.stderr.write(`b9s: could not attach branch measure results: ${error.message}\n`);
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
const payload = submitPayload({ evidence: evidenceIds, ...where, branch_values: branchValueIds, pr_url: pr, rebased, pushed, usage, expect: str(p.flags, "expect") }, !!def.review_rules?.length, unitTarget);
|
|
263
362
|
const r = await client.call("POST", `${base}/${num()}/submit`, payload);
|
|
264
363
|
const u = r.unit;
|
|
265
364
|
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.`}${remoteCommitBranch ? `\n${formatRemoteCommitSuccess(remoteCommitBranch)}` : ""}`, r);
|
|
@@ -310,7 +409,11 @@ export async function wu(p, out) {
|
|
|
310
409
|
const on = str(p.flags, "on");
|
|
311
410
|
if (!on && !bool(p.flags, "clear"))
|
|
312
411
|
throw new CliError("usage", 'wu wait <n> --on <m> [--note ".."] (or --clear)');
|
|
313
|
-
|
|
412
|
+
if (on && bool(p.flags, "clear"))
|
|
413
|
+
throw new CliError("usage", "choose either --on or --clear");
|
|
414
|
+
if (on && !str(p.flags, "note"))
|
|
415
|
+
throw new CliError("usage", 'wu wait <n> --on "evidence|unit #m|ask id|machine name|text blocker" --note "why"');
|
|
416
|
+
const r = await client.call("POST", `${base}/${num()}/wait`, waitPayload(on, bool(p.flags, "clear"), str(p.flags, "note") ?? "", str(p.flags, "partial") ?? ""));
|
|
314
417
|
out.print(fmt(r.unit), r);
|
|
315
418
|
return;
|
|
316
419
|
}
|
|
@@ -320,7 +423,7 @@ export async function wu(p, out) {
|
|
|
320
423
|
if (!note)
|
|
321
424
|
throw new CliError("usage", 'wu hold <n> --note "what must happen before it moves on" (operator or assigner)');
|
|
322
425
|
const r = await client.call("POST", `${base}/${num()}/hold`, { note });
|
|
323
|
-
out.print(`${fmt(r.unit)}\nOn hold: verdicts and done are refused until ${r.unit.owner_name} resubmits or you run
|
|
426
|
+
out.print(`${fmt(r.unit)}\nOn hold: verdicts and done are refused until ${r.unit.owner_name} resubmits or you run b9s wu release ${num()}.`, r);
|
|
324
427
|
return;
|
|
325
428
|
}
|
|
326
429
|
case "release": {
|
|
@@ -329,7 +432,14 @@ export async function wu(p, out) {
|
|
|
329
432
|
return;
|
|
330
433
|
}
|
|
331
434
|
case "scope": {
|
|
332
|
-
const
|
|
435
|
+
const note = str(p.flags, "note");
|
|
436
|
+
const hasScopeSource = str(p.flags, "scope") !== undefined || str(p.flags, "scope-file") !== undefined || str(p.flags, "scope-from") !== undefined;
|
|
437
|
+
const hasEditMode = bool(p.flags, "replace") || str(p.flags, "append") !== undefined;
|
|
438
|
+
if (Number(hasScopeSource) + Number(hasEditMode) !== 1)
|
|
439
|
+
throw new CliError("usage", "choose exactly one scope source or edit mode (--scope, --scope-file, --scope-from, --replace, or --append)");
|
|
440
|
+
const edit = hasScopeSource ? { scope: await scopeText(), note: note ?? "" } : scopeEditFromArgs(p);
|
|
441
|
+
if (("scope" in edit && !edit.scope.trim()) || !edit.note)
|
|
442
|
+
throw new CliError("usage", 'wu scope <n> --scope "what it now covers" | --scope-file <path> | --scope-from <n> | --replace <old> <new> | --append "clause" --note "why"');
|
|
333
443
|
const r = await client.call("POST", `${base}/${num()}/scope`, edit);
|
|
334
444
|
out.print(`${fmt(r.unit)}\nScope amended; the owner and reviewers were told.`, r);
|
|
335
445
|
return;
|
|
@@ -401,7 +511,7 @@ export async function wu(p, out) {
|
|
|
401
511
|
}
|
|
402
512
|
}
|
|
403
513
|
else if (def.merge.require_merge_commit) {
|
|
404
|
-
throw new CliError("usage", `this project's process requires the merge commit:
|
|
514
|
+
throw new CliError("usage", `this project's process requires the merge commit: b9s wu done ${num()} --merged <sha>`);
|
|
405
515
|
}
|
|
406
516
|
const r = await client.call("POST", `${base}/${num()}/done`, { note: str(p.flags, "note") ?? "", merged });
|
|
407
517
|
out.print(fmt(r.unit) + (verifiedRemoteTarget ? `\nverified on ${verifiedRemoteTarget}` : "") + cleanupUnitWorktree(r.unit.worktree, def, !!p.flags["keep-worktree"]), r);
|
|
@@ -445,7 +555,8 @@ export async function wu(p, out) {
|
|
|
445
555
|
case "review": {
|
|
446
556
|
// The reviewer's checkout: the submitted commit, fetched from the remote, in its own worktree.
|
|
447
557
|
const n = num();
|
|
448
|
-
const
|
|
558
|
+
const reviewDetail = await client.call("GET", `${base}/${n}`);
|
|
559
|
+
const unit = reviewDetail.unit;
|
|
449
560
|
if (!unit.branch)
|
|
450
561
|
throw new CliError("no_branch", `WU #${n} has no branch recorded; ask ${unit.owner_name} to submit from the branch`);
|
|
451
562
|
if (!unit.head)
|
|
@@ -483,7 +594,8 @@ export async function wu(p, out) {
|
|
|
483
594
|
const path = resolve(parent, `${name}-review-wu${n}`);
|
|
484
595
|
const made = ensureReviewWorktree(path, remote);
|
|
485
596
|
const ev = unit.evidence.map((e) => `evidence:${e}`).join(" ") || "(none)";
|
|
486
|
-
|
|
597
|
+
const context = measureContextOutput(reviewDetail.measure_context, unit.expected_effect, unit.measured_effect);
|
|
598
|
+
out.print(`${fmt(unit)}${context ? `\n${context}` : ""}\nReview checkout: ${path} (detached at ${remote.slice(0, 9)}${made.created ? "" : ", already there"})${onTarget ? `\nThe submitted commit is already on origin/${target}: the unit added no commits, so its evidence is the work.` : ""}\n cd ${path}\nEvidence: ${ev} (b9s evidence get <id>)\nVerdict: b9s wu approve ${n} --note "..." | b9s wu changes ${n} --note "..."\nWhen finished: git worktree remove ${path}`, { unit, worktree: path, head: remote, measure_context: reviewDetail.measure_context });
|
|
487
599
|
return;
|
|
488
600
|
}
|
|
489
601
|
case "show": {
|
|
@@ -494,7 +606,8 @@ export async function wu(p, out) {
|
|
|
494
606
|
return;
|
|
495
607
|
}
|
|
496
608
|
const events = r.events.map((e) => ` ${e.at.slice(0, 16).replace("T", " ")} ${e.type.padEnd(18)} ${e.actor_name}${e.note ? `: ${e.note}` : ""}${e.data?.to && Array.isArray(e.data.to) ? ` -> ${e.data.to.join(", ")}` : ""}`).join("\n");
|
|
497
|
-
|
|
609
|
+
const context = measureContextOutput(r.measure_context, r.unit.expected_effect, r.unit.measured_effect);
|
|
610
|
+
out.print(`${fmt(r.unit)}${context ? `\n${context}` : ""}\n${events}`, r);
|
|
498
611
|
return;
|
|
499
612
|
}
|
|
500
613
|
case "list":
|
|
@@ -507,7 +620,7 @@ export async function wu(p, out) {
|
|
|
507
620
|
qs.set(k, str(p.flags, k));
|
|
508
621
|
const r = await client.call("GET", `${base}${qs.size ? `?${qs}` : ""}`);
|
|
509
622
|
const rows = r.units.map((u) => ({ n: `#${u.number}`, status: u.status, tags: u.tags.map((t) => `#${t}`).join(" "), owner: u.owner_name, reviewers: u.reviewers.map((x) => x.name).join(",") || "-", awaiting: (u.uncovered ?? []).map((t) => `#${t}`).join(" ") || "-", title: u.title.slice(0, 50) }));
|
|
510
|
-
out.print(rows.length ? table(rows, ["n", "status", "tags", "owner", "reviewers", "awaiting", "title"]) : "(no open work units;
|
|
623
|
+
out.print(rows.length ? table(rows, ["n", "status", "tags", "owner", "reviewers", "awaiting", "title"]) : "(no open work units; b9s wu list --all for closed ones)", r);
|
|
511
624
|
return;
|
|
512
625
|
}
|
|
513
626
|
default:
|
|
@@ -535,13 +648,14 @@ export async function processCmd(p, out) {
|
|
|
535
648
|
const lines = [
|
|
536
649
|
`Process v${r.process.version}${r.process.version === 0 ? " (defaults; the operator has not published one)" : ""}`,
|
|
537
650
|
`Machine capabilities: ${(d.capabilities ?? []).map((c) => `${c.name} (${c.scope}${c.min_version ? ` >= ${c.min_version}` : ""})`).join(", ") || "none"}`,
|
|
538
|
-
vocab.length ? `Tags (use them on
|
|
539
|
-
...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)"}`),
|
|
651
|
+
vocab.length ? `Tags (use them on b9s wu open --tags):` : `No tag vocabulary yet: units route to the default approver (${d.default_approver_role ?? "none"}).`,
|
|
652
|
+
...vocab.map((t) => ` #${t.name}: ${t.meaning || "(no meaning written)"}${t.min_tier && t.min_tier !== "routine" ? ` · minimum tier ${t.min_tier}` : ""}${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)"}`),
|
|
653
|
+
...Object.entries(d.scope_templates ?? {}).flatMap(([tag, template]) => [` #${tag} scope template:`, ...template.sections.map((section) => ` ${section.name}${section.required ? " (required)" : ""}${section.hint ? ` — ${section.hint}` : ""}`)]),
|
|
540
654
|
...(d.review_rules?.length ? [`Path review rules:`, ...d.review_rules.map((rule) => ` ${rule.paths.join(", ")} -> ${rule.add_tags.map((t) => `#${t}`).join(" ")} (${rule.reason})`)] : []),
|
|
541
655
|
`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.` : ""}`,
|
|
542
656
|
`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.`,
|
|
543
657
|
`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}.`,
|
|
544
|
-
`Merging: ${d.merge.merged_by === "owner" ? "the owner" : d.merge.merged_by === "approver" ? "an approver" : `a ${d.merge.integrator_role}`} merges approved work into ${d.merge.target_branch}${d.merge.require_rebased ? "; the branch must contain " + d.merge.target_branch + " before review" : ""}${d.merge.require_merge_commit ? "; done carries the merge commit (
|
|
658
|
+
`Merging: ${d.merge.merged_by === "owner" ? "the owner" : d.merge.merged_by === "approver" ? "an approver" : `a ${d.merge.integrator_role}`} merges approved work into ${d.merge.target_branch}${d.merge.require_rebased ? "; the branch must contain " + d.merge.target_branch + " before review" : ""}${d.merge.require_merge_commit ? "; done carries the merge commit (b9s wu done <n> --merged <sha>)" : ""}.`,
|
|
545
659
|
r.process.agreements ? `\nWorking agreements:\n${r.process.agreements}` : null,
|
|
546
660
|
r.process.charter ? `\nCharter (how this project weighs its trade-offs; judge reviews and questions by it):\n${r.process.charter}` : null,
|
|
547
661
|
].filter(Boolean);
|
|
@@ -562,7 +676,7 @@ function cleanupUnitWorktree(wt, def, keep) {
|
|
|
562
676
|
if (res.removed)
|
|
563
677
|
return `\nRemoved worktree ${wt} (branch kept).`;
|
|
564
678
|
if (res.reason === "uncommitted changes")
|
|
565
|
-
return `\nWorktree ${wt} kept: it has uncommitted files that are not on the branch. Commit them to the branch if they belong to the record, or run
|
|
679
|
+
return `\nWorktree ${wt} kept: it has uncommitted files that are not on the branch. Commit them to the branch if they belong to the record, or run b9s worktrees prune --archive --yes to save them to an archive branch and remove the worktree.`;
|
|
566
680
|
return `\nWorktree ${wt} kept: ${res.reason}.`;
|
|
567
681
|
}
|
|
568
682
|
/**
|
|
@@ -572,7 +686,7 @@ function cleanupUnitWorktree(wt, def, keep) {
|
|
|
572
686
|
function prepareWorktree(n, unit, def, p, exclude = []) {
|
|
573
687
|
// The unit's own target when it has one: a lane or release branch the work lands in.
|
|
574
688
|
const target = unit.target ?? def.merge.target_branch;
|
|
575
|
-
const log = (line) => process.stderr.write(`
|
|
689
|
+
const log = (line) => process.stderr.write(`b9s: ${line}\n`);
|
|
576
690
|
// Where reviewers may be on other machines, origin is the truth: start from origin's target, not
|
|
577
691
|
// this machine's possibly stale copy, and continue a pinned branch from what origin has of it.
|
|
578
692
|
const remoteFirst = !!def.merge.require_pushed;
|
|
@@ -641,7 +755,7 @@ export async function milestones(p, out) {
|
|
|
641
755
|
return milestonesWith(client, project, p.positionals[1], p, out);
|
|
642
756
|
}
|
|
643
757
|
/**
|
|
644
|
-
* The plan's milestones, shared by agents (`
|
|
758
|
+
* The plan's milestones, shared by agents (`b9s milestones`) and the operator (`b9s-admin
|
|
645
759
|
* milestones <project>`): list, `export` (the editable JSON list `set` takes) and `set`.
|
|
646
760
|
*/
|
|
647
761
|
export async function milestonesWith(client, project, sub, p, out) {
|
|
@@ -675,7 +789,7 @@ export async function milestonesWith(client, project, sub, p, out) {
|
|
|
675
789
|
}
|
|
676
790
|
const r = await client.call("GET", `/projects/${project}/milestones`);
|
|
677
791
|
const rows = r.milestones.map((m) => ({ key: m.key, priority: m.priority ?? "-", status: m.status === "open" ? (m.ready ? "ready" : `waits on ${m.waiting_on.join(",")}`) : m.status, units: `${m.units.done}/${m.units.total}${m.units.queued ? ` (+${m.units.queued} queued)` : ""}`, "depends on": m.depends_on.join(",") || "-", title: m.title.slice(0, 50) }));
|
|
678
|
-
out.print(rows.length ? `${table(rows, ["key", "priority", "status", "units", "depends on", "title"])}\
|
|
792
|
+
out.print(rows.length ? `${table(rows, ["key", "priority", "status", "units", "depends on", "title"])}\nb9s milestone show <key> for the exit criterion; wu open/assign --milestone <key> puts a unit on one.` : "(no milestones defined; the operator defines them on the Process page or with b9s-admin milestones <project> set --file plan.json, an assigner with b9s milestones set --file plan.json)", r);
|
|
679
793
|
}
|
|
680
794
|
/** milestone show <key> | milestone close <key> --note ".." [--evidence a,b] [--abandon | --defer] | milestone reopen <key> */
|
|
681
795
|
export async function milestone(p, out) {
|
|
@@ -687,11 +801,11 @@ export async function milestone(p, out) {
|
|
|
687
801
|
throw new CliError("no_project", `${creds.agent} is an account-scoped agent; pass --project <name>`);
|
|
688
802
|
return milestoneWith(client, project, p.positionals[1], p.positionals[2], p, out, p.positionals.slice(3));
|
|
689
803
|
}
|
|
690
|
-
/** One milestone, shared by agents (`
|
|
804
|
+
/** One milestone, shared by agents (`b9s milestone`) and the operator (`b9s-admin milestone <project>`). */
|
|
691
805
|
export async function milestoneWith(client, project, sub, key, p, out, decisionParts = p.positionals.slice(3)) {
|
|
692
806
|
if (!key)
|
|
693
807
|
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>');
|
|
694
|
-
// "set" is "edit" (
|
|
808
|
+
// "set" is "edit" (b9s milestone set <key> --priority 5): one slice changed, the rest untouched.
|
|
695
809
|
if (sub === "set")
|
|
696
810
|
sub = "edit";
|
|
697
811
|
if (sub === "decide") {
|
|
@@ -741,7 +855,9 @@ export async function milestoneWith(client, project, sub, key, p, out, decisionP
|
|
|
741
855
|
throw new CliError("not_found", `no milestone ${key}`);
|
|
742
856
|
const detail = await client.call("GET", `/projects/${project}/milestones/${key}`);
|
|
743
857
|
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("");
|
|
744
|
-
|
|
858
|
+
const measured = (detail.measure_citations ?? []).map((c) => ` measured citation: ${c.citation} → ${c.found ? `${c.value}${c.unit ? ` ${c.unit}` : ""} (definition v${c.definition_version}, tested ${c.tested_sha}, evidence:${c.evidence_id}, guard passed)` : c.message}`).join("\n");
|
|
859
|
+
const measures = measureContextOutput(detail.measure_context);
|
|
860
|
+
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)"}${measures ? `\n${measures}` : ""}${measured ? `\n${measured}` : ""}${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, measure_context: detail.measure_context, measure_citations: detail.measure_citations });
|
|
745
861
|
return;
|
|
746
862
|
}
|
|
747
863
|
if (sub === "close") {
|
|
@@ -801,7 +917,7 @@ export async function record(p, out) {
|
|
|
801
917
|
const rows = r.record.map((x) => ({ agent: x.agent, tag: `#${x.tag}`, ...counters(x) }));
|
|
802
918
|
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);
|
|
803
919
|
}
|
|
804
|
-
/**
|
|
920
|
+
/** b9s lock <name> [--unit n] [--note ..] | b9s unlock <name> | b9s locks */
|
|
805
921
|
export async function lock(p, out) {
|
|
806
922
|
const name = resolveAgentName(str(p.flags, "as"));
|
|
807
923
|
const creds = loadAgent(name);
|
|
@@ -813,11 +929,11 @@ export async function lock(p, out) {
|
|
|
813
929
|
const lockName = p.positionals[1];
|
|
814
930
|
if (cmd === "locks") {
|
|
815
931
|
const r = await client.call("GET", `/projects/${project}/locks`);
|
|
816
|
-
out.print(r.locks.length ? r.locks.map((l) => `${l.name}${l.machine ? ` on ${l.machine}` : " (shared)"}: ${l.holder_name ? `held by ${l.holder_name}${l.unit ? ` (WU #${l.unit})` : ""} since ${l.acquired_at.slice(11, 16)} UTC` : "free"}${l.waiting.length ? ` · waiting: ${l.waiting.map((w) => `${w.name}${w.unit ? ` (#${w.unit})` : ""}`).join(", ")}` : ""}`).join("\n") : "No locks in this project. Take one with:
|
|
932
|
+
out.print(r.locks.length ? r.locks.map((l) => `${l.name}${l.machine ? ` on ${l.machine}` : " (shared)"}: ${l.holder_name ? `held by ${l.holder_name}${l.unit ? ` (WU #${l.unit})` : ""} since ${l.acquired_at.slice(11, 16)} UTC` : "free"}${l.waiting.length ? ` · waiting: ${l.waiting.map((w) => `${w.name}${w.unit ? ` (#${w.unit})` : ""}`).join(", ")}` : ""}`).join("\n") : "No locks in this project. Take one with: b9s lock <name> [--unit n]", r);
|
|
817
933
|
return;
|
|
818
934
|
}
|
|
819
935
|
if (!lockName)
|
|
820
|
-
throw new CliError("usage", `${cmd} <name> (e.g.
|
|
936
|
+
throw new CliError("usage", `${cmd} <name> (e.g. b9s lock build --unit 60 --note "exact run")`);
|
|
821
937
|
if (cmd === "unlock") {
|
|
822
938
|
const r = await client.call("POST", `/projects/${project}/locks/${lockName}/release`, { shared: bool(p.flags, "shared") });
|
|
823
939
|
out.print(r.lock.holder_name ? `${lockName} released; now held by ${r.lock.holder_name}${r.lock.unit ? ` (WU #${r.lock.unit})` : ""}.` : `${lockName} released; free.`, r);
|
|
@@ -827,13 +943,13 @@ export async function lock(p, out) {
|
|
|
827
943
|
// Scoped to this machine unless --shared: the resource is this box's CPU and disk.
|
|
828
944
|
const r = await client.call("POST", `/projects/${project}/locks/${lockName}/acquire`, { unit: unit ? Number(unit) : null, note: str(p.flags, "note") ?? "", shared: bool(p.flags, "shared") });
|
|
829
945
|
out.print(r.maintenance
|
|
830
|
-
? `${lockName} is not handed out now: ${r.maintenance}. You are #${r.position} in line and will be @mentioned when it is yours after the window; do not poll. Leave the queue:
|
|
946
|
+
? `${lockName} is not handed out now: ${r.maintenance}. You are #${r.position} in line and will be @mentioned when it is yours after the window; do not poll. Leave the queue: b9s unlock ${lockName}`
|
|
831
947
|
: r.acquired
|
|
832
|
-
? `You hold ${lockName}${r.lock.machine ? ` on ${r.lock.machine}` : " (shared)"}${unit ? ` for WU #${unit}` : ""}. Release it when done:
|
|
833
|
-
: `${lockName} is held by ${r.lock.holder_name}${r.lock.unit ? ` (WU #${r.lock.unit})` : ""}; you are ${r.position === 1 ? "next" : `#${r.position} in line`}. You will be @mentioned when it is yours; do not poll. Leave the queue:
|
|
948
|
+
? `You hold ${lockName}${r.lock.machine ? ` on ${r.lock.machine}` : " (shared)"}${unit ? ` for WU #${unit}` : ""}. Release it when done: b9s unlock ${lockName}`
|
|
949
|
+
: `${lockName} is held by ${r.lock.holder_name}${r.lock.unit ? ` (WU #${r.lock.unit})` : ""}; you are ${r.position === 1 ? "next" : `#${r.position} in line`}. You will be @mentioned when it is yours; do not poll. Leave the queue: b9s unlock ${lockName}`, r);
|
|
834
950
|
}
|
|
835
951
|
/**
|
|
836
|
-
*
|
|
952
|
+
* b9s ask-operator "what you need from them" --plain ".." --blocks ".." --if-yes ".." --if-no ".." [--propose ".."]:
|
|
837
953
|
* a decision only the operator can make, in a shape they can follow without the thread.
|
|
838
954
|
*/
|
|
839
955
|
export async function askOperator(p, out) {
|
|
@@ -900,7 +1016,7 @@ async function roundUsage(client, base, n, name) {
|
|
|
900
1016
|
return { harness: session?.harness ?? "unknown", source: "none", scope: "session", since, until, tokens: null, reason: `could not read the session: ${e.message}` };
|
|
901
1017
|
}
|
|
902
1018
|
}
|
|
903
|
-
/**
|
|
1019
|
+
/** b9s explain <ask-id> "...": the operator asked (the banner's Explain) for your request in plain words. */
|
|
904
1020
|
export async function explainAsk(p, out) {
|
|
905
1021
|
const name = resolveAgentName(str(p.flags, "as"));
|
|
906
1022
|
const creds = loadAgent(name);
|
package/dist/config.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { chmodSync, existsSync, mkdirSync, readFileSync, readdirSync, unlinkSync, writeFileSync } from "node:fs";
|
|
2
|
-
import { homedir } from "node:os";
|
|
3
2
|
import { join } from "node:path";
|
|
4
3
|
import { CliError } from "./errors.js";
|
|
5
4
|
import { findIdentityFile, readIdentityFile } from "./harness.js";
|
|
6
5
|
import { resolveModelDetailed } from "./model.js";
|
|
7
6
|
import { readState, writeState } from "./state.js";
|
|
8
7
|
import { detectVendor } from "./vendor.js";
|
|
8
|
+
import { configDirectory } from "./directories.js";
|
|
9
9
|
export const DEFAULT_URL = "https://api.benignswarm.org";
|
|
10
10
|
export function configRoot(env = process.env) {
|
|
11
|
-
return env
|
|
11
|
+
return configDirectory(env);
|
|
12
12
|
}
|
|
13
13
|
const NAME_RE = /^[a-z0-9][a-z0-9-_]{0,62}$/;
|
|
14
14
|
/**
|
|
@@ -121,12 +121,12 @@ export function resolveSavedRef(nameOrRef, env = process.env) {
|
|
|
121
121
|
if (matches.length === 1)
|
|
122
122
|
return matches[0];
|
|
123
123
|
if (matches.length === 0)
|
|
124
|
-
throw new CliError("not_logged_in", `no saved credentials for agent ${nameOrRef}`, `Run:
|
|
125
|
-
throw new CliError("ambiguous_identity", `"${nameOrRef}" is saved for more than one project on this machine: ${matches.join(", ")}`, `Say which one you are: --as ${matches[0]} (or BSCHAT_AGENT=${matches[0]}), or run from a checkout whose .
|
|
124
|
+
throw new CliError("not_logged_in", `no saved credentials for agent ${nameOrRef}`, `Run: b9s login --as ${nameOrRef} --key <bs_agent_...>`);
|
|
125
|
+
throw new CliError("ambiguous_identity", `"${nameOrRef}" is saved for more than one project on this machine: ${matches.join(", ")}`, `Say which one you are: --as ${matches[0]} (or BSCHAT_AGENT=${matches[0]}), or run from a checkout whose .b9s/identity.json names it.`);
|
|
126
126
|
}
|
|
127
127
|
/**
|
|
128
128
|
* Resolves which agent identity to use, in order: --as, BSCHAT_AGENT, then the repo-local
|
|
129
|
-
* `.
|
|
129
|
+
* `.b9s/identity.json` entry for the detected vendor (written by `b9s join`). There is
|
|
130
130
|
* no "only one saved identity" shortcut: several agents share this machine and cwd, so the
|
|
131
131
|
* only file-based answer accepted is an explicit per-vendor mapping for this repo.
|
|
132
132
|
*/
|
|
@@ -164,8 +164,8 @@ export function resolveAgentName(asFlag, env = process.env, cwd = process.cwd())
|
|
|
164
164
|
}
|
|
165
165
|
if (!name) {
|
|
166
166
|
const saved = listSaved("agents", env);
|
|
167
|
-
throw new CliError("no_identity", "BSCHAT_AGENT is not set and --as was not given;
|
|
168
|
-
? `Saved identities on this machine: ${saved.join(", ")}. Ask the user which one is yours, then: export BSCHAT_AGENT=<project>/<name> (or run:
|
|
167
|
+
throw new CliError("no_identity", "BSCHAT_AGENT is not set and --as was not given; b9s cannot tell which agent you are", saved.length
|
|
168
|
+
? `Saved identities on this machine: ${saved.join(", ")}. Ask the user which one is yours, then: export BSCHAT_AGENT=<project>/<name> (or run: b9s setup --as <project>/<name> to record it for this repo)`
|
|
169
169
|
: "No identities are saved here. Ask the account owner for an invite (an enrollment token) and run: npx -y benignswarm join --as <name> --token <bs_enroll_...>");
|
|
170
170
|
}
|
|
171
171
|
return isRef(name) ? name : resolveSavedRef(name, env);
|
|
@@ -174,7 +174,7 @@ export function loadAgent(nameOrRef, env = process.env) {
|
|
|
174
174
|
const ref = resolveSavedRef(nameOrRef, env);
|
|
175
175
|
const p = agentPath(ref, env);
|
|
176
176
|
if (!existsSync(p)) {
|
|
177
|
-
throw new CliError("not_logged_in", `no saved credentials for agent ${ref}`, `Run:
|
|
177
|
+
throw new CliError("not_logged_in", `no saved credentials for agent ${ref}`, `Run: b9s login --as ${splitRef(ref).name} --key <bs_agent_...>`);
|
|
178
178
|
}
|
|
179
179
|
return JSON.parse(readFileSync(p, "utf8"));
|
|
180
180
|
}
|
|
@@ -185,15 +185,15 @@ export function resolveAdminName(flag, env = process.env) {
|
|
|
185
185
|
const saved = listSaved("admins", env);
|
|
186
186
|
if (saved.length === 1)
|
|
187
187
|
return saved[0];
|
|
188
|
-
//
|
|
188
|
+
// b9s-admin login without --as saves under "default": that is the one meant when none is named.
|
|
189
189
|
if (saved.includes("default"))
|
|
190
190
|
return "default";
|
|
191
|
-
throw new CliError("no_admin", "BSCHAT_ADMIN is not set and --admin was not given", saved.length ? `Saved admin logins: ${saved.join(", ")}` : "Run:
|
|
191
|
+
throw new CliError("no_admin", "BSCHAT_ADMIN is not set and --admin was not given", saved.length ? `Saved admin logins: ${saved.join(", ")}` : "Run: b9s-admin login --email <you@example.com>");
|
|
192
192
|
}
|
|
193
193
|
export function loadAdmin(name, env = process.env) {
|
|
194
194
|
const p = adminPath(name, env);
|
|
195
195
|
if (!existsSync(p))
|
|
196
|
-
throw new CliError("not_logged_in", `no saved admin credentials named ${name}`, "Run:
|
|
196
|
+
throw new CliError("not_logged_in", `no saved admin credentials named ${name}`, "Run: b9s-admin login --email <you@example.com>");
|
|
197
197
|
return JSON.parse(readFileSync(p, "utf8"));
|
|
198
198
|
}
|
|
199
199
|
/**
|