bamboo-agents 0.1.5-dev.50.88138ae → 0.1.5-dev.51.78fa2ce

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.50.88138ae";
3040
+ VERSION = "0.1.5-dev.51.78fa2ce";
3041
3041
  }
3042
3042
  });
3043
3043
 
@@ -7374,6 +7374,153 @@ var init_onboarding_status = __esm({
7374
7374
  }
7375
7375
  });
7376
7376
 
7377
+ // ../../src/lib/api-contracts/cli/agents.ts
7378
+ var agents_exports = {};
7379
+ __export(agents_exports, {
7380
+ CliAgentDetailSchema: () => CliAgentDetailSchema,
7381
+ CliAgentGetResponseSchema: () => CliAgentGetResponseSchema,
7382
+ CliAgentLifecycleStateSchema: () => CliAgentLifecycleStateSchema,
7383
+ CliAgentPauseResponseSchema: () => CliAgentPauseResponseSchema,
7384
+ CliAgentPublishResponseSchema: () => CliAgentPublishResponseSchema,
7385
+ CliAgentRowSchema: () => CliAgentRowSchema,
7386
+ CliAgentsListResponseSchema: () => CliAgentsListResponseSchema,
7387
+ CliBrandRowSchema: () => CliBrandRowSchema,
7388
+ CliBrandsListResponseSchema: () => CliBrandsListResponseSchema,
7389
+ CliCreateAgentRequestSchema: () => CliCreateAgentRequestSchema,
7390
+ CliCreateAgentResponseSchema: () => CliCreateAgentResponseSchema,
7391
+ CliTierCapSchema: () => CliTierCapSchema,
7392
+ CliUploadAgentRequestSchema: () => CliUploadAgentRequestSchema,
7393
+ CliUploadAgentResponseSchema: () => CliUploadAgentResponseSchema,
7394
+ CreateFromCliRequestSchema: () => CreateFromCliRequestSchema,
7395
+ CreateFromCliResponseSchema: () => CreateFromCliResponseSchema,
7396
+ UPLOAD_MAX_BYTES: () => UPLOAD_MAX_BYTES,
7397
+ UploadClaudeMdRequestSchema: () => UploadClaudeMdRequestSchema,
7398
+ UploadClaudeMdResponseSchema: () => UploadClaudeMdResponseSchema
7399
+ });
7400
+ var SlugSchema, NameSchema, BrandIdSchema, CliAgentRowSchema, CliTierCapSchema, CliAgentsListResponseSchema, CliCreateAgentRequestSchema, CliAgentMutationResponseBase, CliCreateAgentResponseSchema, UPLOAD_MAX_BYTES, CliUploadAgentRequestSchema, CliUploadAgentResponseSchema, CliBrandRowSchema, CliBrandsListResponseSchema, CliAgentLifecycleStateSchema, CliAgentDetailSchema, CliAgentGetResponseSchema, CliAgentPauseResponseSchema, CliAgentPublishResponseSchema, CreateFromCliRequestSchema, CreateFromCliResponseSchema, UploadClaudeMdRequestSchema, UploadClaudeMdResponseSchema;
7401
+ var init_agents = __esm({
7402
+ "../../src/lib/api-contracts/cli/agents.ts"() {
7403
+ init_zod();
7404
+ SlugSchema = external_exports.string().min(1).max(63).regex(/^[a-z0-9]+(?:-[a-z0-9]+)*$/, "slug must be lowercase kebab-case");
7405
+ NameSchema = external_exports.string().min(1).max(120);
7406
+ BrandIdSchema = external_exports.string().uuid();
7407
+ CliAgentRowSchema = external_exports.object({
7408
+ id: external_exports.string().uuid(),
7409
+ name: external_exports.string(),
7410
+ /** `false` = user-created (eligible for picker choices).
7411
+ * `true` = pre-installed (MAM etc.) — shown informational-only. */
7412
+ is_auto_installed: external_exports.boolean(),
7413
+ /** Canonical kebab-case identifier — last segment of `folder_path`
7414
+ * (`brands/<brand>/agents/<slug>`). `null` for legacy rows whose
7415
+ * `folder_path` is missing or malformed. */
7416
+ slug: external_exports.string().nullable(),
7417
+ /**
7418
+ * BAM-2593 lifecycle fields. OPTIONAL on purpose: the BAM-2243 picker
7419
+ * pre-dates them and doesn't need them, and keeping them optional makes
7420
+ * a new-CLI → old-server response (which omits them) still parse. The
7421
+ * BAM-2593 server always populates them; the `bamboo agents list`
7422
+ * renderer shows the state when present.
7423
+ */
7424
+ status: external_exports.enum(["draft", "ready", "broken"]).optional(),
7425
+ /** ISO timestamp when paused, else null. */
7426
+ paused_at: external_exports.string().nullable().optional(),
7427
+ /** Lite derived state (active/paused/inactive) — see CliAgentLifecycleStateSchema. */
7428
+ state: external_exports.enum(["active", "paused", "inactive"]).optional()
7429
+ });
7430
+ CliTierCapSchema = external_exports.object({
7431
+ limit: external_exports.number().int(),
7432
+ current: external_exports.number().int().nonnegative(),
7433
+ /** Display name for the user's tier (e.g. "Self-Serve"). */
7434
+ tier_name: external_exports.string().nullable()
7435
+ });
7436
+ CliAgentsListResponseSchema = external_exports.object({
7437
+ agents: external_exports.array(CliAgentRowSchema),
7438
+ tier_cap: CliTierCapSchema
7439
+ });
7440
+ CliCreateAgentRequestSchema = external_exports.object({
7441
+ brand_id: BrandIdSchema,
7442
+ name: NameSchema,
7443
+ slug: SlugSchema.optional()
7444
+ });
7445
+ CliAgentMutationResponseBase = external_exports.object({
7446
+ agent_id: external_exports.string().uuid(),
7447
+ /** e.g. "brands/acme/agents/paid-ads" — workspace-repo-relative. */
7448
+ folder_path: external_exports.string().min(1),
7449
+ /**
7450
+ * Whether the write landed straight on `main` (solo workspaces) or
7451
+ * was routed through a queue PR (multi-user — pending admin review).
7452
+ */
7453
+ write_status: external_exports.enum(["instant-merged", "queued-pr"]),
7454
+ /**
7455
+ * True iff the agent already existed (slug idempotency hit). When
7456
+ * true, `write_status` may be `"instant-merged"` even though no file
7457
+ * write happened this call — the existing folder is the answer.
7458
+ */
7459
+ reused: external_exports.boolean()
7460
+ });
7461
+ CliCreateAgentResponseSchema = CliAgentMutationResponseBase;
7462
+ UPLOAD_MAX_BYTES = 256 * 1024;
7463
+ CliUploadAgentRequestSchema = external_exports.object({
7464
+ brand_id: BrandIdSchema,
7465
+ name: NameSchema,
7466
+ slug: SlugSchema.optional(),
7467
+ /** Server caps at 256 KB and validates UTF-8. */
7468
+ claude_md_content: external_exports.string().min(1)
7469
+ });
7470
+ CliUploadAgentResponseSchema = CliAgentMutationResponseBase;
7471
+ CliBrandRowSchema = external_exports.object({
7472
+ id: external_exports.string().uuid(),
7473
+ name: external_exports.string()
7474
+ });
7475
+ CliBrandsListResponseSchema = external_exports.object({
7476
+ brands: external_exports.array(CliBrandRowSchema)
7477
+ });
7478
+ CliAgentLifecycleStateSchema = external_exports.enum([
7479
+ "active",
7480
+ "paused",
7481
+ "inactive"
7482
+ ]);
7483
+ CliAgentDetailSchema = external_exports.object({
7484
+ id: external_exports.string().uuid(),
7485
+ name: external_exports.string(),
7486
+ slug: external_exports.string().nullable(),
7487
+ status: external_exports.enum(["draft", "ready", "broken"]),
7488
+ paused_at: external_exports.string().nullable(),
7489
+ state: CliAgentLifecycleStateSchema,
7490
+ is_auto_installed: external_exports.boolean(),
7491
+ is_system: external_exports.boolean(),
7492
+ template_key: external_exports.string().nullable(),
7493
+ execution_runtime: external_exports.string().nullable(),
7494
+ folder_path: external_exports.string().nullable(),
7495
+ repo_url: external_exports.string().nullable(),
7496
+ description: external_exports.string().nullable(),
7497
+ created_at: external_exports.string().nullable(),
7498
+ /** Brand m:m links (agent_brands → brands). */
7499
+ brands: external_exports.array(CliBrandRowSchema)
7500
+ });
7501
+ CliAgentGetResponseSchema = external_exports.object({
7502
+ agent: CliAgentDetailSchema
7503
+ });
7504
+ CliAgentPauseResponseSchema = external_exports.object({
7505
+ agent: external_exports.object({
7506
+ id: external_exports.string().uuid(),
7507
+ status: external_exports.enum(["draft", "ready", "broken"]),
7508
+ paused_at: external_exports.string().nullable()
7509
+ })
7510
+ });
7511
+ CliAgentPublishResponseSchema = external_exports.object({
7512
+ agent_id: external_exports.string().uuid(),
7513
+ repo_url: external_exports.string().nullable().optional(),
7514
+ folder_path: external_exports.string().nullable().optional(),
7515
+ reused: external_exports.boolean().optional()
7516
+ });
7517
+ CreateFromCliRequestSchema = CliCreateAgentRequestSchema;
7518
+ CreateFromCliResponseSchema = CliCreateAgentResponseSchema;
7519
+ UploadClaudeMdRequestSchema = CliUploadAgentRequestSchema;
7520
+ UploadClaudeMdResponseSchema = CliUploadAgentResponseSchema;
7521
+ }
7522
+ });
7523
+
7377
7524
  // src/lib/paths.ts
7378
7525
  import { homedir } from "node:os";
7379
7526
  import { join } from "node:path";
@@ -12137,76 +12284,6 @@ var init_onboarding_next_prompt = __esm({
12137
12284
  }
12138
12285
  });
12139
12286
 
12140
- // ../../src/lib/api-contracts/cli/agents.ts
12141
- var SlugSchema, NameSchema, BrandIdSchema, CliAgentRowSchema, CliTierCapSchema, CliAgentsListResponseSchema, CliCreateAgentRequestSchema, CliAgentMutationResponseBase, CliCreateAgentResponseSchema, UPLOAD_MAX_BYTES, CliUploadAgentRequestSchema, CliUploadAgentResponseSchema, CliBrandRowSchema, CliBrandsListResponseSchema;
12142
- var init_agents = __esm({
12143
- "../../src/lib/api-contracts/cli/agents.ts"() {
12144
- init_zod();
12145
- SlugSchema = external_exports.string().min(1).max(63).regex(/^[a-z0-9]+(?:-[a-z0-9]+)*$/, "slug must be lowercase kebab-case");
12146
- NameSchema = external_exports.string().min(1).max(120);
12147
- BrandIdSchema = external_exports.string().uuid();
12148
- CliAgentRowSchema = external_exports.object({
12149
- id: external_exports.string().uuid(),
12150
- name: external_exports.string(),
12151
- /** `false` = user-created (eligible for picker choices).
12152
- * `true` = pre-installed (MAM etc.) — shown informational-only. */
12153
- is_auto_installed: external_exports.boolean(),
12154
- /** Canonical kebab-case identifier — last segment of `folder_path`
12155
- * (`brands/<brand>/agents/<slug>`). `null` for legacy rows whose
12156
- * `folder_path` is missing or malformed. */
12157
- slug: external_exports.string().nullable()
12158
- });
12159
- CliTierCapSchema = external_exports.object({
12160
- limit: external_exports.number().int(),
12161
- current: external_exports.number().int().nonnegative(),
12162
- /** Display name for the user's tier (e.g. "Self-Serve"). */
12163
- tier_name: external_exports.string().nullable()
12164
- });
12165
- CliAgentsListResponseSchema = external_exports.object({
12166
- agents: external_exports.array(CliAgentRowSchema),
12167
- tier_cap: CliTierCapSchema
12168
- });
12169
- CliCreateAgentRequestSchema = external_exports.object({
12170
- brand_id: BrandIdSchema,
12171
- name: NameSchema,
12172
- slug: SlugSchema.optional()
12173
- });
12174
- CliAgentMutationResponseBase = external_exports.object({
12175
- agent_id: external_exports.string().uuid(),
12176
- /** e.g. "brands/acme/agents/paid-ads" — workspace-repo-relative. */
12177
- folder_path: external_exports.string().min(1),
12178
- /**
12179
- * Whether the write landed straight on `main` (solo workspaces) or
12180
- * was routed through a queue PR (multi-user — pending admin review).
12181
- */
12182
- write_status: external_exports.enum(["instant-merged", "queued-pr"]),
12183
- /**
12184
- * True iff the agent already existed (slug idempotency hit). When
12185
- * true, `write_status` may be `"instant-merged"` even though no file
12186
- * write happened this call — the existing folder is the answer.
12187
- */
12188
- reused: external_exports.boolean()
12189
- });
12190
- CliCreateAgentResponseSchema = CliAgentMutationResponseBase;
12191
- UPLOAD_MAX_BYTES = 256 * 1024;
12192
- CliUploadAgentRequestSchema = external_exports.object({
12193
- brand_id: BrandIdSchema,
12194
- name: NameSchema,
12195
- slug: SlugSchema.optional(),
12196
- /** Server caps at 256 KB and validates UTF-8. */
12197
- claude_md_content: external_exports.string().min(1)
12198
- });
12199
- CliUploadAgentResponseSchema = CliAgentMutationResponseBase;
12200
- CliBrandRowSchema = external_exports.object({
12201
- id: external_exports.string().uuid(),
12202
- name: external_exports.string()
12203
- });
12204
- CliBrandsListResponseSchema = external_exports.object({
12205
- brands: external_exports.array(CliBrandRowSchema)
12206
- });
12207
- }
12208
- });
12209
-
12210
12287
  // ../../src/lib/api-contracts/cli/context-health.ts
12211
12288
  var ScopeKindSchema, ScopeSchema, CriterionMetricsSchema, StatusSchema, CriterionContributionSchema, CriterionResultSchema, BucketScoresSchema, ResolvedScopeSchema, GapsSchema, HealthyResponseSchema, UnavailableResponseSchema, ContextHealthResponseSchema;
12212
12289
  var init_context_health = __esm({
@@ -12520,6 +12597,41 @@ async function createAgentFromCli(bambooSession, body) {
12520
12597
  const json = await res.json();
12521
12598
  return CliCreateAgentResponseSchema.parse(json);
12522
12599
  }
12600
+ async function getCliAgent(bambooSession, agentId) {
12601
+ const res = await cliApiFetch(
12602
+ `${apiBase()}/api/v1/cli/agents/${encodeURIComponent(agentId)}`,
12603
+ { headers: { Authorization: `Bearer ${bambooSession}` } }
12604
+ );
12605
+ if (!res.ok) throw await parseError(res);
12606
+ return CliAgentGetResponseSchema.parse(await res.json());
12607
+ }
12608
+ async function pauseCliAgent(bambooSession, agentId) {
12609
+ const res = await cliApiFetch(
12610
+ `${apiBase()}/api/v1/agents/${encodeURIComponent(agentId)}/pause`,
12611
+ { method: "POST", headers: { Authorization: `Bearer ${bambooSession}` } }
12612
+ );
12613
+ if (!res.ok) throw await parseError(res);
12614
+ const json = await res.json();
12615
+ return CliAgentPauseResponseSchema.parse(json.data);
12616
+ }
12617
+ async function unpauseCliAgent(bambooSession, agentId) {
12618
+ const res = await cliApiFetch(
12619
+ `${apiBase()}/api/v1/agents/${encodeURIComponent(agentId)}/unpause`,
12620
+ { method: "POST", headers: { Authorization: `Bearer ${bambooSession}` } }
12621
+ );
12622
+ if (!res.ok) throw await parseError(res);
12623
+ const json = await res.json();
12624
+ return CliAgentPauseResponseSchema.parse(json.data);
12625
+ }
12626
+ async function publishCliAgent(bambooSession, agentId) {
12627
+ const res = await cliApiFetch(
12628
+ `${apiBase()}/api/v1/agents/${encodeURIComponent(agentId)}/provision`,
12629
+ { method: "POST", headers: { Authorization: `Bearer ${bambooSession}` } }
12630
+ );
12631
+ if (!res.ok) throw await parseError(res);
12632
+ const json = await res.json();
12633
+ return CliAgentPublishResponseSchema.parse(json.data);
12634
+ }
12523
12635
  async function getAgentSkills(bambooSession, agentId) {
12524
12636
  const res = await cliApiFetch(
12525
12637
  `${apiBase()}/api/v1/agents/${encodeURIComponent(agentId)}/skills`,
@@ -13620,14 +13732,14 @@ async function runCaseA(ctx) {
13620
13732
  if (choice === null) return null;
13621
13733
  return choice === "1" ? runCreateFlow(ctx) : runUploadFlow(ctx);
13622
13734
  }
13623
- async function runCaseB(ctx, agents, healthByAgentId) {
13735
+ async function runCaseB(ctx, agents2, healthByAgentId) {
13624
13736
  console.log(
13625
- ` You have ${agents.length} user-created ${pluralize(
13626
- agents.length,
13737
+ ` You have ${agents2.length} user-created ${pluralize(
13738
+ agents2.length,
13627
13739
  "agent"
13628
13740
  )} so far:`
13629
13741
  );
13630
- for (const a of agents) {
13742
+ for (const a of agents2) {
13631
13743
  console.log(
13632
13744
  ` \u2022 ${a.name} \u2014 ${formatHealth(healthByAgentId.get(a.id) ?? null)}`
13633
13745
  );
@@ -13638,21 +13750,21 @@ async function runCaseB(ctx, agents, healthByAgentId) {
13638
13750
  console.log(" 1) Create another agent");
13639
13751
  console.log(" 2) Upload an existing CLAUDE.md/AGENTS.md");
13640
13752
  console.log(
13641
- ` 3) Improve ${agents.length === 1 ? `"${agents[0].name}"` : "an existing agent"} (run health check + next question)`
13753
+ ` 3) Improve ${agents2.length === 1 ? `"${agents2[0].name}"` : "an existing agent"} (run health check + next question)`
13642
13754
  );
13643
13755
  console.log("");
13644
13756
  const choice = await promptChoice(" Choose [1-3]: ", ["1", "2", "3"]);
13645
13757
  if (choice === null) return null;
13646
13758
  if (choice === "1") return runCreateFlow(ctx);
13647
13759
  if (choice === "2") return runUploadFlow(ctx);
13648
- return runImproveExistingFlow(agents);
13760
+ return runImproveExistingFlow(agents2);
13649
13761
  }
13650
- async function runCaseC(agents, healthByAgentId) {
13762
+ async function runCaseC(agents2, healthByAgentId) {
13651
13763
  console.log(
13652
- ` You're at your tier's agent cap (${agents.length}/${agents.length}). Pick one to improve:`
13764
+ ` You're at your tier's agent cap (${agents2.length}/${agents2.length}). Pick one to improve:`
13653
13765
  );
13654
13766
  console.log("");
13655
- agents.forEach((a, idx) => {
13767
+ agents2.forEach((a, idx) => {
13656
13768
  console.log(
13657
13769
  ` ${idx + 1}) ${a.name} \u2014 ${formatHealth(healthByAgentId.get(a.id) ?? null)}`
13658
13770
  );
@@ -13660,17 +13772,17 @@ async function runCaseC(agents, healthByAgentId) {
13660
13772
  console.log("");
13661
13773
  console.log(` (To add more agents, upgrade your plan at ${BILLING_URL})`);
13662
13774
  console.log("");
13663
- return runImproveExistingFlow(agents);
13775
+ return runImproveExistingFlow(agents2);
13664
13776
  }
13665
- async function runImproveExistingFlow(agents) {
13666
- const validChoices = agents.map((_, idx2) => String(idx2 + 1));
13777
+ async function runImproveExistingFlow(agents2) {
13778
+ const validChoices = agents2.map((_, idx2) => String(idx2 + 1));
13667
13779
  const choice = await promptChoice(
13668
- ` Choose [1-${agents.length}]: `,
13780
+ ` Choose [1-${agents2.length}]: `,
13669
13781
  validChoices
13670
13782
  );
13671
13783
  if (choice === null) return null;
13672
13784
  const idx = Number.parseInt(choice, 10) - 1;
13673
- return agents[idx]?.id ?? null;
13785
+ return agents2[idx]?.id ?? null;
13674
13786
  }
13675
13787
  async function runCreateFlow(ctx) {
13676
13788
  if (!ctx.credentials) return null;
@@ -16063,16 +16175,16 @@ async function resolveAgent(bambooSession, identifier) {
16063
16175
  if (byName) return { id: byName.id, name: byName.name };
16064
16176
  return null;
16065
16177
  }
16066
- function printAgentNotFound(identifier, agents) {
16178
+ function printAgentNotFound(identifier, agents2) {
16067
16179
  console.error(`bamboo-agents: agent not found: ${identifier}`);
16068
- if (agents.length === 0) {
16180
+ if (agents2.length === 0) {
16069
16181
  console.error(
16070
16182
  "No agents in this org yet. Run `bamboo-agents` to create one."
16071
16183
  );
16072
16184
  } else {
16073
16185
  console.error("");
16074
16186
  console.error("Available agents (slug \u2014 name):");
16075
- for (const a of agents) {
16187
+ for (const a of agents2) {
16076
16188
  const label = a.slug ?? `${a.id.slice(0, 8)} (no slug)`;
16077
16189
  console.error(` ${label} \u2014 ${a.name}`);
16078
16190
  }
@@ -16796,6 +16908,271 @@ var init_onboarding = __esm({
16796
16908
  }
16797
16909
  });
16798
16910
 
16911
+ // src/commands/agents.ts
16912
+ var agents_exports2 = {};
16913
+ __export(agents_exports2, {
16914
+ runAgentsActivate: () => runAgentsActivate,
16915
+ runAgentsGet: () => runAgentsGet,
16916
+ runAgentsList: () => runAgentsList,
16917
+ runAgentsPause: () => runAgentsPause,
16918
+ runAgentsProvision: () => runAgentsProvision
16919
+ });
16920
+ async function requireSession7(opts) {
16921
+ const creds = await readCredentials();
16922
+ if (!creds) {
16923
+ emitError(
16924
+ {
16925
+ code: "not_signed_in",
16926
+ message: "not signed in.",
16927
+ hint: "Run `bamboo-agents login` first."
16928
+ },
16929
+ opts,
16930
+ 1
16931
+ );
16932
+ throw new Error("unreachable");
16933
+ }
16934
+ return creds.bamboo_session;
16935
+ }
16936
+ function padRight4(s, n) {
16937
+ return s.length >= n ? s : s + " ".repeat(n - s.length);
16938
+ }
16939
+ async function resolveAgentRef(session, rawRef, opts) {
16940
+ const ref = rawRef.trim();
16941
+ let list;
16942
+ try {
16943
+ list = await listCliAgents(session);
16944
+ } catch (err) {
16945
+ emitError(
16946
+ {
16947
+ code: "agents_list_failed",
16948
+ message: `couldn't resolve agent "${ref}": ${err.message}`
16949
+ },
16950
+ opts,
16951
+ 1
16952
+ );
16953
+ throw new Error("unreachable");
16954
+ }
16955
+ const agents2 = list.agents;
16956
+ const exactId = agents2.find((a) => a.id === ref);
16957
+ if (exactId) return exactId;
16958
+ const lower = ref.toLowerCase();
16959
+ const matches = agents2.filter(
16960
+ (a) => a.slug !== null && a.slug === lower || a.name.toLowerCase() === lower || ref.length >= 8 && a.id.startsWith(ref)
16961
+ );
16962
+ if (matches.length === 1) return matches[0];
16963
+ if (matches.length === 0) {
16964
+ emitError(
16965
+ {
16966
+ code: "agent_not_found",
16967
+ message: `no agent matches "${ref}".`,
16968
+ hint: "Run `bamboo-agents agents list` to see ids, slugs, and names."
16969
+ },
16970
+ opts,
16971
+ 1
16972
+ );
16973
+ throw new Error("unreachable");
16974
+ }
16975
+ emitError(
16976
+ {
16977
+ code: "agent_ambiguous",
16978
+ message: `"${ref}" matches ${matches.length} agents: ${matches.map((a) => a.slug ?? a.id.slice(0, 8)).join(", ")}.`,
16979
+ hint: "Use the full id (from `bamboo-agents agents list`)."
16980
+ },
16981
+ opts,
16982
+ 1
16983
+ );
16984
+ throw new Error("unreachable");
16985
+ }
16986
+ function printList(data, opts) {
16987
+ if (data.agents.length === 0) {
16988
+ human(" No agents yet. Create one with `bamboo-agents agents provision <name> --brand <id>`.", opts);
16989
+ return;
16990
+ }
16991
+ const nameW = Math.max(4, ...data.agents.map((a) => a.name.length));
16992
+ const slugW = Math.max(4, ...data.agents.map((a) => (a.slug ?? "\u2014").length));
16993
+ for (const a of data.agents) {
16994
+ const kind = a.is_auto_installed ? "[pre-installed]" : "";
16995
+ const state = a.state ?? "\u2014";
16996
+ human(
16997
+ ` ${padRight4(a.name, nameW)} ${padRight4(a.slug ?? "\u2014", slugW)} ${padRight4(state, 9)} ${a.id} ${kind}`,
16998
+ opts
16999
+ );
17000
+ }
17001
+ const cap = data.tier_cap;
17002
+ const capStr = cap.limit < 0 ? `${cap.current} agents` : `${cap.current}/${cap.limit} agents`;
17003
+ human(` ${capStr}${cap.tier_name ? ` \xB7 ${cap.tier_name}` : ""}.`, opts);
17004
+ }
17005
+ async function runAgentsList(options) {
17006
+ const opts = options;
17007
+ const session = await requireSession7(opts);
17008
+ let data;
17009
+ try {
17010
+ data = await listCliAgents(session);
17011
+ } catch (err) {
17012
+ emitError(
17013
+ { code: "agents_list_failed", message: `couldn't list agents: ${err.message}` },
17014
+ opts,
17015
+ 1
17016
+ );
17017
+ return;
17018
+ }
17019
+ emitSuccess(data, opts, (d) => printList(d, opts));
17020
+ }
17021
+ function printDetail(agent, opts) {
17022
+ human(` ${agent.name} (${agent.id})`, opts);
17023
+ human(` state: ${agent.state} (status=${agent.status}${agent.paused_at ? ", paused" : ""})`, opts);
17024
+ human(` slug: ${agent.slug ?? "\u2014"}`, opts);
17025
+ human(` runtime: ${agent.execution_runtime ?? "\u2014"}`, opts);
17026
+ human(` template: ${agent.template_key ?? "\u2014"}`, opts);
17027
+ human(` folder: ${agent.folder_path ?? "\u2014"}`, opts);
17028
+ const brands = agent.brands.map((b) => b.name).join(", ") || "\u2014";
17029
+ human(` brands: ${brands}`, opts);
17030
+ if (agent.is_auto_installed) human(" (pre-installed)", opts);
17031
+ }
17032
+ async function runAgentsGet(agentRef, options) {
17033
+ const opts = options;
17034
+ const session = await requireSession7(opts);
17035
+ const row = await resolveAgentRef(session, agentRef, opts);
17036
+ let agent;
17037
+ try {
17038
+ agent = (await getCliAgent(session, row.id)).agent;
17039
+ } catch (err) {
17040
+ emitError(
17041
+ { code: "agent_get_failed", message: `couldn't load agent: ${err.message}` },
17042
+ opts,
17043
+ 1
17044
+ );
17045
+ return;
17046
+ }
17047
+ emitSuccess(agent, opts, (a) => printDetail(a, opts));
17048
+ }
17049
+ async function resolveBrandId(session, explicit, opts) {
17050
+ if (explicit) return explicit;
17051
+ let brands;
17052
+ try {
17053
+ brands = (await listCliBrands(session)).brands;
17054
+ } catch (err) {
17055
+ emitError(
17056
+ { code: "brands_list_failed", message: `couldn't list brands: ${err.message}` },
17057
+ opts,
17058
+ 1
17059
+ );
17060
+ throw new Error("unreachable");
17061
+ }
17062
+ if (brands.length === 1) return brands[0].id;
17063
+ emitError(
17064
+ {
17065
+ code: "brand_required",
17066
+ message: brands.length === 0 ? "no brands found for your org \u2014 create a brand first." : `multiple brands \u2014 pass --brand <id>. Options: ${brands.map((b) => `${b.name} (${b.id})`).join(", ")}.`,
17067
+ hint: "Specify the brand the agent belongs to with --brand <id>."
17068
+ },
17069
+ opts,
17070
+ 1
17071
+ );
17072
+ throw new Error("unreachable");
17073
+ }
17074
+ async function runAgentsProvision(name, options) {
17075
+ const opts = options;
17076
+ const session = await requireSession7(opts);
17077
+ const brandId = await resolveBrandId(session, options.brand, opts);
17078
+ let result;
17079
+ try {
17080
+ result = await createAgentFromCli(session, {
17081
+ brand_id: brandId,
17082
+ name,
17083
+ ...options.slug ? { slug: options.slug } : {}
17084
+ });
17085
+ } catch (err) {
17086
+ emitError(
17087
+ { code: "agent_provision_failed", message: `couldn't provision agent: ${err.message}` },
17088
+ opts,
17089
+ 1
17090
+ );
17091
+ return;
17092
+ }
17093
+ emitSuccess(result, opts, (r) => {
17094
+ const verb = r.reused ? "Already exists" : "Provisioned";
17095
+ human(` ${verb}: ${name} (${r.agent_id})`, opts);
17096
+ human(` folder: ${r.folder_path} \xB7 ${r.write_status}`, opts);
17097
+ if (!r.reused) human(" Agent is active.", opts);
17098
+ });
17099
+ }
17100
+ async function runAgentsPause(agentRef, options) {
17101
+ const opts = options;
17102
+ const session = await requireSession7(opts);
17103
+ const row = await resolveAgentRef(session, agentRef, opts);
17104
+ try {
17105
+ const res = await pauseCliAgent(session, row.id);
17106
+ emitSuccess(res, opts, () => human(` Paused ${row.name} (${row.id}).`, opts));
17107
+ } catch (err) {
17108
+ emitError(
17109
+ { code: "agent_pause_failed", message: `couldn't pause agent: ${err.message}` },
17110
+ opts,
17111
+ 1
17112
+ );
17113
+ }
17114
+ }
17115
+ async function runAgentsActivate(agentRef, options) {
17116
+ const opts = options;
17117
+ const session = await requireSession7(opts);
17118
+ const row = await resolveAgentRef(session, agentRef, opts);
17119
+ let state = row.state;
17120
+ let status = row.status;
17121
+ if (state === void 0 || status === void 0) {
17122
+ try {
17123
+ const d = (await getCliAgent(session, row.id)).agent;
17124
+ state = d.state;
17125
+ status = d.status;
17126
+ } catch (err) {
17127
+ emitError(
17128
+ { code: "agent_get_failed", message: `couldn't read agent state: ${err.message}` },
17129
+ opts,
17130
+ 1
17131
+ );
17132
+ return;
17133
+ }
17134
+ }
17135
+ try {
17136
+ if (state === "paused") {
17137
+ const res = await unpauseCliAgent(session, row.id);
17138
+ emitSuccess(
17139
+ { agent_id: row.id, action: "unpaused", agent: res.agent },
17140
+ opts,
17141
+ () => human(` Activated ${row.name} (${row.id}) \u2014 unpaused.`, opts)
17142
+ );
17143
+ return;
17144
+ }
17145
+ if (status !== "ready") {
17146
+ const res = await publishCliAgent(session, row.id);
17147
+ emitSuccess(
17148
+ { agent_id: res.agent_id, action: "published" },
17149
+ opts,
17150
+ () => human(` Activated ${row.name} (${row.id}) \u2014 published.`, opts)
17151
+ );
17152
+ return;
17153
+ }
17154
+ emitSuccess(
17155
+ { agent_id: row.id, action: "noop" },
17156
+ opts,
17157
+ () => human(` ${row.name} (${row.id}) is already active.`, opts)
17158
+ );
17159
+ } catch (err) {
17160
+ emitError(
17161
+ { code: "agent_activate_failed", message: `couldn't activate agent: ${err.message}` },
17162
+ opts,
17163
+ 1
17164
+ );
17165
+ }
17166
+ }
17167
+ var init_agents2 = __esm({
17168
+ "src/commands/agents.ts"() {
17169
+ "use strict";
17170
+ init_credentials();
17171
+ init_api();
17172
+ init_output();
17173
+ }
17174
+ });
17175
+
16799
17176
  // node_modules/commander/esm.mjs
16800
17177
  var import_index = __toESM(require_commander(), 1);
16801
17178
  var {
@@ -16906,12 +17283,13 @@ function zodToJsonSchema(schema) {
16906
17283
  async function loadOutputSchemas() {
16907
17284
  const map = /* @__PURE__ */ new Map();
16908
17285
  try {
16909
- const [history, changes, knowledgeSlots, knowledgeSave, onboarding2] = await Promise.all([
17286
+ const [history, changes, knowledgeSlots, knowledgeSave, onboarding2, agents2] = await Promise.all([
16910
17287
  Promise.resolve().then(() => (init_history(), history_exports)).catch(() => null),
16911
17288
  Promise.resolve().then(() => (init_changes(), changes_exports)).catch(() => null),
16912
17289
  Promise.resolve().then(() => (init_knowledge_slots(), knowledge_slots_exports)).catch(() => null),
16913
17290
  Promise.resolve().then(() => (init_knowledge_save(), knowledge_save_exports)).catch(() => null),
16914
- Promise.resolve().then(() => (init_onboarding_status(), onboarding_status_exports)).catch(() => null)
17291
+ Promise.resolve().then(() => (init_onboarding_status(), onboarding_status_exports)).catch(() => null),
17292
+ Promise.resolve().then(() => (init_agents(), agents_exports)).catch(() => null)
16915
17293
  ]);
16916
17294
  if (history?.HistoryResponseSchema) {
16917
17295
  const s = zodToJsonSchema(history.HistoryResponseSchema);
@@ -16933,6 +17311,22 @@ async function loadOutputSchemas() {
16933
17311
  const s = zodToJsonSchema(onboarding2.OnboardingStatusResponseSchema);
16934
17312
  if (s) map.set("onboarding status", s);
16935
17313
  }
17314
+ if (agents2?.CliAgentsListResponseSchema) {
17315
+ const s = zodToJsonSchema(agents2.CliAgentsListResponseSchema);
17316
+ if (s) map.set("agents list", s);
17317
+ }
17318
+ if (agents2?.CliAgentDetailSchema) {
17319
+ const s = zodToJsonSchema(agents2.CliAgentDetailSchema);
17320
+ if (s) map.set("agents get", s);
17321
+ }
17322
+ if (agents2?.CliCreateAgentResponseSchema) {
17323
+ const s = zodToJsonSchema(agents2.CliCreateAgentResponseSchema);
17324
+ if (s) map.set("agents provision", s);
17325
+ }
17326
+ if (agents2?.CliAgentPauseResponseSchema) {
17327
+ const s = zodToJsonSchema(agents2.CliAgentPauseResponseSchema);
17328
+ if (s) map.set("agents pause", s);
17329
+ }
16936
17330
  } catch {
16937
17331
  }
16938
17332
  return map;
@@ -17098,6 +17492,29 @@ onboarding.command("status").description("Composite onboarding gate (activation
17098
17492
  const { runOnboardingStatus: runOnboardingStatus2 } = await Promise.resolve().then(() => (init_onboarding(), onboarding_exports));
17099
17493
  await runOnboardingStatus2(options);
17100
17494
  });
17495
+ var agents = program2.command("agents").description("Manage agents \u2014 list, get, provision, activate, pause");
17496
+ agents.command("list").description("List agents with their lifecycle state").option("--json", "Emit a JSON envelope for agent consumption").option("--fields <list>", "Project only these dotted field paths from data (comma-separated)").option("--quiet", "Suppress human chatter (data/errors only)").option("--no-sync", "Skip the auto-sync git pull on this command").action(async (options) => {
17497
+ const { runAgentsList: runAgentsList2 } = await Promise.resolve().then(() => (init_agents2(), agents_exports2));
17498
+ await runAgentsList2(options);
17499
+ });
17500
+ agents.command("get <agent>").description("Show one agent's full config (accepts id, slug, or name)").option("--json", "Emit a JSON envelope for agent consumption").option("--fields <list>", "Project only these dotted field paths from data (comma-separated)").option("--quiet", "Suppress human chatter (data/errors only)").option("--no-sync", "Skip the auto-sync git pull on this command").action(async (agent, options) => {
17501
+ const { runAgentsGet: runAgentsGet2 } = await Promise.resolve().then(() => (init_agents2(), agents_exports2));
17502
+ await runAgentsGet2(agent, options);
17503
+ });
17504
+ agents.command("provision <name>").description("Create a new agent (immediately active)").option("--brand <id>", "Brand the agent belongs to (auto-picked if you have exactly one)").option("--slug <slug>", "Optional kebab-case slug (derived from name otherwise)").option("--json", "Emit a JSON envelope for agent consumption").option("--fields <list>", "Project only these dotted field paths from data (comma-separated)").option("--quiet", "Suppress human chatter (data/errors only)").option("--no-sync", "Skip the auto-sync git pull on this command").action(
17505
+ async (name, options) => {
17506
+ const { runAgentsProvision: runAgentsProvision2 } = await Promise.resolve().then(() => (init_agents2(), agents_exports2));
17507
+ await runAgentsProvision2(name, options);
17508
+ }
17509
+ );
17510
+ agents.command("activate <agent>").description("Activate an agent \u2014 unpause it (or publish a draft). Admin-only.").option("--json", "Emit a JSON envelope for agent consumption").option("--fields <list>", "Project only these dotted field paths from data (comma-separated)").option("--quiet", "Suppress human chatter (data/errors only)").option("--no-sync", "Skip the auto-sync git pull on this command").action(async (agent, options) => {
17511
+ const { runAgentsActivate: runAgentsActivate2 } = await Promise.resolve().then(() => (init_agents2(), agents_exports2));
17512
+ await runAgentsActivate2(agent, options);
17513
+ });
17514
+ agents.command("pause <agent>").description("Pause an agent \u2014 stops its scheduled runs. Admin-only.").option("--json", "Emit a JSON envelope for agent consumption").option("--fields <list>", "Project only these dotted field paths from data (comma-separated)").option("--quiet", "Suppress human chatter (data/errors only)").option("--no-sync", "Skip the auto-sync git pull on this command").action(async (agent, options) => {
17515
+ const { runAgentsPause: runAgentsPause2 } = await Promise.resolve().then(() => (init_agents2(), agents_exports2));
17516
+ await runAgentsPause2(agent, options);
17517
+ });
17101
17518
  (async () => {
17102
17519
  const rawArgs = process.argv.slice(2);
17103
17520
  const { operands } = program2.parseOptions(rawArgs);