@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,533 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Diagnostic utilities for @sparkleideas/ruv-swarm
|
|
3
|
+
* Helps debug connection issues and performance problems
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { Logger } from './logger.js';
|
|
7
|
+
import { loggingConfig } from './logging-config.js';
|
|
8
|
+
import fs from 'fs';
|
|
9
|
+
import path from 'path';
|
|
10
|
+
import { performance } from 'perf_hooks';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Connection diagnostics
|
|
14
|
+
*/
|
|
15
|
+
export class ConnectionDiagnostics {
|
|
16
|
+
constructor(logger = null) {
|
|
17
|
+
this.logger = logger || loggingConfig.getLogger('diagnostics', { level: 'DEBUG' });
|
|
18
|
+
this.connectionHistory = [];
|
|
19
|
+
this.maxHistorySize = 100;
|
|
20
|
+
this.activeConnections = new Map();
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Record connection event
|
|
25
|
+
*/
|
|
26
|
+
recordEvent(connectionId, event, details = {}) {
|
|
27
|
+
const timestamp = new Date().toISOString();
|
|
28
|
+
const entry = {
|
|
29
|
+
connectionId,
|
|
30
|
+
event,
|
|
31
|
+
timestamp,
|
|
32
|
+
details,
|
|
33
|
+
memoryUsage: process.memoryUsage(),
|
|
34
|
+
cpuUsage: process.cpuUsage(),
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
this.connectionHistory.push(entry);
|
|
38
|
+
if (this.connectionHistory.length > this.maxHistorySize) {
|
|
39
|
+
this.connectionHistory.shift();
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// Track active connections
|
|
43
|
+
if (event === 'established') {
|
|
44
|
+
this.activeConnections.set(connectionId, {
|
|
45
|
+
startTime: Date.now(),
|
|
46
|
+
...details,
|
|
47
|
+
});
|
|
48
|
+
} else if (event === 'closed' || event === 'failed') {
|
|
49
|
+
const conn = this.activeConnections.get(connectionId);
|
|
50
|
+
if (conn) {
|
|
51
|
+
entry.duration = Date.now() - conn.startTime;
|
|
52
|
+
this.activeConnections.delete(connectionId);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
this.logger.debug('Connection event recorded', entry);
|
|
57
|
+
return entry;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Get connection summary
|
|
62
|
+
*/
|
|
63
|
+
getConnectionSummary() {
|
|
64
|
+
const events = this.connectionHistory.reduce((acc, event) => {
|
|
65
|
+
acc[event.event] = (acc[event.event] || 0) + 1;
|
|
66
|
+
return acc;
|
|
67
|
+
}, {});
|
|
68
|
+
|
|
69
|
+
const failures = this.connectionHistory.filter(e => e.event === 'failed');
|
|
70
|
+
const recentFailures = failures.slice(-10);
|
|
71
|
+
|
|
72
|
+
return {
|
|
73
|
+
totalEvents: this.connectionHistory.length,
|
|
74
|
+
eventCounts: events,
|
|
75
|
+
activeConnections: this.activeConnections.size,
|
|
76
|
+
recentFailures,
|
|
77
|
+
failureRate: failures.length / this.connectionHistory.length,
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Analyze connection patterns
|
|
83
|
+
*/
|
|
84
|
+
analyzePatterns() {
|
|
85
|
+
const failures = this.connectionHistory.filter(e => e.event === 'failed');
|
|
86
|
+
|
|
87
|
+
// Group failures by error type
|
|
88
|
+
const errorTypes = failures.reduce((acc, failure) => {
|
|
89
|
+
const error = failure.details.error?.message || 'Unknown';
|
|
90
|
+
acc[error] = (acc[error] || 0) + 1;
|
|
91
|
+
return acc;
|
|
92
|
+
}, {});
|
|
93
|
+
|
|
94
|
+
// Find time patterns
|
|
95
|
+
const hourlyFailures = new Array(24).fill(0);
|
|
96
|
+
failures.forEach(failure => {
|
|
97
|
+
const hour = new Date(failure.timestamp).getHours();
|
|
98
|
+
hourlyFailures[hour]++;
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
// Memory patterns at failure time
|
|
102
|
+
const memoryAtFailure = failures.map(f => ({
|
|
103
|
+
timestamp: f.timestamp,
|
|
104
|
+
heapUsed: f.memoryUsage.heapUsed / (1024 * 1024), // MB
|
|
105
|
+
external: f.memoryUsage.external / (1024 * 1024), // MB
|
|
106
|
+
}));
|
|
107
|
+
|
|
108
|
+
return {
|
|
109
|
+
errorTypes,
|
|
110
|
+
hourlyFailures,
|
|
111
|
+
memoryAtFailure,
|
|
112
|
+
avgMemoryAtFailure: memoryAtFailure.reduce((sum, m) => sum + m.heapUsed, 0) / memoryAtFailure.length,
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Generate diagnostic report
|
|
118
|
+
*/
|
|
119
|
+
generateReport() {
|
|
120
|
+
const summary = this.getConnectionSummary();
|
|
121
|
+
const patterns = this.analyzePatterns();
|
|
122
|
+
const systemInfo = {
|
|
123
|
+
platform: process.platform,
|
|
124
|
+
nodeVersion: process.version,
|
|
125
|
+
uptime: process.uptime(),
|
|
126
|
+
memoryUsage: process.memoryUsage(),
|
|
127
|
+
cpuUsage: process.cpuUsage(),
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
const report = {
|
|
131
|
+
timestamp: new Date().toISOString(),
|
|
132
|
+
system: systemInfo,
|
|
133
|
+
connections: summary,
|
|
134
|
+
patterns,
|
|
135
|
+
recommendations: this.generateRecommendations(summary, patterns),
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
this.logger.info('Diagnostic report generated', {
|
|
139
|
+
failureRate: summary.failureRate,
|
|
140
|
+
activeConnections: summary.activeConnections,
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
return report;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Generate recommendations based on patterns
|
|
148
|
+
*/
|
|
149
|
+
generateRecommendations(summary, patterns) {
|
|
150
|
+
const recommendations = [];
|
|
151
|
+
|
|
152
|
+
// High failure rate
|
|
153
|
+
if (summary.failureRate > 0.1) {
|
|
154
|
+
recommendations.push({
|
|
155
|
+
severity: 'high',
|
|
156
|
+
issue: 'High connection failure rate',
|
|
157
|
+
suggestion: 'Check network stability and MCP server configuration',
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
// Memory issues
|
|
162
|
+
if (patterns.avgMemoryAtFailure > 500) {
|
|
163
|
+
recommendations.push({
|
|
164
|
+
severity: 'medium',
|
|
165
|
+
issue: 'High memory usage during failures',
|
|
166
|
+
suggestion: 'Consider increasing memory limits or optimizing memory usage',
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
// Specific error patterns
|
|
171
|
+
Object.entries(patterns.errorTypes).forEach(([error, count]) => {
|
|
172
|
+
if (count > 5) {
|
|
173
|
+
recommendations.push({
|
|
174
|
+
severity: 'medium',
|
|
175
|
+
issue: `Recurring error: ${error}`,
|
|
176
|
+
suggestion: `Investigate root cause of: ${error}`,
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
return recommendations;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* Performance diagnostics
|
|
187
|
+
*/
|
|
188
|
+
export class PerformanceDiagnostics {
|
|
189
|
+
constructor(logger = null) {
|
|
190
|
+
this.logger = logger || loggingConfig.getLogger('diagnostics', { level: 'DEBUG' });
|
|
191
|
+
this.operations = new Map();
|
|
192
|
+
this.thresholds = {
|
|
193
|
+
'swarm_init': 1000, // 1 second
|
|
194
|
+
'agent_spawn': 500, // 500ms
|
|
195
|
+
'task_orchestrate': 2000, // 2 seconds
|
|
196
|
+
'neural_train': 5000, // 5 seconds
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* Start tracking an operation
|
|
202
|
+
*/
|
|
203
|
+
startOperation(name, metadata = {}) {
|
|
204
|
+
const id = `${name}-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
|
|
205
|
+
this.operations.set(id, {
|
|
206
|
+
name,
|
|
207
|
+
startTime: performance.now(),
|
|
208
|
+
startMemory: process.memoryUsage(),
|
|
209
|
+
metadata,
|
|
210
|
+
});
|
|
211
|
+
return id;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* End tracking an operation
|
|
216
|
+
*/
|
|
217
|
+
endOperation(id, success = true) {
|
|
218
|
+
const operation = this.operations.get(id);
|
|
219
|
+
if (!operation) {
|
|
220
|
+
return null;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
const endTime = performance.now();
|
|
224
|
+
const duration = endTime - operation.startTime;
|
|
225
|
+
const endMemory = process.memoryUsage();
|
|
226
|
+
|
|
227
|
+
const result = {
|
|
228
|
+
...operation,
|
|
229
|
+
endTime,
|
|
230
|
+
duration,
|
|
231
|
+
success,
|
|
232
|
+
memoryDelta: {
|
|
233
|
+
heapUsed: endMemory.heapUsed - operation.startMemory.heapUsed,
|
|
234
|
+
external: endMemory.external - operation.startMemory.external,
|
|
235
|
+
},
|
|
236
|
+
aboveThreshold: duration > (this.thresholds[operation.name] || 1000),
|
|
237
|
+
};
|
|
238
|
+
|
|
239
|
+
this.operations.delete(id);
|
|
240
|
+
|
|
241
|
+
if (result.aboveThreshold) {
|
|
242
|
+
this.logger.warn('Operation exceeded threshold', {
|
|
243
|
+
operation: operation.name,
|
|
244
|
+
duration,
|
|
245
|
+
threshold: this.thresholds[operation.name],
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
return result;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* Get slow operations
|
|
254
|
+
*/
|
|
255
|
+
getSlowOperations(limit = 10) {
|
|
256
|
+
const completed = [];
|
|
257
|
+
|
|
258
|
+
// Get completed operations from logger's performance tracker
|
|
259
|
+
// This would need to be implemented to store historical data
|
|
260
|
+
|
|
261
|
+
return completed
|
|
262
|
+
.filter(op => op.aboveThreshold)
|
|
263
|
+
.sort((a, b) => b.duration - a.duration)
|
|
264
|
+
.slice(0, limit);
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* System diagnostics
|
|
270
|
+
*/
|
|
271
|
+
export class SystemDiagnostics {
|
|
272
|
+
constructor(logger = null) {
|
|
273
|
+
this.logger = logger || loggingConfig.getLogger('diagnostics', { level: 'DEBUG' });
|
|
274
|
+
this.samples = [];
|
|
275
|
+
this.maxSamples = 60; // 1 minute of samples at 1Hz
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
/**
|
|
279
|
+
* Collect system sample
|
|
280
|
+
*/
|
|
281
|
+
collectSample() {
|
|
282
|
+
const sample = {
|
|
283
|
+
timestamp: Date.now(),
|
|
284
|
+
memory: process.memoryUsage(),
|
|
285
|
+
cpu: process.cpuUsage(),
|
|
286
|
+
handles: process._getActiveHandles?.().length || 0,
|
|
287
|
+
requests: process._getActiveRequests?.().length || 0,
|
|
288
|
+
};
|
|
289
|
+
|
|
290
|
+
this.samples.push(sample);
|
|
291
|
+
if (this.samples.length > this.maxSamples) {
|
|
292
|
+
this.samples.shift();
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
return sample;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
/**
|
|
299
|
+
* Start monitoring
|
|
300
|
+
*/
|
|
301
|
+
startMonitoring(interval = 1000) {
|
|
302
|
+
if (this.monitorInterval) {
|
|
303
|
+
this.stopMonitoring();
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
this.monitorInterval = setInterval(() => {
|
|
307
|
+
const sample = this.collectSample();
|
|
308
|
+
|
|
309
|
+
// Check for anomalies
|
|
310
|
+
if (sample.memory.heapUsed > 500 * 1024 * 1024) { // 500MB
|
|
311
|
+
this.logger.warn('High memory usage detected', {
|
|
312
|
+
heapUsed: `${(sample.memory.heapUsed / 1024 / 1024).toFixed(2)} MB`,
|
|
313
|
+
});
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
if (sample.handles > 100) {
|
|
317
|
+
this.logger.warn('High number of active handles', {
|
|
318
|
+
handles: sample.handles,
|
|
319
|
+
});
|
|
320
|
+
}
|
|
321
|
+
}, interval);
|
|
322
|
+
|
|
323
|
+
this.logger.info('System monitoring started', { interval });
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
/**
|
|
327
|
+
* Stop monitoring
|
|
328
|
+
*/
|
|
329
|
+
stopMonitoring() {
|
|
330
|
+
if (this.monitorInterval) {
|
|
331
|
+
clearInterval(this.monitorInterval);
|
|
332
|
+
this.monitorInterval = null;
|
|
333
|
+
this.logger.info('System monitoring stopped');
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
/**
|
|
338
|
+
* Get system health
|
|
339
|
+
*/
|
|
340
|
+
getSystemHealth() {
|
|
341
|
+
if (this.samples.length === 0) {
|
|
342
|
+
return { status: 'unknown', message: 'No samples collected' };
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
const latest = this.samples[this.samples.length - 1];
|
|
346
|
+
const avgMemory = this.samples.reduce((sum, s) => sum + s.memory.heapUsed, 0) / this.samples.length;
|
|
347
|
+
|
|
348
|
+
let status = 'healthy';
|
|
349
|
+
const issues = [];
|
|
350
|
+
|
|
351
|
+
if (latest.memory.heapUsed > 400 * 1024 * 1024) {
|
|
352
|
+
status = 'warning';
|
|
353
|
+
issues.push('High memory usage');
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
if (latest.handles > 50) {
|
|
357
|
+
status = 'warning';
|
|
358
|
+
issues.push('Many active handles');
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
if (avgMemory > 300 * 1024 * 1024) {
|
|
362
|
+
status = 'warning';
|
|
363
|
+
issues.push('Sustained high memory usage');
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
return {
|
|
367
|
+
status,
|
|
368
|
+
issues,
|
|
369
|
+
metrics: {
|
|
370
|
+
currentMemory: `${(latest.memory.heapUsed / 1024 / 1024).toFixed(2)} MB`,
|
|
371
|
+
avgMemory: `${(avgMemory / 1024 / 1024).toFixed(2)} MB`,
|
|
372
|
+
handles: latest.handles,
|
|
373
|
+
requests: latest.requests,
|
|
374
|
+
},
|
|
375
|
+
};
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
/**
|
|
380
|
+
* Main diagnostics manager
|
|
381
|
+
*/
|
|
382
|
+
export class DiagnosticsManager {
|
|
383
|
+
constructor() {
|
|
384
|
+
this.logger = loggingConfig.getLogger('diagnostics', { level: 'DEBUG' });
|
|
385
|
+
this.connection = new ConnectionDiagnostics(this.logger);
|
|
386
|
+
this.performance = new PerformanceDiagnostics(this.logger);
|
|
387
|
+
this.system = new SystemDiagnostics(this.logger);
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
/**
|
|
391
|
+
* Enable all diagnostics
|
|
392
|
+
*/
|
|
393
|
+
enableAll() {
|
|
394
|
+
this.system.startMonitoring();
|
|
395
|
+
this.logger.info('All diagnostics enabled');
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
/**
|
|
399
|
+
* Disable all diagnostics
|
|
400
|
+
*/
|
|
401
|
+
disableAll() {
|
|
402
|
+
this.system.stopMonitoring();
|
|
403
|
+
this.logger.info('All diagnostics disabled');
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
/**
|
|
407
|
+
* Generate full diagnostic report
|
|
408
|
+
*/
|
|
409
|
+
async generateFullReport(outputPath = null) {
|
|
410
|
+
const report = {
|
|
411
|
+
timestamp: new Date().toISOString(),
|
|
412
|
+
connection: this.connection.generateReport(),
|
|
413
|
+
performance: {
|
|
414
|
+
slowOperations: this.performance.getSlowOperations(),
|
|
415
|
+
},
|
|
416
|
+
system: this.system.getSystemHealth(),
|
|
417
|
+
logs: await this.collectRecentLogs(),
|
|
418
|
+
};
|
|
419
|
+
|
|
420
|
+
if (outputPath) {
|
|
421
|
+
const reportPath = path.resolve(outputPath);
|
|
422
|
+
fs.writeFileSync(reportPath, JSON.stringify(report, null, 2));
|
|
423
|
+
this.logger.info('Diagnostic report saved', { path: reportPath });
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
return report;
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
/**
|
|
430
|
+
* Collect recent logs
|
|
431
|
+
*/
|
|
432
|
+
async collectRecentLogs() {
|
|
433
|
+
// This would read from log files if file logging is enabled
|
|
434
|
+
// For now, return a placeholder
|
|
435
|
+
return {
|
|
436
|
+
message: 'Log collection would read from log files',
|
|
437
|
+
logsEnabled: process.env.LOG_TO_FILE === 'true',
|
|
438
|
+
};
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
/**
|
|
442
|
+
* Run diagnostic tests
|
|
443
|
+
*/
|
|
444
|
+
async runDiagnosticTests() {
|
|
445
|
+
const tests = [];
|
|
446
|
+
|
|
447
|
+
// Test 1: Memory allocation
|
|
448
|
+
tests.push(await this.testMemoryAllocation());
|
|
449
|
+
|
|
450
|
+
// Test 2: File system access
|
|
451
|
+
tests.push(await this.testFileSystem());
|
|
452
|
+
|
|
453
|
+
// Test 3: WASM loading
|
|
454
|
+
tests.push(await this.testWasmLoading());
|
|
455
|
+
|
|
456
|
+
return {
|
|
457
|
+
timestamp: new Date().toISOString(),
|
|
458
|
+
tests,
|
|
459
|
+
summary: {
|
|
460
|
+
total: tests.length,
|
|
461
|
+
passed: tests.filter(t => t.success).length,
|
|
462
|
+
failed: tests.filter(t => !t.success).length,
|
|
463
|
+
},
|
|
464
|
+
};
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
async testMemoryAllocation() {
|
|
468
|
+
try {
|
|
469
|
+
const start = process.memoryUsage().heapUsed;
|
|
470
|
+
const testArray = new Array(1000000).fill(0);
|
|
471
|
+
const end = process.memoryUsage().heapUsed;
|
|
472
|
+
|
|
473
|
+
return {
|
|
474
|
+
name: 'Memory Allocation',
|
|
475
|
+
success: true,
|
|
476
|
+
allocated: `${((end - start) / 1024 / 1024).toFixed(2)} MB`,
|
|
477
|
+
};
|
|
478
|
+
} catch (error) {
|
|
479
|
+
return {
|
|
480
|
+
name: 'Memory Allocation',
|
|
481
|
+
success: false,
|
|
482
|
+
error: error.message,
|
|
483
|
+
};
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
async testFileSystem() {
|
|
488
|
+
try {
|
|
489
|
+
const testPath = path.join(process.cwd(), 'logs', '.diagnostic-test');
|
|
490
|
+
fs.mkdirSync(path.dirname(testPath), { recursive: true });
|
|
491
|
+
fs.writeFileSync(testPath, 'test');
|
|
492
|
+
fs.unlinkSync(testPath);
|
|
493
|
+
|
|
494
|
+
return {
|
|
495
|
+
name: 'File System Access',
|
|
496
|
+
success: true,
|
|
497
|
+
path: testPath,
|
|
498
|
+
};
|
|
499
|
+
} catch (error) {
|
|
500
|
+
return {
|
|
501
|
+
name: 'File System Access',
|
|
502
|
+
success: false,
|
|
503
|
+
error: error.message,
|
|
504
|
+
};
|
|
505
|
+
}
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
async testWasmLoading() {
|
|
509
|
+
try {
|
|
510
|
+
// Test if WASM module can be loaded
|
|
511
|
+
const wasmPath = path.join(process.cwd(), 'wasm', 'ruv_swarm_wasm_bg.wasm');
|
|
512
|
+
const exists = fs.existsSync(wasmPath);
|
|
513
|
+
|
|
514
|
+
return {
|
|
515
|
+
name: 'WASM Module Check',
|
|
516
|
+
success: exists,
|
|
517
|
+
path: wasmPath,
|
|
518
|
+
exists,
|
|
519
|
+
};
|
|
520
|
+
} catch (error) {
|
|
521
|
+
return {
|
|
522
|
+
name: 'WASM Module Check',
|
|
523
|
+
success: false,
|
|
524
|
+
error: error.message,
|
|
525
|
+
};
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
// Singleton instance
|
|
531
|
+
export const diagnostics = new DiagnosticsManager();
|
|
532
|
+
|
|
533
|
+
export default diagnostics;
|