@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.
@@ -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
+ }