@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,721 +0,0 @@
1
- 'use strict';
2
-
3
- const fs = require('fs');
4
- const path = require('path');
5
- const os = require('os');
6
- const { spawn } = require('child_process');
7
- const { colored } = require('../utils/helpers');
8
- const { detectClaudeCli } = require('../utils/claude-detector');
9
-
10
- // Make ora optional (might not be available during npm install postinstall)
11
- // ora v9+ is an ES module, need to use .default for CommonJS
12
- let ora = null;
13
- try {
14
- const oraModule = require('ora');
15
- ora = oraModule.default || oraModule;
16
- } catch (e) {
17
- // ora not available, create fallback spinner that uses console.log
18
- ora = function(text) {
19
- return {
20
- start: () => ({
21
- succeed: (msg) => console.log(msg || `[OK] ${text}`),
22
- fail: (msg) => console.log(msg || `[X] ${text}`),
23
- warn: (msg) => console.log(msg || `[!] ${text}`),
24
- info: (msg) => console.log(msg || `[i] ${text}`),
25
- text: ''
26
- })
27
- };
28
- };
29
- }
30
-
31
- const Table = require('cli-table3');
32
-
33
- /**
34
- * Health check results
35
- */
36
- class HealthCheck {
37
- constructor() {
38
- this.checks = [];
39
- this.warnings = [];
40
- this.errors = [];
41
- this.details = {}; // Store detailed information for summary table
42
- }
43
-
44
- addCheck(name, status, message = '', fix = null, details = null) {
45
- this.checks.push({ name, status, message, fix });
46
-
47
- if (status === 'error') this.errors.push({ name, message, fix });
48
- if (status === 'warning') this.warnings.push({ name, message, fix });
49
-
50
- // Store details for summary table
51
- if (details) {
52
- this.details[name] = details;
53
- }
54
- }
55
-
56
- hasErrors() {
57
- return this.errors.length > 0;
58
- }
59
-
60
- hasWarnings() {
61
- return this.warnings.length > 0;
62
- }
63
-
64
- isHealthy() {
65
- return !this.hasErrors();
66
- }
67
- }
68
-
69
- /**
70
- * CCS Health Check and Diagnostics
71
- */
72
- class Doctor {
73
- constructor() {
74
- this.homedir = os.homedir();
75
- this.ccsDir = path.join(this.homedir, '.ccs');
76
- this.claudeDir = path.join(this.homedir, '.claude');
77
- this.results = new HealthCheck();
78
-
79
- // Get CCS version
80
- try {
81
- this.ccsVersion = require('../../package.json').version;
82
- } catch (e) {
83
- this.ccsVersion = 'unknown';
84
- }
85
- }
86
-
87
- /**
88
- * Run all health checks
89
- */
90
- async runAllChecks() {
91
- console.log(colored('Running CCS Health Check...', 'cyan'));
92
- console.log('');
93
-
94
- // Store CCS version in details
95
- this.results.details['CCS Version'] = { status: 'OK', info: `v${this.ccsVersion}` };
96
-
97
- // Group 1: System
98
- console.log(colored('System:', 'bold'));
99
- await this.checkClaudeCli();
100
- this.checkCcsDirectory();
101
- console.log('');
102
-
103
- // Group 2: Configuration
104
- console.log(colored('Configuration:', 'bold'));
105
- this.checkConfigFiles();
106
- this.checkClaudeSettings();
107
- console.log('');
108
-
109
- // Group 3: Profiles & Delegation
110
- console.log(colored('Profiles & Delegation:', 'bold'));
111
- this.checkProfiles();
112
- this.checkInstances();
113
- this.checkDelegation();
114
- console.log('');
115
-
116
- // Group 4: System Health
117
- console.log(colored('System Health:', 'bold'));
118
- this.checkPermissions();
119
- this.checkCcsSymlinks();
120
- this.checkSettingsSymlinks();
121
- console.log('');
122
-
123
- this.showReport();
124
- return this.results;
125
- }
126
-
127
- /**
128
- * Check 1: Claude CLI availability
129
- */
130
- async checkClaudeCli() {
131
- const spinner = ora('Checking Claude CLI').start();
132
-
133
- const claudeCli = detectClaudeCli();
134
-
135
- // Try to execute claude --version
136
- try {
137
- const result = await new Promise((resolve, reject) => {
138
- const child = spawn(claudeCli, ['--version'], {
139
- stdio: 'pipe',
140
- timeout: 5000
141
- });
142
-
143
- let output = '';
144
- child.stdout.on('data', data => output += data);
145
- child.stderr.on('data', data => output += data);
146
-
147
- child.on('close', code => {
148
- if (code === 0) resolve(output);
149
- else reject(new Error('Exit code ' + code));
150
- });
151
-
152
- child.on('error', reject);
153
- });
154
-
155
- // Extract version from output
156
- const versionMatch = result.match(/(\d+\.\d+\.\d+)/);
157
- const version = versionMatch ? versionMatch[1] : 'unknown';
158
-
159
- spinner.succeed(` ${'Claude CLI'.padEnd(26)}${colored('[OK]', 'green')} ${claudeCli} (v${version})`);
160
- this.results.addCheck('Claude CLI', 'success', `Found: ${claudeCli}`, null, {
161
- status: 'OK',
162
- info: `v${version} (${claudeCli})`
163
- });
164
- } catch (err) {
165
- spinner.fail(` ${'Claude CLI'.padEnd(26)}${colored('[X]', 'red')} Not found or not working`);
166
- this.results.addCheck(
167
- 'Claude CLI',
168
- 'error',
169
- 'Claude CLI not found or not working',
170
- 'Install from: https://docs.claude.com/en/docs/claude-code/installation',
171
- { status: 'ERROR', info: 'Not installed' }
172
- );
173
- }
174
- }
175
-
176
- /**
177
- * Check 2: ~/.ccs/ directory
178
- */
179
- checkCcsDirectory() {
180
- const spinner = ora('Checking ~/.ccs/ directory').start();
181
-
182
- if (fs.existsSync(this.ccsDir)) {
183
- spinner.succeed(` ${'CCS Directory'.padEnd(26)}${colored('[OK]', 'green')} ~/.ccs/`);
184
- this.results.addCheck('CCS Directory', 'success', null, null, {
185
- status: 'OK',
186
- info: '~/.ccs/'
187
- });
188
- } else {
189
- spinner.fail(` ${'CCS Directory'.padEnd(26)}${colored('[X]', 'red')} Not found`);
190
- this.results.addCheck(
191
- 'CCS Directory',
192
- 'error',
193
- '~/.ccs/ directory not found',
194
- 'Run: npm install -g @kaitranntt/ccs --force',
195
- { status: 'ERROR', info: 'Not found' }
196
- );
197
- }
198
- }
199
-
200
- /**
201
- * Check 3: Config files
202
- */
203
- checkConfigFiles() {
204
- const files = [
205
- { path: path.join(this.ccsDir, 'config.json'), name: 'config.json', key: 'config.json' },
206
- { path: path.join(this.ccsDir, 'glm.settings.json'), name: 'glm.settings.json', key: 'GLM Settings', profile: 'glm' },
207
- { path: path.join(this.ccsDir, 'kimi.settings.json'), name: 'kimi.settings.json', key: 'Kimi Settings', profile: 'kimi' }
208
- ];
209
-
210
- const { DelegationValidator } = require('../utils/delegation-validator');
211
-
212
- for (const file of files) {
213
- const spinner = ora(`Checking ${file.name}`).start();
214
-
215
- if (!fs.existsSync(file.path)) {
216
- spinner.fail(` ${file.name.padEnd(26)}${colored('[X]', 'red')} Not found`);
217
- this.results.addCheck(
218
- file.name,
219
- 'error',
220
- `${file.name} not found`,
221
- 'Run: npm install -g @kaitranntt/ccs --force',
222
- { status: 'ERROR', info: 'Not found' }
223
- );
224
- continue;
225
- }
226
-
227
- // Validate JSON
228
- try {
229
- const content = fs.readFileSync(file.path, 'utf8');
230
- const config = JSON.parse(content);
231
-
232
- // Extract useful info based on file type
233
- let info = 'Valid';
234
- let status = 'OK';
235
-
236
- if (file.profile) {
237
- // For settings files, check if API key is configured
238
- const validation = DelegationValidator.validate(file.profile);
239
-
240
- if (validation.valid) {
241
- info = 'Key configured';
242
- status = 'OK';
243
- } else if (validation.error && validation.error.includes('placeholder')) {
244
- info = 'Placeholder key (not configured)';
245
- status = 'WARN';
246
- } else {
247
- info = 'Valid JSON';
248
- status = 'OK';
249
- }
250
- }
251
-
252
- const statusIcon = status === 'OK' ? colored('[OK]', 'green') : colored('[!]', 'yellow');
253
-
254
- if (status === 'WARN') {
255
- spinner.warn(` ${file.name.padEnd(26)}${statusIcon} ${info}`);
256
- } else {
257
- spinner.succeed(` ${file.name.padEnd(26)}${statusIcon} ${info}`);
258
- }
259
-
260
- this.results.addCheck(file.name, status === 'OK' ? 'success' : 'warning', null, null, {
261
- status: status,
262
- info: info
263
- });
264
- } catch (e) {
265
- spinner.fail(` ${file.name.padEnd(26)}${colored('[X]', 'red')} Invalid JSON`);
266
- this.results.addCheck(
267
- file.name,
268
- 'error',
269
- `Invalid JSON: ${e.message}`,
270
- `Backup and recreate: mv ${file.path} ${file.path}.backup && npm install -g @kaitranntt/ccs --force`,
271
- { status: 'ERROR', info: 'Invalid JSON' }
272
- );
273
- }
274
- }
275
- }
276
-
277
- /**
278
- * Check 4: Claude settings
279
- */
280
- checkClaudeSettings() {
281
- const spinner = ora('Checking ~/.claude/settings.json').start();
282
- const settingsPath = path.join(this.claudeDir, 'settings.json');
283
-
284
- if (!fs.existsSync(settingsPath)) {
285
- spinner.warn(` ${'~/.claude/settings.json'.padEnd(26)}${colored('[!]', 'yellow')} Not found`);
286
- this.results.addCheck(
287
- 'Claude Settings',
288
- 'warning',
289
- '~/.claude/settings.json not found',
290
- 'Run: claude /login'
291
- );
292
- return;
293
- }
294
-
295
- // Validate JSON
296
- try {
297
- const content = fs.readFileSync(settingsPath, 'utf8');
298
- JSON.parse(content);
299
- spinner.succeed(` ${'~/.claude/settings.json'.padEnd(26)}${colored('[OK]', 'green')}`);
300
- this.results.addCheck('Claude Settings', 'success');
301
- } catch (e) {
302
- spinner.warn(` ${'~/.claude/settings.json'.padEnd(26)}${colored('[!]', 'yellow')} Invalid JSON`);
303
- this.results.addCheck(
304
- 'Claude Settings',
305
- 'warning',
306
- `Invalid JSON: ${e.message}`,
307
- 'Run: claude /login'
308
- );
309
- }
310
- }
311
-
312
- /**
313
- * Check 5: Profile configurations
314
- */
315
- checkProfiles() {
316
- const spinner = ora('Checking profiles').start();
317
- const configPath = path.join(this.ccsDir, 'config.json');
318
-
319
- if (!fs.existsSync(configPath)) {
320
- spinner.info(` ${'Profiles'.padEnd(26)}${colored('[SKIP]', 'cyan')} config.json not found`);
321
- return;
322
- }
323
-
324
- try {
325
- const config = JSON.parse(fs.readFileSync(configPath, 'utf8'));
326
-
327
- if (!config.profiles || typeof config.profiles !== 'object') {
328
- spinner.fail(` ${'Profiles'.padEnd(26)}${colored('[X]', 'red')} Missing profiles object`);
329
- this.results.addCheck(
330
- 'Profiles',
331
- 'error',
332
- 'config.json missing profiles object',
333
- 'Run: npm install -g @kaitranntt/ccs --force',
334
- { status: 'ERROR', info: 'Missing profiles object' }
335
- );
336
- return;
337
- }
338
-
339
- const profileCount = Object.keys(config.profiles).length;
340
- const profileNames = Object.keys(config.profiles).join(', ');
341
-
342
- spinner.succeed(` ${'Profiles'.padEnd(26)}${colored('[OK]', 'green')} ${profileCount} configured (${profileNames})`);
343
- this.results.addCheck('Profiles', 'success', `${profileCount} profiles configured`, null, {
344
- status: 'OK',
345
- info: `${profileCount} configured (${profileNames.length > 30 ? profileNames.substring(0, 27) + '...' : profileNames})`
346
- });
347
- } catch (e) {
348
- spinner.fail(` ${'Profiles'.padEnd(26)}${colored('[X]', 'red')} ${e.message}`);
349
- this.results.addCheck('Profiles', 'error', e.message, null, {
350
- status: 'ERROR',
351
- info: e.message
352
- });
353
- }
354
- }
355
-
356
- /**
357
- * Check 6: Instance directories (account-based profiles)
358
- */
359
- checkInstances() {
360
- const spinner = ora('Checking instances').start();
361
- const instancesDir = path.join(this.ccsDir, 'instances');
362
-
363
- if (!fs.existsSync(instancesDir)) {
364
- spinner.info(` ${'Instances'.padEnd(26)}${colored('[i]', 'cyan')} No account profiles`);
365
- this.results.addCheck('Instances', 'success', 'No account profiles configured');
366
- return;
367
- }
368
-
369
- const instances = fs.readdirSync(instancesDir).filter(name => {
370
- return fs.statSync(path.join(instancesDir, name)).isDirectory();
371
- });
372
-
373
- if (instances.length === 0) {
374
- spinner.info(` ${'Instances'.padEnd(26)}${colored('[i]', 'cyan')} No account profiles`);
375
- this.results.addCheck('Instances', 'success', 'No account profiles');
376
- return;
377
- }
378
-
379
- spinner.succeed(` ${'Instances'.padEnd(26)}${colored('[OK]', 'green')} ${instances.length} account profiles`);
380
- this.results.addCheck('Instances', 'success', `${instances.length} account profiles`);
381
- }
382
-
383
- /**
384
- * Check 7: Delegation system
385
- */
386
- checkDelegation() {
387
- const spinner = ora('Checking delegation').start();
388
-
389
- // Check if delegation commands exist in ~/.ccs/.claude/commands/
390
- const ccsClaudeCommandsDir = path.join(this.ccsDir, '.claude', 'commands');
391
- const hasCcsCommand = fs.existsSync(path.join(ccsClaudeCommandsDir, 'ccs.md'));
392
- const hasContinueCommand = fs.existsSync(path.join(ccsClaudeCommandsDir, 'ccs', 'continue.md'));
393
-
394
- if (!hasCcsCommand || !hasContinueCommand) {
395
- spinner.warn(` ${'Delegation'.padEnd(26)}${colored('[!]', 'yellow')} Not installed`);
396
- this.results.addCheck(
397
- 'Delegation',
398
- 'warning',
399
- 'Delegation commands not found',
400
- 'Install with: npm install -g @kaitranntt/ccs --force',
401
- { status: 'WARN', info: 'Not installed' }
402
- );
403
- return;
404
- }
405
-
406
- // Check profile validity using DelegationValidator
407
- const { DelegationValidator } = require('../utils/delegation-validator');
408
- const readyProfiles = [];
409
-
410
- for (const profile of ['glm', 'kimi']) {
411
- const validation = DelegationValidator.validate(profile);
412
- if (validation.valid) {
413
- readyProfiles.push(profile);
414
- }
415
- }
416
-
417
- if (readyProfiles.length === 0) {
418
- spinner.warn(` ${'Delegation'.padEnd(26)}${colored('[!]', 'yellow')} No profiles ready`);
419
- this.results.addCheck(
420
- 'Delegation',
421
- 'warning',
422
- 'Delegation installed but no profiles configured',
423
- 'Configure profiles with valid API keys (not placeholders)',
424
- { status: 'WARN', info: 'No profiles ready' }
425
- );
426
- return;
427
- }
428
-
429
- spinner.succeed(` ${'Delegation'.padEnd(26)}${colored('[OK]', 'green')} ${readyProfiles.length} profiles ready (${readyProfiles.join(', ')})`);
430
- this.results.addCheck(
431
- 'Delegation',
432
- 'success',
433
- `${readyProfiles.length} profile(s) ready: ${readyProfiles.join(', ')}`,
434
- null,
435
- { status: 'OK', info: `${readyProfiles.length} profiles ready` }
436
- );
437
- }
438
-
439
- /**
440
- * Check 8: File permissions
441
- */
442
- checkPermissions() {
443
- const spinner = ora('Checking permissions').start();
444
- const testFile = path.join(this.ccsDir, '.permission-test');
445
-
446
- try {
447
- fs.writeFileSync(testFile, 'test', 'utf8');
448
- fs.unlinkSync(testFile);
449
- spinner.succeed(` ${'Permissions'.padEnd(26)}${colored('[OK]', 'green')} Write access verified`);
450
- this.results.addCheck('Permissions', 'success', null, null, {
451
- status: 'OK',
452
- info: 'Write access verified'
453
- });
454
- } catch (e) {
455
- spinner.fail(` ${'Permissions'.padEnd(26)}${colored('[X]', 'red')} Cannot write to ~/.ccs/`);
456
- this.results.addCheck(
457
- 'Permissions',
458
- 'error',
459
- 'Cannot write to ~/.ccs/',
460
- 'Fix: sudo chown -R $USER ~/.ccs ~/.claude && chmod 755 ~/.ccs ~/.claude',
461
- { status: 'ERROR', info: 'Cannot write to ~/.ccs/' }
462
- );
463
- }
464
- }
465
-
466
- /**
467
- * Check 9: CCS symlinks to ~/.claude/
468
- */
469
- checkCcsSymlinks() {
470
- const spinner = ora('Checking CCS symlinks').start();
471
-
472
- try {
473
- const ClaudeSymlinkManager = require('../utils/claude-symlink-manager');
474
- const manager = new ClaudeSymlinkManager();
475
- const health = manager.checkHealth();
476
-
477
- if (health.healthy) {
478
- const itemCount = manager.ccsItems.length;
479
- spinner.succeed(` ${'CCS Symlinks'.padEnd(26)}${colored('[OK]', 'green')} ${itemCount}/${itemCount} items linked`);
480
- this.results.addCheck('CCS Symlinks', 'success', 'All CCS items properly symlinked', null, {
481
- status: 'OK',
482
- info: `${itemCount}/${itemCount} items synced`
483
- });
484
- } else {
485
- spinner.warn(` ${'CCS Symlinks'.padEnd(26)}${colored('[!]', 'yellow')} ${health.issues.length} issues found`);
486
- this.results.addCheck(
487
- 'CCS Symlinks',
488
- 'warning',
489
- health.issues.join(', '),
490
- 'Run: ccs sync',
491
- { status: 'WARN', info: `${health.issues.length} issues` }
492
- );
493
- }
494
- } catch (e) {
495
- spinner.warn(` ${'CCS Symlinks'.padEnd(26)}${colored('[!]', 'yellow')} Could not check`);
496
- this.results.addCheck(
497
- 'CCS Symlinks',
498
- 'warning',
499
- 'Could not check CCS symlinks: ' + e.message,
500
- 'Run: ccs sync',
501
- { status: 'WARN', info: 'Could not check' }
502
- );
503
- }
504
- }
505
-
506
- /**
507
- * Check 10: settings.json symlinks
508
- */
509
- checkSettingsSymlinks() {
510
- const spinner = ora('Checking settings.json symlinks').start();
511
-
512
- try {
513
- const sharedDir = path.join(this.homedir, '.ccs', 'shared');
514
- const sharedSettings = path.join(sharedDir, 'settings.json');
515
- const claudeSettings = path.join(this.claudeDir, 'settings.json');
516
-
517
- // Check shared settings exists and points to ~/.claude/
518
- if (!fs.existsSync(sharedSettings)) {
519
- spinner.warn(` ${'settings.json (shared)'.padEnd(26)}${colored('[!]', 'yellow')} Not found`);
520
- this.results.addCheck(
521
- 'Settings Symlinks',
522
- 'warning',
523
- 'Shared settings.json not found',
524
- 'Run: ccs sync'
525
- );
526
- return;
527
- }
528
-
529
- const sharedStats = fs.lstatSync(sharedSettings);
530
- if (!sharedStats.isSymbolicLink()) {
531
- spinner.warn(` ${'settings.json (shared)'.padEnd(26)}${colored('[!]', 'yellow')} Not a symlink`);
532
- this.results.addCheck(
533
- 'Settings Symlinks',
534
- 'warning',
535
- 'Shared settings.json is not a symlink',
536
- 'Run: ccs sync'
537
- );
538
- return;
539
- }
540
-
541
- const sharedTarget = fs.readlinkSync(sharedSettings);
542
- const resolvedShared = path.resolve(path.dirname(sharedSettings), sharedTarget);
543
-
544
- if (resolvedShared !== claudeSettings) {
545
- spinner.warn(` ${'settings.json (shared)'.padEnd(26)}${colored('[!]', 'yellow')} Wrong target`);
546
- this.results.addCheck(
547
- 'Settings Symlinks',
548
- 'warning',
549
- `Points to ${resolvedShared} instead of ${claudeSettings}`,
550
- 'Run: ccs sync'
551
- );
552
- return;
553
- }
554
-
555
- // Check each instance
556
- const instancesDir = path.join(this.ccsDir, 'instances');
557
- if (!fs.existsSync(instancesDir)) {
558
- spinner.succeed(` ${'settings.json'.padEnd(26)}${colored('[OK]', 'green')} Shared symlink valid`);
559
- this.results.addCheck('Settings Symlinks', 'success', 'Shared symlink valid', null, {
560
- status: 'OK',
561
- info: 'Shared symlink valid'
562
- });
563
- return;
564
- }
565
-
566
- const instances = fs.readdirSync(instancesDir).filter(name => {
567
- return fs.statSync(path.join(instancesDir, name)).isDirectory();
568
- });
569
-
570
- let broken = 0;
571
- for (const instance of instances) {
572
- const instancePath = path.join(instancesDir, instance);
573
- const instanceSettings = path.join(instancePath, 'settings.json');
574
-
575
- if (!fs.existsSync(instanceSettings)) {
576
- broken++;
577
- continue;
578
- }
579
-
580
- try {
581
- const stats = fs.lstatSync(instanceSettings);
582
- if (!stats.isSymbolicLink()) {
583
- broken++;
584
- continue;
585
- }
586
-
587
- const target = fs.readlinkSync(instanceSettings);
588
- const resolved = path.resolve(path.dirname(instanceSettings), target);
589
-
590
- if (resolved !== sharedSettings) {
591
- broken++;
592
- }
593
- } catch (err) {
594
- broken++;
595
- }
596
- }
597
-
598
- if (broken > 0) {
599
- spinner.warn(` ${'settings.json'.padEnd(26)}${colored('[!]', 'yellow')} ${broken} broken instance(s)`);
600
- this.results.addCheck(
601
- 'Settings Symlinks',
602
- 'warning',
603
- `${broken} instance(s) have broken symlinks`,
604
- 'Run: ccs sync',
605
- { status: 'WARN', info: `${broken} broken instance(s)` }
606
- );
607
- } else {
608
- spinner.succeed(` ${'settings.json'.padEnd(26)}${colored('[OK]', 'green')} ${instances.length} instance(s) valid`);
609
- this.results.addCheck('Settings Symlinks', 'success', 'All instance symlinks valid', null, {
610
- status: 'OK',
611
- info: `${instances.length} instance(s) valid`
612
- });
613
- }
614
-
615
- } catch (err) {
616
- spinner.warn(` ${'settings.json'.padEnd(26)}${colored('[!]', 'yellow')} Check failed`);
617
- this.results.addCheck(
618
- 'Settings Symlinks',
619
- 'warning',
620
- `Failed to check: ${err.message}`,
621
- 'Run: ccs sync',
622
- { status: 'WARN', info: 'Check failed' }
623
- );
624
- }
625
- }
626
-
627
- /**
628
- * Show health check report
629
- */
630
- showReport() {
631
- console.log('');
632
-
633
- // Calculate exact table width to match header bars
634
- // colWidths: [20, 10, 35] = 65 + borders (4) = 69 total
635
- const tableWidth = 69;
636
- const headerBar = '═'.repeat(tableWidth);
637
-
638
- console.log(colored(headerBar, 'cyan'));
639
- console.log(colored(' Health Check Summary', 'bold'));
640
- console.log(colored(headerBar, 'cyan'));
641
-
642
- // Create summary table with detailed information
643
- const table = new Table({
644
- head: [colored('Component', 'cyan'), colored('Status', 'cyan'), colored('Details', 'cyan')],
645
- colWidths: [20, 10, 35],
646
- wordWrap: true,
647
- chars: {
648
- 'top': '═', 'top-mid': '╤', 'top-left': '╔', 'top-right': '╗',
649
- 'bottom': '═', 'bottom-mid': '╧', 'bottom-left': '╚', 'bottom-right': '╝',
650
- 'left': '║', 'left-mid': '╟', 'mid': '─', 'mid-mid': '┼',
651
- 'right': '║', 'right-mid': '╢', 'middle': '│'
652
- }
653
- });
654
-
655
- // Populate table with collected details
656
- for (const [component, detail] of Object.entries(this.results.details)) {
657
- const statusColor = detail.status === 'OK' ? 'green' : detail.status === 'ERROR' ? 'red' : 'yellow';
658
- table.push([
659
- component,
660
- colored(detail.status, statusColor),
661
- detail.info || ''
662
- ]);
663
- }
664
-
665
- console.log(table.toString());
666
- console.log('');
667
-
668
- // Show errors and warnings if present
669
- if (this.results.hasErrors()) {
670
- console.log(colored('Errors:', 'red'));
671
- this.results.errors.forEach(err => {
672
- console.log(` [X] ${err.name}: ${err.message}`);
673
- if (err.fix) {
674
- console.log(` Fix: ${err.fix}`);
675
- }
676
- });
677
- console.log('');
678
- }
679
-
680
- if (this.results.hasWarnings()) {
681
- console.log(colored('Warnings:', 'yellow'));
682
- this.results.warnings.forEach(warn => {
683
- console.log(` [!] ${warn.name}: ${warn.message}`);
684
- if (warn.fix) {
685
- console.log(` Fix: ${warn.fix}`);
686
- }
687
- });
688
- console.log('');
689
- }
690
-
691
- // Final status
692
- if (this.results.isHealthy() && !this.results.hasWarnings()) {
693
- console.log(colored('[OK] All checks passed! Your CCS installation is healthy.', 'green'));
694
- } else if (this.results.hasErrors()) {
695
- console.log(colored('[X] Status: Installation has errors', 'red'));
696
- console.log('Run suggested fixes above to resolve issues.');
697
- } else {
698
- console.log(colored('[OK] Status: Installation healthy (warnings only)', 'green'));
699
- }
700
-
701
- console.log('');
702
- }
703
-
704
- /**
705
- * Generate JSON report
706
- */
707
- generateJsonReport() {
708
- return JSON.stringify({
709
- timestamp: new Date().toISOString(),
710
- platform: process.platform,
711
- nodeVersion: process.version,
712
- ccsVersion: require('../package.json').version,
713
- checks: this.results.checks,
714
- errors: this.results.errors,
715
- warnings: this.results.warnings,
716
- healthy: this.results.isHealthy()
717
- }, null, 2);
718
- }
719
- }
720
-
721
- module.exports = Doctor;