@sparkleideas/ruv-swarm 1.0.18-patch.1
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.
- package/README.md +1565 -0
- package/bin/ruv-swarm-clean.js +1872 -0
- package/bin/ruv-swarm-memory.js +119 -0
- package/bin/ruv-swarm-secure-heartbeat.js +1549 -0
- package/bin/ruv-swarm-secure.js +1689 -0
- package/package.json +221 -0
- package/src/agent.ts +342 -0
- package/src/benchmark.js +267 -0
- package/src/claude-flow-enhanced.js +839 -0
- package/src/claude-integration/advanced-commands.js +561 -0
- package/src/claude-integration/core.js +112 -0
- package/src/claude-integration/docs.js +1548 -0
- package/src/claude-integration/env-template.js +39 -0
- package/src/claude-integration/index.js +209 -0
- package/src/claude-integration/remote.js +408 -0
- package/src/cli-diagnostics.js +364 -0
- package/src/cognitive-pattern-evolution.js +1317 -0
- package/src/daa-cognition.js +977 -0
- package/src/daa-service.d.ts +298 -0
- package/src/daa-service.js +1116 -0
- package/src/diagnostics.js +533 -0
- package/src/errors.js +528 -0
- package/src/github-coordinator/README.md +193 -0
- package/src/github-coordinator/claude-hooks.js +162 -0
- package/src/github-coordinator/gh-cli-coordinator.js +260 -0
- package/src/hooks/cli.js +82 -0
- package/src/hooks/index.js +1900 -0
- package/src/index-enhanced.d.ts +371 -0
- package/src/index-enhanced.js +734 -0
- package/src/index.d.ts +287 -0
- package/src/index.js +405 -0
- package/src/index.ts +457 -0
- package/src/logger.js +182 -0
- package/src/logging-config.js +179 -0
- package/src/mcp-daa-tools.js +735 -0
- package/src/mcp-tools-benchmarks.js +328 -0
- package/src/mcp-tools-enhanced.js +2863 -0
- package/src/memory-config.js +42 -0
- package/src/meta-learning-framework.js +1359 -0
- package/src/neural-agent.js +830 -0
- package/src/neural-coordination-protocol.js +1363 -0
- package/src/neural-models/README.md +118 -0
- package/src/neural-models/autoencoder.js +543 -0
- package/src/neural-models/base.js +269 -0
- package/src/neural-models/cnn.js +497 -0
- package/src/neural-models/gnn.js +447 -0
- package/src/neural-models/gru.js +536 -0
- package/src/neural-models/index.js +273 -0
- package/src/neural-models/lstm.js +551 -0
- package/src/neural-models/neural-presets-complete.js +1306 -0
- package/src/neural-models/presets/graph.js +392 -0
- package/src/neural-models/presets/index.js +279 -0
- package/src/neural-models/presets/nlp.js +328 -0
- package/src/neural-models/presets/timeseries.js +368 -0
- package/src/neural-models/presets/vision.js +387 -0
- package/src/neural-models/resnet.js +534 -0
- package/src/neural-models/transformer.js +515 -0
- package/src/neural-models/vae.js +489 -0
- package/src/neural-network-manager.js +1938 -0
- package/src/neural-network.ts +296 -0
- package/src/neural.js +574 -0
- package/src/performance-benchmarks.js +898 -0
- package/src/performance.js +458 -0
- package/src/persistence-pooled.js +695 -0
- package/src/persistence.js +480 -0
- package/src/schemas.js +864 -0
- package/src/security.js +218 -0
- package/src/singleton-container.js +183 -0
- package/src/sqlite-pool.js +587 -0
- package/src/sqlite-worker.js +141 -0
- package/src/types.ts +164 -0
- package/src/utils.ts +286 -0
- package/src/wasm-loader.js +601 -0
- package/src/wasm-loader2.js +404 -0
- package/src/wasm-memory-optimizer.js +783 -0
- package/src/wasm-types.d.ts +63 -0
- package/wasm/README.md +347 -0
- package/wasm/neuro-divergent.wasm +0 -0
- package/wasm/package.json +18 -0
- package/wasm/ruv-fann.wasm +0 -0
- package/wasm/ruv_swarm_simd.wasm +0 -0
- package/wasm/ruv_swarm_wasm.d.ts +391 -0
- package/wasm/ruv_swarm_wasm.js +2164 -0
- package/wasm/ruv_swarm_wasm_bg.wasm +0 -0
- package/wasm/ruv_swarm_wasm_bg.wasm.d.ts +123 -0
- package/wasm/wasm-bindings-loader.mjs +435 -0
- package/wasm/wasm-updates.md +684 -0
|
@@ -0,0 +1,1872 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Clean, modular @sparkleideas/ruv-swarm CLI with Claude Code integration
|
|
4
|
+
* Uses modular architecture for better maintainability and remote execution
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { setupClaudeIntegration, invokeClaudeWithSwarm } from '../src/claude-integration/index.js';
|
|
8
|
+
import { RuvSwarm } from '../src/index-enhanced.js';
|
|
9
|
+
import { EnhancedMCPTools } from '../src/mcp-tools-enhanced.js';
|
|
10
|
+
import { daaMcpTools } from '../src/mcp-daa-tools.js';
|
|
11
|
+
import mcpToolsEnhanced from '../src/mcp-tools-enhanced.js';
|
|
12
|
+
import { Logger } from '../src/logger.js';
|
|
13
|
+
|
|
14
|
+
// Input validation constants and functions
|
|
15
|
+
const VALID_TOPOLOGIES = ['mesh', 'hierarchical', 'ring', 'star'];
|
|
16
|
+
const VALID_AGENT_TYPES = ['researcher', 'coder', 'analyst', 'optimizer', 'coordinator', 'architect', 'tester'];
|
|
17
|
+
const MAX_AGENTS_LIMIT = 100;
|
|
18
|
+
const MIN_AGENTS_LIMIT = 1;
|
|
19
|
+
|
|
20
|
+
class ValidationError extends Error {
|
|
21
|
+
constructor(message, parameter = null) {
|
|
22
|
+
super(message);
|
|
23
|
+
this.name = 'ValidationError';
|
|
24
|
+
this.parameter = parameter;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function validateTopology(topology) {
|
|
29
|
+
if (!topology || typeof topology !== 'string') {
|
|
30
|
+
throw new ValidationError('Topology must be a non-empty string', 'topology');
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if (!VALID_TOPOLOGIES.includes(topology.toLowerCase())) {
|
|
34
|
+
throw new ValidationError(
|
|
35
|
+
`Invalid topology '${topology}'. Valid topologies are: ${VALID_TOPOLOGIES.join(', ')}`,
|
|
36
|
+
'topology'
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return topology.toLowerCase();
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function validateMaxAgents(maxAgents) {
|
|
44
|
+
// Handle string input
|
|
45
|
+
if (typeof maxAgents === 'string') {
|
|
46
|
+
const parsed = parseInt(maxAgents, 10);
|
|
47
|
+
if (isNaN(parsed)) {
|
|
48
|
+
throw new ValidationError(
|
|
49
|
+
`Invalid maxAgents '${maxAgents}'. Must be a number between ${MIN_AGENTS_LIMIT} and ${MAX_AGENTS_LIMIT}`,
|
|
50
|
+
'maxAgents'
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
maxAgents = parsed;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if (!Number.isInteger(maxAgents) || maxAgents < MIN_AGENTS_LIMIT || maxAgents > MAX_AGENTS_LIMIT) {
|
|
57
|
+
throw new ValidationError(
|
|
58
|
+
`Invalid maxAgents '${maxAgents}'. Must be an integer between ${MIN_AGENTS_LIMIT} and ${MAX_AGENTS_LIMIT}`,
|
|
59
|
+
'maxAgents'
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return maxAgents;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function validateAgentType(type) {
|
|
67
|
+
if (!type || typeof type !== 'string') {
|
|
68
|
+
throw new ValidationError('Agent type must be a non-empty string', 'type');
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
if (!VALID_AGENT_TYPES.includes(type.toLowerCase())) {
|
|
72
|
+
throw new ValidationError(
|
|
73
|
+
`Invalid agent type '${type}'. Valid types are: ${VALID_AGENT_TYPES.join(', ')}`,
|
|
74
|
+
'type'
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return type.toLowerCase();
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function validateAgentName(name) {
|
|
82
|
+
if (name !== null && name !== undefined) {
|
|
83
|
+
if (typeof name !== 'string') {
|
|
84
|
+
throw new ValidationError('Agent name must be a string', 'name');
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
if (name.length === 0) {
|
|
88
|
+
throw new ValidationError('Agent name cannot be empty', 'name');
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
if (name.length > 100) {
|
|
92
|
+
throw new ValidationError('Agent name cannot exceed 100 characters', 'name');
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// Check for invalid characters
|
|
96
|
+
if (!/^[a-zA-Z0-9\s\-_\.]+$/.test(name)) {
|
|
97
|
+
throw new ValidationError(
|
|
98
|
+
'Agent name can only contain letters, numbers, spaces, hyphens, underscores, and periods',
|
|
99
|
+
'name'
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
return name;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function validateTaskDescription(task) {
|
|
108
|
+
if (!task || typeof task !== 'string') {
|
|
109
|
+
throw new ValidationError('Task description must be a non-empty string', 'task');
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
if (task.trim().length === 0) {
|
|
113
|
+
throw new ValidationError('Task description cannot be empty or only whitespace', 'task');
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
if (task.length > 1000) {
|
|
117
|
+
throw new ValidationError('Task description cannot exceed 1000 characters', 'task');
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
return task.trim();
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function logValidationError(error, command) {
|
|
124
|
+
console.log(`❌ Validation Error in '${command}' command:`);
|
|
125
|
+
console.log(` ${error.message}`);
|
|
126
|
+
if (error.parameter) {
|
|
127
|
+
console.log(` Parameter: ${error.parameter}`);
|
|
128
|
+
}
|
|
129
|
+
console.log(`\n💡 For help with valid parameters, run: @sparkleideas/ruv-swarm help`);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
let globalRuvSwarm = null;
|
|
133
|
+
let globalMCPTools = null;
|
|
134
|
+
let globalLogger = null;
|
|
135
|
+
|
|
136
|
+
// Initialize logger based on environment
|
|
137
|
+
function initializeLogger() {
|
|
138
|
+
if (!globalLogger) {
|
|
139
|
+
globalLogger = new Logger({
|
|
140
|
+
name: 'ruv-swarm-mcp',
|
|
141
|
+
level: process.env.LOG_LEVEL || (process.argv.includes('--debug') ? 'DEBUG' : 'INFO'),
|
|
142
|
+
enableStderr: true, // Always use stderr in MCP mode
|
|
143
|
+
enableFile: process.env.LOG_TO_FILE === 'true',
|
|
144
|
+
formatJson: process.env.LOG_FORMAT === 'json',
|
|
145
|
+
logDir: process.env.LOG_DIR || './logs',
|
|
146
|
+
metadata: {
|
|
147
|
+
pid: process.pid,
|
|
148
|
+
version: '1.0.11',
|
|
149
|
+
mode: 'mcp-stdio'
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
// Set up global error handlers
|
|
154
|
+
process.on('uncaughtException', (error) => {
|
|
155
|
+
globalLogger.fatal('Uncaught exception', { error });
|
|
156
|
+
process.exit(1);
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
process.on('unhandledRejection', (reason, promise) => {
|
|
160
|
+
globalLogger.fatal('Unhandled rejection', { reason, promise });
|
|
161
|
+
process.exit(1);
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
return globalLogger;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
async function initializeSystem() {
|
|
168
|
+
if (!globalRuvSwarm) {
|
|
169
|
+
// RuvSwarm.initialize already prints initialization messages
|
|
170
|
+
globalRuvSwarm = await RuvSwarm.initialize({
|
|
171
|
+
loadingStrategy: 'progressive',
|
|
172
|
+
enablePersistence: true,
|
|
173
|
+
enableNeuralNetworks: true,
|
|
174
|
+
enableForecasting: true,
|
|
175
|
+
useSIMD: RuvSwarm.detectSIMDSupport(),
|
|
176
|
+
debug: process.argv.includes('--debug')
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
if (!globalMCPTools) {
|
|
181
|
+
// Pass the already initialized RuvSwarm instance to avoid duplicate initialization
|
|
182
|
+
globalMCPTools = new EnhancedMCPTools(globalRuvSwarm);
|
|
183
|
+
await globalMCPTools.initialize(globalRuvSwarm);
|
|
184
|
+
|
|
185
|
+
// Initialize DAA MCP tools with the same instance
|
|
186
|
+
daaMcpTools.mcpTools = globalMCPTools;
|
|
187
|
+
await daaMcpTools.ensureInitialized();
|
|
188
|
+
|
|
189
|
+
// Add DAA tool methods to the MCP tools object
|
|
190
|
+
const daaToolNames = [
|
|
191
|
+
'daa_init', 'daa_agent_create', 'daa_agent_adapt', 'daa_workflow_create',
|
|
192
|
+
'daa_workflow_execute', 'daa_knowledge_share', 'daa_learning_status',
|
|
193
|
+
'daa_cognitive_pattern', 'daa_meta_learning', 'daa_performance_metrics'
|
|
194
|
+
];
|
|
195
|
+
|
|
196
|
+
for (const toolName of daaToolNames) {
|
|
197
|
+
if (typeof daaMcpTools[toolName] === 'function') {
|
|
198
|
+
globalMCPTools[toolName] = daaMcpTools[toolName].bind(daaMcpTools);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
return { ruvSwarm: globalRuvSwarm, mcpTools: globalMCPTools };
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
async function handleInit(args) {
|
|
207
|
+
try {
|
|
208
|
+
const { mcpTools } = await initializeSystem();
|
|
209
|
+
|
|
210
|
+
// Filter out flags to get positional arguments
|
|
211
|
+
const positionalArgs = args.filter(arg => !arg.startsWith('--'));
|
|
212
|
+
const rawTopology = positionalArgs[0] || 'mesh';
|
|
213
|
+
const rawMaxAgents = positionalArgs[1] || '5';
|
|
214
|
+
const setupClaude = args.includes('--claude') || args.includes('--setup-claude');
|
|
215
|
+
const forceSetup = args.includes('--force');
|
|
216
|
+
const mergeSetup = args.includes('--merge');
|
|
217
|
+
const noInteractive = args.includes('--no-interactive');
|
|
218
|
+
const noBackup = args.includes('--no-backup');
|
|
219
|
+
|
|
220
|
+
// Validate inputs
|
|
221
|
+
const topology = validateTopology(rawTopology);
|
|
222
|
+
const maxAgents = validateMaxAgents(rawMaxAgents);
|
|
223
|
+
|
|
224
|
+
console.log('🚀 Initializing @sparkleideas/ruv-swarm...');
|
|
225
|
+
|
|
226
|
+
const result = await mcpTools.swarm_init({
|
|
227
|
+
topology,
|
|
228
|
+
maxAgents,
|
|
229
|
+
strategy: 'balanced',
|
|
230
|
+
enableCognitiveDiversity: true,
|
|
231
|
+
enableNeuralAgents: true,
|
|
232
|
+
enableForecasting: args.includes('--forecasting')
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
console.log('🐝 Swarm initialized:');
|
|
236
|
+
console.log(' ID: ' + result.id);
|
|
237
|
+
console.log(' Topology: ' + result.topology);
|
|
238
|
+
console.log(' Max Agents: ' + result.maxAgents);
|
|
239
|
+
console.log(' Features: ' + Object.entries(result.features).filter(([k,v]) => v).map(([k,v]) => k).join(', '));
|
|
240
|
+
console.log(' Performance: ' + result.performance.initialization_time_ms.toFixed(1) + 'ms');
|
|
241
|
+
|
|
242
|
+
// Setup Claude integration using modular approach
|
|
243
|
+
if (setupClaude || forceSetup || mergeSetup) {
|
|
244
|
+
console.log('\n📚 Setting up modular Claude Code integration...');
|
|
245
|
+
try {
|
|
246
|
+
await setupClaudeIntegration({
|
|
247
|
+
autoSetup: setupClaude,
|
|
248
|
+
forceSetup: forceSetup,
|
|
249
|
+
mergeSetup: mergeSetup,
|
|
250
|
+
noBackup: noBackup,
|
|
251
|
+
interactive: !noInteractive,
|
|
252
|
+
workingDir: process.cwd(),
|
|
253
|
+
packageName: '@sparkleideas/ruv-swarm'
|
|
254
|
+
});
|
|
255
|
+
} catch (error) {
|
|
256
|
+
console.log('⚠️ Claude integration setup had issues:', error.message);
|
|
257
|
+
console.log('💡 Manual setup: claude mcp add @sparkleideas/ruv-swarm npx @sparkleideas/ruv-swarm mcp start');
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
console.log('\n✅ Initialization complete!');
|
|
262
|
+
console.log('\n🔗 Next steps:');
|
|
263
|
+
console.log(' 1. Test with MCP tools: mcp__ruv-swarm__agent_spawn');
|
|
264
|
+
console.log(' 2. Use wrapper scripts for remote execution');
|
|
265
|
+
console.log(' 3. Check .claude/commands/ for detailed guides');
|
|
266
|
+
|
|
267
|
+
if (forceSetup) {
|
|
268
|
+
console.log('\n🔄 Files regenerated with --force flag');
|
|
269
|
+
} else if (mergeSetup) {
|
|
270
|
+
console.log('\n🔄 Configuration merged with existing files');
|
|
271
|
+
}
|
|
272
|
+
} catch (error) {
|
|
273
|
+
if (error instanceof ValidationError) {
|
|
274
|
+
logValidationError(error, 'init');
|
|
275
|
+
return;
|
|
276
|
+
}
|
|
277
|
+
throw error;
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
async function handleSpawn(args) {
|
|
282
|
+
try {
|
|
283
|
+
const { mcpTools } = await initializeSystem();
|
|
284
|
+
|
|
285
|
+
const rawType = args[0] || 'researcher';
|
|
286
|
+
const rawName = args[1] || null;
|
|
287
|
+
|
|
288
|
+
// Validate inputs
|
|
289
|
+
const type = validateAgentType(rawType);
|
|
290
|
+
const name = validateAgentName(rawName);
|
|
291
|
+
|
|
292
|
+
const result = await mcpTools.agent_spawn({
|
|
293
|
+
type,
|
|
294
|
+
name,
|
|
295
|
+
enableNeuralNetwork: !args.includes('--no-neural')
|
|
296
|
+
});
|
|
297
|
+
|
|
298
|
+
console.log('🤖 Agent spawned:');
|
|
299
|
+
console.log(' ID: ' + result.agent.id);
|
|
300
|
+
console.log(' Name: ' + result.agent.name);
|
|
301
|
+
console.log(' Type: ' + result.agent.type);
|
|
302
|
+
console.log(' Cognitive Pattern: ' + result.agent.cognitive_pattern);
|
|
303
|
+
if (result.agent.neural_network_id) {
|
|
304
|
+
console.log(' Neural Network: ' + result.agent.neural_network_id);
|
|
305
|
+
}
|
|
306
|
+
console.log(' Swarm Capacity: ' + result.swarm_info.capacity);
|
|
307
|
+
} catch (error) {
|
|
308
|
+
if (error instanceof ValidationError) {
|
|
309
|
+
logValidationError(error, 'spawn');
|
|
310
|
+
return;
|
|
311
|
+
}
|
|
312
|
+
throw error;
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
async function handleOrchestrate(args) {
|
|
317
|
+
try {
|
|
318
|
+
const { mcpTools } = await initializeSystem();
|
|
319
|
+
|
|
320
|
+
const rawTask = args.join(' ');
|
|
321
|
+
if (!rawTask) {
|
|
322
|
+
console.log('❌ No task provided');
|
|
323
|
+
console.log('Usage: @sparkleideas/ruv-swarm orchestrate "task description"');
|
|
324
|
+
return;
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
// Validate task description
|
|
328
|
+
const task = validateTaskDescription(rawTask);
|
|
329
|
+
|
|
330
|
+
const result = await mcpTools.task_orchestrate({
|
|
331
|
+
task: task,
|
|
332
|
+
strategy: 'adaptive'
|
|
333
|
+
});
|
|
334
|
+
|
|
335
|
+
console.log('📋 Task orchestrated:');
|
|
336
|
+
console.log(' ID: ' + result.taskId);
|
|
337
|
+
console.log(' Description: ' + result.description);
|
|
338
|
+
console.log(' Assigned Agents: ' + result.assigned_agents.length);
|
|
339
|
+
console.log(' Status: ' + result.status);
|
|
340
|
+
console.log(' Estimated Completion: ' + result.performance.estimated_completion_ms + 'ms');
|
|
341
|
+
} catch (error) {
|
|
342
|
+
if (error instanceof ValidationError) {
|
|
343
|
+
logValidationError(error, 'orchestrate');
|
|
344
|
+
return;
|
|
345
|
+
}
|
|
346
|
+
throw error;
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
async function handleClaudeInvoke(args) {
|
|
351
|
+
const filteredArgs = args.filter(arg =>
|
|
352
|
+
!arg.includes('--skip-permissions') &&
|
|
353
|
+
!arg.includes('--dangerously-skip-permissions')
|
|
354
|
+
);
|
|
355
|
+
|
|
356
|
+
const prompt = filteredArgs.join(' ');
|
|
357
|
+
|
|
358
|
+
if (!prompt.trim()) {
|
|
359
|
+
console.log('❌ No prompt provided');
|
|
360
|
+
console.log('Usage: @sparkleideas/ruv-swarm claude-invoke "your swarm prompt"');
|
|
361
|
+
console.log('Note: --dangerously-skip-permissions is automatically included');
|
|
362
|
+
return;
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
console.log('🚀 Invoking Claude Code with @sparkleideas/ruv-swarm integration...');
|
|
366
|
+
console.log('Prompt: ' + prompt.trim());
|
|
367
|
+
console.log('⚠️ Automatically using --dangerously-skip-permissions for seamless execution');
|
|
368
|
+
|
|
369
|
+
try {
|
|
370
|
+
await invokeClaudeWithSwarm(prompt, {
|
|
371
|
+
workingDir: process.cwd()
|
|
372
|
+
});
|
|
373
|
+
} catch (error) {
|
|
374
|
+
console.error('❌ Claude invocation failed:', error.message);
|
|
375
|
+
console.error('Make sure Claude Code CLI is installed and in your PATH');
|
|
376
|
+
process.exit(1);
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
async function handleStatus(args) {
|
|
381
|
+
const { mcpTools } = await initializeSystem();
|
|
382
|
+
|
|
383
|
+
const verbose = args.includes('--verbose') || args.includes('-v');
|
|
384
|
+
const swarmId = args.find(arg => !arg.startsWith('-'));
|
|
385
|
+
|
|
386
|
+
const result = await mcpTools.swarm_status({ verbose });
|
|
387
|
+
|
|
388
|
+
if (swarmId) {
|
|
389
|
+
console.log(`🐝 Swarm Status (${swarmId}):`);
|
|
390
|
+
console.log(` Agents: ${result.agents.total} (${result.agents.active} active, ${result.agents.idle} idle)`);
|
|
391
|
+
console.log(` Tasks: ${result.tasks.total} (${result.tasks.pending} pending, ${result.tasks.in_progress} in progress)`);
|
|
392
|
+
} else {
|
|
393
|
+
console.log('🌐 Global Status:');
|
|
394
|
+
console.log(` Active Swarms: ${result.active_swarms}`);
|
|
395
|
+
console.log(` Total Agents: ${result.global_metrics.totalAgents}`);
|
|
396
|
+
console.log(` Total Tasks: ${result.global_metrics.totalTasks}`);
|
|
397
|
+
console.log(` Memory Usage: ${result.global_metrics.memoryUsage / (1024 * 1024)}MB`);
|
|
398
|
+
|
|
399
|
+
if (verbose) {
|
|
400
|
+
console.log('\n📊 WASM Modules:');
|
|
401
|
+
Object.entries(result.runtime_info.wasm_modules).forEach(([name, status]) => {
|
|
402
|
+
console.log(` ${name}: ${status.loaded ? '✅ Loaded' : '⏳ Not loaded'} (${(status.size / 1024).toFixed(0)}KB)`);
|
|
403
|
+
});
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
async function handleMonitor(args) {
|
|
409
|
+
const { mcpTools } = await initializeSystem();
|
|
410
|
+
|
|
411
|
+
const duration = parseInt(args.find(arg => arg.match(/^\d+$/))) || 10000;
|
|
412
|
+
|
|
413
|
+
console.log(`📊 Monitoring for ${duration}ms...`);
|
|
414
|
+
console.log('Press Ctrl+C to stop\n');
|
|
415
|
+
|
|
416
|
+
const interval = setInterval(async () => {
|
|
417
|
+
const status = await mcpTools.swarm_status({ verbose: false });
|
|
418
|
+
process.stdout.write('\r');
|
|
419
|
+
process.stdout.write(`Swarms: ${status.active_swarms} | Agents: ${status.global_metrics.totalAgents} | Tasks: ${status.global_metrics.totalTasks} | Memory: ${(status.global_metrics.memoryUsage / (1024 * 1024)).toFixed(1)}MB`);
|
|
420
|
+
}, 1000);
|
|
421
|
+
|
|
422
|
+
setTimeout(() => {
|
|
423
|
+
clearInterval(interval);
|
|
424
|
+
console.log('\n\n✅ Monitoring complete');
|
|
425
|
+
}, duration);
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
async function handleMcp(args) {
|
|
429
|
+
const subcommand = args[0] || 'help';
|
|
430
|
+
|
|
431
|
+
switch (subcommand) {
|
|
432
|
+
case 'start':
|
|
433
|
+
await startMcpServer(args.slice(1));
|
|
434
|
+
break;
|
|
435
|
+
case 'status':
|
|
436
|
+
await getMcpStatus();
|
|
437
|
+
break;
|
|
438
|
+
case 'stop':
|
|
439
|
+
await stopMcpServer();
|
|
440
|
+
break;
|
|
441
|
+
case 'tools':
|
|
442
|
+
await listMcpTools();
|
|
443
|
+
break;
|
|
444
|
+
case 'config':
|
|
445
|
+
await configureMcp(args.slice(1));
|
|
446
|
+
break;
|
|
447
|
+
case 'help':
|
|
448
|
+
default:
|
|
449
|
+
showMcpHelp();
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
async function startMcpServer(args) {
|
|
454
|
+
const protocol = args.find(arg => arg.startsWith('--protocol='))?.split('=')[1] || 'stdio';
|
|
455
|
+
const port = args.find(arg => arg.startsWith('--port='))?.split('=')[1] || '3000';
|
|
456
|
+
const host = args.find(arg => arg.startsWith('--host='))?.split('=')[1] || 'localhost';
|
|
457
|
+
|
|
458
|
+
// Initialize logger first
|
|
459
|
+
const logger = initializeLogger();
|
|
460
|
+
const sessionId = logger.setCorrelationId();
|
|
461
|
+
|
|
462
|
+
try {
|
|
463
|
+
if (protocol === 'stdio') {
|
|
464
|
+
// In stdio mode, only JSON-RPC messages should go to stdout
|
|
465
|
+
logger.info('@sparkleideas/ruv-swarm MCP server starting in stdio mode', {
|
|
466
|
+
protocol,
|
|
467
|
+
sessionId,
|
|
468
|
+
nodeVersion: process.version,
|
|
469
|
+
platform: process.platform,
|
|
470
|
+
arch: process.arch
|
|
471
|
+
});
|
|
472
|
+
|
|
473
|
+
// Log connection establishment
|
|
474
|
+
logger.logConnection('established', sessionId, {
|
|
475
|
+
protocol: 'stdio',
|
|
476
|
+
transport: 'stdin/stdout',
|
|
477
|
+
timestamp: new Date().toISOString()
|
|
478
|
+
});
|
|
479
|
+
|
|
480
|
+
// Initialize WASM if needed
|
|
481
|
+
const initOpId = logger.startOperation('initialize-system');
|
|
482
|
+
const { ruvSwarm, mcpTools } = await initializeSystem();
|
|
483
|
+
logger.endOperation(initOpId, true, { modulesLoaded: true });
|
|
484
|
+
|
|
485
|
+
// Start stdio MCP server loop
|
|
486
|
+
process.stdin.setEncoding('utf8');
|
|
487
|
+
|
|
488
|
+
// Signal server readiness for testing
|
|
489
|
+
if (process.env.MCP_TEST_MODE === 'true') {
|
|
490
|
+
console.error('MCP server ready'); // Use stderr so it doesn't interfere with JSON-RPC
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
let buffer = '';
|
|
494
|
+
let messageCount = 0;
|
|
495
|
+
|
|
496
|
+
process.stdin.on('data', (chunk) => {
|
|
497
|
+
logger.trace('Received stdin data', { bytes: chunk.length });
|
|
498
|
+
buffer += chunk;
|
|
499
|
+
|
|
500
|
+
// Process complete JSON messages
|
|
501
|
+
const lines = buffer.split('\n');
|
|
502
|
+
buffer = lines.pop() || '';
|
|
503
|
+
|
|
504
|
+
for (const line of lines) {
|
|
505
|
+
if (line.trim()) {
|
|
506
|
+
messageCount++;
|
|
507
|
+
const messageId = `msg-${sessionId}-${messageCount}`;
|
|
508
|
+
|
|
509
|
+
try {
|
|
510
|
+
const request = JSON.parse(line);
|
|
511
|
+
logger.logMcp('in', request.method || 'unknown', {
|
|
512
|
+
method: request.method,
|
|
513
|
+
id: request.id,
|
|
514
|
+
params: request.params,
|
|
515
|
+
messageId
|
|
516
|
+
});
|
|
517
|
+
|
|
518
|
+
const opId = logger.startOperation(`mcp-${request.method}`, {
|
|
519
|
+
requestId: request.id,
|
|
520
|
+
messageId
|
|
521
|
+
});
|
|
522
|
+
|
|
523
|
+
handleMcpRequest(request, mcpTools, logger).then(response => {
|
|
524
|
+
logger.endOperation(opId, !response.error, {
|
|
525
|
+
hasError: !!response.error
|
|
526
|
+
});
|
|
527
|
+
|
|
528
|
+
logger.logMcp('out', request.method || 'response', {
|
|
529
|
+
method: request.method,
|
|
530
|
+
id: response.id,
|
|
531
|
+
result: response.result,
|
|
532
|
+
error: response.error,
|
|
533
|
+
messageId
|
|
534
|
+
});
|
|
535
|
+
|
|
536
|
+
try {
|
|
537
|
+
process.stdout.write(JSON.stringify(response) + '\n');
|
|
538
|
+
} catch (writeError) {
|
|
539
|
+
logger.error('Failed to write response to stdout', { writeError, response });
|
|
540
|
+
process.exit(1);
|
|
541
|
+
}
|
|
542
|
+
}).catch(error => {
|
|
543
|
+
logger.endOperation(opId, false, { error });
|
|
544
|
+
logger.error('Request handler error', { error, request });
|
|
545
|
+
|
|
546
|
+
const errorResponse = {
|
|
547
|
+
jsonrpc: '2.0',
|
|
548
|
+
error: {
|
|
549
|
+
code: -32603,
|
|
550
|
+
message: 'Internal error',
|
|
551
|
+
data: error.message
|
|
552
|
+
},
|
|
553
|
+
id: request.id
|
|
554
|
+
};
|
|
555
|
+
process.stdout.write(JSON.stringify(errorResponse) + '\n');
|
|
556
|
+
});
|
|
557
|
+
} catch (error) {
|
|
558
|
+
logger.error('JSON parse error', {
|
|
559
|
+
error,
|
|
560
|
+
line: line.substring(0, 100),
|
|
561
|
+
messageId
|
|
562
|
+
});
|
|
563
|
+
|
|
564
|
+
const errorResponse = {
|
|
565
|
+
jsonrpc: '2.0',
|
|
566
|
+
error: {
|
|
567
|
+
code: -32700,
|
|
568
|
+
message: 'Parse error',
|
|
569
|
+
data: error.message
|
|
570
|
+
},
|
|
571
|
+
id: null
|
|
572
|
+
};
|
|
573
|
+
process.stdout.write(JSON.stringify(errorResponse) + '\n');
|
|
574
|
+
}
|
|
575
|
+
}
|
|
576
|
+
}
|
|
577
|
+
});
|
|
578
|
+
|
|
579
|
+
// Set up connection monitoring
|
|
580
|
+
const monitorInterval = setInterval(() => {
|
|
581
|
+
logger.logMemoryUsage('mcp-server');
|
|
582
|
+
logger.debug('Connection metrics', logger.getConnectionMetrics());
|
|
583
|
+
}, 60000); // Every minute
|
|
584
|
+
|
|
585
|
+
// Handle stdin close
|
|
586
|
+
process.stdin.on('end', () => {
|
|
587
|
+
logger.logConnection('closed', sessionId, {
|
|
588
|
+
messagesProcessed: messageCount,
|
|
589
|
+
uptime: process.uptime()
|
|
590
|
+
});
|
|
591
|
+
logger.info('MCP: stdin closed, shutting down...');
|
|
592
|
+
clearInterval(monitorInterval);
|
|
593
|
+
process.exit(0);
|
|
594
|
+
});
|
|
595
|
+
|
|
596
|
+
process.stdin.on('error', (error) => {
|
|
597
|
+
logger.logConnection('failed', sessionId, { error });
|
|
598
|
+
logger.error('MCP: stdin error, shutting down...', { error });
|
|
599
|
+
clearInterval(monitorInterval);
|
|
600
|
+
process.exit(1);
|
|
601
|
+
});
|
|
602
|
+
|
|
603
|
+
// Handle process termination signals
|
|
604
|
+
process.on('SIGTERM', () => {
|
|
605
|
+
logger.info('MCP: Received SIGTERM, shutting down gracefully...');
|
|
606
|
+
clearInterval(monitorInterval);
|
|
607
|
+
process.exit(0);
|
|
608
|
+
});
|
|
609
|
+
|
|
610
|
+
process.on('SIGINT', () => {
|
|
611
|
+
logger.info('MCP: Received SIGINT, shutting down gracefully...');
|
|
612
|
+
clearInterval(monitorInterval);
|
|
613
|
+
process.exit(0);
|
|
614
|
+
});
|
|
615
|
+
|
|
616
|
+
// Send initialization message
|
|
617
|
+
const initMessage = {
|
|
618
|
+
jsonrpc: '2.0',
|
|
619
|
+
method: 'server.initialized',
|
|
620
|
+
params: {
|
|
621
|
+
serverInfo: {
|
|
622
|
+
name: '@sparkleideas/ruv-swarm',
|
|
623
|
+
version: '1.0.8',
|
|
624
|
+
capabilities: {
|
|
625
|
+
tools: true,
|
|
626
|
+
prompts: false,
|
|
627
|
+
resources: true
|
|
628
|
+
}
|
|
629
|
+
}
|
|
630
|
+
}
|
|
631
|
+
};
|
|
632
|
+
process.stdout.write(JSON.stringify(initMessage) + '\n');
|
|
633
|
+
|
|
634
|
+
// Implement heartbeat mechanism
|
|
635
|
+
let lastActivity = Date.now();
|
|
636
|
+
const heartbeatInterval = 30000; // 30 seconds
|
|
637
|
+
const heartbeatTimeout = 90000; // 90 seconds
|
|
638
|
+
|
|
639
|
+
// Update activity on any received message
|
|
640
|
+
const originalOnData = process.stdin._events.data;
|
|
641
|
+
process.stdin.on('data', () => {
|
|
642
|
+
lastActivity = Date.now();
|
|
643
|
+
});
|
|
644
|
+
|
|
645
|
+
// Check for connection health
|
|
646
|
+
const heartbeatChecker = setInterval(() => {
|
|
647
|
+
const timeSinceLastActivity = Date.now() - lastActivity;
|
|
648
|
+
|
|
649
|
+
if (timeSinceLastActivity > heartbeatTimeout) {
|
|
650
|
+
logger.error('MCP: Connection timeout - no activity for', timeSinceLastActivity, 'ms');
|
|
651
|
+
logger.logConnection('timeout', sessionId, {
|
|
652
|
+
lastActivity: new Date(lastActivity).toISOString(),
|
|
653
|
+
timeout: heartbeatTimeout
|
|
654
|
+
});
|
|
655
|
+
clearInterval(monitorInterval);
|
|
656
|
+
clearInterval(heartbeatChecker);
|
|
657
|
+
process.exit(1);
|
|
658
|
+
} else if (timeSinceLastActivity > heartbeatInterval) {
|
|
659
|
+
logger.debug('MCP: Connection idle for', timeSinceLastActivity, 'ms');
|
|
660
|
+
}
|
|
661
|
+
}, 5000); // Check every 5 seconds
|
|
662
|
+
|
|
663
|
+
// Clean up heartbeat on exit
|
|
664
|
+
process.on('exit', () => {
|
|
665
|
+
clearInterval(heartbeatChecker);
|
|
666
|
+
});
|
|
667
|
+
|
|
668
|
+
} else {
|
|
669
|
+
logger.error('WebSocket protocol not yet implemented', { protocol });
|
|
670
|
+
console.log('❌ WebSocket protocol not yet implemented in clean version');
|
|
671
|
+
console.log('Use stdio mode for Claude Code integration');
|
|
672
|
+
}
|
|
673
|
+
} catch (error) {
|
|
674
|
+
logger.fatal('Failed to start MCP server', { error, protocol });
|
|
675
|
+
console.error('❌ Failed to start MCP server:', error.message);
|
|
676
|
+
process.exit(1);
|
|
677
|
+
}
|
|
678
|
+
}
|
|
679
|
+
|
|
680
|
+
async function getMcpStatus() {
|
|
681
|
+
console.log('🔍 MCP Server Status:');
|
|
682
|
+
console.log(' Protocol: stdio (for Claude Code integration)');
|
|
683
|
+
console.log(' Status: Ready to start');
|
|
684
|
+
console.log(' Usage: npx @sparkleideas/ruv-swarm mcp start');
|
|
685
|
+
}
|
|
686
|
+
|
|
687
|
+
async function stopMcpServer() {
|
|
688
|
+
console.log('✅ MCP server stopped (stdio mode exits automatically)');
|
|
689
|
+
}
|
|
690
|
+
|
|
691
|
+
async function listMcpTools() {
|
|
692
|
+
console.log('🛠️ Available MCP Tools:');
|
|
693
|
+
console.log('\n📊 Core Swarm Tools:');
|
|
694
|
+
console.log(' mcp__ruv-swarm__swarm_init - Initialize a new swarm');
|
|
695
|
+
console.log(' mcp__ruv-swarm__agent_spawn - Spawn new agents');
|
|
696
|
+
console.log(' mcp__ruv-swarm__task_orchestrate - Orchestrate tasks');
|
|
697
|
+
console.log(' mcp__ruv-swarm__swarm_status - Get swarm status');
|
|
698
|
+
console.log(' ... and 11 more core tools');
|
|
699
|
+
console.log('\n🤖 DAA (Decentralized Autonomous Agents) Tools:');
|
|
700
|
+
console.log(' mcp__ruv-swarm__daa_init - Initialize DAA service');
|
|
701
|
+
console.log(' mcp__ruv-swarm__daa_agent_create - Create autonomous agents');
|
|
702
|
+
console.log(' mcp__ruv-swarm__daa_workflow_create - Create DAA workflows');
|
|
703
|
+
console.log(' mcp__ruv-swarm__daa_learning_status - Get learning progress');
|
|
704
|
+
console.log(' ... and 6 more DAA tools');
|
|
705
|
+
console.log('\nFor full documentation, run: @sparkleideas/ruv-swarm init --claude');
|
|
706
|
+
}
|
|
707
|
+
|
|
708
|
+
function showMcpHelp() {
|
|
709
|
+
console.log(`
|
|
710
|
+
🔌 MCP (Model Context Protocol) Commands
|
|
711
|
+
|
|
712
|
+
Usage: @sparkleideas/ruv-swarm mcp <subcommand> [options]
|
|
713
|
+
|
|
714
|
+
Subcommands:
|
|
715
|
+
start [--protocol=stdio] Start MCP server (stdio for Claude Code)
|
|
716
|
+
status Show MCP server status
|
|
717
|
+
stop Stop MCP server
|
|
718
|
+
tools List available MCP tools
|
|
719
|
+
help Show this help message
|
|
720
|
+
|
|
721
|
+
Examples:
|
|
722
|
+
@sparkleideas/ruv-swarm mcp start # Start stdio MCP server
|
|
723
|
+
@sparkleideas/ruv-swarm mcp tools # List available tools
|
|
724
|
+
|
|
725
|
+
For Claude Code integration:
|
|
726
|
+
claude mcp add @sparkleideas/ruv-swarm npx @sparkleideas/ruv-swarm mcp start
|
|
727
|
+
`);
|
|
728
|
+
}
|
|
729
|
+
|
|
730
|
+
async function configureMcp(args) {
|
|
731
|
+
console.log('🔧 MCP configuration is managed through Claude Code');
|
|
732
|
+
console.log('Run: @sparkleideas/ruv-swarm init --claude');
|
|
733
|
+
}
|
|
734
|
+
|
|
735
|
+
async function getResourceContent(uri) {
|
|
736
|
+
const resources = {
|
|
737
|
+
'swarm://docs/getting-started': {
|
|
738
|
+
contents: [{
|
|
739
|
+
uri,
|
|
740
|
+
mimeType: 'text/markdown',
|
|
741
|
+
text: `# Getting Started with @sparkleideas/ruv-swarm
|
|
742
|
+
|
|
743
|
+
## Introduction
|
|
744
|
+
@sparkleideas/ruv-swarm is a powerful WASM-powered neural swarm orchestration system that enhances Claude Code's capabilities through intelligent agent coordination.
|
|
745
|
+
|
|
746
|
+
## Quick Start
|
|
747
|
+
|
|
748
|
+
1. **Initialize a swarm:**
|
|
749
|
+
\`\`\`bash
|
|
750
|
+
mcp__ruv-swarm__swarm_init { topology: "mesh", maxAgents: 5 }
|
|
751
|
+
\`\`\`
|
|
752
|
+
|
|
753
|
+
2. **Spawn agents:**
|
|
754
|
+
\`\`\`bash
|
|
755
|
+
mcp__ruv-swarm__agent_spawn { type: "researcher", name: "Doc Analyzer" }
|
|
756
|
+
mcp__ruv-swarm__agent_spawn { type: "coder", name: "Implementation Expert" }
|
|
757
|
+
\`\`\`
|
|
758
|
+
|
|
759
|
+
3. **Orchestrate tasks:**
|
|
760
|
+
\`\`\`bash
|
|
761
|
+
mcp__ruv-swarm__task_orchestrate { task: "Build a REST API", strategy: "adaptive" }
|
|
762
|
+
\`\`\`
|
|
763
|
+
|
|
764
|
+
## Key Concepts
|
|
765
|
+
|
|
766
|
+
- **Agents**: Cognitive patterns that guide Claude Code's approach
|
|
767
|
+
- **Topologies**: Organizational structures for agent coordination
|
|
768
|
+
- **Memory**: Persistent state across sessions
|
|
769
|
+
- **Neural Training**: Continuous improvement through learning
|
|
770
|
+
|
|
771
|
+
## Best Practices
|
|
772
|
+
|
|
773
|
+
1. Always batch operations in a single message
|
|
774
|
+
2. Use memory for cross-agent coordination
|
|
775
|
+
3. Monitor progress with status tools
|
|
776
|
+
4. Train neural patterns for better results`
|
|
777
|
+
}]
|
|
778
|
+
},
|
|
779
|
+
'swarm://docs/topologies': {
|
|
780
|
+
contents: [{
|
|
781
|
+
uri,
|
|
782
|
+
mimeType: 'text/markdown',
|
|
783
|
+
text: `# Swarm Topologies
|
|
784
|
+
|
|
785
|
+
## Available Topologies
|
|
786
|
+
|
|
787
|
+
### 1. Mesh
|
|
788
|
+
- **Description**: Fully connected network where all agents communicate
|
|
789
|
+
- **Best for**: Complex problems requiring diverse perspectives
|
|
790
|
+
- **Characteristics**: High coordination, maximum information sharing
|
|
791
|
+
|
|
792
|
+
### 2. Hierarchical
|
|
793
|
+
- **Description**: Tree-like structure with clear command chain
|
|
794
|
+
- **Best for**: Large projects with clear subtasks
|
|
795
|
+
- **Characteristics**: Efficient delegation, clear responsibilities
|
|
796
|
+
|
|
797
|
+
### 3. Ring
|
|
798
|
+
- **Description**: Circular arrangement with sequential processing
|
|
799
|
+
- **Best for**: Pipeline tasks, sequential workflows
|
|
800
|
+
- **Characteristics**: Low overhead, predictable flow
|
|
801
|
+
|
|
802
|
+
### 4. Star
|
|
803
|
+
- **Description**: Central coordinator with peripheral agents
|
|
804
|
+
- **Best for**: Simple coordination tasks
|
|
805
|
+
- **Characteristics**: Minimal complexity, central control
|
|
806
|
+
|
|
807
|
+
## Choosing a Topology
|
|
808
|
+
|
|
809
|
+
Consider:
|
|
810
|
+
- Task complexity
|
|
811
|
+
- Number of agents
|
|
812
|
+
- Communication needs
|
|
813
|
+
- Performance requirements`
|
|
814
|
+
}]
|
|
815
|
+
},
|
|
816
|
+
'swarm://docs/agent-types': {
|
|
817
|
+
contents: [{
|
|
818
|
+
uri,
|
|
819
|
+
mimeType: 'text/markdown',
|
|
820
|
+
text: `# Agent Types Guide
|
|
821
|
+
|
|
822
|
+
## Available Agent Types
|
|
823
|
+
|
|
824
|
+
### 1. Researcher
|
|
825
|
+
- **Cognitive Pattern**: Divergent thinking
|
|
826
|
+
- **Capabilities**: Information gathering, analysis, exploration
|
|
827
|
+
- **Best for**: Research tasks, documentation review, learning
|
|
828
|
+
|
|
829
|
+
### 2. Coder
|
|
830
|
+
- **Cognitive Pattern**: Convergent thinking
|
|
831
|
+
- **Capabilities**: Implementation, debugging, optimization
|
|
832
|
+
- **Best for**: Writing code, fixing bugs, refactoring
|
|
833
|
+
|
|
834
|
+
### 3. Analyst
|
|
835
|
+
- **Cognitive Pattern**: Systems thinking
|
|
836
|
+
- **Capabilities**: Pattern recognition, data analysis, insights
|
|
837
|
+
- **Best for**: Architecture design, performance analysis
|
|
838
|
+
|
|
839
|
+
### 4. Optimizer
|
|
840
|
+
- **Cognitive Pattern**: Critical thinking
|
|
841
|
+
- **Capabilities**: Performance tuning, efficiency improvements
|
|
842
|
+
- **Best for**: Optimization tasks, bottleneck resolution
|
|
843
|
+
|
|
844
|
+
### 5. Coordinator
|
|
845
|
+
- **Cognitive Pattern**: Lateral thinking
|
|
846
|
+
- **Capabilities**: Task management, delegation, synthesis
|
|
847
|
+
- **Best for**: Project management, integration tasks
|
|
848
|
+
|
|
849
|
+
### 6. Architect
|
|
850
|
+
- **Cognitive Pattern**: Abstract thinking
|
|
851
|
+
- **Capabilities**: System design, high-level planning
|
|
852
|
+
- **Best for**: Architecture decisions, design patterns
|
|
853
|
+
|
|
854
|
+
### 7. Tester
|
|
855
|
+
- **Cognitive Pattern**: Critical evaluation
|
|
856
|
+
- **Capabilities**: Quality assurance, edge case finding
|
|
857
|
+
- **Best for**: Testing, validation, quality control`
|
|
858
|
+
}]
|
|
859
|
+
},
|
|
860
|
+
'swarm://docs/daa-guide': {
|
|
861
|
+
contents: [{
|
|
862
|
+
uri,
|
|
863
|
+
mimeType: 'text/markdown',
|
|
864
|
+
text: `# DAA Integration Guide
|
|
865
|
+
|
|
866
|
+
## Decentralized Autonomous Agents
|
|
867
|
+
|
|
868
|
+
DAA extends @sparkleideas/ruv-swarm with autonomous learning and adaptation capabilities.
|
|
869
|
+
|
|
870
|
+
## Key Features
|
|
871
|
+
|
|
872
|
+
1. **Autonomous Learning**: Agents learn from experience
|
|
873
|
+
2. **Knowledge Sharing**: Cross-agent knowledge transfer
|
|
874
|
+
3. **Adaptive Workflows**: Self-optimizing execution
|
|
875
|
+
4. **Meta-Learning**: Transfer learning across domains
|
|
876
|
+
|
|
877
|
+
## Using DAA Tools
|
|
878
|
+
|
|
879
|
+
### Initialize DAA
|
|
880
|
+
\`\`\`javascript
|
|
881
|
+
mcp__ruv-swarm__daa_init {
|
|
882
|
+
enableLearning: true,
|
|
883
|
+
enableCoordination: true,
|
|
884
|
+
persistenceMode: "auto"
|
|
885
|
+
}
|
|
886
|
+
\`\`\`
|
|
887
|
+
|
|
888
|
+
### Create Autonomous Agent
|
|
889
|
+
\`\`\`javascript
|
|
890
|
+
mcp__ruv-swarm__daa_agent_create {
|
|
891
|
+
id: "auto-001",
|
|
892
|
+
capabilities: ["learning", "optimization"],
|
|
893
|
+
cognitivePattern: "adaptive",
|
|
894
|
+
learningRate: 0.001
|
|
895
|
+
}
|
|
896
|
+
\`\`\`
|
|
897
|
+
|
|
898
|
+
### Execute Workflow
|
|
899
|
+
\`\`\`javascript
|
|
900
|
+
mcp__ruv-swarm__daa_workflow_execute {
|
|
901
|
+
workflowId: "api-development",
|
|
902
|
+
agentIds: ["auto-001", "auto-002"],
|
|
903
|
+
parallelExecution: true
|
|
904
|
+
}
|
|
905
|
+
\`\`\`
|
|
906
|
+
|
|
907
|
+
## Best Practices
|
|
908
|
+
|
|
909
|
+
1. Start with low learning rates
|
|
910
|
+
2. Enable knowledge sharing for complex tasks
|
|
911
|
+
3. Monitor performance metrics regularly
|
|
912
|
+
4. Use meta-learning for cross-domain tasks`
|
|
913
|
+
}]
|
|
914
|
+
},
|
|
915
|
+
'swarm://examples/rest-api': {
|
|
916
|
+
contents: [{
|
|
917
|
+
uri,
|
|
918
|
+
mimeType: 'text/markdown',
|
|
919
|
+
text: `# REST API Example
|
|
920
|
+
|
|
921
|
+
## Building a Complete REST API with @sparkleideas/ruv-swarm
|
|
922
|
+
|
|
923
|
+
### Step 1: Initialize Swarm
|
|
924
|
+
\`\`\`javascript
|
|
925
|
+
[BatchTool]:
|
|
926
|
+
mcp__ruv-swarm__swarm_init { topology: "hierarchical", maxAgents: 6 }
|
|
927
|
+
mcp__ruv-swarm__agent_spawn { type: "architect", name: "API Designer" }
|
|
928
|
+
mcp__ruv-swarm__agent_spawn { type: "coder", name: "Backend Dev" }
|
|
929
|
+
mcp__ruv-swarm__agent_spawn { type: "analyst", name: "DB Expert" }
|
|
930
|
+
mcp__ruv-swarm__agent_spawn { type: "tester", name: "QA Engineer" }
|
|
931
|
+
mcp__ruv-swarm__agent_spawn { type: "coordinator", name: "Project Lead" }
|
|
932
|
+
\`\`\`
|
|
933
|
+
|
|
934
|
+
### Step 2: Design Architecture
|
|
935
|
+
\`\`\`javascript
|
|
936
|
+
TodoWrite { todos: [
|
|
937
|
+
{ id: "design", content: "Design API architecture", priority: "high" },
|
|
938
|
+
{ id: "auth", content: "Implement authentication", priority: "high" },
|
|
939
|
+
{ id: "crud", content: "Build CRUD endpoints", priority: "medium" },
|
|
940
|
+
{ id: "tests", content: "Write tests", priority: "medium" }
|
|
941
|
+
]}
|
|
942
|
+
\`\`\`
|
|
943
|
+
|
|
944
|
+
### Step 3: Implementation
|
|
945
|
+
\`\`\`javascript
|
|
946
|
+
[BatchTool]:
|
|
947
|
+
Bash "mkdir -p api/{src,tests,docs}"
|
|
948
|
+
Write "api/package.json" { ... }
|
|
949
|
+
Write "api/src/server.js" { ... }
|
|
950
|
+
Write "api/src/routes/auth.js" { ... }
|
|
951
|
+
\`\`\`
|
|
952
|
+
|
|
953
|
+
### Step 4: Testing
|
|
954
|
+
\`\`\`javascript
|
|
955
|
+
mcp__ruv-swarm__task_orchestrate {
|
|
956
|
+
task: "Run comprehensive tests",
|
|
957
|
+
strategy: "parallel"
|
|
958
|
+
}
|
|
959
|
+
\`\`\`
|
|
960
|
+
|
|
961
|
+
## Complete Working Example
|
|
962
|
+
|
|
963
|
+
See the full implementation in the @sparkleideas/ruv-swarm examples directory.`
|
|
964
|
+
}]
|
|
965
|
+
},
|
|
966
|
+
'swarm://examples/neural-training': {
|
|
967
|
+
contents: [{
|
|
968
|
+
uri,
|
|
969
|
+
mimeType: 'text/markdown',
|
|
970
|
+
text: `# Neural Training Example
|
|
971
|
+
|
|
972
|
+
## Training Neural Agents for Specific Tasks
|
|
973
|
+
|
|
974
|
+
### Step 1: Initialize Neural Network
|
|
975
|
+
\`\`\`javascript
|
|
976
|
+
mcp__ruv-swarm__neural_status { agentId: "coder-001" }
|
|
977
|
+
\`\`\`
|
|
978
|
+
|
|
979
|
+
### Step 2: Prepare Training Data
|
|
980
|
+
\`\`\`javascript
|
|
981
|
+
mcp__ruv-swarm__neural_train {
|
|
982
|
+
agentId: "coder-001",
|
|
983
|
+
iterations: 50
|
|
984
|
+
}
|
|
985
|
+
\`\`\`
|
|
986
|
+
|
|
987
|
+
### Step 3: Monitor Training Progress
|
|
988
|
+
\`\`\`javascript
|
|
989
|
+
mcp__ruv-swarm__swarm_monitor {
|
|
990
|
+
duration: 30,
|
|
991
|
+
interval: 1
|
|
992
|
+
}
|
|
993
|
+
\`\`\`
|
|
994
|
+
|
|
995
|
+
### Step 4: Analyze Patterns
|
|
996
|
+
\`\`\`javascript
|
|
997
|
+
mcp__ruv-swarm__neural_patterns {
|
|
998
|
+
pattern: "all"
|
|
999
|
+
}
|
|
1000
|
+
\`\`\`
|
|
1001
|
+
|
|
1002
|
+
## Training Tips
|
|
1003
|
+
|
|
1004
|
+
1. Start with small iteration counts
|
|
1005
|
+
2. Monitor performance metrics
|
|
1006
|
+
3. Adjust learning rates based on results
|
|
1007
|
+
4. Use cognitive patterns that match your task
|
|
1008
|
+
|
|
1009
|
+
## Advanced Training
|
|
1010
|
+
|
|
1011
|
+
For complex tasks, combine multiple cognitive patterns:
|
|
1012
|
+
- Convergent for focused problem-solving
|
|
1013
|
+
- Divergent for creative solutions
|
|
1014
|
+
- Systems for architectural decisions`
|
|
1015
|
+
}]
|
|
1016
|
+
},
|
|
1017
|
+
'swarm://schemas/swarm-config': {
|
|
1018
|
+
contents: [{
|
|
1019
|
+
uri,
|
|
1020
|
+
mimeType: 'application/json',
|
|
1021
|
+
text: JSON.stringify({
|
|
1022
|
+
"$schema": "http://json-schema.org/draft-07/schema#",
|
|
1023
|
+
"title": "Swarm Configuration",
|
|
1024
|
+
"type": "object",
|
|
1025
|
+
"properties": {
|
|
1026
|
+
"topology": {
|
|
1027
|
+
"type": "string",
|
|
1028
|
+
"enum": ["mesh", "hierarchical", "ring", "star"],
|
|
1029
|
+
"description": "Swarm topology type"
|
|
1030
|
+
},
|
|
1031
|
+
"maxAgents": {
|
|
1032
|
+
"type": "integer",
|
|
1033
|
+
"minimum": 1,
|
|
1034
|
+
"maximum": 100,
|
|
1035
|
+
"default": 5,
|
|
1036
|
+
"description": "Maximum number of agents"
|
|
1037
|
+
},
|
|
1038
|
+
"strategy": {
|
|
1039
|
+
"type": "string",
|
|
1040
|
+
"enum": ["balanced", "specialized", "adaptive"],
|
|
1041
|
+
"default": "balanced",
|
|
1042
|
+
"description": "Distribution strategy"
|
|
1043
|
+
},
|
|
1044
|
+
"enableNeuralNetworks": {
|
|
1045
|
+
"type": "boolean",
|
|
1046
|
+
"default": true,
|
|
1047
|
+
"description": "Enable neural network features"
|
|
1048
|
+
},
|
|
1049
|
+
"memoryPersistence": {
|
|
1050
|
+
"type": "boolean",
|
|
1051
|
+
"default": true,
|
|
1052
|
+
"description": "Enable persistent memory"
|
|
1053
|
+
}
|
|
1054
|
+
},
|
|
1055
|
+
"required": ["topology"]
|
|
1056
|
+
}, null, 2)
|
|
1057
|
+
}]
|
|
1058
|
+
},
|
|
1059
|
+
'swarm://schemas/agent-config': {
|
|
1060
|
+
contents: [{
|
|
1061
|
+
uri,
|
|
1062
|
+
mimeType: 'application/json',
|
|
1063
|
+
text: JSON.stringify({
|
|
1064
|
+
"$schema": "http://json-schema.org/draft-07/schema#",
|
|
1065
|
+
"title": "Agent Configuration",
|
|
1066
|
+
"type": "object",
|
|
1067
|
+
"properties": {
|
|
1068
|
+
"type": {
|
|
1069
|
+
"type": "string",
|
|
1070
|
+
"enum": ["researcher", "coder", "analyst", "optimizer", "coordinator", "architect", "tester"],
|
|
1071
|
+
"description": "Agent type"
|
|
1072
|
+
},
|
|
1073
|
+
"name": {
|
|
1074
|
+
"type": "string",
|
|
1075
|
+
"maxLength": 100,
|
|
1076
|
+
"description": "Custom agent name"
|
|
1077
|
+
},
|
|
1078
|
+
"capabilities": {
|
|
1079
|
+
"type": "array",
|
|
1080
|
+
"items": {
|
|
1081
|
+
"type": "string"
|
|
1082
|
+
},
|
|
1083
|
+
"description": "Agent capabilities"
|
|
1084
|
+
},
|
|
1085
|
+
"cognitivePattern": {
|
|
1086
|
+
"type": "string",
|
|
1087
|
+
"enum": ["convergent", "divergent", "lateral", "systems", "critical", "abstract"],
|
|
1088
|
+
"description": "Cognitive thinking pattern"
|
|
1089
|
+
},
|
|
1090
|
+
"learningRate": {
|
|
1091
|
+
"type": "number",
|
|
1092
|
+
"minimum": 0,
|
|
1093
|
+
"maximum": 1,
|
|
1094
|
+
"default": 0.001,
|
|
1095
|
+
"description": "Learning rate for neural network"
|
|
1096
|
+
}
|
|
1097
|
+
},
|
|
1098
|
+
"required": ["type"]
|
|
1099
|
+
}, null, 2)
|
|
1100
|
+
}]
|
|
1101
|
+
},
|
|
1102
|
+
'swarm://performance/benchmarks': {
|
|
1103
|
+
contents: [{
|
|
1104
|
+
uri,
|
|
1105
|
+
mimeType: 'application/json',
|
|
1106
|
+
text: JSON.stringify({
|
|
1107
|
+
"benchmarks": {
|
|
1108
|
+
"wasm_load_time": {
|
|
1109
|
+
"target": "200ms",
|
|
1110
|
+
"achieved": "98ms",
|
|
1111
|
+
"improvement": "51%"
|
|
1112
|
+
},
|
|
1113
|
+
"agent_spawn_time": {
|
|
1114
|
+
"target": "50ms",
|
|
1115
|
+
"achieved": "12ms",
|
|
1116
|
+
"improvement": "76%"
|
|
1117
|
+
},
|
|
1118
|
+
"memory_usage_10_agents": {
|
|
1119
|
+
"target": "50MB",
|
|
1120
|
+
"achieved": "18.5MB",
|
|
1121
|
+
"improvement": "63%"
|
|
1122
|
+
},
|
|
1123
|
+
"cross_boundary_latency": {
|
|
1124
|
+
"target": "0.5ms",
|
|
1125
|
+
"achieved": "0.15ms",
|
|
1126
|
+
"improvement": "70%"
|
|
1127
|
+
},
|
|
1128
|
+
"token_processing": {
|
|
1129
|
+
"target": "10K/sec",
|
|
1130
|
+
"achieved": "42.5K/sec",
|
|
1131
|
+
"improvement": "325%"
|
|
1132
|
+
}
|
|
1133
|
+
},
|
|
1134
|
+
"swe_bench_solve_rate": "84.8%",
|
|
1135
|
+
"token_reduction": "32.3%",
|
|
1136
|
+
"speed_improvement": "2.8-4.4x"
|
|
1137
|
+
}, null, 2)
|
|
1138
|
+
}]
|
|
1139
|
+
},
|
|
1140
|
+
'swarm://hooks/available': {
|
|
1141
|
+
contents: [{
|
|
1142
|
+
uri,
|
|
1143
|
+
mimeType: 'text/markdown',
|
|
1144
|
+
text: `# Available Claude Code Hooks
|
|
1145
|
+
|
|
1146
|
+
## Pre-Operation Hooks
|
|
1147
|
+
|
|
1148
|
+
### pre-task
|
|
1149
|
+
- **Purpose**: Initialize agent context before tasks
|
|
1150
|
+
- **Usage**: \`npx @sparkleideas/ruv-swarm hook pre-task --description "task"\`
|
|
1151
|
+
- **Features**: Auto-spawn agents, load context, optimize topology
|
|
1152
|
+
|
|
1153
|
+
### pre-edit
|
|
1154
|
+
- **Purpose**: Prepare for file edits
|
|
1155
|
+
- **Usage**: \`npx @sparkleideas/ruv-swarm hook pre-edit --file "path"\`
|
|
1156
|
+
- **Features**: Auto-assign agents, validate permissions
|
|
1157
|
+
|
|
1158
|
+
### pre-search
|
|
1159
|
+
- **Purpose**: Optimize search operations
|
|
1160
|
+
- **Usage**: \`npx @sparkleideas/ruv-swarm hook pre-search --query "search"\`
|
|
1161
|
+
- **Features**: Cache results, suggest alternatives
|
|
1162
|
+
|
|
1163
|
+
## Post-Operation Hooks
|
|
1164
|
+
|
|
1165
|
+
### post-edit
|
|
1166
|
+
- **Purpose**: Process file after editing
|
|
1167
|
+
- **Usage**: \`npx @sparkleideas/ruv-swarm hook post-edit --file "path"\`
|
|
1168
|
+
- **Features**: Auto-format, update memory, train neural patterns
|
|
1169
|
+
|
|
1170
|
+
### post-task
|
|
1171
|
+
- **Purpose**: Finalize task execution
|
|
1172
|
+
- **Usage**: \`npx @sparkleideas/ruv-swarm hook post-task --task-id "id"\`
|
|
1173
|
+
- **Features**: Analyze performance, update metrics
|
|
1174
|
+
|
|
1175
|
+
### notification
|
|
1176
|
+
- **Purpose**: Share updates across swarm
|
|
1177
|
+
- **Usage**: \`npx @sparkleideas/ruv-swarm hook notification --message "update"\`
|
|
1178
|
+
- **Features**: Broadcast to agents, update memory
|
|
1179
|
+
|
|
1180
|
+
## Session Hooks
|
|
1181
|
+
|
|
1182
|
+
### session-start
|
|
1183
|
+
- **Purpose**: Initialize session
|
|
1184
|
+
- **Usage**: \`npx @sparkleideas/ruv-swarm hook session-start\`
|
|
1185
|
+
- **Features**: Restore context, load memory
|
|
1186
|
+
|
|
1187
|
+
### session-end
|
|
1188
|
+
- **Purpose**: Clean up session
|
|
1189
|
+
- **Usage**: \`npx @sparkleideas/ruv-swarm hook session-end\`
|
|
1190
|
+
- **Features**: Save state, generate summary
|
|
1191
|
+
|
|
1192
|
+
### session-restore
|
|
1193
|
+
- **Purpose**: Restore previous session
|
|
1194
|
+
- **Usage**: \`npx @sparkleideas/ruv-swarm hook session-restore --session-id "id"\`
|
|
1195
|
+
- **Features**: Load memory, restore agent states`
|
|
1196
|
+
}]
|
|
1197
|
+
}
|
|
1198
|
+
};
|
|
1199
|
+
|
|
1200
|
+
const resource = resources[uri];
|
|
1201
|
+
if (!resource) {
|
|
1202
|
+
throw new Error(`Resource not found: ${uri}`);
|
|
1203
|
+
}
|
|
1204
|
+
|
|
1205
|
+
return resource;
|
|
1206
|
+
}
|
|
1207
|
+
|
|
1208
|
+
async function handleMcpRequest(request, mcpTools, logger = null) {
|
|
1209
|
+
const response = {
|
|
1210
|
+
jsonrpc: '2.0',
|
|
1211
|
+
id: request.id
|
|
1212
|
+
};
|
|
1213
|
+
|
|
1214
|
+
// Use default logger if not provided
|
|
1215
|
+
if (!logger) {
|
|
1216
|
+
logger = initializeLogger();
|
|
1217
|
+
}
|
|
1218
|
+
|
|
1219
|
+
try {
|
|
1220
|
+
logger.debug('Processing MCP request', {
|
|
1221
|
+
method: request.method,
|
|
1222
|
+
hasParams: !!request.params,
|
|
1223
|
+
requestId: request.id
|
|
1224
|
+
});
|
|
1225
|
+
|
|
1226
|
+
switch (request.method) {
|
|
1227
|
+
case 'initialize':
|
|
1228
|
+
response.result = {
|
|
1229
|
+
protocolVersion: '2024-11-05',
|
|
1230
|
+
capabilities: {
|
|
1231
|
+
tools: {},
|
|
1232
|
+
resources: {
|
|
1233
|
+
list: true,
|
|
1234
|
+
read: true
|
|
1235
|
+
}
|
|
1236
|
+
},
|
|
1237
|
+
serverInfo: {
|
|
1238
|
+
name: '@sparkleideas/ruv-swarm',
|
|
1239
|
+
version: '1.0.8'
|
|
1240
|
+
}
|
|
1241
|
+
};
|
|
1242
|
+
break;
|
|
1243
|
+
|
|
1244
|
+
case 'tools/list':
|
|
1245
|
+
response.result = {
|
|
1246
|
+
tools: [
|
|
1247
|
+
{
|
|
1248
|
+
name: 'swarm_init',
|
|
1249
|
+
description: 'Initialize a new swarm with specified topology',
|
|
1250
|
+
inputSchema: {
|
|
1251
|
+
type: 'object',
|
|
1252
|
+
properties: {
|
|
1253
|
+
topology: { type: 'string', enum: ['mesh', 'hierarchical', 'ring', 'star'], description: 'Swarm topology type' },
|
|
1254
|
+
maxAgents: { type: 'number', minimum: 1, maximum: 100, default: 5, description: 'Maximum number of agents' },
|
|
1255
|
+
strategy: { type: 'string', enum: ['balanced', 'specialized', 'adaptive'], default: 'balanced', description: 'Distribution strategy' }
|
|
1256
|
+
},
|
|
1257
|
+
required: ['topology']
|
|
1258
|
+
}
|
|
1259
|
+
},
|
|
1260
|
+
{
|
|
1261
|
+
name: 'swarm_status',
|
|
1262
|
+
description: 'Get current swarm status and agent information',
|
|
1263
|
+
inputSchema: {
|
|
1264
|
+
type: 'object',
|
|
1265
|
+
properties: {
|
|
1266
|
+
verbose: { type: 'boolean', default: false, description: 'Include detailed agent information' }
|
|
1267
|
+
}
|
|
1268
|
+
}
|
|
1269
|
+
},
|
|
1270
|
+
{
|
|
1271
|
+
name: 'swarm_monitor',
|
|
1272
|
+
description: 'Monitor swarm activity in real-time',
|
|
1273
|
+
inputSchema: {
|
|
1274
|
+
type: 'object',
|
|
1275
|
+
properties: {
|
|
1276
|
+
duration: { type: 'number', default: 10, description: 'Monitoring duration in seconds' },
|
|
1277
|
+
interval: { type: 'number', default: 1, description: 'Update interval in seconds' }
|
|
1278
|
+
}
|
|
1279
|
+
}
|
|
1280
|
+
},
|
|
1281
|
+
{
|
|
1282
|
+
name: 'agent_spawn',
|
|
1283
|
+
description: 'Spawn a new agent in the swarm',
|
|
1284
|
+
inputSchema: {
|
|
1285
|
+
type: 'object',
|
|
1286
|
+
properties: {
|
|
1287
|
+
type: { type: 'string', enum: ['researcher', 'coder', 'analyst', 'optimizer', 'coordinator'], description: 'Agent type' },
|
|
1288
|
+
name: { type: 'string', description: 'Custom agent name' },
|
|
1289
|
+
capabilities: { type: 'array', items: { type: 'string' }, description: 'Agent capabilities' }
|
|
1290
|
+
},
|
|
1291
|
+
required: ['type']
|
|
1292
|
+
}
|
|
1293
|
+
},
|
|
1294
|
+
{
|
|
1295
|
+
name: 'agent_list',
|
|
1296
|
+
description: 'List all active agents in the swarm',
|
|
1297
|
+
inputSchema: {
|
|
1298
|
+
type: 'object',
|
|
1299
|
+
properties: {
|
|
1300
|
+
filter: { type: 'string', enum: ['all', 'active', 'idle', 'busy'], default: 'all', description: 'Filter agents by status' }
|
|
1301
|
+
}
|
|
1302
|
+
}
|
|
1303
|
+
},
|
|
1304
|
+
{
|
|
1305
|
+
name: 'agent_metrics',
|
|
1306
|
+
description: 'Get performance metrics for agents',
|
|
1307
|
+
inputSchema: {
|
|
1308
|
+
type: 'object',
|
|
1309
|
+
properties: {
|
|
1310
|
+
agentId: { type: 'string', description: 'Specific agent ID (optional)' },
|
|
1311
|
+
metric: { type: 'string', enum: ['all', 'cpu', 'memory', 'tasks', 'performance'], default: 'all' }
|
|
1312
|
+
}
|
|
1313
|
+
}
|
|
1314
|
+
},
|
|
1315
|
+
{
|
|
1316
|
+
name: 'task_orchestrate',
|
|
1317
|
+
description: 'Orchestrate a task across the swarm',
|
|
1318
|
+
inputSchema: {
|
|
1319
|
+
type: 'object',
|
|
1320
|
+
properties: {
|
|
1321
|
+
task: { type: 'string', description: 'Task description or instructions' },
|
|
1322
|
+
strategy: { type: 'string', enum: ['parallel', 'sequential', 'adaptive'], default: 'adaptive', description: 'Execution strategy' },
|
|
1323
|
+
priority: { type: 'string', enum: ['low', 'medium', 'high', 'critical'], default: 'medium', description: 'Task priority' },
|
|
1324
|
+
maxAgents: { type: 'number', minimum: 1, maximum: 10, description: 'Maximum agents to use' }
|
|
1325
|
+
},
|
|
1326
|
+
required: ['task']
|
|
1327
|
+
}
|
|
1328
|
+
},
|
|
1329
|
+
{
|
|
1330
|
+
name: 'task_status',
|
|
1331
|
+
description: 'Check progress of running tasks',
|
|
1332
|
+
inputSchema: {
|
|
1333
|
+
type: 'object',
|
|
1334
|
+
properties: {
|
|
1335
|
+
taskId: { type: 'string', description: 'Specific task ID (optional)' },
|
|
1336
|
+
detailed: { type: 'boolean', default: false, description: 'Include detailed progress' }
|
|
1337
|
+
}
|
|
1338
|
+
}
|
|
1339
|
+
},
|
|
1340
|
+
{
|
|
1341
|
+
name: 'task_results',
|
|
1342
|
+
description: 'Retrieve results from completed tasks',
|
|
1343
|
+
inputSchema: {
|
|
1344
|
+
type: 'object',
|
|
1345
|
+
properties: {
|
|
1346
|
+
taskId: { type: 'string', description: 'Task ID to retrieve results for' },
|
|
1347
|
+
format: { type: 'string', enum: ['summary', 'detailed', 'raw'], default: 'summary', description: 'Result format' }
|
|
1348
|
+
},
|
|
1349
|
+
required: ['taskId']
|
|
1350
|
+
}
|
|
1351
|
+
},
|
|
1352
|
+
{
|
|
1353
|
+
name: 'benchmark_run',
|
|
1354
|
+
description: 'Execute performance benchmarks',
|
|
1355
|
+
inputSchema: {
|
|
1356
|
+
type: 'object',
|
|
1357
|
+
properties: {
|
|
1358
|
+
type: { type: 'string', enum: ['all', 'wasm', 'swarm', 'agent', 'task'], default: 'all', description: 'Benchmark type' },
|
|
1359
|
+
iterations: { type: 'number', minimum: 1, maximum: 100, default: 10, description: 'Number of iterations' }
|
|
1360
|
+
}
|
|
1361
|
+
}
|
|
1362
|
+
},
|
|
1363
|
+
{
|
|
1364
|
+
name: 'features_detect',
|
|
1365
|
+
description: 'Detect runtime features and capabilities',
|
|
1366
|
+
inputSchema: {
|
|
1367
|
+
type: 'object',
|
|
1368
|
+
properties: {
|
|
1369
|
+
category: { type: 'string', enum: ['all', 'wasm', 'simd', 'memory', 'platform'], default: 'all', description: 'Feature category' }
|
|
1370
|
+
}
|
|
1371
|
+
}
|
|
1372
|
+
},
|
|
1373
|
+
{
|
|
1374
|
+
name: 'memory_usage',
|
|
1375
|
+
description: 'Get current memory usage statistics',
|
|
1376
|
+
inputSchema: {
|
|
1377
|
+
type: 'object',
|
|
1378
|
+
properties: {
|
|
1379
|
+
detail: { type: 'string', enum: ['summary', 'detailed', 'by-agent'], default: 'summary', description: 'Detail level' }
|
|
1380
|
+
}
|
|
1381
|
+
}
|
|
1382
|
+
},
|
|
1383
|
+
{
|
|
1384
|
+
name: 'neural_status',
|
|
1385
|
+
description: 'Get neural agent status and performance metrics',
|
|
1386
|
+
inputSchema: {
|
|
1387
|
+
type: 'object',
|
|
1388
|
+
properties: {
|
|
1389
|
+
agentId: { type: 'string', description: 'Specific agent ID (optional)' }
|
|
1390
|
+
}
|
|
1391
|
+
}
|
|
1392
|
+
},
|
|
1393
|
+
{
|
|
1394
|
+
name: 'neural_train',
|
|
1395
|
+
description: 'Train neural agents with sample tasks',
|
|
1396
|
+
inputSchema: {
|
|
1397
|
+
type: 'object',
|
|
1398
|
+
properties: {
|
|
1399
|
+
agentId: { type: 'string', description: 'Specific agent ID to train (optional)' },
|
|
1400
|
+
iterations: { type: 'number', minimum: 1, maximum: 100, default: 10, description: 'Number of training iterations' }
|
|
1401
|
+
}
|
|
1402
|
+
}
|
|
1403
|
+
},
|
|
1404
|
+
{
|
|
1405
|
+
name: 'neural_patterns',
|
|
1406
|
+
description: 'Get cognitive pattern information',
|
|
1407
|
+
inputSchema: {
|
|
1408
|
+
type: 'object',
|
|
1409
|
+
properties: {
|
|
1410
|
+
pattern: { type: 'string', enum: ['all', 'convergent', 'divergent', 'lateral', 'systems', 'critical', 'abstract'], default: 'all', description: 'Cognitive pattern type' }
|
|
1411
|
+
}
|
|
1412
|
+
}
|
|
1413
|
+
},
|
|
1414
|
+
// Add DAA tools
|
|
1415
|
+
...daaMcpTools.getToolDefinitions()
|
|
1416
|
+
]
|
|
1417
|
+
};
|
|
1418
|
+
break;
|
|
1419
|
+
|
|
1420
|
+
case 'tools/call':
|
|
1421
|
+
const toolName = request.params.name;
|
|
1422
|
+
const toolArgs = request.params.arguments || {};
|
|
1423
|
+
|
|
1424
|
+
logger.info('Tool call requested', {
|
|
1425
|
+
tool: toolName,
|
|
1426
|
+
hasArgs: Object.keys(toolArgs).length > 0,
|
|
1427
|
+
requestId: request.id
|
|
1428
|
+
});
|
|
1429
|
+
|
|
1430
|
+
let result = null;
|
|
1431
|
+
let toolFound = false;
|
|
1432
|
+
const toolOpId = logger.startOperation(`tool-${toolName}`, {
|
|
1433
|
+
tool: toolName,
|
|
1434
|
+
requestId: request.id
|
|
1435
|
+
});
|
|
1436
|
+
|
|
1437
|
+
// Try regular MCP tools first (use mcpToolsEnhanced.tools)
|
|
1438
|
+
if (mcpToolsEnhanced.tools && typeof mcpToolsEnhanced.tools[toolName] === 'function') {
|
|
1439
|
+
try {
|
|
1440
|
+
logger.debug('Executing MCP tool', { tool: toolName, args: toolArgs });
|
|
1441
|
+
result = await mcpToolsEnhanced.tools[toolName](toolArgs);
|
|
1442
|
+
toolFound = true;
|
|
1443
|
+
logger.endOperation(toolOpId, true, { resultType: typeof result });
|
|
1444
|
+
} catch (error) {
|
|
1445
|
+
logger.endOperation(toolOpId, false, { error });
|
|
1446
|
+
logger.error('MCP tool execution failed', {
|
|
1447
|
+
tool: toolName,
|
|
1448
|
+
error,
|
|
1449
|
+
args: toolArgs
|
|
1450
|
+
});
|
|
1451
|
+
response.error = {
|
|
1452
|
+
code: -32603,
|
|
1453
|
+
message: `MCP tool error: ${error.message}`,
|
|
1454
|
+
data: { tool: toolName, error: error.message }
|
|
1455
|
+
};
|
|
1456
|
+
break;
|
|
1457
|
+
}
|
|
1458
|
+
}
|
|
1459
|
+
// Try DAA tools if not found in regular tools
|
|
1460
|
+
else if (typeof daaMcpTools[toolName] === 'function') {
|
|
1461
|
+
try {
|
|
1462
|
+
logger.debug('Executing DAA tool', { tool: toolName, args: toolArgs });
|
|
1463
|
+
result = await daaMcpTools[toolName](toolArgs);
|
|
1464
|
+
toolFound = true;
|
|
1465
|
+
logger.endOperation(toolOpId, true, { resultType: typeof result });
|
|
1466
|
+
} catch (error) {
|
|
1467
|
+
logger.endOperation(toolOpId, false, { error });
|
|
1468
|
+
logger.error('DAA tool execution failed', {
|
|
1469
|
+
tool: toolName,
|
|
1470
|
+
error,
|
|
1471
|
+
args: toolArgs
|
|
1472
|
+
});
|
|
1473
|
+
response.error = {
|
|
1474
|
+
code: -32603,
|
|
1475
|
+
message: `DAA tool error: ${error.message}`,
|
|
1476
|
+
data: { tool: toolName, error: error.message }
|
|
1477
|
+
};
|
|
1478
|
+
break;
|
|
1479
|
+
}
|
|
1480
|
+
}
|
|
1481
|
+
|
|
1482
|
+
if (toolFound) {
|
|
1483
|
+
// Format response with content array as required by Claude Code
|
|
1484
|
+
response.result = {
|
|
1485
|
+
content: [{
|
|
1486
|
+
type: 'text',
|
|
1487
|
+
text: typeof result === 'string' ? result : JSON.stringify(result, null, 2)
|
|
1488
|
+
}]
|
|
1489
|
+
};
|
|
1490
|
+
} else {
|
|
1491
|
+
response.error = {
|
|
1492
|
+
code: -32601,
|
|
1493
|
+
message: 'Method not found',
|
|
1494
|
+
data: `Unknown tool: ${toolName}`
|
|
1495
|
+
};
|
|
1496
|
+
}
|
|
1497
|
+
break;
|
|
1498
|
+
|
|
1499
|
+
case 'resources/list':
|
|
1500
|
+
response.result = {
|
|
1501
|
+
resources: [
|
|
1502
|
+
{
|
|
1503
|
+
uri: 'swarm://docs/getting-started',
|
|
1504
|
+
name: 'Getting Started Guide',
|
|
1505
|
+
description: 'Introduction to @sparkleideas/ruv-swarm and basic usage',
|
|
1506
|
+
mimeType: 'text/markdown'
|
|
1507
|
+
},
|
|
1508
|
+
{
|
|
1509
|
+
uri: 'swarm://docs/topologies',
|
|
1510
|
+
name: 'Swarm Topologies',
|
|
1511
|
+
description: 'Understanding mesh, hierarchical, ring, and star topologies',
|
|
1512
|
+
mimeType: 'text/markdown'
|
|
1513
|
+
},
|
|
1514
|
+
{
|
|
1515
|
+
uri: 'swarm://docs/agent-types',
|
|
1516
|
+
name: 'Agent Types Guide',
|
|
1517
|
+
description: 'Detailed guide on all agent types and their capabilities',
|
|
1518
|
+
mimeType: 'text/markdown'
|
|
1519
|
+
},
|
|
1520
|
+
{
|
|
1521
|
+
uri: 'swarm://docs/daa-guide',
|
|
1522
|
+
name: 'DAA Integration Guide',
|
|
1523
|
+
description: 'Using Decentralized Autonomous Agents effectively',
|
|
1524
|
+
mimeType: 'text/markdown'
|
|
1525
|
+
},
|
|
1526
|
+
{
|
|
1527
|
+
uri: 'swarm://examples/rest-api',
|
|
1528
|
+
name: 'REST API Example',
|
|
1529
|
+
description: 'Complete example of building a REST API with @sparkleideas/ruv-swarm',
|
|
1530
|
+
mimeType: 'text/markdown'
|
|
1531
|
+
},
|
|
1532
|
+
{
|
|
1533
|
+
uri: 'swarm://examples/neural-training',
|
|
1534
|
+
name: 'Neural Training Example',
|
|
1535
|
+
description: 'How to train neural agents for specific tasks',
|
|
1536
|
+
mimeType: 'text/markdown'
|
|
1537
|
+
},
|
|
1538
|
+
{
|
|
1539
|
+
uri: 'swarm://schemas/swarm-config',
|
|
1540
|
+
name: 'Swarm Configuration Schema',
|
|
1541
|
+
description: 'JSON schema for swarm configuration',
|
|
1542
|
+
mimeType: 'application/json'
|
|
1543
|
+
},
|
|
1544
|
+
{
|
|
1545
|
+
uri: 'swarm://schemas/agent-config',
|
|
1546
|
+
name: 'Agent Configuration Schema',
|
|
1547
|
+
description: 'JSON schema for agent configuration',
|
|
1548
|
+
mimeType: 'application/json'
|
|
1549
|
+
},
|
|
1550
|
+
{
|
|
1551
|
+
uri: 'swarm://performance/benchmarks',
|
|
1552
|
+
name: 'Performance Benchmarks',
|
|
1553
|
+
description: 'Latest performance benchmark results',
|
|
1554
|
+
mimeType: 'application/json'
|
|
1555
|
+
},
|
|
1556
|
+
{
|
|
1557
|
+
uri: 'swarm://hooks/available',
|
|
1558
|
+
name: 'Available Hooks',
|
|
1559
|
+
description: 'List of all available Claude Code hooks',
|
|
1560
|
+
mimeType: 'text/markdown'
|
|
1561
|
+
}
|
|
1562
|
+
]
|
|
1563
|
+
};
|
|
1564
|
+
break;
|
|
1565
|
+
|
|
1566
|
+
case 'resources/read':
|
|
1567
|
+
const resourceUri = request.params.uri;
|
|
1568
|
+
response.result = await getResourceContent(resourceUri);
|
|
1569
|
+
break;
|
|
1570
|
+
|
|
1571
|
+
default:
|
|
1572
|
+
response.error = {
|
|
1573
|
+
code: -32601,
|
|
1574
|
+
message: 'Method not found',
|
|
1575
|
+
data: `Unknown method: ${request.method}`
|
|
1576
|
+
};
|
|
1577
|
+
}
|
|
1578
|
+
} catch (error) {
|
|
1579
|
+
response.error = {
|
|
1580
|
+
code: -32603,
|
|
1581
|
+
message: 'Internal error',
|
|
1582
|
+
data: error.message
|
|
1583
|
+
};
|
|
1584
|
+
}
|
|
1585
|
+
|
|
1586
|
+
return response;
|
|
1587
|
+
}
|
|
1588
|
+
|
|
1589
|
+
async function handleHook(args) {
|
|
1590
|
+
// Hook handler for Claude Code integration
|
|
1591
|
+
const { main: hooksCLIMain } = await import('../src/hooks/cli.js');
|
|
1592
|
+
|
|
1593
|
+
// Pass through to hooks CLI with 'hook' already consumed
|
|
1594
|
+
process.argv = ['node', '@sparkleideas/ruv-swarm', 'hook', ...args];
|
|
1595
|
+
|
|
1596
|
+
return hooksCLIMain();
|
|
1597
|
+
}
|
|
1598
|
+
|
|
1599
|
+
async function handleNeural(args) {
|
|
1600
|
+
const { neuralCLI } = await import('../src/neural.js');
|
|
1601
|
+
const subcommand = args[0] || 'help';
|
|
1602
|
+
|
|
1603
|
+
try {
|
|
1604
|
+
switch (subcommand) {
|
|
1605
|
+
case 'status':
|
|
1606
|
+
return await neuralCLI.status(args.slice(1));
|
|
1607
|
+
case 'train':
|
|
1608
|
+
return await neuralCLI.train(args.slice(1));
|
|
1609
|
+
case 'patterns':
|
|
1610
|
+
return await neuralCLI.patterns(args.slice(1));
|
|
1611
|
+
case 'export':
|
|
1612
|
+
return await neuralCLI.export(args.slice(1));
|
|
1613
|
+
case 'help':
|
|
1614
|
+
default:
|
|
1615
|
+
console.log(`Neural Network Commands:
|
|
1616
|
+
neural status Show neural network status
|
|
1617
|
+
neural train [options] Train neural models
|
|
1618
|
+
neural patterns [model] View learned patterns
|
|
1619
|
+
neural export [options] Export neural weights
|
|
1620
|
+
|
|
1621
|
+
Examples:
|
|
1622
|
+
@sparkleideas/ruv-swarm neural status
|
|
1623
|
+
@sparkleideas/ruv-swarm neural train --model attention --iterations 100
|
|
1624
|
+
@sparkleideas/ruv-swarm neural patterns --model attention
|
|
1625
|
+
@sparkleideas/ruv-swarm neural export --model all --output ./weights.json`);
|
|
1626
|
+
break;
|
|
1627
|
+
}
|
|
1628
|
+
} catch (error) {
|
|
1629
|
+
console.error('❌ Neural command error:', error.message);
|
|
1630
|
+
process.exit(1);
|
|
1631
|
+
}
|
|
1632
|
+
}
|
|
1633
|
+
|
|
1634
|
+
async function handleBenchmark(args) {
|
|
1635
|
+
const { benchmarkCLI } = await import('../src/benchmark.js');
|
|
1636
|
+
const subcommand = args[0] || 'help';
|
|
1637
|
+
|
|
1638
|
+
try {
|
|
1639
|
+
switch (subcommand) {
|
|
1640
|
+
case 'run':
|
|
1641
|
+
return await benchmarkCLI.run(args.slice(1));
|
|
1642
|
+
case 'compare':
|
|
1643
|
+
return await benchmarkCLI.compare(args.slice(1));
|
|
1644
|
+
case 'help':
|
|
1645
|
+
default:
|
|
1646
|
+
console.log(`Benchmark Commands:
|
|
1647
|
+
benchmark run [options] Run performance benchmarks
|
|
1648
|
+
benchmark compare [files] Compare benchmark results
|
|
1649
|
+
|
|
1650
|
+
Examples:
|
|
1651
|
+
@sparkleideas/ruv-swarm benchmark run --iterations 10
|
|
1652
|
+
@sparkleideas/ruv-swarm benchmark run --test swarm-coordination
|
|
1653
|
+
@sparkleideas/ruv-swarm benchmark compare results-1.json results-2.json`);
|
|
1654
|
+
break;
|
|
1655
|
+
}
|
|
1656
|
+
} catch (error) {
|
|
1657
|
+
console.error('❌ Benchmark command error:', error.message);
|
|
1658
|
+
process.exit(1);
|
|
1659
|
+
}
|
|
1660
|
+
}
|
|
1661
|
+
|
|
1662
|
+
async function handlePerformance(args) {
|
|
1663
|
+
const { performanceCLI } = await import('../src/performance.js');
|
|
1664
|
+
const subcommand = args[0] || 'help';
|
|
1665
|
+
|
|
1666
|
+
try {
|
|
1667
|
+
switch (subcommand) {
|
|
1668
|
+
case 'analyze':
|
|
1669
|
+
return await performanceCLI.analyze(args.slice(1));
|
|
1670
|
+
case 'optimize':
|
|
1671
|
+
return await performanceCLI.optimize(args.slice(1));
|
|
1672
|
+
case 'suggest':
|
|
1673
|
+
return await performanceCLI.suggest(args.slice(1));
|
|
1674
|
+
case 'help':
|
|
1675
|
+
default:
|
|
1676
|
+
console.log(`Performance Commands:
|
|
1677
|
+
performance analyze [options] Analyze performance bottlenecks
|
|
1678
|
+
performance optimize [target] Optimize swarm configuration
|
|
1679
|
+
performance suggest Get optimization suggestions
|
|
1680
|
+
|
|
1681
|
+
Examples:
|
|
1682
|
+
@sparkleideas/ruv-swarm performance analyze --task-id recent
|
|
1683
|
+
@sparkleideas/ruv-swarm performance optimize --target speed
|
|
1684
|
+
@sparkleideas/ruv-swarm performance suggest`);
|
|
1685
|
+
break;
|
|
1686
|
+
}
|
|
1687
|
+
} catch (error) {
|
|
1688
|
+
console.error('❌ Performance command error:', error.message);
|
|
1689
|
+
process.exit(1);
|
|
1690
|
+
}
|
|
1691
|
+
}
|
|
1692
|
+
|
|
1693
|
+
async function handleDiagnose(args) {
|
|
1694
|
+
const { diagnosticsCLI } = await import('../src/cli-diagnostics.js');
|
|
1695
|
+
return diagnosticsCLI(args);
|
|
1696
|
+
}
|
|
1697
|
+
|
|
1698
|
+
function showHelp() {
|
|
1699
|
+
console.log(`
|
|
1700
|
+
🐝 @sparkleideas/ruv-swarm - Enhanced WASM-powered neural swarm orchestration
|
|
1701
|
+
|
|
1702
|
+
Usage: @sparkleideas/ruv-swarm <command> [options]
|
|
1703
|
+
|
|
1704
|
+
Commands:
|
|
1705
|
+
init [topology] [maxAgents] Initialize swarm (--claude for integration)
|
|
1706
|
+
Options for --claude:
|
|
1707
|
+
--force Overwrite existing CLAUDE.md (creates backup)
|
|
1708
|
+
--merge Merge with existing CLAUDE.md content
|
|
1709
|
+
--no-backup Disable automatic backup creation
|
|
1710
|
+
--no-interactive Skip interactive prompts (fail on conflicts)
|
|
1711
|
+
spawn <type> [name] Spawn an agent (researcher, coder, analyst, etc.)
|
|
1712
|
+
orchestrate <task> Orchestrate a task across agents
|
|
1713
|
+
status [--verbose] Show swarm status
|
|
1714
|
+
monitor [duration] Monitor swarm activity
|
|
1715
|
+
mcp <subcommand> MCP server management
|
|
1716
|
+
hook <type> [options] Claude Code hooks integration
|
|
1717
|
+
claude-invoke <prompt> Invoke Claude with swarm integration
|
|
1718
|
+
neural <subcommand> Neural network training and analysis
|
|
1719
|
+
benchmark <subcommand> Performance benchmarking tools
|
|
1720
|
+
performance <subcommand> Performance analysis and optimization
|
|
1721
|
+
diagnose <subcommand> Run diagnostics and analyze logs
|
|
1722
|
+
version Show version information
|
|
1723
|
+
help Show this help message
|
|
1724
|
+
|
|
1725
|
+
Examples:
|
|
1726
|
+
@sparkleideas/ruv-swarm init mesh 5 --claude # Create CLAUDE.md (fails if exists)
|
|
1727
|
+
@sparkleideas/ruv-swarm init mesh 5 --claude --force # Overwrite CLAUDE.md (creates backup)
|
|
1728
|
+
@sparkleideas/ruv-swarm init mesh 5 --claude --merge # Merge with existing CLAUDE.md
|
|
1729
|
+
@sparkleideas/ruv-swarm init mesh 5 --claude --force --no-backup # Overwrite CLAUDE.md (no backup)
|
|
1730
|
+
@sparkleideas/ruv-swarm init mesh 5 --claude --no-interactive # Non-interactive mode
|
|
1731
|
+
@sparkleideas/ruv-swarm spawn researcher "AI Research Specialist"
|
|
1732
|
+
@sparkleideas/ruv-swarm orchestrate "Build a REST API with authentication"
|
|
1733
|
+
@sparkleideas/ruv-swarm mcp start
|
|
1734
|
+
@sparkleideas/ruv-swarm hook pre-edit --file app.js --ensure-coordination
|
|
1735
|
+
@sparkleideas/ruv-swarm claude-invoke "Create a development swarm for my project"
|
|
1736
|
+
@sparkleideas/ruv-swarm neural status
|
|
1737
|
+
@sparkleideas/ruv-swarm benchmark run --iterations 10
|
|
1738
|
+
@sparkleideas/ruv-swarm performance analyze --task-id recent
|
|
1739
|
+
|
|
1740
|
+
Validation Rules:
|
|
1741
|
+
Topologies: mesh, hierarchical, ring, star
|
|
1742
|
+
Max Agents: 1-100 (integers only)
|
|
1743
|
+
Agent Types: researcher, coder, analyst, optimizer, coordinator, architect, tester
|
|
1744
|
+
Agent Names: 1-100 characters, alphanumeric + spaces/hyphens/underscores/periods
|
|
1745
|
+
Task Descriptions: 1-1000 characters, non-empty
|
|
1746
|
+
|
|
1747
|
+
Modular Features:
|
|
1748
|
+
📚 Automatic documentation generation
|
|
1749
|
+
🌐 Cross-platform remote execution support
|
|
1750
|
+
🤖 Seamless Claude Code MCP integration
|
|
1751
|
+
🔧 Advanced hooks for automation
|
|
1752
|
+
🧠 Neural pattern learning
|
|
1753
|
+
💾 Cross-session memory persistence
|
|
1754
|
+
|
|
1755
|
+
For detailed documentation, check .claude/commands/ after running init --claude
|
|
1756
|
+
`);
|
|
1757
|
+
}
|
|
1758
|
+
|
|
1759
|
+
async function main() {
|
|
1760
|
+
const args = process.argv.slice(2);
|
|
1761
|
+
|
|
1762
|
+
// Handle --version flag
|
|
1763
|
+
if (args.includes('--version') || args.includes('-v')) {
|
|
1764
|
+
try {
|
|
1765
|
+
const fs = await import('fs');
|
|
1766
|
+
const path = await import('path');
|
|
1767
|
+
const { fileURLToPath } = await import('url');
|
|
1768
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
1769
|
+
const __dirname = path.dirname(__filename);
|
|
1770
|
+
const packagePath = path.join(__dirname, '..', 'package.json');
|
|
1771
|
+
const packageJson = JSON.parse(fs.readFileSync(packagePath, 'utf8'));
|
|
1772
|
+
console.log(packageJson.version);
|
|
1773
|
+
} catch (error) {
|
|
1774
|
+
console.log('1.0.8');
|
|
1775
|
+
}
|
|
1776
|
+
return;
|
|
1777
|
+
}
|
|
1778
|
+
|
|
1779
|
+
const command = args[0] || 'help';
|
|
1780
|
+
|
|
1781
|
+
try {
|
|
1782
|
+
switch (command) {
|
|
1783
|
+
case 'init':
|
|
1784
|
+
await handleInit(args.slice(1));
|
|
1785
|
+
break;
|
|
1786
|
+
case 'spawn':
|
|
1787
|
+
await handleSpawn(args.slice(1));
|
|
1788
|
+
break;
|
|
1789
|
+
case 'orchestrate':
|
|
1790
|
+
await handleOrchestrate(args.slice(1));
|
|
1791
|
+
break;
|
|
1792
|
+
case 'mcp':
|
|
1793
|
+
await handleMcp(args.slice(1));
|
|
1794
|
+
break;
|
|
1795
|
+
case 'status':
|
|
1796
|
+
await handleStatus(args.slice(1));
|
|
1797
|
+
break;
|
|
1798
|
+
case 'monitor':
|
|
1799
|
+
await handleMonitor(args.slice(1));
|
|
1800
|
+
break;
|
|
1801
|
+
case 'hook':
|
|
1802
|
+
await handleHook(args.slice(1));
|
|
1803
|
+
break;
|
|
1804
|
+
case 'claude-invoke':
|
|
1805
|
+
case 'claude':
|
|
1806
|
+
await handleClaudeInvoke(args.slice(1));
|
|
1807
|
+
break;
|
|
1808
|
+
case 'neural':
|
|
1809
|
+
await handleNeural(args.slice(1));
|
|
1810
|
+
break;
|
|
1811
|
+
case 'benchmark':
|
|
1812
|
+
await handleBenchmark(args.slice(1));
|
|
1813
|
+
break;
|
|
1814
|
+
case 'performance':
|
|
1815
|
+
await handlePerformance(args.slice(1));
|
|
1816
|
+
break;
|
|
1817
|
+
case 'diagnose':
|
|
1818
|
+
await handleDiagnose(args.slice(1));
|
|
1819
|
+
break;
|
|
1820
|
+
case 'version':
|
|
1821
|
+
try {
|
|
1822
|
+
// Try to read version from package.json
|
|
1823
|
+
const fs = await import('fs');
|
|
1824
|
+
const path = await import('path');
|
|
1825
|
+
const { fileURLToPath } = await import('url');
|
|
1826
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
1827
|
+
const __dirname = path.dirname(__filename);
|
|
1828
|
+
const packagePath = path.join(__dirname, '..', 'package.json');
|
|
1829
|
+
const packageJson = JSON.parse(fs.readFileSync(packagePath, 'utf8'));
|
|
1830
|
+
console.log('@sparkleideas/ruv-swarm v' + packageJson.version);
|
|
1831
|
+
} catch (error) {
|
|
1832
|
+
console.log('@sparkleideas/ruv-swarm v1.0.8');
|
|
1833
|
+
}
|
|
1834
|
+
console.log('Enhanced WASM-powered neural swarm orchestration');
|
|
1835
|
+
console.log('Modular Claude Code integration with remote execution support');
|
|
1836
|
+
console.log('DAA (Decentralized Autonomous Agents) Integration');
|
|
1837
|
+
break;
|
|
1838
|
+
case 'help':
|
|
1839
|
+
default:
|
|
1840
|
+
showHelp();
|
|
1841
|
+
break;
|
|
1842
|
+
}
|
|
1843
|
+
} catch (error) {
|
|
1844
|
+
console.error('❌ Error:', error.message);
|
|
1845
|
+
if (process.argv.includes('--debug')) {
|
|
1846
|
+
console.error(error.stack);
|
|
1847
|
+
}
|
|
1848
|
+
process.exit(1);
|
|
1849
|
+
}
|
|
1850
|
+
}
|
|
1851
|
+
|
|
1852
|
+
// Error handling
|
|
1853
|
+
process.on('uncaughtException', (error) => {
|
|
1854
|
+
console.error('❌ Uncaught Exception:', error.message);
|
|
1855
|
+
if (process.argv.includes('--debug')) {
|
|
1856
|
+
console.error(error.stack);
|
|
1857
|
+
}
|
|
1858
|
+
process.exit(1);
|
|
1859
|
+
});
|
|
1860
|
+
|
|
1861
|
+
process.on('unhandledRejection', (reason, promise) => {
|
|
1862
|
+
console.error('❌ Unhandled Rejection:', reason);
|
|
1863
|
+
if (process.argv.includes('--debug')) {
|
|
1864
|
+
console.error('Promise:', promise);
|
|
1865
|
+
}
|
|
1866
|
+
process.exit(1);
|
|
1867
|
+
});
|
|
1868
|
+
|
|
1869
|
+
// In ES modules, this file is always the main module when run directly
|
|
1870
|
+
main();
|
|
1871
|
+
|
|
1872
|
+
export { main, initializeSystem };
|