@monoes/monomindcli 1.10.7 → 1.10.8

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.
@@ -296,57 +296,82 @@ function _autoIndexKnowledge(knowledgeDir) {
296
296
  } catch (e) {}
297
297
  }
298
298
 
299
- // Inject monograph graph summary as a knowledge chunk
299
+ // Inject monograph graph summary as a knowledge chunk.
300
+ // Reads from .monomind/monograph.db (SQLite, source of truth) and falls
301
+ // back to the legacy .monomind/graph/{stats,graph}.json pair only when
302
+ // present (older installs).
300
303
  try {
301
- var statsPath = path.join(CWD, '.monomind', 'graph', 'stats.json');
302
- var graphPath = path.join(CWD, '.monomind', 'graph', 'graph.json');
303
- if (fs.existsSync(statsPath) && fs.existsSync(graphPath)) {
304
- var stats = JSON.parse(fs.readFileSync(statsPath, 'utf-8'));
305
- var graphStat = fs.statSync(graphPath);
306
- // Only read graph if under 10MB
307
- if (graphStat.size < 10 * 1024 * 1024) {
308
- var graph = JSON.parse(fs.readFileSync(graphPath, 'utf-8'));
309
- var rawNodes = Array.isArray(graph.nodes) ? graph.nodes : [];
310
- var rawEdges = Array.isArray(graph.edges) ? graph.edges : (Array.isArray(graph.links) ? graph.links : []);
311
- // Top 15 nodes by degree (god nodes)
312
- var degree = {};
313
- rawNodes.forEach(function(n) { degree[n.id] = 0; });
314
- rawEdges.forEach(function(e) {
315
- if (degree[e.source] !== undefined) degree[e.source]++;
316
- if (degree[e.target] !== undefined) degree[e.target]++;
317
- });
318
- var topNodes = rawNodes
319
- .filter(function(n) { return n.sourceFile && n.sourceFile !== ''; })
320
- .sort(function(a, b) { return (degree[b.id] || 0) - (degree[a.id] || 0); })
321
- .slice(0, 15);
322
- // Community summary group by type
323
- var typeCounts = {};
324
- rawNodes.forEach(function(n) { var t = n.type || n.label || 'unknown'; typeCounts[t] = (typeCounts[t] || 0) + 1; });
325
- var topTypes = Object.entries(typeCounts).sort(function(a,b){return b[1]-a[1];}).slice(0,8).map(function(e){return e[0]+':'+e[1];}).join(', ');
326
- var builtDate = stats.builtAt ? new Date(stats.builtAt).toISOString().slice(0,10) : 'unknown';
327
- var summaryText = [
328
- 'MONOGRAPH KNOWLEDGE GRAPH SUMMARY',
329
- 'Built: ' + builtDate + ' | Nodes: ' + (stats.nodes || rawNodes.length) + ' | Edges: ' + (stats.edges || rawEdges.length) + ' | Files: ' + (stats.files || 0),
330
- '',
331
- 'TOP GOD NODES (highest connectivity):',
332
- topNodes.map(function(n) {
333
- return ' ' + (n.name || n.id) + ' [' + (n.type || n.label || '?') + '] — ' + (n.sourceFile || '') + ' (degree: ' + (degree[n.id] || 0) + ')';
334
- }).join('\n'),
335
- '',
336
- 'NODE TYPE DISTRIBUTION: ' + topTypes,
337
- '',
338
- 'Use mcp__monomind__monograph_suggest to find files relevant to your task.',
339
- 'Use mcp__monomind__monograph_query to search for symbols.',
340
- 'Use mcp__monomind__monograph_god_nodes for architecture overview.',
341
- ].join('\n');
342
- var chunkId = crypto.createHash('md5').update('monograph-graph-summary').digest('hex').slice(0, 16);
343
- newLines.push(JSON.stringify({
344
- chunkId: chunkId,
345
- namespace: 'knowledge:shared',
346
- text: summaryText,
347
- metadata: { label: 'monograph-graph-summary', builtAt: stats.builtAt }
348
- }));
349
- }
304
+ var mgDbPath2 = path.join(CWD, '.monomind', 'monograph.db');
305
+ var legacyStats2 = path.join(CWD, '.monomind', 'graph', 'stats.json');
306
+ var legacyGraph2 = path.join(CWD, '.monomind', 'graph', 'graph.json');
307
+
308
+ var summaryText = null;
309
+ var summaryMeta = {};
310
+
311
+ if (fs.existsSync(mgDbPath2)) {
312
+ try {
313
+ var mgMod2 = _requireMonograph();
314
+ if (mgMod2 && mgMod2.openDb) {
315
+ var sumDb = mgMod2.openDb(mgDbPath2);
316
+ try {
317
+ var nodeC = sumDb.prepare('SELECT COUNT(*) AS c FROM nodes').get().c;
318
+ var edgeC = sumDb.prepare('SELECT COUNT(*) AS c FROM edges').get().c;
319
+ var topNodes2 = sumDb.prepare(
320
+ 'SELECT n.name, n.label, n.file_path, ' +
321
+ '(SELECT COUNT(*) FROM edges WHERE source_id=n.id OR target_id=n.id) AS deg ' +
322
+ 'FROM nodes n WHERE n.file_path IS NOT NULL AND n.file_path != "" ORDER BY deg DESC LIMIT 15'
323
+ ).all();
324
+ var typeRows = sumDb.prepare(
325
+ 'SELECT label, COUNT(*) AS c FROM nodes GROUP BY label ORDER BY c DESC LIMIT 8'
326
+ ).all();
327
+ var typeStr = typeRows.map(function(r) { return r.label + ':' + r.c; }).join(', ');
328
+ summaryText = [
329
+ 'MONOGRAPH KNOWLEDGE GRAPH SUMMARY',
330
+ 'Source: monograph.db | Nodes: ' + nodeC + ' | Edges: ' + edgeC,
331
+ '',
332
+ 'TOP GOD NODES (highest connectivity start exploration here):',
333
+ topNodes2.map(function(n) {
334
+ return ' ' + n.name + ' [' + n.label + '] — ' + (n.file_path || '') + ' (degree: ' + n.deg + ')';
335
+ }).join('\n'),
336
+ '',
337
+ 'NODE TYPE DISTRIBUTION: ' + typeStr,
338
+ '',
339
+ 'Before grepping or globbing, prefer:',
340
+ ' mcp__monomind__monograph_suggest({ task: "<your task>" }) — ranked relevant files',
341
+ ' mcp__monomind__monograph_query({ q: "<symbol|keyword>" }) BM25 search with file:line',
342
+ ' mcp__monomind__monograph_impact({ name: "<file>" }) upstream + downstream blast radius',
343
+ ].join('\n');
344
+ summaryMeta = { label: 'monograph-graph-summary', source: 'monograph.db', nodes: nodeC, edges: edgeC };
345
+ } finally {
346
+ try { sumDb.close(); } catch (_) {}
347
+ }
348
+ }
349
+ } catch (e) { /* fall through to legacy */ }
350
+ }
351
+
352
+ if (!summaryText && fs.existsSync(legacyStats2) && fs.existsSync(legacyGraph2)) {
353
+ try {
354
+ var lStats = JSON.parse(fs.readFileSync(legacyStats2, 'utf-8'));
355
+ var lGraphStat = fs.statSync(legacyGraph2);
356
+ if (lGraphStat.size < 10 * 1024 * 1024) {
357
+ var lGraph = JSON.parse(fs.readFileSync(legacyGraph2, 'utf-8'));
358
+ var lNodes = Array.isArray(lGraph.nodes) ? lGraph.nodes : [];
359
+ summaryText = 'MONOGRAPH KNOWLEDGE GRAPH SUMMARY (legacy JSON)\n' +
360
+ 'Nodes: ' + (lStats.nodes || lNodes.length) + ' | Edges: ' + (lStats.edges || 0) + '\n' +
361
+ 'Use mcp__monomind__monograph_suggest to find files relevant to your task.';
362
+ summaryMeta = { label: 'monograph-graph-summary', source: 'legacy-json', builtAt: lStats.builtAt };
363
+ }
364
+ } catch (e) { /* ignore */ }
365
+ }
366
+
367
+ if (summaryText) {
368
+ var chunkId = crypto.createHash('md5').update('monograph-graph-summary').digest('hex').slice(0, 16);
369
+ newLines.push(JSON.stringify({
370
+ chunkId: chunkId,
371
+ namespace: 'knowledge:shared',
372
+ text: summaryText,
373
+ metadata: summaryMeta
374
+ }));
350
375
  }
351
376
  } catch (e) { /* graph not available yet, skip */ }
352
377
 
@@ -639,14 +664,34 @@ const handlers = {
639
664
 
640
665
  console.log(output.join('\n'));
641
666
 
642
- // Inject monograph hint for complex tasks
667
+ // Inject monograph hint for complex tasks.
668
+ // Source of truth is .monomind/monograph.db (SQLite). Legacy stats.json
669
+ // is no longer written by the build, so it is checked only as a fallback.
643
670
  try {
644
- var graphStatsPath = path.join(CWD, '.monomind', 'graph', 'stats.json');
645
- if (fs.existsSync(graphStatsPath)) {
646
- var gStats = JSON.parse(fs.readFileSync(graphStatsPath, 'utf-8'));
647
- if (gStats.nodes > 100) {
648
- console.log('\n[MONOGRAPH] ' + gStats.nodes + ' nodes indexed. For this task, call mcp__monomind__monograph_suggest first.');
649
- }
671
+ var monographDb = path.join(CWD, '.monomind', 'monograph.db');
672
+ var legacyStats = path.join(CWD, '.monomind', 'graph', 'stats.json');
673
+ var nodeCount = 0;
674
+ if (fs.existsSync(monographDb)) {
675
+ try {
676
+ var mgMod = _requireMonograph();
677
+ if (mgMod && mgMod.openDb) {
678
+ var hintDb = mgMod.openDb(monographDb);
679
+ try {
680
+ nodeCount = hintDb.prepare('SELECT COUNT(*) AS c FROM nodes').get().c;
681
+ } finally {
682
+ try { hintDb.close(); } catch (_) {}
683
+ }
684
+ }
685
+ } catch (e) { /* ignore — fall back to legacy */ }
686
+ }
687
+ if (nodeCount === 0 && fs.existsSync(legacyStats)) {
688
+ try {
689
+ var gStats = JSON.parse(fs.readFileSync(legacyStats, 'utf-8'));
690
+ nodeCount = gStats.nodes || 0;
691
+ } catch (e) { /* ignore */ }
692
+ }
693
+ if (nodeCount > 100) {
694
+ console.log('\n[MONOGRAPH] ' + nodeCount + ' nodes indexed. For this task, call mcp__monomind__monograph_suggest first to find the right files without grepping.');
650
695
  }
651
696
  } catch(e) {}
652
697
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@monoes/monomindcli",
3
- "version": "1.10.7",
3
+ "version": "1.10.8",
4
4
  "type": "module",
5
5
  "description": "Monomind CLI - Enterprise AI agent orchestration with 60+ specialized agents, swarm coordination, MCP server, self-learning hooks, and vector memory for Claude Code",
6
6
  "main": "dist/src/index.js",