@botbuddy/cli 1.74.0 → 1.75.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.75.0
4
+
5
+ - New `bb release-notes keys create|list|revoke` and `bb release-notes origins set` let a tenant owner give their own app a way to show release notes without its users signing in to BotBuddy (BOT-3158). `keys create --environment <local|preview|staging|production> --out <file>` writes the new viewer-key secret to a new file with mode 0600 and never prints it (not with `--json`, not on error); the file is claimed before BotBuddy is called and removed if nothing was created. `keys list` shows each key id (`<tenant>:<environment>:<n>`), active or revoked, and each environment's origins. `keys revoke --environment <env> --key <n>` makes tokens signed with that key fail at once. `origins set --environment <env> --origin <origin>…` (or `--none`) replaces the web origins that may read the feed. Refusals name their code (`owner_required`, `entitlement_missing`, `too_many_active_keys`, `key_not_found`, `origin_refused`) and exit 1.
6
+ ## 1.74.1
7
+
8
+ - When staging is red, the bb-status band names the staging release manager BB elected for the incident (BOT-3241): `▲ Staging red 20m Release manager: Fanie Sanchez Open staging ↗`. In Claude Code Desktop the name is a button that opens that agent's Claude Code or Codex session; in the terminal it is a link to it. Without a known session the name is plain text, and before anyone is elected the row says `No release manager yet`. Each badge pill now holds its words to the width it was drawn for, so they never run past its rounded end whatever font or zoom Desktop uses (BOT-3230 follow-up), and a wait for staging to go green reads `Until staging green` rather than `Staging green`, which looked like a status beside a red staging. The band now opens with two titled rows on the same grid as the tickets (BOT-3245): `STATUS` (staging red with its release manager and link, then the context alarm) and `WAITS` (each active wait), each title in the id column and every badge starting in the status-badge column, so a wait never sits among the statuses. The plugin version moves to 1.4.4, so `bb update` installs it.
9
+
3
10
  ## 1.74.0
4
11
 
5
12
  - `bb release-notes grants list|add|remove` (BOT-3160). A tenant owner names who may submit or manage release notes: `grants add <email> <submit|manage>` grants one scope to one member of the tenant, `grants remove` revokes it, and `grants list` prints the owners (who manage implicitly), the effective grants and the newest changes. The commands use your own sign-in (`bb login`), never the agent session, and take `--tenant <slug>` and `--json`. A refusal names its code (`scope_missing`, `member_not_in_tenant`, `owner_scope_is_implicit`, `scope_unknown`, `entitlement_missing`) and changes nothing; repeating a grant or a revoke changes nothing twice.
@@ -11,7 +11,7 @@
11
11
  "name": "bb-status",
12
12
  "source": "./bb-status",
13
13
  "description": "BB session status above the prompt: tickets, PRs with review counts, epic, staging, context use and active waits, for BotBuddy and Supply Guard sessions",
14
- "version": "1.4.3"
14
+ "version": "1.4.4"
15
15
  },
16
16
  {
17
17
  "name": "bb-session",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bb-status",
3
- "version": "1.4.3",
3
+ "version": "1.4.4",
4
4
  "description": "BB session status above the prompt: tickets, PRs with review counts, epic, staging, context use and active waits, live only while the session is on screen.",
5
5
  "author": {
6
6
  "name": "BotBuddy"
@@ -214,3 +214,17 @@ words inside, its width estimated from the words. A Claude Code `Box` has no
214
214
  corner radius, and a border draws a whole row above and below. Links stay
215
215
  `Link` elements beside the pill. Failure notes are their own dim line under
216
216
  the tree. The terminal keeps filled `Box` badges.
217
+
218
+ **BOT-3241 release manager.** While staging is red the row names the release
219
+ manager BB elected for the open incident (`staging.release_manager`). On Desktop
220
+ the name is a Button that runs macOS `open` on their session link (a plugin
221
+ `Link` off the terminal only opens `https:`); in the terminal it is a `Link`.
222
+ Only `claude://claude.ai/epitaxy/local_<uuid>` and `codex://threads/<uuid>` are
223
+ accepted; any other link rejects the snapshot. No session: the name is plain
224
+ text; none elected: `No release manager yet`.
225
+
226
+ **BOT-3245 STATUS and WAITS.** The band opens with up to two titled rows on
227
+ the tree's grid: `STATUS` (staging red, its release manager and link, the
228
+ context alarm) and `WAITS` (each active wait, three at most, then `+N more`).
229
+ Each title fills the id column (at least six cells wide); the badges start in
230
+ the status-badge column and wrap there. A row with no badges is not drawn.
@@ -207,7 +207,12 @@ function validSnapshot(value, harness, now) {
207
207
  !(
208
208
  typeof value.staging.configured === "boolean" &&
209
209
  typeof value.staging.red === "boolean" &&
210
- (value.staging.since === null || Number.isFinite(Date.parse(value.staging.since)))
210
+ (value.staging.since === null || Number.isFinite(Date.parse(value.staging.since))) &&
211
+ // BOT-3241: the release manager: absent (unknown), null (none) or a
212
+ // safe name with a verified session link or none.
213
+ (value.staging.release_manager == null ||
214
+ (safeLabel(value.staging.release_manager.name, 80) &&
215
+ (value.staging.release_manager.href === null || SESSION_HREF.some((re) => re.test(value.staging.release_manager.href)))))
211
216
  )) ||
212
217
  // BOT-3212: the agent's active waits; null or absent means unknown (no badge).
213
218
  (value.waits != null &&
@@ -296,7 +301,7 @@ function demoSnapshot(now) {
296
301
  total: 11,
297
302
  percent: 45,
298
303
  },
299
- staging: { configured: true, red: true, since: new Date(now - 12 * 60000).toISOString() },
304
+ staging: { configured: true, red: true, since: new Date(now - 12 * 60000).toISOString(), release_manager: { name: "Fanie Sanchez", href: null } },
300
305
  waits: {
301
306
  count: 2,
302
307
  oldest_at: new Date(now - 14 * 60000).toISOString(),
@@ -833,12 +838,15 @@ function glyphPx(ch) {
833
838
  if (/[A-Z]/.test(ch)) return 8.1;
834
839
  if (/[0-9]/.test(ch)) return 7.1;
835
840
  if (/[a-z]/.test(ch)) return 6.5;
836
- if (ch.codePointAt(0) > 0x2000) return 15; // ⏳ ▲ and other symbols
841
+ if (ch.codePointAt(0) > 0x2000) return 18; // ⏳ ▲ and other symbols
837
842
  return 7.1;
838
843
  }
839
844
  function textPx(text, bold) {
845
+ // BOT-3230 follow-up: ~6% over the 13px system font, since Desktop's own
846
+ // font and zoom draw wider ("Some the SVG buttons are a bit too small for the
847
+ // text", Jono, 2026-11-15); the <text> is then held to this width anyway.
840
848
  const w = [...String(text)].reduce((n, ch) => n + glyphPx(ch), 0);
841
- return Math.ceil(w * (bold ? 1.06 : 1));
849
+ return Math.ceil(w * (bold ? 1.12 : 1.06));
842
850
  }
843
851
  function xml(text) {
844
852
  return String(text).replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#39;");
@@ -857,8 +865,10 @@ function pillSource({ text, icon, fill, bold }, slot) {
857
865
  body += String(icon).replace(/^<svg /, `<svg x="${x}" y="${(PILL.h - PILL.icon) / 2}" `);
858
866
  x += PILL.icon + (text ? PILL.gap : 0);
859
867
  }
868
+ // The words are held to the width the pill was drawn for (textLength), so
869
+ // whatever font or zoom draws them, they end inside the rounded end.
860
870
  if (text)
861
- body += `<text x="${x}" y="15" font-family="-apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif" font-size="${PILL.font}"${bold ? ' font-weight="600"' : ""} fill="#ffffff">${xml(text)}</text>`;
871
+ body += `<text x="${x}" y="15" textLength="${textPx(text, bold)}" lengthAdjust="spacingAndGlyphs" font-family="-apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif" font-size="${PILL.font}"${bold ? ' font-weight="600"' : ""} fill="#ffffff">${xml(text)}</text>`;
862
872
  return { width: outer, source: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${outer} ${PILL.h}" width="${outer}" height="${PILL.h}">${body}</svg>` };
863
873
  }
864
874
  function pillSvg(el, pill, slot) {
@@ -971,18 +981,34 @@ function waitBadges(el, key, w, now) {
971
981
  if (w.count > out.length) out.push(dim(el, "+" + (w.count - out.length) + " more"));
972
982
  return out;
973
983
  }
974
- function contextLine(el, key, waits = null) {
975
- const children = [];
984
+ // The context alarm's red pill (above 30%), or nothing.
985
+ function contextBadge(el, key) {
976
986
  const alarm = contextAlarm(context);
977
- if (alarm)
978
- children.push(
979
- pills() && typeof el.Svg === "function"
980
- ? el.Box({ key: key + "-ctx", flexDirection: "row", flexShrink: 0, children: [pillSvg(el, { text: alarm, fill: RED, bold: true })] })
981
- : el.Box({ key: key + "-ctx", flexDirection: "row", flexShrink: 0, backgroundColor: "error", paddingX: 1, children: [el.Text({ color: "#ffffff", bold: true, children: [alarm] })] }),
982
- );
983
- children.push(...waitBadges(el, key, waits, currentTime));
984
- if (!children.length) return null;
985
- return el.Box({ key, flexDirection: "row", flexWrap: "wrap", alignItems: "center", columnGap: 1, rowGap: 0, children });
987
+ if (!alarm) return [];
988
+ return [
989
+ pills() && typeof el.Svg === "function"
990
+ ? el.Box({ key: key + "-ctx", flexDirection: "row", flexShrink: 0, children: [pillSvg(el, { text: alarm, fill: RED, bold: true })] })
991
+ : el.Box({ key: key + "-ctx", flexDirection: "row", flexShrink: 0, backgroundColor: "error", paddingX: 1, children: [el.Text({ color: "#ffffff", bold: true, children: [alarm] })] }),
992
+ ];
993
+ }
994
+ // BOT-3245: statuses and waits are separate, titled rows on the tree's grid
995
+ // (Jono, 2026-11-15: "Staging green is a wait. Staging red is a status."). The
996
+ // title fills the id column; the badges start in the status-badge column and
997
+ // wrap there, never under the title. No badges, no row.
998
+ const TITLES = { status: "STATUS", waits: "WAITS" };
999
+ const TITLE_CELLS = Math.max(...Object.values(TITLES).map((t) => t.length));
1000
+ function headerRow(el, key, title, idsCells, badges) {
1001
+ if (!badges.length) return null;
1002
+ return el.Box({
1003
+ key,
1004
+ flexDirection: "row",
1005
+ alignItems: "flex-start",
1006
+ columnGap: 1,
1007
+ children: [
1008
+ el.Box({ key: key + "-title", flexDirection: "row", width: idsCells, flexShrink: 0, children: [dim(el, title)] }),
1009
+ el.Box({ key: key + "-badges", flexDirection: "row", flexWrap: "wrap", alignItems: "center", columnGap: 1, rowGap: 0, flexGrow: 1, flexShrink: 1, minWidth: 0, children: badges }),
1010
+ ],
1011
+ });
986
1012
  }
987
1013
  async function readContext($) {
988
1014
  try {
@@ -1007,7 +1033,38 @@ function shortAge(fromIso, now) {
1007
1033
  const hours = Math.floor(mins / 60);
1008
1034
  return hours < 48 ? hours + "h" : Math.floor(hours / 24) + "d";
1009
1035
  }
1010
- function stagingBanner(el, key, since) {
1036
+ // BOT-3241: a release manager's session, as BB's web links it (agentSessionHref):
1037
+ // a Claude Desktop local_<uuid> or a Codex thread uuid, nothing else.
1038
+ const SESSION_HREF = [
1039
+ /^claude:\/\/claude\.ai\/epitaxy\/local_[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i,
1040
+ /^codex:\/\/threads\/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i,
1041
+ ];
1042
+ // "Release manager: <name>". The terminal opens any link itself; Desktop draws a
1043
+ // non-https Link as plain text, so there the name is a Button that opens the
1044
+ // session with macOS `open`.
1045
+ function releaseManager(el, $, rm) {
1046
+ if (rm === undefined) return [];
1047
+ if (rm === null) return [dim(el, "No release manager yet")];
1048
+ const label = dim(el, "Release manager:");
1049
+ if (!rm.href || !SESSION_HREF.some((re) => re.test(rm.href))) return [label, el.Text({ children: [rm.name] })];
1050
+ if (surface === "terminal") return [label, el.Link({ href: rm.href, label: rm.name })];
1051
+ return [
1052
+ label,
1053
+ el.Button({
1054
+ key: "release-manager",
1055
+ label: rm.name,
1056
+ onPress: async () => {
1057
+ try {
1058
+ const r = await $.process.run(["open", rm.href], { timeoutMs: 10000 });
1059
+ if (r?.exitCode !== 0) $.ui.toast("Couldn't open " + rm.name + "'s session");
1060
+ } catch {
1061
+ $.ui.toast("Couldn't open " + rm.name + "'s session");
1062
+ }
1063
+ },
1064
+ }),
1065
+ ];
1066
+ }
1067
+ function stagingBanner(el, $, key, since, rm) {
1011
1068
  const text = "▲ Staging red" + (since ? " " + shortAge(since, currentTime) : "");
1012
1069
  return el.Box({
1013
1070
  key,
@@ -1026,6 +1083,7 @@ function stagingBanner(el, key, since) {
1026
1083
  paddingX: 1,
1027
1084
  children: [el.Text({ color: "#ffffff", bold: true, children: [text] })],
1028
1085
  }),
1086
+ ...releaseManager(el, $, rm),
1029
1087
  el.Link({ href: LINKS.staging, label: "Open staging ↗" }),
1030
1088
  ],
1031
1089
  });
@@ -1050,7 +1108,7 @@ function bandLines(el, $, inPane) {
1050
1108
  columnGap: 1,
1051
1109
  children: [...tag, el.Text({ color: loading ? undefined : "warning", children: ["BB · " + text] }), details].filter(Boolean),
1052
1110
  }),
1053
- contextLine(el, k("line-context")),
1111
+ headerRow(el, k("line-status"), TITLES.status, TITLE_CELLS, contextBadge(el, k("line-context"))),
1054
1112
  ].filter(Boolean);
1055
1113
  }
1056
1114
  const s = snapshot;
@@ -1152,7 +1210,8 @@ function bandLines(el, $, inPane) {
1152
1210
  if (details) right.push(details);
1153
1211
  const svgPills = pills() && typeof el.Svg === "function";
1154
1212
  const widths = {
1155
- ids: Math.max(0, ...specs.map((x) => idsWidth(x.ids, x.prefix))),
1213
+ // BOT-3245: at least as wide as the STATUS / WAITS titles that share the column.
1214
+ ids: Math.max(TITLE_CELLS, ...specs.map((x) => idsWidth(x.ids, x.prefix))),
1156
1215
  status: Math.max(0, ...specs.map(statusWidth)),
1157
1216
  statusPx: svgPills ? Math.max(0, ...specs.filter((x) => x.iconSource).map((x) => pillWidth(statusPill(x)))) : 0,
1158
1217
  };
@@ -1162,11 +1221,15 @@ function bandLines(el, $, inPane) {
1162
1221
  ? [el.Box({ key: k("line-notes-only"), flexDirection: "row", columnGap: 1, children: right })]
1163
1222
  : [];
1164
1223
  if (noteLine) lines.push(noteLine);
1165
- // BOT-3223 AC-1: context alarm and wait badges lead, on one wrapping line.
1166
- const ctx = contextLine(el, k("line-context"), s.waits);
1167
- if (ctx) lines.unshift(ctx);
1168
- // BOT-3152 AC-2: the web Staging chip's red, with its link, above everything.
1169
- if (s.staging?.red) lines.unshift(stagingBanner(el, k("line-staging"), s.staging.since));
1224
+ // BOT-3245: STATUS (staging red, then the context alarm), then WAITS, then the tree.
1225
+ const statuses = [
1226
+ ...(s.staging?.red ? [stagingBanner(el, $, k("line-staging"), s.staging.since, s.staging.release_manager)] : []),
1227
+ ...contextBadge(el, k("line-context")),
1228
+ ];
1229
+ const waitsRow = headerRow(el, k("line-waits"), TITLES.waits, widths.ids, waitBadges(el, k("line-context"), s.waits, currentTime));
1230
+ const statusRow = headerRow(el, k("line-status"), TITLES.status, widths.ids, statuses);
1231
+ if (waitsRow) lines.unshift(waitsRow);
1232
+ if (statusRow) lines.unshift(statusRow);
1170
1233
  return lines;
1171
1234
  }
1172
1235
  export function register(on) {
@@ -1,7 +1,7 @@
1
1
  {
2
- "release_version": "1.74.0",
3
- "source_commit": "07346042a7617efbf032661a79bae0528e4ae2f4",
4
- "source_sha256": "53d3c62c6e011b65b455d7d37dd2a10445e4555e1a48ea92faaa33f9db601440",
2
+ "release_version": "1.75.0",
3
+ "source_commit": "996c48615f708e86157637069407cbb0dee6e396",
4
+ "source_sha256": "fdf8b583fe2b2ea902c36dea1675159ca7bd9fcd657bf5d7589e1160a8565282",
5
5
  "target": "darwin-arm64",
6
- "sha256": "bb0942d5d7a8a247dcbe9ab733bfe38fa40e6e72f5f2432038cb473d6c85338b"
6
+ "sha256": "532c294c0da42ddc09317a21e9644aa0f145aa71e1cc2ffd2fa34c28c92cf50e"
7
7
  }
@@ -1,7 +1,7 @@
1
1
  {
2
- "release_version": "1.74.0",
3
- "source_commit": "07346042a7617efbf032661a79bae0528e4ae2f4",
4
- "source_sha256": "53d3c62c6e011b65b455d7d37dd2a10445e4555e1a48ea92faaa33f9db601440",
2
+ "release_version": "1.75.0",
3
+ "source_commit": "996c48615f708e86157637069407cbb0dee6e396",
4
+ "source_sha256": "fdf8b583fe2b2ea902c36dea1675159ca7bd9fcd657bf5d7589e1160a8565282",
5
5
  "target": "linux-x64",
6
- "sha256": "bccb77188742510964be176335390f4c3da231aee6cfb52bcf1cb3dd190f7a11"
6
+ "sha256": "515f3d0d57f7a3e7b686c27db108a678ce635f14da9843ba984800cb8efb3a78"
7
7
  }
@@ -1,21 +1,21 @@
1
1
  {
2
2
  "schema_version": 1,
3
- "release_version": "1.74.0",
4
- "source_commit": "07346042a7617efbf032661a79bae0528e4ae2f4",
5
- "source_sha256": "53d3c62c6e011b65b455d7d37dd2a10445e4555e1a48ea92faaa33f9db601440",
3
+ "release_version": "1.75.0",
4
+ "source_commit": "996c48615f708e86157637069407cbb0dee6e396",
5
+ "source_sha256": "fdf8b583fe2b2ea902c36dea1675159ca7bd9fcd657bf5d7589e1160a8565282",
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": "bb0942d5d7a8a247dcbe9ab733bfe38fa40e6e72f5f2432038cb473d6c85338b",
11
+ "sha256": "532c294c0da42ddc09317a21e9644aa0f145aa71e1cc2ffd2fa34c28c92cf50e",
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": "bccb77188742510964be176335390f4c3da231aee6cfb52bcf1cb3dd190f7a11",
18
+ "sha256": "515f3d0d57f7a3e7b686c27db108a678ce635f14da9843ba984800cb8efb3a78",
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.74.0",
3
+ "version": "1.75.0",
4
4
  "description": "BotBuddy — Swarm coordination CLI for multi-agent workflows",
5
5
  "type": "module",
6
6
  "bin": {
package/src/commands.mjs CHANGED
@@ -350,6 +350,7 @@ ${bold("EVIDENCE")} (${cyan("bb help evidence")})
350
350
  Submit one release note for your tenant (stored as draft)
351
351
  release-notes grants list|add|remove
352
352
  Owners grant members the release-note submit or manage scope
353
+ release-notes keys|origins Viewer keys and allowed origins for your own app (owners)
353
354
  status-band install Install the bb-status band into Claude Code (bb setup does it)
354
355
  status-band read|relay The band's own reads and live wake (run by the mod)
355
356
  evidence require <file> Record an exact-head evidence disposition → botbuddy/ready
@@ -0,0 +1,194 @@
1
+ // BOT-3158: release-note viewer keys and origins for tenant owners.
2
+ //
3
+ // bb release-notes keys create --environment <env> --out <file> [--json]
4
+ // bb release-notes keys list [--json]
5
+ // bb release-notes keys revoke --environment <env> --key <n> [--json]
6
+ // bb release-notes origins set --environment <env> (--origin <o>… | --none) [--json]
7
+ //
8
+ // A created key's secret is written ONLY to the --out file (created new, mode
9
+ // 0600) and is never printed — not on success, not with --json, not on error.
10
+ // The file is claimed before BotBuddy is called, so a key is never created
11
+ // whose secret has nowhere to go.
12
+ import { open, unlink } from "node:fs/promises";
13
+ import { CALL_EXIT, callToolJson, resolveCallAuth } from "./api.mjs";
14
+
15
+ const ENVIRONMENTS = ["local", "preview", "staging", "production"];
16
+
17
+ export const RELEASE_NOTES_KEYS_USAGE = `Usage:
18
+ bb release-notes keys create --environment <local|preview|staging|production> --out <file> [--json]
19
+ bb release-notes keys list [--json]
20
+ bb release-notes keys revoke --environment <env> --key <n> [--json]
21
+ bb release-notes origins set --environment <env> (--origin <origin> ... | --none) [--json]
22
+
23
+ Viewer keys let your server sign short-lived viewer tokens so your own app can
24
+ show your release notes without your users signing in to BotBuddy (see
25
+ docs/release-notes/viewer-tokens.md). Tenant owners only. One key per
26
+ environment; two may be active while you rotate.
27
+
28
+ keys create writes the secret to --out (a new file, mode 0600) and never prints
29
+ it. BotBuddy cannot show it again. Move it into your server's secret store.
30
+
31
+ origins set replaces the environment's list. An entry is an exact origin or one
32
+ with a single * in the leftmost host label. http://localhost and
33
+ http://127.0.0.1 are always allowed for local and never need listing.
34
+
35
+ Exit codes: 0 done · 1 refused · 2 usage · 3 authentication · 5 BotBuddy unreachable.`;
36
+
37
+ function flags(args, { multi = [] } = {}) {
38
+ const out = { _: [] };
39
+ for (let i = 0; i < args.length; i++) {
40
+ const a = args[i];
41
+ if (a === "--json" || a === "--none") { out[a.slice(2)] = true; continue; }
42
+ if (a.startsWith("--")) {
43
+ const v = args[i + 1];
44
+ if (v === undefined || v.startsWith("--")) return null;
45
+ const k = a.slice(2);
46
+ if (multi.includes(k)) (out[k] ??= []).push(v);
47
+ else if (k in out) return null;
48
+ else out[k] = v;
49
+ i++;
50
+ continue;
51
+ }
52
+ out._.push(a);
53
+ }
54
+ return out;
55
+ }
56
+
57
+ async function run(tool, toolArgs, { resolveAuth, call }) {
58
+ try {
59
+ const resolved = await resolveAuth({ toolName: tool, preferSession: true });
60
+ if (resolved?.error || !resolved?.auth) return { ok: false, auth: true };
61
+ return await call(tool, toolArgs, { auth: resolved.auth, signal: AbortSignal.timeout(30_000) });
62
+ } catch {
63
+ return { ok: false, status: null };
64
+ }
65
+ }
66
+
67
+ // Shared failure reporting. Never echoes the answer, which may hold a secret.
68
+ function failure(result, { json, log, errorLog }) {
69
+ const data = result?.data;
70
+ if (result?.ok && data?.ok === false && typeof data.error === "string") {
71
+ const refusal = { ok: false, error: data.error, ...(data.origin ? { origin: data.origin } : {}), message: data.message ?? null };
72
+ if (json) log(JSON.stringify(refusal));
73
+ errorLog(`✗ ${refusal.error}${refusal.origin ? ` (${refusal.origin})` : ""}: ${refusal.message ?? "Refused."}`);
74
+ return CALL_EXIT.ERROR;
75
+ }
76
+ if (result?.auth) {
77
+ if (json) log(JSON.stringify({ ok: false, error: "authentication_failed" }));
78
+ errorLog("✗ BotBuddy could not authenticate this command. Run bb doctor --fix in this worktree, then retry.");
79
+ return CALL_EXIT.AUTH;
80
+ }
81
+ if (!result?.ok && result?.status == null) {
82
+ if (json) log(JSON.stringify({ ok: false, error: "transport_unavailable" }));
83
+ errorLog("✗ BotBuddy is unreachable. Retry the same command.");
84
+ return CALL_EXIT.TRANSPORT;
85
+ }
86
+ if (json) log(JSON.stringify({ ok: false, error: "receipt_unavailable" }));
87
+ errorLog("✗ BotBuddy did not confirm the command.");
88
+ return CALL_EXIT.ERROR;
89
+ }
90
+
91
+ function usage(errorLog) {
92
+ errorLog(RELEASE_NOTES_KEYS_USAGE);
93
+ return 2;
94
+ }
95
+
96
+ export async function cmdReleaseNotesKeys(args, {
97
+ resolveAuth = resolveCallAuth,
98
+ call = callToolJson,
99
+ log = console.log,
100
+ errorLog = console.error,
101
+ openFile = open,
102
+ removeFile = unlink,
103
+ } = {}) {
104
+ const f = flags(args.slice(1));
105
+ const sub = args[0];
106
+ if (!f || f._.length > 0) return usage(errorLog);
107
+ const json = f.json === true;
108
+ const deps = { resolveAuth, call };
109
+
110
+ if (sub === "create") {
111
+ if (!ENVIRONMENTS.includes(f.environment) || !f.out || Object.keys(f).some((k) => !["_", "json", "environment", "out"].includes(k))) return usage(errorLog);
112
+ let handle;
113
+ try {
114
+ handle = await openFile(f.out, "wx", 0o600);
115
+ } catch (e) {
116
+ errorLog(e?.code === "EEXIST"
117
+ ? `✗ ${f.out} already exists; choose a new file so no key is overwritten. Nothing was created.`
118
+ : `✗ Could not create ${f.out} (${e?.code ?? "error"}). Nothing was created.`);
119
+ return 2;
120
+ }
121
+ let written = false;
122
+ try {
123
+ const result = await run("create_release_note_viewer_key", { environment: f.environment }, deps);
124
+ const data = result?.data;
125
+ if (result?.ok && data?.ok === true && typeof data.secret === "string" && /^[0-9a-f]{64}$/.test(data.secret)) {
126
+ await handle.writeFile(`${data.secret}\n`, "utf8");
127
+ await handle.chmod(0o600);
128
+ written = true;
129
+ const receipt = { ok: true, kid: data.kid, tenant: data.tenant, environment: data.environment, key_number: data.key_number, created_at: data.created_at, out: f.out };
130
+ if (json) log(JSON.stringify(receipt));
131
+ else log(`Created viewer key ${receipt.kid}. The secret is in ${f.out} (mode 0600); BotBuddy cannot show it again. Move it to your server's secret store for ${receipt.environment}, then delete the file.`);
132
+ return CALL_EXIT.OK;
133
+ }
134
+ return failure(result?.ok && data?.ok === true ? { ok: true, data: {} } : result, { json, log, errorLog });
135
+ } finally {
136
+ await handle.close();
137
+ if (!written) await removeFile(f.out).catch(() => {});
138
+ }
139
+ }
140
+
141
+ if (sub === "list") {
142
+ if (Object.keys(f).some((k) => !["_", "json"].includes(k))) return usage(errorLog);
143
+ const result = await run("list_release_note_viewer_keys", {}, deps);
144
+ const data = result?.data;
145
+ if (!(result?.ok && data?.ok === true && Array.isArray(data.keys))) return failure(result, { json, log, errorLog });
146
+ const keys = data.keys.map((k) => ({ kid: `${data.tenant}:${k.environment}:${k.key_number}`, environment: k.environment, key_number: k.key_number, created_at: k.created_at, revoked_at: k.revoked_at ?? null }));
147
+ const origins = data.origins && typeof data.origins === "object" ? data.origins : {};
148
+ if (json) {
149
+ log(JSON.stringify({ ok: true, tenant: data.tenant, keys, origins }));
150
+ return CALL_EXIT.OK;
151
+ }
152
+ if (keys.length === 0) log(`No viewer keys for ${data.tenant}.`);
153
+ for (const k of keys) log(`${k.kid.padEnd(40)} ${k.revoked_at ? `revoked ${k.revoked_at}` : "active"} created ${k.created_at}`);
154
+ for (const env of ENVIRONMENTS) {
155
+ if (Array.isArray(origins[env])) log(`origins ${env}: ${origins[env].length ? origins[env].join(" ") : "(none)"}`);
156
+ }
157
+ return CALL_EXIT.OK;
158
+ }
159
+
160
+ if (sub === "revoke") {
161
+ const n = Number(f.key);
162
+ if (!ENVIRONMENTS.includes(f.environment) || !/^[1-9][0-9]*$/.test(f.key ?? "") || Object.keys(f).some((k) => !["_", "json", "environment", "key"].includes(k))) return usage(errorLog);
163
+ const result = await run("revoke_release_note_viewer_key", { environment: f.environment, key_number: n }, deps);
164
+ const data = result?.data;
165
+ if (!(result?.ok && data?.ok === true)) return failure(result, { json, log, errorLog });
166
+ const receipt = { ok: true, kid: `${data.tenant}:${data.environment}:${data.key_number}`, revoked_at: data.revoked_at };
167
+ if (json) log(JSON.stringify(receipt));
168
+ else log(`Revoked viewer key ${receipt.kid}. Tokens signed with it are refused from now on.`);
169
+ return CALL_EXIT.OK;
170
+ }
171
+
172
+ return usage(errorLog);
173
+ }
174
+
175
+ export async function cmdReleaseNotesOrigins(args, {
176
+ resolveAuth = resolveCallAuth,
177
+ call = callToolJson,
178
+ log = console.log,
179
+ errorLog = console.error,
180
+ } = {}) {
181
+ const f = flags(args.slice(1), { multi: ["origin"] });
182
+ if (args[0] !== "set" || !f || f._.length > 0 || !ENVIRONMENTS.includes(f.environment)) return usage(errorLog);
183
+ if (Object.keys(f).some((k) => !["_", "json", "environment", "origin", "none"].includes(k))) return usage(errorLog);
184
+ if ((f.none === true) === Array.isArray(f.origin)) return usage(errorLog);
185
+ const json = f.json === true;
186
+ const origins = f.none ? [] : f.origin;
187
+ const result = await run("set_release_note_origins", { environment: f.environment, origins }, { resolveAuth, call });
188
+ const data = result?.data;
189
+ if (!(result?.ok && data?.ok === true)) return failure(result, { json, log, errorLog });
190
+ const receipt = { ok: true, tenant: data.tenant, environment: data.environment, origins: data.origins };
191
+ if (json) log(JSON.stringify(receipt));
192
+ else log(`Origins for ${receipt.tenant} ${receipt.environment}: ${receipt.origins.length ? receipt.origins.join(" ") : "(none — server-to-server reads only)"}.`);
193
+ return CALL_EXIT.OK;
194
+ }
@@ -5,6 +5,7 @@
5
5
  // revision, or the named refusal. The tenant is the authenticated agent's.
6
6
  import { readFile } from "node:fs/promises";
7
7
  import { CALL_EXIT, callToolJson, resolveCallAuth } from "./api.mjs";
8
+ import { cmdReleaseNotesKeys, cmdReleaseNotesOrigins, RELEASE_NOTES_KEYS_USAGE } from "./release-notes-keys.mjs";
8
9
 
9
10
  export const RELEASE_NOTES_USAGE = `Usage: bb release-notes submit <note.json> [--json]
10
11
  bb release-notes grants list [--tenant <slug>] [--json]
@@ -43,7 +44,10 @@ the effective grants and the newest changes. Grants use your own sign-in
43
44
  owner), member_not_in_tenant, owner_scope_is_implicit, scope_unknown,
44
45
  entitlement_missing.
45
46
 
46
- Exit codes: 0 stored · 1 refused · 2 usage · 3 authentication · 5 BotBuddy unreachable.`;
47
+ Exit codes: 0 stored · 1 refused · 2 usage · 3 authentication · 5 BotBuddy unreachable.
48
+
49
+ Viewer keys and origins (tenant owners, BOT-3158):
50
+ ${RELEASE_NOTES_KEYS_USAGE.split("\n").slice(1, 5).join("\n")}`;
47
51
 
48
52
  const TOOL = "submit_release_note";
49
53
 
@@ -59,6 +63,9 @@ export async function cmdReleaseNotes(args, {
59
63
  return args.length === 0 ? 2 : CALL_EXIT.OK;
60
64
  }
61
65
  if (args[0] === "grants") return cmdGrants(args.slice(1), { resolveAuth, call, log, errorLog });
66
+ // BOT-3158: viewer keys and allowed origins.
67
+ if (args[0] === "keys") return await cmdReleaseNotesKeys(args.slice(1), { resolveAuth, call, log, errorLog });
68
+ if (args[0] === "origins") return await cmdReleaseNotesOrigins(args.slice(1), { resolveAuth, call, log, errorLog });
62
69
  const json = args.includes("--json");
63
70
  const rest = args.filter((a) => a !== "--json");
64
71
  if (rest[0] !== "submit" || rest.length !== 2 || !rest[1] || rest[1].startsWith("-")) {
@@ -51,7 +51,26 @@ function stagingOf(own) {
51
51
  const st = own?.staging;
52
52
  if (!st || typeof st !== "object" || typeof st.configured !== "boolean") return null;
53
53
  const since = typeof st.open_since === "string" && Number.isFinite(Date.parse(st.open_since)) ? new Date(st.open_since).toISOString() : null;
54
- return { configured: st.configured, red: st.configured && since !== null, since: st.configured ? since : null };
54
+ const out = { configured: st.configured, red: st.configured && since !== null, since: st.configured ? since : null };
55
+ // BOT-3241: a red staging's elected release manager, linked only to a verified
56
+ // Claude Desktop session or Codex thread. null = none elected; no key = BB did
57
+ // not say (an older server, a failed read or an unsafe name): the band shows nothing.
58
+ if (out.red && "release_manager" in st) {
59
+ const rm = st.release_manager;
60
+ if (rm === null) out.release_manager = null;
61
+ else if (rm && typeof rm === "object") {
62
+ const name = safeText(rm.name, 80);
63
+ if (name) out.release_manager = { name, href: sessionHref(rm.session_href) };
64
+ }
65
+ }
66
+ return out;
67
+ }
68
+ const SESSION_HREF = [
69
+ /^claude:\/\/claude\.ai\/epitaxy\/local_[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i,
70
+ /^codex:\/\/threads\/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i,
71
+ ];
72
+ function sessionHref(v) {
73
+ return typeof v === "string" && SESSION_HREF.some((re) => re.test(v)) ? v : null;
55
74
  }
56
75
  // BOT-3212 AC-1: the session agent's active bb waits, for the band's badge; null
57
76
  // when BB did not say (no badge rather than a false "none").