@kaitranntt/ccs 4.4.0 → 5.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.
Files changed (262) hide show
  1. package/README.md +98 -7
  2. package/VERSION +1 -1
  3. package/config/base-agy.settings.json +10 -0
  4. package/config/base-codex.settings.json +10 -0
  5. package/config/base-gemini.settings.json +10 -0
  6. package/dist/auth/auth-commands.d.ts +52 -0
  7. package/dist/auth/auth-commands.d.ts.map +1 -0
  8. package/dist/auth/auth-commands.js +479 -0
  9. package/dist/auth/auth-commands.js.map +1 -0
  10. package/dist/auth/profile-detector.d.ts +68 -0
  11. package/dist/auth/profile-detector.d.ts.map +1 -0
  12. package/dist/auth/profile-detector.js +209 -0
  13. package/dist/auth/profile-detector.js.map +1 -0
  14. package/dist/auth/profile-registry.d.ts +60 -0
  15. package/dist/auth/profile-registry.d.ts.map +1 -0
  16. package/dist/auth/profile-registry.js +188 -0
  17. package/dist/auth/profile-registry.js.map +1 -0
  18. package/dist/ccs.d.ts +10 -0
  19. package/dist/ccs.d.ts.map +1 -0
  20. package/dist/ccs.js +320 -0
  21. package/dist/ccs.js.map +1 -0
  22. package/dist/cliproxy/auth-handler.d.ts +95 -0
  23. package/dist/cliproxy/auth-handler.d.ts.map +1 -0
  24. package/dist/cliproxy/auth-handler.js +443 -0
  25. package/dist/cliproxy/auth-handler.js.map +1 -0
  26. package/dist/cliproxy/base-config-loader.d.ts +42 -0
  27. package/dist/cliproxy/base-config-loader.d.ts.map +1 -0
  28. package/dist/cliproxy/base-config-loader.js +123 -0
  29. package/dist/cliproxy/base-config-loader.js.map +1 -0
  30. package/dist/cliproxy/binary-manager.d.ts +104 -0
  31. package/dist/cliproxy/binary-manager.d.ts.map +1 -0
  32. package/dist/cliproxy/binary-manager.js +567 -0
  33. package/dist/cliproxy/binary-manager.js.map +1 -0
  34. package/dist/cliproxy/cliproxy-executor.d.ts +33 -0
  35. package/dist/cliproxy/cliproxy-executor.d.ts.map +1 -0
  36. package/dist/cliproxy/cliproxy-executor.js +297 -0
  37. package/dist/cliproxy/cliproxy-executor.js.map +1 -0
  38. package/dist/cliproxy/config-generator.d.ts +89 -0
  39. package/dist/cliproxy/config-generator.d.ts.map +1 -0
  40. package/dist/cliproxy/config-generator.js +263 -0
  41. package/dist/cliproxy/config-generator.js.map +1 -0
  42. package/dist/cliproxy/index.d.ts +13 -0
  43. package/dist/cliproxy/index.d.ts.map +1 -0
  44. package/dist/cliproxy/index.js +62 -0
  45. package/dist/cliproxy/index.js.map +1 -0
  46. package/dist/cliproxy/platform-detector.d.ts +48 -0
  47. package/dist/cliproxy/platform-detector.d.ts.map +1 -0
  48. package/dist/cliproxy/platform-detector.js +118 -0
  49. package/dist/cliproxy/platform-detector.js.map +1 -0
  50. package/dist/cliproxy/types.d.ts +169 -0
  51. package/dist/cliproxy/types.d.ts.map +1 -0
  52. package/dist/cliproxy/types.js +7 -0
  53. package/dist/cliproxy/types.js.map +1 -0
  54. package/dist/commands/doctor-command.d.ts +10 -0
  55. package/dist/commands/doctor-command.d.ts.map +1 -0
  56. package/dist/commands/doctor-command.js +44 -0
  57. package/dist/commands/doctor-command.js.map +1 -0
  58. package/dist/commands/help-command.d.ts +5 -0
  59. package/dist/commands/help-command.d.ts.map +1 -0
  60. package/dist/commands/help-command.js +104 -0
  61. package/dist/commands/help-command.js.map +1 -0
  62. package/dist/commands/install-command.d.ts +14 -0
  63. package/dist/commands/install-command.d.ts.map +1 -0
  64. package/dist/commands/install-command.js +39 -0
  65. package/dist/commands/install-command.js.map +1 -0
  66. package/dist/commands/shell-completion-command.d.ts +10 -0
  67. package/dist/commands/shell-completion-command.d.ts.map +1 -0
  68. package/dist/commands/shell-completion-command.js +85 -0
  69. package/dist/commands/shell-completion-command.js.map +1 -0
  70. package/dist/commands/sync-command.d.ts +10 -0
  71. package/dist/commands/sync-command.d.ts.map +1 -0
  72. package/dist/commands/sync-command.js +59 -0
  73. package/dist/commands/sync-command.js.map +1 -0
  74. package/dist/commands/update-command.d.ts +12 -0
  75. package/dist/commands/update-command.d.ts.map +1 -0
  76. package/dist/commands/update-command.js +295 -0
  77. package/dist/commands/update-command.js.map +1 -0
  78. package/dist/commands/version-command.d.ts +10 -0
  79. package/dist/commands/version-command.d.ts.map +1 -0
  80. package/dist/commands/version-command.js +100 -0
  81. package/dist/commands/version-command.js.map +1 -0
  82. package/dist/delegation/delegation-handler.d.ts +60 -0
  83. package/dist/delegation/delegation-handler.d.ts.map +1 -0
  84. package/dist/delegation/delegation-handler.js +174 -0
  85. package/dist/delegation/delegation-handler.js.map +1 -0
  86. package/dist/delegation/headless-executor.d.ts +114 -0
  87. package/dist/delegation/headless-executor.d.ts.map +1 -0
  88. package/dist/delegation/headless-executor.js +562 -0
  89. package/dist/delegation/headless-executor.js.map +1 -0
  90. package/dist/delegation/result-formatter.d.ts +108 -0
  91. package/dist/delegation/result-formatter.d.ts.map +1 -0
  92. package/dist/delegation/result-formatter.js +391 -0
  93. package/dist/delegation/result-formatter.js.map +1 -0
  94. package/dist/delegation/session-manager.d.ts +58 -0
  95. package/dist/delegation/session-manager.d.ts.map +1 -0
  96. package/dist/delegation/session-manager.js +153 -0
  97. package/dist/delegation/session-manager.js.map +1 -0
  98. package/dist/delegation/settings-parser.d.ts +31 -0
  99. package/dist/delegation/settings-parser.d.ts.map +1 -0
  100. package/dist/delegation/settings-parser.js +107 -0
  101. package/dist/delegation/settings-parser.js.map +1 -0
  102. package/dist/glmt/delta-accumulator.d.ts +210 -0
  103. package/dist/glmt/delta-accumulator.d.ts.map +1 -0
  104. package/dist/glmt/delta-accumulator.js +351 -0
  105. package/dist/glmt/delta-accumulator.js.map +1 -0
  106. package/dist/glmt/glmt-proxy.d.ts +72 -0
  107. package/dist/glmt/glmt-proxy.d.ts.map +1 -0
  108. package/dist/glmt/glmt-proxy.js +427 -0
  109. package/dist/glmt/glmt-proxy.js.map +1 -0
  110. package/dist/glmt/glmt-transformer.d.ts +265 -0
  111. package/dist/glmt/glmt-transformer.d.ts.map +1 -0
  112. package/dist/glmt/glmt-transformer.js +832 -0
  113. package/dist/glmt/glmt-transformer.js.map +1 -0
  114. package/dist/glmt/locale-enforcer.d.ts +38 -0
  115. package/dist/glmt/locale-enforcer.d.ts.map +1 -0
  116. package/dist/glmt/locale-enforcer.js +69 -0
  117. package/dist/glmt/locale-enforcer.js.map +1 -0
  118. package/dist/glmt/reasoning-enforcer.d.ts +52 -0
  119. package/dist/glmt/reasoning-enforcer.d.ts.map +1 -0
  120. package/dist/glmt/reasoning-enforcer.js +151 -0
  121. package/dist/glmt/reasoning-enforcer.js.map +1 -0
  122. package/dist/glmt/sse-parser.d.ts +47 -0
  123. package/dist/glmt/sse-parser.d.ts.map +1 -0
  124. package/dist/glmt/sse-parser.js +93 -0
  125. package/dist/glmt/sse-parser.js.map +1 -0
  126. package/dist/management/doctor.d.ts +104 -0
  127. package/dist/management/doctor.d.ts.map +1 -0
  128. package/dist/management/doctor.js +673 -0
  129. package/dist/management/doctor.js.map +1 -0
  130. package/dist/management/instance-manager.d.ts +57 -0
  131. package/dist/management/instance-manager.d.ts.map +1 -0
  132. package/dist/management/instance-manager.js +195 -0
  133. package/dist/management/instance-manager.js.map +1 -0
  134. package/dist/management/recovery-manager.d.ts +39 -0
  135. package/dist/management/recovery-manager.d.ts.map +1 -0
  136. package/dist/management/recovery-manager.js +141 -0
  137. package/dist/management/recovery-manager.js.map +1 -0
  138. package/dist/management/shared-manager.d.ts +47 -0
  139. package/dist/management/shared-manager.d.ts.map +1 -0
  140. package/dist/management/shared-manager.js +388 -0
  141. package/dist/management/shared-manager.js.map +1 -0
  142. package/dist/types/cli.d.ts +50 -0
  143. package/dist/types/cli.d.ts.map +1 -0
  144. package/dist/types/cli.js +16 -0
  145. package/dist/types/cli.js.map +1 -0
  146. package/dist/types/config.d.ts +51 -0
  147. package/dist/types/config.d.ts.map +1 -0
  148. package/dist/types/config.js +26 -0
  149. package/dist/types/config.js.map +1 -0
  150. package/dist/types/delegation.d.ts +61 -0
  151. package/dist/types/delegation.d.ts.map +1 -0
  152. package/dist/types/delegation.js +6 -0
  153. package/dist/types/delegation.js.map +1 -0
  154. package/dist/types/glmt.d.ts +95 -0
  155. package/dist/types/glmt.d.ts.map +1 -0
  156. package/dist/types/glmt.js +7 -0
  157. package/dist/types/glmt.js.map +1 -0
  158. package/dist/types/index.d.ts +13 -0
  159. package/dist/types/index.d.ts.map +1 -0
  160. package/dist/types/index.js +16 -0
  161. package/dist/types/index.js.map +1 -0
  162. package/dist/types/utils.d.ts +36 -0
  163. package/dist/types/utils.d.ts.map +1 -0
  164. package/dist/types/utils.js +22 -0
  165. package/dist/types/utils.js.map +1 -0
  166. package/dist/utils/claude-detector.d.ts +14 -0
  167. package/dist/utils/claude-detector.d.ts.map +1 -0
  168. package/dist/utils/claude-detector.js +112 -0
  169. package/dist/utils/claude-detector.js.map +1 -0
  170. package/dist/utils/claude-dir-installer.d.ts +46 -0
  171. package/dist/utils/claude-dir-installer.d.ts.map +1 -0
  172. package/dist/utils/claude-dir-installer.js +289 -0
  173. package/dist/utils/claude-dir-installer.js.map +1 -0
  174. package/dist/utils/claude-symlink-manager.d.ts +61 -0
  175. package/dist/utils/claude-symlink-manager.d.ts.map +1 -0
  176. package/dist/utils/claude-symlink-manager.js +291 -0
  177. package/dist/utils/claude-symlink-manager.js.map +1 -0
  178. package/dist/utils/config-manager.d.ts +32 -0
  179. package/dist/utils/config-manager.d.ts.map +1 -0
  180. package/dist/utils/config-manager.js +143 -0
  181. package/dist/utils/config-manager.js.map +1 -0
  182. package/dist/utils/delegation-validator.d.ts +39 -0
  183. package/dist/utils/delegation-validator.d.ts.map +1 -0
  184. package/dist/utils/delegation-validator.js +161 -0
  185. package/dist/utils/delegation-validator.js.map +1 -0
  186. package/dist/utils/error-codes.d.ts +36 -0
  187. package/dist/utils/error-codes.d.ts.map +1 -0
  188. package/dist/utils/error-codes.js +63 -0
  189. package/dist/utils/error-codes.js.map +1 -0
  190. package/dist/utils/error-manager.d.ts +59 -0
  191. package/dist/utils/error-manager.d.ts.map +1 -0
  192. package/dist/utils/error-manager.js +228 -0
  193. package/dist/utils/error-manager.js.map +1 -0
  194. package/dist/utils/helpers.d.ts +27 -0
  195. package/dist/utils/helpers.d.ts.map +1 -0
  196. package/dist/utils/helpers.js +150 -0
  197. package/dist/utils/helpers.js.map +1 -0
  198. package/dist/utils/package-manager-detector.d.ts +14 -0
  199. package/dist/utils/package-manager-detector.d.ts.map +1 -0
  200. package/dist/utils/package-manager-detector.js +162 -0
  201. package/dist/utils/package-manager-detector.js.map +1 -0
  202. package/dist/utils/progress-indicator.d.ts +52 -0
  203. package/dist/utils/progress-indicator.d.ts.map +1 -0
  204. package/dist/utils/progress-indicator.js +102 -0
  205. package/dist/utils/progress-indicator.js.map +1 -0
  206. package/dist/utils/prompt.d.ts +29 -0
  207. package/dist/utils/prompt.d.ts.map +1 -0
  208. package/dist/utils/prompt.js +116 -0
  209. package/dist/utils/prompt.js.map +1 -0
  210. package/dist/utils/shell-completion.d.ts +52 -0
  211. package/dist/utils/shell-completion.d.ts.map +1 -0
  212. package/dist/utils/shell-completion.js +231 -0
  213. package/dist/utils/shell-completion.js.map +1 -0
  214. package/dist/utils/shell-executor.d.ts +15 -0
  215. package/dist/utils/shell-executor.d.ts.map +1 -0
  216. package/dist/utils/shell-executor.js +57 -0
  217. package/dist/utils/shell-executor.js.map +1 -0
  218. package/dist/utils/update-checker.d.ts +48 -0
  219. package/dist/utils/update-checker.d.ts.map +1 -0
  220. package/dist/utils/update-checker.js +241 -0
  221. package/dist/utils/update-checker.js.map +1 -0
  222. package/lib/ccs +21 -1907
  223. package/lib/ccs.ps1 +26 -1800
  224. package/lib/error-codes.ps1 +2 -1
  225. package/lib/prompt.ps1 +2 -2
  226. package/package.json +31 -11
  227. package/scripts/add-shebang.js +39 -0
  228. package/scripts/bump-version.sh +25 -37
  229. package/scripts/dev-install.sh +32 -11
  230. package/scripts/postinstall.js +29 -29
  231. package/bin/auth/auth-commands.js +0 -499
  232. package/bin/auth/profile-detector.js +0 -204
  233. package/bin/auth/profile-registry.js +0 -225
  234. package/bin/ccs.js +0 -1034
  235. package/bin/delegation/README.md +0 -191
  236. package/bin/delegation/delegation-handler.js +0 -212
  237. package/bin/delegation/headless-executor.js +0 -618
  238. package/bin/delegation/result-formatter.js +0 -485
  239. package/bin/delegation/session-manager.js +0 -157
  240. package/bin/delegation/settings-parser.js +0 -109
  241. package/bin/glmt/delta-accumulator.js +0 -276
  242. package/bin/glmt/glmt-proxy.js +0 -495
  243. package/bin/glmt/glmt-transformer.js +0 -999
  244. package/bin/glmt/locale-enforcer.js +0 -72
  245. package/bin/glmt/reasoning-enforcer.js +0 -173
  246. package/bin/glmt/sse-parser.js +0 -96
  247. package/bin/management/doctor.js +0 -721
  248. package/bin/management/instance-manager.js +0 -202
  249. package/bin/management/recovery-manager.js +0 -135
  250. package/bin/management/shared-manager.js +0 -402
  251. package/bin/utils/claude-detector.js +0 -73
  252. package/bin/utils/claude-dir-installer.js +0 -283
  253. package/bin/utils/claude-symlink-manager.js +0 -289
  254. package/bin/utils/config-manager.js +0 -103
  255. package/bin/utils/delegation-validator.js +0 -154
  256. package/bin/utils/error-codes.js +0 -59
  257. package/bin/utils/error-manager.js +0 -165
  258. package/bin/utils/helpers.js +0 -136
  259. package/bin/utils/progress-indicator.js +0 -111
  260. package/bin/utils/prompt.js +0 -134
  261. package/bin/utils/shell-completion.js +0 -256
  262. package/bin/utils/update-checker.js +0 -243
@@ -1,202 +0,0 @@
1
- 'use strict';
2
-
3
- const fs = require('fs');
4
- const path = require('path');
5
- const os = require('os');
6
- const SharedManager = require('./shared-manager');
7
-
8
- /**
9
- * Instance Manager (Simplified)
10
- *
11
- * Manages isolated Claude CLI instances per profile for concurrent sessions.
12
- * Each instance is an isolated CLAUDE_CONFIG_DIR where users login directly.
13
- * No credential copying/encryption - Claude manages credentials per instance.
14
- */
15
- class InstanceManager {
16
- constructor() {
17
- this.instancesDir = path.join(os.homedir(), '.ccs', 'instances');
18
- this.sharedManager = new SharedManager();
19
- }
20
-
21
- /**
22
- * Ensure instance exists for profile (lazy init only)
23
- * @param {string} profileName - Profile name
24
- * @returns {string} Instance path
25
- */
26
- ensureInstance(profileName) {
27
- const instancePath = this.getInstancePath(profileName);
28
-
29
- // Lazy initialization
30
- if (!fs.existsSync(instancePath)) {
31
- this.initializeInstance(profileName, instancePath);
32
- }
33
-
34
- // Validate structure (auto-fix missing dirs)
35
- this.validateInstance(instancePath);
36
-
37
- return instancePath;
38
- }
39
-
40
- /**
41
- * Get instance path for profile
42
- * @param {string} profileName - Profile name
43
- * @returns {string} Instance directory path
44
- */
45
- getInstancePath(profileName) {
46
- const safeName = this._sanitizeName(profileName);
47
- return path.join(this.instancesDir, safeName);
48
- }
49
-
50
- /**
51
- * Initialize new instance directory
52
- * @param {string} profileName - Profile name
53
- * @param {string} instancePath - Instance directory path
54
- * @throws {Error} If initialization fails
55
- */
56
- initializeInstance(profileName, instancePath) {
57
- try {
58
- // Create base directory
59
- fs.mkdirSync(instancePath, { recursive: true, mode: 0o700 });
60
-
61
- // Create Claude-expected subdirectories (profile-specific only)
62
- const subdirs = [
63
- 'session-env',
64
- 'todos',
65
- 'logs',
66
- 'file-history',
67
- 'shell-snapshots',
68
- 'debug',
69
- '.anthropic'
70
- ];
71
-
72
- subdirs.forEach(dir => {
73
- const dirPath = path.join(instancePath, dir);
74
- if (!fs.existsSync(dirPath)) {
75
- fs.mkdirSync(dirPath, { recursive: true, mode: 0o700 });
76
- }
77
- });
78
-
79
- // Symlink shared directories (Phase 1: commands, skills)
80
- this.sharedManager.linkSharedDirectories(instancePath);
81
-
82
- // Copy global configs if exist (settings.json only)
83
- this._copyGlobalConfigs(instancePath);
84
- } catch (error) {
85
- throw new Error(`Failed to initialize instance for ${profileName}: ${error.message}`);
86
- }
87
- }
88
-
89
- /**
90
- * Validate instance directory structure (auto-fix missing directories)
91
- * @param {string} instancePath - Instance path
92
- */
93
- validateInstance(instancePath) {
94
- // Check required directories (auto-create if missing for migration)
95
- const requiredDirs = [
96
- 'session-env',
97
- 'todos',
98
- 'logs',
99
- 'file-history',
100
- 'shell-snapshots',
101
- 'debug',
102
- '.anthropic'
103
- ];
104
-
105
- for (const dir of requiredDirs) {
106
- const dirPath = path.join(instancePath, dir);
107
- if (!fs.existsSync(dirPath)) {
108
- // Auto-create missing directory (migration from older versions)
109
- fs.mkdirSync(dirPath, { recursive: true, mode: 0o700 });
110
- }
111
- }
112
-
113
- // Note: Credentials managed by Claude CLI in instance (no validation needed)
114
- }
115
-
116
- /**
117
- * Delete instance for profile
118
- * @param {string} profileName - Profile name
119
- */
120
- deleteInstance(profileName) {
121
- const instancePath = this.getInstancePath(profileName);
122
-
123
- if (!fs.existsSync(instancePath)) {
124
- return;
125
- }
126
-
127
- // Recursive delete
128
- fs.rmSync(instancePath, { recursive: true, force: true });
129
- }
130
-
131
- /**
132
- * List all instance names
133
- * @returns {Array<string>} Instance names
134
- */
135
- listInstances() {
136
- if (!fs.existsSync(this.instancesDir)) {
137
- return [];
138
- }
139
-
140
- return fs.readdirSync(this.instancesDir)
141
- .filter(name => {
142
- const instancePath = path.join(this.instancesDir, name);
143
- return fs.statSync(instancePath).isDirectory();
144
- });
145
- }
146
-
147
- /**
148
- * Check if instance exists for profile
149
- * @param {string} profileName - Profile name
150
- * @returns {boolean} True if exists
151
- */
152
- hasInstance(profileName) {
153
- const instancePath = this.getInstancePath(profileName);
154
- return fs.existsSync(instancePath);
155
- }
156
-
157
- /**
158
- * Copy global configs to instance (optional)
159
- * @param {string} instancePath - Instance path
160
- */
161
- _copyGlobalConfigs(instancePath) {
162
- // No longer needed - settings.json now symlinked via SharedManager
163
- // Keeping method for backward compatibility (empty implementation)
164
- // Can be removed in future major version
165
- }
166
-
167
- /**
168
- * Copy directory recursively
169
- * @param {string} src - Source directory
170
- * @param {string} dest - Destination directory
171
- */
172
- _copyDirectory(src, dest) {
173
- if (!fs.existsSync(dest)) {
174
- fs.mkdirSync(dest, { recursive: true, mode: 0o700 });
175
- }
176
-
177
- const entries = fs.readdirSync(src, { withFileTypes: true });
178
-
179
- for (const entry of entries) {
180
- const srcPath = path.join(src, entry.name);
181
- const destPath = path.join(dest, entry.name);
182
-
183
- if (entry.isDirectory()) {
184
- this._copyDirectory(srcPath, destPath);
185
- } else {
186
- fs.copyFileSync(srcPath, destPath);
187
- }
188
- }
189
- }
190
-
191
- /**
192
- * Sanitize profile name for filesystem
193
- * @param {string} name - Profile name
194
- * @returns {string} Safe name
195
- */
196
- _sanitizeName(name) {
197
- // Replace unsafe characters with dash
198
- return name.replace(/[^a-zA-Z0-9_-]/g, '-').toLowerCase();
199
- }
200
- }
201
-
202
- module.exports = InstanceManager;
@@ -1,135 +0,0 @@
1
- 'use strict';
2
-
3
- const fs = require('fs');
4
- const path = require('path');
5
- const os = require('os');
6
-
7
- /**
8
- * Auto-recovery for missing or corrupted configuration
9
- */
10
- class RecoveryManager {
11
- constructor() {
12
- this.homedir = os.homedir();
13
- this.ccsDir = path.join(this.homedir, '.ccs');
14
- this.claudeDir = path.join(this.homedir, '.claude');
15
- this.recovered = [];
16
- }
17
-
18
- /**
19
- * Ensure ~/.ccs/ directory exists
20
- */
21
- ensureCcsDirectory() {
22
- if (!fs.existsSync(this.ccsDir)) {
23
- fs.mkdirSync(this.ccsDir, { recursive: true, mode: 0o755 });
24
- this.recovered.push('Created ~/.ccs/ directory');
25
- return true;
26
- }
27
- return false;
28
- }
29
-
30
- /**
31
- * Ensure ~/.ccs/config.json exists with defaults
32
- */
33
- ensureConfigJson() {
34
- const configPath = path.join(this.ccsDir, 'config.json');
35
-
36
- // Check if exists and valid
37
- if (fs.existsSync(configPath)) {
38
- try {
39
- const content = fs.readFileSync(configPath, 'utf8');
40
- JSON.parse(content); // Validate JSON
41
- return false; // No recovery needed
42
- } catch (e) {
43
- // Corrupted - backup and recreate
44
- const backupPath = `${configPath}.backup.${Date.now()}`;
45
- fs.renameSync(configPath, backupPath);
46
- this.recovered.push(`Backed up corrupted config.json to ${path.basename(backupPath)}`);
47
- }
48
- }
49
-
50
- // Create default config
51
- const defaultConfig = {
52
- profiles: {
53
- glm: '~/.ccs/glm.settings.json',
54
- kimi: '~/.ccs/kimi.settings.json',
55
- default: '~/.claude/settings.json'
56
- }
57
- };
58
-
59
- const tmpPath = `${configPath}.tmp`;
60
- fs.writeFileSync(tmpPath, JSON.stringify(defaultConfig, null, 2) + '\n', 'utf8');
61
- fs.renameSync(tmpPath, configPath);
62
-
63
- this.recovered.push('Created ~/.ccs/config.json');
64
- return true;
65
- }
66
-
67
- /**
68
- * Ensure ~/.claude/settings.json exists
69
- */
70
- ensureClaudeSettings() {
71
- const claudeSettingsPath = path.join(this.claudeDir, 'settings.json');
72
-
73
- // Create ~/.claude/ if missing
74
- if (!fs.existsSync(this.claudeDir)) {
75
- fs.mkdirSync(this.claudeDir, { recursive: true, mode: 0o755 });
76
- this.recovered.push('Created ~/.claude/ directory');
77
- }
78
-
79
- // Create settings.json if missing
80
- if (!fs.existsSync(claudeSettingsPath)) {
81
- const tmpPath = `${claudeSettingsPath}.tmp`;
82
- fs.writeFileSync(tmpPath, '{}\n', 'utf8');
83
- fs.renameSync(tmpPath, claudeSettingsPath);
84
-
85
- this.recovered.push('Created ~/.claude/settings.json');
86
- return true;
87
- }
88
-
89
- return false;
90
- }
91
-
92
- /**
93
- * Run all recovery operations
94
- * @returns {boolean} True if any recovery performed
95
- */
96
- recoverAll() {
97
- this.recovered = [];
98
-
99
- this.ensureCcsDirectory();
100
- this.ensureConfigJson();
101
- this.ensureClaudeSettings();
102
-
103
- return this.recovered.length > 0;
104
- }
105
-
106
- /**
107
- * Get recovery summary
108
- * @returns {string[]} List of recovery actions performed
109
- */
110
- getRecoverySummary() {
111
- return this.recovered;
112
- }
113
-
114
- /**
115
- * Show recovery hints
116
- */
117
- showRecoveryHints() {
118
- if (this.recovered.length === 0) return;
119
-
120
- console.log('');
121
- console.log('[i] Auto-recovery completed:');
122
- this.recovered.forEach(msg => console.log(` - ${msg}`));
123
-
124
- // Show login hint if created Claude settings
125
- if (this.recovered.some(msg => msg.includes('settings.json'))) {
126
- console.log('');
127
- console.log('[i] Next step: Login to Claude CLI');
128
- console.log(' Run: claude /login');
129
- }
130
-
131
- console.log('');
132
- }
133
- }
134
-
135
- module.exports = RecoveryManager;