grepmax 0.7.25 → 0.7.27
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 +6 -84
- package/dist/commands/recent.js +2 -14
- package/dist/lib/index/watcher.js +2 -3
- package/dist/lib/search/searcher.js +66 -75
- package/dist/lib/skeleton/symbol-extractor.js +29 -0
- package/dist/lib/utils/cache-check.js +8 -0
- package/dist/lib/utils/format-helpers.js +16 -0
- package/dist/lib/utils/import-extractor.js +83 -0
- package/package.json +1 -1
- package/plugins/grepmax/.claude-plugin/plugin.json +1 -1
package/dist/commands/mcp.js
CHANGED
|
@@ -67,10 +67,13 @@ const syncer_1 = require("../lib/index/syncer");
|
|
|
67
67
|
const meta_cache_1 = require("../lib/store/meta-cache");
|
|
68
68
|
const searcher_1 = require("../lib/search/searcher");
|
|
69
69
|
const retriever_1 = require("../lib/skeleton/retriever");
|
|
70
|
+
const symbol_extractor_1 = require("../lib/skeleton/symbol-extractor");
|
|
70
71
|
const skeletonizer_1 = require("../lib/skeleton/skeletonizer");
|
|
71
72
|
const vector_db_1 = require("../lib/store/vector-db");
|
|
72
73
|
const file_utils_1 = require("../lib/utils/file-utils");
|
|
73
74
|
const filter_builder_1 = require("../lib/utils/filter-builder");
|
|
75
|
+
const format_helpers_1 = require("../lib/utils/format-helpers");
|
|
76
|
+
const import_extractor_1 = require("../lib/utils/import-extractor");
|
|
74
77
|
const project_registry_1 = require("../lib/utils/project-registry");
|
|
75
78
|
const project_root_1 = require("../lib/utils/project-root");
|
|
76
79
|
const watcher_registry_1 = require("../lib/utils/watcher-registry");
|
|
@@ -507,49 +510,6 @@ exports.mcp = new commander_1.Command("mcp")
|
|
|
507
510
|
child.unref();
|
|
508
511
|
console.log(`[MCP] Started background watcher for ${projectRoot}`);
|
|
509
512
|
}
|
|
510
|
-
// --- Utilities ---
|
|
511
|
-
function extractImports(filePath) {
|
|
512
|
-
try {
|
|
513
|
-
const content = fs.readFileSync(filePath, "utf-8");
|
|
514
|
-
const lines = content.split("\n");
|
|
515
|
-
const importLines = [];
|
|
516
|
-
let inMultiLine = false;
|
|
517
|
-
for (const line of lines) {
|
|
518
|
-
const trimmed = line.trim();
|
|
519
|
-
if (inMultiLine) {
|
|
520
|
-
importLines.push(line);
|
|
521
|
-
if (trimmed === ")" || trimmed === ");")
|
|
522
|
-
inMultiLine = false;
|
|
523
|
-
continue;
|
|
524
|
-
}
|
|
525
|
-
if (!trimmed ||
|
|
526
|
-
trimmed.startsWith("//") ||
|
|
527
|
-
trimmed.startsWith("#") ||
|
|
528
|
-
trimmed.startsWith("*") ||
|
|
529
|
-
trimmed.startsWith("/*")) {
|
|
530
|
-
continue;
|
|
531
|
-
}
|
|
532
|
-
if (trimmed.startsWith("import ") ||
|
|
533
|
-
trimmed.startsWith("from ") ||
|
|
534
|
-
(trimmed.startsWith("const ") && trimmed.includes("require(")) ||
|
|
535
|
-
trimmed.startsWith("require(") ||
|
|
536
|
-
trimmed.startsWith("use ") ||
|
|
537
|
-
trimmed.startsWith("using ") ||
|
|
538
|
-
trimmed.startsWith("package ")) {
|
|
539
|
-
importLines.push(line);
|
|
540
|
-
if (trimmed.includes("(") && !trimmed.includes(")")) {
|
|
541
|
-
inMultiLine = true;
|
|
542
|
-
}
|
|
543
|
-
continue;
|
|
544
|
-
}
|
|
545
|
-
break;
|
|
546
|
-
}
|
|
547
|
-
return importLines.length > 0 ? importLines.join("\n") : "";
|
|
548
|
-
}
|
|
549
|
-
catch (_a) {
|
|
550
|
-
return "";
|
|
551
|
-
}
|
|
552
|
-
}
|
|
553
513
|
// --- Tool handlers ---
|
|
554
514
|
function handleSemanticSearch(args_1) {
|
|
555
515
|
return __awaiter(this, arguments, void 0, function* (args, searchAll = false) {
|
|
@@ -703,7 +663,7 @@ exports.mcp = new commander_1.Command("mcp")
|
|
|
703
663
|
snippet;
|
|
704
664
|
if (includeImports && absPath) {
|
|
705
665
|
if (!importCache.has(absPath)) {
|
|
706
|
-
importCache.set(absPath, extractImports(absPath));
|
|
666
|
+
importCache.set(absPath, (0, import_extractor_1.extractImports)(absPath));
|
|
707
667
|
}
|
|
708
668
|
const imports = importCache.get(absPath);
|
|
709
669
|
if (imports) {
|
|
@@ -912,32 +872,7 @@ exports.mcp = new commander_1.Command("mcp")
|
|
|
912
872
|
const annotated = sourceContent
|
|
913
873
|
? annotateSkeletonLines(skeleton, sourceContent)
|
|
914
874
|
: skeleton;
|
|
915
|
-
const symbols = annotated
|
|
916
|
-
.split("\n")
|
|
917
|
-
.filter((l) => /^\s*\d+│/.test(l))
|
|
918
|
-
.map((l) => {
|
|
919
|
-
var _a, _b, _c;
|
|
920
|
-
const m = l.match(/^\s*(\d+)│(.+)/);
|
|
921
|
-
if (!m)
|
|
922
|
-
return null;
|
|
923
|
-
const line = Number.parseInt(m[1], 10);
|
|
924
|
-
const sig = m[2].trim();
|
|
925
|
-
const exported = sig.includes("export ");
|
|
926
|
-
const type = ((_a = sig.match(/\b(class|interface|type|function|def|fn|func)\b/)) === null || _a === void 0 ? void 0 : _a[1]) || "other";
|
|
927
|
-
const name = ((_b = sig.match(/(?:function|class|interface|type|def|fn|func)\s+(\w+)/)) === null || _b === void 0 ? void 0 : _b[1]) ||
|
|
928
|
-
((_c = sig.match(/^(?:async\s+)?(\w+)\s*[(<]/)) === null || _c === void 0 ? void 0 : _c[1]) ||
|
|
929
|
-
"unknown";
|
|
930
|
-
return {
|
|
931
|
-
name,
|
|
932
|
-
line,
|
|
933
|
-
signature: sig
|
|
934
|
-
.replace(/\s*\{?\s*\/\/.*$/, "")
|
|
935
|
-
.trim(),
|
|
936
|
-
type,
|
|
937
|
-
exported,
|
|
938
|
-
};
|
|
939
|
-
})
|
|
940
|
-
.filter((s) => s !== null && s.name !== "unknown");
|
|
875
|
+
const symbols = (0, symbol_extractor_1.extractSymbolsFromSkeleton)(annotated);
|
|
941
876
|
jsonFiles.push({
|
|
942
877
|
file: t,
|
|
943
878
|
language: language || path.extname(t).slice(1),
|
|
@@ -1433,19 +1368,6 @@ exports.mcp = new commander_1.Command("mcp")
|
|
|
1433
1368
|
}
|
|
1434
1369
|
});
|
|
1435
1370
|
}
|
|
1436
|
-
function formatTimeAgo(ms) {
|
|
1437
|
-
const sec = Math.floor(ms / 1000);
|
|
1438
|
-
if (sec < 60)
|
|
1439
|
-
return `${sec}s ago`;
|
|
1440
|
-
const min = Math.floor(sec / 60);
|
|
1441
|
-
if (min < 60)
|
|
1442
|
-
return `${min}m ago`;
|
|
1443
|
-
const hr = Math.floor(min / 60);
|
|
1444
|
-
if (hr < 24)
|
|
1445
|
-
return `${hr}h ago`;
|
|
1446
|
-
const days = Math.floor(hr / 24);
|
|
1447
|
-
return `${days}d ago`;
|
|
1448
|
-
}
|
|
1449
1371
|
function handleRecentChanges(args) {
|
|
1450
1372
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1451
1373
|
var _a, e_1, _b, _c;
|
|
@@ -1488,7 +1410,7 @@ exports.mcp = new commander_1.Command("mcp")
|
|
|
1488
1410
|
const rel = f.path.startsWith(prefix)
|
|
1489
1411
|
? f.path.slice(prefix.length)
|
|
1490
1412
|
: f.path;
|
|
1491
|
-
const ago = formatTimeAgo(now - f.mtimeMs);
|
|
1413
|
+
const ago = (0, format_helpers_1.formatTimeAgo)(now - f.mtimeMs);
|
|
1492
1414
|
lines.push(` ${ago.padEnd(10)} ${rel}`);
|
|
1493
1415
|
}
|
|
1494
1416
|
return ok(lines.join("\n"));
|
package/dist/commands/recent.js
CHANGED
|
@@ -55,20 +55,8 @@ const commander_1 = require("commander");
|
|
|
55
55
|
const config_1 = require("../config");
|
|
56
56
|
const meta_cache_1 = require("../lib/store/meta-cache");
|
|
57
57
|
const exit_1 = require("../lib/utils/exit");
|
|
58
|
+
const format_helpers_1 = require("../lib/utils/format-helpers");
|
|
58
59
|
const project_root_1 = require("../lib/utils/project-root");
|
|
59
|
-
function formatTimeAgo(ms) {
|
|
60
|
-
const sec = Math.floor(ms / 1000);
|
|
61
|
-
if (sec < 60)
|
|
62
|
-
return `${sec}s ago`;
|
|
63
|
-
const min = Math.floor(sec / 60);
|
|
64
|
-
if (min < 60)
|
|
65
|
-
return `${min}m ago`;
|
|
66
|
-
const hr = Math.floor(min / 60);
|
|
67
|
-
if (hr < 24)
|
|
68
|
-
return `${hr}h ago`;
|
|
69
|
-
const days = Math.floor(hr / 24);
|
|
70
|
-
return `${days}d ago`;
|
|
71
|
-
}
|
|
72
60
|
exports.recent = new commander_1.Command("recent")
|
|
73
61
|
.description("Show recently modified indexed files")
|
|
74
62
|
.option("-l, --limit <n>", "Max files (default 20)", "20")
|
|
@@ -114,7 +102,7 @@ exports.recent = new commander_1.Command("recent")
|
|
|
114
102
|
const rel = f.path.startsWith(prefix)
|
|
115
103
|
? f.path.slice(prefix.length)
|
|
116
104
|
: f.path;
|
|
117
|
-
const ago = formatTimeAgo(now - f.mtimeMs);
|
|
105
|
+
const ago = (0, format_helpers_1.formatTimeAgo)(now - f.mtimeMs);
|
|
118
106
|
console.log(` ${ago.padEnd(10)} ${rel}`);
|
|
119
107
|
}
|
|
120
108
|
}
|
|
@@ -49,6 +49,7 @@ const path = __importStar(require("node:path"));
|
|
|
49
49
|
const chokidar_1 = require("chokidar");
|
|
50
50
|
const filter_builder_1 = require("../utils/filter-builder");
|
|
51
51
|
const config_1 = require("../../config");
|
|
52
|
+
const cache_check_1 = require("../utils/cache-check");
|
|
52
53
|
const file_utils_1 = require("../utils/file-utils");
|
|
53
54
|
const logger_1 = require("../utils/logger");
|
|
54
55
|
const lock_1 = require("../utils/lock");
|
|
@@ -138,9 +139,7 @@ function startWatcher(opts) {
|
|
|
138
139
|
continue;
|
|
139
140
|
// Quick mtime/size check — skip worker pool if unchanged
|
|
140
141
|
const cached = metaCache.get(absPath);
|
|
141
|
-
if (cached
|
|
142
|
-
cached.mtimeMs === stats.mtimeMs &&
|
|
143
|
-
cached.size === stats.size) {
|
|
142
|
+
if ((0, cache_check_1.isFileCached)(cached, stats)) {
|
|
144
143
|
continue;
|
|
145
144
|
}
|
|
146
145
|
const result = yield pool.processFile({
|
|
@@ -10,10 +10,67 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.Searcher = void 0;
|
|
13
|
+
exports.buildWhereClause = buildWhereClause;
|
|
13
14
|
const config_1 = require("../../config");
|
|
14
15
|
const filter_builder_1 = require("../utils/filter-builder");
|
|
15
16
|
const pool_1 = require("../workers/pool");
|
|
16
17
|
const intent_1 = require("./intent");
|
|
18
|
+
function buildWhereClause(pathPrefix, filters, searchIntent) {
|
|
19
|
+
var _a;
|
|
20
|
+
const parts = [];
|
|
21
|
+
if (pathPrefix) {
|
|
22
|
+
parts.push(`path LIKE '${(0, filter_builder_1.escapeSqlString)((0, filter_builder_1.normalizePath)(pathPrefix))}%'`);
|
|
23
|
+
}
|
|
24
|
+
const fileFilter = filters === null || filters === void 0 ? void 0 : filters.file;
|
|
25
|
+
if (typeof fileFilter === "string" && fileFilter) {
|
|
26
|
+
parts.push(`path LIKE '%/${(0, filter_builder_1.escapeSqlString)(fileFilter)}'`);
|
|
27
|
+
}
|
|
28
|
+
const excludeFilter = filters === null || filters === void 0 ? void 0 : filters.exclude;
|
|
29
|
+
if (typeof excludeFilter === "string" && excludeFilter) {
|
|
30
|
+
const absExclude = pathPrefix
|
|
31
|
+
? (0, filter_builder_1.normalizePath)(pathPrefix + excludeFilter)
|
|
32
|
+
: excludeFilter;
|
|
33
|
+
parts.push(`path NOT LIKE '${(0, filter_builder_1.escapeSqlString)(absExclude)}%'`);
|
|
34
|
+
}
|
|
35
|
+
const langFilter = filters === null || filters === void 0 ? void 0 : filters.language;
|
|
36
|
+
if (typeof langFilter === "string" && langFilter) {
|
|
37
|
+
const ext = langFilter.startsWith(".") ? langFilter : `.${langFilter}`;
|
|
38
|
+
parts.push(`path LIKE '%${(0, filter_builder_1.escapeSqlString)(ext)}'`);
|
|
39
|
+
}
|
|
40
|
+
const roleFilter = filters === null || filters === void 0 ? void 0 : filters.role;
|
|
41
|
+
if (typeof roleFilter === "string" && roleFilter) {
|
|
42
|
+
parts.push(`role = '${(0, filter_builder_1.escapeSqlString)(roleFilter)}'`);
|
|
43
|
+
}
|
|
44
|
+
const projectRoots = filters === null || filters === void 0 ? void 0 : filters.project_roots;
|
|
45
|
+
if (typeof projectRoots === "string" && projectRoots) {
|
|
46
|
+
const roots = projectRoots.split(",");
|
|
47
|
+
const clauses = roots.map((r) => {
|
|
48
|
+
const prefix = r.endsWith("/") ? r : `${r}/`;
|
|
49
|
+
return `path LIKE '${(0, filter_builder_1.escapeSqlString)(prefix)}%'`;
|
|
50
|
+
});
|
|
51
|
+
parts.push(`(${clauses.join(" OR ")})`);
|
|
52
|
+
}
|
|
53
|
+
const excludeRoots = filters === null || filters === void 0 ? void 0 : filters.exclude_project_roots;
|
|
54
|
+
if (typeof excludeRoots === "string" && excludeRoots) {
|
|
55
|
+
for (const r of excludeRoots.split(",")) {
|
|
56
|
+
const prefix = r.endsWith("/") ? r : `${r}/`;
|
|
57
|
+
parts.push(`path NOT LIKE '${(0, filter_builder_1.escapeSqlString)(prefix)}%'`);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
const defFilter = filters === null || filters === void 0 ? void 0 : filters.def;
|
|
61
|
+
if (typeof defFilter === "string" && defFilter) {
|
|
62
|
+
parts.push(`array_contains(defined_symbols, '${(0, filter_builder_1.escapeSqlString)(defFilter)}')`);
|
|
63
|
+
}
|
|
64
|
+
else if (searchIntent.type === "DEFINITION" &&
|
|
65
|
+
((_a = searchIntent.filters) === null || _a === void 0 ? void 0 : _a.definitionsOnly)) {
|
|
66
|
+
parts.push(`(role = 'DEFINITION' OR array_length(defined_symbols) > 0)`);
|
|
67
|
+
}
|
|
68
|
+
const refFilter = filters === null || filters === void 0 ? void 0 : filters.ref;
|
|
69
|
+
if (typeof refFilter === "string" && refFilter) {
|
|
70
|
+
parts.push(`array_contains(referenced_symbols, '${(0, filter_builder_1.escapeSqlString)(refFilter)}')`);
|
|
71
|
+
}
|
|
72
|
+
return parts.length > 0 ? parts.join(" AND ") : undefined;
|
|
73
|
+
}
|
|
17
74
|
class Searcher {
|
|
18
75
|
constructor(db) {
|
|
19
76
|
this.db = db;
|
|
@@ -254,7 +311,7 @@ class Searcher {
|
|
|
254
311
|
}
|
|
255
312
|
search(query, top_k, _search_options, _filters, pathPrefix, intent, signal) {
|
|
256
313
|
return __awaiter(this, void 0, void 0, function* () {
|
|
257
|
-
var _a, _b, _c, _d, _e, _f, _g
|
|
314
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
258
315
|
const finalLimit = top_k !== null && top_k !== void 0 ? top_k : 10;
|
|
259
316
|
const doRerank = (_a = _search_options === null || _search_options === void 0 ? void 0 : _search_options.rerank) !== null && _a !== void 0 ? _a : true;
|
|
260
317
|
const searchIntent = intent || (0, intent_1.detectIntent)(query);
|
|
@@ -273,74 +330,8 @@ class Searcher {
|
|
|
273
330
|
if (colbertDim !== config_1.CONFIG.COLBERT_DIM) {
|
|
274
331
|
throw new Error(`[Searcher] Query ColBERT dim (${colbertDim}) != Config (${config_1.CONFIG.COLBERT_DIM})`);
|
|
275
332
|
}
|
|
276
|
-
const
|
|
277
|
-
|
|
278
|
-
whereClauseParts.push(`path LIKE '${(0, filter_builder_1.escapeSqlString)((0, filter_builder_1.normalizePath)(pathPrefix))}%'`);
|
|
279
|
-
}
|
|
280
|
-
// Handle file name filter
|
|
281
|
-
const fileFilter = _filters === null || _filters === void 0 ? void 0 : _filters.file;
|
|
282
|
-
if (typeof fileFilter === "string" && fileFilter) {
|
|
283
|
-
whereClauseParts.push(`path LIKE '%/${(0, filter_builder_1.escapeSqlString)(fileFilter)}'`);
|
|
284
|
-
}
|
|
285
|
-
// Handle exclude filter
|
|
286
|
-
const excludeFilter = _filters === null || _filters === void 0 ? void 0 : _filters.exclude;
|
|
287
|
-
if (typeof excludeFilter === "string" && excludeFilter) {
|
|
288
|
-
const absExclude = pathPrefix
|
|
289
|
-
? (0, filter_builder_1.normalizePath)(pathPrefix + excludeFilter)
|
|
290
|
-
: excludeFilter;
|
|
291
|
-
whereClauseParts.push(`path NOT LIKE '${(0, filter_builder_1.escapeSqlString)(absExclude)}%'`);
|
|
292
|
-
}
|
|
293
|
-
// Handle language filter (by file extension)
|
|
294
|
-
const langFilter = _filters === null || _filters === void 0 ? void 0 : _filters.language;
|
|
295
|
-
if (typeof langFilter === "string" && langFilter) {
|
|
296
|
-
const ext = langFilter.startsWith(".") ? langFilter : `.${langFilter}`;
|
|
297
|
-
whereClauseParts.push(`path LIKE '%${(0, filter_builder_1.escapeSqlString)(ext)}'`);
|
|
298
|
-
}
|
|
299
|
-
// Handle role filter
|
|
300
|
-
const roleFilter = _filters === null || _filters === void 0 ? void 0 : _filters.role;
|
|
301
|
-
if (typeof roleFilter === "string" && roleFilter) {
|
|
302
|
-
whereClauseParts.push(`role = '${(0, filter_builder_1.escapeSqlString)(roleFilter)}'`);
|
|
303
|
-
}
|
|
304
|
-
// Handle project roots filter (from search_all projects param)
|
|
305
|
-
const projectRoots = _filters === null || _filters === void 0 ? void 0 : _filters.project_roots;
|
|
306
|
-
if (typeof projectRoots === "string" && projectRoots) {
|
|
307
|
-
const roots = projectRoots.split(",");
|
|
308
|
-
const clauses = roots.map((r) => {
|
|
309
|
-
const prefix = r.endsWith("/") ? r : `${r}/`;
|
|
310
|
-
return `path LIKE '${(0, filter_builder_1.escapeSqlString)(prefix)}%'`;
|
|
311
|
-
});
|
|
312
|
-
whereClauseParts.push(`(${clauses.join(" OR ")})`);
|
|
313
|
-
}
|
|
314
|
-
// Handle exclude project roots filter
|
|
315
|
-
const excludeRoots = _filters === null || _filters === void 0 ? void 0 : _filters.exclude_project_roots;
|
|
316
|
-
if (typeof excludeRoots === "string" && excludeRoots) {
|
|
317
|
-
for (const r of excludeRoots.split(",")) {
|
|
318
|
-
const prefix = r.endsWith("/") ? r : `${r}/`;
|
|
319
|
-
whereClauseParts.push(`path NOT LIKE '${(0, filter_builder_1.escapeSqlString)(prefix)}%'`);
|
|
320
|
-
}
|
|
321
|
-
}
|
|
322
|
-
// Handle --def (definition) filter
|
|
323
|
-
const defFilter = _filters === null || _filters === void 0 ? void 0 : _filters.def;
|
|
324
|
-
if (typeof defFilter === "string" && defFilter) {
|
|
325
|
-
whereClauseParts.push(`array_contains(defined_symbols, '${(0, filter_builder_1.escapeSqlString)(defFilter)}')`);
|
|
326
|
-
}
|
|
327
|
-
else if (searchIntent.type === "DEFINITION" &&
|
|
328
|
-
((_b = searchIntent.filters) === null || _b === void 0 ? void 0 : _b.definitionsOnly)) {
|
|
329
|
-
// If intent is DEFINITION but no specific symbol provided, filter by role
|
|
330
|
-
whereClauseParts.push(`(role = 'DEFINITION' OR array_length(defined_symbols) > 0)`);
|
|
331
|
-
}
|
|
332
|
-
// Handle --ref (reference) filter
|
|
333
|
-
const refFilter = _filters === null || _filters === void 0 ? void 0 : _filters.ref;
|
|
334
|
-
if (typeof refFilter === "string" && refFilter) {
|
|
335
|
-
whereClauseParts.push(`array_contains(referenced_symbols, '${(0, filter_builder_1.escapeSqlString)(refFilter)}')`);
|
|
336
|
-
}
|
|
337
|
-
else if (searchIntent.type === "USAGE" &&
|
|
338
|
-
((_c = searchIntent.filters) === null || _c === void 0 ? void 0 : _c.usagesOnly)) {
|
|
339
|
-
// If intent is USAGE, we might want to filter out definitions?
|
|
340
|
-
// For now, let's just rely on boosting.
|
|
341
|
-
}
|
|
342
|
-
const whereClause = whereClauseParts.length > 0 ? whereClauseParts.join(" AND ") : undefined;
|
|
343
|
-
const envPreK = Number.parseInt((_d = process.env.GMAX_PRE_K) !== null && _d !== void 0 ? _d : "", 10);
|
|
333
|
+
const whereClause = buildWhereClause(pathPrefix, _filters, searchIntent);
|
|
334
|
+
const envPreK = Number.parseInt((_b = process.env.GMAX_PRE_K) !== null && _b !== void 0 ? _b : "", 10);
|
|
344
335
|
const PRE_RERANK_K = Number.isFinite(envPreK) && envPreK > 0
|
|
345
336
|
? envPreK
|
|
346
337
|
: Math.max(finalLimit * 5, 500);
|
|
@@ -348,7 +339,7 @@ class Searcher {
|
|
|
348
339
|
try {
|
|
349
340
|
table = yield this.db.ensureTable();
|
|
350
341
|
}
|
|
351
|
-
catch (
|
|
342
|
+
catch (_h) {
|
|
352
343
|
return { data: [] };
|
|
353
344
|
}
|
|
354
345
|
// Ensure FTS index exists (lazy init, retry periodically on failure)
|
|
@@ -417,17 +408,17 @@ class Searcher {
|
|
|
417
408
|
.filter(Boolean);
|
|
418
409
|
// Item 8: Widen PRE_RERANK_K
|
|
419
410
|
// Retrieve a wide set for Stage 1 filtering
|
|
420
|
-
const envStage1 = Number.parseInt((
|
|
411
|
+
const envStage1 = Number.parseInt((_c = process.env.GMAX_STAGE1_K) !== null && _c !== void 0 ? _c : "", 10);
|
|
421
412
|
const STAGE1_K = Number.isFinite(envStage1) && envStage1 > 0 ? envStage1 : 200;
|
|
422
413
|
const topCandidates = fused.slice(0, STAGE1_K);
|
|
423
414
|
// Item 9: Two-stage rerank
|
|
424
415
|
// Stage 1: Cheap pooled cosine filter
|
|
425
416
|
let stage2Candidates = topCandidates;
|
|
426
|
-
const envStage2K = Number.parseInt((
|
|
417
|
+
const envStage2K = Number.parseInt((_d = process.env.GMAX_STAGE2_K) !== null && _d !== void 0 ? _d : "", 10);
|
|
427
418
|
const STAGE2_K = Number.isFinite(envStage2K) && envStage2K > 0 ? envStage2K : 40;
|
|
428
|
-
const envRerankTop = Number.parseInt((
|
|
419
|
+
const envRerankTop = Number.parseInt((_e = process.env.GMAX_RERANK_TOP) !== null && _e !== void 0 ? _e : "", 10);
|
|
429
420
|
const RERANK_TOP = Number.isFinite(envRerankTop) && envRerankTop > 0 ? envRerankTop : 20;
|
|
430
|
-
const envBlend = Number.parseFloat((
|
|
421
|
+
const envBlend = Number.parseFloat((_f = process.env.GMAX_RERANK_BLEND) !== null && _f !== void 0 ? _f : "");
|
|
431
422
|
const FUSED_WEIGHT = Number.isFinite(envBlend) && envBlend >= 0 ? envBlend : 0.5;
|
|
432
423
|
if (queryPooled && topCandidates.length > STAGE2_K) {
|
|
433
424
|
const cosineScores = topCandidates.map((doc) => {
|
|
@@ -493,7 +484,7 @@ class Searcher {
|
|
|
493
484
|
// Item 10: Per-file diversification
|
|
494
485
|
const seenFiles = new Map();
|
|
495
486
|
const diversified = [];
|
|
496
|
-
const envMaxPerFile = Number.parseInt((
|
|
487
|
+
const envMaxPerFile = Number.parseInt((_g = process.env.GMAX_MAX_PER_FILE) !== null && _g !== void 0 ? _g : "", 10);
|
|
497
488
|
const MAX_PER_FILE = Number.isFinite(envMaxPerFile) && envMaxPerFile > 0 ? envMaxPerFile : 3;
|
|
498
489
|
for (const item of uniqueScored) {
|
|
499
490
|
const path = item.record.path || "";
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.extractSymbolsFromSkeleton = extractSymbolsFromSkeleton;
|
|
4
|
+
function extractSymbolsFromSkeleton(annotatedSkeleton) {
|
|
5
|
+
return annotatedSkeleton
|
|
6
|
+
.split("\n")
|
|
7
|
+
.filter((l) => /^\s*\d+│/.test(l))
|
|
8
|
+
.map((l) => {
|
|
9
|
+
var _a, _b, _c;
|
|
10
|
+
const m = l.match(/^\s*(\d+)│(.+)/);
|
|
11
|
+
if (!m)
|
|
12
|
+
return null;
|
|
13
|
+
const line = Number.parseInt(m[1], 10);
|
|
14
|
+
const sig = m[2].trim();
|
|
15
|
+
const exported = sig.includes("export ");
|
|
16
|
+
const type = ((_a = sig.match(/\b(class|interface|type|function|def|fn|func)\b/)) === null || _a === void 0 ? void 0 : _a[1]) || "other";
|
|
17
|
+
const name = ((_b = sig.match(/(?:function|class|interface|type|def|fn|func)\s+(\w+)/)) === null || _b === void 0 ? void 0 : _b[1]) ||
|
|
18
|
+
((_c = sig.match(/^(?:async\s+)?(\w+)\s*[(<]/)) === null || _c === void 0 ? void 0 : _c[1]) ||
|
|
19
|
+
"unknown";
|
|
20
|
+
return {
|
|
21
|
+
name,
|
|
22
|
+
line,
|
|
23
|
+
signature: sig.replace(/\s*\{?\s*\/\/.*$/, "").trim(),
|
|
24
|
+
type,
|
|
25
|
+
exported,
|
|
26
|
+
};
|
|
27
|
+
})
|
|
28
|
+
.filter((s) => s !== null && s.name !== "unknown");
|
|
29
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isFileCached = isFileCached;
|
|
4
|
+
function isFileCached(cached, stats) {
|
|
5
|
+
if (!cached)
|
|
6
|
+
return false;
|
|
7
|
+
return cached.mtimeMs === stats.mtimeMs && cached.size === stats.size;
|
|
8
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.formatTimeAgo = formatTimeAgo;
|
|
4
|
+
function formatTimeAgo(ms) {
|
|
5
|
+
const sec = Math.floor(ms / 1000);
|
|
6
|
+
if (sec < 60)
|
|
7
|
+
return `${sec}s ago`;
|
|
8
|
+
const min = Math.floor(sec / 60);
|
|
9
|
+
if (min < 60)
|
|
10
|
+
return `${min}m ago`;
|
|
11
|
+
const hr = Math.floor(min / 60);
|
|
12
|
+
if (hr < 24)
|
|
13
|
+
return `${hr}h ago`;
|
|
14
|
+
const days = Math.floor(hr / 24);
|
|
15
|
+
return `${days}d ago`;
|
|
16
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.extractImports = extractImports;
|
|
37
|
+
exports.extractImportsFromContent = extractImportsFromContent;
|
|
38
|
+
const fs = __importStar(require("node:fs"));
|
|
39
|
+
function extractImports(filePath) {
|
|
40
|
+
try {
|
|
41
|
+
const content = fs.readFileSync(filePath, "utf-8");
|
|
42
|
+
return extractImportsFromContent(content);
|
|
43
|
+
}
|
|
44
|
+
catch (_a) {
|
|
45
|
+
return "";
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
function extractImportsFromContent(content) {
|
|
49
|
+
const lines = content.split("\n");
|
|
50
|
+
const importLines = [];
|
|
51
|
+
let inMultiLine = false;
|
|
52
|
+
for (const line of lines) {
|
|
53
|
+
const trimmed = line.trim();
|
|
54
|
+
if (inMultiLine) {
|
|
55
|
+
importLines.push(line);
|
|
56
|
+
if (trimmed === ")" || trimmed === ");")
|
|
57
|
+
inMultiLine = false;
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
if (!trimmed ||
|
|
61
|
+
trimmed.startsWith("//") ||
|
|
62
|
+
trimmed.startsWith("#") ||
|
|
63
|
+
trimmed.startsWith("*") ||
|
|
64
|
+
trimmed.startsWith("/*")) {
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
if (trimmed.startsWith("import ") ||
|
|
68
|
+
trimmed.startsWith("from ") ||
|
|
69
|
+
(trimmed.startsWith("const ") && trimmed.includes("require(")) ||
|
|
70
|
+
trimmed.startsWith("require(") ||
|
|
71
|
+
trimmed.startsWith("use ") ||
|
|
72
|
+
trimmed.startsWith("using ") ||
|
|
73
|
+
trimmed.startsWith("package ")) {
|
|
74
|
+
importLines.push(line);
|
|
75
|
+
if (trimmed.includes("(") && !trimmed.includes(")")) {
|
|
76
|
+
inMultiLine = true;
|
|
77
|
+
}
|
|
78
|
+
continue;
|
|
79
|
+
}
|
|
80
|
+
break;
|
|
81
|
+
}
|
|
82
|
+
return importLines.length > 0 ? importLines.join("\n") : "";
|
|
83
|
+
}
|
package/package.json
CHANGED