layermap 0.1.17 → 0.1.19
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 +4 -1
- package/analyzers/project-map-java/java-map.jar +0 -0
- package/dist/cli.mjs +424 -335
- package/package.json +1 -1
- package/pi/layermap.mjs +1 -1
package/dist/cli.mjs
CHANGED
|
@@ -1294,10 +1294,10 @@ function mergeDefs(...defs) {
|
|
|
1294
1294
|
function cloneDef(schema) {
|
|
1295
1295
|
return mergeDefs(schema._zod.def);
|
|
1296
1296
|
}
|
|
1297
|
-
function getElementAtPath(obj,
|
|
1298
|
-
if (!
|
|
1297
|
+
function getElementAtPath(obj, path14) {
|
|
1298
|
+
if (!path14)
|
|
1299
1299
|
return obj;
|
|
1300
|
-
return
|
|
1300
|
+
return path14.reduce((acc, key) => acc?.[key], obj);
|
|
1301
1301
|
}
|
|
1302
1302
|
function promiseAllObject(promisesObj) {
|
|
1303
1303
|
const keys = Object.keys(promisesObj);
|
|
@@ -1706,11 +1706,11 @@ function explicitlyAborted(x, startIndex = 0) {
|
|
|
1706
1706
|
}
|
|
1707
1707
|
return false;
|
|
1708
1708
|
}
|
|
1709
|
-
function prefixIssues(
|
|
1709
|
+
function prefixIssues(path14, issues) {
|
|
1710
1710
|
return issues.map((iss) => {
|
|
1711
1711
|
var _a3;
|
|
1712
1712
|
(_a3 = iss).path ?? (_a3.path = []);
|
|
1713
|
-
iss.path.unshift(
|
|
1713
|
+
iss.path.unshift(path14);
|
|
1714
1714
|
return iss;
|
|
1715
1715
|
});
|
|
1716
1716
|
}
|
|
@@ -1857,16 +1857,16 @@ function flattenError(error51, mapper = (issue2) => issue2.message) {
|
|
|
1857
1857
|
}
|
|
1858
1858
|
function formatError(error51, mapper = (issue2) => issue2.message) {
|
|
1859
1859
|
const fieldErrors = { _errors: [] };
|
|
1860
|
-
const processError = (error52,
|
|
1860
|
+
const processError = (error52, path14 = []) => {
|
|
1861
1861
|
for (const issue2 of error52.issues) {
|
|
1862
1862
|
if (issue2.code === "invalid_union" && issue2.errors.length) {
|
|
1863
|
-
issue2.errors.map((issues) => processError({ issues }, [...
|
|
1863
|
+
issue2.errors.map((issues) => processError({ issues }, [...path14, ...issue2.path]));
|
|
1864
1864
|
} else if (issue2.code === "invalid_key") {
|
|
1865
|
-
processError({ issues: issue2.issues }, [...
|
|
1865
|
+
processError({ issues: issue2.issues }, [...path14, ...issue2.path]);
|
|
1866
1866
|
} else if (issue2.code === "invalid_element") {
|
|
1867
|
-
processError({ issues: issue2.issues }, [...
|
|
1867
|
+
processError({ issues: issue2.issues }, [...path14, ...issue2.path]);
|
|
1868
1868
|
} else {
|
|
1869
|
-
const fullpath = [...
|
|
1869
|
+
const fullpath = [...path14, ...issue2.path];
|
|
1870
1870
|
if (fullpath.length === 0) {
|
|
1871
1871
|
fieldErrors._errors.push(mapper(issue2));
|
|
1872
1872
|
} else {
|
|
@@ -1893,17 +1893,17 @@ function formatError(error51, mapper = (issue2) => issue2.message) {
|
|
|
1893
1893
|
}
|
|
1894
1894
|
function treeifyError(error51, mapper = (issue2) => issue2.message) {
|
|
1895
1895
|
const result = { errors: [] };
|
|
1896
|
-
const processError = (error52,
|
|
1896
|
+
const processError = (error52, path14 = []) => {
|
|
1897
1897
|
var _a3, _b;
|
|
1898
1898
|
for (const issue2 of error52.issues) {
|
|
1899
1899
|
if (issue2.code === "invalid_union" && issue2.errors.length) {
|
|
1900
|
-
issue2.errors.map((issues) => processError({ issues }, [...
|
|
1900
|
+
issue2.errors.map((issues) => processError({ issues }, [...path14, ...issue2.path]));
|
|
1901
1901
|
} else if (issue2.code === "invalid_key") {
|
|
1902
|
-
processError({ issues: issue2.issues }, [...
|
|
1902
|
+
processError({ issues: issue2.issues }, [...path14, ...issue2.path]);
|
|
1903
1903
|
} else if (issue2.code === "invalid_element") {
|
|
1904
|
-
processError({ issues: issue2.issues }, [...
|
|
1904
|
+
processError({ issues: issue2.issues }, [...path14, ...issue2.path]);
|
|
1905
1905
|
} else {
|
|
1906
|
-
const fullpath = [...
|
|
1906
|
+
const fullpath = [...path14, ...issue2.path];
|
|
1907
1907
|
if (fullpath.length === 0) {
|
|
1908
1908
|
result.errors.push(mapper(issue2));
|
|
1909
1909
|
continue;
|
|
@@ -1935,8 +1935,8 @@ function treeifyError(error51, mapper = (issue2) => issue2.message) {
|
|
|
1935
1935
|
}
|
|
1936
1936
|
function toDotPath(_path) {
|
|
1937
1937
|
const segs = [];
|
|
1938
|
-
const
|
|
1939
|
-
for (const seg of
|
|
1938
|
+
const path14 = _path.map((seg) => typeof seg === "object" ? seg.key : seg);
|
|
1939
|
+
for (const seg of path14) {
|
|
1940
1940
|
if (typeof seg === "number")
|
|
1941
1941
|
segs.push(`[${seg}]`);
|
|
1942
1942
|
else if (typeof seg === "symbol")
|
|
@@ -14628,13 +14628,13 @@ function resolveRef(ref, ctx) {
|
|
|
14628
14628
|
if (!ref.startsWith("#")) {
|
|
14629
14629
|
throw new Error("External $ref is not supported, only local refs (#/...) are allowed");
|
|
14630
14630
|
}
|
|
14631
|
-
const
|
|
14632
|
-
if (
|
|
14631
|
+
const path14 = ref.slice(1).split("/").filter(Boolean);
|
|
14632
|
+
if (path14.length === 0) {
|
|
14633
14633
|
return ctx.rootSchema;
|
|
14634
14634
|
}
|
|
14635
14635
|
const defsKey = ctx.version === "draft-2020-12" ? "$defs" : "definitions";
|
|
14636
|
-
if (
|
|
14637
|
-
const key =
|
|
14636
|
+
if (path14[0] === defsKey) {
|
|
14637
|
+
const key = path14[1];
|
|
14638
14638
|
if (!key || !ctx.defs[key]) {
|
|
14639
14639
|
throw new Error(`Reference not found: ${ref}`);
|
|
14640
14640
|
}
|
|
@@ -15874,8 +15874,8 @@ var MapAnalysisSchema = external_exports.object({
|
|
|
15874
15874
|
var mapPathAllowed = (relative, prefixes) => prefixes.some(
|
|
15875
15875
|
(prefix) => prefix === "." || relative === prefix || relative.startsWith(`${prefix}/`)
|
|
15876
15876
|
);
|
|
15877
|
-
var mapTestPath = (
|
|
15878
|
-
|
|
15877
|
+
var mapTestPath = (path14) => /(?:^|\/)(?:__tests__|tests?|fixtures?|e2e|testdata)(?:\/|$)|\.(?:spec|test)\.|_test\.(?:go|py)$|(?:^|\/)(?:test_[^/]*\.py|conftest\.py)$/iu.test(
|
|
15878
|
+
path14
|
|
15879
15879
|
);
|
|
15880
15880
|
|
|
15881
15881
|
// src/project-map-reference-types.ts
|
|
@@ -15959,11 +15959,11 @@ var string4 = (value) => {
|
|
|
15959
15959
|
var identity = (id2, reconstructed) => id2 === reconstructed ? [] : [JSON.stringify(id2)];
|
|
15960
15960
|
function encodeMapText(graph) {
|
|
15961
15961
|
const files = /* @__PURE__ */ new Map();
|
|
15962
|
-
const file2 = (
|
|
15963
|
-
let ref = files.get(
|
|
15962
|
+
const file2 = (path14) => {
|
|
15963
|
+
let ref = files.get(path14);
|
|
15964
15964
|
if (!ref) {
|
|
15965
15965
|
ref = `F${files.size + 1}`;
|
|
15966
|
-
files.set(
|
|
15966
|
+
files.set(path14, ref);
|
|
15967
15967
|
}
|
|
15968
15968
|
return ref;
|
|
15969
15969
|
};
|
|
@@ -16011,7 +16011,7 @@ function encodeMapText(graph) {
|
|
|
16011
16011
|
rows.push(`B ${node(frontier.entityRef)} ${frontier.direction}`);
|
|
16012
16012
|
return [
|
|
16013
16013
|
...header,
|
|
16014
|
-
...[...files].map(([
|
|
16014
|
+
...[...files].map(([path14, ref]) => `${ref} ${JSON.stringify(path14)}`),
|
|
16015
16015
|
...rows
|
|
16016
16016
|
].join("\n");
|
|
16017
16017
|
}
|
|
@@ -16031,10 +16031,10 @@ function decodeMapText(text) {
|
|
|
16031
16031
|
const at = (value) => {
|
|
16032
16032
|
const match = /^(F[1-9]\d*):(\d+)-(\d+)@(\d+)-(\d+)$/u.exec(value ?? "");
|
|
16033
16033
|
if (!match) return failed();
|
|
16034
|
-
const
|
|
16035
|
-
if (
|
|
16034
|
+
const path14 = files.get(match[1] ?? "");
|
|
16035
|
+
if (path14 === void 0) return failed();
|
|
16036
16036
|
return MapAnchorSchema.parse({
|
|
16037
|
-
path:
|
|
16037
|
+
path: path14,
|
|
16038
16038
|
startLine: Number(match[2]),
|
|
16039
16039
|
endLine: Number(match[3]),
|
|
16040
16040
|
start: Number(match[4]),
|
|
@@ -16111,8 +16111,8 @@ function decodeMapText(text) {
|
|
|
16111
16111
|
var locationSchema = MapAnchorSchema.describe(
|
|
16112
16112
|
"Source location: start/end are zero-based UTF-16 offsets with an exclusive end; line numbers are one-based."
|
|
16113
16113
|
);
|
|
16114
|
-
var location = ({ path:
|
|
16115
|
-
path:
|
|
16114
|
+
var location = ({ path: path14, startLine, endLine, start, end }) => ({
|
|
16115
|
+
path: path14,
|
|
16116
16116
|
startLine,
|
|
16117
16117
|
endLine,
|
|
16118
16118
|
start,
|
|
@@ -16215,11 +16215,11 @@ var MapNavigationObjectsSchema = external_exports.union([
|
|
|
16215
16215
|
),
|
|
16216
16216
|
external_exports.object({ files: external_exports.array(searchFileSchema) }).passthrough().refine((value) => !("format" in value), "Text navigation must decode through its format.").transform(
|
|
16217
16217
|
(value) => value.files.flatMap(
|
|
16218
|
-
({ path:
|
|
16218
|
+
({ path: path14, symbols }) => symbols.map(({ id: id2, name, kind, startLine, endLine, start, end, execution }) => ({
|
|
16219
16219
|
id: id2,
|
|
16220
16220
|
name,
|
|
16221
16221
|
kind,
|
|
16222
|
-
anchor: { path:
|
|
16222
|
+
anchor: { path: path14, startLine, endLine, start, end },
|
|
16223
16223
|
...execution ? { execution } : {}
|
|
16224
16224
|
}))
|
|
16225
16225
|
)
|
|
@@ -16232,10 +16232,10 @@ var mapSearchNavigation = (result) => {
|
|
|
16232
16232
|
for (const [index, object2] of found.entries()) {
|
|
16233
16233
|
const ranking = rankings[index];
|
|
16234
16234
|
if (!ranking) throw new Error("PROJECT_MAP_SEARCH_RANKING_MISSING");
|
|
16235
|
-
const
|
|
16235
|
+
const path14 = object2.anchor.path;
|
|
16236
16236
|
let file2 = files.at(-1);
|
|
16237
|
-
if (file2?.path !==
|
|
16238
|
-
file2 = { path:
|
|
16237
|
+
if (file2?.path !== path14) {
|
|
16238
|
+
file2 = { path: path14, symbols: [] };
|
|
16239
16239
|
files.push(file2);
|
|
16240
16240
|
}
|
|
16241
16241
|
file2.symbols.push({
|
|
@@ -16361,8 +16361,8 @@ var MapViewGraph = class {
|
|
|
16361
16361
|
}
|
|
16362
16362
|
return object2;
|
|
16363
16363
|
}
|
|
16364
|
-
objectsAt(
|
|
16365
|
-
return this.statements.path.all(this.version,
|
|
16364
|
+
objectsAt(path14) {
|
|
16365
|
+
return this.statements.path.all(this.version, path14).map((row) => {
|
|
16366
16366
|
const object2 = MapObjectSchema.parse(JSON.parse(String(row.object_json)));
|
|
16367
16367
|
this.objects.set(object2.id, object2);
|
|
16368
16368
|
return object2;
|
|
@@ -16481,8 +16481,8 @@ var MapViewGraph = class {
|
|
|
16481
16481
|
);
|
|
16482
16482
|
}
|
|
16483
16483
|
};
|
|
16484
|
-
function mapSelectDeclarations(graph,
|
|
16485
|
-
const objects2 = graph.objectsAt(
|
|
16484
|
+
function mapSelectDeclarations(graph, path14, name, line) {
|
|
16485
|
+
const objects2 = graph.objectsAt(path14).filter((object2) => !mapIsModule(object2));
|
|
16486
16486
|
const matching = name === void 0 ? objects2 : objects2.filter(
|
|
16487
16487
|
(object2) => object2.name === name || name.includes(".") && graph.qualifiedName(object2.id) === name
|
|
16488
16488
|
);
|
|
@@ -16504,12 +16504,12 @@ function requireMapObject(store, version2, selector, prefixes) {
|
|
|
16504
16504
|
if ([entityRef, locator, symbol2].filter((value) => value !== void 0).length !== 1 || entityRef !== void 0 && !entityRef.length)
|
|
16505
16505
|
throw new ProjectEvidenceError("PROJECT_READ_INPUT_INVALID", false);
|
|
16506
16506
|
if (symbol2) {
|
|
16507
|
-
const
|
|
16508
|
-
if (!mapPathAllowed(
|
|
16507
|
+
const path14 = normalizeProjectEvidencePath(symbol2.path);
|
|
16508
|
+
if (!mapPathAllowed(path14, prefixes))
|
|
16509
16509
|
throw new ProjectEvidenceError("PROJECT_MAP_OBJECT_NOT_FOUND", false);
|
|
16510
16510
|
const selected = mapSelectDeclarations(
|
|
16511
16511
|
new MapViewGraph(store, version2),
|
|
16512
|
-
|
|
16512
|
+
path14,
|
|
16513
16513
|
symbol2.name,
|
|
16514
16514
|
symbol2.line
|
|
16515
16515
|
);
|
|
@@ -16520,14 +16520,14 @@ function requireMapObject(store, version2, selector, prefixes) {
|
|
|
16520
16520
|
}
|
|
16521
16521
|
let rows;
|
|
16522
16522
|
if (locator) {
|
|
16523
|
-
const
|
|
16523
|
+
const path14 = normalizeProjectEvidencePath(locator.path);
|
|
16524
16524
|
if (!Number.isSafeInteger(locator.start) || locator.start < 0 || locator.kind !== void 0 && !MapObjectKindSchema.safeParse(locator.kind).success)
|
|
16525
16525
|
throw new ProjectEvidenceError("PROJECT_READ_INPUT_INVALID", false);
|
|
16526
|
-
if (!mapPathAllowed(
|
|
16526
|
+
if (!mapPathAllowed(path14, prefixes))
|
|
16527
16527
|
throw new ProjectEvidenceError("PROJECT_MAP_OBJECT_NOT_FOUND", false);
|
|
16528
16528
|
rows = store.database.prepare(`SELECT object_json FROM project_map_objects
|
|
16529
16529
|
WHERE version_ref = ? AND path = ? AND json_extract(object_json, '$.anchor.start') = ?
|
|
16530
|
-
AND (? IS NULL OR kind = ?) LIMIT 2`).all(version2,
|
|
16530
|
+
AND (? IS NULL OR kind = ?) LIMIT 2`).all(version2, path14, locator.start, locator.kind ?? null, locator.kind ?? null);
|
|
16531
16531
|
} else {
|
|
16532
16532
|
rows = store.database.prepare(
|
|
16533
16533
|
"SELECT object_json FROM project_map_objects WHERE version_ref = ? AND entity_ref = ?"
|
|
@@ -16568,13 +16568,13 @@ function mapQueryPage(count, materialize, navigation, budget) {
|
|
|
16568
16568
|
|
|
16569
16569
|
// src/project-map-query-selection.ts
|
|
16570
16570
|
var mapQuerySelection = (input, knownKinds) => {
|
|
16571
|
-
const
|
|
16571
|
+
const path14 = normalizeProjectEvidencePath(input.path ?? ".", true) || ".";
|
|
16572
16572
|
const kinds = input.kinds ?? knownKinds;
|
|
16573
16573
|
if (!Array.isArray(kinds) || !kinds.length || kinds.length > knownKinds.length || kinds.some((kind) => !knownKinds.includes(kind)))
|
|
16574
16574
|
throw new ProjectEvidenceError("PROJECT_READ_INPUT_INVALID", false);
|
|
16575
|
-
return { path:
|
|
16575
|
+
return { path: path14, kinds: [...new Set(kinds)].sort() };
|
|
16576
16576
|
};
|
|
16577
|
-
var mapQueryPathMatches = (
|
|
16577
|
+
var mapQueryPathMatches = (path14, prefix) => prefix === "." || path14 === prefix || path14.startsWith(`${prefix}/`);
|
|
16578
16578
|
var mapQueryPathSql = (column) => `(? = '.' OR ${column} = ? OR substr(${column}, 1, length(?) + 1) = ? || '/')`;
|
|
16579
16579
|
|
|
16580
16580
|
// src/project-map-search-focus.ts
|
|
@@ -16672,7 +16672,7 @@ var declarationKinds = /* @__PURE__ */ new Set([
|
|
|
16672
16672
|
"METHOD",
|
|
16673
16673
|
"TYPE"
|
|
16674
16674
|
]);
|
|
16675
|
-
var fileStem = (
|
|
16675
|
+
var fileStem = (path14) => path14.slice(path14.lastIndexOf("/") + 1).replace(/\.(?:[cm]?[jt]sx?|vue|svelte|go|pyi?)$/iu, "");
|
|
16676
16676
|
var compareText = (left, right) => left < right ? -1 : left > right ? 1 : 0;
|
|
16677
16677
|
var compareRows = (left, right) => right.ranking.score - left.ranking.score || compareText(left.object.anchor.path, right.object.anchor.path) || compareText(left.object.id, right.object.id);
|
|
16678
16678
|
function mapSearchQuery(input) {
|
|
@@ -16699,10 +16699,10 @@ function mapSearchQuery(input) {
|
|
|
16699
16699
|
}
|
|
16700
16700
|
function rank(object2, documentation, relationCount, query, focus) {
|
|
16701
16701
|
const name = object2.name.toLowerCase();
|
|
16702
|
-
const
|
|
16702
|
+
const path14 = object2.anchor.path.toLowerCase();
|
|
16703
16703
|
const values = {
|
|
16704
16704
|
NAME: [name],
|
|
16705
|
-
PATH: [
|
|
16705
|
+
PATH: [path14],
|
|
16706
16706
|
DOCUMENTATION: documentation.map((text) => text.toLowerCase())
|
|
16707
16707
|
};
|
|
16708
16708
|
const matched = query.terms.map((term) => ({
|
|
@@ -16727,12 +16727,12 @@ function rank(object2, documentation, relationCount, query, focus) {
|
|
|
16727
16727
|
score += 7e3;
|
|
16728
16728
|
signals.push("SYMBOL_CONTAINS");
|
|
16729
16729
|
} else if (matchedFields.includes("NAME")) signals.push("SYMBOL_CONTAINS");
|
|
16730
|
-
if (object2.kind === "FILE" && fileStem(
|
|
16730
|
+
if (object2.kind === "FILE" && fileStem(path14) === normalizedQuery) {
|
|
16731
16731
|
score += 11e3;
|
|
16732
16732
|
signals.push("EXACT_FILE_STEM");
|
|
16733
16733
|
}
|
|
16734
16734
|
if (matchedFields.includes("PATH")) {
|
|
16735
|
-
score +=
|
|
16735
|
+
score += path14.includes(normalizedQuery) ? 2500 : 0;
|
|
16736
16736
|
signals.push("PATH_CONTAINS");
|
|
16737
16737
|
}
|
|
16738
16738
|
if (matchedFields.includes("DOCUMENTATION")) {
|
|
@@ -16747,8 +16747,8 @@ function rank(object2, documentation, relationCount, query, focus) {
|
|
|
16747
16747
|
score += kindWeight[object2.kind] + Math.min(1200, relationCount * 20) + (focus?.score ?? 0);
|
|
16748
16748
|
if (declarationKinds.has(object2.kind)) signals.push("DECLARATION");
|
|
16749
16749
|
if (relationCount > 0) signals.push("GRAPH_CONNECTED");
|
|
16750
|
-
const isTest = mapTestPath(
|
|
16751
|
-
const isGenerated = generatedPath.test(
|
|
16750
|
+
const isTest = mapTestPath(path14);
|
|
16751
|
+
const isGenerated = generatedPath.test(path14);
|
|
16752
16752
|
const hasTestIntent = query.terms.some((term) => testQuery.test(term));
|
|
16753
16753
|
score += isTest ? hasTestIntent ? 1e3 : -5e3 : 300;
|
|
16754
16754
|
score += isGenerated ? -3e3 : 300;
|
|
@@ -17232,13 +17232,13 @@ function utf16Offsets(text) {
|
|
|
17232
17232
|
}
|
|
17233
17233
|
function offsetConverter(files, offsets) {
|
|
17234
17234
|
const converters = /* @__PURE__ */ new Map();
|
|
17235
|
-
return (
|
|
17236
|
-
let convert = converters.get(
|
|
17235
|
+
return (path14, offset) => {
|
|
17236
|
+
let convert = converters.get(path14);
|
|
17237
17237
|
if (!convert) {
|
|
17238
|
-
const text = files[
|
|
17238
|
+
const text = files[path14];
|
|
17239
17239
|
if (text === void 0) return invalid();
|
|
17240
17240
|
convert = offsets === "UTF16" ? (value) => value <= text.length ? value : invalid() : utf16Offsets(text);
|
|
17241
|
-
converters.set(
|
|
17241
|
+
converters.set(path14, convert);
|
|
17242
17242
|
}
|
|
17243
17243
|
return convert(offset);
|
|
17244
17244
|
};
|
|
@@ -17269,7 +17269,7 @@ function mapFactsAnalysis(facts, input, context) {
|
|
|
17269
17269
|
const collect = new MapOutputCollector(output);
|
|
17270
17270
|
const positions = new MapSourcePositions(input.files);
|
|
17271
17271
|
const offset = offsetConverter(input.files, context.offsets);
|
|
17272
|
-
const anchor = (
|
|
17272
|
+
const anchor = (path14, start, end) => positions.span(path14, offset(path14, start), offset(path14, end));
|
|
17273
17273
|
const located = /* @__PURE__ */ new Map();
|
|
17274
17274
|
const canonical = /* @__PURE__ */ new Map();
|
|
17275
17275
|
const bySpan = /* @__PURE__ */ new Map();
|
|
@@ -17835,8 +17835,8 @@ var goModule = /(?:^|\/)go\.mod$/u;
|
|
|
17835
17835
|
var codeHosts = /* @__PURE__ */ new Set(["github.com", "gitlab.com", "bitbucket.org"]);
|
|
17836
17836
|
var GO_MAP_LANGUAGE = Object.freeze({
|
|
17837
17837
|
id: "go-1.24-map-v9",
|
|
17838
|
-
claims: (
|
|
17839
|
-
reads: (
|
|
17838
|
+
claims: (path14) => path14.endsWith(".go"),
|
|
17839
|
+
reads: (path14) => goModule.test(path14),
|
|
17840
17840
|
// A module path, or the standard library, whose first path element has no dot.
|
|
17841
17841
|
importName: (specifier) => {
|
|
17842
17842
|
const parts = specifier.split("/");
|
|
@@ -17845,7 +17845,7 @@ var GO_MAP_LANGUAGE = Object.freeze({
|
|
|
17845
17845
|
return parts.slice(0, size).join("/");
|
|
17846
17846
|
},
|
|
17847
17847
|
// Go imports a package: the directory of the file.
|
|
17848
|
-
importTarget: (
|
|
17848
|
+
importTarget: (path14) => `${path14.slice(0, path14.lastIndexOf("/") + 1) || "./"}`,
|
|
17849
17849
|
create: () => new GoMapAnalyzer()
|
|
17850
17850
|
});
|
|
17851
17851
|
var GO_GAPS = [
|
|
@@ -17891,12 +17891,12 @@ var GoMapAnalyzer = class {
|
|
|
17891
17891
|
}
|
|
17892
17892
|
}
|
|
17893
17893
|
async analyze(session, signal) {
|
|
17894
|
-
const modules = session.readable.map((entry) => entry.path).filter((
|
|
17895
|
-
const moduleOf = (
|
|
17894
|
+
const modules = session.readable.map((entry) => entry.path).filter((path14) => goModule.test(path14)).sort();
|
|
17895
|
+
const moduleOf = (path14) => {
|
|
17896
17896
|
let best;
|
|
17897
17897
|
for (const modFile of modules) {
|
|
17898
17898
|
const directory = modFile.slice(0, modFile.lastIndexOf("/") + 1);
|
|
17899
|
-
if (
|
|
17899
|
+
if (path14.startsWith(directory) && (!best || directory.length > best.lastIndexOf("/") + 1))
|
|
17900
17900
|
best = modFile;
|
|
17901
17901
|
}
|
|
17902
17902
|
return best;
|
|
@@ -17912,11 +17912,11 @@ var GoMapAnalyzer = class {
|
|
|
17912
17912
|
for (const modFile of [...groups.keys()].sort()) {
|
|
17913
17913
|
if (signal.aborted) throw new ProjectEvidenceError("PROJECT_READ_CANCELLED", true);
|
|
17914
17914
|
const files = /* @__PURE__ */ Object.create(null);
|
|
17915
|
-
for (const
|
|
17916
|
-
const text = session.texts[
|
|
17915
|
+
for (const path14 of [...groups.get(modFile) ?? [], ...modFile ? [modFile] : []]) {
|
|
17916
|
+
const text = session.texts[path14];
|
|
17917
17917
|
if (text === void 0)
|
|
17918
17918
|
throw new ProjectEvidenceError("PROJECT_MAP_PROTOCOL_INVALID", false);
|
|
17919
|
-
files[
|
|
17919
|
+
files[path14] = text;
|
|
17920
17920
|
}
|
|
17921
17921
|
const input = {
|
|
17922
17922
|
contextRef: digestValue({
|
|
@@ -17951,8 +17951,8 @@ var GoMapAnalyzer = class {
|
|
|
17951
17951
|
if (text === void 0 || !existsSync3(this.resources.compilerPath))
|
|
17952
17952
|
throw new ProjectEvidenceError("PROJECT_MAP_REFERENCE_TARGET_UNAVAILABLE", false);
|
|
17953
17953
|
const files = /* @__PURE__ */ Object.create(null);
|
|
17954
|
-
for (const [
|
|
17955
|
-
if (this.claims(
|
|
17954
|
+
for (const [path14, value] of Object.entries(input.files))
|
|
17955
|
+
if (this.claims(path14) || goModule.test(path14)) files[path14] = value;
|
|
17956
17956
|
const facts = await this.operation(
|
|
17957
17957
|
{
|
|
17958
17958
|
...input,
|
|
@@ -17982,14 +17982,14 @@ var BUILD_FILES = [
|
|
|
17982
17982
|
"pom.xml"
|
|
17983
17983
|
];
|
|
17984
17984
|
var buildFile = /(?:^|\/)(?:pom\.xml|(?:build|settings)\.gradle(?:\.kts)?)$/u;
|
|
17985
|
-
var directoryOf = (
|
|
17986
|
-
var nameOf = (
|
|
17985
|
+
var directoryOf = (path14) => path14.slice(0, path14.lastIndexOf("/") + 1);
|
|
17986
|
+
var nameOf = (path14) => path14.slice(path14.lastIndexOf("/") + 1);
|
|
17987
17987
|
var DEFAULT_RELEASE = 21;
|
|
17988
17988
|
var platformPackage = /^(?:java|jdk|sun|com\.sun|javax\.(?:annotation\.processing|crypto|imageio|lang\.model|management|naming|net|print|script|security|sound|sql|swing|tools|transaction\.xa|xml))(?:\.|$)/u;
|
|
17989
17989
|
var JAVA_MAP_LANGUAGE = Object.freeze({
|
|
17990
17990
|
id: "javac-lombok-1.18.48-map-v8",
|
|
17991
|
-
claims: (
|
|
17992
|
-
reads: (
|
|
17991
|
+
claims: (path14) => path14.endsWith(".java"),
|
|
17992
|
+
reads: (path14) => buildFile.test(path14),
|
|
17993
17993
|
// A package of the Java platform, or a library named by its first two package segments.
|
|
17994
17994
|
importName: (specifier) => platformPackage.test(specifier) ? "Java standard library" : specifier.split(".").slice(0, 2).join("."),
|
|
17995
17995
|
create: () => new JavaMapAnalyzer()
|
|
@@ -18079,12 +18079,12 @@ var JavaMapAnalyzer = class _JavaMapAnalyzer {
|
|
|
18079
18079
|
// The worker's request for a context: the Java sources, the release and which are tests.
|
|
18080
18080
|
request(input, buildTexts) {
|
|
18081
18081
|
const files = /* @__PURE__ */ Object.create(null);
|
|
18082
|
-
for (const [
|
|
18083
|
-
if (this.claims(
|
|
18082
|
+
for (const [path14, text] of Object.entries(input.files))
|
|
18083
|
+
if (this.claims(path14)) files[path14] = text;
|
|
18084
18084
|
return {
|
|
18085
18085
|
files,
|
|
18086
18086
|
release: javaRelease(buildTexts, this.resources.runtimeVersion),
|
|
18087
|
-
tests: Object.keys(files).filter((
|
|
18087
|
+
tests: Object.keys(files).filter((path14) => mapTestPath(path14))
|
|
18088
18088
|
};
|
|
18089
18089
|
}
|
|
18090
18090
|
// The build files of a context's root directory, which declare its Java version.
|
|
@@ -18096,35 +18096,35 @@ var JavaMapAnalyzer = class _JavaMapAnalyzer {
|
|
|
18096
18096
|
}
|
|
18097
18097
|
async analyze(session, signal) {
|
|
18098
18098
|
this.refreshRuntime();
|
|
18099
|
-
const builds = session.readable.map((entry) => entry.path).filter((
|
|
18100
|
-
for (const
|
|
18101
|
-
const rank2 = (
|
|
18099
|
+
const builds = session.readable.map((entry) => entry.path).filter((path14) => buildFile.test(path14));
|
|
18100
|
+
for (const path14 of builds) session.configuration(path14);
|
|
18101
|
+
const rank2 = (path14) => BUILD_FILES.indexOf(nameOf(path14));
|
|
18102
18102
|
const roots = /* @__PURE__ */ new Map();
|
|
18103
18103
|
const modules = /* @__PURE__ */ new Map();
|
|
18104
|
-
for (const
|
|
18105
|
-
const directory = directoryOf(
|
|
18104
|
+
for (const path14 of builds) {
|
|
18105
|
+
const directory = directoryOf(path14);
|
|
18106
18106
|
const current = modules.get(directory);
|
|
18107
|
-
if (current === void 0 || rank2(
|
|
18108
|
-
const text = session.texts[
|
|
18109
|
-
if (/settings\.gradle(?:\.kts)?$/u.test(
|
|
18107
|
+
if (current === void 0 || rank2(path14) < rank2(current)) modules.set(directory, path14);
|
|
18108
|
+
const text = session.texts[path14] ?? "";
|
|
18109
|
+
if (/settings\.gradle(?:\.kts)?$/u.test(path14) || path14.endsWith("pom.xml") && /<modules>/u.test(text)) {
|
|
18110
18110
|
const root = roots.get(directory);
|
|
18111
|
-
if (root === void 0 || rank2(
|
|
18111
|
+
if (root === void 0 || rank2(path14) < rank2(root)) roots.set(directory, path14);
|
|
18112
18112
|
}
|
|
18113
18113
|
}
|
|
18114
|
-
const configOf = (
|
|
18114
|
+
const configOf = (path14) => {
|
|
18115
18115
|
let outer;
|
|
18116
18116
|
for (const directory of roots.keys())
|
|
18117
|
-
if (
|
|
18117
|
+
if (path14.startsWith(directory) && (outer === void 0 || directory.length < outer.length))
|
|
18118
18118
|
outer = directory;
|
|
18119
18119
|
if (outer !== void 0) return roots.get(outer);
|
|
18120
18120
|
let nearest;
|
|
18121
18121
|
for (const directory of modules.keys())
|
|
18122
|
-
if (
|
|
18122
|
+
if (path14.startsWith(directory) && (nearest === void 0 || directory.length > nearest.length))
|
|
18123
18123
|
nearest = directory;
|
|
18124
18124
|
return nearest === void 0 ? "" : modules.get(nearest);
|
|
18125
18125
|
};
|
|
18126
|
-
const output = (
|
|
18127
|
-
(directory) =>
|
|
18126
|
+
const output = (path14) => [...modules.keys()].some(
|
|
18127
|
+
(directory) => path14.startsWith(`${directory}build/`) || path14.startsWith(`${directory}target/`)
|
|
18128
18128
|
);
|
|
18129
18129
|
const groups = /* @__PURE__ */ new Map();
|
|
18130
18130
|
for (const entry of session.readable) {
|
|
@@ -18139,13 +18139,13 @@ var JavaMapAnalyzer = class _JavaMapAnalyzer {
|
|
|
18139
18139
|
if (signal.aborted) throw new ProjectEvidenceError("PROJECT_READ_CANCELLED", true);
|
|
18140
18140
|
const files = /* @__PURE__ */ Object.create(null);
|
|
18141
18141
|
const rootBuilds = configPath ? BUILD_FILES.map((name) => `${directoryOf(configPath)}${name}`).filter(
|
|
18142
|
-
(
|
|
18142
|
+
(path14) => builds.includes(path14)
|
|
18143
18143
|
) : [];
|
|
18144
|
-
for (const
|
|
18145
|
-
const text = session.texts[
|
|
18144
|
+
for (const path14 of [...groups.get(configPath) ?? [], ...rootBuilds]) {
|
|
18145
|
+
const text = session.texts[path14];
|
|
18146
18146
|
if (text === void 0)
|
|
18147
18147
|
throw new ProjectEvidenceError("PROJECT_MAP_PROTOCOL_INVALID", false);
|
|
18148
|
-
files[
|
|
18148
|
+
files[path14] = text;
|
|
18149
18149
|
}
|
|
18150
18150
|
const input = {
|
|
18151
18151
|
contextRef: digestValue({
|
|
@@ -18188,7 +18188,7 @@ var JavaMapAnalyzer = class _JavaMapAnalyzer {
|
|
|
18188
18188
|
const prior = JavaStateSchema.safeParse(previous?.state).data;
|
|
18189
18189
|
const incremental = previous && prior?.basis === basis ? {
|
|
18190
18190
|
changed: Object.keys(request.files).filter(
|
|
18191
|
-
(
|
|
18191
|
+
(path14) => digests.get(path14) !== previous.digests.get(path14)
|
|
18192
18192
|
),
|
|
18193
18193
|
state: prior.java
|
|
18194
18194
|
} : void 0;
|
|
@@ -18217,14 +18217,14 @@ var JavaMapAnalyzer = class _JavaMapAnalyzer {
|
|
|
18217
18217
|
continue;
|
|
18218
18218
|
}
|
|
18219
18219
|
const focus = new Set(facts.focus);
|
|
18220
|
-
if (!incremental || facts.focus.some((
|
|
18220
|
+
if (!incremental || facts.focus.some((path14) => !Object.hasOwn(request.files, path14)) || incremental.changed.some((path14) => !focus.has(path14)))
|
|
18221
18221
|
throw new ProjectEvidenceError("PROJECT_MAP_PROTOCOL_INVALID", false);
|
|
18222
18222
|
analysis.objects = analysis.objects.filter((object2) => focus.has(object2.anchor.path));
|
|
18223
18223
|
analysis.relations = analysis.relations.filter((relation) => focus.has(relation.anchor.path));
|
|
18224
18224
|
analysis.notes = analysis.notes.filter((note) => focus.has(note.anchor.path));
|
|
18225
18225
|
session.accept(analysis, {
|
|
18226
18226
|
state,
|
|
18227
|
-
linked: analysis.parsedFiles.filter((
|
|
18227
|
+
linked: analysis.parsedFiles.filter((path14) => !focus.has(path14))
|
|
18228
18228
|
});
|
|
18229
18229
|
}
|
|
18230
18230
|
}
|
|
@@ -18536,12 +18536,12 @@ var PYTHON_STANDARD_LIBRARY = /* @__PURE__ */ new Set([
|
|
|
18536
18536
|
// src/project-map-language-python.ts
|
|
18537
18537
|
var CONFIGURATION = ["pyrightconfig.json", "pyproject.toml", "setup.cfg"];
|
|
18538
18538
|
var pythonConfig = /(?:^|\/)(?:pyrightconfig\.json|pyproject\.toml|setup\.cfg)$/u;
|
|
18539
|
-
var directoryOf2 = (
|
|
18539
|
+
var directoryOf2 = (path14) => path14.slice(0, path14.lastIndexOf("/") + 1);
|
|
18540
18540
|
var DEFAULT_PYTHON = { major: 3, minor: 13 };
|
|
18541
18541
|
var PYTHON_MAP_LANGUAGE = Object.freeze({
|
|
18542
18542
|
id: "pyright-1.1.414-map-v13",
|
|
18543
|
-
claims: (
|
|
18544
|
-
reads: (
|
|
18543
|
+
claims: (path14) => /\.pyi?$/u.test(path14),
|
|
18544
|
+
reads: (path14) => pythonConfig.test(path14),
|
|
18545
18545
|
// An absolute import names the standard library or a distribution's top-level package.
|
|
18546
18546
|
importName: (specifier) => {
|
|
18547
18547
|
const top = specifier.split(".", 1)[0] ?? specifier;
|
|
@@ -18593,21 +18593,21 @@ var PythonMapAnalyzer = class {
|
|
|
18593
18593
|
return {
|
|
18594
18594
|
root: input.configPath ? directoryOf2(input.configPath).replace(/\/$/u, "") : "",
|
|
18595
18595
|
pythonVersion: pythonVersion(input.files, input.configPath),
|
|
18596
|
-
tests: Object.keys(input.files).filter((
|
|
18596
|
+
tests: Object.keys(input.files).filter((path14) => this.claims(path14) && mapTestPath(path14))
|
|
18597
18597
|
};
|
|
18598
18598
|
}
|
|
18599
18599
|
async analyze(session, signal) {
|
|
18600
18600
|
const roots = /* @__PURE__ */ new Map();
|
|
18601
|
-
for (const
|
|
18602
|
-
const directory = directoryOf2(
|
|
18601
|
+
for (const path14 of session.readable.map((entry) => entry.path).filter((path15) => pythonConfig.test(path15))) {
|
|
18602
|
+
const directory = directoryOf2(path14);
|
|
18603
18603
|
const current = roots.get(directory);
|
|
18604
18604
|
const rank2 = (file2) => CONFIGURATION.indexOf(file2.slice(directory.length));
|
|
18605
|
-
if (current === void 0 || rank2(
|
|
18605
|
+
if (current === void 0 || rank2(path14) < rank2(current)) roots.set(directory, path14);
|
|
18606
18606
|
}
|
|
18607
|
-
const rootOf = (
|
|
18607
|
+
const rootOf = (path14) => {
|
|
18608
18608
|
let best;
|
|
18609
18609
|
for (const directory of roots.keys())
|
|
18610
|
-
if (
|
|
18610
|
+
if (path14.startsWith(directory) && (best === void 0 || directory.length > best.length))
|
|
18611
18611
|
best = directory;
|
|
18612
18612
|
return best === void 0 ? "" : roots.get(best);
|
|
18613
18613
|
};
|
|
@@ -18622,11 +18622,11 @@ var PythonMapAnalyzer = class {
|
|
|
18622
18622
|
for (const configPath of [...groups.keys()].sort()) {
|
|
18623
18623
|
if (signal.aborted) throw new ProjectEvidenceError("PROJECT_READ_CANCELLED", true);
|
|
18624
18624
|
const files = /* @__PURE__ */ Object.create(null);
|
|
18625
|
-
for (const
|
|
18626
|
-
const text = session.texts[
|
|
18625
|
+
for (const path14 of [...groups.get(configPath) ?? [], ...configPath ? [configPath] : []]) {
|
|
18626
|
+
const text = session.texts[path14];
|
|
18627
18627
|
if (text === void 0)
|
|
18628
18628
|
throw new ProjectEvidenceError("PROJECT_MAP_PROTOCOL_INVALID", false);
|
|
18629
|
-
files[
|
|
18629
|
+
files[path14] = text;
|
|
18630
18630
|
}
|
|
18631
18631
|
const input = {
|
|
18632
18632
|
contextRef: digestValue({
|
|
@@ -18674,8 +18674,8 @@ var PythonMapAnalyzer = class {
|
|
|
18674
18674
|
if (input.files[reference.targetPath] === void 0)
|
|
18675
18675
|
throw new ProjectEvidenceError("PROJECT_MAP_REFERENCE_TARGET_UNAVAILABLE", false);
|
|
18676
18676
|
const files = /* @__PURE__ */ Object.create(null);
|
|
18677
|
-
for (const [
|
|
18678
|
-
if (this.claims(
|
|
18677
|
+
for (const [path14, value] of Object.entries(input.files))
|
|
18678
|
+
if (this.claims(path14) || pythonConfig.test(path14)) files[path14] = value;
|
|
18679
18679
|
const facts = await this.operation(
|
|
18680
18680
|
{
|
|
18681
18681
|
...input,
|
|
@@ -18695,8 +18695,8 @@ var PythonMapAnalyzer = class {
|
|
|
18695
18695
|
// src/project-map-language-typescript.ts
|
|
18696
18696
|
var TYPESCRIPT_MAP_LANGUAGE = Object.freeze({
|
|
18697
18697
|
id: "typescript-7.0.2-map-v17",
|
|
18698
|
-
claims: (
|
|
18699
|
-
reads: (
|
|
18698
|
+
claims: (path14) => /\.[cm]?[jt]sx?$/u.test(path14),
|
|
18699
|
+
reads: (path14) => path14.endsWith(".json") || path14 === "pnpm-workspace.yaml",
|
|
18700
18700
|
create: () => new TypeScriptMapAnalyzer()
|
|
18701
18701
|
});
|
|
18702
18702
|
var CONFIGURATIONS_KEPT = 4;
|
|
@@ -18808,9 +18808,9 @@ var TypeScriptMapAnalyzer = class {
|
|
|
18808
18808
|
accept(analysis);
|
|
18809
18809
|
return;
|
|
18810
18810
|
}
|
|
18811
|
-
const required2 = analysis.requiredFiles.map((
|
|
18812
|
-
const entry = byPath.get(
|
|
18813
|
-
if (!entry || Object.hasOwn(texts,
|
|
18811
|
+
const required2 = analysis.requiredFiles.map((path14) => {
|
|
18812
|
+
const entry = byPath.get(path14);
|
|
18813
|
+
if (!entry || Object.hasOwn(texts, path14))
|
|
18814
18814
|
throw new ProjectEvidenceError("PROJECT_MAP_PROTOCOL_INVALID", false);
|
|
18815
18815
|
return entry;
|
|
18816
18816
|
});
|
|
@@ -18868,16 +18868,16 @@ var MAP_LANGUAGES = Object.freeze([
|
|
|
18868
18868
|
]);
|
|
18869
18869
|
var mapAnalyzerSuite = (languages) => languages.map((language) => language.id).sort().join("+");
|
|
18870
18870
|
var PROJECT_MAP_ANALYZER = mapAnalyzerSuite(MAP_LANGUAGES);
|
|
18871
|
-
var mapCodePath = (
|
|
18872
|
-
var languageOf = (
|
|
18873
|
-
var mapLanguageOf = (
|
|
18871
|
+
var mapCodePath = (path14) => MAP_LANGUAGES.some((language) => language.claims(path14));
|
|
18872
|
+
var languageOf = (path14) => MAP_LANGUAGES.find((language) => language.claims(path14));
|
|
18873
|
+
var mapLanguageOf = (path14) => languageOf(path14)?.id;
|
|
18874
18874
|
var npmPackage = (specifier) => {
|
|
18875
18875
|
if (specifier.startsWith("node:")) return "node:*";
|
|
18876
18876
|
const parts = specifier.split("/");
|
|
18877
18877
|
return specifier.startsWith("@") ? parts.slice(0, 2).join("/") : parts[0] ?? specifier;
|
|
18878
18878
|
};
|
|
18879
18879
|
var mapExternalImport = (sourcePath, specifier) => languageOf(sourcePath)?.importName?.(specifier) ?? npmPackage(specifier);
|
|
18880
|
-
var mapImportTarget = (
|
|
18880
|
+
var mapImportTarget = (path14) => languageOf(path14)?.importTarget?.(path14) ?? path14;
|
|
18881
18881
|
|
|
18882
18882
|
// src/project-map-view.ts
|
|
18883
18883
|
var MAP_VIEW_FORMAT = "PROJECT_MAP_VIEW_V1";
|
|
@@ -18916,10 +18916,10 @@ var notFound = () => {
|
|
|
18916
18916
|
};
|
|
18917
18917
|
var MAP_KINDS_LEGEND = "kinds f function, c class, m method, p property, v variable, t type, i interface, e enum; numbers are 1-based source lines";
|
|
18918
18918
|
var MAP_DECLARATION_LEGEND = `@n marks where a relationship occurs and +n counts further sites, which project_find_references lists; a quoted path after the sites is the route the call or value is registered under there: its HTTP methods when the registration names them, then its path joined with the prefixes of the routers it is registered on, as far as the same function or file sets them (a prefix added where a router is mounted or passed in is not included); route "\u2026" after a decorator is the full route the decorator maps, its class's path joined with its own. Static relationships are grouped by the declaration that owns them. Callers are direct calls, uses as a value (stored, passed, returned or selected, then usually invoked through that value) and calls through an interface, type or base member that a declaration implements (dispatched from); dispatches to lists the members that implement an interface, type or base member, which a call through it may reach; trace stops names calls whose target is a function value, a member without a mapped implementation or a computed key, which only source reading can follow; possible callers by name are calls elsewhere, in the same language, of a member with a method's name on a receiver of unknown type (an untyped value, or one an unloaded package produced); they may or may not reach that method.`;
|
|
18919
|
-
var within = (
|
|
18920
|
-
var parentDirectory = (
|
|
18921
|
-
const slash =
|
|
18922
|
-
return slash < 0 ? "." :
|
|
18919
|
+
var within = (path14, directory) => directory === "." || path14.startsWith(`${directory}/`);
|
|
18920
|
+
var parentDirectory = (path14) => {
|
|
18921
|
+
const slash = path14.lastIndexOf("/");
|
|
18922
|
+
return slash < 0 ? "." : path14.slice(0, slash);
|
|
18923
18923
|
};
|
|
18924
18924
|
var compareText2 = (left, right) => left < right ? -1 : left > right ? 1 : 0;
|
|
18925
18925
|
var byCount = ([leftName, left], [rightName, right]) => right - left || compareText2(leftName, rightName);
|
|
@@ -18993,7 +18993,7 @@ function pageBlocks(view, head, whole, offset, budget) {
|
|
|
18993
18993
|
if (offset === blocks.length) return materialize(0);
|
|
18994
18994
|
return mapQueryPage(blocks.length - offset, materialize, (page) => page, budget);
|
|
18995
18995
|
}
|
|
18996
|
-
var inModule = (
|
|
18996
|
+
var inModule = (path14, module) => module.direct ? parentDirectory(path14) === module.directory : within(path14, module.directory);
|
|
18997
18997
|
var moduleLabel = (module) => module.direct ? `${module.directory === "." ? "" : `${module.directory}/`}* (files directly here)` : `${module.directory}/`;
|
|
18998
18998
|
function childModules(module, files) {
|
|
18999
18999
|
if (module.direct) return [];
|
|
@@ -19146,12 +19146,12 @@ function loadMemberCalls(store, version2) {
|
|
|
19146
19146
|
FROM project_map_relations
|
|
19147
19147
|
WHERE version_ref = ? AND to_ref IS NULL AND json_extract(relation_json, '$.kind') = 'CALLS'
|
|
19148
19148
|
AND json_extract(relation_json, '$.unresolvedReason') IN ('SYMBOL_NOT_RESOLVED', 'SYNTAX_ONLY')`).all(version2)) {
|
|
19149
|
-
const
|
|
19149
|
+
const path14 = String(row.path);
|
|
19150
19150
|
const target = String(row.target);
|
|
19151
19151
|
const name = MEMBER_NAME.exec(target)?.[1];
|
|
19152
|
-
const language = mapLanguageOf(
|
|
19152
|
+
const language = mapLanguageOf(path14);
|
|
19153
19153
|
if (!name || !language) continue;
|
|
19154
|
-
const call = { from: String(row.from_ref), path:
|
|
19154
|
+
const call = { from: String(row.from_ref), path: path14, line: Number(row.line), target };
|
|
19155
19155
|
const key = memberKey(language, name);
|
|
19156
19156
|
const known = calls.get(key);
|
|
19157
19157
|
if (known) known.push(call);
|
|
@@ -19206,10 +19206,10 @@ function loadCoverageNotes(store, version2) {
|
|
|
19206
19206
|
if (!codes.includes(gap.code)) codes.push(gap.code);
|
|
19207
19207
|
files.set(gap.path, codes);
|
|
19208
19208
|
}
|
|
19209
|
-
for (const [
|
|
19209
|
+
for (const [path14, codes] of files)
|
|
19210
19210
|
if (codes.length > 1 && codes.includes("NOT_IN_PARSED_CONTEXT"))
|
|
19211
19211
|
files.set(
|
|
19212
|
-
|
|
19212
|
+
path14,
|
|
19213
19213
|
codes.filter((code) => code !== "NOT_IN_PARSED_CONTEXT")
|
|
19214
19214
|
);
|
|
19215
19215
|
return { files, limits: [...limits] };
|
|
@@ -19244,9 +19244,9 @@ function directoryView(facts, coverage, entries, input, directory, prefixes) {
|
|
|
19244
19244
|
const visiblePaths = new Set(visible.map((entry) => entry.path));
|
|
19245
19245
|
const code = visible.filter((entry) => entry.state === "TEXT" && mapCodePath(entry.path)).map((entry) => entry.path);
|
|
19246
19246
|
const modules = mapModules(directory, code);
|
|
19247
|
-
const moduleOf = (
|
|
19248
|
-
const outside = (
|
|
19249
|
-
const parts =
|
|
19247
|
+
const moduleOf = (path14) => modules.find((module) => inModule(path14, module));
|
|
19248
|
+
const outside = (path14) => {
|
|
19249
|
+
const parts = path14.split("/");
|
|
19250
19250
|
return `${parts.slice(0, Math.min(2, parts.length - 1)).join("/") || "."}/ (outside)`;
|
|
19251
19251
|
};
|
|
19252
19252
|
const moduleImports = /* @__PURE__ */ new Map();
|
|
@@ -19271,8 +19271,8 @@ function directoryView(facts, coverage, entries, input, directory, prefixes) {
|
|
|
19271
19271
|
const blocks = [];
|
|
19272
19272
|
if (modules.length > 1) {
|
|
19273
19273
|
const sizes = /* @__PURE__ */ new Map();
|
|
19274
|
-
for (const
|
|
19275
|
-
const module = moduleOf(
|
|
19274
|
+
for (const path14 of code) {
|
|
19275
|
+
const module = moduleOf(path14);
|
|
19276
19276
|
if (module) increment(sizes, moduleLabel(module));
|
|
19277
19277
|
}
|
|
19278
19278
|
blocks.push(
|
|
@@ -19301,18 +19301,18 @@ function directoryView(facts, coverage, entries, input, directory, prefixes) {
|
|
|
19301
19301
|
)}${packages.length > shown.length ? `, +${packages.length - shown.length} more` : ""}`
|
|
19302
19302
|
);
|
|
19303
19303
|
}
|
|
19304
|
-
const lineCount = (
|
|
19305
|
-
const file2 = facts.files.get(
|
|
19306
|
-
const gaps = coverage.files.get(
|
|
19304
|
+
const lineCount = (path14) => {
|
|
19305
|
+
const file2 = facts.files.get(path14);
|
|
19306
|
+
const gaps = coverage.files.get(path14) ?? [];
|
|
19307
19307
|
if (file2?.parsed === false) return `[not parsed${gaps.length ? `: ${gaps.join("; ")}` : ""}]`;
|
|
19308
19308
|
return `${file2 ? `${file2.lines}L` : "?L"}${gaps.length ? ` [${gaps.join("; ")}]` : ""}`;
|
|
19309
19309
|
};
|
|
19310
19310
|
const codeDirectories = /* @__PURE__ */ new Set();
|
|
19311
|
-
for (const
|
|
19312
|
-
for (let parent = parentDirectory(
|
|
19311
|
+
for (const path14 of code)
|
|
19312
|
+
for (let parent = parentDirectory(path14); parent !== "." && !codeDirectories.has(parent); parent = parentDirectory(parent))
|
|
19313
19313
|
codeDirectories.add(parent);
|
|
19314
|
-
const groupOf = (
|
|
19315
|
-
let group = parentDirectory(
|
|
19314
|
+
const groupOf = (path14) => {
|
|
19315
|
+
let group = parentDirectory(path14);
|
|
19316
19316
|
for (let parent = group; parent !== "." && parent !== directory && !codeDirectories.has(parent); parent = parentDirectory(parent))
|
|
19317
19317
|
group = parent;
|
|
19318
19318
|
return group;
|
|
@@ -19344,11 +19344,11 @@ function directoryView(facts, coverage, entries, input, directory, prefixes) {
|
|
|
19344
19344
|
]);
|
|
19345
19345
|
}
|
|
19346
19346
|
const detailed = [
|
|
19347
|
-
...code.map((
|
|
19348
|
-
const declarations = (facts.exported.get(
|
|
19347
|
+
...code.map((path14) => {
|
|
19348
|
+
const declarations = (facts.exported.get(path14) ?? []).map(({ text: text2 }) => text2);
|
|
19349
19349
|
return [
|
|
19350
|
-
|
|
19351
|
-
`${
|
|
19350
|
+
path14,
|
|
19351
|
+
`${path14} ${lineCount(path14)}${declarations.length ? `: ${declarations.join(", ")}` : ""}`
|
|
19352
19352
|
];
|
|
19353
19353
|
}),
|
|
19354
19354
|
...listedOther.map((entry) => [
|
|
@@ -19359,7 +19359,7 @@ function directoryView(facts, coverage, entries, input, directory, prefixes) {
|
|
|
19359
19359
|
];
|
|
19360
19360
|
const directories = /* @__PURE__ */ new Map();
|
|
19361
19361
|
for (const entry of [
|
|
19362
|
-
...code.map((
|
|
19362
|
+
...code.map((path14) => ({ path: path14, item: lineCount(path14) })),
|
|
19363
19363
|
...listedOther.map((entry2) => ({
|
|
19364
19364
|
path: entry2.path,
|
|
19365
19365
|
item: entry2.state === "TEXT" ? "" : `(${entry2.state})`
|
|
@@ -19387,10 +19387,10 @@ function directoryView(facts, coverage, entries, input, directory, prefixes) {
|
|
|
19387
19387
|
);
|
|
19388
19388
|
const text = visible.filter((entry) => entry.state === "TEXT").length;
|
|
19389
19389
|
const resolution = /* @__PURE__ */ new Map();
|
|
19390
|
-
for (const
|
|
19391
|
-
const counts = facts.calls.get(
|
|
19390
|
+
for (const path14 of code) {
|
|
19391
|
+
const counts = facts.calls.get(path14);
|
|
19392
19392
|
if (!counts) continue;
|
|
19393
|
-
const language = facts.files.get(
|
|
19393
|
+
const language = facts.files.get(path14)?.language ?? "unknown";
|
|
19394
19394
|
const total = resolution.get(language) ?? { resolved: 0, unresolved: 0, external: 0 };
|
|
19395
19395
|
total.resolved += counts.resolved;
|
|
19396
19396
|
total.unresolved += counts.unresolved;
|
|
@@ -19448,8 +19448,8 @@ var DeclarationGroups = class {
|
|
|
19448
19448
|
prefixes;
|
|
19449
19449
|
showTests;
|
|
19450
19450
|
memberCalls;
|
|
19451
|
-
visible(
|
|
19452
|
-
return mapPathAllowed(
|
|
19451
|
+
visible(path14) {
|
|
19452
|
+
return mapPathAllowed(path14, this.prefixes) && (this.showTests || !mapTestPath(path14));
|
|
19453
19453
|
}
|
|
19454
19454
|
entry(object2, imported = false) {
|
|
19455
19455
|
if (mapIsModule(object2)) return imported ? "(file)" : "(module scope)";
|
|
@@ -19493,11 +19493,11 @@ var DeclarationGroups = class {
|
|
|
19493
19493
|
value.lines.push(line);
|
|
19494
19494
|
aggregates.set(key, value);
|
|
19495
19495
|
};
|
|
19496
|
-
const dispatch = (arrow, label, ref2,
|
|
19496
|
+
const dispatch = (arrow, label, ref2, path14, line) => {
|
|
19497
19497
|
const other = graph.object(graph.owner(ref2));
|
|
19498
19498
|
if (owned.has(other.id)) return;
|
|
19499
|
-
if (!this.visible(
|
|
19500
|
-
if (mapPathAllowed(
|
|
19499
|
+
if (!this.visible(path14)) {
|
|
19500
|
+
if (mapPathAllowed(path14, this.prefixes)) omittedTests++;
|
|
19501
19501
|
return;
|
|
19502
19502
|
}
|
|
19503
19503
|
add(arrow, label, other, line);
|
|
@@ -19654,7 +19654,7 @@ var DeclarationGroups = class {
|
|
|
19654
19654
|
else files2.set(call.path, [item]);
|
|
19655
19655
|
}
|
|
19656
19656
|
lines.push(
|
|
19657
|
-
` \u2190 possible callers by name: ${[...files2].map(([
|
|
19657
|
+
` \u2190 possible callers by name: ${[...files2].map(([path14, items]) => `${path14}: ${items.join(", ")}`).join("; ")}${inTests}`
|
|
19658
19658
|
);
|
|
19659
19659
|
} else if (possibleInTests)
|
|
19660
19660
|
lines.push(` \u2190 possible callers by name: ${possibleInTests} in test files (includeTests)`);
|
|
@@ -19690,14 +19690,14 @@ var DeclarationGroups = class {
|
|
|
19690
19690
|
return { lines, neighbors: [...new Set(neighbors)] };
|
|
19691
19691
|
}
|
|
19692
19692
|
};
|
|
19693
|
-
function fileView(store, coverage, graph, input,
|
|
19694
|
-
const entry = store.getEntry(input.version,
|
|
19695
|
-
if (!entry || !mapPathAllowed(
|
|
19696
|
-
const showTests = input.includeTests === true || mapTestPath(
|
|
19697
|
-
const module = mapCodePath(
|
|
19698
|
-
const gaps = coverage.files.get(
|
|
19693
|
+
function fileView(store, coverage, graph, input, path14, prefixes) {
|
|
19694
|
+
const entry = store.getEntry(input.version, path14);
|
|
19695
|
+
if (!entry || !mapPathAllowed(path14, prefixes)) return notFound();
|
|
19696
|
+
const showTests = input.includeTests === true || mapTestPath(path14);
|
|
19697
|
+
const module = mapCodePath(path14) ? graph.objectsAt(path14).find((object2) => mapIsModule(object2)) : void 0;
|
|
19698
|
+
const gaps = coverage.files.get(path14) ?? [];
|
|
19699
19699
|
const head = [
|
|
19700
|
-
`PROJECT MAP \xB7 FILE ${
|
|
19700
|
+
`PROJECT MAP \xB7 FILE ${path14} \xB7 ${entry.state !== "TEXT" ? entry.state : module ? module.parsing === "NOT_PARSED" ? `not parsed${gaps.length ? ` (${gaps.join("; ")})` : ""}; read it as text` : `${module.anchor.endLine} lines${gaps.length ? ` \xB7 ${gaps.join("; ")}` : ""}` : `${entry.byteLength} bytes, not analyzed; read it as text`}`
|
|
19701
19701
|
];
|
|
19702
19702
|
if (!module || entry.state !== "TEXT")
|
|
19703
19703
|
return pageBlocks("FILE", head, [], input.offset ?? 0, input.outputBudget);
|
|
@@ -19717,7 +19717,7 @@ function fileView(store, coverage, graph, input, path13, prefixes) {
|
|
|
19717
19717
|
tags.set(relation.from, list);
|
|
19718
19718
|
}
|
|
19719
19719
|
const describe3 = (object2) => [
|
|
19720
|
-
`${object2.name} ${mapDeclarationLabel(object2)}${object2.anchor.path ===
|
|
19720
|
+
`${object2.name} ${mapDeclarationLabel(object2)}${object2.anchor.path === path14 ? "" : ` (${object2.anchor.path})`}`,
|
|
19721
19721
|
...tags.get(object2.id) ?? []
|
|
19722
19722
|
].join(" ");
|
|
19723
19723
|
const declarations = [];
|
|
@@ -19732,11 +19732,11 @@ function fileView(store, coverage, graph, input, path13, prefixes) {
|
|
|
19732
19732
|
);
|
|
19733
19733
|
}
|
|
19734
19734
|
const elsewhere = /* @__PURE__ */ new Map();
|
|
19735
|
-
for (const object2 of graph.objectsAt(
|
|
19735
|
+
for (const object2 of graph.objectsAt(path14)) {
|
|
19736
19736
|
const parent = mapIsModule(object2) ? void 0 : graph.parent(object2.id);
|
|
19737
19737
|
if (parent === void 0 || !graph.isAddressable(object2)) continue;
|
|
19738
19738
|
const container = graph.object(parent);
|
|
19739
|
-
if (mapIsModule(container) || container.anchor.path ===
|
|
19739
|
+
if (mapIsModule(container) || container.anchor.path === path14) continue;
|
|
19740
19740
|
const into = elsewhere.get(parent);
|
|
19741
19741
|
if (into) into.push(object2);
|
|
19742
19742
|
else elsewhere.set(parent, [object2]);
|
|
@@ -19750,7 +19750,7 @@ function fileView(store, coverage, graph, input, path13, prefixes) {
|
|
|
19750
19750
|
if (declarations.length) blocks.push(["DECLARATIONS (* exported)", ...declarations].join("\n"));
|
|
19751
19751
|
const imports = /* @__PURE__ */ new Set();
|
|
19752
19752
|
const external = /* @__PURE__ */ new Set();
|
|
19753
|
-
const fileObjects = graph.objectsAt(
|
|
19753
|
+
const fileObjects = graph.objectsAt(path14).map((object2) => object2.id);
|
|
19754
19754
|
for (const relation of graph.relationsFrom(fileObjects)) {
|
|
19755
19755
|
if (!IMPORT_KINDS.has(relation.kind)) continue;
|
|
19756
19756
|
if (relation.to === void 0) external.add(relation.target);
|
|
@@ -19761,8 +19761,8 @@ function fileView(store, coverage, graph, input, path13, prefixes) {
|
|
|
19761
19761
|
}
|
|
19762
19762
|
const importers = /* @__PURE__ */ new Set();
|
|
19763
19763
|
const testImporters = /* @__PURE__ */ new Set();
|
|
19764
|
-
const imported = mapImportTarget(
|
|
19765
|
-
const packageModules = imported ===
|
|
19764
|
+
const imported = mapImportTarget(path14);
|
|
19765
|
+
const packageModules = imported === path14 ? [module.id] : store.listEntries(input.version).filter((entry2) => mapImportTarget(entry2.path) === imported).flatMap((entry2) => graph.objectsAt(entry2.path).filter((object2) => mapIsModule(object2))).map((object2) => object2.id);
|
|
19766
19766
|
for (const relation of graph.relationsTo(packageModules)) {
|
|
19767
19767
|
if (!IMPORT_KINDS.has(relation.kind)) continue;
|
|
19768
19768
|
const source = relation.anchor.path;
|
|
@@ -19790,16 +19790,16 @@ function fileView(store, coverage, graph, input, path13, prefixes) {
|
|
|
19790
19790
|
if (scope.length) blocks.push(["MODULE SCOPE (top-level statements)", ...scope].join("\n"));
|
|
19791
19791
|
return pageBlocks("FILE", head, blocks, input.offset ?? 0, input.outputBudget);
|
|
19792
19792
|
}
|
|
19793
|
-
function declarationView(graph, input,
|
|
19793
|
+
function declarationView(graph, input, path14, prefixes, memberCalls) {
|
|
19794
19794
|
const requested = input.depth ?? 1;
|
|
19795
19795
|
if (!Number.isSafeInteger(requested) || requested < 1 || requested > MAP_VIEW_LIMITS.directedDepth)
|
|
19796
19796
|
return invalid2();
|
|
19797
19797
|
const both = (input.direction ?? "BOTH") === "BOTH";
|
|
19798
19798
|
const depth = both ? Math.min(requested, MAP_VIEW_LIMITS.bothDepth) : requested;
|
|
19799
19799
|
const { name, line } = input;
|
|
19800
|
-
const selected = mapSelectDeclarations(graph,
|
|
19800
|
+
const selected = mapSelectDeclarations(graph, path14, name, line);
|
|
19801
19801
|
if (!selected.length) return notFound();
|
|
19802
|
-
const showTests = input.includeTests === true || mapTestPath(
|
|
19802
|
+
const showTests = input.includeTests === true || mapTestPath(path14);
|
|
19803
19803
|
const groups = new DeclarationGroups(graph, input, prefixes, showTests, memberCalls);
|
|
19804
19804
|
const blocks = [];
|
|
19805
19805
|
const seen = /* @__PURE__ */ new Set();
|
|
@@ -19847,7 +19847,7 @@ function declarationView(graph, input, path13, prefixes, memberCalls) {
|
|
|
19847
19847
|
);
|
|
19848
19848
|
}
|
|
19849
19849
|
const head = [
|
|
19850
|
-
`PROJECT MAP \xB7 DECLARATION ${
|
|
19850
|
+
`PROJECT MAP \xB7 DECLARATION ${path14}${name === void 0 ? "" : ` ${name}`}${line === void 0 ? "" : ` line ${line}`} \xB7 direction ${input.direction ?? "BOTH"} \xB7 depth ${depth}${depth < requested ? ` (BOTH is limited to ${MAP_VIEW_LIMITS.bothDepth})` : ""}${prefixes.includes(".") ? "" : " \xB7 limited to authorized paths"}`,
|
|
19851
19851
|
...truncated ? [`Expansion stopped at ${MAP_VIEW_LIMITS.declarations} declarations.`] : [],
|
|
19852
19852
|
...(input.direction ?? "BOTH") === "OUTGOING" ? [] : [callerCoverage(input.textSearch ?? DEFAULT_TEXT_SEARCH)]
|
|
19853
19853
|
];
|
|
@@ -19974,10 +19974,10 @@ var ProjectMapQuery = class {
|
|
|
19974
19974
|
view(input, signal) {
|
|
19975
19975
|
this.requireReadableMap(input.version, signal);
|
|
19976
19976
|
const { offset, prefixes } = admission(input);
|
|
19977
|
-
const
|
|
19977
|
+
const path14 = normalizeProjectEvidencePath(input.path, true) || ".";
|
|
19978
19978
|
const view = mapView(
|
|
19979
19979
|
this.store,
|
|
19980
|
-
{ ...input, path:
|
|
19980
|
+
{ ...input, path: path14, offset, allowedPathPrefixes: prefixes },
|
|
19981
19981
|
this.views
|
|
19982
19982
|
);
|
|
19983
19983
|
if (signal.aborted) throw new ProjectEvidenceError("PROJECT_READ_CANCELLED", true);
|
|
@@ -20882,7 +20882,7 @@ var CodeIndexStore = class {
|
|
|
20882
20882
|
const staged = this.stageUnits(buildRef, paths, linked);
|
|
20883
20883
|
const reused = linked ? this.database.prepare(`SELECT path, unit_ref FROM project_map_version_units
|
|
20884
20884
|
WHERE version_ref = ? AND path IN (SELECT value FROM json_each(?))`).all(linked.version, JSON.stringify([...linked.paths])).map((row) => ({ path: String(row.path), unit: String(row.unit_ref) })) : [];
|
|
20885
|
-
if (reused.length !== (linked?.paths.size ?? 0) || reused.some(({ path:
|
|
20885
|
+
if (reused.length !== (linked?.paths.size ?? 0) || reused.some(({ path: path14 }) => !paths.has(path14)) || staged.some(({ path: path14 }) => linked?.paths.has(path14)))
|
|
20886
20886
|
throw new MapReplayConflict();
|
|
20887
20887
|
const units = [...staged, ...reused].sort(
|
|
20888
20888
|
(left, right) => left.path < right.path ? -1 : left.path > right.path ? 1 : 0
|
|
@@ -20933,7 +20933,7 @@ var CodeIndexStore = class {
|
|
|
20933
20933
|
const member = this.database.prepare(
|
|
20934
20934
|
"INSERT INTO project_map_version_units VALUES (?, ?, ?)"
|
|
20935
20935
|
);
|
|
20936
|
-
for (const { path:
|
|
20936
|
+
for (const { path: path14, unit } of reused) member.run(version2.version, path14, unit);
|
|
20937
20937
|
this.database.prepare("INSERT INTO project_map_coverage VALUES (?, ?)").run(version2.version, canonicalJson(coverage));
|
|
20938
20938
|
}
|
|
20939
20939
|
this.database.exec("COMMIT");
|
|
@@ -20997,7 +20997,7 @@ var CodeIndexStore = class {
|
|
|
20997
20997
|
corrupt2();
|
|
20998
20998
|
}
|
|
20999
20999
|
if (linked) {
|
|
21000
|
-
const unlinked = database.prepare("SELECT path FROM project_map_version_units WHERE version_ref = ?").all(linked.version).map((row) => String(row.path)).filter((
|
|
21000
|
+
const unlinked = database.prepare("SELECT path FROM project_map_version_units WHERE version_ref = ?").all(linked.version).map((row) => String(row.path)).filter((path14) => !linked.paths.has(path14));
|
|
21001
21001
|
if (database.prepare(`SELECT 1 FROM project_map_objects gone
|
|
21002
21002
|
WHERE gone.version_ref = ? AND gone.path IN (SELECT value FROM json_each(?))
|
|
21003
21003
|
AND gone.entity_ref NOT IN (SELECT entity_ref FROM project_map_publish_objects)
|
|
@@ -21022,17 +21022,17 @@ var CodeIndexStore = class {
|
|
|
21022
21022
|
const units = [];
|
|
21023
21023
|
for (const row of database.prepare(`SELECT path FROM project_map_publish_objects
|
|
21024
21024
|
UNION SELECT path FROM project_map_publish_relations ORDER BY path`).all()) {
|
|
21025
|
-
const
|
|
21026
|
-
const hash2 = createHash3("sha256").update(
|
|
21025
|
+
const path14 = String(row.path);
|
|
21026
|
+
const hash2 = createHash3("sha256").update(path14).update("\0");
|
|
21027
21027
|
for (const [mark, statement] of [
|
|
21028
21028
|
["object", objects2],
|
|
21029
21029
|
["relation", relations],
|
|
21030
21030
|
["note", pathNotes]
|
|
21031
21031
|
])
|
|
21032
|
-
for (const fact of statement.all(
|
|
21032
|
+
for (const fact of statement.all(path14))
|
|
21033
21033
|
for (const value of Object.values(fact))
|
|
21034
21034
|
hash2.update(mark).update("\0").update(String(value)).update("\0");
|
|
21035
|
-
units.push({ path:
|
|
21035
|
+
units.push({ path: path14, unit: hash2.digest("hex") });
|
|
21036
21036
|
}
|
|
21037
21037
|
return units;
|
|
21038
21038
|
}
|
|
@@ -21050,23 +21050,27 @@ var CodeIndexStore = class {
|
|
|
21050
21050
|
"INSERT INTO project_map_unit_notes SELECT ?, * FROM project_map_publish_notes WHERE path = ?"
|
|
21051
21051
|
);
|
|
21052
21052
|
const member = database.prepare("INSERT INTO project_map_version_units VALUES (?, ?, ?)");
|
|
21053
|
-
for (const { path:
|
|
21054
|
-
if (insertUnit.run(unit,
|
|
21055
|
-
unitObjects.run(unit,
|
|
21056
|
-
unitRelations.run(unit,
|
|
21057
|
-
unitNotes.run(unit,
|
|
21053
|
+
for (const { path: path14, unit } of units) {
|
|
21054
|
+
if (insertUnit.run(unit, path14).changes) {
|
|
21055
|
+
unitObjects.run(unit, path14);
|
|
21056
|
+
unitRelations.run(unit, path14);
|
|
21057
|
+
unitNotes.run(unit, path14);
|
|
21058
21058
|
}
|
|
21059
|
-
member.run(version2,
|
|
21059
|
+
member.run(version2, path14, unit);
|
|
21060
21060
|
}
|
|
21061
21061
|
}
|
|
21062
|
-
/**
|
|
21063
|
-
|
|
21062
|
+
/**
|
|
21063
|
+
* Earlier versions of a project's scope built by the same analyzer, most recent first; with
|
|
21064
|
+
* another project, that project's versions of the same scope and analyzer as well.
|
|
21065
|
+
*/
|
|
21066
|
+
mapParentCandidates(version2, limit, otherProjectRef) {
|
|
21064
21067
|
return this.database.prepare(`SELECT version.version_ref FROM project_code_versions version
|
|
21065
21068
|
JOIN project_code_index_state state ON state.version_ref = version.version_ref
|
|
21066
|
-
WHERE version.project_ref
|
|
21069
|
+
WHERE version.project_ref IN (?, ?) AND version.analyzer = ? AND version.scope_json = ?
|
|
21067
21070
|
AND version.version_ref <> ?
|
|
21068
21071
|
ORDER BY state.completed_at DESC LIMIT ?`).all(
|
|
21069
21072
|
version2.projectRef,
|
|
21073
|
+
otherProjectRef ?? version2.projectRef,
|
|
21070
21074
|
version2.analyzer,
|
|
21071
21075
|
canonicalJson(version2.pathPrefixes),
|
|
21072
21076
|
version2.version,
|
|
@@ -21297,21 +21301,21 @@ var contextFiles = (context) => [
|
|
|
21297
21301
|
function replayableContexts(parent, digests) {
|
|
21298
21302
|
const sharing = /* @__PURE__ */ new Map();
|
|
21299
21303
|
for (const [ref, { context }] of parent.contexts)
|
|
21300
|
-
for (const
|
|
21301
|
-
const refs = sharing.get(
|
|
21304
|
+
for (const path14 of contextFiles(context)) {
|
|
21305
|
+
const refs = sharing.get(path14) ?? /* @__PURE__ */ new Set();
|
|
21302
21306
|
refs.add(ref);
|
|
21303
|
-
sharing.set(
|
|
21307
|
+
sharing.set(path14, refs);
|
|
21304
21308
|
}
|
|
21305
21309
|
const unchanged = /* @__PURE__ */ new Set();
|
|
21306
21310
|
for (const [ref, { context }] of parent.contexts)
|
|
21307
21311
|
if (contextFiles(context).every(
|
|
21308
|
-
(
|
|
21312
|
+
(path14) => digests.get(path14) !== void 0 && digests.get(path14) === parent.entries.get(path14)
|
|
21309
21313
|
))
|
|
21310
21314
|
unchanged.add(ref);
|
|
21311
21315
|
const replayable = /* @__PURE__ */ new Set();
|
|
21312
21316
|
for (const [ref, { context }] of parent.contexts)
|
|
21313
21317
|
if (unchanged.has(ref) && contextFiles(context).every(
|
|
21314
|
-
(
|
|
21318
|
+
(path14) => [...sharing.get(path14) ?? []].every((other) => unchanged.has(other))
|
|
21315
21319
|
))
|
|
21316
21320
|
replayable.add(ref);
|
|
21317
21321
|
return { replayable, sharing };
|
|
@@ -21344,8 +21348,8 @@ var ProjectMapAnalyzer = class {
|
|
|
21344
21348
|
languages;
|
|
21345
21349
|
observe;
|
|
21346
21350
|
id;
|
|
21347
|
-
claims(
|
|
21348
|
-
return this.languages.some((language) => language.claims(
|
|
21351
|
+
claims(path14) {
|
|
21352
|
+
return this.languages.some((language) => language.claims(path14));
|
|
21349
21353
|
}
|
|
21350
21354
|
references(input, reference, signal) {
|
|
21351
21355
|
const language = this.languages.find((language2) => language2.claims(reference.targetPath));
|
|
@@ -21385,7 +21389,7 @@ var ProjectMapAnalyzer = class {
|
|
|
21385
21389
|
const reuse = (contextRef2, request, files2) => {
|
|
21386
21390
|
const digest = digestValue({
|
|
21387
21391
|
request,
|
|
21388
|
-
files: files2.map((
|
|
21392
|
+
files: files2.map((path14) => [path14, digests.get(path14) ?? null])
|
|
21389
21393
|
});
|
|
21390
21394
|
requests.set(contextRef2, digest);
|
|
21391
21395
|
if (!parent || !replayable.has(contextRef2)) return void 0;
|
|
@@ -21425,7 +21429,7 @@ var ProjectMapAnalyzer = class {
|
|
|
21425
21429
|
const ref = analysis.contexts[0]?.ref ?? "";
|
|
21426
21430
|
if (options?.linked?.length) {
|
|
21427
21431
|
if (!parent || analysis.contexts.length !== 1) return invalidParent();
|
|
21428
|
-
for (const
|
|
21432
|
+
for (const path14 of options.linked) linked.add(path14);
|
|
21429
21433
|
this.observe?.({
|
|
21430
21434
|
operation: "LINK",
|
|
21431
21435
|
phase: "FINISHED",
|
|
@@ -21452,7 +21456,7 @@ var ProjectMapAnalyzer = class {
|
|
|
21452
21456
|
});
|
|
21453
21457
|
for (const file2 of analysis.parsedFiles) parsed.add(file2);
|
|
21454
21458
|
const staged = factPaths(analysis);
|
|
21455
|
-
for (const
|
|
21459
|
+
for (const path14 of staged) stagedPaths.add(path14);
|
|
21456
21460
|
for (const context of analysis.contexts) {
|
|
21457
21461
|
for (const file2 of context.configurationFiles) configurationInputs.add(file2);
|
|
21458
21462
|
if (!replayed.has(context.ref))
|
|
@@ -21481,7 +21485,7 @@ var ProjectMapAnalyzer = class {
|
|
|
21481
21485
|
accept,
|
|
21482
21486
|
reuse,
|
|
21483
21487
|
previous,
|
|
21484
|
-
configuration: (
|
|
21488
|
+
configuration: (path14) => configurationInputs.add(path14),
|
|
21485
21489
|
observe: this.observe
|
|
21486
21490
|
},
|
|
21487
21491
|
signal
|
|
@@ -21518,12 +21522,12 @@ var ProjectMapAnalyzer = class {
|
|
|
21518
21522
|
if (files.objects.length) accept(files);
|
|
21519
21523
|
if (parent && (replayed.size || linked.size)) {
|
|
21520
21524
|
for (const ref of replayed.keys())
|
|
21521
|
-
for (const
|
|
21522
|
-
if (analyzedFiles.has(
|
|
21525
|
+
for (const path14 of contextFiles(parent.contexts.get(ref)?.context ?? invalidParent()))
|
|
21526
|
+
if (analyzedFiles.has(path14) || [...sharing.get(path14) ?? []].some((other) => !replayed.has(other)))
|
|
21523
21527
|
throw new MapReplayConflict();
|
|
21524
|
-
for (const paths of replayed.values()) for (const
|
|
21525
|
-
for (const
|
|
21526
|
-
if (analyzedFiles.has(
|
|
21528
|
+
for (const paths of replayed.values()) for (const path14 of paths) linked.add(path14);
|
|
21529
|
+
for (const path14 of linked)
|
|
21530
|
+
if (analyzedFiles.has(path14) || stagedPaths.has(path14)) throw new MapReplayConflict();
|
|
21527
21531
|
parent.link([...linked]);
|
|
21528
21532
|
}
|
|
21529
21533
|
result.parsedFiles = [...parsed].sort();
|
|
@@ -21732,7 +21736,7 @@ var CodeIndex = class {
|
|
|
21732
21736
|
throw new ProjectEvidenceError("PROJECT_EVIDENCE_STORE_CONFLICT", false);
|
|
21733
21737
|
return existing;
|
|
21734
21738
|
}
|
|
21735
|
-
await this.buildMap(result, source, combined);
|
|
21739
|
+
await this.buildMap(result, source, combined, options.startFromProjectRef);
|
|
21736
21740
|
return this.store.requireVersion(result.version.version);
|
|
21737
21741
|
}).catch((error51) => {
|
|
21738
21742
|
if (error51 instanceof GitCommandStopUnconfirmedError || error51 instanceof ProjectMapStopUnconfirmedError)
|
|
@@ -21744,7 +21748,7 @@ var CodeIndex = class {
|
|
|
21744
21748
|
this.captures.set(controller, completion);
|
|
21745
21749
|
return completion;
|
|
21746
21750
|
}
|
|
21747
|
-
async buildMap(result, source, signal) {
|
|
21751
|
+
async buildMap(result, source, signal, startFromProjectRef) {
|
|
21748
21752
|
this.assertAccepting(signal);
|
|
21749
21753
|
const ref = result.version.version;
|
|
21750
21754
|
const existing = this.mapBuilds.get(ref);
|
|
@@ -21755,7 +21759,7 @@ var CodeIndex = class {
|
|
|
21755
21759
|
if (!(error51 instanceof ProjectEvidenceError) || error51.code !== "PROJECT_READ_CANCELLED")
|
|
21756
21760
|
throw error51;
|
|
21757
21761
|
}
|
|
21758
|
-
return this.buildMap(result, source, signal);
|
|
21762
|
+
return this.buildMap(result, source, signal, startFromProjectRef);
|
|
21759
21763
|
}
|
|
21760
21764
|
if (existing) return this.awaitRebuild(existing, signal);
|
|
21761
21765
|
if (this.store.getVersion(ref)) return;
|
|
@@ -21794,7 +21798,7 @@ var CodeIndex = class {
|
|
|
21794
21798
|
this.store.discardMapStage(stage);
|
|
21795
21799
|
}
|
|
21796
21800
|
};
|
|
21797
|
-
const completion = run2(this.mapParent(result)).finally(() => {
|
|
21801
|
+
const completion = run2(this.mapParent(result, startFromProjectRef)).finally(() => {
|
|
21798
21802
|
if (this.mapBuilds.get(ref)?.completion === completion) this.mapBuilds.delete(ref);
|
|
21799
21803
|
});
|
|
21800
21804
|
const build = { controller, completion, waiters: /* @__PURE__ */ new Set() };
|
|
@@ -21802,19 +21806,24 @@ var CodeIndex = class {
|
|
|
21802
21806
|
return this.awaitRebuild(build, signal);
|
|
21803
21807
|
}
|
|
21804
21808
|
/**
|
|
21805
|
-
* The recent map of the same project scope and analyzer
|
|
21806
|
-
* revision's: its contexts whose inputs did not change are
|
|
21809
|
+
* The recent map of the same project scope and analyzer, or of the project to start from, whose
|
|
21810
|
+
* files differ least from the new revision's: its contexts whose inputs did not change are
|
|
21811
|
+
* replayed rather than analyzed.
|
|
21807
21812
|
*/
|
|
21808
|
-
mapParent(result) {
|
|
21813
|
+
mapParent(result, startFromProjectRef) {
|
|
21809
21814
|
const digests = new Map(result.entries.map((entry) => [entry.path, entry.contentDigest]));
|
|
21810
21815
|
let best;
|
|
21811
|
-
for (const candidate of this.store.mapParentCandidates(
|
|
21816
|
+
for (const candidate of this.store.mapParentCandidates(
|
|
21817
|
+
result.version,
|
|
21818
|
+
8,
|
|
21819
|
+
startFromProjectRef
|
|
21820
|
+
)) {
|
|
21812
21821
|
const entries2 = /* @__PURE__ */ new Map();
|
|
21813
21822
|
for (const entry of this.store.listEntries(candidate))
|
|
21814
21823
|
if (entry.contentDigest) entries2.set(entry.path, entry.contentDigest);
|
|
21815
21824
|
let changed = 0;
|
|
21816
|
-
for (const [
|
|
21817
|
-
for (const
|
|
21825
|
+
for (const [path14, digest] of digests) if (entries2.get(path14) !== digest) changed++;
|
|
21826
|
+
for (const path14 of entries2.keys()) if (!digests.has(path14)) changed++;
|
|
21818
21827
|
if (!best || changed < best.changed) best = { version: candidate, entries: entries2, changed };
|
|
21819
21828
|
}
|
|
21820
21829
|
if (!best) return void 0;
|
|
@@ -21989,16 +21998,16 @@ var LITERAL = /(["'`])((?:\\.|(?!\1)[^\\])*)\1/gu;
|
|
|
21989
21998
|
var MOUNTING = /(?:\b(?:prefix|root_path|base_path|basePath|baseURL|baseUrl)\s*[=:]|\b(?:Group|Route|Mount|mount|use|include_router|PathPrefix|StripPrefix)\s*\()\s*$/u;
|
|
21990
21999
|
var LIMIT = Object.freeze({ routes: 40, clients: 5 });
|
|
21991
22000
|
var ROUTE = /^(?:[A-Z]+(?:\|[A-Z]+)* +)?\/\S*$/u;
|
|
21992
|
-
var segments = (
|
|
22001
|
+
var segments = (path14) => path14.split("/").filter(Boolean).map((text) => ({ text, param: PARAM.test(text) || /[{}$<>%]/u.test(text) }));
|
|
21993
22002
|
var routeSegments = (label) => segments(label.slice(label.indexOf("/")));
|
|
21994
22003
|
function requestedPath(literal3, joined) {
|
|
21995
22004
|
const match = /^(?:https?:\/\/[^/\s]+|(?:\$\{[^}]*\})+|@\{|redirect:|forward:)?(\/[^\s?#()"'`,;|]*)/u.exec(
|
|
21996
22005
|
literal3
|
|
21997
22006
|
) ?? void 0;
|
|
21998
|
-
const
|
|
21999
|
-
if (!
|
|
22000
|
-
const parts = segments(
|
|
22001
|
-
if (joined &&
|
|
22007
|
+
const path14 = match?.[1];
|
|
22008
|
+
if (!path14 || path14.startsWith("//") || path14.length < 3) return void 0;
|
|
22009
|
+
const parts = segments(path14);
|
|
22010
|
+
if (joined && path14.endsWith("/")) parts.push({ text: "*", param: true });
|
|
22002
22011
|
return parts;
|
|
22003
22012
|
}
|
|
22004
22013
|
var same = (route, requested) => route.param || !requested.param && route.text === requested.text;
|
|
@@ -22303,8 +22312,8 @@ async function readMapChanges(project, base, signal) {
|
|
|
22303
22312
|
baseText: (await git.run(["show", `${commit}:${file2.basePath}`], gitOptions(project, signal))).stdout.toString("utf8")
|
|
22304
22313
|
};
|
|
22305
22314
|
const untracked = (await git.run(["ls-files", "--others", "--exclude-standard", "-z"], gitOptions(project, signal))).stdout.toString("utf8").split("\0").filter(Boolean);
|
|
22306
|
-
for (const
|
|
22307
|
-
files.push({ path:
|
|
22315
|
+
for (const path14 of untracked)
|
|
22316
|
+
files.push({ path: path14, status: "ADDED", lines: [EVERYTHING], baseLines: [], binary: false });
|
|
22308
22317
|
const stranded = await strandedNames(
|
|
22309
22318
|
project,
|
|
22310
22319
|
diff,
|
|
@@ -22382,7 +22391,7 @@ var NON_CODE = [
|
|
|
22382
22391
|
[/(?:^|\/)\.env[^/]*$|\.(?:ya?ml|toml|ini|properties|conf|cfg)$/iu, "configuration"],
|
|
22383
22392
|
[/\.(?:html?|jinja2?|j2|hbs|ejs|tmpl|tpl|gohtml|vue|svelte)$/iu, "template"]
|
|
22384
22393
|
];
|
|
22385
|
-
var nonCodeKind = (
|
|
22394
|
+
var nonCodeKind = (path14) => NON_CODE.find(([pattern]) => pattern.test(path14))?.[1];
|
|
22386
22395
|
var LIMITS = Object.freeze({ depth: 8, declarations: 800, changed: 200, chain: 3, byName: 40 });
|
|
22387
22396
|
var CALLER_KINDS = /* @__PURE__ */ new Set(["CALLS", "REFERENCES"]);
|
|
22388
22397
|
var IMPORT_KINDS2 = /* @__PURE__ */ new Set(["IMPORTS", "TEST_IMPORTS"]);
|
|
@@ -22577,12 +22586,12 @@ var Tracer = class {
|
|
|
22577
22586
|
this.areas.set(area, known);
|
|
22578
22587
|
}
|
|
22579
22588
|
/** A related test file; the closest relation (lowest rank) explains it. */
|
|
22580
|
-
test(
|
|
22581
|
-
if (!mapRunnableTest(
|
|
22582
|
-
const known = this.tests.get(
|
|
22589
|
+
test(path14, name, why, rank2) {
|
|
22590
|
+
if (!mapRunnableTest(path14)) return;
|
|
22591
|
+
const known = this.tests.get(path14) ?? { names: /* @__PURE__ */ new Set(), why, rank: rank2 };
|
|
22583
22592
|
if (rank2 < known.rank) Object.assign(known, { why, rank: rank2 });
|
|
22584
22593
|
if (name && !name.startsWith("<")) known.names.add(name);
|
|
22585
|
-
this.tests.set(
|
|
22594
|
+
this.tests.set(path14, known);
|
|
22586
22595
|
}
|
|
22587
22596
|
};
|
|
22588
22597
|
var mapRunnableTest = (file2) => /_test\.(?:go|py)$|(?:^|\/)test_[^/]*\.py$|\.(?:test|spec)\.[cm]?[jt]sx?$|(?:Test|Tests|IT)\.(?:java|kt)$/u.test(
|
|
@@ -22595,7 +22604,7 @@ function mapChangeImpact(store, working, base, changes, project) {
|
|
|
22595
22604
|
const changed = [];
|
|
22596
22605
|
const unclear = [];
|
|
22597
22606
|
const removed = [];
|
|
22598
|
-
const declarations = (g,
|
|
22607
|
+
const declarations = (g, path14) => g.objectsAt(path14).filter((object2) => !mapIsModule(object2) && g.isAddressable(object2));
|
|
22599
22608
|
let changedCount = 0;
|
|
22600
22609
|
const starts = [];
|
|
22601
22610
|
for (const file2 of changes.files) {
|
|
@@ -22692,18 +22701,18 @@ function mapChangeImpact(store, working, base, changes, project) {
|
|
|
22692
22701
|
beforeTracer.trace(gone);
|
|
22693
22702
|
for (const entry of beforeTracer.entries.values())
|
|
22694
22703
|
if (!tracer.entries.has(entry.label)) tracer.entries.set(entry.label, entry);
|
|
22695
|
-
for (const [
|
|
22696
|
-
const known = tracer.tests.get(
|
|
22704
|
+
for (const [path14, test] of beforeTracer.tests) {
|
|
22705
|
+
const known = tracer.tests.get(path14);
|
|
22697
22706
|
if (known) for (const name of test.names) known.names.add(name);
|
|
22698
|
-
else tracer.tests.set(
|
|
22707
|
+
else tracer.tests.set(path14, test);
|
|
22699
22708
|
}
|
|
22700
22709
|
for (const [area, known] of beforeTracer.areas) {
|
|
22701
22710
|
const now = tracer.areas.get(area);
|
|
22702
22711
|
if (!now) tracer.areas.set(area, known);
|
|
22703
22712
|
else {
|
|
22704
22713
|
for (const name of known.through) now.through.add(name);
|
|
22705
|
-
for (const [
|
|
22706
|
-
now.tests.set(
|
|
22714
|
+
for (const [path14, names] of known.tests)
|
|
22715
|
+
now.tests.set(path14, /* @__PURE__ */ new Set([...now.tests.get(path14) ?? [], ...names]));
|
|
22707
22716
|
}
|
|
22708
22717
|
}
|
|
22709
22718
|
unclear.push(...beforeTracer.unclear.filter((line) => !line.includes("has no callers")));
|
|
@@ -22717,8 +22726,8 @@ function mapChangeImpact(store, working, base, changes, project) {
|
|
|
22717
22726
|
entries: [...tracer.entries.values()].sort(
|
|
22718
22727
|
(left, right) => Number(right.certain) - Number(left.certain) || Number(right.route) - Number(left.route) || (left.label < right.label ? -1 : left.label > right.label ? 1 : 0)
|
|
22719
22728
|
),
|
|
22720
|
-
tests: [...tracer.tests].map(([
|
|
22721
|
-
path:
|
|
22729
|
+
tests: [...tracer.tests].map(([path14, test]) => ({
|
|
22730
|
+
path: path14,
|
|
22722
22731
|
names: [...test.names].sort(),
|
|
22723
22732
|
why: test.why,
|
|
22724
22733
|
rank: test.rank
|
|
@@ -22728,7 +22737,7 @@ function mapChangeImpact(store, working, base, changes, project) {
|
|
|
22728
22737
|
areas: [...tracer.areas].map(([area, known]) => ({
|
|
22729
22738
|
area,
|
|
22730
22739
|
through: [...known.through].sort(),
|
|
22731
|
-
tests: [...known.tests].map(([
|
|
22740
|
+
tests: [...known.tests].map(([path14, names]) => ({ path: path14, names: [...names].sort() })).sort((left, right) => right.names.length - left.names.length)
|
|
22732
22741
|
})).sort((left, right) => right.tests.length - left.tests.length),
|
|
22733
22742
|
unclear: [.../* @__PURE__ */ new Set([...unclear, ...tracer.unclear])],
|
|
22734
22743
|
removedRoutes,
|
|
@@ -22846,9 +22855,9 @@ function routeTests(project, store, version2, entries, tracer) {
|
|
|
22846
22855
|
}
|
|
22847
22856
|
}
|
|
22848
22857
|
}
|
|
22849
|
-
function sameDirectoryTests(store, version2,
|
|
22850
|
-
const slash =
|
|
22851
|
-
const directory = slash < 0 ? "" :
|
|
22858
|
+
function sameDirectoryTests(store, version2, path14, tracer) {
|
|
22859
|
+
const slash = path14.lastIndexOf("/");
|
|
22860
|
+
const directory = slash < 0 ? "" : path14.slice(0, slash + 1);
|
|
22852
22861
|
for (const row of store.database.prepare(
|
|
22853
22862
|
"SELECT DISTINCT path FROM project_map_objects WHERE version_ref = ? AND path LIKE ? ESCAPE '\\'"
|
|
22854
22863
|
).all(version2, `${directory.replace(/[\\%_]/gu, (c) => `\\${c}`)}%`)) {
|
|
@@ -22877,9 +22886,9 @@ var LIST = Object.freeze({
|
|
|
22877
22886
|
areaNames: 3,
|
|
22878
22887
|
through: 2
|
|
22879
22888
|
});
|
|
22880
|
-
function routesIn(graph,
|
|
22889
|
+
function routesIn(graph, path14) {
|
|
22881
22890
|
const routes = /* @__PURE__ */ new Set();
|
|
22882
|
-
for (const relation of graph.relationsFrom(graph.objectsAt(
|
|
22891
|
+
for (const relation of graph.relationsFrom(graph.objectsAt(path14).map((object2) => object2.id))) {
|
|
22883
22892
|
const route = relation.kind === "DECORATED_BY" ? relation.route ?? relation.argument : relation.argument;
|
|
22884
22893
|
if (route && ROUTE2.test(route)) routes.add(route);
|
|
22885
22894
|
}
|
|
@@ -23091,12 +23100,12 @@ var LayerMap = class _LayerMap {
|
|
|
23091
23100
|
refreshing;
|
|
23092
23101
|
static async open(options) {
|
|
23093
23102
|
const project = await realpath2(options.project);
|
|
23094
|
-
const
|
|
23095
|
-
if (!
|
|
23103
|
+
const stat3 = await lstat2(project, { bigint: true });
|
|
23104
|
+
if (!stat3.isDirectory()) throw new ProjectEvidenceError("PROJECT_PATH_INVALID", false);
|
|
23096
23105
|
const source = {
|
|
23097
23106
|
kind: "WORKTREE",
|
|
23098
23107
|
projectRef: `layermap:${createHash4("sha256").update(project).digest("hex").slice(0, 24)}`,
|
|
23099
|
-
directory: { canonicalPath: project, device: String(
|
|
23108
|
+
directory: { canonicalPath: project, device: String(stat3.dev), inode: String(stat3.ino) }
|
|
23100
23109
|
};
|
|
23101
23110
|
const store = new CodeIndexStore(
|
|
23102
23111
|
openMapDatabase(
|
|
@@ -23355,6 +23364,11 @@ async function pruneCache(cache, project, now = Date.now()) {
|
|
|
23355
23364
|
import { createInterface } from "node:readline";
|
|
23356
23365
|
import { setTimeout as delay } from "node:timers/promises";
|
|
23357
23366
|
|
|
23367
|
+
// src/agent/projects.ts
|
|
23368
|
+
import { existsSync as existsSync6 } from "node:fs";
|
|
23369
|
+
import { readdir as readdir2, realpath as realpath3, stat as stat2 } from "node:fs/promises";
|
|
23370
|
+
import path12 from "node:path";
|
|
23371
|
+
|
|
23358
23372
|
// src/tools.ts
|
|
23359
23373
|
var AGENT_MAP_TOOL_HOST = Object.freeze({
|
|
23360
23374
|
readResult: "read its line range in the file",
|
|
@@ -23377,7 +23391,7 @@ var MAP_TOOL_NAMES = Object.freeze({
|
|
|
23377
23391
|
references: "project_find_references",
|
|
23378
23392
|
check: "project_check_changes"
|
|
23379
23393
|
});
|
|
23380
|
-
var mapDirectoryPath = (
|
|
23394
|
+
var mapDirectoryPath = (path14) => path14.length > 1 && path14.endsWith("/") && !path14.endsWith("//") ? path14.slice(0, -1) : path14;
|
|
23381
23395
|
var ProjectMapSearchInputSchema = external_exports.object({
|
|
23382
23396
|
path: external_exports.string().default("."),
|
|
23383
23397
|
query: external_exports.string().min(1).max(256),
|
|
@@ -23405,6 +23419,9 @@ var ProjectMapExploreInputSchema = external_exports.object({
|
|
|
23405
23419
|
var ProjectMapCheckInputSchema = external_exports.object({
|
|
23406
23420
|
base: external_exports.string().min(1).max(200).default("HEAD").describe(
|
|
23407
23421
|
"Commit, branch or tag to compare the working tree with (HEAD, so the uncommitted changes, by default; main for a whole branch)."
|
|
23422
|
+
),
|
|
23423
|
+
path: external_exports.string().optional().describe(
|
|
23424
|
+
"A file or directory in the repository to check, when the session works in more than one; the check covers that repository's whole working tree."
|
|
23408
23425
|
)
|
|
23409
23426
|
}).strip();
|
|
23410
23427
|
var locatorSchema = MapObjectLocatorSchema.describe(
|
|
@@ -23436,6 +23453,60 @@ var mapToolDescriptions = (host) => {
|
|
|
23436
23453
|
});
|
|
23437
23454
|
};
|
|
23438
23455
|
|
|
23456
|
+
// src/agent/projects.ts
|
|
23457
|
+
var escapes = (relative) => {
|
|
23458
|
+
const normal = path12.normalize(relative);
|
|
23459
|
+
return normal === ".." || normal.startsWith(`..${path12.sep}`);
|
|
23460
|
+
};
|
|
23461
|
+
async function locate(start, given) {
|
|
23462
|
+
if (start.git && !path12.isAbsolute(given) && !escapes(given))
|
|
23463
|
+
return { project: start.directory, path: given };
|
|
23464
|
+
const absolute = path12.resolve(start.directory, given);
|
|
23465
|
+
let directory = absolute;
|
|
23466
|
+
while (!(await stat2(directory).catch(() => void 0))?.isDirectory()) {
|
|
23467
|
+
if (path12.dirname(directory) === directory) return void 0;
|
|
23468
|
+
directory = path12.dirname(directory);
|
|
23469
|
+
}
|
|
23470
|
+
const real = path12.join(await realpath3(directory), path12.relative(directory, absolute));
|
|
23471
|
+
const { directory: project, git: git2 } = await projectDirectory(directory);
|
|
23472
|
+
if (!git2) return void 0;
|
|
23473
|
+
const relative = path12.relative(project, real);
|
|
23474
|
+
if (escapes(relative)) return void 0;
|
|
23475
|
+
return { project, path: relative ? relative.split(path12.sep).join("/") : "." };
|
|
23476
|
+
}
|
|
23477
|
+
async function repositoriesIn(directory) {
|
|
23478
|
+
const entries = await readdir2(directory, { withFileTypes: true }).catch(() => []);
|
|
23479
|
+
return entries.filter((entry) => entry.isDirectory() && existsSync6(path12.join(directory, entry.name, ".git"))).map((entry) => `${entry.name}/`).sort();
|
|
23480
|
+
}
|
|
23481
|
+
async function routeMapCall(start, { name, args }) {
|
|
23482
|
+
const holder = ["symbol", "locator"].find(
|
|
23483
|
+
(key) => name === MAP_TOOL_NAMES.references && args[key] !== void 0
|
|
23484
|
+
);
|
|
23485
|
+
const value = holder ? args[holder].path : args.path;
|
|
23486
|
+
const named = value || ".";
|
|
23487
|
+
const located = await locate(start, named);
|
|
23488
|
+
if (!located) {
|
|
23489
|
+
const repositories = start.git ? [] : await repositoriesIn(start.directory);
|
|
23490
|
+
const such = repositories.length ? `, such as ${repositories.join(", ")}` : "";
|
|
23491
|
+
return named === "." ? `LAYERMAP_NOT_A_GIT_REPOSITORY: This session started in ${start.directory}, which is not in a Git repository. Name a file or directory in one, relative to that folder or absolute${such}.` : `LAYERMAP_NOT_A_GIT_REPOSITORY: ${path12.resolve(start.directory, named)} is not in a Git repository; LayerMap maps Git repositories${start.git ? "" : `. Name a file or directory in one, relative to ${start.directory} or absolute${such}`}.`;
|
|
23492
|
+
}
|
|
23493
|
+
if (!holder)
|
|
23494
|
+
return {
|
|
23495
|
+
project: located.project,
|
|
23496
|
+
args: value === void 0 ? args : { ...args, path: located.path }
|
|
23497
|
+
};
|
|
23498
|
+
const routed = {
|
|
23499
|
+
...args,
|
|
23500
|
+
[holder]: { ...args[holder], path: located.path }
|
|
23501
|
+
};
|
|
23502
|
+
const filter = args.path;
|
|
23503
|
+
if (filter === ".") return { project: located.project, args: routed };
|
|
23504
|
+
const within2 = await locate(start, filter);
|
|
23505
|
+
if (within2?.project !== located.project)
|
|
23506
|
+
return `PROJECT_PATH_INVALID: path ${filter} is not in ${located.project}, the repository of the declaration.`;
|
|
23507
|
+
return { project: located.project, args: { ...routed, path: within2.path } };
|
|
23508
|
+
}
|
|
23509
|
+
|
|
23439
23510
|
// src/agent/tools.ts
|
|
23440
23511
|
var ReferencesInputSchema = mapReferencesInputSchema(AGENT_MAP_TOOL_HOST);
|
|
23441
23512
|
var descriptions = mapToolDescriptions(AGENT_MAP_TOOL_HOST);
|
|
@@ -23482,10 +23553,10 @@ var HINTS = {
|
|
|
23482
23553
|
PROJECT_MAP_REFERENCE_TARGET_UNAVAILABLE: "References are not available for this declaration; use its callers in project_explore_map.",
|
|
23483
23554
|
LAYERMAP_BASE_NOT_FOUND: "No such commit, branch or tag. Leave base out to compare with HEAD, or name an existing one such as main.",
|
|
23484
23555
|
LAYERMAP_BASE_INVALID: "base names a commit, branch or tag, such as HEAD or main.",
|
|
23485
|
-
LAYERMAP_NOT_A_GIT_REPOSITORY: "LayerMap maps Git repositories
|
|
23556
|
+
LAYERMAP_NOT_A_GIT_REPOSITORY: "LayerMap maps Git repositories. Run it in one, or name one with --project."
|
|
23486
23557
|
};
|
|
23487
23558
|
var describeMapError = (error51) => error51 instanceof ProjectEvidenceError ? `${error51.code}${HINTS[error51.code] ? `: ${HINTS[error51.code]}` : ""}` : void 0;
|
|
23488
|
-
|
|
23559
|
+
function parseMapToolCall(name, args) {
|
|
23489
23560
|
const tool = agentMapTools.find((candidate) => candidate.name === name);
|
|
23490
23561
|
if (!tool) return { text: `Unknown tool ${name}.`, isError: true };
|
|
23491
23562
|
const parsed = tool.schema.safeParse(args ?? {});
|
|
@@ -23494,9 +23565,12 @@ async function runMapTool(map2, name, args, signal) {
|
|
|
23494
23565
|
text: `Invalid arguments: ${parsed.error.issues.map((issue2) => `${issue2.path.join(".") || "(arguments)"}: ${issue2.message}`).join("; ")}`,
|
|
23495
23566
|
isError: true
|
|
23496
23567
|
};
|
|
23568
|
+
return { name, args: parsed.data };
|
|
23569
|
+
}
|
|
23570
|
+
async function runMapTool(map2, { name, args }, signal) {
|
|
23497
23571
|
try {
|
|
23498
23572
|
if (name === MAP_TOOL_NAMES.explore) {
|
|
23499
|
-
const input2 =
|
|
23573
|
+
const input2 = args;
|
|
23500
23574
|
const declaration = input2.name !== void 0 || input2.line !== void 0;
|
|
23501
23575
|
const page = await map2.explore(
|
|
23502
23576
|
{
|
|
@@ -23513,15 +23587,15 @@ async function runMapTool(map2, name, args, signal) {
|
|
|
23513
23587
|
return { text: page.text + more(page.nextOffset), isError: false };
|
|
23514
23588
|
}
|
|
23515
23589
|
if (name === MAP_TOOL_NAMES.check) {
|
|
23516
|
-
const input2 =
|
|
23517
|
-
return { text: (await map2.checkChanges(input2, signal)).text, isError: false };
|
|
23590
|
+
const input2 = args;
|
|
23591
|
+
return { text: (await map2.checkChanges({ base: input2.base }, signal)).text, isError: false };
|
|
23518
23592
|
}
|
|
23519
23593
|
if (name === MAP_TOOL_NAMES.search) {
|
|
23520
|
-
const input2 =
|
|
23594
|
+
const input2 = args;
|
|
23521
23595
|
const page = await map2.search({ ...input2, path: mapDirectoryPath(input2.path) }, signal);
|
|
23522
23596
|
return { text: page.text + more(page.nextOffset), isError: false };
|
|
23523
23597
|
}
|
|
23524
|
-
const input =
|
|
23598
|
+
const input = args;
|
|
23525
23599
|
return { text: JSON.stringify(await map2.references(input, signal)), isError: false };
|
|
23526
23600
|
} catch (error51) {
|
|
23527
23601
|
const text = describeMapError(error51);
|
|
@@ -23529,7 +23603,7 @@ async function runMapTool(map2, name, args, signal) {
|
|
|
23529
23603
|
throw error51;
|
|
23530
23604
|
}
|
|
23531
23605
|
}
|
|
23532
|
-
var AGENT_MAP_INSTRUCTIONS = `Use the LayerMap tools instead of grep whenever a task needs to know what calls something, what a change could affect beyond the code at hand, where something is used, or how the code is organized; a change confined to code you have read does not need them: project_explore_map on a declaration with direction INCOMING and depth up to 8 traces its callers up to the entry points (HTTP routes, handlers, jobs, commands) in one call, which grep can only approximate one name at a time. LayerMap is a static, layered map of this repository for TypeScript/JavaScript, Go, Python and Java: directories and modules, each file's declarations, and each declaration's callers and callees up to 8 hops. path "." shows what exists. Continue from any NOT EXPANDED declarations a view names, then confirm entry points in source. When the edits are done, call project_check_changes once before reporting the work done, not after every edit: it lists the entry points and existing tests the changes reach, and the existing tests the diff rewrote. The map is static: dynamic dispatch, framework wiring and unresolved targets need source reading, and a missing relationship does not prove absence. The first call on a project builds its map, which can take minutes on a large repository; later calls update only what changed.`;
|
|
23606
|
+
var AGENT_MAP_INSTRUCTIONS = `Use the LayerMap tools instead of grep whenever a task needs to know what calls something, what a change could affect beyond the code at hand, where something is used, or how the code is organized; a change confined to code you have read does not need them: project_explore_map on a declaration with direction INCOMING and depth up to 8 traces its callers up to the entry points (HTTP routes, handlers, jobs, commands) in one call, which grep can only approximate one name at a time. LayerMap is a static, layered map of this repository for TypeScript/JavaScript, Go, Python and Java: directories and modules, each file's declarations, and each declaration's callers and callees up to 8 hops. path "." shows what exists. Continue from any NOT EXPANDED declarations a view names, then confirm entry points in source. When the edits are done, call project_check_changes once before reporting the work done, not after every edit: it lists the entry points and existing tests the changes reach, and the existing tests the diff rewrote. The map is static: dynamic dispatch, framework wiring and unresolved targets need source reading, and a missing relationship does not prove absence. The first call on a project builds its map, which can take minutes on a large repository; later calls update only what changed. Each result names the Git repository it maps, and its paths are relative to that repository's root. The paths you give are relative to the repository the session started in, or to the starting folder when that is not a repository (such as a folder holding several); for a file in another repository, such as after changing directory, give its absolute path. Give project_check_changes a path in the repository to check when the session works in more than one.`;
|
|
23533
23607
|
var AGENT_MAP_NOTE = "The layermap MCP server is available here. When a task needs to know what calls a function, what a change could affect beyond the code you are editing, or where code is used, use its project_explore_map tool (direction INCOMING, depth up to 8) instead of grep, then confirm in source; a change confined to code you have read does not need it. When the edits are done, call its project_check_changes tool once before reporting the work done.";
|
|
23534
23608
|
|
|
23535
23609
|
// src/agent/mcp.ts
|
|
@@ -23540,55 +23614,67 @@ function serveMcp(options) {
|
|
|
23540
23614
|
const send = (message) => output.write(`${JSON.stringify({ jsonrpc: "2.0", ...message })}
|
|
23541
23615
|
`);
|
|
23542
23616
|
const calls = /* @__PURE__ */ new Map();
|
|
23543
|
-
|
|
23544
|
-
const map2 = () => {
|
|
23545
|
-
opened ??= options.open();
|
|
23546
|
-
return opened;
|
|
23547
|
-
};
|
|
23617
|
+
const maps = /* @__PURE__ */ new Map();
|
|
23548
23618
|
const session = new AbortController();
|
|
23549
|
-
|
|
23550
|
-
|
|
23551
|
-
|
|
23552
|
-
|
|
23553
|
-
|
|
23619
|
+
const map2 = (project) => {
|
|
23620
|
+
let entry = maps.get(project);
|
|
23621
|
+
if (!entry) {
|
|
23622
|
+
const opened = options.open(project);
|
|
23623
|
+
const built = opened.then(async (layermap) => {
|
|
23624
|
+
await layermap.refresh(session.signal);
|
|
23625
|
+
void layermap.prepareBase(session.signal).catch(() => {
|
|
23626
|
+
});
|
|
23627
|
+
}).catch((error51) => {
|
|
23628
|
+
if (!session.signal.aborted) log2(`LayerMap could not build the map: ${String(error51)}`);
|
|
23554
23629
|
});
|
|
23555
|
-
|
|
23556
|
-
|
|
23557
|
-
}
|
|
23558
|
-
return
|
|
23630
|
+
entry = { opened, built };
|
|
23631
|
+
maps.set(project, entry);
|
|
23632
|
+
}
|
|
23633
|
+
return entry;
|
|
23559
23634
|
};
|
|
23560
23635
|
const call = async (id2, params) => {
|
|
23561
23636
|
const controller = new AbortController();
|
|
23562
23637
|
calls.set(id2, controller);
|
|
23638
|
+
const name = String(params.name);
|
|
23639
|
+
let project;
|
|
23640
|
+
const respond = (text, isError) => send({
|
|
23641
|
+
id: id2,
|
|
23642
|
+
result: {
|
|
23643
|
+
content: [
|
|
23644
|
+
{
|
|
23645
|
+
type: "text",
|
|
23646
|
+
text: project ? `Project ${project} (paths are relative to it)
|
|
23647
|
+
|
|
23648
|
+
${text}` : text
|
|
23649
|
+
}
|
|
23650
|
+
],
|
|
23651
|
+
isError
|
|
23652
|
+
}
|
|
23653
|
+
});
|
|
23563
23654
|
try {
|
|
23655
|
+
const parsed = parseMapToolCall(name, params.arguments);
|
|
23656
|
+
if ("text" in parsed) return respond(parsed.text, parsed.isError);
|
|
23657
|
+
const routed = await routeMapCall(options.start, parsed);
|
|
23658
|
+
if (typeof routed === "string") return respond(routed, true);
|
|
23659
|
+
project = routed.project;
|
|
23660
|
+
const { opened, built } = map2(project);
|
|
23564
23661
|
const timer = new AbortController();
|
|
23565
|
-
const
|
|
23566
|
-
|
|
23662
|
+
const ready = await Promise.race([
|
|
23663
|
+
built.then(() => true),
|
|
23567
23664
|
delay(options.buildWaitMs ?? 4e4, false, {
|
|
23568
23665
|
signal: AbortSignal.any([timer.signal, controller.signal])
|
|
23569
23666
|
}).catch(() => false)
|
|
23570
23667
|
]);
|
|
23571
23668
|
timer.abort();
|
|
23572
23669
|
if (controller.signal.aborted) return;
|
|
23573
|
-
const result =
|
|
23574
|
-
text: `LayerMap is still building this project's map (a first build can take minutes on a large repository). Call ${
|
|
23670
|
+
const result = ready ? await runMapTool(await opened, { name, args: routed.args }, controller.signal) : {
|
|
23671
|
+
text: `LayerMap is still building this project's map (a first build can take minutes on a large repository). Call ${name} again shortly, or read source meanwhile.`,
|
|
23575
23672
|
isError: false
|
|
23576
23673
|
};
|
|
23577
|
-
|
|
23578
|
-
id: id2,
|
|
23579
|
-
result: { content: [{ type: "text", text: result.text }], isError: result.isError }
|
|
23580
|
-
});
|
|
23674
|
+
respond(result.text, result.isError);
|
|
23581
23675
|
} catch (error51) {
|
|
23582
23676
|
if (controller.signal.aborted) return;
|
|
23583
|
-
|
|
23584
|
-
id: id2,
|
|
23585
|
-
result: {
|
|
23586
|
-
content: [
|
|
23587
|
-
{ type: "text", text: describeMapError(error51) ?? `LayerMap failed: ${String(error51)}` }
|
|
23588
|
-
],
|
|
23589
|
-
isError: true
|
|
23590
|
-
}
|
|
23591
|
-
});
|
|
23677
|
+
respond(describeMapError(error51) ?? `LayerMap failed: ${String(error51)}`, true);
|
|
23592
23678
|
} finally {
|
|
23593
23679
|
calls.delete(id2);
|
|
23594
23680
|
}
|
|
@@ -23597,7 +23683,7 @@ function serveMcp(options) {
|
|
|
23597
23683
|
const { id: id2, method, params = {} } = message;
|
|
23598
23684
|
if (method === void 0) return;
|
|
23599
23685
|
if (id2 === void 0 || id2 === null) {
|
|
23600
|
-
if (method === "notifications/initialized")
|
|
23686
|
+
if (method === "notifications/initialized" && options.start.git) map2(options.start.directory);
|
|
23601
23687
|
if (method === "notifications/cancelled")
|
|
23602
23688
|
calls.get(params.requestId)?.abort();
|
|
23603
23689
|
return;
|
|
@@ -23661,7 +23747,8 @@ function serveMcp(options) {
|
|
|
23661
23747
|
lines.on("close", async () => {
|
|
23662
23748
|
session.abort();
|
|
23663
23749
|
for (const controller of calls.values()) controller.abort();
|
|
23664
|
-
|
|
23750
|
+
for (const { opened } of maps.values())
|
|
23751
|
+
await (await opened.catch(() => void 0))?.close().catch(() => void 0);
|
|
23665
23752
|
resolve();
|
|
23666
23753
|
});
|
|
23667
23754
|
});
|
|
@@ -23669,25 +23756,25 @@ function serveMcp(options) {
|
|
|
23669
23756
|
|
|
23670
23757
|
// src/agent/setup.ts
|
|
23671
23758
|
import { execFile as execFile2 } from "node:child_process";
|
|
23672
|
-
import { existsSync as
|
|
23759
|
+
import { existsSync as existsSync7 } from "node:fs";
|
|
23673
23760
|
import { mkdir as mkdir2, readFile as readFile2, rm as rm2, writeFile as writeFile2 } from "node:fs/promises";
|
|
23674
23761
|
import { homedir as homedir2 } from "node:os";
|
|
23675
|
-
import
|
|
23762
|
+
import path13 from "node:path";
|
|
23676
23763
|
var SERVER = "layermap";
|
|
23677
23764
|
var SETUP_RULE = `mcp__${SERVER}`;
|
|
23678
23765
|
var PLUGIN_RULE = `mcp__plugin_${SERVER}_${SERVER}`;
|
|
23679
23766
|
var BEGIN = "<!-- layermap:begin -->";
|
|
23680
23767
|
var END = "<!-- layermap:end -->";
|
|
23768
|
+
var npxServerArgs = (version2) => [
|
|
23769
|
+
"--prefer-offline",
|
|
23770
|
+
"-y",
|
|
23771
|
+
`layermap@${version2}`,
|
|
23772
|
+
"mcp"
|
|
23773
|
+
];
|
|
23681
23774
|
var mcpLaunchCommand = (version2, platform = process.platform) => {
|
|
23682
|
-
const script =
|
|
23683
|
-
if (script.includes(`${
|
|
23684
|
-
return [
|
|
23685
|
-
...platform === "win32" ? ["cmd", "/c"] : [],
|
|
23686
|
-
"npx",
|
|
23687
|
-
"-y",
|
|
23688
|
-
`layermap@${version2}`,
|
|
23689
|
-
"mcp"
|
|
23690
|
-
];
|
|
23775
|
+
const script = path13.resolve(process.argv[1] ?? "");
|
|
23776
|
+
if (script.includes(`${path13.sep}_npx${path13.sep}`))
|
|
23777
|
+
return [...platform === "win32" ? ["cmd", "/c"] : [], "npx", ...npxServerArgs(version2)];
|
|
23691
23778
|
const execArgv = [];
|
|
23692
23779
|
for (let index = 0; index < process.execArgv.length; index++) {
|
|
23693
23780
|
const argument = process.execArgv[index];
|
|
@@ -23714,7 +23801,7 @@ var run = (command, args, env) => new Promise((resolve) => {
|
|
|
23714
23801
|
);
|
|
23715
23802
|
});
|
|
23716
23803
|
async function allowInClaudeSettings(file2, rule = SETUP_RULE) {
|
|
23717
|
-
const settings =
|
|
23804
|
+
const settings = existsSync7(file2) ? JSON.parse(await readFile2(file2, "utf8")) : {};
|
|
23718
23805
|
if (typeof settings !== "object" || settings === null || Array.isArray(settings))
|
|
23719
23806
|
throw new Error(`${file2} is not a settings object.`);
|
|
23720
23807
|
settings.permissions ??= {};
|
|
@@ -23723,7 +23810,7 @@ async function allowInClaudeSettings(file2, rule = SETUP_RULE) {
|
|
|
23723
23810
|
throw new Error(`${file2} has permissions.allow that is not a list.`);
|
|
23724
23811
|
if (settings.permissions.allow.includes(rule)) return false;
|
|
23725
23812
|
settings.permissions.allow.push(rule);
|
|
23726
|
-
await mkdir2(
|
|
23813
|
+
await mkdir2(path13.dirname(file2), { recursive: true });
|
|
23727
23814
|
await writeFile2(file2, `${JSON.stringify(settings, null, 2)}
|
|
23728
23815
|
`);
|
|
23729
23816
|
return true;
|
|
@@ -23751,17 +23838,17 @@ async function writeInstructionNote(file2, note = AGENT_MAP_NOTE) {
|
|
|
23751
23838
|
const block = `${BEGIN}
|
|
23752
23839
|
${note}
|
|
23753
23840
|
${END}`;
|
|
23754
|
-
const text =
|
|
23841
|
+
const text = existsSync7(file2) ? await readFile2(file2, "utf8") : "";
|
|
23755
23842
|
const start = text.indexOf(BEGIN);
|
|
23756
23843
|
const end = text.indexOf(END);
|
|
23757
23844
|
const next = start >= 0 && end > start ? `${text.slice(0, start)}${block}${text.slice(end + END.length)}` : `${text}${text && !text.endsWith("\n") ? "\n" : ""}${text ? "\n" : ""}${block}
|
|
23758
23845
|
`;
|
|
23759
23846
|
if (next === text) return;
|
|
23760
|
-
await mkdir2(
|
|
23847
|
+
await mkdir2(path13.dirname(file2), { recursive: true });
|
|
23761
23848
|
await writeFile2(file2, next);
|
|
23762
23849
|
}
|
|
23763
23850
|
async function removeInstructionNote(file2) {
|
|
23764
|
-
if (!
|
|
23851
|
+
if (!existsSync7(file2)) return;
|
|
23765
23852
|
const text = await readFile2(file2, "utf8");
|
|
23766
23853
|
const start = text.indexOf(BEGIN);
|
|
23767
23854
|
const end = text.indexOf(END);
|
|
@@ -23772,7 +23859,7 @@ async function removeInstructionNote(file2) {
|
|
|
23772
23859
|
else await writeFile2(file2, rest);
|
|
23773
23860
|
}
|
|
23774
23861
|
async function disallowInClaudeSettings(file2) {
|
|
23775
|
-
if (!
|
|
23862
|
+
if (!existsSync7(file2)) return;
|
|
23776
23863
|
const settings = JSON.parse(await readFile2(file2, "utf8"));
|
|
23777
23864
|
const allow = settings?.permissions?.allow;
|
|
23778
23865
|
const ours = (rule) => rule === SETUP_RULE || rule === PLUGIN_RULE;
|
|
@@ -23785,14 +23872,14 @@ async function disallowInClaudeSettings(file2) {
|
|
|
23785
23872
|
}
|
|
23786
23873
|
var YAML_BEGIN = "# layermap:begin";
|
|
23787
23874
|
var YAML_END = "# layermap:end";
|
|
23788
|
-
var nodeDirectory = (env = process.env) => (env.PATH ?? "").split(
|
|
23789
|
-
(directory) =>
|
|
23790
|
-
) ??
|
|
23875
|
+
var nodeDirectory = (env = process.env) => (env.PATH ?? "").split(path13.delimiter).find(
|
|
23876
|
+
(directory) => path13.isAbsolute(directory) && existsSync7(path13.join(directory, "node")) && existsSync7(path13.join(directory, "npx"))
|
|
23877
|
+
) ?? path13.dirname(process.execPath);
|
|
23791
23878
|
var dshPatchBlock = (command, env) => {
|
|
23792
23879
|
const node = nodeDirectory(env);
|
|
23793
|
-
const npx =
|
|
23794
|
-
const [program = "", ...args] = command[0] === "npx" &&
|
|
23795
|
-
const searchPath2 = `${JSON.stringify(`${node}${
|
|
23880
|
+
const npx = path13.join(node, "npx");
|
|
23881
|
+
const [program = "", ...args] = command[0] === "npx" && existsSync7(npx) ? [npx, ...command.slice(1)] : command;
|
|
23882
|
+
const searchPath2 = `${JSON.stringify(`${node}${path13.delimiter}`)} + process.env.PATH`;
|
|
23796
23883
|
return [
|
|
23797
23884
|
`${YAML_BEGIN} (written by \`layermap setup dsh\`; \`layermap remove dsh\` deletes it)`,
|
|
23798
23885
|
"- insert:",
|
|
@@ -23811,7 +23898,7 @@ var dshPatchBlock = (command, env) => {
|
|
|
23811
23898
|
].join("\n");
|
|
23812
23899
|
};
|
|
23813
23900
|
async function writeDshPatch(file2, block) {
|
|
23814
|
-
const text =
|
|
23901
|
+
const text = existsSync7(file2) ? await readFile2(file2, "utf8") : "";
|
|
23815
23902
|
const start = text.indexOf(YAML_BEGIN);
|
|
23816
23903
|
const end = text.indexOf(YAML_END);
|
|
23817
23904
|
let next;
|
|
@@ -23827,11 +23914,11 @@ async function writeDshPatch(file2, block) {
|
|
|
23827
23914
|
`;
|
|
23828
23915
|
}
|
|
23829
23916
|
if (next === text) return;
|
|
23830
|
-
await mkdir2(
|
|
23917
|
+
await mkdir2(path13.dirname(file2), { recursive: true });
|
|
23831
23918
|
await writeFile2(file2, next);
|
|
23832
23919
|
}
|
|
23833
23920
|
async function removeDshPatch(file2) {
|
|
23834
|
-
if (!
|
|
23921
|
+
if (!existsSync7(file2)) return;
|
|
23835
23922
|
const text = await readFile2(file2, "utf8");
|
|
23836
23923
|
const start = text.indexOf(YAML_BEGIN);
|
|
23837
23924
|
const end = text.indexOf(YAML_END);
|
|
@@ -23845,31 +23932,31 @@ async function removeDshPatch(file2) {
|
|
|
23845
23932
|
var agentFiles = (options) => {
|
|
23846
23933
|
const env = options.env ?? process.env;
|
|
23847
23934
|
if (options.agent === "dsh") {
|
|
23848
|
-
const home = env.DSH_HOME ||
|
|
23935
|
+
const home = env.DSH_HOME || path13.join(homedir2(), ".dsh");
|
|
23849
23936
|
return {
|
|
23850
|
-
settings:
|
|
23851
|
-
instructions:
|
|
23937
|
+
settings: path13.join(home, "cordis.patch.yml"),
|
|
23938
|
+
instructions: path13.join(home, "AGENTS.md")
|
|
23852
23939
|
};
|
|
23853
23940
|
}
|
|
23854
23941
|
if (options.agent === "codex") {
|
|
23855
|
-
const home = env.CODEX_HOME ??
|
|
23856
|
-
return { settings:
|
|
23942
|
+
const home = env.CODEX_HOME ?? path13.join(homedir2(), ".codex");
|
|
23943
|
+
return { settings: path13.join(home, "config.toml"), instructions: path13.join(home, "AGENTS.md") };
|
|
23857
23944
|
}
|
|
23858
23945
|
if (options.scope === "user") {
|
|
23859
|
-
const home = env.CLAUDE_CONFIG_DIR ??
|
|
23946
|
+
const home = env.CLAUDE_CONFIG_DIR ?? path13.join(homedir2(), ".claude");
|
|
23860
23947
|
return {
|
|
23861
|
-
settings:
|
|
23862
|
-
instructions:
|
|
23948
|
+
settings: path13.join(home, "settings.json"),
|
|
23949
|
+
instructions: path13.join(home, "CLAUDE.md")
|
|
23863
23950
|
};
|
|
23864
23951
|
}
|
|
23865
23952
|
const local = options.scope === "local";
|
|
23866
23953
|
return {
|
|
23867
|
-
settings:
|
|
23954
|
+
settings: path13.join(
|
|
23868
23955
|
options.project,
|
|
23869
23956
|
".claude",
|
|
23870
23957
|
local ? "settings.local.json" : "settings.json"
|
|
23871
23958
|
),
|
|
23872
|
-
instructions:
|
|
23959
|
+
instructions: path13.join(options.project, local ? "CLAUDE.local.md" : "CLAUDE.md")
|
|
23873
23960
|
};
|
|
23874
23961
|
};
|
|
23875
23962
|
async function setupAgent(options) {
|
|
@@ -23976,7 +24063,8 @@ Usage:
|
|
|
23976
24063
|
layermap refs PATH NAME [--line N] [--path DIR] [--max N] [--cursor C]
|
|
23977
24064
|
layermap check [--base REF] what the uncommitted changes (or those since REF) affect
|
|
23978
24065
|
|
|
23979
|
-
The project is the Git work tree around the current directory unless --project names one
|
|
24066
|
+
The project is the Git work tree around the current directory unless --project names one; the MCP
|
|
24067
|
+
server also maps any other repository a tool call's path names.
|
|
23980
24068
|
Maps are kept in ${cacheDirectory()}.`;
|
|
23981
24069
|
var log = (line) => process.stderr.write(`${line}
|
|
23982
24070
|
`);
|
|
@@ -24020,10 +24108,9 @@ async function main(argv) {
|
|
|
24020
24108
|
if (values.help || !command) return usage(command ? 0 : 1);
|
|
24021
24109
|
const { directory: project, git: git2 } = await projectDirectory(values.project ?? process.cwd());
|
|
24022
24110
|
const cache = cacheDirectory();
|
|
24023
|
-
const open2 = async () => {
|
|
24024
|
-
if (!git2) throw new ProjectEvidenceError("LAYERMAP_NOT_A_GIT_REPOSITORY", false);
|
|
24111
|
+
const open2 = async (directory) => {
|
|
24025
24112
|
const map3 = await LayerMap.open({
|
|
24026
|
-
project,
|
|
24113
|
+
project: directory,
|
|
24027
24114
|
cacheDirectory: cache,
|
|
24028
24115
|
analyzers: await resolveAnalyzers(cache, log)
|
|
24029
24116
|
});
|
|
@@ -24048,11 +24135,12 @@ async function main(argv) {
|
|
|
24048
24135
|
return done ? 0 : 1;
|
|
24049
24136
|
}
|
|
24050
24137
|
if (command === "mcp") {
|
|
24051
|
-
await serveMcp({ version: version2, open: open2, log });
|
|
24138
|
+
await serveMcp({ version: version2, start: { directory: project, git: git2 }, open: open2, log });
|
|
24052
24139
|
return 0;
|
|
24053
24140
|
}
|
|
24054
24141
|
const number4 = (value) => value === void 0 ? void 0 : Number(value);
|
|
24055
|
-
|
|
24142
|
+
if (!git2) throw new ProjectEvidenceError("LAYERMAP_NOT_A_GIT_REPOSITORY", false);
|
|
24143
|
+
const map2 = await open2(project);
|
|
24056
24144
|
const signal = new AbortController().signal;
|
|
24057
24145
|
try {
|
|
24058
24146
|
if (command === "index") {
|
|
@@ -24107,7 +24195,8 @@ async function main(argv) {
|
|
|
24107
24195
|
field && typeof field === "object" && !Array.isArray(field) ? defined(field) : field
|
|
24108
24196
|
])
|
|
24109
24197
|
);
|
|
24110
|
-
const
|
|
24198
|
+
const parsed = parseMapToolCall(tool, defined(args));
|
|
24199
|
+
const result = "text" in parsed ? parsed : await runMapTool(map2, parsed, signal);
|
|
24111
24200
|
(result.isError ? process.stderr : process.stdout).write(`${result.text}
|
|
24112
24201
|
`);
|
|
24113
24202
|
return result.isError ? 1 : 0;
|