bamboo-agents 0.1.5-dev.62.c11b819 → 0.1.5-dev.64.96d1b4d

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.62.c11b819
1
+ 0.1.5-dev.64.96d1b4d
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.62.c11b819";
3040
+ VERSION = "0.1.5-dev.64.96d1b4d";
3041
3041
  }
3042
3042
  });
3043
3043
 
@@ -12502,6 +12502,45 @@ var init_inbox_revise = __esm({
12502
12502
  }
12503
12503
  });
12504
12504
 
12505
+ // ../../src/lib/api-contracts/cli/inbox-apply-revision.ts
12506
+ var InboxApplyRevisionRequestSchema, InboxApplyRevisionResponseSchema;
12507
+ var init_inbox_apply_revision = __esm({
12508
+ "../../src/lib/api-contracts/cli/inbox-apply-revision.ts"() {
12509
+ init_zod();
12510
+ init_save();
12511
+ InboxApplyRevisionRequestSchema = external_exports.object({
12512
+ /** PR number in the org's workspace repo. */
12513
+ pr_number: external_exports.number().int().positive(),
12514
+ /** Repo-relative path of the single file being revised. */
12515
+ file: external_exports.string().min(1).max(512),
12516
+ /** The complete new file content — the full file, not a diff. */
12517
+ new_content: external_exports.string().min(1).max(1e6),
12518
+ /** Short commit message, e.g. "revision: tighten tone in intro". */
12519
+ commit_message: external_exports.string().min(1).max(200),
12520
+ /**
12521
+ * Blob SHA from the `inbox revise` response — GitHub's optimistic
12522
+ * concurrency check. A stale SHA → 409 `pr_branch_moved`.
12523
+ */
12524
+ file_sha: external_exports.string().min(1).max(64),
12525
+ /**
12526
+ * The head branch from the `inbox revise` response. Validated against
12527
+ * the PR's actual head ref server-side (409 `branch_mismatch` on drift);
12528
+ * the commit always targets the PR's own head ref.
12529
+ */
12530
+ branch: external_exports.string().min(1).max(255).optional()
12531
+ }).refine((r) => isSafeRepoPath(r.file), {
12532
+ message: "unsafe file path: no '..' traversal, absolute paths, backslashes, or control chars",
12533
+ path: ["file"]
12534
+ });
12535
+ InboxApplyRevisionResponseSchema = external_exports.object({
12536
+ committed: external_exports.literal(true),
12537
+ /** The PR head branch the revision landed on. */
12538
+ branch: external_exports.string(),
12539
+ pr_number: external_exports.number()
12540
+ });
12541
+ }
12542
+ });
12543
+
12505
12544
  // ../../src/lib/api-contracts/cli/context-health.ts
12506
12545
  var ScopeKindSchema, ScopeSchema, CriterionMetricsSchema, StatusSchema, CriterionContributionSchema, CriterionResultSchema, BucketScoresSchema, ResolvedScopeSchema, GapsSchema, HealthyResponseSchema, UnavailableResponseSchema, ContextHealthResponseSchema;
12507
12546
  var init_context_health = __esm({
@@ -12607,6 +12646,28 @@ var init_install_token = __esm({
12607
12646
  }
12608
12647
  });
12609
12648
 
12649
+ // ../../src/lib/api-contracts/cli/episodes.ts
12650
+ var CliOutcomeEpisodeRequestSchema, CliOutcomeEpisodeResponseSchema;
12651
+ var init_episodes = __esm({
12652
+ "../../src/lib/api-contracts/cli/episodes.ts"() {
12653
+ init_zod();
12654
+ CliOutcomeEpisodeRequestSchema = external_exports.object({
12655
+ brand_id: external_exports.string().uuid(),
12656
+ /** The recommendation episode this outcome follows. */
12657
+ parent_episode_id: external_exports.string().uuid(),
12658
+ description: external_exports.string().min(1).max(4e3),
12659
+ metrics_before: external_exports.record(external_exports.unknown()).optional(),
12660
+ metrics_after: external_exports.record(external_exports.unknown()).optional()
12661
+ });
12662
+ CliOutcomeEpisodeResponseSchema = external_exports.object({
12663
+ id: external_exports.string().uuid(),
12664
+ brand_id: external_exports.string().uuid(),
12665
+ parent_episode_id: external_exports.string().uuid(),
12666
+ created_at: external_exports.string()
12667
+ });
12668
+ }
12669
+ });
12670
+
12610
12671
  // src/lib/api.ts
12611
12672
  import { platform as platform2 } from "node:os";
12612
12673
  function defaultApiBase(version) {
@@ -12716,6 +12777,19 @@ async function requestInboxRevision(bambooSession, body) {
12716
12777
  const json = await res.json();
12717
12778
  return InboxReviseResponseSchema.parse(json);
12718
12779
  }
12780
+ async function requestInboxApplyRevision(bambooSession, body) {
12781
+ const res = await cliApiFetch(`${apiBase()}/api/v1/cli/inbox/apply-revision`, {
12782
+ method: "POST",
12783
+ headers: {
12784
+ Authorization: `Bearer ${bambooSession}`,
12785
+ "Content-Type": "application/json"
12786
+ },
12787
+ body: JSON.stringify(body)
12788
+ });
12789
+ if (!res.ok) throw await parseError(res);
12790
+ const json = await res.json();
12791
+ return InboxApplyRevisionResponseSchema.parse(json);
12792
+ }
12719
12793
  async function saveWorkspace(bambooSession, body) {
12720
12794
  const res = await cliApiFetch(`${apiBase()}/api/v1/cli/save`, {
12721
12795
  method: "POST",
@@ -13072,6 +13146,19 @@ async function mintCliInstallToken(bambooSession) {
13072
13146
  const json = await res.json();
13073
13147
  return CliInstallTokenSuccessSchema.parse(json);
13074
13148
  }
13149
+ async function postOutcomeEpisode(bambooSession, body) {
13150
+ const res = await cliApiFetch(`${apiBase()}/api/v1/cli/episodes`, {
13151
+ method: "POST",
13152
+ headers: {
13153
+ Authorization: `Bearer ${bambooSession}`,
13154
+ "Content-Type": "application/json"
13155
+ },
13156
+ body: JSON.stringify(body)
13157
+ });
13158
+ if (!res.ok) throw await parseError(res);
13159
+ const json = await res.json();
13160
+ return CliOutcomeEpisodeResponseSchema.parse(json);
13161
+ }
13075
13162
  var PROD_DEFAULT_BASE, DEV_DEFAULT_BASE, REQUEST_TIMEOUT_MS, ApiError, OAuthRelinkStartResponseSchema, ProvisionWorkspaceResponseSchema, FirstAutoInstalledAgentResponseSchema, SkillCatalogEntrySchema, SkillCatalogResponseSchema, SkillSubscriptionsResponseSchema, ScaffoldSkillResponseSchema;
13076
13163
  var init_api = __esm({
13077
13164
  "src/lib/api.ts"() {
@@ -13088,12 +13175,14 @@ var init_api = __esm({
13088
13175
  init_knowledge_save();
13089
13176
  init_skill_apply();
13090
13177
  init_inbox_revise();
13178
+ init_inbox_apply_revision();
13091
13179
  init_save();
13092
13180
  init_history();
13093
13181
  init_changes();
13094
13182
  init_onboarding_status();
13095
13183
  init_context_health();
13096
13184
  init_install_token();
13185
+ init_episodes();
13097
13186
  init_version();
13098
13187
  PROD_DEFAULT_BASE = "https://withbamboo.com";
13099
13188
  DEV_DEFAULT_BASE = "https://dev.withbamboo.com";
@@ -17588,9 +17677,12 @@ var init_knowledge = __esm({
17588
17677
  // src/commands/inbox.ts
17589
17678
  var inbox_exports = {};
17590
17679
  __export(inbox_exports, {
17680
+ runInboxApplyRevision: () => runInboxApplyRevision,
17591
17681
  runInboxRevise: () => runInboxRevise
17592
17682
  });
17593
- import { readFile as readFile8 } from "node:fs/promises";
17683
+ import { mkdir as mkdir5, readFile as readFile8, writeFile as writeFile4 } from "node:fs/promises";
17684
+ import { tmpdir } from "node:os";
17685
+ import { basename, join as join6 } from "node:path";
17594
17686
  async function requireSession4(opts) {
17595
17687
  const session = await resolveSession();
17596
17688
  if (!session) {
@@ -17628,6 +17720,31 @@ async function readSelectionFile(path2) {
17628
17720
  }
17629
17721
  return parsed.data;
17630
17722
  }
17723
+ async function materializeReviseContent(result, file) {
17724
+ const { file_content, file_content_base, ...rest } = result;
17725
+ if (result.dispatched || !file_content || !result.file_sha || !result.branch) {
17726
+ return rest;
17727
+ }
17728
+ const dir = join6(tmpdir(), `bamboo-revise-${result.pr_number}`);
17729
+ const headFile = join6(dir, `head-${basename(file)}`);
17730
+ try {
17731
+ await mkdir5(dir, { recursive: true });
17732
+ await writeFile4(headFile, file_content, "utf8");
17733
+ let baseFile;
17734
+ if (file_content_base !== void 0) {
17735
+ baseFile = join6(dir, `base-${basename(file)}`);
17736
+ await writeFile4(baseFile, file_content_base, "utf8");
17737
+ }
17738
+ return {
17739
+ ...rest,
17740
+ head_file: headFile,
17741
+ base_file: baseFile,
17742
+ next_step: `Edit ${headFile} to apply the requested change, then run: bamboo-agents inbox apply-revision --pr ${result.pr_number} --file "${file}" --content-file ${headFile} --sha ${result.file_sha} --branch "${result.branch}" --message "revision: <short summary>" --json`
17743
+ };
17744
+ } catch {
17745
+ return result;
17746
+ }
17747
+ }
17631
17748
  function printReviseResult(result, opts) {
17632
17749
  if (result.dispatched) {
17633
17750
  human(
@@ -17639,10 +17756,18 @@ function printReviseResult(result, opts) {
17639
17756
  }
17640
17757
  human(` \u2022 Not dispatched \u2014 this PR's source is not a managed agent.`, opts);
17641
17758
  if (result.message) human(` ${result.message}`, opts);
17642
- human(
17643
- ` Applying the change directly isn't available from the CLI yet \u2014 make the edit via the Inbox or GitHub.`,
17644
- opts
17645
- );
17759
+ if (result.head_file) {
17760
+ human(` PR-head content written to ${result.head_file}`, opts);
17761
+ human(
17762
+ ` Edit that file, then commit it back with \`bamboo-agents inbox apply-revision\` (see next_step).`,
17763
+ opts
17764
+ );
17765
+ } else {
17766
+ human(
17767
+ ` The file content could not be read from the PR branch \u2014 make the edit via the Inbox or GitHub.`,
17768
+ opts
17769
+ );
17770
+ }
17646
17771
  }
17647
17772
  async function runInboxRevise(options) {
17648
17773
  const opts = options;
@@ -17717,7 +17842,122 @@ async function runInboxRevise(options) {
17717
17842
  );
17718
17843
  return;
17719
17844
  }
17720
- emitSuccess(result, opts, (r) => printReviseResult(r, opts));
17845
+ const output = await materializeReviseContent(result, file);
17846
+ emitSuccess(output, opts, (r) => printReviseResult(r, opts));
17847
+ }
17848
+ async function runInboxApplyRevision(options) {
17849
+ const opts = options;
17850
+ const session = await requireSession4(opts);
17851
+ const prNumber = Number.parseInt(options.pr ?? "", 10);
17852
+ if (!Number.isInteger(prNumber) || prNumber <= 0) {
17853
+ emitError(
17854
+ {
17855
+ code: "invalid_pr",
17856
+ message: `--pr must be a positive PR number (got ${JSON.stringify(options.pr ?? null)}).`
17857
+ },
17858
+ opts,
17859
+ 1
17860
+ );
17861
+ return;
17862
+ }
17863
+ const file = options.file?.trim();
17864
+ if (!file) {
17865
+ emitError(
17866
+ {
17867
+ code: "missing_file",
17868
+ message: "inbox apply-revision requires --file (the repo-relative path being revised)."
17869
+ },
17870
+ opts,
17871
+ 1
17872
+ );
17873
+ return;
17874
+ }
17875
+ const sha = options.sha?.trim();
17876
+ if (!sha) {
17877
+ emitError(
17878
+ {
17879
+ code: "missing_sha",
17880
+ message: "inbox apply-revision requires --sha (the file_sha from `inbox revise`).",
17881
+ hint: "GitHub uses it to reject the write if the PR branch moved since the file was read."
17882
+ },
17883
+ opts,
17884
+ 1
17885
+ );
17886
+ return;
17887
+ }
17888
+ const message = options.message?.trim();
17889
+ if (!message) {
17890
+ emitError(
17891
+ {
17892
+ code: "missing_message",
17893
+ message: "inbox apply-revision requires --message (a short commit message).",
17894
+ hint: 'e.g. --message "revision: tighten tone in intro paragraph"'
17895
+ },
17896
+ opts,
17897
+ 1
17898
+ );
17899
+ return;
17900
+ }
17901
+ if (!options.contentFile) {
17902
+ emitError(
17903
+ {
17904
+ code: "missing_content_file",
17905
+ message: "inbox apply-revision requires --content-file (the revised file content on disk).",
17906
+ hint: "Edit the head_file from `inbox revise`, then pass its path here \u2014 the FULL file, not a diff."
17907
+ },
17908
+ opts,
17909
+ 1
17910
+ );
17911
+ return;
17912
+ }
17913
+ let newContent;
17914
+ try {
17915
+ newContent = await readFile8(options.contentFile, "utf8");
17916
+ } catch (err) {
17917
+ emitError(
17918
+ {
17919
+ code: "invalid_content_file",
17920
+ message: `couldn't read content file ${options.contentFile}: ${err.message}`
17921
+ },
17922
+ opts,
17923
+ 1
17924
+ );
17925
+ return;
17926
+ }
17927
+ if (!newContent.trim()) {
17928
+ emitError(
17929
+ {
17930
+ code: "empty_content_file",
17931
+ message: `content file ${options.contentFile} is empty \u2014 apply-revision commits the full revised file.`,
17932
+ hint: "To remove the change entirely, decline the PR instead."
17933
+ },
17934
+ opts,
17935
+ 1
17936
+ );
17937
+ return;
17938
+ }
17939
+ let result;
17940
+ try {
17941
+ result = await requestInboxApplyRevision(session, {
17942
+ pr_number: prNumber,
17943
+ file,
17944
+ new_content: newContent,
17945
+ commit_message: message,
17946
+ file_sha: sha,
17947
+ branch: options.branch?.trim() || void 0
17948
+ });
17949
+ } catch (err) {
17950
+ const code = err instanceof ApiError && err.errorCode ? err.errorCode : "apply_revision_failed";
17951
+ emitError(
17952
+ { code, message: `apply-revision failed: ${err.message}` },
17953
+ opts,
17954
+ 1
17955
+ );
17956
+ return;
17957
+ }
17958
+ emitSuccess(result, opts, (r) => {
17959
+ human(` \u2713 Revision committed to ${r.branch} \u2014 the Inbox diff is updated.`, opts);
17960
+ });
17721
17961
  }
17722
17962
  var SelectionFileSchema;
17723
17963
  var init_inbox = __esm({
@@ -18437,6 +18677,79 @@ var init_agents2 = __esm({
18437
18677
  }
18438
18678
  });
18439
18679
 
18680
+ // src/commands/episode.ts
18681
+ var episode_exports = {};
18682
+ __export(episode_exports, {
18683
+ runEpisodeLogOutcome: () => runEpisodeLogOutcome
18684
+ });
18685
+ async function requireSession10() {
18686
+ const creds = await readCredentials();
18687
+ if (!creds) {
18688
+ console.error("bamboo-agents: not signed in. Run `bamboo-agents login` first.");
18689
+ process.exit(1);
18690
+ }
18691
+ return creds.bamboo_session;
18692
+ }
18693
+ async function runEpisodeLogOutcome(options) {
18694
+ if (!options.rec || !options.brand || !options.description) {
18695
+ console.error(
18696
+ "bamboo-agents: `episode log-outcome` requires --rec, --brand, and --description."
18697
+ );
18698
+ process.exit(2);
18699
+ }
18700
+ let metricsBefore;
18701
+ let metricsAfter;
18702
+ if (options.metricsBefore) {
18703
+ try {
18704
+ metricsBefore = JSON.parse(options.metricsBefore);
18705
+ } catch {
18706
+ console.error(`bamboo-agents: --metrics-before must be valid JSON, e.g. '{"cpa": 35}'.`);
18707
+ process.exit(2);
18708
+ }
18709
+ }
18710
+ if (options.metricsAfter) {
18711
+ try {
18712
+ metricsAfter = JSON.parse(options.metricsAfter);
18713
+ } catch {
18714
+ console.error(`bamboo-agents: --metrics-after must be valid JSON, e.g. '{"cpa": 31}'.`);
18715
+ process.exit(2);
18716
+ }
18717
+ }
18718
+ const session = await requireSession10();
18719
+ let result;
18720
+ try {
18721
+ result = await postOutcomeEpisode(session, {
18722
+ brand_id: options.brand,
18723
+ parent_episode_id: options.rec,
18724
+ description: options.description,
18725
+ ...metricsBefore ? { metrics_before: metricsBefore } : {},
18726
+ ...metricsAfter ? { metrics_after: metricsAfter } : {}
18727
+ });
18728
+ } catch (err) {
18729
+ console.error(`bamboo-agents: outcome entry failed: ${err.message}`);
18730
+ process.exit(1);
18731
+ }
18732
+ if (options.json) {
18733
+ console.log(JSON.stringify(result));
18734
+ return;
18735
+ }
18736
+ if (!options.quiet) {
18737
+ console.log("");
18738
+ console.log(` \u2713 Outcome logged \u2014 episode ${result.id}`);
18739
+ console.log(` Chained to rec: ${result.parent_episode_id}`);
18740
+ console.log(` Brand: ${result.brand_id}`);
18741
+ console.log(` Created: ${result.created_at}`);
18742
+ console.log("");
18743
+ }
18744
+ }
18745
+ var init_episode = __esm({
18746
+ "src/commands/episode.ts"() {
18747
+ "use strict";
18748
+ init_credentials();
18749
+ init_api();
18750
+ }
18751
+ });
18752
+
18440
18753
  // node_modules/commander/esm.mjs
18441
18754
  var import_index = __toESM(require_commander(), 1);
18442
18755
  var {
@@ -18758,6 +19071,10 @@ inbox.command("revise").description("Request a revision on a pending inbox PR (d
18758
19071
  const { runInboxRevise: runInboxRevise2 } = await Promise.resolve().then(() => (init_inbox(), inbox_exports));
18759
19072
  await runInboxRevise2(options);
18760
19073
  });
19074
+ inbox.command("apply-revision").description("Commit revised file content to a pending inbox PR's head branch (the dispatched:false follow-up to `inbox revise`)").requiredOption("--pr <number>", "PR number in the workspace repo").requiredOption("--file <path>", "Repo-relative path of the file being revised").requiredOption("--content-file <path>", "Local file holding the COMPLETE revised content (edit the head_file from `inbox revise`)").requiredOption("--sha <sha>", "The file_sha from `inbox revise` (GitHub's stale-write check)").requiredOption("--message <text>", "Short commit message, e.g. 'revision: tighten tone in intro'").option("--branch <name>", "PR head branch from `inbox revise` (validated server-side)").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) => {
19075
+ const { runInboxApplyRevision: runInboxApplyRevision2 } = await Promise.resolve().then(() => (init_inbox(), inbox_exports));
19076
+ await runInboxApplyRevision2(options);
19077
+ });
18761
19078
  program2.command("history").description("Recent workspace actions (reverse-chronological)").option("--limit <n>", "Max entries (default 20, max 100)").option(
18762
19079
  "--source <runtime>",
18763
19080
  "Filter by runtime origin (boo | sandbox-boo | managed-agent)"
@@ -18840,6 +19157,13 @@ agents.command("pause <agent>").description("Pause an agent \u2014 stops its sch
18840
19157
  const { runAgentsPause: runAgentsPause2 } = await Promise.resolve().then(() => (init_agents2(), agents_exports2));
18841
19158
  await runAgentsPause2(agent, options);
18842
19159
  });
19160
+ var episode = program2.command("episode").description("Pilot decision-ledger \u2014 log outcomes against recommendations");
19161
+ episode.command("log-outcome").description(
19162
+ "Log an outcome episode chained to a recommendation (closes the accept\u2192result loop)"
19163
+ ).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) => {
19164
+ const { runEpisodeLogOutcome: runEpisodeLogOutcome2 } = await Promise.resolve().then(() => (init_episode(), episode_exports));
19165
+ await runEpisodeLogOutcome2(options);
19166
+ });
18843
19167
  (async () => {
18844
19168
  const rawArgs = process.argv.slice(2);
18845
19169
  const { operands } = program2.parseOptions(rawArgs);