grepmax 0.3.0 → 0.3.1
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
|
@@ -335,21 +335,21 @@ exports.mcp = new commander_1.Command("mcp")
|
|
|
335
335
|
const query = String(args.query || "");
|
|
336
336
|
if (!query)
|
|
337
337
|
return err("Missing required parameter: query");
|
|
338
|
-
const limit = Math.min(Math.max(Number(args.limit) ||
|
|
338
|
+
const limit = Math.min(Math.max(Number(args.limit) || 3, 1), 50);
|
|
339
339
|
yield ensureIndexReady();
|
|
340
340
|
try {
|
|
341
341
|
const searcher = getSearcher();
|
|
342
|
-
// Determine path prefix for
|
|
342
|
+
// Determine path prefix and display root for relative paths
|
|
343
343
|
let pathPrefix;
|
|
344
|
+
let displayRoot = projectRoot;
|
|
344
345
|
if (!searchAll) {
|
|
345
|
-
// Resolve search root — default to project root
|
|
346
346
|
const searchRoot = typeof args.root === "string"
|
|
347
347
|
? path.resolve(args.root)
|
|
348
348
|
: path.resolve(projectRoot);
|
|
349
|
+
displayRoot = searchRoot;
|
|
349
350
|
pathPrefix = searchRoot.endsWith("/")
|
|
350
351
|
? searchRoot
|
|
351
352
|
: `${searchRoot}/`;
|
|
352
|
-
// If a sub-path is specified, append it
|
|
353
353
|
if (typeof args.path === "string") {
|
|
354
354
|
pathPrefix = path.join(searchRoot, args.path);
|
|
355
355
|
if (!pathPrefix.endsWith("/"))
|
|
@@ -362,47 +362,47 @@ exports.mcp = new commander_1.Command("mcp")
|
|
|
362
362
|
}
|
|
363
363
|
const minScore = typeof args.min_score === "number" ? args.min_score : 0;
|
|
364
364
|
const maxPerFile = typeof args.max_per_file === "number" ? args.max_per_file : 0;
|
|
365
|
-
const MAX_SNIPPET_LINES =
|
|
366
|
-
let
|
|
367
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l
|
|
368
|
-
const
|
|
365
|
+
const MAX_SNIPPET_LINES = 4;
|
|
366
|
+
let results = result.data.map((r) => {
|
|
367
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
|
|
368
|
+
const absPath = (_c = (_a = r.path) !== null && _a !== void 0 ? _a : (_b = r.metadata) === null || _b === void 0 ? void 0 : _b.path) !== null && _c !== void 0 ? _c : "";
|
|
369
|
+
const relPath = absPath.startsWith(displayRoot)
|
|
370
|
+
? absPath.slice(displayRoot.length + 1)
|
|
371
|
+
: absPath;
|
|
372
|
+
const startLine = (_f = (_d = r.startLine) !== null && _d !== void 0 ? _d : (_e = r.generated_metadata) === null || _e === void 0 ? void 0 : _e.start_line) !== null && _f !== void 0 ? _f : 0;
|
|
373
|
+
const endLine = (_j = (_g = r.endLine) !== null && _g !== void 0 ? _g : (_h = r.generated_metadata) === null || _h === void 0 ? void 0 : _h.end_line) !== null && _j !== void 0 ? _j : 0;
|
|
374
|
+
const score = typeof r.score === "number" ? r.score.toFixed(2) : "0";
|
|
375
|
+
const role = ((_k = r.role) !== null && _k !== void 0 ? _k : "IMPL").slice(0, 4).toUpperCase();
|
|
376
|
+
const defs = toStringArray((_l = r.definedSymbols) !== null && _l !== void 0 ? _l : r.defined_symbols).slice(0, 3);
|
|
369
377
|
const raw = typeof r.content === "string"
|
|
370
378
|
? r.content
|
|
371
379
|
: typeof r.text === "string"
|
|
372
380
|
? r.text
|
|
373
381
|
: "";
|
|
374
|
-
// Add line numbers and cap at MAX_SNIPPET_LINES
|
|
375
382
|
const lines = raw.split("\n");
|
|
376
383
|
const capped = lines.slice(0, MAX_SNIPPET_LINES);
|
|
377
384
|
const numbered = capped.map((line, i) => `${startLine + i + 1}│${line}`);
|
|
378
|
-
const
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
return {
|
|
382
|
-
path: (_f = (_d = r.path) !== null && _d !== void 0 ? _d : (_e = r.metadata) === null || _e === void 0 ? void 0 : _e.path) !== null && _f !== void 0 ? _f : "",
|
|
383
|
-
startLine,
|
|
384
|
-
endLine: (_j = (_g = r.endLine) !== null && _g !== void 0 ? _g : (_h = r.generated_metadata) === null || _h === void 0 ? void 0 : _h.end_line) !== null && _j !== void 0 ? _j : 0,
|
|
385
|
-
score: typeof r.score === "number" ? +r.score.toFixed(3) : 0,
|
|
386
|
-
role: (_k = r.role) !== null && _k !== void 0 ? _k : "IMPLEMENTATION",
|
|
387
|
-
confidence: (_l = r.confidence) !== null && _l !== void 0 ? _l : "Unknown",
|
|
388
|
-
definedSymbols: toStringArray((_m = r.definedSymbols) !== null && _m !== void 0 ? _m : r.defined_symbols).slice(0, 5),
|
|
389
|
-
snippet,
|
|
390
|
-
};
|
|
385
|
+
const header = `${relPath}:${startLine + 1}-${endLine + 1} [${role}] score:${score}${defs.length ? ` defines:${defs.join(",")}` : ""}`;
|
|
386
|
+
const snippet = numbered.join("\n");
|
|
387
|
+
return { absPath, header, snippet, score: +score };
|
|
391
388
|
});
|
|
392
389
|
if (minScore > 0) {
|
|
393
|
-
|
|
390
|
+
results = results.filter((r) => r.score >= minScore);
|
|
394
391
|
}
|
|
395
392
|
if (maxPerFile > 0) {
|
|
396
393
|
const counts = new Map();
|
|
397
|
-
|
|
398
|
-
const count = counts.get(r.
|
|
394
|
+
results = results.filter((r) => {
|
|
395
|
+
const count = counts.get(r.absPath) || 0;
|
|
399
396
|
if (count >= maxPerFile)
|
|
400
397
|
return false;
|
|
401
|
-
counts.set(r.
|
|
398
|
+
counts.set(r.absPath, count + 1);
|
|
402
399
|
return true;
|
|
403
400
|
});
|
|
404
401
|
}
|
|
405
|
-
|
|
402
|
+
const output = results
|
|
403
|
+
.map((r) => `${r.header}\n${r.snippet}`)
|
|
404
|
+
.join("\n\n");
|
|
405
|
+
return ok(output);
|
|
406
406
|
}
|
|
407
407
|
catch (e) {
|
|
408
408
|
const msg = e instanceof Error ? e.message : String(e);
|
package/package.json
CHANGED