benignswarm 0.12.82 → 0.12.84
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 +68 -25
- 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 +168 -61
- 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 +208 -183
- package/dist/index.js +37 -3
- package/dist/install.js +27 -19
- package/dist/legacy-alias.js +42 -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,15 +37,15 @@ 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
49
|
}
|
|
50
50
|
/** Keeps the former numeric --on unit request shape while allowing named review blockers. */
|
|
51
51
|
export function waitPayload(on, clear, note, partial = "") {
|
|
@@ -56,19 +56,19 @@ export function waitPayload(on, clear, note, partial = "") {
|
|
|
56
56
|
* Work units under the project's process. Work is described by tags from the project's
|
|
57
57
|
* vocabulary; reviewers are whoever is qualified to review those tags.
|
|
58
58
|
*
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
*
|
|
65
|
-
*
|
|
66
|
-
*
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
*
|
|
70
|
-
*
|
|
71
|
-
*
|
|
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
|
|
72
72
|
*/
|
|
73
73
|
export function parseEvidenceReplacement(positionals) {
|
|
74
74
|
if (positionals[2] !== "replace")
|
|
@@ -79,7 +79,7 @@ export function parseEvidenceReplacement(positionals) {
|
|
|
79
79
|
if (!Number.isInteger(unit) || unit < 1 || !oldId || !newId)
|
|
80
80
|
throw new CliError("usage", "wu evidence replace <n> <old> <new> [--note \"why\"]");
|
|
81
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))
|
|
82
|
-
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)`);
|
|
83
83
|
if (oldId === newId)
|
|
84
84
|
throw new CliError("usage", "the replacement evidence id must differ from the old id");
|
|
85
85
|
return { unit, oldId, newId };
|
|
@@ -104,6 +104,34 @@ export function changedPathsAgainstTarget(target, cwd = process.cwd()) {
|
|
|
104
104
|
export function submitPayload(fields, hasReviewRules, target, cwd = process.cwd()) {
|
|
105
105
|
return { ...fields, changed_paths: hasReviewRules ? changedPathsAgainstTarget(target, cwd) : [] };
|
|
106
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
|
+
}
|
|
107
135
|
export async function wu(p, out) {
|
|
108
136
|
const sub = p.positionals[1];
|
|
109
137
|
const name = resolveAgentName(str(p.flags, "as"));
|
|
@@ -120,10 +148,10 @@ export async function wu(p, out) {
|
|
|
120
148
|
// ester #57: a submission arrived with blank evidence ids after the shell swallowed backticks;
|
|
121
149
|
// three messages were spent recovering it. Refuse anything that is not an evidence id.
|
|
122
150
|
if (raw !== undefined && !items.length)
|
|
123
|
-
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");
|
|
124
152
|
return items.map((x) => x.replace(/^evidence:/, "")).map((x) => {
|
|
125
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))
|
|
126
|
-
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)`);
|
|
127
155
|
return x;
|
|
128
156
|
});
|
|
129
157
|
}
|
|
@@ -141,49 +169,104 @@ export async function wu(p, out) {
|
|
|
141
169
|
const reviewers = u.reviewers.map((r) => `${r.name}${r.tags.length ? ` for ${r.tags.map((t) => `#${t}`).join(" ")}` : ""}`).join(", ");
|
|
142
170
|
const approvals = u.approvals.map((a) => a.name).join(", ");
|
|
143
171
|
return [
|
|
144
|
-
`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,
|
|
145
174
|
` owner ${u.owner_name || "unassigned (queued)"}${reviewers ? ` · reviewers ${reviewers}` : ""}${approvals ? ` · approved by ${approvals}` : ""}${u.uncovered?.length ? ` · awaiting ${u.uncovered.map((t) => `#${t}`).join(" ")}` : ""}`,
|
|
146
175
|
Object.keys(u.tag_focus ?? {}).length ? ` review focus:\n${Object.entries(u.tag_focus).map(([tag, focus]) => ` #${tag}: ${focus}`).join("\n")}` : null,
|
|
147
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,
|
|
148
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,
|
|
149
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(" ")}` : ""}`,
|
|
150
180
|
u.scope ? ` scope: ${u.scope}` : null,
|
|
151
181
|
].filter(Boolean).join("\n");
|
|
152
182
|
};
|
|
153
183
|
const processDef = async () => (await client.call("GET", `/projects/${project}/process`)).process.definition;
|
|
154
|
-
|
|
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.
|
|
155
215
|
const checkoutExclude = async () => (await client.call("GET", `/projects/${project}/process`)).checkout?.exclude ?? [];
|
|
156
216
|
switch (sub) {
|
|
157
217
|
case "open": {
|
|
158
218
|
const title = p.positionals.slice(2).join(" ").trim();
|
|
159
219
|
if (!title)
|
|
160
|
-
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();
|
|
161
223
|
// The unit exists first (it needs its number for the branch name), then its worktree is made
|
|
162
224
|
// and recorded exactly as `wu start` would; --here keeps the current checkout.
|
|
163
|
-
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 });
|
|
164
226
|
const n = r.unit.number;
|
|
165
227
|
const { path, branch, mode } = prepareWorktree(n, r.unit, await processDef(), p, await checkoutExclude());
|
|
166
228
|
const where = branchAndHead(path);
|
|
167
229
|
const s = await client.call("POST", `${base}/${n}/start`, { branch: branch ?? where.branch, head: where.head, worktree: path, mode });
|
|
168
|
-
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 });
|
|
169
231
|
return;
|
|
170
232
|
}
|
|
171
233
|
case "assign": {
|
|
172
234
|
// Dispatch as state: the unit exists from now, the worker is mentioned, the sweep chases it.
|
|
173
|
-
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
|
+
}
|
|
174
247
|
const to = str(p.flags, "to");
|
|
175
|
-
if (!
|
|
176
|
-
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();
|
|
177
260
|
const replay = str(p.flags, "replay-of");
|
|
178
|
-
const r = await client.call("POST", `${base}/assign`, { to, title, scope
|
|
179
|
-
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);
|
|
180
263
|
return;
|
|
181
264
|
}
|
|
182
265
|
case "take": {
|
|
183
266
|
// Pull a queued unit: for yourself (qualified by works or trial), or for someone with --to (assigners).
|
|
184
267
|
const to = str(p.flags, "to") ?? null;
|
|
185
268
|
const r = await client.call("POST", `${base}/${num()}/take`, { to });
|
|
186
|
-
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);
|
|
187
270
|
return;
|
|
188
271
|
}
|
|
189
272
|
case "next": {
|
|
@@ -192,7 +275,7 @@ export async function wu(p, out) {
|
|
|
192
275
|
out.print("(nothing queued that you qualify for)", { unit: null });
|
|
193
276
|
return;
|
|
194
277
|
}
|
|
195
|
-
out.print(`${fmt(r.unit)}\nYours. Start it:
|
|
278
|
+
out.print(`${fmt(r.unit)}\nYours. Start it: b9s wu start ${r.unit.number}`, r);
|
|
196
279
|
return;
|
|
197
280
|
}
|
|
198
281
|
case "start": {
|
|
@@ -218,7 +301,7 @@ export async function wu(p, out) {
|
|
|
218
301
|
}
|
|
219
302
|
throw error;
|
|
220
303
|
}
|
|
221
|
-
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 });
|
|
222
305
|
return;
|
|
223
306
|
}
|
|
224
307
|
case "decline": {
|
|
@@ -252,19 +335,30 @@ export async function wu(p, out) {
|
|
|
252
335
|
}
|
|
253
336
|
else if (def.merge.require_pushed) {
|
|
254
337
|
const message = formatRemoteCommitFailure(localBranch, check.checkedRef, check.reason ?? "no containing origin branch was found");
|
|
255
|
-
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");
|
|
256
339
|
}
|
|
257
340
|
else if (pushed !== true) {
|
|
258
|
-
process.stderr.write(`
|
|
341
|
+
process.stderr.write(`b9s: ${formatRemoteCommitFailure(localBranch, check.checkedRef, check.reason ?? "no containing origin branch was found")}\n`);
|
|
259
342
|
}
|
|
260
343
|
}
|
|
261
344
|
else if (def.merge.require_pushed) {
|
|
262
|
-
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");
|
|
263
346
|
}
|
|
264
347
|
}
|
|
265
348
|
const pr = str(p.flags, "pr") ?? null;
|
|
266
349
|
const usage = await roundUsage(client, base, num(), name);
|
|
267
|
-
|
|
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);
|
|
268
362
|
const r = await client.call("POST", `${base}/${num()}/submit`, payload);
|
|
269
363
|
const u = r.unit;
|
|
270
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);
|
|
@@ -329,7 +423,7 @@ export async function wu(p, out) {
|
|
|
329
423
|
if (!note)
|
|
330
424
|
throw new CliError("usage", 'wu hold <n> --note "what must happen before it moves on" (operator or assigner)');
|
|
331
425
|
const r = await client.call("POST", `${base}/${num()}/hold`, { note });
|
|
332
|
-
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);
|
|
333
427
|
return;
|
|
334
428
|
}
|
|
335
429
|
case "release": {
|
|
@@ -338,7 +432,14 @@ export async function wu(p, out) {
|
|
|
338
432
|
return;
|
|
339
433
|
}
|
|
340
434
|
case "scope": {
|
|
341
|
-
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"');
|
|
342
443
|
const r = await client.call("POST", `${base}/${num()}/scope`, edit);
|
|
343
444
|
out.print(`${fmt(r.unit)}\nScope amended; the owner and reviewers were told.`, r);
|
|
344
445
|
return;
|
|
@@ -410,7 +511,7 @@ export async function wu(p, out) {
|
|
|
410
511
|
}
|
|
411
512
|
}
|
|
412
513
|
else if (def.merge.require_merge_commit) {
|
|
413
|
-
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>`);
|
|
414
515
|
}
|
|
415
516
|
const r = await client.call("POST", `${base}/${num()}/done`, { note: str(p.flags, "note") ?? "", merged });
|
|
416
517
|
out.print(fmt(r.unit) + (verifiedRemoteTarget ? `\nverified on ${verifiedRemoteTarget}` : "") + cleanupUnitWorktree(r.unit.worktree, def, !!p.flags["keep-worktree"]), r);
|
|
@@ -454,7 +555,8 @@ export async function wu(p, out) {
|
|
|
454
555
|
case "review": {
|
|
455
556
|
// The reviewer's checkout: the submitted commit, fetched from the remote, in its own worktree.
|
|
456
557
|
const n = num();
|
|
457
|
-
const
|
|
558
|
+
const reviewDetail = await client.call("GET", `${base}/${n}`);
|
|
559
|
+
const unit = reviewDetail.unit;
|
|
458
560
|
if (!unit.branch)
|
|
459
561
|
throw new CliError("no_branch", `WU #${n} has no branch recorded; ask ${unit.owner_name} to submit from the branch`);
|
|
460
562
|
if (!unit.head)
|
|
@@ -492,7 +594,8 @@ export async function wu(p, out) {
|
|
|
492
594
|
const path = resolve(parent, `${name}-review-wu${n}`);
|
|
493
595
|
const made = ensureReviewWorktree(path, remote);
|
|
494
596
|
const ev = unit.evidence.map((e) => `evidence:${e}`).join(" ") || "(none)";
|
|
495
|
-
|
|
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 });
|
|
496
599
|
return;
|
|
497
600
|
}
|
|
498
601
|
case "show": {
|
|
@@ -503,7 +606,8 @@ export async function wu(p, out) {
|
|
|
503
606
|
return;
|
|
504
607
|
}
|
|
505
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");
|
|
506
|
-
|
|
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);
|
|
507
611
|
return;
|
|
508
612
|
}
|
|
509
613
|
case "list":
|
|
@@ -516,7 +620,7 @@ export async function wu(p, out) {
|
|
|
516
620
|
qs.set(k, str(p.flags, k));
|
|
517
621
|
const r = await client.call("GET", `${base}${qs.size ? `?${qs}` : ""}`);
|
|
518
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) }));
|
|
519
|
-
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);
|
|
520
624
|
return;
|
|
521
625
|
}
|
|
522
626
|
default:
|
|
@@ -544,13 +648,14 @@ export async function processCmd(p, out) {
|
|
|
544
648
|
const lines = [
|
|
545
649
|
`Process v${r.process.version}${r.process.version === 0 ? " (defaults; the operator has not published one)" : ""}`,
|
|
546
650
|
`Machine capabilities: ${(d.capabilities ?? []).map((c) => `${c.name} (${c.scope}${c.min_version ? ` >= ${c.min_version}` : ""})`).join(", ") || "none"}`,
|
|
547
|
-
vocab.length ? `Tags (use them on
|
|
548
|
-
...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}` : ""}`)]),
|
|
549
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})`)] : []),
|
|
550
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.` : ""}`,
|
|
551
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.`,
|
|
552
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}.`,
|
|
553
|
-
`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>)" : ""}.`,
|
|
554
659
|
r.process.agreements ? `\nWorking agreements:\n${r.process.agreements}` : null,
|
|
555
660
|
r.process.charter ? `\nCharter (how this project weighs its trade-offs; judge reviews and questions by it):\n${r.process.charter}` : null,
|
|
556
661
|
].filter(Boolean);
|
|
@@ -571,7 +676,7 @@ function cleanupUnitWorktree(wt, def, keep) {
|
|
|
571
676
|
if (res.removed)
|
|
572
677
|
return `\nRemoved worktree ${wt} (branch kept).`;
|
|
573
678
|
if (res.reason === "uncommitted changes")
|
|
574
|
-
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.`;
|
|
575
680
|
return `\nWorktree ${wt} kept: ${res.reason}.`;
|
|
576
681
|
}
|
|
577
682
|
/**
|
|
@@ -581,7 +686,7 @@ function cleanupUnitWorktree(wt, def, keep) {
|
|
|
581
686
|
function prepareWorktree(n, unit, def, p, exclude = []) {
|
|
582
687
|
// The unit's own target when it has one: a lane or release branch the work lands in.
|
|
583
688
|
const target = unit.target ?? def.merge.target_branch;
|
|
584
|
-
const log = (line) => process.stderr.write(`
|
|
689
|
+
const log = (line) => process.stderr.write(`b9s: ${line}\n`);
|
|
585
690
|
// Where reviewers may be on other machines, origin is the truth: start from origin's target, not
|
|
586
691
|
// this machine's possibly stale copy, and continue a pinned branch from what origin has of it.
|
|
587
692
|
const remoteFirst = !!def.merge.require_pushed;
|
|
@@ -650,7 +755,7 @@ export async function milestones(p, out) {
|
|
|
650
755
|
return milestonesWith(client, project, p.positionals[1], p, out);
|
|
651
756
|
}
|
|
652
757
|
/**
|
|
653
|
-
* The plan's milestones, shared by agents (`
|
|
758
|
+
* The plan's milestones, shared by agents (`b9s milestones`) and the operator (`b9s-admin
|
|
654
759
|
* milestones <project>`): list, `export` (the editable JSON list `set` takes) and `set`.
|
|
655
760
|
*/
|
|
656
761
|
export async function milestonesWith(client, project, sub, p, out) {
|
|
@@ -684,7 +789,7 @@ export async function milestonesWith(client, project, sub, p, out) {
|
|
|
684
789
|
}
|
|
685
790
|
const r = await client.call("GET", `/projects/${project}/milestones`);
|
|
686
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) }));
|
|
687
|
-
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);
|
|
688
793
|
}
|
|
689
794
|
/** milestone show <key> | milestone close <key> --note ".." [--evidence a,b] [--abandon | --defer] | milestone reopen <key> */
|
|
690
795
|
export async function milestone(p, out) {
|
|
@@ -696,11 +801,11 @@ export async function milestone(p, out) {
|
|
|
696
801
|
throw new CliError("no_project", `${creds.agent} is an account-scoped agent; pass --project <name>`);
|
|
697
802
|
return milestoneWith(client, project, p.positionals[1], p.positionals[2], p, out, p.positionals.slice(3));
|
|
698
803
|
}
|
|
699
|
-
/** One milestone, shared by agents (`
|
|
804
|
+
/** One milestone, shared by agents (`b9s milestone`) and the operator (`b9s-admin milestone <project>`). */
|
|
700
805
|
export async function milestoneWith(client, project, sub, key, p, out, decisionParts = p.positionals.slice(3)) {
|
|
701
806
|
if (!key)
|
|
702
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>');
|
|
703
|
-
// "set" is "edit" (
|
|
808
|
+
// "set" is "edit" (b9s milestone set <key> --priority 5): one slice changed, the rest untouched.
|
|
704
809
|
if (sub === "set")
|
|
705
810
|
sub = "edit";
|
|
706
811
|
if (sub === "decide") {
|
|
@@ -750,7 +855,9 @@ export async function milestoneWith(client, project, sub, key, p, out, decisionP
|
|
|
750
855
|
throw new CliError("not_found", `no milestone ${key}`);
|
|
751
856
|
const detail = await client.call("GET", `/projects/${project}/milestones/${key}`);
|
|
752
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("");
|
|
753
|
-
|
|
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 });
|
|
754
861
|
return;
|
|
755
862
|
}
|
|
756
863
|
if (sub === "close") {
|
|
@@ -810,7 +917,7 @@ export async function record(p, out) {
|
|
|
810
917
|
const rows = r.record.map((x) => ({ agent: x.agent, tag: `#${x.tag}`, ...counters(x) }));
|
|
811
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);
|
|
812
919
|
}
|
|
813
|
-
/**
|
|
920
|
+
/** b9s lock <name> [--unit n] [--note ..] | b9s unlock <name> | b9s locks */
|
|
814
921
|
export async function lock(p, out) {
|
|
815
922
|
const name = resolveAgentName(str(p.flags, "as"));
|
|
816
923
|
const creds = loadAgent(name);
|
|
@@ -822,11 +929,11 @@ export async function lock(p, out) {
|
|
|
822
929
|
const lockName = p.positionals[1];
|
|
823
930
|
if (cmd === "locks") {
|
|
824
931
|
const r = await client.call("GET", `/projects/${project}/locks`);
|
|
825
|
-
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);
|
|
826
933
|
return;
|
|
827
934
|
}
|
|
828
935
|
if (!lockName)
|
|
829
|
-
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")`);
|
|
830
937
|
if (cmd === "unlock") {
|
|
831
938
|
const r = await client.call("POST", `/projects/${project}/locks/${lockName}/release`, { shared: bool(p.flags, "shared") });
|
|
832
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);
|
|
@@ -836,13 +943,13 @@ export async function lock(p, out) {
|
|
|
836
943
|
// Scoped to this machine unless --shared: the resource is this box's CPU and disk.
|
|
837
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") });
|
|
838
945
|
out.print(r.maintenance
|
|
839
|
-
? `${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}`
|
|
840
947
|
: r.acquired
|
|
841
|
-
? `You hold ${lockName}${r.lock.machine ? ` on ${r.lock.machine}` : " (shared)"}${unit ? ` for WU #${unit}` : ""}. Release it when done:
|
|
842
|
-
: `${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);
|
|
843
950
|
}
|
|
844
951
|
/**
|
|
845
|
-
*
|
|
952
|
+
* b9s ask-operator "what you need from them" --plain ".." --blocks ".." --if-yes ".." --if-no ".." [--propose ".."]:
|
|
846
953
|
* a decision only the operator can make, in a shape they can follow without the thread.
|
|
847
954
|
*/
|
|
848
955
|
export async function askOperator(p, out) {
|
|
@@ -909,7 +1016,7 @@ async function roundUsage(client, base, n, name) {
|
|
|
909
1016
|
return { harness: session?.harness ?? "unknown", source: "none", scope: "session", since, until, tokens: null, reason: `could not read the session: ${e.message}` };
|
|
910
1017
|
}
|
|
911
1018
|
}
|
|
912
|
-
/**
|
|
1019
|
+
/** b9s explain <ask-id> "...": the operator asked (the banner's Explain) for your request in plain words. */
|
|
913
1020
|
export async function explainAsk(p, out) {
|
|
914
1021
|
const name = resolveAgentName(str(p.flags, "as"));
|
|
915
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
|
/**
|