bamboo-agents 0.1.1 → 0.1.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/dist/VERSION +1 -1
- package/dist/index.js +204 -23
- package/dist/index.js.map +4 -4
- package/package.json +1 -1
package/dist/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
0.1.
|
|
1
|
+
0.1.3
|
package/dist/index.js
CHANGED
|
@@ -3032,6 +3032,15 @@ var require_commander = __commonJS({
|
|
|
3032
3032
|
}
|
|
3033
3033
|
});
|
|
3034
3034
|
|
|
3035
|
+
// src/version.ts
|
|
3036
|
+
var VERSION;
|
|
3037
|
+
var init_version = __esm({
|
|
3038
|
+
"src/version.ts"() {
|
|
3039
|
+
"use strict";
|
|
3040
|
+
VERSION = "0.1.3";
|
|
3041
|
+
}
|
|
3042
|
+
});
|
|
3043
|
+
|
|
3035
3044
|
// ../../node_modules/is-docker/index.js
|
|
3036
3045
|
import fs from "node:fs";
|
|
3037
3046
|
function hasDockerEnv() {
|
|
@@ -11397,6 +11406,7 @@ var init_auth_status = __esm({
|
|
|
11397
11406
|
});
|
|
11398
11407
|
|
|
11399
11408
|
// src/lib/api.ts
|
|
11409
|
+
import { platform as platform2 } from "node:os";
|
|
11400
11410
|
function apiBase() {
|
|
11401
11411
|
return process.env.BAMBOO_API_BASE ?? DEFAULT_BASE;
|
|
11402
11412
|
}
|
|
@@ -11409,11 +11419,23 @@ async function parseError(res) {
|
|
|
11409
11419
|
const message = body.message ?? body.error ?? `HTTP ${res.status} from ${res.url}`;
|
|
11410
11420
|
return new ApiError(message, res.status, body.error);
|
|
11411
11421
|
}
|
|
11412
|
-
|
|
11413
|
-
|
|
11422
|
+
function userAgent() {
|
|
11423
|
+
const nodeVersion = process.versions.node;
|
|
11424
|
+
const plat = platform2();
|
|
11425
|
+
return `bamboo-agents/${VERSION} (node/${nodeVersion}; ${plat})`;
|
|
11426
|
+
}
|
|
11427
|
+
async function cliApiFetch(url, init = {}) {
|
|
11428
|
+
const headers = new Headers(init.headers);
|
|
11429
|
+
headers.set("User-Agent", userAgent());
|
|
11430
|
+
headers.set("Bamboo-CLI-Version", VERSION);
|
|
11431
|
+
return fetch(url, {
|
|
11432
|
+
...init,
|
|
11433
|
+
headers,
|
|
11434
|
+
signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS)
|
|
11435
|
+
});
|
|
11414
11436
|
}
|
|
11415
11437
|
async function getGithubToken(bambooSession) {
|
|
11416
|
-
const res = await
|
|
11438
|
+
const res = await cliApiFetch(`${apiBase()}/api/auth/github/token`, {
|
|
11417
11439
|
headers: { Authorization: `Bearer ${bambooSession}` }
|
|
11418
11440
|
});
|
|
11419
11441
|
if (!res.ok) throw await parseError(res);
|
|
@@ -11421,20 +11443,35 @@ async function getGithubToken(bambooSession) {
|
|
|
11421
11443
|
return AuthTokenSuccessSchema.parse(json);
|
|
11422
11444
|
}
|
|
11423
11445
|
async function getCliAuthStatus(bambooSession) {
|
|
11424
|
-
const res = await
|
|
11446
|
+
const res = await cliApiFetch(`${apiBase()}/api/cli/auth/status`, {
|
|
11425
11447
|
headers: { Authorization: `Bearer ${bambooSession}` }
|
|
11426
11448
|
});
|
|
11427
11449
|
if (!res.ok) throw await parseError(res);
|
|
11428
11450
|
const json = await res.json();
|
|
11429
11451
|
return AuthStatusResponseSchema.parse(json);
|
|
11430
11452
|
}
|
|
11431
|
-
|
|
11453
|
+
async function startGithubOAuthRelink(bambooSession) {
|
|
11454
|
+
const res = await cliApiFetch(
|
|
11455
|
+
`${apiBase()}/api/auth/github/oauth-relink/start`,
|
|
11456
|
+
{
|
|
11457
|
+
method: "POST",
|
|
11458
|
+
headers: { Authorization: `Bearer ${bambooSession}` }
|
|
11459
|
+
}
|
|
11460
|
+
);
|
|
11461
|
+
if (!res.ok) throw await parseError(res);
|
|
11462
|
+
const json = await res.json();
|
|
11463
|
+
return OAuthRelinkStartResponseSchema.parse(json);
|
|
11464
|
+
}
|
|
11465
|
+
var DEFAULT_BASE, REQUEST_TIMEOUT_MS, ApiError, OAuthRelinkStartResponseSchema;
|
|
11432
11466
|
var init_api = __esm({
|
|
11433
11467
|
"src/lib/api.ts"() {
|
|
11434
11468
|
"use strict";
|
|
11469
|
+
init_zod();
|
|
11435
11470
|
init_auth_token();
|
|
11436
11471
|
init_auth_status();
|
|
11472
|
+
init_version();
|
|
11437
11473
|
DEFAULT_BASE = "https://withbamboo.com";
|
|
11474
|
+
REQUEST_TIMEOUT_MS = 3e4;
|
|
11438
11475
|
ApiError = class extends Error {
|
|
11439
11476
|
constructor(message, status, errorCode) {
|
|
11440
11477
|
super(message);
|
|
@@ -11443,7 +11480,9 @@ var init_api = __esm({
|
|
|
11443
11480
|
this.name = "ApiError";
|
|
11444
11481
|
}
|
|
11445
11482
|
};
|
|
11446
|
-
|
|
11483
|
+
OAuthRelinkStartResponseSchema = external_exports.object({
|
|
11484
|
+
relink_url: external_exports.string().url()
|
|
11485
|
+
});
|
|
11447
11486
|
}
|
|
11448
11487
|
});
|
|
11449
11488
|
|
|
@@ -11507,7 +11546,9 @@ var init_credentials = __esm({
|
|
|
11507
11546
|
// src/commands/login.ts
|
|
11508
11547
|
var login_exports = {};
|
|
11509
11548
|
__export(login_exports, {
|
|
11549
|
+
handleMissingGithubToken: () => handleMissingGithubToken,
|
|
11510
11550
|
runLogin: () => runLogin,
|
|
11551
|
+
startCallbackServer: () => startCallbackServer,
|
|
11511
11552
|
verificationCode: () => verificationCode
|
|
11512
11553
|
});
|
|
11513
11554
|
import { randomBytes } from "node:crypto";
|
|
@@ -11518,6 +11559,26 @@ function verificationCode(state) {
|
|
|
11518
11559
|
const head = state.slice(0, 8).toUpperCase();
|
|
11519
11560
|
return `${head.slice(0, 4)}-${head.slice(4, 8)}`;
|
|
11520
11561
|
}
|
|
11562
|
+
async function handleMissingGithubToken(bambooSession) {
|
|
11563
|
+
try {
|
|
11564
|
+
const { relink_url } = await startGithubOAuthRelink(bambooSession);
|
|
11565
|
+
await open_default(relink_url);
|
|
11566
|
+
console.log("");
|
|
11567
|
+
console.log(
|
|
11568
|
+
" After authorizing in your browser, re-run `bamboo-agents login`."
|
|
11569
|
+
);
|
|
11570
|
+
console.log("");
|
|
11571
|
+
return 0;
|
|
11572
|
+
} catch {
|
|
11573
|
+
console.log("");
|
|
11574
|
+
console.log(
|
|
11575
|
+
` Couldn't start GitHub re-link automatically. Open this URL in your browser, then re-run \`bamboo-agents login\`:`
|
|
11576
|
+
);
|
|
11577
|
+
console.log(` ${FALLBACK_RELINK_URL}`);
|
|
11578
|
+
console.log("");
|
|
11579
|
+
return 1;
|
|
11580
|
+
}
|
|
11581
|
+
}
|
|
11521
11582
|
async function startCallbackServer(expectedState) {
|
|
11522
11583
|
let resolveSession;
|
|
11523
11584
|
let rejectSession;
|
|
@@ -11550,10 +11611,8 @@ async function startCallbackServer(expectedState) {
|
|
|
11550
11611
|
let body;
|
|
11551
11612
|
try {
|
|
11552
11613
|
body = JSON.parse(Buffer.concat(chunks).toString("utf8"));
|
|
11553
|
-
} catch
|
|
11614
|
+
} catch {
|
|
11554
11615
|
respondCors(400, { error: "invalid_json" });
|
|
11555
|
-
rejectSession(new Error(`Bad callback body: ${err.message}`));
|
|
11556
|
-
setTimeout(() => server.close(), 100);
|
|
11557
11616
|
return;
|
|
11558
11617
|
}
|
|
11559
11618
|
if (typeof body.session !== "string" || typeof body.state !== "string") {
|
|
@@ -11561,9 +11620,10 @@ async function startCallbackServer(expectedState) {
|
|
|
11561
11620
|
return;
|
|
11562
11621
|
}
|
|
11563
11622
|
if (body.state !== expectedState) {
|
|
11623
|
+
console.warn(
|
|
11624
|
+
" (ignored a callback with a mismatched state token \u2014 keep the browser tab open)"
|
|
11625
|
+
);
|
|
11564
11626
|
respondCors(400, { error: "state_mismatch" });
|
|
11565
|
-
rejectSession(new Error("Login state token didn't match \u2014 possible CSRF, aborted."));
|
|
11566
|
-
setTimeout(() => server.close(), 100);
|
|
11567
11627
|
return;
|
|
11568
11628
|
}
|
|
11569
11629
|
respondCors(200, { ok: true });
|
|
@@ -11626,10 +11686,11 @@ async function runLogin() {
|
|
|
11626
11686
|
tokenResp = await getGithubToken(bambooSession);
|
|
11627
11687
|
} catch (err) {
|
|
11628
11688
|
if (err instanceof ApiError && err.status === 404) {
|
|
11629
|
-
tokenSpinner.
|
|
11630
|
-
"No GitHub token linked yet
|
|
11689
|
+
tokenSpinner.warn(
|
|
11690
|
+
"No GitHub token linked yet \u2014 opening browser to authorize Bamboo with GitHub\u2026"
|
|
11631
11691
|
);
|
|
11632
|
-
|
|
11692
|
+
const code2 = await handleMissingGithubToken(bambooSession);
|
|
11693
|
+
process.exit(code2);
|
|
11633
11694
|
}
|
|
11634
11695
|
if (err instanceof ApiError && err.status === 410) {
|
|
11635
11696
|
tokenSpinner.fail("Your GitHub token expired. Sign in to Bamboo with GitHub again, then re-run.");
|
|
@@ -11653,7 +11714,7 @@ async function runLogin() {
|
|
|
11653
11714
|
console.log(" Next: `bamboo-agents init` to clone your workspace.");
|
|
11654
11715
|
console.log("");
|
|
11655
11716
|
}
|
|
11656
|
-
var LOGIN_TIMEOUT_MS;
|
|
11717
|
+
var FALLBACK_RELINK_URL, LOGIN_TIMEOUT_MS;
|
|
11657
11718
|
var init_login = __esm({
|
|
11658
11719
|
"src/commands/login.ts"() {
|
|
11659
11720
|
"use strict";
|
|
@@ -11661,6 +11722,7 @@ var init_login = __esm({
|
|
|
11661
11722
|
init_ora();
|
|
11662
11723
|
init_api();
|
|
11663
11724
|
init_credentials();
|
|
11725
|
+
FALLBACK_RELINK_URL = "https://withbamboo.com/connect-github";
|
|
11664
11726
|
LOGIN_TIMEOUT_MS = 5 * 60 * 1e3;
|
|
11665
11727
|
}
|
|
11666
11728
|
});
|
|
@@ -11715,6 +11777,29 @@ async function cloneRepo(repoFullName, targetDir) {
|
|
|
11715
11777
|
);
|
|
11716
11778
|
}
|
|
11717
11779
|
}
|
|
11780
|
+
async function checkGitCredentialForGitHub() {
|
|
11781
|
+
return new Promise((resolve) => {
|
|
11782
|
+
const proc = execFile6(
|
|
11783
|
+
"git",
|
|
11784
|
+
["credential", "fill"],
|
|
11785
|
+
{
|
|
11786
|
+
encoding: "utf8",
|
|
11787
|
+
env: { ...process.env, GIT_TERMINAL_PROMPT: "0" }
|
|
11788
|
+
},
|
|
11789
|
+
(err, stdout) => {
|
|
11790
|
+
if (err) {
|
|
11791
|
+
resolve(false);
|
|
11792
|
+
return;
|
|
11793
|
+
}
|
|
11794
|
+
const hasOurUsername = /^username=x-access-token\s*$/m.test(stdout);
|
|
11795
|
+
const hasPassword = /^password=\S+/m.test(stdout);
|
|
11796
|
+
resolve(hasOurUsername && hasPassword);
|
|
11797
|
+
}
|
|
11798
|
+
);
|
|
11799
|
+
proc.stdin?.write("protocol=https\nhost=github.com\n\n");
|
|
11800
|
+
proc.stdin?.end();
|
|
11801
|
+
});
|
|
11802
|
+
}
|
|
11718
11803
|
async function getGitConfig(key) {
|
|
11719
11804
|
try {
|
|
11720
11805
|
const { stdout } = await execFileP("git", ["config", "--global", "--get", key], {
|
|
@@ -11923,6 +12008,49 @@ var init_init = __esm({
|
|
|
11923
12008
|
}
|
|
11924
12009
|
});
|
|
11925
12010
|
|
|
12011
|
+
// src/lib/claude-desktop.ts
|
|
12012
|
+
import { execFile as execFile7 } from "node:child_process";
|
|
12013
|
+
import { platform as platform3 } from "node:os";
|
|
12014
|
+
import { promisify as promisify7 } from "node:util";
|
|
12015
|
+
async function detectClaudeDesktop() {
|
|
12016
|
+
const plat = platform3();
|
|
12017
|
+
if (plat === "darwin") return await detectMacOS();
|
|
12018
|
+
if (plat === "win32") return await detectWindows();
|
|
12019
|
+
return { kind: "unsupported_platform" };
|
|
12020
|
+
}
|
|
12021
|
+
async function detectMacOS() {
|
|
12022
|
+
try {
|
|
12023
|
+
const { stdout } = await execFileP2(
|
|
12024
|
+
"mdfind",
|
|
12025
|
+
[`kMDItemCFBundleIdentifier == "${MACOS_BUNDLE_ID}"`],
|
|
12026
|
+
{ encoding: "utf8" }
|
|
12027
|
+
);
|
|
12028
|
+
return stdout.trim().length > 0 ? { kind: "installed" } : { kind: "missing" };
|
|
12029
|
+
} catch {
|
|
12030
|
+
return { kind: "missing" };
|
|
12031
|
+
}
|
|
12032
|
+
}
|
|
12033
|
+
async function detectWindows() {
|
|
12034
|
+
try {
|
|
12035
|
+
await execFileP2(
|
|
12036
|
+
"reg",
|
|
12037
|
+
["query", "HKCU\\Software\\Classes\\claude"],
|
|
12038
|
+
{ encoding: "utf8" }
|
|
12039
|
+
);
|
|
12040
|
+
return { kind: "installed" };
|
|
12041
|
+
} catch {
|
|
12042
|
+
return { kind: "missing" };
|
|
12043
|
+
}
|
|
12044
|
+
}
|
|
12045
|
+
var execFileP2, MACOS_BUNDLE_ID;
|
|
12046
|
+
var init_claude_desktop = __esm({
|
|
12047
|
+
"src/lib/claude-desktop.ts"() {
|
|
12048
|
+
"use strict";
|
|
12049
|
+
execFileP2 = promisify7(execFile7);
|
|
12050
|
+
MACOS_BUNDLE_ID = "com.anthropic.claudefordesktop";
|
|
12051
|
+
}
|
|
12052
|
+
});
|
|
12053
|
+
|
|
11926
12054
|
// src/commands/open.ts
|
|
11927
12055
|
var open_exports = {};
|
|
11928
12056
|
__export(open_exports, {
|
|
@@ -11934,16 +12062,34 @@ async function runOpen() {
|
|
|
11934
12062
|
console.error("No workspace configured. Run `bamboo-agents init` first.");
|
|
11935
12063
|
process.exit(2);
|
|
11936
12064
|
}
|
|
12065
|
+
const status = await detectClaudeDesktop();
|
|
12066
|
+
if (status.kind === "missing") {
|
|
12067
|
+
console.error(
|
|
12068
|
+
`Claude Desktop isn't installed. Get it at ${DOWNLOAD_URL}, then re-run \`bamboo-agents open\`.`
|
|
12069
|
+
);
|
|
12070
|
+
console.error(`(Your workspace is cloned at ${cfg.repo_path}.)`);
|
|
12071
|
+
process.exit(1);
|
|
12072
|
+
}
|
|
12073
|
+
if (status.kind === "unsupported_platform") {
|
|
12074
|
+
console.log("");
|
|
12075
|
+
console.log(" Claude Desktop isn't available on Linux yet.");
|
|
12076
|
+
console.log(` Your workspace is cloned at: ${cfg.repo_path}`);
|
|
12077
|
+
console.log("");
|
|
12078
|
+
return;
|
|
12079
|
+
}
|
|
11937
12080
|
const url = `claude://code/new?folder=${encodeURIComponent(cfg.repo_path)}`;
|
|
11938
12081
|
await open_default(url);
|
|
11939
12082
|
console.log(`Opening Claude Code at ${cfg.repo_path}\u2026`);
|
|
11940
12083
|
console.log("(Claude Desktop will ask you to trust the folder the first time.)");
|
|
11941
12084
|
}
|
|
12085
|
+
var DOWNLOAD_URL;
|
|
11942
12086
|
var init_open2 = __esm({
|
|
11943
12087
|
"src/commands/open.ts"() {
|
|
11944
12088
|
"use strict";
|
|
11945
12089
|
init_open();
|
|
12090
|
+
init_claude_desktop();
|
|
11946
12091
|
init_state();
|
|
12092
|
+
DOWNLOAD_URL = "https://claude.com/download";
|
|
11947
12093
|
}
|
|
11948
12094
|
});
|
|
11949
12095
|
|
|
@@ -11990,6 +12136,8 @@ var init_status = __esm({
|
|
|
11990
12136
|
// src/commands/doctor.ts
|
|
11991
12137
|
var doctor_exports = {};
|
|
11992
12138
|
__export(doctor_exports, {
|
|
12139
|
+
checkBambooSession: () => checkBambooSession,
|
|
12140
|
+
checkGitCredential: () => checkGitCredential,
|
|
11993
12141
|
runDoctor: () => runDoctor
|
|
11994
12142
|
});
|
|
11995
12143
|
import { access as access2 } from "node:fs/promises";
|
|
@@ -12011,26 +12159,57 @@ async function checkGit() {
|
|
|
12011
12159
|
}
|
|
12012
12160
|
return { name: "git installed", ok: true, detail: v.join(".") };
|
|
12013
12161
|
}
|
|
12014
|
-
async function
|
|
12162
|
+
async function checkBambooSession() {
|
|
12015
12163
|
const c = await readCredentials();
|
|
12016
12164
|
if (!c) {
|
|
12017
12165
|
return {
|
|
12018
|
-
name: "Bamboo
|
|
12166
|
+
name: "Bamboo session",
|
|
12019
12167
|
ok: false,
|
|
12020
12168
|
detail: "missing \u2014 run `bamboo-agents login`."
|
|
12021
12169
|
};
|
|
12022
12170
|
}
|
|
12023
12171
|
if (c.github_token_expires_at && new Date(c.github_token_expires_at).getTime() < Date.now()) {
|
|
12024
12172
|
return {
|
|
12025
|
-
name: "Bamboo
|
|
12173
|
+
name: "Bamboo session",
|
|
12026
12174
|
ok: false,
|
|
12027
12175
|
detail: "GitHub token expired \u2014 run `bamboo-agents login` again."
|
|
12028
12176
|
};
|
|
12029
12177
|
}
|
|
12178
|
+
try {
|
|
12179
|
+
await getCliAuthStatus(c.bamboo_session);
|
|
12180
|
+
return {
|
|
12181
|
+
name: "Bamboo session",
|
|
12182
|
+
ok: true,
|
|
12183
|
+
detail: c.github_username ? `@${c.github_username}` : "valid"
|
|
12184
|
+
};
|
|
12185
|
+
} catch (err) {
|
|
12186
|
+
if (err instanceof ApiError && err.status === 401) {
|
|
12187
|
+
return {
|
|
12188
|
+
name: "Bamboo session",
|
|
12189
|
+
ok: false,
|
|
12190
|
+
detail: "session expired \u2014 run `bamboo-agents login` again."
|
|
12191
|
+
};
|
|
12192
|
+
}
|
|
12193
|
+
return {
|
|
12194
|
+
name: "Bamboo session",
|
|
12195
|
+
ok: false,
|
|
12196
|
+
detail: `couldn't reach Bamboo \u2014 check connectivity (${err.message}).`
|
|
12197
|
+
};
|
|
12198
|
+
}
|
|
12199
|
+
}
|
|
12200
|
+
async function checkGitCredential() {
|
|
12201
|
+
const ok = await checkGitCredentialForGitHub();
|
|
12202
|
+
if (ok) {
|
|
12203
|
+
return {
|
|
12204
|
+
name: "Git credential",
|
|
12205
|
+
ok: true,
|
|
12206
|
+
detail: "github.com entry present in credential helper"
|
|
12207
|
+
};
|
|
12208
|
+
}
|
|
12030
12209
|
return {
|
|
12031
|
-
name: "
|
|
12032
|
-
ok:
|
|
12033
|
-
detail:
|
|
12210
|
+
name: "Git credential",
|
|
12211
|
+
ok: false,
|
|
12212
|
+
detail: "no github.com entry in git's credential helper \u2014 run `bamboo-agents login` then `bamboo-agents init` to reinstall."
|
|
12034
12213
|
};
|
|
12035
12214
|
}
|
|
12036
12215
|
async function checkConfig() {
|
|
@@ -12067,7 +12246,8 @@ async function checkRepoPath() {
|
|
|
12067
12246
|
async function runDoctor() {
|
|
12068
12247
|
const checks = await Promise.all([
|
|
12069
12248
|
checkGit(),
|
|
12070
|
-
|
|
12249
|
+
checkBambooSession(),
|
|
12250
|
+
checkGitCredential(),
|
|
12071
12251
|
checkConfig(),
|
|
12072
12252
|
checkRepoPath()
|
|
12073
12253
|
]);
|
|
@@ -12087,6 +12267,7 @@ async function runDoctor() {
|
|
|
12087
12267
|
var init_doctor = __esm({
|
|
12088
12268
|
"src/commands/doctor.ts"() {
|
|
12089
12269
|
"use strict";
|
|
12270
|
+
init_api();
|
|
12090
12271
|
init_git();
|
|
12091
12272
|
init_state();
|
|
12092
12273
|
init_credentials();
|
|
@@ -12111,7 +12292,7 @@ var {
|
|
|
12111
12292
|
} = import_index.default;
|
|
12112
12293
|
|
|
12113
12294
|
// src/index.ts
|
|
12114
|
-
|
|
12295
|
+
init_version();
|
|
12115
12296
|
var program2 = new Command();
|
|
12116
12297
|
program2.name("bamboo-agents").description("Set up your local Bamboo workspace and drop into Claude.").version(VERSION);
|
|
12117
12298
|
program2.command("login").description("Sign in to Bamboo via your browser").action(async () => {
|