benignswarm 0.12.95 → 0.12.97
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 +0 -0
- package/dist/args.js +39 -3
- package/dist/brief.js +5 -1
- package/dist/client.js +207 -1
- package/dist/commands/admin.js +84 -22
- package/dist/commands/agent.js +15 -2
- package/dist/commands/cloud-admin.js +56 -3
- package/dist/commands/codex-start.js +333 -239
- package/dist/commands/environment-admin.js +130 -0
- package/dist/commands/environment.js +53 -0
- package/dist/commands/evidence.js +6 -3
- package/dist/commands/feedback.js +12 -1
- package/dist/commands/flow.js +153 -0
- package/dist/commands/hook.js +29 -9
- package/dist/commands/image-admin.js +77 -0
- package/dist/commands/install.js +81 -3
- package/dist/commands/lists.js +4 -0
- package/dist/commands/machine-admin.js +444 -111
- package/dist/commands/machine-resize.js +234 -0
- package/dist/commands/machine.js +957 -39
- package/dist/commands/operator.js +5 -8
- package/dist/commands/retire.js +4 -0
- package/dist/commands/templates.js +27 -0
- package/dist/commands/watch.js +43 -10
- package/dist/commands/wu.js +131 -81
- package/dist/container.js +480 -0
- package/dist/environment-checks.js +79 -0
- package/dist/git.js +29 -1
- package/dist/help.js +88 -34
- package/dist/index.js +5 -1
- package/dist/install.js +43 -1
- package/dist/macos-readiness.js +173 -0
- package/dist/output.js +15 -4
- package/dist/templates.js +218 -0
- package/dist/test-workers.js +17 -0
- package/dist/turn.js +6 -0
- package/dist/usage.js +117 -0
- package/dist/version.js +1 -1
- package/package.json +1 -1
package/dist/admin-index.js
CHANGED
|
File without changes
|
package/dist/args.js
CHANGED
|
@@ -2,9 +2,45 @@ import { parseArgs } from "node:util";
|
|
|
2
2
|
import { CliError } from "./errors.js";
|
|
3
3
|
// These options accept comma-separated collections, so repeating them should
|
|
4
4
|
// append another collection instead of discarding earlier values.
|
|
5
|
-
export const LIST_FLAGS = [
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
export const LIST_FLAGS = [
|
|
6
|
+
"tags", "projects", "evidence", "statuses", "depends-on", "default-tags", "units", "waits-on",
|
|
7
|
+
"writable-root", "needs", "exclude", "remove", "post", "harness", "variant", "requires",
|
|
8
|
+
"reworks", "confirm-causes", "processes", "cache", "caches", "root", "signing-key", "machines",
|
|
9
|
+
];
|
|
10
|
+
export const STRING_FLAGS = [
|
|
11
|
+
"as", "admin", "key", "url", "label", "model", "since", "limit", "after", "topic", "goal", "task",
|
|
12
|
+
"state", "blocked-on", "tags", "custom", "vendor", "role", "description", "permissions",
|
|
13
|
+
"cardinality", "assign-outside-qualifications", "machine", "idempotency-key", "dir", "confirm", "impact-revision", "type",
|
|
14
|
+
"name", "out", "token", "token-file", "prefix", "uses", "expires-hours", "skill-dir", "harness", "provider", "reply-to",
|
|
15
|
+
"event", "project", "projects", "post", "title", "body", "body-file", "handoff-to", "evidence", "agent",
|
|
16
|
+
"parent", "parent-item", "channel", "statuses", "assign", "if-status", "status", "exec", "interval",
|
|
17
|
+
"requeue-after", "unacked-after", "category", "command", "command-pattern", "follow-delay", "env", "scope",
|
|
18
|
+
"scope-file", "scope-from", "append", "pr", "note", "note-file", "add", "remove", "merged", "tag",
|
|
19
|
+
"activity", "max-unanswered", "to", "replay-of", "branch", "effort", "max-budget-usd", "by", "target", "lands-with",
|
|
20
|
+
"milestone", "file", "exit", "depends-on", "default-tags", "source", "on", "partial", "question", "ruling",
|
|
21
|
+
"gaps", "unit", "units", "blocks", "sla", "takeover", "max-open", "max-in-progress", "require-scope",
|
|
22
|
+
"require-evidence", "default-approver", "merged-by", "integrator-role", "require-rebased", "require-merge-commit",
|
|
23
|
+
"require-pushed", "quiet", "summary", "meaning", "expert-role", "reviews", "works", "trials", "email",
|
|
24
|
+
"repeat", "summary-minutes", "churn", "unmet", "require-cited-changes", "checks-every", "propose", "waits-on",
|
|
25
|
+
"sandbox", "thread", "turn-timeout", "turns-per-hour", "unproductive-per-hour", "turn-coalesce-seconds", "session",
|
|
26
|
+
"plain", "if-yes", "if-no", "ssh", "variant", "count", "needs", "min-ram", "exclude", "carry", "from",
|
|
27
|
+
"to-ssh", "wait", "writable", "writable-root", "dsh", "agy", "for", "until", "reason", "at", "requires",
|
|
28
|
+
"priority", "informs", "amend", "waive-informs", "text", "kind", "claim", "decision", "sha", "value", "expect",
|
|
29
|
+
"expectations", "reworks", "cause", "lesson", "disputes", "annotation", "send-back-event", "confirm-causes", "floor",
|
|
30
|
+
"tool", "processes", "arch", "arn", "base-image", "b9s-version", "cache", "caches", "commit", "dockerfile",
|
|
31
|
+
"instance-id", "machine-id", "machine-name", "node-sha256", "node-version", "path", "recipe-version", "region",
|
|
32
|
+
"root", "signing-key", "catalog", "context", "source-commit", "component", "normalized-key",
|
|
33
|
+
"drain-timeout", "on-running-turn", "extend", "ssh-config", "poll-ms",
|
|
34
|
+
"stage", "machines", "resolved-retention-days", "wont-fix-retention-days", "alert-cooldown-minutes", "alerts", "confirm-force",
|
|
35
|
+
];
|
|
36
|
+
export const BOOL_FLAGS = [
|
|
37
|
+
"latest", "no-restart", "json", "follow", "account", "help", "version", "broadcast", "create-channels",
|
|
38
|
+
"read-account-status", "replace-key", "mentions-me", "no-skill", "replace", "template", "scope-only", "unread",
|
|
39
|
+
"pending", "force", "no-hooks", "yes", "open", "bind-here", "peek", "once", "launchd", "full", "no-bind",
|
|
40
|
+
"all", "here", "keep-worktree", "prune", "abandon", "defer", "hold", "clear", "met", "shared", "archive",
|
|
41
|
+
"approve", "turn", "service", "print-hooks", "create", "rotate", "codex-userns", "bwrap-userns", "print-apparmor",
|
|
42
|
+
"cancel", "rerun", "confirmed", "refuted", "no-source", "confirm-bypass-signal", "in-container", "assessment-only", "retrieve-ec2", "no-wait-verify", "preview", "remove-empty", "dry-run",
|
|
43
|
+
];
|
|
8
44
|
export function parse(argv) {
|
|
9
45
|
const options = {};
|
|
10
46
|
for (const f of STRING_FLAGS)
|
package/dist/brief.js
CHANGED
|
@@ -47,7 +47,11 @@ export function formatRecoveryBrief(brief) {
|
|
|
47
47
|
if (brief.projects.length)
|
|
48
48
|
lines.push(`Process: ${brief.projects.map((p) => `${p.name} ${p.process} (${Array.isArray(p.changed_since_last_read) ? `changed since you last read: ${p.changed_since_last_read.join("; ")}` : p.changed_since_last_read})`).join("; ")}`);
|
|
49
49
|
lines.push("Questions waiting on you:");
|
|
50
|
-
|
|
50
|
+
const addressed = (brief.addressed_questions ?? []).map((q) => ` ${q.project} #${q.channel} seq ${q.seq} from ${q.from} (${q.age_minutes} min ago): ${q.question} — ${q.next}`);
|
|
51
|
+
const unitQuestions = brief.questions.map((q) => ` ${q.project} WU #${q.number} (${q.age_minutes ?? 0} min ago): ${q.question} — ${q.next}`);
|
|
52
|
+
if (brief.addressed_questions_omitted)
|
|
53
|
+
addressed.push(` ${brief.addressed_questions_omitted} more open chat question${brief.addressed_questions_omitted === 1 ? "" : "s"}; run b9s inbox`);
|
|
54
|
+
lines.push(...(addressed.length || unitQuestions.length ? [...addressed, ...unitQuestions] : [" none"]));
|
|
51
55
|
lines.push("Units:");
|
|
52
56
|
lines.push(...(brief.units.length ? brief.units.map((u) => ` [${u.state}] ${u.project} WU #${u.number} ${u.title}${scope(u.base_scope, u.scope_amendments, u.scope_amendments_omitted)}${u.recovery ? `\n Recovery: ${u.recovery.available ? `available (${u.recovery.size ?? "?"} bytes, sha256 ${u.recovery.sha256 ?? "?"})` : "not verified"}${u.recovery.expires_at ? `, expires ${u.recovery.expires_at}` : ""}${u.recovery.manifest?.skipped.length ? `, ${u.recovery.manifest.skipped.length} regenerable path(s) skipped` : ""}${u.recovery.manifest?.omitted.length ? `, ${u.recovery.manifest.omitted.length} file(s) remain uncaptured` : ""}; restore: b9s wu recovery restore ${u.number}` : ""} — ${u.next}`) : [" none"]));
|
|
53
57
|
lines.push("Reviews waiting on you:");
|
package/dist/client.js
CHANGED
|
@@ -1,8 +1,186 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
1
2
|
import { CliError } from "./errors.js";
|
|
2
3
|
import { collectAuto } from "./git.js";
|
|
3
4
|
import { resolveEffort } from "./model.js";
|
|
4
5
|
import { cliUserAgent } from "./legacy-alias.js";
|
|
5
6
|
import { noteServerVersions } from "./update.js";
|
|
7
|
+
function expectedTextReceiptFields(method, path, body, response) {
|
|
8
|
+
if (!body)
|
|
9
|
+
return [];
|
|
10
|
+
const fields = body;
|
|
11
|
+
const route = path.split("?", 1)[0];
|
|
12
|
+
const verb = method.toUpperCase();
|
|
13
|
+
const strings = (...names) => names.filter((name) => typeof fields[name] === "string");
|
|
14
|
+
const workUnits = /^\/projects\/[^/]+\/work-units(?:\/(\d+)(?:\/(.*))?)?$/;
|
|
15
|
+
const milestone = /^\/projects\/[^/]+\/milestones\/[^/]+\/(decide|close|verdict)$/;
|
|
16
|
+
if (verb === "POST" && /^\/projects\/[^/]+\/channels\/[^/]+\/messages$/.test(route))
|
|
17
|
+
return strings("body");
|
|
18
|
+
if (verb === "POST" && route === "/feedback")
|
|
19
|
+
return strings("text");
|
|
20
|
+
if (verb === "POST" && /^\/projects\/[^/]+\/channels$/.test(route))
|
|
21
|
+
return strings("topic");
|
|
22
|
+
if (verb === "POST" && route === "/machine-operations")
|
|
23
|
+
return strings("ssh_host");
|
|
24
|
+
if (verb === "POST" && /^\/machine-operations\/[^/]+\/progress$/.test(route))
|
|
25
|
+
return strings("detail");
|
|
26
|
+
if (verb === "POST" && /^\/machine-operations\/[^/]+\/finish$/.test(route))
|
|
27
|
+
return strings("result");
|
|
28
|
+
if (verb === "PATCH" && /^\/projects\/[^/]+\/agents\/[^/]+\/moves\/[^/]+$/.test(route))
|
|
29
|
+
return strings("detail");
|
|
30
|
+
if (verb === "PUT" && /^\/projects\/[^/]+\/process$/.test(route))
|
|
31
|
+
return fields.dry_run === true ? [] : strings("agreements", "charter");
|
|
32
|
+
if (verb === "PUT" && /^\/projects\/[^/]+\/context-policy$/.test(route))
|
|
33
|
+
return strings("note");
|
|
34
|
+
if (verb === "POST" && route === "/account/needs/answer")
|
|
35
|
+
return strings("answer");
|
|
36
|
+
if (verb === "POST" && /^\/account\/watch\/needs\/[^/]+\/action$/.test(route))
|
|
37
|
+
return fields.action === "answer" ? strings("answer") : [];
|
|
38
|
+
if (verb === "POST" && /^\/projects\/[^/]+\/work-units\/\d+\/submit$/.test(route)) {
|
|
39
|
+
const required = strings("expect", "lesson");
|
|
40
|
+
if (Array.isArray(fields.disputes))
|
|
41
|
+
fields.disputes.forEach((dispute, index) => {
|
|
42
|
+
if (!dispute || typeof dispute !== "object" || Array.isArray(dispute))
|
|
43
|
+
return;
|
|
44
|
+
const value = dispute;
|
|
45
|
+
if (typeof value.cited_clause === "string")
|
|
46
|
+
required.push(`disputes.${index}.cited_clause`);
|
|
47
|
+
if (typeof value.reason === "string")
|
|
48
|
+
required.push(`disputes.${index}.reason`);
|
|
49
|
+
});
|
|
50
|
+
return required;
|
|
51
|
+
}
|
|
52
|
+
if (verb === "POST" && /^\/projects\/[^/]+\/work-units$/.test(route))
|
|
53
|
+
return strings("title", "scope");
|
|
54
|
+
if (verb === "POST" && /^\/projects\/[^/]+\/work-units\/assign$/.test(route))
|
|
55
|
+
return strings("title", "scope", "reason");
|
|
56
|
+
const wu = workUnits.exec(route);
|
|
57
|
+
if (wu?.[1] && wu[2]) {
|
|
58
|
+
const action = wu[2];
|
|
59
|
+
if (action === "context-policy")
|
|
60
|
+
return strings("note");
|
|
61
|
+
if (action === "context-policy/decision")
|
|
62
|
+
return strings("reason");
|
|
63
|
+
if (action === "start") {
|
|
64
|
+
const decision = fields.context_decision;
|
|
65
|
+
return decision && typeof decision === "object" && !Array.isArray(decision) && typeof decision.reason === "string"
|
|
66
|
+
? ["context_decision.reason"]
|
|
67
|
+
: [];
|
|
68
|
+
}
|
|
69
|
+
if (action === "assign" || action === "kind")
|
|
70
|
+
return strings("reason");
|
|
71
|
+
if (action === "ask")
|
|
72
|
+
return strings("question");
|
|
73
|
+
if (action === "rule")
|
|
74
|
+
return typeof fields.ruling === "string" && fields.ruling.trim() ? ["ruling"] : [];
|
|
75
|
+
if (action === "propose")
|
|
76
|
+
return strings("proposal");
|
|
77
|
+
if (action === "question/explanation")
|
|
78
|
+
return strings("text");
|
|
79
|
+
if (action === "scope") {
|
|
80
|
+
const required = strings("scope", "append", "note");
|
|
81
|
+
const replacement = fields.replace;
|
|
82
|
+
if (replacement && typeof replacement === "object" && !Array.isArray(replacement) && typeof replacement.new === "string")
|
|
83
|
+
required.push("replace.new");
|
|
84
|
+
return required;
|
|
85
|
+
}
|
|
86
|
+
if (action === "wait")
|
|
87
|
+
return strings("note", "partial");
|
|
88
|
+
if (["approve", "changes", "proceed"].includes(action))
|
|
89
|
+
return strings("note", "unmet");
|
|
90
|
+
if (["park", "requeue", "decline", "classify", "tags", "reopen", "supersede", "done", "abandon", "merge", "evidence/replace", "restore", "note", "hold", "hold/release", "question/escalate"].includes(action))
|
|
91
|
+
return strings("note");
|
|
92
|
+
}
|
|
93
|
+
if (verb === "POST" && milestone.test(route)) {
|
|
94
|
+
const action = milestone.exec(route)?.[1];
|
|
95
|
+
return action === "decide" ? strings("decision") : action === "close" ? strings("note", "waive_informs") : strings("note", "gaps", "waive_informs");
|
|
96
|
+
}
|
|
97
|
+
if (verb === "PUT" && /^\/projects\/[^/]+\/milestones$/.test(route) && Array.isArray(fields.milestones)) {
|
|
98
|
+
return fields.milestones.flatMap((milestone, index) => ["title", "exit", "source"].filter((key) => typeof milestone?.[key] === "string").map((key) => `milestones.${index}.${key}`));
|
|
99
|
+
}
|
|
100
|
+
if (verb === "POST" && /^\/projects\/[^/]+\/milestones\/[^/]+\/reopen$/.test(route))
|
|
101
|
+
return [];
|
|
102
|
+
if (verb === "POST" && /^\/projects\/[^/]+\/locks\/[^/]+\/acquire$/.test(route))
|
|
103
|
+
return strings("note");
|
|
104
|
+
if (verb === "POST" && /^\/projects\/[^/]+\/ask-operator$/.test(route))
|
|
105
|
+
return strings("text", "blocks", "proposal", "plain", "if_yes", "if_no");
|
|
106
|
+
if (verb === "POST" && /^\/projects\/[^/]+\/asks\/[^/]+\/amend$/.test(route))
|
|
107
|
+
return strings("text", "plain", "blocks", "if_yes", "if_no", "proposal");
|
|
108
|
+
if (verb === "POST" && /^\/projects\/[^/]+\/asks\/[^/]+\/withdraw$/.test(route))
|
|
109
|
+
return strings("note");
|
|
110
|
+
if (verb === "POST" && /^\/projects\/[^/]+\/asks\/[^/]+\/explanation$/.test(route))
|
|
111
|
+
return strings("text");
|
|
112
|
+
if (verb === "POST" && /^\/projects\/[^/]+\/asks\/[^/]+\/answer$/.test(route))
|
|
113
|
+
return typeof fields.answer === "string" && fields.answer.trim() ? ["answer"] : [];
|
|
114
|
+
if (verb === "POST" && (/^\/projects\/[^/]+\/lists$/.test(route) || route === "/lists"))
|
|
115
|
+
return strings("description");
|
|
116
|
+
if (verb === "PATCH" && /^\/lists\/[^/]+$/.test(route))
|
|
117
|
+
return strings("description");
|
|
118
|
+
if (verb === "POST" && /^\/lists\/[^/]+\/items$/.test(route))
|
|
119
|
+
return strings("title", "body");
|
|
120
|
+
if (verb === "PATCH" && /^\/items\/[^/]+$/.test(route))
|
|
121
|
+
return strings("title", "body");
|
|
122
|
+
if (verb === "POST" && (/^\/projects\/[^/]+\/notices$/.test(route) || route === "/notices"))
|
|
123
|
+
return strings("text");
|
|
124
|
+
if (verb === "PUT" && route === "/machines/me/notices/disk")
|
|
125
|
+
return strings("text");
|
|
126
|
+
if (verb === "POST" && (/^\/projects\/[^/]+\/agents\/me\/wake$/.test(route) || route === "/agents/me/wake"))
|
|
127
|
+
return strings("reason");
|
|
128
|
+
if (verb === "POST" && /^\/projects\/[^/]+\/evidence$/.test(route))
|
|
129
|
+
return strings("label", "claim");
|
|
130
|
+
if (verb === "POST" && /^\/projects\/[^/]+\/evidence\/[^/]+\/verify$/.test(route))
|
|
131
|
+
return strings("note");
|
|
132
|
+
if (verb === "POST" && (/^\/projects\/[^/]+\/environment\/issues$/.test(route) || /^\/machines\/[^/]+\/environment\/issues$/.test(route))) {
|
|
133
|
+
const required = strings("description");
|
|
134
|
+
if (response?.deduplicated !== true)
|
|
135
|
+
required.push(...strings("title", "category", "component"));
|
|
136
|
+
return required;
|
|
137
|
+
}
|
|
138
|
+
if (verb === "POST" && /^\/environment\/issues\/[^/]+\/observations$/.test(route))
|
|
139
|
+
return strings("description");
|
|
140
|
+
if (verb === "POST" && /^\/environment\/issues\/[^/]+\/claim$/.test(route))
|
|
141
|
+
return strings("note");
|
|
142
|
+
if (verb === "POST" && /^\/environment\/issues\/[^/]+\/diagnosis$/.test(route))
|
|
143
|
+
return strings("diagnosis", "remedy", "note");
|
|
144
|
+
if (verb === "POST" && /^\/environment\/issues\/[^/]+\/resolve$/.test(route))
|
|
145
|
+
return strings("note", "verification");
|
|
146
|
+
if (verb === "POST" && /^\/environment\/issues\/[^/]+\/(merge|related)$/.test(route))
|
|
147
|
+
return strings("note");
|
|
148
|
+
if (verb === "POST" && (/^\/projects\/[^/]+\/roles$/.test(route) || route === "/roles") && typeof fields.description === "string")
|
|
149
|
+
return ["description"];
|
|
150
|
+
if (verb === "PATCH" && (/^\/roles\/[^/]+$/.test(route) || /^\/projects\/[^/]+\/roles\/[^/]+$/.test(route)) && typeof fields.description === "string")
|
|
151
|
+
return ["description"];
|
|
152
|
+
if (verb === "POST" && route === "/cloud/secrets" && typeof fields.secret_name === "string" && fields.secret_name.trim())
|
|
153
|
+
return ["secret_name"];
|
|
154
|
+
return [];
|
|
155
|
+
}
|
|
156
|
+
export function verifyTextReceipts(response, body, requiredFields = []) {
|
|
157
|
+
const receipts = Array.isArray(response?.receipts)
|
|
158
|
+
? response.receipts
|
|
159
|
+
: response?.receipt ? [response.receipt] : [];
|
|
160
|
+
const receivedFields = new Set(receipts.map((receipt) => receipt?.field));
|
|
161
|
+
for (const field of requiredFields) {
|
|
162
|
+
if (!receivedFields.has(field))
|
|
163
|
+
throw new CliError("text_receipt_missing", `${field}: server did not return a text receipt`);
|
|
164
|
+
}
|
|
165
|
+
for (const receipt of receipts) {
|
|
166
|
+
const field = typeof receipt?.field === "string" ? receipt.field : "text";
|
|
167
|
+
let expected = body;
|
|
168
|
+
for (const part of field.split("."))
|
|
169
|
+
expected = expected && typeof expected === "object" ? expected[part] : undefined;
|
|
170
|
+
if (typeof expected !== "string")
|
|
171
|
+
throw new CliError("text_receipt_mismatch", `${field}: response included a text receipt but the CLI cannot find the sent text field`);
|
|
172
|
+
if (typeof receipt.id !== "string" || !receipt.id)
|
|
173
|
+
throw new CliError("text_receipt_mismatch", `${field}: server receipt is missing its id`);
|
|
174
|
+
const bytes = new TextEncoder().encode(expected).byteLength;
|
|
175
|
+
if (receipt.bytes_received !== bytes)
|
|
176
|
+
throw new CliError("text_receipt_mismatch", `${field}: server received ${receipt.bytes_received} bytes; CLI sent ${bytes}`);
|
|
177
|
+
if (receipt.bytes_stored !== bytes)
|
|
178
|
+
throw new CliError("text_receipt_mismatch", `${field}: server stored ${receipt.bytes_stored} of ${bytes} sent bytes`);
|
|
179
|
+
const sha256 = createHash("sha256").update(expected, "utf8").digest("hex");
|
|
180
|
+
if (receipt.sha256 !== sha256)
|
|
181
|
+
throw new CliError("text_receipt_mismatch", `${field}: stored text SHA-256 does not match the sent text`);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
6
184
|
export class Client {
|
|
7
185
|
url;
|
|
8
186
|
key;
|
|
@@ -22,7 +200,7 @@ export class Client {
|
|
|
22
200
|
* by the hook or the watcher, which say nothing about whether the agent is alive.
|
|
23
201
|
*/
|
|
24
202
|
static forAgent(c, model, opts = {}) {
|
|
25
|
-
const auto = collectAuto({ model, machine: c.machine, effort: resolveEffort(opts.effort, process.env, c.vendor) });
|
|
203
|
+
const auto = collectAuto({ model, machine: c.machine, effort: resolveEffort(opts.effort, process.env, c.vendor), provider: process.env.BSCHAT_PROVIDER });
|
|
26
204
|
return new Client(c.url, c.key, opts.presence === false ? null : { ...auto }, c.agent, opts.machineIdentity ? auto.machine : null);
|
|
27
205
|
}
|
|
28
206
|
static forAdmin(c) {
|
|
@@ -101,9 +279,37 @@ export class Client {
|
|
|
101
279
|
: undefined;
|
|
102
280
|
throw new CliError(err.error ?? `http_${res.status}`, err.message ?? text, hint);
|
|
103
281
|
}
|
|
282
|
+
verifyTextReceipts(json, body, expectedTextReceiptFields(method, path, body, json));
|
|
104
283
|
return json;
|
|
105
284
|
}
|
|
106
285
|
}
|
|
286
|
+
/** Like call(), but returns HTTP status and parsed JSON even for 4xx responses (such as preflight or drain conflicts). */
|
|
287
|
+
async callWithStatus(method, path, body) {
|
|
288
|
+
const headers = this.headers();
|
|
289
|
+
if (body !== undefined)
|
|
290
|
+
headers["content-type"] = "application/json";
|
|
291
|
+
let res;
|
|
292
|
+
try {
|
|
293
|
+
res = await fetch(this.url + path, { method, headers, body: body === undefined ? undefined : JSON.stringify(body) });
|
|
294
|
+
}
|
|
295
|
+
catch (e) {
|
|
296
|
+
throw new CliError("network", `could not reach ${this.url}: ${e.message}`);
|
|
297
|
+
}
|
|
298
|
+
noteServerVersions(res.headers, this.agentName);
|
|
299
|
+
const text = await res.text();
|
|
300
|
+
let json;
|
|
301
|
+
try {
|
|
302
|
+
json = JSON.parse(text);
|
|
303
|
+
}
|
|
304
|
+
catch {
|
|
305
|
+
throw new CliError("bad_response", `${method} ${path} returned non-JSON (${res.status}): ${text.slice(0, 200)}`);
|
|
306
|
+
}
|
|
307
|
+
if (res.status >= 500) {
|
|
308
|
+
const err = json;
|
|
309
|
+
throw new CliError(err.error ?? `http_${res.status}`, err.message ?? text);
|
|
310
|
+
}
|
|
311
|
+
return { status: res.status, ok: res.ok, json: json };
|
|
312
|
+
}
|
|
107
313
|
wsUrl(path) {
|
|
108
314
|
return this.url.replace(/^http/, "ws") + path;
|
|
109
315
|
}
|
package/dist/commands/admin.js
CHANGED
|
@@ -13,6 +13,9 @@ import { agentMove, machineAdmin, poolAdmin, projectCheckoutAdmin, projectRepoAd
|
|
|
13
13
|
import { accountAdmin, answerAdmin, explainAdmin, keysAdmin, needsAdmin, notifierAdmin, processAdmin, skillAdmin, tagList, textCheckAdmin, worktreeAdmin } from "./operator.js";
|
|
14
14
|
import { adminNotice } from "./notices.js";
|
|
15
15
|
import { cloudAdmin } from "./cloud-admin.js";
|
|
16
|
+
import { projectImageAdmin } from "./image-admin.js";
|
|
17
|
+
import { environmentAdmin } from "./environment-admin.js";
|
|
18
|
+
import { flowAdmin } from "./flow.js";
|
|
16
19
|
function adminClient(p) {
|
|
17
20
|
return Client.forAdmin(loadAdmin(resolveAdminName(str(p.flags, "admin"))));
|
|
18
21
|
}
|
|
@@ -67,6 +70,10 @@ export async function admin(p, out) {
|
|
|
67
70
|
return projectGitHubAdmin(rest, p, out);
|
|
68
71
|
if (action === "hosted-merge")
|
|
69
72
|
return projectHostedMergeAdmin(rest, p, out);
|
|
73
|
+
if (action === "image")
|
|
74
|
+
return projectImageAdmin(rest, p, out);
|
|
75
|
+
if (action === "environment")
|
|
76
|
+
return projectEnvironmentAdmin(rest, p, out);
|
|
70
77
|
return project(action, rest, p, out);
|
|
71
78
|
case "github":
|
|
72
79
|
return githubAdmin(action, rest, p, out);
|
|
@@ -100,6 +107,8 @@ export async function admin(p, out) {
|
|
|
100
107
|
}
|
|
101
108
|
case "needs":
|
|
102
109
|
return needsAdmin(p, out);
|
|
110
|
+
case "flow":
|
|
111
|
+
return flowAdmin(action, rest, p, out);
|
|
103
112
|
case "notice":
|
|
104
113
|
return adminNotice(action, rest, p, out);
|
|
105
114
|
case "answer":
|
|
@@ -119,6 +128,8 @@ export async function admin(p, out) {
|
|
|
119
128
|
return machineAdmin(action, rest, p, out);
|
|
120
129
|
case "cloud":
|
|
121
130
|
return cloudAdmin(action, rest, p, out);
|
|
131
|
+
case "environment":
|
|
132
|
+
return environmentAdmin(adminClient(p), action, rest, p, out);
|
|
122
133
|
case "pool":
|
|
123
134
|
case "pools":
|
|
124
135
|
return poolAdmin(action, rest, p, out, process.argv.slice(2));
|
|
@@ -159,7 +170,8 @@ async function projectGitHubAdmin(rest, p, out) {
|
|
|
159
170
|
if (action === "status") {
|
|
160
171
|
const r = await c.call("GET", `/projects/${project}/github-link`);
|
|
161
172
|
const link = r.link;
|
|
162
|
-
|
|
173
|
+
const rulesetUnverified = link.ruleset_unverified_reason ?? (!link.ruleset_fingerprint || !link.ruleset_metadata_hash || !link.verified_at ? "not verified" : null);
|
|
174
|
+
out.print(`${project}: ${link.owner}/${link.name} -> ${link.target_branch}; hosted merge ${r.hosted_merge_enabled ? "enabled" : "disabled"}${rulesetUnverified ? `; ruleset unverified: ${rulesetUnverified}` : ""}`, r);
|
|
163
175
|
return;
|
|
164
176
|
}
|
|
165
177
|
if (action === "unlink") {
|
|
@@ -177,10 +189,71 @@ async function projectHostedMergeAdmin(rest, p, out) {
|
|
|
177
189
|
const enabled = action === "enable";
|
|
178
190
|
const confirmed = bool(p.flags, "confirm-bypass-signal");
|
|
179
191
|
if (enabled && !confirmed)
|
|
180
|
-
throw new CliError("usage", "
|
|
192
|
+
throw new CliError("usage", "verify the exact target ruleset in Account -> GitHub connection, complete the live GitHub bypass-change signal check, then pass --confirm-bypass-signal");
|
|
181
193
|
const r = await adminClient(p).call("PATCH", `/projects/${project}/github-link`, { hosted_merge_enabled: enabled, ...(enabled ? { bypass_signal_verified: true } : {}) });
|
|
182
194
|
out.print(`Hosted merge ${enabled ? "enabled" : "disabled"} for ${project}.`, r);
|
|
183
195
|
}
|
|
196
|
+
async function projectEnvironmentAdmin(rest, p, out) {
|
|
197
|
+
const [operation, project, ...extra] = rest;
|
|
198
|
+
if (!operation || !project)
|
|
199
|
+
throw new CliError("usage", "b9s-admin project environment show <project> | setup <project> [--catalog family@version] [--assessment-only] [--context text] | set <project> --file declaration.json --source-commit <merged-sha>");
|
|
200
|
+
const c = adminClient(p);
|
|
201
|
+
const projectPath = encodeURIComponent(project);
|
|
202
|
+
if (operation === "show") {
|
|
203
|
+
if (extra.length)
|
|
204
|
+
throw new CliError("usage", "b9s-admin project environment show <project>");
|
|
205
|
+
const r = await c.call("GET", `/projects/${projectPath}/environment`);
|
|
206
|
+
const declaration = r.declaration;
|
|
207
|
+
const link = r.repository;
|
|
208
|
+
const latest = r.setup?.latest;
|
|
209
|
+
const source = declaration?.container === "none" ? `host-native${declaration.machine_labels?.length ? ` (${declaration.machine_labels.join(", ")})` : ""}` : declaration?.path ?? "";
|
|
210
|
+
const template = declaration?.template ? `${declaration.template.family}@${declaration.template.version} (catalog ${declaration.template.catalog_release}, revision ${declaration.template.source_revision})` : "";
|
|
211
|
+
const declarationStatus = r.declaration_status === "stale"
|
|
212
|
+
? "stale declaration from a previous repository link; request setup for the current link"
|
|
213
|
+
: declaration ? `${source}${template ? ` (${template})` : ""}, source ${declaration.source_commit}` : "no reviewed environment declaration";
|
|
214
|
+
const setupStatus = latest ? `latest setup #${latest.unit_number}${latest.stale ? " (stale; belongs to a previous repository link)" : ""}` : "no setup request";
|
|
215
|
+
out.print(`${project}: ${declarationStatus}; ${setupStatus}; repository ${link?.linked ? `${link.owner}/${link.name} -> ${link.target_branch}` : "not linked"}.`, r);
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
218
|
+
if (operation === "setup") {
|
|
219
|
+
if (extra.length)
|
|
220
|
+
throw new CliError("usage", "b9s-admin project environment setup <project> [--catalog family@version] [--assessment-only] [--context text]");
|
|
221
|
+
const catalog = str(p.flags, "catalog");
|
|
222
|
+
let template;
|
|
223
|
+
if (catalog !== undefined) {
|
|
224
|
+
const match = /^(node-web|python|rust|eda|mobile-linux|hardware-bound)@(\d+\.\d+\.\d+)$/.exec(catalog);
|
|
225
|
+
if (!match)
|
|
226
|
+
throw new CliError("usage", "--catalog must be family@version");
|
|
227
|
+
template = { family: match[1], version: match[2] };
|
|
228
|
+
}
|
|
229
|
+
const body = {
|
|
230
|
+
...(template ? { template } : {}),
|
|
231
|
+
...(bool(p.flags, "assessment-only") ? { assessment_only: true } : {}),
|
|
232
|
+
...(str(p.flags, "context") !== undefined ? { context: str(p.flags, "context") } : {}),
|
|
233
|
+
};
|
|
234
|
+
const r = await c.call("POST", `/projects/${projectPath}/environment/setup`, body);
|
|
235
|
+
const unit = r.work_unit;
|
|
236
|
+
out.print(`Queued environment ${r.mode === "assessment" ? "assessment" : "setup"} work unit #${unit?.number} for ${project} (${unit?.status ?? "unknown"}).`, r);
|
|
237
|
+
return;
|
|
238
|
+
}
|
|
239
|
+
if (operation === "set") {
|
|
240
|
+
if (extra.length)
|
|
241
|
+
throw new CliError("usage", "b9s-admin project environment set <project> --file declaration.json --source-commit <merged-sha>");
|
|
242
|
+
let declaration;
|
|
243
|
+
try {
|
|
244
|
+
declaration = JSON.parse(readFileSync(need(p.flags, "file"), "utf8"));
|
|
245
|
+
}
|
|
246
|
+
catch (error) {
|
|
247
|
+
throw new CliError("usage", `cannot read environment declaration JSON: ${error.message}`);
|
|
248
|
+
}
|
|
249
|
+
if (!declaration || typeof declaration !== "object" || Array.isArray(declaration))
|
|
250
|
+
throw new CliError("usage", "environment declaration file must contain a JSON object");
|
|
251
|
+
const r = await c.call("PATCH", `/projects/${projectPath}/environment`, { ...declaration, source_commit: need(p.flags, "source-commit") });
|
|
252
|
+
out.print(`Recorded reviewed environment declaration for ${project} from ${str(p.flags, "source-commit")}.`, r);
|
|
253
|
+
return;
|
|
254
|
+
}
|
|
255
|
+
throw new CliError("usage", "b9s-admin project environment show <project> | setup <project> [--catalog family@version] [--assessment-only] [--context text] | set <project> --file declaration.json --source-commit <merged-sha>");
|
|
256
|
+
}
|
|
184
257
|
async function project(action, rest, p, out) {
|
|
185
258
|
const c = adminClient(p);
|
|
186
259
|
if (action === "list") {
|
|
@@ -200,6 +273,8 @@ async function project(action, rest, p, out) {
|
|
|
200
273
|
}
|
|
201
274
|
async function agent(action, rest, p, out) {
|
|
202
275
|
const c = adminClient(p);
|
|
276
|
+
if (action === "tier")
|
|
277
|
+
throw new CliError("tier_retired", "agent tiers are retired; evidence-based routing now determines dispatch by model, effort, and tag evidence");
|
|
203
278
|
if (bool(p.flags, "account"))
|
|
204
279
|
return accountAgent(action, rest, p, out, c);
|
|
205
280
|
if (action === "retire") {
|
|
@@ -222,16 +297,7 @@ async function agent(action, rest, p, out) {
|
|
|
222
297
|
return;
|
|
223
298
|
}
|
|
224
299
|
const [proj, name, extra] = rest;
|
|
225
|
-
if (action === "
|
|
226
|
-
const slash = proj.indexOf("/");
|
|
227
|
-
if (slash < 1 || slash === proj.length - 1 || proj.indexOf("/", slash + 1) !== -1)
|
|
228
|
-
throw new CliError("usage", "agent tier <project>/<agent> <routine|careful|expert>");
|
|
229
|
-
if (!["routine", "careful", "expert"].includes(name))
|
|
230
|
-
throw new CliError("usage", "tier must be routine, careful, or expert");
|
|
231
|
-
const r = await c.call("PATCH", `/projects/${proj.slice(0, slash)}/agents/${proj.slice(slash + 1)}`, { tier: name });
|
|
232
|
-
out.print(`agent ${proj} tier is now ${r.tier}`, r);
|
|
233
|
-
}
|
|
234
|
-
else if ((action === "away" || action === "back") && proj && !name) {
|
|
300
|
+
if ((action === "away" || action === "back") && proj && !name) {
|
|
235
301
|
const slash = proj.indexOf("/");
|
|
236
302
|
if (slash < 1 || slash === proj.length - 1 || proj.indexOf("/", slash + 1) !== -1)
|
|
237
303
|
throw new CliError("usage", `agent ${action} <project>/<agent>${action === "away" ? " --for <duration>|--until <ISO> --reason <why>" : ""}`);
|
|
@@ -245,7 +311,7 @@ async function agent(action, rest, p, out) {
|
|
|
245
311
|
}
|
|
246
312
|
else if (action === "list" && proj) {
|
|
247
313
|
const r = await c.call("GET", `/projects/${proj}/agents`);
|
|
248
|
-
out.print(table(r.agents, ["name", "scope", "vendor", "role_name", "
|
|
314
|
+
out.print(table(r.agents, ["name", "scope", "vendor", "role_name", "benched_at", "benched_by", "active_keys", "created_at"]), r);
|
|
249
315
|
}
|
|
250
316
|
else if (action === "create" && proj && name) {
|
|
251
317
|
const r = await c.call("POST", `/projects/${proj}/agents`, { name, vendor: need(p.flags, "vendor"), role: str(p.flags, "role") ?? null, machine: str(p.flags, "machine") ?? null });
|
|
@@ -268,9 +334,11 @@ async function agent(action, rest, p, out) {
|
|
|
268
334
|
out.print(`deleted agent ${name}`, r);
|
|
269
335
|
}
|
|
270
336
|
else
|
|
271
|
-
throw new CliError("usage", "admin agent create|list|retire|role|
|
|
337
|
+
throw new CliError("usage", "admin agent create|list|retire|role|rotate-key|bench|unbench|delete ...", "Run: b9s --help");
|
|
272
338
|
}
|
|
273
339
|
async function accountAgent(action, rest, p, out, c) {
|
|
340
|
+
if (action === "tier")
|
|
341
|
+
throw new CliError("tier_retired", "agent tiers are retired; evidence-based routing now determines dispatch by model, effort, and tag evidence");
|
|
274
342
|
const [name, extra] = rest;
|
|
275
343
|
if (action === "retire" && name && !extra) {
|
|
276
344
|
if (name.includes("/"))
|
|
@@ -287,7 +355,7 @@ async function accountAgent(action, rest, p, out, c) {
|
|
|
287
355
|
}
|
|
288
356
|
if (action === "list") {
|
|
289
357
|
const r = await c.call("GET", "/agents");
|
|
290
|
-
out.print(table(r.agents, ["name", "vendor", "role_name", "
|
|
358
|
+
out.print(table(r.agents, ["name", "vendor", "role_name", "benched_at", "benched_by", "active_keys", "created_at"]), r);
|
|
291
359
|
}
|
|
292
360
|
else if (action === "create" && name) {
|
|
293
361
|
const r = await c.call("POST", "/agents", { name, vendor: need(p.flags, "vendor"), role: need(p.flags, "role"), machine: str(p.flags, "machine") ?? null });
|
|
@@ -297,12 +365,6 @@ async function accountAgent(action, rest, p, out, c) {
|
|
|
297
365
|
const r = await c.call("PATCH", `/agents/${name}`, { role: extra });
|
|
298
366
|
out.print(`agent ${name} role is now ${r.role_name}`, r);
|
|
299
367
|
}
|
|
300
|
-
else if (action === "tier" && name && extra) {
|
|
301
|
-
if (!["routine", "careful", "expert"].includes(extra))
|
|
302
|
-
throw new CliError("usage", "tier must be routine, careful, or expert");
|
|
303
|
-
const r = await c.call("PATCH", `/agents/${name}`, { tier: extra });
|
|
304
|
-
out.print(`agent ${name} tier is now ${r.tier}`, r);
|
|
305
|
-
}
|
|
306
368
|
else if (action === "rotate-key" && name) {
|
|
307
369
|
const r = await c.call("POST", `/agents/${name}/keys`, { machine: str(p.flags, "machine") ?? null });
|
|
308
370
|
out.print(`previous keys revoked. New key shown once.\nPaste this into the agent's instructions:\n\n${r.instructions}`, r);
|
|
@@ -312,7 +374,7 @@ async function accountAgent(action, rest, p, out, c) {
|
|
|
312
374
|
out.print(`deleted account agent ${name}`, r);
|
|
313
375
|
}
|
|
314
376
|
else
|
|
315
|
-
throw new CliError("usage", "admin agent --account create <name> --vendor v --role r | list | retire <name> [--note <text> | --note-file <file>] --yes | role <name> <role> |
|
|
377
|
+
throw new CliError("usage", "admin agent --account create <name> --vendor v --role r | list | retire <name> [--note <text> | --note-file <file>] --yes | role <name> <role> | rotate-key <name> | bench|unbench <name> | delete <name>");
|
|
316
378
|
}
|
|
317
379
|
async function retireAdminAgent(c, ref, path, p, out) {
|
|
318
380
|
const note = str(p.flags, "note");
|
package/dist/commands/agent.js
CHANGED
|
@@ -67,7 +67,6 @@ export async function me(p, out) {
|
|
|
67
67
|
const r = await client.call("GET", "/me");
|
|
68
68
|
const lines = [
|
|
69
69
|
`agent: ${r.agent.name} (${r.agent.vendor})`,
|
|
70
|
-
`tier: ${r.agent.tier ?? "routine"}`,
|
|
71
70
|
r.scope === "account" ? `scope: account-wide; projects: ${r.projects.length ? r.projects.map((x) => x.name).join(", ") : "(none allowed by your role)"}` : `project: ${r.project.name}`,
|
|
72
71
|
`role: ${r.role ? `${r.role.name} [${r.role.scope} scope, cardinality ${r.role.cardinality}]` : "(none)"}${r.role_name_unresolved ? ` (assigned role ${r.role_name_unresolved} no longer exists)` : ""}`,
|
|
73
72
|
r.role?.description ? `\n${r.role.description}\n` : "",
|
|
@@ -184,6 +183,8 @@ export async function send(p, out) {
|
|
|
184
183
|
const channel = p.positionals[1];
|
|
185
184
|
let body = p.positionals.slice(2).join(" ");
|
|
186
185
|
const file = str(p.flags, "body-file");
|
|
186
|
+
if (file && body.length)
|
|
187
|
+
throw new CliError("usage", "send accepts a message or --body-file, not both");
|
|
187
188
|
if (file) {
|
|
188
189
|
const { readFileSync } = await import("node:fs");
|
|
189
190
|
body = file === "-" ? readFileSync(0, "utf8") : readFileSync(file, "utf8");
|
|
@@ -325,6 +326,17 @@ function follow(client, path, out) {
|
|
|
325
326
|
/** Mentions of me and replies to my messages. --unread shows only what this identity has not seen yet. */
|
|
326
327
|
export async function inbox(p, out) {
|
|
327
328
|
const { client, creds } = agentClient(p);
|
|
329
|
+
if (p.positionals[1] === "handle") {
|
|
330
|
+
const ref = p.positionals[2];
|
|
331
|
+
const parts = ref?.split("/");
|
|
332
|
+
if (!parts || parts.length !== 3 || !parts[0] || !parts[1] || !/^\d+$/.test(parts[2]) || Number(parts[2]) < 1) {
|
|
333
|
+
throw new CliError("usage", "inbox handle <project>/<channel>/<seq>", "Copy the reference from b9s inbox or b9s resume");
|
|
334
|
+
}
|
|
335
|
+
const [project, channel, seq] = parts;
|
|
336
|
+
const r = await client.call("POST", `/projects/${encodeURIComponent(project)}/channels/${encodeURIComponent(channel)}/questions/${seq}/handle`, {});
|
|
337
|
+
out.print(`Marked ${project}/#${channel} message #${seq} handled`, r);
|
|
338
|
+
return;
|
|
339
|
+
}
|
|
328
340
|
const qs = new URLSearchParams();
|
|
329
341
|
const unread = bool(p.flags, "unread");
|
|
330
342
|
const state = readState(agentRef(creds));
|
|
@@ -336,8 +348,9 @@ export async function inbox(p, out) {
|
|
|
336
348
|
if (unread && r.messages.length)
|
|
337
349
|
writeState(agentRef(creds), { ...state, inbox_after: r.messages[r.messages.length - 1].created_at, last_check: Date.now() });
|
|
338
350
|
const fmt = (m) => `${creds.project ? "" : `[${m.project}] `}${fmtMessage(m)}${m.reply_to_seq ? ` (reply to #${m.reply_to_seq})` : ""}`;
|
|
351
|
+
const questions = (r.questions ?? []).map((q) => ` ${q.project} #${q.channel} seq ${q.seq} from ${q.from} (${q.age_minutes} min ago): ${q.question} — ${q.next}`);
|
|
339
352
|
const items = (r.items ?? []).map((i) => `list "${i.list}": [${i.status}] ${i.title} (item ${i.id})`);
|
|
340
|
-
const text = [...r.messages.map(fmt), ...(items.length ? ["assigned to you:", ...items] : [])].join("\n");
|
|
353
|
+
const text = [...(questions.length ? ["Questions waiting on you:", ...questions] : []), ...r.messages.map(fmt), ...(items.length ? ["assigned to you:", ...items] : [])].join("\n");
|
|
341
354
|
out.print(text || (unread ? "(nothing new for you)" : "(nothing mentions you)"), r);
|
|
342
355
|
}
|
|
343
356
|
export async function channels(p, out) {
|