@kaitranntt/ccs 5.13.0-dev.4 → 5.14.0-dev.1
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/VERSION +1 -1
- package/dist/auth/auth-commands.d.ts +8 -0
- package/dist/auth/auth-commands.d.ts.map +1 -1
- package/dist/auth/auth-commands.js +54 -14
- package/dist/auth/auth-commands.js.map +1 -1
- package/dist/auth/profile-detector.d.ts +25 -6
- package/dist/auth/profile-detector.d.ts.map +1 -1
- package/dist/auth/profile-detector.js +150 -7
- package/dist/auth/profile-detector.js.map +1 -1
- package/dist/auth/profile-registry.d.ts +35 -0
- package/dist/auth/profile-registry.d.ts.map +1 -1
- package/dist/auth/profile-registry.js +91 -0
- package/dist/auth/profile-registry.js.map +1 -1
- package/dist/ccs.js +17 -0
- package/dist/ccs.js.map +1 -1
- package/dist/cliproxy/account-manager.d.ts +4 -0
- package/dist/cliproxy/account-manager.d.ts.map +1 -1
- package/dist/cliproxy/account-manager.js +25 -1
- package/dist/cliproxy/account-manager.js.map +1 -1
- package/dist/cliproxy/auth-handler.d.ts +1 -0
- package/dist/cliproxy/auth-handler.d.ts.map +1 -1
- package/dist/cliproxy/auth-handler.js +8 -5
- package/dist/cliproxy/auth-handler.js.map +1 -1
- package/dist/cliproxy/cliproxy-executor.d.ts.map +1 -1
- package/dist/cliproxy/cliproxy-executor.js +43 -3
- package/dist/cliproxy/cliproxy-executor.js.map +1 -1
- package/dist/commands/api-command.d.ts +4 -0
- package/dist/commands/api-command.d.ts.map +1 -1
- package/dist/commands/api-command.js +192 -34
- package/dist/commands/api-command.js.map +1 -1
- package/dist/commands/cliproxy-command.d.ts +4 -0
- package/dist/commands/cliproxy-command.d.ts.map +1 -1
- package/dist/commands/cliproxy-command.js +181 -55
- package/dist/commands/cliproxy-command.js.map +1 -1
- package/dist/commands/migrate-command.d.ts +17 -0
- package/dist/commands/migrate-command.d.ts.map +1 -0
- package/dist/commands/migrate-command.js +139 -0
- package/dist/commands/migrate-command.js.map +1 -0
- package/dist/config/feature-flags.d.ts +19 -0
- package/dist/config/feature-flags.d.ts.map +1 -0
- package/dist/config/feature-flags.js +31 -0
- package/dist/config/feature-flags.js.map +1 -0
- package/dist/config/index.d.ts +12 -0
- package/dist/config/index.d.ts.map +1 -0
- package/dist/config/index.js +33 -0
- package/dist/config/index.js.map +1 -0
- package/dist/config/migration-manager.d.ts +46 -0
- package/dist/config/migration-manager.d.ts.map +1 -0
- package/dist/config/migration-manager.js +338 -0
- package/dist/config/migration-manager.js.map +1 -0
- package/dist/config/reserved-names.d.ts +19 -0
- package/dist/config/reserved-names.d.ts.map +1 -0
- package/dist/config/reserved-names.js +40 -0
- package/dist/config/reserved-names.js.map +1 -0
- package/dist/config/secrets-manager.d.ts +51 -0
- package/dist/config/secrets-manager.d.ts.map +1 -0
- package/dist/config/secrets-manager.js +194 -0
- package/dist/config/secrets-manager.js.map +1 -0
- package/dist/config/unified-config-loader.d.ts +55 -0
- package/dist/config/unified-config-loader.d.ts.map +1 -0
- package/dist/config/unified-config-loader.js +262 -0
- package/dist/config/unified-config-loader.js.map +1 -0
- package/dist/config/unified-config-types.d.ts +126 -0
- package/dist/config/unified-config-types.d.ts.map +1 -0
- package/dist/config/unified-config-types.js +75 -0
- package/dist/config/unified-config-types.js.map +1 -0
- package/dist/utils/sensitive-keys.d.ts +35 -0
- package/dist/utils/sensitive-keys.d.ts.map +1 -0
- package/dist/utils/sensitive-keys.js +67 -0
- package/dist/utils/sensitive-keys.js.map +1 -0
- package/dist/utils/update-checker.d.ts.map +1 -1
- package/dist/utils/update-checker.js +4 -4
- package/dist/utils/update-checker.js.map +1 -1
- package/dist/web-server/routes.d.ts.map +1 -1
- package/dist/web-server/routes.js +100 -14
- package/dist/web-server/routes.js.map +1 -1
- package/dist/web-server/usage-disk-cache.d.ts +1 -1
- package/dist/web-server/usage-disk-cache.d.ts.map +1 -1
- package/dist/web-server/usage-disk-cache.js +8 -7
- package/dist/web-server/usage-disk-cache.js.map +1 -1
- package/package.json +3 -1
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Secrets Manager
|
|
4
|
+
*
|
|
5
|
+
* Handles loading and saving secrets (API keys, tokens) in a separate file
|
|
6
|
+
* with restricted permissions (chmod 600).
|
|
7
|
+
*/
|
|
8
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
9
|
+
if (k2 === undefined) k2 = k;
|
|
10
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
11
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
12
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
13
|
+
}
|
|
14
|
+
Object.defineProperty(o, k2, desc);
|
|
15
|
+
}) : (function(o, m, k, k2) {
|
|
16
|
+
if (k2 === undefined) k2 = k;
|
|
17
|
+
o[k2] = m[k];
|
|
18
|
+
}));
|
|
19
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
20
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
21
|
+
}) : function(o, v) {
|
|
22
|
+
o["default"] = v;
|
|
23
|
+
});
|
|
24
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
25
|
+
if (mod && mod.__esModule) return mod;
|
|
26
|
+
var result = {};
|
|
27
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
28
|
+
__setModuleDefault(result, mod);
|
|
29
|
+
return result;
|
|
30
|
+
};
|
|
31
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
32
|
+
exports.deleteAllProfileSecrets = exports.setProfileSecrets = exports.getProfileSecrets = exports.deleteProfileSecret = exports.setProfileSecret = exports.getProfileSecret = exports.saveSecrets = exports.loadSecrets = exports.hasSecrets = exports.getSecretsPath = exports.isSecretKey = void 0;
|
|
33
|
+
const fs = __importStar(require("fs"));
|
|
34
|
+
const path = __importStar(require("path"));
|
|
35
|
+
const yaml = __importStar(require("js-yaml"));
|
|
36
|
+
const config_manager_1 = require("../utils/config-manager");
|
|
37
|
+
const unified_config_types_1 = require("./unified-config-types");
|
|
38
|
+
// Re-export from shared utility for backward compatibility
|
|
39
|
+
var sensitive_keys_1 = require("../utils/sensitive-keys");
|
|
40
|
+
Object.defineProperty(exports, "isSecretKey", { enumerable: true, get: function () { return sensitive_keys_1.isSensitiveKey; } });
|
|
41
|
+
const SECRETS_FILE = 'secrets.yaml';
|
|
42
|
+
const SECRETS_FILE_MODE = 0o600; // Owner read/write only
|
|
43
|
+
/**
|
|
44
|
+
* Get path to secrets.yaml
|
|
45
|
+
*/
|
|
46
|
+
function getSecretsPath() {
|
|
47
|
+
return path.join((0, config_manager_1.getCcsDir)(), SECRETS_FILE);
|
|
48
|
+
}
|
|
49
|
+
exports.getSecretsPath = getSecretsPath;
|
|
50
|
+
/**
|
|
51
|
+
* Check if secrets.yaml exists
|
|
52
|
+
*/
|
|
53
|
+
function hasSecrets() {
|
|
54
|
+
return fs.existsSync(getSecretsPath());
|
|
55
|
+
}
|
|
56
|
+
exports.hasSecrets = hasSecrets;
|
|
57
|
+
/**
|
|
58
|
+
* Load secrets from YAML file.
|
|
59
|
+
* Returns empty secrets config if file doesn't exist.
|
|
60
|
+
*/
|
|
61
|
+
function loadSecrets() {
|
|
62
|
+
const secretsPath = getSecretsPath();
|
|
63
|
+
if (!fs.existsSync(secretsPath)) {
|
|
64
|
+
return (0, unified_config_types_1.createEmptySecretsConfig)();
|
|
65
|
+
}
|
|
66
|
+
try {
|
|
67
|
+
const content = fs.readFileSync(secretsPath, 'utf8');
|
|
68
|
+
const parsed = yaml.load(content);
|
|
69
|
+
if (!(0, unified_config_types_1.isSecretsConfig)(parsed)) {
|
|
70
|
+
console.error(`[!] Invalid secrets format in ${secretsPath}`);
|
|
71
|
+
return (0, unified_config_types_1.createEmptySecretsConfig)();
|
|
72
|
+
}
|
|
73
|
+
return parsed;
|
|
74
|
+
}
|
|
75
|
+
catch (err) {
|
|
76
|
+
const error = err instanceof Error ? err.message : 'Unknown error';
|
|
77
|
+
console.error(`[X] Failed to load secrets: ${error}`);
|
|
78
|
+
return (0, unified_config_types_1.createEmptySecretsConfig)();
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
exports.loadSecrets = loadSecrets;
|
|
82
|
+
/**
|
|
83
|
+
* Save secrets to YAML file with restricted permissions.
|
|
84
|
+
* Uses atomic write (temp file + rename) to prevent corruption.
|
|
85
|
+
*/
|
|
86
|
+
function saveSecrets(secrets) {
|
|
87
|
+
const secretsPath = getSecretsPath();
|
|
88
|
+
const dir = path.dirname(secretsPath);
|
|
89
|
+
// Ensure directory exists
|
|
90
|
+
if (!fs.existsSync(dir)) {
|
|
91
|
+
fs.mkdirSync(dir, { recursive: true, mode: 0o700 });
|
|
92
|
+
}
|
|
93
|
+
// Convert to YAML
|
|
94
|
+
const content = yaml.dump(secrets, {
|
|
95
|
+
indent: 2,
|
|
96
|
+
lineWidth: -1,
|
|
97
|
+
quotingType: '"',
|
|
98
|
+
noRefs: true,
|
|
99
|
+
});
|
|
100
|
+
// Atomic write: write to temp file, then rename
|
|
101
|
+
const tempPath = `${secretsPath}.tmp.${process.pid}`;
|
|
102
|
+
try {
|
|
103
|
+
fs.writeFileSync(tempPath, content, { mode: SECRETS_FILE_MODE });
|
|
104
|
+
fs.renameSync(tempPath, secretsPath);
|
|
105
|
+
// Ensure correct permissions after rename (some systems may not preserve)
|
|
106
|
+
fs.chmodSync(secretsPath, SECRETS_FILE_MODE);
|
|
107
|
+
}
|
|
108
|
+
catch (err) {
|
|
109
|
+
// Clean up temp file on error
|
|
110
|
+
if (fs.existsSync(tempPath)) {
|
|
111
|
+
try {
|
|
112
|
+
fs.unlinkSync(tempPath);
|
|
113
|
+
}
|
|
114
|
+
catch {
|
|
115
|
+
// Ignore cleanup errors
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
throw err;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
exports.saveSecrets = saveSecrets;
|
|
122
|
+
/**
|
|
123
|
+
* Get a secret value for a specific profile.
|
|
124
|
+
*/
|
|
125
|
+
function getProfileSecret(profileName, key) {
|
|
126
|
+
const secrets = loadSecrets();
|
|
127
|
+
return secrets.profiles[profileName]?.[key];
|
|
128
|
+
}
|
|
129
|
+
exports.getProfileSecret = getProfileSecret;
|
|
130
|
+
/**
|
|
131
|
+
* Set a secret value for a specific profile.
|
|
132
|
+
*/
|
|
133
|
+
function setProfileSecret(profileName, key, value) {
|
|
134
|
+
const secrets = loadSecrets();
|
|
135
|
+
if (!secrets.profiles[profileName]) {
|
|
136
|
+
secrets.profiles[profileName] = {};
|
|
137
|
+
}
|
|
138
|
+
secrets.profiles[profileName][key] = value;
|
|
139
|
+
saveSecrets(secrets);
|
|
140
|
+
}
|
|
141
|
+
exports.setProfileSecret = setProfileSecret;
|
|
142
|
+
/**
|
|
143
|
+
* Delete a secret value for a specific profile.
|
|
144
|
+
*/
|
|
145
|
+
function deleteProfileSecret(profileName, key) {
|
|
146
|
+
const secrets = loadSecrets();
|
|
147
|
+
if (!secrets.profiles[profileName]?.[key]) {
|
|
148
|
+
return false;
|
|
149
|
+
}
|
|
150
|
+
delete secrets.profiles[profileName][key];
|
|
151
|
+
// Clean up empty profile object
|
|
152
|
+
if (Object.keys(secrets.profiles[profileName]).length === 0) {
|
|
153
|
+
delete secrets.profiles[profileName];
|
|
154
|
+
}
|
|
155
|
+
saveSecrets(secrets);
|
|
156
|
+
return true;
|
|
157
|
+
}
|
|
158
|
+
exports.deleteProfileSecret = deleteProfileSecret;
|
|
159
|
+
/**
|
|
160
|
+
* Get all secrets for a profile.
|
|
161
|
+
*/
|
|
162
|
+
function getProfileSecrets(profileName) {
|
|
163
|
+
const secrets = loadSecrets();
|
|
164
|
+
return secrets.profiles[profileName] || {};
|
|
165
|
+
}
|
|
166
|
+
exports.getProfileSecrets = getProfileSecrets;
|
|
167
|
+
/**
|
|
168
|
+
* Set all secrets for a profile (replaces existing).
|
|
169
|
+
*/
|
|
170
|
+
function setProfileSecrets(profileName, profileSecrets) {
|
|
171
|
+
const secrets = loadSecrets();
|
|
172
|
+
if (Object.keys(profileSecrets).length === 0) {
|
|
173
|
+
delete secrets.profiles[profileName];
|
|
174
|
+
}
|
|
175
|
+
else {
|
|
176
|
+
secrets.profiles[profileName] = profileSecrets;
|
|
177
|
+
}
|
|
178
|
+
saveSecrets(secrets);
|
|
179
|
+
}
|
|
180
|
+
exports.setProfileSecrets = setProfileSecrets;
|
|
181
|
+
/**
|
|
182
|
+
* Delete all secrets for a profile.
|
|
183
|
+
*/
|
|
184
|
+
function deleteAllProfileSecrets(profileName) {
|
|
185
|
+
const secrets = loadSecrets();
|
|
186
|
+
if (!secrets.profiles[profileName]) {
|
|
187
|
+
return false;
|
|
188
|
+
}
|
|
189
|
+
delete secrets.profiles[profileName];
|
|
190
|
+
saveSecrets(secrets);
|
|
191
|
+
return true;
|
|
192
|
+
}
|
|
193
|
+
exports.deleteAllProfileSecrets = deleteAllProfileSecrets;
|
|
194
|
+
//# sourceMappingURL=secrets-manager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"secrets-manager.js","sourceRoot":"","sources":["../../src/config/secrets-manager.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,uCAAyB;AACzB,2CAA6B;AAC7B,8CAAgC;AAChC,4DAAoD;AACpD,iEAAkG;AAElG,2DAA2D;AAC3D,0DAAwE;AAA/D,6GAAA,cAAc,OAAe;AAEtC,MAAM,YAAY,GAAG,cAAc,CAAC;AACpC,MAAM,iBAAiB,GAAG,KAAK,CAAC,CAAC,wBAAwB;AAEzD;;GAEG;AACH,SAAgB,cAAc;IAC5B,OAAO,IAAI,CAAC,IAAI,CAAC,IAAA,0BAAS,GAAE,EAAE,Y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AM,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC7C,OAAO,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC;IACvC,CAAC;SAAM,CAAC;QACN,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAC,GAAG,cAAc,CAAC;IACjD,CAAC;IAED,WAAW,CAAC,OAAO,CAAC,CAAC;AACvB,CAAC;AAbD,8CAaC;AAED;;GAEG;AACH,SAAgB,uBAAuB,CAAC,WAAmB;IACzD,MAAM,OAAO,GAAG,WAAW,EAAE,CAAC;IAE9B,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAC,EAAE,CAAC;QACnC,OAAO,KAAK,CAAC;IACf,CAAC;IAED,OAAO,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC;IACrC,WAAW,CAAC,OAAO,CAAC,CAAC;IACrB,OAAO,IAAI,CAAC;AACd,CAAC;AAVD,0DAUC"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Unified Config Loader
|
|
3
|
+
*
|
|
4
|
+
* Loads and saves the unified YAML configuration.
|
|
5
|
+
* Provides fallback to legacy JSON format for backward compatibility.
|
|
6
|
+
*/
|
|
7
|
+
import { UnifiedConfig } from './unified-config-types';
|
|
8
|
+
/**
|
|
9
|
+
* Get path to unified config.yaml
|
|
10
|
+
*/
|
|
11
|
+
export declare function getConfigYamlPath(): string;
|
|
12
|
+
/**
|
|
13
|
+
* Get path to legacy config.json
|
|
14
|
+
*/
|
|
15
|
+
export declare function getConfigJsonPath(): string;
|
|
16
|
+
/**
|
|
17
|
+
* Check if unified config.yaml exists
|
|
18
|
+
*/
|
|
19
|
+
export declare function hasUnifiedConfig(): boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Check if legacy config.json exists
|
|
22
|
+
*/
|
|
23
|
+
export declare function hasLegacyConfig(): boolean;
|
|
24
|
+
/**
|
|
25
|
+
* Determine which config format is active.
|
|
26
|
+
* Returns 'yaml' if unified config exists or is enabled,
|
|
27
|
+
* 'json' if only legacy config exists,
|
|
28
|
+
* 'none' if no config exists.
|
|
29
|
+
*/
|
|
30
|
+
export declare function getConfigFormat(): 'yaml' | 'json' | 'none';
|
|
31
|
+
/**
|
|
32
|
+
* Load unified config from YAML file.
|
|
33
|
+
* Returns null if file doesn't exist or format check fails.
|
|
34
|
+
*/
|
|
35
|
+
export declare function loadUnifiedConfig(): UnifiedConfig | null;
|
|
36
|
+
/**
|
|
37
|
+
* Load config, preferring YAML if available, falling back to creating empty config.
|
|
38
|
+
*/
|
|
39
|
+
export declare function loadOrCreateUnifiedConfig(): UnifiedConfig;
|
|
40
|
+
/**
|
|
41
|
+
* Save unified config to YAML file.
|
|
42
|
+
* Uses atomic write (temp file + rename) to prevent corruption.
|
|
43
|
+
*/
|
|
44
|
+
export declare function saveUnifiedConfig(config: UnifiedConfig): void;
|
|
45
|
+
/**
|
|
46
|
+
* Update unified config with partial data.
|
|
47
|
+
* Loads existing config, merges changes, and saves.
|
|
48
|
+
*/
|
|
49
|
+
export declare function updateUnifiedConfig(updates: Partial<UnifiedConfig>): UnifiedConfig;
|
|
50
|
+
/**
|
|
51
|
+
* Get or set default profile name.
|
|
52
|
+
*/
|
|
53
|
+
export declare function getDefaultProfile(): string | undefined;
|
|
54
|
+
export declare function setDefaultProfile(name: string): void;
|
|
55
|
+
//# sourceMappingURL=unified-config-loader.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"unified-config-loader.d.ts","sourceRoot":"","sources":["../../src/config/unified-config-loader.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAMH,OAAO,EACL,aAAa,EAId,MAAM,wBAAwB,CAAC;AAMhC;;GAEG;AACH,wBAAgB,iBAAiB,IAAI,MAAM,CAE1C;AAED;;GAEG;AACH,wBAAgB,iBAAiB,IAAI,MAAM,CAE1C;AAED;;GAEG;AACH,wBAAgB,gBAAgB,IAAI,OAAO,CAE1C;AAED;;GAEG;AACH,wBAAgB,eAAe,IAAI,OAAO,CAEzC;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,IAAI,MAAM,GAAG,MAAM,GAAG,MAAM,CAK1D;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,IAAI,aAAa,GAAG,IAAI,CAuBxD;AAED;;GAEG;AACH,wBAAgB,yBAAyB,IAAI,aAAa,CAOzD;AAmGD;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,aAAa,GAAG,IAAI,CAiC7D;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,OAAO,CAAC,aAAa,CAAC,GAAG,aAAa,CAKlF;AAED;;GAEG;AACH,wBAAgB,iBAAiB,IAAI,MAAM,GAAG,SAAS,CAGtD;AAED,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAEpD"}
|
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Unified Config Loader
|
|
4
|
+
*
|
|
5
|
+
* Loads and saves the unified YAML configuration.
|
|
6
|
+
* Provides fallback to legacy JSON format for backward compatibility.
|
|
7
|
+
*/
|
|
8
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
9
|
+
if (k2 === undefined) k2 = k;
|
|
10
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
11
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
12
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
13
|
+
}
|
|
14
|
+
Object.defineProperty(o, k2, desc);
|
|
15
|
+
}) : (function(o, m, k, k2) {
|
|
16
|
+
if (k2 === undefined) k2 = k;
|
|
17
|
+
o[k2] = m[k];
|
|
18
|
+
}));
|
|
19
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
20
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
21
|
+
}) : function(o, v) {
|
|
22
|
+
o["default"] = v;
|
|
23
|
+
});
|
|
24
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
25
|
+
if (mod && mod.__esModule) return mod;
|
|
26
|
+
var result = {};
|
|
27
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
28
|
+
__setModuleDefault(result, mod);
|
|
29
|
+
return result;
|
|
30
|
+
};
|
|
31
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
32
|
+
exports.setDefaultProfile = exports.getDefaultProfile = exports.updateUnifiedConfig = exports.saveUnifiedConfig = exports.loadOrCreateUnifiedConfig = exports.loadUnifiedConfig = exports.getConfigFormat = exports.hasLegacyConfig = exports.hasUnifiedConfig = exports.getConfigJsonPath = exports.getConfigYamlPath = void 0;
|
|
33
|
+
const fs = __importStar(require("fs"));
|
|
34
|
+
const path = __importStar(require("path"));
|
|
35
|
+
const yaml = __importStar(require("js-yaml"));
|
|
36
|
+
const config_manager_1 = require("../utils/config-manager");
|
|
37
|
+
const unified_config_types_1 = require("./unified-config-types");
|
|
38
|
+
const feature_flags_1 = require("./feature-flags");
|
|
39
|
+
const CONFIG_YAML = 'config.yaml';
|
|
40
|
+
const CONFIG_JSON = 'config.json';
|
|
41
|
+
/**
|
|
42
|
+
* Get path to unified config.yaml
|
|
43
|
+
*/
|
|
44
|
+
function getConfigYamlPath() {
|
|
45
|
+
return path.join((0, config_manager_1.getCcsDir)(), CONFIG_YAML);
|
|
46
|
+
}
|
|
47
|
+
exports.getConfigYamlPath = getConfigYamlPath;
|
|
48
|
+
/**
|
|
49
|
+
* Get path to legacy config.json
|
|
50
|
+
*/
|
|
51
|
+
function getConfigJsonPath() {
|
|
52
|
+
return path.join((0, config_manager_1.getCcsDir)(), CONFIG_JSON);
|
|
53
|
+
}
|
|
54
|
+
exports.getConfigJsonPath = getConfigJsonPath;
|
|
55
|
+
/**
|
|
56
|
+
* Check if unified config.yaml exists
|
|
57
|
+
*/
|
|
58
|
+
function hasUnifiedConfig() {
|
|
59
|
+
return fs.existsSync(getConfigYamlPath());
|
|
60
|
+
}
|
|
61
|
+
exports.hasUnifiedConfig = hasUnifiedConfig;
|
|
62
|
+
/**
|
|
63
|
+
* Check if legacy config.json exists
|
|
64
|
+
*/
|
|
65
|
+
function hasLegacyConfig() {
|
|
66
|
+
return fs.existsSync(getConfigJsonPath());
|
|
67
|
+
}
|
|
68
|
+
exports.hasLegacyConfig = hasLegacyConfig;
|
|
69
|
+
/**
|
|
70
|
+
* Determine which config format is active.
|
|
71
|
+
* Returns 'yaml' if unified config exists or is enabled,
|
|
72
|
+
* 'json' if only legacy config exists,
|
|
73
|
+
* 'none' if no config exists.
|
|
74
|
+
*/
|
|
75
|
+
function getConfigFormat() {
|
|
76
|
+
if (hasUnifiedConfig())
|
|
77
|
+
return 'yaml';
|
|
78
|
+
if ((0, feature_flags_1.isUnifiedConfigEnabled)())
|
|
79
|
+
return 'yaml';
|
|
80
|
+
if (hasLegacyConfig())
|
|
81
|
+
return 'json';
|
|
82
|
+
return 'none';
|
|
83
|
+
}
|
|
84
|
+
exports.getConfigFormat = getConfigFormat;
|
|
85
|
+
/**
|
|
86
|
+
* Load unified config from YAML file.
|
|
87
|
+
* Returns null if file doesn't exist or format check fails.
|
|
88
|
+
*/
|
|
89
|
+
function loadUnifiedConfig() {
|
|
90
|
+
const yamlPath = getConfigYamlPath();
|
|
91
|
+
// If file doesn't exist, return null
|
|
92
|
+
if (!fs.existsSync(yamlPath)) {
|
|
93
|
+
return null;
|
|
94
|
+
}
|
|
95
|
+
try {
|
|
96
|
+
const content = fs.readFileSync(yamlPath, 'utf8');
|
|
97
|
+
const parsed = yaml.load(content);
|
|
98
|
+
if (!(0, unified_config_types_1.isUnifiedConfig)(parsed)) {
|
|
99
|
+
console.error(`[!] Invalid config format in ${yamlPath}`);
|
|
100
|
+
return null;
|
|
101
|
+
}
|
|
102
|
+
return parsed;
|
|
103
|
+
}
|
|
104
|
+
catch (err) {
|
|
105
|
+
const error = err instanceof Error ? err.message : 'Unknown error';
|
|
106
|
+
console.error(`[X] Failed to load config: ${error}`);
|
|
107
|
+
return null;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
exports.loadUnifiedConfig = loadUnifiedConfig;
|
|
111
|
+
/**
|
|
112
|
+
* Load config, preferring YAML if available, falling back to creating empty config.
|
|
113
|
+
*/
|
|
114
|
+
function loadOrCreateUnifiedConfig() {
|
|
115
|
+
const existing = loadUnifiedConfig();
|
|
116
|
+
if (existing)
|
|
117
|
+
return existing;
|
|
118
|
+
// Create empty config
|
|
119
|
+
const config = (0, unified_config_types_1.createEmptyUnifiedConfig)();
|
|
120
|
+
return config;
|
|
121
|
+
}
|
|
122
|
+
exports.loadOrCreateUnifiedConfig = loadOrCreateUnifiedConfig;
|
|
123
|
+
/**
|
|
124
|
+
* Generate YAML header with helpful comments.
|
|
125
|
+
*/
|
|
126
|
+
function generateYamlHeader() {
|
|
127
|
+
return `# ============================================================================
|
|
128
|
+
# CCS Unified Configuration (config.yaml)
|
|
129
|
+
# ============================================================================
|
|
130
|
+
# Generated by: ccs migrate
|
|
131
|
+
# Documentation: https://github.com/kaitranntt/ccs
|
|
132
|
+
#
|
|
133
|
+
# This file references your settings - actual env vars are in *.settings.json
|
|
134
|
+
# files (matching Claude's ~/.claude/settings.json pattern).
|
|
135
|
+
#
|
|
136
|
+
# To customize a profile:
|
|
137
|
+
# 1. Edit the *.settings.json file directly (e.g., ~/.ccs/glm.settings.json)
|
|
138
|
+
# 2. The file format matches Claude's settings.json: { "env": { ... } }
|
|
139
|
+
#
|
|
140
|
+
# Structure:
|
|
141
|
+
# ┌─────────────────────────────────────────────────────────────────────────────┐
|
|
142
|
+
# │ profiles - References to *.settings.json files for API providers │
|
|
143
|
+
# │ cliproxy - References to *.settings.json files for OAuth providers │
|
|
144
|
+
# │ accounts - Isolated Claude instances (managed by 'ccs auth') │
|
|
145
|
+
# │ preferences - User preferences (theme, telemetry, auto-update) │
|
|
146
|
+
# └─────────────────────────────────────────────────────────────────────────────┘
|
|
147
|
+
#
|
|
148
|
+
# Usage:
|
|
149
|
+
# ccs <profile> Switch to profile
|
|
150
|
+
# ccs api add <name> Add new API profile
|
|
151
|
+
# ccs cliproxy create Create CLIProxy variant
|
|
152
|
+
# ccs migrate --rollback Restore from backup
|
|
153
|
+
#
|
|
154
|
+
`;
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Generate YAML content with section comments for better readability.
|
|
158
|
+
*/
|
|
159
|
+
function generateYamlWithComments(config) {
|
|
160
|
+
const lines = [];
|
|
161
|
+
// Version
|
|
162
|
+
lines.push(`version: ${config.version}`);
|
|
163
|
+
lines.push('');
|
|
164
|
+
// Default
|
|
165
|
+
if (config.default) {
|
|
166
|
+
lines.push(`# Default profile used when running 'ccs' without arguments`);
|
|
167
|
+
lines.push(`default: "${config.default}"`);
|
|
168
|
+
lines.push('');
|
|
169
|
+
}
|
|
170
|
+
// Accounts section
|
|
171
|
+
lines.push('# ----------------------------------------------------------------------------');
|
|
172
|
+
lines.push('# Accounts: Isolated Claude instances (each with separate auth/sessions)');
|
|
173
|
+
lines.push('# Manage with: ccs auth add <name>, ccs auth list, ccs auth remove <name>');
|
|
174
|
+
lines.push('# ----------------------------------------------------------------------------');
|
|
175
|
+
lines.push(yaml.dump({ accounts: config.accounts }, { indent: 2, lineWidth: -1, quotingType: '"' }).trim());
|
|
176
|
+
lines.push('');
|
|
177
|
+
// Profiles section
|
|
178
|
+
lines.push('# ----------------------------------------------------------------------------');
|
|
179
|
+
lines.push('# Profiles: API-based providers (GLM, GLMT, Kimi, custom endpoints)');
|
|
180
|
+
lines.push('# Each profile points to a *.settings.json file containing env vars.');
|
|
181
|
+
lines.push('# Edit the settings file directly to customize (ANTHROPIC_MAX_TOKENS, etc.)');
|
|
182
|
+
lines.push('# ----------------------------------------------------------------------------');
|
|
183
|
+
lines.push(yaml.dump({ profiles: config.profiles }, { indent: 2, lineWidth: -1, quotingType: '"' }).trim());
|
|
184
|
+
lines.push('');
|
|
185
|
+
// CLIProxy section
|
|
186
|
+
lines.push('# ----------------------------------------------------------------------------');
|
|
187
|
+
lines.push('# CLIProxy: OAuth-based providers (gemini, codex, agy, qwen, iflow)');
|
|
188
|
+
lines.push('# Each variant can reference a *.settings.json file for custom env vars.');
|
|
189
|
+
lines.push('# Edit the settings file directly to customize model or other settings.');
|
|
190
|
+
lines.push('# ----------------------------------------------------------------------------');
|
|
191
|
+
lines.push(yaml.dump({ cliproxy: config.cliproxy }, { indent: 2, lineWidth: -1, quotingType: '"' }).trim());
|
|
192
|
+
lines.push('');
|
|
193
|
+
// Preferences section
|
|
194
|
+
lines.push('# ----------------------------------------------------------------------------');
|
|
195
|
+
lines.push('# Preferences: User settings');
|
|
196
|
+
lines.push('# ----------------------------------------------------------------------------');
|
|
197
|
+
lines.push(yaml
|
|
198
|
+
.dump({ preferences: config.preferences }, { indent: 2, lineWidth: -1, quotingType: '"' })
|
|
199
|
+
.trim());
|
|
200
|
+
lines.push('');
|
|
201
|
+
return lines.join('\n');
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Save unified config to YAML file.
|
|
205
|
+
* Uses atomic write (temp file + rename) to prevent corruption.
|
|
206
|
+
*/
|
|
207
|
+
function saveUnifiedConfig(config) {
|
|
208
|
+
const yamlPath = getConfigYamlPath();
|
|
209
|
+
const dir = path.dirname(yamlPath);
|
|
210
|
+
// Ensure directory exists
|
|
211
|
+
if (!fs.existsSync(dir)) {
|
|
212
|
+
fs.mkdirSync(dir, { recursive: true, mode: 0o700 });
|
|
213
|
+
}
|
|
214
|
+
// Ensure version is set
|
|
215
|
+
config.version = unified_config_types_1.UNIFIED_CONFIG_VERSION;
|
|
216
|
+
// Generate YAML with section comments
|
|
217
|
+
const yamlContent = generateYamlWithComments(config);
|
|
218
|
+
const content = generateYamlHeader() + yamlContent;
|
|
219
|
+
// Atomic write: write to temp file, then rename
|
|
220
|
+
const tempPath = `${yamlPath}.tmp.${process.pid}`;
|
|
221
|
+
try {
|
|
222
|
+
fs.writeFileSync(tempPath, content, { mode: 0o600 });
|
|
223
|
+
fs.renameSync(tempPath, yamlPath);
|
|
224
|
+
}
|
|
225
|
+
catch (err) {
|
|
226
|
+
// Clean up temp file on error
|
|
227
|
+
if (fs.existsSync(tempPath)) {
|
|
228
|
+
try {
|
|
229
|
+
fs.unlinkSync(tempPath);
|
|
230
|
+
}
|
|
231
|
+
catch {
|
|
232
|
+
// Ignore cleanup errors
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
throw err;
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
exports.saveUnifiedConfig = saveUnifiedConfig;
|
|
239
|
+
/**
|
|
240
|
+
* Update unified config with partial data.
|
|
241
|
+
* Loads existing config, merges changes, and saves.
|
|
242
|
+
*/
|
|
243
|
+
function updateUnifiedConfig(updates) {
|
|
244
|
+
const config = loadOrCreateUnifiedConfig();
|
|
245
|
+
const updated = { ...config, ...updates };
|
|
246
|
+
saveUnifiedConfig(updated);
|
|
247
|
+
return updated;
|
|
248
|
+
}
|
|
249
|
+
exports.updateUnifiedConfig = updateUnifiedConfig;
|
|
250
|
+
/**
|
|
251
|
+
* Get or set default profile name.
|
|
252
|
+
*/
|
|
253
|
+
function getDefaultProfile() {
|
|
254
|
+
const config = loadUnifiedConfig();
|
|
255
|
+
return config?.default;
|
|
256
|
+
}
|
|
257
|
+
exports.getDefaultProfile = getDefaultProfile;
|
|
258
|
+
function setDefaultProfile(name) {
|
|
259
|
+
updateUnifiedConfig({ default: name });
|
|
260
|
+
}
|
|
261
|
+
exports.setDefaultProfile = setDefaultProfile;
|
|
262
|
+
//# sourceMappingURL=unified-config-loader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"unified-config-loader.js","sourceRoot":"","sources":["../../src/config/unified-config-loader.ts"],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,CAAC;AACzB,CAAC;AAHD,8CAGC;AAED,SAAgB,iBAAiB,CAAC,IAAY;IAC5C,mBAAmB,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC;AACzC,CAAC;AAFD,8CAEC"}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Unified Config Types for CCS v2
|
|
3
|
+
*
|
|
4
|
+
* This file defines the new unified YAML configuration format that consolidates:
|
|
5
|
+
* - config.json (API profiles)
|
|
6
|
+
* - profiles.json (account metadata)
|
|
7
|
+
* - *.settings.json (env vars)
|
|
8
|
+
*
|
|
9
|
+
* Into a single config.yaml + secrets.yaml structure.
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* Unified config version.
|
|
13
|
+
* Version 2 = YAML unified format
|
|
14
|
+
*/
|
|
15
|
+
export declare const UNIFIED_CONFIG_VERSION = 2;
|
|
16
|
+
/**
|
|
17
|
+
* Account configuration (formerly in profiles.json).
|
|
18
|
+
* Represents an isolated Claude instance via CLAUDE_CONFIG_DIR.
|
|
19
|
+
*/
|
|
20
|
+
export interface AccountConfig {
|
|
21
|
+
/** ISO timestamp when account was created */
|
|
22
|
+
created: string;
|
|
23
|
+
/** ISO timestamp of last usage, null if never used */
|
|
24
|
+
last_used: string | null;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* API-based profile configuration.
|
|
28
|
+
* Injects environment variables for alternative providers (GLM, Kimi, etc.).
|
|
29
|
+
*
|
|
30
|
+
* Settings are stored in separate *.settings.json files (matching Claude's pattern)
|
|
31
|
+
* to allow users to edit them directly without touching config.yaml.
|
|
32
|
+
*/
|
|
33
|
+
export interface ProfileConfig {
|
|
34
|
+
/** Profile type - currently only 'api' */
|
|
35
|
+
type: 'api';
|
|
36
|
+
/** Path to settings file (e.g., "~/.ccs/glm.settings.json") */
|
|
37
|
+
settings: string;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* CLIProxy OAuth account nickname mapping.
|
|
41
|
+
* Maps user-friendly nicknames to email addresses.
|
|
42
|
+
*/
|
|
43
|
+
export type OAuthAccounts = Record<string, string>;
|
|
44
|
+
/**
|
|
45
|
+
* CLIProxy variant configuration.
|
|
46
|
+
* User-defined variants of built-in OAuth providers.
|
|
47
|
+
*
|
|
48
|
+
* Settings are stored in separate *.settings.json files (matching Claude's pattern)
|
|
49
|
+
* to allow users to edit them directly without touching config.yaml.
|
|
50
|
+
*/
|
|
51
|
+
export interface CLIProxyVariantConfig {
|
|
52
|
+
/** Base provider to use */
|
|
53
|
+
provider: 'gemini' | 'codex' | 'agy' | 'qwen' | 'iflow';
|
|
54
|
+
/** Account nickname (references oauth_accounts) */
|
|
55
|
+
account?: string;
|
|
56
|
+
/** Path to settings file (e.g., "~/.ccs/gemini-custom.settings.json") */
|
|
57
|
+
settings?: string;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* CLIProxy configuration section.
|
|
61
|
+
*/
|
|
62
|
+
export interface CLIProxyConfig {
|
|
63
|
+
/** Nickname to email mapping for OAuth accounts */
|
|
64
|
+
oauth_accounts: OAuthAccounts;
|
|
65
|
+
/** Built-in providers (read-only, for reference) */
|
|
66
|
+
providers: readonly string[];
|
|
67
|
+
/** User-defined provider variants */
|
|
68
|
+
variants: Record<string, CLIProxyVariantConfig>;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* User preferences.
|
|
72
|
+
*/
|
|
73
|
+
export interface PreferencesConfig {
|
|
74
|
+
/** UI theme preference */
|
|
75
|
+
theme?: 'light' | 'dark' | 'system';
|
|
76
|
+
/** Enable anonymous telemetry */
|
|
77
|
+
telemetry?: boolean;
|
|
78
|
+
/** Enable automatic update checks */
|
|
79
|
+
auto_update?: boolean;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Main unified configuration structure.
|
|
83
|
+
* Stored in ~/.ccs/config.yaml
|
|
84
|
+
*/
|
|
85
|
+
export interface UnifiedConfig {
|
|
86
|
+
/** Config version (2 for unified format) */
|
|
87
|
+
version: number;
|
|
88
|
+
/** Default profile name to use when none specified */
|
|
89
|
+
default?: string;
|
|
90
|
+
/** Account-based profiles (isolated Claude instances) */
|
|
91
|
+
accounts: Record<string, AccountConfig>;
|
|
92
|
+
/** API-based profiles (env var injection) */
|
|
93
|
+
profiles: Record<string, ProfileConfig>;
|
|
94
|
+
/** CLIProxy configuration */
|
|
95
|
+
cliproxy: CLIProxyConfig;
|
|
96
|
+
/** User preferences */
|
|
97
|
+
preferences: PreferencesConfig;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Secrets configuration structure.
|
|
101
|
+
* Stored in ~/.ccs/secrets.yaml with chmod 600.
|
|
102
|
+
* Contains sensitive values like API keys.
|
|
103
|
+
*/
|
|
104
|
+
export interface SecretsConfig {
|
|
105
|
+
/** Secrets version */
|
|
106
|
+
version: number;
|
|
107
|
+
/** Profile secrets mapping: profile_name -> { key: value } */
|
|
108
|
+
profiles: Record<string, Record<string, string>>;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Create an empty unified config with defaults.
|
|
112
|
+
*/
|
|
113
|
+
export declare function createEmptyUnifiedConfig(): UnifiedConfig;
|
|
114
|
+
/**
|
|
115
|
+
* Create an empty secrets config.
|
|
116
|
+
*/
|
|
117
|
+
export declare function createEmptySecretsConfig(): SecretsConfig;
|
|
118
|
+
/**
|
|
119
|
+
* Type guard for UnifiedConfig.
|
|
120
|
+
*/
|
|
121
|
+
export declare function isUnifiedConfig(obj: unknown): obj is UnifiedConfig;
|
|
122
|
+
/**
|
|
123
|
+
* Type guard for SecretsConfig.
|
|
124
|
+
*/
|
|
125
|
+
export declare function isSecretsConfig(obj: unknown): obj is SecretsConfig;
|
|
126
|
+
//# sourceMappingURL=unified-config-types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"unified-config-types.d.ts","sourceRoot":"","sources":["../../src/config/unified-config-types.ts"],"names":[],"mappings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