@esankhan3/code-search-mcp 1.1.8 → 1.1.9

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.
@@ -0,0 +1,94 @@
1
+ import { describe, it, before, after } from "node:test";
2
+ import assert from "node:assert/strict";
3
+ import { mkdirSync, rmSync, writeFileSync } from "node:fs";
4
+ import { join } from "node:path";
5
+ import {
6
+ BIN,
7
+ tmp,
8
+ makeRepo,
9
+ baseEnv,
10
+ spawnProc,
11
+ getJson,
12
+ waitFor,
13
+ exitWithin,
14
+ startFakeEmbedder
15
+ } from "./_harness.js";
16
+ let root;
17
+ let ws;
18
+ let embedder;
19
+ before(async () => {
20
+ root = tmp("cs-cal-");
21
+ ws = join(root, "ws");
22
+ makeRepo(ws, "svc", Object.fromEntries(Array.from({ length: 300 }, (_, i) => [
23
+ `src/m${i}.ts`,
24
+ `export function handler${i}(a: number): number {
25
+ return a * ${i} + ${i * 7};
26
+ }
27
+ `
28
+ ])));
29
+ embedder = await startFakeEmbedder(47404);
30
+ mkdirSync(join(root, "home", ".code-search"), { recursive: true });
31
+ writeFileSync(join(root, "home", ".code-search", "config.yaml"), [
32
+ "storage:",
33
+ " backends:",
34
+ " vector:",
35
+ " lancedb:",
36
+ " index: { type: ivf_pq, minRows: 256, numPartitions: 4, numSubVectors: 2 }",
37
+ ""
38
+ ].join("\n"));
39
+ });
40
+ after(async () => {
41
+ await embedder.close();
42
+ rmSync(root, { recursive: true, force: true });
43
+ });
44
+ describe("nprobes calibration and server starts", () => {
45
+ it("the first index run after each server start recalibrates; later runs only when due", async () => {
46
+ const env = baseEnv({
47
+ home: join(root, "home"),
48
+ dataDir: join(root, "data"),
49
+ embedderUrl: embedder.url,
50
+ extra: { CODE_SEARCH_WORKERS: "2" }
51
+ });
52
+ const base = "http://127.0.0.1:47405";
53
+ const serve = async () => {
54
+ const p2 = spawnProc(BIN.mcp, ["--serve", "--port", "47405"], env);
55
+ await waitFor(async () => (await getJson(`${base}/health`)).status === 200, 2e4, `health
56
+ ${p2.stderr()}`);
57
+ await waitFor(() => (p2.stderr().match(/Server running for/g) ?? []).length >= 2, 2e4, "two workers");
58
+ return p2;
59
+ };
60
+ const index = async (p2) => {
61
+ const r = await getJson(`${base}/index`, {
62
+ method: "POST",
63
+ headers: { "Content-Type": "application/json" },
64
+ body: JSON.stringify({ path: ws })
65
+ });
66
+ assert.equal(r.status, 200, `${JSON.stringify(r.body)}
67
+ ${p2.stderr()}`);
68
+ };
69
+ const calibrations = (p2) => p2.stderr().match(/nprobes=\d+ \([^;]*/g) ?? [];
70
+ const stop = async (p2) => {
71
+ p2.child.kill("SIGTERM");
72
+ await exitWithin(p2, 5e3);
73
+ };
74
+ let p = await serve();
75
+ try {
76
+ await index(p);
77
+ await index(p);
78
+ assert.equal(calibrations(p).length, 1, p.stderr());
79
+ assert.doesNotMatch(calibrations(p)[0], /recalibrated/);
80
+ } finally {
81
+ await stop(p);
82
+ }
83
+ p = await serve();
84
+ try {
85
+ await index(p);
86
+ await index(p);
87
+ const runs = calibrations(p);
88
+ assert.equal(runs.length, 1, p.stderr());
89
+ assert.match(runs[0], /recalibrated at server start/);
90
+ } finally {
91
+ await stop(p);
92
+ }
93
+ });
94
+ });
@@ -4,6 +4,7 @@ process.once("message", (run) => {
4
4
  indexFromPath(run.project, run.dirPath, {
5
5
  force: run.force,
6
6
  config: run.config,
7
+ freshCalibration: run.freshCalibration,
7
8
  onProgress: (message) => send({ type: "progress", message }),
8
9
  onDetailedProgress: (progress) => send({ type: "detail", progress })
9
10
  }).then(
package/dist/server.js CHANGED
@@ -401,6 +401,7 @@ function registerWorkerIpc(ctx) {
401
401
  }
402
402
  let indexInChild = false;
403
403
  let activeIndexChild = null;
404
+ let freshCalibrationPending = true;
404
405
  function indexInChildProcess(project, dirPath, opts) {
405
406
  return new Promise((resolveRun, rejectRun) => {
406
407
  const child = fork(fileURLToPath(new URL("./index-child.js", import.meta.url)), [], {
@@ -417,7 +418,14 @@ function indexInChildProcess(project, dirPath, opts) {
417
418
  activeIndexChild = null;
418
419
  finish();
419
420
  };
420
- const run = { type: "run", project, dirPath, force: opts.force, config: opts.config };
421
+ const run = {
422
+ type: "run",
423
+ project,
424
+ dirPath,
425
+ force: opts.force,
426
+ config: opts.config,
427
+ freshCalibration: opts.freshCalibration
428
+ };
421
429
  child.on("message", (msg) => {
422
430
  if (msg.type === "ready") child.send(run);
423
431
  else if (msg.type === "progress") opts.onProgress?.(msg.message);
@@ -459,6 +467,7 @@ async function trackedIndex(ctx, project, dirPath, opts) {
459
467
  const stats = await (indexInChild ? indexInChildProcess : indexFromPath)(project, dirPath, {
460
468
  force: opts?.force,
461
469
  config: resolvedKnowledgeConfig(),
470
+ freshCalibration: freshCalibrationPending,
462
471
  onProgress: (m) => {
463
472
  ctx.indexing.message = m;
464
473
  progressLog.info(m);
@@ -469,6 +478,7 @@ async function trackedIndex(ctx, project, dirPath, opts) {
469
478
  ctx.indexing.message = p.message;
470
479
  }
471
480
  });
481
+ freshCalibrationPending = false;
472
482
  try {
473
483
  await invalidateRetriever(project);
474
484
  } catch {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@esankhan3/code-search-mcp",
3
- "version": "1.1.8",
3
+ "version": "1.1.9",
4
4
  "description": "MCP server for multi-repo code search \u2014 GitHub org or local path, zero config",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -24,7 +24,7 @@
24
24
  },
25
25
  "dependencies": {
26
26
  "@esankhan3/anvil-agent-core": "^0.5.4",
27
- "@esankhan3/anvil-knowledge-core": "^0.4.13",
27
+ "@esankhan3/anvil-knowledge-core": "^0.4.15",
28
28
  "@modelcontextprotocol/node": "^2.0.0",
29
29
  "@modelcontextprotocol/server": "^2.0.0"
30
30
  },