bamboo-agents 0.1.5-dev.63.0d55db2 → 0.1.5-dev.65.b4a6bfe

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.63.0d55db2
1
+ 0.1.5-dev.65.b4a6bfe
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.63.0d55db2";
3040
+ VERSION = "0.1.5-dev.65.b4a6bfe";
3041
3041
  }
3042
3042
  });
3043
3043
 
@@ -12646,6 +12646,122 @@ var init_install_token = __esm({
12646
12646
  }
12647
12647
  });
12648
12648
 
12649
+ // ../../src/lib/api-contracts/episodes/index.ts
12650
+ var KnowledgeCiteSchema, EpisodeCiteSchema, NoPriorHistoryCiteSchema, CiteSchema, CitesArraySchema, InsightBodySchema, RecommendationBodySchema, ActionBodySchema, OutcomeBodySchema, FeedbackBodySchema, EpisodeBaseFields, EpisodeInsertSchema, EpisodeRowSchema;
12651
+ var init_episodes = __esm({
12652
+ "../../src/lib/api-contracts/episodes/index.ts"() {
12653
+ init_zod();
12654
+ KnowledgeCiteSchema = external_exports.object({
12655
+ /** Repo-relative path, e.g. `brands/acme/knowledge/competitors.md`. */
12656
+ path: external_exports.string().min(1).max(512),
12657
+ /** Verbatim excerpt from the file (validated at write time against blob). */
12658
+ excerpt: external_exports.string().min(1).max(2e3),
12659
+ /** Git SHA of the commit where this excerpt was read. */
12660
+ sha: external_exports.string().min(7).max(64)
12661
+ });
12662
+ EpisodeCiteSchema = external_exports.object({
12663
+ /** Back-reference to a prior episode (e.g. outcome cites recommendation). */
12664
+ episode_id: external_exports.string().uuid()
12665
+ });
12666
+ NoPriorHistoryCiteSchema = external_exports.object({
12667
+ kind: external_exports.literal("no-prior-history")
12668
+ });
12669
+ CiteSchema = external_exports.union([KnowledgeCiteSchema, EpisodeCiteSchema, NoPriorHistoryCiteSchema]);
12670
+ CitesArraySchema = external_exports.array(CiteSchema);
12671
+ InsightBodySchema = external_exports.object({
12672
+ /** Short summary of the insight. */
12673
+ summary: external_exports.string().min(1).max(4e3),
12674
+ findings: external_exports.array(external_exports.record(external_exports.unknown())).optional()
12675
+ });
12676
+ RecommendationBodySchema = external_exports.object({
12677
+ /** Short imperative title, e.g. "Increase Budget on Brand Campaigns". */
12678
+ title: external_exports.string().min(1).max(500),
12679
+ /** Explanation grounded in evidence. */
12680
+ rationale: external_exports.string().min(1).max(8e3),
12681
+ action_items: external_exports.array(external_exports.string().max(1e3)).optional()
12682
+ });
12683
+ ActionBodySchema = external_exports.object({
12684
+ /** Human-readable description of the action taken. */
12685
+ description: external_exports.string().min(1).max(4e3),
12686
+ tool_calls: external_exports.array(external_exports.record(external_exports.unknown())).optional()
12687
+ });
12688
+ OutcomeBodySchema = external_exports.object({
12689
+ /** What happened after the action was taken. */
12690
+ description: external_exports.string().min(1).max(4e3),
12691
+ metrics_before: external_exports.record(external_exports.unknown()).optional(),
12692
+ metrics_after: external_exports.record(external_exports.unknown()).optional()
12693
+ });
12694
+ FeedbackBodySchema = external_exports.object({
12695
+ /** true = approved, false = declined. */
12696
+ approved: external_exports.boolean(),
12697
+ /** Free-form reason, especially on decline. */
12698
+ reason: external_exports.string().max(2e3).optional(),
12699
+ /** Links this feedback episode to the conversation where the user responded. */
12700
+ conversation_id: external_exports.string().uuid().optional()
12701
+ });
12702
+ EpisodeBaseFields = external_exports.object({
12703
+ org_id: external_exports.string().uuid(),
12704
+ brand_id: external_exports.string().uuid(),
12705
+ agent_id: external_exports.string().uuid().optional(),
12706
+ conversation_id: external_exports.string().uuid().optional(),
12707
+ trace_id: external_exports.string().max(256).optional(),
12708
+ parent_episode_id: external_exports.string().uuid().optional(),
12709
+ cites: CitesArraySchema.optional().default([]),
12710
+ idempotency_key: external_exports.string().min(1).max(256).optional()
12711
+ });
12712
+ EpisodeInsertSchema = external_exports.discriminatedUnion("type", [
12713
+ EpisodeBaseFields.extend({ type: external_exports.literal("insight"), body: InsightBodySchema }),
12714
+ EpisodeBaseFields.extend({ type: external_exports.literal("recommendation"), body: RecommendationBodySchema }),
12715
+ EpisodeBaseFields.extend({ type: external_exports.literal("action"), body: ActionBodySchema }),
12716
+ EpisodeBaseFields.extend({ type: external_exports.literal("outcome"), body: OutcomeBodySchema }),
12717
+ EpisodeBaseFields.extend({ type: external_exports.literal("feedback"), body: FeedbackBodySchema })
12718
+ ]);
12719
+ EpisodeRowSchema = EpisodeBaseFields.extend({
12720
+ id: external_exports.string().uuid(),
12721
+ type: external_exports.enum(["insight", "recommendation", "action", "outcome", "feedback"]),
12722
+ body: external_exports.record(external_exports.unknown()),
12723
+ cites: CitesArraySchema,
12724
+ created_at: external_exports.string().datetime()
12725
+ });
12726
+ }
12727
+ });
12728
+
12729
+ // ../../src/lib/api-contracts/cli/episodes.ts
12730
+ var CliOutcomeEpisodeRequestSchema, CliOutcomeEpisodeResponseSchema, CliRecEpisodeRequestSchema, CliRecEpisodeResponseSchema;
12731
+ var init_episodes2 = __esm({
12732
+ "../../src/lib/api-contracts/cli/episodes.ts"() {
12733
+ init_zod();
12734
+ init_episodes();
12735
+ CliOutcomeEpisodeRequestSchema = external_exports.object({
12736
+ brand_id: external_exports.string().uuid(),
12737
+ /** The recommendation episode this outcome follows. */
12738
+ parent_episode_id: external_exports.string().uuid(),
12739
+ description: external_exports.string().min(1).max(4e3),
12740
+ metrics_before: external_exports.record(external_exports.unknown()).optional(),
12741
+ metrics_after: external_exports.record(external_exports.unknown()).optional()
12742
+ });
12743
+ CliOutcomeEpisodeResponseSchema = external_exports.object({
12744
+ id: external_exports.string().uuid(),
12745
+ brand_id: external_exports.string().uuid(),
12746
+ parent_episode_id: external_exports.string().uuid(),
12747
+ created_at: external_exports.string()
12748
+ });
12749
+ CliRecEpisodeRequestSchema = external_exports.object({
12750
+ brand_id: external_exports.string().uuid(),
12751
+ title: external_exports.string().min(1).max(500),
12752
+ rationale: external_exports.string().min(1).max(8e3),
12753
+ action_items: external_exports.array(external_exports.string().max(1e3)).optional(),
12754
+ cites: CitesArraySchema,
12755
+ conversation_id: external_exports.string().uuid().optional(),
12756
+ idempotency_key: external_exports.string().min(1).max(256).optional()
12757
+ });
12758
+ CliRecEpisodeResponseSchema = external_exports.object({
12759
+ episode_id: external_exports.string().uuid(),
12760
+ is_no_prior_history: external_exports.boolean()
12761
+ });
12762
+ }
12763
+ });
12764
+
12649
12765
  // src/lib/api.ts
12650
12766
  import { platform as platform2 } from "node:os";
12651
12767
  function defaultApiBase(version) {
@@ -13124,6 +13240,32 @@ async function mintCliInstallToken(bambooSession) {
13124
13240
  const json = await res.json();
13125
13241
  return CliInstallTokenSuccessSchema.parse(json);
13126
13242
  }
13243
+ async function postOutcomeEpisode(bambooSession, body) {
13244
+ const res = await cliApiFetch(`${apiBase()}/api/v1/cli/episodes`, {
13245
+ method: "POST",
13246
+ headers: {
13247
+ Authorization: `Bearer ${bambooSession}`,
13248
+ "Content-Type": "application/json"
13249
+ },
13250
+ body: JSON.stringify(body)
13251
+ });
13252
+ if (!res.ok) throw await parseError(res);
13253
+ const json = await res.json();
13254
+ return CliOutcomeEpisodeResponseSchema.parse(json);
13255
+ }
13256
+ async function postRecEpisode(bambooSession, body) {
13257
+ const res = await cliApiFetch(`${apiBase()}/api/v1/cli/episodes/recommendation`, {
13258
+ method: "POST",
13259
+ headers: {
13260
+ Authorization: `Bearer ${bambooSession}`,
13261
+ "Content-Type": "application/json"
13262
+ },
13263
+ body: JSON.stringify(body)
13264
+ });
13265
+ if (!res.ok) throw await parseError(res);
13266
+ const json = await res.json();
13267
+ return CliRecEpisodeResponseSchema.parse(json);
13268
+ }
13127
13269
  var PROD_DEFAULT_BASE, DEV_DEFAULT_BASE, REQUEST_TIMEOUT_MS, ApiError, OAuthRelinkStartResponseSchema, ProvisionWorkspaceResponseSchema, FirstAutoInstalledAgentResponseSchema, SkillCatalogEntrySchema, SkillCatalogResponseSchema, SkillSubscriptionsResponseSchema, ScaffoldSkillResponseSchema;
13128
13270
  var init_api = __esm({
13129
13271
  "src/lib/api.ts"() {
@@ -13147,6 +13289,7 @@ var init_api = __esm({
13147
13289
  init_onboarding_status();
13148
13290
  init_context_health();
13149
13291
  init_install_token();
13292
+ init_episodes2();
13150
13293
  init_version();
13151
13294
  PROD_DEFAULT_BASE = "https://withbamboo.com";
13152
13295
  DEV_DEFAULT_BASE = "https://dev.withbamboo.com";
@@ -18641,6 +18784,150 @@ var init_agents2 = __esm({
18641
18784
  }
18642
18785
  });
18643
18786
 
18787
+ // src/commands/episode.ts
18788
+ var episode_exports = {};
18789
+ __export(episode_exports, {
18790
+ runEpisodeLogOutcome: () => runEpisodeLogOutcome,
18791
+ runEpisodeLogRec: () => runEpisodeLogRec
18792
+ });
18793
+ async function requireSession10() {
18794
+ const creds = await readCredentials();
18795
+ if (!creds) {
18796
+ console.error("bamboo-agents: not signed in. Run `bamboo-agents login` first.");
18797
+ process.exit(1);
18798
+ }
18799
+ return creds.bamboo_session;
18800
+ }
18801
+ async function runEpisodeLogOutcome(options) {
18802
+ if (!options.rec || !options.brand || !options.description) {
18803
+ console.error(
18804
+ "bamboo-agents: `episode log-outcome` requires --rec, --brand, and --description."
18805
+ );
18806
+ process.exit(2);
18807
+ }
18808
+ let metricsBefore;
18809
+ let metricsAfter;
18810
+ if (options.metricsBefore) {
18811
+ try {
18812
+ metricsBefore = JSON.parse(options.metricsBefore);
18813
+ } catch {
18814
+ console.error(`bamboo-agents: --metrics-before must be valid JSON, e.g. '{"cpa": 35}'.`);
18815
+ process.exit(2);
18816
+ }
18817
+ }
18818
+ if (options.metricsAfter) {
18819
+ try {
18820
+ metricsAfter = JSON.parse(options.metricsAfter);
18821
+ } catch {
18822
+ console.error(`bamboo-agents: --metrics-after must be valid JSON, e.g. '{"cpa": 31}'.`);
18823
+ process.exit(2);
18824
+ }
18825
+ }
18826
+ const session = await requireSession10();
18827
+ let result;
18828
+ try {
18829
+ result = await postOutcomeEpisode(session, {
18830
+ brand_id: options.brand,
18831
+ parent_episode_id: options.rec,
18832
+ description: options.description,
18833
+ ...metricsBefore ? { metrics_before: metricsBefore } : {},
18834
+ ...metricsAfter ? { metrics_after: metricsAfter } : {}
18835
+ });
18836
+ } catch (err) {
18837
+ console.error(`bamboo-agents: outcome entry failed: ${err.message}`);
18838
+ process.exit(1);
18839
+ }
18840
+ if (options.json) {
18841
+ console.log(JSON.stringify(result));
18842
+ return;
18843
+ }
18844
+ if (!options.quiet) {
18845
+ console.log("");
18846
+ console.log(` \u2713 Outcome logged \u2014 episode ${result.id}`);
18847
+ console.log(` Chained to rec: ${result.parent_episode_id}`);
18848
+ console.log(` Brand: ${result.brand_id}`);
18849
+ console.log(` Created: ${result.created_at}`);
18850
+ console.log("");
18851
+ }
18852
+ }
18853
+ async function runEpisodeLogRec(options) {
18854
+ if (!options.brand || !options.title || !options.rationale) {
18855
+ console.error(
18856
+ "bamboo-agents: `episode log-rec` requires --brand, --title, and --rationale."
18857
+ );
18858
+ process.exit(2);
18859
+ }
18860
+ if (!options.cites && !options.noPriorHistory) {
18861
+ console.error(
18862
+ "bamboo-agents: `episode log-rec` requires either --cites '<json>' or --no-prior-history."
18863
+ );
18864
+ process.exit(2);
18865
+ }
18866
+ let cites = [];
18867
+ if (options.noPriorHistory) {
18868
+ cites = [{ kind: "no-prior-history" }];
18869
+ } else if (options.cites) {
18870
+ try {
18871
+ cites = JSON.parse(options.cites);
18872
+ if (!Array.isArray(cites)) throw new Error("cites must be a JSON array");
18873
+ } catch (e) {
18874
+ console.error(
18875
+ `bamboo-agents: --cites must be a valid JSON array, e.g. '[{"path":"...","excerpt":"...","sha":"..."}]': ${e.message}`
18876
+ );
18877
+ process.exit(2);
18878
+ }
18879
+ }
18880
+ let actionItems;
18881
+ if (options.actionItems) {
18882
+ try {
18883
+ actionItems = JSON.parse(options.actionItems);
18884
+ if (!Array.isArray(actionItems)) throw new Error("action-items must be a JSON array");
18885
+ } catch (e) {
18886
+ console.error(
18887
+ `bamboo-agents: --action-items must be a valid JSON array of strings: ${e.message}`
18888
+ );
18889
+ process.exit(2);
18890
+ }
18891
+ }
18892
+ const session = await requireSession10();
18893
+ let result;
18894
+ try {
18895
+ result = await postRecEpisode(session, {
18896
+ brand_id: options.brand,
18897
+ title: options.title,
18898
+ rationale: options.rationale,
18899
+ ...actionItems ? { action_items: actionItems } : {},
18900
+ cites,
18901
+ ...options.conversationId ? { conversation_id: options.conversationId } : {},
18902
+ ...options.idempotencyKey ? { idempotency_key: options.idempotencyKey } : {}
18903
+ });
18904
+ } catch (err) {
18905
+ if (options.json) {
18906
+ console.log(JSON.stringify({ ok: false, error: err.message }));
18907
+ } else {
18908
+ console.error(`bamboo-agents: recommendation entry failed: ${err.message}`);
18909
+ }
18910
+ process.exit(1);
18911
+ }
18912
+ if (options.json) {
18913
+ console.log(JSON.stringify({ ok: true, ...result }));
18914
+ return;
18915
+ }
18916
+ if (!options.quiet) {
18917
+ const kind = result.is_no_prior_history ? " (no prior history \u2014 cold start)" : "";
18918
+ console.log("");
18919
+ console.log(` \u2713 Recommendation logged${kind} \u2014 episode ${result.episode_id}`);
18920
+ console.log("");
18921
+ }
18922
+ }
18923
+ var init_episode = __esm({
18924
+ "src/commands/episode.ts"() {
18925
+ "use strict";
18926
+ init_credentials();
18927
+ init_api();
18928
+ }
18929
+ });
18930
+
18644
18931
  // node_modules/commander/esm.mjs
18645
18932
  var import_index = __toESM(require_commander(), 1);
18646
18933
  var {
@@ -19048,6 +19335,25 @@ agents.command("pause <agent>").description("Pause an agent \u2014 stops its sch
19048
19335
  const { runAgentsPause: runAgentsPause2 } = await Promise.resolve().then(() => (init_agents2(), agents_exports2));
19049
19336
  await runAgentsPause2(agent, options);
19050
19337
  });
19338
+ var episode = program2.command("episode").description("Pilot decision-ledger \u2014 log outcomes against recommendations");
19339
+ episode.command("log-outcome").description(
19340
+ "Log an outcome episode chained to a recommendation (closes the accept\u2192result loop)"
19341
+ ).requiredOption("--rec <uuid>", "Recommendation episode id to chain this outcome to").requiredOption("--brand <id>", "Brand id the recommendation belongs to").requiredOption("--description <text>", "What happened after the recommendation was applied").option("--metrics-before <json>", `JSON object of metrics before the change, e.g. '{"cpa":35}'`).option("--metrics-after <json>", `JSON object of metrics after the change, e.g. '{"cpa":31}'`).option("--json", "Emit a JSON envelope for agent consumption").option("--quiet", "Suppress human chatter (data/errors only)").option("--no-sync", "Skip the auto-sync git pull on this command").action(async (options) => {
19342
+ const { runEpisodeLogOutcome: runEpisodeLogOutcome2 } = await Promise.resolve().then(() => (init_episode(), episode_exports));
19343
+ await runEpisodeLogOutcome2(options);
19344
+ });
19345
+ episode.command("log-rec").description(
19346
+ "Log a cited recommendation episode (sandbox-Boo pilot runtime, BAM-2944)"
19347
+ ).requiredOption("--brand <id>", "Brand id the recommendation belongs to").requiredOption("--title <text>", "Short imperative title for the recommendation").requiredOption("--rationale <text>", "Explanation grounded in evidence").option(
19348
+ "--cites <json>",
19349
+ "JSON array of citations \u2014 [{path, excerpt, sha}] or [{episode_id}]. Omit when --no-prior-history is set."
19350
+ ).option(
19351
+ "--no-prior-history",
19352
+ "Brand has no prior knowledge to cite (cold-start). Mutually exclusive with --cites."
19353
+ ).option("--action-items <json>", "Optional JSON array of action item strings").option("--conversation-id <uuid>", "Conversation UUID to link this episode to a Boo session").option("--idempotency-key <key>", "Client key \u2014 same key + same brand returns existing episode").option("--json", "Emit a JSON envelope for agent consumption").option("--quiet", "Suppress human chatter (data/errors only)").action(async (options) => {
19354
+ const { runEpisodeLogRec: runEpisodeLogRec2 } = await Promise.resolve().then(() => (init_episode(), episode_exports));
19355
+ await runEpisodeLogRec2(options);
19356
+ });
19051
19357
  (async () => {
19052
19358
  const rawArgs = process.argv.slice(2);
19053
19359
  const { operands } = program2.parseOptions(rawArgs);