@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,218 @@
1
+ /**
2
+ * Security module for @sparkleideas/ruv-swarm
3
+ * Provides integrity verification and security controls
4
+ */
5
+
6
+ import crypto from 'crypto';
7
+ import fs from 'fs/promises';
8
+ import path from 'path';
9
+
10
+ /**
11
+ * WASM module integrity verification
12
+ */
13
+ export class WasmIntegrityVerifier {
14
+ constructor(hashesPath = path.join(new URL('.', import.meta.url).pathname, '..', 'wasm', 'checksums.json')) {
15
+ this.hashesPath = hashesPath;
16
+ this.knownHashes = new Map();
17
+ this.initialized = false;
18
+ }
19
+
20
+ async loadKnownHashes() {
21
+ try {
22
+ const data = await fs.readFile(this.hashesPath, 'utf8');
23
+ const hashes = JSON.parse(data);
24
+ Object.entries(hashes).forEach(([file, hash]) => {
25
+ this.knownHashes.set(file, hash);
26
+ });
27
+ } catch (error) {
28
+ // Silently initialize with empty checksums if file doesn't exist
29
+ // This is expected on first run or if checksums.json is gitignored
30
+ }
31
+ }
32
+
33
+ async saveKnownHashes() {
34
+ try {
35
+ // Ensure directory exists
36
+ const dir = path.dirname(this.hashesPath);
37
+ await fs.mkdir(dir, { recursive: true });
38
+
39
+ const hashes = Object.fromEntries(this.knownHashes);
40
+ await fs.writeFile(this.hashesPath, JSON.stringify(hashes, null, 2));
41
+ } catch (error) {
42
+ // Silently fail if unable to save checksums
43
+ // This prevents errors when checksums.json is gitignored
44
+ }
45
+ }
46
+
47
+ /**
48
+ * Verify WASM module integrity before loading
49
+ * @param {string} wasmPath - Path to WASM module
50
+ * @param {boolean} updateHash - Update the known hash if verification fails
51
+ * @returns {Promise<boolean>} - True if verification passes
52
+ */
53
+ async verifyWasmModule(wasmPath, updateHash = false) {
54
+ // Ensure hashes are loaded
55
+ if (!this.initialized) {
56
+ await this.loadKnownHashes();
57
+ this.initialized = true;
58
+ }
59
+
60
+ try {
61
+ const wasmData = await fs.readFile(wasmPath);
62
+ const hash = crypto.createHash('sha256').update(wasmData).digest('hex');
63
+
64
+ const filename = path.basename(wasmPath);
65
+ const knownHash = this.knownHashes.get(filename);
66
+
67
+ if (!knownHash) {
68
+ if (updateHash) {
69
+ this.knownHashes.set(filename, hash);
70
+ await this.saveKnownHashes();
71
+ return true;
72
+ }
73
+ throw new SecurityError(`Unknown WASM module: ${filename}`);
74
+ }
75
+
76
+ if (hash !== knownHash) {
77
+ throw new SecurityError(`WASM module integrity check failed for ${filename}`);
78
+ }
79
+
80
+ return true;
81
+ } catch (error) {
82
+ if (error instanceof SecurityError) {
83
+ throw error;
84
+ }
85
+ throw new SecurityError(`Failed to verify WASM module: ${error.message}`);
86
+ }
87
+ }
88
+
89
+ /**
90
+ * Load and verify WASM module
91
+ * @param {string} wasmPath - Path to WASM module
92
+ * @returns {Promise<ArrayBuffer>} - Verified WASM data
93
+ */
94
+ async loadVerifiedWasm(wasmPath) {
95
+ // Ensure hashes are loaded
96
+ if (!this.initialized) {
97
+ await this.loadKnownHashes();
98
+ this.initialized = true;
99
+ }
100
+
101
+ await this.verifyWasmModule(wasmPath);
102
+ return await fs.readFile(wasmPath);
103
+ }
104
+ }
105
+
106
+ /**
107
+ * Command injection prevention
108
+ */
109
+ export class CommandSanitizer {
110
+ static validateArgument(arg) {
111
+ // Only allow alphanumeric, dash, underscore, and common safe characters
112
+ const safePattern = /^[a-zA-Z0-9\-_./=:\s]+$/;
113
+
114
+ if (!safePattern.test(arg)) {
115
+ throw new SecurityError(`Invalid argument contains unsafe characters: ${arg}`);
116
+ }
117
+
118
+ // Check for command injection patterns
119
+ const dangerousPatterns = [
120
+ /[;&|`$(){}[\]<>]/, // Shell metacharacters
121
+ /\.\./, // Path traversal
122
+ /^-/, // Argument injection
123
+ ];
124
+
125
+ for (const pattern of dangerousPatterns) {
126
+ if (pattern.test(arg)) {
127
+ throw new SecurityError(`Potentially dangerous pattern detected in argument: ${arg}`);
128
+ }
129
+ }
130
+
131
+ return arg;
132
+ }
133
+
134
+ static sanitizeCommand(command, args = []) {
135
+ // Validate command is from allowed list
136
+ const allowedCommands = ['claude', 'npm', 'node', 'npx'];
137
+
138
+ if (!allowedCommands.includes(command)) {
139
+ throw new SecurityError(`Command not in allowlist: ${command}`);
140
+ }
141
+
142
+ // Validate all arguments
143
+ const sanitizedArgs = args.map(arg => this.validateArgument(arg));
144
+
145
+ return { command, args: sanitizedArgs };
146
+ }
147
+ }
148
+
149
+ /**
150
+ * Dependency integrity verification
151
+ */
152
+ export class DependencyVerifier {
153
+ static async verifyNpmPackage(packageName, expectedVersion) {
154
+ try {
155
+ const packageJsonPath = path.join(
156
+ new URL('.', import.meta.url).pathname,
157
+ '..',
158
+ 'node_modules',
159
+ packageName,
160
+ 'package.json',
161
+ );
162
+
163
+ const packageData = JSON.parse(await fs.readFile(packageJsonPath, 'utf8'));
164
+
165
+ if (packageData.version !== expectedVersion) {
166
+ throw new SecurityError(
167
+ `Package version mismatch for ${packageName}: expected ${expectedVersion}, got ${packageData.version}`,
168
+ );
169
+ }
170
+
171
+ return true;
172
+ } catch (error) {
173
+ if (error instanceof SecurityError) {
174
+ throw error;
175
+ }
176
+ throw new SecurityError(`Failed to verify package ${packageName}: ${error.message}`);
177
+ }
178
+ }
179
+ }
180
+
181
+ /**
182
+ * Security error class
183
+ */
184
+ export class SecurityError extends Error {
185
+ constructor(message) {
186
+ super(message);
187
+ this.name = 'SecurityError';
188
+ }
189
+ }
190
+
191
+ /**
192
+ * Security middleware for MCP server
193
+ */
194
+ export function createSecurityMiddleware() {
195
+ const wasmVerifier = new WasmIntegrityVerifier();
196
+
197
+ return {
198
+ async verifyWasmBeforeLoad(wasmPath) {
199
+ return await wasmVerifier.verifyWasmModule(wasmPath);
200
+ },
201
+
202
+ sanitizeCommand(command, args) {
203
+ return CommandSanitizer.sanitizeCommand(command, args);
204
+ },
205
+
206
+ async verifyDependency(packageName, version) {
207
+ return await DependencyVerifier.verifyNpmPackage(packageName, version);
208
+ },
209
+ };
210
+ }
211
+
212
+ export default {
213
+ WasmIntegrityVerifier,
214
+ CommandSanitizer,
215
+ DependencyVerifier,
216
+ SecurityError,
217
+ createSecurityMiddleware,
218
+ };
@@ -0,0 +1,183 @@
1
+ /**
2
+ * Singleton Container - Dependency Injection Pattern
3
+ * Replaces global state management with proper IoC container
4
+ */
5
+
6
+ class SingletonContainer {
7
+ constructor() {
8
+ this.instances = new Map();
9
+ this.factories = new Map();
10
+ this.isDestroying = false;
11
+ }
12
+
13
+ /**
14
+ * Register a singleton factory
15
+ * @param {string} key - Service identifier
16
+ * @param {Function} factory - Factory function to create instance
17
+ * @param {Object} options - Configuration options
18
+ */
19
+ register(key, factory, options = {}) {
20
+ if (typeof factory !== 'function') {
21
+ throw new Error(`Factory for '${key}' must be a function`);
22
+ }
23
+
24
+ this.factories.set(key, {
25
+ factory,
26
+ lazy: options.lazy !== false, // Default to lazy loading
27
+ singleton: options.singleton !== false, // Default to singleton
28
+ dependencies: options.dependencies || [],
29
+ });
30
+ }
31
+
32
+ /**
33
+ * Get or create singleton instance
34
+ * @param {string} key - Service identifier
35
+ * @returns {*} Singleton instance
36
+ */
37
+ get(key) {
38
+ if (this.isDestroying) {
39
+ throw new Error(`Cannot get instance '${key}' during container destruction`);
40
+ }
41
+
42
+ // Return existing instance if available
43
+ if (this.instances.has(key)) {
44
+ return this.instances.get(key);
45
+ }
46
+
47
+ // Get factory configuration
48
+ const config = this.factories.get(key);
49
+ if (!config) {
50
+ throw new Error(`No factory registered for '${key}'`);
51
+ }
52
+
53
+ // Resolve dependencies
54
+ const dependencies = config.dependencies.map(dep => this.get(dep));
55
+
56
+ try {
57
+ // Create instance using factory
58
+ const instance = config.factory(...dependencies);
59
+
60
+ // Store singleton instance
61
+ if (config.singleton) {
62
+ this.instances.set(key, instance);
63
+ }
64
+
65
+ return instance;
66
+ } catch (error) {
67
+ throw new Error(`Failed to create instance '${key}': ${error.message}`);
68
+ }
69
+ }
70
+
71
+ /**
72
+ * Check if service is registered
73
+ * @param {string} key - Service identifier
74
+ * @returns {boolean} True if registered
75
+ */
76
+ has(key) {
77
+ return this.factories.has(key) || this.instances.has(key);
78
+ }
79
+
80
+ /**
81
+ * Clear specific instance (force recreation)
82
+ * @param {string} key - Service identifier
83
+ */
84
+ clear(key) {
85
+ const instance = this.instances.get(key);
86
+ if (instance && typeof instance.destroy === 'function') {
87
+ instance.destroy();
88
+ }
89
+ this.instances.delete(key);
90
+ }
91
+
92
+ /**
93
+ * Destroy all instances and clear container
94
+ */
95
+ destroy() {
96
+ this.isDestroying = true;
97
+
98
+ // Destroy instances in reverse order of creation
99
+ const instances = Array.from(this.instances.entries()).reverse();
100
+
101
+ for (const [key, instance] of instances) {
102
+ try {
103
+ if (instance && typeof instance.destroy === 'function') {
104
+ instance.destroy();
105
+ }
106
+ } catch (error) {
107
+ console.warn(`Error destroying instance '${key}':`, error.message);
108
+ }
109
+ }
110
+
111
+ this.instances.clear();
112
+ this.factories.clear();
113
+
114
+ // Keep destroying flag to prevent new instance creation
115
+ // Reset only when explicitly requested
116
+ }
117
+
118
+ /**
119
+ * Reset container state (for testing)
120
+ */
121
+ reset() {
122
+ this.destroy();
123
+ this.isDestroying = false;
124
+ }
125
+
126
+ /**
127
+ * Get container statistics
128
+ * @returns {Object} Container stats
129
+ */
130
+ getStats() {
131
+ return {
132
+ registeredServices: this.factories.size,
133
+ activeInstances: this.instances.size,
134
+ services: Array.from(this.factories.keys()),
135
+ instances: Array.from(this.instances.keys()),
136
+ };
137
+ }
138
+ }
139
+
140
+ // Global container instance (properly managed)
141
+ let globalContainer = null;
142
+
143
+ /**
144
+ * Get or create global container
145
+ * @returns {SingletonContainer} Global container instance
146
+ */
147
+ export function getContainer() {
148
+ if (!globalContainer) {
149
+ globalContainer = new SingletonContainer();
150
+
151
+ // Register cleanup on process exit
152
+ if (typeof process !== 'undefined') {
153
+ process.on('exit', () => {
154
+ if (globalContainer) {
155
+ globalContainer.destroy();
156
+ globalContainer = null;
157
+ }
158
+ });
159
+
160
+ process.on('SIGINT', () => {
161
+ if (globalContainer) {
162
+ globalContainer.destroy();
163
+ globalContainer = null;
164
+ }
165
+ process.exit(0);
166
+ });
167
+ }
168
+ }
169
+
170
+ return globalContainer;
171
+ }
172
+
173
+ /**
174
+ * Reset global container (for testing)
175
+ */
176
+ export function resetContainer() {
177
+ if (globalContainer) {
178
+ globalContainer.destroy();
179
+ }
180
+ globalContainer = null;
181
+ }
182
+
183
+ export { SingletonContainer };