layermap 0.1.52 → 0.1.54

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
@@ -8,7 +8,7 @@ var __export = (target, all) => {
8
8
 
9
9
  // src/cli.ts
10
10
  import { realpath as realpath4 } from "node:fs/promises";
11
- import path19 from "node:path";
11
+ import path20 from "node:path";
12
12
  import { parseArgs } from "node:util";
13
13
 
14
14
  // src/agent/call-log.ts
@@ -34,10 +34,15 @@ function mapCallLog(cache) {
34
34
  };
35
35
  }
36
36
 
37
+ // src/agent/command.ts
38
+ import { chmod, lstat as lstat5, mkdir as mkdir3, readFile as readFile6, rename as rename3, rm as rm2, writeFile as writeFile2 } from "node:fs/promises";
39
+ import { homedir as homedir2 } from "node:os";
40
+ import path17 from "node:path";
41
+
37
42
  // src/agent/environment.ts
38
43
  import { createHash as createHash6 } from "node:crypto";
39
44
  import { existsSync as existsSync6, readFileSync as readFileSync3 } from "node:fs";
40
- import { mkdir as mkdir2, readdir, readFile as readFile4, rename as rename2, rm, stat as stat2, utimes, writeFile } from "node:fs/promises";
45
+ import { mkdir as mkdir2, readdir, readFile as readFile5, rename as rename2, rm, stat as stat2, utimes, writeFile } from "node:fs/promises";
41
46
  import { createRequire } from "node:module";
42
47
  import { homedir } from "node:os";
43
48
  import path16 from "node:path";
@@ -344,9 +349,9 @@ async function gitGrep(git2, search, options) {
344
349
  }
345
350
  const hits = [];
346
351
  for (const record2 of found.split("\n")) {
347
- const [path20, line, text, extra] = record2.split("\0");
348
- if (path20 && line && text !== void 0 && extra === void 0)
349
- hits.push({ path: path20, line: Number(line), text });
352
+ const [path21, line, text, extra] = record2.split("\0");
353
+ if (path21 && line && text !== void 0 && extra === void 0)
354
+ hits.push({ path: path21, line: Number(line), text });
350
355
  }
351
356
  return { hits };
352
357
  }
@@ -1370,10 +1375,10 @@ function mergeDefs(...defs) {
1370
1375
  function cloneDef(schema) {
1371
1376
  return mergeDefs(schema._zod.def);
1372
1377
  }
1373
- function getElementAtPath(obj, path20) {
1374
- if (!path20)
1378
+ function getElementAtPath(obj, path21) {
1379
+ if (!path21)
1375
1380
  return obj;
1376
- return path20.reduce((acc, key) => acc?.[key], obj);
1381
+ return path21.reduce((acc, key) => acc?.[key], obj);
1377
1382
  }
1378
1383
  function promiseAllObject(promisesObj) {
1379
1384
  const keys = Object.keys(promisesObj);
@@ -1782,11 +1787,11 @@ function explicitlyAborted(x, startIndex = 0) {
1782
1787
  }
1783
1788
  return false;
1784
1789
  }
1785
- function prefixIssues(path20, issues) {
1790
+ function prefixIssues(path21, issues) {
1786
1791
  return issues.map((iss) => {
1787
1792
  var _a3;
1788
1793
  (_a3 = iss).path ?? (_a3.path = []);
1789
- iss.path.unshift(path20);
1794
+ iss.path.unshift(path21);
1790
1795
  return iss;
1791
1796
  });
1792
1797
  }
@@ -1933,16 +1938,16 @@ function flattenError(error51, mapper = (issue2) => issue2.message) {
1933
1938
  }
1934
1939
  function formatError(error51, mapper = (issue2) => issue2.message) {
1935
1940
  const fieldErrors = { _errors: [] };
1936
- const processError = (error52, path20 = []) => {
1941
+ const processError = (error52, path21 = []) => {
1937
1942
  for (const issue2 of error52.issues) {
1938
1943
  if (issue2.code === "invalid_union" && issue2.errors.length) {
1939
- issue2.errors.map((issues) => processError({ issues }, [...path20, ...issue2.path]));
1944
+ issue2.errors.map((issues) => processError({ issues }, [...path21, ...issue2.path]));
1940
1945
  } else if (issue2.code === "invalid_key") {
1941
- processError({ issues: issue2.issues }, [...path20, ...issue2.path]);
1946
+ processError({ issues: issue2.issues }, [...path21, ...issue2.path]);
1942
1947
  } else if (issue2.code === "invalid_element") {
1943
- processError({ issues: issue2.issues }, [...path20, ...issue2.path]);
1948
+ processError({ issues: issue2.issues }, [...path21, ...issue2.path]);
1944
1949
  } else {
1945
- const fullpath = [...path20, ...issue2.path];
1950
+ const fullpath = [...path21, ...issue2.path];
1946
1951
  if (fullpath.length === 0) {
1947
1952
  fieldErrors._errors.push(mapper(issue2));
1948
1953
  } else {
@@ -1969,17 +1974,17 @@ function formatError(error51, mapper = (issue2) => issue2.message) {
1969
1974
  }
1970
1975
  function treeifyError(error51, mapper = (issue2) => issue2.message) {
1971
1976
  const result = { errors: [] };
1972
- const processError = (error52, path20 = []) => {
1977
+ const processError = (error52, path21 = []) => {
1973
1978
  var _a3, _b;
1974
1979
  for (const issue2 of error52.issues) {
1975
1980
  if (issue2.code === "invalid_union" && issue2.errors.length) {
1976
- issue2.errors.map((issues) => processError({ issues }, [...path20, ...issue2.path]));
1981
+ issue2.errors.map((issues) => processError({ issues }, [...path21, ...issue2.path]));
1977
1982
  } else if (issue2.code === "invalid_key") {
1978
- processError({ issues: issue2.issues }, [...path20, ...issue2.path]);
1983
+ processError({ issues: issue2.issues }, [...path21, ...issue2.path]);
1979
1984
  } else if (issue2.code === "invalid_element") {
1980
- processError({ issues: issue2.issues }, [...path20, ...issue2.path]);
1985
+ processError({ issues: issue2.issues }, [...path21, ...issue2.path]);
1981
1986
  } else {
1982
- const fullpath = [...path20, ...issue2.path];
1987
+ const fullpath = [...path21, ...issue2.path];
1983
1988
  if (fullpath.length === 0) {
1984
1989
  result.errors.push(mapper(issue2));
1985
1990
  continue;
@@ -2011,8 +2016,8 @@ function treeifyError(error51, mapper = (issue2) => issue2.message) {
2011
2016
  }
2012
2017
  function toDotPath(_path) {
2013
2018
  const segs = [];
2014
- const path20 = _path.map((seg) => typeof seg === "object" ? seg.key : seg);
2015
- for (const seg of path20) {
2019
+ const path21 = _path.map((seg) => typeof seg === "object" ? seg.key : seg);
2020
+ for (const seg of path21) {
2016
2021
  if (typeof seg === "number")
2017
2022
  segs.push(`[${seg}]`);
2018
2023
  else if (typeof seg === "symbol")
@@ -14704,13 +14709,13 @@ function resolveRef(ref, ctx) {
14704
14709
  if (!ref.startsWith("#")) {
14705
14710
  throw new Error("External $ref is not supported, only local refs (#/...) are allowed");
14706
14711
  }
14707
- const path20 = ref.slice(1).split("/").filter(Boolean);
14708
- if (path20.length === 0) {
14712
+ const path21 = ref.slice(1).split("/").filter(Boolean);
14713
+ if (path21.length === 0) {
14709
14714
  return ctx.rootSchema;
14710
14715
  }
14711
14716
  const defsKey = ctx.version === "draft-2020-12" ? "$defs" : "definitions";
14712
- if (path20[0] === defsKey) {
14713
- const key = path20[1];
14717
+ if (path21[0] === defsKey) {
14718
+ const key = path21[1];
14714
14719
  if (!key || !ctx.defs[key]) {
14715
14720
  throw new Error(`Reference not found: ${ref}`);
14716
14721
  }
@@ -16117,8 +16122,8 @@ var MapAnalysisSchema = external_exports.object({
16117
16122
  var mapPathAllowed = (relative, prefixes) => prefixes.some(
16118
16123
  (prefix) => prefix === "." || relative === prefix || relative.startsWith(`${prefix}/`)
16119
16124
  );
16120
- var mapTestPath = (path20) => /(?:^|\/)(?:__tests__|tests?|fixtures?|testFixtures|e2e|testdata)(?:\/|$)|\.(?:spec|test)\.|_test\.(?:go|py)$|(?:^|\/)(?:test_[^/]*\.py|conftest\.py)$/iu.test(
16121
- path20
16125
+ var mapTestPath = (path21) => /(?:^|\/)(?:__tests__|tests?|fixtures?|testFixtures|e2e|testdata)(?:\/|$)|\.(?:spec|test)\.|_test\.(?:go|py)$|(?:^|\/)(?:test_[^/]*\.py|conftest\.py)$/iu.test(
16126
+ path21
16122
16127
  );
16123
16128
  var mapRunnableTest = (file2) => /_test\.(?:go|py)$|(?:^|\/)test_[^/]*\.py$|(?:\.(?:test|spec)|\.e2e-spec|(?:^|\/)__tests__\/.*)\.[cm]?[jt]sx?$|(?:^|\/)(?:Test|IT)[A-Z]\w*\.(?:java|kt)$|(?:Test|Tests|TestCase|IT|ITCase)\.(?:java|kt)$/u.test(
16124
16129
  file2
@@ -16223,11 +16228,11 @@ var string4 = (value) => {
16223
16228
  var identity = (id2, reconstructed) => id2 === reconstructed ? [] : [JSON.stringify(id2)];
16224
16229
  function encodeMapText(graph) {
16225
16230
  const files = /* @__PURE__ */ new Map();
16226
- const file2 = (path20) => {
16227
- let ref = files.get(path20);
16231
+ const file2 = (path21) => {
16232
+ let ref = files.get(path21);
16228
16233
  if (!ref) {
16229
16234
  ref = `F${files.size + 1}`;
16230
- files.set(path20, ref);
16235
+ files.set(path21, ref);
16231
16236
  }
16232
16237
  return ref;
16233
16238
  };
@@ -16275,7 +16280,7 @@ function encodeMapText(graph) {
16275
16280
  rows2.push(`B ${node(frontier.entityRef)} ${frontier.direction}`);
16276
16281
  return [
16277
16282
  ...header,
16278
- ...[...files].map(([path20, ref]) => `${ref} ${JSON.stringify(path20)}`),
16283
+ ...[...files].map(([path21, ref]) => `${ref} ${JSON.stringify(path21)}`),
16279
16284
  ...rows2
16280
16285
  ].join("\n");
16281
16286
  }
@@ -16295,10 +16300,10 @@ function decodeMapText(text) {
16295
16300
  const at = (value) => {
16296
16301
  const match = /^(F[1-9]\d*):(\d+)-(\d+)@(\d+)-(\d+)$/u.exec(value ?? "");
16297
16302
  if (!match) return failed();
16298
- const path20 = files.get(match[1] ?? "");
16299
- if (path20 === void 0) return failed();
16303
+ const path21 = files.get(match[1] ?? "");
16304
+ if (path21 === void 0) return failed();
16300
16305
  return MapAnchorSchema.parse({
16301
- path: path20,
16306
+ path: path21,
16302
16307
  startLine: Number(match[2]),
16303
16308
  endLine: Number(match[3]),
16304
16309
  start: Number(match[4]),
@@ -16375,8 +16380,8 @@ function decodeMapText(text) {
16375
16380
  var locationSchema = MapAnchorSchema.describe(
16376
16381
  "Source location: start/end are zero-based UTF-16 offsets with an exclusive end; line numbers are one-based."
16377
16382
  );
16378
- var location = ({ path: path20, startLine, endLine, start, end }) => ({
16379
- path: path20,
16383
+ var location = ({ path: path21, startLine, endLine, start, end }) => ({
16384
+ path: path21,
16380
16385
  startLine,
16381
16386
  endLine,
16382
16387
  start,
@@ -16479,11 +16484,11 @@ var MapNavigationObjectsSchema = external_exports.union([
16479
16484
  ),
16480
16485
  external_exports.object({ files: external_exports.array(searchFileSchema) }).passthrough().refine((value) => !("format" in value), "Text navigation must decode through its format.").transform(
16481
16486
  (value) => value.files.flatMap(
16482
- ({ path: path20, symbols }) => symbols.map(({ id: id2, name, kind, startLine, endLine, start, end, execution }) => ({
16487
+ ({ path: path21, symbols }) => symbols.map(({ id: id2, name, kind, startLine, endLine, start, end, execution }) => ({
16483
16488
  id: id2,
16484
16489
  name,
16485
16490
  kind,
16486
- anchor: { path: path20, startLine, endLine, start, end },
16491
+ anchor: { path: path21, startLine, endLine, start, end },
16487
16492
  ...execution ? { execution } : {}
16488
16493
  }))
16489
16494
  )
@@ -16496,10 +16501,10 @@ var mapSearchNavigation = (result) => {
16496
16501
  for (const [index, object2] of found.entries()) {
16497
16502
  const ranking = rankings[index];
16498
16503
  if (!ranking) throw new Error("PROJECT_MAP_SEARCH_RANKING_MISSING");
16499
- const path20 = object2.anchor.path;
16504
+ const path21 = object2.anchor.path;
16500
16505
  let file2 = files.at(-1);
16501
- if (file2?.path !== path20) {
16502
- file2 = { path: path20, symbols: [] };
16506
+ if (file2?.path !== path21) {
16507
+ file2 = { path: path21, symbols: [] };
16503
16508
  files.push(file2);
16504
16509
  }
16505
16510
  file2.symbols.push({
@@ -16630,8 +16635,8 @@ var MapViewGraph = class {
16630
16635
  }
16631
16636
  return object2;
16632
16637
  }
16633
- objectsAt(path20) {
16634
- return this.statements.path.all(this.version, path20).map((row) => {
16638
+ objectsAt(path21) {
16639
+ return this.statements.path.all(this.version, path21).map((row) => {
16635
16640
  const object2 = MapObjectSchema.parse(JSON.parse(String(row.object_json)));
16636
16641
  this.objects.set(object2.id, object2);
16637
16642
  return object2;
@@ -16657,8 +16662,8 @@ var MapViewGraph = class {
16657
16662
  return this.statements.children.all(this.version, ref).map((row) => String(row.to_ref));
16658
16663
  }
16659
16664
  /** The declarations of a file other code can name, without the file itself. */
16660
- declarationsAt(path20) {
16661
- return this.objectsAt(path20).filter(
16665
+ declarationsAt(path21) {
16666
+ return this.objectsAt(path21).filter(
16662
16667
  (object2) => !mapIsModule(object2) && this.isAddressable(object2)
16663
16668
  );
16664
16669
  }
@@ -16766,8 +16771,8 @@ var MapViewGraph = class {
16766
16771
  );
16767
16772
  }
16768
16773
  };
16769
- function mapSelectDeclarations(graph, path20, name, line) {
16770
- const objects2 = graph.objectsAt(path20).filter((object2) => !mapIsModule(object2));
16774
+ function mapSelectDeclarations(graph, path21, name, line) {
16775
+ const objects2 = graph.objectsAt(path21).filter((object2) => !mapIsModule(object2));
16771
16776
  const matching = name === void 0 ? objects2 : objects2.filter(
16772
16777
  (object2) => object2.name === name || name.includes(".") && graph.qualifiedName(object2.id) === name
16773
16778
  );
@@ -16789,12 +16794,12 @@ function requireMapObject(store, version2, selector, prefixes) {
16789
16794
  if ([entityRef, locator, symbol2].filter((value) => value !== void 0).length !== 1 || entityRef !== void 0 && !entityRef.length)
16790
16795
  throw new ProjectEvidenceError("PROJECT_READ_INPUT_INVALID", false);
16791
16796
  if (symbol2) {
16792
- const path20 = normalizeProjectEvidencePath(symbol2.path);
16793
- if (!mapPathAllowed(path20, prefixes))
16797
+ const path21 = normalizeProjectEvidencePath(symbol2.path);
16798
+ if (!mapPathAllowed(path21, prefixes))
16794
16799
  throw new ProjectEvidenceError("PROJECT_MAP_OBJECT_NOT_FOUND", false);
16795
16800
  const selected = mapSelectDeclarations(
16796
16801
  new MapViewGraph(store, version2),
16797
- path20,
16802
+ path21,
16798
16803
  symbol2.name,
16799
16804
  symbol2.line
16800
16805
  );
@@ -16805,14 +16810,14 @@ function requireMapObject(store, version2, selector, prefixes) {
16805
16810
  }
16806
16811
  let rows2;
16807
16812
  if (locator) {
16808
- const path20 = normalizeProjectEvidencePath(locator.path);
16813
+ const path21 = normalizeProjectEvidencePath(locator.path);
16809
16814
  if (!Number.isSafeInteger(locator.start) || locator.start < 0 || locator.kind !== void 0 && !MapObjectKindSchema.safeParse(locator.kind).success)
16810
16815
  throw new ProjectEvidenceError("PROJECT_READ_INPUT_INVALID", false);
16811
- if (!mapPathAllowed(path20, prefixes))
16816
+ if (!mapPathAllowed(path21, prefixes))
16812
16817
  throw new ProjectEvidenceError("PROJECT_MAP_OBJECT_NOT_FOUND", false);
16813
16818
  rows2 = store.database.prepare(`SELECT object_json FROM project_map_objects
16814
16819
  WHERE version_ref = ? AND path = ? AND json_extract(object_json, '$.anchor.start') = ?
16815
- AND (? IS NULL OR kind = ?) LIMIT 2`).all(version2, path20, locator.start, locator.kind ?? null, locator.kind ?? null);
16820
+ AND (? IS NULL OR kind = ?) LIMIT 2`).all(version2, path21, locator.start, locator.kind ?? null, locator.kind ?? null);
16816
16821
  } else {
16817
16822
  rows2 = store.database.prepare(
16818
16823
  "SELECT object_json FROM project_map_objects WHERE version_ref = ? AND entity_ref = ?"
@@ -16853,13 +16858,13 @@ function mapQueryPage(count, materialize, navigation, budget) {
16853
16858
 
16854
16859
  // src/project-map-query-selection.ts
16855
16860
  var mapQuerySelection = (input, knownKinds) => {
16856
- const path20 = normalizeProjectEvidencePath(input.path ?? ".", true) || ".";
16861
+ const path21 = normalizeProjectEvidencePath(input.path ?? ".", true) || ".";
16857
16862
  const kinds = input.kinds ?? knownKinds;
16858
16863
  if (!Array.isArray(kinds) || !kinds.length || kinds.length > knownKinds.length || kinds.some((kind) => !knownKinds.includes(kind)))
16859
16864
  throw new ProjectEvidenceError("PROJECT_READ_INPUT_INVALID", false);
16860
- return { path: path20, kinds: [...new Set(kinds)].sort() };
16865
+ return { path: path21, kinds: [...new Set(kinds)].sort() };
16861
16866
  };
16862
- var mapQueryPathMatches = (path20, prefix) => prefix === "." || path20 === prefix || path20.startsWith(`${prefix}/`);
16867
+ var mapQueryPathMatches = (path21, prefix) => prefix === "." || path21 === prefix || path21.startsWith(`${prefix}/`);
16863
16868
  var MAP_RELATION_TARGET_JOIN = `LEFT JOIN project_map_unit_objects t ON t.entity_ref = r.to_ref
16864
16869
  AND EXISTS (SELECT 1 FROM project_map_version_units target
16865
16870
  WHERE target.version_ref = r.version_ref AND target.unit_ref = t.unit_ref AND target.path = t.path)`;
@@ -16961,7 +16966,7 @@ var declarationKinds = /* @__PURE__ */ new Set([
16961
16966
  "METHOD",
16962
16967
  "TYPE"
16963
16968
  ]);
16964
- var fileStem = (path20) => path20.slice(path20.lastIndexOf("/") + 1).replace(/\.(?:[cm]?[jt]sx?|vue|svelte|go|pyi?)$/iu, "");
16969
+ var fileStem = (path21) => path21.slice(path21.lastIndexOf("/") + 1).replace(/\.(?:[cm]?[jt]sx?|vue|svelte|go|pyi?)$/iu, "");
16965
16970
  var compareText = (left, right) => left < right ? -1 : left > right ? 1 : 0;
16966
16971
  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);
16967
16972
  function mapSearchQuery(input) {
@@ -16988,10 +16993,10 @@ function mapSearchQuery(input) {
16988
16993
  }
16989
16994
  function rank(object2, documentation, relationCount, query, focus) {
16990
16995
  const name = object2.name.toLowerCase();
16991
- const path20 = object2.anchor.path.toLowerCase();
16996
+ const path21 = object2.anchor.path.toLowerCase();
16992
16997
  const values = {
16993
16998
  NAME: [name],
16994
- PATH: [path20],
16999
+ PATH: [path21],
16995
17000
  DOCUMENTATION: documentation.map((text) => text.toLowerCase())
16996
17001
  };
16997
17002
  const matched = query.terms.map((term) => ({
@@ -17016,12 +17021,12 @@ function rank(object2, documentation, relationCount, query, focus) {
17016
17021
  score += 7e3;
17017
17022
  signals.push("SYMBOL_CONTAINS");
17018
17023
  } else if (matchedFields.includes("NAME")) signals.push("SYMBOL_CONTAINS");
17019
- if (object2.kind === "FILE" && fileStem(path20) === normalizedQuery) {
17024
+ if (object2.kind === "FILE" && fileStem(path21) === normalizedQuery) {
17020
17025
  score += 11e3;
17021
17026
  signals.push("EXACT_FILE_STEM");
17022
17027
  }
17023
17028
  if (matchedFields.includes("PATH")) {
17024
- score += path20.includes(normalizedQuery) ? 2500 : 0;
17029
+ score += path21.includes(normalizedQuery) ? 2500 : 0;
17025
17030
  signals.push("PATH_CONTAINS");
17026
17031
  }
17027
17032
  if (matchedFields.includes("DOCUMENTATION")) {
@@ -17036,8 +17041,8 @@ function rank(object2, documentation, relationCount, query, focus) {
17036
17041
  score += kindWeight[object2.kind] + Math.min(1200, relationCount * 20) + (focus?.score ?? 0);
17037
17042
  if (declarationKinds.has(object2.kind)) signals.push("DECLARATION");
17038
17043
  if (relationCount > 0) signals.push("GRAPH_CONNECTED");
17039
- const isTest = mapTestPath(path20);
17040
- const isGenerated = generatedPath.test(path20);
17044
+ const isTest = mapTestPath(path21);
17045
+ const isGenerated = generatedPath.test(path21);
17041
17046
  const hasTestIntent = query.terms.some((term) => testQuery.test(term));
17042
17047
  score += isTest ? hasTestIntent ? 1e3 : -5e3 : 300;
17043
17048
  score += isGenerated ? -3e3 : 300;
@@ -17549,13 +17554,13 @@ function utf16Offsets(text) {
17549
17554
  }
17550
17555
  function offsetConverter(files, offsets) {
17551
17556
  const converters = /* @__PURE__ */ new Map();
17552
- return (path20, offset) => {
17553
- let convert = converters.get(path20);
17557
+ return (path21, offset) => {
17558
+ let convert = converters.get(path21);
17554
17559
  if (!convert) {
17555
- const text = files[path20];
17560
+ const text = files[path21];
17556
17561
  if (text === void 0) return invalid();
17557
17562
  convert = offsets === "UTF16" ? (value) => value <= text.length ? value : invalid() : utf16Offsets(text);
17558
- converters.set(path20, convert);
17563
+ converters.set(path21, convert);
17559
17564
  }
17560
17565
  return convert(offset);
17561
17566
  };
@@ -17586,7 +17591,7 @@ function mapFactsAnalysis(facts, input, context) {
17586
17591
  const collect = new MapOutputCollector(output);
17587
17592
  const positions = new MapSourcePositions(input.files);
17588
17593
  const offset = offsetConverter(input.files, context.offsets);
17589
- const anchor = (path20, start, end) => positions.span(path20, offset(path20, start), offset(path20, end));
17594
+ const anchor = (path21, start, end) => positions.span(path21, offset(path21, start), offset(path21, end));
17590
17595
  const located = /* @__PURE__ */ new Map();
17591
17596
  const canonical = /* @__PURE__ */ new Map();
17592
17597
  const bySpan = /* @__PURE__ */ new Map();
@@ -18166,8 +18171,8 @@ var goWork = /(?:^|\/)go\.work$/u;
18166
18171
  var codeHosts = /* @__PURE__ */ new Set(["github.com", "gitlab.com", "bitbucket.org"]);
18167
18172
  var GO_MAP_LANGUAGE = Object.freeze({
18168
18173
  id: "go-1.24-map-v11",
18169
- claims: (path20) => path20.endsWith(".go"),
18170
- reads: (path20) => goModule.test(path20) || goWork.test(path20),
18174
+ claims: (path21) => path21.endsWith(".go"),
18175
+ reads: (path21) => goModule.test(path21) || goWork.test(path21),
18171
18176
  // A module path, or the standard library, whose first path element has no dot.
18172
18177
  importName: (specifier) => {
18173
18178
  const parts = specifier.split("/");
@@ -18176,7 +18181,7 @@ var GO_MAP_LANGUAGE = Object.freeze({
18176
18181
  return parts.slice(0, size).join("/");
18177
18182
  },
18178
18183
  // Go imports a package: the directory of the file.
18179
- importTarget: (path20) => `${path20.slice(0, path20.lastIndexOf("/") + 1) || "./"}`,
18184
+ importTarget: (path21) => `${path21.slice(0, path21.lastIndexOf("/") + 1) || "./"}`,
18180
18185
  create: () => new GoMapAnalyzer()
18181
18186
  });
18182
18187
  var GO_GAPS = [
@@ -18201,8 +18206,8 @@ var goMapAnalysis = (facts, input, configurations) => mapFactsAnalysis(facts, in
18201
18206
  typeIssues: "GO_TYPE_CHECK_ISSUES",
18202
18207
  contract: "Declares a Go interface. This does not establish runtime enforcement or business authority."
18203
18208
  });
18204
- var goLocalModules = (path20, text) => {
18205
- const directive = goWork.test(path20) ? "use" : "replace";
18209
+ var goLocalModules = (path21, text) => {
18210
+ const directive = goWork.test(path21) ? "use" : "replace";
18206
18211
  const found = [];
18207
18212
  let block = false;
18208
18213
  for (const raw of text.split("\n")) {
@@ -18216,37 +18221,37 @@ var goLocalModules = (path20, text) => {
18216
18221
  const target = directive === "use" ? entry : entry?.split("=>")[1];
18217
18222
  const directory = target?.trim().split(/\s+/u)[0]?.replace(/^(["`])(.*)\1$/u, "$2");
18218
18223
  if (!directory || !/^\.\.?(?:\/|$)/u.test(directory)) continue;
18219
- const joined = posix.normalize(posix.join(posix.dirname(path20), directory)).replace(/\/$/u, "");
18224
+ const joined = posix.normalize(posix.join(posix.dirname(path21), directory)).replace(/\/$/u, "");
18220
18225
  if (joined !== ".." && !joined.startsWith("../")) found.push(joined);
18221
18226
  }
18222
18227
  return found;
18223
18228
  };
18224
18229
  var goModuleGroups = (files, text) => {
18225
- const modules = files.filter((path20) => goModule.test(path20)).sort();
18226
- const moduleAt = new Map(modules.map((path20) => [posix.dirname(path20), path20]));
18227
- const parent = new Map(modules.map((path20) => [path20, path20]));
18228
- const root = (path20) => {
18229
- const up = parent.get(path20) ?? path20;
18230
- return up === path20 ? path20 : root(up);
18230
+ const modules = files.filter((path21) => goModule.test(path21)).sort();
18231
+ const moduleAt = new Map(modules.map((path21) => [posix.dirname(path21), path21]));
18232
+ const parent = new Map(modules.map((path21) => [path21, path21]));
18233
+ const root = (path21) => {
18234
+ const up = parent.get(path21) ?? path21;
18235
+ return up === path21 ? path21 : root(up);
18231
18236
  };
18232
18237
  const works = [];
18233
- for (const path20 of [...files].filter((file2) => goModule.test(file2) || goWork.test(file2)).sort()) {
18234
- const linked = goLocalModules(path20, text(path20)).flatMap((dir) => moduleAt.get(dir) ?? []);
18235
- const first = goWork.test(path20) ? linked[0] : path20;
18238
+ for (const path21 of [...files].filter((file2) => goModule.test(file2) || goWork.test(file2)).sort()) {
18239
+ const linked = goLocalModules(path21, text(path21)).flatMap((dir) => moduleAt.get(dir) ?? []);
18240
+ const first = goWork.test(path21) ? linked[0] : path21;
18236
18241
  if (!first) continue;
18237
- if (goWork.test(path20)) works.push([path20, first]);
18242
+ if (goWork.test(path21)) works.push([path21, first]);
18238
18243
  for (const module of linked) {
18239
18244
  const [low = first, high = module] = [root(first), root(module)].sort();
18240
18245
  if (low !== high) parent.set(high, low);
18241
18246
  }
18242
18247
  }
18243
18248
  const members = /* @__PURE__ */ new Map();
18244
- for (const path20 of modules) members.set(root(path20), [...members.get(root(path20)) ?? [], path20]);
18249
+ for (const path21 of modules) members.set(root(path21), [...members.get(root(path21)) ?? [], path21]);
18245
18250
  const named = new Map(works.reverse().map(([work, module]) => [root(module), work]));
18246
18251
  return new Map(
18247
- modules.map((path20) => [
18248
- path20,
18249
- { configPath: named.get(root(path20)) ?? root(path20), modules: members.get(root(path20)) ?? [] }
18252
+ modules.map((path21) => [
18253
+ path21,
18254
+ { configPath: named.get(root(path21)) ?? root(path21), modules: members.get(root(path21)) ?? [] }
18250
18255
  ])
18251
18256
  );
18252
18257
  };
@@ -18276,28 +18281,28 @@ var GoMapAnalyzer = class {
18276
18281
  }
18277
18282
  async analyze(session, signal) {
18278
18283
  const paths = session.readable.map((entry) => entry.path);
18279
- const groupOf = goModuleGroups(paths, (path20) => session.texts[path20] ?? "");
18280
- const moduleOf = (path20) => {
18284
+ const groupOf = goModuleGroups(paths, (path21) => session.texts[path21] ?? "");
18285
+ const moduleOf = (path21) => {
18281
18286
  let best;
18282
18287
  for (const modFile of groupOf.keys()) {
18283
18288
  const directory = modFile.slice(0, modFile.lastIndexOf("/") + 1);
18284
- if (path20.startsWith(directory) && (!best || directory.length > best.lastIndexOf("/") + 1))
18289
+ if (path21.startsWith(directory) && (!best || directory.length > best.lastIndexOf("/") + 1))
18285
18290
  best = modFile;
18286
18291
  }
18287
18292
  return best;
18288
18293
  };
18289
18294
  const contexts = /* @__PURE__ */ new Map();
18290
- for (const path20 of paths) {
18291
- if (!this.claims(path20)) continue;
18292
- const module = moduleOf(path20);
18295
+ for (const path21 of paths) {
18296
+ if (!this.claims(path21)) continue;
18297
+ const module = moduleOf(path21);
18293
18298
  const group = module ? groupOf.get(module) : void 0;
18294
18299
  const configPath = group?.configPath ?? "";
18295
18300
  const into = contexts.get(configPath);
18296
- if (into) into.sources.push(path20);
18301
+ if (into) into.sources.push(path21);
18297
18302
  else
18298
18303
  contexts.set(configPath, {
18299
18304
  configurations: group ? [.../* @__PURE__ */ new Set([...group.modules, configPath])].sort() : [],
18300
- sources: [path20]
18305
+ sources: [path21]
18301
18306
  });
18302
18307
  }
18303
18308
  for (const [configPath, { configurations, sources }] of [...contexts].sort(
@@ -18305,11 +18310,11 @@ var GoMapAnalyzer = class {
18305
18310
  )) {
18306
18311
  if (signal.aborted) throw new ProjectEvidenceError("PROJECT_READ_CANCELLED", true);
18307
18312
  const files = /* @__PURE__ */ Object.create(null);
18308
- for (const path20 of [...sources, ...configurations]) {
18309
- const text = session.texts[path20];
18313
+ for (const path21 of [...sources, ...configurations]) {
18314
+ const text = session.texts[path21];
18310
18315
  if (text === void 0)
18311
18316
  throw new ProjectEvidenceError("PROJECT_MAP_PROTOCOL_INVALID", false);
18312
- files[path20] = text;
18317
+ files[path21] = text;
18313
18318
  }
18314
18319
  const input = {
18315
18320
  contextRef: digestValue({
@@ -18343,8 +18348,8 @@ var GoMapAnalyzer = class {
18343
18348
  if (!existsSync4(this.resources.compilerPath))
18344
18349
  return { pages: references.map(() => null), requiredFiles: [] };
18345
18350
  const files = /* @__PURE__ */ Object.create(null);
18346
- for (const [path20, value] of Object.entries(input.files))
18347
- if (this.claims(path20) || this.reads(path20)) files[path20] = value;
18351
+ for (const [path21, value] of Object.entries(input.files))
18352
+ if (this.claims(path21) || this.reads(path21)) files[path21] = value;
18348
18353
  const facts = await this.operation(
18349
18354
  {
18350
18355
  ...input,
@@ -18373,14 +18378,14 @@ var BUILD_FILES = [
18373
18378
  "pom.xml"
18374
18379
  ];
18375
18380
  var buildFile = /(?:^|\/)(?:pom\.xml|(?:build|settings)\.gradle(?:\.kts)?)$/u;
18376
- var directoryOf = (path20) => path20.slice(0, path20.lastIndexOf("/") + 1);
18377
- var nameOf = (path20) => path20.slice(path20.lastIndexOf("/") + 1);
18381
+ var directoryOf = (path21) => path21.slice(0, path21.lastIndexOf("/") + 1);
18382
+ var nameOf = (path21) => path21.slice(path21.lastIndexOf("/") + 1);
18378
18383
  var DEFAULT_RELEASE = 21;
18379
18384
  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;
18380
18385
  var JAVA_MAP_LANGUAGE = Object.freeze({
18381
18386
  id: "javac-lombok-1.18.48-map-v10",
18382
- claims: (path20) => path20.endsWith(".java"),
18383
- reads: (path20) => buildFile.test(path20),
18387
+ claims: (path21) => path21.endsWith(".java"),
18388
+ reads: (path21) => buildFile.test(path21),
18384
18389
  // A package of the Java platform, or a library named by its first two package segments.
18385
18390
  importName: (specifier) => platformPackage.test(specifier) ? "Java standard library" : specifier.split(".").slice(0, 2).join("."),
18386
18391
  create: () => new JavaMapAnalyzer()
@@ -18470,8 +18475,8 @@ var JavaMapAnalyzer = class _JavaMapAnalyzer {
18470
18475
  // The worker's request for a context: the Java sources and the release.
18471
18476
  request(input, buildTexts) {
18472
18477
  const files = /* @__PURE__ */ Object.create(null);
18473
- for (const [path20, text] of Object.entries(input.files))
18474
- if (this.claims(path20)) files[path20] = text;
18478
+ for (const [path21, text] of Object.entries(input.files))
18479
+ if (this.claims(path21)) files[path21] = text;
18475
18480
  return {
18476
18481
  files,
18477
18482
  release: javaRelease(buildTexts, this.resources.runtimeVersion)
@@ -18486,35 +18491,35 @@ var JavaMapAnalyzer = class _JavaMapAnalyzer {
18486
18491
  }
18487
18492
  async analyze(session, signal) {
18488
18493
  this.refreshRuntime();
18489
- const builds = session.readable.map((entry) => entry.path).filter((path20) => buildFile.test(path20));
18490
- for (const path20 of builds) session.configuration(path20);
18491
- const rank2 = (path20) => BUILD_FILES.indexOf(nameOf(path20));
18494
+ const builds = session.readable.map((entry) => entry.path).filter((path21) => buildFile.test(path21));
18495
+ for (const path21 of builds) session.configuration(path21);
18496
+ const rank2 = (path21) => BUILD_FILES.indexOf(nameOf(path21));
18492
18497
  const roots = /* @__PURE__ */ new Map();
18493
18498
  const modules = /* @__PURE__ */ new Map();
18494
- for (const path20 of builds) {
18495
- const directory = directoryOf(path20);
18499
+ for (const path21 of builds) {
18500
+ const directory = directoryOf(path21);
18496
18501
  const current = modules.get(directory);
18497
- if (current === void 0 || rank2(path20) < rank2(current)) modules.set(directory, path20);
18498
- const text = session.texts[path20] ?? "";
18499
- if (/settings\.gradle(?:\.kts)?$/u.test(path20) || path20.endsWith("pom.xml") && /<modules>/u.test(text)) {
18502
+ if (current === void 0 || rank2(path21) < rank2(current)) modules.set(directory, path21);
18503
+ const text = session.texts[path21] ?? "";
18504
+ if (/settings\.gradle(?:\.kts)?$/u.test(path21) || path21.endsWith("pom.xml") && /<modules>/u.test(text)) {
18500
18505
  const root = roots.get(directory);
18501
- if (root === void 0 || rank2(path20) < rank2(root)) roots.set(directory, path20);
18506
+ if (root === void 0 || rank2(path21) < rank2(root)) roots.set(directory, path21);
18502
18507
  }
18503
18508
  }
18504
- const configOf = (path20) => {
18509
+ const configOf = (path21) => {
18505
18510
  let outer;
18506
18511
  for (const directory of roots.keys())
18507
- if (path20.startsWith(directory) && (outer === void 0 || directory.length < outer.length))
18512
+ if (path21.startsWith(directory) && (outer === void 0 || directory.length < outer.length))
18508
18513
  outer = directory;
18509
18514
  if (outer !== void 0) return roots.get(outer);
18510
18515
  let nearest;
18511
18516
  for (const directory of modules.keys())
18512
- if (path20.startsWith(directory) && (nearest === void 0 || directory.length > nearest.length))
18517
+ if (path21.startsWith(directory) && (nearest === void 0 || directory.length > nearest.length))
18513
18518
  nearest = directory;
18514
18519
  return nearest === void 0 ? "" : modules.get(nearest);
18515
18520
  };
18516
- const output = (path20) => [...modules.keys()].some(
18517
- (directory) => path20.startsWith(`${directory}build/`) || path20.startsWith(`${directory}target/`)
18521
+ const output = (path21) => [...modules.keys()].some(
18522
+ (directory) => path21.startsWith(`${directory}build/`) || path21.startsWith(`${directory}target/`)
18518
18523
  );
18519
18524
  const groups = /* @__PURE__ */ new Map();
18520
18525
  for (const entry of session.readable) {
@@ -18529,13 +18534,13 @@ var JavaMapAnalyzer = class _JavaMapAnalyzer {
18529
18534
  if (signal.aborted) throw new ProjectEvidenceError("PROJECT_READ_CANCELLED", true);
18530
18535
  const files = /* @__PURE__ */ Object.create(null);
18531
18536
  const rootBuilds = configPath ? BUILD_FILES.map((name) => `${directoryOf(configPath)}${name}`).filter(
18532
- (path20) => builds.includes(path20)
18537
+ (path21) => builds.includes(path21)
18533
18538
  ) : [];
18534
- for (const path20 of [...groups.get(configPath) ?? [], ...rootBuilds]) {
18535
- const text = session.texts[path20];
18539
+ for (const path21 of [...groups.get(configPath) ?? [], ...rootBuilds]) {
18540
+ const text = session.texts[path21];
18536
18541
  if (text === void 0)
18537
18542
  throw new ProjectEvidenceError("PROJECT_MAP_PROTOCOL_INVALID", false);
18538
- files[path20] = text;
18543
+ files[path21] = text;
18539
18544
  }
18540
18545
  const input = {
18541
18546
  contextRef: digestValue({
@@ -18577,7 +18582,7 @@ var JavaMapAnalyzer = class _JavaMapAnalyzer {
18577
18582
  const prior = JavaStateSchema.safeParse(previous?.state).data;
18578
18583
  const incremental = previous && prior?.basis === basis ? {
18579
18584
  changed: Object.keys(request.files).filter(
18580
- (path20) => digests.get(path20) !== previous.digests.get(path20)
18585
+ (path21) => digests.get(path21) !== previous.digests.get(path21)
18581
18586
  ),
18582
18587
  state: prior.java
18583
18588
  } : void 0;
@@ -18600,20 +18605,20 @@ var JavaMapAnalyzer = class _JavaMapAnalyzer {
18600
18605
  ]
18601
18606
  );
18602
18607
  validateMapAnalysis(analysis, input);
18603
- const state = facts.state && { basis, java: facts.state };
18608
+ const state2 = facts.state && { basis, java: facts.state };
18604
18609
  if (!facts.focus) {
18605
- session.accept(analysis, { state });
18610
+ session.accept(analysis, { state: state2 });
18606
18611
  continue;
18607
18612
  }
18608
18613
  const focus = new Set(facts.focus);
18609
- if (!incremental || facts.focus.some((path20) => !Object.hasOwn(request.files, path20)) || incremental.changed.some((path20) => !focus.has(path20)))
18614
+ if (!incremental || facts.focus.some((path21) => !Object.hasOwn(request.files, path21)) || incremental.changed.some((path21) => !focus.has(path21)))
18610
18615
  throw new ProjectEvidenceError("PROJECT_MAP_PROTOCOL_INVALID", false);
18611
18616
  analysis.objects = analysis.objects.filter((object2) => focus.has(object2.anchor.path));
18612
18617
  analysis.relations = analysis.relations.filter((relation) => focus.has(relation.anchor.path));
18613
18618
  analysis.notes = analysis.notes.filter((note) => focus.has(note.anchor.path));
18614
18619
  session.accept(analysis, {
18615
- state,
18616
- linked: analysis.parsedFiles.filter((path20) => !focus.has(path20))
18620
+ state: state2,
18621
+ linked: analysis.parsedFiles.filter((path21) => !focus.has(path21))
18617
18622
  });
18618
18623
  }
18619
18624
  }
@@ -18928,12 +18933,12 @@ var PYTHON_STANDARD_LIBRARY = /* @__PURE__ */ new Set([
18928
18933
  // src/project-map-language-python.ts
18929
18934
  var CONFIGURATION = ["pyrightconfig.json", "pyproject.toml", "setup.cfg"];
18930
18935
  var pythonConfig = /(?:^|\/)(?:pyrightconfig\.json|pyproject\.toml|setup\.cfg)$/u;
18931
- var directoryOf2 = (path20) => path20.slice(0, path20.lastIndexOf("/") + 1);
18936
+ var directoryOf2 = (path21) => path21.slice(0, path21.lastIndexOf("/") + 1);
18932
18937
  var DEFAULT_PYTHON = { major: 3, minor: 13 };
18933
18938
  var PYTHON_MAP_LANGUAGE = Object.freeze({
18934
18939
  id: "pyright-1.1.414-map-v14",
18935
- claims: (path20) => /\.pyi?$/u.test(path20),
18936
- reads: (path20) => pythonConfig.test(path20),
18940
+ claims: (path21) => /\.pyi?$/u.test(path21),
18941
+ reads: (path21) => pythonConfig.test(path21),
18937
18942
  // An absolute import names the standard library or a distribution's top-level package.
18938
18943
  importName: (specifier) => {
18939
18944
  const top = specifier.split(".", 1)[0] ?? specifier;
@@ -18989,16 +18994,16 @@ var PythonMapAnalyzer = class {
18989
18994
  }
18990
18995
  async analyze(session, signal) {
18991
18996
  const roots = /* @__PURE__ */ new Map();
18992
- for (const path20 of session.readable.map((entry) => entry.path).filter((path21) => pythonConfig.test(path21))) {
18993
- const directory = directoryOf2(path20);
18997
+ for (const path21 of session.readable.map((entry) => entry.path).filter((path22) => pythonConfig.test(path22))) {
18998
+ const directory = directoryOf2(path21);
18994
18999
  const current = roots.get(directory);
18995
19000
  const rank2 = (file2) => CONFIGURATION.indexOf(file2.slice(directory.length));
18996
- if (current === void 0 || rank2(path20) < rank2(current)) roots.set(directory, path20);
19001
+ if (current === void 0 || rank2(path21) < rank2(current)) roots.set(directory, path21);
18997
19002
  }
18998
- const rootOf = (path20) => {
19003
+ const rootOf = (path21) => {
18999
19004
  let best;
19000
19005
  for (const directory of roots.keys())
19001
- if (path20.startsWith(directory) && (best === void 0 || directory.length > best.length))
19006
+ if (path21.startsWith(directory) && (best === void 0 || directory.length > best.length))
19002
19007
  best = directory;
19003
19008
  return best === void 0 ? "" : roots.get(best);
19004
19009
  };
@@ -19013,11 +19018,11 @@ var PythonMapAnalyzer = class {
19013
19018
  for (const configPath of [...groups.keys()].sort()) {
19014
19019
  if (signal.aborted) throw new ProjectEvidenceError("PROJECT_READ_CANCELLED", true);
19015
19020
  const files = /* @__PURE__ */ Object.create(null);
19016
- for (const path20 of [...groups.get(configPath) ?? [], ...configPath ? [configPath] : []]) {
19017
- const text = session.texts[path20];
19021
+ for (const path21 of [...groups.get(configPath) ?? [], ...configPath ? [configPath] : []]) {
19022
+ const text = session.texts[path21];
19018
19023
  if (text === void 0)
19019
19024
  throw new ProjectEvidenceError("PROJECT_MAP_PROTOCOL_INVALID", false);
19020
- files[path20] = text;
19025
+ files[path21] = text;
19021
19026
  }
19022
19027
  const input = {
19023
19028
  contextRef: digestValue({
@@ -19063,8 +19068,8 @@ var PythonMapAnalyzer = class {
19063
19068
  }
19064
19069
  async references(input, references, signal, observe) {
19065
19070
  const files = /* @__PURE__ */ Object.create(null);
19066
- for (const [path20, value] of Object.entries(input.files))
19067
- if (this.claims(path20) || pythonConfig.test(path20)) files[path20] = value;
19071
+ for (const [path21, value] of Object.entries(input.files))
19072
+ if (this.claims(path21) || pythonConfig.test(path21)) files[path21] = value;
19068
19073
  const facts = await this.operation(
19069
19074
  {
19070
19075
  ...input,
@@ -19121,9 +19126,9 @@ var miniprogramEventOf = (target) => {
19121
19126
  // src/project-map-language-typescript.ts
19122
19127
  var TYPESCRIPT_MAP_LANGUAGE = Object.freeze({
19123
19128
  id: "typescript-7.0.2-map-v35",
19124
- claims: (path20) => /\.[cm]?[jt]sx?$/u.test(path20),
19129
+ claims: (path21) => /\.[cm]?[jt]sx?$/u.test(path21),
19125
19130
  readsRequests: true,
19126
- reads: (path20) => path20.endsWith(".json") || path20.endsWith(".wxml") || path20 === "pnpm-workspace.yaml",
19131
+ reads: (path21) => path21.endsWith(".json") || path21.endsWith(".wxml") || path21 === "pnpm-workspace.yaml",
19127
19132
  create: () => new TypeScriptMapAnalyzer()
19128
19133
  });
19129
19134
  var WORKERS_AT_ONCE = Math.min(4, availableParallelism());
@@ -19150,7 +19155,7 @@ var KeptDiscoverySchema = external_exports.object({
19150
19155
  installed: external_exports.string(),
19151
19156
  files: external_exports.array(external_exports.tuple([external_exports.string(), external_exports.string().nullable(), external_exports.string().nullable()]))
19152
19157
  }).strict();
19153
- var sameShape = (left, right) => left.installed === right.installed && left.files.size === right.files.size && [...left.files].every(([path20, { shape }]) => right.files.get(path20)?.shape === shape);
19158
+ var sameShape = (left, right) => left.installed === right.installed && left.files.size === right.files.size && [...left.files].every(([path21, { shape }]) => right.files.get(path21)?.shape === shape);
19154
19159
  var stopUnconfirmed = async (runs) => (await Promise.allSettled(runs)).flatMap((settled) => settled.status === "rejected" ? [settled.reason] : []).find((reason) => reason instanceof ProjectMapStopUnconfirmedError);
19155
19160
  async function inOrder(tasks, take, signal, sizes) {
19156
19161
  const stopping = new AbortController();
@@ -19314,9 +19319,9 @@ var TypeScriptMapAnalyzer = class {
19314
19319
  first = void 0;
19315
19320
  validateMapAnalysis(analysis, input);
19316
19321
  if (!analysis.requiredFiles.length) return analysis;
19317
- const required2 = analysis.requiredFiles.map((path20) => {
19318
- const entry = byPath.get(path20);
19319
- if (!entry || Object.hasOwn(texts, path20))
19322
+ const required2 = analysis.requiredFiles.map((path21) => {
19323
+ const entry = byPath.get(path21);
19324
+ if (!entry || Object.hasOwn(texts, path21))
19320
19325
  throw new ProjectEvidenceError("PROJECT_MAP_PROTOCOL_INVALID", false);
19321
19326
  return entry;
19322
19327
  });
@@ -19336,7 +19341,7 @@ var TypeScriptMapAnalyzer = class {
19336
19341
  discovered: kept.discovered,
19337
19342
  shape: {
19338
19343
  installed: kept.installed,
19339
- files: new Map(kept.files.map(([path20, digest, shape2]) => [path20, { digest, shape: shape2 }]))
19344
+ files: new Map(kept.files.map(([path21, digest, shape2]) => [path21, { digest, shape: shape2 }]))
19340
19345
  }
19341
19346
  };
19342
19347
  const known = kept?.key === configurationKey ? kept.discovered : void 0;
@@ -19393,7 +19398,7 @@ var TypeScriptMapAnalyzer = class {
19393
19398
  key: configurationKey,
19394
19399
  discovered,
19395
19400
  installed: installed.digest,
19396
- files: [...shape.files].map(([path20, file2]) => [path20, file2.digest, file2.shape])
19401
+ files: [...shape.files].map(([path21, file2]) => [path21, file2.digest, file2.shape])
19397
19402
  });
19398
19403
  if (!admitted(discovered))
19399
19404
  throw new ProjectEvidenceError("PROJECT_MAP_PROTOCOL_INVALID", false);
@@ -19445,17 +19450,17 @@ var MAP_LANGUAGES = Object.freeze([
19445
19450
  ]);
19446
19451
  var mapAnalyzerSuite = (languages) => languages.map((language) => language.id).sort().join("+");
19447
19452
  var PROJECT_MAP_ANALYZER = mapAnalyzerSuite(MAP_LANGUAGES);
19448
- var mapCodePath = (path20) => MAP_LANGUAGES.some((language) => language.claims(path20));
19449
- var languageOf = (path20) => MAP_LANGUAGES.find((language) => language.claims(path20));
19450
- var mapReadsRequests = (path20) => languageOf(path20)?.readsRequests === true;
19451
- var mapLanguageOf = (path20) => languageOf(path20)?.id;
19453
+ var mapCodePath = (path21) => MAP_LANGUAGES.some((language) => language.claims(path21));
19454
+ var languageOf = (path21) => MAP_LANGUAGES.find((language) => language.claims(path21));
19455
+ var mapReadsRequests = (path21) => languageOf(path21)?.readsRequests === true;
19456
+ var mapLanguageOf = (path21) => languageOf(path21)?.id;
19452
19457
  var npmPackage = (specifier) => {
19453
19458
  if (specifier.startsWith("node:")) return "node:*";
19454
19459
  const parts = specifier.split("/");
19455
19460
  return specifier.startsWith("@") ? parts.slice(0, 2).join("/") : parts[0] ?? specifier;
19456
19461
  };
19457
19462
  var mapExternalImport = (sourcePath, specifier) => languageOf(sourcePath)?.importName?.(specifier) ?? npmPackage(specifier);
19458
- var mapImportTarget = (path20) => languageOf(path20)?.importTarget?.(path20) ?? path20;
19463
+ var mapImportTarget = (path21) => languageOf(path21)?.importTarget?.(path21) ?? path21;
19459
19464
 
19460
19465
  // src/project-map-view.ts
19461
19466
  var MAP_VIEW_FORMAT = "PROJECT_MAP_VIEW_V1";
@@ -19495,10 +19500,10 @@ var notFound = () => {
19495
19500
  };
19496
19501
  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";
19497
19502
  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.`;
19498
- var within = (path20, directory) => directory === "." || path20.startsWith(`${directory}/`);
19499
- var parentDirectory = (path20) => {
19500
- const slash = path20.lastIndexOf("/");
19501
- return slash < 0 ? "." : path20.slice(0, slash);
19503
+ var within = (path21, directory) => directory === "." || path21.startsWith(`${directory}/`);
19504
+ var parentDirectory = (path21) => {
19505
+ const slash = path21.lastIndexOf("/");
19506
+ return slash < 0 ? "." : path21.slice(0, slash);
19502
19507
  };
19503
19508
  var compareText2 = (left, right) => left < right ? -1 : left > right ? 1 : 0;
19504
19509
  var byCount = ([leftName, left], [rightName, right]) => right - left || compareText2(leftName, rightName);
@@ -19572,7 +19577,7 @@ function pageBlocks(view, head, whole, offset, budget) {
19572
19577
  if (offset === blocks.length) return materialize(0);
19573
19578
  return mapQueryPage(blocks.length - offset, materialize, (page) => page, budget);
19574
19579
  }
19575
- var inModule = (path20, module) => module.direct ? parentDirectory(path20) === module.directory : within(path20, module.directory);
19580
+ var inModule = (path21, module) => module.direct ? parentDirectory(path21) === module.directory : within(path21, module.directory);
19576
19581
  var moduleLabel = (module) => module.direct ? `${module.directory === "." ? "" : `${module.directory}/`}* (files directly here)` : `${module.directory}/`;
19577
19582
  function childModules(module, files) {
19578
19583
  if (module.direct) return [];
@@ -19627,9 +19632,9 @@ function mapProjectModules(entries) {
19627
19632
  (entry) => entry.state === "TEXT" && mapCodePath(entry.path) && !mapTestPath(entry.path)
19628
19633
  ).map((entry) => entry.path)
19629
19634
  );
19630
- return (path20) => {
19631
- if (mapTestPath(path20)) return void 0;
19632
- const module = modules.find((candidate) => inModule(path20, candidate));
19635
+ return (path21) => {
19636
+ if (mapTestPath(path21)) return void 0;
19637
+ const module = modules.find((candidate) => inModule(path21, candidate));
19633
19638
  return module && moduleLabel(module);
19634
19639
  };
19635
19640
  }
@@ -19727,12 +19732,12 @@ function loadMemberCalls(store, version2) {
19727
19732
  FROM project_map_relations
19728
19733
  WHERE version_ref = ? AND to_ref IS NULL AND json_extract(relation_json, '$.kind') = 'CALLS'
19729
19734
  AND json_extract(relation_json, '$.unresolvedReason') IN ('SYMBOL_NOT_RESOLVED', 'SYNTAX_ONLY')`).all(version2)) {
19730
- const path20 = String(row.path);
19735
+ const path21 = String(row.path);
19731
19736
  const target = String(row.target);
19732
19737
  const name = MEMBER_NAME.exec(target)?.[1];
19733
- const language = mapLanguageOf(path20);
19738
+ const language = mapLanguageOf(path21);
19734
19739
  if (!name || !language) continue;
19735
- const call = { from: String(row.from_ref), path: path20, line: Number(row.line), target };
19740
+ const call = { from: String(row.from_ref), path: path21, line: Number(row.line), target };
19736
19741
  const key = memberKey(language, name);
19737
19742
  const known = calls.get(key);
19738
19743
  if (known) known.push(call);
@@ -19793,10 +19798,10 @@ function loadCoverageNotes(store, version2) {
19793
19798
  if (!codes.includes(gap.code)) codes.push(gap.code);
19794
19799
  files.set(gap.path, codes);
19795
19800
  }
19796
- for (const [path20, codes] of files)
19801
+ for (const [path21, codes] of files)
19797
19802
  if (codes.length > 1 && codes.includes("NOT_IN_PARSED_CONTEXT"))
19798
19803
  files.set(
19799
- path20,
19804
+ path21,
19800
19805
  codes.filter((code) => code !== "NOT_IN_PARSED_CONTEXT")
19801
19806
  );
19802
19807
  const missing = [...notInstalled].sort();
@@ -19841,9 +19846,9 @@ function directoryView(facts, imports, coverage, entries, input, directory, pref
19841
19846
  const visiblePaths = new Set(visible.map((entry) => entry.path));
19842
19847
  const code = visible.filter((entry) => entry.state === "TEXT" && mapCodePath(entry.path)).map((entry) => entry.path);
19843
19848
  const modules = mapModules(directory, code);
19844
- const moduleOf = (path20) => modules.find((module) => inModule(path20, module));
19845
- const outside = (path20) => {
19846
- const parts = path20.split("/");
19849
+ const moduleOf = (path21) => modules.find((module) => inModule(path21, module));
19850
+ const outside = (path21) => {
19851
+ const parts = path21.split("/");
19847
19852
  return `${parts.slice(0, Math.min(2, parts.length - 1)).join("/") || "."}/ (outside)`;
19848
19853
  };
19849
19854
  const moduleImports = /* @__PURE__ */ new Map();
@@ -19867,8 +19872,8 @@ function directoryView(facts, imports, coverage, entries, input, directory, pref
19867
19872
  const blocks = [];
19868
19873
  if (modules.length > 1) {
19869
19874
  const sizes = /* @__PURE__ */ new Map();
19870
- for (const path20 of code) {
19871
- const module = moduleOf(path20);
19875
+ for (const path21 of code) {
19876
+ const module = moduleOf(path21);
19872
19877
  if (module) increment(sizes, moduleLabel(module));
19873
19878
  }
19874
19879
  blocks.push(
@@ -19897,18 +19902,18 @@ function directoryView(facts, imports, coverage, entries, input, directory, pref
19897
19902
  )}${packages.length > shown.length ? `, +${packages.length - shown.length} more` : ""}`
19898
19903
  );
19899
19904
  }
19900
- const lineCount = (path20) => {
19901
- const file2 = facts.files.get(path20);
19902
- const gaps = coverage.files.get(path20) ?? [];
19905
+ const lineCount = (path21) => {
19906
+ const file2 = facts.files.get(path21);
19907
+ const gaps = coverage.files.get(path21) ?? [];
19903
19908
  if (file2?.parsed === false) return `[not parsed${gaps.length ? `: ${gaps.join("; ")}` : ""}]`;
19904
19909
  return `${file2 ? `${file2.lines}L` : "?L"}${gaps.length ? ` [${gaps.join("; ")}]` : ""}`;
19905
19910
  };
19906
19911
  const codeDirectories = /* @__PURE__ */ new Set();
19907
- for (const path20 of code)
19908
- for (let parent = parentDirectory(path20); parent !== "." && !codeDirectories.has(parent); parent = parentDirectory(parent))
19912
+ for (const path21 of code)
19913
+ for (let parent = parentDirectory(path21); parent !== "." && !codeDirectories.has(parent); parent = parentDirectory(parent))
19909
19914
  codeDirectories.add(parent);
19910
- const groupOf = (path20) => {
19911
- let group = parentDirectory(path20);
19915
+ const groupOf = (path21) => {
19916
+ let group = parentDirectory(path21);
19912
19917
  for (let parent = group; parent !== "." && parent !== directory && !codeDirectories.has(parent); parent = parentDirectory(parent))
19913
19918
  group = parent;
19914
19919
  return group;
@@ -19940,11 +19945,11 @@ function directoryView(facts, imports, coverage, entries, input, directory, pref
19940
19945
  ]);
19941
19946
  }
19942
19947
  const detailed = [
19943
- ...code.map((path20) => {
19944
- const declarations2 = (facts.exported.get(path20) ?? []).map(({ text: text2 }) => text2);
19948
+ ...code.map((path21) => {
19949
+ const declarations2 = (facts.exported.get(path21) ?? []).map(({ text: text2 }) => text2);
19945
19950
  return [
19946
- path20,
19947
- `${path20} ${lineCount(path20)}${declarations2.length ? `: ${declarations2.join(", ")}` : ""}`
19951
+ path21,
19952
+ `${path21} ${lineCount(path21)}${declarations2.length ? `: ${declarations2.join(", ")}` : ""}`
19948
19953
  ];
19949
19954
  }),
19950
19955
  ...listedOther.map((entry) => [
@@ -19955,7 +19960,7 @@ function directoryView(facts, imports, coverage, entries, input, directory, pref
19955
19960
  ];
19956
19961
  const directories = /* @__PURE__ */ new Map();
19957
19962
  for (const entry of [
19958
- ...code.map((path20) => ({ path: path20, item: lineCount(path20) })),
19963
+ ...code.map((path21) => ({ path: path21, item: lineCount(path21) })),
19959
19964
  ...listedOther.map((entry2) => ({
19960
19965
  path: entry2.path,
19961
19966
  item: entry2.state === "TEXT" ? "" : `(${entry2.state})`
@@ -19983,10 +19988,10 @@ function directoryView(facts, imports, coverage, entries, input, directory, pref
19983
19988
  );
19984
19989
  const text = visible.filter((entry) => entry.state === "TEXT").length;
19985
19990
  const resolution = /* @__PURE__ */ new Map();
19986
- for (const path20 of code) {
19987
- const counts = facts.calls.get(path20);
19991
+ for (const path21 of code) {
19992
+ const counts = facts.calls.get(path21);
19988
19993
  if (!counts) continue;
19989
- const language = facts.files.get(path20)?.language ?? "unknown";
19994
+ const language = facts.files.get(path21)?.language ?? "unknown";
19990
19995
  const total = resolution.get(language) ?? { resolved: 0, unresolved: 0, external: 0 };
19991
19996
  total.resolved += counts.resolved;
19992
19997
  total.unresolved += counts.unresolved;
@@ -20043,8 +20048,8 @@ var DeclarationGroups = class {
20043
20048
  prefixes;
20044
20049
  showTests;
20045
20050
  memberCalls;
20046
- visible(path20) {
20047
- return mapPathAllowed(path20, this.prefixes) && (this.showTests || !mapTestPath(path20));
20051
+ visible(path21) {
20052
+ return mapPathAllowed(path21, this.prefixes) && (this.showTests || !mapTestPath(path21));
20048
20053
  }
20049
20054
  entry(object2, imported = false) {
20050
20055
  if (mapMiniprogramTemplate(object2.anchor.path)) return "(template)";
@@ -20089,11 +20094,11 @@ var DeclarationGroups = class {
20089
20094
  value.lines.push(line);
20090
20095
  aggregates.set(key, value);
20091
20096
  };
20092
- const dispatch = (arrow, label, ref2, path20, line) => {
20097
+ const dispatch = (arrow, label, ref2, path21, line) => {
20093
20098
  const other = graph.object(graph.owner(ref2));
20094
20099
  if (owned.has(other.id)) return;
20095
- if (!this.visible(path20)) {
20096
- if (mapPathAllowed(path20, this.prefixes)) omittedTests++;
20100
+ if (!this.visible(path21)) {
20101
+ if (mapPathAllowed(path21, this.prefixes)) omittedTests++;
20097
20102
  return;
20098
20103
  }
20099
20104
  add(arrow, label, other, line);
@@ -20250,7 +20255,7 @@ var DeclarationGroups = class {
20250
20255
  else files2.set(call.path, [item]);
20251
20256
  }
20252
20257
  lines.push(
20253
- ` \u2190 possible callers by name: ${[...files2].map(([path20, items]) => `${path20}: ${items.join(", ")}`).join("; ")}${inTests}`
20258
+ ` \u2190 possible callers by name: ${[...files2].map(([path21, items]) => `${path21}: ${items.join(", ")}`).join("; ")}${inTests}`
20254
20259
  );
20255
20260
  } else if (possibleInTests)
20256
20261
  lines.push(` \u2190 possible callers by name: ${possibleInTests} in test files (includeTests)`);
@@ -20286,14 +20291,14 @@ var DeclarationGroups = class {
20286
20291
  return { lines, neighbors: [...new Set(neighbors)] };
20287
20292
  }
20288
20293
  };
20289
- function fileView(store, coverage, graph, input, path20, prefixes) {
20290
- const entry = store.getEntry(input.version, path20);
20291
- if (!entry || !mapPathAllowed(path20, prefixes)) return notFound();
20292
- const showTests = input.includeTests === true || mapTestPath(path20);
20293
- const module = mapCodePath(path20) ? graph.objectsAt(path20).find((object2) => mapIsModule(object2)) : mapMiniprogramTemplate(path20) ? graph.objectsAt(path20).find((object2) => mapIsModule(object2) && object2.parsing === "PARSED") : void 0;
20294
- const gaps = coverage.files.get(path20) ?? [];
20294
+ function fileView(store, coverage, graph, input, path21, prefixes) {
20295
+ const entry = store.getEntry(input.version, path21);
20296
+ if (!entry || !mapPathAllowed(path21, prefixes)) return notFound();
20297
+ const showTests = input.includeTests === true || mapTestPath(path21);
20298
+ const module = mapCodePath(path21) ? graph.objectsAt(path21).find((object2) => mapIsModule(object2)) : mapMiniprogramTemplate(path21) ? graph.objectsAt(path21).find((object2) => mapIsModule(object2) && object2.parsing === "PARSED") : void 0;
20299
+ const gaps = coverage.files.get(path21) ?? [];
20295
20300
  const head = [
20296
- `PROJECT MAP \xB7 FILE ${path20} \xB7 ${entry.state !== "TEXT" ? entry.state : module ? module.parsing === "NOT_PARSED" ? `not parsed${gaps.length ? ` (${gaps.join("; ")})` : ""}; read it as text` : `${module.anchor.endLine} lines${gaps.length ? ` \xB7 ${gaps.join("; ")}` : ""}` : `${entry.byteLength} bytes, not analyzed; read it as text`}`
20301
+ `PROJECT MAP \xB7 FILE ${path21} \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`}`
20297
20302
  ];
20298
20303
  if (!module || entry.state !== "TEXT")
20299
20304
  return pageBlocks("FILE", head, [], input.offset ?? 0, input.outputBudget);
@@ -20313,7 +20318,7 @@ function fileView(store, coverage, graph, input, path20, prefixes) {
20313
20318
  tags.set(relation.from, list);
20314
20319
  }
20315
20320
  const describe3 = (object2) => [
20316
- `${object2.name} ${mapDeclarationLabel(object2)}${object2.anchor.path === path20 ? "" : ` (${object2.anchor.path})`}`,
20321
+ `${object2.name} ${mapDeclarationLabel(object2)}${object2.anchor.path === path21 ? "" : ` (${object2.anchor.path})`}`,
20317
20322
  ...tags.get(object2.id) ?? []
20318
20323
  ].join(" ");
20319
20324
  const declarations2 = [];
@@ -20328,11 +20333,11 @@ function fileView(store, coverage, graph, input, path20, prefixes) {
20328
20333
  );
20329
20334
  }
20330
20335
  const elsewhere = /* @__PURE__ */ new Map();
20331
- for (const object2 of graph.objectsAt(path20)) {
20336
+ for (const object2 of graph.objectsAt(path21)) {
20332
20337
  const parent = mapIsModule(object2) ? void 0 : graph.parent(object2.id);
20333
20338
  if (parent === void 0 || !graph.isAddressable(object2)) continue;
20334
20339
  const container = graph.object(parent);
20335
- if (mapIsModule(container) || container.anchor.path === path20) continue;
20340
+ if (mapIsModule(container) || container.anchor.path === path21) continue;
20336
20341
  const into = elsewhere.get(parent);
20337
20342
  if (into) into.push(object2);
20338
20343
  else elsewhere.set(parent, [object2]);
@@ -20346,7 +20351,7 @@ function fileView(store, coverage, graph, input, path20, prefixes) {
20346
20351
  if (declarations2.length) blocks.push(["DECLARATIONS (* exported)", ...declarations2].join("\n"));
20347
20352
  const imports = /* @__PURE__ */ new Set();
20348
20353
  const external = /* @__PURE__ */ new Set();
20349
- const fileObjects = graph.objectsAt(path20).map((object2) => object2.id);
20354
+ const fileObjects = graph.objectsAt(path21).map((object2) => object2.id);
20350
20355
  for (const relation of graph.relationsFrom(fileObjects)) {
20351
20356
  if (relation.kind !== "IMPORTS") continue;
20352
20357
  if (relation.to === void 0) external.add(relation.target);
@@ -20357,8 +20362,8 @@ function fileView(store, coverage, graph, input, path20, prefixes) {
20357
20362
  }
20358
20363
  const importers = /* @__PURE__ */ new Set();
20359
20364
  const testImporters = /* @__PURE__ */ new Set();
20360
- const imported = mapImportTarget(path20);
20361
- const packageModules = imported === path20 ? [module.id] : store.listEntries(input.version).filter((entry2) => mapImportTarget(entry2.path) === imported).flatMap((entry2) => graph.objectsAt(entry2.path).filter((object2) => mapIsModule(object2))).map((object2) => object2.id);
20365
+ const imported = mapImportTarget(path21);
20366
+ const packageModules = imported === path21 ? [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);
20362
20367
  for (const relation of graph.relationsTo(packageModules)) {
20363
20368
  if (relation.kind !== "IMPORTS") continue;
20364
20369
  const source = relation.anchor.path;
@@ -20386,16 +20391,16 @@ function fileView(store, coverage, graph, input, path20, prefixes) {
20386
20391
  if (scope.length) blocks.push(["MODULE SCOPE (top-level statements)", ...scope].join("\n"));
20387
20392
  return pageBlocks("FILE", head, blocks, input.offset ?? 0, input.outputBudget);
20388
20393
  }
20389
- function declarationView(graph, input, path20, prefixes, memberCalls) {
20394
+ function declarationView(graph, input, path21, prefixes, memberCalls) {
20390
20395
  const requested = input.depth ?? 1;
20391
20396
  if (!Number.isSafeInteger(requested) || requested < 1 || requested > MAP_VIEW_LIMITS.directedDepth)
20392
20397
  return invalid2();
20393
20398
  const both = (input.direction ?? "BOTH") === "BOTH";
20394
20399
  const depth = both ? Math.min(requested, MAP_VIEW_LIMITS.bothDepth) : requested;
20395
20400
  const { name, line } = input;
20396
- const selected = mapSelectDeclarations(graph, path20, name, line);
20401
+ const selected = mapSelectDeclarations(graph, path21, name, line);
20397
20402
  if (!selected.length) return notFound();
20398
- const showTests = input.includeTests === true || mapTestPath(path20);
20403
+ const showTests = input.includeTests === true || mapTestPath(path21);
20399
20404
  const groups = new DeclarationGroups(graph, input, prefixes, showTests, memberCalls);
20400
20405
  const blocks = [];
20401
20406
  const seen = /* @__PURE__ */ new Set();
@@ -20443,7 +20448,7 @@ function declarationView(graph, input, path20, prefixes, memberCalls) {
20443
20448
  );
20444
20449
  }
20445
20450
  const head = [
20446
- `PROJECT MAP \xB7 DECLARATION ${path20}${name === void 0 ? "" : ` ${name}`}${line === void 0 ? "" : ` line ${line}`} \xB7 direction ${input.direction ?? "BOTH"} \xB7 depth ${depth}${depth < requested ? ` (BOTH is limited to ${MAP_VIEW_LIMITS.bothDepth})` : ""}${prefixes.includes(".") ? "" : " \xB7 limited to authorized paths"}`,
20451
+ `PROJECT MAP \xB7 DECLARATION ${path21}${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"}`,
20447
20452
  ...truncated ? [`Expansion stopped at ${MAP_VIEW_LIMITS.declarations} declarations.`] : [],
20448
20453
  ...(input.direction ?? "BOTH") === "OUTGOING" ? [] : [callerCoverage(input.textSearch ?? DEFAULT_TEXT_SEARCH)]
20449
20454
  ];
@@ -20571,10 +20576,10 @@ var ProjectMapQuery = class {
20571
20576
  view(input, signal) {
20572
20577
  this.requireReadableMap(input.version, signal);
20573
20578
  const { offset, prefixes } = admission(input);
20574
- const path20 = normalizeProjectEvidencePath(input.path, true) || ".";
20579
+ const path21 = normalizeProjectEvidencePath(input.path, true) || ".";
20575
20580
  const view = mapView(
20576
20581
  this.store,
20577
- { ...input, path: path20, offset, allowedPathPrefixes: prefixes },
20582
+ { ...input, path: path21, offset, allowedPathPrefixes: prefixes },
20578
20583
  this.views
20579
20584
  );
20580
20585
  if (signal.aborted) throw new ProjectEvidenceError("PROJECT_READ_CANCELLED", true);
@@ -20775,13 +20780,13 @@ var ProjectMapSourceReader = class _ProjectMapSourceReader {
20775
20780
  */
20776
20781
  async readAll(expected) {
20777
20782
  if (this.signal.aborted) throw new ProjectEvidenceError("PROJECT_READ_CANCELLED", true);
20778
- const paths = expected.map(({ path: path20 }) => {
20779
- assertProjectEvidencePathNotSensitive(path20);
20780
- if (isProjectEvidenceTraversalExcluded(path20))
20783
+ const paths = expected.map(({ path: path21 }) => {
20784
+ assertProjectEvidencePathNotSensitive(path21);
20785
+ if (isProjectEvidenceTraversalExcluded(path21))
20781
20786
  throw new ProjectEvidenceError("PROJECT_FILE_NOT_ALLOWED", false);
20782
- return path20;
20787
+ return path21;
20783
20788
  });
20784
- const results = this.commit ? await this.commit.readAll(paths) : await concurrently(paths, (path20) => this.session.captureFile(path20));
20789
+ const results = this.commit ? await this.commit.readAll(paths) : await concurrently(paths, (path21) => this.session.captureFile(path21));
20785
20790
  for (const [index, { entry }] of results.entries()) {
20786
20791
  const wanted = expected[index];
20787
20792
  if (entry.state !== wanted?.state || entry.contentDigest !== wanted.contentDigest || entry.byteLength !== wanted.byteLength)
@@ -21502,8 +21507,8 @@ var CodeIndexStore = class {
21502
21507
  }
21503
21508
  }
21504
21509
  /** Stages what a language keeps of the build for the next one, stored with the version. */
21505
- appendMapLanguageState(buildRef, language, state) {
21506
- this.database.prepare("INSERT INTO project_map_staging (build_ref, kind, value_json) VALUES (?, ?, ?)").run(buildRef, "states", canonicalJson({ language, state }));
21510
+ appendMapLanguageState(buildRef, language, state2) {
21511
+ this.database.prepare("INSERT INTO project_map_staging (build_ref, kind, value_json) VALUES (?, ?, ?)").run(buildRef, "states", canonicalJson({ language, state: state2 }));
21507
21512
  }
21508
21513
  discardMapStage(buildRef) {
21509
21514
  this.database.prepare("DELETE FROM project_map_staging WHERE build_ref = ?").run(buildRef);
@@ -21523,7 +21528,7 @@ var CodeIndexStore = class {
21523
21528
  const staged = this.stageUnits(buildRef, paths, linked);
21524
21529
  const reused = linked ? this.database.prepare(`SELECT path, unit_ref FROM project_map_version_units
21525
21530
  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) })) : [];
21526
- if (reused.length !== (linked?.paths.size ?? 0) || reused.some(({ path: path20 }) => !paths.has(path20)) || staged.some(({ path: path20 }) => linked?.paths.has(path20)))
21531
+ if (reused.length !== (linked?.paths.size ?? 0) || reused.some(({ path: path21 }) => !paths.has(path21)) || staged.some(({ path: path21 }) => linked?.paths.has(path21)))
21527
21532
  throw new MapReplayConflict();
21528
21533
  const units = [...staged, ...reused].sort(
21529
21534
  (left, right) => left.path < right.path ? -1 : left.path > right.path ? 1 : 0
@@ -21577,7 +21582,7 @@ var CodeIndexStore = class {
21577
21582
  const member = this.database.prepare(
21578
21583
  "INSERT INTO project_map_version_units VALUES (?, ?, ?)"
21579
21584
  );
21580
- for (const { path: path20, unit } of reused) member.run(version2.version, path20, unit);
21585
+ for (const { path: path21, unit } of reused) member.run(version2.version, path21, unit);
21581
21586
  this.database.prepare("INSERT INTO project_map_coverage VALUES (?, ?)").run(version2.version, canonicalJson(coverage));
21582
21587
  }
21583
21588
  this.database.exec(`DELETE FROM project_map_publish_objects;
@@ -21632,7 +21637,7 @@ var CodeIndexStore = class {
21632
21637
  corrupt2();
21633
21638
  }
21634
21639
  if (linked) {
21635
- const unlinked = database.prepare("SELECT path FROM project_map_version_units WHERE version_ref = ?").all(linked.version).map((row) => String(row.path)).filter((path20) => !linked.paths.has(path20));
21640
+ const unlinked = database.prepare("SELECT path FROM project_map_version_units WHERE version_ref = ?").all(linked.version).map((row) => String(row.path)).filter((path21) => !linked.paths.has(path21));
21636
21641
  if (database.prepare(`SELECT 1 FROM project_map_objects gone
21637
21642
  WHERE gone.version_ref = ? AND gone.path IN (SELECT value FROM json_each(?))
21638
21643
  AND gone.entity_ref NOT IN (SELECT entity_ref FROM project_map_publish_objects)
@@ -21654,17 +21659,17 @@ var CodeIndexStore = class {
21654
21659
  const units = [];
21655
21660
  for (const row of database.prepare(`SELECT path FROM project_map_publish_objects
21656
21661
  UNION SELECT path FROM project_map_publish_relations ORDER BY path`).all()) {
21657
- const path20 = String(row.path);
21658
- const hash2 = createHash4("sha256").update(path20).update("\0");
21662
+ const path21 = String(row.path);
21663
+ const hash2 = createHash4("sha256").update(path21).update("\0");
21659
21664
  for (const [mark, statement] of [
21660
21665
  ["object", objects2],
21661
21666
  ["relation", relations],
21662
21667
  ["note", pathNotes]
21663
21668
  ])
21664
- for (const fact of statement.all(path20))
21669
+ for (const fact of statement.all(path21))
21665
21670
  for (const value of Object.values(fact))
21666
21671
  hash2.update(mark).update("\0").update(String(value)).update("\0");
21667
- units.push({ path: path20, unit: hash2.digest("hex") });
21672
+ units.push({ path: path21, unit: hash2.digest("hex") });
21668
21673
  }
21669
21674
  return units;
21670
21675
  }
@@ -21682,13 +21687,13 @@ var CodeIndexStore = class {
21682
21687
  "INSERT INTO project_map_unit_notes SELECT ?, * FROM project_map_publish_notes WHERE path = ?"
21683
21688
  );
21684
21689
  const member = database.prepare("INSERT INTO project_map_version_units VALUES (?, ?, ?)");
21685
- for (const { path: path20, unit } of units) {
21686
- if (insertUnit.run(unit, path20).changes) {
21687
- unitObjects.run(unit, path20);
21688
- unitRelations.run(unit, path20);
21689
- unitNotes.run(unit, path20);
21690
+ for (const { path: path21, unit } of units) {
21691
+ if (insertUnit.run(unit, path21).changes) {
21692
+ unitObjects.run(unit, path21);
21693
+ unitRelations.run(unit, path21);
21694
+ unitNotes.run(unit, path21);
21690
21695
  }
21691
- member.run(version2, path20, unit);
21696
+ member.run(version2, path21, unit);
21692
21697
  }
21693
21698
  }
21694
21699
  /**
@@ -21735,7 +21740,7 @@ var CodeIndexStore = class {
21735
21740
  "SELECT result_json FROM project_map_context_results WHERE version_ref = ? AND context_ref = ?"
21736
21741
  ).get(version2, contextRef);
21737
21742
  if (!context || !result) return corrupt2();
21738
- const { gaps, parsedFiles, state, paths } = JSON.parse(String(result.result_json));
21743
+ const { gaps, parsedFiles, state: state2, paths } = JSON.parse(String(result.result_json));
21739
21744
  const analysis = MapAnalysisSchema.parse({
21740
21745
  contexts: [JSON.parse(String(context.context_json))],
21741
21746
  objects: [],
@@ -21747,7 +21752,7 @@ var CodeIndexStore = class {
21747
21752
  });
21748
21753
  return {
21749
21754
  analysis,
21750
- ...state !== void 0 ? { state } : {},
21755
+ ...state2 !== void 0 ? { state: state2 } : {},
21751
21756
  ...paths !== void 0 ? { paths: external_exports.array(external_exports.string()).parse(paths) } : {}
21752
21757
  };
21753
21758
  }
@@ -21951,7 +21956,7 @@ var CodeIndexStore = class {
21951
21956
  }
21952
21957
  }
21953
21958
  entry(row) {
21954
- const state = String(row.entry_state);
21959
+ const state2 = String(row.entry_state);
21955
21960
  if (![
21956
21961
  "TEXT",
21957
21962
  "TYPE_RESTRICTED",
@@ -21960,11 +21965,11 @@ var CodeIndexStore = class {
21960
21965
  "NOT_READABLE",
21961
21966
  "SYMLINK",
21962
21967
  "UNSUPPORTED_ENTRY"
21963
- ].includes(state) || state === "TEXT" && typeof row.content_digest !== "string")
21968
+ ].includes(state2) || state2 === "TEXT" && typeof row.content_digest !== "string")
21964
21969
  return corrupt2();
21965
21970
  return Object.freeze({
21966
21971
  path: String(row.path),
21967
- state,
21972
+ state: state2,
21968
21973
  byteLength: Number(row.byte_length),
21969
21974
  ...typeof row.content_digest === "string" ? { contentDigest: row.content_digest } : {}
21970
21975
  });
@@ -21986,19 +21991,19 @@ function replayableContexts(parent, digests, claims) {
21986
21991
  const { analysis, paths } = parent.shell(ref);
21987
21992
  const files = /* @__PURE__ */ new Set([...codeFiles(context, analysis.parsedFiles, claims), ...paths ?? []]);
21988
21993
  factFiles.set(ref, files);
21989
- for (const path20 of files) {
21990
- const refs = sharing.get(path20) ?? /* @__PURE__ */ new Set();
21994
+ for (const path21 of files) {
21995
+ const refs = sharing.get(path21) ?? /* @__PURE__ */ new Set();
21991
21996
  refs.add(ref);
21992
- sharing.set(path20, refs);
21997
+ sharing.set(path21, refs);
21993
21998
  }
21994
21999
  if (!paths || !contextFiles(context).every(
21995
- (path20) => digests.get(path20) !== void 0 && digests.get(path20) === parent.entries.get(path20)
22000
+ (path21) => digests.get(path21) !== void 0 && digests.get(path21) === parent.entries.get(path21)
21996
22001
  ))
21997
22002
  analyzed.add(ref);
21998
22003
  }
21999
22004
  for (const ref of analyzed)
22000
- for (const path20 of factFiles.get(ref) ?? [])
22001
- for (const other of sharing.get(path20) ?? []) analyzed.add(other);
22005
+ for (const path21 of factFiles.get(ref) ?? [])
22006
+ for (const other of sharing.get(path21) ?? []) analyzed.add(other);
22002
22007
  const replayable = new Set([...parent.contexts.keys()].filter((ref) => !analyzed.has(ref)));
22003
22008
  return { replayable, sharing, factFiles };
22004
22009
  }
@@ -22030,8 +22035,8 @@ var ProjectMapAnalyzer = class {
22030
22035
  languages;
22031
22036
  observe;
22032
22037
  id;
22033
- claims(path20) {
22034
- return this.languages.some((language) => language.claims(path20));
22038
+ claims(path21) {
22039
+ return this.languages.some((language) => language.claims(path21));
22035
22040
  }
22036
22041
  // A context holds one language's code, so its requests are that language's.
22037
22042
  async references(input, references, signal, until) {
@@ -22040,8 +22045,8 @@ var ProjectMapAnalyzer = class {
22040
22045
  return language?.references ? language.references(input, references, signal, this.observe, until) : { pages: references.map(() => null), requiredFiles: [] };
22041
22046
  }
22042
22047
  // A context's compiler diagnostics, undefined for a language without a compiler to ask.
22043
- diagnostics(input, path20, signal) {
22044
- return this.languages.find((language) => language.claims(path20))?.diagnostics?.(input, signal, this.observe);
22048
+ diagnostics(input, path21, signal) {
22049
+ return this.languages.find((language) => language.claims(path21))?.diagnostics?.(input, signal, this.observe);
22045
22050
  }
22046
22051
  async analyze(reader, entries, installed, signal, consume, keep, parent) {
22047
22052
  const result = {
@@ -22065,7 +22070,7 @@ var ProjectMapAnalyzer = class {
22065
22070
  const digests = /* @__PURE__ */ new Map();
22066
22071
  for (const entry of entries)
22067
22072
  if (entry.contentDigest) digests.set(entry.path, entry.contentDigest);
22068
- const claims = (path20) => this.claims(path20);
22073
+ const claims = (path21) => this.claims(path21);
22069
22074
  const { replayable, sharing, factFiles } = parent ? replayableContexts(parent, digests, claims) : {
22070
22075
  replayable: /* @__PURE__ */ new Set(),
22071
22076
  sharing: /* @__PURE__ */ new Map(),
@@ -22077,16 +22082,16 @@ var ProjectMapAnalyzer = class {
22077
22082
  const linked = /* @__PURE__ */ new Set();
22078
22083
  const analyzedFiles = /* @__PURE__ */ new Set();
22079
22084
  const stagedPaths = /* @__PURE__ */ new Set();
22080
- const requestDigest = (request, files2) => digestValue({ request, files: files2.map((path20) => [path20, digests.get(path20) ?? null]) });
22085
+ const requestDigest = (request, files2) => digestValue({ request, files: files2.map((path21) => [path21, digests.get(path21) ?? null]) });
22081
22086
  const replaysDigest = (contextRef2, digest) => parent !== void 0 && replayable.has(contextRef2) && parent.contexts.get(contextRef2)?.requestDigest === digest;
22082
22087
  const replays = (contextRef2, request, files2) => replaysDigest(contextRef2, requestDigest(request, files2));
22083
22088
  const reuse = (contextRef2, request, files2) => {
22084
22089
  const digest = requestDigest(request, files2);
22085
22090
  requests.set(contextRef2, digest);
22086
22091
  if (!parent || !replaysDigest(contextRef2, digest)) return void 0;
22087
- const { analysis, state, paths } = parent.shell(contextRef2);
22092
+ const { analysis, state: state2, paths } = parent.shell(contextRef2);
22088
22093
  if (!paths) return invalidParent();
22089
- if (state !== void 0) states.set(contextRef2, state);
22094
+ if (state2 !== void 0) states.set(contextRef2, state2);
22090
22095
  replayed.set(contextRef2, paths);
22091
22096
  this.observe?.({
22092
22097
  operation: "REUSE",
@@ -22098,8 +22103,8 @@ var ProjectMapAnalyzer = class {
22098
22103
  };
22099
22104
  const previous = (contextRef2) => {
22100
22105
  if (!parent?.contexts.has(contextRef2)) return void 0;
22101
- const state = parent.state(contextRef2);
22102
- return state === void 0 ? void 0 : { state, digests: parent.entries };
22106
+ const state2 = parent.state(contextRef2);
22107
+ return state2 === void 0 ? void 0 : { state: state2, digests: parent.entries };
22103
22108
  };
22104
22109
  const decode3 = (value) => {
22105
22110
  if (!value?.content) throw new ProjectEvidenceError("PROJECT_MAP_SOURCE_CHANGED", true);
@@ -22118,7 +22123,7 @@ var ProjectMapAnalyzer = class {
22118
22123
  const ref = analysis.contexts[0]?.ref ?? "";
22119
22124
  if (options?.linked?.length) {
22120
22125
  if (!parent || analysis.contexts.length !== 1) return invalidParent();
22121
- for (const path20 of options.linked) linked.add(path20);
22126
+ for (const path21 of options.linked) linked.add(path21);
22122
22127
  this.observe?.({
22123
22128
  operation: "LINK",
22124
22129
  phase: "FINISHED",
@@ -22145,7 +22150,7 @@ var ProjectMapAnalyzer = class {
22145
22150
  });
22146
22151
  for (const file2 of analysis.parsedFiles) parsed.add(file2);
22147
22152
  const staged = factPaths(analysis);
22148
- for (const path20 of staged) stagedPaths.add(path20);
22153
+ for (const path21 of staged) stagedPaths.add(path21);
22149
22154
  for (const context of analysis.contexts) {
22150
22155
  for (const file2 of context.configurationFiles) configurationInputs.add(file2);
22151
22156
  if (!replayed.has(context.ref))
@@ -22154,10 +22159,10 @@ var ProjectMapAnalyzer = class {
22154
22159
  }
22155
22160
  for (const gap of analysis.gaps) result.gaps.push(gap);
22156
22161
  const requestDigest2 = requests.get(ref);
22157
- const state = states.get(ref);
22162
+ const state2 = states.get(ref);
22158
22163
  consume(analysis, {
22159
22164
  ...requestDigest2 ? { requestDigest: requestDigest2 } : {},
22160
- ...state !== void 0 ? { state } : {},
22165
+ ...state2 !== void 0 ? { state: state2 } : {},
22161
22166
  paths: replayed.get(ref) ?? [.../* @__PURE__ */ new Set([...staged, ...options?.linked ?? []])].sort()
22162
22167
  });
22163
22168
  };
@@ -22176,9 +22181,9 @@ var ProjectMapAnalyzer = class {
22176
22181
  reuse,
22177
22182
  replays,
22178
22183
  previous,
22179
- configuration: (path20) => configurationInputs.add(path20),
22184
+ configuration: (path21) => configurationInputs.add(path21),
22180
22185
  kept: parent?.kept(language.id),
22181
- keep: (state) => keep(language.id, state),
22186
+ keep: (state2) => keep(language.id, state2),
22182
22187
  observe: this.observe
22183
22188
  },
22184
22189
  signal
@@ -22215,12 +22220,12 @@ var ProjectMapAnalyzer = class {
22215
22220
  if (files.objects.length) accept(files);
22216
22221
  if (parent && (replayed.size || linked.size)) {
22217
22222
  for (const ref of replayed.keys())
22218
- for (const path20 of factFiles.get(ref) ?? invalidParent())
22219
- if (analyzedFiles.has(path20) || [...sharing.get(path20) ?? []].some((other) => !replayed.has(other)))
22223
+ for (const path21 of factFiles.get(ref) ?? invalidParent())
22224
+ if (analyzedFiles.has(path21) || [...sharing.get(path21) ?? []].some((other) => !replayed.has(other)))
22220
22225
  throw new MapReplayConflict();
22221
- for (const paths of replayed.values()) for (const path20 of paths) linked.add(path20);
22222
- for (const path20 of linked)
22223
- if (analyzedFiles.has(path20) || stagedPaths.has(path20)) throw new MapReplayConflict();
22226
+ for (const paths of replayed.values()) for (const path21 of paths) linked.add(path21);
22227
+ for (const path21 of linked)
22228
+ if (analyzedFiles.has(path21) || stagedPaths.has(path21)) throw new MapReplayConflict();
22224
22229
  parent.link([...linked]);
22225
22230
  }
22226
22231
  result.parsedFiles = [...parsed].sort();
@@ -22257,12 +22262,12 @@ var ProjectMapReferenceQuery = class {
22257
22262
  return source;
22258
22263
  }
22259
22264
  // The compiler contexts a file is in.
22260
- contexts(version2, path20) {
22265
+ contexts(version2, path21) {
22261
22266
  return this.store.database.prepare(`SELECT DISTINCT c.context_ref, c.context_json
22262
22267
  FROM project_map_contexts c, json_each(c.context_json, '$.inputFiles') f
22263
22268
  WHERE c.version_ref = ? AND f.value = ?
22264
22269
  AND json_extract(c.context_json, '$.mode') != 'SYNTAX_ONLY'
22265
- ORDER BY c.context_ref`).all(version2, path20).map((value) => MapContextSchema.parse(JSON.parse(String(value.context_json))));
22270
+ ORDER BY c.context_ref`).all(version2, path21).map((value) => MapContextSchema.parse(JSON.parse(String(value.context_json))));
22266
22271
  }
22267
22272
  // A context's files as the version captured them.
22268
22273
  entries(version2, context) {
@@ -22297,7 +22302,7 @@ var ProjectMapReferenceQuery = class {
22297
22302
  * A context's compiler diagnostics: the stored result of a compile of the same inputs, or a
22298
22303
  * compile's, stored for the next. Undefined for a language without a compiler to ask.
22299
22304
  */
22300
- async compileDiagnostics(version2, source, context, path20, signal) {
22305
+ async compileDiagnostics(version2, source, context, path21, signal) {
22301
22306
  const key = digestValue({
22302
22307
  operation: "DIAGNOSTICS",
22303
22308
  inputs: this.compileInputs(version2, source, context)
@@ -22305,7 +22310,7 @@ var ProjectMapReferenceQuery = class {
22305
22310
  const stored = this.store.compileResults(version2, [key]);
22306
22311
  if (stored.has(key)) return MapDiagnosticsSchema.parse(stored.get(key));
22307
22312
  const { reader, request } = await this.open(version2, source, context, signal);
22308
- const result = await this.analyzer.diagnostics(request, path20, signal);
22313
+ const result = await this.analyzer.diagnostics(request, path21, signal);
22309
22314
  await reader.assertStable();
22310
22315
  if (!result) return void 0;
22311
22316
  if (result.requiredFiles.length)
@@ -22379,7 +22384,7 @@ var ProjectMapReferenceQuery = class {
22379
22384
  /** The configurations of the contexts a version's files are in. */
22380
22385
  contextConfigurations(version2, paths) {
22381
22386
  return paths.flatMap(
22382
- (path20) => this.contexts(version2, path20).flatMap((context) => context.configPath ?? [])
22387
+ (path21) => this.contexts(version2, path21).flatMap((context) => context.configPath ?? [])
22383
22388
  );
22384
22389
  }
22385
22390
  /**
@@ -22405,8 +22410,8 @@ var ProjectMapReferenceQuery = class {
22405
22410
  unchecked.push(configPath);
22406
22411
  continue;
22407
22412
  }
22408
- const [path20] = context.rootFiles ?? context.inputFiles;
22409
- const result = path20 === void 0 ? void 0 : await this.compileDiagnostics(input.version, source, context, path20, signal);
22413
+ const [path21] = context.rootFiles ?? context.inputFiles;
22414
+ const result = path21 === void 0 ? void 0 : await this.compileDiagnostics(input.version, source, context, path21, signal);
22410
22415
  if (!result) continue;
22411
22416
  const found = new Map(
22412
22417
  result.diagnostics.map((item) => [
@@ -22437,9 +22442,9 @@ var ProjectMapReferenceQuery = class {
22437
22442
  const compiles = /* @__PURE__ */ new Map();
22438
22443
  for (const ref of input.refs) {
22439
22444
  const object2 = requireMapObject(this.store, input.version, { entityRef: ref }, ["."]);
22440
- const path20 = object2.anchor.path;
22441
- const contexts = contextsOf.get(path20) ?? this.contexts(input.version, path20);
22442
- contextsOf.set(path20, contexts);
22445
+ const path21 = object2.anchor.path;
22446
+ const contexts = contextsOf.get(path21) ?? this.contexts(input.version, path21);
22447
+ contextsOf.set(path21, contexts);
22443
22448
  const readable = object2.symbolStart === void 0 ? [] : contexts;
22444
22449
  found.set(ref, {
22445
22450
  uses: [],
@@ -22499,8 +22504,8 @@ var ProjectMapReferenceQuery = class {
22499
22504
  );
22500
22505
  if (!prefixes.length || prefixes.length > 64)
22501
22506
  throw new ProjectEvidenceError("PROJECT_READ_INPUT_INVALID", false);
22502
- const { path: path20, name, line, entityRef, locator } = input;
22503
- if (path20 === void 0 !== (name === void 0) || line !== void 0 && name === void 0)
22507
+ const { path: path21, name, line, entityRef, locator } = input;
22508
+ if (path21 === void 0 !== (name === void 0) || line !== void 0 && name === void 0)
22504
22509
  throw new ProjectEvidenceError("PROJECT_READ_INPUT_INVALID", false);
22505
22510
  const selection = mapQuerySelection(
22506
22511
  { path: input.within, kinds: input.kinds },
@@ -22513,7 +22518,7 @@ var ProjectMapReferenceQuery = class {
22513
22518
  {
22514
22519
  entityRef,
22515
22520
  locator,
22516
- symbol: path20 !== void 0 && name !== void 0 ? { path: path20, name, ...line === void 0 ? {} : { line } } : void 0
22521
+ symbol: path21 !== void 0 && name !== void 0 ? { path: path21, name, ...line === void 0 ? {} : { line } } : void 0
22517
22522
  },
22518
22523
  prefixes
22519
22524
  );
@@ -22704,7 +22709,7 @@ var CodeIndex = class {
22704
22709
  { directory: source.directory.canonicalPath, digest: result.installedDigest },
22705
22710
  controller.signal,
22706
22711
  (unit, record2) => this.store.appendMapStage(stage, unit, record2),
22707
- (language, state) => this.store.appendMapLanguageState(stage, language, state),
22712
+ (language, state2) => this.store.appendMapLanguageState(stage, language, state2),
22708
22713
  parent && { ...parent, link: (paths) => linked.push(...paths) }
22709
22714
  );
22710
22715
  await reader.readAll(result.entries);
@@ -22758,8 +22763,8 @@ var CodeIndex = class {
22758
22763
  for (const entry of this.store.listEntries(candidate))
22759
22764
  if (entry.contentDigest) entries2.set(entry.path, entry.contentDigest);
22760
22765
  let changed = 0;
22761
- for (const [path20, digest] of digests) if (entries2.get(path20) !== digest) changed++;
22762
- for (const path20 of entries2.keys()) if (!digests.has(path20)) changed++;
22766
+ for (const [path21, digest] of digests) if (entries2.get(path21) !== digest) changed++;
22767
+ for (const path21 of entries2.keys()) if (!digests.has(path21)) changed++;
22763
22768
  if (!best || changed < best.changed) best = { version: candidate, entries: entries2, changed };
22764
22769
  }
22765
22770
  if (!best) return void 0;
@@ -22918,9 +22923,178 @@ var CodeIndex = class {
22918
22923
  };
22919
22924
 
22920
22925
  // src/project-map-change-diff.ts
22921
- import { lstat as lstat3, open as open2 } from "node:fs/promises";
22926
+ import { lstat as lstat3, open as open2, readFile as readFile2 } from "node:fs/promises";
22922
22927
  import path12 from "node:path";
22923
22928
 
22929
+ // src/project-map-change-runtime.ts
22930
+ import { transformSync } from "esbuild";
22931
+ var LOADERS = {
22932
+ ".ts": "ts",
22933
+ ".mts": "ts",
22934
+ ".cts": "ts",
22935
+ ".tsx": "tsx"
22936
+ };
22937
+ var DECORATED = /\b__decorat(?:orStart|eClass|eParam)\b/u;
22938
+ var PAIRS = 4e6;
22939
+ var mapErasable = (path21) => !path21.endsWith(".d.ts") && LOADERS[path21.slice(path21.lastIndexOf("."))] !== void 0;
22940
+ function erase(text, path21) {
22941
+ const loader = LOADERS[path21.slice(path21.lastIndexOf("."))];
22942
+ if (!loader) return void 0;
22943
+ let code;
22944
+ let map2;
22945
+ try {
22946
+ ({ code, map: map2 } = transformSync(text, {
22947
+ loader,
22948
+ sourcefile: path21,
22949
+ target: "esnext",
22950
+ // Lowered, so a decorator shows in the helpers it needs.
22951
+ supported: { decorators: false },
22952
+ jsx: "preserve",
22953
+ legalComments: "none",
22954
+ sourcemap: "external",
22955
+ logLevel: "silent",
22956
+ // Fields declared without a value are fields at run time under the standard semantics, and an
22957
+ // import is kept as written: whichever the project's settings, a change to either is code.
22958
+ tsconfigRaw: {
22959
+ compilerOptions: { useDefineForClassFields: true, verbatimModuleSyntax: true }
22960
+ }
22961
+ }));
22962
+ } catch {
22963
+ return void 0;
22964
+ }
22965
+ if (DECORATED.test(code)) return void 0;
22966
+ const lines = code.split("\n");
22967
+ if (lines.at(-1) === "") lines.pop();
22968
+ const from = sourceLines(map2, lines.length);
22969
+ if (!from) return void 0;
22970
+ return { lines: lines.map((line) => line.trim()), from };
22971
+ }
22972
+ var VLQ = new Map(
22973
+ [..."ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"].map((c, i) => [c, i])
22974
+ );
22975
+ function sourceLines(map2, count) {
22976
+ let mappings;
22977
+ try {
22978
+ mappings = String(JSON.parse(map2).mappings);
22979
+ } catch {
22980
+ return void 0;
22981
+ }
22982
+ const seen = [];
22983
+ let source = 0;
22984
+ const groups = mappings.split(";");
22985
+ for (const [generated, group] of groups.entries()) {
22986
+ for (const segment of group ? group.split(",") : []) {
22987
+ const fields2 = [];
22988
+ let value = 0;
22989
+ let shift = 0;
22990
+ for (const char of segment) {
22991
+ const digit = VLQ.get(char);
22992
+ if (digit === void 0) return void 0;
22993
+ value += (digit & 31) << shift;
22994
+ if (digit & 32) shift += 5;
22995
+ else {
22996
+ fields2.push(value & 1 ? -(value >>> 1) : value >>> 1);
22997
+ value = 0;
22998
+ shift = 0;
22999
+ }
23000
+ }
23001
+ if (fields2.length < 4) continue;
23002
+ source += fields2[2];
23003
+ if (fields2[2] === 0 && fields2[3] === 0) continue;
23004
+ const lines = seen[generated] ?? [];
23005
+ lines.push(source + 1);
23006
+ seen[generated] = lines;
23007
+ }
23008
+ }
23009
+ const last = [];
23010
+ const next = [];
23011
+ for (let line = 0, at; line < count; line++) {
23012
+ last[line] = at;
23013
+ const own = seen[line];
23014
+ if (own?.length) at = Math.max(...own);
23015
+ }
23016
+ for (let line = count - 1, at; line >= 0; line--) {
23017
+ next[line] = at;
23018
+ const own = seen[line];
23019
+ if (own?.length) at = Math.min(...own);
23020
+ }
23021
+ const from = [];
23022
+ for (let line = 0; line < count; line++) {
23023
+ const own = seen[line];
23024
+ if (own?.length) from.push([Math.min(...own), Math.max(...own)]);
23025
+ else if (last[line] === void 0 && next[line] === void 0) return void 0;
23026
+ else from.push([last[line] ?? 1, next[line] ?? Number.MAX_SAFE_INTEGER]);
23027
+ }
23028
+ return from;
23029
+ }
23030
+ var touches = (region, [start, end]) => region.from <= region.to ? start <= region.to && region.from <= end : start <= region.to && end >= region.from;
23031
+ function mapRuntimeLines(path21, baseText, text, hunks) {
23032
+ const before = erase(baseText, path21);
23033
+ const after = erase(text, path21);
23034
+ if (!before || !after) return void 0;
23035
+ const regions = hunks.map((hunk) => ({
23036
+ base: hunk.baseCount ? { from: hunk.baseStart, to: hunk.baseStart + hunk.baseCount - 1 } : { from: hunk.baseStart + 1, to: hunk.baseStart },
23037
+ working: hunk.count ? { from: hunk.start, to: hunk.start + hunk.count - 1 } : { from: hunk.start + 1, to: hunk.start }
23038
+ }));
23039
+ const outside = (erased, side) => erased.lines.filter(
23040
+ (_, line) => !regions.some((region) => touches(region[side], erased.from[line]))
23041
+ );
23042
+ const kept = outside(before, "base");
23043
+ const left = outside(after, "working");
23044
+ const bare = (line) => line?.replace(/,$/u, "");
23045
+ if (kept.length !== left.length || kept.some((line, at) => bare(line) !== bare(left[at])))
23046
+ return void 0;
23047
+ const lines = [];
23048
+ for (const region of regions) {
23049
+ const pick2 = (erased, side) => erased.lines.flatMap((line, at) => {
23050
+ const from = erased.from[at];
23051
+ return touches(side, from) ? [{ line, from }] : [];
23052
+ });
23053
+ lines.push(
23054
+ ...changedIn(pick2(before, region.base), pick2(after, region.working), region.working)
23055
+ );
23056
+ }
23057
+ const same3 = before.lines.length === after.lines.length && before.lines.every((line, at) => line === after.lines[at]);
23058
+ if (!same3 && !lines.length) return void 0;
23059
+ const seen = /* @__PURE__ */ new Set();
23060
+ return lines.sort(([a, b], [c, d]) => a - c || b - d).filter((range) => !seen.has(`${range}`) && Boolean(seen.add(`${range}`)));
23061
+ }
23062
+ function changedIn(base, working, region) {
23063
+ if (base.length === working.length && base.every((piece, at) => piece.line === working[at]?.line))
23064
+ return [];
23065
+ const whole = [region.from, region.to];
23066
+ if (base.length * working.length > PAIRS) return [whole];
23067
+ const width = working.length + 1;
23068
+ const table = new Uint32Array((base.length + 1) * width);
23069
+ for (let i = base.length - 1; i >= 0; i--)
23070
+ for (let j = working.length - 1; j >= 0; j--)
23071
+ table[i * width + j] = base[i]?.line === working[j]?.line ? table[(i + 1) * width + j + 1] + 1 : Math.max(table[(i + 1) * width + j], table[i * width + j + 1]);
23072
+ const pairs = [];
23073
+ for (let i = 0, j = 0; i < base.length && j < working.length; )
23074
+ if (base[i]?.line === working[j]?.line) pairs.push([i++, j++]);
23075
+ else if (table[(i + 1) * width + j] >= table[i * width + j + 1]) i++;
23076
+ else j++;
23077
+ const lines = [];
23078
+ const clamp = (start, end) => {
23079
+ const from = Math.max(start, region.from);
23080
+ const to = Math.min(end, region.to);
23081
+ lines.push(region.from <= region.to && from <= to ? [from, to] : whole);
23082
+ };
23083
+ const matched = new Set(pairs.map(([, j]) => j));
23084
+ for (const [j, piece] of working.entries()) if (!matched.has(j)) clamp(...piece.from);
23085
+ const bounds = [[-1, -1], ...pairs, [base.length, working.length]];
23086
+ for (let at = 1; at < bounds.length; at++) {
23087
+ const [i0, j0] = bounds[at - 1];
23088
+ const [i1, j1] = bounds[at];
23089
+ if (i1 - i0 <= 1) continue;
23090
+ clamp(
23091
+ j0 >= 0 ? working[j0].from[1] : region.from,
23092
+ j1 < working.length ? working[j1].from[0] : region.to
23093
+ );
23094
+ }
23095
+ return lines;
23096
+ }
23097
+
22924
23098
  // src/project-map-names.ts
22925
23099
  import { readFile } from "node:fs/promises";
22926
23100
  import path11 from "node:path";
@@ -23070,7 +23244,7 @@ async function readMapChanges(project, base, signal, options = { names: true })
23070
23244
  ...file2,
23071
23245
  baseText: (await git.run(["show", `${commit}:${file2.basePath}`], gitOptions(project, signal))).stdout.toString("utf8")
23072
23246
  };
23073
- const untracked = (await git.run(["ls-files", "--others", "--exclude-standard", "-z"], gitOptions(project, signal))).stdout.toString("utf8").split("\0").filter((path20) => path20 && !inExcludedDirectory(path20));
23247
+ const untracked = (await git.run(["ls-files", "--others", "--exclude-standard", "-z"], gitOptions(project, signal))).stdout.toString("utf8").split("\0").filter((path21) => path21 && !inExcludedDirectory(path21));
23074
23248
  for (const file2 of untracked)
23075
23249
  files.push({
23076
23250
  path: file2,
@@ -23083,6 +23257,7 @@ async function readMapChanges(project, base, signal, options = { names: true })
23083
23257
  // not analyze is told the way git tells it, by a NUL in its first 8000 bytes.
23084
23258
  binary: !mapLanguageOf(file2) && await startsBinary(path12.join(project, file2))
23085
23259
  });
23260
+ await eraseTypes(project, commit, files, signal);
23086
23261
  const stranded = options.names ? await strandedNames(
23087
23262
  project,
23088
23263
  files,
@@ -23092,6 +23267,22 @@ async function readMapChanges(project, base, signal, options = { names: true })
23092
23267
  ) : { names: [] };
23093
23268
  return { base, commit, files, quoted: parsed.quoted, stranded };
23094
23269
  }
23270
+ async function eraseTypes(project, commit, files, signal) {
23271
+ const erasable = [...files.entries()].filter(
23272
+ ([, file2]) => file2.status !== "DELETED" && !file2.binary && !mapTestPath(file2.path) && mapErasable(file2.path)
23273
+ );
23274
+ for (let at = 0; at < erasable.length; at += 8)
23275
+ await Promise.all(
23276
+ erasable.slice(at, at + 8).map(async ([index, file2]) => {
23277
+ const text = await readFile2(path12.join(project, file2.path), "utf8").catch(() => void 0);
23278
+ const baseText = file2.status === "ADDED" || !file2.basePath ? "" : await git.run(["show", `${commit}:${file2.basePath}`], gitOptions(project, signal)).then((result) => result.stdout.toString("utf8")).catch(() => void 0);
23279
+ if (text === void 0 || baseText === void 0) return;
23280
+ const hunks = file2.hunks.length ? file2.hunks : [{ baseStart: 0, baseCount: 0, start: 1, count: text.split("\n").length }];
23281
+ const runtime = mapRuntimeLines(file2.path, baseText, text, hunks);
23282
+ if (runtime) files[index] = { ...file2, runtime };
23283
+ })
23284
+ );
23285
+ }
23095
23286
  async function startsBinary(file2) {
23096
23287
  if (!(await lstat3(file2).catch(() => void 0))?.isFile()) return false;
23097
23288
  const handle = await open2(file2, "r").catch(() => void 0);
@@ -23182,7 +23373,7 @@ function mapPathNow(files) {
23182
23373
  (file2) => file2.basePath !== void 0 && file2.status !== "DELETED" ? [[file2.basePath, file2.path]] : []
23183
23374
  )
23184
23375
  );
23185
- return (path20) => moved.get(path20) ?? path20;
23376
+ return (path21) => moved.get(path21) ?? path21;
23186
23377
  }
23187
23378
  var overlaps = (lines, start, end) => lines.some(([from, to]) => from <= end && start <= to);
23188
23379
  var workingLine = (file2, line) => {
@@ -23206,7 +23397,7 @@ var NON_CODE = [
23206
23397
  [/(?:^|\/)\.env[^/]*$|\.(?:ya?ml|toml|ini|properties|conf|cfg)$/iu, "configuration"],
23207
23398
  [/\.(?:html?|jinja2?|j2|hbs|ejs|tmpl|tpl|gohtml|vue|svelte|wxml)$/iu, "template"]
23208
23399
  ];
23209
- var nonCodeKind = (path20) => NON_CODE.find(([pattern]) => pattern.test(path20))?.[1];
23400
+ var nonCodeKind = (path21) => NON_CODE.find(([pattern]) => pattern.test(path21))?.[1];
23210
23401
  var UNANALYZED = [
23211
23402
  [/\.(?:sh|bash|zsh|fish|ps1|bat|cmd)$/iu, "shell script"],
23212
23403
  [/\.(?:css|scss|sass|less|styl|wxss|acss)$/iu, "style sheet"],
@@ -23214,10 +23405,10 @@ var UNANALYZED = [
23214
23405
  [/\/$/u, "nested repository"]
23215
23406
  ];
23216
23407
  var DOCUMENTATION = /\.(?:md|mdx|markdown|rst|adoc)$|(?:^|\/)(?:LICENSE|NOTICE)[^/]*$/iu;
23217
- var unmappedKind = (path20, binary) => nonCodeKind(path20) ?? (binary ? "binary file" : DOCUMENTATION.test(path20) ? void 0 : UNANALYZED.find(([pattern]) => pattern.test(path20))?.[1] ?? "unanalyzed file");
23408
+ var unmappedKind = (path21, binary) => nonCodeKind(path21) ?? (binary ? "binary file" : DOCUMENTATION.test(path21) ? void 0 : UNANALYZED.find(([pattern]) => pattern.test(path21))?.[1] ?? "unanalyzed file");
23218
23409
 
23219
23410
  // src/project-map-changes.ts
23220
- import { readFile as readFile3 } from "node:fs/promises";
23411
+ import { readFile as readFile4 } from "node:fs/promises";
23221
23412
  import path14 from "node:path";
23222
23413
 
23223
23414
  // src/project-map-change-types.ts
@@ -23281,7 +23472,7 @@ var LITERAL = /(["'`])((?:\\.|(?!\1)[^\\])*)\1/gu;
23281
23472
  var MOUNTING = /(?:\b(?:prefix|root_path|base_path|basePath|baseURL|baseUrl)\s*[=:]|\b(?:Group|Route|Mount|mount|use|include_router|PathPrefix|StripPrefix)\s*\()\s*$/u;
23282
23473
  var LIMIT2 = Object.freeze({ routes: 40, clients: 5 });
23283
23474
  var ROUTE = /^(?:[A-Z]+(?:\|[A-Z]+)* +)?\/\S*$/u;
23284
- var segments = (path20) => path20.split("/").filter(Boolean).map((text) => ({ text, param: PARAM.test(text) || /[{}$<>%]/u.test(text) }));
23475
+ var segments = (path21) => path21.split("/").filter(Boolean).map((text) => ({ text, param: PARAM.test(text) || /[{}$<>%]/u.test(text) }));
23285
23476
  function mapRouteLabel(label) {
23286
23477
  const match = /^([A-Z]+(?:\|[A-Z]+)*) +(\S.*)$/u.exec(label);
23287
23478
  return match ? { methods: (match[1] ?? "").split("|"), path: match[2] ?? "" } : { path: label };
@@ -23314,10 +23505,10 @@ function requestedPath(literal3, joined) {
23314
23505
  const match = /^(?:https?:\/\/[^/\s]+|(?:\$\{[^}]*\})+|@\{|redirect:|forward:)?(\/[^\s?#()"'`,;|]*)/u.exec(
23315
23506
  literal3
23316
23507
  ) ?? void 0;
23317
- const path20 = match?.[1];
23318
- if (!path20 || path20.startsWith("//") || path20.length < 3) return void 0;
23319
- const parts = segments(path20);
23320
- if (joined && path20.endsWith("/")) parts.push({ text: "*", param: true });
23508
+ const path21 = match?.[1];
23509
+ if (!path21 || path21.startsWith("//") || path21.length < 3) return void 0;
23510
+ const parts = segments(path21);
23511
+ if (joined && path21.endsWith("/")) parts.push({ text: "*", param: true });
23321
23512
  return parts;
23322
23513
  }
23323
23514
  var same = (route, requested) => route.param || !requested.param && route.text === requested.text;
@@ -23422,6 +23613,15 @@ var routeClientsLine = ({ route, removed, clients }) => `${JSON.stringify(route)
23422
23613
  var KINDS = /* @__PURE__ */ new Set(["PROPERTY", "TYPE", "INTERFACE", "ENUM"]);
23423
23614
  var READ_MS = 2e4;
23424
23615
  var mapIsShape = (object2) => KINDS.has(object2.kind) && object2.execution !== "CLOSURE";
23616
+ var TYPE_KINDS = /* @__PURE__ */ new Set(["TYPE", "INTERFACE"]);
23617
+ function mapTypeOnly(graph, ref) {
23618
+ for (let at = ref; at !== void 0; at = graph.parent(at)) {
23619
+ const object2 = graph.object(at);
23620
+ if (TYPE_KINDS.has(object2.kind)) return true;
23621
+ if (object2.execution || object2.kind !== "PROPERTY" && object2.kind !== "METHOD") return false;
23622
+ }
23623
+ return false;
23624
+ }
23425
23625
  var mapShapeDeadline = () => Date.now() + READ_MS;
23426
23626
  var MapShapeUses = class {
23427
23627
  constructor(graph, reader, until) {
@@ -23470,11 +23670,11 @@ var USED_BY = {
23470
23670
  OVERRIDES: "overridden"
23471
23671
  };
23472
23672
  var runsTarget = (relation) => CALLER_KINDS.has(relation.kind) && !relation.event;
23473
- var changeUnits = (graph, path20) => mapMiniprogramTemplate(path20) ? graph.objectsAt(path20).filter((object2) => mapIsModule(object2) && object2.parsing === "PARSED") : graph.declarationsAt(path20);
23474
- function changedUnits(graph, path20, lines) {
23673
+ var changeUnits = (graph, path21) => mapMiniprogramTemplate(path21) ? graph.objectsAt(path21).filter((object2) => mapIsModule(object2) && object2.parsing === "PARSED") : graph.declarationsAt(path21);
23674
+ function changedUnits(graph, path21, lines) {
23475
23675
  const refs = /* @__PURE__ */ new Set();
23476
23676
  let topLevel = false;
23477
- const inFile = changeUnits(graph, path20);
23677
+ const inFile = changeUnits(graph, path21);
23478
23678
  for (const [from, to] of lines) {
23479
23679
  const containing = inFile.filter(
23480
23680
  (object2) => object2.anchor.startLine <= to && from <= object2.anchor.endLine
@@ -23997,12 +24197,12 @@ var Tracer = class {
23997
24197
  this.mentions.set(route, (this.mentions.get(route) ?? /* @__PURE__ */ new Set()).add(file2));
23998
24198
  }
23999
24199
  /** A related test file; the closest relation (lowest rank) explains it. */
24000
- test(path20, name, why, rank2) {
24001
- if (!mapRunnableTest(path20)) return;
24002
- const known = this.tests.get(path20) ?? { names: /* @__PURE__ */ new Set(), why, rank: rank2 };
24200
+ test(path21, name, why, rank2) {
24201
+ if (!mapRunnableTest(path21)) return;
24202
+ const known = this.tests.get(path21) ?? { names: /* @__PURE__ */ new Set(), why, rank: rank2 };
24003
24203
  if (rank2 < known.rank) Object.assign(known, { why, rank: rank2 });
24004
24204
  if (name && !name.startsWith("<")) known.names.add(name);
24005
- this.tests.set(path20, known);
24205
+ this.tests.set(path21, known);
24006
24206
  }
24007
24207
  };
24008
24208
  var entriesOf = /* @__PURE__ */ new WeakMap();
@@ -24051,19 +24251,19 @@ function findTestEntries(graph, ref) {
24051
24251
  }
24052
24252
 
24053
24253
  // src/project-map-change-edges.ts
24054
- var same2 = (path20) => path20;
24254
+ var same2 = (path21) => path21;
24055
24255
  var compare = (left, right) => left < right ? -1 : left > right ? 1 : 0;
24056
- function linksOf(side, path20) {
24256
+ function linksOf(side, path21) {
24057
24257
  const imports = /* @__PURE__ */ new Map();
24058
24258
  const calls = /* @__PURE__ */ new Map();
24059
- if (path20 === void 0) return { imports, calls };
24259
+ if (path21 === void 0) return { imports, calls };
24060
24260
  const { graph } = side;
24061
- for (const relation of graph.relationsFrom(graph.objectsAt(path20).map((object2) => object2.id))) {
24261
+ for (const relation of graph.relationsFrom(graph.objectsAt(path21).map((object2) => object2.id))) {
24062
24262
  const line = relation.anchor.startLine;
24063
- if (relation.to === void 0 || !side.counts(path20, line)) continue;
24263
+ if (relation.to === void 0 || !side.counts(path21, line)) continue;
24064
24264
  if (relation.kind === "IMPORTS") {
24065
24265
  const target = graph.object(relation.to).anchor.path;
24066
- if (target === path20) continue;
24266
+ if (target === path21) continue;
24067
24267
  const to = side.pathNow(target);
24068
24268
  const found = imports.get(to) ?? { to, lines: [] };
24069
24269
  found.lines.push(line);
@@ -24071,7 +24271,7 @@ function linksOf(side, path20) {
24071
24271
  } else if (CALLER_KINDS.has(relation.kind)) {
24072
24272
  const ref = graph.owner(relation.to);
24073
24273
  const owner = graph.object(ref);
24074
- if (owner.anchor.path === path20 || mapIsModule(owner)) continue;
24274
+ if (owner.anchor.path === path21 || mapIsModule(owner)) continue;
24075
24275
  const to = side.pathNow(owner.anchor.path);
24076
24276
  const key = `${to}\0${graph.declarationKey(owner)}`;
24077
24277
  const found = calls.get(key) ?? { to, lines: [], ref };
@@ -24102,17 +24302,17 @@ function mapChangeLinks(store, working, base, files) {
24102
24302
  counts: always,
24103
24303
  pathOf,
24104
24304
  declaration: (file2, ref) => {
24105
- const path20 = pathOf(file2);
24106
- if (path20 === void 0) return void 0;
24107
- let keys = declared.get(path20);
24305
+ const path21 = pathOf(file2);
24306
+ if (path21 === void 0) return void 0;
24307
+ let keys = declared.get(path21);
24108
24308
  if (!keys) {
24109
24309
  keys = new Map(
24110
- changeUnits(baseGraph, path20).map((object2) => [
24310
+ changeUnits(baseGraph, path21).map((object2) => [
24111
24311
  baseGraph.declarationKey(object2),
24112
24312
  object2.id
24113
24313
  ])
24114
24314
  );
24115
- declared.set(path20, keys);
24315
+ declared.set(path21, keys);
24116
24316
  }
24117
24317
  return keys.get(graph.declarationKey(graph.object(ref)));
24118
24318
  }
@@ -24122,8 +24322,8 @@ function mapChangeLinks(store, working, base, files) {
24122
24322
  before = {
24123
24323
  graph,
24124
24324
  pathNow: same2,
24125
- counts: (path20, line) => {
24126
- const file2 = changedAt.get(path20);
24325
+ counts: (path21, line) => {
24326
+ const file2 = changedAt.get(path21);
24127
24327
  return !file2 || !overlaps(file2.lines, line, line);
24128
24328
  },
24129
24329
  pathOf: (file2) => file2.status === "ADDED" ? void 0 : file2.path,
@@ -24157,9 +24357,9 @@ function callersOf(side, ref) {
24157
24357
  const home = side.graph.object(ref).anchor.path;
24158
24358
  const files = /* @__PURE__ */ new Set();
24159
24359
  for (const relation of side.graph.relationsTo([ref])) {
24160
- const path20 = relation.anchor.path;
24161
- if (!CALLER_KINDS.has(relation.kind) || path20 === home || mapTestPath(path20)) continue;
24162
- if (side.counts(path20, relation.anchor.startLine)) files.add(side.pathNow(path20));
24360
+ const path21 = relation.anchor.path;
24361
+ if (!CALLER_KINDS.has(relation.kind) || path21 === home || mapTestPath(path21)) continue;
24362
+ if (side.counts(path21, relation.anchor.startLine)) files.add(side.pathNow(path21));
24163
24363
  }
24164
24364
  return [...files].sort();
24165
24365
  }
@@ -24220,7 +24420,7 @@ function mapChangeEdges(links) {
24220
24420
  }
24221
24421
 
24222
24422
  // src/project-map-change-tests.ts
24223
- import { readFile as readFile2 } from "node:fs/promises";
24423
+ import { readFile as readFile3 } from "node:fs/promises";
24224
24424
  import path13 from "node:path";
24225
24425
 
24226
24426
  // src/project-map-route-paths.ts
@@ -24348,7 +24548,7 @@ var MAP_PATH_PARAMETER = "{}";
24348
24548
  async function existingTestsChanged(before, after, file2, project) {
24349
24549
  if (!file2.basePath || file2.baseText === void 0) return [];
24350
24550
  const baseLines = file2.baseText.split("\n");
24351
- const workingLines = file2.status !== "DELETED" && project ? (await readFile2(path13.join(project, file2.path), "utf8").catch(() => void 0))?.split(
24551
+ const workingLines = file2.status !== "DELETED" && project ? (await readFile3(path13.join(project, file2.path), "utf8").catch(() => void 0))?.split(
24352
24552
  "\n"
24353
24553
  ) ?? [] : [];
24354
24554
  const body = (lines, object2) => lines.slice(object2.anchor.startLine - 1, object2.anchor.endLine).map((line) => line.trimEnd());
@@ -24385,10 +24585,10 @@ function importerTests(graph, objects2, tracer, importers) {
24385
24585
  }
24386
24586
  const next = [];
24387
24587
  for (const imported of modules)
24388
- for (const { path: path20, module } of importers.get(imported) ?? [])
24389
- if (mapTestPath(path20))
24588
+ for (const { path: path21, module } of importers.get(imported) ?? [])
24589
+ if (mapTestPath(path21))
24390
24590
  tracer.test(
24391
- path20,
24591
+ path21,
24392
24592
  void 0,
24393
24593
  hop ? "imports a changed file indirectly" : "imports a changed file",
24394
24594
  hop ? 4 : 2
@@ -24413,17 +24613,17 @@ function supportTests(store, version2, tracer) {
24413
24613
  function mapPathIndex(paths) {
24414
24614
  const testsIn = /* @__PURE__ */ new Map();
24415
24615
  const under = /* @__PURE__ */ new Map();
24416
- const add = (map2, key, path20) => {
24616
+ const add = (map2, key, path21) => {
24417
24617
  const found = map2.get(key);
24418
- if (found) found.push(path20);
24419
- else map2.set(key, [path20]);
24618
+ if (found) found.push(path21);
24619
+ else map2.set(key, [path21]);
24420
24620
  };
24421
- for (const path20 of paths) {
24422
- const slash = path20.lastIndexOf("/");
24423
- const directory = slash < 0 ? "" : path20.slice(0, slash + 1);
24424
- if (mapTestPath(path20)) add(testsIn, directory, path20);
24621
+ for (const path21 of paths) {
24622
+ const slash = path21.lastIndexOf("/");
24623
+ const directory = slash < 0 ? "" : path21.slice(0, slash + 1);
24624
+ if (mapTestPath(path21)) add(testsIn, directory, path21);
24425
24625
  const name = directory.slice(directory.lastIndexOf("/", directory.length - 2) + 1, -1);
24426
- if (name) add(under, name, path20);
24626
+ if (name) add(under, name, path21);
24427
24627
  }
24428
24628
  return { testsIn, under };
24429
24629
  }
@@ -24516,7 +24716,7 @@ var RouteRequests = class {
24516
24716
  }
24517
24717
  const batch = this.candidates.slice(at, at + READ_BATCH);
24518
24718
  const texts = await Promise.all(
24519
- batch.map((file2) => readFile2(path13.join(project, file2), "utf8").catch(() => void 0))
24719
+ batch.map((file2) => readFile3(path13.join(project, file2), "utf8").catch(() => void 0))
24520
24720
  );
24521
24721
  for (const [index, text] of texts.entries())
24522
24722
  if (text !== void 0) yield [batch[index], text];
@@ -24557,9 +24757,9 @@ async function routeTests(requests, entries, tracer) {
24557
24757
  }
24558
24758
  return requested;
24559
24759
  }
24560
- function wholePath(text, path20) {
24561
- for (let at = text.indexOf(path20); at >= 0; at = text.indexOf(path20, at + 1))
24562
- if (!/[\w./-]/u.test(text[at + path20.length] ?? "")) return true;
24760
+ function wholePath(text, path21) {
24761
+ for (let at = text.indexOf(path21); at >= 0; at = text.indexOf(path21, at + 1))
24762
+ if (!/[\w./-]/u.test(text[at + path21.length] ?? "")) return true;
24563
24763
  return false;
24564
24764
  }
24565
24765
  async function unworkedRequests(requests, tracer, reaching) {
@@ -24580,14 +24780,14 @@ async function unworkedRequests(requests, tracer, reaching) {
24580
24780
  }
24581
24781
  }
24582
24782
  }
24583
- function sameDirectoryTests(paths, path20, tracer) {
24584
- const slash = path20.lastIndexOf("/");
24585
- for (const candidate of paths.testsIn.get(slash < 0 ? "" : path20.slice(0, slash + 1)) ?? [])
24783
+ function sameDirectoryTests(paths, path21, tracer) {
24784
+ const slash = path21.lastIndexOf("/");
24785
+ for (const candidate of paths.testsIn.get(slash < 0 ? "" : path21.slice(0, slash + 1)) ?? [])
24586
24786
  tracer.test(candidate, void 0, "in the same directory", 3);
24587
24787
  }
24588
- function routesIn(graph, path20) {
24788
+ function routesIn(graph, path21) {
24589
24789
  const routes = /* @__PURE__ */ new Set();
24590
- for (const relation of graph.relationsFrom(graph.objectsAt(path20).map((object2) => object2.id))) {
24790
+ for (const relation of graph.relationsFrom(graph.objectsAt(path21).map((object2) => object2.id))) {
24591
24791
  const route = mapRegisteredRoute(relation);
24592
24792
  if (route) routes.add(route);
24593
24793
  }
@@ -24624,13 +24824,13 @@ async function mapRemovedImpact(input) {
24624
24824
  input.cache.memberCalls(store, base),
24625
24825
  new MapShapeUses(before, input.shapes, input.until)
24626
24826
  );
24627
- const changedIn = changedInBase(changes.files);
24628
- const pathNow = (path20) => {
24629
- const file2 = changedIn.get(path20);
24630
- return file2?.status === "DELETED" ? void 0 : file2?.path ?? path20;
24827
+ const changedIn2 = changedInBase(changes.files);
24828
+ const pathNow = (path21) => {
24829
+ const file2 = changedIn2.get(path21);
24830
+ return file2?.status === "DELETED" ? void 0 : file2?.path ?? path21;
24631
24831
  };
24632
24832
  const nowAt = (anchor) => {
24633
- const file2 = changedIn.get(anchor.path);
24833
+ const file2 = changedIn2.get(anchor.path);
24634
24834
  if (file2 && (file2.status === "DELETED" || overlaps(file2.baseLines, anchor.startLine, anchor.endLine)))
24635
24835
  return void 0;
24636
24836
  return {
@@ -24642,11 +24842,11 @@ async function mapRemovedImpact(input) {
24642
24842
  const samePlace = (anchor, place) => anchor.path === place.path && anchor.startLine === place.startLine && anchor.endLine === place.endLine;
24643
24843
  const replaces = (now, removed2) => now.kind === removed2.kind && now.name === removed2.name;
24644
24844
  const relationsNow = /* @__PURE__ */ new Map();
24645
- const relationsIn = (path20) => {
24646
- let found = relationsNow.get(path20);
24845
+ const relationsIn = (path21) => {
24846
+ let found = relationsNow.get(path21);
24647
24847
  if (!found) {
24648
- found = graph.relationsFrom(graph.objectsAt(path20).map((object2) => object2.id));
24649
- relationsNow.set(path20, found);
24848
+ found = graph.relationsFrom(graph.objectsAt(path21).map((object2) => object2.id));
24849
+ relationsNow.set(path21, found);
24650
24850
  }
24651
24851
  return found;
24652
24852
  };
@@ -24755,13 +24955,13 @@ async function mapRemovedImpact(input) {
24755
24955
  });
24756
24956
  const lost = /* @__PURE__ */ new Map();
24757
24957
  const changedAt = changedInWorkingTree(changes.files);
24758
- for (const path20 of input.mappedPaths().filter(mapMiniprogramTemplate)) {
24759
- const template = graph.objectsAt(path20).find((object2) => mapIsModule(object2));
24958
+ for (const path21 of input.mappedPaths().filter(mapMiniprogramTemplate)) {
24959
+ const template = graph.objectsAt(path21).find((object2) => mapIsModule(object2));
24760
24960
  if (!template) continue;
24761
24961
  const broken = graph.relationsFrom(graph.scope(template.id).refs).filter((relation) => relation.to === void 0 && NAMING_KINDS.has(relation.kind));
24762
24962
  if (!broken.length) continue;
24763
- const file2 = changedAt.get(path20);
24764
- const basePath = file2 ? file2.basePath : path20;
24963
+ const file2 = changedAt.get(path21);
24964
+ const basePath = file2 ? file2.basePath : path21;
24765
24965
  const was = basePath === void 0 ? void 0 : before.objectsAt(basePath).find(mapIsModule);
24766
24966
  const links = was ? before.relationsFrom(before.scope(was.id).refs) : [];
24767
24967
  for (const relation of broken) {
@@ -24770,7 +24970,7 @@ async function mapRemovedImpact(input) {
24770
24970
  );
24771
24971
  if (earlier.some((link) => link.to === void 0)) continue;
24772
24972
  const event = miniprogramEventOf(relation.target);
24773
- const at = `${path20}:${relation.anchor.startLine}`;
24973
+ const at = `${path21}:${relation.anchor.startLine}`;
24774
24974
  if (file2 && overlaps(file2.lines, relation.anchor.startLine, relation.anchor.endLine)) {
24775
24975
  unclear.push({
24776
24976
  text: event ? `${at} binds the ${event.event} event of <${event.tag}>, which it does not emit` : relation.kind === "REFERENCES" ? `${at} puts <${relation.target}>, which its registration does not find` : `${at} binds ${relation.target}, which its page or component does not register`
@@ -24782,7 +24982,7 @@ async function mapRemovedImpact(input) {
24782
24982
  const object2 = before.object(reached);
24783
24983
  const name = mapIsModule(object2) ? `${object2.anchor.path} (template)${event ? `: ${event.event} event` : ""}` : `${object2.anchor.path}: ${before.qualifiedName(reached)} ${mapDeclarationLabel(object2)}`;
24784
24984
  const users = lost.get(name) ?? /* @__PURE__ */ new Set();
24785
- users.add(`${path20} (template)`);
24985
+ users.add(`${path21} (template)`);
24786
24986
  lost.set(name, users);
24787
24987
  }
24788
24988
  }
@@ -24796,8 +24996,9 @@ async function mapRemovedImpact(input) {
24796
24996
  ))
24797
24997
  topLevel.push(file2.path);
24798
24998
  }
24799
- if (gone2.size) {
24800
- await beforeTracer.trace([...gone2], [...gone2], true);
24999
+ const ran = [...gone2].filter((ref) => !mapTypeOnly(before, ref));
25000
+ if (ran.length) {
25001
+ await beforeTracer.trace(ran, ran, true);
24801
25002
  const siteNow = (site) => {
24802
25003
  const at = site.lastIndexOf(":");
24803
25004
  const line = Number(site.slice(at + 1));
@@ -24824,15 +25025,15 @@ async function mapRemovedImpact(input) {
24824
25025
  ...removed2 ? { removed: true } : {}
24825
25026
  });
24826
25027
  }
24827
- for (const [path20, test] of beforeTracer.tests) {
24828
- const now = pathNow(path20);
25028
+ for (const [path21, test] of beforeTracer.tests) {
25029
+ const now = pathNow(path21);
24829
25030
  if (now === void 0) continue;
24830
25031
  tracer.test(now, void 0, test.why, test.rank);
24831
25032
  for (const name of test.names) tracer.test(now, name, test.why, test.rank);
24832
25033
  }
24833
25034
  for (const [area, known] of beforeTracer.areas)
24834
- for (const [path20, names] of known.tests) {
24835
- const now = pathNow(path20);
25035
+ for (const [path21, names] of known.tests) {
25036
+ const now = pathNow(path21);
24836
25037
  const place = pathNow(area);
24837
25038
  if (now !== void 0 && place !== void 0)
24838
25039
  tracer.shareArea(place, known.through, now, names);
@@ -24855,24 +25056,24 @@ async function mapRemovedImpact(input) {
24855
25056
  for (const ref of called) {
24856
25057
  const object2 = before.object(ref);
24857
25058
  if (mapIsModule(object2) || mapTestPath(object2.anchor.path) || gone2.has(ref)) continue;
24858
- const path20 = pathNow(object2.anchor.path);
24859
- if (path20 === void 0) continue;
25059
+ const path21 = pathNow(object2.anchor.path);
25060
+ if (path21 === void 0) continue;
24860
25061
  const key = before.declarationKey(object2);
24861
- const now = graph.declarationsAt(path20).find((candidate) => graph.declarationKey(candidate) === key);
25062
+ const now = graph.declarationsAt(path21).find((candidate) => graph.declarationKey(candidate) === key);
24862
25063
  if (!now) continue;
24863
25064
  const calls = tracer.callers(now.id).filter((caller) => !caller.uses);
24864
25065
  if (outsideTests(calls, graph).length || tracer.usesWithoutCalls(now.id).length) continue;
24865
25066
  if (!outsideTests(beforeTracer.callers(ref), before).length) continue;
24866
- candidates.push({ path: path20, name: before.qualifiedName(ref), now, tested: calls.length > 0 });
25067
+ candidates.push({ path: path21, name: before.qualifiedName(ref), now, tested: calls.length > 0 });
24867
25068
  }
24868
25069
  await tracer.shapes.read(candidates.map(({ now }) => now.id));
24869
25070
  const uncalled = [];
24870
25071
  const unknown2 = [];
24871
- for (const { path: path20, name, now, tested } of candidates) {
25072
+ for (const { path: path21, name, now, tested } of candidates) {
24872
25073
  if (tracer.shapes.unread.has(now.id)) unknown2.push(name);
24873
25074
  else if (!tracer.shapes.uses.get(now.id)?.some(({ owner, write }) => !write && !mapTestPath(graph.object(owner).anchor.path))) {
24874
25075
  uncalled.push(
24875
- `${path20}: ${name} ${mapDeclarationLabel(now)}${tested ? " (only tests call it now)" : ""}`
25076
+ `${path21}: ${name} ${mapDeclarationLabel(now)}${tested ? " (only tests call it now)" : ""}`
24876
25077
  );
24877
25078
  }
24878
25079
  }
@@ -25086,7 +25287,8 @@ Nothing changed against ${changes.base}.`;
25086
25287
  "Where the diff changed a route's registration, check that the route still reaches the right handler."
25087
25288
  );
25088
25289
  if (impact.untested) {
25089
- const { changed, entries, throughRoutes, routes: routes2, missing, truncated } = impact.untested;
25290
+ const { changed, entries, throughRoutes, routes: routes2, missing, truncated, typeOnly } = impact.untested;
25291
+ const runs = impact.changed.length - typeOnly;
25090
25292
  const items = (shown, limit2) => {
25091
25293
  lines.push(...shown.slice(0, limit2).map((item) => ` ${item}`));
25092
25294
  if (shown.length > limit2) lines.push(` +${shown.length - limit2} more`);
@@ -25096,7 +25298,7 @@ Nothing changed against ${changes.base}.`;
25096
25298
  lines.push(` the map has no code for these given files: ${missing.join(", ")}`);
25097
25299
  if (changed.length) {
25098
25300
  lines.push(
25099
- ` ${changed.length} of ${impact.changed.length} changed declarations are reached by none of the given tests; ${entries.length ? "the entry points above them, then the declarations:" : "the declarations:"}`
25301
+ ` ${changed.length} of ${runs} changed declarations are reached by none of the given tests; ${entries.length ? "the entry points above them, then the declarations:" : "the declarations:"}`
25100
25302
  );
25101
25303
  items(
25102
25304
  entries.map((item) => {
@@ -25123,7 +25325,11 @@ Nothing changed against ${changes.base}.`;
25123
25325
  );
25124
25326
  } else
25125
25327
  lines.push(
25126
- impact.changed.length ? ` none: the given tests reach all ${impact.changed.length} changed declarations` : " none: the diff changes no declarations outside the tests"
25328
+ runs ? ` none: the given tests reach all ${runs} changed declarations` : impact.changed.length ? " none: outside the tests the diff changes types alone (or comments and layout)" : " none: the diff changes no declarations outside the tests"
25329
+ );
25330
+ if (typeOnly)
25331
+ lines.push(
25332
+ ` ${typeOnly} changed declarations change types alone (or comments and layout) and are not judged: none of the code they run changed, and the type checker checks the types`
25127
25333
  );
25128
25334
  if (throughRoutes.length) {
25129
25335
  lines.push(
@@ -25234,9 +25440,9 @@ function pathBetween(edges, from, to) {
25234
25440
  if (via.has(target)) continue;
25235
25441
  via.set(target, module);
25236
25442
  if (target === to) {
25237
- const path20 = [to];
25238
- for (let step = module; step !== from; step = via.get(step) ?? from) path20.unshift(step);
25239
- return [from, ...path20];
25443
+ const path21 = [to];
25444
+ for (let step = module; step !== from; step = via.get(step) ?? from) path21.unshift(step);
25445
+ return [from, ...path21];
25240
25446
  }
25241
25447
  next.push(target);
25242
25448
  }
@@ -25289,11 +25495,11 @@ function newModuleDependencies(store, cache, working, files, links) {
25289
25495
  );
25290
25496
  }
25291
25497
  var MANIFEST = /(?:^|\/)(?:package\.json|go\.mod|pom\.xml|build\.gradle(?:\.kts)?|pyproject\.toml|setup\.py|setup\.cfg)$/u;
25292
- var directoryOf3 = (path20) => path20.slice(0, Math.max(path20.lastIndexOf("/"), 0));
25498
+ var directoryOf3 = (path21) => path21.slice(0, Math.max(path21.lastIndexOf("/"), 0));
25293
25499
  var directoryLabel = (directory) => directory ? `${directory}/` : "./";
25294
25500
  function mapReuseImports(store, cache, working) {
25295
25501
  const roots = store.listEntries(working).filter((entry) => MANIFEST.test(entry.path)).map((entry) => directoryOf3(entry.path)).sort((left, right) => right.length - left.length);
25296
- const packageOf = (path20) => roots.find((root) => !root || path20.startsWith(`${root}/`)) ?? "";
25502
+ const packageOf = (path21) => roots.find((root) => !root || path21.startsWith(`${root}/`)) ?? "";
25297
25503
  const directories = /* @__PURE__ */ new Map();
25298
25504
  const packages = /* @__PURE__ */ new Map();
25299
25505
  const files = /* @__PURE__ */ new Set();
@@ -25326,21 +25532,21 @@ function mapReuseImports(store, cache, working) {
25326
25532
  };
25327
25533
  const graph = new MapViewGraph(store, working);
25328
25534
  const usedFrom = /* @__PURE__ */ new Map();
25329
- const used = (path20) => {
25330
- let found = usedFrom.get(path20);
25535
+ const used = (path21) => {
25536
+ let found = usedFrom.get(path21);
25331
25537
  if (found === void 0) {
25332
- found = graph.relationsTo(graph.objectsAt(path20).map((object2) => object2.id)).some((relation) => graph.object(relation.from).anchor.path !== path20);
25333
- usedFrom.set(path20, found);
25538
+ found = graph.relationsTo(graph.objectsAt(path21).map((object2) => object2.id)).some((relation) => graph.object(relation.from).anchor.path !== path21);
25539
+ usedFrom.set(path21, found);
25334
25540
  }
25335
25541
  return found;
25336
25542
  };
25337
- return (path20, existing) => {
25338
- const added = [directoryOf3(path20), packageOf(path20)];
25543
+ return (path21, existing) => {
25544
+ const added = [directoryOf3(path21), packageOf(path21)];
25339
25545
  const old = [directoryOf3(existing), packageOf(existing)];
25340
25546
  const ahead = use("NEW", added, old);
25341
- if (files.has(`${path20}\0${existing}`)) return ahead;
25342
- if (files.has(`${existing}\0${path20}`))
25343
- return { ...use("EXISTING", old, added), from: existing, to: path20 };
25547
+ if (files.has(`${path21}\0${existing}`)) return ahead;
25548
+ if (files.has(`${existing}\0${path21}`))
25549
+ return { ...use("EXISTING", old, added), from: existing, to: path21 };
25344
25550
  const usable = used(existing);
25345
25551
  if (usable && ahead.imported) return ahead;
25346
25552
  if (directories.get(old[0])?.has(added[0])) return use("EXISTING", old, added);
@@ -25362,9 +25568,9 @@ var KEYWORDS = new Set(
25362
25568
  );
25363
25569
  var ROWS = `SELECT entity_ref AS id, path, name, kind, object_json AS object
25364
25570
  FROM project_map_objects WHERE version_ref = ? AND kind <> 'PROPERTY'`;
25365
- function rows(store, version2, path20) {
25366
- const statement = store.database.prepare(path20 === void 0 ? ROWS : `${ROWS} AND path = ?`);
25367
- return (path20 === void 0 ? statement.all(version2) : statement.all(version2, path20)).map((row) => {
25571
+ function rows(store, version2, path21) {
25572
+ const statement = store.database.prepare(path21 === void 0 ? ROWS : `${ROWS} AND path = ?`);
25573
+ return (path21 === void 0 ? statement.all(version2) : statement.all(version2, path21)).map((row) => {
25368
25574
  const { anchor } = JSON.parse(String(row.object));
25369
25575
  return {
25370
25576
  id: String(row.id),
@@ -25406,10 +25612,10 @@ function lineWords(line) {
25406
25612
  var within2 = (lines, declaration) => lines.some(([from, to]) => from <= declaration.startLine && declaration.endLine <= to);
25407
25613
  var copyText = (code) => code.replace(/^export\s+(?:default\s+)?/u, "").replace(/\s+/gu, " ").trim();
25408
25614
  async function similarCode(store, working, base, files, read) {
25409
- const code = (path20) => mapCodePath(path20) && !mapTestPath(path20) && !MAP_MIGRATION_PATH.test(path20);
25615
+ const code = (path21) => mapCodePath(path21) && !mapTestPath(path21) && !MAP_MIGRATION_PATH.test(path21);
25410
25616
  const changed = files.filter((file2) => file2.status !== "DELETED" && code(file2.path));
25411
25617
  if (!changed.length) return [];
25412
- const names = (version2, path20) => new Set(declarations(rows(store, version2, path20)).map((item) => item.qualifiedName));
25618
+ const names = (version2, path21) => new Set(declarations(rows(store, version2, path21)).map((item) => item.qualifiedName));
25413
25619
  const movedOut = /* @__PURE__ */ new Set();
25414
25620
  if (base !== void 0)
25415
25621
  for (const file2 of files) {
@@ -25441,11 +25647,11 @@ async function similarCode(store, working, base, files, read) {
25441
25647
  const all = [];
25442
25648
  const shortCopies = /* @__PURE__ */ new Map();
25443
25649
  const texts = await Promise.all(
25444
- [...byPath].sort(([left], [right]) => left < right ? -1 : left > right ? 1 : 0).map(async ([path20, inFile]) => {
25650
+ [...byPath].sort(([left], [right]) => left < right ? -1 : left > right ? 1 : 0).map(async ([path21, inFile]) => {
25445
25651
  const found2 = declarations(inFile).filter(
25446
25652
  (item) => KINDS2.has(item.kind) && (long(item) ? longAdded : shortNames.has(item.qualifiedName))
25447
25653
  );
25448
- return { found: found2, text: found2.length ? await read(path20) : void 0 };
25654
+ return { found: found2, text: found2.length ? await read(path21) : void 0 };
25449
25655
  })
25450
25656
  );
25451
25657
  for (const { found: found2, text } of texts) {
@@ -25571,17 +25777,19 @@ async function mapChangeImpact(store, views, working, base, changes, links, shap
25571
25777
  `the text search for the environment variables and configuration keys the diff removed did not finish (${changes.stranded.failed}), so the files still using them are not listed`
25572
25778
  );
25573
25779
  const unmapped = [];
25574
- let changedCount = 0;
25575
25780
  const starts = [];
25781
+ const traced = [];
25782
+ let typeOnly = 0;
25783
+ let untraced = 0;
25576
25784
  const importers = /* @__PURE__ */ new Map();
25577
25785
  let mapped;
25578
25786
  const mappedPaths = () => mapped ??= store.database.prepare("SELECT DISTINCT path FROM project_map_objects WHERE version_ref = ?").all(working).map((row) => String(row.path));
25579
25787
  let paths;
25580
25788
  const pathIndex = () => paths ??= mapPathIndex(mappedPaths());
25581
- const topLevelChanged = (path20) => {
25582
- const text = `top-level code of ${path20} changed (imports, constants or registrations)`;
25789
+ const topLevelChanged = (path21) => {
25790
+ const text = `top-level code of ${path21} changed (imports, constants or registrations)`;
25583
25791
  if (!unclear.some((note) => note.text === text))
25584
- unclear.push({ text, group: { kind: "TOP_LEVEL", subject: path20 } });
25792
+ unclear.push({ text, group: { kind: "TOP_LEVEL", subject: path21 } });
25585
25793
  };
25586
25794
  for (const file2 of changes.files) {
25587
25795
  const objects2 = file2.status === "DELETED" || file2.binary ? [] : graph.objectsAt(file2.path);
@@ -25602,21 +25810,26 @@ async function mapChangeImpact(store, views, working, base, changes, links, shap
25602
25810
  unmapped.push({ path: file2.path, kind });
25603
25811
  }
25604
25812
  if (!objects2.length) continue;
25605
- const { refs: hits, topLevel } = changedUnits(graph, file2.path, file2.lines);
25813
+ const { refs: hits } = changedUnits(graph, file2.path, file2.lines);
25814
+ const lines = file2.runtime ?? file2.lines;
25815
+ const { refs: running, topLevel } = changedUnits(graph, file2.path, lines);
25606
25816
  for (const ref of hits) {
25607
- if (changedCount++ >= LIMITS.changed) {
25608
- tracer.truncated = true;
25609
- break;
25817
+ const types = !running.has(ref) || mapTypeOnly(graph, ref);
25818
+ if (!types && starts.length >= LIMITS.changed) {
25819
+ untraced++;
25820
+ continue;
25821
+ }
25822
+ const label = `${file2.path}${template ? " (template)" : `: ${graph.qualifiedName(ref)} ${mapDeclarationLabel(graph.object(ref))}`}${file2.status === "ADDED" ? " (new file)" : ""}`;
25823
+ changed.push(label);
25824
+ if (types) typeOnly++;
25825
+ else {
25826
+ traced.push(label);
25827
+ starts.push(tracer.startsAt(ref, lines));
25610
25828
  }
25611
- const object2 = graph.object(ref);
25612
- changed.push(
25613
- `${file2.path}${template ? " (template)" : `: ${graph.qualifiedName(ref)} ${mapDeclarationLabel(object2)}`}${file2.status === "ADDED" ? " (new file)" : ""}`
25614
- );
25615
- starts.push(tracer.startsAt(ref, file2.lines));
25616
25829
  }
25617
25830
  for (const relation of graph.relationsFrom(objects2.map((object2) => object2.id))) {
25618
25831
  const route = mapRegisteredRoute(relation);
25619
- if (route && overlaps(file2.lines, relation.anchor.startLine, relation.anchor.endLine)) {
25832
+ if (route && overlaps(lines, relation.anchor.startLine, relation.anchor.endLine)) {
25620
25833
  const site = `${relation.anchor.path}:${relation.anchor.startLine}`;
25621
25834
  unclear.push({
25622
25835
  text: `the registration of ${JSON.stringify(route)} at ${site} changed; check that the route still reaches the right handler`,
@@ -25692,7 +25905,7 @@ async function mapChangeImpact(store, views, working, base, changes, links, shap
25692
25905
  ", "
25693
25906
  )}${unread.length > LIST.names ? ", \u2026" : ""}); project_find_references lists their uses`
25694
25907
  });
25695
- const untested = tests && await untestedChanges(graph, tracer, memberCalls, starts, changed, tests);
25908
+ const untested = tests && await untestedChanges(graph, tracer, memberCalls, starts, traced, tests, typeOnly);
25696
25909
  supportTests(store, working, tracer);
25697
25910
  const taken = base ? await mapRemovedImpact({
25698
25911
  store,
@@ -25706,15 +25919,15 @@ async function mapChangeImpact(store, views, working, base, changes, links, shap
25706
25919
  project,
25707
25920
  mappedPaths
25708
25921
  }) : void 0;
25709
- for (const path20 of taken?.topLevel ?? []) topLevelChanged(path20);
25922
+ for (const path21 of taken?.topLevel ?? []) topLevelChanged(path21);
25710
25923
  unclear.push(...taken?.unclear ?? []);
25711
25924
  return {
25712
25925
  changed,
25713
25926
  removed: taken?.removed ?? [],
25714
25927
  rewrittenTests: taken?.rewrittenTests ?? [],
25715
25928
  entries: [...tracer.entries.values()].sort(entryOrder),
25716
- tests: [...tracer.tests].map(([path20, test]) => ({
25717
- path: path20,
25929
+ tests: [...tracer.tests].map(([path21, test]) => ({
25930
+ path: path21,
25718
25931
  names: [...test.names].sort(),
25719
25932
  why: test.why,
25720
25933
  rank: test.rank
@@ -25724,13 +25937,16 @@ async function mapChangeImpact(store, views, working, base, changes, links, shap
25724
25937
  areas: [...tracer.areas].map(([area, known]) => ({
25725
25938
  area,
25726
25939
  through: [...known.through].sort(),
25727
- tests: [...known.tests].map(([path20, names]) => ({ path: path20, names: [...names].sort() })).sort((left, right) => right.names.length - left.names.length)
25940
+ tests: [...known.tests].map(([path21, names]) => ({ path: path21, names: [...names].sort() })).sort((left, right) => right.names.length - left.names.length)
25728
25941
  })).sort((left, right) => right.tests.length - left.tests.length),
25729
25942
  unclear: [
25730
25943
  ...new Map([...unclear, ...tracer.unclear].map((note) => [note.text, note])).values()
25731
25944
  ],
25732
25945
  incomplete: [
25733
25946
  ...incomplete,
25947
+ ...untraced ? [
25948
+ `the diff changes more than ${LIMITS.changed} declarations that run; the ${untraced} after the first ${LIMITS.changed} were not followed, so what only they reach is not listed`
25949
+ ] : [],
25734
25950
  ...tracer.truncated ? [
25735
25951
  `the trace stopped at ${LIMITS.depth} levels or ${LIMITS.declarations} declarations; continue with project_explore_map from the last ones`
25736
25952
  ] : []
@@ -25740,11 +25956,11 @@ async function mapChangeImpact(store, views, working, base, changes, links, shap
25740
25956
  uncalled: taken?.uncalled ?? [],
25741
25957
  dependencies: newModuleDependencies(store, views, working, changes.files, links.files),
25742
25958
  ...untested ? { untested } : {},
25743
- truncated: tracer.truncated
25959
+ truncated: tracer.truncated || untraced > 0
25744
25960
  };
25745
25961
  }
25746
25962
  var entryOrder = (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);
25747
- async function untestedChanges(graph, tracer, memberCalls, starts, changed, tests) {
25963
+ async function untestedChanges(graph, tracer, memberCalls, starts, changed, tests, typeOnly) {
25748
25964
  const given = new Set(tests);
25749
25965
  const handlers = (requests, files) => {
25750
25966
  const into = /* @__PURE__ */ new Map();
@@ -25796,6 +26012,7 @@ async function untestedChanges(graph, tracer, memberCalls, starts, changed, test
25796
26012
  const others = new Set([...tracer.tests.keys()].filter((file2) => !given.has(file2)));
25797
26013
  return {
25798
26014
  changed: unreached.map((at) => changed[at] ?? ""),
26015
+ typeOnly,
25799
26016
  runByOthers: runBy(others, requested),
25800
26017
  mayRun: runBy(given, tracer.mayRequest),
25801
26018
  entries: [...above.entries.values()].sort(entryOrder),
@@ -25809,9 +26026,9 @@ function mapChangesData(changes, impact, edges) {
25809
26026
  return {
25810
26027
  base: changes.base,
25811
26028
  commit: changes.commit,
25812
- files: changes.files.map(({ path: path20, basePath, status }) => ({
25813
- path: path20,
25814
- ...basePath !== void 0 && basePath !== path20 ? { basePath } : {},
26029
+ files: changes.files.map(({ path: path21, basePath, status }) => ({
26030
+ path: path21,
26031
+ ...basePath !== void 0 && basePath !== path21 ? { basePath } : {},
25815
26032
  status
25816
26033
  })),
25817
26034
  tests: impact.tests,
@@ -25895,7 +26112,7 @@ async function checkMapChanges(input, signal) {
25895
26112
  working,
25896
26113
  base,
25897
26114
  changes.files,
25898
- (file2) => readFile3(path14.join(project, file2), "utf8").catch(() => void 0)
26115
+ (file2) => readFile4(path14.join(project, file2), "utf8").catch(() => void 0)
25899
26116
  )
25900
26117
  ),
25901
26118
  changes.files.length ? await compileBreaks(input, views, changes, base, until, signal, phase, baseVersion) : void 0
@@ -25972,7 +26189,7 @@ async function compileBreaks(input, views, changes, base, until, signal, phase,
25972
26189
  signal
25973
26190
  ) : { contexts: [], unchecked: [] };
25974
26191
  const inBase = changedInBase(changes.files);
25975
- const named = (path20, item) => `${path20}\0${item.code}\0${item.span}\0${item.text}`;
26192
+ const named = (path21, item) => `${path21}\0${item.code}\0${item.span}\0${item.text}`;
25976
26193
  const compiled = new Map(before.contexts.map((context) => [context.configPath, context.errors]));
25977
26194
  const unchecked = new Set(after.unchecked);
25978
26195
  const errors = /* @__PURE__ */ new Set();
@@ -26416,7 +26633,7 @@ var packageRoot = (() => {
26416
26633
  directory = path16.dirname(directory);
26417
26634
  }
26418
26635
  })();
26419
- var packageVersion = async () => JSON.parse(await readFile4(path16.join(packageRoot, "package.json"), "utf8")).version;
26636
+ var packageVersion = async () => JSON.parse(await readFile5(path16.join(packageRoot, "package.json"), "utf8")).version;
26420
26637
  var cacheDirectory = (env = process.env) => {
26421
26638
  if (env.LAYERMAP_CACHE) return path16.resolve(env.LAYERMAP_CACHE);
26422
26639
  if (process.platform === "darwin") return path16.join(homedir(), "Library", "Caches", "layermap");
@@ -26476,11 +26693,11 @@ var absoluteIn = (directory, value) => Object.fromEntries(
26476
26693
  var readAnalyzers = async (directory) => {
26477
26694
  const file2 = path16.join(directory, "analyzers.json");
26478
26695
  if (!existsSync6(file2)) return void 0;
26479
- const analyzers = absoluteIn(directory, JSON.parse(await readFile4(file2, "utf8")));
26696
+ const analyzers = absoluteIn(directory, JSON.parse(await readFile5(file2, "utf8")));
26480
26697
  return analyzers.java.runtimePath ? analyzers : { ...analyzers, java: { ...analyzers.java, ...discoverJavaRuntime() } };
26481
26698
  };
26482
26699
  var sourceDigest = async () => {
26483
- const hash2 = createHash6("sha256").update(await readFile4(path16.join(packageRoot, "package.json")));
26700
+ const hash2 = createHash6("sha256").update(await readFile5(path16.join(packageRoot, "package.json")));
26484
26701
  for (const part of ["src", "go-map", "java-map", "scripts"]) {
26485
26702
  const directory = path16.join(packageRoot, part);
26486
26703
  if (!existsSync6(directory)) continue;
@@ -26529,7 +26746,7 @@ async function pruneCache(cache, project, now = Date.now(), installed = packageR
26529
26746
  const directory = path16.join(projects, name);
26530
26747
  const marker = path16.join(directory, "last-used");
26531
26748
  const last = (await stat2(existsSync6(marker) ? marker : directory).catch(() => void 0))?.mtimeMs;
26532
- const owner = await readFile4(marker, "utf8").catch(() => "");
26749
+ const owner = await readFile5(marker, "utf8").catch(() => "");
26533
26750
  if (last !== void 0 && now - last > 30 * DAY || owner !== "" && await gone(owner))
26534
26751
  await rm(directory, { recursive: true, force: true });
26535
26752
  }
@@ -26570,7 +26787,7 @@ async function pruneVersions(versions, own, now) {
26570
26787
  }
26571
26788
  async function pruneNpxInstalls(npx, installed, now) {
26572
26789
  const own = path16.dirname(path16.dirname(installed));
26573
- const manifest = async (file2) => JSON.parse(await readFile4(file2, "utf8").catch(() => "{}"));
26790
+ const manifest = async (file2) => JSON.parse(await readFile5(file2, "utf8").catch(() => "{}"));
26574
26791
  const parts = (version2) => version2?.split(".").map(Number) ?? [];
26575
26792
  const current = parts((await manifest(path16.join(installed, "package.json"))).version);
26576
26793
  const older = (version2) => {
@@ -26593,6 +26810,104 @@ async function pruneNpxInstalls(npx, installed, now) {
26593
26810
  }
26594
26811
  }
26595
26812
 
26813
+ // src/agent/command.ts
26814
+ var MARK = "// LayerMap's command, written by `layermap setup command`.";
26815
+ var commandScript = (cache) => `#!/usr/bin/env node
26816
+ ${MARK}
26817
+ // It runs the newest LayerMap version installed in LayerMap's cache, where each agent's LayerMap
26818
+ // plugin installs the version it starts. \`layermap remove command\` deletes this file.
26819
+ if (typeof process.getBuiltinModule !== "function") {
26820
+ process.stderr.write("layermap: LayerMap needs Node.js 22.22 or later; this is " + process.version + "\\n");
26821
+ process.exit(1);
26822
+ }
26823
+ const fs = process.getBuiltinModule("node:fs");
26824
+ const path = process.getBuiltinModule("node:path");
26825
+ const { pathToFileURL } = process.getBuiltinModule("node:url");
26826
+ const cache = process.env.LAYERMAP_CACHE ? path.resolve(process.env.LAYERMAP_CACHE) : ${JSON.stringify(cache)};
26827
+ const versions = path.join(cache, "versions");
26828
+ const installed = (version) => path.join(versions, version, "node_modules", "layermap");
26829
+ // A version being installed is a directory named .<version>-\u2026, and has no manifest in place yet.
26830
+ const numbers = (version) => version.split(".").map(Number);
26831
+ const newest = (fs.existsSync(versions) ? fs.readdirSync(versions) : [])
26832
+ .filter((name) => /^\\d+\\.\\d+\\.\\d+$/.test(name) && fs.existsSync(path.join(installed(name), "package.json")))
26833
+ .sort((a, b) => {
26834
+ const [left, right] = [numbers(a), numbers(b)];
26835
+ return left[0] - right[0] || left[1] - right[1] || left[2] - right[2];
26836
+ })
26837
+ .at(-1);
26838
+ if (!newest) {
26839
+ process.stderr.write(
26840
+ "layermap: no LayerMap version is installed in " + versions + ". Start a session of an agent that has the LayerMap plugin, which installs its version there, then run this again.\\n",
26841
+ );
26842
+ process.exit(1);
26843
+ }
26844
+ const entry = path.join(
26845
+ installed(newest),
26846
+ JSON.parse(fs.readFileSync(path.join(installed(newest), "package.json"), "utf8")).bin.layermap,
26847
+ );
26848
+ process.argv = [process.argv[0], entry, ...process.argv.slice(2)];
26849
+ import(pathToFileURL(entry).href).catch((error) => {
26850
+ process.stderr.write("layermap: could not start LayerMap " + newest + ": " + (error?.message ?? error) + "\\n");
26851
+ process.exit(1);
26852
+ });
26853
+ `;
26854
+ var commandFile = (env = process.env) => path17.join(env.HOME || homedir2(), ".local", "bin", "layermap");
26855
+ async function state(file2) {
26856
+ const found = await lstat5(file2).catch(() => void 0);
26857
+ if (!found) return "absent";
26858
+ if (!found.isFile()) return "other";
26859
+ return (await readFile6(file2, "utf8")).includes(MARK) ? "own" : "other";
26860
+ }
26861
+ var unsupported = (log2) => {
26862
+ log2(
26863
+ "The layermap command is for macOS and Linux, whose shells run a file in ~/.local/bin; on Windows use `npx layermap`."
26864
+ );
26865
+ return false;
26866
+ };
26867
+ async function setupCommand(options) {
26868
+ const env = options.env ?? process.env;
26869
+ const { log: log2 } = options;
26870
+ if (process.platform === "win32") return unsupported(log2);
26871
+ const file2 = commandFile(env);
26872
+ if (await state(file2) === "other") {
26873
+ log2(
26874
+ `${file2} is there already and is not LayerMap's command: left as it is. Remove it if you do not need it, then run setup again.`
26875
+ );
26876
+ return false;
26877
+ }
26878
+ log2(`write LayerMap's command to ${file2}`);
26879
+ if (options.dryRun) return true;
26880
+ await mkdir3(path17.dirname(file2), { recursive: true });
26881
+ await writeFile2(`${file2}.${process.pid}`, commandScript(cacheDirectory(env)));
26882
+ await chmod(`${file2}.${process.pid}`, 493);
26883
+ await rename3(`${file2}.${process.pid}`, file2);
26884
+ if (!(env.PATH ?? "").split(path17.delimiter).includes(path17.dirname(file2)))
26885
+ log2(`${path17.dirname(file2)} is not on this shell's PATH: add it for the command to be found.`);
26886
+ log2(
26887
+ `Done. \`layermap\` runs the newest LayerMap version installed in ${path17.join(cacheDirectory(env), "versions")}, where each agent's LayerMap plugin installs the version it starts.`
26888
+ );
26889
+ return true;
26890
+ }
26891
+ async function removeCommand(options) {
26892
+ const { log: log2 } = options;
26893
+ if (process.platform === "win32") return unsupported(log2);
26894
+ const file2 = commandFile(options.env ?? process.env);
26895
+ const found = await state(file2);
26896
+ if (found === "other") {
26897
+ log2(`${file2} is not LayerMap's command: left as it is.`);
26898
+ return false;
26899
+ }
26900
+ if (found === "absent") {
26901
+ log2(`${file2} is not there: nothing to remove.`);
26902
+ return true;
26903
+ }
26904
+ log2(`remove LayerMap's command from ${file2}`);
26905
+ if (options.dryRun) return true;
26906
+ await rm2(file2);
26907
+ log2("Removed.");
26908
+ return true;
26909
+ }
26910
+
26596
26911
  // src/agent/mcp.ts
26597
26912
  import { createInterface } from "node:readline";
26598
26913
  import { setTimeout as delay2 } from "node:timers/promises";
@@ -26620,7 +26935,7 @@ var MAP_TOOL_NAMES = Object.freeze({
26620
26935
  references: "project_find_references",
26621
26936
  check: "project_check_changes"
26622
26937
  });
26623
- var mapDirectoryPath = (path20) => path20.length > 1 && path20.endsWith("/") && !path20.endsWith("//") ? path20.slice(0, -1) : path20;
26938
+ var mapDirectoryPath = (path21) => path21.length > 1 && path21.endsWith("/") && !path21.endsWith("//") ? path21.slice(0, -1) : path21;
26624
26939
  var ProjectMapSearchInputSchema = external_exports.object({
26625
26940
  path: external_exports.string().default("."),
26626
26941
  query: external_exports.string().min(1).max(256),
@@ -26692,30 +27007,30 @@ var projectHeading = (project) => `Project ${project} (paths are relative to it)
26692
27007
  // src/agent/projects.ts
26693
27008
  import { existsSync as existsSync7 } from "node:fs";
26694
27009
  import { readdir as readdir2, realpath as realpath3, stat as stat3 } from "node:fs/promises";
26695
- import path17 from "node:path";
27010
+ import path18 from "node:path";
26696
27011
  var escapes = (relative) => {
26697
- const normal = path17.normalize(relative);
26698
- return normal === ".." || normal.startsWith(`..${path17.sep}`);
27012
+ const normal = path18.normalize(relative);
27013
+ return normal === ".." || normal.startsWith(`..${path18.sep}`);
26699
27014
  };
26700
27015
  async function locate(start, given) {
26701
- if (start.git && !path17.isAbsolute(given) && !escapes(given))
27016
+ if (start.git && !path18.isAbsolute(given) && !escapes(given))
26702
27017
  return { project: start.directory, path: given };
26703
- const absolute = path17.resolve(start.directory, given);
27018
+ const absolute = path18.resolve(start.directory, given);
26704
27019
  let directory = absolute;
26705
27020
  while (!(await stat3(directory).catch(() => void 0))?.isDirectory()) {
26706
- if (path17.dirname(directory) === directory) return void 0;
26707
- directory = path17.dirname(directory);
27021
+ if (path18.dirname(directory) === directory) return void 0;
27022
+ directory = path18.dirname(directory);
26708
27023
  }
26709
- const real = path17.join(await realpath3(directory), path17.relative(directory, absolute));
27024
+ const real = path18.join(await realpath3(directory), path18.relative(directory, absolute));
26710
27025
  const { directory: project, git: git2 } = await projectDirectory(directory);
26711
27026
  if (!git2) return void 0;
26712
- const relative = path17.relative(project, real);
27027
+ const relative = path18.relative(project, real);
26713
27028
  if (escapes(relative)) return void 0;
26714
- return { project, path: relative ? relative.split(path17.sep).join("/") : "." };
27029
+ return { project, path: relative ? relative.split(path18.sep).join("/") : "." };
26715
27030
  }
26716
27031
  async function repositoriesIn(directory) {
26717
27032
  const entries = await readdir2(directory, { withFileTypes: true }).catch(() => []);
26718
- return entries.filter((entry) => entry.isDirectory() && existsSync7(path17.join(directory, entry.name, ".git"))).map((entry) => `${entry.name}/`).sort();
27033
+ return entries.filter((entry) => entry.isDirectory() && existsSync7(path18.join(directory, entry.name, ".git"))).map((entry) => `${entry.name}/`).sort();
26719
27034
  }
26720
27035
  async function routeMapCall(start, { name, args }) {
26721
27036
  const references = name === MAP_TOOL_NAMES.references;
@@ -26726,7 +27041,7 @@ async function routeMapCall(start, { name, args }) {
26726
27041
  if (!located) {
26727
27042
  const repositories = start.git ? [] : await repositoriesIn(start.directory);
26728
27043
  const such = repositories.length ? `, such as ${repositories.join(", ")}` : "";
26729
- return named === "." ? `LAYERMAP_NOT_A_GIT_REPOSITORY: This session started in ${start.directory}, which is not in a Git repository. Name a file or directory in one, relative to that folder or absolute${such}.` : `LAYERMAP_NOT_A_GIT_REPOSITORY: ${path17.resolve(start.directory, named)} is not in a Git repository; LayerMap maps Git repositories${start.git ? "" : `. Name a file or directory in one, relative to ${start.directory} or absolute${such}`}.`;
27044
+ return named === "." ? `LAYERMAP_NOT_A_GIT_REPOSITORY: This session started in ${start.directory}, which is not in a Git repository. Name a file or directory in one, relative to that folder or absolute${such}.` : `LAYERMAP_NOT_A_GIT_REPOSITORY: ${path18.resolve(start.directory, named)} is not in a Git repository; LayerMap maps Git repositories${start.git ? "" : `. Name a file or directory in one, relative to ${start.directory} or absolute${such}`}.`;
26730
27045
  }
26731
27046
  if (!references) {
26732
27047
  const routed2 = value === void 0 ? args : { ...args, path: located.path };
@@ -27116,9 +27431,9 @@ ${text}` : text
27116
27431
  // src/agent/setup.ts
27117
27432
  import { execFile } from "node:child_process";
27118
27433
  import { existsSync as existsSync8 } from "node:fs";
27119
- import { mkdir as mkdir3, readFile as readFile5, rename as rename3, rm as rm2, writeFile as writeFile2 } from "node:fs/promises";
27120
- import { homedir as homedir2 } from "node:os";
27121
- import path18 from "node:path";
27434
+ import { mkdir as mkdir4, readFile as readFile7, rename as rename4, rm as rm3, writeFile as writeFile3 } from "node:fs/promises";
27435
+ import { homedir as homedir3 } from "node:os";
27436
+ import path19 from "node:path";
27122
27437
  var SERVER = "layermap";
27123
27438
  var SETUP_RULE = `mcp__${SERVER}`;
27124
27439
  var PLUGIN_RULE = `mcp__plugin_${SERVER}_${SERVER}`;
@@ -27126,11 +27441,11 @@ var BEGIN = "<!-- layermap:begin -->";
27126
27441
  var END = "<!-- layermap:end -->";
27127
27442
  var launcherScript = (template, version2, args = '["mcp"]') => `// Generated from scripts/launcher.mjs.
27128
27443
  ${template.replace("__VERSION__", JSON.stringify(version2)).replace("__ARGUMENTS__", args)}`;
27129
- var PUBLISHED_LAUNCHER = path18.join(packageRoot, "dist", "launcher.mjs");
27130
- var launcherFile = (env = process.env) => path18.join(cacheDirectory(env), "server.mjs");
27444
+ var PUBLISHED_LAUNCHER = path19.join(packageRoot, "dist", "launcher.mjs");
27445
+ var launcherFile = (env = process.env) => path19.join(cacheDirectory(env), "server.mjs");
27131
27446
  var mcpLaunchCommand = (env = process.env, published = existsSync8(PUBLISHED_LAUNCHER)) => {
27132
27447
  if (published) return ["node", launcherFile(env)];
27133
- const script = path18.resolve(process.argv[1] ?? "");
27448
+ const script = path19.resolve(process.argv[1] ?? "");
27134
27449
  const execArgv = [];
27135
27450
  for (let index = 0; index < process.execArgv.length; index++) {
27136
27451
  const argument = process.execArgv[index];
@@ -27157,7 +27472,7 @@ var run = (command, args, env) => new Promise((resolve) => {
27157
27472
  );
27158
27473
  });
27159
27474
  async function allowInClaudeSettings(file2, rule = SETUP_RULE) {
27160
- const settings = existsSync8(file2) ? JSON.parse(await readFile5(file2, "utf8")) : {};
27475
+ const settings = existsSync8(file2) ? JSON.parse(await readFile7(file2, "utf8")) : {};
27161
27476
  if (typeof settings !== "object" || settings === null || Array.isArray(settings))
27162
27477
  throw new Error(`${file2} is not a settings object.`);
27163
27478
  settings.permissions ??= {};
@@ -27166,14 +27481,14 @@ async function allowInClaudeSettings(file2, rule = SETUP_RULE) {
27166
27481
  throw new Error(`${file2} has permissions.allow that is not a list.`);
27167
27482
  if (settings.permissions.allow.includes(rule)) return false;
27168
27483
  settings.permissions.allow.push(rule);
27169
- await mkdir3(path18.dirname(file2), { recursive: true });
27170
- await writeFile2(file2, `${JSON.stringify(settings, null, 2)}
27484
+ await mkdir4(path19.dirname(file2), { recursive: true });
27485
+ await writeFile3(file2, `${JSON.stringify(settings, null, 2)}
27171
27486
  `);
27172
27487
  return true;
27173
27488
  }
27174
27489
  var CODEX_TOOL_TIMEOUT_SEC = 300;
27175
27490
  async function configureCodexServer(file2) {
27176
- const lines = (await readFile5(file2, "utf8")).split("\n");
27491
+ const lines = (await readFile7(file2, "utf8")).split("\n");
27177
27492
  const header2 = lines.findIndex((line) => line.trim() === `[mcp_servers.${SERVER}]`);
27178
27493
  if (header2 < 0) throw new Error(`${file2} has no [mcp_servers.${SERVER}] table.`);
27179
27494
  let end = header2 + 1;
@@ -27189,52 +27504,52 @@ async function configureCodexServer(file2) {
27189
27504
  const added = Object.entries(wanted).filter(([key]) => !present.has(key)).map(([key, value]) => `${key} = ${value}`);
27190
27505
  if (!added.length) return false;
27191
27506
  lines.splice(header2 + 1, 0, ...added);
27192
- await writeFile2(file2, lines.join("\n"));
27507
+ await writeFile3(file2, lines.join("\n"));
27193
27508
  return true;
27194
27509
  }
27195
27510
  async function writeInstructionNote(file2, note = AGENT_MAP_NOTE) {
27196
27511
  const block = `${BEGIN}
27197
27512
  ${note}
27198
27513
  ${END}`;
27199
- const text = existsSync8(file2) ? await readFile5(file2, "utf8") : "";
27514
+ const text = existsSync8(file2) ? await readFile7(file2, "utf8") : "";
27200
27515
  const start = text.indexOf(BEGIN);
27201
27516
  const end = text.indexOf(END);
27202
27517
  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}
27203
27518
  `;
27204
27519
  if (next === text) return;
27205
- await mkdir3(path18.dirname(file2), { recursive: true });
27206
- await writeFile2(file2, next);
27520
+ await mkdir4(path19.dirname(file2), { recursive: true });
27521
+ await writeFile3(file2, next);
27207
27522
  }
27208
27523
  async function removeInstructionNote(file2) {
27209
27524
  if (!existsSync8(file2)) return;
27210
- const text = await readFile5(file2, "utf8");
27525
+ const text = await readFile7(file2, "utf8");
27211
27526
  const start = text.indexOf(BEGIN);
27212
27527
  const end = text.indexOf(END);
27213
27528
  if (start < 0 || end < start) return;
27214
27529
  const before = text.slice(0, start).replace(/\n\n$/u, "\n");
27215
27530
  const rest = `${before}${text.slice(end + END.length).replace(/^\n/u, "")}`;
27216
- if (!rest.trim()) await rm2(file2);
27217
- else await writeFile2(file2, rest);
27531
+ if (!rest.trim()) await rm3(file2);
27532
+ else await writeFile3(file2, rest);
27218
27533
  }
27219
27534
  async function disallowInClaudeSettings(file2) {
27220
27535
  if (!existsSync8(file2)) return;
27221
- const settings = JSON.parse(await readFile5(file2, "utf8"));
27536
+ const settings = JSON.parse(await readFile7(file2, "utf8"));
27222
27537
  const allow = settings?.permissions?.allow;
27223
27538
  const ours = (rule) => rule === SETUP_RULE || rule === PLUGIN_RULE;
27224
27539
  if (!Array.isArray(allow) || !allow.some(ours)) return;
27225
27540
  settings.permissions.allow = allow.filter((rule) => !ours(rule));
27226
27541
  if (!settings.permissions.allow.length) delete settings.permissions.allow;
27227
27542
  if (!Object.keys(settings.permissions).length) delete settings.permissions;
27228
- await writeFile2(file2, `${JSON.stringify(settings, null, 2)}
27543
+ await writeFile3(file2, `${JSON.stringify(settings, null, 2)}
27229
27544
  `);
27230
27545
  }
27231
27546
  var YAML_BEGIN = "# layermap:begin";
27232
27547
  var YAML_END = "# layermap:end";
27233
- var nodeDirectory = (env = process.env) => (env.PATH ?? "").split(path18.delimiter).find((directory) => path18.isAbsolute(directory) && existsSync8(path18.join(directory, "node"))) ?? path18.dirname(process.execPath);
27548
+ var nodeDirectory = (env = process.env) => (env.PATH ?? "").split(path19.delimiter).find((directory) => path19.isAbsolute(directory) && existsSync8(path19.join(directory, "node"))) ?? path19.dirname(process.execPath);
27234
27549
  var dshPatchBlock = (command, env) => {
27235
27550
  const node = nodeDirectory(env);
27236
- const [program = "", ...args] = command[0] === "node" ? [path18.join(node, "node"), ...command.slice(1)] : command;
27237
- const searchPath2 = `${JSON.stringify(`${node}${path18.delimiter}`)} + process.env.PATH`;
27551
+ const [program = "", ...args] = command[0] === "node" ? [path19.join(node, "node"), ...command.slice(1)] : command;
27552
+ const searchPath2 = `${JSON.stringify(`${node}${path19.delimiter}`)} + process.env.PATH`;
27238
27553
  return [
27239
27554
  `${YAML_BEGIN} (written by \`layermap setup dsh\`; \`layermap remove dsh\` deletes it)`,
27240
27555
  "- insert:",
@@ -27253,7 +27568,7 @@ var dshPatchBlock = (command, env) => {
27253
27568
  ].join("\n");
27254
27569
  };
27255
27570
  async function writeDshPatch(file2, block) {
27256
- const text = existsSync8(file2) ? await readFile5(file2, "utf8") : "";
27571
+ const text = existsSync8(file2) ? await readFile7(file2, "utf8") : "";
27257
27572
  const start = text.indexOf(YAML_BEGIN);
27258
27573
  const end = text.indexOf(YAML_END);
27259
27574
  let next;
@@ -27269,49 +27584,49 @@ async function writeDshPatch(file2, block) {
27269
27584
  `;
27270
27585
  }
27271
27586
  if (next === text) return;
27272
- await mkdir3(path18.dirname(file2), { recursive: true });
27273
- await writeFile2(file2, next);
27587
+ await mkdir4(path19.dirname(file2), { recursive: true });
27588
+ await writeFile3(file2, next);
27274
27589
  }
27275
27590
  async function removeDshPatch(file2) {
27276
27591
  if (!existsSync8(file2)) return;
27277
- const text = await readFile5(file2, "utf8");
27592
+ const text = await readFile7(file2, "utf8");
27278
27593
  const start = text.indexOf(YAML_BEGIN);
27279
27594
  const end = text.indexOf(YAML_END);
27280
27595
  if (start < 0 || end < start) return;
27281
27596
  const rest = `${text.slice(0, start)}${text.slice(end + YAML_END.length).replace(/^\n/u, "")}`;
27282
- if (!rest.trim()) return rm2(file2);
27597
+ if (!rest.trim()) return rm3(file2);
27283
27598
  const content = rest.split("\n").some((line) => line.trim() && !line.trim().startsWith("#"));
27284
- await writeFile2(file2, content ? rest : `${rest}${rest.endsWith("\n") ? "" : "\n"}[]
27599
+ await writeFile3(file2, content ? rest : `${rest}${rest.endsWith("\n") ? "" : "\n"}[]
27285
27600
  `);
27286
27601
  }
27287
27602
  var agentFiles = (options) => {
27288
27603
  const env = options.env ?? process.env;
27289
27604
  if (options.agent === "dsh") {
27290
- const home = env.DSH_HOME || path18.join(homedir2(), ".dsh");
27605
+ const home = env.DSH_HOME || path19.join(homedir3(), ".dsh");
27291
27606
  return {
27292
- settings: path18.join(home, "cordis.patch.yml"),
27293
- instructions: path18.join(home, "AGENTS.md")
27607
+ settings: path19.join(home, "cordis.patch.yml"),
27608
+ instructions: path19.join(home, "AGENTS.md")
27294
27609
  };
27295
27610
  }
27296
27611
  if (options.agent === "codex") {
27297
- const home = env.CODEX_HOME ?? path18.join(homedir2(), ".codex");
27298
- return { settings: path18.join(home, "config.toml"), instructions: path18.join(home, "AGENTS.md") };
27612
+ const home = env.CODEX_HOME ?? path19.join(homedir3(), ".codex");
27613
+ return { settings: path19.join(home, "config.toml"), instructions: path19.join(home, "AGENTS.md") };
27299
27614
  }
27300
27615
  if (options.scope === "user") {
27301
- const home = env.CLAUDE_CONFIG_DIR ?? path18.join(homedir2(), ".claude");
27616
+ const home = env.CLAUDE_CONFIG_DIR ?? path19.join(homedir3(), ".claude");
27302
27617
  return {
27303
- settings: path18.join(home, "settings.json"),
27304
- instructions: path18.join(home, "CLAUDE.md")
27618
+ settings: path19.join(home, "settings.json"),
27619
+ instructions: path19.join(home, "CLAUDE.md")
27305
27620
  };
27306
27621
  }
27307
27622
  const local = options.scope === "local";
27308
27623
  return {
27309
- settings: path18.join(
27624
+ settings: path19.join(
27310
27625
  options.project,
27311
27626
  ".claude",
27312
27627
  local ? "settings.local.json" : "settings.json"
27313
27628
  ),
27314
- instructions: path18.join(options.project, local ? "CLAUDE.local.md" : "CLAUDE.md")
27629
+ instructions: path19.join(options.project, local ? "CLAUDE.local.md" : "CLAUDE.md")
27315
27630
  };
27316
27631
  };
27317
27632
  async function setupAgent(options) {
@@ -27331,12 +27646,12 @@ async function setupAgent(options) {
27331
27646
  const writeLauncher = async () => {
27332
27647
  if (!published) return;
27333
27648
  const file2 = launcherFile(env);
27334
- await mkdir3(path18.dirname(file2), { recursive: true, mode: 448 });
27335
- await writeFile2(
27649
+ await mkdir4(path19.dirname(file2), { recursive: true, mode: 448 });
27650
+ await writeFile3(
27336
27651
  `${file2}.${process.pid}`,
27337
- launcherScript(await readFile5(PUBLISHED_LAUNCHER, "utf8"), options.version)
27652
+ launcherScript(await readFile7(PUBLISHED_LAUNCHER, "utf8"), options.version)
27338
27653
  );
27339
- await rename3(`${file2}.${process.pid}`, file2);
27654
+ await rename4(`${file2}.${process.pid}`, file2);
27340
27655
  };
27341
27656
  if (published) log2(`write the launcher of LayerMap ${options.version} to ${launcherFile(env)}`);
27342
27657
  if (options.agent === "dsh") {
@@ -27432,6 +27747,10 @@ Usage:
27432
27747
  layermap allow claude [--scope user|project|local] [--dry-run]
27433
27748
  let the plugin's read-only tools run without a prompt
27434
27749
  layermap remove claude|codex|dsh [--scope user|project|local] [--dry-run]
27750
+ layermap setup command [--dry-run] put a layermap command in ~/.local/bin, for shells with no
27751
+ plugin's on their PATH (Codex's commands, a terminal): it
27752
+ runs the newest version the agents' plugins have installed
27753
+ layermap remove command [--dry-run]
27435
27754
  layermap mcp [--project DIR] serve the map tools over MCP (stdio)
27436
27755
  layermap index [--project DIR] build or update the map now
27437
27756
  layermap explore [PATH] [--name NAME] [--line N] [--direction INCOMING|OUTGOING|BOTH]
@@ -27455,10 +27774,10 @@ var log = (line) => process.stderr.write(`${line}
27455
27774
  async function checkedTests(project, tests) {
27456
27775
  const here = await realpath4(process.cwd());
27457
27776
  return tests.map((test) => {
27458
- const relative = path19.relative(project, path19.resolve(here, test));
27459
- if (!relative || relative === ".." || relative.startsWith(`..${path19.sep}`) || path19.isAbsolute(relative))
27777
+ const relative = path20.relative(project, path20.resolve(here, test));
27778
+ if (!relative || relative === ".." || relative.startsWith(`..${path20.sep}`) || path20.isAbsolute(relative))
27460
27779
  throw new Error(`${test} is not in ${project}.`);
27461
- return relative.split(path19.sep).join("/");
27780
+ return relative.split(path20.sep).join("/");
27462
27781
  });
27463
27782
  }
27464
27783
  var usage = (code) => {
@@ -27517,6 +27836,11 @@ async function main(argv) {
27517
27836
  };
27518
27837
  if (command === "setup" || command === "allow" || command === "remove") {
27519
27838
  const agent = rest[0];
27839
+ if (agent === "command" && command !== "allow")
27840
+ return await (command === "setup" ? setupCommand : removeCommand)({
27841
+ dryRun: values["dry-run"],
27842
+ log
27843
+ }) ? 0 : 1;
27520
27844
  if (agent !== "claude" && agent !== "codex" && agent !== "dsh") return usage(1);
27521
27845
  if (!["user", "project", "local"].includes(values.scope)) return usage(1);
27522
27846
  const done = await { setup: setupAgent, allow: allowAgent, remove: removeAgent }[command]({