@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
@@ -1,558 +0,0 @@
1
- /**
2
- * V3 CLI Main Tests
3
- * Comprehensive tests for CLI parsing, help output, version, and error handling
4
- */
5
-
6
- import { describe, it, expect, beforeEach, vi, afterEach } from 'vitest';
7
- import { CLI, VERSION } from '../src/index.js';
8
- import type { Command } from '../src/types.js';
9
-
10
- describe('CLI', () => {
11
- let cli: CLI;
12
- let consoleOutput: string[];
13
- let consoleErrorOutput: string[];
14
- let processExitMock: ReturnType<typeof vi.spyOn>;
15
-
16
- beforeEach(() => {
17
- // Capture console output
18
- consoleOutput = [];
19
- consoleErrorOutput = [];
20
-
21
- vi.spyOn(process.stdout, 'write').mockImplementation((str: string | Uint8Array) => {
22
- consoleOutput.push(String(str));
23
- return true;
24
- });
25
-
26
- vi.spyOn(process.stderr, 'write').mockImplementation((str: string | Uint8Array) => {
27
- consoleErrorOutput.push(String(str));
28
- return true;
29
- });
30
-
31
- // Mock process.exit to prevent actual exits
32
- processExitMock = vi.spyOn(process, 'exit').mockImplementation((code?: string | number | null | undefined) => {
33
- throw new Error(`process.exit: ${code}`);
34
- }) as unknown as ReturnType<typeof vi.spyOn>;
35
-
36
- // Create CLI instance (non-interactive for testing)
37
- cli = new CLI({ interactive: false });
38
- });
39
-
40
- afterEach(() => {
41
- vi.restoreAllMocks();
42
- });
43
-
44
- describe('Version Command', () => {
45
- it('should show version with --version flag', async () => {
46
- await cli.run(['--version']);
47
-
48
- const output = consoleOutput.join('');
49
- expect(output).toContain('claude-flow');
50
- expect(output).toContain(VERSION);
51
- });
52
-
53
- it('should show version with -V flag', async () => {
54
- await cli.run(['-V']);
55
-
56
- const output = consoleOutput.join('');
57
- expect(output).toContain('claude-flow');
58
- expect(output).toContain(VERSION);
59
- });
60
-
61
- it('should show version with correct format', async () => {
62
- await cli.run(['--version']);
63
-
64
- const output = consoleOutput.join('');
65
- expect(output).toMatch(/claude-flow v\d+\.\d+\.\d+/);
66
- });
67
- });
68
-
69
- describe('Help Command', () => {
70
- it('should show help when no command provided', async () => {
71
- await cli.run([]);
72
-
73
- const output = consoleOutput.join('');
74
- expect(output).toContain('USAGE:');
75
- expect(output).toContain('COMMANDS:');
76
- expect(output).toContain('GLOBAL OPTIONS:');
77
- });
78
-
79
- it('should show help with --help flag', async () => {
80
- await cli.run(['--help']);
81
-
82
- const output = consoleOutput.join('');
83
- expect(output).toContain('USAGE:');
84
- expect(output).toContain('COMMANDS:');
85
- });
86
-
87
- it('should show help with -h flag', async () => {
88
- await cli.run(['-h']);
89
-
90
- const output = consoleOutput.join('');
91
- expect(output).toContain('USAGE:');
92
- expect(output).toContain('COMMANDS:');
93
- });
94
-
95
- it('should show command-specific help', async () => {
96
- await cli.run(['agent', '--help']);
97
-
98
- const output = consoleOutput.join('');
99
- expect(output).toContain('agent');
100
- expect(output).toContain('Agent management');
101
- });
102
-
103
- it('should list all available commands', async () => {
104
- await cli.run(['--help']);
105
-
106
- const output = consoleOutput.join('');
107
- expect(output).toContain('agent');
108
- expect(output).toContain('swarm');
109
- expect(output).toContain('memory');
110
- expect(output).toContain('config');
111
- });
112
-
113
- it('should show V3 features in help', async () => {
114
- await cli.run(['--help']);
115
-
116
- const output = consoleOutput.join('');
117
- expect(output).toContain('V3 FEATURES:');
118
- expect(output).toContain('15-agent');
119
- expect(output).toContain('AgentDB');
120
- expect(output).toContain('Flash Attention');
121
- });
122
-
123
- it('should show examples in help', async () => {
124
- await cli.run(['--help']);
125
-
126
- const output = consoleOutput.join('');
127
- expect(output).toContain('EXAMPLES:');
128
- });
129
- });
130
-
131
- describe('Invalid Commands', () => {
132
- it('should show error for unknown command', async () => {
133
- // Reset output
134
- consoleOutput = [];
135
-
136
- try {
137
- await cli.run(['invalid-command']);
138
- // Should throw, but might not in current implementation
139
- } catch (e) {
140
- // Error may or may not be thrown
141
- }
142
-
143
- const output = consoleOutput.join('');
144
- // Check that output contains either error message or help
145
- const hasError = output.includes('Unknown command') || output.includes('invalid-command');
146
- const hasHelp = output.includes('USAGE:') || output.includes('COMMANDS:');
147
- expect(hasError || hasHelp).toBe(true);
148
- });
149
-
150
- it('should suggest help for unknown command', async () => {
151
- consoleOutput = [];
152
-
153
- try {
154
- await cli.run(['nonexistent']);
155
- } catch (e) {
156
- // Error may or may not be thrown
157
- }
158
-
159
- const output = consoleOutput.join('');
160
- // Either shows error or help
161
- const hasMessage = output.includes('nonexistent') || output.includes('help') || output.includes('COMMANDS:');
162
- expect(hasMessage).toBe(true);
163
- });
164
-
165
- it('should handle misspelled commands', async () => {
166
- consoleOutput = [];
167
-
168
- try {
169
- await cli.run(['agnet']);
170
- } catch (e) {
171
- // Error may or may not be thrown
172
- }
173
-
174
- const output = consoleOutput.join('');
175
- // Either shows error or help
176
- const hasMessage = output.includes('agnet') || output.includes('Unknown') || output.includes('COMMANDS:');
177
- expect(hasMessage).toBe(true);
178
- });
179
- });
180
-
181
- describe('Argument Parsing', () => {
182
- it('should parse long flags', async () => {
183
- consoleOutput = [];
184
- let flagsPassed = false;
185
- const mockCommand: Command = {
186
- name: 'testparse',
187
- description: 'Test command',
188
- action: async (ctx) => {
189
- expect(ctx.flags.verbose).toBe(true);
190
- flagsPassed = true;
191
- return { success: true };
192
- }
193
- };
194
-
195
- cli['parser'].registerCommand(mockCommand);
196
- await cli.run(['testparse', '--verbose']);
197
- expect(flagsPassed).toBe(true);
198
- });
199
-
200
- it('should parse short flags', async () => {
201
- let flagsPassed = false;
202
- const mockCommand: Command = {
203
- name: 'testshort',
204
- description: 'Test command',
205
- options: [
206
- { name: 'debug', short: 'd', type: 'boolean', description: 'Debug mode' }
207
- ],
208
- action: async (ctx) => {
209
- // -d is mapped to 'debug' via the command options
210
- expect(ctx.flags.debug).toBe(true);
211
- flagsPassed = true;
212
- return { success: true };
213
- }
214
- };
215
-
216
- cli['parser'].registerCommand(mockCommand);
217
- await cli.run(['testshort', '-d']);
218
- expect(flagsPassed).toBe(true);
219
- });
220
-
221
- it('should parse flags with values', async () => {
222
- let flagsPassed = false;
223
- const mockCommand: Command = {
224
- name: 'testvalue',
225
- description: 'Test command',
226
- action: async (ctx) => {
227
- expect(ctx.flags.format).toBe('json');
228
- flagsPassed = true;
229
- return { success: true };
230
- }
231
- };
232
-
233
- cli['parser'].registerCommand(mockCommand);
234
- await cli.run(['testvalue', '--format', 'json']);
235
- expect(flagsPassed).toBe(true);
236
- });
237
-
238
- it('should parse flags with equals syntax', async () => {
239
- let flagsPassed = false;
240
- const mockCommand: Command = {
241
- name: 'testequals',
242
- description: 'Test command',
243
- action: async (ctx) => {
244
- expect(ctx.flags.output).toBe('file.txt');
245
- flagsPassed = true;
246
- return { success: true };
247
- }
248
- };
249
-
250
- cli['parser'].registerCommand(mockCommand);
251
- await cli.run(['testequals', '--output=file.txt']);
252
- expect(flagsPassed).toBe(true);
253
- });
254
-
255
- it('should parse multiple flags', async () => {
256
- let flagsPassed = false;
257
- const mockCommand: Command = {
258
- name: 'testmulti',
259
- description: 'Test command',
260
- action: async (ctx) => {
261
- expect(ctx.flags.verbose).toBe(true);
262
- expect(ctx.flags.format).toBe('json');
263
- expect(ctx.flags.quiet).toBe(true);
264
- flagsPassed = true;
265
- return { success: true };
266
- }
267
- };
268
-
269
- cli['parser'].registerCommand(mockCommand);
270
- await cli.run(['testmulti', '--verbose', '--format', 'json', '-q']);
271
- expect(flagsPassed).toBe(true);
272
- });
273
-
274
- it('should parse positional arguments', async () => {
275
- let flagsPassed = false;
276
- const mockCommand: Command = {
277
- name: 'testpos',
278
- description: 'Test command',
279
- action: async (ctx) => {
280
- expect(ctx.args).toEqual(['arg1', 'arg2', 'arg3']);
281
- flagsPassed = true;
282
- return { success: true };
283
- }
284
- };
285
-
286
- cli['parser'].registerCommand(mockCommand);
287
- await cli.run(['testpos', 'arg1', 'arg2', 'arg3']);
288
- expect(flagsPassed).toBe(true);
289
- });
290
-
291
- it('should handle boolean flags correctly', async () => {
292
- let flagsPassed = false;
293
- const mockCommand: Command = {
294
- name: 'testbool',
295
- description: 'Test command',
296
- options: [
297
- { name: 'force', type: 'boolean', description: 'Force operation' }
298
- ],
299
- action: async (ctx) => {
300
- expect(ctx.flags.force).toBe(true);
301
- flagsPassed = true;
302
- return { success: true };
303
- }
304
- };
305
-
306
- cli['parser'].registerCommand(mockCommand);
307
- await cli.run(['testbool', '--force']);
308
- expect(flagsPassed).toBe(true);
309
- });
310
-
311
- it('should handle negated boolean flags', async () => {
312
- let flagsPassed = false;
313
- const mockCommand: Command = {
314
- name: 'testnegate',
315
- description: 'Test command',
316
- action: async (ctx) => {
317
- expect(ctx.flags.color).toBe(false);
318
- flagsPassed = true;
319
- return { success: true };
320
- }
321
- };
322
-
323
- cli['parser'].registerCommand(mockCommand);
324
- await cli.run(['testnegate', '--no-color']);
325
- expect(flagsPassed).toBe(true);
326
- });
327
- });
328
-
329
- describe('Global Flags', () => {
330
- it('should handle --quiet flag', async () => {
331
- let flagsPassed = false;
332
- const mockCommand: Command = {
333
- name: 'testquiet',
334
- description: 'Test command',
335
- action: async (ctx) => {
336
- expect(ctx.flags.quiet).toBe(true);
337
- expect(ctx.interactive).toBe(false);
338
- flagsPassed = true;
339
- return { success: true };
340
- }
341
- };
342
-
343
- cli['parser'].registerCommand(mockCommand);
344
- await cli.run(['testquiet', '--quiet']);
345
- expect(flagsPassed).toBe(true);
346
- });
347
-
348
- it('should handle --format flag', async () => {
349
- let flagsPassed = false;
350
- const mockCommand: Command = {
351
- name: 'testformat',
352
- description: 'Test command',
353
- action: async (ctx) => {
354
- expect(ctx.flags.format).toBe('json');
355
- flagsPassed = true;
356
- return { success: true };
357
- }
358
- };
359
-
360
- cli['parser'].registerCommand(mockCommand);
361
- await cli.run(['testformat', '--format', 'json']);
362
- expect(flagsPassed).toBe(true);
363
- });
364
-
365
- it('should handle --config flag', async () => {
366
- let flagsPassed = false;
367
- const mockCommand: Command = {
368
- name: 'testconfig',
369
- description: 'Test command',
370
- action: async (ctx) => {
371
- expect(ctx.flags.config).toBe('./custom-config.json');
372
- flagsPassed = true;
373
- return { success: true };
374
- }
375
- };
376
-
377
- cli['parser'].registerCommand(mockCommand);
378
- await cli.run(['testconfig', '--config', './custom-config.json']);
379
- expect(flagsPassed).toBe(true);
380
- });
381
-
382
- it('should disable color with --no-color', async () => {
383
- await cli.run(['--no-color', '--help']);
384
- // Color should be disabled - check output formatter state
385
- expect(cli['output']['colorEnabled']).toBe(false);
386
- });
387
- });
388
-
389
- describe('Error Handling', () => {
390
- it('should handle command execution errors', async () => {
391
- const mockCommand: Command = {
392
- name: 'testerror',
393
- description: 'Test command',
394
- action: async () => {
395
- throw new Error('Command failed');
396
- }
397
- };
398
-
399
- cli['parser'].registerCommand(mockCommand);
400
-
401
- try {
402
- await cli.run(['testerror']);
403
- } catch (e) {
404
- expect((e as Error).message).toContain('process.exit');
405
- }
406
-
407
- // Error messages go to stderr, so check both stdout and stderr
408
- const allOutput = [...consoleOutput, ...consoleErrorOutput].join('');
409
- expect(allOutput).toContain('Command failed');
410
- });
411
-
412
- it('should handle missing required options', async () => {
413
- const mockCommand: Command = {
414
- name: 'testreq',
415
- description: 'Test command',
416
- options: [
417
- { name: 'required-opt', type: 'string', required: true, description: 'Required option' }
418
- ],
419
- action: async () => ({ success: true })
420
- };
421
-
422
- cli['parser'].registerCommand(mockCommand);
423
-
424
- try {
425
- await cli.run(['testreq']);
426
- } catch (e) {
427
- expect((e as Error).message).toContain('process.exit');
428
- }
429
-
430
- // Error messages go to stderr, so check both stdout and stderr
431
- const allOutput = [...consoleOutput, ...consoleErrorOutput].join('');
432
- expect(allOutput).toContain('Required option missing');
433
- });
434
-
435
- it('should show debug info when DEBUG env var is set', async () => {
436
- process.env.DEBUG = '1';
437
-
438
- const mockCommand: Command = {
439
- name: 'testdebug',
440
- description: 'Test command',
441
- action: async () => {
442
- const error = new Error('Test error');
443
- error.stack = 'Error: Test error\n at test:1:1';
444
- throw error;
445
- }
446
- };
447
-
448
- cli['parser'].registerCommand(mockCommand);
449
-
450
- try {
451
- await cli.run(['testdebug']);
452
- } catch (e) {
453
- expect((e as Error).message).toContain('process.exit');
454
- }
455
-
456
- const output = consoleOutput.join('');
457
- expect(output).toContain('Test error');
458
-
459
- delete process.env.DEBUG;
460
- });
461
- });
462
-
463
- describe('Subcommands', () => {
464
- it('should execute subcommand', async () => {
465
- let subcommandExecuted = false;
466
-
467
- const subcommand: Command = {
468
- name: 'sub',
469
- description: 'Subcommand',
470
- action: async () => {
471
- subcommandExecuted = true;
472
- return { success: true };
473
- }
474
- };
475
-
476
- const mainCommand: Command = {
477
- name: 'maincmd',
478
- description: 'Main command',
479
- subcommands: [subcommand]
480
- };
481
-
482
- cli['parser'].registerCommand(mainCommand);
483
- await cli.run(['maincmd', 'sub']);
484
-
485
- expect(subcommandExecuted).toBe(true);
486
- });
487
-
488
- it('should handle subcommand aliases', async () => {
489
- let executed = false;
490
-
491
- const subcommand: Command = {
492
- name: 'list',
493
- aliases: ['ls'],
494
- description: 'List items',
495
- action: async () => {
496
- executed = true;
497
- return { success: true };
498
- }
499
- };
500
-
501
- const mainCommand: Command = {
502
- name: 'mainalias',
503
- description: 'Main command',
504
- subcommands: [subcommand]
505
- };
506
-
507
- cli['parser'].registerCommand(mainCommand);
508
- await cli.run(['mainalias', 'ls']);
509
-
510
- expect(executed).toBe(true);
511
- });
512
- });
513
-
514
- describe('Exit Codes', () => {
515
- it('should exit with code 0 on success', async () => {
516
- await cli.run(['--version']);
517
- // No error thrown = exit code 0
518
- });
519
-
520
- it('should exit with code 1 on unknown command', async () => {
521
- try {
522
- await cli.run(['unknowntest']);
523
- } catch (e) {
524
- expect((e as Error).message).toContain('process.exit: 1');
525
- }
526
- });
527
-
528
- it('should exit with custom code from command result', async () => {
529
- let actionCalled = false;
530
- let returnedResult: { success: boolean; exitCode: number } | null = null;
531
- const mockCommand: Command = {
532
- name: 'testexitcode',
533
- description: 'Test command for exit code',
534
- action: async () => {
535
- actionCalled = true;
536
- returnedResult = { success: false, exitCode: 42 };
537
- return returnedResult;
538
- }
539
- };
540
-
541
- cli['parser'].registerCommand(mockCommand);
542
-
543
- let errorMessage = '';
544
- try {
545
- await cli.run(['testexitcode']);
546
- } catch (e) {
547
- errorMessage = (e as Error).message;
548
- }
549
-
550
- // Verify the action was called and returned the expected result
551
- expect(actionCalled).toBe(true);
552
- expect(returnedResult).toEqual({ success: false, exitCode: 42 });
553
-
554
- // Now check exit code
555
- expect(errorMessage).toContain('process.exit: 42');
556
- });
557
- });
558
- });