moflo 4.6.9 → 4.6.11

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.
@@ -458,12 +458,13 @@ function getHooksStatus() {
458
458
  return { enabled, total };
459
459
  }
460
460
 
461
- // AgentDB stats (pure stat calls)
461
+ // AgentDB stats queries real count from sqlite when possible, falls back to file size estimate
462
462
  function getAgentDBStats() {
463
463
  let vectorCount = 0;
464
464
  let dbSizeKB = 0;
465
465
  let namespaces = 0;
466
466
  let hasHnsw = false;
467
+ let dbPath = null;
467
468
 
468
469
  const dbFiles = [
469
470
  path.join(CWD, '.swarm', 'memory.db'),
@@ -476,31 +477,25 @@ function getAgentDBStats() {
476
477
  const stat = safeStat(f);
477
478
  if (stat) {
478
479
  dbSizeKB = stat.size / 1024;
479
- vectorCount = Math.floor(dbSizeKB / 2);
480
- namespaces = 1;
480
+ dbPath = f;
481
481
  break;
482
482
  }
483
483
  }
484
484
 
485
- if (vectorCount === 0) {
486
- const dbDirs = [
487
- path.join(CWD, '.claude-flow', 'agentdb'),
488
- path.join(CWD, '.swarm', 'agentdb'),
489
- path.join(CWD, '.agentdb'),
490
- ];
491
- for (const dir of dbDirs) {
485
+ // Try to get real count from sqlite (fast single COUNT query)
486
+ if (dbPath) {
487
+ const countOutput = safeExec(`node -e "const S=require('sql.js');const f=require('fs');S().then(Q=>{const d=new Q.Database(f.readFileSync('${dbPath.replace(/\\/g, '/')}'));const s=d.prepare('SELECT COUNT(*) as c FROM memory_entries WHERE status=\\"active\\" AND embedding IS NOT NULL');s.step();console.log(JSON.stringify(s.getAsObject()));s.free();const n=d.prepare('SELECT COUNT(DISTINCT namespace) as n FROM memory_entries WHERE status=\\"active\\"');n.step();console.log(JSON.stringify(n.getAsObject()));n.free();d.close();})"`, 3000);
488
+ if (countOutput) {
492
489
  try {
493
- if (fs.existsSync(dir) && fs.statSync(dir).isDirectory()) {
494
- const files = fs.readdirSync(dir);
495
- namespaces = files.filter(f => f.endsWith('.db') || f.endsWith('.sqlite')).length;
496
- for (const file of files) {
497
- const stat = safeStat(path.join(dir, file));
498
- if (stat?.isFile()) dbSizeKB += stat.size / 1024;
499
- }
500
- vectorCount = Math.floor(dbSizeKB / 2);
501
- break;
502
- }
503
- } catch { /* ignore */ }
490
+ const lines = countOutput.trim().split('\n');
491
+ vectorCount = JSON.parse(lines[0]).c || 0;
492
+ namespaces = lines[1] ? JSON.parse(lines[1]).n || 0 : 0;
493
+ } catch { /* fall back to estimate */ }
494
+ }
495
+ // Fallback to file size estimate if query failed
496
+ if (vectorCount === 0) {
497
+ vectorCount = Math.floor(dbSizeKB / 2);
498
+ namespaces = 1;
504
499
  }
505
500
  }
506
501
 
@@ -509,10 +504,8 @@ function getAgentDBStats() {
509
504
  path.join(CWD, '.claude-flow', 'hnsw.index'),
510
505
  ];
511
506
  for (const p of hnswPaths) {
512
- const stat = safeStat(p);
513
- if (stat) {
507
+ if (safeStat(p)) {
514
508
  hasHnsw = true;
515
- vectorCount = Math.max(vectorCount, Math.floor(stat.size / 512));
516
509
  break;
517
510
  }
518
511
  }