@claude-flow/cli 3.0.0-alpha.11 → 3.0.0-alpha.12

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 (51) hide show
  1. package/.agentic-flow/intelligence.json +4 -4
  2. package/.claude-flow/daemon-state.json +25 -25
  3. package/.claude-flow/metrics/codebase-map.json +2 -2
  4. package/.claude-flow/metrics/consolidation.json +1 -1
  5. package/.claude-flow/metrics/performance.json +3 -3
  6. package/.claude-flow/metrics/security-audit.json +1 -1
  7. package/.claude-flow/metrics/task-metrics.json +3 -3
  8. package/.claude-flow/metrics/test-gaps.json +1 -1
  9. package/README.md +172 -6
  10. package/agents/architect.yaml +1 -1
  11. package/agents/coder.yaml +1 -1
  12. package/agents/reviewer.yaml +1 -1
  13. package/agents/security-architect.yaml +1 -1
  14. package/agents/tester.yaml +1 -1
  15. package/dist/src/commands/completions.d.ts +10 -0
  16. package/dist/src/commands/completions.d.ts.map +1 -0
  17. package/dist/src/commands/completions.js +539 -0
  18. package/dist/src/commands/completions.js.map +1 -0
  19. package/dist/src/commands/doctor.d.ts +10 -0
  20. package/dist/src/commands/doctor.d.ts.map +1 -0
  21. package/dist/src/commands/doctor.js +352 -0
  22. package/dist/src/commands/doctor.js.map +1 -0
  23. package/dist/src/commands/embeddings.d.ts +8 -0
  24. package/dist/src/commands/embeddings.d.ts.map +1 -1
  25. package/dist/src/commands/embeddings.js +328 -6
  26. package/dist/src/commands/embeddings.js.map +1 -1
  27. package/dist/src/commands/index.d.ts +2 -0
  28. package/dist/src/commands/index.d.ts.map +1 -1
  29. package/dist/src/commands/index.js +9 -0
  30. package/dist/src/commands/index.js.map +1 -1
  31. package/dist/src/commands/memory.js +2 -2
  32. package/dist/src/commands/memory.js.map +1 -1
  33. package/dist/src/commands/neural.js +1 -1
  34. package/dist/src/commands/neural.js.map +1 -1
  35. package/dist/src/index.d.ts.map +1 -1
  36. package/dist/src/index.js +15 -2
  37. package/dist/src/index.js.map +1 -1
  38. package/dist/src/suggest.d.ts +53 -0
  39. package/dist/src/suggest.d.ts.map +1 -0
  40. package/dist/src/suggest.js +200 -0
  41. package/dist/src/suggest.js.map +1 -0
  42. package/dist/tsconfig.tsbuildinfo +1 -1
  43. package/package.json +1 -1
  44. package/src/commands/completions.ts +558 -0
  45. package/src/commands/doctor.ts +378 -0
  46. package/src/commands/embeddings.ts +360 -6
  47. package/src/commands/index.ts +9 -0
  48. package/src/commands/memory.ts +2 -2
  49. package/src/commands/neural.ts +1 -1
  50. package/src/index.ts +15 -3
  51. package/src/suggest.ts +245 -0
@@ -0,0 +1,378 @@
1
+ /**
2
+ * V3 CLI Doctor Command
3
+ * System diagnostics, dependency checks, config validation
4
+ *
5
+ * Created with ruv.io
6
+ */
7
+
8
+ import type { Command, CommandContext, CommandResult } from '../types.js';
9
+ import { output } from '../output.js';
10
+ import { existsSync, readFileSync } from 'fs';
11
+ import { join } from 'path';
12
+ import { execSync } from 'child_process';
13
+
14
+ interface HealthCheck {
15
+ name: string;
16
+ status: 'pass' | 'warn' | 'fail';
17
+ message: string;
18
+ fix?: string;
19
+ }
20
+
21
+ // Check Node.js version
22
+ async function checkNodeVersion(): Promise<HealthCheck> {
23
+ const requiredMajor = 20;
24
+ const version = process.version;
25
+ const major = parseInt(version.slice(1).split('.')[0], 10);
26
+
27
+ if (major >= requiredMajor) {
28
+ return { name: 'Node.js Version', status: 'pass', message: `${version} (>= ${requiredMajor} required)` };
29
+ } else if (major >= 18) {
30
+ return { name: 'Node.js Version', status: 'warn', message: `${version} (>= ${requiredMajor} recommended)`, fix: 'nvm install 20 && nvm use 20' };
31
+ } else {
32
+ return { name: 'Node.js Version', status: 'fail', message: `${version} (>= ${requiredMajor} required)`, fix: 'nvm install 20 && nvm use 20' };
33
+ }
34
+ }
35
+
36
+ // Check npm version
37
+ async function checkNpmVersion(): Promise<HealthCheck> {
38
+ try {
39
+ const version = execSync('npm --version', { encoding: 'utf8' }).trim();
40
+ const major = parseInt(version.split('.')[0], 10);
41
+ if (major >= 9) {
42
+ return { name: 'npm Version', status: 'pass', message: `v${version}` };
43
+ } else {
44
+ return { name: 'npm Version', status: 'warn', message: `v${version} (>= 9 recommended)`, fix: 'npm install -g npm@latest' };
45
+ }
46
+ } catch {
47
+ return { name: 'npm Version', status: 'fail', message: 'npm not found', fix: 'Install Node.js from https://nodejs.org' };
48
+ }
49
+ }
50
+
51
+ // Check config file
52
+ async function checkConfigFile(): Promise<HealthCheck> {
53
+ const configPaths = [
54
+ '.claude-flow/config.json',
55
+ 'claude-flow.config.json',
56
+ '.claude-flow.json'
57
+ ];
58
+
59
+ for (const configPath of configPaths) {
60
+ if (existsSync(configPath)) {
61
+ try {
62
+ const content = readFileSync(configPath, 'utf8');
63
+ JSON.parse(content);
64
+ return { name: 'Config File', status: 'pass', message: `Found: ${configPath}` };
65
+ } catch (e) {
66
+ return { name: 'Config File', status: 'fail', message: `Invalid JSON: ${configPath}`, fix: 'Fix JSON syntax in config file' };
67
+ }
68
+ }
69
+ }
70
+
71
+ return { name: 'Config File', status: 'warn', message: 'No config file (using defaults)', fix: 'claude-flow config init' };
72
+ }
73
+
74
+ // Check daemon status
75
+ async function checkDaemonStatus(): Promise<HealthCheck> {
76
+ try {
77
+ const pidFile = '.claude-flow/daemon.pid';
78
+ if (existsSync(pidFile)) {
79
+ const pid = readFileSync(pidFile, 'utf8').trim();
80
+ try {
81
+ process.kill(parseInt(pid, 10), 0); // Check if process exists
82
+ return { name: 'Daemon Status', status: 'pass', message: `Running (PID: ${pid})` };
83
+ } catch {
84
+ return { name: 'Daemon Status', status: 'warn', message: 'Stale PID file', fix: 'rm .claude-flow/daemon.pid && claude-flow daemon start' };
85
+ }
86
+ }
87
+ return { name: 'Daemon Status', status: 'warn', message: 'Not running', fix: 'claude-flow daemon start' };
88
+ } catch {
89
+ return { name: 'Daemon Status', status: 'warn', message: 'Unable to check', fix: 'claude-flow daemon status' };
90
+ }
91
+ }
92
+
93
+ // Check memory database
94
+ async function checkMemoryDatabase(): Promise<HealthCheck> {
95
+ const dbPaths = [
96
+ '.claude-flow/memory.db',
97
+ '.swarm/memory.db',
98
+ 'data/memory.db'
99
+ ];
100
+
101
+ for (const dbPath of dbPaths) {
102
+ if (existsSync(dbPath)) {
103
+ try {
104
+ const stats = require('fs').statSync(dbPath);
105
+ const sizeMB = (stats.size / 1024 / 1024).toFixed(2);
106
+ return { name: 'Memory Database', status: 'pass', message: `${dbPath} (${sizeMB} MB)` };
107
+ } catch {
108
+ return { name: 'Memory Database', status: 'warn', message: `${dbPath} (unable to stat)` };
109
+ }
110
+ }
111
+ }
112
+
113
+ return { name: 'Memory Database', status: 'warn', message: 'Not initialized', fix: 'claude-flow memory configure --backend hybrid' };
114
+ }
115
+
116
+ // Check API keys
117
+ async function checkApiKeys(): Promise<HealthCheck> {
118
+ const keys = ['ANTHROPIC_API_KEY', 'CLAUDE_API_KEY', 'OPENAI_API_KEY'];
119
+ const found: string[] = [];
120
+
121
+ for (const key of keys) {
122
+ if (process.env[key]) {
123
+ found.push(key);
124
+ }
125
+ }
126
+
127
+ if (found.includes('ANTHROPIC_API_KEY') || found.includes('CLAUDE_API_KEY')) {
128
+ return { name: 'API Keys', status: 'pass', message: `Found: ${found.join(', ')}` };
129
+ } else if (found.length > 0) {
130
+ return { name: 'API Keys', status: 'warn', message: `Found: ${found.join(', ')} (no Claude key)`, fix: 'export ANTHROPIC_API_KEY=your_key' };
131
+ } else {
132
+ return { name: 'API Keys', status: 'warn', message: 'No API keys found', fix: 'export ANTHROPIC_API_KEY=your_key' };
133
+ }
134
+ }
135
+
136
+ // Check git
137
+ async function checkGit(): Promise<HealthCheck> {
138
+ try {
139
+ const version = execSync('git --version', { encoding: 'utf8' }).trim();
140
+ return { name: 'Git', status: 'pass', message: version.replace('git version ', 'v') };
141
+ } catch {
142
+ return { name: 'Git', status: 'warn', message: 'Not installed', fix: 'Install git from https://git-scm.com' };
143
+ }
144
+ }
145
+
146
+ // Check if in git repo
147
+ async function checkGitRepo(): Promise<HealthCheck> {
148
+ try {
149
+ execSync('git rev-parse --git-dir', { encoding: 'utf8', stdio: 'pipe' });
150
+ return { name: 'Git Repository', status: 'pass', message: 'In a git repository' };
151
+ } catch {
152
+ return { name: 'Git Repository', status: 'warn', message: 'Not a git repository', fix: 'git init' };
153
+ }
154
+ }
155
+
156
+ // Check MCP servers
157
+ async function checkMcpServers(): Promise<HealthCheck> {
158
+ const mcpConfigPaths = [
159
+ join(process.env.HOME || '', '.claude/claude_desktop_config.json'),
160
+ join(process.env.HOME || '', '.config/claude/mcp.json'),
161
+ '.mcp.json'
162
+ ];
163
+
164
+ for (const configPath of mcpConfigPaths) {
165
+ if (existsSync(configPath)) {
166
+ try {
167
+ const content = JSON.parse(readFileSync(configPath, 'utf8'));
168
+ const servers = content.mcpServers || content.servers || {};
169
+ const count = Object.keys(servers).length;
170
+ const hasClaudeFlow = 'claude-flow' in servers || 'claude-flow_alpha' in servers;
171
+ if (hasClaudeFlow) {
172
+ return { name: 'MCP Servers', status: 'pass', message: `${count} servers (claude-flow configured)` };
173
+ } else {
174
+ return { name: 'MCP Servers', status: 'warn', message: `${count} servers (claude-flow not found)`, fix: 'claude mcp add claude-flow npx @claude-flow/cli@v3alpha mcp start' };
175
+ }
176
+ } catch {
177
+ // continue to next path
178
+ }
179
+ }
180
+ }
181
+
182
+ return { name: 'MCP Servers', status: 'warn', message: 'No MCP config found', fix: 'claude mcp add claude-flow npx @claude-flow/cli@v3alpha mcp start' };
183
+ }
184
+
185
+ // Check disk space
186
+ async function checkDiskSpace(): Promise<HealthCheck> {
187
+ try {
188
+ if (process.platform === 'win32') {
189
+ return { name: 'Disk Space', status: 'pass', message: 'Check skipped on Windows' };
190
+ }
191
+ const output_str = execSync('df -h . | tail -1', { encoding: 'utf8' });
192
+ const parts = output_str.split(/\s+/);
193
+ const available = parts[3];
194
+ const usePercent = parseInt(parts[4]?.replace('%', '') || '0', 10);
195
+
196
+ if (usePercent > 90) {
197
+ return { name: 'Disk Space', status: 'fail', message: `${available} available (${usePercent}% used)`, fix: 'Free up disk space' };
198
+ } else if (usePercent > 80) {
199
+ return { name: 'Disk Space', status: 'warn', message: `${available} available (${usePercent}% used)` };
200
+ }
201
+ return { name: 'Disk Space', status: 'pass', message: `${available} available` };
202
+ } catch {
203
+ return { name: 'Disk Space', status: 'warn', message: 'Unable to check' };
204
+ }
205
+ }
206
+
207
+ // Check TypeScript/build
208
+ async function checkBuildTools(): Promise<HealthCheck> {
209
+ try {
210
+ const tscVersion = execSync('npx tsc --version 2>/dev/null || echo "not found"', { encoding: 'utf8' }).trim();
211
+ if (tscVersion.includes('not found')) {
212
+ return { name: 'TypeScript', status: 'warn', message: 'Not installed locally', fix: 'npm install -D typescript' };
213
+ }
214
+ return { name: 'TypeScript', status: 'pass', message: tscVersion.replace('Version ', 'v') };
215
+ } catch {
216
+ return { name: 'TypeScript', status: 'warn', message: 'Unable to check' };
217
+ }
218
+ }
219
+
220
+ // Format health check result
221
+ function formatCheck(check: HealthCheck): string {
222
+ const icon = check.status === 'pass' ? output.success('✓') :
223
+ check.status === 'warn' ? output.warning('⚠') :
224
+ output.error('✗');
225
+ return `${icon} ${check.name}: ${check.message}`;
226
+ }
227
+
228
+ // Main doctor command
229
+ export const doctorCommand: Command = {
230
+ name: 'doctor',
231
+ description: 'System diagnostics and health checks',
232
+ options: [
233
+ {
234
+ name: 'fix',
235
+ short: 'f',
236
+ description: 'Show fix commands for issues',
237
+ type: 'boolean',
238
+ default: false
239
+ },
240
+ {
241
+ name: 'component',
242
+ short: 'c',
243
+ description: 'Check specific component (node, config, daemon, memory, api, git, mcp)',
244
+ type: 'string'
245
+ },
246
+ {
247
+ name: 'verbose',
248
+ short: 'v',
249
+ description: 'Verbose output',
250
+ type: 'boolean',
251
+ default: false
252
+ }
253
+ ],
254
+ examples: [
255
+ { command: 'claude-flow doctor', description: 'Run full health check' },
256
+ { command: 'claude-flow doctor --fix', description: 'Show fixes for issues' },
257
+ { command: 'claude-flow doctor -c daemon', description: 'Check specific component' }
258
+ ],
259
+ action: async (ctx: CommandContext): Promise<CommandResult> => {
260
+ const showFix = ctx.flags.fix as boolean;
261
+ const component = ctx.flags.component as string;
262
+ const verbose = ctx.flags.verbose as boolean;
263
+
264
+ output.writeln();
265
+ output.writeln(output.bold('Claude Flow Doctor'));
266
+ output.writeln(output.dim('System diagnostics and health check'));
267
+ output.writeln(output.dim('─'.repeat(50)));
268
+ output.writeln();
269
+
270
+ const allChecks: (() => Promise<HealthCheck>)[] = [
271
+ checkNodeVersion,
272
+ checkNpmVersion,
273
+ checkGit,
274
+ checkGitRepo,
275
+ checkConfigFile,
276
+ checkDaemonStatus,
277
+ checkMemoryDatabase,
278
+ checkApiKeys,
279
+ checkMcpServers,
280
+ checkDiskSpace,
281
+ checkBuildTools
282
+ ];
283
+
284
+ const componentMap: Record<string, () => Promise<HealthCheck>> = {
285
+ 'node': checkNodeVersion,
286
+ 'npm': checkNpmVersion,
287
+ 'config': checkConfigFile,
288
+ 'daemon': checkDaemonStatus,
289
+ 'memory': checkMemoryDatabase,
290
+ 'api': checkApiKeys,
291
+ 'git': checkGit,
292
+ 'mcp': checkMcpServers,
293
+ 'disk': checkDiskSpace,
294
+ 'typescript': checkBuildTools
295
+ };
296
+
297
+ let checksToRun = allChecks;
298
+ if (component && componentMap[component]) {
299
+ checksToRun = [componentMap[component]];
300
+ }
301
+
302
+ const results: HealthCheck[] = [];
303
+ const fixes: string[] = [];
304
+
305
+ for (const check of checksToRun) {
306
+ const spinner = output.createSpinner({ text: 'Checking...', spinner: 'dots' });
307
+ spinner.start();
308
+
309
+ try {
310
+ const result = await check();
311
+ results.push(result);
312
+
313
+ spinner.stop();
314
+ output.writeln(formatCheck(result));
315
+
316
+ if (result.fix && (result.status === 'fail' || result.status === 'warn')) {
317
+ fixes.push(`${result.name}: ${result.fix}`);
318
+ }
319
+ } catch (error) {
320
+ spinner.stop();
321
+ const errorResult: HealthCheck = {
322
+ name: 'Check',
323
+ status: 'fail',
324
+ message: error instanceof Error ? error.message : 'Unknown error'
325
+ };
326
+ results.push(errorResult);
327
+ output.writeln(formatCheck(errorResult));
328
+ }
329
+ }
330
+
331
+ // Summary
332
+ const passed = results.filter(r => r.status === 'pass').length;
333
+ const warnings = results.filter(r => r.status === 'warn').length;
334
+ const failed = results.filter(r => r.status === 'fail').length;
335
+
336
+ output.writeln();
337
+ output.writeln(output.dim('─'.repeat(50)));
338
+ output.writeln();
339
+
340
+ const summaryParts = [
341
+ output.success(`${passed} passed`),
342
+ warnings > 0 ? output.warning(`${warnings} warnings`) : null,
343
+ failed > 0 ? output.error(`${failed} failed`) : null
344
+ ].filter(Boolean);
345
+
346
+ output.writeln(`Summary: ${summaryParts.join(', ')}`);
347
+
348
+ // Show fixes
349
+ if (showFix && fixes.length > 0) {
350
+ output.writeln();
351
+ output.writeln(output.bold('Suggested Fixes:'));
352
+ output.writeln();
353
+ for (const fix of fixes) {
354
+ output.writeln(output.dim(` ${fix}`));
355
+ }
356
+ } else if (fixes.length > 0 && !showFix) {
357
+ output.writeln();
358
+ output.writeln(output.dim(`Run with --fix to see ${fixes.length} suggested fix${fixes.length > 1 ? 'es' : ''}`));
359
+ }
360
+
361
+ // Overall result
362
+ if (failed > 0) {
363
+ output.writeln();
364
+ output.writeln(output.error('Some checks failed. Please address the issues above.'));
365
+ return { success: false, exitCode: 1, data: { passed, warnings, failed, results } };
366
+ } else if (warnings > 0) {
367
+ output.writeln();
368
+ output.writeln(output.warning('All checks passed with some warnings.'));
369
+ return { success: true, data: { passed, warnings, failed, results } };
370
+ } else {
371
+ output.writeln();
372
+ output.writeln(output.success('All checks passed! System is healthy.'));
373
+ return { success: true, data: { passed, warnings, failed, results } };
374
+ }
375
+ }
376
+ };
377
+
378
+ export default doctorCommand;