@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
package/src/index.d.ts
ADDED
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @ruv/swarm - High-performance neural network swarm orchestration in WebAssembly
|
|
3
|
+
* Enhanced version with progressive WASM loading and full feature set
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
// Re-export all types from the enhanced definitions
|
|
7
|
+
export * from './index-enhanced';
|
|
8
|
+
|
|
9
|
+
export interface InitOptions {
|
|
10
|
+
/** Path to WASM files */
|
|
11
|
+
wasmPath?: string;
|
|
12
|
+
/** Use SIMD optimizations if available */
|
|
13
|
+
useSIMD?: boolean;
|
|
14
|
+
/** Enable debug logging */
|
|
15
|
+
debug?: boolean;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface SwarmConfig {
|
|
19
|
+
/** Name of the swarm */
|
|
20
|
+
name: string;
|
|
21
|
+
/** Swarm strategy */
|
|
22
|
+
strategy: 'research' | 'development' | 'analysis' | 'testing' | 'optimization' | 'maintenance';
|
|
23
|
+
/** Coordination mode */
|
|
24
|
+
mode: 'centralized' | 'distributed' | 'hierarchical' | 'mesh' | 'hybrid';
|
|
25
|
+
/** Maximum number of agents */
|
|
26
|
+
maxAgents?: number;
|
|
27
|
+
/** Enable parallel execution */
|
|
28
|
+
parallel?: boolean;
|
|
29
|
+
/** Enable monitoring */
|
|
30
|
+
monitor?: boolean;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export interface AgentConfig {
|
|
34
|
+
/** Agent name */
|
|
35
|
+
name: string;
|
|
36
|
+
/** Agent type */
|
|
37
|
+
type: 'researcher' | 'coder' | 'analyst' | 'optimizer' | 'coordinator';
|
|
38
|
+
/** Agent capabilities */
|
|
39
|
+
capabilities?: string[];
|
|
40
|
+
/** Maximum concurrent tasks */
|
|
41
|
+
maxConcurrentTasks?: number;
|
|
42
|
+
/** Memory limit in bytes */
|
|
43
|
+
memoryLimit?: number;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export interface TaskConfig {
|
|
47
|
+
/** Task ID */
|
|
48
|
+
id: string;
|
|
49
|
+
/** Task description */
|
|
50
|
+
description: string;
|
|
51
|
+
/** Task priority */
|
|
52
|
+
priority: 'low' | 'medium' | 'high';
|
|
53
|
+
/** Task dependencies */
|
|
54
|
+
dependencies: string[];
|
|
55
|
+
/** Additional metadata */
|
|
56
|
+
metadata?: Record<string, any>;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export interface TaskRequest {
|
|
60
|
+
/** Task ID */
|
|
61
|
+
id: string;
|
|
62
|
+
/** Task description */
|
|
63
|
+
description: string;
|
|
64
|
+
/** Task parameters */
|
|
65
|
+
parameters?: any;
|
|
66
|
+
/** Timeout in milliseconds */
|
|
67
|
+
timeout?: number;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export interface TaskResponse {
|
|
71
|
+
/** Task ID */
|
|
72
|
+
taskId: string;
|
|
73
|
+
/** Execution status */
|
|
74
|
+
status: 'completed' | 'failed' | 'timeout';
|
|
75
|
+
/** Task result */
|
|
76
|
+
result: any;
|
|
77
|
+
/** Execution time in seconds */
|
|
78
|
+
executionTime: number;
|
|
79
|
+
/** Error message if failed */
|
|
80
|
+
error?: string;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export interface OrchestrationResult {
|
|
84
|
+
/** Task ID */
|
|
85
|
+
taskId: string;
|
|
86
|
+
/** Overall status */
|
|
87
|
+
status: string;
|
|
88
|
+
/** Results from each agent */
|
|
89
|
+
results: AgentResult[];
|
|
90
|
+
/** Orchestration metrics */
|
|
91
|
+
metrics: OrchestrationMetrics;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export interface AgentResult {
|
|
95
|
+
/** Agent ID */
|
|
96
|
+
agentId: string;
|
|
97
|
+
/** Agent type */
|
|
98
|
+
agentType: string;
|
|
99
|
+
/** Agent output */
|
|
100
|
+
output: any;
|
|
101
|
+
/** Execution time in seconds */
|
|
102
|
+
executionTime: number;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export interface OrchestrationMetrics {
|
|
106
|
+
/** Total orchestration time in seconds */
|
|
107
|
+
totalTime: number;
|
|
108
|
+
/** Number of agents spawned */
|
|
109
|
+
agentsSpawned: number;
|
|
110
|
+
/** Number of tasks completed */
|
|
111
|
+
tasksCompleted: number;
|
|
112
|
+
/** Memory usage in MB */
|
|
113
|
+
memoryUsage: number;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export interface AgentMetrics {
|
|
117
|
+
/** Number of tasks completed */
|
|
118
|
+
tasksCompleted: number;
|
|
119
|
+
/** Number of tasks failed */
|
|
120
|
+
tasksFailed: number;
|
|
121
|
+
/** Average execution time in seconds */
|
|
122
|
+
averageExecutionTime: number;
|
|
123
|
+
/** Memory usage in bytes */
|
|
124
|
+
memoryUsage: number;
|
|
125
|
+
/** CPU usage percentage */
|
|
126
|
+
cpuUsage: number;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export interface RuntimeFeatures {
|
|
130
|
+
/** SIMD support available */
|
|
131
|
+
simdAvailable: boolean;
|
|
132
|
+
/** Threading support available */
|
|
133
|
+
threadsAvailable: boolean;
|
|
134
|
+
/** Memory limit in bytes */
|
|
135
|
+
memoryLimit: number;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* JavaScript Agent interface for swarm orchestration
|
|
140
|
+
*/
|
|
141
|
+
export declare class JsAgent {
|
|
142
|
+
/** Agent ID */
|
|
143
|
+
readonly id: string;
|
|
144
|
+
/** Agent type */
|
|
145
|
+
readonly agentType: string;
|
|
146
|
+
/** Current status */
|
|
147
|
+
readonly status: string;
|
|
148
|
+
/** Number of completed tasks */
|
|
149
|
+
readonly tasksCompleted: number;
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Execute a task
|
|
153
|
+
* @param task Task request configuration
|
|
154
|
+
* @returns Task response with results
|
|
155
|
+
*/
|
|
156
|
+
execute(task: TaskRequest): Promise<TaskResponse>;
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Get agent metrics
|
|
160
|
+
* @returns Current agent metrics
|
|
161
|
+
*/
|
|
162
|
+
getMetrics(): AgentMetrics;
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Get agent capabilities
|
|
166
|
+
* @returns List of agent capabilities
|
|
167
|
+
*/
|
|
168
|
+
getCapabilities(): string[];
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* Reset agent state
|
|
172
|
+
*/
|
|
173
|
+
reset(): void;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* Main RuvSwarm class for neural network swarm orchestration
|
|
178
|
+
*/
|
|
179
|
+
export declare class RuvSwarm {
|
|
180
|
+
/** Swarm name */
|
|
181
|
+
readonly name: string;
|
|
182
|
+
/** Number of active agents */
|
|
183
|
+
readonly agentCount: number;
|
|
184
|
+
/** Maximum number of agents */
|
|
185
|
+
readonly maxAgents: number;
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* Create a new RuvSwarm instance
|
|
189
|
+
* @param config Swarm configuration
|
|
190
|
+
*/
|
|
191
|
+
constructor(config: SwarmConfig);
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* Initialize RuvSwarm with WASM module
|
|
195
|
+
* @param options Initialization options
|
|
196
|
+
* @returns Initialized RuvSwarm instance
|
|
197
|
+
*/
|
|
198
|
+
static initialize(options?: InitOptions): Promise<RuvSwarm>;
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* Detect SIMD support in the current environment
|
|
202
|
+
* @returns True if SIMD is supported
|
|
203
|
+
*/
|
|
204
|
+
static detectSIMDSupport(): boolean;
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* Get runtime features
|
|
208
|
+
* @returns Runtime feature detection results
|
|
209
|
+
*/
|
|
210
|
+
static getRuntimeFeatures(): RuntimeFeatures;
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* Get library version
|
|
214
|
+
* @returns Version string
|
|
215
|
+
*/
|
|
216
|
+
static getVersion(): string;
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* Spawn a new agent
|
|
220
|
+
* @param config Agent configuration
|
|
221
|
+
* @returns Spawned agent instance
|
|
222
|
+
*/
|
|
223
|
+
spawn(config: AgentConfig): Promise<JsAgent>;
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* Orchestrate a task across the swarm
|
|
227
|
+
* @param task Task configuration
|
|
228
|
+
* @returns Orchestration results
|
|
229
|
+
*/
|
|
230
|
+
orchestrate(task: TaskConfig): Promise<OrchestrationResult>;
|
|
231
|
+
|
|
232
|
+
/**
|
|
233
|
+
* Get list of active agents
|
|
234
|
+
* @returns Array of agent IDs
|
|
235
|
+
*/
|
|
236
|
+
getAgents(): string[];
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* Get swarm status
|
|
240
|
+
* @returns Current swarm status
|
|
241
|
+
*/
|
|
242
|
+
getStatus(): {
|
|
243
|
+
name: string;
|
|
244
|
+
strategy: string;
|
|
245
|
+
mode: string;
|
|
246
|
+
agents: string[];
|
|
247
|
+
agentCount: number;
|
|
248
|
+
maxAgents: number;
|
|
249
|
+
};
|
|
250
|
+
|
|
251
|
+
/**
|
|
252
|
+
* Get WASM memory usage
|
|
253
|
+
* @returns Memory usage in bytes
|
|
254
|
+
*/
|
|
255
|
+
static getMemoryUsage(): number;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
/**
|
|
259
|
+
* Performance timer utility
|
|
260
|
+
*/
|
|
261
|
+
export declare class PerformanceTimer {
|
|
262
|
+
/**
|
|
263
|
+
* Create a new performance timer
|
|
264
|
+
* @param name Timer name
|
|
265
|
+
*/
|
|
266
|
+
constructor(name: string);
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* Get elapsed time in milliseconds
|
|
270
|
+
* @returns Elapsed time
|
|
271
|
+
*/
|
|
272
|
+
elapsed(): number;
|
|
273
|
+
|
|
274
|
+
/**
|
|
275
|
+
* Log elapsed time to console
|
|
276
|
+
*/
|
|
277
|
+
log(): void;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
// Re-export utility functions
|
|
281
|
+
export declare function consoleLog(message: string): void;
|
|
282
|
+
export declare function consoleError(message: string): void;
|
|
283
|
+
export declare function consoleWarn(message: string): void;
|
|
284
|
+
export declare function formatJsError(error: any): string;
|
|
285
|
+
|
|
286
|
+
// Export DAA service types and interfaces
|
|
287
|
+
export * from './daa-service';
|
package/src/index.js
ADDED
|
@@ -0,0 +1,405 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @ruv/swarm - High-performance neural network swarm orchestration in WebAssembly
|
|
3
|
+
* Enhanced version with progressive WASM loading and full feature set
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
// Re-export the enhanced implementation
|
|
7
|
+
export * from './index-enhanced.js';
|
|
8
|
+
|
|
9
|
+
/* Legacy exports for backward compatibility */
|
|
10
|
+
import path from 'path';
|
|
11
|
+
import { promises as fs } from 'fs';
|
|
12
|
+
|
|
13
|
+
// Lazy-loaded WASM module
|
|
14
|
+
let wasmModule = null;
|
|
15
|
+
let wasmInstance = null;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* WASM loader with feature detection and caching
|
|
19
|
+
*/
|
|
20
|
+
class WASMLoader {
|
|
21
|
+
constructor(options = {}) {
|
|
22
|
+
this.useSIMD = options.useSIMD && this.detectSIMDSupport();
|
|
23
|
+
this.wasmPath = options.wasmPath || path.join(new URL('.', import.meta.url).pathname, '..', 'wasm');
|
|
24
|
+
this.debug = options.debug || false;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
detectSIMDSupport() {
|
|
28
|
+
try {
|
|
29
|
+
// WebAssembly SIMD feature detection
|
|
30
|
+
if (typeof WebAssembly !== 'undefined' && WebAssembly.validate) {
|
|
31
|
+
// Test SIMD instruction
|
|
32
|
+
const simdTest = new Uint8Array([
|
|
33
|
+
0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00,
|
|
34
|
+
0x01, 0x05, 0x01, 0x60, 0x00, 0x01, 0x7b, 0x03,
|
|
35
|
+
0x02, 0x01, 0x00, 0x0a, 0x0a, 0x01, 0x08, 0x00,
|
|
36
|
+
0x41, 0x00, 0xfd, 0x0f, 0x26, 0x0b,
|
|
37
|
+
]);
|
|
38
|
+
return WebAssembly.validate(simdTest);
|
|
39
|
+
}
|
|
40
|
+
} catch (e) {
|
|
41
|
+
if (this.debug) {
|
|
42
|
+
console.warn('SIMD detection failed:', e);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
async loadModule() {
|
|
49
|
+
if (wasmModule) {
|
|
50
|
+
return wasmModule;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// Use the generated WASM bindings directly (ES module import)
|
|
54
|
+
try {
|
|
55
|
+
const wasmJsPath = path.join(this.wasmPath, 'ruv_swarm_wasm.js');
|
|
56
|
+
const wasmBindings = await import(path.resolve(wasmJsPath));
|
|
57
|
+
wasmModule = wasmBindings;
|
|
58
|
+
return wasmModule;
|
|
59
|
+
} catch (error) {
|
|
60
|
+
if (this.debug) {
|
|
61
|
+
console.error('Failed to load WASM bindings:', error);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// Fallback to manual loading
|
|
66
|
+
const moduleFile = this.useSIMD ? 'ruv_swarm_simd.wasm' : 'ruv_swarm_wasm_bg.wasm';
|
|
67
|
+
const wasmFilePath = path.join(this.wasmPath, moduleFile);
|
|
68
|
+
|
|
69
|
+
try {
|
|
70
|
+
let wasmBuffer;
|
|
71
|
+
|
|
72
|
+
if (typeof window !== 'undefined') {
|
|
73
|
+
// Browser environment
|
|
74
|
+
const response = await fetch(wasmFilePath);
|
|
75
|
+
wasmBuffer = await response.arrayBuffer();
|
|
76
|
+
} else {
|
|
77
|
+
// Node.js environment
|
|
78
|
+
wasmBuffer = await fs.readFile(wasmFilePath);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const imports = {
|
|
82
|
+
// Add any required imports here
|
|
83
|
+
env: {
|
|
84
|
+
memory: new WebAssembly.Memory({ initial: 256, maximum: 4096 }),
|
|
85
|
+
},
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
const result = await WebAssembly.instantiate(wasmBuffer, imports);
|
|
89
|
+
wasmModule = result.module;
|
|
90
|
+
wasmInstance = result.instance;
|
|
91
|
+
|
|
92
|
+
if (this.debug) {
|
|
93
|
+
console.log(`Loaded WASM module: ${moduleFile}`);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
return result;
|
|
97
|
+
} catch (error) {
|
|
98
|
+
throw new Error(`Failed to load WASM module: ${error.message}`);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Worker pool for parallel execution
|
|
105
|
+
*/
|
|
106
|
+
class WorkerPool {
|
|
107
|
+
constructor(size = 4) {
|
|
108
|
+
this.size = size;
|
|
109
|
+
this.workers = [];
|
|
110
|
+
this.queue = [];
|
|
111
|
+
this.initialized = false;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
async initialize() {
|
|
115
|
+
if (this.initialized) {
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// In Node.js, use worker_threads
|
|
120
|
+
if (typeof window === 'undefined') {
|
|
121
|
+
// const { Worker } = require('worker_threads');
|
|
122
|
+
for (let i = 0; i < this.size; i++) {
|
|
123
|
+
// TODO: Create worker thread
|
|
124
|
+
}
|
|
125
|
+
} else {
|
|
126
|
+
// In browser, use Web Workers
|
|
127
|
+
for (let i = 0; i < this.size; i++) {
|
|
128
|
+
// TODO: Create web worker
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
this.initialized = true;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
async execute(task) {
|
|
136
|
+
// TODO: Implement worker pool execution
|
|
137
|
+
return task;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
terminate() {
|
|
141
|
+
this.workers.forEach(worker => {
|
|
142
|
+
if (worker.terminate) {
|
|
143
|
+
worker.terminate();
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
this.workers = [];
|
|
147
|
+
this.initialized = false;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Main RuvSwarm class
|
|
153
|
+
*/
|
|
154
|
+
class RuvSwarm {
|
|
155
|
+
constructor(wasmSwarm, options = {}) {
|
|
156
|
+
this._wasmSwarm = wasmSwarm;
|
|
157
|
+
this._options = options;
|
|
158
|
+
this._workerPool = null;
|
|
159
|
+
|
|
160
|
+
if (options.parallel) {
|
|
161
|
+
this._workerPool = new WorkerPool(options.workerPoolSize || 4);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
static async initialize(options = {}) {
|
|
166
|
+
const loader = new WASMLoader(options);
|
|
167
|
+
// const wasmResult = await loader.loadModule();
|
|
168
|
+
|
|
169
|
+
// Load the WASM bindings (ES module import with proper file URL)
|
|
170
|
+
const wasmJsPath = path.join(loader.wasmPath, 'ruv_swarm_wasm.js');
|
|
171
|
+
const bindings = await import(path.resolve(wasmJsPath));
|
|
172
|
+
|
|
173
|
+
// Initialize WASM module with file buffer for Node.js
|
|
174
|
+
if (bindings.default) {
|
|
175
|
+
const wasmPath = path.join(loader.wasmPath, 'ruv_swarm_wasm_bg.wasm');
|
|
176
|
+
const wasmBuffer = await fs.readFile(wasmPath);
|
|
177
|
+
await bindings.default({ module_or_path: wasmBuffer });
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
// Get runtime features
|
|
181
|
+
const features = new bindings.RuntimeFeatures();
|
|
182
|
+
if (options.debug) {
|
|
183
|
+
console.log('Runtime features:', {
|
|
184
|
+
simd: features.simd_available,
|
|
185
|
+
threads: features.threads_available,
|
|
186
|
+
memoryLimit: features.memory_limit,
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
return new RuvSwarm(bindings, options);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
static detectSIMDSupport() {
|
|
194
|
+
const loader = new WASMLoader();
|
|
195
|
+
return loader.detectSIMDSupport();
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
static getRuntimeFeatures() {
|
|
199
|
+
if (!wasmInstance) {
|
|
200
|
+
throw new Error('RuvSwarm not initialized. Call RuvSwarm.initialize() first.');
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
const features = new wasmInstance.exports.RuntimeFeatures();
|
|
204
|
+
return {
|
|
205
|
+
simdAvailable: features.simd_available,
|
|
206
|
+
threadsAvailable: features.threads_available,
|
|
207
|
+
memoryLimit: features.memory_limit,
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
static getVersion() {
|
|
212
|
+
if (!wasmInstance) {
|
|
213
|
+
return require('../package.json').version;
|
|
214
|
+
}
|
|
215
|
+
return wasmInstance.exports.get_version();
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
static getMemoryUsage() {
|
|
219
|
+
if (!wasmInstance) {
|
|
220
|
+
return 0;
|
|
221
|
+
}
|
|
222
|
+
return wasmInstance.exports.get_wasm_memory_usage();
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
async createSwarm(config) {
|
|
226
|
+
try {
|
|
227
|
+
const swarm = new this._wasmSwarm.RuvSwarm(config);
|
|
228
|
+
return new SwarmWrapper(swarm, this._options);
|
|
229
|
+
} catch (error) {
|
|
230
|
+
throw new Error(`Failed to create swarm: ${error.message}`);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
// Instance method that delegates to static method for API convenience
|
|
235
|
+
detectSIMDSupport() {
|
|
236
|
+
return RuvSwarm.detectSIMDSupport();
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
/**
|
|
241
|
+
* Swarm wrapper class
|
|
242
|
+
*/
|
|
243
|
+
class SwarmWrapper {
|
|
244
|
+
constructor(wasmSwarm, options = {}) {
|
|
245
|
+
this._swarm = wasmSwarm;
|
|
246
|
+
this._options = options;
|
|
247
|
+
this._retryAttempts = options.retryAttempts || 3;
|
|
248
|
+
this._retryDelay = options.retryDelay || 1000;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
get name() {
|
|
252
|
+
return this._swarm.name;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
get agentCount() {
|
|
256
|
+
return this._swarm.agent_count;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
get maxAgents() {
|
|
260
|
+
return this._swarm.max_agents;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
async spawn(config) {
|
|
264
|
+
return await this._retryOperation(async() => {
|
|
265
|
+
const agent = await this._swarm.spawn(config);
|
|
266
|
+
return new AgentWrapper(agent, this._options);
|
|
267
|
+
});
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
async orchestrate(task) {
|
|
271
|
+
return await this._retryOperation(async() => {
|
|
272
|
+
return await this._swarm.orchestrate(task);
|
|
273
|
+
});
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
getAgents() {
|
|
277
|
+
return this._swarm.get_agents();
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
getStatus() {
|
|
281
|
+
return this._swarm.get_status();
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
async _retryOperation(operation) {
|
|
285
|
+
let lastError;
|
|
286
|
+
|
|
287
|
+
for (let attempt = 0; attempt < this._retryAttempts; attempt++) {
|
|
288
|
+
try {
|
|
289
|
+
return await operation();
|
|
290
|
+
} catch (error) {
|
|
291
|
+
lastError = error;
|
|
292
|
+
if (attempt < this._retryAttempts - 1) {
|
|
293
|
+
await new Promise(resolve => setTimeout(resolve, this._retryDelay));
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
throw lastError;
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
/**
|
|
303
|
+
* Agent wrapper class
|
|
304
|
+
*/
|
|
305
|
+
class AgentWrapper {
|
|
306
|
+
constructor(wasmAgent, options = {}) {
|
|
307
|
+
this._agent = wasmAgent;
|
|
308
|
+
this._options = options;
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
get id() {
|
|
312
|
+
return this._agent.id;
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
get agentType() {
|
|
316
|
+
return this._agent.agent_type;
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
get status() {
|
|
320
|
+
return this._agent.status;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
get tasksCompleted() {
|
|
324
|
+
return this._agent.tasks_completed;
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
async execute(task) {
|
|
328
|
+
return await this._agent.execute(task);
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
getMetrics() {
|
|
332
|
+
return this._agent.get_metrics();
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
getCapabilities() {
|
|
336
|
+
return this._agent.get_capabilities();
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
reset() {
|
|
340
|
+
this._agent.reset();
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
// Re-export utility functions
|
|
345
|
+
const consoleLog = (message) => {
|
|
346
|
+
if (wasmInstance && wasmInstance.exports.console_log) {
|
|
347
|
+
wasmInstance.exports.console_log(message);
|
|
348
|
+
} else {
|
|
349
|
+
console.log(message);
|
|
350
|
+
}
|
|
351
|
+
};
|
|
352
|
+
|
|
353
|
+
const consoleError = (message) => {
|
|
354
|
+
if (wasmInstance && wasmInstance.exports.console_error) {
|
|
355
|
+
wasmInstance.exports.console_error(message);
|
|
356
|
+
} else {
|
|
357
|
+
console.error(message);
|
|
358
|
+
}
|
|
359
|
+
};
|
|
360
|
+
|
|
361
|
+
const consoleWarn = (message) => {
|
|
362
|
+
if (wasmInstance && wasmInstance.exports.console_warn) {
|
|
363
|
+
wasmInstance.exports.console_warn(message);
|
|
364
|
+
} else {
|
|
365
|
+
console.warn(message);
|
|
366
|
+
}
|
|
367
|
+
};
|
|
368
|
+
|
|
369
|
+
const formatJsError = (error) => {
|
|
370
|
+
if (wasmInstance && wasmInstance.exports.format_js_error) {
|
|
371
|
+
return wasmInstance.exports.format_js_error(error);
|
|
372
|
+
}
|
|
373
|
+
return error.toString();
|
|
374
|
+
};
|
|
375
|
+
|
|
376
|
+
// Import neural agent capabilities
|
|
377
|
+
import {
|
|
378
|
+
NeuralAgent,
|
|
379
|
+
NeuralAgentFactory,
|
|
380
|
+
NeuralNetwork,
|
|
381
|
+
COGNITIVE_PATTERNS,
|
|
382
|
+
AGENT_COGNITIVE_PROFILES,
|
|
383
|
+
} from './neural-agent.js';
|
|
384
|
+
|
|
385
|
+
// Import DAA service for comprehensive agent management
|
|
386
|
+
import { DAAService, daaService } from './daa-service.js';
|
|
387
|
+
|
|
388
|
+
// Legacy exports - these are now provided by index-enhanced.js
|
|
389
|
+
// Export all the legacy functions and classes directly
|
|
390
|
+
export {
|
|
391
|
+
RuvSwarm,
|
|
392
|
+
consoleLog,
|
|
393
|
+
consoleError,
|
|
394
|
+
consoleWarn,
|
|
395
|
+
formatJsError,
|
|
396
|
+
// Neural agent exports
|
|
397
|
+
NeuralAgent,
|
|
398
|
+
NeuralAgentFactory,
|
|
399
|
+
NeuralNetwork,
|
|
400
|
+
COGNITIVE_PATTERNS,
|
|
401
|
+
AGENT_COGNITIVE_PROFILES,
|
|
402
|
+
// DAA service exports
|
|
403
|
+
DAAService,
|
|
404
|
+
daaService,
|
|
405
|
+
};
|