layermap 0.1.18 → 0.1.19

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
@@ -1294,10 +1294,10 @@ function mergeDefs(...defs) {
1294
1294
  function cloneDef(schema) {
1295
1295
  return mergeDefs(schema._zod.def);
1296
1296
  }
1297
- function getElementAtPath(obj, path13) {
1298
- if (!path13)
1297
+ function getElementAtPath(obj, path14) {
1298
+ if (!path14)
1299
1299
  return obj;
1300
- return path13.reduce((acc, key) => acc?.[key], obj);
1300
+ return path14.reduce((acc, key) => acc?.[key], obj);
1301
1301
  }
1302
1302
  function promiseAllObject(promisesObj) {
1303
1303
  const keys = Object.keys(promisesObj);
@@ -1706,11 +1706,11 @@ function explicitlyAborted(x, startIndex = 0) {
1706
1706
  }
1707
1707
  return false;
1708
1708
  }
1709
- function prefixIssues(path13, issues) {
1709
+ function prefixIssues(path14, issues) {
1710
1710
  return issues.map((iss) => {
1711
1711
  var _a3;
1712
1712
  (_a3 = iss).path ?? (_a3.path = []);
1713
- iss.path.unshift(path13);
1713
+ iss.path.unshift(path14);
1714
1714
  return iss;
1715
1715
  });
1716
1716
  }
@@ -1857,16 +1857,16 @@ function flattenError(error51, mapper = (issue2) => issue2.message) {
1857
1857
  }
1858
1858
  function formatError(error51, mapper = (issue2) => issue2.message) {
1859
1859
  const fieldErrors = { _errors: [] };
1860
- const processError = (error52, path13 = []) => {
1860
+ const processError = (error52, path14 = []) => {
1861
1861
  for (const issue2 of error52.issues) {
1862
1862
  if (issue2.code === "invalid_union" && issue2.errors.length) {
1863
- issue2.errors.map((issues) => processError({ issues }, [...path13, ...issue2.path]));
1863
+ issue2.errors.map((issues) => processError({ issues }, [...path14, ...issue2.path]));
1864
1864
  } else if (issue2.code === "invalid_key") {
1865
- processError({ issues: issue2.issues }, [...path13, ...issue2.path]);
1865
+ processError({ issues: issue2.issues }, [...path14, ...issue2.path]);
1866
1866
  } else if (issue2.code === "invalid_element") {
1867
- processError({ issues: issue2.issues }, [...path13, ...issue2.path]);
1867
+ processError({ issues: issue2.issues }, [...path14, ...issue2.path]);
1868
1868
  } else {
1869
- const fullpath = [...path13, ...issue2.path];
1869
+ const fullpath = [...path14, ...issue2.path];
1870
1870
  if (fullpath.length === 0) {
1871
1871
  fieldErrors._errors.push(mapper(issue2));
1872
1872
  } else {
@@ -1893,17 +1893,17 @@ function formatError(error51, mapper = (issue2) => issue2.message) {
1893
1893
  }
1894
1894
  function treeifyError(error51, mapper = (issue2) => issue2.message) {
1895
1895
  const result = { errors: [] };
1896
- const processError = (error52, path13 = []) => {
1896
+ const processError = (error52, path14 = []) => {
1897
1897
  var _a3, _b;
1898
1898
  for (const issue2 of error52.issues) {
1899
1899
  if (issue2.code === "invalid_union" && issue2.errors.length) {
1900
- issue2.errors.map((issues) => processError({ issues }, [...path13, ...issue2.path]));
1900
+ issue2.errors.map((issues) => processError({ issues }, [...path14, ...issue2.path]));
1901
1901
  } else if (issue2.code === "invalid_key") {
1902
- processError({ issues: issue2.issues }, [...path13, ...issue2.path]);
1902
+ processError({ issues: issue2.issues }, [...path14, ...issue2.path]);
1903
1903
  } else if (issue2.code === "invalid_element") {
1904
- processError({ issues: issue2.issues }, [...path13, ...issue2.path]);
1904
+ processError({ issues: issue2.issues }, [...path14, ...issue2.path]);
1905
1905
  } else {
1906
- const fullpath = [...path13, ...issue2.path];
1906
+ const fullpath = [...path14, ...issue2.path];
1907
1907
  if (fullpath.length === 0) {
1908
1908
  result.errors.push(mapper(issue2));
1909
1909
  continue;
@@ -1935,8 +1935,8 @@ function treeifyError(error51, mapper = (issue2) => issue2.message) {
1935
1935
  }
1936
1936
  function toDotPath(_path) {
1937
1937
  const segs = [];
1938
- const path13 = _path.map((seg) => typeof seg === "object" ? seg.key : seg);
1939
- for (const seg of path13) {
1938
+ const path14 = _path.map((seg) => typeof seg === "object" ? seg.key : seg);
1939
+ for (const seg of path14) {
1940
1940
  if (typeof seg === "number")
1941
1941
  segs.push(`[${seg}]`);
1942
1942
  else if (typeof seg === "symbol")
@@ -14628,13 +14628,13 @@ function resolveRef(ref, ctx) {
14628
14628
  if (!ref.startsWith("#")) {
14629
14629
  throw new Error("External $ref is not supported, only local refs (#/...) are allowed");
14630
14630
  }
14631
- const path13 = ref.slice(1).split("/").filter(Boolean);
14632
- if (path13.length === 0) {
14631
+ const path14 = ref.slice(1).split("/").filter(Boolean);
14632
+ if (path14.length === 0) {
14633
14633
  return ctx.rootSchema;
14634
14634
  }
14635
14635
  const defsKey = ctx.version === "draft-2020-12" ? "$defs" : "definitions";
14636
- if (path13[0] === defsKey) {
14637
- const key = path13[1];
14636
+ if (path14[0] === defsKey) {
14637
+ const key = path14[1];
14638
14638
  if (!key || !ctx.defs[key]) {
14639
14639
  throw new Error(`Reference not found: ${ref}`);
14640
14640
  }
@@ -15874,8 +15874,8 @@ var MapAnalysisSchema = external_exports.object({
15874
15874
  var mapPathAllowed = (relative, prefixes) => prefixes.some(
15875
15875
  (prefix) => prefix === "." || relative === prefix || relative.startsWith(`${prefix}/`)
15876
15876
  );
15877
- var mapTestPath = (path13) => /(?:^|\/)(?:__tests__|tests?|fixtures?|e2e|testdata)(?:\/|$)|\.(?:spec|test)\.|_test\.(?:go|py)$|(?:^|\/)(?:test_[^/]*\.py|conftest\.py)$/iu.test(
15878
- path13
15877
+ var mapTestPath = (path14) => /(?:^|\/)(?:__tests__|tests?|fixtures?|e2e|testdata)(?:\/|$)|\.(?:spec|test)\.|_test\.(?:go|py)$|(?:^|\/)(?:test_[^/]*\.py|conftest\.py)$/iu.test(
15878
+ path14
15879
15879
  );
15880
15880
 
15881
15881
  // src/project-map-reference-types.ts
@@ -15959,11 +15959,11 @@ var string4 = (value) => {
15959
15959
  var identity = (id2, reconstructed) => id2 === reconstructed ? [] : [JSON.stringify(id2)];
15960
15960
  function encodeMapText(graph) {
15961
15961
  const files = /* @__PURE__ */ new Map();
15962
- const file2 = (path13) => {
15963
- let ref = files.get(path13);
15962
+ const file2 = (path14) => {
15963
+ let ref = files.get(path14);
15964
15964
  if (!ref) {
15965
15965
  ref = `F${files.size + 1}`;
15966
- files.set(path13, ref);
15966
+ files.set(path14, ref);
15967
15967
  }
15968
15968
  return ref;
15969
15969
  };
@@ -16011,7 +16011,7 @@ function encodeMapText(graph) {
16011
16011
  rows.push(`B ${node(frontier.entityRef)} ${frontier.direction}`);
16012
16012
  return [
16013
16013
  ...header,
16014
- ...[...files].map(([path13, ref]) => `${ref} ${JSON.stringify(path13)}`),
16014
+ ...[...files].map(([path14, ref]) => `${ref} ${JSON.stringify(path14)}`),
16015
16015
  ...rows
16016
16016
  ].join("\n");
16017
16017
  }
@@ -16031,10 +16031,10 @@ function decodeMapText(text) {
16031
16031
  const at = (value) => {
16032
16032
  const match = /^(F[1-9]\d*):(\d+)-(\d+)@(\d+)-(\d+)$/u.exec(value ?? "");
16033
16033
  if (!match) return failed();
16034
- const path13 = files.get(match[1] ?? "");
16035
- if (path13 === void 0) return failed();
16034
+ const path14 = files.get(match[1] ?? "");
16035
+ if (path14 === void 0) return failed();
16036
16036
  return MapAnchorSchema.parse({
16037
- path: path13,
16037
+ path: path14,
16038
16038
  startLine: Number(match[2]),
16039
16039
  endLine: Number(match[3]),
16040
16040
  start: Number(match[4]),
@@ -16111,8 +16111,8 @@ function decodeMapText(text) {
16111
16111
  var locationSchema = MapAnchorSchema.describe(
16112
16112
  "Source location: start/end are zero-based UTF-16 offsets with an exclusive end; line numbers are one-based."
16113
16113
  );
16114
- var location = ({ path: path13, startLine, endLine, start, end }) => ({
16115
- path: path13,
16114
+ var location = ({ path: path14, startLine, endLine, start, end }) => ({
16115
+ path: path14,
16116
16116
  startLine,
16117
16117
  endLine,
16118
16118
  start,
@@ -16215,11 +16215,11 @@ var MapNavigationObjectsSchema = external_exports.union([
16215
16215
  ),
16216
16216
  external_exports.object({ files: external_exports.array(searchFileSchema) }).passthrough().refine((value) => !("format" in value), "Text navigation must decode through its format.").transform(
16217
16217
  (value) => value.files.flatMap(
16218
- ({ path: path13, symbols }) => symbols.map(({ id: id2, name, kind, startLine, endLine, start, end, execution }) => ({
16218
+ ({ path: path14, symbols }) => symbols.map(({ id: id2, name, kind, startLine, endLine, start, end, execution }) => ({
16219
16219
  id: id2,
16220
16220
  name,
16221
16221
  kind,
16222
- anchor: { path: path13, startLine, endLine, start, end },
16222
+ anchor: { path: path14, startLine, endLine, start, end },
16223
16223
  ...execution ? { execution } : {}
16224
16224
  }))
16225
16225
  )
@@ -16232,10 +16232,10 @@ var mapSearchNavigation = (result) => {
16232
16232
  for (const [index, object2] of found.entries()) {
16233
16233
  const ranking = rankings[index];
16234
16234
  if (!ranking) throw new Error("PROJECT_MAP_SEARCH_RANKING_MISSING");
16235
- const path13 = object2.anchor.path;
16235
+ const path14 = object2.anchor.path;
16236
16236
  let file2 = files.at(-1);
16237
- if (file2?.path !== path13) {
16238
- file2 = { path: path13, symbols: [] };
16237
+ if (file2?.path !== path14) {
16238
+ file2 = { path: path14, symbols: [] };
16239
16239
  files.push(file2);
16240
16240
  }
16241
16241
  file2.symbols.push({
@@ -16361,8 +16361,8 @@ var MapViewGraph = class {
16361
16361
  }
16362
16362
  return object2;
16363
16363
  }
16364
- objectsAt(path13) {
16365
- return this.statements.path.all(this.version, path13).map((row) => {
16364
+ objectsAt(path14) {
16365
+ return this.statements.path.all(this.version, path14).map((row) => {
16366
16366
  const object2 = MapObjectSchema.parse(JSON.parse(String(row.object_json)));
16367
16367
  this.objects.set(object2.id, object2);
16368
16368
  return object2;
@@ -16481,8 +16481,8 @@ var MapViewGraph = class {
16481
16481
  );
16482
16482
  }
16483
16483
  };
16484
- function mapSelectDeclarations(graph, path13, name, line) {
16485
- const objects2 = graph.objectsAt(path13).filter((object2) => !mapIsModule(object2));
16484
+ function mapSelectDeclarations(graph, path14, name, line) {
16485
+ const objects2 = graph.objectsAt(path14).filter((object2) => !mapIsModule(object2));
16486
16486
  const matching = name === void 0 ? objects2 : objects2.filter(
16487
16487
  (object2) => object2.name === name || name.includes(".") && graph.qualifiedName(object2.id) === name
16488
16488
  );
@@ -16504,12 +16504,12 @@ function requireMapObject(store, version2, selector, prefixes) {
16504
16504
  if ([entityRef, locator, symbol2].filter((value) => value !== void 0).length !== 1 || entityRef !== void 0 && !entityRef.length)
16505
16505
  throw new ProjectEvidenceError("PROJECT_READ_INPUT_INVALID", false);
16506
16506
  if (symbol2) {
16507
- const path13 = normalizeProjectEvidencePath(symbol2.path);
16508
- if (!mapPathAllowed(path13, prefixes))
16507
+ const path14 = normalizeProjectEvidencePath(symbol2.path);
16508
+ if (!mapPathAllowed(path14, prefixes))
16509
16509
  throw new ProjectEvidenceError("PROJECT_MAP_OBJECT_NOT_FOUND", false);
16510
16510
  const selected = mapSelectDeclarations(
16511
16511
  new MapViewGraph(store, version2),
16512
- path13,
16512
+ path14,
16513
16513
  symbol2.name,
16514
16514
  symbol2.line
16515
16515
  );
@@ -16520,14 +16520,14 @@ function requireMapObject(store, version2, selector, prefixes) {
16520
16520
  }
16521
16521
  let rows;
16522
16522
  if (locator) {
16523
- const path13 = normalizeProjectEvidencePath(locator.path);
16523
+ const path14 = normalizeProjectEvidencePath(locator.path);
16524
16524
  if (!Number.isSafeInteger(locator.start) || locator.start < 0 || locator.kind !== void 0 && !MapObjectKindSchema.safeParse(locator.kind).success)
16525
16525
  throw new ProjectEvidenceError("PROJECT_READ_INPUT_INVALID", false);
16526
- if (!mapPathAllowed(path13, prefixes))
16526
+ if (!mapPathAllowed(path14, prefixes))
16527
16527
  throw new ProjectEvidenceError("PROJECT_MAP_OBJECT_NOT_FOUND", false);
16528
16528
  rows = store.database.prepare(`SELECT object_json FROM project_map_objects
16529
16529
  WHERE version_ref = ? AND path = ? AND json_extract(object_json, '$.anchor.start') = ?
16530
- AND (? IS NULL OR kind = ?) LIMIT 2`).all(version2, path13, locator.start, locator.kind ?? null, locator.kind ?? null);
16530
+ AND (? IS NULL OR kind = ?) LIMIT 2`).all(version2, path14, locator.start, locator.kind ?? null, locator.kind ?? null);
16531
16531
  } else {
16532
16532
  rows = store.database.prepare(
16533
16533
  "SELECT object_json FROM project_map_objects WHERE version_ref = ? AND entity_ref = ?"
@@ -16568,13 +16568,13 @@ function mapQueryPage(count, materialize, navigation, budget) {
16568
16568
 
16569
16569
  // src/project-map-query-selection.ts
16570
16570
  var mapQuerySelection = (input, knownKinds) => {
16571
- const path13 = normalizeProjectEvidencePath(input.path ?? ".", true) || ".";
16571
+ const path14 = normalizeProjectEvidencePath(input.path ?? ".", true) || ".";
16572
16572
  const kinds = input.kinds ?? knownKinds;
16573
16573
  if (!Array.isArray(kinds) || !kinds.length || kinds.length > knownKinds.length || kinds.some((kind) => !knownKinds.includes(kind)))
16574
16574
  throw new ProjectEvidenceError("PROJECT_READ_INPUT_INVALID", false);
16575
- return { path: path13, kinds: [...new Set(kinds)].sort() };
16575
+ return { path: path14, kinds: [...new Set(kinds)].sort() };
16576
16576
  };
16577
- var mapQueryPathMatches = (path13, prefix) => prefix === "." || path13 === prefix || path13.startsWith(`${prefix}/`);
16577
+ var mapQueryPathMatches = (path14, prefix) => prefix === "." || path14 === prefix || path14.startsWith(`${prefix}/`);
16578
16578
  var mapQueryPathSql = (column) => `(? = '.' OR ${column} = ? OR substr(${column}, 1, length(?) + 1) = ? || '/')`;
16579
16579
 
16580
16580
  // src/project-map-search-focus.ts
@@ -16672,7 +16672,7 @@ var declarationKinds = /* @__PURE__ */ new Set([
16672
16672
  "METHOD",
16673
16673
  "TYPE"
16674
16674
  ]);
16675
- var fileStem = (path13) => path13.slice(path13.lastIndexOf("/") + 1).replace(/\.(?:[cm]?[jt]sx?|vue|svelte|go|pyi?)$/iu, "");
16675
+ var fileStem = (path14) => path14.slice(path14.lastIndexOf("/") + 1).replace(/\.(?:[cm]?[jt]sx?|vue|svelte|go|pyi?)$/iu, "");
16676
16676
  var compareText = (left, right) => left < right ? -1 : left > right ? 1 : 0;
16677
16677
  var compareRows = (left, right) => right.ranking.score - left.ranking.score || compareText(left.object.anchor.path, right.object.anchor.path) || compareText(left.object.id, right.object.id);
16678
16678
  function mapSearchQuery(input) {
@@ -16699,10 +16699,10 @@ function mapSearchQuery(input) {
16699
16699
  }
16700
16700
  function rank(object2, documentation, relationCount, query, focus) {
16701
16701
  const name = object2.name.toLowerCase();
16702
- const path13 = object2.anchor.path.toLowerCase();
16702
+ const path14 = object2.anchor.path.toLowerCase();
16703
16703
  const values = {
16704
16704
  NAME: [name],
16705
- PATH: [path13],
16705
+ PATH: [path14],
16706
16706
  DOCUMENTATION: documentation.map((text) => text.toLowerCase())
16707
16707
  };
16708
16708
  const matched = query.terms.map((term) => ({
@@ -16727,12 +16727,12 @@ function rank(object2, documentation, relationCount, query, focus) {
16727
16727
  score += 7e3;
16728
16728
  signals.push("SYMBOL_CONTAINS");
16729
16729
  } else if (matchedFields.includes("NAME")) signals.push("SYMBOL_CONTAINS");
16730
- if (object2.kind === "FILE" && fileStem(path13) === normalizedQuery) {
16730
+ if (object2.kind === "FILE" && fileStem(path14) === normalizedQuery) {
16731
16731
  score += 11e3;
16732
16732
  signals.push("EXACT_FILE_STEM");
16733
16733
  }
16734
16734
  if (matchedFields.includes("PATH")) {
16735
- score += path13.includes(normalizedQuery) ? 2500 : 0;
16735
+ score += path14.includes(normalizedQuery) ? 2500 : 0;
16736
16736
  signals.push("PATH_CONTAINS");
16737
16737
  }
16738
16738
  if (matchedFields.includes("DOCUMENTATION")) {
@@ -16747,8 +16747,8 @@ function rank(object2, documentation, relationCount, query, focus) {
16747
16747
  score += kindWeight[object2.kind] + Math.min(1200, relationCount * 20) + (focus?.score ?? 0);
16748
16748
  if (declarationKinds.has(object2.kind)) signals.push("DECLARATION");
16749
16749
  if (relationCount > 0) signals.push("GRAPH_CONNECTED");
16750
- const isTest = mapTestPath(path13);
16751
- const isGenerated = generatedPath.test(path13);
16750
+ const isTest = mapTestPath(path14);
16751
+ const isGenerated = generatedPath.test(path14);
16752
16752
  const hasTestIntent = query.terms.some((term) => testQuery.test(term));
16753
16753
  score += isTest ? hasTestIntent ? 1e3 : -5e3 : 300;
16754
16754
  score += isGenerated ? -3e3 : 300;
@@ -17232,13 +17232,13 @@ function utf16Offsets(text) {
17232
17232
  }
17233
17233
  function offsetConverter(files, offsets) {
17234
17234
  const converters = /* @__PURE__ */ new Map();
17235
- return (path13, offset) => {
17236
- let convert = converters.get(path13);
17235
+ return (path14, offset) => {
17236
+ let convert = converters.get(path14);
17237
17237
  if (!convert) {
17238
- const text = files[path13];
17238
+ const text = files[path14];
17239
17239
  if (text === void 0) return invalid();
17240
17240
  convert = offsets === "UTF16" ? (value) => value <= text.length ? value : invalid() : utf16Offsets(text);
17241
- converters.set(path13, convert);
17241
+ converters.set(path14, convert);
17242
17242
  }
17243
17243
  return convert(offset);
17244
17244
  };
@@ -17269,7 +17269,7 @@ function mapFactsAnalysis(facts, input, context) {
17269
17269
  const collect = new MapOutputCollector(output);
17270
17270
  const positions = new MapSourcePositions(input.files);
17271
17271
  const offset = offsetConverter(input.files, context.offsets);
17272
- const anchor = (path13, start, end) => positions.span(path13, offset(path13, start), offset(path13, end));
17272
+ const anchor = (path14, start, end) => positions.span(path14, offset(path14, start), offset(path14, end));
17273
17273
  const located = /* @__PURE__ */ new Map();
17274
17274
  const canonical = /* @__PURE__ */ new Map();
17275
17275
  const bySpan = /* @__PURE__ */ new Map();
@@ -17835,8 +17835,8 @@ var goModule = /(?:^|\/)go\.mod$/u;
17835
17835
  var codeHosts = /* @__PURE__ */ new Set(["github.com", "gitlab.com", "bitbucket.org"]);
17836
17836
  var GO_MAP_LANGUAGE = Object.freeze({
17837
17837
  id: "go-1.24-map-v9",
17838
- claims: (path13) => path13.endsWith(".go"),
17839
- reads: (path13) => goModule.test(path13),
17838
+ claims: (path14) => path14.endsWith(".go"),
17839
+ reads: (path14) => goModule.test(path14),
17840
17840
  // A module path, or the standard library, whose first path element has no dot.
17841
17841
  importName: (specifier) => {
17842
17842
  const parts = specifier.split("/");
@@ -17845,7 +17845,7 @@ var GO_MAP_LANGUAGE = Object.freeze({
17845
17845
  return parts.slice(0, size).join("/");
17846
17846
  },
17847
17847
  // Go imports a package: the directory of the file.
17848
- importTarget: (path13) => `${path13.slice(0, path13.lastIndexOf("/") + 1) || "./"}`,
17848
+ importTarget: (path14) => `${path14.slice(0, path14.lastIndexOf("/") + 1) || "./"}`,
17849
17849
  create: () => new GoMapAnalyzer()
17850
17850
  });
17851
17851
  var GO_GAPS = [
@@ -17891,12 +17891,12 @@ var GoMapAnalyzer = class {
17891
17891
  }
17892
17892
  }
17893
17893
  async analyze(session, signal) {
17894
- const modules = session.readable.map((entry) => entry.path).filter((path13) => goModule.test(path13)).sort();
17895
- const moduleOf = (path13) => {
17894
+ const modules = session.readable.map((entry) => entry.path).filter((path14) => goModule.test(path14)).sort();
17895
+ const moduleOf = (path14) => {
17896
17896
  let best;
17897
17897
  for (const modFile of modules) {
17898
17898
  const directory = modFile.slice(0, modFile.lastIndexOf("/") + 1);
17899
- if (path13.startsWith(directory) && (!best || directory.length > best.lastIndexOf("/") + 1))
17899
+ if (path14.startsWith(directory) && (!best || directory.length > best.lastIndexOf("/") + 1))
17900
17900
  best = modFile;
17901
17901
  }
17902
17902
  return best;
@@ -17912,11 +17912,11 @@ var GoMapAnalyzer = class {
17912
17912
  for (const modFile of [...groups.keys()].sort()) {
17913
17913
  if (signal.aborted) throw new ProjectEvidenceError("PROJECT_READ_CANCELLED", true);
17914
17914
  const files = /* @__PURE__ */ Object.create(null);
17915
- for (const path13 of [...groups.get(modFile) ?? [], ...modFile ? [modFile] : []]) {
17916
- const text = session.texts[path13];
17915
+ for (const path14 of [...groups.get(modFile) ?? [], ...modFile ? [modFile] : []]) {
17916
+ const text = session.texts[path14];
17917
17917
  if (text === void 0)
17918
17918
  throw new ProjectEvidenceError("PROJECT_MAP_PROTOCOL_INVALID", false);
17919
- files[path13] = text;
17919
+ files[path14] = text;
17920
17920
  }
17921
17921
  const input = {
17922
17922
  contextRef: digestValue({
@@ -17951,8 +17951,8 @@ var GoMapAnalyzer = class {
17951
17951
  if (text === void 0 || !existsSync3(this.resources.compilerPath))
17952
17952
  throw new ProjectEvidenceError("PROJECT_MAP_REFERENCE_TARGET_UNAVAILABLE", false);
17953
17953
  const files = /* @__PURE__ */ Object.create(null);
17954
- for (const [path13, value] of Object.entries(input.files))
17955
- if (this.claims(path13) || goModule.test(path13)) files[path13] = value;
17954
+ for (const [path14, value] of Object.entries(input.files))
17955
+ if (this.claims(path14) || goModule.test(path14)) files[path14] = value;
17956
17956
  const facts = await this.operation(
17957
17957
  {
17958
17958
  ...input,
@@ -17982,14 +17982,14 @@ var BUILD_FILES = [
17982
17982
  "pom.xml"
17983
17983
  ];
17984
17984
  var buildFile = /(?:^|\/)(?:pom\.xml|(?:build|settings)\.gradle(?:\.kts)?)$/u;
17985
- var directoryOf = (path13) => path13.slice(0, path13.lastIndexOf("/") + 1);
17986
- var nameOf = (path13) => path13.slice(path13.lastIndexOf("/") + 1);
17985
+ var directoryOf = (path14) => path14.slice(0, path14.lastIndexOf("/") + 1);
17986
+ var nameOf = (path14) => path14.slice(path14.lastIndexOf("/") + 1);
17987
17987
  var DEFAULT_RELEASE = 21;
17988
17988
  var platformPackage = /^(?:java|jdk|sun|com\.sun|javax\.(?:annotation\.processing|crypto|imageio|lang\.model|management|naming|net|print|script|security|sound|sql|swing|tools|transaction\.xa|xml))(?:\.|$)/u;
17989
17989
  var JAVA_MAP_LANGUAGE = Object.freeze({
17990
17990
  id: "javac-lombok-1.18.48-map-v8",
17991
- claims: (path13) => path13.endsWith(".java"),
17992
- reads: (path13) => buildFile.test(path13),
17991
+ claims: (path14) => path14.endsWith(".java"),
17992
+ reads: (path14) => buildFile.test(path14),
17993
17993
  // A package of the Java platform, or a library named by its first two package segments.
17994
17994
  importName: (specifier) => platformPackage.test(specifier) ? "Java standard library" : specifier.split(".").slice(0, 2).join("."),
17995
17995
  create: () => new JavaMapAnalyzer()
@@ -18079,12 +18079,12 @@ var JavaMapAnalyzer = class _JavaMapAnalyzer {
18079
18079
  // The worker's request for a context: the Java sources, the release and which are tests.
18080
18080
  request(input, buildTexts) {
18081
18081
  const files = /* @__PURE__ */ Object.create(null);
18082
- for (const [path13, text] of Object.entries(input.files))
18083
- if (this.claims(path13)) files[path13] = text;
18082
+ for (const [path14, text] of Object.entries(input.files))
18083
+ if (this.claims(path14)) files[path14] = text;
18084
18084
  return {
18085
18085
  files,
18086
18086
  release: javaRelease(buildTexts, this.resources.runtimeVersion),
18087
- tests: Object.keys(files).filter((path13) => mapTestPath(path13))
18087
+ tests: Object.keys(files).filter((path14) => mapTestPath(path14))
18088
18088
  };
18089
18089
  }
18090
18090
  // The build files of a context's root directory, which declare its Java version.
@@ -18096,35 +18096,35 @@ var JavaMapAnalyzer = class _JavaMapAnalyzer {
18096
18096
  }
18097
18097
  async analyze(session, signal) {
18098
18098
  this.refreshRuntime();
18099
- const builds = session.readable.map((entry) => entry.path).filter((path13) => buildFile.test(path13));
18100
- for (const path13 of builds) session.configuration(path13);
18101
- const rank2 = (path13) => BUILD_FILES.indexOf(nameOf(path13));
18099
+ const builds = session.readable.map((entry) => entry.path).filter((path14) => buildFile.test(path14));
18100
+ for (const path14 of builds) session.configuration(path14);
18101
+ const rank2 = (path14) => BUILD_FILES.indexOf(nameOf(path14));
18102
18102
  const roots = /* @__PURE__ */ new Map();
18103
18103
  const modules = /* @__PURE__ */ new Map();
18104
- for (const path13 of builds) {
18105
- const directory = directoryOf(path13);
18104
+ for (const path14 of builds) {
18105
+ const directory = directoryOf(path14);
18106
18106
  const current = modules.get(directory);
18107
- if (current === void 0 || rank2(path13) < rank2(current)) modules.set(directory, path13);
18108
- const text = session.texts[path13] ?? "";
18109
- if (/settings\.gradle(?:\.kts)?$/u.test(path13) || path13.endsWith("pom.xml") && /<modules>/u.test(text)) {
18107
+ if (current === void 0 || rank2(path14) < rank2(current)) modules.set(directory, path14);
18108
+ const text = session.texts[path14] ?? "";
18109
+ if (/settings\.gradle(?:\.kts)?$/u.test(path14) || path14.endsWith("pom.xml") && /<modules>/u.test(text)) {
18110
18110
  const root = roots.get(directory);
18111
- if (root === void 0 || rank2(path13) < rank2(root)) roots.set(directory, path13);
18111
+ if (root === void 0 || rank2(path14) < rank2(root)) roots.set(directory, path14);
18112
18112
  }
18113
18113
  }
18114
- const configOf = (path13) => {
18114
+ const configOf = (path14) => {
18115
18115
  let outer;
18116
18116
  for (const directory of roots.keys())
18117
- if (path13.startsWith(directory) && (outer === void 0 || directory.length < outer.length))
18117
+ if (path14.startsWith(directory) && (outer === void 0 || directory.length < outer.length))
18118
18118
  outer = directory;
18119
18119
  if (outer !== void 0) return roots.get(outer);
18120
18120
  let nearest;
18121
18121
  for (const directory of modules.keys())
18122
- if (path13.startsWith(directory) && (nearest === void 0 || directory.length > nearest.length))
18122
+ if (path14.startsWith(directory) && (nearest === void 0 || directory.length > nearest.length))
18123
18123
  nearest = directory;
18124
18124
  return nearest === void 0 ? "" : modules.get(nearest);
18125
18125
  };
18126
- const output = (path13) => [...modules.keys()].some(
18127
- (directory) => path13.startsWith(`${directory}build/`) || path13.startsWith(`${directory}target/`)
18126
+ const output = (path14) => [...modules.keys()].some(
18127
+ (directory) => path14.startsWith(`${directory}build/`) || path14.startsWith(`${directory}target/`)
18128
18128
  );
18129
18129
  const groups = /* @__PURE__ */ new Map();
18130
18130
  for (const entry of session.readable) {
@@ -18139,13 +18139,13 @@ var JavaMapAnalyzer = class _JavaMapAnalyzer {
18139
18139
  if (signal.aborted) throw new ProjectEvidenceError("PROJECT_READ_CANCELLED", true);
18140
18140
  const files = /* @__PURE__ */ Object.create(null);
18141
18141
  const rootBuilds = configPath ? BUILD_FILES.map((name) => `${directoryOf(configPath)}${name}`).filter(
18142
- (path13) => builds.includes(path13)
18142
+ (path14) => builds.includes(path14)
18143
18143
  ) : [];
18144
- for (const path13 of [...groups.get(configPath) ?? [], ...rootBuilds]) {
18145
- const text = session.texts[path13];
18144
+ for (const path14 of [...groups.get(configPath) ?? [], ...rootBuilds]) {
18145
+ const text = session.texts[path14];
18146
18146
  if (text === void 0)
18147
18147
  throw new ProjectEvidenceError("PROJECT_MAP_PROTOCOL_INVALID", false);
18148
- files[path13] = text;
18148
+ files[path14] = text;
18149
18149
  }
18150
18150
  const input = {
18151
18151
  contextRef: digestValue({
@@ -18188,7 +18188,7 @@ var JavaMapAnalyzer = class _JavaMapAnalyzer {
18188
18188
  const prior = JavaStateSchema.safeParse(previous?.state).data;
18189
18189
  const incremental = previous && prior?.basis === basis ? {
18190
18190
  changed: Object.keys(request.files).filter(
18191
- (path13) => digests.get(path13) !== previous.digests.get(path13)
18191
+ (path14) => digests.get(path14) !== previous.digests.get(path14)
18192
18192
  ),
18193
18193
  state: prior.java
18194
18194
  } : void 0;
@@ -18217,14 +18217,14 @@ var JavaMapAnalyzer = class _JavaMapAnalyzer {
18217
18217
  continue;
18218
18218
  }
18219
18219
  const focus = new Set(facts.focus);
18220
- if (!incremental || facts.focus.some((path13) => !Object.hasOwn(request.files, path13)) || incremental.changed.some((path13) => !focus.has(path13)))
18220
+ if (!incremental || facts.focus.some((path14) => !Object.hasOwn(request.files, path14)) || incremental.changed.some((path14) => !focus.has(path14)))
18221
18221
  throw new ProjectEvidenceError("PROJECT_MAP_PROTOCOL_INVALID", false);
18222
18222
  analysis.objects = analysis.objects.filter((object2) => focus.has(object2.anchor.path));
18223
18223
  analysis.relations = analysis.relations.filter((relation) => focus.has(relation.anchor.path));
18224
18224
  analysis.notes = analysis.notes.filter((note) => focus.has(note.anchor.path));
18225
18225
  session.accept(analysis, {
18226
18226
  state,
18227
- linked: analysis.parsedFiles.filter((path13) => !focus.has(path13))
18227
+ linked: analysis.parsedFiles.filter((path14) => !focus.has(path14))
18228
18228
  });
18229
18229
  }
18230
18230
  }
@@ -18536,12 +18536,12 @@ var PYTHON_STANDARD_LIBRARY = /* @__PURE__ */ new Set([
18536
18536
  // src/project-map-language-python.ts
18537
18537
  var CONFIGURATION = ["pyrightconfig.json", "pyproject.toml", "setup.cfg"];
18538
18538
  var pythonConfig = /(?:^|\/)(?:pyrightconfig\.json|pyproject\.toml|setup\.cfg)$/u;
18539
- var directoryOf2 = (path13) => path13.slice(0, path13.lastIndexOf("/") + 1);
18539
+ var directoryOf2 = (path14) => path14.slice(0, path14.lastIndexOf("/") + 1);
18540
18540
  var DEFAULT_PYTHON = { major: 3, minor: 13 };
18541
18541
  var PYTHON_MAP_LANGUAGE = Object.freeze({
18542
18542
  id: "pyright-1.1.414-map-v13",
18543
- claims: (path13) => /\.pyi?$/u.test(path13),
18544
- reads: (path13) => pythonConfig.test(path13),
18543
+ claims: (path14) => /\.pyi?$/u.test(path14),
18544
+ reads: (path14) => pythonConfig.test(path14),
18545
18545
  // An absolute import names the standard library or a distribution's top-level package.
18546
18546
  importName: (specifier) => {
18547
18547
  const top = specifier.split(".", 1)[0] ?? specifier;
@@ -18593,21 +18593,21 @@ var PythonMapAnalyzer = class {
18593
18593
  return {
18594
18594
  root: input.configPath ? directoryOf2(input.configPath).replace(/\/$/u, "") : "",
18595
18595
  pythonVersion: pythonVersion(input.files, input.configPath),
18596
- tests: Object.keys(input.files).filter((path13) => this.claims(path13) && mapTestPath(path13))
18596
+ tests: Object.keys(input.files).filter((path14) => this.claims(path14) && mapTestPath(path14))
18597
18597
  };
18598
18598
  }
18599
18599
  async analyze(session, signal) {
18600
18600
  const roots = /* @__PURE__ */ new Map();
18601
- for (const path13 of session.readable.map((entry) => entry.path).filter((path14) => pythonConfig.test(path14))) {
18602
- const directory = directoryOf2(path13);
18601
+ for (const path14 of session.readable.map((entry) => entry.path).filter((path15) => pythonConfig.test(path15))) {
18602
+ const directory = directoryOf2(path14);
18603
18603
  const current = roots.get(directory);
18604
18604
  const rank2 = (file2) => CONFIGURATION.indexOf(file2.slice(directory.length));
18605
- if (current === void 0 || rank2(path13) < rank2(current)) roots.set(directory, path13);
18605
+ if (current === void 0 || rank2(path14) < rank2(current)) roots.set(directory, path14);
18606
18606
  }
18607
- const rootOf = (path13) => {
18607
+ const rootOf = (path14) => {
18608
18608
  let best;
18609
18609
  for (const directory of roots.keys())
18610
- if (path13.startsWith(directory) && (best === void 0 || directory.length > best.length))
18610
+ if (path14.startsWith(directory) && (best === void 0 || directory.length > best.length))
18611
18611
  best = directory;
18612
18612
  return best === void 0 ? "" : roots.get(best);
18613
18613
  };
@@ -18622,11 +18622,11 @@ var PythonMapAnalyzer = class {
18622
18622
  for (const configPath of [...groups.keys()].sort()) {
18623
18623
  if (signal.aborted) throw new ProjectEvidenceError("PROJECT_READ_CANCELLED", true);
18624
18624
  const files = /* @__PURE__ */ Object.create(null);
18625
- for (const path13 of [...groups.get(configPath) ?? [], ...configPath ? [configPath] : []]) {
18626
- const text = session.texts[path13];
18625
+ for (const path14 of [...groups.get(configPath) ?? [], ...configPath ? [configPath] : []]) {
18626
+ const text = session.texts[path14];
18627
18627
  if (text === void 0)
18628
18628
  throw new ProjectEvidenceError("PROJECT_MAP_PROTOCOL_INVALID", false);
18629
- files[path13] = text;
18629
+ files[path14] = text;
18630
18630
  }
18631
18631
  const input = {
18632
18632
  contextRef: digestValue({
@@ -18674,8 +18674,8 @@ var PythonMapAnalyzer = class {
18674
18674
  if (input.files[reference.targetPath] === void 0)
18675
18675
  throw new ProjectEvidenceError("PROJECT_MAP_REFERENCE_TARGET_UNAVAILABLE", false);
18676
18676
  const files = /* @__PURE__ */ Object.create(null);
18677
- for (const [path13, value] of Object.entries(input.files))
18678
- if (this.claims(path13) || pythonConfig.test(path13)) files[path13] = value;
18677
+ for (const [path14, value] of Object.entries(input.files))
18678
+ if (this.claims(path14) || pythonConfig.test(path14)) files[path14] = value;
18679
18679
  const facts = await this.operation(
18680
18680
  {
18681
18681
  ...input,
@@ -18695,8 +18695,8 @@ var PythonMapAnalyzer = class {
18695
18695
  // src/project-map-language-typescript.ts
18696
18696
  var TYPESCRIPT_MAP_LANGUAGE = Object.freeze({
18697
18697
  id: "typescript-7.0.2-map-v17",
18698
- claims: (path13) => /\.[cm]?[jt]sx?$/u.test(path13),
18699
- reads: (path13) => path13.endsWith(".json") || path13 === "pnpm-workspace.yaml",
18698
+ claims: (path14) => /\.[cm]?[jt]sx?$/u.test(path14),
18699
+ reads: (path14) => path14.endsWith(".json") || path14 === "pnpm-workspace.yaml",
18700
18700
  create: () => new TypeScriptMapAnalyzer()
18701
18701
  });
18702
18702
  var CONFIGURATIONS_KEPT = 4;
@@ -18808,9 +18808,9 @@ var TypeScriptMapAnalyzer = class {
18808
18808
  accept(analysis);
18809
18809
  return;
18810
18810
  }
18811
- const required2 = analysis.requiredFiles.map((path13) => {
18812
- const entry = byPath.get(path13);
18813
- if (!entry || Object.hasOwn(texts, path13))
18811
+ const required2 = analysis.requiredFiles.map((path14) => {
18812
+ const entry = byPath.get(path14);
18813
+ if (!entry || Object.hasOwn(texts, path14))
18814
18814
  throw new ProjectEvidenceError("PROJECT_MAP_PROTOCOL_INVALID", false);
18815
18815
  return entry;
18816
18816
  });
@@ -18868,16 +18868,16 @@ var MAP_LANGUAGES = Object.freeze([
18868
18868
  ]);
18869
18869
  var mapAnalyzerSuite = (languages) => languages.map((language) => language.id).sort().join("+");
18870
18870
  var PROJECT_MAP_ANALYZER = mapAnalyzerSuite(MAP_LANGUAGES);
18871
- var mapCodePath = (path13) => MAP_LANGUAGES.some((language) => language.claims(path13));
18872
- var languageOf = (path13) => MAP_LANGUAGES.find((language) => language.claims(path13));
18873
- var mapLanguageOf = (path13) => languageOf(path13)?.id;
18871
+ var mapCodePath = (path14) => MAP_LANGUAGES.some((language) => language.claims(path14));
18872
+ var languageOf = (path14) => MAP_LANGUAGES.find((language) => language.claims(path14));
18873
+ var mapLanguageOf = (path14) => languageOf(path14)?.id;
18874
18874
  var npmPackage = (specifier) => {
18875
18875
  if (specifier.startsWith("node:")) return "node:*";
18876
18876
  const parts = specifier.split("/");
18877
18877
  return specifier.startsWith("@") ? parts.slice(0, 2).join("/") : parts[0] ?? specifier;
18878
18878
  };
18879
18879
  var mapExternalImport = (sourcePath, specifier) => languageOf(sourcePath)?.importName?.(specifier) ?? npmPackage(specifier);
18880
- var mapImportTarget = (path13) => languageOf(path13)?.importTarget?.(path13) ?? path13;
18880
+ var mapImportTarget = (path14) => languageOf(path14)?.importTarget?.(path14) ?? path14;
18881
18881
 
18882
18882
  // src/project-map-view.ts
18883
18883
  var MAP_VIEW_FORMAT = "PROJECT_MAP_VIEW_V1";
@@ -18916,10 +18916,10 @@ var notFound = () => {
18916
18916
  };
18917
18917
  var MAP_KINDS_LEGEND = "kinds f function, c class, m method, p property, v variable, t type, i interface, e enum; numbers are 1-based source lines";
18918
18918
  var MAP_DECLARATION_LEGEND = `@n marks where a relationship occurs and +n counts further sites, which project_find_references lists; a quoted path after the sites is the route the call or value is registered under there: its HTTP methods when the registration names them, then its path joined with the prefixes of the routers it is registered on, as far as the same function or file sets them (a prefix added where a router is mounted or passed in is not included); route "\u2026" after a decorator is the full route the decorator maps, its class's path joined with its own. Static relationships are grouped by the declaration that owns them. Callers are direct calls, uses as a value (stored, passed, returned or selected, then usually invoked through that value) and calls through an interface, type or base member that a declaration implements (dispatched from); dispatches to lists the members that implement an interface, type or base member, which a call through it may reach; trace stops names calls whose target is a function value, a member without a mapped implementation or a computed key, which only source reading can follow; possible callers by name are calls elsewhere, in the same language, of a member with a method's name on a receiver of unknown type (an untyped value, or one an unloaded package produced); they may or may not reach that method.`;
18919
- var within = (path13, directory) => directory === "." || path13.startsWith(`${directory}/`);
18920
- var parentDirectory = (path13) => {
18921
- const slash = path13.lastIndexOf("/");
18922
- return slash < 0 ? "." : path13.slice(0, slash);
18919
+ var within = (path14, directory) => directory === "." || path14.startsWith(`${directory}/`);
18920
+ var parentDirectory = (path14) => {
18921
+ const slash = path14.lastIndexOf("/");
18922
+ return slash < 0 ? "." : path14.slice(0, slash);
18923
18923
  };
18924
18924
  var compareText2 = (left, right) => left < right ? -1 : left > right ? 1 : 0;
18925
18925
  var byCount = ([leftName, left], [rightName, right]) => right - left || compareText2(leftName, rightName);
@@ -18993,7 +18993,7 @@ function pageBlocks(view, head, whole, offset, budget) {
18993
18993
  if (offset === blocks.length) return materialize(0);
18994
18994
  return mapQueryPage(blocks.length - offset, materialize, (page) => page, budget);
18995
18995
  }
18996
- var inModule = (path13, module) => module.direct ? parentDirectory(path13) === module.directory : within(path13, module.directory);
18996
+ var inModule = (path14, module) => module.direct ? parentDirectory(path14) === module.directory : within(path14, module.directory);
18997
18997
  var moduleLabel = (module) => module.direct ? `${module.directory === "." ? "" : `${module.directory}/`}* (files directly here)` : `${module.directory}/`;
18998
18998
  function childModules(module, files) {
18999
18999
  if (module.direct) return [];
@@ -19146,12 +19146,12 @@ function loadMemberCalls(store, version2) {
19146
19146
  FROM project_map_relations
19147
19147
  WHERE version_ref = ? AND to_ref IS NULL AND json_extract(relation_json, '$.kind') = 'CALLS'
19148
19148
  AND json_extract(relation_json, '$.unresolvedReason') IN ('SYMBOL_NOT_RESOLVED', 'SYNTAX_ONLY')`).all(version2)) {
19149
- const path13 = String(row.path);
19149
+ const path14 = String(row.path);
19150
19150
  const target = String(row.target);
19151
19151
  const name = MEMBER_NAME.exec(target)?.[1];
19152
- const language = mapLanguageOf(path13);
19152
+ const language = mapLanguageOf(path14);
19153
19153
  if (!name || !language) continue;
19154
- const call = { from: String(row.from_ref), path: path13, line: Number(row.line), target };
19154
+ const call = { from: String(row.from_ref), path: path14, line: Number(row.line), target };
19155
19155
  const key = memberKey(language, name);
19156
19156
  const known = calls.get(key);
19157
19157
  if (known) known.push(call);
@@ -19206,10 +19206,10 @@ function loadCoverageNotes(store, version2) {
19206
19206
  if (!codes.includes(gap.code)) codes.push(gap.code);
19207
19207
  files.set(gap.path, codes);
19208
19208
  }
19209
- for (const [path13, codes] of files)
19209
+ for (const [path14, codes] of files)
19210
19210
  if (codes.length > 1 && codes.includes("NOT_IN_PARSED_CONTEXT"))
19211
19211
  files.set(
19212
- path13,
19212
+ path14,
19213
19213
  codes.filter((code) => code !== "NOT_IN_PARSED_CONTEXT")
19214
19214
  );
19215
19215
  return { files, limits: [...limits] };
@@ -19244,9 +19244,9 @@ function directoryView(facts, coverage, entries, input, directory, prefixes) {
19244
19244
  const visiblePaths = new Set(visible.map((entry) => entry.path));
19245
19245
  const code = visible.filter((entry) => entry.state === "TEXT" && mapCodePath(entry.path)).map((entry) => entry.path);
19246
19246
  const modules = mapModules(directory, code);
19247
- const moduleOf = (path13) => modules.find((module) => inModule(path13, module));
19248
- const outside = (path13) => {
19249
- const parts = path13.split("/");
19247
+ const moduleOf = (path14) => modules.find((module) => inModule(path14, module));
19248
+ const outside = (path14) => {
19249
+ const parts = path14.split("/");
19250
19250
  return `${parts.slice(0, Math.min(2, parts.length - 1)).join("/") || "."}/ (outside)`;
19251
19251
  };
19252
19252
  const moduleImports = /* @__PURE__ */ new Map();
@@ -19271,8 +19271,8 @@ function directoryView(facts, coverage, entries, input, directory, prefixes) {
19271
19271
  const blocks = [];
19272
19272
  if (modules.length > 1) {
19273
19273
  const sizes = /* @__PURE__ */ new Map();
19274
- for (const path13 of code) {
19275
- const module = moduleOf(path13);
19274
+ for (const path14 of code) {
19275
+ const module = moduleOf(path14);
19276
19276
  if (module) increment(sizes, moduleLabel(module));
19277
19277
  }
19278
19278
  blocks.push(
@@ -19301,18 +19301,18 @@ function directoryView(facts, coverage, entries, input, directory, prefixes) {
19301
19301
  )}${packages.length > shown.length ? `, +${packages.length - shown.length} more` : ""}`
19302
19302
  );
19303
19303
  }
19304
- const lineCount = (path13) => {
19305
- const file2 = facts.files.get(path13);
19306
- const gaps = coverage.files.get(path13) ?? [];
19304
+ const lineCount = (path14) => {
19305
+ const file2 = facts.files.get(path14);
19306
+ const gaps = coverage.files.get(path14) ?? [];
19307
19307
  if (file2?.parsed === false) return `[not parsed${gaps.length ? `: ${gaps.join("; ")}` : ""}]`;
19308
19308
  return `${file2 ? `${file2.lines}L` : "?L"}${gaps.length ? ` [${gaps.join("; ")}]` : ""}`;
19309
19309
  };
19310
19310
  const codeDirectories = /* @__PURE__ */ new Set();
19311
- for (const path13 of code)
19312
- for (let parent = parentDirectory(path13); parent !== "." && !codeDirectories.has(parent); parent = parentDirectory(parent))
19311
+ for (const path14 of code)
19312
+ for (let parent = parentDirectory(path14); parent !== "." && !codeDirectories.has(parent); parent = parentDirectory(parent))
19313
19313
  codeDirectories.add(parent);
19314
- const groupOf = (path13) => {
19315
- let group = parentDirectory(path13);
19314
+ const groupOf = (path14) => {
19315
+ let group = parentDirectory(path14);
19316
19316
  for (let parent = group; parent !== "." && parent !== directory && !codeDirectories.has(parent); parent = parentDirectory(parent))
19317
19317
  group = parent;
19318
19318
  return group;
@@ -19344,11 +19344,11 @@ function directoryView(facts, coverage, entries, input, directory, prefixes) {
19344
19344
  ]);
19345
19345
  }
19346
19346
  const detailed = [
19347
- ...code.map((path13) => {
19348
- const declarations = (facts.exported.get(path13) ?? []).map(({ text: text2 }) => text2);
19347
+ ...code.map((path14) => {
19348
+ const declarations = (facts.exported.get(path14) ?? []).map(({ text: text2 }) => text2);
19349
19349
  return [
19350
- path13,
19351
- `${path13} ${lineCount(path13)}${declarations.length ? `: ${declarations.join(", ")}` : ""}`
19350
+ path14,
19351
+ `${path14} ${lineCount(path14)}${declarations.length ? `: ${declarations.join(", ")}` : ""}`
19352
19352
  ];
19353
19353
  }),
19354
19354
  ...listedOther.map((entry) => [
@@ -19359,7 +19359,7 @@ function directoryView(facts, coverage, entries, input, directory, prefixes) {
19359
19359
  ];
19360
19360
  const directories = /* @__PURE__ */ new Map();
19361
19361
  for (const entry of [
19362
- ...code.map((path13) => ({ path: path13, item: lineCount(path13) })),
19362
+ ...code.map((path14) => ({ path: path14, item: lineCount(path14) })),
19363
19363
  ...listedOther.map((entry2) => ({
19364
19364
  path: entry2.path,
19365
19365
  item: entry2.state === "TEXT" ? "" : `(${entry2.state})`
@@ -19387,10 +19387,10 @@ function directoryView(facts, coverage, entries, input, directory, prefixes) {
19387
19387
  );
19388
19388
  const text = visible.filter((entry) => entry.state === "TEXT").length;
19389
19389
  const resolution = /* @__PURE__ */ new Map();
19390
- for (const path13 of code) {
19391
- const counts = facts.calls.get(path13);
19390
+ for (const path14 of code) {
19391
+ const counts = facts.calls.get(path14);
19392
19392
  if (!counts) continue;
19393
- const language = facts.files.get(path13)?.language ?? "unknown";
19393
+ const language = facts.files.get(path14)?.language ?? "unknown";
19394
19394
  const total = resolution.get(language) ?? { resolved: 0, unresolved: 0, external: 0 };
19395
19395
  total.resolved += counts.resolved;
19396
19396
  total.unresolved += counts.unresolved;
@@ -19448,8 +19448,8 @@ var DeclarationGroups = class {
19448
19448
  prefixes;
19449
19449
  showTests;
19450
19450
  memberCalls;
19451
- visible(path13) {
19452
- return mapPathAllowed(path13, this.prefixes) && (this.showTests || !mapTestPath(path13));
19451
+ visible(path14) {
19452
+ return mapPathAllowed(path14, this.prefixes) && (this.showTests || !mapTestPath(path14));
19453
19453
  }
19454
19454
  entry(object2, imported = false) {
19455
19455
  if (mapIsModule(object2)) return imported ? "(file)" : "(module scope)";
@@ -19493,11 +19493,11 @@ var DeclarationGroups = class {
19493
19493
  value.lines.push(line);
19494
19494
  aggregates.set(key, value);
19495
19495
  };
19496
- const dispatch = (arrow, label, ref2, path13, line) => {
19496
+ const dispatch = (arrow, label, ref2, path14, line) => {
19497
19497
  const other = graph.object(graph.owner(ref2));
19498
19498
  if (owned.has(other.id)) return;
19499
- if (!this.visible(path13)) {
19500
- if (mapPathAllowed(path13, this.prefixes)) omittedTests++;
19499
+ if (!this.visible(path14)) {
19500
+ if (mapPathAllowed(path14, this.prefixes)) omittedTests++;
19501
19501
  return;
19502
19502
  }
19503
19503
  add(arrow, label, other, line);
@@ -19654,7 +19654,7 @@ var DeclarationGroups = class {
19654
19654
  else files2.set(call.path, [item]);
19655
19655
  }
19656
19656
  lines.push(
19657
- ` \u2190 possible callers by name: ${[...files2].map(([path13, items]) => `${path13}: ${items.join(", ")}`).join("; ")}${inTests}`
19657
+ ` \u2190 possible callers by name: ${[...files2].map(([path14, items]) => `${path14}: ${items.join(", ")}`).join("; ")}${inTests}`
19658
19658
  );
19659
19659
  } else if (possibleInTests)
19660
19660
  lines.push(` \u2190 possible callers by name: ${possibleInTests} in test files (includeTests)`);
@@ -19690,14 +19690,14 @@ var DeclarationGroups = class {
19690
19690
  return { lines, neighbors: [...new Set(neighbors)] };
19691
19691
  }
19692
19692
  };
19693
- function fileView(store, coverage, graph, input, path13, prefixes) {
19694
- const entry = store.getEntry(input.version, path13);
19695
- if (!entry || !mapPathAllowed(path13, prefixes)) return notFound();
19696
- const showTests = input.includeTests === true || mapTestPath(path13);
19697
- const module = mapCodePath(path13) ? graph.objectsAt(path13).find((object2) => mapIsModule(object2)) : void 0;
19698
- const gaps = coverage.files.get(path13) ?? [];
19693
+ function fileView(store, coverage, graph, input, path14, prefixes) {
19694
+ const entry = store.getEntry(input.version, path14);
19695
+ if (!entry || !mapPathAllowed(path14, prefixes)) return notFound();
19696
+ const showTests = input.includeTests === true || mapTestPath(path14);
19697
+ const module = mapCodePath(path14) ? graph.objectsAt(path14).find((object2) => mapIsModule(object2)) : void 0;
19698
+ const gaps = coverage.files.get(path14) ?? [];
19699
19699
  const head = [
19700
- `PROJECT MAP \xB7 FILE ${path13} \xB7 ${entry.state !== "TEXT" ? entry.state : module ? module.parsing === "NOT_PARSED" ? `not parsed${gaps.length ? ` (${gaps.join("; ")})` : ""}; read it as text` : `${module.anchor.endLine} lines${gaps.length ? ` \xB7 ${gaps.join("; ")}` : ""}` : `${entry.byteLength} bytes, not analyzed; read it as text`}`
19700
+ `PROJECT MAP \xB7 FILE ${path14} \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`}`
19701
19701
  ];
19702
19702
  if (!module || entry.state !== "TEXT")
19703
19703
  return pageBlocks("FILE", head, [], input.offset ?? 0, input.outputBudget);
@@ -19717,7 +19717,7 @@ function fileView(store, coverage, graph, input, path13, prefixes) {
19717
19717
  tags.set(relation.from, list);
19718
19718
  }
19719
19719
  const describe3 = (object2) => [
19720
- `${object2.name} ${mapDeclarationLabel(object2)}${object2.anchor.path === path13 ? "" : ` (${object2.anchor.path})`}`,
19720
+ `${object2.name} ${mapDeclarationLabel(object2)}${object2.anchor.path === path14 ? "" : ` (${object2.anchor.path})`}`,
19721
19721
  ...tags.get(object2.id) ?? []
19722
19722
  ].join(" ");
19723
19723
  const declarations = [];
@@ -19732,11 +19732,11 @@ function fileView(store, coverage, graph, input, path13, prefixes) {
19732
19732
  );
19733
19733
  }
19734
19734
  const elsewhere = /* @__PURE__ */ new Map();
19735
- for (const object2 of graph.objectsAt(path13)) {
19735
+ for (const object2 of graph.objectsAt(path14)) {
19736
19736
  const parent = mapIsModule(object2) ? void 0 : graph.parent(object2.id);
19737
19737
  if (parent === void 0 || !graph.isAddressable(object2)) continue;
19738
19738
  const container = graph.object(parent);
19739
- if (mapIsModule(container) || container.anchor.path === path13) continue;
19739
+ if (mapIsModule(container) || container.anchor.path === path14) continue;
19740
19740
  const into = elsewhere.get(parent);
19741
19741
  if (into) into.push(object2);
19742
19742
  else elsewhere.set(parent, [object2]);
@@ -19750,7 +19750,7 @@ function fileView(store, coverage, graph, input, path13, prefixes) {
19750
19750
  if (declarations.length) blocks.push(["DECLARATIONS (* exported)", ...declarations].join("\n"));
19751
19751
  const imports = /* @__PURE__ */ new Set();
19752
19752
  const external = /* @__PURE__ */ new Set();
19753
- const fileObjects = graph.objectsAt(path13).map((object2) => object2.id);
19753
+ const fileObjects = graph.objectsAt(path14).map((object2) => object2.id);
19754
19754
  for (const relation of graph.relationsFrom(fileObjects)) {
19755
19755
  if (!IMPORT_KINDS.has(relation.kind)) continue;
19756
19756
  if (relation.to === void 0) external.add(relation.target);
@@ -19761,8 +19761,8 @@ function fileView(store, coverage, graph, input, path13, prefixes) {
19761
19761
  }
19762
19762
  const importers = /* @__PURE__ */ new Set();
19763
19763
  const testImporters = /* @__PURE__ */ new Set();
19764
- const imported = mapImportTarget(path13);
19765
- const packageModules = imported === path13 ? [module.id] : store.listEntries(input.version).filter((entry2) => mapImportTarget(entry2.path) === imported).flatMap((entry2) => graph.objectsAt(entry2.path).filter((object2) => mapIsModule(object2))).map((object2) => object2.id);
19764
+ const imported = mapImportTarget(path14);
19765
+ const packageModules = imported === path14 ? [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);
19766
19766
  for (const relation of graph.relationsTo(packageModules)) {
19767
19767
  if (!IMPORT_KINDS.has(relation.kind)) continue;
19768
19768
  const source = relation.anchor.path;
@@ -19790,16 +19790,16 @@ function fileView(store, coverage, graph, input, path13, prefixes) {
19790
19790
  if (scope.length) blocks.push(["MODULE SCOPE (top-level statements)", ...scope].join("\n"));
19791
19791
  return pageBlocks("FILE", head, blocks, input.offset ?? 0, input.outputBudget);
19792
19792
  }
19793
- function declarationView(graph, input, path13, prefixes, memberCalls) {
19793
+ function declarationView(graph, input, path14, prefixes, memberCalls) {
19794
19794
  const requested = input.depth ?? 1;
19795
19795
  if (!Number.isSafeInteger(requested) || requested < 1 || requested > MAP_VIEW_LIMITS.directedDepth)
19796
19796
  return invalid2();
19797
19797
  const both = (input.direction ?? "BOTH") === "BOTH";
19798
19798
  const depth = both ? Math.min(requested, MAP_VIEW_LIMITS.bothDepth) : requested;
19799
19799
  const { name, line } = input;
19800
- const selected = mapSelectDeclarations(graph, path13, name, line);
19800
+ const selected = mapSelectDeclarations(graph, path14, name, line);
19801
19801
  if (!selected.length) return notFound();
19802
- const showTests = input.includeTests === true || mapTestPath(path13);
19802
+ const showTests = input.includeTests === true || mapTestPath(path14);
19803
19803
  const groups = new DeclarationGroups(graph, input, prefixes, showTests, memberCalls);
19804
19804
  const blocks = [];
19805
19805
  const seen = /* @__PURE__ */ new Set();
@@ -19847,7 +19847,7 @@ function declarationView(graph, input, path13, prefixes, memberCalls) {
19847
19847
  );
19848
19848
  }
19849
19849
  const head = [
19850
- `PROJECT MAP \xB7 DECLARATION ${path13}${name === void 0 ? "" : ` ${name}`}${line === void 0 ? "" : ` line ${line}`} \xB7 direction ${input.direction ?? "BOTH"} \xB7 depth ${depth}${depth < requested ? ` (BOTH is limited to ${MAP_VIEW_LIMITS.bothDepth})` : ""}${prefixes.includes(".") ? "" : " \xB7 limited to authorized paths"}`,
19850
+ `PROJECT MAP \xB7 DECLARATION ${path14}${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"}`,
19851
19851
  ...truncated ? [`Expansion stopped at ${MAP_VIEW_LIMITS.declarations} declarations.`] : [],
19852
19852
  ...(input.direction ?? "BOTH") === "OUTGOING" ? [] : [callerCoverage(input.textSearch ?? DEFAULT_TEXT_SEARCH)]
19853
19853
  ];
@@ -19974,10 +19974,10 @@ var ProjectMapQuery = class {
19974
19974
  view(input, signal) {
19975
19975
  this.requireReadableMap(input.version, signal);
19976
19976
  const { offset, prefixes } = admission(input);
19977
- const path13 = normalizeProjectEvidencePath(input.path, true) || ".";
19977
+ const path14 = normalizeProjectEvidencePath(input.path, true) || ".";
19978
19978
  const view = mapView(
19979
19979
  this.store,
19980
- { ...input, path: path13, offset, allowedPathPrefixes: prefixes },
19980
+ { ...input, path: path14, offset, allowedPathPrefixes: prefixes },
19981
19981
  this.views
19982
19982
  );
19983
19983
  if (signal.aborted) throw new ProjectEvidenceError("PROJECT_READ_CANCELLED", true);
@@ -20882,7 +20882,7 @@ var CodeIndexStore = class {
20882
20882
  const staged = this.stageUnits(buildRef, paths, linked);
20883
20883
  const reused = linked ? this.database.prepare(`SELECT path, unit_ref FROM project_map_version_units
20884
20884
  WHERE version_ref = ? AND path IN (SELECT value FROM json_each(?))`).all(linked.version, JSON.stringify([...linked.paths])).map((row) => ({ path: String(row.path), unit: String(row.unit_ref) })) : [];
20885
- if (reused.length !== (linked?.paths.size ?? 0) || reused.some(({ path: path13 }) => !paths.has(path13)) || staged.some(({ path: path13 }) => linked?.paths.has(path13)))
20885
+ if (reused.length !== (linked?.paths.size ?? 0) || reused.some(({ path: path14 }) => !paths.has(path14)) || staged.some(({ path: path14 }) => linked?.paths.has(path14)))
20886
20886
  throw new MapReplayConflict();
20887
20887
  const units = [...staged, ...reused].sort(
20888
20888
  (left, right) => left.path < right.path ? -1 : left.path > right.path ? 1 : 0
@@ -20933,7 +20933,7 @@ var CodeIndexStore = class {
20933
20933
  const member = this.database.prepare(
20934
20934
  "INSERT INTO project_map_version_units VALUES (?, ?, ?)"
20935
20935
  );
20936
- for (const { path: path13, unit } of reused) member.run(version2.version, path13, unit);
20936
+ for (const { path: path14, unit } of reused) member.run(version2.version, path14, unit);
20937
20937
  this.database.prepare("INSERT INTO project_map_coverage VALUES (?, ?)").run(version2.version, canonicalJson(coverage));
20938
20938
  }
20939
20939
  this.database.exec("COMMIT");
@@ -20997,7 +20997,7 @@ var CodeIndexStore = class {
20997
20997
  corrupt2();
20998
20998
  }
20999
20999
  if (linked) {
21000
- const unlinked = database.prepare("SELECT path FROM project_map_version_units WHERE version_ref = ?").all(linked.version).map((row) => String(row.path)).filter((path13) => !linked.paths.has(path13));
21000
+ const unlinked = database.prepare("SELECT path FROM project_map_version_units WHERE version_ref = ?").all(linked.version).map((row) => String(row.path)).filter((path14) => !linked.paths.has(path14));
21001
21001
  if (database.prepare(`SELECT 1 FROM project_map_objects gone
21002
21002
  WHERE gone.version_ref = ? AND gone.path IN (SELECT value FROM json_each(?))
21003
21003
  AND gone.entity_ref NOT IN (SELECT entity_ref FROM project_map_publish_objects)
@@ -21022,17 +21022,17 @@ var CodeIndexStore = class {
21022
21022
  const units = [];
21023
21023
  for (const row of database.prepare(`SELECT path FROM project_map_publish_objects
21024
21024
  UNION SELECT path FROM project_map_publish_relations ORDER BY path`).all()) {
21025
- const path13 = String(row.path);
21026
- const hash2 = createHash3("sha256").update(path13).update("\0");
21025
+ const path14 = String(row.path);
21026
+ const hash2 = createHash3("sha256").update(path14).update("\0");
21027
21027
  for (const [mark, statement] of [
21028
21028
  ["object", objects2],
21029
21029
  ["relation", relations],
21030
21030
  ["note", pathNotes]
21031
21031
  ])
21032
- for (const fact of statement.all(path13))
21032
+ for (const fact of statement.all(path14))
21033
21033
  for (const value of Object.values(fact))
21034
21034
  hash2.update(mark).update("\0").update(String(value)).update("\0");
21035
- units.push({ path: path13, unit: hash2.digest("hex") });
21035
+ units.push({ path: path14, unit: hash2.digest("hex") });
21036
21036
  }
21037
21037
  return units;
21038
21038
  }
@@ -21050,13 +21050,13 @@ var CodeIndexStore = class {
21050
21050
  "INSERT INTO project_map_unit_notes SELECT ?, * FROM project_map_publish_notes WHERE path = ?"
21051
21051
  );
21052
21052
  const member = database.prepare("INSERT INTO project_map_version_units VALUES (?, ?, ?)");
21053
- for (const { path: path13, unit } of units) {
21054
- if (insertUnit.run(unit, path13).changes) {
21055
- unitObjects.run(unit, path13);
21056
- unitRelations.run(unit, path13);
21057
- unitNotes.run(unit, path13);
21053
+ for (const { path: path14, unit } of units) {
21054
+ if (insertUnit.run(unit, path14).changes) {
21055
+ unitObjects.run(unit, path14);
21056
+ unitRelations.run(unit, path14);
21057
+ unitNotes.run(unit, path14);
21058
21058
  }
21059
- member.run(version2, path13, unit);
21059
+ member.run(version2, path14, unit);
21060
21060
  }
21061
21061
  }
21062
21062
  /**
@@ -21301,21 +21301,21 @@ var contextFiles = (context) => [
21301
21301
  function replayableContexts(parent, digests) {
21302
21302
  const sharing = /* @__PURE__ */ new Map();
21303
21303
  for (const [ref, { context }] of parent.contexts)
21304
- for (const path13 of contextFiles(context)) {
21305
- const refs = sharing.get(path13) ?? /* @__PURE__ */ new Set();
21304
+ for (const path14 of contextFiles(context)) {
21305
+ const refs = sharing.get(path14) ?? /* @__PURE__ */ new Set();
21306
21306
  refs.add(ref);
21307
- sharing.set(path13, refs);
21307
+ sharing.set(path14, refs);
21308
21308
  }
21309
21309
  const unchanged = /* @__PURE__ */ new Set();
21310
21310
  for (const [ref, { context }] of parent.contexts)
21311
21311
  if (contextFiles(context).every(
21312
- (path13) => digests.get(path13) !== void 0 && digests.get(path13) === parent.entries.get(path13)
21312
+ (path14) => digests.get(path14) !== void 0 && digests.get(path14) === parent.entries.get(path14)
21313
21313
  ))
21314
21314
  unchanged.add(ref);
21315
21315
  const replayable = /* @__PURE__ */ new Set();
21316
21316
  for (const [ref, { context }] of parent.contexts)
21317
21317
  if (unchanged.has(ref) && contextFiles(context).every(
21318
- (path13) => [...sharing.get(path13) ?? []].every((other) => unchanged.has(other))
21318
+ (path14) => [...sharing.get(path14) ?? []].every((other) => unchanged.has(other))
21319
21319
  ))
21320
21320
  replayable.add(ref);
21321
21321
  return { replayable, sharing };
@@ -21348,8 +21348,8 @@ var ProjectMapAnalyzer = class {
21348
21348
  languages;
21349
21349
  observe;
21350
21350
  id;
21351
- claims(path13) {
21352
- return this.languages.some((language) => language.claims(path13));
21351
+ claims(path14) {
21352
+ return this.languages.some((language) => language.claims(path14));
21353
21353
  }
21354
21354
  references(input, reference, signal) {
21355
21355
  const language = this.languages.find((language2) => language2.claims(reference.targetPath));
@@ -21389,7 +21389,7 @@ var ProjectMapAnalyzer = class {
21389
21389
  const reuse = (contextRef2, request, files2) => {
21390
21390
  const digest = digestValue({
21391
21391
  request,
21392
- files: files2.map((path13) => [path13, digests.get(path13) ?? null])
21392
+ files: files2.map((path14) => [path14, digests.get(path14) ?? null])
21393
21393
  });
21394
21394
  requests.set(contextRef2, digest);
21395
21395
  if (!parent || !replayable.has(contextRef2)) return void 0;
@@ -21429,7 +21429,7 @@ var ProjectMapAnalyzer = class {
21429
21429
  const ref = analysis.contexts[0]?.ref ?? "";
21430
21430
  if (options?.linked?.length) {
21431
21431
  if (!parent || analysis.contexts.length !== 1) return invalidParent();
21432
- for (const path13 of options.linked) linked.add(path13);
21432
+ for (const path14 of options.linked) linked.add(path14);
21433
21433
  this.observe?.({
21434
21434
  operation: "LINK",
21435
21435
  phase: "FINISHED",
@@ -21456,7 +21456,7 @@ var ProjectMapAnalyzer = class {
21456
21456
  });
21457
21457
  for (const file2 of analysis.parsedFiles) parsed.add(file2);
21458
21458
  const staged = factPaths(analysis);
21459
- for (const path13 of staged) stagedPaths.add(path13);
21459
+ for (const path14 of staged) stagedPaths.add(path14);
21460
21460
  for (const context of analysis.contexts) {
21461
21461
  for (const file2 of context.configurationFiles) configurationInputs.add(file2);
21462
21462
  if (!replayed.has(context.ref))
@@ -21485,7 +21485,7 @@ var ProjectMapAnalyzer = class {
21485
21485
  accept,
21486
21486
  reuse,
21487
21487
  previous,
21488
- configuration: (path13) => configurationInputs.add(path13),
21488
+ configuration: (path14) => configurationInputs.add(path14),
21489
21489
  observe: this.observe
21490
21490
  },
21491
21491
  signal
@@ -21522,12 +21522,12 @@ var ProjectMapAnalyzer = class {
21522
21522
  if (files.objects.length) accept(files);
21523
21523
  if (parent && (replayed.size || linked.size)) {
21524
21524
  for (const ref of replayed.keys())
21525
- for (const path13 of contextFiles(parent.contexts.get(ref)?.context ?? invalidParent()))
21526
- if (analyzedFiles.has(path13) || [...sharing.get(path13) ?? []].some((other) => !replayed.has(other)))
21525
+ for (const path14 of contextFiles(parent.contexts.get(ref)?.context ?? invalidParent()))
21526
+ if (analyzedFiles.has(path14) || [...sharing.get(path14) ?? []].some((other) => !replayed.has(other)))
21527
21527
  throw new MapReplayConflict();
21528
- for (const paths of replayed.values()) for (const path13 of paths) linked.add(path13);
21529
- for (const path13 of linked)
21530
- if (analyzedFiles.has(path13) || stagedPaths.has(path13)) throw new MapReplayConflict();
21528
+ for (const paths of replayed.values()) for (const path14 of paths) linked.add(path14);
21529
+ for (const path14 of linked)
21530
+ if (analyzedFiles.has(path14) || stagedPaths.has(path14)) throw new MapReplayConflict();
21531
21531
  parent.link([...linked]);
21532
21532
  }
21533
21533
  result.parsedFiles = [...parsed].sort();
@@ -21822,8 +21822,8 @@ var CodeIndex = class {
21822
21822
  for (const entry of this.store.listEntries(candidate))
21823
21823
  if (entry.contentDigest) entries2.set(entry.path, entry.contentDigest);
21824
21824
  let changed = 0;
21825
- for (const [path13, digest] of digests) if (entries2.get(path13) !== digest) changed++;
21826
- for (const path13 of entries2.keys()) if (!digests.has(path13)) changed++;
21825
+ for (const [path14, digest] of digests) if (entries2.get(path14) !== digest) changed++;
21826
+ for (const path14 of entries2.keys()) if (!digests.has(path14)) changed++;
21827
21827
  if (!best || changed < best.changed) best = { version: candidate, entries: entries2, changed };
21828
21828
  }
21829
21829
  if (!best) return void 0;
@@ -21998,16 +21998,16 @@ var LITERAL = /(["'`])((?:\\.|(?!\1)[^\\])*)\1/gu;
21998
21998
  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;
21999
21999
  var LIMIT = Object.freeze({ routes: 40, clients: 5 });
22000
22000
  var ROUTE = /^(?:[A-Z]+(?:\|[A-Z]+)* +)?\/\S*$/u;
22001
- var segments = (path13) => path13.split("/").filter(Boolean).map((text) => ({ text, param: PARAM.test(text) || /[{}$<>%]/u.test(text) }));
22001
+ var segments = (path14) => path14.split("/").filter(Boolean).map((text) => ({ text, param: PARAM.test(text) || /[{}$<>%]/u.test(text) }));
22002
22002
  var routeSegments = (label) => segments(label.slice(label.indexOf("/")));
22003
22003
  function requestedPath(literal3, joined) {
22004
22004
  const match = /^(?:https?:\/\/[^/\s]+|(?:\$\{[^}]*\})+|@\{|redirect:|forward:)?(\/[^\s?#()"'`,;|]*)/u.exec(
22005
22005
  literal3
22006
22006
  ) ?? void 0;
22007
- const path13 = match?.[1];
22008
- if (!path13 || path13.startsWith("//") || path13.length < 3) return void 0;
22009
- const parts = segments(path13);
22010
- if (joined && path13.endsWith("/")) parts.push({ text: "*", param: true });
22007
+ const path14 = match?.[1];
22008
+ if (!path14 || path14.startsWith("//") || path14.length < 3) return void 0;
22009
+ const parts = segments(path14);
22010
+ if (joined && path14.endsWith("/")) parts.push({ text: "*", param: true });
22011
22011
  return parts;
22012
22012
  }
22013
22013
  var same = (route, requested) => route.param || !requested.param && route.text === requested.text;
@@ -22312,8 +22312,8 @@ async function readMapChanges(project, base, signal) {
22312
22312
  baseText: (await git.run(["show", `${commit}:${file2.basePath}`], gitOptions(project, signal))).stdout.toString("utf8")
22313
22313
  };
22314
22314
  const untracked = (await git.run(["ls-files", "--others", "--exclude-standard", "-z"], gitOptions(project, signal))).stdout.toString("utf8").split("\0").filter(Boolean);
22315
- for (const path13 of untracked)
22316
- files.push({ path: path13, status: "ADDED", lines: [EVERYTHING], baseLines: [], binary: false });
22315
+ for (const path14 of untracked)
22316
+ files.push({ path: path14, status: "ADDED", lines: [EVERYTHING], baseLines: [], binary: false });
22317
22317
  const stranded = await strandedNames(
22318
22318
  project,
22319
22319
  diff,
@@ -22391,7 +22391,7 @@ var NON_CODE = [
22391
22391
  [/(?:^|\/)\.env[^/]*$|\.(?:ya?ml|toml|ini|properties|conf|cfg)$/iu, "configuration"],
22392
22392
  [/\.(?:html?|jinja2?|j2|hbs|ejs|tmpl|tpl|gohtml|vue|svelte)$/iu, "template"]
22393
22393
  ];
22394
- var nonCodeKind = (path13) => NON_CODE.find(([pattern]) => pattern.test(path13))?.[1];
22394
+ var nonCodeKind = (path14) => NON_CODE.find(([pattern]) => pattern.test(path14))?.[1];
22395
22395
  var LIMITS = Object.freeze({ depth: 8, declarations: 800, changed: 200, chain: 3, byName: 40 });
22396
22396
  var CALLER_KINDS = /* @__PURE__ */ new Set(["CALLS", "REFERENCES"]);
22397
22397
  var IMPORT_KINDS2 = /* @__PURE__ */ new Set(["IMPORTS", "TEST_IMPORTS"]);
@@ -22586,12 +22586,12 @@ var Tracer = class {
22586
22586
  this.areas.set(area, known);
22587
22587
  }
22588
22588
  /** A related test file; the closest relation (lowest rank) explains it. */
22589
- test(path13, name, why, rank2) {
22590
- if (!mapRunnableTest(path13)) return;
22591
- const known = this.tests.get(path13) ?? { names: /* @__PURE__ */ new Set(), why, rank: rank2 };
22589
+ test(path14, name, why, rank2) {
22590
+ if (!mapRunnableTest(path14)) return;
22591
+ const known = this.tests.get(path14) ?? { names: /* @__PURE__ */ new Set(), why, rank: rank2 };
22592
22592
  if (rank2 < known.rank) Object.assign(known, { why, rank: rank2 });
22593
22593
  if (name && !name.startsWith("<")) known.names.add(name);
22594
- this.tests.set(path13, known);
22594
+ this.tests.set(path14, known);
22595
22595
  }
22596
22596
  };
22597
22597
  var mapRunnableTest = (file2) => /_test\.(?:go|py)$|(?:^|\/)test_[^/]*\.py$|\.(?:test|spec)\.[cm]?[jt]sx?$|(?:Test|Tests|IT)\.(?:java|kt)$/u.test(
@@ -22604,7 +22604,7 @@ function mapChangeImpact(store, working, base, changes, project) {
22604
22604
  const changed = [];
22605
22605
  const unclear = [];
22606
22606
  const removed = [];
22607
- const declarations = (g, path13) => g.objectsAt(path13).filter((object2) => !mapIsModule(object2) && g.isAddressable(object2));
22607
+ const declarations = (g, path14) => g.objectsAt(path14).filter((object2) => !mapIsModule(object2) && g.isAddressable(object2));
22608
22608
  let changedCount = 0;
22609
22609
  const starts = [];
22610
22610
  for (const file2 of changes.files) {
@@ -22701,18 +22701,18 @@ function mapChangeImpact(store, working, base, changes, project) {
22701
22701
  beforeTracer.trace(gone);
22702
22702
  for (const entry of beforeTracer.entries.values())
22703
22703
  if (!tracer.entries.has(entry.label)) tracer.entries.set(entry.label, entry);
22704
- for (const [path13, test] of beforeTracer.tests) {
22705
- const known = tracer.tests.get(path13);
22704
+ for (const [path14, test] of beforeTracer.tests) {
22705
+ const known = tracer.tests.get(path14);
22706
22706
  if (known) for (const name of test.names) known.names.add(name);
22707
- else tracer.tests.set(path13, test);
22707
+ else tracer.tests.set(path14, test);
22708
22708
  }
22709
22709
  for (const [area, known] of beforeTracer.areas) {
22710
22710
  const now = tracer.areas.get(area);
22711
22711
  if (!now) tracer.areas.set(area, known);
22712
22712
  else {
22713
22713
  for (const name of known.through) now.through.add(name);
22714
- for (const [path13, names] of known.tests)
22715
- now.tests.set(path13, /* @__PURE__ */ new Set([...now.tests.get(path13) ?? [], ...names]));
22714
+ for (const [path14, names] of known.tests)
22715
+ now.tests.set(path14, /* @__PURE__ */ new Set([...now.tests.get(path14) ?? [], ...names]));
22716
22716
  }
22717
22717
  }
22718
22718
  unclear.push(...beforeTracer.unclear.filter((line) => !line.includes("has no callers")));
@@ -22726,8 +22726,8 @@ function mapChangeImpact(store, working, base, changes, project) {
22726
22726
  entries: [...tracer.entries.values()].sort(
22727
22727
  (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)
22728
22728
  ),
22729
- tests: [...tracer.tests].map(([path13, test]) => ({
22730
- path: path13,
22729
+ tests: [...tracer.tests].map(([path14, test]) => ({
22730
+ path: path14,
22731
22731
  names: [...test.names].sort(),
22732
22732
  why: test.why,
22733
22733
  rank: test.rank
@@ -22737,7 +22737,7 @@ function mapChangeImpact(store, working, base, changes, project) {
22737
22737
  areas: [...tracer.areas].map(([area, known]) => ({
22738
22738
  area,
22739
22739
  through: [...known.through].sort(),
22740
- tests: [...known.tests].map(([path13, names]) => ({ path: path13, names: [...names].sort() })).sort((left, right) => right.names.length - left.names.length)
22740
+ tests: [...known.tests].map(([path14, names]) => ({ path: path14, names: [...names].sort() })).sort((left, right) => right.names.length - left.names.length)
22741
22741
  })).sort((left, right) => right.tests.length - left.tests.length),
22742
22742
  unclear: [.../* @__PURE__ */ new Set([...unclear, ...tracer.unclear])],
22743
22743
  removedRoutes,
@@ -22855,9 +22855,9 @@ function routeTests(project, store, version2, entries, tracer) {
22855
22855
  }
22856
22856
  }
22857
22857
  }
22858
- function sameDirectoryTests(store, version2, path13, tracer) {
22859
- const slash = path13.lastIndexOf("/");
22860
- const directory = slash < 0 ? "" : path13.slice(0, slash + 1);
22858
+ function sameDirectoryTests(store, version2, path14, tracer) {
22859
+ const slash = path14.lastIndexOf("/");
22860
+ const directory = slash < 0 ? "" : path14.slice(0, slash + 1);
22861
22861
  for (const row of store.database.prepare(
22862
22862
  "SELECT DISTINCT path FROM project_map_objects WHERE version_ref = ? AND path LIKE ? ESCAPE '\\'"
22863
22863
  ).all(version2, `${directory.replace(/[\\%_]/gu, (c) => `\\${c}`)}%`)) {
@@ -22886,9 +22886,9 @@ var LIST = Object.freeze({
22886
22886
  areaNames: 3,
22887
22887
  through: 2
22888
22888
  });
22889
- function routesIn(graph, path13) {
22889
+ function routesIn(graph, path14) {
22890
22890
  const routes = /* @__PURE__ */ new Set();
22891
- for (const relation of graph.relationsFrom(graph.objectsAt(path13).map((object2) => object2.id))) {
22891
+ for (const relation of graph.relationsFrom(graph.objectsAt(path14).map((object2) => object2.id))) {
22892
22892
  const route = relation.kind === "DECORATED_BY" ? relation.route ?? relation.argument : relation.argument;
22893
22893
  if (route && ROUTE2.test(route)) routes.add(route);
22894
22894
  }
@@ -23100,12 +23100,12 @@ var LayerMap = class _LayerMap {
23100
23100
  refreshing;
23101
23101
  static async open(options) {
23102
23102
  const project = await realpath2(options.project);
23103
- const stat2 = await lstat2(project, { bigint: true });
23104
- if (!stat2.isDirectory()) throw new ProjectEvidenceError("PROJECT_PATH_INVALID", false);
23103
+ const stat3 = await lstat2(project, { bigint: true });
23104
+ if (!stat3.isDirectory()) throw new ProjectEvidenceError("PROJECT_PATH_INVALID", false);
23105
23105
  const source = {
23106
23106
  kind: "WORKTREE",
23107
23107
  projectRef: `layermap:${createHash4("sha256").update(project).digest("hex").slice(0, 24)}`,
23108
- directory: { canonicalPath: project, device: String(stat2.dev), inode: String(stat2.ino) }
23108
+ directory: { canonicalPath: project, device: String(stat3.dev), inode: String(stat3.ino) }
23109
23109
  };
23110
23110
  const store = new CodeIndexStore(
23111
23111
  openMapDatabase(
@@ -23364,6 +23364,11 @@ async function pruneCache(cache, project, now = Date.now()) {
23364
23364
  import { createInterface } from "node:readline";
23365
23365
  import { setTimeout as delay } from "node:timers/promises";
23366
23366
 
23367
+ // src/agent/projects.ts
23368
+ import { existsSync as existsSync6 } from "node:fs";
23369
+ import { readdir as readdir2, realpath as realpath3, stat as stat2 } from "node:fs/promises";
23370
+ import path12 from "node:path";
23371
+
23367
23372
  // src/tools.ts
23368
23373
  var AGENT_MAP_TOOL_HOST = Object.freeze({
23369
23374
  readResult: "read its line range in the file",
@@ -23386,7 +23391,7 @@ var MAP_TOOL_NAMES = Object.freeze({
23386
23391
  references: "project_find_references",
23387
23392
  check: "project_check_changes"
23388
23393
  });
23389
- var mapDirectoryPath = (path13) => path13.length > 1 && path13.endsWith("/") && !path13.endsWith("//") ? path13.slice(0, -1) : path13;
23394
+ var mapDirectoryPath = (path14) => path14.length > 1 && path14.endsWith("/") && !path14.endsWith("//") ? path14.slice(0, -1) : path14;
23390
23395
  var ProjectMapSearchInputSchema = external_exports.object({
23391
23396
  path: external_exports.string().default("."),
23392
23397
  query: external_exports.string().min(1).max(256),
@@ -23414,6 +23419,9 @@ var ProjectMapExploreInputSchema = external_exports.object({
23414
23419
  var ProjectMapCheckInputSchema = external_exports.object({
23415
23420
  base: external_exports.string().min(1).max(200).default("HEAD").describe(
23416
23421
  "Commit, branch or tag to compare the working tree with (HEAD, so the uncommitted changes, by default; main for a whole branch)."
23422
+ ),
23423
+ path: external_exports.string().optional().describe(
23424
+ "A file or directory in the repository to check, when the session works in more than one; the check covers that repository's whole working tree."
23417
23425
  )
23418
23426
  }).strip();
23419
23427
  var locatorSchema = MapObjectLocatorSchema.describe(
@@ -23445,6 +23453,60 @@ var mapToolDescriptions = (host) => {
23445
23453
  });
23446
23454
  };
23447
23455
 
23456
+ // src/agent/projects.ts
23457
+ var escapes = (relative) => {
23458
+ const normal = path12.normalize(relative);
23459
+ return normal === ".." || normal.startsWith(`..${path12.sep}`);
23460
+ };
23461
+ async function locate(start, given) {
23462
+ if (start.git && !path12.isAbsolute(given) && !escapes(given))
23463
+ return { project: start.directory, path: given };
23464
+ const absolute = path12.resolve(start.directory, given);
23465
+ let directory = absolute;
23466
+ while (!(await stat2(directory).catch(() => void 0))?.isDirectory()) {
23467
+ if (path12.dirname(directory) === directory) return void 0;
23468
+ directory = path12.dirname(directory);
23469
+ }
23470
+ const real = path12.join(await realpath3(directory), path12.relative(directory, absolute));
23471
+ const { directory: project, git: git2 } = await projectDirectory(directory);
23472
+ if (!git2) return void 0;
23473
+ const relative = path12.relative(project, real);
23474
+ if (escapes(relative)) return void 0;
23475
+ return { project, path: relative ? relative.split(path12.sep).join("/") : "." };
23476
+ }
23477
+ async function repositoriesIn(directory) {
23478
+ const entries = await readdir2(directory, { withFileTypes: true }).catch(() => []);
23479
+ return entries.filter((entry) => entry.isDirectory() && existsSync6(path12.join(directory, entry.name, ".git"))).map((entry) => `${entry.name}/`).sort();
23480
+ }
23481
+ async function routeMapCall(start, { name, args }) {
23482
+ const holder = ["symbol", "locator"].find(
23483
+ (key) => name === MAP_TOOL_NAMES.references && args[key] !== void 0
23484
+ );
23485
+ const value = holder ? args[holder].path : args.path;
23486
+ const named = value || ".";
23487
+ const located = await locate(start, named);
23488
+ if (!located) {
23489
+ const repositories = start.git ? [] : await repositoriesIn(start.directory);
23490
+ const such = repositories.length ? `, such as ${repositories.join(", ")}` : "";
23491
+ 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: ${path12.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}`}.`;
23492
+ }
23493
+ if (!holder)
23494
+ return {
23495
+ project: located.project,
23496
+ args: value === void 0 ? args : { ...args, path: located.path }
23497
+ };
23498
+ const routed = {
23499
+ ...args,
23500
+ [holder]: { ...args[holder], path: located.path }
23501
+ };
23502
+ const filter = args.path;
23503
+ if (filter === ".") return { project: located.project, args: routed };
23504
+ const within2 = await locate(start, filter);
23505
+ if (within2?.project !== located.project)
23506
+ return `PROJECT_PATH_INVALID: path ${filter} is not in ${located.project}, the repository of the declaration.`;
23507
+ return { project: located.project, args: { ...routed, path: within2.path } };
23508
+ }
23509
+
23448
23510
  // src/agent/tools.ts
23449
23511
  var ReferencesInputSchema = mapReferencesInputSchema(AGENT_MAP_TOOL_HOST);
23450
23512
  var descriptions = mapToolDescriptions(AGENT_MAP_TOOL_HOST);
@@ -23491,10 +23553,10 @@ var HINTS = {
23491
23553
  PROJECT_MAP_REFERENCE_TARGET_UNAVAILABLE: "References are not available for this declaration; use its callers in project_explore_map.",
23492
23554
  LAYERMAP_BASE_NOT_FOUND: "No such commit, branch or tag. Leave base out to compare with HEAD, or name an existing one such as main.",
23493
23555
  LAYERMAP_BASE_INVALID: "base names a commit, branch or tag, such as HEAD or main.",
23494
- LAYERMAP_NOT_A_GIT_REPOSITORY: "LayerMap maps Git repositories, and the agent was started outside one. Start it in a repository, or run layermap with --project naming one."
23556
+ LAYERMAP_NOT_A_GIT_REPOSITORY: "LayerMap maps Git repositories. Run it in one, or name one with --project."
23495
23557
  };
23496
23558
  var describeMapError = (error51) => error51 instanceof ProjectEvidenceError ? `${error51.code}${HINTS[error51.code] ? `: ${HINTS[error51.code]}` : ""}` : void 0;
23497
- async function runMapTool(map2, name, args, signal) {
23559
+ function parseMapToolCall(name, args) {
23498
23560
  const tool = agentMapTools.find((candidate) => candidate.name === name);
23499
23561
  if (!tool) return { text: `Unknown tool ${name}.`, isError: true };
23500
23562
  const parsed = tool.schema.safeParse(args ?? {});
@@ -23503,9 +23565,12 @@ async function runMapTool(map2, name, args, signal) {
23503
23565
  text: `Invalid arguments: ${parsed.error.issues.map((issue2) => `${issue2.path.join(".") || "(arguments)"}: ${issue2.message}`).join("; ")}`,
23504
23566
  isError: true
23505
23567
  };
23568
+ return { name, args: parsed.data };
23569
+ }
23570
+ async function runMapTool(map2, { name, args }, signal) {
23506
23571
  try {
23507
23572
  if (name === MAP_TOOL_NAMES.explore) {
23508
- const input2 = parsed.data;
23573
+ const input2 = args;
23509
23574
  const declaration = input2.name !== void 0 || input2.line !== void 0;
23510
23575
  const page = await map2.explore(
23511
23576
  {
@@ -23522,15 +23587,15 @@ async function runMapTool(map2, name, args, signal) {
23522
23587
  return { text: page.text + more(page.nextOffset), isError: false };
23523
23588
  }
23524
23589
  if (name === MAP_TOOL_NAMES.check) {
23525
- const input2 = parsed.data;
23526
- return { text: (await map2.checkChanges(input2, signal)).text, isError: false };
23590
+ const input2 = args;
23591
+ return { text: (await map2.checkChanges({ base: input2.base }, signal)).text, isError: false };
23527
23592
  }
23528
23593
  if (name === MAP_TOOL_NAMES.search) {
23529
- const input2 = parsed.data;
23594
+ const input2 = args;
23530
23595
  const page = await map2.search({ ...input2, path: mapDirectoryPath(input2.path) }, signal);
23531
23596
  return { text: page.text + more(page.nextOffset), isError: false };
23532
23597
  }
23533
- const input = parsed.data;
23598
+ const input = args;
23534
23599
  return { text: JSON.stringify(await map2.references(input, signal)), isError: false };
23535
23600
  } catch (error51) {
23536
23601
  const text = describeMapError(error51);
@@ -23538,7 +23603,7 @@ async function runMapTool(map2, name, args, signal) {
23538
23603
  throw error51;
23539
23604
  }
23540
23605
  }
23541
- var AGENT_MAP_INSTRUCTIONS = `Use the LayerMap tools instead of grep whenever a task needs to know what calls something, what a change could affect beyond the code at hand, where something is used, or how the code is organized; a change confined to code you have read does not need them: project_explore_map on a declaration with direction INCOMING and depth up to 8 traces its callers up to the entry points (HTTP routes, handlers, jobs, commands) in one call, which grep can only approximate one name at a time. LayerMap is a static, layered map of this repository for TypeScript/JavaScript, Go, Python and Java: directories and modules, each file's declarations, and each declaration's callers and callees up to 8 hops. path "." shows what exists. Continue from any NOT EXPANDED declarations a view names, then confirm entry points in source. When the edits are done, call project_check_changes once before reporting the work done, not after every edit: it lists the entry points and existing tests the changes reach, and the existing tests the diff rewrote. The map is static: dynamic dispatch, framework wiring and unresolved targets need source reading, and a missing relationship does not prove absence. The first call on a project builds its map, which can take minutes on a large repository; later calls update only what changed.`;
23606
+ var AGENT_MAP_INSTRUCTIONS = `Use the LayerMap tools instead of grep whenever a task needs to know what calls something, what a change could affect beyond the code at hand, where something is used, or how the code is organized; a change confined to code you have read does not need them: project_explore_map on a declaration with direction INCOMING and depth up to 8 traces its callers up to the entry points (HTTP routes, handlers, jobs, commands) in one call, which grep can only approximate one name at a time. LayerMap is a static, layered map of this repository for TypeScript/JavaScript, Go, Python and Java: directories and modules, each file's declarations, and each declaration's callers and callees up to 8 hops. path "." shows what exists. Continue from any NOT EXPANDED declarations a view names, then confirm entry points in source. When the edits are done, call project_check_changes once before reporting the work done, not after every edit: it lists the entry points and existing tests the changes reach, and the existing tests the diff rewrote. The map is static: dynamic dispatch, framework wiring and unresolved targets need source reading, and a missing relationship does not prove absence. The first call on a project builds its map, which can take minutes on a large repository; later calls update only what changed. Each result names the Git repository it maps, and its paths are relative to that repository's root. The paths you give are relative to the repository the session started in, or to the starting folder when that is not a repository (such as a folder holding several); for a file in another repository, such as after changing directory, give its absolute path. Give project_check_changes a path in the repository to check when the session works in more than one.`;
23542
23607
  var AGENT_MAP_NOTE = "The layermap MCP server is available here. When a task needs to know what calls a function, what a change could affect beyond the code you are editing, or where code is used, use its project_explore_map tool (direction INCOMING, depth up to 8) instead of grep, then confirm in source; a change confined to code you have read does not need it. When the edits are done, call its project_check_changes tool once before reporting the work done.";
23543
23608
 
23544
23609
  // src/agent/mcp.ts
@@ -23549,55 +23614,67 @@ function serveMcp(options) {
23549
23614
  const send = (message) => output.write(`${JSON.stringify({ jsonrpc: "2.0", ...message })}
23550
23615
  `);
23551
23616
  const calls = /* @__PURE__ */ new Map();
23552
- let opened;
23553
- const map2 = () => {
23554
- opened ??= options.open();
23555
- return opened;
23556
- };
23617
+ const maps = /* @__PURE__ */ new Map();
23557
23618
  const session = new AbortController();
23558
- let warm;
23559
- const warmUp = () => {
23560
- warm ??= map2().then(async (layermap) => {
23561
- await layermap.refresh(session.signal);
23562
- void layermap.prepareBase(session.signal).catch(() => {
23619
+ const map2 = (project) => {
23620
+ let entry = maps.get(project);
23621
+ if (!entry) {
23622
+ const opened = options.open(project);
23623
+ const built = opened.then(async (layermap) => {
23624
+ await layermap.refresh(session.signal);
23625
+ void layermap.prepareBase(session.signal).catch(() => {
23626
+ });
23627
+ }).catch((error51) => {
23628
+ if (!session.signal.aborted) log2(`LayerMap could not build the map: ${String(error51)}`);
23563
23629
  });
23564
- }).catch((error51) => {
23565
- if (!session.signal.aborted) log2(`LayerMap could not build the map: ${String(error51)}`);
23566
- });
23567
- return warm;
23630
+ entry = { opened, built };
23631
+ maps.set(project, entry);
23632
+ }
23633
+ return entry;
23568
23634
  };
23569
23635
  const call = async (id2, params) => {
23570
23636
  const controller = new AbortController();
23571
23637
  calls.set(id2, controller);
23638
+ const name = String(params.name);
23639
+ let project;
23640
+ const respond = (text, isError) => send({
23641
+ id: id2,
23642
+ result: {
23643
+ content: [
23644
+ {
23645
+ type: "text",
23646
+ text: project ? `Project ${project} (paths are relative to it)
23647
+
23648
+ ${text}` : text
23649
+ }
23650
+ ],
23651
+ isError
23652
+ }
23653
+ });
23572
23654
  try {
23655
+ const parsed = parseMapToolCall(name, params.arguments);
23656
+ if ("text" in parsed) return respond(parsed.text, parsed.isError);
23657
+ const routed = await routeMapCall(options.start, parsed);
23658
+ if (typeof routed === "string") return respond(routed, true);
23659
+ project = routed.project;
23660
+ const { opened, built } = map2(project);
23573
23661
  const timer = new AbortController();
23574
- const built = await Promise.race([
23575
- warmUp().then(() => true),
23662
+ const ready = await Promise.race([
23663
+ built.then(() => true),
23576
23664
  delay(options.buildWaitMs ?? 4e4, false, {
23577
23665
  signal: AbortSignal.any([timer.signal, controller.signal])
23578
23666
  }).catch(() => false)
23579
23667
  ]);
23580
23668
  timer.abort();
23581
23669
  if (controller.signal.aborted) return;
23582
- const result = built ? await runMapTool(await map2(), String(params.name), params.arguments, controller.signal) : {
23583
- text: `LayerMap is still building this project's map (a first build can take minutes on a large repository). Call ${String(params.name)} again shortly, or read source meanwhile.`,
23670
+ const result = ready ? await runMapTool(await opened, { name, args: routed.args }, controller.signal) : {
23671
+ text: `LayerMap is still building this project's map (a first build can take minutes on a large repository). Call ${name} again shortly, or read source meanwhile.`,
23584
23672
  isError: false
23585
23673
  };
23586
- send({
23587
- id: id2,
23588
- result: { content: [{ type: "text", text: result.text }], isError: result.isError }
23589
- });
23674
+ respond(result.text, result.isError);
23590
23675
  } catch (error51) {
23591
23676
  if (controller.signal.aborted) return;
23592
- send({
23593
- id: id2,
23594
- result: {
23595
- content: [
23596
- { type: "text", text: describeMapError(error51) ?? `LayerMap failed: ${String(error51)}` }
23597
- ],
23598
- isError: true
23599
- }
23600
- });
23677
+ respond(describeMapError(error51) ?? `LayerMap failed: ${String(error51)}`, true);
23601
23678
  } finally {
23602
23679
  calls.delete(id2);
23603
23680
  }
@@ -23606,7 +23683,7 @@ function serveMcp(options) {
23606
23683
  const { id: id2, method, params = {} } = message;
23607
23684
  if (method === void 0) return;
23608
23685
  if (id2 === void 0 || id2 === null) {
23609
- if (method === "notifications/initialized") void warmUp();
23686
+ if (method === "notifications/initialized" && options.start.git) map2(options.start.directory);
23610
23687
  if (method === "notifications/cancelled")
23611
23688
  calls.get(params.requestId)?.abort();
23612
23689
  return;
@@ -23670,7 +23747,8 @@ function serveMcp(options) {
23670
23747
  lines.on("close", async () => {
23671
23748
  session.abort();
23672
23749
  for (const controller of calls.values()) controller.abort();
23673
- if (opened) await (await opened.catch(() => void 0))?.close().catch(() => void 0);
23750
+ for (const { opened } of maps.values())
23751
+ await (await opened.catch(() => void 0))?.close().catch(() => void 0);
23674
23752
  resolve();
23675
23753
  });
23676
23754
  });
@@ -23678,10 +23756,10 @@ function serveMcp(options) {
23678
23756
 
23679
23757
  // src/agent/setup.ts
23680
23758
  import { execFile as execFile2 } from "node:child_process";
23681
- import { existsSync as existsSync6 } from "node:fs";
23759
+ import { existsSync as existsSync7 } from "node:fs";
23682
23760
  import { mkdir as mkdir2, readFile as readFile2, rm as rm2, writeFile as writeFile2 } from "node:fs/promises";
23683
23761
  import { homedir as homedir2 } from "node:os";
23684
- import path12 from "node:path";
23762
+ import path13 from "node:path";
23685
23763
  var SERVER = "layermap";
23686
23764
  var SETUP_RULE = `mcp__${SERVER}`;
23687
23765
  var PLUGIN_RULE = `mcp__plugin_${SERVER}_${SERVER}`;
@@ -23694,8 +23772,8 @@ var npxServerArgs = (version2) => [
23694
23772
  "mcp"
23695
23773
  ];
23696
23774
  var mcpLaunchCommand = (version2, platform = process.platform) => {
23697
- const script = path12.resolve(process.argv[1] ?? "");
23698
- if (script.includes(`${path12.sep}_npx${path12.sep}`))
23775
+ const script = path13.resolve(process.argv[1] ?? "");
23776
+ if (script.includes(`${path13.sep}_npx${path13.sep}`))
23699
23777
  return [...platform === "win32" ? ["cmd", "/c"] : [], "npx", ...npxServerArgs(version2)];
23700
23778
  const execArgv = [];
23701
23779
  for (let index = 0; index < process.execArgv.length; index++) {
@@ -23723,7 +23801,7 @@ var run = (command, args, env) => new Promise((resolve) => {
23723
23801
  );
23724
23802
  });
23725
23803
  async function allowInClaudeSettings(file2, rule = SETUP_RULE) {
23726
- const settings = existsSync6(file2) ? JSON.parse(await readFile2(file2, "utf8")) : {};
23804
+ const settings = existsSync7(file2) ? JSON.parse(await readFile2(file2, "utf8")) : {};
23727
23805
  if (typeof settings !== "object" || settings === null || Array.isArray(settings))
23728
23806
  throw new Error(`${file2} is not a settings object.`);
23729
23807
  settings.permissions ??= {};
@@ -23732,7 +23810,7 @@ async function allowInClaudeSettings(file2, rule = SETUP_RULE) {
23732
23810
  throw new Error(`${file2} has permissions.allow that is not a list.`);
23733
23811
  if (settings.permissions.allow.includes(rule)) return false;
23734
23812
  settings.permissions.allow.push(rule);
23735
- await mkdir2(path12.dirname(file2), { recursive: true });
23813
+ await mkdir2(path13.dirname(file2), { recursive: true });
23736
23814
  await writeFile2(file2, `${JSON.stringify(settings, null, 2)}
23737
23815
  `);
23738
23816
  return true;
@@ -23760,17 +23838,17 @@ async function writeInstructionNote(file2, note = AGENT_MAP_NOTE) {
23760
23838
  const block = `${BEGIN}
23761
23839
  ${note}
23762
23840
  ${END}`;
23763
- const text = existsSync6(file2) ? await readFile2(file2, "utf8") : "";
23841
+ const text = existsSync7(file2) ? await readFile2(file2, "utf8") : "";
23764
23842
  const start = text.indexOf(BEGIN);
23765
23843
  const end = text.indexOf(END);
23766
23844
  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}
23767
23845
  `;
23768
23846
  if (next === text) return;
23769
- await mkdir2(path12.dirname(file2), { recursive: true });
23847
+ await mkdir2(path13.dirname(file2), { recursive: true });
23770
23848
  await writeFile2(file2, next);
23771
23849
  }
23772
23850
  async function removeInstructionNote(file2) {
23773
- if (!existsSync6(file2)) return;
23851
+ if (!existsSync7(file2)) return;
23774
23852
  const text = await readFile2(file2, "utf8");
23775
23853
  const start = text.indexOf(BEGIN);
23776
23854
  const end = text.indexOf(END);
@@ -23781,7 +23859,7 @@ async function removeInstructionNote(file2) {
23781
23859
  else await writeFile2(file2, rest);
23782
23860
  }
23783
23861
  async function disallowInClaudeSettings(file2) {
23784
- if (!existsSync6(file2)) return;
23862
+ if (!existsSync7(file2)) return;
23785
23863
  const settings = JSON.parse(await readFile2(file2, "utf8"));
23786
23864
  const allow = settings?.permissions?.allow;
23787
23865
  const ours = (rule) => rule === SETUP_RULE || rule === PLUGIN_RULE;
@@ -23794,14 +23872,14 @@ async function disallowInClaudeSettings(file2) {
23794
23872
  }
23795
23873
  var YAML_BEGIN = "# layermap:begin";
23796
23874
  var YAML_END = "# layermap:end";
23797
- var nodeDirectory = (env = process.env) => (env.PATH ?? "").split(path12.delimiter).find(
23798
- (directory) => path12.isAbsolute(directory) && existsSync6(path12.join(directory, "node")) && existsSync6(path12.join(directory, "npx"))
23799
- ) ?? path12.dirname(process.execPath);
23875
+ var nodeDirectory = (env = process.env) => (env.PATH ?? "").split(path13.delimiter).find(
23876
+ (directory) => path13.isAbsolute(directory) && existsSync7(path13.join(directory, "node")) && existsSync7(path13.join(directory, "npx"))
23877
+ ) ?? path13.dirname(process.execPath);
23800
23878
  var dshPatchBlock = (command, env) => {
23801
23879
  const node = nodeDirectory(env);
23802
- const npx = path12.join(node, "npx");
23803
- const [program = "", ...args] = command[0] === "npx" && existsSync6(npx) ? [npx, ...command.slice(1)] : command;
23804
- const searchPath2 = `${JSON.stringify(`${node}${path12.delimiter}`)} + process.env.PATH`;
23880
+ const npx = path13.join(node, "npx");
23881
+ const [program = "", ...args] = command[0] === "npx" && existsSync7(npx) ? [npx, ...command.slice(1)] : command;
23882
+ const searchPath2 = `${JSON.stringify(`${node}${path13.delimiter}`)} + process.env.PATH`;
23805
23883
  return [
23806
23884
  `${YAML_BEGIN} (written by \`layermap setup dsh\`; \`layermap remove dsh\` deletes it)`,
23807
23885
  "- insert:",
@@ -23820,7 +23898,7 @@ var dshPatchBlock = (command, env) => {
23820
23898
  ].join("\n");
23821
23899
  };
23822
23900
  async function writeDshPatch(file2, block) {
23823
- const text = existsSync6(file2) ? await readFile2(file2, "utf8") : "";
23901
+ const text = existsSync7(file2) ? await readFile2(file2, "utf8") : "";
23824
23902
  const start = text.indexOf(YAML_BEGIN);
23825
23903
  const end = text.indexOf(YAML_END);
23826
23904
  let next;
@@ -23836,11 +23914,11 @@ async function writeDshPatch(file2, block) {
23836
23914
  `;
23837
23915
  }
23838
23916
  if (next === text) return;
23839
- await mkdir2(path12.dirname(file2), { recursive: true });
23917
+ await mkdir2(path13.dirname(file2), { recursive: true });
23840
23918
  await writeFile2(file2, next);
23841
23919
  }
23842
23920
  async function removeDshPatch(file2) {
23843
- if (!existsSync6(file2)) return;
23921
+ if (!existsSync7(file2)) return;
23844
23922
  const text = await readFile2(file2, "utf8");
23845
23923
  const start = text.indexOf(YAML_BEGIN);
23846
23924
  const end = text.indexOf(YAML_END);
@@ -23854,31 +23932,31 @@ async function removeDshPatch(file2) {
23854
23932
  var agentFiles = (options) => {
23855
23933
  const env = options.env ?? process.env;
23856
23934
  if (options.agent === "dsh") {
23857
- const home = env.DSH_HOME || path12.join(homedir2(), ".dsh");
23935
+ const home = env.DSH_HOME || path13.join(homedir2(), ".dsh");
23858
23936
  return {
23859
- settings: path12.join(home, "cordis.patch.yml"),
23860
- instructions: path12.join(home, "AGENTS.md")
23937
+ settings: path13.join(home, "cordis.patch.yml"),
23938
+ instructions: path13.join(home, "AGENTS.md")
23861
23939
  };
23862
23940
  }
23863
23941
  if (options.agent === "codex") {
23864
- const home = env.CODEX_HOME ?? path12.join(homedir2(), ".codex");
23865
- return { settings: path12.join(home, "config.toml"), instructions: path12.join(home, "AGENTS.md") };
23942
+ const home = env.CODEX_HOME ?? path13.join(homedir2(), ".codex");
23943
+ return { settings: path13.join(home, "config.toml"), instructions: path13.join(home, "AGENTS.md") };
23866
23944
  }
23867
23945
  if (options.scope === "user") {
23868
- const home = env.CLAUDE_CONFIG_DIR ?? path12.join(homedir2(), ".claude");
23946
+ const home = env.CLAUDE_CONFIG_DIR ?? path13.join(homedir2(), ".claude");
23869
23947
  return {
23870
- settings: path12.join(home, "settings.json"),
23871
- instructions: path12.join(home, "CLAUDE.md")
23948
+ settings: path13.join(home, "settings.json"),
23949
+ instructions: path13.join(home, "CLAUDE.md")
23872
23950
  };
23873
23951
  }
23874
23952
  const local = options.scope === "local";
23875
23953
  return {
23876
- settings: path12.join(
23954
+ settings: path13.join(
23877
23955
  options.project,
23878
23956
  ".claude",
23879
23957
  local ? "settings.local.json" : "settings.json"
23880
23958
  ),
23881
- instructions: path12.join(options.project, local ? "CLAUDE.local.md" : "CLAUDE.md")
23959
+ instructions: path13.join(options.project, local ? "CLAUDE.local.md" : "CLAUDE.md")
23882
23960
  };
23883
23961
  };
23884
23962
  async function setupAgent(options) {
@@ -23985,7 +24063,8 @@ Usage:
23985
24063
  layermap refs PATH NAME [--line N] [--path DIR] [--max N] [--cursor C]
23986
24064
  layermap check [--base REF] what the uncommitted changes (or those since REF) affect
23987
24065
 
23988
- The project is the Git work tree around the current directory unless --project names one.
24066
+ The project is the Git work tree around the current directory unless --project names one; the MCP
24067
+ server also maps any other repository a tool call's path names.
23989
24068
  Maps are kept in ${cacheDirectory()}.`;
23990
24069
  var log = (line) => process.stderr.write(`${line}
23991
24070
  `);
@@ -24029,10 +24108,9 @@ async function main(argv) {
24029
24108
  if (values.help || !command) return usage(command ? 0 : 1);
24030
24109
  const { directory: project, git: git2 } = await projectDirectory(values.project ?? process.cwd());
24031
24110
  const cache = cacheDirectory();
24032
- const open2 = async () => {
24033
- if (!git2) throw new ProjectEvidenceError("LAYERMAP_NOT_A_GIT_REPOSITORY", false);
24111
+ const open2 = async (directory) => {
24034
24112
  const map3 = await LayerMap.open({
24035
- project,
24113
+ project: directory,
24036
24114
  cacheDirectory: cache,
24037
24115
  analyzers: await resolveAnalyzers(cache, log)
24038
24116
  });
@@ -24057,11 +24135,12 @@ async function main(argv) {
24057
24135
  return done ? 0 : 1;
24058
24136
  }
24059
24137
  if (command === "mcp") {
24060
- await serveMcp({ version: version2, open: open2, log });
24138
+ await serveMcp({ version: version2, start: { directory: project, git: git2 }, open: open2, log });
24061
24139
  return 0;
24062
24140
  }
24063
24141
  const number4 = (value) => value === void 0 ? void 0 : Number(value);
24064
- const map2 = await open2();
24142
+ if (!git2) throw new ProjectEvidenceError("LAYERMAP_NOT_A_GIT_REPOSITORY", false);
24143
+ const map2 = await open2(project);
24065
24144
  const signal = new AbortController().signal;
24066
24145
  try {
24067
24146
  if (command === "index") {
@@ -24116,7 +24195,8 @@ async function main(argv) {
24116
24195
  field && typeof field === "object" && !Array.isArray(field) ? defined(field) : field
24117
24196
  ])
24118
24197
  );
24119
- const result = await runMapTool(map2, tool, defined(args), signal);
24198
+ const parsed = parseMapToolCall(tool, defined(args));
24199
+ const result = "text" in parsed ? parsed : await runMapTool(map2, parsed, signal);
24120
24200
  (result.isError ? process.stderr : process.stdout).write(`${result.text}
24121
24201
  `);
24122
24202
  return result.isError ? 1 : 0;