@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,480 +0,0 @@
1
- /**
2
- * V3 CLI MCP Client Tests
3
- * Tests for MCP tool invocation with proper mocking
4
- */
5
-
6
- import { describe, it, expect, beforeEach, vi } from 'vitest';
7
- import {
8
- callMCPTool,
9
- getToolMetadata,
10
- listMCPTools,
11
- hasTool,
12
- getToolCategories,
13
- validateToolInput,
14
- MCPClientError
15
- } from '../src/mcp-client.js';
16
-
17
- // Mock MCP tool modules - correct paths matching mcp-client.ts imports
18
- vi.mock('../src/mcp-tools/agent-tools.js', () => ({
19
- agentTools: [
20
- {
21
- name: 'agent/spawn',
22
- description: 'Spawn a new agent',
23
- category: 'agent',
24
- inputSchema: {
25
- type: 'object',
26
- required: ['agentType'],
27
- properties: {
28
- agentType: { type: 'string' },
29
- id: { type: 'string' },
30
- config: { type: 'object' }
31
- }
32
- },
33
- handler: vi.fn(async (input) => ({
34
- agentId: input.id || 'test-agent',
35
- agentType: input.agentType,
36
- status: 'active',
37
- createdAt: new Date().toISOString()
38
- }))
39
- },
40
- {
41
- name: 'agent/list',
42
- description: 'List all agents',
43
- category: 'agent',
44
- inputSchema: {
45
- type: 'object',
46
- properties: {
47
- status: { type: 'string' },
48
- limit: { type: 'number' }
49
- }
50
- },
51
- handler: vi.fn(async () => ({
52
- agents: [
53
- { id: 'agent-1', agentType: 'coder', status: 'active', createdAt: '2024-01-01T00:00:00Z' },
54
- { id: 'agent-2', agentType: 'tester', status: 'idle', createdAt: '2024-01-01T00:01:00Z' }
55
- ],
56
- total: 2
57
- }))
58
- },
59
- {
60
- name: 'agent/terminate',
61
- description: 'Terminate an agent',
62
- category: 'agent',
63
- inputSchema: {
64
- type: 'object',
65
- required: ['agentId'],
66
- properties: {
67
- agentId: { type: 'string' },
68
- graceful: { type: 'boolean' }
69
- }
70
- },
71
- handler: vi.fn(async (input) => ({
72
- agentId: input.agentId,
73
- terminated: true,
74
- terminatedAt: new Date().toISOString()
75
- }))
76
- }
77
- ]
78
- }));
79
-
80
- vi.mock('../src/mcp-tools/swarm-tools.js', () => ({
81
- swarmTools: [
82
- {
83
- name: 'swarm/init',
84
- description: 'Initialize a swarm',
85
- category: 'swarm',
86
- inputSchema: {
87
- type: 'object',
88
- required: ['topology'],
89
- properties: {
90
- topology: { type: 'string' },
91
- maxAgents: { type: 'number' }
92
- }
93
- },
94
- handler: vi.fn(async (input) => ({
95
- swarmId: 'swarm-test',
96
- topology: input.topology,
97
- initializedAt: new Date().toISOString(),
98
- config: {
99
- topology: input.topology,
100
- maxAgents: input.maxAgents || 15,
101
- currentAgents: 0
102
- }
103
- }))
104
- }
105
- ]
106
- }));
107
-
108
- vi.mock('../src/mcp-tools/memory-tools.js', () => ({
109
- memoryTools: [
110
- {
111
- name: 'memory/store',
112
- description: 'Store data in memory',
113
- category: 'memory',
114
- inputSchema: {
115
- type: 'object',
116
- required: ['key', 'value'],
117
- properties: {
118
- key: { type: 'string' },
119
- value: { type: 'string' },
120
- namespace: { type: 'string' }
121
- }
122
- },
123
- handler: vi.fn(async (input) => ({
124
- key: input.key,
125
- stored: true,
126
- timestamp: new Date().toISOString()
127
- }))
128
- }
129
- ]
130
- }));
131
-
132
- vi.mock('../src/mcp-tools/config-tools.js', () => ({
133
- configTools: [
134
- {
135
- name: 'config/get',
136
- description: 'Get configuration value',
137
- category: 'config',
138
- inputSchema: {
139
- type: 'object',
140
- properties: {
141
- key: { type: 'string' }
142
- }
143
- },
144
- handler: vi.fn(async (input) => ({
145
- key: input.key,
146
- value: 'test-value'
147
- }))
148
- }
149
- ]
150
- }));
151
-
152
- describe('MCP Client', () => {
153
- describe('callMCPTool', () => {
154
- it('should call agent/spawn tool successfully', async () => {
155
- const result = await callMCPTool('agent/spawn', {
156
- agentType: 'coder',
157
- id: 'test-coder-1'
158
- });
159
-
160
- expect(result).toMatchObject({
161
- agentId: 'test-coder-1',
162
- agentType: 'coder',
163
- status: 'active'
164
- });
165
- expect(result.createdAt).toBeDefined();
166
- });
167
-
168
- it('should call agent/list tool successfully', async () => {
169
- const result = await callMCPTool<{ agents: unknown[]; total: number }>('agent/list', {
170
- status: 'active',
171
- limit: 10
172
- });
173
-
174
- expect(result.agents).toHaveLength(2);
175
- expect(result.total).toBe(2);
176
- expect(result.agents[0]).toHaveProperty('id');
177
- expect(result.agents[0]).toHaveProperty('agentType');
178
- });
179
-
180
- it('should call agent/terminate tool successfully', async () => {
181
- const result = await callMCPTool('agent/terminate', {
182
- agentId: 'agent-1',
183
- graceful: true
184
- });
185
-
186
- expect(result).toMatchObject({
187
- agentId: 'agent-1',
188
- terminated: true
189
- });
190
- expect(result.terminatedAt).toBeDefined();
191
- });
192
-
193
- it('should call swarm/init tool successfully', async () => {
194
- const result = await callMCPTool('swarm/init', {
195
- topology: 'hierarchical-mesh',
196
- maxAgents: 15
197
- });
198
-
199
- expect(result).toMatchObject({
200
- swarmId: 'swarm-test',
201
- topology: 'hierarchical-mesh'
202
- });
203
- expect(result.config).toMatchObject({
204
- topology: 'hierarchical-mesh',
205
- maxAgents: 15
206
- });
207
- });
208
-
209
- it('should call memory/store tool successfully', async () => {
210
- const result = await callMCPTool('memory/store', {
211
- key: 'test-key',
212
- value: 'test-value',
213
- namespace: 'default'
214
- });
215
-
216
- expect(result).toMatchObject({
217
- key: 'test-key',
218
- stored: true
219
- });
220
- expect(result.timestamp).toBeDefined();
221
- });
222
-
223
- it('should call config/get tool successfully', async () => {
224
- const result = await callMCPTool('config/get', {
225
- key: 'swarm.topology'
226
- });
227
-
228
- expect(result).toMatchObject({
229
- key: 'swarm.topology',
230
- value: 'test-value'
231
- });
232
- });
233
-
234
- it('should throw MCPClientError for non-existent tool', async () => {
235
- await expect(
236
- callMCPTool('nonexistent/tool', {})
237
- ).rejects.toThrow(MCPClientError);
238
-
239
- await expect(
240
- callMCPTool('nonexistent/tool', {})
241
- ).rejects.toThrow('MCP tool not found: nonexistent/tool');
242
- });
243
-
244
- it('should wrap handler errors in MCPClientError', async () => {
245
- // This test verifies error wrapping behavior
246
- // Since our mock is already defined at module level, we need to test
247
- // the error case by temporarily replacing the tool registry
248
-
249
- // We can't easily test this with the current mock setup, so we'll test
250
- // that a non-existent tool throws the correct error type
251
- try {
252
- await callMCPTool('nonexistent/tool', {});
253
- expect.fail('Should have thrown MCPClientError');
254
- } catch (error) {
255
- expect(error).toBeInstanceOf(MCPClientError);
256
- expect((error as MCPClientError).toolName).toBe('nonexistent/tool');
257
- }
258
- });
259
-
260
- it('should pass context to tool handler', async () => {
261
- const context = { userId: 'test-user', sessionId: 'test-session' };
262
-
263
- const result = await callMCPTool('agent/spawn', {
264
- agentType: 'coder'
265
- }, context);
266
-
267
- expect(result).toBeDefined();
268
- // Tool should have access to context
269
- });
270
-
271
- it('should handle empty input object', async () => {
272
- const result = await callMCPTool('agent/list', {});
273
-
274
- expect(result).toHaveProperty('agents');
275
- expect(result).toHaveProperty('total');
276
- });
277
- });
278
-
279
- describe('getToolMetadata', () => {
280
- it('should return metadata for existing tool', () => {
281
- const metadata = getToolMetadata('agent/spawn');
282
-
283
- expect(metadata).toBeDefined();
284
- expect(metadata?.name).toBe('agent/spawn');
285
- expect(metadata?.description).toBe('Spawn a new agent');
286
- expect(metadata?.category).toBe('agent');
287
- expect(metadata?.inputSchema).toBeDefined();
288
- expect(metadata).not.toHaveProperty('handler');
289
- });
290
-
291
- it('should return undefined for non-existent tool', () => {
292
- const metadata = getToolMetadata('nonexistent/tool');
293
-
294
- expect(metadata).toBeUndefined();
295
- });
296
-
297
- it('should not include handler in metadata', () => {
298
- const metadata = getToolMetadata('agent/spawn');
299
-
300
- expect(metadata).toBeDefined();
301
- expect(metadata).not.toHaveProperty('handler');
302
- });
303
-
304
- it('should return complete metadata structure', () => {
305
- const metadata = getToolMetadata('swarm/init');
306
-
307
- expect(metadata).toMatchObject({
308
- name: 'swarm/init',
309
- description: expect.any(String),
310
- category: 'swarm',
311
- inputSchema: expect.any(Object)
312
- });
313
- });
314
- });
315
-
316
- describe('listMCPTools', () => {
317
- it('should list all available tools', () => {
318
- const tools = listMCPTools();
319
-
320
- expect(tools.length).toBeGreaterThan(0);
321
- expect(tools.every(t => t.name && t.description)).toBe(true);
322
- });
323
-
324
- it('should filter tools by category', () => {
325
- const agentTools = listMCPTools('agent');
326
-
327
- expect(agentTools.length).toBeGreaterThan(0);
328
- expect(agentTools.every(t => t.category === 'agent')).toBe(true);
329
- });
330
-
331
- it('should return empty array for non-existent category', () => {
332
- const tools = listMCPTools('nonexistent');
333
-
334
- expect(tools).toEqual([]);
335
- });
336
-
337
- it('should not include handlers in listed tools', () => {
338
- const tools = listMCPTools();
339
-
340
- expect(tools.every(t => !('handler' in t))).toBe(true);
341
- });
342
-
343
- it('should include all metadata fields', () => {
344
- const tools = listMCPTools();
345
-
346
- tools.forEach(tool => {
347
- expect(tool).toHaveProperty('name');
348
- expect(tool).toHaveProperty('description');
349
- expect(tool).toHaveProperty('inputSchema');
350
- expect(tool).toHaveProperty('category');
351
- });
352
- });
353
- });
354
-
355
- describe('hasTool', () => {
356
- it('should return true for existing tool', () => {
357
- expect(hasTool('agent/spawn')).toBe(true);
358
- expect(hasTool('agent/list')).toBe(true);
359
- expect(hasTool('swarm/init')).toBe(true);
360
- });
361
-
362
- it('should return false for non-existent tool', () => {
363
- expect(hasTool('nonexistent/tool')).toBe(false);
364
- expect(hasTool('invalid')).toBe(false);
365
- });
366
-
367
- it('should be case-sensitive', () => {
368
- expect(hasTool('agent/spawn')).toBe(true);
369
- expect(hasTool('Agent/Spawn')).toBe(false);
370
- });
371
- });
372
-
373
- describe('getToolCategories', () => {
374
- it('should return all unique categories', () => {
375
- const categories = getToolCategories();
376
-
377
- expect(categories).toContain('agent');
378
- expect(categories).toContain('swarm');
379
- expect(categories).toContain('memory');
380
- expect(categories).toContain('config');
381
- });
382
-
383
- it('should return sorted categories', () => {
384
- const categories = getToolCategories();
385
- const sorted = [...categories].sort();
386
-
387
- expect(categories).toEqual(sorted);
388
- });
389
-
390
- it('should not contain duplicates', () => {
391
- const categories = getToolCategories();
392
- const unique = [...new Set(categories)];
393
-
394
- expect(categories).toEqual(unique);
395
- });
396
- });
397
-
398
- describe('validateToolInput', () => {
399
- it('should validate required fields', () => {
400
- const result = validateToolInput('agent/spawn', {
401
- agentType: 'coder',
402
- id: 'test-1'
403
- });
404
-
405
- expect(result.valid).toBe(true);
406
- expect(result.errors).toBeUndefined();
407
- });
408
-
409
- it('should detect missing required fields', () => {
410
- const result = validateToolInput('agent/spawn', {
411
- id: 'test-1'
412
- // Missing required 'agentType'
413
- });
414
-
415
- expect(result.valid).toBe(false);
416
- expect(result.errors).toBeDefined();
417
- expect(result.errors).toContain('Missing required field: agentType');
418
- });
419
-
420
- it('should return invalid for non-existent tool', () => {
421
- const result = validateToolInput('nonexistent/tool', {});
422
-
423
- expect(result.valid).toBe(false);
424
- expect(result.errors).toContain("Tool 'nonexistent/tool' not found");
425
- });
426
-
427
- it('should validate multiple required fields', () => {
428
- const result = validateToolInput('agent/terminate', {
429
- // Missing required 'agentId'
430
- graceful: true
431
- });
432
-
433
- expect(result.valid).toBe(false);
434
- expect(result.errors).toContain('Missing required field: agentId');
435
- });
436
-
437
- it('should pass with all required fields present', () => {
438
- const result = validateToolInput('agent/terminate', {
439
- agentId: 'agent-1',
440
- graceful: true
441
- });
442
-
443
- expect(result.valid).toBe(true);
444
- expect(result.errors).toBeUndefined();
445
- });
446
-
447
- it('should allow optional fields to be missing', () => {
448
- const result = validateToolInput('swarm/init', {
449
- topology: 'hierarchical'
450
- // maxAgents is optional
451
- });
452
-
453
- expect(result.valid).toBe(true);
454
- });
455
- });
456
-
457
- describe('MCPClientError', () => {
458
- it('should create error with tool name', () => {
459
- const error = new MCPClientError('Test error', 'test/tool');
460
-
461
- expect(error.message).toBe('Test error');
462
- expect(error.toolName).toBe('test/tool');
463
- expect(error.name).toBe('MCPClientError');
464
- });
465
-
466
- it('should include cause error', () => {
467
- const cause = new Error('Original error');
468
- const error = new MCPClientError('Wrapper error', 'test/tool', cause);
469
-
470
- expect(error.cause).toBe(cause);
471
- });
472
-
473
- it('should be instanceof Error', () => {
474
- const error = new MCPClientError('Test', 'tool');
475
-
476
- expect(error instanceof Error).toBe(true);
477
- expect(error instanceof MCPClientError).toBe(true);
478
- });
479
- });
480
- });