@botbuddy/cli 1.74.1 → 1.75.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 +7 -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/commands.mjs +1 -0
- package/src/release-notes-keys.mjs +194 -0
- package/src/release-notes.mjs +8 -1
- package/src/status-band.mjs +128 -4
- package/src/update-check.mjs +3 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 1.75.1
|
|
4
|
+
|
|
5
|
+
- `bb update` (and `bb setup`, `bb status-band install`) now brings every copy of the bb-status band and the bb-session start-up hook up to date, not just the user-scope one (BOT-3216). A copy installed at local or project scope wins over user scope for its project, so stale ones kept old bands in Supply Guard worktrees: a checkout's local install was copied into every new worktree through its `settings.local.json`, and each copy stayed at the version current when that worktree was made. Now an enabled local copy behind the shipped version is uninstalled so the user-scope install applies (this also clears the checkout's `enabledPlugins` line, so new worktrees stop getting copies), a disabled one is updated and stays disabled, a project-scope one is updated in place, and a deleted worktree's entry is removed. If the user-scope install failed, nothing is removed, only updated. The install line ends with a count, e.g. `4 stale project copies removed (user scope now applies), 1 stale project copy updated.` A second run changes nothing.
|
|
6
|
+
|
|
7
|
+
## 1.75.0
|
|
8
|
+
|
|
9
|
+
- 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.
|
|
3
10
|
## 1.74.1
|
|
4
11
|
|
|
5
12
|
- 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.
|
|
Binary file
|
|
Binary file
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
|
-
"release_version": "1.
|
|
3
|
-
"source_commit": "
|
|
4
|
-
"source_sha256": "
|
|
2
|
+
"release_version": "1.75.1",
|
|
3
|
+
"source_commit": "c9b26bd073fb410fe6f6287eb8fed4460a05dc2b",
|
|
4
|
+
"source_sha256": "53efdcfde9d976b8b3ef630be679aedc998595399ac7b00a6c6559c334fd8bd1",
|
|
5
5
|
"target": "darwin-arm64",
|
|
6
|
-
"sha256": "
|
|
6
|
+
"sha256": "77b42d25b1f0ff1841b0352aad50ef42b49c49eef40c41abd7749d99a419cdc3"
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
|
-
"release_version": "1.
|
|
3
|
-
"source_commit": "
|
|
4
|
-
"source_sha256": "
|
|
2
|
+
"release_version": "1.75.1",
|
|
3
|
+
"source_commit": "c9b26bd073fb410fe6f6287eb8fed4460a05dc2b",
|
|
4
|
+
"source_sha256": "53efdcfde9d976b8b3ef630be679aedc998595399ac7b00a6c6559c334fd8bd1",
|
|
5
5
|
"target": "linux-x64",
|
|
6
|
-
"sha256": "
|
|
6
|
+
"sha256": "f621ec730416980c7dc41a580f17c278997a1b597050dcfb9cb4db01253fe574"
|
|
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.75.1",
|
|
4
|
+
"source_commit": "c9b26bd073fb410fe6f6287eb8fed4460a05dc2b",
|
|
5
|
+
"source_sha256": "53efdcfde9d976b8b3ef630be679aedc998595399ac7b00a6c6559c334fd8bd1",
|
|
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": "77b42d25b1f0ff1841b0352aad50ef42b49c49eef40c41abd7749d99a419cdc3",
|
|
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": "f621ec730416980c7dc41a580f17c278997a1b597050dcfb9cb4db01253fe574",
|
|
19
19
|
"mode": "0755"
|
|
20
20
|
}
|
|
21
21
|
}
|
package/package.json
CHANGED
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
|
+
}
|
package/src/release-notes.mjs
CHANGED
|
@@ -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("-")) {
|
package/src/status-band.mjs
CHANGED
|
@@ -9,7 +9,8 @@
|
|
|
9
9
|
// `botbuddy-labs` Claude Code marketplace at the plugin shipped in this package
|
|
10
10
|
// and installs `bb-status` at user scope, so every worktree gets the band.
|
|
11
11
|
import { execFile as nodeExecFile } from "node:child_process";
|
|
12
|
-
import {
|
|
12
|
+
import { existsSync } from "node:fs";
|
|
13
|
+
import { mkdir, readFile, rmdir } from "node:fs/promises";
|
|
13
14
|
import { dirname, join, resolve, sep } from "node:path";
|
|
14
15
|
import { fileURLToPath } from "node:url";
|
|
15
16
|
import { promisify } from "node:util";
|
|
@@ -83,6 +84,106 @@ async function installOne({ run, name, shipped, installed, repointed }) {
|
|
|
83
84
|
return { status: mine && !repointed ? "updated" : "installed", version: shipped };
|
|
84
85
|
}
|
|
85
86
|
|
|
87
|
+
// BOT-3216: a local- or project-scope copy wins over user scope for its project.
|
|
88
|
+
// The desktop app copies a checkout's gitignored .claude/settings.local.json into
|
|
89
|
+
// every new worktree, and Claude Code then installs the plugin at local scope at
|
|
90
|
+
// whatever version is current — a copy nothing ever updated again.
|
|
91
|
+
export const projectDirs = {
|
|
92
|
+
exists: (p) => existsSync(p),
|
|
93
|
+
// Claude Code keeps a git worktree's local enabledPlugins in its main
|
|
94
|
+
// checkout's settings.local.json, so it alone knows the effective state:
|
|
95
|
+
// `claude plugin list` run from the project reports it.
|
|
96
|
+
async enabled(p, id, run) {
|
|
97
|
+
const { stdout } = await run(["plugin", "list", "--json"], { cwd: p });
|
|
98
|
+
const list = JSON.parse(stdout);
|
|
99
|
+
const entry = Array.isArray(list) ? list.find((e) => e?.id === id && e?.scope === "local" && e?.projectPath === p) : null;
|
|
100
|
+
return entry?.enabled !== false;
|
|
101
|
+
},
|
|
102
|
+
// A deleted worktree's entry can only be uninstalled from its own path, so the
|
|
103
|
+
// path is recreated empty for that one command and the dirs made are removed
|
|
104
|
+
// again (rmdir only: never deletes anything it did not create).
|
|
105
|
+
async materialize(p) {
|
|
106
|
+
const made = [];
|
|
107
|
+
for (let d = resolve(p); !existsSync(d); d = dirname(d)) made.push(d);
|
|
108
|
+
await mkdir(p, { recursive: true });
|
|
109
|
+
return async () => {
|
|
110
|
+
for (const d of made) await rmdir(d).catch(() => {});
|
|
111
|
+
};
|
|
112
|
+
},
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
// Bring every local/project copy of our plugins that is behind the shipped
|
|
116
|
+
// version up to date. An enabled local copy is uninstalled so user scope takes
|
|
117
|
+
// over (that also drops its enabledPlugins line, so the checkout stops seeding
|
|
118
|
+
// new worktrees); a disabled one is updated and stays disabled; a project-scope
|
|
119
|
+
// one is updated in place (never edits committed settings). When the user-scope
|
|
120
|
+
// install failed nothing is removed, only updated. Sequential: every command
|
|
121
|
+
// rewrites Claude Code's one installed_plugins.json.
|
|
122
|
+
async function refreshScoped({ run, installed, shipped, userOk, dirs }) {
|
|
123
|
+
const counts = { removed: 0, updated: 0, failed: 0 };
|
|
124
|
+
const ours = (Array.isArray(installed) ? installed : []).filter((p) => {
|
|
125
|
+
const [name, market] = String(p?.id ?? "").split("@");
|
|
126
|
+
return market === MARKETPLACE && name in shipped && (p.scope === "local" || p.scope === "project") && p.projectPath;
|
|
127
|
+
});
|
|
128
|
+
const stale = ours.filter((p) => p.version !== shipped[p.id.split("@")[0]]);
|
|
129
|
+
if (!stale.length) return null;
|
|
130
|
+
const nameOf = (p) => p.id.split("@")[0];
|
|
131
|
+
// Snapshot every existing local copy's effective state (true | false | null =
|
|
132
|
+
// unread) before changing any: one removal rewrites the settings file a whole
|
|
133
|
+
// checkout's worktrees share, so it can change copies it never touched.
|
|
134
|
+
const state = new Map();
|
|
135
|
+
for (const p of ours) {
|
|
136
|
+
if (p.scope !== "local" || !dirs.exists(p.projectPath)) continue;
|
|
137
|
+
state.set(p, await dirs.enabled(p.projectPath, p.id, run).catch(() => null));
|
|
138
|
+
}
|
|
139
|
+
const plan = stale.map((p) => {
|
|
140
|
+
const exists = dirs.exists(p.projectPath);
|
|
141
|
+
// A local override is removed only when user scope will run it in its
|
|
142
|
+
// place and its state is known; a deleted worktree's entry always goes.
|
|
143
|
+
const remove = p.scope === "local" && (!exists || (userOk[nameOf(p)] && state.get(p) === true));
|
|
144
|
+
return { p, exists, remove };
|
|
145
|
+
});
|
|
146
|
+
for (const { p, exists, remove } of plan) {
|
|
147
|
+
let cleanup = null;
|
|
148
|
+
try {
|
|
149
|
+
if (!exists) cleanup = await dirs.materialize(p.projectPath);
|
|
150
|
+
await run(["plugin", remove ? "uninstall" : "update", p.id, "--scope", p.scope], { cwd: p.projectPath });
|
|
151
|
+
counts[remove ? "removed" : "updated"] += 1;
|
|
152
|
+
} catch {
|
|
153
|
+
counts.failed += 1;
|
|
154
|
+
} finally {
|
|
155
|
+
if (cleanup) await cleanup().catch(() => {});
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
if (!counts.removed) return counts;
|
|
159
|
+
// Put back what a removal may have cleared from the shared settings: a
|
|
160
|
+
// disabled copy is disabled again; an enabled one is re-enabled only where
|
|
161
|
+
// user scope would not run it (re-enabling elsewhere would re-seed new
|
|
162
|
+
// worktrees). A copy left in the wrong state is a failure named with the one
|
|
163
|
+
// command that fixes it, since the stale entry is gone and a re-run would not
|
|
164
|
+
// revisit it; a copy whose state could not be read is reported, never guessed.
|
|
165
|
+
const removed = new Set(plan.filter((x) => x.remove).map((x) => x.p));
|
|
166
|
+
for (const [p, was] of state) {
|
|
167
|
+
if (removed.has(p)) continue;
|
|
168
|
+
if (was === null) {
|
|
169
|
+
counts.failed += 1;
|
|
170
|
+
(counts.unread ??= []).push({ id: p.id, projectPath: p.projectPath });
|
|
171
|
+
continue;
|
|
172
|
+
}
|
|
173
|
+
if (was === true && userOk[nameOf(p)]) continue;
|
|
174
|
+
const now = await dirs.enabled(p.projectPath, p.id, run).catch(() => null);
|
|
175
|
+
if (now === was) continue;
|
|
176
|
+
const verb = was ? "enable" : "disable";
|
|
177
|
+
try {
|
|
178
|
+
await run(["plugin", verb, p.id, "--scope", "local"], { cwd: p.projectPath });
|
|
179
|
+
} catch {
|
|
180
|
+
counts.failed += 1;
|
|
181
|
+
(counts.restore ??= []).push({ id: p.id, projectPath: p.projectPath, verb });
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
return counts;
|
|
185
|
+
}
|
|
186
|
+
|
|
86
187
|
/**
|
|
87
188
|
* Point `botbuddy-labs` at this package's plugin folder and install `bb-status`
|
|
88
189
|
* (and, BOT-3222, `bb-session`) at user scope. Idempotent; never throws. Returns
|
|
@@ -96,9 +197,10 @@ export async function installStatusBand({
|
|
|
96
197
|
claude = "claude",
|
|
97
198
|
execFileImpl = promisify(nodeExecFile),
|
|
98
199
|
readJson = async (p) => JSON.parse(await readFile(p, "utf8")),
|
|
200
|
+
projectDirs: dirs = projectDirs,
|
|
99
201
|
} = {}) {
|
|
100
202
|
if (!isInstalledPackage(packageRoot)) return { status: "skipped", reason: "not_installed_package" };
|
|
101
|
-
const run = (args) => execFileImpl(claude, args, { timeout: 60_000, maxBuffer: 4 * 1024 * 1024 });
|
|
203
|
+
const run = (args, extra = {}) => execFileImpl(claude, args, { timeout: 60_000, maxBuffer: 4 * 1024 * 1024, ...extra });
|
|
102
204
|
try {
|
|
103
205
|
await run(["--version"]);
|
|
104
206
|
} catch {
|
|
@@ -139,12 +241,34 @@ export async function installStatusBand({
|
|
|
139
241
|
const band = wanted.includes(PLUGIN) ? await one(PLUGIN) : { status: "skipped", reason: "not_requested" };
|
|
140
242
|
const result = { ...band, ...(band.status !== "failed" && repointed ? { replaced: String(current.path ?? "") } : {}) };
|
|
141
243
|
if (wanted.includes(SESSION_PLUGIN)) result.session = await one(SESSION_PLUGIN);
|
|
244
|
+
// The band's user copy is always (re-)enabled; bb-session's stays disabled if
|
|
245
|
+
// the operator disabled it, and then a local override is not safe to remove.
|
|
246
|
+
const userSession = Array.isArray(installed) ? installed.find((p) => p?.id === `${SESSION_PLUGIN}@${MARKETPLACE}` && p?.scope === "user") : null;
|
|
247
|
+
const userOk = {
|
|
248
|
+
[PLUGIN]: band.status !== "failed",
|
|
249
|
+
[SESSION_PLUGIN]: Boolean(result.session) && result.session.status !== "failed" && userSession?.enabled !== false,
|
|
250
|
+
};
|
|
251
|
+
const scoped = await refreshScoped({ run, installed, shipped, userOk, dirs });
|
|
252
|
+
if (scoped) result.scoped = scoped;
|
|
142
253
|
return result;
|
|
143
254
|
}
|
|
144
255
|
|
|
145
256
|
export function statusBandLine(result) {
|
|
146
|
-
const
|
|
147
|
-
|
|
257
|
+
const parts = [bandLine(result)];
|
|
258
|
+
if (result?.session) parts.push(sessionLine(result.session));
|
|
259
|
+
if (result?.scoped) parts.push(scopedLine(result.scoped));
|
|
260
|
+
return parts.join(" ");
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
const copies = (n) => `${n} stale project ${n === 1 ? "copy" : "copies"}`;
|
|
264
|
+
function scopedLine({ removed = 0, updated = 0, failed = 0, restore = [], unread = [] }) {
|
|
265
|
+
const done = [removed && `${copies(removed)} removed (user scope now applies)`, updated && `${copies(updated)} updated`].filter(Boolean);
|
|
266
|
+
const head = done.length ? `${done.join(", ")}.` : "";
|
|
267
|
+
const other = failed - restore.length - unread.length;
|
|
268
|
+
const tail = other > 0 ? `${copies(other)} could not be fixed; run bb status-band install to retry.` : "";
|
|
269
|
+
const fix = restore.map((r) => `A copy lost its ${r.verb === "disable" ? "disabled" : "enabled"} setting; restore it: cd ${r.projectPath} && claude plugin ${r.verb} ${r.id} --scope local`);
|
|
270
|
+
const check = unread.map((r) => `Could not read whether ${r.id} is enabled in ${r.projectPath}; check it with claude plugin list there.`);
|
|
271
|
+
return [head, tail, ...fix, ...check].filter(Boolean).join(" ");
|
|
148
272
|
}
|
|
149
273
|
|
|
150
274
|
function sessionLine(s) {
|
package/src/update-check.mjs
CHANGED
|
@@ -306,9 +306,11 @@ export async function refreshInstalledPools({
|
|
|
306
306
|
|
|
307
307
|
// BOT-3152: run the NEW package's `status-band install` (this process is the old
|
|
308
308
|
// one), so Claude Code's bb-status band and its marketplace match the update.
|
|
309
|
+
// BOT-3216: it also fixes every stale local/project copy, two `claude` calls
|
|
310
|
+
// each (53 on one Mac), so it gets 10 minutes rather than 3.
|
|
309
311
|
export async function installBandFromNewPackage({ npmBin, shellOpt, probeImpl, log, nodeBin = process.execPath, execFileImpl = promisify(execFile) }) {
|
|
310
312
|
const root = readNpmGlobalRoot({ npmBin, shellOpt, probeImpl });
|
|
311
|
-
const { stdout } = await execFileImpl(nodeBin, [join(root, "@botbuddy", "cli", "bin", "botbuddy.mjs"), "status-band", "install"], { timeout:
|
|
313
|
+
const { stdout } = await execFileImpl(nodeBin, [join(root, "@botbuddy", "cli", "bin", "botbuddy.mjs"), "status-band", "install"], { timeout: 600_000, maxBuffer: 1024 * 1024 });
|
|
312
314
|
const line = String(stdout).trim().split("\n").filter(Boolean).pop();
|
|
313
315
|
if (line) log(line);
|
|
314
316
|
}
|