bamboo-agents 0.1.5-dev.47.e6dcb2e → 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/VERSION +1 -1
- package/dist/index.js +394 -250
- package/dist/index.js.map +4 -4
- package/package.json +1 -1
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.
|
|
3040
|
+
VERSION = "0.1.5-dev.48.0e1a6eb";
|
|
3041
3041
|
}
|
|
3042
3042
|
});
|
|
3043
3043
|
|
|
@@ -14386,11 +14386,338 @@ var init_open2 = __esm({
|
|
|
14386
14386
|
}
|
|
14387
14387
|
});
|
|
14388
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
|
+
|
|
14389
14700
|
// src/commands/status.ts
|
|
14390
14701
|
var status_exports = {};
|
|
14391
14702
|
__export(status_exports, {
|
|
14703
|
+
formatSyncLine: () => formatSyncLine,
|
|
14392
14704
|
runStatus: () => runStatus
|
|
14393
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
|
+
}
|
|
14394
14721
|
function formatSubscriptionLine(billing) {
|
|
14395
14722
|
switch (billing.state) {
|
|
14396
14723
|
case "trialing": {
|
|
@@ -14438,6 +14765,12 @@ async function runStatus() {
|
|
|
14438
14765
|
if (state?.last_sync) {
|
|
14439
14766
|
console.log(` Last sync: ${state.last_sync}`);
|
|
14440
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
|
+
);
|
|
14441
14774
|
}
|
|
14442
14775
|
if (creds?.bamboo_session) {
|
|
14443
14776
|
try {
|
|
@@ -14456,14 +14789,15 @@ var init_status = __esm({
|
|
|
14456
14789
|
init_credentials();
|
|
14457
14790
|
init_api();
|
|
14458
14791
|
init_workspace();
|
|
14792
|
+
init_workspace_status();
|
|
14459
14793
|
}
|
|
14460
14794
|
});
|
|
14461
14795
|
|
|
14462
14796
|
// src/lib/workspace-health.ts
|
|
14463
|
-
import { execFile as
|
|
14464
|
-
import { promisify as
|
|
14465
|
-
import { lstat, readlink, readdir as readdir2, mkdir as mkdir3, symlink, rm as
|
|
14466
|
-
import { join as
|
|
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";
|
|
14467
14801
|
import { homedir as homedir2 } from "node:os";
|
|
14468
14802
|
function getStaleSyncHours() {
|
|
14469
14803
|
const raw = process.env.BAMBOO_STALE_SYNC_HOURS;
|
|
@@ -14475,7 +14809,7 @@ function getStaleSyncHours() {
|
|
|
14475
14809
|
function cloneSearchRoots(cwd) {
|
|
14476
14810
|
const overridden = process.env.BAMBOO_CLONE_SEARCH_DIRS;
|
|
14477
14811
|
const home = homedir2();
|
|
14478
|
-
const base = overridden ? overridden.split(":").filter(Boolean) : [home,
|
|
14812
|
+
const base = overridden ? overridden.split(":").filter(Boolean) : [home, join3(home, "Documents"), join3(home, "Downloads"), join3(home, "Desktop")];
|
|
14479
14813
|
const walk = [];
|
|
14480
14814
|
let cur = cwd ?? process.cwd();
|
|
14481
14815
|
for (let i = 0; i < 20; i++) {
|
|
@@ -14505,7 +14839,7 @@ async function findClones(remoteUrl, roots, maxDepth = 4) {
|
|
|
14505
14839
|
if (scanned >= MAX_DIRS_SCANNED) return;
|
|
14506
14840
|
if (depth < 0) return;
|
|
14507
14841
|
scanned += 1;
|
|
14508
|
-
const gitDir =
|
|
14842
|
+
const gitDir = join3(dir, ".git");
|
|
14509
14843
|
let isRepo = false;
|
|
14510
14844
|
try {
|
|
14511
14845
|
const s = await lstat(gitDir);
|
|
@@ -14532,7 +14866,7 @@ async function findClones(remoteUrl, roots, maxDepth = 4) {
|
|
|
14532
14866
|
if (SKIP_DIRS.has(entry.name)) continue;
|
|
14533
14867
|
}
|
|
14534
14868
|
if (SKIP_DIRS.has(entry.name)) continue;
|
|
14535
|
-
await visit(
|
|
14869
|
+
await visit(join3(dir, entry.name), depth - 1);
|
|
14536
14870
|
}
|
|
14537
14871
|
}
|
|
14538
14872
|
for (const root of roots) {
|
|
@@ -14563,7 +14897,7 @@ function remoteUrlSlug(url) {
|
|
|
14563
14897
|
async function checkAdapters(workspacePath) {
|
|
14564
14898
|
const out = [];
|
|
14565
14899
|
for (const { path: path2, target } of CROSS_TOOL_ADAPTERS) {
|
|
14566
|
-
const full =
|
|
14900
|
+
const full = join3(workspacePath, path2);
|
|
14567
14901
|
let s;
|
|
14568
14902
|
try {
|
|
14569
14903
|
s = await lstat(full);
|
|
@@ -14607,10 +14941,10 @@ async function healAdapters(workspacePath) {
|
|
|
14607
14941
|
const current = await checkAdapters(workspacePath);
|
|
14608
14942
|
for (const status of current) {
|
|
14609
14943
|
if (status.ok) continue;
|
|
14610
|
-
const full =
|
|
14944
|
+
const full = join3(workspacePath, status.path);
|
|
14611
14945
|
if (status.state === "wrong_target" || status.state === "not_symlink") {
|
|
14612
14946
|
try {
|
|
14613
|
-
await
|
|
14947
|
+
await rm3(full, { recursive: true, force: true });
|
|
14614
14948
|
} catch {
|
|
14615
14949
|
}
|
|
14616
14950
|
}
|
|
@@ -14637,7 +14971,7 @@ function describeAge(lastSync) {
|
|
|
14637
14971
|
}
|
|
14638
14972
|
async function gitPullFfOnly(workspacePath) {
|
|
14639
14973
|
try {
|
|
14640
|
-
const { stderr } = await
|
|
14974
|
+
const { stderr } = await execFileP5("git", ["-C", workspacePath, "pull", "--ff-only"], {
|
|
14641
14975
|
encoding: "utf8"
|
|
14642
14976
|
});
|
|
14643
14977
|
return { ok: true, stderr };
|
|
@@ -14654,12 +14988,12 @@ async function pathExists(p) {
|
|
|
14654
14988
|
return false;
|
|
14655
14989
|
}
|
|
14656
14990
|
}
|
|
14657
|
-
var
|
|
14991
|
+
var execFileP5, CROSS_TOOL_ADAPTERS, DEFAULT_STALE_SYNC_HOURS, MAX_DIRS_SCANNED, SKIP_DIRS;
|
|
14658
14992
|
var init_workspace_health = __esm({
|
|
14659
14993
|
"src/lib/workspace-health.ts"() {
|
|
14660
14994
|
"use strict";
|
|
14661
14995
|
init_git();
|
|
14662
|
-
|
|
14996
|
+
execFileP5 = promisify10(execFile10);
|
|
14663
14997
|
CROSS_TOOL_ADAPTERS = [
|
|
14664
14998
|
{ path: ".claude/skills", target: "../skills" },
|
|
14665
14999
|
{ path: ".cursor/skills", target: "../skills" },
|
|
@@ -14769,7 +15103,7 @@ __export(doctor_exports, {
|
|
|
14769
15103
|
runDoctor: () => runDoctor
|
|
14770
15104
|
});
|
|
14771
15105
|
import { access as access4 } from "node:fs/promises";
|
|
14772
|
-
import { rm as
|
|
15106
|
+
import { rm as rm4 } from "node:fs/promises";
|
|
14773
15107
|
async function checkGit() {
|
|
14774
15108
|
const v = await gitVersion();
|
|
14775
15109
|
if (!v) {
|
|
@@ -15036,7 +15370,7 @@ async function healMultiClone(finding, state, opts) {
|
|
|
15036
15370
|
if (wantDelete) {
|
|
15037
15371
|
for (const p of nonCanonical) {
|
|
15038
15372
|
try {
|
|
15039
|
-
await
|
|
15373
|
+
await rm4(p, { recursive: true, force: true });
|
|
15040
15374
|
console.log(` \u2713 removed ${p}`);
|
|
15041
15375
|
} catch (err) {
|
|
15042
15376
|
console.log(` \u2717 couldn't remove ${p}: ${err.message}`);
|
|
@@ -15210,266 +15544,76 @@ var init_doctor = __esm({
|
|
|
15210
15544
|
}
|
|
15211
15545
|
});
|
|
15212
15546
|
|
|
15213
|
-
// src/commands/
|
|
15214
|
-
var
|
|
15215
|
-
__export(
|
|
15216
|
-
|
|
15217
|
-
isManagedPath: () => isManagedPath,
|
|
15218
|
-
parsePorcelain: () => parsePorcelain,
|
|
15219
|
-
planBatchFromPorcelain: () => planBatchFromPorcelain,
|
|
15220
|
-
runSave: () => runSave
|
|
15547
|
+
// src/commands/update.ts
|
|
15548
|
+
var update_exports = {};
|
|
15549
|
+
__export(update_exports, {
|
|
15550
|
+
runUpdate: () => runUpdate
|
|
15221
15551
|
});
|
|
15222
|
-
|
|
15223
|
-
|
|
15224
|
-
|
|
15225
|
-
|
|
15226
|
-
|
|
15227
|
-
|
|
15228
|
-
|
|
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);
|
|
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;
|
|
15289
15559
|
}
|
|
15290
|
-
return creds.bamboo_session;
|
|
15291
15560
|
}
|
|
15292
|
-
async function
|
|
15561
|
+
async function runUpdate() {
|
|
15293
15562
|
let workspacePath;
|
|
15294
15563
|
try {
|
|
15295
15564
|
workspacePath = (await resolveWorkspace()).path;
|
|
15296
15565
|
} catch (err) {
|
|
15297
15566
|
if (err instanceof NoWorkspaceError) {
|
|
15298
|
-
console.error(`bamboo-agents
|
|
15567
|
+
console.error(`bamboo-agents update: ${err.message}`);
|
|
15299
15568
|
process.exit(2);
|
|
15300
15569
|
}
|
|
15301
15570
|
throw err;
|
|
15302
15571
|
}
|
|
15303
|
-
const
|
|
15304
|
-
|
|
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) {
|
|
15572
|
+
const { health } = await inspectCloneHealth(workspacePath);
|
|
15573
|
+
if (health === "wrecked") {
|
|
15321
15574
|
console.log("");
|
|
15322
|
-
|
|
15323
|
-
|
|
15324
|
-
|
|
15325
|
-
|
|
15326
|
-
} else {
|
|
15327
|
-
console.log(" Nothing to save \u2014 your workspace is already up to date.");
|
|
15328
|
-
}
|
|
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
|
+
);
|
|
15329
15579
|
console.log("");
|
|
15580
|
+
const { runInit: runInit2 } = await Promise.resolve().then(() => (init_init(), init_exports));
|
|
15581
|
+
await runInit2({ reset: true });
|
|
15330
15582
|
return;
|
|
15331
15583
|
}
|
|
15332
|
-
const
|
|
15333
|
-
|
|
15334
|
-
|
|
15335
|
-
const content = await readFile4(join3(workspacePath, path2), "utf8");
|
|
15336
|
-
edits.push({ path: path2, content });
|
|
15337
|
-
}
|
|
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
|
-
}
|
|
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
|
-
);
|
|
15359
|
-
process.exit(1);
|
|
15360
|
-
}
|
|
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);
|
|
15368
|
-
}
|
|
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
|
-
);
|
|
15378
|
-
}
|
|
15379
|
-
const total = edits.length;
|
|
15380
|
-
const live = result.live_count;
|
|
15381
|
-
const queued = result.queued_count;
|
|
15382
|
-
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) {
|
|
15584
|
+
const unsaved = await countUnsavedManagedEdits(workspacePath);
|
|
15585
|
+
if (unsaved > 0) {
|
|
15586
|
+
console.log("");
|
|
15392
15587
|
console.log(
|
|
15393
|
-
`
|
|
15588
|
+
` You have ${unsaved} unsaved change${unsaved === 1 ? "" : "s"} \u2014 saving ${unsaved === 1 ? "it" : "them"} first\u2026`
|
|
15394
15589
|
);
|
|
15395
|
-
|
|
15396
|
-
|
|
15397
|
-
}
|
|
15398
|
-
var execFileP4, MANAGED_PREFIXES, MANAGED_FILES;
|
|
15399
|
-
var init_save2 = __esm({
|
|
15400
|
-
"src/commands/save.ts"() {
|
|
15401
|
-
"use strict";
|
|
15402
|
-
init_api();
|
|
15403
|
-
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"];
|
|
15415
|
-
}
|
|
15416
|
-
});
|
|
15417
|
-
|
|
15418
|
-
// src/commands/sync.ts
|
|
15419
|
-
var sync_exports = {};
|
|
15420
|
-
__export(sync_exports, {
|
|
15421
|
-
runSync: () => runSync
|
|
15422
|
-
});
|
|
15423
|
-
import { execFile as execFile10 } from "node:child_process";
|
|
15424
|
-
import { promisify as promisify10 } from "node:util";
|
|
15425
|
-
async function runSync() {
|
|
15426
|
-
let workspacePath;
|
|
15427
|
-
try {
|
|
15428
|
-
workspacePath = (await resolveWorkspace()).path;
|
|
15429
|
-
} catch (err) {
|
|
15430
|
-
if (err instanceof NoWorkspaceError) {
|
|
15431
|
-
console.error(`bamboo-agents sync: ${err.message}`);
|
|
15432
|
-
process.exit(2);
|
|
15433
|
-
}
|
|
15434
|
-
throw err;
|
|
15590
|
+
const { runSave: runSave2 } = await Promise.resolve().then(() => (init_save2(), save_exports));
|
|
15591
|
+
await runSave2(void 0);
|
|
15435
15592
|
}
|
|
15436
15593
|
try {
|
|
15437
|
-
|
|
15438
|
-
"git",
|
|
15439
|
-
["-C", workspacePath, "pull", "--ff-only"],
|
|
15440
|
-
{ encoding: "utf8" }
|
|
15441
|
-
);
|
|
15594
|
+
await gitPullFFOnly(workspacePath);
|
|
15442
15595
|
console.log("");
|
|
15443
|
-
console.log("
|
|
15444
|
-
if (stdout.trim()) {
|
|
15445
|
-
console.log(` ${stdout.trim().split("\n").pop()}`);
|
|
15446
|
-
}
|
|
15596
|
+
console.log(" Your workspace is up to date with the cloud.");
|
|
15447
15597
|
console.log(` (workspace: ${workspacePath})`);
|
|
15448
15598
|
console.log("");
|
|
15449
|
-
} catch
|
|
15450
|
-
|
|
15451
|
-
console.
|
|
15452
|
-
|
|
15453
|
-
|
|
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("");
|
|
15454
15606
|
process.exit(1);
|
|
15455
15607
|
}
|
|
15456
|
-
|
|
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;
|
|
15464
|
-
}
|
|
15608
|
+
await bumpLastSync();
|
|
15465
15609
|
}
|
|
15466
|
-
var
|
|
15467
|
-
|
|
15468
|
-
"src/commands/sync.ts"() {
|
|
15610
|
+
var init_update = __esm({
|
|
15611
|
+
"src/commands/update.ts"() {
|
|
15469
15612
|
"use strict";
|
|
15613
|
+
init_git();
|
|
15470
15614
|
init_state();
|
|
15471
15615
|
init_workspace();
|
|
15472
|
-
|
|
15616
|
+
init_workspace_status();
|
|
15473
15617
|
}
|
|
15474
15618
|
});
|
|
15475
15619
|
|
|
@@ -16542,9 +16686,9 @@ program2.command("save [intent]").description("Save your workspace changes (rout
|
|
|
16542
16686
|
const { runSave: runSave2 } = await Promise.resolve().then(() => (init_save2(), save_exports));
|
|
16543
16687
|
await runSave2(intent);
|
|
16544
16688
|
});
|
|
16545
|
-
program2.command("sync").description("
|
|
16546
|
-
const {
|
|
16547
|
-
await
|
|
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();
|
|
16548
16692
|
});
|
|
16549
16693
|
var skills = program2.command("skills").description("Read workspace skills from your local clone");
|
|
16550
16694
|
skills.command("list").description("List every skill in the workspace").option(
|