@botbuddy/cli 1.6.2 → 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
|
@@ -27,9 +27,21 @@ function keychainService(profile) {
|
|
|
27
27
|
return profileCredentialEnvironment(profile);
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
|
|
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 =
|
|
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`
|
|
41
|
-
//
|
|
42
|
-
|
|
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
|
|
49
|
-
|
|
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:
|
|
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
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
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");
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"schema_version":1,"source_version":"1.6.1","source_identity":"9cc6a78baeb0da589214386daad729a2e8909936a2407da801777f9902e8667f"}
|