codebase-snapshot 0.10.2 → 0.12.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/cli.cjs CHANGED
@@ -1,8 +1,8 @@
1
1
  'use strict';
2
2
 
3
3
  var childProcess = require('child_process');
4
- var fs15 = require('fs');
5
- var path16 = require('path');
4
+ var fs16 = require('fs');
5
+ var path17 = require('path');
6
6
  var util = require('util');
7
7
  var crypto3 = require('crypto');
8
8
  var module$1 = require('module');
@@ -37,8 +37,8 @@ function _interopNamespace(e) {
37
37
  }
38
38
 
39
39
  var childProcess__namespace = /*#__PURE__*/_interopNamespace(childProcess);
40
- var fs15__namespace = /*#__PURE__*/_interopNamespace(fs15);
41
- var path16__namespace = /*#__PURE__*/_interopNamespace(path16);
40
+ var fs16__namespace = /*#__PURE__*/_interopNamespace(fs16);
41
+ var path17__namespace = /*#__PURE__*/_interopNamespace(path17);
42
42
  var crypto3__namespace = /*#__PURE__*/_interopNamespace(crypto3);
43
43
  var ts2__default = /*#__PURE__*/_interopDefault(ts2);
44
44
  var readline__namespace = /*#__PURE__*/_interopNamespace(readline);
@@ -93,15 +93,15 @@ var SKIPPED_WALK_DIRS = /* @__PURE__ */ new Set([
93
93
  ]);
94
94
  function readSmallFile(fullPath) {
95
95
  try {
96
- const stats = fs15__namespace.statSync(fullPath);
96
+ const stats = fs16__namespace.statSync(fullPath);
97
97
  if (!stats.isFile() || stats.size > MANIFEST_MAX_BYTES) return null;
98
- return fs15__namespace.readFileSync(fullPath, "utf8");
98
+ return fs16__namespace.readFileSync(fullPath, "utf8");
99
99
  } catch {
100
100
  return null;
101
101
  }
102
102
  }
103
103
  function readManifest(cwd, name) {
104
- return readSmallFile(path16__namespace.join(cwd, name));
104
+ return readSmallFile(path17__namespace.join(cwd, name));
105
105
  }
106
106
  function dependenciesFromPackageJson(raw) {
107
107
  const names = /* @__PURE__ */ new Set();
@@ -161,7 +161,7 @@ function pnpmWorkspacePatterns(raw) {
161
161
  function childDirectories(cwd, parent) {
162
162
  let entries;
163
163
  try {
164
- entries = fs15__namespace.readdirSync(path16__namespace.join(cwd, parent), { withFileTypes: true });
164
+ entries = fs16__namespace.readdirSync(path17__namespace.join(cwd, parent), { withFileTypes: true });
165
165
  } catch {
166
166
  return [];
167
167
  }
@@ -197,12 +197,12 @@ function scanWorkspacePackages(cwd, patterns) {
197
197
  const files = /* @__PURE__ */ new Set();
198
198
  const dependencies = /* @__PURE__ */ new Set();
199
199
  for (const relative15 of workspacePackageDirs(cwd, patterns)) {
200
- const full = path16__namespace.join(cwd, relative15);
200
+ const full = path17__namespace.join(cwd, relative15);
201
201
  try {
202
- for (const entry of fs15__namespace.readdirSync(full, { withFileTypes: true })) files.add(entry.name);
202
+ for (const entry of fs16__namespace.readdirSync(full, { withFileTypes: true })) files.add(entry.name);
203
203
  } catch {
204
204
  }
205
- const raw = readSmallFile(path16__namespace.join(full, "package.json"));
205
+ const raw = readSmallFile(path17__namespace.join(full, "package.json"));
206
206
  if (raw !== null) {
207
207
  for (const name of dependenciesFromPackageJson(raw)) dependencies.add(name);
208
208
  }
@@ -212,7 +212,7 @@ function scanWorkspacePackages(cwd, patterns) {
212
212
  var SNAPSHOT_MARKER = ".codebase-snapshot";
213
213
  function isToolOwnedDirectory(dir) {
214
214
  try {
215
- return fs15__namespace.statSync(dir).isDirectory() && fs15__namespace.existsSync(path16__namespace.join(dir, SNAPSHOT_MARKER));
215
+ return fs16__namespace.statSync(dir).isDirectory() && fs16__namespace.existsSync(path17__namespace.join(dir, SNAPSHOT_MARKER));
216
216
  } catch {
217
217
  return false;
218
218
  }
@@ -227,7 +227,7 @@ function countMarkdownFiles(cwd) {
227
227
  directoriesSeen += 1;
228
228
  let entries;
229
229
  try {
230
- entries = fs15__namespace.readdirSync(current.dir, { withFileTypes: true });
230
+ entries = fs16__namespace.readdirSync(current.dir, { withFileTypes: true });
231
231
  } catch {
232
232
  continue;
233
233
  }
@@ -238,7 +238,7 @@ function countMarkdownFiles(cwd) {
238
238
  }
239
239
  if (!entry.isDirectory() || current.depth >= 2) continue;
240
240
  if (entry.name.startsWith(".") || SKIPPED_WALK_DIRS.has(entry.name)) continue;
241
- const child = path16__namespace.join(current.dir, entry.name);
241
+ const child = path17__namespace.join(current.dir, entry.name);
242
242
  if (isToolOwnedDirectory(child)) continue;
243
243
  queue.push({ dir: child, depth: current.depth + 1 });
244
244
  }
@@ -249,7 +249,7 @@ function buildPresetContext(cwd) {
249
249
  const files = /* @__PURE__ */ new Set();
250
250
  const dirs = /* @__PURE__ */ new Set();
251
251
  try {
252
- for (const entry of fs15__namespace.readdirSync(cwd, { withFileTypes: true })) {
252
+ for (const entry of fs16__namespace.readdirSync(cwd, { withFileTypes: true })) {
253
253
  if (entry.isDirectory()) dirs.add(entry.name);
254
254
  else if (entry.isFile()) files.add(entry.name);
255
255
  }
@@ -266,7 +266,7 @@ function buildPresetContext(cwd) {
266
266
  const isWorkspace = files.has("pnpm-workspace.yaml") || files.has("nx.json") || files.has("turbo.json") || files.has("lerna.json") || packageJson !== void 0 && packageJson.includes('"workspaces"') || declaredWorkspaces.length > 0;
267
267
  let workspace = { files: /* @__PURE__ */ new Set(), dependencies: /* @__PURE__ */ new Set() };
268
268
  if (isWorkspace) {
269
- const pnpmRaw = files.has("pnpm-workspace.yaml") ? readSmallFile(path16__namespace.join(cwd, "pnpm-workspace.yaml")) : null;
269
+ const pnpmRaw = files.has("pnpm-workspace.yaml") ? readSmallFile(path17__namespace.join(cwd, "pnpm-workspace.yaml")) : null;
270
270
  const declared = pnpmRaw === null ? [] : pnpmWorkspacePatterns(pnpmRaw);
271
271
  const patterns = declared.length > 0 ? declared : declaredWorkspaces.length > 0 ? declaredWorkspaces : DEFAULT_WORKSPACE_PATTERNS;
272
272
  workspace = scanWorkspacePackages(cwd, patterns);
@@ -2220,7 +2220,7 @@ function applySpansKeepingQuotes(line, spans) {
2220
2220
 
2221
2221
  // src/version.ts
2222
2222
  var GENERATOR_NAME = "codebase-snapshot";
2223
- var GENERATOR_VERSION = "0.10.2";
2223
+ var GENERATOR_VERSION = "0.12.0";
2224
2224
  var SCHEMA_VERSION = "3.0.0";
2225
2225
  var LEGACY_GENERATOR_NAMES = ["@ankurhalder/codebase-snapshot"];
2226
2226
  function isOurGeneratorName(name) {
@@ -2237,14 +2237,14 @@ var PRESET_IGNORES = new Set(
2237
2237
  );
2238
2238
  function readLinkTarget(linkPath, fallback) {
2239
2239
  try {
2240
- return fs15__namespace.readlinkSync(linkPath);
2240
+ return fs16__namespace.readlinkSync(linkPath);
2241
2241
  } catch {
2242
2242
  return fallback;
2243
2243
  }
2244
2244
  }
2245
2245
  function brokenLinkRecord(linkPath, relativePath, rootReal) {
2246
2246
  const rawTarget = readLinkTarget(linkPath, linkPath);
2247
- const resolvedFallback = path16__namespace.resolve(path16__namespace.dirname(linkPath), rawTarget);
2247
+ const resolvedFallback = path17__namespace.resolve(path17__namespace.dirname(linkPath), rawTarget);
2248
2248
  return isInside(rootReal, resolvedFallback) ? { path: relativePath, reason: "read-error", detail: "broken symlink" } : {
2249
2249
  path: relativePath,
2250
2250
  reason: "outside-root",
@@ -2252,8 +2252,8 @@ function brokenLinkRecord(linkPath, relativePath, rootReal) {
2252
2252
  };
2253
2253
  }
2254
2254
  function isInside(root, candidate) {
2255
- const relative15 = path16__namespace.relative(root, candidate);
2256
- return relative15 === "" || !relative15.startsWith(`..${path16__namespace.sep}`) && relative15 !== ".." && !path16__namespace.isAbsolute(relative15);
2255
+ const relative15 = path17__namespace.relative(root, candidate);
2256
+ return relative15 === "" || !relative15.startsWith(`..${path17__namespace.sep}`) && relative15 !== ".." && !path17__namespace.isAbsolute(relative15);
2257
2257
  }
2258
2258
  var GIT_OUTPUT_LIMIT = 68157440;
2259
2259
  function getGitInfo(cwd, fallbackBranch = "main") {
@@ -2511,10 +2511,10 @@ function trimUnescapedTrailingSpaces(line) {
2511
2511
  return line.slice(0, end);
2512
2512
  }
2513
2513
  function readGitignoreRules(dir) {
2514
- const gitignorePath2 = path16__namespace.join(dir, ".gitignore");
2514
+ const gitignorePath2 = path17__namespace.join(dir, ".gitignore");
2515
2515
  let raw;
2516
2516
  try {
2517
- raw = fs15__namespace.readFileSync(gitignorePath2, "utf8");
2517
+ raw = fs16__namespace.readFileSync(gitignorePath2, "utf8");
2518
2518
  } catch {
2519
2519
  return [];
2520
2520
  }
@@ -2668,6 +2668,35 @@ function defaultIgnoreReason(relativePath, toolDirNames = DEFAULT_TOOL_DIR_NAMES
2668
2668
  }
2669
2669
  return null;
2670
2670
  }
2671
+ var COMMIT_BODY_LIMIT = 400;
2672
+ function recentCommits(cwd, limit = 10) {
2673
+ try {
2674
+ const stdout = childProcess__namespace.execFileSync(
2675
+ "git",
2676
+ // \x1f between fields and \x1e between records: neither can appear in a commit message, so
2677
+ // the parse cannot be confused by a message that contains a newline or a dash.
2678
+ ["log", "-n", String(limit), "--pretty=format:%s%x1f%b%x1e", "--no-color"],
2679
+ {
2680
+ cwd,
2681
+ stdio: ["ignore", "pipe", "ignore"],
2682
+ encoding: "utf8",
2683
+ maxBuffer: GIT_OUTPUT_LIMIT
2684
+ }
2685
+ );
2686
+ return stdout.split("").map((record) => record.replace(/^\n+/, "")).filter((record) => record.length > 0).map((record) => {
2687
+ const separator = record.indexOf("");
2688
+ const subject = separator === -1 ? record : record.slice(0, separator);
2689
+ const rawBody = separator === -1 ? "" : record.slice(separator + 1);
2690
+ const body = rawBody.split("\n").map((line) => line.trim()).filter((line) => line.length > 0).join(" ");
2691
+ return {
2692
+ subject: subject.trim(),
2693
+ body: body.length > COMMIT_BODY_LIMIT ? body.slice(0, COMMIT_BODY_LIMIT - 1) + "\u2026" : body
2694
+ };
2695
+ }).filter((commit) => commit.subject.length > 0);
2696
+ } catch {
2697
+ return [];
2698
+ }
2699
+ }
2671
2700
  function listIgnoredPaths(cwd) {
2672
2701
  try {
2673
2702
  const stdout = childProcess__namespace.execFileSync(
@@ -2687,7 +2716,7 @@ function listIgnoredPaths(cwd) {
2687
2716
  }
2688
2717
  function hasSnapshotMarker(target) {
2689
2718
  try {
2690
- return fs15__namespace.statSync(target).isDirectory() && fs15__namespace.existsSync(path16__namespace.join(target, ".codebase-snapshot"));
2719
+ return fs16__namespace.statSync(target).isDirectory() && fs16__namespace.existsSync(path17__namespace.join(target, ".codebase-snapshot"));
2691
2720
  } catch {
2692
2721
  return false;
2693
2722
  }
@@ -2696,7 +2725,7 @@ var IGNORABLE_DIRECTORY_ENTRIES = /* @__PURE__ */ new Set([".DS_Store"]);
2696
2725
  function isToolOwnedDirectory2(dir) {
2697
2726
  let raw;
2698
2727
  try {
2699
- raw = fs15__namespace.readFileSync(path16__namespace.join(dir, ".codebase-snapshot"), "utf8");
2728
+ raw = fs16__namespace.readFileSync(path17__namespace.join(dir, ".codebase-snapshot"), "utf8");
2700
2729
  } catch {
2701
2730
  return false;
2702
2731
  }
@@ -2723,7 +2752,7 @@ function isToolOwnedDirectory2(dir) {
2723
2752
  }
2724
2753
  let entries;
2725
2754
  try {
2726
- entries = fs15__namespace.readdirSync(dir);
2755
+ entries = fs16__namespace.readdirSync(dir);
2727
2756
  } catch {
2728
2757
  return false;
2729
2758
  }
@@ -2740,7 +2769,7 @@ function makeToolOwnedDecider(cwd, toolOwnedPaths) {
2740
2769
  const prefix = parts.slice(0, depth).join("/");
2741
2770
  let hasMarker = markers.get(prefix);
2742
2771
  if (hasMarker === void 0) {
2743
- hasMarker = isToolOwnedDirectory2(path16__namespace.join(cwd, prefix));
2772
+ hasMarker = isToolOwnedDirectory2(path17__namespace.join(cwd, prefix));
2744
2773
  markers.set(prefix, hasMarker);
2745
2774
  }
2746
2775
  if (hasMarker) return true;
@@ -2755,7 +2784,7 @@ function makeLinkProbe() {
2755
2784
  let known = cache.get(absolutePath);
2756
2785
  if (known === void 0) {
2757
2786
  try {
2758
- known = fs15__namespace.lstatSync(absolutePath).isSymbolicLink();
2787
+ known = fs16__namespace.lstatSync(absolutePath).isSymbolicLink();
2759
2788
  } catch {
2760
2789
  known = false;
2761
2790
  }
@@ -2768,7 +2797,7 @@ function dropLinkedDirectories(cwd, candidates, skipped) {
2768
2797
  const isLink = makeLinkProbe();
2769
2798
  let rootReal = cwd;
2770
2799
  try {
2771
- rootReal = fs15__namespace.realpathSync(cwd);
2800
+ rootReal = fs16__namespace.realpathSync(cwd);
2772
2801
  } catch {
2773
2802
  }
2774
2803
  const reported = /* @__PURE__ */ new Set();
@@ -2783,7 +2812,7 @@ function dropLinkedDirectories(cwd, candidates, skipped) {
2783
2812
  let linkedPath = null;
2784
2813
  for (let depth = 1; depth <= parts.length; depth += 1) {
2785
2814
  const prefix = parts.slice(0, depth).join("/");
2786
- if (isLink(path16__namespace.join(cwd, prefix))) {
2815
+ if (isLink(path17__namespace.join(cwd, prefix))) {
2787
2816
  linkedPath = prefix;
2788
2817
  break;
2789
2818
  }
@@ -2792,11 +2821,11 @@ function dropLinkedDirectories(cwd, candidates, skipped) {
2792
2821
  kept.push(candidate);
2793
2822
  continue;
2794
2823
  }
2795
- const absolute = path16__namespace.join(cwd, linkedPath);
2824
+ const absolute = path17__namespace.join(cwd, linkedPath);
2796
2825
  const rawTarget = readLinkTarget(absolute, absolute);
2797
2826
  let targetReal = null;
2798
2827
  try {
2799
- targetReal = fs15__namespace.realpathSync(absolute);
2828
+ targetReal = fs16__namespace.realpathSync(absolute);
2800
2829
  } catch {
2801
2830
  targetReal = null;
2802
2831
  }
@@ -2814,7 +2843,7 @@ function dropLinkedDirectories(cwd, candidates, skipped) {
2814
2843
  }
2815
2844
  let stats = null;
2816
2845
  try {
2817
- stats = fs15__namespace.statSync(absolute);
2846
+ stats = fs16__namespace.statSync(absolute);
2818
2847
  } catch {
2819
2848
  stats = null;
2820
2849
  }
@@ -2902,7 +2931,7 @@ function collectFiles(cwd, options = {}) {
2902
2931
  "Discovery mode is `git`, but git could not list this directory's files. Run inside a working repository, or pass --discovery walk (or auto) to scan the tree directly."
2903
2932
  );
2904
2933
  }
2905
- if (fs15__namespace.existsSync(path16__namespace.join(cwd, ".git"))) {
2934
+ if (fs16__namespace.existsSync(path17__namespace.join(cwd, ".git"))) {
2906
2935
  throw new Error(
2907
2936
  "This directory is a git repository, but git could not list its files. A plain walk honours .gitignore files, but git also applies .git/info/exclude and your global excludes file, includes files that are tracked although a .gitignore now matches them, and treats a submodule as a single entry. Fix the repository (git status should work), run outside git, or pass --discovery walk to accept those differences."
2908
2937
  );
@@ -2970,7 +2999,7 @@ function collectFiles(cwd, options = {}) {
2970
2999
  }
2971
3000
  function rootRealFor(root) {
2972
3001
  try {
2973
- return fs15__namespace.realpathSync(root);
3002
+ return fs16__namespace.realpathSync(root);
2974
3003
  } catch {
2975
3004
  return root;
2976
3005
  }
@@ -2979,18 +3008,18 @@ function walkDirectory(dir, baseDir, rootReal, visited, reservedPaths = /* @__PU
2979
3008
  const results = { files: [], skipped: [] };
2980
3009
  const stack = [];
2981
3010
  const toolDirNames = toolDirNamesFor(reservedPaths);
2982
- const relativeToBase = (target) => path16__namespace.relative(baseDir, target).replace(/\\/g, "/") || ".";
3011
+ const relativeToBase = (target) => path17__namespace.relative(baseDir, target).replace(/\\/g, "/") || ".";
2983
3012
  const enter = (current, layers) => {
2984
3013
  if (visited.has(current)) return false;
2985
3014
  visited.add(current);
2986
3015
  const localRules = readGitignoreRules(current);
2987
3016
  const gitignoreLayers = localRules.length === 0 ? layers : [
2988
3017
  ...layers,
2989
- { prefix: path16__namespace.relative(baseDir, current).replace(/\\/g, "/"), rules: localRules }
3018
+ { prefix: path17__namespace.relative(baseDir, current).replace(/\\/g, "/"), rules: localRules }
2990
3019
  ];
2991
3020
  let entries;
2992
3021
  try {
2993
- entries = fs15__namespace.readdirSync(current, { withFileTypes: true });
3022
+ entries = fs16__namespace.readdirSync(current, { withFileTypes: true });
2994
3023
  } catch {
2995
3024
  results.skipped.push({
2996
3025
  path: relativeToBase(current),
@@ -3012,8 +3041,8 @@ function walkDirectory(dir, baseDir, rootReal, visited, reservedPaths = /* @__PU
3012
3041
  }
3013
3042
  const entry = frame.entries[frame.index];
3014
3043
  frame.index += 1;
3015
- const fullPath = path16__namespace.join(frame.dir, entry.name);
3016
- const relPath = path16__namespace.relative(baseDir, fullPath).replace(/\\/g, "/");
3044
+ const fullPath = path17__namespace.join(frame.dir, entry.name);
3045
+ const relPath = path17__namespace.relative(baseDir, fullPath).replace(/\\/g, "/");
3017
3046
  if (reservedPaths.has(relPath)) continue;
3018
3047
  if (entry.isDirectory() && DEFAULT_IGNORED_DIRS.includes(entry.name)) {
3019
3048
  results.skipped.push({
@@ -3046,14 +3075,14 @@ function walkDirectory(dir, baseDir, rootReal, visited, reservedPaths = /* @__PU
3046
3075
  if (entry.isSymbolicLink()) {
3047
3076
  let targetReal;
3048
3077
  try {
3049
- targetReal = fs15__namespace.realpathSync(fullPath);
3078
+ targetReal = fs16__namespace.realpathSync(fullPath);
3050
3079
  } catch {
3051
3080
  results.skipped.push(brokenLinkRecord(fullPath, relPath, rootReal));
3052
3081
  continue;
3053
3082
  }
3054
3083
  let stats;
3055
3084
  try {
3056
- stats = fs15__namespace.statSync(fullPath);
3085
+ stats = fs16__namespace.statSync(fullPath);
3057
3086
  } catch {
3058
3087
  results.skipped.push({ path: relPath, reason: "read-error", detail: "unreadable symlink" });
3059
3088
  continue;
@@ -3083,7 +3112,7 @@ function walkDirectory(dir, baseDir, rootReal, visited, reservedPaths = /* @__PU
3083
3112
  });
3084
3113
  continue;
3085
3114
  }
3086
- const targetRelative = path16__namespace.relative(rootReal, targetReal).split(path16__namespace.sep).join("/");
3115
+ const targetRelative = path17__namespace.relative(rootReal, targetReal).split(path17__namespace.sep).join("/");
3087
3116
  if (isSensitivePath(targetRelative)) {
3088
3117
  results.skipped.push({
3089
3118
  path: relPath,
@@ -3275,6 +3304,77 @@ function summarizeMarkdown(content) {
3275
3304
  frontmatterKeys: Array.from(new Set(frontmatterKeys)).sort()
3276
3305
  };
3277
3306
  }
3307
+ var OWNER_SECTIONS = ["Stakes", "The system", "What came before", "The bar", "Calibration"];
3308
+ var RESERVED_SECTIONS = [
3309
+ "The job",
3310
+ "What you have",
3311
+ "Coverage",
3312
+ "What a useful answer contains",
3313
+ "This snapshot",
3314
+ "Attaching this",
3315
+ "Your task"
3316
+ ];
3317
+ function parseOwnerBrief(filePath, text2) {
3318
+ const problems = [];
3319
+ const source = text2.replace(/^\uFEFF/, "");
3320
+ const preamble = [];
3321
+ const sections = [];
3322
+ let current = null;
3323
+ for (const line of source.split(/\r?\n/)) {
3324
+ const heading = /^##\s+(.+?)\s*$/.exec(line);
3325
+ if (heading) {
3326
+ current = { heading: heading[1], body: [] };
3327
+ sections.push(current);
3328
+ continue;
3329
+ }
3330
+ if (current) current.body.push(line);
3331
+ else preamble.push(line);
3332
+ }
3333
+ const recognised = {};
3334
+ const notes = [];
3335
+ const canonical = (heading) => heading.trim().toLowerCase().replace(/\s+/g, " ");
3336
+ const canonicalOwner = new Map(OWNER_SECTIONS.map((name) => [canonical(name), name]));
3337
+ const canonicalReserved = new Set(RESERVED_SECTIONS.map(canonical));
3338
+ const seen = /* @__PURE__ */ new Set();
3339
+ for (const section of sections) {
3340
+ const body = section.body.join("\n").trim();
3341
+ const key = canonical(section.heading);
3342
+ if (seen.has(key)) {
3343
+ problems.push(
3344
+ `the brief defines "${section.heading}" twice; a section cannot say two things.`
3345
+ );
3346
+ continue;
3347
+ }
3348
+ seen.add(key);
3349
+ if (canonicalReserved.has(key)) {
3350
+ problems.push(
3351
+ `the brief may not define "${section.heading}": that section is rendered from the manifest, and letting prose overwrite a measured section would make the document lie.`
3352
+ );
3353
+ continue;
3354
+ }
3355
+ const ownerName = canonicalOwner.get(key);
3356
+ if (ownerName !== void 0) {
3357
+ recognised[ownerName] = body;
3358
+ continue;
3359
+ }
3360
+ notes.push({ heading: section.heading, body });
3361
+ }
3362
+ const preambleText = preamble.join("\n").trim();
3363
+ return {
3364
+ brief: {
3365
+ path: filePath,
3366
+ digest: crypto3.createHash("sha256").update(text2, "utf8").digest("hex"),
3367
+ ...recognised["Stakes"] ? { stakes: recognised["Stakes"] } : {},
3368
+ ...recognised["The system"] ? { system: recognised["The system"] } : {},
3369
+ ...recognised["What came before"] ? { history: recognised["What came before"] } : {},
3370
+ ...recognised["The bar"] ? { bar: recognised["The bar"] } : {},
3371
+ ...recognised["Calibration"] ? { calibration: recognised["Calibration"] } : {},
3372
+ notes,
3373
+ ...preambleText.length > 0 ? { preamble: preambleText } : {}
3374
+ },
3375
+ problems
3376
+ };
3377
+ }
3278
3378
 
3279
3379
  // src/tokenize.ts
3280
3380
  var WORD_RUN = /[A-Za-z0-9_]+/g;
@@ -3311,20 +3411,20 @@ var CONFIG_FILENAMES = [
3311
3411
  ];
3312
3412
  function findConfigFile(cwd) {
3313
3413
  for (const filename of CONFIG_FILENAMES) {
3314
- const fullPath = path16__namespace.join(cwd, filename);
3414
+ const fullPath = path17__namespace.join(cwd, filename);
3315
3415
  let stats = null;
3316
3416
  try {
3317
- stats = fs15__namespace.statSync(fullPath);
3417
+ stats = fs16__namespace.statSync(fullPath);
3318
3418
  } catch {
3319
- if (fs15__namespace.existsSync(fullPath)) return fullPath;
3419
+ if (fs16__namespace.existsSync(fullPath)) return fullPath;
3320
3420
  continue;
3321
3421
  }
3322
3422
  if (stats.isFile()) return fullPath;
3323
3423
  }
3324
- const pkgJsonPath = path16__namespace.join(cwd, "package.json");
3325
- if (!fs15__namespace.existsSync(pkgJsonPath)) return null;
3424
+ const pkgJsonPath = path17__namespace.join(cwd, "package.json");
3425
+ if (!fs16__namespace.existsSync(pkgJsonPath)) return null;
3326
3426
  try {
3327
- const parsed = JSON.parse(stripJsonComments(fs15__namespace.readFileSync(pkgJsonPath, "utf8")));
3427
+ const parsed = JSON.parse(stripJsonComments(fs16__namespace.readFileSync(pkgJsonPath, "utf8")));
3328
3428
  const snapshot = parsed?.snapshot;
3329
3429
  return typeof snapshot === "object" && snapshot !== null && !Array.isArray(snapshot) ? pkgJsonPath : null;
3330
3430
  } catch {
@@ -3386,6 +3486,12 @@ function normalizeResolvedConfig(config) {
3386
3486
  return markResolvedConfig({
3387
3487
  ...config,
3388
3488
  discovery,
3489
+ // A spread copy built before the field existed carries no value; the default applies, and it
3490
+ // is re-validated because the number reaches a rendered artifact.
3491
+ attachmentSlots: resolveAttachmentSlots(config.attachmentSlots),
3492
+ maxParts: resolveMaxParts(config.maxParts),
3493
+ promptTask: resolvePromptTask(config.promptTask),
3494
+ ...config.brief === void 0 ? {} : { brief: config.brief },
3389
3495
  includeMonolith: artifacts.monolith,
3390
3496
  secretRules: compileSecretRules(config.secretRules),
3391
3497
  artifacts,
@@ -3454,7 +3560,9 @@ function describeValue2(value) {
3454
3560
  var isThenable = (value) => typeof value.then === "function";
3455
3561
  var CONFIG_KEY_NAMES = [
3456
3562
  "artifacts",
3563
+ "attachmentSlots",
3457
3564
  "branch",
3565
+ "brief",
3458
3566
  "budgets",
3459
3567
  "changedSince",
3460
3568
  "cwd",
@@ -3471,10 +3579,12 @@ var CONFIG_KEY_NAMES = [
3471
3579
  "layersMode",
3472
3580
  "maxMonolithBytes",
3473
3581
  "maxPartBytes",
3582
+ "maxParts",
3474
3583
  "maxPartTokens",
3475
3584
  "outDir",
3476
3585
  "preset",
3477
3586
  "previewHeadLines",
3587
+ "promptTask",
3478
3588
  "staged",
3479
3589
  "previewTailLines",
3480
3590
  "secretRules",
@@ -3525,10 +3635,10 @@ function readConfigExport(exported, file) {
3525
3635
  var lastModuleConfig = null;
3526
3636
  function moduleConfigKey(fullPath) {
3527
3637
  try {
3528
- return crypto3.createHash("sha256").update(fs15__namespace.readFileSync(fullPath)).digest("hex").slice(0, 24);
3638
+ return crypto3.createHash("sha256").update(fs16__namespace.readFileSync(fullPath)).digest("hex").slice(0, 24);
3529
3639
  } catch {
3530
3640
  try {
3531
- const stats = fs15__namespace.statSync(fullPath);
3641
+ const stats = fs16__namespace.statSync(fullPath);
3532
3642
  return `stat-${stats.mtimeMs}-${stats.size}`;
3533
3643
  } catch {
3534
3644
  return "unreadable";
@@ -3554,7 +3664,7 @@ async function importConfigModule(fullPath) {
3554
3664
  function attachConfigDir(config, filePath) {
3555
3665
  if (typeof config === "object" && config !== null) {
3556
3666
  Object.defineProperty(config, CONFIG_DIR_SYMBOL, {
3557
- value: path16__namespace.dirname(filePath),
3667
+ value: path17__namespace.dirname(filePath),
3558
3668
  enumerable: false,
3559
3669
  configurable: true
3560
3670
  });
@@ -3566,12 +3676,12 @@ async function loadConfigFileDetailed(cwd, options = {}) {
3566
3676
  const errors = [];
3567
3677
  const configDirectories = [];
3568
3678
  for (const filename of CONFIG_FILENAMES) {
3569
- const fullPath = path16__namespace.join(cwd, filename);
3679
+ const fullPath = path17__namespace.join(cwd, filename);
3570
3680
  let candidateStats = null;
3571
3681
  try {
3572
- candidateStats = fs15__namespace.statSync(fullPath);
3682
+ candidateStats = fs16__namespace.statSync(fullPath);
3573
3683
  } catch {
3574
- if (!fs15__namespace.existsSync(fullPath)) continue;
3684
+ if (!fs16__namespace.existsSync(fullPath)) continue;
3575
3685
  }
3576
3686
  if (candidateStats !== null && !candidateStats.isFile()) {
3577
3687
  configDirectories.push(fullPath);
@@ -3579,7 +3689,7 @@ async function loadConfigFileDetailed(cwd, options = {}) {
3579
3689
  }
3580
3690
  if (filename.endsWith(".json") || filename === ".snapshotrc") {
3581
3691
  try {
3582
- const config = parseJsonish(fs15__namespace.readFileSync(fullPath, "utf8"), fullPath);
3692
+ const config = parseJsonish(fs16__namespace.readFileSync(fullPath, "utf8"), fullPath);
3583
3693
  if (config === null || typeof config !== "object" || Array.isArray(config)) {
3584
3694
  throw new Error(
3585
3695
  `${fullPath} does not hold a configuration object (received ${describeValue2(config)}).`
@@ -3619,10 +3729,10 @@ async function loadConfigFileDetailed(cwd, options = {}) {
3619
3729
  continue;
3620
3730
  }
3621
3731
  }
3622
- const pkgJsonPath = path16__namespace.join(cwd, "package.json");
3623
- if (fs15__namespace.existsSync(pkgJsonPath)) {
3732
+ const pkgJsonPath = path17__namespace.join(cwd, "package.json");
3733
+ if (fs16__namespace.existsSync(pkgJsonPath)) {
3624
3734
  try {
3625
- const parsed = parseJsonish(fs15__namespace.readFileSync(pkgJsonPath, "utf8"), pkgJsonPath);
3735
+ const parsed = parseJsonish(fs16__namespace.readFileSync(pkgJsonPath, "utf8"), pkgJsonPath);
3626
3736
  const snapshotKey = parsed.snapshot;
3627
3737
  if (snapshotKey && typeof snapshotKey === "object" && !Array.isArray(snapshotKey)) {
3628
3738
  assertKnownConfigKeys(
@@ -3669,6 +3779,7 @@ var MIN_MAX_PART_BYTES = 4096;
3669
3779
  var MIN_MAX_PART_TOKENS = MIN_MAX_PART_BYTES / 4;
3670
3780
  var ARTIFACT_NAMES = [
3671
3781
  "readme",
3782
+ "prompt",
3672
3783
  "manifest",
3673
3784
  "parts",
3674
3785
  "navigation",
@@ -3678,6 +3789,7 @@ var ARTIFACT_NAMES = [
3678
3789
  ];
3679
3790
  var DEFAULT_ARTIFACTS = {
3680
3791
  readme: true,
3792
+ prompt: true,
3681
3793
  manifest: true,
3682
3794
  parts: true,
3683
3795
  navigation: true,
@@ -3738,6 +3850,57 @@ function resolveArtifacts(requested, skipped, includeMonolith, monolithOverride,
3738
3850
  }
3739
3851
  return artifacts;
3740
3852
  }
3853
+ var DEFAULT_ATTACHMENT_SLOTS = 10;
3854
+ function resolveAttachmentSlots(value) {
3855
+ if (value === void 0 || value === null) return DEFAULT_ATTACHMENT_SLOTS;
3856
+ if (typeof value !== "number" || !Number.isInteger(value) || value < 0) {
3857
+ throw new Error(
3858
+ "attachmentSlots must be a whole number, with 0 meaning no limit (received " + describeValue2(value) + ")."
3859
+ );
3860
+ }
3861
+ return value;
3862
+ }
3863
+ function resolveMaxParts(value) {
3864
+ if (value === void 0 || value === null) return null;
3865
+ if (typeof value !== "number" || !Number.isInteger(value) || value < 1) {
3866
+ throw new Error(
3867
+ "maxParts must be a whole number of parts, or null to disable it (received " + describeValue2(value) + ")."
3868
+ );
3869
+ }
3870
+ return value;
3871
+ }
3872
+ function resolvePromptTask(value) {
3873
+ if (value === void 0 || value === null) return "audit";
3874
+ if (value === "audit" || value === "review" || value === "explain") return value;
3875
+ throw new Error(
3876
+ 'promptTask must be one of "audit", "review" or "explain" (received ' + describeValue2(value) + ")."
3877
+ );
3878
+ }
3879
+ function readConfiguredBrief(cwd, value) {
3880
+ if (value === void 0 || value === null) return void 0;
3881
+ if (typeof value !== "string" || value.trim().length === 0) {
3882
+ throw new Error(
3883
+ "brief must be a path to a markdown file (received " + describeValue2(value) + ")."
3884
+ );
3885
+ }
3886
+ const filePath = path17__namespace.resolve(cwd, value);
3887
+ let text2;
3888
+ try {
3889
+ if (!fs16__namespace.statSync(filePath).isFile()) throw new Error("not a file");
3890
+ text2 = fs16__namespace.readFileSync(filePath, "utf8");
3891
+ } catch {
3892
+ throw new Error(
3893
+ 'brief "' + value + '" could not be read as a file; a snapshot must not ship without the half of the brief the owner wrote.'
3894
+ );
3895
+ }
3896
+ const parsed = parseOwnerBrief(value, text2);
3897
+ if (parsed.problems.length > 0) {
3898
+ throw new Error(
3899
+ 'brief "' + value + '" cannot be used:\n - ' + parsed.problems.join("\n - ")
3900
+ );
3901
+ }
3902
+ return parsed.brief;
3903
+ }
3741
3904
  function strictPositiveInteger(value, fallback, label) {
3742
3905
  if (value === void 0) return fallback;
3743
3906
  if (typeof value !== "number" || !Number.isInteger(value) || value <= 0) {
@@ -3830,9 +3993,9 @@ function resolveKindRules(value) {
3830
3993
  function outputExcludePatterns(cwd, outDir, tmpDir) {
3831
3994
  const patterns = [];
3832
3995
  for (const dir of [outDir, tmpDir]) {
3833
- const absolute = path16__namespace.resolve(cwd, dir);
3834
- const relative15 = path16__namespace.relative(cwd, absolute);
3835
- if (!relative15 || relative15 === ".." || relative15.startsWith(`..${path16__namespace.sep}`) || path16__namespace.isAbsolute(relative15)) {
3996
+ const absolute = path17__namespace.resolve(cwd, dir);
3997
+ const relative15 = path17__namespace.relative(cwd, absolute);
3998
+ if (!relative15 || relative15 === ".." || relative15.startsWith(`..${path17__namespace.sep}`) || path17__namespace.isAbsolute(relative15)) {
3836
3999
  continue;
3837
4000
  }
3838
4001
  patterns.push(`${relative15.replace(/\\/g, "/")}/**`);
@@ -3965,11 +4128,11 @@ function resolveCandidateCwd(userConfig, cliOptions, baseDir) {
3965
4128
  );
3966
4129
  }
3967
4130
  const candidate = cliOptions?.cwd || userConfig?.cwd || baseDir || process.cwd();
3968
- const resolved = path16__namespace.resolve(candidate);
3969
- if (!fs15__namespace.existsSync(resolved)) {
4131
+ const resolved = path17__namespace.resolve(candidate);
4132
+ if (!fs16__namespace.existsSync(resolved)) {
3970
4133
  throw new Error(`Working directory does not exist: ${resolved}`);
3971
4134
  }
3972
- if (!fs15__namespace.statSync(resolved).isDirectory()) {
4135
+ if (!fs16__namespace.statSync(resolved).isDirectory()) {
3973
4136
  throw new Error(`Working directory is not a directory: ${resolved}`);
3974
4137
  }
3975
4138
  return resolved;
@@ -4097,6 +4260,10 @@ function resolveConfig(userConfig, cliOptions, baseDir) {
4097
4260
  configuredSensitiveFiles,
4098
4261
  "`includeSensitiveFiles`"
4099
4262
  );
4263
+ const configuredBrief = readConfiguredBrief(
4264
+ cwd,
4265
+ cliOptions?.brief ?? userConfig?.brief
4266
+ );
4100
4267
  const presetExclude = [
4101
4268
  .../* @__PURE__ */ new Set([...preset.exclude, ...outputExcludePatterns(cwd, outDir, tmpDir)])
4102
4269
  ];
@@ -4116,6 +4283,12 @@ function resolveConfig(userConfig, cliOptions, baseDir) {
4116
4283
  "maxMonolithBytes"
4117
4284
  ),
4118
4285
  includeSensitiveFiles,
4286
+ attachmentSlots: resolveAttachmentSlots(
4287
+ cliOptions?.attachmentSlots ?? userConfig?.attachmentSlots
4288
+ ),
4289
+ maxParts: resolveMaxParts(cliOptions?.maxParts ?? userConfig?.maxParts),
4290
+ promptTask: resolvePromptTask(cliOptions?.promptTask ?? userConfig?.promptTask),
4291
+ ...configuredBrief === void 0 ? {} : { brief: configuredBrief },
4119
4292
  ...changedSince === void 0 ? {} : { changedSince },
4120
4293
  ...staged ? { staged } : {},
4121
4294
  ...withDependents ? { withDependents } : {},
@@ -4198,6 +4371,15 @@ function configDigest(config) {
4198
4371
  includeMonolith: config.includeMonolith,
4199
4372
  maxMonolithBytes: config.maxMonolithBytes ?? null,
4200
4373
  includeSensitiveFiles: config.includeSensitiveFiles,
4374
+ // Only when the experimental mode is on: `null` is the off switch, and writing it into the
4375
+ // material would change the digest of every snapshot taken before the setting existed.
4376
+ ...config.maxParts === null ? {} : { maxParts: config.maxParts },
4377
+ // The default value is omitted for the same reason: a snapshot taken before the setting
4378
+ // existed kept the audit job, so it must keep the digest it was written with.
4379
+ ...config.promptTask === "audit" ? {} : { promptTask: config.promptTask },
4380
+ // The owner brief is instruction, not payload, but it changes what the snapshot tells a
4381
+ // reader to do, so a changed brief is drift exactly like a changed budget.
4382
+ ...config.brief === void 0 ? {} : { brief: config.brief.digest },
4201
4383
  artifacts: config.artifacts,
4202
4384
  include: config.include,
4203
4385
  excludePatterns: config.excludePatterns,
@@ -4281,7 +4463,7 @@ function resolveChangedScope(cwd, request) {
4281
4463
  const descriptions = [];
4282
4464
  if (request.changedSince !== void 0) {
4283
4465
  assertUsableRef(request.changedSince);
4284
- for (const path22 of gitPaths(cwd, [
4466
+ for (const path23 of gitPaths(cwd, [
4285
4467
  "diff",
4286
4468
  "--name-only",
4287
4469
  "-z",
@@ -4289,9 +4471,9 @@ function resolveChangedScope(cwd, request) {
4289
4471
  `${request.changedSince}...HEAD`,
4290
4472
  "--"
4291
4473
  ])) {
4292
- paths.add(path22);
4474
+ paths.add(path23);
4293
4475
  }
4294
- for (const path22 of gitPaths(cwd, [
4476
+ for (const path23 of gitPaths(cwd, [
4295
4477
  "diff",
4296
4478
  "--name-only",
4297
4479
  "-z",
@@ -4299,15 +4481,15 @@ function resolveChangedScope(cwd, request) {
4299
4481
  "HEAD",
4300
4482
  "--"
4301
4483
  ])) {
4302
- paths.add(path22);
4484
+ paths.add(path23);
4303
4485
  }
4304
- for (const path22 of gitPaths(cwd, ["ls-files", "--others", "--exclude-standard", "-z", "--"])) {
4305
- paths.add(path22);
4486
+ for (const path23 of gitPaths(cwd, ["ls-files", "--others", "--exclude-standard", "-z", "--"])) {
4487
+ paths.add(path23);
4306
4488
  }
4307
4489
  descriptions.push(`changed since ${request.changedSince}`);
4308
4490
  }
4309
4491
  if (request.staged === true) {
4310
- for (const path22 of gitPaths(cwd, [
4492
+ for (const path23 of gitPaths(cwd, [
4311
4493
  "diff",
4312
4494
  "--cached",
4313
4495
  "--name-only",
@@ -4315,10 +4497,10 @@ function resolveChangedScope(cwd, request) {
4315
4497
  "--relative",
4316
4498
  "--"
4317
4499
  ])) {
4318
- paths.add(path22);
4319
- stagedPaths.add(path22);
4500
+ paths.add(path23);
4501
+ stagedPaths.add(path23);
4320
4502
  }
4321
- for (const path22 of gitPaths(cwd, [
4503
+ for (const path23 of gitPaths(cwd, [
4322
4504
  "diff",
4323
4505
  "--cached",
4324
4506
  "--name-only",
@@ -4327,7 +4509,7 @@ function resolveChangedScope(cwd, request) {
4327
4509
  "--diff-filter=D",
4328
4510
  "--"
4329
4511
  ])) {
4330
- deletedPaths.add(path22);
4512
+ deletedPaths.add(path23);
4331
4513
  }
4332
4514
  descriptions.push("staged");
4333
4515
  }
@@ -4365,10 +4547,10 @@ var PYTHON_SUFFIXES = [".py", ".pyi", "/__init__.py", "/__init__.pyi"];
4365
4547
  var CASE_INSENSITIVE_FILESYSTEM = process.platform === "win32" || process.platform === "darwin";
4366
4548
  var TSCONFIG_CACHE = /* @__PURE__ */ new Map();
4367
4549
  function tsconfigPathsFor(cwd) {
4368
- const configPath = path16__namespace.join(cwd, "tsconfig.json");
4550
+ const configPath = path17__namespace.join(cwd, "tsconfig.json");
4369
4551
  let stats;
4370
4552
  try {
4371
- stats = fs15__namespace.statSync(configPath);
4553
+ stats = fs16__namespace.statSync(configPath);
4372
4554
  } catch (err) {
4373
4555
  if (err.code === "ENOENT") return null;
4374
4556
  return null;
@@ -4402,8 +4584,8 @@ function tsconfigPathsFor(cwd) {
4402
4584
  return value;
4403
4585
  }
4404
4586
  function repositoryRelative(cwd, target) {
4405
- const relative15 = path16__namespace.relative(cwd, target).replace(/\\/g, "/");
4406
- return relative15.length === 0 || !relative15.startsWith("..") && !path16__namespace.isAbsolute(relative15) ? relative15 : null;
4587
+ const relative15 = path17__namespace.relative(cwd, target).replace(/\\/g, "/");
4588
+ return relative15.length === 0 || !relative15.startsWith("..") && !path17__namespace.isAbsolute(relative15) ? relative15 : null;
4407
4589
  }
4408
4590
  function rememberFirst(map, key, value) {
4409
4591
  if (!map.has(key)) map.set(key, value);
@@ -4418,15 +4600,15 @@ function buildImportResolver(files, options = {}) {
4418
4600
  if (CASE_INSENSITIVE_FILESYSTEM) {
4419
4601
  rememberFirst(byPathFolded, relativePath.toLowerCase(), relativePath);
4420
4602
  }
4421
- const extension = path16__namespace.posix.extname(relativePath);
4603
+ const extension = path17__namespace.posix.extname(relativePath);
4422
4604
  if (!SOURCE_EXTENSIONS.has(extension)) return;
4423
4605
  const stem = relativePath.slice(0, -extension.length);
4424
4606
  rememberFirst(byStem, stem, relativePath);
4425
4607
  if (CASE_INSENSITIVE_FILESYSTEM) {
4426
4608
  rememberFirst(byStemFolded, stem.toLowerCase(), relativePath);
4427
4609
  }
4428
- if (path16__namespace.posix.basename(stem) === "index") {
4429
- const directory = path16__namespace.posix.dirname(stem);
4610
+ if (path17__namespace.posix.basename(stem) === "index") {
4611
+ const directory = path17__namespace.posix.dirname(stem);
4430
4612
  rememberFirst(byStem, directory, relativePath);
4431
4613
  if (CASE_INSENSITIVE_FILESYSTEM) {
4432
4614
  rememberFirst(byStemFolded, directory.toLowerCase(), relativePath);
@@ -4442,7 +4624,7 @@ function buildImportResolver(files, options = {}) {
4442
4624
  return { byPath, byPathFolded, byStem, byStemFolded, tsconfig: options.tsconfig ?? null };
4443
4625
  }
4444
4626
  function resolveSpecifier(fromFile, specifier, resolver) {
4445
- const extension = path16__namespace.posix.extname(fromFile).toLowerCase();
4627
+ const extension = path17__namespace.posix.extname(fromFile).toLowerCase();
4446
4628
  const exact = (key) => resolver.byPath.get(key) ?? (CASE_INSENSITIVE_FILESYSTEM ? resolver.byPathFolded.get(key.toLowerCase()) : void 0) ?? null;
4447
4629
  const firstOf = (candidates) => {
4448
4630
  for (const candidate of candidates) {
@@ -4465,34 +4647,34 @@ function resolveSpecifier(fromFile, specifier, resolver) {
4465
4647
  if (PYTHON_EXTENSIONS.has(extension) && specifier.startsWith(".")) {
4466
4648
  const dots = /^\.+/.exec(specifier)?.[0].length ?? 0;
4467
4649
  const rest = specifier.slice(dots).replace(/\./g, "/");
4468
- let base = path16__namespace.posix.dirname(fromFile);
4469
- for (let up = 1; up < dots; up += 1) base = path16__namespace.posix.dirname(base);
4470
- const joined2 = rest ? path16__namespace.posix.normalize(path16__namespace.posix.join(base, rest)) : base;
4650
+ let base = path17__namespace.posix.dirname(fromFile);
4651
+ for (let up = 1; up < dots; up += 1) base = path17__namespace.posix.dirname(base);
4652
+ const joined2 = rest ? path17__namespace.posix.normalize(path17__namespace.posix.join(base, rest)) : base;
4471
4653
  return firstOf([joined2, ...PYTHON_SUFFIXES.map((suffix) => `${joined2}${suffix}`)]);
4472
4654
  }
4473
4655
  if (RUBY_EXTENSIONS.has(extension) && specifier.startsWith("./")) {
4474
- const joined2 = path16__namespace.posix.normalize(
4475
- path16__namespace.posix.join(path16__namespace.posix.dirname(fromFile), specifier)
4656
+ const joined2 = path17__namespace.posix.normalize(
4657
+ path17__namespace.posix.join(path17__namespace.posix.dirname(fromFile), specifier)
4476
4658
  );
4477
4659
  return firstOf([`${joined2}.rb`, joined2]);
4478
4660
  }
4479
4661
  if (C_EXTENSIONS.has(extension) && specifier.startsWith("./")) {
4480
- const joined2 = path16__namespace.posix.normalize(
4481
- path16__namespace.posix.join(path16__namespace.posix.dirname(fromFile), specifier)
4662
+ const joined2 = path17__namespace.posix.normalize(
4663
+ path17__namespace.posix.join(path17__namespace.posix.dirname(fromFile), specifier)
4482
4664
  );
4483
4665
  return exact(joined2);
4484
4666
  }
4485
4667
  if (extension === ".dart" && !specifier.includes(":")) {
4486
- const joined2 = path16__namespace.posix.normalize(
4487
- path16__namespace.posix.join(path16__namespace.posix.dirname(fromFile), specifier)
4668
+ const joined2 = path17__namespace.posix.normalize(
4669
+ path17__namespace.posix.join(path17__namespace.posix.dirname(fromFile), specifier)
4488
4670
  );
4489
4671
  return firstOf([joined2, `${joined2}.dart`]);
4490
4672
  }
4491
4673
  if (!RELATIVE_SPECIFIER.test(specifier)) {
4492
4674
  return resolveTsconfigSpecifier(specifier, resolver, lookupPath);
4493
4675
  }
4494
- const joined = path16__namespace.posix.normalize(
4495
- path16__namespace.posix.join(path16__namespace.posix.dirname(fromFile), specifier)
4676
+ const joined = path17__namespace.posix.normalize(
4677
+ path17__namespace.posix.join(path17__namespace.posix.dirname(fromFile), specifier)
4496
4678
  );
4497
4679
  return lookupPath(joined);
4498
4680
  }
@@ -4516,13 +4698,13 @@ function resolveTsconfigSpecifier(specifier, resolver, lookupPath) {
4516
4698
  if (captured === null) continue;
4517
4699
  for (const target of rule.targets) {
4518
4700
  const substituted = target.split("*").join(captured);
4519
- const base = config.baseUrl === null ? substituted : path16__namespace.posix.join(config.baseUrl, substituted);
4520
- const hit = lookupPath(path16__namespace.posix.normalize(base));
4701
+ const base = config.baseUrl === null ? substituted : path17__namespace.posix.join(config.baseUrl, substituted);
4702
+ const hit = lookupPath(path17__namespace.posix.normalize(base));
4521
4703
  if (hit) return hit;
4522
4704
  }
4523
4705
  }
4524
4706
  if (config.baseUrl !== null) {
4525
- return lookupPath(path16__namespace.posix.normalize(path16__namespace.posix.join(config.baseUrl, specifier)));
4707
+ return lookupPath(path17__namespace.posix.normalize(path17__namespace.posix.join(config.baseUrl, specifier)));
4526
4708
  }
4527
4709
  return null;
4528
4710
  }
@@ -5142,9 +5324,9 @@ var JAVA_METHOD = /^\s+(?:public|private|protected)\s+(?:static\s+)?(?:final\s+)
5142
5324
  var jvmProfile = {
5143
5325
  id: "jvm",
5144
5326
  extensions: [".java", ".kt", ".kts", ".scala"],
5145
- summarize(path22, content) {
5327
+ summarize(path23, content) {
5146
5328
  const summary = emptySummary();
5147
- const lower = path22.toLowerCase();
5329
+ const lower = path23.toLowerCase();
5148
5330
  const isJava = lower.endsWith(".java");
5149
5331
  const isKotlin = lower.endsWith(".kt") || lower.endsWith(".kts");
5150
5332
  eachLine(content, (line) => {
@@ -5465,17 +5647,17 @@ var rustProfile = {
5465
5647
  var SCRIPT_BLOCK = /<script([^>]*)>([\s\S]*?)<\/script>/gi;
5466
5648
  var JSX_LANG = /\blang\s*=\s*["']?[tj]sx\b/i;
5467
5649
  var ASTRO_FRONTMATTER = /^\uFEFF?---[ \t]*\r?\n([\s\S]*?)\r?\n---[ \t]*(?=\r?\n|$)/;
5468
- function componentName(path22) {
5469
- const base = path22.split("/").pop() ?? path22;
5650
+ function componentName(path23) {
5651
+ const base = path23.split("/").pop() ?? path23;
5470
5652
  return base.replace(/\.[^.]+$/, "");
5471
5653
  }
5472
5654
  var sfcProfile = {
5473
5655
  id: "sfc",
5474
5656
  extensions: [".vue", ".svelte", ".astro"],
5475
- summarize(path22, content) {
5657
+ summarize(path23, content) {
5476
5658
  let script = "";
5477
- let usesJsx = path22.toLowerCase().endsWith(".astro");
5478
- if (path22.toLowerCase().endsWith(".astro")) {
5659
+ let usesJsx = path23.toLowerCase().endsWith(".astro");
5660
+ if (path23.toLowerCase().endsWith(".astro")) {
5479
5661
  const frontmatter = ASTRO_FRONTMATTER.exec(content);
5480
5662
  if (frontmatter) script += `${frontmatter[1]}
5481
5663
  `;
@@ -5485,7 +5667,7 @@ var sfcProfile = {
5485
5667
  script += `${match[2]}
5486
5668
  `;
5487
5669
  }
5488
- const name = componentName(path22);
5670
+ const name = componentName(path23);
5489
5671
  if (!script.trim()) {
5490
5672
  const summary2 = emptySummary();
5491
5673
  if (name) {
@@ -5676,15 +5858,15 @@ for (const profile of LANGUAGE_PROFILES) {
5676
5858
  BY_EXTENSION.set(extension.toLowerCase(), profile);
5677
5859
  }
5678
5860
  }
5679
- function profileForPath(path22) {
5680
- const lower = path22.toLowerCase();
5861
+ function profileForPath(path23) {
5862
+ const lower = path23.toLowerCase();
5681
5863
  const dot = lower.lastIndexOf(".");
5682
5864
  if (dot === -1) return null;
5683
5865
  return BY_EXTENSION.get(lower.slice(dot)) ?? null;
5684
5866
  }
5685
- function summarizeWithProfile(path22, content) {
5686
- const profile = profileForPath(path22);
5687
- return profile ? profile.summarize(path22, content) : null;
5867
+ function summarizeWithProfile(path23, content) {
5868
+ const profile = profileForPath(path23);
5869
+ return profile ? profile.summarize(path23, content) : null;
5688
5870
  }
5689
5871
  var BINARY_EXTENSIONS = /* @__PURE__ */ new Set([
5690
5872
  ".png",
@@ -5729,7 +5911,7 @@ var BINARY_EXTENSIONS = /* @__PURE__ */ new Set([
5729
5911
  ".so"
5730
5912
  ]);
5731
5913
  function isBinaryExtension(filePath) {
5732
- const ext = path16__namespace.extname(filePath).toLowerCase();
5914
+ const ext = path17__namespace.extname(filePath).toLowerCase();
5733
5915
  return BINARY_EXTENSIONS.has(ext);
5734
5916
  }
5735
5917
  function countControlBytes(buffer) {
@@ -5896,13 +6078,13 @@ function isBinaryFile(absolutePath) {
5896
6078
  if (isBinaryExtension(absolutePath)) return true;
5897
6079
  let fd;
5898
6080
  try {
5899
- fd = fs15__namespace.openSync(absolutePath, "r");
6081
+ fd = fs16__namespace.openSync(absolutePath, "r");
5900
6082
  const buffer = Buffer.alloc(CHUNK);
5901
6083
  let sample;
5902
6084
  let position = 0;
5903
6085
  while (position < BINARY_SCAN_BYTES) {
5904
6086
  const wanted = Math.min(CHUNK, BINARY_SCAN_BYTES - position);
5905
- const bytesRead = fs15__namespace.readSync(fd, buffer, 0, wanted, position);
6087
+ const bytesRead = fs16__namespace.readSync(fd, buffer, 0, wanted, position);
5906
6088
  if (bytesRead === 0) return false;
5907
6089
  const chunk = buffer.subarray(0, bytesRead);
5908
6090
  if (sample === void 0) {
@@ -5920,7 +6102,7 @@ function isBinaryFile(absolutePath) {
5920
6102
  } finally {
5921
6103
  if (fd !== void 0) {
5922
6104
  try {
5923
- fs15__namespace.closeSync(fd);
6105
+ fs16__namespace.closeSync(fd);
5924
6106
  } catch {
5925
6107
  }
5926
6108
  }
@@ -5942,9 +6124,9 @@ function importsOfText(relativePath, text2) {
5942
6124
  function importsOfFile(relativePath, absolutePath) {
5943
6125
  let buffer;
5944
6126
  try {
5945
- const stats = fs15__namespace.statSync(absolutePath);
6127
+ const stats = fs16__namespace.statSync(absolutePath);
5946
6128
  if (!stats.isFile() || stats.size > SUMMARY_MAX_SOURCE_BYTES) return [];
5947
- buffer = fs15__namespace.readFileSync(absolutePath);
6129
+ buffer = fs16__namespace.readFileSync(absolutePath);
5948
6130
  } catch {
5949
6131
  return [];
5950
6132
  }
@@ -5959,33 +6141,33 @@ function maskedPath(value, secretRules) {
5959
6141
  }
5960
6142
  function confineToDirectory(directory, filename) {
5961
6143
  if (filename.includes("\0")) return null;
5962
- if (path16__namespace.isAbsolute(filename)) return null;
5963
- const base = path16__namespace.resolve(directory);
5964
- const resolved = path16__namespace.resolve(base, filename);
6144
+ if (path17__namespace.isAbsolute(filename)) return null;
6145
+ const base = path17__namespace.resolve(directory);
6146
+ const resolved = path17__namespace.resolve(base, filename);
5965
6147
  const caseInsensitive = process.platform === "win32" || process.platform === "darwin";
5966
- const prefix = caseInsensitive ? `${base}${path16__namespace.sep}`.toLowerCase() : `${base}${path16__namespace.sep}`;
6148
+ const prefix = caseInsensitive ? `${base}${path17__namespace.sep}`.toLowerCase() : `${base}${path17__namespace.sep}`;
5967
6149
  const candidate = caseInsensitive ? resolved.toLowerCase() : resolved;
5968
6150
  return candidate.startsWith(prefix) ? resolved : null;
5969
6151
  }
5970
6152
  function findStagingDirectory(config) {
5971
- const tmpDir = path16__namespace.resolve(config.cwd, config.tmpDir);
6153
+ const tmpDir = path17__namespace.resolve(config.cwd, config.tmpDir);
5972
6154
  let entries;
5973
6155
  try {
5974
- entries = fs15__namespace.readdirSync(tmpDir);
6156
+ entries = fs16__namespace.readdirSync(tmpDir);
5975
6157
  } catch {
5976
6158
  return null;
5977
6159
  }
5978
6160
  const runs = entries.filter((name) => name.startsWith("run-")).sort();
5979
6161
  const newest = runs[runs.length - 1];
5980
- return newest ? path16__namespace.join(tmpDir, newest) : null;
6162
+ return newest ? path17__namespace.join(tmpDir, newest) : null;
5981
6163
  }
5982
6164
  function describeMissingManifest(config, manifestPath) {
5983
- const outDir = path16__namespace.resolve(config.cwd, config.outDir);
5984
- const markerPath = path16__namespace.join(outDir, ".codebase-snapshot");
6165
+ const outDir = path17__namespace.resolve(config.cwd, config.outDir);
6166
+ const markerPath = path17__namespace.join(outDir, ".codebase-snapshot");
5985
6167
  let marker2 = null;
5986
6168
  try {
5987
- if (fs15__namespace.existsSync(markerPath)) {
5988
- const parsed = JSON.parse(fs15__namespace.readFileSync(markerPath, "utf8"));
6169
+ if (fs16__namespace.existsSync(markerPath)) {
6170
+ const parsed = JSON.parse(fs16__namespace.readFileSync(markerPath, "utf8"));
5989
6171
  if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
5990
6172
  marker2 = parsed;
5991
6173
  }
@@ -6020,13 +6202,13 @@ function sha256Hex(buffer) {
6020
6202
  return crypto3__namespace.createHash("sha256").update(buffer).digest("hex");
6021
6203
  }
6022
6204
  function wouldNowBeIncluded(cwd, relativePath) {
6023
- const absolutePath = path16__namespace.join(cwd, relativePath);
6205
+ const absolutePath = path17__namespace.join(cwd, relativePath);
6024
6206
  try {
6025
- const stats = fs15__namespace.statSync(absolutePath);
6207
+ const stats = fs16__namespace.statSync(absolutePath);
6026
6208
  if (!stats.isFile()) return false;
6027
6209
  if (isBinaryExtension(absolutePath)) return false;
6028
6210
  if (stats.size > BINARY_SCAN_BYTES && isBinaryFile(absolutePath)) return false;
6029
- return !decodeText(fs15__namespace.readFileSync(absolutePath)).binary;
6211
+ return !decodeText(fs16__namespace.readFileSync(absolutePath)).binary;
6030
6212
  } catch {
6031
6213
  return false;
6032
6214
  }
@@ -6038,7 +6220,7 @@ var TRUNCATION_REASONS = /* @__PURE__ */ new Set([
6038
6220
  ]);
6039
6221
  function isConfinedRelative(value) {
6040
6222
  if (value.length === 0 || value.includes("\0") || value.includes("\\")) return false;
6041
- if (path16__namespace.isAbsolute(value)) return false;
6223
+ if (path17__namespace.isAbsolute(value)) return false;
6042
6224
  return !value.split("/").includes("..");
6043
6225
  }
6044
6226
  function describeManifestShapeProblem(value) {
@@ -6206,7 +6388,7 @@ function describeManifestShapeProblem(value) {
6206
6388
  if (typeof filename !== "string" || filename.trim() === "") {
6207
6389
  return 'a "parts" entry has no "filename"';
6208
6390
  }
6209
- if (filename.includes("/") || filename.includes("\\") || filename.includes("\0") || filename === "." || filename === ".." || path16__namespace.isAbsolute(filename)) {
6391
+ if (filename.includes("/") || filename.includes("\\") || filename.includes("\0") || filename === "." || filename === ".." || path17__namespace.isAbsolute(filename)) {
6210
6392
  return 'a "parts" entry "filename" must be a bare filename inside parts/';
6211
6393
  }
6212
6394
  if (currentSchema) {
@@ -6232,8 +6414,8 @@ function describeManifestShapeProblem(value) {
6232
6414
  function validateSnapshot(configInput) {
6233
6415
  assertUsableConfigInput(configInput);
6234
6416
  const config = isResolvedConfig(configInput) ? normalizeResolvedConfig(configInput) : resolveConfig(configInput);
6235
- const manifestPath = path16__namespace.resolve(config.cwd, config.outDir, "manifest.json");
6236
- if (!fs15__namespace.existsSync(manifestPath)) {
6417
+ const manifestPath = path17__namespace.resolve(config.cwd, config.outDir, "manifest.json");
6418
+ if (!fs16__namespace.existsSync(manifestPath)) {
6237
6419
  return {
6238
6420
  valid: false,
6239
6421
  manifestPresent: false,
@@ -6244,7 +6426,7 @@ function validateSnapshot(configInput) {
6244
6426
  }
6245
6427
  let manifest;
6246
6428
  try {
6247
- manifest = JSON.parse(fs15__namespace.readFileSync(manifestPath, "utf8"));
6429
+ manifest = JSON.parse(fs16__namespace.readFileSync(manifestPath, "utf8"));
6248
6430
  } catch (err) {
6249
6431
  return {
6250
6432
  valid: false,
@@ -6266,7 +6448,7 @@ function validateSnapshot(configInput) {
6266
6448
  }
6267
6449
  const drift = emptyDrift();
6268
6450
  const warnings = [];
6269
- const snapshotDir = path16__namespace.resolve(config.cwd, config.outDir);
6451
+ const snapshotDir = path17__namespace.resolve(config.cwd, config.outDir);
6270
6452
  const unreadableSkips = manifest.skipped.filter(
6271
6453
  (entry) => entry.reason === "missing" || entry.reason === "read-error"
6272
6454
  );
@@ -6369,7 +6551,7 @@ function validateSnapshot(configInput) {
6369
6551
  );
6370
6552
  return importsChangedFile(
6371
6553
  diskFile,
6372
- importsOfFile(diskFile, path16__namespace.join(config.cwd, diskFile)),
6554
+ importsOfFile(diskFile, path17__namespace.join(config.cwd, diskFile)),
6373
6555
  unchangedScope,
6374
6556
  dependentResolver
6375
6557
  );
@@ -6387,7 +6569,7 @@ function validateSnapshot(configInput) {
6387
6569
  // own output directory as a set of files missing from the snapshot, so a correct
6388
6570
  // snapshot was reported as drifting.
6389
6571
  toolOwnedPaths: [config.outDir, config.tmpDir].map(
6390
- (directory) => path16__namespace.relative(config.cwd, path16__namespace.resolve(config.cwd, directory)).replace(/\\/g, "/")
6572
+ (directory) => path17__namespace.relative(config.cwd, path17__namespace.resolve(config.cwd, directory)).replace(/\\/g, "/")
6391
6573
  ).filter((relative15) => relative15.length > 0 && !relative15.startsWith(".."))
6392
6574
  });
6393
6575
  for (const diskFile of collection.files) {
@@ -6413,7 +6595,7 @@ function validateSnapshot(configInput) {
6413
6595
  }
6414
6596
  let diskHash;
6415
6597
  try {
6416
- diskHash = sha256Hex(fs15__namespace.readFileSync(path16__namespace.join(config.cwd, diskFile)));
6598
+ diskHash = sha256Hex(fs16__namespace.readFileSync(path17__namespace.join(config.cwd, diskFile)));
6417
6599
  } catch (err) {
6418
6600
  if (err.code === "ENOENT") {
6419
6601
  drift.missingOnDisk.push(diskFile);
@@ -6437,7 +6619,7 @@ function validateSnapshot(configInput) {
6437
6619
  }
6438
6620
  let statFailure = null;
6439
6621
  try {
6440
- fs15__namespace.statSync(confined);
6622
+ fs16__namespace.statSync(confined);
6441
6623
  } catch (err) {
6442
6624
  statFailure = err;
6443
6625
  }
@@ -6457,7 +6639,7 @@ function validateSnapshot(configInput) {
6457
6639
  ...Object.values(config.budgets.byLayer)
6458
6640
  );
6459
6641
  const partNames = /* @__PURE__ */ new Set();
6460
- const partsDir = path16__namespace.join(snapshotDir, "parts");
6642
+ const partsDir = path17__namespace.join(snapshotDir, "parts");
6461
6643
  for (const part of manifest.parts) {
6462
6644
  if (!part || typeof part.filename !== "string") continue;
6463
6645
  partNames.add(part.filename);
@@ -6472,7 +6654,7 @@ function validateSnapshot(configInput) {
6472
6654
  }
6473
6655
  let buffer;
6474
6656
  try {
6475
- buffer = fs15__namespace.readFileSync(partPath);
6657
+ buffer = fs16__namespace.readFileSync(partPath);
6476
6658
  } catch {
6477
6659
  drift.partIssues.push({ part: part.filename, issue: "missing from snapshot/parts" });
6478
6660
  continue;
@@ -6789,7 +6971,8 @@ function validateSnapshot(configInput) {
6789
6971
  );
6790
6972
  }
6791
6973
  }
6792
- if (manifest.budgets && manifest.budgets.maxPartBytes !== config.maxPartBytes) {
6974
+ const ceilingDerivedByMaxParts = (manifest.config?.maxParts ?? null) !== null;
6975
+ if (!ceilingDerivedByMaxParts && manifest.budgets && manifest.budgets.maxPartBytes !== config.maxPartBytes) {
6793
6976
  totalsMismatches.push(
6794
6977
  `budgets.maxPartBytes: manifest ${manifest.budgets.maxPartBytes} vs current ${config.maxPartBytes}`
6795
6978
  );
@@ -6818,6 +7001,7 @@ function validateSnapshot(configInput) {
6818
7001
  }
6819
7002
  const declaredArtifacts = [
6820
7003
  ["README.md", manifest.artifacts?.readme],
7004
+ ["PROMPT.md", manifest.artifacts?.prompt],
6821
7005
  ["reports/navigation.md", manifest.artifacts?.navigation],
6822
7006
  ["reports/project-tree.md", manifest.artifacts?.projectTree],
6823
7007
  ["reports/audit.md", manifest.artifacts?.audit],
@@ -6826,11 +7010,11 @@ function validateSnapshot(configInput) {
6826
7010
  ];
6827
7011
  for (const [key, artifact] of declaredArtifacts) {
6828
7012
  if (!artifact) continue;
6829
- const artifactPath = path16__namespace.join(snapshotDir, ...key.split("/"));
7013
+ const artifactPath = path17__namespace.join(snapshotDir, ...key.split("/"));
6830
7014
  let buffer;
6831
7015
  try {
6832
- if (!fs15__namespace.statSync(artifactPath).isFile()) throw new Error("not a regular file");
6833
- buffer = fs15__namespace.readFileSync(artifactPath);
7016
+ if (!fs16__namespace.statSync(artifactPath).isFile()) throw new Error("not a regular file");
7017
+ buffer = fs16__namespace.readFileSync(artifactPath);
6834
7018
  } catch {
6835
7019
  drift.partIssues.push({ part: key, issue: "declared artifact is missing" });
6836
7020
  continue;
@@ -6843,9 +7027,9 @@ function validateSnapshot(configInput) {
6843
7027
  for (const match of buffer.toString("utf8").matchAll(/\]\(([^)\s]+)\)/g)) {
6844
7028
  const target = match[1].split("#")[0];
6845
7029
  if (target.length === 0 || /^[a-z][a-z0-9+.-]*:/i.test(target)) continue;
6846
- const resolved = path16__namespace.resolve(snapshotDir, "reports", target);
6847
- const relative15 = path16__namespace.relative(snapshotDir, resolved);
6848
- if (relative15.startsWith("..") || path16__namespace.isAbsolute(relative15) || !fs15__namespace.existsSync(resolved)) {
7030
+ const resolved = path17__namespace.resolve(snapshotDir, "reports", target);
7031
+ const relative15 = path17__namespace.relative(snapshotDir, resolved);
7032
+ if (relative15.startsWith("..") || path17__namespace.isAbsolute(relative15) || !fs16__namespace.existsSync(resolved)) {
6849
7033
  drift.partIssues.push({
6850
7034
  part: key,
6851
7035
  issue: `links to ${maskedPath(target, config.secretRules)}, which does not exist in the snapshot`
@@ -6858,7 +7042,7 @@ function validateSnapshot(configInput) {
6858
7042
  if (sarifArtifact) {
6859
7043
  const sarifKey = "reports/audit.sarif";
6860
7044
  try {
6861
- const buffer = fs15__namespace.readFileSync(path16__namespace.join(snapshotDir, "reports", "audit.sarif"));
7045
+ const buffer = fs16__namespace.readFileSync(path17__namespace.join(snapshotDir, "reports", "audit.sarif"));
6862
7046
  if (sha256Hex(buffer) !== sarifArtifact.sha256 || buffer.length !== sarifArtifact.byteSize) {
6863
7047
  drift.partIssues.push({ part: sarifKey, issue: "artifact does not match its recorded digest" });
6864
7048
  }
@@ -7142,14 +7326,14 @@ function compareManifests(before, after, secretRules) {
7142
7326
  function loadManifest(target) {
7143
7327
  let isDirectory;
7144
7328
  try {
7145
- isDirectory = fs15__namespace.statSync(target).isDirectory();
7329
+ isDirectory = fs16__namespace.statSync(target).isDirectory();
7146
7330
  } catch {
7147
7331
  throw new Error(`No snapshot found at ${target}: the path does not exist.`);
7148
7332
  }
7149
- const manifestPath = isDirectory ? path16__namespace.join(target, "manifest.json") : target;
7333
+ const manifestPath = isDirectory ? path17__namespace.join(target, "manifest.json") : target;
7150
7334
  let raw;
7151
7335
  try {
7152
- raw = fs15__namespace.readFileSync(manifestPath, "utf8");
7336
+ raw = fs16__namespace.readFileSync(manifestPath, "utf8");
7153
7337
  } catch {
7154
7338
  throw new Error(`Could not read a manifest at ${manifestPath}.`);
7155
7339
  }
@@ -7382,10 +7566,10 @@ var LANGUAGE_BY_BASENAME = {
7382
7566
  };
7383
7567
  function detectLanguage(filePath) {
7384
7568
  const normalized = filePath.replace(/\\/g, "/");
7385
- const base = path16__namespace.posix.basename(normalized);
7569
+ const base = path17__namespace.posix.basename(normalized);
7386
7570
  if (LANGUAGE_BY_BASENAME[base]) return LANGUAGE_BY_BASENAME[base];
7387
7571
  if (base === ".env" || base.startsWith(".env.")) return "dotenv";
7388
- const ext = path16__namespace.posix.extname(base).toLowerCase();
7572
+ const ext = path17__namespace.posix.extname(base).toLowerCase();
7389
7573
  return LANGUAGE_BY_EXTENSION[ext] ?? "text";
7390
7574
  }
7391
7575
 
@@ -7427,13 +7611,13 @@ function describeMatcher(matcher) {
7427
7611
  return String(matcher);
7428
7612
  }
7429
7613
  function normalizeTarget(cwd, target) {
7430
- const resolvedCwd = path16__namespace.resolve(cwd);
7431
- const absolute = path16__namespace.resolve(resolvedCwd, target);
7432
- const relative15 = path16__namespace.relative(resolvedCwd, absolute);
7433
- if (relative15 === "" || relative15 === ".." || relative15.startsWith(`..${path16__namespace.sep}`) || path16__namespace.isAbsolute(relative15)) {
7614
+ const resolvedCwd = path17__namespace.resolve(cwd);
7615
+ const absolute = path17__namespace.resolve(resolvedCwd, target);
7616
+ const relative15 = path17__namespace.relative(resolvedCwd, absolute);
7617
+ if (relative15 === "" || relative15 === ".." || relative15.startsWith(`..${path17__namespace.sep}`) || path17__namespace.isAbsolute(relative15)) {
7434
7618
  return { relative: target.replace(/\\/g, "/"), outsideRoot: true };
7435
7619
  }
7436
- return { relative: relative15.split(path16__namespace.sep).join("/"), outsideRoot: false };
7620
+ return { relative: relative15.split(path17__namespace.sep).join("/"), outsideRoot: false };
7437
7621
  }
7438
7622
  function findRuleMatch(rules, relativePath) {
7439
7623
  return rules.find(
@@ -7452,9 +7636,9 @@ function findRecordedAncestor(skipped, relative15, maskedPath2) {
7452
7636
  return nearest;
7453
7637
  }
7454
7638
  function readManifest2(config) {
7455
- const manifestPath = path16__namespace.resolve(config.cwd, config.outDir, "manifest.json");
7639
+ const manifestPath = path17__namespace.resolve(config.cwd, config.outDir, "manifest.json");
7456
7640
  try {
7457
- return JSON.parse(fs15__namespace.readFileSync(manifestPath, "utf8"));
7641
+ return JSON.parse(fs16__namespace.readFileSync(manifestPath, "utf8"));
7458
7642
  } catch {
7459
7643
  return null;
7460
7644
  }
@@ -7472,10 +7656,10 @@ function explainPath(config, target) {
7472
7656
  detail: "path resolves outside the configured repository root and was not inspected"
7473
7657
  };
7474
7658
  }
7475
- const absolute = path16__namespace.join(config.cwd, relative15);
7659
+ const absolute = path17__namespace.join(config.cwd, relative15);
7476
7660
  const result = {
7477
7661
  path: maskedPath2,
7478
- exists: fs15__namespace.existsSync(absolute),
7662
+ exists: fs16__namespace.existsSync(absolute),
7479
7663
  included: false
7480
7664
  };
7481
7665
  const collection = collectFiles(config.cwd, {
@@ -7489,7 +7673,7 @@ function explainPath(config, target) {
7489
7673
  // Same exclusion `generate` applies, so `explain` never says "not-discovered" about a file
7490
7674
  // that is only missing because the walker dropped the tool's own output directory.
7491
7675
  toolOwnedPaths: [config.outDir, config.tmpDir].map(
7492
- (directory) => path16__namespace.relative(config.cwd, path16__namespace.resolve(config.cwd, directory)).replace(/\\/g, "/")
7676
+ (directory) => path17__namespace.relative(config.cwd, path17__namespace.resolve(config.cwd, directory)).replace(/\\/g, "/")
7493
7677
  ).filter((relative16) => relative16.length > 0 && !relative16.startsWith(".."))
7494
7678
  });
7495
7679
  if (!collection.files.includes(relative15)) {
@@ -7554,7 +7738,7 @@ function explainPath(config, target) {
7554
7738
  }
7555
7739
  let sizeOnDisk = null;
7556
7740
  try {
7557
- sizeOnDisk = fs15__namespace.statSync(absolute).size;
7741
+ sizeOnDisk = fs16__namespace.statSync(absolute).size;
7558
7742
  } catch {
7559
7743
  sizeOnDisk = null;
7560
7744
  }
@@ -7564,10 +7748,10 @@ function explainPath(config, target) {
7564
7748
  result.detail = "binary content; generate skips it and records `binary` in manifest.skipped[]";
7565
7749
  return result;
7566
7750
  }
7567
- if (fs15__namespace.existsSync(absolute) && fs15__namespace.statSync(absolute).isFile()) {
7751
+ if (fs16__namespace.existsSync(absolute) && fs16__namespace.statSync(absolute).isFile()) {
7568
7752
  let buffer;
7569
7753
  try {
7570
- buffer = fs15__namespace.readFileSync(absolute);
7754
+ buffer = fs16__namespace.readFileSync(absolute);
7571
7755
  } catch (err) {
7572
7756
  result.included = false;
7573
7757
  result.reason = "read-error";
@@ -7693,15 +7877,15 @@ function canonicalIgnorePattern(line) {
7693
7877
  function appendGitignoreEntries(cwd, entries) {
7694
7878
  const wanted = [...new Set(entries)].filter((entry) => entry.trim().length > 0);
7695
7879
  if (wanted.length === 0) return { added: [], note: null };
7696
- const ignorePath = path16__namespace.join(cwd, ".gitignore");
7880
+ const ignorePath = path17__namespace.join(cwd, ".gitignore");
7697
7881
  const manual = `Add ${wanted.map((entry) => `"${entry}"`).join(" and ")} to your .gitignore yourself.`;
7698
7882
  let decoded = { text: "", bom: Buffer.alloc(0), encoding: "utf8" };
7699
7883
  try {
7700
- if (fs15__namespace.existsSync(ignorePath)) {
7701
- if (fs15__namespace.statSync(ignorePath).isDirectory()) {
7884
+ if (fs16__namespace.existsSync(ignorePath)) {
7885
+ if (fs16__namespace.statSync(ignorePath).isDirectory()) {
7702
7886
  return { added: [], note: `${ignorePath} is a directory, so it was not updated. ${manual}` };
7703
7887
  }
7704
- const read = decodeGitignore(fs15__namespace.readFileSync(ignorePath));
7888
+ const read = decodeGitignore(fs16__namespace.readFileSync(ignorePath));
7705
7889
  if (read === null) {
7706
7890
  return {
7707
7891
  added: [],
@@ -7723,7 +7907,7 @@ function appendGitignoreEntries(cwd, entries) {
7723
7907
  const newline = existing.includes("\r\n") ? "\r\n" : "\n";
7724
7908
  const prefix = existing.length === 0 || existing.endsWith("\n") ? "" : newline;
7725
7909
  try {
7726
- fs15__namespace.writeFileSync(
7910
+ fs16__namespace.writeFileSync(
7727
7911
  ignorePath,
7728
7912
  encodeGitignore(decoded, `${existing}${prefix}${added.join(newline)}${newline}`)
7729
7913
  );
@@ -7733,7 +7917,7 @@ function appendGitignoreEntries(cwd, entries) {
7733
7917
  return { added, note: null };
7734
7918
  }
7735
7919
  function gitignorePath(cwd, filePath) {
7736
- return path16__namespace.relative(cwd, filePath).split(path16__namespace.sep).join("/");
7920
+ return path17__namespace.relative(cwd, filePath).split(path17__namespace.sep).join("/");
7737
7921
  }
7738
7922
 
7739
7923
  // src/wizard/config-template.ts
@@ -7746,6 +7930,7 @@ var DEFAULT_ANSWERS = {
7746
7930
  sarif: false,
7747
7931
  artifacts: {
7748
7932
  readme: true,
7933
+ prompt: true,
7749
7934
  manifest: true,
7750
7935
  parts: true,
7751
7936
  navigation: true,
@@ -7862,6 +8047,7 @@ function renderConfig(answers) {
7862
8047
  // \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
7863
8048
  artifacts: {
7864
8049
  readme: ${artifacts.readme}, // README.md
8050
+ prompt: ${artifacts.prompt}, // PROMPT.md \u2014 the instruction sheet a model is given
7865
8051
  manifest: ${artifacts.manifest}, // manifest.json \u2014 required by validate and report
7866
8052
  parts: ${artifacts.parts}, // parts/part-XXX.md
7867
8053
  navigation: ${artifacts.navigation}, // reports/navigation.md
@@ -7877,6 +8063,15 @@ function renderConfig(answers) {
7877
8063
  includeMonolith: ${artifacts.monolith},
7878
8064
 
7879
8065
  // \u2500\u2500 Advanced \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\u2500
8066
+ // Files your destination accepts in one message, used by PROMPT.md to plan the delivery.
8067
+ // attachmentSlots: 10,
8068
+ // Experimental: grow the per-part budget until the snapshot fits this many parts, instead of
8069
+ // adding a part as the code grows. The plan in PROMPT.md becomes a fixed-length attachment list.
8070
+ // maxParts: 10,
8071
+ // The owner-written half of PROMPT.md: Stakes, The system, What came before, The bar, Calibration.
8072
+ // brief: "docs/brief.md",
8073
+ // Which job the brief is written for: audit, review or explain.
8074
+ // promptTask: "audit",
7880
8075
  // afterGenerate: (manifest) => { /* write your own artifact */ }
7881
8076
  hooks: {},
7882
8077
  };
@@ -8271,7 +8466,7 @@ function parsePackageJson(raw) {
8271
8466
  }
8272
8467
  function readPackageJson(cwd) {
8273
8468
  try {
8274
- return parsePackageJson(fs15__namespace.readFileSync(path16__namespace.join(cwd, "package.json"), "utf8"));
8469
+ return parsePackageJson(fs16__namespace.readFileSync(path17__namespace.join(cwd, "package.json"), "utf8"));
8275
8470
  } catch {
8276
8471
  return null;
8277
8472
  }
@@ -8308,7 +8503,7 @@ function artifactAnswers(options) {
8308
8503
  }
8309
8504
  function topLevelDirs(cwd) {
8310
8505
  try {
8311
- return fs15__namespace.readdirSync(cwd, { withFileTypes: true }).filter((entry) => entry.isDirectory() && !entry.name.startsWith(".") && entry.name !== "node_modules").map((entry) => entry.name).sort();
8506
+ return fs16__namespace.readdirSync(cwd, { withFileTypes: true }).filter((entry) => entry.isDirectory() && !entry.name.startsWith(".") && entry.name !== "node_modules").map((entry) => entry.name).sort();
8312
8507
  } catch {
8313
8508
  return [];
8314
8509
  }
@@ -8323,7 +8518,7 @@ function writeFileOrExplain(target, content) {
8323
8518
  try {
8324
8519
  let stats = null;
8325
8520
  try {
8326
- stats = fs15__namespace.lstatSync(target);
8521
+ stats = fs16__namespace.lstatSync(target);
8327
8522
  } catch {
8328
8523
  stats = null;
8329
8524
  }
@@ -8338,12 +8533,12 @@ function writeFileOrExplain(target, content) {
8338
8533
  );
8339
8534
  }
8340
8535
  const temporary = `${target}.tmp-${process.pid}-${Date.now()}`;
8341
- fs15__namespace.writeFileSync(temporary, content, { encoding: "utf8", flag: "wx" });
8536
+ fs16__namespace.writeFileSync(temporary, content, { encoding: "utf8", flag: "wx" });
8342
8537
  try {
8343
- fs15__namespace.renameSync(temporary, target);
8538
+ fs16__namespace.renameSync(temporary, target);
8344
8539
  } catch (err) {
8345
8540
  try {
8346
- fs15__namespace.unlinkSync(temporary);
8541
+ fs16__namespace.unlinkSync(temporary);
8347
8542
  } catch {
8348
8543
  }
8349
8544
  throw err;
@@ -8391,19 +8586,19 @@ function serializePackageJson(raw, value) {
8391
8586
  return `${bom}${text2}${raw.endsWith("\n") ? crlf ? "\r\n" : "\n" : ""}`;
8392
8587
  }
8393
8588
  function updatePackageJson(cwd, notes) {
8394
- const packagePath = path16__namespace.join(cwd, "package.json");
8589
+ const packagePath = path17__namespace.join(cwd, "package.json");
8395
8590
  const unchanged = {
8396
8591
  scripts: [],
8397
8592
  dependency: { name: GENERATOR_NAME, range: null, added: false }
8398
8593
  };
8399
- if (!fs15__namespace.existsSync(packagePath)) {
8594
+ if (!fs16__namespace.existsSync(packagePath)) {
8400
8595
  notes.push("No package.json found, so npm scripts and the devDependency were not added.");
8401
8596
  return unchanged;
8402
8597
  }
8403
8598
  let raw;
8404
8599
  let parsed;
8405
8600
  try {
8406
- raw = fs15__namespace.readFileSync(packagePath, "utf8");
8601
+ raw = fs16__namespace.readFileSync(packagePath, "utf8");
8407
8602
  parsed = parsePackageJson(raw);
8408
8603
  } catch {
8409
8604
  notes.push("Could not parse package.json; npm scripts and the devDependency were not added.");
@@ -8478,8 +8673,8 @@ function gitignoreEntriesFor(cwd, outDir, tmpDir) {
8478
8673
  const entries = [];
8479
8674
  for (const directory of [outDir, tmpDir]) {
8480
8675
  if (directory === null) continue;
8481
- const relative15 = path16__namespace.relative(cwd, path16__namespace.resolve(cwd, directory)).replace(/\\/g, "/");
8482
- if (relative15 === "" || relative15 === "." || relative15.startsWith("..") || path16__namespace.isAbsolute(relative15)) {
8676
+ const relative15 = path17__namespace.relative(cwd, path17__namespace.resolve(cwd, directory)).replace(/\\/g, "/");
8677
+ if (relative15 === "" || relative15 === "." || relative15.startsWith("..") || path17__namespace.isAbsolute(relative15)) {
8483
8678
  continue;
8484
8679
  }
8485
8680
  entries.push(`/${relative15}/`);
@@ -8567,6 +8762,7 @@ async function runInit(options) {
8567
8762
  let lastScope = "all";
8568
8763
  const artifactChoices = [
8569
8764
  { value: "readme", label: "README.md", hint: "orientation page" },
8765
+ { value: "prompt", label: "PROMPT.md", hint: "instruction sheet for the model" },
8570
8766
  { value: "manifest", label: "manifest.json", hint: "required by validate and report" },
8571
8767
  { value: "parts", label: "parts/", hint: "the code payload" },
8572
8768
  { value: "navigation", label: "reports/navigation.md", hint: "file \u2192 part index" },
@@ -8730,7 +8926,7 @@ async function runInit(options) {
8730
8926
  const configText = renderConfig(answers);
8731
8927
  const preferredName = chooseConfigFileName(options.cwd);
8732
8928
  const presentConfigs = CONFIG_CANDIDATES.filter(
8733
- (name) => fs15__namespace.existsSync(path16__namespace.join(options.cwd, name))
8929
+ (name) => fs16__namespace.existsSync(path17__namespace.join(options.cwd, name))
8734
8930
  );
8735
8931
  const present = presentConfigs[0] ?? null;
8736
8932
  if (presentConfigs.length > 1) {
@@ -8739,7 +8935,7 @@ async function runInit(options) {
8739
8935
  );
8740
8936
  }
8741
8937
  const configName = present !== null && options.force ? present : preferredName;
8742
- const configPath = path16__namespace.join(options.cwd, configName);
8938
+ const configPath = path17__namespace.join(options.cwd, configName);
8743
8939
  const reused = present !== null && options.force !== true && options.reuseConfig === true;
8744
8940
  if (reused) notes.push(`Kept the existing ${present} instead of writing a new one.`);
8745
8941
  if (options.dryRun) {
@@ -8773,7 +8969,7 @@ async function runInit(options) {
8773
8969
  'package.json already defines a "snapshot" config. Remove that key, or re-run with --force to write a config file that takes precedence over it.'
8774
8970
  );
8775
8971
  }
8776
- if (fs15__namespace.existsSync(configPath) && !options.force && !reused) {
8972
+ if (fs16__namespace.existsSync(configPath) && !options.force && !reused) {
8777
8973
  throw new Error(`${configName} already exists. Re-run with --force to replace it.`);
8778
8974
  }
8779
8975
  if (!reused) writeFileOrExplain(configPath, configText);
@@ -8799,9 +8995,9 @@ async function runInit(options) {
8799
8995
  };
8800
8996
  }
8801
8997
  function describeTarget(cwd) {
8802
- const relative15 = path16__namespace.relative(process.cwd(), cwd);
8998
+ const relative15 = path17__namespace.relative(process.cwd(), cwd);
8803
8999
  if (relative15 === "") return "this directory";
8804
- if (relative15.startsWith("..") || path16__namespace.isAbsolute(relative15)) return cwd;
9000
+ if (relative15.startsWith("..") || path17__namespace.isAbsolute(relative15)) return cwd;
8805
9001
  return relative15;
8806
9002
  }
8807
9003
  function firstRunMessage(reason, cwd) {
@@ -8825,7 +9021,7 @@ function planFirstRun(facts) {
8825
9021
  var NOT_CONTENT = /* @__PURE__ */ new Set([".git", ".hg", ".svn", ".bzr", ".DS_Store", "Thumbs.db"]);
8826
9022
  function isEffectivelyEmpty(cwd) {
8827
9023
  try {
8828
- return fs15__namespace.readdirSync(cwd).every((entry) => NOT_CONTENT.has(entry));
9024
+ return fs16__namespace.readdirSync(cwd).every((entry) => NOT_CONTENT.has(entry));
8829
9025
  } catch {
8830
9026
  return false;
8831
9027
  }
@@ -8833,7 +9029,7 @@ function isEffectivelyEmpty(cwd) {
8833
9029
  function hasPriorSnapshot(cwd, outDir) {
8834
9030
  let parsed;
8835
9031
  try {
8836
- parsed = JSON.parse(fs15__namespace.readFileSync(path16__namespace.join(cwd, outDir, ".codebase-snapshot"), "utf8"));
9032
+ parsed = JSON.parse(fs16__namespace.readFileSync(path17__namespace.join(cwd, outDir, ".codebase-snapshot"), "utf8"));
8837
9033
  } catch {
8838
9034
  return false;
8839
9035
  }
@@ -9660,10 +9856,509 @@ function generateNavigation(manifest) {
9660
9856
  return lines.join("\n");
9661
9857
  }
9662
9858
 
9859
+ // src/generator/prompt.ts
9860
+ var MAX_PART_ROWS = 16;
9861
+ var MAX_LAYER_ROWS = 8;
9862
+ var MAX_INCOMPLETE_ROWS = 50;
9863
+ var MAX_CENTRAL_FILES = 5;
9864
+ var MAX_ENTRY_POINTS = 4;
9865
+ var MAX_LARGEST_FILES = 3;
9866
+ var partWord = (count) => count === 1 ? "part" : "parts";
9867
+ var UNLIMITED_SLOTS = 0;
9868
+ var ENTRY_POINT = /(^|\/)(index|cli|main|bin|server|app|mod)\.[cm]?[jt]sx?$/;
9869
+ var TEST_PATH = /(^|\/)(tests?|__tests__)\//;
9870
+ var TEST_FILE = /\.(test|spec)\.[^.]+$/;
9871
+ function generatePrompt(manifest, artifacts, context = {}) {
9872
+ const slots = context.slots ?? DEFAULT_ATTACHMENT_SLOTS;
9873
+ const task = context.task ?? "audit";
9874
+ const history = context.history ?? [];
9875
+ const overview = context.overview ?? { releases: [] };
9876
+ const brief = context.brief;
9877
+ const wrote = (name) => artifacts?.[name] !== false;
9878
+ const code = (value) => inlineCode(escapeControls(value));
9879
+ const hasOwnerHistory = (brief?.history ?? "").trim().length > 0;
9880
+ const lines = [
9881
+ "# PROMPT.md",
9882
+ "",
9883
+ "The brief and the apparatus for this snapshot. Paste this file first, then the parts it names.",
9884
+ "",
9885
+ "It is generated rather than written once: the system map, the omissions, the fingerprint and",
9886
+ "the history below are read from `manifest.json` and this repository, so they describe this run.",
9887
+ "Regenerate it after the code moves.",
9888
+ "",
9889
+ "---",
9890
+ "",
9891
+ "```text",
9892
+ "You are working on a codebase you cannot clone, run or grep. Everything you know about it comes",
9893
+ "from the snapshot that follows this instruction. Where these notes and the snapshot disagree,",
9894
+ "the snapshot is what exists.",
9895
+ ""
9896
+ ];
9897
+ if (brief?.preamble !== void 0) lines.push(brief.preamble, "");
9898
+ lines.push(...jobSection(task, history.length > 0 || hasOwnerHistory), "");
9899
+ lines.push(...stakesSection(brief, code));
9900
+ lines.push(...haveSection(wrote), "");
9901
+ lines.push(...whatThisIsSection(overview), "");
9902
+ lines.push(...systemSection(manifest, code, brief), "");
9903
+ lines.push(...historySection(history, brief, code), "");
9904
+ lines.push(...barSection(brief, code), "");
9905
+ lines.push(...coverageSection(manifest, code, wrote("audit")), "");
9906
+ lines.push(...answerSection(), "");
9907
+ lines.push(...calibrationSection(brief, code), "");
9908
+ lines.push(...ownerNotesSection(brief, code));
9909
+ lines.push(...snapshotSection(manifest, code), "");
9910
+ lines.push(...deliverySection(manifest, wrote("parts"), slots));
9911
+ lines.push(
9912
+ "## Your task",
9913
+ "",
9914
+ "<replace with the question, the area to review, or the subsystem to audit>",
9915
+ "```"
9916
+ );
9917
+ lines.push(
9918
+ "",
9919
+ "---",
9920
+ "",
9921
+ "## Why this file exists",
9922
+ "",
9923
+ "Parts on their own are a dump: the model receives text, has no idea what was left out of it,",
9924
+ "and fills the gap by invention. A brief on its own is a wish list: it cannot say which files",
9925
+ "are present, which are partial or which part holds what. This file is both halves, and the",
9926
+ "facts in it move with the snapshot.",
9927
+ "",
9928
+ "## Keeping it true",
9929
+ "",
9930
+ "- It is one of the artifacts recorded in `manifest.json` under `artifacts.prompt`, so deleting",
9931
+ " or editing `PROMPT.md` makes `snapshot validate` fail.",
9932
+ "- `--skip-artifacts prompt`, or `artifacts: { prompt: false }` in the config, turns it off.",
9933
+ "- The history section disappears when git cannot be read, rather than being invented.",
9934
+ "- If the code moves, regenerate. A brief naming the previous run parts is worse than no",
9935
+ " brief, because it reads as current.",
9936
+ ""
9937
+ );
9938
+ return lines.join("\n");
9939
+ }
9940
+ function haveSection(wrote) {
9941
+ const out = ["## What you have", ""];
9942
+ const bullets = [];
9943
+ if (wrote("readme")) {
9944
+ bullets.push("- `README.md` - orientation: metrics, the part table, and the fingerprint.");
9945
+ }
9946
+ if (wrote("manifest")) {
9947
+ bullets.push(
9948
+ "- `manifest.json` - the index. Per file: `relativePath`, `layer`, `kind`, `language`,",
9949
+ " `part`, `sha256`, `inclusionMode`, `truncationReason`, `omittedRanges`. It also carries",
9950
+ " every excluded path under `skipped[]` with its reason, and `incomplete[]`, which names",
9951
+ " every included file whose emitted body is not the whole file."
9952
+ );
9953
+ }
9954
+ if (wrote("navigation")) {
9955
+ bullets.push("- `reports/navigation.md` - file to part. Locate here before you read anything.");
9956
+ }
9957
+ if (wrote("projectTree")) {
9958
+ bullets.push("- `reports/project-tree.md` - the directory shape of what was included.");
9959
+ }
9960
+ if (wrote("audit")) {
9961
+ bullets.push(
9962
+ "- `reports/audit.md` - secret findings, the files whose lines were redacted, large files,",
9963
+ " parse diagnostics and the git state the snapshot was taken from."
9964
+ );
9965
+ }
9966
+ if (wrote("parts")) {
9967
+ bullets.push(
9968
+ "- `parts/part-NNN.md` - the code itself, split to a fixed byte budget. Each part states its",
9969
+ " own number, the files it contains, and the fingerprint it was built from."
9970
+ );
9971
+ }
9972
+ if (wrote("monolith")) {
9973
+ bullets.push(
9974
+ "- `full-codebase.json` and `full-codebase.md` - the entire payload in one file each.",
9975
+ " Where they are present, they supersede the parts: nothing was left out of them."
9976
+ );
9977
+ }
9978
+ if (bullets.length === 0) {
9979
+ bullets.push(
9980
+ "- Nothing but this brief: every code artifact was disabled for this run. Ask for a snapshot",
9981
+ " generated with the artifacts you need, and do not answer from memory."
9982
+ );
9983
+ }
9984
+ out.push(...bullets);
9985
+ return out;
9986
+ }
9987
+ function systemSection(manifest, code, brief) {
9988
+ const out = ["## The system", ""];
9989
+ if (brief?.system !== void 0) {
9990
+ out.push(...ownerBlock(brief.system, brief.path, code), "", "What the index records:", "");
9991
+ }
9992
+ const layers = Object.entries(manifest.layers).sort((a, b) => b[1] - a[1] || a[0].localeCompare(b[0]));
9993
+ if (layers.length > 0) {
9994
+ const shown = layers.slice(0, MAX_LAYER_ROWS).map(([name, count]) => code(name) + " " + formatNumber(count));
9995
+ const rest = layers.length > MAX_LAYER_ROWS ? ", and " + formatNumber(layers.length - MAX_LAYER_ROWS) + " more" : "";
9996
+ out.push("- Layers, by file count: " + shown.join(", ") + rest + ".");
9997
+ }
9998
+ const central = manifest.indexes.imports.centralFiles;
9999
+ if (central.length > 0) {
10000
+ const shown = central.slice(0, MAX_CENTRAL_FILES).map((entry) => code(entry.path) + " (" + formatNumber(entry.importedByCount) + ")").join(", ");
10001
+ out.push(
10002
+ "- Load-bearing modules, by how many files import them: " + shown + ".",
10003
+ " A change here reaches the most call sites; read it before judging anything that uses it."
10004
+ );
10005
+ }
10006
+ const entryPoints = manifest.files.map((file) => file.relativePath).filter((path23) => ENTRY_POINT.test(path23)).sort((a, b) => a.split("/").length - b.split("/").length || a.length - b.length).slice(0, MAX_ENTRY_POINTS);
10007
+ out.push(
10008
+ 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"
10009
+ );
10010
+ if (entryPoints.length === 0) out.push(" starts, and the call graph in `manifest.json` is the map.");
10011
+ const routes = manifest.indexes.routes.length;
10012
+ const handlers = manifest.indexes.handlers.length;
10013
+ const components = manifest.indexes.components.length;
10014
+ const routesShown = manifest.indexes.routes.slice(0, 4).map((route) => code(route.path));
10015
+ const componentsShown = manifest.indexes.components.slice(0, 4).map((entry) => code(entry.path));
10016
+ if (routes + handlers + components === 0) {
10017
+ out.push(
10018
+ "- No routes, handlers or UI components were recorded: this snapshot indexes no HTTP or",
10019
+ " component surface. Do not go looking for one, and do not infer one from a file name."
10020
+ );
10021
+ } else {
10022
+ const parts = [];
10023
+ if (routes > 0) parts.push(formatNumber(routes) + " route(s), e.g. " + routesShown.join(", "));
10024
+ if (handlers > 0) parts.push(formatNumber(handlers) + " handler(s)");
10025
+ if (components > 0) parts.push(formatNumber(components) + " component(s), e.g. " + componentsShown.join(", "));
10026
+ out.push("- Surfaces the index found: " + parts.join("; ") + ".");
10027
+ }
10028
+ const largest = [...manifest.files].sort((a, b) => b.includedBytes - a.includedBytes).slice(0, MAX_LARGEST_FILES);
10029
+ if (largest.length > 0) {
10030
+ out.push(
10031
+ "- Largest files: " + largest.map((file) => code(file.relativePath) + " (" + formatNumber(Math.round(file.includedBytes / 1024)) + " KB)").join(", ") + "."
10032
+ );
10033
+ }
10034
+ const tests = manifest.files.filter(
10035
+ (file) => TEST_PATH.test(file.relativePath) || TEST_FILE.test(file.relativePath)
10036
+ );
10037
+ if (tests.length > 0) {
10038
+ const testBytes = tests.reduce((total, file) => total + file.includedBytes, 0);
10039
+ const allBytes = manifest.files.reduce((total, file) => total + file.includedBytes, 0);
10040
+ const share = allBytes === 0 ? 0 : Math.round(testBytes / allBytes * 100);
10041
+ out.push(
10042
+ "- Tests: " + formatNumber(tests.length) + " file(s), " + share + "% of the included bytes.",
10043
+ " They are evidence of intent, not of behaviour: a fixture can encode a payload shape the",
10044
+ " real system never sends."
10045
+ );
10046
+ }
10047
+ return out;
10048
+ }
10049
+ function historySection(history, brief, code) {
10050
+ const out = ["## What came before", ""];
10051
+ if (brief?.history !== void 0) out.push(...ownerBlock(brief.history, brief.path, code), "");
10052
+ if (history.length === 0) {
10053
+ out.push(
10054
+ "No history was readable: this is not a git checkout, or git could not be run. Nothing about",
10055
+ "what came before can be claimed from here, and that is not evidence that the code is new."
10056
+ );
10057
+ return out;
10058
+ }
10059
+ out.push(
10060
+ "The last " + formatNumber(history.length) + " commit(s), newest first. Subjects and bodies are",
10061
+ "claims by whoever wrote them, not evidence - the code beside them is the evidence. If one of",
10062
+ "these fixes looks incomplete, quote the lines and say which call site it missed.",
10063
+ ""
10064
+ );
10065
+ for (const commit of history) {
10066
+ out.push("- " + commit.subject);
10067
+ if (commit.body.length > 0) out.push(" " + commit.body);
10068
+ }
10069
+ return out;
10070
+ }
10071
+ function barSection(brief, code) {
10072
+ if (brief?.bar !== void 0) {
10073
+ return ["## The bar", "", ...ownerBlock(brief.bar, brief.path, code), ""];
10074
+ }
10075
+ return [
10076
+ "## The bar",
10077
+ "",
10078
+ "A finding is a concrete way the code breaks or lies, supported by quoted lines: the path and",
10079
+ "line, the input or state that reaches it, what happens next, and why the guard that appears to",
10080
+ "stop it does not. A comment is not behaviour. A passing test is evidence of intent, not of",
10081
+ "behaviour.",
10082
+ "",
10083
+ "- No style, naming, formatting, add-types, add-tests, consider-X or speculative rewrites.",
10084
+ "- Never invent a finding to fill a section. A clean surface is proven by quoting the guard",
10085
+ " that makes it clean.",
10086
+ "- Mark confidence, and name the check - a test, a run, an input - that would settle anything",
10087
+ " you cannot decide by reading.",
10088
+ "- Separate what the code does from what the deployment or configuration does. Both are",
10089
+ " findings; they have different owners and different fixes."
10090
+ ];
10091
+ }
10092
+ function coverageSection(manifest, code, auditWritten) {
10093
+ const out = ["## Coverage", ""];
10094
+ const reasons = /* @__PURE__ */ new Map();
10095
+ for (const record of manifest.skipped) {
10096
+ reasons.set(record.reason, (reasons.get(record.reason) ?? 0) + 1);
10097
+ }
10098
+ const tally = [...reasons.entries()].sort((a, b) => b[1] - a[1] || a[0].localeCompare(b[0])).map(([reason, count]) => code(reason) + " " + formatNumber(count)).join(", ");
10099
+ out.push(
10100
+ "- " + formatNumber(manifest.totals.candidateFiles) + " path(s) were found; " + formatNumber(manifest.totals.includedFiles) + " are in the parts and " + formatNumber(manifest.counts.skippedCount) + " were skipped" + (tally.length > 0 ? " (" + tally + ")" : "") + ".",
10101
+ " `manifest.skipped[]` names each one and why. An absent path is not a clean path."
10102
+ );
10103
+ out.push(...incompleteSection(manifest, code));
10104
+ out.push(...redactionSection(manifest, auditWritten));
10105
+ out.push(
10106
+ "- Everything unseen is unread, never clean. If you were given only some of the parts, say",
10107
+ " which ones are missing before you answer. A file the index names but the parts do not carry",
10108
+ " is an input defect, not a code finding - report it as one."
10109
+ );
10110
+ return out;
10111
+ }
10112
+ function answerSection() {
10113
+ return [
10114
+ "## What a useful answer contains",
10115
+ "",
10116
+ "- An opening line, filled from This snapshot below:",
10117
+ "",
10118
+ " snapshot <fingerprint> generated <generatedAt>",
10119
+ "",
10120
+ "- What you read and what you did not, named by path or by part.",
10121
+ "- Findings ordered by consequence, each with the lines quoted.",
10122
+ "- The checks or attacks that failed, and the line or guard that blocked them. A failed attack",
10123
+ " is how anyone knows an invariant is real rather than asserted.",
10124
+ "- What you retracted after re-reading.",
10125
+ "- What only a run, a test or a host can settle, and the check that would settle each.",
10126
+ "- One paragraph on the failure you would bet on next.",
10127
+ "- A closing line: Needed but not received: <paths>, or none. That line is not decoration -",
10128
+ " an invented function is indistinguishable from a real one, and this is where you name",
10129
+ " the gap you filled by asking instead of guessing."
10130
+ ];
10131
+ }
10132
+ function calibrationSection(brief, code) {
10133
+ if (brief?.calibration !== void 0) {
10134
+ return ["## Calibration", "", ...ownerBlock(brief.calibration, brief.path, code), ""];
10135
+ }
10136
+ return [
10137
+ "## Calibration",
10138
+ "",
10139
+ "The findings that matter here do not crash. They look like:",
10140
+ "",
10141
+ "- a guard applied at one call site and not its twin - the route checks, the timer does not;",
10142
+ "- a budget shorter than the work it guards, so the caller gives up while the work continues;",
10143
+ "- a success flag that means the call returned, consumed as the change happened;",
10144
+ "- a document that describes a different run than the one beside it;",
10145
+ "- a default that fabricates a number when the measurement failed.",
10146
+ "",
10147
+ "None of these throw. All are invisible in a summary."
10148
+ ];
10149
+ }
10150
+ function jobSection(task, hasHistory) {
10151
+ const out = ["## The job", ""];
10152
+ if (task === "audit") {
10153
+ out.push(
10154
+ "Find what is still wrong or will break. How you read the code is yours to decide - by",
10155
+ "subsystem, by data flow, by the invariants you derive yourself. What you owe in return is an",
10156
+ "honest account of what you covered and what you did not.",
10157
+ ""
10158
+ );
10159
+ if (hasHistory) {
10160
+ out.push(
10161
+ "Another pass of the same findings is worth nothing. This repository carries a record of",
10162
+ "what was already fixed, below. Verify that those fixes hold instead of rediscovering them,",
10163
+ "and treat a variant of one at a different call site as a new finding."
10164
+ );
10165
+ } else {
10166
+ out.push(
10167
+ "Another pass of the same findings is worth nothing, but no earlier round is readable here,",
10168
+ "so you cannot tell what has already been tried. Do not assume this is the first attempt."
10169
+ );
10170
+ }
10171
+ out.push(
10172
+ "",
10173
+ "If the task at the end asks for something narrower - explain a file, review a change, answer",
10174
+ "a question - that task wins. The standard and the coverage duty below still apply to it."
10175
+ );
10176
+ } else if (task === "review") {
10177
+ out.push(
10178
+ "Review the change or the area named in the task against this snapshot. Report what breaks,",
10179
+ "what the change claims but does not do, and what a reader would believe that the code does",
10180
+ "not support. Restating the diff is not a review; the standard and the coverage duty below",
10181
+ "still apply."
10182
+ );
10183
+ } else {
10184
+ out.push(
10185
+ "Explain how the part of the system named in the task works: the data flow, the boundaries",
10186
+ "and the invariants it depends on. Cite the lines. If the snapshot does not contain what you",
10187
+ "need, say which file you need rather than reconstructing it from the shape of the names."
10188
+ );
10189
+ }
10190
+ return out;
10191
+ }
10192
+ function stakesSection(brief, code) {
10193
+ if (brief?.stakes === void 0) return [];
10194
+ return ["## Stakes", "", ...ownerBlock(brief.stakes, brief.path, code), ""];
10195
+ }
10196
+ function whatThisIsSection(overview) {
10197
+ const body = [];
10198
+ if (overview.description !== void 0) {
10199
+ body.push("- Declared in `package.json`: " + overview.description);
10200
+ }
10201
+ if (overview.summary !== void 0) {
10202
+ body.push("- From the `README.md` first paragraph: " + overview.summary);
10203
+ }
10204
+ if (overview.releases.length > 0) {
10205
+ body.push("- Most recent releases: " + overview.releases.join("; ") + ".");
10206
+ }
10207
+ if (body.length === 0) return [];
10208
+ return [
10209
+ "## What this is",
10210
+ "",
10211
+ ...body,
10212
+ "",
10213
+ "Those are the project's own claims, not evidence about the code.",
10214
+ ""
10215
+ ];
10216
+ }
10217
+ function ownerNotesSection(brief, code) {
10218
+ if (brief === void 0 || brief.notes.length === 0) return [];
10219
+ const out = ["## Owner notes", ""];
10220
+ for (const note of brief.notes) {
10221
+ out.push("### " + note.heading, "", ...ownerBlock(note.body, brief.path, code), "");
10222
+ }
10223
+ return out;
10224
+ }
10225
+ function ownerBlock(text2, path23, code) {
10226
+ return ["> Written by the project owner in " + code(path23) + ", not generated.", "", text2];
10227
+ }
10228
+ function snapshotSection(manifest, code) {
10229
+ const out = ["## This snapshot", ""];
10230
+ out.push("- Fingerprint: " + code(manifest.fingerprint) + " - quote it verbatim in your answer.");
10231
+ out.push(
10232
+ "- Generated: " + code(manifest.generatedAt) + " from branch " + code(manifest.git.branch) + " at commit " + code(manifest.git.commit.slice(0, 8)) + "."
10233
+ );
10234
+ out.push(
10235
+ manifest.git.isDirty ? " The working tree had uncommitted changes at generation time." : " The working tree was clean at generation time."
10236
+ );
10237
+ out.push(
10238
+ "- Validation: `manifest.validation.status` was " + code(manifest.validation.status) + " at generation time.",
10239
+ " That describes the run, not now: if the tree may have moved since, the snapshot is a",
10240
+ " claim that needs re-checking, not a fact."
10241
+ );
10242
+ if (manifest.parts.length > 0) {
10243
+ out.push(
10244
+ "- Parts: " + formatNumber(manifest.parts.length) + " at a " + formatNumber(Math.round(manifest.budgets.maxPartBytes / 1024)) + " KB ceiling" + (manifest.parts.length === 1 ? ":" : " each:")
10245
+ );
10246
+ for (const part of manifest.parts.slice(0, MAX_PART_ROWS)) {
10247
+ out.push(" - " + code(part.filename) + " - " + formatNumber(part.fileCount) + " file(s)");
10248
+ }
10249
+ if (manifest.parts.length > MAX_PART_ROWS) {
10250
+ out.push(
10251
+ " - and " + formatNumber(manifest.parts.length - MAX_PART_ROWS) + " more, tabled in `README.md`"
10252
+ );
10253
+ }
10254
+ }
10255
+ return out;
10256
+ }
10257
+ function incompleteSection(manifest, code) {
10258
+ const out = [];
10259
+ const list2 = manifest.incomplete;
10260
+ if (list2.length === 0) {
10261
+ out.push("- Partial files: none. Every included file is present in full.");
10262
+ return out;
10263
+ }
10264
+ out.push(
10265
+ "- Partial files: " + formatNumber(list2.length) + ". These are present only in part, and the",
10266
+ " missing lines are named, not implied:"
10267
+ );
10268
+ for (const entry of list2.slice(0, MAX_INCOMPLETE_ROWS)) {
10269
+ const ranges = entry.omittedRanges.map(([start, end]) => start === end ? String(start) : start + "-" + end).join(", ");
10270
+ out.push(
10271
+ " - " + code(entry.relativePath) + " in " + code(entry.part) + " - " + entry.reason + ", lines " + ranges + " (" + formatNumber(entry.omittedLines) + " of " + formatNumber(entry.lines) + " missing)"
10272
+ );
10273
+ }
10274
+ if (list2.length > MAX_INCOMPLETE_ROWS) {
10275
+ out.push(
10276
+ " - and " + formatNumber(list2.length - MAX_INCOMPLETE_ROWS) + " more, all named in `manifest.json` under `incomplete[]`"
10277
+ );
10278
+ }
10279
+ return out;
10280
+ }
10281
+ function redactionSection(manifest, auditWritten) {
10282
+ const redacted = manifest.totals.redactedLines;
10283
+ if (redacted === 0) {
10284
+ return ["- Redacted: no line matched a secret rule."];
10285
+ }
10286
+ const where = auditWritten ? "`reports/audit.md` names the files; the values are not recoverable from it." : "`reports/audit.md` was disabled for this run, so only the count is available.";
10287
+ return [
10288
+ "- Redacted: " + formatNumber(redacted) + " line(s) had values masked before you received them.",
10289
+ " A masked span is a deliberate redaction, not an empty value.",
10290
+ " " + where
10291
+ ];
10292
+ }
10293
+ function deliverySection(manifest, partsWritten, slots) {
10294
+ if (!partsWritten || manifest.parts.length === 0) return [];
10295
+ const parts = manifest.parts.length;
10296
+ const wholeSet = parts + 5;
10297
+ const unlimited = slots <= UNLIMITED_SLOTS;
10298
+ const out = ["## Attaching this", ""];
10299
+ out.push(
10300
+ "Paste this file as text: instructions cost no attachment slot. Attach the files it names.",
10301
+ "",
10302
+ "- Every part opens with `# Codebase Snapshot Part NNN of MMM` and repeats the fingerprint",
10303
+ " above, so check both before relying on one. A part you were not given is not an empty part."
10304
+ );
10305
+ if (unlimited) {
10306
+ out.push(
10307
+ "- No attachment limit is configured, so every file can travel: " + parts + " " + partWord(parts) + " plus `manifest.json`, `README.md` and the three reports (" + wholeSet + " files)."
10308
+ );
10309
+ } else if (wholeSet <= slots) {
10310
+ out.push(
10311
+ "- A " + slots + "-file destination carries the whole set: " + parts + " " + partWord(parts) + " plus `manifest.json`, `README.md` and the three reports - " + wholeSet + " of " + slots + "."
10312
+ );
10313
+ } else if (parts + 1 <= slots) {
10314
+ out.push(
10315
+ "- A " + slots + "-file destination carries " + parts + " " + partWord(parts) + " and",
10316
+ " `manifest.json` (" + (parts + 1) + " of " + slots + "); `README.md` and",
10317
+ " `reports/` stay behind - the brief above carries what they add."
10318
+ );
10319
+ } else if (parts <= slots) {
10320
+ out.push(
10321
+ parts === 1 ? "- The only part fills a " + slots + "-file destination, so `manifest.json` and" : "- The " + parts + " parts fill a " + slots + "-file destination, so `manifest.json` and",
10322
+ " `reports/` stay behind. The brief above carries what they add."
10323
+ );
10324
+ if (parts > 1) {
10325
+ out.push(
10326
+ " Either raise `--max-part-bytes` to merge the parts, or set `--max-parts " + slots + "` and let the parts grow to the count instead."
10327
+ );
10328
+ }
10329
+ } else {
10330
+ out.push(
10331
+ "- The " + parts + " parts do not fit a " + slots + "-file destination: at most " + slots + " can be attached.",
10332
+ " Choose by task - `reports/navigation.md` maps a file to its part - and name the parts",
10333
+ " you left out, or regenerate with `--max-part-bytes " + suggestBudgetBytes(manifest, slots) + "` for about " + (slots - 1) + " parts. `--max-parts " + slots + "` grows the parts until",
10334
+ " they fit instead, and says so when they end up larger than maxPartBytes."
10335
+ );
10336
+ }
10337
+ out.push(
10338
+ "- If you were given only some of them, say which parts are missing before you answer, and",
10339
+ " name the files you needed. Do not infer the contents of a part you did not receive.",
10340
+ ""
10341
+ );
10342
+ return out;
10343
+ }
10344
+ function suggestBudgetBytes(manifest, slots) {
10345
+ const total = manifest.parts.reduce((sum, part) => sum + part.byteSize, 0);
10346
+ const target = Math.max(1, slots - 1);
10347
+ const estimated = Math.ceil(total / target * 1.15);
10348
+ const rounded = Math.ceil(estimated / 16384) * 16384;
10349
+ const budget = Math.max(rounded, manifest.budgets.maxPartBytes);
10350
+ return Math.round(budget / 1024) + "k";
10351
+ }
10352
+
9663
10353
  // src/generator/readme.ts
9664
10354
  function generateReadme(manifest, artifacts) {
9665
10355
  const wrote = (name) => artifacts?.[name] !== false;
9666
10356
  const reportLinks = [];
10357
+ if (wrote("prompt")) {
10358
+ reportLinks.push(
10359
+ "- [PROMPT.md](PROMPT.md) \u2014 The instruction sheet to paste with this snapshot: what it contains, what it left out, and the rules for citing it."
10360
+ );
10361
+ }
9667
10362
  if (wrote("navigation")) {
9668
10363
  reportLinks.push(
9669
10364
  "- [reports/navigation.md](reports/navigation.md) \u2014 Comprehensive file directory mapping files to chunk files."
@@ -9733,6 +10428,11 @@ function generateReadme(manifest, artifacts) {
9733
10428
  lines.push("", "## Snapshot Parts", "", "No parts were written for this run.");
9734
10429
  }
9735
10430
  const readOrder = [];
10431
+ if (wrote("prompt")) {
10432
+ readOrder.push(
10433
+ "1. Hand `PROMPT.md` to the model that receives this snapshot: it names the parts, the partial files and the fingerprint of this run."
10434
+ );
10435
+ }
9736
10436
  if (wrote("navigation") || wrote("projectTree")) {
9737
10437
  const first = [wrote("navigation") ? "`reports/navigation.md`" : null, wrote("projectTree") ? "`reports/project-tree.md`" : null].filter(Boolean).join(" or ");
9738
10438
  readOrder.push(`1. Read ${first} first to locate target features or files.`);
@@ -9837,6 +10537,58 @@ function treeTruncationWarnings(treeText) {
9837
10537
  }
9838
10538
  return warnings;
9839
10539
  }
10540
+ var SUMMARY_LIMIT = 400;
10541
+ var MAX_RELEASES = 2;
10542
+ function readProjectOverview(cwd) {
10543
+ return {
10544
+ ...readDescription(cwd),
10545
+ ...readSummary(cwd),
10546
+ releases: readReleases(cwd)
10547
+ };
10548
+ }
10549
+ function readText(file) {
10550
+ try {
10551
+ return fs16__namespace.readFileSync(file, "utf8");
10552
+ } catch {
10553
+ return null;
10554
+ }
10555
+ }
10556
+ function readDescription(cwd) {
10557
+ const raw = readText(path17__namespace.join(cwd, "package.json"));
10558
+ if (raw === null) return {};
10559
+ try {
10560
+ const parsed = JSON.parse(stripJsonComments(raw));
10561
+ return typeof parsed.description === "string" && parsed.description.trim().length > 0 ? { description: parsed.description.trim() } : {};
10562
+ } catch {
10563
+ return {};
10564
+ }
10565
+ }
10566
+ function readSummary(cwd) {
10567
+ const raw = readText(path17__namespace.join(cwd, "README.md"));
10568
+ if (raw === null) return {};
10569
+ const lines = raw.split(/\r?\n/);
10570
+ const paragraph = [];
10571
+ for (const line of lines) {
10572
+ const trimmed = line.trim();
10573
+ if (paragraph.length === 0) {
10574
+ if (trimmed.length === 0) continue;
10575
+ if (/^#/.test(trimmed) || /^!\[/.test(trimmed) || /^</.test(trimmed) || /^[-*|]/.test(trimmed)) continue;
10576
+ if (/^\[[^\]]+\]:/.test(trimmed)) continue;
10577
+ } else if (trimmed.length === 0 || /^#/.test(trimmed)) {
10578
+ break;
10579
+ }
10580
+ paragraph.push(trimmed);
10581
+ }
10582
+ const summary = paragraph.join(" ").replace(/\s+/g, " ").trim();
10583
+ if (summary.length === 0) return {};
10584
+ return { summary: summary.length > SUMMARY_LIMIT ? summary.slice(0, SUMMARY_LIMIT - 1) + "\u2026" : summary };
10585
+ }
10586
+ function readReleases(cwd) {
10587
+ const raw = readText(path17__namespace.join(cwd, "CHANGELOG.md"));
10588
+ if (raw === null) return [];
10589
+ const headings = raw.split(/\r?\n/).filter((line) => /^##\s+\S/.test(line)).map((line) => line.replace(/^##\s+/, "").trim());
10590
+ return headings.slice(0, MAX_RELEASES);
10591
+ }
9840
10592
  var PACKAGE_LATEST_URL = "https://registry.npmjs.org/codebase-snapshot/latest";
9841
10593
  var CHECK_INTERVAL_MS = 24 * 60 * 60 * 1e3;
9842
10594
  var UP_TO_DATE_INTERVAL_MS = 60 * 60 * 1e3;
@@ -9885,17 +10637,17 @@ function isNewer(candidate, current) {
9885
10637
  }
9886
10638
  function cacheDirectory(env = process.env, platform = process.platform) {
9887
10639
  if (platform === "win32") {
9888
- const base2 = env.LOCALAPPDATA ?? path16__namespace.join(os__namespace.homedir(), "AppData", "Local");
9889
- return path16__namespace.join(base2, "codebase-snapshot");
10640
+ const base2 = env.LOCALAPPDATA ?? path17__namespace.join(os__namespace.homedir(), "AppData", "Local");
10641
+ return path17__namespace.join(base2, "codebase-snapshot");
9890
10642
  }
9891
10643
  if (platform === "darwin") {
9892
- return path16__namespace.join(os__namespace.homedir(), "Library", "Caches", "codebase-snapshot");
10644
+ return path17__namespace.join(os__namespace.homedir(), "Library", "Caches", "codebase-snapshot");
9893
10645
  }
9894
- const base = env.XDG_CACHE_HOME ?? path16__namespace.join(os__namespace.homedir(), ".cache");
9895
- return path16__namespace.join(base, "codebase-snapshot");
10646
+ const base = env.XDG_CACHE_HOME ?? path17__namespace.join(os__namespace.homedir(), ".cache");
10647
+ return path17__namespace.join(base, "codebase-snapshot");
9896
10648
  }
9897
10649
  function cacheFilePath(env = process.env) {
9898
- return path16__namespace.join(cacheDirectory(env), "update-check.json");
10650
+ return path17__namespace.join(cacheDirectory(env), "update-check.json");
9899
10651
  }
9900
10652
  function shouldCheck(argv, env) {
9901
10653
  const disabled = ["1", "true", "yes"].includes(
@@ -9925,7 +10677,7 @@ function shouldCheck(argv, env) {
9925
10677
  function readCache(file) {
9926
10678
  let raw;
9927
10679
  try {
9928
- raw = fs15__namespace.readFileSync(file, "utf8");
10680
+ raw = fs16__namespace.readFileSync(file, "utf8");
9929
10681
  } catch {
9930
10682
  return null;
9931
10683
  }
@@ -9942,8 +10694,8 @@ function readCache(file) {
9942
10694
  }
9943
10695
  function writeCache(file, entry) {
9944
10696
  try {
9945
- fs15__namespace.mkdirSync(path16__namespace.dirname(file), { recursive: true });
9946
- fs15__namespace.writeFileSync(file, `${JSON.stringify(entry)}
10697
+ fs16__namespace.mkdirSync(path17__namespace.dirname(file), { recursive: true });
10698
+ fs16__namespace.writeFileSync(file, `${JSON.stringify(entry)}
9947
10699
  `, "utf8");
9948
10700
  } catch {
9949
10701
  }
@@ -10074,36 +10826,36 @@ fi
10074
10826
  `;
10075
10827
  }
10076
10828
  function gitDirectory(cwd) {
10077
- const dotGit = path16__namespace.join(cwd, ".git");
10829
+ const dotGit = path17__namespace.join(cwd, ".git");
10078
10830
  let stats;
10079
10831
  try {
10080
- stats = fs15__namespace.statSync(dotGit);
10832
+ stats = fs16__namespace.statSync(dotGit);
10081
10833
  } catch {
10082
10834
  return null;
10083
10835
  }
10084
10836
  if (stats.isDirectory()) return dotGit;
10085
10837
  if (!stats.isFile()) return null;
10086
10838
  try {
10087
- const contents = fs15__namespace.readFileSync(dotGit, "utf8");
10839
+ const contents = fs16__namespace.readFileSync(dotGit, "utf8");
10088
10840
  const match = /^gitdir:\s*(.+)$/m.exec(contents);
10089
10841
  if (!match) return null;
10090
10842
  const target = match[1];
10091
- const resolved = path16__namespace.isAbsolute(target.trim()) ? target.trim() : path16__namespace.join(cwd, target.trim());
10092
- if (!fs15__namespace.statSync(resolved).isDirectory()) return null;
10093
- if (isInside2(path16__namespace.resolve(cwd), path16__namespace.resolve(resolved))) return resolved;
10094
- return isRegisteredWorktree(path16__namespace.resolve(resolved), cwd) ? resolved : null;
10843
+ const resolved = path17__namespace.isAbsolute(target.trim()) ? target.trim() : path17__namespace.join(cwd, target.trim());
10844
+ if (!fs16__namespace.statSync(resolved).isDirectory()) return null;
10845
+ if (isInside2(path17__namespace.resolve(cwd), path17__namespace.resolve(resolved))) return resolved;
10846
+ return isRegisteredWorktree(path17__namespace.resolve(resolved), cwd) ? resolved : null;
10095
10847
  } catch {
10096
10848
  return null;
10097
10849
  }
10098
10850
  }
10099
10851
  function isInside2(parent, child) {
10100
- const relative15 = path16__namespace.relative(parent, child);
10101
- return relative15 === "" || !relative15.startsWith("..") && !path16__namespace.isAbsolute(relative15);
10852
+ const relative15 = path17__namespace.relative(parent, child);
10853
+ return relative15 === "" || !relative15.startsWith("..") && !path17__namespace.isAbsolute(relative15);
10102
10854
  }
10103
10855
  function isRegisteredWorktree(gitDir, cwd) {
10104
10856
  try {
10105
- const back = fs15__namespace.readFileSync(path16__namespace.join(gitDir, "gitdir"), "utf8").trim();
10106
- return path16__namespace.resolve(gitDir, back) === path16__namespace.join(path16__namespace.resolve(cwd), ".git");
10857
+ const back = fs16__namespace.readFileSync(path17__namespace.join(gitDir, "gitdir"), "utf8").trim();
10858
+ return path17__namespace.resolve(gitDir, back) === path17__namespace.join(path17__namespace.resolve(cwd), ".git");
10107
10859
  } catch {
10108
10860
  return false;
10109
10861
  }
@@ -10124,10 +10876,10 @@ function gitOutput(cwd, args) {
10124
10876
  function configuredHooksDirectory(cwd) {
10125
10877
  const hooks = gitOutput(cwd, ["rev-parse", "--git-path", "hooks"]);
10126
10878
  if (hooks === null) return null;
10127
- const resolved = path16__namespace.resolve(cwd, hooks);
10879
+ const resolved = path17__namespace.resolve(cwd, hooks);
10128
10880
  const common = gitOutput(cwd, ["rev-parse", "--git-common-dir"]);
10129
- const commonDir = common === null ? null : path16__namespace.resolve(cwd, common);
10130
- if (isInside2(path16__namespace.resolve(cwd), resolved)) return { dir: resolved };
10881
+ const commonDir = common === null ? null : path17__namespace.resolve(cwd, common);
10882
+ if (isInside2(path17__namespace.resolve(cwd), resolved)) return { dir: resolved };
10131
10883
  if (commonDir !== null && isInside2(commonDir, resolved)) return { dir: resolved };
10132
10884
  return {
10133
10885
  refusal: `The hooks directory git reports (${resolved}) is outside this repository, so no hook was written. Add \`npx ${GENERATOR_NAME} validate\` to the hook manager that owns it instead.`
@@ -10148,10 +10900,10 @@ function installPreCommitHook(cwd, outDir = "snapshot") {
10148
10900
  ]
10149
10901
  };
10150
10902
  }
10151
- const hooksDir = configured === null ? path16__namespace.join(gitDir, "hooks") : configured.dir;
10152
- const hookPath = path16__namespace.join(hooksDir, "pre-commit");
10903
+ const hooksDir = configured === null ? path17__namespace.join(gitDir, "hooks") : configured.dir;
10904
+ const hookPath = path17__namespace.join(hooksDir, "pre-commit");
10153
10905
  try {
10154
- fs15__namespace.mkdirSync(hooksDir, { recursive: true });
10906
+ fs16__namespace.mkdirSync(hooksDir, { recursive: true });
10155
10907
  } catch (err) {
10156
10908
  return {
10157
10909
  path: hookPath,
@@ -10161,7 +10913,7 @@ function installPreCommitHook(cwd, outDir = "snapshot") {
10161
10913
  }
10162
10914
  let existing = null;
10163
10915
  try {
10164
- existing = fs15__namespace.readFileSync(hookPath, "utf8");
10916
+ existing = fs16__namespace.readFileSync(hookPath, "utf8");
10165
10917
  } catch {
10166
10918
  existing = null;
10167
10919
  }
@@ -10176,8 +10928,8 @@ function installPreCommitHook(cwd, outDir = "snapshot") {
10176
10928
  };
10177
10929
  }
10178
10930
  try {
10179
- fs15__namespace.writeFileSync(hookPath, hookScript(outDir), "utf8");
10180
- fs15__namespace.chmodSync(hookPath, 493);
10931
+ fs16__namespace.writeFileSync(hookPath, hookScript(outDir), "utf8");
10932
+ fs16__namespace.chmodSync(hookPath, 493);
10181
10933
  } catch (err) {
10182
10934
  return {
10183
10935
  path: hookPath,
@@ -10194,7 +10946,7 @@ function installPreCommitHook(cwd, outDir = "snapshot") {
10194
10946
  };
10195
10947
  }
10196
10948
  function workerEntry(directory, isCjs) {
10197
- const entry = path16__namespace.join(directory, isCjs ? "index.cjs" : "index.js");
10949
+ const entry = path17__namespace.join(directory, isCjs ? "index.cjs" : "index.js");
10198
10950
  return { path: entry, url: url.pathToFileURL(entry).href };
10199
10951
  }
10200
10952
  var WORKER_SOURCE = `
@@ -10261,7 +11013,7 @@ function generateInWorker(cwd, cliOptions, options = {}) {
10261
11013
  resolve12(result);
10262
11014
  };
10263
11015
  const isCjs = typeof __dirname !== "undefined";
10264
- const directory = isCjs ? __dirname : path16__namespace.dirname(url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('cli.cjs', document.baseURI).href))));
11016
+ const directory = isCjs ? __dirname : path17__namespace.dirname(url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('cli.cjs', document.baseURI).href))));
10265
11017
  try {
10266
11018
  worker = new worker_threads.Worker(WORKER_SOURCE, {
10267
11019
  eval: true,
@@ -10296,23 +11048,23 @@ var SUMMARY_MAX_SOURCE_BYTES2 = SUMMARY_MAX_SOURCE_BYTES;
10296
11048
  var FILE_DERIVATIONS = /* @__PURE__ */ new Map();
10297
11049
  var FILE_DERIVATION_LIMIT_BYTES = 64 * 1024 * 1024;
10298
11050
  var fileDerivationBytes = 0;
10299
- function takeDerivation(path22, hash, settings) {
10300
- const cached = FILE_DERIVATIONS.get(path22);
11051
+ function takeDerivation(path23, hash, settings) {
11052
+ const cached = FILE_DERIVATIONS.get(path23);
10301
11053
  if (cached === void 0 || cached.hash !== hash || cached.settings !== settings) return void 0;
10302
- FILE_DERIVATIONS.delete(path22);
10303
- FILE_DERIVATIONS.set(path22, cached);
11054
+ FILE_DERIVATIONS.delete(path23);
11055
+ FILE_DERIVATIONS.set(path23, cached);
10304
11056
  return cached;
10305
11057
  }
10306
- function rememberDerivation(path22, hash, settings, derivation) {
11058
+ function rememberDerivation(path23, hash, settings, derivation) {
10307
11059
  const bodyBytes = derivation.finalContent === derivation.redacted ? derivation.redacted.length : derivation.redacted.length + derivation.finalContent.length;
10308
11060
  const bytes = bodyBytes * 2 + 512;
10309
11061
  if (bytes > FILE_DERIVATION_LIMIT_BYTES / 4) return;
10310
- const previous = FILE_DERIVATIONS.get(path22);
11062
+ const previous = FILE_DERIVATIONS.get(path23);
10311
11063
  if (previous !== void 0) {
10312
- FILE_DERIVATIONS.delete(path22);
11064
+ FILE_DERIVATIONS.delete(path23);
10313
11065
  fileDerivationBytes -= previous.bytes;
10314
11066
  } else {
10315
- FILE_DERIVATIONS.delete(path22);
11067
+ FILE_DERIVATIONS.delete(path23);
10316
11068
  }
10317
11069
  while (fileDerivationBytes + bytes > FILE_DERIVATION_LIMIT_BYTES) {
10318
11070
  const oldest = FILE_DERIVATIONS.keys().next();
@@ -10321,7 +11073,7 @@ function rememberDerivation(path22, hash, settings, derivation) {
10321
11073
  FILE_DERIVATIONS.delete(oldest.value);
10322
11074
  if (evicted !== void 0) fileDerivationBytes -= evicted.bytes;
10323
11075
  }
10324
- FILE_DERIVATIONS.set(path22, { ...derivation, hash, settings, bytes });
11076
+ FILE_DERIVATIONS.set(path23, { ...derivation, hash, settings, bytes });
10325
11077
  fileDerivationBytes += bytes;
10326
11078
  }
10327
11079
  function derivationSettings(config) {
@@ -10572,11 +11324,11 @@ function verifyInMemory(files, parts, unaccounted) {
10572
11324
  return errors;
10573
11325
  }
10574
11326
  function resolveSafeOutputDirs(config) {
10575
- const cwd = path16__namespace.resolve(config.cwd);
10576
- const outDir = path16__namespace.resolve(cwd, config.outDir);
10577
- const tmpDir = path16__namespace.resolve(cwd, config.tmpDir);
10578
- const root = path16__namespace.parse(cwd).root;
10579
- const contains = (parent, child) => child === parent || child.startsWith(`${parent}${path16__namespace.sep}`);
11327
+ const cwd = path17__namespace.resolve(config.cwd);
11328
+ const outDir = path17__namespace.resolve(cwd, config.outDir);
11329
+ const tmpDir = path17__namespace.resolve(cwd, config.tmpDir);
11330
+ const root = path17__namespace.parse(cwd).root;
11331
+ const contains = (parent, child) => child === parent || child.startsWith(`${parent}${path17__namespace.sep}`);
10580
11332
  const reject = (reason) => {
10581
11333
  throw new Error(
10582
11334
  `Refusing to generate: ${reason}. outDir=${outDir} tmpDir=${tmpDir} cwd=${cwd}`
@@ -10616,6 +11368,28 @@ function maskSummaryStrings(value, secretRules) {
10616
11368
  function maskPathText(value, secretRules) {
10617
11369
  return findSecretInPath(value, secretRules)?.masked ?? value;
10618
11370
  }
11371
+ function maskOwnerBrief(brief, secretRules) {
11372
+ if (brief === void 0) return void 0;
11373
+ const mask = (value) => maskPathText(value, secretRules);
11374
+ return {
11375
+ ...brief,
11376
+ ...brief.stakes === void 0 ? {} : { stakes: mask(brief.stakes) },
11377
+ ...brief.system === void 0 ? {} : { system: mask(brief.system) },
11378
+ ...brief.history === void 0 ? {} : { history: mask(brief.history) },
11379
+ ...brief.bar === void 0 ? {} : { bar: mask(brief.bar) },
11380
+ ...brief.calibration === void 0 ? {} : { calibration: mask(brief.calibration) },
11381
+ ...brief.preamble === void 0 ? {} : { preamble: mask(brief.preamble) },
11382
+ notes: brief.notes.map((note) => ({ heading: note.heading, body: mask(note.body) }))
11383
+ };
11384
+ }
11385
+ function maskOverview(overview, secretRules) {
11386
+ const mask = (value) => maskPathText(value, secretRules);
11387
+ return {
11388
+ ...overview.description === void 0 ? {} : { description: mask(overview.description) },
11389
+ ...overview.summary === void 0 ? {} : { summary: mask(overview.summary) },
11390
+ releases: overview.releases.map(mask)
11391
+ };
11392
+ }
10619
11393
  function maskSkipRecords(records, secretRules) {
10620
11394
  return maskSkipPaths(records, secretRules);
10621
11395
  }
@@ -10636,14 +11410,14 @@ function listEntries(dir) {
10636
11410
  const walk = (absolute, prefix) => {
10637
11411
  let children;
10638
11412
  try {
10639
- children = fs15__namespace.readdirSync(absolute, { withFileTypes: true });
11413
+ children = fs16__namespace.readdirSync(absolute, { withFileTypes: true });
10640
11414
  } catch {
10641
11415
  return;
10642
11416
  }
10643
11417
  for (const child of children) {
10644
11418
  const relative15 = prefix === "" ? child.name : `${prefix}/${child.name}`;
10645
11419
  entries.push(relative15);
10646
- if (child.isDirectory()) walk(path16__namespace.join(absolute, child.name), relative15);
11420
+ if (child.isDirectory()) walk(path17__namespace.join(absolute, child.name), relative15);
10647
11421
  }
10648
11422
  };
10649
11423
  walk(dir, "");
@@ -10655,10 +11429,10 @@ function markerInventory(dir, written) {
10655
11429
  for (const entry of entries) {
10656
11430
  if (entry === OWNERSHIP_MARKER) continue;
10657
11431
  if (isIgnorableEntry(entry)) continue;
10658
- const full = path16__namespace.join(dir, ...entry.split("/"));
11432
+ const full = path17__namespace.join(dir, ...entry.split("/"));
10659
11433
  let stats;
10660
11434
  try {
10661
- stats = fs15__namespace.lstatSync(full);
11435
+ stats = fs16__namespace.lstatSync(full);
10662
11436
  } catch {
10663
11437
  continue;
10664
11438
  }
@@ -10670,7 +11444,7 @@ function markerInventory(dir, written) {
10670
11444
  }
10671
11445
  let digest;
10672
11446
  try {
10673
- digest = sha256Hex2(fs15__namespace.readFileSync(full));
11447
+ digest = sha256Hex2(fs16__namespace.readFileSync(full));
10674
11448
  } catch {
10675
11449
  continue;
10676
11450
  }
@@ -10691,15 +11465,15 @@ function markerPayload(dir, state, id, createdAt, written) {
10691
11465
  entries,
10692
11466
  files
10693
11467
  };
10694
- const manifestPath = path16__namespace.join(dir, "manifest.json");
10695
- if (fs15__namespace.existsSync(manifestPath)) {
10696
- marker2.manifestSha256 = sha256Hex2(fs15__namespace.readFileSync(manifestPath));
11468
+ const manifestPath = path17__namespace.join(dir, "manifest.json");
11469
+ if (fs16__namespace.existsSync(manifestPath)) {
11470
+ marker2.manifestSha256 = sha256Hex2(fs16__namespace.readFileSync(manifestPath));
10697
11471
  }
10698
11472
  return marker2;
10699
11473
  }
10700
11474
  function writeOwnershipMarker(dir, marker2) {
10701
- fs15__namespace.writeFileSync(
10702
- path16__namespace.join(dir, OWNERSHIP_MARKER),
11475
+ fs16__namespace.writeFileSync(
11476
+ path17__namespace.join(dir, OWNERSHIP_MARKER),
10703
11477
  `${JSON.stringify(marker2, null, 2)}
10704
11478
  `,
10705
11479
  "utf8"
@@ -10711,13 +11485,13 @@ function markerBelongsTo(dir, id) {
10711
11485
  return evidence.marker.id === id;
10712
11486
  }
10713
11487
  function readOwnershipMarker(dir) {
10714
- const markerPath = path16__namespace.join(dir, OWNERSHIP_MARKER);
10715
- if (!fs15__namespace.existsSync(markerPath)) {
11488
+ const markerPath = path17__namespace.join(dir, OWNERSHIP_MARKER);
11489
+ if (!fs16__namespace.existsSync(markerPath)) {
10716
11490
  return { marker: null, problem: "it holds no .codebase-snapshot marker" };
10717
11491
  }
10718
11492
  let raw;
10719
11493
  try {
10720
- raw = fs15__namespace.readFileSync(markerPath, "utf8");
11494
+ raw = fs16__namespace.readFileSync(markerPath, "utf8");
10721
11495
  } catch {
10722
11496
  return { marker: null, problem: "its .codebase-snapshot marker could not be read" };
10723
11497
  }
@@ -10817,10 +11591,10 @@ function verifyMarkerInventory(dir, entries, files) {
10817
11591
  for (const entry of entries) {
10818
11592
  if (entry === OWNERSHIP_MARKER) continue;
10819
11593
  if (IGNORABLE_ENTRIES.has(entry.slice(entry.lastIndexOf("/") + 1))) continue;
10820
- const full = path16__namespace.join(dir, ...entry.split("/"));
11594
+ const full = path17__namespace.join(dir, ...entry.split("/"));
10821
11595
  let stats;
10822
11596
  try {
10823
- stats = fs15__namespace.lstatSync(full);
11597
+ stats = fs16__namespace.lstatSync(full);
10824
11598
  } catch {
10825
11599
  return `its .codebase-snapshot inventory lists ${entry}, which cannot be read`;
10826
11600
  }
@@ -10845,7 +11619,7 @@ function verifyMarkerInventory(dir, entries, files) {
10845
11619
  }
10846
11620
  let digest;
10847
11621
  try {
10848
- digest = sha256Hex2(fs15__namespace.readFileSync(full));
11622
+ digest = sha256Hex2(fs16__namespace.readFileSync(full));
10849
11623
  } catch {
10850
11624
  return `its .codebase-snapshot inventory cannot verify ${entry}: the file could not be read`;
10851
11625
  }
@@ -10866,12 +11640,12 @@ function assessSnapshotDirectory(dir) {
10866
11640
  marker: marker2
10867
11641
  };
10868
11642
  }
10869
- const manifestPath = path16__namespace.join(dir, "manifest.json");
10870
- const hasManifest = fs15__namespace.existsSync(manifestPath);
11643
+ const manifestPath = path17__namespace.join(dir, "manifest.json");
11644
+ const hasManifest = fs16__namespace.existsSync(manifestPath);
10871
11645
  if (hasManifest) {
10872
11646
  let raw;
10873
11647
  try {
10874
- raw = fs15__namespace.readFileSync(manifestPath, "utf8");
11648
+ raw = fs16__namespace.readFileSync(manifestPath, "utf8");
10875
11649
  } catch {
10876
11650
  return {
10877
11651
  owned: false,
@@ -10966,13 +11740,13 @@ function containsNoFiles(dir) {
10966
11740
  const current = pending.pop();
10967
11741
  let entries;
10968
11742
  try {
10969
- entries = fs15__namespace.readdirSync(current, { withFileTypes: true });
11743
+ entries = fs16__namespace.readdirSync(current, { withFileTypes: true });
10970
11744
  } catch {
10971
11745
  return false;
10972
11746
  }
10973
11747
  for (const entry of entries) {
10974
11748
  if (entry.isDirectory()) {
10975
- pending.push(path16__namespace.join(current, entry.name));
11749
+ pending.push(path17__namespace.join(current, entry.name));
10976
11750
  } else if (!IGNORABLE_ENTRIES.has(entry.name)) {
10977
11751
  return false;
10978
11752
  }
@@ -10981,13 +11755,13 @@ function containsNoFiles(dir) {
10981
11755
  return true;
10982
11756
  }
10983
11757
  function assertReplaceable(target, label, secretRules) {
10984
- if (!fs15__namespace.existsSync(target)) return;
10985
- if (!fs15__namespace.statSync(target).isDirectory()) {
11758
+ if (!fs16__namespace.existsSync(target)) return;
11759
+ if (!fs16__namespace.statSync(target).isDirectory()) {
10986
11760
  throw new Error(
10987
11761
  `Refusing to write into ${label} ${target}: it exists but is not a directory.`
10988
11762
  );
10989
11763
  }
10990
- const entries = fs15__namespace.readdirSync(target);
11764
+ const entries = fs16__namespace.readdirSync(target);
10991
11765
  if (entries.length === 0) return;
10992
11766
  if (entries.every((name) => IGNORABLE_ENTRIES.has(name))) return;
10993
11767
  if (containsNoFiles(target)) return;
@@ -11007,18 +11781,18 @@ function assertReplaceable(target, label, secretRules) {
11007
11781
  );
11008
11782
  }
11009
11783
  function assertStagingRootUsable(tmpDir, secretRules) {
11010
- if (!fs15__namespace.existsSync(tmpDir)) return;
11011
- if (!fs15__namespace.statSync(tmpDir).isDirectory()) {
11784
+ if (!fs16__namespace.existsSync(tmpDir)) return;
11785
+ if (!fs16__namespace.statSync(tmpDir).isDirectory()) {
11012
11786
  throw new Error(`Refusing to write into tmpDir ${tmpDir}: it exists but is not a directory.`);
11013
11787
  }
11014
- const entries = fs15__namespace.readdirSync(tmpDir);
11788
+ const entries = fs16__namespace.readdirSync(tmpDir);
11015
11789
  if (entries.length === 0) return;
11016
11790
  const foreign = entries.filter((name) => {
11017
- const full = path16__namespace.join(tmpDir, name);
11791
+ const full = path17__namespace.join(tmpDir, name);
11018
11792
  if (!name.startsWith(RUN_DIR_PREFIX)) return true;
11019
11793
  let stats;
11020
11794
  try {
11021
- stats = fs15__namespace.statSync(full);
11795
+ stats = fs16__namespace.statSync(full);
11022
11796
  } catch {
11023
11797
  return true;
11024
11798
  }
@@ -11026,7 +11800,7 @@ function assertStagingRootUsable(tmpDir, secretRules) {
11026
11800
  const { marker: marker2 } = readOwnershipMarker(full);
11027
11801
  if (marker2) return false;
11028
11802
  try {
11029
- return fs15__namespace.readdirSync(full).length > 0;
11803
+ return fs16__namespace.readdirSync(full).length > 0;
11030
11804
  } catch {
11031
11805
  return true;
11032
11806
  }
@@ -11041,13 +11815,13 @@ function assertStagingRootUsable(tmpDir, secretRules) {
11041
11815
  function cleanStaleRunDirs(tmpDir) {
11042
11816
  let entries;
11043
11817
  try {
11044
- entries = fs15__namespace.readdirSync(tmpDir);
11818
+ entries = fs16__namespace.readdirSync(tmpDir);
11045
11819
  } catch {
11046
11820
  return;
11047
11821
  }
11048
11822
  for (const name of entries) {
11049
11823
  if (!name.startsWith(RUN_DIR_PREFIX)) continue;
11050
- const full = path16__namespace.join(tmpDir, name);
11824
+ const full = path17__namespace.join(tmpDir, name);
11051
11825
  const { marker: marker2 } = readOwnershipMarker(full);
11052
11826
  if (marker2) {
11053
11827
  const created = Date.parse(marker2.createdAt);
@@ -11055,33 +11829,33 @@ function cleanStaleRunDirs(tmpDir) {
11055
11829
  const abandoned = typeof marker2.pid === "number" && !isProcessAlive(marker2.pid);
11056
11830
  if (aged || abandoned) {
11057
11831
  try {
11058
- fs15__namespace.rmSync(full, { recursive: true, force: true });
11832
+ fs16__namespace.rmSync(full, { recursive: true, force: true });
11059
11833
  } catch {
11060
11834
  }
11061
11835
  }
11062
11836
  continue;
11063
11837
  }
11064
11838
  try {
11065
- if (fs15__namespace.readdirSync(full).length === 0) fs15__namespace.rmSync(full, { recursive: true, force: true });
11839
+ if (fs16__namespace.readdirSync(full).length === 0) fs16__namespace.rmSync(full, { recursive: true, force: true });
11066
11840
  } catch {
11067
11841
  }
11068
11842
  }
11069
11843
  }
11070
11844
  function removeIfEmpty(dir) {
11071
11845
  try {
11072
- if (fs15__namespace.readdirSync(dir).length === 0) fs15__namespace.rmSync(dir, { recursive: true, force: true });
11846
+ if (fs16__namespace.readdirSync(dir).length === 0) fs16__namespace.rmSync(dir, { recursive: true, force: true });
11073
11847
  } catch {
11074
11848
  }
11075
11849
  }
11076
11850
  function ensureParentDirectory(target, label) {
11077
- const parent = path16__namespace.dirname(target);
11078
- if (fs15__namespace.existsSync(parent) && !fs15__namespace.statSync(parent).isDirectory()) {
11851
+ const parent = path17__namespace.dirname(target);
11852
+ if (fs16__namespace.existsSync(parent) && !fs16__namespace.statSync(parent).isDirectory()) {
11079
11853
  throw new Error(
11080
11854
  `Refusing to create ${label} ${target}: ${parent} exists but is not a directory.`
11081
11855
  );
11082
11856
  }
11083
11857
  try {
11084
- fs15__namespace.mkdirSync(parent, { recursive: true });
11858
+ fs16__namespace.mkdirSync(parent, { recursive: true });
11085
11859
  } catch (err) {
11086
11860
  throw new Error(
11087
11861
  `Refusing to create ${label} ${target}: its parent ${parent} could not be created (${err.message}).`
@@ -11139,17 +11913,17 @@ function acquireRunLock(stagingRoot) {
11139
11913
  `;
11140
11914
  for (let attempt = 0; attempt < 2; attempt += 1) {
11141
11915
  try {
11142
- const handle = fs15__namespace.openSync(lockPath, "wx");
11916
+ const handle = fs16__namespace.openSync(lockPath, "wx");
11143
11917
  try {
11144
- fs15__namespace.writeSync(handle, payload);
11918
+ fs16__namespace.writeSync(handle, payload);
11145
11919
  } finally {
11146
- fs15__namespace.closeSync(handle);
11920
+ fs16__namespace.closeSync(handle);
11147
11921
  }
11148
11922
  const stopHeartbeat = startLockHeartbeat(lockPath);
11149
11923
  return () => {
11150
11924
  stopHeartbeat();
11151
11925
  try {
11152
- fs15__namespace.rmSync(lockPath, { force: true });
11926
+ fs16__namespace.rmSync(lockPath, { force: true });
11153
11927
  } catch {
11154
11928
  }
11155
11929
  };
@@ -11169,26 +11943,26 @@ function lockKeyFor(stagingRoot) {
11169
11943
  return sha256Hex2(key).slice(0, 16);
11170
11944
  }
11171
11945
  function canonicalLockTarget(targetPath2) {
11172
- const resolved = path16__namespace.resolve(targetPath2);
11946
+ const resolved = path17__namespace.resolve(targetPath2);
11173
11947
  let existing = resolved;
11174
11948
  const tail = [];
11175
11949
  for (; ; ) {
11176
11950
  try {
11177
- return path16__namespace.join(fs15__namespace.realpathSync(existing), ...tail);
11951
+ return path17__namespace.join(fs16__namespace.realpathSync(existing), ...tail);
11178
11952
  } catch {
11179
- const parent = path16__namespace.dirname(existing);
11953
+ const parent = path17__namespace.dirname(existing);
11180
11954
  if (parent === existing) return resolved;
11181
- tail.unshift(path16__namespace.basename(existing));
11955
+ tail.unshift(path17__namespace.basename(existing));
11182
11956
  existing = parent;
11183
11957
  }
11184
11958
  }
11185
11959
  }
11186
11960
  function lockPathFor(stagingRoot) {
11187
- return path16__namespace.join(os__namespace.tmpdir(), `codebase-snapshot-${lockKeyFor(stagingRoot)}.lock`);
11961
+ return path17__namespace.join(os__namespace.tmpdir(), `codebase-snapshot-${lockKeyFor(stagingRoot)}.lock`);
11188
11962
  }
11189
11963
  function lockHeartbeatAgeMs(lockPath) {
11190
11964
  try {
11191
- return Date.now() - fs15__namespace.statSync(lockPath).mtimeMs;
11965
+ return Date.now() - fs16__namespace.statSync(lockPath).mtimeMs;
11192
11966
  } catch {
11193
11967
  return Number.POSITIVE_INFINITY;
11194
11968
  }
@@ -11196,7 +11970,7 @@ function lockHeartbeatAgeMs(lockPath) {
11196
11970
  function lockOwnerIsGone(lockPath) {
11197
11971
  let raw;
11198
11972
  try {
11199
- raw = fs15__namespace.readFileSync(lockPath, "utf8");
11973
+ raw = fs16__namespace.readFileSync(lockPath, "utf8");
11200
11974
  } catch {
11201
11975
  return false;
11202
11976
  }
@@ -11218,16 +11992,16 @@ function lockOwnerIsGone(lockPath) {
11218
11992
  function reclaimStaleLock(lockPath) {
11219
11993
  let before;
11220
11994
  try {
11221
- before = fs15__namespace.statSync(lockPath);
11995
+ before = fs16__namespace.statSync(lockPath);
11222
11996
  } catch {
11223
11997
  return true;
11224
11998
  }
11225
11999
  if (!lockOwnerIsGone(lockPath)) return false;
11226
12000
  try {
11227
- const current = fs15__namespace.statSync(lockPath);
12001
+ const current = fs16__namespace.statSync(lockPath);
11228
12002
  const sameFile = current.ino === before.ino && current.birthtimeMs === before.birthtimeMs && current.mtimeMs === before.mtimeMs;
11229
12003
  if (!sameFile) return false;
11230
- fs15__namespace.rmSync(lockPath, { force: true });
12004
+ fs16__namespace.rmSync(lockPath, { force: true });
11231
12005
  return true;
11232
12006
  } catch {
11233
12007
  return false;
@@ -11238,12 +12012,12 @@ function lockFileIsAncient(lockPath) {
11238
12012
  }
11239
12013
  function writeManifestAtomically(manifestPath, manifest) {
11240
12014
  const tempPath = `${manifestPath}.${process.pid}.tmp`;
11241
- fs15__namespace.writeFileSync(tempPath, JSON.stringify(manifest, null, 2), "utf8");
12015
+ fs16__namespace.writeFileSync(tempPath, JSON.stringify(manifest, null, 2), "utf8");
11242
12016
  try {
11243
- fs15__namespace.renameSync(tempPath, manifestPath);
12017
+ fs16__namespace.renameSync(tempPath, manifestPath);
11244
12018
  } catch (err) {
11245
12019
  try {
11246
- fs15__namespace.rmSync(tempPath, { force: true });
12020
+ fs16__namespace.rmSync(tempPath, { force: true });
11247
12021
  } catch {
11248
12022
  }
11249
12023
  throw err;
@@ -11268,21 +12042,21 @@ function swapIntoPlace(stagingDir, outDir, beforeSwap) {
11268
12042
  }
11269
12043
  }
11270
12044
  function recoverInterruptedPublish(outDir) {
11271
- if (fs15__namespace.existsSync(outDir)) return;
11272
- const parent = path16__namespace.dirname(outDir);
11273
- const base = path16__namespace.basename(outDir);
12045
+ if (fs16__namespace.existsSync(outDir)) return;
12046
+ const parent = path17__namespace.dirname(outDir);
12047
+ const base = path17__namespace.basename(outDir);
11274
12048
  let backups;
11275
12049
  try {
11276
- backups = fs15__namespace.readdirSync(parent).filter((name) => name.startsWith(`${base}.backup-`));
12050
+ backups = fs16__namespace.readdirSync(parent).filter((name) => name.startsWith(`${base}.backup-`));
11277
12051
  } catch {
11278
12052
  return;
11279
12053
  }
11280
12054
  if (backups.length !== 1) return;
11281
- const backupDir = path16__namespace.join(parent, backups[0]);
12055
+ const backupDir = path17__namespace.join(parent, backups[0]);
11282
12056
  const { marker: marker2, problem } = readOwnershipMarker(backupDir);
11283
12057
  if (problem !== null || marker2 === null || marker2.state !== "complete") return;
11284
12058
  try {
11285
- fs15__namespace.renameSync(backupDir, outDir);
12059
+ fs16__namespace.renameSync(backupDir, outDir);
11286
12060
  process.stderr.write(
11287
12061
  `\u26A0 Recovered ${outDir} from ${backupDir}, left by an interrupted run. That snapshot is the one from before the interrupted run.
11288
12062
  `
@@ -11292,16 +12066,16 @@ function recoverInterruptedPublish(outDir) {
11292
12066
  }
11293
12067
  function swapOnce(stagingDir, outDir, beforeSwap) {
11294
12068
  const backupDir = `${outDir}.backup-${process.pid}-${Date.now()}`;
11295
- const hadPrevious = fs15__namespace.existsSync(outDir);
12069
+ const hadPrevious = fs16__namespace.existsSync(outDir);
11296
12070
  if (hadPrevious) beforeSwap?.();
11297
12071
  let movedAside = false;
11298
12072
  if (hadPrevious) {
11299
12073
  try {
11300
- fs15__namespace.renameSync(outDir, backupDir);
12074
+ fs16__namespace.renameSync(outDir, backupDir);
11301
12075
  movedAside = true;
11302
12076
  } catch (err) {
11303
12077
  if (!isLockError(err)) throw err;
11304
- fs15__namespace.rmSync(outDir, { recursive: true, force: true, maxRetries: 5, retryDelay: 100 });
12078
+ fs16__namespace.rmSync(outDir, { recursive: true, force: true, maxRetries: 5, retryDelay: 100 });
11305
12079
  process.stderr.write(
11306
12080
  `\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.
11307
12081
  `
@@ -11310,26 +12084,26 @@ function swapOnce(stagingDir, outDir, beforeSwap) {
11310
12084
  }
11311
12085
  try {
11312
12086
  try {
11313
- fs15__namespace.renameSync(stagingDir, outDir);
12087
+ fs16__namespace.renameSync(stagingDir, outDir);
11314
12088
  } catch (err) {
11315
12089
  if (err.code !== "EXDEV") throw err;
11316
12090
  const partialDir = `${outDir}.partial-${process.pid}-${Date.now()}`;
11317
12091
  try {
11318
- fs15__namespace.cpSync(stagingDir, partialDir, { recursive: true });
11319
- fs15__namespace.renameSync(partialDir, outDir);
11320
- fs15__namespace.rmSync(stagingDir, { recursive: true, force: true });
12092
+ fs16__namespace.cpSync(stagingDir, partialDir, { recursive: true });
12093
+ fs16__namespace.renameSync(partialDir, outDir);
12094
+ fs16__namespace.rmSync(stagingDir, { recursive: true, force: true });
11321
12095
  } catch (copyErr) {
11322
12096
  try {
11323
- fs15__namespace.rmSync(partialDir, { recursive: true, force: true });
12097
+ fs16__namespace.rmSync(partialDir, { recursive: true, force: true });
11324
12098
  } catch {
11325
12099
  }
11326
12100
  throw copyErr;
11327
12101
  }
11328
12102
  }
11329
12103
  } catch (err) {
11330
- if (hadPrevious && movedAside && fs15__namespace.existsSync(backupDir)) {
11331
- if (fs15__namespace.existsSync(outDir)) fs15__namespace.rmSync(outDir, { recursive: true, force: true });
11332
- fs15__namespace.renameSync(backupDir, outDir);
12104
+ if (hadPrevious && movedAside && fs16__namespace.existsSync(backupDir)) {
12105
+ if (fs16__namespace.existsSync(outDir)) fs16__namespace.rmSync(outDir, { recursive: true, force: true });
12106
+ fs16__namespace.renameSync(backupDir, outDir);
11333
12107
  } else if (hadPrevious && !movedAside) {
11334
12108
  process.stderr.write(
11335
12109
  `\u26A0 The previous snapshot at ${outDir} was removed and the new one could not be moved into place. It is complete at ${stagingDir}.
@@ -11340,7 +12114,7 @@ function swapOnce(stagingDir, outDir, beforeSwap) {
11340
12114
  }
11341
12115
  if (hadPrevious) {
11342
12116
  try {
11343
- fs15__namespace.rmSync(backupDir, { recursive: true, force: true });
12117
+ fs16__namespace.rmSync(backupDir, { recursive: true, force: true });
11344
12118
  } catch (err) {
11345
12119
  process.stderr.write(
11346
12120
  `\u26A0 The previous snapshot could not be removed from ${backupDir} (${err.message}). The new snapshot is in place; delete that directory by hand when convenient.
@@ -11399,7 +12173,55 @@ function runAfterGenerate(config, manifest) {
11399
12173
  return Promise.resolve(returned).finally(releaseRedirect);
11400
12174
  }
11401
12175
  function partitionByBudget(files, config, fingerprint) {
11402
- const budgetFor = (file) => config.budgets.byLayer[file.layer] ?? config.budgets.default;
12176
+ const configured = {
12177
+ parts: partitionWithBudgets(files, config.budgets, fingerprint),
12178
+ budgets: config.budgets,
12179
+ maxPartBytes: config.maxPartBytes,
12180
+ warnings: []
12181
+ };
12182
+ const limit = config.maxParts;
12183
+ if (limit === null || !config.artifacts.parts || configured.parts.length <= limit) return configured;
12184
+ const totalBytes = files.reduce((total, file) => total + file.includedBytes, 0);
12185
+ let target = Math.max(config.budgets.default, Math.ceil(totalBytes * 1.15 / limit));
12186
+ const seen = [];
12187
+ let low = config.budgets.default;
12188
+ let fitting = null;
12189
+ for (let pass = 0; pass < 6; pass += 1) {
12190
+ const parts2 = partitionWithBudgets(files, scaleBudgets(config.budgets, target), fingerprint);
12191
+ if (parts2.length <= limit) {
12192
+ fitting = { target, parts: parts2 };
12193
+ break;
12194
+ }
12195
+ seen.push(parts2.length);
12196
+ low = target;
12197
+ target = Math.ceil(target * 1.3);
12198
+ }
12199
+ if (fitting === null) {
12200
+ throw new Error(
12201
+ `maxParts ${limit} could not be met: ${seen.join(", ")} part(s) at budgets up to ${formatNumber(target)} B. Raise maxParts, include fewer files, or drop the setting.`
12202
+ );
12203
+ }
12204
+ for (let step = 0; step < 3 && fitting.target - low > 8192; step += 1) {
12205
+ const middle = Math.round((low + fitting.target) / 2);
12206
+ const parts2 = partitionWithBudgets(files, scaleBudgets(config.budgets, middle), fingerprint);
12207
+ if (parts2.length <= limit) fitting = { target: middle, parts: parts2 };
12208
+ else low = middle;
12209
+ }
12210
+ const { target: chosen, parts } = fitting;
12211
+ const budgets = scaleBudgets(config.budgets, chosen);
12212
+ const maxPartBytes = Math.max(config.maxPartBytes, chosen);
12213
+ const warnings = [
12214
+ `maxParts ${limit}: the part budget grew from ${formatNumber(config.maxPartBytes)} B to ${formatNumber(maxPartBytes)} B, and the snapshot now has ${formatNumber(parts.length)} part(s).`
12215
+ ];
12216
+ if (maxPartBytes > config.maxPartBytes) {
12217
+ warnings.push(
12218
+ `maxParts ${limit}: parts are now above the configured maxPartBytes (${formatNumber(config.maxPartBytes)} B). A larger part is more tokens for the destination to take at once, and some destinations cap a single file.`
12219
+ );
12220
+ }
12221
+ return { parts, budgets, maxPartBytes, warnings };
12222
+ }
12223
+ function partitionWithBudgets(files, budgets, fingerprint) {
12224
+ const budgetFor = (file) => budgets.byLayer[file.layer] ?? budgets.default;
11403
12225
  const buckets = /* @__PURE__ */ new Map();
11404
12226
  for (const file of files) {
11405
12227
  const budget = budgetFor(file);
@@ -11416,6 +12238,18 @@ function partitionByBudget(files, config, fingerprint) {
11416
12238
  fingerprint
11417
12239
  );
11418
12240
  }
12241
+ function scaleBudgets(budgets, targetDefault) {
12242
+ const factor = targetDefault / budgets.default;
12243
+ return {
12244
+ default: Math.max(budgets.default, Math.round(targetDefault)),
12245
+ byLayer: Object.fromEntries(
12246
+ Object.entries(budgets.byLayer).map(([name, bytes]) => [
12247
+ name,
12248
+ Math.max(bytes, Math.round(bytes * factor))
12249
+ ])
12250
+ )
12251
+ };
12252
+ }
11419
12253
  function generateSnapshot(configInput, options) {
11420
12254
  assertUsableConfigInput(configInput);
11421
12255
  const config = isResolvedConfig(configInput) ? normalizeResolvedConfig(configInput) : resolveConfig(configInput ?? null);
@@ -11438,7 +12272,7 @@ function generateSnapshot(configInput, options) {
11438
12272
  // first run cannot have marked them yet, so the name alone keeps a run from recording its own
11439
12273
  // output — but only at these exact paths, not at every directory that shares the name.
11440
12274
  toolOwnedPaths: [config.outDir, config.tmpDir].map(
11441
- (directory) => path16__namespace.relative(config.cwd, path16__namespace.resolve(config.cwd, directory)).replace(/\\/g, "/")
12275
+ (directory) => path17__namespace.relative(config.cwd, path17__namespace.resolve(config.cwd, directory)).replace(/\\/g, "/")
11442
12276
  ).filter((relative15) => relative15.length > 0 && !relative15.startsWith("..")),
11443
12277
  // A staged path can be absent from the working tree while its index blob exists. Discovery
11444
12278
  // lists the working tree, so those paths would never reach the scan at all.
@@ -11467,7 +12301,7 @@ function generateSnapshot(configInput, options) {
11467
12301
  let totalSizeBytes = 0;
11468
12302
  let largeFileCount = 0;
11469
12303
  for (const relativePath of candidateFiles) {
11470
- const absolutePath = path16__namespace.join(config.cwd, relativePath);
12304
+ const absolutePath = path17__namespace.join(config.cwd, relativePath);
11471
12305
  const fromIndex = stagedPaths.has(relativePath);
11472
12306
  let buffer;
11473
12307
  let sizeBytes;
@@ -11498,9 +12332,9 @@ function generateSnapshot(configInput, options) {
11498
12332
  } else {
11499
12333
  let stats;
11500
12334
  try {
11501
- stats = fs15__namespace.statSync(absolutePath);
12335
+ stats = fs16__namespace.statSync(absolutePath);
11502
12336
  if (!stats.isFile()) {
11503
- const nestedRepository = stats.isDirectory() && fs15__namespace.existsSync(path16__namespace.join(absolutePath, ".git"));
12337
+ const nestedRepository = stats.isDirectory() && fs16__namespace.existsSync(path17__namespace.join(absolutePath, ".git"));
11504
12338
  skipped.push(
11505
12339
  nestedRepository ? {
11506
12340
  path: relativePath,
@@ -11536,7 +12370,7 @@ function generateSnapshot(configInput, options) {
11536
12370
  continue;
11537
12371
  }
11538
12372
  try {
11539
- buffer = fs15__namespace.readFileSync(absolutePath);
12373
+ buffer = fs16__namespace.readFileSync(absolutePath);
11540
12374
  } catch (err) {
11541
12375
  const code = err.code;
11542
12376
  skipped.push({
@@ -11665,14 +12499,14 @@ function generateSnapshot(configInput, options) {
11665
12499
  (finding) => finding.path === void 0 || keep.has(finding.path)
11666
12500
  );
11667
12501
  retain(encodingNotes, (note) => keep.has(note.path));
11668
- retain(oversizeSummaryPaths, (path22) => keep.has(path22));
11669
- retain(previewSummaryPaths, (path22) => keep.has(path22));
12502
+ retain(oversizeSummaryPaths, (path23) => keep.has(path23));
12503
+ retain(previewSummaryPaths, (path23) => keep.has(path23));
11670
12504
  retain(fileWarnings, (warning) => keep.has(warning.path));
11671
- for (const path22 of [...monolithBodies.keys()]) {
11672
- if (!keep.has(path22)) monolithBodies.delete(path22);
12505
+ for (const path23 of [...monolithBodies.keys()]) {
12506
+ if (!keep.has(path23)) monolithBodies.delete(path23);
11673
12507
  }
11674
- for (const path22 of [...skippedSummaryImports.keys()]) {
11675
- if (!keep.has(path22)) skippedSummaryImports.delete(path22);
12508
+ for (const path23 of [...skippedSummaryImports.keys()]) {
12509
+ if (!keep.has(path23)) skippedSummaryImports.delete(path23);
11676
12510
  }
11677
12511
  }
11678
12512
  if (changedScope !== null) {
@@ -11744,7 +12578,8 @@ function generateSnapshot(configInput, options) {
11744
12578
  );
11745
12579
  }
11746
12580
  }
11747
- const parts = partitionByBudget(files, config, fingerprint);
12581
+ const partitioned = partitionByBudget(files, config, fingerprint);
12582
+ const parts = partitioned.parts;
11748
12583
  const truncatedPreviewCount = files.filter((file) => file.isPreviewTruncated).length;
11749
12584
  const incomplete = files.flatMap((file) => {
11750
12585
  if (file.truncationReason === void 0) return [];
@@ -11781,7 +12616,10 @@ function generateSnapshot(configInput, options) {
11781
12616
  // the README and the audit report.
11782
12617
  git: { ...gitInfo, branch: maskPathText(gitInfo.branch, config.secretRules) },
11783
12618
  budgets: {
11784
- maxPartBytes: config.maxPartBytes,
12619
+ // The ceiling the parts actually honour. It equals the configured one unless `maxParts`
12620
+ // grew it; `config.maxPartBytes` below keeps the configured value, because that is what
12621
+ // `validate` compares against the config on disk.
12622
+ maxPartBytes: partitioned.maxPartBytes,
11785
12623
  largeFileBytes: config.largeFileBytes
11786
12624
  },
11787
12625
  config: {
@@ -11799,6 +12637,16 @@ function generateSnapshot(configInput, options) {
11799
12637
  // invisible in the manifest that is supposed to describe the run.
11800
12638
  maxMonolithBytes: config.maxMonolithBytes ?? null,
11801
12639
  includeSensitiveFiles: config.includeSensitiveFiles,
12640
+ // The destination the instructions were written for. Not part of `digest`: the payload is
12641
+ // identical whatever this says, and a new delivery preference must not make an existing
12642
+ // snapshot fail `validate` as configuration drift.
12643
+ attachmentSlots: config.attachmentSlots,
12644
+ // The part-count ceiling the run enforced. Recorded because it decided the part sizes, and
12645
+ // omitted from `digest` when it is off so an existing snapshot does not start reporting
12646
+ // configuration drift.
12647
+ maxParts: config.maxParts ?? null,
12648
+ promptTask: config.promptTask,
12649
+ ...config.brief === void 0 ? {} : { brief: { path: config.brief.path, digest: config.brief.digest } },
11802
12650
  discovery: config.discovery ?? "auto",
11803
12651
  // A changed-files scope decides which files are in the snapshot, so the manifest that
11804
12652
  // describes the run has to name it.
@@ -11869,6 +12717,10 @@ function generateSnapshot(configInput, options) {
11869
12717
  incomplete,
11870
12718
  warnings
11871
12719
  };
12720
+ if (partitioned.warnings.length > 0) {
12721
+ manifest.warnings.push(...partitioned.warnings);
12722
+ manifest.totals.warningCount = manifest.warnings.length;
12723
+ }
11872
12724
  manifest.totals.redactedLines = secretFindings.length;
11873
12725
  manifest.totals.warningCount = manifest.warnings.length;
11874
12726
  if (files.some((file) => file.isPreviewTruncated) && config.largeFileBytes < config.maxPartBytes) {
@@ -11925,6 +12777,17 @@ function generateSnapshot(configInput, options) {
11925
12777
  if (auditText !== null) manifest.artifacts.audit = artifactRecord(auditText);
11926
12778
  const readmeText = artifacts.readme ? generateReadme(manifest, artifacts) : null;
11927
12779
  if (readmeText !== null) manifest.artifacts.readme = artifactRecord(readmeText);
12780
+ const promptText = artifacts.prompt ? generatePrompt(manifest, artifacts, {
12781
+ slots: config.attachmentSlots,
12782
+ task: config.promptTask,
12783
+ brief: maskOwnerBrief(config.brief, config.secretRules),
12784
+ history: recentCommits(config.cwd).map((commit) => ({
12785
+ subject: maskPathText(commit.subject, config.secretRules),
12786
+ body: maskPathText(commit.body, config.secretRules)
12787
+ })),
12788
+ overview: maskOverview(readProjectOverview(config.cwd), config.secretRules)
12789
+ }) : null;
12790
+ if (promptText !== null) manifest.artifacts.prompt = artifactRecord(promptText);
11928
12791
  if (projectTree !== null) manifest.artifacts.projectTree = artifactRecord(projectTree);
11929
12792
  let monolithJson = null;
11930
12793
  let monolithMarkdown = null;
@@ -11999,12 +12862,12 @@ function generateSnapshot(configInput, options) {
11999
12862
  let releaseDeferred = false;
12000
12863
  try {
12001
12864
  ensureParentDirectory(outDir, "outDir");
12002
- fs15__namespace.mkdirSync(tmpDir, { recursive: true });
12865
+ fs16__namespace.mkdirSync(tmpDir, { recursive: true });
12003
12866
  cleanStaleRunDirs(tmpDir);
12004
12867
  const snapshotId = crypto3__namespace.randomUUID();
12005
12868
  const createdAt = (/* @__PURE__ */ new Date()).toISOString();
12006
- stagingDir = path16__namespace.join(tmpDir, `${RUN_DIR_PREFIX}${process.pid}-${snapshotId.slice(0, 8)}`);
12007
- fs15__namespace.mkdirSync(stagingDir);
12869
+ stagingDir = path17__namespace.join(tmpDir, `${RUN_DIR_PREFIX}${process.pid}-${snapshotId.slice(0, 8)}`);
12870
+ fs16__namespace.mkdirSync(stagingDir);
12008
12871
  writeOwnershipMarker(stagingDir, {
12009
12872
  generator: GENERATOR_NAME,
12010
12873
  version: GENERATOR_VERSION,
@@ -12014,30 +12877,30 @@ function generateSnapshot(configInput, options) {
12014
12877
  id: snapshotId,
12015
12878
  pid: process.pid
12016
12879
  });
12017
- const partsDir = path16__namespace.join(stagingDir, "parts");
12018
- const reportsDir = path16__namespace.join(stagingDir, "reports");
12019
- if (artifacts.parts) fs15__namespace.mkdirSync(partsDir, { recursive: true });
12880
+ const partsDir = path17__namespace.join(stagingDir, "parts");
12881
+ const reportsDir = path17__namespace.join(stagingDir, "reports");
12882
+ if (artifacts.parts) fs16__namespace.mkdirSync(partsDir, { recursive: true });
12020
12883
  if (artifacts.navigation || artifacts.projectTree || artifacts.audit || config.sarif === true) {
12021
- fs15__namespace.mkdirSync(reportsDir, { recursive: true });
12884
+ fs16__namespace.mkdirSync(reportsDir, { recursive: true });
12022
12885
  }
12023
12886
  const writtenArtifacts = /* @__PURE__ */ new Map();
12024
12887
  const writeArtifact = (targetDir, relativeEntry, data) => {
12025
- const full = path16__namespace.join(targetDir, ...relativeEntry.split("/"));
12026
- fs15__namespace.writeFileSync(full, data, "utf8");
12027
- const stats = fs15__namespace.statSync(full);
12888
+ const full = path17__namespace.join(targetDir, ...relativeEntry.split("/"));
12889
+ fs16__namespace.writeFileSync(full, data, "utf8");
12890
+ const stats = fs16__namespace.statSync(full);
12028
12891
  writtenArtifacts.set(relativeEntry, {
12029
12892
  digest: { path: relativeEntry, bytes: stats.size, sha256: sha256Hex2(data) },
12030
12893
  mtimeMs: stats.mtimeMs
12031
12894
  });
12032
12895
  };
12033
12896
  const recordArtifact = (targetDir, relativeEntry) => {
12034
- const full = path16__namespace.join(targetDir, ...relativeEntry.split("/"));
12035
- const stats = fs15__namespace.statSync(full);
12897
+ const full = path17__namespace.join(targetDir, ...relativeEntry.split("/"));
12898
+ const stats = fs16__namespace.statSync(full);
12036
12899
  writtenArtifacts.set(relativeEntry, {
12037
12900
  digest: {
12038
12901
  path: relativeEntry,
12039
12902
  bytes: stats.size,
12040
- sha256: sha256Hex2(fs15__namespace.readFileSync(full))
12903
+ sha256: sha256Hex2(fs16__namespace.readFileSync(full))
12041
12904
  },
12042
12905
  mtimeMs: stats.mtimeMs
12043
12906
  });
@@ -12062,6 +12925,9 @@ function generateSnapshot(configInput, options) {
12062
12925
  if (readmeText !== null) {
12063
12926
  writeArtifact(stagingDir, "README.md", readmeText);
12064
12927
  }
12928
+ if (promptText !== null) {
12929
+ writeArtifact(stagingDir, "PROMPT.md", promptText);
12930
+ }
12065
12931
  if (artifacts.manifest) {
12066
12932
  writeArtifact(stagingDir, "manifest.json", JSON.stringify(manifest, null, 2));
12067
12933
  }
@@ -12082,7 +12948,7 @@ function generateSnapshot(configInput, options) {
12082
12948
  const shipHookState = () => {
12083
12949
  if (!markerBelongsTo(outDir, snapshotId)) return;
12084
12950
  if (artifacts.manifest && manifest.warnings.length !== warningsBeforeHook) {
12085
- writeManifestAtomically(path16__namespace.join(outDir, "manifest.json"), manifest);
12951
+ writeManifestAtomically(path17__namespace.join(outDir, "manifest.json"), manifest);
12086
12952
  recordArtifact(outDir, "manifest.json");
12087
12953
  }
12088
12954
  writeOwnershipMarker(
@@ -12125,7 +12991,7 @@ function generateSnapshot(configInput, options) {
12125
12991
  } catch (err) {
12126
12992
  if (stagingDir !== null) {
12127
12993
  try {
12128
- fs15__namespace.rmSync(stagingDir, { recursive: true, force: true });
12994
+ fs16__namespace.rmSync(stagingDir, { recursive: true, force: true });
12129
12995
  } catch {
12130
12996
  }
12131
12997
  }
@@ -12219,8 +13085,8 @@ function findSection(sections, relativePath) {
12219
13085
  if (exact) return exact;
12220
13086
  const foldedPath = rendered.toLowerCase();
12221
13087
  const folded = sections.filter((section) => {
12222
- const path22 = section.path.toLowerCase();
12223
- return path22 === relativePath.toLowerCase() || path22 === foldedPath;
13088
+ const path23 = section.path.toLowerCase();
13089
+ return path23 === relativePath.toLowerCase() || path23 === foldedPath;
12224
13090
  });
12225
13091
  return folded.length === 1 ? folded[0] : null;
12226
13092
  }
@@ -12246,9 +13112,9 @@ function foldForComparison(value) {
12246
13112
  return process.platform === "win32" || process.platform === "darwin" ? value.toLowerCase() : value;
12247
13113
  }
12248
13114
  function canonicalPath(value) {
12249
- const absolute = path16__namespace.resolve(value);
13115
+ const absolute = path17__namespace.resolve(value);
12250
13116
  try {
12251
- return fs15__namespace.realpathSync(absolute);
13117
+ return fs16__namespace.realpathSync(absolute);
12252
13118
  } catch {
12253
13119
  return absolute;
12254
13120
  }
@@ -12256,29 +13122,29 @@ function canonicalPath(value) {
12256
13122
  function isInside3(parent, child) {
12257
13123
  const foldedParent = foldForComparison(parent);
12258
13124
  const foldedChild = foldForComparison(child);
12259
- return foldedChild === foldedParent || foldedChild.startsWith(`${foldedParent}${path16__namespace.sep}`);
13125
+ return foldedChild === foldedParent || foldedChild.startsWith(`${foldedParent}${path17__namespace.sep}`);
12260
13126
  }
12261
13127
  function resolveThroughExistingAncestor(target) {
12262
13128
  let existing = target;
12263
13129
  const missing = [];
12264
- while (!fs15__namespace.existsSync(existing)) {
12265
- missing.unshift(path16__namespace.basename(existing));
12266
- const parent = path16__namespace.dirname(existing);
13130
+ while (!fs16__namespace.existsSync(existing)) {
13131
+ missing.unshift(path17__namespace.basename(existing));
13132
+ const parent = path17__namespace.dirname(existing);
12267
13133
  if (parent === existing) break;
12268
13134
  existing = parent;
12269
13135
  }
12270
13136
  const resolved = canonicalPath(existing);
12271
- return missing.length === 0 ? resolved : path16__namespace.join(resolved, ...missing);
13137
+ return missing.length === 0 ? resolved : path17__namespace.join(resolved, ...missing);
12272
13138
  }
12273
13139
  function resolveRoot(requested, context) {
12274
13140
  if (requested !== void 0 && (typeof requested !== "string" || requested.trim().length === 0)) {
12275
13141
  return { ok: false, message: '"root" must be a non-empty string when provided.' };
12276
13142
  }
12277
13143
  const wanted = typeof requested === "string" ? requested.trim() : context.cwd;
12278
- const absolute = path16__namespace.resolve(context.cwd, wanted);
13144
+ const absolute = path17__namespace.resolve(context.cwd, wanted);
12279
13145
  let stats;
12280
13146
  try {
12281
- stats = fs15__namespace.statSync(absolute);
13147
+ stats = fs16__namespace.statSync(absolute);
12282
13148
  } catch {
12283
13149
  return { ok: false, message: `"${wanted}" does not exist, so it cannot be a repository root.` };
12284
13150
  }
@@ -12330,7 +13196,7 @@ async function openWorkspace(root, overrides = {}, allowedRoots, options = {}) {
12330
13196
  }
12331
13197
  const requested = overrides.outDir.trim();
12332
13198
  const permitted = allowedRoots !== void 0 && allowedRoots.length > 0 ? allowedRoots : [root];
12333
- const resolved = resolveThroughExistingAncestor(path16__namespace.resolve(root, requested));
13199
+ const resolved = resolveThroughExistingAncestor(path17__namespace.resolve(root, requested));
12334
13200
  if (!permitted.some((allowed) => isInside3(canonicalPath(allowed), resolved))) {
12335
13201
  const shown = permitted.map((allowed) => canonicalPath(allowed)).join(", ");
12336
13202
  return {
@@ -12363,25 +13229,25 @@ async function openWorkspace(root, overrides = {}, allowedRoots, options = {}) {
12363
13229
  var MANIFEST_CACHE_LIMIT = 8;
12364
13230
  var manifestCache = /* @__PURE__ */ new Map();
12365
13231
  function manifestPathFor(workspace) {
12366
- return path16__namespace.resolve(workspace.root, workspace.config.outDir, "manifest.json");
13232
+ return path17__namespace.resolve(workspace.root, workspace.config.outDir, "manifest.json");
12367
13233
  }
12368
13234
  function partPathFor(workspace, filename) {
12369
13235
  if (filename.length === 0 || filename.includes("\0")) return null;
12370
- const partsDir = path16__namespace.resolve(workspace.root, workspace.config.outDir, "parts");
12371
- const resolved = path16__namespace.resolve(partsDir, filename);
12372
- const relative15 = path16__namespace.relative(partsDir, resolved);
12373
- if (relative15.length === 0 || relative15.includes(path16__namespace.sep) || relative15.includes("/") || relative15.includes("\\") || path16__namespace.isAbsolute(relative15)) {
13236
+ const partsDir = path17__namespace.resolve(workspace.root, workspace.config.outDir, "parts");
13237
+ const resolved = path17__namespace.resolve(partsDir, filename);
13238
+ const relative15 = path17__namespace.relative(partsDir, resolved);
13239
+ if (relative15.length === 0 || relative15.includes(path17__namespace.sep) || relative15.includes("/") || relative15.includes("\\") || path17__namespace.isAbsolute(relative15)) {
12374
13240
  return null;
12375
13241
  }
12376
13242
  let stats;
12377
13243
  try {
12378
- stats = fs15__namespace.lstatSync(resolved);
13244
+ stats = fs16__namespace.lstatSync(resolved);
12379
13245
  } catch {
12380
13246
  return null;
12381
13247
  }
12382
13248
  if (!stats.isFile()) return null;
12383
13249
  try {
12384
- if (path16__namespace.dirname(fs15__namespace.realpathSync(resolved)) !== fs15__namespace.realpathSync(partsDir)) return null;
13250
+ if (path17__namespace.dirname(fs16__namespace.realpathSync(resolved)) !== fs16__namespace.realpathSync(partsDir)) return null;
12385
13251
  } catch {
12386
13252
  return null;
12387
13253
  }
@@ -12389,10 +13255,10 @@ function partPathFor(workspace, filename) {
12389
13255
  }
12390
13256
  function readManifest3(workspace) {
12391
13257
  const file = manifestPathFor(workspace);
12392
- const shown = path16__namespace.relative(workspace.root, file).split(path16__namespace.sep).join("/") || file;
13258
+ const shown = path17__namespace.relative(workspace.root, file).split(path17__namespace.sep).join("/") || file;
12393
13259
  let stats;
12394
13260
  try {
12395
- stats = fs15__namespace.statSync(file);
13261
+ stats = fs16__namespace.statSync(file);
12396
13262
  } catch {
12397
13263
  return {
12398
13264
  ok: false,
@@ -12406,7 +13272,7 @@ function readManifest3(workspace) {
12406
13272
  }
12407
13273
  let raw;
12408
13274
  try {
12409
- raw = fs15__namespace.readFileSync(file, "utf8");
13275
+ raw = fs16__namespace.readFileSync(file, "utf8");
12410
13276
  } catch (error) {
12411
13277
  return {
12412
13278
  ok: false,
@@ -12518,7 +13384,7 @@ function formatBytes(bytes) {
12518
13384
  return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
12519
13385
  }
12520
13386
  function relativeFor(workspace, absolute) {
12521
- return path16__namespace.relative(workspace.root, absolute).split(path16__namespace.sep).join("/");
13387
+ return path17__namespace.relative(workspace.root, absolute).split(path17__namespace.sep).join("/");
12522
13388
  }
12523
13389
  function capped(values, limit = 20) {
12524
13390
  return { count: values.length, sample: values.slice(0, limit) };
@@ -12537,13 +13403,13 @@ function summarizeDrift(drift) {
12537
13403
  function toRelativePath(root, value) {
12538
13404
  const cleaned = value.trim();
12539
13405
  if (cleaned.length === 0 || cleaned.includes("\0")) return null;
12540
- const resolvedRoot = path16__namespace.resolve(root);
12541
- const absolute = path16__namespace.resolve(resolvedRoot, cleaned);
12542
- const relative15 = path16__namespace.relative(resolvedRoot, absolute);
12543
- if (relative15 === "" || relative15 === ".." || relative15.startsWith(`..${path16__namespace.sep}`) || path16__namespace.isAbsolute(relative15)) {
13406
+ const resolvedRoot = path17__namespace.resolve(root);
13407
+ const absolute = path17__namespace.resolve(resolvedRoot, cleaned);
13408
+ const relative15 = path17__namespace.relative(resolvedRoot, absolute);
13409
+ if (relative15 === "" || relative15 === ".." || relative15.startsWith(`..${path17__namespace.sep}`) || path17__namespace.isAbsolute(relative15)) {
12544
13410
  return null;
12545
13411
  }
12546
- return relative15.split(path16__namespace.sep).join("/");
13412
+ return relative15.split(path17__namespace.sep).join("/");
12547
13413
  }
12548
13414
  function symbolsOf(entry) {
12549
13415
  const summary = entry.summary;
@@ -12773,7 +13639,7 @@ var generateTool = {
12773
13639
  if (!result.ok) return failure(result.message);
12774
13640
  const summary = result.summary;
12775
13641
  forgetManifest(manifestPathFor(workspace));
12776
- const written = relativeFor(workspace, path16__namespace.resolve(workspace.root, workspace.config.outDir));
13642
+ const written = relativeFor(workspace, path17__namespace.resolve(workspace.root, workspace.config.outDir));
12777
13643
  const lines = [
12778
13644
  `Wrote ${written}/`,
12779
13645
  `Files: ${summary.totalFiles} included, ${summary.skippedCount} skipped, ${plural(summary.partsCount, "part")}`,
@@ -13174,7 +14040,7 @@ var readTool = {
13174
14040
  }
13175
14041
  let partText;
13176
14042
  try {
13177
- partText = fs15__namespace.readFileSync(partPath, "utf8");
14043
+ partText = fs16__namespace.readFileSync(partPath, "utf8");
13178
14044
  } catch {
13179
14045
  return failure(
13180
14046
  `${entry.part} could not be read, so the snapshot is damaged. Run snapshot_generate to rebuild it.`
@@ -13478,6 +14344,9 @@ var VALIDATE_OPTIONS = [
13478
14344
  "max-part-tokens",
13479
14345
  "large-file-bytes",
13480
14346
  "max-monolith-bytes",
14347
+ "max-parts",
14348
+ "brief",
14349
+ "prompt-task",
13481
14350
  "include-monolith",
13482
14351
  "include-sensitive-files",
13483
14352
  "skip-artifacts",
@@ -13503,6 +14372,10 @@ var COMMAND_OPTION_SCOPE = {
13503
14372
  "max-part-tokens",
13504
14373
  "large-file-bytes",
13505
14374
  "max-monolith-bytes",
14375
+ "attachment-slots",
14376
+ "max-parts",
14377
+ "brief",
14378
+ "prompt-task",
13506
14379
  "include-monolith",
13507
14380
  "include-sensitive-files",
13508
14381
  "skip-artifacts",
@@ -13648,6 +14521,7 @@ var PACKAGE_NAME = "codebase-snapshot";
13648
14521
  var MAJOR_VERSION = GENERATOR_VERSION.split(".")[0];
13649
14522
  var ARTIFACT_SUMMARY = {
13650
14523
  readme: "README.md describing the snapshot at the output root.",
14524
+ prompt: "PROMPT.md: the instruction sheet to paste with the snapshot, rendered from its manifest.",
13651
14525
  manifest: "manifest.json: machine-readable index of every file, part, hash and config.",
13652
14526
  parts: "parts/*.md: the packed, budget-limited markdown parts that carry the code.",
13653
14527
  navigation: "reports/navigation.md: links between parts and layers.",
@@ -13657,6 +14531,7 @@ var ARTIFACT_SUMMARY = {
13657
14531
  };
13658
14532
  var ARTIFACT_DEFAULTS = {
13659
14533
  readme: true,
14534
+ prompt: true,
13660
14535
  manifest: true,
13661
14536
  parts: true,
13662
14537
  navigation: true,
@@ -13797,9 +14672,9 @@ function buildAgentContract() {
13797
14672
  {
13798
14673
  step: 6,
13799
14674
  id: "consume",
13800
- run: "read ./snapshot/parts/*.md, then ./snapshot/manifest.json, then ./snapshot/reports/audit.md",
14675
+ run: "read ./snapshot/PROMPT.md first, then ./snapshot/parts/*.md, ./snapshot/manifest.json and ./snapshot/reports/audit.md",
13801
14676
  expect: "the code, the index of what was included, and the risk findings",
13802
- notes: "manifest.json.files[] lists every included file with layer, kind, language, part and summary. manifest.skipped[] explains every file that was left out and why; manifest.incomplete[] lists every included file that is not present in full, with its missing line ranges."
14677
+ notes: "manifest.json.files[] lists every included file with layer, kind, language, part and summary. manifest.skipped[] explains every file that was left out and why; manifest.incomplete[] lists every included file that is not present in full, with its missing line ranges. PROMPT.md is the instruction sheet for whoever reads the snapshot; it is rendered from the manifest, so it names this run's omissions rather than describing snapshots in general."
13803
14678
  }
13804
14679
  ],
13805
14680
  commands: [
@@ -13936,6 +14811,34 @@ function buildAgentContract() {
13936
14811
  appliesTo: optionAppliesTo("discovery"),
13937
14812
  summary: "How files are discovered: auto (git when usable), git (require git), walk (read .gitignore files directly, including nested ones; the escape hatch for a .git that cannot be listed)."
13938
14813
  },
14814
+ {
14815
+ flag: "--attachment-slots",
14816
+ type: "number",
14817
+ default: "10",
14818
+ appliesTo: optionAppliesTo("attachment-slots"),
14819
+ summary: "Files the destination accepts in one message (0 = no limit). PROMPT.md plans the delivery against it: which parts to attach, what to leave behind, and the part budget that would merge them. It does not change the payload."
14820
+ },
14821
+ {
14822
+ flag: "--brief",
14823
+ type: "string",
14824
+ default: "unset",
14825
+ appliesTo: optionAppliesTo("brief"),
14826
+ summary: "Path to the owner-written half of PROMPT.md: Stakes, The system, What came before, The bar and Calibration replace or extend the generated prose; any other heading is kept as Owner notes. The measured headings cannot be redefined. A missing file is an error and an edited file is config drift."
14827
+ },
14828
+ {
14829
+ flag: "--prompt-task",
14830
+ type: "string",
14831
+ default: "audit",
14832
+ appliesTo: optionAppliesTo("prompt-task"),
14833
+ summary: "Which job the brief is written for: audit (default), review or explain. It changes the opening section, not the standard."
14834
+ },
14835
+ {
14836
+ flag: "--max-parts",
14837
+ type: "number",
14838
+ default: "unset",
14839
+ appliesTo: optionAppliesTo("max-parts"),
14840
+ summary: "Experimental: grow the per-part budget until the snapshot has at most this many parts. The budget it settles on is recorded in manifest.budgets.maxPartBytes and may exceed maxPartBytes; a warning says so."
14841
+ },
13939
14842
  {
13940
14843
  flag: "--skip-artifacts",
13941
14844
  type: "string",
@@ -14149,6 +15052,10 @@ function buildAgentContract() {
14149
15052
  { key: "includeSensitiveFiles", type: "boolean", default: false, summary: "Emit .env / *.pem / credential files." },
14150
15053
  { key: "include", type: "string[]", default: "[]", summary: "Allow-list of globs; empty means everything." },
14151
15054
  { key: "excludePatterns", type: "string[]", default: "[]", summary: "Extra exclude globs." },
15055
+ { key: "brief", type: "string", default: "unset", summary: "Path to the owner-written half of PROMPT.md. Recognised headings: Stakes, The system, What came before, The bar, Calibration; unknown headings are kept as Owner notes; measured headings are refused. The file is digested, so editing it is drift." },
15056
+ { key: "promptTask", type: "string", default: "audit", summary: "Which job the brief is written for: audit, review or explain. The standard and the coverage duty are the same in all three." },
15057
+ { key: "maxParts", type: "number | null", default: null, summary: "Experimental: the most parts a snapshot may have. The per-part budget grows to fit, up to the run's own needs; the effective ceiling is recorded in manifest.budgets.maxPartBytes and may exceed maxPartBytes." },
15058
+ { key: "attachmentSlots", type: "number", default: 10, summary: "Files the destination accepts in one message (0 = no limit); PROMPT.md plans the delivery to fit. It does not change the payload, and it is not part of the config digest." },
14152
15059
  { key: "discovery", type: '"auto" | "git" | "walk"', default: "auto", summary: "How files are discovered; `walk` scans the tree and reads .gitignore directly when a .git directory cannot be listed." },
14153
15060
  { key: "artifacts", type: "object", default: "all on except monolith", summary: "Per-artifact opt-out." },
14154
15061
  { key: "budgets", type: "object", default: "{ default, byLayer }", summary: "Per-layer byte budgets." },
@@ -14163,6 +15070,7 @@ function buildAgentContract() {
14163
15070
  output: {
14164
15071
  layout: [
14165
15072
  "<outDir>/README.md",
15073
+ "<outDir>/PROMPT.md",
14166
15074
  "<outDir>/manifest.json",
14167
15075
  "<outDir>/parts/part-NNN.md",
14168
15076
  "<outDir>/reports/project-tree.md",
@@ -14176,6 +15084,7 @@ function buildAgentContract() {
14176
15084
  "indexes.imports.byFile includes previewed files (their import specifiers are still extracted); such an entry carries `exportsOmitted: true` instead of pretending it exports nothing.",
14177
15085
  "validate re-checks manifest.incomplete[] against files[] and refuses a manifest whose two statements of what is missing disagree.",
14178
15086
  "manifest.skipped[] carries the path and the exact reason it was excluded.",
15087
+ "PROMPT.md is rendered from the manifest of the run that wrote it \u2014 its parts, partial files, skip tallies and fingerprint are that run's \u2014 and manifest.artifacts.prompt records its digest, so an edited prompt fails validate.",
14179
15088
  `The output directory is replaced atomically; ${MIN_MAX_PART_BYTES} bytes is the smallest legal budget.`
14180
15089
  ]
14181
15090
  },
@@ -14346,6 +15255,10 @@ do not assume the repository is broken.
14346
15255
  - \`snapshot/reports/audit.md\` \u2014 secrets found, large files, parse diagnostics, git
14347
15256
  state. Read this before you quote code back to a user.
14348
15257
  - \`snapshot/reports/project-tree.md\` and \`navigation.md\` \u2014 structure and cross-links.
15258
+ - \`snapshot/PROMPT.md\` \u2014 the instruction sheet to hand to the model that receives the
15259
+ snapshot: paste it with the parts. It is rendered from this run's manifest and names the
15260
+ parts, the partial files and the fingerprint, so do not rewrite it by hand \u2014 \`validate\`
15261
+ fails when it was edited.
14349
15262
 
14350
15263
  ## Project types
14351
15264
 
@@ -14408,17 +15321,17 @@ var LEGACY_AGENTS_MARKER = "<!-- codebase-snapshot:skill:start -->";
14408
15321
  function targetPath(cwd, target) {
14409
15322
  switch (target) {
14410
15323
  case "claude":
14411
- return path16__namespace.join(cwd, ".claude", "skills", SKILL_NAME, "SKILL.md");
15324
+ return path17__namespace.join(cwd, ".claude", "skills", SKILL_NAME, "SKILL.md");
14412
15325
  case "cursor":
14413
- return path16__namespace.join(cwd, ".cursor", "rules", `${SKILL_NAME}.mdc`);
15326
+ return path17__namespace.join(cwd, ".cursor", "rules", `${SKILL_NAME}.mdc`);
14414
15327
  }
14415
15328
  }
14416
15329
  function assertWritableInsideRepository(cwd, filePath) {
14417
- const root = fs15__namespace.realpathSync(cwd);
14418
- const shown = path16__namespace.relative(root, filePath) || filePath;
15330
+ const root = fs16__namespace.realpathSync(cwd);
15331
+ const shown = path17__namespace.relative(root, filePath) || filePath;
14419
15332
  let stat = null;
14420
15333
  try {
14421
- stat = fs15__namespace.lstatSync(filePath);
15334
+ stat = fs16__namespace.lstatSync(filePath);
14422
15335
  } catch {
14423
15336
  stat = null;
14424
15337
  }
@@ -14434,32 +15347,32 @@ function assertWritableInsideRepository(cwd, filePath) {
14434
15347
  }
14435
15348
  let existing = filePath;
14436
15349
  const missing = [];
14437
- while (!fs15__namespace.existsSync(existing)) {
14438
- missing.unshift(path16__namespace.basename(existing));
14439
- const parent = path16__namespace.dirname(existing);
15350
+ while (!fs16__namespace.existsSync(existing)) {
15351
+ missing.unshift(path17__namespace.basename(existing));
15352
+ const parent = path17__namespace.dirname(existing);
14440
15353
  if (parent === existing) break;
14441
15354
  existing = parent;
14442
15355
  }
14443
- const realAncestor = fs15__namespace.realpathSync(existing);
14444
- const resolved = missing.length === 0 ? realAncestor : path16__namespace.join(realAncestor, ...missing);
14445
- if (resolved !== root && !resolved.startsWith(`${root}${path16__namespace.sep}`)) {
15356
+ const realAncestor = fs16__namespace.realpathSync(existing);
15357
+ const resolved = missing.length === 0 ? realAncestor : path17__namespace.join(realAncestor, ...missing);
15358
+ if (resolved !== root && !resolved.startsWith(`${root}${path17__namespace.sep}`)) {
14446
15359
  throw new Error(
14447
15360
  `${REFUSED}: ${shown} resolves outside the repository (${resolved}). Move it back inside ${root}, or remove the link, and run again.`
14448
15361
  );
14449
15362
  }
14450
15363
  }
14451
15364
  function writeIfChanged(target, filePath, content) {
14452
- const existing = fs15__namespace.existsSync(filePath) ? fs15__namespace.readFileSync(filePath, "utf8") : null;
15365
+ const existing = fs16__namespace.existsSync(filePath) ? fs16__namespace.readFileSync(filePath, "utf8") : null;
14453
15366
  if (existing === content) return { target, path: filePath, action: "unchanged" };
14454
- fs15__namespace.mkdirSync(path16__namespace.dirname(filePath), { recursive: true });
14455
- fs15__namespace.writeFileSync(filePath, content, "utf8");
15367
+ fs16__namespace.mkdirSync(path17__namespace.dirname(filePath), { recursive: true });
15368
+ fs16__namespace.writeFileSync(filePath, content, "utf8");
14456
15369
  return { target, path: filePath, action: existing === null ? "created" : "updated" };
14457
15370
  }
14458
15371
  function legacyAgentsNote(cwd) {
14459
- const filePath = path16__namespace.join(cwd, "AGENTS.md");
15372
+ const filePath = path17__namespace.join(cwd, "AGENTS.md");
14460
15373
  try {
14461
- if (!fs15__namespace.existsSync(filePath)) return null;
14462
- if (!fs15__namespace.readFileSync(filePath, "utf8").includes(LEGACY_AGENTS_MARKER)) return null;
15374
+ if (!fs16__namespace.existsSync(filePath)) return null;
15375
+ if (!fs16__namespace.readFileSync(filePath, "utf8").includes(LEGACY_AGENTS_MARKER)) return null;
14463
15376
  } catch {
14464
15377
  return null;
14465
15378
  }
@@ -14471,9 +15384,9 @@ function installSkill(cwd, target = "all") {
14471
15384
  const notes = [];
14472
15385
  const wanted = target === "all" ? ["claude", "cursor"] : [target];
14473
15386
  for (const item of wanted) assertWritableInsideRepository(cwd, targetPath(cwd, item));
14474
- const createsSomething = wanted.some((item) => !fs15__namespace.existsSync(targetPath(cwd, item)));
15387
+ const createsSomething = wanted.some((item) => !fs16__namespace.existsSync(targetPath(cwd, item)));
14475
15388
  if (createsSomething) {
14476
- assertWritableInsideRepository(cwd, path16__namespace.join(cwd, ".gitignore"));
15389
+ assertWritableInsideRepository(cwd, path17__namespace.join(cwd, ".gitignore"));
14477
15390
  }
14478
15391
  for (const item of wanted) {
14479
15392
  written.push(writeIfChanged(item, targetPath(cwd, item), skill));
@@ -14634,7 +15547,7 @@ async function workspaceFor(context) {
14634
15547
  }
14635
15548
  function readFileIfPresent(file) {
14636
15549
  try {
14637
- return fs15__namespace.readFileSync(file, "utf8");
15550
+ return fs16__namespace.readFileSync(file, "utf8");
14638
15551
  } catch {
14639
15552
  return null;
14640
15553
  }
@@ -14730,7 +15643,7 @@ function buildResourceProvider() {
14730
15643
  const report = REPORT_URIS.get(uri);
14731
15644
  if (report) {
14732
15645
  const text2 = readFileIfPresent(
14733
- path16__namespace.resolve(workspace.root, workspace.config.outDir, "reports", report.file)
15646
+ path17__namespace.resolve(workspace.root, workspace.config.outDir, "reports", report.file)
14734
15647
  );
14735
15648
  if (text2 === null) return null;
14736
15649
  return { uri, mimeType: "text/markdown", text: ensureSingleRead(uri, text2, REPORT_ADVICE) };
@@ -14752,7 +15665,7 @@ function buildResourceProvider() {
14752
15665
  if (partPath === null) return null;
14753
15666
  let partBytes;
14754
15667
  try {
14755
- partBytes = fs15__namespace.statSync(partPath).size;
15668
+ partBytes = fs16__namespace.statSync(partPath).size;
14756
15669
  } catch {
14757
15670
  return null;
14758
15671
  }
@@ -14788,52 +15701,52 @@ function validateArguments(schema, value) {
14788
15701
  }
14789
15702
  return problems;
14790
15703
  }
14791
- function checkValue(path22, schema, value) {
15704
+ function checkValue(path23, schema, value) {
14792
15705
  if (schema.enum && !schema.enum.includes(value)) {
14793
- return [`"${path22}" must be one of: ${schema.enum.join(", ")}`];
15706
+ return [`"${path23}" must be one of: ${schema.enum.join(", ")}`];
14794
15707
  }
14795
15708
  switch (schema.type) {
14796
15709
  case "string": {
14797
- if (typeof value !== "string") return [`"${path22}" must be a string`];
15710
+ if (typeof value !== "string") return [`"${path23}" must be a string`];
14798
15711
  const problems = [];
14799
15712
  if (schema.minLength !== void 0 && value.length < schema.minLength) {
14800
- problems.push(`"${path22}" must be at least ${schema.minLength} character(s)`);
15713
+ problems.push(`"${path23}" must be at least ${schema.minLength} character(s)`);
14801
15714
  }
14802
15715
  if (schema.maxLength !== void 0 && value.length > schema.maxLength) {
14803
- problems.push(`"${path22}" must be at most ${schema.maxLength} character(s)`);
15716
+ problems.push(`"${path23}" must be at most ${schema.maxLength} character(s)`);
14804
15717
  }
14805
15718
  return problems;
14806
15719
  }
14807
15720
  case "number":
14808
15721
  case "integer": {
14809
15722
  if (typeof value !== "number" || Number.isNaN(value)) {
14810
- return [`"${path22}" must be a number`];
15723
+ return [`"${path23}" must be a number`];
14811
15724
  }
14812
15725
  if (schema.type === "integer" && !Number.isInteger(value)) {
14813
- return [`"${path22}" must be an integer`];
15726
+ return [`"${path23}" must be an integer`];
14814
15727
  }
14815
15728
  const problems = [];
14816
15729
  if (schema.minimum !== void 0 && value < schema.minimum) {
14817
- problems.push(`"${path22}" must be >= ${schema.minimum}`);
15730
+ problems.push(`"${path23}" must be >= ${schema.minimum}`);
14818
15731
  }
14819
15732
  if (schema.maximum !== void 0 && value > schema.maximum) {
14820
- problems.push(`"${path22}" must be <= ${schema.maximum}`);
15733
+ problems.push(`"${path23}" must be <= ${schema.maximum}`);
14821
15734
  }
14822
15735
  return problems;
14823
15736
  }
14824
15737
  case "boolean":
14825
- return typeof value === "boolean" ? [] : [`"${path22}" must be a boolean`];
15738
+ return typeof value === "boolean" ? [] : [`"${path23}" must be a boolean`];
14826
15739
  case "array": {
14827
- if (!Array.isArray(value)) return [`"${path22}" must be an array`];
15740
+ if (!Array.isArray(value)) return [`"${path23}" must be an array`];
14828
15741
  if (!schema.items) return [];
14829
15742
  const problems = [];
14830
15743
  value.forEach((item, index) => {
14831
- problems.push(...checkValue(`${path22}[${index}]`, schema.items, item));
15744
+ problems.push(...checkValue(`${path23}[${index}]`, schema.items, item));
14832
15745
  });
14833
15746
  return problems;
14834
15747
  }
14835
15748
  case "object":
14836
- return isJsonObject(value) ? [] : [`"${path22}" must be an object`];
15749
+ return isJsonObject(value) ? [] : [`"${path23}" must be an object`];
14837
15750
  default:
14838
15751
  return [];
14839
15752
  }
@@ -15407,6 +16320,10 @@ var CLI_OPTIONS = {
15407
16320
  "max-part-bytes": { type: "string" },
15408
16321
  "large-file-bytes": { type: "string" },
15409
16322
  "max-monolith-bytes": { type: "string" },
16323
+ "attachment-slots": { type: "string" },
16324
+ "max-parts": { type: "string" },
16325
+ brief: { type: "string" },
16326
+ "prompt-task": { type: "string" },
15410
16327
  "include-monolith": { type: "boolean" },
15411
16328
  "include-sensitive-files": { type: "boolean" },
15412
16329
  "skip-artifacts": { type: "string" },
@@ -15481,6 +16398,13 @@ Options:
15481
16398
  --skeleton Emit TypeScript signatures instead of bodies
15482
16399
  --sarif Also write reports/audit.sarif for GitHub Code Scanning
15483
16400
  --include-sensitive-files Emit .env / *.pem / .npmrc / credential files
16401
+ --attachment-slots <n> Files the destination takes in one message (default: 10,
16402
+ 0 = no limit); PROMPT.md plans the delivery to fit
16403
+ --max-parts <n> Experimental: grow the part budget until the snapshot has at
16404
+ most n parts, instead of adding parts as the code grows
16405
+ --brief <path> Owner-written half of PROMPT.md (stakes, system, history,
16406
+ bar, calibration); merged at fixed slots
16407
+ --prompt-task <task> audit | review | explain - which job the brief is for
15484
16408
  --skip-artifacts <names> Comma-separated artifacts to omit
15485
16409
  (readme, manifest, parts, navigation,
15486
16410
  projectTree, audit, monolith)
@@ -15551,6 +16475,27 @@ function parseByteOption(raw, optionName, minimum, unit = "byte count") {
15551
16475
  }
15552
16476
  return value;
15553
16477
  }
16478
+ function parseCountOption(raw, optionName, minimum = 0) {
16479
+ if (raw === void 0) return void 0;
16480
+ const trimmed = raw.trim();
16481
+ if (!/^\d+$/.test(trimmed) || !Number.isSafeInteger(Number(trimmed))) {
16482
+ throw new UsageError(
16483
+ `--${optionName} expects a whole number such as 10 or 20, received "${raw}".`
16484
+ );
16485
+ }
16486
+ const value = Number(trimmed);
16487
+ if (value < minimum) {
16488
+ throw new UsageError(`--${optionName} must be at least ${minimum}, received "${raw}".`);
16489
+ }
16490
+ return value;
16491
+ }
16492
+ function parsePromptTask(value) {
16493
+ if (value === void 0) return void 0;
16494
+ if (value === "audit" || value === "review" || value === "explain") return value;
16495
+ throw new UsageError(
16496
+ '--prompt-task expects audit, review or explain, received "' + value + '".'
16497
+ );
16498
+ }
15554
16499
  function parseArtifactList(raw, flag) {
15555
16500
  const names = raw.split(",").map((name) => name.trim()).filter(Boolean);
15556
16501
  if (names.length === 0) {
@@ -15615,10 +16560,10 @@ function parseCliArgs(argv) {
15615
16560
  }
15616
16561
  if (values.cwd !== void 0) {
15617
16562
  const target = String(values.cwd);
15618
- if (!fs15__namespace.existsSync(target)) {
16563
+ if (!fs16__namespace.existsSync(target)) {
15619
16564
  throw new UsageError(`--cwd directory does not exist: ${target}`);
15620
16565
  }
15621
- if (!fs15__namespace.statSync(target).isDirectory()) {
16566
+ if (!fs16__namespace.statSync(target).isDirectory()) {
15622
16567
  throw new UsageError(`--cwd is not a directory: ${target}`);
15623
16568
  }
15624
16569
  }
@@ -15764,7 +16709,7 @@ function parseCliArgs(argv) {
15764
16709
  install: values.install === true,
15765
16710
  noInstall: values["no-install"] === true,
15766
16711
  target: values.target === void 0 ? void 0 : String(values.target),
15767
- cwd: values.cwd === void 0 ? process.cwd() : path16__namespace.resolve(String(values.cwd)),
16712
+ cwd: values.cwd === void 0 ? process.cwd() : path17__namespace.resolve(String(values.cwd)),
15768
16713
  outDir: values["out-dir"] === void 0 ? void 0 : String(values["out-dir"]),
15769
16714
  includeMonolith: values["include-monolith"] === true || onlyNamesMonolith === true ? true : void 0,
15770
16715
  includeSensitiveFiles: values["include-sensitive-files"] === true ? true : void 0,
@@ -15792,6 +16737,13 @@ function parseCliArgs(argv) {
15792
16737
  "max-monolith-bytes",
15793
16738
  1
15794
16739
  ),
16740
+ attachmentSlots: parseCountOption(
16741
+ values["attachment-slots"],
16742
+ "attachment-slots"
16743
+ ),
16744
+ maxParts: parseCountOption(values["max-parts"], "max-parts", 1),
16745
+ brief: values.brief === void 0 ? void 0 : String(values.brief),
16746
+ promptTask: parsePromptTask(values["prompt-task"]),
15795
16747
  skipArtifacts,
15796
16748
  onlyArtifacts,
15797
16749
  discovery: isDiscoveryMode(rawDiscovery) ? rawDiscovery : void 0,
@@ -15845,9 +16797,9 @@ function splitList(value) {
15845
16797
  return value.split(",").map((entry) => entry.trim()).filter(Boolean);
15846
16798
  }
15847
16799
  function displayOutPath(cwd, outDir, ...segments) {
15848
- const absolute = path16__namespace.resolve(cwd, outDir, ...segments);
15849
- const relative15 = path16__namespace.relative(cwd, absolute);
15850
- if (relative15 && !relative15.startsWith("..") && !path16__namespace.isAbsolute(relative15)) return relative15;
16800
+ const absolute = path17__namespace.resolve(cwd, outDir, ...segments);
16801
+ const relative15 = path17__namespace.relative(cwd, absolute);
16802
+ if (relative15 && !relative15.startsWith("..") && !path17__namespace.isAbsolute(relative15)) return relative15;
15851
16803
  return absolute;
15852
16804
  }
15853
16805
  function nextStepHint(cwd, scriptsAddedNow) {
@@ -15855,7 +16807,7 @@ function nextStepHint(cwd, scriptsAddedNow) {
15855
16807
  if (!hasScript) {
15856
16808
  try {
15857
16809
  const parsed = JSON.parse(
15858
- stripJsonComments(fs15__namespace.readFileSync(path16__namespace.join(cwd, "package.json"), "utf8"))
16810
+ stripJsonComments(fs16__namespace.readFileSync(path17__namespace.join(cwd, "package.json"), "utf8"))
15859
16811
  );
15860
16812
  hasScript = typeof parsed.scripts?.snapshot === "string";
15861
16813
  } catch {
@@ -15863,8 +16815,8 @@ function nextStepHint(cwd, scriptsAddedNow) {
15863
16815
  }
15864
16816
  }
15865
16817
  if (!hasScript) return `npx ${GENERATOR_NAME} generate`;
15866
- const bin = path16__namespace.join(cwd, "node_modules", ".bin", "codebase-snapshot");
15867
- const installed = fs15__namespace.existsSync(bin) || fs15__namespace.existsSync(`${bin}.cmd`);
16818
+ const bin = path17__namespace.join(cwd, "node_modules", ".bin", "codebase-snapshot");
16819
+ const installed = fs16__namespace.existsSync(bin) || fs16__namespace.existsSync(`${bin}.cmd`);
15868
16820
  return installed ? "npm run snapshot" : "npm install && npm run snapshot";
15869
16821
  }
15870
16822
  function presetSummary(init) {
@@ -15900,7 +16852,7 @@ async function runInitCommand(invocation) {
15900
16852
  if (hook) for (const note of hook.notes) info(` ${note}`);
15901
16853
  return 0;
15902
16854
  }
15903
- info(`\u2705 Created ${path16__namespace.basename(result.configPath)} (${presetSummary(result)})`);
16855
+ info(`\u2705 Created ${path17__namespace.basename(result.configPath)} (${presetSummary(result)})`);
15904
16856
  if (result.scripts.length > 0) info(` Added npm scripts: ${result.scripts.join(", ")}`);
15905
16857
  if (result.dependency.added && result.dependency.range !== null) {
15906
16858
  info(` Added devDependency: ${result.dependency.name} ${result.dependency.range}`);
@@ -15923,18 +16875,18 @@ async function runInitCommand(invocation) {
15923
16875
  function generatorOrigin(cwd) {
15924
16876
  try {
15925
16877
  const pkg = JSON.parse(
15926
- stripJsonComments(fs15__namespace.readFileSync(path16__namespace.join(cwd, "package.json"), "utf8"))
16878
+ stripJsonComments(fs16__namespace.readFileSync(path17__namespace.join(cwd, "package.json"), "utf8"))
15927
16879
  );
15928
16880
  const spec = pkg.dependencies?.["codebase-snapshot"] ?? pkg.devDependencies?.["codebase-snapshot"];
15929
16881
  if (typeof spec === "string") return `project dependency ${spec}`;
15930
16882
  } catch {
15931
16883
  }
15932
16884
  const entry = process.argv[1] ?? "";
15933
- if (entry.includes("_npx") || entry.includes(`${path16__namespace.sep}npx${path16__namespace.sep}`)) return "via npx";
16885
+ if (entry.includes("_npx") || entry.includes(`${path17__namespace.sep}npx${path17__namespace.sep}`)) return "via npx";
15934
16886
  return "global or direct install";
15935
16887
  }
15936
16888
  function detectPackageManager(cwd) {
15937
- const has = (name) => fs15__namespace.existsSync(path16__namespace.join(cwd, name));
16889
+ const has = (name) => fs16__namespace.existsSync(path17__namespace.join(cwd, name));
15938
16890
  if (has("bun.lockb") || has("bun.lock")) return { name: "bun", command: "bun", args: ["install"] };
15939
16891
  if (has("pnpm-lock.yaml")) return { name: "pnpm", command: "pnpm", args: ["install"] };
15940
16892
  if (has("yarn.lock")) return { name: "yarn", command: "yarn", args: ["install"] };
@@ -16051,7 +17003,7 @@ async function runSetupCommand(invocation, options = {}) {
16051
17003
  }
16052
17004
  info("\n\u{1F9EA} Dry run \u2014 setup would:");
16053
17005
  info(
16054
- ` 1. ${init.reused ? `keep ${path16__namespace.basename(keptConfigPath)}` : `write ${path16__namespace.basename(keptConfigPath)} (preset: ${appliedPreset})`}`
17006
+ ` 1. ${init.reused ? `keep ${path17__namespace.basename(keptConfigPath)}` : `write ${path17__namespace.basename(keptConfigPath)} (preset: ${appliedPreset})`}`
16055
17007
  );
16056
17008
  info(" 2. add the npm scripts, the devDependency and the .gitignore entries");
16057
17009
  if (manager !== null) info(` 3. install with ${manager}`);
@@ -16064,9 +17016,9 @@ async function runSetupCommand(invocation, options = {}) {
16064
17016
  if (invocation.format !== "json") {
16065
17017
  if (!interactive) info(`\u{1F680} Setup for: ${invocation.cwd}`);
16066
17018
  if (init.reused) {
16067
- info(`\u267B Keeping ${path16__namespace.basename(keptConfigPath)}`);
17019
+ info(`\u267B Keeping ${path17__namespace.basename(keptConfigPath)}`);
16068
17020
  } else {
16069
- info(`\u2705 Created ${path16__namespace.basename(keptConfigPath)} (${presetSummary(init)})`);
17021
+ info(`\u2705 Created ${path17__namespace.basename(keptConfigPath)} (${presetSummary(init)})`);
16070
17022
  }
16071
17023
  if (init.scripts.length > 0) info(` Added npm scripts: ${init.scripts.join(", ")}`);
16072
17024
  if (init.dependency.added && init.dependency.range !== null) {
@@ -16080,7 +17032,7 @@ async function runSetupCommand(invocation, options = {}) {
16080
17032
  info(` \u26A0 --preset ${invocation.preset} was not applied: the existing config is kept.`);
16081
17033
  }
16082
17034
  }
16083
- const hasManifest = fs15__namespace.existsSync(path16__namespace.join(invocation.cwd, "package.json"));
17035
+ const hasManifest = fs16__namespace.existsSync(path17__namespace.join(invocation.cwd, "package.json"));
16084
17036
  let install = null;
16085
17037
  if (invocation.noInstall) {
16086
17038
  if (invocation.format !== "json") info(" Skipped the install (--no-install)");
@@ -16117,6 +17069,16 @@ async function runSetupCommand(invocation, options = {}) {
16117
17069
  if (invocation.maxPartTokens !== void 0) {
16118
17070
  generateArgs.push("--max-part-tokens", String(invocation.maxPartTokens));
16119
17071
  }
17072
+ if (invocation.attachmentSlots !== void 0) {
17073
+ generateArgs.push("--attachment-slots", String(invocation.attachmentSlots));
17074
+ }
17075
+ if (invocation.maxParts !== void 0) {
17076
+ generateArgs.push("--max-parts", String(invocation.maxParts));
17077
+ }
17078
+ if (invocation.brief !== void 0) generateArgs.push("--brief", invocation.brief);
17079
+ if (invocation.promptTask !== void 0) {
17080
+ generateArgs.push("--prompt-task", invocation.promptTask);
17081
+ }
16120
17082
  if (invocation.skeleton === true) generateArgs.push("--skeleton");
16121
17083
  if (invocation.sarif === true) generateArgs.push("--sarif");
16122
17084
  if (invocation.noUpdateCheck) generateArgs.push("--no-update-check");
@@ -16202,7 +17164,7 @@ function runSkillCommand(invocation) {
16202
17164
  }
16203
17165
  info(`\u2705 Agent skill installed (${SKILL_NAME}):`);
16204
17166
  for (const item of result.written) {
16205
- const shown = path16__namespace.relative(invocation.cwd, item.path) || item.path;
17167
+ const shown = path17__namespace.relative(invocation.cwd, item.path) || item.path;
16206
17168
  info(` - ${item.action.padEnd(9)} ${shown}`);
16207
17169
  }
16208
17170
  if (result.gitignored.length > 0) {
@@ -16323,7 +17285,7 @@ ${USAGE}
16323
17285
  return runSkillCommand(invocation);
16324
17286
  }
16325
17287
  if (invocation.command === "mcp") {
16326
- return await runStdioServer({ cwd: path16__namespace.resolve(invocation.cwd) });
17288
+ return await runStdioServer({ cwd: path17__namespace.resolve(invocation.cwd) });
16327
17289
  }
16328
17290
  if (invocation.command === "setup") {
16329
17291
  return runSetupCommand(invocation);
@@ -16342,7 +17304,7 @@ ${USAGE}
16342
17304
  );
16343
17305
  }
16344
17306
  for (const warning of loaded.warnings) warn(`\u26A0 Config: ${warning}`);
16345
- if (loaded.file) info(`\u2699 Using config ${path16__namespace.relative(process.cwd(), loaded.file) || loaded.file}`);
17307
+ if (loaded.file) info(`\u2699 Using config ${path17__namespace.relative(process.cwd(), loaded.file) || loaded.file}`);
16346
17308
  let resolved;
16347
17309
  try {
16348
17310
  resolved = resolveConfig(
@@ -16359,6 +17321,10 @@ ${USAGE}
16359
17321
  maxPartTokens: invocation.maxPartTokens,
16360
17322
  largeFileBytes: invocation.largeFileBytes,
16361
17323
  maxMonolithBytes: invocation.maxMonolithBytes,
17324
+ attachmentSlots: invocation.attachmentSlots,
17325
+ maxParts: invocation.maxParts,
17326
+ brief: invocation.brief,
17327
+ promptTask: invocation.promptTask,
16362
17328
  skipArtifacts: invocation.skipArtifacts,
16363
17329
  // `--only-artifacts` is forwarded as itself, not only as the derived suppression list:
16364
17330
  // suppression cannot switch an artifact *on*, so a config that had turned one of the
@@ -16382,13 +17348,13 @@ ${USAGE}
16382
17348
  return result.valid ? 0 : 1;
16383
17349
  }
16384
17350
  if (invocation.command === "report") {
16385
- const manifestPath = path16__namespace.resolve(resolved.cwd, resolved.outDir, "manifest.json");
16386
- if (!fs15__namespace.existsSync(manifestPath)) {
17351
+ const manifestPath = path17__namespace.resolve(resolved.cwd, resolved.outDir, "manifest.json");
17352
+ if (!fs16__namespace.existsSync(manifestPath)) {
16387
17353
  return fail(invocation.format, `Manifest not found at ${manifestPath}. Run generate first.`);
16388
17354
  }
16389
17355
  let manifest;
16390
17356
  try {
16391
- manifest = JSON.parse(fs15__namespace.readFileSync(manifestPath, "utf8"));
17357
+ manifest = JSON.parse(fs16__namespace.readFileSync(manifestPath, "utf8"));
16392
17358
  } catch (err) {
16393
17359
  return fail(invocation.format, `Could not read ${manifestPath}: ${err.message}`);
16394
17360
  }
@@ -16531,7 +17497,16 @@ ${USAGE}
16531
17497
  );
16532
17498
  }
16533
17499
  }
16534
- if (reports.length === 0 && !artifacts.parts && !artifacts.manifest && !artifacts.monolith) {
17500
+ const orientation = [
17501
+ artifacts.readme ? "README.md" : null,
17502
+ artifacts.prompt ? "PROMPT.md" : null
17503
+ ].filter((name) => name !== null);
17504
+ if (orientation.length > 0) {
17505
+ info(
17506
+ ` - Orientation: ${orientation.map((name) => displayOutPath(resolved.cwd, resolved.outDir, name)).join(", ")}`
17507
+ );
17508
+ }
17509
+ if (reports.length === 0 && !artifacts.parts && !artifacts.manifest && !artifacts.monolith && orientation.length === 0) {
16535
17510
  info(` - Artifacts: all disabled (only the ownership marker was written)`);
16536
17511
  }
16537
17512
  info(` - Fingerprint: ${manifest.fingerprint}`);
@@ -16583,19 +17558,19 @@ function finishWatchRun(state, now) {
16583
17558
  };
16584
17559
  }
16585
17560
  function comparablePath(value) {
16586
- const absolute = path16__namespace.resolve(value);
17561
+ const absolute = path17__namespace.resolve(value);
16587
17562
  return process.platform === "win32" ? absolute.toLowerCase() : absolute;
16588
17563
  }
16589
17564
  function isSameOrInside(parent, candidate) {
16590
- const relative15 = path16__namespace.relative(parent, candidate);
16591
- return relative15 === "" || relative15 !== ".." && !relative15.startsWith(`..${path16__namespace.sep}`) && !path16__namespace.isAbsolute(relative15);
17565
+ const relative15 = path17__namespace.relative(parent, candidate);
17566
+ return relative15 === "" || relative15 !== ".." && !relative15.startsWith(`..${path17__namespace.sep}`) && !path17__namespace.isAbsolute(relative15);
16592
17567
  }
16593
17568
  function isGeneratedWatchPath(candidate, paths) {
16594
- const absolute = comparablePath(path16__namespace.resolve(paths.cwd, candidate));
16595
- const outDir = comparablePath(path16__namespace.resolve(paths.cwd, paths.outDir));
16596
- const tmpDir = comparablePath(path16__namespace.resolve(paths.cwd, paths.tmpDir));
17569
+ const absolute = comparablePath(path17__namespace.resolve(paths.cwd, candidate));
17570
+ const outDir = comparablePath(path17__namespace.resolve(paths.cwd, paths.outDir));
17571
+ const tmpDir = comparablePath(path17__namespace.resolve(paths.cwd, paths.tmpDir));
16597
17572
  if (isSameOrInside(outDir, absolute) || isSameOrInside(tmpDir, absolute)) return true;
16598
- const offsets = [path16__namespace.basename(outDir), path16__namespace.basename(tmpDir)].filter((name) => name.length > 0);
17573
+ const offsets = [path17__namespace.basename(outDir), path17__namespace.basename(tmpDir)].filter((name) => name.length > 0);
16599
17574
  const leftover = absolute.split(/[\\/]+/).some(
16600
17575
  (segment) => offsets.some(
16601
17576
  (name) => segment.startsWith(`${name}.backup-`) || segment.startsWith(`${name}.partial-`)
@@ -16618,8 +17593,8 @@ function decideWatchEvent(state, event, paths) {
16618
17593
  function watchPathsFor(config) {
16619
17594
  return {
16620
17595
  cwd: config.cwd,
16621
- outDir: path16__namespace.resolve(config.cwd, config.outDir),
16622
- tmpDir: path16__namespace.resolve(config.cwd, config.tmpDir)
17596
+ outDir: path17__namespace.resolve(config.cwd, config.outDir),
17597
+ tmpDir: path17__namespace.resolve(config.cwd, config.tmpDir)
16623
17598
  };
16624
17599
  }
16625
17600
  function watchSupportProblem(platform = process.platform, version = process.versions.node) {
@@ -16675,6 +17650,10 @@ async function runWatchLoop(invocation, resolved, options) {
16675
17650
  maxPartTokens: invocation.maxPartTokens,
16676
17651
  largeFileBytes: invocation.largeFileBytes,
16677
17652
  maxMonolithBytes: invocation.maxMonolithBytes,
17653
+ attachmentSlots: invocation.attachmentSlots,
17654
+ maxParts: invocation.maxParts,
17655
+ brief: invocation.brief,
17656
+ promptTask: invocation.promptTask,
16678
17657
  skipArtifacts: invocation.skipArtifacts,
16679
17658
  onlyArtifacts: invocation.onlyArtifacts,
16680
17659
  discovery: invocation.discovery,
@@ -16703,11 +17682,11 @@ async function runWatchLoop(invocation, resolved, options) {
16703
17682
  info("\u{1F440} Watching for changes. Press Ctrl+C to stop.");
16704
17683
  let watcher;
16705
17684
  try {
16706
- watcher = fs15__namespace.watch(resolved.cwd, { recursive: true }, (_event, filename) => {
17685
+ watcher = fs16__namespace.watch(resolved.cwd, { recursive: true }, (_event, filename) => {
16707
17686
  const decision = decideWatchEvent(
16708
17687
  state,
16709
17688
  {
16710
- path: filename ? path16__namespace.resolve(resolved.cwd, filename.toString()) : null,
17689
+ path: filename ? path17__namespace.resolve(resolved.cwd, filename.toString()) : null,
16711
17690
  now: performance.now()
16712
17691
  },
16713
17692
  paths
@@ -16746,7 +17725,7 @@ async function runWatchLoop(invocation, resolved, options) {
16746
17725
  return 0;
16747
17726
  }
16748
17727
  var entryFile = process.argv[1] ?? "";
16749
- var entryName = path16__namespace.basename(entryFile).toLowerCase();
17728
+ var entryName = path17__namespace.basename(entryFile).toLowerCase();
16750
17729
  var invokedDirectly = entryName === "cli.js" || entryName === "cli.cjs";
16751
17730
  if (invokedDirectly) {
16752
17731
  void main().then(
@@ -16775,6 +17754,7 @@ exports.isGeneratedWatchPath = isGeneratedWatchPath;
16775
17754
  exports.main = main;
16776
17755
  exports.parseByteOption = parseByteOption;
16777
17756
  exports.parseCliArgs = parseCliArgs;
17757
+ exports.parseCountOption = parseCountOption;
16778
17758
  exports.parsePositiveInteger = parsePositiveInteger;
16779
17759
  exports.watchPathsFor = watchPathsFor;
16780
17760
  exports.watchSupportProblem = watchSupportProblem;