bamboo-agents 0.1.5-dev.39.69fcffd → 0.1.5-dev.40.51dbc4d

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/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.5-dev.39.69fcffd";
3040
+ VERSION = "0.1.5-dev.40.51dbc4d";
3041
3041
  }
3042
3042
  });
3043
3043
 
@@ -7351,6 +7351,234 @@ var init_state = __esm({
7351
7351
  }
7352
7352
  });
7353
7353
 
7354
+ // src/lib/git.ts
7355
+ var git_exports = {};
7356
+ __export(git_exports, {
7357
+ GitError: () => GitError,
7358
+ checkGitCredentialForGitHub: () => checkGitCredentialForGitHub,
7359
+ cloneRepo: () => cloneRepo,
7360
+ getGitConfig: () => getGitConfig,
7361
+ getRepoRemoteUrl: () => getRepoRemoteUrl,
7362
+ gitPullFFOnly: () => gitPullFFOnly,
7363
+ gitVersion: () => gitVersion,
7364
+ installGithubCredential: () => installGithubCredential,
7365
+ isGitRecentEnough: () => isGitRecentEnough,
7366
+ remoteUrlMatchesRepo: () => remoteUrlMatchesRepo
7367
+ });
7368
+ import { execFile } from "node:child_process";
7369
+ import { promisify } from "node:util";
7370
+ async function gitVersion() {
7371
+ try {
7372
+ const { stdout } = await execFileP("git", ["--version"], { encoding: "utf8" });
7373
+ const m = stdout.match(/git version (\d+)\.(\d+)\.(\d+)/);
7374
+ if (!m) return null;
7375
+ return [Number(m[1]), Number(m[2]), Number(m[3])];
7376
+ } catch (err) {
7377
+ if (err.code === "ENOENT") return null;
7378
+ throw err;
7379
+ }
7380
+ }
7381
+ function isGitRecentEnough(version) {
7382
+ const [major, minor] = version;
7383
+ return major > 2 || major === 2 && minor >= 11;
7384
+ }
7385
+ async function installGithubCredential(token) {
7386
+ const input = `protocol=https
7387
+ host=github.com
7388
+ username=x-access-token
7389
+ password=${token}
7390
+
7391
+ `;
7392
+ const child = execFile("git", ["credential", "approve"], { encoding: "utf8" });
7393
+ const proc = child;
7394
+ proc.stdin?.write(input);
7395
+ proc.stdin?.end();
7396
+ await new Promise((resolve2, reject) => {
7397
+ proc.on("exit", (code) => {
7398
+ if (code === 0) resolve2();
7399
+ else reject(new GitError(`git credential approve exited with code ${code}`));
7400
+ });
7401
+ proc.on("error", reject);
7402
+ });
7403
+ }
7404
+ async function cloneRepo(repoFullName, targetDir) {
7405
+ const url = `https://github.com/${repoFullName}.git`;
7406
+ try {
7407
+ await execFileP("git", ["clone", url, targetDir], { encoding: "utf8" });
7408
+ } catch (err) {
7409
+ const errAny = err;
7410
+ throw new GitError(
7411
+ `git clone failed: ${errAny.stderr ?? errAny.message}`,
7412
+ errAny.stdout,
7413
+ errAny.stderr
7414
+ );
7415
+ }
7416
+ }
7417
+ async function checkGitCredentialForGitHub() {
7418
+ return new Promise((resolve2) => {
7419
+ const proc = execFile(
7420
+ "git",
7421
+ ["credential", "fill"],
7422
+ {
7423
+ encoding: "utf8",
7424
+ env: { ...process.env, GIT_TERMINAL_PROMPT: "0" }
7425
+ },
7426
+ (err, stdout) => {
7427
+ if (err) {
7428
+ resolve2(false);
7429
+ return;
7430
+ }
7431
+ const hasOurUsername = /^username=x-access-token\s*$/m.test(stdout);
7432
+ const hasPassword = /^password=\S+/m.test(stdout);
7433
+ resolve2(hasOurUsername && hasPassword);
7434
+ }
7435
+ );
7436
+ proc.stdin?.write("protocol=https\nhost=github.com\n\n");
7437
+ proc.stdin?.end();
7438
+ });
7439
+ }
7440
+ async function getRepoRemoteUrl(repoPath, remoteName = "origin") {
7441
+ try {
7442
+ const { stdout } = await execFileP(
7443
+ "git",
7444
+ ["-C", repoPath, "remote", "get-url", remoteName],
7445
+ { encoding: "utf8" }
7446
+ );
7447
+ return stdout.trim() || null;
7448
+ } catch {
7449
+ return null;
7450
+ }
7451
+ }
7452
+ function remoteUrlMatchesRepo(remoteUrl, repoFullName) {
7453
+ const expected = repoFullName.replace(/\.git$/i, "").toLowerCase();
7454
+ const url = remoteUrl.trim().replace(/\.git$/i, "");
7455
+ const httpsMatch = url.match(/^https?:\/\/[^/]*github\.com\/(.+)$/i);
7456
+ if (httpsMatch && httpsMatch[1].toLowerCase() === expected) return true;
7457
+ const sshMatch = url.match(/^[^@]+@github\.com:(.+)$/i);
7458
+ if (sshMatch && sshMatch[1].toLowerCase() === expected) return true;
7459
+ return false;
7460
+ }
7461
+ async function gitPullFFOnly(repoPath) {
7462
+ try {
7463
+ await execFileP("git", ["-C", repoPath, "pull", "--ff-only"], {
7464
+ encoding: "utf8"
7465
+ });
7466
+ } catch (err) {
7467
+ const errAny = err;
7468
+ const stderr = (errAny.stderr ?? "").toLowerCase();
7469
+ let summary;
7470
+ if (stderr.includes("non-fast-forward") || stderr.includes("not possible to fast-forward")) {
7471
+ summary = "local branch has diverged from origin \u2014 commit or `save-bamboo` first, then retry";
7472
+ } else if (stderr.includes("uncommitted") || stderr.includes("would be overwritten")) {
7473
+ summary = "uncommitted changes block fast-forward \u2014 commit or `save-bamboo` first, then retry";
7474
+ } else {
7475
+ summary = (errAny.stderr ?? errAny.message).trim().split("\n")[0] ?? errAny.message;
7476
+ }
7477
+ throw new GitError(summary, errAny.stdout, errAny.stderr);
7478
+ }
7479
+ }
7480
+ async function getGitConfig(key) {
7481
+ try {
7482
+ const { stdout } = await execFileP("git", ["config", "--global", "--get", key], {
7483
+ encoding: "utf8"
7484
+ });
7485
+ return stdout.trim() || null;
7486
+ } catch (err) {
7487
+ if (err.code === 1) return null;
7488
+ throw err;
7489
+ }
7490
+ }
7491
+ var execFileP, GitError;
7492
+ var init_git = __esm({
7493
+ "src/lib/git.ts"() {
7494
+ "use strict";
7495
+ execFileP = promisify(execFile);
7496
+ GitError = class extends Error {
7497
+ constructor(message, stdout, stderr) {
7498
+ super(message);
7499
+ this.stdout = stdout;
7500
+ this.stderr = stderr;
7501
+ this.name = "GitError";
7502
+ }
7503
+ };
7504
+ }
7505
+ });
7506
+
7507
+ // src/lib/workspace.ts
7508
+ import { existsSync } from "node:fs";
7509
+ import os from "node:os";
7510
+ import { resolve as pathResolve } from "node:path";
7511
+ function defaultClonePath(orgSlug) {
7512
+ const cleanSlug = orgSlug.replace(/^bamboo-?/i, "") || orgSlug;
7513
+ return pathResolve(os.homedir(), "Bamboo", cleanSlug);
7514
+ }
7515
+ async function resolveWorkspace() {
7516
+ const state = await readState();
7517
+ if (state) {
7518
+ if (!existsSync(state.workspace_path)) {
7519
+ throw new NoWorkspaceError(
7520
+ `Bamboo workspace not found.
7521
+ (State recorded ${state.workspace_path} but it's missing on disk \u2014 run \`bamboo-agents init --reset\` to re-clone.)`
7522
+ );
7523
+ }
7524
+ return { path: state.workspace_path, orgId: state.org_id };
7525
+ }
7526
+ const config = await readConfig();
7527
+ if (config) {
7528
+ if (!existsSync(config.repo_path)) {
7529
+ throw new NoWorkspaceError(
7530
+ `Bamboo workspace not found.
7531
+ (Config recorded ${config.repo_path} but it's missing on disk \u2014 run \`bamboo-agents init --reset\` to re-clone.)`
7532
+ );
7533
+ }
7534
+ return { path: config.repo_path, orgId: config.org_id };
7535
+ }
7536
+ throw new NoWorkspaceError(
7537
+ "No Bamboo workspace yet. Run `bamboo-agents init` first."
7538
+ );
7539
+ }
7540
+ function shouldAutoSync() {
7541
+ if (process.env.BAMBOO_AUTO_SYNC === "false") return false;
7542
+ if (process.argv.includes("--no-sync")) return false;
7543
+ return true;
7544
+ }
7545
+ async function withFreshWorkspace(fn) {
7546
+ if (!shouldAutoSync()) return fn();
7547
+ let state;
7548
+ try {
7549
+ state = await readState();
7550
+ } catch {
7551
+ return fn();
7552
+ }
7553
+ if (!state) return fn();
7554
+ const lastSyncMs = new Date(state.last_sync).getTime();
7555
+ const since = Number.isFinite(lastSyncMs) ? Date.now() - lastSyncMs : Infinity;
7556
+ if (since < AUTO_SYNC_MIN_INTERVAL_MS) return fn();
7557
+ try {
7558
+ await gitPullFFOnly(state.workspace_path);
7559
+ await updateLastSync(/* @__PURE__ */ new Date());
7560
+ } catch (err) {
7561
+ const msg = err instanceof Error ? err.message : String(err);
7562
+ console.warn(`[bamboo] auto-sync warning: ${msg}`);
7563
+ }
7564
+ return fn();
7565
+ }
7566
+ var NoWorkspaceError, AUTO_SYNC_MIN_INTERVAL_MS;
7567
+ var init_workspace = __esm({
7568
+ "src/lib/workspace.ts"() {
7569
+ "use strict";
7570
+ init_git();
7571
+ init_state();
7572
+ NoWorkspaceError = class extends Error {
7573
+ constructor(message) {
7574
+ super(message);
7575
+ this.name = "NoWorkspaceError";
7576
+ }
7577
+ };
7578
+ AUTO_SYNC_MIN_INTERVAL_MS = 6e4;
7579
+ }
7580
+ });
7581
+
7354
7582
  // ../../node_modules/is-docker/index.js
7355
7583
  import fs from "node:fs";
7356
7584
  function hasDockerEnv() {
@@ -7405,7 +7633,7 @@ var init_is_inside_container = __esm({
7405
7633
 
7406
7634
  // ../../node_modules/is-wsl/index.js
7407
7635
  import process2 from "node:process";
7408
- import os from "node:os";
7636
+ import os2 from "node:os";
7409
7637
  import fs3 from "node:fs";
7410
7638
  var isWsl, is_wsl_default;
7411
7639
  var init_is_wsl = __esm({
@@ -7415,7 +7643,7 @@ var init_is_wsl = __esm({
7415
7643
  if (process2.platform !== "linux") {
7416
7644
  return false;
7417
7645
  }
7418
- if (os.release().toLowerCase().includes("microsoft")) {
7646
+ if (os2.release().toLowerCase().includes("microsoft")) {
7419
7647
  if (isInsideContainer()) {
7420
7648
  return false;
7421
7649
  }
@@ -7507,9 +7735,9 @@ var init_define_lazy_prop = __esm({
7507
7735
  });
7508
7736
 
7509
7737
  // ../../node_modules/default-browser-id/index.js
7510
- import { promisify } from "node:util";
7738
+ import { promisify as promisify2 } from "node:util";
7511
7739
  import process4 from "node:process";
7512
- import { execFile } from "node:child_process";
7740
+ import { execFile as execFile2 } from "node:child_process";
7513
7741
  async function defaultBrowserId() {
7514
7742
  if (process4.platform !== "darwin") {
7515
7743
  throw new Error("macOS only");
@@ -7525,14 +7753,14 @@ async function defaultBrowserId() {
7525
7753
  var execFileAsync;
7526
7754
  var init_default_browser_id = __esm({
7527
7755
  "../../node_modules/default-browser-id/index.js"() {
7528
- execFileAsync = promisify(execFile);
7756
+ execFileAsync = promisify2(execFile2);
7529
7757
  }
7530
7758
  });
7531
7759
 
7532
7760
  // ../../node_modules/run-applescript/index.js
7533
7761
  import process5 from "node:process";
7534
- import { promisify as promisify2 } from "node:util";
7535
- import { execFile as execFile2, execFileSync } from "node:child_process";
7762
+ import { promisify as promisify3 } from "node:util";
7763
+ import { execFile as execFile3, execFileSync } from "node:child_process";
7536
7764
  async function runAppleScript(script, { humanReadableOutput = true, signal } = {}) {
7537
7765
  if (process5.platform !== "darwin") {
7538
7766
  throw new Error("macOS only");
@@ -7548,7 +7776,7 @@ async function runAppleScript(script, { humanReadableOutput = true, signal } = {
7548
7776
  var execFileAsync2;
7549
7777
  var init_run_applescript = __esm({
7550
7778
  "../../node_modules/run-applescript/index.js"() {
7551
- execFileAsync2 = promisify2(execFile2);
7779
+ execFileAsync2 = promisify3(execFile3);
7552
7780
  }
7553
7781
  });
7554
7782
 
@@ -7564,8 +7792,8 @@ var init_bundle_name = __esm({
7564
7792
  });
7565
7793
 
7566
7794
  // ../../node_modules/default-browser/windows.js
7567
- import { promisify as promisify3 } from "node:util";
7568
- import { execFile as execFile3 } from "node:child_process";
7795
+ import { promisify as promisify4 } from "node:util";
7796
+ import { execFile as execFile4 } from "node:child_process";
7569
7797
  async function defaultBrowser(_execFileAsync = execFileAsync3) {
7570
7798
  const { stdout } = await _execFileAsync("reg", [
7571
7799
  "QUERY",
@@ -7587,7 +7815,7 @@ async function defaultBrowser(_execFileAsync = execFileAsync3) {
7587
7815
  var execFileAsync3, windowsBrowserProgIds, _windowsBrowserProgIdMap, UnknownBrowserError;
7588
7816
  var init_windows = __esm({
7589
7817
  "../../node_modules/default-browser/windows.js"() {
7590
- execFileAsync3 = promisify3(execFile3);
7818
+ execFileAsync3 = promisify4(execFile4);
7591
7819
  windowsBrowserProgIds = {
7592
7820
  MSEdgeHTM: { name: "Edge", id: "com.microsoft.edge" },
7593
7821
  // The missing `L` is correct.
@@ -7614,9 +7842,9 @@ var init_windows = __esm({
7614
7842
  });
7615
7843
 
7616
7844
  // ../../node_modules/default-browser/index.js
7617
- import { promisify as promisify4 } from "node:util";
7845
+ import { promisify as promisify5 } from "node:util";
7618
7846
  import process6 from "node:process";
7619
- import { execFile as execFile4 } from "node:child_process";
7847
+ import { execFile as execFile5 } from "node:child_process";
7620
7848
  async function defaultBrowser2() {
7621
7849
  if (process6.platform === "darwin") {
7622
7850
  const id = await defaultBrowserId();
@@ -7640,7 +7868,7 @@ var init_default_browser = __esm({
7640
7868
  init_default_browser_id();
7641
7869
  init_bundle_name();
7642
7870
  init_windows();
7643
- execFileAsync4 = promisify4(execFile4);
7871
+ execFileAsync4 = promisify5(execFile5);
7644
7872
  titleize = (string) => string.toLowerCase().replaceAll(/(?:^|\s|-)\S/g, (x) => x.toUpperCase());
7645
7873
  }
7646
7874
  });
@@ -7650,14 +7878,14 @@ import process7 from "node:process";
7650
7878
  import { Buffer as Buffer2 } from "node:buffer";
7651
7879
  import path from "node:path";
7652
7880
  import { fileURLToPath } from "node:url";
7653
- import { promisify as promisify5 } from "node:util";
7881
+ import { promisify as promisify6 } from "node:util";
7654
7882
  import childProcess from "node:child_process";
7655
7883
  import fs5, { constants as fsConstants2 } from "node:fs/promises";
7656
7884
  async function getWindowsDefaultBrowserFromWsl() {
7657
7885
  const powershellPath = await powerShellPath();
7658
7886
  const rawCommand = String.raw`(Get-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\Shell\Associations\UrlAssociations\http\UserChoice").ProgId`;
7659
7887
  const encodedCommand = Buffer2.from(rawCommand, "utf16le").toString("base64");
7660
- const { stdout } = await execFile5(
7888
+ const { stdout } = await execFile6(
7661
7889
  powershellPath,
7662
7890
  [
7663
7891
  "-NoProfile",
@@ -7697,14 +7925,14 @@ function detectPlatformBinary({ [platform]: platformBinary }, { wsl }) {
7697
7925
  }
7698
7926
  return detectArchBinary(platformBinary);
7699
7927
  }
7700
- var execFile5, __dirname, localXdgOpenPath, platform, arch, pTryEach, baseOpen, open, apps, open_default;
7928
+ var execFile6, __dirname, localXdgOpenPath, platform, arch, pTryEach, baseOpen, open, apps, open_default;
7701
7929
  var init_open = __esm({
7702
7930
  "node_modules/open/index.js"() {
7703
7931
  init_wsl_utils();
7704
7932
  init_define_lazy_prop();
7705
7933
  init_default_browser();
7706
7934
  init_is_inside_container();
7707
- execFile5 = promisify5(childProcess.execFile);
7935
+ execFile6 = promisify6(childProcess.execFile);
7708
7936
  __dirname = path.dirname(fileURLToPath(import.meta.url));
7709
7937
  localXdgOpenPath = path.join(__dirname, "xdg-open");
7710
7938
  ({ platform, arch } = process7);
@@ -8111,7 +8339,7 @@ var init_ansi_styles = __esm({
8111
8339
 
8112
8340
  // ../../node_modules/ora/node_modules/chalk/source/vendor/supports-color/index.js
8113
8341
  import process8 from "node:process";
8114
- import os2 from "node:os";
8342
+ import os3 from "node:os";
8115
8343
  import tty from "node:tty";
8116
8344
  function hasFlag(flag, argv = globalThis.Deno ? globalThis.Deno.args : process8.argv) {
8117
8345
  const prefix = flag.startsWith("-") ? "" : flag.length === 1 ? "-" : "--";
@@ -8169,7 +8397,7 @@ function _supportsColor(haveStream, { streamIsTTY, sniffFlags = true } = {}) {
8169
8397
  return min;
8170
8398
  }
8171
8399
  if (process8.platform === "win32") {
8172
- const osRelease = os2.release().split(".");
8400
+ const osRelease = os3.release().split(".");
8173
8401
  if (Number(osRelease[0]) >= 10 && Number(osRelease[2]) >= 10586) {
8174
8402
  return Number(osRelease[2]) >= 14931 ? 3 : 2;
8175
8403
  }
@@ -10683,7 +10911,7 @@ var init_ansi_styles2 = __esm({
10683
10911
 
10684
10912
  // ../../node_modules/log-symbols/node_modules/chalk/source/vendor/supports-color/index.js
10685
10913
  import process12 from "node:process";
10686
- import os3 from "node:os";
10914
+ import os4 from "node:os";
10687
10915
  import tty2 from "node:tty";
10688
10916
  function hasFlag2(flag, argv = globalThis.Deno ? globalThis.Deno.args : process12.argv) {
10689
10917
  const prefix = flag.startsWith("-") ? "" : flag.length === 1 ? "-" : "--";
@@ -10741,7 +10969,7 @@ function _supportsColor2(haveStream, { streamIsTTY, sniffFlags = true } = {}) {
10741
10969
  return min;
10742
10970
  }
10743
10971
  if (process12.platform === "win32") {
10744
- const osRelease = os3.release().split(".");
10972
+ const osRelease = os4.release().split(".");
10745
10973
  if (Number(osRelease[0]) >= 10 && Number(osRelease[2]) >= 10586) {
10746
10974
  return Number(osRelease[2]) >= 14931 ? 3 : 2;
10747
10975
  }
@@ -12311,139 +12539,6 @@ var init_login_phase = __esm({
12311
12539
  }
12312
12540
  });
12313
12541
 
12314
- // src/lib/git.ts
12315
- var git_exports = {};
12316
- __export(git_exports, {
12317
- GitError: () => GitError,
12318
- checkGitCredentialForGitHub: () => checkGitCredentialForGitHub,
12319
- cloneRepo: () => cloneRepo,
12320
- getGitConfig: () => getGitConfig,
12321
- getRepoRemoteUrl: () => getRepoRemoteUrl,
12322
- gitVersion: () => gitVersion,
12323
- installGithubCredential: () => installGithubCredential,
12324
- isGitRecentEnough: () => isGitRecentEnough,
12325
- remoteUrlMatchesRepo: () => remoteUrlMatchesRepo
12326
- });
12327
- import { execFile as execFile6 } from "node:child_process";
12328
- import { promisify as promisify6 } from "node:util";
12329
- async function gitVersion() {
12330
- try {
12331
- const { stdout } = await execFileP("git", ["--version"], { encoding: "utf8" });
12332
- const m = stdout.match(/git version (\d+)\.(\d+)\.(\d+)/);
12333
- if (!m) return null;
12334
- return [Number(m[1]), Number(m[2]), Number(m[3])];
12335
- } catch (err) {
12336
- if (err.code === "ENOENT") return null;
12337
- throw err;
12338
- }
12339
- }
12340
- function isGitRecentEnough(version) {
12341
- const [major, minor] = version;
12342
- return major > 2 || major === 2 && minor >= 11;
12343
- }
12344
- async function installGithubCredential(token) {
12345
- const input = `protocol=https
12346
- host=github.com
12347
- username=x-access-token
12348
- password=${token}
12349
-
12350
- `;
12351
- const child = execFile6("git", ["credential", "approve"], { encoding: "utf8" });
12352
- const proc = child;
12353
- proc.stdin?.write(input);
12354
- proc.stdin?.end();
12355
- await new Promise((resolve2, reject) => {
12356
- proc.on("exit", (code) => {
12357
- if (code === 0) resolve2();
12358
- else reject(new GitError(`git credential approve exited with code ${code}`));
12359
- });
12360
- proc.on("error", reject);
12361
- });
12362
- }
12363
- async function cloneRepo(repoFullName, targetDir) {
12364
- const url = `https://github.com/${repoFullName}.git`;
12365
- try {
12366
- await execFileP("git", ["clone", url, targetDir], { encoding: "utf8" });
12367
- } catch (err) {
12368
- const errAny = err;
12369
- throw new GitError(
12370
- `git clone failed: ${errAny.stderr ?? errAny.message}`,
12371
- errAny.stdout,
12372
- errAny.stderr
12373
- );
12374
- }
12375
- }
12376
- async function checkGitCredentialForGitHub() {
12377
- return new Promise((resolve2) => {
12378
- const proc = execFile6(
12379
- "git",
12380
- ["credential", "fill"],
12381
- {
12382
- encoding: "utf8",
12383
- env: { ...process.env, GIT_TERMINAL_PROMPT: "0" }
12384
- },
12385
- (err, stdout) => {
12386
- if (err) {
12387
- resolve2(false);
12388
- return;
12389
- }
12390
- const hasOurUsername = /^username=x-access-token\s*$/m.test(stdout);
12391
- const hasPassword = /^password=\S+/m.test(stdout);
12392
- resolve2(hasOurUsername && hasPassword);
12393
- }
12394
- );
12395
- proc.stdin?.write("protocol=https\nhost=github.com\n\n");
12396
- proc.stdin?.end();
12397
- });
12398
- }
12399
- async function getRepoRemoteUrl(repoPath, remoteName = "origin") {
12400
- try {
12401
- const { stdout } = await execFileP(
12402
- "git",
12403
- ["-C", repoPath, "remote", "get-url", remoteName],
12404
- { encoding: "utf8" }
12405
- );
12406
- return stdout.trim() || null;
12407
- } catch {
12408
- return null;
12409
- }
12410
- }
12411
- function remoteUrlMatchesRepo(remoteUrl, repoFullName) {
12412
- const expected = repoFullName.replace(/\.git$/i, "").toLowerCase();
12413
- const url = remoteUrl.trim().replace(/\.git$/i, "");
12414
- const httpsMatch = url.match(/^https?:\/\/[^/]*github\.com\/(.+)$/i);
12415
- if (httpsMatch && httpsMatch[1].toLowerCase() === expected) return true;
12416
- const sshMatch = url.match(/^[^@]+@github\.com:(.+)$/i);
12417
- if (sshMatch && sshMatch[1].toLowerCase() === expected) return true;
12418
- return false;
12419
- }
12420
- async function getGitConfig(key) {
12421
- try {
12422
- const { stdout } = await execFileP("git", ["config", "--global", "--get", key], {
12423
- encoding: "utf8"
12424
- });
12425
- return stdout.trim() || null;
12426
- } catch (err) {
12427
- if (err.code === 1) return null;
12428
- throw err;
12429
- }
12430
- }
12431
- var execFileP, GitError;
12432
- var init_git = __esm({
12433
- "src/lib/git.ts"() {
12434
- "use strict";
12435
- execFileP = promisify6(execFile6);
12436
- GitError = class extends Error {
12437
- constructor(message, stdout, stderr) {
12438
- super(message);
12439
- this.stdout = stdout;
12440
- this.stderr = stderr;
12441
- this.name = "GitError";
12442
- }
12443
- };
12444
- }
12445
- });
12446
-
12447
12542
  // src/lib/prompt.ts
12448
12543
  import { createInterface } from "node:readline";
12449
12544
  async function promptStdin(question, opts = {}) {
@@ -12493,53 +12588,6 @@ var init_prompt = __esm({
12493
12588
  }
12494
12589
  });
12495
12590
 
12496
- // src/lib/workspace.ts
12497
- import { existsSync } from "node:fs";
12498
- import os4 from "node:os";
12499
- import { resolve as pathResolve } from "node:path";
12500
- function defaultClonePath(orgSlug) {
12501
- const cleanSlug = orgSlug.replace(/^bamboo-?/i, "") || orgSlug;
12502
- return pathResolve(os4.homedir(), "Bamboo", cleanSlug);
12503
- }
12504
- async function resolveWorkspace() {
12505
- const state = await readState();
12506
- if (state) {
12507
- if (!existsSync(state.workspace_path)) {
12508
- throw new NoWorkspaceError(
12509
- `Bamboo workspace not found.
12510
- (State recorded ${state.workspace_path} but it's missing on disk \u2014 run \`bamboo-agents init --reset\` to re-clone.)`
12511
- );
12512
- }
12513
- return { path: state.workspace_path, orgId: state.org_id };
12514
- }
12515
- const config = await readConfig();
12516
- if (config) {
12517
- if (!existsSync(config.repo_path)) {
12518
- throw new NoWorkspaceError(
12519
- `Bamboo workspace not found.
12520
- (Config recorded ${config.repo_path} but it's missing on disk \u2014 run \`bamboo-agents init --reset\` to re-clone.)`
12521
- );
12522
- }
12523
- return { path: config.repo_path, orgId: config.org_id };
12524
- }
12525
- throw new NoWorkspaceError(
12526
- "No Bamboo workspace yet. Run `bamboo-agents init` first."
12527
- );
12528
- }
12529
- var NoWorkspaceError;
12530
- var init_workspace = __esm({
12531
- "src/lib/workspace.ts"() {
12532
- "use strict";
12533
- init_state();
12534
- NoWorkspaceError = class extends Error {
12535
- constructor(message) {
12536
- super(message);
12537
- this.name = "NoWorkspaceError";
12538
- }
12539
- };
12540
- }
12541
- });
12542
-
12543
12591
  // src/commands/init.ts
12544
12592
  var init_exports = {};
12545
12593
  __export(init_exports, {
@@ -13789,6 +13837,9 @@ function printNeedsAction(reason) {
13789
13837
  console.error("");
13790
13838
  }
13791
13839
  async function runOrchestrator() {
13840
+ return withFreshWorkspace(async () => runOrchestratorImpl());
13841
+ }
13842
+ async function runOrchestratorImpl() {
13792
13843
  if (process.platform === "win32") {
13793
13844
  console.error("");
13794
13845
  console.error(" Bamboo CLI doesn't support native Windows yet.");
@@ -13854,6 +13905,7 @@ var init_orchestrator = __esm({
13854
13905
  "use strict";
13855
13906
  init_credentials();
13856
13907
  init_state();
13908
+ init_workspace();
13857
13909
  init_login_phase();
13858
13910
  init_provision_phase();
13859
13911
  init_clone_or_adopt_phase();
@@ -13921,35 +13973,37 @@ __export(open_exports, {
13921
13973
  runOpen: () => runOpen
13922
13974
  });
13923
13975
  async function runOpen() {
13924
- let workspacePath;
13925
- try {
13926
- workspacePath = (await resolveWorkspace()).path;
13927
- } catch (err) {
13928
- if (err instanceof NoWorkspaceError) {
13929
- console.error(err.message);
13930
- process.exit(2);
13976
+ return withFreshWorkspace(async () => {
13977
+ let workspacePath;
13978
+ try {
13979
+ workspacePath = (await resolveWorkspace()).path;
13980
+ } catch (err) {
13981
+ if (err instanceof NoWorkspaceError) {
13982
+ console.error(err.message);
13983
+ process.exit(2);
13984
+ }
13985
+ throw err;
13931
13986
  }
13932
- throw err;
13933
- }
13934
- const status = await detectClaudeDesktop();
13935
- if (status.kind === "missing") {
13936
- console.error(
13937
- `Claude Desktop isn't installed. Get it at ${DOWNLOAD_URL}, then re-run \`bamboo-agents open\`.`
13938
- );
13939
- console.error(`(Your workspace is cloned at ${workspacePath}.)`);
13940
- process.exit(1);
13941
- }
13942
- if (status.kind === "unsupported_platform") {
13943
- console.log("");
13944
- console.log(" Claude Desktop isn't available on Linux yet.");
13945
- console.log(` Your workspace is cloned at: ${workspacePath}`);
13946
- console.log("");
13947
- return;
13948
- }
13949
- const url = `claude://code/new?folder=${encodeURIComponent(workspacePath)}`;
13950
- await open_default(url);
13951
- console.log(`Opening Claude Code at ${workspacePath}\u2026`);
13952
- console.log("(Claude Desktop will ask you to trust the folder the first time.)");
13987
+ const status = await detectClaudeDesktop();
13988
+ if (status.kind === "missing") {
13989
+ console.error(
13990
+ `Claude Desktop isn't installed. Get it at ${DOWNLOAD_URL}, then re-run \`bamboo-agents open\`.`
13991
+ );
13992
+ console.error(`(Your workspace is cloned at ${workspacePath}.)`);
13993
+ process.exit(1);
13994
+ }
13995
+ if (status.kind === "unsupported_platform") {
13996
+ console.log("");
13997
+ console.log(" Claude Desktop isn't available on Linux yet.");
13998
+ console.log(` Your workspace is cloned at: ${workspacePath}`);
13999
+ console.log("");
14000
+ return;
14001
+ }
14002
+ const url = `claude://code/new?folder=${encodeURIComponent(workspacePath)}`;
14003
+ await open_default(url);
14004
+ console.log(`Opening Claude Code at ${workspacePath}\u2026`);
14005
+ console.log("(Claude Desktop will ask you to trust the folder the first time.)");
14006
+ });
13953
14007
  }
13954
14008
  var DOWNLOAD_URL;
13955
14009
  var init_open2 = __esm({
@@ -13984,44 +14038,46 @@ function formatSubscriptionLine(billing) {
13984
14038
  }
13985
14039
  }
13986
14040
  async function runStatus() {
13987
- const creds = await readCredentials();
13988
- const state = await readState().catch(() => null);
13989
- const cfg = await readConfig();
13990
- console.log("");
13991
- console.log(" Bamboo CLI status");
13992
- console.log("");
13993
- if (!creds) {
13994
- console.log(" Credentials: not set (run `bamboo-agents login`)");
13995
- } else {
13996
- console.log(
13997
- ` Credentials: set${creds.github_username ? ` (@${creds.github_username})` : ""}`
13998
- );
13999
- console.log(` Written: ${creds.written_at}`);
14000
- if (creds.github_token_expires_at) {
14001
- console.log(` GitHub expires: ${creds.github_token_expires_at}`);
14041
+ return withFreshWorkspace(async () => {
14042
+ const creds = await readCredentials();
14043
+ const state = await readState().catch(() => null);
14044
+ const cfg = await readConfig();
14045
+ console.log("");
14046
+ console.log(" Bamboo CLI status");
14047
+ console.log("");
14048
+ if (!creds) {
14049
+ console.log(" Credentials: not set (run `bamboo-agents login`)");
14050
+ } else {
14051
+ console.log(
14052
+ ` Credentials: set${creds.github_username ? ` (@${creds.github_username})` : ""}`
14053
+ );
14054
+ console.log(` Written: ${creds.written_at}`);
14055
+ if (creds.github_token_expires_at) {
14056
+ console.log(` GitHub expires: ${creds.github_token_expires_at}`);
14057
+ }
14002
14058
  }
14003
- }
14004
- const workspacePath = state?.workspace_path ?? cfg?.repo_path ?? null;
14005
- if (!workspacePath) {
14006
- console.log(" Workspace: not configured (run `bamboo-agents init`)");
14007
- } else {
14008
- const repoLabel = cfg?.workspace_repo ?? state?.remote_url?.replace(/^https?:\/\/github\.com\//, "") ?? "(unknown)";
14009
- console.log(` Workspace: ${repoLabel}`);
14010
- console.log(` Repo path: ${workspacePath}`);
14011
- console.log(` Org: ${cfg?.org_name ?? state?.org_slug ?? "(unknown)"}`);
14012
- console.log(` Installed: ${cfg?.installed_at ?? state?.cloned_at ?? "(unknown)"}`);
14013
- if (state?.last_sync) {
14014
- console.log(` Last sync: ${state.last_sync}`);
14059
+ const workspacePath = state?.workspace_path ?? cfg?.repo_path ?? null;
14060
+ if (!workspacePath) {
14061
+ console.log(" Workspace: not configured (run `bamboo-agents init`)");
14062
+ } else {
14063
+ const repoLabel = cfg?.workspace_repo ?? state?.remote_url?.replace(/^https?:\/\/github\.com\//, "") ?? "(unknown)";
14064
+ console.log(` Workspace: ${repoLabel}`);
14065
+ console.log(` Repo path: ${workspacePath}`);
14066
+ console.log(` Org: ${cfg?.org_name ?? state?.org_slug ?? "(unknown)"}`);
14067
+ console.log(` Installed: ${cfg?.installed_at ?? state?.cloned_at ?? "(unknown)"}`);
14068
+ if (state?.last_sync) {
14069
+ console.log(` Last sync: ${state.last_sync}`);
14070
+ }
14015
14071
  }
14016
- }
14017
- if (creds?.bamboo_session) {
14018
- try {
14019
- const billing = await getCliBillingStatus(creds.bamboo_session);
14020
- console.log(` ${formatSubscriptionLine(billing)}`);
14021
- } catch {
14072
+ if (creds?.bamboo_session) {
14073
+ try {
14074
+ const billing = await getCliBillingStatus(creds.bamboo_session);
14075
+ console.log(` ${formatSubscriptionLine(billing)}`);
14076
+ } catch {
14077
+ }
14022
14078
  }
14023
- }
14024
- console.log("");
14079
+ console.log("");
14080
+ });
14025
14081
  }
14026
14082
  var init_status = __esm({
14027
14083
  "src/commands/status.ts"() {
@@ -14029,6 +14085,7 @@ var init_status = __esm({
14029
14085
  init_state();
14030
14086
  init_credentials();
14031
14087
  init_api();
14088
+ init_workspace();
14032
14089
  }
14033
14090
  });
14034
14091
 
@@ -15145,6 +15202,9 @@ async function requireSession() {
15145
15202
  return creds.bamboo_session;
15146
15203
  }
15147
15204
  async function runSkillsList(options = {}) {
15205
+ return withFreshWorkspace(async () => runSkillsListImpl(options));
15206
+ }
15207
+ async function runSkillsListImpl(options = {}) {
15148
15208
  if (options.agent) {
15149
15209
  const bambooSession = await requireSession();
15150
15210
  const resolved = await resolveAgent(bambooSession, options.agent);
@@ -15229,18 +15289,20 @@ async function runSkillsList(options = {}) {
15229
15289
  console.log("");
15230
15290
  }
15231
15291
  async function runSkillsGet(name) {
15232
- if (!name || !name.trim()) {
15233
- console.error("bamboo-agents: skills get requires a skill name.");
15234
- console.error("Example: bamboo-agents skills get enhance-instructions");
15235
- process.exit(2);
15236
- }
15237
- const repoPath = await resolveWorkspacePath();
15238
- const skill = await getLocalSkill(repoPath, name.trim());
15239
- if (!skill) {
15240
- await printNotFound(repoPath, name);
15241
- process.exit(2);
15242
- }
15243
- printSkillToStdout(skill);
15292
+ return withFreshWorkspace(async () => {
15293
+ if (!name || !name.trim()) {
15294
+ console.error("bamboo-agents: skills get requires a skill name.");
15295
+ console.error("Example: bamboo-agents skills get enhance-instructions");
15296
+ process.exit(2);
15297
+ }
15298
+ const repoPath = await resolveWorkspacePath();
15299
+ const skill = await getLocalSkill(repoPath, name.trim());
15300
+ if (!skill) {
15301
+ await printNotFound(repoPath, name);
15302
+ process.exit(2);
15303
+ }
15304
+ printSkillToStdout(skill);
15305
+ });
15244
15306
  }
15245
15307
  function printSkillToStdout(skill) {
15246
15308
  process.stdout.write("---\n");
@@ -15283,10 +15345,14 @@ async function printNotFound(repoPath, name) {
15283
15345
  }
15284
15346
  }
15285
15347
  async function runSkillsSubscribe(agentIdentifier, skillName) {
15286
- await runSubscribeOp("subscribe", agentIdentifier, skillName);
15348
+ return withFreshWorkspace(
15349
+ async () => runSubscribeOp("subscribe", agentIdentifier, skillName)
15350
+ );
15287
15351
  }
15288
15352
  async function runSkillsUnsubscribe(agentIdentifier, skillName) {
15289
- await runSubscribeOp("unsubscribe", agentIdentifier, skillName);
15353
+ return withFreshWorkspace(
15354
+ async () => runSubscribeOp("unsubscribe", agentIdentifier, skillName)
15355
+ );
15290
15356
  }
15291
15357
  async function runSubscribeOp(action, agentIdentifier, skillName) {
15292
15358
  if (!agentIdentifier || !skillName) {
@@ -15334,6 +15400,9 @@ async function runSubscribeOp(action, agentIdentifier, skillName) {
15334
15400
  console.log("");
15335
15401
  }
15336
15402
  async function runSkillsCreate(skillName, options = {}) {
15403
+ return withFreshWorkspace(async () => runSkillsCreateImpl(skillName, options));
15404
+ }
15405
+ async function runSkillsCreateImpl(skillName, options = {}) {
15337
15406
  if (!skillName || !skillName.trim()) {
15338
15407
  console.error("bamboo-agents: skills create requires a skill name.");
15339
15408
  console.error("Example: bamboo-agents skills create analyze-creative");
@@ -15370,6 +15439,11 @@ async function runSkillsCreate(skillName, options = {}) {
15370
15439
  console.log("");
15371
15440
  }
15372
15441
  async function runSkillsUpdate(agentIdentifier, skillName) {
15442
+ return withFreshWorkspace(
15443
+ async () => runSkillsUpdateImpl(agentIdentifier, skillName)
15444
+ );
15445
+ }
15446
+ async function runSkillsUpdateImpl(agentIdentifier, skillName) {
15373
15447
  if (!agentIdentifier || !skillName) {
15374
15448
  console.error(
15375
15449
  "bamboo-agents: `skills update` requires an agent identifier and a skill name."
@@ -15405,6 +15479,7 @@ var init_skills = __esm({
15405
15479
  init_workspace();
15406
15480
  init_skills_local();
15407
15481
  init_api();
15482
+ init_workspace();
15408
15483
  }
15409
15484
  });
15410
15485
 
@@ -15428,7 +15503,7 @@ var {
15428
15503
  // src/index.ts
15429
15504
  init_version();
15430
15505
  var program2 = new Command();
15431
- program2.name("bamboo-agents").description("Set up your local Bamboo workspace and drop into Claude.").version(VERSION);
15506
+ program2.name("bamboo-agents").description("Set up your local Bamboo workspace and drop into Claude.").version(VERSION).option("--no-sync", "Skip the auto-sync git pull on this command");
15432
15507
  program2.action(async () => {
15433
15508
  const { runOrchestrator: runOrchestrator2 } = await Promise.resolve().then(() => (init_orchestrator(), orchestrator_exports));
15434
15509
  await runOrchestrator2();
@@ -15444,11 +15519,11 @@ program2.command("init").description("Clone your workspace + set up git credenti
15444
15519
  const { runInit: runInit2 } = await Promise.resolve().then(() => (init_init(), init_exports));
15445
15520
  await runInit2({ reset: options.reset });
15446
15521
  });
15447
- program2.command("open").description("Launch Claude Code at your workspace").action(async () => {
15522
+ program2.command("open").description("Launch Claude Code at your workspace").option("--no-sync", "Skip the auto-sync git pull on this command").action(async () => {
15448
15523
  const { runOpen: runOpen2 } = await Promise.resolve().then(() => (init_open2(), open_exports));
15449
15524
  await runOpen2();
15450
15525
  });
15451
- program2.command("status").description("Show current Bamboo CLI state").action(async () => {
15526
+ program2.command("status").description("Show current Bamboo CLI state").option("--no-sync", "Skip the auto-sync git pull on this command").action(async () => {
15452
15527
  const { runStatus: runStatus2 } = await Promise.resolve().then(() => (init_status(), status_exports));
15453
15528
  await runStatus2();
15454
15529
  });
@@ -15468,29 +15543,29 @@ var skills = program2.command("skills").description("Read workspace skills from
15468
15543
  skills.command("list").description("List every skill in the workspace").option(
15469
15544
  "--agent <slug>",
15470
15545
  "Filter to one agent's subscribed skills (via server)"
15471
- ).action(async (options) => {
15546
+ ).option("--no-sync", "Skip the auto-sync git pull on this command").action(async (options) => {
15472
15547
  const { runSkillsList: runSkillsList2 } = await Promise.resolve().then(() => (init_skills(), skills_exports));
15473
15548
  await runSkillsList2(options);
15474
15549
  });
15475
- skills.command("get <name>").description("Print one skill's SKILL.md body to stdout").action(async (name) => {
15550
+ skills.command("get <name>").description("Print one skill's SKILL.md body to stdout").option("--no-sync", "Skip the auto-sync git pull on this command").action(async (name) => {
15476
15551
  const { runSkillsGet: runSkillsGet2 } = await Promise.resolve().then(() => (init_skills(), skills_exports));
15477
15552
  await runSkillsGet2(name);
15478
15553
  });
15479
- skills.command("subscribe <agent> <skill-name>").description("Subscribe an agent to a skill from the catalog").action(async (agent, skillName) => {
15554
+ skills.command("subscribe <agent> <skill-name>").description("Subscribe an agent to a skill from the catalog").option("--no-sync", "Skip the auto-sync git pull on this command").action(async (agent, skillName) => {
15480
15555
  const { runSkillsSubscribe: runSkillsSubscribe2 } = await Promise.resolve().then(() => (init_skills(), skills_exports));
15481
15556
  await runSkillsSubscribe2(agent, skillName);
15482
15557
  });
15483
- skills.command("unsubscribe <agent> <skill-name>").description("Unsubscribe an agent from a skill").action(async (agent, skillName) => {
15558
+ skills.command("unsubscribe <agent> <skill-name>").description("Unsubscribe an agent from a skill").option("--no-sync", "Skip the auto-sync git pull on this command").action(async (agent, skillName) => {
15484
15559
  const { runSkillsUnsubscribe: runSkillsUnsubscribe2 } = await Promise.resolve().then(() => (init_skills(), skills_exports));
15485
15560
  await runSkillsUnsubscribe2(agent, skillName);
15486
15561
  });
15487
- skills.command("create <skill-name>").description("Scaffold a new org-custom skill in your workspace").option("--category <category>", "Optional category label (e.g. analysis)").option("--description <description>", "Optional one-line description").action(
15562
+ skills.command("create <skill-name>").description("Scaffold a new org-custom skill in your workspace").option("--category <category>", "Optional category label (e.g. analysis)").option("--description <description>", "Optional one-line description").option("--no-sync", "Skip the auto-sync git pull on this command").action(
15488
15563
  async (skillName, options) => {
15489
15564
  const { runSkillsCreate: runSkillsCreate2 } = await Promise.resolve().then(() => (init_skills(), skills_exports));
15490
15565
  await runSkillsCreate2(skillName, options);
15491
15566
  }
15492
15567
  );
15493
- skills.command("update <agent> <skill-name>").description("Update an installed skill from the bamboo registry").action(async (agent, skillName) => {
15568
+ skills.command("update <agent> <skill-name>").description("Update an installed skill from the bamboo registry").option("--no-sync", "Skip the auto-sync git pull on this command").action(async (agent, skillName) => {
15494
15569
  const { runSkillsUpdate: runSkillsUpdate2 } = await Promise.resolve().then(() => (init_skills(), skills_exports));
15495
15570
  await runSkillsUpdate2(agent, skillName);
15496
15571
  });