@grec0/memory-bank-mcp 0.1.40 → 0.1.41
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/dist/common/astChunker.js +60 -11
- package/package.json +4 -4
|
@@ -7,9 +7,11 @@ import * as path from "path";
|
|
|
7
7
|
import * as fs from "fs";
|
|
8
8
|
import * as crypto from "crypto";
|
|
9
9
|
import { fileURLToPath } from "url";
|
|
10
|
+
import { createRequire } from "module";
|
|
10
11
|
import { encode } from "gpt-tokenizer";
|
|
11
12
|
const __filename = fileURLToPath(import.meta.url);
|
|
12
13
|
const __dirname = path.dirname(__filename);
|
|
14
|
+
const require = createRequire(import.meta.url);
|
|
13
15
|
// Constants
|
|
14
16
|
const MAX_TOKENS_PER_CHUNK = 6000;
|
|
15
17
|
const DEFAULT_CHUNK_OVERLAP_TOKENS = 200;
|
|
@@ -131,6 +133,7 @@ const SEMANTIC_NODE_TYPES = {
|
|
|
131
133
|
// Cache for loaded languages
|
|
132
134
|
// Using 'any' types because web-tree-sitter's TypeScript types don't work well with dynamic imports
|
|
133
135
|
let ParserClass = null;
|
|
136
|
+
let LanguageClass = null;
|
|
134
137
|
const loadedLanguages = new Map();
|
|
135
138
|
let treeSitterInitialized = false;
|
|
136
139
|
/**
|
|
@@ -155,15 +158,28 @@ function generateChunkId(filePath, content, startLine) {
|
|
|
155
158
|
* Initializes Tree-sitter WASM module
|
|
156
159
|
*/
|
|
157
160
|
async function initTreeSitter() {
|
|
158
|
-
if (treeSitterInitialized && ParserClass) {
|
|
161
|
+
if (treeSitterInitialized && ParserClass && LanguageClass) {
|
|
159
162
|
return true;
|
|
160
163
|
}
|
|
161
164
|
try {
|
|
162
165
|
// Dynamic import of web-tree-sitter
|
|
163
|
-
// web-tree-sitter exports Parser as a named export, not default
|
|
164
166
|
const TreeSitterModule = await import("web-tree-sitter");
|
|
165
|
-
//
|
|
166
|
-
|
|
167
|
+
// Handle different export formats across web-tree-sitter versions:
|
|
168
|
+
// - v0.20.x: exports Parser as default, Language is Parser.Language
|
|
169
|
+
// - v0.26.x: exports Parser and Language as separate named exports
|
|
170
|
+
if (TreeSitterModule.Parser) {
|
|
171
|
+
// v0.26.x style: named exports
|
|
172
|
+
ParserClass = TreeSitterModule.Parser;
|
|
173
|
+
LanguageClass = TreeSitterModule.Language;
|
|
174
|
+
}
|
|
175
|
+
else if (TreeSitterModule.default) {
|
|
176
|
+
// v0.20.x style: default export is Parser, Language is a static property
|
|
177
|
+
ParserClass = TreeSitterModule.default;
|
|
178
|
+
LanguageClass = null; // Will use ParserClass.Language after init
|
|
179
|
+
}
|
|
180
|
+
else {
|
|
181
|
+
throw new Error('Could not find Parser in web-tree-sitter module');
|
|
182
|
+
}
|
|
167
183
|
if (!ParserClass) {
|
|
168
184
|
throw new Error('Parser class not found in web-tree-sitter module');
|
|
169
185
|
}
|
|
@@ -171,6 +187,13 @@ async function initTreeSitter() {
|
|
|
171
187
|
if (typeof ParserClass.init === 'function') {
|
|
172
188
|
await ParserClass.init();
|
|
173
189
|
}
|
|
190
|
+
// For v0.20.x, Language becomes available after init
|
|
191
|
+
if (!LanguageClass && ParserClass.Language) {
|
|
192
|
+
LanguageClass = ParserClass.Language;
|
|
193
|
+
}
|
|
194
|
+
if (!LanguageClass) {
|
|
195
|
+
throw new Error('Language class not found in web-tree-sitter module');
|
|
196
|
+
}
|
|
174
197
|
treeSitterInitialized = true;
|
|
175
198
|
console.error("[AST Chunker] Tree-sitter initialized successfully");
|
|
176
199
|
return true;
|
|
@@ -179,6 +202,7 @@ async function initTreeSitter() {
|
|
|
179
202
|
console.error(`[AST Chunker] Failed to initialize Tree-sitter: ${error}`);
|
|
180
203
|
treeSitterInitialized = false;
|
|
181
204
|
ParserClass = null;
|
|
205
|
+
LanguageClass = null;
|
|
182
206
|
return false;
|
|
183
207
|
}
|
|
184
208
|
}
|
|
@@ -190,26 +214,46 @@ function getWasmPath(language) {
|
|
|
190
214
|
if (!wasmFile) {
|
|
191
215
|
return null;
|
|
192
216
|
}
|
|
193
|
-
//
|
|
217
|
+
// Build comprehensive list of possible paths
|
|
218
|
+
// The compiled JS runs from dist/common/, so we need to account for various scenarios:
|
|
219
|
+
// 1. Local development: dist/common/../node_modules = dist/node_modules (wrong)
|
|
220
|
+
// 2. Local development: __dirname/../../node_modules = node_modules (correct)
|
|
221
|
+
// 3. NPM installed package: need to resolve from the package location
|
|
222
|
+
// 4. Global install or monorepo: process.cwd() based paths
|
|
194
223
|
const possiblePaths = [
|
|
195
|
-
|
|
196
|
-
path.join(process.cwd(), "node_modules", "tree-sitter-wasms", "out", wasmFile),
|
|
224
|
+
// From dist/common/ go up two levels to project root then into node_modules
|
|
197
225
|
path.join(__dirname, "..", "..", "node_modules", "tree-sitter-wasms", "out", wasmFile),
|
|
226
|
+
// From current working directory
|
|
227
|
+
path.join(process.cwd(), "node_modules", "tree-sitter-wasms", "out", wasmFile),
|
|
228
|
+
// From dist/ go up one level (in case __dirname is dist/)
|
|
229
|
+
path.join(__dirname, "..", "node_modules", "tree-sitter-wasms", "out", wasmFile),
|
|
230
|
+
// Three levels up (for nested structures like dist/common/subdir)
|
|
231
|
+
path.join(__dirname, "..", "..", "..", "node_modules", "tree-sitter-wasms", "out", wasmFile),
|
|
198
232
|
];
|
|
233
|
+
// Try to use require.resolve to find the package (works in most Node.js scenarios)
|
|
234
|
+
try {
|
|
235
|
+
const treeSitterWasmsPath = require.resolve("tree-sitter-wasms/package.json");
|
|
236
|
+
const packageDir = path.dirname(treeSitterWasmsPath);
|
|
237
|
+
possiblePaths.unshift(path.join(packageDir, "out", wasmFile));
|
|
238
|
+
}
|
|
239
|
+
catch {
|
|
240
|
+
// Package not found via require.resolve, continue with file-based search
|
|
241
|
+
}
|
|
199
242
|
for (const p of possiblePaths) {
|
|
200
243
|
if (fs.existsSync(p)) {
|
|
201
244
|
return p;
|
|
202
245
|
}
|
|
203
246
|
}
|
|
204
247
|
console.error(`[AST Chunker] WASM file not found for ${language}: ${wasmFile}`);
|
|
248
|
+
console.error(`[AST Chunker] Searched paths: ${possiblePaths.map(p => `\n - ${p}`).join('')}`);
|
|
205
249
|
return null;
|
|
206
250
|
}
|
|
207
251
|
/**
|
|
208
252
|
* Loads a language parser
|
|
209
253
|
*/
|
|
210
254
|
async function loadLanguage(language) {
|
|
211
|
-
if (!ParserClass) {
|
|
212
|
-
console.error("[AST Chunker] Parser not initialized");
|
|
255
|
+
if (!ParserClass || !LanguageClass) {
|
|
256
|
+
console.error("[AST Chunker] Parser or Language not initialized");
|
|
213
257
|
return null;
|
|
214
258
|
}
|
|
215
259
|
const langKey = language.toLowerCase();
|
|
@@ -220,15 +264,19 @@ async function loadLanguage(language) {
|
|
|
220
264
|
if (!wasmPath) {
|
|
221
265
|
return null;
|
|
222
266
|
}
|
|
267
|
+
console.error(`[AST Chunker] Attempting to load WASM from: ${wasmPath}`);
|
|
223
268
|
try {
|
|
224
269
|
// Use the Language.load static method
|
|
225
|
-
const lang = await
|
|
270
|
+
const lang = await LanguageClass.load(wasmPath);
|
|
226
271
|
loadedLanguages.set(langKey, lang);
|
|
227
272
|
console.error(`[AST Chunker] Loaded language: ${language}`);
|
|
228
273
|
return lang;
|
|
229
274
|
}
|
|
230
275
|
catch (error) {
|
|
231
|
-
console.error(`[AST Chunker] Failed to load language ${language}: ${error}`);
|
|
276
|
+
console.error(`[AST Chunker] Failed to load language ${language}: ${error instanceof Error ? error.message : error}`);
|
|
277
|
+
if (error instanceof Error && error.stack) {
|
|
278
|
+
console.error(`[AST Chunker] Stack: ${error.stack}`);
|
|
279
|
+
}
|
|
232
280
|
return null;
|
|
233
281
|
}
|
|
234
282
|
}
|
|
@@ -556,5 +604,6 @@ export function disposeASTChunker() {
|
|
|
556
604
|
loadedLanguages.clear();
|
|
557
605
|
treeSitterInitialized = false;
|
|
558
606
|
ParserClass = null;
|
|
607
|
+
LanguageClass = null;
|
|
559
608
|
console.error("[AST Chunker] Disposed");
|
|
560
609
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@grec0/memory-bank-mcp",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.41",
|
|
4
4
|
"description": "MCP server for semantic code indexing with Memory Bank - AI-powered codebase understanding",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "@grec0",
|
|
@@ -40,14 +40,14 @@
|
|
|
40
40
|
"@lancedb/lancedb": "^0.9.0",
|
|
41
41
|
"@modelcontextprotocol/sdk": "1.25.2",
|
|
42
42
|
"@types/node": "^22",
|
|
43
|
+
"better-sqlite3": "^11.7.0",
|
|
43
44
|
"gpt-tokenizer": "3.4.0",
|
|
44
45
|
"ignore": "^5.3.0",
|
|
45
46
|
"openai": "^4.0.0",
|
|
46
47
|
"tree-sitter-wasms": "0.1.13",
|
|
47
|
-
"web-tree-sitter": "0.
|
|
48
|
+
"web-tree-sitter": "0.20.8",
|
|
48
49
|
"zod": "^3.22.4",
|
|
49
|
-
"zod-to-json-schema": "^3.23.5"
|
|
50
|
-
"better-sqlite3": "^11.7.0"
|
|
50
|
+
"zod-to-json-schema": "^3.23.5"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
53
|
"@jest/globals": "^29.7.0",
|