codebase-snapshot 0.9.18 → 0.10.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.
@@ -1,4 +1,4 @@
1
- import { GENERATOR_VERSION, anchorForPath, displayPath, MIN_MAX_PART_BYTES, SCHEMA_VERSION, GENERATOR_NAME, ARTIFACT_NAMES, PRESETS, generateSnapshot, generateInWorker, validateSnapshot, buildImportResolver, resolveSpecifier, truncateToBytes, explainPath, renderExplainText, describeManifestShapeProblem, loadConfigFileDetailed, parseByteSize, resolveConfig } from './chunk-ZXWAVHSZ.js';
1
+ import { GENERATOR_VERSION, anchorForPath, displayPath, MIN_MAX_PART_BYTES, SCHEMA_VERSION, GENERATOR_NAME, ARTIFACT_NAMES, PRESETS, generateSnapshot, generateInWorker, validateSnapshot, buildImportResolver, resolveSpecifier, truncateToBytes, explainPath, renderExplainText, describeManifestShapeProblem, loadConfigFileDetailed, parseByteSize, resolveConfig } from './chunk-EP7OCPUM.js';
2
2
  import * as fs from 'fs';
3
3
  import * as path from 'path';
4
4
 
@@ -1277,6 +1277,9 @@ var readTool = {
1277
1277
  structured: {
1278
1278
  path: entry.relativePath,
1279
1279
  part: entry.part,
1280
+ // The window itself: a caller that wants to measure or re-send what it received should
1281
+ // not have to strip the header and the paging note back off `text`.
1282
+ body,
1280
1283
  layer: entry.layer,
1281
1284
  kind: entry.kind,
1282
1285
  language: entry.language,
@@ -1870,9 +1873,9 @@ function buildAgentContract() {
1870
1873
  {
1871
1874
  flag: "--large-file-bytes",
1872
1875
  type: "string",
1873
- default: 204800,
1876
+ default: 307200,
1874
1877
  appliesTo: optionAppliesTo("large-file-bytes"),
1875
- summary: "Above this size a file gets a head/tail preview instead of the full body."
1878
+ summary: "Above this size a file gets a head/tail preview instead of the full body. It defaults to maxPartBytes and may not exceed it: a file between the two could not fit a part."
1876
1879
  },
1877
1880
  {
1878
1881
  flag: "--max-monolith-bytes",
@@ -2107,7 +2110,7 @@ function buildAgentContract() {
2107
2110
  { key: "changedSince", type: "string | null", default: null, summary: "Snapshot only files that differ from this git ref." },
2108
2111
  { key: "staged", type: "boolean", default: false, summary: "Snapshot only files staged in the index." },
2109
2112
  { key: "withDependents", type: "boolean", default: false, summary: "With a changed-files scope, also include one hop of importers." },
2110
- { key: "largeFileBytes", type: "number | string", default: 204800, summary: "Preview threshold for large files." },
2113
+ { key: "largeFileBytes", type: "number | string", default: 307200, summary: "Preview threshold for large files; defaults to maxPartBytes and may not exceed it." },
2111
2114
  { key: "previewHeadLines", type: "number", default: 80, summary: "Lines kept from the head of a large file." },
2112
2115
  { key: "previewTailLines", type: "number", default: 40, summary: "Lines kept from the tail of a large file." },
2113
2116
  { key: "includeMonolith", type: "boolean", default: false, summary: "Also write the single-file monolith." },
@@ -2136,8 +2139,8 @@ function buildAgentContract() {
2136
2139
  "<outDir>/.codebase-snapshot (ownership marker, always written)"
2137
2140
  ],
2138
2141
  notes: [
2139
- "Parts are ordered and budget-limited; a single file larger than the budget becomes a head/tail preview.",
2140
- "manifest.json.files[] carries relativePath, layer, kind, language, part, inclusionMode and hash; `summary` is conditional \u2014 it is absent for languages with no structural summary, and `summaryOmitted: true` marks a summary dropped to fit the part budget; encoding appears when the file was not plain UTF-8.",
2142
+ "Parts are ordered and budget-limited; a file that cannot fit one part is emitted as a head/tail preview, and every file not present in full is listed in manifest.json incomplete[] with the missing line ranges.",
2143
+ "manifest.json.files[] carries relativePath, layer, kind, language, part, inclusionMode, truncationReason, omittedRanges and hash; manifest.json.incomplete[] lists every file not present in full; `summary` is conditional \u2014 it is absent for languages with no structural summary, and `summaryOmitted: true` marks a summary dropped to fit the part budget; encoding appears when the file was not plain UTF-8.",
2141
2144
  "manifest.skipped[] carries the path and the exact reason it was excluded.",
2142
2145
  `The output directory is replaced atomically; ${MIN_MAX_PART_BYTES} bytes is the smallest legal budget.`
2143
2146
  ]
@@ -2299,10 +2302,12 @@ do not assume the repository is broken.
2299
2302
  \`kind\`, \`language\`, \`part\`, \`inclusionMode\`, \`hashSha256\` and the structural
2300
2303
  \`summary\`, plus \`encoding\` when the file was not plain UTF-8. \`summary\` is
2301
2304
  **optional**: it is absent for languages with no structural summary, and
2302
- \`summaryOmitted: true\` marks one dropped to fit the part budget \u2014 never assume it
2305
+ \`summaryOmitted: true\` marks one dropped for size, and the reason in \`summaryOmittedReason\` says which rule \u2014 never assume it
2303
2306
  exists. The per-file \`hashSha256\` is only here and in the manifest; it is not printed
2304
2307
  into the parts.
2305
- \`skipped[]\` records every excluded file **and why**. Prefer querying this over
2308
+ \`skipped[]\` records every excluded file **and why**. The top-level \`incomplete[]\` records every included
2309
+ file whose body is not the whole file, with its reason and omittedRanges: ask that list,
2310
+ not the footer of a part, when the question is whether anything was lost. Prefer querying this over
2306
2311
  re-reading the parts.
2307
2312
  - \`snapshot/reports/audit.md\` \u2014 secrets found, large files, parse diagnostics, git
2308
2313
  state. Read this before you quote code back to a user.
@@ -2238,7 +2238,7 @@ var JS_PRESETS = [
2238
2238
  ...commonKinds()
2239
2239
  ],
2240
2240
  exclude: [".nuxt", ".output"],
2241
- recommendedBudget: "200k"
2241
+ recommendedBudget: "300k"
2242
2242
  },
2243
2243
  {
2244
2244
  name: "sveltekit",
@@ -2259,7 +2259,7 @@ var JS_PRESETS = [
2259
2259
  ...commonKinds()
2260
2260
  ],
2261
2261
  exclude: [".svelte-kit", ".vercel"],
2262
- recommendedBudget: "200k"
2262
+ recommendedBudget: "300k"
2263
2263
  },
2264
2264
  {
2265
2265
  name: "remix",
@@ -2273,7 +2273,7 @@ var JS_PRESETS = [
2273
2273
  ],
2274
2274
  kinds: [kindOf("route", "routes/"), ...commonKinds()],
2275
2275
  exclude: [".cache", "public/build"],
2276
- recommendedBudget: "200k"
2276
+ recommendedBudget: "300k"
2277
2277
  },
2278
2278
  {
2279
2279
  name: "astro",
@@ -2288,7 +2288,7 @@ var JS_PRESETS = [
2288
2288
  ],
2289
2289
  kinds: [suffixKind("page", ".astro"), kindOf("layout", "layouts/"), ...commonKinds()],
2290
2290
  exclude: [".astro", "dist"],
2291
- recommendedBudget: "150k"
2291
+ recommendedBudget: "300k"
2292
2292
  },
2293
2293
  {
2294
2294
  name: "angular",
@@ -2312,7 +2312,7 @@ var JS_PRESETS = [
2312
2312
  ...commonKinds()
2313
2313
  ],
2314
2314
  exclude: [".angular", "dist"],
2315
- recommendedBudget: "200k"
2315
+ recommendedBudget: "300k"
2316
2316
  },
2317
2317
  {
2318
2318
  name: "solid",
@@ -2325,7 +2325,7 @@ var JS_PRESETS = [
2325
2325
  ],
2326
2326
  kinds: [kindOf("route", "routes/"), ...commonKinds()],
2327
2327
  exclude: [".solid", "dist"],
2328
- recommendedBudget: "120k"
2328
+ recommendedBudget: "300k"
2329
2329
  },
2330
2330
  {
2331
2331
  name: "vue-vite",
@@ -2358,7 +2358,7 @@ var JS_PRESETS = [
2358
2358
  ...commonKinds()
2359
2359
  ],
2360
2360
  exclude: [".vite", "dist"],
2361
- recommendedBudget: "120k"
2361
+ recommendedBudget: "300k"
2362
2362
  },
2363
2363
  {
2364
2364
  name: "react-vite",
@@ -2372,7 +2372,7 @@ var JS_PRESETS = [
2372
2372
  layers: VITE_LAYERS,
2373
2373
  kinds: VITE_KINDS,
2374
2374
  exclude: [".vite", "dist"],
2375
- recommendedBudget: "120k"
2375
+ recommendedBudget: "300k"
2376
2376
  },
2377
2377
  {
2378
2378
  name: "nest",
@@ -2398,7 +2398,7 @@ var JS_PRESETS = [
2398
2398
  ...commonKinds()
2399
2399
  ],
2400
2400
  exclude: ["dist", "node_modules"],
2401
- recommendedBudget: "200k"
2401
+ recommendedBudget: "300k"
2402
2402
  },
2403
2403
  {
2404
2404
  name: "node-express",
@@ -2407,7 +2407,7 @@ var JS_PRESETS = [
2407
2407
  layers: NODE_LAYERS,
2408
2408
  kinds: NODE_KINDS,
2409
2409
  exclude: ["dist"],
2410
- recommendedBudget: "200k"
2410
+ recommendedBudget: "300k"
2411
2411
  },
2412
2412
  {
2413
2413
  name: "node-lib",
@@ -2423,7 +2423,7 @@ var JS_PRESETS = [
2423
2423
  ],
2424
2424
  kinds: [suffixKind("type", ".d.ts"), ...commonKinds()],
2425
2425
  exclude: ["dist"],
2426
- recommendedBudget: "120k"
2426
+ recommendedBudget: "300k"
2427
2427
  }
2428
2428
  ];
2429
2429
 
@@ -2454,7 +2454,7 @@ var LANGUAGE_PRESETS = [
2454
2454
  ...commonKinds()
2455
2455
  ],
2456
2456
  exclude: ["__pycache__", ".venv", "venv", ".mypy_cache", ".pytest_cache", ".tox", ".eggs", "staticfiles", "media"],
2457
- recommendedBudget: "150k"
2457
+ recommendedBudget: "300k"
2458
2458
  },
2459
2459
  {
2460
2460
  name: "python-fastapi",
@@ -2477,7 +2477,7 @@ var LANGUAGE_PRESETS = [
2477
2477
  ...commonKinds()
2478
2478
  ],
2479
2479
  exclude: ["__pycache__", ".venv", "venv", ".mypy_cache", ".pytest_cache", ".tox", ".eggs"],
2480
- recommendedBudget: "150k"
2480
+ recommendedBudget: "300k"
2481
2481
  },
2482
2482
  {
2483
2483
  name: "python-lib",
@@ -2491,7 +2491,7 @@ var LANGUAGE_PRESETS = [
2491
2491
  ],
2492
2492
  kinds: [suffixKind("module", ".py"), ...commonKinds()],
2493
2493
  exclude: ["__pycache__", ".venv", "venv", ".mypy_cache", ".pytest_cache", ".tox", ".eggs"],
2494
- recommendedBudget: "120k"
2494
+ recommendedBudget: "300k"
2495
2495
  },
2496
2496
  {
2497
2497
  name: "go",
@@ -2515,7 +2515,7 @@ var LANGUAGE_PRESETS = [
2515
2515
  ...commonKinds()
2516
2516
  ],
2517
2517
  exclude: ["vendor", "testdata"],
2518
- recommendedBudget: "200k"
2518
+ recommendedBudget: "300k"
2519
2519
  },
2520
2520
  {
2521
2521
  name: "rust",
@@ -2531,7 +2531,7 @@ var LANGUAGE_PRESETS = [
2531
2531
  ],
2532
2532
  kinds: [suffixKind("module", ".rs"), suffixKind("test", "_test.rs"), ...commonKinds()],
2533
2533
  exclude: ["target"],
2534
- recommendedBudget: "200k"
2534
+ recommendedBudget: "300k"
2535
2535
  },
2536
2536
  {
2537
2537
  name: "java-spring",
@@ -2554,7 +2554,7 @@ var LANGUAGE_PRESETS = [
2554
2554
  ...commonKinds()
2555
2555
  ],
2556
2556
  exclude: [".gradle", "out", "target"],
2557
- recommendedBudget: "200k"
2557
+ recommendedBudget: "300k"
2558
2558
  },
2559
2559
  {
2560
2560
  name: "dotnet",
@@ -2577,7 +2577,7 @@ var LANGUAGE_PRESETS = [
2577
2577
  ...commonKinds()
2578
2578
  ],
2579
2579
  exclude: ["bin", "obj", ".vs"],
2580
- recommendedBudget: "200k"
2580
+ recommendedBudget: "300k"
2581
2581
  },
2582
2582
  {
2583
2583
  name: "php-laravel",
@@ -2603,7 +2603,7 @@ var LANGUAGE_PRESETS = [
2603
2603
  ...commonKinds()
2604
2604
  ],
2605
2605
  exclude: ["vendor", "storage", "bootstrap/cache", "public/build"],
2606
- recommendedBudget: "150k"
2606
+ recommendedBudget: "300k"
2607
2607
  },
2608
2608
  {
2609
2609
  name: "ruby-rails",
@@ -2628,7 +2628,7 @@ var LANGUAGE_PRESETS = [
2628
2628
  ...commonKinds()
2629
2629
  ],
2630
2630
  exclude: [".bundle", "log", "tmp", "vendor/bundle", "public/assets"],
2631
- recommendedBudget: "150k"
2631
+ recommendedBudget: "300k"
2632
2632
  }
2633
2633
  ];
2634
2634
 
@@ -2690,7 +2690,7 @@ var SHAPE_PRESETS = [
2690
2690
  ],
2691
2691
  kinds: commonKinds(),
2692
2692
  exclude: [".turbo", ".nx"],
2693
- recommendedBudget: "200k"
2693
+ recommendedBudget: "300k"
2694
2694
  },
2695
2695
  {
2696
2696
  name: "infra",
@@ -2708,7 +2708,7 @@ var SHAPE_PRESETS = [
2708
2708
  ...commonKinds()
2709
2709
  ],
2710
2710
  exclude: [".terraform", ".terragrunt-cache"],
2711
- recommendedBudget: "100k"
2711
+ recommendedBudget: "300k"
2712
2712
  },
2713
2713
  {
2714
2714
  name: "docs",
@@ -2725,7 +2725,7 @@ var SHAPE_PRESETS = [
2725
2725
  ],
2726
2726
  kinds: commonKinds(),
2727
2727
  exclude: [".docusaurus", ".vitepress/dist", "site"],
2728
- recommendedBudget: "100k"
2728
+ recommendedBudget: "300k"
2729
2729
  },
2730
2730
  {
2731
2731
  name: "generic",
@@ -2737,7 +2737,7 @@ var SHAPE_PRESETS = [
2737
2737
  layers: DEFAULT_LAYERS,
2738
2738
  kinds: DEFAULT_KINDS,
2739
2739
  exclude: [],
2740
- recommendedBudget: "120k"
2740
+ recommendedBudget: "300k"
2741
2741
  }
2742
2742
  ];
2743
2743
 
@@ -3863,7 +3863,7 @@ function applySpans(line, spans) {
3863
3863
 
3864
3864
  // src/version.ts
3865
3865
  var GENERATOR_NAME = "codebase-snapshot";
3866
- var GENERATOR_VERSION = "0.9.18";
3866
+ var GENERATOR_VERSION = "0.10.0";
3867
3867
  var SCHEMA_VERSION = "3.0.0";
3868
3868
  var LEGACY_GENERATOR_NAMES = ["@ankurhalder/codebase-snapshot"];
3869
3869
  function isOurGeneratorName(name) {
@@ -5196,6 +5196,16 @@ async function loadConfigFile(cwd) {
5196
5196
  }
5197
5197
  return loaded.config;
5198
5198
  }
5199
+ function largeFileBytesFor(maxPartBytes, cliOptions, userConfig) {
5200
+ const requested = cliOptions?.largeFileBytes ?? userConfig?.largeFileBytes;
5201
+ const value = boundedBytes(requested, maxPartBytes, 1, "largeFileBytes");
5202
+ if (value > maxPartBytes) {
5203
+ throw new Error(
5204
+ `largeFileBytes (${describeBytes(value)}) is larger than maxPartBytes (${describeBytes(maxPartBytes)}). A file between the two cannot fit a part, so it would be cut to fit while the manifest called it complete. Raise maxPartBytes to at least largeFileBytes, or lower largeFileBytes.`
5205
+ );
5206
+ }
5207
+ return value;
5208
+ }
5199
5209
  var MIN_MAX_PART_BYTES = 4096;
5200
5210
  var MIN_MAX_PART_TOKENS = MIN_MAX_PART_BYTES / 4;
5201
5211
  var ARTIFACT_NAMES = [
@@ -5638,7 +5648,7 @@ function resolveConfig(userConfig, cliOptions, baseDir) {
5638
5648
  tmpDir,
5639
5649
  maxPartBytes: resolvedMaxPartBytes,
5640
5650
  ...maxPartTokens === void 0 ? {} : { maxPartTokens },
5641
- largeFileBytes: boundedBytes(cliOptions?.largeFileBytes ?? userConfig?.largeFileBytes, 200 * 1024, 1, "largeFileBytes"),
5651
+ largeFileBytes: largeFileBytesFor(resolvedMaxPartBytes, cliOptions, userConfig),
5642
5652
  previewHeadLines: strictPositiveInteger(userConfig?.previewHeadLines, 80, "`previewHeadLines`"),
5643
5653
  previewTailLines: strictPositiveInteger(userConfig?.previewTailLines, 40, "`previewTailLines`"),
5644
5654
  includeMonolith: artifacts.monolith,
@@ -5901,7 +5911,7 @@ function generateAuditReport(manifest, secretFindings, secretRules) {
5901
5911
  );
5902
5912
  for (const file of affected) {
5903
5913
  const status = file.isPreviewTruncated ? "Truncated" : "Full";
5904
- const cutBy = file.isLarge ? "largeFileBytes" : "maxPartBytes";
5914
+ const cutBy = file.truncationReason === "part-budget" ? "maxPartBytes" : "largeFileBytes";
5905
5915
  lines.push(
5906
5916
  `| ${code(file.relativePath)} | ${file.sizeBytes} | ${file.lines} | ${file.includedBytes} | ${file.includedLines} | ${status} | ${cutBy} |`
5907
5917
  );
@@ -6080,7 +6090,8 @@ function truncatePreview(content, headLines, tailLines) {
6080
6090
  content: normalised,
6081
6091
  isTruncated: false,
6082
6092
  originalLines: total,
6083
- includedLines: total
6093
+ includedLines: total,
6094
+ omittedRanges: []
6084
6095
  };
6085
6096
  }
6086
6097
  const window = normalised.endsWith("\n") ? lines.slice(0, -1) : lines;
@@ -6092,13 +6103,16 @@ function truncatePreview(content, headLines, tailLines) {
6092
6103
  `... [${omitted} lines omitted: file exceeds large file size budget] ...`,
6093
6104
  ...tail
6094
6105
  ].join("\n");
6106
+ const firstOmitted = head.length + 1;
6107
+ const lastOmitted = total - tail.length;
6095
6108
  return {
6096
6109
  content: result,
6097
6110
  isTruncated: true,
6098
6111
  originalLines: total,
6099
6112
  // Head + notice + tail is exactly what is emitted; counting the slice is
6100
6113
  // wrong when the source ended with a newline (the trailing "" issue above).
6101
- includedLines: head.length + tail.length + 1
6114
+ includedLines: head.length + tail.length + 1,
6115
+ omittedRanges: lastOmitted >= firstOmitted ? [[firstOmitted, lastOmitted]] : []
6102
6116
  };
6103
6117
  }
6104
6118
 
@@ -6198,7 +6212,7 @@ function partitionFilesForBuckets(buckets, contentFingerprint) {
6198
6212
  section.file.originalLines
6199
6213
  );
6200
6214
  if (shrunk.isTruncated) {
6201
- applyTruncatedContent(section.file, shrunk.content);
6215
+ applyTruncatedContent(section.file, shrunk.content, "part-budget");
6202
6216
  section.text = renderFileSection(section.file);
6203
6217
  section.byteSize = Buffer.byteLength(section.text, "utf8");
6204
6218
  assemblies.delete(group);
@@ -6334,7 +6348,7 @@ function prepareSection(file, sectionBudget, partBudget) {
6334
6348
  file.originalLines
6335
6349
  );
6336
6350
  if (!truncated.isTruncated) return;
6337
- applyTruncatedContent(file, truncated.content);
6351
+ applyTruncatedContent(file, truncated.content, "part-budget");
6338
6352
  text2 = renderFileSection(file);
6339
6353
  byteSize = Buffer.byteLength(text2, "utf8");
6340
6354
  };
@@ -6342,14 +6356,16 @@ function prepareSection(file, sectionBudget, partBudget) {
6342
6356
  if (byteSize > sectionBudget && file.summary) {
6343
6357
  file.summary = void 0;
6344
6358
  file.summaryOmitted = true;
6359
+ file.summaryOmittedReason = "part-budget";
6345
6360
  text2 = renderFileSection(file);
6346
6361
  byteSize = Buffer.byteLength(text2, "utf8");
6347
6362
  shrinkBody();
6348
6363
  }
6349
6364
  if (byteSize > sectionBudget) {
6350
- applyTruncatedContent(file, SECTION_TRUNCATION_NOTICE);
6365
+ applyTruncatedContent(file, SECTION_TRUNCATION_NOTICE, "section-metadata");
6351
6366
  file.summary = void 0;
6352
6367
  file.summaryOmitted = true;
6368
+ file.summaryOmittedReason = "part-budget";
6353
6369
  text2 = renderFileSection(file);
6354
6370
  byteSize = Buffer.byteLength(text2, "utf8");
6355
6371
  if (byteSize > sectionBudget) {
@@ -6398,10 +6414,14 @@ function fenceIsOpen(text2, fence) {
6398
6414
  }
6399
6415
  return open;
6400
6416
  }
6401
- function applyTruncatedContent(file, content) {
6417
+ var OMISSION_NOTICE_LINE = /^\.\.\. \[\d+ lines omitted: [^\]]*\] \.\.\.$/;
6418
+ function applyTruncatedContent(file, content, reason) {
6419
+ const keptLines = content.split("\n").filter((line) => !OMISSION_NOTICE_LINE.test(line)).length;
6402
6420
  file.content = content;
6403
6421
  file.isPreviewTruncated = true;
6404
6422
  file.inclusionMode = "preview";
6423
+ file.truncationReason = reason;
6424
+ file.omittedRanges = keptLines >= file.originalLines ? file.originalLines > 0 ? [[file.originalLines, file.originalLines]] : [] : [[keptLines + 1, file.originalLines]];
6405
6425
  file.includedBytes = Buffer.byteLength(content, "utf8");
6406
6426
  file.includedLines = countLines(content);
6407
6427
  }
@@ -6548,7 +6568,9 @@ function renderFileSection(file) {
6548
6568
  compactMetadata(file),
6549
6569
  ...file.summaryQuality ? [`- Summary Quality: ${file.summaryQuality}`] : [],
6550
6570
  ...renderSummary(file.summary, file.inclusionMode),
6551
- ...file.summaryOmitted ? ["- Summary: (omitted: exceeds the part budget)"] : [],
6571
+ ...file.summaryOmitted ? [
6572
+ file.summaryOmittedReason === "preview" ? "- Summary: (omitted: the file is a head/tail preview)" : file.summaryOmittedReason === "oversize" ? "- Summary: (omitted: the file is too large to parse)" : "- Summary: (omitted: exceeds the part budget)"
6573
+ ] : [],
6552
6574
  "",
6553
6575
  file.inclusionMode === "preview" ? "#### Bounded Preview" : "#### Content",
6554
6576
  "",
@@ -8876,7 +8898,9 @@ function renderConfig(answers) {
8876
8898
  // The same ceiling expressed in tokens; it narrows maxPartBytes rather than
8877
8899
  // replacing it. null = not set. Minimum 1024.
8878
8900
  maxPartTokens: ${answers.maxPartTokens === null ? "null" : String(answers.maxPartTokens)},
8879
- // Files above this size get a head/tail preview instead of the full body.
8901
+ // Files above this size get a head/tail preview instead of the full body. It may not
8902
+ // exceed maxPartBytes: a file between the two could not fit a part, and cutting it to fit
8903
+ // while the manifest called it a preview is exactly what this ceiling pair must prevent.
8880
8904
  largeFileBytes: ${size(answers.largeFileBytes)},
8881
8905
  previewHeadLines: 80,
8882
8906
  previewTailLines: 40,
@@ -9561,6 +9585,9 @@ async function runInit(options) {
9561
9585
  let reason = detected.reason;
9562
9586
  let fallback = detected.fallback;
9563
9587
  const notes = [];
9588
+ const budgetBytes = parseByteSize(options.maxPartBytes ?? detected.recommendedBudget ?? DEFAULT_ANSWERS.maxPartBytes) ?? 307200;
9589
+ const tokenBudgetBytes = options.maxPartTokens === void 0 || options.maxPartTokens === null ? void 0 : options.maxPartTokens * 4;
9590
+ const effectiveBudgetBytes = tokenBudgetBytes === void 0 ? budgetBytes : Math.min(budgetBytes, tokenBudgetBytes);
9564
9591
  const answers = {
9565
9592
  preset: detected.presetName,
9566
9593
  // The repository's own branch, read the same way the generator reads it.
@@ -9574,7 +9601,13 @@ async function runInit(options) {
9574
9601
  // what the run used is drift the next `validate` reports, and `setup` is the one command
9575
9602
  // that is supposed to leave a project in a consistent state.
9576
9603
  maxPartTokens: options.maxPartTokens ?? DEFAULT_ANSWERS.maxPartTokens,
9577
- largeFileBytes: options.largeFileBytes ?? DEFAULT_ANSWERS.largeFileBytes,
9604
+ largeFileBytes: options.largeFileBytes ?? // A threshold above the part budget is a configuration error (a file between the two
9605
+ // cannot fit, so it is cut while the manifest calls it a preview). Writing the old fixed
9606
+ // 200 KB beside `--max-part-tokens 32k` made the setup's own output fail its own validate.
9607
+ Math.min(
9608
+ parseByteSize(DEFAULT_ANSWERS.largeFileBytes) ?? effectiveBudgetBytes,
9609
+ effectiveBudgetBytes
9610
+ ),
9578
9611
  maxMonolithBytes: options.maxMonolithBytes ?? DEFAULT_ANSWERS.maxMonolithBytes,
9579
9612
  discovery: options.discovery ?? DEFAULT_ANSWERS.discovery,
9580
9613
  skeleton: options.skeleton ?? DEFAULT_ANSWERS.skeleton,
@@ -10178,6 +10211,8 @@ function deriveFile(relativePath, rawContent, sizeBytes, config) {
10178
10211
  const oversizeForSummary = Buffer.byteLength(rawContent, "utf8") > SUMMARY_MAX_SOURCE_BYTES2;
10179
10212
  let finalContent = redacted;
10180
10213
  let isPreviewTruncated = false;
10214
+ let truncationReason;
10215
+ let omittedRanges = [];
10181
10216
  let includedLines = lineCount;
10182
10217
  let inclusionMode = "full";
10183
10218
  if (config.skeleton === true && isSkeletonizable(relativePath) && !oversizeForSummary) {
@@ -10194,6 +10229,10 @@ function deriveFile(relativePath, rawContent, sizeBytes, config) {
10194
10229
  isPreviewTruncated = preview.isTruncated;
10195
10230
  includedLines = preview.includedLines;
10196
10231
  inclusionMode = isPreviewTruncated ? "preview" : "full";
10232
+ if (isPreviewTruncated) {
10233
+ truncationReason = "large-file-budget";
10234
+ omittedRanges = preview.omittedRanges;
10235
+ }
10197
10236
  }
10198
10237
  let summary;
10199
10238
  let summaryQuality;
@@ -10228,6 +10267,8 @@ function deriveFile(relativePath, rawContent, sizeBytes, config) {
10228
10267
  finalContent,
10229
10268
  inclusionMode,
10230
10269
  isPreviewTruncated,
10270
+ truncationReason,
10271
+ omittedRanges,
10231
10272
  includedLines,
10232
10273
  isLarge,
10233
10274
  summary,
@@ -10337,8 +10378,30 @@ function buildIndexes(files, tsconfigPaths) {
10337
10378
  }))
10338
10379
  };
10339
10380
  }
10340
- function verifyInMemory(files, parts) {
10381
+ function verifyInMemory(files, parts, unaccounted) {
10341
10382
  const errors = [];
10383
+ if (unaccounted.length > 0) {
10384
+ const shown = unaccounted.slice(0, 5).join(", ");
10385
+ errors.push(
10386
+ `${unaccounted.length} scanned file(s) appear in neither files[] nor skipped[]${unaccounted.length > 5 ? ` (first five: ${shown})` : `: ${shown}`}.`
10387
+ );
10388
+ }
10389
+ for (const file of files) {
10390
+ if (file.isPreviewTruncated && file.truncationReason === void 0) {
10391
+ errors.push(`${file.relativePath} is truncated but records no truncationReason.`);
10392
+ }
10393
+ const ranges = file.omittedRanges ?? [];
10394
+ if (file.truncationReason !== void 0 && ranges.length === 0) {
10395
+ errors.push(`${file.relativePath} is truncated but records no omittedRanges.`);
10396
+ }
10397
+ for (const [from, to] of ranges) {
10398
+ if (from < 1 || to < from || to > file.lines) {
10399
+ errors.push(
10400
+ `${file.relativePath} records omitted range ${from}-${to}, outside 1-${file.lines}.`
10401
+ );
10402
+ }
10403
+ }
10404
+ }
10342
10405
  const partNames = new Set(parts.map((part) => part.filename));
10343
10406
  for (const file of files) {
10344
10407
  if (!file.part || !partNames.has(file.part)) {
@@ -11089,7 +11152,20 @@ function swapOnce(stagingDir, outDir, beforeSwap) {
11089
11152
  const backupDir = `${outDir}.backup-${process.pid}-${Date.now()}`;
11090
11153
  const hadPrevious = fs15.existsSync(outDir);
11091
11154
  if (hadPrevious) beforeSwap?.();
11092
- if (hadPrevious) fs15.renameSync(outDir, backupDir);
11155
+ let movedAside = false;
11156
+ if (hadPrevious) {
11157
+ try {
11158
+ fs15.renameSync(outDir, backupDir);
11159
+ movedAside = true;
11160
+ } catch (err) {
11161
+ if (!isLockError(err)) throw err;
11162
+ fs15.rmSync(outDir, { recursive: true, force: true, maxRetries: 5, retryDelay: 100 });
11163
+ process.stderr.write(
11164
+ `\u26A0 ${outDir} could not be moved aside (${err.message}), so it was replaced in place. Close anything holding the old snapshot open to avoid this next time.
11165
+ `
11166
+ );
11167
+ }
11168
+ }
11093
11169
  try {
11094
11170
  try {
11095
11171
  fs15.renameSync(stagingDir, outDir);
@@ -11109,9 +11185,14 @@ function swapOnce(stagingDir, outDir, beforeSwap) {
11109
11185
  }
11110
11186
  }
11111
11187
  } catch (err) {
11112
- if (hadPrevious && fs15.existsSync(backupDir)) {
11188
+ if (hadPrevious && movedAside && fs15.existsSync(backupDir)) {
11113
11189
  if (fs15.existsSync(outDir)) fs15.rmSync(outDir, { recursive: true, force: true });
11114
11190
  fs15.renameSync(backupDir, outDir);
11191
+ } else if (hadPrevious && !movedAside) {
11192
+ process.stderr.write(
11193
+ `\u26A0 The previous snapshot at ${outDir} was removed and the new one could not be moved into place. It is complete at ${stagingDir}.
11194
+ `
11195
+ );
11115
11196
  }
11116
11197
  throw err;
11117
11198
  }
@@ -11126,6 +11207,10 @@ function swapOnce(stagingDir, outDir, beforeSwap) {
11126
11207
  }
11127
11208
  }
11128
11209
  }
11210
+ function isLockError(err) {
11211
+ const code = err.code;
11212
+ return code === "EPERM" || code === "EBUSY" || code === "EACCES";
11213
+ }
11129
11214
  function sleepSync(milliseconds) {
11130
11215
  const buffer = new Int32Array(new SharedArrayBuffer(4));
11131
11216
  Atomics.wait(buffer, 0, 0, milliseconds);
@@ -11229,10 +11314,6 @@ function generateSnapshot(configInput, options) {
11229
11314
  const skipped = maskSkipRecords([...collection.skipped], config.secretRules);
11230
11315
  const secretFindings = [];
11231
11316
  const warnings = [];
11232
- const budgetOrderCutsFiles = () => {
11233
- if (config.maxPartBytes >= config.largeFileBytes) return false;
11234
- return files.some((file) => file.isPreviewTruncated && !file.isLarge);
11235
- };
11236
11317
  const encodingNotes = [];
11237
11318
  const fileWarnings = [];
11238
11319
  const oversizeSummaryPaths = [];
@@ -11394,11 +11475,16 @@ function generateSnapshot(configInput, options) {
11394
11475
  inclusionMode: derivation.inclusionMode,
11395
11476
  isLarge: derivation.isLarge,
11396
11477
  isPreviewTruncated: derivation.isPreviewTruncated,
11478
+ ...derivation.truncationReason === void 0 ? {} : { truncationReason: derivation.truncationReason },
11479
+ ...derivation.omittedRanges.length === 0 ? {} : { omittedRanges: derivation.omittedRanges },
11397
11480
  originalLines: lineCount,
11398
11481
  includedLines: derivation.includedLines,
11399
11482
  includedBytes: Buffer.byteLength(derivation.finalContent, "utf8"),
11400
11483
  summary: derivation.summary,
11401
11484
  summaryQuality: derivation.summaryQuality,
11485
+ // A summary skipped for size is not an absent summary: record it the same way the
11486
+ // partitioner records one it had to drop, so a reader can tell the two apart.
11487
+ ...derivation.summarySkip === null ? {} : { summaryOmitted: true, summaryOmittedReason: derivation.summarySkip },
11402
11488
  ...decoded.encoding === "utf-8" ? {} : { encoding: decoded.encoding },
11403
11489
  content: derivation.finalContent
11404
11490
  });
@@ -11518,7 +11604,28 @@ function generateSnapshot(configInput, options) {
11518
11604
  }
11519
11605
  const parts = partitionByBudget(files, config, fingerprint);
11520
11606
  const truncatedPreviewCount = files.filter((file) => file.isPreviewTruncated).length;
11521
- const validationErrors = verifyInMemory(files, parts);
11607
+ const incomplete = files.flatMap((file) => {
11608
+ if (file.truncationReason === void 0) return [];
11609
+ const ranges = file.omittedRanges ?? [];
11610
+ const omittedLines = ranges.reduce((total, [from, to]) => total + (to - from + 1), 0);
11611
+ return [
11612
+ {
11613
+ relativePath: file.relativePath,
11614
+ part: file.part,
11615
+ reason: file.truncationReason,
11616
+ omittedRanges: ranges,
11617
+ omittedLines,
11618
+ includedLines: file.includedLines,
11619
+ lines: file.lines
11620
+ }
11621
+ ];
11622
+ });
11623
+ const accounted = /* @__PURE__ */ new Set([
11624
+ ...files.map((file) => maskPathText(file.relativePath, config.secretRules)),
11625
+ ...skipped.map((record) => record.path)
11626
+ ]);
11627
+ const unaccounted = candidateFiles.map((candidate) => maskPathText(candidate, config.secretRules)).filter((candidate) => !accounted.has(candidate));
11628
+ const validationErrors = verifyInMemory(files, parts, unaccounted);
11522
11629
  const totalContentBytes = files.reduce((total, file) => total + file.includedBytes, 0);
11523
11630
  const maskName = (value) => maskPathText(value, config.secretRules);
11524
11631
  const manifest = {
@@ -11579,7 +11686,8 @@ function generateSnapshot(configInput, options) {
11579
11686
  partsCount: parts.length,
11580
11687
  skippedCount: skipped.length,
11581
11688
  largeFileCount,
11582
- truncatedPreviewCount
11689
+ truncatedPreviewCount,
11690
+ incompleteCount: incomplete.length
11583
11691
  },
11584
11692
  totals: {
11585
11693
  candidateFiles: files.length + skipped.length,
@@ -11616,19 +11724,14 @@ function generateSnapshot(configInput, options) {
11616
11724
  return rest;
11617
11725
  }),
11618
11726
  skipped: maskSkipRecords(skipped, config.secretRules),
11727
+ incomplete,
11619
11728
  warnings
11620
11729
  };
11621
11730
  manifest.totals.redactedLines = secretFindings.length;
11622
11731
  manifest.totals.warningCount = manifest.warnings.length;
11623
- if (budgetOrderCutsFiles()) {
11624
- manifest.warnings.push(
11625
- `maxPartBytes (${config.maxPartBytes} B) is below largeFileBytes (${config.largeFileBytes} B), so files cut by the part budget are not marked as large previews. Increase maxPartBytes or lower largeFileBytes.`
11626
- );
11627
- manifest.totals.warningCount = manifest.warnings.length;
11628
- }
11629
- if (files.some((file) => file.isPreviewTruncated) && config.largeFileBytes <= config.maxPartBytes) {
11732
+ if (files.some((file) => file.isPreviewTruncated) && config.largeFileBytes < config.maxPartBytes) {
11630
11733
  manifest.warnings.push(
11631
- `${files.filter((file) => file.isPreviewTruncated).length} file(s) were previewed because largeFileBytes (${config.largeFileBytes} B) is not above maxPartBytes (${config.maxPartBytes} B). Raise largeFileBytes if a whole file is wanted.`
11734
+ `${files.filter((file) => file.isPreviewTruncated).length} file(s) were previewed because largeFileBytes (${config.largeFileBytes} B) is below maxPartBytes (${config.maxPartBytes} B). Raise largeFileBytes if a whole file is wanted.`
11632
11735
  );
11633
11736
  manifest.totals.warningCount = manifest.warnings.length;
11634
11737
  }