@softerist/heuristic-mcp 2.1.2 → 2.1.3
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 +21 -9
- package/features/index-codebase.js +34 -6
- package/lib/cache.js +47 -6
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -86,14 +86,33 @@ Since it runs the **Local LLM** (Xenova) directly on your machine:
|
|
|
86
86
|
|
|
87
87
|
For a developer (or an AI agent) working on a confusing or large project, this tool is a massive productivity booster. It essentially turns the entire codebase into a searchable database of knowledge.
|
|
88
88
|
|
|
89
|
-
|
|
89
|
+
## How This is Different
|
|
90
|
+
|
|
91
|
+
Most MCP servers and RAG tools are "naive"—they just embed code chunks and run a vector search. **Heuristic MCP** is different because it adds **deterministic intelligence** on top of AI:
|
|
92
|
+
|
|
93
|
+
| Feature | Generic MCP / RAG Tool | Heuristic MCP |
|
|
94
|
+
| :- | :- | :- |
|
|
95
|
+
| **Ranking** | Pure similarity score | Similarity + **Call Graph Proximity** + **Recency Boost** |
|
|
96
|
+
| **Logic** | "Is this text similar?" | "Is this similar, AND used by this function, AND active?" |
|
|
97
|
+
| **Refactoring** | N/A | **`find_similar_code`** tool to detect duplicates |
|
|
98
|
+
| **Tuning** | Static (hardcoded) | **Runtime Config** (adjust ANN parameters on the fly) |
|
|
99
|
+
|
|
100
|
+
### Comparison to Cursor
|
|
101
|
+
|
|
102
|
+
[Cursor](https://cursor.sh) is an excellent AI editor with built-in codebase indexing.
|
|
103
|
+
|
|
104
|
+
- **Cursor** is an *Editor*: You must use their IDE to get the features.
|
|
105
|
+
- **Heuristic MCP** is a *Protocol*: It brings Cursor-like intelligence to **any** tool (Claude Desktop, multiple IDEs, agentic workflows) without locking you into a specific editor.
|
|
106
|
+
- **Transparency**: This is open-source. You know exactly how your code is indexed and where the data lives (locally).
|
|
107
|
+
|
|
108
|
+
## Performance
|
|
90
109
|
|
|
91
110
|
- Pre-indexed embeddings are faster than scanning files at runtime
|
|
92
111
|
- Smart project detection skips dependencies automatically (node_modules, vendor, etc.)
|
|
93
112
|
- Incremental updates - only re-processes changed files
|
|
94
113
|
- Optional ANN search (HNSW) for faster queries on large codebases
|
|
95
114
|
|
|
96
|
-
|
|
115
|
+
## Privacy
|
|
97
116
|
|
|
98
117
|
- Everything runs locally on your machine
|
|
99
118
|
- Your code never leaves your system
|
|
@@ -269,13 +288,6 @@ Query: "error handling and exceptions"
|
|
|
269
288
|
|
|
270
289
|
Finds all try/catch blocks and error handling patterns.
|
|
271
290
|
|
|
272
|
-
## Privacy
|
|
273
|
-
|
|
274
|
-
- AI model runs entirely on your machine
|
|
275
|
-
- No network requests to external services
|
|
276
|
-
- No telemetry or analytics
|
|
277
|
-
- Cache stored locally in `.smart-coding-cache/`
|
|
278
|
-
|
|
279
291
|
## Technical Details
|
|
280
292
|
|
|
281
293
|
**Embedding Model**: all-MiniLM-L6-v2 via transformers.js
|
|
@@ -503,6 +503,7 @@ export class CodebaseIndexer {
|
|
|
503
503
|
console.error("[Indexer] Force reindex requested: clearing cache");
|
|
504
504
|
this.cache.setVectorStore([]);
|
|
505
505
|
this.cache.fileHashes = new Map();
|
|
506
|
+
await this.cache.clearCallGraphData({ removeFile: true });
|
|
506
507
|
}
|
|
507
508
|
|
|
508
509
|
const totalStartTime = Date.now();
|
|
@@ -520,9 +521,10 @@ export class CodebaseIndexer {
|
|
|
520
521
|
// Send progress: discovery complete
|
|
521
522
|
this.sendProgress(5, 100, `Discovered ${files.length} files`);
|
|
522
523
|
|
|
524
|
+
const currentFilesSet = new Set(files);
|
|
525
|
+
|
|
523
526
|
// Step 1.5: Prune deleted or excluded files from cache
|
|
524
527
|
if (!force) {
|
|
525
|
-
const currentFilesSet = new Set(files);
|
|
526
528
|
const cachedFiles = Array.from(this.cache.fileHashes.keys());
|
|
527
529
|
let prunedCount = 0;
|
|
528
530
|
|
|
@@ -540,10 +542,16 @@ export class CodebaseIndexer {
|
|
|
540
542
|
}
|
|
541
543
|
// If we pruned files, we should save these changes even if no other files changed
|
|
542
544
|
}
|
|
545
|
+
|
|
546
|
+
const prunedCallGraph = this.cache.pruneCallGraphData(currentFilesSet);
|
|
547
|
+
if (prunedCallGraph > 0 && this.config.verbose) {
|
|
548
|
+
console.error(`[Indexer] Pruned ${prunedCallGraph} call-graph entries`);
|
|
549
|
+
}
|
|
543
550
|
}
|
|
544
551
|
|
|
545
552
|
// Step 2: Pre-filter unchanged files (early hash check)
|
|
546
553
|
const filesToProcess = await this.preFilterFiles(files);
|
|
554
|
+
const filesToProcessSet = new Set(filesToProcess.map(entry => entry.file));
|
|
547
555
|
|
|
548
556
|
if (filesToProcess.length === 0) {
|
|
549
557
|
console.error("[Indexer] All files unchanged, nothing to index");
|
|
@@ -556,17 +564,37 @@ export class CodebaseIndexer {
|
|
|
556
564
|
|
|
557
565
|
const missingCallData = [];
|
|
558
566
|
for (const file of cachedFiles) {
|
|
559
|
-
if (!callDataFiles.has(file)) {
|
|
567
|
+
if (!callDataFiles.has(file) && currentFilesSet.has(file)) {
|
|
560
568
|
missingCallData.push(file);
|
|
561
569
|
}
|
|
562
570
|
}
|
|
563
571
|
|
|
564
572
|
if (missingCallData.length > 0) {
|
|
565
573
|
console.error(`[Indexer] Found ${missingCallData.length} files missing call graph data, re-indexing...`);
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
574
|
+
const BATCH_SIZE = 100;
|
|
575
|
+
for (let i = 0; i < missingCallData.length; i += BATCH_SIZE) {
|
|
576
|
+
const batch = missingCallData.slice(i, i + BATCH_SIZE);
|
|
577
|
+
const results = await Promise.all(
|
|
578
|
+
batch.map(async (file) => {
|
|
579
|
+
try {
|
|
580
|
+
const stats = await fs.stat(file);
|
|
581
|
+
if (stats.isDirectory()) return null;
|
|
582
|
+
if (stats.size > this.config.maxFileSize) return null;
|
|
583
|
+
const content = await fs.readFile(file, "utf-8");
|
|
584
|
+
const hash = hashContent(content);
|
|
585
|
+
return { file, content, hash };
|
|
586
|
+
} catch {
|
|
587
|
+
return null;
|
|
588
|
+
}
|
|
589
|
+
})
|
|
590
|
+
);
|
|
591
|
+
|
|
592
|
+
for (const result of results) {
|
|
593
|
+
if (!result) continue;
|
|
594
|
+
if (filesToProcessSet.has(result.file)) continue;
|
|
595
|
+
filesToProcess.push(result);
|
|
596
|
+
filesToProcessSet.add(result.file);
|
|
597
|
+
}
|
|
570
598
|
}
|
|
571
599
|
}
|
|
572
600
|
}
|
package/lib/cache.js
CHANGED
|
@@ -6,6 +6,7 @@ const CACHE_META_FILE = "meta.json";
|
|
|
6
6
|
const ANN_META_VERSION = 1;
|
|
7
7
|
const ANN_INDEX_FILE = "ann-index.bin";
|
|
8
8
|
const ANN_META_FILE = "ann-meta.json";
|
|
9
|
+
const CALL_GRAPH_FILE = "call-graph.json";
|
|
9
10
|
|
|
10
11
|
let hnswlibPromise = null;
|
|
11
12
|
let hnswlibLoadError = null;
|
|
@@ -166,7 +167,7 @@ export class EmbeddingsCache {
|
|
|
166
167
|
}
|
|
167
168
|
|
|
168
169
|
// Load call-graph data if it exists
|
|
169
|
-
const callGraphFile = path.join(this.config.cacheDirectory,
|
|
170
|
+
const callGraphFile = path.join(this.config.cacheDirectory, CALL_GRAPH_FILE);
|
|
170
171
|
try {
|
|
171
172
|
const callGraphData = await fs.readFile(callGraphFile, "utf8");
|
|
172
173
|
const parsed = JSON.parse(callGraphData);
|
|
@@ -203,10 +204,12 @@ export class EmbeddingsCache {
|
|
|
203
204
|
fs.writeFile(metaFile, JSON.stringify(this.cacheMeta, null, 2))
|
|
204
205
|
]);
|
|
205
206
|
|
|
206
|
-
// Save call-graph data
|
|
207
|
+
// Save call-graph data (or remove stale cache if empty)
|
|
208
|
+
const callGraphFile = path.join(this.config.cacheDirectory, CALL_GRAPH_FILE);
|
|
207
209
|
if (this.fileCallData.size > 0) {
|
|
208
|
-
const callGraphFile = path.join(this.config.cacheDirectory, "call-graph.json");
|
|
209
210
|
await fs.writeFile(callGraphFile, JSON.stringify(Object.fromEntries(this.fileCallData), null, 2));
|
|
211
|
+
} else {
|
|
212
|
+
await fs.rm(callGraphFile, { force: true });
|
|
210
213
|
}
|
|
211
214
|
} catch (error) {
|
|
212
215
|
console.error("[Cache] Failed to save cache:", error.message);
|
|
@@ -440,9 +443,7 @@ export class EmbeddingsCache {
|
|
|
440
443
|
this.vectorStore = [];
|
|
441
444
|
this.fileHashes = new Map();
|
|
442
445
|
this.invalidateAnnIndex();
|
|
443
|
-
|
|
444
|
-
this.fileCallData.clear();
|
|
445
|
-
this.callGraph = null;
|
|
446
|
+
await this.clearCallGraphData();
|
|
446
447
|
console.error(`[Cache] Cache cleared successfully: ${this.config.cacheDirectory}`);
|
|
447
448
|
} catch (error) {
|
|
448
449
|
console.error("[Cache] Failed to clear cache:", error.message);
|
|
@@ -497,6 +498,46 @@ export class EmbeddingsCache {
|
|
|
497
498
|
|
|
498
499
|
// ========== Call Graph Methods ==========
|
|
499
500
|
|
|
501
|
+
/**
|
|
502
|
+
* Clear all call-graph data (optionally remove persisted cache file)
|
|
503
|
+
*/
|
|
504
|
+
async clearCallGraphData({ removeFile = false } = {}) {
|
|
505
|
+
this.fileCallData.clear();
|
|
506
|
+
this.callGraph = null;
|
|
507
|
+
|
|
508
|
+
if (removeFile && this.config.enableCache) {
|
|
509
|
+
const callGraphFile = path.join(this.config.cacheDirectory, CALL_GRAPH_FILE);
|
|
510
|
+
try {
|
|
511
|
+
await fs.rm(callGraphFile, { force: true });
|
|
512
|
+
} catch (error) {
|
|
513
|
+
if (this.config.verbose) {
|
|
514
|
+
console.error(`[Cache] Failed to remove call-graph cache: ${error.message}`);
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
/**
|
|
521
|
+
* Remove call-graph entries for files no longer in the codebase
|
|
522
|
+
*/
|
|
523
|
+
pruneCallGraphData(validFiles) {
|
|
524
|
+
if (!validFiles || this.fileCallData.size === 0) return 0;
|
|
525
|
+
|
|
526
|
+
let pruned = 0;
|
|
527
|
+
for (const file of Array.from(this.fileCallData.keys())) {
|
|
528
|
+
if (!validFiles.has(file)) {
|
|
529
|
+
this.fileCallData.delete(file);
|
|
530
|
+
pruned++;
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
if (pruned > 0) {
|
|
535
|
+
this.callGraph = null;
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
return pruned;
|
|
539
|
+
}
|
|
540
|
+
|
|
500
541
|
/**
|
|
501
542
|
* Store call data for a file
|
|
502
543
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@softerist/heuristic-mcp",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.3",
|
|
4
4
|
"description": "An enhanced MCP server providing intelligent semantic code search with find-similar-code, recency ranking, and improved chunking. Fork of smart-coding-mcp.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "index.js",
|