bamboo-agents 0.1.5-dev.47.e6dcb2e → 0.1.5-dev.49.eaaa602

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.47.e6dcb2e";
3040
+ VERSION = "0.1.5-dev.49.eaaa602";
3041
3041
  }
3042
3042
  });
3043
3043
 
@@ -14386,11 +14386,469 @@ var init_open2 = __esm({
14386
14386
  }
14387
14387
  });
14388
14388
 
14389
+ // src/lib/output.ts
14390
+ function isJsonMode(opts = {}) {
14391
+ if (opts.json === true) return true;
14392
+ return process.stdout.isTTY !== true;
14393
+ }
14394
+ function parseFields(raw) {
14395
+ if (!raw) return [];
14396
+ return raw.split(",").map((s) => s.trim()).filter((s) => s.length > 0);
14397
+ }
14398
+ function pluckPath(value, segments) {
14399
+ if (segments.length === 0) return value;
14400
+ if (value === null || value === void 0) return void 0;
14401
+ if (Array.isArray(value)) {
14402
+ return value.map((item) => pluckPath(item, segments)).filter((v) => v !== void 0);
14403
+ }
14404
+ if (typeof value === "object") {
14405
+ const [head, ...rest] = segments;
14406
+ return pluckPath(value[head], rest);
14407
+ }
14408
+ return void 0;
14409
+ }
14410
+ function projectFields(data, fields) {
14411
+ if (fields.length === 0) return data;
14412
+ if (data === null || typeof data !== "object" || Array.isArray(data)) {
14413
+ return data;
14414
+ }
14415
+ const out = {};
14416
+ for (const field of fields) {
14417
+ const segments = field.split(".").filter((s) => s.length > 0);
14418
+ if (segments.length === 0) continue;
14419
+ const value = pluckPath(data, segments);
14420
+ if (value === void 0) continue;
14421
+ out[field] = value;
14422
+ }
14423
+ return out;
14424
+ }
14425
+ function writeStdout(line) {
14426
+ process.stdout.write(line.endsWith("\n") ? line : line + "\n");
14427
+ }
14428
+ function writeStderr(line) {
14429
+ process.stderr.write(line.endsWith("\n") ? line : line + "\n");
14430
+ }
14431
+ function emitSuccess(data, opts, renderHuman) {
14432
+ if (isJsonMode(opts)) {
14433
+ const projected = projectFields(data, parseFields(opts.fields));
14434
+ const envelope = { ok: true, data: projected };
14435
+ writeStdout(JSON.stringify(envelope, null, 2));
14436
+ return;
14437
+ }
14438
+ if (opts.quiet) return;
14439
+ if (renderHuman) renderHuman(data);
14440
+ }
14441
+ function emitError(err, opts, exitCode) {
14442
+ if (isJsonMode(opts)) {
14443
+ const envelope = {
14444
+ ok: false,
14445
+ error: {
14446
+ code: err.code,
14447
+ message: err.message,
14448
+ ...err.hint ? { hint: err.hint } : {}
14449
+ }
14450
+ };
14451
+ writeStdout(JSON.stringify(envelope, null, 2));
14452
+ } else if (!opts.quiet) {
14453
+ writeStderr(`bamboo-agents: ${err.message}`);
14454
+ if (err.hint) writeStderr(` ${err.hint}`);
14455
+ }
14456
+ if (exitCode !== void 0) process.exit(exitCode);
14457
+ }
14458
+ function human(line = "", opts = {}) {
14459
+ if (opts.quiet) return;
14460
+ writeStderr(line);
14461
+ }
14462
+ var init_output = __esm({
14463
+ "src/lib/output.ts"() {
14464
+ "use strict";
14465
+ }
14466
+ });
14467
+
14468
+ // src/commands/save.ts
14469
+ var save_exports = {};
14470
+ __export(save_exports, {
14471
+ isDeletion: () => isDeletion,
14472
+ isManagedPath: () => isManagedPath,
14473
+ parsePorcelain: () => parsePorcelain,
14474
+ planBatchFromPorcelain: () => planBatchFromPorcelain,
14475
+ reconcilePlan: () => reconcilePlan,
14476
+ runSave: () => runSave
14477
+ });
14478
+ import { execFile as execFile8 } from "node:child_process";
14479
+ import { readFile as readFile4, rm as rm2 } from "node:fs/promises";
14480
+ import { join as join2 } from "node:path";
14481
+ import { promisify as promisify8 } from "node:util";
14482
+ function parsePorcelain(out) {
14483
+ if (!out) return [];
14484
+ const fields = out.split("\0");
14485
+ const entries = [];
14486
+ for (let i = 0; i < fields.length; i++) {
14487
+ const field = fields[i];
14488
+ if (!field) continue;
14489
+ const status = field.slice(0, 2);
14490
+ const path2 = field.slice(3);
14491
+ if (!path2) continue;
14492
+ entries.push({ status, path: path2 });
14493
+ if (status[0] === "R" || status[0] === "C") {
14494
+ i++;
14495
+ }
14496
+ }
14497
+ return entries;
14498
+ }
14499
+ function isManagedPath(path2) {
14500
+ if (MANAGED_FILES.includes(path2)) return true;
14501
+ return MANAGED_PREFIXES.some((p) => path2.startsWith(p));
14502
+ }
14503
+ function isDeletion(entry) {
14504
+ return entry.status[0] === "D" || entry.status[1] === "D";
14505
+ }
14506
+ function planBatchFromPorcelain(entries) {
14507
+ const deletes = [];
14508
+ const writes = [];
14509
+ const skipped = [];
14510
+ const seen = /* @__PURE__ */ new Set();
14511
+ for (const entry of entries) {
14512
+ if (seen.has(entry.path)) continue;
14513
+ seen.add(entry.path);
14514
+ if (!isManagedPath(entry.path)) {
14515
+ skipped.push(entry.path);
14516
+ continue;
14517
+ }
14518
+ if (isDeletion(entry)) {
14519
+ deletes.push(entry.path);
14520
+ } else {
14521
+ writes.push(entry.path);
14522
+ }
14523
+ }
14524
+ return { deletes, writes, skipped };
14525
+ }
14526
+ function reconcilePlan(files, deletePaths) {
14527
+ const deleteSet = new Set(deletePaths);
14528
+ const checkout = [];
14529
+ const remove = [];
14530
+ const seen = /* @__PURE__ */ new Set();
14531
+ for (const f of files) {
14532
+ if (f.routed !== "auto") continue;
14533
+ if (!f.path || seen.has(f.path)) continue;
14534
+ seen.add(f.path);
14535
+ if (deleteSet.has(f.path)) remove.push(f.path);
14536
+ else checkout.push(f.path);
14537
+ }
14538
+ return { checkout, remove };
14539
+ }
14540
+ async function gitC(repoPath, args) {
14541
+ const { stdout } = await execFileP3("git", ["-C", repoPath, ...args], {
14542
+ encoding: "utf8",
14543
+ // -z output + file content can exceed the default 1MB buffer.
14544
+ maxBuffer: 32 * 1024 * 1024
14545
+ });
14546
+ return stdout;
14547
+ }
14548
+ async function currentBranch(repoPath) {
14549
+ const out = await gitC(repoPath, ["rev-parse", "--abbrev-ref", "HEAD"]);
14550
+ return out.trim() || "main";
14551
+ }
14552
+ async function requireSession(opts) {
14553
+ const creds = await readCredentials();
14554
+ if (!creds) {
14555
+ emitError(
14556
+ {
14557
+ code: "not_signed_in",
14558
+ message: "not signed in.",
14559
+ hint: "Run `bamboo-agents login` first."
14560
+ },
14561
+ opts,
14562
+ 1
14563
+ );
14564
+ throw new Error("unreachable");
14565
+ }
14566
+ return creds.bamboo_session;
14567
+ }
14568
+ async function runSave(intent, options = {}) {
14569
+ const opts = options;
14570
+ let workspacePath;
14571
+ try {
14572
+ workspacePath = (await resolveWorkspace()).path;
14573
+ } catch (err) {
14574
+ if (err instanceof NoWorkspaceError) {
14575
+ emitError({ code: "no_workspace", message: err.message }, opts, 2);
14576
+ return;
14577
+ }
14578
+ throw err;
14579
+ }
14580
+ const session = await requireSession(opts);
14581
+ let entries;
14582
+ try {
14583
+ const porcelain = await gitC(workspacePath, [
14584
+ "status",
14585
+ "--porcelain=v1",
14586
+ "-z",
14587
+ "-uall"
14588
+ ]);
14589
+ entries = parsePorcelain(porcelain);
14590
+ } catch {
14591
+ emitError(
14592
+ {
14593
+ code: "read_failed",
14594
+ message: "couldn't read your workspace changes.",
14595
+ hint: "Run `bamboo-agents doctor` to check your workspace is healthy."
14596
+ },
14597
+ opts,
14598
+ 1
14599
+ );
14600
+ return;
14601
+ }
14602
+ const { deletes, writes, skipped } = planBatchFromPorcelain(entries);
14603
+ if (deletes.length === 0 && writes.length === 0) {
14604
+ const payload2 = {
14605
+ saved: 0,
14606
+ live: 0,
14607
+ queued: 0,
14608
+ skipped: skipped.length,
14609
+ pr_url: null,
14610
+ files: []
14611
+ };
14612
+ emitSuccess(payload2, opts, () => {
14613
+ human("", opts);
14614
+ if (skipped.length > 0) {
14615
+ human(
14616
+ " Nothing to save \u2014 the only changes are outside your context folders.",
14617
+ opts
14618
+ );
14619
+ } else {
14620
+ human(" Nothing to save \u2014 your workspace is already up to date.", opts);
14621
+ }
14622
+ human("", opts);
14623
+ });
14624
+ return;
14625
+ }
14626
+ const edits = [];
14627
+ try {
14628
+ for (const path2 of writes) {
14629
+ const content = await readFile4(join2(workspacePath, path2), "utf8");
14630
+ edits.push({ path: path2, content });
14631
+ }
14632
+ } catch {
14633
+ emitError(
14634
+ {
14635
+ code: "read_failed",
14636
+ message: "couldn't read one of your changed files.",
14637
+ hint: "Make sure the file still exists, then run `bamboo-agents save` again."
14638
+ },
14639
+ opts,
14640
+ 1
14641
+ );
14642
+ return;
14643
+ }
14644
+ for (const path2 of deletes) {
14645
+ edits.push({ path: path2, delete: true });
14646
+ }
14647
+ let result;
14648
+ try {
14649
+ result = await saveWorkspace(session, {
14650
+ edits,
14651
+ intent: intent?.trim() || void 0
14652
+ });
14653
+ } catch (err) {
14654
+ if (err instanceof ApiError && err.status === 403) {
14655
+ emitError(
14656
+ {
14657
+ code: "forbidden",
14658
+ message: "couldn't save \u2014 you don't have permission to change some of these files.",
14659
+ hint: "Ask an org admin to review, or edit only your own brand/agent files."
14660
+ },
14661
+ opts,
14662
+ 1
14663
+ );
14664
+ return;
14665
+ }
14666
+ const message = err instanceof Error ? err.message : String(err);
14667
+ emitError(
14668
+ {
14669
+ code: "save_failed",
14670
+ message: `couldn't reach Bamboo to save your changes. (${message})`,
14671
+ hint: "Check your connection and run `bamboo-agents save` again."
14672
+ },
14673
+ opts,
14674
+ 1
14675
+ );
14676
+ return;
14677
+ }
14678
+ const { checkout, remove } = reconcilePlan(result.files, deletes);
14679
+ if (checkout.length > 0 || remove.length > 0) {
14680
+ try {
14681
+ const branch = await currentBranch(workspacePath);
14682
+ await gitC(workspacePath, ["fetch", "origin", branch]);
14683
+ if (checkout.length > 0) {
14684
+ await gitC(workspacePath, [
14685
+ "checkout",
14686
+ `origin/${branch}`,
14687
+ "--",
14688
+ ...checkout
14689
+ ]);
14690
+ }
14691
+ for (const path2 of remove) {
14692
+ await rm2(join2(workspacePath, path2), { force: true });
14693
+ }
14694
+ } catch {
14695
+ human(
14696
+ " (Saved, but couldn't refresh your local copy just now \u2014 it'll catch up on your next command.)",
14697
+ opts
14698
+ );
14699
+ }
14700
+ }
14701
+ const total = edits.length;
14702
+ const live = result.live_count;
14703
+ const queued = result.queued_count;
14704
+ const payload = {
14705
+ saved: total,
14706
+ live,
14707
+ queued,
14708
+ skipped: skipped.length,
14709
+ pr_url: result.pr_url ?? null,
14710
+ files: result.files
14711
+ };
14712
+ emitSuccess(payload, opts, () => {
14713
+ human("", opts);
14714
+ const parts = [];
14715
+ if (live > 0) parts.push(`${live} live`);
14716
+ if (queued > 0) parts.push(`${queued} queued for review`);
14717
+ const summary = parts.length > 0 ? ` \u2014 ${parts.join(", ")}` : "";
14718
+ human(` Saved ${total} file${total === 1 ? "" : "s"}${summary}.`, opts);
14719
+ if (queued > 0 && result.pr_url) {
14720
+ human(` Review: ${result.pr_url}`, opts);
14721
+ }
14722
+ if (skipped.length > 0) {
14723
+ human(
14724
+ ` (Skipped ${skipped.length} file${skipped.length === 1 ? "" : "s"} outside your context folders.)`,
14725
+ opts
14726
+ );
14727
+ }
14728
+ human("", opts);
14729
+ });
14730
+ }
14731
+ var execFileP3, MANAGED_PREFIXES, MANAGED_FILES;
14732
+ var init_save2 = __esm({
14733
+ "src/commands/save.ts"() {
14734
+ "use strict";
14735
+ init_api();
14736
+ init_credentials();
14737
+ init_workspace();
14738
+ init_output();
14739
+ execFileP3 = promisify8(execFile8);
14740
+ MANAGED_PREFIXES = [
14741
+ "brands/",
14742
+ "agents/",
14743
+ "knowledge/",
14744
+ "skills/",
14745
+ "instructions/",
14746
+ "org/"
14747
+ ];
14748
+ MANAGED_FILES = ["CLAUDE.md", "AGENTS.md"];
14749
+ }
14750
+ });
14751
+
14752
+ // src/lib/workspace-status.ts
14753
+ import { execFile as execFile9 } from "node:child_process";
14754
+ import { promisify as promisify9 } from "node:util";
14755
+ async function git(repoPath, args) {
14756
+ const { stdout } = await execFileP4("git", ["-C", repoPath, ...args], {
14757
+ encoding: "utf8",
14758
+ maxBuffer: 32 * 1024 * 1024
14759
+ });
14760
+ return stdout;
14761
+ }
14762
+ async function countUnsavedManagedEdits(repoPath) {
14763
+ let out;
14764
+ try {
14765
+ out = await git(repoPath, ["status", "--porcelain=v1", "-z", "-uall"]);
14766
+ } catch {
14767
+ return 0;
14768
+ }
14769
+ const seen = /* @__PURE__ */ new Set();
14770
+ for (const entry of parsePorcelain(out)) {
14771
+ if (!isManagedPath(entry.path)) continue;
14772
+ if (seen.has(entry.path)) continue;
14773
+ seen.add(entry.path);
14774
+ }
14775
+ return seen.size;
14776
+ }
14777
+ function parseAheadBehind(out) {
14778
+ const m = out.trim().match(/^(\d+)\s+(\d+)$/);
14779
+ if (!m) return null;
14780
+ return { behind: Number(m[1]), ahead: Number(m[2]) };
14781
+ }
14782
+ async function aheadBehind(repoPath, branch) {
14783
+ try {
14784
+ const out = await git(repoPath, [
14785
+ "rev-list",
14786
+ "--left-right",
14787
+ "--count",
14788
+ `origin/${branch}...HEAD`
14789
+ ]);
14790
+ return parseAheadBehind(out);
14791
+ } catch {
14792
+ return null;
14793
+ }
14794
+ }
14795
+ function classifyCloneHealth(input) {
14796
+ if (input.detachedHead) return "wrecked";
14797
+ if (input.ahead !== null && input.ahead > 0) return "wrecked";
14798
+ return "clean";
14799
+ }
14800
+ async function currentBranchOrNull(repoPath) {
14801
+ try {
14802
+ const out = await git(repoPath, ["symbolic-ref", "--quiet", "--short", "HEAD"]);
14803
+ const name = out.trim();
14804
+ return name || null;
14805
+ } catch {
14806
+ return null;
14807
+ }
14808
+ }
14809
+ async function inspectCloneHealth(repoPath) {
14810
+ const branch = await currentBranchOrNull(repoPath);
14811
+ if (branch === null) {
14812
+ return { health: "wrecked", branch: null, ahead: null };
14813
+ }
14814
+ const ab = await aheadBehind(repoPath, branch);
14815
+ const ahead = ab?.ahead ?? null;
14816
+ return {
14817
+ health: classifyCloneHealth({ detachedHead: false, ahead }),
14818
+ branch,
14819
+ ahead
14820
+ };
14821
+ }
14822
+ var execFileP4;
14823
+ var init_workspace_status = __esm({
14824
+ "src/lib/workspace-status.ts"() {
14825
+ "use strict";
14826
+ init_save2();
14827
+ execFileP4 = promisify9(execFile9);
14828
+ }
14829
+ });
14830
+
14389
14831
  // src/commands/status.ts
14390
14832
  var status_exports = {};
14391
14833
  __export(status_exports, {
14834
+ formatSyncLine: () => formatSyncLine,
14392
14835
  runStatus: () => runStatus
14393
14836
  });
14837
+ function formatSyncLine(input) {
14838
+ const { unsaved, behind, ahead } = input;
14839
+ const parts = [];
14840
+ if (unsaved > 0) {
14841
+ parts.push(`${unsaved} edit${unsaved === 1 ? "" : "s"} not saved`);
14842
+ }
14843
+ if (behind !== null && behind > 0) {
14844
+ parts.push(`cloud has ${behind} newer`);
14845
+ }
14846
+ if (ahead !== null && ahead > 0) {
14847
+ parts.push(`${ahead} local commit${ahead === 1 ? "" : "s"} ahead (run \`bamboo-agents doctor\`)`);
14848
+ }
14849
+ const summary = parts.length === 0 ? "in sync" : parts.join(", ");
14850
+ return `Sync: ${summary}`;
14851
+ }
14394
14852
  function formatSubscriptionLine(billing) {
14395
14853
  switch (billing.state) {
14396
14854
  case "trialing": {
@@ -14407,46 +14865,79 @@ function formatSubscriptionLine(billing) {
14407
14865
  return `Subscription: not yet started \u2014 subscribe at ${billing.billing_url}`;
14408
14866
  }
14409
14867
  }
14410
- async function runStatus() {
14868
+ async function runStatus(options = {}) {
14869
+ const opts = options;
14411
14870
  return withFreshWorkspace(async () => {
14412
14871
  const creds = await readCredentials();
14413
14872
  const state = await readState().catch(() => null);
14414
14873
  const cfg = await readConfig();
14415
- console.log("");
14416
- console.log(" Bamboo CLI status");
14417
- console.log("");
14418
- if (!creds) {
14419
- console.log(" Credentials: not set (run `bamboo-agents login`)");
14420
- } else {
14421
- console.log(
14422
- ` Credentials: set${creds.github_username ? ` (@${creds.github_username})` : ""}`
14423
- );
14424
- console.log(` Written: ${creds.written_at}`);
14425
- if (creds.github_token_expires_at) {
14426
- console.log(` GitHub expires: ${creds.github_token_expires_at}`);
14427
- }
14428
- }
14429
14874
  const workspacePath = state?.workspace_path ?? cfg?.repo_path ?? null;
14430
- if (!workspacePath) {
14431
- console.log(" Workspace: not configured (run `bamboo-agents init`)");
14432
- } else {
14433
- const repoLabel = cfg?.workspace_repo ?? state?.remote_url?.replace(/^https?:\/\/github\.com\//, "") ?? "(unknown)";
14434
- console.log(` Workspace: ${repoLabel}`);
14435
- console.log(` Repo path: ${workspacePath}`);
14436
- console.log(` Org: ${cfg?.org_name ?? state?.org_slug ?? "(unknown)"}`);
14437
- console.log(` Installed: ${cfg?.installed_at ?? state?.cloned_at ?? "(unknown)"}`);
14438
- if (state?.last_sync) {
14439
- console.log(` Last sync: ${state.last_sync}`);
14440
- }
14875
+ const repoLabel = workspacePath ? cfg?.workspace_repo ?? state?.remote_url?.replace(/^https?:\/\/github\.com\//, "") ?? "(unknown)" : null;
14876
+ let sync = null;
14877
+ if (workspacePath) {
14878
+ const unsaved = await countUnsavedManagedEdits(workspacePath);
14879
+ const branch = await currentBranchOrNull(workspacePath);
14880
+ const ab = branch ? await aheadBehind(workspacePath, branch) : null;
14881
+ sync = { unsaved, behind: ab?.behind ?? null, ahead: ab?.ahead ?? null };
14441
14882
  }
14883
+ let billing = null;
14442
14884
  if (creds?.bamboo_session) {
14443
14885
  try {
14444
- const billing = await getCliBillingStatus(creds.bamboo_session);
14445
- console.log(` ${formatSubscriptionLine(billing)}`);
14886
+ billing = await getCliBillingStatus(creds.bamboo_session);
14446
14887
  } catch {
14447
14888
  }
14448
14889
  }
14449
- console.log("");
14890
+ const payload = {
14891
+ signed_in: !!creds,
14892
+ github_username: creds?.github_username ?? null,
14893
+ credentials_written_at: creds?.written_at ?? null,
14894
+ github_token_expires_at: creds?.github_token_expires_at ?? null,
14895
+ workspace: {
14896
+ configured: !!workspacePath,
14897
+ repo: repoLabel,
14898
+ path: workspacePath,
14899
+ org: cfg?.org_name ?? state?.org_slug ?? null,
14900
+ installed_at: cfg?.installed_at ?? state?.cloned_at ?? null,
14901
+ last_sync: state?.last_sync ?? null,
14902
+ sync
14903
+ },
14904
+ subscription: billing
14905
+ };
14906
+ emitSuccess(payload, opts, (d) => {
14907
+ human("", opts);
14908
+ human(" Bamboo CLI status", opts);
14909
+ human("", opts);
14910
+ if (!d.signed_in) {
14911
+ human(" Credentials: not set (run `bamboo-agents login`)", opts);
14912
+ } else {
14913
+ human(
14914
+ ` Credentials: set${d.github_username ? ` (@${d.github_username})` : ""}`,
14915
+ opts
14916
+ );
14917
+ human(` Written: ${d.credentials_written_at}`, opts);
14918
+ if (d.github_token_expires_at) {
14919
+ human(` GitHub expires: ${d.github_token_expires_at}`, opts);
14920
+ }
14921
+ }
14922
+ if (!d.workspace.configured) {
14923
+ human(" Workspace: not configured (run `bamboo-agents init`)", opts);
14924
+ } else {
14925
+ human(` Workspace: ${d.workspace.repo ?? "(unknown)"}`, opts);
14926
+ human(` Repo path: ${d.workspace.path}`, opts);
14927
+ human(` Org: ${d.workspace.org ?? "(unknown)"}`, opts);
14928
+ human(` Installed: ${d.workspace.installed_at ?? "(unknown)"}`, opts);
14929
+ if (d.workspace.last_sync) {
14930
+ human(` Last sync: ${d.workspace.last_sync}`, opts);
14931
+ }
14932
+ if (d.workspace.sync) {
14933
+ human(` ${formatSyncLine(d.workspace.sync)}`, opts);
14934
+ }
14935
+ }
14936
+ if (d.subscription) {
14937
+ human(` ${formatSubscriptionLine(d.subscription)}`, opts);
14938
+ }
14939
+ human("", opts);
14940
+ });
14450
14941
  });
14451
14942
  }
14452
14943
  var init_status = __esm({
@@ -14456,14 +14947,16 @@ var init_status = __esm({
14456
14947
  init_credentials();
14457
14948
  init_api();
14458
14949
  init_workspace();
14950
+ init_workspace_status();
14951
+ init_output();
14459
14952
  }
14460
14953
  });
14461
14954
 
14462
14955
  // src/lib/workspace-health.ts
14463
- import { execFile as execFile8 } from "node:child_process";
14464
- import { promisify as promisify8 } from "node:util";
14465
- import { lstat, readlink, readdir as readdir2, mkdir as mkdir3, symlink, rm as rm2, access as access3 } from "node:fs/promises";
14466
- import { join as join2, dirname as dirname2, resolve } from "node:path";
14956
+ import { execFile as execFile10 } from "node:child_process";
14957
+ import { promisify as promisify10 } from "node:util";
14958
+ import { lstat, readlink, readdir as readdir2, mkdir as mkdir3, symlink, rm as rm3, access as access3 } from "node:fs/promises";
14959
+ import { join as join3, dirname as dirname2, resolve } from "node:path";
14467
14960
  import { homedir as homedir2 } from "node:os";
14468
14961
  function getStaleSyncHours() {
14469
14962
  const raw = process.env.BAMBOO_STALE_SYNC_HOURS;
@@ -14475,7 +14968,7 @@ function getStaleSyncHours() {
14475
14968
  function cloneSearchRoots(cwd) {
14476
14969
  const overridden = process.env.BAMBOO_CLONE_SEARCH_DIRS;
14477
14970
  const home = homedir2();
14478
- const base = overridden ? overridden.split(":").filter(Boolean) : [home, join2(home, "Documents"), join2(home, "Downloads"), join2(home, "Desktop")];
14971
+ const base = overridden ? overridden.split(":").filter(Boolean) : [home, join3(home, "Documents"), join3(home, "Downloads"), join3(home, "Desktop")];
14479
14972
  const walk = [];
14480
14973
  let cur = cwd ?? process.cwd();
14481
14974
  for (let i = 0; i < 20; i++) {
@@ -14505,7 +14998,7 @@ async function findClones(remoteUrl, roots, maxDepth = 4) {
14505
14998
  if (scanned >= MAX_DIRS_SCANNED) return;
14506
14999
  if (depth < 0) return;
14507
15000
  scanned += 1;
14508
- const gitDir = join2(dir, ".git");
15001
+ const gitDir = join3(dir, ".git");
14509
15002
  let isRepo = false;
14510
15003
  try {
14511
15004
  const s = await lstat(gitDir);
@@ -14532,7 +15025,7 @@ async function findClones(remoteUrl, roots, maxDepth = 4) {
14532
15025
  if (SKIP_DIRS.has(entry.name)) continue;
14533
15026
  }
14534
15027
  if (SKIP_DIRS.has(entry.name)) continue;
14535
- await visit(join2(dir, entry.name), depth - 1);
15028
+ await visit(join3(dir, entry.name), depth - 1);
14536
15029
  }
14537
15030
  }
14538
15031
  for (const root of roots) {
@@ -14563,7 +15056,7 @@ function remoteUrlSlug(url) {
14563
15056
  async function checkAdapters(workspacePath) {
14564
15057
  const out = [];
14565
15058
  for (const { path: path2, target } of CROSS_TOOL_ADAPTERS) {
14566
- const full = join2(workspacePath, path2);
15059
+ const full = join3(workspacePath, path2);
14567
15060
  let s;
14568
15061
  try {
14569
15062
  s = await lstat(full);
@@ -14607,10 +15100,10 @@ async function healAdapters(workspacePath) {
14607
15100
  const current = await checkAdapters(workspacePath);
14608
15101
  for (const status of current) {
14609
15102
  if (status.ok) continue;
14610
- const full = join2(workspacePath, status.path);
15103
+ const full = join3(workspacePath, status.path);
14611
15104
  if (status.state === "wrong_target" || status.state === "not_symlink") {
14612
15105
  try {
14613
- await rm2(full, { recursive: true, force: true });
15106
+ await rm3(full, { recursive: true, force: true });
14614
15107
  } catch {
14615
15108
  }
14616
15109
  }
@@ -14637,7 +15130,7 @@ function describeAge(lastSync) {
14637
15130
  }
14638
15131
  async function gitPullFfOnly(workspacePath) {
14639
15132
  try {
14640
- const { stderr } = await execFileP3("git", ["-C", workspacePath, "pull", "--ff-only"], {
15133
+ const { stderr } = await execFileP5("git", ["-C", workspacePath, "pull", "--ff-only"], {
14641
15134
  encoding: "utf8"
14642
15135
  });
14643
15136
  return { ok: true, stderr };
@@ -14654,12 +15147,12 @@ async function pathExists(p) {
14654
15147
  return false;
14655
15148
  }
14656
15149
  }
14657
- var execFileP3, CROSS_TOOL_ADAPTERS, DEFAULT_STALE_SYNC_HOURS, MAX_DIRS_SCANNED, SKIP_DIRS;
15150
+ var execFileP5, CROSS_TOOL_ADAPTERS, DEFAULT_STALE_SYNC_HOURS, MAX_DIRS_SCANNED, SKIP_DIRS;
14658
15151
  var init_workspace_health = __esm({
14659
15152
  "src/lib/workspace-health.ts"() {
14660
15153
  "use strict";
14661
15154
  init_git();
14662
- execFileP3 = promisify8(execFile8);
15155
+ execFileP5 = promisify10(execFile10);
14663
15156
  CROSS_TOOL_ADAPTERS = [
14664
15157
  { path: ".claude/skills", target: "../skills" },
14665
15158
  { path: ".cursor/skills", target: "../skills" },
@@ -14769,7 +15262,7 @@ __export(doctor_exports, {
14769
15262
  runDoctor: () => runDoctor
14770
15263
  });
14771
15264
  import { access as access4 } from "node:fs/promises";
14772
- import { rm as rm3 } from "node:fs/promises";
15265
+ import { rm as rm4 } from "node:fs/promises";
14773
15266
  async function checkGit() {
14774
15267
  const v = await gitVersion();
14775
15268
  if (!v) {
@@ -15036,7 +15529,7 @@ async function healMultiClone(finding, state, opts) {
15036
15529
  if (wantDelete) {
15037
15530
  for (const p of nonCanonical) {
15038
15531
  try {
15039
- await rm3(p, { recursive: true, force: true });
15532
+ await rm4(p, { recursive: true, force: true });
15040
15533
  console.log(` \u2713 removed ${p}`);
15041
15534
  } catch (err) {
15042
15535
  console.log(` \u2717 couldn't remove ${p}: ${err.message}`);
@@ -15139,337 +15632,176 @@ async function runDoctor(options = {}) {
15139
15632
  multi_clone: "Single clone",
15140
15633
  wrong_state: "State matches workspace",
15141
15634
  missing_adapters: "Cross-tool adapters",
15142
- stale_sync: "Recent sync"
15143
- };
15144
- for (const f of drift) {
15145
- const mark = f.ok ? "\u2713" : "\u2717";
15146
- console.log(` ${mark} ${labels[f.kind].padEnd(28)} ${f.summary}`);
15147
- }
15148
- }
15149
- console.log("");
15150
- const remaining = (drift ?? []).filter((f) => !f.ok);
15151
- if (remaining.length === 0) {
15152
- const baseFailures = baseChecks.filter((c) => !c.ok).length;
15153
- if (baseFailures > 0) {
15154
- console.log(` ${baseFailures} check(s) failing.`);
15155
- process.exit(1);
15156
- }
15157
- console.log(" All checks passing.");
15158
- return;
15159
- }
15160
- console.log(` ${remaining.length} drift issue(s) detected \u2014 let's fix them.`);
15161
- let cur = state;
15162
- const order = [
15163
- "stale_state",
15164
- "wrong_state",
15165
- "multi_clone",
15166
- "missing_adapters",
15167
- "stale_sync"
15168
- ];
15169
- for (const kind of order) {
15170
- const f = remaining.find((r) => r.kind === kind);
15171
- if (!f) continue;
15172
- switch (kind) {
15173
- case "stale_state":
15174
- cur = await healStaleState(f, cur, opts);
15175
- break;
15176
- case "multi_clone":
15177
- cur = await healMultiClone(f, cur, opts);
15178
- break;
15179
- case "wrong_state":
15180
- cur = await healWrongState(f, cur, opts);
15181
- break;
15182
- case "missing_adapters":
15183
- cur = await healMissingAdapters(f, cur, opts);
15184
- break;
15185
- case "stale_sync":
15186
- cur = await healStaleSync(f, cur, opts);
15187
- break;
15188
- }
15189
- }
15190
- const post = await readState().catch(() => null);
15191
- const postDrift = post ? await collectDriftFindings(post) : drift;
15192
- const stillBroken = (postDrift ?? []).filter((d) => !d.ok);
15193
- console.log("");
15194
- if (stillBroken.length === 0) {
15195
- console.log(" \u2713 Workspace healthy.");
15196
- return;
15197
- }
15198
- console.log(` ${stillBroken.length} issue(s) remain \u2014 re-run \`bamboo-agents doctor\` after addressing.`);
15199
- process.exit(1);
15200
- }
15201
- var init_doctor = __esm({
15202
- "src/commands/doctor.ts"() {
15203
- "use strict";
15204
- init_api();
15205
- init_git();
15206
- init_state();
15207
- init_credentials();
15208
- init_workspace_health();
15209
- init_heal_prompt();
15210
- }
15211
- });
15212
-
15213
- // src/commands/save.ts
15214
- var save_exports = {};
15215
- __export(save_exports, {
15216
- isDeletion: () => isDeletion,
15217
- isManagedPath: () => isManagedPath,
15218
- parsePorcelain: () => parsePorcelain,
15219
- planBatchFromPorcelain: () => planBatchFromPorcelain,
15220
- runSave: () => runSave
15221
- });
15222
- import { execFile as execFile9 } from "node:child_process";
15223
- import { readFile as readFile4 } from "node:fs/promises";
15224
- import { join as join3 } from "node:path";
15225
- import { promisify as promisify9 } from "node:util";
15226
- function parsePorcelain(out) {
15227
- if (!out) return [];
15228
- const fields = out.split("\0");
15229
- const entries = [];
15230
- for (let i = 0; i < fields.length; i++) {
15231
- const field = fields[i];
15232
- if (!field) continue;
15233
- const status = field.slice(0, 2);
15234
- const path2 = field.slice(3);
15235
- if (!path2) continue;
15236
- entries.push({ status, path: path2 });
15237
- if (status[0] === "R" || status[0] === "C") {
15238
- i++;
15239
- }
15240
- }
15241
- return entries;
15242
- }
15243
- function isManagedPath(path2) {
15244
- if (MANAGED_FILES.includes(path2)) return true;
15245
- return MANAGED_PREFIXES.some((p) => path2.startsWith(p));
15246
- }
15247
- function isDeletion(entry) {
15248
- return entry.status[0] === "D" || entry.status[1] === "D";
15249
- }
15250
- function planBatchFromPorcelain(entries) {
15251
- const deletes = [];
15252
- const writes = [];
15253
- const skipped = [];
15254
- const seen = /* @__PURE__ */ new Set();
15255
- for (const entry of entries) {
15256
- if (seen.has(entry.path)) continue;
15257
- seen.add(entry.path);
15258
- if (!isManagedPath(entry.path)) {
15259
- skipped.push(entry.path);
15260
- continue;
15261
- }
15262
- if (isDeletion(entry)) {
15263
- deletes.push(entry.path);
15264
- } else {
15265
- writes.push(entry.path);
15266
- }
15267
- }
15268
- return { deletes, writes, skipped };
15269
- }
15270
- async function gitC(repoPath, args) {
15271
- const { stdout } = await execFileP4("git", ["-C", repoPath, ...args], {
15272
- encoding: "utf8",
15273
- // -z output + file content can exceed the default 1MB buffer.
15274
- maxBuffer: 32 * 1024 * 1024
15275
- });
15276
- return stdout;
15277
- }
15278
- async function currentBranch(repoPath) {
15279
- const out = await gitC(repoPath, ["rev-parse", "--abbrev-ref", "HEAD"]);
15280
- return out.trim() || "main";
15281
- }
15282
- async function requireSession() {
15283
- const creds = await readCredentials();
15284
- if (!creds) {
15285
- console.error(
15286
- "bamboo-agents save: not signed in. Run `bamboo-agents login` first."
15287
- );
15288
- process.exit(1);
15289
- }
15290
- return creds.bamboo_session;
15291
- }
15292
- async function runSave(intent) {
15293
- let workspacePath;
15294
- try {
15295
- workspacePath = (await resolveWorkspace()).path;
15296
- } catch (err) {
15297
- if (err instanceof NoWorkspaceError) {
15298
- console.error(`bamboo-agents save: ${err.message}`);
15299
- process.exit(2);
15300
- }
15301
- throw err;
15302
- }
15303
- const session = await requireSession();
15304
- let entries;
15305
- try {
15306
- const porcelain = await gitC(workspacePath, [
15307
- "status",
15308
- "--porcelain=v1",
15309
- "-z",
15310
- "-uall"
15311
- ]);
15312
- entries = parsePorcelain(porcelain);
15313
- } catch {
15314
- console.error(
15315
- " Couldn't read your workspace changes.\n Next: run `bamboo-agents doctor` to check your workspace is healthy."
15316
- );
15317
- process.exit(1);
15318
- }
15319
- const { deletes, writes, skipped } = planBatchFromPorcelain(entries);
15320
- if (deletes.length === 0 && writes.length === 0) {
15321
- console.log("");
15322
- if (skipped.length > 0) {
15323
- console.log(
15324
- " Nothing to save \u2014 the only changes are outside your context folders."
15325
- );
15326
- } else {
15327
- console.log(" Nothing to save \u2014 your workspace is already up to date.");
15328
- }
15329
- console.log("");
15330
- return;
15331
- }
15332
- const edits = [];
15333
- try {
15334
- for (const path2 of writes) {
15335
- const content = await readFile4(join3(workspacePath, path2), "utf8");
15336
- edits.push({ path: path2, content });
15635
+ stale_sync: "Recent sync"
15636
+ };
15637
+ for (const f of drift) {
15638
+ const mark = f.ok ? "\u2713" : "\u2717";
15639
+ console.log(` ${mark} ${labels[f.kind].padEnd(28)} ${f.summary}`);
15337
15640
  }
15338
- } catch {
15339
- console.error(
15340
- " Couldn't read one of your changed files.\n Next: make sure the file still exists, then run `bamboo-agents save` again."
15341
- );
15342
- process.exit(1);
15343
- }
15344
- for (const path2 of deletes) {
15345
- edits.push({ path: path2, delete: true });
15346
15641
  }
15347
- let result;
15348
- try {
15349
- result = await saveWorkspace(session, {
15350
- edits,
15351
- intent: intent?.trim() || void 0
15352
- });
15353
- } catch (err) {
15354
- if (err instanceof ApiError && err.status === 403) {
15355
- console.error("");
15356
- console.error(
15357
- " Couldn't save \u2014 you don't have permission to change some of these files.\n Next: ask an org admin to review, or edit only your own brand/agent files."
15358
- );
15642
+ console.log("");
15643
+ const remaining = (drift ?? []).filter((f) => !f.ok);
15644
+ if (remaining.length === 0) {
15645
+ const baseFailures = baseChecks.filter((c) => !c.ok).length;
15646
+ if (baseFailures > 0) {
15647
+ console.log(` ${baseFailures} check(s) failing.`);
15359
15648
  process.exit(1);
15360
15649
  }
15361
- const message = err instanceof Error ? err.message : String(err);
15362
- console.error("");
15363
- console.error(
15364
- ` Couldn't reach Bamboo to save your changes.
15365
- Next: check your connection and run \`bamboo-agents save\` again. (${message})`
15366
- );
15367
- process.exit(1);
15650
+ console.log(" All checks passing.");
15651
+ return;
15368
15652
  }
15369
- let branch = "main";
15370
- try {
15371
- branch = await currentBranch(workspacePath);
15372
- await gitC(workspacePath, ["fetch", "origin", branch]);
15373
- await gitC(workspacePath, ["reset", "--hard", `origin/${branch}`]);
15374
- } catch {
15375
- console.warn(
15376
- " (Saved, but couldn't refresh your local copy just now \u2014 it'll catch up on your next command.)"
15377
- );
15653
+ console.log(` ${remaining.length} drift issue(s) detected \u2014 let's fix them.`);
15654
+ let cur = state;
15655
+ const order = [
15656
+ "stale_state",
15657
+ "wrong_state",
15658
+ "multi_clone",
15659
+ "missing_adapters",
15660
+ "stale_sync"
15661
+ ];
15662
+ for (const kind of order) {
15663
+ const f = remaining.find((r) => r.kind === kind);
15664
+ if (!f) continue;
15665
+ switch (kind) {
15666
+ case "stale_state":
15667
+ cur = await healStaleState(f, cur, opts);
15668
+ break;
15669
+ case "multi_clone":
15670
+ cur = await healMultiClone(f, cur, opts);
15671
+ break;
15672
+ case "wrong_state":
15673
+ cur = await healWrongState(f, cur, opts);
15674
+ break;
15675
+ case "missing_adapters":
15676
+ cur = await healMissingAdapters(f, cur, opts);
15677
+ break;
15678
+ case "stale_sync":
15679
+ cur = await healStaleSync(f, cur, opts);
15680
+ break;
15681
+ }
15378
15682
  }
15379
- const total = edits.length;
15380
- const live = result.live_count;
15381
- const queued = result.queued_count;
15683
+ const post = await readState().catch(() => null);
15684
+ const postDrift = post ? await collectDriftFindings(post) : drift;
15685
+ const stillBroken = (postDrift ?? []).filter((d) => !d.ok);
15382
15686
  console.log("");
15383
- const parts = [];
15384
- if (live > 0) parts.push(`${live} live`);
15385
- if (queued > 0) parts.push(`${queued} queued for review`);
15386
- const summary = parts.length > 0 ? ` \u2014 ${parts.join(", ")}` : "";
15387
- console.log(` Saved ${total} file${total === 1 ? "" : "s"}${summary}.`);
15388
- if (queued > 0 && result.pr_url) {
15389
- console.log(` Review: ${result.pr_url}`);
15390
- }
15391
- if (skipped.length > 0) {
15392
- console.log(
15393
- ` (Skipped ${skipped.length} file${skipped.length === 1 ? "" : "s"} outside your context folders.)`
15394
- );
15687
+ if (stillBroken.length === 0) {
15688
+ console.log(" \u2713 Workspace healthy.");
15689
+ return;
15395
15690
  }
15396
- console.log("");
15691
+ console.log(` ${stillBroken.length} issue(s) remain \u2014 re-run \`bamboo-agents doctor\` after addressing.`);
15692
+ process.exit(1);
15397
15693
  }
15398
- var execFileP4, MANAGED_PREFIXES, MANAGED_FILES;
15399
- var init_save2 = __esm({
15400
- "src/commands/save.ts"() {
15694
+ var init_doctor = __esm({
15695
+ "src/commands/doctor.ts"() {
15401
15696
  "use strict";
15402
15697
  init_api();
15698
+ init_git();
15699
+ init_state();
15403
15700
  init_credentials();
15404
- init_workspace();
15405
- execFileP4 = promisify9(execFile9);
15406
- MANAGED_PREFIXES = [
15407
- "brands/",
15408
- "agents/",
15409
- "knowledge/",
15410
- "skills/",
15411
- "instructions/",
15412
- "org/"
15413
- ];
15414
- MANAGED_FILES = ["CLAUDE.md", "AGENTS.md"];
15701
+ init_workspace_health();
15702
+ init_heal_prompt();
15415
15703
  }
15416
15704
  });
15417
15705
 
15418
- // src/commands/sync.ts
15419
- var sync_exports = {};
15420
- __export(sync_exports, {
15421
- runSync: () => runSync
15706
+ // src/commands/update.ts
15707
+ var update_exports = {};
15708
+ __export(update_exports, {
15709
+ runUpdate: () => runUpdate
15422
15710
  });
15423
- import { execFile as execFile10 } from "node:child_process";
15424
- import { promisify as promisify10 } from "node:util";
15425
- async function runSync() {
15711
+ async function bumpLastSync() {
15712
+ try {
15713
+ const state = await readState();
15714
+ if (state) await updateLastSync(/* @__PURE__ */ new Date());
15715
+ } catch (err) {
15716
+ if (err instanceof WorkspaceStateError) return;
15717
+ throw err;
15718
+ }
15719
+ }
15720
+ async function runUpdate(options = {}) {
15721
+ const opts = options;
15426
15722
  let workspacePath;
15427
15723
  try {
15428
15724
  workspacePath = (await resolveWorkspace()).path;
15429
15725
  } catch (err) {
15430
15726
  if (err instanceof NoWorkspaceError) {
15431
- console.error(`bamboo-agents sync: ${err.message}`);
15432
- process.exit(2);
15727
+ emitError({ code: "no_workspace", message: err.message }, opts, 2);
15728
+ return;
15433
15729
  }
15434
15730
  throw err;
15435
15731
  }
15436
- try {
15437
- const { stdout } = await execFileP5(
15438
- "git",
15439
- ["-C", workspacePath, "pull", "--ff-only"],
15440
- { encoding: "utf8" }
15732
+ const { health } = await inspectCloneHealth(workspacePath);
15733
+ if (health === "wrecked") {
15734
+ if (isJsonMode(opts)) {
15735
+ emitError(
15736
+ {
15737
+ code: "wrecked_clone",
15738
+ message: "your local copy has drifted in a way that can't auto-update.",
15739
+ hint: "Run `bamboo-agents update` interactively (or `bamboo-agents init --reset`) to refresh it from scratch."
15740
+ },
15741
+ opts,
15742
+ 1
15743
+ );
15744
+ return;
15745
+ }
15746
+ human("", opts);
15747
+ human(" Your local copy has drifted in a way that can't auto-update.", opts);
15748
+ human(
15749
+ " Your workspace is a cached copy of the cloud \u2014 the safe fix is to refresh it from scratch.",
15750
+ opts
15441
15751
  );
15442
- console.log("");
15443
- console.log(" Synced your workspace with the remote.");
15444
- if (stdout.trim()) {
15445
- console.log(` ${stdout.trim().split("\n").pop()}`);
15752
+ human("", opts);
15753
+ const { runInit: runInit2 } = await Promise.resolve().then(() => (init_init(), init_exports));
15754
+ await runInit2({ reset: true });
15755
+ return;
15756
+ }
15757
+ const unsaved = await countUnsavedManagedEdits(workspacePath);
15758
+ if (unsaved > 0) {
15759
+ human("", opts);
15760
+ human(
15761
+ ` You have ${unsaved} unsaved change${unsaved === 1 ? "" : "s"} \u2014 saving ${unsaved === 1 ? "it" : "them"} first\u2026`,
15762
+ opts
15763
+ );
15764
+ const { runSave: runSave2 } = await Promise.resolve().then(() => (init_save2(), save_exports));
15765
+ if (isJsonMode(opts)) {
15766
+ await runSave2(void 0, { quiet: true, json: false });
15767
+ } else {
15768
+ await runSave2(void 0, opts);
15446
15769
  }
15447
- console.log(` (workspace: ${workspacePath})`);
15448
- console.log("");
15449
- } catch (err) {
15450
- const e = err;
15451
- console.error("bamboo-agents sync: git failed.");
15452
- if (e.stderr?.trim()) console.error(e.stderr.trim());
15453
- else console.error(e.message);
15454
- process.exit(1);
15455
15770
  }
15456
15771
  try {
15457
- const state = await readState();
15458
- if (state) await updateLastSync(/* @__PURE__ */ new Date());
15459
- } catch (err) {
15460
- if (err instanceof WorkspaceStateError) {
15461
- return;
15462
- }
15463
- throw err;
15772
+ await gitPullFFOnly(workspacePath);
15773
+ } catch {
15774
+ emitError(
15775
+ {
15776
+ code: "update_failed",
15777
+ message: "couldn't reach the cloud to update just now.",
15778
+ hint: "Check your connection and run `bamboo-agents update` again. If it keeps failing, run `bamboo-agents doctor`."
15779
+ },
15780
+ opts,
15781
+ 1
15782
+ );
15783
+ return;
15464
15784
  }
15785
+ await bumpLastSync();
15786
+ emitSuccess(
15787
+ { status: "up_to_date", workspace: workspacePath, saved_before_update: unsaved },
15788
+ opts,
15789
+ () => {
15790
+ human("", opts);
15791
+ human(" Your workspace is up to date with the cloud.", opts);
15792
+ human(` (workspace: ${workspacePath})`, opts);
15793
+ human("", opts);
15794
+ }
15795
+ );
15465
15796
  }
15466
- var execFileP5;
15467
- var init_sync = __esm({
15468
- "src/commands/sync.ts"() {
15797
+ var init_update = __esm({
15798
+ "src/commands/update.ts"() {
15469
15799
  "use strict";
15800
+ init_git();
15470
15801
  init_state();
15471
15802
  init_workspace();
15472
- execFileP5 = promisify10(execFile10);
15803
+ init_workspace_status();
15804
+ init_output();
15473
15805
  }
15474
15806
  });
15475
15807
 
@@ -15999,59 +16331,70 @@ __export(knowledge_exports, {
15999
16331
  runKnowledgeSlots: () => runKnowledgeSlots
16000
16332
  });
16001
16333
  import { readFile as readFile6 } from "node:fs/promises";
16002
- async function requireSession3() {
16334
+ async function requireSession3(opts) {
16003
16335
  const creds = await readCredentials();
16004
16336
  if (!creds) {
16005
- console.error("bamboo-agents: not signed in. Run `bamboo-agents login` first.");
16006
- process.exit(1);
16337
+ emitError(
16338
+ {
16339
+ code: "not_signed_in",
16340
+ message: "not signed in.",
16341
+ hint: "Run `bamboo-agents login` first."
16342
+ },
16343
+ opts,
16344
+ 1
16345
+ );
16346
+ throw new Error("unreachable");
16007
16347
  }
16008
16348
  return creds.bamboo_session;
16009
16349
  }
16010
16350
  function padRight2(s, n) {
16011
16351
  return s.length >= n ? s : s + " ".repeat(n - s.length);
16012
16352
  }
16013
- function printHuman(data) {
16014
- console.log("");
16015
- console.log(" Knowledge slots \u2014 where a file belongs in the workspace repo:");
16016
- console.log("");
16353
+ function printHuman(data, opts) {
16354
+ human("", opts);
16355
+ human(" Knowledge slots \u2014 where a file belongs in the workspace repo:", opts);
16356
+ human("", opts);
16017
16357
  const kindW = Math.max(4, ...data.kinds.map((k) => k.kind.length));
16018
16358
  const scopeW = Math.max(5, ...data.kinds.map((k) => k.scope.length));
16019
- console.log(
16020
- ` ${padRight2("KIND", kindW)} ${padRight2("SCOPE", scopeW)} PATH`
16021
- );
16359
+ human(` ${padRight2("KIND", kindW)} ${padRight2("SCOPE", scopeW)} PATH`, opts);
16022
16360
  for (const k of data.kinds) {
16023
16361
  const pinned = k.filename_pinned ? " (filename pinned)" : "";
16024
- console.log(
16025
- ` ${padRight2(k.kind, kindW)} ${padRight2(k.scope, scopeW)} ${k.example_path}${pinned}`
16362
+ human(
16363
+ ` ${padRight2(k.kind, kindW)} ${padRight2(k.scope, scopeW)} ${k.example_path}${pinned}`,
16364
+ opts
16026
16365
  );
16027
16366
  }
16028
- console.log("");
16029
- console.log(` Filename rule: ${data.filename_regex}`);
16030
- console.log("");
16031
- console.log(" Dimensions (tag freshly-written files with these):");
16367
+ human("", opts);
16368
+ human(` Filename rule: ${data.filename_regex}`, opts);
16369
+ human("", opts);
16370
+ human(" Dimensions (tag freshly-written files with these):", opts);
16032
16371
  const keyW = Math.max(3, ...data.dimensions.map((d) => d.key.length));
16033
16372
  for (const d of data.dimensions) {
16034
- console.log(` ${padRight2(d.key, keyW)} ${d.label} [${d.tags.join(", ")}]`);
16373
+ human(` ${padRight2(d.key, keyW)} ${d.label} [${d.tags.join(", ")}]`, opts);
16035
16374
  }
16036
- console.log("");
16037
- console.log(" Substitute {brand} / {agent} with your workspace slugs, then write");
16038
- console.log(" the file natively and push a branch \u2014 routeWrite merges or queues it.");
16039
- console.log("");
16375
+ human("", opts);
16376
+ human(" Substitute {brand} / {agent} with your workspace slugs, then write", opts);
16377
+ human(" the file natively and push a branch \u2014 routeWrite merges or queues it.", opts);
16378
+ human("", opts);
16040
16379
  }
16041
16380
  async function runKnowledgeSlots(options) {
16042
- const session = await requireSession3();
16381
+ const opts = options;
16382
+ const session = await requireSession3(opts);
16043
16383
  let data;
16044
16384
  try {
16045
16385
  data = await getKnowledgeSlots(session);
16046
16386
  } catch (err) {
16047
- console.error(`bamboo-agents: couldn't load knowledge slots: ${err.message}`);
16048
- process.exit(1);
16049
- }
16050
- if (options.json) {
16051
- console.log(JSON.stringify(data, null, 2));
16387
+ emitError(
16388
+ {
16389
+ code: "knowledge_slots_failed",
16390
+ message: `couldn't load knowledge slots: ${err.message}`
16391
+ },
16392
+ opts,
16393
+ 1
16394
+ );
16052
16395
  return;
16053
16396
  }
16054
- printHuman(data);
16397
+ emitSuccess(data, opts, (d) => printHuman(d, opts));
16055
16398
  }
16056
16399
  async function resolveContent(options) {
16057
16400
  if (options.contentFile) {
@@ -16069,20 +16412,52 @@ async function resolveContent(options) {
16069
16412
  }
16070
16413
  return "";
16071
16414
  }
16415
+ function printSaveResult(result, path2, opts) {
16416
+ switch (result.routed) {
16417
+ case "auto":
16418
+ human(` \u2713 Saved \u2014 auto-merged to main (${path2})`, opts);
16419
+ break;
16420
+ case "queued":
16421
+ case "submitted":
16422
+ human(
16423
+ ` \u2713 Queued for review (${path2})` + (result.pr_url ? `
16424
+ ${result.pr_url}` : ""),
16425
+ opts
16426
+ );
16427
+ break;
16428
+ case "noop":
16429
+ human(` \u2022 Nothing to do${result.reason ? ` (${result.reason})` : ""}.`, opts);
16430
+ break;
16431
+ }
16432
+ }
16072
16433
  async function runKnowledgeSave(options) {
16073
- const session = await requireSession3();
16434
+ const opts = options;
16435
+ const session = await requireSession3(opts);
16074
16436
  if (!options.path) {
16075
- console.error("bamboo-agents: knowledge save requires --path.");
16076
- console.error("Tip: run `bamboo-agents knowledge slots` to find the right path.");
16077
- process.exit(1);
16437
+ emitError(
16438
+ {
16439
+ code: "missing_path",
16440
+ message: "knowledge save requires --path.",
16441
+ hint: "Run `bamboo-agents knowledge slots` to find the right path."
16442
+ },
16443
+ opts,
16444
+ 1
16445
+ );
16446
+ return;
16078
16447
  }
16079
16448
  const isDelete = options.delete === true;
16080
16449
  const content = isDelete ? "" : await resolveContent(options);
16081
16450
  if (!isDelete && content.length === 0) {
16082
- console.error(
16083
- "bamboo-agents: no content. Pass --content, --content-file <path>, or pipe via stdin."
16451
+ emitError(
16452
+ {
16453
+ code: "missing_content",
16454
+ message: "no content.",
16455
+ hint: "Pass --content, --content-file <path>, or pipe via stdin."
16456
+ },
16457
+ opts,
16458
+ 1
16084
16459
  );
16085
- process.exit(1);
16460
+ return;
16086
16461
  }
16087
16462
  let result;
16088
16463
  try {
@@ -16093,37 +16468,33 @@ async function runKnowledgeSave(options) {
16093
16468
  intent: options.intent
16094
16469
  });
16095
16470
  } catch (err) {
16096
- console.error(`bamboo-agents: save failed: ${err.message}`);
16097
- process.exit(1);
16098
- }
16099
- if (options.json) {
16100
- console.log(JSON.stringify(result, null, 2));
16471
+ emitError(
16472
+ { code: "save_failed", message: `save failed: ${err.message}` },
16473
+ opts,
16474
+ 1
16475
+ );
16101
16476
  return;
16102
16477
  }
16103
- switch (result.routed) {
16104
- case "auto":
16105
- console.log(` \u2713 Saved \u2014 auto-merged to main (${options.path})`);
16106
- break;
16107
- case "queued":
16108
- case "submitted":
16109
- console.log(
16110
- ` \u2713 Queued for review (${options.path})` + (result.pr_url ? `
16111
- ${result.pr_url}` : "")
16112
- );
16113
- break;
16114
- case "noop":
16115
- console.log(` \u2022 Nothing to do${result.reason ? ` (${result.reason})` : ""}.`);
16116
- break;
16117
- case "rejected":
16118
- console.error(` \u2717 Rejected${result.reason ? `: ${result.reason}` : ""}.`);
16119
- process.exit(1);
16478
+ if (result.routed === "rejected") {
16479
+ emitError(
16480
+ {
16481
+ code: "rejected",
16482
+ message: `save rejected${result.reason ? `: ${result.reason}` : "."}`,
16483
+ hint: "Check the path scope and your permissions."
16484
+ },
16485
+ opts,
16486
+ 1
16487
+ );
16488
+ return;
16120
16489
  }
16490
+ emitSuccess(result, opts, (r) => printSaveResult(r, options.path, opts));
16121
16491
  }
16122
16492
  var init_knowledge = __esm({
16123
16493
  "src/commands/knowledge.ts"() {
16124
16494
  "use strict";
16125
16495
  init_credentials();
16126
16496
  init_api();
16497
+ init_output();
16127
16498
  }
16128
16499
  });
16129
16500
 
@@ -16133,11 +16504,19 @@ __export(history_exports2, {
16133
16504
  runChanges: () => runChanges,
16134
16505
  runHistory: () => runHistory
16135
16506
  });
16136
- async function requireSession4() {
16507
+ async function requireSession4(opts) {
16137
16508
  const creds = await readCredentials();
16138
16509
  if (!creds) {
16139
- console.error("bamboo-agents: not signed in. Run `bamboo-agents login` first.");
16140
- process.exit(1);
16510
+ emitError(
16511
+ {
16512
+ code: "not_signed_in",
16513
+ message: "not signed in.",
16514
+ hint: "Run `bamboo-agents login` first."
16515
+ },
16516
+ opts,
16517
+ 1
16518
+ );
16519
+ throw new Error("unreachable");
16141
16520
  }
16142
16521
  return creds.bamboo_session;
16143
16522
  }
@@ -16149,48 +16528,51 @@ function parseLimit(raw) {
16149
16528
  function padRight3(s, n) {
16150
16529
  return s.length >= n ? s : s + " ".repeat(n - s.length);
16151
16530
  }
16152
- function printHistory(data) {
16531
+ function printHistory(data, opts) {
16153
16532
  if (data.entries.length === 0) {
16154
- console.log(" No recent actions.");
16533
+ human(" No recent actions.", opts);
16155
16534
  return;
16156
16535
  }
16157
16536
  const nameW = Math.max(4, ...data.entries.map((e) => (e.tool_name ?? "\u2014").length));
16158
16537
  for (const e of data.entries) {
16159
16538
  const dur = e.duration_ms != null ? `${e.duration_ms}ms` : "";
16160
- console.log(
16161
- ` ${padRight3(e.tool_name ?? "\u2014", nameW)} ${padRight3(e.status, 10)} ${e.timestamp} ${dur}`
16539
+ human(
16540
+ ` ${padRight3(e.tool_name ?? "\u2014", nameW)} ${padRight3(e.status, 10)} ${e.timestamp} ${dur}`,
16541
+ opts
16162
16542
  );
16163
16543
  }
16164
- console.log(` ${data.count} action${data.count === 1 ? "" : "s"}.`);
16544
+ human(` ${data.count} action${data.count === 1 ? "" : "s"}.`, opts);
16165
16545
  }
16166
16546
  async function runHistory(options) {
16167
- const session = await requireSession4();
16547
+ const opts = options;
16548
+ const session = await requireSession4(opts);
16168
16549
  let data;
16169
16550
  try {
16170
16551
  data = await getHistory(session, { limit: parseLimit(options.limit) });
16171
16552
  } catch (err) {
16172
- console.error(`bamboo-agents: couldn't load history: ${err.message}`);
16173
- process.exit(1);
16174
- }
16175
- if (options.json) {
16176
- console.log(JSON.stringify(data, null, 2));
16553
+ emitError(
16554
+ { code: "history_failed", message: `couldn't load history: ${err.message}` },
16555
+ opts,
16556
+ 1
16557
+ );
16177
16558
  return;
16178
16559
  }
16179
- printHistory(data);
16560
+ emitSuccess(data, opts, (d) => printHistory(d, opts));
16180
16561
  }
16181
- function printChanges(data) {
16562
+ function printChanges(data, opts) {
16182
16563
  if (data.entries.length === 0) {
16183
- console.log(" No changes.");
16564
+ human(" No changes.", opts);
16184
16565
  return;
16185
16566
  }
16186
16567
  for (const e of data.entries) {
16187
16568
  const what = [e.action, e.entity_type, e.entity_name].filter(Boolean).join(" ");
16188
- console.log(` ${e.timestamp} ${what || e.tool_name || "\u2014"}`);
16569
+ human(` ${e.timestamp} ${what || e.tool_name || "\u2014"}`, opts);
16189
16570
  }
16190
- console.log(` ${data.count} change${data.count === 1 ? "" : "s"}.`);
16571
+ human(` ${data.count} change${data.count === 1 ? "" : "s"}.`, opts);
16191
16572
  }
16192
16573
  async function runChanges(options) {
16193
- const session = await requireSession4();
16574
+ const opts = options;
16575
+ const session = await requireSession4(opts);
16194
16576
  let data;
16195
16577
  try {
16196
16578
  data = await getChanges(session, {
@@ -16200,20 +16582,21 @@ async function runChanges(options) {
16200
16582
  entityType: options.entityType
16201
16583
  });
16202
16584
  } catch (err) {
16203
- console.error(`bamboo-agents: couldn't load changes: ${err.message}`);
16204
- process.exit(1);
16205
- }
16206
- if (options.json) {
16207
- console.log(JSON.stringify(data, null, 2));
16585
+ emitError(
16586
+ { code: "changes_failed", message: `couldn't load changes: ${err.message}` },
16587
+ opts,
16588
+ 1
16589
+ );
16208
16590
  return;
16209
16591
  }
16210
- printChanges(data);
16592
+ emitSuccess(data, opts, (d) => printChanges(d, opts));
16211
16593
  }
16212
16594
  var init_history2 = __esm({
16213
16595
  "src/commands/history.ts"() {
16214
16596
  "use strict";
16215
16597
  init_credentials();
16216
16598
  init_api();
16599
+ init_output();
16217
16600
  }
16218
16601
  });
16219
16602
 
@@ -16222,42 +16605,62 @@ var context_exports = {};
16222
16605
  __export(context_exports, {
16223
16606
  runContextHealth: () => runContextHealth
16224
16607
  });
16225
- async function requireSession5() {
16608
+ async function requireSession5(opts) {
16226
16609
  const creds = await readCredentials();
16227
16610
  if (!creds) {
16228
- console.error("bamboo-agents: not signed in. Run `bamboo-agents login` first.");
16229
- process.exit(1);
16611
+ emitError(
16612
+ {
16613
+ code: "not_signed_in",
16614
+ message: "not signed in.",
16615
+ hint: "Run `bamboo-agents login` first."
16616
+ },
16617
+ opts,
16618
+ 1
16619
+ );
16620
+ throw new Error("unreachable");
16230
16621
  }
16231
16622
  return creds.bamboo_session;
16232
16623
  }
16233
16624
  function gradeSymbol(grade) {
16234
16625
  return grade === "A" ? "\u2713" : grade === "B" || grade === "C" ? "\u2022" : "\u2717";
16235
16626
  }
16236
- function printHealth(data) {
16627
+ function printHealth(data, opts) {
16237
16628
  const { grade, score, gaps, bucketScores, scope } = data;
16238
16629
  const scopeLabel = scope.kind === "agent" ? `agent (${scope.agentId ?? "\u2014"})` : scope.kind === "brand" ? `brand (${scope.brandId ?? "\u2014"})` : "org";
16239
- console.log("");
16240
- console.log(
16241
- ` Context health [${scopeLabel}]: ${gradeSymbol(grade)} ${grade} (score ${Math.round(score)}/100)`
16630
+ human("", opts);
16631
+ human(
16632
+ ` Context health [${scopeLabel}]: ${gradeSymbol(grade)} ${grade} (score ${Math.round(score)}/100)`,
16633
+ opts
16242
16634
  );
16243
16635
  const fmtBucket = (label, v) => ` ${label.padEnd(12)} ${v != null ? `${Math.round(v)}/100` : "n/a"}`;
16244
- console.log(fmtBucket("inherited:", bucketScores.inherited));
16245
- console.log(fmtBucket("structural:", bucketScores.structural));
16246
- console.log(fmtBucket("job_spec:", bucketScores.job_spec));
16247
- console.log("");
16636
+ human(fmtBucket("inherited:", bucketScores.inherited), opts);
16637
+ human(fmtBucket("structural:", bucketScores.structural), opts);
16638
+ human(fmtBucket("job_spec:", bucketScores.job_spec), opts);
16639
+ human("", opts);
16248
16640
  if (gaps.empty.length > 0) {
16249
- console.log(` Missing (empty): ${gaps.empty.join(", ")}`);
16641
+ human(` Missing (empty): ${gaps.empty.join(", ")}`, opts);
16250
16642
  }
16251
16643
  if (gaps.basic.length > 0) {
16252
- console.log(` Sparse (basic): ${gaps.basic.join(", ")}`);
16644
+ human(` Sparse (basic): ${gaps.basic.join(", ")}`, opts);
16253
16645
  }
16254
16646
  if (gaps.empty.length === 0 && gaps.basic.length === 0) {
16255
- console.log(" No gaps \u2014 all criteria at good or deep.");
16647
+ human(" No gaps \u2014 all criteria at good or deep.", opts);
16256
16648
  }
16257
- console.log("");
16649
+ human("", opts);
16650
+ }
16651
+ function printHealthResponse(data, opts) {
16652
+ if (!data.available) {
16653
+ human("", opts);
16654
+ human(" Context health is unavailable right now.", opts);
16655
+ human(` (${data.reason})`, opts);
16656
+ human("", opts);
16657
+ return;
16658
+ }
16659
+ printHealth(data, opts);
16258
16660
  }
16259
16661
  async function runContextHealth(options) {
16260
- const session = await requireSession5();
16662
+ const opts = options;
16663
+ const session = await requireSession5(opts);
16261
16664
  let data;
16262
16665
  try {
16263
16666
  data = await getContextHealth(session, {
@@ -16265,27 +16668,24 @@ async function runContextHealth(options) {
16265
16668
  agentId: options.agent
16266
16669
  });
16267
16670
  } catch (err) {
16268
- console.error(`bamboo-agents: couldn't load context health: ${err.message}`);
16269
- process.exit(1);
16270
- }
16271
- if (options.json) {
16272
- console.log(JSON.stringify(data, null, 2));
16273
- return;
16274
- }
16275
- if (!data.available) {
16276
- console.log("");
16277
- console.log(" Context health is unavailable right now.");
16278
- console.log(` (${data.reason})`);
16279
- console.log("");
16671
+ emitError(
16672
+ {
16673
+ code: "context_health_failed",
16674
+ message: `couldn't load context health: ${err.message}`
16675
+ },
16676
+ opts,
16677
+ 1
16678
+ );
16280
16679
  return;
16281
16680
  }
16282
- printHealth(data);
16681
+ emitSuccess(data, opts, (d) => printHealthResponse(d, opts));
16283
16682
  }
16284
16683
  var init_context = __esm({
16285
16684
  "src/commands/context.ts"() {
16286
16685
  "use strict";
16287
16686
  init_credentials();
16288
16687
  init_api();
16688
+ init_output();
16289
16689
  }
16290
16690
  });
16291
16691
 
@@ -16294,44 +16694,58 @@ var onboarding_exports = {};
16294
16694
  __export(onboarding_exports, {
16295
16695
  runOnboardingStatus: () => runOnboardingStatus
16296
16696
  });
16297
- async function requireSession6() {
16697
+ async function requireSession6(opts) {
16298
16698
  const creds = await readCredentials();
16299
16699
  if (!creds) {
16300
- console.error("bamboo-agents: not signed in. Run `bamboo-agents login` first.");
16301
- process.exit(1);
16700
+ emitError(
16701
+ {
16702
+ code: "not_signed_in",
16703
+ message: "not signed in.",
16704
+ hint: "Run `bamboo-agents login` first."
16705
+ },
16706
+ opts,
16707
+ 1
16708
+ );
16709
+ throw new Error("unreachable");
16302
16710
  }
16303
16711
  return creds.bamboo_session;
16304
16712
  }
16305
- function printStatus(data) {
16713
+ function printStatus(data, opts) {
16306
16714
  const g = data.composite_gate;
16307
- console.log("");
16308
- console.log(` Onboarding: ${g.passed ? "\u2713 complete" : "\u2022 in progress"}`);
16309
- console.log(
16310
- ` knowledge: ${g.knowledge_ok ? "ok" : "needs work"} (grade ${data.health.grade ?? "\u2014"}, score ${data.health.score ?? "\u2014"})`
16715
+ human("", opts);
16716
+ human(` Onboarding: ${g.passed ? "\u2713 complete" : "\u2022 in progress"}`, opts);
16717
+ human(
16718
+ ` knowledge: ${g.knowledge_ok ? "ok" : "needs work"} (grade ${data.health.grade ?? "\u2014"}, score ${data.health.score ?? "\u2014"})`,
16719
+ opts
16311
16720
  );
16312
- console.log(` activation: ${g.activation_ok ? "ok" : "incomplete"}`);
16313
- console.log("");
16721
+ human(` activation: ${g.activation_ok ? "ok" : "incomplete"}`, opts);
16722
+ human("", opts);
16314
16723
  }
16315
16724
  async function runOnboardingStatus(options) {
16316
- const session = await requireSession6();
16725
+ const opts = options;
16726
+ const session = await requireSession6(opts);
16317
16727
  let data;
16318
16728
  try {
16319
16729
  data = await getOnboardingStatus(session, { brandId: options.brand });
16320
16730
  } catch (err) {
16321
- console.error(`bamboo-agents: couldn't load onboarding status: ${err.message}`);
16322
- process.exit(1);
16323
- }
16324
- if (options.json) {
16325
- console.log(JSON.stringify(data, null, 2));
16731
+ emitError(
16732
+ {
16733
+ code: "onboarding_status_failed",
16734
+ message: `couldn't load onboarding status: ${err.message}`
16735
+ },
16736
+ opts,
16737
+ 1
16738
+ );
16326
16739
  return;
16327
16740
  }
16328
- printStatus(data);
16741
+ emitSuccess(data, opts, (d) => printStatus(d, opts));
16329
16742
  }
16330
16743
  var init_onboarding = __esm({
16331
16744
  "src/commands/onboarding.ts"() {
16332
16745
  "use strict";
16333
16746
  init_credentials();
16334
16747
  init_api();
16748
+ init_output();
16335
16749
  }
16336
16750
  });
16337
16751
 
@@ -16356,6 +16770,35 @@ var {
16356
16770
  init_version();
16357
16771
 
16358
16772
  // src/lib/describe.ts
16773
+ var ENVELOPE = {
16774
+ success: {
16775
+ type: "object",
16776
+ properties: {
16777
+ ok: { const: true },
16778
+ data: {
16779
+ description: "The command's payload \u2014 its shape is the per-command `output_schema`."
16780
+ }
16781
+ },
16782
+ required: ["ok", "data"]
16783
+ },
16784
+ error: {
16785
+ type: "object",
16786
+ properties: {
16787
+ ok: { const: false },
16788
+ error: {
16789
+ type: "object",
16790
+ properties: {
16791
+ code: { type: "string" },
16792
+ message: { type: "string" },
16793
+ hint: { type: "string" }
16794
+ },
16795
+ required: ["code", "message"]
16796
+ }
16797
+ },
16798
+ required: ["ok", "error"]
16799
+ },
16800
+ note: "Every --json (or piped) response is wrapped in this envelope. On success, `data` matches the command's `output_schema`. On failure, `error.code` is a stable string an agent can branch on. stdout carries only the envelope; human/diagnostic text goes to stderr."
16801
+ };
16359
16802
  function zodToJsonSchema(schema) {
16360
16803
  const s = schema;
16361
16804
  const typeName = s?._def?.typeName ?? "";
@@ -16486,9 +16929,10 @@ async function buildManifest(program3, cliVersion) {
16486
16929
  output_schema: outputSchemas.get(fullName) ?? null
16487
16930
  }));
16488
16931
  return {
16489
- version: 1,
16932
+ version: 2,
16490
16933
  cli: program3.name(),
16491
16934
  cli_version: cliVersion,
16935
+ envelope: ENVELOPE,
16492
16936
  commands
16493
16937
  };
16494
16938
  }
@@ -16530,21 +16974,23 @@ program2.command("open").description("Launch Claude Code at your workspace").opt
16530
16974
  const { runOpen: runOpen2 } = await Promise.resolve().then(() => (init_open2(), open_exports));
16531
16975
  await runOpen2();
16532
16976
  });
16533
- program2.command("status").description("Show current Bamboo CLI state").option("--no-sync", "Skip the auto-sync git pull on this command").action(async () => {
16977
+ program2.command("status").description("Show current Bamboo CLI state").option("--no-sync", "Skip the auto-sync git pull on this command").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)").action(async (options) => {
16534
16978
  const { runStatus: runStatus2 } = await Promise.resolve().then(() => (init_status(), status_exports));
16535
- await runStatus2();
16979
+ await runStatus2(options);
16536
16980
  });
16537
16981
  program2.command("doctor").description("Verify your local setup is ready + heal workspace drift").option("--quiet", "Emit JSON without prompting (CI / scripts)").option("--auto-heal", "Apply non-destructive fixes silently").action(async (options) => {
16538
16982
  const { runDoctor: runDoctor2 } = await Promise.resolve().then(() => (init_doctor(), doctor_exports));
16539
16983
  await runDoctor2({ quiet: options.quiet, autoHeal: options.autoHeal });
16540
16984
  });
16541
- program2.command("save [intent]").description("Save your workspace changes (routed write \u2014 auto-merges or queues)").option("--no-sync", "Skip the auto-sync git pull on this command").action(async (intent) => {
16542
- const { runSave: runSave2 } = await Promise.resolve().then(() => (init_save2(), save_exports));
16543
- await runSave2(intent);
16544
- });
16545
- program2.command("sync").description("Pull your workspace clone up to remote (cwd-agnostic)").action(async () => {
16546
- const { runSync: runSync2 } = await Promise.resolve().then(() => (init_sync(), sync_exports));
16547
- await runSync2();
16985
+ program2.command("save [intent]").description("Save your workspace changes (routed write \u2014 auto-merges or queues)").option("--no-sync", "Skip the auto-sync git pull on this command").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)").action(
16986
+ async (intent, options) => {
16987
+ const { runSave: runSave2 } = await Promise.resolve().then(() => (init_save2(), save_exports));
16988
+ await runSave2(intent, options);
16989
+ }
16990
+ );
16991
+ program2.command("update").alias("sync").description("Update your workspace from the cloud (saves unsaved edits first, then pulls)").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)").action(async (options) => {
16992
+ const { runUpdate: runUpdate2 } = await Promise.resolve().then(() => (init_update(), update_exports));
16993
+ await runUpdate2(options);
16548
16994
  });
16549
16995
  var skills = program2.command("skills").description("Read workspace skills from your local clone");
16550
16996
  skills.command("list").description("List every skill in the workspace").option(
@@ -16577,31 +17023,31 @@ skills.command("update <agent> <skill-name>").description("Update an installed s
16577
17023
  await runSkillsUpdate2(agent, skillName);
16578
17024
  });
16579
17025
  var knowledge = program2.command("knowledge").description("Knowledge surface for CLI-first skills");
16580
- knowledge.command("slots").description("Print the knowledge slot schema (kind \xD7 scope \u2192 path) + dimensions").option("--json", "Emit raw JSON for agent consumption").option("--no-sync", "Skip the auto-sync git pull on this command").action(async (options) => {
17026
+ knowledge.command("slots").description("Print the knowledge slot schema (kind \xD7 scope \u2192 path) + dimensions").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) => {
16581
17027
  const { runKnowledgeSlots: runKnowledgeSlots2 } = await Promise.resolve().then(() => (init_knowledge(), knowledge_exports));
16582
17028
  await runKnowledgeSlots2(options);
16583
17029
  });
16584
- knowledge.command("save").description("Save a knowledge file (routed write \u2014 auto-merges or queues)").requiredOption("--path <path>", "Repo path (from `knowledge slots`), e.g. brands/acme/knowledge/competitors.md").option("--content <text>", "Inline file content").option("--content-file <file>", "Read file content from a local path").option("--delete", "Delete the file instead of writing content").option("--intent <text>", "Human-readable summary for the PR body").option("--json", "Emit raw JSON for agent consumption").option("--no-sync", "Skip the auto-sync git pull on this command").action(async (options) => {
17030
+ knowledge.command("save").description("Save a knowledge file (routed write \u2014 auto-merges or queues)").requiredOption("--path <path>", "Repo path (from `knowledge slots`), e.g. brands/acme/knowledge/competitors.md").option("--content <text>", "Inline file content").option("--content-file <file>", "Read file content from a local path").option("--delete", "Delete the file instead of writing content").option("--intent <text>", "Human-readable summary for the PR body").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) => {
16585
17031
  const { runKnowledgeSave: runKnowledgeSave2 } = await Promise.resolve().then(() => (init_knowledge(), knowledge_exports));
16586
17032
  await runKnowledgeSave2(options);
16587
17033
  });
16588
- program2.command("history").description("Recent workspace actions (reverse-chronological)").option("--limit <n>", "Max entries (default 20, max 100)").option("--json", "Emit raw JSON for agent consumption").option("--no-sync", "Skip the auto-sync git pull on this command").action(async (options) => {
17034
+ program2.command("history").description("Recent workspace actions (reverse-chronological)").option("--limit <n>", "Max entries (default 20, max 100)").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) => {
16589
17035
  const { runHistory: runHistory2 } = await Promise.resolve().then(() => (init_history2(), history_exports2));
16590
17036
  await runHistory2(options);
16591
17037
  });
16592
- program2.command("changes").description("Structured change log \u2014 what was created/updated/deleted").option("--limit <n>", "Max entries (default 20, max 100)").option("--brand <id>", "Filter to one brand_id").option("--since <iso>", "Only changes at/after this ISO timestamp").option("--entity-type <type>", "Filter by entity type").option("--json", "Emit raw JSON for agent consumption").option("--no-sync", "Skip the auto-sync git pull on this command").action(
17038
+ program2.command("changes").description("Structured change log \u2014 what was created/updated/deleted").option("--limit <n>", "Max entries (default 20, max 100)").option("--brand <id>", "Filter to one brand_id").option("--since <iso>", "Only changes at/after this ISO timestamp").option("--entity-type <type>", "Filter by entity type").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(
16593
17039
  async (options) => {
16594
17040
  const { runChanges: runChanges2 } = await Promise.resolve().then(() => (init_history2(), history_exports2));
16595
17041
  await runChanges2(options);
16596
17042
  }
16597
17043
  );
16598
17044
  var context = program2.command("context").description("Context health for CLI-first skills");
16599
- context.command("health").description("Knowledge/context health \u2014 grade, score, and gaps").option("--brand <id>", "Scope to a brand_id (default: org)").option("--agent <id>", "Scope to an agent_id").option("--json", "Emit raw JSON for agent consumption").option("--no-sync", "Skip the auto-sync git pull on this command").action(async (options) => {
17045
+ context.command("health").description("Knowledge/context health \u2014 grade, score, and gaps").option("--brand <id>", "Scope to a brand_id (default: org)").option("--agent <id>", "Scope to an agent_id").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) => {
16600
17046
  const { runContextHealth: runContextHealth2 } = await Promise.resolve().then(() => (init_context(), context_exports));
16601
17047
  await runContextHealth2(options);
16602
17048
  });
16603
17049
  var onboarding = program2.command("onboarding").description("Onboarding status for CLI-first skills");
16604
- onboarding.command("status").description("Composite onboarding gate (activation milestones + knowledge health)").option("--brand <id>", "Scope to a brand_id (default: org)").option("--json", "Emit raw JSON for agent consumption").option("--no-sync", "Skip the auto-sync git pull on this command").action(async (options) => {
17050
+ onboarding.command("status").description("Composite onboarding gate (activation milestones + knowledge health)").option("--brand <id>", "Scope to a brand_id (default: org)").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) => {
16605
17051
  const { runOnboardingStatus: runOnboardingStatus2 } = await Promise.resolve().then(() => (init_onboarding(), onboarding_exports));
16606
17052
  await runOnboardingStatus2(options);
16607
17053
  });