codebase-snapshot 0.10.1 → 0.10.2

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/index.cjs CHANGED
@@ -637,9 +637,9 @@ var rubyProfile = {
637
637
  eachLine(content, (line) => {
638
638
  const trimmed = line.trim();
639
639
  if (!trimmed || trimmed.startsWith("#")) return;
640
- const relative10 = REQUIRE_RELATIVE.exec(trimmed);
641
- if (relative10) {
642
- summary.imports.push(`./${relative10[1]}`);
640
+ const relative11 = REQUIRE_RELATIVE.exec(trimmed);
641
+ if (relative11) {
642
+ summary.imports.push(`./${relative11[1]}`);
643
643
  return;
644
644
  }
645
645
  const required = REQUIRE.exec(trimmed);
@@ -998,6 +998,8 @@ function summarizeTypeScriptSource(relativePath, content) {
998
998
  if (cjsExports.length > 0) {
999
999
  summary.exportsKind = summary.exports.length > 0 ? "mixed" : "cjs";
1000
1000
  summary.exports.push(...cjsExports);
1001
+ } else if (summary.exports.length > 0) {
1002
+ summary.exportsKind = "esm";
1001
1003
  }
1002
1004
  const dedupeSorted2 = (values) => Array.from(new Set(values)).sort((a, b) => a < b ? -1 : a > b ? 1 : 0);
1003
1005
  summary.directives = dedupeSorted2(summary.directives);
@@ -1897,8 +1899,8 @@ function workspacePackageDirs(cwd, patterns) {
1897
1899
  function scanWorkspacePackages(cwd, patterns) {
1898
1900
  const files = /* @__PURE__ */ new Set();
1899
1901
  const dependencies = /* @__PURE__ */ new Set();
1900
- for (const relative10 of workspacePackageDirs(cwd, patterns)) {
1901
- const full = path16__namespace.join(cwd, relative10);
1902
+ for (const relative11 of workspacePackageDirs(cwd, patterns)) {
1903
+ const full = path16__namespace.join(cwd, relative11);
1902
1904
  try {
1903
1905
  for (const entry of fs15__namespace.readdirSync(full, { withFileTypes: true })) files.add(entry.name);
1904
1906
  } catch {
@@ -3017,6 +3019,24 @@ var DEFAULT_SECRET_PATTERNS = [
3017
3019
  ),
3018
3020
  valueGroup: 2
3019
3021
  },
3022
+ {
3023
+ // A quoted assignment whose closing quote is **not on this line**.
3024
+ //
3025
+ // The rule above requires `\1`, so an unterminated literal never matched it and the
3026
+ // credential reached the artefact in clear with no finding at all. That is the shape a
3027
+ // truncated file, a hand-edited `.env` and a string that continues on the next line all
3028
+ // produce, and it was the only branch of the redaction pass that was silent.
3029
+ //
3030
+ // The value runs to the end of the line on purpose — there is no delimiter to stop at — and
3031
+ // a later quote of the same kind disables the rule (`(?!\1)`), so a balanced literal is
3032
+ // never matched here: `password: "abc" and "def"` belongs to the rule above.
3033
+ rule: "credential-assignment-unterminated",
3034
+ pattern: new RegExp(
3035
+ `(?:${QUOTED_CREDENTIAL_KEY}|${NOT_AFTER_QUOTE}(?<!id[-_])${STRONG_CREDENTIAL_NAME})\\s{0,8}${ASSIGN}\\s{0,8}(["'\`])((?:(?!\\1)[^\\\\\\n]|\\\\.){1,512})$`,
3036
+ "i"
3037
+ ),
3038
+ valueGroup: 2
3039
+ },
3020
3040
  {
3021
3041
  // `pass` and `credentials` are ambiguous on their own, so they
3022
3042
  // are accepted only against a quoted value long enough to be a credential.
@@ -3576,10 +3596,8 @@ function scanAndRedactSecrets(content, rules, filePath) {
3576
3596
  }
3577
3597
  if (spans.length > 0) {
3578
3598
  const maskedLine = applySpans(line, spans);
3579
- if (!quotesAreBalanced(line) || quotesAreBalanced(maskedLine)) {
3580
- recordFinding(lineNumber, matchedRules);
3581
- segments[index] = maskedLine;
3582
- }
3599
+ recordFinding(lineNumber, matchedRules);
3600
+ segments[index] = !quotesAreBalanced(line) || quotesAreBalanced(maskedLine) ? maskedLine : applySpansKeepingQuotes(line, spans);
3583
3601
  }
3584
3602
  }
3585
3603
  if (index + 1 < segments.length) lineNumber += 1;
@@ -3857,6 +3875,17 @@ function isDeclaredBinding(line, matchIndex, filePath) {
3857
3875
  return DECLARATION_KEYWORDS.test(line.slice(from, runStart));
3858
3876
  }
3859
3877
  function applySpans(line, spans) {
3878
+ let out = "";
3879
+ let cursor = 0;
3880
+ for (const span of mergedSpans(line, spans)) {
3881
+ out += line.slice(cursor, span.start);
3882
+ out += REDACTION_MARKER;
3883
+ cursor = span.end;
3884
+ }
3885
+ out += line.slice(cursor);
3886
+ return out;
3887
+ }
3888
+ function mergedSpans(line, spans) {
3860
3889
  const ordered = [...spans].sort((a, b) => a.start - b.start || a.end - b.end);
3861
3890
  const merged = [];
3862
3891
  for (const span of ordered) {
@@ -3867,11 +3896,25 @@ function applySpans(line, spans) {
3867
3896
  if (last && start <= last.end) last.end = Math.max(last.end, end);
3868
3897
  else merged.push({ start, end });
3869
3898
  }
3899
+ return merged;
3900
+ }
3901
+ function applySpansKeepingQuotes(line, spans) {
3870
3902
  let out = "";
3871
3903
  let cursor = 0;
3872
- for (const span of merged) {
3904
+ for (const span of mergedSpans(line, spans)) {
3873
3905
  out += line.slice(cursor, span.start);
3874
- out += REDACTION_MARKER;
3906
+ let run = false;
3907
+ for (let index = span.start; index < span.end; index += 1) {
3908
+ const char = line[index];
3909
+ if (char === '"' || char === "'" || char === "`" || char === "\\") {
3910
+ if (run) out += REDACTION_MARKER;
3911
+ run = false;
3912
+ out += char;
3913
+ continue;
3914
+ }
3915
+ run = true;
3916
+ }
3917
+ if (run) out += REDACTION_MARKER;
3875
3918
  cursor = span.end;
3876
3919
  }
3877
3920
  out += line.slice(cursor);
@@ -3880,7 +3923,7 @@ function applySpans(line, spans) {
3880
3923
 
3881
3924
  // src/version.ts
3882
3925
  var GENERATOR_NAME = "codebase-snapshot";
3883
- var GENERATOR_VERSION = "0.10.1";
3926
+ var GENERATOR_VERSION = "0.10.2";
3884
3927
  var SCHEMA_VERSION = "3.0.0";
3885
3928
  var LEGACY_GENERATOR_NAMES = ["@ankurhalder/codebase-snapshot"];
3886
3929
  function isOurGeneratorName(name) {
@@ -3912,8 +3955,8 @@ function brokenLinkRecord(linkPath, relativePath, rootReal) {
3912
3955
  };
3913
3956
  }
3914
3957
  function isInside(root, candidate) {
3915
- const relative10 = path16__namespace.relative(root, candidate);
3916
- return relative10 === "" || !relative10.startsWith(`..${path16__namespace.sep}`) && relative10 !== ".." && !path16__namespace.isAbsolute(relative10);
3958
+ const relative11 = path16__namespace.relative(root, candidate);
3959
+ return relative11 === "" || !relative11.startsWith(`..${path16__namespace.sep}`) && relative11 !== ".." && !path16__namespace.isAbsolute(relative11);
3917
3960
  }
3918
3961
  var GIT_OUTPUT_LIMIT = 68157440;
3919
3962
  function getGitInfo(cwd, fallbackBranch = "main") {
@@ -4898,73 +4941,9 @@ function supportsTypeScriptImports() {
4898
4941
  if (!Number.isFinite(major)) return false;
4899
4942
  return major > 22 || major === 22 && minor >= 6;
4900
4943
  }
4901
- function stripJsonComments2(raw) {
4902
- const text2 = raw.replace(/^\uFEFF/, "");
4903
- let out = "";
4904
- let inString = false;
4905
- let escaped = false;
4906
- for (let index = 0; index < text2.length; index += 1) {
4907
- const char = text2[index];
4908
- if (inString) {
4909
- out += char;
4910
- if (escaped) escaped = false;
4911
- else if (char === "\\") escaped = true;
4912
- else if (char === '"') inString = false;
4913
- continue;
4914
- }
4915
- if (char === '"') {
4916
- inString = true;
4917
- out += char;
4918
- continue;
4919
- }
4920
- if (char === "/" && text2[index + 1] === "/") {
4921
- while (index < text2.length && text2[index] !== "\n" && text2[index] !== "\r") index += 1;
4922
- index -= 1;
4923
- continue;
4924
- }
4925
- if (char === "/" && text2[index + 1] === "*") {
4926
- index += 2;
4927
- while (index < text2.length && !(text2[index] === "*" && text2[index + 1] === "/")) {
4928
- if (text2[index] === "\n" || text2[index] === "\r") out += text2[index];
4929
- index += 1;
4930
- }
4931
- index += 1;
4932
- continue;
4933
- }
4934
- out += char;
4935
- }
4936
- return stripTrailingCommas2(out);
4937
- }
4938
- function stripTrailingCommas2(text2) {
4939
- let out = "";
4940
- let inString = false;
4941
- let escaped = false;
4942
- for (let index = 0; index < text2.length; index += 1) {
4943
- const char = text2[index];
4944
- if (inString) {
4945
- out += char;
4946
- if (escaped) escaped = false;
4947
- else if (char === "\\") escaped = true;
4948
- else if (char === '"') inString = false;
4949
- continue;
4950
- }
4951
- if (char === '"') {
4952
- inString = true;
4953
- out += char;
4954
- continue;
4955
- }
4956
- if (char === ",") {
4957
- let next = index + 1;
4958
- while (next < text2.length && /\s/.test(text2[next])) next += 1;
4959
- if (text2[next] === "}" || text2[next] === "]") continue;
4960
- }
4961
- out += char;
4962
- }
4963
- return out;
4964
- }
4965
4944
  function parseJsonish(raw, file) {
4966
4945
  try {
4967
- return JSON.parse(stripJsonComments2(raw));
4946
+ return JSON.parse(stripJsonComments(raw));
4968
4947
  } catch (err) {
4969
4948
  throw new Error(`Could not parse ${file}: ${err.message}`);
4970
4949
  }
@@ -4982,7 +4961,7 @@ function describeValue2(value) {
4982
4961
  return `${typeof value} (${String(value)})`;
4983
4962
  }
4984
4963
  var isThenable = (value) => typeof value.then === "function";
4985
- var CONFIG_KEYS = /* @__PURE__ */ new Set([
4964
+ var CONFIG_KEY_NAMES = [
4986
4965
  "artifacts",
4987
4966
  "branch",
4988
4967
  "budgets",
@@ -5013,7 +4992,8 @@ var CONFIG_KEYS = /* @__PURE__ */ new Set([
5013
4992
  "skeleton",
5014
4993
  "tmpDir",
5015
4994
  "withDependents"
5016
- ]);
4995
+ ];
4996
+ var CONFIG_KEYS = new Set(CONFIG_KEY_NAMES);
5017
4997
  function assertKnownConfigKeys(value, file) {
5018
4998
  const unknownKeys = Object.keys(value).filter((key) => !CONFIG_KEYS.has(key));
5019
4999
  if (unknownKeys.length === 0) return;
@@ -5367,11 +5347,11 @@ function outputExcludePatterns(cwd, outDir, tmpDir) {
5367
5347
  const patterns = [];
5368
5348
  for (const dir of [outDir, tmpDir]) {
5369
5349
  const absolute = path16__namespace.resolve(cwd, dir);
5370
- const relative10 = path16__namespace.relative(cwd, absolute);
5371
- if (!relative10 || relative10 === ".." || relative10.startsWith(`..${path16__namespace.sep}`) || path16__namespace.isAbsolute(relative10)) {
5350
+ const relative11 = path16__namespace.relative(cwd, absolute);
5351
+ if (!relative11 || relative11 === ".." || relative11.startsWith(`..${path16__namespace.sep}`) || path16__namespace.isAbsolute(relative11)) {
5372
5352
  continue;
5373
5353
  }
5374
- patterns.push(`${relative10.replace(/\\/g, "/")}/**`);
5354
+ patterns.push(`${relative11.replace(/\\/g, "/")}/**`);
5375
5355
  }
5376
5356
  return patterns;
5377
5357
  }
@@ -5906,7 +5886,7 @@ function generateAuditReport(manifest, secretFindings, secretRules) {
5906
5886
  );
5907
5887
  for (const file of affected) {
5908
5888
  const status = file.isPreviewTruncated ? "Truncated" : "Full";
5909
- const cutBy = file.truncationReason === "part-budget" ? "maxPartBytes" : "largeFileBytes";
5889
+ const cutBy = file.truncationReason === "part-budget" ? "part budget (maxPartBytes)" : "large-file budget (largeFileBytes)";
5910
5890
  lines.push(
5911
5891
  `| ${code(file.relativePath)} | ${file.sizeBytes} | ${file.lines} | ${file.includedBytes} | ${file.includedLines} | ${status} | ${cutBy} |`
5912
5892
  );
@@ -6019,11 +5999,11 @@ function generateSarifReport(manifest, findings, rules, toolVersion) {
6019
5999
  codebaseSnapshotFinding: `${findingPath}#L${line}#${finding.rules.join("+")}`
6020
6000
  }
6021
6001
  };
6022
- }).sort(
6023
- (a, b) => a.locations[0].physicalLocation.artifactLocation.uri.localeCompare(
6024
- b.locations[0].physicalLocation.artifactLocation.uri
6025
- ) || a.locations[0].physicalLocation.region.startLine - b.locations[0].physicalLocation.region.startLine
6026
- );
6002
+ }).sort((a, b) => {
6003
+ const left = a.locations[0].physicalLocation.artifactLocation.uri;
6004
+ const right = b.locations[0].physicalLocation.artifactLocation.uri;
6005
+ return (left < right ? -1 : left > right ? 1 : 0) || a.locations[0].physicalLocation.region.startLine - b.locations[0].physicalLocation.region.startLine;
6006
+ });
6027
6007
  const log = {
6028
6008
  $schema: SARIF_SCHEMA,
6029
6009
  version: SARIF_VERSION,
@@ -6114,6 +6094,7 @@ function truncatePreview(content, headLines, tailLines) {
6114
6094
  // src/partitioner/chunker.ts
6115
6095
  var HEADER_RESERVE_BYTES = 2048 + Buffer.byteLength(UNTRUSTED_CONTENT_NOTICE, "utf8") + 8;
6116
6096
  var MIN_SECTION_BUDGET_BYTES = 512;
6097
+ var MIN_PART_BUDGET_BYTES = MIN_SECTION_BUDGET_BYTES + HEADER_RESERVE_BYTES;
6117
6098
  var MAX_SPLIT_PASSES = 64;
6118
6099
  var BUDGET_MARKER_RESERVE = 96;
6119
6100
  function insertTokenLine(markdown, tokens) {
@@ -6152,10 +6133,17 @@ function partitionFilesForBuckets(buckets, contentFingerprint) {
6152
6133
  const groups = [];
6153
6134
  for (const bucket of buckets) {
6154
6135
  if (bucket.files.length === 0) continue;
6155
- const budget = Math.max(
6156
- MIN_SECTION_BUDGET_BYTES + HEADER_RESERVE_BYTES,
6157
- bucket.budgetBytes
6158
- );
6136
+ if (!Number.isFinite(bucket.budgetBytes)) {
6137
+ throw new Error(
6138
+ `A part budget must be a finite number of bytes; received ${String(bucket.budgetBytes)}.`
6139
+ );
6140
+ }
6141
+ if (bucket.budgetBytes < MIN_PART_BUDGET_BYTES) {
6142
+ throw new Error(
6143
+ `A part budget of ${bucket.budgetBytes} B is below the ${MIN_PART_BUDGET_BYTES} B minimum: the header every part must carry is larger than that, so the budget could not be honoured. Use a budget of at least 4096 B.`
6144
+ );
6145
+ }
6146
+ const budget = bucket.budgetBytes;
6159
6147
  const sectionBudget = budget - HEADER_RESERVE_BYTES;
6160
6148
  const prepared = bucket.files.map((file) => prepareSection(file, sectionBudget, budget));
6161
6149
  for (const sections of greedyGroups(prepared, budget)) groups.push({ sections, budget });
@@ -6846,6 +6834,22 @@ function generateProjectTree(filePaths) {
6846
6834
  const fence = fenceForText(lines.join("\n"), 3);
6847
6835
  return ["# Project Tree", "", `${fence}text`, ...lines, fence, ""].join("\n");
6848
6836
  }
6837
+ function treeTruncationWarnings(treeText) {
6838
+ const warnings = [];
6839
+ const depth = /\[tree truncated at (\d+) levels\]/.exec(treeText);
6840
+ if (depth) {
6841
+ warnings.push(
6842
+ `reports/project-tree.md was truncated at the ${depth[1]}-level depth cap: deeper directories are not listed there.`
6843
+ );
6844
+ }
6845
+ const lines = /\[tree truncated at (\d+) lines\]/.exec(treeText);
6846
+ if (lines) {
6847
+ warnings.push(
6848
+ `reports/project-tree.md was truncated at the ${lines[1]}-line cap: the rest of the tree is not listed there.`
6849
+ );
6850
+ }
6851
+ return warnings;
6852
+ }
6849
6853
  function gitPaths(cwd, args) {
6850
6854
  let output;
6851
6855
  try {
@@ -7010,8 +7014,8 @@ function tsconfigPathsFor(cwd) {
7010
7014
  return value;
7011
7015
  }
7012
7016
  function repositoryRelative(cwd, target) {
7013
- const relative10 = path16__namespace.relative(cwd, target).replace(/\\/g, "/");
7014
- return relative10.length === 0 || !relative10.startsWith("..") && !path16__namespace.isAbsolute(relative10) ? relative10 : null;
7017
+ const relative11 = path16__namespace.relative(cwd, target).replace(/\\/g, "/");
7018
+ return relative11.length === 0 || !relative11.startsWith("..") && !path16__namespace.isAbsolute(relative11) ? relative11 : null;
7015
7019
  }
7016
7020
  function rememberFirst(map, key, value) {
7017
7021
  if (!map.has(key)) map.set(key, value);
@@ -7281,6 +7285,16 @@ function wouldNowBeIncluded(cwd, relativePath) {
7281
7285
  return false;
7282
7286
  }
7283
7287
  }
7288
+ var TRUNCATION_REASONS = /* @__PURE__ */ new Set([
7289
+ "large-file-budget",
7290
+ "part-budget",
7291
+ "section-metadata"
7292
+ ]);
7293
+ function isConfinedRelative(value) {
7294
+ if (value.length === 0 || value.includes("\0") || value.includes("\\")) return false;
7295
+ if (path16__namespace.isAbsolute(value)) return false;
7296
+ return !value.split("/").includes("..");
7297
+ }
7284
7298
  function describeManifestShapeProblem(value) {
7285
7299
  if (!value || typeof value !== "object" || Array.isArray(value)) return "not a JSON object";
7286
7300
  const candidate = value;
@@ -7346,6 +7360,68 @@ function describeManifestShapeProblem(value) {
7346
7360
  if (!candidate.kinds || typeof candidate.kinds !== "object" || Array.isArray(candidate.kinds)) {
7347
7361
  return 'missing "kinds" object';
7348
7362
  }
7363
+ const incompleteCount = counts.incompleteCount;
7364
+ if (typeof incompleteCount !== "number" || !Number.isSafeInteger(incompleteCount) || incompleteCount < 0) {
7365
+ return "missing numeric `counts.incompleteCount`";
7366
+ }
7367
+ const incomplete = candidate.incomplete;
7368
+ if (!Array.isArray(incomplete)) return 'missing "incomplete" array';
7369
+ if (incompleteCount !== incomplete.length) {
7370
+ return "`counts.incompleteCount` does not match the length of `incomplete`";
7371
+ }
7372
+ for (const entry of incomplete) {
7373
+ if (!entry || typeof entry !== "object" || Array.isArray(entry)) {
7374
+ return 'an "incomplete" entry is not an object';
7375
+ }
7376
+ const fields = entry;
7377
+ const relativePath = fields.relativePath;
7378
+ if (typeof relativePath !== "string" || relativePath.length === 0) {
7379
+ return 'an "incomplete" entry has no "relativePath"';
7380
+ }
7381
+ if (!isConfinedRelative(relativePath)) {
7382
+ return 'an "incomplete" entry "relativePath" must stay inside the repository';
7383
+ }
7384
+ if (typeof fields.part !== "string" || fields.part.trim() === "") {
7385
+ return 'an "incomplete" entry has no "part"';
7386
+ }
7387
+ if (typeof fields.reason !== "string" || !TRUNCATION_REASONS.has(fields.reason)) {
7388
+ return 'an "incomplete" entry has an unknown "reason"';
7389
+ }
7390
+ for (const key of ["omittedLines", "includedLines", "lines"]) {
7391
+ const value2 = fields[key];
7392
+ if (typeof value2 !== "number" || !Number.isSafeInteger(value2) || value2 < 0) {
7393
+ return `an "incomplete" entry "${key}" must be a non-negative integer`;
7394
+ }
7395
+ }
7396
+ const lines = fields.lines;
7397
+ if (fields.includedLines > lines) {
7398
+ return 'an "incomplete" entry "includedLines" exceeds its "lines"';
7399
+ }
7400
+ const ranges = fields.omittedRanges;
7401
+ if (!Array.isArray(ranges)) return 'an "incomplete" entry has no "omittedRanges" array';
7402
+ let previousEnd = 0;
7403
+ let omitted = 0;
7404
+ for (const range of ranges) {
7405
+ if (!Array.isArray(range) || range.length !== 2) {
7406
+ return 'an "incomplete" entry "omittedRanges" must hold [from, to] pairs';
7407
+ }
7408
+ const [from, to] = range;
7409
+ if (typeof from !== "number" || typeof to !== "number" || !Number.isSafeInteger(from) || !Number.isSafeInteger(to)) {
7410
+ return 'an "incomplete" entry "omittedRanges" must hold integer pairs';
7411
+ }
7412
+ if (from < 1 || to < from || to > lines) {
7413
+ return `an "incomplete" entry records an omitted range ${from}-${to}, outside 1-${lines}`;
7414
+ }
7415
+ if (from <= previousEnd) {
7416
+ return 'an "incomplete" entry "omittedRanges" must be sorted and non-overlapping';
7417
+ }
7418
+ previousEnd = to;
7419
+ omitted += to - from + 1;
7420
+ }
7421
+ if (omitted !== fields.omittedLines) {
7422
+ return "`omittedLines` does not match the ranges it records";
7423
+ }
7424
+ }
7349
7425
  }
7350
7426
  if (!Array.isArray(candidate.files)) return 'missing "files" array';
7351
7427
  for (const entry of candidate.files) {
@@ -7459,10 +7535,56 @@ function validateSnapshot(configInput) {
7459
7535
  );
7460
7536
  }
7461
7537
  const manifestFileMap = /* @__PURE__ */ new Map();
7538
+ const manifestFilesByPath = /* @__PURE__ */ new Map();
7462
7539
  for (const file of manifest.files) {
7463
7540
  if (file && typeof file.relativePath === "string") {
7464
7541
  manifestFileMap.set(file.relativePath, file.hashSha256);
7542
+ manifestFilesByPath.set(file.relativePath, file);
7543
+ }
7544
+ }
7545
+ const incompleteRecords = manifest.incomplete ?? [];
7546
+ const incompleteness = /* @__PURE__ */ new Map();
7547
+ for (const record of incompleteRecords) {
7548
+ incompleteness.set(record.relativePath, record);
7549
+ const label = maskedPath(record.relativePath, config.secretRules);
7550
+ const file = manifestFilesByPath.get(record.relativePath);
7551
+ if (file === void 0) {
7552
+ drift.partIssues.push({
7553
+ part: "(manifest)",
7554
+ issue: `${label} is in incomplete[] but not in files[]`
7555
+ });
7556
+ continue;
7557
+ }
7558
+ if (file.part !== record.part) {
7559
+ drift.partIssues.push({
7560
+ part: "(manifest)",
7561
+ issue: `${label} is recorded in part ${String(record.part)} in incomplete[] and part ${String(file.part)} in files[]`
7562
+ });
7465
7563
  }
7564
+ if (file.truncationReason !== record.reason) {
7565
+ drift.partIssues.push({
7566
+ part: "(manifest)",
7567
+ issue: `${label} records truncationReason ${String(file.truncationReason)} in files[] and reason ${String(record.reason)} in incomplete[]`
7568
+ });
7569
+ }
7570
+ const recordedRanges = file.omittedRanges ?? [];
7571
+ const rangesAgree = recordedRanges.length === record.omittedRanges.length && recordedRanges.every(
7572
+ ([from, to], index) => record.omittedRanges[index][0] === from && record.omittedRanges[index][1] === to
7573
+ );
7574
+ if (!rangesAgree || file.includedLines !== record.includedLines || file.lines !== record.lines) {
7575
+ drift.partIssues.push({
7576
+ part: "(manifest)",
7577
+ issue: `${label} records different omission numbers in files[] and incomplete[]`
7578
+ });
7579
+ }
7580
+ }
7581
+ for (const file of manifest.files) {
7582
+ if (file.truncationReason === void 0) continue;
7583
+ if (incompleteness.has(file.relativePath)) continue;
7584
+ drift.partIssues.push({
7585
+ part: "(manifest)",
7586
+ issue: `${maskedPath(file.relativePath, config.secretRules)} records a truncationReason but is missing from incomplete[]`
7587
+ });
7466
7588
  }
7467
7589
  const skippedReasons = /* @__PURE__ */ new Map();
7468
7590
  for (const entry of manifest.skipped) {
@@ -7520,7 +7642,7 @@ function validateSnapshot(configInput) {
7520
7642
  // snapshot was reported as drifting.
7521
7643
  toolOwnedPaths: [config.outDir, config.tmpDir].map(
7522
7644
  (directory) => path16__namespace.relative(config.cwd, path16__namespace.resolve(config.cwd, directory)).replace(/\\/g, "/")
7523
- ).filter((relative10) => relative10.length > 0 && !relative10.startsWith(".."))
7645
+ ).filter((relative11) => relative11.length > 0 && !relative11.startsWith(".."))
7524
7646
  });
7525
7647
  for (const diskFile of collection.files) {
7526
7648
  const snapshotHash = manifestFileMap.get(diskFile);
@@ -7976,8 +8098,8 @@ function validateSnapshot(configInput) {
7976
8098
  const target = match[1].split("#")[0];
7977
8099
  if (target.length === 0 || /^[a-z][a-z0-9+.-]*:/i.test(target)) continue;
7978
8100
  const resolved = path16__namespace.resolve(snapshotDir, "reports", target);
7979
- const relative10 = path16__namespace.relative(snapshotDir, resolved);
7980
- if (relative10.startsWith("..") || path16__namespace.isAbsolute(relative10) || !fs15__namespace.existsSync(resolved)) {
8101
+ const relative11 = path16__namespace.relative(snapshotDir, resolved);
8102
+ if (relative11.startsWith("..") || path16__namespace.isAbsolute(relative11) || !fs15__namespace.existsSync(resolved)) {
7981
8103
  drift.partIssues.push({
7982
8104
  part: key,
7983
8105
  issue: `links to ${maskedPath(target, config.secretRules)}, which does not exist in the snapshot`
@@ -8172,14 +8294,14 @@ function writeCache(file, entry) {
8172
8294
  }
8173
8295
  }
8174
8296
  function fetchLatestVersion(url = PACKAGE_LATEST_URL, timeoutMs = REQUEST_TIMEOUT_MS) {
8175
- return new Promise((resolve7) => {
8297
+ return new Promise((resolve8) => {
8176
8298
  let settled = false;
8177
8299
  let request = null;
8178
8300
  const finish = (value) => {
8179
8301
  if (settled) return;
8180
8302
  settled = true;
8181
8303
  clearTimeout(deadline);
8182
- resolve7(value);
8304
+ resolve8(value);
8183
8305
  };
8184
8306
  const deadline = setTimeout(() => {
8185
8307
  request?.destroy();
@@ -8267,23 +8389,23 @@ function describeMatcher(matcher) {
8267
8389
  function normalizeTarget(cwd, target) {
8268
8390
  const resolvedCwd = path16__namespace.resolve(cwd);
8269
8391
  const absolute = path16__namespace.resolve(resolvedCwd, target);
8270
- const relative10 = path16__namespace.relative(resolvedCwd, absolute);
8271
- if (relative10 === "" || relative10 === ".." || relative10.startsWith(`..${path16__namespace.sep}`) || path16__namespace.isAbsolute(relative10)) {
8392
+ const relative11 = path16__namespace.relative(resolvedCwd, absolute);
8393
+ if (relative11 === "" || relative11 === ".." || relative11.startsWith(`..${path16__namespace.sep}`) || path16__namespace.isAbsolute(relative11)) {
8272
8394
  return { relative: target.replace(/\\/g, "/"), outsideRoot: true };
8273
8395
  }
8274
- return { relative: relative10.split(path16__namespace.sep).join("/"), outsideRoot: false };
8396
+ return { relative: relative11.split(path16__namespace.sep).join("/"), outsideRoot: false };
8275
8397
  }
8276
8398
  function findRuleMatch(rules, relativePath) {
8277
8399
  return rules.find(
8278
8400
  (rule) => matchRule(relativePath, rule.match)
8279
8401
  );
8280
8402
  }
8281
- function findRecordedAncestor(skipped, relative10, maskedPath2) {
8403
+ function findRecordedAncestor(skipped, relative11, maskedPath2) {
8282
8404
  let nearest;
8283
8405
  for (const record of skipped) {
8284
8406
  const ancestorPath = record.path;
8285
8407
  if (ancestorPath.length === 0) continue;
8286
- const isAncestor = relative10.startsWith(`${ancestorPath}/`) || maskedPath2.startsWith(`${ancestorPath}/`);
8408
+ const isAncestor = relative11.startsWith(`${ancestorPath}/`) || maskedPath2.startsWith(`${ancestorPath}/`);
8287
8409
  if (!isAncestor) continue;
8288
8410
  if (!nearest || ancestorPath.length > nearest.path.length) nearest = record;
8289
8411
  }
@@ -8299,8 +8421,8 @@ function readManifest2(config) {
8299
8421
  }
8300
8422
  function explainPath(config, target) {
8301
8423
  const normalized = normalizeTarget(config.cwd, target);
8302
- const relative10 = normalized.relative;
8303
- const maskedPath2 = findSecretInPath(relative10, config.secretRules)?.masked ?? relative10;
8424
+ const relative11 = normalized.relative;
8425
+ const maskedPath2 = findSecretInPath(relative11, config.secretRules)?.masked ?? relative11;
8304
8426
  if (normalized.outsideRoot) {
8305
8427
  return {
8306
8428
  path: maskedPath2,
@@ -8310,7 +8432,7 @@ function explainPath(config, target) {
8310
8432
  detail: "path resolves outside the configured repository root and was not inspected"
8311
8433
  };
8312
8434
  }
8313
- const absolute = path16__namespace.join(config.cwd, relative10);
8435
+ const absolute = path16__namespace.join(config.cwd, relative11);
8314
8436
  const result = {
8315
8437
  path: maskedPath2,
8316
8438
  exists: fs15__namespace.existsSync(absolute),
@@ -8328,11 +8450,11 @@ function explainPath(config, target) {
8328
8450
  // that is only missing because the walker dropped the tool's own output directory.
8329
8451
  toolOwnedPaths: [config.outDir, config.tmpDir].map(
8330
8452
  (directory) => path16__namespace.relative(config.cwd, path16__namespace.resolve(config.cwd, directory)).replace(/\\/g, "/")
8331
- ).filter((relative11) => relative11.length > 0 && !relative11.startsWith(".."))
8453
+ ).filter((relative12) => relative12.length > 0 && !relative12.startsWith(".."))
8332
8454
  });
8333
- if (!collection.files.includes(relative10)) {
8455
+ if (!collection.files.includes(relative11)) {
8334
8456
  const record = collection.skipped.find(
8335
- (entry2) => entry2.path === relative10 || entry2.path === maskedPath2
8457
+ (entry2) => entry2.path === relative11 || entry2.path === maskedPath2
8336
8458
  );
8337
8459
  if (record) {
8338
8460
  result.reason = record.reason;
@@ -8341,7 +8463,7 @@ function explainPath(config, target) {
8341
8463
  result.reason = "missing";
8342
8464
  result.detail = "no such file or directory, relative to the configured cwd";
8343
8465
  } else {
8344
- const ancestor = findRecordedAncestor(collection.skipped, relative10, maskedPath2);
8466
+ const ancestor = findRecordedAncestor(collection.skipped, relative11, maskedPath2);
8345
8467
  if (ancestor) {
8346
8468
  result.reason = ancestor.reason;
8347
8469
  result.detail = ancestor.detail ? `${ancestor.detail} \u2014 inherited from the skipped directory \`${ancestor.path}\`` : `inside the skipped directory \`${ancestor.path}\``;
@@ -8361,11 +8483,11 @@ function explainPath(config, target) {
8361
8483
  ...config.changedSince === void 0 ? {} : { changedSince: config.changedSince },
8362
8484
  ...config.staged === true ? { staged: true } : {}
8363
8485
  });
8364
- inScope = scope.paths.has(relative10);
8486
+ inScope = scope.paths.has(relative11);
8365
8487
  if (!inScope && config.withDependents === true) {
8366
8488
  inScope = importsChangedFile(
8367
- relative10,
8368
- importsOfFile(relative10, absolute),
8489
+ relative11,
8490
+ importsOfFile(relative11, absolute),
8369
8491
  scope.paths,
8370
8492
  buildImportResolver(collection.files.map((file) => ({ relativePath: file })))
8371
8493
  );
@@ -8423,12 +8545,12 @@ function explainPath(config, target) {
8423
8545
  result.bytes = buffer.length;
8424
8546
  result.lines = countLines(text2);
8425
8547
  if (decoded.encoding !== "utf-8") result.encoding = decoded.encoding;
8426
- const { findings } = scanAndRedactSecrets(text2, config.secretRules, relative10);
8548
+ const { findings } = scanAndRedactSecrets(text2, config.secretRules, relative11);
8427
8549
  result.secretCount = findings.length;
8428
8550
  result.secrets = findings.slice(0, 20).map((finding) => ({ rules: finding.rules, line: finding.line }));
8429
8551
  let inclusionMode = "full";
8430
- if (config.skeleton === true && isSkeletonizable(relative10)) {
8431
- const skeleton = skeletonizeTypeScript(text2, relative10);
8552
+ if (config.skeleton === true && isSkeletonizable(relative11)) {
8553
+ const skeleton = skeletonizeTypeScript(text2, relative11);
8432
8554
  if (skeleton.collapsed > 0) inclusionMode = "signatures";
8433
8555
  }
8434
8556
  if (inclusionMode !== "signatures" && buffer.length > config.largeFileBytes) {
@@ -8437,15 +8559,15 @@ function explainPath(config, target) {
8437
8559
  }
8438
8560
  result.inclusionMode = inclusionMode;
8439
8561
  }
8440
- result.layer = classifyLayer(relative10, config.layers);
8441
- result.kind = classifyKind(relative10, config.kinds);
8442
- result.language = detectLanguage(relative10);
8443
- const layerRule = findRuleMatch(config.layers, relative10);
8562
+ result.layer = classifyLayer(relative11, config.layers);
8563
+ result.kind = classifyKind(relative11, config.kinds);
8564
+ result.language = detectLanguage(relative11);
8565
+ const layerRule = findRuleMatch(config.layers, relative11);
8444
8566
  if (layerRule) result.layerMatch = describeMatcher(layerRule.match);
8445
- const kindRule = findRuleMatch(config.kinds, relative10);
8567
+ const kindRule = findRuleMatch(config.kinds, relative11);
8446
8568
  if (kindRule) result.kindMatch = describeMatcher(kindRule.match);
8447
8569
  const manifest = readManifest2(config);
8448
- const entry = Array.isArray(manifest?.files) ? manifest.files.find((file) => file.relativePath === relative10) : void 0;
8570
+ const entry = Array.isArray(manifest?.files) ? manifest.files.find((file) => file.relativePath === relative11) : void 0;
8449
8571
  result.part = entry?.part ?? null;
8450
8572
  return result;
8451
8573
  }
@@ -8494,19 +8616,19 @@ function side(manifest) {
8494
8616
  function shortDigest(value) {
8495
8617
  return value === null ? "not recorded" : `${value.slice(0, 12)}\u2026`;
8496
8618
  }
8497
- function describeLayerChanges(before, after) {
8619
+ function describeLayerChanges(before, after, secretRules) {
8498
8620
  const names = Array.from(/* @__PURE__ */ new Set([...Object.keys(before), ...Object.keys(after)])).sort();
8499
8621
  const changes = [];
8500
8622
  for (const name of names) {
8501
8623
  const was = before[name] ?? 0;
8502
8624
  const now = after[name] ?? 0;
8503
8625
  if (was === now) continue;
8504
- const label = findSecretInPath(name)?.masked ?? name;
8626
+ const label = findSecretInPath(name, secretRules)?.masked ?? name;
8505
8627
  changes.push(`layer "${label}": ${was} file(s) \u2192 ${now} file(s)`);
8506
8628
  }
8507
8629
  return changes;
8508
8630
  }
8509
- function describePartChanges(before, after) {
8631
+ function describePartChanges(before, after, secretRules) {
8510
8632
  const index = (parts) => {
8511
8633
  const map = /* @__PURE__ */ new Map();
8512
8634
  for (const part of parts) {
@@ -8516,7 +8638,7 @@ function describePartChanges(before, after) {
8516
8638
  };
8517
8639
  const left = index(before);
8518
8640
  const right = index(after);
8519
- const label = (filename) => findSecretInPath(filename)?.masked ?? filename;
8641
+ const label = (filename) => findSecretInPath(filename, secretRules)?.masked ?? filename;
8520
8642
  const changes = [];
8521
8643
  for (const [filename, part] of right) {
8522
8644
  const previous = left.get(filename);
@@ -8544,7 +8666,15 @@ function describePartChanges(before, after) {
8544
8666
  }
8545
8667
  return changes;
8546
8668
  }
8547
- function describePayloadDiff(before, after, sourceFilesIdentical) {
8669
+ function maskLayerNames(layers, secretRules) {
8670
+ return Object.fromEntries(
8671
+ Object.entries(layers ?? {}).map(([name, count]) => [
8672
+ findSecretInPath(name, secretRules)?.masked ?? name,
8673
+ count
8674
+ ])
8675
+ );
8676
+ }
8677
+ function describePayloadDiff(before, after, sourceFilesIdentical, secretRules) {
8548
8678
  const generatorBefore = before.generator?.version ?? "unknown";
8549
8679
  const generatorAfter = after.generator?.version ?? "unknown";
8550
8680
  const digestBefore = typeof before.config?.digest === "string" ? before.config.digest : null;
@@ -8557,35 +8687,43 @@ function describePayloadDiff(before, after, sourceFilesIdentical) {
8557
8687
  const configurationDiffers = generatorDiffers || digestDiffers || schemaDiffers;
8558
8688
  const fingerprintDiffers = before.fingerprint !== after.fingerprint;
8559
8689
  const partsDiffer = before.counts.partsCount !== after.counts.partsCount;
8560
- const partChanges = describePartChanges(before.parts ?? [], after.parts ?? []);
8561
- const layerChanges = describeLayerChanges(before.layers ?? {}, after.layers ?? {});
8690
+ const partChanges = describePartChanges(before.parts ?? [], after.parts ?? [], secretRules);
8691
+ const layerChanges = describeLayerChanges(before.layers ?? {}, after.layers ?? {}, secretRules);
8562
8692
  const reasons = [];
8693
+ const codes = [];
8563
8694
  if (schemaDiffers) {
8695
+ codes.push("schema-version");
8564
8696
  reasons.push(
8565
8697
  `schema version ${schemaBefore} \u2192 ${schemaAfter} (the two manifests describe different formats)`
8566
8698
  );
8567
8699
  }
8568
8700
  if (digestDiffers) {
8701
+ codes.push("config-digest");
8569
8702
  reasons.push(
8570
8703
  `configuration digest ${shortDigest(digestBefore)} \u2192 ${shortDigest(digestAfter)} (budgets, preview thresholds, redaction rules and artifact selection all count)`
8571
8704
  );
8572
8705
  } else if (digestBefore === null || digestAfter === null) {
8573
8706
  const missing = digestBefore === null && digestAfter !== null ? "before" : digestAfter === null && digestBefore !== null ? "after" : "both";
8707
+ codes.push("config-digest-missing");
8574
8708
  reasons.push(
8575
8709
  `configuration digest not recorded on the ${missing} side (manifest written before 4.0.5); compared the content fingerprint and part count instead`
8576
8710
  );
8577
8711
  }
8578
8712
  if (generatorDiffers) {
8713
+ codes.push("generator");
8579
8714
  reasons.push(`generator ${generatorBefore} \u2192 ${generatorAfter}`);
8580
8715
  }
8581
8716
  if (fingerprintDiffers && (sourceFilesIdentical || configurationDiffers)) {
8717
+ codes.push("fingerprint");
8582
8718
  reasons.push(
8583
8719
  `content fingerprint ${shortDigest(before.fingerprint)} \u2192 ${shortDigest(after.fingerprint)}` + (sourceFilesIdentical ? " (same source files, packed or configured differently)" : "")
8584
8720
  );
8585
8721
  }
8586
8722
  if (partsDiffer) {
8723
+ codes.push("parts-count");
8587
8724
  reasons.push(`${before.counts.partsCount} part(s) \u2192 ${after.counts.partsCount} part(s)`);
8588
8725
  }
8726
+ for (let index = 0; index < layerChanges.length; index += 1) codes.push("layer-changed");
8589
8727
  reasons.push(...layerChanges);
8590
8728
  return {
8591
8729
  sourceFilesIdentical,
@@ -8597,8 +8735,12 @@ function describePayloadDiff(before, after, sourceFilesIdentical) {
8597
8735
  partsCount: { before: before.counts.partsCount, after: after.counts.partsCount },
8598
8736
  schemaVersion: { before: schemaBefore, after: schemaAfter },
8599
8737
  partsManifest: { differs: partChanges.length > 0, changes: partChanges },
8600
- layers: { before: { ...before.layers ?? {} }, after: { ...after.layers ?? {} } },
8601
- reasons
8738
+ // The layer maps are printed and serialized, so a layer named after a project token leaks the
8739
+ // token here even though every reason line above is masked. Found while testing the rules
8740
+ // parameter: masking the prose and not the data it describes is the same bug one layer down.
8741
+ layers: { before: maskLayerNames(before.layers, secretRules), after: maskLayerNames(after.layers, secretRules) },
8742
+ reasons,
8743
+ codes
8602
8744
  };
8603
8745
  }
8604
8746
  function hashMap(manifest) {
@@ -8637,10 +8779,10 @@ function comparableProblem(value) {
8637
8779
  function assertUsableManifest(value, label) {
8638
8780
  const problem = comparableProblem(value);
8639
8781
  if (problem) {
8640
- throw new Error(`The ${label} manifest is not a snapshot manifest this tool wrote: ${problem}.`);
8782
+ throw new Error(`The ${label} manifest is not a snapshot manifest: ${problem}.`);
8641
8783
  }
8642
8784
  }
8643
- function compareManifests(before, after) {
8785
+ function compareManifests(before, after, secretRules) {
8644
8786
  assertUsableManifest(before, "before");
8645
8787
  assertUsableManifest(after, "after");
8646
8788
  const left = hashMap(before);
@@ -8660,8 +8802,8 @@ function compareManifests(before, after) {
8660
8802
  }
8661
8803
  const sort = (values) => values.sort((a, b) => a < b ? -1 : a > b ? 1 : 0);
8662
8804
  const sourceFilesIdentical = added.length === 0 && removed.length === 0 && changed.length === 0;
8663
- const payload = describePayloadDiff(before, after, sourceFilesIdentical);
8664
- const mask = (values) => values.map((value) => findSecretInPath(value)?.masked ?? value);
8805
+ const payload = describePayloadDiff(before, after, sourceFilesIdentical, secretRules);
8806
+ const mask = (values) => values.map((value) => findSecretInPath(value, secretRules)?.masked ?? value);
8665
8807
  return {
8666
8808
  before: side(before),
8667
8809
  after: side(after),
@@ -8695,7 +8837,7 @@ function loadManifest(target) {
8695
8837
  const problem = describeManifestShapeProblem(parsed);
8696
8838
  if (problem) {
8697
8839
  throw new Error(
8698
- `${manifestPath} is not a usable snapshot manifest: ${problem}. Point diff at a manifest.json written by \`generate\` (or at the directory that holds it).`
8840
+ `${manifestPath} is not a snapshot manifest: ${problem}. Point diff at a manifest.json written by \`generate\` (or at the directory that holds it).`
8699
8841
  );
8700
8842
  }
8701
8843
  return parsed;
@@ -8950,6 +9092,10 @@ function renderConfig(answers) {
8950
9092
  // Set true to drop the built-in rules above and keep only customPatterns.
8951
9093
  disableDefaultPatterns: false,
8952
9094
  },
9095
+ // The library spelling of the same list, accepted here too so a config file can
9096
+ // express what a caller passes in code: an array of { rule, pattern } or a bare
9097
+ // RegExp. Use \`secrets.customPatterns\` above unless you are porting code.
9098
+ // secretRules: [],
8953
9099
 
8954
9100
  // \u2500\u2500 Artifacts \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500
8955
9101
  artifacts: {
@@ -9137,7 +9283,7 @@ function keyReader(input) {
9137
9283
  next() {
9138
9284
  const queued = queue.shift();
9139
9285
  if (queued) return Promise.resolve(queued);
9140
- return new Promise((resolve7) => waiters.push(resolve7));
9286
+ return new Promise((resolve8) => waiters.push(resolve8));
9141
9287
  },
9142
9288
  close() {
9143
9289
  input.off("keypress", onKey);
@@ -9566,7 +9712,18 @@ function updatePackageJson(cwd, notes) {
9566
9712
  writeFileOrExplain(packagePath, serializePackageJson(raw, parsed));
9567
9713
  return { scripts: added, dependency };
9568
9714
  }
9569
- var GITIGNORE_ENTRIES = ["/snapshot/", "/snapshot.tmp/"];
9715
+ function gitignoreEntriesFor(cwd, outDir, tmpDir) {
9716
+ const entries = [];
9717
+ for (const directory of [outDir, tmpDir]) {
9718
+ if (directory === null) continue;
9719
+ const relative11 = path16__namespace.relative(cwd, path16__namespace.resolve(cwd, directory)).replace(/\\/g, "/");
9720
+ if (relative11 === "" || relative11 === "." || relative11.startsWith("..") || path16__namespace.isAbsolute(relative11)) {
9721
+ continue;
9722
+ }
9723
+ entries.push(`/${relative11}/`);
9724
+ }
9725
+ return [...new Set(entries)];
9726
+ }
9570
9727
  function resolvePresetChoice(detectedName, presetName) {
9571
9728
  return {
9572
9729
  value: presetName,
@@ -9859,7 +10016,10 @@ async function runInit(options) {
9859
10016
  }
9860
10017
  if (!reused) writeFileOrExplain(configPath, configText);
9861
10018
  const { scripts, dependency } = updatePackageJson(options.cwd, notes);
9862
- const ignore = appendGitignoreEntries(options.cwd, GITIGNORE_ENTRIES);
10019
+ const ignore = appendGitignoreEntries(
10020
+ options.cwd,
10021
+ gitignoreEntriesFor(options.cwd, answers.outDir, options.tmpDir ?? (reused ? null : "snapshot.tmp"))
10022
+ );
9863
10023
  if (ignore.note !== null) notes.push(ignore.note);
9864
10024
  return {
9865
10025
  configPath,
@@ -9877,10 +10037,10 @@ async function runInit(options) {
9877
10037
  };
9878
10038
  }
9879
10039
  function describeTarget(cwd) {
9880
- const relative10 = path16__namespace.relative(process.cwd(), cwd);
9881
- if (relative10 === "") return "this directory";
9882
- if (relative10.startsWith("..") || path16__namespace.isAbsolute(relative10)) return cwd;
9883
- return relative10;
10040
+ const relative11 = path16__namespace.relative(process.cwd(), cwd);
10041
+ if (relative11 === "") return "this directory";
10042
+ if (relative11.startsWith("..") || path16__namespace.isAbsolute(relative11)) return cwd;
10043
+ return relative11;
9884
10044
  }
9885
10045
  function firstRunMessage(reason, cwd) {
9886
10046
  const where = describeTarget(cwd);
@@ -9982,8 +10142,8 @@ function gitDirectory(cwd) {
9982
10142
  }
9983
10143
  }
9984
10144
  function isInside2(parent, child) {
9985
- const relative10 = path16__namespace.relative(parent, child);
9986
- return relative10 === "" || !relative10.startsWith("..") && !path16__namespace.isAbsolute(relative10);
10145
+ const relative11 = path16__namespace.relative(parent, child);
10146
+ return relative11 === "" || !relative11.startsWith("..") && !path16__namespace.isAbsolute(relative11);
9987
10147
  }
9988
10148
  function isRegisteredWorktree(gitDir, cwd) {
9989
10149
  try {
@@ -10246,16 +10406,29 @@ function retain(items, keep) {
10246
10406
  }
10247
10407
  items.length = write;
10248
10408
  }
10249
- function buildIndexes(files, tsconfigPaths) {
10409
+ function buildIndexes(files, tsconfigPaths, skippedSummaryImports = /* @__PURE__ */ new Map()) {
10250
10410
  const resolver = buildImportResolver(files, { tsconfig: tsconfigPaths });
10251
10411
  const importerCounts = /* @__PURE__ */ new Map();
10252
- const byFile = files.filter((file) => isSourceSummary(file.summary)).map((file) => {
10253
- const summary = file.summary;
10254
- return {
10255
- path: file.relativePath,
10256
- imports: summary.imports,
10257
- exports: summary.exports
10258
- };
10412
+ const byFile = files.flatMap((file) => {
10413
+ if (isSourceSummary(file.summary)) {
10414
+ return [
10415
+ {
10416
+ path: file.relativePath,
10417
+ imports: file.summary.imports,
10418
+ exports: file.summary.exports
10419
+ }
10420
+ ];
10421
+ }
10422
+ const imports = skippedSummaryImports.get(file.relativePath);
10423
+ if (imports === void 0) return [];
10424
+ return [
10425
+ {
10426
+ path: file.relativePath,
10427
+ imports,
10428
+ exports: [],
10429
+ exportsOmitted: true
10430
+ }
10431
+ ];
10259
10432
  });
10260
10433
  for (const entry of byFile) {
10261
10434
  for (const specifier of entry.imports) {
@@ -10375,6 +10548,9 @@ function resolveSafeOutputDirs(config) {
10375
10548
  return { outDir, tmpDir };
10376
10549
  }
10377
10550
  var IGNORABLE_ENTRIES = /* @__PURE__ */ new Set([".DS_Store"]);
10551
+ function isIgnorableEntry(entry) {
10552
+ return IGNORABLE_ENTRIES.has(entry.slice(entry.lastIndexOf("/") + 1));
10553
+ }
10378
10554
  var RUN_DIR_PREFIX = "run-";
10379
10555
  var STALE_RUN_MS = 60 * 60 * 1e3;
10380
10556
  function maskSummaryStrings(value, secretRules) {
@@ -10417,9 +10593,9 @@ function listEntries(dir) {
10417
10593
  return;
10418
10594
  }
10419
10595
  for (const child of children) {
10420
- const relative10 = prefix === "" ? child.name : `${prefix}/${child.name}`;
10421
- entries.push(relative10);
10422
- if (child.isDirectory()) walk(path16__namespace.join(absolute, child.name), relative10);
10596
+ const relative11 = prefix === "" ? child.name : `${prefix}/${child.name}`;
10597
+ entries.push(relative11);
10598
+ if (child.isDirectory()) walk(path16__namespace.join(absolute, child.name), relative11);
10423
10599
  }
10424
10600
  };
10425
10601
  walk(dir, "");
@@ -10430,7 +10606,7 @@ function markerInventory(dir, written) {
10430
10606
  const files = [];
10431
10607
  for (const entry of entries) {
10432
10608
  if (entry === OWNERSHIP_MARKER) continue;
10433
- if (IGNORABLE_ENTRIES.has(entry.slice(entry.lastIndexOf("/") + 1))) continue;
10609
+ if (isIgnorableEntry(entry)) continue;
10434
10610
  const full = path16__namespace.join(dir, ...entry.split("/"));
10435
10611
  let stats;
10436
10612
  try {
@@ -10719,7 +10895,7 @@ function assessSnapshotDirectory(dir) {
10719
10895
  }
10720
10896
  const entries = listEntries(dir);
10721
10897
  const foreignEntries = entries.filter(
10722
- (entry) => !recorded.has(entry) && !IGNORABLE_ENTRIES.has(entry)
10898
+ (entry) => !recorded.has(entry) && !isIgnorableEntry(entry)
10723
10899
  );
10724
10900
  if (foreignEntries.length > 0) {
10725
10901
  return { owned: false, problem: null, foreignEntries, marker: marker2 };
@@ -11215,7 +11391,7 @@ function generateSnapshot(configInput, options) {
11215
11391
  // output — but only at these exact paths, not at every directory that shares the name.
11216
11392
  toolOwnedPaths: [config.outDir, config.tmpDir].map(
11217
11393
  (directory) => path16__namespace.relative(config.cwd, path16__namespace.resolve(config.cwd, directory)).replace(/\\/g, "/")
11218
- ).filter((relative10) => relative10.length > 0 && !relative10.startsWith("..")),
11394
+ ).filter((relative11) => relative11.length > 0 && !relative11.startsWith("..")),
11219
11395
  // A staged path can be absent from the working tree while its index blob exists. Discovery
11220
11396
  // lists the working tree, so those paths would never reach the scan at all.
11221
11397
  ...stagedPaths.size > 0 ? { extraPaths: [...stagedPaths] } : {}
@@ -11635,7 +11811,7 @@ function generateSnapshot(configInput, options) {
11635
11811
  },
11636
11812
  layers: layerCounts,
11637
11813
  kinds: kindCounts,
11638
- indexes: buildIndexes(files, tsconfigPathsFor(config.cwd)),
11814
+ indexes: buildIndexes(files, tsconfigPathsFor(config.cwd), skippedSummaryImports),
11639
11815
  parts: parts.map((part) => part.metadata),
11640
11816
  files: files.map((file) => {
11641
11817
  const { content: _content, ...rest } = file;
@@ -11677,11 +11853,9 @@ function generateSnapshot(configInput, options) {
11677
11853
  let projectTree = null;
11678
11854
  if (config.artifacts.projectTree) {
11679
11855
  projectTree = generateProjectTree(files.map((file) => file.relativePath));
11680
- const depthMarker = /\[tree truncated at (\d+) levels\]/.exec(projectTree);
11681
- if (depthMarker) {
11682
- manifest.warnings.push(
11683
- `reports/project-tree.md was truncated at the ${depthMarker[1]}-level depth cap: deeper directories are not listed there.`
11684
- );
11856
+ const truncations = treeTruncationWarnings(projectTree);
11857
+ if (truncations.length > 0) {
11858
+ manifest.warnings.push(...truncations);
11685
11859
  manifest.totals.warningCount = manifest.warnings.length;
11686
11860
  }
11687
11861
  }
@@ -11709,7 +11883,7 @@ function generateSnapshot(configInput, options) {
11709
11883
  if (config.includeMonolith) {
11710
11884
  const fullFiles = files.map((file) => {
11711
11885
  const content = fullContents.get(file.relativePath) ?? "";
11712
- return {
11886
+ const entry = {
11713
11887
  ...file,
11714
11888
  content,
11715
11889
  inclusionMode: "full",
@@ -11717,6 +11891,9 @@ function generateSnapshot(configInput, options) {
11717
11891
  includedBytes: Buffer.byteLength(content, "utf8"),
11718
11892
  includedLines: countLines(content)
11719
11893
  };
11894
+ delete entry.truncationReason;
11895
+ delete entry.omittedRanges;
11896
+ return entry;
11720
11897
  });
11721
11898
  const bodyBytes = fullFiles.reduce((total, file) => total + file.includedBytes, 0);
11722
11899
  const definitelyTooLarge = config.maxMonolithBytes !== null && bodyBytes > config.maxMonolithBytes;
@@ -12031,6 +12208,7 @@ exports.summarizeMarkdown = summarizeMarkdown;
12031
12208
  exports.summarizeTypeScriptSource = summarizeTypeScriptSource;
12032
12209
  exports.summarizeWithProfile = summarizeWithProfile;
12033
12210
  exports.supportsTypeScriptImports = supportsTypeScriptImports;
12211
+ exports.treeTruncationWarnings = treeTruncationWarnings;
12034
12212
  exports.truncatePreview = truncatePreview;
12035
12213
  exports.truncateToBytes = truncateToBytes;
12036
12214
  exports.tsconfigPathsFor = tsconfigPathsFor;