grepmax 0.7.13 → 0.7.15

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.
@@ -293,6 +293,24 @@ const TOOLS = [
293
293
  },
294
294
  },
295
295
  },
296
+ {
297
+ name: "related_files",
298
+ description: "Find files related to a given file by shared symbol references. Shows dependencies (what this file calls) and dependents (what calls this file).",
299
+ inputSchema: {
300
+ type: "object",
301
+ properties: {
302
+ file: {
303
+ type: "string",
304
+ description: "File path relative to project root (e.g. 'src/lib/index/syncer.ts')",
305
+ },
306
+ limit: {
307
+ type: "number",
308
+ description: "Max related files per direction (default 10)",
309
+ },
310
+ },
311
+ required: ["file"],
312
+ },
313
+ },
296
314
  ];
297
315
  // ---------------------------------------------------------------------------
298
316
  // Helpers
@@ -1210,6 +1228,107 @@ exports.mcp = new commander_1.Command("mcp")
1210
1228
  }
1211
1229
  });
1212
1230
  }
1231
+ function handleRelatedFiles(args) {
1232
+ return __awaiter(this, void 0, void 0, function* () {
1233
+ const file = String(args.file || "");
1234
+ if (!file)
1235
+ return err("Missing required parameter: file");
1236
+ const limit = Math.min(Math.max(Number(args.limit) || 10, 1), 25);
1237
+ const absPath = path.resolve(projectRoot, file);
1238
+ try {
1239
+ const db = getVectorDb();
1240
+ const table = yield db.ensureTable();
1241
+ const fileChunks = yield table
1242
+ .query()
1243
+ .select(["defined_symbols", "referenced_symbols"])
1244
+ .where(`path = '${(0, filter_builder_1.escapeSqlString)(absPath)}'`)
1245
+ .toArray();
1246
+ if (fileChunks.length === 0) {
1247
+ return ok(`File not found in index: ${file}`);
1248
+ }
1249
+ const definedHere = new Set();
1250
+ const referencedHere = new Set();
1251
+ for (const chunk of fileChunks) {
1252
+ for (const s of toStringArray(chunk.defined_symbols))
1253
+ definedHere.add(s);
1254
+ for (const s of toStringArray(chunk.referenced_symbols))
1255
+ referencedHere.add(s);
1256
+ }
1257
+ // Dependencies: files that DEFINE symbols this file REFERENCES
1258
+ const depCounts = new Map();
1259
+ for (const sym of referencedHere) {
1260
+ if (definedHere.has(sym))
1261
+ continue;
1262
+ const rows = yield table
1263
+ .query()
1264
+ .select(["path"])
1265
+ .where(`array_contains(defined_symbols, '${(0, filter_builder_1.escapeSqlString)(sym)}')`)
1266
+ .limit(3)
1267
+ .toArray();
1268
+ for (const row of rows) {
1269
+ const p = String(row.path || "");
1270
+ if (p === absPath)
1271
+ continue;
1272
+ depCounts.set(p, (depCounts.get(p) || 0) + 1);
1273
+ }
1274
+ }
1275
+ // Dependents: files that REFERENCE symbols this file DEFINES
1276
+ const revCounts = new Map();
1277
+ for (const sym of definedHere) {
1278
+ const rows = yield table
1279
+ .query()
1280
+ .select(["path"])
1281
+ .where(`array_contains(referenced_symbols, '${(0, filter_builder_1.escapeSqlString)(sym)}')`)
1282
+ .limit(20)
1283
+ .toArray();
1284
+ for (const row of rows) {
1285
+ const p = String(row.path || "");
1286
+ if (p === absPath)
1287
+ continue;
1288
+ revCounts.set(p, (revCounts.get(p) || 0) + 1);
1289
+ }
1290
+ }
1291
+ const lines = [];
1292
+ lines.push(`Related files for ${file}:\n`);
1293
+ const topDeps = Array.from(depCounts.entries())
1294
+ .sort((a, b) => b[1] - a[1])
1295
+ .slice(0, limit);
1296
+ if (topDeps.length > 0) {
1297
+ lines.push("Dependencies (files this imports/calls):");
1298
+ for (const [p, count] of topDeps) {
1299
+ const rel = p.startsWith(`${projectRoot}/`)
1300
+ ? p.slice(projectRoot.length + 1)
1301
+ : p;
1302
+ lines.push(` ${rel.padEnd(40)} (${count} shared symbol${count > 1 ? "s" : ""})`);
1303
+ }
1304
+ }
1305
+ else {
1306
+ lines.push("Dependencies: none found");
1307
+ }
1308
+ lines.push("");
1309
+ const topRevs = Array.from(revCounts.entries())
1310
+ .sort((a, b) => b[1] - a[1])
1311
+ .slice(0, limit);
1312
+ if (topRevs.length > 0) {
1313
+ lines.push("Dependents (files that call this):");
1314
+ for (const [p, count] of topRevs) {
1315
+ const rel = p.startsWith(`${projectRoot}/`)
1316
+ ? p.slice(projectRoot.length + 1)
1317
+ : p;
1318
+ lines.push(` ${rel.padEnd(40)} (${count} shared symbol${count > 1 ? "s" : ""})`);
1319
+ }
1320
+ }
1321
+ else {
1322
+ lines.push("Dependents: none found");
1323
+ }
1324
+ return ok(lines.join("\n"));
1325
+ }
1326
+ catch (e) {
1327
+ const msg = e instanceof Error ? e.message : String(e);
1328
+ return err(`Related files failed: ${msg}`);
1329
+ }
1330
+ });
1331
+ }
1213
1332
  // --- MCP server setup ---
1214
1333
  const transport = new stdio_js_1.StdioServerTransport();
1215
1334
  const server = new index_js_1.Server({
@@ -1245,6 +1364,8 @@ exports.mcp = new commander_1.Command("mcp")
1245
1364
  return handleSummarizeDirectory(toolArgs);
1246
1365
  case "summarize_project":
1247
1366
  return handleSummarizeProject(toolArgs);
1367
+ case "related_files":
1368
+ return handleRelatedFiles(toolArgs);
1248
1369
  default:
1249
1370
  return err(`Unknown tool: ${name}`);
1250
1371
  }
@@ -58,7 +58,7 @@ const logger_1 = require("../utils/logger");
58
58
  const meta_cache_1 = require("../store/meta-cache");
59
59
  const vector_db_1 = require("../store/vector-db");
60
60
  const filter_builder_1 = require("../utils/filter-builder");
61
- const file_utils_1 = require("../utils/file-utils");
61
+ // isIndexableFile no longer used — extension check inlined for performance
62
62
  const lock_1 = require("../utils/lock");
63
63
  const project_registry_1 = require("../utils/project-registry");
64
64
  const project_root_1 = require("../utils/project-root");
@@ -329,19 +329,13 @@ function initialSync(options) {
329
329
  break;
330
330
  }
331
331
  const absPath = path.join(paths.root, relPath);
332
- // Check real path to avoid duplicates and loops
333
- try {
334
- const realPath = fs.realpathSync(absPath);
335
- if (visitedRealPaths.has(realPath))
336
- continue;
337
- visitedRealPaths.add(realPath);
338
- }
339
- catch (_g) {
340
- // Skip broken symlinks or inaccessible files
332
+ // Extension check only no stat syscall
333
+ const ext = path.extname(absPath).toLowerCase();
334
+ const basename = path.basename(absPath).toLowerCase();
335
+ if (!config_1.INDEXABLE_EXTENSIONS.has(ext) &&
336
+ !config_1.INDEXABLE_EXTENSIONS.has(basename)) {
341
337
  continue;
342
338
  }
343
- if (!(0, file_utils_1.isIndexableFile)(absPath))
344
- continue;
345
339
  walkedFiles++;
346
340
  yield schedule(() => __awaiter(this, void 0, void 0, function* () {
347
341
  if (signal === null || signal === void 0 ? void 0 : signal.aborted) {
@@ -349,8 +343,20 @@ function initialSync(options) {
349
343
  return;
350
344
  }
351
345
  try {
352
- const stats = yield fs.promises.stat(absPath);
353
- if (!(0, file_utils_1.isIndexableFile)(absPath, stats.size)) {
346
+ // Stat + symlink dedup (lstat to detect symlinks without resolving)
347
+ const stats = yield fs.promises.lstat(absPath);
348
+ if (stats.isSymbolicLink()) {
349
+ try {
350
+ const realPath = yield fs.promises.realpath(absPath);
351
+ if (visitedRealPaths.has(realPath))
352
+ return;
353
+ visitedRealPaths.add(realPath);
354
+ }
355
+ catch (_a) {
356
+ return; // Broken symlink
357
+ }
358
+ }
359
+ if (!stats.isFile() || stats.size === 0 || stats.size > config_1.MAX_FILE_SIZE_BYTES) {
354
360
  return;
355
361
  }
356
362
  // Use absolute path as the key for MetaCache
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "grepmax",
3
- "version": "0.7.13",
3
+ "version": "0.7.15",
4
4
  "author": "Robert Owens <robowens@me.com>",
5
5
  "homepage": "https://github.com/reowens/grepmax",
6
6
  "bugs": {
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "grepmax",
3
- "version": "0.7.13",
3
+ "version": "0.7.15",
4
4
  "description": "Semantic code search for Claude Code. Automatically indexes your project and provides intelligent search capabilities.",
5
5
  "author": {
6
6
  "name": "Robert Owens",
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  name: grepmax
3
3
  description: Semantic code search. Use alongside grep - grep for exact strings, gmax for concepts.
4
- allowed-tools: "mcp__grepmax__semantic_search, mcp__grepmax__search_all, mcp__grepmax__code_skeleton, mcp__grepmax__trace_calls, mcp__grepmax__list_symbols, mcp__grepmax__index_status, mcp__grepmax__summarize_directory, mcp__grepmax__summarize_project, Bash(gmax:*), Read"
4
+ allowed-tools: "mcp__grepmax__semantic_search, mcp__grepmax__search_all, mcp__grepmax__code_skeleton, mcp__grepmax__trace_calls, mcp__grepmax__list_symbols, mcp__grepmax__index_status, mcp__grepmax__summarize_directory, mcp__grepmax__summarize_project, mcp__grepmax__related_files, Bash(gmax:*), Read"
5
5
  ---
6
6
 
7
7
  ## What gmax does
@@ -85,6 +85,11 @@ Output: `symbolName [ORCH] exported src/path/file.ts:42`
85
85
  High-level project overview — languages, directory structure, role distribution, key symbols, entry points. Use when first exploring a new codebase.
86
86
  - `root` (optional): Project root path. Defaults to current project.
87
87
 
88
+ ### related_files
89
+ Find files related to a given file by shared symbol references. Shows dependencies (what this file calls) and dependents (what calls this file).
90
+ - `file` (required): File path relative to project root
91
+ - `limit` (optional): Max results per direction (default 10)
92
+
88
93
  ### index_status
89
94
  Check centralized index health — chunks, files, indexed directories, model info, watcher status.
90
95