layermap 0.1.48 → 0.1.49

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