layermap 0.1.12 → 0.1.14
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 +10 -5
- package/analyzers/go/win32-arm64/go-map.exe +0 -0
- package/analyzers/go/win32-x64/go-map.exe +0 -0
- package/analyzers/project-map-go-worker.mjs +64 -26
- package/analyzers/project-map-java/java-map.jar +0 -0
- package/analyzers/project-map-java-worker.mjs +62 -28
- package/analyzers/project-map-python-worker.mjs +42 -41
- package/analyzers/project-map-worker.mjs +218 -200
- package/dist/cli.mjs +644 -388
- package/package.json +3 -2
package/dist/cli.mjs
CHANGED
|
@@ -12,28 +12,96 @@ 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
|
|
15
|
+
import { existsSync as existsSync5, readFileSync as readFileSync4 } 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 path11 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 path10 from "node:path";
|
|
27
27
|
import { DatabaseSync } from "@photostructure/sqlite";
|
|
28
28
|
|
|
29
29
|
// src/capture-policy.ts
|
|
30
|
-
import
|
|
30
|
+
import path3 from "node:path";
|
|
31
31
|
|
|
32
32
|
// src/file-universe.ts
|
|
33
|
-
import
|
|
33
|
+
import path2 from "node:path";
|
|
34
34
|
|
|
35
35
|
// src/git-runner.ts
|
|
36
36
|
import { spawn } from "node:child_process";
|
|
37
|
+
|
|
38
|
+
// src/platform.ts
|
|
39
|
+
import { spawnSync } from "node:child_process";
|
|
40
|
+
import { existsSync } from "node:fs";
|
|
41
|
+
import path from "node:path";
|
|
42
|
+
var executableName = (name, platform = process.platform) => platform === "win32" ? `${name}.exe` : name;
|
|
43
|
+
var searchPath = (env) => env.PATH ?? Object.entries(env).find(([name]) => name.toUpperCase() === "PATH")?.[1] ?? "";
|
|
44
|
+
function findOnPath(files, env, platform) {
|
|
45
|
+
const join = platform === "win32" ? path.win32.join : path.posix.join;
|
|
46
|
+
for (const directory of searchPath(env).split(platform === "win32" ? ";" : ":"))
|
|
47
|
+
for (const file2 of files)
|
|
48
|
+
if (directory && existsSync(join(directory, file2))) return join(directory, file2);
|
|
49
|
+
return void 0;
|
|
50
|
+
}
|
|
51
|
+
var findExecutable = (name, env = process.env, platform = process.platform) => findOnPath([executableName(name, platform)], env, platform);
|
|
52
|
+
var CMD_META = /([()\][%!^"`<>&|;, *?])/gu;
|
|
53
|
+
var cmdArgument = (value) => `"${value.replace(/(\\*)"/gu, '$1$1\\"').replace(/(\\*)$/u, "$1$1")}"`.replace(CMD_META, "^$1").replace(CMD_META, "^$1");
|
|
54
|
+
function commandInvocation(command, args, env = process.env, platform = process.platform) {
|
|
55
|
+
if (platform !== "win32") return { file: command, args: [...args] };
|
|
56
|
+
const program = findOnPath([`${command}.exe`, `${command}.cmd`, `${command}.bat`], env, platform);
|
|
57
|
+
if (!program || program.toLowerCase().endsWith(".exe"))
|
|
58
|
+
return { file: program ?? command, args: [...args] };
|
|
59
|
+
return cmdInvocation(program, args, env.ComSpec ?? process.env.ComSpec ?? "cmd.exe");
|
|
60
|
+
}
|
|
61
|
+
function cmdInvocation(script, args, comspec = "cmd.exe") {
|
|
62
|
+
const line = [script.replace(CMD_META, "^$1"), ...args.map(cmdArgument)].join(" ");
|
|
63
|
+
return { file: comspec, args: ["/d", "/s", "/c", `"${line}"`], windowsVerbatimArguments: true };
|
|
64
|
+
}
|
|
65
|
+
var WINDOWS_SYSTEM = [
|
|
66
|
+
"SystemRoot",
|
|
67
|
+
"windir",
|
|
68
|
+
"SystemDrive",
|
|
69
|
+
"TEMP",
|
|
70
|
+
"TMP",
|
|
71
|
+
"USERPROFILE",
|
|
72
|
+
"LOCALAPPDATA",
|
|
73
|
+
"APPDATA",
|
|
74
|
+
"PATHEXT",
|
|
75
|
+
"ComSpec"
|
|
76
|
+
];
|
|
77
|
+
function childEnvironment(variables, platform = process.platform, env = process.env) {
|
|
78
|
+
if (platform !== "win32") return variables;
|
|
79
|
+
const system = {};
|
|
80
|
+
for (const name of WINDOWS_SYSTEM) if (env[name] !== void 0) system[name] = env[name];
|
|
81
|
+
return { ...system, ...variables };
|
|
82
|
+
}
|
|
83
|
+
function stopProcessTree(pid, signal, platform = process.platform) {
|
|
84
|
+
if (platform !== "win32") {
|
|
85
|
+
process.kill(-pid, signal);
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
const taskkill = path.win32.join(
|
|
89
|
+
process.env.SystemRoot ?? "C:\\Windows",
|
|
90
|
+
"System32",
|
|
91
|
+
"taskkill.exe"
|
|
92
|
+
);
|
|
93
|
+
spawnSync(taskkill, ["/PID", String(pid), "/T", "/F"], { stdio: "ignore", windowsHide: true });
|
|
94
|
+
}
|
|
95
|
+
function processTreeGone(pid, platform = process.platform) {
|
|
96
|
+
try {
|
|
97
|
+
process.kill(platform === "win32" ? pid : -pid, 0);
|
|
98
|
+
return false;
|
|
99
|
+
} catch (error51) {
|
|
100
|
+
return error51.code === "ESRCH" ? true : void 0;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// src/git-runner.ts
|
|
37
105
|
var CONSTRAINED_CONFIG = [
|
|
38
106
|
"-c",
|
|
39
107
|
"core.fsmonitor=false",
|
|
@@ -66,8 +134,27 @@ var GitCommandStopUnconfirmedError = class extends GitCommandError {
|
|
|
66
134
|
this.name = "GitCommandStopUnconfirmedError";
|
|
67
135
|
}
|
|
68
136
|
};
|
|
137
|
+
function gitEnvironment() {
|
|
138
|
+
const windows = process.platform === "win32";
|
|
139
|
+
return childEnvironment({
|
|
140
|
+
LANG: process.env.LANG ?? "C",
|
|
141
|
+
LC_ALL: "C",
|
|
142
|
+
PATH: windows ? process.env.PATH ?? "" : "/usr/bin:/bin",
|
|
143
|
+
...windows ? {} : { TMPDIR: process.env.TMPDIR ?? "/tmp" },
|
|
144
|
+
GIT_ATTR_NOSYSTEM: "1",
|
|
145
|
+
GIT_CONFIG_COUNT: "0",
|
|
146
|
+
GIT_CONFIG_NOSYSTEM: "1",
|
|
147
|
+
GIT_CONFIG_GLOBAL: "/dev/null",
|
|
148
|
+
GIT_OPTIONAL_LOCKS: "0",
|
|
149
|
+
GIT_TERMINAL_PROMPT: "0",
|
|
150
|
+
GIT_PAGER: "cat",
|
|
151
|
+
PAGER: "cat",
|
|
152
|
+
...windows ? {} : { GIT_ASKPASS: "/usr/bin/false", SSH_ASKPASS: "/usr/bin/false" }
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
var defaultGit = () => process.platform === "win32" ? findExecutable("git") ?? "git.exe" : "/usr/bin/git";
|
|
69
156
|
var GitRunner = class {
|
|
70
|
-
constructor(executable =
|
|
157
|
+
constructor(executable = defaultGit()) {
|
|
71
158
|
this.executable = executable;
|
|
72
159
|
}
|
|
73
160
|
executable;
|
|
@@ -82,22 +169,8 @@ var GitRunner = class {
|
|
|
82
169
|
return new Promise((resolve, reject) => {
|
|
83
170
|
const child = spawn(this.executable, finalArgs, {
|
|
84
171
|
cwd: options.cwd,
|
|
85
|
-
env:
|
|
86
|
-
|
|
87
|
-
LC_ALL: "C",
|
|
88
|
-
PATH: "/usr/bin:/bin",
|
|
89
|
-
TMPDIR: process.env.TMPDIR ?? "/tmp",
|
|
90
|
-
GIT_ATTR_NOSYSTEM: "1",
|
|
91
|
-
GIT_CONFIG_COUNT: "0",
|
|
92
|
-
GIT_CONFIG_NOSYSTEM: "1",
|
|
93
|
-
GIT_CONFIG_GLOBAL: "/dev/null",
|
|
94
|
-
GIT_OPTIONAL_LOCKS: "0",
|
|
95
|
-
GIT_TERMINAL_PROMPT: "0",
|
|
96
|
-
GIT_PAGER: "cat",
|
|
97
|
-
PAGER: "cat",
|
|
98
|
-
GIT_ASKPASS: "/usr/bin/false",
|
|
99
|
-
SSH_ASKPASS: "/usr/bin/false"
|
|
100
|
-
},
|
|
172
|
+
env: gitEnvironment(),
|
|
173
|
+
windowsHide: true,
|
|
101
174
|
stdio: ["pipe", "pipe", "pipe"]
|
|
102
175
|
});
|
|
103
176
|
const stdout = [];
|
|
@@ -217,8 +290,8 @@ var parseFileUniverse = (output) => {
|
|
|
217
290
|
const records = output.toString("utf8").split("\0");
|
|
218
291
|
for (const record2 of records) {
|
|
219
292
|
if (record2.length === 0) continue;
|
|
220
|
-
const normalized =
|
|
221
|
-
if (normalized !== record2 || normalized === "." || normalized === ".." || normalized.startsWith("../") ||
|
|
293
|
+
const normalized = path2.posix.normalize(record2);
|
|
294
|
+
if (normalized !== record2 || normalized === "." || normalized === ".." || normalized.startsWith("../") || path2.posix.isAbsolute(normalized) || normalized.includes("\\")) {
|
|
222
295
|
throw new ProjectEvidenceFileUniverseError("PROJECT_FILE_UNIVERSE_INVALID");
|
|
223
296
|
}
|
|
224
297
|
files.add(normalized);
|
|
@@ -430,7 +503,7 @@ var ProjectEvidencePolicyError = class extends Error {
|
|
|
430
503
|
var assertProjectEvidencePathNotSensitive = (relativePath) => {
|
|
431
504
|
const segments = relativePath.toLowerCase().split("/");
|
|
432
505
|
const basename = segments.at(-1) ?? "";
|
|
433
|
-
const extension =
|
|
506
|
+
const extension = path3.posix.extname(basename);
|
|
434
507
|
const containsSensitiveSequence = sensitiveSegmentSequences.some(
|
|
435
508
|
(sequence) => segments.length >= sequence.length && segments.some(
|
|
436
509
|
(_, start) => sequence.every((segment, offset) => segments[start + offset] === segment)
|
|
@@ -443,8 +516,8 @@ var assertProjectEvidencePathNotSensitive = (relativePath) => {
|
|
|
443
516
|
};
|
|
444
517
|
var isProjectEvidenceTraversalExcluded = (relativePath) => relativePath.toLowerCase().split("/").some((segment) => traversalExcludedSegmentSet.has(segment));
|
|
445
518
|
var isProjectEvidenceTextPath = (relativePath) => {
|
|
446
|
-
const basename =
|
|
447
|
-
const extension =
|
|
519
|
+
const basename = path3.posix.basename(relativePath).toLowerCase();
|
|
520
|
+
const extension = path3.posix.extname(basename);
|
|
448
521
|
if (allowedTextBasenameSet.has(basename)) return true;
|
|
449
522
|
return extension ? allowedTextExtensionSet.has(extension) : allowedExtensionlessNameSet.has(basename);
|
|
450
523
|
};
|
|
@@ -453,7 +526,7 @@ var isProjectEvidenceTextPath = (relativePath) => {
|
|
|
453
526
|
import { createHash as createHash2 } from "node:crypto";
|
|
454
527
|
|
|
455
528
|
// src/core.ts
|
|
456
|
-
import
|
|
529
|
+
import path4 from "node:path";
|
|
457
530
|
|
|
458
531
|
// node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/classic/external.js
|
|
459
532
|
var external_exports = {};
|
|
@@ -1221,10 +1294,10 @@ function mergeDefs(...defs) {
|
|
|
1221
1294
|
function cloneDef(schema) {
|
|
1222
1295
|
return mergeDefs(schema._zod.def);
|
|
1223
1296
|
}
|
|
1224
|
-
function getElementAtPath(obj,
|
|
1225
|
-
if (!
|
|
1297
|
+
function getElementAtPath(obj, path13) {
|
|
1298
|
+
if (!path13)
|
|
1226
1299
|
return obj;
|
|
1227
|
-
return
|
|
1300
|
+
return path13.reduce((acc, key) => acc?.[key], obj);
|
|
1228
1301
|
}
|
|
1229
1302
|
function promiseAllObject(promisesObj) {
|
|
1230
1303
|
const keys = Object.keys(promisesObj);
|
|
@@ -1633,11 +1706,11 @@ function explicitlyAborted(x, startIndex = 0) {
|
|
|
1633
1706
|
}
|
|
1634
1707
|
return false;
|
|
1635
1708
|
}
|
|
1636
|
-
function prefixIssues(
|
|
1709
|
+
function prefixIssues(path13, issues) {
|
|
1637
1710
|
return issues.map((iss) => {
|
|
1638
1711
|
var _a3;
|
|
1639
1712
|
(_a3 = iss).path ?? (_a3.path = []);
|
|
1640
|
-
iss.path.unshift(
|
|
1713
|
+
iss.path.unshift(path13);
|
|
1641
1714
|
return iss;
|
|
1642
1715
|
});
|
|
1643
1716
|
}
|
|
@@ -1784,16 +1857,16 @@ function flattenError(error51, mapper = (issue2) => issue2.message) {
|
|
|
1784
1857
|
}
|
|
1785
1858
|
function formatError(error51, mapper = (issue2) => issue2.message) {
|
|
1786
1859
|
const fieldErrors = { _errors: [] };
|
|
1787
|
-
const processError = (error52,
|
|
1860
|
+
const processError = (error52, path13 = []) => {
|
|
1788
1861
|
for (const issue2 of error52.issues) {
|
|
1789
1862
|
if (issue2.code === "invalid_union" && issue2.errors.length) {
|
|
1790
|
-
issue2.errors.map((issues) => processError({ issues }, [...
|
|
1863
|
+
issue2.errors.map((issues) => processError({ issues }, [...path13, ...issue2.path]));
|
|
1791
1864
|
} else if (issue2.code === "invalid_key") {
|
|
1792
|
-
processError({ issues: issue2.issues }, [...
|
|
1865
|
+
processError({ issues: issue2.issues }, [...path13, ...issue2.path]);
|
|
1793
1866
|
} else if (issue2.code === "invalid_element") {
|
|
1794
|
-
processError({ issues: issue2.issues }, [...
|
|
1867
|
+
processError({ issues: issue2.issues }, [...path13, ...issue2.path]);
|
|
1795
1868
|
} else {
|
|
1796
|
-
const fullpath = [...
|
|
1869
|
+
const fullpath = [...path13, ...issue2.path];
|
|
1797
1870
|
if (fullpath.length === 0) {
|
|
1798
1871
|
fieldErrors._errors.push(mapper(issue2));
|
|
1799
1872
|
} else {
|
|
@@ -1820,17 +1893,17 @@ function formatError(error51, mapper = (issue2) => issue2.message) {
|
|
|
1820
1893
|
}
|
|
1821
1894
|
function treeifyError(error51, mapper = (issue2) => issue2.message) {
|
|
1822
1895
|
const result = { errors: [] };
|
|
1823
|
-
const processError = (error52,
|
|
1896
|
+
const processError = (error52, path13 = []) => {
|
|
1824
1897
|
var _a3, _b;
|
|
1825
1898
|
for (const issue2 of error52.issues) {
|
|
1826
1899
|
if (issue2.code === "invalid_union" && issue2.errors.length) {
|
|
1827
|
-
issue2.errors.map((issues) => processError({ issues }, [...
|
|
1900
|
+
issue2.errors.map((issues) => processError({ issues }, [...path13, ...issue2.path]));
|
|
1828
1901
|
} else if (issue2.code === "invalid_key") {
|
|
1829
|
-
processError({ issues: issue2.issues }, [...
|
|
1902
|
+
processError({ issues: issue2.issues }, [...path13, ...issue2.path]);
|
|
1830
1903
|
} else if (issue2.code === "invalid_element") {
|
|
1831
|
-
processError({ issues: issue2.issues }, [...
|
|
1904
|
+
processError({ issues: issue2.issues }, [...path13, ...issue2.path]);
|
|
1832
1905
|
} else {
|
|
1833
|
-
const fullpath = [...
|
|
1906
|
+
const fullpath = [...path13, ...issue2.path];
|
|
1834
1907
|
if (fullpath.length === 0) {
|
|
1835
1908
|
result.errors.push(mapper(issue2));
|
|
1836
1909
|
continue;
|
|
@@ -1862,8 +1935,8 @@ function treeifyError(error51, mapper = (issue2) => issue2.message) {
|
|
|
1862
1935
|
}
|
|
1863
1936
|
function toDotPath(_path) {
|
|
1864
1937
|
const segs = [];
|
|
1865
|
-
const
|
|
1866
|
-
for (const seg of
|
|
1938
|
+
const path13 = _path.map((seg) => typeof seg === "object" ? seg.key : seg);
|
|
1939
|
+
for (const seg of path13) {
|
|
1867
1940
|
if (typeof seg === "number")
|
|
1868
1941
|
segs.push(`[${seg}]`);
|
|
1869
1942
|
else if (typeof seg === "symbol")
|
|
@@ -14555,13 +14628,13 @@ function resolveRef(ref, ctx) {
|
|
|
14555
14628
|
if (!ref.startsWith("#")) {
|
|
14556
14629
|
throw new Error("External $ref is not supported, only local refs (#/...) are allowed");
|
|
14557
14630
|
}
|
|
14558
|
-
const
|
|
14559
|
-
if (
|
|
14631
|
+
const path13 = ref.slice(1).split("/").filter(Boolean);
|
|
14632
|
+
if (path13.length === 0) {
|
|
14560
14633
|
return ctx.rootSchema;
|
|
14561
14634
|
}
|
|
14562
14635
|
const defsKey = ctx.version === "draft-2020-12" ? "$defs" : "definitions";
|
|
14563
|
-
if (
|
|
14564
|
-
const key =
|
|
14636
|
+
if (path13[0] === defsKey) {
|
|
14637
|
+
const key = path13[1];
|
|
14565
14638
|
if (!key || !ctx.defs[key]) {
|
|
14566
14639
|
throw new Error(`Reference not found: ${ref}`);
|
|
14567
14640
|
}
|
|
@@ -14989,14 +15062,14 @@ var ProjectEvidencePathError = class extends Error {
|
|
|
14989
15062
|
code;
|
|
14990
15063
|
};
|
|
14991
15064
|
var normalizeProjectEvidencePath = (value, allowRoot = false) => {
|
|
14992
|
-
if (value.includes("\0") ||
|
|
15065
|
+
if (value.includes("\0") || path4.isAbsolute(value) || value.includes("\\")) {
|
|
14993
15066
|
throw new ProjectEvidencePathError("PROJECT_PATH_INVALID");
|
|
14994
15067
|
}
|
|
14995
15068
|
if (value === ".") {
|
|
14996
15069
|
if (allowRoot) return "";
|
|
14997
15070
|
throw new ProjectEvidencePathError("PROJECT_PATH_INVALID");
|
|
14998
15071
|
}
|
|
14999
|
-
const normalized =
|
|
15072
|
+
const normalized = path4.posix.normalize(value);
|
|
15000
15073
|
if (normalized.length === 0 || normalized !== value || normalized === ".." || normalized.startsWith("../") || value.split("/").some((segment) => segment.length === 0 || segment === "." || segment === "..")) {
|
|
15001
15074
|
throw new ProjectEvidencePathError("PROJECT_PATH_INVALID");
|
|
15002
15075
|
}
|
|
@@ -15148,14 +15221,14 @@ var CodeCommitReader = class _CodeCommitReader {
|
|
|
15148
15221
|
// src/code-worktree-reader.ts
|
|
15149
15222
|
import { constants as fsConstants } from "node:fs";
|
|
15150
15223
|
import { lstat, open, realpath } from "node:fs/promises";
|
|
15151
|
-
import
|
|
15224
|
+
import path5 from "node:path";
|
|
15152
15225
|
var fileSystemErrorCode = (error51) => {
|
|
15153
15226
|
if (typeof error51 !== "object" || error51 === null || !("code" in error51)) return void 0;
|
|
15154
15227
|
return typeof error51.code === "string" ? error51.code : void 0;
|
|
15155
15228
|
};
|
|
15156
15229
|
var isInsideRoot = (root, candidate) => {
|
|
15157
|
-
const relative =
|
|
15158
|
-
return relative === "" || !relative.startsWith(`..${
|
|
15230
|
+
const relative = path5.relative(root, candidate);
|
|
15231
|
+
return relative === "" || !relative.startsWith(`..${path5.sep}`) && relative !== "..";
|
|
15159
15232
|
};
|
|
15160
15233
|
var stablePathFingerprint = (stats) => [
|
|
15161
15234
|
stats.dev,
|
|
@@ -15198,7 +15271,7 @@ var StableProjectCaptureSession = class _StableProjectCaptureSession {
|
|
|
15198
15271
|
}
|
|
15199
15272
|
async captureFile(relativePath) {
|
|
15200
15273
|
this.assertNotAborted();
|
|
15201
|
-
const absolutePath =
|
|
15274
|
+
const absolutePath = path5.join(this.root, ...relativePath.split("/"));
|
|
15202
15275
|
const stats = await this.inspectPath(absolutePath, true);
|
|
15203
15276
|
const fingerprint = stablePathFingerprint(stats);
|
|
15204
15277
|
const byteLength = stats.isDirectory() ? 0 : Number(stats.size);
|
|
@@ -15320,11 +15393,11 @@ var StableProjectCaptureSession = class _StableProjectCaptureSession {
|
|
|
15320
15393
|
if (!isInsideRoot(this.root, absolutePath)) {
|
|
15321
15394
|
throw new ProjectEvidenceError("PROJECT_PATH_OUTSIDE_ROOT", false);
|
|
15322
15395
|
}
|
|
15323
|
-
const relative =
|
|
15324
|
-
const components = relative === "" ? [] : relative.split(
|
|
15396
|
+
const relative = path5.relative(this.root, absolutePath);
|
|
15397
|
+
const components = relative === "" ? [] : relative.split(path5.sep);
|
|
15325
15398
|
const paths = [
|
|
15326
15399
|
this.root,
|
|
15327
|
-
...components.map((_, index) =>
|
|
15400
|
+
...components.map((_, index) => path5.join(this.root, ...components.slice(0, index + 1)))
|
|
15328
15401
|
];
|
|
15329
15402
|
let finalStats;
|
|
15330
15403
|
for (const [index, currentPath] of paths.entries()) {
|
|
@@ -15365,7 +15438,7 @@ var StableProjectCaptureSession = class _StableProjectCaptureSession {
|
|
|
15365
15438
|
};
|
|
15366
15439
|
|
|
15367
15440
|
// src/source-scope.ts
|
|
15368
|
-
import
|
|
15441
|
+
import path6 from "node:path";
|
|
15369
15442
|
var InitialEvidenceScopeSchema = external_exports.object({
|
|
15370
15443
|
pathPrefixes: external_exports.array(ProjectEvidenceGrantPathPrefixSchema).min(1).max(64)
|
|
15371
15444
|
}).strict();
|
|
@@ -15448,7 +15521,7 @@ var includesInitialEvidencePath = (relativePath, scope) => {
|
|
|
15448
15521
|
const segments = relativePath.toLowerCase().split("/");
|
|
15449
15522
|
if (segments.slice(0, -1).some((segment) => excluded.has(segment))) return false;
|
|
15450
15523
|
const basename = segments.at(-1) ?? "";
|
|
15451
|
-
return extensions.has(
|
|
15524
|
+
return extensions.has(path6.posix.extname(basename)) || SOURCE_POLICY.documentationFiles.includes(basename) || SOURCE_POLICY.configurationFiles.includes(basename) || SOURCE_POLICY.workspaceFiles.includes(relativePath);
|
|
15452
15525
|
};
|
|
15453
15526
|
|
|
15454
15527
|
// src/code-index-capture.ts
|
|
@@ -15801,8 +15874,8 @@ var MapAnalysisSchema = external_exports.object({
|
|
|
15801
15874
|
var mapPathAllowed = (relative, prefixes) => prefixes.some(
|
|
15802
15875
|
(prefix) => prefix === "." || relative === prefix || relative.startsWith(`${prefix}/`)
|
|
15803
15876
|
);
|
|
15804
|
-
var mapTestPath = (
|
|
15805
|
-
|
|
15877
|
+
var mapTestPath = (path13) => /(?:^|\/)(?:__tests__|tests?|fixtures?|e2e|testdata)(?:\/|$)|\.(?:spec|test)\.|_test\.(?:go|py)$|(?:^|\/)(?:test_[^/]*\.py|conftest\.py)$/iu.test(
|
|
15878
|
+
path13
|
|
15806
15879
|
);
|
|
15807
15880
|
|
|
15808
15881
|
// src/project-map-reference-types.ts
|
|
@@ -15886,11 +15959,11 @@ var string4 = (value) => {
|
|
|
15886
15959
|
var identity = (id2, reconstructed) => id2 === reconstructed ? [] : [JSON.stringify(id2)];
|
|
15887
15960
|
function encodeMapText(graph) {
|
|
15888
15961
|
const files = /* @__PURE__ */ new Map();
|
|
15889
|
-
const file2 = (
|
|
15890
|
-
let ref = files.get(
|
|
15962
|
+
const file2 = (path13) => {
|
|
15963
|
+
let ref = files.get(path13);
|
|
15891
15964
|
if (!ref) {
|
|
15892
15965
|
ref = `F${files.size + 1}`;
|
|
15893
|
-
files.set(
|
|
15966
|
+
files.set(path13, ref);
|
|
15894
15967
|
}
|
|
15895
15968
|
return ref;
|
|
15896
15969
|
};
|
|
@@ -15938,7 +16011,7 @@ function encodeMapText(graph) {
|
|
|
15938
16011
|
rows.push(`B ${node(frontier.entityRef)} ${frontier.direction}`);
|
|
15939
16012
|
return [
|
|
15940
16013
|
...header,
|
|
15941
|
-
...[...files].map(([
|
|
16014
|
+
...[...files].map(([path13, ref]) => `${ref} ${JSON.stringify(path13)}`),
|
|
15942
16015
|
...rows
|
|
15943
16016
|
].join("\n");
|
|
15944
16017
|
}
|
|
@@ -15958,10 +16031,10 @@ function decodeMapText(text) {
|
|
|
15958
16031
|
const at = (value) => {
|
|
15959
16032
|
const match = /^(F[1-9]\d*):(\d+)-(\d+)@(\d+)-(\d+)$/u.exec(value ?? "");
|
|
15960
16033
|
if (!match) return failed();
|
|
15961
|
-
const
|
|
15962
|
-
if (
|
|
16034
|
+
const path13 = files.get(match[1] ?? "");
|
|
16035
|
+
if (path13 === void 0) return failed();
|
|
15963
16036
|
return MapAnchorSchema.parse({
|
|
15964
|
-
path:
|
|
16037
|
+
path: path13,
|
|
15965
16038
|
startLine: Number(match[2]),
|
|
15966
16039
|
endLine: Number(match[3]),
|
|
15967
16040
|
start: Number(match[4]),
|
|
@@ -16038,8 +16111,8 @@ function decodeMapText(text) {
|
|
|
16038
16111
|
var locationSchema = MapAnchorSchema.describe(
|
|
16039
16112
|
"Source location: start/end are zero-based UTF-16 offsets with an exclusive end; line numbers are one-based."
|
|
16040
16113
|
);
|
|
16041
|
-
var location = ({ path:
|
|
16042
|
-
path:
|
|
16114
|
+
var location = ({ path: path13, startLine, endLine, start, end }) => ({
|
|
16115
|
+
path: path13,
|
|
16043
16116
|
startLine,
|
|
16044
16117
|
endLine,
|
|
16045
16118
|
start,
|
|
@@ -16142,11 +16215,11 @@ var MapNavigationObjectsSchema = external_exports.union([
|
|
|
16142
16215
|
),
|
|
16143
16216
|
external_exports.object({ files: external_exports.array(searchFileSchema) }).passthrough().refine((value) => !("format" in value), "Text navigation must decode through its format.").transform(
|
|
16144
16217
|
(value) => value.files.flatMap(
|
|
16145
|
-
({ path:
|
|
16218
|
+
({ path: path13, symbols }) => symbols.map(({ id: id2, name, kind, startLine, endLine, start, end, execution }) => ({
|
|
16146
16219
|
id: id2,
|
|
16147
16220
|
name,
|
|
16148
16221
|
kind,
|
|
16149
|
-
anchor: { path:
|
|
16222
|
+
anchor: { path: path13, startLine, endLine, start, end },
|
|
16150
16223
|
...execution ? { execution } : {}
|
|
16151
16224
|
}))
|
|
16152
16225
|
)
|
|
@@ -16159,10 +16232,10 @@ var mapSearchNavigation = (result) => {
|
|
|
16159
16232
|
for (const [index, object2] of found.entries()) {
|
|
16160
16233
|
const ranking = rankings[index];
|
|
16161
16234
|
if (!ranking) throw new Error("PROJECT_MAP_SEARCH_RANKING_MISSING");
|
|
16162
|
-
const
|
|
16235
|
+
const path13 = object2.anchor.path;
|
|
16163
16236
|
let file2 = files.at(-1);
|
|
16164
|
-
if (file2?.path !==
|
|
16165
|
-
file2 = { path:
|
|
16237
|
+
if (file2?.path !== path13) {
|
|
16238
|
+
file2 = { path: path13, symbols: [] };
|
|
16166
16239
|
files.push(file2);
|
|
16167
16240
|
}
|
|
16168
16241
|
file2.symbols.push({
|
|
@@ -16288,8 +16361,8 @@ var MapViewGraph = class {
|
|
|
16288
16361
|
}
|
|
16289
16362
|
return object2;
|
|
16290
16363
|
}
|
|
16291
|
-
objectsAt(
|
|
16292
|
-
return this.statements.path.all(this.version,
|
|
16364
|
+
objectsAt(path13) {
|
|
16365
|
+
return this.statements.path.all(this.version, path13).map((row) => {
|
|
16293
16366
|
const object2 = MapObjectSchema.parse(JSON.parse(String(row.object_json)));
|
|
16294
16367
|
this.objects.set(object2.id, object2);
|
|
16295
16368
|
return object2;
|
|
@@ -16408,8 +16481,8 @@ var MapViewGraph = class {
|
|
|
16408
16481
|
);
|
|
16409
16482
|
}
|
|
16410
16483
|
};
|
|
16411
|
-
function mapSelectDeclarations(graph,
|
|
16412
|
-
const objects2 = graph.objectsAt(
|
|
16484
|
+
function mapSelectDeclarations(graph, path13, name, line) {
|
|
16485
|
+
const objects2 = graph.objectsAt(path13).filter((object2) => !mapIsModule(object2));
|
|
16413
16486
|
const matching = name === void 0 ? objects2 : objects2.filter(
|
|
16414
16487
|
(object2) => object2.name === name || name.includes(".") && graph.qualifiedName(object2.id) === name
|
|
16415
16488
|
);
|
|
@@ -16431,12 +16504,12 @@ function requireMapObject(store, version2, selector, prefixes) {
|
|
|
16431
16504
|
if ([entityRef, locator, symbol2].filter((value) => value !== void 0).length !== 1 || entityRef !== void 0 && !entityRef.length)
|
|
16432
16505
|
throw new ProjectEvidenceError("PROJECT_READ_INPUT_INVALID", false);
|
|
16433
16506
|
if (symbol2) {
|
|
16434
|
-
const
|
|
16435
|
-
if (!mapPathAllowed(
|
|
16507
|
+
const path13 = normalizeProjectEvidencePath(symbol2.path);
|
|
16508
|
+
if (!mapPathAllowed(path13, prefixes))
|
|
16436
16509
|
throw new ProjectEvidenceError("PROJECT_MAP_OBJECT_NOT_FOUND", false);
|
|
16437
16510
|
const selected = mapSelectDeclarations(
|
|
16438
16511
|
new MapViewGraph(store, version2),
|
|
16439
|
-
|
|
16512
|
+
path13,
|
|
16440
16513
|
symbol2.name,
|
|
16441
16514
|
symbol2.line
|
|
16442
16515
|
);
|
|
@@ -16447,14 +16520,14 @@ function requireMapObject(store, version2, selector, prefixes) {
|
|
|
16447
16520
|
}
|
|
16448
16521
|
let rows;
|
|
16449
16522
|
if (locator) {
|
|
16450
|
-
const
|
|
16523
|
+
const path13 = normalizeProjectEvidencePath(locator.path);
|
|
16451
16524
|
if (!Number.isSafeInteger(locator.start) || locator.start < 0 || locator.kind !== void 0 && !MapObjectKindSchema.safeParse(locator.kind).success)
|
|
16452
16525
|
throw new ProjectEvidenceError("PROJECT_READ_INPUT_INVALID", false);
|
|
16453
|
-
if (!mapPathAllowed(
|
|
16526
|
+
if (!mapPathAllowed(path13, prefixes))
|
|
16454
16527
|
throw new ProjectEvidenceError("PROJECT_MAP_OBJECT_NOT_FOUND", false);
|
|
16455
16528
|
rows = store.database.prepare(`SELECT object_json FROM project_map_objects
|
|
16456
16529
|
WHERE version_ref = ? AND path = ? AND json_extract(object_json, '$.anchor.start') = ?
|
|
16457
|
-
AND (? IS NULL OR kind = ?) LIMIT 2`).all(version2,
|
|
16530
|
+
AND (? IS NULL OR kind = ?) LIMIT 2`).all(version2, path13, locator.start, locator.kind ?? null, locator.kind ?? null);
|
|
16458
16531
|
} else {
|
|
16459
16532
|
rows = store.database.prepare(
|
|
16460
16533
|
"SELECT object_json FROM project_map_objects WHERE version_ref = ? AND entity_ref = ?"
|
|
@@ -16495,13 +16568,13 @@ function mapQueryPage(count, materialize, navigation, budget) {
|
|
|
16495
16568
|
|
|
16496
16569
|
// src/project-map-query-selection.ts
|
|
16497
16570
|
var mapQuerySelection = (input, knownKinds) => {
|
|
16498
|
-
const
|
|
16571
|
+
const path13 = normalizeProjectEvidencePath(input.path ?? ".", true) || ".";
|
|
16499
16572
|
const kinds = input.kinds ?? knownKinds;
|
|
16500
16573
|
if (!Array.isArray(kinds) || !kinds.length || kinds.length > knownKinds.length || kinds.some((kind) => !knownKinds.includes(kind)))
|
|
16501
16574
|
throw new ProjectEvidenceError("PROJECT_READ_INPUT_INVALID", false);
|
|
16502
|
-
return { path:
|
|
16575
|
+
return { path: path13, kinds: [...new Set(kinds)].sort() };
|
|
16503
16576
|
};
|
|
16504
|
-
var mapQueryPathMatches = (
|
|
16577
|
+
var mapQueryPathMatches = (path13, prefix) => prefix === "." || path13 === prefix || path13.startsWith(`${prefix}/`);
|
|
16505
16578
|
var mapQueryPathSql = (column) => `(? = '.' OR ${column} = ? OR substr(${column}, 1, length(?) + 1) = ? || '/')`;
|
|
16506
16579
|
|
|
16507
16580
|
// src/project-map-search-focus.ts
|
|
@@ -16599,7 +16672,7 @@ var declarationKinds = /* @__PURE__ */ new Set([
|
|
|
16599
16672
|
"METHOD",
|
|
16600
16673
|
"TYPE"
|
|
16601
16674
|
]);
|
|
16602
|
-
var fileStem = (
|
|
16675
|
+
var fileStem = (path13) => path13.slice(path13.lastIndexOf("/") + 1).replace(/\.(?:[cm]?[jt]sx?|vue|svelte|go|pyi?)$/iu, "");
|
|
16603
16676
|
var compareText = (left, right) => left < right ? -1 : left > right ? 1 : 0;
|
|
16604
16677
|
var compareRows = (left, right) => right.ranking.score - left.ranking.score || compareText(left.object.anchor.path, right.object.anchor.path) || compareText(left.object.id, right.object.id);
|
|
16605
16678
|
function mapSearchQuery(input) {
|
|
@@ -16626,10 +16699,10 @@ function mapSearchQuery(input) {
|
|
|
16626
16699
|
}
|
|
16627
16700
|
function rank(object2, documentation, relationCount, query, focus) {
|
|
16628
16701
|
const name = object2.name.toLowerCase();
|
|
16629
|
-
const
|
|
16702
|
+
const path13 = object2.anchor.path.toLowerCase();
|
|
16630
16703
|
const values = {
|
|
16631
16704
|
NAME: [name],
|
|
16632
|
-
PATH: [
|
|
16705
|
+
PATH: [path13],
|
|
16633
16706
|
DOCUMENTATION: documentation.map((text) => text.toLowerCase())
|
|
16634
16707
|
};
|
|
16635
16708
|
const matched = query.terms.map((term) => ({
|
|
@@ -16654,12 +16727,12 @@ function rank(object2, documentation, relationCount, query, focus) {
|
|
|
16654
16727
|
score += 7e3;
|
|
16655
16728
|
signals.push("SYMBOL_CONTAINS");
|
|
16656
16729
|
} else if (matchedFields.includes("NAME")) signals.push("SYMBOL_CONTAINS");
|
|
16657
|
-
if (object2.kind === "FILE" && fileStem(
|
|
16730
|
+
if (object2.kind === "FILE" && fileStem(path13) === normalizedQuery) {
|
|
16658
16731
|
score += 11e3;
|
|
16659
16732
|
signals.push("EXACT_FILE_STEM");
|
|
16660
16733
|
}
|
|
16661
16734
|
if (matchedFields.includes("PATH")) {
|
|
16662
|
-
score +=
|
|
16735
|
+
score += path13.includes(normalizedQuery) ? 2500 : 0;
|
|
16663
16736
|
signals.push("PATH_CONTAINS");
|
|
16664
16737
|
}
|
|
16665
16738
|
if (matchedFields.includes("DOCUMENTATION")) {
|
|
@@ -16674,8 +16747,8 @@ function rank(object2, documentation, relationCount, query, focus) {
|
|
|
16674
16747
|
score += kindWeight[object2.kind] + Math.min(1200, relationCount * 20) + (focus?.score ?? 0);
|
|
16675
16748
|
if (declarationKinds.has(object2.kind)) signals.push("DECLARATION");
|
|
16676
16749
|
if (relationCount > 0) signals.push("GRAPH_CONNECTED");
|
|
16677
|
-
const isTest = mapTestPath(
|
|
16678
|
-
const isGenerated = generatedPath.test(
|
|
16750
|
+
const isTest = mapTestPath(path13);
|
|
16751
|
+
const isGenerated = generatedPath.test(path13);
|
|
16679
16752
|
const hasTestIntent = query.terms.some((term) => testQuery.test(term));
|
|
16680
16753
|
score += isTest ? hasTestIntent ? 1e3 : -5e3 : 300;
|
|
16681
16754
|
score += isGenerated ? -3e3 : 300;
|
|
@@ -16974,7 +17047,7 @@ function mapPageFrontier(frontier, rows) {
|
|
|
16974
17047
|
}
|
|
16975
17048
|
|
|
16976
17049
|
// src/project-map-language-go.ts
|
|
16977
|
-
import { existsSync as
|
|
17050
|
+
import { existsSync as existsSync3 } from "node:fs";
|
|
16978
17051
|
|
|
16979
17052
|
// src/project-map-analysis-validation.ts
|
|
16980
17053
|
function validateMapAnalysis(analysis, input) {
|
|
@@ -17159,13 +17232,13 @@ function utf16Offsets(text) {
|
|
|
17159
17232
|
}
|
|
17160
17233
|
function offsetConverter(files, offsets) {
|
|
17161
17234
|
const converters = /* @__PURE__ */ new Map();
|
|
17162
|
-
return (
|
|
17163
|
-
let convert = converters.get(
|
|
17235
|
+
return (path13, offset) => {
|
|
17236
|
+
let convert = converters.get(path13);
|
|
17164
17237
|
if (!convert) {
|
|
17165
|
-
const text = files[
|
|
17238
|
+
const text = files[path13];
|
|
17166
17239
|
if (text === void 0) return invalid();
|
|
17167
17240
|
convert = offsets === "UTF16" ? (value) => value <= text.length ? value : invalid() : utf16Offsets(text);
|
|
17168
|
-
converters.set(
|
|
17241
|
+
converters.set(path13, convert);
|
|
17169
17242
|
}
|
|
17170
17243
|
return convert(offset);
|
|
17171
17244
|
};
|
|
@@ -17196,7 +17269,7 @@ function mapFactsAnalysis(facts, input, context) {
|
|
|
17196
17269
|
const collect = new MapOutputCollector(output);
|
|
17197
17270
|
const positions = new MapSourcePositions(input.files);
|
|
17198
17271
|
const offset = offsetConverter(input.files, context.offsets);
|
|
17199
|
-
const anchor = (
|
|
17272
|
+
const anchor = (path13, start, end) => positions.span(path13, offset(path13, start), offset(path13, end));
|
|
17200
17273
|
const located = /* @__PURE__ */ new Map();
|
|
17201
17274
|
const canonical = /* @__PURE__ */ new Map();
|
|
17202
17275
|
const bySpan = /* @__PURE__ */ new Map();
|
|
@@ -17361,8 +17434,8 @@ function mapReferencesPage(facts, files, reference, offsets) {
|
|
|
17361
17434
|
|
|
17362
17435
|
// src/project-map-process.ts
|
|
17363
17436
|
import { execFileSync, spawn as spawn2 } from "node:child_process";
|
|
17364
|
-
import { existsSync, readFileSync, realpathSync } from "node:fs";
|
|
17365
|
-
import
|
|
17437
|
+
import { existsSync as existsSync2, readFileSync, realpathSync } from "node:fs";
|
|
17438
|
+
import path7 from "node:path";
|
|
17366
17439
|
|
|
17367
17440
|
// src/project-map-failure.ts
|
|
17368
17441
|
var PhaseSchema = external_exports.enum([
|
|
@@ -17487,24 +17560,24 @@ var ProjectMapStopUnconfirmedError = class extends ProjectEvidenceError {
|
|
|
17487
17560
|
}
|
|
17488
17561
|
};
|
|
17489
17562
|
var installedMapParserResources = () => {
|
|
17490
|
-
const directory =
|
|
17563
|
+
const directory = path7.dirname(path7.resolve(process.argv[1] ?? "."));
|
|
17491
17564
|
return {
|
|
17492
|
-
workerPath:
|
|
17493
|
-
compilerPath:
|
|
17565
|
+
workerPath: path7.join(directory, "project-map-worker.mjs"),
|
|
17566
|
+
compilerPath: path7.join(directory, "project-map-native/tsc")
|
|
17494
17567
|
};
|
|
17495
17568
|
};
|
|
17496
17569
|
var installedPythonMapResources = () => {
|
|
17497
|
-
const directory =
|
|
17570
|
+
const directory = path7.dirname(path7.resolve(process.argv[1] ?? "."));
|
|
17498
17571
|
return {
|
|
17499
|
-
workerPath:
|
|
17500
|
-
compilerPath:
|
|
17572
|
+
workerPath: path7.join(directory, "project-map-python-worker.mjs"),
|
|
17573
|
+
compilerPath: path7.join(directory, "project-map-python/typeshed")
|
|
17501
17574
|
};
|
|
17502
17575
|
};
|
|
17503
17576
|
function discoverJavaRuntime(env = process.env) {
|
|
17504
17577
|
const homes = [env.LAYERMAP_JAVA_HOME, env.JAVA_HOME];
|
|
17505
|
-
for (const directory of (env.PATH ?? "").split(
|
|
17506
|
-
const java =
|
|
17507
|
-
if (directory &&
|
|
17578
|
+
for (const directory of (env.PATH ?? env.Path ?? "").split(path7.delimiter)) {
|
|
17579
|
+
const java = path7.join(directory, executableName("java"));
|
|
17580
|
+
if (directory && existsSync2(java)) homes.push(path7.dirname(path7.dirname(realpathSync(java))));
|
|
17508
17581
|
}
|
|
17509
17582
|
homes.push(
|
|
17510
17583
|
...["/opt/homebrew/opt", "/usr/local/opt"].flatMap(
|
|
@@ -17512,7 +17585,7 @@ function discoverJavaRuntime(env = process.env) {
|
|
|
17512
17585
|
(formula) => `${prefix}/${formula}/libexec/openjdk.jdk/Contents/Home`
|
|
17513
17586
|
)
|
|
17514
17587
|
),
|
|
17515
|
-
...env.HOME ? [
|
|
17588
|
+
...env.HOME ? [path7.join(env.HOME, ".sdkman/candidates/java/current")] : []
|
|
17516
17589
|
);
|
|
17517
17590
|
if (process.platform === "darwin")
|
|
17518
17591
|
try {
|
|
@@ -17527,11 +17600,12 @@ function discoverJavaRuntime(env = process.env) {
|
|
|
17527
17600
|
}
|
|
17528
17601
|
for (const home of homes) {
|
|
17529
17602
|
if (!home) continue;
|
|
17530
|
-
const runtimePath =
|
|
17531
|
-
if (!
|
|
17603
|
+
const runtimePath = path7.join(home, "bin", executableName("java"));
|
|
17604
|
+
if (!existsSync2(runtimePath) || !existsSync2(path7.join(home, "bin", executableName("javac"))))
|
|
17605
|
+
continue;
|
|
17532
17606
|
let release = "";
|
|
17533
17607
|
try {
|
|
17534
|
-
release = readFileSync(
|
|
17608
|
+
release = readFileSync(path7.join(home, "release"), "utf8");
|
|
17535
17609
|
} catch {
|
|
17536
17610
|
continue;
|
|
17537
17611
|
}
|
|
@@ -17542,28 +17616,26 @@ function discoverJavaRuntime(env = process.env) {
|
|
|
17542
17616
|
return void 0;
|
|
17543
17617
|
}
|
|
17544
17618
|
var installedJavaMapResources = () => {
|
|
17545
|
-
const directory =
|
|
17546
|
-
const compilerPath =
|
|
17619
|
+
const directory = path7.dirname(path7.resolve(process.argv[1] ?? "."));
|
|
17620
|
+
const compilerPath = path7.join(directory, "project-map-java/java-map.jar");
|
|
17547
17621
|
return {
|
|
17548
|
-
workerPath:
|
|
17622
|
+
workerPath: path7.join(directory, "project-map-java-worker.mjs"),
|
|
17549
17623
|
compilerPath,
|
|
17550
17624
|
// A build without a JDK leaves no analyzer to run, whatever runtime this machine has.
|
|
17551
|
-
...
|
|
17625
|
+
...existsSync2(compilerPath) ? discoverJavaRuntime() : {}
|
|
17552
17626
|
};
|
|
17553
17627
|
};
|
|
17554
17628
|
var installedGoMapResources = () => {
|
|
17555
|
-
const directory =
|
|
17629
|
+
const directory = path7.dirname(path7.resolve(process.argv[1] ?? "."));
|
|
17556
17630
|
return {
|
|
17557
|
-
workerPath:
|
|
17558
|
-
compilerPath:
|
|
17631
|
+
workerPath: path7.join(directory, "project-map-go-worker.mjs"),
|
|
17632
|
+
compilerPath: path7.join(directory, "project-map-go/go-map")
|
|
17559
17633
|
};
|
|
17560
17634
|
};
|
|
17561
17635
|
function runMapOperation(resources, input, schema, signal, observeTiming) {
|
|
17562
|
-
if (process.platform === "win32")
|
|
17563
|
-
return Promise.reject(new ProjectEvidenceError("PROJECT_MAP_PLATFORM_UNSUPPORTED", false));
|
|
17564
17636
|
if (signal.aborted)
|
|
17565
17637
|
return Promise.reject(new ProjectEvidenceError("PROJECT_READ_CANCELLED", true));
|
|
17566
|
-
if (!
|
|
17638
|
+
if (!path7.isAbsolute(resources.workerPath) || !path7.isAbsolute(resources.compilerPath)) {
|
|
17567
17639
|
return Promise.reject(
|
|
17568
17640
|
new ProjectEvidenceError("PROJECT_MAP_PARSER_CONFIGURATION_INVALID", false)
|
|
17569
17641
|
);
|
|
@@ -17584,14 +17656,15 @@ function runMapOperation(resources, input, schema, signal, observeTiming) {
|
|
|
17584
17656
|
return new Promise((resolve, reject) => {
|
|
17585
17657
|
const child = spawn2(process.execPath, [...resources.execArgv ?? [], resources.workerPath], {
|
|
17586
17658
|
detached: true,
|
|
17659
|
+
windowsHide: true,
|
|
17587
17660
|
stdio: ["ignore", "pipe", "pipe", "ipc"],
|
|
17588
|
-
env: {
|
|
17661
|
+
env: childEnvironment({
|
|
17589
17662
|
PATH: "/usr/bin:/bin",
|
|
17590
17663
|
LANG: "C",
|
|
17591
17664
|
HOME: process.env.HOME,
|
|
17592
17665
|
TMPDIR: process.env.TMPDIR,
|
|
17593
17666
|
ELECTRON_RUN_AS_NODE: "1"
|
|
17594
|
-
}
|
|
17667
|
+
})
|
|
17595
17668
|
});
|
|
17596
17669
|
let result;
|
|
17597
17670
|
let resultAt;
|
|
@@ -17613,7 +17686,7 @@ function runMapOperation(resources, input, schema, signal, observeTiming) {
|
|
|
17613
17686
|
const kill = (value) => {
|
|
17614
17687
|
if (!child.pid) return;
|
|
17615
17688
|
try {
|
|
17616
|
-
|
|
17689
|
+
stopProcessTree(child.pid, value);
|
|
17617
17690
|
} catch {
|
|
17618
17691
|
}
|
|
17619
17692
|
};
|
|
@@ -17731,11 +17804,7 @@ function runMapOperation(resources, input, schema, signal, observeTiming) {
|
|
|
17731
17804
|
const drained = async () => {
|
|
17732
17805
|
const until = Date.now() + PROJECT_MAP_LIMITS.stopMs;
|
|
17733
17806
|
while (child.pid) {
|
|
17734
|
-
|
|
17735
|
-
process.kill(-child.pid, 0);
|
|
17736
|
-
} catch (error51) {
|
|
17737
|
-
if (error51.code === "ESRCH") return true;
|
|
17738
|
-
}
|
|
17807
|
+
if (processTreeGone(child.pid)) return true;
|
|
17739
17808
|
if (Date.now() >= until) return false;
|
|
17740
17809
|
await new Promise((resolve2) => setTimeout(resolve2, 20));
|
|
17741
17810
|
}
|
|
@@ -17766,8 +17835,8 @@ var goModule = /(?:^|\/)go\.mod$/u;
|
|
|
17766
17835
|
var codeHosts = /* @__PURE__ */ new Set(["github.com", "gitlab.com", "bitbucket.org"]);
|
|
17767
17836
|
var GO_MAP_LANGUAGE = Object.freeze({
|
|
17768
17837
|
id: "go-1.24-map-v9",
|
|
17769
|
-
claims: (
|
|
17770
|
-
reads: (
|
|
17838
|
+
claims: (path13) => path13.endsWith(".go"),
|
|
17839
|
+
reads: (path13) => goModule.test(path13),
|
|
17771
17840
|
// A module path, or the standard library, whose first path element has no dot.
|
|
17772
17841
|
importName: (specifier) => {
|
|
17773
17842
|
const parts = specifier.split("/");
|
|
@@ -17776,7 +17845,7 @@ var GO_MAP_LANGUAGE = Object.freeze({
|
|
|
17776
17845
|
return parts.slice(0, size).join("/");
|
|
17777
17846
|
},
|
|
17778
17847
|
// Go imports a package: the directory of the file.
|
|
17779
|
-
importTarget: (
|
|
17848
|
+
importTarget: (path13) => `${path13.slice(0, path13.lastIndexOf("/") + 1) || "./"}`,
|
|
17780
17849
|
create: () => new GoMapAnalyzer()
|
|
17781
17850
|
});
|
|
17782
17851
|
var GO_GAPS = [
|
|
@@ -17822,12 +17891,12 @@ var GoMapAnalyzer = class {
|
|
|
17822
17891
|
}
|
|
17823
17892
|
}
|
|
17824
17893
|
async analyze(session, signal) {
|
|
17825
|
-
const modules = session.readable.map((entry) => entry.path).filter((
|
|
17826
|
-
const moduleOf = (
|
|
17894
|
+
const modules = session.readable.map((entry) => entry.path).filter((path13) => goModule.test(path13)).sort();
|
|
17895
|
+
const moduleOf = (path13) => {
|
|
17827
17896
|
let best;
|
|
17828
17897
|
for (const modFile of modules) {
|
|
17829
17898
|
const directory = modFile.slice(0, modFile.lastIndexOf("/") + 1);
|
|
17830
|
-
if (
|
|
17899
|
+
if (path13.startsWith(directory) && (!best || directory.length > best.lastIndexOf("/") + 1))
|
|
17831
17900
|
best = modFile;
|
|
17832
17901
|
}
|
|
17833
17902
|
return best;
|
|
@@ -17843,11 +17912,11 @@ var GoMapAnalyzer = class {
|
|
|
17843
17912
|
for (const modFile of [...groups.keys()].sort()) {
|
|
17844
17913
|
if (signal.aborted) throw new ProjectEvidenceError("PROJECT_READ_CANCELLED", true);
|
|
17845
17914
|
const files = /* @__PURE__ */ Object.create(null);
|
|
17846
|
-
for (const
|
|
17847
|
-
const text = session.texts[
|
|
17915
|
+
for (const path13 of [...groups.get(modFile) ?? [], ...modFile ? [modFile] : []]) {
|
|
17916
|
+
const text = session.texts[path13];
|
|
17848
17917
|
if (text === void 0)
|
|
17849
17918
|
throw new ProjectEvidenceError("PROJECT_MAP_PROTOCOL_INVALID", false);
|
|
17850
|
-
files[
|
|
17919
|
+
files[path13] = text;
|
|
17851
17920
|
}
|
|
17852
17921
|
const input = {
|
|
17853
17922
|
contextRef: digestValue({
|
|
@@ -17859,7 +17928,7 @@ var GoMapAnalyzer = class {
|
|
|
17859
17928
|
inventory: Object.keys(files).sort(),
|
|
17860
17929
|
syntaxOnly: false
|
|
17861
17930
|
};
|
|
17862
|
-
const built =
|
|
17931
|
+
const built = existsSync3(this.resources.compilerPath);
|
|
17863
17932
|
const reused = session.reuse(input.contextRef, { modFile, built }, Object.keys(files));
|
|
17864
17933
|
if (reused) {
|
|
17865
17934
|
session.accept(reused);
|
|
@@ -17879,11 +17948,11 @@ var GoMapAnalyzer = class {
|
|
|
17879
17948
|
}
|
|
17880
17949
|
async references(input, reference, signal, observe) {
|
|
17881
17950
|
const text = input.files[reference.targetPath];
|
|
17882
|
-
if (text === void 0 || !
|
|
17951
|
+
if (text === void 0 || !existsSync3(this.resources.compilerPath))
|
|
17883
17952
|
throw new ProjectEvidenceError("PROJECT_MAP_REFERENCE_TARGET_UNAVAILABLE", false);
|
|
17884
17953
|
const files = /* @__PURE__ */ Object.create(null);
|
|
17885
|
-
for (const [
|
|
17886
|
-
if (this.claims(
|
|
17954
|
+
for (const [path13, value] of Object.entries(input.files))
|
|
17955
|
+
if (this.claims(path13) || goModule.test(path13)) files[path13] = value;
|
|
17887
17956
|
const facts = await this.operation(
|
|
17888
17957
|
{
|
|
17889
17958
|
...input,
|
|
@@ -17904,7 +17973,7 @@ var GoMapAnalyzer = class {
|
|
|
17904
17973
|
};
|
|
17905
17974
|
|
|
17906
17975
|
// src/project-map-language-java.ts
|
|
17907
|
-
import { existsSync as
|
|
17976
|
+
import { existsSync as existsSync4 } from "node:fs";
|
|
17908
17977
|
var BUILD_FILES = [
|
|
17909
17978
|
"settings.gradle.kts",
|
|
17910
17979
|
"settings.gradle",
|
|
@@ -17913,14 +17982,14 @@ var BUILD_FILES = [
|
|
|
17913
17982
|
"pom.xml"
|
|
17914
17983
|
];
|
|
17915
17984
|
var buildFile = /(?:^|\/)(?:pom\.xml|(?:build|settings)\.gradle(?:\.kts)?)$/u;
|
|
17916
|
-
var directoryOf = (
|
|
17917
|
-
var nameOf = (
|
|
17985
|
+
var directoryOf = (path13) => path13.slice(0, path13.lastIndexOf("/") + 1);
|
|
17986
|
+
var nameOf = (path13) => path13.slice(path13.lastIndexOf("/") + 1);
|
|
17918
17987
|
var DEFAULT_RELEASE = 21;
|
|
17919
17988
|
var platformPackage = /^(?:java|jdk|sun|com\.sun|javax\.(?:annotation\.processing|crypto|imageio|lang\.model|management|naming|net|print|script|security|sound|sql|swing|tools|transaction\.xa|xml))(?:\.|$)/u;
|
|
17920
17989
|
var JAVA_MAP_LANGUAGE = Object.freeze({
|
|
17921
17990
|
id: "javac-lombok-1.18.48-map-v8",
|
|
17922
|
-
claims: (
|
|
17923
|
-
reads: (
|
|
17991
|
+
claims: (path13) => path13.endsWith(".java"),
|
|
17992
|
+
reads: (path13) => buildFile.test(path13),
|
|
17924
17993
|
// A package of the Java platform, or a library named by its first two package segments.
|
|
17925
17994
|
importName: (specifier) => platformPackage.test(specifier) ? "Java standard library" : specifier.split(".").slice(0, 2).join("."),
|
|
17926
17995
|
create: () => new JavaMapAnalyzer()
|
|
@@ -17983,7 +18052,7 @@ var JavaMapAnalyzer = class _JavaMapAnalyzer {
|
|
|
17983
18052
|
// The runtime found at startup may be gone since (an upgraded JDK replaces its directory).
|
|
17984
18053
|
refreshRuntime() {
|
|
17985
18054
|
const { runtimePath } = this.resources;
|
|
17986
|
-
if (runtimePath && !
|
|
18055
|
+
if (runtimePath && !existsSync4(runtimePath)) {
|
|
17987
18056
|
const { runtimePath: _gone, runtimeVersion: _version, ...rest } = this.resources;
|
|
17988
18057
|
this.resources = { ...rest, ...discoverJavaRuntime() };
|
|
17989
18058
|
}
|
|
@@ -18010,12 +18079,12 @@ var JavaMapAnalyzer = class _JavaMapAnalyzer {
|
|
|
18010
18079
|
// The worker's request for a context: the Java sources, the release and which are tests.
|
|
18011
18080
|
request(input, buildTexts) {
|
|
18012
18081
|
const files = /* @__PURE__ */ Object.create(null);
|
|
18013
|
-
for (const [
|
|
18014
|
-
if (this.claims(
|
|
18082
|
+
for (const [path13, text] of Object.entries(input.files))
|
|
18083
|
+
if (this.claims(path13)) files[path13] = text;
|
|
18015
18084
|
return {
|
|
18016
18085
|
files,
|
|
18017
18086
|
release: javaRelease(buildTexts, this.resources.runtimeVersion),
|
|
18018
|
-
tests: Object.keys(files).filter((
|
|
18087
|
+
tests: Object.keys(files).filter((path13) => mapTestPath(path13))
|
|
18019
18088
|
};
|
|
18020
18089
|
}
|
|
18021
18090
|
// The build files of a context's root directory, which declare its Java version.
|
|
@@ -18027,35 +18096,35 @@ var JavaMapAnalyzer = class _JavaMapAnalyzer {
|
|
|
18027
18096
|
}
|
|
18028
18097
|
async analyze(session, signal) {
|
|
18029
18098
|
this.refreshRuntime();
|
|
18030
|
-
const builds = session.readable.map((entry) => entry.path).filter((
|
|
18031
|
-
for (const
|
|
18032
|
-
const rank2 = (
|
|
18099
|
+
const builds = session.readable.map((entry) => entry.path).filter((path13) => buildFile.test(path13));
|
|
18100
|
+
for (const path13 of builds) session.configuration(path13);
|
|
18101
|
+
const rank2 = (path13) => BUILD_FILES.indexOf(nameOf(path13));
|
|
18033
18102
|
const roots = /* @__PURE__ */ new Map();
|
|
18034
18103
|
const modules = /* @__PURE__ */ new Map();
|
|
18035
|
-
for (const
|
|
18036
|
-
const directory = directoryOf(
|
|
18104
|
+
for (const path13 of builds) {
|
|
18105
|
+
const directory = directoryOf(path13);
|
|
18037
18106
|
const current = modules.get(directory);
|
|
18038
|
-
if (current === void 0 || rank2(
|
|
18039
|
-
const text = session.texts[
|
|
18040
|
-
if (/settings\.gradle(?:\.kts)?$/u.test(
|
|
18107
|
+
if (current === void 0 || rank2(path13) < rank2(current)) modules.set(directory, path13);
|
|
18108
|
+
const text = session.texts[path13] ?? "";
|
|
18109
|
+
if (/settings\.gradle(?:\.kts)?$/u.test(path13) || path13.endsWith("pom.xml") && /<modules>/u.test(text)) {
|
|
18041
18110
|
const root = roots.get(directory);
|
|
18042
|
-
if (root === void 0 || rank2(
|
|
18111
|
+
if (root === void 0 || rank2(path13) < rank2(root)) roots.set(directory, path13);
|
|
18043
18112
|
}
|
|
18044
18113
|
}
|
|
18045
|
-
const configOf = (
|
|
18114
|
+
const configOf = (path13) => {
|
|
18046
18115
|
let outer;
|
|
18047
18116
|
for (const directory of roots.keys())
|
|
18048
|
-
if (
|
|
18117
|
+
if (path13.startsWith(directory) && (outer === void 0 || directory.length < outer.length))
|
|
18049
18118
|
outer = directory;
|
|
18050
18119
|
if (outer !== void 0) return roots.get(outer);
|
|
18051
18120
|
let nearest;
|
|
18052
18121
|
for (const directory of modules.keys())
|
|
18053
|
-
if (
|
|
18122
|
+
if (path13.startsWith(directory) && (nearest === void 0 || directory.length > nearest.length))
|
|
18054
18123
|
nearest = directory;
|
|
18055
18124
|
return nearest === void 0 ? "" : modules.get(nearest);
|
|
18056
18125
|
};
|
|
18057
|
-
const output = (
|
|
18058
|
-
(directory) =>
|
|
18126
|
+
const output = (path13) => [...modules.keys()].some(
|
|
18127
|
+
(directory) => path13.startsWith(`${directory}build/`) || path13.startsWith(`${directory}target/`)
|
|
18059
18128
|
);
|
|
18060
18129
|
const groups = /* @__PURE__ */ new Map();
|
|
18061
18130
|
for (const entry of session.readable) {
|
|
@@ -18070,13 +18139,13 @@ var JavaMapAnalyzer = class _JavaMapAnalyzer {
|
|
|
18070
18139
|
if (signal.aborted) throw new ProjectEvidenceError("PROJECT_READ_CANCELLED", true);
|
|
18071
18140
|
const files = /* @__PURE__ */ Object.create(null);
|
|
18072
18141
|
const rootBuilds = configPath ? BUILD_FILES.map((name) => `${directoryOf(configPath)}${name}`).filter(
|
|
18073
|
-
(
|
|
18142
|
+
(path13) => builds.includes(path13)
|
|
18074
18143
|
) : [];
|
|
18075
|
-
for (const
|
|
18076
|
-
const text = session.texts[
|
|
18144
|
+
for (const path13 of [...groups.get(configPath) ?? [], ...rootBuilds]) {
|
|
18145
|
+
const text = session.texts[path13];
|
|
18077
18146
|
if (text === void 0)
|
|
18078
18147
|
throw new ProjectEvidenceError("PROJECT_MAP_PROTOCOL_INVALID", false);
|
|
18079
|
-
files[
|
|
18148
|
+
files[path13] = text;
|
|
18080
18149
|
}
|
|
18081
18150
|
const input = {
|
|
18082
18151
|
contextRef: digestValue({
|
|
@@ -18101,7 +18170,7 @@ var JavaMapAnalyzer = class _JavaMapAnalyzer {
|
|
|
18101
18170
|
release: request.release,
|
|
18102
18171
|
tests: request.tests,
|
|
18103
18172
|
runtime,
|
|
18104
|
-
built:
|
|
18173
|
+
built: existsSync4(this.resources.compilerPath),
|
|
18105
18174
|
lombokConfig
|
|
18106
18175
|
},
|
|
18107
18176
|
Object.keys(files)
|
|
@@ -18119,7 +18188,7 @@ var JavaMapAnalyzer = class _JavaMapAnalyzer {
|
|
|
18119
18188
|
const prior = JavaStateSchema.safeParse(previous?.state).data;
|
|
18120
18189
|
const incremental = previous && prior?.basis === basis ? {
|
|
18121
18190
|
changed: Object.keys(request.files).filter(
|
|
18122
|
-
(
|
|
18191
|
+
(path13) => digests.get(path13) !== previous.digests.get(path13)
|
|
18123
18192
|
),
|
|
18124
18193
|
state: prior.java
|
|
18125
18194
|
} : void 0;
|
|
@@ -18136,7 +18205,7 @@ var JavaMapAnalyzer = class _JavaMapAnalyzer {
|
|
|
18136
18205
|
this.resources.runtimeVersion,
|
|
18137
18206
|
[
|
|
18138
18207
|
...this.resources.runtimePath ? [] : [
|
|
18139
|
-
|
|
18208
|
+
existsSync4(this.resources.compilerPath) ? "JAVA_RUNTIME_UNAVAILABLE" : "JAVA_ANALYZER_NOT_BUILT"
|
|
18140
18209
|
],
|
|
18141
18210
|
...lombokConfig ? ["LOMBOK_CONFIG_NOT_APPLIED"] : []
|
|
18142
18211
|
]
|
|
@@ -18148,14 +18217,14 @@ var JavaMapAnalyzer = class _JavaMapAnalyzer {
|
|
|
18148
18217
|
continue;
|
|
18149
18218
|
}
|
|
18150
18219
|
const focus = new Set(facts.focus);
|
|
18151
|
-
if (!incremental || facts.focus.some((
|
|
18220
|
+
if (!incremental || facts.focus.some((path13) => !Object.hasOwn(request.files, path13)) || incremental.changed.some((path13) => !focus.has(path13)))
|
|
18152
18221
|
throw new ProjectEvidenceError("PROJECT_MAP_PROTOCOL_INVALID", false);
|
|
18153
18222
|
analysis.objects = analysis.objects.filter((object2) => focus.has(object2.anchor.path));
|
|
18154
18223
|
analysis.relations = analysis.relations.filter((relation) => focus.has(relation.anchor.path));
|
|
18155
18224
|
analysis.notes = analysis.notes.filter((note) => focus.has(note.anchor.path));
|
|
18156
18225
|
session.accept(analysis, {
|
|
18157
18226
|
state,
|
|
18158
|
-
linked: analysis.parsedFiles.filter((
|
|
18227
|
+
linked: analysis.parsedFiles.filter((path13) => !focus.has(path13))
|
|
18159
18228
|
});
|
|
18160
18229
|
}
|
|
18161
18230
|
}
|
|
@@ -18467,12 +18536,12 @@ var PYTHON_STANDARD_LIBRARY = /* @__PURE__ */ new Set([
|
|
|
18467
18536
|
// src/project-map-language-python.ts
|
|
18468
18537
|
var CONFIGURATION = ["pyrightconfig.json", "pyproject.toml", "setup.cfg"];
|
|
18469
18538
|
var pythonConfig = /(?:^|\/)(?:pyrightconfig\.json|pyproject\.toml|setup\.cfg)$/u;
|
|
18470
|
-
var directoryOf2 = (
|
|
18539
|
+
var directoryOf2 = (path13) => path13.slice(0, path13.lastIndexOf("/") + 1);
|
|
18471
18540
|
var DEFAULT_PYTHON = { major: 3, minor: 13 };
|
|
18472
18541
|
var PYTHON_MAP_LANGUAGE = Object.freeze({
|
|
18473
18542
|
id: "pyright-1.1.414-map-v13",
|
|
18474
|
-
claims: (
|
|
18475
|
-
reads: (
|
|
18543
|
+
claims: (path13) => /\.pyi?$/u.test(path13),
|
|
18544
|
+
reads: (path13) => pythonConfig.test(path13),
|
|
18476
18545
|
// An absolute import names the standard library or a distribution's top-level package.
|
|
18477
18546
|
importName: (specifier) => {
|
|
18478
18547
|
const top = specifier.split(".", 1)[0] ?? specifier;
|
|
@@ -18524,21 +18593,21 @@ var PythonMapAnalyzer = class {
|
|
|
18524
18593
|
return {
|
|
18525
18594
|
root: input.configPath ? directoryOf2(input.configPath).replace(/\/$/u, "") : "",
|
|
18526
18595
|
pythonVersion: pythonVersion(input.files, input.configPath),
|
|
18527
|
-
tests: Object.keys(input.files).filter((
|
|
18596
|
+
tests: Object.keys(input.files).filter((path13) => this.claims(path13) && mapTestPath(path13))
|
|
18528
18597
|
};
|
|
18529
18598
|
}
|
|
18530
18599
|
async analyze(session, signal) {
|
|
18531
18600
|
const roots = /* @__PURE__ */ new Map();
|
|
18532
|
-
for (const
|
|
18533
|
-
const directory = directoryOf2(
|
|
18601
|
+
for (const path13 of session.readable.map((entry) => entry.path).filter((path14) => pythonConfig.test(path14))) {
|
|
18602
|
+
const directory = directoryOf2(path13);
|
|
18534
18603
|
const current = roots.get(directory);
|
|
18535
18604
|
const rank2 = (file2) => CONFIGURATION.indexOf(file2.slice(directory.length));
|
|
18536
|
-
if (current === void 0 || rank2(
|
|
18605
|
+
if (current === void 0 || rank2(path13) < rank2(current)) roots.set(directory, path13);
|
|
18537
18606
|
}
|
|
18538
|
-
const rootOf = (
|
|
18607
|
+
const rootOf = (path13) => {
|
|
18539
18608
|
let best;
|
|
18540
18609
|
for (const directory of roots.keys())
|
|
18541
|
-
if (
|
|
18610
|
+
if (path13.startsWith(directory) && (best === void 0 || directory.length > best.length))
|
|
18542
18611
|
best = directory;
|
|
18543
18612
|
return best === void 0 ? "" : roots.get(best);
|
|
18544
18613
|
};
|
|
@@ -18553,11 +18622,11 @@ var PythonMapAnalyzer = class {
|
|
|
18553
18622
|
for (const configPath of [...groups.keys()].sort()) {
|
|
18554
18623
|
if (signal.aborted) throw new ProjectEvidenceError("PROJECT_READ_CANCELLED", true);
|
|
18555
18624
|
const files = /* @__PURE__ */ Object.create(null);
|
|
18556
|
-
for (const
|
|
18557
|
-
const text = session.texts[
|
|
18625
|
+
for (const path13 of [...groups.get(configPath) ?? [], ...configPath ? [configPath] : []]) {
|
|
18626
|
+
const text = session.texts[path13];
|
|
18558
18627
|
if (text === void 0)
|
|
18559
18628
|
throw new ProjectEvidenceError("PROJECT_MAP_PROTOCOL_INVALID", false);
|
|
18560
|
-
files[
|
|
18629
|
+
files[path13] = text;
|
|
18561
18630
|
}
|
|
18562
18631
|
const input = {
|
|
18563
18632
|
contextRef: digestValue({
|
|
@@ -18605,8 +18674,8 @@ var PythonMapAnalyzer = class {
|
|
|
18605
18674
|
if (input.files[reference.targetPath] === void 0)
|
|
18606
18675
|
throw new ProjectEvidenceError("PROJECT_MAP_REFERENCE_TARGET_UNAVAILABLE", false);
|
|
18607
18676
|
const files = /* @__PURE__ */ Object.create(null);
|
|
18608
|
-
for (const [
|
|
18609
|
-
if (this.claims(
|
|
18677
|
+
for (const [path13, value] of Object.entries(input.files))
|
|
18678
|
+
if (this.claims(path13) || pythonConfig.test(path13)) files[path13] = value;
|
|
18610
18679
|
const facts = await this.operation(
|
|
18611
18680
|
{
|
|
18612
18681
|
...input,
|
|
@@ -18626,8 +18695,8 @@ var PythonMapAnalyzer = class {
|
|
|
18626
18695
|
// src/project-map-language-typescript.ts
|
|
18627
18696
|
var TYPESCRIPT_MAP_LANGUAGE = Object.freeze({
|
|
18628
18697
|
id: "typescript-7.0.2-map-v17",
|
|
18629
|
-
claims: (
|
|
18630
|
-
reads: (
|
|
18698
|
+
claims: (path13) => /\.[cm]?[jt]sx?$/u.test(path13),
|
|
18699
|
+
reads: (path13) => path13.endsWith(".json") || path13 === "pnpm-workspace.yaml",
|
|
18631
18700
|
create: () => new TypeScriptMapAnalyzer()
|
|
18632
18701
|
});
|
|
18633
18702
|
var CONFIGURATIONS_KEPT = 4;
|
|
@@ -18739,9 +18808,9 @@ var TypeScriptMapAnalyzer = class {
|
|
|
18739
18808
|
accept(analysis);
|
|
18740
18809
|
return;
|
|
18741
18810
|
}
|
|
18742
|
-
const required2 = analysis.requiredFiles.map((
|
|
18743
|
-
const entry = byPath.get(
|
|
18744
|
-
if (!entry || Object.hasOwn(texts,
|
|
18811
|
+
const required2 = analysis.requiredFiles.map((path13) => {
|
|
18812
|
+
const entry = byPath.get(path13);
|
|
18813
|
+
if (!entry || Object.hasOwn(texts, path13))
|
|
18745
18814
|
throw new ProjectEvidenceError("PROJECT_MAP_PROTOCOL_INVALID", false);
|
|
18746
18815
|
return entry;
|
|
18747
18816
|
});
|
|
@@ -18799,16 +18868,16 @@ var MAP_LANGUAGES = Object.freeze([
|
|
|
18799
18868
|
]);
|
|
18800
18869
|
var mapAnalyzerSuite = (languages) => languages.map((language) => language.id).sort().join("+");
|
|
18801
18870
|
var PROJECT_MAP_ANALYZER = mapAnalyzerSuite(MAP_LANGUAGES);
|
|
18802
|
-
var mapCodePath = (
|
|
18803
|
-
var languageOf = (
|
|
18804
|
-
var mapLanguageOf = (
|
|
18871
|
+
var mapCodePath = (path13) => MAP_LANGUAGES.some((language) => language.claims(path13));
|
|
18872
|
+
var languageOf = (path13) => MAP_LANGUAGES.find((language) => language.claims(path13));
|
|
18873
|
+
var mapLanguageOf = (path13) => languageOf(path13)?.id;
|
|
18805
18874
|
var npmPackage = (specifier) => {
|
|
18806
18875
|
if (specifier.startsWith("node:")) return "node:*";
|
|
18807
18876
|
const parts = specifier.split("/");
|
|
18808
18877
|
return specifier.startsWith("@") ? parts.slice(0, 2).join("/") : parts[0] ?? specifier;
|
|
18809
18878
|
};
|
|
18810
18879
|
var mapExternalImport = (sourcePath, specifier) => languageOf(sourcePath)?.importName?.(specifier) ?? npmPackage(specifier);
|
|
18811
|
-
var mapImportTarget = (
|
|
18880
|
+
var mapImportTarget = (path13) => languageOf(path13)?.importTarget?.(path13) ?? path13;
|
|
18812
18881
|
|
|
18813
18882
|
// src/project-map-view.ts
|
|
18814
18883
|
var MAP_VIEW_FORMAT = "PROJECT_MAP_VIEW_V1";
|
|
@@ -18847,10 +18916,10 @@ var notFound = () => {
|
|
|
18847
18916
|
};
|
|
18848
18917
|
var MAP_KINDS_LEGEND = "kinds f function, c class, m method, p property, v variable, t type, i interface, e enum; numbers are 1-based source lines";
|
|
18849
18918
|
var MAP_DECLARATION_LEGEND = `@n marks where a relationship occurs and +n counts further sites, which project_find_references lists; a quoted path after the sites is the route the call or value is registered under there: its HTTP methods when the registration names them, then its path joined with the prefixes of the routers it is registered on, as far as the same function or file sets them (a prefix added where a router is mounted or passed in is not included); route "\u2026" after a decorator is the full route the decorator maps, its class's path joined with its own. Static relationships are grouped by the declaration that owns them. Callers are direct calls, uses as a value (stored, passed, returned or selected, then usually invoked through that value) and calls through an interface, type or base member that a declaration implements (dispatched from); dispatches to lists the members that implement an interface, type or base member, which a call through it may reach; trace stops names calls whose target is a function value, a member without a mapped implementation or a computed key, which only source reading can follow; possible callers by name are calls elsewhere, in the same language, of a member with a method's name on a receiver of unknown type (an untyped value, or one an unloaded package produced); they may or may not reach that method.`;
|
|
18850
|
-
var within = (
|
|
18851
|
-
var parentDirectory = (
|
|
18852
|
-
const slash =
|
|
18853
|
-
return slash < 0 ? "." :
|
|
18919
|
+
var within = (path13, directory) => directory === "." || path13.startsWith(`${directory}/`);
|
|
18920
|
+
var parentDirectory = (path13) => {
|
|
18921
|
+
const slash = path13.lastIndexOf("/");
|
|
18922
|
+
return slash < 0 ? "." : path13.slice(0, slash);
|
|
18854
18923
|
};
|
|
18855
18924
|
var compareText2 = (left, right) => left < right ? -1 : left > right ? 1 : 0;
|
|
18856
18925
|
var byCount = ([leftName, left], [rightName, right]) => right - left || compareText2(leftName, rightName);
|
|
@@ -18924,7 +18993,7 @@ function pageBlocks(view, head, whole, offset, budget) {
|
|
|
18924
18993
|
if (offset === blocks.length) return materialize(0);
|
|
18925
18994
|
return mapQueryPage(blocks.length - offset, materialize, (page) => page, budget);
|
|
18926
18995
|
}
|
|
18927
|
-
var inModule = (
|
|
18996
|
+
var inModule = (path13, module) => module.direct ? parentDirectory(path13) === module.directory : within(path13, module.directory);
|
|
18928
18997
|
var moduleLabel = (module) => module.direct ? `${module.directory === "." ? "" : `${module.directory}/`}* (files directly here)` : `${module.directory}/`;
|
|
18929
18998
|
function childModules(module, files) {
|
|
18930
18999
|
if (module.direct) return [];
|
|
@@ -19077,12 +19146,12 @@ function loadMemberCalls(store, version2) {
|
|
|
19077
19146
|
FROM project_map_relations
|
|
19078
19147
|
WHERE version_ref = ? AND to_ref IS NULL AND json_extract(relation_json, '$.kind') = 'CALLS'
|
|
19079
19148
|
AND json_extract(relation_json, '$.unresolvedReason') IN ('SYMBOL_NOT_RESOLVED', 'SYNTAX_ONLY')`).all(version2)) {
|
|
19080
|
-
const
|
|
19149
|
+
const path13 = String(row.path);
|
|
19081
19150
|
const target = String(row.target);
|
|
19082
19151
|
const name = MEMBER_NAME.exec(target)?.[1];
|
|
19083
|
-
const language = mapLanguageOf(
|
|
19152
|
+
const language = mapLanguageOf(path13);
|
|
19084
19153
|
if (!name || !language) continue;
|
|
19085
|
-
const call = { from: String(row.from_ref), path:
|
|
19154
|
+
const call = { from: String(row.from_ref), path: path13, line: Number(row.line), target };
|
|
19086
19155
|
const key = memberKey(language, name);
|
|
19087
19156
|
const known = calls.get(key);
|
|
19088
19157
|
if (known) known.push(call);
|
|
@@ -19137,10 +19206,10 @@ function loadCoverageNotes(store, version2) {
|
|
|
19137
19206
|
if (!codes.includes(gap.code)) codes.push(gap.code);
|
|
19138
19207
|
files.set(gap.path, codes);
|
|
19139
19208
|
}
|
|
19140
|
-
for (const [
|
|
19209
|
+
for (const [path13, codes] of files)
|
|
19141
19210
|
if (codes.length > 1 && codes.includes("NOT_IN_PARSED_CONTEXT"))
|
|
19142
19211
|
files.set(
|
|
19143
|
-
|
|
19212
|
+
path13,
|
|
19144
19213
|
codes.filter((code) => code !== "NOT_IN_PARSED_CONTEXT")
|
|
19145
19214
|
);
|
|
19146
19215
|
return { files, limits: [...limits] };
|
|
@@ -19175,9 +19244,9 @@ function directoryView(facts, coverage, entries, input, directory, prefixes) {
|
|
|
19175
19244
|
const visiblePaths = new Set(visible.map((entry) => entry.path));
|
|
19176
19245
|
const code = visible.filter((entry) => entry.state === "TEXT" && mapCodePath(entry.path)).map((entry) => entry.path);
|
|
19177
19246
|
const modules = mapModules(directory, code);
|
|
19178
|
-
const moduleOf = (
|
|
19179
|
-
const outside = (
|
|
19180
|
-
const parts =
|
|
19247
|
+
const moduleOf = (path13) => modules.find((module) => inModule(path13, module));
|
|
19248
|
+
const outside = (path13) => {
|
|
19249
|
+
const parts = path13.split("/");
|
|
19181
19250
|
return `${parts.slice(0, Math.min(2, parts.length - 1)).join("/") || "."}/ (outside)`;
|
|
19182
19251
|
};
|
|
19183
19252
|
const moduleImports = /* @__PURE__ */ new Map();
|
|
@@ -19202,8 +19271,8 @@ function directoryView(facts, coverage, entries, input, directory, prefixes) {
|
|
|
19202
19271
|
const blocks = [];
|
|
19203
19272
|
if (modules.length > 1) {
|
|
19204
19273
|
const sizes = /* @__PURE__ */ new Map();
|
|
19205
|
-
for (const
|
|
19206
|
-
const module = moduleOf(
|
|
19274
|
+
for (const path13 of code) {
|
|
19275
|
+
const module = moduleOf(path13);
|
|
19207
19276
|
if (module) increment(sizes, moduleLabel(module));
|
|
19208
19277
|
}
|
|
19209
19278
|
blocks.push(
|
|
@@ -19232,18 +19301,18 @@ function directoryView(facts, coverage, entries, input, directory, prefixes) {
|
|
|
19232
19301
|
)}${packages.length > shown.length ? `, +${packages.length - shown.length} more` : ""}`
|
|
19233
19302
|
);
|
|
19234
19303
|
}
|
|
19235
|
-
const lineCount = (
|
|
19236
|
-
const file2 = facts.files.get(
|
|
19237
|
-
const gaps = coverage.files.get(
|
|
19304
|
+
const lineCount = (path13) => {
|
|
19305
|
+
const file2 = facts.files.get(path13);
|
|
19306
|
+
const gaps = coverage.files.get(path13) ?? [];
|
|
19238
19307
|
if (file2?.parsed === false) return `[not parsed${gaps.length ? `: ${gaps.join("; ")}` : ""}]`;
|
|
19239
19308
|
return `${file2 ? `${file2.lines}L` : "?L"}${gaps.length ? ` [${gaps.join("; ")}]` : ""}`;
|
|
19240
19309
|
};
|
|
19241
19310
|
const codeDirectories = /* @__PURE__ */ new Set();
|
|
19242
|
-
for (const
|
|
19243
|
-
for (let parent = parentDirectory(
|
|
19311
|
+
for (const path13 of code)
|
|
19312
|
+
for (let parent = parentDirectory(path13); parent !== "." && !codeDirectories.has(parent); parent = parentDirectory(parent))
|
|
19244
19313
|
codeDirectories.add(parent);
|
|
19245
|
-
const groupOf = (
|
|
19246
|
-
let group = parentDirectory(
|
|
19314
|
+
const groupOf = (path13) => {
|
|
19315
|
+
let group = parentDirectory(path13);
|
|
19247
19316
|
for (let parent = group; parent !== "." && parent !== directory && !codeDirectories.has(parent); parent = parentDirectory(parent))
|
|
19248
19317
|
group = parent;
|
|
19249
19318
|
return group;
|
|
@@ -19275,11 +19344,11 @@ function directoryView(facts, coverage, entries, input, directory, prefixes) {
|
|
|
19275
19344
|
]);
|
|
19276
19345
|
}
|
|
19277
19346
|
const detailed = [
|
|
19278
|
-
...code.map((
|
|
19279
|
-
const declarations = (facts.exported.get(
|
|
19347
|
+
...code.map((path13) => {
|
|
19348
|
+
const declarations = (facts.exported.get(path13) ?? []).map(({ text: text2 }) => text2);
|
|
19280
19349
|
return [
|
|
19281
|
-
|
|
19282
|
-
`${
|
|
19350
|
+
path13,
|
|
19351
|
+
`${path13} ${lineCount(path13)}${declarations.length ? `: ${declarations.join(", ")}` : ""}`
|
|
19283
19352
|
];
|
|
19284
19353
|
}),
|
|
19285
19354
|
...listedOther.map((entry) => [
|
|
@@ -19290,7 +19359,7 @@ function directoryView(facts, coverage, entries, input, directory, prefixes) {
|
|
|
19290
19359
|
];
|
|
19291
19360
|
const directories = /* @__PURE__ */ new Map();
|
|
19292
19361
|
for (const entry of [
|
|
19293
|
-
...code.map((
|
|
19362
|
+
...code.map((path13) => ({ path: path13, item: lineCount(path13) })),
|
|
19294
19363
|
...listedOther.map((entry2) => ({
|
|
19295
19364
|
path: entry2.path,
|
|
19296
19365
|
item: entry2.state === "TEXT" ? "" : `(${entry2.state})`
|
|
@@ -19318,10 +19387,10 @@ function directoryView(facts, coverage, entries, input, directory, prefixes) {
|
|
|
19318
19387
|
);
|
|
19319
19388
|
const text = visible.filter((entry) => entry.state === "TEXT").length;
|
|
19320
19389
|
const resolution = /* @__PURE__ */ new Map();
|
|
19321
|
-
for (const
|
|
19322
|
-
const counts = facts.calls.get(
|
|
19390
|
+
for (const path13 of code) {
|
|
19391
|
+
const counts = facts.calls.get(path13);
|
|
19323
19392
|
if (!counts) continue;
|
|
19324
|
-
const language = facts.files.get(
|
|
19393
|
+
const language = facts.files.get(path13)?.language ?? "unknown";
|
|
19325
19394
|
const total = resolution.get(language) ?? { resolved: 0, unresolved: 0, external: 0 };
|
|
19326
19395
|
total.resolved += counts.resolved;
|
|
19327
19396
|
total.unresolved += counts.unresolved;
|
|
@@ -19379,8 +19448,8 @@ var DeclarationGroups = class {
|
|
|
19379
19448
|
prefixes;
|
|
19380
19449
|
showTests;
|
|
19381
19450
|
memberCalls;
|
|
19382
|
-
visible(
|
|
19383
|
-
return mapPathAllowed(
|
|
19451
|
+
visible(path13) {
|
|
19452
|
+
return mapPathAllowed(path13, this.prefixes) && (this.showTests || !mapTestPath(path13));
|
|
19384
19453
|
}
|
|
19385
19454
|
entry(object2, imported = false) {
|
|
19386
19455
|
if (mapIsModule(object2)) return imported ? "(file)" : "(module scope)";
|
|
@@ -19424,11 +19493,11 @@ var DeclarationGroups = class {
|
|
|
19424
19493
|
value.lines.push(line);
|
|
19425
19494
|
aggregates.set(key, value);
|
|
19426
19495
|
};
|
|
19427
|
-
const dispatch = (arrow, label, ref2,
|
|
19496
|
+
const dispatch = (arrow, label, ref2, path13, line) => {
|
|
19428
19497
|
const other = graph.object(graph.owner(ref2));
|
|
19429
19498
|
if (owned.has(other.id)) return;
|
|
19430
|
-
if (!this.visible(
|
|
19431
|
-
if (mapPathAllowed(
|
|
19499
|
+
if (!this.visible(path13)) {
|
|
19500
|
+
if (mapPathAllowed(path13, this.prefixes)) omittedTests++;
|
|
19432
19501
|
return;
|
|
19433
19502
|
}
|
|
19434
19503
|
add(arrow, label, other, line);
|
|
@@ -19585,7 +19654,7 @@ var DeclarationGroups = class {
|
|
|
19585
19654
|
else files2.set(call.path, [item]);
|
|
19586
19655
|
}
|
|
19587
19656
|
lines.push(
|
|
19588
|
-
` \u2190 possible callers by name: ${[...files2].map(([
|
|
19657
|
+
` \u2190 possible callers by name: ${[...files2].map(([path13, items]) => `${path13}: ${items.join(", ")}`).join("; ")}${inTests}`
|
|
19589
19658
|
);
|
|
19590
19659
|
} else if (possibleInTests)
|
|
19591
19660
|
lines.push(` \u2190 possible callers by name: ${possibleInTests} in test files (includeTests)`);
|
|
@@ -19621,14 +19690,14 @@ var DeclarationGroups = class {
|
|
|
19621
19690
|
return { lines, neighbors: [...new Set(neighbors)] };
|
|
19622
19691
|
}
|
|
19623
19692
|
};
|
|
19624
|
-
function fileView(store, coverage, graph, input,
|
|
19625
|
-
const entry = store.getEntry(input.version,
|
|
19626
|
-
if (!entry || !mapPathAllowed(
|
|
19627
|
-
const showTests = input.includeTests === true || mapTestPath(
|
|
19628
|
-
const module = mapCodePath(
|
|
19629
|
-
const gaps = coverage.files.get(
|
|
19693
|
+
function fileView(store, coverage, graph, input, path13, prefixes) {
|
|
19694
|
+
const entry = store.getEntry(input.version, path13);
|
|
19695
|
+
if (!entry || !mapPathAllowed(path13, prefixes)) return notFound();
|
|
19696
|
+
const showTests = input.includeTests === true || mapTestPath(path13);
|
|
19697
|
+
const module = mapCodePath(path13) ? graph.objectsAt(path13).find((object2) => mapIsModule(object2)) : void 0;
|
|
19698
|
+
const gaps = coverage.files.get(path13) ?? [];
|
|
19630
19699
|
const head = [
|
|
19631
|
-
`PROJECT MAP \xB7 FILE ${
|
|
19700
|
+
`PROJECT MAP \xB7 FILE ${path13} \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`}`
|
|
19632
19701
|
];
|
|
19633
19702
|
if (!module || entry.state !== "TEXT")
|
|
19634
19703
|
return pageBlocks("FILE", head, [], input.offset ?? 0, input.outputBudget);
|
|
@@ -19648,7 +19717,7 @@ function fileView(store, coverage, graph, input, path11, prefixes) {
|
|
|
19648
19717
|
tags.set(relation.from, list);
|
|
19649
19718
|
}
|
|
19650
19719
|
const describe3 = (object2) => [
|
|
19651
|
-
`${object2.name} ${mapDeclarationLabel(object2)}${object2.anchor.path ===
|
|
19720
|
+
`${object2.name} ${mapDeclarationLabel(object2)}${object2.anchor.path === path13 ? "" : ` (${object2.anchor.path})`}`,
|
|
19652
19721
|
...tags.get(object2.id) ?? []
|
|
19653
19722
|
].join(" ");
|
|
19654
19723
|
const declarations = [];
|
|
@@ -19663,11 +19732,11 @@ function fileView(store, coverage, graph, input, path11, prefixes) {
|
|
|
19663
19732
|
);
|
|
19664
19733
|
}
|
|
19665
19734
|
const elsewhere = /* @__PURE__ */ new Map();
|
|
19666
|
-
for (const object2 of graph.objectsAt(
|
|
19735
|
+
for (const object2 of graph.objectsAt(path13)) {
|
|
19667
19736
|
const parent = mapIsModule(object2) ? void 0 : graph.parent(object2.id);
|
|
19668
19737
|
if (parent === void 0 || !graph.isAddressable(object2)) continue;
|
|
19669
19738
|
const container = graph.object(parent);
|
|
19670
|
-
if (mapIsModule(container) || container.anchor.path ===
|
|
19739
|
+
if (mapIsModule(container) || container.anchor.path === path13) continue;
|
|
19671
19740
|
const into = elsewhere.get(parent);
|
|
19672
19741
|
if (into) into.push(object2);
|
|
19673
19742
|
else elsewhere.set(parent, [object2]);
|
|
@@ -19681,7 +19750,7 @@ function fileView(store, coverage, graph, input, path11, prefixes) {
|
|
|
19681
19750
|
if (declarations.length) blocks.push(["DECLARATIONS (* exported)", ...declarations].join("\n"));
|
|
19682
19751
|
const imports = /* @__PURE__ */ new Set();
|
|
19683
19752
|
const external = /* @__PURE__ */ new Set();
|
|
19684
|
-
const fileObjects = graph.objectsAt(
|
|
19753
|
+
const fileObjects = graph.objectsAt(path13).map((object2) => object2.id);
|
|
19685
19754
|
for (const relation of graph.relationsFrom(fileObjects)) {
|
|
19686
19755
|
if (!IMPORT_KINDS.has(relation.kind)) continue;
|
|
19687
19756
|
if (relation.to === void 0) external.add(relation.target);
|
|
@@ -19692,8 +19761,8 @@ function fileView(store, coverage, graph, input, path11, prefixes) {
|
|
|
19692
19761
|
}
|
|
19693
19762
|
const importers = /* @__PURE__ */ new Set();
|
|
19694
19763
|
const testImporters = /* @__PURE__ */ new Set();
|
|
19695
|
-
const imported = mapImportTarget(
|
|
19696
|
-
const packageModules = imported ===
|
|
19764
|
+
const imported = mapImportTarget(path13);
|
|
19765
|
+
const packageModules = imported === path13 ? [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);
|
|
19697
19766
|
for (const relation of graph.relationsTo(packageModules)) {
|
|
19698
19767
|
if (!IMPORT_KINDS.has(relation.kind)) continue;
|
|
19699
19768
|
const source = relation.anchor.path;
|
|
@@ -19721,16 +19790,16 @@ function fileView(store, coverage, graph, input, path11, prefixes) {
|
|
|
19721
19790
|
if (scope.length) blocks.push(["MODULE SCOPE (top-level statements)", ...scope].join("\n"));
|
|
19722
19791
|
return pageBlocks("FILE", head, blocks, input.offset ?? 0, input.outputBudget);
|
|
19723
19792
|
}
|
|
19724
|
-
function declarationView(graph, input,
|
|
19793
|
+
function declarationView(graph, input, path13, prefixes, memberCalls) {
|
|
19725
19794
|
const requested = input.depth ?? 1;
|
|
19726
19795
|
if (!Number.isSafeInteger(requested) || requested < 1 || requested > MAP_VIEW_LIMITS.directedDepth)
|
|
19727
19796
|
return invalid2();
|
|
19728
19797
|
const both = (input.direction ?? "BOTH") === "BOTH";
|
|
19729
19798
|
const depth = both ? Math.min(requested, MAP_VIEW_LIMITS.bothDepth) : requested;
|
|
19730
19799
|
const { name, line } = input;
|
|
19731
|
-
const selected = mapSelectDeclarations(graph,
|
|
19800
|
+
const selected = mapSelectDeclarations(graph, path13, name, line);
|
|
19732
19801
|
if (!selected.length) return notFound();
|
|
19733
|
-
const showTests = input.includeTests === true || mapTestPath(
|
|
19802
|
+
const showTests = input.includeTests === true || mapTestPath(path13);
|
|
19734
19803
|
const groups = new DeclarationGroups(graph, input, prefixes, showTests, memberCalls);
|
|
19735
19804
|
const blocks = [];
|
|
19736
19805
|
const seen = /* @__PURE__ */ new Set();
|
|
@@ -19778,7 +19847,7 @@ function declarationView(graph, input, path11, prefixes, memberCalls) {
|
|
|
19778
19847
|
);
|
|
19779
19848
|
}
|
|
19780
19849
|
const head = [
|
|
19781
|
-
`PROJECT MAP \xB7 DECLARATION ${
|
|
19850
|
+
`PROJECT MAP \xB7 DECLARATION ${path13}${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
19851
|
...truncated ? [`Expansion stopped at ${MAP_VIEW_LIMITS.declarations} declarations.`] : [],
|
|
19783
19852
|
...(input.direction ?? "BOTH") === "OUTGOING" ? [] : [callerCoverage(input.textSearch ?? DEFAULT_TEXT_SEARCH)]
|
|
19784
19853
|
];
|
|
@@ -19905,10 +19974,10 @@ var ProjectMapQuery = class {
|
|
|
19905
19974
|
view(input, signal) {
|
|
19906
19975
|
this.requireReadableMap(input.version, signal);
|
|
19907
19976
|
const { offset, prefixes } = admission(input);
|
|
19908
|
-
const
|
|
19977
|
+
const path13 = normalizeProjectEvidencePath(input.path, true) || ".";
|
|
19909
19978
|
const view = mapView(
|
|
19910
19979
|
this.store,
|
|
19911
|
-
{ ...input, path:
|
|
19980
|
+
{ ...input, path: path13, offset, allowedPathPrefixes: prefixes },
|
|
19912
19981
|
this.views
|
|
19913
19982
|
);
|
|
19914
19983
|
if (signal.aborted) throw new ProjectEvidenceError("PROJECT_READ_CANCELLED", true);
|
|
@@ -20813,7 +20882,7 @@ var CodeIndexStore = class {
|
|
|
20813
20882
|
const staged = this.stageUnits(buildRef, paths, linked);
|
|
20814
20883
|
const reused = linked ? this.database.prepare(`SELECT path, unit_ref FROM project_map_version_units
|
|
20815
20884
|
WHERE version_ref = ? AND path IN (SELECT value FROM json_each(?))`).all(linked.version, JSON.stringify([...linked.paths])).map((row) => ({ path: String(row.path), unit: String(row.unit_ref) })) : [];
|
|
20816
|
-
if (reused.length !== (linked?.paths.size ?? 0) || reused.some(({ path:
|
|
20885
|
+
if (reused.length !== (linked?.paths.size ?? 0) || reused.some(({ path: path13 }) => !paths.has(path13)) || staged.some(({ path: path13 }) => linked?.paths.has(path13)))
|
|
20817
20886
|
throw new MapReplayConflict();
|
|
20818
20887
|
const units = [...staged, ...reused].sort(
|
|
20819
20888
|
(left, right) => left.path < right.path ? -1 : left.path > right.path ? 1 : 0
|
|
@@ -20864,7 +20933,7 @@ var CodeIndexStore = class {
|
|
|
20864
20933
|
const member = this.database.prepare(
|
|
20865
20934
|
"INSERT INTO project_map_version_units VALUES (?, ?, ?)"
|
|
20866
20935
|
);
|
|
20867
|
-
for (const { path:
|
|
20936
|
+
for (const { path: path13, unit } of reused) member.run(version2.version, path13, unit);
|
|
20868
20937
|
this.database.prepare("INSERT INTO project_map_coverage VALUES (?, ?)").run(version2.version, canonicalJson(coverage));
|
|
20869
20938
|
}
|
|
20870
20939
|
this.database.exec("COMMIT");
|
|
@@ -20928,7 +20997,7 @@ var CodeIndexStore = class {
|
|
|
20928
20997
|
corrupt2();
|
|
20929
20998
|
}
|
|
20930
20999
|
if (linked) {
|
|
20931
|
-
const unlinked = database.prepare("SELECT path FROM project_map_version_units WHERE version_ref = ?").all(linked.version).map((row) => String(row.path)).filter((
|
|
21000
|
+
const unlinked = database.prepare("SELECT path FROM project_map_version_units WHERE version_ref = ?").all(linked.version).map((row) => String(row.path)).filter((path13) => !linked.paths.has(path13));
|
|
20932
21001
|
if (database.prepare(`SELECT 1 FROM project_map_objects gone
|
|
20933
21002
|
WHERE gone.version_ref = ? AND gone.path IN (SELECT value FROM json_each(?))
|
|
20934
21003
|
AND gone.entity_ref NOT IN (SELECT entity_ref FROM project_map_publish_objects)
|
|
@@ -20953,17 +21022,17 @@ var CodeIndexStore = class {
|
|
|
20953
21022
|
const units = [];
|
|
20954
21023
|
for (const row of database.prepare(`SELECT path FROM project_map_publish_objects
|
|
20955
21024
|
UNION SELECT path FROM project_map_publish_relations ORDER BY path`).all()) {
|
|
20956
|
-
const
|
|
20957
|
-
const hash2 = createHash3("sha256").update(
|
|
21025
|
+
const path13 = String(row.path);
|
|
21026
|
+
const hash2 = createHash3("sha256").update(path13).update("\0");
|
|
20958
21027
|
for (const [mark, statement] of [
|
|
20959
21028
|
["object", objects2],
|
|
20960
21029
|
["relation", relations],
|
|
20961
21030
|
["note", pathNotes]
|
|
20962
21031
|
])
|
|
20963
|
-
for (const fact of statement.all(
|
|
21032
|
+
for (const fact of statement.all(path13))
|
|
20964
21033
|
for (const value of Object.values(fact))
|
|
20965
21034
|
hash2.update(mark).update("\0").update(String(value)).update("\0");
|
|
20966
|
-
units.push({ path:
|
|
21035
|
+
units.push({ path: path13, unit: hash2.digest("hex") });
|
|
20967
21036
|
}
|
|
20968
21037
|
return units;
|
|
20969
21038
|
}
|
|
@@ -20981,13 +21050,13 @@ var CodeIndexStore = class {
|
|
|
20981
21050
|
"INSERT INTO project_map_unit_notes SELECT ?, * FROM project_map_publish_notes WHERE path = ?"
|
|
20982
21051
|
);
|
|
20983
21052
|
const member = database.prepare("INSERT INTO project_map_version_units VALUES (?, ?, ?)");
|
|
20984
|
-
for (const { path:
|
|
20985
|
-
if (insertUnit.run(unit,
|
|
20986
|
-
unitObjects.run(unit,
|
|
20987
|
-
unitRelations.run(unit,
|
|
20988
|
-
unitNotes.run(unit,
|
|
21053
|
+
for (const { path: path13, unit } of units) {
|
|
21054
|
+
if (insertUnit.run(unit, path13).changes) {
|
|
21055
|
+
unitObjects.run(unit, path13);
|
|
21056
|
+
unitRelations.run(unit, path13);
|
|
21057
|
+
unitNotes.run(unit, path13);
|
|
20989
21058
|
}
|
|
20990
|
-
member.run(version2,
|
|
21059
|
+
member.run(version2, path13, unit);
|
|
20991
21060
|
}
|
|
20992
21061
|
}
|
|
20993
21062
|
/** Earlier versions of a project's scope built by the same analyzer, most recent first. */
|
|
@@ -21228,21 +21297,21 @@ var contextFiles = (context) => [
|
|
|
21228
21297
|
function replayableContexts(parent, digests) {
|
|
21229
21298
|
const sharing = /* @__PURE__ */ new Map();
|
|
21230
21299
|
for (const [ref, { context }] of parent.contexts)
|
|
21231
|
-
for (const
|
|
21232
|
-
const refs = sharing.get(
|
|
21300
|
+
for (const path13 of contextFiles(context)) {
|
|
21301
|
+
const refs = sharing.get(path13) ?? /* @__PURE__ */ new Set();
|
|
21233
21302
|
refs.add(ref);
|
|
21234
|
-
sharing.set(
|
|
21303
|
+
sharing.set(path13, refs);
|
|
21235
21304
|
}
|
|
21236
21305
|
const unchanged = /* @__PURE__ */ new Set();
|
|
21237
21306
|
for (const [ref, { context }] of parent.contexts)
|
|
21238
21307
|
if (contextFiles(context).every(
|
|
21239
|
-
(
|
|
21308
|
+
(path13) => digests.get(path13) !== void 0 && digests.get(path13) === parent.entries.get(path13)
|
|
21240
21309
|
))
|
|
21241
21310
|
unchanged.add(ref);
|
|
21242
21311
|
const replayable = /* @__PURE__ */ new Set();
|
|
21243
21312
|
for (const [ref, { context }] of parent.contexts)
|
|
21244
21313
|
if (unchanged.has(ref) && contextFiles(context).every(
|
|
21245
|
-
(
|
|
21314
|
+
(path13) => [...sharing.get(path13) ?? []].every((other) => unchanged.has(other))
|
|
21246
21315
|
))
|
|
21247
21316
|
replayable.add(ref);
|
|
21248
21317
|
return { replayable, sharing };
|
|
@@ -21275,8 +21344,8 @@ var ProjectMapAnalyzer = class {
|
|
|
21275
21344
|
languages;
|
|
21276
21345
|
observe;
|
|
21277
21346
|
id;
|
|
21278
|
-
claims(
|
|
21279
|
-
return this.languages.some((language) => language.claims(
|
|
21347
|
+
claims(path13) {
|
|
21348
|
+
return this.languages.some((language) => language.claims(path13));
|
|
21280
21349
|
}
|
|
21281
21350
|
references(input, reference, signal) {
|
|
21282
21351
|
const language = this.languages.find((language2) => language2.claims(reference.targetPath));
|
|
@@ -21316,7 +21385,7 @@ var ProjectMapAnalyzer = class {
|
|
|
21316
21385
|
const reuse = (contextRef2, request, files2) => {
|
|
21317
21386
|
const digest = digestValue({
|
|
21318
21387
|
request,
|
|
21319
|
-
files: files2.map((
|
|
21388
|
+
files: files2.map((path13) => [path13, digests.get(path13) ?? null])
|
|
21320
21389
|
});
|
|
21321
21390
|
requests.set(contextRef2, digest);
|
|
21322
21391
|
if (!parent || !replayable.has(contextRef2)) return void 0;
|
|
@@ -21356,7 +21425,7 @@ var ProjectMapAnalyzer = class {
|
|
|
21356
21425
|
const ref = analysis.contexts[0]?.ref ?? "";
|
|
21357
21426
|
if (options?.linked?.length) {
|
|
21358
21427
|
if (!parent || analysis.contexts.length !== 1) return invalidParent();
|
|
21359
|
-
for (const
|
|
21428
|
+
for (const path13 of options.linked) linked.add(path13);
|
|
21360
21429
|
this.observe?.({
|
|
21361
21430
|
operation: "LINK",
|
|
21362
21431
|
phase: "FINISHED",
|
|
@@ -21383,7 +21452,7 @@ var ProjectMapAnalyzer = class {
|
|
|
21383
21452
|
});
|
|
21384
21453
|
for (const file2 of analysis.parsedFiles) parsed.add(file2);
|
|
21385
21454
|
const staged = factPaths(analysis);
|
|
21386
|
-
for (const
|
|
21455
|
+
for (const path13 of staged) stagedPaths.add(path13);
|
|
21387
21456
|
for (const context of analysis.contexts) {
|
|
21388
21457
|
for (const file2 of context.configurationFiles) configurationInputs.add(file2);
|
|
21389
21458
|
if (!replayed.has(context.ref))
|
|
@@ -21412,7 +21481,7 @@ var ProjectMapAnalyzer = class {
|
|
|
21412
21481
|
accept,
|
|
21413
21482
|
reuse,
|
|
21414
21483
|
previous,
|
|
21415
|
-
configuration: (
|
|
21484
|
+
configuration: (path13) => configurationInputs.add(path13),
|
|
21416
21485
|
observe: this.observe
|
|
21417
21486
|
},
|
|
21418
21487
|
signal
|
|
@@ -21449,12 +21518,12 @@ var ProjectMapAnalyzer = class {
|
|
|
21449
21518
|
if (files.objects.length) accept(files);
|
|
21450
21519
|
if (parent && (replayed.size || linked.size)) {
|
|
21451
21520
|
for (const ref of replayed.keys())
|
|
21452
|
-
for (const
|
|
21453
|
-
if (analyzedFiles.has(
|
|
21521
|
+
for (const path13 of contextFiles(parent.contexts.get(ref)?.context ?? invalidParent()))
|
|
21522
|
+
if (analyzedFiles.has(path13) || [...sharing.get(path13) ?? []].some((other) => !replayed.has(other)))
|
|
21454
21523
|
throw new MapReplayConflict();
|
|
21455
|
-
for (const paths of replayed.values()) for (const
|
|
21456
|
-
for (const
|
|
21457
|
-
if (analyzedFiles.has(
|
|
21524
|
+
for (const paths of replayed.values()) for (const path13 of paths) linked.add(path13);
|
|
21525
|
+
for (const path13 of linked)
|
|
21526
|
+
if (analyzedFiles.has(path13) || stagedPaths.has(path13)) throw new MapReplayConflict();
|
|
21458
21527
|
parent.link([...linked]);
|
|
21459
21528
|
}
|
|
21460
21529
|
result.parsedFiles = [...parsed].sort();
|
|
@@ -21744,8 +21813,8 @@ var CodeIndex = class {
|
|
|
21744
21813
|
for (const entry of this.store.listEntries(candidate))
|
|
21745
21814
|
if (entry.contentDigest) entries2.set(entry.path, entry.contentDigest);
|
|
21746
21815
|
let changed = 0;
|
|
21747
|
-
for (const [
|
|
21748
|
-
for (const
|
|
21816
|
+
for (const [path13, digest] of digests) if (entries2.get(path13) !== digest) changed++;
|
|
21817
|
+
for (const path13 of entries2.keys()) if (!digests.has(path13)) changed++;
|
|
21749
21818
|
if (!best || changed < best.changed) best = { version: candidate, entries: entries2, changed };
|
|
21750
21819
|
}
|
|
21751
21820
|
if (!best) return void 0;
|
|
@@ -21884,8 +21953,157 @@ var CodeIndex = class {
|
|
|
21884
21953
|
};
|
|
21885
21954
|
|
|
21886
21955
|
// src/project-map-changes.ts
|
|
21956
|
+
import { readFileSync as readFileSync3 } from "node:fs";
|
|
21957
|
+
import path9 from "node:path";
|
|
21958
|
+
|
|
21959
|
+
// src/project-map-names.ts
|
|
21887
21960
|
import { readFileSync as readFileSync2 } from "node:fs";
|
|
21888
|
-
import
|
|
21961
|
+
import path8 from "node:path";
|
|
21962
|
+
var CONFIG_KEY = /^\s*(?:export\s+|-\s+)?["']?([A-Za-z_][\w.-]*)["']?\s*(?:=|:(?:\s|$))/u;
|
|
21963
|
+
var CODE_READS = [
|
|
21964
|
+
// process.env.NAME, import.meta.env.NAME
|
|
21965
|
+
/\benv\.([A-Za-z_]\w*)/gu,
|
|
21966
|
+
// getenv("NAME"), os.Getenv, os.LookupEnv, System.getProperty, env("NAME")
|
|
21967
|
+
/\b(?:getenv|Getenv|LookupEnv|setenv|Setenv|getProperty|env)\s*\(\s*["'`]([^"'`\s]+)["'`]/gu,
|
|
21968
|
+
// os.environ["NAME"], os.environ.get("NAME"), config.get("key"), settings["key"], viper.GetString("key")
|
|
21969
|
+
/\b(?:environ|env|conf|config|cfg|settings|viper)\w*(?:\s*\.\s*\w+)?\s*(?:<[^<>()]*>)?\s*[[(]\s*["'`]([^"'`\s]+)["'`]/giu,
|
|
21970
|
+
// "LOG_LEVEL": a quoted name spelled as an environment variable, as option tables keep them
|
|
21971
|
+
/["'`]([A-Z][A-Z0-9]*(?:_[A-Z0-9]+)+)["'`]/gu
|
|
21972
|
+
];
|
|
21973
|
+
var PLACEHOLDER = /\$\{([A-Za-z_][\w.-]*)/gu;
|
|
21974
|
+
var PYTHON_FIELD = /^\s+([A-Z][A-Z0-9]*(?:_[A-Z0-9]+)+)\s*:/gu;
|
|
21975
|
+
var NAME = /^[A-Za-z_][\w.-]+[A-Za-z0-9]$/u;
|
|
21976
|
+
var UPPER = /^[A-Z][A-Z0-9_]*$/u;
|
|
21977
|
+
var PLATFORM = /^(?:GITHUB_\w+|RUNNER_\w+|CI|NODE_ENV|PATH|HOME|USER|PWD|SHELL|LANG|LC_\w+|TZ|TERM|TMPDIR|TEMP|TMP|PYTHONPATH|GOPATH|GOOS|GOARCH|JAVA_HOME)$/u;
|
|
21978
|
+
var HISTORY = /(?:^|\/)(?:CHANGELOG|CHANGES|HISTORY|NEWS|RELEASES?|release[-_ ]?notes)[^/]*$/iu;
|
|
21979
|
+
var LIMIT = Object.freeze({ names: 50, mentions: 5 });
|
|
21980
|
+
var literal2 = (text) => text.replace(/[.*+?^${}()|[\]\\]/gu, "\\$&");
|
|
21981
|
+
var wholeName = (name) => new RegExp(`(?<![\\w-])${literal2(name)}(?![\\w-])`, "u");
|
|
21982
|
+
var quotedName = (name) => new RegExp(
|
|
21983
|
+
`["'\`]${literal2(name)}["'\`]|\\benv\\.${literal2(name)}\\b|\\$\\{${literal2(name)}[}:]`,
|
|
21984
|
+
"u"
|
|
21985
|
+
);
|
|
21986
|
+
function codeReads(line, file2) {
|
|
21987
|
+
const names = /* @__PURE__ */ new Set();
|
|
21988
|
+
const extra = file2.endsWith(".java") ? [PLACEHOLDER] : file2.endsWith(".py") ? [PYTHON_FIELD] : [];
|
|
21989
|
+
for (const pattern of [...CODE_READS, ...extra])
|
|
21990
|
+
for (const match of line.matchAll(pattern)) if (match[1]) names.add(match[1]);
|
|
21991
|
+
return names;
|
|
21992
|
+
}
|
|
21993
|
+
function diffLines(diff) {
|
|
21994
|
+
const removed = /* @__PURE__ */ new Map();
|
|
21995
|
+
const added = /* @__PURE__ */ new Map();
|
|
21996
|
+
let gone;
|
|
21997
|
+
let fresh;
|
|
21998
|
+
let inHunk = false;
|
|
21999
|
+
let line = 0;
|
|
22000
|
+
for (const text of diff.split("\n")) {
|
|
22001
|
+
if (text.startsWith("diff --git ")) {
|
|
22002
|
+
const match = /^diff --git a\/(.+) b\/(.+)$/u.exec(text);
|
|
22003
|
+
gone = [];
|
|
22004
|
+
fresh = /* @__PURE__ */ new Set();
|
|
22005
|
+
if (match?.[1] && !match[1].startsWith('"')) removed.set(match[1], gone);
|
|
22006
|
+
if (match?.[2] && !match[2].startsWith('"')) added.set(match[2], fresh);
|
|
22007
|
+
inHunk = false;
|
|
22008
|
+
} else if (text.startsWith("rename from ") && gone)
|
|
22009
|
+
removed.set(text.slice("rename from ".length), gone);
|
|
22010
|
+
else if (text.startsWith("rename to ") && fresh)
|
|
22011
|
+
added.set(text.slice("rename to ".length), fresh);
|
|
22012
|
+
else if (text.startsWith("@@ ")) {
|
|
22013
|
+
inHunk = true;
|
|
22014
|
+
line = Number(/\+(\d+)/u.exec(text)?.[1] ?? 0);
|
|
22015
|
+
} else if (inHunk && text.startsWith("-")) gone?.push(text.slice(1));
|
|
22016
|
+
else if (inHunk && text.startsWith("+")) fresh?.add(line++);
|
|
22017
|
+
}
|
|
22018
|
+
return { removed, added };
|
|
22019
|
+
}
|
|
22020
|
+
async function strandedNames(project, diff, files, configuration, git2, options) {
|
|
22021
|
+
const { removed, added } = diffLines(diff);
|
|
22022
|
+
const from = /* @__PURE__ */ new Map();
|
|
22023
|
+
for (const file2 of files) {
|
|
22024
|
+
const lines = file2.basePath === void 0 ? void 0 : removed.get(file2.basePath);
|
|
22025
|
+
if (!lines?.length || file2.status === "DELETED" || mapTestPath(file2.path)) continue;
|
|
22026
|
+
const config2 = configuration(file2.path);
|
|
22027
|
+
if (!config2 && !mapLanguageOf(file2.path)) continue;
|
|
22028
|
+
const names2 = /* @__PURE__ */ new Set();
|
|
22029
|
+
for (const line of lines)
|
|
22030
|
+
if (config2) {
|
|
22031
|
+
const key = CONFIG_KEY.exec(line)?.[1];
|
|
22032
|
+
if (key) names2.add(key);
|
|
22033
|
+
for (const match of line.matchAll(PLACEHOLDER)) if (match[1]) names2.add(match[1]);
|
|
22034
|
+
} else for (const name of codeReads(line, file2.path)) names2.add(name);
|
|
22035
|
+
let text;
|
|
22036
|
+
try {
|
|
22037
|
+
text = readFileSync2(path8.join(project, file2.path), "utf8");
|
|
22038
|
+
} catch {
|
|
22039
|
+
continue;
|
|
22040
|
+
}
|
|
22041
|
+
for (const name of names2)
|
|
22042
|
+
if (NAME.test(name) && !PLATFORM.test(name) && !from.has(name) && !wholeName(name).test(text))
|
|
22043
|
+
from.set(name, { path: file2.path, code: !config2 });
|
|
22044
|
+
}
|
|
22045
|
+
const names = [...from.keys()].slice(0, LIMIT.names);
|
|
22046
|
+
if (!names.length) return [];
|
|
22047
|
+
const patterns = new Map(
|
|
22048
|
+
names.map((name) => [name, { whole: wholeName(name), quoted: quotedName(name) }])
|
|
22049
|
+
);
|
|
22050
|
+
let found;
|
|
22051
|
+
try {
|
|
22052
|
+
found = (await git2.run(
|
|
22053
|
+
[
|
|
22054
|
+
"grep",
|
|
22055
|
+
"-n",
|
|
22056
|
+
"-I",
|
|
22057
|
+
"-w",
|
|
22058
|
+
"-F",
|
|
22059
|
+
"--untracked",
|
|
22060
|
+
"--full-name",
|
|
22061
|
+
"--no-color",
|
|
22062
|
+
...names.flatMap((name) => ["-e", name]),
|
|
22063
|
+
"--",
|
|
22064
|
+
"."
|
|
22065
|
+
],
|
|
22066
|
+
options
|
|
22067
|
+
)).stdout.toString("utf8");
|
|
22068
|
+
} catch (error51) {
|
|
22069
|
+
if (error51 instanceof GitCommandError && !options.signal?.aborted) return [];
|
|
22070
|
+
throw error51;
|
|
22071
|
+
}
|
|
22072
|
+
const untracked = new Set(
|
|
22073
|
+
files.filter((file2) => file2.status === "ADDED" && !added.has(file2.path)).map((file2) => file2.path)
|
|
22074
|
+
);
|
|
22075
|
+
const moved = /* @__PURE__ */ new Set();
|
|
22076
|
+
const mentions = /* @__PURE__ */ new Map();
|
|
22077
|
+
for (const hit of found.split("\n")) {
|
|
22078
|
+
const match = /^(.+?):(\d+):(.*)$/u.exec(hit);
|
|
22079
|
+
if (!match) continue;
|
|
22080
|
+
const [, file2 = "", number4 = "", line = ""] = match;
|
|
22081
|
+
if (HISTORY.test(file2)) continue;
|
|
22082
|
+
const at = Number(number4);
|
|
22083
|
+
const code = mapLanguageOf(file2) !== void 0;
|
|
22084
|
+
const reads = code ? codeReads(line, file2) : void 0;
|
|
22085
|
+
const key = configuration(file2) ? CONFIG_KEY.exec(line)?.[1] : void 0;
|
|
22086
|
+
for (const name of names) {
|
|
22087
|
+
const source = from.get(name);
|
|
22088
|
+
const pattern = patterns.get(name);
|
|
22089
|
+
if (!source || !pattern || file2 === source.path || !pattern.whole.test(line)) continue;
|
|
22090
|
+
if (untracked.has(file2) || added.get(file2)?.has(at)) {
|
|
22091
|
+
moved.add(name);
|
|
22092
|
+
continue;
|
|
22093
|
+
}
|
|
22094
|
+
const uses = UPPER.test(name) ? !reads || reads.has(name) || pattern.quoted.test(line) : reads ? reads.has(name) : source.code && /[_.-]/u.test(name) && key === name;
|
|
22095
|
+
if (uses) mentions.set(name, [...mentions.get(name) ?? [], `${file2}:${at}`]);
|
|
22096
|
+
}
|
|
22097
|
+
}
|
|
22098
|
+
return names.filter((name) => !moved.has(name) && mentions.has(name)).map((name) => ({
|
|
22099
|
+
name,
|
|
22100
|
+
from: from.get(name)?.path ?? "",
|
|
22101
|
+
mentions: mentions.get(name) ?? []
|
|
22102
|
+
}));
|
|
22103
|
+
}
|
|
22104
|
+
var strandedNameLine = ({ name, from, mentions }) => `${name}, gone from ${from}: ${mentions.slice(0, LIMIT.mentions).join(", ")}${mentions.length > LIMIT.mentions ? `, +${mentions.length - LIMIT.mentions} more` : ""}`;
|
|
22105
|
+
|
|
22106
|
+
// src/project-map-changes.ts
|
|
21889
22107
|
var git = new GitRunner();
|
|
21890
22108
|
var gitOptions = (cwd, signal) => ({
|
|
21891
22109
|
cwd,
|
|
@@ -21937,9 +22155,17 @@ async function readMapChanges(project, base, signal) {
|
|
|
21937
22155
|
baseText: (await git.run(["show", `${commit}:${file2.basePath}`], gitOptions(project, signal))).stdout.toString("utf8")
|
|
21938
22156
|
};
|
|
21939
22157
|
const untracked = (await git.run(["ls-files", "--others", "--exclude-standard", "-z"], gitOptions(project, signal))).stdout.toString("utf8").split("\0").filter(Boolean);
|
|
21940
|
-
for (const
|
|
21941
|
-
files.push({ path:
|
|
21942
|
-
|
|
22158
|
+
for (const path13 of untracked)
|
|
22159
|
+
files.push({ path: path13, status: "ADDED", lines: [EVERYTHING], baseLines: [], binary: false });
|
|
22160
|
+
const stranded = await strandedNames(
|
|
22161
|
+
project,
|
|
22162
|
+
diff,
|
|
22163
|
+
files,
|
|
22164
|
+
(file2) => nonCodeKind(file2) === "configuration",
|
|
22165
|
+
git,
|
|
22166
|
+
gitOptions(project, signal)
|
|
22167
|
+
);
|
|
22168
|
+
return { base, commit, files, stranded };
|
|
21943
22169
|
}
|
|
21944
22170
|
function parseMapDiff(text) {
|
|
21945
22171
|
const files = [];
|
|
@@ -22008,7 +22234,7 @@ var NON_CODE = [
|
|
|
22008
22234
|
[/(?:^|\/)\.env[^/]*$|\.(?:ya?ml|toml|ini|properties|conf|cfg)$/iu, "configuration"],
|
|
22009
22235
|
[/\.(?:html?|jinja2?|j2|hbs|ejs|tmpl|tpl|gohtml|vue|svelte)$/iu, "template"]
|
|
22010
22236
|
];
|
|
22011
|
-
var nonCodeKind = (
|
|
22237
|
+
var nonCodeKind = (path13) => NON_CODE.find(([pattern]) => pattern.test(path13))?.[1];
|
|
22012
22238
|
var LIMITS = Object.freeze({ depth: 8, declarations: 800, changed: 200, chain: 3, byName: 40 });
|
|
22013
22239
|
var CALLER_KINDS = /* @__PURE__ */ new Set(["CALLS", "REFERENCES"]);
|
|
22014
22240
|
var IMPORT_KINDS2 = /* @__PURE__ */ new Set(["IMPORTS", "TEST_IMPORTS"]);
|
|
@@ -22203,12 +22429,12 @@ var Tracer = class {
|
|
|
22203
22429
|
this.areas.set(area, known);
|
|
22204
22430
|
}
|
|
22205
22431
|
/** A related test file; the closest relation (lowest rank) explains it. */
|
|
22206
|
-
test(
|
|
22207
|
-
if (!mapRunnableTest(
|
|
22208
|
-
const known = this.tests.get(
|
|
22432
|
+
test(path13, name, why, rank2) {
|
|
22433
|
+
if (!mapRunnableTest(path13)) return;
|
|
22434
|
+
const known = this.tests.get(path13) ?? { names: /* @__PURE__ */ new Set(), why, rank: rank2 };
|
|
22209
22435
|
if (rank2 < known.rank) Object.assign(known, { why, rank: rank2 });
|
|
22210
22436
|
if (name && !name.startsWith("<")) known.names.add(name);
|
|
22211
|
-
this.tests.set(
|
|
22437
|
+
this.tests.set(path13, known);
|
|
22212
22438
|
}
|
|
22213
22439
|
};
|
|
22214
22440
|
var mapRunnableTest = (file2) => /_test\.(?:go|py)$|(?:^|\/)test_[^/]*\.py$|\.(?:test|spec)\.[cm]?[jt]sx?$|(?:Test|Tests|IT)\.(?:java|kt)$/u.test(
|
|
@@ -22221,7 +22447,7 @@ function mapChangeImpact(store, working, base, changes, project) {
|
|
|
22221
22447
|
const changed = [];
|
|
22222
22448
|
const unclear = [];
|
|
22223
22449
|
const removed = [];
|
|
22224
|
-
const declarations = (g,
|
|
22450
|
+
const declarations = (g, path13) => g.objectsAt(path13).filter((object2) => !mapIsModule(object2) && g.isAddressable(object2));
|
|
22225
22451
|
let changedCount = 0;
|
|
22226
22452
|
const starts = [];
|
|
22227
22453
|
for (const file2 of changes.files) {
|
|
@@ -22309,18 +22535,18 @@ function mapChangeImpact(store, working, base, changes, project) {
|
|
|
22309
22535
|
beforeTracer.trace(gone);
|
|
22310
22536
|
for (const entry of beforeTracer.entries.values())
|
|
22311
22537
|
if (!tracer.entries.has(entry.label)) tracer.entries.set(entry.label, entry);
|
|
22312
|
-
for (const [
|
|
22313
|
-
const known = tracer.tests.get(
|
|
22538
|
+
for (const [path13, test] of beforeTracer.tests) {
|
|
22539
|
+
const known = tracer.tests.get(path13);
|
|
22314
22540
|
if (known) for (const name of test.names) known.names.add(name);
|
|
22315
|
-
else tracer.tests.set(
|
|
22541
|
+
else tracer.tests.set(path13, test);
|
|
22316
22542
|
}
|
|
22317
22543
|
for (const [area, known] of beforeTracer.areas) {
|
|
22318
22544
|
const now = tracer.areas.get(area);
|
|
22319
22545
|
if (!now) tracer.areas.set(area, known);
|
|
22320
22546
|
else {
|
|
22321
22547
|
for (const name of known.through) now.through.add(name);
|
|
22322
|
-
for (const [
|
|
22323
|
-
now.tests.set(
|
|
22548
|
+
for (const [path13, names] of known.tests)
|
|
22549
|
+
now.tests.set(path13, /* @__PURE__ */ new Set([...now.tests.get(path13) ?? [], ...names]));
|
|
22324
22550
|
}
|
|
22325
22551
|
}
|
|
22326
22552
|
unclear.push(...beforeTracer.unclear.filter((line) => !line.includes("has no callers")));
|
|
@@ -22334,8 +22560,8 @@ function mapChangeImpact(store, working, base, changes, project) {
|
|
|
22334
22560
|
entries: [...tracer.entries.values()].sort(
|
|
22335
22561
|
(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)
|
|
22336
22562
|
),
|
|
22337
|
-
tests: [...tracer.tests].map(([
|
|
22338
|
-
path:
|
|
22563
|
+
tests: [...tracer.tests].map(([path13, test]) => ({
|
|
22564
|
+
path: path13,
|
|
22339
22565
|
names: [...test.names].sort(),
|
|
22340
22566
|
why: test.why,
|
|
22341
22567
|
rank: test.rank
|
|
@@ -22345,7 +22571,7 @@ function mapChangeImpact(store, working, base, changes, project) {
|
|
|
22345
22571
|
areas: [...tracer.areas].map(([area, known]) => ({
|
|
22346
22572
|
area,
|
|
22347
22573
|
through: [...known.through].sort(),
|
|
22348
|
-
tests: [...known.tests].map(([
|
|
22574
|
+
tests: [...known.tests].map(([path13, names]) => ({ path: path13, names: [...names].sort() })).sort((left, right) => right.names.length - left.names.length)
|
|
22349
22575
|
})).sort((left, right) => right.tests.length - left.tests.length),
|
|
22350
22576
|
unclear: [.../* @__PURE__ */ new Set([...unclear, ...tracer.unclear])],
|
|
22351
22577
|
truncated: tracer.truncated
|
|
@@ -22357,7 +22583,7 @@ function existingTestsChanged(before, after, file2, project) {
|
|
|
22357
22583
|
let workingLines = [];
|
|
22358
22584
|
if (file2.status !== "DELETED" && project)
|
|
22359
22585
|
try {
|
|
22360
|
-
workingLines =
|
|
22586
|
+
workingLines = readFileSync3(path9.join(project, file2.path), "utf8").split("\n");
|
|
22361
22587
|
} catch {
|
|
22362
22588
|
}
|
|
22363
22589
|
const key = (graph, object2) => `${object2.kind}\0${graph.qualifiedName(object2.id)}`;
|
|
@@ -22444,7 +22670,7 @@ function routeTests(project, store, version2, entries, tracer) {
|
|
|
22444
22670
|
if (!mapRunnableTest(candidate)) continue;
|
|
22445
22671
|
let text;
|
|
22446
22672
|
try {
|
|
22447
|
-
text =
|
|
22673
|
+
text = readFileSync3(path9.join(project, candidate), "utf8");
|
|
22448
22674
|
} catch {
|
|
22449
22675
|
continue;
|
|
22450
22676
|
}
|
|
@@ -22462,9 +22688,9 @@ function routeTests(project, store, version2, entries, tracer) {
|
|
|
22462
22688
|
}
|
|
22463
22689
|
}
|
|
22464
22690
|
}
|
|
22465
|
-
function sameDirectoryTests(store, version2,
|
|
22466
|
-
const slash =
|
|
22467
|
-
const directory = slash < 0 ? "" :
|
|
22691
|
+
function sameDirectoryTests(store, version2, path13, tracer) {
|
|
22692
|
+
const slash = path13.lastIndexOf("/");
|
|
22693
|
+
const directory = slash < 0 ? "" : path13.slice(0, slash + 1);
|
|
22468
22694
|
for (const row of store.database.prepare(
|
|
22469
22695
|
"SELECT DISTINCT path FROM project_map_objects WHERE version_ref = ? AND path LIKE ? ESCAPE '\\'"
|
|
22470
22696
|
).all(version2, `${directory.replace(/[\\%_]/gu, (c) => `\\${c}`)}%`)) {
|
|
@@ -22485,6 +22711,7 @@ var LIST = Object.freeze({
|
|
|
22485
22711
|
entries: 40,
|
|
22486
22712
|
tests: 12,
|
|
22487
22713
|
unclear: 20,
|
|
22714
|
+
stranded: 12,
|
|
22488
22715
|
names: 6,
|
|
22489
22716
|
areas: 8,
|
|
22490
22717
|
areaTests: 3,
|
|
@@ -22512,6 +22739,16 @@ Nothing changed against ${changes.base}.`;
|
|
|
22512
22739
|
impact.removed,
|
|
22513
22740
|
LIST.changed
|
|
22514
22741
|
);
|
|
22742
|
+
if (changes.stranded.length) {
|
|
22743
|
+
list(
|
|
22744
|
+
"NAMES STILL USED ELSEWHERE (environment variables and configuration keys the diff removed from a file, found by text)",
|
|
22745
|
+
changes.stranded.map(strandedNameLine),
|
|
22746
|
+
LIST.stranded
|
|
22747
|
+
);
|
|
22748
|
+
lines.push(
|
|
22749
|
+
"These places still read or set the old name. If the diff renamed or dropped it on purpose, update them too or keep the old name working. Names built at run time are not found."
|
|
22750
|
+
);
|
|
22751
|
+
}
|
|
22515
22752
|
if (impact.rewrittenTests.length) {
|
|
22516
22753
|
list(
|
|
22517
22754
|
"EXISTING TESTS CHANGED (tests that existed before this diff, whose code it changed or removed)",
|
|
@@ -22585,7 +22822,7 @@ Nothing changed against ${changes.base}.`;
|
|
|
22585
22822
|
var SCHEMA_VERSION = 2;
|
|
22586
22823
|
var KEEP_VERSIONS = 3;
|
|
22587
22824
|
function openMapDatabase(file2) {
|
|
22588
|
-
mkdirSync(
|
|
22825
|
+
mkdirSync(path10.dirname(file2), { recursive: true, mode: 448 });
|
|
22589
22826
|
const database = new DatabaseSync(file2);
|
|
22590
22827
|
try {
|
|
22591
22828
|
database.exec("PRAGMA busy_timeout = 30000;");
|
|
@@ -22622,7 +22859,7 @@ function openMapDatabase(file2) {
|
|
|
22622
22859
|
throw error51;
|
|
22623
22860
|
}
|
|
22624
22861
|
}
|
|
22625
|
-
var mapDatabasePath = (cacheDirectory2, canonicalProject) =>
|
|
22862
|
+
var mapDatabasePath = (cacheDirectory2, canonicalProject) => path10.join(
|
|
22626
22863
|
cacheDirectory2,
|
|
22627
22864
|
"projects",
|
|
22628
22865
|
createHash4("sha256").update(canonicalProject).digest("hex").slice(0, 24),
|
|
@@ -22772,19 +23009,25 @@ var LayerMap = class _LayerMap {
|
|
|
22772
23009
|
|
|
22773
23010
|
// src/agent/environment.ts
|
|
22774
23011
|
var packageRoot = (() => {
|
|
22775
|
-
for (let directory =
|
|
22776
|
-
const manifest =
|
|
22777
|
-
if (
|
|
23012
|
+
for (let directory = path11.dirname(fileURLToPath(import.meta.url)); ; ) {
|
|
23013
|
+
const manifest = path11.join(directory, "package.json");
|
|
23014
|
+
if (existsSync5(manifest) && JSON.parse(readFileSync4(manifest, "utf8")).name === "layermap")
|
|
22778
23015
|
return directory;
|
|
22779
|
-
if (
|
|
22780
|
-
directory =
|
|
23016
|
+
if (path11.dirname(directory) === directory) throw new Error("LayerMap cannot find its package.");
|
|
23017
|
+
directory = path11.dirname(directory);
|
|
22781
23018
|
}
|
|
22782
23019
|
})();
|
|
22783
|
-
var packageVersion = async () => JSON.parse(await readFile(
|
|
23020
|
+
var packageVersion = async () => JSON.parse(await readFile(path11.join(packageRoot, "package.json"), "utf8")).version;
|
|
22784
23021
|
var cacheDirectory = (env = process.env) => {
|
|
22785
|
-
if (env.LAYERMAP_CACHE) return
|
|
22786
|
-
if (process.platform === "darwin") return
|
|
22787
|
-
|
|
23022
|
+
if (env.LAYERMAP_CACHE) return path11.resolve(env.LAYERMAP_CACHE);
|
|
23023
|
+
if (process.platform === "darwin") return path11.join(homedir(), "Library", "Caches", "layermap");
|
|
23024
|
+
if (process.platform === "win32")
|
|
23025
|
+
return path11.join(
|
|
23026
|
+
env.LOCALAPPDATA || path11.join(homedir(), "AppData", "Local"),
|
|
23027
|
+
"layermap",
|
|
23028
|
+
"Cache"
|
|
23029
|
+
);
|
|
23030
|
+
return path11.join(env.XDG_CACHE_HOME || path11.join(homedir(), ".cache"), "layermap");
|
|
22788
23031
|
};
|
|
22789
23032
|
var projectDirectory = (directory) => new Promise(
|
|
22790
23033
|
(resolve) => execFile(
|
|
@@ -22792,7 +23035,7 @@ var projectDirectory = (directory) => new Promise(
|
|
|
22792
23035
|
["rev-parse", "--show-toplevel"],
|
|
22793
23036
|
{ cwd: directory, timeout: 1e4 },
|
|
22794
23037
|
(error51, stdout) => resolve(
|
|
22795
|
-
error51 ? { directory:
|
|
23038
|
+
error51 ? { directory: path11.resolve(directory), git: false } : { directory: stdout.trim(), git: true }
|
|
22796
23039
|
)
|
|
22797
23040
|
)
|
|
22798
23041
|
);
|
|
@@ -22802,7 +23045,7 @@ var relativeTo = (directory, value) => Object.fromEntries(
|
|
|
22802
23045
|
Object.fromEntries(
|
|
22803
23046
|
Object.entries(resources).map(([key, field]) => [
|
|
22804
23047
|
key,
|
|
22805
|
-
key.endsWith("Path") && typeof field === "string" && field.startsWith(directory) ?
|
|
23048
|
+
key.endsWith("Path") && typeof field === "string" && field.startsWith(directory) ? path11.relative(directory, field) : field
|
|
22806
23049
|
])
|
|
22807
23050
|
)
|
|
22808
23051
|
])
|
|
@@ -22813,9 +23056,10 @@ var resolvePlaceholder = (field) => {
|
|
|
22813
23056
|
createRequire(import.meta.url).resolve("typescript/package.json")
|
|
22814
23057
|
);
|
|
22815
23058
|
const native = `@typescript/typescript-${process.platform}-${process.arch}/package.json`;
|
|
22816
|
-
return
|
|
23059
|
+
return path11.join(path11.dirname(compiler.resolve(native)), "lib", executableName("tsc"));
|
|
22817
23060
|
}
|
|
22818
|
-
|
|
23061
|
+
const resolved = field.replaceAll("{platform}", process.platform).replaceAll("{arch}", process.arch);
|
|
23062
|
+
return field.includes("{platform}") ? executableName(resolved) : resolved;
|
|
22819
23063
|
};
|
|
22820
23064
|
var absoluteIn = (directory, value) => Object.fromEntries(
|
|
22821
23065
|
Object.entries(value).map(([language, resources]) => [
|
|
@@ -22824,24 +23068,24 @@ var absoluteIn = (directory, value) => Object.fromEntries(
|
|
|
22824
23068
|
Object.entries(resources).map(([key, field]) => {
|
|
22825
23069
|
if (!key.endsWith("Path") || typeof field !== "string") return [key, field];
|
|
22826
23070
|
const resolved = resolvePlaceholder(field);
|
|
22827
|
-
return [key,
|
|
23071
|
+
return [key, path11.isAbsolute(resolved) ? resolved : path11.join(directory, resolved)];
|
|
22828
23072
|
})
|
|
22829
23073
|
)
|
|
22830
23074
|
])
|
|
22831
23075
|
);
|
|
22832
23076
|
var readAnalyzers = async (directory) => {
|
|
22833
|
-
const file2 =
|
|
22834
|
-
if (!
|
|
23077
|
+
const file2 = path11.join(directory, "analyzers.json");
|
|
23078
|
+
if (!existsSync5(file2)) return void 0;
|
|
22835
23079
|
const analyzers = absoluteIn(directory, JSON.parse(await readFile(file2, "utf8")));
|
|
22836
23080
|
return analyzers.java.runtimePath ? analyzers : { ...analyzers, java: { ...analyzers.java, ...discoverJavaRuntime() } };
|
|
22837
23081
|
};
|
|
22838
23082
|
var sourceDigest = async () => {
|
|
22839
|
-
const hash2 = createHash5("sha256").update(await readFile(
|
|
23083
|
+
const hash2 = createHash5("sha256").update(await readFile(path11.join(packageRoot, "package.json")));
|
|
22840
23084
|
for (const part of ["src", "go-map", "java-map", "scripts"]) {
|
|
22841
|
-
const directory =
|
|
22842
|
-
if (!
|
|
23085
|
+
const directory = path11.join(packageRoot, part);
|
|
23086
|
+
if (!existsSync5(directory)) continue;
|
|
22843
23087
|
for (const entry of (await readdir(directory, { recursive: true })).sort()) {
|
|
22844
|
-
const file2 =
|
|
23088
|
+
const file2 = path11.join(directory, entry);
|
|
22845
23089
|
const info = await stat(file2);
|
|
22846
23090
|
if (info.isFile()) hash2.update(`${part}/${entry}\0${info.size}\0${info.mtimeMs}\0`);
|
|
22847
23091
|
}
|
|
@@ -22849,11 +23093,11 @@ var sourceDigest = async () => {
|
|
|
22849
23093
|
return hash2.digest("hex").slice(0, 16);
|
|
22850
23094
|
};
|
|
22851
23095
|
async function resolveAnalyzers(cache, log2, env = process.env) {
|
|
22852
|
-
for (const directory2 of [env.LAYERMAP_ANALYZERS,
|
|
22853
|
-
const analyzers = directory2 && await readAnalyzers(
|
|
23096
|
+
for (const directory2 of [env.LAYERMAP_ANALYZERS, path11.join(packageRoot, "analyzers")]) {
|
|
23097
|
+
const analyzers = directory2 && await readAnalyzers(path11.resolve(directory2));
|
|
22854
23098
|
if (analyzers) return analyzers;
|
|
22855
23099
|
}
|
|
22856
|
-
const directory =
|
|
23100
|
+
const directory = path11.join(cache, "analyzers", await sourceDigest());
|
|
22857
23101
|
const built = await readAnalyzers(directory);
|
|
22858
23102
|
if (built) return built;
|
|
22859
23103
|
log2("Building the language analyzers (once per LayerMap version)...");
|
|
@@ -22869,32 +23113,32 @@ async function resolveAnalyzers(cache, log2, env = process.env) {
|
|
|
22869
23113
|
python: parser.pythonResources,
|
|
22870
23114
|
java: parser.javaResources
|
|
22871
23115
|
});
|
|
22872
|
-
await writeFile(
|
|
23116
|
+
await writeFile(path11.join(staging, "analyzers.json"), `${JSON.stringify(stored, null, 2)}
|
|
22873
23117
|
`);
|
|
22874
23118
|
await rename(staging, directory).catch(() => rm(staging, { recursive: true, force: true }));
|
|
22875
23119
|
return await readAnalyzers(directory);
|
|
22876
23120
|
}
|
|
22877
23121
|
var DAY = 24 * 60 * 60 * 1e3;
|
|
22878
23122
|
async function pruneCache(cache, project, now = Date.now()) {
|
|
22879
|
-
const used =
|
|
22880
|
-
await mkdir(
|
|
23123
|
+
const used = path11.join(path11.dirname(mapDatabasePath(cache, project)), "last-used");
|
|
23124
|
+
await mkdir(path11.dirname(used), { recursive: true, mode: 448 });
|
|
22881
23125
|
await writeFile(used, "");
|
|
22882
23126
|
await utimes(used, now / 1e3, now / 1e3);
|
|
22883
|
-
const projects =
|
|
23127
|
+
const projects = path11.join(cache, "projects");
|
|
22884
23128
|
for (const name of await readdir(projects).catch(() => [])) {
|
|
22885
|
-
const directory =
|
|
22886
|
-
const marker =
|
|
22887
|
-
const last = (await stat(
|
|
23129
|
+
const directory = path11.join(projects, name);
|
|
23130
|
+
const marker = path11.join(directory, "last-used");
|
|
23131
|
+
const last = (await stat(existsSync5(marker) ? marker : directory).catch(() => void 0))?.mtimeMs;
|
|
22888
23132
|
if (last !== void 0 && now - last > 30 * DAY)
|
|
22889
23133
|
await rm(directory, { recursive: true, force: true });
|
|
22890
23134
|
}
|
|
22891
|
-
const builds =
|
|
23135
|
+
const builds = path11.join(cache, "analyzers");
|
|
22892
23136
|
const current = await sourceDigest();
|
|
22893
23137
|
for (const name of await readdir(builds).catch(() => [])) {
|
|
22894
23138
|
if (name === current) continue;
|
|
22895
|
-
const built = (await stat(
|
|
23139
|
+
const built = (await stat(path11.join(builds, name)).catch(() => void 0))?.mtimeMs;
|
|
22896
23140
|
if (built !== void 0 && now - built > (name.includes(".") ? DAY / 24 : DAY))
|
|
22897
|
-
await rm(
|
|
23141
|
+
await rm(path11.join(builds, name), { recursive: true, force: true });
|
|
22898
23142
|
}
|
|
22899
23143
|
}
|
|
22900
23144
|
|
|
@@ -22924,7 +23168,7 @@ var MAP_TOOL_NAMES = Object.freeze({
|
|
|
22924
23168
|
references: "project_find_references",
|
|
22925
23169
|
check: "project_check_changes"
|
|
22926
23170
|
});
|
|
22927
|
-
var mapDirectoryPath = (
|
|
23171
|
+
var mapDirectoryPath = (path13) => path13.length > 1 && path13.endsWith("/") && !path13.endsWith("//") ? path13.slice(0, -1) : path13;
|
|
22928
23172
|
var ProjectMapSearchInputSchema = external_exports.object({
|
|
22929
23173
|
path: external_exports.string().default("."),
|
|
22930
23174
|
query: external_exports.string().min(1).max(256),
|
|
@@ -22978,7 +23222,7 @@ var mapToolDescriptions = (host) => {
|
|
|
22978
23222
|
return Object.freeze({
|
|
22979
23223
|
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.`,
|
|
22980
23224
|
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.`,
|
|
22981
|
-
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; EXISTING TESTS CHANGED, the tests that existed before the diff and whose code it changed or removed; SHARED BY, when tests reach the changed code through more than one area (package or module), so a change meant for one feature may change others; 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; a failing or rewritten test of a feature the request is not about means the change leaked, so restore the test and narrow the change; call it once when the edits are done; and confirm the entry points in source, since an empty list does not prove a change safe.`,
|
|
23225
|
+
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; EXISTING TESTS CHANGED, the tests that existed before the diff and whose code it changed or removed; SHARED BY, when tests reach the changed code through more than one area (package or module), so a change meant for one feature may change others; NAMES STILL USED ELSEWHERE, environment variables and configuration keys the diff removed from a file that other files still read or set, found by text; 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; a failing or rewritten test of a feature the request is not about means the change leaked, so restore the test and narrow the change; call it once when the edits are done; and confirm the entry points in source, since an empty list does not prove a change safe.`,
|
|
22982
23226
|
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.`
|
|
22983
23227
|
});
|
|
22984
23228
|
};
|
|
@@ -23216,19 +23460,25 @@ function serveMcp(options) {
|
|
|
23216
23460
|
|
|
23217
23461
|
// src/agent/setup.ts
|
|
23218
23462
|
import { execFile as execFile2 } from "node:child_process";
|
|
23219
|
-
import { existsSync as
|
|
23463
|
+
import { existsSync as existsSync6 } from "node:fs";
|
|
23220
23464
|
import { mkdir as mkdir2, readFile as readFile2, rm as rm2, writeFile as writeFile2 } from "node:fs/promises";
|
|
23221
23465
|
import { homedir as homedir2 } from "node:os";
|
|
23222
|
-
import
|
|
23466
|
+
import path12 from "node:path";
|
|
23223
23467
|
var SERVER = "layermap";
|
|
23224
23468
|
var SETUP_RULE = `mcp__${SERVER}`;
|
|
23225
23469
|
var PLUGIN_RULE = `mcp__plugin_${SERVER}_${SERVER}`;
|
|
23226
23470
|
var BEGIN = "<!-- layermap:begin -->";
|
|
23227
23471
|
var END = "<!-- layermap:end -->";
|
|
23228
|
-
var mcpLaunchCommand = (version2) => {
|
|
23229
|
-
const script =
|
|
23230
|
-
if (script.includes(`${
|
|
23231
|
-
return [
|
|
23472
|
+
var mcpLaunchCommand = (version2, platform = process.platform) => {
|
|
23473
|
+
const script = path12.resolve(process.argv[1] ?? "");
|
|
23474
|
+
if (script.includes(`${path12.sep}_npx${path12.sep}`))
|
|
23475
|
+
return [
|
|
23476
|
+
...platform === "win32" ? ["cmd", "/c"] : [],
|
|
23477
|
+
"npx",
|
|
23478
|
+
"-y",
|
|
23479
|
+
`layermap@${version2}`,
|
|
23480
|
+
"mcp"
|
|
23481
|
+
];
|
|
23232
23482
|
const execArgv = [];
|
|
23233
23483
|
for (let index = 0; index < process.execArgv.length; index++) {
|
|
23234
23484
|
const argument = process.execArgv[index];
|
|
@@ -23240,16 +23490,22 @@ var mcpLaunchCommand = (version2) => {
|
|
|
23240
23490
|
}
|
|
23241
23491
|
return [process.execPath, ...execArgv, script, "mcp"];
|
|
23242
23492
|
};
|
|
23243
|
-
var run = (command, args, env) => new Promise(
|
|
23244
|
-
(
|
|
23245
|
-
|
|
23246
|
-
|
|
23247
|
-
|
|
23493
|
+
var run = (command, args, env) => new Promise((resolve) => {
|
|
23494
|
+
const invocation = commandInvocation(command, args, env);
|
|
23495
|
+
execFile2(
|
|
23496
|
+
invocation.file,
|
|
23497
|
+
invocation.args,
|
|
23498
|
+
{
|
|
23499
|
+
env,
|
|
23500
|
+
timeout: 6e4,
|
|
23501
|
+
windowsHide: true,
|
|
23502
|
+
windowsVerbatimArguments: invocation.windowsVerbatimArguments
|
|
23503
|
+
},
|
|
23248
23504
|
(error51, stdout, stderr) => resolve({ ok: !error51, output: `${stdout}${stderr}`.trim() })
|
|
23249
|
-
)
|
|
23250
|
-
);
|
|
23505
|
+
);
|
|
23506
|
+
});
|
|
23251
23507
|
async function allowInClaudeSettings(file2, rule = SETUP_RULE) {
|
|
23252
|
-
const settings =
|
|
23508
|
+
const settings = existsSync6(file2) ? JSON.parse(await readFile2(file2, "utf8")) : {};
|
|
23253
23509
|
if (typeof settings !== "object" || settings === null || Array.isArray(settings))
|
|
23254
23510
|
throw new Error(`${file2} is not a settings object.`);
|
|
23255
23511
|
settings.permissions ??= {};
|
|
@@ -23258,7 +23514,7 @@ async function allowInClaudeSettings(file2, rule = SETUP_RULE) {
|
|
|
23258
23514
|
throw new Error(`${file2} has permissions.allow that is not a list.`);
|
|
23259
23515
|
if (settings.permissions.allow.includes(rule)) return false;
|
|
23260
23516
|
settings.permissions.allow.push(rule);
|
|
23261
|
-
await mkdir2(
|
|
23517
|
+
await mkdir2(path12.dirname(file2), { recursive: true });
|
|
23262
23518
|
await writeFile2(file2, `${JSON.stringify(settings, null, 2)}
|
|
23263
23519
|
`);
|
|
23264
23520
|
return true;
|
|
@@ -23286,17 +23542,17 @@ async function writeInstructionNote(file2, note = AGENT_MAP_NOTE) {
|
|
|
23286
23542
|
const block = `${BEGIN}
|
|
23287
23543
|
${note}
|
|
23288
23544
|
${END}`;
|
|
23289
|
-
const text =
|
|
23545
|
+
const text = existsSync6(file2) ? await readFile2(file2, "utf8") : "";
|
|
23290
23546
|
const start = text.indexOf(BEGIN);
|
|
23291
23547
|
const end = text.indexOf(END);
|
|
23292
23548
|
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}
|
|
23293
23549
|
`;
|
|
23294
23550
|
if (next === text) return;
|
|
23295
|
-
await mkdir2(
|
|
23551
|
+
await mkdir2(path12.dirname(file2), { recursive: true });
|
|
23296
23552
|
await writeFile2(file2, next);
|
|
23297
23553
|
}
|
|
23298
23554
|
async function removeInstructionNote(file2) {
|
|
23299
|
-
if (!
|
|
23555
|
+
if (!existsSync6(file2)) return;
|
|
23300
23556
|
const text = await readFile2(file2, "utf8");
|
|
23301
23557
|
const start = text.indexOf(BEGIN);
|
|
23302
23558
|
const end = text.indexOf(END);
|
|
@@ -23307,7 +23563,7 @@ async function removeInstructionNote(file2) {
|
|
|
23307
23563
|
else await writeFile2(file2, rest);
|
|
23308
23564
|
}
|
|
23309
23565
|
async function disallowInClaudeSettings(file2) {
|
|
23310
|
-
if (!
|
|
23566
|
+
if (!existsSync6(file2)) return;
|
|
23311
23567
|
const settings = JSON.parse(await readFile2(file2, "utf8"));
|
|
23312
23568
|
const allow = settings?.permissions?.allow;
|
|
23313
23569
|
const ours = (rule) => rule === SETUP_RULE || rule === PLUGIN_RULE;
|
|
@@ -23320,14 +23576,14 @@ async function disallowInClaudeSettings(file2) {
|
|
|
23320
23576
|
}
|
|
23321
23577
|
var YAML_BEGIN = "# layermap:begin";
|
|
23322
23578
|
var YAML_END = "# layermap:end";
|
|
23323
|
-
var nodeDirectory = (env = process.env) => (env.PATH ?? "").split(
|
|
23324
|
-
(directory) =>
|
|
23325
|
-
) ??
|
|
23579
|
+
var nodeDirectory = (env = process.env) => (env.PATH ?? "").split(path12.delimiter).find(
|
|
23580
|
+
(directory) => path12.isAbsolute(directory) && existsSync6(path12.join(directory, "node")) && existsSync6(path12.join(directory, "npx"))
|
|
23581
|
+
) ?? path12.dirname(process.execPath);
|
|
23326
23582
|
var dshPatchBlock = (command, env) => {
|
|
23327
23583
|
const node = nodeDirectory(env);
|
|
23328
|
-
const npx =
|
|
23329
|
-
const [program = "", ...args] = command[0] === "npx" &&
|
|
23330
|
-
const
|
|
23584
|
+
const npx = path12.join(node, "npx");
|
|
23585
|
+
const [program = "", ...args] = command[0] === "npx" && existsSync6(npx) ? [npx, ...command.slice(1)] : command;
|
|
23586
|
+
const searchPath2 = `${JSON.stringify(`${node}${path12.delimiter}`)} + process.env.PATH`;
|
|
23331
23587
|
return [
|
|
23332
23588
|
`${YAML_BEGIN} (written by \`layermap setup dsh\`; \`layermap remove dsh\` deletes it)`,
|
|
23333
23589
|
"- insert:",
|
|
@@ -23339,14 +23595,14 @@ var dshPatchBlock = (command, env) => {
|
|
|
23339
23595
|
` command: ${JSON.stringify(program)}`,
|
|
23340
23596
|
` args: ${JSON.stringify(args)}`,
|
|
23341
23597
|
" env:",
|
|
23342
|
-
` PATH: !!js ${JSON.stringify(
|
|
23598
|
+
` PATH: !!js ${JSON.stringify(searchPath2)}`,
|
|
23343
23599
|
" cwd: !!js process.cwd()",
|
|
23344
23600
|
" toolCallTimeoutMs: 120000",
|
|
23345
23601
|
YAML_END
|
|
23346
23602
|
].join("\n");
|
|
23347
23603
|
};
|
|
23348
23604
|
async function writeDshPatch(file2, block) {
|
|
23349
|
-
const text =
|
|
23605
|
+
const text = existsSync6(file2) ? await readFile2(file2, "utf8") : "";
|
|
23350
23606
|
const start = text.indexOf(YAML_BEGIN);
|
|
23351
23607
|
const end = text.indexOf(YAML_END);
|
|
23352
23608
|
let next;
|
|
@@ -23362,11 +23618,11 @@ async function writeDshPatch(file2, block) {
|
|
|
23362
23618
|
`;
|
|
23363
23619
|
}
|
|
23364
23620
|
if (next === text) return;
|
|
23365
|
-
await mkdir2(
|
|
23621
|
+
await mkdir2(path12.dirname(file2), { recursive: true });
|
|
23366
23622
|
await writeFile2(file2, next);
|
|
23367
23623
|
}
|
|
23368
23624
|
async function removeDshPatch(file2) {
|
|
23369
|
-
if (!
|
|
23625
|
+
if (!existsSync6(file2)) return;
|
|
23370
23626
|
const text = await readFile2(file2, "utf8");
|
|
23371
23627
|
const start = text.indexOf(YAML_BEGIN);
|
|
23372
23628
|
const end = text.indexOf(YAML_END);
|
|
@@ -23380,31 +23636,31 @@ async function removeDshPatch(file2) {
|
|
|
23380
23636
|
var agentFiles = (options) => {
|
|
23381
23637
|
const env = options.env ?? process.env;
|
|
23382
23638
|
if (options.agent === "dsh") {
|
|
23383
|
-
const home = env.DSH_HOME ||
|
|
23639
|
+
const home = env.DSH_HOME || path12.join(homedir2(), ".dsh");
|
|
23384
23640
|
return {
|
|
23385
|
-
settings:
|
|
23386
|
-
instructions:
|
|
23641
|
+
settings: path12.join(home, "cordis.patch.yml"),
|
|
23642
|
+
instructions: path12.join(home, "AGENTS.md")
|
|
23387
23643
|
};
|
|
23388
23644
|
}
|
|
23389
23645
|
if (options.agent === "codex") {
|
|
23390
|
-
const home = env.CODEX_HOME ??
|
|
23391
|
-
return { settings:
|
|
23646
|
+
const home = env.CODEX_HOME ?? path12.join(homedir2(), ".codex");
|
|
23647
|
+
return { settings: path12.join(home, "config.toml"), instructions: path12.join(home, "AGENTS.md") };
|
|
23392
23648
|
}
|
|
23393
23649
|
if (options.scope === "user") {
|
|
23394
|
-
const home = env.CLAUDE_CONFIG_DIR ??
|
|
23650
|
+
const home = env.CLAUDE_CONFIG_DIR ?? path12.join(homedir2(), ".claude");
|
|
23395
23651
|
return {
|
|
23396
|
-
settings:
|
|
23397
|
-
instructions:
|
|
23652
|
+
settings: path12.join(home, "settings.json"),
|
|
23653
|
+
instructions: path12.join(home, "CLAUDE.md")
|
|
23398
23654
|
};
|
|
23399
23655
|
}
|
|
23400
23656
|
const local = options.scope === "local";
|
|
23401
23657
|
return {
|
|
23402
|
-
settings:
|
|
23658
|
+
settings: path12.join(
|
|
23403
23659
|
options.project,
|
|
23404
23660
|
".claude",
|
|
23405
23661
|
local ? "settings.local.json" : "settings.json"
|
|
23406
23662
|
),
|
|
23407
|
-
instructions:
|
|
23663
|
+
instructions: path12.join(options.project, local ? "CLAUDE.local.md" : "CLAUDE.md")
|
|
23408
23664
|
};
|
|
23409
23665
|
};
|
|
23410
23666
|
async function setupAgent(options) {
|