ccjk 14.1.2 → 14.1.5
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 +5 -5
- package/dist/chunks/api-config-selector.mjs +18 -5
- package/dist/chunks/api-providers.mjs +24 -9
- package/dist/chunks/auto-updater.mjs +13 -13
- package/dist/chunks/boost.mjs +1 -1
- package/dist/chunks/ccjk-all.mjs +4 -4
- package/dist/chunks/ccjk-config.mjs +78 -1
- package/dist/chunks/ccjk-mcp.mjs +4 -4
- package/dist/chunks/ccjk-setup.mjs +4 -4
- package/dist/chunks/ccr.mjs +11 -11
- package/dist/chunks/check-updates.mjs +3 -3
- package/dist/chunks/claude-code-incremental-manager.mjs +8 -6
- package/dist/chunks/claude-config.mjs +73 -0
- package/dist/chunks/claude-wrapper.mjs +1 -1
- package/dist/chunks/cli-hook.mjs +76 -1
- package/dist/chunks/code-type-resolver.mjs +14 -13
- package/dist/chunks/codex-config-switch.mjs +2 -2
- package/dist/chunks/codex-provider-manager.mjs +2 -2
- package/dist/chunks/codex.mjs +3 -3
- package/dist/chunks/config-switch.mjs +5 -5
- package/dist/chunks/config.mjs +531 -158
- package/dist/chunks/config2.mjs +22 -20
- package/dist/chunks/config3.mjs +6 -6
- package/dist/chunks/constants.mjs +20 -13
- package/dist/chunks/doctor.mjs +1 -1
- package/dist/chunks/features.mjs +59 -4
- package/dist/chunks/fs-operations.mjs +2 -14
- package/dist/chunks/index.mjs +1 -1
- package/dist/chunks/index10.mjs +115 -100
- package/dist/chunks/init.mjs +121 -53
- package/dist/chunks/installer.mjs +28 -21
- package/dist/chunks/mcp-cli.mjs +6 -6
- package/dist/chunks/mcp.mjs +6 -6
- package/dist/chunks/package.mjs +1 -1
- package/dist/chunks/platform.mjs +3 -3
- package/dist/chunks/prompts.mjs +9 -7
- package/dist/chunks/quick-actions.mjs +1 -1
- package/dist/chunks/quick-provider.mjs +23 -31
- package/dist/chunks/quick-setup.mjs +3 -4
- package/dist/chunks/simple-config.mjs +57 -16
- package/dist/chunks/slash-commands.mjs +1 -1
- package/dist/chunks/smart-guide.mjs +23 -10
- package/dist/chunks/status.mjs +28 -24
- package/dist/chunks/update.mjs +19 -18
- package/dist/chunks/upgrade.mjs +88 -5
- package/dist/chunks/version-checker.mjs +2 -2
- package/dist/chunks/zero-config.mjs +121 -16
- package/dist/cli.mjs +50 -27
- package/dist/i18n/locales/en/configuration.json +5 -3
- package/dist/i18n/locales/en/language.json +1 -1
- package/dist/i18n/locales/en/menu.json +8 -7
- package/dist/i18n/locales/en/multi-config.json +1 -1
- package/dist/i18n/locales/zh-CN/configuration.json +5 -3
- package/dist/i18n/locales/zh-CN/language.json +1 -1
- package/dist/i18n/locales/zh-CN/menu.json +8 -7
- package/dist/i18n/locales/zh-CN/multi-config.json +1 -1
- package/dist/index.d.mts +13 -11
- package/dist/index.d.ts +13 -11
- package/dist/index.mjs +7 -7
- package/dist/shared/{ccjk.B6VCKdyy.mjs → ccjk.BXTrU9TN.mjs} +31 -68
- package/dist/shared/{ccjk.DScm_NnL.mjs → ccjk.Ccrqt7u2.mjs} +30 -1
- package/dist/shared/{ccjk.CVjfbEIj.mjs → ccjk.DZtwozOG.mjs} +1 -1
- package/dist/shared/{ccjk.D6wx-rxT.mjs → ccjk.Dxgd2vjc.mjs} +3 -3
- package/dist/shared/{ccjk.BO45TPXJ.mjs → ccjk.K8c6VnM2.mjs} +2 -2
- package/dist/shared/{ccjk.BJENIVf7.mjs → ccjk.MpkxXQJL.mjs} +179 -19
- package/dist/shared/{ccjk.Dh6Be-ef.mjs → ccjk.ygJzcD-n.mjs} +28 -24
- package/package.json +1 -30
- package/dist/chunks/auto-fix.mjs +0 -253
- package/dist/chunks/auto-init.mjs +0 -311
- package/dist/chunks/auto-upgrade.mjs +0 -152
- package/dist/chunks/migrator.mjs +0 -178
- package/dist/shared/ccjk.DDq2hqA5.mjs +0 -158
- package/dist/shared/ccjk.KPLeMP-o.mjs +0 -79
- package/templates/common/workflow/essential/en/agents/planner.md +0 -116
- package/templates/common/workflow/essential/zh-CN/agents/planner.md +0 -116
package/dist/chunks/config.mjs
CHANGED
|
@@ -1,77 +1,16 @@
|
|
|
1
|
+
import { fileURLToPath } from 'node:url';
|
|
1
2
|
import a from './index5.mjs';
|
|
2
3
|
import { d as dayjs } from '../shared/ccjk.RyizuzOI.mjs';
|
|
3
4
|
import { i as inquirer } from './index6.mjs';
|
|
4
|
-
import {
|
|
5
|
-
import { ZCF_CONFIG_FILE, ZCF_CONFIG_DIR, SETTINGS_FILE, CLAUDE_VSC_CONFIG_FILE, CLAUDE_DIR, ClAUDE_CONFIG_FILE, AI_OUTPUT_LANGUAGES } from './constants.mjs';
|
|
5
|
+
import { ZCF_CONFIG_FILE, ZCF_CONFIG_DIR, CLAUDE_VSC_CONFIG_FILE, CLAVUE_CONFIG_FILE, CLAVUE_CREDENTIALS_FILE, CLAVUE_SETTINGS_FILE, AI_OUTPUT_LANGUAGES, SETTINGS_FILE } from './constants.mjs';
|
|
6
6
|
import { ensureI18nInitialized, i18n } from './index2.mjs';
|
|
7
|
-
import { existsSync, readFileSync } from 'node:fs';
|
|
8
|
-
import {
|
|
9
|
-
import { i as isWindows, m as getMcpCommand } from './platform.mjs';
|
|
7
|
+
import { existsSync, readFileSync, chmodSync } from 'node:fs';
|
|
8
|
+
import { readDefaultTomlConfig, createDefaultTomlConfig, writeTomlConfig } from './ccjk-config.mjs';
|
|
10
9
|
import { ensureDir, exists, copyFile, copyDir, writeFileAtomic } from './fs-operations.mjs';
|
|
11
|
-
import {
|
|
10
|
+
import { readJsonConfig, writeJsonConfig, backupJsonConfig } from './json-config.mjs';
|
|
11
|
+
import { r as resolveClaudeFamilySettingsTarget, m as mergeAndCleanPermissions } from '../shared/ccjk.Ccrqt7u2.mjs';
|
|
12
12
|
import { j as join, d as dirname } from '../shared/ccjk.bQ7Dh1g4.mjs';
|
|
13
|
-
import {
|
|
14
|
-
|
|
15
|
-
function mergeArraysUnique(arr1, arr2) {
|
|
16
|
-
const combined = [...arr1 || [], ...arr2 || []];
|
|
17
|
-
return [...new Set(combined)];
|
|
18
|
-
}
|
|
19
|
-
function isPlainObject(value) {
|
|
20
|
-
return value !== null && typeof value === "object" && value.constructor === Object && Object.prototype.toString.call(value) === "[object Object]";
|
|
21
|
-
}
|
|
22
|
-
function deepMerge(target, source, options = {}) {
|
|
23
|
-
const { mergeArrays = false, arrayMergeStrategy = "replace" } = options;
|
|
24
|
-
const result = { ...target };
|
|
25
|
-
for (const key in source) {
|
|
26
|
-
const sourceValue = source[key];
|
|
27
|
-
const targetValue = result[key];
|
|
28
|
-
if (sourceValue === void 0) {
|
|
29
|
-
continue;
|
|
30
|
-
}
|
|
31
|
-
if (isPlainObject(sourceValue) && isPlainObject(targetValue)) {
|
|
32
|
-
result[key] = deepMerge(targetValue, sourceValue, options);
|
|
33
|
-
} else if (Array.isArray(sourceValue)) {
|
|
34
|
-
if (!mergeArrays || !Array.isArray(targetValue)) {
|
|
35
|
-
result[key] = sourceValue;
|
|
36
|
-
} else {
|
|
37
|
-
switch (arrayMergeStrategy) {
|
|
38
|
-
case "concat":
|
|
39
|
-
result[key] = [...targetValue, ...sourceValue];
|
|
40
|
-
break;
|
|
41
|
-
case "unique":
|
|
42
|
-
result[key] = mergeArraysUnique(targetValue, sourceValue);
|
|
43
|
-
break;
|
|
44
|
-
case "replace":
|
|
45
|
-
default:
|
|
46
|
-
result[key] = sourceValue;
|
|
47
|
-
break;
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
} else {
|
|
51
|
-
result[key] = sourceValue;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
return result;
|
|
55
|
-
}
|
|
56
|
-
function deepClone(obj) {
|
|
57
|
-
if (obj === null || typeof obj !== "object") {
|
|
58
|
-
return obj;
|
|
59
|
-
}
|
|
60
|
-
if (obj instanceof Date) {
|
|
61
|
-
return new Date(obj.getTime());
|
|
62
|
-
}
|
|
63
|
-
if (Array.isArray(obj)) {
|
|
64
|
-
return obj.map((item) => deepClone(item));
|
|
65
|
-
}
|
|
66
|
-
if (isPlainObject(obj)) {
|
|
67
|
-
const cloned = {};
|
|
68
|
-
for (const key in obj) {
|
|
69
|
-
cloned[key] = deepClone(obj[key]);
|
|
70
|
-
}
|
|
71
|
-
return cloned;
|
|
72
|
-
}
|
|
73
|
-
return obj;
|
|
74
|
-
}
|
|
13
|
+
import { i as isWindows, m as getMcpCommand } from './platform.mjs';
|
|
75
14
|
|
|
76
15
|
class ClaudeCodeConfigManager {
|
|
77
16
|
static CONFIG_FILE = ZCF_CONFIG_FILE;
|
|
@@ -263,14 +202,16 @@ class ClaudeCodeConfigManager {
|
|
|
263
202
|
static async applyProfileSettings(profile) {
|
|
264
203
|
const { ensureI18nInitialized, i18n } = await import('./index2.mjs');
|
|
265
204
|
ensureI18nInitialized();
|
|
205
|
+
const target = resolveClaudeFamilySettingsTarget();
|
|
266
206
|
try {
|
|
267
207
|
if (!profile) {
|
|
268
208
|
const { switchToOfficialLogin } = await Promise.resolve().then(function () { return config; });
|
|
269
|
-
switchToOfficialLogin();
|
|
209
|
+
switchToOfficialLogin(target.codeTool);
|
|
270
210
|
return;
|
|
271
211
|
}
|
|
272
212
|
const { readJsonConfig: readJsonConfig2, writeJsonConfig } = await import('./json-config.mjs');
|
|
273
|
-
const settings = readJsonConfig2(
|
|
213
|
+
const settings = readJsonConfig2(target.settingsFile) || {};
|
|
214
|
+
clearLegacyTopLevelRuntimeSettings(settings);
|
|
274
215
|
if (!settings.env)
|
|
275
216
|
settings.env = {};
|
|
276
217
|
let shouldRestartCcr = false;
|
|
@@ -310,13 +251,14 @@ class ClaudeCodeConfigManager {
|
|
|
310
251
|
sonnetModel: profile.defaultSonnetModel,
|
|
311
252
|
opusModel: profile.defaultOpusModel
|
|
312
253
|
}, modelMode);
|
|
313
|
-
writeJsonConfig(
|
|
254
|
+
writeJsonConfig(target.settingsFile, settings);
|
|
314
255
|
const { setPrimaryApiKey, addCompletedOnboarding } = await Promise.resolve().then(function () { return claudeConfig; });
|
|
315
|
-
setPrimaryApiKey();
|
|
316
|
-
addCompletedOnboarding();
|
|
317
|
-
let verifiedSettings = readJsonConfig2(
|
|
256
|
+
setPrimaryApiKey(target.codeTool);
|
|
257
|
+
addCompletedOnboarding(target.codeTool);
|
|
258
|
+
let verifiedSettings = readJsonConfig2(target.settingsFile) || {};
|
|
318
259
|
if (!this.settingsMatchProfile(verifiedSettings, profile)) {
|
|
319
|
-
const repairedSettings = readJsonConfig2(
|
|
260
|
+
const repairedSettings = readJsonConfig2(target.settingsFile) || {};
|
|
261
|
+
clearLegacyTopLevelRuntimeSettings(repairedSettings);
|
|
320
262
|
repairedSettings.env = repairedSettings.env || {};
|
|
321
263
|
if (profile?.authType === "api_key") {
|
|
322
264
|
repairedSettings.env.ANTHROPIC_API_KEY = profile.apiKey;
|
|
@@ -337,8 +279,8 @@ class ClaudeCodeConfigManager {
|
|
|
337
279
|
sonnetModel: profile?.defaultSonnetModel,
|
|
338
280
|
opusModel: profile?.defaultOpusModel
|
|
339
281
|
}, profile ? modelMode : "reset");
|
|
340
|
-
writeJsonConfig(
|
|
341
|
-
verifiedSettings = readJsonConfig2(
|
|
282
|
+
writeJsonConfig(target.settingsFile, repairedSettings);
|
|
283
|
+
verifiedSettings = readJsonConfig2(target.settingsFile) || {};
|
|
342
284
|
}
|
|
343
285
|
if (!this.settingsMatchProfile(verifiedSettings, profile)) {
|
|
344
286
|
throw new Error("settings.json verification failed after applying current profile");
|
|
@@ -849,15 +791,83 @@ const claudeCodeConfigManager = {
|
|
|
849
791
|
ClaudeCodeConfigManager: ClaudeCodeConfigManager
|
|
850
792
|
};
|
|
851
793
|
|
|
852
|
-
function
|
|
853
|
-
|
|
794
|
+
function mergeArraysUnique(arr1, arr2) {
|
|
795
|
+
const combined = [...arr1 || [], ...arr2 || []];
|
|
796
|
+
return [...new Set(combined)];
|
|
854
797
|
}
|
|
855
|
-
function
|
|
856
|
-
|
|
798
|
+
function isPlainObject(value) {
|
|
799
|
+
return value !== null && typeof value === "object" && value.constructor === Object && Object.prototype.toString.call(value) === "[object Object]";
|
|
857
800
|
}
|
|
858
|
-
function
|
|
859
|
-
const
|
|
860
|
-
|
|
801
|
+
function deepMerge(target, source, options = {}) {
|
|
802
|
+
const { mergeArrays = false, arrayMergeStrategy = "replace" } = options;
|
|
803
|
+
const result = { ...target };
|
|
804
|
+
for (const key in source) {
|
|
805
|
+
const sourceValue = source[key];
|
|
806
|
+
const targetValue = result[key];
|
|
807
|
+
if (sourceValue === void 0) {
|
|
808
|
+
continue;
|
|
809
|
+
}
|
|
810
|
+
if (isPlainObject(sourceValue) && isPlainObject(targetValue)) {
|
|
811
|
+
result[key] = deepMerge(targetValue, sourceValue, options);
|
|
812
|
+
} else if (Array.isArray(sourceValue)) {
|
|
813
|
+
if (!mergeArrays || !Array.isArray(targetValue)) {
|
|
814
|
+
result[key] = sourceValue;
|
|
815
|
+
} else {
|
|
816
|
+
switch (arrayMergeStrategy) {
|
|
817
|
+
case "concat":
|
|
818
|
+
result[key] = [...targetValue, ...sourceValue];
|
|
819
|
+
break;
|
|
820
|
+
case "unique":
|
|
821
|
+
result[key] = mergeArraysUnique(targetValue, sourceValue);
|
|
822
|
+
break;
|
|
823
|
+
case "replace":
|
|
824
|
+
default:
|
|
825
|
+
result[key] = sourceValue;
|
|
826
|
+
break;
|
|
827
|
+
}
|
|
828
|
+
}
|
|
829
|
+
} else {
|
|
830
|
+
result[key] = sourceValue;
|
|
831
|
+
}
|
|
832
|
+
}
|
|
833
|
+
return result;
|
|
834
|
+
}
|
|
835
|
+
function deepClone(obj) {
|
|
836
|
+
if (obj === null || typeof obj !== "object") {
|
|
837
|
+
return obj;
|
|
838
|
+
}
|
|
839
|
+
if (obj instanceof Date) {
|
|
840
|
+
return new Date(obj.getTime());
|
|
841
|
+
}
|
|
842
|
+
if (Array.isArray(obj)) {
|
|
843
|
+
return obj.map((item) => deepClone(item));
|
|
844
|
+
}
|
|
845
|
+
if (isPlainObject(obj)) {
|
|
846
|
+
const cloned = {};
|
|
847
|
+
for (const key in obj) {
|
|
848
|
+
cloned[key] = deepClone(obj[key]);
|
|
849
|
+
}
|
|
850
|
+
return cloned;
|
|
851
|
+
}
|
|
852
|
+
return obj;
|
|
853
|
+
}
|
|
854
|
+
|
|
855
|
+
function readMcpConfig(codeTool) {
|
|
856
|
+
return readJsonConfig(resolveClaudeFamilySettingsTarget(codeTool).runtimeConfigFile);
|
|
857
|
+
}
|
|
858
|
+
function writeMcpConfig(config, codeTool) {
|
|
859
|
+
writeJsonConfig(resolveClaudeFamilySettingsTarget(codeTool).runtimeConfigFile, config);
|
|
860
|
+
}
|
|
861
|
+
function backupMcpConfig(codeTool) {
|
|
862
|
+
const target = resolveClaudeFamilySettingsTarget(codeTool);
|
|
863
|
+
const backupBaseDir = join(target.configDir, target.runtimeBackupDirName);
|
|
864
|
+
return backupJsonConfig(target.runtimeConfigFile, backupBaseDir);
|
|
865
|
+
}
|
|
866
|
+
function readClavueConfig() {
|
|
867
|
+
return readJsonConfig(CLAVUE_CONFIG_FILE);
|
|
868
|
+
}
|
|
869
|
+
function writeClavueConfig(config) {
|
|
870
|
+
writeJsonConfig(CLAVUE_CONFIG_FILE, config);
|
|
861
871
|
}
|
|
862
872
|
function mergeMcpServers(existing, newServers) {
|
|
863
873
|
const config = existing || { mcpServers: {} };
|
|
@@ -911,9 +921,9 @@ function fixWindowsMcpConfig(config) {
|
|
|
911
921
|
}
|
|
912
922
|
return fixed;
|
|
913
923
|
}
|
|
914
|
-
function addCompletedOnboarding() {
|
|
924
|
+
function addCompletedOnboarding(codeTool) {
|
|
915
925
|
try {
|
|
916
|
-
let config = readMcpConfig();
|
|
926
|
+
let config = readMcpConfig(codeTool);
|
|
917
927
|
if (!config) {
|
|
918
928
|
config = { mcpServers: {} };
|
|
919
929
|
}
|
|
@@ -921,7 +931,7 @@ function addCompletedOnboarding() {
|
|
|
921
931
|
return;
|
|
922
932
|
}
|
|
923
933
|
config.hasCompletedOnboarding = true;
|
|
924
|
-
writeMcpConfig(config);
|
|
934
|
+
writeMcpConfig(config, codeTool);
|
|
925
935
|
} catch (error) {
|
|
926
936
|
console.error("Failed to add onboarding flag", error);
|
|
927
937
|
throw error;
|
|
@@ -954,21 +964,24 @@ function ensureApiKeyApproved(config, apiKey) {
|
|
|
954
964
|
}
|
|
955
965
|
return updatedConfig;
|
|
956
966
|
}
|
|
957
|
-
function manageApiKeyApproval(apiKey) {
|
|
967
|
+
function manageApiKeyApproval(apiKey, codeTool) {
|
|
958
968
|
try {
|
|
959
|
-
let config = readMcpConfig();
|
|
969
|
+
let config = readMcpConfig(codeTool);
|
|
960
970
|
if (!config) {
|
|
961
971
|
config = { mcpServers: {} };
|
|
962
972
|
}
|
|
963
973
|
const updatedConfig = ensureApiKeyApproved(config, apiKey);
|
|
964
|
-
writeMcpConfig(updatedConfig);
|
|
974
|
+
writeMcpConfig(updatedConfig, codeTool);
|
|
965
975
|
} catch (error) {
|
|
966
976
|
ensureI18nInitialized();
|
|
967
977
|
console.error(i18n.t("mcp:apiKeyApprovalFailed"), error);
|
|
968
978
|
}
|
|
969
979
|
}
|
|
970
|
-
function setPrimaryApiKey() {
|
|
980
|
+
function setPrimaryApiKey(codeTool) {
|
|
971
981
|
try {
|
|
982
|
+
if (resolveClaudeFamilySettingsTarget(codeTool).codeTool !== "claude-code") {
|
|
983
|
+
return;
|
|
984
|
+
}
|
|
972
985
|
let config = readJsonConfig(CLAUDE_VSC_CONFIG_FILE);
|
|
973
986
|
if (!config) {
|
|
974
987
|
config = {};
|
|
@@ -980,16 +993,310 @@ function setPrimaryApiKey() {
|
|
|
980
993
|
console.error(i18n.t("mcp:primaryApiKeySetFailed"), error);
|
|
981
994
|
}
|
|
982
995
|
}
|
|
996
|
+
function normalizeMyclaudeProviderProfile(profile) {
|
|
997
|
+
return {
|
|
998
|
+
...profile,
|
|
999
|
+
...describeMyclaudeProviderProfile(profile)
|
|
1000
|
+
};
|
|
1001
|
+
}
|
|
1002
|
+
function normalizeClavueBaseUrl(url) {
|
|
1003
|
+
if (typeof url !== "string") {
|
|
1004
|
+
return void 0;
|
|
1005
|
+
}
|
|
1006
|
+
const normalized = url.trim().replace(/\/v1(?:\/messages|\/responses)?\/?$/i, "").replace(/\/+$/, "");
|
|
1007
|
+
return normalized || void 0;
|
|
1008
|
+
}
|
|
1009
|
+
function normalizeClavueAuthType(authType) {
|
|
1010
|
+
return authType === "auth_token" ? "auth_token" : "api_key";
|
|
1011
|
+
}
|
|
1012
|
+
function inferClavueProviderId(provider, baseUrl) {
|
|
1013
|
+
const providerId = typeof provider === "string" ? provider.trim() : "";
|
|
1014
|
+
if (providerId && providerId !== "ccr_proxy") {
|
|
1015
|
+
return providerId;
|
|
1016
|
+
}
|
|
1017
|
+
if (baseUrl === "https://api.anthropic.com") {
|
|
1018
|
+
return "anthropic";
|
|
1019
|
+
}
|
|
1020
|
+
return "custom";
|
|
1021
|
+
}
|
|
1022
|
+
function isOpenAiFamilyModel(model) {
|
|
1023
|
+
return /^(?:gpt-|o\d|codex|kimi|glm|moonshot|deepseek|qwen|doubao|yi-|minimax)/i.test(model.trim());
|
|
1024
|
+
}
|
|
1025
|
+
function inferClavueModelMode(profile) {
|
|
1026
|
+
if (profile.authType === "ccr_proxy" || profile.mode === "ccr-proxy") {
|
|
1027
|
+
return "hybrid_compatible";
|
|
1028
|
+
}
|
|
1029
|
+
const routedModels = [
|
|
1030
|
+
profile.primaryModel,
|
|
1031
|
+
profile.model,
|
|
1032
|
+
profile.defaultHaikuModel,
|
|
1033
|
+
profile.fastModel,
|
|
1034
|
+
profile.defaultSonnetModel,
|
|
1035
|
+
profile.defaultOpusModel
|
|
1036
|
+
].filter((model) => typeof model === "string" && model.trim().length > 0);
|
|
1037
|
+
if (routedModels.length > 0 && routedModels.every(isOpenAiFamilyModel)) {
|
|
1038
|
+
return "openai_native";
|
|
1039
|
+
}
|
|
1040
|
+
if (routedModels.length > 0 && !routedModels.some(isOpenAiFamilyModel)) {
|
|
1041
|
+
return "anthropic_native";
|
|
1042
|
+
}
|
|
1043
|
+
if (profile.mode === "openai-native") {
|
|
1044
|
+
return "openai_native";
|
|
1045
|
+
}
|
|
1046
|
+
if (!profile.baseUrl || profile.provider === "anthropic" || profile.mode === "official") {
|
|
1047
|
+
return "anthropic_native";
|
|
1048
|
+
}
|
|
1049
|
+
return routedModels.some(isOpenAiFamilyModel) ? "hybrid_compatible" : "anthropic_native";
|
|
1050
|
+
}
|
|
1051
|
+
function isCcjkClavueProfile(profile) {
|
|
1052
|
+
return profile.provenance?.kind === "imported" && profile.provenance.sourceId === "ccjk";
|
|
1053
|
+
}
|
|
1054
|
+
const CCJK_CLAVUE_PROFILE_ID_PREFIX = "ccjk-";
|
|
1055
|
+
function getSourceProfileId(profile) {
|
|
1056
|
+
const id = typeof profile.id === "string" ? profile.id.trim() : "";
|
|
1057
|
+
if (id) {
|
|
1058
|
+
return id;
|
|
1059
|
+
}
|
|
1060
|
+
const name = typeof profile.name === "string" ? profile.name.trim() : "";
|
|
1061
|
+
return name || "profile";
|
|
1062
|
+
}
|
|
1063
|
+
function getCcjkExternalProfileId(profile) {
|
|
1064
|
+
const externalProfileId = profile.provenance?.externalProfileId;
|
|
1065
|
+
if (typeof externalProfileId === "string" && externalProfileId.trim()) {
|
|
1066
|
+
return externalProfileId.trim();
|
|
1067
|
+
}
|
|
1068
|
+
const profileId = typeof profile.id === "string" ? profile.id.trim() : "";
|
|
1069
|
+
if (profileId.startsWith(CCJK_CLAVUE_PROFILE_ID_PREFIX) && profileId.length > CCJK_CLAVUE_PROFILE_ID_PREFIX.length) {
|
|
1070
|
+
return profileId.slice(CCJK_CLAVUE_PROFILE_ID_PREFIX.length);
|
|
1071
|
+
}
|
|
1072
|
+
return profileId || "profile";
|
|
1073
|
+
}
|
|
1074
|
+
function getCcjkClavueProfileId(externalProfileId) {
|
|
1075
|
+
const cleanExternalId = externalProfileId.trim() || "profile";
|
|
1076
|
+
return cleanExternalId.startsWith(CCJK_CLAVUE_PROFILE_ID_PREFIX) ? cleanExternalId : `${CCJK_CLAVUE_PROFILE_ID_PREFIX}${cleanExternalId}`;
|
|
1077
|
+
}
|
|
1078
|
+
function getUniqueClavueProfileId(baseProfileId, reservedProfileIds) {
|
|
1079
|
+
if (!reservedProfileIds.has(baseProfileId)) {
|
|
1080
|
+
return baseProfileId;
|
|
1081
|
+
}
|
|
1082
|
+
let index = 2;
|
|
1083
|
+
let candidate = `${baseProfileId}-${index}`;
|
|
1084
|
+
while (reservedProfileIds.has(candidate)) {
|
|
1085
|
+
index += 1;
|
|
1086
|
+
candidate = `${baseProfileId}-${index}`;
|
|
1087
|
+
}
|
|
1088
|
+
return candidate;
|
|
1089
|
+
}
|
|
1090
|
+
function buildExistingCcjkProfileByExternalId(existingProfiles) {
|
|
1091
|
+
const existingByExternalId = /* @__PURE__ */ new Map();
|
|
1092
|
+
for (const profile of existingProfiles) {
|
|
1093
|
+
if (!isCcjkClavueProfile(profile)) {
|
|
1094
|
+
continue;
|
|
1095
|
+
}
|
|
1096
|
+
const externalProfileId = getCcjkExternalProfileId(profile);
|
|
1097
|
+
const current = existingByExternalId.get(externalProfileId);
|
|
1098
|
+
if (!current || profile.id.startsWith(CCJK_CLAVUE_PROFILE_ID_PREFIX)) {
|
|
1099
|
+
existingByExternalId.set(externalProfileId, profile);
|
|
1100
|
+
}
|
|
1101
|
+
}
|
|
1102
|
+
return existingByExternalId;
|
|
1103
|
+
}
|
|
1104
|
+
function resolveClavueProviderProfiles(profiles, existingProfiles) {
|
|
1105
|
+
const existingCcjkByExternalId = buildExistingCcjkProfileByExternalId(existingProfiles);
|
|
1106
|
+
const reservedProfileIds = new Set(existingProfiles.filter((profile) => !isCcjkClavueProfile(profile)).map((profile) => profile.id));
|
|
1107
|
+
return profiles.map((profile) => {
|
|
1108
|
+
const externalProfileId = getSourceProfileId(profile);
|
|
1109
|
+
const existing = existingCcjkByExternalId.get(externalProfileId);
|
|
1110
|
+
const canReuseExistingManagedId = Boolean(
|
|
1111
|
+
existing && existing.id.startsWith(CCJK_CLAVUE_PROFILE_ID_PREFIX) && !reservedProfileIds.has(existing.id)
|
|
1112
|
+
);
|
|
1113
|
+
const clavueProfileId = canReuseExistingManagedId ? existing.id : getUniqueClavueProfileId(getCcjkClavueProfileId(externalProfileId), reservedProfileIds);
|
|
1114
|
+
reservedProfileIds.add(clavueProfileId);
|
|
1115
|
+
return {
|
|
1116
|
+
source: profile,
|
|
1117
|
+
clavueProfileId,
|
|
1118
|
+
existing
|
|
1119
|
+
};
|
|
1120
|
+
});
|
|
1121
|
+
}
|
|
1122
|
+
function findResolvedClavueProfile(profiles, profileId) {
|
|
1123
|
+
const requestedProfileId = typeof profileId === "string" ? profileId.trim() : "";
|
|
1124
|
+
if (!requestedProfileId) {
|
|
1125
|
+
return void 0;
|
|
1126
|
+
}
|
|
1127
|
+
return profiles.find((profile) => {
|
|
1128
|
+
return profile.clavueProfileId === requestedProfileId || getSourceProfileId(profile.source) === requestedProfileId;
|
|
1129
|
+
});
|
|
1130
|
+
}
|
|
1131
|
+
function resolveClavueActiveProviderProfileId(config, activeProfileId) {
|
|
1132
|
+
const requestedProfileId = typeof activeProfileId === "string" ? activeProfileId.trim() : "";
|
|
1133
|
+
if (!requestedProfileId) {
|
|
1134
|
+
return void 0;
|
|
1135
|
+
}
|
|
1136
|
+
const existingProfiles = getClavueProviderProfiles(config);
|
|
1137
|
+
if (existingProfiles.some((profile) => profile.id === requestedProfileId)) {
|
|
1138
|
+
return requestedProfileId;
|
|
1139
|
+
}
|
|
1140
|
+
return existingProfiles.find((profile) => {
|
|
1141
|
+
return isCcjkClavueProfile(profile) && getCcjkExternalProfileId(profile) === requestedProfileId;
|
|
1142
|
+
})?.id || requestedProfileId;
|
|
1143
|
+
}
|
|
1144
|
+
function createClavueModelRouting(profile) {
|
|
1145
|
+
const primaryModel = (profile.primaryModel || profile.model || "").trim();
|
|
1146
|
+
const haikuModel = (profile.defaultHaikuModel || profile.fastModel || "").trim();
|
|
1147
|
+
const sonnetModel = (profile.defaultSonnetModel || primaryModel).trim();
|
|
1148
|
+
const opusModel = (profile.defaultOpusModel || primaryModel).trim();
|
|
1149
|
+
const executionModel = sonnetModel || primaryModel;
|
|
1150
|
+
return {
|
|
1151
|
+
presetId: "custom",
|
|
1152
|
+
primaryModel,
|
|
1153
|
+
subagentModel: executionModel && executionModel !== primaryModel ? executionModel : "",
|
|
1154
|
+
smallFastModel: haikuModel,
|
|
1155
|
+
planModel: opusModel || primaryModel,
|
|
1156
|
+
exploreModel: executionModel,
|
|
1157
|
+
generalModel: executionModel,
|
|
1158
|
+
teamModel: executionModel,
|
|
1159
|
+
guideModel: opusModel || primaryModel
|
|
1160
|
+
};
|
|
1161
|
+
}
|
|
1162
|
+
function toClavueProviderProfile(profile, clavueProfileId, existing) {
|
|
1163
|
+
const now = Date.now();
|
|
1164
|
+
const normalizedBaseUrl = normalizeClavueBaseUrl(profile.baseUrl);
|
|
1165
|
+
const createdAt = typeof existing?.createdAt === "number" ? existing.createdAt : now;
|
|
1166
|
+
return {
|
|
1167
|
+
id: clavueProfileId,
|
|
1168
|
+
name: profile.name,
|
|
1169
|
+
providerId: inferClavueProviderId(profile.provider, normalizedBaseUrl),
|
|
1170
|
+
modelMode: inferClavueModelMode(profile),
|
|
1171
|
+
...normalizedBaseUrl ? { baseUrl: normalizedBaseUrl } : {},
|
|
1172
|
+
authType: normalizeClavueAuthType(profile.authType),
|
|
1173
|
+
modelRouting: createClavueModelRouting(profile),
|
|
1174
|
+
provenance: {
|
|
1175
|
+
kind: "imported",
|
|
1176
|
+
sourceId: "ccjk",
|
|
1177
|
+
importedAt: typeof existing?.provenance?.importedAt === "number" ? existing.provenance.importedAt : createdAt,
|
|
1178
|
+
externalProfileId: getSourceProfileId(profile)
|
|
1179
|
+
},
|
|
1180
|
+
createdAt,
|
|
1181
|
+
updatedAt: now
|
|
1182
|
+
};
|
|
1183
|
+
}
|
|
1184
|
+
function readClavueCredentialsConfig() {
|
|
1185
|
+
return readJsonConfig(CLAVUE_CREDENTIALS_FILE) || {};
|
|
1186
|
+
}
|
|
1187
|
+
function writeClavueCredentialsConfig(config) {
|
|
1188
|
+
writeJsonConfig(CLAVUE_CREDENTIALS_FILE, config);
|
|
1189
|
+
try {
|
|
1190
|
+
chmodSync(CLAVUE_CREDENTIALS_FILE, 384);
|
|
1191
|
+
} catch {
|
|
1192
|
+
}
|
|
1193
|
+
}
|
|
1194
|
+
function syncClavueProviderCredentials(profiles, replaceProfileIds = /* @__PURE__ */ new Set()) {
|
|
1195
|
+
const existingCredentials = readClavueCredentialsConfig();
|
|
1196
|
+
const providerProfiles = { ...existingCredentials.providerProfiles || {} };
|
|
1197
|
+
for (const profileId of replaceProfileIds) {
|
|
1198
|
+
delete providerProfiles[profileId];
|
|
1199
|
+
}
|
|
1200
|
+
for (const profile of profiles) {
|
|
1201
|
+
const credential = typeof profile.source.apiKey === "string" ? profile.source.apiKey.trim() : "";
|
|
1202
|
+
if (!profile.clavueProfileId || !credential) {
|
|
1203
|
+
continue;
|
|
1204
|
+
}
|
|
1205
|
+
providerProfiles[profile.clavueProfileId] = {
|
|
1206
|
+
credential,
|
|
1207
|
+
authType: normalizeClavueAuthType(profile.source.authType)
|
|
1208
|
+
};
|
|
1209
|
+
}
|
|
1210
|
+
writeClavueCredentialsConfig({
|
|
1211
|
+
...existingCredentials,
|
|
1212
|
+
providerProfiles: Object.keys(providerProfiles).length > 0 ? providerProfiles : void 0
|
|
1213
|
+
});
|
|
1214
|
+
}
|
|
1215
|
+
function getClavueProviderProfiles(config) {
|
|
1216
|
+
return Array.isArray(config?.clavueProviderProfiles) ? config.clavueProviderProfiles : [];
|
|
1217
|
+
}
|
|
1218
|
+
function getLegacyMyclaudeProviderProfiles(config) {
|
|
1219
|
+
return Array.isArray(config?.myclaudeProviderProfiles) ? config.myclaudeProviderProfiles : [];
|
|
1220
|
+
}
|
|
1221
|
+
function toLegacyProviderProfile(profile) {
|
|
1222
|
+
const routing = profile.modelRouting || createClavueModelRouting({ id: profile.id, name: profile.name, provider: profile.providerId });
|
|
1223
|
+
return {
|
|
1224
|
+
id: isCcjkClavueProfile(profile) ? getCcjkExternalProfileId(profile) : profile.id,
|
|
1225
|
+
name: profile.name,
|
|
1226
|
+
provider: profile.providerId || "custom",
|
|
1227
|
+
baseUrl: profile.baseUrl,
|
|
1228
|
+
model: routing.primaryModel,
|
|
1229
|
+
fastModel: routing.smallFastModel,
|
|
1230
|
+
authType: profile.authType,
|
|
1231
|
+
primaryModel: routing.primaryModel,
|
|
1232
|
+
defaultHaikuModel: routing.smallFastModel,
|
|
1233
|
+
defaultSonnetModel: routing.generalModel || routing.subagentModel,
|
|
1234
|
+
defaultOpusModel: routing.planModel,
|
|
1235
|
+
...describeMyclaudeProviderProfile({
|
|
1236
|
+
authType: profile.authType,
|
|
1237
|
+
baseUrl: profile.baseUrl,
|
|
1238
|
+
mode: profile.modelMode === "openai_native" ? "openai-native" : profile.modelMode === "hybrid_compatible" ? "ccr-proxy" : "official"
|
|
1239
|
+
})
|
|
1240
|
+
};
|
|
1241
|
+
}
|
|
1242
|
+
function getClavueActiveProfile(config) {
|
|
1243
|
+
const activeId = config?.clavueActiveProviderProfileId || config?.myclaudeActiveProviderProfileId || "";
|
|
1244
|
+
const legacyProfiles = getLegacyMyclaudeProviderProfiles(config);
|
|
1245
|
+
const activeLegacyProfile = legacyProfiles.find((profile) => profile.id === activeId);
|
|
1246
|
+
if (activeLegacyProfile) {
|
|
1247
|
+
return activeLegacyProfile;
|
|
1248
|
+
}
|
|
1249
|
+
const nativeProfiles = getClavueProviderProfiles(config);
|
|
1250
|
+
const activeNativeProfile = nativeProfiles.find((profile) => profile.id === activeId);
|
|
1251
|
+
if (activeNativeProfile) {
|
|
1252
|
+
return toLegacyProviderProfile(activeNativeProfile);
|
|
1253
|
+
}
|
|
1254
|
+
return nativeProfiles.map(toLegacyProviderProfile).find((profile) => profile.id === activeId) || null;
|
|
1255
|
+
}
|
|
983
1256
|
function setMyclaudeProviderProfiles(profiles, activeProfileId) {
|
|
984
|
-
const config =
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
1257
|
+
const config = readClavueConfig() || { mcpServers: {} };
|
|
1258
|
+
const normalizedProfiles = profiles.map(normalizeMyclaudeProviderProfile);
|
|
1259
|
+
const existingProfiles = getClavueProviderProfiles(config);
|
|
1260
|
+
const resolvedProfiles = resolveClavueProviderProfiles(normalizedProfiles, existingProfiles);
|
|
1261
|
+
const selectedProfile = findResolvedClavueProfile(
|
|
1262
|
+
resolvedProfiles,
|
|
1263
|
+
activeProfileId ?? (normalizedProfiles[0] ? getSourceProfileId(normalizedProfiles[0]) : void 0)
|
|
1264
|
+
);
|
|
1265
|
+
const nextActiveProfileId = selectedProfile?.clavueProfileId;
|
|
1266
|
+
const existingCcjkProfileIds = new Set(existingProfiles.filter(isCcjkClavueProfile).map((profile) => profile.id));
|
|
1267
|
+
const preservedProfiles = existingProfiles.filter((profile) => !isCcjkClavueProfile(profile));
|
|
1268
|
+
const preservedProfileIds = new Set(preservedProfiles.map((profile) => profile.id));
|
|
1269
|
+
const replacedCredentialIds = new Set([...existingCcjkProfileIds].filter((profileId) => !preservedProfileIds.has(profileId)));
|
|
1270
|
+
const clavueProfiles = resolvedProfiles.map((profile) => toClavueProviderProfile(
|
|
1271
|
+
profile.source,
|
|
1272
|
+
profile.clavueProfileId,
|
|
1273
|
+
profile.existing
|
|
1274
|
+
));
|
|
1275
|
+
config.clavueProviderProfiles = [...preservedProfiles, ...clavueProfiles];
|
|
1276
|
+
if (nextActiveProfileId) {
|
|
1277
|
+
config.clavueActiveProviderProfileId = nextActiveProfileId;
|
|
1278
|
+
} else {
|
|
1279
|
+
delete config.clavueActiveProviderProfileId;
|
|
1280
|
+
}
|
|
1281
|
+
delete config.myclaudeProviderProfiles;
|
|
1282
|
+
delete config.myclaudeActiveProviderProfileId;
|
|
1283
|
+
writeClavueConfig(config);
|
|
1284
|
+
syncClavueProviderCredentials(resolvedProfiles, replacedCredentialIds);
|
|
1285
|
+
const activeProfile = selectedProfile?.source || null;
|
|
1286
|
+
syncMyclaudeActiveProfileToSettings(activeProfile);
|
|
1287
|
+
return nextActiveProfileId;
|
|
988
1288
|
}
|
|
989
1289
|
function setMyclaudeActiveProviderProfile(activeProfileId) {
|
|
990
|
-
const config =
|
|
991
|
-
|
|
992
|
-
|
|
1290
|
+
const config = readClavueConfig() || { mcpServers: {} };
|
|
1291
|
+
const nextActiveProfileId = resolveClavueActiveProviderProfileId(config, activeProfileId);
|
|
1292
|
+
if (nextActiveProfileId) {
|
|
1293
|
+
config.clavueActiveProviderProfileId = nextActiveProfileId;
|
|
1294
|
+
} else {
|
|
1295
|
+
delete config.clavueActiveProviderProfileId;
|
|
1296
|
+
}
|
|
1297
|
+
delete config.myclaudeActiveProviderProfileId;
|
|
1298
|
+
writeClavueConfig(config);
|
|
1299
|
+
syncMyclaudeActiveProfileToSettings(getClavueActiveProfile(config));
|
|
993
1300
|
}
|
|
994
1301
|
function detectMyclaudeProviderMode(profile) {
|
|
995
1302
|
if (profile.authType === "ccr_proxy") {
|
|
@@ -1046,20 +1353,13 @@ function toMyclaudeProviderProfile(profile, existing) {
|
|
|
1046
1353
|
};
|
|
1047
1354
|
}
|
|
1048
1355
|
function syncMyclaudeActiveProfileToSettings(profile) {
|
|
1049
|
-
const settings = readJsonConfig(
|
|
1356
|
+
const settings = readJsonConfig(CLAVUE_SETTINGS_FILE) || {};
|
|
1050
1357
|
settings.env = settings.env || {};
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
} else if (profile?.apiKey) {
|
|
1055
|
-
settings.env.ANTHROPIC_API_KEY = profile.apiKey;
|
|
1056
|
-
delete settings.env.ANTHROPIC_AUTH_TOKEN;
|
|
1057
|
-
} else {
|
|
1058
|
-
delete settings.env.ANTHROPIC_API_KEY;
|
|
1059
|
-
delete settings.env.ANTHROPIC_AUTH_TOKEN;
|
|
1060
|
-
}
|
|
1358
|
+
clearLegacyTopLevelRuntimeSettings(settings);
|
|
1359
|
+
delete settings.env.ANTHROPIC_API_KEY;
|
|
1360
|
+
delete settings.env.ANTHROPIC_AUTH_TOKEN;
|
|
1061
1361
|
if (profile?.baseUrl) {
|
|
1062
|
-
settings.env.ANTHROPIC_BASE_URL = profile.baseUrl;
|
|
1362
|
+
settings.env.ANTHROPIC_BASE_URL = normalizeClavueBaseUrl(profile.baseUrl);
|
|
1063
1363
|
} else {
|
|
1064
1364
|
delete settings.env.ANTHROPIC_BASE_URL;
|
|
1065
1365
|
}
|
|
@@ -1069,7 +1369,26 @@ function syncMyclaudeActiveProfileToSettings(profile) {
|
|
|
1069
1369
|
sonnetModel: typeof profile?.defaultSonnetModel === "string" ? profile.defaultSonnetModel : void 0,
|
|
1070
1370
|
opusModel: typeof profile?.defaultOpusModel === "string" ? profile.defaultOpusModel : void 0
|
|
1071
1371
|
}, profile ? "override" : "reset");
|
|
1072
|
-
|
|
1372
|
+
const primaryModel = typeof profile?.primaryModel === "string" ? profile.primaryModel.trim() : typeof profile?.model === "string" ? profile.model.trim() : "";
|
|
1373
|
+
const subagentModel = typeof profile?.defaultSonnetModel === "string" ? profile.defaultSonnetModel.trim() : "";
|
|
1374
|
+
if (primaryModel) {
|
|
1375
|
+
settings.env.ANTHROPIC_MODEL = primaryModel;
|
|
1376
|
+
settings.env.ANTHROPIC_CUSTOM_MODEL_OPTION = primaryModel;
|
|
1377
|
+
settings.model = primaryModel;
|
|
1378
|
+
} else if (profile) {
|
|
1379
|
+
delete settings.env.ANTHROPIC_MODEL;
|
|
1380
|
+
delete settings.env.ANTHROPIC_CUSTOM_MODEL_OPTION;
|
|
1381
|
+
delete settings.model;
|
|
1382
|
+
} else {
|
|
1383
|
+
delete settings.env.ANTHROPIC_CUSTOM_MODEL_OPTION;
|
|
1384
|
+
delete settings.model;
|
|
1385
|
+
}
|
|
1386
|
+
if (subagentModel) {
|
|
1387
|
+
settings.env.CLAUDE_CODE_SUBAGENT_MODEL = subagentModel;
|
|
1388
|
+
} else {
|
|
1389
|
+
delete settings.env.CLAUDE_CODE_SUBAGENT_MODEL;
|
|
1390
|
+
}
|
|
1391
|
+
writeJsonConfig(CLAVUE_SETTINGS_FILE, settings);
|
|
1073
1392
|
}
|
|
1074
1393
|
function syncMyclaudeProviderProfilesFromClaudeConfig(configData) {
|
|
1075
1394
|
if (!configData) {
|
|
@@ -1080,15 +1399,15 @@ function syncMyclaudeProviderProfilesFromClaudeConfig(configData) {
|
|
|
1080
1399
|
profiles: []
|
|
1081
1400
|
};
|
|
1082
1401
|
}
|
|
1083
|
-
const
|
|
1402
|
+
const existingConfig = readClavueConfig();
|
|
1403
|
+
const existingProfiles = getLegacyMyclaudeProviderProfiles(existingConfig).length > 0 ? getLegacyMyclaudeProviderProfiles(existingConfig) : getClavueProviderProfiles(existingConfig).map(toLegacyProviderProfile);
|
|
1084
1404
|
const existingById = new Map(existingProfiles.map((profile) => [String(profile.id), profile]));
|
|
1085
1405
|
const profiles = Object.entries(configData.profiles).map(([id, profile]) => toMyclaudeProviderProfile({ ...profile, id }, existingById.get(id)));
|
|
1086
1406
|
const activeProfileId = configData.currentProfileId ?? "";
|
|
1087
1407
|
const activeProfile = profiles.find((profile) => profile.id === activeProfileId) || null;
|
|
1088
|
-
setMyclaudeProviderProfiles(profiles, activeProfileId);
|
|
1089
|
-
syncMyclaudeActiveProfileToSettings(activeProfile);
|
|
1408
|
+
const activeClavueProfileId = setMyclaudeProviderProfiles(profiles, activeProfileId);
|
|
1090
1409
|
return {
|
|
1091
|
-
activeProfileId,
|
|
1410
|
+
activeProfileId: activeClavueProfileId || "",
|
|
1092
1411
|
activeProfile,
|
|
1093
1412
|
profiles
|
|
1094
1413
|
};
|
|
@@ -1098,18 +1417,49 @@ function syncMyclaudeProviderProfilesFromCurrentClaudeConfig() {
|
|
|
1098
1417
|
return syncMyclaudeProviderProfilesFromClaudeConfig(configData);
|
|
1099
1418
|
}
|
|
1100
1419
|
function clearMyclaudeProviderProfiles() {
|
|
1101
|
-
const config =
|
|
1420
|
+
const config = readClavueConfig();
|
|
1421
|
+
let preservedActiveProfile = null;
|
|
1102
1422
|
if (config) {
|
|
1423
|
+
const existingProfiles = getClavueProviderProfiles(config);
|
|
1424
|
+
const removedIds = /* @__PURE__ */ new Set([
|
|
1425
|
+
...existingProfiles.filter(isCcjkClavueProfile).map((profile) => profile.id),
|
|
1426
|
+
...getLegacyMyclaudeProviderProfiles(config).map((profile) => profile.id)
|
|
1427
|
+
]);
|
|
1428
|
+
const preservedProfiles = existingProfiles.filter((profile) => !removedIds.has(profile.id));
|
|
1429
|
+
const currentActiveId = config.clavueActiveProviderProfileId || config.myclaudeActiveProviderProfileId;
|
|
1430
|
+
const nextActiveId = preservedProfiles.some((profile) => profile.id === currentActiveId) ? currentActiveId : preservedProfiles[0]?.id;
|
|
1431
|
+
if (preservedProfiles.length > 0) {
|
|
1432
|
+
config.clavueProviderProfiles = preservedProfiles;
|
|
1433
|
+
config.clavueActiveProviderProfileId = nextActiveId;
|
|
1434
|
+
preservedActiveProfile = preservedProfiles.find((profile) => profile.id === nextActiveId) ? toLegacyProviderProfile(preservedProfiles.find((profile) => profile.id === nextActiveId)) : null;
|
|
1435
|
+
} else {
|
|
1436
|
+
delete config.clavueProviderProfiles;
|
|
1437
|
+
delete config.clavueActiveProviderProfileId;
|
|
1438
|
+
}
|
|
1103
1439
|
delete config.myclaudeProviderProfiles;
|
|
1104
1440
|
delete config.myclaudeActiveProviderProfileId;
|
|
1105
|
-
|
|
1441
|
+
writeClavueConfig(config);
|
|
1442
|
+
if (removedIds.size > 0) {
|
|
1443
|
+
const credentials = readClavueCredentialsConfig();
|
|
1444
|
+
if (credentials.providerProfiles) {
|
|
1445
|
+
const nextProviderProfiles = { ...credentials.providerProfiles };
|
|
1446
|
+
for (const profileId of removedIds) {
|
|
1447
|
+
delete nextProviderProfiles[profileId];
|
|
1448
|
+
}
|
|
1449
|
+
writeClavueCredentialsConfig({
|
|
1450
|
+
...credentials,
|
|
1451
|
+
providerProfiles: Object.keys(nextProviderProfiles).length > 0 ? nextProviderProfiles : void 0
|
|
1452
|
+
});
|
|
1453
|
+
}
|
|
1454
|
+
}
|
|
1106
1455
|
}
|
|
1107
|
-
syncMyclaudeActiveProfileToSettings(
|
|
1456
|
+
syncMyclaudeActiveProfileToSettings(preservedActiveProfile);
|
|
1108
1457
|
}
|
|
1109
|
-
function syncMcpPermissions() {
|
|
1110
|
-
const
|
|
1458
|
+
function syncMcpPermissions(codeTool) {
|
|
1459
|
+
const target = resolveClaudeFamilySettingsTarget(codeTool);
|
|
1460
|
+
const mcpConfig = readMcpConfig(codeTool);
|
|
1111
1461
|
const mcpServerIds = Object.keys(mcpConfig?.mcpServers || {});
|
|
1112
|
-
const settingsPath =
|
|
1462
|
+
const settingsPath = target.settingsFile;
|
|
1113
1463
|
if (!existsSync(settingsPath))
|
|
1114
1464
|
return;
|
|
1115
1465
|
try {
|
|
@@ -1138,6 +1488,7 @@ const claudeConfig = {
|
|
|
1138
1488
|
fixWindowsMcpConfig: fixWindowsMcpConfig,
|
|
1139
1489
|
manageApiKeyApproval: manageApiKeyApproval,
|
|
1140
1490
|
mergeMcpServers: mergeMcpServers,
|
|
1491
|
+
readClavueConfig: readClavueConfig,
|
|
1141
1492
|
readMcpConfig: readMcpConfig,
|
|
1142
1493
|
replaceMcpServers: replaceMcpServers,
|
|
1143
1494
|
setMyclaudeActiveProviderProfile: setMyclaudeActiveProviderProfile,
|
|
@@ -1146,6 +1497,7 @@ const claudeConfig = {
|
|
|
1146
1497
|
syncMcpPermissions: syncMcpPermissions,
|
|
1147
1498
|
syncMyclaudeProviderProfilesFromClaudeConfig: syncMyclaudeProviderProfilesFromClaudeConfig,
|
|
1148
1499
|
syncMyclaudeProviderProfilesFromCurrentClaudeConfig: syncMyclaudeProviderProfilesFromCurrentClaudeConfig,
|
|
1500
|
+
writeClavueConfig: writeClavueConfig,
|
|
1149
1501
|
writeMcpConfig: writeMcpConfig
|
|
1150
1502
|
};
|
|
1151
1503
|
|
|
@@ -1168,36 +1520,47 @@ function clearModelEnv(env, mode = "reset") {
|
|
|
1168
1520
|
}
|
|
1169
1521
|
|
|
1170
1522
|
const BUILTIN_MODEL_VALUES = ["opus", "sonnet", "sonnet[1m]"];
|
|
1523
|
+
function clearLegacyTopLevelRuntimeSettings(settings) {
|
|
1524
|
+
delete settings.baseUrl;
|
|
1525
|
+
delete settings.apiProvider;
|
|
1526
|
+
delete settings.apiUrl;
|
|
1527
|
+
delete settings.apiKey;
|
|
1528
|
+
delete settings.authToken;
|
|
1529
|
+
delete settings.defaultModel;
|
|
1530
|
+
delete settings.preferredModel;
|
|
1531
|
+
}
|
|
1171
1532
|
function hasAdaptiveRoutingEnv(settings) {
|
|
1172
1533
|
return Boolean(
|
|
1173
1534
|
settings.env?.ANTHROPIC_DEFAULT_HAIKU_MODEL || settings.env?.ANTHROPIC_DEFAULT_SONNET_MODEL || settings.env?.ANTHROPIC_DEFAULT_OPUS_MODEL
|
|
1174
1535
|
);
|
|
1175
1536
|
}
|
|
1176
|
-
function ensureClaudeDir() {
|
|
1177
|
-
ensureDir(
|
|
1537
|
+
function ensureClaudeDir(codeTool) {
|
|
1538
|
+
ensureDir(resolveClaudeFamilySettingsTarget(codeTool).configDir);
|
|
1178
1539
|
}
|
|
1179
|
-
function backupExistingConfig() {
|
|
1180
|
-
|
|
1540
|
+
function backupExistingConfig(codeTool) {
|
|
1541
|
+
const target = resolveClaudeFamilySettingsTarget(codeTool);
|
|
1542
|
+
if (!exists(target.configDir)) {
|
|
1181
1543
|
return null;
|
|
1182
1544
|
}
|
|
1183
1545
|
const timestamp = dayjs().format("YYYY-MM-DD_HH-mm-ss");
|
|
1184
|
-
const backupBaseDir = join(
|
|
1546
|
+
const backupBaseDir = join(target.configDir, target.runtimeBackupDirName);
|
|
1185
1547
|
const backupDir = join(backupBaseDir, `backup_${timestamp}`);
|
|
1186
1548
|
ensureDir(backupDir);
|
|
1187
1549
|
const filter = (path) => {
|
|
1188
|
-
return !path.includes("/backup");
|
|
1550
|
+
return !path.includes("/backup") && !path.includes("/backups");
|
|
1189
1551
|
};
|
|
1190
|
-
copyDir(
|
|
1552
|
+
copyDir(target.configDir, backupDir, { filter });
|
|
1191
1553
|
return backupDir;
|
|
1192
1554
|
}
|
|
1193
|
-
function copyConfigFiles(onlyMd = false) {
|
|
1555
|
+
function copyConfigFiles(onlyMd = false, codeTool) {
|
|
1556
|
+
const target = resolveClaudeFamilySettingsTarget(codeTool);
|
|
1194
1557
|
const currentFilePath = fileURLToPath(import.meta.url);
|
|
1195
1558
|
const distDir = dirname(dirname(currentFilePath));
|
|
1196
1559
|
const rootDir = dirname(distDir);
|
|
1197
1560
|
const baseTemplateDir = join(rootDir, "templates", "claude-code");
|
|
1198
1561
|
if (!onlyMd) {
|
|
1199
1562
|
const baseSettingsPath = join(baseTemplateDir, "common", "settings.json");
|
|
1200
|
-
const destSettingsPath =
|
|
1563
|
+
const destSettingsPath = target.settingsFile;
|
|
1201
1564
|
if (exists(baseSettingsPath)) {
|
|
1202
1565
|
mergeSettingsFile(baseSettingsPath, destSettingsPath);
|
|
1203
1566
|
}
|
|
@@ -1215,10 +1578,11 @@ function getDefaultSettings() {
|
|
|
1215
1578
|
return {};
|
|
1216
1579
|
}
|
|
1217
1580
|
}
|
|
1218
|
-
function configureApi(apiConfig) {
|
|
1581
|
+
function configureApi(apiConfig, codeTool) {
|
|
1219
1582
|
if (!apiConfig)
|
|
1220
1583
|
return null;
|
|
1221
|
-
const
|
|
1584
|
+
const target = resolveClaudeFamilySettingsTarget(codeTool);
|
|
1585
|
+
const existingSettings = readJsonConfig(target.settingsFile);
|
|
1222
1586
|
let settings;
|
|
1223
1587
|
if (existingSettings) {
|
|
1224
1588
|
settings = existingSettings;
|
|
@@ -1228,6 +1592,7 @@ function configureApi(apiConfig) {
|
|
|
1228
1592
|
if (!settings.env) {
|
|
1229
1593
|
settings.env = {};
|
|
1230
1594
|
}
|
|
1595
|
+
clearLegacyTopLevelRuntimeSettings(settings);
|
|
1231
1596
|
if (apiConfig.authType === "api_key") {
|
|
1232
1597
|
settings.env.ANTHROPIC_API_KEY = apiConfig.key;
|
|
1233
1598
|
delete settings.env.ANTHROPIC_AUTH_TOKEN;
|
|
@@ -1238,26 +1603,27 @@ function configureApi(apiConfig) {
|
|
|
1238
1603
|
if (apiConfig.url) {
|
|
1239
1604
|
settings.env.ANTHROPIC_BASE_URL = apiConfig.url;
|
|
1240
1605
|
}
|
|
1241
|
-
writeJsonConfig(
|
|
1242
|
-
if (apiConfig.authType) {
|
|
1606
|
+
writeJsonConfig(target.settingsFile, settings);
|
|
1607
|
+
if (apiConfig.authType && target.codeTool === "claude-code") {
|
|
1243
1608
|
try {
|
|
1244
|
-
setPrimaryApiKey();
|
|
1609
|
+
setPrimaryApiKey(target.codeTool);
|
|
1245
1610
|
} catch (error) {
|
|
1246
1611
|
ensureI18nInitialized();
|
|
1247
1612
|
console.error(i18n.t("mcp:primaryApiKeySetFailed"), error);
|
|
1248
1613
|
}
|
|
1249
1614
|
}
|
|
1250
1615
|
try {
|
|
1251
|
-
addCompletedOnboarding();
|
|
1616
|
+
addCompletedOnboarding(target.codeTool);
|
|
1252
1617
|
} catch (error) {
|
|
1253
1618
|
console.error("Failed to set onboarding flag", error);
|
|
1254
1619
|
}
|
|
1255
|
-
const verification = readJsonConfig(
|
|
1620
|
+
const verification = readJsonConfig(target.settingsFile);
|
|
1256
1621
|
if (verification?.env) {
|
|
1257
1622
|
const envKey = apiConfig.authType === "api_key" ? "ANTHROPIC_API_KEY" : "ANTHROPIC_AUTH_TOKEN";
|
|
1258
1623
|
if (verification.env[envKey] !== apiConfig.key) {
|
|
1259
1624
|
console.error(a.red("\u26A0 API config write verification failed \u2014 retrying..."));
|
|
1260
|
-
const freshSettings = readJsonConfig(
|
|
1625
|
+
const freshSettings = readJsonConfig(target.settingsFile) || settings;
|
|
1626
|
+
clearLegacyTopLevelRuntimeSettings(freshSettings);
|
|
1261
1627
|
if (!freshSettings.env)
|
|
1262
1628
|
freshSettings.env = {};
|
|
1263
1629
|
if (apiConfig.authType === "api_key") {
|
|
@@ -1270,7 +1636,7 @@ function configureApi(apiConfig) {
|
|
|
1270
1636
|
if (apiConfig.url) {
|
|
1271
1637
|
freshSettings.env.ANTHROPIC_BASE_URL = apiConfig.url;
|
|
1272
1638
|
}
|
|
1273
|
-
writeJsonConfig(
|
|
1639
|
+
writeJsonConfig(target.settingsFile, freshSettings);
|
|
1274
1640
|
}
|
|
1275
1641
|
}
|
|
1276
1642
|
return apiConfig;
|
|
@@ -1320,22 +1686,24 @@ function overwriteModelSettings(settings, {
|
|
|
1320
1686
|
}
|
|
1321
1687
|
return settings;
|
|
1322
1688
|
}
|
|
1323
|
-
function updateCustomModel(primaryModel, haikuModel, sonnetModel, opusModel) {
|
|
1689
|
+
function updateCustomModel(primaryModel, haikuModel, sonnetModel, opusModel, codeTool) {
|
|
1324
1690
|
if (!primaryModel?.trim() && !haikuModel?.trim() && !sonnetModel?.trim() && !opusModel?.trim()) {
|
|
1325
1691
|
return;
|
|
1326
1692
|
}
|
|
1693
|
+
const target = resolveClaudeFamilySettingsTarget(codeTool);
|
|
1327
1694
|
let settings = getDefaultSettings();
|
|
1328
|
-
const existingSettings = readJsonConfig(
|
|
1695
|
+
const existingSettings = readJsonConfig(target.settingsFile);
|
|
1329
1696
|
if (existingSettings) {
|
|
1330
1697
|
settings = existingSettings;
|
|
1331
1698
|
}
|
|
1699
|
+
clearLegacyTopLevelRuntimeSettings(settings);
|
|
1332
1700
|
overwriteModelSettings(settings, {
|
|
1333
1701
|
primaryModel,
|
|
1334
1702
|
haikuModel,
|
|
1335
1703
|
sonnetModel,
|
|
1336
1704
|
opusModel
|
|
1337
1705
|
}, "override");
|
|
1338
|
-
writeJsonConfig(
|
|
1706
|
+
writeJsonConfig(target.settingsFile, settings);
|
|
1339
1707
|
}
|
|
1340
1708
|
function updateDefaultModel(model) {
|
|
1341
1709
|
let settings = getDefaultSettings();
|
|
@@ -1343,6 +1711,7 @@ function updateDefaultModel(model) {
|
|
|
1343
1711
|
if (existingSettings) {
|
|
1344
1712
|
settings = existingSettings;
|
|
1345
1713
|
}
|
|
1714
|
+
clearLegacyTopLevelRuntimeSettings(settings);
|
|
1346
1715
|
if (!settings.env) {
|
|
1347
1716
|
settings.env = {};
|
|
1348
1717
|
}
|
|
@@ -1461,8 +1830,9 @@ function getExistingCustomModelConfig() {
|
|
|
1461
1830
|
opusModel: ANTHROPIC_DEFAULT_OPUS_MODEL
|
|
1462
1831
|
};
|
|
1463
1832
|
}
|
|
1464
|
-
function getExistingApiConfig() {
|
|
1465
|
-
const
|
|
1833
|
+
function getExistingApiConfig(codeTool) {
|
|
1834
|
+
const target = resolveClaudeFamilySettingsTarget(codeTool);
|
|
1835
|
+
const settings = readJsonConfig(target.settingsFile);
|
|
1466
1836
|
if (!settings || !settings.env) {
|
|
1467
1837
|
return null;
|
|
1468
1838
|
}
|
|
@@ -1485,8 +1855,9 @@ function getExistingApiConfig() {
|
|
|
1485
1855
|
authType
|
|
1486
1856
|
};
|
|
1487
1857
|
}
|
|
1488
|
-
function applyAiLanguageDirective(aiOutputLang) {
|
|
1489
|
-
const
|
|
1858
|
+
function applyAiLanguageDirective(aiOutputLang, codeTool) {
|
|
1859
|
+
const target = resolveClaudeFamilySettingsTarget(codeTool);
|
|
1860
|
+
const instructionsFile = target.instructionsFile;
|
|
1490
1861
|
let directive = "";
|
|
1491
1862
|
if (aiOutputLang === "custom") {
|
|
1492
1863
|
return;
|
|
@@ -1495,25 +1866,26 @@ function applyAiLanguageDirective(aiOutputLang) {
|
|
|
1495
1866
|
} else {
|
|
1496
1867
|
directive = `Always respond in ${aiOutputLang}`;
|
|
1497
1868
|
}
|
|
1498
|
-
const frontmatter = "---\nscope: user\n
|
|
1499
|
-
writeFileAtomic(
|
|
1500
|
-
|
|
1501
|
-
${directive}`);
|
|
1869
|
+
const frontmatter = target.codeTool === "clavue" ? "" : "---\nscope: user\n---\n\n";
|
|
1870
|
+
writeFileAtomic(instructionsFile, `${frontmatter}${directive}`);
|
|
1502
1871
|
}
|
|
1503
|
-
function switchToOfficialLogin() {
|
|
1872
|
+
function switchToOfficialLogin(codeTool) {
|
|
1504
1873
|
try {
|
|
1505
1874
|
ensureI18nInitialized();
|
|
1506
|
-
const
|
|
1875
|
+
const target = resolveClaudeFamilySettingsTarget(codeTool);
|
|
1876
|
+
const settings = readJsonConfig(target.settingsFile) || {};
|
|
1507
1877
|
if (settings.env) {
|
|
1508
1878
|
delete settings.env.ANTHROPIC_BASE_URL;
|
|
1509
1879
|
delete settings.env.ANTHROPIC_AUTH_TOKEN;
|
|
1510
1880
|
delete settings.env.ANTHROPIC_API_KEY;
|
|
1511
1881
|
}
|
|
1512
|
-
writeJsonConfig(
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1882
|
+
writeJsonConfig(target.settingsFile, settings);
|
|
1883
|
+
if (target.codeTool === "claude-code") {
|
|
1884
|
+
const vscConfig = readJsonConfig(CLAUDE_VSC_CONFIG_FILE);
|
|
1885
|
+
if (vscConfig) {
|
|
1886
|
+
delete vscConfig.primaryApiKey;
|
|
1887
|
+
writeJsonConfig(CLAUDE_VSC_CONFIG_FILE, vscConfig);
|
|
1888
|
+
}
|
|
1517
1889
|
}
|
|
1518
1890
|
console.log(i18n.t("api:officialLoginConfigured"));
|
|
1519
1891
|
return true;
|
|
@@ -1561,6 +1933,7 @@ const config = {
|
|
|
1561
1933
|
__proto__: null,
|
|
1562
1934
|
applyAiLanguageDirective: applyAiLanguageDirective,
|
|
1563
1935
|
backupExistingConfig: backupExistingConfig,
|
|
1936
|
+
clearLegacyTopLevelRuntimeSettings: clearLegacyTopLevelRuntimeSettings,
|
|
1564
1937
|
configureApi: configureApi,
|
|
1565
1938
|
configureHooks: configureHooks,
|
|
1566
1939
|
copyConfigFiles: copyConfigFiles,
|
|
@@ -1577,4 +1950,4 @@ const config = {
|
|
|
1577
1950
|
updateDefaultModel: updateDefaultModel
|
|
1578
1951
|
};
|
|
1579
1952
|
|
|
1580
|
-
export {
|
|
1953
|
+
export { clearMyclaudeProviderProfiles as A, replaceMcpServers as B, ClaudeCodeConfigManager as C, syncMcpPermissions as D, buildMyclaudeProviderPresentation as E, config as F, claudeCodeConfigManager as G, claudeConfig as H, getExistingCustomModelConfig as a, backupExistingConfig as b, updateDefaultModel as c, backupMcpConfig as d, buildMcpServerConfig as e, fixWindowsMcpConfig as f, getExistingModelConfig as g, getExistingApiConfig as h, configureApi as i, syncMyclaudeProviderProfilesFromClaudeConfig as j, copyConfigFiles as k, deepMerge as l, mergeMcpServers as m, clearLegacyTopLevelRuntimeSettings as n, setPrimaryApiKey as o, promptApiConfigurationAction as p, addCompletedOnboarding as q, readMcpConfig as r, setMyclaudeActiveProviderProfile as s, switchToOfficialLogin as t, updateCustomModel as u, applyAiLanguageDirective as v, writeMcpConfig as w, overwriteModelSettings as x, setMyclaudeProviderProfiles as y, ensureClaudeDir as z };
|