ccjk 14.2.0 → 14.2.2
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/chunks/api-cli.mjs +3 -2
- package/dist/chunks/api-config-selector.mjs +8 -6
- package/dist/chunks/auto-updater.mjs +1 -1
- package/dist/chunks/ccjk-agents.mjs +2 -2
- package/dist/chunks/ccjk-all.mjs +6 -6
- package/dist/chunks/ccjk-hooks.mjs +2 -2
- package/dist/chunks/ccjk-mcp.mjs +5 -5
- package/dist/chunks/ccjk-setup.mjs +4 -4
- package/dist/chunks/ccjk-skills.mjs +2 -2
- package/dist/chunks/ccr.mjs +11 -9
- package/dist/chunks/check-updates.mjs +2 -1
- package/dist/chunks/claude-code-incremental-manager.mjs +8 -6
- package/dist/chunks/claude-config.mjs +594 -62
- package/dist/chunks/claude-config2.mjs +62 -0
- package/dist/chunks/clavue-config.mjs +1454 -0
- package/dist/chunks/code-type-resolver.mjs +1 -1
- package/dist/chunks/codex-config-switch.mjs +1 -0
- package/dist/chunks/codex-provider-manager.mjs +2 -1
- package/dist/chunks/codex.mjs +4 -3
- package/dist/chunks/config-switch.mjs +6 -4
- package/dist/chunks/config.mjs +7 -1973
- package/dist/chunks/config2.mjs +8 -7
- package/dist/chunks/config3.mjs +1 -0
- package/dist/chunks/doctor.mjs +7 -6
- package/dist/chunks/features.mjs +9 -7
- package/dist/chunks/index10.mjs +14 -5379
- package/dist/chunks/index9.mjs +5379 -14
- package/dist/chunks/init.mjs +12 -10
- package/dist/chunks/installer.mjs +7 -5
- package/dist/chunks/interview.mjs +1 -1
- package/dist/chunks/mcp-cli.mjs +23 -22
- package/dist/chunks/mcp.mjs +8 -7
- package/dist/chunks/package.mjs +1 -1
- package/dist/chunks/platform.mjs +1 -1
- package/dist/chunks/quick-provider.mjs +7 -5
- package/dist/chunks/quick-setup.mjs +7 -5
- package/dist/chunks/simple-config.mjs +3 -2
- package/dist/chunks/slash-commands.mjs +1 -1
- package/dist/chunks/thinking.mjs +1 -1
- package/dist/chunks/uninstall.mjs +1 -1
- package/dist/chunks/update.mjs +10 -9
- package/dist/chunks/version-checker.mjs +1 -1
- package/dist/chunks/zero-config.mjs +4 -3
- package/dist/cli.mjs +3 -3
- package/dist/i18n/locales/en/configuration.json +2 -0
- package/dist/i18n/locales/zh-CN/configuration.json +2 -0
- package/dist/index.mjs +7 -6
- package/dist/shared/{ccjk.DOw7Fawt.mjs → ccjk.5bEolFrk.mjs} +2 -2
- package/dist/shared/{ccjk.DGllfVCZ.mjs → ccjk.BtrioX1Z.mjs} +1 -1
- package/dist/shared/{ccjk.BCzOWT1L.mjs → ccjk.C0WLUnFV.mjs} +12 -2
- package/dist/shared/{ccjk.Cv13QsGp.mjs → ccjk.CoCHVXl3.mjs} +1 -1
- package/dist/shared/{ccjk.f3TBLJSt.mjs → ccjk.CwGZSTAK.mjs} +7 -7
- package/dist/shared/{ccjk.CfKJnpbB.mjs → ccjk.D-magaEx.mjs} +2 -2
- package/dist/shared/{ccjk.CbWVbtb9.mjs → ccjk.DhJ1kyDR.mjs} +1 -1
- package/dist/shared/{ccjk.Cgv_cFVX.mjs → ccjk.L7yC58_i.mjs} +2 -2
- package/dist/shared/{ccjk.zFGcZT7Y.mjs → ccjk.OJKHVSOb.mjs} +1 -1
- package/dist/templates/common/output-styles/zh-CN/codex-rigor-mode.md +114 -0
- package/package.json +43 -40
- package/templates/common/output-styles/zh-CN/codex-rigor-mode.md +114 -0
package/dist/chunks/config.mjs
CHANGED
|
@@ -2,1980 +2,14 @@ import { fileURLToPath } from 'node:url';
|
|
|
2
2
|
import a from './index5.mjs';
|
|
3
3
|
import { d as dayjs } from '../shared/ccjk.RyizuzOI.mjs';
|
|
4
4
|
import { i as inquirer } from './index6.mjs';
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
5
|
+
import { readFileSync } from 'node:fs';
|
|
6
|
+
import { CLAUDE_VSC_CONFIG_FILE, AI_OUTPUT_LANGUAGES, SETTINGS_FILE } from './constants.mjs';
|
|
7
7
|
import { ensureI18nInitialized, i18n } from './index2.mjs';
|
|
8
|
-
import {
|
|
9
|
-
import
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import { ensureDir, exists, copyFile, copyDir, writeFileAtomic } from './fs-operations.mjs';
|
|
13
|
-
import { readJsonConfig, writeJsonConfig, backupJsonConfig } from './json-config.mjs';
|
|
8
|
+
import { h as setPrimaryApiKey, i as addCompletedOnboarding, e as deepMerge } from './claude-config.mjs';
|
|
9
|
+
import { r as resolveClaudeFamilySettingsTarget, n as normalizeClaudeFamilySettings } from '../shared/ccjk.DDL-4C-k.mjs';
|
|
10
|
+
import { exists, ensureDir, copyDir, writeFileAtomic, copyFile } from './fs-operations.mjs';
|
|
11
|
+
import { readJsonConfig, writeJsonConfig } from './json-config.mjs';
|
|
14
12
|
import { j as join, d as dirname } from '../shared/ccjk.bQ7Dh1g4.mjs';
|
|
15
|
-
import { i as isWindows, m as getMcpCommand } from './platform.mjs';
|
|
16
|
-
|
|
17
|
-
const MCP_SERVICE_CONFIGS = [
|
|
18
|
-
// Documentation and research services
|
|
19
|
-
{
|
|
20
|
-
id: "context7",
|
|
21
|
-
requiresApiKey: false,
|
|
22
|
-
defaultSelected: true,
|
|
23
|
-
config: {
|
|
24
|
-
type: "stdio",
|
|
25
|
-
command: "npx",
|
|
26
|
-
args: ["-y", "@upstash/context7-mcp@latest"],
|
|
27
|
-
env: {}
|
|
28
|
-
}
|
|
29
|
-
},
|
|
30
|
-
{
|
|
31
|
-
id: "open-websearch",
|
|
32
|
-
requiresApiKey: false,
|
|
33
|
-
config: {
|
|
34
|
-
type: "stdio",
|
|
35
|
-
command: "npx",
|
|
36
|
-
args: ["-y", "open-websearch@latest"],
|
|
37
|
-
env: {
|
|
38
|
-
MODE: "stdio",
|
|
39
|
-
DEFAULT_SEARCH_ENGINE: "duckduckgo",
|
|
40
|
-
ALLOWED_SEARCH_ENGINES: "duckduckgo,bing,brave"
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
},
|
|
44
|
-
{
|
|
45
|
-
id: "mcp-deepwiki",
|
|
46
|
-
requiresApiKey: false,
|
|
47
|
-
config: {
|
|
48
|
-
type: "stdio",
|
|
49
|
-
command: "npx",
|
|
50
|
-
args: ["-y", "mcp-deepwiki@latest"],
|
|
51
|
-
env: {}
|
|
52
|
-
}
|
|
53
|
-
},
|
|
54
|
-
{
|
|
55
|
-
id: "spec-workflow",
|
|
56
|
-
requiresApiKey: false,
|
|
57
|
-
config: {
|
|
58
|
-
type: "stdio",
|
|
59
|
-
command: "npx",
|
|
60
|
-
args: ["-y", "@pimzino/spec-workflow-mcp@latest"],
|
|
61
|
-
env: {}
|
|
62
|
-
}
|
|
63
|
-
},
|
|
64
|
-
{
|
|
65
|
-
id: "serena",
|
|
66
|
-
requiresApiKey: false,
|
|
67
|
-
config: {
|
|
68
|
-
type: "stdio",
|
|
69
|
-
command: "uvx",
|
|
70
|
-
args: ["--from", "git+https://github.com/oraios/serena", "serena", "start-mcp-server", "--context", "ide-assistant", "--enable-web-dashboard", "false"],
|
|
71
|
-
env: {}
|
|
72
|
-
},
|
|
73
|
-
platformRequirements: {
|
|
74
|
-
requiredCommands: ["uvx"]
|
|
75
|
-
}
|
|
76
|
-
},
|
|
77
|
-
{
|
|
78
|
-
id: "Playwright",
|
|
79
|
-
requiresApiKey: false,
|
|
80
|
-
config: {
|
|
81
|
-
type: "stdio",
|
|
82
|
-
command: "npx",
|
|
83
|
-
args: ["-y", "@playwright/mcp@latest", "--browser", "chromium"],
|
|
84
|
-
env: {}
|
|
85
|
-
},
|
|
86
|
-
platformRequirements: {
|
|
87
|
-
platforms: ["macos", "windows"],
|
|
88
|
-
requiresGui: true
|
|
89
|
-
}
|
|
90
|
-
},
|
|
91
|
-
{
|
|
92
|
-
id: "intent-engine",
|
|
93
|
-
requiresApiKey: false,
|
|
94
|
-
config: {
|
|
95
|
-
type: "stdio",
|
|
96
|
-
command: "npx",
|
|
97
|
-
args: ["-y", "@origintask/intent-engine@latest", "mcp"],
|
|
98
|
-
env: {}
|
|
99
|
-
}
|
|
100
|
-
},
|
|
101
|
-
{
|
|
102
|
-
id: "sqlite",
|
|
103
|
-
requiresApiKey: false,
|
|
104
|
-
config: {
|
|
105
|
-
type: "stdio",
|
|
106
|
-
command: "npx",
|
|
107
|
-
args: ["-y", "@anthropic-ai/mcp-server-sqlite@latest"],
|
|
108
|
-
env: {}
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
];
|
|
112
|
-
async function getMcpServices() {
|
|
113
|
-
ensureI18nInitialized();
|
|
114
|
-
const mcpServiceList = [
|
|
115
|
-
{
|
|
116
|
-
id: "context7",
|
|
117
|
-
name: i18n.t("mcp:services.context7.name"),
|
|
118
|
-
description: i18n.t("mcp:services.context7.description")
|
|
119
|
-
},
|
|
120
|
-
{
|
|
121
|
-
id: "open-websearch",
|
|
122
|
-
name: i18n.t("mcp:services.open-websearch.name"),
|
|
123
|
-
description: i18n.t("mcp:services.open-websearch.description")
|
|
124
|
-
},
|
|
125
|
-
{
|
|
126
|
-
id: "mcp-deepwiki",
|
|
127
|
-
name: i18n.t("mcp:services.mcp-deepwiki.name"),
|
|
128
|
-
description: i18n.t("mcp:services.mcp-deepwiki.description")
|
|
129
|
-
},
|
|
130
|
-
{
|
|
131
|
-
id: "spec-workflow",
|
|
132
|
-
name: i18n.t("mcp:services.spec-workflow.name"),
|
|
133
|
-
description: i18n.t("mcp:services.spec-workflow.description")
|
|
134
|
-
},
|
|
135
|
-
{
|
|
136
|
-
id: "serena",
|
|
137
|
-
name: i18n.t("mcp:services.serena.name"),
|
|
138
|
-
description: i18n.t("mcp:services.serena.description")
|
|
139
|
-
},
|
|
140
|
-
{
|
|
141
|
-
id: "Playwright",
|
|
142
|
-
name: i18n.t("mcp:services.Playwright.name"),
|
|
143
|
-
description: i18n.t("mcp:services.Playwright.description")
|
|
144
|
-
},
|
|
145
|
-
{
|
|
146
|
-
id: "intent-engine",
|
|
147
|
-
name: i18n.t("mcp:services.intent-engine.name"),
|
|
148
|
-
description: i18n.t("mcp:services.intent-engine.description")
|
|
149
|
-
},
|
|
150
|
-
{
|
|
151
|
-
id: "sqlite",
|
|
152
|
-
name: i18n.t("mcp:services.sqlite.name"),
|
|
153
|
-
description: i18n.t("mcp:services.sqlite.description")
|
|
154
|
-
}
|
|
155
|
-
];
|
|
156
|
-
return MCP_SERVICE_CONFIGS.map((config) => {
|
|
157
|
-
const serviceInfo = mcpServiceList.find((s) => s.id === config.id);
|
|
158
|
-
const service = {
|
|
159
|
-
id: config.id,
|
|
160
|
-
name: serviceInfo?.name || config.id,
|
|
161
|
-
description: serviceInfo?.description || "",
|
|
162
|
-
requiresApiKey: config.requiresApiKey,
|
|
163
|
-
config: config.config
|
|
164
|
-
};
|
|
165
|
-
if (config.apiKeyEnvVar) {
|
|
166
|
-
service.apiKeyEnvVar = config.apiKeyEnvVar;
|
|
167
|
-
}
|
|
168
|
-
return service;
|
|
169
|
-
});
|
|
170
|
-
}
|
|
171
|
-
async function getMcpService(id) {
|
|
172
|
-
const services = await getMcpServices();
|
|
173
|
-
return services.find((service) => service.id === id);
|
|
174
|
-
}
|
|
175
|
-
function detectPlatform() {
|
|
176
|
-
const platform = process__default.platform;
|
|
177
|
-
const env = process__default.env;
|
|
178
|
-
const isWsl = !!(env.WSL_DISTRO_NAME || env.WSLENV || env.PATH && env.PATH.includes("/mnt/c/"));
|
|
179
|
-
const isTermux = !!(env.TERMUX_VERSION || env.PREFIX?.includes("com.termux"));
|
|
180
|
-
const isHeadless = !!(env.SSH_CLIENT || env.SSH_TTY || env.SSH_CONNECTION || !env.DISPLAY && platform === "linux");
|
|
181
|
-
const hasGui = (() => {
|
|
182
|
-
if (platform === "darwin")
|
|
183
|
-
return true;
|
|
184
|
-
if (platform === "win32")
|
|
185
|
-
return !isHeadless;
|
|
186
|
-
if (isWsl || isTermux)
|
|
187
|
-
return false;
|
|
188
|
-
if (platform === "linux")
|
|
189
|
-
return !!env.DISPLAY || !!env.WAYLAND_DISPLAY;
|
|
190
|
-
return false;
|
|
191
|
-
})();
|
|
192
|
-
let detectedPlatform;
|
|
193
|
-
if (platform === "darwin") {
|
|
194
|
-
detectedPlatform = "macos";
|
|
195
|
-
} else if (platform === "win32") {
|
|
196
|
-
detectedPlatform = "windows";
|
|
197
|
-
} else if (isWsl) {
|
|
198
|
-
detectedPlatform = "wsl";
|
|
199
|
-
} else if (isTermux) {
|
|
200
|
-
detectedPlatform = "termux";
|
|
201
|
-
} else if (platform === "linux") {
|
|
202
|
-
detectedPlatform = "linux";
|
|
203
|
-
} else {
|
|
204
|
-
detectedPlatform = "unknown";
|
|
205
|
-
}
|
|
206
|
-
return {
|
|
207
|
-
platform: detectedPlatform,
|
|
208
|
-
hasGui,
|
|
209
|
-
isHeadless
|
|
210
|
-
};
|
|
211
|
-
}
|
|
212
|
-
function isCommandAvailable(command) {
|
|
213
|
-
try {
|
|
214
|
-
execSync(`which ${command}`, { stdio: "ignore" });
|
|
215
|
-
return true;
|
|
216
|
-
} catch {
|
|
217
|
-
return false;
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
function isMcpServiceCompatible(serviceId) {
|
|
221
|
-
const config = MCP_SERVICE_CONFIGS.find((c) => c.id === serviceId);
|
|
222
|
-
if (!config) {
|
|
223
|
-
return { compatible: false, reason: "Service not found" };
|
|
224
|
-
}
|
|
225
|
-
const requirements = config.platformRequirements;
|
|
226
|
-
if (!requirements) {
|
|
227
|
-
return { compatible: true };
|
|
228
|
-
}
|
|
229
|
-
const { platform, hasGui } = detectPlatform();
|
|
230
|
-
if (requirements.platforms && requirements.platforms.length > 0) {
|
|
231
|
-
if (platform !== "unknown" && !requirements.platforms.includes(platform)) {
|
|
232
|
-
return {
|
|
233
|
-
compatible: false,
|
|
234
|
-
reason: `Not supported on ${platform}. Requires: ${requirements.platforms.join(", ")}`
|
|
235
|
-
};
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
if (requirements.requiresGui && !hasGui) {
|
|
239
|
-
return {
|
|
240
|
-
compatible: false,
|
|
241
|
-
reason: "Requires GUI environment (X11/Wayland/Desktop)"
|
|
242
|
-
};
|
|
243
|
-
}
|
|
244
|
-
if (requirements.requiredCommands) {
|
|
245
|
-
for (const cmd of requirements.requiredCommands) {
|
|
246
|
-
if (!isCommandAvailable(cmd)) {
|
|
247
|
-
return {
|
|
248
|
-
compatible: false,
|
|
249
|
-
reason: `Required command not found: ${cmd}`
|
|
250
|
-
};
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
return { compatible: true };
|
|
255
|
-
}
|
|
256
|
-
async function getMcpServicesWithCompatibility() {
|
|
257
|
-
const allServices = await getMcpServices();
|
|
258
|
-
return allServices.map((service) => {
|
|
259
|
-
const { compatible, reason } = isMcpServiceCompatible(service.id);
|
|
260
|
-
return {
|
|
261
|
-
...service,
|
|
262
|
-
compatible,
|
|
263
|
-
incompatibleReason: reason
|
|
264
|
-
};
|
|
265
|
-
});
|
|
266
|
-
}
|
|
267
|
-
const DEFAULT_MCP_TOOL_SEARCH_CONFIG = {
|
|
268
|
-
mcpAutoEnableThreshold: 10,
|
|
269
|
-
excludedServices: ["mcp-search", "context7"]
|
|
270
|
-
};
|
|
271
|
-
function getMcpToolSearchConfig() {
|
|
272
|
-
const env = process__default.env;
|
|
273
|
-
return {
|
|
274
|
-
mcpAutoEnableThreshold: env.MCP_AUTO_THRESHOLD || DEFAULT_MCP_TOOL_SEARCH_CONFIG.mcpAutoEnableThreshold,
|
|
275
|
-
dynamicServiceDiscovery: env.MCP_DYNAMIC_DISCOVERY !== "false",
|
|
276
|
-
listChangedNotifications: env.MCP_LIST_CHANGED !== "false",
|
|
277
|
-
excludedServices: env.MCP_EXCLUDED_SERVICES?.split(",").map((s) => s.trim()).filter(Boolean) || DEFAULT_MCP_TOOL_SEARCH_CONFIG.excludedServices
|
|
278
|
-
};
|
|
279
|
-
}
|
|
280
|
-
class DynamicMcpServiceRegistry {
|
|
281
|
-
_services = /* @__PURE__ */ new Map();
|
|
282
|
-
_listeners = /* @__PURE__ */ new Set();
|
|
283
|
-
_enabled = false;
|
|
284
|
-
/**
|
|
285
|
-
* Enable dynamic service discovery
|
|
286
|
-
*/
|
|
287
|
-
enable() {
|
|
288
|
-
this._enabled = true;
|
|
289
|
-
}
|
|
290
|
-
/**
|
|
291
|
-
* Disable dynamic service discovery
|
|
292
|
-
*/
|
|
293
|
-
disable() {
|
|
294
|
-
this._enabled = false;
|
|
295
|
-
}
|
|
296
|
-
/**
|
|
297
|
-
* Check if dynamic discovery is enabled
|
|
298
|
-
*/
|
|
299
|
-
isEnabled() {
|
|
300
|
-
return this._enabled;
|
|
301
|
-
}
|
|
302
|
-
/**
|
|
303
|
-
* Add a service dynamically
|
|
304
|
-
*/
|
|
305
|
-
addService(serviceId, config) {
|
|
306
|
-
if (!this._enabled) {
|
|
307
|
-
return false;
|
|
308
|
-
}
|
|
309
|
-
const isUpdate = this._services.has(serviceId);
|
|
310
|
-
this._services.set(serviceId, config);
|
|
311
|
-
this._notify({
|
|
312
|
-
type: isUpdate ? "updated" : "added",
|
|
313
|
-
serviceId,
|
|
314
|
-
timestamp: Date.now(),
|
|
315
|
-
config
|
|
316
|
-
});
|
|
317
|
-
return true;
|
|
318
|
-
}
|
|
319
|
-
/**
|
|
320
|
-
* Remove a service dynamically
|
|
321
|
-
*/
|
|
322
|
-
removeService(serviceId) {
|
|
323
|
-
if (!this._enabled || !this._services.has(serviceId)) {
|
|
324
|
-
return false;
|
|
325
|
-
}
|
|
326
|
-
const config = this._services.get(serviceId);
|
|
327
|
-
this._services.delete(serviceId);
|
|
328
|
-
this._notify({
|
|
329
|
-
type: "removed",
|
|
330
|
-
serviceId,
|
|
331
|
-
timestamp: Date.now(),
|
|
332
|
-
config
|
|
333
|
-
});
|
|
334
|
-
return true;
|
|
335
|
-
}
|
|
336
|
-
/**
|
|
337
|
-
* Get a service configuration
|
|
338
|
-
*/
|
|
339
|
-
getService(serviceId) {
|
|
340
|
-
return this._services.get(serviceId);
|
|
341
|
-
}
|
|
342
|
-
/**
|
|
343
|
-
* List all dynamically registered services
|
|
344
|
-
*/
|
|
345
|
-
listServices() {
|
|
346
|
-
return new Map(this._services);
|
|
347
|
-
}
|
|
348
|
-
/**
|
|
349
|
-
* Subscribe to list change notifications
|
|
350
|
-
*/
|
|
351
|
-
subscribe(listener) {
|
|
352
|
-
this._listeners.add(listener);
|
|
353
|
-
return () => this._listeners.delete(listener);
|
|
354
|
-
}
|
|
355
|
-
/**
|
|
356
|
-
* Notify all listeners of a change
|
|
357
|
-
*/
|
|
358
|
-
_notify(notification) {
|
|
359
|
-
const toolSearchConfig = getMcpToolSearchConfig();
|
|
360
|
-
if (toolSearchConfig.listChangedNotifications) {
|
|
361
|
-
for (const listener of Array.from(this._listeners)) {
|
|
362
|
-
try {
|
|
363
|
-
listener(notification);
|
|
364
|
-
} catch (error) {
|
|
365
|
-
console.error("Error notifying MCP list change listener:", error);
|
|
366
|
-
}
|
|
367
|
-
}
|
|
368
|
-
}
|
|
369
|
-
}
|
|
370
|
-
}
|
|
371
|
-
const dynamicMcpRegistry = new DynamicMcpServiceRegistry();
|
|
372
|
-
|
|
373
|
-
class ClaudeCodeConfigManager {
|
|
374
|
-
static CONFIG_FILE = ZCF_CONFIG_FILE;
|
|
375
|
-
static LEGACY_CONFIG_FILE = join(ZCF_CONFIG_DIR, "claude-code-configs.json");
|
|
376
|
-
/**
|
|
377
|
-
* Ensure configuration directory exists
|
|
378
|
-
*/
|
|
379
|
-
static ensureConfigDir() {
|
|
380
|
-
ensureDir(ZCF_CONFIG_DIR);
|
|
381
|
-
}
|
|
382
|
-
/**
|
|
383
|
-
* Read TOML configuration
|
|
384
|
-
*/
|
|
385
|
-
static readTomlConfig() {
|
|
386
|
-
return readDefaultTomlConfig();
|
|
387
|
-
}
|
|
388
|
-
/**
|
|
389
|
-
* Load TOML configuration, falling back to default when missing
|
|
390
|
-
*/
|
|
391
|
-
static loadTomlConfig() {
|
|
392
|
-
const existingConfig = this.readTomlConfig();
|
|
393
|
-
if (existingConfig) {
|
|
394
|
-
return existingConfig;
|
|
395
|
-
}
|
|
396
|
-
return createDefaultTomlConfig();
|
|
397
|
-
}
|
|
398
|
-
/**
|
|
399
|
-
* Migrate legacy JSON-based configuration into TOML storage
|
|
400
|
-
*/
|
|
401
|
-
static migrateFromLegacyConfig() {
|
|
402
|
-
if (!exists(this.LEGACY_CONFIG_FILE)) {
|
|
403
|
-
return null;
|
|
404
|
-
}
|
|
405
|
-
try {
|
|
406
|
-
const legacyConfig = readJsonConfig(this.LEGACY_CONFIG_FILE);
|
|
407
|
-
if (!legacyConfig) {
|
|
408
|
-
return null;
|
|
409
|
-
}
|
|
410
|
-
const normalizedProfiles = {};
|
|
411
|
-
const existingKeys = /* @__PURE__ */ new Set();
|
|
412
|
-
let migratedCurrentKey = "";
|
|
413
|
-
Object.entries(legacyConfig.profiles || {}).forEach(([legacyKey, profile]) => {
|
|
414
|
-
const sourceProfile = profile;
|
|
415
|
-
const name = sourceProfile.name?.trim() || legacyKey;
|
|
416
|
-
const baseKey = this.generateProfileId(name);
|
|
417
|
-
let uniqueKey = baseKey || legacyKey;
|
|
418
|
-
let suffix = 2;
|
|
419
|
-
while (existingKeys.has(uniqueKey)) {
|
|
420
|
-
uniqueKey = `${baseKey || legacyKey}-${suffix++}`;
|
|
421
|
-
}
|
|
422
|
-
existingKeys.add(uniqueKey);
|
|
423
|
-
const sanitizedProfile = this.sanitizeProfile({
|
|
424
|
-
...sourceProfile,
|
|
425
|
-
name
|
|
426
|
-
});
|
|
427
|
-
normalizedProfiles[uniqueKey] = {
|
|
428
|
-
...sanitizedProfile,
|
|
429
|
-
id: uniqueKey
|
|
430
|
-
};
|
|
431
|
-
if (legacyConfig.currentProfileId === legacyKey || legacyConfig.currentProfileId === sourceProfile.id) {
|
|
432
|
-
migratedCurrentKey = uniqueKey;
|
|
433
|
-
}
|
|
434
|
-
});
|
|
435
|
-
if (!migratedCurrentKey && legacyConfig.currentProfileId) {
|
|
436
|
-
const fallbackKey = this.generateProfileId(legacyConfig.currentProfileId);
|
|
437
|
-
if (existingKeys.has(fallbackKey)) {
|
|
438
|
-
migratedCurrentKey = fallbackKey;
|
|
439
|
-
}
|
|
440
|
-
}
|
|
441
|
-
if (!migratedCurrentKey && existingKeys.size > 0) {
|
|
442
|
-
migratedCurrentKey = Array.from(existingKeys)[0];
|
|
443
|
-
}
|
|
444
|
-
const migratedConfig = {
|
|
445
|
-
currentProfileId: migratedCurrentKey,
|
|
446
|
-
profiles: normalizedProfiles
|
|
447
|
-
};
|
|
448
|
-
this.writeConfig(migratedConfig);
|
|
449
|
-
return migratedConfig;
|
|
450
|
-
} catch (error) {
|
|
451
|
-
console.error("Failed to migrate legacy Claude Code config:", error);
|
|
452
|
-
return null;
|
|
453
|
-
}
|
|
454
|
-
}
|
|
455
|
-
/**
|
|
456
|
-
* Read configuration
|
|
457
|
-
*/
|
|
458
|
-
static readConfig() {
|
|
459
|
-
try {
|
|
460
|
-
const tomlConfig = readDefaultTomlConfig();
|
|
461
|
-
if (!tomlConfig || !tomlConfig.claudeCode) {
|
|
462
|
-
return this.migrateFromLegacyConfig();
|
|
463
|
-
}
|
|
464
|
-
const { claudeCode } = tomlConfig;
|
|
465
|
-
const rawProfiles = claudeCode.profiles || {};
|
|
466
|
-
const sanitizedProfiles = Object.fromEntries(
|
|
467
|
-
Object.entries(rawProfiles).map(([key, profile]) => {
|
|
468
|
-
const storedProfile = this.sanitizeProfile({
|
|
469
|
-
...profile,
|
|
470
|
-
name: profile.name || key
|
|
471
|
-
});
|
|
472
|
-
return [key, { ...storedProfile, id: key }];
|
|
473
|
-
})
|
|
474
|
-
);
|
|
475
|
-
const configData = {
|
|
476
|
-
currentProfileId: claudeCode.currentProfile || "",
|
|
477
|
-
profiles: sanitizedProfiles
|
|
478
|
-
};
|
|
479
|
-
if (Object.keys(configData.profiles).length === 0) {
|
|
480
|
-
const migrated = this.migrateFromLegacyConfig();
|
|
481
|
-
if (migrated) {
|
|
482
|
-
return migrated;
|
|
483
|
-
}
|
|
484
|
-
}
|
|
485
|
-
return configData;
|
|
486
|
-
} catch (error) {
|
|
487
|
-
console.error("Failed to read Claude Code config:", error);
|
|
488
|
-
return null;
|
|
489
|
-
}
|
|
490
|
-
}
|
|
491
|
-
/**
|
|
492
|
-
* Write configuration
|
|
493
|
-
*/
|
|
494
|
-
static writeConfig(config) {
|
|
495
|
-
try {
|
|
496
|
-
this.ensureConfigDir();
|
|
497
|
-
const keyMap = /* @__PURE__ */ new Map();
|
|
498
|
-
const sanitizedProfiles = Object.fromEntries(
|
|
499
|
-
Object.entries(config.profiles).map(([key, profile]) => {
|
|
500
|
-
const normalizedName = profile.name?.trim() || key;
|
|
501
|
-
const profileKey = this.generateProfileId(normalizedName);
|
|
502
|
-
keyMap.set(key, profileKey);
|
|
503
|
-
const sanitizedProfile = this.sanitizeProfile({
|
|
504
|
-
...profile,
|
|
505
|
-
name: normalizedName
|
|
506
|
-
});
|
|
507
|
-
return [profileKey, sanitizedProfile];
|
|
508
|
-
})
|
|
509
|
-
);
|
|
510
|
-
const tomlConfig = this.loadTomlConfig();
|
|
511
|
-
const nextTomlConfig = {
|
|
512
|
-
...tomlConfig,
|
|
513
|
-
claudeCode: {
|
|
514
|
-
...tomlConfig.claudeCode,
|
|
515
|
-
currentProfile: keyMap.get(config.currentProfileId) || config.currentProfileId,
|
|
516
|
-
profiles: sanitizedProfiles
|
|
517
|
-
}
|
|
518
|
-
};
|
|
519
|
-
writeTomlConfig(this.CONFIG_FILE, nextTomlConfig);
|
|
520
|
-
} catch (error) {
|
|
521
|
-
console.error("Failed to write Claude Code config:", error);
|
|
522
|
-
throw new Error(`Failed to write config: ${error instanceof Error ? error.message : String(error)}`);
|
|
523
|
-
}
|
|
524
|
-
}
|
|
525
|
-
/**
|
|
526
|
-
* Create empty configuration
|
|
527
|
-
*/
|
|
528
|
-
static createEmptyConfig() {
|
|
529
|
-
return {
|
|
530
|
-
currentProfileId: "",
|
|
531
|
-
profiles: {}
|
|
532
|
-
};
|
|
533
|
-
}
|
|
534
|
-
static settingsMatchProfile(settings, profile) {
|
|
535
|
-
const env = settings?.env || {};
|
|
536
|
-
if (!profile) {
|
|
537
|
-
return !settings?.model && !env.ANTHROPIC_MODEL && !env.ANTHROPIC_DEFAULT_HAIKU_MODEL && !env.ANTHROPIC_DEFAULT_SONNET_MODEL && !env.ANTHROPIC_DEFAULT_OPUS_MODEL;
|
|
538
|
-
}
|
|
539
|
-
const expectedPrimary = profile.primaryModel?.trim();
|
|
540
|
-
const expectedHaiku = profile.defaultHaikuModel?.trim();
|
|
541
|
-
const expectedSonnet = profile.defaultSonnetModel?.trim();
|
|
542
|
-
const expectedOpus = profile.defaultOpusModel?.trim();
|
|
543
|
-
const hasExplicitModelConfig = Boolean(expectedPrimary || expectedHaiku || expectedSonnet || expectedOpus);
|
|
544
|
-
if (!hasExplicitModelConfig) {
|
|
545
|
-
return !settings?.model && (env.ANTHROPIC_MODEL === "" || env.ANTHROPIC_MODEL === void 0) && env.ANTHROPIC_DEFAULT_HAIKU_MODEL === void 0 && env.ANTHROPIC_DEFAULT_SONNET_MODEL === void 0 && env.ANTHROPIC_DEFAULT_OPUS_MODEL === void 0;
|
|
546
|
-
}
|
|
547
|
-
const hasAdaptiveRouting = Boolean(expectedHaiku || expectedSonnet || expectedOpus);
|
|
548
|
-
if (hasAdaptiveRouting) {
|
|
549
|
-
return !settings?.model && env.ANTHROPIC_MODEL === void 0 && env.ANTHROPIC_DEFAULT_HAIKU_MODEL === expectedHaiku && env.ANTHROPIC_SMALL_FAST_MODEL === expectedHaiku && env.ANTHROPIC_DEFAULT_SONNET_MODEL === expectedSonnet && env.ANTHROPIC_DEFAULT_OPUS_MODEL === expectedOpus;
|
|
550
|
-
}
|
|
551
|
-
return settings?.model === expectedPrimary && env.ANTHROPIC_MODEL === void 0 && env.ANTHROPIC_DEFAULT_HAIKU_MODEL === expectedHaiku && env.ANTHROPIC_SMALL_FAST_MODEL === expectedHaiku && env.ANTHROPIC_DEFAULT_SONNET_MODEL === expectedSonnet && env.ANTHROPIC_DEFAULT_OPUS_MODEL === expectedOpus;
|
|
552
|
-
}
|
|
553
|
-
static async syncCurrentProfileToSettings() {
|
|
554
|
-
const currentProfile = this.getCurrentProfile();
|
|
555
|
-
await this.applyProfileSettings(currentProfile);
|
|
556
|
-
}
|
|
557
|
-
/**
|
|
558
|
-
* Apply profile settings to Claude Code runtime
|
|
559
|
-
*/
|
|
560
|
-
static async applyProfileSettings(profile) {
|
|
561
|
-
const { ensureI18nInitialized, i18n } = await import('./index2.mjs');
|
|
562
|
-
ensureI18nInitialized();
|
|
563
|
-
const target = resolveClaudeFamilySettingsTarget();
|
|
564
|
-
try {
|
|
565
|
-
if (!profile) {
|
|
566
|
-
const { switchToOfficialLogin } = await Promise.resolve().then(function () { return config; });
|
|
567
|
-
switchToOfficialLogin(target.codeTool);
|
|
568
|
-
return;
|
|
569
|
-
}
|
|
570
|
-
const { readJsonConfig: readJsonConfig2, writeJsonConfig } = await import('./json-config.mjs');
|
|
571
|
-
const settings = readJsonConfig2(target.settingsFile) || {};
|
|
572
|
-
clearLegacyTopLevelRuntimeSettings(settings);
|
|
573
|
-
if (!settings.env)
|
|
574
|
-
settings.env = {};
|
|
575
|
-
let shouldRestartCcr = false;
|
|
576
|
-
if (profile.authType === "api_key") {
|
|
577
|
-
settings.env.ANTHROPIC_API_KEY = profile.apiKey;
|
|
578
|
-
delete settings.env.ANTHROPIC_AUTH_TOKEN;
|
|
579
|
-
} else if (profile.authType === "auth_token") {
|
|
580
|
-
settings.env.ANTHROPIC_AUTH_TOKEN = profile.apiKey;
|
|
581
|
-
delete settings.env.ANTHROPIC_API_KEY;
|
|
582
|
-
} else if (profile.authType === "ccr_proxy") {
|
|
583
|
-
const { readCcrConfig } = await import('./config2.mjs');
|
|
584
|
-
const ccrConfig = readCcrConfig();
|
|
585
|
-
if (!ccrConfig) {
|
|
586
|
-
throw new Error(i18n.t("ccr:ccrNotConfigured") || "CCR proxy configuration not found");
|
|
587
|
-
}
|
|
588
|
-
const host = ccrConfig.HOST || "127.0.0.1";
|
|
589
|
-
const port = ccrConfig.PORT || 3456;
|
|
590
|
-
const apiKey = ccrConfig.APIKEY || "sk-ccjk-x-ccr";
|
|
591
|
-
settings.env.ANTHROPIC_BASE_URL = `http://${host}:${port}`;
|
|
592
|
-
settings.env.ANTHROPIC_API_KEY = apiKey;
|
|
593
|
-
delete settings.env.ANTHROPIC_AUTH_TOKEN;
|
|
594
|
-
shouldRestartCcr = true;
|
|
595
|
-
}
|
|
596
|
-
if (profile.authType !== "ccr_proxy") {
|
|
597
|
-
if (profile.baseUrl)
|
|
598
|
-
settings.env.ANTHROPIC_BASE_URL = profile.baseUrl;
|
|
599
|
-
else
|
|
600
|
-
delete settings.env.ANTHROPIC_BASE_URL;
|
|
601
|
-
}
|
|
602
|
-
const hasModelConfig = Boolean(
|
|
603
|
-
profile.primaryModel || profile.defaultHaikuModel || profile.defaultSonnetModel || profile.defaultOpusModel
|
|
604
|
-
);
|
|
605
|
-
const modelMode = hasModelConfig ? "override" : "reset";
|
|
606
|
-
overwriteModelSettings(settings, {
|
|
607
|
-
primaryModel: profile.primaryModel,
|
|
608
|
-
haikuModel: profile.defaultHaikuModel,
|
|
609
|
-
sonnetModel: profile.defaultSonnetModel,
|
|
610
|
-
opusModel: profile.defaultOpusModel
|
|
611
|
-
}, modelMode);
|
|
612
|
-
normalizeClaudeFamilySettings(settings);
|
|
613
|
-
writeJsonConfig(target.settingsFile, settings);
|
|
614
|
-
const { setPrimaryApiKey, addCompletedOnboarding } = await Promise.resolve().then(function () { return claudeConfig; });
|
|
615
|
-
setPrimaryApiKey(target.codeTool);
|
|
616
|
-
addCompletedOnboarding(target.codeTool);
|
|
617
|
-
let verifiedSettings = readJsonConfig2(target.settingsFile) || {};
|
|
618
|
-
if (!this.settingsMatchProfile(verifiedSettings, profile)) {
|
|
619
|
-
const repairedSettings = readJsonConfig2(target.settingsFile) || {};
|
|
620
|
-
clearLegacyTopLevelRuntimeSettings(repairedSettings);
|
|
621
|
-
repairedSettings.env = repairedSettings.env || {};
|
|
622
|
-
if (profile?.authType === "api_key") {
|
|
623
|
-
repairedSettings.env.ANTHROPIC_API_KEY = profile.apiKey;
|
|
624
|
-
delete repairedSettings.env.ANTHROPIC_AUTH_TOKEN;
|
|
625
|
-
} else if (profile?.authType === "auth_token") {
|
|
626
|
-
repairedSettings.env.ANTHROPIC_AUTH_TOKEN = profile.apiKey;
|
|
627
|
-
delete repairedSettings.env.ANTHROPIC_API_KEY;
|
|
628
|
-
}
|
|
629
|
-
if (profile?.authType !== "ccr_proxy") {
|
|
630
|
-
if (profile?.baseUrl)
|
|
631
|
-
repairedSettings.env.ANTHROPIC_BASE_URL = profile.baseUrl;
|
|
632
|
-
else
|
|
633
|
-
delete repairedSettings.env.ANTHROPIC_BASE_URL;
|
|
634
|
-
}
|
|
635
|
-
overwriteModelSettings(repairedSettings, {
|
|
636
|
-
primaryModel: profile?.primaryModel,
|
|
637
|
-
haikuModel: profile?.defaultHaikuModel,
|
|
638
|
-
sonnetModel: profile?.defaultSonnetModel,
|
|
639
|
-
opusModel: profile?.defaultOpusModel
|
|
640
|
-
}, profile ? modelMode : "reset");
|
|
641
|
-
normalizeClaudeFamilySettings(repairedSettings);
|
|
642
|
-
writeJsonConfig(target.settingsFile, repairedSettings);
|
|
643
|
-
verifiedSettings = readJsonConfig2(target.settingsFile) || {};
|
|
644
|
-
}
|
|
645
|
-
if (!this.settingsMatchProfile(verifiedSettings, profile)) {
|
|
646
|
-
throw new Error("settings.json verification failed after applying current profile");
|
|
647
|
-
}
|
|
648
|
-
if (shouldRestartCcr) {
|
|
649
|
-
const { runCcrRestart } = await import('./commands.mjs');
|
|
650
|
-
await runCcrRestart();
|
|
651
|
-
}
|
|
652
|
-
} catch (error) {
|
|
653
|
-
const reason = error instanceof Error ? error.message : String(error);
|
|
654
|
-
throw new Error(`${i18n.t("multi-config:failedToApplySettings")}: ${reason}`);
|
|
655
|
-
}
|
|
656
|
-
}
|
|
657
|
-
static async applyCurrentProfile() {
|
|
658
|
-
await this.syncCurrentProfileToSettings();
|
|
659
|
-
}
|
|
660
|
-
/**
|
|
661
|
-
* Remove unsupported fields from profile payload
|
|
662
|
-
*/
|
|
663
|
-
static sanitizeProfile(profile) {
|
|
664
|
-
const sanitized = {
|
|
665
|
-
name: profile.name,
|
|
666
|
-
authType: profile.authType
|
|
667
|
-
};
|
|
668
|
-
if (profile.provider)
|
|
669
|
-
sanitized.provider = profile.provider;
|
|
670
|
-
if (profile.apiKey)
|
|
671
|
-
sanitized.apiKey = profile.apiKey;
|
|
672
|
-
if (profile.baseUrl)
|
|
673
|
-
sanitized.baseUrl = profile.baseUrl;
|
|
674
|
-
if (profile.primaryModel)
|
|
675
|
-
sanitized.primaryModel = profile.primaryModel;
|
|
676
|
-
if (profile.defaultHaikuModel)
|
|
677
|
-
sanitized.defaultHaikuModel = profile.defaultHaikuModel;
|
|
678
|
-
if (profile.defaultSonnetModel)
|
|
679
|
-
sanitized.defaultSonnetModel = profile.defaultSonnetModel;
|
|
680
|
-
if (profile.defaultOpusModel)
|
|
681
|
-
sanitized.defaultOpusModel = profile.defaultOpusModel;
|
|
682
|
-
return sanitized;
|
|
683
|
-
}
|
|
684
|
-
/**
|
|
685
|
-
* Backup configuration
|
|
686
|
-
*/
|
|
687
|
-
static backupConfig() {
|
|
688
|
-
try {
|
|
689
|
-
if (!exists(this.CONFIG_FILE)) {
|
|
690
|
-
return null;
|
|
691
|
-
}
|
|
692
|
-
const timestamp = dayjs().format("YYYY-MM-DD_HH-mm-ss");
|
|
693
|
-
const backupPath = join(ZCF_CONFIG_DIR, `config.backup.${timestamp}.toml`);
|
|
694
|
-
copyFile(this.CONFIG_FILE, backupPath);
|
|
695
|
-
return backupPath;
|
|
696
|
-
} catch (error) {
|
|
697
|
-
console.error("Failed to backup Claude Code config:", error);
|
|
698
|
-
return null;
|
|
699
|
-
}
|
|
700
|
-
}
|
|
701
|
-
/**
|
|
702
|
-
* Add configuration
|
|
703
|
-
*/
|
|
704
|
-
static async addProfile(profile) {
|
|
705
|
-
try {
|
|
706
|
-
const validationErrors = this.validateProfile(profile);
|
|
707
|
-
if (validationErrors.length > 0) {
|
|
708
|
-
return {
|
|
709
|
-
success: false,
|
|
710
|
-
error: `Validation failed: ${validationErrors.join(", ")}`
|
|
711
|
-
};
|
|
712
|
-
}
|
|
713
|
-
const backupPath = this.backupConfig();
|
|
714
|
-
let config = this.readConfig();
|
|
715
|
-
if (!config) {
|
|
716
|
-
config = this.createEmptyConfig();
|
|
717
|
-
}
|
|
718
|
-
if (profile.id && config.profiles[profile.id]) {
|
|
719
|
-
return {
|
|
720
|
-
success: false,
|
|
721
|
-
error: `Profile with ID "${profile.id}" already exists`,
|
|
722
|
-
backupPath: backupPath || void 0
|
|
723
|
-
};
|
|
724
|
-
}
|
|
725
|
-
const normalizedName = profile.name.trim();
|
|
726
|
-
const profileKey = this.generateProfileId(normalizedName);
|
|
727
|
-
const existingNames = Object.values(config.profiles).map((p) => p.name || "");
|
|
728
|
-
if (config.profiles[profileKey] || existingNames.some((name) => name.toLowerCase() === normalizedName.toLowerCase())) {
|
|
729
|
-
return {
|
|
730
|
-
success: false,
|
|
731
|
-
error: `Profile with name "${profile.name}" already exists`,
|
|
732
|
-
backupPath: backupPath || void 0
|
|
733
|
-
};
|
|
734
|
-
}
|
|
735
|
-
const sanitizedProfile = this.sanitizeProfile({
|
|
736
|
-
...profile,
|
|
737
|
-
name: normalizedName
|
|
738
|
-
});
|
|
739
|
-
const runtimeProfile = {
|
|
740
|
-
...sanitizedProfile,
|
|
741
|
-
id: profileKey
|
|
742
|
-
};
|
|
743
|
-
config.profiles[profileKey] = runtimeProfile;
|
|
744
|
-
if (!config.currentProfileId) {
|
|
745
|
-
config.currentProfileId = profileKey;
|
|
746
|
-
}
|
|
747
|
-
this.writeConfig(config);
|
|
748
|
-
if (config.currentProfileId === profileKey) {
|
|
749
|
-
await this.syncCurrentProfileToSettings();
|
|
750
|
-
}
|
|
751
|
-
return {
|
|
752
|
-
success: true,
|
|
753
|
-
backupPath: backupPath || void 0,
|
|
754
|
-
addedProfile: runtimeProfile
|
|
755
|
-
};
|
|
756
|
-
} catch (error) {
|
|
757
|
-
return {
|
|
758
|
-
success: false,
|
|
759
|
-
error: error instanceof Error ? error.message : String(error)
|
|
760
|
-
};
|
|
761
|
-
}
|
|
762
|
-
}
|
|
763
|
-
/**
|
|
764
|
-
* Update configuration
|
|
765
|
-
*/
|
|
766
|
-
static async updateProfile(id, data) {
|
|
767
|
-
try {
|
|
768
|
-
const validationErrors = this.validateProfile(data, true);
|
|
769
|
-
if (validationErrors.length > 0) {
|
|
770
|
-
return {
|
|
771
|
-
success: false,
|
|
772
|
-
error: `Validation failed: ${validationErrors.join(", ")}`
|
|
773
|
-
};
|
|
774
|
-
}
|
|
775
|
-
const backupPath = this.backupConfig();
|
|
776
|
-
const config = this.readConfig();
|
|
777
|
-
if (!config || !config.profiles[id]) {
|
|
778
|
-
return {
|
|
779
|
-
success: false,
|
|
780
|
-
error: `Profile with ID "${id}" not found`,
|
|
781
|
-
backupPath: backupPath || void 0
|
|
782
|
-
};
|
|
783
|
-
}
|
|
784
|
-
const existingProfile = config.profiles[id];
|
|
785
|
-
const nextName = data.name !== void 0 ? data.name.trim() : existingProfile.name;
|
|
786
|
-
const nextKey = this.generateProfileId(nextName);
|
|
787
|
-
const nameChanged = nextKey !== id;
|
|
788
|
-
if (nameChanged) {
|
|
789
|
-
const duplicateName = Object.entries(config.profiles).some(([key, profile]) => key !== id && (profile.name || "").toLowerCase() === nextName.toLowerCase());
|
|
790
|
-
if (duplicateName || config.profiles[nextKey]) {
|
|
791
|
-
return {
|
|
792
|
-
success: false,
|
|
793
|
-
error: `Profile with name "${data.name}" already exists`,
|
|
794
|
-
backupPath: backupPath || void 0
|
|
795
|
-
};
|
|
796
|
-
}
|
|
797
|
-
}
|
|
798
|
-
const mergedProfile = this.sanitizeProfile({
|
|
799
|
-
...existingProfile,
|
|
800
|
-
...data,
|
|
801
|
-
name: nextName
|
|
802
|
-
});
|
|
803
|
-
if (nameChanged) {
|
|
804
|
-
delete config.profiles[id];
|
|
805
|
-
config.profiles[nextKey] = {
|
|
806
|
-
...mergedProfile,
|
|
807
|
-
id: nextKey
|
|
808
|
-
};
|
|
809
|
-
if (config.currentProfileId === id) {
|
|
810
|
-
config.currentProfileId = nextKey;
|
|
811
|
-
}
|
|
812
|
-
} else {
|
|
813
|
-
config.profiles[id] = {
|
|
814
|
-
...mergedProfile,
|
|
815
|
-
id
|
|
816
|
-
};
|
|
817
|
-
}
|
|
818
|
-
this.writeConfig(config);
|
|
819
|
-
if (config.currentProfileId === (nameChanged ? nextKey : id)) {
|
|
820
|
-
await this.syncCurrentProfileToSettings();
|
|
821
|
-
}
|
|
822
|
-
return {
|
|
823
|
-
success: true,
|
|
824
|
-
backupPath: backupPath || void 0,
|
|
825
|
-
updatedProfile: {
|
|
826
|
-
...mergedProfile,
|
|
827
|
-
id: nameChanged ? nextKey : id
|
|
828
|
-
}
|
|
829
|
-
};
|
|
830
|
-
} catch (error) {
|
|
831
|
-
return {
|
|
832
|
-
success: false,
|
|
833
|
-
error: error instanceof Error ? error.message : String(error)
|
|
834
|
-
};
|
|
835
|
-
}
|
|
836
|
-
}
|
|
837
|
-
/**
|
|
838
|
-
* Delete configuration
|
|
839
|
-
*/
|
|
840
|
-
static async deleteProfile(id) {
|
|
841
|
-
try {
|
|
842
|
-
const backupPath = this.backupConfig();
|
|
843
|
-
const config = this.readConfig();
|
|
844
|
-
if (!config || !config.profiles[id]) {
|
|
845
|
-
return {
|
|
846
|
-
success: false,
|
|
847
|
-
error: `Profile with ID "${id}" not found`,
|
|
848
|
-
backupPath: backupPath || void 0
|
|
849
|
-
};
|
|
850
|
-
}
|
|
851
|
-
const profileCount = Object.keys(config.profiles).length;
|
|
852
|
-
if (profileCount === 1) {
|
|
853
|
-
return {
|
|
854
|
-
success: false,
|
|
855
|
-
error: "Cannot delete the last profile. At least one profile must remain.",
|
|
856
|
-
backupPath: backupPath || void 0
|
|
857
|
-
};
|
|
858
|
-
}
|
|
859
|
-
delete config.profiles[id];
|
|
860
|
-
if (config.currentProfileId === id) {
|
|
861
|
-
const remainingIds = Object.keys(config.profiles);
|
|
862
|
-
config.currentProfileId = remainingIds[0];
|
|
863
|
-
}
|
|
864
|
-
this.writeConfig(config);
|
|
865
|
-
if (config.currentProfileId) {
|
|
866
|
-
await this.syncCurrentProfileToSettings();
|
|
867
|
-
}
|
|
868
|
-
return {
|
|
869
|
-
success: true,
|
|
870
|
-
backupPath: backupPath || void 0,
|
|
871
|
-
remainingProfiles: Object.entries(config.profiles).map(([key, profile]) => ({
|
|
872
|
-
...profile,
|
|
873
|
-
id: key
|
|
874
|
-
}))
|
|
875
|
-
};
|
|
876
|
-
} catch (error) {
|
|
877
|
-
return {
|
|
878
|
-
success: false,
|
|
879
|
-
error: error instanceof Error ? error.message : String(error)
|
|
880
|
-
};
|
|
881
|
-
}
|
|
882
|
-
}
|
|
883
|
-
/**
|
|
884
|
-
* Delete multiple configurations
|
|
885
|
-
*/
|
|
886
|
-
static async deleteProfiles(ids) {
|
|
887
|
-
try {
|
|
888
|
-
const backupPath = this.backupConfig();
|
|
889
|
-
const config = this.readConfig();
|
|
890
|
-
if (!config) {
|
|
891
|
-
return {
|
|
892
|
-
success: false,
|
|
893
|
-
error: "No configuration found",
|
|
894
|
-
backupPath: backupPath || void 0
|
|
895
|
-
};
|
|
896
|
-
}
|
|
897
|
-
const missingIds = ids.filter((id) => !config.profiles[id]);
|
|
898
|
-
if (missingIds.length > 0) {
|
|
899
|
-
return {
|
|
900
|
-
success: false,
|
|
901
|
-
error: `Profiles not found: ${missingIds.join(", ")}`,
|
|
902
|
-
backupPath: backupPath || void 0
|
|
903
|
-
};
|
|
904
|
-
}
|
|
905
|
-
const remainingCount = Object.keys(config.profiles).length - ids.length;
|
|
906
|
-
if (remainingCount === 0) {
|
|
907
|
-
return {
|
|
908
|
-
success: false,
|
|
909
|
-
error: "Cannot delete all profiles. At least one profile must remain.",
|
|
910
|
-
backupPath: backupPath || void 0
|
|
911
|
-
};
|
|
912
|
-
}
|
|
913
|
-
let newCurrentProfileId;
|
|
914
|
-
ids.forEach((id) => {
|
|
915
|
-
delete config.profiles[id];
|
|
916
|
-
});
|
|
917
|
-
if (ids.includes(config.currentProfileId)) {
|
|
918
|
-
const remainingIds = Object.keys(config.profiles);
|
|
919
|
-
config.currentProfileId = remainingIds[0];
|
|
920
|
-
newCurrentProfileId = config.currentProfileId;
|
|
921
|
-
}
|
|
922
|
-
this.writeConfig(config);
|
|
923
|
-
if (config.currentProfileId) {
|
|
924
|
-
await this.syncCurrentProfileToSettings();
|
|
925
|
-
}
|
|
926
|
-
return {
|
|
927
|
-
success: true,
|
|
928
|
-
backupPath: backupPath || void 0,
|
|
929
|
-
newCurrentProfileId,
|
|
930
|
-
deletedProfiles: ids,
|
|
931
|
-
remainingProfiles: Object.entries(config.profiles).map(([key, profile]) => ({
|
|
932
|
-
...profile,
|
|
933
|
-
id: key
|
|
934
|
-
}))
|
|
935
|
-
};
|
|
936
|
-
} catch (error) {
|
|
937
|
-
return {
|
|
938
|
-
success: false,
|
|
939
|
-
error: error instanceof Error ? error.message : String(error)
|
|
940
|
-
};
|
|
941
|
-
}
|
|
942
|
-
}
|
|
943
|
-
/**
|
|
944
|
-
* Generate profile ID from name
|
|
945
|
-
*/
|
|
946
|
-
static generateProfileId(name) {
|
|
947
|
-
return name.trim().toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "") || "profile";
|
|
948
|
-
}
|
|
949
|
-
/**
|
|
950
|
-
* Switch configuration
|
|
951
|
-
*/
|
|
952
|
-
static async switchProfile(id) {
|
|
953
|
-
try {
|
|
954
|
-
const config = this.readConfig();
|
|
955
|
-
if (!config || !config.profiles[id]) {
|
|
956
|
-
return {
|
|
957
|
-
success: false,
|
|
958
|
-
error: "Profile not found"
|
|
959
|
-
};
|
|
960
|
-
}
|
|
961
|
-
if (config.currentProfileId === id) {
|
|
962
|
-
return { success: true };
|
|
963
|
-
}
|
|
964
|
-
config.currentProfileId = id;
|
|
965
|
-
this.writeConfig(config);
|
|
966
|
-
await this.syncCurrentProfileToSettings();
|
|
967
|
-
return { success: true };
|
|
968
|
-
} catch (error) {
|
|
969
|
-
return {
|
|
970
|
-
success: false,
|
|
971
|
-
error: error instanceof Error ? error.message : String(error)
|
|
972
|
-
};
|
|
973
|
-
}
|
|
974
|
-
}
|
|
975
|
-
/**
|
|
976
|
-
* List all configurations
|
|
977
|
-
*/
|
|
978
|
-
static listProfiles() {
|
|
979
|
-
const config = this.readConfig();
|
|
980
|
-
if (!config) {
|
|
981
|
-
return [];
|
|
982
|
-
}
|
|
983
|
-
return Object.values(config.profiles);
|
|
984
|
-
}
|
|
985
|
-
/**
|
|
986
|
-
* Get current configuration
|
|
987
|
-
*/
|
|
988
|
-
static getCurrentProfile() {
|
|
989
|
-
const config = this.readConfig();
|
|
990
|
-
if (!config || !config.currentProfileId) {
|
|
991
|
-
return null;
|
|
992
|
-
}
|
|
993
|
-
return config.profiles[config.currentProfileId] || null;
|
|
994
|
-
}
|
|
995
|
-
/**
|
|
996
|
-
* Get configuration by ID
|
|
997
|
-
*/
|
|
998
|
-
static getProfileById(id) {
|
|
999
|
-
const config = this.readConfig();
|
|
1000
|
-
if (!config) {
|
|
1001
|
-
return null;
|
|
1002
|
-
}
|
|
1003
|
-
return config.profiles[id] || null;
|
|
1004
|
-
}
|
|
1005
|
-
/**
|
|
1006
|
-
* Get configuration by name
|
|
1007
|
-
*/
|
|
1008
|
-
static getProfileByName(name) {
|
|
1009
|
-
const config = this.readConfig();
|
|
1010
|
-
if (!config) {
|
|
1011
|
-
return null;
|
|
1012
|
-
}
|
|
1013
|
-
return Object.values(config.profiles).find((p) => p.name === name) || null;
|
|
1014
|
-
}
|
|
1015
|
-
/**
|
|
1016
|
-
* Sync CCR configuration
|
|
1017
|
-
*/
|
|
1018
|
-
static async syncCcrProfile() {
|
|
1019
|
-
try {
|
|
1020
|
-
const { readCcrConfig } = await import('./config2.mjs');
|
|
1021
|
-
const ccrConfig = readCcrConfig();
|
|
1022
|
-
if (!ccrConfig) {
|
|
1023
|
-
await this.ensureCcrProfileExists(ccrConfig);
|
|
1024
|
-
return;
|
|
1025
|
-
}
|
|
1026
|
-
await this.ensureCcrProfileExists(ccrConfig);
|
|
1027
|
-
} catch (error) {
|
|
1028
|
-
console.error("Failed to sync CCR profile:", error);
|
|
1029
|
-
}
|
|
1030
|
-
}
|
|
1031
|
-
/**
|
|
1032
|
-
* 确保CCR配置文件存在
|
|
1033
|
-
*/
|
|
1034
|
-
static async ensureCcrProfileExists(ccrConfig) {
|
|
1035
|
-
const config = this.readConfig() || this.createEmptyConfig();
|
|
1036
|
-
const ccrProfileId = "ccr-proxy";
|
|
1037
|
-
const existingCcrProfile = config.profiles[ccrProfileId];
|
|
1038
|
-
if (!ccrConfig) {
|
|
1039
|
-
if (existingCcrProfile) {
|
|
1040
|
-
delete config.profiles[ccrProfileId];
|
|
1041
|
-
if (config.currentProfileId === ccrProfileId) {
|
|
1042
|
-
const remainingIds = Object.keys(config.profiles);
|
|
1043
|
-
config.currentProfileId = remainingIds[0] || "";
|
|
1044
|
-
}
|
|
1045
|
-
this.writeConfig(config);
|
|
1046
|
-
}
|
|
1047
|
-
return;
|
|
1048
|
-
}
|
|
1049
|
-
const host = ccrConfig.HOST || "127.0.0.1";
|
|
1050
|
-
const port = ccrConfig.PORT || 3456;
|
|
1051
|
-
const apiKey = ccrConfig.APIKEY || "sk-ccjk-x-ccr";
|
|
1052
|
-
const baseUrl = `http://${host}:${port}`;
|
|
1053
|
-
const ccrProfile = {
|
|
1054
|
-
name: "CCR Proxy",
|
|
1055
|
-
authType: "ccr_proxy",
|
|
1056
|
-
baseUrl,
|
|
1057
|
-
apiKey
|
|
1058
|
-
};
|
|
1059
|
-
config.profiles[ccrProfileId] = {
|
|
1060
|
-
...ccrProfile,
|
|
1061
|
-
id: ccrProfileId
|
|
1062
|
-
};
|
|
1063
|
-
if (!config.currentProfileId) {
|
|
1064
|
-
config.currentProfileId = ccrProfileId;
|
|
1065
|
-
}
|
|
1066
|
-
this.writeConfig(config);
|
|
1067
|
-
}
|
|
1068
|
-
/**
|
|
1069
|
-
* Switch to official login
|
|
1070
|
-
*/
|
|
1071
|
-
static async switchToOfficial() {
|
|
1072
|
-
try {
|
|
1073
|
-
const config = this.readConfig();
|
|
1074
|
-
if (!config) {
|
|
1075
|
-
return { success: true };
|
|
1076
|
-
}
|
|
1077
|
-
config.currentProfileId = "";
|
|
1078
|
-
this.writeConfig(config);
|
|
1079
|
-
await this.applyProfileSettings(null);
|
|
1080
|
-
return { success: true };
|
|
1081
|
-
} catch (error) {
|
|
1082
|
-
return {
|
|
1083
|
-
success: false,
|
|
1084
|
-
error: error instanceof Error ? error.message : String(error)
|
|
1085
|
-
};
|
|
1086
|
-
}
|
|
1087
|
-
}
|
|
1088
|
-
/**
|
|
1089
|
-
* Switch to CCR proxy
|
|
1090
|
-
*/
|
|
1091
|
-
static async switchToCcr() {
|
|
1092
|
-
try {
|
|
1093
|
-
await this.syncCcrProfile();
|
|
1094
|
-
const config = this.readConfig();
|
|
1095
|
-
if (!config || !config.profiles["ccr-proxy"]) {
|
|
1096
|
-
return {
|
|
1097
|
-
success: false,
|
|
1098
|
-
error: "CCR proxy configuration not found. Please configure CCR first."
|
|
1099
|
-
};
|
|
1100
|
-
}
|
|
1101
|
-
return await this.switchProfile("ccr-proxy");
|
|
1102
|
-
} catch (error) {
|
|
1103
|
-
return {
|
|
1104
|
-
success: false,
|
|
1105
|
-
error: error instanceof Error ? error.message : String(error)
|
|
1106
|
-
};
|
|
1107
|
-
}
|
|
1108
|
-
}
|
|
1109
|
-
/**
|
|
1110
|
-
* Validate configuration
|
|
1111
|
-
*/
|
|
1112
|
-
static validateProfile(profile, isUpdate = false) {
|
|
1113
|
-
const errors = [];
|
|
1114
|
-
if (!isUpdate && (!profile.name || typeof profile.name !== "string" || profile.name.trim() === "")) {
|
|
1115
|
-
errors.push("Profile name is required");
|
|
1116
|
-
}
|
|
1117
|
-
if (profile.name && typeof profile.name !== "string") {
|
|
1118
|
-
errors.push("Profile name must be a string");
|
|
1119
|
-
}
|
|
1120
|
-
if (profile.authType && !["api_key", "auth_token", "ccr_proxy"].includes(profile.authType)) {
|
|
1121
|
-
errors.push("Invalid auth type. Must be one of: api_key, auth_token, ccr_proxy");
|
|
1122
|
-
}
|
|
1123
|
-
if (profile.authType === "api_key" || profile.authType === "auth_token") {
|
|
1124
|
-
if (!profile.apiKey || typeof profile.apiKey !== "string" || profile.apiKey.trim() === "") {
|
|
1125
|
-
errors.push("API key is required for api_key and auth_token types");
|
|
1126
|
-
}
|
|
1127
|
-
}
|
|
1128
|
-
if (profile.baseUrl) {
|
|
1129
|
-
try {
|
|
1130
|
-
new URL(profile.baseUrl);
|
|
1131
|
-
} catch {
|
|
1132
|
-
errors.push("Invalid base URL format");
|
|
1133
|
-
}
|
|
1134
|
-
}
|
|
1135
|
-
return errors;
|
|
1136
|
-
}
|
|
1137
|
-
/**
|
|
1138
|
-
* 检查是否为最后一个配置
|
|
1139
|
-
*/
|
|
1140
|
-
static isLastProfile(id) {
|
|
1141
|
-
const config = this.readConfig();
|
|
1142
|
-
if (!config || !config.profiles[id]) {
|
|
1143
|
-
return false;
|
|
1144
|
-
}
|
|
1145
|
-
return Object.keys(config.profiles).length === 1;
|
|
1146
|
-
}
|
|
1147
|
-
}
|
|
1148
|
-
|
|
1149
|
-
const claudeCodeConfigManager = {
|
|
1150
|
-
__proto__: null,
|
|
1151
|
-
ClaudeCodeConfigManager: ClaudeCodeConfigManager
|
|
1152
|
-
};
|
|
1153
|
-
|
|
1154
|
-
function mergeArraysUnique(arr1, arr2) {
|
|
1155
|
-
const combined = [...arr1 || [], ...arr2 || []];
|
|
1156
|
-
return [...new Set(combined)];
|
|
1157
|
-
}
|
|
1158
|
-
function isPlainObject(value) {
|
|
1159
|
-
return value !== null && typeof value === "object" && value.constructor === Object && Object.prototype.toString.call(value) === "[object Object]";
|
|
1160
|
-
}
|
|
1161
|
-
function deepMerge(target, source, options = {}) {
|
|
1162
|
-
const { mergeArrays = false, arrayMergeStrategy = "replace" } = options;
|
|
1163
|
-
const result = { ...target };
|
|
1164
|
-
for (const key in source) {
|
|
1165
|
-
const sourceValue = source[key];
|
|
1166
|
-
const targetValue = result[key];
|
|
1167
|
-
if (sourceValue === void 0) {
|
|
1168
|
-
continue;
|
|
1169
|
-
}
|
|
1170
|
-
if (isPlainObject(sourceValue) && isPlainObject(targetValue)) {
|
|
1171
|
-
result[key] = deepMerge(targetValue, sourceValue, options);
|
|
1172
|
-
} else if (Array.isArray(sourceValue)) {
|
|
1173
|
-
if (!mergeArrays || !Array.isArray(targetValue)) {
|
|
1174
|
-
result[key] = sourceValue;
|
|
1175
|
-
} else {
|
|
1176
|
-
switch (arrayMergeStrategy) {
|
|
1177
|
-
case "concat":
|
|
1178
|
-
result[key] = [...targetValue, ...sourceValue];
|
|
1179
|
-
break;
|
|
1180
|
-
case "unique":
|
|
1181
|
-
result[key] = mergeArraysUnique(targetValue, sourceValue);
|
|
1182
|
-
break;
|
|
1183
|
-
case "replace":
|
|
1184
|
-
default:
|
|
1185
|
-
result[key] = sourceValue;
|
|
1186
|
-
break;
|
|
1187
|
-
}
|
|
1188
|
-
}
|
|
1189
|
-
} else {
|
|
1190
|
-
result[key] = sourceValue;
|
|
1191
|
-
}
|
|
1192
|
-
}
|
|
1193
|
-
return result;
|
|
1194
|
-
}
|
|
1195
|
-
function deepClone(obj) {
|
|
1196
|
-
if (obj === null || typeof obj !== "object") {
|
|
1197
|
-
return obj;
|
|
1198
|
-
}
|
|
1199
|
-
if (obj instanceof Date) {
|
|
1200
|
-
return new Date(obj.getTime());
|
|
1201
|
-
}
|
|
1202
|
-
if (Array.isArray(obj)) {
|
|
1203
|
-
return obj.map((item) => deepClone(item));
|
|
1204
|
-
}
|
|
1205
|
-
if (isPlainObject(obj)) {
|
|
1206
|
-
const cloned = {};
|
|
1207
|
-
for (const key in obj) {
|
|
1208
|
-
cloned[key] = deepClone(obj[key]);
|
|
1209
|
-
}
|
|
1210
|
-
return cloned;
|
|
1211
|
-
}
|
|
1212
|
-
return obj;
|
|
1213
|
-
}
|
|
1214
|
-
|
|
1215
|
-
function readMcpConfig(codeTool) {
|
|
1216
|
-
return readJsonConfig(resolveClaudeFamilySettingsTarget(codeTool).runtimeConfigFile);
|
|
1217
|
-
}
|
|
1218
|
-
function writeMcpConfig(config, codeTool) {
|
|
1219
|
-
writeJsonConfig(resolveClaudeFamilySettingsTarget(codeTool).runtimeConfigFile, config);
|
|
1220
|
-
}
|
|
1221
|
-
function backupMcpConfig(codeTool) {
|
|
1222
|
-
const target = resolveClaudeFamilySettingsTarget(codeTool);
|
|
1223
|
-
const backupBaseDir = join(target.configDir, target.runtimeBackupDirName);
|
|
1224
|
-
return backupJsonConfig(target.runtimeConfigFile, backupBaseDir);
|
|
1225
|
-
}
|
|
1226
|
-
function readClavueConfig() {
|
|
1227
|
-
return readJsonConfig(CLAVUE_CONFIG_FILE);
|
|
1228
|
-
}
|
|
1229
|
-
function writeClavueConfig(config) {
|
|
1230
|
-
writeJsonConfig(CLAVUE_CONFIG_FILE, config);
|
|
1231
|
-
}
|
|
1232
|
-
function mergeMcpServers(existing, newServers) {
|
|
1233
|
-
const config = existing || { mcpServers: {} };
|
|
1234
|
-
if (!config.mcpServers) {
|
|
1235
|
-
config.mcpServers = {};
|
|
1236
|
-
}
|
|
1237
|
-
Object.assign(config.mcpServers, newServers);
|
|
1238
|
-
return config;
|
|
1239
|
-
}
|
|
1240
|
-
function replaceMcpServers(existing, newServers) {
|
|
1241
|
-
const config = existing ? { ...existing } : { mcpServers: {} };
|
|
1242
|
-
config.mcpServers = { ...newServers };
|
|
1243
|
-
return config;
|
|
1244
|
-
}
|
|
1245
|
-
function applyPlatformCommand(config) {
|
|
1246
|
-
if (isWindows() && config.command) {
|
|
1247
|
-
const mcpCmd = getMcpCommand(config.command);
|
|
1248
|
-
if (mcpCmd[0] === "cmd") {
|
|
1249
|
-
config.command = mcpCmd[0];
|
|
1250
|
-
config.args = [...mcpCmd.slice(1), ...config.args || []];
|
|
1251
|
-
}
|
|
1252
|
-
}
|
|
1253
|
-
}
|
|
1254
|
-
function buildMcpServerConfig(baseConfig, apiKey, placeholder = "YOUR_EXA_API_KEY", envVarName) {
|
|
1255
|
-
const config = deepClone(baseConfig);
|
|
1256
|
-
applyPlatformCommand(config);
|
|
1257
|
-
if (!apiKey) {
|
|
1258
|
-
return config;
|
|
1259
|
-
}
|
|
1260
|
-
if (envVarName && config.env) {
|
|
1261
|
-
config.env[envVarName] = apiKey;
|
|
1262
|
-
return config;
|
|
1263
|
-
}
|
|
1264
|
-
if (config.args) {
|
|
1265
|
-
config.args = config.args.map((arg) => arg.replace(placeholder, apiKey));
|
|
1266
|
-
}
|
|
1267
|
-
if (config.url) {
|
|
1268
|
-
config.url = config.url.replace(placeholder, apiKey);
|
|
1269
|
-
}
|
|
1270
|
-
return config;
|
|
1271
|
-
}
|
|
1272
|
-
function fixWindowsMcpConfig(config) {
|
|
1273
|
-
if (!isWindows() || !config.mcpServers) {
|
|
1274
|
-
return config;
|
|
1275
|
-
}
|
|
1276
|
-
const fixed = { ...config };
|
|
1277
|
-
for (const [, serverConfig] of Object.entries(fixed.mcpServers)) {
|
|
1278
|
-
if (serverConfig && typeof serverConfig === "object" && "command" in serverConfig) {
|
|
1279
|
-
applyPlatformCommand(serverConfig);
|
|
1280
|
-
}
|
|
1281
|
-
}
|
|
1282
|
-
return fixed;
|
|
1283
|
-
}
|
|
1284
|
-
function addCompletedOnboarding(codeTool) {
|
|
1285
|
-
try {
|
|
1286
|
-
let config = readMcpConfig(codeTool);
|
|
1287
|
-
if (!config) {
|
|
1288
|
-
config = { mcpServers: {} };
|
|
1289
|
-
}
|
|
1290
|
-
if (config.hasCompletedOnboarding === true) {
|
|
1291
|
-
return;
|
|
1292
|
-
}
|
|
1293
|
-
config.hasCompletedOnboarding = true;
|
|
1294
|
-
writeMcpConfig(config, codeTool);
|
|
1295
|
-
} catch (error) {
|
|
1296
|
-
console.error("Failed to add onboarding flag", error);
|
|
1297
|
-
throw error;
|
|
1298
|
-
}
|
|
1299
|
-
}
|
|
1300
|
-
function ensureApiKeyApproved(config, apiKey) {
|
|
1301
|
-
if (!apiKey || typeof apiKey !== "string" || apiKey.trim() === "") {
|
|
1302
|
-
return config;
|
|
1303
|
-
}
|
|
1304
|
-
const truncatedApiKey = apiKey.substring(0, 20);
|
|
1305
|
-
const updatedConfig = { ...config };
|
|
1306
|
-
if (!updatedConfig.customApiKeyResponses) {
|
|
1307
|
-
updatedConfig.customApiKeyResponses = {
|
|
1308
|
-
approved: [],
|
|
1309
|
-
rejected: []
|
|
1310
|
-
};
|
|
1311
|
-
}
|
|
1312
|
-
if (!Array.isArray(updatedConfig.customApiKeyResponses.approved)) {
|
|
1313
|
-
updatedConfig.customApiKeyResponses.approved = [];
|
|
1314
|
-
}
|
|
1315
|
-
if (!Array.isArray(updatedConfig.customApiKeyResponses.rejected)) {
|
|
1316
|
-
updatedConfig.customApiKeyResponses.rejected = [];
|
|
1317
|
-
}
|
|
1318
|
-
const rejectedIndex = updatedConfig.customApiKeyResponses.rejected.indexOf(truncatedApiKey);
|
|
1319
|
-
if (rejectedIndex > -1) {
|
|
1320
|
-
updatedConfig.customApiKeyResponses.rejected.splice(rejectedIndex, 1);
|
|
1321
|
-
}
|
|
1322
|
-
if (!updatedConfig.customApiKeyResponses.approved.includes(truncatedApiKey)) {
|
|
1323
|
-
updatedConfig.customApiKeyResponses.approved.push(truncatedApiKey);
|
|
1324
|
-
}
|
|
1325
|
-
return updatedConfig;
|
|
1326
|
-
}
|
|
1327
|
-
function manageApiKeyApproval(apiKey, codeTool) {
|
|
1328
|
-
try {
|
|
1329
|
-
let config = readMcpConfig(codeTool);
|
|
1330
|
-
if (!config) {
|
|
1331
|
-
config = { mcpServers: {} };
|
|
1332
|
-
}
|
|
1333
|
-
const updatedConfig = ensureApiKeyApproved(config, apiKey);
|
|
1334
|
-
writeMcpConfig(updatedConfig, codeTool);
|
|
1335
|
-
} catch (error) {
|
|
1336
|
-
ensureI18nInitialized();
|
|
1337
|
-
console.error(i18n.t("mcp:apiKeyApprovalFailed"), error);
|
|
1338
|
-
}
|
|
1339
|
-
}
|
|
1340
|
-
function setPrimaryApiKey(codeTool) {
|
|
1341
|
-
try {
|
|
1342
|
-
if (resolveClaudeFamilySettingsTarget(codeTool).codeTool !== "claude-code") {
|
|
1343
|
-
return;
|
|
1344
|
-
}
|
|
1345
|
-
let config = readJsonConfig(CLAUDE_VSC_CONFIG_FILE);
|
|
1346
|
-
if (!config) {
|
|
1347
|
-
config = {};
|
|
1348
|
-
}
|
|
1349
|
-
config.primaryApiKey = "ccjk";
|
|
1350
|
-
writeJsonConfig(CLAUDE_VSC_CONFIG_FILE, config);
|
|
1351
|
-
} catch (error) {
|
|
1352
|
-
ensureI18nInitialized();
|
|
1353
|
-
console.error(i18n.t("mcp:primaryApiKeySetFailed"), error);
|
|
1354
|
-
}
|
|
1355
|
-
}
|
|
1356
|
-
function normalizeMyclaudeProviderProfile(profile) {
|
|
1357
|
-
return {
|
|
1358
|
-
...profile,
|
|
1359
|
-
...describeMyclaudeProviderProfile(profile)
|
|
1360
|
-
};
|
|
1361
|
-
}
|
|
1362
|
-
function normalizeClavueBaseUrl(url) {
|
|
1363
|
-
if (typeof url !== "string") {
|
|
1364
|
-
return void 0;
|
|
1365
|
-
}
|
|
1366
|
-
const normalized = url.trim().replace(/\/v1(?:\/messages|\/responses)?\/?$/i, "").replace(/\/+$/, "");
|
|
1367
|
-
return normalized || void 0;
|
|
1368
|
-
}
|
|
1369
|
-
function normalizeClavueAuthType(authType) {
|
|
1370
|
-
return authType === "auth_token" ? "auth_token" : "api_key";
|
|
1371
|
-
}
|
|
1372
|
-
function inferClavueProviderId(provider, baseUrl) {
|
|
1373
|
-
const providerId = typeof provider === "string" ? provider.trim() : "";
|
|
1374
|
-
if (providerId && providerId !== "ccr_proxy") {
|
|
1375
|
-
return providerId;
|
|
1376
|
-
}
|
|
1377
|
-
if (baseUrl === "https://api.anthropic.com") {
|
|
1378
|
-
return "anthropic";
|
|
1379
|
-
}
|
|
1380
|
-
return "custom";
|
|
1381
|
-
}
|
|
1382
|
-
function isOpenAiFamilyModel(model) {
|
|
1383
|
-
return /^(?:gpt-|o\d|codex|kimi|glm|moonshot|deepseek|qwen|doubao|yi-|minimax)/i.test(model.trim());
|
|
1384
|
-
}
|
|
1385
|
-
function inferClavueModelMode(profile) {
|
|
1386
|
-
if (profile.authType === "ccr_proxy" || profile.mode === "ccr-proxy") {
|
|
1387
|
-
return "hybrid_compatible";
|
|
1388
|
-
}
|
|
1389
|
-
const routedModels = [
|
|
1390
|
-
profile.primaryModel,
|
|
1391
|
-
profile.model,
|
|
1392
|
-
profile.defaultHaikuModel,
|
|
1393
|
-
profile.fastModel,
|
|
1394
|
-
profile.defaultSonnetModel,
|
|
1395
|
-
profile.defaultOpusModel
|
|
1396
|
-
].filter((model) => typeof model === "string" && model.trim().length > 0);
|
|
1397
|
-
if (routedModels.length > 0 && routedModels.every(isOpenAiFamilyModel)) {
|
|
1398
|
-
return "openai_native";
|
|
1399
|
-
}
|
|
1400
|
-
if (routedModels.length > 0 && !routedModels.some(isOpenAiFamilyModel)) {
|
|
1401
|
-
return "anthropic_native";
|
|
1402
|
-
}
|
|
1403
|
-
if (routedModels.length > 0) {
|
|
1404
|
-
return "hybrid_compatible";
|
|
1405
|
-
}
|
|
1406
|
-
if (profile.mode === "openai-native") {
|
|
1407
|
-
return "openai_native";
|
|
1408
|
-
}
|
|
1409
|
-
if (!profile.baseUrl || profile.provider === "anthropic" || profile.mode === "official") {
|
|
1410
|
-
return "anthropic_native";
|
|
1411
|
-
}
|
|
1412
|
-
return routedModels.some(isOpenAiFamilyModel) ? "hybrid_compatible" : "anthropic_native";
|
|
1413
|
-
}
|
|
1414
|
-
function getClavueRoutingPresetId(profile) {
|
|
1415
|
-
const mode = inferClavueModelMode(profile);
|
|
1416
|
-
if (mode === "openai_native") {
|
|
1417
|
-
return "gpt_5_4_codex";
|
|
1418
|
-
}
|
|
1419
|
-
if (mode === "anthropic_native") {
|
|
1420
|
-
return "claude_code_heritage";
|
|
1421
|
-
}
|
|
1422
|
-
return "custom";
|
|
1423
|
-
}
|
|
1424
|
-
function isCcjkClavueProfile(profile) {
|
|
1425
|
-
return profile.provenance?.kind === "imported" && profile.provenance.sourceId === "ccjk";
|
|
1426
|
-
}
|
|
1427
|
-
const CCJK_CLAVUE_PROFILE_ID_PREFIX = "ccjk-";
|
|
1428
|
-
function getSourceProfileId(profile) {
|
|
1429
|
-
const id = typeof profile.id === "string" ? profile.id.trim() : "";
|
|
1430
|
-
if (id) {
|
|
1431
|
-
return id;
|
|
1432
|
-
}
|
|
1433
|
-
const name = typeof profile.name === "string" ? profile.name.trim() : "";
|
|
1434
|
-
return name || "profile";
|
|
1435
|
-
}
|
|
1436
|
-
function getCcjkExternalProfileId(profile) {
|
|
1437
|
-
const externalProfileId = profile.provenance?.externalProfileId;
|
|
1438
|
-
if (typeof externalProfileId === "string" && externalProfileId.trim()) {
|
|
1439
|
-
return externalProfileId.trim();
|
|
1440
|
-
}
|
|
1441
|
-
const profileId = typeof profile.id === "string" ? profile.id.trim() : "";
|
|
1442
|
-
if (profileId.startsWith(CCJK_CLAVUE_PROFILE_ID_PREFIX) && profileId.length > CCJK_CLAVUE_PROFILE_ID_PREFIX.length) {
|
|
1443
|
-
return profileId.slice(CCJK_CLAVUE_PROFILE_ID_PREFIX.length);
|
|
1444
|
-
}
|
|
1445
|
-
return profileId || "profile";
|
|
1446
|
-
}
|
|
1447
|
-
function getCcjkClavueProfileId(externalProfileId) {
|
|
1448
|
-
const cleanExternalId = externalProfileId.trim() || "profile";
|
|
1449
|
-
return cleanExternalId.startsWith(CCJK_CLAVUE_PROFILE_ID_PREFIX) ? cleanExternalId : `${CCJK_CLAVUE_PROFILE_ID_PREFIX}${cleanExternalId}`;
|
|
1450
|
-
}
|
|
1451
|
-
function getUniqueClavueProfileId(baseProfileId, reservedProfileIds) {
|
|
1452
|
-
if (!reservedProfileIds.has(baseProfileId)) {
|
|
1453
|
-
return baseProfileId;
|
|
1454
|
-
}
|
|
1455
|
-
let index = 2;
|
|
1456
|
-
let candidate = `${baseProfileId}-${index}`;
|
|
1457
|
-
while (reservedProfileIds.has(candidate)) {
|
|
1458
|
-
index += 1;
|
|
1459
|
-
candidate = `${baseProfileId}-${index}`;
|
|
1460
|
-
}
|
|
1461
|
-
return candidate;
|
|
1462
|
-
}
|
|
1463
|
-
function buildExistingCcjkProfileByExternalId(existingProfiles) {
|
|
1464
|
-
const existingByExternalId = /* @__PURE__ */ new Map();
|
|
1465
|
-
for (const profile of existingProfiles) {
|
|
1466
|
-
if (!isCcjkClavueProfile(profile)) {
|
|
1467
|
-
continue;
|
|
1468
|
-
}
|
|
1469
|
-
const externalProfileId = getCcjkExternalProfileId(profile);
|
|
1470
|
-
const current = existingByExternalId.get(externalProfileId);
|
|
1471
|
-
if (!current || profile.id.startsWith(CCJK_CLAVUE_PROFILE_ID_PREFIX)) {
|
|
1472
|
-
existingByExternalId.set(externalProfileId, profile);
|
|
1473
|
-
}
|
|
1474
|
-
}
|
|
1475
|
-
return existingByExternalId;
|
|
1476
|
-
}
|
|
1477
|
-
function resolveClavueProviderProfiles(profiles, existingProfiles) {
|
|
1478
|
-
const existingCcjkByExternalId = buildExistingCcjkProfileByExternalId(existingProfiles);
|
|
1479
|
-
const reservedProfileIds = new Set(existingProfiles.filter((profile) => !isCcjkClavueProfile(profile)).map((profile) => profile.id));
|
|
1480
|
-
return profiles.map((profile) => {
|
|
1481
|
-
const externalProfileId = getSourceProfileId(profile);
|
|
1482
|
-
const existing = existingCcjkByExternalId.get(externalProfileId);
|
|
1483
|
-
const canReuseExistingManagedId = Boolean(
|
|
1484
|
-
existing && existing.id.startsWith(CCJK_CLAVUE_PROFILE_ID_PREFIX) && !reservedProfileIds.has(existing.id)
|
|
1485
|
-
);
|
|
1486
|
-
const clavueProfileId = canReuseExistingManagedId ? existing.id : getUniqueClavueProfileId(getCcjkClavueProfileId(externalProfileId), reservedProfileIds);
|
|
1487
|
-
reservedProfileIds.add(clavueProfileId);
|
|
1488
|
-
return {
|
|
1489
|
-
source: profile,
|
|
1490
|
-
clavueProfileId,
|
|
1491
|
-
existing
|
|
1492
|
-
};
|
|
1493
|
-
});
|
|
1494
|
-
}
|
|
1495
|
-
function findResolvedClavueProfile(profiles, profileId) {
|
|
1496
|
-
const requestedProfileId = typeof profileId === "string" ? profileId.trim() : "";
|
|
1497
|
-
if (!requestedProfileId) {
|
|
1498
|
-
return void 0;
|
|
1499
|
-
}
|
|
1500
|
-
return profiles.find((profile) => {
|
|
1501
|
-
return profile.clavueProfileId === requestedProfileId || getSourceProfileId(profile.source) === requestedProfileId;
|
|
1502
|
-
});
|
|
1503
|
-
}
|
|
1504
|
-
function resolveClavueActiveProviderProfileId(config, activeProfileId) {
|
|
1505
|
-
const requestedProfileId = typeof activeProfileId === "string" ? activeProfileId.trim() : "";
|
|
1506
|
-
if (!requestedProfileId) {
|
|
1507
|
-
return void 0;
|
|
1508
|
-
}
|
|
1509
|
-
const existingProfiles = getClavueProviderProfiles(config);
|
|
1510
|
-
if (existingProfiles.some((profile) => profile.id === requestedProfileId)) {
|
|
1511
|
-
return requestedProfileId;
|
|
1512
|
-
}
|
|
1513
|
-
return existingProfiles.find((profile) => {
|
|
1514
|
-
return isCcjkClavueProfile(profile) && getCcjkExternalProfileId(profile) === requestedProfileId;
|
|
1515
|
-
})?.id || requestedProfileId;
|
|
1516
|
-
}
|
|
1517
|
-
function createClavueModelRouting(profile) {
|
|
1518
|
-
const primaryModel = (profile.primaryModel || profile.model || "").trim();
|
|
1519
|
-
const haikuModel = (profile.defaultHaikuModel || profile.fastModel || "").trim();
|
|
1520
|
-
const sonnetModel = (profile.defaultSonnetModel || primaryModel).trim();
|
|
1521
|
-
const opusModel = (profile.defaultOpusModel || primaryModel).trim();
|
|
1522
|
-
const executionModel = sonnetModel || primaryModel;
|
|
1523
|
-
return {
|
|
1524
|
-
presetId: getClavueRoutingPresetId(profile),
|
|
1525
|
-
primaryModel,
|
|
1526
|
-
subagentModel: executionModel && executionModel !== primaryModel ? executionModel : "",
|
|
1527
|
-
smallFastModel: haikuModel,
|
|
1528
|
-
planModel: opusModel || primaryModel,
|
|
1529
|
-
exploreModel: executionModel,
|
|
1530
|
-
generalModel: executionModel,
|
|
1531
|
-
teamModel: executionModel,
|
|
1532
|
-
guideModel: opusModel || primaryModel
|
|
1533
|
-
};
|
|
1534
|
-
}
|
|
1535
|
-
function toClavueProviderProfile(profile, clavueProfileId, existing) {
|
|
1536
|
-
const now = Date.now();
|
|
1537
|
-
const normalizedBaseUrl = normalizeClavueBaseUrl(profile.baseUrl);
|
|
1538
|
-
const createdAt = typeof existing?.createdAt === "number" ? existing.createdAt : now;
|
|
1539
|
-
return {
|
|
1540
|
-
id: clavueProfileId,
|
|
1541
|
-
name: profile.name,
|
|
1542
|
-
providerId: inferClavueProviderId(profile.provider, normalizedBaseUrl),
|
|
1543
|
-
modelMode: inferClavueModelMode(profile),
|
|
1544
|
-
...normalizedBaseUrl ? { baseUrl: normalizedBaseUrl } : {},
|
|
1545
|
-
authType: normalizeClavueAuthType(profile.authType),
|
|
1546
|
-
modelRouting: createClavueModelRouting(profile),
|
|
1547
|
-
provenance: {
|
|
1548
|
-
kind: "imported",
|
|
1549
|
-
sourceId: "ccjk",
|
|
1550
|
-
importedAt: typeof existing?.provenance?.importedAt === "number" ? existing.provenance.importedAt : createdAt,
|
|
1551
|
-
externalProfileId: getSourceProfileId(profile)
|
|
1552
|
-
},
|
|
1553
|
-
createdAt,
|
|
1554
|
-
updatedAt: now
|
|
1555
|
-
};
|
|
1556
|
-
}
|
|
1557
|
-
function readClavueCredentialsConfig() {
|
|
1558
|
-
return readJsonConfig(CLAVUE_CREDENTIALS_FILE) || {};
|
|
1559
|
-
}
|
|
1560
|
-
function writeClavueCredentialsConfig(config) {
|
|
1561
|
-
writeJsonConfig(CLAVUE_CREDENTIALS_FILE, config);
|
|
1562
|
-
try {
|
|
1563
|
-
chmodSync(CLAVUE_CREDENTIALS_FILE, 384);
|
|
1564
|
-
} catch {
|
|
1565
|
-
}
|
|
1566
|
-
}
|
|
1567
|
-
function syncClavueProviderCredentials(profiles, replaceProfileIds = /* @__PURE__ */ new Set()) {
|
|
1568
|
-
const existingCredentials = readClavueCredentialsConfig();
|
|
1569
|
-
const providerProfiles = { ...existingCredentials.providerProfiles || {} };
|
|
1570
|
-
for (const profileId of replaceProfileIds) {
|
|
1571
|
-
delete providerProfiles[profileId];
|
|
1572
|
-
}
|
|
1573
|
-
for (const profile of profiles) {
|
|
1574
|
-
const credential = typeof profile.source.apiKey === "string" ? profile.source.apiKey.trim() : "";
|
|
1575
|
-
if (!profile.clavueProfileId || !credential) {
|
|
1576
|
-
continue;
|
|
1577
|
-
}
|
|
1578
|
-
providerProfiles[profile.clavueProfileId] = {
|
|
1579
|
-
credential,
|
|
1580
|
-
authType: normalizeClavueAuthType(profile.source.authType)
|
|
1581
|
-
};
|
|
1582
|
-
}
|
|
1583
|
-
writeClavueCredentialsConfig({
|
|
1584
|
-
...existingCredentials,
|
|
1585
|
-
providerProfiles: Object.keys(providerProfiles).length > 0 ? providerProfiles : void 0
|
|
1586
|
-
});
|
|
1587
|
-
}
|
|
1588
|
-
function getClavueProviderProfiles(config) {
|
|
1589
|
-
return Array.isArray(config?.clavueProviderProfiles) ? config.clavueProviderProfiles : [];
|
|
1590
|
-
}
|
|
1591
|
-
function getLegacyMyclaudeProviderProfiles(config) {
|
|
1592
|
-
return Array.isArray(config?.myclaudeProviderProfiles) ? config.myclaudeProviderProfiles : [];
|
|
1593
|
-
}
|
|
1594
|
-
function toLegacyProviderProfile(profile) {
|
|
1595
|
-
const routing = profile.modelRouting || createClavueModelRouting({ id: profile.id, name: profile.name, provider: profile.providerId });
|
|
1596
|
-
return {
|
|
1597
|
-
id: isCcjkClavueProfile(profile) ? getCcjkExternalProfileId(profile) : profile.id,
|
|
1598
|
-
name: profile.name,
|
|
1599
|
-
provider: profile.providerId || "custom",
|
|
1600
|
-
baseUrl: profile.baseUrl,
|
|
1601
|
-
model: routing.primaryModel,
|
|
1602
|
-
fastModel: routing.smallFastModel,
|
|
1603
|
-
authType: profile.authType,
|
|
1604
|
-
primaryModel: routing.primaryModel,
|
|
1605
|
-
defaultHaikuModel: routing.smallFastModel,
|
|
1606
|
-
defaultSonnetModel: routing.generalModel || routing.subagentModel,
|
|
1607
|
-
defaultOpusModel: routing.planModel,
|
|
1608
|
-
...describeMyclaudeProviderProfile({
|
|
1609
|
-
authType: profile.authType,
|
|
1610
|
-
baseUrl: profile.baseUrl,
|
|
1611
|
-
mode: profile.modelMode === "openai_native" ? "openai-native" : profile.modelMode === "hybrid_compatible" ? "ccr-proxy" : "official"
|
|
1612
|
-
})
|
|
1613
|
-
};
|
|
1614
|
-
}
|
|
1615
|
-
function normalizeModelSlot(model) {
|
|
1616
|
-
return typeof model === "string" && model.trim() ? model.trim() : void 0;
|
|
1617
|
-
}
|
|
1618
|
-
function resolveClavueModelSelectionSlots(options) {
|
|
1619
|
-
if (options.reset) {
|
|
1620
|
-
return {};
|
|
1621
|
-
}
|
|
1622
|
-
const selectedModel = normalizeModelSlot(options.selectedModel);
|
|
1623
|
-
if (selectedModel) {
|
|
1624
|
-
return {
|
|
1625
|
-
primaryModel: selectedModel,
|
|
1626
|
-
haikuModel: selectedModel,
|
|
1627
|
-
sonnetModel: selectedModel,
|
|
1628
|
-
opusModel: selectedModel
|
|
1629
|
-
};
|
|
1630
|
-
}
|
|
1631
|
-
const primaryModel = normalizeModelSlot(options.primaryModel);
|
|
1632
|
-
const haikuModel = normalizeModelSlot(options.haikuModel);
|
|
1633
|
-
const sonnetModel = normalizeModelSlot(options.sonnetModel);
|
|
1634
|
-
const opusModel = normalizeModelSlot(options.opusModel);
|
|
1635
|
-
if (primaryModel) {
|
|
1636
|
-
return {
|
|
1637
|
-
primaryModel,
|
|
1638
|
-
haikuModel: haikuModel || primaryModel,
|
|
1639
|
-
sonnetModel: sonnetModel || primaryModel,
|
|
1640
|
-
opusModel: opusModel || primaryModel
|
|
1641
|
-
};
|
|
1642
|
-
}
|
|
1643
|
-
return {
|
|
1644
|
-
haikuModel,
|
|
1645
|
-
sonnetModel,
|
|
1646
|
-
opusModel
|
|
1647
|
-
};
|
|
1648
|
-
}
|
|
1649
|
-
function getClavueActiveProfile(config) {
|
|
1650
|
-
const activeId = config?.clavueActiveProviderProfileId || config?.myclaudeActiveProviderProfileId || "";
|
|
1651
|
-
const legacyProfiles = getLegacyMyclaudeProviderProfiles(config);
|
|
1652
|
-
const activeLegacyProfile = legacyProfiles.find((profile) => profile.id === activeId);
|
|
1653
|
-
if (activeLegacyProfile) {
|
|
1654
|
-
return activeLegacyProfile;
|
|
1655
|
-
}
|
|
1656
|
-
const nativeProfiles = getClavueProviderProfiles(config);
|
|
1657
|
-
const activeNativeProfile = nativeProfiles.find((profile) => profile.id === activeId);
|
|
1658
|
-
if (activeNativeProfile) {
|
|
1659
|
-
return toLegacyProviderProfile(activeNativeProfile);
|
|
1660
|
-
}
|
|
1661
|
-
return nativeProfiles.map(toLegacyProviderProfile).find((profile) => profile.id === activeId) || null;
|
|
1662
|
-
}
|
|
1663
|
-
function syncClavueActiveProviderModelSelection(options) {
|
|
1664
|
-
const config = readClavueConfig();
|
|
1665
|
-
const activeId = config?.clavueActiveProviderProfileId || config?.myclaudeActiveProviderProfileId || "";
|
|
1666
|
-
if (!config || !activeId) {
|
|
1667
|
-
return false;
|
|
1668
|
-
}
|
|
1669
|
-
const slots = resolveClavueModelSelectionSlots(options);
|
|
1670
|
-
const nativeProfiles = getClavueProviderProfiles(config);
|
|
1671
|
-
const nativeProfileIndex = nativeProfiles.findIndex((profile) => profile.id === activeId);
|
|
1672
|
-
if (nativeProfileIndex >= 0) {
|
|
1673
|
-
const currentProfile = nativeProfiles[nativeProfileIndex];
|
|
1674
|
-
const routingProfile = {
|
|
1675
|
-
id: currentProfile.id,
|
|
1676
|
-
name: currentProfile.name,
|
|
1677
|
-
provider: currentProfile.providerId,
|
|
1678
|
-
baseUrl: currentProfile.baseUrl,
|
|
1679
|
-
authType: currentProfile.authType,
|
|
1680
|
-
model: slots.primaryModel,
|
|
1681
|
-
fastModel: slots.haikuModel,
|
|
1682
|
-
primaryModel: slots.primaryModel,
|
|
1683
|
-
defaultHaikuModel: slots.haikuModel,
|
|
1684
|
-
defaultSonnetModel: slots.sonnetModel,
|
|
1685
|
-
defaultOpusModel: slots.opusModel,
|
|
1686
|
-
mode: currentProfile.modelMode === "openai_native" ? "openai-native" : currentProfile.modelMode === "hybrid_compatible" ? "ccr-proxy" : "official"
|
|
1687
|
-
};
|
|
1688
|
-
const nextProfile = {
|
|
1689
|
-
...currentProfile,
|
|
1690
|
-
modelMode: options.reset ? currentProfile.modelMode : inferClavueModelMode(routingProfile),
|
|
1691
|
-
modelRouting: createClavueModelRouting(routingProfile),
|
|
1692
|
-
updatedAt: Date.now()
|
|
1693
|
-
};
|
|
1694
|
-
config.clavueProviderProfiles = nativeProfiles.map((profile, index) => index === nativeProfileIndex ? nextProfile : profile);
|
|
1695
|
-
delete config.myclaudeProviderProfiles;
|
|
1696
|
-
delete config.myclaudeActiveProviderProfileId;
|
|
1697
|
-
writeClavueConfig(config);
|
|
1698
|
-
syncMyclaudeActiveProfileToSettings(toLegacyProviderProfile(nextProfile));
|
|
1699
|
-
return true;
|
|
1700
|
-
}
|
|
1701
|
-
const legacyProfiles = getLegacyMyclaudeProviderProfiles(config);
|
|
1702
|
-
const legacyProfileIndex = legacyProfiles.findIndex((profile) => profile.id === activeId);
|
|
1703
|
-
if (legacyProfileIndex < 0) {
|
|
1704
|
-
return false;
|
|
1705
|
-
}
|
|
1706
|
-
const updatedProfiles = legacyProfiles.map((profile, index) => {
|
|
1707
|
-
if (index !== legacyProfileIndex) {
|
|
1708
|
-
return profile;
|
|
1709
|
-
}
|
|
1710
|
-
return {
|
|
1711
|
-
...profile,
|
|
1712
|
-
model: slots.primaryModel,
|
|
1713
|
-
fastModel: slots.haikuModel,
|
|
1714
|
-
primaryModel: slots.primaryModel,
|
|
1715
|
-
defaultHaikuModel: slots.haikuModel,
|
|
1716
|
-
defaultSonnetModel: slots.sonnetModel,
|
|
1717
|
-
defaultOpusModel: slots.opusModel
|
|
1718
|
-
};
|
|
1719
|
-
});
|
|
1720
|
-
setMyclaudeProviderProfiles(updatedProfiles, activeId);
|
|
1721
|
-
return true;
|
|
1722
|
-
}
|
|
1723
|
-
function setMyclaudeProviderProfiles(profiles, activeProfileId) {
|
|
1724
|
-
const config = readClavueConfig() || { mcpServers: {} };
|
|
1725
|
-
const normalizedProfiles = profiles.map(normalizeMyclaudeProviderProfile);
|
|
1726
|
-
const existingProfiles = getClavueProviderProfiles(config);
|
|
1727
|
-
const resolvedProfiles = resolveClavueProviderProfiles(normalizedProfiles, existingProfiles);
|
|
1728
|
-
const selectedProfile = findResolvedClavueProfile(
|
|
1729
|
-
resolvedProfiles,
|
|
1730
|
-
activeProfileId ?? (normalizedProfiles[0] ? getSourceProfileId(normalizedProfiles[0]) : void 0)
|
|
1731
|
-
);
|
|
1732
|
-
const nextActiveProfileId = selectedProfile?.clavueProfileId;
|
|
1733
|
-
const existingCcjkProfileIds = new Set(existingProfiles.filter(isCcjkClavueProfile).map((profile) => profile.id));
|
|
1734
|
-
const preservedProfiles = existingProfiles.filter((profile) => !isCcjkClavueProfile(profile));
|
|
1735
|
-
const preservedProfileIds = new Set(preservedProfiles.map((profile) => profile.id));
|
|
1736
|
-
const replacedCredentialIds = new Set([...existingCcjkProfileIds].filter((profileId) => !preservedProfileIds.has(profileId)));
|
|
1737
|
-
const clavueProfiles = resolvedProfiles.map((profile) => toClavueProviderProfile(
|
|
1738
|
-
profile.source,
|
|
1739
|
-
profile.clavueProfileId,
|
|
1740
|
-
profile.existing
|
|
1741
|
-
));
|
|
1742
|
-
config.clavueProviderProfiles = [...preservedProfiles, ...clavueProfiles];
|
|
1743
|
-
if (nextActiveProfileId) {
|
|
1744
|
-
config.clavueActiveProviderProfileId = nextActiveProfileId;
|
|
1745
|
-
} else {
|
|
1746
|
-
delete config.clavueActiveProviderProfileId;
|
|
1747
|
-
}
|
|
1748
|
-
delete config.myclaudeProviderProfiles;
|
|
1749
|
-
delete config.myclaudeActiveProviderProfileId;
|
|
1750
|
-
writeClavueConfig(config);
|
|
1751
|
-
syncClavueProviderCredentials(resolvedProfiles, replacedCredentialIds);
|
|
1752
|
-
const activeProfile = selectedProfile?.source || null;
|
|
1753
|
-
syncMyclaudeActiveProfileToSettings(activeProfile);
|
|
1754
|
-
return nextActiveProfileId;
|
|
1755
|
-
}
|
|
1756
|
-
function setMyclaudeActiveProviderProfile(activeProfileId) {
|
|
1757
|
-
const config = readClavueConfig() || { mcpServers: {} };
|
|
1758
|
-
const nextActiveProfileId = resolveClavueActiveProviderProfileId(config, activeProfileId);
|
|
1759
|
-
if (nextActiveProfileId) {
|
|
1760
|
-
config.clavueActiveProviderProfileId = nextActiveProfileId;
|
|
1761
|
-
} else {
|
|
1762
|
-
delete config.clavueActiveProviderProfileId;
|
|
1763
|
-
}
|
|
1764
|
-
delete config.myclaudeActiveProviderProfileId;
|
|
1765
|
-
writeClavueConfig(config);
|
|
1766
|
-
syncMyclaudeActiveProfileToSettings(getClavueActiveProfile(config));
|
|
1767
|
-
}
|
|
1768
|
-
function detectMyclaudeProviderMode(profile) {
|
|
1769
|
-
if (profile.authType === "ccr_proxy") {
|
|
1770
|
-
return "ccr-proxy";
|
|
1771
|
-
}
|
|
1772
|
-
if (profile.baseUrl) {
|
|
1773
|
-
return "openai-native";
|
|
1774
|
-
}
|
|
1775
|
-
return "official";
|
|
1776
|
-
}
|
|
1777
|
-
function describeMyclaudeProviderProfile(profile) {
|
|
1778
|
-
const mode = profile.mode || detectMyclaudeProviderMode({
|
|
1779
|
-
authType: profile.authType,
|
|
1780
|
-
baseUrl: profile.baseUrl
|
|
1781
|
-
});
|
|
1782
|
-
return { mode };
|
|
1783
|
-
}
|
|
1784
|
-
function buildMyclaudeProviderPresentation(profile) {
|
|
1785
|
-
const mode = profile.mode || detectMyclaudeProviderMode({
|
|
1786
|
-
authType: profile.authType,
|
|
1787
|
-
baseUrl: profile.baseUrl
|
|
1788
|
-
});
|
|
1789
|
-
const hasAdaptiveRouting = Boolean(profile.defaultHaikuModel || profile.defaultSonnetModel || profile.defaultOpusModel);
|
|
1790
|
-
const hasPrimaryModel = Boolean(profile.primaryModel || profile.model);
|
|
1791
|
-
const modeLabel = mode === "ccr-proxy" ? "CCR-proxy" : mode === "openai-native" ? "OpenAI-native" : "Anthropic-native";
|
|
1792
|
-
const routeLabel = mode === "ccr-proxy" ? profile.baseUrl ? `Claude-family route through CCR \xB7 ${profile.baseUrl}` : "Claude-family route through CCR" : mode === "openai-native" ? profile.baseUrl ? `OpenAI-family route through a compatible gateway \xB7 ${profile.baseUrl}` : "OpenAI-family route through a compatible gateway" : "Official Anthropic route";
|
|
1793
|
-
const strategyLabel = hasAdaptiveRouting ? "Custom routing \xB7 Advanced custom routing. Validate carefully when mixing model families." : hasPrimaryModel ? "Single-model override \xB7 Primary model is pinned for the active profile." : "Native runtime default \xB7 Runtime follows the official provider defaults.";
|
|
1794
|
-
return {
|
|
1795
|
-
modeLabel,
|
|
1796
|
-
sourceLabel: "Imported from ccjk \xB7 Reusable profile imported from the compatible ccjk configuration.",
|
|
1797
|
-
routeLabel,
|
|
1798
|
-
strategyLabel
|
|
1799
|
-
};
|
|
1800
|
-
}
|
|
1801
|
-
function toMyclaudeProviderProfile(profile, existing) {
|
|
1802
|
-
return {
|
|
1803
|
-
id: profile.id || existing?.id || profile.name,
|
|
1804
|
-
name: profile.name,
|
|
1805
|
-
provider: profile.provider || existing?.provider || "custom",
|
|
1806
|
-
apiKey: profile.apiKey,
|
|
1807
|
-
baseUrl: profile.baseUrl,
|
|
1808
|
-
model: profile.primaryModel,
|
|
1809
|
-
fastModel: profile.defaultHaikuModel,
|
|
1810
|
-
authType: profile.authType,
|
|
1811
|
-
primaryModel: profile.primaryModel,
|
|
1812
|
-
defaultHaikuModel: profile.defaultHaikuModel,
|
|
1813
|
-
defaultSonnetModel: profile.defaultSonnetModel,
|
|
1814
|
-
defaultOpusModel: profile.defaultOpusModel,
|
|
1815
|
-
...describeMyclaudeProviderProfile({
|
|
1816
|
-
authType: profile.authType,
|
|
1817
|
-
baseUrl: profile.baseUrl,
|
|
1818
|
-
mode: existing?.mode
|
|
1819
|
-
})
|
|
1820
|
-
};
|
|
1821
|
-
}
|
|
1822
|
-
function syncMyclaudeActiveProfileToSettings(profile) {
|
|
1823
|
-
const settings = readJsonConfig(CLAVUE_SETTINGS_FILE) || {};
|
|
1824
|
-
settings.env = settings.env || {};
|
|
1825
|
-
clearLegacyTopLevelRuntimeSettings(settings);
|
|
1826
|
-
delete settings.env.ANTHROPIC_API_KEY;
|
|
1827
|
-
delete settings.env.ANTHROPIC_AUTH_TOKEN;
|
|
1828
|
-
if (profile?.baseUrl) {
|
|
1829
|
-
settings.env.ANTHROPIC_BASE_URL = normalizeClavueBaseUrl(profile.baseUrl);
|
|
1830
|
-
} else {
|
|
1831
|
-
delete settings.env.ANTHROPIC_BASE_URL;
|
|
1832
|
-
}
|
|
1833
|
-
overwriteModelSettings(settings, {
|
|
1834
|
-
primaryModel: typeof profile?.primaryModel === "string" ? profile.primaryModel : typeof profile?.model === "string" ? profile.model : void 0,
|
|
1835
|
-
haikuModel: typeof profile?.defaultHaikuModel === "string" ? profile.defaultHaikuModel : typeof profile?.fastModel === "string" ? profile.fastModel : void 0,
|
|
1836
|
-
sonnetModel: typeof profile?.defaultSonnetModel === "string" ? profile.defaultSonnetModel : void 0,
|
|
1837
|
-
opusModel: typeof profile?.defaultOpusModel === "string" ? profile.defaultOpusModel : void 0
|
|
1838
|
-
}, profile ? "override" : "reset");
|
|
1839
|
-
const primaryModel = typeof profile?.primaryModel === "string" ? profile.primaryModel.trim() : typeof profile?.model === "string" ? profile.model.trim() : "";
|
|
1840
|
-
const subagentModel = typeof profile?.defaultSonnetModel === "string" ? profile.defaultSonnetModel.trim() : "";
|
|
1841
|
-
if (primaryModel) {
|
|
1842
|
-
settings.env.ANTHROPIC_MODEL = primaryModel;
|
|
1843
|
-
settings.env.ANTHROPIC_CUSTOM_MODEL_OPTION = primaryModel;
|
|
1844
|
-
settings.model = primaryModel;
|
|
1845
|
-
} else if (profile) {
|
|
1846
|
-
delete settings.env.ANTHROPIC_MODEL;
|
|
1847
|
-
delete settings.env.ANTHROPIC_CUSTOM_MODEL_OPTION;
|
|
1848
|
-
delete settings.model;
|
|
1849
|
-
} else {
|
|
1850
|
-
delete settings.env.ANTHROPIC_CUSTOM_MODEL_OPTION;
|
|
1851
|
-
delete settings.model;
|
|
1852
|
-
}
|
|
1853
|
-
if (subagentModel) {
|
|
1854
|
-
settings.env.CLAUDE_CODE_SUBAGENT_MODEL = subagentModel;
|
|
1855
|
-
} else {
|
|
1856
|
-
delete settings.env.CLAUDE_CODE_SUBAGENT_MODEL;
|
|
1857
|
-
}
|
|
1858
|
-
normalizeClaudeFamilySettings(settings);
|
|
1859
|
-
writeJsonConfig(CLAVUE_SETTINGS_FILE, settings);
|
|
1860
|
-
}
|
|
1861
|
-
function syncMyclaudeProviderProfilesFromClaudeConfig(configData) {
|
|
1862
|
-
if (!configData) {
|
|
1863
|
-
clearMyclaudeProviderProfiles();
|
|
1864
|
-
return {
|
|
1865
|
-
activeProfileId: "",
|
|
1866
|
-
activeProfile: null,
|
|
1867
|
-
profiles: []
|
|
1868
|
-
};
|
|
1869
|
-
}
|
|
1870
|
-
const existingConfig = readClavueConfig();
|
|
1871
|
-
const existingProfiles = getLegacyMyclaudeProviderProfiles(existingConfig).length > 0 ? getLegacyMyclaudeProviderProfiles(existingConfig) : getClavueProviderProfiles(existingConfig).map(toLegacyProviderProfile);
|
|
1872
|
-
const existingById = new Map(existingProfiles.map((profile) => [String(profile.id), profile]));
|
|
1873
|
-
const profiles = Object.entries(configData.profiles).map(([id, profile]) => toMyclaudeProviderProfile({ ...profile, id }, existingById.get(id)));
|
|
1874
|
-
const activeProfileId = configData.currentProfileId ?? "";
|
|
1875
|
-
const activeProfile = profiles.find((profile) => profile.id === activeProfileId) || null;
|
|
1876
|
-
const activeClavueProfileId = setMyclaudeProviderProfiles(profiles, activeProfileId);
|
|
1877
|
-
return {
|
|
1878
|
-
activeProfileId: activeClavueProfileId || "",
|
|
1879
|
-
activeProfile,
|
|
1880
|
-
profiles
|
|
1881
|
-
};
|
|
1882
|
-
}
|
|
1883
|
-
function syncMyclaudeProviderProfilesFromCurrentClaudeConfig() {
|
|
1884
|
-
const configData = ClaudeCodeConfigManager.readConfig();
|
|
1885
|
-
return syncMyclaudeProviderProfilesFromClaudeConfig(configData);
|
|
1886
|
-
}
|
|
1887
|
-
function clearMyclaudeProviderProfiles() {
|
|
1888
|
-
const config = readClavueConfig();
|
|
1889
|
-
let preservedActiveProfile = null;
|
|
1890
|
-
if (config) {
|
|
1891
|
-
const existingProfiles = getClavueProviderProfiles(config);
|
|
1892
|
-
const removedIds = /* @__PURE__ */ new Set([
|
|
1893
|
-
...existingProfiles.filter(isCcjkClavueProfile).map((profile) => profile.id),
|
|
1894
|
-
...getLegacyMyclaudeProviderProfiles(config).map((profile) => profile.id)
|
|
1895
|
-
]);
|
|
1896
|
-
const preservedProfiles = existingProfiles.filter((profile) => !removedIds.has(profile.id));
|
|
1897
|
-
const currentActiveId = config.clavueActiveProviderProfileId || config.myclaudeActiveProviderProfileId;
|
|
1898
|
-
const nextActiveId = preservedProfiles.some((profile) => profile.id === currentActiveId) ? currentActiveId : preservedProfiles[0]?.id;
|
|
1899
|
-
if (preservedProfiles.length > 0) {
|
|
1900
|
-
config.clavueProviderProfiles = preservedProfiles;
|
|
1901
|
-
config.clavueActiveProviderProfileId = nextActiveId;
|
|
1902
|
-
preservedActiveProfile = preservedProfiles.find((profile) => profile.id === nextActiveId) ? toLegacyProviderProfile(preservedProfiles.find((profile) => profile.id === nextActiveId)) : null;
|
|
1903
|
-
} else {
|
|
1904
|
-
delete config.clavueProviderProfiles;
|
|
1905
|
-
delete config.clavueActiveProviderProfileId;
|
|
1906
|
-
}
|
|
1907
|
-
delete config.myclaudeProviderProfiles;
|
|
1908
|
-
delete config.myclaudeActiveProviderProfileId;
|
|
1909
|
-
writeClavueConfig(config);
|
|
1910
|
-
if (removedIds.size > 0) {
|
|
1911
|
-
const credentials = readClavueCredentialsConfig();
|
|
1912
|
-
if (credentials.providerProfiles) {
|
|
1913
|
-
const nextProviderProfiles = { ...credentials.providerProfiles };
|
|
1914
|
-
for (const profileId of removedIds) {
|
|
1915
|
-
delete nextProviderProfiles[profileId];
|
|
1916
|
-
}
|
|
1917
|
-
writeClavueCredentialsConfig({
|
|
1918
|
-
...credentials,
|
|
1919
|
-
providerProfiles: Object.keys(nextProviderProfiles).length > 0 ? nextProviderProfiles : void 0
|
|
1920
|
-
});
|
|
1921
|
-
}
|
|
1922
|
-
}
|
|
1923
|
-
}
|
|
1924
|
-
syncMyclaudeActiveProfileToSettings(preservedActiveProfile);
|
|
1925
|
-
}
|
|
1926
|
-
function getKnownMcpServiceIds() {
|
|
1927
|
-
return new Set(MCP_SERVICE_CONFIGS.map((service) => service.id));
|
|
1928
|
-
}
|
|
1929
|
-
function getMcpPermission(serviceId) {
|
|
1930
|
-
return `mcp__${serviceId.toLowerCase().replace(/-/g, "_")}__*`;
|
|
1931
|
-
}
|
|
1932
|
-
function syncMcpPermissions(codeTool) {
|
|
1933
|
-
const target = resolveClaudeFamilySettingsTarget(codeTool);
|
|
1934
|
-
const mcpConfig = readMcpConfig(target.codeTool);
|
|
1935
|
-
const knownServiceIds = getKnownMcpServiceIds();
|
|
1936
|
-
const managedMcpServerIds = Object.keys(mcpConfig?.mcpServers || {}).filter((id) => knownServiceIds.has(id));
|
|
1937
|
-
const settingsPath = target.settingsFile;
|
|
1938
|
-
const settings = readJsonConfig(settingsPath) || {};
|
|
1939
|
-
const allow = Array.isArray(settings.permissions?.allow) ? settings.permissions.allow.filter((permission) => typeof permission === "string") : [];
|
|
1940
|
-
const managedMcpPermissions = new Set(
|
|
1941
|
-
[...knownServiceIds].map(getMcpPermission)
|
|
1942
|
-
);
|
|
1943
|
-
const nonManagedPerms = allow.filter((permission) => !managedMcpPermissions.has(permission));
|
|
1944
|
-
const mcpPerms = managedMcpServerIds.map(getMcpPermission);
|
|
1945
|
-
settings.permissions = {
|
|
1946
|
-
...settings.permissions || {},
|
|
1947
|
-
allow: [...nonManagedPerms, ...mcpPerms]
|
|
1948
|
-
};
|
|
1949
|
-
applyTrustedOperatorPermissions(settings);
|
|
1950
|
-
normalizeClaudeFamilySettings(settings);
|
|
1951
|
-
writeJsonConfig(settingsPath, settings);
|
|
1952
|
-
}
|
|
1953
|
-
|
|
1954
|
-
const claudeConfig = {
|
|
1955
|
-
__proto__: null,
|
|
1956
|
-
addCompletedOnboarding: addCompletedOnboarding,
|
|
1957
|
-
backupMcpConfig: backupMcpConfig,
|
|
1958
|
-
buildMcpServerConfig: buildMcpServerConfig,
|
|
1959
|
-
buildMyclaudeProviderPresentation: buildMyclaudeProviderPresentation,
|
|
1960
|
-
clearMyclaudeProviderProfiles: clearMyclaudeProviderProfiles,
|
|
1961
|
-
describeMyclaudeProviderProfile: describeMyclaudeProviderProfile,
|
|
1962
|
-
ensureApiKeyApproved: ensureApiKeyApproved,
|
|
1963
|
-
fixWindowsMcpConfig: fixWindowsMcpConfig,
|
|
1964
|
-
manageApiKeyApproval: manageApiKeyApproval,
|
|
1965
|
-
mergeMcpServers: mergeMcpServers,
|
|
1966
|
-
readClavueConfig: readClavueConfig,
|
|
1967
|
-
readMcpConfig: readMcpConfig,
|
|
1968
|
-
replaceMcpServers: replaceMcpServers,
|
|
1969
|
-
setMyclaudeActiveProviderProfile: setMyclaudeActiveProviderProfile,
|
|
1970
|
-
setMyclaudeProviderProfiles: setMyclaudeProviderProfiles,
|
|
1971
|
-
setPrimaryApiKey: setPrimaryApiKey,
|
|
1972
|
-
syncClavueActiveProviderModelSelection: syncClavueActiveProviderModelSelection,
|
|
1973
|
-
syncMcpPermissions: syncMcpPermissions,
|
|
1974
|
-
syncMyclaudeProviderProfilesFromClaudeConfig: syncMyclaudeProviderProfilesFromClaudeConfig,
|
|
1975
|
-
syncMyclaudeProviderProfilesFromCurrentClaudeConfig: syncMyclaudeProviderProfilesFromCurrentClaudeConfig,
|
|
1976
|
-
writeClavueConfig: writeClavueConfig,
|
|
1977
|
-
writeMcpConfig: writeMcpConfig
|
|
1978
|
-
};
|
|
1979
13
|
|
|
1980
14
|
const MODEL_ENV_KEYS = [
|
|
1981
15
|
"ANTHROPIC_MODEL",
|
|
@@ -2521,4 +555,4 @@ const config = {
|
|
|
2521
555
|
updateDefaultModel: updateDefaultModel
|
|
2522
556
|
};
|
|
2523
557
|
|
|
2524
|
-
export {
|
|
558
|
+
export { getExistingCustomModelConfig as a, backupExistingConfig as b, copyConfigFiles as c, updateDefaultModel as d, getExistingApiConfig as e, configureApi as f, getExistingModelConfig as g, clearLegacyTopLevelRuntimeSettings as h, applyAiLanguageDirective as i, ensureClaudeDir as j, config as k, mergeAndCleanPermissions as m, overwriteModelSettings as o, promptApiConfigurationAction as p, switchToOfficialLogin as s, updateCustomModel as u };
|