layermap 0.1.4 → 0.1.6
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 +37 -12
- package/analyzers/go/darwin-arm64/go-map +0 -0
- package/analyzers/go/darwin-x64/go-map +0 -0
- package/analyzers/go/linux-arm64/go-map +0 -0
- package/analyzers/go/linux-x64/go-map +0 -0
- package/analyzers/project-map-java/java-map.jar +0 -0
- package/analyzers/project-map-python-worker.mjs +68 -1
- package/analyzers/project-map-worker.mjs +267 -150
- package/dist/cli.mjs +968 -307
- package/package.json +1 -1
package/dist/cli.mjs
CHANGED
|
@@ -12,18 +12,18 @@ import { parseArgs } from "node:util";
|
|
|
12
12
|
// src/agent/environment.ts
|
|
13
13
|
import { execFile } from "node:child_process";
|
|
14
14
|
import { createHash as createHash5 } from "node:crypto";
|
|
15
|
-
import { existsSync as existsSync4, readFileSync as
|
|
15
|
+
import { existsSync as existsSync4, readFileSync as readFileSync3 } from "node:fs";
|
|
16
16
|
import { mkdir, readdir, readFile, rename, rm, stat, utimes, writeFile } from "node:fs/promises";
|
|
17
17
|
import { createRequire } from "node:module";
|
|
18
18
|
import { homedir } from "node:os";
|
|
19
|
-
import
|
|
19
|
+
import path9 from "node:path";
|
|
20
20
|
import { fileURLToPath } from "node:url";
|
|
21
21
|
|
|
22
22
|
// src/layermap.ts
|
|
23
23
|
import { createHash as createHash4 } from "node:crypto";
|
|
24
24
|
import { mkdirSync } from "node:fs";
|
|
25
25
|
import { lstat as lstat2, realpath as realpath2 } from "node:fs/promises";
|
|
26
|
-
import
|
|
26
|
+
import path8 from "node:path";
|
|
27
27
|
import { DatabaseSync } from "@photostructure/sqlite";
|
|
28
28
|
|
|
29
29
|
// src/capture-policy.ts
|
|
@@ -228,8 +228,8 @@ var parseFileUniverse = (output) => {
|
|
|
228
228
|
);
|
|
229
229
|
};
|
|
230
230
|
var ProjectEvidenceFileUniverse = class {
|
|
231
|
-
constructor(
|
|
232
|
-
this.git =
|
|
231
|
+
constructor(git2 = new GitRunner()) {
|
|
232
|
+
this.git = git2;
|
|
233
233
|
}
|
|
234
234
|
git;
|
|
235
235
|
async capture(root, signal) {
|
|
@@ -1221,10 +1221,10 @@ function mergeDefs(...defs) {
|
|
|
1221
1221
|
function cloneDef(schema) {
|
|
1222
1222
|
return mergeDefs(schema._zod.def);
|
|
1223
1223
|
}
|
|
1224
|
-
function getElementAtPath(obj,
|
|
1225
|
-
if (!
|
|
1224
|
+
function getElementAtPath(obj, path11) {
|
|
1225
|
+
if (!path11)
|
|
1226
1226
|
return obj;
|
|
1227
|
-
return
|
|
1227
|
+
return path11.reduce((acc, key) => acc?.[key], obj);
|
|
1228
1228
|
}
|
|
1229
1229
|
function promiseAllObject(promisesObj) {
|
|
1230
1230
|
const keys = Object.keys(promisesObj);
|
|
@@ -1633,11 +1633,11 @@ function explicitlyAborted(x, startIndex = 0) {
|
|
|
1633
1633
|
}
|
|
1634
1634
|
return false;
|
|
1635
1635
|
}
|
|
1636
|
-
function prefixIssues(
|
|
1636
|
+
function prefixIssues(path11, issues) {
|
|
1637
1637
|
return issues.map((iss) => {
|
|
1638
1638
|
var _a3;
|
|
1639
1639
|
(_a3 = iss).path ?? (_a3.path = []);
|
|
1640
|
-
iss.path.unshift(
|
|
1640
|
+
iss.path.unshift(path11);
|
|
1641
1641
|
return iss;
|
|
1642
1642
|
});
|
|
1643
1643
|
}
|
|
@@ -1784,16 +1784,16 @@ function flattenError(error51, mapper = (issue2) => issue2.message) {
|
|
|
1784
1784
|
}
|
|
1785
1785
|
function formatError(error51, mapper = (issue2) => issue2.message) {
|
|
1786
1786
|
const fieldErrors = { _errors: [] };
|
|
1787
|
-
const processError = (error52,
|
|
1787
|
+
const processError = (error52, path11 = []) => {
|
|
1788
1788
|
for (const issue2 of error52.issues) {
|
|
1789
1789
|
if (issue2.code === "invalid_union" && issue2.errors.length) {
|
|
1790
|
-
issue2.errors.map((issues) => processError({ issues }, [...
|
|
1790
|
+
issue2.errors.map((issues) => processError({ issues }, [...path11, ...issue2.path]));
|
|
1791
1791
|
} else if (issue2.code === "invalid_key") {
|
|
1792
|
-
processError({ issues: issue2.issues }, [...
|
|
1792
|
+
processError({ issues: issue2.issues }, [...path11, ...issue2.path]);
|
|
1793
1793
|
} else if (issue2.code === "invalid_element") {
|
|
1794
|
-
processError({ issues: issue2.issues }, [...
|
|
1794
|
+
processError({ issues: issue2.issues }, [...path11, ...issue2.path]);
|
|
1795
1795
|
} else {
|
|
1796
|
-
const fullpath = [...
|
|
1796
|
+
const fullpath = [...path11, ...issue2.path];
|
|
1797
1797
|
if (fullpath.length === 0) {
|
|
1798
1798
|
fieldErrors._errors.push(mapper(issue2));
|
|
1799
1799
|
} else {
|
|
@@ -1820,17 +1820,17 @@ function formatError(error51, mapper = (issue2) => issue2.message) {
|
|
|
1820
1820
|
}
|
|
1821
1821
|
function treeifyError(error51, mapper = (issue2) => issue2.message) {
|
|
1822
1822
|
const result = { errors: [] };
|
|
1823
|
-
const processError = (error52,
|
|
1823
|
+
const processError = (error52, path11 = []) => {
|
|
1824
1824
|
var _a3, _b;
|
|
1825
1825
|
for (const issue2 of error52.issues) {
|
|
1826
1826
|
if (issue2.code === "invalid_union" && issue2.errors.length) {
|
|
1827
|
-
issue2.errors.map((issues) => processError({ issues }, [...
|
|
1827
|
+
issue2.errors.map((issues) => processError({ issues }, [...path11, ...issue2.path]));
|
|
1828
1828
|
} else if (issue2.code === "invalid_key") {
|
|
1829
|
-
processError({ issues: issue2.issues }, [...
|
|
1829
|
+
processError({ issues: issue2.issues }, [...path11, ...issue2.path]);
|
|
1830
1830
|
} else if (issue2.code === "invalid_element") {
|
|
1831
|
-
processError({ issues: issue2.issues }, [...
|
|
1831
|
+
processError({ issues: issue2.issues }, [...path11, ...issue2.path]);
|
|
1832
1832
|
} else {
|
|
1833
|
-
const fullpath = [...
|
|
1833
|
+
const fullpath = [...path11, ...issue2.path];
|
|
1834
1834
|
if (fullpath.length === 0) {
|
|
1835
1835
|
result.errors.push(mapper(issue2));
|
|
1836
1836
|
continue;
|
|
@@ -1862,8 +1862,8 @@ function treeifyError(error51, mapper = (issue2) => issue2.message) {
|
|
|
1862
1862
|
}
|
|
1863
1863
|
function toDotPath(_path) {
|
|
1864
1864
|
const segs = [];
|
|
1865
|
-
const
|
|
1866
|
-
for (const seg of
|
|
1865
|
+
const path11 = _path.map((seg) => typeof seg === "object" ? seg.key : seg);
|
|
1866
|
+
for (const seg of path11) {
|
|
1867
1867
|
if (typeof seg === "number")
|
|
1868
1868
|
segs.push(`[${seg}]`);
|
|
1869
1869
|
else if (typeof seg === "symbol")
|
|
@@ -14555,13 +14555,13 @@ function resolveRef(ref, ctx) {
|
|
|
14555
14555
|
if (!ref.startsWith("#")) {
|
|
14556
14556
|
throw new Error("External $ref is not supported, only local refs (#/...) are allowed");
|
|
14557
14557
|
}
|
|
14558
|
-
const
|
|
14559
|
-
if (
|
|
14558
|
+
const path11 = ref.slice(1).split("/").filter(Boolean);
|
|
14559
|
+
if (path11.length === 0) {
|
|
14560
14560
|
return ctx.rootSchema;
|
|
14561
14561
|
}
|
|
14562
14562
|
const defsKey = ctx.version === "draft-2020-12" ? "$defs" : "definitions";
|
|
14563
|
-
if (
|
|
14564
|
-
const key =
|
|
14563
|
+
if (path11[0] === defsKey) {
|
|
14564
|
+
const key = path11[1];
|
|
14565
14565
|
if (!key || !ctx.defs[key]) {
|
|
14566
14566
|
throw new Error(`Reference not found: ${ref}`);
|
|
14567
14567
|
}
|
|
@@ -15058,10 +15058,10 @@ var digestValue = (value) => createHash("sha256").update(canonicalJson(value)).d
|
|
|
15058
15058
|
|
|
15059
15059
|
// src/code-commit-reader.ts
|
|
15060
15060
|
var CodeCommitReader = class _CodeCommitReader {
|
|
15061
|
-
constructor(root, entries,
|
|
15061
|
+
constructor(root, entries, git2, signal) {
|
|
15062
15062
|
this.root = root;
|
|
15063
15063
|
this.entries = entries;
|
|
15064
|
-
this.git =
|
|
15064
|
+
this.git = git2;
|
|
15065
15065
|
this.signal = signal;
|
|
15066
15066
|
this.byPath = new Map(entries.map((entry) => [entry.path, entry]));
|
|
15067
15067
|
}
|
|
@@ -15076,14 +15076,14 @@ var CodeCommitReader = class _CodeCommitReader {
|
|
|
15076
15076
|
if (!/^(?:[a-f0-9]{40}|[a-f0-9]{64})$/u.test(commit)) {
|
|
15077
15077
|
throw new ProjectEvidenceError("PROJECT_CODE_COMMIT_INVALID", false);
|
|
15078
15078
|
}
|
|
15079
|
-
const
|
|
15079
|
+
const git2 = new GitRunner();
|
|
15080
15080
|
const options = { cwd: root, signal, timeoutMs: null, maxOutputBytes: null };
|
|
15081
|
-
const resolved = (await
|
|
15081
|
+
const resolved = (await git2.run(
|
|
15082
15082
|
["--no-replace-objects", "rev-parse", "--verify", `${commit}^{commit}`],
|
|
15083
15083
|
options
|
|
15084
15084
|
)).stdout.toString("utf8").trim();
|
|
15085
15085
|
if (resolved !== commit) throw new ProjectEvidenceError("PROJECT_CODE_COMMIT_INVALID", false);
|
|
15086
|
-
const tree = (await
|
|
15086
|
+
const tree = (await git2.run(
|
|
15087
15087
|
[
|
|
15088
15088
|
"--no-replace-objects",
|
|
15089
15089
|
"--literal-pathspecs",
|
|
@@ -15114,7 +15114,7 @@ var CodeCommitReader = class _CodeCommitReader {
|
|
|
15114
15114
|
}
|
|
15115
15115
|
if (selectedPath !== void 0 && (entries.length !== 1 || entries[0]?.path !== selectedPath))
|
|
15116
15116
|
throw new ProjectEvidenceError("PROJECT_MAP_SOURCE_CHANGED", true);
|
|
15117
|
-
return new _CodeCommitReader(root, entries,
|
|
15117
|
+
return new _CodeCommitReader(root, entries, git2, signal);
|
|
15118
15118
|
}
|
|
15119
15119
|
async read(relativePath) {
|
|
15120
15120
|
const source = this.byPath.get(relativePath);
|
|
@@ -15662,13 +15662,13 @@ var MapOutputCollector = class {
|
|
|
15662
15662
|
|
|
15663
15663
|
// src/project-map-query-selection.ts
|
|
15664
15664
|
var mapQuerySelection = (input, knownKinds) => {
|
|
15665
|
-
const
|
|
15665
|
+
const path11 = normalizeProjectEvidencePath(input.path ?? ".", true) || ".";
|
|
15666
15666
|
const kinds = input.kinds ?? knownKinds;
|
|
15667
15667
|
if (!Array.isArray(kinds) || !kinds.length || kinds.length > knownKinds.length || kinds.some((kind) => !knownKinds.includes(kind)))
|
|
15668
15668
|
throw new ProjectEvidenceError("PROJECT_READ_INPUT_INVALID", false);
|
|
15669
|
-
return { path:
|
|
15669
|
+
return { path: path11, kinds: [...new Set(kinds)].sort() };
|
|
15670
15670
|
};
|
|
15671
|
-
var mapQueryPathMatches = (
|
|
15671
|
+
var mapQueryPathMatches = (path11, prefix) => prefix === "." || path11 === prefix || path11.startsWith(`${prefix}/`);
|
|
15672
15672
|
var mapQueryPathSql = (column) => `(? = '.' OR ${column} = ? OR substr(${column}, 1, length(?) + 1) = ? || '/')`;
|
|
15673
15673
|
|
|
15674
15674
|
// src/project-map-configuration-types.ts
|
|
@@ -15782,8 +15782,11 @@ var MapRelationSchema = external_exports.object({
|
|
|
15782
15782
|
anchor: MapAnchorSchema,
|
|
15783
15783
|
target: external_exports.string(),
|
|
15784
15784
|
// A literal the relation carries: a decorator's first argument on the declaration itself, or
|
|
15785
|
-
// the
|
|
15785
|
+
// the route a call or value is registered under (its methods, if named, then its path).
|
|
15786
15786
|
argument: external_exports.string().min(1).max(256).optional(),
|
|
15787
|
+
// The full route a decorator registers its declaration under, when it says more than the
|
|
15788
|
+
// argument: the HTTP methods, then the class's path joined with the member's.
|
|
15789
|
+
route: external_exports.string().min(1).max(256).optional(),
|
|
15787
15790
|
basis: external_exports.enum(["TYPE_RESOLVED", "SYNTAX_DECLARED", "UNRESOLVED"]),
|
|
15788
15791
|
unresolvedReason: external_exports.enum([
|
|
15789
15792
|
"SYNTAX_ONLY",
|
|
@@ -15872,8 +15875,8 @@ var MapAnalysisSchema = external_exports.object({
|
|
|
15872
15875
|
var mapPathAllowed = (relative, prefixes) => prefixes.some(
|
|
15873
15876
|
(prefix) => prefix === "." || relative === prefix || relative.startsWith(`${prefix}/`)
|
|
15874
15877
|
);
|
|
15875
|
-
var mapTestPath = (
|
|
15876
|
-
|
|
15878
|
+
var mapTestPath = (path11) => /(?:^|\/)(?:__tests__|tests?|fixtures?|e2e|testdata)(?:\/|$)|\.(?:spec|test)\.|_test\.(?:go|py)$|(?:^|\/)(?:test_[^/]*\.py|conftest\.py)$/iu.test(
|
|
15879
|
+
path11
|
|
15877
15880
|
);
|
|
15878
15881
|
|
|
15879
15882
|
// src/project-map-reference-types.ts
|
|
@@ -16005,7 +16008,8 @@ var MapFactsSchema = external_exports.object({
|
|
|
16005
16008
|
target: external_exports.string(),
|
|
16006
16009
|
basis: MapRelationSchema.shape.basis,
|
|
16007
16010
|
reason: MapRelationSchema.shape.unresolvedReason,
|
|
16008
|
-
argument: MapRelationSchema.shape.argument
|
|
16011
|
+
argument: MapRelationSchema.shape.argument,
|
|
16012
|
+
route: MapRelationSchema.shape.route
|
|
16009
16013
|
}).strict()
|
|
16010
16014
|
),
|
|
16011
16015
|
notes: external_exports.array(
|
|
@@ -16040,13 +16044,13 @@ function utf16Offsets(text) {
|
|
|
16040
16044
|
}
|
|
16041
16045
|
function offsetConverter(files, offsets) {
|
|
16042
16046
|
const converters = /* @__PURE__ */ new Map();
|
|
16043
|
-
return (
|
|
16044
|
-
let convert = converters.get(
|
|
16047
|
+
return (path11, offset) => {
|
|
16048
|
+
let convert = converters.get(path11);
|
|
16045
16049
|
if (!convert) {
|
|
16046
|
-
const text = files[
|
|
16050
|
+
const text = files[path11];
|
|
16047
16051
|
if (text === void 0) return invalid();
|
|
16048
16052
|
convert = offsets === "UTF16" ? (value) => value <= text.length ? value : invalid() : utf16Offsets(text);
|
|
16049
|
-
converters.set(
|
|
16053
|
+
converters.set(path11, convert);
|
|
16050
16054
|
}
|
|
16051
16055
|
return convert(offset);
|
|
16052
16056
|
};
|
|
@@ -16077,7 +16081,7 @@ function mapFactsAnalysis(facts, input, context) {
|
|
|
16077
16081
|
const collect = new MapOutputCollector(output);
|
|
16078
16082
|
const positions = new MapSourcePositions(input.files);
|
|
16079
16083
|
const offset = offsetConverter(input.files, context.offsets);
|
|
16080
|
-
const anchor = (
|
|
16084
|
+
const anchor = (path11, start, end) => positions.span(path11, offset(path11, start), offset(path11, end));
|
|
16081
16085
|
const located = /* @__PURE__ */ new Map();
|
|
16082
16086
|
const canonical = /* @__PURE__ */ new Map();
|
|
16083
16087
|
const bySpan = /* @__PURE__ */ new Map();
|
|
@@ -16183,7 +16187,8 @@ function mapFactsAnalysis(facts, input, context) {
|
|
|
16183
16187
|
target: fact.target,
|
|
16184
16188
|
basis: fact.basis,
|
|
16185
16189
|
...fact.reason ? { unresolvedReason: fact.reason } : {},
|
|
16186
|
-
...fact.argument ? { argument: fact.argument } : {}
|
|
16190
|
+
...fact.argument ? { argument: fact.argument } : {},
|
|
16191
|
+
...fact.route ? { route: fact.route } : {}
|
|
16187
16192
|
});
|
|
16188
16193
|
if (fact.kind === "WRITES")
|
|
16189
16194
|
collect.note({
|
|
@@ -16645,9 +16650,9 @@ function runMapOperation(resources, input, schema, signal, observeTiming) {
|
|
|
16645
16650
|
var goModule = /(?:^|\/)go\.mod$/u;
|
|
16646
16651
|
var codeHosts = /* @__PURE__ */ new Set(["github.com", "gitlab.com", "bitbucket.org"]);
|
|
16647
16652
|
var GO_MAP_LANGUAGE = Object.freeze({
|
|
16648
|
-
id: "go-1.24-map-
|
|
16649
|
-
claims: (
|
|
16650
|
-
reads: (
|
|
16653
|
+
id: "go-1.24-map-v7",
|
|
16654
|
+
claims: (path11) => path11.endsWith(".go"),
|
|
16655
|
+
reads: (path11) => goModule.test(path11),
|
|
16651
16656
|
// A module path, or the standard library, whose first path element has no dot.
|
|
16652
16657
|
importName: (specifier) => {
|
|
16653
16658
|
const parts = specifier.split("/");
|
|
@@ -16656,7 +16661,7 @@ var GO_MAP_LANGUAGE = Object.freeze({
|
|
|
16656
16661
|
return parts.slice(0, size).join("/");
|
|
16657
16662
|
},
|
|
16658
16663
|
// Go imports a package: the directory of the file.
|
|
16659
|
-
importTarget: (
|
|
16664
|
+
importTarget: (path11) => `${path11.slice(0, path11.lastIndexOf("/") + 1) || "./"}`,
|
|
16660
16665
|
create: () => new GoMapAnalyzer()
|
|
16661
16666
|
});
|
|
16662
16667
|
var GO_GAPS = [
|
|
@@ -16702,12 +16707,12 @@ var GoMapAnalyzer = class {
|
|
|
16702
16707
|
}
|
|
16703
16708
|
}
|
|
16704
16709
|
async analyze(session, signal) {
|
|
16705
|
-
const modules = session.readable.map((entry) => entry.path).filter((
|
|
16706
|
-
const moduleOf = (
|
|
16710
|
+
const modules = session.readable.map((entry) => entry.path).filter((path11) => goModule.test(path11)).sort();
|
|
16711
|
+
const moduleOf = (path11) => {
|
|
16707
16712
|
let best;
|
|
16708
16713
|
for (const modFile of modules) {
|
|
16709
16714
|
const directory = modFile.slice(0, modFile.lastIndexOf("/") + 1);
|
|
16710
|
-
if (
|
|
16715
|
+
if (path11.startsWith(directory) && (!best || directory.length > best.lastIndexOf("/") + 1))
|
|
16711
16716
|
best = modFile;
|
|
16712
16717
|
}
|
|
16713
16718
|
return best;
|
|
@@ -16723,11 +16728,11 @@ var GoMapAnalyzer = class {
|
|
|
16723
16728
|
for (const modFile of [...groups.keys()].sort()) {
|
|
16724
16729
|
if (signal.aborted) throw new ProjectEvidenceError("PROJECT_READ_CANCELLED", true);
|
|
16725
16730
|
const files = /* @__PURE__ */ Object.create(null);
|
|
16726
|
-
for (const
|
|
16727
|
-
const text = session.texts[
|
|
16731
|
+
for (const path11 of [...groups.get(modFile) ?? [], ...modFile ? [modFile] : []]) {
|
|
16732
|
+
const text = session.texts[path11];
|
|
16728
16733
|
if (text === void 0)
|
|
16729
16734
|
throw new ProjectEvidenceError("PROJECT_MAP_PROTOCOL_INVALID", false);
|
|
16730
|
-
files[
|
|
16735
|
+
files[path11] = text;
|
|
16731
16736
|
}
|
|
16732
16737
|
const input = {
|
|
16733
16738
|
contextRef: digestValue({
|
|
@@ -16762,8 +16767,8 @@ var GoMapAnalyzer = class {
|
|
|
16762
16767
|
if (text === void 0 || !existsSync2(this.resources.compilerPath))
|
|
16763
16768
|
throw new ProjectEvidenceError("PROJECT_MAP_REFERENCE_TARGET_UNAVAILABLE", false);
|
|
16764
16769
|
const files = /* @__PURE__ */ Object.create(null);
|
|
16765
|
-
for (const [
|
|
16766
|
-
if (this.claims(
|
|
16770
|
+
for (const [path11, value] of Object.entries(input.files))
|
|
16771
|
+
if (this.claims(path11) || goModule.test(path11)) files[path11] = value;
|
|
16767
16772
|
const facts = await this.operation(
|
|
16768
16773
|
{
|
|
16769
16774
|
...input,
|
|
@@ -16793,14 +16798,14 @@ var BUILD_FILES = [
|
|
|
16793
16798
|
"pom.xml"
|
|
16794
16799
|
];
|
|
16795
16800
|
var buildFile = /(?:^|\/)(?:pom\.xml|(?:build|settings)\.gradle(?:\.kts)?)$/u;
|
|
16796
|
-
var directoryOf = (
|
|
16797
|
-
var nameOf = (
|
|
16801
|
+
var directoryOf = (path11) => path11.slice(0, path11.lastIndexOf("/") + 1);
|
|
16802
|
+
var nameOf = (path11) => path11.slice(path11.lastIndexOf("/") + 1);
|
|
16798
16803
|
var DEFAULT_RELEASE = 21;
|
|
16799
16804
|
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;
|
|
16800
16805
|
var JAVA_MAP_LANGUAGE = Object.freeze({
|
|
16801
|
-
id: "javac-lombok-1.18.48-map-
|
|
16802
|
-
claims: (
|
|
16803
|
-
reads: (
|
|
16806
|
+
id: "javac-lombok-1.18.48-map-v6",
|
|
16807
|
+
claims: (path11) => path11.endsWith(".java"),
|
|
16808
|
+
reads: (path11) => buildFile.test(path11),
|
|
16804
16809
|
// A package of the Java platform, or a library named by its first two package segments.
|
|
16805
16810
|
importName: (specifier) => platformPackage.test(specifier) ? "Java standard library" : specifier.split(".").slice(0, 2).join("."),
|
|
16806
16811
|
create: () => new JavaMapAnalyzer()
|
|
@@ -16890,12 +16895,12 @@ var JavaMapAnalyzer = class _JavaMapAnalyzer {
|
|
|
16890
16895
|
// The worker's request for a context: the Java sources, the release and which are tests.
|
|
16891
16896
|
request(input, buildTexts) {
|
|
16892
16897
|
const files = /* @__PURE__ */ Object.create(null);
|
|
16893
|
-
for (const [
|
|
16894
|
-
if (this.claims(
|
|
16898
|
+
for (const [path11, text] of Object.entries(input.files))
|
|
16899
|
+
if (this.claims(path11)) files[path11] = text;
|
|
16895
16900
|
return {
|
|
16896
16901
|
files,
|
|
16897
16902
|
release: javaRelease(buildTexts, this.resources.runtimeVersion),
|
|
16898
|
-
tests: Object.keys(files).filter((
|
|
16903
|
+
tests: Object.keys(files).filter((path11) => mapTestPath(path11))
|
|
16899
16904
|
};
|
|
16900
16905
|
}
|
|
16901
16906
|
// The build files of a context's root directory, which declare its Java version.
|
|
@@ -16907,35 +16912,35 @@ var JavaMapAnalyzer = class _JavaMapAnalyzer {
|
|
|
16907
16912
|
}
|
|
16908
16913
|
async analyze(session, signal) {
|
|
16909
16914
|
this.refreshRuntime();
|
|
16910
|
-
const builds = session.readable.map((entry) => entry.path).filter((
|
|
16911
|
-
for (const
|
|
16912
|
-
const rank2 = (
|
|
16915
|
+
const builds = session.readable.map((entry) => entry.path).filter((path11) => buildFile.test(path11));
|
|
16916
|
+
for (const path11 of builds) session.configuration(path11);
|
|
16917
|
+
const rank2 = (path11) => BUILD_FILES.indexOf(nameOf(path11));
|
|
16913
16918
|
const roots = /* @__PURE__ */ new Map();
|
|
16914
16919
|
const modules = /* @__PURE__ */ new Map();
|
|
16915
|
-
for (const
|
|
16916
|
-
const directory = directoryOf(
|
|
16920
|
+
for (const path11 of builds) {
|
|
16921
|
+
const directory = directoryOf(path11);
|
|
16917
16922
|
const current = modules.get(directory);
|
|
16918
|
-
if (current === void 0 || rank2(
|
|
16919
|
-
const text = session.texts[
|
|
16920
|
-
if (/settings\.gradle(?:\.kts)?$/u.test(
|
|
16923
|
+
if (current === void 0 || rank2(path11) < rank2(current)) modules.set(directory, path11);
|
|
16924
|
+
const text = session.texts[path11] ?? "";
|
|
16925
|
+
if (/settings\.gradle(?:\.kts)?$/u.test(path11) || path11.endsWith("pom.xml") && /<modules>/u.test(text)) {
|
|
16921
16926
|
const root = roots.get(directory);
|
|
16922
|
-
if (root === void 0 || rank2(
|
|
16927
|
+
if (root === void 0 || rank2(path11) < rank2(root)) roots.set(directory, path11);
|
|
16923
16928
|
}
|
|
16924
16929
|
}
|
|
16925
|
-
const configOf = (
|
|
16930
|
+
const configOf = (path11) => {
|
|
16926
16931
|
let outer;
|
|
16927
16932
|
for (const directory of roots.keys())
|
|
16928
|
-
if (
|
|
16933
|
+
if (path11.startsWith(directory) && (outer === void 0 || directory.length < outer.length))
|
|
16929
16934
|
outer = directory;
|
|
16930
16935
|
if (outer !== void 0) return roots.get(outer);
|
|
16931
16936
|
let nearest;
|
|
16932
16937
|
for (const directory of modules.keys())
|
|
16933
|
-
if (
|
|
16938
|
+
if (path11.startsWith(directory) && (nearest === void 0 || directory.length > nearest.length))
|
|
16934
16939
|
nearest = directory;
|
|
16935
16940
|
return nearest === void 0 ? "" : modules.get(nearest);
|
|
16936
16941
|
};
|
|
16937
|
-
const output = (
|
|
16938
|
-
(directory) =>
|
|
16942
|
+
const output = (path11) => [...modules.keys()].some(
|
|
16943
|
+
(directory) => path11.startsWith(`${directory}build/`) || path11.startsWith(`${directory}target/`)
|
|
16939
16944
|
);
|
|
16940
16945
|
const groups = /* @__PURE__ */ new Map();
|
|
16941
16946
|
for (const entry of session.readable) {
|
|
@@ -16950,13 +16955,13 @@ var JavaMapAnalyzer = class _JavaMapAnalyzer {
|
|
|
16950
16955
|
if (signal.aborted) throw new ProjectEvidenceError("PROJECT_READ_CANCELLED", true);
|
|
16951
16956
|
const files = /* @__PURE__ */ Object.create(null);
|
|
16952
16957
|
const rootBuilds = configPath ? BUILD_FILES.map((name) => `${directoryOf(configPath)}${name}`).filter(
|
|
16953
|
-
(
|
|
16958
|
+
(path11) => builds.includes(path11)
|
|
16954
16959
|
) : [];
|
|
16955
|
-
for (const
|
|
16956
|
-
const text = session.texts[
|
|
16960
|
+
for (const path11 of [...groups.get(configPath) ?? [], ...rootBuilds]) {
|
|
16961
|
+
const text = session.texts[path11];
|
|
16957
16962
|
if (text === void 0)
|
|
16958
16963
|
throw new ProjectEvidenceError("PROJECT_MAP_PROTOCOL_INVALID", false);
|
|
16959
|
-
files[
|
|
16964
|
+
files[path11] = text;
|
|
16960
16965
|
}
|
|
16961
16966
|
const input = {
|
|
16962
16967
|
contextRef: digestValue({
|
|
@@ -16999,7 +17004,7 @@ var JavaMapAnalyzer = class _JavaMapAnalyzer {
|
|
|
16999
17004
|
const prior = JavaStateSchema.safeParse(previous?.state).data;
|
|
17000
17005
|
const incremental = previous && prior?.basis === basis ? {
|
|
17001
17006
|
changed: Object.keys(request.files).filter(
|
|
17002
|
-
(
|
|
17007
|
+
(path11) => digests.get(path11) !== previous.digests.get(path11)
|
|
17003
17008
|
),
|
|
17004
17009
|
state: prior.java
|
|
17005
17010
|
} : void 0;
|
|
@@ -17028,14 +17033,14 @@ var JavaMapAnalyzer = class _JavaMapAnalyzer {
|
|
|
17028
17033
|
continue;
|
|
17029
17034
|
}
|
|
17030
17035
|
const focus = new Set(facts.focus);
|
|
17031
|
-
if (!incremental || facts.focus.some((
|
|
17036
|
+
if (!incremental || facts.focus.some((path11) => !Object.hasOwn(request.files, path11)) || incremental.changed.some((path11) => !focus.has(path11)))
|
|
17032
17037
|
throw new ProjectEvidenceError("PROJECT_MAP_PROTOCOL_INVALID", false);
|
|
17033
17038
|
analysis.objects = analysis.objects.filter((object2) => focus.has(object2.anchor.path));
|
|
17034
17039
|
analysis.relations = analysis.relations.filter((relation) => focus.has(relation.anchor.path));
|
|
17035
17040
|
analysis.notes = analysis.notes.filter((note) => focus.has(note.anchor.path));
|
|
17036
17041
|
session.accept(analysis, {
|
|
17037
17042
|
state,
|
|
17038
|
-
linked: analysis.parsedFiles.filter((
|
|
17043
|
+
linked: analysis.parsedFiles.filter((path11) => !focus.has(path11))
|
|
17039
17044
|
});
|
|
17040
17045
|
}
|
|
17041
17046
|
}
|
|
@@ -17347,12 +17352,12 @@ var PYTHON_STANDARD_LIBRARY = /* @__PURE__ */ new Set([
|
|
|
17347
17352
|
// src/project-map-language-python.ts
|
|
17348
17353
|
var CONFIGURATION = ["pyrightconfig.json", "pyproject.toml", "setup.cfg"];
|
|
17349
17354
|
var pythonConfig = /(?:^|\/)(?:pyrightconfig\.json|pyproject\.toml|setup\.cfg)$/u;
|
|
17350
|
-
var directoryOf2 = (
|
|
17355
|
+
var directoryOf2 = (path11) => path11.slice(0, path11.lastIndexOf("/") + 1);
|
|
17351
17356
|
var DEFAULT_PYTHON = { major: 3, minor: 13 };
|
|
17352
17357
|
var PYTHON_MAP_LANGUAGE = Object.freeze({
|
|
17353
|
-
id: "pyright-1.1.414-map-
|
|
17354
|
-
claims: (
|
|
17355
|
-
reads: (
|
|
17358
|
+
id: "pyright-1.1.414-map-v10",
|
|
17359
|
+
claims: (path11) => /\.pyi?$/u.test(path11),
|
|
17360
|
+
reads: (path11) => pythonConfig.test(path11),
|
|
17356
17361
|
// An absolute import names the standard library or a distribution's top-level package.
|
|
17357
17362
|
importName: (specifier) => {
|
|
17358
17363
|
const top = specifier.split(".", 1)[0] ?? specifier;
|
|
@@ -17404,21 +17409,21 @@ var PythonMapAnalyzer = class {
|
|
|
17404
17409
|
return {
|
|
17405
17410
|
root: input.configPath ? directoryOf2(input.configPath).replace(/\/$/u, "") : "",
|
|
17406
17411
|
pythonVersion: pythonVersion(input.files, input.configPath),
|
|
17407
|
-
tests: Object.keys(input.files).filter((
|
|
17412
|
+
tests: Object.keys(input.files).filter((path11) => this.claims(path11) && mapTestPath(path11))
|
|
17408
17413
|
};
|
|
17409
17414
|
}
|
|
17410
17415
|
async analyze(session, signal) {
|
|
17411
17416
|
const roots = /* @__PURE__ */ new Map();
|
|
17412
|
-
for (const
|
|
17413
|
-
const directory = directoryOf2(
|
|
17417
|
+
for (const path11 of session.readable.map((entry) => entry.path).filter((path12) => pythonConfig.test(path12))) {
|
|
17418
|
+
const directory = directoryOf2(path11);
|
|
17414
17419
|
const current = roots.get(directory);
|
|
17415
17420
|
const rank2 = (file2) => CONFIGURATION.indexOf(file2.slice(directory.length));
|
|
17416
|
-
if (current === void 0 || rank2(
|
|
17421
|
+
if (current === void 0 || rank2(path11) < rank2(current)) roots.set(directory, path11);
|
|
17417
17422
|
}
|
|
17418
|
-
const rootOf = (
|
|
17423
|
+
const rootOf = (path11) => {
|
|
17419
17424
|
let best;
|
|
17420
17425
|
for (const directory of roots.keys())
|
|
17421
|
-
if (
|
|
17426
|
+
if (path11.startsWith(directory) && (best === void 0 || directory.length > best.length))
|
|
17422
17427
|
best = directory;
|
|
17423
17428
|
return best === void 0 ? "" : roots.get(best);
|
|
17424
17429
|
};
|
|
@@ -17433,11 +17438,11 @@ var PythonMapAnalyzer = class {
|
|
|
17433
17438
|
for (const configPath of [...groups.keys()].sort()) {
|
|
17434
17439
|
if (signal.aborted) throw new ProjectEvidenceError("PROJECT_READ_CANCELLED", true);
|
|
17435
17440
|
const files = /* @__PURE__ */ Object.create(null);
|
|
17436
|
-
for (const
|
|
17437
|
-
const text = session.texts[
|
|
17441
|
+
for (const path11 of [...groups.get(configPath) ?? [], ...configPath ? [configPath] : []]) {
|
|
17442
|
+
const text = session.texts[path11];
|
|
17438
17443
|
if (text === void 0)
|
|
17439
17444
|
throw new ProjectEvidenceError("PROJECT_MAP_PROTOCOL_INVALID", false);
|
|
17440
|
-
files[
|
|
17445
|
+
files[path11] = text;
|
|
17441
17446
|
}
|
|
17442
17447
|
const input = {
|
|
17443
17448
|
contextRef: digestValue({
|
|
@@ -17485,8 +17490,8 @@ var PythonMapAnalyzer = class {
|
|
|
17485
17490
|
if (input.files[reference.targetPath] === void 0)
|
|
17486
17491
|
throw new ProjectEvidenceError("PROJECT_MAP_REFERENCE_TARGET_UNAVAILABLE", false);
|
|
17487
17492
|
const files = /* @__PURE__ */ Object.create(null);
|
|
17488
|
-
for (const [
|
|
17489
|
-
if (this.claims(
|
|
17493
|
+
for (const [path11, value] of Object.entries(input.files))
|
|
17494
|
+
if (this.claims(path11) || pythonConfig.test(path11)) files[path11] = value;
|
|
17490
17495
|
const facts = await this.operation(
|
|
17491
17496
|
{
|
|
17492
17497
|
...input,
|
|
@@ -17505,9 +17510,9 @@ var PythonMapAnalyzer = class {
|
|
|
17505
17510
|
|
|
17506
17511
|
// src/project-map-language-typescript.ts
|
|
17507
17512
|
var TYPESCRIPT_MAP_LANGUAGE = Object.freeze({
|
|
17508
|
-
id: "typescript-7.0.2-map-
|
|
17509
|
-
claims: (
|
|
17510
|
-
reads: (
|
|
17513
|
+
id: "typescript-7.0.2-map-v15",
|
|
17514
|
+
claims: (path11) => /\.[cm]?[jt]sx?$/u.test(path11),
|
|
17515
|
+
reads: (path11) => path11.endsWith(".json") || path11 === "pnpm-workspace.yaml",
|
|
17511
17516
|
create: () => new TypeScriptMapAnalyzer()
|
|
17512
17517
|
});
|
|
17513
17518
|
var CONFIGURATIONS_KEPT = 4;
|
|
@@ -17619,9 +17624,9 @@ var TypeScriptMapAnalyzer = class {
|
|
|
17619
17624
|
accept(analysis);
|
|
17620
17625
|
return;
|
|
17621
17626
|
}
|
|
17622
|
-
const required2 = analysis.requiredFiles.map((
|
|
17623
|
-
const entry = byPath.get(
|
|
17624
|
-
if (!entry || Object.hasOwn(texts,
|
|
17627
|
+
const required2 = analysis.requiredFiles.map((path11) => {
|
|
17628
|
+
const entry = byPath.get(path11);
|
|
17629
|
+
if (!entry || Object.hasOwn(texts, path11))
|
|
17625
17630
|
throw new ProjectEvidenceError("PROJECT_MAP_PROTOCOL_INVALID", false);
|
|
17626
17631
|
return entry;
|
|
17627
17632
|
});
|
|
@@ -17679,16 +17684,16 @@ var MAP_LANGUAGES = Object.freeze([
|
|
|
17679
17684
|
]);
|
|
17680
17685
|
var mapAnalyzerSuite = (languages) => languages.map((language) => language.id).sort().join("+");
|
|
17681
17686
|
var PROJECT_MAP_ANALYZER = mapAnalyzerSuite(MAP_LANGUAGES);
|
|
17682
|
-
var mapCodePath = (
|
|
17683
|
-
var languageOf = (
|
|
17684
|
-
var mapLanguageOf = (
|
|
17687
|
+
var mapCodePath = (path11) => MAP_LANGUAGES.some((language) => language.claims(path11));
|
|
17688
|
+
var languageOf = (path11) => MAP_LANGUAGES.find((language) => language.claims(path11));
|
|
17689
|
+
var mapLanguageOf = (path11) => languageOf(path11)?.id;
|
|
17685
17690
|
var npmPackage = (specifier) => {
|
|
17686
17691
|
if (specifier.startsWith("node:")) return "node:*";
|
|
17687
17692
|
const parts = specifier.split("/");
|
|
17688
17693
|
return specifier.startsWith("@") ? parts.slice(0, 2).join("/") : parts[0] ?? specifier;
|
|
17689
17694
|
};
|
|
17690
17695
|
var mapExternalImport = (sourcePath, specifier) => languageOf(sourcePath)?.importName?.(specifier) ?? npmPackage(specifier);
|
|
17691
|
-
var mapImportTarget = (
|
|
17696
|
+
var mapImportTarget = (path11) => languageOf(path11)?.importTarget?.(path11) ?? path11;
|
|
17692
17697
|
|
|
17693
17698
|
// src/project-map-text.ts
|
|
17694
17699
|
var MapTextObjectSchema = external_exports.object({
|
|
@@ -17729,11 +17734,11 @@ var string4 = (value) => {
|
|
|
17729
17734
|
var identity = (id2, reconstructed) => id2 === reconstructed ? [] : [JSON.stringify(id2)];
|
|
17730
17735
|
function encodeMapText(graph) {
|
|
17731
17736
|
const files = /* @__PURE__ */ new Map();
|
|
17732
|
-
const file2 = (
|
|
17733
|
-
let ref = files.get(
|
|
17737
|
+
const file2 = (path11) => {
|
|
17738
|
+
let ref = files.get(path11);
|
|
17734
17739
|
if (!ref) {
|
|
17735
17740
|
ref = `F${files.size + 1}`;
|
|
17736
|
-
files.set(
|
|
17741
|
+
files.set(path11, ref);
|
|
17737
17742
|
}
|
|
17738
17743
|
return ref;
|
|
17739
17744
|
};
|
|
@@ -17781,7 +17786,7 @@ function encodeMapText(graph) {
|
|
|
17781
17786
|
rows.push(`B ${node(frontier.entityRef)} ${frontier.direction}`);
|
|
17782
17787
|
return [
|
|
17783
17788
|
...header,
|
|
17784
|
-
...[...files].map(([
|
|
17789
|
+
...[...files].map(([path11, ref]) => `${ref} ${JSON.stringify(path11)}`),
|
|
17785
17790
|
...rows
|
|
17786
17791
|
].join("\n");
|
|
17787
17792
|
}
|
|
@@ -17801,10 +17806,10 @@ function decodeMapText(text) {
|
|
|
17801
17806
|
const at = (value) => {
|
|
17802
17807
|
const match = /^(F[1-9]\d*):(\d+)-(\d+)@(\d+)-(\d+)$/u.exec(value ?? "");
|
|
17803
17808
|
if (!match) return failed();
|
|
17804
|
-
const
|
|
17805
|
-
if (
|
|
17809
|
+
const path11 = files.get(match[1] ?? "");
|
|
17810
|
+
if (path11 === void 0) return failed();
|
|
17806
17811
|
return MapAnchorSchema.parse({
|
|
17807
|
-
path:
|
|
17812
|
+
path: path11,
|
|
17808
17813
|
startLine: Number(match[2]),
|
|
17809
17814
|
endLine: Number(match[3]),
|
|
17810
17815
|
start: Number(match[4]),
|
|
@@ -17881,8 +17886,8 @@ function decodeMapText(text) {
|
|
|
17881
17886
|
var locationSchema = MapAnchorSchema.describe(
|
|
17882
17887
|
"Source location: start/end are zero-based UTF-16 offsets with an exclusive end; line numbers are one-based."
|
|
17883
17888
|
);
|
|
17884
|
-
var location = ({ path:
|
|
17885
|
-
path:
|
|
17889
|
+
var location = ({ path: path11, startLine, endLine, start, end }) => ({
|
|
17890
|
+
path: path11,
|
|
17886
17891
|
startLine,
|
|
17887
17892
|
endLine,
|
|
17888
17893
|
start,
|
|
@@ -17985,11 +17990,11 @@ var MapNavigationObjectsSchema = external_exports.union([
|
|
|
17985
17990
|
),
|
|
17986
17991
|
external_exports.object({ files: external_exports.array(searchFileSchema) }).passthrough().refine((value) => !("format" in value), "Text navigation must decode through its format.").transform(
|
|
17987
17992
|
(value) => value.files.flatMap(
|
|
17988
|
-
({ path:
|
|
17993
|
+
({ path: path11, symbols }) => symbols.map(({ id: id2, name, kind, startLine, endLine, start, end, execution }) => ({
|
|
17989
17994
|
id: id2,
|
|
17990
17995
|
name,
|
|
17991
17996
|
kind,
|
|
17992
|
-
anchor: { path:
|
|
17997
|
+
anchor: { path: path11, startLine, endLine, start, end },
|
|
17993
17998
|
...execution ? { execution } : {}
|
|
17994
17999
|
}))
|
|
17995
18000
|
)
|
|
@@ -18002,10 +18007,10 @@ var mapSearchNavigation = (result) => {
|
|
|
18002
18007
|
for (const [index, object2] of found.entries()) {
|
|
18003
18008
|
const ranking = rankings[index];
|
|
18004
18009
|
if (!ranking) throw new Error("PROJECT_MAP_SEARCH_RANKING_MISSING");
|
|
18005
|
-
const
|
|
18010
|
+
const path11 = object2.anchor.path;
|
|
18006
18011
|
let file2 = files.at(-1);
|
|
18007
|
-
if (file2?.path !==
|
|
18008
|
-
file2 = { path:
|
|
18012
|
+
if (file2?.path !== path11) {
|
|
18013
|
+
file2 = { path: path11, symbols: [] };
|
|
18009
18014
|
files.push(file2);
|
|
18010
18015
|
}
|
|
18011
18016
|
file2.symbols.push({
|
|
@@ -18131,8 +18136,8 @@ var MapViewGraph = class {
|
|
|
18131
18136
|
}
|
|
18132
18137
|
return object2;
|
|
18133
18138
|
}
|
|
18134
|
-
objectsAt(
|
|
18135
|
-
return this.statements.path.all(this.version,
|
|
18139
|
+
objectsAt(path11) {
|
|
18140
|
+
return this.statements.path.all(this.version, path11).map((row) => {
|
|
18136
18141
|
const object2 = MapObjectSchema.parse(JSON.parse(String(row.object_json)));
|
|
18137
18142
|
this.objects.set(object2.id, object2);
|
|
18138
18143
|
return object2;
|
|
@@ -18251,8 +18256,8 @@ var MapViewGraph = class {
|
|
|
18251
18256
|
);
|
|
18252
18257
|
}
|
|
18253
18258
|
};
|
|
18254
|
-
function mapSelectDeclarations(graph,
|
|
18255
|
-
const objects2 = graph.objectsAt(
|
|
18259
|
+
function mapSelectDeclarations(graph, path11, name, line) {
|
|
18260
|
+
const objects2 = graph.objectsAt(path11).filter((object2) => !mapIsModule(object2));
|
|
18256
18261
|
const matching = name === void 0 ? objects2 : objects2.filter(
|
|
18257
18262
|
(object2) => object2.name === name || name.includes(".") && graph.qualifiedName(object2.id) === name
|
|
18258
18263
|
);
|
|
@@ -18274,12 +18279,12 @@ function requireMapObject(store, version2, selector, prefixes) {
|
|
|
18274
18279
|
if ([entityRef, locator, symbol2].filter((value) => value !== void 0).length !== 1 || entityRef !== void 0 && !entityRef.length)
|
|
18275
18280
|
throw new ProjectEvidenceError("PROJECT_READ_INPUT_INVALID", false);
|
|
18276
18281
|
if (symbol2) {
|
|
18277
|
-
const
|
|
18278
|
-
if (!mapPathAllowed(
|
|
18282
|
+
const path11 = normalizeProjectEvidencePath(symbol2.path);
|
|
18283
|
+
if (!mapPathAllowed(path11, prefixes))
|
|
18279
18284
|
throw new ProjectEvidenceError("PROJECT_MAP_OBJECT_NOT_FOUND", false);
|
|
18280
18285
|
const selected = mapSelectDeclarations(
|
|
18281
18286
|
new MapViewGraph(store, version2),
|
|
18282
|
-
|
|
18287
|
+
path11,
|
|
18283
18288
|
symbol2.name,
|
|
18284
18289
|
symbol2.line
|
|
18285
18290
|
);
|
|
@@ -18290,14 +18295,14 @@ function requireMapObject(store, version2, selector, prefixes) {
|
|
|
18290
18295
|
}
|
|
18291
18296
|
let rows;
|
|
18292
18297
|
if (locator) {
|
|
18293
|
-
const
|
|
18298
|
+
const path11 = normalizeProjectEvidencePath(locator.path);
|
|
18294
18299
|
if (!Number.isSafeInteger(locator.start) || locator.start < 0 || locator.kind !== void 0 && !MapObjectKindSchema.safeParse(locator.kind).success)
|
|
18295
18300
|
throw new ProjectEvidenceError("PROJECT_READ_INPUT_INVALID", false);
|
|
18296
|
-
if (!mapPathAllowed(
|
|
18301
|
+
if (!mapPathAllowed(path11, prefixes))
|
|
18297
18302
|
throw new ProjectEvidenceError("PROJECT_MAP_OBJECT_NOT_FOUND", false);
|
|
18298
18303
|
rows = store.database.prepare(`SELECT object_json FROM project_map_objects
|
|
18299
18304
|
WHERE version_ref = ? AND path = ? AND json_extract(object_json, '$.anchor.start') = ?
|
|
18300
|
-
AND (? IS NULL OR kind = ?) LIMIT 2`).all(version2,
|
|
18305
|
+
AND (? IS NULL OR kind = ?) LIMIT 2`).all(version2, path11, locator.start, locator.kind ?? null, locator.kind ?? null);
|
|
18301
18306
|
} else {
|
|
18302
18307
|
rows = store.database.prepare(
|
|
18303
18308
|
"SELECT object_json FROM project_map_objects WHERE version_ref = ? AND entity_ref = ?"
|
|
@@ -18431,7 +18436,7 @@ var declarationKinds = /* @__PURE__ */ new Set([
|
|
|
18431
18436
|
"METHOD",
|
|
18432
18437
|
"TYPE"
|
|
18433
18438
|
]);
|
|
18434
|
-
var fileStem = (
|
|
18439
|
+
var fileStem = (path11) => path11.slice(path11.lastIndexOf("/") + 1).replace(/\.(?:[cm]?[jt]sx?|vue|svelte|go|pyi?)$/iu, "");
|
|
18435
18440
|
var compareText = (left, right) => left < right ? -1 : left > right ? 1 : 0;
|
|
18436
18441
|
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);
|
|
18437
18442
|
function mapSearchQuery(input) {
|
|
@@ -18458,10 +18463,10 @@ function mapSearchQuery(input) {
|
|
|
18458
18463
|
}
|
|
18459
18464
|
function rank(object2, documentation, relationCount, query, focus) {
|
|
18460
18465
|
const name = object2.name.toLowerCase();
|
|
18461
|
-
const
|
|
18466
|
+
const path11 = object2.anchor.path.toLowerCase();
|
|
18462
18467
|
const values = {
|
|
18463
18468
|
NAME: [name],
|
|
18464
|
-
PATH: [
|
|
18469
|
+
PATH: [path11],
|
|
18465
18470
|
DOCUMENTATION: documentation.map((text) => text.toLowerCase())
|
|
18466
18471
|
};
|
|
18467
18472
|
const matched = query.terms.map((term) => ({
|
|
@@ -18486,12 +18491,12 @@ function rank(object2, documentation, relationCount, query, focus) {
|
|
|
18486
18491
|
score += 7e3;
|
|
18487
18492
|
signals.push("SYMBOL_CONTAINS");
|
|
18488
18493
|
} else if (matchedFields.includes("NAME")) signals.push("SYMBOL_CONTAINS");
|
|
18489
|
-
if (object2.kind === "FILE" && fileStem(
|
|
18494
|
+
if (object2.kind === "FILE" && fileStem(path11) === normalizedQuery) {
|
|
18490
18495
|
score += 11e3;
|
|
18491
18496
|
signals.push("EXACT_FILE_STEM");
|
|
18492
18497
|
}
|
|
18493
18498
|
if (matchedFields.includes("PATH")) {
|
|
18494
|
-
score +=
|
|
18499
|
+
score += path11.includes(normalizedQuery) ? 2500 : 0;
|
|
18495
18500
|
signals.push("PATH_CONTAINS");
|
|
18496
18501
|
}
|
|
18497
18502
|
if (matchedFields.includes("DOCUMENTATION")) {
|
|
@@ -18506,8 +18511,8 @@ function rank(object2, documentation, relationCount, query, focus) {
|
|
|
18506
18511
|
score += kindWeight[object2.kind] + Math.min(1200, relationCount * 20) + (focus?.score ?? 0);
|
|
18507
18512
|
if (declarationKinds.has(object2.kind)) signals.push("DECLARATION");
|
|
18508
18513
|
if (relationCount > 0) signals.push("GRAPH_CONNECTED");
|
|
18509
|
-
const isTest = mapTestPath(
|
|
18510
|
-
const isGenerated = generatedPath.test(
|
|
18514
|
+
const isTest = mapTestPath(path11);
|
|
18515
|
+
const isGenerated = generatedPath.test(path11);
|
|
18511
18516
|
const hasTestIntent = query.terms.some((term) => testQuery.test(term));
|
|
18512
18517
|
score += isTest ? hasTestIntent ? 1e3 : -5e3 : 300;
|
|
18513
18518
|
score += isGenerated ? -3e3 : 300;
|
|
@@ -18657,7 +18662,6 @@ function mapSearchView(store, version2, query, rows, offset, maxResults, budget)
|
|
|
18657
18662
|
format: MAP_SEARCH_FORMAT,
|
|
18658
18663
|
text: [
|
|
18659
18664
|
`PROJECT MAP \xB7 SEARCH ${JSON.stringify(query.text)} ${query.matchMode}${filters.length ? ` \xB7 ${filters.join(" \xB7 ")}` : ""} \xB7 ${count ? `results ${offset + 1}-${offset + count}` : "no matching declarations or files"}${more2 ? ` \xB7 continue with offset ${offset + count}` : ""}`,
|
|
18660
|
-
"Ranked by relevance; kinds f function, c class, m method, p property, v variable, t type, i interface, e enum, followed by 1-based source lines and the matched fields.",
|
|
18661
18665
|
...lines
|
|
18662
18666
|
].join("\n"),
|
|
18663
18667
|
...more2 ? { nextOffset: offset + count } : {},
|
|
@@ -18841,16 +18845,17 @@ var invalid2 = () => {
|
|
|
18841
18845
|
var notFound = () => {
|
|
18842
18846
|
throw new ProjectEvidenceError("PROJECT_MAP_OBJECT_NOT_FOUND", false);
|
|
18843
18847
|
};
|
|
18844
|
-
var
|
|
18845
|
-
var
|
|
18846
|
-
var
|
|
18847
|
-
|
|
18848
|
-
|
|
18848
|
+
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";
|
|
18849
|
+
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.`;
|
|
18850
|
+
var within = (path11, directory) => directory === "." || path11.startsWith(`${directory}/`);
|
|
18851
|
+
var parentDirectory = (path11) => {
|
|
18852
|
+
const slash = path11.lastIndexOf("/");
|
|
18853
|
+
return slash < 0 ? "." : path11.slice(0, slash);
|
|
18849
18854
|
};
|
|
18850
18855
|
var compareText2 = (left, right) => left < right ? -1 : left > right ? 1 : 0;
|
|
18851
18856
|
var byCount = ([leftName, left], [rightName, right]) => right - left || compareText2(leftName, rightName);
|
|
18852
18857
|
var increment = (counts, key, count = 1) => counts.set(key, (counts.get(key) ?? 0) + count);
|
|
18853
|
-
var decoratorTag = (name, argument) => `@${name}${argument === void 0 ? "" : `(${JSON.stringify(argument)})`}`;
|
|
18858
|
+
var decoratorTag = (name, argument, route) => `@${name}${argument === void 0 ? "" : `(${JSON.stringify(argument)})`}${route === void 0 ? "" : ` route ${JSON.stringify(route)}`}`;
|
|
18854
18859
|
var targetText = (target) => {
|
|
18855
18860
|
const limit = MAP_VIEW_LIMITS.targetText;
|
|
18856
18861
|
if (target.length <= limit) return target;
|
|
@@ -18906,8 +18911,9 @@ function pageBlocks(view, head, whole, offset, budget) {
|
|
|
18906
18911
|
return {
|
|
18907
18912
|
format: MAP_VIEW_FORMAT,
|
|
18908
18913
|
view,
|
|
18914
|
+
// Later pages continue a view the agent has already read, so only its title repeats.
|
|
18909
18915
|
text: [
|
|
18910
|
-
...head,
|
|
18916
|
+
...offset ? head.slice(0, 1) : head,
|
|
18911
18917
|
...blocks.slice(offset, end),
|
|
18912
18918
|
...more2 ? [`\u2026 ${blocks.length - end} more entries; continue with offset ${end}.`] : []
|
|
18913
18919
|
].join("\n"),
|
|
@@ -18918,7 +18924,7 @@ function pageBlocks(view, head, whole, offset, budget) {
|
|
|
18918
18924
|
if (offset === blocks.length) return materialize(0);
|
|
18919
18925
|
return mapQueryPage(blocks.length - offset, materialize, (page) => page, budget);
|
|
18920
18926
|
}
|
|
18921
|
-
var inModule = (
|
|
18927
|
+
var inModule = (path11, module) => module.direct ? parentDirectory(path11) === module.directory : within(path11, module.directory);
|
|
18922
18928
|
var moduleLabel = (module) => module.direct ? `${module.directory === "." ? "" : `${module.directory}/`}* (files directly here)` : `${module.directory}/`;
|
|
18923
18929
|
function childModules(module, files) {
|
|
18924
18930
|
if (module.direct) return [];
|
|
@@ -19000,7 +19006,8 @@ function loadDirectoryFacts(store, version2) {
|
|
|
19000
19006
|
const classes = declarations.filter((item) => item.kind === "CLASS").map((item) => item.ref);
|
|
19001
19007
|
const decoratorQuery = store.database.prepare(`SELECT from_ref,
|
|
19002
19008
|
json_extract(relation_json, '$.target') AS target,
|
|
19003
|
-
json_extract(relation_json, '$.argument') AS argument
|
|
19009
|
+
json_extract(relation_json, '$.argument') AS argument,
|
|
19010
|
+
json_extract(relation_json, '$.route') AS route
|
|
19004
19011
|
FROM project_map_relations WHERE version_ref = ?
|
|
19005
19012
|
AND from_ref IN (SELECT value FROM json_each(?))
|
|
19006
19013
|
AND json_extract(relation_json, '$.kind') = 'DECORATED_BY'`);
|
|
@@ -19011,7 +19018,11 @@ function loadDirectoryFacts(store, version2) {
|
|
|
19011
19018
|
))
|
|
19012
19019
|
decorators.set(String(row.from_ref), [
|
|
19013
19020
|
...decorators.get(String(row.from_ref)) ?? [],
|
|
19014
|
-
decoratorTag(
|
|
19021
|
+
decoratorTag(
|
|
19022
|
+
String(row.target),
|
|
19023
|
+
row.argument === null ? void 0 : String(row.argument),
|
|
19024
|
+
row.route === null ? void 0 : String(row.route)
|
|
19025
|
+
)
|
|
19015
19026
|
]);
|
|
19016
19027
|
const exported = /* @__PURE__ */ new Map();
|
|
19017
19028
|
for (const item of declarations) {
|
|
@@ -19066,12 +19077,12 @@ function loadMemberCalls(store, version2) {
|
|
|
19066
19077
|
FROM project_map_relations
|
|
19067
19078
|
WHERE version_ref = ? AND to_ref IS NULL AND json_extract(relation_json, '$.kind') = 'CALLS'
|
|
19068
19079
|
AND json_extract(relation_json, '$.unresolvedReason') IN ('SYMBOL_NOT_RESOLVED', 'SYNTAX_ONLY')`).all(version2)) {
|
|
19069
|
-
const
|
|
19080
|
+
const path11 = String(row.path);
|
|
19070
19081
|
const target = String(row.target);
|
|
19071
19082
|
const name = MEMBER_NAME.exec(target)?.[1];
|
|
19072
|
-
const language = mapLanguageOf(
|
|
19083
|
+
const language = mapLanguageOf(path11);
|
|
19073
19084
|
if (!name || !language) continue;
|
|
19074
|
-
const call = { from: String(row.from_ref), path:
|
|
19085
|
+
const call = { from: String(row.from_ref), path: path11, line: Number(row.line), target };
|
|
19075
19086
|
const key = memberKey(language, name);
|
|
19076
19087
|
const known = calls.get(key);
|
|
19077
19088
|
if (known) known.push(call);
|
|
@@ -19126,10 +19137,10 @@ function loadCoverageNotes(store, version2) {
|
|
|
19126
19137
|
if (!codes.includes(gap.code)) codes.push(gap.code);
|
|
19127
19138
|
files.set(gap.path, codes);
|
|
19128
19139
|
}
|
|
19129
|
-
for (const [
|
|
19140
|
+
for (const [path11, codes] of files)
|
|
19130
19141
|
if (codes.length > 1 && codes.includes("NOT_IN_PARSED_CONTEXT"))
|
|
19131
19142
|
files.set(
|
|
19132
|
-
|
|
19143
|
+
path11,
|
|
19133
19144
|
codes.filter((code) => code !== "NOT_IN_PARSED_CONTEXT")
|
|
19134
19145
|
);
|
|
19135
19146
|
return { files, limits: [...limits] };
|
|
@@ -19164,9 +19175,9 @@ function directoryView(facts, coverage, entries, input, directory, prefixes) {
|
|
|
19164
19175
|
const visiblePaths = new Set(visible.map((entry) => entry.path));
|
|
19165
19176
|
const code = visible.filter((entry) => entry.state === "TEXT" && mapCodePath(entry.path)).map((entry) => entry.path);
|
|
19166
19177
|
const modules = mapModules(directory, code);
|
|
19167
|
-
const moduleOf = (
|
|
19168
|
-
const outside = (
|
|
19169
|
-
const parts =
|
|
19178
|
+
const moduleOf = (path11) => modules.find((module) => inModule(path11, module));
|
|
19179
|
+
const outside = (path11) => {
|
|
19180
|
+
const parts = path11.split("/");
|
|
19170
19181
|
return `${parts.slice(0, Math.min(2, parts.length - 1)).join("/") || "."}/ (outside)`;
|
|
19171
19182
|
};
|
|
19172
19183
|
const moduleImports = /* @__PURE__ */ new Map();
|
|
@@ -19191,8 +19202,8 @@ function directoryView(facts, coverage, entries, input, directory, prefixes) {
|
|
|
19191
19202
|
const blocks = [];
|
|
19192
19203
|
if (modules.length > 1) {
|
|
19193
19204
|
const sizes = /* @__PURE__ */ new Map();
|
|
19194
|
-
for (const
|
|
19195
|
-
const module = moduleOf(
|
|
19205
|
+
for (const path11 of code) {
|
|
19206
|
+
const module = moduleOf(path11);
|
|
19196
19207
|
if (module) increment(sizes, moduleLabel(module));
|
|
19197
19208
|
}
|
|
19198
19209
|
blocks.push(
|
|
@@ -19221,18 +19232,18 @@ function directoryView(facts, coverage, entries, input, directory, prefixes) {
|
|
|
19221
19232
|
)}${packages.length > shown.length ? `, +${packages.length - shown.length} more` : ""}`
|
|
19222
19233
|
);
|
|
19223
19234
|
}
|
|
19224
|
-
const lineCount = (
|
|
19225
|
-
const file2 = facts.files.get(
|
|
19226
|
-
const gaps = coverage.files.get(
|
|
19235
|
+
const lineCount = (path11) => {
|
|
19236
|
+
const file2 = facts.files.get(path11);
|
|
19237
|
+
const gaps = coverage.files.get(path11) ?? [];
|
|
19227
19238
|
if (file2?.parsed === false) return `[not parsed${gaps.length ? `: ${gaps.join("; ")}` : ""}]`;
|
|
19228
19239
|
return `${file2 ? `${file2.lines}L` : "?L"}${gaps.length ? ` [${gaps.join("; ")}]` : ""}`;
|
|
19229
19240
|
};
|
|
19230
19241
|
const codeDirectories = /* @__PURE__ */ new Set();
|
|
19231
|
-
for (const
|
|
19232
|
-
for (let parent = parentDirectory(
|
|
19242
|
+
for (const path11 of code)
|
|
19243
|
+
for (let parent = parentDirectory(path11); parent !== "." && !codeDirectories.has(parent); parent = parentDirectory(parent))
|
|
19233
19244
|
codeDirectories.add(parent);
|
|
19234
|
-
const groupOf = (
|
|
19235
|
-
let group = parentDirectory(
|
|
19245
|
+
const groupOf = (path11) => {
|
|
19246
|
+
let group = parentDirectory(path11);
|
|
19236
19247
|
for (let parent = group; parent !== "." && parent !== directory && !codeDirectories.has(parent); parent = parentDirectory(parent))
|
|
19237
19248
|
group = parent;
|
|
19238
19249
|
return group;
|
|
@@ -19264,11 +19275,11 @@ function directoryView(facts, coverage, entries, input, directory, prefixes) {
|
|
|
19264
19275
|
]);
|
|
19265
19276
|
}
|
|
19266
19277
|
const detailed = [
|
|
19267
|
-
...code.map((
|
|
19268
|
-
const declarations = (facts.exported.get(
|
|
19278
|
+
...code.map((path11) => {
|
|
19279
|
+
const declarations = (facts.exported.get(path11) ?? []).map(({ text: text2 }) => text2);
|
|
19269
19280
|
return [
|
|
19270
|
-
|
|
19271
|
-
`${
|
|
19281
|
+
path11,
|
|
19282
|
+
`${path11} ${lineCount(path11)}${declarations.length ? `: ${declarations.join(", ")}` : ""}`
|
|
19272
19283
|
];
|
|
19273
19284
|
}),
|
|
19274
19285
|
...listedOther.map((entry) => [
|
|
@@ -19279,7 +19290,7 @@ function directoryView(facts, coverage, entries, input, directory, prefixes) {
|
|
|
19279
19290
|
];
|
|
19280
19291
|
const directories = /* @__PURE__ */ new Map();
|
|
19281
19292
|
for (const entry of [
|
|
19282
|
-
...code.map((
|
|
19293
|
+
...code.map((path11) => ({ path: path11, item: lineCount(path11) })),
|
|
19283
19294
|
...listedOther.map((entry2) => ({
|
|
19284
19295
|
path: entry2.path,
|
|
19285
19296
|
item: entry2.state === "TEXT" ? "" : `(${entry2.state})`
|
|
@@ -19307,10 +19318,10 @@ function directoryView(facts, coverage, entries, input, directory, prefixes) {
|
|
|
19307
19318
|
);
|
|
19308
19319
|
const text = visible.filter((entry) => entry.state === "TEXT").length;
|
|
19309
19320
|
const resolution = /* @__PURE__ */ new Map();
|
|
19310
|
-
for (const
|
|
19311
|
-
const counts = facts.calls.get(
|
|
19321
|
+
for (const path11 of code) {
|
|
19322
|
+
const counts = facts.calls.get(path11);
|
|
19312
19323
|
if (!counts) continue;
|
|
19313
|
-
const language = facts.files.get(
|
|
19324
|
+
const language = facts.files.get(path11)?.language ?? "unknown";
|
|
19314
19325
|
const total = resolution.get(language) ?? { resolved: 0, unresolved: 0, external: 0 };
|
|
19315
19326
|
total.resolved += counts.resolved;
|
|
19316
19327
|
total.unresolved += counts.unresolved;
|
|
@@ -19324,7 +19335,7 @@ function directoryView(facts, coverage, entries, input, directory, prefixes) {
|
|
|
19324
19335
|
});
|
|
19325
19336
|
const head = [
|
|
19326
19337
|
`PROJECT MAP \xB7 DIRECTORY ${directory} \xB7 ${code.length} code files \xB7 ${text - code.length} other text files${visible.length > text ? ` \xB7 ${visible.length - text} unreadable entries` : ""}${hiddenTests ? ` \xB7 ${hiddenTests} test files hidden (includeTests)` : ""}${prefixes.includes(".") ? "" : " \xB7 limited to authorized paths"}`,
|
|
19327
|
-
tier === "DETAILED" ?
|
|
19338
|
+
tier === "DETAILED" ? "Code files list line count and exported declarations; other files show size." : tier === "COMPACT" ? "File lines give a directory, then its files with line counts; join them for a path. Declarations are omitted to keep this overview small: open a file, or a directory with fewer files, to see them." : "Files are omitted because this directory is large: open a module directory to list its files.",
|
|
19328
19339
|
...rates.length ? [
|
|
19329
19340
|
`Static calls linked to project declarations: ${rates.join(", ")}; the rest have a callee of unknown type, such as a value from a package whose types are not loaded. ${externalCalls} calls into the standard library or into packages that are not loaded are not counted.`
|
|
19330
19341
|
] : [],
|
|
@@ -19353,8 +19364,7 @@ var INCOMING = {
|
|
|
19353
19364
|
DECORATED_BY: "decorates"
|
|
19354
19365
|
};
|
|
19355
19366
|
var IMPORT_KINDS = /* @__PURE__ */ new Set(["IMPORTS", "TEST_IMPORTS"]);
|
|
19356
|
-
var callerCoverage = (textSearch) => `
|
|
19357
|
-
var DISPATCH_LEGEND = "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.";
|
|
19367
|
+
var callerCoverage = (textSearch) => `Calls through dependency injection, framework routing, reflection or computed names are not mapped, so a complete view is not a complete caller list; confirm impact with project_find_references or ${textSearch}.`;
|
|
19358
19368
|
var SPECIAL_METHOD = /^__\w+__$/u;
|
|
19359
19369
|
var DeclarationGroups = class {
|
|
19360
19370
|
constructor(graph, input, prefixes, showTests, memberCalls) {
|
|
@@ -19369,8 +19379,8 @@ var DeclarationGroups = class {
|
|
|
19369
19379
|
prefixes;
|
|
19370
19380
|
showTests;
|
|
19371
19381
|
memberCalls;
|
|
19372
|
-
visible(
|
|
19373
|
-
return mapPathAllowed(
|
|
19382
|
+
visible(path11) {
|
|
19383
|
+
return mapPathAllowed(path11, this.prefixes) && (this.showTests || !mapTestPath(path11));
|
|
19374
19384
|
}
|
|
19375
19385
|
entry(object2, imported = false) {
|
|
19376
19386
|
if (mapIsModule(object2)) return imported ? "(file)" : "(module scope)";
|
|
@@ -19414,11 +19424,11 @@ var DeclarationGroups = class {
|
|
|
19414
19424
|
value.lines.push(line);
|
|
19415
19425
|
aggregates.set(key, value);
|
|
19416
19426
|
};
|
|
19417
|
-
const dispatch = (arrow, label, ref2,
|
|
19427
|
+
const dispatch = (arrow, label, ref2, path11, line) => {
|
|
19418
19428
|
const other = graph.object(graph.owner(ref2));
|
|
19419
19429
|
if (owned.has(other.id)) return;
|
|
19420
|
-
if (!this.visible(
|
|
19421
|
-
if (mapPathAllowed(
|
|
19430
|
+
if (!this.visible(path11)) {
|
|
19431
|
+
if (mapPathAllowed(path11, this.prefixes)) omittedTests++;
|
|
19422
19432
|
return;
|
|
19423
19433
|
}
|
|
19424
19434
|
add(arrow, label, other, line);
|
|
@@ -19437,6 +19447,11 @@ var DeclarationGroups = class {
|
|
|
19437
19447
|
}
|
|
19438
19448
|
continue;
|
|
19439
19449
|
}
|
|
19450
|
+
if (!outgoing && relation.kind === "DECORATED_BY") {
|
|
19451
|
+
const name = relation.to === void 0 ? relation.target : graph.qualifiedName(graph.owner(relation.to));
|
|
19452
|
+
tags.push(decoratorTag(name, relation.argument, relation.route));
|
|
19453
|
+
continue;
|
|
19454
|
+
}
|
|
19440
19455
|
if (!outgoing || relation.kind === "CONTAINS") continue;
|
|
19441
19456
|
const reason = relation.kind === "CALLS" ? this.stop(relation) : void 0;
|
|
19442
19457
|
if (reason) {
|
|
@@ -19450,7 +19465,7 @@ var DeclarationGroups = class {
|
|
|
19450
19465
|
if (IMPORT_KINDS.has(relation.kind) && mapIsModule(graph.object(relation.from))) continue;
|
|
19451
19466
|
if (relation.to === void 0) {
|
|
19452
19467
|
if (relation.kind === "DECORATED_BY")
|
|
19453
|
-
tags.push(decoratorTag(relation.target, relation.argument));
|
|
19468
|
+
tags.push(decoratorTag(relation.target, relation.argument, relation.route));
|
|
19454
19469
|
else if (relation.kind === "EXTENDS" || relation.kind === "IMPLEMENTS")
|
|
19455
19470
|
tags.push(`${relation.kind.toLowerCase()} ${relation.target}`);
|
|
19456
19471
|
else {
|
|
@@ -19471,7 +19486,7 @@ var DeclarationGroups = class {
|
|
|
19471
19486
|
continue;
|
|
19472
19487
|
}
|
|
19473
19488
|
if (relation.kind === "DECORATED_BY")
|
|
19474
|
-
tags.push(decoratorTag(graph.qualifiedName(other.id), relation.argument));
|
|
19489
|
+
tags.push(decoratorTag(graph.qualifiedName(other.id), relation.argument, relation.route));
|
|
19475
19490
|
else if (relation.kind === "EXTENDS" || relation.kind === "IMPLEMENTS")
|
|
19476
19491
|
tags.push(`${relation.kind.toLowerCase()} ${graph.qualifiedName(other.id)}`);
|
|
19477
19492
|
else
|
|
@@ -19570,7 +19585,7 @@ var DeclarationGroups = class {
|
|
|
19570
19585
|
else files2.set(call.path, [item]);
|
|
19571
19586
|
}
|
|
19572
19587
|
lines.push(
|
|
19573
|
-
` \u2190 possible callers by name: ${[...files2].map(([
|
|
19588
|
+
` \u2190 possible callers by name: ${[...files2].map(([path11, items]) => `${path11}: ${items.join(", ")}`).join("; ")}${inTests}`
|
|
19574
19589
|
);
|
|
19575
19590
|
} else if (possibleInTests)
|
|
19576
19591
|
lines.push(` \u2190 possible callers by name: ${possibleInTests} in test files (includeTests)`);
|
|
@@ -19606,15 +19621,14 @@ var DeclarationGroups = class {
|
|
|
19606
19621
|
return { lines, neighbors: [...new Set(neighbors)] };
|
|
19607
19622
|
}
|
|
19608
19623
|
};
|
|
19609
|
-
function fileView(store, coverage, graph, input,
|
|
19610
|
-
const entry = store.getEntry(input.version,
|
|
19611
|
-
if (!entry || !mapPathAllowed(
|
|
19612
|
-
const showTests = input.includeTests === true || mapTestPath(
|
|
19613
|
-
const module = mapCodePath(
|
|
19614
|
-
const gaps = coverage.files.get(
|
|
19624
|
+
function fileView(store, coverage, graph, input, path11, prefixes) {
|
|
19625
|
+
const entry = store.getEntry(input.version, path11);
|
|
19626
|
+
if (!entry || !mapPathAllowed(path11, prefixes)) return notFound();
|
|
19627
|
+
const showTests = input.includeTests === true || mapTestPath(path11);
|
|
19628
|
+
const module = mapCodePath(path11) ? graph.objectsAt(path11).find((object2) => mapIsModule(object2)) : void 0;
|
|
19629
|
+
const gaps = coverage.files.get(path11) ?? [];
|
|
19615
19630
|
const head = [
|
|
19616
|
-
`PROJECT MAP \xB7 FILE ${
|
|
19617
|
-
LEGEND
|
|
19631
|
+
`PROJECT MAP \xB7 FILE ${path11} \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`}`
|
|
19618
19632
|
];
|
|
19619
19633
|
if (!module || entry.state !== "TEXT")
|
|
19620
19634
|
return pageBlocks("FILE", head, [], input.offset ?? 0, input.outputBudget);
|
|
@@ -19629,12 +19643,12 @@ function fileView(store, coverage, graph, input, path10, prefixes) {
|
|
|
19629
19643
|
if (!["DECORATED_BY", "EXTENDS", "IMPLEMENTS"].includes(relation.kind)) continue;
|
|
19630
19644
|
const list = tags.get(relation.from) ?? [];
|
|
19631
19645
|
list.push(
|
|
19632
|
-
relation.kind === "DECORATED_BY" ? decoratorTag(relation.target, relation.argument) : `${relation.kind.toLowerCase()} ${relation.target}`
|
|
19646
|
+
relation.kind === "DECORATED_BY" ? decoratorTag(relation.target, relation.argument, relation.route) : `${relation.kind.toLowerCase()} ${relation.target}`
|
|
19633
19647
|
);
|
|
19634
19648
|
tags.set(relation.from, list);
|
|
19635
19649
|
}
|
|
19636
19650
|
const describe3 = (object2) => [
|
|
19637
|
-
`${object2.name} ${mapDeclarationLabel(object2)}${object2.anchor.path ===
|
|
19651
|
+
`${object2.name} ${mapDeclarationLabel(object2)}${object2.anchor.path === path11 ? "" : ` (${object2.anchor.path})`}`,
|
|
19638
19652
|
...tags.get(object2.id) ?? []
|
|
19639
19653
|
].join(" ");
|
|
19640
19654
|
const declarations = [];
|
|
@@ -19649,11 +19663,11 @@ function fileView(store, coverage, graph, input, path10, prefixes) {
|
|
|
19649
19663
|
);
|
|
19650
19664
|
}
|
|
19651
19665
|
const elsewhere = /* @__PURE__ */ new Map();
|
|
19652
|
-
for (const object2 of graph.objectsAt(
|
|
19666
|
+
for (const object2 of graph.objectsAt(path11)) {
|
|
19653
19667
|
const parent = mapIsModule(object2) ? void 0 : graph.parent(object2.id);
|
|
19654
19668
|
if (parent === void 0 || !graph.isAddressable(object2)) continue;
|
|
19655
19669
|
const container = graph.object(parent);
|
|
19656
|
-
if (mapIsModule(container) || container.anchor.path ===
|
|
19670
|
+
if (mapIsModule(container) || container.anchor.path === path11) continue;
|
|
19657
19671
|
const into = elsewhere.get(parent);
|
|
19658
19672
|
if (into) into.push(object2);
|
|
19659
19673
|
else elsewhere.set(parent, [object2]);
|
|
@@ -19667,7 +19681,7 @@ function fileView(store, coverage, graph, input, path10, prefixes) {
|
|
|
19667
19681
|
if (declarations.length) blocks.push(["DECLARATIONS (* exported)", ...declarations].join("\n"));
|
|
19668
19682
|
const imports = /* @__PURE__ */ new Set();
|
|
19669
19683
|
const external = /* @__PURE__ */ new Set();
|
|
19670
|
-
const fileObjects = graph.objectsAt(
|
|
19684
|
+
const fileObjects = graph.objectsAt(path11).map((object2) => object2.id);
|
|
19671
19685
|
for (const relation of graph.relationsFrom(fileObjects)) {
|
|
19672
19686
|
if (!IMPORT_KINDS.has(relation.kind)) continue;
|
|
19673
19687
|
if (relation.to === void 0) external.add(relation.target);
|
|
@@ -19678,8 +19692,8 @@ function fileView(store, coverage, graph, input, path10, prefixes) {
|
|
|
19678
19692
|
}
|
|
19679
19693
|
const importers = /* @__PURE__ */ new Set();
|
|
19680
19694
|
const testImporters = /* @__PURE__ */ new Set();
|
|
19681
|
-
const imported = mapImportTarget(
|
|
19682
|
-
const packageModules = imported ===
|
|
19695
|
+
const imported = mapImportTarget(path11);
|
|
19696
|
+
const packageModules = imported === path11 ? [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);
|
|
19683
19697
|
for (const relation of graph.relationsTo(packageModules)) {
|
|
19684
19698
|
if (!IMPORT_KINDS.has(relation.kind)) continue;
|
|
19685
19699
|
const source = relation.anchor.path;
|
|
@@ -19707,16 +19721,16 @@ function fileView(store, coverage, graph, input, path10, prefixes) {
|
|
|
19707
19721
|
if (scope.length) blocks.push(["MODULE SCOPE (top-level statements)", ...scope].join("\n"));
|
|
19708
19722
|
return pageBlocks("FILE", head, blocks, input.offset ?? 0, input.outputBudget);
|
|
19709
19723
|
}
|
|
19710
|
-
function declarationView(graph, input,
|
|
19724
|
+
function declarationView(graph, input, path11, prefixes, memberCalls) {
|
|
19711
19725
|
const requested = input.depth ?? 1;
|
|
19712
19726
|
if (!Number.isSafeInteger(requested) || requested < 1 || requested > MAP_VIEW_LIMITS.directedDepth)
|
|
19713
19727
|
return invalid2();
|
|
19714
19728
|
const both = (input.direction ?? "BOTH") === "BOTH";
|
|
19715
19729
|
const depth = both ? Math.min(requested, MAP_VIEW_LIMITS.bothDepth) : requested;
|
|
19716
19730
|
const { name, line } = input;
|
|
19717
|
-
const selected = mapSelectDeclarations(graph,
|
|
19731
|
+
const selected = mapSelectDeclarations(graph, path11, name, line);
|
|
19718
19732
|
if (!selected.length) return notFound();
|
|
19719
|
-
const showTests = input.includeTests === true || mapTestPath(
|
|
19733
|
+
const showTests = input.includeTests === true || mapTestPath(path11);
|
|
19720
19734
|
const groups = new DeclarationGroups(graph, input, prefixes, showTests, memberCalls);
|
|
19721
19735
|
const blocks = [];
|
|
19722
19736
|
const seen = /* @__PURE__ */ new Set();
|
|
@@ -19764,8 +19778,8 @@ function declarationView(graph, input, path10, prefixes, memberCalls) {
|
|
|
19764
19778
|
);
|
|
19765
19779
|
}
|
|
19766
19780
|
const head = [
|
|
19767
|
-
`PROJECT MAP \xB7 DECLARATION ${
|
|
19768
|
-
|
|
19781
|
+
`PROJECT MAP \xB7 DECLARATION ${path11}${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"}`,
|
|
19782
|
+
...truncated ? [`Expansion stopped at ${MAP_VIEW_LIMITS.declarations} declarations.`] : [],
|
|
19769
19783
|
...(input.direction ?? "BOTH") === "OUTGOING" ? [] : [callerCoverage(input.textSearch ?? DEFAULT_TEXT_SEARCH)]
|
|
19770
19784
|
];
|
|
19771
19785
|
return pageBlocks("DECLARATION", head, blocks, input.offset ?? 0, input.outputBudget);
|
|
@@ -19889,10 +19903,10 @@ var ProjectMapQuery = class {
|
|
|
19889
19903
|
view(input, signal) {
|
|
19890
19904
|
this.requireReadableMap(input.version, signal);
|
|
19891
19905
|
const { offset, prefixes } = admission(input);
|
|
19892
|
-
const
|
|
19906
|
+
const path11 = normalizeProjectEvidencePath(input.path, true) || ".";
|
|
19893
19907
|
const view = mapView(
|
|
19894
19908
|
this.store,
|
|
19895
|
-
{ ...input, path:
|
|
19909
|
+
{ ...input, path: path11, offset, allowedPathPrefixes: prefixes },
|
|
19896
19910
|
this.views
|
|
19897
19911
|
);
|
|
19898
19912
|
if (signal.aborted) throw new ProjectEvidenceError("PROJECT_READ_CANCELLED", true);
|
|
@@ -20797,7 +20811,7 @@ var CodeIndexStore = class {
|
|
|
20797
20811
|
const staged = this.stageUnits(buildRef, paths, linked);
|
|
20798
20812
|
const reused = linked ? this.database.prepare(`SELECT path, unit_ref FROM project_map_version_units
|
|
20799
20813
|
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) })) : [];
|
|
20800
|
-
if (reused.length !== (linked?.paths.size ?? 0) || reused.some(({ path:
|
|
20814
|
+
if (reused.length !== (linked?.paths.size ?? 0) || reused.some(({ path: path11 }) => !paths.has(path11)) || staged.some(({ path: path11 }) => linked?.paths.has(path11)))
|
|
20801
20815
|
throw new MapReplayConflict();
|
|
20802
20816
|
const units = [...staged, ...reused].sort(
|
|
20803
20817
|
(left, right) => left.path < right.path ? -1 : left.path > right.path ? 1 : 0
|
|
@@ -20848,7 +20862,7 @@ var CodeIndexStore = class {
|
|
|
20848
20862
|
const member = this.database.prepare(
|
|
20849
20863
|
"INSERT INTO project_map_version_units VALUES (?, ?, ?)"
|
|
20850
20864
|
);
|
|
20851
|
-
for (const { path:
|
|
20865
|
+
for (const { path: path11, unit } of reused) member.run(version2.version, path11, unit);
|
|
20852
20866
|
this.database.prepare("INSERT INTO project_map_coverage VALUES (?, ?)").run(version2.version, canonicalJson(coverage));
|
|
20853
20867
|
}
|
|
20854
20868
|
this.database.exec("COMMIT");
|
|
@@ -20912,7 +20926,7 @@ var CodeIndexStore = class {
|
|
|
20912
20926
|
corrupt2();
|
|
20913
20927
|
}
|
|
20914
20928
|
if (linked) {
|
|
20915
|
-
const unlinked = database.prepare("SELECT path FROM project_map_version_units WHERE version_ref = ?").all(linked.version).map((row) => String(row.path)).filter((
|
|
20929
|
+
const unlinked = database.prepare("SELECT path FROM project_map_version_units WHERE version_ref = ?").all(linked.version).map((row) => String(row.path)).filter((path11) => !linked.paths.has(path11));
|
|
20916
20930
|
if (database.prepare(`SELECT 1 FROM project_map_objects gone
|
|
20917
20931
|
WHERE gone.version_ref = ? AND gone.path IN (SELECT value FROM json_each(?))
|
|
20918
20932
|
AND gone.entity_ref NOT IN (SELECT entity_ref FROM project_map_publish_objects)
|
|
@@ -20937,17 +20951,17 @@ var CodeIndexStore = class {
|
|
|
20937
20951
|
const units = [];
|
|
20938
20952
|
for (const row of database.prepare(`SELECT path FROM project_map_publish_objects
|
|
20939
20953
|
UNION SELECT path FROM project_map_publish_relations ORDER BY path`).all()) {
|
|
20940
|
-
const
|
|
20941
|
-
const hash2 = createHash3("sha256").update(
|
|
20954
|
+
const path11 = String(row.path);
|
|
20955
|
+
const hash2 = createHash3("sha256").update(path11).update("\0");
|
|
20942
20956
|
for (const [mark, statement] of [
|
|
20943
20957
|
["object", objects2],
|
|
20944
20958
|
["relation", relations],
|
|
20945
20959
|
["note", pathNotes]
|
|
20946
20960
|
])
|
|
20947
|
-
for (const fact of statement.all(
|
|
20961
|
+
for (const fact of statement.all(path11))
|
|
20948
20962
|
for (const value of Object.values(fact))
|
|
20949
20963
|
hash2.update(mark).update("\0").update(String(value)).update("\0");
|
|
20950
|
-
units.push({ path:
|
|
20964
|
+
units.push({ path: path11, unit: hash2.digest("hex") });
|
|
20951
20965
|
}
|
|
20952
20966
|
return units;
|
|
20953
20967
|
}
|
|
@@ -20965,13 +20979,13 @@ var CodeIndexStore = class {
|
|
|
20965
20979
|
"INSERT INTO project_map_unit_notes SELECT ?, * FROM project_map_publish_notes WHERE path = ?"
|
|
20966
20980
|
);
|
|
20967
20981
|
const member = database.prepare("INSERT INTO project_map_version_units VALUES (?, ?, ?)");
|
|
20968
|
-
for (const { path:
|
|
20969
|
-
if (insertUnit.run(unit,
|
|
20970
|
-
unitObjects.run(unit,
|
|
20971
|
-
unitRelations.run(unit,
|
|
20972
|
-
unitNotes.run(unit,
|
|
20982
|
+
for (const { path: path11, unit } of units) {
|
|
20983
|
+
if (insertUnit.run(unit, path11).changes) {
|
|
20984
|
+
unitObjects.run(unit, path11);
|
|
20985
|
+
unitRelations.run(unit, path11);
|
|
20986
|
+
unitNotes.run(unit, path11);
|
|
20973
20987
|
}
|
|
20974
|
-
member.run(version2,
|
|
20988
|
+
member.run(version2, path11, unit);
|
|
20975
20989
|
}
|
|
20976
20990
|
}
|
|
20977
20991
|
/** Earlier versions of a project's scope built by the same analyzer, most recent first. */
|
|
@@ -21212,21 +21226,21 @@ var contextFiles = (context) => [
|
|
|
21212
21226
|
function replayableContexts(parent, digests) {
|
|
21213
21227
|
const sharing = /* @__PURE__ */ new Map();
|
|
21214
21228
|
for (const [ref, { context }] of parent.contexts)
|
|
21215
|
-
for (const
|
|
21216
|
-
const refs = sharing.get(
|
|
21229
|
+
for (const path11 of contextFiles(context)) {
|
|
21230
|
+
const refs = sharing.get(path11) ?? /* @__PURE__ */ new Set();
|
|
21217
21231
|
refs.add(ref);
|
|
21218
|
-
sharing.set(
|
|
21232
|
+
sharing.set(path11, refs);
|
|
21219
21233
|
}
|
|
21220
21234
|
const unchanged = /* @__PURE__ */ new Set();
|
|
21221
21235
|
for (const [ref, { context }] of parent.contexts)
|
|
21222
21236
|
if (contextFiles(context).every(
|
|
21223
|
-
(
|
|
21237
|
+
(path11) => digests.get(path11) !== void 0 && digests.get(path11) === parent.entries.get(path11)
|
|
21224
21238
|
))
|
|
21225
21239
|
unchanged.add(ref);
|
|
21226
21240
|
const replayable = /* @__PURE__ */ new Set();
|
|
21227
21241
|
for (const [ref, { context }] of parent.contexts)
|
|
21228
21242
|
if (unchanged.has(ref) && contextFiles(context).every(
|
|
21229
|
-
(
|
|
21243
|
+
(path11) => [...sharing.get(path11) ?? []].every((other) => unchanged.has(other))
|
|
21230
21244
|
))
|
|
21231
21245
|
replayable.add(ref);
|
|
21232
21246
|
return { replayable, sharing };
|
|
@@ -21259,8 +21273,8 @@ var ProjectMapAnalyzer = class {
|
|
|
21259
21273
|
languages;
|
|
21260
21274
|
observe;
|
|
21261
21275
|
id;
|
|
21262
|
-
claims(
|
|
21263
|
-
return this.languages.some((language) => language.claims(
|
|
21276
|
+
claims(path11) {
|
|
21277
|
+
return this.languages.some((language) => language.claims(path11));
|
|
21264
21278
|
}
|
|
21265
21279
|
references(input, reference, signal) {
|
|
21266
21280
|
const language = this.languages.find((language2) => language2.claims(reference.targetPath));
|
|
@@ -21300,7 +21314,7 @@ var ProjectMapAnalyzer = class {
|
|
|
21300
21314
|
const reuse = (contextRef2, request, files2) => {
|
|
21301
21315
|
const digest = digestValue({
|
|
21302
21316
|
request,
|
|
21303
|
-
files: files2.map((
|
|
21317
|
+
files: files2.map((path11) => [path11, digests.get(path11) ?? null])
|
|
21304
21318
|
});
|
|
21305
21319
|
requests.set(contextRef2, digest);
|
|
21306
21320
|
if (!parent || !replayable.has(contextRef2)) return void 0;
|
|
@@ -21340,7 +21354,7 @@ var ProjectMapAnalyzer = class {
|
|
|
21340
21354
|
const ref = analysis.contexts[0]?.ref ?? "";
|
|
21341
21355
|
if (options?.linked?.length) {
|
|
21342
21356
|
if (!parent || analysis.contexts.length !== 1) return invalidParent();
|
|
21343
|
-
for (const
|
|
21357
|
+
for (const path11 of options.linked) linked.add(path11);
|
|
21344
21358
|
this.observe?.({
|
|
21345
21359
|
operation: "LINK",
|
|
21346
21360
|
phase: "FINISHED",
|
|
@@ -21367,7 +21381,7 @@ var ProjectMapAnalyzer = class {
|
|
|
21367
21381
|
});
|
|
21368
21382
|
for (const file2 of analysis.parsedFiles) parsed.add(file2);
|
|
21369
21383
|
const staged = factPaths(analysis);
|
|
21370
|
-
for (const
|
|
21384
|
+
for (const path11 of staged) stagedPaths.add(path11);
|
|
21371
21385
|
for (const context of analysis.contexts) {
|
|
21372
21386
|
for (const file2 of context.configurationFiles) configurationInputs.add(file2);
|
|
21373
21387
|
if (!replayed.has(context.ref))
|
|
@@ -21396,7 +21410,7 @@ var ProjectMapAnalyzer = class {
|
|
|
21396
21410
|
accept,
|
|
21397
21411
|
reuse,
|
|
21398
21412
|
previous,
|
|
21399
|
-
configuration: (
|
|
21413
|
+
configuration: (path11) => configurationInputs.add(path11),
|
|
21400
21414
|
observe: this.observe
|
|
21401
21415
|
},
|
|
21402
21416
|
signal
|
|
@@ -21433,12 +21447,12 @@ var ProjectMapAnalyzer = class {
|
|
|
21433
21447
|
if (files.objects.length) accept(files);
|
|
21434
21448
|
if (parent && (replayed.size || linked.size)) {
|
|
21435
21449
|
for (const ref of replayed.keys())
|
|
21436
|
-
for (const
|
|
21437
|
-
if (analyzedFiles.has(
|
|
21450
|
+
for (const path11 of contextFiles(parent.contexts.get(ref)?.context ?? invalidParent()))
|
|
21451
|
+
if (analyzedFiles.has(path11) || [...sharing.get(path11) ?? []].some((other) => !replayed.has(other)))
|
|
21438
21452
|
throw new MapReplayConflict();
|
|
21439
|
-
for (const paths of replayed.values()) for (const
|
|
21440
|
-
for (const
|
|
21441
|
-
if (analyzedFiles.has(
|
|
21453
|
+
for (const paths of replayed.values()) for (const path11 of paths) linked.add(path11);
|
|
21454
|
+
for (const path11 of linked)
|
|
21455
|
+
if (analyzedFiles.has(path11) || stagedPaths.has(path11)) throw new MapReplayConflict();
|
|
21442
21456
|
parent.link([...linked]);
|
|
21443
21457
|
}
|
|
21444
21458
|
result.parsedFiles = [...parsed].sort();
|
|
@@ -21728,8 +21742,8 @@ var CodeIndex = class {
|
|
|
21728
21742
|
for (const entry of this.store.listEntries(candidate))
|
|
21729
21743
|
if (entry.contentDigest) entries2.set(entry.path, entry.contentDigest);
|
|
21730
21744
|
let changed = 0;
|
|
21731
|
-
for (const [
|
|
21732
|
-
for (const
|
|
21745
|
+
for (const [path11, digest] of digests) if (entries2.get(path11) !== digest) changed++;
|
|
21746
|
+
for (const path11 of entries2.keys()) if (!digests.has(path11)) changed++;
|
|
21733
21747
|
if (!best || changed < best.changed) best = { version: candidate, entries: entries2, changed };
|
|
21734
21748
|
}
|
|
21735
21749
|
if (!best) return void 0;
|
|
@@ -21867,11 +21881,596 @@ var CodeIndex = class {
|
|
|
21867
21881
|
}
|
|
21868
21882
|
};
|
|
21869
21883
|
|
|
21884
|
+
// src/project-map-changes.ts
|
|
21885
|
+
import { readFileSync as readFileSync2 } from "node:fs";
|
|
21886
|
+
import path7 from "node:path";
|
|
21887
|
+
var git = new GitRunner();
|
|
21888
|
+
var gitOptions = (cwd, signal) => ({
|
|
21889
|
+
cwd,
|
|
21890
|
+
signal,
|
|
21891
|
+
timeoutMs: 6e4,
|
|
21892
|
+
maxOutputBytes: 64 * 1024 * 1024
|
|
21893
|
+
});
|
|
21894
|
+
var EVERYTHING = [1, Number.MAX_SAFE_INTEGER];
|
|
21895
|
+
async function resolveMapBase(project, base, signal) {
|
|
21896
|
+
if (!/^[\w./@^~-]{1,200}$/u.test(base) || base.startsWith("-"))
|
|
21897
|
+
throw new ProjectEvidenceError("LAYERMAP_BASE_INVALID", false);
|
|
21898
|
+
let commit;
|
|
21899
|
+
try {
|
|
21900
|
+
commit = (await git.run(
|
|
21901
|
+
["rev-parse", "--verify", "--quiet", `${base}^{commit}`],
|
|
21902
|
+
gitOptions(project, signal)
|
|
21903
|
+
)).stdout.toString().trim();
|
|
21904
|
+
} catch {
|
|
21905
|
+
throw new ProjectEvidenceError("LAYERMAP_BASE_NOT_FOUND", false);
|
|
21906
|
+
}
|
|
21907
|
+
if (!/^[a-f0-9]{40,64}$/u.test(commit))
|
|
21908
|
+
throw new ProjectEvidenceError("LAYERMAP_BASE_NOT_FOUND", false);
|
|
21909
|
+
return commit;
|
|
21910
|
+
}
|
|
21911
|
+
async function readMapChanges(project, base, signal) {
|
|
21912
|
+
const commit = await resolveMapBase(project, base, signal);
|
|
21913
|
+
const diff = (await git.run(
|
|
21914
|
+
[
|
|
21915
|
+
"-c",
|
|
21916
|
+
"core.quotePath=false",
|
|
21917
|
+
"diff",
|
|
21918
|
+
"--no-ext-diff",
|
|
21919
|
+
"--no-textconv",
|
|
21920
|
+
"--no-color",
|
|
21921
|
+
"--src-prefix=a/",
|
|
21922
|
+
"--dst-prefix=b/",
|
|
21923
|
+
"--unified=0",
|
|
21924
|
+
"-M",
|
|
21925
|
+
commit,
|
|
21926
|
+
"--"
|
|
21927
|
+
],
|
|
21928
|
+
gitOptions(project, signal)
|
|
21929
|
+
)).stdout.toString("utf8");
|
|
21930
|
+
const files = parseMapDiff(diff);
|
|
21931
|
+
const untracked = (await git.run(["ls-files", "--others", "--exclude-standard", "-z"], gitOptions(project, signal))).stdout.toString("utf8").split("\0").filter(Boolean);
|
|
21932
|
+
for (const path11 of untracked)
|
|
21933
|
+
files.push({ path: path11, status: "ADDED", lines: [EVERYTHING], baseLines: [], binary: false });
|
|
21934
|
+
return { base, commit, files };
|
|
21935
|
+
}
|
|
21936
|
+
function parseMapDiff(text) {
|
|
21937
|
+
const files = [];
|
|
21938
|
+
let current;
|
|
21939
|
+
const finish = () => {
|
|
21940
|
+
if (!current) return;
|
|
21941
|
+
if (!current.path.startsWith('"')) files.push(current);
|
|
21942
|
+
current = void 0;
|
|
21943
|
+
};
|
|
21944
|
+
for (const line of text.split("\n")) {
|
|
21945
|
+
if (line.startsWith("diff --git ")) {
|
|
21946
|
+
finish();
|
|
21947
|
+
const match = /^diff --git a\/(.+) b\/(.+)$/u.exec(line);
|
|
21948
|
+
current = {
|
|
21949
|
+
path: match?.[2] ?? "",
|
|
21950
|
+
basePath: match?.[1] ?? "",
|
|
21951
|
+
status: "MODIFIED",
|
|
21952
|
+
lines: [],
|
|
21953
|
+
baseLines: [],
|
|
21954
|
+
binary: false
|
|
21955
|
+
};
|
|
21956
|
+
continue;
|
|
21957
|
+
}
|
|
21958
|
+
if (!current) continue;
|
|
21959
|
+
if (line.startsWith("new file mode")) {
|
|
21960
|
+
current.status = "ADDED";
|
|
21961
|
+
current.basePath = void 0;
|
|
21962
|
+
} else if (line.startsWith("deleted file mode")) {
|
|
21963
|
+
current.status = "DELETED";
|
|
21964
|
+
current.path = current.basePath ?? current.path;
|
|
21965
|
+
} else if (line.startsWith("rename from ")) {
|
|
21966
|
+
current.status = "RENAMED";
|
|
21967
|
+
current.basePath = line.slice("rename from ".length);
|
|
21968
|
+
} else if (line.startsWith("rename to ")) current.path = line.slice("rename to ".length);
|
|
21969
|
+
else if (line.startsWith("Binary files ")) current.binary = true;
|
|
21970
|
+
else if (line.startsWith("@@ ")) {
|
|
21971
|
+
const hunk = /^@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@/u.exec(line);
|
|
21972
|
+
if (!hunk) continue;
|
|
21973
|
+
const [oldStart, oldCount, newStart, newCount] = [
|
|
21974
|
+
Number(hunk[1]),
|
|
21975
|
+
hunk[2] === void 0 ? 1 : Number(hunk[2]),
|
|
21976
|
+
Number(hunk[3]),
|
|
21977
|
+
hunk[4] === void 0 ? 1 : Number(hunk[4])
|
|
21978
|
+
];
|
|
21979
|
+
if (oldCount > 0) current.baseLines.push([oldStart, oldStart + oldCount - 1]);
|
|
21980
|
+
current.lines.push(
|
|
21981
|
+
newCount > 0 ? [newStart, newStart + newCount - 1] : [Math.max(newStart, 1), newStart + 1]
|
|
21982
|
+
);
|
|
21983
|
+
}
|
|
21984
|
+
}
|
|
21985
|
+
finish();
|
|
21986
|
+
return files;
|
|
21987
|
+
}
|
|
21988
|
+
var testCode = (file2) => mapTestPath(file2) || /(?:^|\/)testFixtures\//u.test(file2);
|
|
21989
|
+
var overlaps = (lines, start, end) => lines.some(([from, to]) => from <= end && start <= to);
|
|
21990
|
+
var NON_CODE = [
|
|
21991
|
+
[
|
|
21992
|
+
/(?:^|\/)(?:package-lock\.json|pnpm-lock\.yaml|yarn\.lock|go\.sum|poetry\.lock|Pipfile\.lock|uv\.lock|Cargo\.lock|gradle\.lockfile)$/u,
|
|
21993
|
+
"dependency lock file"
|
|
21994
|
+
],
|
|
21995
|
+
[
|
|
21996
|
+
/(?:^|\/)(?:package\.json|go\.mod|pom\.xml|build\.gradle(?:\.kts)?|settings\.gradle(?:\.kts)?|pyproject\.toml|setup\.py|setup\.cfg|requirements[^/]*\.txt|Makefile|Dockerfile|tsconfig[^/]*\.json)$/u,
|
|
21997
|
+
"build or dependency file"
|
|
21998
|
+
],
|
|
21999
|
+
[/(?:^|\/)migrations?\/|\.sql$/iu, "database migration or schema"],
|
|
22000
|
+
[/(?:^|\/)\.env[^/]*$|\.(?:ya?ml|toml|ini|properties|conf|cfg)$/iu, "configuration"],
|
|
22001
|
+
[/\.(?:html?|jinja2?|j2|hbs|ejs|tmpl|tpl|gohtml|vue|svelte)$/iu, "template"]
|
|
22002
|
+
];
|
|
22003
|
+
var nonCodeKind = (path11) => NON_CODE.find(([pattern]) => pattern.test(path11))?.[1];
|
|
22004
|
+
var LIMITS = Object.freeze({ depth: 8, declarations: 800, changed: 200, chain: 3, byName: 40 });
|
|
22005
|
+
var CALLER_KINDS = /* @__PURE__ */ new Set(["CALLS", "REFERENCES"]);
|
|
22006
|
+
var IMPORT_KINDS2 = /* @__PURE__ */ new Set(["IMPORTS", "TEST_IMPORTS"]);
|
|
22007
|
+
var ROUTE = /^(?:[A-Z]+(?:\|[A-Z]+)* +)?\/\S*$/u;
|
|
22008
|
+
var Tracer = class {
|
|
22009
|
+
constructor(graph, memberCalls) {
|
|
22010
|
+
this.graph = graph;
|
|
22011
|
+
this.memberCalls = memberCalls;
|
|
22012
|
+
}
|
|
22013
|
+
graph;
|
|
22014
|
+
memberCalls;
|
|
22015
|
+
reached = /* @__PURE__ */ new Map();
|
|
22016
|
+
entries = /* @__PURE__ */ new Map();
|
|
22017
|
+
tests = /* @__PURE__ */ new Map();
|
|
22018
|
+
unclear = [];
|
|
22019
|
+
truncated = false;
|
|
22020
|
+
callerCount = /* @__PURE__ */ new Map();
|
|
22021
|
+
// Declarations a decorator maps to a route: entry points already, never "top of a chain".
|
|
22022
|
+
routes = /* @__PURE__ */ new Set();
|
|
22023
|
+
/** Test support files that call the changed code; the tests beside and below them may use it. */
|
|
22024
|
+
support = /* @__PURE__ */ new Set();
|
|
22025
|
+
name = (ref) => this.graph.qualifiedName(ref);
|
|
22026
|
+
where = (ref) => {
|
|
22027
|
+
const object2 = this.graph.object(ref);
|
|
22028
|
+
return `${object2.anchor.path}: ${this.name(ref)}`;
|
|
22029
|
+
};
|
|
22030
|
+
/** Follows callers up from the given declarations, recording entry points and tests. */
|
|
22031
|
+
trace(starts) {
|
|
22032
|
+
let frontier = [];
|
|
22033
|
+
for (const ref of starts)
|
|
22034
|
+
if (!this.reached.has(ref)) {
|
|
22035
|
+
const start = { ref, depth: 0, certain: true };
|
|
22036
|
+
this.reached.set(ref, start);
|
|
22037
|
+
frontier.push(start);
|
|
22038
|
+
}
|
|
22039
|
+
for (const start of frontier) this.byName(start.ref);
|
|
22040
|
+
while (frontier.length) {
|
|
22041
|
+
const next = [];
|
|
22042
|
+
for (const current of frontier) {
|
|
22043
|
+
const object2 = this.graph.object(current.ref);
|
|
22044
|
+
if (testCode(object2.anchor.path)) continue;
|
|
22045
|
+
this.decoratorRoutes(current);
|
|
22046
|
+
const callers = this.callers(current.ref);
|
|
22047
|
+
this.callerCount.set(current.ref, callers.length);
|
|
22048
|
+
for (const caller of callers) {
|
|
22049
|
+
const site = `${caller.relation.anchor.path}:${caller.relation.anchor.startLine}`;
|
|
22050
|
+
const certain = current.certain && caller.certain;
|
|
22051
|
+
if (caller.relation.argument && ROUTE.test(caller.relation.argument))
|
|
22052
|
+
this.entry(caller.relation.argument, true, current, site, certain);
|
|
22053
|
+
const callerObject = this.graph.object(caller.ref);
|
|
22054
|
+
if (testCode(callerObject.anchor.path)) {
|
|
22055
|
+
if (!mapRunnableTest(callerObject.anchor.path))
|
|
22056
|
+
this.support.add(callerObject.anchor.path);
|
|
22057
|
+
this.test(
|
|
22058
|
+
callerObject.anchor.path,
|
|
22059
|
+
this.name(caller.ref),
|
|
22060
|
+
`calls ${this.name(current.ref)}`,
|
|
22061
|
+
// Tests closer to the change come first; all of them rank before other relations.
|
|
22062
|
+
current.depth / 10
|
|
22063
|
+
);
|
|
22064
|
+
continue;
|
|
22065
|
+
}
|
|
22066
|
+
if (this.reached.has(caller.ref)) continue;
|
|
22067
|
+
if (current.depth + 1 > LIMITS.depth || this.reached.size >= LIMITS.declarations) {
|
|
22068
|
+
this.truncated = true;
|
|
22069
|
+
continue;
|
|
22070
|
+
}
|
|
22071
|
+
const reached = { ref: caller.ref, depth: current.depth + 1, certain, via: current.ref };
|
|
22072
|
+
this.reached.set(caller.ref, reached);
|
|
22073
|
+
next.push(reached);
|
|
22074
|
+
}
|
|
22075
|
+
}
|
|
22076
|
+
frontier = next;
|
|
22077
|
+
}
|
|
22078
|
+
for (const reached of this.reached.values()) {
|
|
22079
|
+
const object2 = this.graph.object(reached.ref);
|
|
22080
|
+
const language = mapLanguageOf(object2.anchor.path);
|
|
22081
|
+
if (object2.kind !== "METHOD" || !language || /^__\w+__$/u.test(object2.name)) continue;
|
|
22082
|
+
const calls = this.memberCalls.get(`${language}\0${object2.name}`) ?? [];
|
|
22083
|
+
if (calls.length > LIMITS.byName) continue;
|
|
22084
|
+
for (const call of calls)
|
|
22085
|
+
if (testCode(call.path))
|
|
22086
|
+
this.test(
|
|
22087
|
+
call.path,
|
|
22088
|
+
this.name(this.graph.owner(call.from)),
|
|
22089
|
+
`may call ${this.name(reached.ref)} through a receiver of unknown type`,
|
|
22090
|
+
3.5
|
|
22091
|
+
);
|
|
22092
|
+
}
|
|
22093
|
+
for (const reached of this.reached.values()) {
|
|
22094
|
+
if (this.callerCount.get(reached.ref) !== 0) continue;
|
|
22095
|
+
const object2 = this.graph.object(reached.ref);
|
|
22096
|
+
if (testCode(object2.anchor.path) || this.routes.has(reached.ref)) continue;
|
|
22097
|
+
if (reached.depth === 0)
|
|
22098
|
+
this.unclear.push(
|
|
22099
|
+
`${this.where(reached.ref)} has no callers in the map: it may be wired by a framework, called dynamically, or unused`
|
|
22100
|
+
);
|
|
22101
|
+
else this.entry(this.where(reached.ref), false, reached, void 0, reached.certain, true);
|
|
22102
|
+
}
|
|
22103
|
+
}
|
|
22104
|
+
callers(ref) {
|
|
22105
|
+
const callers = [];
|
|
22106
|
+
for (const relation of this.graph.relationsTo([ref]))
|
|
22107
|
+
if (CALLER_KINDS.has(relation.kind)) {
|
|
22108
|
+
const owner = this.graph.owner(relation.from);
|
|
22109
|
+
if (owner !== ref) callers.push({ ref: owner, relation, certain: true });
|
|
22110
|
+
}
|
|
22111
|
+
const object2 = this.graph.object(ref);
|
|
22112
|
+
const parent = this.graph.parent(ref);
|
|
22113
|
+
if (parent && this.graph.object(parent).kind === "CLASS") {
|
|
22114
|
+
const constructs = object2.execution === "CONSTRUCTOR" || object2.name === "__init__" || object2.name === "constructor";
|
|
22115
|
+
const implicit = constructs || /^__\w+__$/u.test(object2.name) || object2.kind === "PROPERTY" || this.graph.relationsFrom([ref]).some(
|
|
22116
|
+
(relation) => relation.kind === "DECORATED_BY" && /property$/u.test(relation.target)
|
|
22117
|
+
);
|
|
22118
|
+
if (implicit) {
|
|
22119
|
+
for (const relation of this.graph.relationsTo([parent]))
|
|
22120
|
+
if (CALLER_KINDS.has(relation.kind)) {
|
|
22121
|
+
const owner = this.graph.owner(relation.from);
|
|
22122
|
+
if (owner !== ref && owner !== parent)
|
|
22123
|
+
callers.push({ ref: owner, relation, certain: constructs });
|
|
22124
|
+
}
|
|
22125
|
+
}
|
|
22126
|
+
}
|
|
22127
|
+
for (const override of this.graph.relationsFrom([ref]))
|
|
22128
|
+
if (override.kind === "OVERRIDES" && override.to !== void 0) {
|
|
22129
|
+
const contract = override.to;
|
|
22130
|
+
const relations = this.graph.relationsTo([contract]);
|
|
22131
|
+
const only = relations.filter((relation) => relation.kind === "OVERRIDES").length === 1;
|
|
22132
|
+
for (const relation of relations)
|
|
22133
|
+
if (CALLER_KINDS.has(relation.kind)) {
|
|
22134
|
+
const owner = this.graph.owner(relation.from);
|
|
22135
|
+
if (owner !== ref) callers.push({ ref: owner, relation, certain: only });
|
|
22136
|
+
}
|
|
22137
|
+
}
|
|
22138
|
+
return callers;
|
|
22139
|
+
}
|
|
22140
|
+
decoratorRoutes(current) {
|
|
22141
|
+
for (const relation of this.graph.relationsFrom([current.ref])) {
|
|
22142
|
+
if (relation.kind !== "DECORATED_BY") continue;
|
|
22143
|
+
const route = relation.route ?? relation.argument;
|
|
22144
|
+
if (!route || !ROUTE.test(route)) continue;
|
|
22145
|
+
this.routes.add(current.ref);
|
|
22146
|
+
this.entry(
|
|
22147
|
+
route,
|
|
22148
|
+
true,
|
|
22149
|
+
current,
|
|
22150
|
+
`${relation.anchor.path}:${relation.anchor.startLine}`,
|
|
22151
|
+
current.certain
|
|
22152
|
+
);
|
|
22153
|
+
}
|
|
22154
|
+
}
|
|
22155
|
+
// Calls of a method's name on receivers of unknown type may reach it; they are only counted.
|
|
22156
|
+
byName(ref) {
|
|
22157
|
+
const object2 = this.graph.object(ref);
|
|
22158
|
+
const language = mapLanguageOf(object2.anchor.path);
|
|
22159
|
+
if (object2.kind !== "METHOD" || !language || /^__\w+__$/u.test(object2.name)) return;
|
|
22160
|
+
const calls = this.memberCalls.get(`${language}\0${object2.name}`) ?? [];
|
|
22161
|
+
if (calls.length)
|
|
22162
|
+
this.unclear.push(
|
|
22163
|
+
`${calls.length} calls of a member named ${object2.name} on receivers of unknown type may reach ${this.name(ref)}; a text search finds them`
|
|
22164
|
+
);
|
|
22165
|
+
}
|
|
22166
|
+
entry(label, route, at, site, certain, top = false) {
|
|
22167
|
+
const chain = [];
|
|
22168
|
+
let step = top && at.via ? this.reached.get(at.via) : at;
|
|
22169
|
+
for (; step && chain.length < LIMITS.chain; ) {
|
|
22170
|
+
chain.push(this.name(step.ref));
|
|
22171
|
+
step = step.via ? this.reached.get(step.via) : void 0;
|
|
22172
|
+
}
|
|
22173
|
+
const known = this.entries.get(label);
|
|
22174
|
+
if (known && (known.certain || !certain)) return;
|
|
22175
|
+
this.entries.set(label, { label, route, chain, ...site ? { site } : {}, certain });
|
|
22176
|
+
}
|
|
22177
|
+
/** A related test file; the closest relation (lowest rank) explains it. */
|
|
22178
|
+
test(path11, name, why, rank2) {
|
|
22179
|
+
if (!mapRunnableTest(path11)) return;
|
|
22180
|
+
const known = this.tests.get(path11) ?? { names: /* @__PURE__ */ new Set(), why, rank: rank2 };
|
|
22181
|
+
if (rank2 < known.rank) Object.assign(known, { why, rank: rank2 });
|
|
22182
|
+
if (name && !name.startsWith("<")) known.names.add(name);
|
|
22183
|
+
this.tests.set(path11, known);
|
|
22184
|
+
}
|
|
22185
|
+
};
|
|
22186
|
+
var mapRunnableTest = (file2) => /_test\.(?:go|py)$|(?:^|\/)test_[^/]*\.py$|\.(?:test|spec)\.[cm]?[jt]sx?$|(?:Test|Tests|IT)\.(?:java|kt)$/u.test(
|
|
22187
|
+
file2
|
|
22188
|
+
);
|
|
22189
|
+
function mapChangeImpact(store, working, base, changes, project) {
|
|
22190
|
+
const graph = new MapViewGraph(store, working);
|
|
22191
|
+
const cache = new MapViewCache();
|
|
22192
|
+
const tracer = new Tracer(graph, cache.memberCalls(store, working));
|
|
22193
|
+
const changed = [];
|
|
22194
|
+
const unclear = [];
|
|
22195
|
+
const removed = [];
|
|
22196
|
+
const declarations = (g, path11) => g.objectsAt(path11).filter((object2) => !mapIsModule(object2) && g.isAddressable(object2));
|
|
22197
|
+
let changedCount = 0;
|
|
22198
|
+
const starts = [];
|
|
22199
|
+
for (const file2 of changes.files) {
|
|
22200
|
+
if (file2.binary) continue;
|
|
22201
|
+
const kind = nonCodeKind(file2.path);
|
|
22202
|
+
const objects2 = file2.status === "DELETED" ? [] : graph.objectsAt(file2.path);
|
|
22203
|
+
if (testCode(file2.path)) {
|
|
22204
|
+
if (file2.status !== "DELETED") tracer.test(file2.path, void 0, "changed in this diff", 1);
|
|
22205
|
+
continue;
|
|
22206
|
+
}
|
|
22207
|
+
if (!objects2.length) {
|
|
22208
|
+
if (file2.status !== "DELETED" && kind)
|
|
22209
|
+
unclear.push(`${file2.path} changed (${kind}): its effects are not mapped`);
|
|
22210
|
+
continue;
|
|
22211
|
+
}
|
|
22212
|
+
const hits = /* @__PURE__ */ new Set();
|
|
22213
|
+
let topLevel = false;
|
|
22214
|
+
const inFile = declarations(graph, file2.path);
|
|
22215
|
+
for (const [from, to] of file2.lines) {
|
|
22216
|
+
const containing = inFile.filter(
|
|
22217
|
+
(object2) => object2.anchor.startLine <= to && from <= object2.anchor.endLine
|
|
22218
|
+
);
|
|
22219
|
+
if (!containing.length) topLevel = true;
|
|
22220
|
+
for (const object2 of containing)
|
|
22221
|
+
if (!containing.some(
|
|
22222
|
+
(other) => other !== object2 && object2.anchor.start <= other.anchor.start && other.anchor.end <= object2.anchor.end && other.anchor.startLine <= to && from <= other.anchor.endLine
|
|
22223
|
+
))
|
|
22224
|
+
hits.add(object2.id);
|
|
22225
|
+
}
|
|
22226
|
+
for (const ref of hits) {
|
|
22227
|
+
if (changedCount++ >= LIMITS.changed) {
|
|
22228
|
+
tracer.truncated = true;
|
|
22229
|
+
break;
|
|
22230
|
+
}
|
|
22231
|
+
const object2 = graph.object(ref);
|
|
22232
|
+
changed.push(
|
|
22233
|
+
`${file2.path}: ${graph.qualifiedName(ref)} ${mapDeclarationLabel(object2)}${file2.status === "ADDED" ? " (new file)" : ""}`
|
|
22234
|
+
);
|
|
22235
|
+
starts.push(ref);
|
|
22236
|
+
}
|
|
22237
|
+
for (const relation of graph.relationsFrom(objects2.map((object2) => object2.id)))
|
|
22238
|
+
if (relation.argument && ROUTE.test(relation.argument) && overlaps(file2.lines, relation.anchor.startLine, relation.anchor.endLine))
|
|
22239
|
+
unclear.push(
|
|
22240
|
+
`the registration of ${JSON.stringify(relation.argument)} at ${relation.anchor.path}:${relation.anchor.startLine} changed; check that the route still reaches the right handler`
|
|
22241
|
+
);
|
|
22242
|
+
if (topLevel && file2.status !== "ADDED")
|
|
22243
|
+
unclear.push(`top-level code of ${file2.path} changed (imports, constants or registrations)`);
|
|
22244
|
+
importerTests(graph, objects2, tracer);
|
|
22245
|
+
sameDirectoryTests(store, working, file2.path, tracer);
|
|
22246
|
+
mirroredTests(store, working, file2.path, tracer);
|
|
22247
|
+
}
|
|
22248
|
+
tracer.trace(starts);
|
|
22249
|
+
if (project) routeTests(project, store, working, [...tracer.entries.values()], tracer);
|
|
22250
|
+
supportTests(store, working, tracer);
|
|
22251
|
+
if (base) {
|
|
22252
|
+
const before = new MapViewGraph(store, base);
|
|
22253
|
+
const beforeTracer = new Tracer(before, cache.memberCalls(store, base));
|
|
22254
|
+
const gone = [];
|
|
22255
|
+
for (const file2 of changes.files) {
|
|
22256
|
+
if (!file2.basePath || !file2.baseLines.length || file2.binary || testCode(file2.basePath))
|
|
22257
|
+
continue;
|
|
22258
|
+
const now = new Set(
|
|
22259
|
+
file2.status === "DELETED" ? [] : declarations(graph, file2.path).map(
|
|
22260
|
+
(o) => `${o.kind}\0${graph.qualifiedName(o.id)}`
|
|
22261
|
+
)
|
|
22262
|
+
);
|
|
22263
|
+
for (const object2 of declarations(before, file2.basePath)) {
|
|
22264
|
+
if (!overlaps(file2.baseLines, object2.anchor.startLine, object2.anchor.endLine)) continue;
|
|
22265
|
+
if (now.has(`${object2.kind}\0${before.qualifiedName(object2.id)}`)) continue;
|
|
22266
|
+
const parent = before.parent(object2.id);
|
|
22267
|
+
if (parent && !mapIsModule(before.object(parent)) && gone.includes(parent)) continue;
|
|
22268
|
+
gone.push(object2.id);
|
|
22269
|
+
removed.push(
|
|
22270
|
+
`${file2.basePath}: ${before.qualifiedName(object2.id)} ${mapDeclarationLabel(object2)}`
|
|
22271
|
+
);
|
|
22272
|
+
}
|
|
22273
|
+
}
|
|
22274
|
+
if (gone.length) {
|
|
22275
|
+
beforeTracer.trace(gone);
|
|
22276
|
+
for (const entry of beforeTracer.entries.values())
|
|
22277
|
+
if (!tracer.entries.has(entry.label)) tracer.entries.set(entry.label, entry);
|
|
22278
|
+
for (const [path11, test] of beforeTracer.tests) {
|
|
22279
|
+
const known = tracer.tests.get(path11);
|
|
22280
|
+
if (known) for (const name of test.names) known.names.add(name);
|
|
22281
|
+
else tracer.tests.set(path11, test);
|
|
22282
|
+
}
|
|
22283
|
+
unclear.push(...beforeTracer.unclear.filter((line) => !line.includes("has no callers")));
|
|
22284
|
+
if (beforeTracer.truncated) tracer.truncated = true;
|
|
22285
|
+
}
|
|
22286
|
+
}
|
|
22287
|
+
return {
|
|
22288
|
+
changed,
|
|
22289
|
+
removed,
|
|
22290
|
+
entries: [...tracer.entries.values()].sort(
|
|
22291
|
+
(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)
|
|
22292
|
+
),
|
|
22293
|
+
tests: [...tracer.tests].map(([path11, test]) => ({
|
|
22294
|
+
path: path11,
|
|
22295
|
+
names: [...test.names].sort(),
|
|
22296
|
+
why: test.why,
|
|
22297
|
+
rank: test.rank
|
|
22298
|
+
})).sort(
|
|
22299
|
+
(left, right) => left.rank - right.rank || (left.path < right.path ? -1 : left.path > right.path ? 1 : 0)
|
|
22300
|
+
),
|
|
22301
|
+
unclear: [.../* @__PURE__ */ new Set([...unclear, ...tracer.unclear])],
|
|
22302
|
+
truncated: tracer.truncated
|
|
22303
|
+
};
|
|
22304
|
+
}
|
|
22305
|
+
function importerTests(graph, objects2, tracer) {
|
|
22306
|
+
let modules = objects2.filter((object2) => mapIsModule(object2)).map((object2) => object2.id);
|
|
22307
|
+
const seen = new Set(modules);
|
|
22308
|
+
for (let hop = 0; hop < 3 && modules.length; hop++) {
|
|
22309
|
+
const next = [];
|
|
22310
|
+
for (const relation of graph.relationsTo(modules)) {
|
|
22311
|
+
if (!IMPORT_KINDS2.has(relation.kind)) continue;
|
|
22312
|
+
const importer = graph.object(relation.from);
|
|
22313
|
+
const module = mapIsModule(importer) ? importer.id : graph.owner(relation.from);
|
|
22314
|
+
if (testCode(relation.anchor.path))
|
|
22315
|
+
tracer.test(
|
|
22316
|
+
relation.anchor.path,
|
|
22317
|
+
void 0,
|
|
22318
|
+
hop ? "imports a changed file indirectly" : "imports a changed file",
|
|
22319
|
+
hop ? 4 : 2
|
|
22320
|
+
);
|
|
22321
|
+
else if (!seen.has(module)) {
|
|
22322
|
+
seen.add(module);
|
|
22323
|
+
next.push(module);
|
|
22324
|
+
}
|
|
22325
|
+
}
|
|
22326
|
+
modules = next;
|
|
22327
|
+
}
|
|
22328
|
+
}
|
|
22329
|
+
function supportTests(store, version2, tracer) {
|
|
22330
|
+
for (const file2 of tracer.support) {
|
|
22331
|
+
const slash = file2.lastIndexOf("/");
|
|
22332
|
+
const directory = slash < 0 ? "" : file2.slice(0, slash + 1);
|
|
22333
|
+
for (const row of store.database.prepare(
|
|
22334
|
+
"SELECT DISTINCT path FROM project_map_objects WHERE version_ref = ? AND substr(path, 1, ?) = ?"
|
|
22335
|
+
).all(version2, directory.length, directory))
|
|
22336
|
+
tracer.test(String(row.path), void 0, `may use it through ${file2}`, 3.5);
|
|
22337
|
+
}
|
|
22338
|
+
}
|
|
22339
|
+
function mirroredTests(store, version2, file2, tracer) {
|
|
22340
|
+
const directories = file2.split("/").slice(0, -1);
|
|
22341
|
+
const module = directories.at(-1);
|
|
22342
|
+
if (!module || directories.length < 1) return;
|
|
22343
|
+
for (const row of store.database.prepare(
|
|
22344
|
+
"SELECT DISTINCT path FROM project_map_objects WHERE version_ref = ? AND instr(path, ?) > 0"
|
|
22345
|
+
).all(version2, `/${module}/`)) {
|
|
22346
|
+
const candidate = String(row.path);
|
|
22347
|
+
const parts = candidate.split("/");
|
|
22348
|
+
const at = parts.lastIndexOf(module);
|
|
22349
|
+
if (at < 1 || at !== parts.length - 2) continue;
|
|
22350
|
+
if (!parts.slice(0, at).some((part) => /^(?:tests?|__tests__|specs?)$/iu.test(part))) continue;
|
|
22351
|
+
tracer.test(candidate, void 0, `tests the ${module} module`, 3);
|
|
22352
|
+
}
|
|
22353
|
+
}
|
|
22354
|
+
function routeTests(project, store, version2, entries, tracer) {
|
|
22355
|
+
const fragments = /* @__PURE__ */ new Map();
|
|
22356
|
+
for (const entry of entries) {
|
|
22357
|
+
if (!entry.route) continue;
|
|
22358
|
+
const route = entry.label.slice(entry.label.indexOf("/"));
|
|
22359
|
+
const longest = route.split(/\/(?:\{[^}]*\}|:[^/]+|<[^>]*>|\*)(?=\/|$)/u).sort((left, right) => right.length - left.length)[0];
|
|
22360
|
+
if (longest && longest.replace(/\//gu, "").length >= 4) fragments.set(longest, entry.label);
|
|
22361
|
+
}
|
|
22362
|
+
if (!fragments.size) return;
|
|
22363
|
+
let budget = 32 * 1024 * 1024;
|
|
22364
|
+
for (const row of store.database.prepare("SELECT DISTINCT path FROM project_map_objects WHERE version_ref = ?").all(version2)) {
|
|
22365
|
+
const candidate = String(row.path);
|
|
22366
|
+
if (!mapRunnableTest(candidate)) continue;
|
|
22367
|
+
let text;
|
|
22368
|
+
try {
|
|
22369
|
+
text = readFileSync2(path7.join(project, candidate), "utf8");
|
|
22370
|
+
} catch {
|
|
22371
|
+
continue;
|
|
22372
|
+
}
|
|
22373
|
+
budget -= text.length;
|
|
22374
|
+
if (budget < 0) return;
|
|
22375
|
+
for (const [fragment, label] of fragments)
|
|
22376
|
+
if (text.includes(fragment)) {
|
|
22377
|
+
tracer.test(
|
|
22378
|
+
candidate,
|
|
22379
|
+
void 0,
|
|
22380
|
+
`mentions ${JSON.stringify(label)}`,
|
|
22381
|
+
tracer.tests.has(candidate) ? 2 : 3.5
|
|
22382
|
+
);
|
|
22383
|
+
break;
|
|
22384
|
+
}
|
|
22385
|
+
}
|
|
22386
|
+
}
|
|
22387
|
+
function sameDirectoryTests(store, version2, path11, tracer) {
|
|
22388
|
+
const slash = path11.lastIndexOf("/");
|
|
22389
|
+
const directory = slash < 0 ? "" : path11.slice(0, slash + 1);
|
|
22390
|
+
for (const row of store.database.prepare(
|
|
22391
|
+
"SELECT DISTINCT path FROM project_map_objects WHERE version_ref = ? AND path LIKE ? ESCAPE '\\'"
|
|
22392
|
+
).all(version2, `${directory.replace(/[\\%_]/gu, (c) => `\\${c}`)}%`)) {
|
|
22393
|
+
const candidate = String(row.path);
|
|
22394
|
+
if (candidate.slice(directory.length).includes("/") || !mapTestPath(candidate)) continue;
|
|
22395
|
+
tracer.test(candidate, void 0, "in the same directory", 3);
|
|
22396
|
+
}
|
|
22397
|
+
}
|
|
22398
|
+
function testNames(names) {
|
|
22399
|
+
if (!names.length) return "";
|
|
22400
|
+
const tests = names.filter((name) => /(?:^|\.)(?:test|Test|should|it_)\w*$/u.test(name));
|
|
22401
|
+
const shown = (tests.length ? tests : names).slice(0, LIST.names);
|
|
22402
|
+
const more2 = (tests.length ? tests : names).length - shown.length;
|
|
22403
|
+
return `: ${shown.join(", ")}${more2 > 0 ? `, +${more2} more` : ""}`;
|
|
22404
|
+
}
|
|
22405
|
+
var LIST = Object.freeze({ changed: 20, entries: 40, tests: 30, unclear: 20, names: 6 });
|
|
22406
|
+
function mapChangesText(changes, impact) {
|
|
22407
|
+
const files = changes.files.length;
|
|
22408
|
+
const direct = impact.tests.filter((test) => test.rank < 4);
|
|
22409
|
+
const indirect = impact.tests.filter((test) => test.rank >= 4);
|
|
22410
|
+
const routes = impact.entries.filter((entry2) => entry2.route);
|
|
22411
|
+
const lines = [
|
|
22412
|
+
`PROJECT MAP \xB7 CHANGES against ${changes.base} (${changes.commit.slice(0, 12)}) \xB7 ${files} changed file${files === 1 ? "" : "s"} \xB7 ${impact.changed.length} changed and ${impact.removed.length} removed declarations \xB7 ${routes.length} routes and ${impact.entries.length - routes.length} other entry points reached \xB7 ${direct.length} related test files${indirect.length ? ` (+${indirect.length} importing the changes indirectly)` : ""}`
|
|
22413
|
+
];
|
|
22414
|
+
if (!files) return `${lines[0]}
|
|
22415
|
+
Nothing changed against ${changes.base}.`;
|
|
22416
|
+
const list = (title, items, limit) => {
|
|
22417
|
+
if (!items.length) return;
|
|
22418
|
+
lines.push(title, ...items.slice(0, limit).map((item) => ` ${item}`));
|
|
22419
|
+
if (items.length > limit) lines.push(` +${items.length - limit} more`);
|
|
22420
|
+
};
|
|
22421
|
+
list("CHANGED", impact.changed, LIST.changed);
|
|
22422
|
+
list(
|
|
22423
|
+
"REMOVED OR RENAMED (their callers in the base still refer to them)",
|
|
22424
|
+
impact.removed,
|
|
22425
|
+
LIST.changed
|
|
22426
|
+
);
|
|
22427
|
+
const entry = (item) => `${item.route ? JSON.stringify(item.label) : item.label}${item.chain.length ? ` \u2192 ${item.chain.join(" \u2192 ")}` : ""}${item.site ? ` (registered at ${item.site})` : ""}`;
|
|
22428
|
+
list(
|
|
22429
|
+
"AFFECTED ENTRY POINTS (through resolved calls)",
|
|
22430
|
+
impact.entries.filter((e) => e.certain).map(entry),
|
|
22431
|
+
LIST.entries
|
|
22432
|
+
);
|
|
22433
|
+
list(
|
|
22434
|
+
"POSSIBLY AFFECTED (through a call on an interface or base member, which may dispatch elsewhere)",
|
|
22435
|
+
impact.entries.filter((e) => !e.certain).map(entry),
|
|
22436
|
+
LIST.entries
|
|
22437
|
+
);
|
|
22438
|
+
list(
|
|
22439
|
+
"CHECK BY HAND (the map cannot see these)",
|
|
22440
|
+
[
|
|
22441
|
+
...impact.unclear,
|
|
22442
|
+
...impact.truncated ? [
|
|
22443
|
+
`the trace stopped at ${LIMITS.depth} levels or ${LIMITS.declarations} declarations; continue with project_explore_map from the last ones`
|
|
22444
|
+
] : []
|
|
22445
|
+
],
|
|
22446
|
+
LIST.unclear
|
|
22447
|
+
);
|
|
22448
|
+
if (direct.length) {
|
|
22449
|
+
list(
|
|
22450
|
+
"RELATED TESTS (closest first)",
|
|
22451
|
+
direct.map((test) => `${test.path}${testNames(test.names)} (${test.why})`),
|
|
22452
|
+
LIST.tests
|
|
22453
|
+
);
|
|
22454
|
+
if (indirect.length)
|
|
22455
|
+
lines.push(
|
|
22456
|
+
` +${indirect.length} more test files import the changed files through other modules; run them for a broader check`
|
|
22457
|
+
);
|
|
22458
|
+
lines.push("If the change needs verifying, these existing tests are the ones to run.");
|
|
22459
|
+
} else if (indirect.length)
|
|
22460
|
+
lines.push(
|
|
22461
|
+
`RELATED TESTS: none call or import the changed code directly; ${indirect.length} test files import it through other modules, which a broader run covers.`
|
|
22462
|
+
);
|
|
22463
|
+
lines.push(
|
|
22464
|
+
"Static estimate: calls through dependency injection, reflection, string dispatch, configuration and database coupling are not mapped, so an empty list does not prove the change is safe; confirm the entry points in source."
|
|
22465
|
+
);
|
|
22466
|
+
return lines.join("\n");
|
|
22467
|
+
}
|
|
22468
|
+
|
|
21870
22469
|
// src/layermap.ts
|
|
21871
22470
|
var SCHEMA_VERSION = 2;
|
|
21872
22471
|
var KEEP_VERSIONS = 3;
|
|
21873
22472
|
function openMapDatabase(file2) {
|
|
21874
|
-
mkdirSync(
|
|
22473
|
+
mkdirSync(path8.dirname(file2), { recursive: true, mode: 448 });
|
|
21875
22474
|
const database = new DatabaseSync(file2);
|
|
21876
22475
|
try {
|
|
21877
22476
|
database.exec("PRAGMA busy_timeout = 30000;");
|
|
@@ -21908,7 +22507,7 @@ function openMapDatabase(file2) {
|
|
|
21908
22507
|
throw error51;
|
|
21909
22508
|
}
|
|
21910
22509
|
}
|
|
21911
|
-
var mapDatabasePath = (cacheDirectory2, canonicalProject) =>
|
|
22510
|
+
var mapDatabasePath = (cacheDirectory2, canonicalProject) => path8.join(
|
|
21912
22511
|
cacheDirectory2,
|
|
21913
22512
|
"projects",
|
|
21914
22513
|
createHash4("sha256").update(canonicalProject).digest("hex").slice(0, 24),
|
|
@@ -21960,14 +22559,26 @@ var LayerMap = class _LayerMap {
|
|
|
21960
22559
|
}
|
|
21961
22560
|
/** The map version of the directory as it is now, built or updated if needed. */
|
|
21962
22561
|
refresh(signal) {
|
|
21963
|
-
|
|
21964
|
-
const next = previous.catch(() => "").then(async () => {
|
|
22562
|
+
return this.serialized(async () => {
|
|
21965
22563
|
const version2 = await this.index.prepare(this.source, signal, {
|
|
21966
22564
|
initialScope: DEFAULT_INITIAL_EVIDENCE_SCOPE
|
|
21967
22565
|
});
|
|
21968
22566
|
this.prune(version2);
|
|
21969
22567
|
return version2.version;
|
|
21970
22568
|
});
|
|
22569
|
+
}
|
|
22570
|
+
/** The map version of a commit of the directory; files it shares with other versions are reused. */
|
|
22571
|
+
versionAt(commit, signal) {
|
|
22572
|
+
return this.serialized(async () => {
|
|
22573
|
+
const version2 = await this.index.prepare({ ...this.source, kind: "COMMIT", commit }, signal, {
|
|
22574
|
+
initialScope: DEFAULT_INITIAL_EVIDENCE_SCOPE
|
|
22575
|
+
});
|
|
22576
|
+
return version2.version;
|
|
22577
|
+
});
|
|
22578
|
+
}
|
|
22579
|
+
// One capture at a time; a query waiting behind one captures again, since files may change.
|
|
22580
|
+
serialized(capture) {
|
|
22581
|
+
const next = (this.refreshing ?? Promise.resolve("")).catch(() => "").then(capture);
|
|
21971
22582
|
this.refreshing = next;
|
|
21972
22583
|
return next;
|
|
21973
22584
|
}
|
|
@@ -22012,6 +22623,29 @@ var LayerMap = class _LayerMap {
|
|
|
22012
22623
|
)
|
|
22013
22624
|
);
|
|
22014
22625
|
}
|
|
22626
|
+
/**
|
|
22627
|
+
* What the working tree's changes against a commit (HEAD by default) affect: the changed and
|
|
22628
|
+
* removed declarations, the entry points and tests their callers reach, and what the map cannot
|
|
22629
|
+
* see. The base commit's map is built only when the diff removes or changes lines there.
|
|
22630
|
+
*/
|
|
22631
|
+
async checkChanges(input, signal) {
|
|
22632
|
+
const changes = await readMapChanges(this.project, input.base ?? "HEAD", signal);
|
|
22633
|
+
const working = await this.refresh(signal);
|
|
22634
|
+
const base = changes.files.some((file2) => file2.basePath !== void 0 && file2.baseLines.length) ? await this.versionAt(changes.commit, signal) : void 0;
|
|
22635
|
+
return {
|
|
22636
|
+
text: mapChangesText(
|
|
22637
|
+
changes,
|
|
22638
|
+
mapChangeImpact(this.store, working, base, changes, this.project)
|
|
22639
|
+
)
|
|
22640
|
+
};
|
|
22641
|
+
}
|
|
22642
|
+
/**
|
|
22643
|
+
* Builds the map of a base commit (HEAD by default) ahead of a change check, so the check after an
|
|
22644
|
+
* edit does not wait for it. A clean working tree's base shares every file with its map.
|
|
22645
|
+
*/
|
|
22646
|
+
async prepareBase(signal, base = "HEAD") {
|
|
22647
|
+
await this.versionAt(await resolveMapBase(this.project, base, signal), signal);
|
|
22648
|
+
}
|
|
22015
22649
|
async close() {
|
|
22016
22650
|
await this.index.quiesce();
|
|
22017
22651
|
this.index.close();
|
|
@@ -22021,19 +22655,19 @@ var LayerMap = class _LayerMap {
|
|
|
22021
22655
|
|
|
22022
22656
|
// src/agent/environment.ts
|
|
22023
22657
|
var packageRoot = (() => {
|
|
22024
|
-
for (let directory =
|
|
22025
|
-
const manifest =
|
|
22026
|
-
if (existsSync4(manifest) && JSON.parse(
|
|
22658
|
+
for (let directory = path9.dirname(fileURLToPath(import.meta.url)); ; ) {
|
|
22659
|
+
const manifest = path9.join(directory, "package.json");
|
|
22660
|
+
if (existsSync4(manifest) && JSON.parse(readFileSync3(manifest, "utf8")).name === "layermap")
|
|
22027
22661
|
return directory;
|
|
22028
|
-
if (
|
|
22029
|
-
directory =
|
|
22662
|
+
if (path9.dirname(directory) === directory) throw new Error("LayerMap cannot find its package.");
|
|
22663
|
+
directory = path9.dirname(directory);
|
|
22030
22664
|
}
|
|
22031
22665
|
})();
|
|
22032
|
-
var packageVersion = async () => JSON.parse(await readFile(
|
|
22666
|
+
var packageVersion = async () => JSON.parse(await readFile(path9.join(packageRoot, "package.json"), "utf8")).version;
|
|
22033
22667
|
var cacheDirectory = (env = process.env) => {
|
|
22034
|
-
if (env.LAYERMAP_CACHE) return
|
|
22035
|
-
if (process.platform === "darwin") return
|
|
22036
|
-
return
|
|
22668
|
+
if (env.LAYERMAP_CACHE) return path9.resolve(env.LAYERMAP_CACHE);
|
|
22669
|
+
if (process.platform === "darwin") return path9.join(homedir(), "Library", "Caches", "layermap");
|
|
22670
|
+
return path9.join(env.XDG_CACHE_HOME || path9.join(homedir(), ".cache"), "layermap");
|
|
22037
22671
|
};
|
|
22038
22672
|
var projectDirectory = (directory) => new Promise(
|
|
22039
22673
|
(resolve) => execFile(
|
|
@@ -22041,7 +22675,7 @@ var projectDirectory = (directory) => new Promise(
|
|
|
22041
22675
|
["rev-parse", "--show-toplevel"],
|
|
22042
22676
|
{ cwd: directory, timeout: 1e4 },
|
|
22043
22677
|
(error51, stdout) => resolve(
|
|
22044
|
-
error51 ? { directory:
|
|
22678
|
+
error51 ? { directory: path9.resolve(directory), git: false } : { directory: stdout.trim(), git: true }
|
|
22045
22679
|
)
|
|
22046
22680
|
)
|
|
22047
22681
|
);
|
|
@@ -22051,7 +22685,7 @@ var relativeTo = (directory, value) => Object.fromEntries(
|
|
|
22051
22685
|
Object.fromEntries(
|
|
22052
22686
|
Object.entries(resources).map(([key, field]) => [
|
|
22053
22687
|
key,
|
|
22054
|
-
key.endsWith("Path") && typeof field === "string" && field.startsWith(directory) ?
|
|
22688
|
+
key.endsWith("Path") && typeof field === "string" && field.startsWith(directory) ? path9.relative(directory, field) : field
|
|
22055
22689
|
])
|
|
22056
22690
|
)
|
|
22057
22691
|
])
|
|
@@ -22062,7 +22696,7 @@ var resolvePlaceholder = (field) => {
|
|
|
22062
22696
|
createRequire(import.meta.url).resolve("typescript/package.json")
|
|
22063
22697
|
);
|
|
22064
22698
|
const native = `@typescript/typescript-${process.platform}-${process.arch}/package.json`;
|
|
22065
|
-
return
|
|
22699
|
+
return path9.join(path9.dirname(compiler.resolve(native)), "lib", "tsc");
|
|
22066
22700
|
}
|
|
22067
22701
|
return field.replaceAll("{platform}", process.platform).replaceAll("{arch}", process.arch);
|
|
22068
22702
|
};
|
|
@@ -22073,24 +22707,24 @@ var absoluteIn = (directory, value) => Object.fromEntries(
|
|
|
22073
22707
|
Object.entries(resources).map(([key, field]) => {
|
|
22074
22708
|
if (!key.endsWith("Path") || typeof field !== "string") return [key, field];
|
|
22075
22709
|
const resolved = resolvePlaceholder(field);
|
|
22076
|
-
return [key,
|
|
22710
|
+
return [key, path9.isAbsolute(resolved) ? resolved : path9.join(directory, resolved)];
|
|
22077
22711
|
})
|
|
22078
22712
|
)
|
|
22079
22713
|
])
|
|
22080
22714
|
);
|
|
22081
22715
|
var readAnalyzers = async (directory) => {
|
|
22082
|
-
const file2 =
|
|
22716
|
+
const file2 = path9.join(directory, "analyzers.json");
|
|
22083
22717
|
if (!existsSync4(file2)) return void 0;
|
|
22084
22718
|
const analyzers = absoluteIn(directory, JSON.parse(await readFile(file2, "utf8")));
|
|
22085
22719
|
return analyzers.java.runtimePath ? analyzers : { ...analyzers, java: { ...analyzers.java, ...discoverJavaRuntime() } };
|
|
22086
22720
|
};
|
|
22087
22721
|
var sourceDigest = async () => {
|
|
22088
|
-
const hash2 = createHash5("sha256").update(await readFile(
|
|
22722
|
+
const hash2 = createHash5("sha256").update(await readFile(path9.join(packageRoot, "package.json")));
|
|
22089
22723
|
for (const part of ["src", "go-map", "java-map", "scripts"]) {
|
|
22090
|
-
const directory =
|
|
22724
|
+
const directory = path9.join(packageRoot, part);
|
|
22091
22725
|
if (!existsSync4(directory)) continue;
|
|
22092
22726
|
for (const entry of (await readdir(directory, { recursive: true })).sort()) {
|
|
22093
|
-
const file2 =
|
|
22727
|
+
const file2 = path9.join(directory, entry);
|
|
22094
22728
|
const info = await stat(file2);
|
|
22095
22729
|
if (info.isFile()) hash2.update(`${part}/${entry}\0${info.size}\0${info.mtimeMs}\0`);
|
|
22096
22730
|
}
|
|
@@ -22098,11 +22732,11 @@ var sourceDigest = async () => {
|
|
|
22098
22732
|
return hash2.digest("hex").slice(0, 16);
|
|
22099
22733
|
};
|
|
22100
22734
|
async function resolveAnalyzers(cache, log2, env = process.env) {
|
|
22101
|
-
for (const directory2 of [env.LAYERMAP_ANALYZERS,
|
|
22102
|
-
const analyzers = directory2 && await readAnalyzers(
|
|
22735
|
+
for (const directory2 of [env.LAYERMAP_ANALYZERS, path9.join(packageRoot, "analyzers")]) {
|
|
22736
|
+
const analyzers = directory2 && await readAnalyzers(path9.resolve(directory2));
|
|
22103
22737
|
if (analyzers) return analyzers;
|
|
22104
22738
|
}
|
|
22105
|
-
const directory =
|
|
22739
|
+
const directory = path9.join(cache, "analyzers", await sourceDigest());
|
|
22106
22740
|
const built = await readAnalyzers(directory);
|
|
22107
22741
|
if (built) return built;
|
|
22108
22742
|
log2("Building the language analyzers (once per LayerMap version)...");
|
|
@@ -22118,32 +22752,32 @@ async function resolveAnalyzers(cache, log2, env = process.env) {
|
|
|
22118
22752
|
python: parser.pythonResources,
|
|
22119
22753
|
java: parser.javaResources
|
|
22120
22754
|
});
|
|
22121
|
-
await writeFile(
|
|
22755
|
+
await writeFile(path9.join(staging, "analyzers.json"), `${JSON.stringify(stored, null, 2)}
|
|
22122
22756
|
`);
|
|
22123
22757
|
await rename(staging, directory).catch(() => rm(staging, { recursive: true, force: true }));
|
|
22124
22758
|
return await readAnalyzers(directory);
|
|
22125
22759
|
}
|
|
22126
22760
|
var DAY = 24 * 60 * 60 * 1e3;
|
|
22127
22761
|
async function pruneCache(cache, project, now = Date.now()) {
|
|
22128
|
-
const used =
|
|
22129
|
-
await mkdir(
|
|
22762
|
+
const used = path9.join(path9.dirname(mapDatabasePath(cache, project)), "last-used");
|
|
22763
|
+
await mkdir(path9.dirname(used), { recursive: true, mode: 448 });
|
|
22130
22764
|
await writeFile(used, "");
|
|
22131
22765
|
await utimes(used, now / 1e3, now / 1e3);
|
|
22132
|
-
const projects =
|
|
22766
|
+
const projects = path9.join(cache, "projects");
|
|
22133
22767
|
for (const name of await readdir(projects).catch(() => [])) {
|
|
22134
|
-
const directory =
|
|
22135
|
-
const marker =
|
|
22768
|
+
const directory = path9.join(projects, name);
|
|
22769
|
+
const marker = path9.join(directory, "last-used");
|
|
22136
22770
|
const last = (await stat(existsSync4(marker) ? marker : directory).catch(() => void 0))?.mtimeMs;
|
|
22137
22771
|
if (last !== void 0 && now - last > 30 * DAY)
|
|
22138
22772
|
await rm(directory, { recursive: true, force: true });
|
|
22139
22773
|
}
|
|
22140
|
-
const builds =
|
|
22774
|
+
const builds = path9.join(cache, "analyzers");
|
|
22141
22775
|
const current = await sourceDigest();
|
|
22142
22776
|
for (const name of await readdir(builds).catch(() => [])) {
|
|
22143
22777
|
if (name === current) continue;
|
|
22144
|
-
const built = (await stat(
|
|
22778
|
+
const built = (await stat(path9.join(builds, name)).catch(() => void 0))?.mtimeMs;
|
|
22145
22779
|
if (built !== void 0 && now - built > (name.includes(".") ? DAY / 24 : DAY))
|
|
22146
|
-
await rm(
|
|
22780
|
+
await rm(path9.join(builds, name), { recursive: true, force: true });
|
|
22147
22781
|
}
|
|
22148
22782
|
}
|
|
22149
22783
|
|
|
@@ -22163,15 +22797,17 @@ var AGENT_MAP_TOOL_HOST = Object.freeze({
|
|
|
22163
22797
|
lead: {
|
|
22164
22798
|
explore: "Use this before grep or reading files to answer what calls a function or method, what changing it affects (callers traced up to entry points such as HTTP routes, handlers, jobs and commands), what it calls, and what a directory or file contains: one call returns the callers or callees up to 8 levels deep, with file paths and line numbers, for TypeScript, JavaScript, Go, Python and Java.",
|
|
22165
22799
|
search: "Use this to find where a function, method, class or type is declared, by name or by words in its name, path or documentation, before exploring its callers with project_explore_map.",
|
|
22166
|
-
references: "Use this to list every place a declaration is used (calls, imports, re-exports, reads and writes), compiled from current source: more complete than searching for its name."
|
|
22800
|
+
references: "Use this to list every place a declaration is used (calls, imports, re-exports, reads and writes), compiled from current source: more complete than searching for its name.",
|
|
22801
|
+
check: "Use this after editing code and before reporting the work done: it lists what the uncommitted changes affect, from the changed functions up to the HTTP routes, jobs and commands that reach them, plus the existing tests related to them."
|
|
22167
22802
|
}
|
|
22168
22803
|
});
|
|
22169
22804
|
var MAP_TOOL_NAMES = Object.freeze({
|
|
22170
22805
|
search: "project_search_map",
|
|
22171
22806
|
explore: "project_explore_map",
|
|
22172
|
-
references: "project_find_references"
|
|
22807
|
+
references: "project_find_references",
|
|
22808
|
+
check: "project_check_changes"
|
|
22173
22809
|
});
|
|
22174
|
-
var mapDirectoryPath = (
|
|
22810
|
+
var mapDirectoryPath = (path11) => path11.length > 1 && path11.endsWith("/") && !path11.endsWith("//") ? path11.slice(0, -1) : path11;
|
|
22175
22811
|
var ProjectMapSearchInputSchema = external_exports.object({
|
|
22176
22812
|
path: external_exports.string().default("."),
|
|
22177
22813
|
query: external_exports.string().min(1).max(256),
|
|
@@ -22196,6 +22832,11 @@ var ProjectMapExploreInputSchema = external_exports.object({
|
|
|
22196
22832
|
includeUnresolved: external_exports.boolean().default(false),
|
|
22197
22833
|
offset: external_exports.number().int().nonnegative().default(0)
|
|
22198
22834
|
}).strict();
|
|
22835
|
+
var ProjectMapCheckInputSchema = external_exports.object({
|
|
22836
|
+
base: external_exports.string().min(1).max(200).default("HEAD").describe(
|
|
22837
|
+
"Commit, branch or tag to compare the working tree with (HEAD, so the uncommitted changes, by default; main for a whole branch)."
|
|
22838
|
+
)
|
|
22839
|
+
}).strict();
|
|
22199
22840
|
var locatorSchema = MapObjectLocatorSchema.describe(
|
|
22200
22841
|
"Declaration location: path and UTF-16 start offset; include kind to distinguish declarations at the same offset."
|
|
22201
22842
|
);
|
|
@@ -22216,10 +22857,11 @@ var mapReferencesInputSchema = (host) => external_exports.object({
|
|
|
22216
22857
|
"Provide exactly one symbol, entityRef or locator."
|
|
22217
22858
|
);
|
|
22218
22859
|
var mapToolDescriptions = (host) => {
|
|
22219
|
-
const lead = (tool) => host.lead ? `${host.lead[tool]} ` : "";
|
|
22860
|
+
const lead = (tool) => host.lead?.[tool] ? `${host.lead[tool]} ` : "";
|
|
22220
22861
|
return Object.freeze({
|
|
22221
|
-
search: `${lead("search")}Find declarations and files whose names, paths or source documentation match query terms. ANY (default) matches any term, ALL requires every term, LITERAL matches the exact text. Results are ranked by relevance and grouped by file with the declaration name, kind, 1-based line range and matched fields. Zoom into a result with project_explore_map({path,name}) or ${host.readResult}. This is not a full-text search and does not prove absence; ${host.textSearch}. Continue with offset and unchanged conditions.`,
|
|
22222
|
-
explore: `${lead("explore")}Read the static project map, zooming from the whole project to one declaration. path "." or a directory lists modules, module imports, external packages and its files: with exported declarations when the listing is small, as file names and line counts by directory when larger, and as modules only when very large. Start here to see what exists before searching or reading. A file path lists its declarations and members, imports, importers and top-level statements. A file path with name (or Container.member), optionally narrowed by its start line, or with a line alone, shows that declaration's calls, callers (including uses as a value), writes, heritage, decorators and members, aggregated per related declaration with @line sites; closures and locals are folded into their named container. depth also expands the related declarations hop by hop: up to 8 in one direction, which traces callers up to entry points (INCOMING) or callees down (OUTGOING), and up to 3 for BOTH. To find what a change affects, select the declaration with direction INCOMING and a depth up to 8, continue from any NOT EXPANDED declarations the view names, then confirm the entry points in source. Test files and standard-library call targets are hidden and counted by default; includeTests and includeUnresolved show them. ${host.readSource} The map is static:
|
|
22862
|
+
search: `${lead("search")}Find declarations and files whose names, paths or source documentation match query terms. ANY (default) matches any term, ALL requires every term, LITERAL matches the exact text. Results are ranked by relevance and grouped by file with the declaration name, kind, 1-based line range and matched fields (${MAP_KINDS_LEGEND}). Zoom into a result with project_explore_map({path,name}) or ${host.readResult}. This is not a full-text search and does not prove absence; ${host.textSearch}. Continue with offset and unchanged conditions.`,
|
|
22863
|
+
explore: `${lead("explore")}Read the static project map, zooming from the whole project to one declaration. path "." or a directory lists modules, module imports, external packages and its files: with exported declarations when the listing is small, as file names and line counts by directory when larger, and as modules only when very large. Start here to see what exists before searching or reading. A file path lists its declarations and members, imports, importers and top-level statements. A file path with name (or Container.member), optionally narrowed by its start line, or with a line alone, shows that declaration's calls, callers (including uses as a value), writes, heritage, decorators and members, aggregated per related declaration with @line sites; closures and locals are folded into their named container. depth also expands the related declarations hop by hop: up to 8 in one direction, which traces callers up to entry points (INCOMING) or callees down (OUTGOING), and up to 3 for BOTH. To find what a change affects, select the declaration with direction INCOMING and a depth up to 8, continue from any NOT EXPANDED declarations the view names, then confirm the entry points in source. Test files and standard-library call targets are hidden and counted by default; includeTests and includeUnresolved show them. Views use ${MAP_KINDS_LEGEND}. In a declaration view, ${MAP_DECLARATION_LEGEND} ${host.readSource} The map is static: trace stops, possible callers by name, framework wiring and unresolved targets need source reading, and a missing relationship does not prove absence. When a page reports more entries, continue with offset and otherwise unchanged arguments.`,
|
|
22864
|
+
check: `${lead("check")}Compares the working tree with a commit (HEAD by default, so uncommitted and untracked changes), finds the declarations the diff changed, removed or renamed, and follows their callers up to 8 levels. It reports, conclusion first: AFFECTED ENTRY POINTS reached through resolved calls, each route with its HTTP methods and full path and the chain to the change; POSSIBLY AFFECTED ones reached only through a call on an interface or base member; CHECK BY HAND for what a static map cannot follow (changed configuration, templates, migrations or dependency files, changed route registrations, declarations with no callers, calls by name on receivers of unknown type); and RELATED TESTS, the existing test files that call the changed code, import a changed file or sit beside it. It does not run or write tests: run the related ones if the change needs verifying, and confirm the entry points in source, since an empty list does not prove a change safe.`,
|
|
22223
22865
|
references: `${lead("references")}Compute usages of a mapped declaration from current source, including aliases, re-exports and non-call references. Select it with symbol {path,name,line?} as printed by project_explore_map or project_search_map (line is its start line when names repeat), or with an entityRef or locator {path,start,kind}. Broader and more expensive than the cached callers in project_explore_map; file or unsupported declarations may lack a reference target. path and kinds filter usage locations before paging. ${host.grantRules}objects contains compact declarations; targetRef and reference ownerRef identify them. ${host.readReference} A file that several compiler contexts read (such as packages of one workspace) lists its references once per context, each with that context's configPath. Continue with nextCursor and unchanged conditions, including after an empty partial page. Filtered exhaustion and missing results do not prove absence.`
|
|
22224
22866
|
});
|
|
22225
22867
|
};
|
|
@@ -22245,6 +22887,12 @@ var agentMapTools = [
|
|
|
22245
22887
|
title: "All usages of a declaration (LayerMap)",
|
|
22246
22888
|
description: descriptions.references,
|
|
22247
22889
|
schema: ReferencesInputSchema
|
|
22890
|
+
},
|
|
22891
|
+
{
|
|
22892
|
+
name: MAP_TOOL_NAMES.check,
|
|
22893
|
+
title: "What uncommitted changes affect (LayerMap)",
|
|
22894
|
+
description: descriptions.check,
|
|
22895
|
+
schema: ProjectMapCheckInputSchema
|
|
22248
22896
|
}
|
|
22249
22897
|
].map(({ schema, ...tool }) => {
|
|
22250
22898
|
const { $schema: _dialect, ...inputSchema } = external_exports.toJSONSchema(schema, { io: "input" });
|
|
@@ -22262,6 +22910,8 @@ var HINTS = {
|
|
|
22262
22910
|
PROJECT_READ_INPUT_INVALID: "The arguments do not describe a valid selection.",
|
|
22263
22911
|
PROJECT_PATH_INVALID: "Paths are relative to the project root, use / and contain no . or .. parts.",
|
|
22264
22912
|
PROJECT_MAP_REFERENCE_TARGET_UNAVAILABLE: "References are not available for this declaration; use its callers in project_explore_map.",
|
|
22913
|
+
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.",
|
|
22914
|
+
LAYERMAP_BASE_INVALID: "base names a commit, branch or tag, such as HEAD or main.",
|
|
22265
22915
|
LAYERMAP_NOT_A_GIT_REPOSITORY: "LayerMap maps Git repositories, and the agent was started outside one. Start it in a repository, or run layermap with --project naming one."
|
|
22266
22916
|
};
|
|
22267
22917
|
var describeMapError = (error51) => error51 instanceof ProjectEvidenceError ? `${error51.code}${HINTS[error51.code] ? `: ${HINTS[error51.code]}` : ""}` : void 0;
|
|
@@ -22292,6 +22942,10 @@ async function runMapTool(map2, name, args, signal) {
|
|
|
22292
22942
|
);
|
|
22293
22943
|
return { text: page.text + more(page.nextOffset), isError: false };
|
|
22294
22944
|
}
|
|
22945
|
+
if (name === MAP_TOOL_NAMES.check) {
|
|
22946
|
+
const input2 = parsed.data;
|
|
22947
|
+
return { text: (await map2.checkChanges(input2, signal)).text, isError: false };
|
|
22948
|
+
}
|
|
22295
22949
|
if (name === MAP_TOOL_NAMES.search) {
|
|
22296
22950
|
const input2 = parsed.data;
|
|
22297
22951
|
const page = await map2.search({ ...input2, path: mapDirectoryPath(input2.path) }, signal);
|
|
@@ -22305,8 +22959,8 @@ async function runMapTool(map2, name, args, signal) {
|
|
|
22305
22959
|
throw error51;
|
|
22306
22960
|
}
|
|
22307
22961
|
}
|
|
22308
|
-
var AGENT_MAP_INSTRUCTIONS = `Use the LayerMap tools before grep or reading files whenever a task asks what calls something, what a change affects, where something is used, or how the code is organized: 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. 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.`;
|
|
22309
|
-
var AGENT_MAP_NOTE = "The layermap MCP server is available here. For questions about what calls a function, what a change affects or where code is used, start with its project_explore_map tool (direction INCOMING, depth up to 8) before grep, then confirm in source.";
|
|
22962
|
+
var AGENT_MAP_INSTRUCTIONS = `Use the LayerMap tools before grep or reading files whenever a task asks what calls something, what a change affects, where something is used, or how the code is organized: 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. After editing code, call project_check_changes before reporting the work done: it lists the entry points and existing tests the changes reach. 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.`;
|
|
22963
|
+
var AGENT_MAP_NOTE = "The layermap MCP server is available here. For questions about what calls a function, what a change affects or where code is used, start with its project_explore_map tool (direction INCOMING, depth up to 8) before grep, then confirm in source. After editing code, call its project_check_changes tool before reporting the work done.";
|
|
22310
22964
|
|
|
22311
22965
|
// src/agent/mcp.ts
|
|
22312
22966
|
function serveMcp(options) {
|
|
@@ -22324,7 +22978,11 @@ function serveMcp(options) {
|
|
|
22324
22978
|
const session = new AbortController();
|
|
22325
22979
|
let warm;
|
|
22326
22980
|
const warmUp = () => {
|
|
22327
|
-
warm ??= map2().then((layermap) =>
|
|
22981
|
+
warm ??= map2().then(async (layermap) => {
|
|
22982
|
+
await layermap.refresh(session.signal);
|
|
22983
|
+
void layermap.prepareBase(session.signal).catch(() => {
|
|
22984
|
+
});
|
|
22985
|
+
}).catch((error51) => {
|
|
22328
22986
|
if (!session.signal.aborted) log2(`LayerMap could not build the map: ${String(error51)}`);
|
|
22329
22987
|
});
|
|
22330
22988
|
return warm;
|
|
@@ -22444,15 +23102,15 @@ import { execFile as execFile2 } from "node:child_process";
|
|
|
22444
23102
|
import { existsSync as existsSync5 } from "node:fs";
|
|
22445
23103
|
import { mkdir as mkdir2, readFile as readFile2, rm as rm2, writeFile as writeFile2 } from "node:fs/promises";
|
|
22446
23104
|
import { homedir as homedir2 } from "node:os";
|
|
22447
|
-
import
|
|
23105
|
+
import path10 from "node:path";
|
|
22448
23106
|
var SERVER = "layermap";
|
|
22449
23107
|
var SETUP_RULE = `mcp__${SERVER}`;
|
|
22450
23108
|
var PLUGIN_RULE = `mcp__plugin_${SERVER}_${SERVER}`;
|
|
22451
23109
|
var BEGIN = "<!-- layermap:begin -->";
|
|
22452
23110
|
var END = "<!-- layermap:end -->";
|
|
22453
23111
|
var mcpLaunchCommand = (version2) => {
|
|
22454
|
-
const script =
|
|
22455
|
-
if (script.includes(`${
|
|
23112
|
+
const script = path10.resolve(process.argv[1] ?? "");
|
|
23113
|
+
if (script.includes(`${path10.sep}_npx${path10.sep}`))
|
|
22456
23114
|
return ["npx", "-y", `layermap@${version2}`, "mcp"];
|
|
22457
23115
|
const execArgv = [];
|
|
22458
23116
|
for (let index = 0; index < process.execArgv.length; index++) {
|
|
@@ -22483,7 +23141,7 @@ async function allowInClaudeSettings(file2, rule = SETUP_RULE) {
|
|
|
22483
23141
|
throw new Error(`${file2} has permissions.allow that is not a list.`);
|
|
22484
23142
|
if (settings.permissions.allow.includes(rule)) return false;
|
|
22485
23143
|
settings.permissions.allow.push(rule);
|
|
22486
|
-
await mkdir2(
|
|
23144
|
+
await mkdir2(path10.dirname(file2), { recursive: true });
|
|
22487
23145
|
await writeFile2(file2, `${JSON.stringify(settings, null, 2)}
|
|
22488
23146
|
`);
|
|
22489
23147
|
return true;
|
|
@@ -22517,7 +23175,7 @@ ${END}`;
|
|
|
22517
23175
|
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}
|
|
22518
23176
|
`;
|
|
22519
23177
|
if (next === text) return;
|
|
22520
|
-
await mkdir2(
|
|
23178
|
+
await mkdir2(path10.dirname(file2), { recursive: true });
|
|
22521
23179
|
await writeFile2(file2, next);
|
|
22522
23180
|
}
|
|
22523
23181
|
async function removeInstructionNote(file2) {
|
|
@@ -22545,14 +23203,14 @@ async function disallowInClaudeSettings(file2) {
|
|
|
22545
23203
|
}
|
|
22546
23204
|
var YAML_BEGIN = "# layermap:begin";
|
|
22547
23205
|
var YAML_END = "# layermap:end";
|
|
22548
|
-
var nodeDirectory = (env = process.env) => (env.PATH ?? "").split(
|
|
22549
|
-
(directory) =>
|
|
22550
|
-
) ??
|
|
23206
|
+
var nodeDirectory = (env = process.env) => (env.PATH ?? "").split(path10.delimiter).find(
|
|
23207
|
+
(directory) => path10.isAbsolute(directory) && existsSync5(path10.join(directory, "node")) && existsSync5(path10.join(directory, "npx"))
|
|
23208
|
+
) ?? path10.dirname(process.execPath);
|
|
22551
23209
|
var dshPatchBlock = (command, env) => {
|
|
22552
23210
|
const node = nodeDirectory(env);
|
|
22553
|
-
const npx =
|
|
23211
|
+
const npx = path10.join(node, "npx");
|
|
22554
23212
|
const [program = "", ...args] = command[0] === "npx" && existsSync5(npx) ? [npx, ...command.slice(1)] : command;
|
|
22555
|
-
const searchPath = `${JSON.stringify(`${node}${
|
|
23213
|
+
const searchPath = `${JSON.stringify(`${node}${path10.delimiter}`)} + process.env.PATH`;
|
|
22556
23214
|
return [
|
|
22557
23215
|
`${YAML_BEGIN} (written by \`layermap setup dsh\`; \`layermap remove dsh\` deletes it)`,
|
|
22558
23216
|
"- insert:",
|
|
@@ -22587,7 +23245,7 @@ async function writeDshPatch(file2, block) {
|
|
|
22587
23245
|
`;
|
|
22588
23246
|
}
|
|
22589
23247
|
if (next === text) return;
|
|
22590
|
-
await mkdir2(
|
|
23248
|
+
await mkdir2(path10.dirname(file2), { recursive: true });
|
|
22591
23249
|
await writeFile2(file2, next);
|
|
22592
23250
|
}
|
|
22593
23251
|
async function removeDshPatch(file2) {
|
|
@@ -22605,31 +23263,31 @@ async function removeDshPatch(file2) {
|
|
|
22605
23263
|
var agentFiles = (options) => {
|
|
22606
23264
|
const env = options.env ?? process.env;
|
|
22607
23265
|
if (options.agent === "dsh") {
|
|
22608
|
-
const home = env.DSH_HOME ||
|
|
23266
|
+
const home = env.DSH_HOME || path10.join(homedir2(), ".dsh");
|
|
22609
23267
|
return {
|
|
22610
|
-
settings:
|
|
22611
|
-
instructions:
|
|
23268
|
+
settings: path10.join(home, "cordis.patch.yml"),
|
|
23269
|
+
instructions: path10.join(home, "AGENTS.md")
|
|
22612
23270
|
};
|
|
22613
23271
|
}
|
|
22614
23272
|
if (options.agent === "codex") {
|
|
22615
|
-
const home = env.CODEX_HOME ??
|
|
22616
|
-
return { settings:
|
|
23273
|
+
const home = env.CODEX_HOME ?? path10.join(homedir2(), ".codex");
|
|
23274
|
+
return { settings: path10.join(home, "config.toml"), instructions: path10.join(home, "AGENTS.md") };
|
|
22617
23275
|
}
|
|
22618
23276
|
if (options.scope === "user") {
|
|
22619
|
-
const home = env.CLAUDE_CONFIG_DIR ??
|
|
23277
|
+
const home = env.CLAUDE_CONFIG_DIR ?? path10.join(homedir2(), ".claude");
|
|
22620
23278
|
return {
|
|
22621
|
-
settings:
|
|
22622
|
-
instructions:
|
|
23279
|
+
settings: path10.join(home, "settings.json"),
|
|
23280
|
+
instructions: path10.join(home, "CLAUDE.md")
|
|
22623
23281
|
};
|
|
22624
23282
|
}
|
|
22625
23283
|
const local = options.scope === "local";
|
|
22626
23284
|
return {
|
|
22627
|
-
settings:
|
|
23285
|
+
settings: path10.join(
|
|
22628
23286
|
options.project,
|
|
22629
23287
|
".claude",
|
|
22630
23288
|
local ? "settings.local.json" : "settings.json"
|
|
22631
23289
|
),
|
|
22632
|
-
instructions:
|
|
23290
|
+
instructions: path10.join(options.project, local ? "CLAUDE.local.md" : "CLAUDE.md")
|
|
22633
23291
|
};
|
|
22634
23292
|
};
|
|
22635
23293
|
async function setupAgent(options) {
|
|
@@ -22734,6 +23392,7 @@ Usage:
|
|
|
22734
23392
|
[--depth N] [--tests] [--unresolved] [--offset N]
|
|
22735
23393
|
layermap search QUERY [--path DIR] [--mode ANY|ALL|LITERAL] [--max N] [--offset N]
|
|
22736
23394
|
layermap refs PATH NAME [--line N] [--path DIR] [--max N] [--cursor C]
|
|
23395
|
+
layermap check [--base REF] what the uncommitted changes (or those since REF) affect
|
|
22737
23396
|
|
|
22738
23397
|
The project is the Git work tree around the current directory unless --project names one.
|
|
22739
23398
|
Maps are kept in ${cacheDirectory()}.`;
|
|
@@ -22750,6 +23409,7 @@ async function main(argv) {
|
|
|
22750
23409
|
allowPositionals: true,
|
|
22751
23410
|
options: {
|
|
22752
23411
|
project: { type: "string" },
|
|
23412
|
+
base: { type: "string" },
|
|
22753
23413
|
scope: { type: "string", default: "user" },
|
|
22754
23414
|
"dry-run": { type: "boolean", default: false },
|
|
22755
23415
|
"no-instructions": { type: "boolean", default: false },
|
|
@@ -22776,10 +23436,10 @@ async function main(argv) {
|
|
|
22776
23436
|
return 0;
|
|
22777
23437
|
}
|
|
22778
23438
|
if (values.help || !command) return usage(command ? 0 : 1);
|
|
22779
|
-
const { directory: project, git } = await projectDirectory(values.project ?? process.cwd());
|
|
23439
|
+
const { directory: project, git: git2 } = await projectDirectory(values.project ?? process.cwd());
|
|
22780
23440
|
const cache = cacheDirectory();
|
|
22781
23441
|
const open2 = async () => {
|
|
22782
|
-
if (!
|
|
23442
|
+
if (!git2) throw new ProjectEvidenceError("LAYERMAP_NOT_A_GIT_REPOSITORY", false);
|
|
22783
23443
|
const map3 = await LayerMap.open({
|
|
22784
23444
|
project,
|
|
22785
23445
|
cacheDirectory: cache,
|
|
@@ -22845,6 +23505,7 @@ async function main(argv) {
|
|
|
22845
23505
|
offset: number4(values.offset)
|
|
22846
23506
|
}
|
|
22847
23507
|
],
|
|
23508
|
+
check: [MAP_TOOL_NAMES.check, { base: values.base }],
|
|
22848
23509
|
refs: [
|
|
22849
23510
|
MAP_TOOL_NAMES.references,
|
|
22850
23511
|
{
|