bamboo-agents 0.1.4 → 0.1.5-dev.13
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 +168 -25
- package/dist/index.js.map +4 -4
- package/package.json +1 -1
package/dist/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
0.1.
|
|
1
|
+
0.1.5-dev.13
|
package/dist/index.js
CHANGED
|
@@ -3037,7 +3037,7 @@ var VERSION;
|
|
|
3037
3037
|
var init_version = __esm({
|
|
3038
3038
|
"src/version.ts"() {
|
|
3039
3039
|
"use strict";
|
|
3040
|
-
VERSION = "0.1.
|
|
3040
|
+
VERSION = "0.1.5-dev.13";
|
|
3041
3041
|
}
|
|
3042
3042
|
});
|
|
3043
3043
|
|
|
@@ -11465,7 +11465,16 @@ async function startGithubOAuthRelink(bambooSession) {
|
|
|
11465
11465
|
const json = await res.json();
|
|
11466
11466
|
return OAuthRelinkStartResponseSchema.parse(json);
|
|
11467
11467
|
}
|
|
11468
|
-
|
|
11468
|
+
async function provisionWorkspace(bambooSession) {
|
|
11469
|
+
const res = await cliApiFetch(`${apiBase()}/api/cli/workspace/provision`, {
|
|
11470
|
+
method: "POST",
|
|
11471
|
+
headers: { Authorization: `Bearer ${bambooSession}` }
|
|
11472
|
+
});
|
|
11473
|
+
if (!res.ok) throw await parseError(res);
|
|
11474
|
+
const json = await res.json();
|
|
11475
|
+
return ProvisionWorkspaceResponseSchema.parse(json);
|
|
11476
|
+
}
|
|
11477
|
+
var PROD_DEFAULT_BASE, DEV_DEFAULT_BASE, REQUEST_TIMEOUT_MS, ApiError, OAuthRelinkStartResponseSchema, ProvisionWorkspaceResponseSchema;
|
|
11469
11478
|
var init_api = __esm({
|
|
11470
11479
|
"src/lib/api.ts"() {
|
|
11471
11480
|
"use strict";
|
|
@@ -11487,6 +11496,9 @@ var init_api = __esm({
|
|
|
11487
11496
|
OAuthRelinkStartResponseSchema = external_exports.object({
|
|
11488
11497
|
relink_url: external_exports.string().url()
|
|
11489
11498
|
});
|
|
11499
|
+
ProvisionWorkspaceResponseSchema = external_exports.object({
|
|
11500
|
+
workspace_repo: external_exports.string()
|
|
11501
|
+
});
|
|
11490
11502
|
}
|
|
11491
11503
|
});
|
|
11492
11504
|
|
|
@@ -11547,9 +11559,20 @@ var init_credentials = __esm({
|
|
|
11547
11559
|
}
|
|
11548
11560
|
});
|
|
11549
11561
|
|
|
11562
|
+
// src/lib/util.ts
|
|
11563
|
+
function sleep(ms) {
|
|
11564
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
11565
|
+
}
|
|
11566
|
+
var init_util2 = __esm({
|
|
11567
|
+
"src/lib/util.ts"() {
|
|
11568
|
+
"use strict";
|
|
11569
|
+
}
|
|
11570
|
+
});
|
|
11571
|
+
|
|
11550
11572
|
// src/commands/login.ts
|
|
11551
11573
|
var login_exports = {};
|
|
11552
11574
|
__export(login_exports, {
|
|
11575
|
+
TOKEN_POLL: () => TOKEN_POLL,
|
|
11553
11576
|
handleMissingGithubToken: () => handleMissingGithubToken,
|
|
11554
11577
|
runLogin: () => runLogin,
|
|
11555
11578
|
startCallbackServer: () => startCallbackServer,
|
|
@@ -11564,24 +11587,50 @@ function verificationCode(state) {
|
|
|
11564
11587
|
return `${head.slice(0, 4)}-${head.slice(4, 8)}`;
|
|
11565
11588
|
}
|
|
11566
11589
|
async function handleMissingGithubToken(bambooSession) {
|
|
11590
|
+
let relinkUrl;
|
|
11567
11591
|
try {
|
|
11568
11592
|
const { relink_url } = await startGithubOAuthRelink(bambooSession);
|
|
11569
|
-
|
|
11570
|
-
console.log("");
|
|
11571
|
-
console.log(
|
|
11572
|
-
" After authorizing in your browser, re-run `bamboo-agents login`."
|
|
11573
|
-
);
|
|
11574
|
-
console.log("");
|
|
11575
|
-
return 0;
|
|
11593
|
+
relinkUrl = relink_url;
|
|
11576
11594
|
} catch {
|
|
11577
11595
|
console.log("");
|
|
11578
11596
|
console.log(
|
|
11579
|
-
` Couldn't start GitHub
|
|
11597
|
+
` Couldn't start GitHub auth automatically. Open this URL in your browser, then re-run \`bamboo-agents login\`:`
|
|
11580
11598
|
);
|
|
11581
11599
|
console.log(` ${FALLBACK_RELINK_URL}`);
|
|
11582
11600
|
console.log("");
|
|
11583
|
-
return
|
|
11601
|
+
return null;
|
|
11602
|
+
}
|
|
11603
|
+
await open_default(relinkUrl);
|
|
11604
|
+
const spinner = ora("Waiting for GitHub authorization in your browser\u2026").start();
|
|
11605
|
+
const start = Date.now();
|
|
11606
|
+
while (Date.now() - start < TOKEN_POLL.timeoutMs) {
|
|
11607
|
+
await sleep(TOKEN_POLL.intervalMs);
|
|
11608
|
+
try {
|
|
11609
|
+
const tokenResp = await getGithubToken(bambooSession);
|
|
11610
|
+
spinner.succeed("GitHub authorization complete");
|
|
11611
|
+
return tokenResp;
|
|
11612
|
+
} catch (err) {
|
|
11613
|
+
if (err instanceof ApiError) {
|
|
11614
|
+
if (err.status === 401) {
|
|
11615
|
+
spinner.fail(
|
|
11616
|
+
"Your Bamboo session expired. Re-run `bamboo-agents login`."
|
|
11617
|
+
);
|
|
11618
|
+
return null;
|
|
11619
|
+
}
|
|
11620
|
+
if (err.status === 410) {
|
|
11621
|
+
spinner.fail(
|
|
11622
|
+
"Your GitHub token expired. Sign in to Bamboo with GitHub again, then re-run."
|
|
11623
|
+
);
|
|
11624
|
+
return null;
|
|
11625
|
+
}
|
|
11626
|
+
}
|
|
11627
|
+
continue;
|
|
11628
|
+
}
|
|
11584
11629
|
}
|
|
11630
|
+
spinner.fail(
|
|
11631
|
+
`Timed out waiting for GitHub authorization. Re-run \`bamboo-agents login\` after authorizing in your browser.`
|
|
11632
|
+
);
|
|
11633
|
+
return null;
|
|
11585
11634
|
}
|
|
11586
11635
|
async function startCallbackServer(expectedState) {
|
|
11587
11636
|
let resolveSession;
|
|
@@ -11688,22 +11737,23 @@ async function runLogin() {
|
|
|
11688
11737
|
let tokenResp;
|
|
11689
11738
|
try {
|
|
11690
11739
|
tokenResp = await getGithubToken(bambooSession);
|
|
11740
|
+
tokenSpinner.succeed("GitHub token retrieved");
|
|
11691
11741
|
} catch (err) {
|
|
11692
11742
|
if (err instanceof ApiError && err.status === 404) {
|
|
11693
11743
|
tokenSpinner.warn(
|
|
11694
11744
|
"No GitHub token linked yet \u2014 opening browser to authorize Bamboo with GitHub\u2026"
|
|
11695
11745
|
);
|
|
11696
|
-
const
|
|
11697
|
-
process.exit(
|
|
11698
|
-
|
|
11699
|
-
if (err instanceof ApiError && err.status === 410) {
|
|
11746
|
+
const polled = await handleMissingGithubToken(bambooSession);
|
|
11747
|
+
if (!polled) process.exit(1);
|
|
11748
|
+
tokenResp = polled;
|
|
11749
|
+
} else if (err instanceof ApiError && err.status === 410) {
|
|
11700
11750
|
tokenSpinner.fail("Your GitHub token expired. Sign in to Bamboo with GitHub again, then re-run.");
|
|
11701
11751
|
process.exit(1);
|
|
11752
|
+
} else {
|
|
11753
|
+
tokenSpinner.fail(`Couldn't fetch GitHub token: ${err.message}`);
|
|
11754
|
+
process.exit(1);
|
|
11702
11755
|
}
|
|
11703
|
-
tokenSpinner.fail(`Couldn't fetch GitHub token: ${err.message}`);
|
|
11704
|
-
process.exit(1);
|
|
11705
11756
|
}
|
|
11706
|
-
tokenSpinner.succeed("GitHub token retrieved");
|
|
11707
11757
|
await writeCredentials({
|
|
11708
11758
|
bamboo_session: bambooSession,
|
|
11709
11759
|
github_token: tokenResp.access_token,
|
|
@@ -11718,7 +11768,7 @@ async function runLogin() {
|
|
|
11718
11768
|
console.log(" Next: `bamboo-agents init` to clone your workspace.");
|
|
11719
11769
|
console.log("");
|
|
11720
11770
|
}
|
|
11721
|
-
var FALLBACK_RELINK_URL, LOGIN_TIMEOUT_MS;
|
|
11771
|
+
var FALLBACK_RELINK_URL, LOGIN_TIMEOUT_MS, TOKEN_POLL;
|
|
11722
11772
|
var init_login = __esm({
|
|
11723
11773
|
"src/commands/login.ts"() {
|
|
11724
11774
|
"use strict";
|
|
@@ -11726,8 +11776,13 @@ var init_login = __esm({
|
|
|
11726
11776
|
init_ora();
|
|
11727
11777
|
init_api();
|
|
11728
11778
|
init_credentials();
|
|
11779
|
+
init_util2();
|
|
11729
11780
|
FALLBACK_RELINK_URL = "https://withbamboo.com/connect-github";
|
|
11730
11781
|
LOGIN_TIMEOUT_MS = 5 * 60 * 1e3;
|
|
11782
|
+
TOKEN_POLL = {
|
|
11783
|
+
intervalMs: 2e3,
|
|
11784
|
+
timeoutMs: 5 * 60 * 1e3
|
|
11785
|
+
};
|
|
11731
11786
|
}
|
|
11732
11787
|
});
|
|
11733
11788
|
|
|
@@ -11875,14 +11930,53 @@ var init_state = __esm({
|
|
|
11875
11930
|
// src/commands/init.ts
|
|
11876
11931
|
var init_exports = {};
|
|
11877
11932
|
__export(init_exports, {
|
|
11933
|
+
WORKSPACE_POLL: () => WORKSPACE_POLL,
|
|
11934
|
+
pollForWorkspaceReady: () => pollForWorkspaceReady,
|
|
11935
|
+
preProvisionWorkspace: () => preProvisionWorkspace,
|
|
11878
11936
|
runInit: () => runInit,
|
|
11879
11937
|
slugify: () => slugify
|
|
11880
11938
|
});
|
|
11881
11939
|
import { access } from "node:fs/promises";
|
|
11882
11940
|
import { resolve as pathResolve } from "node:path";
|
|
11941
|
+
async function pollForWorkspaceReady(bambooSession, initial) {
|
|
11942
|
+
if (initial.workspace_ready && initial.org.workspace_repo) {
|
|
11943
|
+
return { ok: true, membership: initial };
|
|
11944
|
+
}
|
|
11945
|
+
const start = Date.now();
|
|
11946
|
+
while (Date.now() - start < WORKSPACE_POLL.timeoutMs) {
|
|
11947
|
+
await sleep(WORKSPACE_POLL.intervalMs);
|
|
11948
|
+
let fresh;
|
|
11949
|
+
try {
|
|
11950
|
+
fresh = await getCliAuthStatus(bambooSession);
|
|
11951
|
+
} catch (err) {
|
|
11952
|
+
if (err instanceof ApiError && err.status === 401) {
|
|
11953
|
+
return { ok: false, reason: "session_expired" };
|
|
11954
|
+
}
|
|
11955
|
+
continue;
|
|
11956
|
+
}
|
|
11957
|
+
const m = fresh.memberships[0];
|
|
11958
|
+
if (m?.workspace_ready && m.org.workspace_repo) {
|
|
11959
|
+
return { ok: true, membership: m };
|
|
11960
|
+
}
|
|
11961
|
+
}
|
|
11962
|
+
return { ok: false, reason: "timeout" };
|
|
11963
|
+
}
|
|
11883
11964
|
function slugify(input) {
|
|
11884
11965
|
return input.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "");
|
|
11885
11966
|
}
|
|
11967
|
+
async function preProvisionWorkspace(bambooSession, call = provisionWorkspace) {
|
|
11968
|
+
try {
|
|
11969
|
+
const result = await call(bambooSession);
|
|
11970
|
+
return { kind: "ok", workspaceRepo: result.workspace_repo };
|
|
11971
|
+
} catch (err) {
|
|
11972
|
+
if (err instanceof ApiError) {
|
|
11973
|
+
if (err.status === 412) return { kind: "fatal_412" };
|
|
11974
|
+
if (err.status === 403) return { kind: "fatal_403" };
|
|
11975
|
+
if (err.status === 401) return { kind: "fatal_401" };
|
|
11976
|
+
}
|
|
11977
|
+
return { kind: "transient", message: err.message };
|
|
11978
|
+
}
|
|
11979
|
+
}
|
|
11886
11980
|
async function runInit() {
|
|
11887
11981
|
const creds = await readCredentials();
|
|
11888
11982
|
if (!creds) {
|
|
@@ -11921,12 +12015,55 @@ async function runInit() {
|
|
|
11921
12015
|
console.error(`Orgs: ${status.memberships.map((m) => m.org.name).join(", ")}`);
|
|
11922
12016
|
process.exit(2);
|
|
11923
12017
|
}
|
|
11924
|
-
const
|
|
11925
|
-
|
|
11926
|
-
|
|
11927
|
-
|
|
11928
|
-
|
|
11929
|
-
|
|
12018
|
+
const initialMembership = status.memberships[0];
|
|
12019
|
+
let membership;
|
|
12020
|
+
if (initialMembership.workspace_ready && initialMembership.org.workspace_repo) {
|
|
12021
|
+
membership = initialMembership;
|
|
12022
|
+
} else {
|
|
12023
|
+
const provisionSpinner = ora("Setting up your workspace\u2026").start();
|
|
12024
|
+
const provisionResult = await preProvisionWorkspace(creds.bamboo_session);
|
|
12025
|
+
if (provisionResult.kind === "ok") {
|
|
12026
|
+
provisionSpinner.succeed(
|
|
12027
|
+
`Workspace repo ready: ${provisionResult.workspaceRepo}`
|
|
12028
|
+
);
|
|
12029
|
+
} else if (provisionResult.kind === "fatal_412") {
|
|
12030
|
+
provisionSpinner.fail(
|
|
12031
|
+
"GitHub isn't connected. Run `bamboo-agents login` first."
|
|
12032
|
+
);
|
|
12033
|
+
process.exit(2);
|
|
12034
|
+
} else if (provisionResult.kind === "fatal_403") {
|
|
12035
|
+
provisionSpinner.fail(
|
|
12036
|
+
"Only org admins can create the workspace. Ask an admin to run `bamboo-agents init` once."
|
|
12037
|
+
);
|
|
12038
|
+
process.exit(2);
|
|
12039
|
+
} else if (provisionResult.kind === "fatal_401") {
|
|
12040
|
+
provisionSpinner.fail(
|
|
12041
|
+
"Your Bamboo session expired. Run `bamboo-agents login` again."
|
|
12042
|
+
);
|
|
12043
|
+
process.exit(1);
|
|
12044
|
+
} else {
|
|
12045
|
+
provisionSpinner.warn(
|
|
12046
|
+
`Couldn't pre-provision workspace (${provisionResult.message}); falling back to polling\u2026`
|
|
12047
|
+
);
|
|
12048
|
+
}
|
|
12049
|
+
const pollSpinner = ora(
|
|
12050
|
+
`Waiting for ${initialMembership.org.name}'s workspace to be ready\u2026`
|
|
12051
|
+
).start();
|
|
12052
|
+
const result = await pollForWorkspaceReady(creds.bamboo_session, initialMembership);
|
|
12053
|
+
if (!result.ok) {
|
|
12054
|
+
if (result.reason === "session_expired") {
|
|
12055
|
+
pollSpinner.fail(
|
|
12056
|
+
"Your Bamboo session expired. Run `bamboo-agents login` again."
|
|
12057
|
+
);
|
|
12058
|
+
process.exit(1);
|
|
12059
|
+
}
|
|
12060
|
+
pollSpinner.fail(
|
|
12061
|
+
`Timed out waiting for ${initialMembership.org.name}'s workspace. If you just connected GitHub, give it another moment and re-run \`bamboo-agents init\`.`
|
|
12062
|
+
);
|
|
12063
|
+
process.exit(2);
|
|
12064
|
+
}
|
|
12065
|
+
membership = result.membership;
|
|
12066
|
+
pollSpinner.succeed(`Workspace ready: ${membership.org.workspace_repo}`);
|
|
11930
12067
|
}
|
|
11931
12068
|
const gitSpinner = ora("Checking git\u2026").start();
|
|
11932
12069
|
const version = await gitVersion();
|
|
@@ -12001,6 +12138,7 @@ async function runInit() {
|
|
|
12001
12138
|
console.log(" Next: `bamboo-agents open` to launch Claude Code there.");
|
|
12002
12139
|
console.log("");
|
|
12003
12140
|
}
|
|
12141
|
+
var WORKSPACE_POLL;
|
|
12004
12142
|
var init_init = __esm({
|
|
12005
12143
|
"src/commands/init.ts"() {
|
|
12006
12144
|
"use strict";
|
|
@@ -12009,6 +12147,11 @@ var init_init = __esm({
|
|
|
12009
12147
|
init_credentials();
|
|
12010
12148
|
init_git();
|
|
12011
12149
|
init_state();
|
|
12150
|
+
init_util2();
|
|
12151
|
+
WORKSPACE_POLL = {
|
|
12152
|
+
intervalMs: 2e3,
|
|
12153
|
+
timeoutMs: 5 * 60 * 1e3
|
|
12154
|
+
};
|
|
12012
12155
|
}
|
|
12013
12156
|
});
|
|
12014
12157
|
|