bamboo-agents 0.1.5-dev.57.9905e44 → 0.1.5-dev.59.bf3c8c5
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 +619 -60
- 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.59.bf3c8c5";
|
|
3041
3041
|
}
|
|
3042
3042
|
});
|
|
3043
3043
|
|
|
@@ -7377,6 +7377,8 @@ var init_onboarding_status = __esm({
|
|
|
7377
7377
|
// ../../src/lib/api-contracts/cli/agents.ts
|
|
7378
7378
|
var agents_exports = {};
|
|
7379
7379
|
__export(agents_exports, {
|
|
7380
|
+
CliActivationBlockerSchema: () => CliActivationBlockerSchema,
|
|
7381
|
+
CliActivationReadinessSchema: () => CliActivationReadinessSchema,
|
|
7380
7382
|
CliAgentDetailSchema: () => CliAgentDetailSchema,
|
|
7381
7383
|
CliAgentGetResponseSchema: () => CliAgentGetResponseSchema,
|
|
7382
7384
|
CliAgentLifecycleStateSchema: () => CliAgentLifecycleStateSchema,
|
|
@@ -7404,7 +7406,7 @@ __export(agents_exports, {
|
|
|
7404
7406
|
UploadClaudeMdRequestSchema: () => UploadClaudeMdRequestSchema,
|
|
7405
7407
|
UploadClaudeMdResponseSchema: () => UploadClaudeMdResponseSchema
|
|
7406
7408
|
});
|
|
7407
|
-
var SlugSchema, NameSchema, BrandIdSchema, CliAgentRowSchema, CliTierCapSchema, CliAgentsListResponseSchema, CliCreateAgentRequestSchema, CliAgentMutationResponseBase, CliCreateAgentResponseSchema, UPLOAD_MAX_BYTES, CliUploadAgentRequestSchema, CliUploadAgentResponseSchema, CliUpdateAgentRequestSchema, CliUpdateAgentResponseSchema, CliDeleteAgentResponseSchema, CliCloneAgentRequestSchema, CliCloneAgentResponseSchema, CliEnableTemplateRequestSchema, CliEnableTemplateResponseSchema, CliBrandRowSchema, CliBrandsListResponseSchema, CliAgentLifecycleStateSchema, CliAgentDetailSchema, CliAgentGetResponseSchema, CliAgentPauseResponseSchema, CliAgentPublishResponseSchema, CreateFromCliRequestSchema, CreateFromCliResponseSchema, UploadClaudeMdRequestSchema, UploadClaudeMdResponseSchema;
|
|
7409
|
+
var SlugSchema, NameSchema, BrandIdSchema, CliAgentRowSchema, CliTierCapSchema, CliAgentsListResponseSchema, CliCreateAgentRequestSchema, CliAgentMutationResponseBase, CliCreateAgentResponseSchema, UPLOAD_MAX_BYTES, CliUploadAgentRequestSchema, CliUploadAgentResponseSchema, CliUpdateAgentRequestSchema, CliUpdateAgentResponseSchema, CliDeleteAgentResponseSchema, CliCloneAgentRequestSchema, CliCloneAgentResponseSchema, CliEnableTemplateRequestSchema, CliEnableTemplateResponseSchema, CliBrandRowSchema, CliBrandsListResponseSchema, CliAgentLifecycleStateSchema, CliActivationBlockerSchema, CliActivationReadinessSchema, CliAgentDetailSchema, CliAgentGetResponseSchema, CliAgentPauseResponseSchema, CliAgentPublishResponseSchema, CreateFromCliRequestSchema, CreateFromCliResponseSchema, UploadClaudeMdRequestSchema, UploadClaudeMdResponseSchema;
|
|
7408
7410
|
var init_agents = __esm({
|
|
7409
7411
|
"../../src/lib/api-contracts/cli/agents.ts"() {
|
|
7410
7412
|
init_zod();
|
|
@@ -7527,6 +7529,18 @@ var init_agents = __esm({
|
|
|
7527
7529
|
"paused",
|
|
7528
7530
|
"inactive"
|
|
7529
7531
|
]);
|
|
7532
|
+
CliActivationBlockerSchema = external_exports.object({
|
|
7533
|
+
kind: external_exports.string(),
|
|
7534
|
+
scope: external_exports.string(),
|
|
7535
|
+
label: external_exports.string(),
|
|
7536
|
+
cta: external_exports.string(),
|
|
7537
|
+
action_url: external_exports.string(),
|
|
7538
|
+
meta: external_exports.record(external_exports.unknown())
|
|
7539
|
+
});
|
|
7540
|
+
CliActivationReadinessSchema = external_exports.object({
|
|
7541
|
+
ready: external_exports.boolean(),
|
|
7542
|
+
blockers: external_exports.array(CliActivationBlockerSchema)
|
|
7543
|
+
});
|
|
7530
7544
|
CliAgentDetailSchema = external_exports.object({
|
|
7531
7545
|
id: external_exports.string().uuid(),
|
|
7532
7546
|
name: external_exports.string(),
|
|
@@ -7543,7 +7557,12 @@ var init_agents = __esm({
|
|
|
7543
7557
|
description: external_exports.string().nullable(),
|
|
7544
7558
|
created_at: external_exports.string().nullable(),
|
|
7545
7559
|
/** Brand m:m links (agent_brands → brands). */
|
|
7546
|
-
brands: external_exports.array(CliBrandRowSchema)
|
|
7560
|
+
brands: external_exports.array(CliBrandRowSchema),
|
|
7561
|
+
/**
|
|
7562
|
+
* BAM-2651: activation-readiness result. Always present on new servers;
|
|
7563
|
+
* optional here for forward-compat with old servers that don't emit it.
|
|
7564
|
+
*/
|
|
7565
|
+
activation_readiness: CliActivationReadinessSchema.optional()
|
|
7547
7566
|
});
|
|
7548
7567
|
CliAgentGetResponseSchema = external_exports.object({
|
|
7549
7568
|
agent: CliAgentDetailSchema
|
|
@@ -7617,6 +7636,12 @@ async function writeCredentials(creds) {
|
|
|
7617
7636
|
});
|
|
7618
7637
|
await chmod(bambooDir(), 448);
|
|
7619
7638
|
}
|
|
7639
|
+
async function resolveSession() {
|
|
7640
|
+
const envToken = process.env.BAMBOO_API_TOKEN?.trim();
|
|
7641
|
+
if (envToken) return envToken;
|
|
7642
|
+
const creds = await readCredentials();
|
|
7643
|
+
return creds?.bamboo_session ?? null;
|
|
7644
|
+
}
|
|
7620
7645
|
var CredentialsSchema;
|
|
7621
7646
|
var init_credentials = __esm({
|
|
7622
7647
|
"src/lib/credentials.ts"() {
|
|
@@ -7625,7 +7650,16 @@ var init_credentials = __esm({
|
|
|
7625
7650
|
init_paths();
|
|
7626
7651
|
CredentialsSchema = external_exports.object({
|
|
7627
7652
|
bamboo_session: external_exports.string().min(1),
|
|
7628
|
-
|
|
7653
|
+
/**
|
|
7654
|
+
* GitHub token for git push (interactive login flow). Empty string when
|
|
7655
|
+
* the credentials were written by the BAM-2666 headless `bamboo login --token`
|
|
7656
|
+
* path — that flow runs in environments (managed agents, CI) where the
|
|
7657
|
+
* GitHub token isn't needed (writes route through the server's
|
|
7658
|
+
* `executeKnowledgeWrite` core via `bamboo save`, not a client-side push).
|
|
7659
|
+
* Downstream consumers must handle empty string gracefully or fall back
|
|
7660
|
+
* to re-running interactive login.
|
|
7661
|
+
*/
|
|
7662
|
+
github_token: external_exports.string(),
|
|
7629
7663
|
github_token_expires_at: external_exports.string().nullable(),
|
|
7630
7664
|
/** Display-only — git push uses `x-access-token` as username, not the user's login. */
|
|
7631
7665
|
github_username: external_exports.string().nullable(),
|
|
@@ -12432,6 +12466,34 @@ var init_context_health = __esm({
|
|
|
12432
12466
|
}
|
|
12433
12467
|
});
|
|
12434
12468
|
|
|
12469
|
+
// ../../src/lib/api-contracts/cli/install-token.ts
|
|
12470
|
+
var CliInstallTokenSuccessSchema, CliInstallTokenErrorSchema;
|
|
12471
|
+
var init_install_token = __esm({
|
|
12472
|
+
"../../src/lib/api-contracts/cli/install-token.ts"() {
|
|
12473
|
+
init_zod();
|
|
12474
|
+
CliInstallTokenSuccessSchema = external_exports.object({
|
|
12475
|
+
/** Raw API key. Returned exactly once — caller must write into MCP config + discard. */
|
|
12476
|
+
api_key: external_exports.string().min(1),
|
|
12477
|
+
/** First 16 chars of the key (e.g. `bam_live_xxxxxxx`). Safe to log/display. */
|
|
12478
|
+
prefix: external_exports.string().min(1),
|
|
12479
|
+
/** Full workspace repo URL (e.g. `https://github.com/acme/acme-workspace`). */
|
|
12480
|
+
workspace_url: external_exports.string().url(),
|
|
12481
|
+
/** MCP server URL the CLI should put in the `~/.claude.json` MCP entry. */
|
|
12482
|
+
mcp_url: external_exports.string().url()
|
|
12483
|
+
});
|
|
12484
|
+
CliInstallTokenErrorSchema = external_exports.object({
|
|
12485
|
+
error: external_exports.enum([
|
|
12486
|
+
"unauthorized",
|
|
12487
|
+
"no_active_install",
|
|
12488
|
+
"no_workspace_repo",
|
|
12489
|
+
"mint_failed",
|
|
12490
|
+
"internal_error"
|
|
12491
|
+
]),
|
|
12492
|
+
message: external_exports.string().optional()
|
|
12493
|
+
});
|
|
12494
|
+
}
|
|
12495
|
+
});
|
|
12496
|
+
|
|
12435
12497
|
// src/lib/api.ts
|
|
12436
12498
|
import { platform as platform2 } from "node:os";
|
|
12437
12499
|
function defaultApiBase(version) {
|
|
@@ -12861,6 +12923,15 @@ async function uploadClaudeMdFromCli(bambooSession, body) {
|
|
|
12861
12923
|
const json = await res.json();
|
|
12862
12924
|
return CliUploadAgentResponseSchema.parse(json);
|
|
12863
12925
|
}
|
|
12926
|
+
async function mintCliInstallToken(bambooSession) {
|
|
12927
|
+
const res = await cliApiFetch(`${apiBase()}/api/v1/cli/api-key`, {
|
|
12928
|
+
method: "POST",
|
|
12929
|
+
headers: { Authorization: `Bearer ${bambooSession}` }
|
|
12930
|
+
});
|
|
12931
|
+
if (!res.ok) throw await parseError(res);
|
|
12932
|
+
const json = await res.json();
|
|
12933
|
+
return CliInstallTokenSuccessSchema.parse(json);
|
|
12934
|
+
}
|
|
12864
12935
|
var PROD_DEFAULT_BASE, DEV_DEFAULT_BASE, REQUEST_TIMEOUT_MS, ApiError, OAuthRelinkStartResponseSchema, ProvisionWorkspaceResponseSchema, FirstAutoInstalledAgentResponseSchema, SkillCatalogEntrySchema, SkillCatalogResponseSchema, SkillSubscriptionsResponseSchema, ScaffoldSkillResponseSchema;
|
|
12865
12936
|
var init_api = __esm({
|
|
12866
12937
|
"src/lib/api.ts"() {
|
|
@@ -12880,6 +12951,7 @@ var init_api = __esm({
|
|
|
12880
12951
|
init_changes();
|
|
12881
12952
|
init_onboarding_status();
|
|
12882
12953
|
init_context_health();
|
|
12954
|
+
init_install_token();
|
|
12883
12955
|
init_version();
|
|
12884
12956
|
PROD_DEFAULT_BASE = "https://withbamboo.com";
|
|
12885
12957
|
DEV_DEFAULT_BASE = "https://dev.withbamboo.com";
|
|
@@ -12945,8 +13017,11 @@ var login_exports = {};
|
|
|
12945
13017
|
__export(login_exports, {
|
|
12946
13018
|
TOKEN_POLL: () => TOKEN_POLL,
|
|
12947
13019
|
handleMissingGithubToken: () => handleMissingGithubToken,
|
|
13020
|
+
isAgentScopedKey: () => isAgentScopedKey,
|
|
12948
13021
|
runLogin: () => runLogin,
|
|
13022
|
+
runLoginWithToken: () => runLoginWithToken,
|
|
12949
13023
|
startCallbackServer: () => startCallbackServer,
|
|
13024
|
+
validateAndWriteHeadlessCreds: () => validateAndWriteHeadlessCreds,
|
|
12950
13025
|
verificationCode: () => verificationCode
|
|
12951
13026
|
});
|
|
12952
13027
|
import { randomBytes as randomBytes2 } from "node:crypto";
|
|
@@ -12998,10 +13073,10 @@ async function handleMissingGithubToken(bambooSession) {
|
|
|
12998
13073
|
return null;
|
|
12999
13074
|
}
|
|
13000
13075
|
async function startCallbackServer(expectedState) {
|
|
13001
|
-
let
|
|
13076
|
+
let resolveSession2;
|
|
13002
13077
|
let rejectSession;
|
|
13003
13078
|
const session = new Promise((resolve2, reject) => {
|
|
13004
|
-
|
|
13079
|
+
resolveSession2 = resolve2;
|
|
13005
13080
|
rejectSession = reject;
|
|
13006
13081
|
});
|
|
13007
13082
|
const server = createServer((req, res) => {
|
|
@@ -13045,7 +13120,7 @@ async function startCallbackServer(expectedState) {
|
|
|
13045
13120
|
return;
|
|
13046
13121
|
}
|
|
13047
13122
|
respondCors(200, { ok: true });
|
|
13048
|
-
|
|
13123
|
+
resolveSession2(body.session);
|
|
13049
13124
|
setTimeout(() => server.close(), 100);
|
|
13050
13125
|
});
|
|
13051
13126
|
});
|
|
@@ -13073,6 +13148,78 @@ async function startCallbackServer(expectedState) {
|
|
|
13073
13148
|
session: session.finally(() => clearTimeout(timer))
|
|
13074
13149
|
};
|
|
13075
13150
|
}
|
|
13151
|
+
function isAgentScopedKey(token) {
|
|
13152
|
+
return token.startsWith("bam_live_");
|
|
13153
|
+
}
|
|
13154
|
+
async function validateAndWriteHeadlessCreds(bambooSession) {
|
|
13155
|
+
if (!isAgentScopedKey(bambooSession)) {
|
|
13156
|
+
try {
|
|
13157
|
+
await getCliAuthStatus(bambooSession);
|
|
13158
|
+
} catch (err) {
|
|
13159
|
+
if (err instanceof ApiError) {
|
|
13160
|
+
if (err.status === 401) {
|
|
13161
|
+
return {
|
|
13162
|
+
kind: "invalid_token",
|
|
13163
|
+
message: "The token was rejected by Bamboo's auth check."
|
|
13164
|
+
};
|
|
13165
|
+
}
|
|
13166
|
+
if (err.status >= 400 && err.status < 500) {
|
|
13167
|
+
return {
|
|
13168
|
+
kind: "invalid_token",
|
|
13169
|
+
message: `Bamboo's auth check returned ${err.status}: ${err.message}`
|
|
13170
|
+
};
|
|
13171
|
+
}
|
|
13172
|
+
return {
|
|
13173
|
+
kind: "network_error",
|
|
13174
|
+
message: `Bamboo's auth check returned ${err.status}: ${err.message}`
|
|
13175
|
+
};
|
|
13176
|
+
}
|
|
13177
|
+
return {
|
|
13178
|
+
kind: "network_error",
|
|
13179
|
+
message: err?.message ?? String(err)
|
|
13180
|
+
};
|
|
13181
|
+
}
|
|
13182
|
+
}
|
|
13183
|
+
await writeCredentials({
|
|
13184
|
+
bamboo_session: bambooSession,
|
|
13185
|
+
github_token: "",
|
|
13186
|
+
github_token_expires_at: null,
|
|
13187
|
+
github_username: null,
|
|
13188
|
+
written_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
13189
|
+
});
|
|
13190
|
+
return { kind: "success", githubUsername: null };
|
|
13191
|
+
}
|
|
13192
|
+
async function runLoginWithToken(bambooSession) {
|
|
13193
|
+
const result = await validateAndWriteHeadlessCreds(bambooSession);
|
|
13194
|
+
switch (result.kind) {
|
|
13195
|
+
case "success": {
|
|
13196
|
+
console.log("");
|
|
13197
|
+
console.log(
|
|
13198
|
+
` \u2713 Logged in${result.githubUsername ? ` as @${result.githubUsername}` : ""} (headless).`
|
|
13199
|
+
);
|
|
13200
|
+
console.log("");
|
|
13201
|
+
return;
|
|
13202
|
+
}
|
|
13203
|
+
case "invalid_token": {
|
|
13204
|
+
console.error("");
|
|
13205
|
+
console.error(` Invalid token: ${result.message}`);
|
|
13206
|
+
console.error(
|
|
13207
|
+
" Mint a fresh token from your Bamboo workspace and retry."
|
|
13208
|
+
);
|
|
13209
|
+
console.error("");
|
|
13210
|
+
process.exit(1);
|
|
13211
|
+
}
|
|
13212
|
+
case "network_error": {
|
|
13213
|
+
console.error("");
|
|
13214
|
+
console.error(` Network error: ${result.message}`);
|
|
13215
|
+
console.error(
|
|
13216
|
+
` Verify $BAMBOO_BASE_URL (${apiBase()}) is reachable and retry.`
|
|
13217
|
+
);
|
|
13218
|
+
console.error("");
|
|
13219
|
+
process.exit(2);
|
|
13220
|
+
}
|
|
13221
|
+
}
|
|
13222
|
+
}
|
|
13076
13223
|
async function runLogin() {
|
|
13077
13224
|
const state = randomBytes2(32).toString("hex");
|
|
13078
13225
|
const code = verificationCode(state);
|
|
@@ -13434,13 +13581,19 @@ async function runInit(options = {}) {
|
|
|
13434
13581
|
process.exit(1);
|
|
13435
13582
|
}
|
|
13436
13583
|
gitSpinner.succeed(`git ${version.join(".")} ready (${gitEmail})`);
|
|
13437
|
-
|
|
13438
|
-
|
|
13439
|
-
|
|
13440
|
-
|
|
13441
|
-
|
|
13442
|
-
|
|
13443
|
-
|
|
13584
|
+
if (creds.github_token) {
|
|
13585
|
+
const credSpinner = ora("Installing GitHub credential into git\u2026").start();
|
|
13586
|
+
try {
|
|
13587
|
+
await installGithubCredential(creds.github_token);
|
|
13588
|
+
credSpinner.succeed("GitHub credential installed");
|
|
13589
|
+
} catch (err) {
|
|
13590
|
+
credSpinner.fail(`Couldn't install git credential: ${err.message}`);
|
|
13591
|
+
process.exit(1);
|
|
13592
|
+
}
|
|
13593
|
+
} else {
|
|
13594
|
+
console.log(
|
|
13595
|
+
" Skipping git credential install \u2014 credentials are headless (no GitHub token)."
|
|
13596
|
+
);
|
|
13444
13597
|
}
|
|
13445
13598
|
const orgSlug = slugify(membership.org.name);
|
|
13446
13599
|
const canonicalPath = defaultClonePath(orgSlug);
|
|
@@ -13871,9 +14024,269 @@ var init_clone_or_adopt_phase = __esm({
|
|
|
13871
14024
|
}
|
|
13872
14025
|
});
|
|
13873
14026
|
|
|
14027
|
+
// src/lib/mcp-config.ts
|
|
14028
|
+
import { access as access3, mkdir as mkdir3, readFile as readFile3, rename as rename2, writeFile as writeFile3 } from "node:fs/promises";
|
|
14029
|
+
import { homedir as homedir2, platform as platform3 } from "node:os";
|
|
14030
|
+
import { dirname, join as join2 } from "node:path";
|
|
14031
|
+
function mcpConfigPath(client) {
|
|
14032
|
+
const home = homedir2();
|
|
14033
|
+
if (client === "claude-code") {
|
|
14034
|
+
return join2(home, ".claude.json");
|
|
14035
|
+
}
|
|
14036
|
+
const plat = platform3();
|
|
14037
|
+
if (plat === "darwin") {
|
|
14038
|
+
return join2(home, "Library", "Application Support", "Claude", "claude_desktop_config.json");
|
|
14039
|
+
}
|
|
14040
|
+
if (plat === "win32") {
|
|
14041
|
+
const appData = process.env.APPDATA;
|
|
14042
|
+
if (!appData) return null;
|
|
14043
|
+
return join2(appData, "Claude", "claude_desktop_config.json");
|
|
14044
|
+
}
|
|
14045
|
+
return null;
|
|
14046
|
+
}
|
|
14047
|
+
async function readMcpConfig(client) {
|
|
14048
|
+
const path2 = mcpConfigPath(client);
|
|
14049
|
+
if (!path2) return null;
|
|
14050
|
+
try {
|
|
14051
|
+
await access3(path2);
|
|
14052
|
+
} catch {
|
|
14053
|
+
return null;
|
|
14054
|
+
}
|
|
14055
|
+
const raw = await readFile3(path2, "utf8");
|
|
14056
|
+
if (!raw.trim()) {
|
|
14057
|
+
return {};
|
|
14058
|
+
}
|
|
14059
|
+
let parsed;
|
|
14060
|
+
try {
|
|
14061
|
+
parsed = JSON.parse(raw);
|
|
14062
|
+
} catch (err) {
|
|
14063
|
+
const message = err instanceof Error ? err.message : "unknown JSON parse error";
|
|
14064
|
+
throw new Error(`Invalid JSON in ${path2}: ${message}`);
|
|
14065
|
+
}
|
|
14066
|
+
if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) {
|
|
14067
|
+
throw new Error(`Expected object at top of ${path2}, got ${typeof parsed}`);
|
|
14068
|
+
}
|
|
14069
|
+
return parsed;
|
|
14070
|
+
}
|
|
14071
|
+
async function writeMcpConfig(client, config) {
|
|
14072
|
+
const path2 = mcpConfigPath(client);
|
|
14073
|
+
if (!path2) {
|
|
14074
|
+
throw new Error(`No config path for client ${client} on this platform`);
|
|
14075
|
+
}
|
|
14076
|
+
await mkdir3(dirname(path2), { recursive: true });
|
|
14077
|
+
const tmp = `${path2}.tmp`;
|
|
14078
|
+
const serialized = JSON.stringify(config, null, 2) + "\n";
|
|
14079
|
+
await writeFile3(tmp, serialized, { encoding: "utf8", mode: 384 });
|
|
14080
|
+
await rename2(tmp, path2);
|
|
14081
|
+
}
|
|
14082
|
+
function getBambooEntry(config) {
|
|
14083
|
+
return config.mcpServers?.[BAMBOO_MCP_ENTRY_KEY];
|
|
14084
|
+
}
|
|
14085
|
+
function setBambooEntry(config, entry) {
|
|
14086
|
+
const existingServers = config.mcpServers ?? {};
|
|
14087
|
+
return {
|
|
14088
|
+
...config,
|
|
14089
|
+
mcpServers: {
|
|
14090
|
+
...existingServers,
|
|
14091
|
+
[BAMBOO_MCP_ENTRY_KEY]: entry
|
|
14092
|
+
}
|
|
14093
|
+
};
|
|
14094
|
+
}
|
|
14095
|
+
async function probeMcpServer(url, token, options = {}) {
|
|
14096
|
+
const controller = new AbortController();
|
|
14097
|
+
const timeout = setTimeout(() => controller.abort(), PROBE_TIMEOUT_MS);
|
|
14098
|
+
try {
|
|
14099
|
+
const response = await fetch(url, {
|
|
14100
|
+
method: "POST",
|
|
14101
|
+
headers: {
|
|
14102
|
+
"Content-Type": "application/json",
|
|
14103
|
+
Authorization: `Bearer ${token}`
|
|
14104
|
+
},
|
|
14105
|
+
body: JSON.stringify({
|
|
14106
|
+
jsonrpc: "2.0",
|
|
14107
|
+
id: 1,
|
|
14108
|
+
method: "initialize",
|
|
14109
|
+
params: {
|
|
14110
|
+
protocolVersion: "2024-11-05",
|
|
14111
|
+
capabilities: {},
|
|
14112
|
+
clientInfo: {
|
|
14113
|
+
name: "bamboo-agents-doctor",
|
|
14114
|
+
version: options.cliVersion ?? "0.0.0"
|
|
14115
|
+
}
|
|
14116
|
+
}
|
|
14117
|
+
}),
|
|
14118
|
+
signal: controller.signal
|
|
14119
|
+
});
|
|
14120
|
+
if (response.status === 401 || response.status === 403) {
|
|
14121
|
+
return { status: "auth-failed", detail: `HTTP ${response.status}` };
|
|
14122
|
+
}
|
|
14123
|
+
if (!response.ok) {
|
|
14124
|
+
return { status: "unreachable", detail: `HTTP ${response.status}` };
|
|
14125
|
+
}
|
|
14126
|
+
let body;
|
|
14127
|
+
try {
|
|
14128
|
+
body = await response.json();
|
|
14129
|
+
} catch {
|
|
14130
|
+
return { status: "invalid-response", detail: "non-JSON body" };
|
|
14131
|
+
}
|
|
14132
|
+
if (typeof body !== "object" || body === null || // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
14133
|
+
body.jsonrpc !== "2.0" || // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
14134
|
+
!body.result?.serverInfo) {
|
|
14135
|
+
return { status: "invalid-response", detail: "missing initialize result.serverInfo" };
|
|
14136
|
+
}
|
|
14137
|
+
const serverInfo = body.result.serverInfo;
|
|
14138
|
+
return {
|
|
14139
|
+
status: "reachable",
|
|
14140
|
+
detail: typeof serverInfo.name === "string" ? serverInfo.name : void 0
|
|
14141
|
+
};
|
|
14142
|
+
} catch (err) {
|
|
14143
|
+
if (err instanceof Error && err.name === "AbortError") {
|
|
14144
|
+
return { status: "unreachable", detail: "timeout" };
|
|
14145
|
+
}
|
|
14146
|
+
const message = err instanceof Error ? err.message : "unknown error";
|
|
14147
|
+
return { status: "unreachable", detail: message };
|
|
14148
|
+
} finally {
|
|
14149
|
+
clearTimeout(timeout);
|
|
14150
|
+
}
|
|
14151
|
+
}
|
|
14152
|
+
var BAMBOO_MCP_ENTRY_KEY, PROBE_TIMEOUT_MS;
|
|
14153
|
+
var init_mcp_config = __esm({
|
|
14154
|
+
"src/lib/mcp-config.ts"() {
|
|
14155
|
+
"use strict";
|
|
14156
|
+
BAMBOO_MCP_ENTRY_KEY = "bamboo";
|
|
14157
|
+
PROBE_TIMEOUT_MS = 5e3;
|
|
14158
|
+
}
|
|
14159
|
+
});
|
|
14160
|
+
|
|
14161
|
+
// src/lib/phases-impl/install-mcp-phase.ts
|
|
14162
|
+
function isBambooEntryShape(entry) {
|
|
14163
|
+
if (typeof entry !== "object" || entry === null) return false;
|
|
14164
|
+
const e = entry;
|
|
14165
|
+
return e.type === "http" && typeof e.url === "string" && typeof e.headers === "object" && e.headers !== null && typeof e.headers.Authorization === "string" && e.headers.Authorization.startsWith("Bearer ");
|
|
14166
|
+
}
|
|
14167
|
+
var CLIENTS, installMcpSpec;
|
|
14168
|
+
var init_install_mcp_phase = __esm({
|
|
14169
|
+
"src/lib/phases-impl/install-mcp-phase.ts"() {
|
|
14170
|
+
"use strict";
|
|
14171
|
+
init_ora();
|
|
14172
|
+
init_api();
|
|
14173
|
+
init_mcp_config();
|
|
14174
|
+
CLIENTS = ["claude-code", "claude-desktop"];
|
|
14175
|
+
installMcpSpec = {
|
|
14176
|
+
name: "install-mcp",
|
|
14177
|
+
async probe() {
|
|
14178
|
+
let codeConfig;
|
|
14179
|
+
try {
|
|
14180
|
+
codeConfig = await readMcpConfig("claude-code");
|
|
14181
|
+
} catch (err) {
|
|
14182
|
+
const message = err instanceof Error ? err.message : "unknown error";
|
|
14183
|
+
return {
|
|
14184
|
+
status: "needs_action",
|
|
14185
|
+
summary: "(broken config)",
|
|
14186
|
+
reason: `Could not read ~/.claude.json: ${message}. Fix or delete that file, then re-run.`
|
|
14187
|
+
};
|
|
14188
|
+
}
|
|
14189
|
+
if (!codeConfig) {
|
|
14190
|
+
return {
|
|
14191
|
+
status: "needs_work",
|
|
14192
|
+
summary: "install Bamboo MCP"
|
|
14193
|
+
};
|
|
14194
|
+
}
|
|
14195
|
+
const existing = getBambooEntry(codeConfig);
|
|
14196
|
+
if (!existing || !isBambooEntryShape(existing)) {
|
|
14197
|
+
return {
|
|
14198
|
+
status: "needs_work",
|
|
14199
|
+
summary: "install Bamboo MCP"
|
|
14200
|
+
};
|
|
14201
|
+
}
|
|
14202
|
+
return { status: "done", summary: "Bamboo MCP installed" };
|
|
14203
|
+
},
|
|
14204
|
+
async execute(ctx) {
|
|
14205
|
+
if (!ctx.credentials) {
|
|
14206
|
+
return {
|
|
14207
|
+
kind: "needs_action",
|
|
14208
|
+
reason: "Internal: installMcpPhase execute called without credentials."
|
|
14209
|
+
};
|
|
14210
|
+
}
|
|
14211
|
+
const spinner = ora("Installing Bamboo MCP\u2026").start();
|
|
14212
|
+
let token;
|
|
14213
|
+
try {
|
|
14214
|
+
token = await mintCliInstallToken(ctx.credentials.bamboo_session);
|
|
14215
|
+
} catch (err) {
|
|
14216
|
+
spinner.fail("Could not mint Bamboo MCP credentials");
|
|
14217
|
+
if (err instanceof ApiError) {
|
|
14218
|
+
if (err.errorCode === "no_active_install") {
|
|
14219
|
+
return {
|
|
14220
|
+
kind: "needs_action",
|
|
14221
|
+
reason: "GitHub App isn't installed for this org. Run `bamboo-agents login` first."
|
|
14222
|
+
};
|
|
14223
|
+
}
|
|
14224
|
+
if (err.errorCode === "no_workspace_repo") {
|
|
14225
|
+
return {
|
|
14226
|
+
kind: "needs_action",
|
|
14227
|
+
reason: "Workspace repo doesn't exist yet. Run `bamboo-agents init` first."
|
|
14228
|
+
};
|
|
14229
|
+
}
|
|
14230
|
+
return {
|
|
14231
|
+
kind: "needs_action",
|
|
14232
|
+
reason: `Could not mint Bamboo MCP API key: ${err.message}`
|
|
14233
|
+
};
|
|
14234
|
+
}
|
|
14235
|
+
const message = err instanceof Error ? err.message : "unknown error";
|
|
14236
|
+
return {
|
|
14237
|
+
kind: "needs_action",
|
|
14238
|
+
reason: `Could not mint Bamboo MCP API key: ${message}`
|
|
14239
|
+
};
|
|
14240
|
+
}
|
|
14241
|
+
const entry = {
|
|
14242
|
+
type: "http",
|
|
14243
|
+
url: token.mcp_url,
|
|
14244
|
+
headers: { Authorization: `Bearer ${token.api_key}` }
|
|
14245
|
+
};
|
|
14246
|
+
const written = [];
|
|
14247
|
+
const errors = [];
|
|
14248
|
+
for (const client of CLIENTS) {
|
|
14249
|
+
const path2 = mcpConfigPath(client);
|
|
14250
|
+
if (!path2) continue;
|
|
14251
|
+
let existing;
|
|
14252
|
+
try {
|
|
14253
|
+
existing = await readMcpConfig(client);
|
|
14254
|
+
} catch (err) {
|
|
14255
|
+
const message = err instanceof Error ? err.message : "unknown error";
|
|
14256
|
+
errors.push(`${client} (${path2}): ${message}`);
|
|
14257
|
+
continue;
|
|
14258
|
+
}
|
|
14259
|
+
const next = setBambooEntry(existing ?? {}, entry);
|
|
14260
|
+
try {
|
|
14261
|
+
await writeMcpConfig(client, next);
|
|
14262
|
+
written.push(client);
|
|
14263
|
+
} catch (err) {
|
|
14264
|
+
const message = err instanceof Error ? err.message : "unknown error";
|
|
14265
|
+
errors.push(`${client} (${path2}): ${message}`);
|
|
14266
|
+
}
|
|
14267
|
+
}
|
|
14268
|
+
if (written.length === 0) {
|
|
14269
|
+
spinner.fail("Could not install Bamboo MCP");
|
|
14270
|
+
return {
|
|
14271
|
+
kind: "needs_action",
|
|
14272
|
+
reason: `No AI client configs were writable. ${errors.length ? `Errors: ${errors.join("; ")}` : "Is Claude Code installed?"}`
|
|
14273
|
+
};
|
|
14274
|
+
}
|
|
14275
|
+
const summary = `Installed Bamboo MCP (${written.join(", ")})`;
|
|
14276
|
+
if (errors.length) {
|
|
14277
|
+
spinner.warn(`${summary}; partial: ${errors.join("; ")}`);
|
|
14278
|
+
} else {
|
|
14279
|
+
spinner.succeed(summary);
|
|
14280
|
+
}
|
|
14281
|
+
return { kind: "advanced", summary };
|
|
14282
|
+
}
|
|
14283
|
+
};
|
|
14284
|
+
}
|
|
14285
|
+
});
|
|
14286
|
+
|
|
13874
14287
|
// src/lib/phases-impl/pick-first-user-agent-phase.ts
|
|
13875
|
-
import { readdir, readFile as
|
|
13876
|
-
import { dirname, join as pathJoin, resolve as pathResolve3 } from "node:path";
|
|
14288
|
+
import { readdir, readFile as readFile4, stat } from "node:fs/promises";
|
|
14289
|
+
import { dirname as dirname2, join as pathJoin, resolve as pathResolve3 } from "node:path";
|
|
13877
14290
|
async function runCaseA(ctx) {
|
|
13878
14291
|
console.log(" Let's set up YOUR first agent. How would you like to start?");
|
|
13879
14292
|
console.log("");
|
|
@@ -14069,7 +14482,7 @@ async function resolveUploadFile(ctx) {
|
|
|
14069
14482
|
} catch {
|
|
14070
14483
|
}
|
|
14071
14484
|
try {
|
|
14072
|
-
const content = await
|
|
14485
|
+
const content = await readFile4(absPath, "utf8");
|
|
14073
14486
|
return { absPath, content };
|
|
14074
14487
|
} catch (err) {
|
|
14075
14488
|
await handleReadFailure(ctx, absPath, err);
|
|
@@ -14091,7 +14504,7 @@ async function handleReadFailure(ctx, absPath, err) {
|
|
|
14091
14504
|
}
|
|
14092
14505
|
}
|
|
14093
14506
|
async function printDirectorySneakPeek(cwd, failedAbsPath) {
|
|
14094
|
-
const parent =
|
|
14507
|
+
const parent = dirname2(failedAbsPath);
|
|
14095
14508
|
const targets = [parent, cwd];
|
|
14096
14509
|
const seen = /* @__PURE__ */ new Set();
|
|
14097
14510
|
for (const target of targets) {
|
|
@@ -14564,6 +14977,7 @@ var init_orchestrator = __esm({
|
|
|
14564
14977
|
init_login_phase();
|
|
14565
14978
|
init_provision_phase();
|
|
14566
14979
|
init_clone_or_adopt_phase();
|
|
14980
|
+
init_install_mcp_phase();
|
|
14567
14981
|
init_pick_first_user_agent_phase();
|
|
14568
14982
|
init_magic_moment_phase();
|
|
14569
14983
|
init_open_phase();
|
|
@@ -14572,6 +14986,7 @@ var init_orchestrator = __esm({
|
|
|
14572
14986
|
loginSpec,
|
|
14573
14987
|
provisionSpec,
|
|
14574
14988
|
cloneOrAdoptSpec,
|
|
14989
|
+
installMcpSpec,
|
|
14575
14990
|
pickFirstUserAgentSpec,
|
|
14576
14991
|
magicMomentSpec,
|
|
14577
14992
|
openSpec
|
|
@@ -14581,10 +14996,10 @@ var init_orchestrator = __esm({
|
|
|
14581
14996
|
|
|
14582
14997
|
// src/lib/claude-desktop.ts
|
|
14583
14998
|
import { execFile as execFile7 } from "node:child_process";
|
|
14584
|
-
import { platform as
|
|
14999
|
+
import { platform as platform4 } from "node:os";
|
|
14585
15000
|
import { promisify as promisify7 } from "node:util";
|
|
14586
15001
|
async function detectClaudeDesktop() {
|
|
14587
|
-
const plat =
|
|
15002
|
+
const plat = platform4();
|
|
14588
15003
|
if (plat === "darwin") return await detectMacOS();
|
|
14589
15004
|
if (plat === "win32") return await detectWindows();
|
|
14590
15005
|
return { kind: "unsupported_platform" };
|
|
@@ -14761,8 +15176,8 @@ __export(save_exports, {
|
|
|
14761
15176
|
runSave: () => runSave
|
|
14762
15177
|
});
|
|
14763
15178
|
import { execFile as execFile8 } from "node:child_process";
|
|
14764
|
-
import { readFile as
|
|
14765
|
-
import { join as
|
|
15179
|
+
import { readFile as readFile5, rm as rm2 } from "node:fs/promises";
|
|
15180
|
+
import { join as join3 } from "node:path";
|
|
14766
15181
|
import { promisify as promisify8 } from "node:util";
|
|
14767
15182
|
function parsePorcelain(out) {
|
|
14768
15183
|
if (!out) return [];
|
|
@@ -14835,20 +15250,20 @@ async function currentBranch(repoPath) {
|
|
|
14835
15250
|
return out.trim() || "main";
|
|
14836
15251
|
}
|
|
14837
15252
|
async function requireSession(opts) {
|
|
14838
|
-
const
|
|
14839
|
-
if (!
|
|
15253
|
+
const session = await resolveSession();
|
|
15254
|
+
if (!session) {
|
|
14840
15255
|
emitError(
|
|
14841
15256
|
{
|
|
14842
15257
|
code: "not_signed_in",
|
|
14843
15258
|
message: "not signed in.",
|
|
14844
|
-
hint: "Run `bamboo-agents login` first."
|
|
15259
|
+
hint: "Run `bamboo-agents login` first (or set BAMBOO_API_TOKEN for headless use)."
|
|
14845
15260
|
},
|
|
14846
15261
|
opts,
|
|
14847
15262
|
1
|
|
14848
15263
|
);
|
|
14849
15264
|
throw new Error("unreachable");
|
|
14850
15265
|
}
|
|
14851
|
-
return
|
|
15266
|
+
return session;
|
|
14852
15267
|
}
|
|
14853
15268
|
async function runSave(intent, options = {}) {
|
|
14854
15269
|
const opts = options;
|
|
@@ -14925,7 +15340,7 @@ async function runSave(intent, options = {}) {
|
|
|
14925
15340
|
const edits = [];
|
|
14926
15341
|
try {
|
|
14927
15342
|
for (const path2 of writes) {
|
|
14928
|
-
const content = await
|
|
15343
|
+
const content = await readFile5(join3(workspacePath, path2), "utf8");
|
|
14929
15344
|
edits.push({ path: path2, content });
|
|
14930
15345
|
}
|
|
14931
15346
|
} catch {
|
|
@@ -14989,7 +15404,7 @@ async function runSave(intent, options = {}) {
|
|
|
14989
15404
|
]);
|
|
14990
15405
|
}
|
|
14991
15406
|
for (const path2 of remove) {
|
|
14992
|
-
await rm2(
|
|
15407
|
+
await rm2(join3(workspacePath, path2), { force: true });
|
|
14993
15408
|
}
|
|
14994
15409
|
} catch {
|
|
14995
15410
|
human(
|
|
@@ -15266,9 +15681,9 @@ var init_status = __esm({
|
|
|
15266
15681
|
// src/lib/workspace-health.ts
|
|
15267
15682
|
import { execFile as execFile10 } from "node:child_process";
|
|
15268
15683
|
import { promisify as promisify10 } from "node:util";
|
|
15269
|
-
import { lstat, readlink, readdir as readdir2, mkdir as
|
|
15270
|
-
import { join as
|
|
15271
|
-
import { homedir as
|
|
15684
|
+
import { lstat, readlink, readdir as readdir2, mkdir as mkdir4, symlink, rm as rm3, access as access4 } from "node:fs/promises";
|
|
15685
|
+
import { join as join4, dirname as dirname3, resolve } from "node:path";
|
|
15686
|
+
import { homedir as homedir3 } from "node:os";
|
|
15272
15687
|
function getStaleSyncHours() {
|
|
15273
15688
|
const raw = process.env.BAMBOO_STALE_SYNC_HOURS;
|
|
15274
15689
|
if (!raw) return DEFAULT_STALE_SYNC_HOURS;
|
|
@@ -15278,13 +15693,13 @@ function getStaleSyncHours() {
|
|
|
15278
15693
|
}
|
|
15279
15694
|
function cloneSearchRoots(cwd) {
|
|
15280
15695
|
const overridden = process.env.BAMBOO_CLONE_SEARCH_DIRS;
|
|
15281
|
-
const home =
|
|
15282
|
-
const base = overridden ? overridden.split(":").filter(Boolean) : [home,
|
|
15696
|
+
const home = homedir3();
|
|
15697
|
+
const base = overridden ? overridden.split(":").filter(Boolean) : [home, join4(home, "Documents"), join4(home, "Downloads"), join4(home, "Desktop")];
|
|
15283
15698
|
const walk = [];
|
|
15284
15699
|
let cur = cwd ?? process.cwd();
|
|
15285
15700
|
for (let i = 0; i < 20; i++) {
|
|
15286
15701
|
walk.push(cur);
|
|
15287
|
-
const parent =
|
|
15702
|
+
const parent = dirname3(cur);
|
|
15288
15703
|
if (parent === cur) break;
|
|
15289
15704
|
if (parent === home) {
|
|
15290
15705
|
walk.push(home);
|
|
@@ -15309,7 +15724,7 @@ async function findClones(remoteUrl, roots, maxDepth = 4) {
|
|
|
15309
15724
|
if (scanned >= MAX_DIRS_SCANNED) return;
|
|
15310
15725
|
if (depth < 0) return;
|
|
15311
15726
|
scanned += 1;
|
|
15312
|
-
const gitDir =
|
|
15727
|
+
const gitDir = join4(dir, ".git");
|
|
15313
15728
|
let isRepo = false;
|
|
15314
15729
|
try {
|
|
15315
15730
|
const s = await lstat(gitDir);
|
|
@@ -15336,12 +15751,12 @@ async function findClones(remoteUrl, roots, maxDepth = 4) {
|
|
|
15336
15751
|
if (SKIP_DIRS.has(entry.name)) continue;
|
|
15337
15752
|
}
|
|
15338
15753
|
if (SKIP_DIRS.has(entry.name)) continue;
|
|
15339
|
-
await visit(
|
|
15754
|
+
await visit(join4(dir, entry.name), depth - 1);
|
|
15340
15755
|
}
|
|
15341
15756
|
}
|
|
15342
15757
|
for (const root of roots) {
|
|
15343
15758
|
try {
|
|
15344
|
-
await
|
|
15759
|
+
await access4(root);
|
|
15345
15760
|
} catch {
|
|
15346
15761
|
continue;
|
|
15347
15762
|
}
|
|
@@ -15367,7 +15782,7 @@ function remoteUrlSlug(url) {
|
|
|
15367
15782
|
async function checkAdapters(workspacePath) {
|
|
15368
15783
|
const out = [];
|
|
15369
15784
|
for (const { path: path2, target } of CROSS_TOOL_ADAPTERS) {
|
|
15370
|
-
const full =
|
|
15785
|
+
const full = join4(workspacePath, path2);
|
|
15371
15786
|
let s;
|
|
15372
15787
|
try {
|
|
15373
15788
|
s = await lstat(full);
|
|
@@ -15411,14 +15826,14 @@ async function healAdapters(workspacePath) {
|
|
|
15411
15826
|
const current = await checkAdapters(workspacePath);
|
|
15412
15827
|
for (const status of current) {
|
|
15413
15828
|
if (status.ok) continue;
|
|
15414
|
-
const full =
|
|
15829
|
+
const full = join4(workspacePath, status.path);
|
|
15415
15830
|
if (status.state === "wrong_target" || status.state === "not_symlink") {
|
|
15416
15831
|
try {
|
|
15417
15832
|
await rm3(full, { recursive: true, force: true });
|
|
15418
15833
|
} catch {
|
|
15419
15834
|
}
|
|
15420
15835
|
}
|
|
15421
|
-
await
|
|
15836
|
+
await mkdir4(dirname3(full), { recursive: true });
|
|
15422
15837
|
await symlink(status.expectedTarget, full);
|
|
15423
15838
|
fixed.push(status.path);
|
|
15424
15839
|
}
|
|
@@ -15452,7 +15867,7 @@ async function gitPullFfOnly(workspacePath) {
|
|
|
15452
15867
|
}
|
|
15453
15868
|
async function pathExists(p) {
|
|
15454
15869
|
try {
|
|
15455
|
-
await
|
|
15870
|
+
await access4(p);
|
|
15456
15871
|
return true;
|
|
15457
15872
|
} catch {
|
|
15458
15873
|
return false;
|
|
@@ -15570,9 +15985,10 @@ __export(doctor_exports, {
|
|
|
15570
15985
|
checkBambooSession: () => checkBambooSession,
|
|
15571
15986
|
checkGitCredential: () => checkGitCredential,
|
|
15572
15987
|
collectDriftFindings: () => collectDriftFindings,
|
|
15988
|
+
collectMcpDriftFinding: () => collectMcpDriftFinding,
|
|
15573
15989
|
runDoctor: () => runDoctor
|
|
15574
15990
|
});
|
|
15575
|
-
import { access as
|
|
15991
|
+
import { access as access5 } from "node:fs/promises";
|
|
15576
15992
|
import { rm as rm4 } from "node:fs/promises";
|
|
15577
15993
|
async function checkGit() {
|
|
15578
15994
|
const v = await gitVersion();
|
|
@@ -15666,7 +16082,7 @@ async function checkRepoPath() {
|
|
|
15666
16082
|
};
|
|
15667
16083
|
}
|
|
15668
16084
|
try {
|
|
15669
|
-
await
|
|
16085
|
+
await access5(cfg.repo_path);
|
|
15670
16086
|
return { name: "Repo cloned", ok: true, detail: cfg.repo_path };
|
|
15671
16087
|
} catch {
|
|
15672
16088
|
return {
|
|
@@ -15771,14 +16187,77 @@ async function collectDriftFindings(state, cwd) {
|
|
|
15771
16187
|
ok: true,
|
|
15772
16188
|
summary: `synced ${describeAge(state.last_sync)} ago`
|
|
15773
16189
|
};
|
|
16190
|
+
const mcpFinding = await collectMcpDriftFinding();
|
|
15774
16191
|
return [
|
|
15775
16192
|
staleStateFinding,
|
|
15776
16193
|
multiCloneFinding,
|
|
15777
16194
|
wrongStateFinding,
|
|
15778
16195
|
adapterFinding,
|
|
15779
|
-
staleSyncFinding
|
|
16196
|
+
staleSyncFinding,
|
|
16197
|
+
mcpFinding
|
|
15780
16198
|
];
|
|
15781
16199
|
}
|
|
16200
|
+
async function collectMcpDriftFinding() {
|
|
16201
|
+
let config;
|
|
16202
|
+
try {
|
|
16203
|
+
config = await readMcpConfig("claude-code");
|
|
16204
|
+
} catch (err) {
|
|
16205
|
+
const message = err instanceof Error ? err.message : "unknown error";
|
|
16206
|
+
return {
|
|
16207
|
+
kind: "mcp_drift",
|
|
16208
|
+
ok: false,
|
|
16209
|
+
summary: `~/.claude.json unparseable (${message})`,
|
|
16210
|
+
data: { reason: "malformed", detail: message }
|
|
16211
|
+
};
|
|
16212
|
+
}
|
|
16213
|
+
if (!config) {
|
|
16214
|
+
return {
|
|
16215
|
+
kind: "mcp_drift",
|
|
16216
|
+
ok: false,
|
|
16217
|
+
summary: "Bamboo MCP not installed in ~/.claude.json",
|
|
16218
|
+
data: { reason: "missing" }
|
|
16219
|
+
};
|
|
16220
|
+
}
|
|
16221
|
+
const entry = getBambooEntry(config);
|
|
16222
|
+
if (!entry) {
|
|
16223
|
+
return {
|
|
16224
|
+
kind: "mcp_drift",
|
|
16225
|
+
ok: false,
|
|
16226
|
+
summary: "Bamboo MCP entry missing from ~/.claude.json",
|
|
16227
|
+
data: { reason: "missing" }
|
|
16228
|
+
};
|
|
16229
|
+
}
|
|
16230
|
+
const url = entry.url;
|
|
16231
|
+
const authHeader = entry.headers?.Authorization;
|
|
16232
|
+
if (typeof url !== "string" || typeof authHeader !== "string" || !authHeader.startsWith("Bearer ")) {
|
|
16233
|
+
return {
|
|
16234
|
+
kind: "mcp_drift",
|
|
16235
|
+
ok: false,
|
|
16236
|
+
summary: "Bamboo MCP entry is malformed",
|
|
16237
|
+
data: { reason: "malformed" }
|
|
16238
|
+
};
|
|
16239
|
+
}
|
|
16240
|
+
const token = authHeader.slice("Bearer ".length);
|
|
16241
|
+
const probe = await probeMcpServer(url, token);
|
|
16242
|
+
if (probe.status === "reachable") {
|
|
16243
|
+
return {
|
|
16244
|
+
kind: "mcp_drift",
|
|
16245
|
+
ok: true,
|
|
16246
|
+
summary: `reachable (${probe.detail ?? "ok"})`
|
|
16247
|
+
};
|
|
16248
|
+
}
|
|
16249
|
+
const reasonMap = {
|
|
16250
|
+
"auth-failed": "auth_failed",
|
|
16251
|
+
unreachable: "unreachable",
|
|
16252
|
+
"invalid-response": "invalid_response"
|
|
16253
|
+
};
|
|
16254
|
+
return {
|
|
16255
|
+
kind: "mcp_drift",
|
|
16256
|
+
ok: false,
|
|
16257
|
+
summary: `MCP probe \u2192 ${probe.status}${probe.detail ? ` (${probe.detail})` : ""}`,
|
|
16258
|
+
data: { reason: reasonMap[probe.status], detail: probe.detail ?? null }
|
|
16259
|
+
};
|
|
16260
|
+
}
|
|
15782
16261
|
function slugMatch(a, b) {
|
|
15783
16262
|
const slug = (u) => {
|
|
15784
16263
|
const cleaned = u.trim().replace(/\.git$/i, "");
|
|
@@ -15887,6 +16366,72 @@ async function healMissingAdapters(finding, state, opts) {
|
|
|
15887
16366
|
}
|
|
15888
16367
|
return state;
|
|
15889
16368
|
}
|
|
16369
|
+
async function healMcpDrift(finding, state, opts) {
|
|
16370
|
+
const reason = finding.data?.reason ?? "missing";
|
|
16371
|
+
console.log("");
|
|
16372
|
+
console.log(` \u2717 ${finding.summary}`);
|
|
16373
|
+
if (reason === "unreachable") {
|
|
16374
|
+
console.log(" Bamboo MCP server is unreachable \u2014 likely transient.");
|
|
16375
|
+
console.log(" Try again in a few minutes, or check status.withbamboo.com.");
|
|
16376
|
+
return state;
|
|
16377
|
+
}
|
|
16378
|
+
if (opts.quiet) return state;
|
|
16379
|
+
const want = opts.autoHeal ? true : await confirm(" Re-install Bamboo MCP credentials?", true);
|
|
16380
|
+
if (!want) {
|
|
16381
|
+
console.log(" Skipped. Re-run doctor when ready.");
|
|
16382
|
+
return state;
|
|
16383
|
+
}
|
|
16384
|
+
const creds = await readCredentials();
|
|
16385
|
+
if (!creds) {
|
|
16386
|
+
console.log(" \u2717 No Bamboo credentials \u2014 run `bamboo-agents login` first.");
|
|
16387
|
+
return state;
|
|
16388
|
+
}
|
|
16389
|
+
let token;
|
|
16390
|
+
try {
|
|
16391
|
+
token = await mintCliInstallToken(creds.bamboo_session);
|
|
16392
|
+
} catch (err) {
|
|
16393
|
+
const message = err instanceof Error ? err.message : "unknown error";
|
|
16394
|
+
if (err instanceof ApiError && err.errorCode === "no_active_install") {
|
|
16395
|
+
console.log(" \u2717 GitHub App isn't installed \u2014 run `bamboo-agents login` first.");
|
|
16396
|
+
return state;
|
|
16397
|
+
}
|
|
16398
|
+
if (err instanceof ApiError && err.errorCode === "no_workspace_repo") {
|
|
16399
|
+
console.log(" \u2717 Workspace repo doesn't exist \u2014 run `bamboo-agents init` first.");
|
|
16400
|
+
return state;
|
|
16401
|
+
}
|
|
16402
|
+
console.log(` \u2717 Could not mint Bamboo MCP API key: ${message}`);
|
|
16403
|
+
return state;
|
|
16404
|
+
}
|
|
16405
|
+
const entry = {
|
|
16406
|
+
type: "http",
|
|
16407
|
+
url: token.mcp_url,
|
|
16408
|
+
headers: { Authorization: `Bearer ${token.api_key}` }
|
|
16409
|
+
};
|
|
16410
|
+
const clients = ["claude-code", "claude-desktop"];
|
|
16411
|
+
let writeCount = 0;
|
|
16412
|
+
for (const client of clients) {
|
|
16413
|
+
const path2 = mcpConfigPath(client);
|
|
16414
|
+
if (!path2) continue;
|
|
16415
|
+
let existing;
|
|
16416
|
+
try {
|
|
16417
|
+
existing = await readMcpConfig(client);
|
|
16418
|
+
} catch {
|
|
16419
|
+
existing = null;
|
|
16420
|
+
}
|
|
16421
|
+
try {
|
|
16422
|
+
await writeMcpConfig(client, setBambooEntry(existing ?? {}, entry));
|
|
16423
|
+
writeCount++;
|
|
16424
|
+
console.log(` \u2713 rewrote ${client} (${path2})`);
|
|
16425
|
+
} catch (err) {
|
|
16426
|
+
const message = err instanceof Error ? err.message : "unknown error";
|
|
16427
|
+
console.log(` \u2717 couldn't write ${client}: ${message}`);
|
|
16428
|
+
}
|
|
16429
|
+
}
|
|
16430
|
+
if (writeCount === 0) {
|
|
16431
|
+
console.log(" \u2717 No client configs were writable. Is Claude Code installed?");
|
|
16432
|
+
}
|
|
16433
|
+
return state;
|
|
16434
|
+
}
|
|
15890
16435
|
async function healStaleSync(_finding, state, opts) {
|
|
15891
16436
|
console.log("");
|
|
15892
16437
|
console.log(` \u2717 Last sync was ${describeAge(state.last_sync)} ago.`);
|
|
@@ -15943,7 +16488,8 @@ async function runDoctor(options = {}) {
|
|
|
15943
16488
|
multi_clone: "Single clone",
|
|
15944
16489
|
wrong_state: "State matches workspace",
|
|
15945
16490
|
missing_adapters: "Cross-tool adapters",
|
|
15946
|
-
stale_sync: "Recent sync"
|
|
16491
|
+
stale_sync: "Recent sync",
|
|
16492
|
+
mcp_drift: "Bamboo MCP installed"
|
|
15947
16493
|
};
|
|
15948
16494
|
for (const f of drift) {
|
|
15949
16495
|
const mark = f.ok ? "\u2713" : "\u2717";
|
|
@@ -15968,7 +16514,8 @@ async function runDoctor(options = {}) {
|
|
|
15968
16514
|
"wrong_state",
|
|
15969
16515
|
"multi_clone",
|
|
15970
16516
|
"missing_adapters",
|
|
15971
|
-
"stale_sync"
|
|
16517
|
+
"stale_sync",
|
|
16518
|
+
"mcp_drift"
|
|
15972
16519
|
];
|
|
15973
16520
|
for (const kind of order) {
|
|
15974
16521
|
const f = remaining.find((r) => r.kind === kind);
|
|
@@ -15989,6 +16536,9 @@ async function runDoctor(options = {}) {
|
|
|
15989
16536
|
case "stale_sync":
|
|
15990
16537
|
cur = await healStaleSync(f, cur, opts);
|
|
15991
16538
|
break;
|
|
16539
|
+
case "mcp_drift":
|
|
16540
|
+
cur = await healMcpDrift(f, cur, opts);
|
|
16541
|
+
break;
|
|
15992
16542
|
}
|
|
15993
16543
|
}
|
|
15994
16544
|
const post = await readState().catch(() => null);
|
|
@@ -16006,6 +16556,7 @@ var init_doctor = __esm({
|
|
|
16006
16556
|
"src/commands/doctor.ts"() {
|
|
16007
16557
|
"use strict";
|
|
16008
16558
|
init_api();
|
|
16559
|
+
init_mcp_config();
|
|
16009
16560
|
init_git();
|
|
16010
16561
|
init_state();
|
|
16011
16562
|
init_credentials();
|
|
@@ -16117,8 +16668,8 @@ var init_update = __esm({
|
|
|
16117
16668
|
});
|
|
16118
16669
|
|
|
16119
16670
|
// src/lib/skills-local.ts
|
|
16120
|
-
import { readdir as readdir3, readFile as
|
|
16121
|
-
import { join as
|
|
16671
|
+
import { readdir as readdir3, readFile as readFile6, stat as stat2 } from "node:fs/promises";
|
|
16672
|
+
import { join as join5 } from "node:path";
|
|
16122
16673
|
function parseSimpleFrontmatter(raw) {
|
|
16123
16674
|
const text = raw.replace(/\r\n/g, "\n");
|
|
16124
16675
|
const m = text.match(/^---\n([\s\S]*?)\n---\n?([\s\S]*)$/);
|
|
@@ -16233,7 +16784,7 @@ function parseSkillContent(raw, sourcePath) {
|
|
|
16233
16784
|
};
|
|
16234
16785
|
}
|
|
16235
16786
|
async function resolveSkillsDir(repoPath) {
|
|
16236
|
-
const dir =
|
|
16787
|
+
const dir = join5(repoPath, "skills");
|
|
16237
16788
|
try {
|
|
16238
16789
|
const s = await stat2(dir);
|
|
16239
16790
|
return s.isDirectory() ? dir : null;
|
|
@@ -16248,10 +16799,10 @@ async function listLocalSkills(repoPath) {
|
|
|
16248
16799
|
const skillDirs = entries.filter((e) => e.isDirectory());
|
|
16249
16800
|
const skills2 = [];
|
|
16250
16801
|
for (const entry of skillDirs) {
|
|
16251
|
-
const full =
|
|
16802
|
+
const full = join5(dir, entry.name, "SKILL.md");
|
|
16252
16803
|
let raw;
|
|
16253
16804
|
try {
|
|
16254
|
-
raw = await
|
|
16805
|
+
raw = await readFile6(full, "utf8");
|
|
16255
16806
|
} catch (err) {
|
|
16256
16807
|
const code = err.code;
|
|
16257
16808
|
if (code === "ENOENT") continue;
|
|
@@ -16269,10 +16820,10 @@ async function listLocalSkills(repoPath) {
|
|
|
16269
16820
|
async function getLocalSkill(repoPath, name) {
|
|
16270
16821
|
const dir = await resolveSkillsDir(repoPath);
|
|
16271
16822
|
if (!dir) return null;
|
|
16272
|
-
const full =
|
|
16823
|
+
const full = join5(dir, name, "SKILL.md");
|
|
16273
16824
|
let raw;
|
|
16274
16825
|
try {
|
|
16275
|
-
raw = await
|
|
16826
|
+
raw = await readFile6(full, "utf8");
|
|
16276
16827
|
} catch {
|
|
16277
16828
|
return null;
|
|
16278
16829
|
}
|
|
@@ -16641,22 +17192,22 @@ __export(knowledge_exports, {
|
|
|
16641
17192
|
runKnowledgeSave: () => runKnowledgeSave,
|
|
16642
17193
|
runKnowledgeSlots: () => runKnowledgeSlots
|
|
16643
17194
|
});
|
|
16644
|
-
import { readFile as
|
|
17195
|
+
import { readFile as readFile7 } from "node:fs/promises";
|
|
16645
17196
|
async function requireSession3(opts) {
|
|
16646
|
-
const
|
|
16647
|
-
if (!
|
|
17197
|
+
const session = await resolveSession();
|
|
17198
|
+
if (!session) {
|
|
16648
17199
|
emitError(
|
|
16649
17200
|
{
|
|
16650
17201
|
code: "not_signed_in",
|
|
16651
17202
|
message: "not signed in.",
|
|
16652
|
-
hint: "Run `bamboo-agents login` first."
|
|
17203
|
+
hint: "Run `bamboo-agents login` first (or set BAMBOO_API_TOKEN for headless use)."
|
|
16653
17204
|
},
|
|
16654
17205
|
opts,
|
|
16655
17206
|
1
|
|
16656
17207
|
);
|
|
16657
17208
|
throw new Error("unreachable");
|
|
16658
17209
|
}
|
|
16659
|
-
return
|
|
17210
|
+
return session;
|
|
16660
17211
|
}
|
|
16661
17212
|
function padRight2(s, n) {
|
|
16662
17213
|
return s.length >= n ? s : s + " ".repeat(n - s.length);
|
|
@@ -16709,7 +17260,7 @@ async function runKnowledgeSlots(options) {
|
|
|
16709
17260
|
}
|
|
16710
17261
|
async function resolveContent(options) {
|
|
16711
17262
|
if (options.contentFile) {
|
|
16712
|
-
return
|
|
17263
|
+
return readFile7(options.contentFile, "utf8");
|
|
16713
17264
|
}
|
|
16714
17265
|
if (typeof options.content === "string") {
|
|
16715
17266
|
return options.content;
|
|
@@ -17738,7 +18289,15 @@ program2.action(async () => {
|
|
|
17738
18289
|
const { runOrchestrator: runOrchestrator2 } = await Promise.resolve().then(() => (init_orchestrator(), orchestrator_exports));
|
|
17739
18290
|
await runOrchestrator2();
|
|
17740
18291
|
});
|
|
17741
|
-
program2.command("login").description("Sign in to Bamboo via your browser").
|
|
18292
|
+
program2.command("login").description("Sign in to Bamboo via your browser (or use --token for headless setup)").option(
|
|
18293
|
+
"--token <session>",
|
|
18294
|
+
"Headless login with a pre-minted Bamboo session token (skips the browser flow). Used by managed agents + CI environments."
|
|
18295
|
+
).action(async (opts) => {
|
|
18296
|
+
if (opts.token) {
|
|
18297
|
+
const { runLoginWithToken: runLoginWithToken2 } = await Promise.resolve().then(() => (init_login(), login_exports));
|
|
18298
|
+
await runLoginWithToken2(opts.token);
|
|
18299
|
+
return;
|
|
18300
|
+
}
|
|
17742
18301
|
const { runLogin: runLogin2 } = await Promise.resolve().then(() => (init_login(), login_exports));
|
|
17743
18302
|
await runLogin2();
|
|
17744
18303
|
});
|