bamboo-agents 0.1.5-dev.37.e3cb3a7 → 0.1.5-dev.38.aeaecba

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 CHANGED
@@ -1 +1 @@
1
- 0.1.5-dev.37.e3cb3a7
1
+ 0.1.5-dev.38.aeaecba
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.37.e3cb3a7";
3040
+ VERSION = "0.1.5-dev.38.aeaecba";
3041
3041
  }
3042
3042
  });
3043
3043
 
@@ -12432,17 +12432,115 @@ var init_git = __esm({
12432
12432
  }
12433
12433
  });
12434
12434
 
12435
+ // src/lib/prompt.ts
12436
+ import { createInterface } from "node:readline";
12437
+ async function promptStdin(question, opts = {}) {
12438
+ const maxRetries = opts.maxRetries ?? 2;
12439
+ const isInteractive2 = process.stdin.isTTY === true;
12440
+ const rl = createInterface({
12441
+ input: process.stdin,
12442
+ output: process.stdout,
12443
+ terminal: isInteractive2
12444
+ });
12445
+ const onSigInt = () => {
12446
+ rl.close();
12447
+ };
12448
+ rl.on("SIGINT", onSigInt);
12449
+ try {
12450
+ let attempts = 0;
12451
+ while (attempts <= maxRetries) {
12452
+ const answer = await readOnce(rl, question);
12453
+ if (answer === null) return null;
12454
+ const trimmed = answer.trim();
12455
+ if (trimmed.length > 0) return trimmed;
12456
+ attempts += 1;
12457
+ if (attempts > maxRetries || !isInteractive2) return null;
12458
+ console.log(" (Press Enter without typing to skip \u2014 or answer Boo's question.)");
12459
+ }
12460
+ return null;
12461
+ } finally {
12462
+ rl.off("SIGINT", onSigInt);
12463
+ rl.close();
12464
+ }
12465
+ }
12466
+ function readOnce(rl, question) {
12467
+ return new Promise((resolve) => {
12468
+ let resolved = false;
12469
+ const settle = (value) => {
12470
+ if (resolved) return;
12471
+ resolved = true;
12472
+ resolve(value);
12473
+ };
12474
+ rl.once("close", () => settle(null));
12475
+ rl.question(question, (answer) => settle(answer));
12476
+ });
12477
+ }
12478
+ var init_prompt = __esm({
12479
+ "src/lib/prompt.ts"() {
12480
+ "use strict";
12481
+ }
12482
+ });
12483
+
12484
+ // src/lib/workspace.ts
12485
+ import { existsSync } from "node:fs";
12486
+ import os4 from "node:os";
12487
+ import { resolve as pathResolve } from "node:path";
12488
+ function defaultClonePath(orgSlug) {
12489
+ const cleanSlug = orgSlug.replace(/^bamboo-?/i, "") || orgSlug;
12490
+ return pathResolve(os4.homedir(), "Bamboo", cleanSlug);
12491
+ }
12492
+ async function resolveWorkspace() {
12493
+ const state = await readState();
12494
+ if (state) {
12495
+ if (!existsSync(state.workspace_path)) {
12496
+ throw new NoWorkspaceError(
12497
+ `Bamboo workspace not found.
12498
+ (State recorded ${state.workspace_path} but it's missing on disk \u2014 run \`bamboo-agents init --reset\` to re-clone.)`
12499
+ );
12500
+ }
12501
+ return { path: state.workspace_path, orgId: state.org_id };
12502
+ }
12503
+ const config = await readConfig();
12504
+ if (config) {
12505
+ if (!existsSync(config.repo_path)) {
12506
+ throw new NoWorkspaceError(
12507
+ `Bamboo workspace not found.
12508
+ (Config recorded ${config.repo_path} but it's missing on disk \u2014 run \`bamboo-agents init --reset\` to re-clone.)`
12509
+ );
12510
+ }
12511
+ return { path: config.repo_path, orgId: config.org_id };
12512
+ }
12513
+ throw new NoWorkspaceError(
12514
+ "No Bamboo workspace yet. Run `bamboo-agents init` first."
12515
+ );
12516
+ }
12517
+ var NoWorkspaceError;
12518
+ var init_workspace = __esm({
12519
+ "src/lib/workspace.ts"() {
12520
+ "use strict";
12521
+ init_state();
12522
+ NoWorkspaceError = class extends Error {
12523
+ constructor(message) {
12524
+ super(message);
12525
+ this.name = "NoWorkspaceError";
12526
+ }
12527
+ };
12528
+ }
12529
+ });
12530
+
12435
12531
  // src/commands/init.ts
12436
12532
  var init_exports = {};
12437
12533
  __export(init_exports, {
12438
12534
  WORKSPACE_POLL: () => WORKSPACE_POLL,
12535
+ confirmReset: () => confirmReset,
12536
+ decideInitBranch: () => decideInitBranch,
12537
+ interpretResetAnswer: () => interpretResetAnswer,
12439
12538
  pollForWorkspaceReady: () => pollForWorkspaceReady,
12440
12539
  preProvisionWorkspace: () => preProvisionWorkspace,
12441
12540
  runInit: () => runInit,
12442
12541
  slugify: () => slugify
12443
12542
  });
12444
- import { access } from "node:fs/promises";
12445
- import { resolve as pathResolve } from "node:path";
12543
+ import { access, rm } from "node:fs/promises";
12446
12544
  async function pollForWorkspaceReady(bambooSession, initial) {
12447
12545
  if (initial.workspace_ready && initial.org.workspace_repo) {
12448
12546
  return { ok: true, membership: initial };
@@ -12482,7 +12580,35 @@ async function preProvisionWorkspace(bambooSession, call = provisionWorkspace) {
12482
12580
  return { kind: "transient", message: err.message };
12483
12581
  }
12484
12582
  }
12485
- async function runInit() {
12583
+ async function confirmReset(targetPath) {
12584
+ console.log(` ! \`--reset\` will delete: ${targetPath}`);
12585
+ if (process.stdin.isTTY !== true) return true;
12586
+ const answer = await promptStdin(" Continue? [Y/n] ");
12587
+ return interpretResetAnswer(answer);
12588
+ }
12589
+ function interpretResetAnswer(answer) {
12590
+ if (answer === null) return true;
12591
+ const normalized = answer.trim().toLowerCase();
12592
+ if (normalized === "" || normalized === "y" || normalized === "yes") {
12593
+ return true;
12594
+ }
12595
+ return false;
12596
+ }
12597
+ function decideInitBranch(input) {
12598
+ const { hasState, recordedPath, dirExists, canonicalPath, reset } = input;
12599
+ if (reset) {
12600
+ return {
12601
+ kind: "reset_then_clone",
12602
+ path: hasState && recordedPath || canonicalPath
12603
+ };
12604
+ }
12605
+ if (hasState && recordedPath) {
12606
+ if (dirExists) return { kind: "short_circuit", path: recordedPath };
12607
+ return { kind: "reclone_recorded", path: recordedPath };
12608
+ }
12609
+ return { kind: "fresh_clone", path: canonicalPath };
12610
+ }
12611
+ async function runInit(options = {}) {
12486
12612
  const creds = await readCredentials();
12487
12613
  if (!creds) {
12488
12614
  console.error("No credentials found. Run `bamboo-agents login` first.");
@@ -12602,33 +12728,114 @@ async function runInit() {
12602
12728
  process.exit(1);
12603
12729
  }
12604
12730
  const orgSlug = slugify(membership.org.name);
12605
- const repoPath = pathResolve(process.cwd(), `bamboo-${orgSlug}`);
12606
- let dirExists = false;
12731
+ const canonicalPath = defaultClonePath(orgSlug);
12732
+ let existingState;
12607
12733
  try {
12608
- await access(repoPath);
12609
- dirExists = true;
12734
+ existingState = await readState();
12735
+ } catch (err) {
12736
+ if (err instanceof WorkspaceStateError) {
12737
+ console.error(`
12738
+ ${err.message}
12739
+ `);
12740
+ process.exit(2);
12741
+ }
12742
+ throw err;
12743
+ }
12744
+ const targetPath = existingState?.workspace_path ?? canonicalPath;
12745
+ if (options.reset) {
12746
+ const confirmed = await confirmReset(targetPath);
12747
+ if (!confirmed) {
12748
+ console.log(" Aborted \u2014 workspace untouched.");
12749
+ process.exit(2);
12750
+ }
12751
+ const resetSpinner = ora(`Removing ${targetPath}\u2026`).start();
12752
+ try {
12753
+ await rm(targetPath, { recursive: true, force: true });
12754
+ resetSpinner.succeed(`Removed ${targetPath}`);
12755
+ } catch (err) {
12756
+ resetSpinner.fail(`Couldn't remove ${targetPath}: ${err.message}`);
12757
+ process.exit(1);
12758
+ }
12759
+ await cloneAndPersist(targetPath, membership);
12760
+ return;
12761
+ }
12762
+ if (existingState) {
12763
+ let dirExists = false;
12764
+ try {
12765
+ await access(existingState.workspace_path);
12766
+ dirExists = true;
12767
+ } catch {
12768
+ }
12769
+ if (dirExists) {
12770
+ const existingRemote = await getRepoRemoteUrl(existingState.workspace_path);
12771
+ const matches = existingRemote != null && remoteUrlMatchesRepo(existingRemote, membership.org.workspace_repo);
12772
+ if (matches) {
12773
+ await writeConfig({
12774
+ org_id: membership.org.id,
12775
+ org_name: membership.org.name,
12776
+ workspace_repo: membership.org.workspace_repo,
12777
+ repo_path: existingState.workspace_path,
12778
+ installed_at: (/* @__PURE__ */ new Date()).toISOString()
12779
+ });
12780
+ console.log("");
12781
+ console.log(` \u2713 Workspace already at ${existingState.workspace_path}`);
12782
+ console.log(" (init is idempotent \u2014 re-run with --reset to start over)");
12783
+ console.log("");
12784
+ return;
12785
+ }
12786
+ console.error(
12787
+ `
12788
+ ${existingState.workspace_path} exists but its origin doesn't match your workspace repo.
12789
+
12790
+ ` + (existingRemote ? ` Found origin: ${existingRemote}
12791
+ Expected: github.com/${membership.org.workspace_repo}
12792
+
12793
+ ` : ` It's not a git repo (no origin remote).
12794
+
12795
+ `) + " Re-run with `bamboo-agents init --reset` to start over, or move the directory aside.\n"
12796
+ );
12797
+ process.exit(2);
12798
+ }
12799
+ console.log(` State points at ${existingState.workspace_path}, but the directory is missing \u2014 re-cloning there.`);
12800
+ await cloneAndPersist(existingState.workspace_path, membership);
12801
+ return;
12802
+ }
12803
+ let canonicalExists = false;
12804
+ try {
12805
+ await access(canonicalPath);
12806
+ canonicalExists = true;
12610
12807
  } catch {
12611
12808
  }
12612
- if (dirExists) {
12613
- const existingRemote = await getRepoRemoteUrl(repoPath);
12809
+ if (canonicalExists) {
12810
+ const existingRemote = await getRepoRemoteUrl(canonicalPath);
12614
12811
  const matches = existingRemote != null && remoteUrlMatchesRepo(existingRemote, membership.org.workspace_repo);
12615
12812
  if (matches) {
12616
12813
  await writeConfig({
12617
12814
  org_id: membership.org.id,
12618
12815
  org_name: membership.org.name,
12619
12816
  workspace_repo: membership.org.workspace_repo,
12620
- repo_path: repoPath,
12817
+ repo_path: canonicalPath,
12621
12818
  installed_at: (/* @__PURE__ */ new Date()).toISOString()
12622
12819
  });
12820
+ const now = (/* @__PURE__ */ new Date()).toISOString();
12821
+ await writeState({
12822
+ $schema_version: STATE_SCHEMA_VERSION,
12823
+ workspace_path: canonicalPath,
12824
+ org_id: membership.org.id,
12825
+ org_slug: orgSlug,
12826
+ cloned_at: now,
12827
+ last_sync: now,
12828
+ remote_url: `https://github.com/${membership.org.workspace_repo}`
12829
+ });
12623
12830
  console.log("");
12624
- console.log(` \u2713 Workspace already at ${repoPath}`);
12625
- console.log(" (skipped clone \u2014 origin matches your workspace repo)");
12831
+ console.log(` \u2713 Adopted existing workspace at ${canonicalPath}`);
12832
+ console.log(" (origin matches \u2014 registered in state.json)");
12626
12833
  console.log("");
12627
12834
  return;
12628
12835
  }
12629
12836
  console.error(
12630
12837
  `
12631
- ${repoPath} already exists and is NOT the right repo.
12838
+ ${canonicalPath} already exists and is NOT the right repo.
12632
12839
 
12633
12840
  ` + (existingRemote ? ` Found origin: ${existingRemote}
12634
12841
  Expected: github.com/${membership.org.workspace_repo}
@@ -12639,7 +12846,12 @@ async function runInit() {
12639
12846
  );
12640
12847
  process.exit(2);
12641
12848
  }
12642
- const cloneSpinner = ora(`Cloning ${membership.org.workspace_repo} \u2192 ${repoPath}\u2026`).start();
12849
+ await cloneAndPersist(canonicalPath, membership);
12850
+ }
12851
+ async function cloneAndPersist(repoPath, membership) {
12852
+ const cloneSpinner = ora(
12853
+ `Cloning ${membership.org.workspace_repo} \u2192 ${repoPath}\u2026`
12854
+ ).start();
12643
12855
  try {
12644
12856
  await cloneRepo(membership.org.workspace_repo, repoPath);
12645
12857
  cloneSpinner.succeed(`Cloned to ${repoPath}`);
@@ -12654,6 +12866,16 @@ async function runInit() {
12654
12866
  repo_path: repoPath,
12655
12867
  installed_at: (/* @__PURE__ */ new Date()).toISOString()
12656
12868
  });
12869
+ const now = (/* @__PURE__ */ new Date()).toISOString();
12870
+ await writeState({
12871
+ $schema_version: 1,
12872
+ workspace_path: repoPath,
12873
+ org_id: membership.org.id,
12874
+ org_slug: slugify(membership.org.name),
12875
+ cloned_at: now,
12876
+ last_sync: now,
12877
+ remote_url: `https://github.com/${membership.org.workspace_repo}`
12878
+ });
12657
12879
  console.log("");
12658
12880
  console.log(` \u2713 Workspace ready at ${repoPath}`);
12659
12881
  console.log(" Next: `bamboo-agents open` to launch Claude Code there.");
@@ -12667,8 +12889,10 @@ var init_init = __esm({
12667
12889
  init_api();
12668
12890
  init_credentials();
12669
12891
  init_git();
12892
+ init_prompt();
12670
12893
  init_state();
12671
12894
  init_util2();
12895
+ init_workspace();
12672
12896
  WORKSPACE_POLL = {
12673
12897
  intervalMs: 2e3,
12674
12898
  timeoutMs: 5 * 60 * 1e3
@@ -12932,55 +13156,6 @@ var init_clone_or_adopt_phase = __esm({
12932
13156
  }
12933
13157
  });
12934
13158
 
12935
- // src/lib/prompt.ts
12936
- import { createInterface } from "node:readline";
12937
- async function promptStdin(question, opts = {}) {
12938
- const maxRetries = opts.maxRetries ?? 2;
12939
- const isInteractive2 = process.stdin.isTTY === true;
12940
- const rl = createInterface({
12941
- input: process.stdin,
12942
- output: process.stdout,
12943
- terminal: isInteractive2
12944
- });
12945
- const onSigInt = () => {
12946
- rl.close();
12947
- };
12948
- rl.on("SIGINT", onSigInt);
12949
- try {
12950
- let attempts = 0;
12951
- while (attempts <= maxRetries) {
12952
- const answer = await readOnce(rl, question);
12953
- if (answer === null) return null;
12954
- const trimmed = answer.trim();
12955
- if (trimmed.length > 0) return trimmed;
12956
- attempts += 1;
12957
- if (attempts > maxRetries || !isInteractive2) return null;
12958
- console.log(" (Press Enter without typing to skip \u2014 or answer Boo's question.)");
12959
- }
12960
- return null;
12961
- } finally {
12962
- rl.off("SIGINT", onSigInt);
12963
- rl.close();
12964
- }
12965
- }
12966
- function readOnce(rl, question) {
12967
- return new Promise((resolve) => {
12968
- let resolved = false;
12969
- const settle = (value) => {
12970
- if (resolved) return;
12971
- resolved = true;
12972
- resolve(value);
12973
- };
12974
- rl.once("close", () => settle(null));
12975
- rl.question(question, (answer) => settle(answer));
12976
- });
12977
- }
12978
- var init_prompt = __esm({
12979
- "src/lib/prompt.ts"() {
12980
- "use strict";
12981
- }
12982
- });
12983
-
12984
13159
  // src/lib/phases-impl/pick-first-user-agent-phase.ts
12985
13160
  import { readdir, readFile as readFile3, stat } from "node:fs/promises";
12986
13161
  import { dirname, join as pathJoin, resolve as pathResolve3 } from "node:path";
@@ -13728,47 +13903,6 @@ var init_claude_desktop = __esm({
13728
13903
  }
13729
13904
  });
13730
13905
 
13731
- // src/lib/workspace.ts
13732
- import { existsSync } from "node:fs";
13733
- async function resolveWorkspace() {
13734
- const state = await readState();
13735
- if (state) {
13736
- if (!existsSync(state.workspace_path)) {
13737
- throw new NoWorkspaceError(
13738
- `Bamboo workspace not found.
13739
- (State recorded ${state.workspace_path} but it's missing on disk \u2014 run \`bamboo-agents init --reset\` to re-clone.)`
13740
- );
13741
- }
13742
- return { path: state.workspace_path, orgId: state.org_id };
13743
- }
13744
- const config = await readConfig();
13745
- if (config) {
13746
- if (!existsSync(config.repo_path)) {
13747
- throw new NoWorkspaceError(
13748
- `Bamboo workspace not found.
13749
- (Config recorded ${config.repo_path} but it's missing on disk \u2014 run \`bamboo-agents init --reset\` to re-clone.)`
13750
- );
13751
- }
13752
- return { path: config.repo_path, orgId: config.org_id };
13753
- }
13754
- throw new NoWorkspaceError(
13755
- "No Bamboo workspace yet. Run `bamboo-agents init` first."
13756
- );
13757
- }
13758
- var NoWorkspaceError;
13759
- var init_workspace = __esm({
13760
- "src/lib/workspace.ts"() {
13761
- "use strict";
13762
- init_state();
13763
- NoWorkspaceError = class extends Error {
13764
- constructor(message) {
13765
- super(message);
13766
- this.name = "NoWorkspaceError";
13767
- }
13768
- };
13769
- }
13770
- });
13771
-
13772
13906
  // src/commands/open.ts
13773
13907
  var open_exports = {};
13774
13908
  __export(open_exports, {
@@ -14681,9 +14815,12 @@ program2.command("login").description("Sign in to Bamboo via your browser").acti
14681
14815
  const { runLogin: runLogin2 } = await Promise.resolve().then(() => (init_login(), login_exports));
14682
14816
  await runLogin2();
14683
14817
  });
14684
- program2.command("init").description("Clone your workspace + set up git credentials").action(async () => {
14818
+ program2.command("init").description("Clone your workspace + set up git credentials").option(
14819
+ "--reset",
14820
+ "Delete the existing workspace clone and start over (prompts for confirmation)"
14821
+ ).action(async (options) => {
14685
14822
  const { runInit: runInit2 } = await Promise.resolve().then(() => (init_init(), init_exports));
14686
- await runInit2();
14823
+ await runInit2({ reset: options.reset });
14687
14824
  });
14688
14825
  program2.command("open").description("Launch Claude Code at your workspace").action(async () => {
14689
14826
  const { runOpen: runOpen2 } = await Promise.resolve().then(() => (init_open2(), open_exports));