@botbuddy/cli 1.33.9 → 1.33.10

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@botbuddy/cli",
3
- "version": "1.33.9",
3
+ "version": "1.33.10",
4
4
  "description": "BotBuddy — Swarm coordination CLI for multi-agent workflows",
5
5
  "type": "module",
6
6
  "bin": {
@@ -67,7 +67,13 @@ function prerequisiteRecovery(report) {
67
67
  * credential-store failure must point at unlocking the store — not `bb login` or a
68
68
  * binding repair — matching prerequisiteRecovery's wording.
69
69
  */
70
- function repairFailureRecovery(code) {
70
+ function repairFailureRecovery(code, error = null) {
71
+ // BOT-1891: a tier-2 MCP key the server rejected (revoked/rotated) is replaced by
72
+ // minting a new one and re-delivering it — not by `bb login`, which a Background
73
+ // job cannot run anyway. Name the variable, never the value.
74
+ if (code === "session_mint_unauthorized" && error?.mintedWith === "mcp_key") {
75
+ return `the tier-2 MCP key in ${error.mcpEnv ?? "the binding's mcp_env"} was rejected (revoked?); mint a new one, store it in Keychain under that name, then re-run \`bash scripts/install-stack-canary.sh\` (or re-export it) and \`bb doctor --fix\``;
76
+ }
71
77
  if (code === "client_key_unavailable") {
72
78
  return "the client key could not be read (locked or failing credential store); unlock it, then run `bb doctor --fix`";
73
79
  }
@@ -120,11 +126,17 @@ export async function doctorAgentAuth({
120
126
  ]);
121
127
  try { owner = await ownerToken(); } catch { ownerReadFailed = true; }
122
128
  const fresh = Boolean(state && isFresh(state, new Date()));
129
+ // BOT-1891: whether the binding's tier-2 MCP key is in THIS process's env — the
130
+ // self-heal fallback when the owner token is unreachable (a Background
131
+ // LaunchAgent). Env only, exactly like selfHealAgentSession; never the value.
132
+ const mcpEnv = typeof bound?.mcpEnv === "string" && bound.mcpEnv ? bound.mcpEnv : null;
133
+ const mcpKeyInEnv = Boolean(mcpEnv && typeof env?.[mcpEnv] === "string" && env[mcpEnv]);
123
134
  const report = {
124
135
  schema_version: 1,
125
136
  worktree: cwd,
126
137
  binding: bound?.tenant ? { status: "available", tenant: bound.tenant } : { status: "missing" },
127
138
  client_key: clientKeyStatus(owner, now(), ownerReadFailed),
139
+ ...(mcpEnv ? { mcp_key: { env: mcpEnv, in_env: mcpKeyInEnv } } : {}),
128
140
  session: fresh
129
141
  ? { status: "fresh", agent_id: state.agent_id, session_id: state.session_id, expires_at: state.expires_at }
130
142
  : { status: state ? "stale" : "missing" },
@@ -147,14 +159,28 @@ export async function doctorAgentAuth({
147
159
  // `bb doctor --fix` (the remedy the stack refusal points at) would reuse a fresh but
148
160
  // never-attested session and never re-establish the capability. `force` makes the
149
161
  // self-heal run a registration/attestation round regardless of cache freshness.
150
- if (fix && report.binding.status === "available" && report.client_key.status === "available") {
162
+ // BOT-1891: an UNREADABLE client key (a Background LaunchAgent cannot reach the
163
+ // login Keychain) is repairable when the binding's tier-2 MCP key is in the env —
164
+ // selfHeal mints with it. A missing or expired key keeps its `bb login` verdict.
165
+ const mintCredentialAvailable = report.client_key.status === "available"
166
+ || (mcpKeyInEnv && report.client_key.status === "unavailable");
167
+ if (fix && report.binding.status === "available" && mintCredentialAvailable) {
151
168
  try {
152
169
  credential = await selfHeal({ cwd, env, force: true });
153
- report.session = { status: credential.source === "minted" ? "minted" : credential.source, agent_id: credential.agentId ?? null, session_id: credential.sessionId ?? null };
170
+ report.session = {
171
+ status: credential.source === "minted" ? "minted" : credential.source,
172
+ agent_id: credential.agentId ?? null,
173
+ session_id: credential.sessionId ?? null,
174
+ ...(credential.mintedWith ? { minted_with: credential.mintedWith } : {}),
175
+ };
154
176
  applyStackLeaseCapability(report, credential.stackLeaseCapability);
155
177
  } catch (error) {
156
- report.session = { status: "repair_failed", error: error?.code ?? "agent_session_unavailable" };
157
- report.recovery = repairFailureRecovery(error?.code);
178
+ report.session = {
179
+ status: "repair_failed",
180
+ error: error?.code ?? "agent_session_unavailable",
181
+ ...(error?.mintedWith ? { minted_with: error.mintedWith } : {}),
182
+ };
183
+ report.recovery = repairFailureRecovery(error?.code, error);
158
184
  return { exitCode: 3, report, exports: null };
159
185
  }
160
186
  }
@@ -173,7 +199,7 @@ export async function doctorAgentAuth({
173
199
  // cached session left `credential` populated, report THAT prerequisite — not the
174
200
  // Helper/capability message below, since registration never ran and the real remedy
175
201
  // is `bb login` or restoring the binding.
176
- if (fix && (report.binding.status !== "available" || report.client_key.status !== "available")) {
202
+ if (fix && (report.binding.status !== "available" || !mintCredentialAvailable)) {
177
203
  report.recovery = prerequisiteRecovery(report) ?? "run `bb doctor --fix` to mint a replacement session";
178
204
  return { exitCode: 3, report, exports };
179
205
  }
@@ -194,5 +220,5 @@ export async function doctorAgentAuth({
194
220
  }
195
221
 
196
222
  export function doctorHelp() {
197
- return "bb doctor [--fix] [--print-exports] [--json]\n\nChecks the client key, repo binding, cached agent session, and this worktree's stack-lease capability (registered host + attested machine). --fix mints a replacement session and (re)establishes the stack-lease capability; --print-exports prints its canonical shell exports.";
223
+ return "bb doctor [--fix] [--print-exports] [--json]\n\nChecks the client key, repo binding, cached agent session, and this worktree's stack-lease capability (registered host + attested machine). --fix mints a replacement session and (re)establishes the stack-lease capability; --print-exports prints its canonical shell exports. When the client key is unreachable (a Background LaunchAgent cannot read the login Keychain), --fix mints from the tier-2 MCP key exported under the binding's mcp_env name (env only, never Keychain).";
198
224
  }
Binary file
package/src/commands.mjs CHANGED
@@ -226,7 +226,8 @@ export async function cmdDoctor(args, { log = (line) => console.log(line), error
226
226
  } else {
227
227
  log(`binding: ${result.report.binding.status}${result.report.binding.tenant ? ` (${result.report.binding.tenant})` : ""}`);
228
228
  log(`client key: ${result.report.client_key.status}`);
229
- log(`agent session: ${result.report.session.status}`);
229
+ if (result.report.mcp_key) log(`mcp key: ${result.report.mcp_key.env} ${result.report.mcp_key.in_env ? "in env" : "not in env"}`);
230
+ log(`agent session: ${result.report.session.status}${result.report.session.minted_with ? ` (minted_with: ${result.report.session.minted_with})` : ""}`);
230
231
  if (result.report.stack_lease) {
231
232
  const sl = result.report.stack_lease;
232
233
  log(`stack lease: ${sl.capability} (host ${sl.host}, machine id ${sl.machine_id_readable ? "readable" : "unavailable"})${sl.reason ? ` — ${sl.reason}` : ""}`);