@botbuddy/cli 1.6.1 → 1.6.3

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.6.1",
3
+ "version": "1.6.3",
4
4
  "description": "BotBuddy — Swarm coordination CLI for multi-agent workflows",
5
5
  "type": "module",
6
6
  "bin": {
@@ -27,9 +27,21 @@ function keychainService(profile) {
27
27
  return profileCredentialEnvironment(profile);
28
28
  }
29
29
 
30
- function writePasswordPrompt(command, args, password) {
30
+ // A keychain/credential-store write failed AFTER OAuth + registration already
31
+ // succeeded. It carries its own code so the CLI never mislabels a storage
32
+ // failure as an auth failure (which would tell the user to re-`login`).
33
+ export class ProfileCredentialStoreError extends Error {
34
+ constructor(message, { cause } = {}) {
35
+ super(message);
36
+ this.name = "ProfileCredentialStoreError";
37
+ this.code = "profile_credential_store_failed";
38
+ if (cause !== undefined) this.cause = cause;
39
+ }
40
+ }
41
+
42
+ function writePasswordPrompt(command, args, password, spawnProcess) {
31
43
  return new Promise((resolve, reject) => {
32
- const child = spawn(command, args, { stdio: ["pipe", "ignore", "pipe"] });
44
+ const child = spawnProcess(command, args, { stdio: ["pipe", "ignore", "pipe"] });
33
45
  let stderr = "";
34
46
  child.stderr.on("data", (chunk) => { stderr += chunk; });
35
47
  child.once("error", reject);
@@ -37,16 +49,37 @@ function writePasswordPrompt(command, args, password) {
37
49
  if (code === 0) resolve();
38
50
  else reject(new Error(`${command} exited ${code}${stderr ? `: ${stderr.trim()}` : ""}`));
39
51
  });
40
- // `security -w` prompts from standard input when it is the last option.
41
- // Keeping the password off argv prevents process-list disclosure.
42
- child.stdin.end(`${password}\n`);
52
+ // `security -w` prompt mode reads the secret from standard input TWICE (the
53
+ // value and a retype). A single piped line leaves the retype empty, so
54
+ // `security` exits with "passwords don't match" the moment there is no TTY.
55
+ // Feeding the same value twice satisfies both reads without an interactive
56
+ // terminal, and keeping it off argv prevents process-list disclosure.
57
+ child.stdin.end(`${password}\n${password}\n`);
43
58
  });
44
59
  }
45
60
 
46
- async function writeKeychain(profile, token) {
61
+ export async function writeKeychain(profile, token, { spawnProcess = spawn } = {}) {
47
62
  const service = keychainService(profile);
48
- if (!service) throw new Error("unknown profile keychain service");
49
- await writePasswordPrompt("security", ["add-generic-password", "-U", "-s", service, "-a", userInfo().username, "-w"], token);
63
+ if (!service) throw new ProfileCredentialStoreError(`unknown profile keychain service for "${profile}"`);
64
+ try {
65
+ await writePasswordPrompt(
66
+ "security",
67
+ ["add-generic-password", "-U", "-s", service, "-a", userInfo().username, "-w"],
68
+ token,
69
+ spawnProcess,
70
+ );
71
+ } catch (error) {
72
+ // `security` cancels its authorization when the login keychain is locked in
73
+ // a headless session; guide the user to unlock it rather than re-login.
74
+ const detail = String(error?.message ?? error);
75
+ if (/authorization was cancell?ed/i.test(detail)) {
76
+ throw new ProfileCredentialStoreError(
77
+ "macOS Keychain authorization was canceled — unlock your login keychain (`security unlock-keychain`) and retry; a headless session needs it already unlocked",
78
+ { cause: error },
79
+ );
80
+ }
81
+ throw new ProfileCredentialStoreError(`could not write the profile credential to the macOS Keychain: ${detail}`, { cause: error });
82
+ }
50
83
  }
51
84
 
52
85
  async function readKeychain(profile) {
package/src/commands.mjs CHANGED
@@ -10,7 +10,7 @@ import { cmdRun } from "./run.mjs";
10
10
  import { runWait } from "./wait.mjs";
11
11
  import { green, red, cyan, dim, bold, die } from "./utils.mjs";
12
12
  import { VERSION } from "./version.mjs";
13
- import { bootstrapProfile, ProfileBootstrapError, profileShellRefresh } from "./profile-bootstrap.mjs";
13
+ import { bootstrapProfile, ProfileBootstrapError, profileBootstrapRecovery, profileShellRefresh } from "./profile-bootstrap.mjs";
14
14
  import { runPw } from "./pw/run.mjs";
15
15
 
16
16
  export async function run(argv) {
@@ -325,7 +325,7 @@ async function cmdProfile(args) {
325
325
  schema_version: 1,
326
326
  outcome: "error",
327
327
  error: code,
328
- recovery: "botbuddy login && botbuddy profile setup " + args[1],
328
+ recovery: profileBootstrapRecovery(code, args[1]),
329
329
  }));
330
330
  process.exitCode = 3;
331
331
  }
@@ -1,7 +1,7 @@
1
1
  import { hostname } from "node:os";
2
2
  import { randomUUID } from "node:crypto";
3
3
 
4
- import { ensureProfileCredentialBackend, readProfileIdentity, readProfileRetryIdentity, recordProfileRetryIdentity, installProfileCredential, profileCredentialEnvironment } from "./agent-credential-store.mjs";
4
+ import { ensureProfileCredentialBackend, readProfileIdentity, readProfileRetryIdentity, recordProfileRetryIdentity, installProfileCredential, profileCredentialEnvironment, ProfileCredentialStoreError } from "./agent-credential-store.mjs";
5
5
  import { callToolJson } from "./api.mjs";
6
6
  import { latestPublicCliCommand } from "./public-invocation.mjs";
7
7
 
@@ -79,13 +79,31 @@ export async function bootstrapProfile(profileName, {
79
79
  const token = registrationCredential(data);
80
80
  if (!token) throw new ProfileBootstrapError("profile_agent_required");
81
81
 
82
- await store({
83
- profile: profileName,
84
- tenant: profile.tenant,
85
- agentId: data.agent_id,
86
- name: agentName,
87
- token,
88
- });
82
+ try {
83
+ await store({
84
+ profile: profileName,
85
+ tenant: profile.tenant,
86
+ agentId: data.agent_id,
87
+ name: agentName,
88
+ token,
89
+ });
90
+ } catch (error) {
91
+ // OAuth + registration + tenant attestation all succeeded; only persisting
92
+ // the credential failed. Give the two persistence failures accurate,
93
+ // distinct recoveries — never the `botbuddy login` OAuth recovery:
94
+ // • a Keychain write failure (ProfileCredentialStoreError) is resolved by
95
+ // unlocking the login keychain;
96
+ // • a filesystem/lock failure writing ~/.botbuddy/agent-profiles.json
97
+ // (EACCES/ENOSPC/busy store lock) is NOT — unlocking the keychain would
98
+ // not help, so it gets its own code.
99
+ if (error instanceof ProfileBootstrapError) throw error;
100
+ const code = error instanceof ProfileCredentialStoreError
101
+ ? "profile_credential_store_failed"
102
+ : "profile_credential_persist_failed";
103
+ const failure = new ProfileBootstrapError(code);
104
+ failure.cause = error;
105
+ throw failure;
106
+ }
89
107
  return {
90
108
  schema_version: 1,
91
109
  outcome: "installed",
@@ -98,6 +116,19 @@ export async function bootstrapProfile(profileName, {
98
116
  };
99
117
  }
100
118
 
119
+ // Maps a bootstrap error code to the recovery hint shown in the CLI receipt.
120
+ // A credential-store/Keychain failure gets its own actionable recovery; every
121
+ // other failure keeps the historical login-first recovery verbatim.
122
+ export function profileBootstrapRecovery(code, profileName) {
123
+ if (code === "profile_credential_store_failed") {
124
+ return `unlock your login keychain (security unlock-keychain), then re-run: botbuddy profile setup ${profileName}`;
125
+ }
126
+ if (code === "profile_credential_persist_failed") {
127
+ return `ensure ~/.botbuddy is writable and no other setup is running, then re-run: botbuddy profile setup ${profileName}`;
128
+ }
129
+ return `botbuddy login && botbuddy profile setup ${profileName}`;
130
+ }
131
+
101
132
  export function profileShellRefresh(profileName) {
102
133
  const tokenEnv = profileCredentialEnvironment(profileName);
103
134
  if (!tokenEnv) throw new ProfileBootstrapError("profile_required");
package/src/wait-core.mjs CHANGED
@@ -228,6 +228,35 @@ const VALIDATORS = {
228
228
  }
229
229
  return { repo };
230
230
  },
231
+ // BOT-1458 — staging-release: wake when the first staging release train whose
232
+ // head commit CONTAINS this PR's merge commit reaches a terminal conclusion
233
+ // (success OR failure). Unlike `staging-green` this is PR-scoped and reports
234
+ // the train's outcome, never a health verdict. Inclusion is decided server-side
235
+ // by git ancestry (GitHub compare API), never by wall-clock ordering, so the
236
+ // condition only names the repo + PR; the relay stamps the resolved
237
+ // merge_commit_sha and workspace at registration. Optional
238
+ // `after_run=<run_id>[:<attempt>]` lets a wait re-armed from a failure receipt
239
+ // skip the run it already saw and park for the NEXT train.
240
+ "staging-release"(p) {
241
+ const { repo, number } = parsePrTarget(p, "staging-release");
242
+ if (number == null) {
243
+ throw new Error("staging-release needs pr=<number> (or pr=<owner/repo#number>)");
244
+ }
245
+ const out = { repo, pr: number };
246
+ if (p.after_run !== undefined) {
247
+ const raw = String(p.after_run).trim();
248
+ const m = /^(\d+)(?::(\d+))?$/.exec(raw);
249
+ if (!m) throw new Error("staging-release after_run must be <run_id>[:<attempt>]");
250
+ out.afterRunId = m[1];
251
+ if (m[2] !== undefined) out.afterRunAttempt = Number(m[2]);
252
+ }
253
+ const allowed = new Set(["repo", "pr", "number", "after_run"]);
254
+ const extras = Object.keys(p).filter((key) => !allowed.has(key));
255
+ if (extras.length > 0) {
256
+ throw new Error(`staging-release accepts only repo=<owner/repo>, pr=<number>, after_run=<run_id>[:<attempt>] (got: ${extras.join(", ")})`);
257
+ }
258
+ return out;
259
+ },
231
260
  // BOT-1247 — unblocked: wake when a ticket's LAST open blocker clears (its
232
261
  // open-blocker count transitions >0 → 0). Level-triggered: a ticket already
233
262
  // unblocked (or never blocked) at registration is granted immediately with
@@ -666,6 +695,27 @@ function conditionMatchesSignal(condition, signal, waitSessionId) {
666
695
  payload.gate_open === false &&
667
696
  payload.operational_status === "healthy";
668
697
  }
698
+ case "staging-release": {
699
+ // BOT-1458: a PR-scoped staging release train reached a terminal conclusion
700
+ // and its head commit contains this PR's merge (`includes_pr:true`, decided
701
+ // server-side by ancestry). The signal is tenant-scoped, so the central
702
+ // guard already fenced foreign workspaces. Subject is `<owner/repo>#<pr>`.
703
+ if (signal.signal_type !== "staging_release") return false;
704
+ const payload = signal.payload ?? {};
705
+ const subject = typeof signal.subject_key === "string" ? signal.subject_key.toLowerCase() : "";
706
+ if (subject !== `${params.repo}#${params.pr}`.toLowerCase()) return false;
707
+ if (payload.includes_pr !== true) return false;
708
+ // AC-9: a wait re-armed with after_run ignores the run it already saw — that
709
+ // run id, and (when an attempt was named) that attempt or lower — so a
710
+ // re-registration after a failure receipt parks for the NEXT train instead
711
+ // of instantly replaying the same failure via `--since`.
712
+ if (params.afterRunId != null && String(payload.workflow_run_id) === String(params.afterRunId)) {
713
+ if (params.afterRunAttempt == null) return false;
714
+ const attempt = Number(payload.workflow_run_attempt);
715
+ if (Number.isFinite(attempt) && attempt <= params.afterRunAttempt) return false;
716
+ }
717
+ return true;
718
+ }
669
719
  case "unblocked": {
670
720
  // Wakes on the ticket_unblocked spine signal for this ticket (the server emits both
671
721
  // the genuine >0→0 transition and the level-triggered `already_unblocked` echo).