@claude-flow/cli 3.0.0-alpha.13 → 3.0.0-alpha.14

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 (102) hide show
  1. package/package.json +12 -4
  2. package/.agentic-flow/intelligence.json +0 -17
  3. package/.claude-flow/agents/store.json +0 -16
  4. package/.claude-flow/daemon-state.json +0 -123
  5. package/.claude-flow/daemon-test.log +0 -0
  6. package/.claude-flow/daemon.log +0 -0
  7. package/.claude-flow/daemon2.log +0 -0
  8. package/.claude-flow/daemon3.log +0 -0
  9. package/.claude-flow/hive-mind/state.json +0 -51
  10. package/.claude-flow/metrics/agent-metrics.json +0 -1
  11. package/.claude-flow/metrics/codebase-map.json +0 -11
  12. package/.claude-flow/metrics/consolidation.json +0 -6
  13. package/.claude-flow/metrics/performance.json +0 -87
  14. package/.claude-flow/metrics/security-audit.json +0 -10
  15. package/.claude-flow/metrics/task-metrics.json +0 -10
  16. package/.claude-flow/metrics/test-gaps.json +0 -6
  17. package/__tests__/README.md +0 -140
  18. package/__tests__/TEST_SUMMARY.md +0 -144
  19. package/__tests__/cli.test.ts +0 -558
  20. package/__tests__/commands.test.ts +0 -726
  21. package/__tests__/config-adapter.test.ts +0 -362
  22. package/__tests__/config-loading.test.ts +0 -106
  23. package/__tests__/coverage/.tmp/coverage-0.json +0 -1
  24. package/__tests__/coverage/.tmp/coverage-1.json +0 -1
  25. package/__tests__/coverage/.tmp/coverage-2.json +0 -1
  26. package/__tests__/coverage/.tmp/coverage-3.json +0 -1
  27. package/__tests__/coverage/.tmp/coverage-4.json +0 -1
  28. package/__tests__/coverage/.tmp/coverage-5.json +0 -1
  29. package/__tests__/mcp-client.test.ts +0 -480
  30. package/__tests__/p1-commands.test.ts +0 -1064
  31. package/agents/architect.yaml +0 -11
  32. package/agents/coder.yaml +0 -11
  33. package/agents/reviewer.yaml +0 -10
  34. package/agents/security-architect.yaml +0 -10
  35. package/agents/tester.yaml +0 -10
  36. package/docs/CONFIG_LOADING.md +0 -236
  37. package/docs/IMPLEMENTATION_COMPLETE.md +0 -421
  38. package/docs/MCP_CLIENT_GUIDE.md +0 -620
  39. package/docs/REFACTORING_SUMMARY.md +0 -247
  40. package/scripts/publish.sh +0 -46
  41. package/src/commands/agent.ts +0 -955
  42. package/src/commands/claims.ts +0 -317
  43. package/src/commands/completions.ts +0 -558
  44. package/src/commands/config.ts +0 -452
  45. package/src/commands/daemon.ts +0 -621
  46. package/src/commands/deployment.ts +0 -323
  47. package/src/commands/doctor.ts +0 -382
  48. package/src/commands/embeddings.ts +0 -686
  49. package/src/commands/hive-mind.ts +0 -928
  50. package/src/commands/hooks.ts +0 -2603
  51. package/src/commands/index.ts +0 -154
  52. package/src/commands/init.ts +0 -597
  53. package/src/commands/mcp.ts +0 -753
  54. package/src/commands/memory.ts +0 -1161
  55. package/src/commands/migrate.ts +0 -447
  56. package/src/commands/neural.ts +0 -253
  57. package/src/commands/performance.ts +0 -292
  58. package/src/commands/plugins.ts +0 -316
  59. package/src/commands/process.ts +0 -695
  60. package/src/commands/providers.ts +0 -259
  61. package/src/commands/security.ts +0 -288
  62. package/src/commands/session.ts +0 -891
  63. package/src/commands/start.ts +0 -457
  64. package/src/commands/status.ts +0 -736
  65. package/src/commands/swarm.ts +0 -648
  66. package/src/commands/task.ts +0 -792
  67. package/src/commands/workflow.ts +0 -742
  68. package/src/config-adapter.ts +0 -210
  69. package/src/index.ts +0 -443
  70. package/src/infrastructure/in-memory-repositories.ts +0 -310
  71. package/src/init/claudemd-generator.ts +0 -631
  72. package/src/init/executor.ts +0 -762
  73. package/src/init/helpers-generator.ts +0 -628
  74. package/src/init/index.ts +0 -60
  75. package/src/init/mcp-generator.ts +0 -83
  76. package/src/init/settings-generator.ts +0 -284
  77. package/src/init/statusline-generator.ts +0 -211
  78. package/src/init/types.ts +0 -447
  79. package/src/mcp-client.ts +0 -241
  80. package/src/mcp-server.ts +0 -577
  81. package/src/mcp-tools/agent-tools.ts +0 -466
  82. package/src/mcp-tools/config-tools.ts +0 -370
  83. package/src/mcp-tools/hive-mind-tools.ts +0 -521
  84. package/src/mcp-tools/hooks-tools.ts +0 -1888
  85. package/src/mcp-tools/index.ts +0 -16
  86. package/src/mcp-tools/memory-tools.ts +0 -270
  87. package/src/mcp-tools/session-tools.ts +0 -359
  88. package/src/mcp-tools/swarm-tools.ts +0 -105
  89. package/src/mcp-tools/task-tools.ts +0 -347
  90. package/src/mcp-tools/types.ts +0 -33
  91. package/src/mcp-tools/workflow-tools.ts +0 -573
  92. package/src/output.ts +0 -639
  93. package/src/parser.ts +0 -417
  94. package/src/prompt.ts +0 -619
  95. package/src/services/index.ts +0 -15
  96. package/src/services/worker-daemon.ts +0 -726
  97. package/src/suggest.ts +0 -245
  98. package/src/types.ts +0 -287
  99. package/tmp.json +0 -0
  100. package/tsconfig.json +0 -16
  101. package/tsconfig.tsbuildinfo +0 -1
  102. package/vitest.config.ts +0 -13
package/src/mcp-server.ts DELETED
@@ -1,577 +0,0 @@
1
- /**
2
- * V3 CLI MCP Server Management
3
- *
4
- * Provides server lifecycle management for MCP integration:
5
- * - Start/stop/status methods with process management
6
- * - Health check endpoint integration
7
- * - Graceful shutdown handling
8
- * - PID file management for daemon detection
9
- * - Event-based status monitoring
10
- *
11
- * Performance Targets:
12
- * - Server startup: <400ms
13
- * - Health check: <10ms
14
- * - Graceful shutdown: <5s
15
- *
16
- * @module @claude-flow/cli/mcp-server
17
- * @version 3.0.0
18
- */
19
-
20
- import { EventEmitter } from 'events';
21
- import { spawn, ChildProcess } from 'child_process';
22
- import { createServer, Server } from 'http';
23
- import * as path from 'path';
24
- import * as fs from 'fs';
25
- import * as os from 'os';
26
- import { fileURLToPath } from 'url';
27
- import { dirname } from 'path';
28
-
29
- // ESM-compatible __dirname
30
- const __filename = fileURLToPath(import.meta.url);
31
- const __dirname = dirname(__filename);
32
-
33
- /**
34
- * MCP Server configuration
35
- */
36
- export interface MCPServerOptions {
37
- transport?: 'stdio' | 'http' | 'websocket';
38
- host?: string;
39
- port?: number;
40
- pidFile?: string;
41
- logFile?: string;
42
- tools?: string[] | 'all';
43
- daemonize?: boolean;
44
- timeout?: number;
45
- }
46
-
47
- /**
48
- * MCP Server status
49
- */
50
- export interface MCPServerStatus {
51
- running: boolean;
52
- pid?: number;
53
- transport?: string;
54
- host?: string;
55
- port?: number;
56
- uptime?: number;
57
- tools?: number;
58
- startedAt?: string;
59
- health?: {
60
- healthy: boolean;
61
- error?: string;
62
- metrics?: Record<string, number>;
63
- };
64
- }
65
-
66
- /**
67
- * Default configuration
68
- */
69
- const DEFAULT_OPTIONS: Required<MCPServerOptions> = {
70
- transport: 'stdio',
71
- host: 'localhost',
72
- port: 3000,
73
- pidFile: path.join(os.tmpdir(), 'claude-flow-mcp.pid'),
74
- logFile: path.join(os.tmpdir(), 'claude-flow-mcp.log'),
75
- tools: 'all',
76
- daemonize: false,
77
- timeout: 30000,
78
- };
79
-
80
- /**
81
- * MCP Server Manager
82
- *
83
- * Manages the lifecycle of the MCP server process
84
- */
85
- export class MCPServerManager extends EventEmitter {
86
- private options: Required<MCPServerOptions>;
87
- private process?: ChildProcess;
88
- private server?: Server;
89
- private startTime?: Date;
90
- private healthCheckInterval?: NodeJS.Timeout;
91
-
92
- constructor(options: MCPServerOptions = {}) {
93
- super();
94
- this.options = { ...DEFAULT_OPTIONS, ...options };
95
- }
96
-
97
- /**
98
- * Start the MCP server
99
- */
100
- async start(): Promise<MCPServerStatus> {
101
- // Check if already running
102
- const status = await this.getStatus();
103
- if (status.running) {
104
- throw new Error(`MCP Server already running (PID: ${status.pid})`);
105
- }
106
-
107
- const startTime = performance.now();
108
- this.startTime = new Date();
109
-
110
- this.emit('starting', { options: this.options });
111
-
112
- try {
113
- if (this.options.transport === 'stdio') {
114
- // For stdio transport, spawn the server process
115
- await this.startStdioServer();
116
- } else {
117
- // For HTTP/WebSocket, start in-process server
118
- await this.startHttpServer();
119
- }
120
-
121
- const duration = performance.now() - startTime;
122
-
123
- // Write PID file
124
- await this.writePidFile();
125
-
126
- // Start health check monitoring
127
- this.startHealthMonitoring();
128
-
129
- const finalStatus = await this.getStatus();
130
-
131
- this.emit('started', {
132
- ...finalStatus,
133
- startupTime: duration,
134
- });
135
-
136
- return finalStatus;
137
- } catch (error) {
138
- this.emit('error', error);
139
- throw error;
140
- }
141
- }
142
-
143
- /**
144
- * Stop the MCP server
145
- */
146
- async stop(force = false): Promise<void> {
147
- const status = await this.getStatus();
148
-
149
- if (!status.running) {
150
- return;
151
- }
152
-
153
- this.emit('stopping', { force });
154
-
155
- try {
156
- // Stop health monitoring
157
- if (this.healthCheckInterval) {
158
- clearInterval(this.healthCheckInterval);
159
- this.healthCheckInterval = undefined;
160
- }
161
-
162
- if (this.process) {
163
- // Graceful shutdown
164
- if (!force) {
165
- this.process.kill('SIGTERM');
166
- await this.waitForExit(5000);
167
- }
168
-
169
- // Force kill if still running
170
- if (this.process && !this.process.killed) {
171
- this.process.kill('SIGKILL');
172
- }
173
-
174
- this.process = undefined;
175
- }
176
-
177
- if (this.server) {
178
- await new Promise<void>((resolve) => {
179
- this.server!.close(() => resolve());
180
- });
181
- this.server = undefined;
182
- }
183
-
184
- // Remove PID file
185
- await this.removePidFile();
186
-
187
- this.startTime = undefined;
188
- this.emit('stopped');
189
- } catch (error) {
190
- this.emit('error', error);
191
- throw error;
192
- }
193
- }
194
-
195
- /**
196
- * Get server status
197
- */
198
- async getStatus(): Promise<MCPServerStatus> {
199
- // Check PID file
200
- const pid = await this.readPidFile();
201
-
202
- if (!pid) {
203
- return { running: false };
204
- }
205
-
206
- // Check if process is running
207
- const isRunning = this.isProcessRunning(pid);
208
-
209
- if (!isRunning) {
210
- // Clean up stale PID file
211
- await this.removePidFile();
212
- return { running: false };
213
- }
214
-
215
- // Build status
216
- const status: MCPServerStatus = {
217
- running: true,
218
- pid,
219
- transport: this.options.transport,
220
- host: this.options.host,
221
- port: this.options.port,
222
- startedAt: this.startTime?.toISOString(),
223
- uptime: this.startTime
224
- ? Math.floor((Date.now() - this.startTime.getTime()) / 1000)
225
- : undefined,
226
- };
227
-
228
- // Get health status for HTTP transport
229
- if (this.options.transport !== 'stdio') {
230
- status.health = await this.checkHealth();
231
- }
232
-
233
- return status;
234
- }
235
-
236
- /**
237
- * Check server health
238
- */
239
- async checkHealth(): Promise<{
240
- healthy: boolean;
241
- error?: string;
242
- metrics?: Record<string, number>;
243
- }> {
244
- if (this.options.transport === 'stdio') {
245
- // For stdio, just check if process is running
246
- const pid = await this.readPidFile();
247
- return {
248
- healthy: pid !== null && this.isProcessRunning(pid),
249
- };
250
- }
251
-
252
- // For HTTP/WebSocket, make health check request
253
- try {
254
- const response = await this.httpRequest(
255
- `http://${this.options.host}:${this.options.port}/health`,
256
- 'GET',
257
- this.options.timeout
258
- );
259
-
260
- return {
261
- healthy: response.status === 'ok',
262
- metrics: {
263
- connections: response.connections || 0,
264
- },
265
- };
266
- } catch (error) {
267
- return {
268
- healthy: false,
269
- error: error instanceof Error ? error.message : 'Unknown error',
270
- };
271
- }
272
- }
273
-
274
- /**
275
- * Restart the server
276
- */
277
- async restart(): Promise<MCPServerStatus> {
278
- await this.stop();
279
- return await this.start();
280
- }
281
-
282
- /**
283
- * Start stdio server process
284
- */
285
- private async startStdioServer(): Promise<void> {
286
- // Resolve server script path relative to this file
287
- const serverScript = path.resolve(
288
- __dirname,
289
- '../../../mcp/server-entry.ts'
290
- );
291
-
292
- // Check if tsx is available
293
- const command = 'npx';
294
- const args = [
295
- 'tsx',
296
- serverScript,
297
- '--transport', this.options.transport,
298
- '--host', this.options.host,
299
- '--port', String(this.options.port),
300
- ];
301
-
302
- if (this.options.tools !== 'all') {
303
- args.push('--tools', this.options.tools.join(','));
304
- }
305
-
306
- this.process = spawn(command, args, {
307
- stdio: this.options.daemonize ? 'ignore' : ['pipe', 'pipe', 'pipe'],
308
- detached: this.options.daemonize,
309
- env: {
310
- ...process.env,
311
- NODE_ENV: process.env.NODE_ENV || 'production',
312
- MCP_SERVER_MODE: 'true',
313
- },
314
- });
315
-
316
- if (this.options.daemonize) {
317
- this.process.unref();
318
- }
319
-
320
- // Handle process events
321
- this.process.on('error', (error) => {
322
- this.emit('error', error);
323
- });
324
-
325
- this.process.on('exit', (code, signal) => {
326
- this.emit('exit', { code, signal });
327
- this.process = undefined;
328
- });
329
-
330
- // Wait for server to be ready
331
- await this.waitForReady();
332
- }
333
-
334
- /**
335
- * Start HTTP server in-process
336
- */
337
- private async startHttpServer(): Promise<void> {
338
- // Dynamically import the MCP server
339
- // Note: Path is relative to the compiled output location
340
- const mcpServerPath = path.resolve(__dirname, '../../../mcp/server.js');
341
- const { MCPServer, createMCPServer } = await import(mcpServerPath);
342
-
343
- const logger = {
344
- debug: (msg: string, data?: unknown) => this.emit('log', { level: 'debug', msg, data }),
345
- info: (msg: string, data?: unknown) => this.emit('log', { level: 'info', msg, data }),
346
- warn: (msg: string, data?: unknown) => this.emit('log', { level: 'warn', msg, data }),
347
- error: (msg: string, data?: unknown) => this.emit('log', { level: 'error', msg, data }),
348
- };
349
-
350
- const mcpServer = createMCPServer(
351
- {
352
- name: 'Claude-Flow MCP Server V3',
353
- version: '3.0.0',
354
- transport: this.options.transport as 'http' | 'websocket',
355
- host: this.options.host,
356
- port: this.options.port,
357
- enableMetrics: true,
358
- enableCaching: true,
359
- },
360
- logger
361
- );
362
-
363
- await mcpServer.start();
364
-
365
- // Store reference for stopping
366
- (this as any)._mcpServer = mcpServer;
367
- }
368
-
369
- /**
370
- * Wait for server to be ready
371
- */
372
- private async waitForReady(timeout = 10000): Promise<void> {
373
- const startTime = Date.now();
374
-
375
- while (Date.now() - startTime < timeout) {
376
- const health = await this.checkHealth();
377
- if (health.healthy) {
378
- return;
379
- }
380
- await this.sleep(100);
381
- }
382
-
383
- // For stdio, just check if process is running
384
- if (this.options.transport === 'stdio' && this.process && !this.process.killed) {
385
- return;
386
- }
387
-
388
- throw new Error('Server failed to start within timeout');
389
- }
390
-
391
- /**
392
- * Wait for process to exit
393
- */
394
- private async waitForExit(timeout: number): Promise<void> {
395
- if (!this.process) return;
396
-
397
- return new Promise((resolve) => {
398
- const timer = setTimeout(() => {
399
- resolve();
400
- }, timeout);
401
-
402
- this.process!.once('exit', () => {
403
- clearTimeout(timer);
404
- resolve();
405
- });
406
- });
407
- }
408
-
409
- /**
410
- * Start health monitoring
411
- */
412
- private startHealthMonitoring(): void {
413
- this.healthCheckInterval = setInterval(async () => {
414
- try {
415
- const health = await this.checkHealth();
416
- this.emit('health', health);
417
-
418
- if (!health.healthy) {
419
- this.emit('unhealthy', health);
420
- }
421
- } catch (error) {
422
- this.emit('health-error', error);
423
- }
424
- }, 30000);
425
- }
426
-
427
- /**
428
- * Write PID file
429
- */
430
- private async writePidFile(): Promise<void> {
431
- const pid = this.process?.pid || process.pid;
432
- await fs.promises.writeFile(this.options.pidFile, String(pid), 'utf8');
433
- }
434
-
435
- /**
436
- * Read PID file
437
- */
438
- private async readPidFile(): Promise<number | null> {
439
- try {
440
- const content = await fs.promises.readFile(this.options.pidFile, 'utf8');
441
- const pid = parseInt(content.trim(), 10);
442
- return isNaN(pid) ? null : pid;
443
- } catch {
444
- return null;
445
- }
446
- }
447
-
448
- /**
449
- * Remove PID file
450
- */
451
- private async removePidFile(): Promise<void> {
452
- try {
453
- await fs.promises.unlink(this.options.pidFile);
454
- } catch {
455
- // Ignore errors
456
- }
457
- }
458
-
459
- /**
460
- * Check if process is running
461
- */
462
- private isProcessRunning(pid: number): boolean {
463
- try {
464
- process.kill(pid, 0);
465
- return true;
466
- } catch {
467
- return false;
468
- }
469
- }
470
-
471
- /**
472
- * Make HTTP request
473
- */
474
- private async httpRequest(
475
- url: string,
476
- method: string,
477
- timeout: number
478
- ): Promise<any> {
479
- return new Promise((resolve, reject) => {
480
- const urlObj = new URL(url);
481
- const http = require('http');
482
-
483
- const req = http.request(
484
- {
485
- hostname: urlObj.hostname,
486
- port: urlObj.port,
487
- path: urlObj.pathname,
488
- method,
489
- timeout,
490
- },
491
- (res: any) => {
492
- let data = '';
493
- res.on('data', (chunk: string) => {
494
- data += chunk;
495
- });
496
- res.on('end', () => {
497
- try {
498
- resolve(JSON.parse(data));
499
- } catch {
500
- resolve({ status: res.statusCode === 200 ? 'ok' : 'error' });
501
- }
502
- });
503
- }
504
- );
505
-
506
- req.on('error', reject);
507
- req.on('timeout', () => {
508
- req.destroy();
509
- reject(new Error('Request timeout'));
510
- });
511
-
512
- req.end();
513
- });
514
- }
515
-
516
- /**
517
- * Sleep utility
518
- */
519
- private sleep(ms: number): Promise<void> {
520
- return new Promise((resolve) => setTimeout(resolve, ms));
521
- }
522
- }
523
-
524
- /**
525
- * Create MCP server manager
526
- */
527
- export function createMCPServerManager(
528
- options?: MCPServerOptions
529
- ): MCPServerManager {
530
- return new MCPServerManager(options);
531
- }
532
-
533
- /**
534
- * Singleton server manager instance
535
- */
536
- let serverManager: MCPServerManager | null = null;
537
-
538
- /**
539
- * Get or create server manager singleton
540
- */
541
- export function getServerManager(
542
- options?: MCPServerOptions
543
- ): MCPServerManager {
544
- if (!serverManager) {
545
- serverManager = new MCPServerManager(options);
546
- }
547
- return serverManager;
548
- }
549
-
550
- /**
551
- * Quick start MCP server
552
- */
553
- export async function startMCPServer(
554
- options?: MCPServerOptions
555
- ): Promise<MCPServerStatus> {
556
- const manager = getServerManager(options);
557
- return await manager.start();
558
- }
559
-
560
- /**
561
- * Quick stop MCP server
562
- */
563
- export async function stopMCPServer(force = false): Promise<void> {
564
- if (serverManager) {
565
- await serverManager.stop(force);
566
- }
567
- }
568
-
569
- /**
570
- * Get MCP server status
571
- */
572
- export async function getMCPServerStatus(): Promise<MCPServerStatus> {
573
- const manager = getServerManager();
574
- return await manager.getStatus();
575
- }
576
-
577
- export default MCPServerManager;