grepmax 0.7.3 → 0.7.4
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/commands/mcp.js
CHANGED
|
@@ -304,10 +304,39 @@ exports.mcp = new commander_1.Command("mcp")
|
|
|
304
304
|
});
|
|
305
305
|
}
|
|
306
306
|
// --- Index sync ---
|
|
307
|
+
let _indexChildPid = null;
|
|
308
|
+
function isIndexProcessRunning() {
|
|
309
|
+
if (!_indexChildPid)
|
|
310
|
+
return false;
|
|
311
|
+
try {
|
|
312
|
+
process.kill(_indexChildPid, 0);
|
|
313
|
+
return true;
|
|
314
|
+
}
|
|
315
|
+
catch (_a) {
|
|
316
|
+
return false;
|
|
317
|
+
}
|
|
318
|
+
}
|
|
307
319
|
function ensureIndexReady() {
|
|
308
320
|
return __awaiter(this, void 0, void 0, function* () {
|
|
321
|
+
var _a;
|
|
309
322
|
if (_indexReady)
|
|
310
323
|
return;
|
|
324
|
+
// Check if a previously spawned index process finished
|
|
325
|
+
if (_indexing && !isIndexProcessRunning()) {
|
|
326
|
+
_indexing = false;
|
|
327
|
+
_indexProgress = "";
|
|
328
|
+
_indexChildPid = null;
|
|
329
|
+
// Re-check if index now exists
|
|
330
|
+
try {
|
|
331
|
+
const db = getVectorDb();
|
|
332
|
+
if (yield db.hasRowsForPath(projectRoot)) {
|
|
333
|
+
_indexReady = true;
|
|
334
|
+
console.log("[MCP] Background indexing complete.");
|
|
335
|
+
return;
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
catch (_b) { }
|
|
339
|
+
}
|
|
311
340
|
try {
|
|
312
341
|
const db = getVectorDb();
|
|
313
342
|
const hasIndex = yield db.hasRowsForPath(projectRoot);
|
|
@@ -316,23 +345,25 @@ exports.mcp = new commander_1.Command("mcp")
|
|
|
316
345
|
return; // Already indexing in background
|
|
317
346
|
_indexing = true;
|
|
318
347
|
_indexProgress = "starting...";
|
|
319
|
-
console.log("[MCP] No index found,
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
_indexing = false;
|
|
329
|
-
_indexProgress = "";
|
|
330
|
-
console.log("[MCP] Initial sync complete.");
|
|
331
|
-
})
|
|
332
|
-
.catch((e) => {
|
|
348
|
+
console.log("[MCP] No index found, spawning background index...");
|
|
349
|
+
// Spawn gmax index as a detached child process — doesn't hold
|
|
350
|
+
// the lock inside this MCP process, so CLI `gmax index` won't conflict.
|
|
351
|
+
const child = (0, node_child_process_1.spawn)(process.argv[0], [process.argv[1], "index", "--path", projectRoot], { detached: true, stdio: "ignore" });
|
|
352
|
+
_indexChildPid = (_a = child.pid) !== null && _a !== void 0 ? _a : null;
|
|
353
|
+
child.unref();
|
|
354
|
+
_indexProgress = `PID ${_indexChildPid}`;
|
|
355
|
+
console.log(`[MCP] Background index started (PID: ${_indexChildPid})`);
|
|
356
|
+
child.on("exit", (code) => {
|
|
333
357
|
_indexing = false;
|
|
334
358
|
_indexProgress = "";
|
|
335
|
-
|
|
359
|
+
_indexChildPid = null;
|
|
360
|
+
if (code === 0) {
|
|
361
|
+
_indexReady = true;
|
|
362
|
+
console.log("[MCP] Background indexing complete.");
|
|
363
|
+
}
|
|
364
|
+
else {
|
|
365
|
+
console.error(`[MCP] Background indexing failed (exit code: ${code})`);
|
|
366
|
+
}
|
|
336
367
|
});
|
|
337
368
|
}
|
|
338
369
|
else {
|
package/package.json
CHANGED