layermap 0.1.48 → 0.1.50
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 +5 -0
- package/analyzers/project-map-java/java-map.jar +0 -0
- package/dist/cli.mjs +859 -636
- package/package.json +1 -1
- package/pi/layermap.mjs +1 -1
package/dist/cli.mjs
CHANGED
|
@@ -8,16 +8,39 @@ var __export = (target, all) => {
|
|
|
8
8
|
|
|
9
9
|
// src/cli.ts
|
|
10
10
|
import { realpath as realpath4 } from "node:fs/promises";
|
|
11
|
-
import
|
|
11
|
+
import path19 from "node:path";
|
|
12
12
|
import { parseArgs } from "node:util";
|
|
13
13
|
|
|
14
|
+
// src/agent/call-log.ts
|
|
15
|
+
import { appendFile, mkdir, rename, stat } from "node:fs/promises";
|
|
16
|
+
import path from "node:path";
|
|
17
|
+
var LIMIT_BYTES = 2 * 1024 * 1024;
|
|
18
|
+
function mapCallLog(cache) {
|
|
19
|
+
const directory = path.join(cache, "logs");
|
|
20
|
+
const file2 = path.join(directory, "calls.jsonl");
|
|
21
|
+
let queue = Promise.resolve();
|
|
22
|
+
return (record2) => {
|
|
23
|
+
queue = queue.then(async () => {
|
|
24
|
+
await mkdir(directory, { recursive: true, mode: 448 });
|
|
25
|
+
if (((await stat(file2).catch(() => void 0))?.size ?? 0) > LIMIT_BYTES)
|
|
26
|
+
await rename(file2, path.join(directory, "calls.1.jsonl"));
|
|
27
|
+
await appendFile(file2, `${JSON.stringify({ ...record2, pid: process.pid })}
|
|
28
|
+
`, {
|
|
29
|
+
mode: 384
|
|
30
|
+
});
|
|
31
|
+
}).catch(() => {
|
|
32
|
+
});
|
|
33
|
+
return queue;
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
|
|
14
37
|
// src/agent/environment.ts
|
|
15
38
|
import { createHash as createHash6 } from "node:crypto";
|
|
16
39
|
import { existsSync as existsSync6, readFileSync as readFileSync3 } from "node:fs";
|
|
17
|
-
import { mkdir, readdir, readFile as readFile4, rename, rm, stat, utimes, writeFile } from "node:fs/promises";
|
|
40
|
+
import { mkdir as mkdir2, readdir, readFile as readFile4, rename as rename2, rm, stat as stat2, utimes, writeFile } from "node:fs/promises";
|
|
18
41
|
import { createRequire } from "node:module";
|
|
19
42
|
import { homedir } from "node:os";
|
|
20
|
-
import
|
|
43
|
+
import path16 from "node:path";
|
|
21
44
|
import { fileURLToPath } from "node:url";
|
|
22
45
|
|
|
23
46
|
// src/git-runner.ts
|
|
@@ -26,11 +49,11 @@ import { spawn } from "node:child_process";
|
|
|
26
49
|
// src/platform.ts
|
|
27
50
|
import { spawnSync } from "node:child_process";
|
|
28
51
|
import { existsSync } from "node:fs";
|
|
29
|
-
import
|
|
52
|
+
import path2 from "node:path";
|
|
30
53
|
var executableName = (name, platform = process.platform) => platform === "win32" ? `${name}.exe` : name;
|
|
31
54
|
var searchPath = (env) => env.PATH ?? Object.entries(env).find(([name]) => name.toUpperCase() === "PATH")?.[1] ?? "";
|
|
32
55
|
function findOnPath(files, env, platform) {
|
|
33
|
-
const join = platform === "win32" ?
|
|
56
|
+
const join = platform === "win32" ? path2.win32.join : path2.posix.join;
|
|
34
57
|
for (const directory of searchPath(env).split(platform === "win32" ? ";" : ":"))
|
|
35
58
|
for (const file2 of files)
|
|
36
59
|
if (directory && existsSync(join(directory, file2))) return join(directory, file2);
|
|
@@ -73,7 +96,7 @@ function stopProcessTree(pid, signal, platform = process.platform) {
|
|
|
73
96
|
process.kill(-pid, signal);
|
|
74
97
|
return;
|
|
75
98
|
}
|
|
76
|
-
const taskkill =
|
|
99
|
+
const taskkill = path2.win32.join(
|
|
77
100
|
process.env.SystemRoot ?? "C:\\Windows",
|
|
78
101
|
"System32",
|
|
79
102
|
"taskkill.exe"
|
|
@@ -321,9 +344,9 @@ async function gitGrep(git2, search, options) {
|
|
|
321
344
|
}
|
|
322
345
|
const hits = [];
|
|
323
346
|
for (const record2 of found.split("\n")) {
|
|
324
|
-
const [
|
|
325
|
-
if (
|
|
326
|
-
hits.push({ path:
|
|
347
|
+
const [path20, line, text, extra] = record2.split("\0");
|
|
348
|
+
if (path20 && line && text !== void 0 && extra === void 0)
|
|
349
|
+
hits.push({ path: path20, line: Number(line), text });
|
|
327
350
|
}
|
|
328
351
|
return { hits };
|
|
329
352
|
}
|
|
@@ -331,17 +354,17 @@ async function gitGrep(git2, search, options) {
|
|
|
331
354
|
// src/layermap.ts
|
|
332
355
|
import { createHash as createHash5, randomUUID as randomUUID2 } from "node:crypto";
|
|
333
356
|
import { mkdirSync, statSync } from "node:fs";
|
|
334
|
-
import { lstat as
|
|
335
|
-
import
|
|
357
|
+
import { lstat as lstat4, realpath as realpath2 } from "node:fs/promises";
|
|
358
|
+
import path15 from "node:path";
|
|
336
359
|
import { setTimeout as delay } from "node:timers/promises";
|
|
337
360
|
import { DatabaseSync } from "@photostructure/sqlite";
|
|
338
361
|
|
|
339
362
|
// src/capture-policy.ts
|
|
340
|
-
import
|
|
363
|
+
import path4 from "node:path";
|
|
341
364
|
|
|
342
365
|
// src/file-universe.ts
|
|
343
366
|
import { lstat } from "node:fs/promises";
|
|
344
|
-
import
|
|
367
|
+
import path3 from "node:path";
|
|
345
368
|
var FILE_UNIVERSE_ARGS = Object.freeze([
|
|
346
369
|
"ls-files",
|
|
347
370
|
"-z",
|
|
@@ -370,8 +393,8 @@ var parseFileUniverse = (output) => {
|
|
|
370
393
|
const records = output.toString("utf8").split("\0");
|
|
371
394
|
for (const record2 of records) {
|
|
372
395
|
if (record2.length === 0) continue;
|
|
373
|
-
const normalized =
|
|
374
|
-
if (normalized !== record2 || normalized === "." || normalized === ".." || normalized.startsWith("../") ||
|
|
396
|
+
const normalized = path3.posix.normalize(record2);
|
|
397
|
+
if (normalized !== record2 || normalized === "." || normalized === ".." || normalized.startsWith("../") || path3.posix.isAbsolute(normalized) || normalized.includes("\\")) {
|
|
375
398
|
throw new ProjectEvidenceFileUniverseError("PROJECT_FILE_UNIVERSE_INVALID");
|
|
376
399
|
}
|
|
377
400
|
files.add(normalized);
|
|
@@ -416,7 +439,7 @@ var ProjectEvidenceFileUniverse = class {
|
|
|
416
439
|
const candidates = parseFileUniverse(listed);
|
|
417
440
|
const present = await Promise.all(
|
|
418
441
|
candidates.map(
|
|
419
|
-
(file2) => lstat(
|
|
442
|
+
(file2) => lstat(path3.join(root, ...file2.split("/"))).then(
|
|
420
443
|
() => true,
|
|
421
444
|
(error51) => {
|
|
422
445
|
if (error51.code === "ENOENT" || error51.code === "ENOTDIR") return false;
|
|
@@ -556,7 +579,7 @@ var ProjectEvidencePolicyError = class extends Error {
|
|
|
556
579
|
var assertProjectEvidencePathNotSensitive = (relativePath) => {
|
|
557
580
|
const segments2 = relativePath.toLowerCase().split("/");
|
|
558
581
|
const basename = segments2.at(-1) ?? "";
|
|
559
|
-
const extension =
|
|
582
|
+
const extension = path4.posix.extname(basename);
|
|
560
583
|
const containsSensitiveSequence = sensitiveSegmentSequences.some(
|
|
561
584
|
(sequence) => segments2.length >= sequence.length && segments2.some(
|
|
562
585
|
(_, start) => sequence.every((segment, offset) => segments2[start + offset] === segment)
|
|
@@ -569,8 +592,8 @@ var assertProjectEvidencePathNotSensitive = (relativePath) => {
|
|
|
569
592
|
};
|
|
570
593
|
var isProjectEvidenceTraversalExcluded = (relativePath) => relativePath.toLowerCase().split("/").some((segment) => traversalExcludedSegmentSet.has(segment));
|
|
571
594
|
var isProjectEvidenceTextPath = (relativePath) => {
|
|
572
|
-
const basename =
|
|
573
|
-
const extension =
|
|
595
|
+
const basename = path4.posix.basename(relativePath).toLowerCase();
|
|
596
|
+
const extension = path4.posix.extname(basename);
|
|
574
597
|
if (allowedTextBasenameSet.has(basename)) return true;
|
|
575
598
|
return extension ? allowedTextExtensionSet.has(extension) : allowedExtensionlessNameSet.has(basename);
|
|
576
599
|
};
|
|
@@ -579,7 +602,7 @@ var isProjectEvidenceTextPath = (relativePath) => {
|
|
|
579
602
|
import { createHash as createHash2 } from "node:crypto";
|
|
580
603
|
|
|
581
604
|
// src/core.ts
|
|
582
|
-
import
|
|
605
|
+
import path5 from "node:path";
|
|
583
606
|
|
|
584
607
|
// node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/classic/external.js
|
|
585
608
|
var external_exports = {};
|
|
@@ -1347,10 +1370,10 @@ function mergeDefs(...defs) {
|
|
|
1347
1370
|
function cloneDef(schema) {
|
|
1348
1371
|
return mergeDefs(schema._zod.def);
|
|
1349
1372
|
}
|
|
1350
|
-
function getElementAtPath(obj,
|
|
1351
|
-
if (!
|
|
1373
|
+
function getElementAtPath(obj, path20) {
|
|
1374
|
+
if (!path20)
|
|
1352
1375
|
return obj;
|
|
1353
|
-
return
|
|
1376
|
+
return path20.reduce((acc, key) => acc?.[key], obj);
|
|
1354
1377
|
}
|
|
1355
1378
|
function promiseAllObject(promisesObj) {
|
|
1356
1379
|
const keys = Object.keys(promisesObj);
|
|
@@ -1759,11 +1782,11 @@ function explicitlyAborted(x, startIndex = 0) {
|
|
|
1759
1782
|
}
|
|
1760
1783
|
return false;
|
|
1761
1784
|
}
|
|
1762
|
-
function prefixIssues(
|
|
1785
|
+
function prefixIssues(path20, issues) {
|
|
1763
1786
|
return issues.map((iss) => {
|
|
1764
1787
|
var _a3;
|
|
1765
1788
|
(_a3 = iss).path ?? (_a3.path = []);
|
|
1766
|
-
iss.path.unshift(
|
|
1789
|
+
iss.path.unshift(path20);
|
|
1767
1790
|
return iss;
|
|
1768
1791
|
});
|
|
1769
1792
|
}
|
|
@@ -1910,16 +1933,16 @@ function flattenError(error51, mapper = (issue2) => issue2.message) {
|
|
|
1910
1933
|
}
|
|
1911
1934
|
function formatError(error51, mapper = (issue2) => issue2.message) {
|
|
1912
1935
|
const fieldErrors = { _errors: [] };
|
|
1913
|
-
const processError = (error52,
|
|
1936
|
+
const processError = (error52, path20 = []) => {
|
|
1914
1937
|
for (const issue2 of error52.issues) {
|
|
1915
1938
|
if (issue2.code === "invalid_union" && issue2.errors.length) {
|
|
1916
|
-
issue2.errors.map((issues) => processError({ issues }, [...
|
|
1939
|
+
issue2.errors.map((issues) => processError({ issues }, [...path20, ...issue2.path]));
|
|
1917
1940
|
} else if (issue2.code === "invalid_key") {
|
|
1918
|
-
processError({ issues: issue2.issues }, [...
|
|
1941
|
+
processError({ issues: issue2.issues }, [...path20, ...issue2.path]);
|
|
1919
1942
|
} else if (issue2.code === "invalid_element") {
|
|
1920
|
-
processError({ issues: issue2.issues }, [...
|
|
1943
|
+
processError({ issues: issue2.issues }, [...path20, ...issue2.path]);
|
|
1921
1944
|
} else {
|
|
1922
|
-
const fullpath = [...
|
|
1945
|
+
const fullpath = [...path20, ...issue2.path];
|
|
1923
1946
|
if (fullpath.length === 0) {
|
|
1924
1947
|
fieldErrors._errors.push(mapper(issue2));
|
|
1925
1948
|
} else {
|
|
@@ -1946,17 +1969,17 @@ function formatError(error51, mapper = (issue2) => issue2.message) {
|
|
|
1946
1969
|
}
|
|
1947
1970
|
function treeifyError(error51, mapper = (issue2) => issue2.message) {
|
|
1948
1971
|
const result = { errors: [] };
|
|
1949
|
-
const processError = (error52,
|
|
1972
|
+
const processError = (error52, path20 = []) => {
|
|
1950
1973
|
var _a3, _b;
|
|
1951
1974
|
for (const issue2 of error52.issues) {
|
|
1952
1975
|
if (issue2.code === "invalid_union" && issue2.errors.length) {
|
|
1953
|
-
issue2.errors.map((issues) => processError({ issues }, [...
|
|
1976
|
+
issue2.errors.map((issues) => processError({ issues }, [...path20, ...issue2.path]));
|
|
1954
1977
|
} else if (issue2.code === "invalid_key") {
|
|
1955
|
-
processError({ issues: issue2.issues }, [...
|
|
1978
|
+
processError({ issues: issue2.issues }, [...path20, ...issue2.path]);
|
|
1956
1979
|
} else if (issue2.code === "invalid_element") {
|
|
1957
|
-
processError({ issues: issue2.issues }, [...
|
|
1980
|
+
processError({ issues: issue2.issues }, [...path20, ...issue2.path]);
|
|
1958
1981
|
} else {
|
|
1959
|
-
const fullpath = [...
|
|
1982
|
+
const fullpath = [...path20, ...issue2.path];
|
|
1960
1983
|
if (fullpath.length === 0) {
|
|
1961
1984
|
result.errors.push(mapper(issue2));
|
|
1962
1985
|
continue;
|
|
@@ -1988,8 +2011,8 @@ function treeifyError(error51, mapper = (issue2) => issue2.message) {
|
|
|
1988
2011
|
}
|
|
1989
2012
|
function toDotPath(_path) {
|
|
1990
2013
|
const segs = [];
|
|
1991
|
-
const
|
|
1992
|
-
for (const seg of
|
|
2014
|
+
const path20 = _path.map((seg) => typeof seg === "object" ? seg.key : seg);
|
|
2015
|
+
for (const seg of path20) {
|
|
1993
2016
|
if (typeof seg === "number")
|
|
1994
2017
|
segs.push(`[${seg}]`);
|
|
1995
2018
|
else if (typeof seg === "symbol")
|
|
@@ -14681,13 +14704,13 @@ function resolveRef(ref, ctx) {
|
|
|
14681
14704
|
if (!ref.startsWith("#")) {
|
|
14682
14705
|
throw new Error("External $ref is not supported, only local refs (#/...) are allowed");
|
|
14683
14706
|
}
|
|
14684
|
-
const
|
|
14685
|
-
if (
|
|
14707
|
+
const path20 = ref.slice(1).split("/").filter(Boolean);
|
|
14708
|
+
if (path20.length === 0) {
|
|
14686
14709
|
return ctx.rootSchema;
|
|
14687
14710
|
}
|
|
14688
14711
|
const defsKey = ctx.version === "draft-2020-12" ? "$defs" : "definitions";
|
|
14689
|
-
if (
|
|
14690
|
-
const key =
|
|
14712
|
+
if (path20[0] === defsKey) {
|
|
14713
|
+
const key = path20[1];
|
|
14691
14714
|
if (!key || !ctx.defs[key]) {
|
|
14692
14715
|
throw new Error(`Reference not found: ${ref}`);
|
|
14693
14716
|
}
|
|
@@ -15115,14 +15138,14 @@ var ProjectEvidencePathError = class extends Error {
|
|
|
15115
15138
|
code;
|
|
15116
15139
|
};
|
|
15117
15140
|
var normalizeProjectEvidencePath = (value, allowRoot = false) => {
|
|
15118
|
-
if (value.includes("\0") ||
|
|
15141
|
+
if (value.includes("\0") || path5.isAbsolute(value) || value.includes("\\")) {
|
|
15119
15142
|
throw new ProjectEvidencePathError("PROJECT_PATH_INVALID");
|
|
15120
15143
|
}
|
|
15121
15144
|
if (value === ".") {
|
|
15122
15145
|
if (allowRoot) return "";
|
|
15123
15146
|
throw new ProjectEvidencePathError("PROJECT_PATH_INVALID");
|
|
15124
15147
|
}
|
|
15125
|
-
const normalized =
|
|
15148
|
+
const normalized = path5.posix.normalize(value);
|
|
15126
15149
|
if (normalized.length === 0 || normalized !== value || normalized === ".." || normalized.startsWith("../") || value.split("/").some((segment) => segment.length === 0 || segment === "." || segment === "..")) {
|
|
15127
15150
|
throw new ProjectEvidencePathError("PROJECT_PATH_INVALID");
|
|
15128
15151
|
}
|
|
@@ -15330,14 +15353,14 @@ var CodeCommitReader = class _CodeCommitReader {
|
|
|
15330
15353
|
// src/code-worktree-reader.ts
|
|
15331
15354
|
import { constants as fsConstants } from "node:fs";
|
|
15332
15355
|
import { lstat as lstat2, open, realpath } from "node:fs/promises";
|
|
15333
|
-
import
|
|
15356
|
+
import path6 from "node:path";
|
|
15334
15357
|
var fileSystemErrorCode = (error51) => {
|
|
15335
15358
|
if (typeof error51 !== "object" || error51 === null || !("code" in error51)) return void 0;
|
|
15336
15359
|
return typeof error51.code === "string" ? error51.code : void 0;
|
|
15337
15360
|
};
|
|
15338
15361
|
var isInsideRoot = (root, candidate) => {
|
|
15339
|
-
const relative =
|
|
15340
|
-
return relative === "" || !relative.startsWith(`..${
|
|
15362
|
+
const relative = path6.relative(root, candidate);
|
|
15363
|
+
return relative === "" || !relative.startsWith(`..${path6.sep}`) && relative !== "..";
|
|
15341
15364
|
};
|
|
15342
15365
|
var stablePathFingerprint = (stats) => (stats.isDirectory() ? ["directory", stats.dev, stats.ino] : [
|
|
15343
15366
|
stats.dev,
|
|
@@ -15380,7 +15403,7 @@ var StableProjectCaptureSession = class _StableProjectCaptureSession {
|
|
|
15380
15403
|
}
|
|
15381
15404
|
async captureFile(relativePath) {
|
|
15382
15405
|
this.assertNotAborted();
|
|
15383
|
-
const absolutePath =
|
|
15406
|
+
const absolutePath = path6.join(this.root, ...relativePath.split("/"));
|
|
15384
15407
|
const stats = await this.inspectPath(absolutePath, true);
|
|
15385
15408
|
const fingerprint = stablePathFingerprint(stats);
|
|
15386
15409
|
const byteLength = stats.isDirectory() ? 0 : Number(stats.size);
|
|
@@ -15502,11 +15525,11 @@ var StableProjectCaptureSession = class _StableProjectCaptureSession {
|
|
|
15502
15525
|
if (!isInsideRoot(this.root, absolutePath)) {
|
|
15503
15526
|
throw new ProjectEvidenceError("PROJECT_PATH_OUTSIDE_ROOT", false);
|
|
15504
15527
|
}
|
|
15505
|
-
const relative =
|
|
15506
|
-
const components = relative === "" ? [] : relative.split(
|
|
15528
|
+
const relative = path6.relative(this.root, absolutePath);
|
|
15529
|
+
const components = relative === "" ? [] : relative.split(path6.sep);
|
|
15507
15530
|
const paths = [
|
|
15508
15531
|
this.root,
|
|
15509
|
-
...components.map((_, index) =>
|
|
15532
|
+
...components.map((_, index) => path6.join(this.root, ...components.slice(0, index + 1)))
|
|
15510
15533
|
];
|
|
15511
15534
|
let finalStats;
|
|
15512
15535
|
for (const [index, currentPath] of paths.entries()) {
|
|
@@ -15550,7 +15573,7 @@ var StableProjectCaptureSession = class _StableProjectCaptureSession {
|
|
|
15550
15573
|
import { createHash as createHash3 } from "node:crypto";
|
|
15551
15574
|
import { existsSync as existsSync2, readdirSync, readFileSync, realpathSync } from "node:fs";
|
|
15552
15575
|
import { isBuiltin } from "node:module";
|
|
15553
|
-
import
|
|
15576
|
+
import path7 from "node:path";
|
|
15554
15577
|
var INSTALL_RECORDS = [
|
|
15555
15578
|
".pnpm/lock.yaml",
|
|
15556
15579
|
".package-lock.json",
|
|
@@ -15572,8 +15595,8 @@ function mapPackageOf(specifier) {
|
|
|
15572
15595
|
}
|
|
15573
15596
|
function mapInstalledPath(realRoot, relative) {
|
|
15574
15597
|
try {
|
|
15575
|
-
const real = realpathSync.native(
|
|
15576
|
-
return real.startsWith(`${realRoot}${
|
|
15598
|
+
const real = realpathSync.native(path7.join(realRoot, relative));
|
|
15599
|
+
return real.startsWith(`${realRoot}${path7.sep}`) ? real : void 0;
|
|
15577
15600
|
} catch {
|
|
15578
15601
|
return void 0;
|
|
15579
15602
|
}
|
|
@@ -15590,21 +15613,21 @@ var versionOf = (realRoot, relative) => {
|
|
|
15590
15613
|
};
|
|
15591
15614
|
function installedAt(realRoot, directory, real) {
|
|
15592
15615
|
const records = INSTALL_RECORDS.flatMap((name) => {
|
|
15593
|
-
const file2 = mapInstalledPath(realRoot,
|
|
15616
|
+
const file2 = mapInstalledPath(realRoot, path7.posix.join(directory, name));
|
|
15594
15617
|
return file2 ? [[name, contentDigest(file2)]] : [];
|
|
15595
15618
|
});
|
|
15596
15619
|
if (records.length) return records;
|
|
15597
15620
|
const packages = readdirSync(real).flatMap((name) => {
|
|
15598
15621
|
if (name.startsWith(".")) return [];
|
|
15599
15622
|
if (!name.startsWith("@")) return [name];
|
|
15600
|
-
const scope = mapInstalledPath(realRoot,
|
|
15623
|
+
const scope = mapInstalledPath(realRoot, path7.posix.join(directory, name));
|
|
15601
15624
|
return scope ? readdirSync(scope).map((inner) => `${name}/${inner}`) : [];
|
|
15602
15625
|
});
|
|
15603
|
-
const beside =
|
|
15626
|
+
const beside = path7.join(realRoot, path7.posix.dirname(directory));
|
|
15604
15627
|
return {
|
|
15605
15628
|
packages: packages.sort().map((name) => [name, versionOf(realRoot, `${directory}/${name}`)]),
|
|
15606
15629
|
lockfiles: LOCKFILES.flatMap((name) => {
|
|
15607
|
-
const file2 =
|
|
15630
|
+
const file2 = path7.join(beside, name);
|
|
15608
15631
|
return existsSync2(file2) ? [[name, contentDigest(file2)]] : [];
|
|
15609
15632
|
})
|
|
15610
15633
|
};
|
|
@@ -15613,15 +15636,15 @@ function mapInstalledDigest(root, paths) {
|
|
|
15613
15636
|
const realRoot = realpathSync.native(root);
|
|
15614
15637
|
const directories = /* @__PURE__ */ new Set(["."]);
|
|
15615
15638
|
for (const file2 of paths) {
|
|
15616
|
-
let at =
|
|
15639
|
+
let at = path7.posix.dirname(file2);
|
|
15617
15640
|
while (at !== "." && !directories.has(at)) {
|
|
15618
15641
|
directories.add(at);
|
|
15619
|
-
at =
|
|
15642
|
+
at = path7.posix.dirname(at);
|
|
15620
15643
|
}
|
|
15621
15644
|
}
|
|
15622
15645
|
const installed = [];
|
|
15623
15646
|
for (const directory of [...directories].sort()) {
|
|
15624
|
-
const modules =
|
|
15647
|
+
const modules = path7.posix.join(directory, "node_modules");
|
|
15625
15648
|
const real = mapInstalledPath(realRoot, modules);
|
|
15626
15649
|
if (real) installed.push([modules, installedAt(realRoot, modules, real)]);
|
|
15627
15650
|
}
|
|
@@ -15629,7 +15652,7 @@ function mapInstalledDigest(root, paths) {
|
|
|
15629
15652
|
}
|
|
15630
15653
|
|
|
15631
15654
|
// src/source-scope.ts
|
|
15632
|
-
import
|
|
15655
|
+
import path8 from "node:path";
|
|
15633
15656
|
var InitialEvidenceScopeSchema = external_exports.object({
|
|
15634
15657
|
pathPrefixes: external_exports.array(ProjectEvidenceGrantPathPrefixSchema).min(1).max(64)
|
|
15635
15658
|
}).strict();
|
|
@@ -15717,7 +15740,7 @@ var includesInitialEvidencePath = (relativePath, scope) => {
|
|
|
15717
15740
|
if (isProjectEvidenceTraversalExcluded(relativePath) || inExcludedDirectory(relativePath))
|
|
15718
15741
|
return false;
|
|
15719
15742
|
const basename = relativePath.toLowerCase().split("/").at(-1) ?? "";
|
|
15720
|
-
return extensions.has(
|
|
15743
|
+
return extensions.has(path8.posix.extname(basename)) || SOURCE_POLICY.documentationFiles.includes(basename) || SOURCE_POLICY.configurationFiles.includes(basename) || SOURCE_POLICY.workspaceFiles.includes(relativePath);
|
|
15721
15744
|
};
|
|
15722
15745
|
|
|
15723
15746
|
// src/code-index-capture.ts
|
|
@@ -16094,8 +16117,8 @@ var MapAnalysisSchema = external_exports.object({
|
|
|
16094
16117
|
var mapPathAllowed = (relative, prefixes) => prefixes.some(
|
|
16095
16118
|
(prefix) => prefix === "." || relative === prefix || relative.startsWith(`${prefix}/`)
|
|
16096
16119
|
);
|
|
16097
|
-
var mapTestPath = (
|
|
16098
|
-
|
|
16120
|
+
var mapTestPath = (path20) => /(?:^|\/)(?:__tests__|tests?|fixtures?|testFixtures|e2e|testdata)(?:\/|$)|\.(?:spec|test)\.|_test\.(?:go|py)$|(?:^|\/)(?:test_[^/]*\.py|conftest\.py)$/iu.test(
|
|
16121
|
+
path20
|
|
16099
16122
|
);
|
|
16100
16123
|
var mapRunnableTest = (file2) => /_test\.(?:go|py)$|(?:^|\/)test_[^/]*\.py$|(?:\.(?:test|spec)|\.e2e-spec|(?:^|\/)__tests__\/.*)\.[cm]?[jt]sx?$|(?:^|\/)(?:Test|IT)[A-Z]\w*\.(?:java|kt)$|(?:Test|Tests|TestCase|IT|ITCase)\.(?:java|kt)$/u.test(
|
|
16101
16124
|
file2
|
|
@@ -16144,7 +16167,7 @@ var MapReferenceResultSchema = external_exports.object({
|
|
|
16144
16167
|
authority: external_exports.literal("CODE_FACTS_AND_SOURCE_DECLARATIONS_NOT_BUSINESS_AUTHORITY"),
|
|
16145
16168
|
testing: external_exports.literal("TEST_ASSOCIATION_IS_NOT_BEHAVIOR_VERIFICATION"),
|
|
16146
16169
|
object: MapObjectSchema,
|
|
16147
|
-
query: external_exports.object({
|
|
16170
|
+
query: external_exports.object({ within: external_exports.string(), kinds: external_exports.array(MapReferenceKindSchema) }).strict(),
|
|
16148
16171
|
references: external_exports.array(
|
|
16149
16172
|
MapReferenceSchema.extend({
|
|
16150
16173
|
contextRef: external_exports.string(),
|
|
@@ -16200,11 +16223,11 @@ var string4 = (value) => {
|
|
|
16200
16223
|
var identity = (id2, reconstructed) => id2 === reconstructed ? [] : [JSON.stringify(id2)];
|
|
16201
16224
|
function encodeMapText(graph) {
|
|
16202
16225
|
const files = /* @__PURE__ */ new Map();
|
|
16203
|
-
const file2 = (
|
|
16204
|
-
let ref = files.get(
|
|
16226
|
+
const file2 = (path20) => {
|
|
16227
|
+
let ref = files.get(path20);
|
|
16205
16228
|
if (!ref) {
|
|
16206
16229
|
ref = `F${files.size + 1}`;
|
|
16207
|
-
files.set(
|
|
16230
|
+
files.set(path20, ref);
|
|
16208
16231
|
}
|
|
16209
16232
|
return ref;
|
|
16210
16233
|
};
|
|
@@ -16252,7 +16275,7 @@ function encodeMapText(graph) {
|
|
|
16252
16275
|
rows2.push(`B ${node(frontier.entityRef)} ${frontier.direction}`);
|
|
16253
16276
|
return [
|
|
16254
16277
|
...header,
|
|
16255
|
-
...[...files].map(([
|
|
16278
|
+
...[...files].map(([path20, ref]) => `${ref} ${JSON.stringify(path20)}`),
|
|
16256
16279
|
...rows2
|
|
16257
16280
|
].join("\n");
|
|
16258
16281
|
}
|
|
@@ -16272,10 +16295,10 @@ function decodeMapText(text) {
|
|
|
16272
16295
|
const at = (value) => {
|
|
16273
16296
|
const match = /^(F[1-9]\d*):(\d+)-(\d+)@(\d+)-(\d+)$/u.exec(value ?? "");
|
|
16274
16297
|
if (!match) return failed();
|
|
16275
|
-
const
|
|
16276
|
-
if (
|
|
16298
|
+
const path20 = files.get(match[1] ?? "");
|
|
16299
|
+
if (path20 === void 0) return failed();
|
|
16277
16300
|
return MapAnchorSchema.parse({
|
|
16278
|
-
path:
|
|
16301
|
+
path: path20,
|
|
16279
16302
|
startLine: Number(match[2]),
|
|
16280
16303
|
endLine: Number(match[3]),
|
|
16281
16304
|
start: Number(match[4]),
|
|
@@ -16352,8 +16375,8 @@ function decodeMapText(text) {
|
|
|
16352
16375
|
var locationSchema = MapAnchorSchema.describe(
|
|
16353
16376
|
"Source location: start/end are zero-based UTF-16 offsets with an exclusive end; line numbers are one-based."
|
|
16354
16377
|
);
|
|
16355
|
-
var location = ({ path:
|
|
16356
|
-
path:
|
|
16378
|
+
var location = ({ path: path20, startLine, endLine, start, end }) => ({
|
|
16379
|
+
path: path20,
|
|
16357
16380
|
startLine,
|
|
16358
16381
|
endLine,
|
|
16359
16382
|
start,
|
|
@@ -16456,11 +16479,11 @@ var MapNavigationObjectsSchema = external_exports.union([
|
|
|
16456
16479
|
),
|
|
16457
16480
|
external_exports.object({ files: external_exports.array(searchFileSchema) }).passthrough().refine((value) => !("format" in value), "Text navigation must decode through its format.").transform(
|
|
16458
16481
|
(value) => value.files.flatMap(
|
|
16459
|
-
({ path:
|
|
16482
|
+
({ path: path20, symbols }) => symbols.map(({ id: id2, name, kind, startLine, endLine, start, end, execution }) => ({
|
|
16460
16483
|
id: id2,
|
|
16461
16484
|
name,
|
|
16462
16485
|
kind,
|
|
16463
|
-
anchor: { path:
|
|
16486
|
+
anchor: { path: path20, startLine, endLine, start, end },
|
|
16464
16487
|
...execution ? { execution } : {}
|
|
16465
16488
|
}))
|
|
16466
16489
|
)
|
|
@@ -16473,10 +16496,10 @@ var mapSearchNavigation = (result) => {
|
|
|
16473
16496
|
for (const [index, object2] of found.entries()) {
|
|
16474
16497
|
const ranking = rankings[index];
|
|
16475
16498
|
if (!ranking) throw new Error("PROJECT_MAP_SEARCH_RANKING_MISSING");
|
|
16476
|
-
const
|
|
16499
|
+
const path20 = object2.anchor.path;
|
|
16477
16500
|
let file2 = files.at(-1);
|
|
16478
|
-
if (file2?.path !==
|
|
16479
|
-
file2 = { path:
|
|
16501
|
+
if (file2?.path !== path20) {
|
|
16502
|
+
file2 = { path: path20, symbols: [] };
|
|
16480
16503
|
files.push(file2);
|
|
16481
16504
|
}
|
|
16482
16505
|
file2.symbols.push({
|
|
@@ -16607,8 +16630,8 @@ var MapViewGraph = class {
|
|
|
16607
16630
|
}
|
|
16608
16631
|
return object2;
|
|
16609
16632
|
}
|
|
16610
|
-
objectsAt(
|
|
16611
|
-
return this.statements.path.all(this.version,
|
|
16633
|
+
objectsAt(path20) {
|
|
16634
|
+
return this.statements.path.all(this.version, path20).map((row) => {
|
|
16612
16635
|
const object2 = MapObjectSchema.parse(JSON.parse(String(row.object_json)));
|
|
16613
16636
|
this.objects.set(object2.id, object2);
|
|
16614
16637
|
return object2;
|
|
@@ -16634,8 +16657,8 @@ var MapViewGraph = class {
|
|
|
16634
16657
|
return this.statements.children.all(this.version, ref).map((row) => String(row.to_ref));
|
|
16635
16658
|
}
|
|
16636
16659
|
/** The declarations of a file other code can name, without the file itself. */
|
|
16637
|
-
declarationsAt(
|
|
16638
|
-
return this.objectsAt(
|
|
16660
|
+
declarationsAt(path20) {
|
|
16661
|
+
return this.objectsAt(path20).filter(
|
|
16639
16662
|
(object2) => !mapIsModule(object2) && this.isAddressable(object2)
|
|
16640
16663
|
);
|
|
16641
16664
|
}
|
|
@@ -16743,8 +16766,8 @@ var MapViewGraph = class {
|
|
|
16743
16766
|
);
|
|
16744
16767
|
}
|
|
16745
16768
|
};
|
|
16746
|
-
function mapSelectDeclarations(graph,
|
|
16747
|
-
const objects2 = graph.objectsAt(
|
|
16769
|
+
function mapSelectDeclarations(graph, path20, name, line) {
|
|
16770
|
+
const objects2 = graph.objectsAt(path20).filter((object2) => !mapIsModule(object2));
|
|
16748
16771
|
const matching = name === void 0 ? objects2 : objects2.filter(
|
|
16749
16772
|
(object2) => object2.name === name || name.includes(".") && graph.qualifiedName(object2.id) === name
|
|
16750
16773
|
);
|
|
@@ -16766,12 +16789,12 @@ function requireMapObject(store, version2, selector, prefixes) {
|
|
|
16766
16789
|
if ([entityRef, locator, symbol2].filter((value) => value !== void 0).length !== 1 || entityRef !== void 0 && !entityRef.length)
|
|
16767
16790
|
throw new ProjectEvidenceError("PROJECT_READ_INPUT_INVALID", false);
|
|
16768
16791
|
if (symbol2) {
|
|
16769
|
-
const
|
|
16770
|
-
if (!mapPathAllowed(
|
|
16792
|
+
const path20 = normalizeProjectEvidencePath(symbol2.path);
|
|
16793
|
+
if (!mapPathAllowed(path20, prefixes))
|
|
16771
16794
|
throw new ProjectEvidenceError("PROJECT_MAP_OBJECT_NOT_FOUND", false);
|
|
16772
16795
|
const selected = mapSelectDeclarations(
|
|
16773
16796
|
new MapViewGraph(store, version2),
|
|
16774
|
-
|
|
16797
|
+
path20,
|
|
16775
16798
|
symbol2.name,
|
|
16776
16799
|
symbol2.line
|
|
16777
16800
|
);
|
|
@@ -16782,14 +16805,14 @@ function requireMapObject(store, version2, selector, prefixes) {
|
|
|
16782
16805
|
}
|
|
16783
16806
|
let rows2;
|
|
16784
16807
|
if (locator) {
|
|
16785
|
-
const
|
|
16808
|
+
const path20 = normalizeProjectEvidencePath(locator.path);
|
|
16786
16809
|
if (!Number.isSafeInteger(locator.start) || locator.start < 0 || locator.kind !== void 0 && !MapObjectKindSchema.safeParse(locator.kind).success)
|
|
16787
16810
|
throw new ProjectEvidenceError("PROJECT_READ_INPUT_INVALID", false);
|
|
16788
|
-
if (!mapPathAllowed(
|
|
16811
|
+
if (!mapPathAllowed(path20, prefixes))
|
|
16789
16812
|
throw new ProjectEvidenceError("PROJECT_MAP_OBJECT_NOT_FOUND", false);
|
|
16790
16813
|
rows2 = store.database.prepare(`SELECT object_json FROM project_map_objects
|
|
16791
16814
|
WHERE version_ref = ? AND path = ? AND json_extract(object_json, '$.anchor.start') = ?
|
|
16792
|
-
AND (? IS NULL OR kind = ?) LIMIT 2`).all(version2,
|
|
16815
|
+
AND (? IS NULL OR kind = ?) LIMIT 2`).all(version2, path20, locator.start, locator.kind ?? null, locator.kind ?? null);
|
|
16793
16816
|
} else {
|
|
16794
16817
|
rows2 = store.database.prepare(
|
|
16795
16818
|
"SELECT object_json FROM project_map_objects WHERE version_ref = ? AND entity_ref = ?"
|
|
@@ -16830,13 +16853,13 @@ function mapQueryPage(count, materialize, navigation, budget) {
|
|
|
16830
16853
|
|
|
16831
16854
|
// src/project-map-query-selection.ts
|
|
16832
16855
|
var mapQuerySelection = (input, knownKinds) => {
|
|
16833
|
-
const
|
|
16856
|
+
const path20 = normalizeProjectEvidencePath(input.path ?? ".", true) || ".";
|
|
16834
16857
|
const kinds = input.kinds ?? knownKinds;
|
|
16835
16858
|
if (!Array.isArray(kinds) || !kinds.length || kinds.length > knownKinds.length || kinds.some((kind) => !knownKinds.includes(kind)))
|
|
16836
16859
|
throw new ProjectEvidenceError("PROJECT_READ_INPUT_INVALID", false);
|
|
16837
|
-
return { path:
|
|
16860
|
+
return { path: path20, kinds: [...new Set(kinds)].sort() };
|
|
16838
16861
|
};
|
|
16839
|
-
var mapQueryPathMatches = (
|
|
16862
|
+
var mapQueryPathMatches = (path20, prefix) => prefix === "." || path20 === prefix || path20.startsWith(`${prefix}/`);
|
|
16840
16863
|
var MAP_RELATION_TARGET_JOIN = `LEFT JOIN project_map_unit_objects t ON t.entity_ref = r.to_ref
|
|
16841
16864
|
AND EXISTS (SELECT 1 FROM project_map_version_units target
|
|
16842
16865
|
WHERE target.version_ref = r.version_ref AND target.unit_ref = t.unit_ref AND target.path = t.path)`;
|
|
@@ -16938,7 +16961,7 @@ var declarationKinds = /* @__PURE__ */ new Set([
|
|
|
16938
16961
|
"METHOD",
|
|
16939
16962
|
"TYPE"
|
|
16940
16963
|
]);
|
|
16941
|
-
var fileStem = (
|
|
16964
|
+
var fileStem = (path20) => path20.slice(path20.lastIndexOf("/") + 1).replace(/\.(?:[cm]?[jt]sx?|vue|svelte|go|pyi?)$/iu, "");
|
|
16942
16965
|
var compareText = (left, right) => left < right ? -1 : left > right ? 1 : 0;
|
|
16943
16966
|
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);
|
|
16944
16967
|
function mapSearchQuery(input) {
|
|
@@ -16965,10 +16988,10 @@ function mapSearchQuery(input) {
|
|
|
16965
16988
|
}
|
|
16966
16989
|
function rank(object2, documentation, relationCount, query, focus) {
|
|
16967
16990
|
const name = object2.name.toLowerCase();
|
|
16968
|
-
const
|
|
16991
|
+
const path20 = object2.anchor.path.toLowerCase();
|
|
16969
16992
|
const values = {
|
|
16970
16993
|
NAME: [name],
|
|
16971
|
-
PATH: [
|
|
16994
|
+
PATH: [path20],
|
|
16972
16995
|
DOCUMENTATION: documentation.map((text) => text.toLowerCase())
|
|
16973
16996
|
};
|
|
16974
16997
|
const matched = query.terms.map((term) => ({
|
|
@@ -16993,12 +17016,12 @@ function rank(object2, documentation, relationCount, query, focus) {
|
|
|
16993
17016
|
score += 7e3;
|
|
16994
17017
|
signals.push("SYMBOL_CONTAINS");
|
|
16995
17018
|
} else if (matchedFields.includes("NAME")) signals.push("SYMBOL_CONTAINS");
|
|
16996
|
-
if (object2.kind === "FILE" && fileStem(
|
|
17019
|
+
if (object2.kind === "FILE" && fileStem(path20) === normalizedQuery) {
|
|
16997
17020
|
score += 11e3;
|
|
16998
17021
|
signals.push("EXACT_FILE_STEM");
|
|
16999
17022
|
}
|
|
17000
17023
|
if (matchedFields.includes("PATH")) {
|
|
17001
|
-
score +=
|
|
17024
|
+
score += path20.includes(normalizedQuery) ? 2500 : 0;
|
|
17002
17025
|
signals.push("PATH_CONTAINS");
|
|
17003
17026
|
}
|
|
17004
17027
|
if (matchedFields.includes("DOCUMENTATION")) {
|
|
@@ -17013,8 +17036,8 @@ function rank(object2, documentation, relationCount, query, focus) {
|
|
|
17013
17036
|
score += kindWeight[object2.kind] + Math.min(1200, relationCount * 20) + (focus?.score ?? 0);
|
|
17014
17037
|
if (declarationKinds.has(object2.kind)) signals.push("DECLARATION");
|
|
17015
17038
|
if (relationCount > 0) signals.push("GRAPH_CONNECTED");
|
|
17016
|
-
const isTest = mapTestPath(
|
|
17017
|
-
const isGenerated = generatedPath.test(
|
|
17039
|
+
const isTest = mapTestPath(path20);
|
|
17040
|
+
const isGenerated = generatedPath.test(path20);
|
|
17018
17041
|
const hasTestIntent = query.terms.some((term) => testQuery.test(term));
|
|
17019
17042
|
score += isTest ? hasTestIntent ? 1e3 : -5e3 : 300;
|
|
17020
17043
|
score += isGenerated ? -3e3 : 300;
|
|
@@ -17526,13 +17549,13 @@ function utf16Offsets(text) {
|
|
|
17526
17549
|
}
|
|
17527
17550
|
function offsetConverter(files, offsets) {
|
|
17528
17551
|
const converters = /* @__PURE__ */ new Map();
|
|
17529
|
-
return (
|
|
17530
|
-
let convert = converters.get(
|
|
17552
|
+
return (path20, offset) => {
|
|
17553
|
+
let convert = converters.get(path20);
|
|
17531
17554
|
if (!convert) {
|
|
17532
|
-
const text = files[
|
|
17555
|
+
const text = files[path20];
|
|
17533
17556
|
if (text === void 0) return invalid();
|
|
17534
17557
|
convert = offsets === "UTF16" ? (value) => value <= text.length ? value : invalid() : utf16Offsets(text);
|
|
17535
|
-
converters.set(
|
|
17558
|
+
converters.set(path20, convert);
|
|
17536
17559
|
}
|
|
17537
17560
|
return convert(offset);
|
|
17538
17561
|
};
|
|
@@ -17563,7 +17586,7 @@ function mapFactsAnalysis(facts, input, context) {
|
|
|
17563
17586
|
const collect = new MapOutputCollector(output);
|
|
17564
17587
|
const positions = new MapSourcePositions(input.files);
|
|
17565
17588
|
const offset = offsetConverter(input.files, context.offsets);
|
|
17566
|
-
const anchor = (
|
|
17589
|
+
const anchor = (path20, start, end) => positions.span(path20, offset(path20, start), offset(path20, end));
|
|
17567
17590
|
const located = /* @__PURE__ */ new Map();
|
|
17568
17591
|
const canonical = /* @__PURE__ */ new Map();
|
|
17569
17592
|
const bySpan = /* @__PURE__ */ new Map();
|
|
@@ -17738,7 +17761,7 @@ function referencePage(found, positions, offset, reference) {
|
|
|
17738
17761
|
// src/project-map-process.ts
|
|
17739
17762
|
import { execFileSync, spawn as spawn2 } from "node:child_process";
|
|
17740
17763
|
import { existsSync as existsSync3, readFileSync as readFileSync2, realpathSync as realpathSync2 } from "node:fs";
|
|
17741
|
-
import
|
|
17764
|
+
import path9 from "node:path";
|
|
17742
17765
|
|
|
17743
17766
|
// src/project-map-failure.ts
|
|
17744
17767
|
var PhaseSchema = external_exports.enum([
|
|
@@ -17865,24 +17888,24 @@ var ProjectMapStopUnconfirmedError = class extends ProjectEvidenceError {
|
|
|
17865
17888
|
}
|
|
17866
17889
|
};
|
|
17867
17890
|
var installedMapParserResources = () => {
|
|
17868
|
-
const directory =
|
|
17891
|
+
const directory = path9.dirname(path9.resolve(process.argv[1] ?? "."));
|
|
17869
17892
|
return {
|
|
17870
|
-
workerPath:
|
|
17871
|
-
compilerPath:
|
|
17893
|
+
workerPath: path9.join(directory, "project-map-worker.mjs"),
|
|
17894
|
+
compilerPath: path9.join(directory, "project-map-native/tsc")
|
|
17872
17895
|
};
|
|
17873
17896
|
};
|
|
17874
17897
|
var installedPythonMapResources = () => {
|
|
17875
|
-
const directory =
|
|
17898
|
+
const directory = path9.dirname(path9.resolve(process.argv[1] ?? "."));
|
|
17876
17899
|
return {
|
|
17877
|
-
workerPath:
|
|
17878
|
-
compilerPath:
|
|
17900
|
+
workerPath: path9.join(directory, "project-map-python-worker.mjs"),
|
|
17901
|
+
compilerPath: path9.join(directory, "project-map-python/typeshed")
|
|
17879
17902
|
};
|
|
17880
17903
|
};
|
|
17881
17904
|
function discoverJavaRuntime(env = process.env) {
|
|
17882
17905
|
const homes = [env.LAYERMAP_JAVA_HOME, env.JAVA_HOME];
|
|
17883
|
-
for (const directory of (env.PATH ?? env.Path ?? "").split(
|
|
17884
|
-
const java =
|
|
17885
|
-
if (directory && existsSync3(java)) homes.push(
|
|
17906
|
+
for (const directory of (env.PATH ?? env.Path ?? "").split(path9.delimiter)) {
|
|
17907
|
+
const java = path9.join(directory, executableName("java"));
|
|
17908
|
+
if (directory && existsSync3(java)) homes.push(path9.dirname(path9.dirname(realpathSync2(java))));
|
|
17886
17909
|
}
|
|
17887
17910
|
homes.push(
|
|
17888
17911
|
...["/opt/homebrew/opt", "/usr/local/opt"].flatMap(
|
|
@@ -17890,7 +17913,7 @@ function discoverJavaRuntime(env = process.env) {
|
|
|
17890
17913
|
(formula) => `${prefix}/${formula}/libexec/openjdk.jdk/Contents/Home`
|
|
17891
17914
|
)
|
|
17892
17915
|
),
|
|
17893
|
-
...env.HOME ? [
|
|
17916
|
+
...env.HOME ? [path9.join(env.HOME, ".sdkman/candidates/java/current")] : []
|
|
17894
17917
|
);
|
|
17895
17918
|
if (process.platform === "darwin")
|
|
17896
17919
|
try {
|
|
@@ -17905,12 +17928,12 @@ function discoverJavaRuntime(env = process.env) {
|
|
|
17905
17928
|
}
|
|
17906
17929
|
for (const home of homes) {
|
|
17907
17930
|
if (!home) continue;
|
|
17908
|
-
const runtimePath =
|
|
17909
|
-
if (!existsSync3(runtimePath) || !existsSync3(
|
|
17931
|
+
const runtimePath = path9.join(home, "bin", executableName("java"));
|
|
17932
|
+
if (!existsSync3(runtimePath) || !existsSync3(path9.join(home, "bin", executableName("javac"))))
|
|
17910
17933
|
continue;
|
|
17911
17934
|
let release = "";
|
|
17912
17935
|
try {
|
|
17913
|
-
release = readFileSync2(
|
|
17936
|
+
release = readFileSync2(path9.join(home, "release"), "utf8");
|
|
17914
17937
|
} catch {
|
|
17915
17938
|
continue;
|
|
17916
17939
|
}
|
|
@@ -17921,26 +17944,26 @@ function discoverJavaRuntime(env = process.env) {
|
|
|
17921
17944
|
return void 0;
|
|
17922
17945
|
}
|
|
17923
17946
|
var installedJavaMapResources = () => {
|
|
17924
|
-
const directory =
|
|
17925
|
-
const compilerPath =
|
|
17947
|
+
const directory = path9.dirname(path9.resolve(process.argv[1] ?? "."));
|
|
17948
|
+
const compilerPath = path9.join(directory, "project-map-java/java-map.jar");
|
|
17926
17949
|
return {
|
|
17927
|
-
workerPath:
|
|
17950
|
+
workerPath: path9.join(directory, "project-map-java-worker.mjs"),
|
|
17928
17951
|
compilerPath,
|
|
17929
17952
|
// A build without a JDK leaves no analyzer to run, whatever runtime this machine has.
|
|
17930
17953
|
...existsSync3(compilerPath) ? discoverJavaRuntime() : {}
|
|
17931
17954
|
};
|
|
17932
17955
|
};
|
|
17933
17956
|
var installedGoMapResources = () => {
|
|
17934
|
-
const directory =
|
|
17957
|
+
const directory = path9.dirname(path9.resolve(process.argv[1] ?? "."));
|
|
17935
17958
|
return {
|
|
17936
|
-
workerPath:
|
|
17937
|
-
compilerPath:
|
|
17959
|
+
workerPath: path9.join(directory, "project-map-go-worker.mjs"),
|
|
17960
|
+
compilerPath: path9.join(directory, "project-map-go/go-map")
|
|
17938
17961
|
};
|
|
17939
17962
|
};
|
|
17940
17963
|
function runMapOperation(resources, input, schema, signal, observeTiming) {
|
|
17941
17964
|
if (signal.aborted)
|
|
17942
17965
|
return Promise.reject(new ProjectEvidenceError("PROJECT_READ_CANCELLED", true));
|
|
17943
|
-
if (!
|
|
17966
|
+
if (!path9.isAbsolute(resources.workerPath) || !path9.isAbsolute(resources.compilerPath)) {
|
|
17944
17967
|
return Promise.reject(
|
|
17945
17968
|
new ProjectEvidenceError("PROJECT_MAP_PARSER_CONFIGURATION_INVALID", false)
|
|
17946
17969
|
);
|
|
@@ -18143,8 +18166,8 @@ var goWork = /(?:^|\/)go\.work$/u;
|
|
|
18143
18166
|
var codeHosts = /* @__PURE__ */ new Set(["github.com", "gitlab.com", "bitbucket.org"]);
|
|
18144
18167
|
var GO_MAP_LANGUAGE = Object.freeze({
|
|
18145
18168
|
id: "go-1.24-map-v11",
|
|
18146
|
-
claims: (
|
|
18147
|
-
reads: (
|
|
18169
|
+
claims: (path20) => path20.endsWith(".go"),
|
|
18170
|
+
reads: (path20) => goModule.test(path20) || goWork.test(path20),
|
|
18148
18171
|
// A module path, or the standard library, whose first path element has no dot.
|
|
18149
18172
|
importName: (specifier) => {
|
|
18150
18173
|
const parts = specifier.split("/");
|
|
@@ -18153,7 +18176,7 @@ var GO_MAP_LANGUAGE = Object.freeze({
|
|
|
18153
18176
|
return parts.slice(0, size).join("/");
|
|
18154
18177
|
},
|
|
18155
18178
|
// Go imports a package: the directory of the file.
|
|
18156
|
-
importTarget: (
|
|
18179
|
+
importTarget: (path20) => `${path20.slice(0, path20.lastIndexOf("/") + 1) || "./"}`,
|
|
18157
18180
|
create: () => new GoMapAnalyzer()
|
|
18158
18181
|
});
|
|
18159
18182
|
var GO_GAPS = [
|
|
@@ -18178,8 +18201,8 @@ var goMapAnalysis = (facts, input, configurations) => mapFactsAnalysis(facts, in
|
|
|
18178
18201
|
typeIssues: "GO_TYPE_CHECK_ISSUES",
|
|
18179
18202
|
contract: "Declares a Go interface. This does not establish runtime enforcement or business authority."
|
|
18180
18203
|
});
|
|
18181
|
-
var goLocalModules = (
|
|
18182
|
-
const directive = goWork.test(
|
|
18204
|
+
var goLocalModules = (path20, text) => {
|
|
18205
|
+
const directive = goWork.test(path20) ? "use" : "replace";
|
|
18183
18206
|
const found = [];
|
|
18184
18207
|
let block = false;
|
|
18185
18208
|
for (const raw of text.split("\n")) {
|
|
@@ -18193,37 +18216,37 @@ var goLocalModules = (path19, text) => {
|
|
|
18193
18216
|
const target = directive === "use" ? entry : entry?.split("=>")[1];
|
|
18194
18217
|
const directory = target?.trim().split(/\s+/u)[0]?.replace(/^(["`])(.*)\1$/u, "$2");
|
|
18195
18218
|
if (!directory || !/^\.\.?(?:\/|$)/u.test(directory)) continue;
|
|
18196
|
-
const joined = posix.normalize(posix.join(posix.dirname(
|
|
18219
|
+
const joined = posix.normalize(posix.join(posix.dirname(path20), directory)).replace(/\/$/u, "");
|
|
18197
18220
|
if (joined !== ".." && !joined.startsWith("../")) found.push(joined);
|
|
18198
18221
|
}
|
|
18199
18222
|
return found;
|
|
18200
18223
|
};
|
|
18201
18224
|
var goModuleGroups = (files, text) => {
|
|
18202
|
-
const modules = files.filter((
|
|
18203
|
-
const moduleAt = new Map(modules.map((
|
|
18204
|
-
const parent = new Map(modules.map((
|
|
18205
|
-
const root = (
|
|
18206
|
-
const up = parent.get(
|
|
18207
|
-
return up ===
|
|
18225
|
+
const modules = files.filter((path20) => goModule.test(path20)).sort();
|
|
18226
|
+
const moduleAt = new Map(modules.map((path20) => [posix.dirname(path20), path20]));
|
|
18227
|
+
const parent = new Map(modules.map((path20) => [path20, path20]));
|
|
18228
|
+
const root = (path20) => {
|
|
18229
|
+
const up = parent.get(path20) ?? path20;
|
|
18230
|
+
return up === path20 ? path20 : root(up);
|
|
18208
18231
|
};
|
|
18209
18232
|
const works = [];
|
|
18210
|
-
for (const
|
|
18211
|
-
const linked = goLocalModules(
|
|
18212
|
-
const first = goWork.test(
|
|
18233
|
+
for (const path20 of [...files].filter((file2) => goModule.test(file2) || goWork.test(file2)).sort()) {
|
|
18234
|
+
const linked = goLocalModules(path20, text(path20)).flatMap((dir) => moduleAt.get(dir) ?? []);
|
|
18235
|
+
const first = goWork.test(path20) ? linked[0] : path20;
|
|
18213
18236
|
if (!first) continue;
|
|
18214
|
-
if (goWork.test(
|
|
18237
|
+
if (goWork.test(path20)) works.push([path20, first]);
|
|
18215
18238
|
for (const module of linked) {
|
|
18216
18239
|
const [low = first, high = module] = [root(first), root(module)].sort();
|
|
18217
18240
|
if (low !== high) parent.set(high, low);
|
|
18218
18241
|
}
|
|
18219
18242
|
}
|
|
18220
18243
|
const members = /* @__PURE__ */ new Map();
|
|
18221
|
-
for (const
|
|
18244
|
+
for (const path20 of modules) members.set(root(path20), [...members.get(root(path20)) ?? [], path20]);
|
|
18222
18245
|
const named = new Map(works.reverse().map(([work, module]) => [root(module), work]));
|
|
18223
18246
|
return new Map(
|
|
18224
|
-
modules.map((
|
|
18225
|
-
|
|
18226
|
-
{ configPath: named.get(root(
|
|
18247
|
+
modules.map((path20) => [
|
|
18248
|
+
path20,
|
|
18249
|
+
{ configPath: named.get(root(path20)) ?? root(path20), modules: members.get(root(path20)) ?? [] }
|
|
18227
18250
|
])
|
|
18228
18251
|
);
|
|
18229
18252
|
};
|
|
@@ -18253,28 +18276,28 @@ var GoMapAnalyzer = class {
|
|
|
18253
18276
|
}
|
|
18254
18277
|
async analyze(session, signal) {
|
|
18255
18278
|
const paths = session.readable.map((entry) => entry.path);
|
|
18256
|
-
const groupOf = goModuleGroups(paths, (
|
|
18257
|
-
const moduleOf = (
|
|
18279
|
+
const groupOf = goModuleGroups(paths, (path20) => session.texts[path20] ?? "");
|
|
18280
|
+
const moduleOf = (path20) => {
|
|
18258
18281
|
let best;
|
|
18259
18282
|
for (const modFile of groupOf.keys()) {
|
|
18260
18283
|
const directory = modFile.slice(0, modFile.lastIndexOf("/") + 1);
|
|
18261
|
-
if (
|
|
18284
|
+
if (path20.startsWith(directory) && (!best || directory.length > best.lastIndexOf("/") + 1))
|
|
18262
18285
|
best = modFile;
|
|
18263
18286
|
}
|
|
18264
18287
|
return best;
|
|
18265
18288
|
};
|
|
18266
18289
|
const contexts = /* @__PURE__ */ new Map();
|
|
18267
|
-
for (const
|
|
18268
|
-
if (!this.claims(
|
|
18269
|
-
const module = moduleOf(
|
|
18290
|
+
for (const path20 of paths) {
|
|
18291
|
+
if (!this.claims(path20)) continue;
|
|
18292
|
+
const module = moduleOf(path20);
|
|
18270
18293
|
const group = module ? groupOf.get(module) : void 0;
|
|
18271
18294
|
const configPath = group?.configPath ?? "";
|
|
18272
18295
|
const into = contexts.get(configPath);
|
|
18273
|
-
if (into) into.sources.push(
|
|
18296
|
+
if (into) into.sources.push(path20);
|
|
18274
18297
|
else
|
|
18275
18298
|
contexts.set(configPath, {
|
|
18276
18299
|
configurations: group ? [.../* @__PURE__ */ new Set([...group.modules, configPath])].sort() : [],
|
|
18277
|
-
sources: [
|
|
18300
|
+
sources: [path20]
|
|
18278
18301
|
});
|
|
18279
18302
|
}
|
|
18280
18303
|
for (const [configPath, { configurations, sources }] of [...contexts].sort(
|
|
@@ -18282,11 +18305,11 @@ var GoMapAnalyzer = class {
|
|
|
18282
18305
|
)) {
|
|
18283
18306
|
if (signal.aborted) throw new ProjectEvidenceError("PROJECT_READ_CANCELLED", true);
|
|
18284
18307
|
const files = /* @__PURE__ */ Object.create(null);
|
|
18285
|
-
for (const
|
|
18286
|
-
const text = session.texts[
|
|
18308
|
+
for (const path20 of [...sources, ...configurations]) {
|
|
18309
|
+
const text = session.texts[path20];
|
|
18287
18310
|
if (text === void 0)
|
|
18288
18311
|
throw new ProjectEvidenceError("PROJECT_MAP_PROTOCOL_INVALID", false);
|
|
18289
|
-
files[
|
|
18312
|
+
files[path20] = text;
|
|
18290
18313
|
}
|
|
18291
18314
|
const input = {
|
|
18292
18315
|
contextRef: digestValue({
|
|
@@ -18320,8 +18343,8 @@ var GoMapAnalyzer = class {
|
|
|
18320
18343
|
if (!existsSync4(this.resources.compilerPath))
|
|
18321
18344
|
return { pages: references.map(() => null), requiredFiles: [] };
|
|
18322
18345
|
const files = /* @__PURE__ */ Object.create(null);
|
|
18323
|
-
for (const [
|
|
18324
|
-
if (this.claims(
|
|
18346
|
+
for (const [path20, value] of Object.entries(input.files))
|
|
18347
|
+
if (this.claims(path20) || this.reads(path20)) files[path20] = value;
|
|
18325
18348
|
const facts = await this.operation(
|
|
18326
18349
|
{
|
|
18327
18350
|
...input,
|
|
@@ -18350,14 +18373,14 @@ var BUILD_FILES = [
|
|
|
18350
18373
|
"pom.xml"
|
|
18351
18374
|
];
|
|
18352
18375
|
var buildFile = /(?:^|\/)(?:pom\.xml|(?:build|settings)\.gradle(?:\.kts)?)$/u;
|
|
18353
|
-
var directoryOf = (
|
|
18354
|
-
var nameOf = (
|
|
18376
|
+
var directoryOf = (path20) => path20.slice(0, path20.lastIndexOf("/") + 1);
|
|
18377
|
+
var nameOf = (path20) => path20.slice(path20.lastIndexOf("/") + 1);
|
|
18355
18378
|
var DEFAULT_RELEASE = 21;
|
|
18356
18379
|
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;
|
|
18357
18380
|
var JAVA_MAP_LANGUAGE = Object.freeze({
|
|
18358
18381
|
id: "javac-lombok-1.18.48-map-v10",
|
|
18359
|
-
claims: (
|
|
18360
|
-
reads: (
|
|
18382
|
+
claims: (path20) => path20.endsWith(".java"),
|
|
18383
|
+
reads: (path20) => buildFile.test(path20),
|
|
18361
18384
|
// A package of the Java platform, or a library named by its first two package segments.
|
|
18362
18385
|
importName: (specifier) => platformPackage.test(specifier) ? "Java standard library" : specifier.split(".").slice(0, 2).join("."),
|
|
18363
18386
|
create: () => new JavaMapAnalyzer()
|
|
@@ -18447,8 +18470,8 @@ var JavaMapAnalyzer = class _JavaMapAnalyzer {
|
|
|
18447
18470
|
// The worker's request for a context: the Java sources and the release.
|
|
18448
18471
|
request(input, buildTexts) {
|
|
18449
18472
|
const files = /* @__PURE__ */ Object.create(null);
|
|
18450
|
-
for (const [
|
|
18451
|
-
if (this.claims(
|
|
18473
|
+
for (const [path20, text] of Object.entries(input.files))
|
|
18474
|
+
if (this.claims(path20)) files[path20] = text;
|
|
18452
18475
|
return {
|
|
18453
18476
|
files,
|
|
18454
18477
|
release: javaRelease(buildTexts, this.resources.runtimeVersion)
|
|
@@ -18463,35 +18486,35 @@ var JavaMapAnalyzer = class _JavaMapAnalyzer {
|
|
|
18463
18486
|
}
|
|
18464
18487
|
async analyze(session, signal) {
|
|
18465
18488
|
this.refreshRuntime();
|
|
18466
|
-
const builds = session.readable.map((entry) => entry.path).filter((
|
|
18467
|
-
for (const
|
|
18468
|
-
const rank2 = (
|
|
18489
|
+
const builds = session.readable.map((entry) => entry.path).filter((path20) => buildFile.test(path20));
|
|
18490
|
+
for (const path20 of builds) session.configuration(path20);
|
|
18491
|
+
const rank2 = (path20) => BUILD_FILES.indexOf(nameOf(path20));
|
|
18469
18492
|
const roots = /* @__PURE__ */ new Map();
|
|
18470
18493
|
const modules = /* @__PURE__ */ new Map();
|
|
18471
|
-
for (const
|
|
18472
|
-
const directory = directoryOf(
|
|
18494
|
+
for (const path20 of builds) {
|
|
18495
|
+
const directory = directoryOf(path20);
|
|
18473
18496
|
const current = modules.get(directory);
|
|
18474
|
-
if (current === void 0 || rank2(
|
|
18475
|
-
const text = session.texts[
|
|
18476
|
-
if (/settings\.gradle(?:\.kts)?$/u.test(
|
|
18497
|
+
if (current === void 0 || rank2(path20) < rank2(current)) modules.set(directory, path20);
|
|
18498
|
+
const text = session.texts[path20] ?? "";
|
|
18499
|
+
if (/settings\.gradle(?:\.kts)?$/u.test(path20) || path20.endsWith("pom.xml") && /<modules>/u.test(text)) {
|
|
18477
18500
|
const root = roots.get(directory);
|
|
18478
|
-
if (root === void 0 || rank2(
|
|
18501
|
+
if (root === void 0 || rank2(path20) < rank2(root)) roots.set(directory, path20);
|
|
18479
18502
|
}
|
|
18480
18503
|
}
|
|
18481
|
-
const configOf = (
|
|
18504
|
+
const configOf = (path20) => {
|
|
18482
18505
|
let outer;
|
|
18483
18506
|
for (const directory of roots.keys())
|
|
18484
|
-
if (
|
|
18507
|
+
if (path20.startsWith(directory) && (outer === void 0 || directory.length < outer.length))
|
|
18485
18508
|
outer = directory;
|
|
18486
18509
|
if (outer !== void 0) return roots.get(outer);
|
|
18487
18510
|
let nearest;
|
|
18488
18511
|
for (const directory of modules.keys())
|
|
18489
|
-
if (
|
|
18512
|
+
if (path20.startsWith(directory) && (nearest === void 0 || directory.length > nearest.length))
|
|
18490
18513
|
nearest = directory;
|
|
18491
18514
|
return nearest === void 0 ? "" : modules.get(nearest);
|
|
18492
18515
|
};
|
|
18493
|
-
const output = (
|
|
18494
|
-
(directory) =>
|
|
18516
|
+
const output = (path20) => [...modules.keys()].some(
|
|
18517
|
+
(directory) => path20.startsWith(`${directory}build/`) || path20.startsWith(`${directory}target/`)
|
|
18495
18518
|
);
|
|
18496
18519
|
const groups = /* @__PURE__ */ new Map();
|
|
18497
18520
|
for (const entry of session.readable) {
|
|
@@ -18506,13 +18529,13 @@ var JavaMapAnalyzer = class _JavaMapAnalyzer {
|
|
|
18506
18529
|
if (signal.aborted) throw new ProjectEvidenceError("PROJECT_READ_CANCELLED", true);
|
|
18507
18530
|
const files = /* @__PURE__ */ Object.create(null);
|
|
18508
18531
|
const rootBuilds = configPath ? BUILD_FILES.map((name) => `${directoryOf(configPath)}${name}`).filter(
|
|
18509
|
-
(
|
|
18532
|
+
(path20) => builds.includes(path20)
|
|
18510
18533
|
) : [];
|
|
18511
|
-
for (const
|
|
18512
|
-
const text = session.texts[
|
|
18534
|
+
for (const path20 of [...groups.get(configPath) ?? [], ...rootBuilds]) {
|
|
18535
|
+
const text = session.texts[path20];
|
|
18513
18536
|
if (text === void 0)
|
|
18514
18537
|
throw new ProjectEvidenceError("PROJECT_MAP_PROTOCOL_INVALID", false);
|
|
18515
|
-
files[
|
|
18538
|
+
files[path20] = text;
|
|
18516
18539
|
}
|
|
18517
18540
|
const input = {
|
|
18518
18541
|
contextRef: digestValue({
|
|
@@ -18554,7 +18577,7 @@ var JavaMapAnalyzer = class _JavaMapAnalyzer {
|
|
|
18554
18577
|
const prior = JavaStateSchema.safeParse(previous?.state).data;
|
|
18555
18578
|
const incremental = previous && prior?.basis === basis ? {
|
|
18556
18579
|
changed: Object.keys(request.files).filter(
|
|
18557
|
-
(
|
|
18580
|
+
(path20) => digests.get(path20) !== previous.digests.get(path20)
|
|
18558
18581
|
),
|
|
18559
18582
|
state: prior.java
|
|
18560
18583
|
} : void 0;
|
|
@@ -18583,14 +18606,14 @@ var JavaMapAnalyzer = class _JavaMapAnalyzer {
|
|
|
18583
18606
|
continue;
|
|
18584
18607
|
}
|
|
18585
18608
|
const focus = new Set(facts.focus);
|
|
18586
|
-
if (!incremental || facts.focus.some((
|
|
18609
|
+
if (!incremental || facts.focus.some((path20) => !Object.hasOwn(request.files, path20)) || incremental.changed.some((path20) => !focus.has(path20)))
|
|
18587
18610
|
throw new ProjectEvidenceError("PROJECT_MAP_PROTOCOL_INVALID", false);
|
|
18588
18611
|
analysis.objects = analysis.objects.filter((object2) => focus.has(object2.anchor.path));
|
|
18589
18612
|
analysis.relations = analysis.relations.filter((relation) => focus.has(relation.anchor.path));
|
|
18590
18613
|
analysis.notes = analysis.notes.filter((note) => focus.has(note.anchor.path));
|
|
18591
18614
|
session.accept(analysis, {
|
|
18592
18615
|
state,
|
|
18593
|
-
linked: analysis.parsedFiles.filter((
|
|
18616
|
+
linked: analysis.parsedFiles.filter((path20) => !focus.has(path20))
|
|
18594
18617
|
});
|
|
18595
18618
|
}
|
|
18596
18619
|
}
|
|
@@ -18905,12 +18928,12 @@ var PYTHON_STANDARD_LIBRARY = /* @__PURE__ */ new Set([
|
|
|
18905
18928
|
// src/project-map-language-python.ts
|
|
18906
18929
|
var CONFIGURATION = ["pyrightconfig.json", "pyproject.toml", "setup.cfg"];
|
|
18907
18930
|
var pythonConfig = /(?:^|\/)(?:pyrightconfig\.json|pyproject\.toml|setup\.cfg)$/u;
|
|
18908
|
-
var directoryOf2 = (
|
|
18931
|
+
var directoryOf2 = (path20) => path20.slice(0, path20.lastIndexOf("/") + 1);
|
|
18909
18932
|
var DEFAULT_PYTHON = { major: 3, minor: 13 };
|
|
18910
18933
|
var PYTHON_MAP_LANGUAGE = Object.freeze({
|
|
18911
18934
|
id: "pyright-1.1.414-map-v14",
|
|
18912
|
-
claims: (
|
|
18913
|
-
reads: (
|
|
18935
|
+
claims: (path20) => /\.pyi?$/u.test(path20),
|
|
18936
|
+
reads: (path20) => pythonConfig.test(path20),
|
|
18914
18937
|
// An absolute import names the standard library or a distribution's top-level package.
|
|
18915
18938
|
importName: (specifier) => {
|
|
18916
18939
|
const top = specifier.split(".", 1)[0] ?? specifier;
|
|
@@ -18966,16 +18989,16 @@ var PythonMapAnalyzer = class {
|
|
|
18966
18989
|
}
|
|
18967
18990
|
async analyze(session, signal) {
|
|
18968
18991
|
const roots = /* @__PURE__ */ new Map();
|
|
18969
|
-
for (const
|
|
18970
|
-
const directory = directoryOf2(
|
|
18992
|
+
for (const path20 of session.readable.map((entry) => entry.path).filter((path21) => pythonConfig.test(path21))) {
|
|
18993
|
+
const directory = directoryOf2(path20);
|
|
18971
18994
|
const current = roots.get(directory);
|
|
18972
18995
|
const rank2 = (file2) => CONFIGURATION.indexOf(file2.slice(directory.length));
|
|
18973
|
-
if (current === void 0 || rank2(
|
|
18996
|
+
if (current === void 0 || rank2(path20) < rank2(current)) roots.set(directory, path20);
|
|
18974
18997
|
}
|
|
18975
|
-
const rootOf = (
|
|
18998
|
+
const rootOf = (path20) => {
|
|
18976
18999
|
let best;
|
|
18977
19000
|
for (const directory of roots.keys())
|
|
18978
|
-
if (
|
|
19001
|
+
if (path20.startsWith(directory) && (best === void 0 || directory.length > best.length))
|
|
18979
19002
|
best = directory;
|
|
18980
19003
|
return best === void 0 ? "" : roots.get(best);
|
|
18981
19004
|
};
|
|
@@ -18990,11 +19013,11 @@ var PythonMapAnalyzer = class {
|
|
|
18990
19013
|
for (const configPath of [...groups.keys()].sort()) {
|
|
18991
19014
|
if (signal.aborted) throw new ProjectEvidenceError("PROJECT_READ_CANCELLED", true);
|
|
18992
19015
|
const files = /* @__PURE__ */ Object.create(null);
|
|
18993
|
-
for (const
|
|
18994
|
-
const text = session.texts[
|
|
19016
|
+
for (const path20 of [...groups.get(configPath) ?? [], ...configPath ? [configPath] : []]) {
|
|
19017
|
+
const text = session.texts[path20];
|
|
18995
19018
|
if (text === void 0)
|
|
18996
19019
|
throw new ProjectEvidenceError("PROJECT_MAP_PROTOCOL_INVALID", false);
|
|
18997
|
-
files[
|
|
19020
|
+
files[path20] = text;
|
|
18998
19021
|
}
|
|
18999
19022
|
const input = {
|
|
19000
19023
|
contextRef: digestValue({
|
|
@@ -19040,8 +19063,8 @@ var PythonMapAnalyzer = class {
|
|
|
19040
19063
|
}
|
|
19041
19064
|
async references(input, references, signal, observe) {
|
|
19042
19065
|
const files = /* @__PURE__ */ Object.create(null);
|
|
19043
|
-
for (const [
|
|
19044
|
-
if (this.claims(
|
|
19066
|
+
for (const [path20, value] of Object.entries(input.files))
|
|
19067
|
+
if (this.claims(path20) || pythonConfig.test(path20)) files[path20] = value;
|
|
19045
19068
|
const facts = await this.operation(
|
|
19046
19069
|
{
|
|
19047
19070
|
...input,
|
|
@@ -19065,7 +19088,7 @@ var PythonMapAnalyzer = class {
|
|
|
19065
19088
|
import { availableParallelism } from "node:os";
|
|
19066
19089
|
|
|
19067
19090
|
// src/project-map-miniprogram.ts
|
|
19068
|
-
import
|
|
19091
|
+
import path10 from "node:path";
|
|
19069
19092
|
import {
|
|
19070
19093
|
isCallExpression,
|
|
19071
19094
|
isExpressionStatement,
|
|
@@ -19083,9 +19106,9 @@ var miniprogramTemplateOf = (script, inventory) => /\.[cm]?[jt]sx?$/u.test(scrip
|
|
|
19083
19106
|
function miniprogramConfiguration(template, inventory) {
|
|
19084
19107
|
const own = template.replace(/\.wxml$/u, ".json");
|
|
19085
19108
|
const configuration = inventory.has(own) ? { own } : {};
|
|
19086
|
-
for (let directory =
|
|
19109
|
+
for (let directory = path10.posix.dirname(template); ; directory = path10.posix.dirname(directory)) {
|
|
19087
19110
|
const root = directory === "." ? "" : directory;
|
|
19088
|
-
const app =
|
|
19111
|
+
const app = path10.posix.join(root, "app.json");
|
|
19089
19112
|
if (inventory.has(app)) return { ...configuration, app, root };
|
|
19090
19113
|
if (!root) return configuration;
|
|
19091
19114
|
}
|
|
@@ -19098,9 +19121,9 @@ var miniprogramEventOf = (target) => {
|
|
|
19098
19121
|
// src/project-map-language-typescript.ts
|
|
19099
19122
|
var TYPESCRIPT_MAP_LANGUAGE = Object.freeze({
|
|
19100
19123
|
id: "typescript-7.0.2-map-v34",
|
|
19101
|
-
claims: (
|
|
19124
|
+
claims: (path20) => /\.[cm]?[jt]sx?$/u.test(path20),
|
|
19102
19125
|
readsRequests: true,
|
|
19103
|
-
reads: (
|
|
19126
|
+
reads: (path20) => path20.endsWith(".json") || path20.endsWith(".wxml") || path20 === "pnpm-workspace.yaml",
|
|
19104
19127
|
create: () => new TypeScriptMapAnalyzer()
|
|
19105
19128
|
});
|
|
19106
19129
|
var CONFIGURATIONS_KEPT = 4;
|
|
@@ -19122,7 +19145,7 @@ function limit(atOnce) {
|
|
|
19122
19145
|
}
|
|
19123
19146
|
var MODULE_NAMES = /\b(?:from|import|require)\s*\(?\s*(["'`])([^"'`\n]+)\1|\/\/\/\s*<reference\s+(?:path|types|lib)\s*=\s*(["'])([^"'\n]+)\3/gu;
|
|
19124
19147
|
var moduleNames = (text) => digestValue([...text.matchAll(MODULE_NAMES)].map((match) => match[2] ?? match[4] ?? ""));
|
|
19125
|
-
var sameShape = (left, right) => left.installed === right.installed && left.files.size === right.files.size && [...left.files].every(([
|
|
19148
|
+
var sameShape = (left, right) => left.installed === right.installed && left.files.size === right.files.size && [...left.files].every(([path20, { shape }]) => right.files.get(path20)?.shape === shape);
|
|
19126
19149
|
var stopUnconfirmed = async (runs) => (await Promise.allSettled(runs)).flatMap((settled) => settled.status === "rejected" ? [settled.reason] : []).find((reason) => reason instanceof ProjectMapStopUnconfirmedError);
|
|
19127
19150
|
async function inOrder(tasks, take, signal, sizes) {
|
|
19128
19151
|
const stopping = new AbortController();
|
|
@@ -19291,9 +19314,9 @@ var TypeScriptMapAnalyzer = class {
|
|
|
19291
19314
|
first = void 0;
|
|
19292
19315
|
validateMapAnalysis(analysis, input);
|
|
19293
19316
|
if (!analysis.requiredFiles.length) return analysis;
|
|
19294
|
-
const required2 = analysis.requiredFiles.map((
|
|
19295
|
-
const entry = byPath.get(
|
|
19296
|
-
if (!entry || Object.hasOwn(texts,
|
|
19317
|
+
const required2 = analysis.requiredFiles.map((path20) => {
|
|
19318
|
+
const entry = byPath.get(path20);
|
|
19319
|
+
if (!entry || Object.hasOwn(texts, path20))
|
|
19297
19320
|
throw new ProjectEvidenceError("PROJECT_MAP_PROTOCOL_INVALID", false);
|
|
19298
19321
|
return entry;
|
|
19299
19322
|
});
|
|
@@ -19413,17 +19436,17 @@ var MAP_LANGUAGES = Object.freeze([
|
|
|
19413
19436
|
]);
|
|
19414
19437
|
var mapAnalyzerSuite = (languages) => languages.map((language) => language.id).sort().join("+");
|
|
19415
19438
|
var PROJECT_MAP_ANALYZER = mapAnalyzerSuite(MAP_LANGUAGES);
|
|
19416
|
-
var mapCodePath = (
|
|
19417
|
-
var languageOf = (
|
|
19418
|
-
var mapReadsRequests = (
|
|
19419
|
-
var mapLanguageOf = (
|
|
19439
|
+
var mapCodePath = (path20) => MAP_LANGUAGES.some((language) => language.claims(path20));
|
|
19440
|
+
var languageOf = (path20) => MAP_LANGUAGES.find((language) => language.claims(path20));
|
|
19441
|
+
var mapReadsRequests = (path20) => languageOf(path20)?.readsRequests === true;
|
|
19442
|
+
var mapLanguageOf = (path20) => languageOf(path20)?.id;
|
|
19420
19443
|
var npmPackage = (specifier) => {
|
|
19421
19444
|
if (specifier.startsWith("node:")) return "node:*";
|
|
19422
19445
|
const parts = specifier.split("/");
|
|
19423
19446
|
return specifier.startsWith("@") ? parts.slice(0, 2).join("/") : parts[0] ?? specifier;
|
|
19424
19447
|
};
|
|
19425
19448
|
var mapExternalImport = (sourcePath, specifier) => languageOf(sourcePath)?.importName?.(specifier) ?? npmPackage(specifier);
|
|
19426
|
-
var mapImportTarget = (
|
|
19449
|
+
var mapImportTarget = (path20) => languageOf(path20)?.importTarget?.(path20) ?? path20;
|
|
19427
19450
|
|
|
19428
19451
|
// src/project-map-view.ts
|
|
19429
19452
|
var MAP_VIEW_FORMAT = "PROJECT_MAP_VIEW_V1";
|
|
@@ -19463,10 +19486,10 @@ var notFound = () => {
|
|
|
19463
19486
|
};
|
|
19464
19487
|
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";
|
|
19465
19488
|
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.`;
|
|
19466
|
-
var within = (
|
|
19467
|
-
var parentDirectory = (
|
|
19468
|
-
const slash =
|
|
19469
|
-
return slash < 0 ? "." :
|
|
19489
|
+
var within = (path20, directory) => directory === "." || path20.startsWith(`${directory}/`);
|
|
19490
|
+
var parentDirectory = (path20) => {
|
|
19491
|
+
const slash = path20.lastIndexOf("/");
|
|
19492
|
+
return slash < 0 ? "." : path20.slice(0, slash);
|
|
19470
19493
|
};
|
|
19471
19494
|
var compareText2 = (left, right) => left < right ? -1 : left > right ? 1 : 0;
|
|
19472
19495
|
var byCount = ([leftName, left], [rightName, right]) => right - left || compareText2(leftName, rightName);
|
|
@@ -19540,7 +19563,7 @@ function pageBlocks(view, head, whole, offset, budget) {
|
|
|
19540
19563
|
if (offset === blocks.length) return materialize(0);
|
|
19541
19564
|
return mapQueryPage(blocks.length - offset, materialize, (page) => page, budget);
|
|
19542
19565
|
}
|
|
19543
|
-
var inModule = (
|
|
19566
|
+
var inModule = (path20, module) => module.direct ? parentDirectory(path20) === module.directory : within(path20, module.directory);
|
|
19544
19567
|
var moduleLabel = (module) => module.direct ? `${module.directory === "." ? "" : `${module.directory}/`}* (files directly here)` : `${module.directory}/`;
|
|
19545
19568
|
function childModules(module, files) {
|
|
19546
19569
|
if (module.direct) return [];
|
|
@@ -19595,9 +19618,9 @@ function mapProjectModules(entries) {
|
|
|
19595
19618
|
(entry) => entry.state === "TEXT" && mapCodePath(entry.path) && !mapTestPath(entry.path)
|
|
19596
19619
|
).map((entry) => entry.path)
|
|
19597
19620
|
);
|
|
19598
|
-
return (
|
|
19599
|
-
if (mapTestPath(
|
|
19600
|
-
const module = modules.find((candidate) => inModule(
|
|
19621
|
+
return (path20) => {
|
|
19622
|
+
if (mapTestPath(path20)) return void 0;
|
|
19623
|
+
const module = modules.find((candidate) => inModule(path20, candidate));
|
|
19601
19624
|
return module && moduleLabel(module);
|
|
19602
19625
|
};
|
|
19603
19626
|
}
|
|
@@ -19695,12 +19718,12 @@ function loadMemberCalls(store, version2) {
|
|
|
19695
19718
|
FROM project_map_relations
|
|
19696
19719
|
WHERE version_ref = ? AND to_ref IS NULL AND json_extract(relation_json, '$.kind') = 'CALLS'
|
|
19697
19720
|
AND json_extract(relation_json, '$.unresolvedReason') IN ('SYMBOL_NOT_RESOLVED', 'SYNTAX_ONLY')`).all(version2)) {
|
|
19698
|
-
const
|
|
19721
|
+
const path20 = String(row.path);
|
|
19699
19722
|
const target = String(row.target);
|
|
19700
19723
|
const name = MEMBER_NAME.exec(target)?.[1];
|
|
19701
|
-
const language = mapLanguageOf(
|
|
19724
|
+
const language = mapLanguageOf(path20);
|
|
19702
19725
|
if (!name || !language) continue;
|
|
19703
|
-
const call = { from: String(row.from_ref), path:
|
|
19726
|
+
const call = { from: String(row.from_ref), path: path20, line: Number(row.line), target };
|
|
19704
19727
|
const key = memberKey(language, name);
|
|
19705
19728
|
const known = calls.get(key);
|
|
19706
19729
|
if (known) known.push(call);
|
|
@@ -19761,10 +19784,10 @@ function loadCoverageNotes(store, version2) {
|
|
|
19761
19784
|
if (!codes.includes(gap.code)) codes.push(gap.code);
|
|
19762
19785
|
files.set(gap.path, codes);
|
|
19763
19786
|
}
|
|
19764
|
-
for (const [
|
|
19787
|
+
for (const [path20, codes] of files)
|
|
19765
19788
|
if (codes.length > 1 && codes.includes("NOT_IN_PARSED_CONTEXT"))
|
|
19766
19789
|
files.set(
|
|
19767
|
-
|
|
19790
|
+
path20,
|
|
19768
19791
|
codes.filter((code) => code !== "NOT_IN_PARSED_CONTEXT")
|
|
19769
19792
|
);
|
|
19770
19793
|
const missing = [...notInstalled].sort();
|
|
@@ -19809,9 +19832,9 @@ function directoryView(facts, imports, coverage, entries, input, directory, pref
|
|
|
19809
19832
|
const visiblePaths = new Set(visible.map((entry) => entry.path));
|
|
19810
19833
|
const code = visible.filter((entry) => entry.state === "TEXT" && mapCodePath(entry.path)).map((entry) => entry.path);
|
|
19811
19834
|
const modules = mapModules(directory, code);
|
|
19812
|
-
const moduleOf = (
|
|
19813
|
-
const outside = (
|
|
19814
|
-
const parts =
|
|
19835
|
+
const moduleOf = (path20) => modules.find((module) => inModule(path20, module));
|
|
19836
|
+
const outside = (path20) => {
|
|
19837
|
+
const parts = path20.split("/");
|
|
19815
19838
|
return `${parts.slice(0, Math.min(2, parts.length - 1)).join("/") || "."}/ (outside)`;
|
|
19816
19839
|
};
|
|
19817
19840
|
const moduleImports = /* @__PURE__ */ new Map();
|
|
@@ -19835,8 +19858,8 @@ function directoryView(facts, imports, coverage, entries, input, directory, pref
|
|
|
19835
19858
|
const blocks = [];
|
|
19836
19859
|
if (modules.length > 1) {
|
|
19837
19860
|
const sizes = /* @__PURE__ */ new Map();
|
|
19838
|
-
for (const
|
|
19839
|
-
const module = moduleOf(
|
|
19861
|
+
for (const path20 of code) {
|
|
19862
|
+
const module = moduleOf(path20);
|
|
19840
19863
|
if (module) increment(sizes, moduleLabel(module));
|
|
19841
19864
|
}
|
|
19842
19865
|
blocks.push(
|
|
@@ -19865,18 +19888,18 @@ function directoryView(facts, imports, coverage, entries, input, directory, pref
|
|
|
19865
19888
|
)}${packages.length > shown.length ? `, +${packages.length - shown.length} more` : ""}`
|
|
19866
19889
|
);
|
|
19867
19890
|
}
|
|
19868
|
-
const lineCount = (
|
|
19869
|
-
const file2 = facts.files.get(
|
|
19870
|
-
const gaps = coverage.files.get(
|
|
19891
|
+
const lineCount = (path20) => {
|
|
19892
|
+
const file2 = facts.files.get(path20);
|
|
19893
|
+
const gaps = coverage.files.get(path20) ?? [];
|
|
19871
19894
|
if (file2?.parsed === false) return `[not parsed${gaps.length ? `: ${gaps.join("; ")}` : ""}]`;
|
|
19872
19895
|
return `${file2 ? `${file2.lines}L` : "?L"}${gaps.length ? ` [${gaps.join("; ")}]` : ""}`;
|
|
19873
19896
|
};
|
|
19874
19897
|
const codeDirectories = /* @__PURE__ */ new Set();
|
|
19875
|
-
for (const
|
|
19876
|
-
for (let parent = parentDirectory(
|
|
19898
|
+
for (const path20 of code)
|
|
19899
|
+
for (let parent = parentDirectory(path20); parent !== "." && !codeDirectories.has(parent); parent = parentDirectory(parent))
|
|
19877
19900
|
codeDirectories.add(parent);
|
|
19878
|
-
const groupOf = (
|
|
19879
|
-
let group = parentDirectory(
|
|
19901
|
+
const groupOf = (path20) => {
|
|
19902
|
+
let group = parentDirectory(path20);
|
|
19880
19903
|
for (let parent = group; parent !== "." && parent !== directory && !codeDirectories.has(parent); parent = parentDirectory(parent))
|
|
19881
19904
|
group = parent;
|
|
19882
19905
|
return group;
|
|
@@ -19908,11 +19931,11 @@ function directoryView(facts, imports, coverage, entries, input, directory, pref
|
|
|
19908
19931
|
]);
|
|
19909
19932
|
}
|
|
19910
19933
|
const detailed = [
|
|
19911
|
-
...code.map((
|
|
19912
|
-
const declarations2 = (facts.exported.get(
|
|
19934
|
+
...code.map((path20) => {
|
|
19935
|
+
const declarations2 = (facts.exported.get(path20) ?? []).map(({ text: text2 }) => text2);
|
|
19913
19936
|
return [
|
|
19914
|
-
|
|
19915
|
-
`${
|
|
19937
|
+
path20,
|
|
19938
|
+
`${path20} ${lineCount(path20)}${declarations2.length ? `: ${declarations2.join(", ")}` : ""}`
|
|
19916
19939
|
];
|
|
19917
19940
|
}),
|
|
19918
19941
|
...listedOther.map((entry) => [
|
|
@@ -19923,7 +19946,7 @@ function directoryView(facts, imports, coverage, entries, input, directory, pref
|
|
|
19923
19946
|
];
|
|
19924
19947
|
const directories = /* @__PURE__ */ new Map();
|
|
19925
19948
|
for (const entry of [
|
|
19926
|
-
...code.map((
|
|
19949
|
+
...code.map((path20) => ({ path: path20, item: lineCount(path20) })),
|
|
19927
19950
|
...listedOther.map((entry2) => ({
|
|
19928
19951
|
path: entry2.path,
|
|
19929
19952
|
item: entry2.state === "TEXT" ? "" : `(${entry2.state})`
|
|
@@ -19951,10 +19974,10 @@ function directoryView(facts, imports, coverage, entries, input, directory, pref
|
|
|
19951
19974
|
);
|
|
19952
19975
|
const text = visible.filter((entry) => entry.state === "TEXT").length;
|
|
19953
19976
|
const resolution = /* @__PURE__ */ new Map();
|
|
19954
|
-
for (const
|
|
19955
|
-
const counts = facts.calls.get(
|
|
19977
|
+
for (const path20 of code) {
|
|
19978
|
+
const counts = facts.calls.get(path20);
|
|
19956
19979
|
if (!counts) continue;
|
|
19957
|
-
const language = facts.files.get(
|
|
19980
|
+
const language = facts.files.get(path20)?.language ?? "unknown";
|
|
19958
19981
|
const total = resolution.get(language) ?? { resolved: 0, unresolved: 0, external: 0 };
|
|
19959
19982
|
total.resolved += counts.resolved;
|
|
19960
19983
|
total.unresolved += counts.unresolved;
|
|
@@ -20011,8 +20034,8 @@ var DeclarationGroups = class {
|
|
|
20011
20034
|
prefixes;
|
|
20012
20035
|
showTests;
|
|
20013
20036
|
memberCalls;
|
|
20014
|
-
visible(
|
|
20015
|
-
return mapPathAllowed(
|
|
20037
|
+
visible(path20) {
|
|
20038
|
+
return mapPathAllowed(path20, this.prefixes) && (this.showTests || !mapTestPath(path20));
|
|
20016
20039
|
}
|
|
20017
20040
|
entry(object2, imported = false) {
|
|
20018
20041
|
if (mapMiniprogramTemplate(object2.anchor.path)) return "(template)";
|
|
@@ -20057,11 +20080,11 @@ var DeclarationGroups = class {
|
|
|
20057
20080
|
value.lines.push(line);
|
|
20058
20081
|
aggregates.set(key, value);
|
|
20059
20082
|
};
|
|
20060
|
-
const dispatch = (arrow, label, ref2,
|
|
20083
|
+
const dispatch = (arrow, label, ref2, path20, line) => {
|
|
20061
20084
|
const other = graph.object(graph.owner(ref2));
|
|
20062
20085
|
if (owned.has(other.id)) return;
|
|
20063
|
-
if (!this.visible(
|
|
20064
|
-
if (mapPathAllowed(
|
|
20086
|
+
if (!this.visible(path20)) {
|
|
20087
|
+
if (mapPathAllowed(path20, this.prefixes)) omittedTests++;
|
|
20065
20088
|
return;
|
|
20066
20089
|
}
|
|
20067
20090
|
add(arrow, label, other, line);
|
|
@@ -20218,7 +20241,7 @@ var DeclarationGroups = class {
|
|
|
20218
20241
|
else files2.set(call.path, [item]);
|
|
20219
20242
|
}
|
|
20220
20243
|
lines.push(
|
|
20221
|
-
` \u2190 possible callers by name: ${[...files2].map(([
|
|
20244
|
+
` \u2190 possible callers by name: ${[...files2].map(([path20, items]) => `${path20}: ${items.join(", ")}`).join("; ")}${inTests}`
|
|
20222
20245
|
);
|
|
20223
20246
|
} else if (possibleInTests)
|
|
20224
20247
|
lines.push(` \u2190 possible callers by name: ${possibleInTests} in test files (includeTests)`);
|
|
@@ -20254,14 +20277,14 @@ var DeclarationGroups = class {
|
|
|
20254
20277
|
return { lines, neighbors: [...new Set(neighbors)] };
|
|
20255
20278
|
}
|
|
20256
20279
|
};
|
|
20257
|
-
function fileView(store, coverage, graph, input,
|
|
20258
|
-
const entry = store.getEntry(input.version,
|
|
20259
|
-
if (!entry || !mapPathAllowed(
|
|
20260
|
-
const showTests = input.includeTests === true || mapTestPath(
|
|
20261
|
-
const module = mapCodePath(
|
|
20262
|
-
const gaps = coverage.files.get(
|
|
20280
|
+
function fileView(store, coverage, graph, input, path20, prefixes) {
|
|
20281
|
+
const entry = store.getEntry(input.version, path20);
|
|
20282
|
+
if (!entry || !mapPathAllowed(path20, prefixes)) return notFound();
|
|
20283
|
+
const showTests = input.includeTests === true || mapTestPath(path20);
|
|
20284
|
+
const module = mapCodePath(path20) ? graph.objectsAt(path20).find((object2) => mapIsModule(object2)) : mapMiniprogramTemplate(path20) ? graph.objectsAt(path20).find((object2) => mapIsModule(object2) && object2.parsing === "PARSED") : void 0;
|
|
20285
|
+
const gaps = coverage.files.get(path20) ?? [];
|
|
20263
20286
|
const head = [
|
|
20264
|
-
`PROJECT MAP \xB7 FILE ${
|
|
20287
|
+
`PROJECT MAP \xB7 FILE ${path20} \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`}`
|
|
20265
20288
|
];
|
|
20266
20289
|
if (!module || entry.state !== "TEXT")
|
|
20267
20290
|
return pageBlocks("FILE", head, [], input.offset ?? 0, input.outputBudget);
|
|
@@ -20281,7 +20304,7 @@ function fileView(store, coverage, graph, input, path19, prefixes) {
|
|
|
20281
20304
|
tags.set(relation.from, list);
|
|
20282
20305
|
}
|
|
20283
20306
|
const describe3 = (object2) => [
|
|
20284
|
-
`${object2.name} ${mapDeclarationLabel(object2)}${object2.anchor.path ===
|
|
20307
|
+
`${object2.name} ${mapDeclarationLabel(object2)}${object2.anchor.path === path20 ? "" : ` (${object2.anchor.path})`}`,
|
|
20285
20308
|
...tags.get(object2.id) ?? []
|
|
20286
20309
|
].join(" ");
|
|
20287
20310
|
const declarations2 = [];
|
|
@@ -20296,11 +20319,11 @@ function fileView(store, coverage, graph, input, path19, prefixes) {
|
|
|
20296
20319
|
);
|
|
20297
20320
|
}
|
|
20298
20321
|
const elsewhere = /* @__PURE__ */ new Map();
|
|
20299
|
-
for (const object2 of graph.objectsAt(
|
|
20322
|
+
for (const object2 of graph.objectsAt(path20)) {
|
|
20300
20323
|
const parent = mapIsModule(object2) ? void 0 : graph.parent(object2.id);
|
|
20301
20324
|
if (parent === void 0 || !graph.isAddressable(object2)) continue;
|
|
20302
20325
|
const container = graph.object(parent);
|
|
20303
|
-
if (mapIsModule(container) || container.anchor.path ===
|
|
20326
|
+
if (mapIsModule(container) || container.anchor.path === path20) continue;
|
|
20304
20327
|
const into = elsewhere.get(parent);
|
|
20305
20328
|
if (into) into.push(object2);
|
|
20306
20329
|
else elsewhere.set(parent, [object2]);
|
|
@@ -20314,7 +20337,7 @@ function fileView(store, coverage, graph, input, path19, prefixes) {
|
|
|
20314
20337
|
if (declarations2.length) blocks.push(["DECLARATIONS (* exported)", ...declarations2].join("\n"));
|
|
20315
20338
|
const imports = /* @__PURE__ */ new Set();
|
|
20316
20339
|
const external = /* @__PURE__ */ new Set();
|
|
20317
|
-
const fileObjects = graph.objectsAt(
|
|
20340
|
+
const fileObjects = graph.objectsAt(path20).map((object2) => object2.id);
|
|
20318
20341
|
for (const relation of graph.relationsFrom(fileObjects)) {
|
|
20319
20342
|
if (relation.kind !== "IMPORTS") continue;
|
|
20320
20343
|
if (relation.to === void 0) external.add(relation.target);
|
|
@@ -20325,8 +20348,8 @@ function fileView(store, coverage, graph, input, path19, prefixes) {
|
|
|
20325
20348
|
}
|
|
20326
20349
|
const importers = /* @__PURE__ */ new Set();
|
|
20327
20350
|
const testImporters = /* @__PURE__ */ new Set();
|
|
20328
|
-
const imported = mapImportTarget(
|
|
20329
|
-
const packageModules = imported ===
|
|
20351
|
+
const imported = mapImportTarget(path20);
|
|
20352
|
+
const packageModules = imported === path20 ? [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);
|
|
20330
20353
|
for (const relation of graph.relationsTo(packageModules)) {
|
|
20331
20354
|
if (relation.kind !== "IMPORTS") continue;
|
|
20332
20355
|
const source = relation.anchor.path;
|
|
@@ -20354,16 +20377,16 @@ function fileView(store, coverage, graph, input, path19, prefixes) {
|
|
|
20354
20377
|
if (scope.length) blocks.push(["MODULE SCOPE (top-level statements)", ...scope].join("\n"));
|
|
20355
20378
|
return pageBlocks("FILE", head, blocks, input.offset ?? 0, input.outputBudget);
|
|
20356
20379
|
}
|
|
20357
|
-
function declarationView(graph, input,
|
|
20380
|
+
function declarationView(graph, input, path20, prefixes, memberCalls) {
|
|
20358
20381
|
const requested = input.depth ?? 1;
|
|
20359
20382
|
if (!Number.isSafeInteger(requested) || requested < 1 || requested > MAP_VIEW_LIMITS.directedDepth)
|
|
20360
20383
|
return invalid2();
|
|
20361
20384
|
const both = (input.direction ?? "BOTH") === "BOTH";
|
|
20362
20385
|
const depth = both ? Math.min(requested, MAP_VIEW_LIMITS.bothDepth) : requested;
|
|
20363
20386
|
const { name, line } = input;
|
|
20364
|
-
const selected = mapSelectDeclarations(graph,
|
|
20387
|
+
const selected = mapSelectDeclarations(graph, path20, name, line);
|
|
20365
20388
|
if (!selected.length) return notFound();
|
|
20366
|
-
const showTests = input.includeTests === true || mapTestPath(
|
|
20389
|
+
const showTests = input.includeTests === true || mapTestPath(path20);
|
|
20367
20390
|
const groups = new DeclarationGroups(graph, input, prefixes, showTests, memberCalls);
|
|
20368
20391
|
const blocks = [];
|
|
20369
20392
|
const seen = /* @__PURE__ */ new Set();
|
|
@@ -20411,7 +20434,7 @@ function declarationView(graph, input, path19, prefixes, memberCalls) {
|
|
|
20411
20434
|
);
|
|
20412
20435
|
}
|
|
20413
20436
|
const head = [
|
|
20414
|
-
`PROJECT MAP \xB7 DECLARATION ${
|
|
20437
|
+
`PROJECT MAP \xB7 DECLARATION ${path20}${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"}`,
|
|
20415
20438
|
...truncated ? [`Expansion stopped at ${MAP_VIEW_LIMITS.declarations} declarations.`] : [],
|
|
20416
20439
|
...(input.direction ?? "BOTH") === "OUTGOING" ? [] : [callerCoverage(input.textSearch ?? DEFAULT_TEXT_SEARCH)]
|
|
20417
20440
|
];
|
|
@@ -20539,10 +20562,10 @@ var ProjectMapQuery = class {
|
|
|
20539
20562
|
view(input, signal) {
|
|
20540
20563
|
this.requireReadableMap(input.version, signal);
|
|
20541
20564
|
const { offset, prefixes } = admission(input);
|
|
20542
|
-
const
|
|
20565
|
+
const path20 = normalizeProjectEvidencePath(input.path, true) || ".";
|
|
20543
20566
|
const view = mapView(
|
|
20544
20567
|
this.store,
|
|
20545
|
-
{ ...input, path:
|
|
20568
|
+
{ ...input, path: path20, offset, allowedPathPrefixes: prefixes },
|
|
20546
20569
|
this.views
|
|
20547
20570
|
);
|
|
20548
20571
|
if (signal.aborted) throw new ProjectEvidenceError("PROJECT_READ_CANCELLED", true);
|
|
@@ -20743,13 +20766,13 @@ var ProjectMapSourceReader = class _ProjectMapSourceReader {
|
|
|
20743
20766
|
*/
|
|
20744
20767
|
async readAll(expected) {
|
|
20745
20768
|
if (this.signal.aborted) throw new ProjectEvidenceError("PROJECT_READ_CANCELLED", true);
|
|
20746
|
-
const paths = expected.map(({ path:
|
|
20747
|
-
assertProjectEvidencePathNotSensitive(
|
|
20748
|
-
if (isProjectEvidenceTraversalExcluded(
|
|
20769
|
+
const paths = expected.map(({ path: path20 }) => {
|
|
20770
|
+
assertProjectEvidencePathNotSensitive(path20);
|
|
20771
|
+
if (isProjectEvidenceTraversalExcluded(path20))
|
|
20749
20772
|
throw new ProjectEvidenceError("PROJECT_FILE_NOT_ALLOWED", false);
|
|
20750
|
-
return
|
|
20773
|
+
return path20;
|
|
20751
20774
|
});
|
|
20752
|
-
const results = this.commit ? await this.commit.readAll(paths) : await concurrently(paths, (
|
|
20775
|
+
const results = this.commit ? await this.commit.readAll(paths) : await concurrently(paths, (path20) => this.session.captureFile(path20));
|
|
20753
20776
|
for (const [index, { entry }] of results.entries()) {
|
|
20754
20777
|
const wanted = expected[index];
|
|
20755
20778
|
if (entry.state !== wanted?.state || entry.contentDigest !== wanted.contentDigest || entry.byteLength !== wanted.byteLength)
|
|
@@ -21472,7 +21495,7 @@ var CodeIndexStore = class {
|
|
|
21472
21495
|
const staged = this.stageUnits(buildRef, paths, linked);
|
|
21473
21496
|
const reused = linked ? this.database.prepare(`SELECT path, unit_ref FROM project_map_version_units
|
|
21474
21497
|
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) })) : [];
|
|
21475
|
-
if (reused.length !== (linked?.paths.size ?? 0) || reused.some(({ path:
|
|
21498
|
+
if (reused.length !== (linked?.paths.size ?? 0) || reused.some(({ path: path20 }) => !paths.has(path20)) || staged.some(({ path: path20 }) => linked?.paths.has(path20)))
|
|
21476
21499
|
throw new MapReplayConflict();
|
|
21477
21500
|
const units = [...staged, ...reused].sort(
|
|
21478
21501
|
(left, right) => left.path < right.path ? -1 : left.path > right.path ? 1 : 0
|
|
@@ -21523,7 +21546,7 @@ var CodeIndexStore = class {
|
|
|
21523
21546
|
const member = this.database.prepare(
|
|
21524
21547
|
"INSERT INTO project_map_version_units VALUES (?, ?, ?)"
|
|
21525
21548
|
);
|
|
21526
|
-
for (const { path:
|
|
21549
|
+
for (const { path: path20, unit } of reused) member.run(version2.version, path20, unit);
|
|
21527
21550
|
this.database.prepare("INSERT INTO project_map_coverage VALUES (?, ?)").run(version2.version, canonicalJson(coverage));
|
|
21528
21551
|
}
|
|
21529
21552
|
this.database.exec(`DELETE FROM project_map_publish_objects;
|
|
@@ -21578,7 +21601,7 @@ var CodeIndexStore = class {
|
|
|
21578
21601
|
corrupt2();
|
|
21579
21602
|
}
|
|
21580
21603
|
if (linked) {
|
|
21581
|
-
const unlinked = database.prepare("SELECT path FROM project_map_version_units WHERE version_ref = ?").all(linked.version).map((row) => String(row.path)).filter((
|
|
21604
|
+
const unlinked = database.prepare("SELECT path FROM project_map_version_units WHERE version_ref = ?").all(linked.version).map((row) => String(row.path)).filter((path20) => !linked.paths.has(path20));
|
|
21582
21605
|
if (database.prepare(`SELECT 1 FROM project_map_objects gone
|
|
21583
21606
|
WHERE gone.version_ref = ? AND gone.path IN (SELECT value FROM json_each(?))
|
|
21584
21607
|
AND gone.entity_ref NOT IN (SELECT entity_ref FROM project_map_publish_objects)
|
|
@@ -21600,17 +21623,17 @@ var CodeIndexStore = class {
|
|
|
21600
21623
|
const units = [];
|
|
21601
21624
|
for (const row of database.prepare(`SELECT path FROM project_map_publish_objects
|
|
21602
21625
|
UNION SELECT path FROM project_map_publish_relations ORDER BY path`).all()) {
|
|
21603
|
-
const
|
|
21604
|
-
const hash2 = createHash4("sha256").update(
|
|
21626
|
+
const path20 = String(row.path);
|
|
21627
|
+
const hash2 = createHash4("sha256").update(path20).update("\0");
|
|
21605
21628
|
for (const [mark, statement] of [
|
|
21606
21629
|
["object", objects2],
|
|
21607
21630
|
["relation", relations],
|
|
21608
21631
|
["note", pathNotes]
|
|
21609
21632
|
])
|
|
21610
|
-
for (const fact of statement.all(
|
|
21633
|
+
for (const fact of statement.all(path20))
|
|
21611
21634
|
for (const value of Object.values(fact))
|
|
21612
21635
|
hash2.update(mark).update("\0").update(String(value)).update("\0");
|
|
21613
|
-
units.push({ path:
|
|
21636
|
+
units.push({ path: path20, unit: hash2.digest("hex") });
|
|
21614
21637
|
}
|
|
21615
21638
|
return units;
|
|
21616
21639
|
}
|
|
@@ -21628,13 +21651,13 @@ var CodeIndexStore = class {
|
|
|
21628
21651
|
"INSERT INTO project_map_unit_notes SELECT ?, * FROM project_map_publish_notes WHERE path = ?"
|
|
21629
21652
|
);
|
|
21630
21653
|
const member = database.prepare("INSERT INTO project_map_version_units VALUES (?, ?, ?)");
|
|
21631
|
-
for (const { path:
|
|
21632
|
-
if (insertUnit.run(unit,
|
|
21633
|
-
unitObjects.run(unit,
|
|
21634
|
-
unitRelations.run(unit,
|
|
21635
|
-
unitNotes.run(unit,
|
|
21654
|
+
for (const { path: path20, unit } of units) {
|
|
21655
|
+
if (insertUnit.run(unit, path20).changes) {
|
|
21656
|
+
unitObjects.run(unit, path20);
|
|
21657
|
+
unitRelations.run(unit, path20);
|
|
21658
|
+
unitNotes.run(unit, path20);
|
|
21636
21659
|
}
|
|
21637
|
-
member.run(version2,
|
|
21660
|
+
member.run(version2, path20, unit);
|
|
21638
21661
|
}
|
|
21639
21662
|
}
|
|
21640
21663
|
/**
|
|
@@ -21896,19 +21919,19 @@ function replayableContexts(parent, digests, claims) {
|
|
|
21896
21919
|
const { analysis, paths } = parent.shell(ref);
|
|
21897
21920
|
const files = /* @__PURE__ */ new Set([...codeFiles(context, analysis.parsedFiles, claims), ...paths ?? []]);
|
|
21898
21921
|
factFiles.set(ref, files);
|
|
21899
|
-
for (const
|
|
21900
|
-
const refs = sharing.get(
|
|
21922
|
+
for (const path20 of files) {
|
|
21923
|
+
const refs = sharing.get(path20) ?? /* @__PURE__ */ new Set();
|
|
21901
21924
|
refs.add(ref);
|
|
21902
|
-
sharing.set(
|
|
21925
|
+
sharing.set(path20, refs);
|
|
21903
21926
|
}
|
|
21904
21927
|
if (!paths || !contextFiles(context).every(
|
|
21905
|
-
(
|
|
21928
|
+
(path20) => digests.get(path20) !== void 0 && digests.get(path20) === parent.entries.get(path20)
|
|
21906
21929
|
))
|
|
21907
21930
|
analyzed.add(ref);
|
|
21908
21931
|
}
|
|
21909
21932
|
for (const ref of analyzed)
|
|
21910
|
-
for (const
|
|
21911
|
-
for (const other of sharing.get(
|
|
21933
|
+
for (const path20 of factFiles.get(ref) ?? [])
|
|
21934
|
+
for (const other of sharing.get(path20) ?? []) analyzed.add(other);
|
|
21912
21935
|
const replayable = new Set([...parent.contexts.keys()].filter((ref) => !analyzed.has(ref)));
|
|
21913
21936
|
return { replayable, sharing, factFiles };
|
|
21914
21937
|
}
|
|
@@ -21940,8 +21963,8 @@ var ProjectMapAnalyzer = class {
|
|
|
21940
21963
|
languages;
|
|
21941
21964
|
observe;
|
|
21942
21965
|
id;
|
|
21943
|
-
claims(
|
|
21944
|
-
return this.languages.some((language) => language.claims(
|
|
21966
|
+
claims(path20) {
|
|
21967
|
+
return this.languages.some((language) => language.claims(path20));
|
|
21945
21968
|
}
|
|
21946
21969
|
// A context holds one language's code, so its requests are that language's.
|
|
21947
21970
|
async references(input, references, signal, until) {
|
|
@@ -21950,8 +21973,8 @@ var ProjectMapAnalyzer = class {
|
|
|
21950
21973
|
return language?.references ? language.references(input, references, signal, this.observe, until) : { pages: references.map(() => null), requiredFiles: [] };
|
|
21951
21974
|
}
|
|
21952
21975
|
// A context's compiler diagnostics, undefined for a language without a compiler to ask.
|
|
21953
|
-
diagnostics(input,
|
|
21954
|
-
return this.languages.find((language) => language.claims(
|
|
21976
|
+
diagnostics(input, path20, signal) {
|
|
21977
|
+
return this.languages.find((language) => language.claims(path20))?.diagnostics?.(input, signal, this.observe);
|
|
21955
21978
|
}
|
|
21956
21979
|
async analyze(reader, entries, installed, signal, consume, parent) {
|
|
21957
21980
|
const result = {
|
|
@@ -21975,7 +21998,7 @@ var ProjectMapAnalyzer = class {
|
|
|
21975
21998
|
const digests = /* @__PURE__ */ new Map();
|
|
21976
21999
|
for (const entry of entries)
|
|
21977
22000
|
if (entry.contentDigest) digests.set(entry.path, entry.contentDigest);
|
|
21978
|
-
const claims = (
|
|
22001
|
+
const claims = (path20) => this.claims(path20);
|
|
21979
22002
|
const { replayable, sharing, factFiles } = parent ? replayableContexts(parent, digests, claims) : {
|
|
21980
22003
|
replayable: /* @__PURE__ */ new Set(),
|
|
21981
22004
|
sharing: /* @__PURE__ */ new Map(),
|
|
@@ -21987,7 +22010,7 @@ var ProjectMapAnalyzer = class {
|
|
|
21987
22010
|
const linked = /* @__PURE__ */ new Set();
|
|
21988
22011
|
const analyzedFiles = /* @__PURE__ */ new Set();
|
|
21989
22012
|
const stagedPaths = /* @__PURE__ */ new Set();
|
|
21990
|
-
const requestDigest = (request, files2) => digestValue({ request, files: files2.map((
|
|
22013
|
+
const requestDigest = (request, files2) => digestValue({ request, files: files2.map((path20) => [path20, digests.get(path20) ?? null]) });
|
|
21991
22014
|
const replaysDigest = (contextRef2, digest) => parent !== void 0 && replayable.has(contextRef2) && parent.contexts.get(contextRef2)?.requestDigest === digest;
|
|
21992
22015
|
const replays = (contextRef2, request, files2) => replaysDigest(contextRef2, requestDigest(request, files2));
|
|
21993
22016
|
const reuse = (contextRef2, request, files2) => {
|
|
@@ -22028,7 +22051,7 @@ var ProjectMapAnalyzer = class {
|
|
|
22028
22051
|
const ref = analysis.contexts[0]?.ref ?? "";
|
|
22029
22052
|
if (options?.linked?.length) {
|
|
22030
22053
|
if (!parent || analysis.contexts.length !== 1) return invalidParent();
|
|
22031
|
-
for (const
|
|
22054
|
+
for (const path20 of options.linked) linked.add(path20);
|
|
22032
22055
|
this.observe?.({
|
|
22033
22056
|
operation: "LINK",
|
|
22034
22057
|
phase: "FINISHED",
|
|
@@ -22055,7 +22078,7 @@ var ProjectMapAnalyzer = class {
|
|
|
22055
22078
|
});
|
|
22056
22079
|
for (const file2 of analysis.parsedFiles) parsed.add(file2);
|
|
22057
22080
|
const staged = factPaths(analysis);
|
|
22058
|
-
for (const
|
|
22081
|
+
for (const path20 of staged) stagedPaths.add(path20);
|
|
22059
22082
|
for (const context of analysis.contexts) {
|
|
22060
22083
|
for (const file2 of context.configurationFiles) configurationInputs.add(file2);
|
|
22061
22084
|
if (!replayed.has(context.ref))
|
|
@@ -22086,7 +22109,7 @@ var ProjectMapAnalyzer = class {
|
|
|
22086
22109
|
reuse,
|
|
22087
22110
|
replays,
|
|
22088
22111
|
previous,
|
|
22089
|
-
configuration: (
|
|
22112
|
+
configuration: (path20) => configurationInputs.add(path20),
|
|
22090
22113
|
observe: this.observe
|
|
22091
22114
|
},
|
|
22092
22115
|
signal
|
|
@@ -22123,12 +22146,12 @@ var ProjectMapAnalyzer = class {
|
|
|
22123
22146
|
if (files.objects.length) accept(files);
|
|
22124
22147
|
if (parent && (replayed.size || linked.size)) {
|
|
22125
22148
|
for (const ref of replayed.keys())
|
|
22126
|
-
for (const
|
|
22127
|
-
if (analyzedFiles.has(
|
|
22149
|
+
for (const path20 of factFiles.get(ref) ?? invalidParent())
|
|
22150
|
+
if (analyzedFiles.has(path20) || [...sharing.get(path20) ?? []].some((other) => !replayed.has(other)))
|
|
22128
22151
|
throw new MapReplayConflict();
|
|
22129
|
-
for (const paths of replayed.values()) for (const
|
|
22130
|
-
for (const
|
|
22131
|
-
if (analyzedFiles.has(
|
|
22152
|
+
for (const paths of replayed.values()) for (const path20 of paths) linked.add(path20);
|
|
22153
|
+
for (const path20 of linked)
|
|
22154
|
+
if (analyzedFiles.has(path20) || stagedPaths.has(path20)) throw new MapReplayConflict();
|
|
22132
22155
|
parent.link([...linked]);
|
|
22133
22156
|
}
|
|
22134
22157
|
result.parsedFiles = [...parsed].sort();
|
|
@@ -22165,12 +22188,12 @@ var ProjectMapReferenceQuery = class {
|
|
|
22165
22188
|
return source;
|
|
22166
22189
|
}
|
|
22167
22190
|
// The compiler contexts a file is in.
|
|
22168
|
-
contexts(version2,
|
|
22191
|
+
contexts(version2, path20) {
|
|
22169
22192
|
return this.store.database.prepare(`SELECT DISTINCT c.context_ref, c.context_json
|
|
22170
22193
|
FROM project_map_contexts c, json_each(c.context_json, '$.inputFiles') f
|
|
22171
22194
|
WHERE c.version_ref = ? AND f.value = ?
|
|
22172
22195
|
AND json_extract(c.context_json, '$.mode') != 'SYNTAX_ONLY'
|
|
22173
|
-
ORDER BY c.context_ref`).all(version2,
|
|
22196
|
+
ORDER BY c.context_ref`).all(version2, path20).map((value) => MapContextSchema.parse(JSON.parse(String(value.context_json))));
|
|
22174
22197
|
}
|
|
22175
22198
|
// A context's sources, and the request for its compile.
|
|
22176
22199
|
async open(version2, source, context, signal) {
|
|
@@ -22208,7 +22231,7 @@ var ProjectMapReferenceQuery = class {
|
|
|
22208
22231
|
/** The configurations of the contexts a version's files are in. */
|
|
22209
22232
|
contextConfigurations(version2, paths) {
|
|
22210
22233
|
return paths.flatMap(
|
|
22211
|
-
(
|
|
22234
|
+
(path20) => this.contexts(version2, path20).flatMap((context) => context.configPath ?? [])
|
|
22212
22235
|
);
|
|
22213
22236
|
}
|
|
22214
22237
|
/**
|
|
@@ -22234,9 +22257,9 @@ var ProjectMapReferenceQuery = class {
|
|
|
22234
22257
|
unchecked.push(configPath);
|
|
22235
22258
|
continue;
|
|
22236
22259
|
}
|
|
22237
|
-
const [
|
|
22260
|
+
const [path20] = context.rootFiles ?? context.inputFiles;
|
|
22238
22261
|
const { reader, request } = await this.open(input.version, source, context, signal);
|
|
22239
|
-
const result =
|
|
22262
|
+
const result = path20 === void 0 ? void 0 : await this.analyzer.diagnostics(request, path20, signal);
|
|
22240
22263
|
await reader.assertStable();
|
|
22241
22264
|
if (!result) continue;
|
|
22242
22265
|
if (result.requiredFiles.length)
|
|
@@ -22270,9 +22293,9 @@ var ProjectMapReferenceQuery = class {
|
|
|
22270
22293
|
const compiles = /* @__PURE__ */ new Map();
|
|
22271
22294
|
for (const ref of input.refs) {
|
|
22272
22295
|
const object2 = requireMapObject(this.store, input.version, { entityRef: ref }, ["."]);
|
|
22273
|
-
const
|
|
22274
|
-
const contexts = contextsOf.get(
|
|
22275
|
-
contextsOf.set(
|
|
22296
|
+
const path20 = object2.anchor.path;
|
|
22297
|
+
const contexts = contextsOf.get(path20) ?? this.contexts(input.version, path20);
|
|
22298
|
+
contextsOf.set(path20, contexts);
|
|
22276
22299
|
const readable = object2.symbolStart === void 0 ? [] : contexts;
|
|
22277
22300
|
found.set(ref, {
|
|
22278
22301
|
uses: [],
|
|
@@ -22336,16 +22359,31 @@ var ProjectMapReferenceQuery = class {
|
|
|
22336
22359
|
);
|
|
22337
22360
|
if (!prefixes.length || prefixes.length > 64)
|
|
22338
22361
|
throw new ProjectEvidenceError("PROJECT_READ_INPUT_INVALID", false);
|
|
22339
|
-
const
|
|
22340
|
-
|
|
22341
|
-
|
|
22362
|
+
const { path: path20, name, line, entityRef, locator } = input;
|
|
22363
|
+
if (path20 === void 0 !== (name === void 0) || line !== void 0 && name === void 0)
|
|
22364
|
+
throw new ProjectEvidenceError("PROJECT_READ_INPUT_INVALID", false);
|
|
22365
|
+
const selection = mapQuerySelection(
|
|
22366
|
+
{ path: input.within, kinds: input.kinds },
|
|
22367
|
+
MapReferenceKindSchema.options
|
|
22368
|
+
);
|
|
22369
|
+
const query = { within: selection.path, kinds: [...selection.kinds] };
|
|
22370
|
+
const object2 = requireMapObject(
|
|
22371
|
+
this.store,
|
|
22372
|
+
input.version,
|
|
22373
|
+
{
|
|
22374
|
+
entityRef,
|
|
22375
|
+
locator,
|
|
22376
|
+
symbol: path20 !== void 0 && name !== void 0 ? { path: path20, name, ...line === void 0 ? {} : { line } } : void 0
|
|
22377
|
+
},
|
|
22378
|
+
prefixes
|
|
22379
|
+
);
|
|
22342
22380
|
if (object2.symbolStart === void 0)
|
|
22343
22381
|
throw new ProjectEvidenceError("PROJECT_MAP_REFERENCE_TARGET_UNAVAILABLE", false);
|
|
22344
22382
|
const availableContexts = this.contexts(input.version, object2.anchor.path);
|
|
22345
22383
|
if (!availableContexts.length)
|
|
22346
22384
|
throw new ProjectEvidenceError("PROJECT_MAP_REFERENCE_CONTEXT_UNAVAILABLE", false);
|
|
22347
22385
|
const contexts = availableContexts.filter(
|
|
22348
|
-
(context2) => context2.inputFiles.some((file2) => mapQueryPathMatches(file2, query.
|
|
22386
|
+
(context2) => context2.inputFiles.some((file2) => mapQueryPathMatches(file2, query.within))
|
|
22349
22387
|
);
|
|
22350
22388
|
if (contexts.some((context2) => context2.inputFiles.some((file2) => !mapPathAllowed(file2, prefixes))))
|
|
22351
22389
|
throw new ProjectEvidenceError("PROJECT_MAP_REFERENCE_CONTEXT_NOT_AUTHORIZED", false);
|
|
@@ -22410,7 +22448,7 @@ ${scope}`, input.cursor, 2) : [];
|
|
|
22410
22448
|
const locations = /* @__PURE__ */ new Set();
|
|
22411
22449
|
for (const reference of page.references) {
|
|
22412
22450
|
const location2 = canonicalJson(reference.anchor);
|
|
22413
|
-
if (!anchored(reference, files) || !mapPathAllowed(reference.anchor.path, prefixes) || !mapQueryPathMatches(reference.anchor.path, query.
|
|
22451
|
+
if (!anchored(reference, files) || !mapPathAllowed(reference.anchor.path, prefixes) || !mapQueryPathMatches(reference.anchor.path, query.within) || !query.kinds.includes(reference.kind) || locations.has(location2))
|
|
22414
22452
|
throw invalidProtocol();
|
|
22415
22453
|
locations.add(location2);
|
|
22416
22454
|
const owner = this.owner(input.version, reference.anchor);
|
|
@@ -22584,8 +22622,8 @@ var CodeIndex = class {
|
|
|
22584
22622
|
for (const entry of this.store.listEntries(candidate))
|
|
22585
22623
|
if (entry.contentDigest) entries2.set(entry.path, entry.contentDigest);
|
|
22586
22624
|
let changed = 0;
|
|
22587
|
-
for (const [
|
|
22588
|
-
for (const
|
|
22625
|
+
for (const [path20, digest] of digests) if (entries2.get(path20) !== digest) changed++;
|
|
22626
|
+
for (const path20 of entries2.keys()) if (!digests.has(path20)) changed++;
|
|
22589
22627
|
if (!best || changed < best.changed) best = { version: candidate, entries: entries2, changed };
|
|
22590
22628
|
}
|
|
22591
22629
|
if (!best) return void 0;
|
|
@@ -22743,12 +22781,12 @@ var CodeIndex = class {
|
|
|
22743
22781
|
};
|
|
22744
22782
|
|
|
22745
22783
|
// src/project-map-change-diff.ts
|
|
22746
|
-
import { open as open2 } from "node:fs/promises";
|
|
22747
|
-
import
|
|
22784
|
+
import { lstat as lstat3, open as open2 } from "node:fs/promises";
|
|
22785
|
+
import path12 from "node:path";
|
|
22748
22786
|
|
|
22749
22787
|
// src/project-map-names.ts
|
|
22750
22788
|
import { readFile } from "node:fs/promises";
|
|
22751
|
-
import
|
|
22789
|
+
import path11 from "node:path";
|
|
22752
22790
|
var CONFIG_KEY = /^\s*(?:export\s+|-\s+)?["']?([A-Za-z_][\w.-]*)["']?\s*(?:=|:(?:\s|$))/u;
|
|
22753
22791
|
var CODE_READS = [
|
|
22754
22792
|
// process.env.NAME, import.meta.env.NAME
|
|
@@ -22794,7 +22832,7 @@ async function strandedNames(project, files, configuration, git2, options) {
|
|
|
22794
22832
|
if (key) names2.add(key);
|
|
22795
22833
|
for (const match of line.matchAll(PLACEHOLDER)) if (match[1]) names2.add(match[1]);
|
|
22796
22834
|
} else for (const name of codeReads(line, file2.path)) names2.add(name);
|
|
22797
|
-
const text = await readFile(
|
|
22835
|
+
const text = await readFile(path11.join(project, file2.path), "utf8").catch(() => void 0);
|
|
22798
22836
|
if (text === void 0) continue;
|
|
22799
22837
|
for (const name of names2)
|
|
22800
22838
|
if (NAME.test(name) && !PLATFORM.test(name) && !from.has(name) && !wholeName(name).test(text))
|
|
@@ -22895,7 +22933,7 @@ async function readMapChanges(project, base, signal, options = { names: true })
|
|
|
22895
22933
|
...file2,
|
|
22896
22934
|
baseText: (await git.run(["show", `${commit}:${file2.basePath}`], gitOptions(project, signal))).stdout.toString("utf8")
|
|
22897
22935
|
};
|
|
22898
|
-
const untracked = (await git.run(["ls-files", "--others", "--exclude-standard", "-z"], gitOptions(project, signal))).stdout.toString("utf8").split("\0").filter((
|
|
22936
|
+
const untracked = (await git.run(["ls-files", "--others", "--exclude-standard", "-z"], gitOptions(project, signal))).stdout.toString("utf8").split("\0").filter((path20) => path20 && !inExcludedDirectory(path20));
|
|
22899
22937
|
for (const file2 of untracked)
|
|
22900
22938
|
files.push({
|
|
22901
22939
|
path: file2,
|
|
@@ -22906,7 +22944,7 @@ async function readMapChanges(project, base, signal, options = { names: true })
|
|
|
22906
22944
|
removed: [],
|
|
22907
22945
|
// git diff says which tracked files are binary; an untracked one in a language the map does
|
|
22908
22946
|
// not analyze is told the way git tells it, by a NUL in its first 8000 bytes.
|
|
22909
|
-
binary: !mapLanguageOf(file2) && await startsBinary(
|
|
22947
|
+
binary: !mapLanguageOf(file2) && await startsBinary(path12.join(project, file2))
|
|
22910
22948
|
});
|
|
22911
22949
|
const stranded = options.names ? await strandedNames(
|
|
22912
22950
|
project,
|
|
@@ -22918,6 +22956,7 @@ async function readMapChanges(project, base, signal, options = { names: true })
|
|
|
22918
22956
|
return { base, commit, files, quoted: parsed.quoted, stranded };
|
|
22919
22957
|
}
|
|
22920
22958
|
async function startsBinary(file2) {
|
|
22959
|
+
if (!(await lstat3(file2).catch(() => void 0))?.isFile()) return false;
|
|
22921
22960
|
const handle = await open2(file2, "r").catch(() => void 0);
|
|
22922
22961
|
if (!handle) return false;
|
|
22923
22962
|
try {
|
|
@@ -23006,7 +23045,7 @@ function mapPathNow(files) {
|
|
|
23006
23045
|
(file2) => file2.basePath !== void 0 && file2.status !== "DELETED" ? [[file2.basePath, file2.path]] : []
|
|
23007
23046
|
)
|
|
23008
23047
|
);
|
|
23009
|
-
return (
|
|
23048
|
+
return (path20) => moved.get(path20) ?? path20;
|
|
23010
23049
|
}
|
|
23011
23050
|
var overlaps = (lines, start, end) => lines.some(([from, to]) => from <= end && start <= to);
|
|
23012
23051
|
var workingLine = (file2, line) => {
|
|
@@ -23030,17 +23069,19 @@ var NON_CODE = [
|
|
|
23030
23069
|
[/(?:^|\/)\.env[^/]*$|\.(?:ya?ml|toml|ini|properties|conf|cfg)$/iu, "configuration"],
|
|
23031
23070
|
[/\.(?:html?|jinja2?|j2|hbs|ejs|tmpl|tpl|gohtml|vue|svelte|wxml)$/iu, "template"]
|
|
23032
23071
|
];
|
|
23033
|
-
var nonCodeKind = (
|
|
23072
|
+
var nonCodeKind = (path20) => NON_CODE.find(([pattern]) => pattern.test(path20))?.[1];
|
|
23034
23073
|
var UNANALYZED = [
|
|
23035
23074
|
[/\.(?:sh|bash|zsh|fish|ps1|bat|cmd)$/iu, "shell script"],
|
|
23036
|
-
[/\.(?:css|scss|sass|less|styl|wxss|acss)$/iu, "style sheet"]
|
|
23075
|
+
[/\.(?:css|scss|sass|less|styl|wxss|acss)$/iu, "style sheet"],
|
|
23076
|
+
// Git lists a repository nested in the project by its directory, and nothing inside it.
|
|
23077
|
+
[/\/$/u, "nested repository"]
|
|
23037
23078
|
];
|
|
23038
23079
|
var DOCUMENTATION = /\.(?:md|mdx|markdown|rst|adoc)$|(?:^|\/)(?:LICENSE|NOTICE)[^/]*$/iu;
|
|
23039
|
-
var unmappedKind = (
|
|
23080
|
+
var unmappedKind = (path20, binary) => nonCodeKind(path20) ?? (binary ? "binary file" : DOCUMENTATION.test(path20) ? void 0 : UNANALYZED.find(([pattern]) => pattern.test(path20))?.[1] ?? "unanalyzed file");
|
|
23040
23081
|
|
|
23041
23082
|
// src/project-map-changes.ts
|
|
23042
23083
|
import { readFile as readFile3 } from "node:fs/promises";
|
|
23043
|
-
import
|
|
23084
|
+
import path14 from "node:path";
|
|
23044
23085
|
|
|
23045
23086
|
// src/project-map-change-types.ts
|
|
23046
23087
|
var LIMITS = Object.freeze({
|
|
@@ -23055,6 +23096,8 @@ var LIST = Object.freeze({
|
|
|
23055
23096
|
entries: 40,
|
|
23056
23097
|
tests: 12,
|
|
23057
23098
|
unclear: 20,
|
|
23099
|
+
/** Subjects named on the line of one kind of note to check by hand. */
|
|
23100
|
+
grouped: 8,
|
|
23058
23101
|
stranded: 12,
|
|
23059
23102
|
clients: 8,
|
|
23060
23103
|
names: 6,
|
|
@@ -23101,7 +23144,7 @@ var LITERAL = /(["'`])((?:\\.|(?!\1)[^\\])*)\1/gu;
|
|
|
23101
23144
|
var MOUNTING = /(?:\b(?:prefix|root_path|base_path|basePath|baseURL|baseUrl)\s*[=:]|\b(?:Group|Route|Mount|mount|use|include_router|PathPrefix|StripPrefix)\s*\()\s*$/u;
|
|
23102
23145
|
var LIMIT2 = Object.freeze({ routes: 40, clients: 5 });
|
|
23103
23146
|
var ROUTE = /^(?:[A-Z]+(?:\|[A-Z]+)* +)?\/\S*$/u;
|
|
23104
|
-
var segments = (
|
|
23147
|
+
var segments = (path20) => path20.split("/").filter(Boolean).map((text) => ({ text, param: PARAM.test(text) || /[{}$<>%]/u.test(text) }));
|
|
23105
23148
|
function mapRouteLabel(label) {
|
|
23106
23149
|
const match = /^([A-Z]+(?:\|[A-Z]+)*) +(\S.*)$/u.exec(label);
|
|
23107
23150
|
return match ? { methods: (match[1] ?? "").split("|"), path: match[2] ?? "" } : { path: label };
|
|
@@ -23134,10 +23177,10 @@ function requestedPath(literal3, joined) {
|
|
|
23134
23177
|
const match = /^(?:https?:\/\/[^/\s]+|(?:\$\{[^}]*\})+|@\{|redirect:|forward:)?(\/[^\s?#()"'`,;|]*)/u.exec(
|
|
23135
23178
|
literal3
|
|
23136
23179
|
) ?? void 0;
|
|
23137
|
-
const
|
|
23138
|
-
if (!
|
|
23139
|
-
const parts = segments(
|
|
23140
|
-
if (joined &&
|
|
23180
|
+
const path20 = match?.[1];
|
|
23181
|
+
if (!path20 || path20.startsWith("//") || path20.length < 3) return void 0;
|
|
23182
|
+
const parts = segments(path20);
|
|
23183
|
+
if (joined && path20.endsWith("/")) parts.push({ text: "*", param: true });
|
|
23141
23184
|
return parts;
|
|
23142
23185
|
}
|
|
23143
23186
|
var same = (route, requested) => route.param || !requested.param && route.text === requested.text;
|
|
@@ -23290,11 +23333,11 @@ var USED_BY = {
|
|
|
23290
23333
|
OVERRIDES: "overridden"
|
|
23291
23334
|
};
|
|
23292
23335
|
var runsTarget = (relation) => CALLER_KINDS.has(relation.kind) && !relation.event;
|
|
23293
|
-
var changeUnits = (graph,
|
|
23294
|
-
function changedUnits(graph,
|
|
23336
|
+
var changeUnits = (graph, path20) => mapMiniprogramTemplate(path20) ? graph.objectsAt(path20).filter((object2) => mapIsModule(object2) && object2.parsing === "PARSED") : graph.declarationsAt(path20);
|
|
23337
|
+
function changedUnits(graph, path20, lines) {
|
|
23295
23338
|
const refs = /* @__PURE__ */ new Set();
|
|
23296
23339
|
let topLevel = false;
|
|
23297
|
-
const inFile = changeUnits(graph,
|
|
23340
|
+
const inFile = changeUnits(graph, path20);
|
|
23298
23341
|
for (const [from, to] of lines) {
|
|
23299
23342
|
const containing = inFile.filter(
|
|
23300
23343
|
(object2) => object2.anchor.startLine <= to && from <= object2.anchor.endLine
|
|
@@ -23493,8 +23536,17 @@ var Tracer = class {
|
|
|
23493
23536
|
if (mapTestPath(object2.anchor.path) || this.routes.has(reached.ref)) continue;
|
|
23494
23537
|
if (reached.depth === 0 && !mapMiniprogramTemplate(object2.anchor.path)) {
|
|
23495
23538
|
const uses = this.usesWithoutCalls(reached.ref);
|
|
23539
|
+
const subject = this.where(reached.ref);
|
|
23496
23540
|
this.unclear.push(
|
|
23497
|
-
uses.length ?
|
|
23541
|
+
uses.length ? {
|
|
23542
|
+
text: `${subject} has no callers in the map, and is used without a call: ${uses.join("; ")}`
|
|
23543
|
+
} : mapIsShape(object2) ? {
|
|
23544
|
+
text: `${subject} has no callers in the map, and a search for references found no use: it may be read through reflection, serialization or a value of unknown type, or be unused`,
|
|
23545
|
+
group: { kind: "NO_USE", subject }
|
|
23546
|
+
} : {
|
|
23547
|
+
text: `${subject} has no callers in the map: it may be wired by a framework, called dynamically, or unused`,
|
|
23548
|
+
group: { kind: "NO_CALLERS", subject }
|
|
23549
|
+
}
|
|
23498
23550
|
);
|
|
23499
23551
|
} else if (!mapIsShape(object2) || !reached.used && object2.kind === "PROPERTY")
|
|
23500
23552
|
this.entry(this.where(reached.ref), false, reached, void 0, reached.certain, true);
|
|
@@ -23762,9 +23814,9 @@ var Tracer = class {
|
|
|
23762
23814
|
if (object2.kind !== "METHOD" || !language || /^__\w+__$/u.test(object2.name)) return;
|
|
23763
23815
|
const calls = this.memberCalls.get(`${language}\0${object2.name}`) ?? [];
|
|
23764
23816
|
if (calls.length)
|
|
23765
|
-
this.unclear.push(
|
|
23766
|
-
`${calls.length} calls of a member named ${object2.name} on receivers of unknown type may reach ${this.graph.qualifiedName(ref)}; a text search finds them`
|
|
23767
|
-
);
|
|
23817
|
+
this.unclear.push({
|
|
23818
|
+
text: `${calls.length} calls of a member named ${object2.name} on receivers of unknown type may reach ${this.graph.qualifiedName(ref)}; a text search finds them`
|
|
23819
|
+
});
|
|
23768
23820
|
}
|
|
23769
23821
|
entry(label, route, at, site, certain, top = false) {
|
|
23770
23822
|
if (route) this.handlers.set(label, (this.handlers.get(label) ?? /* @__PURE__ */ new Set()).add(at.ref));
|
|
@@ -23808,12 +23860,12 @@ var Tracer = class {
|
|
|
23808
23860
|
this.mentions.set(route, (this.mentions.get(route) ?? /* @__PURE__ */ new Set()).add(file2));
|
|
23809
23861
|
}
|
|
23810
23862
|
/** A related test file; the closest relation (lowest rank) explains it. */
|
|
23811
|
-
test(
|
|
23812
|
-
if (!mapRunnableTest(
|
|
23813
|
-
const known = this.tests.get(
|
|
23863
|
+
test(path20, name, why, rank2) {
|
|
23864
|
+
if (!mapRunnableTest(path20)) return;
|
|
23865
|
+
const known = this.tests.get(path20) ?? { names: /* @__PURE__ */ new Set(), why, rank: rank2 };
|
|
23814
23866
|
if (rank2 < known.rank) Object.assign(known, { why, rank: rank2 });
|
|
23815
23867
|
if (name && !name.startsWith("<")) known.names.add(name);
|
|
23816
|
-
this.tests.set(
|
|
23868
|
+
this.tests.set(path20, known);
|
|
23817
23869
|
}
|
|
23818
23870
|
};
|
|
23819
23871
|
var entriesOf = /* @__PURE__ */ new WeakMap();
|
|
@@ -23862,19 +23914,19 @@ function findTestEntries(graph, ref) {
|
|
|
23862
23914
|
}
|
|
23863
23915
|
|
|
23864
23916
|
// src/project-map-change-edges.ts
|
|
23865
|
-
var same2 = (
|
|
23917
|
+
var same2 = (path20) => path20;
|
|
23866
23918
|
var compare = (left, right) => left < right ? -1 : left > right ? 1 : 0;
|
|
23867
|
-
function linksOf(side,
|
|
23919
|
+
function linksOf(side, path20) {
|
|
23868
23920
|
const imports = /* @__PURE__ */ new Map();
|
|
23869
23921
|
const calls = /* @__PURE__ */ new Map();
|
|
23870
|
-
if (
|
|
23922
|
+
if (path20 === void 0) return { imports, calls };
|
|
23871
23923
|
const { graph } = side;
|
|
23872
|
-
for (const relation of graph.relationsFrom(graph.objectsAt(
|
|
23924
|
+
for (const relation of graph.relationsFrom(graph.objectsAt(path20).map((object2) => object2.id))) {
|
|
23873
23925
|
const line = relation.anchor.startLine;
|
|
23874
|
-
if (relation.to === void 0 || !side.counts(
|
|
23926
|
+
if (relation.to === void 0 || !side.counts(path20, line)) continue;
|
|
23875
23927
|
if (relation.kind === "IMPORTS") {
|
|
23876
23928
|
const target = graph.object(relation.to).anchor.path;
|
|
23877
|
-
if (target ===
|
|
23929
|
+
if (target === path20) continue;
|
|
23878
23930
|
const to = side.pathNow(target);
|
|
23879
23931
|
const found = imports.get(to) ?? { to, lines: [] };
|
|
23880
23932
|
found.lines.push(line);
|
|
@@ -23882,7 +23934,7 @@ function linksOf(side, path19) {
|
|
|
23882
23934
|
} else if (CALLER_KINDS.has(relation.kind)) {
|
|
23883
23935
|
const ref = graph.owner(relation.to);
|
|
23884
23936
|
const owner = graph.object(ref);
|
|
23885
|
-
if (owner.anchor.path ===
|
|
23937
|
+
if (owner.anchor.path === path20 || mapIsModule(owner)) continue;
|
|
23886
23938
|
const to = side.pathNow(owner.anchor.path);
|
|
23887
23939
|
const key = `${to}\0${graph.declarationKey(owner)}`;
|
|
23888
23940
|
const found = calls.get(key) ?? { to, lines: [], ref };
|
|
@@ -23913,17 +23965,17 @@ function mapChangeLinks(store, working, base, files) {
|
|
|
23913
23965
|
counts: always,
|
|
23914
23966
|
pathOf,
|
|
23915
23967
|
declaration: (file2, ref) => {
|
|
23916
|
-
const
|
|
23917
|
-
if (
|
|
23918
|
-
let keys = declared.get(
|
|
23968
|
+
const path20 = pathOf(file2);
|
|
23969
|
+
if (path20 === void 0) return void 0;
|
|
23970
|
+
let keys = declared.get(path20);
|
|
23919
23971
|
if (!keys) {
|
|
23920
23972
|
keys = new Map(
|
|
23921
|
-
changeUnits(baseGraph,
|
|
23973
|
+
changeUnits(baseGraph, path20).map((object2) => [
|
|
23922
23974
|
baseGraph.declarationKey(object2),
|
|
23923
23975
|
object2.id
|
|
23924
23976
|
])
|
|
23925
23977
|
);
|
|
23926
|
-
declared.set(
|
|
23978
|
+
declared.set(path20, keys);
|
|
23927
23979
|
}
|
|
23928
23980
|
return keys.get(graph.declarationKey(graph.object(ref)));
|
|
23929
23981
|
}
|
|
@@ -23933,8 +23985,8 @@ function mapChangeLinks(store, working, base, files) {
|
|
|
23933
23985
|
before = {
|
|
23934
23986
|
graph,
|
|
23935
23987
|
pathNow: same2,
|
|
23936
|
-
counts: (
|
|
23937
|
-
const file2 = changedAt.get(
|
|
23988
|
+
counts: (path20, line) => {
|
|
23989
|
+
const file2 = changedAt.get(path20);
|
|
23938
23990
|
return !file2 || !overlaps(file2.lines, line, line);
|
|
23939
23991
|
},
|
|
23940
23992
|
pathOf: (file2) => file2.status === "ADDED" ? void 0 : file2.path,
|
|
@@ -23968,9 +24020,9 @@ function callersOf(side, ref) {
|
|
|
23968
24020
|
const home = side.graph.object(ref).anchor.path;
|
|
23969
24021
|
const files = /* @__PURE__ */ new Set();
|
|
23970
24022
|
for (const relation of side.graph.relationsTo([ref])) {
|
|
23971
|
-
const
|
|
23972
|
-
if (!CALLER_KINDS.has(relation.kind) ||
|
|
23973
|
-
if (side.counts(
|
|
24023
|
+
const path20 = relation.anchor.path;
|
|
24024
|
+
if (!CALLER_KINDS.has(relation.kind) || path20 === home || mapTestPath(path20)) continue;
|
|
24025
|
+
if (side.counts(path20, relation.anchor.startLine)) files.add(side.pathNow(path20));
|
|
23974
24026
|
}
|
|
23975
24027
|
return [...files].sort();
|
|
23976
24028
|
}
|
|
@@ -24032,7 +24084,7 @@ function mapChangeEdges(links) {
|
|
|
24032
24084
|
|
|
24033
24085
|
// src/project-map-change-tests.ts
|
|
24034
24086
|
import { readFile as readFile2 } from "node:fs/promises";
|
|
24035
|
-
import
|
|
24087
|
+
import path13 from "node:path";
|
|
24036
24088
|
|
|
24037
24089
|
// src/project-map-route-paths.ts
|
|
24038
24090
|
import {
|
|
@@ -24087,7 +24139,7 @@ var MAP_PATH_PARAMETER = "{}";
|
|
|
24087
24139
|
async function existingTestsChanged(before, after, file2, project) {
|
|
24088
24140
|
if (!file2.basePath || file2.baseText === void 0) return [];
|
|
24089
24141
|
const baseLines = file2.baseText.split("\n");
|
|
24090
|
-
const workingLines = file2.status !== "DELETED" && project ? (await readFile2(
|
|
24142
|
+
const workingLines = file2.status !== "DELETED" && project ? (await readFile2(path13.join(project, file2.path), "utf8").catch(() => void 0))?.split(
|
|
24091
24143
|
"\n"
|
|
24092
24144
|
) ?? [] : [];
|
|
24093
24145
|
const body = (lines, object2) => lines.slice(object2.anchor.startLine - 1, object2.anchor.endLine).map((line) => line.trimEnd());
|
|
@@ -24124,10 +24176,10 @@ function importerTests(graph, objects2, tracer, importers) {
|
|
|
24124
24176
|
}
|
|
24125
24177
|
const next = [];
|
|
24126
24178
|
for (const imported of modules)
|
|
24127
|
-
for (const { path:
|
|
24128
|
-
if (mapTestPath(
|
|
24179
|
+
for (const { path: path20, module } of importers.get(imported) ?? [])
|
|
24180
|
+
if (mapTestPath(path20))
|
|
24129
24181
|
tracer.test(
|
|
24130
|
-
|
|
24182
|
+
path20,
|
|
24131
24183
|
void 0,
|
|
24132
24184
|
hop ? "imports a changed file indirectly" : "imports a changed file",
|
|
24133
24185
|
hop ? 4 : 2
|
|
@@ -24152,17 +24204,17 @@ function supportTests(store, version2, tracer) {
|
|
|
24152
24204
|
function mapPathIndex(paths) {
|
|
24153
24205
|
const testsIn = /* @__PURE__ */ new Map();
|
|
24154
24206
|
const under = /* @__PURE__ */ new Map();
|
|
24155
|
-
const add = (map2, key,
|
|
24207
|
+
const add = (map2, key, path20) => {
|
|
24156
24208
|
const found = map2.get(key);
|
|
24157
|
-
if (found) found.push(
|
|
24158
|
-
else map2.set(key, [
|
|
24209
|
+
if (found) found.push(path20);
|
|
24210
|
+
else map2.set(key, [path20]);
|
|
24159
24211
|
};
|
|
24160
|
-
for (const
|
|
24161
|
-
const slash =
|
|
24162
|
-
const directory = slash < 0 ? "" :
|
|
24163
|
-
if (mapTestPath(
|
|
24212
|
+
for (const path20 of paths) {
|
|
24213
|
+
const slash = path20.lastIndexOf("/");
|
|
24214
|
+
const directory = slash < 0 ? "" : path20.slice(0, slash + 1);
|
|
24215
|
+
if (mapTestPath(path20)) add(testsIn, directory, path20);
|
|
24164
24216
|
const name = directory.slice(directory.lastIndexOf("/", directory.length - 2) + 1, -1);
|
|
24165
|
-
if (name) add(under, name,
|
|
24217
|
+
if (name) add(under, name, path20);
|
|
24166
24218
|
}
|
|
24167
24219
|
return { testsIn, under };
|
|
24168
24220
|
}
|
|
@@ -24255,7 +24307,7 @@ var RouteRequests = class {
|
|
|
24255
24307
|
}
|
|
24256
24308
|
const batch = this.candidates.slice(at, at + READ_BATCH);
|
|
24257
24309
|
const texts = await Promise.all(
|
|
24258
|
-
batch.map((file2) => readFile2(
|
|
24310
|
+
batch.map((file2) => readFile2(path13.join(project, file2), "utf8").catch(() => void 0))
|
|
24259
24311
|
);
|
|
24260
24312
|
for (const [index, text] of texts.entries())
|
|
24261
24313
|
if (text !== void 0) yield [batch[index], text];
|
|
@@ -24296,9 +24348,9 @@ async function routeTests(requests, entries, tracer) {
|
|
|
24296
24348
|
}
|
|
24297
24349
|
return requested;
|
|
24298
24350
|
}
|
|
24299
|
-
function wholePath(text,
|
|
24300
|
-
for (let at = text.indexOf(
|
|
24301
|
-
if (!/[\w./-]/u.test(text[at +
|
|
24351
|
+
function wholePath(text, path20) {
|
|
24352
|
+
for (let at = text.indexOf(path20); at >= 0; at = text.indexOf(path20, at + 1))
|
|
24353
|
+
if (!/[\w./-]/u.test(text[at + path20.length] ?? "")) return true;
|
|
24302
24354
|
return false;
|
|
24303
24355
|
}
|
|
24304
24356
|
async function unworkedRequests(requests, tracer, reaching) {
|
|
@@ -24319,14 +24371,14 @@ async function unworkedRequests(requests, tracer, reaching) {
|
|
|
24319
24371
|
}
|
|
24320
24372
|
}
|
|
24321
24373
|
}
|
|
24322
|
-
function sameDirectoryTests(paths,
|
|
24323
|
-
const slash =
|
|
24324
|
-
for (const candidate of paths.testsIn.get(slash < 0 ? "" :
|
|
24374
|
+
function sameDirectoryTests(paths, path20, tracer) {
|
|
24375
|
+
const slash = path20.lastIndexOf("/");
|
|
24376
|
+
for (const candidate of paths.testsIn.get(slash < 0 ? "" : path20.slice(0, slash + 1)) ?? [])
|
|
24325
24377
|
tracer.test(candidate, void 0, "in the same directory", 3);
|
|
24326
24378
|
}
|
|
24327
|
-
function routesIn(graph,
|
|
24379
|
+
function routesIn(graph, path20) {
|
|
24328
24380
|
const routes = /* @__PURE__ */ new Set();
|
|
24329
|
-
for (const relation of graph.relationsFrom(graph.objectsAt(
|
|
24381
|
+
for (const relation of graph.relationsFrom(graph.objectsAt(path20).map((object2) => object2.id))) {
|
|
24330
24382
|
const route = mapRegisteredRoute(relation);
|
|
24331
24383
|
if (route) routes.add(route);
|
|
24332
24384
|
}
|
|
@@ -24364,9 +24416,9 @@ async function mapRemovedImpact(input) {
|
|
|
24364
24416
|
new MapShapeUses(before, input.shapes, input.until)
|
|
24365
24417
|
);
|
|
24366
24418
|
const changedIn = changedInBase(changes.files);
|
|
24367
|
-
const pathNow = (
|
|
24368
|
-
const file2 = changedIn.get(
|
|
24369
|
-
return file2?.status === "DELETED" ? void 0 : file2?.path ??
|
|
24419
|
+
const pathNow = (path20) => {
|
|
24420
|
+
const file2 = changedIn.get(path20);
|
|
24421
|
+
return file2?.status === "DELETED" ? void 0 : file2?.path ?? path20;
|
|
24370
24422
|
};
|
|
24371
24423
|
const nowAt = (anchor) => {
|
|
24372
24424
|
const file2 = changedIn.get(anchor.path);
|
|
@@ -24381,11 +24433,11 @@ async function mapRemovedImpact(input) {
|
|
|
24381
24433
|
const samePlace = (anchor, place) => anchor.path === place.path && anchor.startLine === place.startLine && anchor.endLine === place.endLine;
|
|
24382
24434
|
const replaces = (now, removed2) => now.kind === removed2.kind && now.name === removed2.name;
|
|
24383
24435
|
const relationsNow = /* @__PURE__ */ new Map();
|
|
24384
|
-
const relationsIn = (
|
|
24385
|
-
let found = relationsNow.get(
|
|
24436
|
+
const relationsIn = (path20) => {
|
|
24437
|
+
let found = relationsNow.get(path20);
|
|
24386
24438
|
if (!found) {
|
|
24387
|
-
found = graph.relationsFrom(graph.objectsAt(
|
|
24388
|
-
relationsNow.set(
|
|
24439
|
+
found = graph.relationsFrom(graph.objectsAt(path20).map((object2) => object2.id));
|
|
24440
|
+
relationsNow.set(path20, found);
|
|
24389
24441
|
}
|
|
24390
24442
|
return found;
|
|
24391
24443
|
};
|
|
@@ -24464,9 +24516,9 @@ async function mapRemovedImpact(input) {
|
|
|
24464
24516
|
for (const { shapes: inRemoved, inside, usedBy } of goneShapes)
|
|
24465
24517
|
for (const shape of inRemoved) {
|
|
24466
24518
|
if (beforeTracer.shapes.unread.has(shape))
|
|
24467
|
-
unclear.push(
|
|
24468
|
-
`${before.object(shape).anchor.path}: ${before.qualifiedName(shape)} was removed, and who used it was not read; search the code for its name`
|
|
24469
|
-
);
|
|
24519
|
+
unclear.push({
|
|
24520
|
+
text: `${before.object(shape).anchor.path}: ${before.qualifiedName(shape)} was removed, and who used it was not read; search the code for its name`
|
|
24521
|
+
});
|
|
24470
24522
|
const now = successors(shape);
|
|
24471
24523
|
for (const { owner, anchor } of beforeTracer.shapes.uses.get(shape) ?? []) {
|
|
24472
24524
|
const place = nowAt(anchor);
|
|
@@ -24485,22 +24537,22 @@ async function mapRemovedImpact(input) {
|
|
|
24485
24537
|
}
|
|
24486
24538
|
}
|
|
24487
24539
|
if (unfollowed.size)
|
|
24488
|
-
unclear.push(
|
|
24489
|
-
`${unfollowed.size} removed fields or types are used on lines the diff left alone, and whether that code now uses what took their place was not read (${[
|
|
24540
|
+
unclear.push({
|
|
24541
|
+
text: `${unfollowed.size} removed fields or types are used on lines the diff left alone, and whether that code now uses what took their place was not read (${[
|
|
24490
24542
|
...unfollowed
|
|
24491
24543
|
].sort().slice(0, LIST.names).join(
|
|
24492
24544
|
", "
|
|
24493
24545
|
)}${unfollowed.size > LIST.names ? ", \u2026" : ""}); project_find_references lists their uses`
|
|
24494
|
-
);
|
|
24546
|
+
});
|
|
24495
24547
|
const lost = /* @__PURE__ */ new Map();
|
|
24496
24548
|
const changedAt = changedInWorkingTree(changes.files);
|
|
24497
|
-
for (const
|
|
24498
|
-
const template = graph.objectsAt(
|
|
24549
|
+
for (const path20 of input.mappedPaths().filter(mapMiniprogramTemplate)) {
|
|
24550
|
+
const template = graph.objectsAt(path20).find((object2) => mapIsModule(object2));
|
|
24499
24551
|
if (!template) continue;
|
|
24500
24552
|
const broken = graph.relationsFrom(graph.scope(template.id).refs).filter((relation) => relation.to === void 0 && NAMING_KINDS.has(relation.kind));
|
|
24501
24553
|
if (!broken.length) continue;
|
|
24502
|
-
const file2 = changedAt.get(
|
|
24503
|
-
const basePath = file2 ? file2.basePath :
|
|
24554
|
+
const file2 = changedAt.get(path20);
|
|
24555
|
+
const basePath = file2 ? file2.basePath : path20;
|
|
24504
24556
|
const was = basePath === void 0 ? void 0 : before.objectsAt(basePath).find(mapIsModule);
|
|
24505
24557
|
const links = was ? before.relationsFrom(before.scope(was.id).refs) : [];
|
|
24506
24558
|
for (const relation of broken) {
|
|
@@ -24509,11 +24561,11 @@ async function mapRemovedImpact(input) {
|
|
|
24509
24561
|
);
|
|
24510
24562
|
if (earlier.some((link) => link.to === void 0)) continue;
|
|
24511
24563
|
const event = miniprogramEventOf(relation.target);
|
|
24512
|
-
const at = `${
|
|
24564
|
+
const at = `${path20}:${relation.anchor.startLine}`;
|
|
24513
24565
|
if (file2 && overlaps(file2.lines, relation.anchor.startLine, relation.anchor.endLine)) {
|
|
24514
|
-
unclear.push(
|
|
24515
|
-
event ? `${at} binds the ${event.event} event of <${event.tag}>, which it does not emit` : relation.kind === "REFERENCES" ? `${at} puts <${relation.target}>, which its registration does not find` : `${at} binds ${relation.target}, which its page or component does not register`
|
|
24516
|
-
);
|
|
24566
|
+
unclear.push({
|
|
24567
|
+
text: event ? `${at} binds the ${event.event} event of <${event.tag}>, which it does not emit` : relation.kind === "REFERENCES" ? `${at} puts <${relation.target}>, which its registration does not find` : `${at} binds ${relation.target}, which its page or component does not register`
|
|
24568
|
+
});
|
|
24517
24569
|
continue;
|
|
24518
24570
|
}
|
|
24519
24571
|
const reached = event ? links.find((link) => link.kind === "REFERENCES" && link.target === event.tag)?.to : earlier.find((link) => link.to !== void 0)?.to;
|
|
@@ -24521,7 +24573,7 @@ async function mapRemovedImpact(input) {
|
|
|
24521
24573
|
const object2 = before.object(reached);
|
|
24522
24574
|
const name = mapIsModule(object2) ? `${object2.anchor.path} (template)${event ? `: ${event.event} event` : ""}` : `${object2.anchor.path}: ${before.qualifiedName(reached)} ${mapDeclarationLabel(object2)}`;
|
|
24523
24575
|
const users = lost.get(name) ?? /* @__PURE__ */ new Set();
|
|
24524
|
-
users.add(`${
|
|
24576
|
+
users.add(`${path20} (template)`);
|
|
24525
24577
|
lost.set(name, users);
|
|
24526
24578
|
}
|
|
24527
24579
|
}
|
|
@@ -24563,15 +24615,15 @@ async function mapRemovedImpact(input) {
|
|
|
24563
24615
|
...removed2 ? { removed: true } : {}
|
|
24564
24616
|
});
|
|
24565
24617
|
}
|
|
24566
|
-
for (const [
|
|
24567
|
-
const now = pathNow(
|
|
24618
|
+
for (const [path20, test] of beforeTracer.tests) {
|
|
24619
|
+
const now = pathNow(path20);
|
|
24568
24620
|
if (now === void 0) continue;
|
|
24569
24621
|
tracer.test(now, void 0, test.why, test.rank);
|
|
24570
24622
|
for (const name of test.names) tracer.test(now, name, test.why, test.rank);
|
|
24571
24623
|
}
|
|
24572
24624
|
for (const [area, known] of beforeTracer.areas)
|
|
24573
|
-
for (const [
|
|
24574
|
-
const now = pathNow(
|
|
24625
|
+
for (const [path20, names] of known.tests) {
|
|
24626
|
+
const now = pathNow(path20);
|
|
24575
24627
|
const place = pathNow(area);
|
|
24576
24628
|
if (now !== void 0 && place !== void 0)
|
|
24577
24629
|
tracer.shareArea(place, known.through, now, names);
|
|
@@ -24594,34 +24646,34 @@ async function mapRemovedImpact(input) {
|
|
|
24594
24646
|
for (const ref of called) {
|
|
24595
24647
|
const object2 = before.object(ref);
|
|
24596
24648
|
if (mapIsModule(object2) || mapTestPath(object2.anchor.path) || gone2.has(ref)) continue;
|
|
24597
|
-
const
|
|
24598
|
-
if (
|
|
24649
|
+
const path20 = pathNow(object2.anchor.path);
|
|
24650
|
+
if (path20 === void 0) continue;
|
|
24599
24651
|
const key = before.declarationKey(object2);
|
|
24600
|
-
const now = graph.declarationsAt(
|
|
24652
|
+
const now = graph.declarationsAt(path20).find((candidate) => graph.declarationKey(candidate) === key);
|
|
24601
24653
|
if (!now) continue;
|
|
24602
24654
|
const calls = tracer.callers(now.id).filter((caller) => !caller.uses);
|
|
24603
24655
|
if (outsideTests(calls, graph).length || tracer.usesWithoutCalls(now.id).length) continue;
|
|
24604
24656
|
if (!outsideTests(beforeTracer.callers(ref), before).length) continue;
|
|
24605
|
-
candidates.push({ path:
|
|
24657
|
+
candidates.push({ path: path20, name: before.qualifiedName(ref), now, tested: calls.length > 0 });
|
|
24606
24658
|
}
|
|
24607
24659
|
await tracer.shapes.read(candidates.map(({ now }) => now.id));
|
|
24608
24660
|
const uncalled = [];
|
|
24609
24661
|
const unknown2 = [];
|
|
24610
|
-
for (const { path:
|
|
24662
|
+
for (const { path: path20, name, now, tested } of candidates) {
|
|
24611
24663
|
if (tracer.shapes.unread.has(now.id)) unknown2.push(name);
|
|
24612
24664
|
else if (!tracer.shapes.uses.get(now.id)?.some(({ owner, write }) => !write && !mapTestPath(graph.object(owner).anchor.path))) {
|
|
24613
24665
|
uncalled.push(
|
|
24614
|
-
`${
|
|
24666
|
+
`${path20}: ${name} ${mapDeclarationLabel(now)}${tested ? " (only tests call it now)" : ""}`
|
|
24615
24667
|
);
|
|
24616
24668
|
}
|
|
24617
24669
|
}
|
|
24618
24670
|
uncalled.sort();
|
|
24619
24671
|
if (unknown2.length)
|
|
24620
|
-
unclear.push(
|
|
24621
|
-
`${unknown2.length} fields lost callers the diff removed, and whether others use them was not read (${unknown2.sort().slice(0, LIST.names).join(
|
|
24672
|
+
unclear.push({
|
|
24673
|
+
text: `${unknown2.length} fields lost callers the diff removed, and whether others use them was not read (${unknown2.sort().slice(0, LIST.names).join(
|
|
24622
24674
|
", "
|
|
24623
24675
|
)}${unknown2.length > LIST.names ? ", \u2026" : ""}); project_find_references lists their uses`
|
|
24624
|
-
);
|
|
24676
|
+
});
|
|
24625
24677
|
return {
|
|
24626
24678
|
removed: removed.map(({ declaration, usedBy }) => ({
|
|
24627
24679
|
declaration,
|
|
@@ -24636,6 +24688,43 @@ async function mapRemovedImpact(input) {
|
|
|
24636
24688
|
}
|
|
24637
24689
|
|
|
24638
24690
|
// src/project-map-change-text.ts
|
|
24691
|
+
var GROUPED = {
|
|
24692
|
+
TOP_LEVEL: (count, subjects) => `top-level code of ${count} files changed (imports, constants or registrations): ${subjects}`,
|
|
24693
|
+
UNMAPPED: (count, subjects) => `${count} changed files are of kinds the map does not analyze, so their effects are not mapped: ${subjects}`,
|
|
24694
|
+
NO_CALLERS: (count, subjects) => `${count} changed declarations have no callers in the map: they may be wired by a framework, called dynamically, or unused (${subjects})`,
|
|
24695
|
+
NO_USE: (count, subjects) => `${count} changed fields or types have no callers in the map, and a search for references found no use: they may be read through reflection, serialization or a value of unknown type, or be unused (${subjects})`,
|
|
24696
|
+
REGISTRATION: (count, subjects) => `${count} route registrations changed; check that each route still reaches the right handler: ${subjects}`
|
|
24697
|
+
};
|
|
24698
|
+
function uncertainLines(notes) {
|
|
24699
|
+
const lines = [];
|
|
24700
|
+
const kinds = /* @__PURE__ */ new Map();
|
|
24701
|
+
for (const { text, group } of notes) {
|
|
24702
|
+
if (!group) {
|
|
24703
|
+
lines.push(text);
|
|
24704
|
+
continue;
|
|
24705
|
+
}
|
|
24706
|
+
let same3 = kinds.get(group.kind);
|
|
24707
|
+
if (!same3) {
|
|
24708
|
+
same3 = { kind: group.kind, texts: [], groups: [] };
|
|
24709
|
+
kinds.set(group.kind, same3);
|
|
24710
|
+
lines.push(same3);
|
|
24711
|
+
}
|
|
24712
|
+
same3.texts.push(text);
|
|
24713
|
+
same3.groups.push(group);
|
|
24714
|
+
}
|
|
24715
|
+
return lines.map((line) => {
|
|
24716
|
+
if (typeof line === "string") return line;
|
|
24717
|
+
if (line.texts.length === 1) return line.texts[0];
|
|
24718
|
+
const shown = line.groups.slice(0, LIST.grouped).map(
|
|
24719
|
+
({ subject, route }) => route === void 0 ? subject : `${JSON.stringify(route)} at ${subject}`
|
|
24720
|
+
);
|
|
24721
|
+
const more2 = line.groups.length - shown.length;
|
|
24722
|
+
return GROUPED[line.kind](
|
|
24723
|
+
line.groups.length,
|
|
24724
|
+
`${shown.join(", ")}${more2 > 0 ? `, +${more2} more` : ""}`
|
|
24725
|
+
);
|
|
24726
|
+
});
|
|
24727
|
+
}
|
|
24639
24728
|
function testNames(names, limit2 = LIST.names) {
|
|
24640
24729
|
if (!names.length) return "";
|
|
24641
24730
|
const tests = names.filter((name) => /(?:^|\.)(?:test|Test|should|it_)\w*$/u.test(name));
|
|
@@ -24678,7 +24767,7 @@ Nothing changed against ${changes.base}.`;
|
|
|
24678
24767
|
);
|
|
24679
24768
|
if (compile.missing.length)
|
|
24680
24769
|
lines.push(
|
|
24681
|
-
`PACKAGES NOT FOUND (${compile.missing.slice(0, LIST.names).join(", ")}${compile.missing.length > LIST.names ? `, +${compile.missing.length - LIST.names} more` : ""}): are dependencies installed in this directory?
|
|
24770
|
+
`PACKAGES NOT FOUND (${compile.missing.slice(0, LIST.names).join(", ")}${compile.missing.length > LIST.names ? `, +${compile.missing.length - LIST.names} more` : ""}): are dependencies installed in this directory? Without their types, calls through them (framework page methods among them), their uses and compile errors are not seen, so this report can miss what the change reaches.`
|
|
24682
24771
|
);
|
|
24683
24772
|
if (compile.unchecked.length)
|
|
24684
24773
|
lines.push(
|
|
@@ -24752,7 +24841,26 @@ Nothing changed against ${changes.base}.`;
|
|
|
24752
24841
|
`Decide for each whether it runs the way the project's layers do: code others build on (shared types, storage, utilities) should not import the features or interfaces built on it.${impact.dependencies.some((dependency) => dependency.back) ? " A cycle ties the modules together, so neither can change or be tested alone." : ""} If one runs the wrong way, move what both need into the lower module or pass it in, rather than import upward.`
|
|
24753
24842
|
);
|
|
24754
24843
|
}
|
|
24755
|
-
const
|
|
24844
|
+
const registrations = /* @__PURE__ */ new Map();
|
|
24845
|
+
for (const { group } of impact.unclear)
|
|
24846
|
+
if (group?.route !== void 0)
|
|
24847
|
+
registrations.set(group.route, [...registrations.get(group.route) ?? [], group.subject]);
|
|
24848
|
+
const certain = impact.entries.filter((e) => e.certain).slice(0, LIST.entries);
|
|
24849
|
+
const possible = impact.entries.filter((e) => !e.certain).slice(0, LIST.entries);
|
|
24850
|
+
const marked = new Set(
|
|
24851
|
+
[...certain, ...possible].filter((item) => item.route && !item.removed && registrations.has(item.label)).map((item) => item.label)
|
|
24852
|
+
);
|
|
24853
|
+
const label = (item) => item.route ? JSON.stringify(item.label) : item.label;
|
|
24854
|
+
const entry = (item) => {
|
|
24855
|
+
const changedAt = marked.has(item.label) ? registrations.get(item.label) ?? [] : [];
|
|
24856
|
+
const registered = item.site ? `registered at ${item.site}${changedAt.includes(item.site) ? ", a line the diff changed" : ""}` : "";
|
|
24857
|
+
const elsewhere = changedAt.filter((site) => site !== item.site);
|
|
24858
|
+
const where = [
|
|
24859
|
+
...registered ? [registered] : [],
|
|
24860
|
+
...elsewhere.length ? [`its registration at ${elsewhere.join(", ")} changed`] : []
|
|
24861
|
+
];
|
|
24862
|
+
return `${label(item)}${item.chain.length ? ` \u2192 ${item.chain.join(" \u2192 ")}` : ""}${item.removed ? ` (the diff removes it${item.site ? `; registered at ${item.site} before` : ""})` : where.length ? ` (${where.join("; ")})` : ""}`;
|
|
24863
|
+
};
|
|
24756
24864
|
list(
|
|
24757
24865
|
"AFFECTED ENTRY POINTS (through resolved calls)",
|
|
24758
24866
|
impact.entries.filter((e) => e.certain).map(entry),
|
|
@@ -24763,6 +24871,11 @@ Nothing changed against ${changes.base}.`;
|
|
|
24763
24871
|
impact.entries.filter((e) => !e.certain).map(entry),
|
|
24764
24872
|
LIST.entries
|
|
24765
24873
|
);
|
|
24874
|
+
const listed = new Set([...certain, ...possible].map(entry));
|
|
24875
|
+
if (marked.size)
|
|
24876
|
+
lines.push(
|
|
24877
|
+
"Where the diff changed a route's registration, check that the route still reaches the right handler."
|
|
24878
|
+
);
|
|
24766
24879
|
if (impact.untested) {
|
|
24767
24880
|
const { changed, entries, throughRoutes, routes: routes2, missing, truncated } = impact.untested;
|
|
24768
24881
|
const items = (shown, limit2) => {
|
|
@@ -24777,7 +24890,10 @@ Nothing changed against ${changes.base}.`;
|
|
|
24777
24890
|
` ${changed.length} of ${impact.changed.length} changed declarations are reached by none of the given tests; ${entries.length ? "the entry points above them, then the declarations:" : "the declarations:"}`
|
|
24778
24891
|
);
|
|
24779
24892
|
items(
|
|
24780
|
-
entries.map((item) =>
|
|
24893
|
+
entries.map((item) => {
|
|
24894
|
+
const full = entry(item);
|
|
24895
|
+
return `${listed.has(full) ? `${label(item)} (as listed above)` : full}${item.certain ? "" : " (possibly)"}`;
|
|
24896
|
+
}),
|
|
24781
24897
|
LIST.entries
|
|
24782
24898
|
);
|
|
24783
24899
|
items(changed, LIST.changed);
|
|
@@ -24836,7 +24952,14 @@ Nothing changed against ${changes.base}.`;
|
|
|
24836
24952
|
];
|
|
24837
24953
|
list(
|
|
24838
24954
|
"CHECK BY HAND (the map cannot see these)",
|
|
24839
|
-
[
|
|
24955
|
+
[
|
|
24956
|
+
...incomplete,
|
|
24957
|
+
...uncertainLines(
|
|
24958
|
+
impact.unclear.filter(
|
|
24959
|
+
({ group }) => group?.route === void 0 || !marked.has(group.route)
|
|
24960
|
+
)
|
|
24961
|
+
)
|
|
24962
|
+
],
|
|
24840
24963
|
incomplete.length + LIST.unclear
|
|
24841
24964
|
);
|
|
24842
24965
|
if (direct.length) {
|
|
@@ -24855,7 +24978,7 @@ Nothing changed against ${changes.base}.`;
|
|
|
24855
24978
|
`RELATED TESTS: none call or import the changed code directly; ${indirect.length} test files import it through other modules, which a broader run covers.`
|
|
24856
24979
|
);
|
|
24857
24980
|
lines.push(
|
|
24858
|
-
"Static estimate:
|
|
24981
|
+
"Static estimate: dependency injection, reflection, string dispatch, configuration and the database are not followed, so an empty list does not prove the change safe."
|
|
24859
24982
|
);
|
|
24860
24983
|
if (similar.length) {
|
|
24861
24984
|
const declaration = (item) => `${item.path}: ${item.name} ${item.label}`;
|
|
@@ -24902,9 +25025,9 @@ function pathBetween(edges, from, to) {
|
|
|
24902
25025
|
if (via.has(target)) continue;
|
|
24903
25026
|
via.set(target, module);
|
|
24904
25027
|
if (target === to) {
|
|
24905
|
-
const
|
|
24906
|
-
for (let step = module; step !== from; step = via.get(step) ?? from)
|
|
24907
|
-
return [from, ...
|
|
25028
|
+
const path20 = [to];
|
|
25029
|
+
for (let step = module; step !== from; step = via.get(step) ?? from) path20.unshift(step);
|
|
25030
|
+
return [from, ...path20];
|
|
24908
25031
|
}
|
|
24909
25032
|
next.push(target);
|
|
24910
25033
|
}
|
|
@@ -24957,11 +25080,11 @@ function newModuleDependencies(store, cache, working, files, links) {
|
|
|
24957
25080
|
);
|
|
24958
25081
|
}
|
|
24959
25082
|
var MANIFEST = /(?:^|\/)(?:package\.json|go\.mod|pom\.xml|build\.gradle(?:\.kts)?|pyproject\.toml|setup\.py|setup\.cfg)$/u;
|
|
24960
|
-
var directoryOf3 = (
|
|
25083
|
+
var directoryOf3 = (path20) => path20.slice(0, Math.max(path20.lastIndexOf("/"), 0));
|
|
24961
25084
|
var directoryLabel = (directory) => directory ? `${directory}/` : "./";
|
|
24962
25085
|
function mapReuseImports(store, cache, working) {
|
|
24963
25086
|
const roots = store.listEntries(working).filter((entry) => MANIFEST.test(entry.path)).map((entry) => directoryOf3(entry.path)).sort((left, right) => right.length - left.length);
|
|
24964
|
-
const packageOf = (
|
|
25087
|
+
const packageOf = (path20) => roots.find((root) => !root || path20.startsWith(`${root}/`)) ?? "";
|
|
24965
25088
|
const directories = /* @__PURE__ */ new Map();
|
|
24966
25089
|
const packages = /* @__PURE__ */ new Map();
|
|
24967
25090
|
const files = /* @__PURE__ */ new Set();
|
|
@@ -24994,21 +25117,21 @@ function mapReuseImports(store, cache, working) {
|
|
|
24994
25117
|
};
|
|
24995
25118
|
const graph = new MapViewGraph(store, working);
|
|
24996
25119
|
const usedFrom = /* @__PURE__ */ new Map();
|
|
24997
|
-
const used = (
|
|
24998
|
-
let found = usedFrom.get(
|
|
25120
|
+
const used = (path20) => {
|
|
25121
|
+
let found = usedFrom.get(path20);
|
|
24999
25122
|
if (found === void 0) {
|
|
25000
|
-
found = graph.relationsTo(graph.objectsAt(
|
|
25001
|
-
usedFrom.set(
|
|
25123
|
+
found = graph.relationsTo(graph.objectsAt(path20).map((object2) => object2.id)).some((relation) => graph.object(relation.from).anchor.path !== path20);
|
|
25124
|
+
usedFrom.set(path20, found);
|
|
25002
25125
|
}
|
|
25003
25126
|
return found;
|
|
25004
25127
|
};
|
|
25005
|
-
return (
|
|
25006
|
-
const added = [directoryOf3(
|
|
25128
|
+
return (path20, existing) => {
|
|
25129
|
+
const added = [directoryOf3(path20), packageOf(path20)];
|
|
25007
25130
|
const old = [directoryOf3(existing), packageOf(existing)];
|
|
25008
25131
|
const ahead = use("NEW", added, old);
|
|
25009
|
-
if (files.has(`${
|
|
25010
|
-
if (files.has(`${existing}\0${
|
|
25011
|
-
return { ...use("EXISTING", old, added), from: existing, to:
|
|
25132
|
+
if (files.has(`${path20}\0${existing}`)) return ahead;
|
|
25133
|
+
if (files.has(`${existing}\0${path20}`))
|
|
25134
|
+
return { ...use("EXISTING", old, added), from: existing, to: path20 };
|
|
25012
25135
|
const usable = used(existing);
|
|
25013
25136
|
if (usable && ahead.imported) return ahead;
|
|
25014
25137
|
if (directories.get(old[0])?.has(added[0])) return use("EXISTING", old, added);
|
|
@@ -25030,9 +25153,9 @@ var KEYWORDS = new Set(
|
|
|
25030
25153
|
);
|
|
25031
25154
|
var ROWS = `SELECT entity_ref AS id, path, name, kind, object_json AS object
|
|
25032
25155
|
FROM project_map_objects WHERE version_ref = ? AND kind <> 'PROPERTY'`;
|
|
25033
|
-
function rows(store, version2,
|
|
25034
|
-
const statement = store.database.prepare(
|
|
25035
|
-
return (
|
|
25156
|
+
function rows(store, version2, path20) {
|
|
25157
|
+
const statement = store.database.prepare(path20 === void 0 ? ROWS : `${ROWS} AND path = ?`);
|
|
25158
|
+
return (path20 === void 0 ? statement.all(version2) : statement.all(version2, path20)).map((row) => {
|
|
25036
25159
|
const { anchor } = JSON.parse(String(row.object));
|
|
25037
25160
|
return {
|
|
25038
25161
|
id: String(row.id),
|
|
@@ -25074,10 +25197,10 @@ function lineWords(line) {
|
|
|
25074
25197
|
var within2 = (lines, declaration) => lines.some(([from, to]) => from <= declaration.startLine && declaration.endLine <= to);
|
|
25075
25198
|
var copyText = (code) => code.replace(/^export\s+(?:default\s+)?/u, "").replace(/\s+/gu, " ").trim();
|
|
25076
25199
|
async function similarCode(store, working, base, files, read) {
|
|
25077
|
-
const code = (
|
|
25200
|
+
const code = (path20) => mapCodePath(path20) && !mapTestPath(path20) && !MAP_MIGRATION_PATH.test(path20);
|
|
25078
25201
|
const changed = files.filter((file2) => file2.status !== "DELETED" && code(file2.path));
|
|
25079
25202
|
if (!changed.length) return [];
|
|
25080
|
-
const names = (version2,
|
|
25203
|
+
const names = (version2, path20) => new Set(declarations(rows(store, version2, path20)).map((item) => item.qualifiedName));
|
|
25081
25204
|
const movedOut = /* @__PURE__ */ new Set();
|
|
25082
25205
|
if (base !== void 0)
|
|
25083
25206
|
for (const file2 of files) {
|
|
@@ -25109,11 +25232,11 @@ async function similarCode(store, working, base, files, read) {
|
|
|
25109
25232
|
const all = [];
|
|
25110
25233
|
const shortCopies = /* @__PURE__ */ new Map();
|
|
25111
25234
|
const texts = await Promise.all(
|
|
25112
|
-
[...byPath].sort(([left], [right]) => left < right ? -1 : left > right ? 1 : 0).map(async ([
|
|
25235
|
+
[...byPath].sort(([left], [right]) => left < right ? -1 : left > right ? 1 : 0).map(async ([path20, inFile]) => {
|
|
25113
25236
|
const found2 = declarations(inFile).filter(
|
|
25114
25237
|
(item) => KINDS2.has(item.kind) && (long(item) ? longAdded : shortNames.has(item.qualifiedName))
|
|
25115
25238
|
);
|
|
25116
|
-
return { found: found2, text: found2.length ? await read(
|
|
25239
|
+
return { found: found2, text: found2.length ? await read(path20) : void 0 };
|
|
25117
25240
|
})
|
|
25118
25241
|
);
|
|
25119
25242
|
for (const { found: found2, text } of texts) {
|
|
@@ -25246,9 +25369,10 @@ async function mapChangeImpact(store, views, working, base, changes, links, shap
|
|
|
25246
25369
|
const mappedPaths = () => mapped ??= store.database.prepare("SELECT DISTINCT path FROM project_map_objects WHERE version_ref = ?").all(working).map((row) => String(row.path));
|
|
25247
25370
|
let paths;
|
|
25248
25371
|
const pathIndex = () => paths ??= mapPathIndex(mappedPaths());
|
|
25249
|
-
const topLevelChanged = (
|
|
25250
|
-
const
|
|
25251
|
-
if (!unclear.
|
|
25372
|
+
const topLevelChanged = (path20) => {
|
|
25373
|
+
const text = `top-level code of ${path20} changed (imports, constants or registrations)`;
|
|
25374
|
+
if (!unclear.some((note) => note.text === text))
|
|
25375
|
+
unclear.push({ text, group: { kind: "TOP_LEVEL", subject: path20 } });
|
|
25252
25376
|
};
|
|
25253
25377
|
for (const file2 of changes.files) {
|
|
25254
25378
|
const objects2 = file2.status === "DELETED" || file2.binary ? [] : graph.objectsAt(file2.path);
|
|
@@ -25261,9 +25385,11 @@ async function mapChangeImpact(store, views, working, base, changes, links, shap
|
|
|
25261
25385
|
const analyzed = file2.status === "DELETED" ? !file2.binary && (mapLanguageOf(file2.path) !== void 0 || template) : objects2.length > 0 && (mapLanguageOf(file2.path) !== void 0 || template && objects2.some((object2) => object2.parsing === "PARSED"));
|
|
25262
25386
|
const kind = !analyzed || MAP_MIGRATION_PATH.test(file2.path) ? unmappedKind(file2.path, file2.binary) : void 0;
|
|
25263
25387
|
if (kind) {
|
|
25264
|
-
|
|
25265
|
-
|
|
25266
|
-
|
|
25388
|
+
const deleted = file2.status === "DELETED";
|
|
25389
|
+
unclear.push({
|
|
25390
|
+
text: `${file2.path} ${deleted ? "deleted" : "changed"} (${kind}): its effects are not mapped`,
|
|
25391
|
+
group: { kind: "UNMAPPED", subject: `${file2.path}${deleted ? " deleted" : ""} (${kind})` }
|
|
25392
|
+
});
|
|
25267
25393
|
unmapped.push({ path: file2.path, kind });
|
|
25268
25394
|
}
|
|
25269
25395
|
if (!objects2.length) continue;
|
|
@@ -25281,10 +25407,13 @@ async function mapChangeImpact(store, views, working, base, changes, links, shap
|
|
|
25281
25407
|
}
|
|
25282
25408
|
for (const relation of graph.relationsFrom(objects2.map((object2) => object2.id))) {
|
|
25283
25409
|
const route = mapRegisteredRoute(relation);
|
|
25284
|
-
if (route && overlaps(file2.lines, relation.anchor.startLine, relation.anchor.endLine))
|
|
25285
|
-
|
|
25286
|
-
|
|
25287
|
-
|
|
25410
|
+
if (route && overlaps(file2.lines, relation.anchor.startLine, relation.anchor.endLine)) {
|
|
25411
|
+
const site = `${relation.anchor.path}:${relation.anchor.startLine}`;
|
|
25412
|
+
unclear.push({
|
|
25413
|
+
text: `the registration of ${JSON.stringify(route)} at ${site} changed; check that the route still reaches the right handler`,
|
|
25414
|
+
group: { kind: "REGISTRATION", subject: site, route }
|
|
25415
|
+
});
|
|
25416
|
+
}
|
|
25288
25417
|
}
|
|
25289
25418
|
if (analyzed && topLevel && file2.status !== "ADDED") topLevelChanged(file2.path);
|
|
25290
25419
|
importerTests(graph, objects2, tracer, importers);
|
|
@@ -25337,11 +25466,11 @@ async function mapChangeImpact(store, views, working, base, changes, links, shap
|
|
|
25337
25466
|
await tracer.release(climbing);
|
|
25338
25467
|
}
|
|
25339
25468
|
if (unfound.length)
|
|
25340
|
-
unclear.push(
|
|
25341
|
-
`no test is found to request ${unfound.length > 1 ? `${unfound.length} routes the change reaches (` : ""}${unfound.slice(0, LIST.names).map((label) => JSON.stringify(label)).join(
|
|
25469
|
+
unclear.push({
|
|
25470
|
+
text: `no test is found to request ${unfound.length > 1 ? `${unfound.length} routes the change reaches (` : ""}${unfound.slice(0, LIST.names).map((label) => JSON.stringify(label)).join(
|
|
25342
25471
|
", "
|
|
25343
25472
|
)}${unfound.length > LIST.names ? ", \u2026" : ""}${unfound.length > 1 ? ")" : ""}: a test requesting ${unfound.length > 1 ? "them" : "it"} in a way the map does not read is not selected`
|
|
25344
|
-
);
|
|
25473
|
+
});
|
|
25345
25474
|
if (tracer.held.size) await unworkedRequests(routeRequests(), tracer, reaching);
|
|
25346
25475
|
if (requests?.unsearched)
|
|
25347
25476
|
incomplete.push(
|
|
@@ -25349,11 +25478,11 @@ async function mapChangeImpact(store, views, working, base, changes, links, shap
|
|
|
25349
25478
|
);
|
|
25350
25479
|
const unread = [...tracer.shapes.unread];
|
|
25351
25480
|
if (unread.length)
|
|
25352
|
-
unclear.push(
|
|
25353
|
-
`who uses ${unread.length} fields or types the change reaches was not read, so what they affect is not known (${unread.slice(0, LIST.names).map((ref) => graph.qualifiedName(ref)).join(
|
|
25481
|
+
unclear.push({
|
|
25482
|
+
text: `who uses ${unread.length} fields or types the change reaches was not read, so what they affect is not known (${unread.slice(0, LIST.names).map((ref) => graph.qualifiedName(ref)).join(
|
|
25354
25483
|
", "
|
|
25355
25484
|
)}${unread.length > LIST.names ? ", \u2026" : ""}); project_find_references lists their uses`
|
|
25356
|
-
);
|
|
25485
|
+
});
|
|
25357
25486
|
const untested = tests && await untestedChanges(graph, tracer, memberCalls, starts, changed, tests);
|
|
25358
25487
|
supportTests(store, working, tracer);
|
|
25359
25488
|
const taken = base ? await mapRemovedImpact({
|
|
@@ -25368,15 +25497,15 @@ async function mapChangeImpact(store, views, working, base, changes, links, shap
|
|
|
25368
25497
|
project,
|
|
25369
25498
|
mappedPaths
|
|
25370
25499
|
}) : void 0;
|
|
25371
|
-
for (const
|
|
25500
|
+
for (const path20 of taken?.topLevel ?? []) topLevelChanged(path20);
|
|
25372
25501
|
unclear.push(...taken?.unclear ?? []);
|
|
25373
25502
|
return {
|
|
25374
25503
|
changed,
|
|
25375
25504
|
removed: taken?.removed ?? [],
|
|
25376
25505
|
rewrittenTests: taken?.rewrittenTests ?? [],
|
|
25377
25506
|
entries: [...tracer.entries.values()].sort(entryOrder),
|
|
25378
|
-
tests: [...tracer.tests].map(([
|
|
25379
|
-
path:
|
|
25507
|
+
tests: [...tracer.tests].map(([path20, test]) => ({
|
|
25508
|
+
path: path20,
|
|
25380
25509
|
names: [...test.names].sort(),
|
|
25381
25510
|
why: test.why,
|
|
25382
25511
|
rank: test.rank
|
|
@@ -25386,9 +25515,11 @@ async function mapChangeImpact(store, views, working, base, changes, links, shap
|
|
|
25386
25515
|
areas: [...tracer.areas].map(([area, known]) => ({
|
|
25387
25516
|
area,
|
|
25388
25517
|
through: [...known.through].sort(),
|
|
25389
|
-
tests: [...known.tests].map(([
|
|
25518
|
+
tests: [...known.tests].map(([path20, names]) => ({ path: path20, names: [...names].sort() })).sort((left, right) => right.names.length - left.names.length)
|
|
25390
25519
|
})).sort((left, right) => right.tests.length - left.tests.length),
|
|
25391
|
-
unclear: [
|
|
25520
|
+
unclear: [
|
|
25521
|
+
...new Map([...unclear, ...tracer.unclear].map((note) => [note.text, note])).values()
|
|
25522
|
+
],
|
|
25392
25523
|
incomplete: [
|
|
25393
25524
|
...incomplete,
|
|
25394
25525
|
...tracer.truncated ? [
|
|
@@ -25469,15 +25600,15 @@ function mapChangesData(changes, impact, edges) {
|
|
|
25469
25600
|
return {
|
|
25470
25601
|
base: changes.base,
|
|
25471
25602
|
commit: changes.commit,
|
|
25472
|
-
files: changes.files.map(({ path:
|
|
25473
|
-
path:
|
|
25474
|
-
...basePath !== void 0 && basePath !==
|
|
25603
|
+
files: changes.files.map(({ path: path20, basePath, status }) => ({
|
|
25604
|
+
path: path20,
|
|
25605
|
+
...basePath !== void 0 && basePath !== path20 ? { basePath } : {},
|
|
25475
25606
|
status
|
|
25476
25607
|
})),
|
|
25477
25608
|
tests: impact.tests,
|
|
25478
25609
|
unmapped: impact.unmapped,
|
|
25479
25610
|
incomplete: impact.incomplete,
|
|
25480
|
-
checkByHand: impact.unclear,
|
|
25611
|
+
checkByHand: impact.unclear.map(({ text }) => text),
|
|
25481
25612
|
truncated: impact.truncated,
|
|
25482
25613
|
...impact.untested ? { untested: impact.untested } : {},
|
|
25483
25614
|
edges
|
|
@@ -25485,13 +25616,23 @@ function mapChangesData(changes, impact, edges) {
|
|
|
25485
25616
|
}
|
|
25486
25617
|
async function checkMapChanges(input, signal) {
|
|
25487
25618
|
const { index, project, working } = input;
|
|
25619
|
+
const phase = input.phase ?? (() => {
|
|
25620
|
+
});
|
|
25621
|
+
const baseVersion = async (commit, then) => {
|
|
25622
|
+
phase("BASE");
|
|
25623
|
+
const version2 = await input.baseVersion(commit, signal);
|
|
25624
|
+
phase(then);
|
|
25625
|
+
return version2;
|
|
25626
|
+
};
|
|
25627
|
+
phase("DIFF");
|
|
25488
25628
|
const changes = await readMapChanges(project, input.base, signal, {
|
|
25489
25629
|
names: input.format !== "json"
|
|
25490
25630
|
});
|
|
25491
25631
|
await index.ensureIndex(working, signal);
|
|
25492
25632
|
const base = changes.files.some(
|
|
25493
25633
|
(file2) => file2.basePath !== void 0 && (file2.baseLines.length || file2.baseText !== void 0 || file2.status === "RENAMED")
|
|
25494
|
-
) ? await
|
|
25634
|
+
) ? await baseVersion(changes.commit, "TRACE") : void 0;
|
|
25635
|
+
if (!base) phase("TRACE");
|
|
25495
25636
|
const usesIn = (version2, source) => async (refs, until2) => {
|
|
25496
25637
|
const found = await index.findUses(
|
|
25497
25638
|
{ version: version2, source, refs, until: until2, maxResults: MAP_REFERENCES_MAX },
|
|
@@ -25529,6 +25670,7 @@ async function checkMapChanges(input, signal) {
|
|
|
25529
25670
|
);
|
|
25530
25671
|
const data = mapChangesData(changes, impact, mapChangeEdges(links));
|
|
25531
25672
|
if (input.format === "json") return { text: JSON.stringify(data), data };
|
|
25673
|
+
phase("REPORT");
|
|
25532
25674
|
return {
|
|
25533
25675
|
data,
|
|
25534
25676
|
text: mapChangesText(
|
|
@@ -25544,10 +25686,10 @@ async function checkMapChanges(input, signal) {
|
|
|
25544
25686
|
working,
|
|
25545
25687
|
base,
|
|
25546
25688
|
changes.files,
|
|
25547
|
-
(file2) => readFile3(
|
|
25689
|
+
(file2) => readFile3(path14.join(project, file2), "utf8").catch(() => void 0)
|
|
25548
25690
|
)
|
|
25549
25691
|
),
|
|
25550
|
-
changes.files.length ? await compileBreaks(input, views, changes, base, until, signal) : void 0
|
|
25692
|
+
changes.files.length ? await compileBreaks(input, views, changes, base, until, signal, phase, baseVersion) : void 0
|
|
25551
25693
|
)
|
|
25552
25694
|
};
|
|
25553
25695
|
}
|
|
@@ -25575,8 +25717,9 @@ async function mapRouteClients(project, store, working, impact, signal) {
|
|
|
25575
25717
|
if (!routes.length) return { routes: [] };
|
|
25576
25718
|
return routeClients(routes, registrations, git, gitOptions(project, signal));
|
|
25577
25719
|
}
|
|
25578
|
-
async function compileBreaks(input, views, changes, base, until, signal) {
|
|
25720
|
+
async function compileBreaks(input, views, changes, base, until, signal, phase, baseVersion) {
|
|
25579
25721
|
const { index, working } = input;
|
|
25722
|
+
phase("COMPILE");
|
|
25580
25723
|
const present = changes.files.filter((file2) => file2.status !== "DELETED").map((file2) => file2.path);
|
|
25581
25724
|
const gone2 = changes.files.flatMap((file2) => file2.basePath ? [file2.basePath] : []);
|
|
25582
25725
|
const after = await index.findDiagnostics(
|
|
@@ -25612,7 +25755,7 @@ async function compileBreaks(input, views, changes, base, until, signal) {
|
|
|
25612
25755
|
});
|
|
25613
25756
|
const before = onUnchanged.length && Date.now() <= until ? await index.findDiagnostics(
|
|
25614
25757
|
{
|
|
25615
|
-
version: base ?? await
|
|
25758
|
+
version: base ?? await baseVersion(changes.commit, "COMPILE"),
|
|
25616
25759
|
source: { ...input.source, kind: "COMMIT", commit: changes.commit },
|
|
25617
25760
|
configurations: onUnchanged.map(({ configPath }) => configPath),
|
|
25618
25761
|
until
|
|
@@ -25620,7 +25763,7 @@ async function compileBreaks(input, views, changes, base, until, signal) {
|
|
|
25620
25763
|
signal
|
|
25621
25764
|
) : { contexts: [], unchecked: [] };
|
|
25622
25765
|
const inBase = changedInBase(changes.files);
|
|
25623
|
-
const named = (
|
|
25766
|
+
const named = (path20, item) => `${path20}\0${item.code}\0${item.span}\0${item.text}`;
|
|
25624
25767
|
const compiled = new Map(before.contexts.map((context) => [context.configPath, context.errors]));
|
|
25625
25768
|
const unchecked = new Set(after.unchecked);
|
|
25626
25769
|
const errors = /* @__PURE__ */ new Set();
|
|
@@ -25680,7 +25823,7 @@ CREATE INDEX layermap_commit_version ON layermap_commit_versions(version_ref);
|
|
|
25680
25823
|
`;
|
|
25681
25824
|
var schemaVersion = (database) => Number(database.prepare("PRAGMA user_version").get()?.user_version ?? 0);
|
|
25682
25825
|
function openMapDatabase(file2) {
|
|
25683
|
-
mkdirSync(
|
|
25826
|
+
mkdirSync(path15.dirname(file2), { recursive: true, mode: 448 });
|
|
25684
25827
|
const database = new DatabaseSync(file2);
|
|
25685
25828
|
try {
|
|
25686
25829
|
database.exec(BUSY_TIMEOUT);
|
|
@@ -25737,7 +25880,7 @@ async function lockMapBuilds(file2, signal) {
|
|
|
25737
25880
|
throw error51;
|
|
25738
25881
|
}
|
|
25739
25882
|
}
|
|
25740
|
-
var mapDatabasePath = (cacheDirectory2, canonicalProject) =>
|
|
25883
|
+
var mapDatabasePath = (cacheDirectory2, canonicalProject) => path15.join(
|
|
25741
25884
|
cacheDirectory2,
|
|
25742
25885
|
"projects",
|
|
25743
25886
|
createHash5("sha256").update(canonicalProject).digest("hex").slice(0, 24),
|
|
@@ -25769,12 +25912,12 @@ var LayerMap = class _LayerMap {
|
|
|
25769
25912
|
closed = false;
|
|
25770
25913
|
static async open(options) {
|
|
25771
25914
|
const project = await realpath2(options.project);
|
|
25772
|
-
const
|
|
25773
|
-
if (!
|
|
25915
|
+
const stat4 = await lstat4(project, { bigint: true });
|
|
25916
|
+
if (!stat4.isDirectory()) throw new ProjectEvidenceError("PROJECT_PATH_INVALID", false);
|
|
25774
25917
|
const source = {
|
|
25775
25918
|
kind: "WORKTREE",
|
|
25776
25919
|
projectRef: `layermap:${createHash5("sha256").update(project).digest("hex").slice(0, 24)}`,
|
|
25777
|
-
directory: { canonicalPath: project, device: String(
|
|
25920
|
+
directory: { canonicalPath: project, device: String(stat4.dev), inode: String(stat4.ino) }
|
|
25778
25921
|
};
|
|
25779
25922
|
const file2 = mapDatabasePath(options.cacheDirectory, project);
|
|
25780
25923
|
const store = new CodeIndexStore(
|
|
@@ -25795,7 +25938,7 @@ var LayerMap = class _LayerMap {
|
|
|
25795
25938
|
store,
|
|
25796
25939
|
void 0,
|
|
25797
25940
|
analyzer,
|
|
25798
|
-
(signal) => lockMapBuilds(
|
|
25941
|
+
(signal) => lockMapBuilds(path15.join(path15.dirname(file2), "build.lock"), signal)
|
|
25799
25942
|
),
|
|
25800
25943
|
analyzer.id,
|
|
25801
25944
|
{ maxBytes: options.maxOutputBytes ?? 96 * 1024, envelopeBytes: 0 },
|
|
@@ -26015,8 +26158,9 @@ var LayerMap = class _LayerMap {
|
|
|
26015
26158
|
* The base commit's map is built only when the diff removes or changes lines there.
|
|
26016
26159
|
*/
|
|
26017
26160
|
checkChanges(input, signal) {
|
|
26018
|
-
return this.using(
|
|
26019
|
-
|
|
26161
|
+
return this.using(async (hold) => {
|
|
26162
|
+
input.phase?.("MAP");
|
|
26163
|
+
return checkMapChanges(
|
|
26020
26164
|
{
|
|
26021
26165
|
index: this.index,
|
|
26022
26166
|
project: this.project,
|
|
@@ -26025,11 +26169,12 @@ var LayerMap = class _LayerMap {
|
|
|
26025
26169
|
base: input.base ?? "HEAD",
|
|
26026
26170
|
baseVersion: (commit, baseSignal) => this.versionAt(commit, baseSignal, hold),
|
|
26027
26171
|
...input.tests ? { tests: input.tests } : {},
|
|
26028
|
-
...input.format ? { format: input.format } : {}
|
|
26172
|
+
...input.format ? { format: input.format } : {},
|
|
26173
|
+
...input.phase ? { phase: input.phase } : {}
|
|
26029
26174
|
},
|
|
26030
26175
|
signal
|
|
26031
|
-
)
|
|
26032
|
-
);
|
|
26176
|
+
);
|
|
26177
|
+
});
|
|
26033
26178
|
}
|
|
26034
26179
|
/**
|
|
26035
26180
|
* Builds the map of a base commit (HEAD by default) ahead of a change check, so the check after an
|
|
@@ -26052,25 +26197,25 @@ var LayerMap = class _LayerMap {
|
|
|
26052
26197
|
|
|
26053
26198
|
// src/agent/environment.ts
|
|
26054
26199
|
var packageRoot = (() => {
|
|
26055
|
-
for (let directory =
|
|
26056
|
-
const manifest =
|
|
26200
|
+
for (let directory = path16.dirname(fileURLToPath(import.meta.url)); ; ) {
|
|
26201
|
+
const manifest = path16.join(directory, "package.json");
|
|
26057
26202
|
if (existsSync6(manifest) && JSON.parse(readFileSync3(manifest, "utf8")).name === "layermap")
|
|
26058
26203
|
return directory;
|
|
26059
|
-
if (
|
|
26060
|
-
directory =
|
|
26204
|
+
if (path16.dirname(directory) === directory) throw new Error("LayerMap cannot find its package.");
|
|
26205
|
+
directory = path16.dirname(directory);
|
|
26061
26206
|
}
|
|
26062
26207
|
})();
|
|
26063
|
-
var packageVersion = async () => JSON.parse(await readFile4(
|
|
26208
|
+
var packageVersion = async () => JSON.parse(await readFile4(path16.join(packageRoot, "package.json"), "utf8")).version;
|
|
26064
26209
|
var cacheDirectory = (env = process.env) => {
|
|
26065
|
-
if (env.LAYERMAP_CACHE) return
|
|
26066
|
-
if (process.platform === "darwin") return
|
|
26210
|
+
if (env.LAYERMAP_CACHE) return path16.resolve(env.LAYERMAP_CACHE);
|
|
26211
|
+
if (process.platform === "darwin") return path16.join(homedir(), "Library", "Caches", "layermap");
|
|
26067
26212
|
if (process.platform === "win32")
|
|
26068
|
-
return
|
|
26069
|
-
env.LOCALAPPDATA ||
|
|
26213
|
+
return path16.join(
|
|
26214
|
+
env.LOCALAPPDATA || path16.join(homedir(), "AppData", "Local"),
|
|
26070
26215
|
"layermap",
|
|
26071
26216
|
"Cache"
|
|
26072
26217
|
);
|
|
26073
|
-
return
|
|
26218
|
+
return path16.join(env.XDG_CACHE_HOME || path16.join(homedir(), ".cache"), "layermap");
|
|
26074
26219
|
};
|
|
26075
26220
|
var projectDirectory = async (directory) => {
|
|
26076
26221
|
try {
|
|
@@ -26080,7 +26225,7 @@ var projectDirectory = async (directory) => {
|
|
|
26080
26225
|
});
|
|
26081
26226
|
return { directory: stdout.toString().trim(), git: true };
|
|
26082
26227
|
} catch {
|
|
26083
|
-
return { directory:
|
|
26228
|
+
return { directory: path16.resolve(directory), git: false };
|
|
26084
26229
|
}
|
|
26085
26230
|
};
|
|
26086
26231
|
var relativeTo = (directory, value) => Object.fromEntries(
|
|
@@ -26089,7 +26234,7 @@ var relativeTo = (directory, value) => Object.fromEntries(
|
|
|
26089
26234
|
Object.fromEntries(
|
|
26090
26235
|
Object.entries(resources).map(([key, field]) => [
|
|
26091
26236
|
key,
|
|
26092
|
-
key.endsWith("Path") && typeof field === "string" && field.startsWith(directory) ?
|
|
26237
|
+
key.endsWith("Path") && typeof field === "string" && field.startsWith(directory) ? path16.relative(directory, field) : field
|
|
26093
26238
|
])
|
|
26094
26239
|
)
|
|
26095
26240
|
])
|
|
@@ -26100,7 +26245,7 @@ var resolvePlaceholder = (field) => {
|
|
|
26100
26245
|
createRequire(import.meta.url).resolve("typescript/package.json")
|
|
26101
26246
|
);
|
|
26102
26247
|
const native = `@typescript/typescript-${process.platform}-${process.arch}/package.json`;
|
|
26103
|
-
return
|
|
26248
|
+
return path16.join(path16.dirname(compiler.resolve(native)), "lib", executableName("tsc"));
|
|
26104
26249
|
}
|
|
26105
26250
|
const resolved = field.replaceAll("{platform}", process.platform).replaceAll("{arch}", process.arch);
|
|
26106
26251
|
return field.includes("{platform}") ? executableName(resolved) : resolved;
|
|
@@ -26112,42 +26257,42 @@ var absoluteIn = (directory, value) => Object.fromEntries(
|
|
|
26112
26257
|
Object.entries(resources).map(([key, field]) => {
|
|
26113
26258
|
if (!key.endsWith("Path") || typeof field !== "string") return [key, field];
|
|
26114
26259
|
const resolved = resolvePlaceholder(field);
|
|
26115
|
-
return [key,
|
|
26260
|
+
return [key, path16.isAbsolute(resolved) ? resolved : path16.join(directory, resolved)];
|
|
26116
26261
|
})
|
|
26117
26262
|
)
|
|
26118
26263
|
])
|
|
26119
26264
|
);
|
|
26120
26265
|
var readAnalyzers = async (directory) => {
|
|
26121
|
-
const file2 =
|
|
26266
|
+
const file2 = path16.join(directory, "analyzers.json");
|
|
26122
26267
|
if (!existsSync6(file2)) return void 0;
|
|
26123
26268
|
const analyzers = absoluteIn(directory, JSON.parse(await readFile4(file2, "utf8")));
|
|
26124
26269
|
return analyzers.java.runtimePath ? analyzers : { ...analyzers, java: { ...analyzers.java, ...discoverJavaRuntime() } };
|
|
26125
26270
|
};
|
|
26126
26271
|
var sourceDigest = async () => {
|
|
26127
|
-
const hash2 = createHash6("sha256").update(await readFile4(
|
|
26272
|
+
const hash2 = createHash6("sha256").update(await readFile4(path16.join(packageRoot, "package.json")));
|
|
26128
26273
|
for (const part of ["src", "go-map", "java-map", "scripts"]) {
|
|
26129
|
-
const directory =
|
|
26274
|
+
const directory = path16.join(packageRoot, part);
|
|
26130
26275
|
if (!existsSync6(directory)) continue;
|
|
26131
26276
|
for (const entry of (await readdir(directory, { recursive: true })).sort()) {
|
|
26132
|
-
const file2 =
|
|
26133
|
-
const info = await
|
|
26277
|
+
const file2 = path16.join(directory, entry);
|
|
26278
|
+
const info = await stat2(file2);
|
|
26134
26279
|
if (info.isFile()) hash2.update(`${part}/${entry}\0${info.size}\0${info.mtimeMs}\0`);
|
|
26135
26280
|
}
|
|
26136
26281
|
}
|
|
26137
26282
|
return hash2.digest("hex").slice(0, 16);
|
|
26138
26283
|
};
|
|
26139
26284
|
async function resolveAnalyzers(cache, log2, env = process.env) {
|
|
26140
|
-
for (const directory2 of [env.LAYERMAP_ANALYZERS,
|
|
26141
|
-
const analyzers = directory2 && await readAnalyzers(
|
|
26285
|
+
for (const directory2 of [env.LAYERMAP_ANALYZERS, path16.join(packageRoot, "analyzers")]) {
|
|
26286
|
+
const analyzers = directory2 && await readAnalyzers(path16.resolve(directory2));
|
|
26142
26287
|
if (analyzers) return analyzers;
|
|
26143
26288
|
}
|
|
26144
|
-
const directory =
|
|
26289
|
+
const directory = path16.join(cache, "analyzers", await sourceDigest());
|
|
26145
26290
|
const built = await readAnalyzers(directory);
|
|
26146
26291
|
if (built) return built;
|
|
26147
26292
|
log2("Building the language analyzers (once per LayerMap version)...");
|
|
26148
26293
|
const staging = `${directory}.${process.pid}`;
|
|
26149
26294
|
await rm(staging, { recursive: true, force: true });
|
|
26150
|
-
await
|
|
26295
|
+
await mkdir2(staging, { recursive: true, mode: 448 });
|
|
26151
26296
|
const builder = new URL("../../scripts/build.mjs", import.meta.url).href;
|
|
26152
26297
|
const { buildProjectMapParser } = await import(builder);
|
|
26153
26298
|
const parser = await buildProjectMapParser(staging);
|
|
@@ -26157,81 +26302,81 @@ async function resolveAnalyzers(cache, log2, env = process.env) {
|
|
|
26157
26302
|
python: parser.pythonResources,
|
|
26158
26303
|
java: parser.javaResources
|
|
26159
26304
|
});
|
|
26160
|
-
await writeFile(
|
|
26305
|
+
await writeFile(path16.join(staging, "analyzers.json"), `${JSON.stringify(stored, null, 2)}
|
|
26161
26306
|
`);
|
|
26162
|
-
await
|
|
26307
|
+
await rename2(staging, directory).catch(() => rm(staging, { recursive: true, force: true }));
|
|
26163
26308
|
return await readAnalyzers(directory);
|
|
26164
26309
|
}
|
|
26165
26310
|
var DAY = 24 * 60 * 60 * 1e3;
|
|
26166
26311
|
async function pruneCache(cache, project, now = Date.now(), installed = packageRoot, env = process.env) {
|
|
26167
|
-
const used =
|
|
26168
|
-
await
|
|
26312
|
+
const used = path16.join(path16.dirname(mapDatabasePath(cache, project)), "last-used");
|
|
26313
|
+
await mkdir2(path16.dirname(used), { recursive: true, mode: 448 });
|
|
26169
26314
|
await writeFile(used, project);
|
|
26170
26315
|
await utimes(used, now / 1e3, now / 1e3);
|
|
26171
|
-
const projects =
|
|
26316
|
+
const projects = path16.join(cache, "projects");
|
|
26172
26317
|
for (const name of await readdir(projects).catch(() => [])) {
|
|
26173
|
-
const directory =
|
|
26174
|
-
const marker =
|
|
26175
|
-
const last = (await
|
|
26318
|
+
const directory = path16.join(projects, name);
|
|
26319
|
+
const marker = path16.join(directory, "last-used");
|
|
26320
|
+
const last = (await stat2(existsSync6(marker) ? marker : directory).catch(() => void 0))?.mtimeMs;
|
|
26176
26321
|
const owner = await readFile4(marker, "utf8").catch(() => "");
|
|
26177
26322
|
if (last !== void 0 && now - last > 30 * DAY || owner !== "" && await gone(owner))
|
|
26178
26323
|
await rm(directory, { recursive: true, force: true });
|
|
26179
26324
|
}
|
|
26180
|
-
const builds =
|
|
26325
|
+
const builds = path16.join(cache, "analyzers");
|
|
26181
26326
|
const current = await sourceDigest();
|
|
26182
26327
|
for (const name of await readdir(builds).catch(() => [])) {
|
|
26183
26328
|
if (name === current) continue;
|
|
26184
|
-
const built = (await
|
|
26329
|
+
const built = (await stat2(path16.join(builds, name)).catch(() => void 0))?.mtimeMs;
|
|
26185
26330
|
if (built !== void 0 && now - built > (name.includes(".") ? DAY / 24 : DAY))
|
|
26186
|
-
await rm(
|
|
26331
|
+
await rm(path16.join(builds, name), { recursive: true, force: true });
|
|
26187
26332
|
}
|
|
26188
|
-
const own =
|
|
26189
|
-
const versions =
|
|
26190
|
-
const launched =
|
|
26333
|
+
const own = path16.dirname(path16.dirname(installed));
|
|
26334
|
+
const versions = path16.join(cache, "versions");
|
|
26335
|
+
const launched = path16.dirname(own) === versions;
|
|
26191
26336
|
if (launched) await pruneVersions(versions, own, now);
|
|
26192
|
-
const npx = launched ?
|
|
26193
|
-
env.npm_config_cache || (process.platform === "win32" ?
|
|
26337
|
+
const npx = launched ? path16.join(
|
|
26338
|
+
env.npm_config_cache || (process.platform === "win32" ? path16.join(env.LOCALAPPDATA || path16.join(homedir(), "AppData", "Local"), "npm-cache") : path16.join(homedir(), ".npm")),
|
|
26194
26339
|
"_npx"
|
|
26195
|
-
) :
|
|
26196
|
-
if (
|
|
26340
|
+
) : path16.dirname(own);
|
|
26341
|
+
if (path16.basename(path16.dirname(installed)) === "node_modules" && path16.basename(npx) === "_npx")
|
|
26197
26342
|
await pruneNpxInstalls(npx, installed, now);
|
|
26198
26343
|
}
|
|
26199
|
-
var gone = (directory) =>
|
|
26344
|
+
var gone = (directory) => stat2(directory).then(
|
|
26200
26345
|
() => false,
|
|
26201
26346
|
(error51) => error51.code === "ENOENT"
|
|
26202
26347
|
);
|
|
26203
26348
|
async function pruneVersions(versions, own, now) {
|
|
26204
|
-
const used =
|
|
26349
|
+
const used = path16.join(own, "last-used");
|
|
26205
26350
|
await writeFile(used, "");
|
|
26206
26351
|
await utimes(used, now / 1e3, now / 1e3);
|
|
26207
26352
|
for (const name of await readdir(versions).catch(() => [])) {
|
|
26208
|
-
const directory =
|
|
26209
|
-
const marker =
|
|
26210
|
-
const last = (await
|
|
26353
|
+
const directory = path16.join(versions, name);
|
|
26354
|
+
const marker = path16.join(directory, "last-used");
|
|
26355
|
+
const last = (await stat2(existsSync6(marker) ? marker : directory).catch(() => void 0))?.mtimeMs;
|
|
26211
26356
|
if (last !== void 0 && now - last > (name.startsWith(".") ? DAY / 24 : 7 * DAY))
|
|
26212
26357
|
await rm(directory, { recursive: true, force: true });
|
|
26213
26358
|
}
|
|
26214
26359
|
}
|
|
26215
26360
|
async function pruneNpxInstalls(npx, installed, now) {
|
|
26216
|
-
const own =
|
|
26361
|
+
const own = path16.dirname(path16.dirname(installed));
|
|
26217
26362
|
const manifest = async (file2) => JSON.parse(await readFile4(file2, "utf8").catch(() => "{}"));
|
|
26218
26363
|
const parts = (version2) => version2?.split(".").map(Number) ?? [];
|
|
26219
|
-
const current = parts((await manifest(
|
|
26364
|
+
const current = parts((await manifest(path16.join(installed, "package.json"))).version);
|
|
26220
26365
|
const older = (version2) => {
|
|
26221
26366
|
for (let index = 0; index < 3; index++)
|
|
26222
26367
|
if (version2[index] !== current[index]) return (version2[index] ?? 0) < (current[index] ?? 0);
|
|
26223
26368
|
return false;
|
|
26224
26369
|
};
|
|
26225
26370
|
for (const name of await readdir(npx).catch(() => [])) {
|
|
26226
|
-
const directory =
|
|
26371
|
+
const directory = path16.join(npx, name);
|
|
26227
26372
|
if (directory === own) continue;
|
|
26228
|
-
const requested = (await manifest(
|
|
26373
|
+
const requested = (await manifest(path16.join(directory, "package.json"))).dependencies ?? {};
|
|
26229
26374
|
if (Object.keys(requested).join() !== "layermap") continue;
|
|
26230
26375
|
const version2 = parts(
|
|
26231
|
-
(await manifest(
|
|
26376
|
+
(await manifest(path16.join(directory, "node_modules", "layermap", "package.json"))).version
|
|
26232
26377
|
);
|
|
26233
26378
|
if (version2.length !== 3 || version2.some(Number.isNaN) || !older(version2)) continue;
|
|
26234
|
-
const at = (await
|
|
26379
|
+
const at = (await stat2(directory).catch(() => void 0))?.mtimeMs;
|
|
26235
26380
|
if (at !== void 0 && now - at > 7 * DAY)
|
|
26236
26381
|
await rm(directory, { recursive: true, force: true });
|
|
26237
26382
|
}
|
|
@@ -26242,15 +26387,6 @@ import { createInterface } from "node:readline";
|
|
|
26242
26387
|
import { setTimeout as delay2 } from "node:timers/promises";
|
|
26243
26388
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
26244
26389
|
|
|
26245
|
-
// src/agent/notes.ts
|
|
26246
|
-
var AGENT_MAP_NOTE = "The layermap MCP server is available here. When a task needs to know what calls a function, what a change could affect beyond the code you are editing, or where code is used, use its project_explore_map tool (direction INCOMING, depth up to 8) instead of grep, then confirm in source; a change confined to code you have read does not need it. When the edits are done, call its project_check_changes tool once before reporting the work done.";
|
|
26247
|
-
var projectHeading = (project) => `Project ${project} (paths are relative to it)`;
|
|
26248
|
-
|
|
26249
|
-
// src/agent/projects.ts
|
|
26250
|
-
import { existsSync as existsSync7 } from "node:fs";
|
|
26251
|
-
import { readdir as readdir2, realpath as realpath3, stat as stat2 } from "node:fs/promises";
|
|
26252
|
-
import path16 from "node:path";
|
|
26253
|
-
|
|
26254
26390
|
// src/tools.ts
|
|
26255
26391
|
var AGENT_MAP_TOOL_HOST = Object.freeze({
|
|
26256
26392
|
readResult: "read its line range in the file",
|
|
@@ -26273,7 +26409,7 @@ var MAP_TOOL_NAMES = Object.freeze({
|
|
|
26273
26409
|
references: "project_find_references",
|
|
26274
26410
|
check: "project_check_changes"
|
|
26275
26411
|
});
|
|
26276
|
-
var mapDirectoryPath = (
|
|
26412
|
+
var mapDirectoryPath = (path20) => path20.length > 1 && path20.endsWith("/") && !path20.endsWith("//") ? path20.slice(0, -1) : path20;
|
|
26277
26413
|
var ProjectMapSearchInputSchema = external_exports.object({
|
|
26278
26414
|
path: external_exports.string().default("."),
|
|
26279
26415
|
query: external_exports.string().min(1).max(256),
|
|
@@ -26313,69 +26449,75 @@ var locatorSchema = MapObjectLocatorSchema.describe(
|
|
|
26313
26449
|
"Declaration location: path and UTF-16 start offset; include kind to distinguish declarations at the same offset."
|
|
26314
26450
|
);
|
|
26315
26451
|
var mapReferencesInputSchema = (host) => external_exports.object({
|
|
26316
|
-
|
|
26317
|
-
|
|
26318
|
-
),
|
|
26452
|
+
path: external_exports.string().min(1).optional().describe("The file declaring it, as for project_explore_map."),
|
|
26453
|
+
name: MapSymbolSelectorSchema.shape.name.optional().describe("Declaration name or Container.member in the file, as printed by the map."),
|
|
26454
|
+
line: MapSymbolSelectorSchema.shape.line.describe("Start line of a same-named declaration."),
|
|
26319
26455
|
entityRef: external_exports.string().min(1).max(128).optional(),
|
|
26320
26456
|
locator: locatorSchema.optional(),
|
|
26321
|
-
|
|
26322
|
-
`
|
|
26457
|
+
within: external_exports.string().default(".").describe(
|
|
26458
|
+
`Only usages in this file or directory; compiler inputs and declarations may lie elsewhere in the ${host.scope}.`
|
|
26323
26459
|
),
|
|
26324
26460
|
kinds: external_exports.array(MapReferenceKindSchema).min(1).max(MapReferenceKindSchema.options.length).optional(),
|
|
26325
26461
|
maxResults: external_exports.number().int().min(1).max(200).default(20),
|
|
26326
26462
|
cursor: external_exports.string().max(2048).optional()
|
|
26327
26463
|
}).strict().refine(
|
|
26328
|
-
(input) => [input.
|
|
26329
|
-
"
|
|
26464
|
+
(input) => [input.name, input.entityRef, input.locator].filter((value) => value !== void 0).length === 1 && input.name === void 0 === (input.path === void 0 && input.line === void 0),
|
|
26465
|
+
"Select the declaration with path and name (and line when names repeat), as for project_explore_map, or with an entityRef or locator alone."
|
|
26330
26466
|
);
|
|
26331
26467
|
var mapToolDescriptions = (host) => {
|
|
26332
26468
|
const lead = (tool) => host.lead?.[tool] ? `${host.lead[tool]} ` : "";
|
|
26333
26469
|
return Object.freeze({
|
|
26334
26470
|
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.`,
|
|
26335
26471
|
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.`,
|
|
26336
|
-
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, and the code using a field or type, up to 8 levels. It reports, conclusion first: AFFECTED ENTRY POINTS reached through resolved calls, each route with its HTTP methods and full path
|
|
26337
|
-
references: `${lead("references")}Compute usages of a mapped declaration from current source, including aliases, re-exports and non-call references. Select it with
|
|
26472
|
+
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, and the code using a field or type, up to 8 levels. It reports, conclusion first: AFFECTED ENTRY POINTS reached through resolved calls, each route with its HTTP methods and full path, the chain to the change and whether the diff changed its registration; POSSIBLY AFFECTED ones reached only through a call on an interface or base member, or through code that uses a changed field or type; REQUESTED BY, the code and templates outside the tests that request the path of a route whose handler the change reaches or a route it removed, found by text; 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; NEW MODULE DEPENDENCIES, imports between the modules of the project overview that the base did not have, and those that make two modules depend on each other, for you to judge against the project's layers; NEW COMPILE ERRORS, what the compiler reports on lines the diff left unchanged and did not report before, in code a tsconfig covers; PACKAGES NOT FOUND, packages the changed code needs that are not installed in this directory, whose types the trace then lacks; EXISTING CODE LIKE THE NEW CODE, declarations the diff adds whose code reads almost the same as code the project already has; LEFT WITHOUT CALLERS, declarations whose last callers outside the tests the diff removed or changed, and that nothing extends, implements, overrides or wires with a decorator; CHECK BY HAND for what a static map cannot follow (changed configuration, templates, migrations or dependency files, changed registrations of routes not listed above, declarations with no callers, calls by name on receivers of unknown type); and RELATED TESTS, closest first, the existing test files the diff changed, that call or use the changed code, request a route it reaches, may request one through a path the map does not work out, spell out a stretch of such a route's path in their text, may call it through a receiver of unknown type or through a test support file beside or above them, import a changed file, are named for its module or sit beside it; given tests, NOT REACHED BY THE GIVEN TESTS, the changed declarations none of them calls or requests through a route, or uses when it is a field or type, with the entry points above them, the other tests of the project that run them, and those the given tests may run through a request whose path the map does not work out. 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; a new dependency that runs against the layers or closes a cycle means moving what both modules need down rather than importing upward; new code like existing code means using the existing code, removing the old if the new replaces it, or having the existing code use the new where it is the one that can, unless the two are meant to differ, and changing existing code only where it is part of the task while telling the user of the rest; code left without callers means deleting it, with the tests that only test it, when the change replaced it; 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.`,
|
|
26473
|
+
references: `${lead("references")}Compute usages of a mapped declaration from current source, including aliases, re-exports and non-call references. Select it as project_explore_map does, with path (its file) and name as printed by project_explore_map or project_search_map, and line (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. within 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.`
|
|
26338
26474
|
});
|
|
26339
26475
|
};
|
|
26340
26476
|
|
|
26477
|
+
// src/agent/notes.ts
|
|
26478
|
+
var AGENT_MAP_NOTE = "The layermap MCP server is available here. When a task needs to know what calls a function, what a change could affect beyond the code you are editing, or where code is used, use its project_explore_map tool (direction INCOMING, depth up to 8) instead of grep, then confirm in source; a change confined to code you have read does not need it. When the edits are done, call its project_check_changes tool once before reporting the work done.";
|
|
26479
|
+
var projectHeading = (project) => `Project ${project} (paths are relative to it)`;
|
|
26480
|
+
|
|
26341
26481
|
// src/agent/projects.ts
|
|
26482
|
+
import { existsSync as existsSync7 } from "node:fs";
|
|
26483
|
+
import { readdir as readdir2, realpath as realpath3, stat as stat3 } from "node:fs/promises";
|
|
26484
|
+
import path17 from "node:path";
|
|
26342
26485
|
var escapes = (relative) => {
|
|
26343
|
-
const normal =
|
|
26344
|
-
return normal === ".." || normal.startsWith(`..${
|
|
26486
|
+
const normal = path17.normalize(relative);
|
|
26487
|
+
return normal === ".." || normal.startsWith(`..${path17.sep}`);
|
|
26345
26488
|
};
|
|
26346
26489
|
async function locate(start, given) {
|
|
26347
|
-
if (start.git && !
|
|
26490
|
+
if (start.git && !path17.isAbsolute(given) && !escapes(given))
|
|
26348
26491
|
return { project: start.directory, path: given };
|
|
26349
|
-
const absolute =
|
|
26492
|
+
const absolute = path17.resolve(start.directory, given);
|
|
26350
26493
|
let directory = absolute;
|
|
26351
|
-
while (!(await
|
|
26352
|
-
if (
|
|
26353
|
-
directory =
|
|
26494
|
+
while (!(await stat3(directory).catch(() => void 0))?.isDirectory()) {
|
|
26495
|
+
if (path17.dirname(directory) === directory) return void 0;
|
|
26496
|
+
directory = path17.dirname(directory);
|
|
26354
26497
|
}
|
|
26355
|
-
const real =
|
|
26498
|
+
const real = path17.join(await realpath3(directory), path17.relative(directory, absolute));
|
|
26356
26499
|
const { directory: project, git: git2 } = await projectDirectory(directory);
|
|
26357
26500
|
if (!git2) return void 0;
|
|
26358
|
-
const relative =
|
|
26501
|
+
const relative = path17.relative(project, real);
|
|
26359
26502
|
if (escapes(relative)) return void 0;
|
|
26360
|
-
return { project, path: relative ? relative.split(
|
|
26503
|
+
return { project, path: relative ? relative.split(path17.sep).join("/") : "." };
|
|
26361
26504
|
}
|
|
26362
26505
|
async function repositoriesIn(directory) {
|
|
26363
26506
|
const entries = await readdir2(directory, { withFileTypes: true }).catch(() => []);
|
|
26364
|
-
return entries.filter((entry) => entry.isDirectory() && existsSync7(
|
|
26507
|
+
return entries.filter((entry) => entry.isDirectory() && existsSync7(path17.join(directory, entry.name, ".git"))).map((entry) => `${entry.name}/`).sort();
|
|
26365
26508
|
}
|
|
26366
26509
|
async function routeMapCall(start, { name, args }) {
|
|
26367
|
-
const
|
|
26368
|
-
|
|
26369
|
-
);
|
|
26370
|
-
const value = holder ? args[holder].path : args.path;
|
|
26510
|
+
const references = name === MAP_TOOL_NAMES.references;
|
|
26511
|
+
const locator = references ? args.locator : void 0;
|
|
26512
|
+
const value = locator?.path ?? args.path ?? (references && args.within !== "." ? args.within : void 0);
|
|
26371
26513
|
const named = value || ".";
|
|
26372
26514
|
const located = await locate(start, named);
|
|
26373
26515
|
if (!located) {
|
|
26374
26516
|
const repositories = start.git ? [] : await repositoriesIn(start.directory);
|
|
26375
26517
|
const such = repositories.length ? `, such as ${repositories.join(", ")}` : "";
|
|
26376
|
-
return named === "." ? `LAYERMAP_NOT_A_GIT_REPOSITORY: This session started in ${start.directory}, which is not in a Git repository. Name a file or directory in one, relative to that folder or absolute${such}.` : `LAYERMAP_NOT_A_GIT_REPOSITORY: ${
|
|
26518
|
+
return named === "." ? `LAYERMAP_NOT_A_GIT_REPOSITORY: This session started in ${start.directory}, which is not in a Git repository. Name a file or directory in one, relative to that folder or absolute${such}.` : `LAYERMAP_NOT_A_GIT_REPOSITORY: ${path17.resolve(start.directory, named)} is not in a Git repository; LayerMap maps Git repositories${start.git ? "" : `. Name a file or directory in one, relative to ${start.directory} or absolute${such}`}.`;
|
|
26377
26519
|
}
|
|
26378
|
-
if (!
|
|
26520
|
+
if (!references) {
|
|
26379
26521
|
const routed2 = value === void 0 ? args : { ...args, path: located.path };
|
|
26380
26522
|
if (!Array.isArray(args.tests)) return { project: located.project, args: routed2 };
|
|
26381
26523
|
const tests = [];
|
|
@@ -26387,16 +26529,13 @@ async function routeMapCall(start, { name, args }) {
|
|
|
26387
26529
|
}
|
|
26388
26530
|
return { project: located.project, args: { ...routed2, tests } };
|
|
26389
26531
|
}
|
|
26390
|
-
const routed = {
|
|
26391
|
-
|
|
26392
|
-
[holder]: { ...args[holder], path: located.path }
|
|
26393
|
-
};
|
|
26394
|
-
const filter = args.path;
|
|
26532
|
+
const routed = locator ? { ...args, locator: { ...locator, path: located.path } } : args.path !== void 0 ? { ...args, path: located.path } : args;
|
|
26533
|
+
const filter = args.within;
|
|
26395
26534
|
if (filter === ".") return { project: located.project, args: routed };
|
|
26396
26535
|
const within3 = await locate(start, filter);
|
|
26397
26536
|
if (within3?.project !== located.project)
|
|
26398
|
-
return `PROJECT_PATH_INVALID:
|
|
26399
|
-
return { project: located.project, args: { ...routed,
|
|
26537
|
+
return `PROJECT_PATH_INVALID: within ${filter} is not in ${located.project}, the repository of the declaration.`;
|
|
26538
|
+
return { project: located.project, args: { ...routed, within: within3.path } };
|
|
26400
26539
|
}
|
|
26401
26540
|
|
|
26402
26541
|
// src/agent/tools.ts
|
|
@@ -26435,7 +26574,7 @@ var more = (nextOffset) => nextOffset === void 0 ? "" : `
|
|
|
26435
26574
|
|
|
26436
26575
|
[More entries: call again with offset ${nextOffset} and otherwise the same arguments.]`;
|
|
26437
26576
|
var HINTS = {
|
|
26438
|
-
PROJECT_MAP_OBJECT_NOT_FOUND:
|
|
26577
|
+
PROJECT_MAP_OBJECT_NOT_FOUND: 'No such path or declaration in the map. path names a file or directory, and name a declaration in it (as {path: "src/a.ts", name: "run"}); explore the parent directory or the file to see what it contains.',
|
|
26439
26578
|
PROJECT_FILE_CHANGED: "Files kept changing while the map was updating. Call again.",
|
|
26440
26579
|
PROJECT_FILE_UNIVERSE_CHANGED: "Files kept changing while the map was updating. Call again.",
|
|
26441
26580
|
PROJECT_READ_SOURCE_CHANGED: "Files kept changing while the map was updating. Call again.",
|
|
@@ -26451,18 +26590,23 @@ var HINTS = {
|
|
|
26451
26590
|
LAYERMAP_NOT_A_GIT_REPOSITORY: "LayerMap maps Git repositories. Run it in one, or name one with --project."
|
|
26452
26591
|
};
|
|
26453
26592
|
var describeMapError = (error51) => error51 instanceof ProjectEvidenceError ? `${error51.code}${HINTS[error51.code] ? `: ${HINTS[error51.code]}` : ""}` : void 0;
|
|
26593
|
+
var EXAMPLES = {
|
|
26594
|
+
[MAP_TOOL_NAMES.explore]: '{"path": "src/billing/tax.ts", "name": "calculateTax", "direction": "INCOMING", "depth": 8}',
|
|
26595
|
+
[MAP_TOOL_NAMES.references]: '{"path": "src/billing/tax.ts", "name": "calculateTax"}',
|
|
26596
|
+
[MAP_TOOL_NAMES.search]: '{"query": "tax"}'
|
|
26597
|
+
};
|
|
26454
26598
|
function parseMapToolCall(name, args) {
|
|
26455
26599
|
const tool = agentMapTools.find((candidate) => candidate.name === name);
|
|
26456
26600
|
if (!tool) return { text: `Unknown tool ${name}.`, isError: true };
|
|
26457
26601
|
const parsed = tool.schema.safeParse(args ?? {});
|
|
26458
26602
|
if (!parsed.success)
|
|
26459
26603
|
return {
|
|
26460
|
-
text: `Invalid arguments: ${parsed.error.issues.map((issue2) => `${issue2.path.join(".") || "(arguments)"}: ${issue2.message}`).join("; ")}`,
|
|
26604
|
+
text: `Invalid arguments: ${parsed.error.issues.map((issue2) => `${issue2.path.join(".") || "(arguments)"}: ${issue2.message}`).join("; ")}${EXAMPLES[name] ? `. For example: ${EXAMPLES[name]}` : ""}`,
|
|
26461
26605
|
isError: true
|
|
26462
26606
|
};
|
|
26463
26607
|
return { name, args: parsed.data };
|
|
26464
26608
|
}
|
|
26465
|
-
async function runMapTool(map2, { name, args }, signal) {
|
|
26609
|
+
async function runMapTool(map2, { name, args }, signal, phase) {
|
|
26466
26610
|
try {
|
|
26467
26611
|
if (name === MAP_TOOL_NAMES.explore) {
|
|
26468
26612
|
const input2 = args;
|
|
@@ -26485,7 +26629,11 @@ async function runMapTool(map2, { name, args }, signal) {
|
|
|
26485
26629
|
const input2 = args;
|
|
26486
26630
|
return {
|
|
26487
26631
|
text: (await map2.checkChanges(
|
|
26488
|
-
{
|
|
26632
|
+
{
|
|
26633
|
+
base: input2.base,
|
|
26634
|
+
...input2.tests ? { tests: input2.tests } : {},
|
|
26635
|
+
...phase ? { phase } : {}
|
|
26636
|
+
},
|
|
26489
26637
|
signal
|
|
26490
26638
|
)).text,
|
|
26491
26639
|
isError: false
|
|
@@ -26508,6 +26656,17 @@ var AGENT_MAP_INSTRUCTIONS = `Use the LayerMap tools instead of grep whenever a
|
|
|
26508
26656
|
|
|
26509
26657
|
// src/agent/mcp.ts
|
|
26510
26658
|
var ROOTS_WAIT_MS = 5e3;
|
|
26659
|
+
var PROGRESS_EVERY_MS = 15e3;
|
|
26660
|
+
var PHASE_TEXT = {
|
|
26661
|
+
WAIT: "Waiting for the first build of the project's map",
|
|
26662
|
+
READ: "Reading the map",
|
|
26663
|
+
MAP: "Updating the map of the working tree",
|
|
26664
|
+
DIFF: "Reading the diff",
|
|
26665
|
+
BASE: "Building the map of the base commit",
|
|
26666
|
+
TRACE: "Tracing what the change reaches",
|
|
26667
|
+
REPORT: "Finding the code the report names",
|
|
26668
|
+
COMPILE: "Compiling the changed code"
|
|
26669
|
+
};
|
|
26511
26670
|
function serveMcp(options) {
|
|
26512
26671
|
const output = options.output ?? process.stdout;
|
|
26513
26672
|
const log2 = options.log ?? ((line) => process.stderr.write(`${line}
|
|
@@ -26562,20 +26721,72 @@ function serveMcp(options) {
|
|
|
26562
26721
|
calls.set(id2, controller);
|
|
26563
26722
|
const name = String(params.name);
|
|
26564
26723
|
let project;
|
|
26565
|
-
const
|
|
26566
|
-
|
|
26567
|
-
|
|
26568
|
-
|
|
26569
|
-
|
|
26570
|
-
|
|
26571
|
-
|
|
26724
|
+
const token = params._meta?.progressToken;
|
|
26725
|
+
const started = performance.now();
|
|
26726
|
+
const phases = {};
|
|
26727
|
+
let current = "WAIT";
|
|
26728
|
+
let since = started;
|
|
26729
|
+
let progress = 0;
|
|
26730
|
+
const notify = (message) => {
|
|
26731
|
+
if (typeof token !== "string" && typeof token !== "number") return;
|
|
26732
|
+
send({
|
|
26733
|
+
method: "notifications/progress",
|
|
26734
|
+
params: { progressToken: token, progress: ++progress, message }
|
|
26735
|
+
});
|
|
26736
|
+
};
|
|
26737
|
+
const tally = () => {
|
|
26738
|
+
const now = performance.now();
|
|
26739
|
+
phases[current] = (phases[current] ?? 0) + now - since;
|
|
26740
|
+
since = now;
|
|
26741
|
+
};
|
|
26742
|
+
const enter = (next) => {
|
|
26743
|
+
tally();
|
|
26744
|
+
current = next;
|
|
26745
|
+
notify(PHASE_TEXT[next]);
|
|
26746
|
+
};
|
|
26747
|
+
const beat = setInterval(
|
|
26748
|
+
() => notify(
|
|
26749
|
+
`${PHASE_TEXT[current]} (${Math.round((performance.now() - started) / 1e3)} s so far)`
|
|
26750
|
+
),
|
|
26751
|
+
PROGRESS_EVERY_MS
|
|
26752
|
+
);
|
|
26753
|
+
let answered = false;
|
|
26754
|
+
const finish = (text, isError, cancelled) => {
|
|
26755
|
+
tally();
|
|
26756
|
+
void options.record?.({
|
|
26757
|
+
at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
26758
|
+
version: options.version,
|
|
26759
|
+
tool: name,
|
|
26760
|
+
...project ? { project } : {},
|
|
26761
|
+
...params.arguments === void 0 ? {} : { arguments: params.arguments },
|
|
26762
|
+
ms: Math.round(performance.now() - started),
|
|
26763
|
+
phases: Object.fromEntries(
|
|
26764
|
+
Object.entries(phases).map(([phase, ms]) => [phase, Math.round(ms)])
|
|
26765
|
+
),
|
|
26766
|
+
chars: text.length,
|
|
26767
|
+
head: text.split("\n", 1)[0]?.slice(0, 300) ?? "",
|
|
26768
|
+
isError,
|
|
26769
|
+
...cancelled ? { cancelled } : {}
|
|
26770
|
+
});
|
|
26771
|
+
};
|
|
26772
|
+
const respond = (text, isError) => {
|
|
26773
|
+
answered = true;
|
|
26774
|
+
finish(text, isError, false);
|
|
26775
|
+
send({
|
|
26776
|
+
id: id2,
|
|
26777
|
+
result: {
|
|
26778
|
+
content: [
|
|
26779
|
+
{
|
|
26780
|
+
type: "text",
|
|
26781
|
+
text: project ? `${projectHeading(project)}
|
|
26572
26782
|
|
|
26573
26783
|
${text}` : text
|
|
26574
|
-
|
|
26575
|
-
|
|
26576
|
-
|
|
26577
|
-
|
|
26578
|
-
|
|
26784
|
+
}
|
|
26785
|
+
],
|
|
26786
|
+
isError
|
|
26787
|
+
}
|
|
26788
|
+
});
|
|
26789
|
+
};
|
|
26579
26790
|
try {
|
|
26580
26791
|
const parsed = parseMapToolCall(name, params.arguments);
|
|
26581
26792
|
if ("text" in parsed) return respond(parsed.text, parsed.isError);
|
|
@@ -26593,7 +26804,8 @@ ${text}` : text
|
|
|
26593
26804
|
]);
|
|
26594
26805
|
timer.abort();
|
|
26595
26806
|
if (controller.signal.aborted) return;
|
|
26596
|
-
|
|
26807
|
+
if (ready && name !== MAP_TOOL_NAMES.check) enter("READ");
|
|
26808
|
+
const result = ready ? await runMapTool(await opened, { name, args: routed.args }, controller.signal, enter) : {
|
|
26597
26809
|
text: `LayerMap is still building this project's map (a first build can take minutes on a large repository). Call ${name} again shortly, or read source meanwhile.`,
|
|
26598
26810
|
isError: false
|
|
26599
26811
|
};
|
|
@@ -26602,6 +26814,8 @@ ${text}` : text
|
|
|
26602
26814
|
if (controller.signal.aborted) return;
|
|
26603
26815
|
respond(describeMapError(error51) ?? `LayerMap failed: ${String(error51)}`, true);
|
|
26604
26816
|
} finally {
|
|
26817
|
+
clearInterval(beat);
|
|
26818
|
+
if (!answered) finish("", false, true);
|
|
26605
26819
|
calls.delete(id2);
|
|
26606
26820
|
}
|
|
26607
26821
|
};
|
|
@@ -26691,9 +26905,9 @@ ${text}` : text
|
|
|
26691
26905
|
// src/agent/setup.ts
|
|
26692
26906
|
import { execFile } from "node:child_process";
|
|
26693
26907
|
import { existsSync as existsSync8 } from "node:fs";
|
|
26694
|
-
import { mkdir as
|
|
26908
|
+
import { mkdir as mkdir3, readFile as readFile5, rename as rename3, rm as rm2, writeFile as writeFile2 } from "node:fs/promises";
|
|
26695
26909
|
import { homedir as homedir2 } from "node:os";
|
|
26696
|
-
import
|
|
26910
|
+
import path18 from "node:path";
|
|
26697
26911
|
var SERVER = "layermap";
|
|
26698
26912
|
var SETUP_RULE = `mcp__${SERVER}`;
|
|
26699
26913
|
var PLUGIN_RULE = `mcp__plugin_${SERVER}_${SERVER}`;
|
|
@@ -26701,11 +26915,11 @@ var BEGIN = "<!-- layermap:begin -->";
|
|
|
26701
26915
|
var END = "<!-- layermap:end -->";
|
|
26702
26916
|
var launcherScript = (template, version2, args = '["mcp"]') => `// Generated from scripts/launcher.mjs.
|
|
26703
26917
|
${template.replace("__VERSION__", JSON.stringify(version2)).replace("__ARGUMENTS__", args)}`;
|
|
26704
|
-
var PUBLISHED_LAUNCHER =
|
|
26705
|
-
var launcherFile = (env = process.env) =>
|
|
26918
|
+
var PUBLISHED_LAUNCHER = path18.join(packageRoot, "dist", "launcher.mjs");
|
|
26919
|
+
var launcherFile = (env = process.env) => path18.join(cacheDirectory(env), "server.mjs");
|
|
26706
26920
|
var mcpLaunchCommand = (env = process.env, published = existsSync8(PUBLISHED_LAUNCHER)) => {
|
|
26707
26921
|
if (published) return ["node", launcherFile(env)];
|
|
26708
|
-
const script =
|
|
26922
|
+
const script = path18.resolve(process.argv[1] ?? "");
|
|
26709
26923
|
const execArgv = [];
|
|
26710
26924
|
for (let index = 0; index < process.execArgv.length; index++) {
|
|
26711
26925
|
const argument = process.execArgv[index];
|
|
@@ -26741,7 +26955,7 @@ async function allowInClaudeSettings(file2, rule = SETUP_RULE) {
|
|
|
26741
26955
|
throw new Error(`${file2} has permissions.allow that is not a list.`);
|
|
26742
26956
|
if (settings.permissions.allow.includes(rule)) return false;
|
|
26743
26957
|
settings.permissions.allow.push(rule);
|
|
26744
|
-
await
|
|
26958
|
+
await mkdir3(path18.dirname(file2), { recursive: true });
|
|
26745
26959
|
await writeFile2(file2, `${JSON.stringify(settings, null, 2)}
|
|
26746
26960
|
`);
|
|
26747
26961
|
return true;
|
|
@@ -26777,7 +26991,7 @@ ${END}`;
|
|
|
26777
26991
|
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}
|
|
26778
26992
|
`;
|
|
26779
26993
|
if (next === text) return;
|
|
26780
|
-
await
|
|
26994
|
+
await mkdir3(path18.dirname(file2), { recursive: true });
|
|
26781
26995
|
await writeFile2(file2, next);
|
|
26782
26996
|
}
|
|
26783
26997
|
async function removeInstructionNote(file2) {
|
|
@@ -26805,11 +27019,11 @@ async function disallowInClaudeSettings(file2) {
|
|
|
26805
27019
|
}
|
|
26806
27020
|
var YAML_BEGIN = "# layermap:begin";
|
|
26807
27021
|
var YAML_END = "# layermap:end";
|
|
26808
|
-
var nodeDirectory = (env = process.env) => (env.PATH ?? "").split(
|
|
27022
|
+
var nodeDirectory = (env = process.env) => (env.PATH ?? "").split(path18.delimiter).find((directory) => path18.isAbsolute(directory) && existsSync8(path18.join(directory, "node"))) ?? path18.dirname(process.execPath);
|
|
26809
27023
|
var dshPatchBlock = (command, env) => {
|
|
26810
27024
|
const node = nodeDirectory(env);
|
|
26811
|
-
const [program = "", ...args] = command[0] === "node" ? [
|
|
26812
|
-
const searchPath2 = `${JSON.stringify(`${node}${
|
|
27025
|
+
const [program = "", ...args] = command[0] === "node" ? [path18.join(node, "node"), ...command.slice(1)] : command;
|
|
27026
|
+
const searchPath2 = `${JSON.stringify(`${node}${path18.delimiter}`)} + process.env.PATH`;
|
|
26813
27027
|
return [
|
|
26814
27028
|
`${YAML_BEGIN} (written by \`layermap setup dsh\`; \`layermap remove dsh\` deletes it)`,
|
|
26815
27029
|
"- insert:",
|
|
@@ -26844,7 +27058,7 @@ async function writeDshPatch(file2, block) {
|
|
|
26844
27058
|
`;
|
|
26845
27059
|
}
|
|
26846
27060
|
if (next === text) return;
|
|
26847
|
-
await
|
|
27061
|
+
await mkdir3(path18.dirname(file2), { recursive: true });
|
|
26848
27062
|
await writeFile2(file2, next);
|
|
26849
27063
|
}
|
|
26850
27064
|
async function removeDshPatch(file2) {
|
|
@@ -26862,31 +27076,31 @@ async function removeDshPatch(file2) {
|
|
|
26862
27076
|
var agentFiles = (options) => {
|
|
26863
27077
|
const env = options.env ?? process.env;
|
|
26864
27078
|
if (options.agent === "dsh") {
|
|
26865
|
-
const home = env.DSH_HOME ||
|
|
27079
|
+
const home = env.DSH_HOME || path18.join(homedir2(), ".dsh");
|
|
26866
27080
|
return {
|
|
26867
|
-
settings:
|
|
26868
|
-
instructions:
|
|
27081
|
+
settings: path18.join(home, "cordis.patch.yml"),
|
|
27082
|
+
instructions: path18.join(home, "AGENTS.md")
|
|
26869
27083
|
};
|
|
26870
27084
|
}
|
|
26871
27085
|
if (options.agent === "codex") {
|
|
26872
|
-
const home = env.CODEX_HOME ??
|
|
26873
|
-
return { settings:
|
|
27086
|
+
const home = env.CODEX_HOME ?? path18.join(homedir2(), ".codex");
|
|
27087
|
+
return { settings: path18.join(home, "config.toml"), instructions: path18.join(home, "AGENTS.md") };
|
|
26874
27088
|
}
|
|
26875
27089
|
if (options.scope === "user") {
|
|
26876
|
-
const home = env.CLAUDE_CONFIG_DIR ??
|
|
27090
|
+
const home = env.CLAUDE_CONFIG_DIR ?? path18.join(homedir2(), ".claude");
|
|
26877
27091
|
return {
|
|
26878
|
-
settings:
|
|
26879
|
-
instructions:
|
|
27092
|
+
settings: path18.join(home, "settings.json"),
|
|
27093
|
+
instructions: path18.join(home, "CLAUDE.md")
|
|
26880
27094
|
};
|
|
26881
27095
|
}
|
|
26882
27096
|
const local = options.scope === "local";
|
|
26883
27097
|
return {
|
|
26884
|
-
settings:
|
|
27098
|
+
settings: path18.join(
|
|
26885
27099
|
options.project,
|
|
26886
27100
|
".claude",
|
|
26887
27101
|
local ? "settings.local.json" : "settings.json"
|
|
26888
27102
|
),
|
|
26889
|
-
instructions:
|
|
27103
|
+
instructions: path18.join(options.project, local ? "CLAUDE.local.md" : "CLAUDE.md")
|
|
26890
27104
|
};
|
|
26891
27105
|
};
|
|
26892
27106
|
async function setupAgent(options) {
|
|
@@ -26906,12 +27120,12 @@ async function setupAgent(options) {
|
|
|
26906
27120
|
const writeLauncher = async () => {
|
|
26907
27121
|
if (!published) return;
|
|
26908
27122
|
const file2 = launcherFile(env);
|
|
26909
|
-
await
|
|
27123
|
+
await mkdir3(path18.dirname(file2), { recursive: true, mode: 448 });
|
|
26910
27124
|
await writeFile2(
|
|
26911
27125
|
`${file2}.${process.pid}`,
|
|
26912
27126
|
launcherScript(await readFile5(PUBLISHED_LAUNCHER, "utf8"), options.version)
|
|
26913
27127
|
);
|
|
26914
|
-
await
|
|
27128
|
+
await rename3(`${file2}.${process.pid}`, file2);
|
|
26915
27129
|
};
|
|
26916
27130
|
if (published) log2(`write the launcher of LayerMap ${options.version} to ${launcherFile(env)}`);
|
|
26917
27131
|
if (options.agent === "dsh") {
|
|
@@ -27012,7 +27226,7 @@ Usage:
|
|
|
27012
27226
|
layermap explore [PATH] [--name NAME] [--line N] [--direction INCOMING|OUTGOING|BOTH]
|
|
27013
27227
|
[--depth N] [--tests] [--unresolved] [--offset N]
|
|
27014
27228
|
layermap search QUERY [--path DIR] [--mode ANY|ALL|LITERAL] [--max N] [--offset N]
|
|
27015
|
-
layermap refs PATH NAME [--line N] [--
|
|
27229
|
+
layermap refs PATH NAME [--line N] [--within DIR] [--max N] [--cursor C]
|
|
27016
27230
|
layermap check [--base REF] [--json] [TEST...]
|
|
27017
27231
|
what the uncommitted changes (or those since REF) affect,
|
|
27018
27232
|
and what of them the test files given do not run; --json
|
|
@@ -27030,10 +27244,10 @@ var log = (line) => process.stderr.write(`${line}
|
|
|
27030
27244
|
async function checkedTests(project, tests) {
|
|
27031
27245
|
const here = await realpath4(process.cwd());
|
|
27032
27246
|
return tests.map((test) => {
|
|
27033
|
-
const relative =
|
|
27034
|
-
if (!relative || relative === ".." || relative.startsWith(`..${
|
|
27247
|
+
const relative = path19.relative(project, path19.resolve(here, test));
|
|
27248
|
+
if (!relative || relative === ".." || relative.startsWith(`..${path19.sep}`) || path19.isAbsolute(relative))
|
|
27035
27249
|
throw new Error(`${test} is not in ${project}.`);
|
|
27036
|
-
return relative.split(
|
|
27250
|
+
return relative.split(path19.sep).join("/");
|
|
27037
27251
|
});
|
|
27038
27252
|
}
|
|
27039
27253
|
var usage = (code) => {
|
|
@@ -27059,6 +27273,7 @@ async function main(argv) {
|
|
|
27059
27273
|
unresolved: { type: "boolean", default: false },
|
|
27060
27274
|
offset: { type: "string" },
|
|
27061
27275
|
path: { type: "string" },
|
|
27276
|
+
within: { type: "string" },
|
|
27062
27277
|
mode: { type: "string" },
|
|
27063
27278
|
max: { type: "string" },
|
|
27064
27279
|
cursor: { type: "string" },
|
|
@@ -27105,7 +27320,13 @@ async function main(argv) {
|
|
|
27105
27320
|
return done ? 0 : 1;
|
|
27106
27321
|
}
|
|
27107
27322
|
if (command === "mcp") {
|
|
27108
|
-
await serveMcp({
|
|
27323
|
+
await serveMcp({
|
|
27324
|
+
version: version2,
|
|
27325
|
+
start: { directory: project, git: git2 },
|
|
27326
|
+
open: open3,
|
|
27327
|
+
log,
|
|
27328
|
+
record: mapCallLog(cache)
|
|
27329
|
+
});
|
|
27109
27330
|
return 0;
|
|
27110
27331
|
}
|
|
27111
27332
|
const number4 = (value) => value === void 0 ? void 0 : Number(value);
|
|
@@ -27181,8 +27402,10 @@ async function main(argv) {
|
|
|
27181
27402
|
refs: [
|
|
27182
27403
|
MAP_TOOL_NAMES.references,
|
|
27183
27404
|
{
|
|
27184
|
-
|
|
27185
|
-
|
|
27405
|
+
path: rest[0],
|
|
27406
|
+
name: rest[1],
|
|
27407
|
+
line: number4(values.line),
|
|
27408
|
+
within: values.within,
|
|
27186
27409
|
maxResults: number4(values.max),
|
|
27187
27410
|
cursor: values.cursor
|
|
27188
27411
|
}
|