benignswarm 0.12.97 → 0.12.99

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.
@@ -0,0 +1,396 @@
1
+ import { bool, str } from "../args.js";
2
+ import { Client } from "../client.js";
3
+ import { loadAdmin, resolveAdminName } from "../config.js";
4
+ import { CliError } from "../errors.js";
5
+ import { table } from "../output.js";
6
+ const adminClient = (p) => Client.forAdmin(loadAdmin(resolveAdminName(str(p.flags, "admin"))));
7
+ /** Parses provider/harness/canonical_model/effort, refusing shorthand guesses. */
8
+ export function parseClassSpec(raw) {
9
+ const parts = raw.trim().split("/");
10
+ if (parts.length !== 4 || parts.some((x) => !x.trim())) {
11
+ throw new CliError("usage", "routing class must be <provider>/<harness>/<canonical_model>/<effort> (e.g. anthropic/claude-code/claude-sonnet-4-5/high)");
12
+ }
13
+ const [provider, harness, canonical_model, effort] = parts.map((x) => x.trim());
14
+ return { provider: provider, harness: harness, canonical_model: canonical_model, effort: effort };
15
+ }
16
+ export function formatClassSpec(cls) {
17
+ if (!cls)
18
+ return "unknown";
19
+ return `${cls.provider ?? "unknown"}/${cls.harness ?? "unknown"}/${cls.canonical_model ?? cls.model ?? "unknown"}/${cls.effort ?? "unknown"}`;
20
+ }
21
+ function formatEstimate(row) {
22
+ if (row.weighted_estimate === null || row.weighted_estimate === undefined)
23
+ return "unknown";
24
+ if (row.unit === "milliseconds")
25
+ return `${Math.round(Number(row.weighted_estimate) / 1000)}s`;
26
+ return `${Math.round(Number(row.weighted_estimate) * 100)}%`;
27
+ }
28
+ function formatInterval(row) {
29
+ if (!row.interval_95)
30
+ return "-";
31
+ if (row.unit === "milliseconds") {
32
+ return `[${Math.round(row.interval_95.lower / 1000)}s, ${Math.round(row.interval_95.upper / 1000)}s]`;
33
+ }
34
+ return `[${Math.round(row.interval_95.lower * 100)}%, ${Math.round(row.interval_95.upper * 100)}%]`;
35
+ }
36
+ /** Formats class x tag confidence rows into an operator-readable matrix table. */
37
+ export function formatConfidenceMatrix(rows, opts = {}) {
38
+ const filtered = rows.filter((r) => (!opts.mode || r.mode === opts.mode) && (!opts.tag || `#${r.tag}` === `#${opts.tag.replace(/^#/, "")}`));
39
+ if (!filtered.length)
40
+ return "(no confidence matrix observations match filters)";
41
+ const mapped = filtered.map((r) => ({
42
+ mode: r.mode,
43
+ tag: `#${r.tag}`,
44
+ class: formatClassSpec(r.routing_class),
45
+ measure: r.outcome_measure,
46
+ estimate: formatEstimate(r),
47
+ ci95: formatInterval(r),
48
+ eff_n: String(Math.round((Number(r.effective_sample_size ?? 0)) * 10) / 10),
49
+ n: String(r.denominator ?? 0),
50
+ status: r.status,
51
+ guardrail: r.quality_guardrail ?? "-",
52
+ }));
53
+ return table(mapped, ["mode", "tag", "class", "measure", "estimate", "ci95", "eff_n", "n", "status", "guardrail"]);
54
+ }
55
+ /** Formats hard required_class + build/review assignment explanation recorded on a unit. */
56
+ export function formatUnitRoutingExplanation(u) {
57
+ const lines = [];
58
+ if (u.required_class) {
59
+ const rc = u.required_class;
60
+ lines.push(` required_class: ${formatClassSpec(rc)} (by ${rc.actor_name ?? "operator"}; reason: ${rc.reason ?? "none"})`);
61
+ }
62
+ if (u.route_decision) {
63
+ const rd = u.route_decision;
64
+ lines.push(` build_route: ${rd.chosen_agent ?? "queued"} · ${formatClassSpec(rd.chosen_class)} · mode ${rd.mode ?? "none"} · ${rd.reason ?? ""}${rd.cost_basis ? ` (cost basis: ${rd.cost_basis})` : ""}`);
65
+ if (rd.preferred_class_unavailable) {
66
+ const pu = rd.preferred_class_unavailable;
67
+ lines.push(` preferred unavailable: ${formatClassSpec(pu.preferred_class)} (${Array.isArray(pu.blockers) ? pu.blockers.join("; ") : pu.reason ?? "unavailable"})`);
68
+ }
69
+ if (Array.isArray(rd.per_tag) && rd.per_tag.length) {
70
+ lines.push(` per-tag: ${rd.per_tag.map((t) => `#${t.tag} score=${t.score ?? "?"}${t.provisional ? "" : " (floor)"}`).join(", ")}`);
71
+ }
72
+ }
73
+ if (u.review_route) {
74
+ const rr = u.review_route;
75
+ lines.push(` review_route: mode ${rr.mode ?? "none"} · chosen ${(rr.selected_reviewers ?? []).map((x) => `${x.agent ?? x.name}(${formatClassSpec(x.routing_class)})`).join(", ") || "none"} · ${rr.reason ?? ""}`);
76
+ }
77
+ if (Array.isArray(u.dispatch_reasons) && u.dispatch_reasons.length) {
78
+ lines.push(` dispatch_reasons:`);
79
+ for (const d of u.dispatch_reasons.slice(0, 8)) {
80
+ lines.push(` - ${d.agent ?? "?"} (${formatClassSpec(d.routing_class)}): eligible=${Boolean(d.eligible)}${d.score !== undefined ? ` score=${d.score}` : ""}${d.reason ? ` · ${d.reason}` : ""}`);
81
+ }
82
+ }
83
+ return lines;
84
+ }
85
+ export function formatExplorationSummary(label, state) {
86
+ if (!state)
87
+ return ` ${label}_exploration: unknown`;
88
+ return ` ${label}_exploration: budget ${state.budget_percent ?? 0}%, spent ${state.spent_percent ?? 0}% (${state.explored_assignments ?? 0}/${state.total_assignments ?? 0}), remaining ${state.remaining_percent ?? 0}%, ${state.paused ? `PAUSED (${state.pause_reason ?? "paused"})` : "active"}`;
89
+ }
90
+ export function formatPoolSuggestion(s) {
91
+ const before = Object.entries(s.slot_effect?.before ?? {}).map(([k, v]) => `${k}=${v}`).join(", ");
92
+ const after = Object.entries(s.slot_effect?.after ?? {}).map(([k, v]) => `${k}=${v}`).join(", ");
93
+ const costBasis = s.evidence_snapshot?.cost_basis ?? "unknown";
94
+ const machines = Array.isArray(s.evidence_snapshot?.constraints?.eligible_machines)
95
+ ? s.evidence_snapshot.constraints.eligible_machines.join(", ") || "none"
96
+ : "unknown";
97
+ return [
98
+ `${s.id} [${s.status}] pool ${s.pool_name} variant ${s.variant_tag} (#${s.tag}, basis: ${s.basis})`,
99
+ ` weight ${s.current_weight} -> ${s.suggested_weight}; slots(${s.slot_effect?.pool_count ?? "?"}): ${before} -> ${after}`,
100
+ ` ${s.summary}`,
101
+ ` machines: ${machines}; cost_basis: ${costBasis}${s.decision_note ? `; note: ${s.decision_note}` : ""}`,
102
+ ].join("\n");
103
+ }
104
+ function parseBoolChoice(raw, flag) {
105
+ const norm = raw.trim().toLowerCase();
106
+ if (norm === "yes" || norm === "true" || norm === "on")
107
+ return true;
108
+ if (norm === "no" || norm === "false" || norm === "off")
109
+ return false;
110
+ throw new CliError("usage", `--${flag} must be yes|no (or true|false)`);
111
+ }
112
+ function normalizeTag(raw) {
113
+ const t = raw.trim().replace(/^#/, "").toLowerCase();
114
+ if (!t)
115
+ throw new CliError("usage", "tag name is required");
116
+ return t;
117
+ }
118
+ function parseUnitNum(raw, usage) {
119
+ const n = Number(raw);
120
+ if (!raw || !Number.isInteger(n) || n < 1)
121
+ throw new CliError("usage", usage);
122
+ return n;
123
+ }
124
+ export async function runRequiredClassUpdate(c, project, unitNumber, p, out) {
125
+ const clear = bool(p.flags, "clear");
126
+ const clsRaw = str(p.flags, "class");
127
+ const reason = str(p.flags, "reason")?.trim();
128
+ if ((clear && clsRaw) || (!clear && !clsRaw) || !reason) {
129
+ throw new CliError("usage", 'required-class <project> <unit> (--class <provider>/<harness>/<canonical_model>/<effort> | --clear) --reason "why"');
130
+ }
131
+ const spec = clear ? null : parseClassSpec(clsRaw);
132
+ const body = clear
133
+ ? { required_class: null, reason }
134
+ : { required_class: { ...spec, reason }, reason };
135
+ const r = await c.call("POST", `/projects/${project}/work-units/${unitNumber}/required-class`, body);
136
+ const rc = r.unit?.required_class;
137
+ out.print(rc
138
+ ? `WU #${unitNumber}: required_class set to ${formatClassSpec(rc)} (reason: ${rc.reason}).`
139
+ : `WU #${unitNumber}: required_class cleared (reason: ${reason}).`, r);
140
+ }
141
+ /**
142
+ * Operator routing console CLI (WU #242):
143
+ * b9s-admin routing show <project> [--mode build|review] [--tag <tag>]
144
+ * b9s-admin routing policy <project> [--weights q,t,c] [--quality-target <0..100|none>] [--half-life <days>] [--min-samples <n>] [--build-explore <0..20>] [--review-explore <0..20>] [--pause-build yes|no] [--pause-review yes|no] [--reason "why"]
145
+ * b9s-admin routing explain <project> <unit>
146
+ * b9s-admin routing required-class <project> <unit> (--class p/h/m/e | --clear) --reason "why"
147
+ * b9s-admin routing tag-required-class <project> <tag> (--class p/h/m/e | --clear) --reason "why"
148
+ * b9s-admin routing tier-migration <project>
149
+ * b9s-admin routing pool-suggestions <project> [--status pending|accepted|rejected|superseded|all]
150
+ */
151
+ export async function routingAdmin(action, rest, p, out) {
152
+ const c = adminClient(p);
153
+ switch (action) {
154
+ case "show": {
155
+ const project = rest[0];
156
+ if (!project)
157
+ throw new CliError("usage", "routing show <project> [--mode build|review] [--tag <tag>]");
158
+ const mode = str(p.flags, "mode");
159
+ if (mode && mode !== "build" && mode !== "review")
160
+ throw new CliError("usage", "--mode must be build or review");
161
+ const tag = str(p.flags, "tag");
162
+ const r = await c.call("GET", `/projects/${project}/routing`);
163
+ const pol = r.policy ?? {};
164
+ const w = pol.weights ?? { quality: 65, time: 20, cost: 15 };
165
+ const lines = [
166
+ `Routing for ${r.project} (cost tracking is currently unavailable cleanly until WU #236):`,
167
+ ` policy: weights quality=${w.quality}% time=${w.time}% cost=${w.cost}%, quality target=${pol.quality_target_percent ?? "none"}, half-life=${pol.recency_half_life_days ?? 30}d, min samples=${pol.minimum_sample_count ?? 8}`,
168
+ formatExplorationSummary("build", r.exploration?.build),
169
+ formatExplorationSummary("review", r.exploration?.review),
170
+ r.vocabulary_required_classes?.length
171
+ ? ` tag required classes: ${r.vocabulary_required_classes.map((x) => `#${x.tag}=${formatClassSpec(x.required_class)}`).join("; ")}`
172
+ : ` tag required classes: none`,
173
+ "",
174
+ "Confidence matrix:",
175
+ formatConfidenceMatrix(r.confidence ?? [], { mode, tag }),
176
+ ];
177
+ if (Array.isArray(r.recent_build_decisions) && r.recent_build_decisions.length) {
178
+ lines.push("", "Recent build decisions:");
179
+ for (const d of r.recent_build_decisions.slice(0, 8)) {
180
+ lines.push(` WU #${d.unit_number} (${d.mode}): ${d.chosen_agent ?? "?"} · ${formatClassSpec(d.chosen_class)} · ${d.reason ?? ""}`);
181
+ }
182
+ }
183
+ if (Array.isArray(r.recent_review_decisions) && r.recent_review_decisions.length) {
184
+ lines.push("", "Recent review decisions:");
185
+ for (const d of r.recent_review_decisions.slice(0, 8)) {
186
+ lines.push(` WU #${d.unit_number} (${d.mode}): ${d.reason ?? ""}`);
187
+ }
188
+ }
189
+ if (Array.isArray(r.comparisons) && r.comparisons.length) {
190
+ lines.push("", `Recent comparisons (${r.comparisons.length}): ${r.comparisons.slice(0, 5).map((x) => `pair ${x.compare_group_id ?? x.id ?? "?"}`).join(", ")}`);
191
+ }
192
+ out.print(lines.join("\n"), r);
193
+ return;
194
+ }
195
+ case "policy": {
196
+ const project = rest[0];
197
+ if (!project)
198
+ throw new CliError("usage", "routing policy <project> [--weights q,t,c] [--quality-target <0..100|none>] [--half-life <days>] [--min-samples <n>] [--build-explore <0..20>] [--review-explore <0..20>] [--pause-build yes|no] [--pause-review yes|no] [--reason \"why\"]");
199
+ const current = await c.call("GET", `/projects/${project}/process`);
200
+ const nextPolicy = { ...(current.process?.definition?.routing_policy ?? {}) };
201
+ let changed = false;
202
+ const weightsRaw = str(p.flags, "weights");
203
+ if (weightsRaw !== undefined) {
204
+ const parts = weightsRaw.split(",").map((x) => Number(x.trim()));
205
+ if (parts.length !== 3 || parts.some((n) => !Number.isInteger(n) || n < 0) || parts[0] + parts[1] + parts[2] !== 100) {
206
+ throw new CliError("usage", "--weights must be three non-negative integers q,t,c summing to 100 (e.g. 65,20,15)");
207
+ }
208
+ nextPolicy.weights = { quality: parts[0], time: parts[1], cost: parts[2] };
209
+ changed = true;
210
+ }
211
+ const qtRaw = str(p.flags, "quality-target");
212
+ if (qtRaw !== undefined) {
213
+ if (qtRaw === "none" || qtRaw === "null")
214
+ nextPolicy.quality_target_percent = null;
215
+ else {
216
+ const qt = Number(qtRaw);
217
+ if (!Number.isFinite(qt) || qt < 0 || qt > 100)
218
+ throw new CliError("usage", "--quality-target must be 0..100 or none");
219
+ nextPolicy.quality_target_percent = qt;
220
+ }
221
+ changed = true;
222
+ }
223
+ const hlRaw = str(p.flags, "half-life");
224
+ if (hlRaw !== undefined) {
225
+ const hl = Number(hlRaw);
226
+ if (!Number.isInteger(hl) || hl < 1 || hl > 3650)
227
+ throw new CliError("usage", "--half-life must be an integer 1..3650");
228
+ nextPolicy.recency_half_life_days = hl;
229
+ changed = true;
230
+ }
231
+ const msRaw = str(p.flags, "min-samples");
232
+ if (msRaw !== undefined) {
233
+ const ms = Number(msRaw);
234
+ if (!Number.isInteger(ms) || ms < 5 || ms > 100000)
235
+ throw new CliError("usage", "--min-samples must be an integer 5..100000");
236
+ nextPolicy.minimum_sample_count = ms;
237
+ changed = true;
238
+ }
239
+ const beRaw = str(p.flags, "build-explore");
240
+ if (beRaw !== undefined) {
241
+ const be = Number(beRaw);
242
+ if (!Number.isInteger(be) || be < 0 || be > 20)
243
+ throw new CliError("usage", "--build-explore must be an integer 0..20");
244
+ nextPolicy.build_exploration_budget_percent = be;
245
+ changed = true;
246
+ }
247
+ const reRaw = str(p.flags, "review-explore");
248
+ if (reRaw !== undefined) {
249
+ const re = Number(reRaw);
250
+ if (!Number.isInteger(re) || re < 0 || re > 20)
251
+ throw new CliError("usage", "--review-explore must be an integer 0..20");
252
+ nextPolicy.review_exploration_budget_percent = re;
253
+ changed = true;
254
+ }
255
+ const pbRaw = str(p.flags, "pause-build");
256
+ if (pbRaw !== undefined) {
257
+ nextPolicy.build_exploration_paused = parseBoolChoice(pbRaw, "pause-build");
258
+ changed = true;
259
+ }
260
+ const prRaw = str(p.flags, "pause-review");
261
+ if (prRaw !== undefined) {
262
+ nextPolicy.review_exploration_paused = parseBoolChoice(prRaw, "pause-review");
263
+ changed = true;
264
+ }
265
+ if (!changed) {
266
+ throw new CliError("usage", "pass at least one routing policy flag (--weights, --quality-target, --half-life, --min-samples, --build-explore, --review-explore, --pause-build, --pause-review)");
267
+ }
268
+ const reason = str(p.flags, "reason");
269
+ const r = await c.call("PUT", `/projects/${project}/process`, {
270
+ definition: { routing_policy: nextPolicy },
271
+ ...(reason ? { reason } : {}),
272
+ });
273
+ const updated = r.process?.definition?.routing_policy ?? nextPolicy;
274
+ out.print(`${project} process v${r.process?.version ?? "?"}: weights ${updated.weights.quality}/${updated.weights.time}/${updated.weights.cost}, quality target ${updated.quality_target_percent ?? "none"}, half-life ${updated.recency_half_life_days ?? 30}d, min samples ${updated.minimum_sample_count}, build explore ${updated.build_exploration_budget_percent}%${updated.build_exploration_paused ? " (PAUSED)" : ""}, review explore ${updated.review_exploration_budget_percent}%${updated.review_exploration_paused ? " (PAUSED)" : ""}.`, r);
275
+ return;
276
+ }
277
+ case "explain": {
278
+ const project = rest[0];
279
+ const n = parseUnitNum(rest[1], "routing explain <project> <unit>");
280
+ if (!project)
281
+ throw new CliError("usage", "routing explain <project> <unit>");
282
+ const r = await c.call("GET", `/projects/${project}/work-units/${n}`);
283
+ const u = r.unit;
284
+ const lines = [
285
+ `WU #${u.number} [${u.status}] tags ${(u.tags ?? []).map((t) => `#${t}`).join(" ") || "(none)"} · owner ${u.owner_name || "(none)"}`,
286
+ ...formatUnitRoutingExplanation(u),
287
+ ];
288
+ const routeEvents = Array.isArray(r.events)
289
+ ? r.events.filter((e) => e.data?.route_decision || e.data?.required_class || e.type === "assigned" || e.type === "queued" || e.type === "submitted")
290
+ : [];
291
+ if (routeEvents.length) {
292
+ lines.push(" events:");
293
+ for (const e of routeEvents.slice(-5)) {
294
+ lines.push(` ${e.at?.slice(0, 16).replace("T", " ") ?? ""} ${e.type} by ${e.actor_name ?? "?"}${e.note ? `: ${e.note}` : ""}`);
295
+ }
296
+ }
297
+ out.print(lines.join("\n"), r);
298
+ return;
299
+ }
300
+ case "required-class": {
301
+ const project = rest[0];
302
+ const n = parseUnitNum(rest[1], 'routing required-class <project> <unit> (--class p/h/m/e | --clear) --reason "why"');
303
+ if (!project)
304
+ throw new CliError("usage", 'routing required-class <project> <unit> (--class p/h/m/e | --clear) --reason "why"');
305
+ await runRequiredClassUpdate(c, project, n, p, out);
306
+ return;
307
+ }
308
+ case "tag-required-class": {
309
+ const project = rest[0];
310
+ const tagRaw = rest[1];
311
+ const clear = bool(p.flags, "clear");
312
+ const clsRaw = str(p.flags, "class");
313
+ const reason = str(p.flags, "reason")?.trim();
314
+ if (!project || !tagRaw || (clear && clsRaw) || (!clear && !clsRaw) || !reason) {
315
+ throw new CliError("usage", 'routing tag-required-class <project> <tag> (--class p/h/m/e | --clear) --reason "why"');
316
+ }
317
+ const tag = normalizeTag(tagRaw);
318
+ const spec = clear ? null : parseClassSpec(clsRaw);
319
+ const cur = await c.call("GET", `/projects/${project}/process`);
320
+ const vocab = Array.isArray(cur.vocabulary) ? cur.vocabulary : [];
321
+ if (!vocab.some((v) => v.name === tag)) {
322
+ throw new CliError("not_found", `tag #${tag} is not in ${project}'s vocabulary`);
323
+ }
324
+ const nextVocab = vocab.map((v) => {
325
+ if (v.name !== tag)
326
+ return v;
327
+ if (clear)
328
+ return { ...v, required_class: null, required_class_clear_reason: reason };
329
+ return { ...v, required_class: { ...spec, reason } };
330
+ });
331
+ const r = await c.call("PUT", `/projects/${project}/process`, { vocabulary: nextVocab, reason });
332
+ out.print(clear
333
+ ? `${project} #${tag}: required_class cleared (process v${r.process?.version ?? "?"}, reason: ${reason}).`
334
+ : `${project} #${tag}: required_class set to ${formatClassSpec(spec)} (process v${r.process?.version ?? "?"}, reason: ${reason}).`, r);
335
+ return;
336
+ }
337
+ case "tier-migration": {
338
+ const project = rest[0];
339
+ if (!project)
340
+ throw new CliError("usage", "routing tier-migration <project>");
341
+ const r = await c.call("GET", `/projects/${project}/routing/tier-migration`);
342
+ const rows = Array.isArray(r.units) ? r.units : [];
343
+ out.print(rows.length
344
+ ? [
345
+ `${project} tier-migration backlog (${rows.length} legacy min_tier unit(s) needing explicit operator review; set or clear via b9s-admin routing required-class):`,
346
+ ...rows.map((u) => ` WU #${u.number} [${u.status}] legacy min_tier=${u.legacy_min_tier ?? "?"} · ${u.title ?? ""}`),
347
+ ].join("\n")
348
+ : `${project}: no legacy min_tier units awaiting required_class review.`, r);
349
+ return;
350
+ }
351
+ case "pool-suggestions": {
352
+ await poolSuggestionsAdmin("suggestions", rest, p, out);
353
+ return;
354
+ }
355
+ default:
356
+ throw new CliError("usage", "routing show <project> [--mode build|review] [--tag t] | policy <project> ... | explain <project> <unit> | required-class <project> <unit> ... | tag-required-class <project> <tag> ... | tier-migration <project> | pool-suggestions <project>");
357
+ }
358
+ }
359
+ /** Handles `b9s-admin pool suggestions` and `b9s-admin pool suggestion accept|reject`. */
360
+ export async function poolSuggestionsAdmin(action, rest, p, out) {
361
+ const c = adminClient(p);
362
+ if (action === "suggestions") {
363
+ const project = rest[0];
364
+ if (!project)
365
+ throw new CliError("usage", "pool suggestions <project> [--status pending|accepted|rejected|superseded|all]");
366
+ const statusFilter = str(p.flags, "status") ?? "pending";
367
+ const r = await c.call("GET", `/projects/${project}/pools/suggestions`);
368
+ const all = Array.isArray(r.suggestions) ? r.suggestions : [];
369
+ const shown = statusFilter === "all" ? all : all.filter((s) => s.status === statusFilter);
370
+ out.print(shown.length
371
+ ? [
372
+ ...shown.map(formatPoolSuggestion),
373
+ shown.some((s) => s.status === "pending")
374
+ ? `\nAct with: b9s-admin pool suggestion accept ${project} <id> [--note "..."] | reject ${project} <id> [--reason "..."]`
375
+ : "",
376
+ ].filter(Boolean).join("\n\n")
377
+ : `No ${statusFilter} pool-weight suggestions for ${project}.`, r);
378
+ return;
379
+ }
380
+ const sub = rest[0];
381
+ const project = rest[1];
382
+ const id = rest[2];
383
+ if (action === "suggestion" && (sub === "accept" || sub === "reject") && project && id) {
384
+ if (sub === "accept") {
385
+ const note = str(p.flags, "note");
386
+ const r = await c.call("POST", `/projects/${project}/pools/suggestions/${id}/accept`, note !== undefined ? { note } : {});
387
+ out.print(`Accepted pool suggestion ${id}: ${r.suggestion?.pool_name ?? "pool"} variant ${r.suggestion?.variant_tag ?? ""} weight -> ${r.suggestion?.suggested_weight ?? "?"}.\n${formatPoolSuggestion(r.suggestion)}`, r);
388
+ return;
389
+ }
390
+ const reason = str(p.flags, "reason") ?? str(p.flags, "note");
391
+ const r = await c.call("POST", `/projects/${project}/pools/suggestions/${id}/reject`, reason !== undefined ? { note: reason } : {});
392
+ out.print(`Rejected pool suggestion ${id}.\n${formatPoolSuggestion(r.suggestion)}`, r);
393
+ return;
394
+ }
395
+ throw new CliError("usage", 'pool suggestions <project> [--status ...] | pool suggestion accept <project> <id> [--note "..."] | pool suggestion reject <project> <id> [--reason "..."]');
396
+ }
@@ -0,0 +1,21 @@
1
+ import { str } from "../args.js";
2
+ import { resolveAgentName } from "../config.js";
3
+ import { readState, writeState } from "../state.js";
4
+ import { CliError } from "../errors.js";
5
+ /** Explicit, local turn-end note; the watcher sends it only as a bounded unverified excerpt. */
6
+ export async function turn(p, out) {
7
+ const name = resolveAgentName(str(p.flags, "as"));
8
+ const sub = p.positionals[1];
9
+ if (sub !== "note")
10
+ throw new CliError("usage", 'turn note "short progress summary"');
11
+ const state = readState(name);
12
+ const attempt = state.turn_guard?.turns.slice().reverse().find((item) => item.productive === null);
13
+ if (!attempt?.telemetry_enabled || !attempt.turn_id || !process.env.BSCHAT_MACHINE_SESSION_ID) {
14
+ throw new CliError("turn_telemetry_disabled", "turn notes are available only for a machine-managed session with account turn policy enabled");
15
+ }
16
+ const note = p.positionals.slice(2).join(" ").trim();
17
+ if (!note || [...note].length > 300)
18
+ throw new CliError("usage", "turn note needs 1 to 300 characters");
19
+ writeState(name, { ...state, turn_note: note });
20
+ out.print("saved a turn-end note; it will be shown as unverified context in the account-scoped judgment packet", { saved: true });
21
+ }