bamboo-agents 0.1.5-dev.23 → 0.1.5-dev.25

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.23
1
+ 0.1.5-dev.25
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.23";
3040
+ VERSION = "0.1.5-dev.25";
3041
3041
  }
3042
3042
  });
3043
3043
 
@@ -11483,7 +11483,8 @@ var init_auth_status = __esm({
11483
11483
  });
11484
11484
  MembershipSchema = external_exports.object({
11485
11485
  org: OrgRefSchema,
11486
- role: external_exports.enum(["owner", "admin", "member"]),
11486
+ // BAM-2229: `owner` collapsed into `admin`.
11487
+ role: external_exports.enum(["admin", "member"]),
11487
11488
  workspace_ready: external_exports.boolean()
11488
11489
  });
11489
11490
  InviterSchema = external_exports.object({
@@ -11565,6 +11566,80 @@ var init_onboarding_next_prompt = __esm({
11565
11566
  }
11566
11567
  });
11567
11568
 
11569
+ // ../../src/lib/api-contracts/cli/agents.ts
11570
+ var SlugSchema, NameSchema, BrandIdSchema, CliAgentRowSchema, CliTierCapSchema, CliAgentsListResponseSchema, CliCreateAgentRequestSchema, CliAgentMutationResponseBase, CliCreateAgentResponseSchema, UPLOAD_MAX_BYTES, CliUploadAgentRequestSchema, CliUploadAgentResponseSchema, CliBrandRowSchema, CliBrandsListResponseSchema;
11571
+ var init_agents = __esm({
11572
+ "../../src/lib/api-contracts/cli/agents.ts"() {
11573
+ init_zod();
11574
+ SlugSchema = external_exports.string().min(1).max(63).regex(/^[a-z0-9]+(?:-[a-z0-9]+)*$/, "slug must be lowercase kebab-case");
11575
+ NameSchema = external_exports.string().min(1).max(120);
11576
+ BrandIdSchema = external_exports.string().uuid();
11577
+ CliAgentRowSchema = external_exports.object({
11578
+ id: external_exports.string().uuid(),
11579
+ name: external_exports.string(),
11580
+ /** `false` = user-created (eligible for picker choices).
11581
+ * `true` = pre-installed (MAM etc.) — shown informational-only. */
11582
+ is_auto_installed: external_exports.boolean(),
11583
+ /**
11584
+ * 0..100 weighted health score (round at render time). Null when
11585
+ * the server omits the value (BAM-2246 omits today because per-agent
11586
+ * health is an N round-trip fan-out; CLI fetches lazily via
11587
+ * `/api/v1/agents/<id>/health`). Also null for legacy agents
11588
+ * without an effective_rubric (pre-BAM-2084 installs).
11589
+ */
11590
+ health_score: external_exports.number().nullable()
11591
+ });
11592
+ CliTierCapSchema = external_exports.object({
11593
+ limit: external_exports.number().int(),
11594
+ current: external_exports.number().int().nonnegative(),
11595
+ /** Display name for the user's tier (e.g. "Self-Serve"). */
11596
+ tier_name: external_exports.string().nullable()
11597
+ });
11598
+ CliAgentsListResponseSchema = external_exports.object({
11599
+ agents: external_exports.array(CliAgentRowSchema),
11600
+ tier_cap: CliTierCapSchema
11601
+ });
11602
+ CliCreateAgentRequestSchema = external_exports.object({
11603
+ brand_id: BrandIdSchema,
11604
+ name: NameSchema,
11605
+ slug: SlugSchema.optional()
11606
+ });
11607
+ CliAgentMutationResponseBase = external_exports.object({
11608
+ agent_id: external_exports.string().uuid(),
11609
+ /** e.g. "brands/acme/agents/paid-ads" — workspace-repo-relative. */
11610
+ folder_path: external_exports.string().min(1),
11611
+ /**
11612
+ * Whether the write landed straight on `main` (solo workspaces) or
11613
+ * was routed through a queue PR (multi-user — pending admin review).
11614
+ */
11615
+ write_status: external_exports.enum(["instant-merged", "queued-pr"]),
11616
+ /**
11617
+ * True iff the agent already existed (slug idempotency hit). When
11618
+ * true, `write_status` may be `"instant-merged"` even though no file
11619
+ * write happened this call — the existing folder is the answer.
11620
+ */
11621
+ reused: external_exports.boolean()
11622
+ });
11623
+ CliCreateAgentResponseSchema = CliAgentMutationResponseBase;
11624
+ UPLOAD_MAX_BYTES = 256 * 1024;
11625
+ CliUploadAgentRequestSchema = external_exports.object({
11626
+ brand_id: BrandIdSchema,
11627
+ name: NameSchema,
11628
+ slug: SlugSchema.optional(),
11629
+ /** Server caps at 256 KB and validates UTF-8. */
11630
+ claude_md_content: external_exports.string().min(1)
11631
+ });
11632
+ CliUploadAgentResponseSchema = CliAgentMutationResponseBase;
11633
+ CliBrandRowSchema = external_exports.object({
11634
+ id: external_exports.string().uuid(),
11635
+ name: external_exports.string()
11636
+ });
11637
+ CliBrandsListResponseSchema = external_exports.object({
11638
+ brands: external_exports.array(CliBrandRowSchema)
11639
+ });
11640
+ }
11641
+ });
11642
+
11568
11643
  // src/lib/api.ts
11569
11644
  import { platform as platform2 } from "node:os";
11570
11645
  function defaultApiBase(version) {
@@ -11701,6 +11776,54 @@ ${answer}
11701
11776
  Saved by Boo via CLI magic-moment, ${stamp}.
11702
11777
  `;
11703
11778
  }
11779
+ async function listCliAgents(bambooSession) {
11780
+ const res = await cliApiFetch(`${apiBase()}/api/v1/cli/agents`, {
11781
+ headers: { Authorization: `Bearer ${bambooSession}` }
11782
+ });
11783
+ if (!res.ok) throw await parseError(res);
11784
+ const json = await res.json();
11785
+ return CliAgentsListResponseSchema.parse(json);
11786
+ }
11787
+ async function listCliBrands(bambooSession) {
11788
+ const res = await cliApiFetch(`${apiBase()}/api/v1/cli/brands`, {
11789
+ headers: { Authorization: `Bearer ${bambooSession}` }
11790
+ });
11791
+ if (!res.ok) throw await parseError(res);
11792
+ const json = await res.json();
11793
+ return CliBrandsListResponseSchema.parse(json);
11794
+ }
11795
+ async function createAgentFromCli(bambooSession, body) {
11796
+ const res = await cliApiFetch(
11797
+ `${apiBase()}/api/v1/cli/agents/create-from-cli`,
11798
+ {
11799
+ method: "POST",
11800
+ headers: {
11801
+ Authorization: `Bearer ${bambooSession}`,
11802
+ "Content-Type": "application/json"
11803
+ },
11804
+ body: JSON.stringify(body)
11805
+ }
11806
+ );
11807
+ if (!res.ok) throw await parseError(res);
11808
+ const json = await res.json();
11809
+ return CliCreateAgentResponseSchema.parse(json);
11810
+ }
11811
+ async function uploadClaudeMdFromCli(bambooSession, body) {
11812
+ const res = await cliApiFetch(
11813
+ `${apiBase()}/api/v1/cli/agents/upload-claude-md`,
11814
+ {
11815
+ method: "POST",
11816
+ headers: {
11817
+ Authorization: `Bearer ${bambooSession}`,
11818
+ "Content-Type": "application/json"
11819
+ },
11820
+ body: JSON.stringify(body)
11821
+ }
11822
+ );
11823
+ if (!res.ok) throw await parseError(res);
11824
+ const json = await res.json();
11825
+ return CliUploadAgentResponseSchema.parse(json);
11826
+ }
11704
11827
  var PROD_DEFAULT_BASE, DEV_DEFAULT_BASE, REQUEST_TIMEOUT_MS, ApiError, OAuthRelinkStartResponseSchema, ProvisionWorkspaceResponseSchema, FirstAutoInstalledAgentResponseSchema;
11705
11828
  var init_api = __esm({
11706
11829
  "src/lib/api.ts"() {
@@ -11711,6 +11834,7 @@ var init_api = __esm({
11711
11834
  init_billing_status();
11712
11835
  init_agent_health();
11713
11836
  init_onboarding_next_prompt();
11837
+ init_agents();
11714
11838
  init_version();
11715
11839
  PROD_DEFAULT_BASE = "https://withbamboo.com";
11716
11840
  DEV_DEFAULT_BASE = "https://dev.withbamboo.com";
@@ -12669,6 +12793,316 @@ var init_prompt = __esm({
12669
12793
  }
12670
12794
  });
12671
12795
 
12796
+ // src/lib/phases-impl/pick-first-user-agent-phase.ts
12797
+ import { readFile as readFile3 } from "node:fs/promises";
12798
+ import { resolve as pathResolve3 } from "node:path";
12799
+ async function runCaseA(ctx) {
12800
+ console.log(" Let's set up YOUR first agent. How would you like to start?");
12801
+ console.log("");
12802
+ console.log(" 1) Create a new agent \u2014 I'll ask you a few questions");
12803
+ console.log(" 2) Upload an existing CLAUDE.md or AGENTS.md from your machine");
12804
+ console.log("");
12805
+ const choice = await promptChoice(" Choose [1-2]: ", ["1", "2"]);
12806
+ if (choice === null) return null;
12807
+ return choice === "1" ? runCreateFlow(ctx) : runUploadFlow(ctx);
12808
+ }
12809
+ async function runCaseB(ctx, agents) {
12810
+ console.log(
12811
+ ` You have ${agents.length} user-created ${pluralize(
12812
+ agents.length,
12813
+ "agent"
12814
+ )} so far:`
12815
+ );
12816
+ for (const a of agents) {
12817
+ console.log(` \u2022 ${a.name} \u2014 ${formatHealth(a.health_score)}`);
12818
+ }
12819
+ console.log("");
12820
+ console.log(" What's next?");
12821
+ console.log("");
12822
+ console.log(" 1) Create another agent");
12823
+ console.log(" 2) Upload an existing CLAUDE.md/AGENTS.md");
12824
+ console.log(
12825
+ ` 3) Improve ${agents.length === 1 ? `"${agents[0].name}"` : "an existing agent"} (run health check + next question)`
12826
+ );
12827
+ console.log("");
12828
+ const choice = await promptChoice(" Choose [1-3]: ", ["1", "2", "3"]);
12829
+ if (choice === null) return null;
12830
+ if (choice === "1") return runCreateFlow(ctx);
12831
+ if (choice === "2") return runUploadFlow(ctx);
12832
+ return runImproveExistingFlow(agents);
12833
+ }
12834
+ async function runCaseC(agents) {
12835
+ console.log(
12836
+ ` You're at your tier's agent cap (${agents.length}/${agents.length}). Pick one to improve:`
12837
+ );
12838
+ console.log("");
12839
+ agents.forEach((a, idx) => {
12840
+ console.log(` ${idx + 1}) ${a.name} \u2014 ${formatHealth(a.health_score)}`);
12841
+ });
12842
+ console.log("");
12843
+ console.log(` (To add more agents, upgrade your plan at ${BILLING_URL})`);
12844
+ console.log("");
12845
+ return runImproveExistingFlow(agents);
12846
+ }
12847
+ async function runImproveExistingFlow(agents) {
12848
+ const validChoices = agents.map((_, idx2) => String(idx2 + 1));
12849
+ const choice = await promptChoice(
12850
+ ` Choose [1-${agents.length}]: `,
12851
+ validChoices
12852
+ );
12853
+ if (choice === null) return null;
12854
+ const idx = Number.parseInt(choice, 10) - 1;
12855
+ return agents[idx]?.id ?? null;
12856
+ }
12857
+ async function runCreateFlow(ctx) {
12858
+ if (!ctx.credentials) return null;
12859
+ console.log("");
12860
+ const name = await promptStdin(" Agent name (e.g. Paid Ads Agent): ");
12861
+ if (!name) return null;
12862
+ const brand = await resolveBrand(ctx);
12863
+ if (!brand) return null;
12864
+ console.log("");
12865
+ console.log(" Creating your agent\u2026");
12866
+ try {
12867
+ const created = await createAgentFromCli(ctx.credentials.bamboo_session, {
12868
+ brand_id: brand.id,
12869
+ name
12870
+ });
12871
+ console.log("");
12872
+ console.log(` \u2713 Created agent at ${created.folder_path}`);
12873
+ return created.agent_id;
12874
+ } catch (err) {
12875
+ const message = err instanceof Error ? err.message : String(err);
12876
+ console.log("");
12877
+ console.log(` Couldn't create agent: ${message}`);
12878
+ return null;
12879
+ }
12880
+ }
12881
+ async function runUploadFlow(ctx) {
12882
+ if (!ctx.credentials) return null;
12883
+ console.log("");
12884
+ const defaultsHint = UPLOAD_DEFAULT_PATHS.join(" or ");
12885
+ const filePathInput = await promptStdin(
12886
+ ` Path to the CLAUDE.md/AGENTS.md file (default: ${defaultsHint}): `
12887
+ );
12888
+ const filePath = filePathInput ?? UPLOAD_DEFAULT_PATHS[0];
12889
+ const absPath = pathResolve3(ctx.cwd, filePath);
12890
+ let content;
12891
+ try {
12892
+ content = await readFile3(absPath, "utf8");
12893
+ } catch (err) {
12894
+ const message = err instanceof Error ? err.message : String(err);
12895
+ console.log("");
12896
+ console.log(` Couldn't read ${absPath}: ${message}`);
12897
+ return null;
12898
+ }
12899
+ const bytes = Buffer.byteLength(content, "utf8");
12900
+ if (bytes > MAX_UPLOAD_BYTES) {
12901
+ console.log("");
12902
+ console.log(
12903
+ ` ${absPath} is ${Math.round(bytes / 1024)} KB \u2014 server caps uploads at 256 KB.`
12904
+ );
12905
+ return null;
12906
+ }
12907
+ if (content.trim().length === 0) {
12908
+ console.log("");
12909
+ console.log(` ${absPath} is empty \u2014 nothing to upload.`);
12910
+ return null;
12911
+ }
12912
+ console.log("");
12913
+ console.log(` Preview of ${absPath} (${Math.round(bytes / 1024)} KB):`);
12914
+ console.log("");
12915
+ const previewLines = content.split("\n").slice(0, 6);
12916
+ for (const line of previewLines) {
12917
+ console.log(` ${line}`);
12918
+ }
12919
+ if (content.split("\n").length > 6) {
12920
+ console.log(" \u2026");
12921
+ }
12922
+ console.log("");
12923
+ const confirm = await promptChoice(
12924
+ " Upload this? [y/n]: ",
12925
+ ["y", "n", "Y", "N"]
12926
+ );
12927
+ if (confirm === null || confirm.toLowerCase() !== "y") return null;
12928
+ console.log("");
12929
+ const name = await promptStdin(
12930
+ " Name this agent (e.g. My Existing Agent): "
12931
+ );
12932
+ if (!name) return null;
12933
+ const brand = await resolveBrand(ctx);
12934
+ if (!brand) return null;
12935
+ console.log("");
12936
+ console.log(" Uploading\u2026");
12937
+ try {
12938
+ const uploaded = await uploadClaudeMdFromCli(
12939
+ ctx.credentials.bamboo_session,
12940
+ {
12941
+ brand_id: brand.id,
12942
+ name,
12943
+ claude_md_content: content
12944
+ }
12945
+ );
12946
+ console.log("");
12947
+ console.log(` \u2713 Uploaded to ${uploaded.folder_path}`);
12948
+ return uploaded.agent_id;
12949
+ } catch (err) {
12950
+ const message = err instanceof Error ? err.message : String(err);
12951
+ console.log("");
12952
+ console.log(` Couldn't upload agent: ${message}`);
12953
+ return null;
12954
+ }
12955
+ }
12956
+ async function resolveBrand(ctx) {
12957
+ if (!ctx.credentials) return null;
12958
+ let brands;
12959
+ try {
12960
+ const listed = await listCliBrands(ctx.credentials.bamboo_session);
12961
+ brands = listed.brands;
12962
+ } catch (err) {
12963
+ const message = err instanceof Error ? err.message : String(err);
12964
+ console.log("");
12965
+ console.log(` Couldn't load brands: ${message}`);
12966
+ return null;
12967
+ }
12968
+ if (brands.length === 0) {
12969
+ console.log("");
12970
+ console.log(
12971
+ " No brands found in this org. Create one in the app first, then re-run."
12972
+ );
12973
+ return null;
12974
+ }
12975
+ if (brands.length === 1) {
12976
+ console.log("");
12977
+ console.log(` Using brand: ${brands[0].name}`);
12978
+ return brands[0];
12979
+ }
12980
+ console.log("");
12981
+ console.log(" Which brand should this agent belong to?");
12982
+ brands.forEach((b, idx) => {
12983
+ console.log(` ${idx + 1}) ${b.name}`);
12984
+ });
12985
+ console.log("");
12986
+ const validChoices = brands.map(
12987
+ (_, idx) => String(idx + 1)
12988
+ );
12989
+ const choice = await promptChoice(
12990
+ ` Choose [1-${brands.length}]: `,
12991
+ validChoices
12992
+ );
12993
+ if (choice === null) return null;
12994
+ return brands[Number.parseInt(choice, 10) - 1] ?? null;
12995
+ }
12996
+ async function promptChoice(question, validChoices) {
12997
+ for (let attempt = 0; attempt < 5; attempt += 1) {
12998
+ const answer = await promptStdin(question);
12999
+ if (answer === null) return null;
13000
+ if (validChoices.includes(answer)) return answer;
13001
+ console.log(` Please choose one of: ${validChoices.join(", ")}`);
13002
+ }
13003
+ return null;
13004
+ }
13005
+ function formatHealth(score) {
13006
+ if (score === null) return "health unknown";
13007
+ const tenScale = Math.round(score / 10);
13008
+ return `health ${tenScale}/10`;
13009
+ }
13010
+ function pluralize(n, word) {
13011
+ return n === 1 ? word : `${word}s`;
13012
+ }
13013
+ var BILLING_URL, UPLOAD_DEFAULT_PATHS, MAX_UPLOAD_BYTES, pickFirstUserAgentSpec;
13014
+ var init_pick_first_user_agent_phase = __esm({
13015
+ "src/lib/phases-impl/pick-first-user-agent-phase.ts"() {
13016
+ "use strict";
13017
+ init_api();
13018
+ init_prompt();
13019
+ BILLING_URL = "https://withbamboo.com/billing";
13020
+ UPLOAD_DEFAULT_PATHS = ["./CLAUDE.md", "./AGENTS.md"];
13021
+ MAX_UPLOAD_BYTES = 256 * 1024;
13022
+ pickFirstUserAgentSpec = {
13023
+ name: "pick-first-user-agent",
13024
+ async probe(ctx) {
13025
+ if (!ctx.credentials) {
13026
+ return {
13027
+ status: "needs_action",
13028
+ summary: "(no creds)",
13029
+ reason: "Internal: pickFirstUserAgentSpec.probe called without creds."
13030
+ };
13031
+ }
13032
+ if (process.stdin.isTTY === false) {
13033
+ return {
13034
+ status: "needs_action",
13035
+ summary: "(no terminal)",
13036
+ reason: "pick-first-user-agent requires a terminal \u2014 re-run interactively. (Set BAMBOO_DEFAULT_PICKER_CHOICE to skip prompts in a future release.)"
13037
+ };
13038
+ }
13039
+ let listing;
13040
+ try {
13041
+ listing = await listCliAgents(ctx.credentials.bamboo_session);
13042
+ } catch (err) {
13043
+ if (err instanceof ApiError && err.status === 401) {
13044
+ return { status: "needs_relogin", summary: "session expired" };
13045
+ }
13046
+ const message = err instanceof Error ? err.message : String(err);
13047
+ return {
13048
+ status: "needs_action",
13049
+ summary: "(couldn't list agents)",
13050
+ reason: `Couldn't load your agents from the server: ${message}
13051
+ Try again in a moment, or run \`bamboo-agents doctor\`.`
13052
+ };
13053
+ }
13054
+ ctx.pickFirstUserAgent = listing;
13055
+ return {
13056
+ status: "needs_work",
13057
+ summary: "pick which agent to set up"
13058
+ };
13059
+ },
13060
+ async execute(ctx) {
13061
+ const listing = ctx.pickFirstUserAgent;
13062
+ if (!listing || !ctx.credentials) {
13063
+ return {
13064
+ kind: "needs_action",
13065
+ reason: "Internal: pickFirstUserAgentSpec.execute called without a stashed listing."
13066
+ };
13067
+ }
13068
+ const userCreated = listing.agents.filter((a) => !a.is_auto_installed);
13069
+ const preInstalled = listing.agents.filter((a) => a.is_auto_installed);
13070
+ const cap = listing.tier_cap;
13071
+ const atCap = cap.limit > -1 && cap.current >= cap.limit;
13072
+ console.log("");
13073
+ if (preInstalled.length > 0) {
13074
+ console.log(
13075
+ " Your workspace already has these pre-installed agents:"
13076
+ );
13077
+ for (const a of preInstalled) {
13078
+ console.log(` \u2022 ${a.name} (sample)`);
13079
+ }
13080
+ console.log("");
13081
+ }
13082
+ let pickedAgentId;
13083
+ if (userCreated.length === 0) {
13084
+ pickedAgentId = await runCaseA(ctx);
13085
+ } else if (atCap) {
13086
+ pickedAgentId = await runCaseC(userCreated);
13087
+ } else {
13088
+ pickedAgentId = await runCaseB(ctx, userCreated);
13089
+ }
13090
+ if (!pickedAgentId) {
13091
+ return {
13092
+ kind: "needs_action",
13093
+ reason: "Couldn't pick a user agent. Re-run `bamboo-agents` when you're ready."
13094
+ };
13095
+ }
13096
+ ctx.agentId = pickedAgentId;
13097
+ return {
13098
+ kind: "advanced",
13099
+ summary: `picked agent ${pickedAgentId}`
13100
+ };
13101
+ }
13102
+ };
13103
+ }
13104
+ });
13105
+
12672
13106
  // src/lib/phases-impl/magic-moment-phase.ts
12673
13107
  var magicMomentSpec;
12674
13108
  var init_magic_moment_phase = __esm({
@@ -12928,7 +13362,8 @@ async function runOrchestrator() {
12928
13362
  credentials: null,
12929
13363
  membership: null,
12930
13364
  config: null,
12931
- cwd: process.cwd()
13365
+ cwd: process.cwd(),
13366
+ agentId: null
12932
13367
  };
12933
13368
  for (const phase of PHASES) {
12934
13369
  let probe = await phase.probe(ctx);
@@ -12957,7 +13392,7 @@ async function runOrchestrator() {
12957
13392
  }
12958
13393
  if (probe.status === "done") {
12959
13394
  console.log(` \u2713 ${probe.summary}`);
12960
- if (phase.name === cloneOrAdoptSpec.name) {
13395
+ if (phase.name === pickFirstUserAgentSpec.name) {
12961
13396
  await printHealthLine(ctx);
12962
13397
  }
12963
13398
  continue;
@@ -12967,7 +13402,7 @@ async function runOrchestrator() {
12967
13402
  printNeedsAction(result.reason);
12968
13403
  process.exit(2);
12969
13404
  }
12970
- if (phase.name === cloneOrAdoptSpec.name) {
13405
+ if (phase.name === pickFirstUserAgentSpec.name) {
12971
13406
  await printHealthLine(ctx);
12972
13407
  }
12973
13408
  }
@@ -12981,6 +13416,7 @@ var init_orchestrator = __esm({
12981
13416
  init_login_phase();
12982
13417
  init_provision_phase();
12983
13418
  init_clone_or_adopt_phase();
13419
+ init_pick_first_user_agent_phase();
12984
13420
  init_magic_moment_phase();
12985
13421
  init_open_phase();
12986
13422
  init_health_line();
@@ -12988,6 +13424,7 @@ var init_orchestrator = __esm({
12988
13424
  loginSpec,
12989
13425
  provisionSpec,
12990
13426
  cloneOrAdoptSpec,
13427
+ pickFirstUserAgentSpec,
12991
13428
  magicMomentSpec,
12992
13429
  openSpec
12993
13430
  ];