@softerist/heuristic-mcp 3.0.0 → 3.0.2
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/CONTRIBUTING.md +0 -227
- package/README.md +54 -19
- package/{config.json → config.jsonc} +723 -876
- package/features/index-codebase.js +2554 -1955
- package/index.js +74 -9
- package/lib/cache.js +178 -148
- package/lib/config.js +825 -718
- package/lib/embedding-process.js +222 -36
- package/lib/embedding-worker.js +684 -582
- package/lib/onnx-backend.js +187 -0
- package/lib/server-lifecycle.js +94 -0
- package/lib/tokenizer.js +7 -3
- package/lib/vector-store-binary.js +612 -592
- package/package.json +4 -4
- package/scripts/download-model.js +1 -1
- package/search-configs.js +1 -1
- package/test/ann-config.test.js +1 -0
- package/test/ann-fallback.test.js +1 -0
- package/test/binary-store.test.js +1 -0
- package/test/cache-branches.test.js +1 -0
- package/test/cache-errors.test.js +1 -0
- package/test/cache-extra.test.js +1 -0
- package/test/cache-helpers.test.js +1 -0
- package/test/cache-hnsw-failure.test.js +1 -0
- package/test/cache-json-worker.test.js +1 -0
- package/test/cache-worker.test.js +1 -0
- package/test/cache.test.js +28 -0
- package/test/call-graph.test.js +1 -0
- package/test/clear-cache.test.js +1 -0
- package/test/code-review-workflow.test.js +1 -0
- package/test/config.test.js +11 -3
- package/test/coverage-gap.test.js +1 -0
- package/test/coverage-maximizer.test.js +1 -0
- package/test/debug-analysis.js +1 -0
- package/test/embedding-model.test.js +2 -1
- package/test/embedding-worker-extra.test.js +3 -2
- package/test/embedding-worker.test.js +3 -2
- package/test/features.test.js +1 -0
- package/test/final-boost.test.js +1 -0
- package/test/final-polish.test.js +1 -0
- package/test/final.test.js +1 -0
- package/test/find-similar-code.test.js +1 -0
- package/test/helpers.js +2 -1
- package/test/helpers.test.js +3 -2
- package/test/hybrid-search-basic.test.js +1 -0
- package/test/hybrid-search-branch.test.js +1 -0
- package/test/hybrid-search-callgraph.test.js +1 -0
- package/test/hybrid-search-extra.test.js +1 -0
- package/test/hybrid-search.test.js +1 -0
- package/test/index-cli.test.js +2 -1
- package/test/index-codebase-batch.test.js +1 -0
- package/test/index-codebase-branches.test.js +6 -4
- package/test/index-codebase-core.test.js +1 -0
- package/test/index-codebase-edge-cases.test.js +1 -0
- package/test/index-codebase-errors.test.js +1 -0
- package/test/index-codebase-gap.test.js +1 -0
- package/test/index-codebase-lines.test.js +1 -0
- package/test/index-codebase-watcher.test.js +337 -229
- package/test/index-codebase-zone.test.js +1 -0
- package/test/index-codebase.test.js +3 -2
- package/test/index-memory.test.js +2 -1
- package/test/indexer-detailed.test.js +1 -0
- package/test/integration.test.js +1 -0
- package/test/json-worker.test.js +1 -0
- package/test/lifecycle.test.js +1 -0
- package/test/master.test.js +1 -0
- package/test/perfection.test.js +1 -0
- package/test/project-detector.test.js +1 -0
- package/test/register.test.js +1 -0
- package/test/stress.js +18955 -0
- package/test/tokenizer.test.js +11 -10
- package/test/ultra-maximizer.test.js +1 -0
- package/test/utils-branches.test.js +1 -0
- package/test/utils-extra.test.js +1 -0
- package/test/utils.test.js +1 -0
- package/test/verify_fixes.js +1 -0
- package/test/worker-errors.test.js +1 -0
- package/test/worker-init.test.js +1 -0
- package/test/worker_throttling.test.js +1 -0
- package/tools/scripts/benchmark-search.js +1 -1
- package/tools/scripts/manual-search.js +7 -7
- package/GEMINI.md +0 -73
package/CONTRIBUTING.md
CHANGED
|
@@ -1,227 +0,0 @@
|
|
|
1
|
-
# Contributing to Heuristic MCP
|
|
2
|
-
|
|
3
|
-
Thank you for your interest in contributing. This document provides guidelines for contributing to the project.
|
|
4
|
-
|
|
5
|
-
## Getting Started
|
|
6
|
-
|
|
7
|
-
### Prerequisites
|
|
8
|
-
|
|
9
|
-
- Node.js 18 or higher
|
|
10
|
-
- npm or yarn
|
|
11
|
-
- Git
|
|
12
|
-
|
|
13
|
-
### Setup Development Environment
|
|
14
|
-
|
|
15
|
-
```bash
|
|
16
|
-
# Fork and clone the repository
|
|
17
|
-
git clone https://github.com/softerist/heuristic-mcp.git
|
|
18
|
-
cd heuristic-mcp
|
|
19
|
-
|
|
20
|
-
# Install dependencies
|
|
21
|
-
npm install
|
|
22
|
-
|
|
23
|
-
# Run in development mode
|
|
24
|
-
npm run dev
|
|
25
|
-
```
|
|
26
|
-
|
|
27
|
-
## Project Structure
|
|
28
|
-
|
|
29
|
-
See `ARCHITECTURE.md` for detailed information about the modular architecture.
|
|
30
|
-
|
|
31
|
-
Key directories:
|
|
32
|
-
|
|
33
|
-
- `lib/` - Core libraries and utilities
|
|
34
|
-
- `features/` - Pluggable feature modules
|
|
35
|
-
- `scripts/` - Utility scripts
|
|
36
|
-
- `tools/` - Developer-only helpers
|
|
37
|
-
|
|
38
|
-
## Development Guidelines
|
|
39
|
-
|
|
40
|
-
### Code Style
|
|
41
|
-
|
|
42
|
-
- Use ES6+ JavaScript features
|
|
43
|
-
- Follow existing code patterns
|
|
44
|
-
- Use meaningful variable and function names
|
|
45
|
-
- Add comments for complex logic
|
|
46
|
-
- Avoid emojis in code comments and logs unless they are part of user-facing CLI output
|
|
47
|
-
|
|
48
|
-
### File Organization
|
|
49
|
-
|
|
50
|
-
```javascript
|
|
51
|
-
// Standard file structure for features:
|
|
52
|
-
|
|
53
|
-
// 1. Imports
|
|
54
|
-
import { dependency } from 'package';
|
|
55
|
-
|
|
56
|
-
// 2. Class definition
|
|
57
|
-
export class FeatureName {
|
|
58
|
-
constructor(embedder, cache, config) {
|
|
59
|
-
// ...
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
async method() {
|
|
63
|
-
// ...
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
// 3. MCP tool definition
|
|
68
|
-
export function getToolDefinition(config) {
|
|
69
|
-
return {
|
|
70
|
-
/* ... */
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
// 4. Tool handler
|
|
75
|
-
export async function handleToolCall(request, instance) {
|
|
76
|
-
// ...
|
|
77
|
-
}
|
|
78
|
-
```
|
|
79
|
-
|
|
80
|
-
### Error Handling
|
|
81
|
-
|
|
82
|
-
```javascript
|
|
83
|
-
// Always handle errors gracefully
|
|
84
|
-
try {
|
|
85
|
-
// operation
|
|
86
|
-
} catch (error) {
|
|
87
|
-
console.error('[Module] Error description:', error.message);
|
|
88
|
-
// Continue execution or return default value
|
|
89
|
-
}
|
|
90
|
-
```
|
|
91
|
-
|
|
92
|
-
### Logging
|
|
93
|
-
|
|
94
|
-
- Use `console.info()` for normal server lifecycle output (redirected to logs in MCP mode)
|
|
95
|
-
- Use `console.warn()` for non-fatal issues and `console.error()` for errors
|
|
96
|
-
- CLI utilities and install scripts may use `console.info()` for user-friendly output
|
|
97
|
-
|
|
98
|
-
## Adding New Features
|
|
99
|
-
|
|
100
|
-
### Step-by-Step Guide
|
|
101
|
-
|
|
102
|
-
1. **Create Feature File**
|
|
103
|
-
|
|
104
|
-
Create `features/your-feature.js`:
|
|
105
|
-
|
|
106
|
-
```javascript
|
|
107
|
-
export class YourFeature {
|
|
108
|
-
constructor(embedder, cache, config) {
|
|
109
|
-
this.embedder = embedder;
|
|
110
|
-
this.cache = cache;
|
|
111
|
-
this.config = config;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
async execute(params) {
|
|
115
|
-
// Implementation
|
|
116
|
-
return { result: 'data' };
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
export function getToolDefinition(config) {
|
|
121
|
-
return {
|
|
122
|
-
name: 'your_tool',
|
|
123
|
-
description: 'Clear description of what the tool does',
|
|
124
|
-
inputSchema: {
|
|
125
|
-
type: 'object',
|
|
126
|
-
properties: {
|
|
127
|
-
param: {
|
|
128
|
-
type: 'string',
|
|
129
|
-
description: 'Parameter description',
|
|
130
|
-
},
|
|
131
|
-
},
|
|
132
|
-
required: ['param'],
|
|
133
|
-
},
|
|
134
|
-
};
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
export async function handleToolCall(request, instance) {
|
|
138
|
-
const params = request.params.arguments;
|
|
139
|
-
const result = await instance.execute(params);
|
|
140
|
-
|
|
141
|
-
return {
|
|
142
|
-
content: [
|
|
143
|
-
{
|
|
144
|
-
type: 'text',
|
|
145
|
-
text: JSON.stringify(result, null, 2),
|
|
146
|
-
},
|
|
147
|
-
],
|
|
148
|
-
};
|
|
149
|
-
}
|
|
150
|
-
```
|
|
151
|
-
|
|
152
|
-
2. **Register Feature**
|
|
153
|
-
|
|
154
|
-
Update `index.js`:
|
|
155
|
-
|
|
156
|
-
```javascript
|
|
157
|
-
import * as YourFeature from './features/your-feature.js';
|
|
158
|
-
|
|
159
|
-
// In initialize():
|
|
160
|
-
const yourFeature = new YourFeature.YourFeature(embedder, cache, config);
|
|
161
|
-
|
|
162
|
-
// Add to features array:
|
|
163
|
-
features.push({
|
|
164
|
-
module: YourFeature,
|
|
165
|
-
instance: yourFeature,
|
|
166
|
-
handler: YourFeature.handleToolCall,
|
|
167
|
-
});
|
|
168
|
-
```
|
|
169
|
-
|
|
170
|
-
3. **Test Your Feature**
|
|
171
|
-
|
|
172
|
-
- Test with a sample codebase
|
|
173
|
-
- Verify MCP tool contract
|
|
174
|
-
- Check error handling and output format
|
|
175
|
-
|
|
176
|
-
4. **Document Your Feature**
|
|
177
|
-
|
|
178
|
-
- Add to README.md features section
|
|
179
|
-
- Update ARCHITECTURE.md if needed
|
|
180
|
-
|
|
181
|
-
## Testing
|
|
182
|
-
|
|
183
|
-
```bash
|
|
184
|
-
npm test
|
|
185
|
-
```
|
|
186
|
-
|
|
187
|
-
By default, tests use a mock embedder to avoid network/model downloads. To run the real model tests:
|
|
188
|
-
|
|
189
|
-
```bash
|
|
190
|
-
USE_REAL_EMBEDDER=true npm test
|
|
191
|
-
```
|
|
192
|
-
|
|
193
|
-
## Pull Request Process
|
|
194
|
-
|
|
195
|
-
1. **Fork the repository**
|
|
196
|
-
|
|
197
|
-
2. **Create a feature branch**
|
|
198
|
-
|
|
199
|
-
```bash
|
|
200
|
-
git checkout -b feature/your-feature-name
|
|
201
|
-
```
|
|
202
|
-
|
|
203
|
-
3. **Make your changes**
|
|
204
|
-
|
|
205
|
-
- Follow code style guidelines
|
|
206
|
-
- Add appropriate comments
|
|
207
|
-
- Test thoroughly
|
|
208
|
-
|
|
209
|
-
4. **Commit your changes**
|
|
210
|
-
|
|
211
|
-
```bash
|
|
212
|
-
git add .
|
|
213
|
-
git commit -m "Add feature: description"
|
|
214
|
-
```
|
|
215
|
-
|
|
216
|
-
Follow commit message conventions:
|
|
217
|
-
|
|
218
|
-
- `Add feature: description` - New features
|
|
219
|
-
- `Fix: description` - Bug fixes
|
|
220
|
-
- `Update: description` - Updates to existing code
|
|
221
|
-
- `Docs: description` - Documentation changes
|
|
222
|
-
|
|
223
|
-
5. **Push to your fork**
|
|
224
|
-
|
|
225
|
-
```bash
|
|
226
|
-
git push origin feature/your-feature-name
|
|
227
|
-
```
|
package/README.md
CHANGED
|
@@ -98,11 +98,11 @@ Clears the cache for the current working directory (or `--workspace` if provided
|
|
|
98
98
|
|
|
99
99
|
---
|
|
100
100
|
|
|
101
|
-
## Configuration (`config.
|
|
101
|
+
## Configuration (`config.jsonc`)
|
|
102
102
|
|
|
103
|
-
Configuration is loaded from your workspace root when the server runs with `--workspace` (this is how IDEs launch it). In server mode, it falls back to the package `config.json` and then your current working directory.
|
|
103
|
+
Configuration is loaded from your workspace root when the server runs with `--workspace` (this is how IDEs launch it). In server mode, it falls back to the package `config.jsonc` (or `config.json`) and then your current working directory.
|
|
104
104
|
|
|
105
|
-
Example `config.
|
|
105
|
+
Example `config.jsonc`:
|
|
106
106
|
|
|
107
107
|
```json
|
|
108
108
|
{
|
|
@@ -111,6 +111,9 @@ Example `config.json`:
|
|
|
111
111
|
"smartIndexing": true,
|
|
112
112
|
"embeddingModel": "jinaai/jina-embeddings-v2-base-code",
|
|
113
113
|
"workerThreads": 0,
|
|
114
|
+
"embeddingBatchSize": null,
|
|
115
|
+
"embeddingProcessNumThreads": 8,
|
|
116
|
+
"enableExplicitGc": false,
|
|
114
117
|
"recencyBoost": 0.1,
|
|
115
118
|
"recencyDecayDays": 30,
|
|
116
119
|
"callGraphEnabled": true,
|
|
@@ -128,27 +131,31 @@ Example `config.json`:
|
|
|
128
131
|
Cache location:
|
|
129
132
|
|
|
130
133
|
- By default, the cache is stored in a global OS cache directory under `heuristic-mcp/<hash>`.
|
|
131
|
-
- You can override with `cacheDirectory` in
|
|
134
|
+
- You can override with `cacheDirectory` in your config file.
|
|
132
135
|
|
|
133
136
|
### Environment Variables
|
|
134
137
|
|
|
135
138
|
Selected overrides (prefix `SMART_CODING_`):
|
|
136
139
|
|
|
137
|
-
- `SMART_CODING_VERBOSE=true|false`
|
|
138
|
-
- `SMART_CODING_WORKER_THREADS=auto|
|
|
139
|
-
- `SMART_CODING_BATCH_SIZE=100`
|
|
140
|
-
- `SMART_CODING_CHUNK_SIZE=25`
|
|
141
|
-
- `SMART_CODING_MAX_RESULTS=5`
|
|
142
|
-
- `
|
|
143
|
-
- `
|
|
144
|
-
- `
|
|
145
|
-
- `
|
|
146
|
-
- `
|
|
147
|
-
- `
|
|
148
|
-
- `
|
|
149
|
-
- `
|
|
150
|
-
- `
|
|
151
|
-
- `
|
|
140
|
+
- `SMART_CODING_VERBOSE=true|false` — enable detailed logging.
|
|
141
|
+
- `SMART_CODING_WORKER_THREADS=auto|N` — worker thread count.
|
|
142
|
+
- `SMART_CODING_BATCH_SIZE=100` — files per indexing batch.
|
|
143
|
+
- `SMART_CODING_CHUNK_SIZE=25` — lines per chunk.
|
|
144
|
+
- `SMART_CODING_MAX_RESULTS=5` — max search results.
|
|
145
|
+
- `SMART_CODING_EMBEDDING_BATCH_SIZE=64` — embedding batch size (1–256, overrides auto).
|
|
146
|
+
- `SMART_CODING_EMBEDDING_THREADS=8` — ONNX threads for the embedding child process.
|
|
147
|
+
- `SMART_CODING_RECENCY_BOOST=0.1` — boost for recently edited files.
|
|
148
|
+
- `SMART_CODING_RECENCY_DECAY_DAYS=30` — days until recency boost decays to 0.
|
|
149
|
+
- `SMART_CODING_ANN_ENABLED=true|false` — enable ANN index.
|
|
150
|
+
- `SMART_CODING_ANN_EF_SEARCH=64` — ANN search quality/speed tradeoff.
|
|
151
|
+
- `SMART_CODING_VECTOR_STORE_FORMAT=json|binary` — on-disk vector store format.
|
|
152
|
+
- `SMART_CODING_VECTOR_STORE_CONTENT_MODE=external|inline` — where content is stored for binary format.
|
|
153
|
+
- `SMART_CODING_VECTOR_STORE_LOAD_MODE=memory|disk` — vector loading strategy.
|
|
154
|
+
- `SMART_CODING_CONTENT_CACHE_ENTRIES=256` — LRU entries for decoded content.
|
|
155
|
+
- `SMART_CODING_VECTOR_CACHE_ENTRIES=64` — LRU entries for vectors (disk mode).
|
|
156
|
+
- `SMART_CODING_CLEAR_CACHE_AFTER_INDEX=true|false` — drop in-memory vectors after indexing.
|
|
157
|
+
- `SMART_CODING_EXPLICIT_GC=true|false` — opt-in to explicit GC (requires `--expose-gc`).
|
|
158
|
+
- `SMART_CODING_INCREMENTAL_GC_THRESHOLD_MB=2048` — RSS threshold for running incremental GC after watcher updates (requires explicit GC).
|
|
152
159
|
|
|
153
160
|
See `lib/config.js` for the full list.
|
|
154
161
|
|
|
@@ -191,6 +198,34 @@ Note: On small repos, disk mode may be slightly slower and show noisy RSS deltas
|
|
|
191
198
|
1. Run `heuristic-mcp --status` to check config and cache status.
|
|
192
199
|
2. Run `heuristic-mcp --logs` to see startup errors.
|
|
193
200
|
|
|
201
|
+
**Native ONNX backend unavailable (falls back to WASM)**
|
|
202
|
+
|
|
203
|
+
If you see log lines like:
|
|
204
|
+
|
|
205
|
+
```
|
|
206
|
+
Native ONNX backend unavailable: The operating system cannot run %1.
|
|
207
|
+
...onnxruntime_binding.node. Falling back to WASM.
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
The server will automatically disable workers and force `embeddingProcessPerBatch` to reduce memory spikes, but you
|
|
211
|
+
should fix the native binding to restore stable memory usage:
|
|
212
|
+
|
|
213
|
+
- Ensure you are running **64-bit Node.js** (`node -p "process.arch"` should be `x64`).
|
|
214
|
+
- Install **Microsoft Visual C++ 2015–2022 Redistributable (x64)**.
|
|
215
|
+
- Reinstall dependencies (clears locked native binaries):
|
|
216
|
+
|
|
217
|
+
```bash
|
|
218
|
+
Remove-Item -Recurse -Force node_modules\\onnxruntime-node, node_modules\\.onnxruntime-node-* -ErrorAction SilentlyContinue
|
|
219
|
+
npm install
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
If you see a warning about **version mismatch** (e.g. "onnxruntime-node 1.23.x incompatible with transformers.js
|
|
223
|
+
expectation 1.14.x"), install the matching version:
|
|
224
|
+
|
|
225
|
+
```bash
|
|
226
|
+
npm install onnxruntime-node@1.14.0
|
|
227
|
+
```
|
|
228
|
+
|
|
194
229
|
**Search returns no results**
|
|
195
230
|
|
|
196
231
|
- Check `heuristic-mcp --status` for indexing progress.
|