@leynier/ccst 0.2.1 → 0.3.0
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/package.json +57 -56
- package/src/commands/completions.ts +53 -47
- package/src/commands/config/dump.ts +40 -0
- package/src/commands/config/load.ts +122 -0
- package/src/commands/create.ts +5 -2
- package/src/commands/delete.ts +9 -6
- package/src/commands/edit.ts +13 -10
- package/src/commands/export.ts +13 -10
- package/src/commands/import-profiles/ccs.ts +94 -69
- package/src/commands/import-profiles/configs.ts +78 -60
- package/src/commands/import.ts +8 -5
- package/src/commands/list.ts +5 -2
- package/src/commands/merge.ts +25 -12
- package/src/commands/rename.ts +14 -11
- package/src/commands/show.ts +13 -10
- package/src/commands/switch.ts +9 -4
- package/src/commands/unset.ts +1 -1
- package/src/core/context-manager.test.ts +49 -47
- package/src/core/context-manager.ts +484 -389
- package/src/core/merge-manager.test.ts +40 -25
- package/src/core/merge-manager.ts +182 -132
- package/src/core/settings-level.ts +11 -8
- package/src/core/state.ts +22 -17
- package/src/index.ts +169 -130
- package/src/types/index.ts +5 -5
- package/src/utils/ccs-paths.ts +120 -0
- package/src/utils/colors.ts +6 -6
- package/src/utils/deep-merge.ts +21 -18
- package/src/utils/interactive.ts +68 -56
- package/src/utils/json.ts +17 -11
- package/src/utils/paths.ts +46 -44
package/src/utils/json.ts
CHANGED
|
@@ -1,19 +1,25 @@
|
|
|
1
1
|
import { existsSync } from "node:fs";
|
|
2
2
|
|
|
3
3
|
export const readJson = async <T>(filePath: string): Promise<T> => {
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
const text = await Bun.file(filePath).text();
|
|
5
|
+
return JSON.parse(text) as T;
|
|
6
6
|
};
|
|
7
7
|
|
|
8
|
-
export const readJsonIfExists = async <T>(
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
8
|
+
export const readJsonIfExists = async <T>(
|
|
9
|
+
filePath: string,
|
|
10
|
+
fallback: T,
|
|
11
|
+
): Promise<T> => {
|
|
12
|
+
if (!existsSync(filePath)) {
|
|
13
|
+
return fallback;
|
|
14
|
+
}
|
|
15
|
+
const text = await Bun.file(filePath).text();
|
|
16
|
+
return JSON.parse(text) as T;
|
|
14
17
|
};
|
|
15
18
|
|
|
16
|
-
export const writeJson = async (
|
|
17
|
-
|
|
18
|
-
|
|
19
|
+
export const writeJson = async (
|
|
20
|
+
filePath: string,
|
|
21
|
+
value: unknown,
|
|
22
|
+
): Promise<void> => {
|
|
23
|
+
const payload = `${JSON.stringify(value, null, 2)}\n`;
|
|
24
|
+
await Bun.write(filePath, payload);
|
|
19
25
|
};
|
package/src/utils/paths.ts
CHANGED
|
@@ -1,58 +1,60 @@
|
|
|
1
|
-
import path from "node:path";
|
|
2
|
-
import { homedir } from "node:os";
|
|
3
1
|
import { existsSync, readdirSync } from "node:fs";
|
|
2
|
+
import { homedir } from "node:os";
|
|
3
|
+
import path from "node:path";
|
|
4
4
|
import type { SettingsLevel } from "../types/index.js";
|
|
5
5
|
|
|
6
6
|
export type Paths = {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
contextsDir: string;
|
|
8
|
+
settingsPath: string;
|
|
9
|
+
statePath: string;
|
|
10
|
+
settingsLevel: SettingsLevel;
|
|
11
11
|
};
|
|
12
12
|
|
|
13
13
|
export const getPaths = (level: SettingsLevel): Paths => {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
14
|
+
const homeDir = homedir();
|
|
15
|
+
const currentDir = process.cwd();
|
|
16
|
+
if (level === "user") {
|
|
17
|
+
const claudeDir = path.join(homeDir, ".claude");
|
|
18
|
+
const contextsDir = path.join(claudeDir, "settings");
|
|
19
|
+
return {
|
|
20
|
+
contextsDir,
|
|
21
|
+
settingsPath: path.join(claudeDir, "settings.json"),
|
|
22
|
+
statePath: path.join(contextsDir, ".cctx-state.json"),
|
|
23
|
+
settingsLevel: level,
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
if (level === "project") {
|
|
27
|
+
const claudeDir = path.join(currentDir, ".claude");
|
|
28
|
+
const contextsDir = path.join(claudeDir, "settings");
|
|
29
|
+
return {
|
|
30
|
+
contextsDir,
|
|
31
|
+
settingsPath: path.join(claudeDir, "settings.json"),
|
|
32
|
+
statePath: path.join(contextsDir, ".cctx-state.json"),
|
|
33
|
+
settingsLevel: level,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
const claudeDir = path.join(currentDir, ".claude");
|
|
37
|
+
const contextsDir = path.join(claudeDir, "settings");
|
|
38
|
+
return {
|
|
39
|
+
contextsDir,
|
|
40
|
+
settingsPath: path.join(claudeDir, "settings.local.json"),
|
|
41
|
+
statePath: path.join(contextsDir, ".cctx-state.local.json"),
|
|
42
|
+
settingsLevel: level,
|
|
43
|
+
};
|
|
44
44
|
};
|
|
45
45
|
|
|
46
46
|
export const hasProjectContexts = (): boolean => {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
47
|
+
const contextsDir = path.join(process.cwd(), ".claude", "settings");
|
|
48
|
+
try {
|
|
49
|
+
const entries = readdirSync(contextsDir);
|
|
50
|
+
return entries.some(
|
|
51
|
+
(name) => name.endsWith(".json") && !name.startsWith("."),
|
|
52
|
+
);
|
|
53
|
+
} catch {
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
54
56
|
};
|
|
55
57
|
|
|
56
58
|
export const hasLocalContexts = (): boolean => {
|
|
57
|
-
|
|
59
|
+
return existsSync(path.join(process.cwd(), ".claude", "settings.local.json"));
|
|
58
60
|
};
|