@botbuddy/cli 1.119.0 → 1.120.1
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 +4 -0
- package/daemon/bin/darwin-arm64/botbuddy-daemon +0 -0
- package/daemon/bin/linux-x64/botbuddy-daemon +0 -0
- package/daemon-release/darwin-arm64.json +4 -4
- package/daemon-release/linux-x64.json +4 -4
- package/daemon-release/manifest.json +5 -5
- package/package.json +1 -1
- package/src/api.mjs +6 -1
- package/src/commands.mjs +6 -1
- package/src/report.mjs +283 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 1.120.0
|
|
4
|
+
|
|
5
|
+
- BOT-3569: `bb report upload <file.html> --type <type> --title <title>` stores one HTML report (at most 5,242,880 bytes) in your tenant's private report store and prints its BotBuddy link, `<app>/reports/stored/<id>`, with the report id and the file's sha256. It calls the MCP tool `begin_report_upload`, PUTs the bytes straight to Storage through the one signed URL it returns, then `finalize_report_upload`, which reads the stored bytes back and checks size, sha256 and HTML shape. `--ticket`, `--pr` (repository from `--repository` or the origin remote) and `--release` link the report; `--source-key` and `--json` as usual. A refusal (`report_not_html`, `report_too_large`, `report_type_unknown`, `report_digest_mismatch`, `scope_missing`) exits 1 and prints the code, the limit and the fix. Needs MCP 2.163.0.
|
|
6
|
+
|
|
3
7
|
## 1.119.0
|
|
4
8
|
|
|
5
9
|
- BOT-3529: a host child layer's system packages keep their symlinks as the package ships them. The layer build unpacked each `.deb` with `cpio --no-absolute-filenames`, which also strips a leading `../` from link targets, so `/usr/bin/psql -> ../share/postgresql-common/pg_wrapper` dangled and a child could not run `psql`. The fleet host daemon now unpacks each package itself (its binary is bound read-only into the build unit): link targets are kept verbatim, and an absolute or `..` member name, a hard link to anything outside the package, a relative symlink that resolves outside the layer, and a member written through a symlink are refused with `CHILD_LAYER_SYSTEM_PACKAGE_UNPACK_FAILED`.
|
|
Binary file
|
|
Binary file
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
|
-
"release_version": "1.
|
|
3
|
-
"source_commit": "
|
|
4
|
-
"source_sha256": "
|
|
2
|
+
"release_version": "1.120.1",
|
|
3
|
+
"source_commit": "78dbebfd7f66398ce2634866f072fcd0fd161966",
|
|
4
|
+
"source_sha256": "811b47307808f5241690820947dca0ab05a66aae759b1f79a817f06a44d562c2",
|
|
5
5
|
"target": "darwin-arm64",
|
|
6
|
-
"sha256": "
|
|
6
|
+
"sha256": "854da93c46032385536144538e658ad57493cb14417559d6f8d826d8e0de71aa"
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
|
-
"release_version": "1.
|
|
3
|
-
"source_commit": "
|
|
4
|
-
"source_sha256": "
|
|
2
|
+
"release_version": "1.120.1",
|
|
3
|
+
"source_commit": "78dbebfd7f66398ce2634866f072fcd0fd161966",
|
|
4
|
+
"source_sha256": "811b47307808f5241690820947dca0ab05a66aae759b1f79a817f06a44d562c2",
|
|
5
5
|
"target": "linux-x64",
|
|
6
|
-
"sha256": "
|
|
6
|
+
"sha256": "f7ee959017b284cfa6571df43564d3262e8ac12d556fed9af7fe62622d4ac803"
|
|
7
7
|
}
|
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"schema_version": 1,
|
|
3
|
-
"release_version": "1.
|
|
4
|
-
"source_commit": "
|
|
5
|
-
"source_sha256": "
|
|
3
|
+
"release_version": "1.120.1",
|
|
4
|
+
"source_commit": "78dbebfd7f66398ce2634866f072fcd0fd161966",
|
|
5
|
+
"source_sha256": "811b47307808f5241690820947dca0ab05a66aae759b1f79a817f06a44d562c2",
|
|
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": "
|
|
11
|
+
"sha256": "854da93c46032385536144538e658ad57493cb14417559d6f8d826d8e0de71aa",
|
|
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": "
|
|
18
|
+
"sha256": "f7ee959017b284cfa6571df43564d3262e8ac12d556fed9af7fe62622d4ac803",
|
|
19
19
|
"mode": "0755"
|
|
20
20
|
}
|
|
21
21
|
}
|
package/package.json
CHANGED
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
|
@@ -21,6 +21,7 @@ import { cmdTest } from "./test-lane.mjs";
|
|
|
21
21
|
import { cmdEvidence } from "./evidence.mjs";
|
|
22
22
|
import { cmdFeedback } from "./feedback.mjs";
|
|
23
23
|
import { cmdReleaseNotes } from "./release-notes.mjs";
|
|
24
|
+
import { cmdReport } from "./report.mjs";
|
|
24
25
|
import { cmdStatusBand, installStatusBand, statusBandLine } from "./status-band.mjs";
|
|
25
26
|
import { runWait } from "./wait.mjs";
|
|
26
27
|
import { SETUP_BLOCK } from "./setup-block.mjs";
|
|
@@ -67,7 +68,7 @@ export function shouldCheckForUpdates(argv) {
|
|
|
67
68
|
export const LOCAL_HELP_COMMANDS = Object.freeze([
|
|
68
69
|
"wait", "stack", "pw", "docker", "run", "mcp", "login", "setup", "doctor", "host",
|
|
69
70
|
"staging-pool", "daemon", "evidence", "feedback", "usage", "telemetry", "allocation",
|
|
70
|
-
"release-notes", "status-band", "push",
|
|
71
|
+
"release-notes", "report", "status-band", "push",
|
|
71
72
|
]);
|
|
72
73
|
const HELP_WORDS = new Set(["help", "--help", "-h"]);
|
|
73
74
|
|
|
@@ -163,6 +164,8 @@ export async function run(argv, {
|
|
|
163
164
|
case "feedback": return cmdFeedback(args);
|
|
164
165
|
// BOT-3156: governed release notes (submit one note through submit_release_note).
|
|
165
166
|
case "release-notes": return cmdReleaseNotes(args);
|
|
167
|
+
// BOT-3569: store one HTML report in the tenant report store.
|
|
168
|
+
case "report": return cmdReport(args);
|
|
166
169
|
// BOT-3152: the bb-status band's host side (read/relay) and its Claude Code install.
|
|
167
170
|
case "status-band": return cmdStatusBand(args);
|
|
168
171
|
case "test-ingest": return cmdTestIngest(args);
|
|
@@ -365,6 +368,8 @@ ${bold("EVIDENCE")} (${cyan("bb help evidence")})
|
|
|
365
368
|
release-notes tags [group|add|retire|view]
|
|
366
369
|
List or manage the tenant's release-note tag groups
|
|
367
370
|
release-notes keys|origins Viewer keys and allowed origins for your own app (owners)
|
|
371
|
+
report upload <file.html> --type <type> --title <title> [--tenant <slug>]
|
|
372
|
+
Store one HTML report for your tenant and print its BotBuddy link
|
|
368
373
|
status-band install Install the bb-status band into Claude Code (bb setup does it)
|
|
369
374
|
status-band read|relay The band's own reads and live wake (run by the mod)
|
|
370
375
|
evidence require <file> Record an exact-head evidence disposition → botbuddy/ready
|
package/src/report.mjs
ADDED
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
// BOT-3569: `bb report upload <file.html>` — store one HTML report in the
|
|
2
|
+
// tenant's private report store and print its BotBuddy link.
|
|
3
|
+
//
|
|
4
|
+
// The CLI is a client of the MCP tools (ADR 2026-11-20): begin_report_upload
|
|
5
|
+
// records the pending report and returns one signed PUT URL, the CLI PUTs the
|
|
6
|
+
// file's bytes straight to Storage (they never pass through a function), and
|
|
7
|
+
// finalize_report_upload has the server read the stored bytes back and check
|
|
8
|
+
// their size, sha256 and HTML shape. The server is the only validator; the CLI
|
|
9
|
+
// measures the file and prints the receipt or the named refusal with its limit
|
|
10
|
+
// and fix. The tenant is the authenticated credential's; a user login that
|
|
11
|
+
// reaches several workspaces pins one with --tenant (BOT-3623).
|
|
12
|
+
import { createHash } from "node:crypto";
|
|
13
|
+
import { execFileSync } from "node:child_process";
|
|
14
|
+
import { readFile } from "node:fs/promises";
|
|
15
|
+
import { basename } from "node:path";
|
|
16
|
+
import { CALL_EXIT, callToolJson, resolveCallAuth } from "./api.mjs";
|
|
17
|
+
|
|
18
|
+
export const REPORT_TYPES = Object.freeze(["sg_analysis", "architecture", "impact", "release_tour"]);
|
|
19
|
+
export const REPORT_LIMIT_BYTES = 5_242_880;
|
|
20
|
+
const LIMIT_LINE = `Limit: one HTML file (.html or .htm, UTF-8, with a <title> or a body), at most ${REPORT_LIMIT_BYTES.toLocaleString("en-US")} bytes (5 MB).`;
|
|
21
|
+
|
|
22
|
+
export const REPORT_USAGE = `Usage: bb report upload <file.html> --type <type> --title <title>
|
|
23
|
+
[--source-key <key>] [--ticket <KEY>]... [--pr <n>]... [--release <tag>]...
|
|
24
|
+
[--repository <owner/name>] [--tenant <slug>] [--json]
|
|
25
|
+
|
|
26
|
+
Stores one HTML report in your tenant's private report store and prints its
|
|
27
|
+
link, <app>/reports/stored/<id>, where a member of your tenant opens it.
|
|
28
|
+
|
|
29
|
+
--type sg_analysis | architecture | impact | release_tour
|
|
30
|
+
--title the report's title (1–200 characters)
|
|
31
|
+
--source-key optional stable key (for example the ticket the report is about)
|
|
32
|
+
--ticket a ticket the report belongs to (repeatable)
|
|
33
|
+
--pr a pull request number (repeatable); its repository is
|
|
34
|
+
--repository, or this checkout's origin remote
|
|
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)
|
|
39
|
+
--json print the receipt or refusal as JSON
|
|
40
|
+
|
|
41
|
+
${LIMIT_LINE}
|
|
42
|
+
The viewer runs no script and loads nothing from outside the file: inline
|
|
43
|
+
images, fonts and styles as data: URLs. Links open in a new tab.
|
|
44
|
+
|
|
45
|
+
Example:
|
|
46
|
+
bb report upload docs/analysis/stored-reports.html --type sg_analysis \\
|
|
47
|
+
--title "Stored reports analysis" --ticket BOT-3569 --pr 1999
|
|
48
|
+
|
|
49
|
+
Refusals (exit 1, nothing stored): report_not_html, report_too_large,
|
|
50
|
+
report_type_unknown, report_digest_mismatch, scope_missing (the key needs the
|
|
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
|
|
53
|
+
scope (bb login --tenant, then bb mcp setup). Guide: docs/stored-reports.md.`;
|
|
54
|
+
|
|
55
|
+
const BEGIN = "begin_report_upload";
|
|
56
|
+
const FINALIZE = "finalize_report_upload";
|
|
57
|
+
|
|
58
|
+
/** owner/name of this checkout's origin remote, or null. */
|
|
59
|
+
export function originRepository({ cwd = process.cwd(), git = defaultGit } = {}) {
|
|
60
|
+
const remote = git(cwd, ["remote", "get-url", "origin"]);
|
|
61
|
+
return remote?.match(/github\.com[:/]([^/\s]+\/[^/\s]+?)(?:\.git)?\/?$/i)?.[1]?.toLowerCase() ?? null;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function defaultGit(cwd, args) {
|
|
65
|
+
try {
|
|
66
|
+
return execFileSync("git", args, { cwd, encoding: "utf8", stdio: ["ignore", "pipe", "ignore"], timeout: 5_000 }).trim() || null;
|
|
67
|
+
} catch {
|
|
68
|
+
return null;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
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}$/;
|
|
75
|
+
const REPEATABLE = new Set(["--ticket", "--pr", "--release"]);
|
|
76
|
+
|
|
77
|
+
export function parseUploadArgs(argv) {
|
|
78
|
+
const out = { file: null, json: false, ticket: [], pr: [], release: [] };
|
|
79
|
+
for (let i = 0; i < argv.length; i += 1) {
|
|
80
|
+
const a = argv[i];
|
|
81
|
+
if (a === "--json") { out.json = true; continue; }
|
|
82
|
+
const eq = a.startsWith("--") ? a.indexOf("=") : -1;
|
|
83
|
+
const flag = eq > 0 ? a.slice(0, eq) : a;
|
|
84
|
+
if (VALUE_FLAGS.has(flag)) {
|
|
85
|
+
const value = eq > 0 ? a.slice(eq + 1) : argv[++i];
|
|
86
|
+
if (value === undefined || value === "" || (eq < 0 && value.startsWith("--"))) return { error: `${flag} needs a value.` };
|
|
87
|
+
const key = flag.slice(2).replace("-", "_");
|
|
88
|
+
if (REPEATABLE.has(flag)) out[key].push(value);
|
|
89
|
+
else if (out[key] !== undefined) return { error: `${flag} was given twice.` };
|
|
90
|
+
else out[key] = value;
|
|
91
|
+
continue;
|
|
92
|
+
}
|
|
93
|
+
if (a.startsWith("-")) return { error: `Unknown option ${a}.` };
|
|
94
|
+
if (out.file) return { error: "Upload one file at a time." };
|
|
95
|
+
out.file = a;
|
|
96
|
+
}
|
|
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." };
|
|
99
|
+
return out;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function sha256Hex(bytes) {
|
|
103
|
+
return createHash("sha256").update(bytes).digest("hex");
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
async function callTool(tool, args, { resolveAuth, call, tenant }) {
|
|
107
|
+
try {
|
|
108
|
+
const resolved = await resolveAuth({ toolName: tool, preferSession: true });
|
|
109
|
+
if (resolved?.error || !resolved?.auth) return { ok: false, auth: true };
|
|
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) });
|
|
113
|
+
} catch {
|
|
114
|
+
return { ok: false, status: null };
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function printRefusal(data, { json, log, errorLog }) {
|
|
119
|
+
const refusal = {
|
|
120
|
+
ok: false,
|
|
121
|
+
error: data.error,
|
|
122
|
+
message: data.message ?? null,
|
|
123
|
+
...(data.field ? { field: data.field } : {}),
|
|
124
|
+
limit_bytes: data.limit_bytes ?? REPORT_LIMIT_BYTES,
|
|
125
|
+
...(data.fix ? { fix: data.fix } : {}),
|
|
126
|
+
};
|
|
127
|
+
if (json) log(JSON.stringify(refusal));
|
|
128
|
+
errorLog(`✗ ${refusal.error}${refusal.field ? ` (${refusal.field})` : ""}: ${refusal.message ?? "Nothing was stored."}`);
|
|
129
|
+
errorLog(LIMIT_LINE);
|
|
130
|
+
if (refusal.fix) errorLog(`Fix: ${refusal.fix}`);
|
|
131
|
+
return CALL_EXIT.ERROR;
|
|
132
|
+
}
|
|
133
|
+
|
|
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
|
+
}
|
|
156
|
+
if (result?.auth) {
|
|
157
|
+
if (json) log(JSON.stringify({ ok: false, error: "authentication_failed" }));
|
|
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.");
|
|
159
|
+
return CALL_EXIT.AUTH;
|
|
160
|
+
}
|
|
161
|
+
if (json) log(JSON.stringify({ ok: false, error: "transport_unavailable" }));
|
|
162
|
+
errorLog(`✗ BotBuddy did not answer ${what}. Retry the same command; nothing was stored.`);
|
|
163
|
+
return CALL_EXIT.TRANSPORT;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
export async function cmdReport(args, {
|
|
167
|
+
read = readFile,
|
|
168
|
+
resolveAuth = resolveCallAuth,
|
|
169
|
+
call = callToolJson,
|
|
170
|
+
fetchImpl = fetch,
|
|
171
|
+
git = defaultGit,
|
|
172
|
+
env = process.env,
|
|
173
|
+
cwd = process.cwd(),
|
|
174
|
+
log = console.log,
|
|
175
|
+
errorLog = console.error,
|
|
176
|
+
} = {}) {
|
|
177
|
+
if (args.length === 0 || ["help", "--help", "-h"].includes(args[0])) {
|
|
178
|
+
(args.length === 0 ? errorLog : log)(REPORT_USAGE);
|
|
179
|
+
return args.length === 0 ? 2 : CALL_EXIT.OK;
|
|
180
|
+
}
|
|
181
|
+
if (args[0] !== "upload") {
|
|
182
|
+
errorLog(`Unknown report command ${args[0]}.\n\n${REPORT_USAGE}`);
|
|
183
|
+
return 2;
|
|
184
|
+
}
|
|
185
|
+
if (args.slice(1).some((a) => ["help", "--help", "-h"].includes(a))) {
|
|
186
|
+
log(REPORT_USAGE);
|
|
187
|
+
return CALL_EXIT.OK;
|
|
188
|
+
}
|
|
189
|
+
const parsed = parseUploadArgs(args.slice(1));
|
|
190
|
+
if (parsed.error) {
|
|
191
|
+
errorLog(`${parsed.error}\n\n${REPORT_USAGE}`);
|
|
192
|
+
return 2;
|
|
193
|
+
}
|
|
194
|
+
const { json } = parsed;
|
|
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.`);
|
|
199
|
+
|
|
200
|
+
let bytes;
|
|
201
|
+
try {
|
|
202
|
+
bytes = await read(parsed.file);
|
|
203
|
+
} catch {
|
|
204
|
+
errorLog(`Could not read ${parsed.file}; nothing was stored.`);
|
|
205
|
+
return 2;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
const links = [
|
|
209
|
+
...parsed.ticket.map((ref) => ({ kind: "ticket", ref })),
|
|
210
|
+
...parsed.release.map((ref) => ({ kind: "release", ref })),
|
|
211
|
+
];
|
|
212
|
+
if (parsed.pr.length) {
|
|
213
|
+
const repository = parsed.repository ?? originRepository({ cwd, git });
|
|
214
|
+
if (!repository) {
|
|
215
|
+
errorLog("--pr needs a repository: pass --repository <owner/name>, or run from a checkout whose origin is on GitHub. Nothing was stored.");
|
|
216
|
+
return 2;
|
|
217
|
+
}
|
|
218
|
+
for (const ref of parsed.pr) links.push({ kind: "pr", ref: ref.replace(/^#/, ""), repository });
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
const begin = await callTool(BEGIN, {
|
|
222
|
+
filename: basename(parsed.file),
|
|
223
|
+
type: parsed.type ?? "",
|
|
224
|
+
title: parsed.title ?? "",
|
|
225
|
+
size_bytes: bytes.length,
|
|
226
|
+
sha256: sha256Hex(bytes),
|
|
227
|
+
...(parsed.source_key ? { source_key: parsed.source_key } : {}),
|
|
228
|
+
...(links.length ? { links } : {}),
|
|
229
|
+
route: "cli",
|
|
230
|
+
}, { resolveAuth, call, tenant });
|
|
231
|
+
const b = begin?.data;
|
|
232
|
+
if (begin?.ok && b?.ok === false && typeof b.error === "string") return printRefusal(b, out);
|
|
233
|
+
if (!begin?.ok || b?.ok !== true || typeof b.report_id !== "string" || typeof b.upload?.url !== "string") {
|
|
234
|
+
return printTransport(begin, "the upload start", out);
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
let put;
|
|
238
|
+
try {
|
|
239
|
+
put = await fetchImpl(b.upload.url, {
|
|
240
|
+
method: "PUT",
|
|
241
|
+
headers: { "content-type": "text/html", "x-upsert": "false" },
|
|
242
|
+
body: bytes,
|
|
243
|
+
signal: AbortSignal.timeout(120_000),
|
|
244
|
+
});
|
|
245
|
+
} catch (err) {
|
|
246
|
+
if (json) log(JSON.stringify({ ok: false, error: "upload_failed", report_id: b.report_id }));
|
|
247
|
+
errorLog(`✗ The upload did not reach storage (${err?.message ?? err}). Retry the same command; the unused pending upload is removed after 6 hours.`);
|
|
248
|
+
return CALL_EXIT.TRANSPORT;
|
|
249
|
+
}
|
|
250
|
+
if (!put.ok) {
|
|
251
|
+
const detail = (await put.text().catch(() => "")).slice(0, 300);
|
|
252
|
+
if (json) log(JSON.stringify({ ok: false, error: "upload_failed", status: put.status, report_id: b.report_id }));
|
|
253
|
+
errorLog(`✗ Storage refused the upload (HTTP ${put.status}${detail ? `: ${detail}` : ""}). Nothing was stored.`);
|
|
254
|
+
errorLog(LIMIT_LINE);
|
|
255
|
+
return CALL_EXIT.ERROR;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
const fin = await callTool(FINALIZE, { report_id: b.report_id, route: "cli" }, { resolveAuth, call, tenant });
|
|
259
|
+
const f = fin?.data;
|
|
260
|
+
if (fin?.ok && f?.ok === false && typeof f.error === "string") return printRefusal(f, out);
|
|
261
|
+
if (!fin?.ok || f?.ok !== true || typeof f.url !== "string") {
|
|
262
|
+
return printTransport(fin, `the finalize of report ${b.report_id} (retry: bb call finalize_report_upload --json '{"report_id":"${b.report_id}"}')`, out);
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
const receipt = {
|
|
266
|
+
ok: true,
|
|
267
|
+
report_id: f.report_id,
|
|
268
|
+
tenant: f.tenant,
|
|
269
|
+
type: f.type,
|
|
270
|
+
title: f.title,
|
|
271
|
+
size_bytes: f.size_bytes,
|
|
272
|
+
sha256: f.sha256,
|
|
273
|
+
revision: f.revision,
|
|
274
|
+
links: Array.isArray(f.links) ? f.links : [],
|
|
275
|
+
url: f.url,
|
|
276
|
+
};
|
|
277
|
+
if (json) log(JSON.stringify(receipt));
|
|
278
|
+
else {
|
|
279
|
+
log(`Stored report ${receipt.report_id} in ${receipt.tenant}: ${receipt.title} (${receipt.type}, ${Number(receipt.size_bytes).toLocaleString("en-US")} bytes, sha256 ${receipt.sha256}).`);
|
|
280
|
+
log(receipt.url);
|
|
281
|
+
}
|
|
282
|
+
return CALL_EXIT.OK;
|
|
283
|
+
}
|