@haiyangj/ccs 1.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/CHANGELOG.md +47 -0
- package/DESIGN_SPEC.md +530 -0
- package/IMPLEMENTATION.md +340 -0
- package/README.md +365 -0
- package/UPDATE_NOTES.md +126 -0
- package/bin/ccm.js +96 -0
- package/package.json +28 -0
- package/src/commands/add.js +98 -0
- package/src/commands/delete.js +50 -0
- package/src/commands/export.js +46 -0
- package/src/commands/import.js +99 -0
- package/src/commands/init.js +55 -0
- package/src/commands/list.js +55 -0
- package/src/commands/rename.js +40 -0
- package/src/commands/set.js +90 -0
- package/src/commands/show.js +33 -0
- package/src/commands/use.js +61 -0
- package/src/core/config.js +123 -0
- package/src/core/profiles.js +221 -0
- package/src/core/validator.js +96 -0
- package/src/utils/logger.js +66 -0
- package/src/utils/paths.js +83 -0
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { fileURLToPath } from 'url';
|
|
2
|
+
import { dirname, join } from 'path';
|
|
3
|
+
import { existsSync } from 'fs';
|
|
4
|
+
import { homedir } from 'os';
|
|
5
|
+
import { execSync } from 'child_process';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Resolves the .claude directory path with fallback strategy
|
|
9
|
+
* Priority: current dir -> git root -> home dir -> env variable
|
|
10
|
+
*/
|
|
11
|
+
export function resolveClaudeDir() {
|
|
12
|
+
// 1. Check environment variable first
|
|
13
|
+
if (process.env.CLAUDE_CONFIG_DIR) {
|
|
14
|
+
const envPath = process.env.CLAUDE_CONFIG_DIR;
|
|
15
|
+
if (existsSync(envPath)) {
|
|
16
|
+
return envPath;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// 2. Check current working directory
|
|
21
|
+
const cwdPath = join(process.cwd(), '.claude');
|
|
22
|
+
if (existsSync(cwdPath)) {
|
|
23
|
+
return cwdPath;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// 3. Check git root directory
|
|
27
|
+
try {
|
|
28
|
+
const gitRoot = execSync('git rev-parse --show-toplevel', {
|
|
29
|
+
encoding: 'utf-8',
|
|
30
|
+
stdio: ['pipe', 'pipe', 'ignore']
|
|
31
|
+
}).trim();
|
|
32
|
+
const gitPath = join(gitRoot, '.claude');
|
|
33
|
+
if (existsSync(gitPath)) {
|
|
34
|
+
return gitPath;
|
|
35
|
+
}
|
|
36
|
+
} catch (error) {
|
|
37
|
+
// Not in a git repo or git not available, continue to next fallback
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// 4. Check home directory
|
|
41
|
+
const homePath = join(homedir(), '.claude');
|
|
42
|
+
if (existsSync(homePath)) {
|
|
43
|
+
return homePath;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// 5. Default to current working directory (will be created if needed)
|
|
47
|
+
return cwdPath;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Get the settings.json file path
|
|
52
|
+
*/
|
|
53
|
+
export function getSettingsPath() {
|
|
54
|
+
return join(resolveClaudeDir(), 'settings.json');
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Get the profiles.json file path
|
|
59
|
+
*/
|
|
60
|
+
export function getProfilesPath() {
|
|
61
|
+
return join(resolveClaudeDir(), 'profiles.json');
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Check if .claude directory exists
|
|
66
|
+
*/
|
|
67
|
+
export function claudeDirExists() {
|
|
68
|
+
return existsSync(resolveClaudeDir());
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Check if settings.json exists
|
|
73
|
+
*/
|
|
74
|
+
export function settingsExists() {
|
|
75
|
+
return existsSync(getSettingsPath());
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Check if profiles.json exists
|
|
80
|
+
*/
|
|
81
|
+
export function profilesExists() {
|
|
82
|
+
return existsSync(getProfilesPath());
|
|
83
|
+
}
|