@botbuddy/cli 1.85.4 → 1.87.0

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.
@@ -1,7 +1,7 @@
1
1
  {
2
- "release_version": "1.85.4",
3
- "source_commit": "0503fade8adc0492e474586d62f8449c412efe4e",
4
- "source_sha256": "c62e2e674b3631d269878779754d19cb8fe9117ca9be82a6ff92218396ef6e91",
2
+ "release_version": "1.87.0",
3
+ "source_commit": "1bc300346f1400d59f347b3d94273b6577e08ace",
4
+ "source_sha256": "cb221a48753f2e53a46ac1d595cf524254d2442ec2d84bee9ece5271e5ae3860",
5
5
  "target": "darwin-arm64",
6
- "sha256": "787782e24b89959b3a4135d19307e599f3fcbdaa292b916cf9475e298ce3da54"
6
+ "sha256": "a93917a4e8f1a2ed383f5c81911a5d42515e397abbd791a844667ab4efb2b559"
7
7
  }
@@ -1,7 +1,7 @@
1
1
  {
2
- "release_version": "1.85.4",
3
- "source_commit": "0503fade8adc0492e474586d62f8449c412efe4e",
4
- "source_sha256": "c62e2e674b3631d269878779754d19cb8fe9117ca9be82a6ff92218396ef6e91",
2
+ "release_version": "1.87.0",
3
+ "source_commit": "1bc300346f1400d59f347b3d94273b6577e08ace",
4
+ "source_sha256": "cb221a48753f2e53a46ac1d595cf524254d2442ec2d84bee9ece5271e5ae3860",
5
5
  "target": "linux-x64",
6
- "sha256": "d0989aef2450836d8ae26c58ef6227da015ccfc63204c3f2fcbbe77e632c1e39"
6
+ "sha256": "3f7405e48ad12350803fd2ab1bddd35877b6d69468d471849f35bb7a0d5edc59"
7
7
  }
@@ -1,21 +1,21 @@
1
1
  {
2
2
  "schema_version": 1,
3
- "release_version": "1.85.4",
4
- "source_commit": "0503fade8adc0492e474586d62f8449c412efe4e",
5
- "source_sha256": "c62e2e674b3631d269878779754d19cb8fe9117ca9be82a6ff92218396ef6e91",
3
+ "release_version": "1.87.0",
4
+ "source_commit": "1bc300346f1400d59f347b3d94273b6577e08ace",
5
+ "source_sha256": "cb221a48753f2e53a46ac1d595cf524254d2442ec2d84bee9ece5271e5ae3860",
6
6
  "targets": {
7
7
  "darwin-arm64": {
8
8
  "goos": "darwin",
9
9
  "goarch": "arm64",
10
10
  "binary": "daemon/bin/darwin-arm64/botbuddy-daemon",
11
- "sha256": "787782e24b89959b3a4135d19307e599f3fcbdaa292b916cf9475e298ce3da54",
11
+ "sha256": "a93917a4e8f1a2ed383f5c81911a5d42515e397abbd791a844667ab4efb2b559",
12
12
  "mode": "0755"
13
13
  },
14
14
  "linux-x64": {
15
15
  "goos": "linux",
16
16
  "goarch": "amd64",
17
17
  "binary": "daemon/bin/linux-x64/botbuddy-daemon",
18
- "sha256": "d0989aef2450836d8ae26c58ef6227da015ccfc63204c3f2fcbbe77e632c1e39",
18
+ "sha256": "3f7405e48ad12350803fd2ab1bddd35877b6d69468d471849f35bb7a0d5edc59",
19
19
  "mode": "0755"
20
20
  }
21
21
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@botbuddy/cli",
3
- "version": "1.85.4",
3
+ "version": "1.87.0",
4
4
  "description": "BotBuddy — Swarm coordination CLI for multi-agent workflows",
5
5
  "type": "module",
6
6
  "bin": {
package/src/commands.mjs CHANGED
@@ -364,6 +364,8 @@ ${bold("EVIDENCE")} (${cyan("bb help evidence")})
364
364
  status-band read|relay The band's own reads and live wake (run by the mod)
365
365
  evidence require <file> Record an exact-head evidence disposition → botbuddy/ready
366
366
  evidence publish <file> Publish a local evidence statement → botbuddy/ready check-run
367
+ evidence bind <file> Bind a run's receipt to its run, on the requester after the reap
368
+ evidence digest <file> Print the digest of one run record
367
369
 
368
370
  ${bold("HOST + DOCKER")}
369
371
  docker hygiene [options] Dry-run/apply safe stale Supabase cleanup on OrbStack
package/src/evidence.mjs CHANGED
@@ -9,13 +9,59 @@
9
9
  // falling back to the owner/MCP-key ladder like every other `bb` call. Prints
10
10
  // the tool's JSON result on stdout; a refusal exits non-zero.
11
11
 
12
+ import { createHash } from "node:crypto";
12
13
  import { readFileSync } from "node:fs";
13
14
  import { CALL_EXIT, callToolJson as defaultCallToolJson, resolveCallAuth } from "./api.mjs";
14
15
 
15
16
  export const EVIDENCE_EXIT = Object.freeze({ ...CALL_EXIT, USAGE: 2, REFUSED: 4 });
16
17
 
18
+ function canonical(value) {
19
+ if (value === null) return "null";
20
+ if (typeof value === "string" || typeof value === "boolean") return JSON.stringify(value);
21
+ if (typeof value === "number") {
22
+ if (!Number.isFinite(value)) throw new Error("a run record number must be finite");
23
+ return JSON.stringify(value);
24
+ }
25
+ if (Array.isArray(value)) return `[${value.map(canonical).join(",")}]`;
26
+ if (typeof value === "object") {
27
+ const entries = Object.entries(value).sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0));
28
+ return `{${entries.map(([k, v]) => `${JSON.stringify(k)}:${canonical(v)}`).join(",")}}`;
29
+ }
30
+ throw new Error("a run record holds only JSON values");
31
+ }
32
+
33
+ /**
34
+ * BOT-3312: sorted-key JSON of one run record. Must stay byte-identical to
35
+ * supabase/functions/_shared/lib/runReceiptBinding.ts; both sides assert one fixed vector.
36
+ */
37
+ export function canonicalRunRecordJson(record) {
38
+ if (!record || typeof record !== "object" || Array.isArray(record)) throw new Error("a run record must be a JSON object");
39
+ return canonical(record);
40
+ }
41
+
42
+ export function runRecordDigest(record) {
43
+ return `sha256:${createHash("sha256").update(canonicalRunRecordJson(record)).digest("hex")}`;
44
+ }
45
+
46
+ const sortedUnique = (values) => [...new Set(values)].sort();
47
+
48
+ /** The first field where the child's record differs from what the requester launched. */
49
+ function claimMismatch({ claim, record, leaseId, testRunId }) {
50
+ if (record.full !== claim.full) return "full";
51
+ const recorded = Array.isArray(record.domains) ? sortedUnique(record.domains) : [];
52
+ const claimed = sortedUnique(claim.domains);
53
+ if (recorded.length !== claimed.length || recorded.some((d, i) => d !== claimed[i])) return "domains";
54
+ if ((record.project ?? null) !== (claim.project ?? null)) return "project";
55
+ if (record.fingerprint !== claim.fingerprint) return "fingerprint";
56
+ if (record.lifecycle?.stackId !== leaseId) return "lifecycle.stackId";
57
+ if (record.runId !== testRunId) return "runId";
58
+ return null;
59
+ }
60
+
17
61
  const USAGE = `Usage: bb evidence require <requirement.json>
18
62
  bb evidence publish <statement.json>
63
+ bb evidence bind <request.json>
64
+ bb evidence digest <run-record.json>
19
65
 
20
66
  require Record the impact producer's decision for one exact PR head. The file
21
67
  is a JSON object with: repo, pr, headSha, disposition
@@ -26,14 +72,44 @@ publish Publish a local evidence statement for a PR head (after an e2e
26
72
  requirement). The statement is a JSON object with:
27
73
  repo, pr, headSha, mainSha, base, fingerprint, requirement, runs[]
28
74
  (each with the BotBuddy runId), verdict ("pass" | "fail"), fixCommand
75
+ bind Bind one run's receipt to its run, after its lease is reaped. Run this
76
+ on the requester, never in the test child. The file is a JSON object
77
+ with: leaseId, testRunId, headSha, childExitCode, record (the run
78
+ record), and claim {full, domains, project, fingerprint}. Build the
79
+ claim from what you launched, not from the child's record. A record
80
+ that differs from the claim is refused and nothing is sent.
81
+ digest Print the digest of one run record. Publish it as runs[i].recordDigest.
29
82
 
30
83
  Exit codes: 0 recorded · 2 usage · 3 auth · 4 refused · 5 unreachable`;
31
84
 
32
85
  const SUBCOMMANDS = Object.freeze({
33
86
  require: { tool: "publish_evidence_requirement", argName: "requirement" },
34
87
  publish: { tool: "publish_evidence", argName: "statement" },
88
+ bind: { tool: "bind_run_receipt" },
89
+ digest: { tool: null },
35
90
  });
36
91
 
92
+ /** BOT-3312: the tool arguments for `bind`, or a refusal made before anything is sent. */
93
+ function bindArguments(body) {
94
+ const { leaseId, testRunId, headSha, childExitCode, claim, record } = body ?? {};
95
+ if (!claim || typeof claim !== "object" || !Array.isArray(claim.domains) || !record || typeof record !== "object" || Array.isArray(record)) {
96
+ return { usage: "the request needs a claim {full, domains, project, fingerprint} and the run record" };
97
+ }
98
+ const field = claimMismatch({ claim, record, leaseId, testRunId });
99
+ if (field) {
100
+ return { refusal: { success: false, code: "RECEIPT_BINDING_CLAIM_MISMATCH", field,
101
+ message: `the run record's ${field} differs from what the requester launched; nothing was bound` } };
102
+ }
103
+ return { args: {
104
+ lease_id: leaseId,
105
+ test_run_id: testRunId,
106
+ head_sha: headSha,
107
+ run_record_digest: runRecordDigest(record),
108
+ child_exit_code: childExitCode,
109
+ claim: { full: claim.full, domains: claim.domains, project: claim.project ?? null, fingerprint: claim.fingerprint },
110
+ } };
111
+ }
112
+
37
113
  export async function cmdEvidence(args, {
38
114
  resolveAuth = resolveCallAuth,
39
115
  callToolJson = defaultCallToolJson,
@@ -63,6 +139,31 @@ export async function cmdEvidence(args, {
63
139
  return EVIDENCE_EXIT.USAGE;
64
140
  }
65
141
 
142
+ if (sub === "digest") {
143
+ try {
144
+ log(JSON.stringify({ digest: runRecordDigest(body) }));
145
+ return EVIDENCE_EXIT.OK;
146
+ } catch (error) {
147
+ errorLog(`✗ ${error?.message ?? error}`);
148
+ return EVIDENCE_EXIT.USAGE;
149
+ }
150
+ }
151
+
152
+ let toolArgs = { [spec.argName]: body };
153
+ if (sub === "bind") {
154
+ const bind = bindArguments(body);
155
+ if (bind.usage) {
156
+ errorLog(`✗ ${bind.usage}\n\n${USAGE}`);
157
+ return EVIDENCE_EXIT.USAGE;
158
+ }
159
+ if (bind.refusal) {
160
+ log(JSON.stringify(bind.refusal, null, 2));
161
+ errorLog(`✗ ${bind.refusal.code}: ${bind.refusal.message}`);
162
+ return EVIDENCE_EXIT.REFUSED;
163
+ }
164
+ toolArgs = bind.args;
165
+ }
166
+
66
167
  const resolved = await resolveAuth({ toolName: spec.tool, preferSession: true });
67
168
  if (resolved?.error || !resolved?.auth) {
68
169
  log(JSON.stringify(resolved?.error ?? { ok: false, auth: true, error: "not_authenticated" }, null, 2));
@@ -70,7 +171,7 @@ export async function cmdEvidence(args, {
70
171
  return EVIDENCE_EXIT.AUTH;
71
172
  }
72
173
 
73
- const res = await callToolJson(spec.tool, { [spec.argName]: body }, { auth: resolved.auth });
174
+ const res = await callToolJson(spec.tool, toolArgs, { auth: resolved.auth });
74
175
  if (!res.ok) {
75
176
  log(JSON.stringify(res, null, 2));
76
177
  if (res.auth) {
@@ -86,10 +187,18 @@ export async function cmdEvidence(args, {
86
187
  }
87
188
 
88
189
  log(JSON.stringify(res.data, null, 2));
89
- if (res.isError || res.data?.ok === false) {
90
- errorLog(`✗ ${res.data?.error ?? `${spec.tool} refused`}: ${res.data?.message ?? ""}`.trimEnd());
190
+ if (res.isError || res.data?.ok === false || res.data?.success === false) {
191
+ errorLog(`✗ ${res.data?.code ?? res.data?.error ?? `${spec.tool} refused`}: ${res.data?.message ?? ""}`.trimEnd());
91
192
  return EVIDENCE_EXIT.REFUSED;
92
193
  }
194
+ if (sub === "bind") {
195
+ // Success means a binding id came back; an empty answer is never "bound".
196
+ if (res.data?.success !== true || typeof res.data?.binding_id !== "string") {
197
+ errorLog("✗ BotBuddy returned no binding — nothing is known to be bound; retry.");
198
+ return EVIDENCE_EXIT.ERROR;
199
+ }
200
+ return EVIDENCE_EXIT.OK;
201
+ }
93
202
  if (sub === "require") {
94
203
  // Success means the control plane echoed the recorded disposition — an
95
204
  // outage body that normalises to an empty result is never "recorded".
@@ -3,7 +3,8 @@
3
3
  // validator: the CLI sends the file's JSON unchanged (no rewriting, no filling
4
4
  // in), records the route as `cli`, and prints the stored source key, state and
5
5
  // revision, or the named refusal. The tenant is the authenticated agent's.
6
- import { readFile } from "node:fs/promises";
6
+ import { randomBytes } from "node:crypto";
7
+ import { open, readFile, rename, rm } from "node:fs/promises";
7
8
  import { CALL_EXIT, callToolJson, resolveCallAuth } from "./api.mjs";
8
9
  import { cmdReleaseNotesKeys, cmdReleaseNotesOrigins, RELEASE_NOTES_KEYS_USAGE } from "./release-notes-keys.mjs";
9
10
 
@@ -13,6 +14,7 @@ export const RELEASE_NOTES_USAGE = `Usage: bb release-notes submit <note.json> [
13
14
  bb release-notes list [--tag <group>=<value>]... [--type <type>] [--state <state>] [--cursor <cursor>] [--json]
14
15
  bb release-notes get <source_key> [--json]
15
16
  bb release-notes digest --release <version> --voice internal|external [--format markdown|json|slack] [--repository owner/name] [--json]
17
+ bb release-notes pack --release <version> [--format md] [--customer <name>] [--repository owner/name] [--out <file>] [--json]
16
18
  bb release-notes grants list [--tenant <slug>] [--json]
17
19
  bb release-notes grants add <email> <submit|manage> [--tenant <slug>] [--json]
18
20
  bb release-notes grants remove <email> <submit|manage> [--tenant <slug>] [--json]
@@ -114,6 +116,13 @@ with no notes prints an explicit empty digest. --json prints the whole answer
114
116
  repository_required, release_not_shipped, no_previous_release,
115
117
  release_range_unavailable, entitlement_missing, scope_missing.
116
118
 
119
+ Pack (BOT-3261). pack prints the internal release pack for one production
120
+ release as Markdown: a cover section with counts and affected customers, release
121
+ readiness, risks and remaining work, and every change with Before, After, Benefit
122
+ and UI. --customer keeps the changes that customer raised. --out writes a file
123
+ only you can read. The pack is internal: do not send it outside your company.
124
+ Refusals: customer_unknown and the digest's refusals.
125
+
117
126
  Exit codes: 0 stored or read · 1 refused or not found · 2 usage · 3 authentication · 5 BotBuddy unreachable.
118
127
 
119
128
  Viewer keys and origins (tenant owners, BOT-3158):
@@ -128,6 +137,7 @@ export async function cmdReleaseNotes(args, {
128
137
  log = console.log,
129
138
  errorLog = console.error,
130
139
  write = (text) => process.stdout.write(text),
140
+ writeFile = writePrivateFile,
131
141
  isTTY = process.stdout.isTTY === true,
132
142
  } = {}) {
133
143
  if (args.length === 0 || ["help", "--help", "-h"].includes(args[0])) {
@@ -145,6 +155,8 @@ export async function cmdReleaseNotes(args, {
145
155
  if (args[0] === "origins") return await cmdReleaseNotesOrigins(args.slice(1), { resolveAuth, call, log, errorLog });
146
156
  // BOT-3204: the per-release digest.
147
157
  if (args[0] === "digest") return await cmdDigest(args.slice(1), { resolveAuth, call, log, errorLog, write, isTTY });
158
+ // BOT-3261: the internal release pack.
159
+ if (args[0] === "pack") return await cmdPack(args.slice(1), { resolveAuth, call, log, errorLog, write, writeFile, isTTY });
148
160
  const json = args.includes("--json");
149
161
  let rest = args.filter((a) => a !== "--json");
150
162
  // BOT-3260: --pack <pack.json>, anywhere after submit.
@@ -573,6 +585,76 @@ export async function cmdDigest(argv, { resolveAuth, call, log, errorLog, write,
573
585
  return printRefusalOrFailure(result, json, log, errorLog, "Nothing was changed.");
574
586
  }
575
587
 
588
+ // ── BOT-3261: bb release-notes pack ───────────────────────────────────
589
+
590
+ /**
591
+ * Write a confidential file only its owner can read. An existing file keeps its
592
+ * own permissions when written in place, so a new private file replaces it.
593
+ */
594
+ export async function writePrivateFile(path, bytes) {
595
+ const temporary = `${path}.${randomBytes(6).toString("hex")}.tmp`;
596
+ const handle = await open(temporary, "wx", 0o600);
597
+ try {
598
+ await handle.writeFile(bytes);
599
+ await handle.close();
600
+ await rename(temporary, path);
601
+ } catch (error) {
602
+ await handle.close().catch(() => {});
603
+ await rm(temporary, { force: true });
604
+ throw error;
605
+ }
606
+ }
607
+
608
+ const PACK_TOOL = "get_release_note_pack";
609
+ const PACK_FLAGS = { "--release": "release", "--format": "format", "--customer": "customer", "--repository": "repository", "--out": "out" };
610
+
611
+ export async function cmdPack(argv, { resolveAuth, call, log, errorLog, write, writeFile, isTTY = false }) {
612
+ const json = argv.includes("--json");
613
+ const opts = {};
614
+ for (let i = 0; i < argv.length; i++) {
615
+ const a = argv[i];
616
+ if (a === "--json") continue;
617
+ const key = PACK_FLAGS[a];
618
+ const v = argv[i + 1];
619
+ if (!key || !v || v.startsWith("--") || key in opts) {
620
+ errorLog(RELEASE_NOTES_USAGE);
621
+ return 2;
622
+ }
623
+ opts[key] = v;
624
+ i++;
625
+ }
626
+ if (!opts.release || (opts.format !== undefined && opts.format !== "md")) {
627
+ errorLog(RELEASE_NOTES_USAGE);
628
+ return 2;
629
+ }
630
+ const { out, ...args } = opts;
631
+
632
+ let result;
633
+ try {
634
+ const resolved = await resolveAuth({ toolName: PACK_TOOL, preferSession: true });
635
+ result = resolved?.error || !resolved?.auth
636
+ ? { ok: false, auth: true }
637
+ : await call(PACK_TOOL, args, { auth: resolved.auth, signal: AbortSignal.timeout(120_000) });
638
+ } catch {
639
+ result = { ok: false, status: null };
640
+ }
641
+ const data = result?.data;
642
+ if (result?.ok && data?.ok === true && typeof data.body === "string") {
643
+ if (json) log(JSON.stringify(data));
644
+ else if (out) {
645
+ await writeFile(out, data.body);
646
+ log(`Wrote ${out}`);
647
+ } else write(isTTY ? data.body.split("\t").map(termClean).join("\t") : data.body);
648
+ return CALL_EXIT.OK;
649
+ }
650
+ if (result?.ok && data?.ok !== false) {
651
+ if (json) log(JSON.stringify({ ok: false, error: "receipt_unavailable" }));
652
+ errorLog("✗ BotBuddy did not return a pack. Retry the same command; a pack is a read and changes nothing.");
653
+ return CALL_EXIT.ERROR;
654
+ }
655
+ return printRefusalOrFailure(result, json, log, errorLog, "Nothing was changed.");
656
+ }
657
+
576
658
  // ── BOT-3166: bb release-notes list | get ──────────────────────────────
577
659
 
578
660
  function readUsage(errorLog) {