grepmax 0.17.19 → 0.17.20
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/README.md
CHANGED
|
@@ -163,6 +163,9 @@ gmax "query" [options]
|
|
|
163
163
|
| `--explain` | Show scoring breakdown per result. | `false` |
|
|
164
164
|
| `-C <n>` | Context lines before/after. | `0` |
|
|
165
165
|
| `--root <dir>` | Search a different project. | cwd |
|
|
166
|
+
| `--all-projects` | Search every indexed project; results grouped by project. | `false` |
|
|
167
|
+
| `--projects <list>` | Search only these projects (comma-separated names). | — |
|
|
168
|
+
| `--exclude-projects <list>` | With `--all-projects`, skip these projects. | — |
|
|
166
169
|
| `--min-score <n>` | Minimum relevance score. | `0` |
|
|
167
170
|
|
|
168
171
|
## Background Daemon
|
package/dist/commands/search.js
CHANGED
|
@@ -56,6 +56,7 @@ const setup_helpers_1 = require("../lib/setup/setup-helpers");
|
|
|
56
56
|
const skeleton_1 = require("../lib/skeleton");
|
|
57
57
|
const retriever_1 = require("../lib/skeleton/retriever");
|
|
58
58
|
const vector_db_1 = require("../lib/store/vector-db");
|
|
59
|
+
const cross_project_1 = require("../lib/utils/cross-project");
|
|
59
60
|
const exit_1 = require("../lib/utils/exit");
|
|
60
61
|
const formatter_1 = require("../lib/utils/formatter");
|
|
61
62
|
const import_extractor_1 = require("../lib/utils/import-extractor");
|
|
@@ -370,6 +371,9 @@ exports.search = new commander_1.Command("search")
|
|
|
370
371
|
.option("--file <name>", "Filter to files matching this name (e.g. 'syncer.ts')")
|
|
371
372
|
.option("--in <subpath>", "Restrict to a sub-path of the project (repeatable; comma-separated also accepted)", (value, prev) => prev ? [...prev, value] : [value])
|
|
372
373
|
.option("--exclude <subpath>", "Exclude a sub-path of the project (repeatable; e.g. 'tests/')", (value, prev) => prev ? [...prev, value] : [value])
|
|
374
|
+
.option("--all-projects", "Search across every indexed project, not just the current one", false)
|
|
375
|
+
.option("--projects <list>", "Search only these indexed projects (comma-separated names)")
|
|
376
|
+
.option("--exclude-projects <list>", "With --all-projects, skip these projects (comma-separated names)")
|
|
373
377
|
.option("--lang <ext>", "Filter by file extension (e.g. 'ts', 'py')")
|
|
374
378
|
.option("--role <role>", "Filter by role: ORCHESTRATION, DEFINITION, IMPLEMENTATION")
|
|
375
379
|
.option("--symbol", "Append call graph after search results", false)
|
|
@@ -389,9 +393,11 @@ Examples:
|
|
|
389
393
|
gmax "VectorDB" --symbol --plain
|
|
390
394
|
gmax "error handling" -C 5 --imports --plain
|
|
391
395
|
gmax "handler" --name "handle.*" --exclude tests/
|
|
396
|
+
gmax "rate limiter" --all-projects --agent
|
|
397
|
+
gmax "auth middleware" --projects api,gateway --plain
|
|
392
398
|
`)
|
|
393
399
|
.action((pattern, exec_path, _options, cmd) => __awaiter(void 0, void 0, void 0, function* () {
|
|
394
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z;
|
|
400
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0;
|
|
395
401
|
const options = cmd.optsWithGlobals();
|
|
396
402
|
const root = process.cwd();
|
|
397
403
|
const minScore = Number.isFinite(Number.parseFloat(options.minScore))
|
|
@@ -401,10 +407,46 @@ Examples:
|
|
|
401
407
|
const _searchStartMs = Date.now();
|
|
402
408
|
let _searchResultCount = 0;
|
|
403
409
|
let _searchError;
|
|
404
|
-
//
|
|
410
|
+
// Cross-project scope (Phase 6): --all-projects / --projects / --exclude-projects.
|
|
411
|
+
// When active, single-project path scoping is dropped in favor of the
|
|
412
|
+
// project_roots filter clauses, and results are grouped by owning project.
|
|
413
|
+
const crossProject = (0, cross_project_1.resolveCrossProjectScope)({
|
|
414
|
+
allProjects: options.allProjects,
|
|
415
|
+
projects: options.projects,
|
|
416
|
+
excludeProjects: options.excludeProjects,
|
|
417
|
+
});
|
|
418
|
+
if (crossProject.active) {
|
|
419
|
+
// These modifiers are inherently single-project (one skeleton root, one
|
|
420
|
+
// call-graph center, one budget rollup). Reject the combination up front
|
|
421
|
+
// rather than emit confusing cross-root output.
|
|
422
|
+
const conflict = options.skeleton
|
|
423
|
+
? "--skeleton"
|
|
424
|
+
: options.contextForLlm
|
|
425
|
+
? "--context-for-llm"
|
|
426
|
+
: options.symbol
|
|
427
|
+
? "--symbol"
|
|
428
|
+
: null;
|
|
429
|
+
if (conflict) {
|
|
430
|
+
console.error(`${conflict} is single-project; drop --all-projects/--projects or ${conflict}.`);
|
|
431
|
+
process.exitCode = 1;
|
|
432
|
+
return;
|
|
433
|
+
}
|
|
434
|
+
for (const w of crossProject.warnings)
|
|
435
|
+
console.warn(`Warning: ${w}`);
|
|
436
|
+
if (!crossProject.roots.length) {
|
|
437
|
+
console.error("No matching indexed projects. Run `gmax status` to list them.");
|
|
438
|
+
process.exitCode = 1;
|
|
439
|
+
return;
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
// Check for running server. The per-project HTTP server can't answer
|
|
443
|
+
// cross-project queries, so cross-project mode skips it and uses the
|
|
444
|
+
// daemon-mediated / in-process path (both query the shared table).
|
|
405
445
|
const execPathForServer = exec_path ? path.resolve(exec_path) : root;
|
|
406
446
|
const projectRootForServer = (_a = (0, project_root_1.findProjectRoot)(execPathForServer)) !== null && _a !== void 0 ? _a : execPathForServer;
|
|
407
|
-
const server =
|
|
447
|
+
const server = crossProject.active
|
|
448
|
+
? null
|
|
449
|
+
: (0, server_registry_1.getServerForProject)(projectRootForServer);
|
|
408
450
|
if (server) {
|
|
409
451
|
try {
|
|
410
452
|
const response = yield fetch(`http://localhost:${server.port}/search`, {
|
|
@@ -552,14 +594,22 @@ Examples:
|
|
|
552
594
|
in: options.in,
|
|
553
595
|
exclude: options.exclude,
|
|
554
596
|
});
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
597
|
+
// Cross-project mode drops the single-project path prefix (and any
|
|
598
|
+
// --in/[path] sub-scoping, which is meaningless across roots) in favor of
|
|
599
|
+
// the project_roots filter clauses computed below.
|
|
600
|
+
if (crossProject.active && (exec_path || ((_d = options.in) === null || _d === void 0 ? void 0 : _d.length))) {
|
|
601
|
+
console.warn("Warning: --in / [path] are single-project; ignored under --all-projects/--projects.");
|
|
602
|
+
}
|
|
603
|
+
const pathFilter = crossProject.active
|
|
604
|
+
? undefined
|
|
605
|
+
: options.in && options.in.length > 0
|
|
606
|
+
? scope.pathPrefix
|
|
607
|
+
: exec_path
|
|
608
|
+
? (() => {
|
|
609
|
+
const p = path.resolve(exec_path);
|
|
610
|
+
return p.endsWith("/") ? p : `${p}/`;
|
|
611
|
+
})()
|
|
612
|
+
: scope.pathPrefix;
|
|
563
613
|
const searchFilters = {};
|
|
564
614
|
if (options.file)
|
|
565
615
|
searchFilters.file = options.file;
|
|
@@ -567,10 +617,19 @@ Examples:
|
|
|
567
617
|
searchFilters.language = options.lang;
|
|
568
618
|
if (options.role)
|
|
569
619
|
searchFilters.role = options.role;
|
|
570
|
-
if (
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
620
|
+
if (crossProject.active) {
|
|
621
|
+
if (crossProject.projectRootsCsv)
|
|
622
|
+
searchFilters.project_roots = crossProject.projectRootsCsv;
|
|
623
|
+
if (crossProject.excludeProjectRootsCsv)
|
|
624
|
+
searchFilters.exclude_project_roots =
|
|
625
|
+
crossProject.excludeProjectRootsCsv;
|
|
626
|
+
}
|
|
627
|
+
else {
|
|
628
|
+
if (scope.inPrefixes.length > 0)
|
|
629
|
+
searchFilters.inPrefixes = scope.inPrefixes;
|
|
630
|
+
if (scope.excludePrefixes.length > 0)
|
|
631
|
+
searchFilters.excludePrefixes = scope.excludePrefixes;
|
|
632
|
+
}
|
|
574
633
|
// Aider-style seeding: --seed-file / --seed-symbol (repeatable, also
|
|
575
634
|
// comma-separated) bias candidate generation toward the caller's working
|
|
576
635
|
// context. Absent → undefined → inert.
|
|
@@ -621,7 +680,7 @@ Examples:
|
|
|
621
680
|
indexState = resp.indexState;
|
|
622
681
|
}
|
|
623
682
|
else if (process.env.GMAX_DEBUG === "1") {
|
|
624
|
-
console.error(`[search] daemon path unavailable: ${(
|
|
683
|
+
console.error(`[search] daemon path unavailable: ${(_e = resp.error) !== null && _e !== void 0 ? _e : "unknown"}`);
|
|
625
684
|
}
|
|
626
685
|
}
|
|
627
686
|
}
|
|
@@ -703,7 +762,7 @@ Examples:
|
|
|
703
762
|
}
|
|
704
763
|
}
|
|
705
764
|
// Ensure a watcher is running for live reindexing
|
|
706
|
-
if (!process.env.VITEST && !((
|
|
765
|
+
if (!process.env.VITEST && !((_f = process.env.NODE_ENV) === null || _f === void 0 ? void 0 : _f.includes("test"))) {
|
|
707
766
|
const { launchWatcher } = yield Promise.resolve().then(() => __importStar(require("../lib/utils/watcher-launcher")));
|
|
708
767
|
const launched = yield launchWatcher(projectRoot);
|
|
709
768
|
if (!launched.ok && launched.reason === "spawn-failed") {
|
|
@@ -715,7 +774,7 @@ Examples:
|
|
|
715
774
|
? searchFilters
|
|
716
775
|
: undefined, pathFilter);
|
|
717
776
|
} // end if (!searchResult) — in-process fallback
|
|
718
|
-
if (!options.agent && ((
|
|
777
|
+
if (!options.agent && ((_g = searchResult.warnings) === null || _g === void 0 ? void 0 : _g.length)) {
|
|
719
778
|
for (const w of searchResult.warnings) {
|
|
720
779
|
console.warn(`Warning: ${w}`);
|
|
721
780
|
}
|
|
@@ -740,7 +799,7 @@ Examples:
|
|
|
740
799
|
return defs.some((d) => regex.test(d));
|
|
741
800
|
});
|
|
742
801
|
}
|
|
743
|
-
catch (
|
|
802
|
+
catch (_1) {
|
|
744
803
|
// Invalid regex — skip
|
|
745
804
|
}
|
|
746
805
|
}
|
|
@@ -757,6 +816,76 @@ Examples:
|
|
|
757
816
|
};
|
|
758
817
|
// Agent mode: ultra-compact one-line-per-result output
|
|
759
818
|
_searchResultCount = filteredData.length;
|
|
819
|
+
// Cross-project (Phase 6): render grouped by owning project so idioms
|
|
820
|
+
// from different stacks don't blur into one flat list. Only the
|
|
821
|
+
// string-formatter modes reach here — skeleton/context-for-llm/symbol
|
|
822
|
+
// were rejected up front.
|
|
823
|
+
if (crossProject.active) {
|
|
824
|
+
const emitFooter = () => {
|
|
825
|
+
const footer = (0, index_state_footer_1.formatIndexStateFooter)(indexState, {
|
|
826
|
+
agent: !!options.agent,
|
|
827
|
+
});
|
|
828
|
+
if (footer) {
|
|
829
|
+
if (options.agent)
|
|
830
|
+
console.log(footer);
|
|
831
|
+
else
|
|
832
|
+
console.warn(footer);
|
|
833
|
+
}
|
|
834
|
+
};
|
|
835
|
+
if (!filteredData.length) {
|
|
836
|
+
console.log(options.agent ? "(none)" : "No matches found.");
|
|
837
|
+
process.exitCode = 1;
|
|
838
|
+
emitFooter();
|
|
839
|
+
return;
|
|
840
|
+
}
|
|
841
|
+
const getPath = (r) => {
|
|
842
|
+
var _a, _b, _c;
|
|
843
|
+
return String((_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 : "");
|
|
844
|
+
};
|
|
845
|
+
const groups = (0, cross_project_1.groupResultsByProject)(filteredData, crossProject.roots, getPath);
|
|
846
|
+
const isTTY = process.stdout.isTTY;
|
|
847
|
+
const shouldBePlain = options.plain || !isTTY;
|
|
848
|
+
const blocks = [];
|
|
849
|
+
for (const g of groups) {
|
|
850
|
+
let body;
|
|
851
|
+
if (options.agent) {
|
|
852
|
+
body = (0, agent_search_formatter_1.formatAgentSearchResults)(g.items, g.root, {
|
|
853
|
+
includeImports: options.imports,
|
|
854
|
+
getImportsForFile,
|
|
855
|
+
explain: options.explain,
|
|
856
|
+
});
|
|
857
|
+
}
|
|
858
|
+
else if (options.compact) {
|
|
859
|
+
body = formatCompactTable(toCompactHits(g.items), g.root, pattern, {
|
|
860
|
+
isTTY: !!isTTY,
|
|
861
|
+
plain: !!options.plain,
|
|
862
|
+
});
|
|
863
|
+
}
|
|
864
|
+
else if (shouldBePlain) {
|
|
865
|
+
body = (0, formatter_1.formatTextResults)(toTextResults(g.items), pattern, g.root, {
|
|
866
|
+
isPlain: true,
|
|
867
|
+
compact: options.compact,
|
|
868
|
+
content: options.content,
|
|
869
|
+
perFile: parseInt(options.perFile, 10),
|
|
870
|
+
showScores: options.scores,
|
|
871
|
+
});
|
|
872
|
+
}
|
|
873
|
+
else {
|
|
874
|
+
const { formatResults } = yield Promise.resolve().then(() => __importStar(require("../lib/output/formatter")));
|
|
875
|
+
body = formatResults(g.items, g.root, {
|
|
876
|
+
content: options.content,
|
|
877
|
+
explain: options.explain,
|
|
878
|
+
});
|
|
879
|
+
}
|
|
880
|
+
const header = options.agent
|
|
881
|
+
? `## ${g.name} (${g.items.length})`
|
|
882
|
+
: `=== ${g.name} (${g.items.length}) ===`;
|
|
883
|
+
blocks.push(`${header}\n${body}`);
|
|
884
|
+
}
|
|
885
|
+
console.log(blocks.join("\n\n"));
|
|
886
|
+
emitFooter();
|
|
887
|
+
return;
|
|
888
|
+
}
|
|
760
889
|
if (options.agent) {
|
|
761
890
|
if (!filteredData.length) {
|
|
762
891
|
console.log("(none)");
|
|
@@ -798,7 +927,7 @@ Examples:
|
|
|
798
927
|
}
|
|
799
928
|
}
|
|
800
929
|
}
|
|
801
|
-
catch (
|
|
930
|
+
catch (_2) { }
|
|
802
931
|
}
|
|
803
932
|
// Partial-index footer last, so it's the final line the agent reads —
|
|
804
933
|
// and emitted even on "(none)", where an empty result may just mean the
|
|
@@ -836,9 +965,9 @@ Examples:
|
|
|
836
965
|
let shown = 0;
|
|
837
966
|
console.log(resultCountHeader(filteredData, parseInt(options.m, 10)));
|
|
838
967
|
for (const r of filteredData) {
|
|
839
|
-
const absP = (
|
|
840
|
-
const startLine = (
|
|
841
|
-
const endLine = (
|
|
968
|
+
const absP = (_k = (_h = r.path) !== null && _h !== void 0 ? _h : (_j = r.metadata) === null || _j === void 0 ? void 0 : _j.path) !== null && _k !== void 0 ? _k : "";
|
|
969
|
+
const startLine = (_p = (_m = (_l = r.startLine) !== null && _l !== void 0 ? _l : r.start_line) !== null && _m !== void 0 ? _m : (_o = r.generated_metadata) === null || _o === void 0 ? void 0 : _o.start_line) !== null && _p !== void 0 ? _p : 0;
|
|
970
|
+
const endLine = (_t = (_r = (_q = r.endLine) !== null && _q !== void 0 ? _q : r.end_line) !== null && _r !== void 0 ? _r : (_s = r.generated_metadata) === null || _s === void 0 ? void 0 : _s.end_line) !== null && _t !== void 0 ? _t : startLine;
|
|
842
971
|
const relPath = absP.startsWith(projectRoot)
|
|
843
972
|
? absP.slice(projectRoot.length + 1)
|
|
844
973
|
: absP;
|
|
@@ -871,7 +1000,7 @@ Examples:
|
|
|
871
1000
|
tokensUsed += blobTokens;
|
|
872
1001
|
shown++;
|
|
873
1002
|
}
|
|
874
|
-
catch (
|
|
1003
|
+
catch (_3) {
|
|
875
1004
|
console.log(`\n--- ${relPath} (file not readable) ---`);
|
|
876
1005
|
shown++;
|
|
877
1006
|
}
|
|
@@ -888,7 +1017,7 @@ Examples:
|
|
|
888
1017
|
if (options.imports) {
|
|
889
1018
|
const seenFiles = new Set();
|
|
890
1019
|
for (const r of filteredData) {
|
|
891
|
-
const absP = (
|
|
1020
|
+
const absP = (_w = (_u = r.path) !== null && _u !== void 0 ? _u : (_v = r.metadata) === null || _v === void 0 ? void 0 : _v.path) !== null && _w !== void 0 ? _w : "";
|
|
892
1021
|
if (absP && !seenFiles.has(absP)) {
|
|
893
1022
|
seenFiles.add(absP);
|
|
894
1023
|
const imports = getImportsForFile(absP);
|
|
@@ -915,7 +1044,7 @@ Examples:
|
|
|
915
1044
|
for (const r of filteredData) {
|
|
916
1045
|
const b = r.scoreBreakdown;
|
|
917
1046
|
if (b) {
|
|
918
|
-
const absP = (
|
|
1047
|
+
const absP = (_z = (_x = r.path) !== null && _x !== void 0 ? _x : (_y = r.metadata) === null || _y === void 0 ? void 0 : _y.path) !== null && _z !== void 0 ? _z : "";
|
|
919
1048
|
const relPath = absP.startsWith(projectRoot)
|
|
920
1049
|
? absP.slice(projectRoot.length + 1)
|
|
921
1050
|
: absP;
|
|
@@ -977,7 +1106,7 @@ Examples:
|
|
|
977
1106
|
console.log(lines.join("\n"));
|
|
978
1107
|
}
|
|
979
1108
|
}
|
|
980
|
-
catch (
|
|
1109
|
+
catch (_4) {
|
|
981
1110
|
// Trace failed — skip silently
|
|
982
1111
|
}
|
|
983
1112
|
}
|
|
@@ -997,13 +1126,13 @@ Examples:
|
|
|
997
1126
|
source: "cli",
|
|
998
1127
|
tool: "search",
|
|
999
1128
|
query: pattern,
|
|
1000
|
-
project: (
|
|
1129
|
+
project: (_0 = (0, project_root_1.findProjectRoot)(root)) !== null && _0 !== void 0 ? _0 : root,
|
|
1001
1130
|
results: _searchResultCount,
|
|
1002
1131
|
ms: Date.now() - _searchStartMs,
|
|
1003
1132
|
error: _searchError,
|
|
1004
1133
|
});
|
|
1005
1134
|
}
|
|
1006
|
-
catch (
|
|
1135
|
+
catch (_5) { }
|
|
1007
1136
|
if (vectorDb) {
|
|
1008
1137
|
try {
|
|
1009
1138
|
yield vectorDb.close();
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Cross-project search scoping (Phase 6).
|
|
4
|
+
*
|
|
5
|
+
* The shared LanceDB table holds chunks from every indexed project, scoped by
|
|
6
|
+
* absolute-path prefix. Single-project search pins a `pathPrefix`; cross-project
|
|
7
|
+
* search drops the prefix and instead scopes with the `project_roots` /
|
|
8
|
+
* `exclude_project_roots` filter clauses (an OR-group of `path LIKE` prefixes —
|
|
9
|
+
* see buildWhereClause in searcher.ts). This module resolves the CLI flags
|
|
10
|
+
* (`--all-projects` / `--projects` / `--exclude-projects`) to those filter
|
|
11
|
+
* values and groups results back by owning project for display.
|
|
12
|
+
*/
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.resolveCrossProjectScope = resolveCrossProjectScope;
|
|
15
|
+
exports.projectForPath = projectForPath;
|
|
16
|
+
exports.groupResultsByProject = groupResultsByProject;
|
|
17
|
+
const project_registry_1 = require("./project-registry");
|
|
18
|
+
function resolveCrossProjectScope(opts) {
|
|
19
|
+
const active = !!(opts.allProjects || opts.projects);
|
|
20
|
+
if (!active) {
|
|
21
|
+
return { active: false, roots: [], warnings: [] };
|
|
22
|
+
}
|
|
23
|
+
// Ignore "error"-status projects: the daemon won't search them anyway.
|
|
24
|
+
const all = (0, project_registry_1.listProjects)().filter((p) => p.status !== "error");
|
|
25
|
+
const byName = new Map(all.map((p) => [p.name, p]));
|
|
26
|
+
const warnings = [];
|
|
27
|
+
const resolveNames = (csv) => {
|
|
28
|
+
const names = (csv !== null && csv !== void 0 ? csv : "")
|
|
29
|
+
.split(",")
|
|
30
|
+
.map((s) => s.trim())
|
|
31
|
+
.filter(Boolean);
|
|
32
|
+
const found = [];
|
|
33
|
+
const missing = [];
|
|
34
|
+
for (const n of names) {
|
|
35
|
+
const p = byName.get(n);
|
|
36
|
+
if (p)
|
|
37
|
+
found.push(p);
|
|
38
|
+
else
|
|
39
|
+
missing.push(n);
|
|
40
|
+
}
|
|
41
|
+
return { found, missing };
|
|
42
|
+
};
|
|
43
|
+
const excluded = resolveNames(opts.excludeProjects);
|
|
44
|
+
const excludedRoots = new Set(excluded.found.map((p) => p.root));
|
|
45
|
+
if (excluded.missing.length) {
|
|
46
|
+
warnings.push(`Unknown --exclude-projects: ${excluded.missing.join(", ")}`);
|
|
47
|
+
}
|
|
48
|
+
let included;
|
|
49
|
+
let projectRootsCsv;
|
|
50
|
+
let excludeProjectRootsCsv;
|
|
51
|
+
if (opts.projects) {
|
|
52
|
+
const r = resolveNames(opts.projects);
|
|
53
|
+
if (r.missing.length) {
|
|
54
|
+
warnings.push(`Unknown --projects: ${r.missing.join(", ")}. Available: ${all
|
|
55
|
+
.map((p) => p.name)
|
|
56
|
+
.join(", ")}`);
|
|
57
|
+
}
|
|
58
|
+
included = r.found.filter((p) => !excludedRoots.has(p.root));
|
|
59
|
+
// Narrowed to an explicit subset → scope with project_roots.
|
|
60
|
+
projectRootsCsv = included.length
|
|
61
|
+
? included.map((p) => p.root).join(",")
|
|
62
|
+
: undefined;
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
// --all-projects: search the whole shared table. No project_roots clause
|
|
66
|
+
// (its absence IS "everything"); only carve out --exclude-projects.
|
|
67
|
+
included = all.filter((p) => !excludedRoots.has(p.root));
|
|
68
|
+
if (excludedRoots.size) {
|
|
69
|
+
excludeProjectRootsCsv = [...excludedRoots].join(",");
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return {
|
|
73
|
+
active: true,
|
|
74
|
+
roots: included.map((p) => ({ root: p.root, name: p.name })),
|
|
75
|
+
projectRootsCsv,
|
|
76
|
+
excludeProjectRootsCsv,
|
|
77
|
+
warnings,
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
/** Longest-prefix match of an absolute path against the in-scope project roots. */
|
|
81
|
+
function projectForPath(absPath, roots) {
|
|
82
|
+
let best = null;
|
|
83
|
+
let bestLen = -1;
|
|
84
|
+
for (const r of roots) {
|
|
85
|
+
const prefix = r.root.endsWith("/") ? r.root : `${r.root}/`;
|
|
86
|
+
if (absPath === r.root || absPath.startsWith(prefix)) {
|
|
87
|
+
if (prefix.length > bestLen) {
|
|
88
|
+
best = r;
|
|
89
|
+
bestLen = prefix.length;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return best;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Bucket ranked results by owning project, preserving rank order: groups appear
|
|
97
|
+
* in order of their best-ranked member, items keep their original order.
|
|
98
|
+
*/
|
|
99
|
+
function groupResultsByProject(results, roots, getPath) {
|
|
100
|
+
var _a, _b, _c;
|
|
101
|
+
const order = [];
|
|
102
|
+
const buckets = new Map();
|
|
103
|
+
for (const r of results) {
|
|
104
|
+
const owner = projectForPath(getPath(r), roots);
|
|
105
|
+
const key = (_a = owner === null || owner === void 0 ? void 0 : owner.root) !== null && _a !== void 0 ? _a : "(unknown)";
|
|
106
|
+
let bucket = buckets.get(key);
|
|
107
|
+
if (!bucket) {
|
|
108
|
+
bucket = { name: (_b = owner === null || owner === void 0 ? void 0 : owner.name) !== null && _b !== void 0 ? _b : "(unknown)", root: (_c = owner === null || owner === void 0 ? void 0 : owner.root) !== null && _c !== void 0 ? _c : "", items: [] };
|
|
109
|
+
buckets.set(key, bucket);
|
|
110
|
+
order.push(key);
|
|
111
|
+
}
|
|
112
|
+
bucket.items.push(r);
|
|
113
|
+
}
|
|
114
|
+
return order.map((k) => buckets.get(k));
|
|
115
|
+
}
|
package/package.json
CHANGED