bamboo-agents 0.1.5-dev.37.e3cb3a7 → 0.1.5-dev.39.69fcffd
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 +908 -149
- 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.39.69fcffd";
|
|
3041
3041
|
}
|
|
3042
3042
|
});
|
|
3043
3043
|
|
|
@@ -7854,14 +7854,14 @@ var init_open = __esm({
|
|
|
7854
7854
|
}
|
|
7855
7855
|
const subprocess = childProcess.spawn(command, cliArguments, childProcessOptions);
|
|
7856
7856
|
if (options.wait) {
|
|
7857
|
-
return new Promise((
|
|
7857
|
+
return new Promise((resolve2, reject) => {
|
|
7858
7858
|
subprocess.once("error", reject);
|
|
7859
7859
|
subprocess.once("close", (exitCode) => {
|
|
7860
7860
|
if (!options.allowNonzeroExitCode && exitCode > 0) {
|
|
7861
7861
|
reject(new Error(`Exited with code ${exitCode}`));
|
|
7862
7862
|
return;
|
|
7863
7863
|
}
|
|
7864
|
-
|
|
7864
|
+
resolve2(subprocess);
|
|
7865
7865
|
});
|
|
7866
7866
|
});
|
|
7867
7867
|
}
|
|
@@ -12049,7 +12049,7 @@ var init_api = __esm({
|
|
|
12049
12049
|
|
|
12050
12050
|
// src/lib/util.ts
|
|
12051
12051
|
function sleep(ms) {
|
|
12052
|
-
return new Promise((
|
|
12052
|
+
return new Promise((resolve2) => setTimeout(resolve2, ms));
|
|
12053
12053
|
}
|
|
12054
12054
|
var init_util2 = __esm({
|
|
12055
12055
|
"src/lib/util.ts"() {
|
|
@@ -12117,8 +12117,8 @@ async function handleMissingGithubToken(bambooSession) {
|
|
|
12117
12117
|
async function startCallbackServer(expectedState) {
|
|
12118
12118
|
let resolveSession;
|
|
12119
12119
|
let rejectSession;
|
|
12120
|
-
const session = new Promise((
|
|
12121
|
-
resolveSession =
|
|
12120
|
+
const session = new Promise((resolve2, reject) => {
|
|
12121
|
+
resolveSession = resolve2;
|
|
12122
12122
|
rejectSession = reject;
|
|
12123
12123
|
});
|
|
12124
12124
|
const server = createServer((req, res) => {
|
|
@@ -12176,10 +12176,10 @@ async function startCallbackServer(expectedState) {
|
|
|
12176
12176
|
server.close();
|
|
12177
12177
|
}, LOGIN_TIMEOUT_MS);
|
|
12178
12178
|
timer.unref();
|
|
12179
|
-
const port = await new Promise((
|
|
12179
|
+
const port = await new Promise((resolve2, reject) => {
|
|
12180
12180
|
server.once("listening", () => {
|
|
12181
12181
|
const addr = server.address();
|
|
12182
|
-
if (addr && typeof addr === "object")
|
|
12182
|
+
if (addr && typeof addr === "object") resolve2(addr.port);
|
|
12183
12183
|
else reject(new Error("Couldn't bind localhost port"));
|
|
12184
12184
|
});
|
|
12185
12185
|
server.once("error", reject);
|
|
@@ -12312,6 +12312,18 @@ var init_login_phase = __esm({
|
|
|
12312
12312
|
});
|
|
12313
12313
|
|
|
12314
12314
|
// src/lib/git.ts
|
|
12315
|
+
var git_exports = {};
|
|
12316
|
+
__export(git_exports, {
|
|
12317
|
+
GitError: () => GitError,
|
|
12318
|
+
checkGitCredentialForGitHub: () => checkGitCredentialForGitHub,
|
|
12319
|
+
cloneRepo: () => cloneRepo,
|
|
12320
|
+
getGitConfig: () => getGitConfig,
|
|
12321
|
+
getRepoRemoteUrl: () => getRepoRemoteUrl,
|
|
12322
|
+
gitVersion: () => gitVersion,
|
|
12323
|
+
installGithubCredential: () => installGithubCredential,
|
|
12324
|
+
isGitRecentEnough: () => isGitRecentEnough,
|
|
12325
|
+
remoteUrlMatchesRepo: () => remoteUrlMatchesRepo
|
|
12326
|
+
});
|
|
12315
12327
|
import { execFile as execFile6 } from "node:child_process";
|
|
12316
12328
|
import { promisify as promisify6 } from "node:util";
|
|
12317
12329
|
async function gitVersion() {
|
|
@@ -12340,9 +12352,9 @@ password=${token}
|
|
|
12340
12352
|
const proc = child;
|
|
12341
12353
|
proc.stdin?.write(input);
|
|
12342
12354
|
proc.stdin?.end();
|
|
12343
|
-
await new Promise((
|
|
12355
|
+
await new Promise((resolve2, reject) => {
|
|
12344
12356
|
proc.on("exit", (code) => {
|
|
12345
|
-
if (code === 0)
|
|
12357
|
+
if (code === 0) resolve2();
|
|
12346
12358
|
else reject(new GitError(`git credential approve exited with code ${code}`));
|
|
12347
12359
|
});
|
|
12348
12360
|
proc.on("error", reject);
|
|
@@ -12362,7 +12374,7 @@ async function cloneRepo(repoFullName, targetDir) {
|
|
|
12362
12374
|
}
|
|
12363
12375
|
}
|
|
12364
12376
|
async function checkGitCredentialForGitHub() {
|
|
12365
|
-
return new Promise((
|
|
12377
|
+
return new Promise((resolve2) => {
|
|
12366
12378
|
const proc = execFile6(
|
|
12367
12379
|
"git",
|
|
12368
12380
|
["credential", "fill"],
|
|
@@ -12372,12 +12384,12 @@ async function checkGitCredentialForGitHub() {
|
|
|
12372
12384
|
},
|
|
12373
12385
|
(err, stdout) => {
|
|
12374
12386
|
if (err) {
|
|
12375
|
-
|
|
12387
|
+
resolve2(false);
|
|
12376
12388
|
return;
|
|
12377
12389
|
}
|
|
12378
12390
|
const hasOurUsername = /^username=x-access-token\s*$/m.test(stdout);
|
|
12379
12391
|
const hasPassword = /^password=\S+/m.test(stdout);
|
|
12380
|
-
|
|
12392
|
+
resolve2(hasOurUsername && hasPassword);
|
|
12381
12393
|
}
|
|
12382
12394
|
);
|
|
12383
12395
|
proc.stdin?.write("protocol=https\nhost=github.com\n\n");
|
|
@@ -12432,17 +12444,115 @@ var init_git = __esm({
|
|
|
12432
12444
|
}
|
|
12433
12445
|
});
|
|
12434
12446
|
|
|
12447
|
+
// src/lib/prompt.ts
|
|
12448
|
+
import { createInterface } from "node:readline";
|
|
12449
|
+
async function promptStdin(question, opts = {}) {
|
|
12450
|
+
const maxRetries = opts.maxRetries ?? 2;
|
|
12451
|
+
const isInteractive2 = process.stdin.isTTY === true;
|
|
12452
|
+
const rl = createInterface({
|
|
12453
|
+
input: process.stdin,
|
|
12454
|
+
output: process.stdout,
|
|
12455
|
+
terminal: isInteractive2
|
|
12456
|
+
});
|
|
12457
|
+
const onSigInt = () => {
|
|
12458
|
+
rl.close();
|
|
12459
|
+
};
|
|
12460
|
+
rl.on("SIGINT", onSigInt);
|
|
12461
|
+
try {
|
|
12462
|
+
let attempts = 0;
|
|
12463
|
+
while (attempts <= maxRetries) {
|
|
12464
|
+
const answer = await readOnce(rl, question);
|
|
12465
|
+
if (answer === null) return null;
|
|
12466
|
+
const trimmed = answer.trim();
|
|
12467
|
+
if (trimmed.length > 0) return trimmed;
|
|
12468
|
+
attempts += 1;
|
|
12469
|
+
if (attempts > maxRetries || !isInteractive2) return null;
|
|
12470
|
+
console.log(" (Press Enter without typing to skip \u2014 or answer Boo's question.)");
|
|
12471
|
+
}
|
|
12472
|
+
return null;
|
|
12473
|
+
} finally {
|
|
12474
|
+
rl.off("SIGINT", onSigInt);
|
|
12475
|
+
rl.close();
|
|
12476
|
+
}
|
|
12477
|
+
}
|
|
12478
|
+
function readOnce(rl, question) {
|
|
12479
|
+
return new Promise((resolve2) => {
|
|
12480
|
+
let resolved = false;
|
|
12481
|
+
const settle = (value) => {
|
|
12482
|
+
if (resolved) return;
|
|
12483
|
+
resolved = true;
|
|
12484
|
+
resolve2(value);
|
|
12485
|
+
};
|
|
12486
|
+
rl.once("close", () => settle(null));
|
|
12487
|
+
rl.question(question, (answer) => settle(answer));
|
|
12488
|
+
});
|
|
12489
|
+
}
|
|
12490
|
+
var init_prompt = __esm({
|
|
12491
|
+
"src/lib/prompt.ts"() {
|
|
12492
|
+
"use strict";
|
|
12493
|
+
}
|
|
12494
|
+
});
|
|
12495
|
+
|
|
12496
|
+
// src/lib/workspace.ts
|
|
12497
|
+
import { existsSync } from "node:fs";
|
|
12498
|
+
import os4 from "node:os";
|
|
12499
|
+
import { resolve as pathResolve } from "node:path";
|
|
12500
|
+
function defaultClonePath(orgSlug) {
|
|
12501
|
+
const cleanSlug = orgSlug.replace(/^bamboo-?/i, "") || orgSlug;
|
|
12502
|
+
return pathResolve(os4.homedir(), "Bamboo", cleanSlug);
|
|
12503
|
+
}
|
|
12504
|
+
async function resolveWorkspace() {
|
|
12505
|
+
const state = await readState();
|
|
12506
|
+
if (state) {
|
|
12507
|
+
if (!existsSync(state.workspace_path)) {
|
|
12508
|
+
throw new NoWorkspaceError(
|
|
12509
|
+
`Bamboo workspace not found.
|
|
12510
|
+
(State recorded ${state.workspace_path} but it's missing on disk \u2014 run \`bamboo-agents init --reset\` to re-clone.)`
|
|
12511
|
+
);
|
|
12512
|
+
}
|
|
12513
|
+
return { path: state.workspace_path, orgId: state.org_id };
|
|
12514
|
+
}
|
|
12515
|
+
const config = await readConfig();
|
|
12516
|
+
if (config) {
|
|
12517
|
+
if (!existsSync(config.repo_path)) {
|
|
12518
|
+
throw new NoWorkspaceError(
|
|
12519
|
+
`Bamboo workspace not found.
|
|
12520
|
+
(Config recorded ${config.repo_path} but it's missing on disk \u2014 run \`bamboo-agents init --reset\` to re-clone.)`
|
|
12521
|
+
);
|
|
12522
|
+
}
|
|
12523
|
+
return { path: config.repo_path, orgId: config.org_id };
|
|
12524
|
+
}
|
|
12525
|
+
throw new NoWorkspaceError(
|
|
12526
|
+
"No Bamboo workspace yet. Run `bamboo-agents init` first."
|
|
12527
|
+
);
|
|
12528
|
+
}
|
|
12529
|
+
var NoWorkspaceError;
|
|
12530
|
+
var init_workspace = __esm({
|
|
12531
|
+
"src/lib/workspace.ts"() {
|
|
12532
|
+
"use strict";
|
|
12533
|
+
init_state();
|
|
12534
|
+
NoWorkspaceError = class extends Error {
|
|
12535
|
+
constructor(message) {
|
|
12536
|
+
super(message);
|
|
12537
|
+
this.name = "NoWorkspaceError";
|
|
12538
|
+
}
|
|
12539
|
+
};
|
|
12540
|
+
}
|
|
12541
|
+
});
|
|
12542
|
+
|
|
12435
12543
|
// src/commands/init.ts
|
|
12436
12544
|
var init_exports = {};
|
|
12437
12545
|
__export(init_exports, {
|
|
12438
12546
|
WORKSPACE_POLL: () => WORKSPACE_POLL,
|
|
12547
|
+
confirmReset: () => confirmReset,
|
|
12548
|
+
decideInitBranch: () => decideInitBranch,
|
|
12549
|
+
interpretResetAnswer: () => interpretResetAnswer,
|
|
12439
12550
|
pollForWorkspaceReady: () => pollForWorkspaceReady,
|
|
12440
12551
|
preProvisionWorkspace: () => preProvisionWorkspace,
|
|
12441
12552
|
runInit: () => runInit,
|
|
12442
12553
|
slugify: () => slugify
|
|
12443
12554
|
});
|
|
12444
|
-
import { access } from "node:fs/promises";
|
|
12445
|
-
import { resolve as pathResolve } from "node:path";
|
|
12555
|
+
import { access, rm } from "node:fs/promises";
|
|
12446
12556
|
async function pollForWorkspaceReady(bambooSession, initial) {
|
|
12447
12557
|
if (initial.workspace_ready && initial.org.workspace_repo) {
|
|
12448
12558
|
return { ok: true, membership: initial };
|
|
@@ -12482,7 +12592,35 @@ async function preProvisionWorkspace(bambooSession, call = provisionWorkspace) {
|
|
|
12482
12592
|
return { kind: "transient", message: err.message };
|
|
12483
12593
|
}
|
|
12484
12594
|
}
|
|
12485
|
-
async function
|
|
12595
|
+
async function confirmReset(targetPath) {
|
|
12596
|
+
console.log(` ! \`--reset\` will delete: ${targetPath}`);
|
|
12597
|
+
if (process.stdin.isTTY !== true) return true;
|
|
12598
|
+
const answer = await promptStdin(" Continue? [Y/n] ");
|
|
12599
|
+
return interpretResetAnswer(answer);
|
|
12600
|
+
}
|
|
12601
|
+
function interpretResetAnswer(answer) {
|
|
12602
|
+
if (answer === null) return true;
|
|
12603
|
+
const normalized = answer.trim().toLowerCase();
|
|
12604
|
+
if (normalized === "" || normalized === "y" || normalized === "yes") {
|
|
12605
|
+
return true;
|
|
12606
|
+
}
|
|
12607
|
+
return false;
|
|
12608
|
+
}
|
|
12609
|
+
function decideInitBranch(input) {
|
|
12610
|
+
const { hasState, recordedPath, dirExists, canonicalPath, reset } = input;
|
|
12611
|
+
if (reset) {
|
|
12612
|
+
return {
|
|
12613
|
+
kind: "reset_then_clone",
|
|
12614
|
+
path: hasState && recordedPath || canonicalPath
|
|
12615
|
+
};
|
|
12616
|
+
}
|
|
12617
|
+
if (hasState && recordedPath) {
|
|
12618
|
+
if (dirExists) return { kind: "short_circuit", path: recordedPath };
|
|
12619
|
+
return { kind: "reclone_recorded", path: recordedPath };
|
|
12620
|
+
}
|
|
12621
|
+
return { kind: "fresh_clone", path: canonicalPath };
|
|
12622
|
+
}
|
|
12623
|
+
async function runInit(options = {}) {
|
|
12486
12624
|
const creds = await readCredentials();
|
|
12487
12625
|
if (!creds) {
|
|
12488
12626
|
console.error("No credentials found. Run `bamboo-agents login` first.");
|
|
@@ -12602,33 +12740,114 @@ async function runInit() {
|
|
|
12602
12740
|
process.exit(1);
|
|
12603
12741
|
}
|
|
12604
12742
|
const orgSlug = slugify(membership.org.name);
|
|
12605
|
-
const
|
|
12606
|
-
let
|
|
12743
|
+
const canonicalPath = defaultClonePath(orgSlug);
|
|
12744
|
+
let existingState;
|
|
12607
12745
|
try {
|
|
12608
|
-
await
|
|
12609
|
-
|
|
12746
|
+
existingState = await readState();
|
|
12747
|
+
} catch (err) {
|
|
12748
|
+
if (err instanceof WorkspaceStateError) {
|
|
12749
|
+
console.error(`
|
|
12750
|
+
${err.message}
|
|
12751
|
+
`);
|
|
12752
|
+
process.exit(2);
|
|
12753
|
+
}
|
|
12754
|
+
throw err;
|
|
12755
|
+
}
|
|
12756
|
+
const targetPath = existingState?.workspace_path ?? canonicalPath;
|
|
12757
|
+
if (options.reset) {
|
|
12758
|
+
const confirmed = await confirmReset(targetPath);
|
|
12759
|
+
if (!confirmed) {
|
|
12760
|
+
console.log(" Aborted \u2014 workspace untouched.");
|
|
12761
|
+
process.exit(2);
|
|
12762
|
+
}
|
|
12763
|
+
const resetSpinner = ora(`Removing ${targetPath}\u2026`).start();
|
|
12764
|
+
try {
|
|
12765
|
+
await rm(targetPath, { recursive: true, force: true });
|
|
12766
|
+
resetSpinner.succeed(`Removed ${targetPath}`);
|
|
12767
|
+
} catch (err) {
|
|
12768
|
+
resetSpinner.fail(`Couldn't remove ${targetPath}: ${err.message}`);
|
|
12769
|
+
process.exit(1);
|
|
12770
|
+
}
|
|
12771
|
+
await cloneAndPersist(targetPath, membership);
|
|
12772
|
+
return;
|
|
12773
|
+
}
|
|
12774
|
+
if (existingState) {
|
|
12775
|
+
let dirExists = false;
|
|
12776
|
+
try {
|
|
12777
|
+
await access(existingState.workspace_path);
|
|
12778
|
+
dirExists = true;
|
|
12779
|
+
} catch {
|
|
12780
|
+
}
|
|
12781
|
+
if (dirExists) {
|
|
12782
|
+
const existingRemote = await getRepoRemoteUrl(existingState.workspace_path);
|
|
12783
|
+
const matches = existingRemote != null && remoteUrlMatchesRepo(existingRemote, membership.org.workspace_repo);
|
|
12784
|
+
if (matches) {
|
|
12785
|
+
await writeConfig({
|
|
12786
|
+
org_id: membership.org.id,
|
|
12787
|
+
org_name: membership.org.name,
|
|
12788
|
+
workspace_repo: membership.org.workspace_repo,
|
|
12789
|
+
repo_path: existingState.workspace_path,
|
|
12790
|
+
installed_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
12791
|
+
});
|
|
12792
|
+
console.log("");
|
|
12793
|
+
console.log(` \u2713 Workspace already at ${existingState.workspace_path}`);
|
|
12794
|
+
console.log(" (init is idempotent \u2014 re-run with --reset to start over)");
|
|
12795
|
+
console.log("");
|
|
12796
|
+
return;
|
|
12797
|
+
}
|
|
12798
|
+
console.error(
|
|
12799
|
+
`
|
|
12800
|
+
${existingState.workspace_path} exists but its origin doesn't match your workspace repo.
|
|
12801
|
+
|
|
12802
|
+
` + (existingRemote ? ` Found origin: ${existingRemote}
|
|
12803
|
+
Expected: github.com/${membership.org.workspace_repo}
|
|
12804
|
+
|
|
12805
|
+
` : ` It's not a git repo (no origin remote).
|
|
12806
|
+
|
|
12807
|
+
`) + " Re-run with `bamboo-agents init --reset` to start over, or move the directory aside.\n"
|
|
12808
|
+
);
|
|
12809
|
+
process.exit(2);
|
|
12810
|
+
}
|
|
12811
|
+
console.log(` State points at ${existingState.workspace_path}, but the directory is missing \u2014 re-cloning there.`);
|
|
12812
|
+
await cloneAndPersist(existingState.workspace_path, membership);
|
|
12813
|
+
return;
|
|
12814
|
+
}
|
|
12815
|
+
let canonicalExists = false;
|
|
12816
|
+
try {
|
|
12817
|
+
await access(canonicalPath);
|
|
12818
|
+
canonicalExists = true;
|
|
12610
12819
|
} catch {
|
|
12611
12820
|
}
|
|
12612
|
-
if (
|
|
12613
|
-
const existingRemote = await getRepoRemoteUrl(
|
|
12821
|
+
if (canonicalExists) {
|
|
12822
|
+
const existingRemote = await getRepoRemoteUrl(canonicalPath);
|
|
12614
12823
|
const matches = existingRemote != null && remoteUrlMatchesRepo(existingRemote, membership.org.workspace_repo);
|
|
12615
12824
|
if (matches) {
|
|
12616
12825
|
await writeConfig({
|
|
12617
12826
|
org_id: membership.org.id,
|
|
12618
12827
|
org_name: membership.org.name,
|
|
12619
12828
|
workspace_repo: membership.org.workspace_repo,
|
|
12620
|
-
repo_path:
|
|
12829
|
+
repo_path: canonicalPath,
|
|
12621
12830
|
installed_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
12622
12831
|
});
|
|
12832
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
12833
|
+
await writeState({
|
|
12834
|
+
$schema_version: STATE_SCHEMA_VERSION,
|
|
12835
|
+
workspace_path: canonicalPath,
|
|
12836
|
+
org_id: membership.org.id,
|
|
12837
|
+
org_slug: orgSlug,
|
|
12838
|
+
cloned_at: now,
|
|
12839
|
+
last_sync: now,
|
|
12840
|
+
remote_url: `https://github.com/${membership.org.workspace_repo}`
|
|
12841
|
+
});
|
|
12623
12842
|
console.log("");
|
|
12624
|
-
console.log(` \u2713
|
|
12625
|
-
console.log(" (
|
|
12843
|
+
console.log(` \u2713 Adopted existing workspace at ${canonicalPath}`);
|
|
12844
|
+
console.log(" (origin matches \u2014 registered in state.json)");
|
|
12626
12845
|
console.log("");
|
|
12627
12846
|
return;
|
|
12628
12847
|
}
|
|
12629
12848
|
console.error(
|
|
12630
12849
|
`
|
|
12631
|
-
${
|
|
12850
|
+
${canonicalPath} already exists and is NOT the right repo.
|
|
12632
12851
|
|
|
12633
12852
|
` + (existingRemote ? ` Found origin: ${existingRemote}
|
|
12634
12853
|
Expected: github.com/${membership.org.workspace_repo}
|
|
@@ -12639,7 +12858,12 @@ async function runInit() {
|
|
|
12639
12858
|
);
|
|
12640
12859
|
process.exit(2);
|
|
12641
12860
|
}
|
|
12642
|
-
|
|
12861
|
+
await cloneAndPersist(canonicalPath, membership);
|
|
12862
|
+
}
|
|
12863
|
+
async function cloneAndPersist(repoPath, membership) {
|
|
12864
|
+
const cloneSpinner = ora(
|
|
12865
|
+
`Cloning ${membership.org.workspace_repo} \u2192 ${repoPath}\u2026`
|
|
12866
|
+
).start();
|
|
12643
12867
|
try {
|
|
12644
12868
|
await cloneRepo(membership.org.workspace_repo, repoPath);
|
|
12645
12869
|
cloneSpinner.succeed(`Cloned to ${repoPath}`);
|
|
@@ -12654,6 +12878,16 @@ async function runInit() {
|
|
|
12654
12878
|
repo_path: repoPath,
|
|
12655
12879
|
installed_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
12656
12880
|
});
|
|
12881
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
12882
|
+
await writeState({
|
|
12883
|
+
$schema_version: 1,
|
|
12884
|
+
workspace_path: repoPath,
|
|
12885
|
+
org_id: membership.org.id,
|
|
12886
|
+
org_slug: slugify(membership.org.name),
|
|
12887
|
+
cloned_at: now,
|
|
12888
|
+
last_sync: now,
|
|
12889
|
+
remote_url: `https://github.com/${membership.org.workspace_repo}`
|
|
12890
|
+
});
|
|
12657
12891
|
console.log("");
|
|
12658
12892
|
console.log(` \u2713 Workspace ready at ${repoPath}`);
|
|
12659
12893
|
console.log(" Next: `bamboo-agents open` to launch Claude Code there.");
|
|
@@ -12667,8 +12901,10 @@ var init_init = __esm({
|
|
|
12667
12901
|
init_api();
|
|
12668
12902
|
init_credentials();
|
|
12669
12903
|
init_git();
|
|
12904
|
+
init_prompt();
|
|
12670
12905
|
init_state();
|
|
12671
12906
|
init_util2();
|
|
12907
|
+
init_workspace();
|
|
12672
12908
|
WORKSPACE_POLL = {
|
|
12673
12909
|
intervalMs: 2e3,
|
|
12674
12910
|
timeoutMs: 5 * 60 * 1e3
|
|
@@ -12932,55 +13168,6 @@ var init_clone_or_adopt_phase = __esm({
|
|
|
12932
13168
|
}
|
|
12933
13169
|
});
|
|
12934
13170
|
|
|
12935
|
-
// src/lib/prompt.ts
|
|
12936
|
-
import { createInterface } from "node:readline";
|
|
12937
|
-
async function promptStdin(question, opts = {}) {
|
|
12938
|
-
const maxRetries = opts.maxRetries ?? 2;
|
|
12939
|
-
const isInteractive2 = process.stdin.isTTY === true;
|
|
12940
|
-
const rl = createInterface({
|
|
12941
|
-
input: process.stdin,
|
|
12942
|
-
output: process.stdout,
|
|
12943
|
-
terminal: isInteractive2
|
|
12944
|
-
});
|
|
12945
|
-
const onSigInt = () => {
|
|
12946
|
-
rl.close();
|
|
12947
|
-
};
|
|
12948
|
-
rl.on("SIGINT", onSigInt);
|
|
12949
|
-
try {
|
|
12950
|
-
let attempts = 0;
|
|
12951
|
-
while (attempts <= maxRetries) {
|
|
12952
|
-
const answer = await readOnce(rl, question);
|
|
12953
|
-
if (answer === null) return null;
|
|
12954
|
-
const trimmed = answer.trim();
|
|
12955
|
-
if (trimmed.length > 0) return trimmed;
|
|
12956
|
-
attempts += 1;
|
|
12957
|
-
if (attempts > maxRetries || !isInteractive2) return null;
|
|
12958
|
-
console.log(" (Press Enter without typing to skip \u2014 or answer Boo's question.)");
|
|
12959
|
-
}
|
|
12960
|
-
return null;
|
|
12961
|
-
} finally {
|
|
12962
|
-
rl.off("SIGINT", onSigInt);
|
|
12963
|
-
rl.close();
|
|
12964
|
-
}
|
|
12965
|
-
}
|
|
12966
|
-
function readOnce(rl, question) {
|
|
12967
|
-
return new Promise((resolve) => {
|
|
12968
|
-
let resolved = false;
|
|
12969
|
-
const settle = (value) => {
|
|
12970
|
-
if (resolved) return;
|
|
12971
|
-
resolved = true;
|
|
12972
|
-
resolve(value);
|
|
12973
|
-
};
|
|
12974
|
-
rl.once("close", () => settle(null));
|
|
12975
|
-
rl.question(question, (answer) => settle(answer));
|
|
12976
|
-
});
|
|
12977
|
-
}
|
|
12978
|
-
var init_prompt = __esm({
|
|
12979
|
-
"src/lib/prompt.ts"() {
|
|
12980
|
-
"use strict";
|
|
12981
|
-
}
|
|
12982
|
-
});
|
|
12983
|
-
|
|
12984
13171
|
// src/lib/phases-impl/pick-first-user-agent-phase.ts
|
|
12985
13172
|
import { readdir, readFile as readFile3, stat } from "node:fs/promises";
|
|
12986
13173
|
import { dirname, join as pathJoin, resolve as pathResolve3 } from "node:path";
|
|
@@ -13099,11 +13286,11 @@ async function runUploadFlow(ctx) {
|
|
|
13099
13286
|
console.log(" \u2026");
|
|
13100
13287
|
}
|
|
13101
13288
|
console.log("");
|
|
13102
|
-
const
|
|
13289
|
+
const confirm2 = await promptChoice(
|
|
13103
13290
|
" Upload this? [y/n]: ",
|
|
13104
13291
|
["y", "n", "Y", "N"]
|
|
13105
13292
|
);
|
|
13106
|
-
if (
|
|
13293
|
+
if (confirm2 === null || confirm2.toLowerCase() !== "y") return null;
|
|
13107
13294
|
console.log("");
|
|
13108
13295
|
const name = await promptStdin(
|
|
13109
13296
|
" Name this agent (e.g. My Existing Agent): "
|
|
@@ -13728,47 +13915,6 @@ var init_claude_desktop = __esm({
|
|
|
13728
13915
|
}
|
|
13729
13916
|
});
|
|
13730
13917
|
|
|
13731
|
-
// src/lib/workspace.ts
|
|
13732
|
-
import { existsSync } from "node:fs";
|
|
13733
|
-
async function resolveWorkspace() {
|
|
13734
|
-
const state = await readState();
|
|
13735
|
-
if (state) {
|
|
13736
|
-
if (!existsSync(state.workspace_path)) {
|
|
13737
|
-
throw new NoWorkspaceError(
|
|
13738
|
-
`Bamboo workspace not found.
|
|
13739
|
-
(State recorded ${state.workspace_path} but it's missing on disk \u2014 run \`bamboo-agents init --reset\` to re-clone.)`
|
|
13740
|
-
);
|
|
13741
|
-
}
|
|
13742
|
-
return { path: state.workspace_path, orgId: state.org_id };
|
|
13743
|
-
}
|
|
13744
|
-
const config = await readConfig();
|
|
13745
|
-
if (config) {
|
|
13746
|
-
if (!existsSync(config.repo_path)) {
|
|
13747
|
-
throw new NoWorkspaceError(
|
|
13748
|
-
`Bamboo workspace not found.
|
|
13749
|
-
(Config recorded ${config.repo_path} but it's missing on disk \u2014 run \`bamboo-agents init --reset\` to re-clone.)`
|
|
13750
|
-
);
|
|
13751
|
-
}
|
|
13752
|
-
return { path: config.repo_path, orgId: config.org_id };
|
|
13753
|
-
}
|
|
13754
|
-
throw new NoWorkspaceError(
|
|
13755
|
-
"No Bamboo workspace yet. Run `bamboo-agents init` first."
|
|
13756
|
-
);
|
|
13757
|
-
}
|
|
13758
|
-
var NoWorkspaceError;
|
|
13759
|
-
var init_workspace = __esm({
|
|
13760
|
-
"src/lib/workspace.ts"() {
|
|
13761
|
-
"use strict";
|
|
13762
|
-
init_state();
|
|
13763
|
-
NoWorkspaceError = class extends Error {
|
|
13764
|
-
constructor(message) {
|
|
13765
|
-
super(message);
|
|
13766
|
-
this.name = "NoWorkspaceError";
|
|
13767
|
-
}
|
|
13768
|
-
};
|
|
13769
|
-
}
|
|
13770
|
-
});
|
|
13771
|
-
|
|
13772
13918
|
// src/commands/open.ts
|
|
13773
13919
|
var open_exports = {};
|
|
13774
13920
|
__export(open_exports, {
|
|
@@ -13886,14 +14032,317 @@ var init_status = __esm({
|
|
|
13886
14032
|
}
|
|
13887
14033
|
});
|
|
13888
14034
|
|
|
14035
|
+
// src/lib/workspace-health.ts
|
|
14036
|
+
import { execFile as execFile8 } from "node:child_process";
|
|
14037
|
+
import { promisify as promisify8 } from "node:util";
|
|
14038
|
+
import { lstat, readlink, readdir as readdir2, mkdir as mkdir3, symlink, rm as rm2, access as access3 } from "node:fs/promises";
|
|
14039
|
+
import { join as join2, dirname as dirname2, resolve } from "node:path";
|
|
14040
|
+
import { homedir as homedir2 } from "node:os";
|
|
14041
|
+
function getStaleSyncHours() {
|
|
14042
|
+
const raw = process.env.BAMBOO_STALE_SYNC_HOURS;
|
|
14043
|
+
if (!raw) return DEFAULT_STALE_SYNC_HOURS;
|
|
14044
|
+
const n = Number(raw);
|
|
14045
|
+
if (!Number.isFinite(n) || n <= 0) return DEFAULT_STALE_SYNC_HOURS;
|
|
14046
|
+
return n;
|
|
14047
|
+
}
|
|
14048
|
+
function cloneSearchRoots(cwd) {
|
|
14049
|
+
const overridden = process.env.BAMBOO_CLONE_SEARCH_DIRS;
|
|
14050
|
+
const home = homedir2();
|
|
14051
|
+
const base = overridden ? overridden.split(":").filter(Boolean) : [home, join2(home, "Documents"), join2(home, "Downloads"), join2(home, "Desktop")];
|
|
14052
|
+
const walk = [];
|
|
14053
|
+
let cur = cwd ?? process.cwd();
|
|
14054
|
+
for (let i = 0; i < 20; i++) {
|
|
14055
|
+
walk.push(cur);
|
|
14056
|
+
const parent = dirname2(cur);
|
|
14057
|
+
if (parent === cur) break;
|
|
14058
|
+
if (parent === home) {
|
|
14059
|
+
walk.push(home);
|
|
14060
|
+
break;
|
|
14061
|
+
}
|
|
14062
|
+
cur = parent;
|
|
14063
|
+
}
|
|
14064
|
+
const seen = /* @__PURE__ */ new Set();
|
|
14065
|
+
const out = [];
|
|
14066
|
+
for (const p of [...base, ...walk]) {
|
|
14067
|
+
const norm = resolve(p);
|
|
14068
|
+
if (seen.has(norm)) continue;
|
|
14069
|
+
seen.add(norm);
|
|
14070
|
+
out.push(norm);
|
|
14071
|
+
}
|
|
14072
|
+
return out;
|
|
14073
|
+
}
|
|
14074
|
+
async function findClones(remoteUrl, roots, maxDepth = 4) {
|
|
14075
|
+
const found = /* @__PURE__ */ new Set();
|
|
14076
|
+
let scanned = 0;
|
|
14077
|
+
async function visit(dir, depth) {
|
|
14078
|
+
if (scanned >= MAX_DIRS_SCANNED) return;
|
|
14079
|
+
if (depth < 0) return;
|
|
14080
|
+
scanned += 1;
|
|
14081
|
+
const gitDir = join2(dir, ".git");
|
|
14082
|
+
let isRepo = false;
|
|
14083
|
+
try {
|
|
14084
|
+
const s = await lstat(gitDir);
|
|
14085
|
+
isRepo = s.isDirectory() || s.isFile();
|
|
14086
|
+
} catch {
|
|
14087
|
+
isRepo = false;
|
|
14088
|
+
}
|
|
14089
|
+
if (isRepo) {
|
|
14090
|
+
const url = await getRepoRemoteUrl(dir);
|
|
14091
|
+
if (url && matchesRemote(url, remoteUrl)) {
|
|
14092
|
+
found.add(resolve(dir));
|
|
14093
|
+
}
|
|
14094
|
+
return;
|
|
14095
|
+
}
|
|
14096
|
+
let entries = [];
|
|
14097
|
+
try {
|
|
14098
|
+
entries = await readdir2(dir, { withFileTypes: true });
|
|
14099
|
+
} catch {
|
|
14100
|
+
return;
|
|
14101
|
+
}
|
|
14102
|
+
for (const entry of entries) {
|
|
14103
|
+
if (!entry.isDirectory() || entry.isSymbolicLink()) continue;
|
|
14104
|
+
if (entry.name.startsWith(".")) {
|
|
14105
|
+
if (SKIP_DIRS.has(entry.name)) continue;
|
|
14106
|
+
}
|
|
14107
|
+
if (SKIP_DIRS.has(entry.name)) continue;
|
|
14108
|
+
await visit(join2(dir, entry.name), depth - 1);
|
|
14109
|
+
}
|
|
14110
|
+
}
|
|
14111
|
+
for (const root of roots) {
|
|
14112
|
+
try {
|
|
14113
|
+
await access3(root);
|
|
14114
|
+
} catch {
|
|
14115
|
+
continue;
|
|
14116
|
+
}
|
|
14117
|
+
await visit(root, maxDepth);
|
|
14118
|
+
}
|
|
14119
|
+
return [...found];
|
|
14120
|
+
}
|
|
14121
|
+
function matchesRemote(a, b) {
|
|
14122
|
+
const slugA = remoteUrlSlug(a);
|
|
14123
|
+
const slugB = remoteUrlSlug(b);
|
|
14124
|
+
if (!slugA || !slugB) return false;
|
|
14125
|
+
return slugA.toLowerCase() === slugB.toLowerCase();
|
|
14126
|
+
}
|
|
14127
|
+
function remoteUrlSlug(url) {
|
|
14128
|
+
const cleaned = url.trim().replace(/\.git$/i, "");
|
|
14129
|
+
const https = cleaned.match(/^https?:\/\/[^/]*github\.com\/(.+)$/i);
|
|
14130
|
+
if (https && https[1]) return https[1];
|
|
14131
|
+
const ssh = cleaned.match(/^[^@]+@github\.com:(.+)$/i);
|
|
14132
|
+
if (ssh && ssh[1]) return ssh[1];
|
|
14133
|
+
if (/^[^/]+\/[^/]+$/.test(cleaned)) return cleaned;
|
|
14134
|
+
return null;
|
|
14135
|
+
}
|
|
14136
|
+
async function checkAdapters(workspacePath) {
|
|
14137
|
+
const out = [];
|
|
14138
|
+
for (const { path: path2, target } of CROSS_TOOL_ADAPTERS) {
|
|
14139
|
+
const full = join2(workspacePath, path2);
|
|
14140
|
+
let s;
|
|
14141
|
+
try {
|
|
14142
|
+
s = await lstat(full);
|
|
14143
|
+
} catch {
|
|
14144
|
+
out.push({ path: path2, expectedTarget: target, ok: false, state: "missing", actualTarget: null });
|
|
14145
|
+
continue;
|
|
14146
|
+
}
|
|
14147
|
+
if (!s.isSymbolicLink()) {
|
|
14148
|
+
out.push({
|
|
14149
|
+
path: path2,
|
|
14150
|
+
expectedTarget: target,
|
|
14151
|
+
ok: false,
|
|
14152
|
+
state: "not_symlink",
|
|
14153
|
+
actualTarget: null
|
|
14154
|
+
});
|
|
14155
|
+
continue;
|
|
14156
|
+
}
|
|
14157
|
+
let actual;
|
|
14158
|
+
try {
|
|
14159
|
+
actual = await readlink(full);
|
|
14160
|
+
} catch {
|
|
14161
|
+
out.push({ path: path2, expectedTarget: target, ok: false, state: "missing", actualTarget: null });
|
|
14162
|
+
continue;
|
|
14163
|
+
}
|
|
14164
|
+
if (actual === target) {
|
|
14165
|
+
out.push({ path: path2, expectedTarget: target, ok: true, state: "ok", actualTarget: actual });
|
|
14166
|
+
} else {
|
|
14167
|
+
out.push({
|
|
14168
|
+
path: path2,
|
|
14169
|
+
expectedTarget: target,
|
|
14170
|
+
ok: false,
|
|
14171
|
+
state: "wrong_target",
|
|
14172
|
+
actualTarget: actual
|
|
14173
|
+
});
|
|
14174
|
+
}
|
|
14175
|
+
}
|
|
14176
|
+
return out;
|
|
14177
|
+
}
|
|
14178
|
+
async function healAdapters(workspacePath) {
|
|
14179
|
+
const fixed = [];
|
|
14180
|
+
const current = await checkAdapters(workspacePath);
|
|
14181
|
+
for (const status of current) {
|
|
14182
|
+
if (status.ok) continue;
|
|
14183
|
+
const full = join2(workspacePath, status.path);
|
|
14184
|
+
if (status.state === "wrong_target" || status.state === "not_symlink") {
|
|
14185
|
+
try {
|
|
14186
|
+
await rm2(full, { recursive: true, force: true });
|
|
14187
|
+
} catch {
|
|
14188
|
+
}
|
|
14189
|
+
}
|
|
14190
|
+
await mkdir3(dirname2(full), { recursive: true });
|
|
14191
|
+
await symlink(status.expectedTarget, full);
|
|
14192
|
+
fixed.push(status.path);
|
|
14193
|
+
}
|
|
14194
|
+
return fixed;
|
|
14195
|
+
}
|
|
14196
|
+
function isStaleSync(lastSync, hours = getStaleSyncHours()) {
|
|
14197
|
+
const parsed = Date.parse(lastSync);
|
|
14198
|
+
if (Number.isNaN(parsed)) return true;
|
|
14199
|
+
return Date.now() - parsed > hours * 60 * 60 * 1e3;
|
|
14200
|
+
}
|
|
14201
|
+
function describeAge(lastSync) {
|
|
14202
|
+
const parsed = Date.parse(lastSync);
|
|
14203
|
+
if (Number.isNaN(parsed)) return "unknown";
|
|
14204
|
+
const ms = Date.now() - parsed;
|
|
14205
|
+
const hours = Math.floor(ms / (60 * 60 * 1e3));
|
|
14206
|
+
if (hours < 1) return "<1h";
|
|
14207
|
+
if (hours < 48) return `${hours}h`;
|
|
14208
|
+
const days = Math.floor(hours / 24);
|
|
14209
|
+
return `${days}d`;
|
|
14210
|
+
}
|
|
14211
|
+
async function gitPullFfOnly(workspacePath) {
|
|
14212
|
+
try {
|
|
14213
|
+
const { stderr } = await execFileP3("git", ["-C", workspacePath, "pull", "--ff-only"], {
|
|
14214
|
+
encoding: "utf8"
|
|
14215
|
+
});
|
|
14216
|
+
return { ok: true, stderr };
|
|
14217
|
+
} catch (err) {
|
|
14218
|
+
const e = err;
|
|
14219
|
+
return { ok: false, stderr: e.stderr ?? e.message };
|
|
14220
|
+
}
|
|
14221
|
+
}
|
|
14222
|
+
async function pathExists(p) {
|
|
14223
|
+
try {
|
|
14224
|
+
await access3(p);
|
|
14225
|
+
return true;
|
|
14226
|
+
} catch {
|
|
14227
|
+
return false;
|
|
14228
|
+
}
|
|
14229
|
+
}
|
|
14230
|
+
var execFileP3, CROSS_TOOL_ADAPTERS, DEFAULT_STALE_SYNC_HOURS, MAX_DIRS_SCANNED, SKIP_DIRS;
|
|
14231
|
+
var init_workspace_health = __esm({
|
|
14232
|
+
"src/lib/workspace-health.ts"() {
|
|
14233
|
+
"use strict";
|
|
14234
|
+
init_git();
|
|
14235
|
+
execFileP3 = promisify8(execFile8);
|
|
14236
|
+
CROSS_TOOL_ADAPTERS = [
|
|
14237
|
+
{ path: ".claude/skills", target: "../skills" },
|
|
14238
|
+
{ path: ".cursor/skills", target: "../skills" },
|
|
14239
|
+
{ path: ".agents/skills", target: "../skills" }
|
|
14240
|
+
];
|
|
14241
|
+
DEFAULT_STALE_SYNC_HOURS = 24;
|
|
14242
|
+
MAX_DIRS_SCANNED = 2e3;
|
|
14243
|
+
SKIP_DIRS = /* @__PURE__ */ new Set([
|
|
14244
|
+
"node_modules",
|
|
14245
|
+
".git",
|
|
14246
|
+
".cache",
|
|
14247
|
+
".npm",
|
|
14248
|
+
".pnpm",
|
|
14249
|
+
".pnpm-store",
|
|
14250
|
+
".turbo",
|
|
14251
|
+
".next",
|
|
14252
|
+
".vercel",
|
|
14253
|
+
"dist",
|
|
14254
|
+
"build",
|
|
14255
|
+
"out",
|
|
14256
|
+
"Library",
|
|
14257
|
+
// macOS — never anything interesting for our purposes
|
|
14258
|
+
"Pictures",
|
|
14259
|
+
"Movies",
|
|
14260
|
+
"Music"
|
|
14261
|
+
]);
|
|
14262
|
+
}
|
|
14263
|
+
});
|
|
14264
|
+
|
|
14265
|
+
// src/lib/heal-prompt.ts
|
|
14266
|
+
import { createInterface as createInterface2 } from "node:readline";
|
|
14267
|
+
async function confirm(question, defaultValue = true) {
|
|
14268
|
+
if (!process.stdin.isTTY) return defaultValue;
|
|
14269
|
+
const hint = defaultValue ? "[Y/n]" : "[y/N]";
|
|
14270
|
+
const ask = `${question} ${hint} `;
|
|
14271
|
+
const rl = createInterface2({
|
|
14272
|
+
input: process.stdin,
|
|
14273
|
+
output: process.stdout,
|
|
14274
|
+
terminal: true
|
|
14275
|
+
});
|
|
14276
|
+
try {
|
|
14277
|
+
const answer = await readOnce2(rl, ask);
|
|
14278
|
+
if (answer === null) return null;
|
|
14279
|
+
const trimmed = answer.trim().toLowerCase();
|
|
14280
|
+
if (trimmed === "") return defaultValue;
|
|
14281
|
+
if (trimmed === "y" || trimmed === "yes") return true;
|
|
14282
|
+
if (trimmed === "n" || trimmed === "no") return false;
|
|
14283
|
+
return defaultValue;
|
|
14284
|
+
} finally {
|
|
14285
|
+
rl.close();
|
|
14286
|
+
}
|
|
14287
|
+
}
|
|
14288
|
+
async function choose(question, choices, defaultIndex = 0) {
|
|
14289
|
+
if (!process.stdin.isTTY) return defaultIndex;
|
|
14290
|
+
if (choices.length === 0) return null;
|
|
14291
|
+
console.log(question);
|
|
14292
|
+
for (let i = 0; i < choices.length; i++) {
|
|
14293
|
+
const letter = String.fromCharCode(65 + i);
|
|
14294
|
+
const marker = i === defaultIndex ? "\u203A" : " ";
|
|
14295
|
+
console.log(` ${marker} ${letter}. ${choices[i]}`);
|
|
14296
|
+
}
|
|
14297
|
+
const defaultLetter = String.fromCharCode(65 + defaultIndex);
|
|
14298
|
+
const ask = ` Pick [${defaultLetter}]: `;
|
|
14299
|
+
const rl = createInterface2({
|
|
14300
|
+
input: process.stdin,
|
|
14301
|
+
output: process.stdout,
|
|
14302
|
+
terminal: true
|
|
14303
|
+
});
|
|
14304
|
+
try {
|
|
14305
|
+
const answer = await readOnce2(rl, ask);
|
|
14306
|
+
if (answer === null) return null;
|
|
14307
|
+
const trimmed = answer.trim().toUpperCase();
|
|
14308
|
+
if (trimmed === "") return defaultIndex;
|
|
14309
|
+
if (trimmed.length === 1) {
|
|
14310
|
+
const idx = trimmed.charCodeAt(0) - 65;
|
|
14311
|
+
if (idx >= 0 && idx < choices.length) return idx;
|
|
14312
|
+
}
|
|
14313
|
+
return defaultIndex;
|
|
14314
|
+
} finally {
|
|
14315
|
+
rl.close();
|
|
14316
|
+
}
|
|
14317
|
+
}
|
|
14318
|
+
function readOnce2(rl, question) {
|
|
14319
|
+
return new Promise((resolve2) => {
|
|
14320
|
+
let resolved = false;
|
|
14321
|
+
const settle = (value) => {
|
|
14322
|
+
if (resolved) return;
|
|
14323
|
+
resolved = true;
|
|
14324
|
+
resolve2(value);
|
|
14325
|
+
};
|
|
14326
|
+
rl.once("close", () => settle(null));
|
|
14327
|
+
rl.question(question, (answer) => settle(answer));
|
|
14328
|
+
});
|
|
14329
|
+
}
|
|
14330
|
+
var init_heal_prompt = __esm({
|
|
14331
|
+
"src/lib/heal-prompt.ts"() {
|
|
14332
|
+
"use strict";
|
|
14333
|
+
}
|
|
14334
|
+
});
|
|
14335
|
+
|
|
13889
14336
|
// src/commands/doctor.ts
|
|
13890
14337
|
var doctor_exports = {};
|
|
13891
14338
|
__export(doctor_exports, {
|
|
13892
14339
|
checkBambooSession: () => checkBambooSession,
|
|
13893
14340
|
checkGitCredential: () => checkGitCredential,
|
|
14341
|
+
collectDriftFindings: () => collectDriftFindings,
|
|
13894
14342
|
runDoctor: () => runDoctor
|
|
13895
14343
|
});
|
|
13896
|
-
import { access as
|
|
14344
|
+
import { access as access4 } from "node:fs/promises";
|
|
14345
|
+
import { rm as rm3 } from "node:fs/promises";
|
|
13897
14346
|
async function checkGit() {
|
|
13898
14347
|
const v = await gitVersion();
|
|
13899
14348
|
if (!v) {
|
|
@@ -13986,7 +14435,7 @@ async function checkRepoPath() {
|
|
|
13986
14435
|
};
|
|
13987
14436
|
}
|
|
13988
14437
|
try {
|
|
13989
|
-
await
|
|
14438
|
+
await access4(cfg.repo_path);
|
|
13990
14439
|
return { name: "Repo cloned", ok: true, detail: cfg.repo_path };
|
|
13991
14440
|
} catch {
|
|
13992
14441
|
return {
|
|
@@ -13996,26 +14445,331 @@ async function checkRepoPath() {
|
|
|
13996
14445
|
};
|
|
13997
14446
|
}
|
|
13998
14447
|
}
|
|
13999
|
-
async function
|
|
14000
|
-
const
|
|
14448
|
+
async function collectDriftFindings(state, cwd) {
|
|
14449
|
+
const stateExists = await pathExists(state.workspace_path);
|
|
14450
|
+
const staleStateFinding = stateExists ? {
|
|
14451
|
+
kind: "stale_state",
|
|
14452
|
+
ok: true,
|
|
14453
|
+
summary: state.workspace_path
|
|
14454
|
+
} : {
|
|
14455
|
+
kind: "stale_state",
|
|
14456
|
+
ok: false,
|
|
14457
|
+
summary: `recorded workspace ${state.workspace_path} doesn't exist`,
|
|
14458
|
+
data: { workspace_path: state.workspace_path }
|
|
14459
|
+
};
|
|
14460
|
+
const found = await findClones(state.remote_url, cloneSearchRoots(cwd));
|
|
14461
|
+
const candidates = new Set(found);
|
|
14462
|
+
if (stateExists) {
|
|
14463
|
+
const { getRepoRemoteUrl: getRepoRemoteUrl2 } = await Promise.resolve().then(() => (init_git(), git_exports));
|
|
14464
|
+
const url = await getRepoRemoteUrl2(state.workspace_path);
|
|
14465
|
+
if (url && slugMatch(url, state.remote_url)) {
|
|
14466
|
+
candidates.add(state.workspace_path);
|
|
14467
|
+
}
|
|
14468
|
+
}
|
|
14469
|
+
const cloneList = [...candidates];
|
|
14470
|
+
const multiCloneFinding = cloneList.length > 1 ? {
|
|
14471
|
+
kind: "multi_clone",
|
|
14472
|
+
ok: false,
|
|
14473
|
+
summary: `found ${cloneList.length} clones of ${state.remote_url}`,
|
|
14474
|
+
data: { clones: cloneList, canonical: state.workspace_path }
|
|
14475
|
+
} : {
|
|
14476
|
+
kind: "multi_clone",
|
|
14477
|
+
ok: true,
|
|
14478
|
+
summary: cloneList.length === 1 ? "single clone" : "no extra clones found",
|
|
14479
|
+
data: { clones: cloneList }
|
|
14480
|
+
};
|
|
14481
|
+
const wrongStateFinding = await (async () => {
|
|
14482
|
+
if (stateExists) {
|
|
14483
|
+
const { getRepoRemoteUrl: getRepoRemoteUrl2 } = await Promise.resolve().then(() => (init_git(), git_exports));
|
|
14484
|
+
const url = await getRepoRemoteUrl2(state.workspace_path);
|
|
14485
|
+
if (!url || !slugMatch(url, state.remote_url)) {
|
|
14486
|
+
const better2 = cloneList.find((p) => p !== state.workspace_path);
|
|
14487
|
+
if (better2) {
|
|
14488
|
+
return {
|
|
14489
|
+
kind: "wrong_state",
|
|
14490
|
+
ok: false,
|
|
14491
|
+
summary: `${state.workspace_path} doesn't match remote ${state.remote_url}`,
|
|
14492
|
+
data: {
|
|
14493
|
+
recorded: state.workspace_path,
|
|
14494
|
+
actual: better2,
|
|
14495
|
+
recorded_origin: url ?? null
|
|
14496
|
+
}
|
|
14497
|
+
};
|
|
14498
|
+
}
|
|
14499
|
+
}
|
|
14500
|
+
return { kind: "wrong_state", ok: true, summary: "state matches workspace" };
|
|
14501
|
+
}
|
|
14502
|
+
const better = cloneList.find((p) => p !== state.workspace_path);
|
|
14503
|
+
if (better) {
|
|
14504
|
+
return {
|
|
14505
|
+
kind: "wrong_state",
|
|
14506
|
+
ok: false,
|
|
14507
|
+
summary: `recorded path missing, but a clone exists at ${better}`,
|
|
14508
|
+
data: { recorded: state.workspace_path, actual: better }
|
|
14509
|
+
};
|
|
14510
|
+
}
|
|
14511
|
+
return { kind: "wrong_state", ok: true, summary: "no alternate clone to switch to" };
|
|
14512
|
+
})();
|
|
14513
|
+
const adapterFinding = await (async () => {
|
|
14514
|
+
if (!stateExists) {
|
|
14515
|
+
return {
|
|
14516
|
+
kind: "missing_adapters",
|
|
14517
|
+
ok: true,
|
|
14518
|
+
summary: "skipped (workspace path missing)"
|
|
14519
|
+
};
|
|
14520
|
+
}
|
|
14521
|
+
const adapters = await checkAdapters(state.workspace_path);
|
|
14522
|
+
const broken = adapters.filter((a) => !a.ok);
|
|
14523
|
+
if (broken.length === 0) {
|
|
14524
|
+
return { kind: "missing_adapters", ok: true, summary: "all adapter symlinks present" };
|
|
14525
|
+
}
|
|
14526
|
+
return {
|
|
14527
|
+
kind: "missing_adapters",
|
|
14528
|
+
ok: false,
|
|
14529
|
+
summary: `${broken.length}/${adapters.length} adapter symlinks missing or wrong`,
|
|
14530
|
+
data: { adapters, broken: broken.map((b) => b.path) }
|
|
14531
|
+
};
|
|
14532
|
+
})();
|
|
14533
|
+
const staleSyncFinding = isStaleSync(state.last_sync) ? {
|
|
14534
|
+
kind: "stale_sync",
|
|
14535
|
+
ok: false,
|
|
14536
|
+
summary: `last sync was ${describeAge(state.last_sync)} ago (threshold: ${getStaleSyncHours()}h)`,
|
|
14537
|
+
data: { last_sync: state.last_sync }
|
|
14538
|
+
} : {
|
|
14539
|
+
kind: "stale_sync",
|
|
14540
|
+
ok: true,
|
|
14541
|
+
summary: `synced ${describeAge(state.last_sync)} ago`
|
|
14542
|
+
};
|
|
14543
|
+
return [
|
|
14544
|
+
staleStateFinding,
|
|
14545
|
+
multiCloneFinding,
|
|
14546
|
+
wrongStateFinding,
|
|
14547
|
+
adapterFinding,
|
|
14548
|
+
staleSyncFinding
|
|
14549
|
+
];
|
|
14550
|
+
}
|
|
14551
|
+
function slugMatch(a, b) {
|
|
14552
|
+
const slug = (u) => {
|
|
14553
|
+
const cleaned = u.trim().replace(/\.git$/i, "");
|
|
14554
|
+
const https = cleaned.match(/^https?:\/\/[^/]*github\.com\/(.+)$/i);
|
|
14555
|
+
if (https && https[1]) return https[1].toLowerCase();
|
|
14556
|
+
const ssh = cleaned.match(/^[^@]+@github\.com:(.+)$/i);
|
|
14557
|
+
if (ssh && ssh[1]) return ssh[1].toLowerCase();
|
|
14558
|
+
if (/^[^/]+\/[^/]+$/.test(cleaned)) return cleaned.toLowerCase();
|
|
14559
|
+
return null;
|
|
14560
|
+
};
|
|
14561
|
+
const sa = slug(a);
|
|
14562
|
+
const sb = slug(b);
|
|
14563
|
+
return sa !== null && sb !== null && sa === sb;
|
|
14564
|
+
}
|
|
14565
|
+
async function healStaleState(finding, state, opts) {
|
|
14566
|
+
console.log("");
|
|
14567
|
+
console.log(` \u2717 Recorded workspace path missing: ${finding.data?.workspace_path}`);
|
|
14568
|
+
if (opts.quiet) return state;
|
|
14569
|
+
const want = await confirm(" Re-run init to re-clone?", true);
|
|
14570
|
+
if (!want) {
|
|
14571
|
+
console.log(" Skipped. Run `bamboo-agents init` manually when ready.");
|
|
14572
|
+
return state;
|
|
14573
|
+
}
|
|
14574
|
+
console.log(" Launching `bamboo-agents init` flow\u2026");
|
|
14575
|
+
const { runInit: runInit2 } = await Promise.resolve().then(() => (init_init(), init_exports));
|
|
14576
|
+
await runInit2();
|
|
14577
|
+
const fresh = await readState();
|
|
14578
|
+
return fresh ?? state;
|
|
14579
|
+
}
|
|
14580
|
+
async function healMultiClone(finding, state, opts) {
|
|
14581
|
+
const clones = finding.data?.clones ?? [];
|
|
14582
|
+
console.log("");
|
|
14583
|
+
console.log(` \u2717 Found ${clones.length} clones of ${state.remote_url}:`);
|
|
14584
|
+
for (const p of clones) console.log(` \u2022 ${p}`);
|
|
14585
|
+
if (opts.quiet) return state;
|
|
14586
|
+
const choices = [...clones, "Skip (leave both)"];
|
|
14587
|
+
const defaultIdx = clones.findIndex((p) => p === state.workspace_path);
|
|
14588
|
+
const idx = await choose(
|
|
14589
|
+
" Which clone should be canonical?",
|
|
14590
|
+
choices,
|
|
14591
|
+
defaultIdx >= 0 ? defaultIdx : 0
|
|
14592
|
+
);
|
|
14593
|
+
if (idx === null || idx === choices.length - 1) {
|
|
14594
|
+
console.log(" Skipped. Multi-clone left as-is.");
|
|
14595
|
+
return state;
|
|
14596
|
+
}
|
|
14597
|
+
const canonical = clones[idx];
|
|
14598
|
+
const nonCanonical = clones.filter((p) => p !== canonical);
|
|
14599
|
+
let next = state;
|
|
14600
|
+
if (canonical !== state.workspace_path) {
|
|
14601
|
+
next = { ...state, workspace_path: canonical };
|
|
14602
|
+
await writeState(next);
|
|
14603
|
+
console.log(` Updated state.json \u2192 ${canonical}`);
|
|
14604
|
+
}
|
|
14605
|
+
if (nonCanonical.length > 0) {
|
|
14606
|
+
console.log(" Other clones:");
|
|
14607
|
+
for (const p of nonCanonical) console.log(` \u2022 ${p}`);
|
|
14608
|
+
const wantDelete = await confirm(" Delete the non-canonical clones?", false);
|
|
14609
|
+
if (wantDelete) {
|
|
14610
|
+
for (const p of nonCanonical) {
|
|
14611
|
+
try {
|
|
14612
|
+
await rm3(p, { recursive: true, force: true });
|
|
14613
|
+
console.log(` \u2713 removed ${p}`);
|
|
14614
|
+
} catch (err) {
|
|
14615
|
+
console.log(` \u2717 couldn't remove ${p}: ${err.message}`);
|
|
14616
|
+
}
|
|
14617
|
+
}
|
|
14618
|
+
} else {
|
|
14619
|
+
console.log(" Left non-canonical clones in place.");
|
|
14620
|
+
}
|
|
14621
|
+
}
|
|
14622
|
+
return next;
|
|
14623
|
+
}
|
|
14624
|
+
async function healWrongState(finding, state, opts) {
|
|
14625
|
+
const actual = finding.data?.actual;
|
|
14626
|
+
const recorded = finding.data?.recorded;
|
|
14627
|
+
if (!actual || !recorded) return state;
|
|
14628
|
+
console.log("");
|
|
14629
|
+
console.log(` \u2717 state.workspace_path = ${recorded}, but workspace lives at ${actual}`);
|
|
14630
|
+
if (opts.quiet) return state;
|
|
14631
|
+
const useActual = opts.autoHeal ? true : await confirm(` Update state.json \u2192 ${actual}?`, true);
|
|
14632
|
+
if (useActual === null || !useActual) {
|
|
14633
|
+
console.log(" Skipped. state.json still points at the recorded path.");
|
|
14634
|
+
return state;
|
|
14635
|
+
}
|
|
14636
|
+
const next = { ...state, workspace_path: actual };
|
|
14637
|
+
await writeState(next);
|
|
14638
|
+
console.log(` Updated state.json \u2192 ${actual}`);
|
|
14639
|
+
return next;
|
|
14640
|
+
}
|
|
14641
|
+
async function healMissingAdapters(finding, state, opts) {
|
|
14642
|
+
const broken = finding.data?.broken ?? [];
|
|
14643
|
+
console.log("");
|
|
14644
|
+
console.log(` \u2717 Missing/wrong adapter symlinks: ${broken.join(", ")}`);
|
|
14645
|
+
if (opts.quiet) return state;
|
|
14646
|
+
const want = opts.autoHeal ? true : await confirm(" Add the missing adapter symlinks?", true);
|
|
14647
|
+
if (!want) {
|
|
14648
|
+
console.log(" Skipped. Add manually with `ln -s ../skills <path>` from your workspace root.");
|
|
14649
|
+
return state;
|
|
14650
|
+
}
|
|
14651
|
+
try {
|
|
14652
|
+
const fixed = await healAdapters(state.workspace_path);
|
|
14653
|
+
for (const p of fixed) console.log(` \u2713 created ${p} \u2192 ../skills`);
|
|
14654
|
+
} catch (err) {
|
|
14655
|
+
console.log(` \u2717 couldn't create symlinks: ${err.message}`);
|
|
14656
|
+
}
|
|
14657
|
+
return state;
|
|
14658
|
+
}
|
|
14659
|
+
async function healStaleSync(_finding, state, opts) {
|
|
14660
|
+
console.log("");
|
|
14661
|
+
console.log(` \u2717 Last sync was ${describeAge(state.last_sync)} ago.`);
|
|
14662
|
+
if (opts.quiet) return state;
|
|
14663
|
+
const want = opts.autoHeal ? true : await confirm(" Pull now (ff-only)?", true);
|
|
14664
|
+
if (!want) {
|
|
14665
|
+
console.log(" Skipped. Run `git pull` in your workspace when ready.");
|
|
14666
|
+
return state;
|
|
14667
|
+
}
|
|
14668
|
+
const result = await gitPullFfOnly(state.workspace_path);
|
|
14669
|
+
if (result.ok) {
|
|
14670
|
+
const next = { ...state, last_sync: (/* @__PURE__ */ new Date()).toISOString() };
|
|
14671
|
+
await writeState(next);
|
|
14672
|
+
console.log(" \u2713 pulled cleanly");
|
|
14673
|
+
return next;
|
|
14674
|
+
}
|
|
14675
|
+
console.log(` \u2717 pull failed: ${result.stderr.trim().split("\n")[0]}`);
|
|
14676
|
+
console.log(" Run `git pull` manually to diagnose.");
|
|
14677
|
+
return state;
|
|
14678
|
+
}
|
|
14679
|
+
async function runDoctor(options = {}) {
|
|
14680
|
+
const opts = {
|
|
14681
|
+
quiet: options.quiet === true,
|
|
14682
|
+
autoHeal: options.autoHeal === true
|
|
14683
|
+
};
|
|
14684
|
+
const baseChecks = await Promise.all([
|
|
14001
14685
|
checkGit(),
|
|
14002
14686
|
checkBambooSession(),
|
|
14003
14687
|
checkGitCredential(),
|
|
14004
14688
|
checkConfig(),
|
|
14005
14689
|
checkRepoPath()
|
|
14006
14690
|
]);
|
|
14691
|
+
const state = await readState().catch(() => null);
|
|
14692
|
+
const drift = state ? await collectDriftFindings(state) : null;
|
|
14693
|
+
if (opts.quiet) {
|
|
14694
|
+
const payload = {
|
|
14695
|
+
ok: baseChecks.every((c) => c.ok) && (drift ?? []).every((d) => d.ok),
|
|
14696
|
+
checks: baseChecks.map((c) => ({ name: c.name, ok: c.ok, detail: c.detail })),
|
|
14697
|
+
drift: drift ?? []
|
|
14698
|
+
};
|
|
14699
|
+
console.log(JSON.stringify(payload, null, 2));
|
|
14700
|
+
process.exit(payload.ok ? 0 : 1);
|
|
14701
|
+
return;
|
|
14702
|
+
}
|
|
14007
14703
|
console.log("");
|
|
14008
|
-
for (const c of
|
|
14704
|
+
for (const c of baseChecks) {
|
|
14009
14705
|
const mark = c.ok ? "\u2713" : "\u2717";
|
|
14010
14706
|
console.log(` ${mark} ${c.name.padEnd(28)} ${c.detail}`);
|
|
14011
14707
|
}
|
|
14708
|
+
if (drift) {
|
|
14709
|
+
console.log("");
|
|
14710
|
+
const labels = {
|
|
14711
|
+
stale_state: "Workspace path on disk",
|
|
14712
|
+
multi_clone: "Single clone",
|
|
14713
|
+
wrong_state: "State matches workspace",
|
|
14714
|
+
missing_adapters: "Cross-tool adapters",
|
|
14715
|
+
stale_sync: "Recent sync"
|
|
14716
|
+
};
|
|
14717
|
+
for (const f of drift) {
|
|
14718
|
+
const mark = f.ok ? "\u2713" : "\u2717";
|
|
14719
|
+
console.log(` ${mark} ${labels[f.kind].padEnd(28)} ${f.summary}`);
|
|
14720
|
+
}
|
|
14721
|
+
}
|
|
14012
14722
|
console.log("");
|
|
14013
|
-
const
|
|
14014
|
-
if (
|
|
14015
|
-
|
|
14016
|
-
|
|
14723
|
+
const remaining = (drift ?? []).filter((f) => !f.ok);
|
|
14724
|
+
if (remaining.length === 0) {
|
|
14725
|
+
const baseFailures = baseChecks.filter((c) => !c.ok).length;
|
|
14726
|
+
if (baseFailures > 0) {
|
|
14727
|
+
console.log(` ${baseFailures} check(s) failing.`);
|
|
14728
|
+
process.exit(1);
|
|
14729
|
+
}
|
|
14730
|
+
console.log(" All checks passing.");
|
|
14731
|
+
return;
|
|
14017
14732
|
}
|
|
14018
|
-
console.log(
|
|
14733
|
+
console.log(` ${remaining.length} drift issue(s) detected \u2014 let's fix them.`);
|
|
14734
|
+
let cur = state;
|
|
14735
|
+
const order = [
|
|
14736
|
+
"stale_state",
|
|
14737
|
+
"wrong_state",
|
|
14738
|
+
"multi_clone",
|
|
14739
|
+
"missing_adapters",
|
|
14740
|
+
"stale_sync"
|
|
14741
|
+
];
|
|
14742
|
+
for (const kind of order) {
|
|
14743
|
+
const f = remaining.find((r) => r.kind === kind);
|
|
14744
|
+
if (!f) continue;
|
|
14745
|
+
switch (kind) {
|
|
14746
|
+
case "stale_state":
|
|
14747
|
+
cur = await healStaleState(f, cur, opts);
|
|
14748
|
+
break;
|
|
14749
|
+
case "multi_clone":
|
|
14750
|
+
cur = await healMultiClone(f, cur, opts);
|
|
14751
|
+
break;
|
|
14752
|
+
case "wrong_state":
|
|
14753
|
+
cur = await healWrongState(f, cur, opts);
|
|
14754
|
+
break;
|
|
14755
|
+
case "missing_adapters":
|
|
14756
|
+
cur = await healMissingAdapters(f, cur, opts);
|
|
14757
|
+
break;
|
|
14758
|
+
case "stale_sync":
|
|
14759
|
+
cur = await healStaleSync(f, cur, opts);
|
|
14760
|
+
break;
|
|
14761
|
+
}
|
|
14762
|
+
}
|
|
14763
|
+
const post = await readState().catch(() => null);
|
|
14764
|
+
const postDrift = post ? await collectDriftFindings(post) : drift;
|
|
14765
|
+
const stillBroken = (postDrift ?? []).filter((d) => !d.ok);
|
|
14766
|
+
console.log("");
|
|
14767
|
+
if (stillBroken.length === 0) {
|
|
14768
|
+
console.log(" \u2713 Workspace healthy.");
|
|
14769
|
+
return;
|
|
14770
|
+
}
|
|
14771
|
+
console.log(` ${stillBroken.length} issue(s) remain \u2014 re-run \`bamboo-agents doctor\` after addressing.`);
|
|
14772
|
+
process.exit(1);
|
|
14019
14773
|
}
|
|
14020
14774
|
var init_doctor = __esm({
|
|
14021
14775
|
"src/commands/doctor.ts"() {
|
|
@@ -14024,6 +14778,8 @@ var init_doctor = __esm({
|
|
|
14024
14778
|
init_git();
|
|
14025
14779
|
init_state();
|
|
14026
14780
|
init_credentials();
|
|
14781
|
+
init_workspace_health();
|
|
14782
|
+
init_heal_prompt();
|
|
14027
14783
|
}
|
|
14028
14784
|
});
|
|
14029
14785
|
|
|
@@ -14032,10 +14788,10 @@ var save_exports = {};
|
|
|
14032
14788
|
__export(save_exports, {
|
|
14033
14789
|
runSave: () => runSave
|
|
14034
14790
|
});
|
|
14035
|
-
import { execFile as
|
|
14036
|
-
import { promisify as
|
|
14791
|
+
import { execFile as execFile9 } from "node:child_process";
|
|
14792
|
+
import { promisify as promisify9 } from "node:util";
|
|
14037
14793
|
async function gitC(repoPath, args) {
|
|
14038
|
-
const { stdout, stderr } = await
|
|
14794
|
+
const { stdout, stderr } = await execFileP4("git", ["-C", repoPath, ...args], {
|
|
14039
14795
|
encoding: "utf8"
|
|
14040
14796
|
});
|
|
14041
14797
|
return { stdout, stderr };
|
|
@@ -14084,12 +14840,12 @@ async function runSave(message) {
|
|
|
14084
14840
|
process.exit(1);
|
|
14085
14841
|
}
|
|
14086
14842
|
}
|
|
14087
|
-
var
|
|
14843
|
+
var execFileP4;
|
|
14088
14844
|
var init_save = __esm({
|
|
14089
14845
|
"src/commands/save.ts"() {
|
|
14090
14846
|
"use strict";
|
|
14091
14847
|
init_workspace();
|
|
14092
|
-
|
|
14848
|
+
execFileP4 = promisify9(execFile9);
|
|
14093
14849
|
}
|
|
14094
14850
|
});
|
|
14095
14851
|
|
|
@@ -14098,8 +14854,8 @@ var sync_exports = {};
|
|
|
14098
14854
|
__export(sync_exports, {
|
|
14099
14855
|
runSync: () => runSync
|
|
14100
14856
|
});
|
|
14101
|
-
import { execFile as
|
|
14102
|
-
import { promisify as
|
|
14857
|
+
import { execFile as execFile10 } from "node:child_process";
|
|
14858
|
+
import { promisify as promisify10 } from "node:util";
|
|
14103
14859
|
async function runSync() {
|
|
14104
14860
|
let workspacePath;
|
|
14105
14861
|
try {
|
|
@@ -14112,7 +14868,7 @@ async function runSync() {
|
|
|
14112
14868
|
throw err;
|
|
14113
14869
|
}
|
|
14114
14870
|
try {
|
|
14115
|
-
const { stdout } = await
|
|
14871
|
+
const { stdout } = await execFileP5(
|
|
14116
14872
|
"git",
|
|
14117
14873
|
["-C", workspacePath, "pull", "--ff-only"],
|
|
14118
14874
|
{ encoding: "utf8" }
|
|
@@ -14141,19 +14897,19 @@ async function runSync() {
|
|
|
14141
14897
|
throw err;
|
|
14142
14898
|
}
|
|
14143
14899
|
}
|
|
14144
|
-
var
|
|
14900
|
+
var execFileP5;
|
|
14145
14901
|
var init_sync = __esm({
|
|
14146
14902
|
"src/commands/sync.ts"() {
|
|
14147
14903
|
"use strict";
|
|
14148
14904
|
init_state();
|
|
14149
14905
|
init_workspace();
|
|
14150
|
-
|
|
14906
|
+
execFileP5 = promisify10(execFile10);
|
|
14151
14907
|
}
|
|
14152
14908
|
});
|
|
14153
14909
|
|
|
14154
14910
|
// src/lib/skills-local.ts
|
|
14155
|
-
import { readdir as
|
|
14156
|
-
import { join as
|
|
14911
|
+
import { readdir as readdir3, readFile as readFile4, stat as stat2 } from "node:fs/promises";
|
|
14912
|
+
import { join as join3 } from "node:path";
|
|
14157
14913
|
function parseSimpleFrontmatter(raw) {
|
|
14158
14914
|
const text = raw.replace(/\r\n/g, "\n");
|
|
14159
14915
|
const m = text.match(/^---\n([\s\S]*?)\n---\n?([\s\S]*)$/);
|
|
@@ -14268,7 +15024,7 @@ function parseSkillContent(raw, sourcePath) {
|
|
|
14268
15024
|
};
|
|
14269
15025
|
}
|
|
14270
15026
|
async function resolveSkillsDir(repoPath) {
|
|
14271
|
-
const dir =
|
|
15027
|
+
const dir = join3(repoPath, "skills");
|
|
14272
15028
|
try {
|
|
14273
15029
|
const s = await stat2(dir);
|
|
14274
15030
|
return s.isDirectory() ? dir : null;
|
|
@@ -14279,11 +15035,11 @@ async function resolveSkillsDir(repoPath) {
|
|
|
14279
15035
|
async function listLocalSkills(repoPath) {
|
|
14280
15036
|
const dir = await resolveSkillsDir(repoPath);
|
|
14281
15037
|
if (!dir) return [];
|
|
14282
|
-
const entries = await
|
|
15038
|
+
const entries = await readdir3(dir, { withFileTypes: true });
|
|
14283
15039
|
const skillDirs = entries.filter((e) => e.isDirectory());
|
|
14284
15040
|
const skills2 = [];
|
|
14285
15041
|
for (const entry of skillDirs) {
|
|
14286
|
-
const full =
|
|
15042
|
+
const full = join3(dir, entry.name, "SKILL.md");
|
|
14287
15043
|
let raw;
|
|
14288
15044
|
try {
|
|
14289
15045
|
raw = await readFile4(full, "utf8");
|
|
@@ -14304,7 +15060,7 @@ async function listLocalSkills(repoPath) {
|
|
|
14304
15060
|
async function getLocalSkill(repoPath, name) {
|
|
14305
15061
|
const dir = await resolveSkillsDir(repoPath);
|
|
14306
15062
|
if (!dir) return null;
|
|
14307
|
-
const full =
|
|
15063
|
+
const full = join3(dir, name, "SKILL.md");
|
|
14308
15064
|
let raw;
|
|
14309
15065
|
try {
|
|
14310
15066
|
raw = await readFile4(full, "utf8");
|
|
@@ -14681,9 +15437,12 @@ program2.command("login").description("Sign in to Bamboo via your browser").acti
|
|
|
14681
15437
|
const { runLogin: runLogin2 } = await Promise.resolve().then(() => (init_login(), login_exports));
|
|
14682
15438
|
await runLogin2();
|
|
14683
15439
|
});
|
|
14684
|
-
program2.command("init").description("Clone your workspace + set up git credentials").
|
|
15440
|
+
program2.command("init").description("Clone your workspace + set up git credentials").option(
|
|
15441
|
+
"--reset",
|
|
15442
|
+
"Delete the existing workspace clone and start over (prompts for confirmation)"
|
|
15443
|
+
).action(async (options) => {
|
|
14685
15444
|
const { runInit: runInit2 } = await Promise.resolve().then(() => (init_init(), init_exports));
|
|
14686
|
-
await runInit2();
|
|
15445
|
+
await runInit2({ reset: options.reset });
|
|
14687
15446
|
});
|
|
14688
15447
|
program2.command("open").description("Launch Claude Code at your workspace").action(async () => {
|
|
14689
15448
|
const { runOpen: runOpen2 } = await Promise.resolve().then(() => (init_open2(), open_exports));
|
|
@@ -14693,9 +15452,9 @@ program2.command("status").description("Show current Bamboo CLI state").action(a
|
|
|
14693
15452
|
const { runStatus: runStatus2 } = await Promise.resolve().then(() => (init_status(), status_exports));
|
|
14694
15453
|
await runStatus2();
|
|
14695
15454
|
});
|
|
14696
|
-
program2.command("doctor").description("Verify your local setup is ready").action(async () => {
|
|
15455
|
+
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) => {
|
|
14697
15456
|
const { runDoctor: runDoctor2 } = await Promise.resolve().then(() => (init_doctor(), doctor_exports));
|
|
14698
|
-
await runDoctor2();
|
|
15457
|
+
await runDoctor2({ quiet: options.quiet, autoHeal: options.autoHeal });
|
|
14699
15458
|
});
|
|
14700
15459
|
program2.command("save <message>").description("Commit + push everything in your workspace (cwd-agnostic)").action(async (message) => {
|
|
14701
15460
|
const { runSave: runSave2 } = await Promise.resolve().then(() => (init_save(), save_exports));
|