ccman 3.0.24 → 3.0.27
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +1226 -170
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -39,7 +39,7 @@ var init_package = __esm({
|
|
|
39
39
|
"../core/package.json"() {
|
|
40
40
|
package_default = {
|
|
41
41
|
name: "@ccman/core",
|
|
42
|
-
version: "3.0.
|
|
42
|
+
version: "3.0.27",
|
|
43
43
|
type: "module",
|
|
44
44
|
description: "Core business logic for ccman",
|
|
45
45
|
main: "./dist/index.js",
|
|
@@ -110,7 +110,10 @@ function getCodexAuthPath() {
|
|
|
110
110
|
function getClaudeConfigPath() {
|
|
111
111
|
return path.join(claudeDir, "settings.json");
|
|
112
112
|
}
|
|
113
|
-
|
|
113
|
+
function getClaudeJsonPath() {
|
|
114
|
+
return path.join(rootDir, ".claude.json");
|
|
115
|
+
}
|
|
116
|
+
var os, path, isDev, isTest, rootDir, ccmanDir, codexDir, claudeDir;
|
|
114
117
|
var init_paths = __esm({
|
|
115
118
|
"../core/dist/paths.js"() {
|
|
116
119
|
"use strict";
|
|
@@ -119,20 +122,15 @@ var init_paths = __esm({
|
|
|
119
122
|
isDev = process.env.NODE_ENV === "development";
|
|
120
123
|
isTest = process.env.NODE_ENV === "test";
|
|
121
124
|
if (isTest) {
|
|
122
|
-
|
|
123
|
-
ccmanDir = path.join(testRoot, ".ccman");
|
|
124
|
-
codexDir = path.join(testRoot, ".codex");
|
|
125
|
-
claudeDir = path.join(testRoot, ".claude");
|
|
125
|
+
rootDir = path.join(os.tmpdir(), `ccman-test-${process.pid}`);
|
|
126
126
|
} else if (isDev) {
|
|
127
|
-
|
|
128
|
-
ccmanDir = path.join(devRoot, ".ccman");
|
|
129
|
-
codexDir = path.join(devRoot, ".codex");
|
|
130
|
-
claudeDir = path.join(devRoot, ".claude");
|
|
127
|
+
rootDir = path.join(os.tmpdir(), "ccman-dev");
|
|
131
128
|
} else {
|
|
132
|
-
|
|
133
|
-
codexDir = path.join(os.homedir(), ".codex");
|
|
134
|
-
claudeDir = path.join(os.homedir(), ".claude");
|
|
129
|
+
rootDir = os.homedir();
|
|
135
130
|
}
|
|
131
|
+
ccmanDir = path.join(rootDir, ".ccman");
|
|
132
|
+
codexDir = path.join(rootDir, ".codex");
|
|
133
|
+
claudeDir = path.join(rootDir, ".claude");
|
|
136
134
|
}
|
|
137
135
|
});
|
|
138
136
|
|
|
@@ -2299,6 +2297,167 @@ var init_claude = __esm({
|
|
|
2299
2297
|
}
|
|
2300
2298
|
});
|
|
2301
2299
|
|
|
2300
|
+
// ../core/dist/writers/mcp.js
|
|
2301
|
+
function getMCPConfigPath() {
|
|
2302
|
+
return path3.join(getCcmanDir(), "mcp.json");
|
|
2303
|
+
}
|
|
2304
|
+
function migrateMCPConfig(config) {
|
|
2305
|
+
if (Array.isArray(config.managedServerNames)) {
|
|
2306
|
+
config.managedServerNames = {
|
|
2307
|
+
claude: config.managedServerNames,
|
|
2308
|
+
codex: [],
|
|
2309
|
+
cursor: [],
|
|
2310
|
+
windsurf: []
|
|
2311
|
+
};
|
|
2312
|
+
} else if (!config.managedServerNames) {
|
|
2313
|
+
config.managedServerNames = {
|
|
2314
|
+
claude: [],
|
|
2315
|
+
codex: [],
|
|
2316
|
+
cursor: [],
|
|
2317
|
+
windsurf: []
|
|
2318
|
+
};
|
|
2319
|
+
}
|
|
2320
|
+
if (config.servers) {
|
|
2321
|
+
for (const server of config.servers) {
|
|
2322
|
+
if (!server.enabledApps) {
|
|
2323
|
+
server.enabledApps = ["claude"];
|
|
2324
|
+
}
|
|
2325
|
+
}
|
|
2326
|
+
}
|
|
2327
|
+
return config;
|
|
2328
|
+
}
|
|
2329
|
+
function loadMCPConfig() {
|
|
2330
|
+
const configPath = getMCPConfigPath();
|
|
2331
|
+
if (!fileExists(configPath)) {
|
|
2332
|
+
return {
|
|
2333
|
+
servers: [],
|
|
2334
|
+
managedServerNames: {
|
|
2335
|
+
claude: [],
|
|
2336
|
+
codex: [],
|
|
2337
|
+
cursor: [],
|
|
2338
|
+
windsurf: []
|
|
2339
|
+
}
|
|
2340
|
+
};
|
|
2341
|
+
}
|
|
2342
|
+
const config = readJSON(configPath);
|
|
2343
|
+
return migrateMCPConfig(config);
|
|
2344
|
+
}
|
|
2345
|
+
function saveMCPConfig(config) {
|
|
2346
|
+
const configPath = getMCPConfigPath();
|
|
2347
|
+
writeJSON(configPath, config);
|
|
2348
|
+
}
|
|
2349
|
+
function providerToMCPServer(provider) {
|
|
2350
|
+
let env;
|
|
2351
|
+
let description;
|
|
2352
|
+
if (provider.model) {
|
|
2353
|
+
try {
|
|
2354
|
+
const modelData = JSON.parse(provider.model);
|
|
2355
|
+
env = modelData.env;
|
|
2356
|
+
description = modelData.description;
|
|
2357
|
+
} catch (error) {
|
|
2358
|
+
env = JSON.parse(provider.model);
|
|
2359
|
+
}
|
|
2360
|
+
}
|
|
2361
|
+
return {
|
|
2362
|
+
id: provider.id,
|
|
2363
|
+
name: provider.name,
|
|
2364
|
+
command: provider.baseUrl,
|
|
2365
|
+
args: provider.apiKey.split(" ").filter((arg) => arg.length > 0),
|
|
2366
|
+
env,
|
|
2367
|
+
description,
|
|
2368
|
+
createdAt: provider.createdAt,
|
|
2369
|
+
lastModified: provider.lastModified,
|
|
2370
|
+
enabledApps: ["claude"]
|
|
2371
|
+
// 新创建的 MCP 默认启用 Claude
|
|
2372
|
+
};
|
|
2373
|
+
}
|
|
2374
|
+
function mcpServerToProvider(server) {
|
|
2375
|
+
let model;
|
|
2376
|
+
if (server.env || server.description) {
|
|
2377
|
+
model = JSON.stringify({
|
|
2378
|
+
env: server.env,
|
|
2379
|
+
description: server.description
|
|
2380
|
+
});
|
|
2381
|
+
}
|
|
2382
|
+
return {
|
|
2383
|
+
id: server.id,
|
|
2384
|
+
name: server.name,
|
|
2385
|
+
baseUrl: server.command,
|
|
2386
|
+
apiKey: server.args.join(" "),
|
|
2387
|
+
model,
|
|
2388
|
+
createdAt: server.createdAt,
|
|
2389
|
+
lastModified: server.lastModified
|
|
2390
|
+
};
|
|
2391
|
+
}
|
|
2392
|
+
function writeMCPConfigForApp(app, _provider) {
|
|
2393
|
+
const mcpConfig = loadMCPConfig();
|
|
2394
|
+
const enabledServers = mcpConfig.servers.filter((server) => server.enabledApps.includes(app));
|
|
2395
|
+
let configPath;
|
|
2396
|
+
let configDir;
|
|
2397
|
+
switch (app) {
|
|
2398
|
+
case "claude":
|
|
2399
|
+
configPath = getClaudeConfigPath();
|
|
2400
|
+
configDir = getClaudeDir();
|
|
2401
|
+
break;
|
|
2402
|
+
case "codex":
|
|
2403
|
+
return;
|
|
2404
|
+
case "cursor":
|
|
2405
|
+
return;
|
|
2406
|
+
case "windsurf":
|
|
2407
|
+
return;
|
|
2408
|
+
}
|
|
2409
|
+
ensureDir(configDir);
|
|
2410
|
+
let appConfig = {};
|
|
2411
|
+
if (fileExists(configPath)) {
|
|
2412
|
+
try {
|
|
2413
|
+
const content = fs4.readFileSync(configPath, "utf-8");
|
|
2414
|
+
appConfig = JSON.parse(content);
|
|
2415
|
+
} catch (error) {
|
|
2416
|
+
throw new Error(`\u65E0\u6CD5\u8BFB\u53D6 ${app} \u914D\u7F6E\u6587\u4EF6: ${error.message}`);
|
|
2417
|
+
}
|
|
2418
|
+
}
|
|
2419
|
+
const existingMCPs = appConfig.mcpServers || {};
|
|
2420
|
+
const userMCPs = {};
|
|
2421
|
+
const managedNames = mcpConfig.managedServerNames[app] || [];
|
|
2422
|
+
for (const [name, config] of Object.entries(existingMCPs)) {
|
|
2423
|
+
if (!managedNames.includes(name)) {
|
|
2424
|
+
userMCPs[name] = config;
|
|
2425
|
+
}
|
|
2426
|
+
}
|
|
2427
|
+
const ccmanMCPs = {};
|
|
2428
|
+
for (const server of enabledServers) {
|
|
2429
|
+
ccmanMCPs[server.name] = {
|
|
2430
|
+
command: server.command,
|
|
2431
|
+
args: server.args,
|
|
2432
|
+
env: server.env
|
|
2433
|
+
};
|
|
2434
|
+
}
|
|
2435
|
+
appConfig.mcpServers = {
|
|
2436
|
+
...ccmanMCPs,
|
|
2437
|
+
// ccman 管理的
|
|
2438
|
+
...userMCPs
|
|
2439
|
+
// 用户手动配置的(优先级更高)
|
|
2440
|
+
};
|
|
2441
|
+
const tempPath = `${configPath}.tmp`;
|
|
2442
|
+
fs4.writeFileSync(tempPath, JSON.stringify(appConfig, null, 2), {
|
|
2443
|
+
mode: 384
|
|
2444
|
+
});
|
|
2445
|
+
fs4.renameSync(tempPath, configPath);
|
|
2446
|
+
}
|
|
2447
|
+
function writeMCPConfig(_provider) {
|
|
2448
|
+
writeMCPConfigForApp("claude", _provider);
|
|
2449
|
+
}
|
|
2450
|
+
var fs4, path3;
|
|
2451
|
+
var init_mcp = __esm({
|
|
2452
|
+
"../core/dist/writers/mcp.js"() {
|
|
2453
|
+
"use strict";
|
|
2454
|
+
fs4 = __toESM(require("fs"), 1);
|
|
2455
|
+
path3 = __toESM(require("path"), 1);
|
|
2456
|
+
init_paths();
|
|
2457
|
+
init_file();
|
|
2458
|
+
}
|
|
2459
|
+
});
|
|
2460
|
+
|
|
2302
2461
|
// ../core/dist/presets/codex.js
|
|
2303
2462
|
var CODEX_PRESETS;
|
|
2304
2463
|
var init_codex2 = __esm({
|
|
@@ -2359,6 +2518,102 @@ var init_claude2 = __esm({
|
|
|
2359
2518
|
}
|
|
2360
2519
|
});
|
|
2361
2520
|
|
|
2521
|
+
// ../core/dist/presets/mcp.js
|
|
2522
|
+
var MCP_PRESETS_DETAIL, MCP_PRESETS;
|
|
2523
|
+
var init_mcp2 = __esm({
|
|
2524
|
+
"../core/dist/presets/mcp.js"() {
|
|
2525
|
+
"use strict";
|
|
2526
|
+
MCP_PRESETS_DETAIL = [
|
|
2527
|
+
{
|
|
2528
|
+
name: "filesystem",
|
|
2529
|
+
command: "npx",
|
|
2530
|
+
args: ["-y", "@modelcontextprotocol/server-filesystem", "/path/to/allowed/files"],
|
|
2531
|
+
description: "\u6587\u4EF6\u7CFB\u7EDF\u8BBF\u95EE",
|
|
2532
|
+
argsPlaceholder: "\u9700\u8981\u4FEE\u6539\u7B2C3\u4E2A\u53C2\u6570\u4E3A\u5141\u8BB8\u8BBF\u95EE\u7684\u76EE\u5F55\u8DEF\u5F84"
|
|
2533
|
+
},
|
|
2534
|
+
{
|
|
2535
|
+
name: "github",
|
|
2536
|
+
command: "npx",
|
|
2537
|
+
args: ["-y", "@modelcontextprotocol/server-github"],
|
|
2538
|
+
description: "GitHub \u96C6\u6210",
|
|
2539
|
+
envRequired: ["GITHUB_PERSONAL_ACCESS_TOKEN"]
|
|
2540
|
+
},
|
|
2541
|
+
{
|
|
2542
|
+
name: "postgres",
|
|
2543
|
+
command: "npx",
|
|
2544
|
+
args: ["-y", "@modelcontextprotocol/server-postgres", "postgresql://localhost/mydb"],
|
|
2545
|
+
description: "PostgreSQL \u6570\u636E\u5E93",
|
|
2546
|
+
argsPlaceholder: "\u9700\u8981\u4FEE\u6539\u7B2C3\u4E2A\u53C2\u6570\u4E3A\u6570\u636E\u5E93\u8FDE\u63A5\u5B57\u7B26\u4E32"
|
|
2547
|
+
},
|
|
2548
|
+
{
|
|
2549
|
+
name: "brave-search",
|
|
2550
|
+
command: "npx",
|
|
2551
|
+
args: ["-y", "@modelcontextprotocol/server-brave-search"],
|
|
2552
|
+
description: "Brave \u641C\u7D22",
|
|
2553
|
+
envRequired: ["BRAVE_API_KEY"]
|
|
2554
|
+
},
|
|
2555
|
+
{
|
|
2556
|
+
name: "google-maps",
|
|
2557
|
+
command: "npx",
|
|
2558
|
+
args: ["-y", "@modelcontextprotocol/server-google-maps"],
|
|
2559
|
+
description: "Google Maps",
|
|
2560
|
+
envRequired: ["GOOGLE_MAPS_API_KEY"]
|
|
2561
|
+
},
|
|
2562
|
+
{
|
|
2563
|
+
name: "puppeteer",
|
|
2564
|
+
command: "npx",
|
|
2565
|
+
args: ["-y", "@modelcontextprotocol/server-puppeteer"],
|
|
2566
|
+
description: "\u6D4F\u89C8\u5668\u81EA\u52A8\u5316"
|
|
2567
|
+
},
|
|
2568
|
+
{
|
|
2569
|
+
name: "sqlite",
|
|
2570
|
+
command: "npx",
|
|
2571
|
+
args: ["-y", "@modelcontextprotocol/server-sqlite", "/path/to/database.db"],
|
|
2572
|
+
description: "SQLite \u6570\u636E\u5E93",
|
|
2573
|
+
argsPlaceholder: "\u9700\u8981\u4FEE\u6539\u7B2C3\u4E2A\u53C2\u6570\u4E3A\u6570\u636E\u5E93\u6587\u4EF6\u8DEF\u5F84"
|
|
2574
|
+
},
|
|
2575
|
+
{
|
|
2576
|
+
name: "sequential-thinking",
|
|
2577
|
+
command: "npx",
|
|
2578
|
+
args: ["-y", "@modelcontextprotocol/server-sequential-thinking"],
|
|
2579
|
+
description: "\u5E8F\u5217\u601D\u8003\u589E\u5F3A"
|
|
2580
|
+
}
|
|
2581
|
+
];
|
|
2582
|
+
MCP_PRESETS = MCP_PRESETS_DETAIL.map((preset) => ({
|
|
2583
|
+
name: preset.name,
|
|
2584
|
+
baseUrl: preset.command,
|
|
2585
|
+
// 字段映射:command → baseUrl
|
|
2586
|
+
description: preset.description
|
|
2587
|
+
}));
|
|
2588
|
+
}
|
|
2589
|
+
});
|
|
2590
|
+
|
|
2591
|
+
// ../core/dist/tool-manager.types.js
|
|
2592
|
+
var ProviderNotFoundError, ProviderNameConflictError, PresetNameConflictError;
|
|
2593
|
+
var init_tool_manager_types = __esm({
|
|
2594
|
+
"../core/dist/tool-manager.types.js"() {
|
|
2595
|
+
"use strict";
|
|
2596
|
+
ProviderNotFoundError = class extends Error {
|
|
2597
|
+
constructor(id) {
|
|
2598
|
+
super(`\u670D\u52A1\u5546\u4E0D\u5B58\u5728: ${id}`);
|
|
2599
|
+
this.name = "ProviderNotFoundError";
|
|
2600
|
+
}
|
|
2601
|
+
};
|
|
2602
|
+
ProviderNameConflictError = class extends Error {
|
|
2603
|
+
constructor(name) {
|
|
2604
|
+
super(`\u670D\u52A1\u5546\u540D\u79F0\u5DF2\u5B58\u5728: ${name}`);
|
|
2605
|
+
this.name = "ProviderNameConflictError";
|
|
2606
|
+
}
|
|
2607
|
+
};
|
|
2608
|
+
PresetNameConflictError = class extends Error {
|
|
2609
|
+
constructor(name) {
|
|
2610
|
+
super(`\u9884\u7F6E\u540D\u79F0\u5DF2\u5B58\u5728: ${name}`);
|
|
2611
|
+
this.name = "PresetNameConflictError";
|
|
2612
|
+
}
|
|
2613
|
+
};
|
|
2614
|
+
}
|
|
2615
|
+
});
|
|
2616
|
+
|
|
2362
2617
|
// ../core/dist/tool-manager.js
|
|
2363
2618
|
function createToolManager(tool) {
|
|
2364
2619
|
const toolConfig = TOOL_CONFIGS[tool];
|
|
@@ -2369,6 +2624,9 @@ function createToolManager(tool) {
|
|
|
2369
2624
|
return `${tool}-${timestamp}-${random}`;
|
|
2370
2625
|
}
|
|
2371
2626
|
function loadConfig2() {
|
|
2627
|
+
if (toolConfig.customLoader) {
|
|
2628
|
+
return toolConfig.customLoader();
|
|
2629
|
+
}
|
|
2372
2630
|
if (!fileExists(configPath)) {
|
|
2373
2631
|
ensureDir(getCcmanDir());
|
|
2374
2632
|
const initialConfig = {
|
|
@@ -2381,6 +2639,10 @@ function createToolManager(tool) {
|
|
|
2381
2639
|
return readJSON(configPath);
|
|
2382
2640
|
}
|
|
2383
2641
|
function saveConfig2(config) {
|
|
2642
|
+
if (toolConfig.customSaver) {
|
|
2643
|
+
toolConfig.customSaver(config);
|
|
2644
|
+
return;
|
|
2645
|
+
}
|
|
2384
2646
|
writeJSON(configPath, config);
|
|
2385
2647
|
}
|
|
2386
2648
|
return {
|
|
@@ -2402,6 +2664,9 @@ function createToolManager(tool) {
|
|
|
2402
2664
|
};
|
|
2403
2665
|
config.providers.push(provider);
|
|
2404
2666
|
saveConfig2(config);
|
|
2667
|
+
if (toolConfig.autoSync) {
|
|
2668
|
+
toolConfig.writer(provider);
|
|
2669
|
+
}
|
|
2405
2670
|
return provider;
|
|
2406
2671
|
},
|
|
2407
2672
|
list() {
|
|
@@ -2440,6 +2705,9 @@ function createToolManager(tool) {
|
|
|
2440
2705
|
const provider = config.providers.find((p) => p.id === config.currentProviderId);
|
|
2441
2706
|
return provider || null;
|
|
2442
2707
|
},
|
|
2708
|
+
// 注:edit 方法的"复杂度"来自必要的业务逻辑(检查存在性、名称冲突、更新 4 个可选字段、同步配置)
|
|
2709
|
+
// 每个 if 都不可避免,没有特殊情况或嵌套逻辑,因此禁用 complexity 检查
|
|
2710
|
+
// eslint-disable-next-line complexity
|
|
2443
2711
|
edit(id, updates) {
|
|
2444
2712
|
const config = loadConfig2();
|
|
2445
2713
|
const provider = config.providers.find((p) => p.id === id);
|
|
@@ -2465,6 +2733,9 @@ function createToolManager(tool) {
|
|
|
2465
2733
|
if (config.currentProviderId === id) {
|
|
2466
2734
|
toolConfig.writer(provider);
|
|
2467
2735
|
}
|
|
2736
|
+
if (toolConfig.autoSync) {
|
|
2737
|
+
toolConfig.writer(provider);
|
|
2738
|
+
}
|
|
2468
2739
|
return provider;
|
|
2469
2740
|
},
|
|
2470
2741
|
remove(id) {
|
|
@@ -2478,6 +2749,9 @@ function createToolManager(tool) {
|
|
|
2478
2749
|
}
|
|
2479
2750
|
config.providers.splice(index, 1);
|
|
2480
2751
|
saveConfig2(config);
|
|
2752
|
+
if (toolConfig.autoSync) {
|
|
2753
|
+
toolConfig.writer({});
|
|
2754
|
+
}
|
|
2481
2755
|
},
|
|
2482
2756
|
clone(sourceId, newName) {
|
|
2483
2757
|
const source = this.get(sourceId);
|
|
@@ -2582,45 +2856,63 @@ function createCodexManager() {
|
|
|
2582
2856
|
function createClaudeManager() {
|
|
2583
2857
|
return createToolManager("claude");
|
|
2584
2858
|
}
|
|
2585
|
-
|
|
2859
|
+
function createMCPManager() {
|
|
2860
|
+
return createToolManager("mcp");
|
|
2861
|
+
}
|
|
2862
|
+
var path4, TOOL_CONFIGS;
|
|
2586
2863
|
var init_tool_manager = __esm({
|
|
2587
2864
|
"../core/dist/tool-manager.js"() {
|
|
2588
2865
|
"use strict";
|
|
2589
|
-
|
|
2866
|
+
path4 = __toESM(require("path"), 1);
|
|
2590
2867
|
init_paths();
|
|
2591
2868
|
init_file();
|
|
2592
2869
|
init_codex();
|
|
2593
2870
|
init_claude();
|
|
2871
|
+
init_mcp();
|
|
2594
2872
|
init_codex2();
|
|
2595
2873
|
init_claude2();
|
|
2596
|
-
|
|
2597
|
-
|
|
2598
|
-
super(`\u670D\u52A1\u5546\u4E0D\u5B58\u5728: ${id}`);
|
|
2599
|
-
this.name = "ProviderNotFoundError";
|
|
2600
|
-
}
|
|
2601
|
-
};
|
|
2602
|
-
ProviderNameConflictError = class extends Error {
|
|
2603
|
-
constructor(name) {
|
|
2604
|
-
super(`\u670D\u52A1\u5546\u540D\u79F0\u5DF2\u5B58\u5728: ${name}`);
|
|
2605
|
-
this.name = "ProviderNameConflictError";
|
|
2606
|
-
}
|
|
2607
|
-
};
|
|
2608
|
-
PresetNameConflictError = class extends Error {
|
|
2609
|
-
constructor(name) {
|
|
2610
|
-
super(`\u9884\u7F6E\u540D\u79F0\u5DF2\u5B58\u5728: ${name}`);
|
|
2611
|
-
this.name = "PresetNameConflictError";
|
|
2612
|
-
}
|
|
2613
|
-
};
|
|
2874
|
+
init_mcp2();
|
|
2875
|
+
init_tool_manager_types();
|
|
2614
2876
|
TOOL_CONFIGS = {
|
|
2615
2877
|
codex: {
|
|
2616
|
-
configPath:
|
|
2878
|
+
configPath: path4.join(getCcmanDir(), "codex.json"),
|
|
2617
2879
|
builtinPresets: CODEX_PRESETS,
|
|
2618
2880
|
writer: writeCodexConfig
|
|
2619
2881
|
},
|
|
2620
2882
|
claude: {
|
|
2621
|
-
configPath:
|
|
2883
|
+
configPath: path4.join(getCcmanDir(), "claude.json"),
|
|
2622
2884
|
builtinPresets: CC_PRESETS,
|
|
2623
2885
|
writer: writeClaudeConfig
|
|
2886
|
+
},
|
|
2887
|
+
mcp: {
|
|
2888
|
+
configPath: path4.join(getCcmanDir(), "mcp.json"),
|
|
2889
|
+
builtinPresets: MCP_PRESETS,
|
|
2890
|
+
writer: writeMCPConfig,
|
|
2891
|
+
autoSync: true,
|
|
2892
|
+
// MCP 需要在每个操作后自动同步到 ~/.claude.json
|
|
2893
|
+
// MCP 使用特殊的配置格式(MCPConfig),需要自定义 loader/saver
|
|
2894
|
+
customLoader: () => {
|
|
2895
|
+
const mcpConfig = loadMCPConfig();
|
|
2896
|
+
return {
|
|
2897
|
+
providers: mcpConfig.servers.map(mcpServerToProvider),
|
|
2898
|
+
presets: []
|
|
2899
|
+
};
|
|
2900
|
+
},
|
|
2901
|
+
customSaver: (config) => {
|
|
2902
|
+
const mcpConfig = loadMCPConfig();
|
|
2903
|
+
mcpConfig.servers = config.providers.map((provider) => {
|
|
2904
|
+
const existingServer = mcpConfig.servers.find((s2) => s2.id === provider.id);
|
|
2905
|
+
const mcpServer = providerToMCPServer(provider);
|
|
2906
|
+
if (existingServer) {
|
|
2907
|
+
mcpServer.enabledApps = existingServer.enabledApps;
|
|
2908
|
+
}
|
|
2909
|
+
return mcpServer;
|
|
2910
|
+
});
|
|
2911
|
+
for (const app of ["claude", "codex", "cursor", "windsurf"]) {
|
|
2912
|
+
mcpConfig.managedServerNames[app] = mcpConfig.servers.filter((s2) => s2.enabledApps.includes(app)).map((s2) => s2.name);
|
|
2913
|
+
}
|
|
2914
|
+
saveMCPConfig(mcpConfig);
|
|
2915
|
+
}
|
|
2624
2916
|
}
|
|
2625
2917
|
};
|
|
2626
2918
|
}
|
|
@@ -2637,17 +2929,17 @@ var init_migrate = __esm({
|
|
|
2637
2929
|
// ../core/dist/config.js
|
|
2638
2930
|
function ensureConfigDir() {
|
|
2639
2931
|
const dir = getCcmanDir();
|
|
2640
|
-
if (!
|
|
2641
|
-
|
|
2932
|
+
if (!fs5.existsSync(dir)) {
|
|
2933
|
+
fs5.mkdirSync(dir, { recursive: true, mode: 448 });
|
|
2642
2934
|
}
|
|
2643
2935
|
}
|
|
2644
2936
|
function loadConfig() {
|
|
2645
2937
|
const configPath = getConfigPath();
|
|
2646
|
-
if (!
|
|
2938
|
+
if (!fs5.existsSync(configPath)) {
|
|
2647
2939
|
return {};
|
|
2648
2940
|
}
|
|
2649
2941
|
try {
|
|
2650
|
-
const content =
|
|
2942
|
+
const content = fs5.readFileSync(configPath, "utf-8");
|
|
2651
2943
|
return JSON.parse(content);
|
|
2652
2944
|
} catch (error) {
|
|
2653
2945
|
throw new Error(`Failed to load config: ${error.message}`);
|
|
@@ -2658,10 +2950,10 @@ function saveConfig(config) {
|
|
|
2658
2950
|
const configPath = getConfigPath();
|
|
2659
2951
|
try {
|
|
2660
2952
|
const tempPath = `${configPath}.tmp`;
|
|
2661
|
-
|
|
2953
|
+
fs5.writeFileSync(tempPath, JSON.stringify(config, null, 2), {
|
|
2662
2954
|
mode: 384
|
|
2663
2955
|
});
|
|
2664
|
-
|
|
2956
|
+
fs5.renameSync(tempPath, configPath);
|
|
2665
2957
|
} catch (error) {
|
|
2666
2958
|
throw new Error(`Failed to save config: ${error.message}`);
|
|
2667
2959
|
}
|
|
@@ -2682,11 +2974,11 @@ function updateLastSyncTime() {
|
|
|
2682
2974
|
saveConfig(config);
|
|
2683
2975
|
}
|
|
2684
2976
|
}
|
|
2685
|
-
var
|
|
2977
|
+
var fs5;
|
|
2686
2978
|
var init_config = __esm({
|
|
2687
2979
|
"../core/dist/config.js"() {
|
|
2688
2980
|
"use strict";
|
|
2689
|
-
|
|
2981
|
+
fs5 = __toESM(require("fs"), 1);
|
|
2690
2982
|
init_paths();
|
|
2691
2983
|
}
|
|
2692
2984
|
});
|
|
@@ -2881,22 +3173,22 @@ var require_url_parse = __commonJS({
|
|
|
2881
3173
|
}
|
|
2882
3174
|
function resolve(relative, base) {
|
|
2883
3175
|
if (relative === "") return base;
|
|
2884
|
-
var
|
|
3176
|
+
var path13 = (base || "/").split("/").slice(0, -1).concat(relative.split("/")), i2 = path13.length, last = path13[i2 - 1], unshift = false, up = 0;
|
|
2885
3177
|
while (i2--) {
|
|
2886
|
-
if (
|
|
2887
|
-
|
|
2888
|
-
} else if (
|
|
2889
|
-
|
|
3178
|
+
if (path13[i2] === ".") {
|
|
3179
|
+
path13.splice(i2, 1);
|
|
3180
|
+
} else if (path13[i2] === "..") {
|
|
3181
|
+
path13.splice(i2, 1);
|
|
2890
3182
|
up++;
|
|
2891
3183
|
} else if (up) {
|
|
2892
3184
|
if (i2 === 0) unshift = true;
|
|
2893
|
-
|
|
3185
|
+
path13.splice(i2, 1);
|
|
2894
3186
|
up--;
|
|
2895
3187
|
}
|
|
2896
3188
|
}
|
|
2897
|
-
if (unshift)
|
|
2898
|
-
if (last === "." || last === "..")
|
|
2899
|
-
return
|
|
3189
|
+
if (unshift) path13.unshift("");
|
|
3190
|
+
if (last === "." || last === "..") path13.push("");
|
|
3191
|
+
return path13.join("/");
|
|
2900
3192
|
}
|
|
2901
3193
|
function Url(address, location, parser) {
|
|
2902
3194
|
address = trimLeft(address);
|
|
@@ -3322,14 +3614,14 @@ var require_path_posix = __commonJS({
|
|
|
3322
3614
|
posix.resolve = function() {
|
|
3323
3615
|
var resolvedPath = "", resolvedAbsolute = false;
|
|
3324
3616
|
for (var i2 = arguments.length - 1; i2 >= -1 && !resolvedAbsolute; i2--) {
|
|
3325
|
-
var
|
|
3326
|
-
if (!isString(
|
|
3617
|
+
var path13 = i2 >= 0 ? arguments[i2] : process.cwd();
|
|
3618
|
+
if (!isString(path13)) {
|
|
3327
3619
|
throw new TypeError("Arguments to path.resolve must be strings");
|
|
3328
|
-
} else if (!
|
|
3620
|
+
} else if (!path13) {
|
|
3329
3621
|
continue;
|
|
3330
3622
|
}
|
|
3331
|
-
resolvedPath =
|
|
3332
|
-
resolvedAbsolute =
|
|
3623
|
+
resolvedPath = path13 + "/" + resolvedPath;
|
|
3624
|
+
resolvedAbsolute = path13.charAt(0) === "/";
|
|
3333
3625
|
}
|
|
3334
3626
|
resolvedPath = normalizeArray(
|
|
3335
3627
|
resolvedPath.split("/"),
|
|
@@ -3337,36 +3629,36 @@ var require_path_posix = __commonJS({
|
|
|
3337
3629
|
).join("/");
|
|
3338
3630
|
return (resolvedAbsolute ? "/" : "") + resolvedPath || ".";
|
|
3339
3631
|
};
|
|
3340
|
-
posix.normalize = function(
|
|
3341
|
-
var isAbsolute = posix.isAbsolute(
|
|
3342
|
-
|
|
3343
|
-
if (!
|
|
3344
|
-
|
|
3632
|
+
posix.normalize = function(path13) {
|
|
3633
|
+
var isAbsolute = posix.isAbsolute(path13), trailingSlash = path13.substr(-1) === "/";
|
|
3634
|
+
path13 = normalizeArray(path13.split("/"), !isAbsolute).join("/");
|
|
3635
|
+
if (!path13 && !isAbsolute) {
|
|
3636
|
+
path13 = ".";
|
|
3345
3637
|
}
|
|
3346
|
-
if (
|
|
3347
|
-
|
|
3638
|
+
if (path13 && trailingSlash) {
|
|
3639
|
+
path13 += "/";
|
|
3348
3640
|
}
|
|
3349
|
-
return (isAbsolute ? "/" : "") +
|
|
3641
|
+
return (isAbsolute ? "/" : "") + path13;
|
|
3350
3642
|
};
|
|
3351
|
-
posix.isAbsolute = function(
|
|
3352
|
-
return
|
|
3643
|
+
posix.isAbsolute = function(path13) {
|
|
3644
|
+
return path13.charAt(0) === "/";
|
|
3353
3645
|
};
|
|
3354
3646
|
posix.join = function() {
|
|
3355
|
-
var
|
|
3647
|
+
var path13 = "";
|
|
3356
3648
|
for (var i2 = 0; i2 < arguments.length; i2++) {
|
|
3357
3649
|
var segment = arguments[i2];
|
|
3358
3650
|
if (!isString(segment)) {
|
|
3359
3651
|
throw new TypeError("Arguments to path.join must be strings");
|
|
3360
3652
|
}
|
|
3361
3653
|
if (segment) {
|
|
3362
|
-
if (!
|
|
3363
|
-
|
|
3654
|
+
if (!path13) {
|
|
3655
|
+
path13 += segment;
|
|
3364
3656
|
} else {
|
|
3365
|
-
|
|
3657
|
+
path13 += "/" + segment;
|
|
3366
3658
|
}
|
|
3367
3659
|
}
|
|
3368
3660
|
}
|
|
3369
|
-
return posix.normalize(
|
|
3661
|
+
return posix.normalize(path13);
|
|
3370
3662
|
};
|
|
3371
3663
|
posix.relative = function(from, to) {
|
|
3372
3664
|
from = posix.resolve(from).substr(1);
|
|
@@ -3400,11 +3692,11 @@ var require_path_posix = __commonJS({
|
|
|
3400
3692
|
outputParts = outputParts.concat(toParts.slice(samePartsLength));
|
|
3401
3693
|
return outputParts.join("/");
|
|
3402
3694
|
};
|
|
3403
|
-
posix._makeLong = function(
|
|
3404
|
-
return
|
|
3695
|
+
posix._makeLong = function(path13) {
|
|
3696
|
+
return path13;
|
|
3405
3697
|
};
|
|
3406
|
-
posix.dirname = function(
|
|
3407
|
-
var result = posixSplitPath(
|
|
3698
|
+
posix.dirname = function(path13) {
|
|
3699
|
+
var result = posixSplitPath(path13), root = result[0], dir = result[1];
|
|
3408
3700
|
if (!root && !dir) {
|
|
3409
3701
|
return ".";
|
|
3410
3702
|
}
|
|
@@ -3413,15 +3705,15 @@ var require_path_posix = __commonJS({
|
|
|
3413
3705
|
}
|
|
3414
3706
|
return root + dir;
|
|
3415
3707
|
};
|
|
3416
|
-
posix.basename = function(
|
|
3417
|
-
var f3 = posixSplitPath(
|
|
3708
|
+
posix.basename = function(path13, ext2) {
|
|
3709
|
+
var f3 = posixSplitPath(path13)[2];
|
|
3418
3710
|
if (ext2 && f3.substr(-1 * ext2.length) === ext2) {
|
|
3419
3711
|
f3 = f3.substr(0, f3.length - ext2.length);
|
|
3420
3712
|
}
|
|
3421
3713
|
return f3;
|
|
3422
3714
|
};
|
|
3423
|
-
posix.extname = function(
|
|
3424
|
-
return posixSplitPath(
|
|
3715
|
+
posix.extname = function(path13) {
|
|
3716
|
+
return posixSplitPath(path13)[3];
|
|
3425
3717
|
};
|
|
3426
3718
|
posix.format = function(pathObject) {
|
|
3427
3719
|
if (!util.isObject(pathObject)) {
|
|
@@ -12083,7 +12375,7 @@ var init_escape2 = __esm({
|
|
|
12083
12375
|
});
|
|
12084
12376
|
|
|
12085
12377
|
// ../../node_modules/.pnpm/minimatch@9.0.5/node_modules/minimatch/dist/esm/index.js
|
|
12086
|
-
var import_brace_expansion, minimatch, starDotExtRE, starDotExtTest, starDotExtTestDot, starDotExtTestNocase, starDotExtTestNocaseDot, starDotStarRE, starDotStarTest, starDotStarTestDot, dotStarRE, dotStarTest, starRE, starTest, starTestDot, qmarksRE, qmarksTestNocase, qmarksTestNocaseDot, qmarksTestDot, qmarksTest, qmarksTestNoExt, qmarksTestNoExtDot, defaultPlatform,
|
|
12378
|
+
var import_brace_expansion, minimatch, starDotExtRE, starDotExtTest, starDotExtTestDot, starDotExtTestNocase, starDotExtTestNocaseDot, starDotStarRE, starDotStarTest, starDotStarTestDot, dotStarRE, dotStarTest, starRE, starTest, starTestDot, qmarksRE, qmarksTestNocase, qmarksTestNocaseDot, qmarksTestDot, qmarksTest, qmarksTestNoExt, qmarksTestNoExtDot, defaultPlatform, path6, sep, GLOBSTAR, qmark2, star2, twoStarDot, twoStarNoDot, filter, ext, defaults, braceExpand, makeRe, match, globMagic, regExpEscape2, Minimatch;
|
|
12087
12379
|
var init_esm2 = __esm({
|
|
12088
12380
|
"../../node_modules/.pnpm/minimatch@9.0.5/node_modules/minimatch/dist/esm/index.js"() {
|
|
12089
12381
|
"use strict";
|
|
@@ -12153,11 +12445,11 @@ var init_esm2 = __esm({
|
|
|
12153
12445
|
return (f3) => f3.length === len && f3 !== "." && f3 !== "..";
|
|
12154
12446
|
};
|
|
12155
12447
|
defaultPlatform = typeof process === "object" && process ? typeof process.env === "object" && process.env && process.env.__MINIMATCH_TESTING_PLATFORM__ || process.platform : "posix";
|
|
12156
|
-
|
|
12448
|
+
path6 = {
|
|
12157
12449
|
win32: { sep: "\\" },
|
|
12158
12450
|
posix: { sep: "/" }
|
|
12159
12451
|
};
|
|
12160
|
-
sep = defaultPlatform === "win32" ?
|
|
12452
|
+
sep = defaultPlatform === "win32" ? path6.win32.sep : path6.posix.sep;
|
|
12161
12453
|
minimatch.sep = sep;
|
|
12162
12454
|
GLOBSTAR = Symbol("globstar **");
|
|
12163
12455
|
minimatch.GLOBSTAR = GLOBSTAR;
|
|
@@ -14819,10 +15111,10 @@ var require_nested_property = __commonJS({
|
|
|
14819
15111
|
return false;
|
|
14820
15112
|
}
|
|
14821
15113
|
}
|
|
14822
|
-
function traverse(object,
|
|
15114
|
+
function traverse(object, path13) {
|
|
14823
15115
|
var callback = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : function() {
|
|
14824
15116
|
};
|
|
14825
|
-
var segments =
|
|
15117
|
+
var segments = path13.split(PATH_DELIMITER);
|
|
14826
15118
|
var length = segments.length;
|
|
14827
15119
|
var _loop = function _loop2(idx2) {
|
|
14828
15120
|
var currentSegment = segments[idx2];
|
|
@@ -15064,11 +15356,11 @@ async function createDirectory(context, dirPath, options = {}) {
|
|
|
15064
15356
|
const response = await request(requestOptions, context);
|
|
15065
15357
|
handleResponseCode(context, response);
|
|
15066
15358
|
}
|
|
15067
|
-
function ensureCollectionPath(
|
|
15068
|
-
if (!
|
|
15069
|
-
return
|
|
15359
|
+
function ensureCollectionPath(path13) {
|
|
15360
|
+
if (!path13.endsWith("/")) {
|
|
15361
|
+
return path13 + "/";
|
|
15070
15362
|
}
|
|
15071
|
-
return
|
|
15363
|
+
return path13;
|
|
15072
15364
|
}
|
|
15073
15365
|
async function createDirectoryRecursively(context, dirPath, options = {}) {
|
|
15074
15366
|
const paths = getAllDirectories(normalisePath(dirPath));
|
|
@@ -15443,7 +15735,7 @@ var init_xml = __esm({
|
|
|
15443
15735
|
});
|
|
15444
15736
|
|
|
15445
15737
|
// ../../node_modules/.pnpm/webdav@5.8.0/node_modules/webdav/dist/node/operations/lock.js
|
|
15446
|
-
async function lock(context,
|
|
15738
|
+
async function lock(context, path13, options = {}) {
|
|
15447
15739
|
const { refreshToken, timeout = DEFAULT_TIMEOUT } = options;
|
|
15448
15740
|
const headers = {
|
|
15449
15741
|
Accept: "text/plain,application/xml",
|
|
@@ -15453,7 +15745,7 @@ async function lock(context, path12, options = {}) {
|
|
|
15453
15745
|
headers.If = refreshToken;
|
|
15454
15746
|
}
|
|
15455
15747
|
const requestOptions = prepareRequestOptions({
|
|
15456
|
-
url: joinURL(context.remoteURL, encodePath(
|
|
15748
|
+
url: joinURL(context.remoteURL, encodePath(path13)),
|
|
15457
15749
|
method: "LOCK",
|
|
15458
15750
|
headers,
|
|
15459
15751
|
data: generateLockXML(context.contactHref)
|
|
@@ -15473,9 +15765,9 @@ async function lock(context, path12, options = {}) {
|
|
|
15473
15765
|
serverTimeout
|
|
15474
15766
|
};
|
|
15475
15767
|
}
|
|
15476
|
-
async function unlock(context,
|
|
15768
|
+
async function unlock(context, path13, token, options = {}) {
|
|
15477
15769
|
const requestOptions = prepareRequestOptions({
|
|
15478
|
-
url: joinURL(context.remoteURL, encodePath(
|
|
15770
|
+
url: joinURL(context.remoteURL, encodePath(path13)),
|
|
15479
15771
|
method: "UNLOCK",
|
|
15480
15772
|
headers: {
|
|
15481
15773
|
"Lock-Token": token
|
|
@@ -15525,9 +15817,9 @@ var init_quota = __esm({
|
|
|
15525
15817
|
|
|
15526
15818
|
// ../../node_modules/.pnpm/webdav@5.8.0/node_modules/webdav/dist/node/operations/getQuota.js
|
|
15527
15819
|
async function getQuota(context, options = {}) {
|
|
15528
|
-
const
|
|
15820
|
+
const path13 = options.path || "/";
|
|
15529
15821
|
const requestOptions = prepareRequestOptions({
|
|
15530
|
-
url: joinURL(context.remoteURL,
|
|
15822
|
+
url: joinURL(context.remoteURL, path13),
|
|
15531
15823
|
method: "PROPFIND",
|
|
15532
15824
|
headers: {
|
|
15533
15825
|
Accept: "text/plain,application/xml",
|
|
@@ -15867,29 +16159,29 @@ function createClient(remoteURL, options = {}) {
|
|
|
15867
16159
|
setupAuth(context, username, password, token, ha1);
|
|
15868
16160
|
return {
|
|
15869
16161
|
copyFile: (filename, destination, options2) => copyFile(context, filename, destination, options2),
|
|
15870
|
-
createDirectory: (
|
|
16162
|
+
createDirectory: (path13, options2) => createDirectory(context, path13, options2),
|
|
15871
16163
|
createReadStream: (filename, options2) => createReadStream2(context, filename, options2),
|
|
15872
16164
|
createWriteStream: (filename, options2, callback) => createWriteStream(context, filename, options2, callback),
|
|
15873
|
-
customRequest: (
|
|
16165
|
+
customRequest: (path13, requestOptions) => customRequest(context, path13, requestOptions),
|
|
15874
16166
|
deleteFile: (filename, options2) => deleteFile(context, filename, options2),
|
|
15875
|
-
exists: (
|
|
15876
|
-
getDirectoryContents: (
|
|
16167
|
+
exists: (path13, options2) => exists(context, path13, options2),
|
|
16168
|
+
getDirectoryContents: (path13, options2) => getDirectoryContents(context, path13, options2),
|
|
15877
16169
|
getFileContents: (filename, options2) => getFileContents(context, filename, options2),
|
|
15878
16170
|
getFileDownloadLink: (filename) => getFileDownloadLink(context, filename),
|
|
15879
16171
|
getFileUploadLink: (filename) => getFileUploadLink(context, filename),
|
|
15880
16172
|
getHeaders: () => Object.assign({}, context.headers),
|
|
15881
16173
|
getQuota: (options2) => getQuota(context, options2),
|
|
15882
|
-
lock: (
|
|
16174
|
+
lock: (path13, options2) => lock(context, path13, options2),
|
|
15883
16175
|
moveFile: (filename, destinationFilename, options2) => moveFile(context, filename, destinationFilename, options2),
|
|
15884
16176
|
putFileContents: (filename, data, options2) => putFileContents(context, filename, data, options2),
|
|
15885
16177
|
partialUpdateFileContents: (filePath, start, end, data, options2) => partialUpdateFileContents(context, filePath, start, end, data, options2),
|
|
15886
|
-
getDAVCompliance: (
|
|
15887
|
-
search: (
|
|
16178
|
+
getDAVCompliance: (path13) => getDAVCompliance(context, path13),
|
|
16179
|
+
search: (path13, options2) => getSearch2(context, path13, options2),
|
|
15888
16180
|
setHeaders: (headers2) => {
|
|
15889
16181
|
context.headers = Object.assign({}, headers2);
|
|
15890
16182
|
},
|
|
15891
|
-
stat: (
|
|
15892
|
-
unlock: (
|
|
16183
|
+
stat: (path13, options2) => getStat(context, path13, options2),
|
|
16184
|
+
unlock: (path13, token2, options2) => unlock(context, path13, token2, options2)
|
|
15893
16185
|
};
|
|
15894
16186
|
}
|
|
15895
16187
|
var DEFAULT_CONTACT_HREF;
|
|
@@ -16510,8 +16802,8 @@ var init_sync_v2 = __esm({
|
|
|
16510
16802
|
// ../core/dist/export.js
|
|
16511
16803
|
function validateExport() {
|
|
16512
16804
|
const ccmanDir2 = getCcmanDir();
|
|
16513
|
-
const codexPath =
|
|
16514
|
-
const claudePath =
|
|
16805
|
+
const codexPath = path10.join(ccmanDir2, CODEX_CONFIG_FILE);
|
|
16806
|
+
const claudePath = path10.join(ccmanDir2, CLAUDE_CONFIG_FILE);
|
|
16515
16807
|
const missingFiles = [];
|
|
16516
16808
|
if (!fileExists(codexPath)) {
|
|
16517
16809
|
missingFiles.push(CODEX_CONFIG_FILE);
|
|
@@ -16536,7 +16828,7 @@ function validateImportDir(sourceDir) {
|
|
|
16536
16828
|
foundFiles: []
|
|
16537
16829
|
};
|
|
16538
16830
|
}
|
|
16539
|
-
const stats =
|
|
16831
|
+
const stats = fs9.statSync(sourceDir);
|
|
16540
16832
|
if (!stats.isDirectory()) {
|
|
16541
16833
|
return {
|
|
16542
16834
|
valid: false,
|
|
@@ -16544,8 +16836,8 @@ function validateImportDir(sourceDir) {
|
|
|
16544
16836
|
foundFiles: []
|
|
16545
16837
|
};
|
|
16546
16838
|
}
|
|
16547
|
-
const codexPath =
|
|
16548
|
-
const claudePath =
|
|
16839
|
+
const codexPath = path10.join(sourceDir, CODEX_CONFIG_FILE);
|
|
16840
|
+
const claudePath = path10.join(sourceDir, CLAUDE_CONFIG_FILE);
|
|
16549
16841
|
const foundFiles = [];
|
|
16550
16842
|
if (fileExists(codexPath)) {
|
|
16551
16843
|
foundFiles.push(CODEX_CONFIG_FILE);
|
|
@@ -16573,16 +16865,16 @@ function exportConfig(targetDir) {
|
|
|
16573
16865
|
ensureDir(targetDir);
|
|
16574
16866
|
const ccmanDir2 = getCcmanDir();
|
|
16575
16867
|
const exportedFiles = [];
|
|
16576
|
-
const codexSrc =
|
|
16577
|
-
const codexDst =
|
|
16868
|
+
const codexSrc = path10.join(ccmanDir2, CODEX_CONFIG_FILE);
|
|
16869
|
+
const codexDst = path10.join(targetDir, CODEX_CONFIG_FILE);
|
|
16578
16870
|
if (fileExists(codexSrc)) {
|
|
16579
|
-
|
|
16871
|
+
fs9.copyFileSync(codexSrc, codexDst);
|
|
16580
16872
|
exportedFiles.push(CODEX_CONFIG_FILE);
|
|
16581
16873
|
}
|
|
16582
|
-
const claudeSrc =
|
|
16583
|
-
const claudeDst =
|
|
16874
|
+
const claudeSrc = path10.join(ccmanDir2, CLAUDE_CONFIG_FILE);
|
|
16875
|
+
const claudeDst = path10.join(targetDir, CLAUDE_CONFIG_FILE);
|
|
16584
16876
|
if (fileExists(claudeSrc)) {
|
|
16585
|
-
|
|
16877
|
+
fs9.copyFileSync(claudeSrc, claudeDst);
|
|
16586
16878
|
exportedFiles.push(CLAUDE_CONFIG_FILE);
|
|
16587
16879
|
}
|
|
16588
16880
|
return {
|
|
@@ -16602,23 +16894,23 @@ function importConfig(sourceDir) {
|
|
|
16602
16894
|
ensureDir(ccmanDir2);
|
|
16603
16895
|
try {
|
|
16604
16896
|
if (validation.foundFiles.includes(CODEX_CONFIG_FILE)) {
|
|
16605
|
-
const codexDst =
|
|
16897
|
+
const codexDst = path10.join(ccmanDir2, CODEX_CONFIG_FILE);
|
|
16606
16898
|
if (fileExists(codexDst)) {
|
|
16607
16899
|
const backupPath = backupConfig(codexDst);
|
|
16608
16900
|
backupPaths.push(backupPath);
|
|
16609
16901
|
}
|
|
16610
|
-
const codexSrc =
|
|
16611
|
-
|
|
16902
|
+
const codexSrc = path10.join(sourceDir, CODEX_CONFIG_FILE);
|
|
16903
|
+
fs9.copyFileSync(codexSrc, codexDst);
|
|
16612
16904
|
importedFiles.push(CODEX_CONFIG_FILE);
|
|
16613
16905
|
}
|
|
16614
16906
|
if (validation.foundFiles.includes(CLAUDE_CONFIG_FILE)) {
|
|
16615
|
-
const claudeDst =
|
|
16907
|
+
const claudeDst = path10.join(ccmanDir2, CLAUDE_CONFIG_FILE);
|
|
16616
16908
|
if (fileExists(claudeDst)) {
|
|
16617
16909
|
const backupPath = backupConfig(claudeDst);
|
|
16618
16910
|
backupPaths.push(backupPath);
|
|
16619
16911
|
}
|
|
16620
|
-
const claudeSrc =
|
|
16621
|
-
|
|
16912
|
+
const claudeSrc = path10.join(sourceDir, CLAUDE_CONFIG_FILE);
|
|
16913
|
+
fs9.copyFileSync(claudeSrc, claudeDst);
|
|
16622
16914
|
importedFiles.push(CLAUDE_CONFIG_FILE);
|
|
16623
16915
|
}
|
|
16624
16916
|
return {
|
|
@@ -16630,18 +16922,18 @@ function importConfig(sourceDir) {
|
|
|
16630
16922
|
for (const backupPath of backupPaths) {
|
|
16631
16923
|
const originalPath = backupPath.replace(/\.backup\.\d+$/, "");
|
|
16632
16924
|
if (fileExists(backupPath)) {
|
|
16633
|
-
|
|
16925
|
+
fs9.copyFileSync(backupPath, originalPath);
|
|
16634
16926
|
}
|
|
16635
16927
|
}
|
|
16636
16928
|
throw new Error(`\u5BFC\u5165\u5931\u8D25\uFF0C\u5DF2\u6062\u590D\u5907\u4EFD: ${error.message}`);
|
|
16637
16929
|
}
|
|
16638
16930
|
}
|
|
16639
|
-
var
|
|
16931
|
+
var fs9, path10, CODEX_CONFIG_FILE, CLAUDE_CONFIG_FILE;
|
|
16640
16932
|
var init_export = __esm({
|
|
16641
16933
|
"../core/dist/export.js"() {
|
|
16642
16934
|
"use strict";
|
|
16643
|
-
|
|
16644
|
-
|
|
16935
|
+
fs9 = __toESM(require("fs"), 1);
|
|
16936
|
+
path10 = __toESM(require("path"), 1);
|
|
16645
16937
|
init_paths();
|
|
16646
16938
|
init_file();
|
|
16647
16939
|
init_merge2();
|
|
@@ -16650,6 +16942,155 @@ var init_export = __esm({
|
|
|
16650
16942
|
}
|
|
16651
16943
|
});
|
|
16652
16944
|
|
|
16945
|
+
// ../core/dist/claude-clean.js
|
|
16946
|
+
function formatBytes(bytes) {
|
|
16947
|
+
if (bytes < 1024)
|
|
16948
|
+
return `${bytes} B`;
|
|
16949
|
+
if (bytes < 1024 * 1024)
|
|
16950
|
+
return `${(bytes / 1024).toFixed(1)} KB`;
|
|
16951
|
+
return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
|
|
16952
|
+
}
|
|
16953
|
+
function getFileSize(filePath) {
|
|
16954
|
+
try {
|
|
16955
|
+
const stats = fs10.statSync(filePath);
|
|
16956
|
+
return stats.size;
|
|
16957
|
+
} catch {
|
|
16958
|
+
return 0;
|
|
16959
|
+
}
|
|
16960
|
+
}
|
|
16961
|
+
function backupFile(filePath) {
|
|
16962
|
+
const timestamp = (/* @__PURE__ */ new Date()).toISOString().replace(/:/g, "-").split(".")[0];
|
|
16963
|
+
const backupPath = `${filePath}.backup-${timestamp}`;
|
|
16964
|
+
fs10.copyFileSync(filePath, backupPath);
|
|
16965
|
+
return backupPath;
|
|
16966
|
+
}
|
|
16967
|
+
function saveJsonAtomic(filePath, data) {
|
|
16968
|
+
const tempPath = `${filePath}.tmp`;
|
|
16969
|
+
const content = JSON.stringify(data, null, 2);
|
|
16970
|
+
fs10.writeFileSync(tempPath, content, { mode: 384 });
|
|
16971
|
+
fs10.renameSync(tempPath, filePath);
|
|
16972
|
+
}
|
|
16973
|
+
function analyzeClaudeJson() {
|
|
16974
|
+
const filePath = getClaudeJsonPath();
|
|
16975
|
+
if (!fs10.existsSync(filePath)) {
|
|
16976
|
+
throw new Error("~/.claude.json \u6587\u4EF6\u4E0D\u5B58\u5728");
|
|
16977
|
+
}
|
|
16978
|
+
const fileSize = getFileSize(filePath);
|
|
16979
|
+
const content = fs10.readFileSync(filePath, "utf-8");
|
|
16980
|
+
const config = JSON.parse(content);
|
|
16981
|
+
const projects = config.projects || {};
|
|
16982
|
+
const projectHistory = [];
|
|
16983
|
+
let totalHistoryCount = 0;
|
|
16984
|
+
for (const [projectPath, projectData] of Object.entries(projects)) {
|
|
16985
|
+
const historyCount = projectData.history?.length || 0;
|
|
16986
|
+
totalHistoryCount += historyCount;
|
|
16987
|
+
projectHistory.push({
|
|
16988
|
+
path: projectPath,
|
|
16989
|
+
count: historyCount
|
|
16990
|
+
});
|
|
16991
|
+
}
|
|
16992
|
+
projectHistory.sort((a, b) => b.count - a.count);
|
|
16993
|
+
const cacheSize = config.cachedChangelog?.length || 0;
|
|
16994
|
+
const historySize = fileSize - cacheSize - 2e4;
|
|
16995
|
+
const avgHistorySize = totalHistoryCount > 0 ? historySize / totalHistoryCount : 0;
|
|
16996
|
+
const estimatedSavings = {
|
|
16997
|
+
conservative: Math.floor(avgHistorySize * Math.max(0, totalHistoryCount - projectHistory.length * 10)) + cacheSize,
|
|
16998
|
+
moderate: Math.floor(avgHistorySize * Math.max(0, totalHistoryCount - projectHistory.length * 5)) + cacheSize,
|
|
16999
|
+
aggressive: Math.floor(historySize) + cacheSize
|
|
17000
|
+
};
|
|
17001
|
+
return {
|
|
17002
|
+
fileSize,
|
|
17003
|
+
fileSizeFormatted: formatBytes(fileSize),
|
|
17004
|
+
projectCount: projectHistory.length,
|
|
17005
|
+
totalHistoryCount,
|
|
17006
|
+
projectHistory,
|
|
17007
|
+
cacheSize,
|
|
17008
|
+
estimatedSavings
|
|
17009
|
+
};
|
|
17010
|
+
}
|
|
17011
|
+
function cleanClaudeJson(options = {}) {
|
|
17012
|
+
const filePath = getClaudeJsonPath();
|
|
17013
|
+
if (!fs10.existsSync(filePath)) {
|
|
17014
|
+
throw new Error("~/.claude.json \u6587\u4EF6\u4E0D\u5B58\u5728");
|
|
17015
|
+
}
|
|
17016
|
+
const backupPath = backupFile(filePath);
|
|
17017
|
+
const sizeBefore = getFileSize(filePath);
|
|
17018
|
+
const content = fs10.readFileSync(filePath, "utf-8");
|
|
17019
|
+
const config = JSON.parse(content);
|
|
17020
|
+
const cleanedItems = applyCleanOptions(config, options);
|
|
17021
|
+
saveJsonAtomic(filePath, config);
|
|
17022
|
+
const sizeAfter = getFileSize(filePath);
|
|
17023
|
+
return {
|
|
17024
|
+
sizeBefore,
|
|
17025
|
+
sizeAfter,
|
|
17026
|
+
saved: sizeBefore - sizeAfter,
|
|
17027
|
+
cleanedItems,
|
|
17028
|
+
backupPath
|
|
17029
|
+
};
|
|
17030
|
+
}
|
|
17031
|
+
function applyCleanOptions(config, options) {
|
|
17032
|
+
let projectHistoryCount = 0;
|
|
17033
|
+
if (options.cleanProjectHistory && config.projects) {
|
|
17034
|
+
const keepCount = options.keepRecentCount ?? 10;
|
|
17035
|
+
const targetProjects = options.projectPaths || [];
|
|
17036
|
+
for (const [projectPath, projectData] of Object.entries(config.projects)) {
|
|
17037
|
+
if (targetProjects.length > 0 && !targetProjects.includes(projectPath)) {
|
|
17038
|
+
continue;
|
|
17039
|
+
}
|
|
17040
|
+
if (projectData.history && Array.isArray(projectData.history)) {
|
|
17041
|
+
const originalCount = projectData.history.length;
|
|
17042
|
+
projectData.history = projectData.history.slice(-keepCount);
|
|
17043
|
+
projectHistoryCount += originalCount - projectData.history.length;
|
|
17044
|
+
}
|
|
17045
|
+
}
|
|
17046
|
+
}
|
|
17047
|
+
if (options.cleanCache) {
|
|
17048
|
+
delete config.cachedChangelog;
|
|
17049
|
+
config.changelogLastFetched = 0;
|
|
17050
|
+
}
|
|
17051
|
+
if (options.cleanStats) {
|
|
17052
|
+
config.numStartups = 0;
|
|
17053
|
+
config.promptQueueUseCount = 0;
|
|
17054
|
+
config.tipsHistory = {};
|
|
17055
|
+
}
|
|
17056
|
+
return {
|
|
17057
|
+
projectHistory: projectHistoryCount,
|
|
17058
|
+
cache: options.cleanCache || false,
|
|
17059
|
+
stats: options.cleanStats || false
|
|
17060
|
+
};
|
|
17061
|
+
}
|
|
17062
|
+
var fs10, CleanPresets;
|
|
17063
|
+
var init_claude_clean = __esm({
|
|
17064
|
+
"../core/dist/claude-clean.js"() {
|
|
17065
|
+
"use strict";
|
|
17066
|
+
fs10 = __toESM(require("fs"), 1);
|
|
17067
|
+
init_paths();
|
|
17068
|
+
CleanPresets = {
|
|
17069
|
+
/** 保守清理:保留最近10条记录,清理缓存 */
|
|
17070
|
+
conservative: () => ({
|
|
17071
|
+
cleanProjectHistory: true,
|
|
17072
|
+
keepRecentCount: 10,
|
|
17073
|
+
cleanCache: true,
|
|
17074
|
+
cleanStats: false
|
|
17075
|
+
}),
|
|
17076
|
+
/** 中等清理:保留最近5条记录,清理缓存和统计 */
|
|
17077
|
+
moderate: () => ({
|
|
17078
|
+
cleanProjectHistory: true,
|
|
17079
|
+
keepRecentCount: 5,
|
|
17080
|
+
cleanCache: true,
|
|
17081
|
+
cleanStats: true
|
|
17082
|
+
}),
|
|
17083
|
+
/** 激进清理:清空历史记录,清理缓存和统计 */
|
|
17084
|
+
aggressive: () => ({
|
|
17085
|
+
cleanProjectHistory: true,
|
|
17086
|
+
keepRecentCount: 0,
|
|
17087
|
+
cleanCache: true,
|
|
17088
|
+
cleanStats: true
|
|
17089
|
+
})
|
|
17090
|
+
};
|
|
17091
|
+
}
|
|
17092
|
+
});
|
|
17093
|
+
|
|
16653
17094
|
// ../core/dist/index.js
|
|
16654
17095
|
var VERSION;
|
|
16655
17096
|
var init_dist4 = __esm({
|
|
@@ -16659,6 +17100,8 @@ var init_dist4 = __esm({
|
|
|
16659
17100
|
init_tool_manager();
|
|
16660
17101
|
init_codex2();
|
|
16661
17102
|
init_claude2();
|
|
17103
|
+
init_mcp2();
|
|
17104
|
+
init_mcp();
|
|
16662
17105
|
init_migrate();
|
|
16663
17106
|
init_paths();
|
|
16664
17107
|
init_config();
|
|
@@ -16667,6 +17110,7 @@ var init_dist4 = __esm({
|
|
|
16667
17110
|
init_crypto2();
|
|
16668
17111
|
init_merge_advanced();
|
|
16669
17112
|
init_export();
|
|
17113
|
+
init_claude_clean();
|
|
16670
17114
|
VERSION = package_default.version;
|
|
16671
17115
|
}
|
|
16672
17116
|
});
|
|
@@ -17119,8 +17563,8 @@ function downloadCommand(program2) {
|
|
|
17119
17563
|
console.log();
|
|
17120
17564
|
if (backupPaths.length > 0) {
|
|
17121
17565
|
console.log(import_chalk7.default.gray("\u672C\u5730\u5907\u4EFD:"));
|
|
17122
|
-
backupPaths.forEach((
|
|
17123
|
-
console.log(import_chalk7.default.gray(` ${
|
|
17566
|
+
backupPaths.forEach((path13) => {
|
|
17567
|
+
console.log(import_chalk7.default.gray(` ${path13}`));
|
|
17124
17568
|
});
|
|
17125
17569
|
console.log();
|
|
17126
17570
|
}
|
|
@@ -17182,8 +17626,8 @@ function mergeCommand(program2) {
|
|
|
17182
17626
|
console.log();
|
|
17183
17627
|
if (result.backupPaths.length > 0) {
|
|
17184
17628
|
console.log(import_chalk8.default.gray("\u5907\u4EFD:"));
|
|
17185
|
-
result.backupPaths.forEach((
|
|
17186
|
-
console.log(import_chalk8.default.gray(` ${
|
|
17629
|
+
result.backupPaths.forEach((path13) => {
|
|
17630
|
+
console.log(import_chalk8.default.gray(` ${path13}`));
|
|
17187
17631
|
});
|
|
17188
17632
|
console.log();
|
|
17189
17633
|
}
|
|
@@ -17380,7 +17824,7 @@ var init_sync = __esm({
|
|
|
17380
17824
|
|
|
17381
17825
|
// src/index.ts
|
|
17382
17826
|
var import_commander3 = require("commander");
|
|
17383
|
-
var
|
|
17827
|
+
var import_chalk33 = __toESM(require("chalk"));
|
|
17384
17828
|
|
|
17385
17829
|
// src/utils/logo.ts
|
|
17386
17830
|
var import_chalk = __toESM(require("chalk"));
|
|
@@ -18810,6 +19254,210 @@ function cloneCommand2(program2) {
|
|
|
18810
19254
|
});
|
|
18811
19255
|
}
|
|
18812
19256
|
|
|
19257
|
+
// src/commands/clean.ts
|
|
19258
|
+
var import_chalk26 = __toESM(require("chalk"));
|
|
19259
|
+
var import_inquirer18 = __toESM(require("inquirer"));
|
|
19260
|
+
init_dist4();
|
|
19261
|
+
function formatBytes2(bytes) {
|
|
19262
|
+
if (bytes < 1024) return `${bytes} B`;
|
|
19263
|
+
if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`;
|
|
19264
|
+
return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
|
|
19265
|
+
}
|
|
19266
|
+
function displayAnalysis() {
|
|
19267
|
+
try {
|
|
19268
|
+
console.log(import_chalk26.default.bold("\n\u{1F4CA} \u5206\u6790 ~/.claude.json\n"));
|
|
19269
|
+
const analysis = analyzeClaudeJson();
|
|
19270
|
+
console.log(import_chalk26.default.cyan("\u6587\u4EF6\u5927\u5C0F:"), import_chalk26.default.bold(analysis.fileSizeFormatted));
|
|
19271
|
+
console.log();
|
|
19272
|
+
console.log(import_chalk26.default.cyan("\u9879\u76EE\u7EDF\u8BA1:"));
|
|
19273
|
+
console.log(` \u9879\u76EE\u603B\u6570: ${import_chalk26.default.bold(analysis.projectCount)}`);
|
|
19274
|
+
console.log(` \u5386\u53F2\u8BB0\u5F55\u603B\u6570: ${import_chalk26.default.bold(analysis.totalHistoryCount)} \u6761`);
|
|
19275
|
+
console.log();
|
|
19276
|
+
console.log(import_chalk26.default.cyan("\u5386\u53F2\u8BB0\u5F55\u6700\u591A\u7684\u9879\u76EE:"));
|
|
19277
|
+
const top5 = analysis.projectHistory.slice(0, 5);
|
|
19278
|
+
for (const project of top5) {
|
|
19279
|
+
const displayPath = project.path.length > 50 ? "..." + project.path.slice(-47) : project.path;
|
|
19280
|
+
console.log(` ${import_chalk26.default.bold(project.count.toString().padStart(3))} \u6761 ${displayPath}`);
|
|
19281
|
+
}
|
|
19282
|
+
console.log();
|
|
19283
|
+
console.log(import_chalk26.default.cyan("\u9884\u8BA1\u53EF\u8282\u7701\u7A7A\u95F4:"));
|
|
19284
|
+
console.log(` ${import_chalk26.default.green("\u4FDD\u5B88\u6E05\u7406")} (\u4FDD\u755910\u6761): ${import_chalk26.default.bold(formatBytes2(analysis.estimatedSavings.conservative))}`);
|
|
19285
|
+
console.log(` ${import_chalk26.default.yellow("\u4E2D\u7B49\u6E05\u7406")} (\u4FDD\u75595\u6761): ${import_chalk26.default.bold(formatBytes2(analysis.estimatedSavings.moderate))}`);
|
|
19286
|
+
console.log(` ${import_chalk26.default.red("\u6FC0\u8FDB\u6E05\u7406")} (\u6E05\u7A7A\u5386\u53F2): ${import_chalk26.default.bold(formatBytes2(analysis.estimatedSavings.aggressive))}`);
|
|
19287
|
+
console.log();
|
|
19288
|
+
console.log(import_chalk26.default.blue(`\u{1F4A1} \u6267\u884C\u6E05\u7406: ccman cc clean
|
|
19289
|
+
`));
|
|
19290
|
+
} catch (error) {
|
|
19291
|
+
console.error(import_chalk26.default.red(`
|
|
19292
|
+
\u274C ${error.message}
|
|
19293
|
+
`));
|
|
19294
|
+
process.exit(1);
|
|
19295
|
+
}
|
|
19296
|
+
}
|
|
19297
|
+
function cleanAnalyzeCommand(program2) {
|
|
19298
|
+
program2.command("clean:analyze").description("\u5206\u6790 ~/.claude.json \u6587\u4EF6\u5927\u5C0F\u548C\u5360\u7528").action(() => {
|
|
19299
|
+
displayAnalysis();
|
|
19300
|
+
});
|
|
19301
|
+
}
|
|
19302
|
+
function cleanCommand(program2) {
|
|
19303
|
+
program2.command("clean").description("\u6E05\u7406 ~/.claude.json \u6587\u4EF6\uFF08\u5386\u53F2\u8BB0\u5F55\u3001\u7F13\u5B58\u7B49\uFF09").option("--preset <type>", "\u4F7F\u7528\u9884\u8BBE\u65B9\u6848 (conservative|moderate|aggressive)").option("--keep <count>", "\u4FDD\u7559\u6700\u8FD1N\u6761\u5386\u53F2\u8BB0\u5F55").option("--cache", "\u6E05\u7406\u7F13\u5B58\u6570\u636E").option("--stats", "\u91CD\u7F6E\u4F7F\u7528\u7EDF\u8BA1").option("--projects <paths>", "\u53EA\u6E05\u7406\u6307\u5B9A\u9879\u76EE\uFF08\u9017\u53F7\u5206\u9694\uFF09").action(async (options) => {
|
|
19304
|
+
try {
|
|
19305
|
+
console.log(import_chalk26.default.bold("\n\u{1F9F9} \u6E05\u7406 ~/.claude.json\n"));
|
|
19306
|
+
const analysis = analyzeClaudeJson();
|
|
19307
|
+
console.log(`\u5F53\u524D\u6587\u4EF6\u5927\u5C0F: ${import_chalk26.default.bold(analysis.fileSizeFormatted)}`);
|
|
19308
|
+
console.log(`\u9879\u76EE\u6570: ${analysis.projectCount}, \u5386\u53F2\u8BB0\u5F55: ${analysis.totalHistoryCount} \u6761`);
|
|
19309
|
+
console.log();
|
|
19310
|
+
let cleanOptions;
|
|
19311
|
+
if (options.preset || options.keep || options.cache || options.stats || options.projects) {
|
|
19312
|
+
cleanOptions = buildOptionsFromArgs(options);
|
|
19313
|
+
} else {
|
|
19314
|
+
cleanOptions = await promptForOptions(analysis);
|
|
19315
|
+
}
|
|
19316
|
+
const { confirmed } = await import_inquirer18.default.prompt([
|
|
19317
|
+
{
|
|
19318
|
+
type: "confirm",
|
|
19319
|
+
name: "confirmed",
|
|
19320
|
+
message: "\u786E\u8BA4\u6267\u884C\u6E05\u7406\uFF1F\uFF08\u4F1A\u81EA\u52A8\u5907\u4EFD\u539F\u6587\u4EF6\uFF09",
|
|
19321
|
+
default: true
|
|
19322
|
+
}
|
|
19323
|
+
]);
|
|
19324
|
+
if (!confirmed) {
|
|
19325
|
+
console.log(import_chalk26.default.yellow("\n\u274C \u5DF2\u53D6\u6D88\n"));
|
|
19326
|
+
return;
|
|
19327
|
+
}
|
|
19328
|
+
console.log(import_chalk26.default.cyan("\n\u6B63\u5728\u6E05\u7406...\n"));
|
|
19329
|
+
const result = cleanClaudeJson(cleanOptions);
|
|
19330
|
+
console.log(import_chalk26.default.green("\u2705 \u6E05\u7406\u5B8C\u6210\n"));
|
|
19331
|
+
console.log(`\u6E05\u7406\u524D: ${import_chalk26.default.bold(formatBytes2(result.sizeBefore))}`);
|
|
19332
|
+
console.log(`\u6E05\u7406\u540E: ${import_chalk26.default.bold(formatBytes2(result.sizeAfter))}`);
|
|
19333
|
+
console.log(`\u8282\u7701\u7A7A\u95F4: ${import_chalk26.default.green.bold(formatBytes2(result.saved))} (${(result.saved / result.sizeBefore * 100).toFixed(1)}%)`);
|
|
19334
|
+
console.log();
|
|
19335
|
+
if (result.cleanedItems.projectHistory > 0) {
|
|
19336
|
+
console.log(`\u6E05\u7406\u5386\u53F2\u8BB0\u5F55: ${import_chalk26.default.bold(result.cleanedItems.projectHistory)} \u6761`);
|
|
19337
|
+
}
|
|
19338
|
+
if (result.cleanedItems.cache) {
|
|
19339
|
+
console.log(`\u6E05\u7406\u7F13\u5B58: ${import_chalk26.default.green("\u2713")}`);
|
|
19340
|
+
}
|
|
19341
|
+
if (result.cleanedItems.stats) {
|
|
19342
|
+
console.log(`\u91CD\u7F6E\u7EDF\u8BA1: ${import_chalk26.default.green("\u2713")}`);
|
|
19343
|
+
}
|
|
19344
|
+
console.log();
|
|
19345
|
+
console.log(`\u5907\u4EFD\u6587\u4EF6: ${import_chalk26.default.cyan(result.backupPath)}`);
|
|
19346
|
+
console.log();
|
|
19347
|
+
} catch (error) {
|
|
19348
|
+
console.error(import_chalk26.default.red(`
|
|
19349
|
+
\u274C ${error.message}
|
|
19350
|
+
`));
|
|
19351
|
+
process.exit(1);
|
|
19352
|
+
}
|
|
19353
|
+
});
|
|
19354
|
+
}
|
|
19355
|
+
function buildOptionsFromArgs(args) {
|
|
19356
|
+
if (args.preset) {
|
|
19357
|
+
const preset = args.preset.toLowerCase();
|
|
19358
|
+
if (preset === "conservative") {
|
|
19359
|
+
return CleanPresets.conservative();
|
|
19360
|
+
} else if (preset === "moderate") {
|
|
19361
|
+
return CleanPresets.moderate();
|
|
19362
|
+
} else if (preset === "aggressive") {
|
|
19363
|
+
return CleanPresets.aggressive();
|
|
19364
|
+
} else {
|
|
19365
|
+
throw new Error(`\u672A\u77E5\u7684\u9884\u8BBE\u65B9\u6848: ${preset}\u3002\u53EF\u7528: conservative, moderate, aggressive`);
|
|
19366
|
+
}
|
|
19367
|
+
}
|
|
19368
|
+
const options = {};
|
|
19369
|
+
if (args.keep !== void 0) {
|
|
19370
|
+
options.cleanProjectHistory = true;
|
|
19371
|
+
options.keepRecentCount = parseInt(args.keep, 10);
|
|
19372
|
+
if (isNaN(options.keepRecentCount)) {
|
|
19373
|
+
throw new Error("--keep \u53C2\u6570\u5FC5\u987B\u662F\u6570\u5B57");
|
|
19374
|
+
}
|
|
19375
|
+
}
|
|
19376
|
+
if (args.cache) {
|
|
19377
|
+
options.cleanCache = true;
|
|
19378
|
+
}
|
|
19379
|
+
if (args.stats) {
|
|
19380
|
+
options.cleanStats = true;
|
|
19381
|
+
}
|
|
19382
|
+
if (args.projects) {
|
|
19383
|
+
options.projectPaths = args.projects.split(",").map((p) => p.trim());
|
|
19384
|
+
}
|
|
19385
|
+
if (!options.cleanProjectHistory && !options.cleanCache && !options.cleanStats) {
|
|
19386
|
+
console.log(import_chalk26.default.yellow("\u672A\u6307\u5B9A\u6E05\u7406\u9009\u9879\uFF0C\u4F7F\u7528\u4FDD\u5B88\u9884\u8BBE\n"));
|
|
19387
|
+
return CleanPresets.conservative();
|
|
19388
|
+
}
|
|
19389
|
+
return options;
|
|
19390
|
+
}
|
|
19391
|
+
async function promptForOptions(analysis) {
|
|
19392
|
+
const answers = await import_inquirer18.default.prompt([
|
|
19393
|
+
{
|
|
19394
|
+
type: "list",
|
|
19395
|
+
name: "preset",
|
|
19396
|
+
message: "\u9009\u62E9\u6E05\u7406\u65B9\u6848:",
|
|
19397
|
+
choices: [
|
|
19398
|
+
{
|
|
19399
|
+
name: `${import_chalk26.default.green("\u4FDD\u5B88\u6E05\u7406")} - \u4FDD\u7559\u6700\u8FD110\u6761\u8BB0\u5F55\uFF0C\u6E05\u7406\u7F13\u5B58 (\u8282\u7701\u7EA6 ${formatBytes2(analysis.estimatedSavings.conservative)})`,
|
|
19400
|
+
value: "conservative"
|
|
19401
|
+
},
|
|
19402
|
+
{
|
|
19403
|
+
name: `${import_chalk26.default.yellow("\u4E2D\u7B49\u6E05\u7406")} - \u4FDD\u7559\u6700\u8FD15\u6761\u8BB0\u5F55\uFF0C\u6E05\u7406\u7F13\u5B58\u548C\u7EDF\u8BA1 (\u8282\u7701\u7EA6 ${formatBytes2(analysis.estimatedSavings.moderate)})`,
|
|
19404
|
+
value: "moderate"
|
|
19405
|
+
},
|
|
19406
|
+
{
|
|
19407
|
+
name: `${import_chalk26.default.red("\u6FC0\u8FDB\u6E05\u7406")} - \u6E05\u7A7A\u5386\u53F2\u8BB0\u5F55\uFF0C\u6E05\u7406\u7F13\u5B58\u548C\u7EDF\u8BA1 (\u8282\u7701\u7EA6 ${formatBytes2(analysis.estimatedSavings.aggressive)})`,
|
|
19408
|
+
value: "aggressive"
|
|
19409
|
+
},
|
|
19410
|
+
{
|
|
19411
|
+
name: `${import_chalk26.default.cyan("\u81EA\u5B9A\u4E49")} - \u81EA\u5B9A\u4E49\u6E05\u7406\u9009\u9879`,
|
|
19412
|
+
value: "custom"
|
|
19413
|
+
}
|
|
19414
|
+
]
|
|
19415
|
+
}
|
|
19416
|
+
]);
|
|
19417
|
+
if (answers.preset !== "custom") {
|
|
19418
|
+
if (answers.preset === "conservative") {
|
|
19419
|
+
return CleanPresets.conservative();
|
|
19420
|
+
} else if (answers.preset === "moderate") {
|
|
19421
|
+
return CleanPresets.moderate();
|
|
19422
|
+
} else {
|
|
19423
|
+
return CleanPresets.aggressive();
|
|
19424
|
+
}
|
|
19425
|
+
}
|
|
19426
|
+
const customAnswers = await import_inquirer18.default.prompt([
|
|
19427
|
+
{
|
|
19428
|
+
type: "confirm",
|
|
19429
|
+
name: "cleanHistory",
|
|
19430
|
+
message: "\u6E05\u7406\u9879\u76EE\u5386\u53F2\u8BB0\u5F55\uFF1F",
|
|
19431
|
+
default: true
|
|
19432
|
+
},
|
|
19433
|
+
{
|
|
19434
|
+
type: "number",
|
|
19435
|
+
name: "keepCount",
|
|
19436
|
+
message: "\u6BCF\u4E2A\u9879\u76EE\u4FDD\u7559\u6700\u8FD1\u591A\u5C11\u6761\u8BB0\u5F55\uFF1F",
|
|
19437
|
+
default: 10,
|
|
19438
|
+
when: (answers2) => answers2.cleanHistory
|
|
19439
|
+
},
|
|
19440
|
+
{
|
|
19441
|
+
type: "confirm",
|
|
19442
|
+
name: "cleanCache",
|
|
19443
|
+
message: "\u6E05\u7406\u7F13\u5B58\u6570\u636E\uFF1F",
|
|
19444
|
+
default: true
|
|
19445
|
+
},
|
|
19446
|
+
{
|
|
19447
|
+
type: "confirm",
|
|
19448
|
+
name: "cleanStats",
|
|
19449
|
+
message: "\u91CD\u7F6E\u4F7F\u7528\u7EDF\u8BA1\uFF1F",
|
|
19450
|
+
default: false
|
|
19451
|
+
}
|
|
19452
|
+
]);
|
|
19453
|
+
return {
|
|
19454
|
+
cleanProjectHistory: customAnswers.cleanHistory,
|
|
19455
|
+
keepRecentCount: customAnswers.keepCount || 0,
|
|
19456
|
+
cleanCache: customAnswers.cleanCache,
|
|
19457
|
+
cleanStats: customAnswers.cleanStats
|
|
19458
|
+
};
|
|
19459
|
+
}
|
|
19460
|
+
|
|
18813
19461
|
// src/commands/claude/index.ts
|
|
18814
19462
|
function createClaudeCommands(program2) {
|
|
18815
19463
|
addCommand2(program2);
|
|
@@ -18819,46 +19467,449 @@ function createClaudeCommands(program2) {
|
|
|
18819
19467
|
removeCommand2(program2);
|
|
18820
19468
|
editCommand2(program2);
|
|
18821
19469
|
cloneCommand2(program2);
|
|
19470
|
+
cleanAnalyzeCommand(program2);
|
|
19471
|
+
cleanCommand(program2);
|
|
19472
|
+
}
|
|
19473
|
+
|
|
19474
|
+
// src/commands/mcp/add.ts
|
|
19475
|
+
var import_chalk27 = __toESM(require("chalk"));
|
|
19476
|
+
var import_inquirer19 = __toESM(require("inquirer"));
|
|
19477
|
+
init_dist4();
|
|
19478
|
+
function addCommand3(program2) {
|
|
19479
|
+
program2.command("add").description("\u6DFB\u52A0\u65B0\u7684 MCP \u670D\u52A1\u5668(\u4EA4\u4E92\u5F0F)").action(async () => {
|
|
19480
|
+
try {
|
|
19481
|
+
const manager = createMCPManager();
|
|
19482
|
+
console.log(import_chalk27.default.bold("\n\u{1F4DD} \u6DFB\u52A0 MCP \u670D\u52A1\u5668\n"));
|
|
19483
|
+
const { usePreset } = await import_inquirer19.default.prompt([
|
|
19484
|
+
{
|
|
19485
|
+
type: "list",
|
|
19486
|
+
name: "usePreset",
|
|
19487
|
+
message: "\u9009\u62E9\u914D\u7F6E\u6765\u6E90:",
|
|
19488
|
+
choices: [
|
|
19489
|
+
{ name: "\u{1F4E6} \u4F7F\u7528\u9884\u7F6E MCP \u670D\u52A1\u5668", value: true },
|
|
19490
|
+
{ name: "\u270F\uFE0F \u81EA\u5B9A\u4E49\u914D\u7F6E", value: false }
|
|
19491
|
+
]
|
|
19492
|
+
}
|
|
19493
|
+
]);
|
|
19494
|
+
let name;
|
|
19495
|
+
let command;
|
|
19496
|
+
let args;
|
|
19497
|
+
let env;
|
|
19498
|
+
if (usePreset) {
|
|
19499
|
+
const { presetName } = await import_inquirer19.default.prompt([
|
|
19500
|
+
{
|
|
19501
|
+
type: "list",
|
|
19502
|
+
name: "presetName",
|
|
19503
|
+
message: "\u9009\u62E9\u9884\u7F6E MCP \u670D\u52A1\u5668:",
|
|
19504
|
+
choices: MCP_PRESETS_DETAIL.map((p) => ({
|
|
19505
|
+
name: `${p.name} - ${p.description}`,
|
|
19506
|
+
value: p.name
|
|
19507
|
+
}))
|
|
19508
|
+
}
|
|
19509
|
+
]);
|
|
19510
|
+
const preset = MCP_PRESETS_DETAIL.find((p) => p.name === presetName);
|
|
19511
|
+
console.log(import_chalk27.default.blue(`
|
|
19512
|
+
\u4F7F\u7528\u9884\u8BBE: ${preset.name} - ${preset.description}
|
|
19513
|
+
`));
|
|
19514
|
+
if (preset.argsPlaceholder) {
|
|
19515
|
+
console.log(import_chalk27.default.yellow(`\u26A0\uFE0F ${preset.argsPlaceholder}
|
|
19516
|
+
`));
|
|
19517
|
+
}
|
|
19518
|
+
if (preset.envRequired && preset.envRequired.length > 0) {
|
|
19519
|
+
console.log(import_chalk27.default.yellow(`\u26A0\uFE0F \u9700\u8981\u914D\u7F6E\u73AF\u5883\u53D8\u91CF: ${preset.envRequired.join(", ")}
|
|
19520
|
+
`));
|
|
19521
|
+
}
|
|
19522
|
+
const input = await import_inquirer19.default.prompt([
|
|
19523
|
+
{
|
|
19524
|
+
type: "input",
|
|
19525
|
+
name: "name",
|
|
19526
|
+
message: "MCP \u670D\u52A1\u5668\u540D\u79F0:",
|
|
19527
|
+
default: preset.name,
|
|
19528
|
+
validate: (value) => {
|
|
19529
|
+
if (!value) return "\u540D\u79F0\u4E0D\u80FD\u4E3A\u7A7A";
|
|
19530
|
+
return true;
|
|
19531
|
+
}
|
|
19532
|
+
},
|
|
19533
|
+
{
|
|
19534
|
+
type: "input",
|
|
19535
|
+
name: "command",
|
|
19536
|
+
message: "\u542F\u52A8\u547D\u4EE4:",
|
|
19537
|
+
default: preset.command,
|
|
19538
|
+
validate: (value) => {
|
|
19539
|
+
if (!value) return "\u547D\u4EE4\u4E0D\u80FD\u4E3A\u7A7A";
|
|
19540
|
+
return true;
|
|
19541
|
+
}
|
|
19542
|
+
},
|
|
19543
|
+
{
|
|
19544
|
+
type: "input",
|
|
19545
|
+
name: "args",
|
|
19546
|
+
message: "\u547D\u4EE4\u53C2\u6570 (\u7A7A\u683C\u5206\u9694):",
|
|
19547
|
+
default: preset.args.join(" "),
|
|
19548
|
+
validate: (value) => {
|
|
19549
|
+
if (!value) return "\u53C2\u6570\u4E0D\u80FD\u4E3A\u7A7A";
|
|
19550
|
+
return true;
|
|
19551
|
+
}
|
|
19552
|
+
},
|
|
19553
|
+
{
|
|
19554
|
+
type: "input",
|
|
19555
|
+
name: "env",
|
|
19556
|
+
message: '\u73AF\u5883\u53D8\u91CF (JSON \u683C\u5F0F, \u5982 {"API_KEY": "xxx"}, \u53EF\u7559\u7A7A):',
|
|
19557
|
+
default: ""
|
|
19558
|
+
}
|
|
19559
|
+
]);
|
|
19560
|
+
name = input.name;
|
|
19561
|
+
command = input.command;
|
|
19562
|
+
args = input.args.split(" ").filter((arg) => arg.length > 0);
|
|
19563
|
+
env = input.env ? JSON.parse(input.env) : void 0;
|
|
19564
|
+
} else {
|
|
19565
|
+
const answers = await import_inquirer19.default.prompt([
|
|
19566
|
+
{
|
|
19567
|
+
type: "input",
|
|
19568
|
+
name: "name",
|
|
19569
|
+
message: "MCP \u670D\u52A1\u5668\u540D\u79F0:",
|
|
19570
|
+
validate: (value) => {
|
|
19571
|
+
if (!value) return "\u540D\u79F0\u4E0D\u80FD\u4E3A\u7A7A";
|
|
19572
|
+
return true;
|
|
19573
|
+
}
|
|
19574
|
+
},
|
|
19575
|
+
{
|
|
19576
|
+
type: "input",
|
|
19577
|
+
name: "command",
|
|
19578
|
+
message: "\u542F\u52A8\u547D\u4EE4 (\u5982 npx, node, python):",
|
|
19579
|
+
default: "npx",
|
|
19580
|
+
validate: (value) => {
|
|
19581
|
+
if (!value) return "\u547D\u4EE4\u4E0D\u80FD\u4E3A\u7A7A";
|
|
19582
|
+
return true;
|
|
19583
|
+
}
|
|
19584
|
+
},
|
|
19585
|
+
{
|
|
19586
|
+
type: "input",
|
|
19587
|
+
name: "args",
|
|
19588
|
+
message: "\u547D\u4EE4\u53C2\u6570 (\u7A7A\u683C\u5206\u9694):",
|
|
19589
|
+
validate: (value) => {
|
|
19590
|
+
if (!value) return "\u53C2\u6570\u4E0D\u80FD\u4E3A\u7A7A";
|
|
19591
|
+
return true;
|
|
19592
|
+
}
|
|
19593
|
+
},
|
|
19594
|
+
{
|
|
19595
|
+
type: "input",
|
|
19596
|
+
name: "env",
|
|
19597
|
+
message: '\u73AF\u5883\u53D8\u91CF (JSON \u683C\u5F0F, \u5982 {"API_KEY": "xxx"}, \u53EF\u7559\u7A7A):',
|
|
19598
|
+
default: ""
|
|
19599
|
+
}
|
|
19600
|
+
]);
|
|
19601
|
+
name = answers.name;
|
|
19602
|
+
command = answers.command;
|
|
19603
|
+
args = answers.args.split(" ").filter((arg) => arg.length > 0);
|
|
19604
|
+
env = answers.env ? JSON.parse(answers.env) : void 0;
|
|
19605
|
+
}
|
|
19606
|
+
const provider = manager.add({
|
|
19607
|
+
name,
|
|
19608
|
+
baseUrl: command,
|
|
19609
|
+
apiKey: args.join(" "),
|
|
19610
|
+
model: env ? JSON.stringify(env) : void 0
|
|
19611
|
+
});
|
|
19612
|
+
console.log();
|
|
19613
|
+
console.log(import_chalk27.default.green("\u2705 MCP \u670D\u52A1\u5668\u6DFB\u52A0\u6210\u529F"));
|
|
19614
|
+
console.log();
|
|
19615
|
+
console.log(` ${import_chalk27.default.bold(provider.name)} ${import_chalk27.default.blue("[MCP]")}`);
|
|
19616
|
+
console.log(` ${import_chalk27.default.gray(`${command} ${args.join(" ")}`)}`);
|
|
19617
|
+
if (env) {
|
|
19618
|
+
console.log(import_chalk27.default.gray(` \u73AF\u5883\u53D8\u91CF: ${Object.keys(env).join(", ")}`));
|
|
19619
|
+
}
|
|
19620
|
+
console.log();
|
|
19621
|
+
console.log(import_chalk27.default.green("\u2705 \u914D\u7F6E\u5DF2\u81EA\u52A8\u540C\u6B65\u5230 ~/.claude.json"));
|
|
19622
|
+
console.log();
|
|
19623
|
+
console.log(import_chalk27.default.gray("\u914D\u7F6E\u6587\u4EF6:"));
|
|
19624
|
+
console.log(import_chalk27.default.gray(` - ${getClaudeConfigPath()}`));
|
|
19625
|
+
console.log();
|
|
19626
|
+
} catch (error) {
|
|
19627
|
+
console.error(import_chalk27.default.red(`
|
|
19628
|
+
\u274C ${error.message}
|
|
19629
|
+
`));
|
|
19630
|
+
process.exit(1);
|
|
19631
|
+
}
|
|
19632
|
+
});
|
|
19633
|
+
}
|
|
19634
|
+
|
|
19635
|
+
// src/commands/mcp/list.ts
|
|
19636
|
+
var import_chalk28 = __toESM(require("chalk"));
|
|
19637
|
+
init_dist4();
|
|
19638
|
+
function listCommand3(program2) {
|
|
19639
|
+
program2.command("list").alias("ls").description("\u5217\u51FA\u6240\u6709 MCP \u670D\u52A1\u5668").action(async () => {
|
|
19640
|
+
try {
|
|
19641
|
+
const manager = createMCPManager();
|
|
19642
|
+
const providers = manager.list();
|
|
19643
|
+
if (providers.length === 0) {
|
|
19644
|
+
console.log(import_chalk28.default.yellow("\n\u26A0\uFE0F \u6682\u65E0 MCP \u670D\u52A1\u5668\n"));
|
|
19645
|
+
console.log(import_chalk28.default.blue("\u{1F4A1} \u6DFB\u52A0 MCP \u670D\u52A1\u5668:") + import_chalk28.default.white(" ccman mcp add\n"));
|
|
19646
|
+
return;
|
|
19647
|
+
}
|
|
19648
|
+
console.log(import_chalk28.default.bold(`
|
|
19649
|
+
\u{1F4CB} MCP \u670D\u52A1\u5668 (${providers.length} \u4E2A)
|
|
19650
|
+
`));
|
|
19651
|
+
providers.forEach((provider) => {
|
|
19652
|
+
const isActive = false;
|
|
19653
|
+
const indicator = isActive ? import_chalk28.default.green("\u25CF") : import_chalk28.default.gray("\u25CB");
|
|
19654
|
+
const nameDisplay = import_chalk28.default.bold(provider.name);
|
|
19655
|
+
const commandDisplay = import_chalk28.default.gray(`${provider.baseUrl} ${provider.apiKey}`);
|
|
19656
|
+
console.log(` ${indicator} ${nameDisplay}`);
|
|
19657
|
+
console.log(` ${commandDisplay}`);
|
|
19658
|
+
if (provider.model) {
|
|
19659
|
+
try {
|
|
19660
|
+
const env = JSON.parse(provider.model);
|
|
19661
|
+
const envKeys = Object.keys(env);
|
|
19662
|
+
if (envKeys.length > 0) {
|
|
19663
|
+
console.log(import_chalk28.default.gray(` \u73AF\u5883\u53D8\u91CF: ${envKeys.join(", ")}`));
|
|
19664
|
+
}
|
|
19665
|
+
} catch {
|
|
19666
|
+
}
|
|
19667
|
+
}
|
|
19668
|
+
console.log();
|
|
19669
|
+
});
|
|
19670
|
+
console.log(import_chalk28.default.gray("\u63D0\u793A: \u6240\u6709\u914D\u7F6E\u7684 MCP \u670D\u52A1\u5668\u4F1A\u81EA\u52A8\u540C\u6B65\u5230 ~/.claude.json"));
|
|
19671
|
+
console.log();
|
|
19672
|
+
} catch (error) {
|
|
19673
|
+
console.error(import_chalk28.default.red(`
|
|
19674
|
+
\u274C ${error.message}
|
|
19675
|
+
`));
|
|
19676
|
+
process.exit(1);
|
|
19677
|
+
}
|
|
19678
|
+
});
|
|
19679
|
+
}
|
|
19680
|
+
|
|
19681
|
+
// src/commands/mcp/remove.ts
|
|
19682
|
+
var import_chalk29 = __toESM(require("chalk"));
|
|
19683
|
+
var import_inquirer20 = __toESM(require("inquirer"));
|
|
19684
|
+
init_dist4();
|
|
19685
|
+
function removeCommand3(program2) {
|
|
19686
|
+
program2.command("remove [name]").alias("rm").description("\u5220\u9664 MCP \u670D\u52A1\u5668").action(async (name) => {
|
|
19687
|
+
try {
|
|
19688
|
+
const manager = createMCPManager();
|
|
19689
|
+
const providers = manager.list();
|
|
19690
|
+
if (providers.length === 0) {
|
|
19691
|
+
console.log(import_chalk29.default.yellow("\n\u26A0\uFE0F \u6682\u65E0 MCP \u670D\u52A1\u5668\n"));
|
|
19692
|
+
return;
|
|
19693
|
+
}
|
|
19694
|
+
let targetId;
|
|
19695
|
+
let targetName;
|
|
19696
|
+
if (name) {
|
|
19697
|
+
const provider = manager.findByName(name);
|
|
19698
|
+
if (!provider) {
|
|
19699
|
+
throw new ProviderNotFoundError(name);
|
|
19700
|
+
}
|
|
19701
|
+
targetId = provider.id;
|
|
19702
|
+
targetName = provider.name;
|
|
19703
|
+
} else {
|
|
19704
|
+
const { selectedId } = await import_inquirer20.default.prompt([
|
|
19705
|
+
{
|
|
19706
|
+
type: "list",
|
|
19707
|
+
name: "selectedId",
|
|
19708
|
+
message: "\u9009\u62E9\u8981\u5220\u9664\u7684 MCP \u670D\u52A1\u5668:",
|
|
19709
|
+
choices: providers.map((p) => ({
|
|
19710
|
+
name: `${p.name} - ${p.baseUrl} ${p.apiKey}`,
|
|
19711
|
+
value: p.id
|
|
19712
|
+
}))
|
|
19713
|
+
}
|
|
19714
|
+
]);
|
|
19715
|
+
const provider = manager.get(selectedId);
|
|
19716
|
+
targetId = selectedId;
|
|
19717
|
+
targetName = provider.name;
|
|
19718
|
+
}
|
|
19719
|
+
const { confirmed } = await import_inquirer20.default.prompt([
|
|
19720
|
+
{
|
|
19721
|
+
type: "confirm",
|
|
19722
|
+
name: "confirmed",
|
|
19723
|
+
message: `\u786E\u5B9A\u5220\u9664 "${targetName}"?`,
|
|
19724
|
+
default: false
|
|
19725
|
+
}
|
|
19726
|
+
]);
|
|
19727
|
+
if (!confirmed) {
|
|
19728
|
+
console.log(import_chalk29.default.gray("\n\u5DF2\u53D6\u6D88\n"));
|
|
19729
|
+
return;
|
|
19730
|
+
}
|
|
19731
|
+
manager.remove(targetId);
|
|
19732
|
+
console.log();
|
|
19733
|
+
console.log(import_chalk29.default.green(`\u2705 \u5DF2\u5220\u9664: ${targetName}`));
|
|
19734
|
+
console.log();
|
|
19735
|
+
console.log(import_chalk29.default.green("\u2705 \u914D\u7F6E\u5DF2\u81EA\u52A8\u540C\u6B65\u5230 ~/.claude.json"));
|
|
19736
|
+
console.log();
|
|
19737
|
+
console.log(import_chalk29.default.gray("\u914D\u7F6E\u6587\u4EF6:"));
|
|
19738
|
+
console.log(import_chalk29.default.gray(` - ${getClaudeConfigPath()}`));
|
|
19739
|
+
console.log();
|
|
19740
|
+
} catch (error) {
|
|
19741
|
+
if (error instanceof ProviderNotFoundError) {
|
|
19742
|
+
console.error(import_chalk29.default.red(`
|
|
19743
|
+
\u274C MCP \u670D\u52A1\u5668\u4E0D\u5B58\u5728
|
|
19744
|
+
`));
|
|
19745
|
+
console.log(import_chalk29.default.blue("\u{1F4A1} \u67E5\u770B\u6240\u6709 MCP \u670D\u52A1\u5668:") + import_chalk29.default.white(" ccman mcp list\n"));
|
|
19746
|
+
} else {
|
|
19747
|
+
console.error(import_chalk29.default.red(`
|
|
19748
|
+
\u274C ${error.message}
|
|
19749
|
+
`));
|
|
19750
|
+
}
|
|
19751
|
+
process.exit(1);
|
|
19752
|
+
}
|
|
19753
|
+
});
|
|
19754
|
+
}
|
|
19755
|
+
|
|
19756
|
+
// src/commands/mcp/edit.ts
|
|
19757
|
+
var import_chalk30 = __toESM(require("chalk"));
|
|
19758
|
+
var import_inquirer21 = __toESM(require("inquirer"));
|
|
19759
|
+
init_dist4();
|
|
19760
|
+
function editCommand3(program2) {
|
|
19761
|
+
program2.command("edit [name]").description("\u7F16\u8F91 MCP \u670D\u52A1\u5668").action(async (name) => {
|
|
19762
|
+
try {
|
|
19763
|
+
const manager = createMCPManager();
|
|
19764
|
+
const providers = manager.list();
|
|
19765
|
+
if (providers.length === 0) {
|
|
19766
|
+
console.log(import_chalk30.default.yellow("\n\u26A0\uFE0F \u6682\u65E0 MCP \u670D\u52A1\u5668\n"));
|
|
19767
|
+
return;
|
|
19768
|
+
}
|
|
19769
|
+
let targetId;
|
|
19770
|
+
if (name) {
|
|
19771
|
+
const provider2 = manager.findByName(name);
|
|
19772
|
+
if (!provider2) {
|
|
19773
|
+
throw new ProviderNotFoundError(name);
|
|
19774
|
+
}
|
|
19775
|
+
targetId = provider2.id;
|
|
19776
|
+
} else {
|
|
19777
|
+
const { selectedId } = await import_inquirer21.default.prompt([
|
|
19778
|
+
{
|
|
19779
|
+
type: "list",
|
|
19780
|
+
name: "selectedId",
|
|
19781
|
+
message: "\u9009\u62E9\u8981\u7F16\u8F91\u7684 MCP \u670D\u52A1\u5668:",
|
|
19782
|
+
choices: providers.map((p) => ({
|
|
19783
|
+
name: `${p.name} - ${p.baseUrl} ${p.apiKey}`,
|
|
19784
|
+
value: p.id
|
|
19785
|
+
}))
|
|
19786
|
+
}
|
|
19787
|
+
]);
|
|
19788
|
+
targetId = selectedId;
|
|
19789
|
+
}
|
|
19790
|
+
const provider = manager.get(targetId);
|
|
19791
|
+
const currentCommand3 = provider.baseUrl;
|
|
19792
|
+
const currentArgs = provider.apiKey;
|
|
19793
|
+
const currentEnv = provider.model;
|
|
19794
|
+
console.log(import_chalk30.default.bold("\n\u270F\uFE0F \u7F16\u8F91 MCP \u670D\u52A1\u5668\n"));
|
|
19795
|
+
console.log(import_chalk30.default.gray("\u63D0\u793A: \u7559\u7A7A\u5219\u4FDD\u6301\u539F\u503C\n"));
|
|
19796
|
+
const answers = await import_inquirer21.default.prompt([
|
|
19797
|
+
{
|
|
19798
|
+
type: "input",
|
|
19799
|
+
name: "name",
|
|
19800
|
+
message: "MCP \u670D\u52A1\u5668\u540D\u79F0:",
|
|
19801
|
+
default: provider.name
|
|
19802
|
+
},
|
|
19803
|
+
{
|
|
19804
|
+
type: "input",
|
|
19805
|
+
name: "command",
|
|
19806
|
+
message: "\u542F\u52A8\u547D\u4EE4:",
|
|
19807
|
+
default: currentCommand3
|
|
19808
|
+
},
|
|
19809
|
+
{
|
|
19810
|
+
type: "input",
|
|
19811
|
+
name: "args",
|
|
19812
|
+
message: "\u547D\u4EE4\u53C2\u6570 (\u7A7A\u683C\u5206\u9694, \u7559\u7A7A\u4FDD\u6301\u4E0D\u53D8):",
|
|
19813
|
+
default: currentArgs
|
|
19814
|
+
},
|
|
19815
|
+
{
|
|
19816
|
+
type: "input",
|
|
19817
|
+
name: "env",
|
|
19818
|
+
message: "\u73AF\u5883\u53D8\u91CF (JSON \u683C\u5F0F, \u7559\u7A7A\u4FDD\u6301\u4E0D\u53D8):",
|
|
19819
|
+
default: currentEnv || ""
|
|
19820
|
+
}
|
|
19821
|
+
]);
|
|
19822
|
+
const updates = {};
|
|
19823
|
+
if (answers.name && answers.name !== provider.name) {
|
|
19824
|
+
updates.name = answers.name;
|
|
19825
|
+
}
|
|
19826
|
+
if (answers.command && answers.command !== currentCommand3) {
|
|
19827
|
+
updates.baseUrl = answers.command;
|
|
19828
|
+
}
|
|
19829
|
+
if (answers.args && answers.args !== currentArgs) {
|
|
19830
|
+
updates.apiKey = answers.args;
|
|
19831
|
+
}
|
|
19832
|
+
if (answers.env !== currentEnv) {
|
|
19833
|
+
updates.model = answers.env || void 0;
|
|
19834
|
+
}
|
|
19835
|
+
if (Object.keys(updates).length === 0) {
|
|
19836
|
+
console.log(import_chalk30.default.gray("\n\u672A\u505A\u4EFB\u4F55\u4FEE\u6539\n"));
|
|
19837
|
+
return;
|
|
19838
|
+
}
|
|
19839
|
+
const updated = manager.edit(targetId, updates);
|
|
19840
|
+
console.log();
|
|
19841
|
+
console.log(import_chalk30.default.green("\u2705 \u7F16\u8F91\u6210\u529F"));
|
|
19842
|
+
console.log();
|
|
19843
|
+
console.log(` ${import_chalk30.default.bold(updated.name)} ${import_chalk30.default.blue("[MCP]")}`);
|
|
19844
|
+
console.log(` ${import_chalk30.default.gray(`\u547D\u4EE4: ${updated.baseUrl} ${updated.apiKey}`)}`);
|
|
19845
|
+
if (updated.model) {
|
|
19846
|
+
try {
|
|
19847
|
+
const env = JSON.parse(updated.model);
|
|
19848
|
+
console.log(import_chalk30.default.gray(` \u73AF\u5883\u53D8\u91CF: ${Object.keys(env).join(", ")}`));
|
|
19849
|
+
} catch {
|
|
19850
|
+
}
|
|
19851
|
+
}
|
|
19852
|
+
console.log();
|
|
19853
|
+
console.log(import_chalk30.default.green("\u2705 \u914D\u7F6E\u5DF2\u81EA\u52A8\u540C\u6B65\u5230 ~/.claude.json"));
|
|
19854
|
+
console.log();
|
|
19855
|
+
console.log(import_chalk30.default.gray("\u914D\u7F6E\u6587\u4EF6:"));
|
|
19856
|
+
console.log(import_chalk30.default.gray(` - ${getClaudeConfigPath()}`));
|
|
19857
|
+
console.log();
|
|
19858
|
+
} catch (error) {
|
|
19859
|
+
console.error(import_chalk30.default.red(`
|
|
19860
|
+
\u274C ${error.message}
|
|
19861
|
+
`));
|
|
19862
|
+
process.exit(1);
|
|
19863
|
+
}
|
|
19864
|
+
});
|
|
19865
|
+
}
|
|
19866
|
+
|
|
19867
|
+
// src/commands/mcp/index.ts
|
|
19868
|
+
function createMCPCommands(program2) {
|
|
19869
|
+
addCommand3(program2);
|
|
19870
|
+
listCommand3(program2);
|
|
19871
|
+
removeCommand3(program2);
|
|
19872
|
+
editCommand3(program2);
|
|
18822
19873
|
}
|
|
18823
19874
|
|
|
18824
19875
|
// src/index.ts
|
|
18825
19876
|
init_sync();
|
|
18826
19877
|
|
|
18827
19878
|
// src/commands/export.ts
|
|
18828
|
-
var
|
|
19879
|
+
var import_chalk31 = __toESM(require("chalk"));
|
|
18829
19880
|
var import_path19 = __toESM(require("path"));
|
|
18830
19881
|
init_dist4();
|
|
18831
19882
|
function exportCommand(program2) {
|
|
18832
19883
|
program2.command("export <\u76EE\u6807\u76EE\u5F55>").description("\u5BFC\u51FA\u914D\u7F6E\u5230\u672C\u5730\u76EE\u5F55\uFF08\u5305\u542B API Key\uFF09").action(async (targetDir) => {
|
|
18833
19884
|
try {
|
|
18834
|
-
console.log(
|
|
19885
|
+
console.log(import_chalk31.default.bold("\n\u{1F4E6} \u5BFC\u51FA\u914D\u7F6E\n"));
|
|
18835
19886
|
const validation = validateExport();
|
|
18836
19887
|
if (!validation.valid) {
|
|
18837
|
-
console.log(
|
|
19888
|
+
console.log(import_chalk31.default.red(`\u274C ${validation.message}
|
|
18838
19889
|
`));
|
|
18839
19890
|
process.exit(1);
|
|
18840
19891
|
}
|
|
18841
19892
|
const resolvedPath = targetDir.startsWith("~") ? import_path19.default.join(process.env.HOME || "", targetDir.slice(1)) : import_path19.default.resolve(targetDir);
|
|
18842
19893
|
console.log("\u5BFC\u51FA\u6587\u4EF6:");
|
|
18843
|
-
console.log(` ${
|
|
18844
|
-
console.log(` ${
|
|
19894
|
+
console.log(` ${import_chalk31.default.cyan("codex.json")} - Codex \u914D\u7F6E`);
|
|
19895
|
+
console.log(` ${import_chalk31.default.cyan("claude.json")} - Claude \u914D\u7F6E`);
|
|
18845
19896
|
console.log();
|
|
18846
|
-
console.log(`\u76EE\u6807\u76EE\u5F55: ${
|
|
19897
|
+
console.log(`\u76EE\u6807\u76EE\u5F55: ${import_chalk31.default.cyan(resolvedPath)}`);
|
|
18847
19898
|
console.log();
|
|
18848
|
-
console.log(
|
|
19899
|
+
console.log(import_chalk31.default.yellow("\u26A0\uFE0F \u5BFC\u51FA\u6587\u4EF6\u5305\u542B API Key\uFF0C\u8BF7\u59A5\u5584\u4FDD\u7BA1"));
|
|
18849
19900
|
console.log();
|
|
18850
19901
|
const result = exportConfig(resolvedPath);
|
|
18851
|
-
console.log(
|
|
19902
|
+
console.log(import_chalk31.default.green("\u2705 \u5BFC\u51FA\u6210\u529F"));
|
|
18852
19903
|
console.log();
|
|
18853
19904
|
console.log("\u5DF2\u5BFC\u51FA\u6587\u4EF6:");
|
|
18854
19905
|
for (const file of result.exportedFiles) {
|
|
18855
|
-
console.log(` ${
|
|
19906
|
+
console.log(` ${import_chalk31.default.cyan("\u2713")} ${file}`);
|
|
18856
19907
|
}
|
|
18857
19908
|
console.log();
|
|
18858
|
-
console.log(
|
|
19909
|
+
console.log(import_chalk31.default.blue(`\u{1F4A1} \u5BFC\u5165\u547D\u4EE4: ccman import ${resolvedPath}
|
|
18859
19910
|
`));
|
|
18860
19911
|
} catch (error) {
|
|
18861
|
-
console.error(
|
|
19912
|
+
console.error(import_chalk31.default.red(`
|
|
18862
19913
|
\u274C ${error.message}
|
|
18863
19914
|
`));
|
|
18864
19915
|
process.exit(1);
|
|
@@ -18867,32 +19918,32 @@ function exportCommand(program2) {
|
|
|
18867
19918
|
}
|
|
18868
19919
|
|
|
18869
19920
|
// src/commands/import.ts
|
|
18870
|
-
var
|
|
18871
|
-
var
|
|
19921
|
+
var import_chalk32 = __toESM(require("chalk"));
|
|
19922
|
+
var import_inquirer22 = __toESM(require("inquirer"));
|
|
18872
19923
|
var import_path20 = __toESM(require("path"));
|
|
18873
19924
|
init_dist4();
|
|
18874
19925
|
function importCommand(program2) {
|
|
18875
19926
|
program2.command("import <\u6E90\u76EE\u5F55>").description("\u4ECE\u672C\u5730\u76EE\u5F55\u5BFC\u5165\u914D\u7F6E\uFF08\u4F1A\u8986\u76D6\u5F53\u524D\u914D\u7F6E\uFF09").action(async (sourceDir) => {
|
|
18876
19927
|
try {
|
|
18877
19928
|
const resolvedPath = sourceDir.startsWith("~") ? import_path20.default.join(process.env.HOME || "", sourceDir.slice(1)) : import_path20.default.resolve(sourceDir);
|
|
18878
|
-
console.log(
|
|
19929
|
+
console.log(import_chalk32.default.bold("\n\u{1F4E5} \u5BFC\u5165\u914D\u7F6E\n"));
|
|
18879
19930
|
const validation = validateImportDir(resolvedPath);
|
|
18880
19931
|
if (!validation.valid) {
|
|
18881
|
-
console.log(
|
|
19932
|
+
console.log(import_chalk32.default.red(`\u274C ${validation.message}
|
|
18882
19933
|
`));
|
|
18883
19934
|
process.exit(1);
|
|
18884
19935
|
}
|
|
18885
|
-
console.log(
|
|
18886
|
-
console.log(`\u6E90\u76EE\u5F55: ${
|
|
19936
|
+
console.log(import_chalk32.default.yellow("\u26A0\uFE0F \u8B66\u544A\uFF1A\u5BFC\u5165\u5C06\u8986\u76D6\u5F53\u524D\u914D\u7F6E\n"));
|
|
19937
|
+
console.log(`\u6E90\u76EE\u5F55: ${import_chalk32.default.cyan(resolvedPath)}`);
|
|
18887
19938
|
console.log();
|
|
18888
19939
|
console.log("\u627E\u5230\u914D\u7F6E\u6587\u4EF6:");
|
|
18889
19940
|
for (const file of validation.foundFiles) {
|
|
18890
|
-
console.log(` ${
|
|
19941
|
+
console.log(` ${import_chalk32.default.cyan("\u2713")} ${file}`);
|
|
18891
19942
|
}
|
|
18892
19943
|
console.log();
|
|
18893
|
-
console.log(
|
|
19944
|
+
console.log(import_chalk32.default.gray("\u5F53\u524D\u914D\u7F6E\u5C06\u88AB\u8986\u76D6\uFF08\u81EA\u52A8\u5907\u4EFD\uFF09"));
|
|
18894
19945
|
console.log();
|
|
18895
|
-
const { confirmFirst } = await
|
|
19946
|
+
const { confirmFirst } = await import_inquirer22.default.prompt([
|
|
18896
19947
|
{
|
|
18897
19948
|
type: "confirm",
|
|
18898
19949
|
name: "confirmFirst",
|
|
@@ -18901,13 +19952,13 @@ function importCommand(program2) {
|
|
|
18901
19952
|
}
|
|
18902
19953
|
]);
|
|
18903
19954
|
if (!confirmFirst) {
|
|
18904
|
-
console.log(
|
|
19955
|
+
console.log(import_chalk32.default.gray("\n\u274C \u5DF2\u53D6\u6D88\n"));
|
|
18905
19956
|
return;
|
|
18906
19957
|
}
|
|
18907
19958
|
console.log();
|
|
18908
|
-
console.log(
|
|
19959
|
+
console.log(import_chalk32.default.red.bold("\u26A0\uFE0F \u6700\u540E\u786E\u8BA4\uFF1A\u6B64\u64CD\u4F5C\u5C06\u8986\u76D6\u6240\u6709\u5F53\u524D\u914D\u7F6E\uFF01"));
|
|
18909
19960
|
console.log();
|
|
18910
|
-
const { confirmSecond } = await
|
|
19961
|
+
const { confirmSecond } = await import_inquirer22.default.prompt([
|
|
18911
19962
|
{
|
|
18912
19963
|
type: "confirm",
|
|
18913
19964
|
name: "confirmSecond",
|
|
@@ -18916,31 +19967,31 @@ function importCommand(program2) {
|
|
|
18916
19967
|
}
|
|
18917
19968
|
]);
|
|
18918
19969
|
if (!confirmSecond) {
|
|
18919
|
-
console.log(
|
|
19970
|
+
console.log(import_chalk32.default.gray("\n\u274C \u5DF2\u53D6\u6D88\n"));
|
|
18920
19971
|
return;
|
|
18921
19972
|
}
|
|
18922
19973
|
console.log();
|
|
18923
|
-
console.log(
|
|
18924
|
-
console.log(
|
|
19974
|
+
console.log(import_chalk32.default.gray("\u{1F4BE} \u5907\u4EFD\u5F53\u524D\u914D\u7F6E..."));
|
|
19975
|
+
console.log(import_chalk32.default.gray("\u{1F4E5} \u5BFC\u5165\u65B0\u914D\u7F6E..."));
|
|
18925
19976
|
const result = importConfig(resolvedPath);
|
|
18926
19977
|
console.log();
|
|
18927
|
-
console.log(
|
|
19978
|
+
console.log(import_chalk32.default.green("\u2705 \u5BFC\u5165\u6210\u529F"));
|
|
18928
19979
|
console.log();
|
|
18929
19980
|
if (result.backupPaths.length > 0) {
|
|
18930
19981
|
console.log("\u5907\u4EFD\u6587\u4EF6:");
|
|
18931
19982
|
for (const backupPath of result.backupPaths) {
|
|
18932
|
-
console.log(` ${
|
|
19983
|
+
console.log(` ${import_chalk32.default.gray(backupPath)}`);
|
|
18933
19984
|
}
|
|
18934
19985
|
console.log();
|
|
18935
19986
|
}
|
|
18936
19987
|
console.log("\u5DF2\u5BFC\u5165\u6587\u4EF6:");
|
|
18937
19988
|
for (const file of result.importedFiles) {
|
|
18938
|
-
console.log(` ${
|
|
19989
|
+
console.log(` ${import_chalk32.default.cyan("\u2713")} ${file}`);
|
|
18939
19990
|
}
|
|
18940
19991
|
console.log();
|
|
18941
|
-
console.log(
|
|
19992
|
+
console.log(import_chalk32.default.blue("\u{1F4A1} \u8BF7\u4F7F\u7528 'ccman cx use' \u6216 'ccman cc use' \u5207\u6362\u670D\u52A1\u5546\n"));
|
|
18942
19993
|
} catch (error) {
|
|
18943
|
-
console.error(
|
|
19994
|
+
console.error(import_chalk32.default.red(`
|
|
18944
19995
|
\u274C ${error.message}
|
|
18945
19996
|
`));
|
|
18946
19997
|
process.exit(1);
|
|
@@ -18951,10 +20002,10 @@ function importCommand(program2) {
|
|
|
18951
20002
|
// src/index.ts
|
|
18952
20003
|
init_dist4();
|
|
18953
20004
|
if (process.env.NODE_ENV === "development") {
|
|
18954
|
-
console.log(
|
|
18955
|
-
console.log(
|
|
18956
|
-
console.log(
|
|
18957
|
-
console.log(
|
|
20005
|
+
console.log(import_chalk33.default.gray("\n[\u5F00\u53D1\u6A21\u5F0F] \u914D\u7F6E\u76EE\u5F55:"));
|
|
20006
|
+
console.log(import_chalk33.default.gray(` ccman: ${getCcmanDir()}`));
|
|
20007
|
+
console.log(import_chalk33.default.gray(` codex: ${getCodexDir()}`));
|
|
20008
|
+
console.log(import_chalk33.default.gray(` claude: ${getClaudeDir()}`));
|
|
18958
20009
|
console.log();
|
|
18959
20010
|
}
|
|
18960
20011
|
var program = new import_commander3.Command();
|
|
@@ -18966,21 +20017,21 @@ program.name("ccman").description("Codex/Claude Code API \u670D\u52A1\u5546\u914
|
|
|
18966
20017
|
});
|
|
18967
20018
|
program.on("command:*", (operands) => {
|
|
18968
20019
|
const unknownCommand = operands[0];
|
|
18969
|
-
console.error(
|
|
20020
|
+
console.error(import_chalk33.default.red(`
|
|
18970
20021
|
\u274C \u672A\u77E5\u547D\u4EE4: ${unknownCommand}
|
|
18971
20022
|
`));
|
|
18972
|
-
const availableCommands = ["cx", "cc", "sync", "export", "import"];
|
|
20023
|
+
const availableCommands = ["cx", "cc", "mcp", "sync", "export", "import"];
|
|
18973
20024
|
const suggestions = availableCommands.filter(
|
|
18974
20025
|
(cmd) => cmd.includes(unknownCommand) || unknownCommand.includes(cmd)
|
|
18975
20026
|
);
|
|
18976
20027
|
if (suggestions.length > 0) {
|
|
18977
|
-
console.log(
|
|
20028
|
+
console.log(import_chalk33.default.yellow("\u{1F4A1} \u4F60\u662F\u4E0D\u662F\u60F3\u8F93\u5165:"));
|
|
18978
20029
|
suggestions.forEach((cmd) => {
|
|
18979
|
-
console.log(
|
|
20030
|
+
console.log(import_chalk33.default.cyan(` ccman ${cmd}`));
|
|
18980
20031
|
});
|
|
18981
20032
|
console.log();
|
|
18982
20033
|
}
|
|
18983
|
-
console.log(
|
|
20034
|
+
console.log(import_chalk33.default.gray("\u67E5\u770B\u6240\u6709\u53EF\u7528\u547D\u4EE4: ") + import_chalk33.default.cyan("ccman --help"));
|
|
18984
20035
|
console.log();
|
|
18985
20036
|
process.exit(1);
|
|
18986
20037
|
});
|
|
@@ -18996,6 +20047,11 @@ cc.action(async () => {
|
|
|
18996
20047
|
printLogo();
|
|
18997
20048
|
await startClaudeMenu();
|
|
18998
20049
|
});
|
|
20050
|
+
var mcp = program.command("mcp").description("\u7BA1\u7406 MCP \u670D\u52A1\u5668");
|
|
20051
|
+
createMCPCommands(mcp);
|
|
20052
|
+
mcp.action(() => {
|
|
20053
|
+
mcp.help();
|
|
20054
|
+
});
|
|
18999
20055
|
var sync = program.command("sync").description("WebDAV \u540C\u6B65\u914D\u7F6E");
|
|
19000
20056
|
createSyncCommands(sync);
|
|
19001
20057
|
sync.action(async () => {
|