codebase-snapshot 0.21.0 → 0.22.0

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/bin.js CHANGED
@@ -3,7 +3,7 @@
3
3
  // src/cli.ts
4
4
  import { spawnSync as spawnSync4 } from "child_process";
5
5
  import * as fs30 from "fs";
6
- import * as path32 from "path";
6
+ import * as path33 from "path";
7
7
  import { fileURLToPath as fileURLToPath4 } from "url";
8
8
  import { parseArgs } from "util";
9
9
 
@@ -344,8 +344,8 @@ function workspacePackageDirs(cwd, patterns) {
344
344
  function scanWorkspacePackages(cwd, patterns) {
345
345
  const files = /* @__PURE__ */ new Set();
346
346
  const dependencies = /* @__PURE__ */ new Set();
347
- for (const relative20 of workspacePackageDirs(cwd, patterns)) {
348
- const full = path.join(cwd, relative20);
347
+ for (const relative21 of workspacePackageDirs(cwd, patterns)) {
348
+ const full = path.join(cwd, relative21);
349
349
  try {
350
350
  for (const entry of fs.readdirSync(full, { withFileTypes: true })) files.add(entry.name);
351
351
  } catch {
@@ -2556,8 +2556,8 @@ import * as path3 from "path";
2556
2556
  import * as fs2 from "fs";
2557
2557
  import * as path2 from "path";
2558
2558
  function isInside(parent, child) {
2559
- const relative20 = path2.relative(parent, child);
2560
- return relative20 === "" || relative20 !== ".." && !relative20.startsWith(`..${path2.sep}`) && !relative20.startsWith("../") && !path2.isAbsolute(relative20);
2559
+ const relative21 = path2.relative(parent, child);
2560
+ return relative21 === "" || relative21 !== ".." && !relative21.startsWith(`..${path2.sep}`) && !relative21.startsWith("../") && !path2.isAbsolute(relative21);
2561
2561
  }
2562
2562
  function resolveConfined(baseDir, relativePath) {
2563
2563
  if (relativePath.length === 0 || relativePath.includes("\0")) {
@@ -2723,7 +2723,7 @@ function verifySnapshotSignature(snapshotDir) {
2723
2723
 
2724
2724
  // src/version.ts
2725
2725
  var GENERATOR_NAME = "codebase-snapshot";
2726
- var GENERATOR_VERSION = "0.21.0";
2726
+ var GENERATOR_VERSION = "0.22.0";
2727
2727
  var SCHEMA_VERSION = "3.0.0";
2728
2728
  var LEGACY_GENERATOR_NAMES = ["@ankurhalder/codebase-snapshot"];
2729
2729
  function isOurGeneratorName(name) {
@@ -2755,8 +2755,8 @@ function brokenLinkRecord(linkPath, relativePath, rootReal) {
2755
2755
  };
2756
2756
  }
2757
2757
  function isInside2(root, candidate) {
2758
- const relative20 = path4.relative(root, candidate);
2759
- return relative20 === "" || !relative20.startsWith(`..${path4.sep}`) && relative20 !== ".." && !path4.isAbsolute(relative20);
2758
+ const relative21 = path4.relative(root, candidate);
2759
+ return relative21 === "" || !relative21.startsWith(`..${path4.sep}`) && relative21 !== ".." && !path4.isAbsolute(relative21);
2760
2760
  }
2761
2761
  var GIT_OUTPUT_LIMIT = 68157440;
2762
2762
  function getGitInfo(cwd, fallbackBranch = "main") {
@@ -3358,17 +3358,17 @@ function isToolOwnedDirectory2(dir) {
3358
3358
  return false;
3359
3359
  }
3360
3360
  for (const entry of entries) {
3361
- const relative20 = current === "" ? entry.name : current + "/" + entry.name;
3362
- if (relative20 === ".codebase-snapshot" || IGNORABLE_DIRECTORY_ENTRIES.has(entry.name)) continue;
3361
+ const relative21 = current === "" ? entry.name : current + "/" + entry.name;
3362
+ if (relative21 === ".codebase-snapshot" || IGNORABLE_DIRECTORY_ENTRIES.has(entry.name)) continue;
3363
3363
  if (entry.isDirectory()) {
3364
- stack.push(relative20);
3364
+ stack.push(relative21);
3365
3365
  continue;
3366
3366
  }
3367
3367
  if (!entry.isFile()) return false;
3368
- if (relative20 === "signature.json" && !recordedFiles.has(relative20) && verifySnapshotSignature(dir).ok) {
3368
+ if (relative21 === "signature.json" && !recordedFiles.has(relative21) && verifySnapshotSignature(dir).ok) {
3369
3369
  continue;
3370
3370
  }
3371
- if (!recordedFiles.has(relative20)) return false;
3371
+ if (!recordedFiles.has(relative21)) return false;
3372
3372
  }
3373
3373
  }
3374
3374
  return true;
@@ -4717,13 +4717,13 @@ function readConfiguredBrief(cwd, value) {
4717
4717
  'brief "' + value + '" could not be read as a file; a snapshot must not ship without the half of the brief the owner wrote.'
4718
4718
  );
4719
4719
  }
4720
- const relative20 = path5.relative(rootReal, filePath);
4721
- if (relative20.length === 0 || relative20 === ".." || relative20.startsWith(`..${path5.sep}`) || path5.isAbsolute(relative20)) {
4720
+ const relative21 = path5.relative(rootReal, filePath);
4721
+ if (relative21.length === 0 || relative21 === ".." || relative21.startsWith(`..${path5.sep}`) || path5.isAbsolute(relative21)) {
4722
4722
  throw new Error(
4723
4723
  'brief "' + value + '" resolves outside the repository. A brief must be a file inside the repository being described; an absolute or parent path is refused.'
4724
4724
  );
4725
4725
  }
4726
- const posixRelative = relative20.split(path5.sep).join("/");
4726
+ const posixRelative = relative21.split(path5.sep).join("/");
4727
4727
  if (isSensitivePath(posixRelative) || isSensitivePath(value)) {
4728
4728
  throw new Error(
4729
4729
  'brief "' + value + '" is a credential-bearing file. A snapshot must not reproduce secrets, so it cannot be used as the owner brief.'
@@ -4765,24 +4765,24 @@ function readConfiguredBrief(cwd, value) {
4765
4765
  }
4766
4766
  return parsed.brief;
4767
4767
  }
4768
- function strictPositiveInteger(value, fallback, label) {
4768
+ function strictPositiveInteger(value, fallback, label2) {
4769
4769
  if (value === void 0) return fallback;
4770
4770
  if (typeof value !== "number" || !Number.isInteger(value) || value <= 0) {
4771
- throw new Error(`${label} must be a positive integer (received ${describeValue2(value)}).`);
4771
+ throw new Error(`${label2} must be a positive integer (received ${describeValue2(value)}).`);
4772
4772
  }
4773
4773
  return value;
4774
4774
  }
4775
- function strictBoolean(value, fallback, label) {
4775
+ function strictBoolean(value, fallback, label2) {
4776
4776
  if (value === void 0) return fallback;
4777
4777
  if (typeof value !== "boolean") {
4778
- throw new Error(`${label} must be true or false (received ${describeValue2(value)}).`);
4778
+ throw new Error(`${label2} must be true or false (received ${describeValue2(value)}).`);
4779
4779
  }
4780
4780
  return value;
4781
4781
  }
4782
- function strictString(value, fallback, label) {
4782
+ function strictString(value, fallback, label2) {
4783
4783
  if (value === void 0) return fallback;
4784
4784
  if (typeof value !== "string" || value.trim() === "") {
4785
- throw new Error(`${label} must be a non-empty string (received ${describeValue2(value)}).`);
4785
+ throw new Error(`${label2} must be a non-empty string (received ${describeValue2(value)}).`);
4786
4786
  }
4787
4787
  return value;
4788
4788
  }
@@ -4871,11 +4871,11 @@ function outputExcludePatterns(cwd, outDir, tmpDir) {
4871
4871
  const patterns = [];
4872
4872
  for (const dir of [outDir, tmpDir]) {
4873
4873
  const absolute = path5.resolve(cwd, dir);
4874
- const relative20 = path5.relative(cwd, absolute);
4875
- if (!relative20 || relative20 === ".." || relative20.startsWith(`..${path5.sep}`) || path5.isAbsolute(relative20)) {
4874
+ const relative21 = path5.relative(cwd, absolute);
4875
+ if (!relative21 || relative21 === ".." || relative21.startsWith(`..${path5.sep}`) || path5.isAbsolute(relative21)) {
4876
4876
  continue;
4877
4877
  }
4878
- patterns.push(`${relative20.replace(/\\/g, "/")}/**`);
4878
+ patterns.push(`${relative21.replace(/\\/g, "/")}/**`);
4879
4879
  }
4880
4880
  return patterns;
4881
4881
  }
@@ -4906,42 +4906,42 @@ function parseByteSize(value) {
4906
4906
  function describeBytes(value) {
4907
4907
  return typeof value === "number" ? String(value) : `"${value}"`;
4908
4908
  }
4909
- function boundedBytes(value, fallback, minimum, label) {
4909
+ function boundedBytes(value, fallback, minimum, label2) {
4910
4910
  if (value === void 0) return fallback;
4911
4911
  const parsed = parseByteSize(value);
4912
4912
  if (parsed === void 0) {
4913
4913
  throw new Error(
4914
- `${label} must be a byte count such as 120000, "120k" or "1.5mb" (received ${describeBytes(value)}).`
4914
+ `${label2} must be a byte count such as 120000, "120k" or "1.5mb" (received ${describeBytes(value)}).`
4915
4915
  );
4916
4916
  }
4917
4917
  if (parsed <= 0) {
4918
- throw new Error(`${label} must be a positive byte count (received ${describeBytes(value)}).`);
4918
+ throw new Error(`${label2} must be a positive byte count (received ${describeBytes(value)}).`);
4919
4919
  }
4920
4920
  if (parsed < minimum) {
4921
- throw new Error(`${label} must be at least ${minimum} bytes (received ${describeBytes(value)}).`);
4921
+ throw new Error(`${label2} must be at least ${minimum} bytes (received ${describeBytes(value)}).`);
4922
4922
  }
4923
4923
  return parsed;
4924
4924
  }
4925
- function boundedTokens(value, label) {
4925
+ function boundedTokens(value, label2) {
4926
4926
  const parsed = parseByteSize(value);
4927
4927
  if (parsed === void 0 || !Number.isInteger(parsed)) {
4928
4928
  throw new Error(
4929
- `${label} must be a whole token count such as 30000 or "30k" (received ${describeBytes(value)}).`
4929
+ `${label2} must be a whole token count such as 30000 or "30k" (received ${describeBytes(value)}).`
4930
4930
  );
4931
4931
  }
4932
4932
  if (parsed < MIN_MAX_PART_TOKENS) {
4933
4933
  throw new Error(
4934
- `${label} must be at least ${MIN_MAX_PART_TOKENS} tokens (${MIN_MAX_PART_BYTES} bytes is the smallest part budget); received ${describeBytes(value)}.`
4934
+ `${label2} must be at least ${MIN_MAX_PART_TOKENS} tokens (${MIN_MAX_PART_BYTES} bytes is the smallest part budget); received ${describeBytes(value)}.`
4935
4935
  );
4936
4936
  }
4937
4937
  return parsed;
4938
4938
  }
4939
- function optionalBytes(value, label) {
4939
+ function optionalBytes(value, label2) {
4940
4940
  if (value === void 0 || value === null) return null;
4941
4941
  const parsed = parseByteSize(value);
4942
4942
  if (parsed === void 0 || parsed <= 0) {
4943
4943
  throw new Error(
4944
- `${label} must be a positive byte count such as 1000000 or "1mb" (received ${describeBytes(value)}).`
4944
+ `${label2} must be a positive byte count such as 1000000 or "1mb" (received ${describeBytes(value)}).`
4945
4945
  );
4946
4946
  }
4947
4947
  return parsed;
@@ -5492,8 +5492,8 @@ function resolveDiffChangedLines(cwd, ref, files) {
5492
5492
  continue;
5493
5493
  }
5494
5494
  const withoutPrefix = raw.startsWith("b/") ? raw.slice(2) : raw;
5495
- const path33 = withoutPrefix.split(" ")[0];
5496
- current = path33.length > 0 ? path33 : null;
5495
+ const path34 = withoutPrefix.split(" ")[0];
5496
+ current = path34.length > 0 ? path34 : null;
5497
5497
  if (current !== null && !ranges.has(current)) ranges.set(current, []);
5498
5498
  continue;
5499
5499
  }
@@ -5522,11 +5522,11 @@ function resolveChangedScope(cwd, request) {
5522
5522
  if (request.changedSince !== void 0) {
5523
5523
  assertUsableRef(request.changedSince);
5524
5524
  if (request.changedSince === "HEAD" && !hasHeadCommit(cwd)) {
5525
- for (const path33 of gitPaths(cwd, ["ls-files", "--cached", "-z", "--"])) {
5526
- paths.add(path33);
5525
+ for (const path34 of gitPaths(cwd, ["ls-files", "--cached", "-z", "--"])) {
5526
+ paths.add(path34);
5527
5527
  }
5528
- for (const path33 of gitPaths(cwd, ["ls-files", "--others", "--exclude-standard", "-z", "--"])) {
5529
- paths.add(path33);
5528
+ for (const path34 of gitPaths(cwd, ["ls-files", "--others", "--exclude-standard", "-z", "--"])) {
5529
+ paths.add(path34);
5530
5530
  }
5531
5531
  descriptions.push("changed since HEAD (unborn)");
5532
5532
  } else {
@@ -5539,7 +5539,7 @@ function resolveChangedScope(cwd, request) {
5539
5539
  );
5540
5540
  }
5541
5541
  if (base !== null) {
5542
- for (const path33 of gitPaths(cwd, [
5542
+ for (const path34 of gitPaths(cwd, [
5543
5543
  "-c",
5544
5544
  "core.quotepath=false",
5545
5545
  "-c",
@@ -5556,17 +5556,17 @@ function resolveChangedScope(cwd, request) {
5556
5556
  base,
5557
5557
  "--"
5558
5558
  ])) {
5559
- paths.add(path33);
5559
+ paths.add(path34);
5560
5560
  }
5561
5561
  }
5562
- for (const path33 of gitPaths(cwd, ["ls-files", "--others", "--exclude-standard", "-z", "--"])) {
5563
- paths.add(path33);
5562
+ for (const path34 of gitPaths(cwd, ["ls-files", "--others", "--exclude-standard", "-z", "--"])) {
5563
+ paths.add(path34);
5564
5564
  }
5565
5565
  descriptions.push(`changed since ${request.changedSince}`);
5566
5566
  }
5567
5567
  }
5568
5568
  if (request.staged === true) {
5569
- for (const path33 of gitPaths(cwd, [
5569
+ for (const path34 of gitPaths(cwd, [
5570
5570
  "-c",
5571
5571
  "core.quotepath=false",
5572
5572
  "diff",
@@ -5577,10 +5577,10 @@ function resolveChangedScope(cwd, request) {
5577
5577
  "--no-renames",
5578
5578
  "--"
5579
5579
  ])) {
5580
- paths.add(path33);
5581
- stagedPaths.add(path33);
5580
+ paths.add(path34);
5581
+ stagedPaths.add(path34);
5582
5582
  }
5583
- for (const path33 of gitPaths(cwd, [
5583
+ for (const path34 of gitPaths(cwd, [
5584
5584
  "-c",
5585
5585
  "core.quotepath=false",
5586
5586
  "diff",
@@ -5592,7 +5592,7 @@ function resolveChangedScope(cwd, request) {
5592
5592
  "--diff-filter=D",
5593
5593
  "--"
5594
5594
  ])) {
5595
- deletedPaths.add(path33);
5595
+ deletedPaths.add(path34);
5596
5596
  }
5597
5597
  descriptions.push("staged");
5598
5598
  }
@@ -5631,8 +5631,8 @@ var MAX_CONFIG_BYTES = 4 * 1024 * 1024;
5631
5631
  var MAX_PACKAGE_BYTES = 1 * 1024 * 1024;
5632
5632
  function repositoryRelative(cwd, target) {
5633
5633
  const absolute = path6.isAbsolute(target) ? target : path6.resolve(cwd, target);
5634
- const relative20 = path6.relative(cwd, absolute).replace(/\\/g, "/");
5635
- return relative20.length === 0 || relative20 !== ".." && !relative20.startsWith(".." + path6.sep) && !relative20.startsWith("../") && !path6.isAbsolute(relative20) ? relative20 : null;
5634
+ const relative21 = path6.relative(cwd, absolute).replace(/\\/g, "/");
5635
+ return relative21.length === 0 || relative21 !== ".." && !relative21.startsWith(".." + path6.sep) && !relative21.startsWith("../") && !path6.isAbsolute(relative21) ? relative21 : null;
5636
5636
  }
5637
5637
  function insideCwd(cwd, file) {
5638
5638
  return repositoryRelative(cwd, file);
@@ -5688,8 +5688,8 @@ function parseImports(value) {
5688
5688
  return Object.entries(record).filter(([key]) => key.startsWith("#")).map(([pattern, target]) => ({ pattern, targets: targetList(target) }));
5689
5689
  }
5690
5690
  function readPackageJson(cwd, packageDir) {
5691
- const relative20 = packageDir.length === 0 ? "package.json" : packageDir + "/package.json";
5692
- const parsed = asRecord(readJson(cwd, relative20, MAX_PACKAGE_BYTES));
5691
+ const relative21 = packageDir.length === 0 ? "package.json" : packageDir + "/package.json";
5692
+ const parsed = asRecord(readJson(cwd, relative21, MAX_PACKAGE_BYTES));
5693
5693
  if (parsed === null) return null;
5694
5694
  const exportsMap = parseExports(parsed.exports);
5695
5695
  if (exportsMap.length === 0) {
@@ -5731,8 +5731,8 @@ function parsePnpmWorkspace(cwd) {
5731
5731
  }
5732
5732
  function listChildDirectories(cwd, relativeDir) {
5733
5733
  const absolute = path6.resolve(cwd, relativeDir);
5734
- const relative20 = repositoryRelative(cwd, absolute);
5735
- if (relative20 === null) return [];
5734
+ const relative21 = repositoryRelative(cwd, absolute);
5735
+ if (relative21 === null) return [];
5736
5736
  let entries;
5737
5737
  try {
5738
5738
  entries = fs6.readdirSync(absolute === cwd ? cwd : absolute, { withFileTypes: true });
@@ -5742,7 +5742,7 @@ function listChildDirectories(cwd, relativeDir) {
5742
5742
  const out = [];
5743
5743
  for (const entry of entries) {
5744
5744
  if (!entry.isDirectory()) continue;
5745
- const child = relative20.length === 0 ? entry.name : relative20 + "/" + entry.name;
5745
+ const child = relative21.length === 0 ? entry.name : relative21 + "/" + entry.name;
5746
5746
  if (child.split("/").includes("node_modules")) continue;
5747
5747
  out.push(child);
5748
5748
  }
@@ -6958,9 +6958,9 @@ var JAVA_METHOD = /^\s+(?:public|private|protected)\s+(?:static\s+)?(?:final\s+)
6958
6958
  var jvmProfile = {
6959
6959
  id: "jvm",
6960
6960
  extensions: [".java", ".kt", ".kts", ".scala"],
6961
- summarize(path33, content) {
6961
+ summarize(path34, content) {
6962
6962
  const summary = emptySummary();
6963
- const lower = path33.toLowerCase();
6963
+ const lower = path34.toLowerCase();
6964
6964
  const isJava = lower.endsWith(".java");
6965
6965
  const isKotlin = lower.endsWith(".kt") || lower.endsWith(".kts");
6966
6966
  eachLine(content, (line) => {
@@ -7183,9 +7183,9 @@ var rubyProfile = {
7183
7183
  eachLine(content, (line) => {
7184
7184
  const trimmed = line.trim();
7185
7185
  if (!trimmed || trimmed.startsWith("#")) return;
7186
- const relative20 = REQUIRE_RELATIVE.exec(trimmed);
7187
- if (relative20) {
7188
- summary.imports.push(`./${relative20[1]}`);
7186
+ const relative21 = REQUIRE_RELATIVE.exec(trimmed);
7187
+ if (relative21) {
7188
+ summary.imports.push(`./${relative21[1]}`);
7189
7189
  return;
7190
7190
  }
7191
7191
  const required = REQUIRE.exec(trimmed);
@@ -7281,17 +7281,17 @@ var rustProfile = {
7281
7281
  var SCRIPT_BLOCK = /<script([^>]*)>([\s\S]*?)<\/script(?:\s[^>]*)?>/gi;
7282
7282
  var JSX_LANG = /\blang\s*=\s*["']?[tj]sx\b/i;
7283
7283
  var ASTRO_FRONTMATTER = /^\uFEFF?---[ \t]*\r?\n([\s\S]*?)\r?\n---[ \t]*(?=\r?\n|$)/;
7284
- function componentName(path33) {
7285
- const base = path33.split("/").pop() ?? path33;
7284
+ function componentName(path34) {
7285
+ const base = path34.split("/").pop() ?? path34;
7286
7286
  return base.replace(/\.[^.]+$/, "");
7287
7287
  }
7288
7288
  var sfcProfile = {
7289
7289
  id: "sfc",
7290
7290
  extensions: [".vue", ".svelte", ".astro"],
7291
- summarize(path33, content) {
7291
+ summarize(path34, content) {
7292
7292
  let script = "";
7293
- let usesJsx = path33.toLowerCase().endsWith(".astro");
7294
- if (path33.toLowerCase().endsWith(".astro")) {
7293
+ let usesJsx = path34.toLowerCase().endsWith(".astro");
7294
+ if (path34.toLowerCase().endsWith(".astro")) {
7295
7295
  const frontmatter = ASTRO_FRONTMATTER.exec(content);
7296
7296
  if (frontmatter) script += `${frontmatter[1]}
7297
7297
  `;
@@ -7301,7 +7301,7 @@ var sfcProfile = {
7301
7301
  script += `${match[2]}
7302
7302
  `;
7303
7303
  }
7304
- const name = componentName(path33);
7304
+ const name = componentName(path34);
7305
7305
  if (!script.trim()) {
7306
7306
  const summary2 = emptySummary();
7307
7307
  if (name) {
@@ -7492,15 +7492,15 @@ for (const profile of LANGUAGE_PROFILES) {
7492
7492
  BY_EXTENSION.set(extension.toLowerCase(), profile);
7493
7493
  }
7494
7494
  }
7495
- function profileForPath(path33) {
7496
- const lower = path33.toLowerCase();
7495
+ function profileForPath(path34) {
7496
+ const lower = path34.toLowerCase();
7497
7497
  const dot = lower.lastIndexOf(".");
7498
7498
  if (dot === -1) return null;
7499
7499
  return BY_EXTENSION.get(lower.slice(dot)) ?? null;
7500
7500
  }
7501
- function summarizeWithProfile(path33, content) {
7502
- const profile = profileForPath(path33);
7503
- return profile ? profile.summarize(path33, content) : null;
7501
+ function summarizeWithProfile(path34, content) {
7502
+ const profile = profileForPath(path34);
7503
+ return profile ? profile.summarize(path34, content) : null;
7504
7504
  }
7505
7505
 
7506
7506
  // src/scanner/binary.ts
@@ -8192,25 +8192,25 @@ function validateSnapshot(configInput) {
8192
8192
  const incompleteness = /* @__PURE__ */ new Map();
8193
8193
  for (const record of incompleteRecords) {
8194
8194
  incompleteness.set(record.relativePath, record);
8195
- const label = maskedPath(record.relativePath, config.secretRules);
8195
+ const label2 = maskedPath(record.relativePath, config.secretRules);
8196
8196
  const file = manifestFilesByPath.get(record.relativePath);
8197
8197
  if (file === void 0) {
8198
8198
  drift.partIssues.push({
8199
8199
  part: "(manifest)",
8200
- issue: `${label} is in incomplete[] but not in files[]`
8200
+ issue: `${label2} is in incomplete[] but not in files[]`
8201
8201
  });
8202
8202
  continue;
8203
8203
  }
8204
8204
  if (file.part !== record.part) {
8205
8205
  drift.partIssues.push({
8206
8206
  part: "(manifest)",
8207
- issue: `${label} is recorded in part ${String(record.part)} in incomplete[] and part ${String(file.part)} in files[]`
8207
+ issue: `${label2} is recorded in part ${String(record.part)} in incomplete[] and part ${String(file.part)} in files[]`
8208
8208
  });
8209
8209
  }
8210
8210
  if (file.truncationReason !== record.reason) {
8211
8211
  drift.partIssues.push({
8212
8212
  part: "(manifest)",
8213
- issue: `${label} records truncationReason ${String(file.truncationReason)} in files[] and reason ${String(record.reason)} in incomplete[]`
8213
+ issue: `${label2} records truncationReason ${String(file.truncationReason)} in files[] and reason ${String(record.reason)} in incomplete[]`
8214
8214
  });
8215
8215
  }
8216
8216
  const recordedRanges = file.omittedRanges ?? [];
@@ -8220,7 +8220,7 @@ function validateSnapshot(configInput) {
8220
8220
  if (!rangesAgree || file.includedLines !== record.includedLines || file.lines !== record.lines) {
8221
8221
  drift.partIssues.push({
8222
8222
  part: "(manifest)",
8223
- issue: `${label} records different omission numbers in files[] and incomplete[]`
8223
+ issue: `${label2} records different omission numbers in files[] and incomplete[]`
8224
8224
  });
8225
8225
  }
8226
8226
  }
@@ -8315,7 +8315,7 @@ function validateSnapshot(configInput) {
8315
8315
  toolOwnedPaths: [config.outDir, config.tmpDir].map(
8316
8316
  (directory) => path8.relative(config.cwd, path8.resolve(config.cwd, directory)).replace(/\\/g, "/")
8317
8317
  ).filter(
8318
- (relative20) => relative20.length > 0 && relative20 !== ".." && !relative20.startsWith(`..${path8.sep}`) && !relative20.startsWith("../") && !path8.isAbsolute(relative20)
8318
+ (relative21) => relative21.length > 0 && relative21 !== ".." && !relative21.startsWith(`..${path8.sep}`) && !relative21.startsWith("../") && !path8.isAbsolute(relative21)
8319
8319
  )
8320
8320
  });
8321
8321
  const discovered = new Set(collection.files);
@@ -8723,9 +8723,9 @@ function validateSnapshot(configInput) {
8723
8723
  drift.configMismatches.push("manifest does not record the effective configuration");
8724
8724
  }
8725
8725
  const totalsMismatches = drift.totalsMismatches;
8726
- const expectEqual = (label, recordedValue, actual) => {
8726
+ const expectEqual = (label2, recordedValue, actual) => {
8727
8727
  if (recordedValue !== actual) {
8728
- totalsMismatches.push(`${label}: manifest ${String(recordedValue)} vs actual ${actual}`);
8728
+ totalsMismatches.push(`${label2}: manifest ${String(recordedValue)} vs actual ${actual}`);
8729
8729
  }
8730
8730
  };
8731
8731
  const counts = manifest.counts ?? {};
@@ -8867,9 +8867,9 @@ function validateSnapshot(configInput) {
8867
8867
  const target = match[1].split("#")[0];
8868
8868
  if (target.length === 0 || /^[a-z][a-z0-9+.-]*:/i.test(target)) continue;
8869
8869
  const resolved = path8.resolve(snapshotDir, "reports", target);
8870
- const relative20 = path8.relative(snapshotDir, resolved);
8871
- const linkTarget = relative20.split(path8.sep).join("/");
8872
- const escapes = relative20 === ".." || relative20.startsWith(`..${path8.sep}`) || relative20.startsWith("../") || path8.isAbsolute(relative20);
8870
+ const relative21 = path8.relative(snapshotDir, resolved);
8871
+ const linkTarget = relative21.split(path8.sep).join("/");
8872
+ const escapes = relative21 === ".." || relative21.startsWith(`..${path8.sep}`) || relative21.startsWith("../") || path8.isAbsolute(relative21);
8873
8873
  const partsRelative = path8.relative(path8.join(snapshotDir, "parts"), resolved);
8874
8874
  const pointsIntoParts = partsRelative === "" || partsRelative !== ".." && !partsRelative.startsWith(`..${path8.sep}`) && !partsRelative.startsWith("../") && !path8.isAbsolute(partsRelative);
8875
8875
  const expectedToBeAbsent = !config.artifacts.parts && pointsIntoParts;
@@ -8988,8 +8988,8 @@ function describeLayerChanges(before, after, secretRules) {
8988
8988
  const was = before[name] ?? 0;
8989
8989
  const now = after[name] ?? 0;
8990
8990
  if (was === now) continue;
8991
- const label = findSecretInPath(name, secretRules)?.masked ?? name;
8992
- changes.push(`layer "${label}": ${was} file(s) \u2192 ${now} file(s)`);
8991
+ const label2 = findSecretInPath(name, secretRules)?.masked ?? name;
8992
+ changes.push(`layer "${label2}": ${was} file(s) \u2192 ${now} file(s)`);
8993
8993
  }
8994
8994
  return changes;
8995
8995
  }
@@ -9003,12 +9003,12 @@ function describePartChanges(before, after, secretRules) {
9003
9003
  };
9004
9004
  const left = index(before);
9005
9005
  const right = index(after);
9006
- const label = (filename) => findSecretInPath(filename, secretRules)?.masked ?? filename;
9006
+ const label2 = (filename) => findSecretInPath(filename, secretRules)?.masked ?? filename;
9007
9007
  const changes = [];
9008
9008
  for (const [filename, part] of right) {
9009
9009
  const previous = left.get(filename);
9010
9010
  if (previous === void 0) {
9011
- changes.push(`part added: ${label(filename)}`);
9011
+ changes.push(`part added: ${label2(filename)}`);
9012
9012
  continue;
9013
9013
  }
9014
9014
  const moved = [];
@@ -9024,10 +9024,10 @@ function describePartChanges(before, after, secretRules) {
9024
9024
  if (previous.fileCount !== part.fileCount) {
9025
9025
  moved.push(`fileCount ${previous.fileCount} \u2192 ${part.fileCount}`);
9026
9026
  }
9027
- if (moved.length > 0) changes.push(`part ${label(filename)}: ${moved.join(", ")}`);
9027
+ if (moved.length > 0) changes.push(`part ${label2(filename)}: ${moved.join(", ")}`);
9028
9028
  }
9029
9029
  for (const filename of left.keys()) {
9030
- if (!right.has(filename)) changes.push(`part removed: ${label(filename)}`);
9030
+ if (!right.has(filename)) changes.push(`part removed: ${label2(filename)}`);
9031
9031
  }
9032
9032
  return changes;
9033
9033
  }
@@ -9141,10 +9141,10 @@ function comparableProblem(value) {
9141
9141
  if (typeof candidate.generatedAt !== "string") return 'no "generatedAt"';
9142
9142
  return null;
9143
9143
  }
9144
- function assertUsableManifest(value, label) {
9144
+ function assertUsableManifest(value, label2) {
9145
9145
  const problem = comparableProblem(value);
9146
9146
  if (problem) {
9147
- throw new Error(`The ${label} manifest is not a snapshot manifest: ${problem}.`);
9147
+ throw new Error(`The ${label2} manifest is not a snapshot manifest: ${problem}.`);
9148
9148
  }
9149
9149
  }
9150
9150
  function compareManifests(before, after, secretRules) {
@@ -9901,17 +9901,17 @@ function diffSectionPaths(body) {
9901
9901
  continue;
9902
9902
  }
9903
9903
  if (line.startsWith("+++ ")) {
9904
- const path33 = wholeLinePath(line.slice(4), "b/");
9905
- if (path33 !== null) paths.add(path33);
9904
+ const path34 = wholeLinePath(line.slice(4), "b/");
9905
+ if (path34 !== null) paths.add(path34);
9906
9906
  continue;
9907
9907
  }
9908
9908
  if (line.startsWith("--- ")) {
9909
- const path33 = wholeLinePath(line.slice(4), "a/");
9910
- if (path33 !== null) paths.add(path33);
9909
+ const path34 = wholeLinePath(line.slice(4), "a/");
9910
+ if (path34 !== null) paths.add(path34);
9911
9911
  }
9912
9912
  }
9913
9913
  if (paths.size === 0 && header2 !== null) {
9914
- for (const path33 of headerPaths(header2)) paths.add(path33);
9914
+ for (const path34 of headerPaths(header2)) paths.add(path34);
9915
9915
  }
9916
9916
  return [...paths];
9917
9917
  }
@@ -9926,7 +9926,7 @@ function filterAndRedactDiff(raw, secretRules, options = {}) {
9926
9926
  omittedUnparseable += 1;
9927
9927
  continue;
9928
9928
  }
9929
- if (paths.some((path33) => isSensitivePath(path33) || options.excluded?.(path33) === true)) {
9929
+ if (paths.some((path34) => isSensitivePath(path34) || options.excluded?.(path34) === true)) {
9930
9930
  omittedSensitive += 1;
9931
9931
  continue;
9932
9932
  }
@@ -9969,7 +9969,7 @@ function generateDiffReport(cwd, options = {}) {
9969
9969
  omittedUnparseable += 1;
9970
9970
  continue;
9971
9971
  }
9972
- const blocked = paths2.some((path33) => isSensitivePath(path33) || options.excluded?.(path33) === true);
9972
+ const blocked = paths2.some((path34) => isSensitivePath(path34) || options.excluded?.(path34) === true);
9973
9973
  if (blocked) {
9974
9974
  omittedSensitive += 1;
9975
9975
  continue;
@@ -10004,7 +10004,7 @@ function generateDiffReport(cwd, options = {}) {
10004
10004
  }
10005
10005
  if (sections.length === 0) return null;
10006
10006
  const paths = /* @__PURE__ */ new Set();
10007
- for (const section of sections) for (const path33 of diffSectionPaths(section)) paths.add(path33);
10007
+ for (const section of sections) for (const path34 of diffSectionPaths(section)) paths.add(path34);
10008
10008
  const joined = [
10009
10009
  "# Uncommitted changes",
10010
10010
  "",
@@ -10119,10 +10119,10 @@ function internalSpecifier(specifier, resolver) {
10119
10119
  }
10120
10120
  function manifestLabel(cwd, manifestPath) {
10121
10121
  if (manifestPath === void 0) return "manifest.json";
10122
- const relative20 = path10.relative(cwd, manifestPath).replace(/\\/g, "/");
10123
- if (relative20.length === 0) return "manifest.json";
10124
- if (relative20.startsWith("../") || path10.isAbsolute(relative20)) return path10.basename(manifestPath);
10125
- return relative20;
10122
+ const relative21 = path10.relative(cwd, manifestPath).replace(/\\/g, "/");
10123
+ if (relative21.length === 0) return "manifest.json";
10124
+ if (relative21.startsWith("../") || path10.isAbsolute(relative21)) return path10.basename(manifestPath);
10125
+ return relative21;
10126
10126
  }
10127
10127
  function isPureBarrel(summary, file) {
10128
10128
  if (summary.parseErrors !== void 0 && summary.parseErrors > 0) return false;
@@ -10519,8 +10519,8 @@ function computeImpact(input) {
10519
10519
  }
10520
10520
  }
10521
10521
  const impacted = /* @__PURE__ */ new Set([...changedSet, ...affected.keys()]);
10522
- for (const path33 of visitedSymbols.keys()) {
10523
- if (!isTestPath(path33) && !isTestSupportPath(path33)) impacted.add(path33);
10522
+ for (const path34 of visitedSymbols.keys()) {
10523
+ if (!isTestPath(path34) && !isTestSupportPath(path34)) impacted.add(path34);
10524
10524
  }
10525
10525
  const tests = [...testHits.entries()].map(([testPath, hit]) => ({
10526
10526
  path: testPath,
@@ -10725,11 +10725,216 @@ function renderImpactText(report2) {
10725
10725
  return lines.join("\n");
10726
10726
  }
10727
10727
 
10728
+ // src/guard.ts
10729
+ import * as path11 from "path";
10730
+ var MAX_CONSUMERS = 10;
10731
+ var MAX_TESTS = 5;
10732
+ var MAX_ROUTES = 5;
10733
+ var MAX_HOOK_CHARS = 1200;
10734
+ function take(values, limit) {
10735
+ return { taken: values.slice(0, limit), omitted: Math.max(0, values.length - limit) };
10736
+ }
10737
+ function toGap(entry) {
10738
+ return {
10739
+ kind: "consumer",
10740
+ path: entry.path,
10741
+ distance: entry.distance,
10742
+ via: entry.via,
10743
+ ...entry.confidence === void 0 ? {} : { confidence: entry.confidence }
10744
+ };
10745
+ }
10746
+ function testGap(entry) {
10747
+ return { kind: "test", path: entry.path, covers: [...entry.covers] };
10748
+ }
10749
+ function routeGap(entry) {
10750
+ return { kind: "route", path: entry.path, methods: [...entry.methods] };
10751
+ }
10752
+ function buildGuardReport(impact) {
10753
+ const changed = impact.changed.filter((entry) => entry.deleted !== true).map((entry) => entry.path);
10754
+ const changedSet = new Set(changed);
10755
+ const consumers = impact.affected.filter((entry) => !changedSet.has(entry.path));
10756
+ const tests = impact.tests.filter((entry) => !changedSet.has(entry.path));
10757
+ const routes = (impact.routesAffected ?? []).filter((entry) => !changedSet.has(entry.path));
10758
+ const consumerPart = take(consumers, MAX_CONSUMERS);
10759
+ const testPart = take(tests, MAX_TESTS);
10760
+ const routePart = take(routes, MAX_ROUTES);
10761
+ const gaps = [
10762
+ ...consumerPart.taken.map(toGap),
10763
+ ...testPart.taken.map(testGap),
10764
+ ...routePart.taken.map(routeGap)
10765
+ ];
10766
+ return {
10767
+ schemaVersion: 1,
10768
+ changed,
10769
+ gaps,
10770
+ trust: impact.trust,
10771
+ truncated: impact.truncated || consumerPart.omitted > 0 || testPart.omitted > 0 || routePart.omitted > 0,
10772
+ omitted: {
10773
+ consumers: consumerPart.omitted,
10774
+ tests: testPart.omitted,
10775
+ routes: routePart.omitted
10776
+ }
10777
+ };
10778
+ }
10779
+ function label(gap) {
10780
+ if (gap.kind === "test") return "test";
10781
+ if (gap.kind === "route") return "route";
10782
+ return "consumer";
10783
+ }
10784
+ function renderGuardText(report2) {
10785
+ if (report2.gaps.length === 0) {
10786
+ return "Change Guard: no gaps in this change.\n changed: " + report2.changed.length + " file(s); coverage: " + report2.trust.coverage + "\n";
10787
+ }
10788
+ const lines = [];
10789
+ lines.push("Change Guard: " + report2.gaps.length + " gap(s) in this change");
10790
+ for (const gap of report2.gaps) {
10791
+ const parts = [gap.path];
10792
+ if (gap.kind === "consumer") {
10793
+ const meta = [];
10794
+ if (gap.distance !== void 0) meta.push(gap.distance + " hop" + (gap.distance === 1 ? "" : "s"));
10795
+ if (gap.confidence !== void 0) meta.push(gap.confidence);
10796
+ if (gap.via !== void 0) meta.push("via " + gap.via);
10797
+ if (meta.length > 0) parts.push("(" + meta.join(", ") + ")");
10798
+ } else if (gap.kind === "test") {
10799
+ parts.push("(test" + (gap.covers && gap.covers.length > 0 ? ": " + gap.covers.join(", ") : "") + ")");
10800
+ } else {
10801
+ parts.push("(route" + (gap.methods && gap.methods.length > 0 ? ": " + gap.methods.join(", ") : "") + ")");
10802
+ }
10803
+ lines.push(" " + label(gap).padEnd(9) + parts.join(" "));
10804
+ }
10805
+ if (report2.truncated) {
10806
+ const omitted = report2.omitted;
10807
+ lines.push(
10808
+ " \u2026 truncated: " + omitted.consumers + " consumer(s), " + omitted.tests + " test(s), " + omitted.routes + " route(s) omitted"
10809
+ );
10810
+ }
10811
+ lines.push(" coverage: " + report2.trust.coverage + " \xB7 confidence: symbol-pruned");
10812
+ return lines.join("\n");
10813
+ }
10814
+ function truncateGuardText(text2, maxChars) {
10815
+ if (text2.length <= maxChars) return text2;
10816
+ const marker2 = "\n\u2026 run codebase-snapshot guard --changed for the full list";
10817
+ const room = Math.max(0, maxChars - marker2.length);
10818
+ return text2.slice(0, room).trimEnd() + marker2;
10819
+ }
10820
+ function renderGuardHookText(report2, maxChars = MAX_HOOK_CHARS) {
10821
+ if (report2.gaps.length === 0) return "";
10822
+ const lines = ["[change-guard] " + report2.gaps.length + " gap(s) in this change:"];
10823
+ for (const gap of report2.gaps) {
10824
+ if (gap.kind === "consumer") {
10825
+ lines.push(
10826
+ " " + gap.path + (gap.distance === void 0 ? "" : " (" + gap.distance + " hop" + (gap.distance === 1 ? "" : "s") + ")")
10827
+ );
10828
+ } else if (gap.kind === "test") {
10829
+ lines.push(" test " + gap.path);
10830
+ } else {
10831
+ lines.push(" route " + gap.path + (gap.methods && gap.methods.length > 0 ? " (" + gap.methods.join(", ") + ")" : ""));
10832
+ }
10833
+ }
10834
+ lines.push("coverage: " + report2.trust.coverage + " \xB7 confidence: symbol-pruned");
10835
+ lines.push("run: npx codebase-snapshot brief --diff HEAD");
10836
+ return truncateGuardText(lines.join("\n"), maxChars);
10837
+ }
10838
+ function renderGuardHook(report2, client, event, maxChars = MAX_HOOK_CHARS) {
10839
+ const text2 = renderGuardHookText(report2, maxChars);
10840
+ if (text2.length === 0) return "{}";
10841
+ if (client === "claude") {
10842
+ return JSON.stringify({
10843
+ hookSpecificOutput: {
10844
+ hookEventName: event,
10845
+ additionalContext: text2
10846
+ }
10847
+ });
10848
+ }
10849
+ return JSON.stringify({ additionalContext: text2 });
10850
+ }
10851
+ function normalizePath(cwd, raw) {
10852
+ const value = raw.trim();
10853
+ if (value.length === 0 || value.includes("\0")) return null;
10854
+ const absolute = path11.isAbsolute(value) ? value : path11.resolve(cwd, value);
10855
+ const relative21 = path11.relative(cwd, absolute).split(path11.sep).join("/");
10856
+ if (relative21 === "" || relative21 === ".." || relative21.startsWith("../") || path11.isAbsolute(relative21)) {
10857
+ return null;
10858
+ }
10859
+ return relative21;
10860
+ }
10861
+ function collectPaths(value, out, depth = 0) {
10862
+ if (depth > 6 || value === null || typeof value !== "object") return;
10863
+ if (Array.isArray(value)) {
10864
+ for (const item of value) collectPaths(item, out, depth + 1);
10865
+ return;
10866
+ }
10867
+ const record = value;
10868
+ for (const [key, item] of Object.entries(record)) {
10869
+ if (typeof item === "string" && /^(file_path|filePath|path|file|filename|fileName)$/i.test(key)) {
10870
+ out.add(item);
10871
+ continue;
10872
+ }
10873
+ if (Array.isArray(item) && /^(files|paths|file_paths|filePaths)$/i.test(key)) {
10874
+ for (const entry of item) if (typeof entry === "string") out.add(entry);
10875
+ continue;
10876
+ }
10877
+ if (typeof item === "object" && item !== null) collectPaths(item, out, depth + 1);
10878
+ }
10879
+ }
10880
+ function parseGuardHookInput(client, raw, cwd) {
10881
+ let payload;
10882
+ try {
10883
+ payload = JSON.parse(raw);
10884
+ } catch {
10885
+ throw new Error("guard --hook expects one JSON object on stdin.");
10886
+ }
10887
+ if (payload === null || typeof payload !== "object" || Array.isArray(payload)) {
10888
+ throw new Error("guard --hook expects one JSON object on stdin.");
10889
+ }
10890
+ const record = payload;
10891
+ const candidates = /* @__PURE__ */ new Set();
10892
+ if (client === "claude") {
10893
+ const toolInput = record.tool_input;
10894
+ if (toolInput !== null && typeof toolInput === "object") collectPaths(toolInput, candidates);
10895
+ const toolResponse = record.tool_response;
10896
+ if (toolResponse !== null && typeof toolResponse === "object") collectPaths(toolResponse, candidates);
10897
+ if (typeof record.file_path === "string") candidates.add(record.file_path);
10898
+ } else if (client === "copilot") {
10899
+ if (typeof record.toolArgs === "string") {
10900
+ try {
10901
+ collectPaths(JSON.parse(record.toolArgs), candidates);
10902
+ } catch {
10903
+ }
10904
+ } else if (record.toolArgs !== null && typeof record.toolArgs === "object") {
10905
+ collectPaths(record.toolArgs, candidates);
10906
+ }
10907
+ if (record.tool_input !== null && typeof record.tool_input === "object") {
10908
+ collectPaths(record.tool_input, candidates);
10909
+ }
10910
+ } else {
10911
+ if (record.tool_input !== null && typeof record.tool_input === "object") {
10912
+ collectPaths(record.tool_input, candidates);
10913
+ }
10914
+ if (record.toolArgs !== null && typeof record.toolArgs === "object") {
10915
+ collectPaths(record.toolArgs, candidates);
10916
+ }
10917
+ if (typeof record.path === "string") candidates.add(record.path);
10918
+ }
10919
+ const paths = [];
10920
+ for (const candidate of candidates) {
10921
+ const normalized = normalizePath(cwd, candidate);
10922
+ if (normalized !== null) paths.push(normalized);
10923
+ }
10924
+ const sessionId = typeof record.session_id === "string" ? record.session_id : typeof record.sessionId === "string" ? record.sessionId : void 0;
10925
+ const event = typeof record.hook_event_name === "string" ? record.hook_event_name : typeof record.hookEventName === "string" ? record.hookEventName : "PostToolUse";
10926
+ return {
10927
+ paths: [...new Set(paths)].sort((left, right) => left.localeCompare(right)),
10928
+ ...sessionId === void 0 ? {} : { sessionId },
10929
+ event
10930
+ };
10931
+ }
10932
+
10728
10933
  // src/live-index.ts
10729
10934
  import { execFileSync as execFileSync5 } from "child_process";
10730
10935
  import * as crypto7 from "crypto";
10731
10936
  import * as fs28 from "fs";
10732
- import * as path30 from "path";
10937
+ import * as path31 from "path";
10733
10938
 
10734
10939
  // src/index.ts
10735
10940
  import * as crypto6 from "crypto";
@@ -10799,7 +11004,7 @@ async function runWithStdoutCapture(fn) {
10799
11004
  // src/index.ts
10800
11005
  import * as fs27 from "fs";
10801
11006
  import * as os3 from "os";
10802
- import * as path29 from "path";
11007
+ import * as path30 from "path";
10803
11008
 
10804
11009
  // src/ast/skeleton.ts
10805
11010
  import ts3 from "typescript";
@@ -11408,12 +11613,12 @@ function planForQuestion(manifest, question, options = {}) {
11408
11613
  const scored = [];
11409
11614
  for (const file of manifest.files) {
11410
11615
  if (isTest(file) && !wantsTests) continue;
11411
- const path33 = file.relativePath.toLowerCase();
11412
- const words = path33.split(/[^a-z0-9_]+/).filter((word) => word.length >= 3);
11616
+ const path34 = file.relativePath.toLowerCase();
11617
+ const words = path34.split(/[^a-z0-9_]+/).filter((word) => word.length >= 3);
11413
11618
  let score = 0;
11414
11619
  const reasons = [];
11415
11620
  for (const term of terms) {
11416
- if (path33.includes(term)) {
11621
+ if (path34.includes(term)) {
11417
11622
  score += 8;
11418
11623
  reasons.push("path:" + term);
11419
11624
  continue;
@@ -11470,7 +11675,7 @@ function planForQuestion(manifest, question, options = {}) {
11470
11675
  const chosen = /* @__PURE__ */ new Map();
11471
11676
  const skipped = [];
11472
11677
  let used = 0;
11473
- const take = (file, why, mode) => {
11678
+ const take2 = (file, why, mode) => {
11474
11679
  const existing = chosen.get(file.relativePath);
11475
11680
  if (existing !== void 0) return false;
11476
11681
  const tokens = tokensOf(file);
@@ -11491,11 +11696,11 @@ function planForQuestion(manifest, question, options = {}) {
11491
11696
  for (const item of scored) {
11492
11697
  const tokens = tokensOf(item.file);
11493
11698
  if (used + tokens <= budget) {
11494
- take(item.file, item.why, "full");
11699
+ take2(item.file, item.why, "full");
11495
11700
  continue;
11496
11701
  }
11497
11702
  if (tokens <= budget * 2 && used + Math.ceil(tokens / 2) <= budget) {
11498
- take(item.file, item.why, "head");
11703
+ take2(item.file, item.why, "head");
11499
11704
  continue;
11500
11705
  }
11501
11706
  skipped.push({ path: item.file.relativePath, reason: "does not fit the remaining budget" });
@@ -11508,8 +11713,8 @@ function planForQuestion(manifest, question, options = {}) {
11508
11713
  const target = byPath.get(targetPath2);
11509
11714
  if (target === void 0 || chosen.has(target.relativePath)) continue;
11510
11715
  if (isTest(target) && !wantsTests) continue;
11511
- if (!take(target, "imported by " + seed.path, "full")) {
11512
- if (!take(target, "imported by " + seed.path, "head")) {
11716
+ if (!take2(target, "imported by " + seed.path, "full")) {
11717
+ if (!take2(target, "imported by " + seed.path, "head")) {
11513
11718
  skipped.push({ path: target.relativePath, reason: "does not fit the remaining budget" });
11514
11719
  }
11515
11720
  }
@@ -11523,9 +11728,9 @@ function planForQuestion(manifest, question, options = {}) {
11523
11728
  const file = byPath.get(caller);
11524
11729
  if (file === void 0) continue;
11525
11730
  if (isTest(file) && !wantsTests) continue;
11526
- if (take(file, "imports " + seed.path, "full")) {
11731
+ if (take2(file, "imports " + seed.path, "full")) {
11527
11732
  callerBudget -= 1;
11528
- } else if (take(file, "imports " + seed.path, "head")) {
11733
+ } else if (take2(file, "imports " + seed.path, "head")) {
11529
11734
  callerBudget -= 1;
11530
11735
  }
11531
11736
  }
@@ -11889,7 +12094,7 @@ function systemSection(manifest, code, brief, escape, sawManifest) {
11889
12094
  " A change here reaches the most call sites; read it before judging anything that uses it."
11890
12095
  );
11891
12096
  }
11892
- const entryPoints = manifest.files.map((file) => file.relativePath).filter((path33) => ENTRY_POINT.test(path33)).sort((a, b) => a.split("/").length - b.split("/").length || a.length - b.length).slice(0, MAX_ENTRY_POINTS);
12097
+ const entryPoints = manifest.files.map((file) => file.relativePath).filter((path34) => ENTRY_POINT.test(path34)).sort((a, b) => a.split("/").length - b.split("/").length || a.length - b.length).slice(0, MAX_ENTRY_POINTS);
11893
12098
  out.push(
11894
12099
  entryPoints.length > 0 ? "- Entry points by convention: " + entryPoints.map(code).join(", ") + "." : "- No entry point was identifiable by name. The largest files below are where execution"
11895
12100
  );
@@ -12124,8 +12329,8 @@ function ownerNotesSection(brief, code, text2) {
12124
12329
  }
12125
12330
  return out;
12126
12331
  }
12127
- function ownerBlock(body, path33, code, escape) {
12128
- return ["> Written by the project owner in " + code(path33) + ", not generated.", "", escape(body)];
12332
+ function ownerBlock(body, path34, code, escape) {
12333
+ return ["> Written by the project owner in " + code(path34) + ", not generated.", "", escape(body)];
12129
12334
  }
12130
12335
  function snapshotSection(manifest, code, partsWritten) {
12131
12336
  const out = ["## This snapshot", ""];
@@ -12409,8 +12614,8 @@ function generateProjectTree(filePaths) {
12409
12614
  const isLast = frame.index === frame.keys.length;
12410
12615
  const child = frame.node.children.get(key);
12411
12616
  const isDirectory = child.children.size > 0;
12412
- const label = escapeControls(key);
12413
- lines.push(`${frame.prefix}${isLast ? "\u2514\u2500\u2500 " : "\u251C\u2500\u2500 "}${label}${isDirectory ? "/" : ""}`);
12617
+ const label2 = escapeControls(key);
12618
+ lines.push(`${frame.prefix}${isLast ? "\u2514\u2500\u2500 " : "\u251C\u2500\u2500 "}${label2}${isDirectory ? "/" : ""}`);
12414
12619
  if (lines.length >= MAX_TREE_LINES) {
12415
12620
  truncatedAt = lines.length;
12416
12621
  break;
@@ -12463,8 +12668,8 @@ function readProjectOverview(cwd) {
12463
12668
  releases: readReleases(cwd)
12464
12669
  };
12465
12670
  }
12466
- function readText(cwd, relative20) {
12467
- const read = readConfinedText(cwd, relative20);
12671
+ function readText(cwd, relative21) {
12672
+ const read = readConfinedText(cwd, relative21);
12468
12673
  return read.ok ? read.text : null;
12469
12674
  }
12470
12675
  function readDescription(cwd) {
@@ -12521,7 +12726,7 @@ function readReleases(cwd) {
12521
12726
  }
12522
12727
 
12523
12728
  // src/scanner/language.ts
12524
- import * as path11 from "path";
12729
+ import * as path12 from "path";
12525
12730
  var LANGUAGE_BY_EXTENSION = {
12526
12731
  ".ts": "typescript",
12527
12732
  ".mts": "typescript",
@@ -12579,17 +12784,17 @@ var LANGUAGE_BY_BASENAME = {
12579
12784
  };
12580
12785
  function detectLanguage(filePath) {
12581
12786
  const normalized = filePath.replace(/\\/g, "/");
12582
- const base = path11.posix.basename(normalized);
12787
+ const base = path12.posix.basename(normalized);
12583
12788
  if (LANGUAGE_BY_BASENAME[base]) return LANGUAGE_BY_BASENAME[base];
12584
12789
  if (base === ".env" || base.startsWith(".env.")) return "dotenv";
12585
- const ext = path11.posix.extname(base).toLowerCase();
12790
+ const ext = path12.posix.extname(base).toLowerCase();
12586
12791
  return LANGUAGE_BY_EXTENSION[ext] ?? "text";
12587
12792
  }
12588
12793
 
12589
12794
  // src/remote/source.ts
12590
12795
  import * as fs12 from "fs";
12591
12796
  import * as os from "os";
12592
- import * as path12 from "path";
12797
+ import * as path13 from "path";
12593
12798
  import { spawn } from "child_process";
12594
12799
  import { lookup } from "dns/promises";
12595
12800
  import { fileURLToPath } from "url";
@@ -12704,7 +12909,7 @@ function parseRemoteSource(input, options = {}) {
12704
12909
  const directory = fileURLToPath(url2);
12705
12910
  return {
12706
12911
  ok: true,
12707
- source: { kind: "file", url: trimmed, host: "file", owner: "", repo: path12.basename(directory), ref: null }
12912
+ source: { kind: "file", url: trimmed, host: "file", owner: "", repo: path13.basename(directory), ref: null }
12708
12913
  };
12709
12914
  }
12710
12915
  let url;
@@ -12759,7 +12964,7 @@ async function assertPublicHost(host, allowPrivate) {
12759
12964
  }
12760
12965
  }
12761
12966
  function runGitAsync(args, options) {
12762
- return new Promise((resolve21) => {
12967
+ return new Promise((resolve22) => {
12763
12968
  let child;
12764
12969
  try {
12765
12970
  child = spawn("git", args, {
@@ -12768,7 +12973,7 @@ function runGitAsync(args, options) {
12768
12973
  stdio: ["ignore", "pipe", "pipe"]
12769
12974
  });
12770
12975
  } catch (error) {
12771
- resolve21({
12976
+ resolve22({
12772
12977
  status: null,
12773
12978
  stdout: "",
12774
12979
  stderr: "",
@@ -12793,7 +12998,7 @@ function runGitAsync(args, options) {
12793
12998
  settled = true;
12794
12999
  if (timer !== void 0) clearTimeout(timer);
12795
13000
  if (killTimer !== void 0) clearTimeout(killTimer);
12796
- resolve21({ status, stdout, stderr, timedOut, error });
13001
+ resolve22({ status, stdout, stderr, timedOut, error });
12797
13002
  };
12798
13003
  child.stdout?.on("data", (chunk) => {
12799
13004
  stdout = append(stdout, chunk);
@@ -12840,7 +13045,7 @@ function gitEnvironment(token, host) {
12840
13045
  async function cloneRepository(source, options) {
12841
13046
  const log = options.log ?? (() => {
12842
13047
  });
12843
- const dest = path12.resolve(options.dest);
13048
+ const dest = path13.resolve(options.dest);
12844
13049
  fs12.rmSync(dest, { recursive: true, force: true });
12845
13050
  fs12.mkdirSync(dest, { recursive: true });
12846
13051
  try {
@@ -12923,7 +13128,7 @@ function directorySize(root) {
12923
13128
  continue;
12924
13129
  }
12925
13130
  for (const entry of entries) {
12926
- const full = path12.join(current, entry.name);
13131
+ const full = path13.join(current, entry.name);
12927
13132
  if (entry.isDirectory()) stack.push(full);
12928
13133
  else if (entry.isFile()) {
12929
13134
  try {
@@ -12936,13 +13141,13 @@ function directorySize(root) {
12936
13141
  return total;
12937
13142
  }
12938
13143
  function makeCloneDirectory() {
12939
- return fs12.mkdtempSync(path12.join(os.tmpdir(), "codebase-snapshot-clone-"));
13144
+ return fs12.mkdtempSync(path13.join(os.tmpdir(), "codebase-snapshot-clone-"));
12940
13145
  }
12941
13146
 
12942
13147
  // src/web/server.ts
12943
13148
  import * as http2 from "http";
12944
13149
  import * as fs19 from "fs";
12945
- import * as path21 from "path";
13150
+ import * as path22 from "path";
12946
13151
  import { randomBytes as randomBytes2, timingSafeEqual as timingSafeEqual3 } from "crypto";
12947
13152
 
12948
13153
  // src/mcp/http.ts
@@ -13161,23 +13366,23 @@ function negotiateLegacyVersion(requested) {
13161
13366
 
13162
13367
  // src/mcp/resources.ts
13163
13368
  import * as fs17 from "fs";
13164
- import * as path19 from "path";
13369
+ import * as path20 from "path";
13165
13370
 
13166
13371
  // src/mcp/tools.ts
13167
13372
  import * as fs16 from "fs";
13168
- import * as path18 from "path";
13373
+ import * as path19 from "path";
13169
13374
  import { randomUUID } from "crypto";
13170
13375
 
13171
13376
  // src/explain.ts
13172
13377
  import * as fs13 from "fs";
13173
- import * as path13 from "path";
13378
+ import * as path14 from "path";
13174
13379
  function safeRegularFile(cwd, absolute) {
13175
13380
  try {
13176
13381
  if (!fs13.lstatSync(absolute).isFile()) return false;
13177
13382
  const root = fs13.realpathSync(cwd);
13178
13383
  const real = fs13.realpathSync(absolute);
13179
- const relative20 = path13.relative(root, real);
13180
- return relative20 !== ".." && !relative20.startsWith(".." + path13.sep) && !path13.isAbsolute(relative20);
13384
+ const relative21 = path14.relative(root, real);
13385
+ return relative21 !== ".." && !relative21.startsWith(".." + path14.sep) && !path14.isAbsolute(relative21);
13181
13386
  } catch {
13182
13387
  return false;
13183
13388
  }
@@ -13191,32 +13396,32 @@ function describeMatcher(matcher) {
13191
13396
  return String(matcher);
13192
13397
  }
13193
13398
  function normalizeTarget2(cwd, target) {
13194
- const resolvedCwd = path13.resolve(cwd);
13195
- const absolute = path13.resolve(resolvedCwd, target);
13196
- const relative20 = path13.relative(resolvedCwd, absolute);
13197
- if (relative20 === "" || relative20 === ".." || relative20.startsWith(`..${path13.sep}`) || path13.isAbsolute(relative20)) {
13399
+ const resolvedCwd = path14.resolve(cwd);
13400
+ const absolute = path14.resolve(resolvedCwd, target);
13401
+ const relative21 = path14.relative(resolvedCwd, absolute);
13402
+ if (relative21 === "" || relative21 === ".." || relative21.startsWith(`..${path14.sep}`) || path14.isAbsolute(relative21)) {
13198
13403
  return { relative: target.replace(/\\/g, "/"), outsideRoot: true };
13199
13404
  }
13200
- return { relative: relative20.split(path13.sep).join("/"), outsideRoot: false };
13405
+ return { relative: relative21.split(path14.sep).join("/"), outsideRoot: false };
13201
13406
  }
13202
13407
  function findRuleMatch(rules, relativePath) {
13203
13408
  return rules.find(
13204
13409
  (rule) => matchRule(relativePath, rule.match)
13205
13410
  );
13206
13411
  }
13207
- function findRecordedAncestor(skipped, relative20, maskedPath2) {
13412
+ function findRecordedAncestor(skipped, relative21, maskedPath2) {
13208
13413
  let nearest;
13209
13414
  for (const record of skipped) {
13210
13415
  const ancestorPath = record.path;
13211
13416
  if (ancestorPath.length === 0) continue;
13212
- const isAncestor = relative20.startsWith(`${ancestorPath}/`) || maskedPath2.startsWith(`${ancestorPath}/`);
13417
+ const isAncestor = relative21.startsWith(`${ancestorPath}/`) || maskedPath2.startsWith(`${ancestorPath}/`);
13213
13418
  if (!isAncestor) continue;
13214
13419
  if (!nearest || ancestorPath.length > nearest.path.length) nearest = record;
13215
13420
  }
13216
13421
  return nearest;
13217
13422
  }
13218
13423
  function readManifest2(config) {
13219
- const manifestPath = path13.resolve(config.cwd, config.outDir, "manifest.json");
13424
+ const manifestPath = path14.resolve(config.cwd, config.outDir, "manifest.json");
13220
13425
  try {
13221
13426
  return JSON.parse(fs13.readFileSync(manifestPath, "utf8"));
13222
13427
  } catch {
@@ -13225,8 +13430,8 @@ function readManifest2(config) {
13225
13430
  }
13226
13431
  function explainPath(config, target) {
13227
13432
  const normalized = normalizeTarget2(config.cwd, target);
13228
- const relative20 = normalized.relative;
13229
- const maskedPath2 = findSecretInPath(relative20, config.secretRules)?.masked ?? relative20;
13433
+ const relative21 = normalized.relative;
13434
+ const maskedPath2 = findSecretInPath(relative21, config.secretRules)?.masked ?? relative21;
13230
13435
  if (normalized.outsideRoot) {
13231
13436
  return {
13232
13437
  path: maskedPath2,
@@ -13236,8 +13441,8 @@ function explainPath(config, target) {
13236
13441
  detail: "path resolves outside the configured repository root and was not inspected"
13237
13442
  };
13238
13443
  }
13239
- const absolute = path13.join(config.cwd, relative20);
13240
- const stagedBlob = config.staged === true ? readStagedBlob(config.cwd, relative20) : null;
13444
+ const absolute = path14.join(config.cwd, relative21);
13445
+ const stagedBlob = config.staged === true ? readStagedBlob(config.cwd, relative21) : null;
13241
13446
  const result = {
13242
13447
  path: maskedPath2,
13243
13448
  // `existsSync` follows a symlink, so an in-repo link to /etc/passwd answered "exists" for a
@@ -13256,18 +13461,18 @@ function explainPath(config, target) {
13256
13461
  discovery: config.discovery,
13257
13462
  // A staged file that is absent from the working tree is still a candidate: `generate --staged`
13258
13463
  // reads its index blob, and `explain --staged` has to explain that same selection.
13259
- ...stagedBlob === null ? {} : { extraPaths: [relative20] },
13464
+ ...stagedBlob === null ? {} : { extraPaths: [relative21] },
13260
13465
  // Same exclusion `generate` applies, so `explain` never says "not-discovered" about a file
13261
13466
  // that is only missing because the walker dropped the tool's own output directory.
13262
13467
  toolOwnedPaths: [config.outDir, config.tmpDir].map(
13263
- (directory) => path13.relative(config.cwd, path13.resolve(config.cwd, directory)).replace(/\\/g, "/")
13468
+ (directory) => path14.relative(config.cwd, path14.resolve(config.cwd, directory)).replace(/\\/g, "/")
13264
13469
  ).filter(
13265
- (relative21) => relative21.length > 0 && relative21 !== ".." && !relative21.startsWith(`..${path13.sep}`) && !relative21.startsWith("../") && !path13.isAbsolute(relative21)
13470
+ (relative22) => relative22.length > 0 && relative22 !== ".." && !relative22.startsWith(`..${path14.sep}`) && !relative22.startsWith("../") && !path14.isAbsolute(relative22)
13266
13471
  )
13267
13472
  });
13268
- if (!collection.files.includes(relative20)) {
13473
+ if (!collection.files.includes(relative21)) {
13269
13474
  const record = collection.skipped.find(
13270
- (entry2) => entry2.path === relative20 || entry2.path === maskedPath2
13475
+ (entry2) => entry2.path === relative21 || entry2.path === maskedPath2
13271
13476
  );
13272
13477
  if (record) {
13273
13478
  result.reason = record.reason;
@@ -13276,7 +13481,7 @@ function explainPath(config, target) {
13276
13481
  result.reason = "missing";
13277
13482
  result.detail = "no such file or directory, relative to the configured cwd";
13278
13483
  } else {
13279
- const ancestor = findRecordedAncestor(collection.skipped, relative20, maskedPath2);
13484
+ const ancestor = findRecordedAncestor(collection.skipped, relative21, maskedPath2);
13280
13485
  if (ancestor) {
13281
13486
  result.reason = ancestor.reason;
13282
13487
  result.detail = ancestor.detail ? `${ancestor.detail} \u2014 inherited from the skipped directory \`${ancestor.path}\`` : `inside the skipped directory \`${ancestor.path}\``;
@@ -13296,12 +13501,12 @@ function explainPath(config, target) {
13296
13501
  ...config.changedSince === void 0 ? {} : { changedSince: config.changedSince },
13297
13502
  ...config.staged === true ? { staged: true } : {}
13298
13503
  });
13299
- inScope = scope.paths.has(relative20);
13504
+ inScope = scope.paths.has(relative21);
13300
13505
  if (!inScope && config.withDependents === true) {
13301
13506
  const workspace = workspaceResolutionFor(config.cwd, collection.files);
13302
- const imports = stagedBlob !== null ? importsOfText(relative20, decodeText(stagedBlob).text) : importsOfFile(relative20, absolute);
13507
+ const imports = stagedBlob !== null ? importsOfText(relative21, decodeText(stagedBlob).text) : importsOfFile(relative21, absolute);
13303
13508
  inScope = importsChangedFile(
13304
- relative20,
13509
+ relative21,
13305
13510
  imports,
13306
13511
  scope.paths,
13307
13512
  buildImportResolver(collection.files.map((file) => ({ relativePath: file })), {
@@ -13366,15 +13571,15 @@ function explainPath(config, target) {
13366
13571
  result.bytes = buffer.length;
13367
13572
  result.lines = countLines(text2);
13368
13573
  if (decoded.encoding !== "utf-8") result.encoding = decoded.encoding;
13369
- const { findings } = scanAndRedactSecrets(text2, config.secretRules, relative20);
13574
+ const { findings } = scanAndRedactSecrets(text2, config.secretRules, relative21);
13370
13575
  result.secretCount = findings.length;
13371
13576
  result.secrets = findings.slice(0, 20).map((finding) => ({ rules: finding.rules, line: finding.line }));
13372
13577
  let inclusionMode = "full";
13373
- if (config.skeleton === true && isSkeletonizable(relative20)) {
13374
- const skeleton = skeletonizeTypeScript(text2, relative20);
13578
+ if (config.skeleton === true && isSkeletonizable(relative21)) {
13579
+ const skeleton = skeletonizeTypeScript(text2, relative21);
13375
13580
  if (skeleton.collapsed > 0) inclusionMode = "signatures";
13376
13581
  }
13377
- if (inclusionMode === "full" && config.stripComments === true && isCommentStrippable(relative20) && stripComments2(text2, relative20).removed > 0) {
13582
+ if (inclusionMode === "full" && config.stripComments === true && isCommentStrippable(relative21) && stripComments2(text2, relative21).removed > 0) {
13378
13583
  inclusionMode = "comments-stripped";
13379
13584
  }
13380
13585
  if (inclusionMode !== "signatures" && buffer.length > config.largeFileBytes) {
@@ -13383,18 +13588,18 @@ function explainPath(config, target) {
13383
13588
  }
13384
13589
  result.inclusionMode = inclusionMode;
13385
13590
  }
13386
- result.layer = classifyLayer(relative20, config.layers);
13387
- result.kind = classifyKind(relative20, config.kinds);
13388
- result.language = detectLanguage(relative20);
13389
- const layerRule = findRuleMatch(config.layers, relative20);
13591
+ result.layer = classifyLayer(relative21, config.layers);
13592
+ result.kind = classifyKind(relative21, config.kinds);
13593
+ result.language = detectLanguage(relative21);
13594
+ const layerRule = findRuleMatch(config.layers, relative21);
13390
13595
  if (layerRule) result.layerMatch = describeMatcher(layerRule.match);
13391
- const kindRule = findRuleMatch(config.kinds, relative20);
13596
+ const kindRule = findRuleMatch(config.kinds, relative21);
13392
13597
  if (kindRule) result.kindMatch = describeMatcher(kindRule.match);
13393
13598
  const manifest = readManifest2(config);
13394
- const entry = Array.isArray(manifest?.files) ? manifest.files.find((file) => file.relativePath === relative20) : void 0;
13599
+ const entry = Array.isArray(manifest?.files) ? manifest.files.find((file) => file.relativePath === relative21) : void 0;
13395
13600
  result.part = entry?.part ?? null;
13396
13601
  if (entry === void 0) {
13397
- const record = manifest?.skipped?.find((skip) => skip.path === relative20);
13602
+ const record = manifest?.skipped?.find((skip) => skip.path === relative21);
13398
13603
  if (record !== void 0 && (record.reason === "not-selected" || record.reason === "unchanged")) {
13399
13604
  result.included = false;
13400
13605
  for (const key of [
@@ -13421,7 +13626,7 @@ function explainPath(config, target) {
13421
13626
  }
13422
13627
  function renderExplainText(result) {
13423
13628
  const lines = [escapeControls(result.path), ""];
13424
- const row = (label, value) => ` ${label.padEnd(11)}${escapeControls(value)}`;
13629
+ const row = (label2, value) => ` ${label2.padEnd(11)}${escapeControls(value)}`;
13425
13630
  if (!result.included) {
13426
13631
  lines.push(row("included", "no"));
13427
13632
  lines.push(row("reason", result.reason ?? "unknown"));
@@ -13456,55 +13661,55 @@ function renderExplainText(result) {
13456
13661
 
13457
13662
  // src/ast/ts-program.ts
13458
13663
  import * as fs14 from "fs";
13459
- import * as path14 from "path";
13664
+ import * as path15 from "path";
13460
13665
  import { createRequire as createRequire2 } from "module";
13461
13666
  import ts5 from "typescript";
13462
13667
  var requireFromHere = createRequire2(import.meta.url);
13463
- var TYPESCRIPT_LIB_DIR = path14.dirname(requireFromHere.resolve("typescript"));
13668
+ var TYPESCRIPT_LIB_DIR = path15.dirname(requireFromHere.resolve("typescript"));
13464
13669
  var DEFAULT_MAX_PROGRAM_FILES = 2500;
13465
13670
  var DEFAULT_TIMEOUT_MS = 4e3;
13466
13671
  var MAX_REFERENCES = 5e3;
13467
13672
  var SOURCE_EXTENSIONS2 = /* @__PURE__ */ new Set([".ts", ".tsx", ".mts", ".cts", ".js", ".jsx", ".mjs", ".cjs"]);
13468
13673
  var CASE_INSENSITIVE_PATHS = process.platform === "win32" || process.platform === "darwin";
13469
13674
  function foldPathKey(value) {
13470
- return CASE_INSENSITIVE_PATHS ? path14.resolve(value).toLowerCase() : path14.resolve(value);
13675
+ return CASE_INSENSITIVE_PATHS ? path15.resolve(value).toLowerCase() : path15.resolve(value);
13471
13676
  }
13472
13677
  function canonicalRoot(root) {
13473
13678
  try {
13474
13679
  return fs14.realpathSync(root);
13475
13680
  } catch {
13476
- return path14.resolve(root);
13681
+ return path15.resolve(root);
13477
13682
  }
13478
13683
  }
13479
13684
  function inside(parent, child) {
13480
- const relative20 = path14.relative(foldPathKey(parent), foldPathKey(child));
13481
- return relative20 === "" || relative20 !== ".." && !relative20.startsWith(".." + path14.sep) && !path14.isAbsolute(relative20);
13685
+ const relative21 = path15.relative(foldPathKey(parent), foldPathKey(child));
13686
+ return relative21 === "" || relative21 !== ".." && !relative21.startsWith(".." + path15.sep) && !path15.isAbsolute(relative21);
13482
13687
  }
13483
13688
  function canonicalCandidate(root, candidate) {
13484
- const absolute = path14.isAbsolute(candidate) ? candidate : path14.resolve(root, candidate);
13689
+ const absolute = path15.isAbsolute(candidate) ? candidate : path15.resolve(root, candidate);
13485
13690
  if (!inside(root, absolute)) return null;
13486
13691
  try {
13487
13692
  const stat = fs14.lstatSync(absolute);
13488
13693
  if (!stat.isFile() && !stat.isSymbolicLink()) return null;
13489
13694
  const real = fs14.realpathSync(absolute);
13490
13695
  if (!inside(root, real)) return null;
13491
- const relative20 = path14.relative(root, real).replace(/\\/g, "/");
13492
- if (isSensitivePath(relative20)) return null;
13696
+ const relative21 = path15.relative(root, real).replace(/\\/g, "/");
13697
+ if (isSensitivePath(relative21)) return null;
13493
13698
  return real;
13494
13699
  } catch {
13495
13700
  return null;
13496
13701
  }
13497
13702
  }
13498
13703
  function isTypeScriptLib(file) {
13499
- const absolute = path14.isAbsolute(file) ? file : path14.resolve(TYPESCRIPT_LIB_DIR, file);
13500
- return inside(TYPESCRIPT_LIB_DIR, absolute) && /^lib(?:\.[^/\\]+)?\.d\.ts$/.test(path14.basename(absolute));
13704
+ const absolute = path15.isAbsolute(file) ? file : path15.resolve(TYPESCRIPT_LIB_DIR, file);
13705
+ return inside(TYPESCRIPT_LIB_DIR, absolute) && /^lib(?:\.[^/\\]+)?\.d\.ts$/.test(path15.basename(absolute));
13501
13706
  }
13502
13707
  function compilerOptionsFor(root) {
13503
13708
  let loaded = {};
13504
13709
  const configFile = ["tsconfig.json", "jsconfig.json"].find(
13505
13710
  (name) => readConfinedText(root, name, 4 * 1024 * 1024).ok
13506
13711
  );
13507
- const configPath = configFile === void 0 ? null : path14.join(root, configFile);
13712
+ const configPath = configFile === void 0 ? null : path15.join(root, configFile);
13508
13713
  const read = configFile === void 0 ? null : readConfinedText(root, configFile, 4 * 1024 * 1024);
13509
13714
  if (read !== null && read.ok && configPath !== null) {
13510
13715
  const parsed = ts5.parseConfigFileTextToJson(configPath, read.text);
@@ -13513,13 +13718,13 @@ function compilerOptionsFor(root) {
13513
13718
  useCaseSensitiveFileNames: ts5.sys.useCaseSensitiveFileNames,
13514
13719
  readDirectory: () => [],
13515
13720
  fileExists: (file) => {
13516
- const relative20 = path14.relative(root, file).replace(/\\/g, "/");
13517
- return relative20.length > 0 && !isSensitivePath(relative20) && readConfinedText(root, relative20).ok;
13721
+ const relative21 = path15.relative(root, file).replace(/\\/g, "/");
13722
+ return relative21.length > 0 && !isSensitivePath(relative21) && readConfinedText(root, relative21).ok;
13518
13723
  },
13519
13724
  readFile: (file) => {
13520
- const relative20 = path14.relative(root, file).replace(/\\/g, "/");
13521
- if (relative20.length === 0 || isSensitivePath(relative20)) return void 0;
13522
- const text2 = readConfinedText(root, relative20);
13725
+ const relative21 = path15.relative(root, file).replace(/\\/g, "/");
13726
+ if (relative21.length === 0 || isSensitivePath(relative21)) return void 0;
13727
+ const text2 = readConfinedText(root, relative21);
13523
13728
  return text2.ok ? text2.text : void 0;
13524
13729
  },
13525
13730
  getDirectories: () => []
@@ -13559,7 +13764,7 @@ function sourceKind(relativePath) {
13559
13764
  return ts5.ScriptKind.TS;
13560
13765
  }
13561
13766
  function isSourcePath(relativePath) {
13562
- return SOURCE_EXTENSIONS2.has(path14.posix.extname(relativePath).toLowerCase());
13767
+ return SOURCE_EXTENSIONS2.has(path15.posix.extname(relativePath).toLowerCase());
13563
13768
  }
13564
13769
  function createScopedProgram(options) {
13565
13770
  const root = canonicalRoot(options.root);
@@ -13572,7 +13777,7 @@ function createScopedProgram(options) {
13572
13777
  for (const file of options.files) {
13573
13778
  const normalized = file.relativePath.replace(/\\/g, "/").replace(/^\.\/+/, "");
13574
13779
  if (!isSourcePath(normalized) || isSensitivePath(normalized)) continue;
13575
- const absolute = path14.resolve(root, normalized);
13780
+ const absolute = path15.resolve(root, normalized);
13576
13781
  const key = foldPathKey(absolute);
13577
13782
  if (!inside(root, absolute) || seen.has(key)) continue;
13578
13783
  seen.add(key);
@@ -13599,12 +13804,12 @@ function createScopedProgram(options) {
13599
13804
  const overlaidContent = (absolute) => {
13600
13805
  const direct = overlay.get(foldPathKey(absolute));
13601
13806
  if (direct === void 0) return void 0;
13602
- const relative20 = path14.relative(root, absolute).replace(/\\/g, "/");
13603
- return isSensitivePath(relative20) ? void 0 : direct;
13807
+ const relative21 = path15.relative(root, absolute).replace(/\\/g, "/");
13808
+ return isSensitivePath(relative21) ? void 0 : direct;
13604
13809
  };
13605
13810
  const host = {
13606
13811
  getSourceFile: (fileName, languageVersion) => {
13607
- const absolute = path14.isAbsolute(fileName) ? fileName : path14.resolve(root, fileName);
13812
+ const absolute = path15.isAbsolute(fileName) ? fileName : path15.resolve(root, fileName);
13608
13813
  const content = overlaidContent(absolute) ?? (() => {
13609
13814
  if (isTypeScriptLib(fileName)) {
13610
13815
  try {
@@ -13616,9 +13821,9 @@ function createScopedProgram(options) {
13616
13821
  if (!allowed.has(foldPathKey(absolute))) return void 0;
13617
13822
  const confined = canonicalCandidate(root, absolute);
13618
13823
  if (confined === null) return void 0;
13619
- const relative20 = path14.relative(root, confined).replace(/\\/g, "/");
13620
- if (isSensitivePath(relative20)) return void 0;
13621
- const read = readConfinedText(root, relative20);
13824
+ const relative21 = path15.relative(root, confined).replace(/\\/g, "/");
13825
+ if (isSensitivePath(relative21)) return void 0;
13826
+ const read = readConfinedText(root, relative21);
13622
13827
  return read.ok ? read.text : void 0;
13623
13828
  })();
13624
13829
  if (content === void 0) return void 0;
@@ -13630,14 +13835,14 @@ function createScopedProgram(options) {
13630
13835
  sourceKind(absolute)
13631
13836
  );
13632
13837
  },
13633
- getDefaultLibFileName: (compilerOptions2) => path14.join(TYPESCRIPT_LIB_DIR, ts5.getDefaultLibFileName(compilerOptions2)),
13838
+ getDefaultLibFileName: (compilerOptions2) => path15.join(TYPESCRIPT_LIB_DIR, ts5.getDefaultLibFileName(compilerOptions2)),
13634
13839
  writeFile: () => void 0,
13635
13840
  getCurrentDirectory: () => root,
13636
13841
  getCanonicalFileName,
13637
13842
  useCaseSensitiveFileNames: () => ts5.sys.useCaseSensitiveFileNames,
13638
13843
  getNewLine: () => "\n",
13639
13844
  fileExists: (fileName) => {
13640
- const absolute = path14.isAbsolute(fileName) ? fileName : path14.resolve(root, fileName);
13845
+ const absolute = path15.isAbsolute(fileName) ? fileName : path15.resolve(root, fileName);
13641
13846
  if (overlaidContent(absolute) !== void 0) return true;
13642
13847
  if (isTypeScriptLib(fileName)) {
13643
13848
  try {
@@ -13646,13 +13851,13 @@ function createScopedProgram(options) {
13646
13851
  return false;
13647
13852
  }
13648
13853
  }
13649
- const relative20 = path14.relative(root, absolute).replace(/\\/g, "/");
13650
- if (isSensitivePath(relative20)) return false;
13854
+ const relative21 = path15.relative(root, absolute).replace(/\\/g, "/");
13855
+ if (isSensitivePath(relative21)) return false;
13651
13856
  if (!allowed.has(foldPathKey(absolute))) return false;
13652
13857
  return canonicalCandidate(root, absolute) !== null;
13653
13858
  },
13654
13859
  readFile: (fileName) => {
13655
- const absolute = path14.isAbsolute(fileName) ? fileName : path14.resolve(root, fileName);
13860
+ const absolute = path15.isAbsolute(fileName) ? fileName : path15.resolve(root, fileName);
13656
13861
  const overlaid = overlaidContent(absolute);
13657
13862
  if (overlaid !== void 0) return overlaid;
13658
13863
  if (isTypeScriptLib(fileName)) {
@@ -13665,26 +13870,26 @@ function createScopedProgram(options) {
13665
13870
  if (!allowed.has(foldPathKey(absolute))) return void 0;
13666
13871
  const confined = canonicalCandidate(root, absolute);
13667
13872
  if (confined === null) return void 0;
13668
- const relative20 = path14.relative(root, confined).replace(/\\/g, "/");
13669
- if (isSensitivePath(relative20)) return void 0;
13670
- const read = readConfinedText(root, relative20);
13873
+ const relative21 = path15.relative(root, confined).replace(/\\/g, "/");
13874
+ if (isSensitivePath(relative21)) return void 0;
13875
+ const read = readConfinedText(root, relative21);
13671
13876
  return read.ok ? read.text : void 0;
13672
13877
  },
13673
13878
  readDirectory: (directory, extensions) => {
13674
- const absolute = path14.resolve(directory);
13879
+ const absolute = path15.resolve(directory);
13675
13880
  if (!inside(root, absolute)) return [];
13676
13881
  const result = [];
13677
13882
  for (const file of rootNames) {
13678
13883
  if (!inside(absolute, file)) continue;
13679
- const extension = path14.extname(file);
13884
+ const extension = path15.extname(file);
13680
13885
  if (!extensions.includes(extension)) continue;
13681
- if (isSensitivePath(path14.relative(root, file).replace(/\\/g, "/"))) continue;
13886
+ if (isSensitivePath(path15.relative(root, file).replace(/\\/g, "/"))) continue;
13682
13887
  result.push(file);
13683
13888
  }
13684
13889
  return result.sort();
13685
13890
  },
13686
13891
  directoryExists: (directory) => {
13687
- const absolute = path14.isAbsolute(directory) ? directory : path14.resolve(root, directory);
13892
+ const absolute = path15.isAbsolute(directory) ? directory : path15.resolve(root, directory);
13688
13893
  if (isTypeScriptLib(directory)) return true;
13689
13894
  if (!inside(root, absolute)) return false;
13690
13895
  try {
@@ -13769,7 +13974,7 @@ function sameRelativePath(left, right) {
13769
13974
  return CASE_INSENSITIVE_PATHS ? left.toLowerCase() === right.toLowerCase() : left === right;
13770
13975
  }
13771
13976
  function relativeInRoot(root, fileName) {
13772
- return path14.relative(root, path14.resolve(fileName)).replace(/\\/g, "/");
13977
+ return path15.relative(root, path15.resolve(fileName)).replace(/\\/g, "/");
13773
13978
  }
13774
13979
  function symbolKey(checker, symbol, fileKeyCache) {
13775
13980
  if ((symbol.flags & ts5.SymbolFlags.Alias) === 0 && symbol.declarations?.[0]?.getSourceFile().isDeclarationFile === true) {
@@ -13817,8 +14022,8 @@ function resolveTargetSymbolKey(checker, program, root, target) {
13817
14022
  const normalizedTarget = target.targetPath?.replace(/\\/g, "/").replace(/^\.\/+/, "");
13818
14023
  for (const sourceFile of program.getSourceFiles()) {
13819
14024
  if (sourceFile.isDeclarationFile) continue;
13820
- const relative20 = relativeInRoot(root, sourceFile.fileName);
13821
- if (normalizedTarget !== void 0 && !sameRelativePath(relative20, normalizedTarget)) continue;
14025
+ const relative21 = relativeInRoot(root, sourceFile.fileName);
14026
+ if (normalizedTarget !== void 0 && !sameRelativePath(relative21, normalizedTarget)) continue;
13822
14027
  const moduleSymbol = checker.getSymbolAtLocation(sourceFile);
13823
14028
  if (moduleSymbol !== void 0) {
13824
14029
  for (const exported of checker.getExportsOfModule(moduleSymbol)) {
@@ -13906,7 +14111,7 @@ function findMultipleSymbolReferences(options) {
13906
14111
  reasons.push("Symbol reference search exceeded its deadline; results are partial");
13907
14112
  break;
13908
14113
  }
13909
- const relative20 = relativeInRoot(roots.root, sourceFile.fileName);
14114
+ const relative21 = relativeInRoot(roots.root, sourceFile.fileName);
13910
14115
  const visit = (node) => {
13911
14116
  if (totalRefs >= maxResults) {
13912
14117
  truncated = true;
@@ -13925,7 +14130,7 @@ function findMultipleSymbolReferences(options) {
13925
14130
  const position = sourceFile.getLineAndCharacterOfPosition(node.getStart(sourceFile));
13926
14131
  const parent = node.parent;
13927
14132
  const ref = {
13928
- path: relative20,
14133
+ path: relative21,
13929
14134
  line: position.line + 1,
13930
14135
  column: position.character + 1,
13931
14136
  name: node.text,
@@ -14059,8 +14264,8 @@ function findSection(sections, relativePath) {
14059
14264
  if (exact) return exact;
14060
14265
  const foldedPath = rendered.toLowerCase();
14061
14266
  const folded = sections.filter((section) => {
14062
- const path33 = section.path.toLowerCase();
14063
- return path33 === relativePath.toLowerCase() || path33 === foldedPath;
14267
+ const path34 = section.path.toLowerCase();
14268
+ return path34 === relativePath.toLowerCase() || path34 === foldedPath;
14064
14269
  });
14065
14270
  return folded.length === 1 ? folded[0] : null;
14066
14271
  }
@@ -14086,16 +14291,16 @@ function windowText(body, fromLine, lineCount) {
14086
14291
  }
14087
14292
 
14088
14293
  // src/mcp/analysis-worker.ts
14089
- import * as path16 from "path";
14294
+ import * as path17 from "path";
14090
14295
  import { fileURLToPath as fileURLToPath3 } from "url";
14091
14296
  import { Worker as Worker2 } from "worker_threads";
14092
14297
 
14093
14298
  // src/mcp/generate-worker.ts
14094
- import * as path15 from "path";
14299
+ import * as path16 from "path";
14095
14300
  import { fileURLToPath as fileURLToPath2, pathToFileURL as pathToFileURL2 } from "url";
14096
14301
  import { Worker } from "worker_threads";
14097
14302
  function workerEntry(directory, isCjs) {
14098
- const entry = path15.join(directory, isCjs ? "index.cjs" : "index.js");
14303
+ const entry = path16.join(directory, isCjs ? "index.cjs" : "index.js");
14099
14304
  return { path: entry, url: pathToFileURL2(entry).href };
14100
14305
  }
14101
14306
  var WORKER_SOURCE = `
@@ -14166,7 +14371,7 @@ var WORKER_SOURCE = `
14166
14371
  })();
14167
14372
  `;
14168
14373
  function generateInWorker(cwd, cliOptions, options = {}) {
14169
- return new Promise((resolve21) => {
14374
+ return new Promise((resolve22) => {
14170
14375
  let settled = false;
14171
14376
  let worker = null;
14172
14377
  const finish = (result) => {
@@ -14177,11 +14382,11 @@ function generateInWorker(cwd, cliOptions, options = {}) {
14177
14382
  if (!result.ok && options.runId !== void 0 && options.lockRoots !== void 0) {
14178
14383
  releaseAbandonedRun(options.lockRoots, options.runId);
14179
14384
  }
14180
- resolve21(result);
14385
+ resolve22(result);
14181
14386
  });
14182
14387
  };
14183
14388
  const isCjs = typeof __dirname !== "undefined";
14184
- const directory = isCjs ? __dirname : path15.dirname(fileURLToPath2(import.meta.url));
14389
+ const directory = isCjs ? __dirname : path16.dirname(fileURLToPath2(import.meta.url));
14185
14390
  try {
14186
14391
  worker = new Worker(WORKER_SOURCE, {
14187
14392
  eval: true,
@@ -14291,7 +14496,7 @@ var WORKER_SOURCE2 = `
14291
14496
  })();
14292
14497
  `;
14293
14498
  function analysisInWorker(request) {
14294
- return new Promise((resolve21) => {
14499
+ return new Promise((resolve22) => {
14295
14500
  let settled = false;
14296
14501
  let worker = null;
14297
14502
  const timer = setTimeout(() => {
@@ -14303,10 +14508,10 @@ function analysisInWorker(request) {
14303
14508
  settled = true;
14304
14509
  clearTimeout(timer);
14305
14510
  const terminated = worker === null ? Promise.resolve(void 0) : worker.terminate();
14306
- void terminated.catch(() => void 0).then(() => resolve21(result));
14511
+ void terminated.catch(() => void 0).then(() => resolve22(result));
14307
14512
  };
14308
14513
  const isCjs = typeof __dirname !== "undefined";
14309
- const directory = isCjs ? __dirname : path16.dirname(fileURLToPath3(import.meta.url));
14514
+ const directory = isCjs ? __dirname : path17.dirname(fileURLToPath3(import.meta.url));
14310
14515
  try {
14311
14516
  worker = new Worker2(WORKER_SOURCE2, {
14312
14517
  eval: true,
@@ -14334,12 +14539,12 @@ function analysisInWorker(request) {
14334
14539
 
14335
14540
  // src/mcp/workspace.ts
14336
14541
  import * as fs15 from "fs";
14337
- import * as path17 from "path";
14542
+ import * as path18 from "path";
14338
14543
  function foldForComparison(value) {
14339
14544
  return process.platform === "win32" || process.platform === "darwin" ? value.toLowerCase() : value;
14340
14545
  }
14341
14546
  function canonicalPath(value) {
14342
- const absolute = path17.resolve(value);
14547
+ const absolute = path18.resolve(value);
14343
14548
  try {
14344
14549
  return fs15.realpathSync(absolute);
14345
14550
  } catch {
@@ -14349,37 +14554,37 @@ function canonicalPath(value) {
14349
14554
  function isInside3(parent, child) {
14350
14555
  const foldedParent = foldForComparison(parent);
14351
14556
  const foldedChild = foldForComparison(child);
14352
- return foldedChild === foldedParent || foldedChild.startsWith(`${foldedParent}${path17.sep}`);
14557
+ return foldedChild === foldedParent || foldedChild.startsWith(`${foldedParent}${path18.sep}`);
14353
14558
  }
14354
14559
  function resolveThroughExistingAncestor(target) {
14355
14560
  let existing = target;
14356
14561
  const missing = [];
14357
14562
  while (!fs15.existsSync(existing)) {
14358
- missing.unshift(path17.basename(existing));
14359
- const parent = path17.dirname(existing);
14563
+ missing.unshift(path18.basename(existing));
14564
+ const parent = path18.dirname(existing);
14360
14565
  if (parent === existing) break;
14361
14566
  existing = parent;
14362
14567
  }
14363
14568
  const resolved = canonicalPath(existing);
14364
- return missing.length === 0 ? resolved : path17.join(resolved, ...missing);
14569
+ return missing.length === 0 ? resolved : path18.join(resolved, ...missing);
14365
14570
  }
14366
- function configuredOutputProblem(root, requested, permitted, label) {
14367
- const resolved = resolveThroughExistingAncestor(path17.resolve(root, requested));
14571
+ function configuredOutputProblem(root, requested, permitted, label2) {
14572
+ const resolved = resolveThroughExistingAncestor(path18.resolve(root, requested));
14368
14573
  if (permitted.some((allowed) => isInside3(canonicalPath(allowed), resolved))) return null;
14369
14574
  const shown = permitted.map((allowed) => canonicalPath(allowed)).join(", ");
14370
- return `"${label}" must resolve inside the repository this server serves (${shown}). A configuration file in the repository may not place snapshot output or staging outside the served root; move the directory inside the repository, or run the CLI directly.`;
14575
+ return `"${label2}" must resolve inside the repository this server serves (${shown}). A configuration file in the repository may not place snapshot output or staging outside the served root; move the directory inside the repository, or run the CLI directly.`;
14371
14576
  }
14372
14577
  function resolveRoot(requested, context) {
14373
14578
  if (requested !== void 0 && (typeof requested !== "string" || requested.trim().length === 0)) {
14374
14579
  return { ok: false, message: '"root" must be a non-empty string when provided.' };
14375
14580
  }
14376
14581
  const wanted = typeof requested === "string" ? requested.trim() : context.cwd;
14377
- const absolute = path17.resolve(context.cwd, wanted);
14582
+ const absolute = path18.resolve(context.cwd, wanted);
14378
14583
  const outside = () => ({
14379
14584
  ok: false,
14380
14585
  message: `"${wanted}" resolves outside the directories this server may read (${context.roots.join(", ")}). The server reads the directory it was started for; restart it with --cwd <directory> to serve a different repository.`
14381
14586
  });
14382
- const lexicalRoots = context.roots.map((allowed) => path17.resolve(allowed));
14587
+ const lexicalRoots = context.roots.map((allowed) => path18.resolve(allowed));
14383
14588
  if (!lexicalRoots.some((allowed) => isInside3(allowed, absolute))) return outside();
14384
14589
  let linkStats;
14385
14590
  try {
@@ -14451,7 +14656,7 @@ async function openWorkspace(root, overrides = {}, allowedRoots, options = {}) {
14451
14656
  }
14452
14657
  const requested = overrides.outDir.trim();
14453
14658
  const permitted = allowedRoots !== void 0 && allowedRoots.length > 0 ? allowedRoots : [root];
14454
- const resolved = resolveThroughExistingAncestor(path17.resolve(root, requested));
14659
+ const resolved = resolveThroughExistingAncestor(path18.resolve(root, requested));
14455
14660
  if (!permitted.some((allowed) => isInside3(canonicalPath(allowed), resolved))) {
14456
14661
  const shown = permitted.map((allowed) => canonicalPath(allowed)).join(", ");
14457
14662
  return {
@@ -14491,11 +14696,11 @@ async function openWorkspace(root, overrides = {}, allowedRoots, options = {}) {
14491
14696
  try {
14492
14697
  const config = resolveConfig(loaded.config, cliOptions, root);
14493
14698
  const permitted = allowedRoots !== void 0 && allowedRoots.length > 0 ? allowedRoots : [root];
14494
- for (const [label, value] of [
14699
+ for (const [label2, value] of [
14495
14700
  ["outDir", config.outDir],
14496
14701
  ["tmpDir", config.tmpDir]
14497
14702
  ]) {
14498
- const problem = configuredOutputProblem(root, value, permitted, label);
14703
+ const problem = configuredOutputProblem(root, value, permitted, label2);
14499
14704
  if (problem !== null) return { ok: false, message: problem };
14500
14705
  }
14501
14706
  return {
@@ -14522,14 +14727,14 @@ async function readLiveManifest(workspace, options = {}) {
14522
14727
  });
14523
14728
  }
14524
14729
  function manifestPathFor(workspace) {
14525
- return path17.resolve(workspace.root, workspace.config.outDir, "manifest.json");
14730
+ return path18.resolve(workspace.root, workspace.config.outDir, "manifest.json");
14526
14731
  }
14527
14732
  function partPathFor(workspace, filename) {
14528
14733
  if (filename.length === 0 || filename.includes("\0")) return null;
14529
- const partsDir = path17.resolve(workspace.root, workspace.config.outDir, "parts");
14530
- const resolved = path17.resolve(partsDir, filename);
14531
- const relative20 = path17.relative(partsDir, resolved);
14532
- if (relative20.length === 0 || relative20.includes(path17.sep) || relative20.includes("/") || relative20.includes("\\") || path17.isAbsolute(relative20)) {
14734
+ const partsDir = path18.resolve(workspace.root, workspace.config.outDir, "parts");
14735
+ const resolved = path18.resolve(partsDir, filename);
14736
+ const relative21 = path18.relative(partsDir, resolved);
14737
+ if (relative21.length === 0 || relative21.includes(path18.sep) || relative21.includes("/") || relative21.includes("\\") || path18.isAbsolute(relative21)) {
14533
14738
  return null;
14534
14739
  }
14535
14740
  let stats;
@@ -14540,12 +14745,12 @@ function partPathFor(workspace, filename) {
14540
14745
  }
14541
14746
  if (!stats.isFile()) return null;
14542
14747
  try {
14543
- const snapshotReal = fs15.realpathSync(path17.resolve(workspace.root, workspace.config.outDir));
14748
+ const snapshotReal = fs15.realpathSync(path18.resolve(workspace.root, workspace.config.outDir));
14544
14749
  const partsReal = fs15.realpathSync(partsDir);
14545
14750
  const resolvedReal = fs15.realpathSync(resolved);
14546
14751
  if (!isInside3(snapshotReal, partsReal)) return null;
14547
14752
  if (!isInside3(partsReal, resolvedReal)) return null;
14548
- if (path17.dirname(resolvedReal) !== partsReal) return null;
14753
+ if (path18.dirname(resolvedReal) !== partsReal) return null;
14549
14754
  } catch {
14550
14755
  return null;
14551
14756
  }
@@ -14563,8 +14768,8 @@ function sensitiveSnapshotProblem(manifest) {
14563
14768
  }
14564
14769
  function readManifest3(workspace) {
14565
14770
  const file = manifestPathFor(workspace);
14566
- const shown = path17.relative(workspace.root, file).split(path17.sep).join("/") || file;
14567
- const confined = readConfinedText(path17.dirname(file), path17.basename(file), MAX_MANIFEST_BYTES);
14771
+ const shown = path18.relative(workspace.root, file).split(path18.sep).join("/") || file;
14772
+ const confined = readConfinedText(path18.dirname(file), path18.basename(file), MAX_MANIFEST_BYTES);
14568
14773
  if (!confined.ok) {
14569
14774
  if (confined.reason === "missing") {
14570
14775
  return {
@@ -14701,7 +14906,7 @@ function formatBytes(bytes) {
14701
14906
  return (bytes / (1024 * 1024)).toFixed(1) + " MB";
14702
14907
  }
14703
14908
  function relativeFor(workspace, absolute) {
14704
- return path18.relative(workspace.root, absolute).split(path18.sep).join("/");
14909
+ return path19.relative(workspace.root, absolute).split(path19.sep).join("/");
14705
14910
  }
14706
14911
  function capped(values, limit = 20) {
14707
14912
  return { count: values.length, sample: values.slice(0, limit) };
@@ -14720,13 +14925,13 @@ function summarizeDrift(drift) {
14720
14925
  function toRelativePath(root, value) {
14721
14926
  const cleaned = value.trim();
14722
14927
  if (cleaned.length === 0 || cleaned.includes("\0")) return null;
14723
- const resolvedRoot = path18.resolve(root);
14724
- const absolute = path18.resolve(resolvedRoot, cleaned);
14725
- const relative20 = path18.relative(resolvedRoot, absolute);
14726
- if (relative20 === "" || relative20 === ".." || relative20.startsWith(".." + path18.sep) || path18.isAbsolute(relative20)) {
14928
+ const resolvedRoot = path19.resolve(root);
14929
+ const absolute = path19.resolve(resolvedRoot, cleaned);
14930
+ const relative21 = path19.relative(resolvedRoot, absolute);
14931
+ if (relative21 === "" || relative21 === ".." || relative21.startsWith(".." + path19.sep) || path19.isAbsolute(relative21)) {
14727
14932
  return null;
14728
14933
  }
14729
- return relative20.split(path18.sep).join("/");
14934
+ return relative21.split(path19.sep).join("/");
14730
14935
  }
14731
14936
  function symbolsOf(entry) {
14732
14937
  const summary = entry.summary;
@@ -15051,16 +15256,16 @@ var contextTool = {
15051
15256
  }
15052
15257
  }
15053
15258
  for (const wanted of wantedFiles) {
15054
- const relative20 = toRelativePath(workspace.root, wanted);
15055
- if (relative20 === null) {
15259
+ const relative21 = toRelativePath(workspace.root, wanted);
15260
+ if (relative21 === null) {
15056
15261
  preOmitted.push({ path: wanted, reason: "outside the served repository" });
15057
15262
  continue;
15058
15263
  }
15059
- if (isSensitivePath(relative20)) {
15060
- preOmitted.push({ path: relative20, reason: "sensitive-file" });
15264
+ if (isSensitivePath(relative21)) {
15265
+ preOmitted.push({ path: relative21, reason: "sensitive-file" });
15061
15266
  continue;
15062
15267
  }
15063
- targets.set(relative20, "requested file");
15268
+ targets.set(relative21, "requested file");
15064
15269
  }
15065
15270
  for (const symbol of wantedSymbols) {
15066
15271
  const needle = symbol.toLowerCase();
@@ -15569,7 +15774,7 @@ var validateTool = {
15569
15774
  const analysis2 = await analysisInWorker({
15570
15775
  task: "health",
15571
15776
  options: {
15572
- snapshotDir: path18.resolve(workspace.root, workspace.config.outDir),
15777
+ snapshotDir: path19.resolve(workspace.root, workspace.config.outDir),
15573
15778
  repoDir: workspace.root,
15574
15779
  // Only the project's own rules: `auditSnapshot` adds the built-in set itself for the
15575
15780
  // section scan. Passing all 32 here re-scans every raw part under its Markdown path,
@@ -15616,7 +15821,7 @@ var validateTool = {
15616
15821
  ["setting(s) changed since the snapshot", result.drift.configMismatches.length],
15617
15822
  ["internal count(s) disagreeing", result.drift.totalsMismatches.length]
15618
15823
  ];
15619
- for (const [label, count] of observations) if (count > 0) lines.push(" - " + count + " " + label);
15824
+ for (const [label2, count] of observations) if (count > 0) lines.push(" - " + count + " " + label2);
15620
15825
  for (const error of result.errors.slice(0, 5)) lines.push(" - " + error);
15621
15826
  lines.push("Run snapshot_generate to refresh it.");
15622
15827
  }
@@ -15777,7 +15982,7 @@ var generateTool = {
15777
15982
  const summary = result.summary;
15778
15983
  if (!dryRun) forgetManifest(manifestPathFor(workspace));
15779
15984
  const validationFailed = summary.validationStatus === "failed";
15780
- const written = relativeFor(workspace, path18.resolve(workspace.root, workspace.config.outDir));
15985
+ const written = relativeFor(workspace, path19.resolve(workspace.root, workspace.config.outDir));
15781
15986
  const lines = dryRun ? [
15782
15987
  "Dry run \u2014 nothing was written.",
15783
15988
  "Would include " + summary.totalFiles + " file(s) in " + summary.partsCount + " part(s).",
@@ -16118,6 +16323,25 @@ var COMMAND_OPTION_SCOPE = {
16118
16323
  "help",
16119
16324
  "version"
16120
16325
  ],
16326
+ guard: [
16327
+ "hook",
16328
+ "changed",
16329
+ "max-chars",
16330
+ "diff",
16331
+ "paths",
16332
+ "depth",
16333
+ "max-results",
16334
+ "no-cache",
16335
+ "no-live",
16336
+ "cwd",
16337
+ "out-dir",
16338
+ "no-config",
16339
+ "format",
16340
+ "mode",
16341
+ "no-update-check",
16342
+ "help",
16343
+ "version"
16344
+ ],
16121
16345
  brief: [
16122
16346
  "diff",
16123
16347
  "paths",
@@ -16270,6 +16494,7 @@ var COMMAND_ORDER = [
16270
16494
  "health",
16271
16495
  "report",
16272
16496
  "impact",
16497
+ "guard",
16273
16498
  "brief",
16274
16499
  "explain",
16275
16500
  "update",
@@ -16492,6 +16717,13 @@ function buildAgentContract() {
16492
16717
  positionals: [],
16493
16718
  exits: [0, 1, 2]
16494
16719
  },
16720
+ {
16721
+ name: "guard",
16722
+ aliases: [],
16723
+ summary: "Check whether a change is complete: untouched consumers, candidate tests, affected routes, and a trust stamp, in one small report. With --hook <claude|copilot|codex|raw>, read one hook payload from stdin and emit the host-shaped additionalContext, or an empty object when there is nothing to say. Defaults to the working tree against HEAD.",
16724
+ positionals: [],
16725
+ exits: [0, 1, 2]
16726
+ },
16495
16727
  {
16496
16728
  name: "brief",
16497
16729
  aliases: [],
@@ -16653,6 +16885,27 @@ function buildAgentContract() {
16653
16885
  appliesTo: optionAppliesTo("include-cycles"),
16654
16886
  summary: "impact only: include import cycles in the impacted subgraph."
16655
16887
  },
16888
+ {
16889
+ flag: "--hook",
16890
+ type: "string",
16891
+ default: "unset",
16892
+ appliesTo: optionAppliesTo("hook"),
16893
+ summary: "guard only: read one hook payload from stdin and shape the response for claude, copilot, codex, or raw. Fail-open: an error returns an empty object and a stderr note."
16894
+ },
16895
+ {
16896
+ flag: "--changed",
16897
+ type: "boolean",
16898
+ default: false,
16899
+ appliesTo: optionAppliesTo("changed"),
16900
+ summary: "guard only: check the working tree against HEAD. This is the default when --hook is not given."
16901
+ },
16902
+ {
16903
+ flag: "--max-chars",
16904
+ type: "number",
16905
+ default: 1200,
16906
+ appliesTo: optionAppliesTo("max-chars"),
16907
+ summary: "guard only: cap on the model-facing hook text (minimum 200, maximum 10000)."
16908
+ },
16656
16909
  {
16657
16910
  flag: "--copy",
16658
16911
  type: "boolean",
@@ -17558,12 +17811,12 @@ function buildResourceProvider() {
17558
17811
  }
17559
17812
  ];
17560
17813
  const workspace = await workspaceFor(context);
17561
- const reportsDir = "error" in workspace ? null : path19.resolve(workspace.root, workspace.config.outDir, "reports");
17814
+ const reportsDir = "error" in workspace ? null : path20.resolve(workspace.root, workspace.config.outDir, "reports");
17562
17815
  if ("error" in workspace) return resources;
17563
17816
  const read = readManifest3(workspace);
17564
17817
  if (!read.ok) return resources;
17565
17818
  for (const [uri, report2] of REPORT_URIS) {
17566
- const present = reportsDir !== null && fs17.existsSync(path19.join(reportsDir, report2.file));
17819
+ const present = reportsDir !== null && fs17.existsSync(path20.join(reportsDir, report2.file));
17567
17820
  if (!present) continue;
17568
17821
  resources.push({
17569
17822
  uri,
@@ -17627,7 +17880,7 @@ function buildResourceProvider() {
17627
17880
  "The repository could not be opened, so this resource is unavailable: " + workspace.error
17628
17881
  );
17629
17882
  }
17630
- const snapshotDir = path19.resolve(workspace.root, workspace.config.outDir);
17883
+ const snapshotDir = path20.resolve(workspace.root, workspace.config.outDir);
17631
17884
  if (uri === PROMPT_URI || REPORT_URIS.has(uri)) {
17632
17885
  const read = readManifest3(workspace);
17633
17886
  if (!read.ok) {
@@ -17650,7 +17903,7 @@ function buildResourceProvider() {
17650
17903
  }
17651
17904
  const report2 = REPORT_URIS.get(uri);
17652
17905
  if (report2) {
17653
- const read = readConfinedText(snapshotDir, path19.posix.join("reports", report2.file));
17906
+ const read = readConfinedText(snapshotDir, path20.posix.join("reports", report2.file));
17654
17907
  if (!read.ok) {
17655
17908
  throw new ResourceNotFoundError(
17656
17909
  uri,
@@ -17668,7 +17921,7 @@ function buildResourceProvider() {
17668
17921
  if (!read.ok) {
17669
17922
  throw new ResourceNotFoundError(uri, read.message);
17670
17923
  }
17671
- const confined = readConfinedText(path19.dirname(read.file), path19.basename(read.file));
17924
+ const confined = readConfinedText(path20.dirname(read.file), path20.basename(read.file));
17672
17925
  if (!confined.ok) {
17673
17926
  throw new ResourceNotFoundError(
17674
17927
  uri,
@@ -17742,41 +17995,41 @@ function validateArguments(schema, value) {
17742
17995
  }
17743
17996
  return problems;
17744
17997
  }
17745
- function checkValue(path33, schema, value) {
17998
+ function checkValue(path34, schema, value) {
17746
17999
  if (schema.enum && !schema.enum.includes(value)) {
17747
- return [`"${path33}" must be one of: ${schema.enum.join(", ")}`];
18000
+ return [`"${path34}" must be one of: ${schema.enum.join(", ")}`];
17748
18001
  }
17749
18002
  const declared = schema.type === void 0 ? [] : Array.isArray(schema.type) ? schema.type : [schema.type];
17750
18003
  if (declared.length > 0 && !declared.some((type) => matchesType(type, value))) {
17751
18004
  if (declared.length === 1 && declared[0] === "integer" && typeof value !== "number") {
17752
- return [`"${path33}" must be a number`];
18005
+ return [`"${path34}" must be a number`];
17753
18006
  }
17754
18007
  const article = (type) => type === "integer" || type === "object" || type === "array" ? `an ${type}` : `a ${type}`;
17755
- return [`"${path33}" must be ${declared.map(article).join(" or ")}`];
18008
+ return [`"${path34}" must be ${declared.map(article).join(" or ")}`];
17756
18009
  }
17757
18010
  const problems = [];
17758
18011
  if (declared.includes("string") && typeof value === "string") {
17759
18012
  if (schema.minLength !== void 0 && value.length < schema.minLength) {
17760
- problems.push(`"${path33}" must be at least ${schema.minLength} character(s)`);
18013
+ problems.push(`"${path34}" must be at least ${schema.minLength} character(s)`);
17761
18014
  }
17762
18015
  if (schema.maxLength !== void 0 && value.length > schema.maxLength) {
17763
- problems.push(`"${path33}" must be at most ${schema.maxLength} character(s)`);
18016
+ problems.push(`"${path34}" must be at most ${schema.maxLength} character(s)`);
17764
18017
  }
17765
18018
  }
17766
18019
  if ((declared.includes("number") || declared.includes("integer")) && typeof value === "number" && !Number.isNaN(value)) {
17767
18020
  if (declared.includes("integer") && !declared.includes("number") && !Number.isInteger(value)) {
17768
- problems.push(`"${path33}" must be an integer`);
18021
+ problems.push(`"${path34}" must be an integer`);
17769
18022
  }
17770
18023
  if (schema.minimum !== void 0 && value < schema.minimum) {
17771
- problems.push(`"${path33}" must be >= ${schema.minimum}`);
18024
+ problems.push(`"${path34}" must be >= ${schema.minimum}`);
17772
18025
  }
17773
18026
  if (schema.maximum !== void 0 && value > schema.maximum) {
17774
- problems.push(`"${path33}" must be <= ${schema.maximum}`);
18027
+ problems.push(`"${path34}" must be <= ${schema.maximum}`);
17775
18028
  }
17776
18029
  }
17777
18030
  if (declared.includes("array") && Array.isArray(value) && schema.items) {
17778
18031
  value.forEach((item, index) => {
17779
- problems.push(...checkValue(`${path33}[${index}]`, schema.items, item));
18032
+ problems.push(...checkValue(`${path34}[${index}]`, schema.items, item));
17780
18033
  });
17781
18034
  }
17782
18035
  return problems;
@@ -18175,11 +18428,11 @@ var MAX_LINE_BYTES = 32 * 1024 * 1024;
18175
18428
  function createWriter(output) {
18176
18429
  return {
18177
18430
  write(value) {
18178
- return new Promise((resolve21, reject) => {
18431
+ return new Promise((resolve22, reject) => {
18179
18432
  output.write(`${JSON.stringify(value)}
18180
18433
  `, (error) => {
18181
18434
  if (error) reject(error);
18182
- else resolve21();
18435
+ else resolve22();
18183
18436
  });
18184
18437
  });
18185
18438
  }
@@ -18324,8 +18577,8 @@ async function runStdioServer(options) {
18324
18577
  let inFlight = 0;
18325
18578
  let inputEnded = false;
18326
18579
  let resolveDone = () => void 0;
18327
- const finished = new Promise((resolve21) => {
18328
- resolveDone = resolve21;
18580
+ const finished = new Promise((resolve22) => {
18581
+ resolveDone = resolve22;
18329
18582
  });
18330
18583
  const finishIfIdle = () => {
18331
18584
  if (inputEnded && inFlight === 0) resolveDone(0);
@@ -19251,11 +19504,11 @@ async function startHttpTransport(options) {
19251
19504
  }
19252
19505
  send(405, { error: "method not allowed" }, { ...cors, allow: "POST, GET, OPTIONS, DELETE" });
19253
19506
  });
19254
- await new Promise((resolve21, reject) => {
19507
+ await new Promise((resolve22, reject) => {
19255
19508
  httpServer.once("error", reject);
19256
19509
  httpServer.listen(port, host, () => {
19257
19510
  httpServer.removeListener("error", reject);
19258
- resolve21();
19511
+ resolve22();
19259
19512
  });
19260
19513
  });
19261
19514
  const address = httpServer.address();
@@ -19268,8 +19521,8 @@ async function startHttpTransport(options) {
19268
19521
  token,
19269
19522
  close: async () => {
19270
19523
  await mcp.close();
19271
- await new Promise((resolve21) => {
19272
- httpServer.close(() => resolve21());
19524
+ await new Promise((resolve22) => {
19525
+ httpServer.close(() => resolve22());
19273
19526
  httpServer.closeAllConnections();
19274
19527
  });
19275
19528
  }
@@ -19278,7 +19531,7 @@ async function startHttpTransport(options) {
19278
19531
 
19279
19532
  // src/web/zip.ts
19280
19533
  import * as fs18 from "fs";
19281
- import * as path20 from "path";
19534
+ import * as path21 from "path";
19282
19535
  var LOCAL_HEADER = 67324752;
19283
19536
  var CENTRAL_HEADER = 33639248;
19284
19537
  var END_RECORD = 101010256;
@@ -19311,10 +19564,10 @@ function walkFiles(root, prefix = "") {
19311
19564
  const stack = [prefix];
19312
19565
  while (stack.length > 0) {
19313
19566
  const current = stack.pop();
19314
- for (const entry of fs18.readdirSync(path20.join(root, current), { withFileTypes: true })) {
19315
- const relative20 = current === "" ? entry.name : current + "/" + entry.name;
19316
- if (entry.isDirectory()) stack.push(relative20);
19317
- else if (entry.isFile()) files.push(relative20);
19567
+ for (const entry of fs18.readdirSync(path21.join(root, current), { withFileTypes: true })) {
19568
+ const relative21 = current === "" ? entry.name : current + "/" + entry.name;
19569
+ if (entry.isDirectory()) stack.push(relative21);
19570
+ else if (entry.isFile()) files.push(relative21);
19318
19571
  }
19319
19572
  }
19320
19573
  return files;
@@ -19328,16 +19581,16 @@ function writeZip(options) {
19328
19581
  }
19329
19582
  if (options.directory !== void 0) {
19330
19583
  const root = options.directory;
19331
- for (const relative20 of walkFiles(root)) {
19332
- if (options.skip !== void 0 && options.skip(relative20)) continue;
19333
- const full = path20.join(root, relative20);
19584
+ for (const relative21 of walkFiles(root)) {
19585
+ if (options.skip !== void 0 && options.skip(relative21)) continue;
19586
+ const full = path21.join(root, relative21);
19334
19587
  const stat = fs18.statSync(full);
19335
19588
  if (totalBytes + stat.size > maxTotalBytes) {
19336
19589
  throw new Error("zip: uncompressed content exceeds " + maxTotalBytes + " bytes");
19337
19590
  }
19338
19591
  const content = fs18.readFileSync(full);
19339
19592
  totalBytes += content.length;
19340
- entries.push({ name: relative20, content, mtime: stat.mtime });
19593
+ entries.push({ name: relative21, content, mtime: stat.mtime });
19341
19594
  }
19342
19595
  }
19343
19596
  if (entries.length > 65535) {
@@ -19618,7 +19871,7 @@ async function startWebServer(options) {
19618
19871
  const pendingClones = /* @__PURE__ */ new Set();
19619
19872
  let closing = false;
19620
19873
  let generateJobs = 0;
19621
- const allowedRoots = [path21.resolve(options.cwd)];
19874
+ const allowedRoots = [path22.resolve(options.cwd)];
19622
19875
  const snapshotRepoRoots = /* @__PURE__ */ new Map();
19623
19876
  const canonical = (candidate) => {
19624
19877
  try {
@@ -19631,32 +19884,32 @@ async function startWebServer(options) {
19631
19884
  const inside2 = (resolved) => allowedRoots.some((root) => {
19632
19885
  const canonicalRoot2 = canonical(root);
19633
19886
  if (canonicalRoot2 === null) return false;
19634
- const relative20 = path21.relative(fold(canonicalRoot2), fold(resolved));
19635
- return relative20 === "" || !relative20.startsWith(`..${path21.sep}`) && relative20 !== ".." && !path21.isAbsolute(relative20);
19887
+ const relative21 = path22.relative(fold(canonicalRoot2), fold(resolved));
19888
+ return relative21 === "" || !relative21.startsWith(`..${path22.sep}`) && relative21 !== ".." && !path22.isAbsolute(relative21);
19636
19889
  });
19637
19890
  const insideAllowedRoots = (candidate) => {
19638
19891
  const resolved = canonical(candidate);
19639
19892
  return resolved === null ? false : inside2(resolved);
19640
19893
  };
19641
19894
  const lexicallyInside = (candidate) => {
19642
- const resolved = fold(path21.resolve(candidate));
19895
+ const resolved = fold(path22.resolve(candidate));
19643
19896
  return allowedRoots.some((root) => {
19644
- const resolvedRoot = fold(path21.resolve(root));
19645
- return resolved === resolvedRoot || resolved.startsWith(resolvedRoot + path21.sep);
19897
+ const resolvedRoot = fold(path22.resolve(root));
19898
+ return resolved === resolvedRoot || resolved.startsWith(resolvedRoot + path22.sep);
19646
19899
  });
19647
19900
  };
19648
19901
  const insideAllowedRootsForWrite = (candidate) => {
19649
- let existing = path21.resolve(candidate);
19902
+ let existing = path22.resolve(candidate);
19650
19903
  const tail = [];
19651
19904
  while (!fs19.existsSync(existing)) {
19652
- tail.unshift(path21.basename(existing));
19653
- const parent = path21.dirname(existing);
19905
+ tail.unshift(path22.basename(existing));
19906
+ const parent = path22.dirname(existing);
19654
19907
  if (parent === existing) break;
19655
19908
  existing = parent;
19656
19909
  }
19657
19910
  const resolved = canonical(existing);
19658
19911
  if (resolved === null) return false;
19659
- return inside2(tail.length === 0 ? resolved : path21.join(resolved, ...tail));
19912
+ return inside2(tail.length === 0 ? resolved : path22.join(resolved, ...tail));
19660
19913
  };
19661
19914
  const authorized = (request) => {
19662
19915
  if (token === null) return true;
@@ -19846,7 +20099,7 @@ async function startWebServer(options) {
19846
20099
  return;
19847
20100
  }
19848
20101
  } else {
19849
- target = path21.resolve(options.cwd, source);
20102
+ target = path22.resolve(options.cwd, source);
19850
20103
  if (!lexicallyInside(target)) {
19851
20104
  send(403, { error: "outside the served directory: " + target });
19852
20105
  return;
@@ -19888,13 +20141,13 @@ async function startWebServer(options) {
19888
20141
  hooks: {}
19889
20142
  } : loaded.config ?? {};
19890
20143
  const configuredOutDir = typeof runConfig.outDir === "string" && runConfig.outDir.trim() !== "" ? runConfig.outDir : "snapshot";
19891
- const snapshotDir = path21.resolve(target, configuredOutDir);
20144
+ const snapshotDir = path22.resolve(target, configuredOutDir);
19892
20145
  if (!insideAllowedRootsForWrite(snapshotDir)) {
19893
20146
  send(403, { error: "the configured outDir resolves outside the served directory" });
19894
20147
  return;
19895
20148
  }
19896
20149
  const configuredTmpDir = typeof runConfig.tmpDir === "string" && runConfig.tmpDir.trim() !== "" ? runConfig.tmpDir : "snapshot.tmp";
19897
- const stagingDir = path21.resolve(target, configuredTmpDir);
20150
+ const stagingDir = path22.resolve(target, configuredTmpDir);
19898
20151
  if (!insideAllowedRootsForWrite(stagingDir)) {
19899
20152
  send(403, { error: "the configured tmpDir resolves outside the served directory" });
19900
20153
  return;
@@ -19929,8 +20182,8 @@ async function startWebServer(options) {
19929
20182
  }
19930
20183
  const seconds = ((Date.now() - started) / 1e3).toFixed(2);
19931
20184
  snapshotRepoRoots.set(
19932
- canonical(snapshotDir) ?? path21.resolve(snapshotDir),
19933
- path21.resolve(target)
20185
+ canonical(snapshotDir) ?? path22.resolve(snapshotDir),
20186
+ path22.resolve(target)
19934
20187
  );
19935
20188
  const audit = await analysisInWorker({
19936
20189
  task: "health",
@@ -19975,7 +20228,7 @@ async function startWebServer(options) {
19975
20228
  return;
19976
20229
  }
19977
20230
  if (request.method === "GET" && request.url?.startsWith("/api/health?") === true) {
19978
- const target = path21.resolve(options.cwd, url.searchParams.get("path") ?? options.cwd);
20231
+ const target = path22.resolve(options.cwd, url.searchParams.get("path") ?? options.cwd);
19979
20232
  if (!lexicallyInside(target)) {
19980
20233
  send(403, { error: "outside the served directory: " + target });
19981
20234
  return;
@@ -19988,12 +20241,12 @@ async function startWebServer(options) {
19988
20241
  send(403, { error: "outside the served directory: " + target });
19989
20242
  return;
19990
20243
  }
19991
- const repoDir = snapshotRepoRoots.get(canonical(target) ?? path21.resolve(target)) ?? path21.resolve(options.cwd);
20244
+ const repoDir = snapshotRepoRoots.get(canonical(target) ?? path22.resolve(target)) ?? path22.resolve(options.cwd);
19992
20245
  if (!insideAllowedRoots(repoDir)) {
19993
20246
  send(403, { error: "the repository root for this snapshot is outside the served directory" });
19994
20247
  return;
19995
20248
  }
19996
- if (!fs19.existsSync(path21.join(target, "manifest.json"))) {
20249
+ if (!fs19.existsSync(path22.join(target, "manifest.json"))) {
19997
20250
  send(404, { error: "no manifest.json under " + target });
19998
20251
  return;
19999
20252
  }
@@ -20013,7 +20266,7 @@ async function startWebServer(options) {
20013
20266
  return;
20014
20267
  }
20015
20268
  if (request.method === "GET" && (request.url?.startsWith("/api/snapshot?") === true || request.url === "/api/snapshot")) {
20016
- const target = path21.resolve(options.cwd, url.searchParams.get("path") ?? options.cwd);
20269
+ const target = path22.resolve(options.cwd, url.searchParams.get("path") ?? options.cwd);
20017
20270
  if (!lexicallyInside(target)) {
20018
20271
  send(403, { error: "outside the served directory: " + target });
20019
20272
  return;
@@ -20066,7 +20319,7 @@ async function startWebServer(options) {
20066
20319
  return;
20067
20320
  }
20068
20321
  if (request.method === "GET" && request.url?.startsWith("/api/snapshot.zip") === true) {
20069
- const target = path21.resolve(options.cwd, url.searchParams.get("path") ?? options.cwd);
20322
+ const target = path22.resolve(options.cwd, url.searchParams.get("path") ?? options.cwd);
20070
20323
  if (!lexicallyInside(target)) {
20071
20324
  send(403, { error: "outside the served directory: " + target });
20072
20325
  return;
@@ -20110,15 +20363,15 @@ async function startWebServer(options) {
20110
20363
  }
20111
20364
  }
20112
20365
  const artifactRecord = zipManifest.artifacts ?? {};
20113
- for (const [key, relative20] of Object.entries(ARTIFACT_PATHS)) {
20114
- if (artifactRecord[key] !== void 0 && artifactRecord[key] !== null) wanted.add(relative20);
20366
+ for (const [key, relative21] of Object.entries(ARTIFACT_PATHS)) {
20367
+ if (artifactRecord[key] !== void 0 && artifactRecord[key] !== null) wanted.add(relative21);
20115
20368
  }
20116
20369
  wanted.add("signature.json");
20117
20370
  const entries = [];
20118
- for (const relative20 of wanted) {
20119
- const read = readConfinedBytes(target, relative20, 256 * 1024 * 1024);
20371
+ for (const relative21 of wanted) {
20372
+ const read = readConfinedBytes(target, relative21, 256 * 1024 * 1024);
20120
20373
  if (!read.ok) continue;
20121
- entries.push({ name: relative20, content: read.bytes, mtime: read.stats.mtime });
20374
+ entries.push({ name: relative21, content: read.bytes, mtime: read.stats.mtime });
20122
20375
  }
20123
20376
  if (entries.length === 0) {
20124
20377
  send(404, { error: "the snapshot manifest declares no readable files" });
@@ -20140,11 +20393,11 @@ async function startWebServer(options) {
20140
20393
  }
20141
20394
  send(404, { error: "not found" });
20142
20395
  });
20143
- await new Promise((resolve21, reject) => {
20396
+ await new Promise((resolve22, reject) => {
20144
20397
  server.once("error", reject);
20145
20398
  server.listen(port, host, () => {
20146
20399
  server.removeListener("error", reject);
20147
- resolve21();
20400
+ resolve22();
20148
20401
  });
20149
20402
  });
20150
20403
  const address = server.address();
@@ -20161,7 +20414,7 @@ async function startWebServer(options) {
20161
20414
  await mcp.close();
20162
20415
  const deadline = Date.now() + 5e3;
20163
20416
  while (pendingClones.size > 0 && Date.now() < deadline) {
20164
- await new Promise((resolve21) => setTimeout(resolve21, 50));
20417
+ await new Promise((resolve22) => setTimeout(resolve22, 50));
20165
20418
  }
20166
20419
  for (const directory of [...pendingClones, ...temporaryClones]) {
20167
20420
  try {
@@ -20170,8 +20423,8 @@ async function startWebServer(options) {
20170
20423
  }
20171
20424
  }
20172
20425
  server.closeAllConnections();
20173
- await new Promise((resolve21) => {
20174
- server.close(() => resolve21());
20426
+ await new Promise((resolve22) => {
20427
+ server.close(() => resolve22());
20175
20428
  });
20176
20429
  }
20177
20430
  };
@@ -20182,7 +20435,7 @@ import * as fs20 from "fs";
20182
20435
  import * as http3 from "http";
20183
20436
  import * as https from "https";
20184
20437
  import * as os2 from "os";
20185
- import * as path22 from "path";
20438
+ import * as path23 from "path";
20186
20439
  var PACKAGE_LATEST_URL = "https://registry.npmjs.org/codebase-snapshot/latest";
20187
20440
  var CHECK_INTERVAL_MS = 24 * 60 * 60 * 1e3;
20188
20441
  var UP_TO_DATE_INTERVAL_MS = 60 * 60 * 1e3;
@@ -20231,17 +20484,17 @@ function isNewer(candidate, current) {
20231
20484
  }
20232
20485
  function cacheDirectory(env = process.env, platform = process.platform) {
20233
20486
  if (platform === "win32") {
20234
- const base2 = env.LOCALAPPDATA ?? path22.join(os2.homedir(), "AppData", "Local");
20235
- return path22.join(base2, "codebase-snapshot");
20487
+ const base2 = env.LOCALAPPDATA ?? path23.join(os2.homedir(), "AppData", "Local");
20488
+ return path23.join(base2, "codebase-snapshot");
20236
20489
  }
20237
20490
  if (platform === "darwin") {
20238
- return path22.join(os2.homedir(), "Library", "Caches", "codebase-snapshot");
20491
+ return path23.join(os2.homedir(), "Library", "Caches", "codebase-snapshot");
20239
20492
  }
20240
- const base = env.XDG_CACHE_HOME ?? path22.join(os2.homedir(), ".cache");
20241
- return path22.join(base, "codebase-snapshot");
20493
+ const base = env.XDG_CACHE_HOME ?? path23.join(os2.homedir(), ".cache");
20494
+ return path23.join(base, "codebase-snapshot");
20242
20495
  }
20243
20496
  function cacheFilePath(env = process.env) {
20244
- return path22.join(cacheDirectory(env), "update-check.json");
20497
+ return path23.join(cacheDirectory(env), "update-check.json");
20245
20498
  }
20246
20499
  function shouldCheck(argv, env) {
20247
20500
  const disabled = ["1", "true", "yes"].includes(
@@ -20288,21 +20541,21 @@ function readCache(file) {
20288
20541
  }
20289
20542
  function writeCache(file, entry) {
20290
20543
  try {
20291
- fs20.mkdirSync(path22.dirname(file), { recursive: true });
20544
+ fs20.mkdirSync(path23.dirname(file), { recursive: true });
20292
20545
  fs20.writeFileSync(file, `${JSON.stringify(entry)}
20293
20546
  `, "utf8");
20294
20547
  } catch {
20295
20548
  }
20296
20549
  }
20297
20550
  function fetchLatestVersion(url = PACKAGE_LATEST_URL, timeoutMs = REQUEST_TIMEOUT_MS) {
20298
- return new Promise((resolve21) => {
20551
+ return new Promise((resolve22) => {
20299
20552
  let settled = false;
20300
20553
  let request = null;
20301
20554
  const finish = (value) => {
20302
20555
  if (settled) return;
20303
20556
  settled = true;
20304
20557
  clearTimeout(deadline);
20305
- resolve21(value);
20558
+ resolve22(value);
20306
20559
  };
20307
20560
  const deadline = setTimeout(() => {
20308
20561
  request?.destroy();
@@ -20388,7 +20641,7 @@ function formatUpdateNotice(notice, kind) {
20388
20641
 
20389
20642
  // src/auditor/health.ts
20390
20643
  import * as fs21 from "fs";
20391
- import * as path23 from "path";
20644
+ import * as path24 from "path";
20392
20645
  import { execFileSync as execFileSync3 } from "child_process";
20393
20646
  import { createHash as createHash8 } from "crypto";
20394
20647
  var ARTIFACT_FILES = {
@@ -20410,16 +20663,16 @@ var TEXT_ARTIFACT = /\.(md|json|txt|sarif|xml)$/i;
20410
20663
  function sha256(buffer) {
20411
20664
  return createHash8("sha256").update(buffer).digest("hex");
20412
20665
  }
20413
- function snapshotText(snapshotDir, relative20) {
20414
- const read = readConfinedText(snapshotDir, relative20);
20666
+ function snapshotText(snapshotDir, relative21) {
20667
+ const read = readConfinedText(snapshotDir, relative21);
20415
20668
  return read.ok ? read.text : null;
20416
20669
  }
20417
- function snapshotBytes(snapshotDir, relative20) {
20418
- const read = readConfinedBytes(snapshotDir, relative20);
20670
+ function snapshotBytes(snapshotDir, relative21) {
20671
+ const read = readConfinedBytes(snapshotDir, relative21);
20419
20672
  return read.ok ? read.bytes : null;
20420
20673
  }
20421
20674
  function readJson2(file) {
20422
- const confined = readConfinedText(path23.dirname(file), path23.basename(file));
20675
+ const confined = readConfinedText(path24.dirname(file), path24.basename(file));
20423
20676
  const text2 = confined.ok ? confined.text : null;
20424
20677
  if (text2 === null) return null;
20425
20678
  try {
@@ -20437,9 +20690,9 @@ function walk(dir, prefix = "") {
20437
20690
  }
20438
20691
  const files = [];
20439
20692
  for (const entry of entries) {
20440
- const relative20 = prefix === "" ? entry.name : prefix + "/" + entry.name;
20441
- if (entry.isDirectory()) files.push(...walk(path23.join(dir, entry.name), relative20));
20442
- else if (entry.isFile()) files.push(relative20);
20693
+ const relative21 = prefix === "" ? entry.name : prefix + "/" + entry.name;
20694
+ if (entry.isDirectory()) files.push(...walk(path24.join(dir, entry.name), relative21));
20695
+ else if (entry.isFile()) files.push(relative21);
20443
20696
  }
20444
20697
  return files;
20445
20698
  }
@@ -20481,9 +20734,9 @@ function readArtifactTexts(snapshotDir, maxBytes = 32 * 1024 * 1024) {
20481
20734
  const texts = [];
20482
20735
  let bytes = 0;
20483
20736
  let truncated = false;
20484
- for (const relative20 of walk(snapshotDir)) {
20485
- if (!TEXT_ARTIFACT.test(relative20)) continue;
20486
- const full = path23.join(snapshotDir, relative20);
20737
+ for (const relative21 of walk(snapshotDir)) {
20738
+ if (!TEXT_ARTIFACT.test(relative21)) continue;
20739
+ const full = path24.join(snapshotDir, relative21);
20487
20740
  let size2;
20488
20741
  try {
20489
20742
  size2 = fs21.statSync(full).size;
@@ -20494,7 +20747,7 @@ function readArtifactTexts(snapshotDir, maxBytes = 32 * 1024 * 1024) {
20494
20747
  truncated = true;
20495
20748
  continue;
20496
20749
  }
20497
- const text2 = snapshotText(snapshotDir, relative20);
20750
+ const text2 = snapshotText(snapshotDir, relative21);
20498
20751
  if (text2 !== null) {
20499
20752
  texts.push(text2);
20500
20753
  bytes += Buffer.byteLength(text2, "utf8");
@@ -20515,11 +20768,11 @@ function findHostPaths(snapshotDir, repoDir, maxBytes = 32 * 1024 * 1024) {
20515
20768
  const hits = /* @__PURE__ */ new Set();
20516
20769
  let scanned = 0;
20517
20770
  let truncated = false;
20518
- for (const relative20 of walk(snapshotDir)) {
20519
- if (!TEXT_ARTIFACT.test(relative20)) continue;
20771
+ for (const relative21 of walk(snapshotDir)) {
20772
+ if (!TEXT_ARTIFACT.test(relative21)) continue;
20520
20773
  let size2;
20521
20774
  try {
20522
- size2 = fs21.statSync(path23.join(snapshotDir, relative20)).size;
20775
+ size2 = fs21.statSync(path24.join(snapshotDir, relative21)).size;
20523
20776
  } catch {
20524
20777
  continue;
20525
20778
  }
@@ -20527,14 +20780,14 @@ function findHostPaths(snapshotDir, repoDir, maxBytes = 32 * 1024 * 1024) {
20527
20780
  truncated = true;
20528
20781
  continue;
20529
20782
  }
20530
- const text2 = snapshotText(snapshotDir, relative20);
20783
+ const text2 = snapshotText(snapshotDir, relative21);
20531
20784
  if (text2 === null) continue;
20532
20785
  scanned += Buffer.byteLength(text2, "utf8");
20533
20786
  for (const pattern of patterns) {
20534
- for (const match of text2.match(pattern) ?? []) hits.add(relative20 + ": " + match);
20787
+ for (const match of text2.match(pattern) ?? []) hits.add(relative21 + ": " + match);
20535
20788
  }
20536
20789
  repoPattern.lastIndex = 0;
20537
- if (repoPattern.test(text2)) hits.add(relative20 + ": the repository absolute path");
20790
+ if (repoPattern.test(text2)) hits.add(relative21 + ": the repository absolute path");
20538
20791
  }
20539
20792
  return { hits: [...hits], truncated };
20540
20793
  }
@@ -20592,13 +20845,13 @@ function summaryClaims(summary) {
20592
20845
  }
20593
20846
  return summary.headings.map((heading) => ({ field: "headings", value: heading }));
20594
20847
  }
20595
- function reportNumber(text2, label) {
20596
- const match = new RegExp("\\*\\*" + escapeRegExp(label) + ":\\*\\* `([0-9][0-9,]*)`").exec(text2);
20848
+ function reportNumber(text2, label2) {
20849
+ const match = new RegExp("\\*\\*" + escapeRegExp(label2) + ":\\*\\* `([0-9][0-9,]*)`").exec(text2);
20597
20850
  return match === null ? null : Number(match[1].replace(/,/g, ""));
20598
20851
  }
20599
- function reportMib(text2, label) {
20852
+ function reportMib(text2, label2) {
20600
20853
  const match = new RegExp(
20601
- "\\*\\*" + escapeRegExp(label) + ":\\*\\* `([0-9]+(?:\\.[0-9]+)?) MiB`"
20854
+ "\\*\\*" + escapeRegExp(label2) + ":\\*\\* `([0-9]+(?:\\.[0-9]+)?) MiB`"
20602
20855
  ).exec(text2);
20603
20856
  return match === null ? null : Number(match[1]);
20604
20857
  }
@@ -20684,10 +20937,10 @@ function markdownPackBodies(text2) {
20684
20937
  return bodies.size === 0 ? null : bodies;
20685
20938
  }
20686
20939
  function auditSnapshot(options) {
20687
- const snapshotDir = path23.resolve(options.snapshotDir);
20688
- const repoDir = path23.resolve(options.repoDir);
20940
+ const snapshotDir = path24.resolve(options.snapshotDir);
20941
+ const repoDir = path24.resolve(options.repoDir);
20689
20942
  const checks = [];
20690
- const manifestFile = path23.join(snapshotDir, "manifest.json");
20943
+ const manifestFile = path24.join(snapshotDir, "manifest.json");
20691
20944
  const raw = readJson2(manifestFile);
20692
20945
  const problem = raw === null ? "the file is missing or is not valid JSON" : describeManifestShapeProblem(raw);
20693
20946
  if (raw === null || problem !== null) {
@@ -20781,13 +21034,13 @@ function auditSnapshot(options) {
20781
21034
  let artifactCount = 0;
20782
21035
  for (const [key, value] of Object.entries(artifacts)) {
20783
21036
  if (value === null || value === void 0) continue;
20784
- const relative20 = ARTIFACT_FILES[key];
20785
- if (relative20 === void 0) continue;
21037
+ const relative21 = ARTIFACT_FILES[key];
21038
+ if (relative21 === void 0) continue;
20786
21039
  artifactCount += 1;
20787
- const bytes = snapshotBytes(snapshotDir, relative20);
20788
- if (bytes === null) artifactProblems.push(relative20 + " is missing");
21040
+ const bytes = snapshotBytes(snapshotDir, relative21);
21041
+ if (bytes === null) artifactProblems.push(relative21 + " is missing");
20789
21042
  else if (typeof value.sha256 === "string" && sha256(bytes) !== value.sha256) {
20790
- artifactProblems.push(relative20 + " changed");
21043
+ artifactProblems.push(relative21 + " changed");
20791
21044
  }
20792
21045
  }
20793
21046
  checks.push(
@@ -20831,7 +21084,7 @@ function auditSnapshot(options) {
20831
21084
  unexpected.length + " unexpected path(s): " + sample(unexpected)
20832
21085
  )
20833
21086
  );
20834
- const signaturePath = path23.join(snapshotDir, "signature.json");
21087
+ const signaturePath = path24.join(snapshotDir, "signature.json");
20835
21088
  if (fs21.existsSync(signaturePath)) {
20836
21089
  const outcome = verifySnapshotSignature(snapshotDir);
20837
21090
  checks.push(
@@ -20948,19 +21201,19 @@ function auditSnapshot(options) {
20948
21201
  );
20949
21202
  const reportProblems = [];
20950
21203
  let reportClaims = 0;
20951
- const compareNumber = (label, actual, expected) => {
21204
+ const compareNumber = (label2, actual, expected) => {
20952
21205
  if (actual === null) return;
20953
21206
  reportClaims += 1;
20954
21207
  if (actual !== expected) {
20955
- reportProblems.push(label + " says " + actual + ", the manifest says " + expected);
21208
+ reportProblems.push(label2 + " says " + actual + ", the manifest says " + expected);
20956
21209
  }
20957
21210
  };
20958
- const compareMib = (label, actual, bytes) => {
21211
+ const compareMib = (label2, actual, bytes) => {
20959
21212
  if (actual === null) return;
20960
21213
  reportClaims += 1;
20961
21214
  const expected = Number((bytes / (1024 * 1024)).toFixed(2));
20962
21215
  if (Math.abs(actual - expected) > 0.011) {
20963
- reportProblems.push(label + " says " + actual + " MiB, the manifest says " + expected);
21216
+ reportProblems.push(label2 + " says " + actual + " MiB, the manifest says " + expected);
20964
21217
  }
20965
21218
  };
20966
21219
  if (manifest.artifacts?.readme != null) {
@@ -21206,8 +21459,8 @@ function auditSnapshot(options) {
21206
21459
  for (const file of manifest.files) {
21207
21460
  if (!packed.has(file.relativePath)) problems.push(file.relativePath + " is in the manifest but not the pack");
21208
21461
  }
21209
- for (const path33 of packed) {
21210
- if (!known2.has(path33)) problems.push(path33 + " is in the pack but not the manifest");
21462
+ for (const path34 of packed) {
21463
+ if (!known2.has(path34)) problems.push(path34 + " is in the pack but not the manifest");
21211
21464
  }
21212
21465
  }
21213
21466
  }
@@ -21459,7 +21712,7 @@ function auditSnapshot(options) {
21459
21712
  )
21460
21713
  );
21461
21714
  }
21462
- const indexParent = path23.dirname(snapshotDir);
21715
+ const indexParent = path24.dirname(snapshotDir);
21463
21716
  const indexRead = readConfinedText(indexParent, "WORKSPACE.json");
21464
21717
  if (indexRead.ok) {
21465
21718
  let members = [];
@@ -21471,7 +21724,7 @@ function auditSnapshot(options) {
21471
21724
  } catch {
21472
21725
  problem2 = "it is not valid JSON";
21473
21726
  }
21474
- const memberName = path23.basename(snapshotDir);
21727
+ const memberName = path24.basename(snapshotDir);
21475
21728
  const member = members.find((entry) => entry.name === memberName);
21476
21729
  if (problem2 !== null) {
21477
21730
  checks.push(check(
@@ -21498,9 +21751,9 @@ function auditSnapshot(options) {
21498
21751
  let sourceGone = null;
21499
21752
  if (typeof member.path === "string") {
21500
21753
  const memberPath = member.path;
21501
- const candidates = [path23.dirname(indexParent), repoDir].map((anchor) => path23.resolve(anchor, memberPath)).filter((candidate) => {
21502
- const relative20 = path23.relative(repoDir, candidate);
21503
- return relative20 !== ".." && !relative20.startsWith(".." + path23.sep) && !path23.isAbsolute(relative20);
21754
+ const candidates = [path24.dirname(indexParent), repoDir].map((anchor) => path24.resolve(anchor, memberPath)).filter((candidate) => {
21755
+ const relative21 = path24.relative(repoDir, candidate);
21756
+ return relative21 !== ".." && !relative21.startsWith(".." + path24.sep) && !path24.isAbsolute(relative21);
21504
21757
  });
21505
21758
  const resolved = candidates.find((candidate) => fs21.existsSync(candidate)) ?? candidates[0];
21506
21759
  if (resolved === void 0) {
@@ -21512,8 +21765,8 @@ function auditSnapshot(options) {
21512
21765
  } catch {
21513
21766
  canonical = null;
21514
21767
  }
21515
- const canonicalRelative = canonical === null ? null : path23.relative(repoDir, canonical);
21516
- const canonicalInside = canonical !== null && (canonicalRelative === "" || canonicalRelative !== null && canonicalRelative !== ".." && !canonicalRelative.startsWith(`..${path23.sep}`) && !canonicalRelative.startsWith("../") && !path23.isAbsolute(canonicalRelative));
21768
+ const canonicalRelative = canonical === null ? null : path24.relative(repoDir, canonical);
21769
+ const canonicalInside = canonical !== null && (canonicalRelative === "" || canonicalRelative !== null && canonicalRelative !== ".." && !canonicalRelative.startsWith(`..${path24.sep}`) && !canonicalRelative.startsWith("../") && !path24.isAbsolute(canonicalRelative));
21517
21770
  if (canonical !== null && !canonicalInside) {
21518
21771
  sourceGone = "Member " + memberName + " source directory resolves outside the repository; not inspected.";
21519
21772
  } else if (canonical === null || !fs21.existsSync(resolved)) {
@@ -21543,12 +21796,12 @@ function auditSnapshot(options) {
21543
21796
  const leakHits = [];
21544
21797
  let scannedBytes = 0;
21545
21798
  let skippedArtifacts = 0;
21546
- for (const relative20 of walk(snapshotDir)) {
21547
- if (!TEXT_ARTIFACT.test(relative20)) continue;
21548
- if (relative20 === SIGNATURE_FILE) continue;
21799
+ for (const relative21 of walk(snapshotDir)) {
21800
+ if (!TEXT_ARTIFACT.test(relative21)) continue;
21801
+ if (relative21 === SIGNATURE_FILE) continue;
21549
21802
  let size2;
21550
21803
  try {
21551
- size2 = fs21.statSync(path23.join(snapshotDir, relative20)).size;
21804
+ size2 = fs21.statSync(path24.join(snapshotDir, relative21)).size;
21552
21805
  } catch {
21553
21806
  continue;
21554
21807
  }
@@ -21556,11 +21809,11 @@ function auditSnapshot(options) {
21556
21809
  skippedArtifacts += 1;
21557
21810
  continue;
21558
21811
  }
21559
- const text2 = snapshotText(snapshotDir, relative20);
21812
+ const text2 = snapshotText(snapshotDir, relative21);
21560
21813
  if (text2 === null) continue;
21561
21814
  scannedBytes += Buffer.byteLength(text2, "utf8");
21562
21815
  let findingCount = 0;
21563
- if (/^parts[\\/].*\.md$/i.test(relative20)) {
21816
+ if (/^parts[\\/].*\.md$/i.test(relative21)) {
21564
21817
  const lines = text2.split("\n");
21565
21818
  const sections = parsePartSections(text2);
21566
21819
  for (const section of sections) {
@@ -21572,18 +21825,18 @@ function auditSnapshot(options) {
21572
21825
  }
21573
21826
  }
21574
21827
  const headerText = lines.join("\n");
21575
- findingCount += scanAndRedactSecrets(headerText, rules, relative20).findings.length;
21828
+ findingCount += scanAndRedactSecrets(headerText, rules, relative21).findings.length;
21576
21829
  if ((options.secretRules ?? []).length > 0) {
21577
- findingCount += scanAndRedactSecrets(text2, options.secretRules ?? [], relative20).findings.length;
21830
+ findingCount += scanAndRedactSecrets(text2, options.secretRules ?? [], relative21).findings.length;
21578
21831
  }
21579
21832
  } else {
21580
- findingCount = scanAndRedactSecrets(text2, rules, relative20).findings.length;
21833
+ findingCount = scanAndRedactSecrets(text2, rules, relative21).findings.length;
21581
21834
  }
21582
21835
  if (findingCount > 0) {
21583
- leakHits.push(relative20 + " (" + findingCount + " line(s))");
21836
+ leakHits.push(relative21 + " (" + findingCount + " line(s))");
21584
21837
  }
21585
21838
  }
21586
- const signatureRecordPath = path23.join(snapshotDir, SIGNATURE_FILE);
21839
+ const signatureRecordPath = path24.join(snapshotDir, SIGNATURE_FILE);
21587
21840
  if (fs21.existsSync(signatureRecordPath)) {
21588
21841
  const recordText = snapshotText(snapshotDir, SIGNATURE_FILE);
21589
21842
  if (recordText !== null) {
@@ -21637,7 +21890,7 @@ function auditSnapshot(options) {
21637
21890
  for (const record of skippedSensitive.slice(0, 40)) {
21638
21891
  if (record.path.includes("[REDACTED") || compared > 400) continue;
21639
21892
  try {
21640
- if (fs21.statSync(path23.join(repoDir, record.path)).size > scanBudget) continue;
21893
+ if (fs21.statSync(path24.join(repoDir, record.path)).size > scanBudget) continue;
21641
21894
  } catch {
21642
21895
  continue;
21643
21896
  }
@@ -21800,7 +22053,7 @@ function report(snapshotDir, repoDir, checks) {
21800
22053
 
21801
22054
  // src/gitignore.ts
21802
22055
  import * as fs22 from "fs";
21803
- import * as path24 from "path";
22056
+ import * as path25 from "path";
21804
22057
  function decodeGitignore(buffer) {
21805
22058
  const startsWith = (...bytes) => buffer.length >= bytes.length && bytes.every((byte, index) => buffer[index] === byte);
21806
22059
  if (startsWith(239, 187, 191)) {
@@ -21849,7 +22102,7 @@ function canonicalIgnorePattern(line) {
21849
22102
  function appendGitignoreEntries(cwd, entries) {
21850
22103
  const wanted = [...new Set(entries)].filter((entry) => entry.trim().length > 0);
21851
22104
  if (wanted.length === 0) return { added: [], note: null };
21852
- const ignorePath = path24.join(cwd, ".gitignore");
22105
+ const ignorePath = path25.join(cwd, ".gitignore");
21853
22106
  const manual = `Add ${wanted.map((entry) => `"${entry}"`).join(" and ")} to your .gitignore yourself.`;
21854
22107
  let decoded = { text: "", bom: Buffer.alloc(0), encoding: "utf8" };
21855
22108
  try {
@@ -21866,8 +22119,8 @@ function appendGitignoreEntries(cwd, entries) {
21866
22119
  }
21867
22120
  const rootReal = fs22.realpathSync(cwd);
21868
22121
  const fileReal = fs22.realpathSync(ignorePath);
21869
- const relative20 = path24.relative(rootReal, fileReal);
21870
- if (relative20 === ".." || relative20.startsWith(`..${path24.sep}`) || path24.isAbsolute(relative20)) {
22122
+ const relative21 = path25.relative(rootReal, fileReal);
22123
+ if (relative21 === ".." || relative21.startsWith(`..${path25.sep}`) || path25.isAbsolute(relative21)) {
21871
22124
  return {
21872
22125
  added: [],
21873
22126
  note: `${ignorePath} resolves outside the repository, so it was not updated. ${manual}`
@@ -21912,12 +22165,12 @@ function appendGitignoreEntries(cwd, entries) {
21912
22165
  return { added, note: null };
21913
22166
  }
21914
22167
  function gitignorePath(cwd, filePath) {
21915
- return path24.relative(cwd, filePath).split(path24.sep).join("/");
22168
+ return path25.relative(cwd, filePath).split(path25.sep).join("/");
21916
22169
  }
21917
22170
 
21918
22171
  // src/wizard/init.ts
21919
22172
  import * as fs23 from "fs";
21920
- import * as path25 from "path";
22173
+ import * as path26 from "path";
21921
22174
 
21922
22175
  // src/wizard/brief-template.ts
21923
22176
  var BRIEF_SCAFFOLD_FILE = "BRIEF.md";
@@ -22368,7 +22621,7 @@ function keyReader(input) {
22368
22621
  next() {
22369
22622
  const queued = queue.shift();
22370
22623
  if (queued) return Promise.resolve(queued);
22371
- return new Promise((resolve21) => waiters.push(resolve21));
22624
+ return new Promise((resolve22) => waiters.push(resolve22));
22372
22625
  },
22373
22626
  close() {
22374
22627
  input.off("keypress", onKey);
@@ -22594,7 +22847,7 @@ function parsePackageJson(raw) {
22594
22847
  }
22595
22848
  function readPackageJson2(cwd) {
22596
22849
  try {
22597
- return parsePackageJson(fs23.readFileSync(path25.join(cwd, "package.json"), "utf8"));
22850
+ return parsePackageJson(fs23.readFileSync(path26.join(cwd, "package.json"), "utf8"));
22598
22851
  } catch {
22599
22852
  return null;
22600
22853
  }
@@ -22712,7 +22965,7 @@ function serializePackageJson(raw, value) {
22712
22965
  return `${bom}${text2}${raw.endsWith("\n") ? crlf ? "\r\n" : "\n" : ""}`;
22713
22966
  }
22714
22967
  function updatePackageJson(cwd, notes) {
22715
- const packagePath = path25.join(cwd, "package.json");
22968
+ const packagePath = path26.join(cwd, "package.json");
22716
22969
  const unchanged = {
22717
22970
  scripts: [],
22718
22971
  dependency: { name: GENERATOR_NAME, range: null, added: false }
@@ -22799,11 +23052,11 @@ function gitignoreEntriesFor(cwd, outDir, tmpDir) {
22799
23052
  const entries = [];
22800
23053
  for (const directory of [outDir, tmpDir]) {
22801
23054
  if (directory === null) continue;
22802
- const relative20 = path25.relative(cwd, path25.resolve(cwd, directory)).replace(/\\/g, "/");
22803
- if (relative20 === "" || relative20 === "." || relative20 === ".." || relative20.startsWith(`..${path25.sep}`) || relative20.startsWith("../") || path25.isAbsolute(relative20)) {
23055
+ const relative21 = path26.relative(cwd, path26.resolve(cwd, directory)).replace(/\\/g, "/");
23056
+ if (relative21 === "" || relative21 === "." || relative21 === ".." || relative21.startsWith(`..${path26.sep}`) || relative21.startsWith("../") || path26.isAbsolute(relative21)) {
22804
23057
  continue;
22805
23058
  }
22806
- entries.push(`/${relative20}/`);
23059
+ entries.push(`/${relative21}/`);
22807
23060
  }
22808
23061
  return [...new Set(entries)];
22809
23062
  }
@@ -23071,7 +23324,7 @@ async function runInit(options) {
23071
23324
  }
23072
23325
  const preferredName = chooseConfigFileName(options.cwd);
23073
23326
  const presentConfigs = CONFIG_CANDIDATES.filter(
23074
- (name) => fs23.existsSync(path25.join(options.cwd, name))
23327
+ (name) => fs23.existsSync(path26.join(options.cwd, name))
23075
23328
  );
23076
23329
  const present = presentConfigs[0] ?? null;
23077
23330
  if (presentConfigs.length > 1) {
@@ -23080,7 +23333,7 @@ async function runInit(options) {
23080
23333
  );
23081
23334
  }
23082
23335
  const configName = present !== null && options.force ? present : preferredName;
23083
- const configPath = path25.join(options.cwd, configName);
23336
+ const configPath = path26.join(options.cwd, configName);
23084
23337
  const configText = configName.endsWith(".json") || configName === ".snapshotrc" ? renderJsonConfig(answers) : renderConfig(answers);
23085
23338
  const reused = present !== null && options.force !== true && options.reuseConfig === true;
23086
23339
  if (reused) notes.push(`Kept the existing ${present} instead of writing a new one.`);
@@ -23098,7 +23351,7 @@ async function runInit(options) {
23098
23351
  dependency: { name: GENERATOR_NAME, range: `^${GENERATOR_VERSION}`, added: false },
23099
23352
  notes,
23100
23353
  outDir: answers.outDir,
23101
- briefPath: path25.join(options.cwd, BRIEF_SCAFFOLD_FILE),
23354
+ briefPath: path26.join(options.cwd, BRIEF_SCAFFOLD_FILE),
23102
23355
  briefWritten: false
23103
23356
  };
23104
23357
  }
@@ -23122,7 +23375,7 @@ async function runInit(options) {
23122
23375
  throw new Error(`${configName} already exists. Re-run with --force to replace it.`);
23123
23376
  }
23124
23377
  if (!reused) writeFileOrExplain(configPath, configText);
23125
- const briefPath = path25.join(options.cwd, BRIEF_SCAFFOLD_FILE);
23378
+ const briefPath = path26.join(options.cwd, BRIEF_SCAFFOLD_FILE);
23126
23379
  let briefWritten = false;
23127
23380
  if (!fs23.existsSync(briefPath)) {
23128
23381
  writeFileOrExplain(briefPath, BRIEF_SCAFFOLD);
@@ -23154,14 +23407,14 @@ async function runInit(options) {
23154
23407
 
23155
23408
  // src/wizard/autopilot.ts
23156
23409
  import * as fs24 from "fs";
23157
- import * as path26 from "path";
23410
+ import * as path27 from "path";
23158
23411
  function describeTarget(cwd) {
23159
- const relative20 = path26.relative(process.cwd(), cwd);
23160
- if (relative20 === "") return "this directory";
23161
- if (relative20 === ".." || relative20.startsWith(`..${path26.sep}`) || relative20.startsWith("../") || path26.isAbsolute(relative20)) {
23412
+ const relative21 = path27.relative(process.cwd(), cwd);
23413
+ if (relative21 === "") return "this directory";
23414
+ if (relative21 === ".." || relative21.startsWith(`..${path27.sep}`) || relative21.startsWith("../") || path27.isAbsolute(relative21)) {
23162
23415
  return cwd;
23163
23416
  }
23164
- return relative20;
23417
+ return relative21;
23165
23418
  }
23166
23419
  function firstRunMessage(reason, cwd) {
23167
23420
  const where = describeTarget(cwd);
@@ -23192,7 +23445,7 @@ function isEffectivelyEmpty(cwd) {
23192
23445
  function hasPriorSnapshot(cwd, outDir) {
23193
23446
  let parsed;
23194
23447
  try {
23195
- parsed = JSON.parse(fs24.readFileSync(path26.join(cwd, outDir, ".codebase-snapshot"), "utf8"));
23448
+ parsed = JSON.parse(fs24.readFileSync(path27.join(cwd, outDir, ".codebase-snapshot"), "utf8"));
23196
23449
  } catch {
23197
23450
  return false;
23198
23451
  }
@@ -23203,7 +23456,7 @@ function hasPriorSnapshot(cwd, outDir) {
23203
23456
  // src/agent/hook.ts
23204
23457
  import * as childProcess2 from "child_process";
23205
23458
  import * as fs25 from "fs";
23206
- import * as path27 from "path";
23459
+ import * as path28 from "path";
23207
23460
  var HOOK_MARKER = `# ${GENERATOR_NAME}: pre-commit snapshot check`;
23208
23461
  function shellQuote(value) {
23209
23462
  return value.replace(/[\\"`$]/g, (character) => `\\${character}`);
@@ -23245,7 +23498,7 @@ fi
23245
23498
  `;
23246
23499
  }
23247
23500
  function gitDirectory(cwd) {
23248
- const dotGit = path27.join(cwd, ".git");
23501
+ const dotGit = path28.join(cwd, ".git");
23249
23502
  let stats;
23250
23503
  try {
23251
23504
  stats = fs25.statSync(dotGit);
@@ -23259,42 +23512,42 @@ function gitDirectory(cwd) {
23259
23512
  const match = /^gitdir:\s*(.+)$/m.exec(contents);
23260
23513
  if (!match) return null;
23261
23514
  const target = match[1];
23262
- const resolved = path27.isAbsolute(target.trim()) ? target.trim() : path27.join(cwd, target.trim());
23515
+ const resolved = path28.isAbsolute(target.trim()) ? target.trim() : path28.join(cwd, target.trim());
23263
23516
  const cwdReal = canonicalForWrite(cwd);
23264
23517
  const resolvedReal = canonicalForWrite(resolved);
23265
23518
  if (cwdReal === null || resolvedReal === null || !fs25.statSync(resolvedReal).isDirectory()) {
23266
23519
  return null;
23267
23520
  }
23268
23521
  if (isInside4(cwdReal, resolvedReal)) return resolvedReal;
23269
- return isRegisteredWorktree(path27.resolve(resolved), cwd) ? resolvedReal : null;
23522
+ return isRegisteredWorktree(path28.resolve(resolved), cwd) ? resolvedReal : null;
23270
23523
  } catch {
23271
23524
  return null;
23272
23525
  }
23273
23526
  }
23274
23527
  function isInside4(parent, child) {
23275
- const relative20 = path27.relative(parent, child);
23276
- return relative20 === "" || relative20 !== ".." && !relative20.startsWith(`..${path27.sep}`) && !relative20.startsWith("../") && !path27.isAbsolute(relative20);
23528
+ const relative21 = path28.relative(parent, child);
23529
+ return relative21 === "" || relative21 !== ".." && !relative21.startsWith(`..${path28.sep}`) && !relative21.startsWith("../") && !path28.isAbsolute(relative21);
23277
23530
  }
23278
23531
  function canonicalForWrite(target) {
23279
- let existing = path27.resolve(target);
23532
+ let existing = path28.resolve(target);
23280
23533
  const tail = [];
23281
23534
  while (!fs25.existsSync(existing)) {
23282
- tail.unshift(path27.basename(existing));
23283
- const parent = path27.dirname(existing);
23535
+ tail.unshift(path28.basename(existing));
23536
+ const parent = path28.dirname(existing);
23284
23537
  if (parent === existing) break;
23285
23538
  existing = parent;
23286
23539
  }
23287
23540
  try {
23288
23541
  const real = fs25.realpathSync(existing);
23289
- return tail.length === 0 ? real : path27.join(real, ...tail);
23542
+ return tail.length === 0 ? real : path28.join(real, ...tail);
23290
23543
  } catch {
23291
23544
  return null;
23292
23545
  }
23293
23546
  }
23294
23547
  function isRegisteredWorktree(gitDir, cwd) {
23295
23548
  try {
23296
- const back = fs25.readFileSync(path27.join(gitDir, "gitdir"), "utf8").trim();
23297
- return path27.resolve(gitDir, back) === path27.join(path27.resolve(cwd), ".git");
23549
+ const back = fs25.readFileSync(path28.join(gitDir, "gitdir"), "utf8").trim();
23550
+ return path28.resolve(gitDir, back) === path28.join(path28.resolve(cwd), ".git");
23298
23551
  } catch {
23299
23552
  return false;
23300
23553
  }
@@ -23315,9 +23568,9 @@ function gitOutput(cwd, args) {
23315
23568
  function configuredHooksDirectory(cwd) {
23316
23569
  const hooks = gitOutput(cwd, ["rev-parse", "--git-path", "hooks"]);
23317
23570
  if (hooks === null) return null;
23318
- const resolved = path27.resolve(cwd, hooks);
23571
+ const resolved = path28.resolve(cwd, hooks);
23319
23572
  const common = gitOutput(cwd, ["rev-parse", "--git-common-dir"]);
23320
- const commonDir = common === null ? null : canonicalForWrite(path27.resolve(cwd, common));
23573
+ const commonDir = common === null ? null : canonicalForWrite(path28.resolve(cwd, common));
23321
23574
  const cwdReal = canonicalForWrite(cwd);
23322
23575
  const hooksReal = canonicalForWrite(resolved);
23323
23576
  if (hooksReal === null || cwdReal === null) {
@@ -23346,7 +23599,7 @@ function installPreCommitHook(cwd, outDir = "snapshot") {
23346
23599
  ]
23347
23600
  };
23348
23601
  }
23349
- const hooksDirRaw = configured === null ? path27.join(gitDir, "hooks") : configured.dir;
23602
+ const hooksDirRaw = configured === null ? path28.join(gitDir, "hooks") : configured.dir;
23350
23603
  const hooksDir = canonicalForWrite(hooksDirRaw);
23351
23604
  if (hooksDir === null) {
23352
23605
  return {
@@ -23355,7 +23608,7 @@ function installPreCommitHook(cwd, outDir = "snapshot") {
23355
23608
  notes: [`Refusing to write the hooks directory: ${hooksDirRaw} could not be resolved.`]
23356
23609
  };
23357
23610
  }
23358
- const hookPath = path27.join(hooksDir, "pre-commit");
23611
+ const hookPath = path28.join(hooksDir, "pre-commit");
23359
23612
  try {
23360
23613
  const existingStats = fs25.lstatSync(hookPath);
23361
23614
  if (existingStats.isSymbolicLink()) {
@@ -23615,7 +23868,7 @@ function briefFromPaths(cwd, request) {
23615
23868
  // src/runner.ts
23616
23869
  import { spawnSync as spawnSync3 } from "child_process";
23617
23870
  import * as fs26 from "fs";
23618
- import * as path28 from "path";
23871
+ import * as path29 from "path";
23619
23872
  var FULL_SUITE_TRIGGER = /(^|\/)(package\.json|tsconfig[^/]*\.json|jsconfig[^/]*\.json|vitest\.config\.[cm]?[jt]s|jest\.config\.[cm]?[jt]s|snapshot\.config\.[cm]?[jt]s|pnpm-workspace\.yaml|yarn\.lock|package-lock\.json|pnpm-lock\.yaml|\.github\/workflows\/)/;
23620
23873
  function packageJson(cwd) {
23621
23874
  const read = readConfinedText(cwd, "package.json", 4 * 1024 * 1024);
@@ -23632,14 +23885,14 @@ function foldPath(value) {
23632
23885
  return CASE_INSENSITIVE_PATHS2 ? value.toLowerCase() : value;
23633
23886
  }
23634
23887
  function insideDirectory(root, candidate) {
23635
- const normalizedRoot = foldPath(path28.resolve(root));
23636
- const normalizedCandidate = foldPath(path28.resolve(candidate));
23637
- return normalizedCandidate === normalizedRoot || normalizedCandidate.startsWith(normalizedRoot + path28.sep);
23888
+ const normalizedRoot = foldPath(path29.resolve(root));
23889
+ const normalizedCandidate = foldPath(path29.resolve(candidate));
23890
+ return normalizedCandidate === normalizedRoot || normalizedCandidate.startsWith(normalizedRoot + path29.sep);
23638
23891
  }
23639
- function confinedFile(cwd, relative20) {
23892
+ function confinedFile(cwd, relative21) {
23640
23893
  try {
23641
23894
  const realRoot = fs26.realpathSync(cwd);
23642
- const candidate = path28.resolve(cwd, relative20);
23895
+ const candidate = path29.resolve(cwd, relative21);
23643
23896
  if (!insideDirectory(cwd, candidate)) return null;
23644
23897
  const stat = fs26.lstatSync(candidate);
23645
23898
  if (!stat.isFile()) return null;
@@ -23651,14 +23904,14 @@ function confinedFile(cwd, relative20) {
23651
23904
  }
23652
23905
  }
23653
23906
  function hasPackage(cwd, name) {
23654
- return confinedFile(cwd, path28.join("node_modules", name, "package.json")) !== null;
23907
+ return confinedFile(cwd, path29.join("node_modules", name, "package.json")) !== null;
23655
23908
  }
23656
23909
  function sanitizePaths(cwd, paths) {
23657
- const root = path28.resolve(cwd);
23910
+ const root = path29.resolve(cwd);
23658
23911
  return paths.map((value) => value.replace(/\\/g, "/").replace(/^\.\/+/, "")).filter((value) => {
23659
23912
  if (value.length === 0 || value.startsWith("/") || /^[A-Za-z]:\//.test(value)) return false;
23660
23913
  if (value.split("/").includes("..")) return false;
23661
- return insideDirectory(root, path28.resolve(root, value));
23914
+ return insideDirectory(root, path29.resolve(root, value));
23662
23915
  }).map((value) => value.startsWith("-") ? "./" + value : value);
23663
23916
  }
23664
23917
  function unsupportedCustomScript(script) {
@@ -23678,7 +23931,7 @@ function planTestRun(cwd, input) {
23678
23931
  const testScript = typeof scripts === "object" && scripts !== null && !Array.isArray(scripts) ? scripts.test : void 0;
23679
23932
  const script = typeof testScript === "string" ? testScript : "";
23680
23933
  if (hasPackage(cwd, "vitest") || /\bvitest\b/.test(script)) {
23681
- const entry = ["node_modules/vitest/vitest.mjs", "node_modules/vitest/dist/cli.js"].map((relative20) => confinedFile(cwd, relative20)).find((resolved) => resolved !== null);
23934
+ const entry = ["node_modules/vitest/vitest.mjs", "node_modules/vitest/dist/cli.js"].map((relative21) => confinedFile(cwd, relative21)).find((resolved) => resolved !== null);
23682
23935
  if (entry !== void 0) {
23683
23936
  if (changed.length === 0) {
23684
23937
  return {
@@ -23770,16 +24023,16 @@ var SUMMARY_MAX_SOURCE_BYTES2 = SUMMARY_MAX_SOURCE_BYTES;
23770
24023
  var FILE_DERIVATIONS = /* @__PURE__ */ new Map();
23771
24024
  var FILE_DERIVATION_LIMIT_BYTES = 64 * 1024 * 1024;
23772
24025
  var fileDerivationBytes = 0;
23773
- function takeDerivation(path33, relativePath, hash, settings) {
23774
- const key = path33 + "\0" + relativePath;
24026
+ function takeDerivation(path34, relativePath, hash, settings) {
24027
+ const key = path34 + "\0" + relativePath;
23775
24028
  const cached = FILE_DERIVATIONS.get(key);
23776
24029
  if (cached === void 0 || cached.hash !== hash || cached.settings !== settings) return void 0;
23777
24030
  FILE_DERIVATIONS.delete(key);
23778
24031
  FILE_DERIVATIONS.set(key, cached);
23779
24032
  return cached;
23780
24033
  }
23781
- function rememberDerivation(path33, relativePath, hash, settings, derivation) {
23782
- const key = path33 + "\0" + relativePath;
24034
+ function rememberDerivation(path34, relativePath, hash, settings, derivation) {
24035
+ const key = path34 + "\0" + relativePath;
23783
24036
  const bodyBytes = derivation.finalContent === derivation.redacted ? derivation.redacted.length : derivation.redacted.length + derivation.finalContent.length;
23784
24037
  const bytes = bodyBytes * 2 + 512;
23785
24038
  if (bytes > FILE_DERIVATION_LIMIT_BYTES / 4) return;
@@ -24084,15 +24337,15 @@ function verifyInMemory(files, parts, unaccounted) {
24084
24337
  return errors;
24085
24338
  }
24086
24339
  function resolveSafeOutputDirs(config) {
24087
- const cwd = path29.resolve(config.cwd);
24088
- const outDir = path29.resolve(cwd, config.outDir);
24089
- const tmpDir = path29.resolve(cwd, config.tmpDir);
24090
- const root = path29.parse(cwd).root;
24340
+ const cwd = path30.resolve(config.cwd);
24341
+ const outDir = path30.resolve(cwd, config.outDir);
24342
+ const tmpDir = path30.resolve(cwd, config.tmpDir);
24343
+ const root = path30.parse(cwd).root;
24091
24344
  const fold = (value) => process.platform === "win32" || process.platform === "darwin" ? value.toLowerCase() : value;
24092
24345
  const contains = (parent, child) => {
24093
24346
  const foldedParent = fold(parent);
24094
24347
  const foldedChild = fold(child);
24095
- return foldedChild === foldedParent || foldedChild.startsWith(`${foldedParent}${path29.sep}`);
24348
+ return foldedChild === foldedParent || foldedChild.startsWith(`${foldedParent}${path30.sep}`);
24096
24349
  };
24097
24350
  const reject = (reason) => {
24098
24351
  throw new Error(
@@ -24187,9 +24440,9 @@ function listEntries(dir) {
24187
24440
  return;
24188
24441
  }
24189
24442
  for (const child of children) {
24190
- const relative20 = prefix === "" ? child.name : `${prefix}/${child.name}`;
24191
- entries.push(relative20);
24192
- if (child.isDirectory()) walk2(path29.join(absolute, child.name), relative20);
24443
+ const relative21 = prefix === "" ? child.name : `${prefix}/${child.name}`;
24444
+ entries.push(relative21);
24445
+ if (child.isDirectory()) walk2(path30.join(absolute, child.name), relative21);
24193
24446
  }
24194
24447
  };
24195
24448
  walk2(dir, "");
@@ -24201,7 +24454,7 @@ function markerInventory(dir, written) {
24201
24454
  for (const entry of entries) {
24202
24455
  if (entry === OWNERSHIP_MARKER) continue;
24203
24456
  if (isIgnorableEntry(entry)) continue;
24204
- const full = path29.join(dir, ...entry.split("/"));
24457
+ const full = path30.join(dir, ...entry.split("/"));
24205
24458
  let stats;
24206
24459
  try {
24207
24460
  stats = fs27.lstatSync(full);
@@ -24238,7 +24491,7 @@ function markerPayload(dir, state, id, createdAt, written, runId) {
24238
24491
  entries,
24239
24492
  files
24240
24493
  };
24241
- const manifestPath = path29.join(dir, "manifest.json");
24494
+ const manifestPath = path30.join(dir, "manifest.json");
24242
24495
  if (fs27.existsSync(manifestPath)) {
24243
24496
  marker2.manifestSha256 = sha256Hex2(fs27.readFileSync(manifestPath));
24244
24497
  }
@@ -24246,7 +24499,7 @@ function markerPayload(dir, state, id, createdAt, written, runId) {
24246
24499
  }
24247
24500
  function writeOwnershipMarker(dir, marker2) {
24248
24501
  fs27.writeFileSync(
24249
- path29.join(dir, OWNERSHIP_MARKER),
24502
+ path30.join(dir, OWNERSHIP_MARKER),
24250
24503
  `${JSON.stringify(marker2, null, 2)}
24251
24504
  `,
24252
24505
  "utf8"
@@ -24258,7 +24511,7 @@ function markerBelongsTo(dir, id) {
24258
24511
  return evidence.marker.id === id;
24259
24512
  }
24260
24513
  function readOwnershipMarker(dir) {
24261
- const markerPath = path29.join(dir, OWNERSHIP_MARKER);
24514
+ const markerPath = path30.join(dir, OWNERSHIP_MARKER);
24262
24515
  if (!fs27.existsSync(markerPath)) {
24263
24516
  return { marker: null, problem: "it holds no .codebase-snapshot marker" };
24264
24517
  }
@@ -24365,7 +24618,7 @@ function verifyMarkerInventory(dir, entries, files) {
24365
24618
  for (const entry of entries) {
24366
24619
  if (entry === OWNERSHIP_MARKER) continue;
24367
24620
  if (IGNORABLE_ENTRIES.has(entry.slice(entry.lastIndexOf("/") + 1))) continue;
24368
- const full = path29.join(dir, ...entry.split("/"));
24621
+ const full = path30.join(dir, ...entry.split("/"));
24369
24622
  let stats;
24370
24623
  try {
24371
24624
  stats = fs27.lstatSync(full);
@@ -24414,7 +24667,7 @@ function assessSnapshotDirectory(dir) {
24414
24667
  marker: marker2
24415
24668
  };
24416
24669
  }
24417
- const manifestPath = path29.join(dir, "manifest.json");
24670
+ const manifestPath = path30.join(dir, "manifest.json");
24418
24671
  const hasManifest = fs27.existsSync(manifestPath);
24419
24672
  if (hasManifest) {
24420
24673
  let raw;
@@ -24526,7 +24779,7 @@ function containsNoFiles(dir) {
24526
24779
  }
24527
24780
  for (const entry of entries) {
24528
24781
  if (entry.isDirectory()) {
24529
- pending.push(path29.join(current, entry.name));
24782
+ pending.push(path30.join(current, entry.name));
24530
24783
  } else if (!IGNORABLE_ENTRIES.has(entry.name)) {
24531
24784
  return false;
24532
24785
  }
@@ -24534,11 +24787,11 @@ function containsNoFiles(dir) {
24534
24787
  }
24535
24788
  return true;
24536
24789
  }
24537
- function assertReplaceable(target, label, secretRules) {
24790
+ function assertReplaceable(target, label2, secretRules) {
24538
24791
  if (!fs27.existsSync(target)) return;
24539
24792
  if (!fs27.statSync(target).isDirectory()) {
24540
24793
  throw new Error(
24541
- `Refusing to write into ${label} ${target}: it exists but is not a directory.`
24794
+ `Refusing to write into ${label2} ${target}: it exists but is not a directory.`
24542
24795
  );
24543
24796
  }
24544
24797
  const entries = fs27.readdirSync(target);
@@ -24552,12 +24805,12 @@ function assertReplaceable(target, label, secretRules) {
24552
24805
  const shownEntries = entries.map((name) => maskPathText(name, secretRules));
24553
24806
  if (verdict.foreignEntries.length > 0) {
24554
24807
  throw new Error(
24555
- `Refusing to replace ${label} ${target}: it carries this generator's ownership marker, but these entries are not part of the snapshot it recorded: ${describeEntries(shownForeign)}. Remove them yourself, or point ${label} at a new or empty directory.`
24808
+ `Refusing to replace ${label2} ${target}: it carries this generator's ownership marker, but these entries are not part of the snapshot it recorded: ${describeEntries(shownForeign)}. Remove them yourself, or point ${label2} at a new or empty directory.`
24556
24809
  );
24557
24810
  }
24558
24811
  const reason = verdict.problem ?? problem ?? "it does not look like a snapshot this generator wrote";
24559
24812
  throw new Error(
24560
- `Refusing to replace ${label} ${target}: ${reason} (found ${describeEntries(shownEntries)}). Remove the directory yourself, or point ${label} at a new or empty directory.`
24813
+ `Refusing to replace ${label2} ${target}: ${reason} (found ${describeEntries(shownEntries)}). Remove the directory yourself, or point ${label2} at a new or empty directory.`
24561
24814
  );
24562
24815
  }
24563
24816
  function assertStagingRootUsable(tmpDir, secretRules) {
@@ -24568,7 +24821,7 @@ function assertStagingRootUsable(tmpDir, secretRules) {
24568
24821
  const entries = fs27.readdirSync(tmpDir);
24569
24822
  if (entries.length === 0) return;
24570
24823
  const foreign = entries.filter((name) => {
24571
- const full = path29.join(tmpDir, name);
24824
+ const full = path30.join(tmpDir, name);
24572
24825
  if (!name.startsWith(RUN_DIR_PREFIX)) return true;
24573
24826
  let stats;
24574
24827
  try {
@@ -24601,7 +24854,7 @@ function cleanStaleRunDirs(tmpDir) {
24601
24854
  }
24602
24855
  for (const name of entries) {
24603
24856
  if (!name.startsWith(RUN_DIR_PREFIX)) continue;
24604
- const full = path29.join(tmpDir, name);
24857
+ const full = path30.join(tmpDir, name);
24605
24858
  const { marker: marker2 } = readOwnershipMarker(full);
24606
24859
  if (marker2) {
24607
24860
  const created = Date.parse(marker2.createdAt);
@@ -24627,18 +24880,18 @@ function removeIfEmpty(dir) {
24627
24880
  } catch {
24628
24881
  }
24629
24882
  }
24630
- function ensureParentDirectory(target, label) {
24631
- const parent = path29.dirname(target);
24883
+ function ensureParentDirectory(target, label2) {
24884
+ const parent = path30.dirname(target);
24632
24885
  if (fs27.existsSync(parent) && !fs27.statSync(parent).isDirectory()) {
24633
24886
  throw new Error(
24634
- `Refusing to create ${label} ${target}: ${parent} exists but is not a directory.`
24887
+ `Refusing to create ${label2} ${target}: ${parent} exists but is not a directory.`
24635
24888
  );
24636
24889
  }
24637
24890
  try {
24638
24891
  fs27.mkdirSync(parent, { recursive: true });
24639
24892
  } catch (err) {
24640
24893
  throw new Error(
24641
- `Refusing to create ${label} ${target}: its parent ${parent} could not be created (${err.message}).`
24894
+ `Refusing to create ${label2} ${target}: its parent ${parent} could not be created (${err.message}).`
24642
24895
  );
24643
24896
  }
24644
24897
  }
@@ -24729,22 +24982,22 @@ function lockKeyFor(stagingRoot) {
24729
24982
  return sha256Hex2(key).slice(0, 16);
24730
24983
  }
24731
24984
  function canonicalLockTarget(targetPath2) {
24732
- const resolved = path29.resolve(targetPath2);
24985
+ const resolved = path30.resolve(targetPath2);
24733
24986
  let existing = resolved;
24734
24987
  const tail = [];
24735
24988
  for (; ; ) {
24736
24989
  try {
24737
- return path29.join(fs27.realpathSync(existing), ...tail);
24990
+ return path30.join(fs27.realpathSync(existing), ...tail);
24738
24991
  } catch {
24739
- const parent = path29.dirname(existing);
24992
+ const parent = path30.dirname(existing);
24740
24993
  if (parent === existing) return resolved;
24741
- tail.unshift(path29.basename(existing));
24994
+ tail.unshift(path30.basename(existing));
24742
24995
  existing = parent;
24743
24996
  }
24744
24997
  }
24745
24998
  }
24746
24999
  function lockPathFor(stagingRoot) {
24747
- return path29.join(os3.tmpdir(), `codebase-snapshot-${lockKeyFor(stagingRoot)}.lock`);
25000
+ return path30.join(os3.tmpdir(), `codebase-snapshot-${lockKeyFor(stagingRoot)}.lock`);
24748
25001
  }
24749
25002
  function releaseAbandonedRun(stagingRoots, runId) {
24750
25003
  if (runId.length === 0) return;
@@ -24763,7 +25016,7 @@ function releaseAbandonedRun(stagingRoots, runId) {
24763
25016
  }
24764
25017
  for (const name of entries) {
24765
25018
  if (!name.startsWith(RUN_DIR_PREFIX)) continue;
24766
- const directory = path29.join(root, name);
25019
+ const directory = path30.join(root, name);
24767
25020
  const { marker: marker2 } = readOwnershipMarker(directory);
24768
25021
  if (marker2?.runId !== runId) continue;
24769
25022
  try {
@@ -24858,8 +25111,8 @@ function swapIntoPlace(stagingDir, outDir, beforeSwap, onStagingPreserved) {
24858
25111
  }
24859
25112
  function recoverInterruptedPublish(outDir) {
24860
25113
  if (fs27.existsSync(outDir)) return;
24861
- const parent = path29.dirname(outDir);
24862
- const base = path29.basename(outDir);
25114
+ const parent = path30.dirname(outDir);
25115
+ const base = path30.basename(outDir);
24863
25116
  let backups;
24864
25117
  try {
24865
25118
  backups = fs27.readdirSync(parent).filter((name) => name.startsWith(`${base}.backup-`));
@@ -24867,7 +25120,7 @@ function recoverInterruptedPublish(outDir) {
24867
25120
  return;
24868
25121
  }
24869
25122
  if (backups.length !== 1) return;
24870
- const backupDir = path29.join(parent, backups[0]);
25123
+ const backupDir = path30.join(parent, backups[0]);
24871
25124
  const { marker: marker2, problem } = readOwnershipMarker(backupDir);
24872
25125
  if (problem !== null || marker2 === null || marker2.state !== "complete") return;
24873
25126
  try {
@@ -25111,9 +25364,9 @@ function generateSnapshot(configInput, options) {
25111
25364
  // first run cannot have marked them yet, so the name alone keeps a run from recording its own
25112
25365
  // output — but only at these exact paths, not at every directory that shares the name.
25113
25366
  toolOwnedPaths: [config.outDir, config.tmpDir].map(
25114
- (directory) => path29.relative(config.cwd, path29.resolve(config.cwd, directory)).replace(/\\/g, "/")
25367
+ (directory) => path30.relative(config.cwd, path30.resolve(config.cwd, directory)).replace(/\\/g, "/")
25115
25368
  ).filter(
25116
- (relative20) => relative20.length > 0 && relative20 !== ".." && !relative20.startsWith(`..${path29.sep}`) && !relative20.startsWith("../") && !path29.isAbsolute(relative20)
25369
+ (relative21) => relative21.length > 0 && relative21 !== ".." && !relative21.startsWith(`..${path30.sep}`) && !relative21.startsWith("../") && !path30.isAbsolute(relative21)
25117
25370
  ),
25118
25371
  // A staged path can be absent from the working tree while its index blob exists. Discovery
25119
25372
  // lists the working tree, so those paths would never reach the scan at all.
@@ -25142,7 +25395,7 @@ function generateSnapshot(configInput, options) {
25142
25395
  let totalSizeBytes = 0;
25143
25396
  let largeFileCount = 0;
25144
25397
  for (const relativePath of candidateFiles) {
25145
- const absolutePath = path29.join(config.cwd, relativePath);
25398
+ const absolutePath = path30.join(config.cwd, relativePath);
25146
25399
  const fromIndex = stagedPaths.has(relativePath);
25147
25400
  let buffer;
25148
25401
  let sizeBytes;
@@ -25175,7 +25428,7 @@ function generateSnapshot(configInput, options) {
25175
25428
  try {
25176
25429
  stats = fs27.statSync(absolutePath);
25177
25430
  if (!stats.isFile()) {
25178
- const nestedRepository = stats.isDirectory() && fs27.existsSync(path29.join(absolutePath, ".git"));
25431
+ const nestedRepository = stats.isDirectory() && fs27.existsSync(path30.join(absolutePath, ".git"));
25179
25432
  skipped.push(
25180
25433
  nestedRepository ? {
25181
25434
  path: relativePath,
@@ -25328,14 +25581,14 @@ function generateSnapshot(configInput, options) {
25328
25581
  }
25329
25582
  retain(secretFindings, (finding) => finding.path === void 0 || keep.has(finding.path));
25330
25583
  retain(encodingNotes, (note) => keep.has(note.path));
25331
- retain(oversizeSummaryPaths, (path33) => keep.has(path33));
25332
- retain(previewSummaryPaths, (path33) => keep.has(path33));
25584
+ retain(oversizeSummaryPaths, (path34) => keep.has(path34));
25585
+ retain(previewSummaryPaths, (path34) => keep.has(path34));
25333
25586
  retain(fileWarnings, (warning) => keep.has(warning.path));
25334
- for (const path33 of [...monolithBodies.keys()]) {
25335
- if (!keep.has(path33)) monolithBodies.delete(path33);
25587
+ for (const path34 of [...monolithBodies.keys()]) {
25588
+ if (!keep.has(path34)) monolithBodies.delete(path34);
25336
25589
  }
25337
- for (const path33 of [...skippedSummaryImports.keys()]) {
25338
- if (!keep.has(path33)) skippedSummaryImports.delete(path33);
25590
+ for (const path34 of [...skippedSummaryImports.keys()]) {
25591
+ if (!keep.has(path34)) skippedSummaryImports.delete(path34);
25339
25592
  }
25340
25593
  };
25341
25594
  if (changedScope !== null && changedPaths !== null && config.withDependents === true) {
@@ -25959,7 +26212,7 @@ function generateSnapshot(configInput, options) {
25959
26212
  cleanStaleRunDirs(tmpDir);
25960
26213
  const snapshotId = crypto6.randomUUID();
25961
26214
  const createdAt = (/* @__PURE__ */ new Date()).toISOString();
25962
- stagingDir = path29.join(tmpDir, `${RUN_DIR_PREFIX}${process.pid}-${snapshotId.slice(0, 8)}`);
26215
+ stagingDir = path30.join(tmpDir, `${RUN_DIR_PREFIX}${process.pid}-${snapshotId.slice(0, 8)}`);
25963
26216
  fs27.mkdirSync(stagingDir);
25964
26217
  writeOwnershipMarker(stagingDir, {
25965
26218
  generator: GENERATOR_NAME,
@@ -25971,17 +26224,17 @@ function generateSnapshot(configInput, options) {
25971
26224
  runId,
25972
26225
  pid: process.pid
25973
26226
  });
25974
- const partsDir = path29.join(stagingDir, "parts");
25975
- const reportsDir = path29.join(stagingDir, "reports");
26227
+ const partsDir = path30.join(stagingDir, "parts");
26228
+ const reportsDir = path30.join(stagingDir, "reports");
25976
26229
  if (artifacts.parts) fs27.mkdirSync(partsDir, { recursive: true });
25977
26230
  if (artifacts.navigation || artifacts.projectTree || artifacts.audit || artifacts.diff || artifacts.log || artifacts.tokenTree || config.sarif === true) {
25978
26231
  fs27.mkdirSync(reportsDir, { recursive: true });
25979
26232
  }
25980
26233
  const writtenArtifacts = /* @__PURE__ */ new Map();
25981
- const ledgerRoot = (targetDir) => stagingDir !== null && (targetDir === stagingDir || targetDir.startsWith(stagingDir + path29.sep)) ? stagingDir : outDir;
25982
- const ledgerEntry = (targetDir, relativeEntry) => path29.relative(ledgerRoot(targetDir), path29.join(targetDir, ...relativeEntry.split("/"))).split(path29.sep).join("/");
26234
+ const ledgerRoot = (targetDir) => stagingDir !== null && (targetDir === stagingDir || targetDir.startsWith(stagingDir + path30.sep)) ? stagingDir : outDir;
26235
+ const ledgerEntry = (targetDir, relativeEntry) => path30.relative(ledgerRoot(targetDir), path30.join(targetDir, ...relativeEntry.split("/"))).split(path30.sep).join("/");
25983
26236
  const writeArtifact = (targetDir, relativeEntry, data) => {
25984
- const full = path29.join(targetDir, ...relativeEntry.split("/"));
26237
+ const full = path30.join(targetDir, ...relativeEntry.split("/"));
25985
26238
  fs27.writeFileSync(full, data, "utf8");
25986
26239
  const stats = fs27.statSync(full);
25987
26240
  const entry = ledgerEntry(targetDir, relativeEntry);
@@ -25991,7 +26244,7 @@ function generateSnapshot(configInput, options) {
25991
26244
  });
25992
26245
  };
25993
26246
  const recordArtifact = (targetDir, relativeEntry) => {
25994
- const full = path29.join(targetDir, ...relativeEntry.split("/"));
26247
+ const full = path30.join(targetDir, ...relativeEntry.split("/"));
25995
26248
  const stats = fs27.statSync(full);
25996
26249
  const entry = ledgerEntry(targetDir, relativeEntry);
25997
26250
  writtenArtifacts.set(entry, {
@@ -26047,7 +26300,7 @@ function generateSnapshot(configInput, options) {
26047
26300
  "Refusing to sign: manifest.json is disabled for this run. Signing covers the manifest, so enable the manifest artifact or drop --sign."
26048
26301
  );
26049
26302
  }
26050
- const record = signManifest(path29.join(stagingDir, "manifest.json"), {
26303
+ const record = signManifest(path30.join(stagingDir, "manifest.json"), {
26051
26304
  key: options.sign.key ?? null
26052
26305
  });
26053
26306
  writeArtifact(stagingDir, SIGNATURE_FILE, JSON.stringify(record, null, 2) + "\n");
@@ -26079,10 +26332,10 @@ function generateSnapshot(configInput, options) {
26079
26332
  const shipHookState = () => {
26080
26333
  if (!markerBelongsTo(outDir, snapshotId)) return;
26081
26334
  if (artifacts.manifest && manifest.warnings.length !== warningsBeforeHook) {
26082
- writeManifestAtomically(path29.join(outDir, "manifest.json"), manifest);
26335
+ writeManifestAtomically(path30.join(outDir, "manifest.json"), manifest);
26083
26336
  recordArtifact(outDir, "manifest.json");
26084
26337
  if (options?.sign !== void 0) {
26085
- const record = signManifest(path29.join(outDir, "manifest.json"), {
26338
+ const record = signManifest(path30.join(outDir, "manifest.json"), {
26086
26339
  key: options.sign.key ?? null
26087
26340
  });
26088
26341
  writeArtifact(outDir, SIGNATURE_FILE, JSON.stringify(record, null, 2) + "\n");
@@ -26149,11 +26402,11 @@ function sha256Hex3(input) {
26149
26402
  return crypto7.createHash("sha256").update(input).digest("hex");
26150
26403
  }
26151
26404
  function manifestPathFor2(config) {
26152
- return path30.resolve(config.cwd, config.outDir, "manifest.json");
26405
+ return path31.resolve(config.cwd, config.outDir, "manifest.json");
26153
26406
  }
26154
26407
  function readBaseline(config) {
26155
26408
  const file = manifestPathFor2(config);
26156
- const read = readConfinedText(path30.dirname(file), path30.basename(file), MAX_MANIFEST_BYTES2);
26409
+ const read = readConfinedText(path31.dirname(file), path31.basename(file), MAX_MANIFEST_BYTES2);
26157
26410
  if (!read.ok) return null;
26158
26411
  let parsed;
26159
26412
  try {
@@ -26228,28 +26481,28 @@ function collectStatStamps(config, manifest, gitState) {
26228
26481
  if (manifest.files.length > 500) return [];
26229
26482
  for (const file of manifest.files) {
26230
26483
  candidates.add(file.relativePath);
26231
- let dir = path30.posix.dirname(file.relativePath);
26484
+ let dir = path31.posix.dirname(file.relativePath);
26232
26485
  while (dir !== "." && dir !== "/" && dir.length > 0) {
26233
26486
  candidates.add(dir);
26234
- const parent = path30.posix.dirname(dir);
26487
+ const parent = path31.posix.dirname(dir);
26235
26488
  if (parent === dir) break;
26236
26489
  dir = parent;
26237
26490
  }
26238
26491
  }
26239
26492
  }
26240
26493
  const stamps = [];
26241
- for (const relative20 of [...candidates].sort((left, right) => left.localeCompare(right))) {
26242
- const target = relative20.length === 0 ? config.cwd : path30.join(config.cwd, relative20);
26494
+ for (const relative21 of [...candidates].sort((left, right) => left.localeCompare(right))) {
26495
+ const target = relative21.length === 0 ? config.cwd : path31.join(config.cwd, relative21);
26243
26496
  try {
26244
26497
  const stat = fs28.lstatSync(target);
26245
26498
  stamps.push({
26246
- path: relative20,
26499
+ path: relative21,
26247
26500
  exists: true,
26248
26501
  mtimeMs: stat.mtimeMs,
26249
26502
  size: stat.size
26250
26503
  });
26251
26504
  } catch {
26252
- stamps.push({ path: relative20, exists: false, mtimeMs: 0, size: 0 });
26505
+ stamps.push({ path: relative21, exists: false, mtimeMs: 0, size: 0 });
26253
26506
  }
26254
26507
  }
26255
26508
  return stamps;
@@ -26257,7 +26510,7 @@ function collectStatStamps(config, manifest, gitState) {
26257
26510
  function stampsMatch(cwd, stamps) {
26258
26511
  if (stamps.length === 0) return false;
26259
26512
  for (const stamp of stamps) {
26260
- const target = stamp.path.length === 0 ? cwd : path30.join(cwd, stamp.path);
26513
+ const target = stamp.path.length === 0 ? cwd : path31.join(cwd, stamp.path);
26261
26514
  try {
26262
26515
  const stat = fs28.lstatSync(target);
26263
26516
  if (!stamp.exists || stat.mtimeMs !== stamp.mtimeMs || stat.size !== stamp.size) {
@@ -26271,7 +26524,7 @@ function stampsMatch(cwd, stamps) {
26271
26524
  }
26272
26525
  function liveIndexCachePath(config) {
26273
26526
  const key = sha256Hex3(config.cwd.replace(/\\/g, "/") + "\0" + config.outDir);
26274
- return path30.join(cacheDirectory(), "live-index", key + ".json");
26527
+ return path31.join(cacheDirectory(), "live-index", key + ".json");
26275
26528
  }
26276
26529
  function isStatStamp(value) {
26277
26530
  if (typeof value !== "object" || value === null || Array.isArray(value)) return false;
@@ -26320,7 +26573,7 @@ function readCache2(config) {
26320
26573
  function writeCache2(config, payload) {
26321
26574
  try {
26322
26575
  const file = liveIndexCachePath(config);
26323
- fs28.mkdirSync(path30.dirname(file), { recursive: true, mode: 448 });
26576
+ fs28.mkdirSync(path31.dirname(file), { recursive: true, mode: 448 });
26324
26577
  const temporary = file + "." + process.pid + "." + Date.now() + ".tmp";
26325
26578
  fs28.writeFileSync(temporary, JSON.stringify(payload), { encoding: "utf8", mode: 384 });
26326
26579
  fs28.renameSync(temporary, file);
@@ -26494,23 +26747,23 @@ async function buildLiveIndex(config, options = {}) {
26494
26747
 
26495
26748
  // src/agent/install-skill.ts
26496
26749
  import * as fs29 from "fs";
26497
- import * as path31 from "path";
26750
+ import * as path32 from "path";
26498
26751
  var SKILL_TARGETS = ["agents", "claude", "cursor", "all"];
26499
26752
  var REFUSED = "Refusing to install the agent skill";
26500
26753
  var LEGACY_AGENTS_MARKER = "<!-- codebase-snapshot:skill:start -->";
26501
26754
  function targetPath(cwd, target) {
26502
26755
  switch (target) {
26503
26756
  case "agents":
26504
- return path31.join(cwd, ".agents", "skills", SKILL_NAME, "SKILL.md");
26757
+ return path32.join(cwd, ".agents", "skills", SKILL_NAME, "SKILL.md");
26505
26758
  case "claude":
26506
- return path31.join(cwd, ".claude", "skills", SKILL_NAME, "SKILL.md");
26759
+ return path32.join(cwd, ".claude", "skills", SKILL_NAME, "SKILL.md");
26507
26760
  case "cursor":
26508
- return path31.join(cwd, ".cursor", "rules", `${SKILL_NAME}.mdc`);
26761
+ return path32.join(cwd, ".cursor", "rules", `${SKILL_NAME}.mdc`);
26509
26762
  }
26510
26763
  }
26511
26764
  function assertWritableInsideRepository(cwd, filePath) {
26512
26765
  const root = fs29.realpathSync(cwd);
26513
- const shown = path31.relative(root, filePath) || filePath;
26766
+ const shown = path32.relative(root, filePath) || filePath;
26514
26767
  let stat = null;
26515
26768
  try {
26516
26769
  stat = fs29.lstatSync(filePath);
@@ -26530,14 +26783,14 @@ function assertWritableInsideRepository(cwd, filePath) {
26530
26783
  let existing = filePath;
26531
26784
  const missing = [];
26532
26785
  while (!fs29.existsSync(existing)) {
26533
- missing.unshift(path31.basename(existing));
26534
- const parent = path31.dirname(existing);
26786
+ missing.unshift(path32.basename(existing));
26787
+ const parent = path32.dirname(existing);
26535
26788
  if (parent === existing) break;
26536
26789
  existing = parent;
26537
26790
  }
26538
26791
  const realAncestor = fs29.realpathSync(existing);
26539
- const resolved = missing.length === 0 ? realAncestor : path31.join(realAncestor, ...missing);
26540
- if (resolved !== root && !resolved.startsWith(`${root}${path31.sep}`)) {
26792
+ const resolved = missing.length === 0 ? realAncestor : path32.join(realAncestor, ...missing);
26793
+ if (resolved !== root && !resolved.startsWith(`${root}${path32.sep}`)) {
26541
26794
  throw new Error(
26542
26795
  `${REFUSED}: ${shown} resolves outside the repository (${resolved}). Move it back inside ${root}, or remove the link, and run again.`
26543
26796
  );
@@ -26546,12 +26799,12 @@ function assertWritableInsideRepository(cwd, filePath) {
26546
26799
  function writeIfChanged(target, filePath, content) {
26547
26800
  const existing = fs29.existsSync(filePath) ? fs29.readFileSync(filePath, "utf8") : null;
26548
26801
  if (existing === content) return { target, path: filePath, action: "unchanged" };
26549
- fs29.mkdirSync(path31.dirname(filePath), { recursive: true });
26802
+ fs29.mkdirSync(path32.dirname(filePath), { recursive: true });
26550
26803
  fs29.writeFileSync(filePath, content, "utf8");
26551
26804
  return { target, path: filePath, action: existing === null ? "created" : "updated" };
26552
26805
  }
26553
26806
  function legacyAgentsNote(cwd) {
26554
- const filePath = path31.join(cwd, "AGENTS.md");
26807
+ const filePath = path32.join(cwd, "AGENTS.md");
26555
26808
  try {
26556
26809
  if (!fs29.existsSync(filePath)) return null;
26557
26810
  if (!fs29.readFileSync(filePath, "utf8").includes(LEGACY_AGENTS_MARKER)) return null;
@@ -26568,7 +26821,7 @@ function installSkill(cwd, target = "all", options = {}) {
26568
26821
  for (const item of wanted) assertWritableInsideRepository(cwd, targetPath(cwd, item));
26569
26822
  const createsSomething = wanted.some((item) => !fs29.existsSync(targetPath(cwd, item)));
26570
26823
  if (createsSomething) {
26571
- assertWritableInsideRepository(cwd, path31.join(cwd, ".gitignore"));
26824
+ assertWritableInsideRepository(cwd, path32.join(cwd, ".gitignore"));
26572
26825
  }
26573
26826
  const pendingMcp = options.withMcp === true ? prepareMcpConfig(cwd) : null;
26574
26827
  for (const item of wanted) {
@@ -26590,7 +26843,7 @@ function installSkill(cwd, target = "all", options = {}) {
26590
26843
  return { cwd, written, gitignored: ignore.added, notes, ...mcp === void 0 ? {} : { mcp } };
26591
26844
  }
26592
26845
  function prepareMcpConfig(cwd) {
26593
- const filePath = path31.join(cwd, ".mcp.json");
26846
+ const filePath = path32.join(cwd, ".mcp.json");
26594
26847
  assertWritableInsideRepository(cwd, filePath);
26595
26848
  const desired = { command: "npx", args: ["-y", "codebase-snapshot@latest", "mcp"] };
26596
26849
  let parsed = {};
@@ -26645,6 +26898,7 @@ var COMMAND_ALIASES = /* @__PURE__ */ new Map([
26645
26898
  ["health", "health"],
26646
26899
  ["report", "report"],
26647
26900
  ["impact", "impact"],
26901
+ ["guard", "guard"],
26648
26902
  ["brief", "brief"],
26649
26903
  ["init", "init"],
26650
26904
  ["setup", "setup"],
@@ -26662,6 +26916,7 @@ var COMMAND_ARITY = {
26662
26916
  health: 0,
26663
26917
  report: 0,
26664
26918
  impact: 0,
26919
+ guard: 0,
26665
26920
  brief: 1,
26666
26921
  init: 0,
26667
26922
  setup: 0,
@@ -26708,6 +26963,9 @@ var CLI_OPTIONS = {
26708
26963
  "changed-since": { type: "string" },
26709
26964
  diff: { type: "string" },
26710
26965
  paths: { type: "string" },
26966
+ hook: { type: "string" },
26967
+ changed: { type: "boolean" },
26968
+ "max-chars": { type: "string" },
26711
26969
  depth: { type: "string" },
26712
26970
  "max-results": { type: "string" },
26713
26971
  "no-cache": { type: "boolean" },
@@ -26782,6 +27040,7 @@ Commands:
26782
27040
  init Generate a starter snapshot.config file
26783
27041
  report Print codebase health, layer metrics, and secret audit
26784
27042
  impact Report changed files, transitive importers, routes and candidate tests
27043
+ guard Check a change for untouched consumers, tests and routes (hook-aware)
26785
27044
  brief One redacted review pack: impact, diff hunks and bounded source windows
26786
27045
  explain <path> Show how one path would be treated: layer, kind, part, skips
26787
27046
  diff <a> <b> Compare two snapshots (directories or manifest.json files)
@@ -26877,6 +27136,11 @@ Options:
26877
27136
  --tests-paths Print candidate test paths, one per line
26878
27137
  --run Run the detected test runner (text format only)
26879
27138
  --precise Add bounded compiler-resolved symbol references
27139
+
27140
+ guard only:
27141
+ --hook <client> Read one hook payload from stdin: claude | copilot | codex | raw
27142
+ --changed Check the working tree against HEAD (default when no --hook)
27143
+ --max-chars <n> Cap the model-facing hook text (default 1200, max 10000)
26880
27144
  --include-imports Include outgoing imports of changed files
26881
27145
  --include-cycles Include import cycles in the impacted subgraph
26882
27146
  --no-live Require the persisted snapshot instead of the live index
@@ -26947,6 +27211,9 @@ function parseCountOption(raw, optionName, minimum = 0) {
26947
27211
  }
26948
27212
  return value;
26949
27213
  }
27214
+ function isGuardClient(value) {
27215
+ return value === "claude" || value === "copilot" || value === "codex" || value === "raw";
27216
+ }
26950
27217
  function parsePromptTask(value) {
26951
27218
  if (value === void 0) return void 0;
26952
27219
  if (value === "audit" || value === "review" || value === "explain") return value;
@@ -27113,6 +27380,26 @@ function parseCliArgs(argv) {
27113
27380
  );
27114
27381
  }
27115
27382
  }
27383
+ const rawHook = values.hook === void 0 ? void 0 : String(values.hook);
27384
+ if (rawHook !== void 0 && !isGuardClient(rawHook)) {
27385
+ throw new UsageError(
27386
+ `--hook must be one of: claude, copilot, codex, raw (received "${rawHook}").`
27387
+ );
27388
+ }
27389
+ if (rawHook !== void 0) {
27390
+ if (paths !== void 0 || rawDiff !== void 0) {
27391
+ throw new UsageError(
27392
+ "guard --hook reads the changed paths from its stdin payload; do not pass --paths or --diff."
27393
+ );
27394
+ }
27395
+ if (values.changed === true) {
27396
+ throw new UsageError("guard --hook already runs on the payload; do not pass --changed.");
27397
+ }
27398
+ }
27399
+ const maxChars = parseCountOption(values["max-chars"], "max-chars", 200);
27400
+ if (maxChars !== void 0 && maxChars > 1e4) {
27401
+ throw new UsageError(`--max-chars must be at most 10000, received ${maxChars}.`);
27402
+ }
27116
27403
  if (command === "impact" || command === "brief") {
27117
27404
  if (rawDiff !== void 0 && paths !== void 0) {
27118
27405
  throw new UsageError("impact accepts either --diff <ref> or --paths <a,b>, not both.");
@@ -27231,7 +27518,7 @@ function parseCliArgs(argv) {
27231
27518
  install: values.install === true,
27232
27519
  noInstall: values["no-install"] === true,
27233
27520
  target: values.target === void 0 ? void 0 : String(values.target),
27234
- cwd: values.cwd === void 0 ? process.cwd() : path32.resolve(String(values.cwd)),
27521
+ cwd: values.cwd === void 0 ? process.cwd() : path33.resolve(String(values.cwd)),
27235
27522
  outDir: values["out-dir"] === void 0 ? void 0 : String(values["out-dir"]),
27236
27523
  includeMonolith: values["include-monolith"] === true || onlyNamesMonolith === true ? true : void 0,
27237
27524
  includeSensitiveFiles: values["include-sensitive-files"] === true ? true : void 0,
@@ -27274,6 +27561,9 @@ function parseCliArgs(argv) {
27274
27561
  changedSince: values["changed-since"] === void 0 ? void 0 : String(values["changed-since"]),
27275
27562
  diff: rawDiff,
27276
27563
  paths,
27564
+ hook: rawHook === void 0 ? void 0 : rawHook,
27565
+ changed: values.changed === true,
27566
+ maxChars,
27277
27567
  depth,
27278
27568
  maxResults,
27279
27569
  // `undefined` when the flag was not given, never `false`.
@@ -27411,20 +27701,20 @@ function renderImpactMarkdown(report2) {
27411
27701
  }
27412
27702
  function realPathInside(realRoot, candidate) {
27413
27703
  const fold = (value) => process.platform === "win32" || process.platform === "darwin" ? value.toLowerCase() : value;
27414
- const relative20 = path32.relative(fold(realRoot), fold(candidate));
27415
- return relative20.length === 0 || relative20 !== ".." && !relative20.startsWith(".." + path32.sep) && !path32.isAbsolute(relative20);
27704
+ const relative21 = path33.relative(fold(realRoot), fold(candidate));
27705
+ return relative21.length === 0 || relative21 !== ".." && !relative21.startsWith(".." + path33.sep) && !path33.isAbsolute(relative21);
27416
27706
  }
27417
- function writeInside(root, relative20, content) {
27418
- const target = path32.resolve(root, relative20);
27419
- const rel = path32.relative(path32.resolve(root), target);
27420
- if (rel.length === 0 || rel === ".." || rel.startsWith(".." + path32.sep) || path32.isAbsolute(rel)) {
27707
+ function writeInside(root, relative21, content) {
27708
+ const target = path33.resolve(root, relative21);
27709
+ const rel = path33.relative(path33.resolve(root), target);
27710
+ if (rel.length === 0 || rel === ".." || rel.startsWith(".." + path33.sep) || path33.isAbsolute(rel)) {
27421
27711
  throw new Error("--out must resolve inside the repository.");
27422
27712
  }
27423
- const parent = path32.dirname(target);
27713
+ const parent = path33.dirname(target);
27424
27714
  const realRoot = fs30.realpathSync(root);
27425
27715
  let existingAncestor = parent;
27426
27716
  while (!fs30.existsSync(existingAncestor)) {
27427
- const next = path32.dirname(existingAncestor);
27717
+ const next = path33.dirname(existingAncestor);
27428
27718
  if (next === existingAncestor) break;
27429
27719
  existingAncestor = next;
27430
27720
  }
@@ -27443,7 +27733,7 @@ function writeInside(root, relative20, content) {
27443
27733
  } catch (error) {
27444
27734
  if (error.code !== "ENOENT") throw error;
27445
27735
  }
27446
- const temporary = path32.join(parent, "." + path32.basename(target) + ".tmp-" + process.pid + "-" + Math.random().toString(16).slice(2));
27736
+ const temporary = path33.join(parent, "." + path33.basename(target) + ".tmp-" + process.pid + "-" + Math.random().toString(16).slice(2));
27447
27737
  fs30.writeFileSync(temporary, content, { encoding: "utf8", flag: "wx", mode: 384 });
27448
27738
  try {
27449
27739
  fs30.renameSync(temporary, target);
@@ -27472,10 +27762,10 @@ function splitList(value) {
27472
27762
  return value.split(",").map((entry) => entry.trim()).filter(Boolean);
27473
27763
  }
27474
27764
  function displayOutPath(cwd, outDir, ...segments) {
27475
- const absolute = path32.resolve(cwd, outDir, ...segments);
27476
- const relative20 = path32.relative(cwd, absolute);
27477
- if (relative20 !== "" && relative20 !== ".." && !relative20.startsWith(`..${path32.sep}`) && !relative20.startsWith("../") && !path32.isAbsolute(relative20)) {
27478
- return relative20;
27765
+ const absolute = path33.resolve(cwd, outDir, ...segments);
27766
+ const relative21 = path33.relative(cwd, absolute);
27767
+ if (relative21 !== "" && relative21 !== ".." && !relative21.startsWith(`..${path33.sep}`) && !relative21.startsWith("../") && !path33.isAbsolute(relative21)) {
27768
+ return relative21;
27479
27769
  }
27480
27770
  return absolute;
27481
27771
  }
@@ -27484,7 +27774,7 @@ function nextStepHint(cwd, scriptsAddedNow) {
27484
27774
  if (!hasScript) {
27485
27775
  try {
27486
27776
  const parsed = JSON.parse(
27487
- stripJsonComments(fs30.readFileSync(path32.join(cwd, "package.json"), "utf8"))
27777
+ stripJsonComments(fs30.readFileSync(path33.join(cwd, "package.json"), "utf8"))
27488
27778
  );
27489
27779
  hasScript = typeof parsed.scripts?.snapshot === "string";
27490
27780
  } catch {
@@ -27492,7 +27782,7 @@ function nextStepHint(cwd, scriptsAddedNow) {
27492
27782
  }
27493
27783
  }
27494
27784
  if (!hasScript) return `npx ${GENERATOR_NAME} generate`;
27495
- const bin = path32.join(cwd, "node_modules", ".bin", "codebase-snapshot");
27785
+ const bin = path33.join(cwd, "node_modules", ".bin", "codebase-snapshot");
27496
27786
  const installed = fs30.existsSync(bin) || fs30.existsSync(`${bin}.cmd`);
27497
27787
  return installed ? "npm run snapshot" : "npm install && npm run snapshot";
27498
27788
  }
@@ -27529,7 +27819,7 @@ async function runInitCommand(invocation) {
27529
27819
  if (hook) for (const note of hook.notes) info(` ${note}`);
27530
27820
  return 0;
27531
27821
  }
27532
- info(`\u2705 Created ${path32.basename(result.configPath)} (${presetSummary(result)})`);
27822
+ info(`\u2705 Created ${path33.basename(result.configPath)} (${presetSummary(result)})`);
27533
27823
  if (result.scripts.length > 0) info(` Added npm scripts: ${result.scripts.join(", ")}`);
27534
27824
  if (result.dependency.added && result.dependency.range !== null) {
27535
27825
  info(` Added devDependency: ${result.dependency.name} ${result.dependency.range}`);
@@ -27539,10 +27829,10 @@ async function runInitCommand(invocation) {
27539
27829
  }
27540
27830
  if (result.briefWritten) {
27541
27831
  info(
27542
- ` Wrote ${path32.basename(result.briefPath)}: a scaffold for the half of PROMPT.md only you can write. Fill it in, then set brief: ${JSON.stringify(path32.basename(result.briefPath))} in the config to merge it.`
27832
+ ` Wrote ${path33.basename(result.briefPath)}: a scaffold for the half of PROMPT.md only you can write. Fill it in, then set brief: ${JSON.stringify(path33.basename(result.briefPath))} in the config to merge it.`
27543
27833
  );
27544
27834
  } else if (fs30.existsSync(result.briefPath)) {
27545
- info(` Kept ${path32.basename(result.briefPath)}: it already exists, and is never overwritten.`);
27835
+ info(` Kept ${path33.basename(result.briefPath)}: it already exists, and is never overwritten.`);
27546
27836
  }
27547
27837
  for (const note of result.notes) info(` \u26A0 ${note}`);
27548
27838
  if (hook) for (const note of hook.notes) info(` ${note}`);
@@ -27579,18 +27869,18 @@ function renderHealthText(report2) {
27579
27869
  function generatorOrigin(cwd) {
27580
27870
  try {
27581
27871
  const pkg = JSON.parse(
27582
- stripJsonComments(fs30.readFileSync(path32.join(cwd, "package.json"), "utf8"))
27872
+ stripJsonComments(fs30.readFileSync(path33.join(cwd, "package.json"), "utf8"))
27583
27873
  );
27584
27874
  const spec = pkg.dependencies?.["codebase-snapshot"] ?? pkg.devDependencies?.["codebase-snapshot"];
27585
27875
  if (typeof spec === "string") return `project dependency ${spec}`;
27586
27876
  } catch {
27587
27877
  }
27588
27878
  const entry = process.argv[1] ?? "";
27589
- if (entry.includes("_npx") || entry.includes(`${path32.sep}npx${path32.sep}`)) return "via npx";
27879
+ if (entry.includes("_npx") || entry.includes(`${path33.sep}npx${path33.sep}`)) return "via npx";
27590
27880
  return "global or direct install";
27591
27881
  }
27592
27882
  function detectPackageManager(cwd) {
27593
- const has = (name) => fs30.existsSync(path32.join(cwd, name));
27883
+ const has = (name) => fs30.existsSync(path33.join(cwd, name));
27594
27884
  if (has("bun.lockb") || has("bun.lock")) return { name: "bun", command: "bun", args: ["install"] };
27595
27885
  if (has("pnpm-lock.yaml")) return { name: "pnpm", command: "pnpm", args: ["install"] };
27596
27886
  if (has("yarn.lock")) return { name: "yarn", command: "yarn", args: ["install"] };
@@ -27707,7 +27997,7 @@ async function runSetupCommand(invocation, options = {}) {
27707
27997
  }
27708
27998
  info("\n\u{1F9EA} Dry run \u2014 setup would:");
27709
27999
  info(
27710
- ` 1. ${init.reused ? `keep ${path32.basename(keptConfigPath)}` : `write ${path32.basename(keptConfigPath)} (preset: ${appliedPreset})`}`
28000
+ ` 1. ${init.reused ? `keep ${path33.basename(keptConfigPath)}` : `write ${path33.basename(keptConfigPath)} (preset: ${appliedPreset})`}`
27711
28001
  );
27712
28002
  info(" 2. add the npm scripts, the devDependency and the .gitignore entries");
27713
28003
  if (manager !== null) info(` 3. install with ${manager}`);
@@ -27720,9 +28010,9 @@ async function runSetupCommand(invocation, options = {}) {
27720
28010
  if (invocation.format !== "json") {
27721
28011
  if (!interactive) info(`\u{1F680} Setup for: ${invocation.cwd}`);
27722
28012
  if (init.reused) {
27723
- info(`\u267B Keeping ${path32.basename(keptConfigPath)}`);
28013
+ info(`\u267B Keeping ${path33.basename(keptConfigPath)}`);
27724
28014
  } else {
27725
- info(`\u2705 Created ${path32.basename(keptConfigPath)} (${presetSummary(init)})`);
28015
+ info(`\u2705 Created ${path33.basename(keptConfigPath)} (${presetSummary(init)})`);
27726
28016
  }
27727
28017
  if (init.scripts.length > 0) info(` Added npm scripts: ${init.scripts.join(", ")}`);
27728
28018
  if (init.dependency.added && init.dependency.range !== null) {
@@ -27733,7 +28023,7 @@ async function runSetupCommand(invocation, options = {}) {
27733
28023
  }
27734
28024
  if (init.briefWritten) {
27735
28025
  info(
27736
- ` Wrote ${path32.basename(init.briefPath)}: a scaffold for the half of PROMPT.md only you can write. Fill it in, then set brief: ${JSON.stringify(path32.basename(init.briefPath))} in the config to merge it.`
28026
+ ` Wrote ${path33.basename(init.briefPath)}: a scaffold for the half of PROMPT.md only you can write. Fill it in, then set brief: ${JSON.stringify(path33.basename(init.briefPath))} in the config to merge it.`
27737
28027
  );
27738
28028
  }
27739
28029
  if (hook) for (const note of hook.notes) info(` ${note}`);
@@ -27741,7 +28031,7 @@ async function runSetupCommand(invocation, options = {}) {
27741
28031
  info(` \u26A0 --preset ${invocation.preset} was not applied: the existing config is kept.`);
27742
28032
  }
27743
28033
  }
27744
- const hasManifest = fs30.existsSync(path32.join(invocation.cwd, "package.json"));
28034
+ const hasManifest = fs30.existsSync(path33.join(invocation.cwd, "package.json"));
27745
28035
  let install = null;
27746
28036
  if (invocation.noInstall) {
27747
28037
  if (invocation.format !== "json") info(" Skipped the install (--no-install)");
@@ -27906,7 +28196,7 @@ function runSkillCommand(invocation) {
27906
28196
  }
27907
28197
  info(`\u2705 Agent skill installed (${SKILL_NAME}):`);
27908
28198
  for (const item of result.written) {
27909
- const shown = path32.relative(invocation.cwd, item.path) || item.path;
28199
+ const shown = path33.relative(invocation.cwd, item.path) || item.path;
27910
28200
  info(` - ${item.action.padEnd(9)} ${shown}`);
27911
28201
  }
27912
28202
  if (result.gitignored.length > 0) {
@@ -27915,7 +28205,7 @@ function runSkillCommand(invocation) {
27915
28205
  info(" These files are this tool's own documentation, so they stay out of git.");
27916
28206
  }
27917
28207
  if (result.mcp !== void 0) {
27918
- const shown = path32.relative(invocation.cwd, result.mcp.path) || result.mcp.path;
28208
+ const shown = path33.relative(invocation.cwd, result.mcp.path) || result.mcp.path;
27919
28209
  info(` - ${result.mcp.action.padEnd(9)} ${shown} (codebase-snapshot MCP entry)`);
27920
28210
  }
27921
28211
  for (const note of result.notes) info(` \u26A0 ${note}`);
@@ -27986,6 +28276,78 @@ function guardClosedStdout() {
27986
28276
  throw error;
27987
28277
  });
27988
28278
  }
28279
+ async function readStdin(limit = 1024 * 1024) {
28280
+ const chunks = [];
28281
+ let size2 = 0;
28282
+ for await (const chunk of process.stdin) {
28283
+ const buffer = Buffer.isBuffer(chunk) ? chunk : Buffer.from(String(chunk));
28284
+ size2 += buffer.length;
28285
+ if (size2 > limit) throw new Error("the hook payload exceeds 1 MiB");
28286
+ chunks.push(buffer);
28287
+ }
28288
+ return Buffer.concat(chunks).toString("utf8");
28289
+ }
28290
+ async function runGuardCommand(invocation, resolved) {
28291
+ const client = invocation.hook;
28292
+ try {
28293
+ let paths = invocation.paths;
28294
+ let event = "PostToolUse";
28295
+ if (client !== void 0) {
28296
+ const parsed = parseGuardHookInput(client, await readStdin(), resolved.cwd);
28297
+ paths = parsed.paths;
28298
+ event = parsed.event;
28299
+ if (paths.length === 0) {
28300
+ process.stdout.write("{}\n");
28301
+ return 0;
28302
+ }
28303
+ }
28304
+ const changes = resolveImpactChanges(resolved.cwd, {
28305
+ ...paths === void 0 ? { diff: invocation.diff ?? "HEAD" } : { paths }
28306
+ });
28307
+ const manifestPath = path33.resolve(resolved.cwd, resolved.outDir, "manifest.json");
28308
+ let manifest;
28309
+ let trust;
28310
+ if (invocation.noLive) {
28311
+ if (!fs30.existsSync(manifestPath)) {
28312
+ if (client !== void 0) {
28313
+ warn("guard: no snapshot manifest; the hook was skipped.");
28314
+ process.stdout.write("{}\n");
28315
+ return 0;
28316
+ }
28317
+ return fail(
28318
+ invocation.format,
28319
+ "Manifest not found at " + manifestPath + ". Run generate first, or omit --no-live."
28320
+ );
28321
+ }
28322
+ manifest = loadManifest(manifestPath);
28323
+ } else {
28324
+ const live = await buildLiveIndex(resolved, { useDiskCache: !invocation.noCache });
28325
+ manifest = live.manifest;
28326
+ trust = live.trust;
28327
+ }
28328
+ const impact = computeImpact({
28329
+ manifest,
28330
+ cwd: resolved.cwd,
28331
+ changes,
28332
+ manifestPath,
28333
+ ...trust === void 0 ? {} : { trust }
28334
+ });
28335
+ const report2 = buildGuardReport(impact);
28336
+ if (client !== void 0) {
28337
+ process.stdout.write(renderGuardHook(report2, client, event, invocation.maxChars ?? 1200) + "\n");
28338
+ return 0;
28339
+ }
28340
+ emit(invocation.format, report2, () => info(renderGuardText(report2)));
28341
+ return 0;
28342
+ } catch (err) {
28343
+ if (client !== void 0) {
28344
+ warn("guard: " + err.message + " (hook skipped)");
28345
+ process.stdout.write("{}\n");
28346
+ return 0;
28347
+ }
28348
+ return fail(invocation.format, err.message);
28349
+ }
28350
+ }
27989
28351
  async function main(argv = process.argv.slice(2)) {
27990
28352
  guardClosedStdout();
27991
28353
  const pending = process.stdout.isTTY === true && shouldCheck(argv, process.env) ? checkForUpdate({ current: GENERATOR_VERSION, cacheFile: cacheFilePath() }) : null;
@@ -28073,7 +28435,7 @@ ${USAGE}
28073
28435
  }
28074
28436
  if (invocation.command === "serve") {
28075
28437
  const server = await startWebServer({
28076
- cwd: path32.resolve(invocation.cwd),
28438
+ cwd: path33.resolve(invocation.cwd),
28077
28439
  ...invocation.host === void 0 ? {} : { host: invocation.host },
28078
28440
  ...invocation.port === void 0 ? {} : { port: invocation.port },
28079
28441
  ...tokenOption,
@@ -28088,9 +28450,9 @@ ${USAGE}
28088
28450
  } else {
28089
28451
  warn(" WARNING: --no-auth is on. Any page on this machine can read the repository.");
28090
28452
  }
28091
- await new Promise((resolve21) => {
28453
+ await new Promise((resolve22) => {
28092
28454
  const stop = () => {
28093
- void server.close().then(resolve21);
28455
+ void server.close().then(resolve22);
28094
28456
  };
28095
28457
  process.once("SIGINT", stop);
28096
28458
  process.once("SIGTERM", stop);
@@ -28100,7 +28462,7 @@ ${USAGE}
28100
28462
  if (invocation.command === "mcp") {
28101
28463
  if (invocation.http === true) {
28102
28464
  const transport = await startHttpTransport({
28103
- cwd: path32.resolve(invocation.cwd),
28465
+ cwd: path33.resolve(invocation.cwd),
28104
28466
  noConfig: invocation.noConfig,
28105
28467
  ...invocation.host === void 0 ? {} : { host: invocation.host },
28106
28468
  ...invocation.port === void 0 ? {} : { port: invocation.port },
@@ -28116,9 +28478,9 @@ ${USAGE}
28116
28478
  } else {
28117
28479
  warn(" WARNING: --no-auth is on. Any page on this machine can read the repository.");
28118
28480
  }
28119
- await new Promise((resolve21) => {
28481
+ await new Promise((resolve22) => {
28120
28482
  const stop = () => {
28121
- void transport.close().then(resolve21);
28483
+ void transport.close().then(resolve22);
28122
28484
  };
28123
28485
  process.once("SIGINT", stop);
28124
28486
  process.once("SIGTERM", stop);
@@ -28126,7 +28488,7 @@ ${USAGE}
28126
28488
  return 0;
28127
28489
  }
28128
28490
  return await runStdioServer({
28129
- cwd: path32.resolve(invocation.cwd),
28491
+ cwd: path33.resolve(invocation.cwd),
28130
28492
  noConfig: invocation.noConfig
28131
28493
  });
28132
28494
  }
@@ -28156,7 +28518,7 @@ ${USAGE}
28156
28518
  log: (line) => info(" " + line)
28157
28519
  });
28158
28520
  sourceProvenance = clone.provenance;
28159
- const outDir = path32.resolve(invocation.cwd, invocation.outDir ?? "snapshot");
28521
+ const outDir = path33.resolve(invocation.cwd, invocation.outDir ?? "snapshot");
28160
28522
  invocation = { ...invocation, cwd: clone.directory, outDir, noConfig: true };
28161
28523
  info(
28162
28524
  " Source: " + parsed.source.owner + "/" + parsed.source.repo + "@" + clone.commit.slice(0, 12) + " (fetched " + clone.provenance.fetchedAt + ")"
@@ -28186,7 +28548,7 @@ ${USAGE}
28186
28548
  );
28187
28549
  }
28188
28550
  for (const warning of loaded.warnings) warn(`\u26A0 Config: ${warning}`);
28189
- if (loaded.file) info(`\u2699 Using config ${path32.relative(process.cwd(), loaded.file) || loaded.file}`);
28551
+ if (loaded.file) info(`\u2699 Using config ${path33.relative(process.cwd(), loaded.file) || loaded.file}`);
28190
28552
  let resolved;
28191
28553
  try {
28192
28554
  resolved = resolveConfig(
@@ -28197,6 +28559,9 @@ ${USAGE}
28197
28559
  } catch (err) {
28198
28560
  return fail(invocation.format, err.message);
28199
28561
  }
28562
+ if (invocation.command === "guard") {
28563
+ return await runGuardCommand(invocation, resolved);
28564
+ }
28200
28565
  if (invocation.command === "validate") {
28201
28566
  const result = validateSnapshot(resolved);
28202
28567
  emit(invocation.format, result, () => renderValidateText(result));
@@ -28204,8 +28569,8 @@ ${USAGE}
28204
28569
  }
28205
28570
  if (invocation.command === "health") {
28206
28571
  if (invocation.allMembers === true) {
28207
- const outRoot = path32.resolve(resolved.cwd, resolved.outDir);
28208
- const indexPath = path32.join(outRoot, "WORKSPACE.json");
28572
+ const outRoot = path33.resolve(resolved.cwd, resolved.outDir);
28573
+ const indexPath = path33.join(outRoot, "WORKSPACE.json");
28209
28574
  if (!fs30.existsSync(indexPath)) {
28210
28575
  return fail(
28211
28576
  invocation.format,
@@ -28224,15 +28589,15 @@ ${USAGE}
28224
28589
  }
28225
28590
  const rows = [];
28226
28591
  const insidePath = (parent, child) => {
28227
- const relative20 = path32.relative(parent, child);
28228
- return relative20 === "" || relative20 !== ".." && !relative20.startsWith(`..${path32.sep}`) && !relative20.startsWith("../") && !path32.isAbsolute(relative20);
28592
+ const relative21 = path33.relative(parent, child);
28593
+ return relative21 === "" || relative21 !== ".." && !relative21.startsWith(`..${path33.sep}`) && !relative21.startsWith("../") && !path33.isAbsolute(relative21);
28229
28594
  };
28230
28595
  for (const member of index.members ?? []) {
28231
28596
  const name = member.name ?? "?";
28232
- const snapshotDir2 = path32.resolve(outRoot, name);
28597
+ const snapshotDir2 = path33.resolve(outRoot, name);
28233
28598
  const repoPath = member.path ?? name;
28234
- const repoDir = path32.resolve(resolved.cwd, repoPath);
28235
- if (name.length === 0 || path32.isAbsolute(name) || name.split(/[\\/]/).includes("..") || !insidePath(outRoot, snapshotDir2) || path32.isAbsolute(repoPath) || repoPath.split(/[\\/]/).includes("..") || !insidePath(resolved.cwd, repoDir)) {
28599
+ const repoDir = path33.resolve(resolved.cwd, repoPath);
28600
+ if (name.length === 0 || path33.isAbsolute(name) || name.split(/[\\/]/).includes("..") || !insidePath(outRoot, snapshotDir2) || path33.isAbsolute(repoPath) || repoPath.split(/[\\/]/).includes("..") || !insidePath(resolved.cwd, repoDir)) {
28236
28601
  rows.push({
28237
28602
  name,
28238
28603
  score: 0,
@@ -28263,7 +28628,7 @@ ${USAGE}
28263
28628
  canonicalSnapshot = snapshotDir2;
28264
28629
  canonicalRepo = repoDir;
28265
28630
  }
28266
- if (!fs30.existsSync(path32.join(snapshotDir2, "manifest.json"))) {
28631
+ if (!fs30.existsSync(path33.join(snapshotDir2, "manifest.json"))) {
28267
28632
  rows.push({ name, score: 0, counts: { pass: 0, warn: 0, fail: 1 }, failed: [], error: "no snapshot at " + snapshotDir2 });
28268
28633
  continue;
28269
28634
  }
@@ -28310,7 +28675,7 @@ ${USAGE}
28310
28675
  if (invocation.strict === true && totals.warn > 0) return 1;
28311
28676
  return 0;
28312
28677
  }
28313
- const snapshotDir = path32.resolve(resolved.cwd, resolved.outDir);
28678
+ const snapshotDir = path33.resolve(resolved.cwd, resolved.outDir);
28314
28679
  const report2 = auditSnapshot({
28315
28680
  snapshotDir,
28316
28681
  repoDir: resolved.cwd,
@@ -28323,7 +28688,7 @@ ${USAGE}
28323
28688
  return 0;
28324
28689
  }
28325
28690
  if (invocation.command === "report") {
28326
- const manifestPath = path32.resolve(resolved.cwd, resolved.outDir, "manifest.json");
28691
+ const manifestPath = path33.resolve(resolved.cwd, resolved.outDir, "manifest.json");
28327
28692
  if (!fs30.existsSync(manifestPath)) {
28328
28693
  return fail(invocation.format, `Manifest not found at ${manifestPath}. Run generate first.`);
28329
28694
  }
@@ -28386,7 +28751,7 @@ ${USAGE}
28386
28751
  if (manifest.delta !== void 0) {
28387
28752
  const delta = manifest.delta;
28388
28753
  info("\n Selection (delta):");
28389
- info(` - Against: ${path32.basename(delta.base.path)} (${delta.base.fingerprint.slice(0, 12)})`);
28754
+ info(` - Against: ${path33.basename(delta.base.path)} (${delta.base.fingerprint.slice(0, 12)})`);
28390
28755
  info(
28391
28756
  ` - Changed: ${delta.changed.length} changed, ${delta.added.length} added, ${delta.removed.length} removed, ${delta.unchanged.length} unchanged`
28392
28757
  );
@@ -28396,7 +28761,7 @@ ${USAGE}
28396
28761
  }
28397
28762
  if (invocation.command === "impact") {
28398
28763
  try {
28399
- const manifestPath = path32.resolve(resolved.cwd, resolved.outDir, "manifest.json");
28764
+ const manifestPath = path33.resolve(resolved.cwd, resolved.outDir, "manifest.json");
28400
28765
  let manifest;
28401
28766
  let live = null;
28402
28767
  if (invocation.noLive) {
@@ -28518,7 +28883,7 @@ ${USAGE}
28518
28883
  }
28519
28884
  if (invocation.command === "brief") {
28520
28885
  try {
28521
- const manifestPath = path32.resolve(resolved.cwd, resolved.outDir, "manifest.json");
28886
+ const manifestPath = path33.resolve(resolved.cwd, resolved.outDir, "manifest.json");
28522
28887
  let manifest;
28523
28888
  let live = null;
28524
28889
  if (invocation.noLive) {
@@ -28574,10 +28939,10 @@ ${USAGE}
28574
28939
  if (isSensitivePath(relativePath)) return null;
28575
28940
  const file = manifest.files.find((candidate) => candidate.relativePath === relativePath);
28576
28941
  if (file === void 0) return null;
28577
- const snapshotDir = path32.resolve(resolved.cwd, resolved.outDir);
28942
+ const snapshotDir = path33.resolve(resolved.cwd, resolved.outDir);
28578
28943
  const read = readConfinedText(
28579
28944
  snapshotDir,
28580
- path32.posix.join("parts", file.part),
28945
+ path33.posix.join("parts", file.part),
28581
28946
  16 * 1024 * 1024
28582
28947
  );
28583
28948
  if (!read.ok) return null;
@@ -28602,7 +28967,7 @@ ${USAGE}
28602
28967
  });
28603
28968
  if (invocation.out !== void 0) {
28604
28969
  const written = writeInside(resolved.cwd, invocation.out, brief.markdown);
28605
- info("Wrote " + path32.relative(resolved.cwd, written));
28970
+ info("Wrote " + path33.relative(resolved.cwd, written));
28606
28971
  } else if (invocation.format !== "json") {
28607
28972
  process.stdout.write(brief.markdown);
28608
28973
  }
@@ -28678,10 +29043,10 @@ ${USAGE}
28678
29043
  "--workspace writes one snapshot per member; --remote, --delta, --slice, --budget-tokens and --sign do not combine with it."
28679
29044
  );
28680
29045
  }
28681
- const outRoot = path32.resolve(invocation.cwd, invocation.outDir ?? "snapshot");
28682
- const workspaceCwd = path32.resolve(invocation.cwd);
28683
- const outRootRelative = path32.relative(outRoot, workspaceCwd);
28684
- if (outRootRelative === "" || outRootRelative !== ".." && !outRootRelative.startsWith(`..${path32.sep}`) && !outRootRelative.startsWith("../") && !path32.isAbsolute(outRootRelative)) {
29046
+ const outRoot = path33.resolve(invocation.cwd, invocation.outDir ?? "snapshot");
29047
+ const workspaceCwd = path33.resolve(invocation.cwd);
29048
+ const outRootRelative = path33.relative(outRoot, workspaceCwd);
29049
+ if (outRootRelative === "" || outRootRelative !== ".." && !outRootRelative.startsWith(`..${path33.sep}`) && !outRootRelative.startsWith("../") && !path33.isAbsolute(outRootRelative)) {
28685
29050
  return fail(
28686
29051
  invocation.format,
28687
29052
  `--workspace refuses --out-dir ${outRoot}: it is the working directory or one of its ancestors.`
@@ -28689,8 +29054,8 @@ ${USAGE}
28689
29054
  }
28690
29055
  const plannedNames = /* @__PURE__ */ new Map();
28691
29056
  for (const member of members) {
28692
- const directory = path32.resolve(invocation.cwd, member);
28693
- const name = path32.basename(directory);
29057
+ const directory = path33.resolve(invocation.cwd, member);
29058
+ const name = path33.basename(directory);
28694
29059
  const previous = plannedNames.get(name);
28695
29060
  if (previous !== void 0) {
28696
29061
  return fail(
@@ -28703,8 +29068,8 @@ ${USAGE}
28703
29068
  const records = [];
28704
29069
  let failed = 0;
28705
29070
  for (const member of members) {
28706
- const directory = path32.resolve(invocation.cwd, member);
28707
- const name = path32.basename(directory);
29071
+ const directory = path33.resolve(invocation.cwd, member);
29072
+ const name = path33.basename(directory);
28708
29073
  let stat;
28709
29074
  try {
28710
29075
  stat = fs30.statSync(directory);
@@ -28724,7 +29089,7 @@ ${USAGE}
28724
29089
  {
28725
29090
  ...generateCliOptions(invocation),
28726
29091
  cwd: directory,
28727
- outDir: path32.join(outRoot, name)
29092
+ outDir: path33.join(outRoot, name)
28728
29093
  },
28729
29094
  directory
28730
29095
  );
@@ -28751,10 +29116,10 @@ ${USAGE}
28751
29116
  for (const entry of record.imports) {
28752
29117
  for (const specifier of entry.imports) {
28753
29118
  if (!specifier.startsWith(".")) continue;
28754
- const resolved2 = path32.resolve(record.path, path32.dirname(entry.path), specifier);
29119
+ const resolved2 = path33.resolve(record.path, path33.dirname(entry.path), specifier);
28755
29120
  for (const other of records) {
28756
29121
  if (other === record) continue;
28757
- const prefix = other.path + path32.sep;
29122
+ const prefix = other.path + path33.sep;
28758
29123
  if (!resolved2.startsWith(prefix) && resolved2 !== other.path) continue;
28759
29124
  const bucket = counts.get(other.name) ?? { count: 0, examples: [] };
28760
29125
  bucket.count += 1;
@@ -28779,12 +29144,12 @@ ${USAGE}
28779
29144
  // Store the member path relative to the workspace cwd, as manifest paths already are.
28780
29145
  members: records.map(({ imports: _imports, ...rest }) => ({
28781
29146
  ...rest,
28782
- path: path32.relative(workspaceCwd, rest.path).split(path32.sep).join("/") || "."
29147
+ path: path33.relative(workspaceCwd, rest.path).split(path33.sep).join("/") || "."
28783
29148
  })),
28784
29149
  links
28785
29150
  };
28786
29151
  if (!invocation.dryRun) {
28787
- const workspacePath = path32.join(outRoot, "WORKSPACE.json");
29152
+ const workspacePath = path33.join(outRoot, "WORKSPACE.json");
28788
29153
  try {
28789
29154
  const stats = fs30.lstatSync(workspacePath);
28790
29155
  if (stats.isSymbolicLink() || !stats.isFile()) {
@@ -28827,8 +29192,8 @@ ${USAGE}
28827
29192
  try {
28828
29193
  let deltaBase;
28829
29194
  if (invocation.delta !== void 0) {
28830
- const basePath = path32.resolve(invocation.cwd, invocation.delta);
28831
- const manifestPath = fs30.existsSync(basePath) && fs30.statSync(basePath).isDirectory() ? path32.join(basePath, "manifest.json") : basePath;
29195
+ const basePath = path33.resolve(invocation.cwd, invocation.delta);
29196
+ const manifestPath = fs30.existsSync(basePath) && fs30.statSync(basePath).isDirectory() ? path33.join(basePath, "manifest.json") : basePath;
28832
29197
  if (!fs30.existsSync(manifestPath)) {
28833
29198
  return fail(invocation.format, "No manifest at " + manifestPath + ". Point --delta at a snapshot directory or its manifest.json.");
28834
29199
  }
@@ -28842,8 +29207,8 @@ ${USAGE}
28842
29207
  if (shape !== null) {
28843
29208
  return fail(invocation.format, manifestPath + " is not a snapshot manifest: " + shape);
28844
29209
  }
28845
- const relativeBase = path32.relative(invocation.cwd, manifestPath).split(path32.sep).join("/");
28846
- const recordedBase = relativeBase === "" || relativeBase === ".." || relativeBase.startsWith(`..${path32.sep}`) || relativeBase.startsWith("../") || path32.isAbsolute(relativeBase) ? path32.basename(manifestPath) : relativeBase;
29210
+ const relativeBase = path33.relative(invocation.cwd, manifestPath).split(path33.sep).join("/");
29211
+ const recordedBase = relativeBase === "" || relativeBase === ".." || relativeBase.startsWith(`..${path33.sep}`) || relativeBase.startsWith("../") || path33.isAbsolute(relativeBase) ? path33.basename(manifestPath) : relativeBase;
28847
29212
  deltaBase = { manifest: base, path: recordedBase };
28848
29213
  info(" Delta base: " + recordedBase + " (" + base.files.length + " files, fingerprint " + base.fingerprint.slice(0, 12) + ")");
28849
29214
  }
@@ -28861,7 +29226,7 @@ ${USAGE}
28861
29226
  ...invocation.sign === true && !invocation.dryRun ? { sign: { key: loadSigningKey() } } : {}
28862
29227
  });
28863
29228
  if (invocation.sign === true && !invocation.dryRun) {
28864
- const signaturePath = path32.resolve(resolved.cwd, resolved.outDir, SIGNATURE_FILE);
29229
+ const signaturePath = path33.resolve(resolved.cwd, resolved.outDir, SIGNATURE_FILE);
28865
29230
  try {
28866
29231
  const record = JSON.parse(fs30.readFileSync(signaturePath, "utf8"));
28867
29232
  info(
@@ -29016,19 +29381,19 @@ function finishWatchRun(state, now) {
29016
29381
  };
29017
29382
  }
29018
29383
  function comparablePath(value) {
29019
- const absolute = path32.resolve(value);
29384
+ const absolute = path33.resolve(value);
29020
29385
  return process.platform === "win32" ? absolute.toLowerCase() : absolute;
29021
29386
  }
29022
29387
  function isSameOrInside(parent, candidate) {
29023
- const relative20 = path32.relative(parent, candidate);
29024
- return relative20 === "" || relative20 !== ".." && !relative20.startsWith(`..${path32.sep}`) && !path32.isAbsolute(relative20);
29388
+ const relative21 = path33.relative(parent, candidate);
29389
+ return relative21 === "" || relative21 !== ".." && !relative21.startsWith(`..${path33.sep}`) && !path33.isAbsolute(relative21);
29025
29390
  }
29026
29391
  function isGeneratedWatchPath(candidate, paths) {
29027
- const absolute = comparablePath(path32.resolve(paths.cwd, candidate));
29028
- const outDir = comparablePath(path32.resolve(paths.cwd, paths.outDir));
29029
- const tmpDir = comparablePath(path32.resolve(paths.cwd, paths.tmpDir));
29392
+ const absolute = comparablePath(path33.resolve(paths.cwd, candidate));
29393
+ const outDir = comparablePath(path33.resolve(paths.cwd, paths.outDir));
29394
+ const tmpDir = comparablePath(path33.resolve(paths.cwd, paths.tmpDir));
29030
29395
  if (isSameOrInside(outDir, absolute) || isSameOrInside(tmpDir, absolute)) return true;
29031
- const offsets = [path32.basename(outDir), path32.basename(tmpDir)].filter((name) => name.length > 0);
29396
+ const offsets = [path33.basename(outDir), path33.basename(tmpDir)].filter((name) => name.length > 0);
29032
29397
  const leftover = absolute.split(/[\\/]+/).some(
29033
29398
  (segment) => offsets.some(
29034
29399
  (name) => segment.startsWith(`${name}.backup-`) || segment.startsWith(`${name}.partial-`)
@@ -29051,8 +29416,8 @@ function decideWatchEvent(state, event, paths) {
29051
29416
  function watchPathsFor(config) {
29052
29417
  return {
29053
29418
  cwd: config.cwd,
29054
- outDir: path32.resolve(config.cwd, config.outDir),
29055
- tmpDir: path32.resolve(config.cwd, config.tmpDir)
29419
+ outDir: path33.resolve(config.cwd, config.outDir),
29420
+ tmpDir: path33.resolve(config.cwd, config.tmpDir)
29056
29421
  };
29057
29422
  }
29058
29423
  function watchSupportProblem(platform = process.platform, version = process.versions.node) {
@@ -29131,7 +29496,7 @@ async function runWatchLoop(invocation, resolved, options) {
29131
29496
  const decision = decideWatchEvent(
29132
29497
  state,
29133
29498
  {
29134
- path: filename ? path32.resolve(resolved.cwd, filename.toString()) : null,
29499
+ path: filename ? path33.resolve(resolved.cwd, filename.toString()) : null,
29135
29500
  now: performance.now()
29136
29501
  },
29137
29502
  paths
@@ -29157,12 +29522,12 @@ async function runWatchLoop(invocation, resolved, options) {
29157
29522
  info(`\u26A0 Watch error: ${err.message}`);
29158
29523
  info(" The watcher may have missed changes. Restart with Ctrl+C if they stop arriving.");
29159
29524
  });
29160
- await new Promise((resolve21) => {
29525
+ await new Promise((resolve22) => {
29161
29526
  const stop = () => {
29162
29527
  stopped = true;
29163
29528
  if (timer) clearTimeout(timer);
29164
29529
  watcher.close();
29165
- resolve21();
29530
+ resolve22();
29166
29531
  };
29167
29532
  process.once("SIGINT", stop);
29168
29533
  process.once("SIGTERM", stop);
@@ -29172,12 +29537,12 @@ async function runWatchLoop(invocation, resolved, options) {
29172
29537
  var entryFile = process.argv[1] ?? "";
29173
29538
  var sameFile = (left, right) => {
29174
29539
  try {
29175
- return fs30.realpathSync(path32.resolve(left)) === fs30.realpathSync(path32.resolve(right));
29540
+ return fs30.realpathSync(path33.resolve(left)) === fs30.realpathSync(path33.resolve(right));
29176
29541
  } catch {
29177
29542
  return false;
29178
29543
  }
29179
29544
  };
29180
- var entryName = path32.basename(entryFile).toLowerCase();
29545
+ var entryName = path33.basename(entryFile).toLowerCase();
29181
29546
  var invokedDirectly = (entryName === "cli.js" || entryName === "cli.cjs") && entryFile.length > 0 && sameFile(entryFile, fileURLToPath4(import.meta.url));
29182
29547
  if (invokedDirectly) {
29183
29548
  void main().then(