layermap 0.1.5 → 0.1.6

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