claude-flow-novice 1.5.12 → 1.5.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 (53) hide show
  1. package/.claude/agents/analysis/code-review/analyze-code-quality.md +160 -177
  2. package/.claude/agents/architecture/system-design/arch-system-design.md +118 -153
  3. package/.claude-flow-novice/dist/mcp/auth.js +347 -0
  4. package/.claude-flow-novice/dist/mcp/claude-code-wrapper.js +717 -0
  5. package/.claude-flow-novice/dist/mcp/claude-flow-tools.js +1365 -0
  6. package/.claude-flow-novice/dist/mcp/client.js +201 -0
  7. package/.claude-flow-novice/dist/mcp/index.js +192 -0
  8. package/.claude-flow-novice/dist/mcp/integrate-wrapper.js +85 -0
  9. package/.claude-flow-novice/dist/mcp/lifecycle-manager.js +348 -0
  10. package/.claude-flow-novice/dist/mcp/load-balancer.js +386 -0
  11. package/.claude-flow-novice/dist/mcp/mcp-config-manager.js +1362 -0
  12. package/.claude-flow-novice/dist/mcp/mcp-server-novice-simplified.js +583 -0
  13. package/.claude-flow-novice/dist/mcp/mcp-server-novice.js +723 -0
  14. package/.claude-flow-novice/dist/mcp/mcp-server-sdk.js +649 -0
  15. package/.claude-flow-novice/dist/mcp/mcp-server.js +2256 -0
  16. package/.claude-flow-novice/dist/mcp/orchestration-integration.js +800 -0
  17. package/.claude-flow-novice/dist/mcp/performance-monitor.js +489 -0
  18. package/.claude-flow-novice/dist/mcp/protocol-manager.js +376 -0
  19. package/.claude-flow-novice/dist/mcp/router.js +220 -0
  20. package/.claude-flow-novice/dist/mcp/ruv-swarm-tools.js +671 -0
  21. package/.claude-flow-novice/dist/mcp/ruv-swarm-wrapper.js +254 -0
  22. package/.claude-flow-novice/dist/mcp/server-with-wrapper.js +32 -0
  23. package/.claude-flow-novice/dist/mcp/server-wrapper-mode.js +26 -0
  24. package/.claude-flow-novice/dist/mcp/server.js +539 -0
  25. package/.claude-flow-novice/dist/mcp/session-manager.js +338 -0
  26. package/.claude-flow-novice/dist/mcp/sparc-modes.js +455 -0
  27. package/.claude-flow-novice/dist/mcp/swarm-tools.js +903 -0
  28. package/.claude-flow-novice/dist/mcp/tools.js +426 -0
  29. package/.claude-flow-novice/dist/src/cli/commands/swarm.js +23 -1
  30. package/.claude-flow-novice/dist/src/cli/commands/swarm.js.map +1 -1
  31. package/.claude-flow-novice/dist/src/cli/simple-commands/init/templates/CLAUDE.md +42 -102
  32. package/.claude-flow-novice/dist/src/config/web-portal-config.js +2 -1
  33. package/.claude-flow-novice/dist/src/config/web-portal-config.js.map +1 -1
  34. package/.claude-flow-novice/dist/src/coordination/swarm-coordinator-factory.js +36 -0
  35. package/.claude-flow-novice/dist/src/coordination/swarm-coordinator-factory.js.map +1 -0
  36. package/.claude-flow-novice/dist/src/preferences/user-preference-manager.js +371 -0
  37. package/.claude-flow-novice/dist/src/preferences/user-preference-manager.js.map +1 -0
  38. package/.claude-flow-novice/dist/src/validators/index.js +12 -0
  39. package/.claude-flow-novice/dist/src/validators/index.js.map +1 -0
  40. package/.claude-flow-novice/dist/src/validators/swarm-init-validator.js +261 -0
  41. package/.claude-flow-novice/dist/src/validators/swarm-init-validator.js.map +1 -0
  42. package/.claude-flow-novice/dist/src/validators/todowrite-batching-validator.js +204 -0
  43. package/.claude-flow-novice/dist/src/validators/todowrite-batching-validator.js.map +1 -0
  44. package/.claude-flow-novice/dist/src/validators/todowrite-integration.js +189 -0
  45. package/.claude-flow-novice/dist/src/validators/todowrite-integration.js.map +1 -0
  46. package/.claude-flow-novice/dist/src/web/portal-server.js +12 -5
  47. package/.claude-flow-novice/dist/src/web/portal-server.js.map +1 -1
  48. package/config/hooks/post-edit-pipeline.js +231 -10
  49. package/package.json +4 -2
  50. package/scripts/src/web/frontend/.claude-flow/metrics/agent-metrics.json +1 -0
  51. package/scripts/src/web/frontend/.claude-flow/metrics/performance.json +9 -0
  52. package/scripts/src/web/frontend/.claude-flow/metrics/task-metrics.json +10 -0
  53. package/src/cli/simple-commands/init/templates/CLAUDE.md +4 -1
@@ -0,0 +1,903 @@
1
+ /**
2
+ * Comprehensive MCP tools for swarm system functionality
3
+ */ export function createSwarmTools(logger) {
4
+ return [
5
+ // === LEGACY SWARM TOOLS ===
6
+ {
7
+ name: 'dispatch_agent',
8
+ description: 'Spawn a new agent in the swarm to handle a specific task',
9
+ inputSchema: {
10
+ type: 'object',
11
+ properties: {
12
+ type: {
13
+ type: 'string',
14
+ enum: [
15
+ 'coordinator',
16
+ 'researcher',
17
+ 'coder',
18
+ 'analyst',
19
+ 'architect',
20
+ 'tester',
21
+ 'reviewer',
22
+ 'optimizer',
23
+ 'documenter',
24
+ 'monitor',
25
+ 'specialist'
26
+ ],
27
+ description: 'The type of agent to spawn'
28
+ },
29
+ task: {
30
+ type: 'string',
31
+ description: 'The specific task for the agent to complete'
32
+ },
33
+ name: {
34
+ type: 'string',
35
+ description: 'Optional name for the agent'
36
+ }
37
+ },
38
+ required: [
39
+ 'type',
40
+ 'task'
41
+ ]
42
+ },
43
+ handler: async (input, context)=>{
44
+ const { type, task, name } = input;
45
+ // Get swarm ID from environment
46
+ const swarmId = process.env['CLAUDE_SWARM_ID'];
47
+ if (!swarmId) {
48
+ throw new Error('Not running in swarm context');
49
+ }
50
+ // Get parent agent ID if available
51
+ const parentId = process.env['CLAUDE_SWARM_AGENT_ID'];
52
+ try {
53
+ // Legacy functionality - would integrate with swarm spawn system
54
+ const agentId = `agent-${Date.now()}`;
55
+ logger.info('Agent spawned via legacy dispatch tool', {
56
+ agentId
57
+ });
58
+ return {
59
+ success: true,
60
+ agentId,
61
+ agentName: name || type,
62
+ terminalId: 'N/A',
63
+ message: `Successfully spawned ${name || type} to work on: ${task}`
64
+ };
65
+ } catch (error) {
66
+ logger.error('Failed to spawn agent via legacy dispatch tool', error);
67
+ return {
68
+ success: false,
69
+ error: error instanceof Error ? error.message : 'Unknown error'
70
+ };
71
+ }
72
+ }
73
+ },
74
+ {
75
+ name: 'swarm_status',
76
+ description: 'Get the current status of the swarm and all agents',
77
+ inputSchema: {
78
+ type: 'object',
79
+ properties: {}
80
+ },
81
+ handler: async (input, context)=>{
82
+ const swarmId = process.env['CLAUDE_SWARM_ID'] || 'default-swarm';
83
+ // Legacy functionality - would integrate with swarm state system
84
+ const mockState = {
85
+ swarmId,
86
+ objective: 'Legacy swarm status',
87
+ startTime: Date.now() - 60000,
88
+ agents: []
89
+ };
90
+ const runtime = Math.floor((Date.now() - mockState.startTime) / 1000);
91
+ return {
92
+ swarmId: mockState.swarmId,
93
+ objective: mockState.objective,
94
+ runtime: `${runtime}s`,
95
+ totalAgents: mockState.agents.length,
96
+ activeAgents: 0,
97
+ completedAgents: 0,
98
+ failedAgents: 0,
99
+ agents: mockState.agents
100
+ };
101
+ }
102
+ },
103
+ // === SWARM COORDINATION TOOLS ===
104
+ {
105
+ name: 'swarm/create-objective',
106
+ description: 'Create a new swarm objective with tasks and coordination',
107
+ inputSchema: {
108
+ type: 'object',
109
+ properties: {
110
+ title: {
111
+ type: 'string',
112
+ description: 'Objective title'
113
+ },
114
+ description: {
115
+ type: 'string',
116
+ description: 'Detailed description'
117
+ },
118
+ tasks: {
119
+ type: 'array',
120
+ items: {
121
+ type: 'object',
122
+ properties: {
123
+ type: {
124
+ type: 'string'
125
+ },
126
+ description: {
127
+ type: 'string'
128
+ },
129
+ requirements: {
130
+ type: 'object'
131
+ },
132
+ priority: {
133
+ type: 'string',
134
+ enum: [
135
+ 'low',
136
+ 'normal',
137
+ 'high',
138
+ 'critical'
139
+ ]
140
+ }
141
+ },
142
+ required: [
143
+ 'type',
144
+ 'description'
145
+ ]
146
+ }
147
+ },
148
+ strategy: {
149
+ type: 'string',
150
+ enum: [
151
+ 'parallel',
152
+ 'sequential',
153
+ 'adaptive'
154
+ ]
155
+ },
156
+ timeout: {
157
+ type: 'number',
158
+ description: 'Timeout in milliseconds'
159
+ }
160
+ },
161
+ required: [
162
+ 'title',
163
+ 'description',
164
+ 'tasks'
165
+ ]
166
+ },
167
+ handler: async (input, context)=>{
168
+ if (!context?.swarmCoordinator) {
169
+ throw new Error('Swarm coordinator not available');
170
+ }
171
+ try {
172
+ const objectiveId = await context.swarmCoordinator.createObjective({
173
+ title: input.title,
174
+ description: input.description,
175
+ tasks: input.tasks || [],
176
+ strategy: input.strategy || 'adaptive',
177
+ timeout: input.timeout
178
+ });
179
+ logger.info('Swarm objective created via MCP', {
180
+ objectiveId
181
+ });
182
+ return {
183
+ success: true,
184
+ objectiveId,
185
+ message: `Created swarm objective: ${input.title}`
186
+ };
187
+ } catch (error) {
188
+ logger.error('Failed to create swarm objective via MCP', error);
189
+ throw error;
190
+ }
191
+ }
192
+ },
193
+ {
194
+ name: 'swarm/execute-objective',
195
+ description: 'Execute a swarm objective',
196
+ inputSchema: {
197
+ type: 'object',
198
+ properties: {
199
+ objectiveId: {
200
+ type: 'string',
201
+ description: 'Objective ID to execute'
202
+ }
203
+ },
204
+ required: [
205
+ 'objectiveId'
206
+ ]
207
+ },
208
+ handler: async (input, context)=>{
209
+ if (!context?.swarmCoordinator) {
210
+ throw new Error('Swarm coordinator not available');
211
+ }
212
+ try {
213
+ const result = await context.swarmCoordinator.executeObjective(input.objectiveId);
214
+ logger.info('Swarm objective executed via MCP', {
215
+ objectiveId: input.objectiveId
216
+ });
217
+ return {
218
+ success: true,
219
+ objectiveId: input.objectiveId,
220
+ result,
221
+ message: 'Objective execution started'
222
+ };
223
+ } catch (error) {
224
+ logger.error('Failed to execute swarm objective via MCP', error);
225
+ throw error;
226
+ }
227
+ }
228
+ },
229
+ {
230
+ name: 'swarm/get-status',
231
+ description: 'Get comprehensive swarm status',
232
+ inputSchema: {
233
+ type: 'object',
234
+ properties: {
235
+ includeDetails: {
236
+ type: 'boolean',
237
+ default: false
238
+ }
239
+ }
240
+ },
241
+ handler: async (input, context)=>{
242
+ if (!context?.swarmCoordinator) {
243
+ throw new Error('Swarm coordinator not available');
244
+ }
245
+ try {
246
+ const status = await context.swarmCoordinator.getSwarmStatus();
247
+ if (input.includeDetails) {
248
+ const detailedStatus = {
249
+ ...status,
250
+ objectives: await context.swarmCoordinator.getActiveObjectives(),
251
+ agents: context.agentManager ? await context.agentManager.getAllAgents() : [],
252
+ resources: context.resourceManager ? context.resourceManager.getManagerStatistics() : null,
253
+ messaging: context.messageBus ? context.messageBus.getMetrics() : null,
254
+ monitoring: context.monitor ? context.monitor.getMonitoringStatistics() : null
255
+ };
256
+ return detailedStatus;
257
+ }
258
+ return status;
259
+ } catch (error) {
260
+ logger.error('Failed to get swarm status via MCP', error);
261
+ throw error;
262
+ }
263
+ }
264
+ },
265
+ // === AGENT MANAGEMENT TOOLS ===
266
+ {
267
+ name: 'agent/create',
268
+ description: 'Create a new agent in the swarm',
269
+ inputSchema: {
270
+ type: 'object',
271
+ properties: {
272
+ type: {
273
+ type: 'string',
274
+ description: 'Agent type (developer, researcher, etc.)'
275
+ },
276
+ capabilities: {
277
+ type: 'object',
278
+ properties: {
279
+ domains: {
280
+ type: 'array',
281
+ items: {
282
+ type: 'string'
283
+ }
284
+ },
285
+ tools: {
286
+ type: 'array',
287
+ items: {
288
+ type: 'string'
289
+ }
290
+ },
291
+ languages: {
292
+ type: 'array',
293
+ items: {
294
+ type: 'string'
295
+ }
296
+ },
297
+ frameworks: {
298
+ type: 'array',
299
+ items: {
300
+ type: 'string'
301
+ }
302
+ }
303
+ }
304
+ },
305
+ config: {
306
+ type: 'object',
307
+ description: 'Agent configuration'
308
+ }
309
+ },
310
+ required: [
311
+ 'type'
312
+ ]
313
+ },
314
+ handler: async (input, context)=>{
315
+ if (!context?.agentManager) {
316
+ throw new Error('Agent manager not available');
317
+ }
318
+ try {
319
+ const agentId = await context.agentManager.createAgent(input.type, input.capabilities || {}, input.config || {});
320
+ logger.info('Agent created via MCP', {
321
+ agentId,
322
+ type: input.type
323
+ });
324
+ return {
325
+ success: true,
326
+ agentId,
327
+ message: `Created ${input.type} agent`
328
+ };
329
+ } catch (error) {
330
+ logger.error('Failed to create agent via MCP', error);
331
+ throw error;
332
+ }
333
+ }
334
+ },
335
+ {
336
+ name: 'agent/list',
337
+ description: 'List all agents with their status',
338
+ inputSchema: {
339
+ type: 'object',
340
+ properties: {
341
+ status: {
342
+ type: 'string',
343
+ enum: [
344
+ 'active',
345
+ 'idle',
346
+ 'busy',
347
+ 'failed',
348
+ 'all'
349
+ ],
350
+ default: 'all'
351
+ }
352
+ }
353
+ },
354
+ handler: async (input, context)=>{
355
+ if (!context?.agentManager) {
356
+ throw new Error('Agent manager not available');
357
+ }
358
+ try {
359
+ const agents = await context.agentManager.getAllAgents();
360
+ const filteredAgents = input.status === 'all' ? agents : agents.filter((agent)=>agent.status === input.status);
361
+ return {
362
+ success: true,
363
+ agents: filteredAgents,
364
+ count: filteredAgents.length,
365
+ filter: input.status
366
+ };
367
+ } catch (error) {
368
+ logger.error('Failed to list agents via MCP', error);
369
+ throw error;
370
+ }
371
+ }
372
+ },
373
+ // === RESOURCE MANAGEMENT TOOLS ===
374
+ {
375
+ name: 'resource/register',
376
+ description: 'Register a new resource',
377
+ inputSchema: {
378
+ type: 'object',
379
+ properties: {
380
+ type: {
381
+ type: 'string',
382
+ enum: [
383
+ 'compute',
384
+ 'storage',
385
+ 'network',
386
+ 'memory',
387
+ 'gpu',
388
+ 'custom'
389
+ ]
390
+ },
391
+ name: {
392
+ type: 'string',
393
+ description: 'Resource name'
394
+ },
395
+ capacity: {
396
+ type: 'object',
397
+ properties: {
398
+ cpu: {
399
+ type: 'number'
400
+ },
401
+ memory: {
402
+ type: 'number'
403
+ },
404
+ disk: {
405
+ type: 'number'
406
+ },
407
+ network: {
408
+ type: 'number'
409
+ }
410
+ }
411
+ },
412
+ metadata: {
413
+ type: 'object',
414
+ description: 'Additional metadata'
415
+ }
416
+ },
417
+ required: [
418
+ 'type',
419
+ 'name',
420
+ 'capacity'
421
+ ]
422
+ },
423
+ handler: async (input, context)=>{
424
+ if (!context?.resourceManager) {
425
+ throw new Error('Resource manager not available');
426
+ }
427
+ try {
428
+ const resourceId = await context.resourceManager.registerResource(input.type, input.name, input.capacity, input.metadata || {});
429
+ logger.info('Resource registered via MCP', {
430
+ resourceId,
431
+ type: input.type
432
+ });
433
+ return {
434
+ success: true,
435
+ resourceId,
436
+ message: `Registered ${input.type} resource: ${input.name}`
437
+ };
438
+ } catch (error) {
439
+ logger.error('Failed to register resource via MCP', error);
440
+ throw error;
441
+ }
442
+ }
443
+ },
444
+ {
445
+ name: 'resource/get-statistics',
446
+ description: 'Get resource manager statistics',
447
+ inputSchema: {
448
+ type: 'object',
449
+ properties: {}
450
+ },
451
+ handler: async (input, context)=>{
452
+ if (!context?.resourceManager) {
453
+ throw new Error('Resource manager not available');
454
+ }
455
+ try {
456
+ const stats = context.resourceManager.getManagerStatistics();
457
+ return {
458
+ success: true,
459
+ statistics: stats
460
+ };
461
+ } catch (error) {
462
+ logger.error('Failed to get resource statistics via MCP', error);
463
+ throw error;
464
+ }
465
+ }
466
+ },
467
+ // === MESSAGING TOOLS ===
468
+ {
469
+ name: 'message/send',
470
+ description: 'Send a message through the message bus',
471
+ inputSchema: {
472
+ type: 'object',
473
+ properties: {
474
+ type: {
475
+ type: 'string',
476
+ description: 'Message type'
477
+ },
478
+ content: {
479
+ type: 'object',
480
+ description: 'Message content'
481
+ },
482
+ sender: {
483
+ type: 'string',
484
+ description: 'Sender agent ID'
485
+ },
486
+ receivers: {
487
+ type: 'array',
488
+ items: {
489
+ type: 'string'
490
+ },
491
+ description: 'Receiver agent IDs'
492
+ },
493
+ priority: {
494
+ type: 'string',
495
+ enum: [
496
+ 'low',
497
+ 'normal',
498
+ 'high',
499
+ 'critical'
500
+ ]
501
+ },
502
+ channel: {
503
+ type: 'string',
504
+ description: 'Optional channel to use'
505
+ }
506
+ },
507
+ required: [
508
+ 'type',
509
+ 'content',
510
+ 'sender',
511
+ 'receivers'
512
+ ]
513
+ },
514
+ handler: async (input, context)=>{
515
+ if (!context?.messageBus) {
516
+ throw new Error('Message bus not available');
517
+ }
518
+ try {
519
+ const senderAgent = {
520
+ id: input.sender,
521
+ swarmId: 'default',
522
+ type: 'coordinator',
523
+ instance: 1
524
+ };
525
+ const receiverAgents = input.receivers.map((id)=>({
526
+ id,
527
+ swarmId: 'default',
528
+ type: 'coordinator',
529
+ instance: 1
530
+ }));
531
+ const messageId = await context.messageBus.sendMessage(input.type, input.content, senderAgent, receiverAgents, {
532
+ priority: input.priority || 'normal',
533
+ channel: input.channel
534
+ });
535
+ logger.info('Message sent via MCP', {
536
+ messageId,
537
+ type: input.type
538
+ });
539
+ return {
540
+ success: true,
541
+ messageId,
542
+ message: 'Message sent successfully'
543
+ };
544
+ } catch (error) {
545
+ logger.error('Failed to send message via MCP', error);
546
+ throw error;
547
+ }
548
+ }
549
+ },
550
+ {
551
+ name: 'message/get-metrics',
552
+ description: 'Get message bus metrics',
553
+ inputSchema: {
554
+ type: 'object',
555
+ properties: {}
556
+ },
557
+ handler: async (input, context)=>{
558
+ if (!context?.messageBus) {
559
+ throw new Error('Message bus not available');
560
+ }
561
+ try {
562
+ const metrics = context.messageBus.getMetrics();
563
+ return {
564
+ success: true,
565
+ metrics
566
+ };
567
+ } catch (error) {
568
+ logger.error('Failed to get message metrics via MCP', error);
569
+ throw error;
570
+ }
571
+ }
572
+ },
573
+ // === MONITORING TOOLS ===
574
+ {
575
+ name: 'monitor/get-metrics',
576
+ description: 'Get system monitoring metrics',
577
+ inputSchema: {
578
+ type: 'object',
579
+ properties: {
580
+ type: {
581
+ type: 'string',
582
+ enum: [
583
+ 'system',
584
+ 'swarm',
585
+ 'agents',
586
+ 'all'
587
+ ],
588
+ default: 'all'
589
+ }
590
+ }
591
+ },
592
+ handler: async (input, context)=>{
593
+ if (!context?.monitor) {
594
+ throw new Error('Monitor not available');
595
+ }
596
+ try {
597
+ const metrics = {};
598
+ if (input.type === 'system' || input.type === 'all') {
599
+ metrics.system = context.monitor.getSystemMetrics();
600
+ }
601
+ if (input.type === 'swarm' || input.type === 'all') {
602
+ metrics.swarm = context.monitor.getSwarmMetrics();
603
+ }
604
+ if (input.type === 'agents' || input.type === 'all') {
605
+ metrics.statistics = context.monitor.getMonitoringStatistics();
606
+ }
607
+ return {
608
+ success: true,
609
+ metrics
610
+ };
611
+ } catch (error) {
612
+ logger.error('Failed to get monitoring metrics via MCP', error);
613
+ throw error;
614
+ }
615
+ }
616
+ },
617
+ {
618
+ name: 'monitor/get-alerts',
619
+ description: 'Get active alerts',
620
+ inputSchema: {
621
+ type: 'object',
622
+ properties: {
623
+ level: {
624
+ type: 'string',
625
+ enum: [
626
+ 'info',
627
+ 'warning',
628
+ 'critical',
629
+ 'all'
630
+ ],
631
+ default: 'all'
632
+ },
633
+ limit: {
634
+ type: 'number',
635
+ default: 50
636
+ }
637
+ }
638
+ },
639
+ handler: async (input, context)=>{
640
+ if (!context?.monitor) {
641
+ throw new Error('Monitor not available');
642
+ }
643
+ try {
644
+ let alerts = context.monitor.getActiveAlerts();
645
+ if (input.level !== 'all') {
646
+ alerts = alerts.filter((alert)=>alert.level === input.level);
647
+ }
648
+ alerts = alerts.slice(0, input.limit);
649
+ return {
650
+ success: true,
651
+ alerts,
652
+ count: alerts.length
653
+ };
654
+ } catch (error) {
655
+ logger.error('Failed to get alerts via MCP', error);
656
+ throw error;
657
+ }
658
+ }
659
+ },
660
+ // === UTILITY TOOLS ===
661
+ {
662
+ name: 'swarm/get-comprehensive-status',
663
+ description: 'Get comprehensive status of the entire swarm system',
664
+ inputSchema: {
665
+ type: 'object',
666
+ properties: {}
667
+ },
668
+ handler: async (input, context)=>{
669
+ try {
670
+ const status = {
671
+ timestamp: new Date(),
672
+ system: 'operational'
673
+ };
674
+ if (context?.swarmCoordinator) {
675
+ status.swarm = await context.swarmCoordinator.getSwarmStatus();
676
+ }
677
+ if (context?.agentManager) {
678
+ const agents = await context.agentManager.getAllAgents();
679
+ status.agents = {
680
+ total: agents.length,
681
+ active: agents.filter((a)=>a.status === 'active').length,
682
+ idle: agents.filter((a)=>a.status === 'idle').length,
683
+ busy: agents.filter((a)=>a.status === 'busy').length,
684
+ failed: agents.filter((a)=>a.status === 'failed').length
685
+ };
686
+ }
687
+ if (context?.resourceManager) {
688
+ status.resources = context.resourceManager.getManagerStatistics();
689
+ }
690
+ if (context?.messageBus) {
691
+ status.messaging = context.messageBus.getMetrics();
692
+ }
693
+ if (context?.monitor) {
694
+ status.monitoring = context.monitor.getMonitoringStatistics();
695
+ status.systemMetrics = context.monitor.getSystemMetrics();
696
+ status.swarmMetrics = context.monitor.getSwarmMetrics();
697
+ status.activeAlerts = context.monitor.getActiveAlerts().length;
698
+ }
699
+ return {
700
+ success: true,
701
+ status
702
+ };
703
+ } catch (error) {
704
+ logger.error('Failed to get comprehensive status via MCP', error);
705
+ throw error;
706
+ }
707
+ }
708
+ },
709
+ {
710
+ name: 'swarm/emergency-stop',
711
+ description: 'Emergency stop of all swarm operations',
712
+ inputSchema: {
713
+ type: 'object',
714
+ properties: {
715
+ reason: {
716
+ type: 'string',
717
+ description: 'Reason for emergency stop'
718
+ },
719
+ force: {
720
+ type: 'boolean',
721
+ default: false
722
+ }
723
+ },
724
+ required: [
725
+ 'reason'
726
+ ]
727
+ },
728
+ handler: async (input, context)=>{
729
+ logger.warn('Emergency stop initiated via MCP', {
730
+ reason: input.reason
731
+ });
732
+ const results = {
733
+ reason: input.reason,
734
+ timestamp: new Date(),
735
+ components: {}
736
+ };
737
+ try {
738
+ // Stop swarm coordinator
739
+ if (context?.swarmCoordinator) {
740
+ await context.swarmCoordinator.emergencyStop(input.reason);
741
+ results.components.swarmCoordinator = 'stopped';
742
+ }
743
+ // Stop all agents
744
+ if (context?.agentManager) {
745
+ await context.agentManager.stopAllAgents();
746
+ results.components.agentManager = 'stopped';
747
+ }
748
+ // Release all resources (if method exists)
749
+ if (context?.resourceManager?.releaseAllAllocations) {
750
+ await context.resourceManager.releaseAllAllocations();
751
+ results.components.resourceManager = 'resources_released';
752
+ }
753
+ // Stop message bus
754
+ if (context?.messageBus?.shutdown) {
755
+ await context.messageBus.shutdown();
756
+ results.components.messageBus = 'stopped';
757
+ }
758
+ results.success = true;
759
+ results.message = 'Emergency stop completed successfully';
760
+ logger.info('Emergency stop completed via MCP', results);
761
+ return results;
762
+ } catch (error) {
763
+ logger.error('Emergency stop failed via MCP', error);
764
+ results.success = false;
765
+ results.error = error instanceof Error ? error.message : 'Unknown error';
766
+ throw error;
767
+ }
768
+ }
769
+ }
770
+ ];
771
+ }
772
+ // Legacy exports for backward compatibility
773
+ export const dispatchAgentTool = {
774
+ name: 'dispatch_agent',
775
+ description: 'Spawn a new agent in the swarm to handle a specific task',
776
+ inputSchema: {
777
+ type: 'object',
778
+ properties: {
779
+ type: {
780
+ type: 'string',
781
+ enum: [
782
+ 'researcher',
783
+ 'coder',
784
+ 'analyst',
785
+ 'reviewer',
786
+ 'coordinator'
787
+ ],
788
+ description: 'The type of agent to spawn'
789
+ },
790
+ task: {
791
+ type: 'string',
792
+ description: 'The specific task for the agent to complete'
793
+ },
794
+ name: {
795
+ type: 'string',
796
+ description: 'Optional name for the agent'
797
+ }
798
+ },
799
+ required: [
800
+ 'type',
801
+ 'task'
802
+ ]
803
+ }
804
+ };
805
+ export const memoryStoreTool = {
806
+ name: 'memory_store',
807
+ description: 'Store data in the shared swarm memory for coordination',
808
+ inputSchema: {
809
+ type: 'object',
810
+ properties: {
811
+ key: {
812
+ type: 'string',
813
+ description: 'The key to store data under'
814
+ },
815
+ value: {
816
+ type: 'object',
817
+ description: 'The data to store (JSON object)'
818
+ }
819
+ },
820
+ required: [
821
+ 'key',
822
+ 'value'
823
+ ]
824
+ }
825
+ };
826
+ export const memoryRetrieveTool = {
827
+ name: 'memory_retrieve',
828
+ description: 'Retrieve data from the shared swarm memory',
829
+ inputSchema: {
830
+ type: 'object',
831
+ properties: {
832
+ key: {
833
+ type: 'string',
834
+ description: 'The key to retrieve data from'
835
+ }
836
+ },
837
+ required: [
838
+ 'key'
839
+ ]
840
+ }
841
+ };
842
+ export const swarmStatusTool = {
843
+ name: 'swarm_status',
844
+ description: 'Get the current status of the swarm and all agents',
845
+ inputSchema: {
846
+ type: 'object',
847
+ properties: {}
848
+ }
849
+ };
850
+ // Legacy handler functions
851
+ export async function handleDispatchAgent(args) {
852
+ const { type, task, name } = args;
853
+ const swarmId = process.env['CLAUDE_SWARM_ID'];
854
+ if (!swarmId) {
855
+ throw new Error('Not running in swarm context');
856
+ }
857
+ const parentId = process.env['CLAUDE_SWARM_AGENT_ID'];
858
+ try {
859
+ // Legacy functionality - would integrate with swarm spawn system
860
+ const agentId = `agent-${Date.now()}`;
861
+ return {
862
+ success: true,
863
+ agentId,
864
+ agentName: name || type,
865
+ terminalId: 'N/A',
866
+ message: `Successfully spawned ${name || type} to work on: ${task}`
867
+ };
868
+ } catch (error) {
869
+ return {
870
+ success: false,
871
+ error: error instanceof Error ? error.message : 'Unknown error'
872
+ };
873
+ }
874
+ }
875
+ export async function handleSwarmStatus(args) {
876
+ const swarmId = process.env['CLAUDE_SWARM_ID'] || 'default-swarm';
877
+ // Legacy functionality - would integrate with swarm state system
878
+ const mockState = {
879
+ swarmId,
880
+ objective: 'Legacy swarm status',
881
+ startTime: Date.now() - 60000,
882
+ agents: []
883
+ };
884
+ const runtime = Math.floor((Date.now() - mockState.startTime) / 1000);
885
+ return {
886
+ swarmId: mockState.swarmId,
887
+ objective: mockState.objective,
888
+ runtime: `${runtime}s`,
889
+ totalAgents: mockState.agents.length,
890
+ activeAgents: 0,
891
+ completedAgents: 0,
892
+ failedAgents: 0,
893
+ agents: mockState.agents
894
+ };
895
+ }
896
+ export const swarmTools = [
897
+ dispatchAgentTool,
898
+ memoryStoreTool,
899
+ memoryRetrieveTool,
900
+ swarmStatusTool
901
+ ];
902
+
903
+ //# sourceMappingURL=swarm-tools.js.map