bamboo-agents 0.1.5-dev.46.a33345f → 0.1.5-dev.48.0e1a6eb

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.46.a33345f";
3040
+ VERSION = "0.1.5-dev.48.0e1a6eb";
3041
3041
  }
3042
3042
  });
3043
3043
 
@@ -12187,7 +12187,7 @@ var init_save = __esm({
12187
12187
  });
12188
12188
 
12189
12189
  // ../../src/lib/api-contracts/cli/context-health.ts
12190
- var ScopeKindSchema, ScopeSchema, CriterionMetricsSchema, StatusSchema, CriterionContributionSchema, CriterionResultSchema, BucketScoresSchema, ResolvedScopeSchema, GapsSchema, ContextHealthResponseSchema;
12190
+ var ScopeKindSchema, ScopeSchema, CriterionMetricsSchema, StatusSchema, CriterionContributionSchema, CriterionResultSchema, BucketScoresSchema, ResolvedScopeSchema, GapsSchema, HealthyResponseSchema, UnavailableResponseSchema, ContextHealthResponseSchema;
12191
12191
  var init_context_health = __esm({
12192
12192
  "../../src/lib/api-contracts/cli/context-health.ts"() {
12193
12193
  init_zod();
@@ -12239,7 +12239,8 @@ var init_context_health = __esm({
12239
12239
  /** Criterion keys that are at "basic" status (partially filled). */
12240
12240
  basic: external_exports.array(external_exports.string())
12241
12241
  });
12242
- ContextHealthResponseSchema = external_exports.object({
12242
+ HealthyResponseSchema = external_exports.object({
12243
+ available: external_exports.literal(true),
12243
12244
  scope: ScopeSchema,
12244
12245
  grade: external_exports.enum(["A", "B", "C", "D", "F"]),
12245
12246
  score: external_exports.number(),
@@ -12250,6 +12251,15 @@ var init_context_health = __esm({
12250
12251
  * don't need to iterate the full results array. */
12251
12252
  gaps: GapsSchema
12252
12253
  });
12254
+ UnavailableResponseSchema = external_exports.object({
12255
+ available: external_exports.literal(false),
12256
+ /** Short, human-readable reason health is unavailable. */
12257
+ reason: external_exports.string()
12258
+ });
12259
+ ContextHealthResponseSchema = external_exports.discriminatedUnion("available", [
12260
+ HealthyResponseSchema,
12261
+ UnavailableResponseSchema
12262
+ ]);
12253
12263
  }
12254
12264
  });
12255
12265
 
@@ -14376,11 +14386,338 @@ var init_open2 = __esm({
14376
14386
  }
14377
14387
  });
14378
14388
 
14389
+ // src/commands/save.ts
14390
+ var save_exports = {};
14391
+ __export(save_exports, {
14392
+ isDeletion: () => isDeletion,
14393
+ isManagedPath: () => isManagedPath,
14394
+ parsePorcelain: () => parsePorcelain,
14395
+ planBatchFromPorcelain: () => planBatchFromPorcelain,
14396
+ reconcilePlan: () => reconcilePlan,
14397
+ runSave: () => runSave
14398
+ });
14399
+ import { execFile as execFile8 } from "node:child_process";
14400
+ import { readFile as readFile4, rm as rm2 } from "node:fs/promises";
14401
+ import { join as join2 } from "node:path";
14402
+ import { promisify as promisify8 } from "node:util";
14403
+ function parsePorcelain(out) {
14404
+ if (!out) return [];
14405
+ const fields = out.split("\0");
14406
+ const entries = [];
14407
+ for (let i = 0; i < fields.length; i++) {
14408
+ const field = fields[i];
14409
+ if (!field) continue;
14410
+ const status = field.slice(0, 2);
14411
+ const path2 = field.slice(3);
14412
+ if (!path2) continue;
14413
+ entries.push({ status, path: path2 });
14414
+ if (status[0] === "R" || status[0] === "C") {
14415
+ i++;
14416
+ }
14417
+ }
14418
+ return entries;
14419
+ }
14420
+ function isManagedPath(path2) {
14421
+ if (MANAGED_FILES.includes(path2)) return true;
14422
+ return MANAGED_PREFIXES.some((p) => path2.startsWith(p));
14423
+ }
14424
+ function isDeletion(entry) {
14425
+ return entry.status[0] === "D" || entry.status[1] === "D";
14426
+ }
14427
+ function planBatchFromPorcelain(entries) {
14428
+ const deletes = [];
14429
+ const writes = [];
14430
+ const skipped = [];
14431
+ const seen = /* @__PURE__ */ new Set();
14432
+ for (const entry of entries) {
14433
+ if (seen.has(entry.path)) continue;
14434
+ seen.add(entry.path);
14435
+ if (!isManagedPath(entry.path)) {
14436
+ skipped.push(entry.path);
14437
+ continue;
14438
+ }
14439
+ if (isDeletion(entry)) {
14440
+ deletes.push(entry.path);
14441
+ } else {
14442
+ writes.push(entry.path);
14443
+ }
14444
+ }
14445
+ return { deletes, writes, skipped };
14446
+ }
14447
+ function reconcilePlan(files, deletePaths) {
14448
+ const deleteSet = new Set(deletePaths);
14449
+ const checkout = [];
14450
+ const remove = [];
14451
+ const seen = /* @__PURE__ */ new Set();
14452
+ for (const f of files) {
14453
+ if (f.routed !== "auto") continue;
14454
+ if (!f.path || seen.has(f.path)) continue;
14455
+ seen.add(f.path);
14456
+ if (deleteSet.has(f.path)) remove.push(f.path);
14457
+ else checkout.push(f.path);
14458
+ }
14459
+ return { checkout, remove };
14460
+ }
14461
+ async function gitC(repoPath, args) {
14462
+ const { stdout } = await execFileP3("git", ["-C", repoPath, ...args], {
14463
+ encoding: "utf8",
14464
+ // -z output + file content can exceed the default 1MB buffer.
14465
+ maxBuffer: 32 * 1024 * 1024
14466
+ });
14467
+ return stdout;
14468
+ }
14469
+ async function currentBranch(repoPath) {
14470
+ const out = await gitC(repoPath, ["rev-parse", "--abbrev-ref", "HEAD"]);
14471
+ return out.trim() || "main";
14472
+ }
14473
+ async function requireSession() {
14474
+ const creds = await readCredentials();
14475
+ if (!creds) {
14476
+ console.error(
14477
+ "bamboo-agents save: not signed in. Run `bamboo-agents login` first."
14478
+ );
14479
+ process.exit(1);
14480
+ }
14481
+ return creds.bamboo_session;
14482
+ }
14483
+ async function runSave(intent) {
14484
+ let workspacePath;
14485
+ try {
14486
+ workspacePath = (await resolveWorkspace()).path;
14487
+ } catch (err) {
14488
+ if (err instanceof NoWorkspaceError) {
14489
+ console.error(`bamboo-agents save: ${err.message}`);
14490
+ process.exit(2);
14491
+ }
14492
+ throw err;
14493
+ }
14494
+ const session = await requireSession();
14495
+ let entries;
14496
+ try {
14497
+ const porcelain = await gitC(workspacePath, [
14498
+ "status",
14499
+ "--porcelain=v1",
14500
+ "-z",
14501
+ "-uall"
14502
+ ]);
14503
+ entries = parsePorcelain(porcelain);
14504
+ } catch {
14505
+ console.error(
14506
+ " Couldn't read your workspace changes.\n Next: run `bamboo-agents doctor` to check your workspace is healthy."
14507
+ );
14508
+ process.exit(1);
14509
+ }
14510
+ const { deletes, writes, skipped } = planBatchFromPorcelain(entries);
14511
+ if (deletes.length === 0 && writes.length === 0) {
14512
+ console.log("");
14513
+ if (skipped.length > 0) {
14514
+ console.log(
14515
+ " Nothing to save \u2014 the only changes are outside your context folders."
14516
+ );
14517
+ } else {
14518
+ console.log(" Nothing to save \u2014 your workspace is already up to date.");
14519
+ }
14520
+ console.log("");
14521
+ return;
14522
+ }
14523
+ const edits = [];
14524
+ try {
14525
+ for (const path2 of writes) {
14526
+ const content = await readFile4(join2(workspacePath, path2), "utf8");
14527
+ edits.push({ path: path2, content });
14528
+ }
14529
+ } catch {
14530
+ console.error(
14531
+ " Couldn't read one of your changed files.\n Next: make sure the file still exists, then run `bamboo-agents save` again."
14532
+ );
14533
+ process.exit(1);
14534
+ }
14535
+ for (const path2 of deletes) {
14536
+ edits.push({ path: path2, delete: true });
14537
+ }
14538
+ let result;
14539
+ try {
14540
+ result = await saveWorkspace(session, {
14541
+ edits,
14542
+ intent: intent?.trim() || void 0
14543
+ });
14544
+ } catch (err) {
14545
+ if (err instanceof ApiError && err.status === 403) {
14546
+ console.error("");
14547
+ console.error(
14548
+ " 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."
14549
+ );
14550
+ process.exit(1);
14551
+ }
14552
+ const message = err instanceof Error ? err.message : String(err);
14553
+ console.error("");
14554
+ console.error(
14555
+ ` Couldn't reach Bamboo to save your changes.
14556
+ Next: check your connection and run \`bamboo-agents save\` again. (${message})`
14557
+ );
14558
+ process.exit(1);
14559
+ }
14560
+ const { checkout, remove } = reconcilePlan(result.files, deletes);
14561
+ if (checkout.length > 0 || remove.length > 0) {
14562
+ try {
14563
+ const branch = await currentBranch(workspacePath);
14564
+ await gitC(workspacePath, ["fetch", "origin", branch]);
14565
+ if (checkout.length > 0) {
14566
+ await gitC(workspacePath, [
14567
+ "checkout",
14568
+ `origin/${branch}`,
14569
+ "--",
14570
+ ...checkout
14571
+ ]);
14572
+ }
14573
+ for (const path2 of remove) {
14574
+ await rm2(join2(workspacePath, path2), { force: true });
14575
+ }
14576
+ } catch {
14577
+ console.warn(
14578
+ " (Saved, but couldn't refresh your local copy just now \u2014 it'll catch up on your next command.)"
14579
+ );
14580
+ }
14581
+ }
14582
+ const total = edits.length;
14583
+ const live = result.live_count;
14584
+ const queued = result.queued_count;
14585
+ console.log("");
14586
+ const parts = [];
14587
+ if (live > 0) parts.push(`${live} live`);
14588
+ if (queued > 0) parts.push(`${queued} queued for review`);
14589
+ const summary = parts.length > 0 ? ` \u2014 ${parts.join(", ")}` : "";
14590
+ console.log(` Saved ${total} file${total === 1 ? "" : "s"}${summary}.`);
14591
+ if (queued > 0 && result.pr_url) {
14592
+ console.log(` Review: ${result.pr_url}`);
14593
+ }
14594
+ if (skipped.length > 0) {
14595
+ console.log(
14596
+ ` (Skipped ${skipped.length} file${skipped.length === 1 ? "" : "s"} outside your context folders.)`
14597
+ );
14598
+ }
14599
+ console.log("");
14600
+ }
14601
+ var execFileP3, MANAGED_PREFIXES, MANAGED_FILES;
14602
+ var init_save2 = __esm({
14603
+ "src/commands/save.ts"() {
14604
+ "use strict";
14605
+ init_api();
14606
+ init_credentials();
14607
+ init_workspace();
14608
+ execFileP3 = promisify8(execFile8);
14609
+ MANAGED_PREFIXES = [
14610
+ "brands/",
14611
+ "agents/",
14612
+ "knowledge/",
14613
+ "skills/",
14614
+ "instructions/",
14615
+ "org/"
14616
+ ];
14617
+ MANAGED_FILES = ["CLAUDE.md", "AGENTS.md"];
14618
+ }
14619
+ });
14620
+
14621
+ // src/lib/workspace-status.ts
14622
+ import { execFile as execFile9 } from "node:child_process";
14623
+ import { promisify as promisify9 } from "node:util";
14624
+ async function git(repoPath, args) {
14625
+ const { stdout } = await execFileP4("git", ["-C", repoPath, ...args], {
14626
+ encoding: "utf8",
14627
+ maxBuffer: 32 * 1024 * 1024
14628
+ });
14629
+ return stdout;
14630
+ }
14631
+ async function countUnsavedManagedEdits(repoPath) {
14632
+ let out;
14633
+ try {
14634
+ out = await git(repoPath, ["status", "--porcelain=v1", "-z", "-uall"]);
14635
+ } catch {
14636
+ return 0;
14637
+ }
14638
+ const seen = /* @__PURE__ */ new Set();
14639
+ for (const entry of parsePorcelain(out)) {
14640
+ if (!isManagedPath(entry.path)) continue;
14641
+ if (seen.has(entry.path)) continue;
14642
+ seen.add(entry.path);
14643
+ }
14644
+ return seen.size;
14645
+ }
14646
+ function parseAheadBehind(out) {
14647
+ const m = out.trim().match(/^(\d+)\s+(\d+)$/);
14648
+ if (!m) return null;
14649
+ return { behind: Number(m[1]), ahead: Number(m[2]) };
14650
+ }
14651
+ async function aheadBehind(repoPath, branch) {
14652
+ try {
14653
+ const out = await git(repoPath, [
14654
+ "rev-list",
14655
+ "--left-right",
14656
+ "--count",
14657
+ `origin/${branch}...HEAD`
14658
+ ]);
14659
+ return parseAheadBehind(out);
14660
+ } catch {
14661
+ return null;
14662
+ }
14663
+ }
14664
+ function classifyCloneHealth(input) {
14665
+ if (input.detachedHead) return "wrecked";
14666
+ if (input.ahead !== null && input.ahead > 0) return "wrecked";
14667
+ return "clean";
14668
+ }
14669
+ async function currentBranchOrNull(repoPath) {
14670
+ try {
14671
+ const out = await git(repoPath, ["symbolic-ref", "--quiet", "--short", "HEAD"]);
14672
+ const name = out.trim();
14673
+ return name || null;
14674
+ } catch {
14675
+ return null;
14676
+ }
14677
+ }
14678
+ async function inspectCloneHealth(repoPath) {
14679
+ const branch = await currentBranchOrNull(repoPath);
14680
+ if (branch === null) {
14681
+ return { health: "wrecked", branch: null, ahead: null };
14682
+ }
14683
+ const ab = await aheadBehind(repoPath, branch);
14684
+ const ahead = ab?.ahead ?? null;
14685
+ return {
14686
+ health: classifyCloneHealth({ detachedHead: false, ahead }),
14687
+ branch,
14688
+ ahead
14689
+ };
14690
+ }
14691
+ var execFileP4;
14692
+ var init_workspace_status = __esm({
14693
+ "src/lib/workspace-status.ts"() {
14694
+ "use strict";
14695
+ init_save2();
14696
+ execFileP4 = promisify9(execFile9);
14697
+ }
14698
+ });
14699
+
14379
14700
  // src/commands/status.ts
14380
14701
  var status_exports = {};
14381
14702
  __export(status_exports, {
14703
+ formatSyncLine: () => formatSyncLine,
14382
14704
  runStatus: () => runStatus
14383
14705
  });
14706
+ function formatSyncLine(input) {
14707
+ const { unsaved, behind, ahead } = input;
14708
+ const parts = [];
14709
+ if (unsaved > 0) {
14710
+ parts.push(`${unsaved} edit${unsaved === 1 ? "" : "s"} not saved`);
14711
+ }
14712
+ if (behind !== null && behind > 0) {
14713
+ parts.push(`cloud has ${behind} newer`);
14714
+ }
14715
+ if (ahead !== null && ahead > 0) {
14716
+ parts.push(`${ahead} local commit${ahead === 1 ? "" : "s"} ahead (run \`bamboo-agents doctor\`)`);
14717
+ }
14718
+ const summary = parts.length === 0 ? "in sync" : parts.join(", ");
14719
+ return `Sync: ${summary}`;
14720
+ }
14384
14721
  function formatSubscriptionLine(billing) {
14385
14722
  switch (billing.state) {
14386
14723
  case "trialing": {
@@ -14428,6 +14765,12 @@ async function runStatus() {
14428
14765
  if (state?.last_sync) {
14429
14766
  console.log(` Last sync: ${state.last_sync}`);
14430
14767
  }
14768
+ const unsaved = await countUnsavedManagedEdits(workspacePath);
14769
+ const branch = await currentBranchOrNull(workspacePath);
14770
+ const ab = branch ? await aheadBehind(workspacePath, branch) : null;
14771
+ console.log(
14772
+ ` ${formatSyncLine({ unsaved, behind: ab?.behind ?? null, ahead: ab?.ahead ?? null })}`
14773
+ );
14431
14774
  }
14432
14775
  if (creds?.bamboo_session) {
14433
14776
  try {
@@ -14446,14 +14789,15 @@ var init_status = __esm({
14446
14789
  init_credentials();
14447
14790
  init_api();
14448
14791
  init_workspace();
14792
+ init_workspace_status();
14449
14793
  }
14450
14794
  });
14451
14795
 
14452
14796
  // src/lib/workspace-health.ts
14453
- import { execFile as execFile8 } from "node:child_process";
14454
- import { promisify as promisify8 } from "node:util";
14455
- import { lstat, readlink, readdir as readdir2, mkdir as mkdir3, symlink, rm as rm2, access as access3 } from "node:fs/promises";
14456
- import { join as join2, dirname as dirname2, resolve } from "node:path";
14797
+ import { execFile as execFile10 } from "node:child_process";
14798
+ import { promisify as promisify10 } from "node:util";
14799
+ import { lstat, readlink, readdir as readdir2, mkdir as mkdir3, symlink, rm as rm3, access as access3 } from "node:fs/promises";
14800
+ import { join as join3, dirname as dirname2, resolve } from "node:path";
14457
14801
  import { homedir as homedir2 } from "node:os";
14458
14802
  function getStaleSyncHours() {
14459
14803
  const raw = process.env.BAMBOO_STALE_SYNC_HOURS;
@@ -14465,7 +14809,7 @@ function getStaleSyncHours() {
14465
14809
  function cloneSearchRoots(cwd) {
14466
14810
  const overridden = process.env.BAMBOO_CLONE_SEARCH_DIRS;
14467
14811
  const home = homedir2();
14468
- const base = overridden ? overridden.split(":").filter(Boolean) : [home, join2(home, "Documents"), join2(home, "Downloads"), join2(home, "Desktop")];
14812
+ const base = overridden ? overridden.split(":").filter(Boolean) : [home, join3(home, "Documents"), join3(home, "Downloads"), join3(home, "Desktop")];
14469
14813
  const walk = [];
14470
14814
  let cur = cwd ?? process.cwd();
14471
14815
  for (let i = 0; i < 20; i++) {
@@ -14495,7 +14839,7 @@ async function findClones(remoteUrl, roots, maxDepth = 4) {
14495
14839
  if (scanned >= MAX_DIRS_SCANNED) return;
14496
14840
  if (depth < 0) return;
14497
14841
  scanned += 1;
14498
- const gitDir = join2(dir, ".git");
14842
+ const gitDir = join3(dir, ".git");
14499
14843
  let isRepo = false;
14500
14844
  try {
14501
14845
  const s = await lstat(gitDir);
@@ -14522,7 +14866,7 @@ async function findClones(remoteUrl, roots, maxDepth = 4) {
14522
14866
  if (SKIP_DIRS.has(entry.name)) continue;
14523
14867
  }
14524
14868
  if (SKIP_DIRS.has(entry.name)) continue;
14525
- await visit(join2(dir, entry.name), depth - 1);
14869
+ await visit(join3(dir, entry.name), depth - 1);
14526
14870
  }
14527
14871
  }
14528
14872
  for (const root of roots) {
@@ -14553,7 +14897,7 @@ function remoteUrlSlug(url) {
14553
14897
  async function checkAdapters(workspacePath) {
14554
14898
  const out = [];
14555
14899
  for (const { path: path2, target } of CROSS_TOOL_ADAPTERS) {
14556
- const full = join2(workspacePath, path2);
14900
+ const full = join3(workspacePath, path2);
14557
14901
  let s;
14558
14902
  try {
14559
14903
  s = await lstat(full);
@@ -14597,10 +14941,10 @@ async function healAdapters(workspacePath) {
14597
14941
  const current = await checkAdapters(workspacePath);
14598
14942
  for (const status of current) {
14599
14943
  if (status.ok) continue;
14600
- const full = join2(workspacePath, status.path);
14944
+ const full = join3(workspacePath, status.path);
14601
14945
  if (status.state === "wrong_target" || status.state === "not_symlink") {
14602
14946
  try {
14603
- await rm2(full, { recursive: true, force: true });
14947
+ await rm3(full, { recursive: true, force: true });
14604
14948
  } catch {
14605
14949
  }
14606
14950
  }
@@ -14627,7 +14971,7 @@ function describeAge(lastSync) {
14627
14971
  }
14628
14972
  async function gitPullFfOnly(workspacePath) {
14629
14973
  try {
14630
- const { stderr } = await execFileP3("git", ["-C", workspacePath, "pull", "--ff-only"], {
14974
+ const { stderr } = await execFileP5("git", ["-C", workspacePath, "pull", "--ff-only"], {
14631
14975
  encoding: "utf8"
14632
14976
  });
14633
14977
  return { ok: true, stderr };
@@ -14644,12 +14988,12 @@ async function pathExists(p) {
14644
14988
  return false;
14645
14989
  }
14646
14990
  }
14647
- var execFileP3, CROSS_TOOL_ADAPTERS, DEFAULT_STALE_SYNC_HOURS, MAX_DIRS_SCANNED, SKIP_DIRS;
14991
+ var execFileP5, CROSS_TOOL_ADAPTERS, DEFAULT_STALE_SYNC_HOURS, MAX_DIRS_SCANNED, SKIP_DIRS;
14648
14992
  var init_workspace_health = __esm({
14649
14993
  "src/lib/workspace-health.ts"() {
14650
14994
  "use strict";
14651
14995
  init_git();
14652
- execFileP3 = promisify8(execFile8);
14996
+ execFileP5 = promisify10(execFile10);
14653
14997
  CROSS_TOOL_ADAPTERS = [
14654
14998
  { path: ".claude/skills", target: "../skills" },
14655
14999
  { path: ".cursor/skills", target: "../skills" },
@@ -14759,7 +15103,7 @@ __export(doctor_exports, {
14759
15103
  runDoctor: () => runDoctor
14760
15104
  });
14761
15105
  import { access as access4 } from "node:fs/promises";
14762
- import { rm as rm3 } from "node:fs/promises";
15106
+ import { rm as rm4 } from "node:fs/promises";
14763
15107
  async function checkGit() {
14764
15108
  const v = await gitVersion();
14765
15109
  if (!v) {
@@ -15026,7 +15370,7 @@ async function healMultiClone(finding, state, opts) {
15026
15370
  if (wantDelete) {
15027
15371
  for (const p of nonCanonical) {
15028
15372
  try {
15029
- await rm3(p, { recursive: true, force: true });
15373
+ await rm4(p, { recursive: true, force: true });
15030
15374
  console.log(` \u2713 removed ${p}`);
15031
15375
  } catch (err) {
15032
15376
  console.log(` \u2717 couldn't remove ${p}: ${err.message}`);
@@ -15200,266 +15544,76 @@ var init_doctor = __esm({
15200
15544
  }
15201
15545
  });
15202
15546
 
15203
- // src/commands/save.ts
15204
- var save_exports = {};
15205
- __export(save_exports, {
15206
- isDeletion: () => isDeletion,
15207
- isManagedPath: () => isManagedPath,
15208
- parsePorcelain: () => parsePorcelain,
15209
- planBatchFromPorcelain: () => planBatchFromPorcelain,
15210
- runSave: () => runSave
15547
+ // src/commands/update.ts
15548
+ var update_exports = {};
15549
+ __export(update_exports, {
15550
+ runUpdate: () => runUpdate
15211
15551
  });
15212
- import { execFile as execFile9 } from "node:child_process";
15213
- import { readFile as readFile4 } from "node:fs/promises";
15214
- import { join as join3 } from "node:path";
15215
- import { promisify as promisify9 } from "node:util";
15216
- function parsePorcelain(out) {
15217
- if (!out) return [];
15218
- const fields = out.split("\0");
15219
- const entries = [];
15220
- for (let i = 0; i < fields.length; i++) {
15221
- const field = fields[i];
15222
- if (!field) continue;
15223
- const status = field.slice(0, 2);
15224
- const path2 = field.slice(3);
15225
- if (!path2) continue;
15226
- entries.push({ status, path: path2 });
15227
- if (status[0] === "R" || status[0] === "C") {
15228
- i++;
15229
- }
15230
- }
15231
- return entries;
15232
- }
15233
- function isManagedPath(path2) {
15234
- if (MANAGED_FILES.includes(path2)) return true;
15235
- return MANAGED_PREFIXES.some((p) => path2.startsWith(p));
15236
- }
15237
- function isDeletion(entry) {
15238
- return entry.status[0] === "D" || entry.status[1] === "D";
15239
- }
15240
- function planBatchFromPorcelain(entries) {
15241
- const deletes = [];
15242
- const writes = [];
15243
- const skipped = [];
15244
- const seen = /* @__PURE__ */ new Set();
15245
- for (const entry of entries) {
15246
- if (seen.has(entry.path)) continue;
15247
- seen.add(entry.path);
15248
- if (!isManagedPath(entry.path)) {
15249
- skipped.push(entry.path);
15250
- continue;
15251
- }
15252
- if (isDeletion(entry)) {
15253
- deletes.push(entry.path);
15254
- } else {
15255
- writes.push(entry.path);
15256
- }
15257
- }
15258
- return { deletes, writes, skipped };
15259
- }
15260
- async function gitC(repoPath, args) {
15261
- const { stdout } = await execFileP4("git", ["-C", repoPath, ...args], {
15262
- encoding: "utf8",
15263
- // -z output + file content can exceed the default 1MB buffer.
15264
- maxBuffer: 32 * 1024 * 1024
15265
- });
15266
- return stdout;
15267
- }
15268
- async function currentBranch(repoPath) {
15269
- const out = await gitC(repoPath, ["rev-parse", "--abbrev-ref", "HEAD"]);
15270
- return out.trim() || "main";
15271
- }
15272
- async function requireSession() {
15273
- const creds = await readCredentials();
15274
- if (!creds) {
15275
- console.error(
15276
- "bamboo-agents save: not signed in. Run `bamboo-agents login` first."
15277
- );
15278
- process.exit(1);
15552
+ async function bumpLastSync() {
15553
+ try {
15554
+ const state = await readState();
15555
+ if (state) await updateLastSync(/* @__PURE__ */ new Date());
15556
+ } catch (err) {
15557
+ if (err instanceof WorkspaceStateError) return;
15558
+ throw err;
15279
15559
  }
15280
- return creds.bamboo_session;
15281
15560
  }
15282
- async function runSave(intent) {
15561
+ async function runUpdate() {
15283
15562
  let workspacePath;
15284
15563
  try {
15285
15564
  workspacePath = (await resolveWorkspace()).path;
15286
15565
  } catch (err) {
15287
15566
  if (err instanceof NoWorkspaceError) {
15288
- console.error(`bamboo-agents save: ${err.message}`);
15567
+ console.error(`bamboo-agents update: ${err.message}`);
15289
15568
  process.exit(2);
15290
15569
  }
15291
15570
  throw err;
15292
15571
  }
15293
- const session = await requireSession();
15294
- let entries;
15295
- try {
15296
- const porcelain = await gitC(workspacePath, [
15297
- "status",
15298
- "--porcelain=v1",
15299
- "-z",
15300
- "-uall"
15301
- ]);
15302
- entries = parsePorcelain(porcelain);
15303
- } catch {
15304
- console.error(
15305
- " Couldn't read your workspace changes.\n Next: run `bamboo-agents doctor` to check your workspace is healthy."
15306
- );
15307
- process.exit(1);
15308
- }
15309
- const { deletes, writes, skipped } = planBatchFromPorcelain(entries);
15310
- if (deletes.length === 0 && writes.length === 0) {
15572
+ const { health } = await inspectCloneHealth(workspacePath);
15573
+ if (health === "wrecked") {
15311
15574
  console.log("");
15312
- if (skipped.length > 0) {
15313
- console.log(
15314
- " Nothing to save \u2014 the only changes are outside your context folders."
15315
- );
15316
- } else {
15317
- console.log(" Nothing to save \u2014 your workspace is already up to date.");
15318
- }
15575
+ console.log(" Your local copy has drifted in a way that can't auto-update.");
15576
+ console.log(
15577
+ " Your workspace is a cached copy of the cloud \u2014 the safe fix is to refresh it from scratch."
15578
+ );
15319
15579
  console.log("");
15580
+ const { runInit: runInit2 } = await Promise.resolve().then(() => (init_init(), init_exports));
15581
+ await runInit2({ reset: true });
15320
15582
  return;
15321
15583
  }
15322
- const edits = [];
15323
- try {
15324
- for (const path2 of writes) {
15325
- const content = await readFile4(join3(workspacePath, path2), "utf8");
15326
- edits.push({ path: path2, content });
15327
- }
15328
- } catch {
15329
- console.error(
15330
- " Couldn't read one of your changed files.\n Next: make sure the file still exists, then run `bamboo-agents save` again."
15331
- );
15332
- process.exit(1);
15333
- }
15334
- for (const path2 of deletes) {
15335
- edits.push({ path: path2, delete: true });
15336
- }
15337
- let result;
15338
- try {
15339
- result = await saveWorkspace(session, {
15340
- edits,
15341
- intent: intent?.trim() || void 0
15342
- });
15343
- } catch (err) {
15344
- if (err instanceof ApiError && err.status === 403) {
15345
- console.error("");
15346
- console.error(
15347
- " 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."
15348
- );
15349
- process.exit(1);
15350
- }
15351
- const message = err instanceof Error ? err.message : String(err);
15352
- console.error("");
15353
- console.error(
15354
- ` Couldn't reach Bamboo to save your changes.
15355
- Next: check your connection and run \`bamboo-agents save\` again. (${message})`
15356
- );
15357
- process.exit(1);
15358
- }
15359
- let branch = "main";
15360
- try {
15361
- branch = await currentBranch(workspacePath);
15362
- await gitC(workspacePath, ["fetch", "origin", branch]);
15363
- await gitC(workspacePath, ["reset", "--hard", `origin/${branch}`]);
15364
- } catch {
15365
- console.warn(
15366
- " (Saved, but couldn't refresh your local copy just now \u2014 it'll catch up on your next command.)"
15367
- );
15368
- }
15369
- const total = edits.length;
15370
- const live = result.live_count;
15371
- const queued = result.queued_count;
15372
- console.log("");
15373
- const parts = [];
15374
- if (live > 0) parts.push(`${live} live`);
15375
- if (queued > 0) parts.push(`${queued} queued for review`);
15376
- const summary = parts.length > 0 ? ` \u2014 ${parts.join(", ")}` : "";
15377
- console.log(` Saved ${total} file${total === 1 ? "" : "s"}${summary}.`);
15378
- if (queued > 0 && result.pr_url) {
15379
- console.log(` Review: ${result.pr_url}`);
15380
- }
15381
- if (skipped.length > 0) {
15584
+ const unsaved = await countUnsavedManagedEdits(workspacePath);
15585
+ if (unsaved > 0) {
15586
+ console.log("");
15382
15587
  console.log(
15383
- ` (Skipped ${skipped.length} file${skipped.length === 1 ? "" : "s"} outside your context folders.)`
15588
+ ` You have ${unsaved} unsaved change${unsaved === 1 ? "" : "s"} \u2014 saving ${unsaved === 1 ? "it" : "them"} first\u2026`
15384
15589
  );
15590
+ const { runSave: runSave2 } = await Promise.resolve().then(() => (init_save2(), save_exports));
15591
+ await runSave2(void 0);
15385
15592
  }
15386
- console.log("");
15387
- }
15388
- var execFileP4, MANAGED_PREFIXES, MANAGED_FILES;
15389
- var init_save2 = __esm({
15390
- "src/commands/save.ts"() {
15391
- "use strict";
15392
- init_api();
15393
- init_credentials();
15394
- init_workspace();
15395
- execFileP4 = promisify9(execFile9);
15396
- MANAGED_PREFIXES = [
15397
- "brands/",
15398
- "agents/",
15399
- "knowledge/",
15400
- "skills/",
15401
- "instructions/",
15402
- "org/"
15403
- ];
15404
- MANAGED_FILES = ["CLAUDE.md", "AGENTS.md"];
15405
- }
15406
- });
15407
-
15408
- // src/commands/sync.ts
15409
- var sync_exports = {};
15410
- __export(sync_exports, {
15411
- runSync: () => runSync
15412
- });
15413
- import { execFile as execFile10 } from "node:child_process";
15414
- import { promisify as promisify10 } from "node:util";
15415
- async function runSync() {
15416
- let workspacePath;
15417
15593
  try {
15418
- workspacePath = (await resolveWorkspace()).path;
15419
- } catch (err) {
15420
- if (err instanceof NoWorkspaceError) {
15421
- console.error(`bamboo-agents sync: ${err.message}`);
15422
- process.exit(2);
15423
- }
15424
- throw err;
15425
- }
15426
- try {
15427
- const { stdout } = await execFileP5(
15428
- "git",
15429
- ["-C", workspacePath, "pull", "--ff-only"],
15430
- { encoding: "utf8" }
15431
- );
15594
+ await gitPullFFOnly(workspacePath);
15432
15595
  console.log("");
15433
- console.log(" Synced your workspace with the remote.");
15434
- if (stdout.trim()) {
15435
- console.log(` ${stdout.trim().split("\n").pop()}`);
15436
- }
15596
+ console.log(" Your workspace is up to date with the cloud.");
15437
15597
  console.log(` (workspace: ${workspacePath})`);
15438
15598
  console.log("");
15439
- } catch (err) {
15440
- const e = err;
15441
- console.error("bamboo-agents sync: git failed.");
15442
- if (e.stderr?.trim()) console.error(e.stderr.trim());
15443
- else console.error(e.message);
15599
+ } catch {
15600
+ console.log("");
15601
+ console.log(" Couldn't reach the cloud to update just now.");
15602
+ console.log(
15603
+ " Next: check your connection and run `bamboo-agents update` again. If it keeps failing, run `bamboo-agents doctor`."
15604
+ );
15605
+ console.log("");
15444
15606
  process.exit(1);
15445
15607
  }
15446
- try {
15447
- const state = await readState();
15448
- if (state) await updateLastSync(/* @__PURE__ */ new Date());
15449
- } catch (err) {
15450
- if (err instanceof WorkspaceStateError) {
15451
- return;
15452
- }
15453
- throw err;
15454
- }
15608
+ await bumpLastSync();
15455
15609
  }
15456
- var execFileP5;
15457
- var init_sync = __esm({
15458
- "src/commands/sync.ts"() {
15610
+ var init_update = __esm({
15611
+ "src/commands/update.ts"() {
15459
15612
  "use strict";
15613
+ init_git();
15460
15614
  init_state();
15461
15615
  init_workspace();
15462
- execFileP5 = promisify10(execFile10);
15616
+ init_workspace_status();
15463
15617
  }
15464
15618
  });
15465
15619
 
@@ -16262,6 +16416,13 @@ async function runContextHealth(options) {
16262
16416
  console.log(JSON.stringify(data, null, 2));
16263
16417
  return;
16264
16418
  }
16419
+ if (!data.available) {
16420
+ console.log("");
16421
+ console.log(" Context health is unavailable right now.");
16422
+ console.log(` (${data.reason})`);
16423
+ console.log("");
16424
+ return;
16425
+ }
16265
16426
  printHealth(data);
16266
16427
  }
16267
16428
  var init_context = __esm({
@@ -16525,9 +16686,9 @@ program2.command("save [intent]").description("Save your workspace changes (rout
16525
16686
  const { runSave: runSave2 } = await Promise.resolve().then(() => (init_save2(), save_exports));
16526
16687
  await runSave2(intent);
16527
16688
  });
16528
- program2.command("sync").description("Pull your workspace clone up to remote (cwd-agnostic)").action(async () => {
16529
- const { runSync: runSync2 } = await Promise.resolve().then(() => (init_sync(), sync_exports));
16530
- await runSync2();
16689
+ program2.command("update").alias("sync").description("Update your workspace from the cloud (saves unsaved edits first, then pulls)").action(async () => {
16690
+ const { runUpdate: runUpdate2 } = await Promise.resolve().then(() => (init_update(), update_exports));
16691
+ await runUpdate2();
16531
16692
  });
16532
16693
  var skills = program2.command("skills").description("Read workspace skills from your local clone");
16533
16694
  skills.command("list").description("List every skill in the workspace").option(