@botbuddy/cli 1.120.0 → 1.120.2

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.120.0",
3
- "source_commit": "f74c27186b6b5cca981bbdef34dc0b12b0ed8beb",
4
- "source_sha256": "5f4042252d77e5d4674141b007ca2795de1746ef882706a8e4359a6457c66758",
2
+ "release_version": "1.120.2",
3
+ "source_commit": "82d0f717a329d32d9ac5f89855b023b08875ab74",
4
+ "source_sha256": "f5e9ca63bf98d3affebc1f0f22f926aedf2d09de911440618a517ac559fab1f0",
5
5
  "target": "darwin-arm64",
6
- "sha256": "9a890a6e9a6a2c9b12bea0c94af1060060318da6a85ddbf8eca41a858a9ae280"
6
+ "sha256": "eaf4b4036330d31152e92f1aed31ad501887c09ec8e737f7646d66d64f38dd89"
7
7
  }
@@ -1,7 +1,7 @@
1
1
  {
2
- "release_version": "1.120.0",
3
- "source_commit": "f74c27186b6b5cca981bbdef34dc0b12b0ed8beb",
4
- "source_sha256": "5f4042252d77e5d4674141b007ca2795de1746ef882706a8e4359a6457c66758",
2
+ "release_version": "1.120.2",
3
+ "source_commit": "82d0f717a329d32d9ac5f89855b023b08875ab74",
4
+ "source_sha256": "f5e9ca63bf98d3affebc1f0f22f926aedf2d09de911440618a517ac559fab1f0",
5
5
  "target": "linux-x64",
6
- "sha256": "05c25c0f04482e067786d4bbca3935868f8df650bf302dd6371971c6e3735911"
6
+ "sha256": "b8cf9a0afc3c72ec7facdd14e9f3944f497cd4474b5fc295e545ada2fb25a08f"
7
7
  }
@@ -1,21 +1,21 @@
1
1
  {
2
2
  "schema_version": 1,
3
- "release_version": "1.120.0",
4
- "source_commit": "f74c27186b6b5cca981bbdef34dc0b12b0ed8beb",
5
- "source_sha256": "5f4042252d77e5d4674141b007ca2795de1746ef882706a8e4359a6457c66758",
3
+ "release_version": "1.120.2",
4
+ "source_commit": "82d0f717a329d32d9ac5f89855b023b08875ab74",
5
+ "source_sha256": "f5e9ca63bf98d3affebc1f0f22f926aedf2d09de911440618a517ac559fab1f0",
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": "9a890a6e9a6a2c9b12bea0c94af1060060318da6a85ddbf8eca41a858a9ae280",
11
+ "sha256": "eaf4b4036330d31152e92f1aed31ad501887c09ec8e737f7646d66d64f38dd89",
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": "05c25c0f04482e067786d4bbca3935868f8df650bf302dd6371971c6e3735911",
18
+ "sha256": "b8cf9a0afc3c72ec7facdd14e9f3944f497cd4474b5fc295e545ada2fb25a08f",
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.120.0",
3
+ "version": "1.120.2",
4
4
  "description": "BotBuddy — Swarm coordination CLI for multi-agent workflows",
5
5
  "type": "module",
6
6
  "bin": {
package/src/api.mjs CHANGED
@@ -563,14 +563,19 @@ export async function callToolJson(toolName, args = {}, {
563
563
  // credential" — so a bad key keeps its not-authenticated / self-heal path.
564
564
  let code = null;
565
565
  let errorCode = null;
566
+ let memberships = null;
566
567
  try {
567
568
  const body = await res.json();
568
569
  const raw = body?.error?.data?.code ?? body?.error?.code ?? body?.code ?? null;
569
570
  if (typeof raw === "string" && raw && !UNAUTHENTICATED_CODES.has(raw)) code = raw;
570
571
  const typed = body?.error?.data?.error_code ?? body?.error_code ?? null;
571
572
  if (typeof typed === "string" && typed) errorCode = typed;
573
+ // BOT-3623: MCP_TENANT_PIN_REQUIRED lists the workspaces the caller may pin.
574
+ const listed = body?.error?.data?.memberships;
575
+ if (Array.isArray(listed)) memberships = listed.filter((t) => typeof t === "string" && t);
572
576
  } catch { /* opaque body */ }
573
- return { ok: false, auth: true, status: res.status, error: "unauthorized", ...(code ? { code } : {}), ...(errorCode ? { error_code: errorCode } : {}) };
577
+ return { ok: false, auth: true, status: res.status, error: "unauthorized", ...(code ? { code } : {}), ...(errorCode ? { error_code: errorCode } : {}),
578
+ ...(memberships?.length ? { memberships } : {}) };
574
579
  }
575
580
  let payload;
576
581
  try { payload = await res.json(); } catch { return { ok: false, status: res.status, error: "invalid_json" }; }
package/src/commands.mjs CHANGED
@@ -368,7 +368,7 @@ ${bold("EVIDENCE")} (${cyan("bb help evidence")})
368
368
  release-notes tags [group|add|retire|view]
369
369
  List or manage the tenant's release-note tag groups
370
370
  release-notes keys|origins Viewer keys and allowed origins for your own app (owners)
371
- report upload <file.html> --type <type> --title <title>
371
+ report upload <file.html> --type <type> --title <title> [--tenant <slug>]
372
372
  Store one HTML report for your tenant and print its BotBuddy link
373
373
  status-band install Install the bb-status band into Claude Code (bb setup does it)
374
374
  status-band read|relay The band's own reads and live wake (run by the mod)
@@ -21,6 +21,11 @@ export const HOST_CHILD_BUNDLE_MAX_BYTES = 200 * 1024 * 1024;
21
21
  /** A host run that never reports terminal is given up this long after its own runtime limit. */
22
22
  export const HOST_CHILD_WAIT_GRACE_MS = 10 * 60_000;
23
23
  export const HOST_CHILD_DEFAULT_MAX_RUNTIME_S = 3600;
24
+ /**
25
+ * BOT-3566: the control plane fails a claim its host has prepared for this long (a cold
26
+ * dependency layer keeps a claim alive with "preparing" reports up to here).
27
+ */
28
+ export const HOST_CHILD_PREPARE_CAP_MS = 45 * 60_000;
24
29
  const ENV_NAME = /^[A-Z][A-Z0-9_]{0,63}$/;
25
30
 
26
31
  /** The four requester tool calls, over the run's retrying caller. */
@@ -168,7 +173,8 @@ export async function startHostChild({
168
173
  };
169
174
  // The caller gave the run up before using it (its slot was lost): stop waiting for it.
170
175
  child.detach = () => { abort.abort("detached"); artifactsAbort.abort("detached"); };
171
- const giveUpAt = now() + (maxRuntimeSeconds * 1000) + HOST_CHILD_WAIT_GRACE_MS;
176
+ const firstGiveUpAt = now() + (maxRuntimeSeconds * 1000) + HOST_CHILD_WAIT_GRACE_MS;
177
+ let giveUpAt = firstGiveUpAt;
172
178
  const finish = (run, code) => {
173
179
  if (child.final) return;
174
180
  child.final = run;
@@ -206,6 +212,11 @@ export async function startHostChild({
206
212
  // The cursor is read with the state, so a change after this read replays into the wait.
207
213
  if (run && Number.isSafeInteger(Number(run.signal_cursor))) since = Number(run.signal_cursor);
208
214
  if (stopWanted) requestCancel();
215
+ // BOT-3566: a run that started late (a cold dependency layer) gets its runtime from its
216
+ // start, replacing any preparation allowance (Codex #2019); one still being prepared
217
+ // gets the control plane's preparation cap once the first deadline passes.
218
+ if (run?.state === "running") giveUpAt = Math.max(firstGiveUpAt, hostRunGiveUpAt(run, maxRuntimeSeconds));
219
+ else if (now() >= giveUpAt) giveUpAt = Math.max(giveUpAt, hostRunGiveUpAt(run, maxRuntimeSeconds));
209
220
  if (now() >= giveUpAt) {
210
221
  child.stop();
211
222
  return finish({ ...(run ?? {}), state: "failed", failure_code: "HOST_CHILD_UNREPORTED", failure_message: "the host never reported the run's end" }, 1);
@@ -233,6 +244,16 @@ export async function startHostChild({
233
244
  return { ok: true, child, runId };
234
245
  }
235
246
 
247
+ /** When a non-terminal host run may be given up, from what the control plane says of it. */
248
+ export function hostRunGiveUpAt(run, maxRuntimeSeconds) {
249
+ const budget = maxRuntimeSeconds * 1000 + HOST_CHILD_WAIT_GRACE_MS;
250
+ const started = Date.parse(run?.started_at ?? "");
251
+ if (run?.state === "running" && Number.isFinite(started)) return started + budget;
252
+ const claimed = Date.parse(run?.claimed_at ?? "");
253
+ if (run?.state === "claimed" && Number.isFinite(claimed)) return claimed + HOST_CHILD_PREPARE_CAP_MS + budget;
254
+ return -Infinity;
255
+ }
256
+
236
257
  /** Receipt fields for a host run. */
237
258
  export function hostChildReceiptFields(child) {
238
259
  if (!child?.hostRun) return {};
package/src/report.mjs CHANGED
@@ -7,7 +7,8 @@
7
7
  // finalize_report_upload has the server read the stored bytes back and check
8
8
  // their size, sha256 and HTML shape. The server is the only validator; the CLI
9
9
  // measures the file and prints the receipt or the named refusal with its limit
10
- // and fix. The tenant is the authenticated agent's, never a flag.
10
+ // and fix. The tenant is the authenticated credential's; a user login that
11
+ // reaches several workspaces pins one with --tenant (BOT-3623).
11
12
  import { createHash } from "node:crypto";
12
13
  import { execFileSync } from "node:child_process";
13
14
  import { readFile } from "node:fs/promises";
@@ -20,7 +21,7 @@ const LIMIT_LINE = `Limit: one HTML file (.html or .htm, UTF-8, with a <title> o
20
21
 
21
22
  export const REPORT_USAGE = `Usage: bb report upload <file.html> --type <type> --title <title>
22
23
  [--source-key <key>] [--ticket <KEY>]... [--pr <n>]... [--release <tag>]...
23
- [--repository <owner/name>] [--json]
24
+ [--repository <owner/name>] [--tenant <slug>] [--json]
24
25
 
25
26
  Stores one HTML report in your tenant's private report store and prints its
26
27
  link, <app>/reports/stored/<id>, where a member of your tenant opens it.
@@ -32,6 +33,9 @@ link, <app>/reports/stored/<id>, where a member of your tenant opens it.
32
33
  --pr a pull request number (repeatable); its repository is
33
34
  --repository, or this checkout's origin remote
34
35
  --release a release tag (repeatable)
36
+ --tenant the workspace to store the report in, when your bb login
37
+ reaches more than one (default: BOTBUDDY_TENANT, then the
38
+ repo's .botbuddy-agent.json, then your only workspace)
35
39
  --json print the receipt or refusal as JSON
36
40
 
37
41
  ${LIMIT_LINE}
@@ -44,7 +48,8 @@ Example:
44
48
 
45
49
  Refusals (exit 1, nothing stored): report_not_html, report_too_large,
46
50
  report_type_unknown, report_digest_mismatch, scope_missing (the key needs the
47
- write scope, or a tenant owner). Uploading needs an agent key with the write
51
+ write scope, or a tenant owner). MCP_TENANT_PIN_REQUIRED (exit 3): your login
52
+ reaches several workspaces; retry with --tenant <slug>. Uploading needs an agent key with the write
48
53
  scope (bb login --tenant, then bb mcp setup). Guide: docs/stored-reports.md.`;
49
54
 
50
55
  const BEGIN = "begin_report_upload";
@@ -64,7 +69,9 @@ function defaultGit(cwd, args) {
64
69
  }
65
70
  }
66
71
 
67
- const VALUE_FLAGS = new Set(["--type", "--title", "--source-key", "--ticket", "--pr", "--release", "--repository"]);
72
+ const VALUE_FLAGS = new Set(["--type", "--title", "--source-key", "--ticket", "--pr", "--release", "--repository", "--tenant"]);
73
+ // Same slug shape the server accepts on ?tenant= (api.mjs TENANT_PIN_RE).
74
+ const TENANT_SLUG_RE = /^[a-z0-9][a-z0-9-]{0,63}$/;
68
75
  const REPEATABLE = new Set(["--ticket", "--pr", "--release"]);
69
76
 
70
77
  export function parseUploadArgs(argv) {
@@ -88,6 +95,7 @@ export function parseUploadArgs(argv) {
88
95
  out.file = a;
89
96
  }
90
97
  if (!out.file) return { error: "Name the HTML file to upload." };
98
+ if (out.tenant !== undefined && !TENANT_SLUG_RE.test(out.tenant)) return { error: "--tenant must be a lowercase workspace slug, for example botbuddy." };
91
99
  return out;
92
100
  }
93
101
 
@@ -95,11 +103,13 @@ function sha256Hex(bytes) {
95
103
  return createHash("sha256").update(bytes).digest("hex");
96
104
  }
97
105
 
98
- async function callTool(tool, args, { resolveAuth, call }) {
106
+ async function callTool(tool, args, { resolveAuth, call, tenant }) {
99
107
  try {
100
108
  const resolved = await resolveAuth({ toolName: tool, preferSession: true });
101
109
  if (resolved?.error || !resolved?.auth) return { ok: false, auth: true };
102
- return await call(tool, args, { auth: resolved.auth, signal: AbortSignal.timeout(60_000) });
110
+ // BOT-3623: only an explicit --tenant is passed; otherwise callToolJson
111
+ // derives the pin exactly as before (BOTBUDDY_TENANT, binding, sole tenant).
112
+ return await call(tool, args, { auth: resolved.auth, ...(tenant ? { tenant } : {}), signal: AbortSignal.timeout(60_000) });
103
113
  } catch {
104
114
  return { ok: false, status: null };
105
115
  }
@@ -121,7 +131,28 @@ function printRefusal(data, { json, log, errorLog }) {
121
131
  return CALL_EXIT.ERROR;
122
132
  }
123
133
 
124
- function printTransport(result, what, { json, log, errorLog }) {
134
+ /** One argv word as the shell needs it to round-trip. */
135
+ function shellWord(word) {
136
+ return /^[A-Za-z0-9_\-./:=@%+,]+$/.test(word) ? word : `'${word.replace(/'/g, "'\\''")}'`;
137
+ }
138
+
139
+ function printTransport(result, what, { json, log, errorLog, argv, tenant }) {
140
+ // BOT-3623: a typed tenant refusal is not a dead credential. Name the
141
+ // server's code; for a missing pin, list the workspaces and the retry.
142
+ const tenantCode = result?.auth && typeof result.code === "string" && result.code.startsWith("MCP_TENANT_") ? result.code : null;
143
+ if (tenantCode === "MCP_TENANT_PIN_REQUIRED") {
144
+ const memberships = Array.isArray(result.memberships) ? result.memberships : [];
145
+ if (json) log(JSON.stringify({ ok: false, error: tenantCode, ...(memberships.length ? { memberships } : {}) }));
146
+ errorLog(`✗ ${tenantCode}: your bb login reaches more than one workspace, so this upload must name one. Nothing was stored.`);
147
+ if (memberships.length) errorLog(`Your workspaces: ${memberships.join(", ")}.`);
148
+ errorLog(`Retry: bb report upload ${argv.map(shellWord).join(" ")} --tenant <slug>`);
149
+ return CALL_EXIT.AUTH;
150
+ }
151
+ if (tenantCode) {
152
+ if (json) log(JSON.stringify({ ok: false, error: tenantCode, ...(tenant ? { tenant } : {}) }));
153
+ errorLog(`✗ ${tenantCode}: BotBuddy refused ${tenant ? `workspace ${tenant}` : "the workspace"} for this credential. Nothing was stored.`);
154
+ return CALL_EXIT.AUTH;
155
+ }
125
156
  if (result?.auth) {
126
157
  if (json) log(JSON.stringify({ ok: false, error: "authentication_failed" }));
127
158
  errorLog("✗ BotBuddy could not authenticate this command. Run bb doctor --fix in this worktree (or bb login --tenant <slug>, then bb mcp setup), then retry. Nothing was stored.");
@@ -138,6 +169,7 @@ export async function cmdReport(args, {
138
169
  call = callToolJson,
139
170
  fetchImpl = fetch,
140
171
  git = defaultGit,
172
+ env = process.env,
141
173
  cwd = process.cwd(),
142
174
  log = console.log,
143
175
  errorLog = console.error,
@@ -160,7 +192,10 @@ export async function cmdReport(args, {
160
192
  return 2;
161
193
  }
162
194
  const { json } = parsed;
163
- const out = { json, log, errorLog };
195
+ const tenant = parsed.tenant ?? null;
196
+ const out = { json, log, errorLog, argv: args.slice(1), tenant };
197
+ const envTenant = typeof env.BOTBUDDY_TENANT === "string" ? env.BOTBUDDY_TENANT.trim() : "";
198
+ if (tenant && envTenant && envTenant !== tenant) errorLog(`--tenant ${tenant} overrides BOTBUDDY_TENANT=${envTenant} for this upload.`);
164
199
 
165
200
  let bytes;
166
201
  try {
@@ -192,7 +227,7 @@ export async function cmdReport(args, {
192
227
  ...(parsed.source_key ? { source_key: parsed.source_key } : {}),
193
228
  ...(links.length ? { links } : {}),
194
229
  route: "cli",
195
- }, { resolveAuth, call });
230
+ }, { resolveAuth, call, tenant });
196
231
  const b = begin?.data;
197
232
  if (begin?.ok && b?.ok === false && typeof b.error === "string") return printRefusal(b, out);
198
233
  if (!begin?.ok || b?.ok !== true || typeof b.report_id !== "string" || typeof b.upload?.url !== "string") {
@@ -220,7 +255,7 @@ export async function cmdReport(args, {
220
255
  return CALL_EXIT.ERROR;
221
256
  }
222
257
 
223
- const fin = await callTool(FINALIZE, { report_id: b.report_id, route: "cli" }, { resolveAuth, call });
258
+ const fin = await callTool(FINALIZE, { report_id: b.report_id, route: "cli" }, { resolveAuth, call, tenant });
224
259
  const f = fin?.data;
225
260
  if (fin?.ok && f?.ok === false && typeof f.error === "string") return printRefusal(f, out);
226
261
  if (!fin?.ok || f?.ok !== true || typeof f.url !== "string") {