@eruoxi/csm-test 0.0.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/LICENSE +21 -0
- package/README.md +217 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +43 -0
- package/dist/cli.js.map +1 -0
- package/dist/commands/backup.d.ts +3 -0
- package/dist/commands/backup.d.ts.map +1 -0
- package/dist/commands/backup.js +99 -0
- package/dist/commands/backup.js.map +1 -0
- package/dist/commands/backups.d.ts +3 -0
- package/dist/commands/backups.d.ts.map +1 -0
- package/dist/commands/backups.js +109 -0
- package/dist/commands/backups.js.map +1 -0
- package/dist/commands/copy.d.ts +3 -0
- package/dist/commands/copy.d.ts.map +1 -0
- package/dist/commands/copy.js +36 -0
- package/dist/commands/copy.js.map +1 -0
- package/dist/commands/create.d.ts +3 -0
- package/dist/commands/create.d.ts.map +1 -0
- package/dist/commands/create.js +102 -0
- package/dist/commands/create.js.map +1 -0
- package/dist/commands/current.d.ts +3 -0
- package/dist/commands/current.d.ts.map +1 -0
- package/dist/commands/current.js +45 -0
- package/dist/commands/current.js.map +1 -0
- package/dist/commands/delete.d.ts +3 -0
- package/dist/commands/delete.d.ts.map +1 -0
- package/dist/commands/delete.js +111 -0
- package/dist/commands/delete.js.map +1 -0
- package/dist/commands/edit.d.ts +3 -0
- package/dist/commands/edit.d.ts.map +1 -0
- package/dist/commands/edit.js +86 -0
- package/dist/commands/edit.js.map +1 -0
- package/dist/commands/export.d.ts +3 -0
- package/dist/commands/export.d.ts.map +1 -0
- package/dist/commands/export.js +43 -0
- package/dist/commands/export.js.map +1 -0
- package/dist/commands/import.d.ts +3 -0
- package/dist/commands/import.d.ts.map +1 -0
- package/dist/commands/import.js +74 -0
- package/dist/commands/import.js.map +1 -0
- package/dist/commands/index.d.ts +7 -0
- package/dist/commands/index.d.ts.map +1 -0
- package/dist/commands/index.js +13 -0
- package/dist/commands/index.js.map +1 -0
- package/dist/commands/list.d.ts +3 -0
- package/dist/commands/list.d.ts.map +1 -0
- package/dist/commands/list.js +66 -0
- package/dist/commands/list.js.map +1 -0
- package/dist/commands/rename.d.ts +3 -0
- package/dist/commands/rename.d.ts.map +1 -0
- package/dist/commands/rename.js +30 -0
- package/dist/commands/rename.js.map +1 -0
- package/dist/commands/restore.d.ts +3 -0
- package/dist/commands/restore.d.ts.map +1 -0
- package/dist/commands/restore.js +184 -0
- package/dist/commands/restore.js.map +1 -0
- package/dist/commands/show.d.ts +3 -0
- package/dist/commands/show.d.ts.map +1 -0
- package/dist/commands/show.js +24 -0
- package/dist/commands/show.js.map +1 -0
- package/dist/commands/use.d.ts +3 -0
- package/dist/commands/use.d.ts.map +1 -0
- package/dist/commands/use.js +234 -0
- package/dist/commands/use.js.map +1 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +37 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/merge.d.ts +20 -0
- package/dist/lib/merge.d.ts.map +1 -0
- package/dist/lib/merge.js +146 -0
- package/dist/lib/merge.js.map +1 -0
- package/dist/lib/profile.d.ts +65 -0
- package/dist/lib/profile.d.ts.map +1 -0
- package/dist/lib/profile.js +158 -0
- package/dist/lib/profile.js.map +1 -0
- package/dist/lib/settings.d.ts +72 -0
- package/dist/lib/settings.d.ts.map +1 -0
- package/dist/lib/settings.js +270 -0
- package/dist/lib/settings.js.map +1 -0
- package/dist/lib/state.d.ts +55 -0
- package/dist/lib/state.d.ts.map +1 -0
- package/dist/lib/state.js +145 -0
- package/dist/lib/state.js.map +1 -0
- package/dist/types/index.d.ts +37 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +6 -0
- package/dist/types/index.js.map +1 -0
- package/dist/utils/atomicWrite.d.ts +24 -0
- package/dist/utils/atomicWrite.d.ts.map +1 -0
- package/dist/utils/atomicWrite.js +67 -0
- package/dist/utils/atomicWrite.js.map +1 -0
- package/dist/utils/backupValidator.d.ts +32 -0
- package/dist/utils/backupValidator.d.ts.map +1 -0
- package/dist/utils/backupValidator.js +144 -0
- package/dist/utils/backupValidator.js.map +1 -0
- package/dist/utils/errors.d.ts +63 -0
- package/dist/utils/errors.d.ts.map +1 -0
- package/dist/utils/errors.js +117 -0
- package/dist/utils/errors.js.map +1 -0
- package/dist/utils/file.d.ts +8 -0
- package/dist/utils/file.d.ts.map +1 -0
- package/dist/utils/file.js +54 -0
- package/dist/utils/file.js.map +1 -0
- package/dist/utils/logger.d.ts +6 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +37 -0
- package/dist/utils/logger.js.map +1 -0
- package/dist/utils/normalize.d.ts +13 -0
- package/dist/utils/normalize.d.ts.map +1 -0
- package/dist/utils/normalize.js +31 -0
- package/dist/utils/normalize.js.map +1 -0
- package/dist/utils/validator.d.ts +24 -0
- package/dist/utils/validator.d.ts.map +1 -0
- package/dist/utils/validator.js +178 -0
- package/dist/utils/validator.js.map +1 -0
- package/package.json +69 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* CSM - Claude Code Settings Manager
|
|
4
|
+
* 核心模块导出
|
|
5
|
+
*/
|
|
6
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
7
|
+
if (k2 === undefined) k2 = k;
|
|
8
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
9
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
10
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
11
|
+
}
|
|
12
|
+
Object.defineProperty(o, k2, desc);
|
|
13
|
+
}) : (function(o, m, k, k2) {
|
|
14
|
+
if (k2 === undefined) k2 = k;
|
|
15
|
+
o[k2] = m[k];
|
|
16
|
+
}));
|
|
17
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
18
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
19
|
+
};
|
|
20
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
+
exports.mergeSettings = exports.StateManager = exports.SettingsManager = exports.ProfileManager = void 0;
|
|
22
|
+
// 导出核心库
|
|
23
|
+
var profile_1 = require("./lib/profile");
|
|
24
|
+
Object.defineProperty(exports, "ProfileManager", { enumerable: true, get: function () { return profile_1.ProfileManager; } });
|
|
25
|
+
var settings_1 = require("./lib/settings");
|
|
26
|
+
Object.defineProperty(exports, "SettingsManager", { enumerable: true, get: function () { return settings_1.SettingsManager; } });
|
|
27
|
+
var state_1 = require("./lib/state");
|
|
28
|
+
Object.defineProperty(exports, "StateManager", { enumerable: true, get: function () { return state_1.StateManager; } });
|
|
29
|
+
var merge_1 = require("./lib/merge");
|
|
30
|
+
Object.defineProperty(exports, "mergeSettings", { enumerable: true, get: function () { return merge_1.mergeSettings; } });
|
|
31
|
+
// 导出类型
|
|
32
|
+
__exportStar(require("./types"), exports);
|
|
33
|
+
// 导出工具
|
|
34
|
+
__exportStar(require("./utils/file"), exports);
|
|
35
|
+
__exportStar(require("./utils/logger"), exports);
|
|
36
|
+
__exportStar(require("./utils/validator"), exports);
|
|
37
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;;;;;;;;;;;;AAEH,QAAQ;AACR,yCAA+C;AAAtC,yGAAA,cAAc,OAAA;AACvB,2CAAiD;AAAxC,2GAAA,eAAe,OAAA;AACxB,qCAA2C;AAAlC,qGAAA,YAAY,OAAA;AACrB,qCAA4C;AAAnC,sGAAA,aAAa,OAAA;AAEtB,OAAO;AACP,0CAAwB;AAExB,OAAO;AACP,+CAA6B;AAC7B,iDAA+B;AAC/B,oDAAkC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 配置合并逻辑
|
|
3
|
+
*/
|
|
4
|
+
import type { ClaudeSettings, MergeOptions } from '../types';
|
|
5
|
+
/**
|
|
6
|
+
* Merge settings from current into target based on options
|
|
7
|
+
*
|
|
8
|
+
* @param current - The current settings (source of values to merge)
|
|
9
|
+
* @param target - The target settings (base, takes precedence)
|
|
10
|
+
* @param options - Merge options
|
|
11
|
+
* @returns Merged settings
|
|
12
|
+
*
|
|
13
|
+
* Rules:
|
|
14
|
+
* - When noMerge is true, return target directly (complete replacement)
|
|
15
|
+
* - merge array specifies which fields to deep merge from current into target
|
|
16
|
+
* - keepPermissions adds 'permissions' to the merge list
|
|
17
|
+
* - keepPlugins adds 'enabledPlugins' to the merge list
|
|
18
|
+
*/
|
|
19
|
+
export declare function mergeSettings(current: ClaudeSettings, target: ClaudeSettings, options: MergeOptions): ClaudeSettings;
|
|
20
|
+
//# sourceMappingURL=merge.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"merge.d.ts","sourceRoot":"","sources":["../../src/lib/merge.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AA6F7D;;;;;;;;;;;;;GAaG;AACH,wBAAgB,aAAa,CAC3B,OAAO,EAAE,cAAc,EACvB,MAAM,EAAE,cAAc,EACtB,OAAO,EAAE,YAAY,GACpB,cAAc,CA0DhB"}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* 配置合并逻辑
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.mergeSettings = mergeSettings;
|
|
7
|
+
/**
|
|
8
|
+
* Deep merge two values
|
|
9
|
+
* - Objects are recursively merged
|
|
10
|
+
* - Arrays are replaced (not merged)
|
|
11
|
+
* - Target values take precedence over source values
|
|
12
|
+
*/
|
|
13
|
+
function deepMerge(source, target) {
|
|
14
|
+
// If target is null/undefined, return source
|
|
15
|
+
if (target === null || target === undefined) {
|
|
16
|
+
return source;
|
|
17
|
+
}
|
|
18
|
+
// If source is null/undefined, return target
|
|
19
|
+
if (source === null || source === undefined) {
|
|
20
|
+
return target;
|
|
21
|
+
}
|
|
22
|
+
// If either is not an object, target takes precedence
|
|
23
|
+
if (typeof source !== 'object' || typeof target !== 'object') {
|
|
24
|
+
return target;
|
|
25
|
+
}
|
|
26
|
+
// If either is an array, return target (arrays are replaced, not merged)
|
|
27
|
+
if (Array.isArray(source) || Array.isArray(target)) {
|
|
28
|
+
return target;
|
|
29
|
+
}
|
|
30
|
+
// Both are plain objects - merge them
|
|
31
|
+
const result = { ...source };
|
|
32
|
+
for (const key of Object.keys(target)) {
|
|
33
|
+
const targetValue = target[key];
|
|
34
|
+
const sourceValue = source[key];
|
|
35
|
+
if (targetValue !== undefined) {
|
|
36
|
+
if (sourceValue !== undefined && typeof sourceValue === 'object' && typeof targetValue === 'object') {
|
|
37
|
+
result[key] = deepMerge(sourceValue, targetValue);
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
result[key] = targetValue;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return result;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Merge arrays by combining them and removing duplicates
|
|
48
|
+
* Target values come first, then source's unique values
|
|
49
|
+
*/
|
|
50
|
+
function mergeArrays(source, target) {
|
|
51
|
+
if (!source && !target)
|
|
52
|
+
return [];
|
|
53
|
+
if (!source)
|
|
54
|
+
return target ? [...target] : [];
|
|
55
|
+
if (!target)
|
|
56
|
+
return [...source];
|
|
57
|
+
const result = [...target];
|
|
58
|
+
for (const item of source) {
|
|
59
|
+
if (!result.includes(item)) {
|
|
60
|
+
result.push(item);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return result;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Deep merge for permissions object specifically
|
|
67
|
+
* Handles arrays by combining them (target first, then source's unique values)
|
|
68
|
+
*/
|
|
69
|
+
function deepMergePermissions(source, target) {
|
|
70
|
+
if (!source && !target)
|
|
71
|
+
return undefined;
|
|
72
|
+
if (!source)
|
|
73
|
+
return target;
|
|
74
|
+
if (!target)
|
|
75
|
+
return source;
|
|
76
|
+
const result = {};
|
|
77
|
+
// Merge allow arrays - target values first, then source's unique values
|
|
78
|
+
if (source.allow || target.allow) {
|
|
79
|
+
result.allow = mergeArrays(source.allow, target.allow);
|
|
80
|
+
}
|
|
81
|
+
// Merge deny arrays - target values first, then source's unique values
|
|
82
|
+
if (source.deny || target.deny) {
|
|
83
|
+
result.deny = mergeArrays(source.deny, target.deny);
|
|
84
|
+
}
|
|
85
|
+
return result;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Merge settings from current into target based on options
|
|
89
|
+
*
|
|
90
|
+
* @param current - The current settings (source of values to merge)
|
|
91
|
+
* @param target - The target settings (base, takes precedence)
|
|
92
|
+
* @param options - Merge options
|
|
93
|
+
* @returns Merged settings
|
|
94
|
+
*
|
|
95
|
+
* Rules:
|
|
96
|
+
* - When noMerge is true, return target directly (complete replacement)
|
|
97
|
+
* - merge array specifies which fields to deep merge from current into target
|
|
98
|
+
* - keepPermissions adds 'permissions' to the merge list
|
|
99
|
+
* - keepPlugins adds 'enabledPlugins' to the merge list
|
|
100
|
+
*/
|
|
101
|
+
function mergeSettings(current, target, options) {
|
|
102
|
+
// When noMerge is true, return target directly (complete replacement)
|
|
103
|
+
if (options.noMerge) {
|
|
104
|
+
return { ...target };
|
|
105
|
+
}
|
|
106
|
+
// Build the set of fields to merge
|
|
107
|
+
const fieldsToMerge = new Set();
|
|
108
|
+
// Add fields from merge array
|
|
109
|
+
if (options.merge) {
|
|
110
|
+
for (const field of options.merge) {
|
|
111
|
+
fieldsToMerge.add(field);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
// Add permissions if keepPermissions is true
|
|
115
|
+
if (options.keepPermissions) {
|
|
116
|
+
fieldsToMerge.add('permissions');
|
|
117
|
+
}
|
|
118
|
+
// Add enabledPlugins if keepPlugins is true
|
|
119
|
+
if (options.keepPlugins) {
|
|
120
|
+
fieldsToMerge.add('enabledPlugins');
|
|
121
|
+
}
|
|
122
|
+
// If no fields to merge, return target as-is
|
|
123
|
+
if (fieldsToMerge.size === 0) {
|
|
124
|
+
return { ...target };
|
|
125
|
+
}
|
|
126
|
+
// Start with a copy of target as the base
|
|
127
|
+
const result = { ...target };
|
|
128
|
+
// Merge each specified field
|
|
129
|
+
for (const field of fieldsToMerge) {
|
|
130
|
+
const currentValue = current[field];
|
|
131
|
+
const targetValue = target[field];
|
|
132
|
+
// Special handling for permissions (contains arrays that should be combined)
|
|
133
|
+
if (field === 'permissions') {
|
|
134
|
+
result.permissions = deepMergePermissions(currentValue, targetValue);
|
|
135
|
+
continue;
|
|
136
|
+
}
|
|
137
|
+
// For other fields, use standard deep merge
|
|
138
|
+
const merged = deepMerge(currentValue, targetValue);
|
|
139
|
+
// Only set the field if there's a value
|
|
140
|
+
if (merged !== undefined) {
|
|
141
|
+
result[field] = merged;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
return result;
|
|
145
|
+
}
|
|
146
|
+
//# sourceMappingURL=merge.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"merge.js","sourceRoot":"","sources":["../../src/lib/merge.ts"],"names":[],"mappings":";AAAA;;GAEG;;AA6GH,sCA8DC;AAvKD;;;;;GAKG;AACH,SAAS,SAAS,CAAC,MAAe,EAAE,MAAe;IACjD,6CAA6C;IAC7C,IAAI,MAAM,KAAK,IAAI,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;QAC5C,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,6CAA6C;IAC7C,IAAI,MAAM,KAAK,IAAI,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;Q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 @@
|
|
|
1
|
+
import type { ClaudeSettings } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Profile Manager - Manage Claude Code configuration profiles
|
|
4
|
+
*/
|
|
5
|
+
export declare class ProfileManager {
|
|
6
|
+
private baseDir;
|
|
7
|
+
private profilesDir;
|
|
8
|
+
/**
|
|
9
|
+
* Create a ProfileManager instance
|
|
10
|
+
* @param customDir - Optional custom base directory (for testing)
|
|
11
|
+
*/
|
|
12
|
+
constructor(customDir?: string);
|
|
13
|
+
/**
|
|
14
|
+
* Ensure required directories exist
|
|
15
|
+
*/
|
|
16
|
+
ensureDirs(): Promise<void>;
|
|
17
|
+
/**
|
|
18
|
+
* List all profile names (sorted alphabetically)
|
|
19
|
+
*/
|
|
20
|
+
list(): Promise<string[]>;
|
|
21
|
+
/**
|
|
22
|
+
* Get a profile settings by name
|
|
23
|
+
* @returns Settings object
|
|
24
|
+
* @throws CsmError if profile not found, name invalid, or file corrupted
|
|
25
|
+
*/
|
|
26
|
+
get(name: string): Promise<ClaudeSettings>;
|
|
27
|
+
/**
|
|
28
|
+
* Check if a profile exists and get it if it does
|
|
29
|
+
* @returns Settings object or null if not found
|
|
30
|
+
* @throws CsmError if name invalid or file corrupted
|
|
31
|
+
*/
|
|
32
|
+
getIfExists(name: string): Promise<ClaudeSettings | null>;
|
|
33
|
+
/**
|
|
34
|
+
* 内部方法:读取 profile 文件
|
|
35
|
+
* @returns Settings 对象,如果文件不存在则返回 null
|
|
36
|
+
* @throws CsmError 如果名称无效或文件损坏
|
|
37
|
+
*/
|
|
38
|
+
private readProfileFile;
|
|
39
|
+
/**
|
|
40
|
+
* Create a new profile
|
|
41
|
+
* @throws CsmError if profile already exists or name is invalid
|
|
42
|
+
*/
|
|
43
|
+
create(name: string, settings: ClaudeSettings): Promise<void>;
|
|
44
|
+
/**
|
|
45
|
+
* Delete a profile
|
|
46
|
+
* @returns true if deleted, false if not found
|
|
47
|
+
* @throws CsmError if name is invalid
|
|
48
|
+
*/
|
|
49
|
+
delete(name: string): Promise<boolean>;
|
|
50
|
+
/**
|
|
51
|
+
* Check if a profile exists
|
|
52
|
+
* @throws CsmError if name is invalid
|
|
53
|
+
*/
|
|
54
|
+
exists(name: string): Promise<boolean>;
|
|
55
|
+
/**
|
|
56
|
+
* Rename a profile
|
|
57
|
+
* @throws CsmError if profile not found, target exists, or names invalid
|
|
58
|
+
*/
|
|
59
|
+
rename(oldName: string, newName: string): Promise<void>;
|
|
60
|
+
/**
|
|
61
|
+
* Get the file path for a profile
|
|
62
|
+
*/
|
|
63
|
+
private getProfilePath;
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=profile.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"profile.d.ts","sourceRoot":"","sources":["../../src/lib/profile.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAI/C;;GAEG;AACH,qBAAa,cAAc;IACzB,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,WAAW,CAAS;IAE5B;;;OAGG;gBACS,SAAS,CAAC,EAAE,MAAM;IAQ9B;;OAEG;IACG,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAIjC;;OAEG;IACG,IAAI,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;IAW/B;;;;OAIG;IACG,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC;IAQhD;;;;OAIG;IACG,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,GAAG,IAAI,CAAC;IAI/D;;;;OAIG;YACW,eAAe;IAsB7B;;;OAGG;IACG,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC;IAcnE;;;;OAIG;IACG,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAiB5C;;;OAGG;IACG,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAS5C;;;OAGG;IACG,MAAM,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAwB7D;;OAEG;IACH,OAAO,CAAC,cAAc;CAGvB"}
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.ProfileManager = void 0;
|
|
7
|
+
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const file_1 = require("../utils/file");
|
|
10
|
+
const validator_1 = require("../utils/validator");
|
|
11
|
+
const errors_1 = require("../utils/errors");
|
|
12
|
+
/**
|
|
13
|
+
* Profile Manager - Manage Claude Code configuration profiles
|
|
14
|
+
*/
|
|
15
|
+
class ProfileManager {
|
|
16
|
+
/**
|
|
17
|
+
* Create a ProfileManager instance
|
|
18
|
+
* @param customDir - Optional custom base directory (for testing)
|
|
19
|
+
*/
|
|
20
|
+
constructor(customDir) {
|
|
21
|
+
// Use customDir for testing, otherwise use default ~/.claude/csm
|
|
22
|
+
this.baseDir = customDir || (0, file_1.getCsmDir)();
|
|
23
|
+
this.profilesDir = customDir
|
|
24
|
+
? path_1.default.join(customDir, 'profiles')
|
|
25
|
+
: (0, file_1.getProfilesDir)();
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Ensure required directories exist
|
|
29
|
+
*/
|
|
30
|
+
async ensureDirs() {
|
|
31
|
+
await fs_extra_1.default.ensureDir(this.profilesDir);
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* List all profile names (sorted alphabetically)
|
|
35
|
+
*/
|
|
36
|
+
async list() {
|
|
37
|
+
await this.ensureDirs();
|
|
38
|
+
const files = await fs_extra_1.default.readdir(this.profilesDir);
|
|
39
|
+
const jsonFiles = files.filter(f => f.endsWith('.json'));
|
|
40
|
+
const names = jsonFiles.map(f => path_1.default.basename(f, '.json'));
|
|
41
|
+
return names.sort((a, b) => a.localeCompare(b));
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Get a profile settings by name
|
|
45
|
+
* @returns Settings object
|
|
46
|
+
* @throws CsmError if profile not found, name invalid, or file corrupted
|
|
47
|
+
*/
|
|
48
|
+
async get(name) {
|
|
49
|
+
const result = await this.readProfileFile(name);
|
|
50
|
+
if (result === null) {
|
|
51
|
+
throw errors_1.CsmError.profileNotFound(name);
|
|
52
|
+
}
|
|
53
|
+
return result;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Check if a profile exists and get it if it does
|
|
57
|
+
* @returns Settings object or null if not found
|
|
58
|
+
* @throws CsmError if name invalid or file corrupted
|
|
59
|
+
*/
|
|
60
|
+
async getIfExists(name) {
|
|
61
|
+
return this.readProfileFile(name);
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* 内部方法:读取 profile 文件
|
|
65
|
+
* @returns Settings 对象,如果文件不存在则返回 null
|
|
66
|
+
* @throws CsmError 如果名称无效或文件损坏
|
|
67
|
+
*/
|
|
68
|
+
async readProfileFile(name) {
|
|
69
|
+
if (!(0, validator_1.validateProfileName)(name)) {
|
|
70
|
+
throw errors_1.CsmError.profileNameInvalid(name, '只允许字母、数字、连字符和下划线');
|
|
71
|
+
}
|
|
72
|
+
await this.ensureDirs();
|
|
73
|
+
const filePath = this.getProfilePath(name);
|
|
74
|
+
if (!(await fs_extra_1.default.pathExists(filePath))) {
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
try {
|
|
78
|
+
const content = await fs_extra_1.default.readJson(filePath);
|
|
79
|
+
return content;
|
|
80
|
+
}
|
|
81
|
+
catch (error) {
|
|
82
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
83
|
+
throw errors_1.CsmError.profileCorrupted(name, message);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Create a new profile
|
|
88
|
+
* @throws CsmError if profile already exists or name is invalid
|
|
89
|
+
*/
|
|
90
|
+
async create(name, settings) {
|
|
91
|
+
if (!(0, validator_1.validateProfileName)(name)) {
|
|
92
|
+
throw errors_1.CsmError.profileNameInvalid(name, '只允许字母、数字、连字符和下划线');
|
|
93
|
+
}
|
|
94
|
+
await this.ensureDirs();
|
|
95
|
+
if (await this.exists(name)) {
|
|
96
|
+
throw errors_1.CsmError.profileAlreadyExists(name);
|
|
97
|
+
}
|
|
98
|
+
await fs_extra_1.default.writeJson(this.getProfilePath(name), settings, { spaces: 2 });
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Delete a profile
|
|
102
|
+
* @returns true if deleted, false if not found
|
|
103
|
+
* @throws CsmError if name is invalid
|
|
104
|
+
*/
|
|
105
|
+
async delete(name) {
|
|
106
|
+
if (!(0, validator_1.validateProfileName)(name)) {
|
|
107
|
+
throw errors_1.CsmError.profileNameInvalid(name, '只允许字母、数字、连字符和下划线');
|
|
108
|
+
}
|
|
109
|
+
await this.ensureDirs();
|
|
110
|
+
const filePath = this.getProfilePath(name);
|
|
111
|
+
if (!(await fs_extra_1.default.pathExists(filePath))) {
|
|
112
|
+
return false;
|
|
113
|
+
}
|
|
114
|
+
await fs_extra_1.default.remove(filePath);
|
|
115
|
+
return true;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Check if a profile exists
|
|
119
|
+
* @throws CsmError if name is invalid
|
|
120
|
+
*/
|
|
121
|
+
async exists(name) {
|
|
122
|
+
if (!(0, validator_1.validateProfileName)(name)) {
|
|
123
|
+
throw errors_1.CsmError.profileNameInvalid(name, '只允许字母、数字、连字符和下划线');
|
|
124
|
+
}
|
|
125
|
+
await this.ensureDirs();
|
|
126
|
+
return fs_extra_1.default.pathExists(this.getProfilePath(name));
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Rename a profile
|
|
130
|
+
* @throws CsmError if profile not found, target exists, or names invalid
|
|
131
|
+
*/
|
|
132
|
+
async rename(oldName, newName) {
|
|
133
|
+
if (!(0, validator_1.validateProfileName)(oldName)) {
|
|
134
|
+
throw errors_1.CsmError.profileNameInvalid(oldName, '只允许字母、数字、连字符和下划线');
|
|
135
|
+
}
|
|
136
|
+
if (!(0, validator_1.validateProfileName)(newName)) {
|
|
137
|
+
throw errors_1.CsmError.profileNameInvalid(newName, '只允许字母、数字、连字符和下划线');
|
|
138
|
+
}
|
|
139
|
+
await this.ensureDirs();
|
|
140
|
+
const oldPath = this.getProfilePath(oldName);
|
|
141
|
+
const newPath = this.getProfilePath(newName);
|
|
142
|
+
if (!(await fs_extra_1.default.pathExists(oldPath))) {
|
|
143
|
+
throw errors_1.CsmError.profileNotFound(oldName);
|
|
144
|
+
}
|
|
145
|
+
if (await fs_extra_1.default.pathExists(newPath)) {
|
|
146
|
+
throw errors_1.CsmError.profileAlreadyExists(newName);
|
|
147
|
+
}
|
|
148
|
+
await fs_extra_1.default.move(oldPath, newPath);
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Get the file path for a profile
|
|
152
|
+
*/
|
|
153
|
+
getProfilePath(name) {
|
|
154
|
+
return path_1.default.join(this.profilesDir, `${name}.json`);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
exports.ProfileManager = ProfileManager;
|
|
158
|
+
//# sourceMappingURL=profile.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"profile.js","sourceRoot":"","sources":["../../src/lib/profile.ts"],"names":[],"mappings":";;;;;;AAAA,wDAA0B;AAC1B,gDAAwB;AACxB,wCAA0D;AAE1D,kDAAyD;AACzD,4CAAyD;AAEzD;;GAEG;AACH,MAAa,cAAc;IAIzB;;;OAGG;IACH,YAAY,SAAkB;Q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C;QACjE,CAAC;QACD,IAAI,CAAC,IAAA,+BAAmB,EAAC,OAAO,CAAC,EAAE,CAAC;YAClC,MAAM,iBAAQ,CAAC,kBAAkB,CAAC,OAAO,EAAE,kBAAkB,CAAC,CAAC;QACjE,CAAC;QAED,MAAM,IAAI,CAAC,UAAU,EAAE,CAAC;QAExB,MAAM,OAAO,GAAG,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC;QAC7C,MAAM,OAAO,GAAG,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC;QAE7C,IAAI,CAAC,CAAC,MAAM,kBAAE,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,EAAE,CAAC;YACpC,MAAM,iBAAQ,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC;QAC1C,CAAC;QAED,IAAI,MAAM,kBAAE,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE,CAAC;YACjC,MAAM,iBAAQ,CAAC,oBAAoB,CAAC,OAAO,CAAC,CAAC;QAC/C,CAAC;QAED,MAAM,kBAAE,CAAC,IAAI,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IAClC,CAAC;IAED;;OAEG;IACK,cAAc,CAAC,IAAY;QACjC,OAAO,cAAI,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,GAAG,IAAI,OAAO,CAAC,CAAC;IACrD,CAAC;CACF;AA7KD,wCA6KC"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SettingsManager - 管理 Claude Code 设置文件
|
|
3
|
+
*/
|
|
4
|
+
import type { ClaudeSettings, MergeOptions } from '../types';
|
|
5
|
+
/**
|
|
6
|
+
* SettingsManager 配置选项
|
|
7
|
+
*/
|
|
8
|
+
export interface SettingsManagerOptions {
|
|
9
|
+
/** 自定义 Claude 目录路径(用于测试) */
|
|
10
|
+
claudeDir?: string;
|
|
11
|
+
/** 最大备份数量,默认 10 */
|
|
12
|
+
maxBackups?: number;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Claude Code 设置管理器
|
|
16
|
+
*/
|
|
17
|
+
export declare class SettingsManager {
|
|
18
|
+
private claudeDir;
|
|
19
|
+
private settingsPath;
|
|
20
|
+
private backupDir;
|
|
21
|
+
private maxBackups;
|
|
22
|
+
constructor(options?: SettingsManagerOptions);
|
|
23
|
+
/**
|
|
24
|
+
* 读取当前 settings
|
|
25
|
+
*/
|
|
26
|
+
read(): Promise<ClaudeSettings>;
|
|
27
|
+
/**
|
|
28
|
+
* 写入 settings(使用原子写入)
|
|
29
|
+
*/
|
|
30
|
+
write(settings: ClaudeSettings): Promise<void>;
|
|
31
|
+
/**
|
|
32
|
+
* 应用 Profile(支持合并)
|
|
33
|
+
* 具有原子性:先备份再写入,失败时可以恢复
|
|
34
|
+
*/
|
|
35
|
+
applyProfile(profileSettings: ClaudeSettings, options?: MergeOptions): Promise<ClaudeSettings>;
|
|
36
|
+
/**
|
|
37
|
+
* 备份当前 settings
|
|
38
|
+
* @returns 备份文件路径
|
|
39
|
+
*/
|
|
40
|
+
backup(): Promise<string>;
|
|
41
|
+
/**
|
|
42
|
+
* 清理旧备份文件,保留最新的 maxBackups 个
|
|
43
|
+
*/
|
|
44
|
+
cleanOldBackups(): Promise<number>;
|
|
45
|
+
/**
|
|
46
|
+
* 获取备份文件列表
|
|
47
|
+
*/
|
|
48
|
+
listBackups(): Promise<{
|
|
49
|
+
name: string;
|
|
50
|
+
path: string;
|
|
51
|
+
size: number;
|
|
52
|
+
createdAt: Date;
|
|
53
|
+
}[]>;
|
|
54
|
+
/**
|
|
55
|
+
* 生成时间戳字符串
|
|
56
|
+
* 格式: YYYYMMDDHHmmssSSS (毫秒级精度)
|
|
57
|
+
*/
|
|
58
|
+
private getTimestamp;
|
|
59
|
+
/**
|
|
60
|
+
* 获取 settings 文件路径
|
|
61
|
+
*/
|
|
62
|
+
getSettingsPath(): string;
|
|
63
|
+
/**
|
|
64
|
+
* 获取备份目录路径
|
|
65
|
+
*/
|
|
66
|
+
getBackupDir(): string;
|
|
67
|
+
/**
|
|
68
|
+
* 获取 Claude 目录路径
|
|
69
|
+
*/
|
|
70
|
+
getClaudeDir(): string;
|
|
71
|
+
}
|
|
72
|
+
//# sourceMappingURL=settings.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"settings.d.ts","sourceRoot":"","sources":["../../src/lib/settings.ts"],"names":[],"mappings":"AAAA;;GAEG;AAQH,OAAO,KAAK,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAK7D;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACrC,4BAA4B;IAC5B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,mBAAmB;IACnB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;GAEG;AACH,qBAAa,eAAe;IAC1B,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,YAAY,CAAS;IAC7B,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,UAAU,CAAS;gBAEf,OAAO,GAAE,sBAA2B;IAYhD;;OAEG;IACG,IAAI,IAAI,OAAO,CAAC,cAAc,CAAC;IAYrC;;OAEG;IACG,KAAK,CAAC,QAAQ,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC;IAUpD;;;OAGG;IACG,YAAY,CAChB,eAAe,EAAE,cAAc,EAC/B,OAAO,GAAE,YAAiB,GACzB,OAAO,CAAC,cAAc,CAAC;IAyC1B;;;OAGG;IACG,MAAM,IAAI,OAAO,CAAC,MAAM,CAAC;IA2B/B;;OAEG;IACG,eAAe,IAAI,OAAO,CAAC,MAAM,CAAC;IA0CxC;;OAEG;IACG,WAAW,IAAI,OAAO,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,IAAI,CAAA;KAAE,EAAE,CAAC;IA6C7F;;;OAG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