benignswarm 0.12.145 → 0.12.147
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/args.js +8 -4
- package/dist/build-caches.js +2 -1
- package/dist/claude-egress-proxy.js +1312 -0
- package/dist/command-flags.js +1 -1
- package/dist/commands/admin.js +3 -1
- package/dist/commands/agent.js +16 -3
- package/dist/commands/codex-start.js +133 -19
- package/dist/commands/evidence.js +5 -1
- package/dist/commands/hook.js +43 -4
- package/dist/commands/lock-run-supervisor.js +113 -0
- package/dist/commands/lock-run.js +180 -13
- package/dist/commands/machine-admin.js +3 -0
- package/dist/commands/machine.js +148 -17
- package/dist/commands/operator.js +90 -15
- package/dist/commands/ux.js +154 -0
- package/dist/commands/watch.js +170 -21
- package/dist/commands/worktrees.js +9 -2
- package/dist/commands/wu.js +52 -8
- package/dist/console-links.js +17 -0
- package/dist/harnesses.js +832 -10
- package/dist/help.js +22 -9
- package/dist/index.js +3 -0
- package/dist/machine-report.js +239 -0
- package/dist/session-secrets.js +214 -0
- package/dist/ux-jobs.js +728 -0
- package/dist/version.js +1 -1
- package/package.json +1 -1
|
@@ -6,6 +6,7 @@ import { bool, need, str } from "../args.js";
|
|
|
6
6
|
import { Client } from "../client.js";
|
|
7
7
|
import { loadAdmin, resolveAdminName } from "../config.js";
|
|
8
8
|
import { CliError } from "../errors.js";
|
|
9
|
+
import { consoleLink } from "../console-links.js";
|
|
9
10
|
import { table } from "../output.js";
|
|
10
11
|
/**
|
|
11
12
|
* Operator commands that used to exist only in the console: the project process (definition,
|
|
@@ -69,6 +70,17 @@ export function definitionPatch(p, cur) {
|
|
|
69
70
|
const take = intFlag(str(p.flags, "takeover"), "takeover");
|
|
70
71
|
if (take !== undefined)
|
|
71
72
|
d.escalate_after_minutes = take;
|
|
73
|
+
const stall = str(p.flags, "stall");
|
|
74
|
+
if (stall !== undefined) {
|
|
75
|
+
if (stall === "default")
|
|
76
|
+
d.stall_minutes = null;
|
|
77
|
+
else {
|
|
78
|
+
const minutes = intFlag(stall, "stall");
|
|
79
|
+
if (minutes === undefined || minutes < 1 || minutes > 525600)
|
|
80
|
+
throw new CliError("usage", "--stall must be default or a whole number from 1 to 525600");
|
|
81
|
+
d.stall_minutes = minutes;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
72
84
|
const open = intFlag(str(p.flags, "max-open"), "max-open");
|
|
73
85
|
if (open !== undefined)
|
|
74
86
|
d.max_open_per_agent = open;
|
|
@@ -134,7 +146,7 @@ function describeProcess(r) {
|
|
|
134
146
|
const m = d.merge;
|
|
135
147
|
return [
|
|
136
148
|
`Process v${r.process.version}${r.process.version === 0 ? " (defaults; nothing published yet)" : ""}`,
|
|
137
|
-
` timing: review SLA ${d.review_sla_minutes} min, takeover ${d.escalate_after_minutes} min, ${d.max_open_per_agent} open / ${d.max_in_progress_per_agent} in progress per agent`,
|
|
149
|
+
` timing: review SLA ${d.review_sla_minutes} min, takeover ${d.escalate_after_minutes} min, stalled after ${d.stall_minutes == null ? `default (twice takeover: ${2 * d.escalate_after_minutes} min)` : `${d.stall_minutes} min`}, ${d.max_open_per_agent} open / ${d.max_in_progress_per_agent} in progress per agent`,
|
|
138
150
|
` requires: scope ${d.require_scope ? "yes" : "no"}, evidence to submit ${d.require_evidence_to_submit ? "yes" : "no"}; default approver ${d.default_approver_role ?? "none"}; assigners ${d.assigners.join(", ") || "none"}`,
|
|
139
151
|
` merging: into ${m.target_branch} by ${m.merged_by === "integrator" ? `a ${m.integrator_role}` : `the ${m.merged_by}`}; merge commit ${m.require_merge_commit ? "yes" : "no"}, rebased ${m.require_rebased ? "yes" : "no"}, pushed ${m.require_pushed ? "yes" : "no"}; gate ${m.gate_command ?? "none"}; gate receipt required ${m.require_gate_receipt ? "yes" : "no"}`,
|
|
140
152
|
` capabilities: ${(d.capabilities ?? []).map((c) => `${c.name} (${c.scope}${c.min_version ? ` >= ${c.min_version}` : ""})`).join(", ") || "none"}`,
|
|
@@ -210,7 +222,7 @@ export async function processAdmin(action, rest, p, out) {
|
|
|
210
222
|
const definition = definitionPatch(p, r.process.definition);
|
|
211
223
|
if (!Object.keys(definition).length)
|
|
212
224
|
throw new CliError("usage", action === "timing"
|
|
213
|
-
? "admin process timing <project> [--sla m] [--takeover m] [--max-open n] [--max-in-progress n] [--require-scope yes|no] [--require-evidence yes|no] [--default-approver role|none]"
|
|
225
|
+
? "admin process timing <project> [--sla m] [--takeover m] [--stall <minutes|default>] [--max-open n] [--max-in-progress n] [--require-scope yes|no] [--require-evidence yes|no] [--default-approver role|none]"
|
|
214
226
|
: "admin process merge <project> [--target branch] [--merged-by owner|approver|integrator] [--integrator-role r] [--gate-command <cmd|none>] [--require-gate-receipt yes|no] [--require-rebased yes|no] [--require-merge-commit yes|no] [--require-pushed yes|no]");
|
|
215
227
|
return publish({ definition }, Object.keys(definition).join(", "));
|
|
216
228
|
}
|
|
@@ -315,7 +327,8 @@ export async function needsAdmin(p, out) {
|
|
|
315
327
|
return out.print("Nothing is waiting on you.", r);
|
|
316
328
|
const ind = (t) => t.replace(/\n/g, "\n ");
|
|
317
329
|
out.print(r.needs.map((n, i) => [
|
|
318
|
-
`${i + 1}. [${n.project}] ${n.kind === "unit_question" ? `WU #${n.unit} question` : n.kind === "wake_broken" ? "wake path" : n.kind === "notifier" ? "your alerts" : n.kind === "machine_session" ? "machine" : "decision"} · ${n.asked_by} · since ${n.since.slice(0, 16).replace("T", " ")} UTC`,
|
|
330
|
+
`${i + 1}. [${n.project || "Account"}] ${n.display_id ?? (n.kind === "unit_question" ? `WU #${n.unit} question` : "decision id unavailable")} · ${n.kind === "unit_question" ? "unit question" : n.kind === "wake_broken" || n.kind === "wake_unresponsive" ? "wake path" : n.kind === "notifier" ? "your alerts" : n.kind === "machine_report_refused" ? "machine report refused" : n.kind === "machine_session" ? "machine" : n.kind === "lock_silent" ? "silent lock job" : "decision"} · ${n.asked_by} · since ${n.since.slice(0, 16).replace("T", " ")} UTC`,
|
|
331
|
+
` Console: ${consoleLink("decision", n.project, n.key)}`,
|
|
319
332
|
n.plain ? ` In plain words: ${ind(n.plain)}` : n.unexplained ? ` In plain words: (${n.asked_by} did not explain this; b9s-admin explain ${n.key})` : null,
|
|
320
333
|
n.blocks ? ` What's stuck: ${ind(n.blocks)}` : null,
|
|
321
334
|
` ${n.kind === "ask" ? "What I need from you: " : ""}${ind(n.text)}`,
|
|
@@ -324,21 +337,28 @@ export async function needsAdmin(p, out) {
|
|
|
324
337
|
n.proposal ? ` Proposed by ${n.proposed_by}: ${ind(n.proposal)}` : null,
|
|
325
338
|
n.explanation ? ` Explained by ${n.explained_by}: ${ind(n.explanation)}` : n.explain_requested_at ? ` (explanation asked for ${n.explain_requested_at.slice(0, 16).replace("T", " ")} UTC)` : null,
|
|
326
339
|
` key: ${n.key}`,
|
|
327
|
-
].filter(Boolean).join("\n")).join("\n\n") + `\n\nAnswer with: b9s-admin answer <key> "decision", or b9s-admin answer <key> --approve [--note ".."] to accept a proposal; b9s-admin explain <key> asks the agent to explain it in plain words`, r);
|
|
340
|
+
].filter(Boolean).join("\n")).join("\n\n") + `\n\nAnswer with: b9s-admin answer <id or key> "decision", or b9s-admin answer <id or key> --approve [--note ".."] to accept a proposal; b9s-admin explain <id or key> asks the agent to explain it in plain words`, r);
|
|
341
|
+
}
|
|
342
|
+
function resolveNeedReference(needs, reference) {
|
|
343
|
+
const normalized = reference.trim().toLowerCase();
|
|
344
|
+
return needs.find((need) => need.key === reference || need.display_id?.toLowerCase() === normalized ||
|
|
345
|
+
(need.kind === "ask" && need.ask_seq != null && `decision #${need.ask_seq}` === normalized) ||
|
|
346
|
+
(need.kind === "unit_question" && `wu #${need.unit} question` === normalized));
|
|
328
347
|
}
|
|
329
348
|
/** b9s-admin explain <key>: the console's Explain; the agent is mentioned and asked to put it in plain words. */
|
|
330
349
|
export async function explainAdmin(rest, p, out) {
|
|
331
350
|
const key = rest[0];
|
|
332
351
|
if (!key)
|
|
333
|
-
throw new CliError("usage", "admin explain <key from admin needs>");
|
|
352
|
+
throw new CliError("usage", "admin explain <id or key from admin needs>");
|
|
334
353
|
const c = adminClient(p);
|
|
335
|
-
const n = (await c.call("GET", "/account/needs")).needs
|
|
354
|
+
const n = resolveNeedReference((await c.call("GET", "/account/needs")).needs, key);
|
|
336
355
|
if (!n)
|
|
337
356
|
throw new CliError("not_found", `nothing waiting with key ${key}; list them with: b9s-admin needs`);
|
|
357
|
+
const itemLink = consoleLink("decision", n.project, n.key);
|
|
338
358
|
if (n.kind === "ask")
|
|
339
|
-
return out.print(`Asked ${n.asked_by} to explain; it appears with the decision (b9s-admin needs) and in the next report to you
|
|
359
|
+
return out.print(`Asked ${n.asked_by} to explain; it appears with the decision (b9s-admin needs) and in the next report to you.\nConsole: ${itemLink}`, await c.call("POST", `/projects/${n.project}/asks/${n.ask_id}/explain`, {}));
|
|
340
360
|
if (n.kind === "unit_question")
|
|
341
|
-
return out.print(`Asked for WU #${n.unit}'s question in plain words; it appears with the question (b9s-admin needs)
|
|
361
|
+
return out.print(`Asked for WU #${n.unit}'s question in plain words; it appears with the question (b9s-admin needs).\nConsole: ${itemLink}`, await c.call("POST", `/projects/${n.project}/work-units/${n.unit}/question/explain`, {}));
|
|
342
362
|
throw new CliError("not_answerable", "only decisions (asks and unit questions) can be explained");
|
|
343
363
|
}
|
|
344
364
|
export async function answerAdmin(rest, p, out) {
|
|
@@ -351,17 +371,20 @@ export async function answerAdmin(rest, p, out) {
|
|
|
351
371
|
if (assign && !approve)
|
|
352
372
|
throw new CliError("usage", "--assign is only valid with --approve");
|
|
353
373
|
const c = adminClient(p);
|
|
354
|
-
const n = (await c.call("GET", "/account/needs")).needs
|
|
374
|
+
const n = resolveNeedReference((await c.call("GET", "/account/needs")).needs, key);
|
|
355
375
|
if (!n)
|
|
356
376
|
throw new CliError("not_found", `nothing waiting with key ${key}; list them with: b9s-admin needs`);
|
|
357
377
|
if (assign && n.kind !== "ask")
|
|
358
378
|
throw new CliError("usage", "--assign names the owner of an approved ask action; this need is not an ask");
|
|
359
379
|
if (approve && n.kind !== "ask" && n.kind !== "unit_question")
|
|
360
380
|
throw new CliError("usage", "--approve accepts a proposal on an ask or a unit question; this one has none");
|
|
381
|
+
const itemLink = n.kind === "unit_question" && n.unit
|
|
382
|
+
? consoleLink("work", n.project, n.unit)
|
|
383
|
+
: consoleLink("decision", n.project, n.key);
|
|
361
384
|
if (n.kind === "ask")
|
|
362
|
-
return out.print(approve ? `Approved the proposal${assign ? ` and assigned the action to ${assign}` : ""}; the asker was told.` : "Answered; the asker was told."
|
|
385
|
+
return out.print(`${approve ? `Approved the proposal${assign ? ` and assigned the action to ${assign}` : ""}; the asker was told.` : "Answered; the asker was told."}\nConsole: ${itemLink}`, await c.call("POST", `/projects/${n.project}/asks/${n.ask_id}/answer`, approve ? { approve: true, answer, ...(assign ? { assign } : {}) } : { answer }));
|
|
363
386
|
if (n.kind === "unit_question")
|
|
364
|
-
return out.print(`Ruled on WU #${n.unit}${approve ? " (proposal approved)" : ""}; the asker, owner and reviewers were told
|
|
387
|
+
return out.print(`Ruled on WU #${n.unit}${approve ? " (proposal approved)" : ""}; the asker, owner and reviewers were told.\nConsole: ${itemLink}`, await c.call("POST", `/projects/${n.project}/work-units/${n.unit}/rule`, approve ? { approve: true, ruling: answer } : { ruling: answer }));
|
|
365
388
|
throw new CliError("not_answerable", n.kind === "wake_broken" ? `a broken wake path clears when ${n.agent} shows activity: fix its watcher or harness session` : "a notifier problem clears on the next report that reaches you: fix it with b9s-admin notifier");
|
|
366
389
|
}
|
|
367
390
|
export async function notifierAdmin(p, out) {
|
|
@@ -417,15 +440,67 @@ export async function accountAdmin(p, out, action, rest = []) {
|
|
|
417
440
|
throw new CliError("usage", "b9s-admin account secrets-kms [status | enable --region <aws-region> [--kms-key <arn-or-id>]]");
|
|
418
441
|
}
|
|
419
442
|
if (action)
|
|
420
|
-
throw new CliError("usage", "b9s-admin account [--summary-minutes <n>] | secrets-kms [status | enable --region <r> [--kms-key <id>]]");
|
|
443
|
+
throw new CliError("usage", "b9s-admin account [--summary-minutes <n>] [--quota-share-threshold <fraction|default>] | secrets-kms [status | enable --region <r> [--kms-key <id>]]");
|
|
421
444
|
const m = intFlag(str(p.flags, "summary-minutes"), "summary-minutes");
|
|
422
|
-
|
|
423
|
-
|
|
445
|
+
const thresholdText = str(p.flags, "quota-share-threshold");
|
|
446
|
+
const threshold = thresholdText === undefined ? undefined : thresholdText === "default" ? null : Number(thresholdText);
|
|
447
|
+
if (threshold !== undefined && threshold !== null && (!Number.isFinite(threshold) || threshold <= 0 || threshold > 1))
|
|
448
|
+
throw new CliError("usage", "--quota-share-threshold must be a fraction greater than 0 and at most 1, or 'default'");
|
|
449
|
+
const changes = { ...(m !== undefined ? { summary_minutes: m } : {}), ...(thresholdText !== undefined ? { quota_pool_share_threshold: threshold } : {}) };
|
|
450
|
+
if (Object.keys(changes).length)
|
|
451
|
+
await c.call("PATCH", "/account", changes);
|
|
424
452
|
const r = await c.call("GET", "/account");
|
|
425
453
|
const u = await c.call("GET", "/account/usage");
|
|
426
454
|
const a = r.account ?? r;
|
|
427
455
|
const usage = u.usage ?? u;
|
|
428
|
-
|
|
456
|
+
const quotaShareThreshold = a.quota_pool_share_threshold ?? 0.5;
|
|
457
|
+
out.print(`${a.name} · plan ${a.plan} · account summary every ${a.summary_minutes ?? 60} min · quota pool share threshold ${Math.round(quotaShareThreshold * 100)}%${a.quota_pool_share_threshold == null ? " (default)" : " (account)"}\nusage: ${JSON.stringify(usage)}\nlegacy bschat CLI requests: ${usage.legacy_cli_invocations ?? 0}`, { account: a, usage: u });
|
|
458
|
+
}
|
|
459
|
+
export async function quotaPoolsAdmin(p, out) {
|
|
460
|
+
const unsupported = Object.keys(p.flags).filter((name) => !["admin", "json", "help", "version"].includes(name));
|
|
461
|
+
if (unsupported.length)
|
|
462
|
+
throw new CliError("usage", `unsupported quota-pools option --${unsupported[0]}`);
|
|
463
|
+
const result = await adminClient(p).call("GET", "/account/quota-pools");
|
|
464
|
+
const lines = [`Harness quota pools · generated ${result.generated_at}`, `Concentration threshold ${Math.round(result.thresholds.per_account_running_session_share * 100)}%; recurring limit window ${result.thresholds.recurrence_window_days} days (${result.thresholds.recurring_limit_events}+ events).`];
|
|
465
|
+
const running = result.running_sessions;
|
|
466
|
+
lines.push(`Running sessions: ${running.count ?? `unknown (${running.observed_count} observed; ${running.unknown_count} unknown${running.reason ? `: ${running.reason}` : ""})`}`);
|
|
467
|
+
if (!result.pools.length)
|
|
468
|
+
lines.push("No identified harness account pools.");
|
|
469
|
+
for (const pool of result.pools) {
|
|
470
|
+
const label = `${pool.harness}${pool.provider ? `/${pool.provider}` : ""} ${pool.account_fingerprint}`;
|
|
471
|
+
const share = pool.share_of_running_sessions.state === "known" ? `${(pool.share_of_running_sessions.value * 100).toFixed(1)}%` : `unknown (${pool.share_of_running_sessions.reason})`;
|
|
472
|
+
lines.push(`${label}: ${pool.running_sessions} running; share ${share}; reset ${pool.latest_reset_at ?? "unknown"}`);
|
|
473
|
+
for (const group of pool.sessions_by_machine)
|
|
474
|
+
lines.push(` machine ${group.machine}: ${group.count}`);
|
|
475
|
+
for (const group of pool.sessions_by_project)
|
|
476
|
+
lines.push(` project ${group.project}: ${group.count}`);
|
|
477
|
+
if (!pool.usage_limit_events.length)
|
|
478
|
+
lines.push(" no usage-limit events in the last seven days");
|
|
479
|
+
for (const event of pool.usage_limit_events)
|
|
480
|
+
lines.push(` limit ${event.occurred_at}; reset ${event.reset_at ?? "unknown"}; ${event.source}`);
|
|
481
|
+
for (const fault of pool.faults)
|
|
482
|
+
lines.push(` FAULT ${fault.kind}: ${fault.reason}`);
|
|
483
|
+
}
|
|
484
|
+
if (result.unattributed_sessions.length) {
|
|
485
|
+
lines.push("Unknown/unattributed sessions:");
|
|
486
|
+
for (const session of result.unattributed_sessions)
|
|
487
|
+
lines.push(` ${session.project ?? "account-wide"}/${session.agent} on ${session.machine} (${session.session_id}): ${session.reason}`);
|
|
488
|
+
}
|
|
489
|
+
if (result.unattributed_quota_events.length) {
|
|
490
|
+
lines.push("Usage-limit events with unknown facts:");
|
|
491
|
+
for (const event of result.unattributed_quota_events) {
|
|
492
|
+
const occurred = event.occurred_at.state === "known" ? event.occurred_at.value : `unknown (${event.occurred_at.reason})`;
|
|
493
|
+
const identity = event.account_fingerprint.state === "known" ? event.account_fingerprint.value : `unknown (${event.account_fingerprint.reason})`;
|
|
494
|
+
const reset = event.reset_at.state === "known" ? event.reset_at.value : `unknown (${event.reset_at.reason})`;
|
|
495
|
+
lines.push(` ${event.project ?? "account-wide"}/${event.agent} on ${event.machine} (${event.session_id}): account ${identity}; occurred ${occurred}; reset ${reset}`);
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
if (result.identity_conflicts.length) {
|
|
499
|
+
lines.push("Session/machine identity conflicts (session fingerprint is authoritative):");
|
|
500
|
+
for (const conflict of result.identity_conflicts)
|
|
501
|
+
lines.push(` ${conflict.project ?? "account-wide"}/${conflict.agent} on ${conflict.machine} (${conflict.session_id}): session ${conflict.session_fingerprint}; machine ${conflict.machine_fingerprint}`);
|
|
502
|
+
}
|
|
503
|
+
out.print(lines.join("\n"), result);
|
|
429
504
|
}
|
|
430
505
|
export async function textCheckAdmin(project, p, out) {
|
|
431
506
|
if (!project)
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import { bool, str } from "../args.js";
|
|
2
|
+
import { Client } from "../client.js";
|
|
3
|
+
import { loadAgent, resolveAgentName, resolveModel } from "../config.js";
|
|
4
|
+
import { CliError } from "../errors.js";
|
|
5
|
+
import { collectAuto } from "../git.js";
|
|
6
|
+
import { table } from "../output.js";
|
|
7
|
+
import { projectOf } from "./agent.js";
|
|
8
|
+
function formatJob(job) {
|
|
9
|
+
const isGate = job.job_kind === "gate";
|
|
10
|
+
const what = isGate
|
|
11
|
+
? "complete-suite gate (scripts/gate.sh)"
|
|
12
|
+
: [job.task ? `ux:task ${job.task}` : null, job.compare_screen ? `ux:compare ${job.compare_screen}` : null].filter(Boolean).join(" + ");
|
|
13
|
+
const headText = job.resolved_head ? job.resolved_head.slice(0, 9) : job.head ? job.head.slice(0, 9) : "branch tip";
|
|
14
|
+
const evidenceLine = Array.isArray(job.evidence_ids) && job.evidence_ids.length
|
|
15
|
+
? `\nEvidence: ${job.evidence_ids.map((id) => `evidence:${id}`).join(" ")}`
|
|
16
|
+
: "";
|
|
17
|
+
const errorLine = job.error ? `\nError: ${job.error}` : "";
|
|
18
|
+
const kindLabel = isGate ? "Gate" : "UX";
|
|
19
|
+
return `${kindLabel} job ${job.id} [${job.status}] on ${job.machine} for WU #${job.work_unit_number}\nTask: ${what}\nBranch: ${job.branch} @ ${headText}${evidenceLine}${errorLine}`;
|
|
20
|
+
}
|
|
21
|
+
export async function ux(p, out) {
|
|
22
|
+
const sub = p.positionals[1];
|
|
23
|
+
const name = resolveAgentName(str(p.flags, "as"));
|
|
24
|
+
const creds = loadAgent(name);
|
|
25
|
+
const client = Client.forAgent(creds, resolveModel(str(p.flags, "model"), process.env, process.cwd(), name));
|
|
26
|
+
const project = projectOf(p, creds);
|
|
27
|
+
if (sub === "run") {
|
|
28
|
+
const task = p.positionals[2]?.trim() || undefined;
|
|
29
|
+
const compare = str(p.flags, "compare")?.trim() || undefined;
|
|
30
|
+
const unitText = str(p.flags, "unit");
|
|
31
|
+
const machine = str(p.flags, "on")?.trim() || undefined;
|
|
32
|
+
const explicitHead = str(p.flags, "head")?.trim() || undefined;
|
|
33
|
+
if (!task && !compare) {
|
|
34
|
+
throw new CliError("usage", "b9s ux run [<task>] [--compare <screen>] --unit <n> [--on <machine>] [--head <sha>]");
|
|
35
|
+
}
|
|
36
|
+
const unitNumber = unitText ? Number(unitText) : NaN;
|
|
37
|
+
if (!Number.isSafeInteger(unitNumber) || unitNumber < 1) {
|
|
38
|
+
throw new CliError("usage", "--unit <n> must be a positive work unit number");
|
|
39
|
+
}
|
|
40
|
+
let head = explicitHead;
|
|
41
|
+
if (!head) {
|
|
42
|
+
const unitRes = await client.call("GET", `/projects/${project}/work-units/${unitNumber}`);
|
|
43
|
+
const unit = unitRes?.unit;
|
|
44
|
+
const where = collectAuto({ model: undefined, machine: creds.machine });
|
|
45
|
+
if (unit?.branch && where.branch === unit.branch && where.head) {
|
|
46
|
+
if (where.dirty === true) {
|
|
47
|
+
throw new CliError("dirty_worktree", `worktree on ${where.branch} has uncommitted changes; commit and push before queuing a remote UX job`);
|
|
48
|
+
}
|
|
49
|
+
if (unit.status !== "in_review" && unit.status !== "approved") {
|
|
50
|
+
head = where.head;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
const res = await client.call("POST", `/projects/${project}/ux-jobs`, {
|
|
55
|
+
unit: unitNumber,
|
|
56
|
+
...(task ? { task } : {}),
|
|
57
|
+
...(compare ? { compare } : {}),
|
|
58
|
+
...(machine ? { machine } : {}),
|
|
59
|
+
...(head ? { head } : {}),
|
|
60
|
+
});
|
|
61
|
+
const job = res.job;
|
|
62
|
+
out.print(`${formatJob(job)}\nQueued for daemon reconcile. Check status: b9s ux job ${job.id}`, bool(p.flags, "json") ? res : res);
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
if (sub === "job") {
|
|
66
|
+
const id = p.positionals[2]?.trim();
|
|
67
|
+
if (!id)
|
|
68
|
+
throw new CliError("usage", "b9s ux job <id>");
|
|
69
|
+
const res = await client.call("GET", `/projects/${project}/ux-jobs/${encodeURIComponent(id)}`);
|
|
70
|
+
out.print(formatJob(res.job), res);
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
if (sub === "jobs") {
|
|
74
|
+
const qs = new URLSearchParams();
|
|
75
|
+
const unit = str(p.flags, "unit");
|
|
76
|
+
const limit = str(p.flags, "limit");
|
|
77
|
+
if (unit !== undefined)
|
|
78
|
+
qs.set("unit", unit);
|
|
79
|
+
if (limit !== undefined)
|
|
80
|
+
qs.set("limit", limit);
|
|
81
|
+
const suffix = qs.toString() ? `?${qs}` : "";
|
|
82
|
+
const res = await client.call("GET", `/projects/${project}/ux-jobs${suffix}`);
|
|
83
|
+
const rows = res.jobs.map((job) => ({
|
|
84
|
+
id: job.id,
|
|
85
|
+
kind: job.job_kind ?? "ux",
|
|
86
|
+
status: job.status,
|
|
87
|
+
unit: `#${job.work_unit_number}`,
|
|
88
|
+
machine: job.machine,
|
|
89
|
+
task: job.job_kind === "gate" ? "gate.sh" : (job.task ?? job.compare_screen ?? "-"),
|
|
90
|
+
head: (job.resolved_head ?? job.head ?? "-").slice(0, 9),
|
|
91
|
+
evidence: Array.isArray(job.evidence_ids) ? job.evidence_ids.length : 0,
|
|
92
|
+
}));
|
|
93
|
+
out.print(table(rows, ["id", "kind", "status", "unit", "machine", "task", "head", "evidence"]), res);
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
throw new CliError("usage", "b9s ux <run|job|jobs>");
|
|
97
|
+
}
|
|
98
|
+
export async function gate(p, out) {
|
|
99
|
+
const sub = p.positionals[1];
|
|
100
|
+
const name = resolveAgentName(str(p.flags, "as"));
|
|
101
|
+
const creds = loadAgent(name);
|
|
102
|
+
const client = Client.forAgent(creds, resolveModel(str(p.flags, "model"), process.env, process.cwd(), name));
|
|
103
|
+
const project = projectOf(p, creds);
|
|
104
|
+
if (sub === "run") {
|
|
105
|
+
const unitText = p.positionals[2]?.trim();
|
|
106
|
+
const unitNumber = unitText ? Number(unitText) : NaN;
|
|
107
|
+
if (!Number.isSafeInteger(unitNumber) || unitNumber < 1) {
|
|
108
|
+
throw new CliError("usage", "b9s gate run <n> [--merge-candidate <sha>] --on <machine>");
|
|
109
|
+
}
|
|
110
|
+
const machine = str(p.flags, "on")?.trim();
|
|
111
|
+
if (!machine) {
|
|
112
|
+
throw new CliError("usage", "b9s gate run <n> [--merge-candidate <sha>] --on <machine> (--on is required)");
|
|
113
|
+
}
|
|
114
|
+
const candidate = str(p.flags, "merge-candidate")?.trim() || undefined;
|
|
115
|
+
const res = await client.call("POST", `/projects/${project}/gate-jobs`, {
|
|
116
|
+
unit: unitNumber,
|
|
117
|
+
machine,
|
|
118
|
+
...(candidate ? { merge_candidate: candidate } : {}),
|
|
119
|
+
});
|
|
120
|
+
const job = res.job;
|
|
121
|
+
out.print(`${formatJob(job)}\nQueued for daemon reconcile. Check status: b9s gate job ${job.id}`, res);
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
if (sub === "job") {
|
|
125
|
+
const id = p.positionals[2]?.trim();
|
|
126
|
+
if (!id)
|
|
127
|
+
throw new CliError("usage", "b9s gate job <id>");
|
|
128
|
+
const res = await client.call("GET", `/projects/${project}/gate-jobs/${encodeURIComponent(id)}`);
|
|
129
|
+
out.print(formatJob(res.job), res);
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
if (sub === "jobs") {
|
|
133
|
+
const qs = new URLSearchParams();
|
|
134
|
+
const unit = str(p.flags, "unit");
|
|
135
|
+
const limit = str(p.flags, "limit");
|
|
136
|
+
if (unit !== undefined)
|
|
137
|
+
qs.set("unit", unit);
|
|
138
|
+
if (limit !== undefined)
|
|
139
|
+
qs.set("limit", limit);
|
|
140
|
+
const suffix = qs.toString() ? `?${qs}` : "";
|
|
141
|
+
const res = await client.call("GET", `/projects/${project}/gate-jobs${suffix}`);
|
|
142
|
+
const rows = res.jobs.map((job) => ({
|
|
143
|
+
id: job.id,
|
|
144
|
+
status: job.status,
|
|
145
|
+
unit: `#${job.work_unit_number}`,
|
|
146
|
+
machine: job.machine,
|
|
147
|
+
head: (job.resolved_head ?? job.head ?? "-").slice(0, 9),
|
|
148
|
+
evidence: Array.isArray(job.evidence_ids) ? job.evidence_ids.length : 0,
|
|
149
|
+
}));
|
|
150
|
+
out.print(table(rows, ["id", "status", "unit", "machine", "head", "evidence"]), res);
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
throw new CliError("usage", "b9s gate <run|job|jobs>");
|
|
154
|
+
}
|