bamboo-agents 0.1.0 → 0.1.2

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/README.md CHANGED
@@ -22,7 +22,7 @@ See the design doc in the parent repo: `docs/product/cli-onboarding-design.md`.
22
22
 
23
23
  ## Development
24
24
 
25
- This CLI lives in the [bamboo-ui](https://github.com/jjwjr94/bamboo-ui-efdaf585)
25
+ This CLI lives in the [bamboo-ui](https://github.com/bamboo-ai-nyc/bamboo-ui)
26
26
  monorepo under `packages/cli/`. From the repo root:
27
27
 
28
28
  ```bash
package/dist/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.1.2
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.2";
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
- async function fetchWithTimeout(url, init) {
11413
- return fetch(url, { ...init, signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS) });
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 fetchWithTimeout(`${apiBase()}/api/auth/github/token`, {
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,22 @@ async function getGithubToken(bambooSession) {
11421
11443
  return AuthTokenSuccessSchema.parse(json);
11422
11444
  }
11423
11445
  async function getCliAuthStatus(bambooSession) {
11424
- const res = await fetchWithTimeout(`${apiBase()}/api/cli/auth/status`, {
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
- var DEFAULT_BASE, ApiError, REQUEST_TIMEOUT_MS;
11453
+ var DEFAULT_BASE, REQUEST_TIMEOUT_MS, ApiError;
11432
11454
  var init_api = __esm({
11433
11455
  "src/lib/api.ts"() {
11434
11456
  "use strict";
11435
11457
  init_auth_token();
11436
11458
  init_auth_status();
11459
+ init_version();
11437
11460
  DEFAULT_BASE = "https://withbamboo.com";
11461
+ REQUEST_TIMEOUT_MS = 3e4;
11438
11462
  ApiError = class extends Error {
11439
11463
  constructor(message, status, errorCode) {
11440
11464
  super(message);
@@ -11443,7 +11467,6 @@ var init_api = __esm({
11443
11467
  this.name = "ApiError";
11444
11468
  }
11445
11469
  };
11446
- REQUEST_TIMEOUT_MS = 3e4;
11447
11470
  }
11448
11471
  });
11449
11472
 
@@ -11508,6 +11531,7 @@ var init_credentials = __esm({
11508
11531
  var login_exports = {};
11509
11532
  __export(login_exports, {
11510
11533
  runLogin: () => runLogin,
11534
+ startCallbackServer: () => startCallbackServer,
11511
11535
  verificationCode: () => verificationCode
11512
11536
  });
11513
11537
  import { randomBytes } from "node:crypto";
@@ -11550,10 +11574,8 @@ async function startCallbackServer(expectedState) {
11550
11574
  let body;
11551
11575
  try {
11552
11576
  body = JSON.parse(Buffer.concat(chunks).toString("utf8"));
11553
- } catch (err) {
11577
+ } catch {
11554
11578
  respondCors(400, { error: "invalid_json" });
11555
- rejectSession(new Error(`Bad callback body: ${err.message}`));
11556
- setTimeout(() => server.close(), 100);
11557
11579
  return;
11558
11580
  }
11559
11581
  if (typeof body.session !== "string" || typeof body.state !== "string") {
@@ -11561,9 +11583,10 @@ async function startCallbackServer(expectedState) {
11561
11583
  return;
11562
11584
  }
11563
11585
  if (body.state !== expectedState) {
11586
+ console.warn(
11587
+ " (ignored a callback with a mismatched state token \u2014 keep the browser tab open)"
11588
+ );
11564
11589
  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
11590
  return;
11568
11591
  }
11569
11592
  respondCors(200, { ok: true });
@@ -11715,6 +11738,29 @@ async function cloneRepo(repoFullName, targetDir) {
11715
11738
  );
11716
11739
  }
11717
11740
  }
11741
+ async function checkGitCredentialForGitHub() {
11742
+ return new Promise((resolve) => {
11743
+ const proc = execFile6(
11744
+ "git",
11745
+ ["credential", "fill"],
11746
+ {
11747
+ encoding: "utf8",
11748
+ env: { ...process.env, GIT_TERMINAL_PROMPT: "0" }
11749
+ },
11750
+ (err, stdout) => {
11751
+ if (err) {
11752
+ resolve(false);
11753
+ return;
11754
+ }
11755
+ const hasOurUsername = /^username=x-access-token\s*$/m.test(stdout);
11756
+ const hasPassword = /^password=\S+/m.test(stdout);
11757
+ resolve(hasOurUsername && hasPassword);
11758
+ }
11759
+ );
11760
+ proc.stdin?.write("protocol=https\nhost=github.com\n\n");
11761
+ proc.stdin?.end();
11762
+ });
11763
+ }
11718
11764
  async function getGitConfig(key) {
11719
11765
  try {
11720
11766
  const { stdout } = await execFileP("git", ["config", "--global", "--get", key], {
@@ -11923,6 +11969,49 @@ var init_init = __esm({
11923
11969
  }
11924
11970
  });
11925
11971
 
11972
+ // src/lib/claude-desktop.ts
11973
+ import { execFile as execFile7 } from "node:child_process";
11974
+ import { platform as platform3 } from "node:os";
11975
+ import { promisify as promisify7 } from "node:util";
11976
+ async function detectClaudeDesktop() {
11977
+ const plat = platform3();
11978
+ if (plat === "darwin") return await detectMacOS();
11979
+ if (plat === "win32") return await detectWindows();
11980
+ return { kind: "unsupported_platform" };
11981
+ }
11982
+ async function detectMacOS() {
11983
+ try {
11984
+ const { stdout } = await execFileP2(
11985
+ "mdfind",
11986
+ [`kMDItemCFBundleIdentifier == "${MACOS_BUNDLE_ID}"`],
11987
+ { encoding: "utf8" }
11988
+ );
11989
+ return stdout.trim().length > 0 ? { kind: "installed" } : { kind: "missing" };
11990
+ } catch {
11991
+ return { kind: "missing" };
11992
+ }
11993
+ }
11994
+ async function detectWindows() {
11995
+ try {
11996
+ await execFileP2(
11997
+ "reg",
11998
+ ["query", "HKCU\\Software\\Classes\\claude"],
11999
+ { encoding: "utf8" }
12000
+ );
12001
+ return { kind: "installed" };
12002
+ } catch {
12003
+ return { kind: "missing" };
12004
+ }
12005
+ }
12006
+ var execFileP2, MACOS_BUNDLE_ID;
12007
+ var init_claude_desktop = __esm({
12008
+ "src/lib/claude-desktop.ts"() {
12009
+ "use strict";
12010
+ execFileP2 = promisify7(execFile7);
12011
+ MACOS_BUNDLE_ID = "com.anthropic.claudefordesktop";
12012
+ }
12013
+ });
12014
+
11926
12015
  // src/commands/open.ts
11927
12016
  var open_exports = {};
11928
12017
  __export(open_exports, {
@@ -11934,16 +12023,34 @@ async function runOpen() {
11934
12023
  console.error("No workspace configured. Run `bamboo-agents init` first.");
11935
12024
  process.exit(2);
11936
12025
  }
12026
+ const status = await detectClaudeDesktop();
12027
+ if (status.kind === "missing") {
12028
+ console.error(
12029
+ `Claude Desktop isn't installed. Get it at ${DOWNLOAD_URL}, then re-run \`bamboo-agents open\`.`
12030
+ );
12031
+ console.error(`(Your workspace is cloned at ${cfg.repo_path}.)`);
12032
+ process.exit(1);
12033
+ }
12034
+ if (status.kind === "unsupported_platform") {
12035
+ console.log("");
12036
+ console.log(" Claude Desktop isn't available on Linux yet.");
12037
+ console.log(` Your workspace is cloned at: ${cfg.repo_path}`);
12038
+ console.log("");
12039
+ return;
12040
+ }
11937
12041
  const url = `claude://code/new?folder=${encodeURIComponent(cfg.repo_path)}`;
11938
12042
  await open_default(url);
11939
12043
  console.log(`Opening Claude Code at ${cfg.repo_path}\u2026`);
11940
12044
  console.log("(Claude Desktop will ask you to trust the folder the first time.)");
11941
12045
  }
12046
+ var DOWNLOAD_URL;
11942
12047
  var init_open2 = __esm({
11943
12048
  "src/commands/open.ts"() {
11944
12049
  "use strict";
11945
12050
  init_open();
12051
+ init_claude_desktop();
11946
12052
  init_state();
12053
+ DOWNLOAD_URL = "https://claude.com/download";
11947
12054
  }
11948
12055
  });
11949
12056
 
@@ -11990,6 +12097,8 @@ var init_status = __esm({
11990
12097
  // src/commands/doctor.ts
11991
12098
  var doctor_exports = {};
11992
12099
  __export(doctor_exports, {
12100
+ checkBambooSession: () => checkBambooSession,
12101
+ checkGitCredential: () => checkGitCredential,
11993
12102
  runDoctor: () => runDoctor
11994
12103
  });
11995
12104
  import { access as access2 } from "node:fs/promises";
@@ -12011,26 +12120,57 @@ async function checkGit() {
12011
12120
  }
12012
12121
  return { name: "git installed", ok: true, detail: v.join(".") };
12013
12122
  }
12014
- async function checkCredentials() {
12123
+ async function checkBambooSession() {
12015
12124
  const c = await readCredentials();
12016
12125
  if (!c) {
12017
12126
  return {
12018
- name: "Bamboo credentials",
12127
+ name: "Bamboo session",
12019
12128
  ok: false,
12020
12129
  detail: "missing \u2014 run `bamboo-agents login`."
12021
12130
  };
12022
12131
  }
12023
12132
  if (c.github_token_expires_at && new Date(c.github_token_expires_at).getTime() < Date.now()) {
12024
12133
  return {
12025
- name: "Bamboo credentials",
12134
+ name: "Bamboo session",
12026
12135
  ok: false,
12027
12136
  detail: "GitHub token expired \u2014 run `bamboo-agents login` again."
12028
12137
  };
12029
12138
  }
12139
+ try {
12140
+ await getCliAuthStatus(c.bamboo_session);
12141
+ return {
12142
+ name: "Bamboo session",
12143
+ ok: true,
12144
+ detail: c.github_username ? `@${c.github_username}` : "valid"
12145
+ };
12146
+ } catch (err) {
12147
+ if (err instanceof ApiError && err.status === 401) {
12148
+ return {
12149
+ name: "Bamboo session",
12150
+ ok: false,
12151
+ detail: "session expired \u2014 run `bamboo-agents login` again."
12152
+ };
12153
+ }
12154
+ return {
12155
+ name: "Bamboo session",
12156
+ ok: false,
12157
+ detail: `couldn't reach Bamboo \u2014 check connectivity (${err.message}).`
12158
+ };
12159
+ }
12160
+ }
12161
+ async function checkGitCredential() {
12162
+ const ok = await checkGitCredentialForGitHub();
12163
+ if (ok) {
12164
+ return {
12165
+ name: "Git credential",
12166
+ ok: true,
12167
+ detail: "github.com entry present in credential helper"
12168
+ };
12169
+ }
12030
12170
  return {
12031
- name: "Bamboo credentials",
12032
- ok: true,
12033
- detail: c.github_username ? `@${c.github_username}` : "present"
12171
+ name: "Git credential",
12172
+ ok: false,
12173
+ detail: "no github.com entry in git's credential helper \u2014 run `bamboo-agents login` then `bamboo-agents init` to reinstall."
12034
12174
  };
12035
12175
  }
12036
12176
  async function checkConfig() {
@@ -12067,7 +12207,8 @@ async function checkRepoPath() {
12067
12207
  async function runDoctor() {
12068
12208
  const checks = await Promise.all([
12069
12209
  checkGit(),
12070
- checkCredentials(),
12210
+ checkBambooSession(),
12211
+ checkGitCredential(),
12071
12212
  checkConfig(),
12072
12213
  checkRepoPath()
12073
12214
  ]);
@@ -12087,6 +12228,7 @@ async function runDoctor() {
12087
12228
  var init_doctor = __esm({
12088
12229
  "src/commands/doctor.ts"() {
12089
12230
  "use strict";
12231
+ init_api();
12090
12232
  init_git();
12091
12233
  init_state();
12092
12234
  init_credentials();
@@ -12111,7 +12253,7 @@ var {
12111
12253
  } = import_index.default;
12112
12254
 
12113
12255
  // src/index.ts
12114
- var VERSION = "0.1.0";
12256
+ init_version();
12115
12257
  var program2 = new Command();
12116
12258
  program2.name("bamboo-agents").description("Set up your local Bamboo workspace and drop into Claude.").version(VERSION);
12117
12259
  program2.command("login").description("Sign in to Bamboo via your browser").action(async () => {