@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.
Files changed (87) hide show
  1. package/README.md +1565 -0
  2. package/bin/ruv-swarm-clean.js +1872 -0
  3. package/bin/ruv-swarm-memory.js +119 -0
  4. package/bin/ruv-swarm-secure-heartbeat.js +1549 -0
  5. package/bin/ruv-swarm-secure.js +1689 -0
  6. package/package.json +221 -0
  7. package/src/agent.ts +342 -0
  8. package/src/benchmark.js +267 -0
  9. package/src/claude-flow-enhanced.js +839 -0
  10. package/src/claude-integration/advanced-commands.js +561 -0
  11. package/src/claude-integration/core.js +112 -0
  12. package/src/claude-integration/docs.js +1548 -0
  13. package/src/claude-integration/env-template.js +39 -0
  14. package/src/claude-integration/index.js +209 -0
  15. package/src/claude-integration/remote.js +408 -0
  16. package/src/cli-diagnostics.js +364 -0
  17. package/src/cognitive-pattern-evolution.js +1317 -0
  18. package/src/daa-cognition.js +977 -0
  19. package/src/daa-service.d.ts +298 -0
  20. package/src/daa-service.js +1116 -0
  21. package/src/diagnostics.js +533 -0
  22. package/src/errors.js +528 -0
  23. package/src/github-coordinator/README.md +193 -0
  24. package/src/github-coordinator/claude-hooks.js +162 -0
  25. package/src/github-coordinator/gh-cli-coordinator.js +260 -0
  26. package/src/hooks/cli.js +82 -0
  27. package/src/hooks/index.js +1900 -0
  28. package/src/index-enhanced.d.ts +371 -0
  29. package/src/index-enhanced.js +734 -0
  30. package/src/index.d.ts +287 -0
  31. package/src/index.js +405 -0
  32. package/src/index.ts +457 -0
  33. package/src/logger.js +182 -0
  34. package/src/logging-config.js +179 -0
  35. package/src/mcp-daa-tools.js +735 -0
  36. package/src/mcp-tools-benchmarks.js +328 -0
  37. package/src/mcp-tools-enhanced.js +2863 -0
  38. package/src/memory-config.js +42 -0
  39. package/src/meta-learning-framework.js +1359 -0
  40. package/src/neural-agent.js +830 -0
  41. package/src/neural-coordination-protocol.js +1363 -0
  42. package/src/neural-models/README.md +118 -0
  43. package/src/neural-models/autoencoder.js +543 -0
  44. package/src/neural-models/base.js +269 -0
  45. package/src/neural-models/cnn.js +497 -0
  46. package/src/neural-models/gnn.js +447 -0
  47. package/src/neural-models/gru.js +536 -0
  48. package/src/neural-models/index.js +273 -0
  49. package/src/neural-models/lstm.js +551 -0
  50. package/src/neural-models/neural-presets-complete.js +1306 -0
  51. package/src/neural-models/presets/graph.js +392 -0
  52. package/src/neural-models/presets/index.js +279 -0
  53. package/src/neural-models/presets/nlp.js +328 -0
  54. package/src/neural-models/presets/timeseries.js +368 -0
  55. package/src/neural-models/presets/vision.js +387 -0
  56. package/src/neural-models/resnet.js +534 -0
  57. package/src/neural-models/transformer.js +515 -0
  58. package/src/neural-models/vae.js +489 -0
  59. package/src/neural-network-manager.js +1938 -0
  60. package/src/neural-network.ts +296 -0
  61. package/src/neural.js +574 -0
  62. package/src/performance-benchmarks.js +898 -0
  63. package/src/performance.js +458 -0
  64. package/src/persistence-pooled.js +695 -0
  65. package/src/persistence.js +480 -0
  66. package/src/schemas.js +864 -0
  67. package/src/security.js +218 -0
  68. package/src/singleton-container.js +183 -0
  69. package/src/sqlite-pool.js +587 -0
  70. package/src/sqlite-worker.js +141 -0
  71. package/src/types.ts +164 -0
  72. package/src/utils.ts +286 -0
  73. package/src/wasm-loader.js +601 -0
  74. package/src/wasm-loader2.js +404 -0
  75. package/src/wasm-memory-optimizer.js +783 -0
  76. package/src/wasm-types.d.ts +63 -0
  77. package/wasm/README.md +347 -0
  78. package/wasm/neuro-divergent.wasm +0 -0
  79. package/wasm/package.json +18 -0
  80. package/wasm/ruv-fann.wasm +0 -0
  81. package/wasm/ruv_swarm_simd.wasm +0 -0
  82. package/wasm/ruv_swarm_wasm.d.ts +391 -0
  83. package/wasm/ruv_swarm_wasm.js +2164 -0
  84. package/wasm/ruv_swarm_wasm_bg.wasm +0 -0
  85. package/wasm/ruv_swarm_wasm_bg.wasm.d.ts +123 -0
  86. package/wasm/wasm-bindings-loader.mjs +435 -0
  87. package/wasm/wasm-updates.md +684 -0
@@ -0,0 +1,328 @@
1
+ /**
2
+ * MCP Tools Benchmarks - Separated for better organization
3
+ * Contains all benchmark and testing functionality for @sparkleideas/ruv-swarm MCP tools
4
+ */
5
+
6
+ /**
7
+ * Benchmark utilities and test functions for MCP tools
8
+ */
9
+ export class MCPBenchmarks {
10
+ constructor(ruvSwarm, persistence) {
11
+ this.ruvSwarm = ruvSwarm;
12
+ this.persistence = persistence;
13
+ }
14
+
15
+ /**
16
+ * Run specialized benchmarks - only real tests, no fake/dummy ones
17
+ */
18
+ async runBenchmarks(type = 'all', iterations = 10) {
19
+ console.log(`MCPBenchmarks.runBenchmarks called with type='${type}', iterations=${iterations}`);
20
+ const benchmarks = {};
21
+
22
+ // Only include real memory benchmarks - no fake setTimeout tests
23
+ if (type === 'all' || type === 'memory') {
24
+ try {
25
+ console.log('🔍 ENTERING MEMORY BENCHMARK SECTION');
26
+ console.log('Running enhanced memory benchmarks...');
27
+ benchmarks.memory = await this.runEnhancedMemoryBenchmarks(iterations);
28
+ console.log('Memory benchmarks completed:', benchmarks.memory);
29
+ } catch (error) {
30
+ console.error('Memory benchmark error:', error);
31
+ benchmarks.memory = { error: error.message };
32
+ }
33
+ }
34
+
35
+ // Performance profiling benchmarks - real CPU/memory intensive tests
36
+ if (type === 'all' || type === 'profiling') {
37
+ try {
38
+ console.log('Running performance profiling benchmarks...');
39
+ benchmarks.profiling = await this.runPerformanceProfilingBenchmarks(iterations);
40
+ } catch (error) {
41
+ console.error('Profiling benchmark error:', error);
42
+ benchmarks.profiling = { error: error.message };
43
+ }
44
+ }
45
+
46
+ console.log('Final benchmarks object keys:', Object.keys(benchmarks));
47
+
48
+ const result = {
49
+ benchmark_type: type,
50
+ iterations,
51
+ results: benchmarks,
52
+ environment: {
53
+ features: this.ruvSwarm?.features || {},
54
+ memory_usage_mb: this.ruvSwarm?.wasmLoader?.getTotalMemoryUsage() / (1024 * 1024) || 0,
55
+ runtime_features: this.ruvSwarm?.getRuntimeFeatures ? this.ruvSwarm.getRuntimeFeatures() : {},
56
+ },
57
+ timestamp: new Date().toISOString(),
58
+ };
59
+
60
+ return result;
61
+ }
62
+
63
+ /**
64
+ * Enhanced Memory-specific benchmarks - REAL TESTS ONLY
65
+ */
66
+ async runEnhancedMemoryBenchmarks(iterations) {
67
+ console.log(`Starting runMemoryBenchmarks with ${iterations} iterations`);
68
+ const benchmarks = {
69
+ memory_allocation: [],
70
+ memory_access: [],
71
+ memory_cleanup: [],
72
+ cache_performance: [],
73
+ garbage_collection: [],
74
+ };
75
+
76
+ for (let i = 0; i < iterations; i++) {
77
+ try {
78
+ // Memory allocation benchmark - more substantial work
79
+ let start = performance.now();
80
+ const allocSize = Math.floor(Math.random() * 10000 + 5000); // 5000-15000 items
81
+ const allocation = new Array(allocSize).fill(0).map((_, idx) => ({
82
+ id: idx,
83
+ data: Math.random(),
84
+ timestamp: Date.now(),
85
+ metadata: `item_${idx}_${Math.random()}`,
86
+ }));
87
+ benchmarks.memory_allocation.push(performance.now() - start);
88
+
89
+ // Memory access benchmark - more operations
90
+ start = performance.now();
91
+ const accessCount = Math.min(1000, allocation.length);
92
+ let sum = 0;
93
+ for (let j = 0; j < accessCount; j++) {
94
+ const randomIndex = Math.floor(Math.random() * allocation.length);
95
+ sum += allocation[randomIndex].data;
96
+ }
97
+ benchmarks.memory_access.push(performance.now() - start);
98
+
99
+ // Cache performance benchmark - more substantial cache operations
100
+ start = performance.now();
101
+ const cacheData = new Map();
102
+ for (let k = 0; k < 1000; k++) {
103
+ cacheData.set(`key_${k}`, { value: Math.random(), index: k });
104
+ }
105
+ // Perform cache lookups
106
+ for (let k = 0; k < 500; k++) {
107
+ const key = `key_${Math.floor(Math.random() * 1000)}`;
108
+ const _ = cacheData.get(key);
109
+ }
110
+ benchmarks.cache_performance.push(performance.now() - start);
111
+
112
+ // Garbage collection simulation benchmark - larger objects
113
+ start = performance.now();
114
+ let tempArrays = [];
115
+ for (let l = 0; l < 100; l++) {
116
+ tempArrays.push(new Array(1000).fill(0).map(x => Math.random()));
117
+ }
118
+ // Force some operations on the arrays
119
+ let total = 0;
120
+ tempArrays.forEach(arr => {
121
+ total += arr.length;
122
+ });
123
+ tempArrays = null; // Release for GC
124
+ benchmarks.garbage_collection.push(performance.now() - start);
125
+
126
+ // Memory cleanup benchmark - more cleanup work
127
+ start = performance.now();
128
+ allocation.splice(0, allocation.length); // More thorough cleanup
129
+ benchmarks.memory_cleanup.push(performance.now() - start);
130
+
131
+ } catch (error) {
132
+ console.warn('Memory benchmark iteration failed:', error.message);
133
+ // Add default values on error to ensure we have data
134
+ benchmarks.memory_allocation.push(0);
135
+ benchmarks.memory_access.push(0);
136
+ benchmarks.cache_performance.push(0);
137
+ benchmarks.garbage_collection.push(0);
138
+ benchmarks.memory_cleanup.push(0);
139
+ }
140
+ }
141
+
142
+ return this.calculateBenchmarkStats(benchmarks);
143
+ }
144
+
145
+ /**
146
+ * Performance profiling benchmarks - CPU intensive real tests
147
+ */
148
+ async runPerformanceProfilingBenchmarks(iterations) {
149
+ console.log(`Starting performance profiling benchmarks with ${iterations} iterations`);
150
+ const benchmarks = {
151
+ cpu_intensive_computation: [],
152
+ string_processing: [],
153
+ json_operations: [],
154
+ array_operations: [],
155
+ math_operations: [],
156
+ };
157
+
158
+ for (let i = 0; i < iterations; i++) {
159
+ try {
160
+ // CPU intensive computation benchmark
161
+ let start = performance.now();
162
+ let result = 0;
163
+ for (let j = 0; j < 100000; j++) {
164
+ result += Math.sqrt(j) * Math.sin(j / 1000) * Math.cos(j / 1000);
165
+ }
166
+ benchmarks.cpu_intensive_computation.push(performance.now() - start);
167
+
168
+ // String processing benchmark
169
+ start = performance.now();
170
+ let text = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. '.repeat(1000);
171
+ for (let k = 0; k < 100; k++) {
172
+ text = text.replace(/Lorem/g, 'Replaced').split(' ').reverse().join(' ');
173
+ }
174
+ benchmarks.string_processing.push(performance.now() - start);
175
+
176
+ // JSON operations benchmark
177
+ start = performance.now();
178
+ const largeObject = {
179
+ data: Array.from({ length: 1000 }, (_, idx) => ({
180
+ id: idx,
181
+ name: `Item ${idx}`,
182
+ values: Array.from({ length: 100 }, () => Math.random()),
183
+ metadata: {
184
+ created: new Date(),
185
+ processed: false,
186
+ tags: [`tag${idx % 10}`, `category${idx % 5}`],
187
+ },
188
+ })),
189
+ };
190
+ for (let l = 0; l < 50; l++) {
191
+ const serialized = JSON.stringify(largeObject);
192
+ const parsed = JSON.parse(serialized);
193
+ }
194
+ benchmarks.json_operations.push(performance.now() - start);
195
+
196
+ // Array operations benchmark
197
+ start = performance.now();
198
+ const largeArray = Array.from({ length: 10000 }, () => Math.random());
199
+ largeArray.sort();
200
+ const filtered = largeArray.filter(x => x > 0.5);
201
+ const mapped = filtered.map(x => x * 2);
202
+ const reduced = mapped.reduce((sum, x) => sum + x, 0);
203
+ benchmarks.array_operations.push(performance.now() - start);
204
+
205
+ // Math operations benchmark
206
+ start = performance.now();
207
+ const matrix1 = Array.from({ length: 100 }, () => Array.from({ length: 100 }, () => Math.random()));
208
+ const matrix2 = Array.from({ length: 100 }, () => Array.from({ length: 100 }, () => Math.random()));
209
+ // Simple matrix multiplication
210
+ const resultMatrix = matrix1.map((row, i) =>
211
+ row.map((_, j) =>
212
+ matrix1[i].reduce((sum, cell, k) => sum + cell * matrix2[k][j], 0),
213
+ ),
214
+ );
215
+ benchmarks.math_operations.push(performance.now() - start);
216
+
217
+ } catch (error) {
218
+ console.warn('Performance profiling benchmark iteration failed:', error.message);
219
+ benchmarks.cpu_intensive_computation.push(0);
220
+ benchmarks.string_processing.push(0);
221
+ benchmarks.json_operations.push(0);
222
+ benchmarks.array_operations.push(0);
223
+ benchmarks.math_operations.push(0);
224
+ }
225
+ }
226
+
227
+ return this.calculateBenchmarkStats(benchmarks);
228
+ }
229
+
230
+ /**
231
+ * Calculate statistics for benchmark results
232
+ */
233
+ calculateBenchmarkStats(benchmarks) {
234
+ const results = {};
235
+
236
+ Object.keys(benchmarks).forEach(benchmarkType => {
237
+ const times = benchmarks[benchmarkType];
238
+ if (times.length > 0) {
239
+ const sorted = times.sort((a, b) => a - b);
240
+ results[benchmarkType] = {
241
+ avg_ms: times.reduce((sum, time) => sum + time, 0) / times.length,
242
+ min_ms: Math.min(...times),
243
+ max_ms: Math.max(...times),
244
+ median_ms: sorted[Math.floor(sorted.length / 2)],
245
+ p95_ms: sorted[Math.floor(sorted.length * 0.95)],
246
+ samples: times.length,
247
+ std_dev: this.calculateStandardDeviation(times),
248
+ };
249
+ }
250
+ });
251
+
252
+ return results;
253
+ }
254
+
255
+ /**
256
+ * Calculate standard deviation
257
+ */
258
+ calculateStandardDeviation(values) {
259
+ const avg = values.reduce((sum, val) => sum + val, 0) / values.length;
260
+ const squaredDiffs = values.map(val => Math.pow(val - avg, 2));
261
+ const avgSquaredDiff = squaredDiffs.reduce((sum, val) => sum + val, 0) / values.length;
262
+ return Math.sqrt(avgSquaredDiff);
263
+ }
264
+
265
+ /**
266
+ * Format benchmark results for display
267
+ */
268
+ formatBenchmarkResults(benchmarks) {
269
+ const summary = [];
270
+
271
+ // Process WASM benchmarks
272
+ if (benchmarks.wasm) {
273
+ Object.keys(benchmarks.wasm).forEach(benchmarkType => {
274
+ const data = benchmarks.wasm[benchmarkType];
275
+ summary.push({
276
+ category: 'WASM',
277
+ name: benchmarkType.replace(/_/g, ' ').replace(/\b\w/g, l => l.toUpperCase()),
278
+ avgTime: `${data.avg_ms?.toFixed(2) }ms` || '0.00ms',
279
+ minTime: `${data.min_ms?.toFixed(2) }ms` || '0.00ms',
280
+ maxTime: `${data.max_ms?.toFixed(2) }ms` || '0.00ms',
281
+ samples: data.samples || 0,
282
+ });
283
+ });
284
+ }
285
+
286
+ // Process Neural Network benchmarks
287
+ if (benchmarks.neural) {
288
+ Object.keys(benchmarks.neural).forEach(benchmarkType => {
289
+ const data = benchmarks.neural[benchmarkType];
290
+ summary.push({
291
+ category: 'Neural Network',
292
+ name: benchmarkType.replace(/_/g, ' ').replace(/\b\w/g, l => l.toUpperCase()),
293
+ avgTime: `${data.avg_ms?.toFixed(2) }ms` || '0.00ms',
294
+ minTime: `${data.min_ms?.toFixed(2) }ms` || '0.00ms',
295
+ maxTime: `${data.max_ms?.toFixed(2) }ms` || '0.00ms',
296
+ medianTime: `${data.median_ms?.toFixed(2) }ms` || '0.00ms',
297
+ samples: data.samples || 0,
298
+ });
299
+ });
300
+ }
301
+
302
+ // Process other benchmark categories
303
+ ['swarm', 'agent', 'task', 'memory'].forEach(category => {
304
+ if (benchmarks[category]) {
305
+ Object.keys(benchmarks[category]).forEach(benchmarkType => {
306
+ const data = benchmarks[category][benchmarkType];
307
+ summary.push({
308
+ category: category.charAt(0).toUpperCase() + category.slice(1),
309
+ name: benchmarkType.replace(/_/g, ' ').replace(/\b\w/g, l => l.toUpperCase()),
310
+ avgTime: `${data.avg_ms?.toFixed(2) }ms` || '0.00ms',
311
+ minTime: `${data.min_ms?.toFixed(2) }ms` || '0.00ms',
312
+ maxTime: `${data.max_ms?.toFixed(2) }ms` || '0.00ms',
313
+ samples: data.samples || 0,
314
+ });
315
+ });
316
+ }
317
+ });
318
+
319
+ return summary.length > 0 ? summary : [{
320
+ category: 'System',
321
+ name: 'No Benchmarks Run',
322
+ avgTime: '0.00ms',
323
+ minTime: '0.00ms',
324
+ maxTime: '0.00ms',
325
+ samples: 0,
326
+ }];
327
+ }
328
+ }