moflo 4.7.8 → 4.8.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 (77) hide show
  1. package/.claude/settings.local.json +4 -1
  2. package/.claude/workflow-state.json +3 -7
  3. package/README.md +3 -1
  4. package/bin/build-embeddings.mjs +59 -3
  5. package/bin/generate-code-map.mjs +3 -1
  6. package/bin/hooks.mjs +23 -20
  7. package/bin/index-guidance.mjs +3 -1
  8. package/bin/lib/moflo-resolve.mjs +14 -0
  9. package/bin/semantic-search.mjs +10 -5
  10. package/bin/session-start-launcher.mjs +116 -3
  11. package/package.json +6 -6
  12. package/src/@claude-flow/cli/dist/src/appliance/ruvllm-bridge.js +3 -7
  13. package/src/@claude-flow/cli/dist/src/commands/daemon.js +42 -95
  14. package/src/@claude-flow/cli/dist/src/commands/doctor.js +127 -6
  15. package/src/@claude-flow/cli/dist/src/commands/embeddings.js +4 -3
  16. package/src/@claude-flow/cli/dist/src/commands/hooks.js +3 -2
  17. package/src/@claude-flow/cli/dist/src/commands/mcp.js +38 -22
  18. package/src/@claude-flow/cli/dist/src/commands/memory.js +2 -1
  19. package/src/@claude-flow/cli/dist/src/commands/neural.js +10 -5
  20. package/src/@claude-flow/cli/dist/src/config/moflo-config.d.ts +5 -0
  21. package/src/@claude-flow/cli/dist/src/config/moflo-config.js +16 -0
  22. package/src/@claude-flow/cli/dist/src/index.js +12 -0
  23. package/src/@claude-flow/cli/dist/src/init/executor.js +74 -0
  24. package/src/@claude-flow/cli/dist/src/init/moflo-init.js +49 -0
  25. package/src/@claude-flow/cli/dist/src/mcp-tools/memory-tools.js +2 -2
  26. package/src/@claude-flow/cli/dist/src/mcp-tools/neural-tools.js +2 -1
  27. package/src/@claude-flow/cli/dist/src/memory/memory-bridge.js +5 -1
  28. package/src/@claude-flow/cli/dist/src/memory/memory-initializer.js +29 -24
  29. package/src/@claude-flow/cli/dist/src/ruvector/ast-analyzer.js +2 -1
  30. package/src/@claude-flow/cli/dist/src/ruvector/coverage-router.js +2 -1
  31. package/src/@claude-flow/cli/dist/src/ruvector/diff-classifier.js +2 -1
  32. package/src/@claude-flow/cli/dist/src/ruvector/enhanced-model-router.js +3 -3
  33. package/src/@claude-flow/cli/dist/src/ruvector/index.js +6 -13
  34. package/src/@claude-flow/cli/dist/src/ruvector/q-learning-router.js +4 -1
  35. package/src/@claude-flow/cli/dist/src/services/daemon-lock.d.ts +39 -0
  36. package/src/@claude-flow/cli/dist/src/services/daemon-lock.js +213 -0
  37. package/src/@claude-flow/cli/dist/src/services/learning-service.js +2 -1
  38. package/src/@claude-flow/cli/dist/src/services/moflo-require.d.ts +34 -0
  39. package/src/@claude-flow/cli/dist/src/services/moflo-require.js +67 -0
  40. package/src/@claude-flow/cli/dist/src/services/ruvector-training.js +8 -6
  41. package/src/@claude-flow/cli/package.json +6 -6
  42. package/.claude/helpers/README.md +0 -97
  43. package/.claude/helpers/adr-compliance.sh +0 -186
  44. package/.claude/helpers/aggressive-microcompact.mjs +0 -36
  45. package/.claude/helpers/auto-commit.sh +0 -178
  46. package/.claude/helpers/checkpoint-manager.sh +0 -251
  47. package/.claude/helpers/context-persistence-hook.mjs +0 -1979
  48. package/.claude/helpers/daemon-manager.sh +0 -252
  49. package/.claude/helpers/ddd-tracker.sh +0 -144
  50. package/.claude/helpers/github-safe.js +0 -106
  51. package/.claude/helpers/github-setup.sh +0 -28
  52. package/.claude/helpers/guidance-hook.sh +0 -13
  53. package/.claude/helpers/guidance-hooks.sh +0 -102
  54. package/.claude/helpers/health-monitor.sh +0 -108
  55. package/.claude/helpers/learning-hooks.sh +0 -329
  56. package/.claude/helpers/learning-optimizer.sh +0 -127
  57. package/.claude/helpers/learning-service.mjs +0 -1211
  58. package/.claude/helpers/memory.cjs +0 -84
  59. package/.claude/helpers/metrics-db.mjs +0 -492
  60. package/.claude/helpers/patch-aggressive-prune.mjs +0 -184
  61. package/.claude/helpers/pattern-consolidator.sh +0 -86
  62. package/.claude/helpers/perf-worker.sh +0 -160
  63. package/.claude/helpers/quick-start.sh +0 -19
  64. package/.claude/helpers/router.cjs +0 -62
  65. package/.claude/helpers/security-scanner.sh +0 -127
  66. package/.claude/helpers/session.cjs +0 -125
  67. package/.claude/helpers/setup-mcp.sh +0 -18
  68. package/.claude/helpers/standard-checkpoint-hooks.sh +0 -189
  69. package/.claude/helpers/swarm-comms.sh +0 -353
  70. package/.claude/helpers/swarm-hooks.sh +0 -761
  71. package/.claude/helpers/swarm-monitor.sh +0 -211
  72. package/.claude/helpers/sync-v3-metrics.sh +0 -245
  73. package/.claude/helpers/update-v3-progress.sh +0 -166
  74. package/.claude/helpers/v3-quick-status.sh +0 -58
  75. package/.claude/helpers/v3.sh +0 -111
  76. package/.claude/helpers/validate-v3-config.sh +0 -216
  77. package/.claude/helpers/worker-manager.sh +0 -170
@@ -1,84 +0,0 @@
1
- #!/usr/bin/env node
2
- /**
3
- * Claude Flow Memory Helper
4
- * Simple key-value memory for cross-session context
5
- */
6
-
7
- const fs = require('fs');
8
- const path = require('path');
9
-
10
- const MEMORY_DIR = path.join(process.cwd(), '.claude-flow', 'data');
11
- const MEMORY_FILE = path.join(MEMORY_DIR, 'memory.json');
12
-
13
- function loadMemory() {
14
- try {
15
- if (fs.existsSync(MEMORY_FILE)) {
16
- return JSON.parse(fs.readFileSync(MEMORY_FILE, 'utf-8'));
17
- }
18
- } catch (e) {
19
- // Ignore
20
- }
21
- return {};
22
- }
23
-
24
- function saveMemory(memory) {
25
- fs.mkdirSync(MEMORY_DIR, { recursive: true });
26
- fs.writeFileSync(MEMORY_FILE, JSON.stringify(memory, null, 2));
27
- }
28
-
29
- const commands = {
30
- get: (key) => {
31
- const memory = loadMemory();
32
- const value = key ? memory[key] : memory;
33
- console.log(JSON.stringify(value, null, 2));
34
- return value;
35
- },
36
-
37
- set: (key, value) => {
38
- if (!key) {
39
- console.error('Key required');
40
- return;
41
- }
42
- const memory = loadMemory();
43
- memory[key] = value;
44
- memory._updated = new Date().toISOString();
45
- saveMemory(memory);
46
- console.log(`Set: ${key}`);
47
- },
48
-
49
- delete: (key) => {
50
- if (!key) {
51
- console.error('Key required');
52
- return;
53
- }
54
- const memory = loadMemory();
55
- delete memory[key];
56
- saveMemory(memory);
57
- console.log(`Deleted: ${key}`);
58
- },
59
-
60
- clear: () => {
61
- saveMemory({});
62
- console.log('Memory cleared');
63
- },
64
-
65
- keys: () => {
66
- const memory = loadMemory();
67
- const keys = Object.keys(memory).filter(k => !k.startsWith('_'));
68
- console.log(keys.join('\n'));
69
- return keys;
70
- },
71
- };
72
-
73
- module.exports = commands;
74
-
75
- // CLI - only run when executed directly
76
- if (require.main === module) {
77
- const [,, command, key, ...valueParts] = process.argv;
78
- const value = valueParts.join(' ');
79
- if (command && commands[command]) {
80
- commands[command](key, value);
81
- } else {
82
- console.log('Usage: memory.js <get|set|delete|clear|keys> [key] [value]');
83
- }
84
- }
@@ -1,492 +0,0 @@
1
- #!/usr/bin/env node
2
- /**
3
- * RuFlo V3 - Metrics Database Manager
4
- * Uses sql.js for cross-platform SQLite storage
5
- * Single .db file with multiple tables
6
- */
7
-
8
- import initSqlJs from 'sql.js';
9
- import { readFileSync, writeFileSync, existsSync, mkdirSync, readdirSync, statSync } from 'fs';
10
- import { dirname, join, basename } from 'path';
11
- import { fileURLToPath } from 'url';
12
- import { execSync } from 'child_process';
13
-
14
- const __dirname = dirname(fileURLToPath(import.meta.url));
15
- const PROJECT_ROOT = join(__dirname, '../..');
16
- const V3_DIR = join(PROJECT_ROOT, 'v3');
17
- const DB_PATH = join(PROJECT_ROOT, '.claude-flow', 'metrics.db');
18
-
19
- // Ensure directory exists
20
- const dbDir = dirname(DB_PATH);
21
- if (!existsSync(dbDir)) {
22
- mkdirSync(dbDir, { recursive: true });
23
- }
24
-
25
- let SQL;
26
- let db;
27
-
28
- /**
29
- * Initialize sql.js and create/load database
30
- */
31
- async function initDatabase() {
32
- SQL = await initSqlJs();
33
-
34
- // Load existing database or create new one
35
- if (existsSync(DB_PATH)) {
36
- const buffer = readFileSync(DB_PATH);
37
- db = new SQL.Database(buffer);
38
- } else {
39
- db = new SQL.Database();
40
- }
41
-
42
- // Create tables if they don't exist
43
- db.run(`
44
- CREATE TABLE IF NOT EXISTS v3_progress (
45
- id INTEGER PRIMARY KEY,
46
- domains_completed INTEGER DEFAULT 0,
47
- domains_total INTEGER DEFAULT 5,
48
- ddd_progress INTEGER DEFAULT 0,
49
- total_modules INTEGER DEFAULT 0,
50
- total_files INTEGER DEFAULT 0,
51
- total_lines INTEGER DEFAULT 0,
52
- last_updated TEXT
53
- );
54
-
55
- CREATE TABLE IF NOT EXISTS security_audit (
56
- id INTEGER PRIMARY KEY,
57
- status TEXT DEFAULT 'PENDING',
58
- cves_fixed INTEGER DEFAULT 0,
59
- total_cves INTEGER DEFAULT 3,
60
- last_audit TEXT
61
- );
62
-
63
- CREATE TABLE IF NOT EXISTS swarm_activity (
64
- id INTEGER PRIMARY KEY,
65
- agentic_flow_processes INTEGER DEFAULT 0,
66
- mcp_server_processes INTEGER DEFAULT 0,
67
- estimated_agents INTEGER DEFAULT 0,
68
- swarm_active INTEGER DEFAULT 0,
69
- coordination_active INTEGER DEFAULT 0,
70
- last_updated TEXT
71
- );
72
-
73
- CREATE TABLE IF NOT EXISTS performance_metrics (
74
- id INTEGER PRIMARY KEY,
75
- flash_attention_speedup TEXT DEFAULT '1.0x',
76
- memory_reduction TEXT DEFAULT '0%',
77
- search_improvement TEXT DEFAULT '1x',
78
- last_updated TEXT
79
- );
80
-
81
- CREATE TABLE IF NOT EXISTS module_status (
82
- name TEXT PRIMARY KEY,
83
- files INTEGER DEFAULT 0,
84
- lines INTEGER DEFAULT 0,
85
- progress INTEGER DEFAULT 0,
86
- has_src INTEGER DEFAULT 0,
87
- has_tests INTEGER DEFAULT 0,
88
- last_updated TEXT
89
- );
90
-
91
- CREATE TABLE IF NOT EXISTS cve_status (
92
- id TEXT PRIMARY KEY,
93
- description TEXT,
94
- severity TEXT DEFAULT 'critical',
95
- status TEXT DEFAULT 'pending',
96
- fixed_by TEXT,
97
- last_updated TEXT
98
- );
99
- `);
100
-
101
- // Initialize rows if empty
102
- const progressCheck = db.exec("SELECT COUNT(*) FROM v3_progress");
103
- if (progressCheck[0]?.values[0][0] === 0) {
104
- db.run("INSERT INTO v3_progress (id) VALUES (1)");
105
- }
106
-
107
- const securityCheck = db.exec("SELECT COUNT(*) FROM security_audit");
108
- if (securityCheck[0]?.values[0][0] === 0) {
109
- db.run("INSERT INTO security_audit (id) VALUES (1)");
110
- }
111
-
112
- const swarmCheck = db.exec("SELECT COUNT(*) FROM swarm_activity");
113
- if (swarmCheck[0]?.values[0][0] === 0) {
114
- db.run("INSERT INTO swarm_activity (id) VALUES (1)");
115
- }
116
-
117
- const perfCheck = db.exec("SELECT COUNT(*) FROM performance_metrics");
118
- if (perfCheck[0]?.values[0][0] === 0) {
119
- db.run("INSERT INTO performance_metrics (id) VALUES (1)");
120
- }
121
-
122
- // Initialize CVE records
123
- const cveCheck = db.exec("SELECT COUNT(*) FROM cve_status");
124
- if (cveCheck[0]?.values[0][0] === 0) {
125
- db.run(`INSERT INTO cve_status (id, description, fixed_by) VALUES
126
- ('CVE-1', 'Input validation bypass', 'input-validator.ts'),
127
- ('CVE-2', 'Path traversal vulnerability', 'path-validator.ts'),
128
- ('CVE-3', 'Command injection vulnerability', 'safe-executor.ts')
129
- `);
130
- }
131
-
132
- persist();
133
- }
134
-
135
- /**
136
- * Persist database to disk
137
- */
138
- function persist() {
139
- const data = db.export();
140
- const buffer = Buffer.from(data);
141
- writeFileSync(DB_PATH, buffer);
142
- }
143
-
144
- /**
145
- * Count files and lines in a directory
146
- */
147
- function countFilesAndLines(dir, ext = '.ts') {
148
- let files = 0;
149
- let lines = 0;
150
-
151
- function walk(currentDir) {
152
- if (!existsSync(currentDir)) return;
153
-
154
- try {
155
- const entries = readdirSync(currentDir, { withFileTypes: true });
156
- for (const entry of entries) {
157
- const fullPath = join(currentDir, entry.name);
158
- if (entry.isDirectory() && !entry.name.includes('node_modules')) {
159
- walk(fullPath);
160
- } else if (entry.isFile() && entry.name.endsWith(ext)) {
161
- files++;
162
- try {
163
- const content = readFileSync(fullPath, 'utf-8');
164
- lines += content.split('\n').length;
165
- } catch (e) {}
166
- }
167
- }
168
- } catch (e) {}
169
- }
170
-
171
- walk(dir);
172
- return { files, lines };
173
- }
174
-
175
- /**
176
- * Calculate module progress
177
- * Utility/service packages (cli, hooks, mcp, etc.) are considered complete (100%)
178
- * as their services ARE the application layer (DDD by design)
179
- */
180
- const UTILITY_PACKAGES = new Set([
181
- 'cli', 'hooks', 'mcp', 'shared', 'testing', 'agents', 'integration',
182
- 'embeddings', 'deployment', 'performance', 'plugins', 'providers'
183
- ]);
184
-
185
- function calculateModuleProgress(moduleDir) {
186
- if (!existsSync(moduleDir)) return 0;
187
-
188
- const moduleName = basename(moduleDir);
189
-
190
- // Utility packages are 100% complete by design
191
- if (UTILITY_PACKAGES.has(moduleName)) {
192
- return 100;
193
- }
194
-
195
- let progress = 0;
196
-
197
- // Check for DDD structure
198
- if (existsSync(join(moduleDir, 'src/domain'))) progress += 30;
199
- if (existsSync(join(moduleDir, 'src/application'))) progress += 30;
200
- if (existsSync(join(moduleDir, 'src'))) progress += 10;
201
- if (existsSync(join(moduleDir, 'src/index.ts')) || existsSync(join(moduleDir, 'index.ts'))) progress += 10;
202
- if (existsSync(join(moduleDir, '__tests__')) || existsSync(join(moduleDir, 'tests'))) progress += 10;
203
- if (existsSync(join(moduleDir, 'package.json'))) progress += 10;
204
-
205
- return Math.min(progress, 100);
206
- }
207
-
208
- /**
209
- * Check security file status
210
- */
211
- function checkSecurityFile(filename, minLines = 100) {
212
- const filePath = join(V3_DIR, '@claude-flow/security/src', filename);
213
- if (!existsSync(filePath)) return false;
214
-
215
- try {
216
- const content = readFileSync(filePath, 'utf-8');
217
- return content.split('\n').length > minLines;
218
- } catch (e) {
219
- return false;
220
- }
221
- }
222
-
223
- /**
224
- * Count active processes
225
- */
226
- function countProcesses() {
227
- try {
228
- const isWin = process.platform === 'win32';
229
- const cmd = isWin
230
- ? 'tasklist.exe /FO CSV /NH 2>NUL'
231
- : 'ps aux 2>/dev/null || echo ""';
232
- const ps = execSync(cmd, { encoding: 'utf-8', timeout: 3000, windowsHide: true });
233
-
234
- const agenticFlow = (ps.match(/agentic-flow/g) || []).length;
235
- const mcp = (ps.match(/mcp.*start/g) || []).length;
236
- const agents = (ps.match(/agent|swarm|coordinator/g) || []).length;
237
-
238
- return {
239
- agenticFlow: Math.max(0, agenticFlow - 1),
240
- mcp,
241
- agents: Math.max(0, agents - 1)
242
- };
243
- } catch (e) {
244
- return { agenticFlow: 0, mcp: 0, agents: 0 };
245
- }
246
- }
247
-
248
- /**
249
- * Sync all metrics from actual implementation
250
- */
251
- async function syncMetrics() {
252
- const now = new Date().toISOString();
253
-
254
- // Count V3 modules
255
- const modulesDir = join(V3_DIR, '@claude-flow');
256
- let modules = [];
257
- let totalProgress = 0;
258
-
259
- if (existsSync(modulesDir)) {
260
- const entries = readdirSync(modulesDir, { withFileTypes: true });
261
- for (const entry of entries) {
262
- // Skip hidden directories (like .agentic-flow, .claude-flow)
263
- if (entry.isDirectory() && !entry.name.startsWith('.')) {
264
- const moduleDir = join(modulesDir, entry.name);
265
- const { files, lines } = countFilesAndLines(moduleDir);
266
- const progress = calculateModuleProgress(moduleDir);
267
-
268
- modules.push({ name: entry.name, files, lines, progress });
269
- totalProgress += progress;
270
-
271
- // Update module_status table
272
- db.run(`
273
- INSERT OR REPLACE INTO module_status (name, files, lines, progress, has_src, has_tests, last_updated)
274
- VALUES (?, ?, ?, ?, ?, ?, ?)
275
- `, [
276
- entry.name,
277
- files,
278
- lines,
279
- progress,
280
- existsSync(join(moduleDir, 'src')) ? 1 : 0,
281
- existsSync(join(moduleDir, '__tests__')) ? 1 : 0,
282
- now
283
- ]);
284
- }
285
- }
286
- }
287
-
288
- const avgProgress = modules.length > 0 ? Math.round(totalProgress / modules.length) : 0;
289
- const totalStats = countFilesAndLines(V3_DIR);
290
-
291
- // Count completed domains (mapped to modules)
292
- const domainModules = ['swarm', 'memory', 'performance', 'cli', 'integration'];
293
- const domainsCompleted = domainModules.filter(m =>
294
- modules.some(mod => mod.name === m && mod.progress >= 50)
295
- ).length;
296
-
297
- // Update v3_progress
298
- db.run(`
299
- UPDATE v3_progress SET
300
- domains_completed = ?,
301
- ddd_progress = ?,
302
- total_modules = ?,
303
- total_files = ?,
304
- total_lines = ?,
305
- last_updated = ?
306
- WHERE id = 1
307
- `, [domainsCompleted, avgProgress, modules.length, totalStats.files, totalStats.lines, now]);
308
-
309
- // Check security CVEs
310
- const cve1Fixed = checkSecurityFile('input-validator.ts');
311
- const cve2Fixed = checkSecurityFile('path-validator.ts');
312
- const cve3Fixed = checkSecurityFile('safe-executor.ts');
313
- const cvesFixed = [cve1Fixed, cve2Fixed, cve3Fixed].filter(Boolean).length;
314
-
315
- let securityStatus = 'PENDING';
316
- if (cvesFixed === 3) securityStatus = 'CLEAN';
317
- else if (cvesFixed > 0) securityStatus = 'IN_PROGRESS';
318
-
319
- db.run(`
320
- UPDATE security_audit SET
321
- status = ?,
322
- cves_fixed = ?,
323
- last_audit = ?
324
- WHERE id = 1
325
- `, [securityStatus, cvesFixed, now]);
326
-
327
- // Update individual CVE status
328
- db.run("UPDATE cve_status SET status = ?, last_updated = ? WHERE id = 'CVE-1'", [cve1Fixed ? 'fixed' : 'pending', now]);
329
- db.run("UPDATE cve_status SET status = ?, last_updated = ? WHERE id = 'CVE-2'", [cve2Fixed ? 'fixed' : 'pending', now]);
330
- db.run("UPDATE cve_status SET status = ?, last_updated = ? WHERE id = 'CVE-3'", [cve3Fixed ? 'fixed' : 'pending', now]);
331
-
332
- // Update swarm activity
333
- const processes = countProcesses();
334
- db.run(`
335
- UPDATE swarm_activity SET
336
- agentic_flow_processes = ?,
337
- mcp_server_processes = ?,
338
- estimated_agents = ?,
339
- swarm_active = ?,
340
- coordination_active = ?,
341
- last_updated = ?
342
- WHERE id = 1
343
- `, [
344
- processes.agenticFlow,
345
- processes.mcp,
346
- processes.agents,
347
- processes.agents > 0 ? 1 : 0,
348
- processes.agenticFlow > 0 ? 1 : 0,
349
- now
350
- ]);
351
-
352
- persist();
353
-
354
- return {
355
- modules: modules.length,
356
- domains: domainsCompleted,
357
- dddProgress: avgProgress,
358
- cvesFixed,
359
- securityStatus,
360
- files: totalStats.files,
361
- lines: totalStats.lines
362
- };
363
- }
364
-
365
- /**
366
- * Get current metrics as JSON (for statusline compatibility)
367
- */
368
- function getMetricsJSON() {
369
- const progress = db.exec("SELECT * FROM v3_progress WHERE id = 1")[0];
370
- const security = db.exec("SELECT * FROM security_audit WHERE id = 1")[0];
371
- const swarm = db.exec("SELECT * FROM swarm_activity WHERE id = 1")[0];
372
- const perf = db.exec("SELECT * FROM performance_metrics WHERE id = 1")[0];
373
-
374
- // Map column names to values
375
- const mapRow = (result) => {
376
- if (!result) return {};
377
- const cols = result.columns;
378
- const vals = result.values[0];
379
- return Object.fromEntries(cols.map((c, i) => [c, vals[i]]));
380
- };
381
-
382
- return {
383
- v3Progress: mapRow(progress),
384
- securityAudit: mapRow(security),
385
- swarmActivity: mapRow(swarm),
386
- performanceMetrics: mapRow(perf)
387
- };
388
- }
389
-
390
- /**
391
- * Export metrics to JSON files for backward compatibility
392
- */
393
- function exportToJSON() {
394
- const metrics = getMetricsJSON();
395
- const metricsDir = join(PROJECT_ROOT, '.claude-flow/metrics');
396
- const securityDir = join(PROJECT_ROOT, '.claude-flow/security');
397
-
398
- if (!existsSync(metricsDir)) mkdirSync(metricsDir, { recursive: true });
399
- if (!existsSync(securityDir)) mkdirSync(securityDir, { recursive: true });
400
-
401
- // v3-progress.json
402
- writeFileSync(join(metricsDir, 'v3-progress.json'), JSON.stringify({
403
- domains: {
404
- completed: metrics.v3Progress.domains_completed,
405
- total: metrics.v3Progress.domains_total
406
- },
407
- ddd: {
408
- progress: metrics.v3Progress.ddd_progress,
409
- modules: metrics.v3Progress.total_modules,
410
- totalFiles: metrics.v3Progress.total_files,
411
- totalLines: metrics.v3Progress.total_lines
412
- },
413
- swarm: {
414
- activeAgents: metrics.swarmActivity.estimated_agents,
415
- totalAgents: 15
416
- },
417
- lastUpdated: metrics.v3Progress.last_updated,
418
- source: 'metrics.db'
419
- }, null, 2));
420
-
421
- // security/audit-status.json
422
- writeFileSync(join(securityDir, 'audit-status.json'), JSON.stringify({
423
- status: metrics.securityAudit.status,
424
- cvesFixed: metrics.securityAudit.cves_fixed,
425
- totalCves: metrics.securityAudit.total_cves,
426
- lastAudit: metrics.securityAudit.last_audit,
427
- source: 'metrics.db'
428
- }, null, 2));
429
-
430
- // swarm-activity.json
431
- writeFileSync(join(metricsDir, 'swarm-activity.json'), JSON.stringify({
432
- timestamp: metrics.swarmActivity.last_updated,
433
- processes: {
434
- agentic_flow: metrics.swarmActivity.agentic_flow_processes,
435
- mcp_server: metrics.swarmActivity.mcp_server_processes,
436
- estimated_agents: metrics.swarmActivity.estimated_agents
437
- },
438
- swarm: {
439
- active: metrics.swarmActivity.swarm_active === 1,
440
- agent_count: metrics.swarmActivity.estimated_agents,
441
- coordination_active: metrics.swarmActivity.coordination_active === 1
442
- },
443
- source: 'metrics.db'
444
- }, null, 2));
445
- }
446
-
447
- /**
448
- * Main entry point
449
- */
450
- async function main() {
451
- const command = process.argv[2] || 'sync';
452
-
453
- await initDatabase();
454
-
455
- switch (command) {
456
- case 'sync':
457
- const result = await syncMetrics();
458
- exportToJSON();
459
- console.log(JSON.stringify(result));
460
- break;
461
-
462
- case 'export':
463
- exportToJSON();
464
- console.log('Exported to JSON files');
465
- break;
466
-
467
- case 'status':
468
- const metrics = getMetricsJSON();
469
- console.log(JSON.stringify(metrics, null, 2));
470
- break;
471
-
472
- case 'daemon':
473
- const interval = parseInt(process.argv[3]) || 30;
474
- console.log(`Starting metrics daemon (interval: ${interval}s)`);
475
-
476
- // Initial sync
477
- await syncMetrics();
478
- exportToJSON();
479
-
480
- // Continuous sync
481
- setInterval(async () => {
482
- await syncMetrics();
483
- exportToJSON();
484
- }, interval * 1000);
485
- break;
486
-
487
- default:
488
- console.log('Usage: metrics-db.mjs [sync|export|status|daemon [interval]]');
489
- }
490
- }
491
-
492
- main().catch(console.error);