@grec0/memory-bank-mcp 0.1.39 → 0.1.40

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.
@@ -6,7 +6,10 @@
6
6
  import * as path from "path";
7
7
  import * as fs from "fs";
8
8
  import * as crypto from "crypto";
9
+ import { fileURLToPath } from "url";
9
10
  import { encode } from "gpt-tokenizer";
11
+ const __filename = fileURLToPath(import.meta.url);
12
+ const __dirname = path.dirname(__filename);
10
13
  // Constants
11
14
  const MAX_TOKENS_PER_CHUNK = 6000;
12
15
  const DEFAULT_CHUNK_OVERLAP_TOKENS = 200;
@@ -214,6 +214,38 @@ export class IndexManager {
214
214
  .replace(/^-|-$/g, "");
215
215
  return sanitized || "default";
216
216
  }
217
+ /**
218
+ * Processes a batch of files concurrently
219
+ */
220
+ async processBatch(batch, startIndex, totalFiles, forceReindex, projectId) {
221
+ const batchErrors = [];
222
+ const batchChangedFiles = [];
223
+ let batchChunks = 0;
224
+ let batchProcessed = 0;
225
+ const results = await Promise.all(batch.map(async (file, index) => {
226
+ console.error(`\n[${startIndex + index + 1}/${totalFiles}] Processing ${file.path}`);
227
+ return {
228
+ file,
229
+ result: await this.indexFile(file, forceReindex, projectId)
230
+ };
231
+ }));
232
+ for (const { file, result } of results) {
233
+ if (result.error) {
234
+ batchErrors.push(result.error);
235
+ }
236
+ else {
237
+ batchProcessed++;
238
+ batchChunks += result.chunksCreated;
239
+ batchChangedFiles.push(file.path);
240
+ }
241
+ }
242
+ return {
243
+ processedCount: batchProcessed,
244
+ chunksCount: batchChunks,
245
+ changedFiles: batchChangedFiles,
246
+ errors: batchErrors
247
+ };
248
+ }
217
249
  /**
218
250
  * Indexes multiple files or a directory
219
251
  */
@@ -281,18 +313,15 @@ export class IndexManager {
281
313
  const changedFiles = [];
282
314
  let totalChunks = 0;
283
315
  let processedFiles = 0;
284
- for (let i = 0; i < filesToIndex.length; i++) {
285
- const file = filesToIndex[i];
286
- console.error(`\n[${i + 1}/${filesToIndex.length}] Processing ${file.path}`);
287
- const result = await this.indexFile(file, options.forceReindex || false, projectId);
288
- if (result.error) {
289
- errors.push(result.error);
290
- }
291
- else {
292
- processedFiles++;
293
- totalChunks += result.chunksCreated;
294
- changedFiles.push(file.path);
295
- }
316
+ // Process files in batches of 5
317
+ const batchSize = 5;
318
+ for (let i = 0; i < filesToIndex.length; i += batchSize) {
319
+ const batch = filesToIndex.slice(i, i + batchSize);
320
+ const batchResult = await this.processBatch(batch, i, filesToIndex.length, options.forceReindex || false, projectId);
321
+ processedFiles += batchResult.processedCount;
322
+ totalChunks += batchResult.chunksCount;
323
+ changedFiles.push(...batchResult.changedFiles);
324
+ errors.push(...batchResult.errors);
296
325
  }
297
326
  const indexDuration = Date.now() - startTime;
298
327
  console.error(`\n=== Indexing complete ===`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@grec0/memory-bank-mcp",
3
- "version": "0.1.39",
3
+ "version": "0.1.40",
4
4
  "description": "MCP server for semantic code indexing with Memory Bank - AI-powered codebase understanding",
5
5
  "license": "MIT",
6
6
  "author": "@grec0",