codebase-snapshot 0.11.0 → 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.
@@ -2,9 +2,9 @@ import * as crypto2 from 'crypto';
2
2
  import { createHash } from 'crypto';
3
3
  import { Worker } from 'worker_threads';
4
4
  import { AsyncLocalStorage } from 'async_hooks';
5
- import * as fs15 from 'fs';
5
+ import * as fs16 from 'fs';
6
6
  import * as os from 'os';
7
- import * as path16 from 'path';
7
+ import * as path17 from 'path';
8
8
  import ts from 'typescript';
9
9
  import { createRequire } from 'module';
10
10
  import { pathToFileURL, fileURLToPath } from 'url';
@@ -395,9 +395,9 @@ var JAVA_METHOD = /^\s+(?:public|private|protected)\s+(?:static\s+)?(?:final\s+)
395
395
  var jvmProfile = {
396
396
  id: "jvm",
397
397
  extensions: [".java", ".kt", ".kts", ".scala"],
398
- summarize(path17, content) {
398
+ summarize(path18, content) {
399
399
  const summary = emptySummary();
400
- const lower = path17.toLowerCase();
400
+ const lower = path18.toLowerCase();
401
401
  const isJava = lower.endsWith(".java");
402
402
  const isKotlin = lower.endsWith(".kt") || lower.endsWith(".kts");
403
403
  eachLine(content, (line) => {
@@ -1005,17 +1005,17 @@ function summarizeTypeScriptSource(relativePath, content) {
1005
1005
  var SCRIPT_BLOCK = /<script([^>]*)>([\s\S]*?)<\/script>/gi;
1006
1006
  var JSX_LANG = /\blang\s*=\s*["']?[tj]sx\b/i;
1007
1007
  var ASTRO_FRONTMATTER = /^\uFEFF?---[ \t]*\r?\n([\s\S]*?)\r?\n---[ \t]*(?=\r?\n|$)/;
1008
- function componentName(path17) {
1009
- const base = path17.split("/").pop() ?? path17;
1008
+ function componentName(path18) {
1009
+ const base = path18.split("/").pop() ?? path18;
1010
1010
  return base.replace(/\.[^.]+$/, "");
1011
1011
  }
1012
1012
  var sfcProfile = {
1013
1013
  id: "sfc",
1014
1014
  extensions: [".vue", ".svelte", ".astro"],
1015
- summarize(path17, content) {
1015
+ summarize(path18, content) {
1016
1016
  let script = "";
1017
- let usesJsx = path17.toLowerCase().endsWith(".astro");
1018
- if (path17.toLowerCase().endsWith(".astro")) {
1017
+ let usesJsx = path18.toLowerCase().endsWith(".astro");
1018
+ if (path18.toLowerCase().endsWith(".astro")) {
1019
1019
  const frontmatter = ASTRO_FRONTMATTER.exec(content);
1020
1020
  if (frontmatter) script += `${frontmatter[1]}
1021
1021
  `;
@@ -1025,7 +1025,7 @@ var sfcProfile = {
1025
1025
  script += `${match[2]}
1026
1026
  `;
1027
1027
  }
1028
- const name = componentName(path17);
1028
+ const name = componentName(path18);
1029
1029
  if (!script.trim()) {
1030
1030
  const summary2 = emptySummary();
1031
1031
  if (name) {
@@ -1216,15 +1216,15 @@ for (const profile of LANGUAGE_PROFILES) {
1216
1216
  BY_EXTENSION.set(extension.toLowerCase(), profile);
1217
1217
  }
1218
1218
  }
1219
- function profileForPath(path17) {
1220
- const lower = path17.toLowerCase();
1219
+ function profileForPath(path18) {
1220
+ const lower = path18.toLowerCase();
1221
1221
  const dot = lower.lastIndexOf(".");
1222
1222
  if (dot === -1) return null;
1223
1223
  return BY_EXTENSION.get(lower.slice(dot)) ?? null;
1224
1224
  }
1225
- function summarizeWithProfile(path17, content) {
1226
- const profile = profileForPath(path17);
1227
- return profile ? profile.summarize(path17, content) : null;
1225
+ function summarizeWithProfile(path18, content) {
1226
+ const profile = profileForPath(path18);
1227
+ return profile ? profile.summarize(path18, content) : null;
1228
1228
  }
1229
1229
  var BINARY_EXTENSIONS = /* @__PURE__ */ new Set([
1230
1230
  ".png",
@@ -1269,7 +1269,7 @@ var BINARY_EXTENSIONS = /* @__PURE__ */ new Set([
1269
1269
  ".so"
1270
1270
  ]);
1271
1271
  function isBinaryExtension(filePath) {
1272
- const ext = path16.extname(filePath).toLowerCase();
1272
+ const ext = path17.extname(filePath).toLowerCase();
1273
1273
  return BINARY_EXTENSIONS.has(ext);
1274
1274
  }
1275
1275
  function isBinaryBuffer(buffer) {
@@ -1439,13 +1439,13 @@ function isBinaryFile(absolutePath) {
1439
1439
  if (isBinaryExtension(absolutePath)) return true;
1440
1440
  let fd;
1441
1441
  try {
1442
- fd = fs15.openSync(absolutePath, "r");
1442
+ fd = fs16.openSync(absolutePath, "r");
1443
1443
  const buffer = Buffer.alloc(CHUNK);
1444
1444
  let sample;
1445
1445
  let position = 0;
1446
1446
  while (position < BINARY_SCAN_BYTES) {
1447
1447
  const wanted = Math.min(CHUNK, BINARY_SCAN_BYTES - position);
1448
- const bytesRead = fs15.readSync(fd, buffer, 0, wanted, position);
1448
+ const bytesRead = fs16.readSync(fd, buffer, 0, wanted, position);
1449
1449
  if (bytesRead === 0) return false;
1450
1450
  const chunk = buffer.subarray(0, bytesRead);
1451
1451
  if (sample === void 0) {
@@ -1463,7 +1463,7 @@ function isBinaryFile(absolutePath) {
1463
1463
  } finally {
1464
1464
  if (fd !== void 0) {
1465
1465
  try {
1466
- fs15.closeSync(fd);
1466
+ fs16.closeSync(fd);
1467
1467
  } catch {
1468
1468
  }
1469
1469
  }
@@ -1485,9 +1485,9 @@ function importsOfText(relativePath, text2) {
1485
1485
  function importsOfFile(relativePath, absolutePath) {
1486
1486
  let buffer;
1487
1487
  try {
1488
- const stats = fs15.statSync(absolutePath);
1488
+ const stats = fs16.statSync(absolutePath);
1489
1489
  if (!stats.isFile() || stats.size > SUMMARY_MAX_SOURCE_BYTES) return [];
1490
- buffer = fs15.readFileSync(absolutePath);
1490
+ buffer = fs16.readFileSync(absolutePath);
1491
1491
  } catch {
1492
1492
  return [];
1493
1493
  }
@@ -1733,6 +1733,77 @@ function isSkeletonizable(filePath) {
1733
1733
  }
1734
1734
  return lower.endsWith(".ts") || lower.endsWith(".tsx") || lower.endsWith(".mts") || lower.endsWith(".cts") || lower.endsWith(".js") || lower.endsWith(".jsx") || lower.endsWith(".mjs") || lower.endsWith(".cjs");
1735
1735
  }
1736
+ var OWNER_SECTIONS = ["Stakes", "The system", "What came before", "The bar", "Calibration"];
1737
+ var RESERVED_SECTIONS = [
1738
+ "The job",
1739
+ "What you have",
1740
+ "Coverage",
1741
+ "What a useful answer contains",
1742
+ "This snapshot",
1743
+ "Attaching this",
1744
+ "Your task"
1745
+ ];
1746
+ function parseOwnerBrief(filePath, text2) {
1747
+ const problems = [];
1748
+ const source = text2.replace(/^\uFEFF/, "");
1749
+ const preamble = [];
1750
+ const sections = [];
1751
+ let current = null;
1752
+ for (const line of source.split(/\r?\n/)) {
1753
+ const heading = /^##\s+(.+?)\s*$/.exec(line);
1754
+ if (heading) {
1755
+ current = { heading: heading[1], body: [] };
1756
+ sections.push(current);
1757
+ continue;
1758
+ }
1759
+ if (current) current.body.push(line);
1760
+ else preamble.push(line);
1761
+ }
1762
+ const recognised = {};
1763
+ const notes = [];
1764
+ const canonical = (heading) => heading.trim().toLowerCase().replace(/\s+/g, " ");
1765
+ const canonicalOwner = new Map(OWNER_SECTIONS.map((name) => [canonical(name), name]));
1766
+ const canonicalReserved = new Set(RESERVED_SECTIONS.map(canonical));
1767
+ const seen = /* @__PURE__ */ new Set();
1768
+ for (const section of sections) {
1769
+ const body = section.body.join("\n").trim();
1770
+ const key = canonical(section.heading);
1771
+ if (seen.has(key)) {
1772
+ problems.push(
1773
+ `the brief defines "${section.heading}" twice; a section cannot say two things.`
1774
+ );
1775
+ continue;
1776
+ }
1777
+ seen.add(key);
1778
+ if (canonicalReserved.has(key)) {
1779
+ problems.push(
1780
+ `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.`
1781
+ );
1782
+ continue;
1783
+ }
1784
+ const ownerName = canonicalOwner.get(key);
1785
+ if (ownerName !== void 0) {
1786
+ recognised[ownerName] = body;
1787
+ continue;
1788
+ }
1789
+ notes.push({ heading: section.heading, body });
1790
+ }
1791
+ const preambleText = preamble.join("\n").trim();
1792
+ return {
1793
+ brief: {
1794
+ path: filePath,
1795
+ digest: createHash("sha256").update(text2, "utf8").digest("hex"),
1796
+ ...recognised["Stakes"] ? { stakes: recognised["Stakes"] } : {},
1797
+ ...recognised["The system"] ? { system: recognised["The system"] } : {},
1798
+ ...recognised["What came before"] ? { history: recognised["What came before"] } : {},
1799
+ ...recognised["The bar"] ? { bar: recognised["The bar"] } : {},
1800
+ ...recognised["Calibration"] ? { calibration: recognised["Calibration"] } : {},
1801
+ notes,
1802
+ ...preambleText.length > 0 ? { preamble: preambleText } : {}
1803
+ },
1804
+ problems
1805
+ };
1806
+ }
1736
1807
  var MANIFEST_FILES = [
1737
1808
  "package.json",
1738
1809
  "pyproject.toml",
@@ -1779,15 +1850,15 @@ var SKIPPED_WALK_DIRS = /* @__PURE__ */ new Set([
1779
1850
  ]);
1780
1851
  function readSmallFile(fullPath) {
1781
1852
  try {
1782
- const stats = fs15.statSync(fullPath);
1853
+ const stats = fs16.statSync(fullPath);
1783
1854
  if (!stats.isFile() || stats.size > MANIFEST_MAX_BYTES) return null;
1784
- return fs15.readFileSync(fullPath, "utf8");
1855
+ return fs16.readFileSync(fullPath, "utf8");
1785
1856
  } catch {
1786
1857
  return null;
1787
1858
  }
1788
1859
  }
1789
1860
  function readManifest(cwd, name) {
1790
- return readSmallFile(path16.join(cwd, name));
1861
+ return readSmallFile(path17.join(cwd, name));
1791
1862
  }
1792
1863
  function dependenciesFromPackageJson(raw) {
1793
1864
  const names = /* @__PURE__ */ new Set();
@@ -1847,7 +1918,7 @@ function pnpmWorkspacePatterns(raw) {
1847
1918
  function childDirectories(cwd, parent) {
1848
1919
  let entries;
1849
1920
  try {
1850
- entries = fs15.readdirSync(path16.join(cwd, parent), { withFileTypes: true });
1921
+ entries = fs16.readdirSync(path17.join(cwd, parent), { withFileTypes: true });
1851
1922
  } catch {
1852
1923
  return [];
1853
1924
  }
@@ -1883,12 +1954,12 @@ function scanWorkspacePackages(cwd, patterns) {
1883
1954
  const files = /* @__PURE__ */ new Set();
1884
1955
  const dependencies = /* @__PURE__ */ new Set();
1885
1956
  for (const relative11 of workspacePackageDirs(cwd, patterns)) {
1886
- const full = path16.join(cwd, relative11);
1957
+ const full = path17.join(cwd, relative11);
1887
1958
  try {
1888
- for (const entry of fs15.readdirSync(full, { withFileTypes: true })) files.add(entry.name);
1959
+ for (const entry of fs16.readdirSync(full, { withFileTypes: true })) files.add(entry.name);
1889
1960
  } catch {
1890
1961
  }
1891
- const raw = readSmallFile(path16.join(full, "package.json"));
1962
+ const raw = readSmallFile(path17.join(full, "package.json"));
1892
1963
  if (raw !== null) {
1893
1964
  for (const name of dependenciesFromPackageJson(raw)) dependencies.add(name);
1894
1965
  }
@@ -1898,7 +1969,7 @@ function scanWorkspacePackages(cwd, patterns) {
1898
1969
  var SNAPSHOT_MARKER = ".codebase-snapshot";
1899
1970
  function isToolOwnedDirectory(dir) {
1900
1971
  try {
1901
- return fs15.statSync(dir).isDirectory() && fs15.existsSync(path16.join(dir, SNAPSHOT_MARKER));
1972
+ return fs16.statSync(dir).isDirectory() && fs16.existsSync(path17.join(dir, SNAPSHOT_MARKER));
1902
1973
  } catch {
1903
1974
  return false;
1904
1975
  }
@@ -1913,7 +1984,7 @@ function countMarkdownFiles(cwd) {
1913
1984
  directoriesSeen += 1;
1914
1985
  let entries;
1915
1986
  try {
1916
- entries = fs15.readdirSync(current.dir, { withFileTypes: true });
1987
+ entries = fs16.readdirSync(current.dir, { withFileTypes: true });
1917
1988
  } catch {
1918
1989
  continue;
1919
1990
  }
@@ -1924,7 +1995,7 @@ function countMarkdownFiles(cwd) {
1924
1995
  }
1925
1996
  if (!entry.isDirectory() || current.depth >= 2) continue;
1926
1997
  if (entry.name.startsWith(".") || SKIPPED_WALK_DIRS.has(entry.name)) continue;
1927
- const child = path16.join(current.dir, entry.name);
1998
+ const child = path17.join(current.dir, entry.name);
1928
1999
  if (isToolOwnedDirectory(child)) continue;
1929
2000
  queue.push({ dir: child, depth: current.depth + 1 });
1930
2001
  }
@@ -1935,7 +2006,7 @@ function buildPresetContext(cwd) {
1935
2006
  const files = /* @__PURE__ */ new Set();
1936
2007
  const dirs = /* @__PURE__ */ new Set();
1937
2008
  try {
1938
- for (const entry of fs15.readdirSync(cwd, { withFileTypes: true })) {
2009
+ for (const entry of fs16.readdirSync(cwd, { withFileTypes: true })) {
1939
2010
  if (entry.isDirectory()) dirs.add(entry.name);
1940
2011
  else if (entry.isFile()) files.add(entry.name);
1941
2012
  }
@@ -1952,7 +2023,7 @@ function buildPresetContext(cwd) {
1952
2023
  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;
1953
2024
  let workspace = { files: /* @__PURE__ */ new Set(), dependencies: /* @__PURE__ */ new Set() };
1954
2025
  if (isWorkspace) {
1955
- const pnpmRaw = files.has("pnpm-workspace.yaml") ? readSmallFile(path16.join(cwd, "pnpm-workspace.yaml")) : null;
2026
+ const pnpmRaw = files.has("pnpm-workspace.yaml") ? readSmallFile(path17.join(cwd, "pnpm-workspace.yaml")) : null;
1956
2027
  const declared = pnpmRaw === null ? [] : pnpmWorkspacePatterns(pnpmRaw);
1957
2028
  const patterns = declared.length > 0 ? declared : declaredWorkspaces.length > 0 ? declaredWorkspaces : DEFAULT_WORKSPACE_PATTERNS;
1958
2029
  workspace = scanWorkspacePackages(cwd, patterns);
@@ -3906,7 +3977,7 @@ function applySpansKeepingQuotes(line, spans) {
3906
3977
 
3907
3978
  // src/version.ts
3908
3979
  var GENERATOR_NAME = "codebase-snapshot";
3909
- var GENERATOR_VERSION = "0.11.0";
3980
+ var GENERATOR_VERSION = "0.12.0";
3910
3981
  var SCHEMA_VERSION = "3.0.0";
3911
3982
  var LEGACY_GENERATOR_NAMES = ["@ankurhalder/codebase-snapshot"];
3912
3983
  function isOurGeneratorName(name) {
@@ -3923,14 +3994,14 @@ var PRESET_IGNORES = new Set(
3923
3994
  );
3924
3995
  function readLinkTarget(linkPath, fallback) {
3925
3996
  try {
3926
- return fs15.readlinkSync(linkPath);
3997
+ return fs16.readlinkSync(linkPath);
3927
3998
  } catch {
3928
3999
  return fallback;
3929
4000
  }
3930
4001
  }
3931
4002
  function brokenLinkRecord(linkPath, relativePath, rootReal) {
3932
4003
  const rawTarget = readLinkTarget(linkPath, linkPath);
3933
- const resolvedFallback = path16.resolve(path16.dirname(linkPath), rawTarget);
4004
+ const resolvedFallback = path17.resolve(path17.dirname(linkPath), rawTarget);
3934
4005
  return isInside(rootReal, resolvedFallback) ? { path: relativePath, reason: "read-error", detail: "broken symlink" } : {
3935
4006
  path: relativePath,
3936
4007
  reason: "outside-root",
@@ -3938,8 +4009,8 @@ function brokenLinkRecord(linkPath, relativePath, rootReal) {
3938
4009
  };
3939
4010
  }
3940
4011
  function isInside(root, candidate) {
3941
- const relative11 = path16.relative(root, candidate);
3942
- return relative11 === "" || !relative11.startsWith(`..${path16.sep}`) && relative11 !== ".." && !path16.isAbsolute(relative11);
4012
+ const relative11 = path17.relative(root, candidate);
4013
+ return relative11 === "" || !relative11.startsWith(`..${path17.sep}`) && relative11 !== ".." && !path17.isAbsolute(relative11);
3943
4014
  }
3944
4015
  var GIT_OUTPUT_LIMIT = 68157440;
3945
4016
  function getGitInfo(cwd, fallbackBranch = "main") {
@@ -4197,10 +4268,10 @@ function trimUnescapedTrailingSpaces(line) {
4197
4268
  return line.slice(0, end);
4198
4269
  }
4199
4270
  function readGitignoreRules(dir) {
4200
- const gitignorePath2 = path16.join(dir, ".gitignore");
4271
+ const gitignorePath2 = path17.join(dir, ".gitignore");
4201
4272
  let raw;
4202
4273
  try {
4203
- raw = fs15.readFileSync(gitignorePath2, "utf8");
4274
+ raw = fs16.readFileSync(gitignorePath2, "utf8");
4204
4275
  } catch {
4205
4276
  return [];
4206
4277
  }
@@ -4354,11 +4425,14 @@ function defaultIgnoreReason(relativePath, toolDirNames = DEFAULT_TOOL_DIR_NAMES
4354
4425
  }
4355
4426
  return null;
4356
4427
  }
4357
- function recentCommitSubjects(cwd, limit = 10) {
4428
+ var COMMIT_BODY_LIMIT = 400;
4429
+ function recentCommits(cwd, limit = 10) {
4358
4430
  try {
4359
4431
  const stdout = childProcess.execFileSync(
4360
4432
  "git",
4361
- ["log", "-n", String(limit), "--pretty=%s", "--no-color"],
4433
+ // \x1f between fields and \x1e between records: neither can appear in a commit message, so
4434
+ // the parse cannot be confused by a message that contains a newline or a dash.
4435
+ ["log", "-n", String(limit), "--pretty=format:%s%x1f%b%x1e", "--no-color"],
4362
4436
  {
4363
4437
  cwd,
4364
4438
  stdio: ["ignore", "pipe", "ignore"],
@@ -4366,7 +4440,16 @@ function recentCommitSubjects(cwd, limit = 10) {
4366
4440
  maxBuffer: GIT_OUTPUT_LIMIT
4367
4441
  }
4368
4442
  );
4369
- return stdout.split("\n").map((line) => line.trim()).filter((line) => line.length > 0);
4443
+ return stdout.split("").map((record) => record.replace(/^\n+/, "")).filter((record) => record.length > 0).map((record) => {
4444
+ const separator = record.indexOf("");
4445
+ const subject = separator === -1 ? record : record.slice(0, separator);
4446
+ const rawBody = separator === -1 ? "" : record.slice(separator + 1);
4447
+ const body = rawBody.split("\n").map((line) => line.trim()).filter((line) => line.length > 0).join(" ");
4448
+ return {
4449
+ subject: subject.trim(),
4450
+ body: body.length > COMMIT_BODY_LIMIT ? body.slice(0, COMMIT_BODY_LIMIT - 1) + "\u2026" : body
4451
+ };
4452
+ }).filter((commit) => commit.subject.length > 0);
4370
4453
  } catch {
4371
4454
  return [];
4372
4455
  }
@@ -4390,7 +4473,7 @@ function listIgnoredPaths(cwd) {
4390
4473
  }
4391
4474
  function hasSnapshotMarker(target) {
4392
4475
  try {
4393
- return fs15.statSync(target).isDirectory() && fs15.existsSync(path16.join(target, ".codebase-snapshot"));
4476
+ return fs16.statSync(target).isDirectory() && fs16.existsSync(path17.join(target, ".codebase-snapshot"));
4394
4477
  } catch {
4395
4478
  return false;
4396
4479
  }
@@ -4399,7 +4482,7 @@ var IGNORABLE_DIRECTORY_ENTRIES = /* @__PURE__ */ new Set([".DS_Store"]);
4399
4482
  function isToolOwnedDirectory2(dir) {
4400
4483
  let raw;
4401
4484
  try {
4402
- raw = fs15.readFileSync(path16.join(dir, ".codebase-snapshot"), "utf8");
4485
+ raw = fs16.readFileSync(path17.join(dir, ".codebase-snapshot"), "utf8");
4403
4486
  } catch {
4404
4487
  return false;
4405
4488
  }
@@ -4426,7 +4509,7 @@ function isToolOwnedDirectory2(dir) {
4426
4509
  }
4427
4510
  let entries;
4428
4511
  try {
4429
- entries = fs15.readdirSync(dir);
4512
+ entries = fs16.readdirSync(dir);
4430
4513
  } catch {
4431
4514
  return false;
4432
4515
  }
@@ -4443,7 +4526,7 @@ function makeToolOwnedDecider(cwd, toolOwnedPaths) {
4443
4526
  const prefix = parts.slice(0, depth).join("/");
4444
4527
  let hasMarker = markers.get(prefix);
4445
4528
  if (hasMarker === void 0) {
4446
- hasMarker = isToolOwnedDirectory2(path16.join(cwd, prefix));
4529
+ hasMarker = isToolOwnedDirectory2(path17.join(cwd, prefix));
4447
4530
  markers.set(prefix, hasMarker);
4448
4531
  }
4449
4532
  if (hasMarker) return true;
@@ -4458,7 +4541,7 @@ function makeLinkProbe() {
4458
4541
  let known = cache.get(absolutePath);
4459
4542
  if (known === void 0) {
4460
4543
  try {
4461
- known = fs15.lstatSync(absolutePath).isSymbolicLink();
4544
+ known = fs16.lstatSync(absolutePath).isSymbolicLink();
4462
4545
  } catch {
4463
4546
  known = false;
4464
4547
  }
@@ -4471,7 +4554,7 @@ function dropLinkedDirectories(cwd, candidates, skipped) {
4471
4554
  const isLink = makeLinkProbe();
4472
4555
  let rootReal = cwd;
4473
4556
  try {
4474
- rootReal = fs15.realpathSync(cwd);
4557
+ rootReal = fs16.realpathSync(cwd);
4475
4558
  } catch {
4476
4559
  }
4477
4560
  const reported = /* @__PURE__ */ new Set();
@@ -4486,7 +4569,7 @@ function dropLinkedDirectories(cwd, candidates, skipped) {
4486
4569
  let linkedPath = null;
4487
4570
  for (let depth = 1; depth <= parts.length; depth += 1) {
4488
4571
  const prefix = parts.slice(0, depth).join("/");
4489
- if (isLink(path16.join(cwd, prefix))) {
4572
+ if (isLink(path17.join(cwd, prefix))) {
4490
4573
  linkedPath = prefix;
4491
4574
  break;
4492
4575
  }
@@ -4495,11 +4578,11 @@ function dropLinkedDirectories(cwd, candidates, skipped) {
4495
4578
  kept.push(candidate);
4496
4579
  continue;
4497
4580
  }
4498
- const absolute = path16.join(cwd, linkedPath);
4581
+ const absolute = path17.join(cwd, linkedPath);
4499
4582
  const rawTarget = readLinkTarget(absolute, absolute);
4500
4583
  let targetReal = null;
4501
4584
  try {
4502
- targetReal = fs15.realpathSync(absolute);
4585
+ targetReal = fs16.realpathSync(absolute);
4503
4586
  } catch {
4504
4587
  targetReal = null;
4505
4588
  }
@@ -4517,7 +4600,7 @@ function dropLinkedDirectories(cwd, candidates, skipped) {
4517
4600
  }
4518
4601
  let stats = null;
4519
4602
  try {
4520
- stats = fs15.statSync(absolute);
4603
+ stats = fs16.statSync(absolute);
4521
4604
  } catch {
4522
4605
  stats = null;
4523
4606
  }
@@ -4605,7 +4688,7 @@ function collectFiles(cwd, options = {}) {
4605
4688
  "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."
4606
4689
  );
4607
4690
  }
4608
- if (fs15.existsSync(path16.join(cwd, ".git"))) {
4691
+ if (fs16.existsSync(path17.join(cwd, ".git"))) {
4609
4692
  throw new Error(
4610
4693
  "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."
4611
4694
  );
@@ -4673,7 +4756,7 @@ function collectFiles(cwd, options = {}) {
4673
4756
  }
4674
4757
  function rootRealFor(root) {
4675
4758
  try {
4676
- return fs15.realpathSync(root);
4759
+ return fs16.realpathSync(root);
4677
4760
  } catch {
4678
4761
  return root;
4679
4762
  }
@@ -4682,18 +4765,18 @@ function walkDirectory(dir, baseDir, rootReal, visited, reservedPaths = /* @__PU
4682
4765
  const results = { files: [], skipped: [] };
4683
4766
  const stack = [];
4684
4767
  const toolDirNames = toolDirNamesFor(reservedPaths);
4685
- const relativeToBase = (target) => path16.relative(baseDir, target).replace(/\\/g, "/") || ".";
4768
+ const relativeToBase = (target) => path17.relative(baseDir, target).replace(/\\/g, "/") || ".";
4686
4769
  const enter = (current, layers) => {
4687
4770
  if (visited.has(current)) return false;
4688
4771
  visited.add(current);
4689
4772
  const localRules = readGitignoreRules(current);
4690
4773
  const gitignoreLayers = localRules.length === 0 ? layers : [
4691
4774
  ...layers,
4692
- { prefix: path16.relative(baseDir, current).replace(/\\/g, "/"), rules: localRules }
4775
+ { prefix: path17.relative(baseDir, current).replace(/\\/g, "/"), rules: localRules }
4693
4776
  ];
4694
4777
  let entries;
4695
4778
  try {
4696
- entries = fs15.readdirSync(current, { withFileTypes: true });
4779
+ entries = fs16.readdirSync(current, { withFileTypes: true });
4697
4780
  } catch {
4698
4781
  results.skipped.push({
4699
4782
  path: relativeToBase(current),
@@ -4715,8 +4798,8 @@ function walkDirectory(dir, baseDir, rootReal, visited, reservedPaths = /* @__PU
4715
4798
  }
4716
4799
  const entry = frame.entries[frame.index];
4717
4800
  frame.index += 1;
4718
- const fullPath = path16.join(frame.dir, entry.name);
4719
- const relPath = path16.relative(baseDir, fullPath).replace(/\\/g, "/");
4801
+ const fullPath = path17.join(frame.dir, entry.name);
4802
+ const relPath = path17.relative(baseDir, fullPath).replace(/\\/g, "/");
4720
4803
  if (reservedPaths.has(relPath)) continue;
4721
4804
  if (entry.isDirectory() && DEFAULT_IGNORED_DIRS.includes(entry.name)) {
4722
4805
  results.skipped.push({
@@ -4749,14 +4832,14 @@ function walkDirectory(dir, baseDir, rootReal, visited, reservedPaths = /* @__PU
4749
4832
  if (entry.isSymbolicLink()) {
4750
4833
  let targetReal;
4751
4834
  try {
4752
- targetReal = fs15.realpathSync(fullPath);
4835
+ targetReal = fs16.realpathSync(fullPath);
4753
4836
  } catch {
4754
4837
  results.skipped.push(brokenLinkRecord(fullPath, relPath, rootReal));
4755
4838
  continue;
4756
4839
  }
4757
4840
  let stats;
4758
4841
  try {
4759
- stats = fs15.statSync(fullPath);
4842
+ stats = fs16.statSync(fullPath);
4760
4843
  } catch {
4761
4844
  results.skipped.push({ path: relPath, reason: "read-error", detail: "unreadable symlink" });
4762
4845
  continue;
@@ -4786,7 +4869,7 @@ function walkDirectory(dir, baseDir, rootReal, visited, reservedPaths = /* @__PU
4786
4869
  });
4787
4870
  continue;
4788
4871
  }
4789
- const targetRelative = path16.relative(rootReal, targetReal).split(path16.sep).join("/");
4872
+ const targetRelative = path17.relative(rootReal, targetReal).split(path17.sep).join("/");
4790
4873
  if (isSensitivePath(targetRelative)) {
4791
4874
  results.skipped.push({
4792
4875
  path: relPath,
@@ -4842,20 +4925,20 @@ var CONFIG_FILENAMES = [
4842
4925
  ];
4843
4926
  function findConfigFile(cwd) {
4844
4927
  for (const filename of CONFIG_FILENAMES) {
4845
- const fullPath = path16.join(cwd, filename);
4928
+ const fullPath = path17.join(cwd, filename);
4846
4929
  let stats = null;
4847
4930
  try {
4848
- stats = fs15.statSync(fullPath);
4931
+ stats = fs16.statSync(fullPath);
4849
4932
  } catch {
4850
- if (fs15.existsSync(fullPath)) return fullPath;
4933
+ if (fs16.existsSync(fullPath)) return fullPath;
4851
4934
  continue;
4852
4935
  }
4853
4936
  if (stats.isFile()) return fullPath;
4854
4937
  }
4855
- const pkgJsonPath = path16.join(cwd, "package.json");
4856
- if (!fs15.existsSync(pkgJsonPath)) return null;
4938
+ const pkgJsonPath = path17.join(cwd, "package.json");
4939
+ if (!fs16.existsSync(pkgJsonPath)) return null;
4857
4940
  try {
4858
- const parsed = JSON.parse(stripJsonComments(fs15.readFileSync(pkgJsonPath, "utf8")));
4941
+ const parsed = JSON.parse(stripJsonComments(fs16.readFileSync(pkgJsonPath, "utf8")));
4859
4942
  const snapshot = parsed?.snapshot;
4860
4943
  return typeof snapshot === "object" && snapshot !== null && !Array.isArray(snapshot) ? pkgJsonPath : null;
4861
4944
  } catch {
@@ -4921,6 +5004,8 @@ function normalizeResolvedConfig(config) {
4921
5004
  // is re-validated because the number reaches a rendered artifact.
4922
5005
  attachmentSlots: resolveAttachmentSlots(config.attachmentSlots),
4923
5006
  maxParts: resolveMaxParts(config.maxParts),
5007
+ promptTask: resolvePromptTask(config.promptTask),
5008
+ ...config.brief === void 0 ? {} : { brief: config.brief },
4924
5009
  includeMonolith: artifacts.monolith,
4925
5010
  secretRules: compileSecretRules(config.secretRules),
4926
5011
  artifacts,
@@ -4991,6 +5076,7 @@ var CONFIG_KEY_NAMES = [
4991
5076
  "artifacts",
4992
5077
  "attachmentSlots",
4993
5078
  "branch",
5079
+ "brief",
4994
5080
  "budgets",
4995
5081
  "changedSince",
4996
5082
  "cwd",
@@ -5012,6 +5098,7 @@ var CONFIG_KEY_NAMES = [
5012
5098
  "outDir",
5013
5099
  "preset",
5014
5100
  "previewHeadLines",
5101
+ "promptTask",
5015
5102
  "staged",
5016
5103
  "previewTailLines",
5017
5104
  "secretRules",
@@ -5062,10 +5149,10 @@ function readConfigExport(exported, file) {
5062
5149
  var lastModuleConfig = null;
5063
5150
  function moduleConfigKey(fullPath) {
5064
5151
  try {
5065
- return createHash("sha256").update(fs15.readFileSync(fullPath)).digest("hex").slice(0, 24);
5152
+ return createHash("sha256").update(fs16.readFileSync(fullPath)).digest("hex").slice(0, 24);
5066
5153
  } catch {
5067
5154
  try {
5068
- const stats = fs15.statSync(fullPath);
5155
+ const stats = fs16.statSync(fullPath);
5069
5156
  return `stat-${stats.mtimeMs}-${stats.size}`;
5070
5157
  } catch {
5071
5158
  return "unreadable";
@@ -5091,7 +5178,7 @@ async function importConfigModule(fullPath) {
5091
5178
  function attachConfigDir(config, filePath) {
5092
5179
  if (typeof config === "object" && config !== null) {
5093
5180
  Object.defineProperty(config, CONFIG_DIR_SYMBOL, {
5094
- value: path16.dirname(filePath),
5181
+ value: path17.dirname(filePath),
5095
5182
  enumerable: false,
5096
5183
  configurable: true
5097
5184
  });
@@ -5103,12 +5190,12 @@ async function loadConfigFileDetailed(cwd, options = {}) {
5103
5190
  const errors = [];
5104
5191
  const configDirectories = [];
5105
5192
  for (const filename of CONFIG_FILENAMES) {
5106
- const fullPath = path16.join(cwd, filename);
5193
+ const fullPath = path17.join(cwd, filename);
5107
5194
  let candidateStats = null;
5108
5195
  try {
5109
- candidateStats = fs15.statSync(fullPath);
5196
+ candidateStats = fs16.statSync(fullPath);
5110
5197
  } catch {
5111
- if (!fs15.existsSync(fullPath)) continue;
5198
+ if (!fs16.existsSync(fullPath)) continue;
5112
5199
  }
5113
5200
  if (candidateStats !== null && !candidateStats.isFile()) {
5114
5201
  configDirectories.push(fullPath);
@@ -5116,7 +5203,7 @@ async function loadConfigFileDetailed(cwd, options = {}) {
5116
5203
  }
5117
5204
  if (filename.endsWith(".json") || filename === ".snapshotrc") {
5118
5205
  try {
5119
- const config = parseJsonish(fs15.readFileSync(fullPath, "utf8"), fullPath);
5206
+ const config = parseJsonish(fs16.readFileSync(fullPath, "utf8"), fullPath);
5120
5207
  if (config === null || typeof config !== "object" || Array.isArray(config)) {
5121
5208
  throw new Error(
5122
5209
  `${fullPath} does not hold a configuration object (received ${describeValue2(config)}).`
@@ -5156,10 +5243,10 @@ async function loadConfigFileDetailed(cwd, options = {}) {
5156
5243
  continue;
5157
5244
  }
5158
5245
  }
5159
- const pkgJsonPath = path16.join(cwd, "package.json");
5160
- if (fs15.existsSync(pkgJsonPath)) {
5246
+ const pkgJsonPath = path17.join(cwd, "package.json");
5247
+ if (fs16.existsSync(pkgJsonPath)) {
5161
5248
  try {
5162
- const parsed = parseJsonish(fs15.readFileSync(pkgJsonPath, "utf8"), pkgJsonPath);
5249
+ const parsed = parseJsonish(fs16.readFileSync(pkgJsonPath, "utf8"), pkgJsonPath);
5163
5250
  const snapshotKey = parsed.snapshot;
5164
5251
  if (snapshotKey && typeof snapshotKey === "object" && !Array.isArray(snapshotKey)) {
5165
5252
  assertKnownConfigKeys(
@@ -5303,6 +5390,38 @@ function resolveMaxParts(value) {
5303
5390
  }
5304
5391
  return value;
5305
5392
  }
5393
+ function resolvePromptTask(value) {
5394
+ if (value === void 0 || value === null) return "audit";
5395
+ if (value === "audit" || value === "review" || value === "explain") return value;
5396
+ throw new Error(
5397
+ 'promptTask must be one of "audit", "review" or "explain" (received ' + describeValue2(value) + ")."
5398
+ );
5399
+ }
5400
+ function readConfiguredBrief(cwd, value) {
5401
+ if (value === void 0 || value === null) return void 0;
5402
+ if (typeof value !== "string" || value.trim().length === 0) {
5403
+ throw new Error(
5404
+ "brief must be a path to a markdown file (received " + describeValue2(value) + ")."
5405
+ );
5406
+ }
5407
+ const filePath = path17.resolve(cwd, value);
5408
+ let text2;
5409
+ try {
5410
+ if (!fs16.statSync(filePath).isFile()) throw new Error("not a file");
5411
+ text2 = fs16.readFileSync(filePath, "utf8");
5412
+ } catch {
5413
+ throw new Error(
5414
+ 'brief "' + value + '" could not be read as a file; a snapshot must not ship without the half of the brief the owner wrote.'
5415
+ );
5416
+ }
5417
+ const parsed = parseOwnerBrief(value, text2);
5418
+ if (parsed.problems.length > 0) {
5419
+ throw new Error(
5420
+ 'brief "' + value + '" cannot be used:\n - ' + parsed.problems.join("\n - ")
5421
+ );
5422
+ }
5423
+ return parsed.brief;
5424
+ }
5306
5425
  function strictPositiveInteger(value, fallback, label) {
5307
5426
  if (value === void 0) return fallback;
5308
5427
  if (typeof value !== "number" || !Number.isInteger(value) || value <= 0) {
@@ -5395,9 +5514,9 @@ function resolveKindRules(value) {
5395
5514
  function outputExcludePatterns(cwd, outDir, tmpDir) {
5396
5515
  const patterns = [];
5397
5516
  for (const dir of [outDir, tmpDir]) {
5398
- const absolute = path16.resolve(cwd, dir);
5399
- const relative11 = path16.relative(cwd, absolute);
5400
- if (!relative11 || relative11 === ".." || relative11.startsWith(`..${path16.sep}`) || path16.isAbsolute(relative11)) {
5517
+ const absolute = path17.resolve(cwd, dir);
5518
+ const relative11 = path17.relative(cwd, absolute);
5519
+ if (!relative11 || relative11 === ".." || relative11.startsWith(`..${path17.sep}`) || path17.isAbsolute(relative11)) {
5401
5520
  continue;
5402
5521
  }
5403
5522
  patterns.push(`${relative11.replace(/\\/g, "/")}/**`);
@@ -5530,11 +5649,11 @@ function resolveCandidateCwd(userConfig, cliOptions, baseDir) {
5530
5649
  );
5531
5650
  }
5532
5651
  const candidate = cliOptions?.cwd || userConfig?.cwd || baseDir || process.cwd();
5533
- const resolved = path16.resolve(candidate);
5534
- if (!fs15.existsSync(resolved)) {
5652
+ const resolved = path17.resolve(candidate);
5653
+ if (!fs16.existsSync(resolved)) {
5535
5654
  throw new Error(`Working directory does not exist: ${resolved}`);
5536
5655
  }
5537
- if (!fs15.statSync(resolved).isDirectory()) {
5656
+ if (!fs16.statSync(resolved).isDirectory()) {
5538
5657
  throw new Error(`Working directory is not a directory: ${resolved}`);
5539
5658
  }
5540
5659
  return resolved;
@@ -5662,6 +5781,10 @@ function resolveConfig(userConfig, cliOptions, baseDir) {
5662
5781
  configuredSensitiveFiles,
5663
5782
  "`includeSensitiveFiles`"
5664
5783
  );
5784
+ const configuredBrief = readConfiguredBrief(
5785
+ cwd,
5786
+ cliOptions?.brief ?? userConfig?.brief
5787
+ );
5665
5788
  const presetExclude = [
5666
5789
  .../* @__PURE__ */ new Set([...preset.exclude, ...outputExcludePatterns(cwd, outDir, tmpDir)])
5667
5790
  ];
@@ -5685,6 +5808,8 @@ function resolveConfig(userConfig, cliOptions, baseDir) {
5685
5808
  cliOptions?.attachmentSlots ?? userConfig?.attachmentSlots
5686
5809
  ),
5687
5810
  maxParts: resolveMaxParts(cliOptions?.maxParts ?? userConfig?.maxParts),
5811
+ promptTask: resolvePromptTask(cliOptions?.promptTask ?? userConfig?.promptTask),
5812
+ ...configuredBrief === void 0 ? {} : { brief: configuredBrief },
5688
5813
  ...changedSince === void 0 ? {} : { changedSince },
5689
5814
  ...staged ? { staged } : {},
5690
5815
  ...withDependents ? { withDependents } : {},
@@ -5770,6 +5895,12 @@ function configDigest(config) {
5770
5895
  // Only when the experimental mode is on: `null` is the off switch, and writing it into the
5771
5896
  // material would change the digest of every snapshot taken before the setting existed.
5772
5897
  ...config.maxParts === null ? {} : { maxParts: config.maxParts },
5898
+ // The default value is omitted for the same reason: a snapshot taken before the setting
5899
+ // existed kept the audit job, so it must keep the digest it was written with.
5900
+ ...config.promptTask === "audit" ? {} : { promptTask: config.promptTask },
5901
+ // The owner brief is instruction, not payload, but it changes what the snapshot tells a
5902
+ // reader to do, so a changed brief is drift exactly like a changed budget.
5903
+ ...config.brief === void 0 ? {} : { brief: config.brief.digest },
5773
5904
  artifacts: config.artifacts,
5774
5905
  include: config.include,
5775
5906
  excludePatterns: config.excludePatterns,
@@ -6741,9 +6872,15 @@ var UNLIMITED_SLOTS = 0;
6741
6872
  var ENTRY_POINT = /(^|\/)(index|cli|main|bin|server|app|mod)\.[cm]?[jt]sx?$/;
6742
6873
  var TEST_PATH = /(^|\/)(tests?|__tests__)\//;
6743
6874
  var TEST_FILE = /\.(test|spec)\.[^.]+$/;
6744
- function generatePrompt(manifest, artifacts, attachmentSlots = DEFAULT_ATTACHMENT_SLOTS, history = []) {
6875
+ function generatePrompt(manifest, artifacts, context = {}) {
6876
+ const slots = context.slots ?? DEFAULT_ATTACHMENT_SLOTS;
6877
+ const task = context.task ?? "audit";
6878
+ const history = context.history ?? [];
6879
+ const overview = context.overview ?? { releases: [] };
6880
+ const brief = context.brief;
6745
6881
  const wrote = (name) => artifacts?.[name] !== false;
6746
6882
  const code = (value) => inlineCode(escapeControls(value));
6883
+ const hasOwnerHistory = (brief?.history ?? "").trim().length > 0;
6747
6884
  const lines = [
6748
6885
  "# PROMPT.md",
6749
6886
  "",
@@ -6759,30 +6896,22 @@ function generatePrompt(manifest, artifacts, attachmentSlots = DEFAULT_ATTACHMEN
6759
6896
  "You are working on a codebase you cannot clone, run or grep. Everything you know about it comes",
6760
6897
  "from the snapshot that follows this instruction. Where these notes and the snapshot disagree,",
6761
6898
  "the snapshot is what exists.",
6762
- "",
6763
- "## The job",
6764
- "",
6765
- "Find what is still wrong or will break. How you read the code is yours to decide - by",
6766
- "subsystem, by data flow, by the invariants you derive yourself. What you owe in return is an",
6767
- "honest account of what you covered and what you did not.",
6768
- "",
6769
- history.length > 0 ? "Another pass of the same findings is worth nothing. This repository carries a record of" : "Another pass of the same findings is worth nothing, but no earlier round is readable here,",
6770
- history.length > 0 ? "what was already fixed, below. Verify that those fixes hold instead of rediscovering them," : "so you cannot tell what has already been tried. Do not assume this is the first attempt.",
6771
- history.length > 0 ? "and treat a variant of one at a different call site as a new finding." : "Every finding you report has to stand on the code alone.",
6772
- "",
6773
- "If the task at the end asks for something narrower - explain a file, review a change, answer a",
6774
- "question - that task wins. The standard and the coverage duty below still apply to it.",
6775
6899
  ""
6776
6900
  ];
6901
+ if (brief?.preamble !== void 0) lines.push(brief.preamble, "");
6902
+ lines.push(...jobSection(task, history.length > 0 || hasOwnerHistory), "");
6903
+ lines.push(...stakesSection(brief, code));
6777
6904
  lines.push(...haveSection(wrote), "");
6778
- lines.push(...systemSection(manifest, code), "");
6779
- lines.push(...historySection(history), "");
6780
- lines.push(...barSection(), "");
6905
+ lines.push(...whatThisIsSection(overview), "");
6906
+ lines.push(...systemSection(manifest, code, brief), "");
6907
+ lines.push(...historySection(history, brief, code), "");
6908
+ lines.push(...barSection(brief, code), "");
6781
6909
  lines.push(...coverageSection(manifest, code, wrote("audit")), "");
6782
6910
  lines.push(...answerSection(), "");
6783
- lines.push(...calibrationSection(), "");
6911
+ lines.push(...calibrationSection(brief, code), "");
6912
+ lines.push(...ownerNotesSection(brief, code));
6784
6913
  lines.push(...snapshotSection(manifest, code), "");
6785
- lines.push(...deliverySection(manifest, wrote("parts"), attachmentSlots));
6914
+ lines.push(...deliverySection(manifest, wrote("parts"), slots));
6786
6915
  lines.push(
6787
6916
  "## Your task",
6788
6917
  "",
@@ -6859,8 +6988,11 @@ function haveSection(wrote) {
6859
6988
  out.push(...bullets);
6860
6989
  return out;
6861
6990
  }
6862
- function systemSection(manifest, code) {
6991
+ function systemSection(manifest, code, brief) {
6863
6992
  const out = ["## The system", ""];
6993
+ if (brief?.system !== void 0) {
6994
+ out.push(...ownerBlock(brief.system, brief.path, code), "", "What the index records:", "");
6995
+ }
6864
6996
  const layers = Object.entries(manifest.layers).sort((a, b) => b[1] - a[1] || a[0].localeCompare(b[0]));
6865
6997
  if (layers.length > 0) {
6866
6998
  const shown = layers.slice(0, MAX_LAYER_ROWS).map(([name, count]) => code(name) + " " + formatNumber(count));
@@ -6875,7 +7007,7 @@ function systemSection(manifest, code) {
6875
7007
  " A change here reaches the most call sites; read it before judging anything that uses it."
6876
7008
  );
6877
7009
  }
6878
- const entryPoints = manifest.files.map((file) => file.relativePath).filter((path17) => ENTRY_POINT.test(path17)).sort((a, b) => a.split("/").length - b.split("/").length || a.length - b.length).slice(0, MAX_ENTRY_POINTS);
7010
+ const entryPoints = manifest.files.map((file) => file.relativePath).filter((path18) => ENTRY_POINT.test(path18)).sort((a, b) => a.split("/").length - b.split("/").length || a.length - b.length).slice(0, MAX_ENTRY_POINTS);
6879
7011
  out.push(
6880
7012
  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"
6881
7013
  );
@@ -6918,8 +7050,9 @@ function systemSection(manifest, code) {
6918
7050
  }
6919
7051
  return out;
6920
7052
  }
6921
- function historySection(history) {
7053
+ function historySection(history, brief, code) {
6922
7054
  const out = ["## What came before", ""];
7055
+ if (brief?.history !== void 0) out.push(...ownerBlock(brief.history, brief.path, code), "");
6923
7056
  if (history.length === 0) {
6924
7057
  out.push(
6925
7058
  "No history was readable: this is not a git checkout, or git could not be run. Nothing about",
@@ -6928,15 +7061,21 @@ function historySection(history) {
6928
7061
  return out;
6929
7062
  }
6930
7063
  out.push(
6931
- "Commit subjects, newest first. They are claims by whoever wrote them, not evidence - the code",
6932
- "beside them is the evidence. If one of these fixes looks incomplete, quote the lines and say",
6933
- "which call site it missed.",
7064
+ "The last " + formatNumber(history.length) + " commit(s), newest first. Subjects and bodies are",
7065
+ "claims by whoever wrote them, not evidence - the code beside them is the evidence. If one of",
7066
+ "these fixes looks incomplete, quote the lines and say which call site it missed.",
6934
7067
  ""
6935
7068
  );
6936
- for (const subject of history) out.push("- " + subject);
7069
+ for (const commit of history) {
7070
+ out.push("- " + commit.subject);
7071
+ if (commit.body.length > 0) out.push(" " + commit.body);
7072
+ }
6937
7073
  return out;
6938
7074
  }
6939
- function barSection() {
7075
+ function barSection(brief, code) {
7076
+ if (brief?.bar !== void 0) {
7077
+ return ["## The bar", "", ...ownerBlock(brief.bar, brief.path, code), ""];
7078
+ }
6940
7079
  return [
6941
7080
  "## The bar",
6942
7081
  "",
@@ -6994,7 +7133,10 @@ function answerSection() {
6994
7133
  " the gap you filled by asking instead of guessing."
6995
7134
  ];
6996
7135
  }
6997
- function calibrationSection() {
7136
+ function calibrationSection(brief, code) {
7137
+ if (brief?.calibration !== void 0) {
7138
+ return ["## Calibration", "", ...ownerBlock(brief.calibration, brief.path, code), ""];
7139
+ }
6998
7140
  return [
6999
7141
  "## Calibration",
7000
7142
  "",
@@ -7009,6 +7151,84 @@ function calibrationSection() {
7009
7151
  "None of these throw. All are invisible in a summary."
7010
7152
  ];
7011
7153
  }
7154
+ function jobSection(task, hasHistory) {
7155
+ const out = ["## The job", ""];
7156
+ if (task === "audit") {
7157
+ out.push(
7158
+ "Find what is still wrong or will break. How you read the code is yours to decide - by",
7159
+ "subsystem, by data flow, by the invariants you derive yourself. What you owe in return is an",
7160
+ "honest account of what you covered and what you did not.",
7161
+ ""
7162
+ );
7163
+ if (hasHistory) {
7164
+ out.push(
7165
+ "Another pass of the same findings is worth nothing. This repository carries a record of",
7166
+ "what was already fixed, below. Verify that those fixes hold instead of rediscovering them,",
7167
+ "and treat a variant of one at a different call site as a new finding."
7168
+ );
7169
+ } else {
7170
+ out.push(
7171
+ "Another pass of the same findings is worth nothing, but no earlier round is readable here,",
7172
+ "so you cannot tell what has already been tried. Do not assume this is the first attempt."
7173
+ );
7174
+ }
7175
+ out.push(
7176
+ "",
7177
+ "If the task at the end asks for something narrower - explain a file, review a change, answer",
7178
+ "a question - that task wins. The standard and the coverage duty below still apply to it."
7179
+ );
7180
+ } else if (task === "review") {
7181
+ out.push(
7182
+ "Review the change or the area named in the task against this snapshot. Report what breaks,",
7183
+ "what the change claims but does not do, and what a reader would believe that the code does",
7184
+ "not support. Restating the diff is not a review; the standard and the coverage duty below",
7185
+ "still apply."
7186
+ );
7187
+ } else {
7188
+ out.push(
7189
+ "Explain how the part of the system named in the task works: the data flow, the boundaries",
7190
+ "and the invariants it depends on. Cite the lines. If the snapshot does not contain what you",
7191
+ "need, say which file you need rather than reconstructing it from the shape of the names."
7192
+ );
7193
+ }
7194
+ return out;
7195
+ }
7196
+ function stakesSection(brief, code) {
7197
+ if (brief?.stakes === void 0) return [];
7198
+ return ["## Stakes", "", ...ownerBlock(brief.stakes, brief.path, code), ""];
7199
+ }
7200
+ function whatThisIsSection(overview) {
7201
+ const body = [];
7202
+ if (overview.description !== void 0) {
7203
+ body.push("- Declared in `package.json`: " + overview.description);
7204
+ }
7205
+ if (overview.summary !== void 0) {
7206
+ body.push("- From the `README.md` first paragraph: " + overview.summary);
7207
+ }
7208
+ if (overview.releases.length > 0) {
7209
+ body.push("- Most recent releases: " + overview.releases.join("; ") + ".");
7210
+ }
7211
+ if (body.length === 0) return [];
7212
+ return [
7213
+ "## What this is",
7214
+ "",
7215
+ ...body,
7216
+ "",
7217
+ "Those are the project's own claims, not evidence about the code.",
7218
+ ""
7219
+ ];
7220
+ }
7221
+ function ownerNotesSection(brief, code) {
7222
+ if (brief === void 0 || brief.notes.length === 0) return [];
7223
+ const out = ["## Owner notes", ""];
7224
+ for (const note of brief.notes) {
7225
+ out.push("### " + note.heading, "", ...ownerBlock(note.body, brief.path, code), "");
7226
+ }
7227
+ return out;
7228
+ }
7229
+ function ownerBlock(text2, path18, code) {
7230
+ return ["> Written by the project owner in " + code(path18) + ", not generated.", "", text2];
7231
+ }
7012
7232
  function snapshotSection(manifest, code) {
7013
7233
  const out = ["## This snapshot", ""];
7014
7234
  out.push("- Fingerprint: " + code(manifest.fingerprint) + " - quote it verbatim in your answer.");
@@ -7364,7 +7584,7 @@ function resolveChangedScope(cwd, request) {
7364
7584
  const descriptions = [];
7365
7585
  if (request.changedSince !== void 0) {
7366
7586
  assertUsableRef(request.changedSince);
7367
- for (const path17 of gitPaths(cwd, [
7587
+ for (const path18 of gitPaths(cwd, [
7368
7588
  "diff",
7369
7589
  "--name-only",
7370
7590
  "-z",
@@ -7372,9 +7592,9 @@ function resolveChangedScope(cwd, request) {
7372
7592
  `${request.changedSince}...HEAD`,
7373
7593
  "--"
7374
7594
  ])) {
7375
- paths.add(path17);
7595
+ paths.add(path18);
7376
7596
  }
7377
- for (const path17 of gitPaths(cwd, [
7597
+ for (const path18 of gitPaths(cwd, [
7378
7598
  "diff",
7379
7599
  "--name-only",
7380
7600
  "-z",
@@ -7382,15 +7602,15 @@ function resolveChangedScope(cwd, request) {
7382
7602
  "HEAD",
7383
7603
  "--"
7384
7604
  ])) {
7385
- paths.add(path17);
7605
+ paths.add(path18);
7386
7606
  }
7387
- for (const path17 of gitPaths(cwd, ["ls-files", "--others", "--exclude-standard", "-z", "--"])) {
7388
- paths.add(path17);
7607
+ for (const path18 of gitPaths(cwd, ["ls-files", "--others", "--exclude-standard", "-z", "--"])) {
7608
+ paths.add(path18);
7389
7609
  }
7390
7610
  descriptions.push(`changed since ${request.changedSince}`);
7391
7611
  }
7392
7612
  if (request.staged === true) {
7393
- for (const path17 of gitPaths(cwd, [
7613
+ for (const path18 of gitPaths(cwd, [
7394
7614
  "diff",
7395
7615
  "--cached",
7396
7616
  "--name-only",
@@ -7398,10 +7618,10 @@ function resolveChangedScope(cwd, request) {
7398
7618
  "--relative",
7399
7619
  "--"
7400
7620
  ])) {
7401
- paths.add(path17);
7402
- stagedPaths.add(path17);
7621
+ paths.add(path18);
7622
+ stagedPaths.add(path18);
7403
7623
  }
7404
- for (const path17 of gitPaths(cwd, [
7624
+ for (const path18 of gitPaths(cwd, [
7405
7625
  "diff",
7406
7626
  "--cached",
7407
7627
  "--name-only",
@@ -7410,7 +7630,7 @@ function resolveChangedScope(cwd, request) {
7410
7630
  "--diff-filter=D",
7411
7631
  "--"
7412
7632
  ])) {
7413
- deletedPaths.add(path17);
7633
+ deletedPaths.add(path18);
7414
7634
  }
7415
7635
  descriptions.push("staged");
7416
7636
  }
@@ -7448,10 +7668,10 @@ var PYTHON_SUFFIXES = [".py", ".pyi", "/__init__.py", "/__init__.pyi"];
7448
7668
  var CASE_INSENSITIVE_FILESYSTEM = process.platform === "win32" || process.platform === "darwin";
7449
7669
  var TSCONFIG_CACHE = /* @__PURE__ */ new Map();
7450
7670
  function tsconfigPathsFor(cwd) {
7451
- const configPath = path16.join(cwd, "tsconfig.json");
7671
+ const configPath = path17.join(cwd, "tsconfig.json");
7452
7672
  let stats;
7453
7673
  try {
7454
- stats = fs15.statSync(configPath);
7674
+ stats = fs16.statSync(configPath);
7455
7675
  } catch (err) {
7456
7676
  if (err.code === "ENOENT") return null;
7457
7677
  return null;
@@ -7485,8 +7705,8 @@ function tsconfigPathsFor(cwd) {
7485
7705
  return value;
7486
7706
  }
7487
7707
  function repositoryRelative(cwd, target) {
7488
- const relative11 = path16.relative(cwd, target).replace(/\\/g, "/");
7489
- return relative11.length === 0 || !relative11.startsWith("..") && !path16.isAbsolute(relative11) ? relative11 : null;
7708
+ const relative11 = path17.relative(cwd, target).replace(/\\/g, "/");
7709
+ return relative11.length === 0 || !relative11.startsWith("..") && !path17.isAbsolute(relative11) ? relative11 : null;
7490
7710
  }
7491
7711
  function rememberFirst(map, key, value) {
7492
7712
  if (!map.has(key)) map.set(key, value);
@@ -7501,15 +7721,15 @@ function buildImportResolver(files, options = {}) {
7501
7721
  if (CASE_INSENSITIVE_FILESYSTEM) {
7502
7722
  rememberFirst(byPathFolded, relativePath.toLowerCase(), relativePath);
7503
7723
  }
7504
- const extension = path16.posix.extname(relativePath);
7724
+ const extension = path17.posix.extname(relativePath);
7505
7725
  if (!SOURCE_EXTENSIONS.has(extension)) return;
7506
7726
  const stem = relativePath.slice(0, -extension.length);
7507
7727
  rememberFirst(byStem, stem, relativePath);
7508
7728
  if (CASE_INSENSITIVE_FILESYSTEM) {
7509
7729
  rememberFirst(byStemFolded, stem.toLowerCase(), relativePath);
7510
7730
  }
7511
- if (path16.posix.basename(stem) === "index") {
7512
- const directory = path16.posix.dirname(stem);
7731
+ if (path17.posix.basename(stem) === "index") {
7732
+ const directory = path17.posix.dirname(stem);
7513
7733
  rememberFirst(byStem, directory, relativePath);
7514
7734
  if (CASE_INSENSITIVE_FILESYSTEM) {
7515
7735
  rememberFirst(byStemFolded, directory.toLowerCase(), relativePath);
@@ -7525,7 +7745,7 @@ function buildImportResolver(files, options = {}) {
7525
7745
  return { byPath, byPathFolded, byStem, byStemFolded, tsconfig: options.tsconfig ?? null };
7526
7746
  }
7527
7747
  function resolveSpecifier(fromFile, specifier, resolver) {
7528
- const extension = path16.posix.extname(fromFile).toLowerCase();
7748
+ const extension = path17.posix.extname(fromFile).toLowerCase();
7529
7749
  const exact = (key) => resolver.byPath.get(key) ?? (CASE_INSENSITIVE_FILESYSTEM ? resolver.byPathFolded.get(key.toLowerCase()) : void 0) ?? null;
7530
7750
  const firstOf = (candidates) => {
7531
7751
  for (const candidate of candidates) {
@@ -7548,34 +7768,34 @@ function resolveSpecifier(fromFile, specifier, resolver) {
7548
7768
  if (PYTHON_EXTENSIONS.has(extension) && specifier.startsWith(".")) {
7549
7769
  const dots = /^\.+/.exec(specifier)?.[0].length ?? 0;
7550
7770
  const rest = specifier.slice(dots).replace(/\./g, "/");
7551
- let base = path16.posix.dirname(fromFile);
7552
- for (let up = 1; up < dots; up += 1) base = path16.posix.dirname(base);
7553
- const joined2 = rest ? path16.posix.normalize(path16.posix.join(base, rest)) : base;
7771
+ let base = path17.posix.dirname(fromFile);
7772
+ for (let up = 1; up < dots; up += 1) base = path17.posix.dirname(base);
7773
+ const joined2 = rest ? path17.posix.normalize(path17.posix.join(base, rest)) : base;
7554
7774
  return firstOf([joined2, ...PYTHON_SUFFIXES.map((suffix) => `${joined2}${suffix}`)]);
7555
7775
  }
7556
7776
  if (RUBY_EXTENSIONS.has(extension) && specifier.startsWith("./")) {
7557
- const joined2 = path16.posix.normalize(
7558
- path16.posix.join(path16.posix.dirname(fromFile), specifier)
7777
+ const joined2 = path17.posix.normalize(
7778
+ path17.posix.join(path17.posix.dirname(fromFile), specifier)
7559
7779
  );
7560
7780
  return firstOf([`${joined2}.rb`, joined2]);
7561
7781
  }
7562
7782
  if (C_EXTENSIONS.has(extension) && specifier.startsWith("./")) {
7563
- const joined2 = path16.posix.normalize(
7564
- path16.posix.join(path16.posix.dirname(fromFile), specifier)
7783
+ const joined2 = path17.posix.normalize(
7784
+ path17.posix.join(path17.posix.dirname(fromFile), specifier)
7565
7785
  );
7566
7786
  return exact(joined2);
7567
7787
  }
7568
7788
  if (extension === ".dart" && !specifier.includes(":")) {
7569
- const joined2 = path16.posix.normalize(
7570
- path16.posix.join(path16.posix.dirname(fromFile), specifier)
7789
+ const joined2 = path17.posix.normalize(
7790
+ path17.posix.join(path17.posix.dirname(fromFile), specifier)
7571
7791
  );
7572
7792
  return firstOf([joined2, `${joined2}.dart`]);
7573
7793
  }
7574
7794
  if (!RELATIVE_SPECIFIER.test(specifier)) {
7575
7795
  return resolveTsconfigSpecifier(specifier, resolver, lookupPath);
7576
7796
  }
7577
- const joined = path16.posix.normalize(
7578
- path16.posix.join(path16.posix.dirname(fromFile), specifier)
7797
+ const joined = path17.posix.normalize(
7798
+ path17.posix.join(path17.posix.dirname(fromFile), specifier)
7579
7799
  );
7580
7800
  return lookupPath(joined);
7581
7801
  }
@@ -7599,13 +7819,13 @@ function resolveTsconfigSpecifier(specifier, resolver, lookupPath) {
7599
7819
  if (captured === null) continue;
7600
7820
  for (const target of rule.targets) {
7601
7821
  const substituted = target.split("*").join(captured);
7602
- const base = config.baseUrl === null ? substituted : path16.posix.join(config.baseUrl, substituted);
7603
- const hit = lookupPath(path16.posix.normalize(base));
7822
+ const base = config.baseUrl === null ? substituted : path17.posix.join(config.baseUrl, substituted);
7823
+ const hit = lookupPath(path17.posix.normalize(base));
7604
7824
  if (hit) return hit;
7605
7825
  }
7606
7826
  }
7607
7827
  if (config.baseUrl !== null) {
7608
- return lookupPath(path16.posix.normalize(path16.posix.join(config.baseUrl, specifier)));
7828
+ return lookupPath(path17.posix.normalize(path17.posix.join(config.baseUrl, specifier)));
7609
7829
  }
7610
7830
  return null;
7611
7831
  }
@@ -7616,6 +7836,58 @@ function importsChangedFile(importerPath, imports, changedPaths, resolver) {
7616
7836
  }
7617
7837
  return false;
7618
7838
  }
7839
+ var SUMMARY_LIMIT = 400;
7840
+ var MAX_RELEASES = 2;
7841
+ function readProjectOverview(cwd) {
7842
+ return {
7843
+ ...readDescription(cwd),
7844
+ ...readSummary(cwd),
7845
+ releases: readReleases(cwd)
7846
+ };
7847
+ }
7848
+ function readText(file) {
7849
+ try {
7850
+ return fs16.readFileSync(file, "utf8");
7851
+ } catch {
7852
+ return null;
7853
+ }
7854
+ }
7855
+ function readDescription(cwd) {
7856
+ const raw = readText(path17.join(cwd, "package.json"));
7857
+ if (raw === null) return {};
7858
+ try {
7859
+ const parsed = JSON.parse(stripJsonComments(raw));
7860
+ return typeof parsed.description === "string" && parsed.description.trim().length > 0 ? { description: parsed.description.trim() } : {};
7861
+ } catch {
7862
+ return {};
7863
+ }
7864
+ }
7865
+ function readSummary(cwd) {
7866
+ const raw = readText(path17.join(cwd, "README.md"));
7867
+ if (raw === null) return {};
7868
+ const lines = raw.split(/\r?\n/);
7869
+ const paragraph = [];
7870
+ for (const line of lines) {
7871
+ const trimmed = line.trim();
7872
+ if (paragraph.length === 0) {
7873
+ if (trimmed.length === 0) continue;
7874
+ if (/^#/.test(trimmed) || /^!\[/.test(trimmed) || /^</.test(trimmed) || /^[-*|]/.test(trimmed)) continue;
7875
+ if (/^\[[^\]]+\]:/.test(trimmed)) continue;
7876
+ } else if (trimmed.length === 0 || /^#/.test(trimmed)) {
7877
+ break;
7878
+ }
7879
+ paragraph.push(trimmed);
7880
+ }
7881
+ const summary = paragraph.join(" ").replace(/\s+/g, " ").trim();
7882
+ if (summary.length === 0) return {};
7883
+ return { summary: summary.length > SUMMARY_LIMIT ? summary.slice(0, SUMMARY_LIMIT - 1) + "\u2026" : summary };
7884
+ }
7885
+ function readReleases(cwd) {
7886
+ const raw = readText(path17.join(cwd, "CHANGELOG.md"));
7887
+ if (raw === null) return [];
7888
+ const headings = raw.split(/\r?\n/).filter((line) => /^##\s+\S/.test(line)).map((line) => line.replace(/^##\s+/, "").trim());
7889
+ return headings.slice(0, MAX_RELEASES);
7890
+ }
7619
7891
  var LANGUAGE_BY_EXTENSION = {
7620
7892
  ".ts": "typescript",
7621
7893
  ".mts": "typescript",
@@ -7673,10 +7945,10 @@ var LANGUAGE_BY_BASENAME = {
7673
7945
  };
7674
7946
  function detectLanguage(filePath) {
7675
7947
  const normalized = filePath.replace(/\\/g, "/");
7676
- const base = path16.posix.basename(normalized);
7948
+ const base = path17.posix.basename(normalized);
7677
7949
  if (LANGUAGE_BY_BASENAME[base]) return LANGUAGE_BY_BASENAME[base];
7678
7950
  if (base === ".env" || base.startsWith(".env.")) return "dotenv";
7679
- const ext = path16.posix.extname(base).toLowerCase();
7951
+ const ext = path17.posix.extname(base).toLowerCase();
7680
7952
  return LANGUAGE_BY_EXTENSION[ext] ?? "text";
7681
7953
  }
7682
7954
  function maskedPath(value, secretRules) {
@@ -7684,33 +7956,33 @@ function maskedPath(value, secretRules) {
7684
7956
  }
7685
7957
  function confineToDirectory(directory, filename) {
7686
7958
  if (filename.includes("\0")) return null;
7687
- if (path16.isAbsolute(filename)) return null;
7688
- const base = path16.resolve(directory);
7689
- const resolved = path16.resolve(base, filename);
7959
+ if (path17.isAbsolute(filename)) return null;
7960
+ const base = path17.resolve(directory);
7961
+ const resolved = path17.resolve(base, filename);
7690
7962
  const caseInsensitive = process.platform === "win32" || process.platform === "darwin";
7691
- const prefix = caseInsensitive ? `${base}${path16.sep}`.toLowerCase() : `${base}${path16.sep}`;
7963
+ const prefix = caseInsensitive ? `${base}${path17.sep}`.toLowerCase() : `${base}${path17.sep}`;
7692
7964
  const candidate = caseInsensitive ? resolved.toLowerCase() : resolved;
7693
7965
  return candidate.startsWith(prefix) ? resolved : null;
7694
7966
  }
7695
7967
  function findStagingDirectory(config) {
7696
- const tmpDir = path16.resolve(config.cwd, config.tmpDir);
7968
+ const tmpDir = path17.resolve(config.cwd, config.tmpDir);
7697
7969
  let entries;
7698
7970
  try {
7699
- entries = fs15.readdirSync(tmpDir);
7971
+ entries = fs16.readdirSync(tmpDir);
7700
7972
  } catch {
7701
7973
  return null;
7702
7974
  }
7703
7975
  const runs = entries.filter((name) => name.startsWith("run-")).sort();
7704
7976
  const newest = runs[runs.length - 1];
7705
- return newest ? path16.join(tmpDir, newest) : null;
7977
+ return newest ? path17.join(tmpDir, newest) : null;
7706
7978
  }
7707
7979
  function describeMissingManifest(config, manifestPath) {
7708
- const outDir = path16.resolve(config.cwd, config.outDir);
7709
- const markerPath = path16.join(outDir, ".codebase-snapshot");
7980
+ const outDir = path17.resolve(config.cwd, config.outDir);
7981
+ const markerPath = path17.join(outDir, ".codebase-snapshot");
7710
7982
  let marker2 = null;
7711
7983
  try {
7712
- if (fs15.existsSync(markerPath)) {
7713
- const parsed = JSON.parse(fs15.readFileSync(markerPath, "utf8"));
7984
+ if (fs16.existsSync(markerPath)) {
7985
+ const parsed = JSON.parse(fs16.readFileSync(markerPath, "utf8"));
7714
7986
  if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
7715
7987
  marker2 = parsed;
7716
7988
  }
@@ -7745,13 +8017,13 @@ function sha256Hex(buffer) {
7745
8017
  return crypto2.createHash("sha256").update(buffer).digest("hex");
7746
8018
  }
7747
8019
  function wouldNowBeIncluded(cwd, relativePath) {
7748
- const absolutePath = path16.join(cwd, relativePath);
8020
+ const absolutePath = path17.join(cwd, relativePath);
7749
8021
  try {
7750
- const stats = fs15.statSync(absolutePath);
8022
+ const stats = fs16.statSync(absolutePath);
7751
8023
  if (!stats.isFile()) return false;
7752
8024
  if (isBinaryExtension(absolutePath)) return false;
7753
8025
  if (stats.size > BINARY_SCAN_BYTES && isBinaryFile(absolutePath)) return false;
7754
- return !decodeText(fs15.readFileSync(absolutePath)).binary;
8026
+ return !decodeText(fs16.readFileSync(absolutePath)).binary;
7755
8027
  } catch {
7756
8028
  return false;
7757
8029
  }
@@ -7763,7 +8035,7 @@ var TRUNCATION_REASONS = /* @__PURE__ */ new Set([
7763
8035
  ]);
7764
8036
  function isConfinedRelative(value) {
7765
8037
  if (value.length === 0 || value.includes("\0") || value.includes("\\")) return false;
7766
- if (path16.isAbsolute(value)) return false;
8038
+ if (path17.isAbsolute(value)) return false;
7767
8039
  return !value.split("/").includes("..");
7768
8040
  }
7769
8041
  function describeManifestShapeProblem(value) {
@@ -7931,7 +8203,7 @@ function describeManifestShapeProblem(value) {
7931
8203
  if (typeof filename !== "string" || filename.trim() === "") {
7932
8204
  return 'a "parts" entry has no "filename"';
7933
8205
  }
7934
- if (filename.includes("/") || filename.includes("\\") || filename.includes("\0") || filename === "." || filename === ".." || path16.isAbsolute(filename)) {
8206
+ if (filename.includes("/") || filename.includes("\\") || filename.includes("\0") || filename === "." || filename === ".." || path17.isAbsolute(filename)) {
7935
8207
  return 'a "parts" entry "filename" must be a bare filename inside parts/';
7936
8208
  }
7937
8209
  if (currentSchema) {
@@ -7957,8 +8229,8 @@ function describeManifestShapeProblem(value) {
7957
8229
  function validateSnapshot(configInput) {
7958
8230
  assertUsableConfigInput(configInput);
7959
8231
  const config = isResolvedConfig(configInput) ? normalizeResolvedConfig(configInput) : resolveConfig(configInput);
7960
- const manifestPath = path16.resolve(config.cwd, config.outDir, "manifest.json");
7961
- if (!fs15.existsSync(manifestPath)) {
8232
+ const manifestPath = path17.resolve(config.cwd, config.outDir, "manifest.json");
8233
+ if (!fs16.existsSync(manifestPath)) {
7962
8234
  return {
7963
8235
  valid: false,
7964
8236
  manifestPresent: false,
@@ -7969,7 +8241,7 @@ function validateSnapshot(configInput) {
7969
8241
  }
7970
8242
  let manifest;
7971
8243
  try {
7972
- manifest = JSON.parse(fs15.readFileSync(manifestPath, "utf8"));
8244
+ manifest = JSON.parse(fs16.readFileSync(manifestPath, "utf8"));
7973
8245
  } catch (err) {
7974
8246
  return {
7975
8247
  valid: false,
@@ -7991,7 +8263,7 @@ function validateSnapshot(configInput) {
7991
8263
  }
7992
8264
  const drift = emptyDrift();
7993
8265
  const warnings = [];
7994
- const snapshotDir = path16.resolve(config.cwd, config.outDir);
8266
+ const snapshotDir = path17.resolve(config.cwd, config.outDir);
7995
8267
  const unreadableSkips = manifest.skipped.filter(
7996
8268
  (entry) => entry.reason === "missing" || entry.reason === "read-error"
7997
8269
  );
@@ -8094,7 +8366,7 @@ function validateSnapshot(configInput) {
8094
8366
  );
8095
8367
  return importsChangedFile(
8096
8368
  diskFile,
8097
- importsOfFile(diskFile, path16.join(config.cwd, diskFile)),
8369
+ importsOfFile(diskFile, path17.join(config.cwd, diskFile)),
8098
8370
  unchangedScope,
8099
8371
  dependentResolver
8100
8372
  );
@@ -8112,7 +8384,7 @@ function validateSnapshot(configInput) {
8112
8384
  // own output directory as a set of files missing from the snapshot, so a correct
8113
8385
  // snapshot was reported as drifting.
8114
8386
  toolOwnedPaths: [config.outDir, config.tmpDir].map(
8115
- (directory) => path16.relative(config.cwd, path16.resolve(config.cwd, directory)).replace(/\\/g, "/")
8387
+ (directory) => path17.relative(config.cwd, path17.resolve(config.cwd, directory)).replace(/\\/g, "/")
8116
8388
  ).filter((relative11) => relative11.length > 0 && !relative11.startsWith(".."))
8117
8389
  });
8118
8390
  for (const diskFile of collection.files) {
@@ -8138,7 +8410,7 @@ function validateSnapshot(configInput) {
8138
8410
  }
8139
8411
  let diskHash;
8140
8412
  try {
8141
- diskHash = sha256Hex(fs15.readFileSync(path16.join(config.cwd, diskFile)));
8413
+ diskHash = sha256Hex(fs16.readFileSync(path17.join(config.cwd, diskFile)));
8142
8414
  } catch (err) {
8143
8415
  if (err.code === "ENOENT") {
8144
8416
  drift.missingOnDisk.push(diskFile);
@@ -8162,7 +8434,7 @@ function validateSnapshot(configInput) {
8162
8434
  }
8163
8435
  let statFailure = null;
8164
8436
  try {
8165
- fs15.statSync(confined);
8437
+ fs16.statSync(confined);
8166
8438
  } catch (err) {
8167
8439
  statFailure = err;
8168
8440
  }
@@ -8182,7 +8454,7 @@ function validateSnapshot(configInput) {
8182
8454
  ...Object.values(config.budgets.byLayer)
8183
8455
  );
8184
8456
  const partNames = /* @__PURE__ */ new Set();
8185
- const partsDir = path16.join(snapshotDir, "parts");
8457
+ const partsDir = path17.join(snapshotDir, "parts");
8186
8458
  for (const part of manifest.parts) {
8187
8459
  if (!part || typeof part.filename !== "string") continue;
8188
8460
  partNames.add(part.filename);
@@ -8197,7 +8469,7 @@ function validateSnapshot(configInput) {
8197
8469
  }
8198
8470
  let buffer;
8199
8471
  try {
8200
- buffer = fs15.readFileSync(partPath);
8472
+ buffer = fs16.readFileSync(partPath);
8201
8473
  } catch {
8202
8474
  drift.partIssues.push({ part: part.filename, issue: "missing from snapshot/parts" });
8203
8475
  continue;
@@ -8553,11 +8825,11 @@ function validateSnapshot(configInput) {
8553
8825
  ];
8554
8826
  for (const [key, artifact] of declaredArtifacts) {
8555
8827
  if (!artifact) continue;
8556
- const artifactPath = path16.join(snapshotDir, ...key.split("/"));
8828
+ const artifactPath = path17.join(snapshotDir, ...key.split("/"));
8557
8829
  let buffer;
8558
8830
  try {
8559
- if (!fs15.statSync(artifactPath).isFile()) throw new Error("not a regular file");
8560
- buffer = fs15.readFileSync(artifactPath);
8831
+ if (!fs16.statSync(artifactPath).isFile()) throw new Error("not a regular file");
8832
+ buffer = fs16.readFileSync(artifactPath);
8561
8833
  } catch {
8562
8834
  drift.partIssues.push({ part: key, issue: "declared artifact is missing" });
8563
8835
  continue;
@@ -8570,9 +8842,9 @@ function validateSnapshot(configInput) {
8570
8842
  for (const match of buffer.toString("utf8").matchAll(/\]\(([^)\s]+)\)/g)) {
8571
8843
  const target = match[1].split("#")[0];
8572
8844
  if (target.length === 0 || /^[a-z][a-z0-9+.-]*:/i.test(target)) continue;
8573
- const resolved = path16.resolve(snapshotDir, "reports", target);
8574
- const relative11 = path16.relative(snapshotDir, resolved);
8575
- if (relative11.startsWith("..") || path16.isAbsolute(relative11) || !fs15.existsSync(resolved)) {
8845
+ const resolved = path17.resolve(snapshotDir, "reports", target);
8846
+ const relative11 = path17.relative(snapshotDir, resolved);
8847
+ if (relative11.startsWith("..") || path17.isAbsolute(relative11) || !fs16.existsSync(resolved)) {
8576
8848
  drift.partIssues.push({
8577
8849
  part: key,
8578
8850
  issue: `links to ${maskedPath(target, config.secretRules)}, which does not exist in the snapshot`
@@ -8585,7 +8857,7 @@ function validateSnapshot(configInput) {
8585
8857
  if (sarifArtifact) {
8586
8858
  const sarifKey = "reports/audit.sarif";
8587
8859
  try {
8588
- const buffer = fs15.readFileSync(path16.join(snapshotDir, "reports", "audit.sarif"));
8860
+ const buffer = fs16.readFileSync(path17.join(snapshotDir, "reports", "audit.sarif"));
8589
8861
  if (sha256Hex(buffer) !== sarifArtifact.sha256 || buffer.length !== sarifArtifact.byteSize) {
8590
8862
  drift.partIssues.push({ part: sarifKey, issue: "artifact does not match its recorded digest" });
8591
8863
  }
@@ -8703,17 +8975,17 @@ function isNewer(candidate, current) {
8703
8975
  }
8704
8976
  function cacheDirectory(env = process.env, platform = process.platform) {
8705
8977
  if (platform === "win32") {
8706
- const base2 = env.LOCALAPPDATA ?? path16.join(os.homedir(), "AppData", "Local");
8707
- return path16.join(base2, "codebase-snapshot");
8978
+ const base2 = env.LOCALAPPDATA ?? path17.join(os.homedir(), "AppData", "Local");
8979
+ return path17.join(base2, "codebase-snapshot");
8708
8980
  }
8709
8981
  if (platform === "darwin") {
8710
- return path16.join(os.homedir(), "Library", "Caches", "codebase-snapshot");
8982
+ return path17.join(os.homedir(), "Library", "Caches", "codebase-snapshot");
8711
8983
  }
8712
- const base = env.XDG_CACHE_HOME ?? path16.join(os.homedir(), ".cache");
8713
- return path16.join(base, "codebase-snapshot");
8984
+ const base = env.XDG_CACHE_HOME ?? path17.join(os.homedir(), ".cache");
8985
+ return path17.join(base, "codebase-snapshot");
8714
8986
  }
8715
8987
  function cacheFilePath(env = process.env) {
8716
- return path16.join(cacheDirectory(env), "update-check.json");
8988
+ return path17.join(cacheDirectory(env), "update-check.json");
8717
8989
  }
8718
8990
  function shouldCheck(argv, env) {
8719
8991
  const disabled = ["1", "true", "yes"].includes(
@@ -8743,7 +9015,7 @@ function shouldCheck(argv, env) {
8743
9015
  function readCache(file) {
8744
9016
  let raw;
8745
9017
  try {
8746
- raw = fs15.readFileSync(file, "utf8");
9018
+ raw = fs16.readFileSync(file, "utf8");
8747
9019
  } catch {
8748
9020
  return null;
8749
9021
  }
@@ -8760,8 +9032,8 @@ function readCache(file) {
8760
9032
  }
8761
9033
  function writeCache(file, entry) {
8762
9034
  try {
8763
- fs15.mkdirSync(path16.dirname(file), { recursive: true });
8764
- fs15.writeFileSync(file, `${JSON.stringify(entry)}
9035
+ fs16.mkdirSync(path17.dirname(file), { recursive: true });
9036
+ fs16.writeFileSync(file, `${JSON.stringify(entry)}
8765
9037
  `, "utf8");
8766
9038
  } catch {
8767
9039
  }
@@ -8860,13 +9132,13 @@ function describeMatcher(matcher) {
8860
9132
  return String(matcher);
8861
9133
  }
8862
9134
  function normalizeTarget(cwd, target) {
8863
- const resolvedCwd = path16.resolve(cwd);
8864
- const absolute = path16.resolve(resolvedCwd, target);
8865
- const relative11 = path16.relative(resolvedCwd, absolute);
8866
- if (relative11 === "" || relative11 === ".." || relative11.startsWith(`..${path16.sep}`) || path16.isAbsolute(relative11)) {
9135
+ const resolvedCwd = path17.resolve(cwd);
9136
+ const absolute = path17.resolve(resolvedCwd, target);
9137
+ const relative11 = path17.relative(resolvedCwd, absolute);
9138
+ if (relative11 === "" || relative11 === ".." || relative11.startsWith(`..${path17.sep}`) || path17.isAbsolute(relative11)) {
8867
9139
  return { relative: target.replace(/\\/g, "/"), outsideRoot: true };
8868
9140
  }
8869
- return { relative: relative11.split(path16.sep).join("/"), outsideRoot: false };
9141
+ return { relative: relative11.split(path17.sep).join("/"), outsideRoot: false };
8870
9142
  }
8871
9143
  function findRuleMatch(rules, relativePath) {
8872
9144
  return rules.find(
@@ -8885,9 +9157,9 @@ function findRecordedAncestor(skipped, relative11, maskedPath2) {
8885
9157
  return nearest;
8886
9158
  }
8887
9159
  function readManifest2(config) {
8888
- const manifestPath = path16.resolve(config.cwd, config.outDir, "manifest.json");
9160
+ const manifestPath = path17.resolve(config.cwd, config.outDir, "manifest.json");
8889
9161
  try {
8890
- return JSON.parse(fs15.readFileSync(manifestPath, "utf8"));
9162
+ return JSON.parse(fs16.readFileSync(manifestPath, "utf8"));
8891
9163
  } catch {
8892
9164
  return null;
8893
9165
  }
@@ -8905,10 +9177,10 @@ function explainPath(config, target) {
8905
9177
  detail: "path resolves outside the configured repository root and was not inspected"
8906
9178
  };
8907
9179
  }
8908
- const absolute = path16.join(config.cwd, relative11);
9180
+ const absolute = path17.join(config.cwd, relative11);
8909
9181
  const result = {
8910
9182
  path: maskedPath2,
8911
- exists: fs15.existsSync(absolute),
9183
+ exists: fs16.existsSync(absolute),
8912
9184
  included: false
8913
9185
  };
8914
9186
  const collection = collectFiles(config.cwd, {
@@ -8922,7 +9194,7 @@ function explainPath(config, target) {
8922
9194
  // Same exclusion `generate` applies, so `explain` never says "not-discovered" about a file
8923
9195
  // that is only missing because the walker dropped the tool's own output directory.
8924
9196
  toolOwnedPaths: [config.outDir, config.tmpDir].map(
8925
- (directory) => path16.relative(config.cwd, path16.resolve(config.cwd, directory)).replace(/\\/g, "/")
9197
+ (directory) => path17.relative(config.cwd, path17.resolve(config.cwd, directory)).replace(/\\/g, "/")
8926
9198
  ).filter((relative12) => relative12.length > 0 && !relative12.startsWith(".."))
8927
9199
  });
8928
9200
  if (!collection.files.includes(relative11)) {
@@ -8987,7 +9259,7 @@ function explainPath(config, target) {
8987
9259
  }
8988
9260
  let sizeOnDisk = null;
8989
9261
  try {
8990
- sizeOnDisk = fs15.statSync(absolute).size;
9262
+ sizeOnDisk = fs16.statSync(absolute).size;
8991
9263
  } catch {
8992
9264
  sizeOnDisk = null;
8993
9265
  }
@@ -8997,10 +9269,10 @@ function explainPath(config, target) {
8997
9269
  result.detail = "binary content; generate skips it and records `binary` in manifest.skipped[]";
8998
9270
  return result;
8999
9271
  }
9000
- if (fs15.existsSync(absolute) && fs15.statSync(absolute).isFile()) {
9272
+ if (fs16.existsSync(absolute) && fs16.statSync(absolute).isFile()) {
9001
9273
  let buffer;
9002
9274
  try {
9003
- buffer = fs15.readFileSync(absolute);
9275
+ buffer = fs16.readFileSync(absolute);
9004
9276
  } catch (err) {
9005
9277
  result.included = false;
9006
9278
  result.reason = "read-error";
@@ -9290,14 +9562,14 @@ function compareManifests(before, after, secretRules) {
9290
9562
  function loadManifest(target) {
9291
9563
  let isDirectory;
9292
9564
  try {
9293
- isDirectory = fs15.statSync(target).isDirectory();
9565
+ isDirectory = fs16.statSync(target).isDirectory();
9294
9566
  } catch {
9295
9567
  throw new Error(`No snapshot found at ${target}: the path does not exist.`);
9296
9568
  }
9297
- const manifestPath = isDirectory ? path16.join(target, "manifest.json") : target;
9569
+ const manifestPath = isDirectory ? path17.join(target, "manifest.json") : target;
9298
9570
  let raw;
9299
9571
  try {
9300
- raw = fs15.readFileSync(manifestPath, "utf8");
9572
+ raw = fs16.readFileSync(manifestPath, "utf8");
9301
9573
  } catch {
9302
9574
  throw new Error(`Could not read a manifest at ${manifestPath}.`);
9303
9575
  }
@@ -9399,15 +9671,15 @@ function canonicalIgnorePattern(line) {
9399
9671
  function appendGitignoreEntries(cwd, entries) {
9400
9672
  const wanted = [...new Set(entries)].filter((entry) => entry.trim().length > 0);
9401
9673
  if (wanted.length === 0) return { added: [], note: null };
9402
- const ignorePath = path16.join(cwd, ".gitignore");
9674
+ const ignorePath = path17.join(cwd, ".gitignore");
9403
9675
  const manual = `Add ${wanted.map((entry) => `"${entry}"`).join(" and ")} to your .gitignore yourself.`;
9404
9676
  let decoded = { text: "", bom: Buffer.alloc(0), encoding: "utf8" };
9405
9677
  try {
9406
- if (fs15.existsSync(ignorePath)) {
9407
- if (fs15.statSync(ignorePath).isDirectory()) {
9678
+ if (fs16.existsSync(ignorePath)) {
9679
+ if (fs16.statSync(ignorePath).isDirectory()) {
9408
9680
  return { added: [], note: `${ignorePath} is a directory, so it was not updated. ${manual}` };
9409
9681
  }
9410
- const read = decodeGitignore(fs15.readFileSync(ignorePath));
9682
+ const read = decodeGitignore(fs16.readFileSync(ignorePath));
9411
9683
  if (read === null) {
9412
9684
  return {
9413
9685
  added: [],
@@ -9429,7 +9701,7 @@ function appendGitignoreEntries(cwd, entries) {
9429
9701
  const newline = existing.includes("\r\n") ? "\r\n" : "\n";
9430
9702
  const prefix = existing.length === 0 || existing.endsWith("\n") ? "" : newline;
9431
9703
  try {
9432
- fs15.writeFileSync(
9704
+ fs16.writeFileSync(
9433
9705
  ignorePath,
9434
9706
  encodeGitignore(decoded, `${existing}${prefix}${added.join(newline)}${newline}`)
9435
9707
  );
@@ -9439,7 +9711,7 @@ function appendGitignoreEntries(cwd, entries) {
9439
9711
  return { added, note: null };
9440
9712
  }
9441
9713
  function gitignorePath(cwd, filePath) {
9442
- return path16.relative(cwd, filePath).split(path16.sep).join("/");
9714
+ return path17.relative(cwd, filePath).split(path17.sep).join("/");
9443
9715
  }
9444
9716
 
9445
9717
  // src/wizard/config-template.ts
@@ -9595,6 +9867,10 @@ function renderConfig(answers) {
9595
9867
  // Experimental: grow the per-part budget until the snapshot fits this many parts, instead of
9596
9868
  // adding a part as the code grows. The plan in PROMPT.md becomes a fixed-length attachment list.
9597
9869
  // maxParts: 10,
9870
+ // The owner-written half of PROMPT.md: Stakes, The system, What came before, The bar, Calibration.
9871
+ // brief: "docs/brief.md",
9872
+ // Which job the brief is written for: audit, review or explain.
9873
+ // promptTask: "audit",
9598
9874
  // afterGenerate: (manifest) => { /* write your own artifact */ }
9599
9875
  hooks: {},
9600
9876
  };
@@ -9989,7 +10265,7 @@ function parsePackageJson(raw) {
9989
10265
  }
9990
10266
  function readPackageJson(cwd) {
9991
10267
  try {
9992
- return parsePackageJson(fs15.readFileSync(path16.join(cwd, "package.json"), "utf8"));
10268
+ return parsePackageJson(fs16.readFileSync(path17.join(cwd, "package.json"), "utf8"));
9993
10269
  } catch {
9994
10270
  return null;
9995
10271
  }
@@ -10026,7 +10302,7 @@ function artifactAnswers(options) {
10026
10302
  }
10027
10303
  function topLevelDirs(cwd) {
10028
10304
  try {
10029
- return fs15.readdirSync(cwd, { withFileTypes: true }).filter((entry) => entry.isDirectory() && !entry.name.startsWith(".") && entry.name !== "node_modules").map((entry) => entry.name).sort();
10305
+ return fs16.readdirSync(cwd, { withFileTypes: true }).filter((entry) => entry.isDirectory() && !entry.name.startsWith(".") && entry.name !== "node_modules").map((entry) => entry.name).sort();
10030
10306
  } catch {
10031
10307
  return [];
10032
10308
  }
@@ -10041,7 +10317,7 @@ function writeFileOrExplain(target, content) {
10041
10317
  try {
10042
10318
  let stats = null;
10043
10319
  try {
10044
- stats = fs15.lstatSync(target);
10320
+ stats = fs16.lstatSync(target);
10045
10321
  } catch {
10046
10322
  stats = null;
10047
10323
  }
@@ -10056,12 +10332,12 @@ function writeFileOrExplain(target, content) {
10056
10332
  );
10057
10333
  }
10058
10334
  const temporary = `${target}.tmp-${process.pid}-${Date.now()}`;
10059
- fs15.writeFileSync(temporary, content, { encoding: "utf8", flag: "wx" });
10335
+ fs16.writeFileSync(temporary, content, { encoding: "utf8", flag: "wx" });
10060
10336
  try {
10061
- fs15.renameSync(temporary, target);
10337
+ fs16.renameSync(temporary, target);
10062
10338
  } catch (err) {
10063
10339
  try {
10064
- fs15.unlinkSync(temporary);
10340
+ fs16.unlinkSync(temporary);
10065
10341
  } catch {
10066
10342
  }
10067
10343
  throw err;
@@ -10109,19 +10385,19 @@ function serializePackageJson(raw, value) {
10109
10385
  return `${bom}${text2}${raw.endsWith("\n") ? crlf ? "\r\n" : "\n" : ""}`;
10110
10386
  }
10111
10387
  function updatePackageJson(cwd, notes) {
10112
- const packagePath = path16.join(cwd, "package.json");
10388
+ const packagePath = path17.join(cwd, "package.json");
10113
10389
  const unchanged = {
10114
10390
  scripts: [],
10115
10391
  dependency: { name: GENERATOR_NAME, range: null, added: false }
10116
10392
  };
10117
- if (!fs15.existsSync(packagePath)) {
10393
+ if (!fs16.existsSync(packagePath)) {
10118
10394
  notes.push("No package.json found, so npm scripts and the devDependency were not added.");
10119
10395
  return unchanged;
10120
10396
  }
10121
10397
  let raw;
10122
10398
  let parsed;
10123
10399
  try {
10124
- raw = fs15.readFileSync(packagePath, "utf8");
10400
+ raw = fs16.readFileSync(packagePath, "utf8");
10125
10401
  parsed = parsePackageJson(raw);
10126
10402
  } catch {
10127
10403
  notes.push("Could not parse package.json; npm scripts and the devDependency were not added.");
@@ -10196,8 +10472,8 @@ function gitignoreEntriesFor(cwd, outDir, tmpDir) {
10196
10472
  const entries = [];
10197
10473
  for (const directory of [outDir, tmpDir]) {
10198
10474
  if (directory === null) continue;
10199
- const relative11 = path16.relative(cwd, path16.resolve(cwd, directory)).replace(/\\/g, "/");
10200
- if (relative11 === "" || relative11 === "." || relative11.startsWith("..") || path16.isAbsolute(relative11)) {
10475
+ const relative11 = path17.relative(cwd, path17.resolve(cwd, directory)).replace(/\\/g, "/");
10476
+ if (relative11 === "" || relative11 === "." || relative11.startsWith("..") || path17.isAbsolute(relative11)) {
10201
10477
  continue;
10202
10478
  }
10203
10479
  entries.push(`/${relative11}/`);
@@ -10449,7 +10725,7 @@ async function runInit(options) {
10449
10725
  const configText = renderConfig(answers);
10450
10726
  const preferredName = chooseConfigFileName(options.cwd);
10451
10727
  const presentConfigs = CONFIG_CANDIDATES.filter(
10452
- (name) => fs15.existsSync(path16.join(options.cwd, name))
10728
+ (name) => fs16.existsSync(path17.join(options.cwd, name))
10453
10729
  );
10454
10730
  const present = presentConfigs[0] ?? null;
10455
10731
  if (presentConfigs.length > 1) {
@@ -10458,7 +10734,7 @@ async function runInit(options) {
10458
10734
  );
10459
10735
  }
10460
10736
  const configName = present !== null && options.force ? present : preferredName;
10461
- const configPath = path16.join(options.cwd, configName);
10737
+ const configPath = path17.join(options.cwd, configName);
10462
10738
  const reused = present !== null && options.force !== true && options.reuseConfig === true;
10463
10739
  if (reused) notes.push(`Kept the existing ${present} instead of writing a new one.`);
10464
10740
  if (options.dryRun) {
@@ -10492,7 +10768,7 @@ async function runInit(options) {
10492
10768
  '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.'
10493
10769
  );
10494
10770
  }
10495
- if (fs15.existsSync(configPath) && !options.force && !reused) {
10771
+ if (fs16.existsSync(configPath) && !options.force && !reused) {
10496
10772
  throw new Error(`${configName} already exists. Re-run with --force to replace it.`);
10497
10773
  }
10498
10774
  if (!reused) writeFileOrExplain(configPath, configText);
@@ -10518,9 +10794,9 @@ async function runInit(options) {
10518
10794
  };
10519
10795
  }
10520
10796
  function describeTarget(cwd) {
10521
- const relative11 = path16.relative(process.cwd(), cwd);
10797
+ const relative11 = path17.relative(process.cwd(), cwd);
10522
10798
  if (relative11 === "") return "this directory";
10523
- if (relative11.startsWith("..") || path16.isAbsolute(relative11)) return cwd;
10799
+ if (relative11.startsWith("..") || path17.isAbsolute(relative11)) return cwd;
10524
10800
  return relative11;
10525
10801
  }
10526
10802
  function firstRunMessage(reason, cwd) {
@@ -10544,7 +10820,7 @@ function planFirstRun(facts) {
10544
10820
  var NOT_CONTENT = /* @__PURE__ */ new Set([".git", ".hg", ".svn", ".bzr", ".DS_Store", "Thumbs.db"]);
10545
10821
  function isEffectivelyEmpty(cwd) {
10546
10822
  try {
10547
- return fs15.readdirSync(cwd).every((entry) => NOT_CONTENT.has(entry));
10823
+ return fs16.readdirSync(cwd).every((entry) => NOT_CONTENT.has(entry));
10548
10824
  } catch {
10549
10825
  return false;
10550
10826
  }
@@ -10552,7 +10828,7 @@ function isEffectivelyEmpty(cwd) {
10552
10828
  function hasPriorSnapshot(cwd, outDir) {
10553
10829
  let parsed;
10554
10830
  try {
10555
- parsed = JSON.parse(fs15.readFileSync(path16.join(cwd, outDir, ".codebase-snapshot"), "utf8"));
10831
+ parsed = JSON.parse(fs16.readFileSync(path17.join(cwd, outDir, ".codebase-snapshot"), "utf8"));
10556
10832
  } catch {
10557
10833
  return false;
10558
10834
  }
@@ -10600,36 +10876,36 @@ fi
10600
10876
  `;
10601
10877
  }
10602
10878
  function gitDirectory(cwd) {
10603
- const dotGit = path16.join(cwd, ".git");
10879
+ const dotGit = path17.join(cwd, ".git");
10604
10880
  let stats;
10605
10881
  try {
10606
- stats = fs15.statSync(dotGit);
10882
+ stats = fs16.statSync(dotGit);
10607
10883
  } catch {
10608
10884
  return null;
10609
10885
  }
10610
10886
  if (stats.isDirectory()) return dotGit;
10611
10887
  if (!stats.isFile()) return null;
10612
10888
  try {
10613
- const contents = fs15.readFileSync(dotGit, "utf8");
10889
+ const contents = fs16.readFileSync(dotGit, "utf8");
10614
10890
  const match = /^gitdir:\s*(.+)$/m.exec(contents);
10615
10891
  if (!match) return null;
10616
10892
  const target = match[1];
10617
- const resolved = path16.isAbsolute(target.trim()) ? target.trim() : path16.join(cwd, target.trim());
10618
- if (!fs15.statSync(resolved).isDirectory()) return null;
10619
- if (isInside2(path16.resolve(cwd), path16.resolve(resolved))) return resolved;
10620
- return isRegisteredWorktree(path16.resolve(resolved), cwd) ? resolved : null;
10893
+ const resolved = path17.isAbsolute(target.trim()) ? target.trim() : path17.join(cwd, target.trim());
10894
+ if (!fs16.statSync(resolved).isDirectory()) return null;
10895
+ if (isInside2(path17.resolve(cwd), path17.resolve(resolved))) return resolved;
10896
+ return isRegisteredWorktree(path17.resolve(resolved), cwd) ? resolved : null;
10621
10897
  } catch {
10622
10898
  return null;
10623
10899
  }
10624
10900
  }
10625
10901
  function isInside2(parent, child) {
10626
- const relative11 = path16.relative(parent, child);
10627
- return relative11 === "" || !relative11.startsWith("..") && !path16.isAbsolute(relative11);
10902
+ const relative11 = path17.relative(parent, child);
10903
+ return relative11 === "" || !relative11.startsWith("..") && !path17.isAbsolute(relative11);
10628
10904
  }
10629
10905
  function isRegisteredWorktree(gitDir, cwd) {
10630
10906
  try {
10631
- const back = fs15.readFileSync(path16.join(gitDir, "gitdir"), "utf8").trim();
10632
- return path16.resolve(gitDir, back) === path16.join(path16.resolve(cwd), ".git");
10907
+ const back = fs16.readFileSync(path17.join(gitDir, "gitdir"), "utf8").trim();
10908
+ return path17.resolve(gitDir, back) === path17.join(path17.resolve(cwd), ".git");
10633
10909
  } catch {
10634
10910
  return false;
10635
10911
  }
@@ -10650,10 +10926,10 @@ function gitOutput(cwd, args) {
10650
10926
  function configuredHooksDirectory(cwd) {
10651
10927
  const hooks = gitOutput(cwd, ["rev-parse", "--git-path", "hooks"]);
10652
10928
  if (hooks === null) return null;
10653
- const resolved = path16.resolve(cwd, hooks);
10929
+ const resolved = path17.resolve(cwd, hooks);
10654
10930
  const common = gitOutput(cwd, ["rev-parse", "--git-common-dir"]);
10655
- const commonDir = common === null ? null : path16.resolve(cwd, common);
10656
- if (isInside2(path16.resolve(cwd), resolved)) return { dir: resolved };
10931
+ const commonDir = common === null ? null : path17.resolve(cwd, common);
10932
+ if (isInside2(path17.resolve(cwd), resolved)) return { dir: resolved };
10657
10933
  if (commonDir !== null && isInside2(commonDir, resolved)) return { dir: resolved };
10658
10934
  return {
10659
10935
  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.`
@@ -10674,10 +10950,10 @@ function installPreCommitHook(cwd, outDir = "snapshot") {
10674
10950
  ]
10675
10951
  };
10676
10952
  }
10677
- const hooksDir = configured === null ? path16.join(gitDir, "hooks") : configured.dir;
10678
- const hookPath = path16.join(hooksDir, "pre-commit");
10953
+ const hooksDir = configured === null ? path17.join(gitDir, "hooks") : configured.dir;
10954
+ const hookPath = path17.join(hooksDir, "pre-commit");
10679
10955
  try {
10680
- fs15.mkdirSync(hooksDir, { recursive: true });
10956
+ fs16.mkdirSync(hooksDir, { recursive: true });
10681
10957
  } catch (err) {
10682
10958
  return {
10683
10959
  path: hookPath,
@@ -10687,7 +10963,7 @@ function installPreCommitHook(cwd, outDir = "snapshot") {
10687
10963
  }
10688
10964
  let existing = null;
10689
10965
  try {
10690
- existing = fs15.readFileSync(hookPath, "utf8");
10966
+ existing = fs16.readFileSync(hookPath, "utf8");
10691
10967
  } catch {
10692
10968
  existing = null;
10693
10969
  }
@@ -10702,8 +10978,8 @@ function installPreCommitHook(cwd, outDir = "snapshot") {
10702
10978
  };
10703
10979
  }
10704
10980
  try {
10705
- fs15.writeFileSync(hookPath, hookScript(outDir), "utf8");
10706
- fs15.chmodSync(hookPath, 493);
10981
+ fs16.writeFileSync(hookPath, hookScript(outDir), "utf8");
10982
+ fs16.chmodSync(hookPath, 493);
10707
10983
  } catch (err) {
10708
10984
  return {
10709
10985
  path: hookPath,
@@ -10720,7 +10996,7 @@ function installPreCommitHook(cwd, outDir = "snapshot") {
10720
10996
  };
10721
10997
  }
10722
10998
  function workerEntry(directory, isCjs) {
10723
- const entry = path16.join(directory, isCjs ? "index.cjs" : "index.js");
10999
+ const entry = path17.join(directory, isCjs ? "index.cjs" : "index.js");
10724
11000
  return { path: entry, url: pathToFileURL(entry).href };
10725
11001
  }
10726
11002
  var WORKER_SOURCE = `
@@ -10787,7 +11063,7 @@ function generateInWorker(cwd, cliOptions, options = {}) {
10787
11063
  resolve8(result);
10788
11064
  };
10789
11065
  const isCjs = typeof __dirname !== "undefined";
10790
- const directory = isCjs ? __dirname : path16.dirname(fileURLToPath(import.meta.url));
11066
+ const directory = isCjs ? __dirname : path17.dirname(fileURLToPath(import.meta.url));
10791
11067
  try {
10792
11068
  worker = new Worker(WORKER_SOURCE, {
10793
11069
  eval: true,
@@ -10822,23 +11098,23 @@ var SUMMARY_MAX_SOURCE_BYTES2 = SUMMARY_MAX_SOURCE_BYTES;
10822
11098
  var FILE_DERIVATIONS = /* @__PURE__ */ new Map();
10823
11099
  var FILE_DERIVATION_LIMIT_BYTES = 64 * 1024 * 1024;
10824
11100
  var fileDerivationBytes = 0;
10825
- function takeDerivation(path17, hash, settings) {
10826
- const cached = FILE_DERIVATIONS.get(path17);
11101
+ function takeDerivation(path18, hash, settings) {
11102
+ const cached = FILE_DERIVATIONS.get(path18);
10827
11103
  if (cached === void 0 || cached.hash !== hash || cached.settings !== settings) return void 0;
10828
- FILE_DERIVATIONS.delete(path17);
10829
- FILE_DERIVATIONS.set(path17, cached);
11104
+ FILE_DERIVATIONS.delete(path18);
11105
+ FILE_DERIVATIONS.set(path18, cached);
10830
11106
  return cached;
10831
11107
  }
10832
- function rememberDerivation(path17, hash, settings, derivation) {
11108
+ function rememberDerivation(path18, hash, settings, derivation) {
10833
11109
  const bodyBytes = derivation.finalContent === derivation.redacted ? derivation.redacted.length : derivation.redacted.length + derivation.finalContent.length;
10834
11110
  const bytes = bodyBytes * 2 + 512;
10835
11111
  if (bytes > FILE_DERIVATION_LIMIT_BYTES / 4) return;
10836
- const previous = FILE_DERIVATIONS.get(path17);
11112
+ const previous = FILE_DERIVATIONS.get(path18);
10837
11113
  if (previous !== void 0) {
10838
- FILE_DERIVATIONS.delete(path17);
11114
+ FILE_DERIVATIONS.delete(path18);
10839
11115
  fileDerivationBytes -= previous.bytes;
10840
11116
  } else {
10841
- FILE_DERIVATIONS.delete(path17);
11117
+ FILE_DERIVATIONS.delete(path18);
10842
11118
  }
10843
11119
  while (fileDerivationBytes + bytes > FILE_DERIVATION_LIMIT_BYTES) {
10844
11120
  const oldest = FILE_DERIVATIONS.keys().next();
@@ -10847,7 +11123,7 @@ function rememberDerivation(path17, hash, settings, derivation) {
10847
11123
  FILE_DERIVATIONS.delete(oldest.value);
10848
11124
  if (evicted !== void 0) fileDerivationBytes -= evicted.bytes;
10849
11125
  }
10850
- FILE_DERIVATIONS.set(path17, { ...derivation, hash, settings, bytes });
11126
+ FILE_DERIVATIONS.set(path18, { ...derivation, hash, settings, bytes });
10851
11127
  fileDerivationBytes += bytes;
10852
11128
  }
10853
11129
  function derivationSettings(config) {
@@ -11098,11 +11374,11 @@ function verifyInMemory(files, parts, unaccounted) {
11098
11374
  return errors;
11099
11375
  }
11100
11376
  function resolveSafeOutputDirs(config) {
11101
- const cwd = path16.resolve(config.cwd);
11102
- const outDir = path16.resolve(cwd, config.outDir);
11103
- const tmpDir = path16.resolve(cwd, config.tmpDir);
11104
- const root = path16.parse(cwd).root;
11105
- const contains = (parent, child) => child === parent || child.startsWith(`${parent}${path16.sep}`);
11377
+ const cwd = path17.resolve(config.cwd);
11378
+ const outDir = path17.resolve(cwd, config.outDir);
11379
+ const tmpDir = path17.resolve(cwd, config.tmpDir);
11380
+ const root = path17.parse(cwd).root;
11381
+ const contains = (parent, child) => child === parent || child.startsWith(`${parent}${path17.sep}`);
11106
11382
  const reject = (reason) => {
11107
11383
  throw new Error(
11108
11384
  `Refusing to generate: ${reason}. outDir=${outDir} tmpDir=${tmpDir} cwd=${cwd}`
@@ -11142,6 +11418,28 @@ function maskSummaryStrings(value, secretRules) {
11142
11418
  function maskPathText(value, secretRules) {
11143
11419
  return findSecretInPath(value, secretRules)?.masked ?? value;
11144
11420
  }
11421
+ function maskOwnerBrief(brief, secretRules) {
11422
+ if (brief === void 0) return void 0;
11423
+ const mask = (value) => maskPathText(value, secretRules);
11424
+ return {
11425
+ ...brief,
11426
+ ...brief.stakes === void 0 ? {} : { stakes: mask(brief.stakes) },
11427
+ ...brief.system === void 0 ? {} : { system: mask(brief.system) },
11428
+ ...brief.history === void 0 ? {} : { history: mask(brief.history) },
11429
+ ...brief.bar === void 0 ? {} : { bar: mask(brief.bar) },
11430
+ ...brief.calibration === void 0 ? {} : { calibration: mask(brief.calibration) },
11431
+ ...brief.preamble === void 0 ? {} : { preamble: mask(brief.preamble) },
11432
+ notes: brief.notes.map((note) => ({ heading: note.heading, body: mask(note.body) }))
11433
+ };
11434
+ }
11435
+ function maskOverview(overview, secretRules) {
11436
+ const mask = (value) => maskPathText(value, secretRules);
11437
+ return {
11438
+ ...overview.description === void 0 ? {} : { description: mask(overview.description) },
11439
+ ...overview.summary === void 0 ? {} : { summary: mask(overview.summary) },
11440
+ releases: overview.releases.map(mask)
11441
+ };
11442
+ }
11145
11443
  function maskSkipRecords(records, secretRules) {
11146
11444
  return maskSkipPaths(records, secretRules);
11147
11445
  }
@@ -11162,14 +11460,14 @@ function listEntries(dir) {
11162
11460
  const walk = (absolute, prefix) => {
11163
11461
  let children;
11164
11462
  try {
11165
- children = fs15.readdirSync(absolute, { withFileTypes: true });
11463
+ children = fs16.readdirSync(absolute, { withFileTypes: true });
11166
11464
  } catch {
11167
11465
  return;
11168
11466
  }
11169
11467
  for (const child of children) {
11170
11468
  const relative11 = prefix === "" ? child.name : `${prefix}/${child.name}`;
11171
11469
  entries.push(relative11);
11172
- if (child.isDirectory()) walk(path16.join(absolute, child.name), relative11);
11470
+ if (child.isDirectory()) walk(path17.join(absolute, child.name), relative11);
11173
11471
  }
11174
11472
  };
11175
11473
  walk(dir, "");
@@ -11181,10 +11479,10 @@ function markerInventory(dir, written) {
11181
11479
  for (const entry of entries) {
11182
11480
  if (entry === OWNERSHIP_MARKER) continue;
11183
11481
  if (isIgnorableEntry(entry)) continue;
11184
- const full = path16.join(dir, ...entry.split("/"));
11482
+ const full = path17.join(dir, ...entry.split("/"));
11185
11483
  let stats;
11186
11484
  try {
11187
- stats = fs15.lstatSync(full);
11485
+ stats = fs16.lstatSync(full);
11188
11486
  } catch {
11189
11487
  continue;
11190
11488
  }
@@ -11196,7 +11494,7 @@ function markerInventory(dir, written) {
11196
11494
  }
11197
11495
  let digest;
11198
11496
  try {
11199
- digest = sha256Hex2(fs15.readFileSync(full));
11497
+ digest = sha256Hex2(fs16.readFileSync(full));
11200
11498
  } catch {
11201
11499
  continue;
11202
11500
  }
@@ -11217,15 +11515,15 @@ function markerPayload(dir, state, id, createdAt, written) {
11217
11515
  entries,
11218
11516
  files
11219
11517
  };
11220
- const manifestPath = path16.join(dir, "manifest.json");
11221
- if (fs15.existsSync(manifestPath)) {
11222
- marker2.manifestSha256 = sha256Hex2(fs15.readFileSync(manifestPath));
11518
+ const manifestPath = path17.join(dir, "manifest.json");
11519
+ if (fs16.existsSync(manifestPath)) {
11520
+ marker2.manifestSha256 = sha256Hex2(fs16.readFileSync(manifestPath));
11223
11521
  }
11224
11522
  return marker2;
11225
11523
  }
11226
11524
  function writeOwnershipMarker(dir, marker2) {
11227
- fs15.writeFileSync(
11228
- path16.join(dir, OWNERSHIP_MARKER),
11525
+ fs16.writeFileSync(
11526
+ path17.join(dir, OWNERSHIP_MARKER),
11229
11527
  `${JSON.stringify(marker2, null, 2)}
11230
11528
  `,
11231
11529
  "utf8"
@@ -11237,13 +11535,13 @@ function markerBelongsTo(dir, id) {
11237
11535
  return evidence.marker.id === id;
11238
11536
  }
11239
11537
  function readOwnershipMarker(dir) {
11240
- const markerPath = path16.join(dir, OWNERSHIP_MARKER);
11241
- if (!fs15.existsSync(markerPath)) {
11538
+ const markerPath = path17.join(dir, OWNERSHIP_MARKER);
11539
+ if (!fs16.existsSync(markerPath)) {
11242
11540
  return { marker: null, problem: "it holds no .codebase-snapshot marker" };
11243
11541
  }
11244
11542
  let raw;
11245
11543
  try {
11246
- raw = fs15.readFileSync(markerPath, "utf8");
11544
+ raw = fs16.readFileSync(markerPath, "utf8");
11247
11545
  } catch {
11248
11546
  return { marker: null, problem: "its .codebase-snapshot marker could not be read" };
11249
11547
  }
@@ -11343,10 +11641,10 @@ function verifyMarkerInventory(dir, entries, files) {
11343
11641
  for (const entry of entries) {
11344
11642
  if (entry === OWNERSHIP_MARKER) continue;
11345
11643
  if (IGNORABLE_ENTRIES.has(entry.slice(entry.lastIndexOf("/") + 1))) continue;
11346
- const full = path16.join(dir, ...entry.split("/"));
11644
+ const full = path17.join(dir, ...entry.split("/"));
11347
11645
  let stats;
11348
11646
  try {
11349
- stats = fs15.lstatSync(full);
11647
+ stats = fs16.lstatSync(full);
11350
11648
  } catch {
11351
11649
  return `its .codebase-snapshot inventory lists ${entry}, which cannot be read`;
11352
11650
  }
@@ -11371,7 +11669,7 @@ function verifyMarkerInventory(dir, entries, files) {
11371
11669
  }
11372
11670
  let digest;
11373
11671
  try {
11374
- digest = sha256Hex2(fs15.readFileSync(full));
11672
+ digest = sha256Hex2(fs16.readFileSync(full));
11375
11673
  } catch {
11376
11674
  return `its .codebase-snapshot inventory cannot verify ${entry}: the file could not be read`;
11377
11675
  }
@@ -11392,12 +11690,12 @@ function assessSnapshotDirectory(dir) {
11392
11690
  marker: marker2
11393
11691
  };
11394
11692
  }
11395
- const manifestPath = path16.join(dir, "manifest.json");
11396
- const hasManifest = fs15.existsSync(manifestPath);
11693
+ const manifestPath = path17.join(dir, "manifest.json");
11694
+ const hasManifest = fs16.existsSync(manifestPath);
11397
11695
  if (hasManifest) {
11398
11696
  let raw;
11399
11697
  try {
11400
- raw = fs15.readFileSync(manifestPath, "utf8");
11698
+ raw = fs16.readFileSync(manifestPath, "utf8");
11401
11699
  } catch {
11402
11700
  return {
11403
11701
  owned: false,
@@ -11492,13 +11790,13 @@ function containsNoFiles(dir) {
11492
11790
  const current = pending.pop();
11493
11791
  let entries;
11494
11792
  try {
11495
- entries = fs15.readdirSync(current, { withFileTypes: true });
11793
+ entries = fs16.readdirSync(current, { withFileTypes: true });
11496
11794
  } catch {
11497
11795
  return false;
11498
11796
  }
11499
11797
  for (const entry of entries) {
11500
11798
  if (entry.isDirectory()) {
11501
- pending.push(path16.join(current, entry.name));
11799
+ pending.push(path17.join(current, entry.name));
11502
11800
  } else if (!IGNORABLE_ENTRIES.has(entry.name)) {
11503
11801
  return false;
11504
11802
  }
@@ -11507,13 +11805,13 @@ function containsNoFiles(dir) {
11507
11805
  return true;
11508
11806
  }
11509
11807
  function assertReplaceable(target, label, secretRules) {
11510
- if (!fs15.existsSync(target)) return;
11511
- if (!fs15.statSync(target).isDirectory()) {
11808
+ if (!fs16.existsSync(target)) return;
11809
+ if (!fs16.statSync(target).isDirectory()) {
11512
11810
  throw new Error(
11513
11811
  `Refusing to write into ${label} ${target}: it exists but is not a directory.`
11514
11812
  );
11515
11813
  }
11516
- const entries = fs15.readdirSync(target);
11814
+ const entries = fs16.readdirSync(target);
11517
11815
  if (entries.length === 0) return;
11518
11816
  if (entries.every((name) => IGNORABLE_ENTRIES.has(name))) return;
11519
11817
  if (containsNoFiles(target)) return;
@@ -11533,18 +11831,18 @@ function assertReplaceable(target, label, secretRules) {
11533
11831
  );
11534
11832
  }
11535
11833
  function assertStagingRootUsable(tmpDir, secretRules) {
11536
- if (!fs15.existsSync(tmpDir)) return;
11537
- if (!fs15.statSync(tmpDir).isDirectory()) {
11834
+ if (!fs16.existsSync(tmpDir)) return;
11835
+ if (!fs16.statSync(tmpDir).isDirectory()) {
11538
11836
  throw new Error(`Refusing to write into tmpDir ${tmpDir}: it exists but is not a directory.`);
11539
11837
  }
11540
- const entries = fs15.readdirSync(tmpDir);
11838
+ const entries = fs16.readdirSync(tmpDir);
11541
11839
  if (entries.length === 0) return;
11542
11840
  const foreign = entries.filter((name) => {
11543
- const full = path16.join(tmpDir, name);
11841
+ const full = path17.join(tmpDir, name);
11544
11842
  if (!name.startsWith(RUN_DIR_PREFIX)) return true;
11545
11843
  let stats;
11546
11844
  try {
11547
- stats = fs15.statSync(full);
11845
+ stats = fs16.statSync(full);
11548
11846
  } catch {
11549
11847
  return true;
11550
11848
  }
@@ -11552,7 +11850,7 @@ function assertStagingRootUsable(tmpDir, secretRules) {
11552
11850
  const { marker: marker2 } = readOwnershipMarker(full);
11553
11851
  if (marker2) return false;
11554
11852
  try {
11555
- return fs15.readdirSync(full).length > 0;
11853
+ return fs16.readdirSync(full).length > 0;
11556
11854
  } catch {
11557
11855
  return true;
11558
11856
  }
@@ -11567,13 +11865,13 @@ function assertStagingRootUsable(tmpDir, secretRules) {
11567
11865
  function cleanStaleRunDirs(tmpDir) {
11568
11866
  let entries;
11569
11867
  try {
11570
- entries = fs15.readdirSync(tmpDir);
11868
+ entries = fs16.readdirSync(tmpDir);
11571
11869
  } catch {
11572
11870
  return;
11573
11871
  }
11574
11872
  for (const name of entries) {
11575
11873
  if (!name.startsWith(RUN_DIR_PREFIX)) continue;
11576
- const full = path16.join(tmpDir, name);
11874
+ const full = path17.join(tmpDir, name);
11577
11875
  const { marker: marker2 } = readOwnershipMarker(full);
11578
11876
  if (marker2) {
11579
11877
  const created = Date.parse(marker2.createdAt);
@@ -11581,33 +11879,33 @@ function cleanStaleRunDirs(tmpDir) {
11581
11879
  const abandoned = typeof marker2.pid === "number" && !isProcessAlive(marker2.pid);
11582
11880
  if (aged || abandoned) {
11583
11881
  try {
11584
- fs15.rmSync(full, { recursive: true, force: true });
11882
+ fs16.rmSync(full, { recursive: true, force: true });
11585
11883
  } catch {
11586
11884
  }
11587
11885
  }
11588
11886
  continue;
11589
11887
  }
11590
11888
  try {
11591
- if (fs15.readdirSync(full).length === 0) fs15.rmSync(full, { recursive: true, force: true });
11889
+ if (fs16.readdirSync(full).length === 0) fs16.rmSync(full, { recursive: true, force: true });
11592
11890
  } catch {
11593
11891
  }
11594
11892
  }
11595
11893
  }
11596
11894
  function removeIfEmpty(dir) {
11597
11895
  try {
11598
- if (fs15.readdirSync(dir).length === 0) fs15.rmSync(dir, { recursive: true, force: true });
11896
+ if (fs16.readdirSync(dir).length === 0) fs16.rmSync(dir, { recursive: true, force: true });
11599
11897
  } catch {
11600
11898
  }
11601
11899
  }
11602
11900
  function ensureParentDirectory(target, label) {
11603
- const parent = path16.dirname(target);
11604
- if (fs15.existsSync(parent) && !fs15.statSync(parent).isDirectory()) {
11901
+ const parent = path17.dirname(target);
11902
+ if (fs16.existsSync(parent) && !fs16.statSync(parent).isDirectory()) {
11605
11903
  throw new Error(
11606
11904
  `Refusing to create ${label} ${target}: ${parent} exists but is not a directory.`
11607
11905
  );
11608
11906
  }
11609
11907
  try {
11610
- fs15.mkdirSync(parent, { recursive: true });
11908
+ fs16.mkdirSync(parent, { recursive: true });
11611
11909
  } catch (err) {
11612
11910
  throw new Error(
11613
11911
  `Refusing to create ${label} ${target}: its parent ${parent} could not be created (${err.message}).`
@@ -11665,17 +11963,17 @@ function acquireRunLock(stagingRoot) {
11665
11963
  `;
11666
11964
  for (let attempt = 0; attempt < 2; attempt += 1) {
11667
11965
  try {
11668
- const handle = fs15.openSync(lockPath, "wx");
11966
+ const handle = fs16.openSync(lockPath, "wx");
11669
11967
  try {
11670
- fs15.writeSync(handle, payload);
11968
+ fs16.writeSync(handle, payload);
11671
11969
  } finally {
11672
- fs15.closeSync(handle);
11970
+ fs16.closeSync(handle);
11673
11971
  }
11674
11972
  const stopHeartbeat = startLockHeartbeat(lockPath);
11675
11973
  return () => {
11676
11974
  stopHeartbeat();
11677
11975
  try {
11678
- fs15.rmSync(lockPath, { force: true });
11976
+ fs16.rmSync(lockPath, { force: true });
11679
11977
  } catch {
11680
11978
  }
11681
11979
  };
@@ -11695,26 +11993,26 @@ function lockKeyFor(stagingRoot) {
11695
11993
  return sha256Hex2(key).slice(0, 16);
11696
11994
  }
11697
11995
  function canonicalLockTarget(targetPath) {
11698
- const resolved = path16.resolve(targetPath);
11996
+ const resolved = path17.resolve(targetPath);
11699
11997
  let existing = resolved;
11700
11998
  const tail = [];
11701
11999
  for (; ; ) {
11702
12000
  try {
11703
- return path16.join(fs15.realpathSync(existing), ...tail);
12001
+ return path17.join(fs16.realpathSync(existing), ...tail);
11704
12002
  } catch {
11705
- const parent = path16.dirname(existing);
12003
+ const parent = path17.dirname(existing);
11706
12004
  if (parent === existing) return resolved;
11707
- tail.unshift(path16.basename(existing));
12005
+ tail.unshift(path17.basename(existing));
11708
12006
  existing = parent;
11709
12007
  }
11710
12008
  }
11711
12009
  }
11712
12010
  function lockPathFor(stagingRoot) {
11713
- return path16.join(os.tmpdir(), `codebase-snapshot-${lockKeyFor(stagingRoot)}.lock`);
12011
+ return path17.join(os.tmpdir(), `codebase-snapshot-${lockKeyFor(stagingRoot)}.lock`);
11714
12012
  }
11715
12013
  function lockHeartbeatAgeMs(lockPath) {
11716
12014
  try {
11717
- return Date.now() - fs15.statSync(lockPath).mtimeMs;
12015
+ return Date.now() - fs16.statSync(lockPath).mtimeMs;
11718
12016
  } catch {
11719
12017
  return Number.POSITIVE_INFINITY;
11720
12018
  }
@@ -11722,7 +12020,7 @@ function lockHeartbeatAgeMs(lockPath) {
11722
12020
  function lockOwnerIsGone(lockPath) {
11723
12021
  let raw;
11724
12022
  try {
11725
- raw = fs15.readFileSync(lockPath, "utf8");
12023
+ raw = fs16.readFileSync(lockPath, "utf8");
11726
12024
  } catch {
11727
12025
  return false;
11728
12026
  }
@@ -11744,16 +12042,16 @@ function lockOwnerIsGone(lockPath) {
11744
12042
  function reclaimStaleLock(lockPath) {
11745
12043
  let before;
11746
12044
  try {
11747
- before = fs15.statSync(lockPath);
12045
+ before = fs16.statSync(lockPath);
11748
12046
  } catch {
11749
12047
  return true;
11750
12048
  }
11751
12049
  if (!lockOwnerIsGone(lockPath)) return false;
11752
12050
  try {
11753
- const current = fs15.statSync(lockPath);
12051
+ const current = fs16.statSync(lockPath);
11754
12052
  const sameFile = current.ino === before.ino && current.birthtimeMs === before.birthtimeMs && current.mtimeMs === before.mtimeMs;
11755
12053
  if (!sameFile) return false;
11756
- fs15.rmSync(lockPath, { force: true });
12054
+ fs16.rmSync(lockPath, { force: true });
11757
12055
  return true;
11758
12056
  } catch {
11759
12057
  return false;
@@ -11764,12 +12062,12 @@ function lockFileIsAncient(lockPath) {
11764
12062
  }
11765
12063
  function writeManifestAtomically(manifestPath, manifest) {
11766
12064
  const tempPath = `${manifestPath}.${process.pid}.tmp`;
11767
- fs15.writeFileSync(tempPath, JSON.stringify(manifest, null, 2), "utf8");
12065
+ fs16.writeFileSync(tempPath, JSON.stringify(manifest, null, 2), "utf8");
11768
12066
  try {
11769
- fs15.renameSync(tempPath, manifestPath);
12067
+ fs16.renameSync(tempPath, manifestPath);
11770
12068
  } catch (err) {
11771
12069
  try {
11772
- fs15.rmSync(tempPath, { force: true });
12070
+ fs16.rmSync(tempPath, { force: true });
11773
12071
  } catch {
11774
12072
  }
11775
12073
  throw err;
@@ -11794,21 +12092,21 @@ function swapIntoPlace(stagingDir, outDir, beforeSwap) {
11794
12092
  }
11795
12093
  }
11796
12094
  function recoverInterruptedPublish(outDir) {
11797
- if (fs15.existsSync(outDir)) return;
11798
- const parent = path16.dirname(outDir);
11799
- const base = path16.basename(outDir);
12095
+ if (fs16.existsSync(outDir)) return;
12096
+ const parent = path17.dirname(outDir);
12097
+ const base = path17.basename(outDir);
11800
12098
  let backups;
11801
12099
  try {
11802
- backups = fs15.readdirSync(parent).filter((name) => name.startsWith(`${base}.backup-`));
12100
+ backups = fs16.readdirSync(parent).filter((name) => name.startsWith(`${base}.backup-`));
11803
12101
  } catch {
11804
12102
  return;
11805
12103
  }
11806
12104
  if (backups.length !== 1) return;
11807
- const backupDir = path16.join(parent, backups[0]);
12105
+ const backupDir = path17.join(parent, backups[0]);
11808
12106
  const { marker: marker2, problem } = readOwnershipMarker(backupDir);
11809
12107
  if (problem !== null || marker2 === null || marker2.state !== "complete") return;
11810
12108
  try {
11811
- fs15.renameSync(backupDir, outDir);
12109
+ fs16.renameSync(backupDir, outDir);
11812
12110
  process.stderr.write(
11813
12111
  `\u26A0 Recovered ${outDir} from ${backupDir}, left by an interrupted run. That snapshot is the one from before the interrupted run.
11814
12112
  `
@@ -11818,16 +12116,16 @@ function recoverInterruptedPublish(outDir) {
11818
12116
  }
11819
12117
  function swapOnce(stagingDir, outDir, beforeSwap) {
11820
12118
  const backupDir = `${outDir}.backup-${process.pid}-${Date.now()}`;
11821
- const hadPrevious = fs15.existsSync(outDir);
12119
+ const hadPrevious = fs16.existsSync(outDir);
11822
12120
  if (hadPrevious) beforeSwap?.();
11823
12121
  let movedAside = false;
11824
12122
  if (hadPrevious) {
11825
12123
  try {
11826
- fs15.renameSync(outDir, backupDir);
12124
+ fs16.renameSync(outDir, backupDir);
11827
12125
  movedAside = true;
11828
12126
  } catch (err) {
11829
12127
  if (!isLockError(err)) throw err;
11830
- fs15.rmSync(outDir, { recursive: true, force: true, maxRetries: 5, retryDelay: 100 });
12128
+ fs16.rmSync(outDir, { recursive: true, force: true, maxRetries: 5, retryDelay: 100 });
11831
12129
  process.stderr.write(
11832
12130
  `\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.
11833
12131
  `
@@ -11836,26 +12134,26 @@ function swapOnce(stagingDir, outDir, beforeSwap) {
11836
12134
  }
11837
12135
  try {
11838
12136
  try {
11839
- fs15.renameSync(stagingDir, outDir);
12137
+ fs16.renameSync(stagingDir, outDir);
11840
12138
  } catch (err) {
11841
12139
  if (err.code !== "EXDEV") throw err;
11842
12140
  const partialDir = `${outDir}.partial-${process.pid}-${Date.now()}`;
11843
12141
  try {
11844
- fs15.cpSync(stagingDir, partialDir, { recursive: true });
11845
- fs15.renameSync(partialDir, outDir);
11846
- fs15.rmSync(stagingDir, { recursive: true, force: true });
12142
+ fs16.cpSync(stagingDir, partialDir, { recursive: true });
12143
+ fs16.renameSync(partialDir, outDir);
12144
+ fs16.rmSync(stagingDir, { recursive: true, force: true });
11847
12145
  } catch (copyErr) {
11848
12146
  try {
11849
- fs15.rmSync(partialDir, { recursive: true, force: true });
12147
+ fs16.rmSync(partialDir, { recursive: true, force: true });
11850
12148
  } catch {
11851
12149
  }
11852
12150
  throw copyErr;
11853
12151
  }
11854
12152
  }
11855
12153
  } catch (err) {
11856
- if (hadPrevious && movedAside && fs15.existsSync(backupDir)) {
11857
- if (fs15.existsSync(outDir)) fs15.rmSync(outDir, { recursive: true, force: true });
11858
- fs15.renameSync(backupDir, outDir);
12154
+ if (hadPrevious && movedAside && fs16.existsSync(backupDir)) {
12155
+ if (fs16.existsSync(outDir)) fs16.rmSync(outDir, { recursive: true, force: true });
12156
+ fs16.renameSync(backupDir, outDir);
11859
12157
  } else if (hadPrevious && !movedAside) {
11860
12158
  process.stderr.write(
11861
12159
  `\u26A0 The previous snapshot at ${outDir} was removed and the new one could not be moved into place. It is complete at ${stagingDir}.
@@ -11866,7 +12164,7 @@ function swapOnce(stagingDir, outDir, beforeSwap) {
11866
12164
  }
11867
12165
  if (hadPrevious) {
11868
12166
  try {
11869
- fs15.rmSync(backupDir, { recursive: true, force: true });
12167
+ fs16.rmSync(backupDir, { recursive: true, force: true });
11870
12168
  } catch (err) {
11871
12169
  process.stderr.write(
11872
12170
  `\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.
@@ -12024,7 +12322,7 @@ function generateSnapshot(configInput, options) {
12024
12322
  // first run cannot have marked them yet, so the name alone keeps a run from recording its own
12025
12323
  // output — but only at these exact paths, not at every directory that shares the name.
12026
12324
  toolOwnedPaths: [config.outDir, config.tmpDir].map(
12027
- (directory) => path16.relative(config.cwd, path16.resolve(config.cwd, directory)).replace(/\\/g, "/")
12325
+ (directory) => path17.relative(config.cwd, path17.resolve(config.cwd, directory)).replace(/\\/g, "/")
12028
12326
  ).filter((relative11) => relative11.length > 0 && !relative11.startsWith("..")),
12029
12327
  // A staged path can be absent from the working tree while its index blob exists. Discovery
12030
12328
  // lists the working tree, so those paths would never reach the scan at all.
@@ -12053,7 +12351,7 @@ function generateSnapshot(configInput, options) {
12053
12351
  let totalSizeBytes = 0;
12054
12352
  let largeFileCount = 0;
12055
12353
  for (const relativePath of candidateFiles) {
12056
- const absolutePath = path16.join(config.cwd, relativePath);
12354
+ const absolutePath = path17.join(config.cwd, relativePath);
12057
12355
  const fromIndex = stagedPaths.has(relativePath);
12058
12356
  let buffer;
12059
12357
  let sizeBytes;
@@ -12084,9 +12382,9 @@ function generateSnapshot(configInput, options) {
12084
12382
  } else {
12085
12383
  let stats;
12086
12384
  try {
12087
- stats = fs15.statSync(absolutePath);
12385
+ stats = fs16.statSync(absolutePath);
12088
12386
  if (!stats.isFile()) {
12089
- const nestedRepository = stats.isDirectory() && fs15.existsSync(path16.join(absolutePath, ".git"));
12387
+ const nestedRepository = stats.isDirectory() && fs16.existsSync(path17.join(absolutePath, ".git"));
12090
12388
  skipped.push(
12091
12389
  nestedRepository ? {
12092
12390
  path: relativePath,
@@ -12122,7 +12420,7 @@ function generateSnapshot(configInput, options) {
12122
12420
  continue;
12123
12421
  }
12124
12422
  try {
12125
- buffer = fs15.readFileSync(absolutePath);
12423
+ buffer = fs16.readFileSync(absolutePath);
12126
12424
  } catch (err) {
12127
12425
  const code = err.code;
12128
12426
  skipped.push({
@@ -12251,14 +12549,14 @@ function generateSnapshot(configInput, options) {
12251
12549
  (finding) => finding.path === void 0 || keep.has(finding.path)
12252
12550
  );
12253
12551
  retain(encodingNotes, (note) => keep.has(note.path));
12254
- retain(oversizeSummaryPaths, (path17) => keep.has(path17));
12255
- retain(previewSummaryPaths, (path17) => keep.has(path17));
12552
+ retain(oversizeSummaryPaths, (path18) => keep.has(path18));
12553
+ retain(previewSummaryPaths, (path18) => keep.has(path18));
12256
12554
  retain(fileWarnings, (warning) => keep.has(warning.path));
12257
- for (const path17 of [...monolithBodies.keys()]) {
12258
- if (!keep.has(path17)) monolithBodies.delete(path17);
12555
+ for (const path18 of [...monolithBodies.keys()]) {
12556
+ if (!keep.has(path18)) monolithBodies.delete(path18);
12259
12557
  }
12260
- for (const path17 of [...skippedSummaryImports.keys()]) {
12261
- if (!keep.has(path17)) skippedSummaryImports.delete(path17);
12558
+ for (const path18 of [...skippedSummaryImports.keys()]) {
12559
+ if (!keep.has(path18)) skippedSummaryImports.delete(path18);
12262
12560
  }
12263
12561
  }
12264
12562
  if (changedScope !== null) {
@@ -12397,6 +12695,8 @@ function generateSnapshot(configInput, options) {
12397
12695
  // omitted from `digest` when it is off so an existing snapshot does not start reporting
12398
12696
  // configuration drift.
12399
12697
  maxParts: config.maxParts ?? null,
12698
+ promptTask: config.promptTask,
12699
+ ...config.brief === void 0 ? {} : { brief: { path: config.brief.path, digest: config.brief.digest } },
12400
12700
  discovery: config.discovery ?? "auto",
12401
12701
  // A changed-files scope decides which files are in the snapshot, so the manifest that
12402
12702
  // describes the run has to name it.
@@ -12527,14 +12827,16 @@ function generateSnapshot(configInput, options) {
12527
12827
  if (auditText !== null) manifest.artifacts.audit = artifactRecord(auditText);
12528
12828
  const readmeText = artifacts.readme ? generateReadme(manifest, artifacts) : null;
12529
12829
  if (readmeText !== null) manifest.artifacts.readme = artifactRecord(readmeText);
12530
- const promptText = artifacts.prompt ? generatePrompt(
12531
- manifest,
12532
- artifacts,
12533
- config.attachmentSlots,
12534
- // Commit subjects are user input and reach an artifact, so they go through the same
12535
- // masking as every other name the run reproduces.
12536
- recentCommitSubjects(config.cwd).map((subject) => maskPathText(subject, config.secretRules))
12537
- ) : null;
12830
+ const promptText = artifacts.prompt ? generatePrompt(manifest, artifacts, {
12831
+ slots: config.attachmentSlots,
12832
+ task: config.promptTask,
12833
+ brief: maskOwnerBrief(config.brief, config.secretRules),
12834
+ history: recentCommits(config.cwd).map((commit) => ({
12835
+ subject: maskPathText(commit.subject, config.secretRules),
12836
+ body: maskPathText(commit.body, config.secretRules)
12837
+ })),
12838
+ overview: maskOverview(readProjectOverview(config.cwd), config.secretRules)
12839
+ }) : null;
12538
12840
  if (promptText !== null) manifest.artifacts.prompt = artifactRecord(promptText);
12539
12841
  if (projectTree !== null) manifest.artifacts.projectTree = artifactRecord(projectTree);
12540
12842
  let monolithJson = null;
@@ -12610,12 +12912,12 @@ function generateSnapshot(configInput, options) {
12610
12912
  let releaseDeferred = false;
12611
12913
  try {
12612
12914
  ensureParentDirectory(outDir, "outDir");
12613
- fs15.mkdirSync(tmpDir, { recursive: true });
12915
+ fs16.mkdirSync(tmpDir, { recursive: true });
12614
12916
  cleanStaleRunDirs(tmpDir);
12615
12917
  const snapshotId = crypto2.randomUUID();
12616
12918
  const createdAt = (/* @__PURE__ */ new Date()).toISOString();
12617
- stagingDir = path16.join(tmpDir, `${RUN_DIR_PREFIX}${process.pid}-${snapshotId.slice(0, 8)}`);
12618
- fs15.mkdirSync(stagingDir);
12919
+ stagingDir = path17.join(tmpDir, `${RUN_DIR_PREFIX}${process.pid}-${snapshotId.slice(0, 8)}`);
12920
+ fs16.mkdirSync(stagingDir);
12619
12921
  writeOwnershipMarker(stagingDir, {
12620
12922
  generator: GENERATOR_NAME,
12621
12923
  version: GENERATOR_VERSION,
@@ -12625,30 +12927,30 @@ function generateSnapshot(configInput, options) {
12625
12927
  id: snapshotId,
12626
12928
  pid: process.pid
12627
12929
  });
12628
- const partsDir = path16.join(stagingDir, "parts");
12629
- const reportsDir = path16.join(stagingDir, "reports");
12630
- if (artifacts.parts) fs15.mkdirSync(partsDir, { recursive: true });
12930
+ const partsDir = path17.join(stagingDir, "parts");
12931
+ const reportsDir = path17.join(stagingDir, "reports");
12932
+ if (artifacts.parts) fs16.mkdirSync(partsDir, { recursive: true });
12631
12933
  if (artifacts.navigation || artifacts.projectTree || artifacts.audit || config.sarif === true) {
12632
- fs15.mkdirSync(reportsDir, { recursive: true });
12934
+ fs16.mkdirSync(reportsDir, { recursive: true });
12633
12935
  }
12634
12936
  const writtenArtifacts = /* @__PURE__ */ new Map();
12635
12937
  const writeArtifact = (targetDir, relativeEntry, data) => {
12636
- const full = path16.join(targetDir, ...relativeEntry.split("/"));
12637
- fs15.writeFileSync(full, data, "utf8");
12638
- const stats = fs15.statSync(full);
12938
+ const full = path17.join(targetDir, ...relativeEntry.split("/"));
12939
+ fs16.writeFileSync(full, data, "utf8");
12940
+ const stats = fs16.statSync(full);
12639
12941
  writtenArtifacts.set(relativeEntry, {
12640
12942
  digest: { path: relativeEntry, bytes: stats.size, sha256: sha256Hex2(data) },
12641
12943
  mtimeMs: stats.mtimeMs
12642
12944
  });
12643
12945
  };
12644
12946
  const recordArtifact = (targetDir, relativeEntry) => {
12645
- const full = path16.join(targetDir, ...relativeEntry.split("/"));
12646
- const stats = fs15.statSync(full);
12947
+ const full = path17.join(targetDir, ...relativeEntry.split("/"));
12948
+ const stats = fs16.statSync(full);
12647
12949
  writtenArtifacts.set(relativeEntry, {
12648
12950
  digest: {
12649
12951
  path: relativeEntry,
12650
12952
  bytes: stats.size,
12651
- sha256: sha256Hex2(fs15.readFileSync(full))
12953
+ sha256: sha256Hex2(fs16.readFileSync(full))
12652
12954
  },
12653
12955
  mtimeMs: stats.mtimeMs
12654
12956
  });
@@ -12696,7 +12998,7 @@ function generateSnapshot(configInput, options) {
12696
12998
  const shipHookState = () => {
12697
12999
  if (!markerBelongsTo(outDir, snapshotId)) return;
12698
13000
  if (artifacts.manifest && manifest.warnings.length !== warningsBeforeHook) {
12699
- writeManifestAtomically(path16.join(outDir, "manifest.json"), manifest);
13001
+ writeManifestAtomically(path17.join(outDir, "manifest.json"), manifest);
12700
13002
  recordArtifact(outDir, "manifest.json");
12701
13003
  }
12702
13004
  writeOwnershipMarker(
@@ -12739,7 +13041,7 @@ function generateSnapshot(configInput, options) {
12739
13041
  } catch (err) {
12740
13042
  if (stagingDir !== null) {
12741
13043
  try {
12742
- fs15.rmSync(stagingDir, { recursive: true, force: true });
13044
+ fs16.rmSync(stagingDir, { recursive: true, force: true });
12743
13045
  } catch {
12744
13046
  }
12745
13047
  }