codebase-snapshot 0.11.0 → 0.12.1

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.1";
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,23 @@ 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 truncateAtSentence(text2, limit) {
4430
+ if (text2.length <= limit) return text2;
4431
+ const window = text2.slice(0, limit);
4432
+ const sentence = Math.max(window.lastIndexOf(". "), window.lastIndexOf("; "));
4433
+ if (sentence > limit / 3) return window.slice(0, sentence + 1).trim();
4434
+ const space = window.lastIndexOf(" ");
4435
+ if (space > limit / 3) return window.slice(0, space).trim() + "\u2026";
4436
+ return window.trim() + "\u2026";
4437
+ }
4438
+ function recentCommits(cwd, limit = 10) {
4358
4439
  try {
4359
4440
  const stdout = childProcess.execFileSync(
4360
4441
  "git",
4361
- ["log", "-n", String(limit), "--pretty=%s", "--no-color"],
4442
+ // \x1f between fields and \x1e between records: neither can appear in a commit message, so
4443
+ // the parse cannot be confused by a message that contains a newline or a dash.
4444
+ ["log", "-n", String(limit), "--pretty=format:%s%x1f%b%x1e", "--no-color"],
4362
4445
  {
4363
4446
  cwd,
4364
4447
  stdio: ["ignore", "pipe", "ignore"],
@@ -4366,7 +4449,16 @@ function recentCommitSubjects(cwd, limit = 10) {
4366
4449
  maxBuffer: GIT_OUTPUT_LIMIT
4367
4450
  }
4368
4451
  );
4369
- return stdout.split("\n").map((line) => line.trim()).filter((line) => line.length > 0);
4452
+ return stdout.split("").map((record) => record.replace(/^\n+/, "")).filter((record) => record.length > 0).map((record) => {
4453
+ const separator = record.indexOf("");
4454
+ const subject = separator === -1 ? record : record.slice(0, separator);
4455
+ const rawBody = separator === -1 ? "" : record.slice(separator + 1);
4456
+ const body = rawBody.split("\n").map((line) => line.trim()).filter((line) => line.length > 0).join(" ").replace(/\s*\|\s*/g, " ").replace(/\s+/g, " ").trim();
4457
+ return {
4458
+ subject: subject.trim(),
4459
+ body: truncateAtSentence(body, COMMIT_BODY_LIMIT)
4460
+ };
4461
+ }).filter((commit) => commit.subject.length > 0);
4370
4462
  } catch {
4371
4463
  return [];
4372
4464
  }
@@ -4390,7 +4482,7 @@ function listIgnoredPaths(cwd) {
4390
4482
  }
4391
4483
  function hasSnapshotMarker(target) {
4392
4484
  try {
4393
- return fs15.statSync(target).isDirectory() && fs15.existsSync(path16.join(target, ".codebase-snapshot"));
4485
+ return fs16.statSync(target).isDirectory() && fs16.existsSync(path17.join(target, ".codebase-snapshot"));
4394
4486
  } catch {
4395
4487
  return false;
4396
4488
  }
@@ -4399,7 +4491,7 @@ var IGNORABLE_DIRECTORY_ENTRIES = /* @__PURE__ */ new Set([".DS_Store"]);
4399
4491
  function isToolOwnedDirectory2(dir) {
4400
4492
  let raw;
4401
4493
  try {
4402
- raw = fs15.readFileSync(path16.join(dir, ".codebase-snapshot"), "utf8");
4494
+ raw = fs16.readFileSync(path17.join(dir, ".codebase-snapshot"), "utf8");
4403
4495
  } catch {
4404
4496
  return false;
4405
4497
  }
@@ -4426,7 +4518,7 @@ function isToolOwnedDirectory2(dir) {
4426
4518
  }
4427
4519
  let entries;
4428
4520
  try {
4429
- entries = fs15.readdirSync(dir);
4521
+ entries = fs16.readdirSync(dir);
4430
4522
  } catch {
4431
4523
  return false;
4432
4524
  }
@@ -4443,7 +4535,7 @@ function makeToolOwnedDecider(cwd, toolOwnedPaths) {
4443
4535
  const prefix = parts.slice(0, depth).join("/");
4444
4536
  let hasMarker = markers.get(prefix);
4445
4537
  if (hasMarker === void 0) {
4446
- hasMarker = isToolOwnedDirectory2(path16.join(cwd, prefix));
4538
+ hasMarker = isToolOwnedDirectory2(path17.join(cwd, prefix));
4447
4539
  markers.set(prefix, hasMarker);
4448
4540
  }
4449
4541
  if (hasMarker) return true;
@@ -4458,7 +4550,7 @@ function makeLinkProbe() {
4458
4550
  let known = cache.get(absolutePath);
4459
4551
  if (known === void 0) {
4460
4552
  try {
4461
- known = fs15.lstatSync(absolutePath).isSymbolicLink();
4553
+ known = fs16.lstatSync(absolutePath).isSymbolicLink();
4462
4554
  } catch {
4463
4555
  known = false;
4464
4556
  }
@@ -4471,7 +4563,7 @@ function dropLinkedDirectories(cwd, candidates, skipped) {
4471
4563
  const isLink = makeLinkProbe();
4472
4564
  let rootReal = cwd;
4473
4565
  try {
4474
- rootReal = fs15.realpathSync(cwd);
4566
+ rootReal = fs16.realpathSync(cwd);
4475
4567
  } catch {
4476
4568
  }
4477
4569
  const reported = /* @__PURE__ */ new Set();
@@ -4486,7 +4578,7 @@ function dropLinkedDirectories(cwd, candidates, skipped) {
4486
4578
  let linkedPath = null;
4487
4579
  for (let depth = 1; depth <= parts.length; depth += 1) {
4488
4580
  const prefix = parts.slice(0, depth).join("/");
4489
- if (isLink(path16.join(cwd, prefix))) {
4581
+ if (isLink(path17.join(cwd, prefix))) {
4490
4582
  linkedPath = prefix;
4491
4583
  break;
4492
4584
  }
@@ -4495,11 +4587,11 @@ function dropLinkedDirectories(cwd, candidates, skipped) {
4495
4587
  kept.push(candidate);
4496
4588
  continue;
4497
4589
  }
4498
- const absolute = path16.join(cwd, linkedPath);
4590
+ const absolute = path17.join(cwd, linkedPath);
4499
4591
  const rawTarget = readLinkTarget(absolute, absolute);
4500
4592
  let targetReal = null;
4501
4593
  try {
4502
- targetReal = fs15.realpathSync(absolute);
4594
+ targetReal = fs16.realpathSync(absolute);
4503
4595
  } catch {
4504
4596
  targetReal = null;
4505
4597
  }
@@ -4517,7 +4609,7 @@ function dropLinkedDirectories(cwd, candidates, skipped) {
4517
4609
  }
4518
4610
  let stats = null;
4519
4611
  try {
4520
- stats = fs15.statSync(absolute);
4612
+ stats = fs16.statSync(absolute);
4521
4613
  } catch {
4522
4614
  stats = null;
4523
4615
  }
@@ -4605,7 +4697,7 @@ function collectFiles(cwd, options = {}) {
4605
4697
  "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
4698
  );
4607
4699
  }
4608
- if (fs15.existsSync(path16.join(cwd, ".git"))) {
4700
+ if (fs16.existsSync(path17.join(cwd, ".git"))) {
4609
4701
  throw new Error(
4610
4702
  "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
4703
  );
@@ -4673,7 +4765,7 @@ function collectFiles(cwd, options = {}) {
4673
4765
  }
4674
4766
  function rootRealFor(root) {
4675
4767
  try {
4676
- return fs15.realpathSync(root);
4768
+ return fs16.realpathSync(root);
4677
4769
  } catch {
4678
4770
  return root;
4679
4771
  }
@@ -4682,18 +4774,18 @@ function walkDirectory(dir, baseDir, rootReal, visited, reservedPaths = /* @__PU
4682
4774
  const results = { files: [], skipped: [] };
4683
4775
  const stack = [];
4684
4776
  const toolDirNames = toolDirNamesFor(reservedPaths);
4685
- const relativeToBase = (target) => path16.relative(baseDir, target).replace(/\\/g, "/") || ".";
4777
+ const relativeToBase = (target) => path17.relative(baseDir, target).replace(/\\/g, "/") || ".";
4686
4778
  const enter = (current, layers) => {
4687
4779
  if (visited.has(current)) return false;
4688
4780
  visited.add(current);
4689
4781
  const localRules = readGitignoreRules(current);
4690
4782
  const gitignoreLayers = localRules.length === 0 ? layers : [
4691
4783
  ...layers,
4692
- { prefix: path16.relative(baseDir, current).replace(/\\/g, "/"), rules: localRules }
4784
+ { prefix: path17.relative(baseDir, current).replace(/\\/g, "/"), rules: localRules }
4693
4785
  ];
4694
4786
  let entries;
4695
4787
  try {
4696
- entries = fs15.readdirSync(current, { withFileTypes: true });
4788
+ entries = fs16.readdirSync(current, { withFileTypes: true });
4697
4789
  } catch {
4698
4790
  results.skipped.push({
4699
4791
  path: relativeToBase(current),
@@ -4715,8 +4807,8 @@ function walkDirectory(dir, baseDir, rootReal, visited, reservedPaths = /* @__PU
4715
4807
  }
4716
4808
  const entry = frame.entries[frame.index];
4717
4809
  frame.index += 1;
4718
- const fullPath = path16.join(frame.dir, entry.name);
4719
- const relPath = path16.relative(baseDir, fullPath).replace(/\\/g, "/");
4810
+ const fullPath = path17.join(frame.dir, entry.name);
4811
+ const relPath = path17.relative(baseDir, fullPath).replace(/\\/g, "/");
4720
4812
  if (reservedPaths.has(relPath)) continue;
4721
4813
  if (entry.isDirectory() && DEFAULT_IGNORED_DIRS.includes(entry.name)) {
4722
4814
  results.skipped.push({
@@ -4749,14 +4841,14 @@ function walkDirectory(dir, baseDir, rootReal, visited, reservedPaths = /* @__PU
4749
4841
  if (entry.isSymbolicLink()) {
4750
4842
  let targetReal;
4751
4843
  try {
4752
- targetReal = fs15.realpathSync(fullPath);
4844
+ targetReal = fs16.realpathSync(fullPath);
4753
4845
  } catch {
4754
4846
  results.skipped.push(brokenLinkRecord(fullPath, relPath, rootReal));
4755
4847
  continue;
4756
4848
  }
4757
4849
  let stats;
4758
4850
  try {
4759
- stats = fs15.statSync(fullPath);
4851
+ stats = fs16.statSync(fullPath);
4760
4852
  } catch {
4761
4853
  results.skipped.push({ path: relPath, reason: "read-error", detail: "unreadable symlink" });
4762
4854
  continue;
@@ -4786,7 +4878,7 @@ function walkDirectory(dir, baseDir, rootReal, visited, reservedPaths = /* @__PU
4786
4878
  });
4787
4879
  continue;
4788
4880
  }
4789
- const targetRelative = path16.relative(rootReal, targetReal).split(path16.sep).join("/");
4881
+ const targetRelative = path17.relative(rootReal, targetReal).split(path17.sep).join("/");
4790
4882
  if (isSensitivePath(targetRelative)) {
4791
4883
  results.skipped.push({
4792
4884
  path: relPath,
@@ -4842,20 +4934,20 @@ var CONFIG_FILENAMES = [
4842
4934
  ];
4843
4935
  function findConfigFile(cwd) {
4844
4936
  for (const filename of CONFIG_FILENAMES) {
4845
- const fullPath = path16.join(cwd, filename);
4937
+ const fullPath = path17.join(cwd, filename);
4846
4938
  let stats = null;
4847
4939
  try {
4848
- stats = fs15.statSync(fullPath);
4940
+ stats = fs16.statSync(fullPath);
4849
4941
  } catch {
4850
- if (fs15.existsSync(fullPath)) return fullPath;
4942
+ if (fs16.existsSync(fullPath)) return fullPath;
4851
4943
  continue;
4852
4944
  }
4853
4945
  if (stats.isFile()) return fullPath;
4854
4946
  }
4855
- const pkgJsonPath = path16.join(cwd, "package.json");
4856
- if (!fs15.existsSync(pkgJsonPath)) return null;
4947
+ const pkgJsonPath = path17.join(cwd, "package.json");
4948
+ if (!fs16.existsSync(pkgJsonPath)) return null;
4857
4949
  try {
4858
- const parsed = JSON.parse(stripJsonComments(fs15.readFileSync(pkgJsonPath, "utf8")));
4950
+ const parsed = JSON.parse(stripJsonComments(fs16.readFileSync(pkgJsonPath, "utf8")));
4859
4951
  const snapshot = parsed?.snapshot;
4860
4952
  return typeof snapshot === "object" && snapshot !== null && !Array.isArray(snapshot) ? pkgJsonPath : null;
4861
4953
  } catch {
@@ -4921,6 +5013,8 @@ function normalizeResolvedConfig(config) {
4921
5013
  // is re-validated because the number reaches a rendered artifact.
4922
5014
  attachmentSlots: resolveAttachmentSlots(config.attachmentSlots),
4923
5015
  maxParts: resolveMaxParts(config.maxParts),
5016
+ promptTask: resolvePromptTask(config.promptTask),
5017
+ ...config.brief === void 0 ? {} : { brief: config.brief },
4924
5018
  includeMonolith: artifacts.monolith,
4925
5019
  secretRules: compileSecretRules(config.secretRules),
4926
5020
  artifacts,
@@ -4991,6 +5085,7 @@ var CONFIG_KEY_NAMES = [
4991
5085
  "artifacts",
4992
5086
  "attachmentSlots",
4993
5087
  "branch",
5088
+ "brief",
4994
5089
  "budgets",
4995
5090
  "changedSince",
4996
5091
  "cwd",
@@ -5012,6 +5107,7 @@ var CONFIG_KEY_NAMES = [
5012
5107
  "outDir",
5013
5108
  "preset",
5014
5109
  "previewHeadLines",
5110
+ "promptTask",
5015
5111
  "staged",
5016
5112
  "previewTailLines",
5017
5113
  "secretRules",
@@ -5062,10 +5158,10 @@ function readConfigExport(exported, file) {
5062
5158
  var lastModuleConfig = null;
5063
5159
  function moduleConfigKey(fullPath) {
5064
5160
  try {
5065
- return createHash("sha256").update(fs15.readFileSync(fullPath)).digest("hex").slice(0, 24);
5161
+ return createHash("sha256").update(fs16.readFileSync(fullPath)).digest("hex").slice(0, 24);
5066
5162
  } catch {
5067
5163
  try {
5068
- const stats = fs15.statSync(fullPath);
5164
+ const stats = fs16.statSync(fullPath);
5069
5165
  return `stat-${stats.mtimeMs}-${stats.size}`;
5070
5166
  } catch {
5071
5167
  return "unreadable";
@@ -5091,7 +5187,7 @@ async function importConfigModule(fullPath) {
5091
5187
  function attachConfigDir(config, filePath) {
5092
5188
  if (typeof config === "object" && config !== null) {
5093
5189
  Object.defineProperty(config, CONFIG_DIR_SYMBOL, {
5094
- value: path16.dirname(filePath),
5190
+ value: path17.dirname(filePath),
5095
5191
  enumerable: false,
5096
5192
  configurable: true
5097
5193
  });
@@ -5103,12 +5199,12 @@ async function loadConfigFileDetailed(cwd, options = {}) {
5103
5199
  const errors = [];
5104
5200
  const configDirectories = [];
5105
5201
  for (const filename of CONFIG_FILENAMES) {
5106
- const fullPath = path16.join(cwd, filename);
5202
+ const fullPath = path17.join(cwd, filename);
5107
5203
  let candidateStats = null;
5108
5204
  try {
5109
- candidateStats = fs15.statSync(fullPath);
5205
+ candidateStats = fs16.statSync(fullPath);
5110
5206
  } catch {
5111
- if (!fs15.existsSync(fullPath)) continue;
5207
+ if (!fs16.existsSync(fullPath)) continue;
5112
5208
  }
5113
5209
  if (candidateStats !== null && !candidateStats.isFile()) {
5114
5210
  configDirectories.push(fullPath);
@@ -5116,7 +5212,7 @@ async function loadConfigFileDetailed(cwd, options = {}) {
5116
5212
  }
5117
5213
  if (filename.endsWith(".json") || filename === ".snapshotrc") {
5118
5214
  try {
5119
- const config = parseJsonish(fs15.readFileSync(fullPath, "utf8"), fullPath);
5215
+ const config = parseJsonish(fs16.readFileSync(fullPath, "utf8"), fullPath);
5120
5216
  if (config === null || typeof config !== "object" || Array.isArray(config)) {
5121
5217
  throw new Error(
5122
5218
  `${fullPath} does not hold a configuration object (received ${describeValue2(config)}).`
@@ -5156,10 +5252,10 @@ async function loadConfigFileDetailed(cwd, options = {}) {
5156
5252
  continue;
5157
5253
  }
5158
5254
  }
5159
- const pkgJsonPath = path16.join(cwd, "package.json");
5160
- if (fs15.existsSync(pkgJsonPath)) {
5255
+ const pkgJsonPath = path17.join(cwd, "package.json");
5256
+ if (fs16.existsSync(pkgJsonPath)) {
5161
5257
  try {
5162
- const parsed = parseJsonish(fs15.readFileSync(pkgJsonPath, "utf8"), pkgJsonPath);
5258
+ const parsed = parseJsonish(fs16.readFileSync(pkgJsonPath, "utf8"), pkgJsonPath);
5163
5259
  const snapshotKey = parsed.snapshot;
5164
5260
  if (snapshotKey && typeof snapshotKey === "object" && !Array.isArray(snapshotKey)) {
5165
5261
  assertKnownConfigKeys(
@@ -5303,6 +5399,38 @@ function resolveMaxParts(value) {
5303
5399
  }
5304
5400
  return value;
5305
5401
  }
5402
+ function resolvePromptTask(value) {
5403
+ if (value === void 0 || value === null) return "audit";
5404
+ if (value === "audit" || value === "review" || value === "explain") return value;
5405
+ throw new Error(
5406
+ 'promptTask must be one of "audit", "review" or "explain" (received ' + describeValue2(value) + ")."
5407
+ );
5408
+ }
5409
+ function readConfiguredBrief(cwd, value) {
5410
+ if (value === void 0 || value === null) return void 0;
5411
+ if (typeof value !== "string" || value.trim().length === 0) {
5412
+ throw new Error(
5413
+ "brief must be a path to a markdown file (received " + describeValue2(value) + ")."
5414
+ );
5415
+ }
5416
+ const filePath = path17.resolve(cwd, value);
5417
+ let text2;
5418
+ try {
5419
+ if (!fs16.statSync(filePath).isFile()) throw new Error("not a file");
5420
+ text2 = fs16.readFileSync(filePath, "utf8");
5421
+ } catch {
5422
+ throw new Error(
5423
+ 'brief "' + value + '" could not be read as a file; a snapshot must not ship without the half of the brief the owner wrote.'
5424
+ );
5425
+ }
5426
+ const parsed = parseOwnerBrief(value, text2);
5427
+ if (parsed.problems.length > 0) {
5428
+ throw new Error(
5429
+ 'brief "' + value + '" cannot be used:\n - ' + parsed.problems.join("\n - ")
5430
+ );
5431
+ }
5432
+ return parsed.brief;
5433
+ }
5306
5434
  function strictPositiveInteger(value, fallback, label) {
5307
5435
  if (value === void 0) return fallback;
5308
5436
  if (typeof value !== "number" || !Number.isInteger(value) || value <= 0) {
@@ -5395,9 +5523,9 @@ function resolveKindRules(value) {
5395
5523
  function outputExcludePatterns(cwd, outDir, tmpDir) {
5396
5524
  const patterns = [];
5397
5525
  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)) {
5526
+ const absolute = path17.resolve(cwd, dir);
5527
+ const relative11 = path17.relative(cwd, absolute);
5528
+ if (!relative11 || relative11 === ".." || relative11.startsWith(`..${path17.sep}`) || path17.isAbsolute(relative11)) {
5401
5529
  continue;
5402
5530
  }
5403
5531
  patterns.push(`${relative11.replace(/\\/g, "/")}/**`);
@@ -5530,11 +5658,11 @@ function resolveCandidateCwd(userConfig, cliOptions, baseDir) {
5530
5658
  );
5531
5659
  }
5532
5660
  const candidate = cliOptions?.cwd || userConfig?.cwd || baseDir || process.cwd();
5533
- const resolved = path16.resolve(candidate);
5534
- if (!fs15.existsSync(resolved)) {
5661
+ const resolved = path17.resolve(candidate);
5662
+ if (!fs16.existsSync(resolved)) {
5535
5663
  throw new Error(`Working directory does not exist: ${resolved}`);
5536
5664
  }
5537
- if (!fs15.statSync(resolved).isDirectory()) {
5665
+ if (!fs16.statSync(resolved).isDirectory()) {
5538
5666
  throw new Error(`Working directory is not a directory: ${resolved}`);
5539
5667
  }
5540
5668
  return resolved;
@@ -5662,6 +5790,10 @@ function resolveConfig(userConfig, cliOptions, baseDir) {
5662
5790
  configuredSensitiveFiles,
5663
5791
  "`includeSensitiveFiles`"
5664
5792
  );
5793
+ const configuredBrief = readConfiguredBrief(
5794
+ cwd,
5795
+ cliOptions?.brief ?? userConfig?.brief
5796
+ );
5665
5797
  const presetExclude = [
5666
5798
  .../* @__PURE__ */ new Set([...preset.exclude, ...outputExcludePatterns(cwd, outDir, tmpDir)])
5667
5799
  ];
@@ -5685,6 +5817,8 @@ function resolveConfig(userConfig, cliOptions, baseDir) {
5685
5817
  cliOptions?.attachmentSlots ?? userConfig?.attachmentSlots
5686
5818
  ),
5687
5819
  maxParts: resolveMaxParts(cliOptions?.maxParts ?? userConfig?.maxParts),
5820
+ promptTask: resolvePromptTask(cliOptions?.promptTask ?? userConfig?.promptTask),
5821
+ ...configuredBrief === void 0 ? {} : { brief: configuredBrief },
5688
5822
  ...changedSince === void 0 ? {} : { changedSince },
5689
5823
  ...staged ? { staged } : {},
5690
5824
  ...withDependents ? { withDependents } : {},
@@ -5770,6 +5904,12 @@ function configDigest(config) {
5770
5904
  // Only when the experimental mode is on: `null` is the off switch, and writing it into the
5771
5905
  // material would change the digest of every snapshot taken before the setting existed.
5772
5906
  ...config.maxParts === null ? {} : { maxParts: config.maxParts },
5907
+ // The default value is omitted for the same reason: a snapshot taken before the setting
5908
+ // existed kept the audit job, so it must keep the digest it was written with.
5909
+ ...config.promptTask === "audit" ? {} : { promptTask: config.promptTask },
5910
+ // The owner brief is instruction, not payload, but it changes what the snapshot tells a
5911
+ // reader to do, so a changed brief is drift exactly like a changed budget.
5912
+ ...config.brief === void 0 ? {} : { brief: config.brief.digest },
5773
5913
  artifacts: config.artifacts,
5774
5914
  include: config.include,
5775
5915
  excludePatterns: config.excludePatterns,
@@ -6741,9 +6881,15 @@ var UNLIMITED_SLOTS = 0;
6741
6881
  var ENTRY_POINT = /(^|\/)(index|cli|main|bin|server|app|mod)\.[cm]?[jt]sx?$/;
6742
6882
  var TEST_PATH = /(^|\/)(tests?|__tests__)\//;
6743
6883
  var TEST_FILE = /\.(test|spec)\.[^.]+$/;
6744
- function generatePrompt(manifest, artifacts, attachmentSlots = DEFAULT_ATTACHMENT_SLOTS, history = []) {
6884
+ function generatePrompt(manifest, artifacts, context = {}) {
6885
+ const slots = context.slots ?? DEFAULT_ATTACHMENT_SLOTS;
6886
+ const task = context.task ?? "audit";
6887
+ const history = context.history ?? [];
6888
+ const overview = context.overview ?? { releases: [] };
6889
+ const brief = context.brief;
6745
6890
  const wrote = (name) => artifacts?.[name] !== false;
6746
6891
  const code = (value) => inlineCode(escapeControls(value));
6892
+ const hasOwnerHistory = (brief?.history ?? "").trim().length > 0;
6747
6893
  const lines = [
6748
6894
  "# PROMPT.md",
6749
6895
  "",
@@ -6759,30 +6905,22 @@ function generatePrompt(manifest, artifacts, attachmentSlots = DEFAULT_ATTACHMEN
6759
6905
  "You are working on a codebase you cannot clone, run or grep. Everything you know about it comes",
6760
6906
  "from the snapshot that follows this instruction. Where these notes and the snapshot disagree,",
6761
6907
  "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
6908
  ""
6776
6909
  ];
6910
+ if (brief?.preamble !== void 0) lines.push(brief.preamble, "");
6911
+ lines.push(...jobSection(task, history.length > 0 || hasOwnerHistory), "");
6912
+ lines.push(...stakesSection(brief, code));
6777
6913
  lines.push(...haveSection(wrote), "");
6778
- lines.push(...systemSection(manifest, code), "");
6779
- lines.push(...historySection(history), "");
6780
- lines.push(...barSection(), "");
6914
+ lines.push(...whatThisIsSection(overview), "");
6915
+ lines.push(...systemSection(manifest, code, brief), "");
6916
+ lines.push(...historySection(history, brief, code), "");
6917
+ lines.push(...barSection(brief, code), "");
6781
6918
  lines.push(...coverageSection(manifest, code, wrote("audit")), "");
6782
6919
  lines.push(...answerSection(), "");
6783
- lines.push(...calibrationSection(), "");
6920
+ lines.push(...calibrationSection(brief, code), "");
6921
+ lines.push(...ownerNotesSection(brief, code));
6784
6922
  lines.push(...snapshotSection(manifest, code), "");
6785
- lines.push(...deliverySection(manifest, wrote("parts"), attachmentSlots));
6923
+ lines.push(...deliverySection(manifest, wrote("parts"), slots));
6786
6924
  lines.push(
6787
6925
  "## Your task",
6788
6926
  "",
@@ -6859,8 +6997,11 @@ function haveSection(wrote) {
6859
6997
  out.push(...bullets);
6860
6998
  return out;
6861
6999
  }
6862
- function systemSection(manifest, code) {
7000
+ function systemSection(manifest, code, brief) {
6863
7001
  const out = ["## The system", ""];
7002
+ if (brief?.system !== void 0) {
7003
+ out.push(...ownerBlock(brief.system, brief.path, code), "", "What the index records:", "");
7004
+ }
6864
7005
  const layers = Object.entries(manifest.layers).sort((a, b) => b[1] - a[1] || a[0].localeCompare(b[0]));
6865
7006
  if (layers.length > 0) {
6866
7007
  const shown = layers.slice(0, MAX_LAYER_ROWS).map(([name, count]) => code(name) + " " + formatNumber(count));
@@ -6875,7 +7016,7 @@ function systemSection(manifest, code) {
6875
7016
  " A change here reaches the most call sites; read it before judging anything that uses it."
6876
7017
  );
6877
7018
  }
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);
7019
+ 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
7020
  out.push(
6880
7021
  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
7022
  );
@@ -6918,8 +7059,9 @@ function systemSection(manifest, code) {
6918
7059
  }
6919
7060
  return out;
6920
7061
  }
6921
- function historySection(history) {
7062
+ function historySection(history, brief, code) {
6922
7063
  const out = ["## What came before", ""];
7064
+ if (brief?.history !== void 0) out.push(...ownerBlock(brief.history, brief.path, code), "");
6923
7065
  if (history.length === 0) {
6924
7066
  out.push(
6925
7067
  "No history was readable: this is not a git checkout, or git could not be run. Nothing about",
@@ -6928,15 +7070,21 @@ function historySection(history) {
6928
7070
  return out;
6929
7071
  }
6930
7072
  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.",
7073
+ "The last " + formatNumber(history.length) + " " + (history.length === 1 ? "commit" : "commits") + ", newest first. Subjects and bodies are claims",
7074
+ "by whoever wrote them, not evidence - the code beside them is the evidence. If one of these",
7075
+ "fixes looks incomplete, quote the lines and say which call site it missed.",
6934
7076
  ""
6935
7077
  );
6936
- for (const subject of history) out.push("- " + subject);
7078
+ for (const commit of history) {
7079
+ out.push("- " + commit.subject);
7080
+ if (commit.body.length > 0) out.push(" " + commit.body);
7081
+ }
6937
7082
  return out;
6938
7083
  }
6939
- function barSection() {
7084
+ function barSection(brief, code) {
7085
+ if (brief?.bar !== void 0) {
7086
+ return ["## The bar", "", ...ownerBlock(brief.bar, brief.path, code), ""];
7087
+ }
6940
7088
  return [
6941
7089
  "## The bar",
6942
7090
  "",
@@ -6994,7 +7142,10 @@ function answerSection() {
6994
7142
  " the gap you filled by asking instead of guessing."
6995
7143
  ];
6996
7144
  }
6997
- function calibrationSection() {
7145
+ function calibrationSection(brief, code) {
7146
+ if (brief?.calibration !== void 0) {
7147
+ return ["## Calibration", "", ...ownerBlock(brief.calibration, brief.path, code), ""];
7148
+ }
6998
7149
  return [
6999
7150
  "## Calibration",
7000
7151
  "",
@@ -7009,6 +7160,84 @@ function calibrationSection() {
7009
7160
  "None of these throw. All are invisible in a summary."
7010
7161
  ];
7011
7162
  }
7163
+ function jobSection(task, hasHistory) {
7164
+ const out = ["## The job", ""];
7165
+ if (task === "audit") {
7166
+ out.push(
7167
+ "Find what is still wrong or will break. How you read the code is yours to decide - by",
7168
+ "subsystem, by data flow, by the invariants you derive yourself. What you owe in return is an",
7169
+ "honest account of what you covered and what you did not.",
7170
+ ""
7171
+ );
7172
+ if (hasHistory) {
7173
+ out.push(
7174
+ "Another pass of the same findings is worth nothing. This repository carries a record of",
7175
+ "what was already fixed, below. Verify that those fixes hold instead of rediscovering them,",
7176
+ "and treat a variant of one at a different call site as a new finding."
7177
+ );
7178
+ } else {
7179
+ out.push(
7180
+ "Another pass of the same findings is worth nothing, but no earlier round is readable here,",
7181
+ "so you cannot tell what has already been tried. Do not assume this is the first attempt."
7182
+ );
7183
+ }
7184
+ out.push(
7185
+ "",
7186
+ "If the task at the end asks for something narrower - explain a file, review a change, answer",
7187
+ "a question - that task wins. The standard and the coverage duty below still apply to it."
7188
+ );
7189
+ } else if (task === "review") {
7190
+ out.push(
7191
+ "Review the change or the area named in the task against this snapshot. Report what breaks,",
7192
+ "what the change claims but does not do, and what a reader would believe that the code does",
7193
+ "not support. Restating the diff is not a review; the standard and the coverage duty below",
7194
+ "still apply."
7195
+ );
7196
+ } else {
7197
+ out.push(
7198
+ "Explain how the part of the system named in the task works: the data flow, the boundaries",
7199
+ "and the invariants it depends on. Cite the lines. If the snapshot does not contain what you",
7200
+ "need, say which file you need rather than reconstructing it from the shape of the names."
7201
+ );
7202
+ }
7203
+ return out;
7204
+ }
7205
+ function stakesSection(brief, code) {
7206
+ if (brief?.stakes === void 0) return [];
7207
+ return ["## Stakes", "", ...ownerBlock(brief.stakes, brief.path, code), ""];
7208
+ }
7209
+ function whatThisIsSection(overview) {
7210
+ const body = [];
7211
+ if (overview.description !== void 0) {
7212
+ body.push("- Declared in `package.json`: " + overview.description);
7213
+ }
7214
+ if (overview.summary !== void 0) {
7215
+ body.push("- From the `README.md` first paragraph: " + overview.summary);
7216
+ }
7217
+ if (overview.releases.length > 0) {
7218
+ body.push("- Most recent releases: " + overview.releases.join("; ") + ".");
7219
+ }
7220
+ if (body.length === 0) return [];
7221
+ return [
7222
+ "## What this is",
7223
+ "",
7224
+ ...body,
7225
+ "",
7226
+ "Those are the project's own claims, not evidence about the code.",
7227
+ ""
7228
+ ];
7229
+ }
7230
+ function ownerNotesSection(brief, code) {
7231
+ if (brief === void 0 || brief.notes.length === 0) return [];
7232
+ const out = ["## Owner notes", ""];
7233
+ for (const note of brief.notes) {
7234
+ out.push("### " + note.heading, "", ...ownerBlock(note.body, brief.path, code), "");
7235
+ }
7236
+ return out;
7237
+ }
7238
+ function ownerBlock(text2, path18, code) {
7239
+ return ["> Written by the project owner in " + code(path18) + ", not generated.", "", text2];
7240
+ }
7012
7241
  function snapshotSection(manifest, code) {
7013
7242
  const out = ["## This snapshot", ""];
7014
7243
  out.push("- Fingerprint: " + code(manifest.fingerprint) + " - quote it verbatim in your answer.");
@@ -7107,7 +7336,8 @@ function deliverySection(manifest, partsWritten, slots) {
7107
7336
  );
7108
7337
  if (parts > 1) {
7109
7338
  out.push(
7110
- " Either raise `--max-part-bytes` to merge the parts, or set `--max-parts " + slots + "` and let the parts grow to the count instead."
7339
+ " Either raise `--max-part-bytes` to merge the parts, or set",
7340
+ " `--max-parts " + slots + "` and let the parts grow to the count instead."
7111
7341
  );
7112
7342
  }
7113
7343
  } else {
@@ -7364,7 +7594,7 @@ function resolveChangedScope(cwd, request) {
7364
7594
  const descriptions = [];
7365
7595
  if (request.changedSince !== void 0) {
7366
7596
  assertUsableRef(request.changedSince);
7367
- for (const path17 of gitPaths(cwd, [
7597
+ for (const path18 of gitPaths(cwd, [
7368
7598
  "diff",
7369
7599
  "--name-only",
7370
7600
  "-z",
@@ -7372,9 +7602,9 @@ function resolveChangedScope(cwd, request) {
7372
7602
  `${request.changedSince}...HEAD`,
7373
7603
  "--"
7374
7604
  ])) {
7375
- paths.add(path17);
7605
+ paths.add(path18);
7376
7606
  }
7377
- for (const path17 of gitPaths(cwd, [
7607
+ for (const path18 of gitPaths(cwd, [
7378
7608
  "diff",
7379
7609
  "--name-only",
7380
7610
  "-z",
@@ -7382,15 +7612,15 @@ function resolveChangedScope(cwd, request) {
7382
7612
  "HEAD",
7383
7613
  "--"
7384
7614
  ])) {
7385
- paths.add(path17);
7615
+ paths.add(path18);
7386
7616
  }
7387
- for (const path17 of gitPaths(cwd, ["ls-files", "--others", "--exclude-standard", "-z", "--"])) {
7388
- paths.add(path17);
7617
+ for (const path18 of gitPaths(cwd, ["ls-files", "--others", "--exclude-standard", "-z", "--"])) {
7618
+ paths.add(path18);
7389
7619
  }
7390
7620
  descriptions.push(`changed since ${request.changedSince}`);
7391
7621
  }
7392
7622
  if (request.staged === true) {
7393
- for (const path17 of gitPaths(cwd, [
7623
+ for (const path18 of gitPaths(cwd, [
7394
7624
  "diff",
7395
7625
  "--cached",
7396
7626
  "--name-only",
@@ -7398,10 +7628,10 @@ function resolveChangedScope(cwd, request) {
7398
7628
  "--relative",
7399
7629
  "--"
7400
7630
  ])) {
7401
- paths.add(path17);
7402
- stagedPaths.add(path17);
7631
+ paths.add(path18);
7632
+ stagedPaths.add(path18);
7403
7633
  }
7404
- for (const path17 of gitPaths(cwd, [
7634
+ for (const path18 of gitPaths(cwd, [
7405
7635
  "diff",
7406
7636
  "--cached",
7407
7637
  "--name-only",
@@ -7410,7 +7640,7 @@ function resolveChangedScope(cwd, request) {
7410
7640
  "--diff-filter=D",
7411
7641
  "--"
7412
7642
  ])) {
7413
- deletedPaths.add(path17);
7643
+ deletedPaths.add(path18);
7414
7644
  }
7415
7645
  descriptions.push("staged");
7416
7646
  }
@@ -7448,10 +7678,10 @@ var PYTHON_SUFFIXES = [".py", ".pyi", "/__init__.py", "/__init__.pyi"];
7448
7678
  var CASE_INSENSITIVE_FILESYSTEM = process.platform === "win32" || process.platform === "darwin";
7449
7679
  var TSCONFIG_CACHE = /* @__PURE__ */ new Map();
7450
7680
  function tsconfigPathsFor(cwd) {
7451
- const configPath = path16.join(cwd, "tsconfig.json");
7681
+ const configPath = path17.join(cwd, "tsconfig.json");
7452
7682
  let stats;
7453
7683
  try {
7454
- stats = fs15.statSync(configPath);
7684
+ stats = fs16.statSync(configPath);
7455
7685
  } catch (err) {
7456
7686
  if (err.code === "ENOENT") return null;
7457
7687
  return null;
@@ -7485,8 +7715,8 @@ function tsconfigPathsFor(cwd) {
7485
7715
  return value;
7486
7716
  }
7487
7717
  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;
7718
+ const relative11 = path17.relative(cwd, target).replace(/\\/g, "/");
7719
+ return relative11.length === 0 || !relative11.startsWith("..") && !path17.isAbsolute(relative11) ? relative11 : null;
7490
7720
  }
7491
7721
  function rememberFirst(map, key, value) {
7492
7722
  if (!map.has(key)) map.set(key, value);
@@ -7501,15 +7731,15 @@ function buildImportResolver(files, options = {}) {
7501
7731
  if (CASE_INSENSITIVE_FILESYSTEM) {
7502
7732
  rememberFirst(byPathFolded, relativePath.toLowerCase(), relativePath);
7503
7733
  }
7504
- const extension = path16.posix.extname(relativePath);
7734
+ const extension = path17.posix.extname(relativePath);
7505
7735
  if (!SOURCE_EXTENSIONS.has(extension)) return;
7506
7736
  const stem = relativePath.slice(0, -extension.length);
7507
7737
  rememberFirst(byStem, stem, relativePath);
7508
7738
  if (CASE_INSENSITIVE_FILESYSTEM) {
7509
7739
  rememberFirst(byStemFolded, stem.toLowerCase(), relativePath);
7510
7740
  }
7511
- if (path16.posix.basename(stem) === "index") {
7512
- const directory = path16.posix.dirname(stem);
7741
+ if (path17.posix.basename(stem) === "index") {
7742
+ const directory = path17.posix.dirname(stem);
7513
7743
  rememberFirst(byStem, directory, relativePath);
7514
7744
  if (CASE_INSENSITIVE_FILESYSTEM) {
7515
7745
  rememberFirst(byStemFolded, directory.toLowerCase(), relativePath);
@@ -7525,7 +7755,7 @@ function buildImportResolver(files, options = {}) {
7525
7755
  return { byPath, byPathFolded, byStem, byStemFolded, tsconfig: options.tsconfig ?? null };
7526
7756
  }
7527
7757
  function resolveSpecifier(fromFile, specifier, resolver) {
7528
- const extension = path16.posix.extname(fromFile).toLowerCase();
7758
+ const extension = path17.posix.extname(fromFile).toLowerCase();
7529
7759
  const exact = (key) => resolver.byPath.get(key) ?? (CASE_INSENSITIVE_FILESYSTEM ? resolver.byPathFolded.get(key.toLowerCase()) : void 0) ?? null;
7530
7760
  const firstOf = (candidates) => {
7531
7761
  for (const candidate of candidates) {
@@ -7548,34 +7778,34 @@ function resolveSpecifier(fromFile, specifier, resolver) {
7548
7778
  if (PYTHON_EXTENSIONS.has(extension) && specifier.startsWith(".")) {
7549
7779
  const dots = /^\.+/.exec(specifier)?.[0].length ?? 0;
7550
7780
  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;
7781
+ let base = path17.posix.dirname(fromFile);
7782
+ for (let up = 1; up < dots; up += 1) base = path17.posix.dirname(base);
7783
+ const joined2 = rest ? path17.posix.normalize(path17.posix.join(base, rest)) : base;
7554
7784
  return firstOf([joined2, ...PYTHON_SUFFIXES.map((suffix) => `${joined2}${suffix}`)]);
7555
7785
  }
7556
7786
  if (RUBY_EXTENSIONS.has(extension) && specifier.startsWith("./")) {
7557
- const joined2 = path16.posix.normalize(
7558
- path16.posix.join(path16.posix.dirname(fromFile), specifier)
7787
+ const joined2 = path17.posix.normalize(
7788
+ path17.posix.join(path17.posix.dirname(fromFile), specifier)
7559
7789
  );
7560
7790
  return firstOf([`${joined2}.rb`, joined2]);
7561
7791
  }
7562
7792
  if (C_EXTENSIONS.has(extension) && specifier.startsWith("./")) {
7563
- const joined2 = path16.posix.normalize(
7564
- path16.posix.join(path16.posix.dirname(fromFile), specifier)
7793
+ const joined2 = path17.posix.normalize(
7794
+ path17.posix.join(path17.posix.dirname(fromFile), specifier)
7565
7795
  );
7566
7796
  return exact(joined2);
7567
7797
  }
7568
7798
  if (extension === ".dart" && !specifier.includes(":")) {
7569
- const joined2 = path16.posix.normalize(
7570
- path16.posix.join(path16.posix.dirname(fromFile), specifier)
7799
+ const joined2 = path17.posix.normalize(
7800
+ path17.posix.join(path17.posix.dirname(fromFile), specifier)
7571
7801
  );
7572
7802
  return firstOf([joined2, `${joined2}.dart`]);
7573
7803
  }
7574
7804
  if (!RELATIVE_SPECIFIER.test(specifier)) {
7575
7805
  return resolveTsconfigSpecifier(specifier, resolver, lookupPath);
7576
7806
  }
7577
- const joined = path16.posix.normalize(
7578
- path16.posix.join(path16.posix.dirname(fromFile), specifier)
7807
+ const joined = path17.posix.normalize(
7808
+ path17.posix.join(path17.posix.dirname(fromFile), specifier)
7579
7809
  );
7580
7810
  return lookupPath(joined);
7581
7811
  }
@@ -7599,13 +7829,13 @@ function resolveTsconfigSpecifier(specifier, resolver, lookupPath) {
7599
7829
  if (captured === null) continue;
7600
7830
  for (const target of rule.targets) {
7601
7831
  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));
7832
+ const base = config.baseUrl === null ? substituted : path17.posix.join(config.baseUrl, substituted);
7833
+ const hit = lookupPath(path17.posix.normalize(base));
7604
7834
  if (hit) return hit;
7605
7835
  }
7606
7836
  }
7607
7837
  if (config.baseUrl !== null) {
7608
- return lookupPath(path16.posix.normalize(path16.posix.join(config.baseUrl, specifier)));
7838
+ return lookupPath(path17.posix.normalize(path17.posix.join(config.baseUrl, specifier)));
7609
7839
  }
7610
7840
  return null;
7611
7841
  }
@@ -7616,6 +7846,64 @@ function importsChangedFile(importerPath, imports, changedPaths, resolver) {
7616
7846
  }
7617
7847
  return false;
7618
7848
  }
7849
+ var SUMMARY_LIMIT = 400;
7850
+ var MAX_RELEASES = 2;
7851
+ function readProjectOverview(cwd) {
7852
+ return {
7853
+ ...readDescription(cwd),
7854
+ ...readSummary(cwd),
7855
+ releases: readReleases(cwd)
7856
+ };
7857
+ }
7858
+ function readText(file) {
7859
+ try {
7860
+ return fs16.readFileSync(file, "utf8");
7861
+ } catch {
7862
+ return null;
7863
+ }
7864
+ }
7865
+ function readDescription(cwd) {
7866
+ const raw = readText(path17.join(cwd, "package.json"));
7867
+ if (raw === null) return {};
7868
+ try {
7869
+ const parsed = JSON.parse(stripJsonComments(raw));
7870
+ return typeof parsed.description === "string" && parsed.description.trim().length > 0 ? { description: parsed.description.trim() } : {};
7871
+ } catch {
7872
+ return {};
7873
+ }
7874
+ }
7875
+ function readSummary(cwd) {
7876
+ const raw = readText(path17.join(cwd, "README.md"));
7877
+ if (raw === null) return {};
7878
+ const text2 = raw.replace(/<h[1-6][^>]*>[\s\S]*?<\/h[1-6]>/gi, "\n").replace(/<\/(p|div|section|header|footer|li)>/gi, "\n").replace(/<br\s*\/?>/gi, " ").replace(/<[^>]*>/g, " ").replace(/&nbsp;/g, " ").replace(/&amp;/g, "&").replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&quot;/g, '"').replace(/&#39;/g, "'");
7879
+ const paragraph = [];
7880
+ for (const line of text2.split(/\r?\n/)) {
7881
+ const trimmed = line.trim();
7882
+ if (paragraph.length === 0) {
7883
+ if (trimmed.length === 0) continue;
7884
+ if (/^#/.test(trimmed) || /^!\[/.test(trimmed) || /^[-*|]/.test(trimmed)) continue;
7885
+ if (/^\[[^\]]+\]:/.test(trimmed)) continue;
7886
+ } else if (trimmed.length === 0 || /^#/.test(trimmed)) {
7887
+ break;
7888
+ }
7889
+ paragraph.push(trimmed);
7890
+ }
7891
+ const summary = paragraph.join(" ").replace(/\s+/g, " ").trim();
7892
+ if (summary.length === 0) return {};
7893
+ return { summary: truncate(summary, SUMMARY_LIMIT) };
7894
+ }
7895
+ function truncate(text2, limit) {
7896
+ if (text2.length <= limit) return text2;
7897
+ const window = text2.slice(0, limit);
7898
+ const space = window.lastIndexOf(" ");
7899
+ return (space > limit / 2 ? window.slice(0, space) : window).trim() + "\u2026";
7900
+ }
7901
+ function readReleases(cwd) {
7902
+ const raw = readText(path17.join(cwd, "CHANGELOG.md"));
7903
+ if (raw === null) return [];
7904
+ const headings = raw.split(/\r?\n/).map((line) => /^##\s+(.+?)\s*$/.exec(line)?.[1]?.trim()).filter((heading) => heading !== void 0 && /^v?\d+\.\d+/.test(heading));
7905
+ return headings.slice(0, MAX_RELEASES);
7906
+ }
7619
7907
  var LANGUAGE_BY_EXTENSION = {
7620
7908
  ".ts": "typescript",
7621
7909
  ".mts": "typescript",
@@ -7673,10 +7961,10 @@ var LANGUAGE_BY_BASENAME = {
7673
7961
  };
7674
7962
  function detectLanguage(filePath) {
7675
7963
  const normalized = filePath.replace(/\\/g, "/");
7676
- const base = path16.posix.basename(normalized);
7964
+ const base = path17.posix.basename(normalized);
7677
7965
  if (LANGUAGE_BY_BASENAME[base]) return LANGUAGE_BY_BASENAME[base];
7678
7966
  if (base === ".env" || base.startsWith(".env.")) return "dotenv";
7679
- const ext = path16.posix.extname(base).toLowerCase();
7967
+ const ext = path17.posix.extname(base).toLowerCase();
7680
7968
  return LANGUAGE_BY_EXTENSION[ext] ?? "text";
7681
7969
  }
7682
7970
  function maskedPath(value, secretRules) {
@@ -7684,33 +7972,33 @@ function maskedPath(value, secretRules) {
7684
7972
  }
7685
7973
  function confineToDirectory(directory, filename) {
7686
7974
  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);
7975
+ if (path17.isAbsolute(filename)) return null;
7976
+ const base = path17.resolve(directory);
7977
+ const resolved = path17.resolve(base, filename);
7690
7978
  const caseInsensitive = process.platform === "win32" || process.platform === "darwin";
7691
- const prefix = caseInsensitive ? `${base}${path16.sep}`.toLowerCase() : `${base}${path16.sep}`;
7979
+ const prefix = caseInsensitive ? `${base}${path17.sep}`.toLowerCase() : `${base}${path17.sep}`;
7692
7980
  const candidate = caseInsensitive ? resolved.toLowerCase() : resolved;
7693
7981
  return candidate.startsWith(prefix) ? resolved : null;
7694
7982
  }
7695
7983
  function findStagingDirectory(config) {
7696
- const tmpDir = path16.resolve(config.cwd, config.tmpDir);
7984
+ const tmpDir = path17.resolve(config.cwd, config.tmpDir);
7697
7985
  let entries;
7698
7986
  try {
7699
- entries = fs15.readdirSync(tmpDir);
7987
+ entries = fs16.readdirSync(tmpDir);
7700
7988
  } catch {
7701
7989
  return null;
7702
7990
  }
7703
7991
  const runs = entries.filter((name) => name.startsWith("run-")).sort();
7704
7992
  const newest = runs[runs.length - 1];
7705
- return newest ? path16.join(tmpDir, newest) : null;
7993
+ return newest ? path17.join(tmpDir, newest) : null;
7706
7994
  }
7707
7995
  function describeMissingManifest(config, manifestPath) {
7708
- const outDir = path16.resolve(config.cwd, config.outDir);
7709
- const markerPath = path16.join(outDir, ".codebase-snapshot");
7996
+ const outDir = path17.resolve(config.cwd, config.outDir);
7997
+ const markerPath = path17.join(outDir, ".codebase-snapshot");
7710
7998
  let marker2 = null;
7711
7999
  try {
7712
- if (fs15.existsSync(markerPath)) {
7713
- const parsed = JSON.parse(fs15.readFileSync(markerPath, "utf8"));
8000
+ if (fs16.existsSync(markerPath)) {
8001
+ const parsed = JSON.parse(fs16.readFileSync(markerPath, "utf8"));
7714
8002
  if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
7715
8003
  marker2 = parsed;
7716
8004
  }
@@ -7745,13 +8033,13 @@ function sha256Hex(buffer) {
7745
8033
  return crypto2.createHash("sha256").update(buffer).digest("hex");
7746
8034
  }
7747
8035
  function wouldNowBeIncluded(cwd, relativePath) {
7748
- const absolutePath = path16.join(cwd, relativePath);
8036
+ const absolutePath = path17.join(cwd, relativePath);
7749
8037
  try {
7750
- const stats = fs15.statSync(absolutePath);
8038
+ const stats = fs16.statSync(absolutePath);
7751
8039
  if (!stats.isFile()) return false;
7752
8040
  if (isBinaryExtension(absolutePath)) return false;
7753
8041
  if (stats.size > BINARY_SCAN_BYTES && isBinaryFile(absolutePath)) return false;
7754
- return !decodeText(fs15.readFileSync(absolutePath)).binary;
8042
+ return !decodeText(fs16.readFileSync(absolutePath)).binary;
7755
8043
  } catch {
7756
8044
  return false;
7757
8045
  }
@@ -7763,7 +8051,7 @@ var TRUNCATION_REASONS = /* @__PURE__ */ new Set([
7763
8051
  ]);
7764
8052
  function isConfinedRelative(value) {
7765
8053
  if (value.length === 0 || value.includes("\0") || value.includes("\\")) return false;
7766
- if (path16.isAbsolute(value)) return false;
8054
+ if (path17.isAbsolute(value)) return false;
7767
8055
  return !value.split("/").includes("..");
7768
8056
  }
7769
8057
  function describeManifestShapeProblem(value) {
@@ -7931,7 +8219,7 @@ function describeManifestShapeProblem(value) {
7931
8219
  if (typeof filename !== "string" || filename.trim() === "") {
7932
8220
  return 'a "parts" entry has no "filename"';
7933
8221
  }
7934
- if (filename.includes("/") || filename.includes("\\") || filename.includes("\0") || filename === "." || filename === ".." || path16.isAbsolute(filename)) {
8222
+ if (filename.includes("/") || filename.includes("\\") || filename.includes("\0") || filename === "." || filename === ".." || path17.isAbsolute(filename)) {
7935
8223
  return 'a "parts" entry "filename" must be a bare filename inside parts/';
7936
8224
  }
7937
8225
  if (currentSchema) {
@@ -7957,8 +8245,8 @@ function describeManifestShapeProblem(value) {
7957
8245
  function validateSnapshot(configInput) {
7958
8246
  assertUsableConfigInput(configInput);
7959
8247
  const config = isResolvedConfig(configInput) ? normalizeResolvedConfig(configInput) : resolveConfig(configInput);
7960
- const manifestPath = path16.resolve(config.cwd, config.outDir, "manifest.json");
7961
- if (!fs15.existsSync(manifestPath)) {
8248
+ const manifestPath = path17.resolve(config.cwd, config.outDir, "manifest.json");
8249
+ if (!fs16.existsSync(manifestPath)) {
7962
8250
  return {
7963
8251
  valid: false,
7964
8252
  manifestPresent: false,
@@ -7969,7 +8257,7 @@ function validateSnapshot(configInput) {
7969
8257
  }
7970
8258
  let manifest;
7971
8259
  try {
7972
- manifest = JSON.parse(fs15.readFileSync(manifestPath, "utf8"));
8260
+ manifest = JSON.parse(fs16.readFileSync(manifestPath, "utf8"));
7973
8261
  } catch (err) {
7974
8262
  return {
7975
8263
  valid: false,
@@ -7991,7 +8279,7 @@ function validateSnapshot(configInput) {
7991
8279
  }
7992
8280
  const drift = emptyDrift();
7993
8281
  const warnings = [];
7994
- const snapshotDir = path16.resolve(config.cwd, config.outDir);
8282
+ const snapshotDir = path17.resolve(config.cwd, config.outDir);
7995
8283
  const unreadableSkips = manifest.skipped.filter(
7996
8284
  (entry) => entry.reason === "missing" || entry.reason === "read-error"
7997
8285
  );
@@ -8094,7 +8382,7 @@ function validateSnapshot(configInput) {
8094
8382
  );
8095
8383
  return importsChangedFile(
8096
8384
  diskFile,
8097
- importsOfFile(diskFile, path16.join(config.cwd, diskFile)),
8385
+ importsOfFile(diskFile, path17.join(config.cwd, diskFile)),
8098
8386
  unchangedScope,
8099
8387
  dependentResolver
8100
8388
  );
@@ -8112,7 +8400,7 @@ function validateSnapshot(configInput) {
8112
8400
  // own output directory as a set of files missing from the snapshot, so a correct
8113
8401
  // snapshot was reported as drifting.
8114
8402
  toolOwnedPaths: [config.outDir, config.tmpDir].map(
8115
- (directory) => path16.relative(config.cwd, path16.resolve(config.cwd, directory)).replace(/\\/g, "/")
8403
+ (directory) => path17.relative(config.cwd, path17.resolve(config.cwd, directory)).replace(/\\/g, "/")
8116
8404
  ).filter((relative11) => relative11.length > 0 && !relative11.startsWith(".."))
8117
8405
  });
8118
8406
  for (const diskFile of collection.files) {
@@ -8138,7 +8426,7 @@ function validateSnapshot(configInput) {
8138
8426
  }
8139
8427
  let diskHash;
8140
8428
  try {
8141
- diskHash = sha256Hex(fs15.readFileSync(path16.join(config.cwd, diskFile)));
8429
+ diskHash = sha256Hex(fs16.readFileSync(path17.join(config.cwd, diskFile)));
8142
8430
  } catch (err) {
8143
8431
  if (err.code === "ENOENT") {
8144
8432
  drift.missingOnDisk.push(diskFile);
@@ -8162,7 +8450,7 @@ function validateSnapshot(configInput) {
8162
8450
  }
8163
8451
  let statFailure = null;
8164
8452
  try {
8165
- fs15.statSync(confined);
8453
+ fs16.statSync(confined);
8166
8454
  } catch (err) {
8167
8455
  statFailure = err;
8168
8456
  }
@@ -8182,7 +8470,7 @@ function validateSnapshot(configInput) {
8182
8470
  ...Object.values(config.budgets.byLayer)
8183
8471
  );
8184
8472
  const partNames = /* @__PURE__ */ new Set();
8185
- const partsDir = path16.join(snapshotDir, "parts");
8473
+ const partsDir = path17.join(snapshotDir, "parts");
8186
8474
  for (const part of manifest.parts) {
8187
8475
  if (!part || typeof part.filename !== "string") continue;
8188
8476
  partNames.add(part.filename);
@@ -8197,7 +8485,7 @@ function validateSnapshot(configInput) {
8197
8485
  }
8198
8486
  let buffer;
8199
8487
  try {
8200
- buffer = fs15.readFileSync(partPath);
8488
+ buffer = fs16.readFileSync(partPath);
8201
8489
  } catch {
8202
8490
  drift.partIssues.push({ part: part.filename, issue: "missing from snapshot/parts" });
8203
8491
  continue;
@@ -8553,11 +8841,11 @@ function validateSnapshot(configInput) {
8553
8841
  ];
8554
8842
  for (const [key, artifact] of declaredArtifacts) {
8555
8843
  if (!artifact) continue;
8556
- const artifactPath = path16.join(snapshotDir, ...key.split("/"));
8844
+ const artifactPath = path17.join(snapshotDir, ...key.split("/"));
8557
8845
  let buffer;
8558
8846
  try {
8559
- if (!fs15.statSync(artifactPath).isFile()) throw new Error("not a regular file");
8560
- buffer = fs15.readFileSync(artifactPath);
8847
+ if (!fs16.statSync(artifactPath).isFile()) throw new Error("not a regular file");
8848
+ buffer = fs16.readFileSync(artifactPath);
8561
8849
  } catch {
8562
8850
  drift.partIssues.push({ part: key, issue: "declared artifact is missing" });
8563
8851
  continue;
@@ -8570,9 +8858,9 @@ function validateSnapshot(configInput) {
8570
8858
  for (const match of buffer.toString("utf8").matchAll(/\]\(([^)\s]+)\)/g)) {
8571
8859
  const target = match[1].split("#")[0];
8572
8860
  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)) {
8861
+ const resolved = path17.resolve(snapshotDir, "reports", target);
8862
+ const relative11 = path17.relative(snapshotDir, resolved);
8863
+ if (relative11.startsWith("..") || path17.isAbsolute(relative11) || !fs16.existsSync(resolved)) {
8576
8864
  drift.partIssues.push({
8577
8865
  part: key,
8578
8866
  issue: `links to ${maskedPath(target, config.secretRules)}, which does not exist in the snapshot`
@@ -8585,7 +8873,7 @@ function validateSnapshot(configInput) {
8585
8873
  if (sarifArtifact) {
8586
8874
  const sarifKey = "reports/audit.sarif";
8587
8875
  try {
8588
- const buffer = fs15.readFileSync(path16.join(snapshotDir, "reports", "audit.sarif"));
8876
+ const buffer = fs16.readFileSync(path17.join(snapshotDir, "reports", "audit.sarif"));
8589
8877
  if (sha256Hex(buffer) !== sarifArtifact.sha256 || buffer.length !== sarifArtifact.byteSize) {
8590
8878
  drift.partIssues.push({ part: sarifKey, issue: "artifact does not match its recorded digest" });
8591
8879
  }
@@ -8703,17 +8991,17 @@ function isNewer(candidate, current) {
8703
8991
  }
8704
8992
  function cacheDirectory(env = process.env, platform = process.platform) {
8705
8993
  if (platform === "win32") {
8706
- const base2 = env.LOCALAPPDATA ?? path16.join(os.homedir(), "AppData", "Local");
8707
- return path16.join(base2, "codebase-snapshot");
8994
+ const base2 = env.LOCALAPPDATA ?? path17.join(os.homedir(), "AppData", "Local");
8995
+ return path17.join(base2, "codebase-snapshot");
8708
8996
  }
8709
8997
  if (platform === "darwin") {
8710
- return path16.join(os.homedir(), "Library", "Caches", "codebase-snapshot");
8998
+ return path17.join(os.homedir(), "Library", "Caches", "codebase-snapshot");
8711
8999
  }
8712
- const base = env.XDG_CACHE_HOME ?? path16.join(os.homedir(), ".cache");
8713
- return path16.join(base, "codebase-snapshot");
9000
+ const base = env.XDG_CACHE_HOME ?? path17.join(os.homedir(), ".cache");
9001
+ return path17.join(base, "codebase-snapshot");
8714
9002
  }
8715
9003
  function cacheFilePath(env = process.env) {
8716
- return path16.join(cacheDirectory(env), "update-check.json");
9004
+ return path17.join(cacheDirectory(env), "update-check.json");
8717
9005
  }
8718
9006
  function shouldCheck(argv, env) {
8719
9007
  const disabled = ["1", "true", "yes"].includes(
@@ -8743,7 +9031,7 @@ function shouldCheck(argv, env) {
8743
9031
  function readCache(file) {
8744
9032
  let raw;
8745
9033
  try {
8746
- raw = fs15.readFileSync(file, "utf8");
9034
+ raw = fs16.readFileSync(file, "utf8");
8747
9035
  } catch {
8748
9036
  return null;
8749
9037
  }
@@ -8760,8 +9048,8 @@ function readCache(file) {
8760
9048
  }
8761
9049
  function writeCache(file, entry) {
8762
9050
  try {
8763
- fs15.mkdirSync(path16.dirname(file), { recursive: true });
8764
- fs15.writeFileSync(file, `${JSON.stringify(entry)}
9051
+ fs16.mkdirSync(path17.dirname(file), { recursive: true });
9052
+ fs16.writeFileSync(file, `${JSON.stringify(entry)}
8765
9053
  `, "utf8");
8766
9054
  } catch {
8767
9055
  }
@@ -8860,13 +9148,13 @@ function describeMatcher(matcher) {
8860
9148
  return String(matcher);
8861
9149
  }
8862
9150
  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)) {
9151
+ const resolvedCwd = path17.resolve(cwd);
9152
+ const absolute = path17.resolve(resolvedCwd, target);
9153
+ const relative11 = path17.relative(resolvedCwd, absolute);
9154
+ if (relative11 === "" || relative11 === ".." || relative11.startsWith(`..${path17.sep}`) || path17.isAbsolute(relative11)) {
8867
9155
  return { relative: target.replace(/\\/g, "/"), outsideRoot: true };
8868
9156
  }
8869
- return { relative: relative11.split(path16.sep).join("/"), outsideRoot: false };
9157
+ return { relative: relative11.split(path17.sep).join("/"), outsideRoot: false };
8870
9158
  }
8871
9159
  function findRuleMatch(rules, relativePath) {
8872
9160
  return rules.find(
@@ -8885,9 +9173,9 @@ function findRecordedAncestor(skipped, relative11, maskedPath2) {
8885
9173
  return nearest;
8886
9174
  }
8887
9175
  function readManifest2(config) {
8888
- const manifestPath = path16.resolve(config.cwd, config.outDir, "manifest.json");
9176
+ const manifestPath = path17.resolve(config.cwd, config.outDir, "manifest.json");
8889
9177
  try {
8890
- return JSON.parse(fs15.readFileSync(manifestPath, "utf8"));
9178
+ return JSON.parse(fs16.readFileSync(manifestPath, "utf8"));
8891
9179
  } catch {
8892
9180
  return null;
8893
9181
  }
@@ -8905,10 +9193,10 @@ function explainPath(config, target) {
8905
9193
  detail: "path resolves outside the configured repository root and was not inspected"
8906
9194
  };
8907
9195
  }
8908
- const absolute = path16.join(config.cwd, relative11);
9196
+ const absolute = path17.join(config.cwd, relative11);
8909
9197
  const result = {
8910
9198
  path: maskedPath2,
8911
- exists: fs15.existsSync(absolute),
9199
+ exists: fs16.existsSync(absolute),
8912
9200
  included: false
8913
9201
  };
8914
9202
  const collection = collectFiles(config.cwd, {
@@ -8922,7 +9210,7 @@ function explainPath(config, target) {
8922
9210
  // Same exclusion `generate` applies, so `explain` never says "not-discovered" about a file
8923
9211
  // that is only missing because the walker dropped the tool's own output directory.
8924
9212
  toolOwnedPaths: [config.outDir, config.tmpDir].map(
8925
- (directory) => path16.relative(config.cwd, path16.resolve(config.cwd, directory)).replace(/\\/g, "/")
9213
+ (directory) => path17.relative(config.cwd, path17.resolve(config.cwd, directory)).replace(/\\/g, "/")
8926
9214
  ).filter((relative12) => relative12.length > 0 && !relative12.startsWith(".."))
8927
9215
  });
8928
9216
  if (!collection.files.includes(relative11)) {
@@ -8987,7 +9275,7 @@ function explainPath(config, target) {
8987
9275
  }
8988
9276
  let sizeOnDisk = null;
8989
9277
  try {
8990
- sizeOnDisk = fs15.statSync(absolute).size;
9278
+ sizeOnDisk = fs16.statSync(absolute).size;
8991
9279
  } catch {
8992
9280
  sizeOnDisk = null;
8993
9281
  }
@@ -8997,10 +9285,10 @@ function explainPath(config, target) {
8997
9285
  result.detail = "binary content; generate skips it and records `binary` in manifest.skipped[]";
8998
9286
  return result;
8999
9287
  }
9000
- if (fs15.existsSync(absolute) && fs15.statSync(absolute).isFile()) {
9288
+ if (fs16.existsSync(absolute) && fs16.statSync(absolute).isFile()) {
9001
9289
  let buffer;
9002
9290
  try {
9003
- buffer = fs15.readFileSync(absolute);
9291
+ buffer = fs16.readFileSync(absolute);
9004
9292
  } catch (err) {
9005
9293
  result.included = false;
9006
9294
  result.reason = "read-error";
@@ -9290,14 +9578,14 @@ function compareManifests(before, after, secretRules) {
9290
9578
  function loadManifest(target) {
9291
9579
  let isDirectory;
9292
9580
  try {
9293
- isDirectory = fs15.statSync(target).isDirectory();
9581
+ isDirectory = fs16.statSync(target).isDirectory();
9294
9582
  } catch {
9295
9583
  throw new Error(`No snapshot found at ${target}: the path does not exist.`);
9296
9584
  }
9297
- const manifestPath = isDirectory ? path16.join(target, "manifest.json") : target;
9585
+ const manifestPath = isDirectory ? path17.join(target, "manifest.json") : target;
9298
9586
  let raw;
9299
9587
  try {
9300
- raw = fs15.readFileSync(manifestPath, "utf8");
9588
+ raw = fs16.readFileSync(manifestPath, "utf8");
9301
9589
  } catch {
9302
9590
  throw new Error(`Could not read a manifest at ${manifestPath}.`);
9303
9591
  }
@@ -9399,15 +9687,15 @@ function canonicalIgnorePattern(line) {
9399
9687
  function appendGitignoreEntries(cwd, entries) {
9400
9688
  const wanted = [...new Set(entries)].filter((entry) => entry.trim().length > 0);
9401
9689
  if (wanted.length === 0) return { added: [], note: null };
9402
- const ignorePath = path16.join(cwd, ".gitignore");
9690
+ const ignorePath = path17.join(cwd, ".gitignore");
9403
9691
  const manual = `Add ${wanted.map((entry) => `"${entry}"`).join(" and ")} to your .gitignore yourself.`;
9404
9692
  let decoded = { text: "", bom: Buffer.alloc(0), encoding: "utf8" };
9405
9693
  try {
9406
- if (fs15.existsSync(ignorePath)) {
9407
- if (fs15.statSync(ignorePath).isDirectory()) {
9694
+ if (fs16.existsSync(ignorePath)) {
9695
+ if (fs16.statSync(ignorePath).isDirectory()) {
9408
9696
  return { added: [], note: `${ignorePath} is a directory, so it was not updated. ${manual}` };
9409
9697
  }
9410
- const read = decodeGitignore(fs15.readFileSync(ignorePath));
9698
+ const read = decodeGitignore(fs16.readFileSync(ignorePath));
9411
9699
  if (read === null) {
9412
9700
  return {
9413
9701
  added: [],
@@ -9429,7 +9717,7 @@ function appendGitignoreEntries(cwd, entries) {
9429
9717
  const newline = existing.includes("\r\n") ? "\r\n" : "\n";
9430
9718
  const prefix = existing.length === 0 || existing.endsWith("\n") ? "" : newline;
9431
9719
  try {
9432
- fs15.writeFileSync(
9720
+ fs16.writeFileSync(
9433
9721
  ignorePath,
9434
9722
  encodeGitignore(decoded, `${existing}${prefix}${added.join(newline)}${newline}`)
9435
9723
  );
@@ -9439,7 +9727,7 @@ function appendGitignoreEntries(cwd, entries) {
9439
9727
  return { added, note: null };
9440
9728
  }
9441
9729
  function gitignorePath(cwd, filePath) {
9442
- return path16.relative(cwd, filePath).split(path16.sep).join("/");
9730
+ return path17.relative(cwd, filePath).split(path17.sep).join("/");
9443
9731
  }
9444
9732
 
9445
9733
  // src/wizard/config-template.ts
@@ -9595,6 +9883,10 @@ function renderConfig(answers) {
9595
9883
  // Experimental: grow the per-part budget until the snapshot fits this many parts, instead of
9596
9884
  // adding a part as the code grows. The plan in PROMPT.md becomes a fixed-length attachment list.
9597
9885
  // maxParts: 10,
9886
+ // The owner-written half of PROMPT.md: Stakes, The system, What came before, The bar, Calibration.
9887
+ // brief: "docs/brief.md",
9888
+ // Which job the brief is written for: audit, review or explain.
9889
+ // promptTask: "audit",
9598
9890
  // afterGenerate: (manifest) => { /* write your own artifact */ }
9599
9891
  hooks: {},
9600
9892
  };
@@ -9989,7 +10281,7 @@ function parsePackageJson(raw) {
9989
10281
  }
9990
10282
  function readPackageJson(cwd) {
9991
10283
  try {
9992
- return parsePackageJson(fs15.readFileSync(path16.join(cwd, "package.json"), "utf8"));
10284
+ return parsePackageJson(fs16.readFileSync(path17.join(cwd, "package.json"), "utf8"));
9993
10285
  } catch {
9994
10286
  return null;
9995
10287
  }
@@ -10026,7 +10318,7 @@ function artifactAnswers(options) {
10026
10318
  }
10027
10319
  function topLevelDirs(cwd) {
10028
10320
  try {
10029
- return fs15.readdirSync(cwd, { withFileTypes: true }).filter((entry) => entry.isDirectory() && !entry.name.startsWith(".") && entry.name !== "node_modules").map((entry) => entry.name).sort();
10321
+ return fs16.readdirSync(cwd, { withFileTypes: true }).filter((entry) => entry.isDirectory() && !entry.name.startsWith(".") && entry.name !== "node_modules").map((entry) => entry.name).sort();
10030
10322
  } catch {
10031
10323
  return [];
10032
10324
  }
@@ -10041,7 +10333,7 @@ function writeFileOrExplain(target, content) {
10041
10333
  try {
10042
10334
  let stats = null;
10043
10335
  try {
10044
- stats = fs15.lstatSync(target);
10336
+ stats = fs16.lstatSync(target);
10045
10337
  } catch {
10046
10338
  stats = null;
10047
10339
  }
@@ -10056,12 +10348,12 @@ function writeFileOrExplain(target, content) {
10056
10348
  );
10057
10349
  }
10058
10350
  const temporary = `${target}.tmp-${process.pid}-${Date.now()}`;
10059
- fs15.writeFileSync(temporary, content, { encoding: "utf8", flag: "wx" });
10351
+ fs16.writeFileSync(temporary, content, { encoding: "utf8", flag: "wx" });
10060
10352
  try {
10061
- fs15.renameSync(temporary, target);
10353
+ fs16.renameSync(temporary, target);
10062
10354
  } catch (err) {
10063
10355
  try {
10064
- fs15.unlinkSync(temporary);
10356
+ fs16.unlinkSync(temporary);
10065
10357
  } catch {
10066
10358
  }
10067
10359
  throw err;
@@ -10109,19 +10401,19 @@ function serializePackageJson(raw, value) {
10109
10401
  return `${bom}${text2}${raw.endsWith("\n") ? crlf ? "\r\n" : "\n" : ""}`;
10110
10402
  }
10111
10403
  function updatePackageJson(cwd, notes) {
10112
- const packagePath = path16.join(cwd, "package.json");
10404
+ const packagePath = path17.join(cwd, "package.json");
10113
10405
  const unchanged = {
10114
10406
  scripts: [],
10115
10407
  dependency: { name: GENERATOR_NAME, range: null, added: false }
10116
10408
  };
10117
- if (!fs15.existsSync(packagePath)) {
10409
+ if (!fs16.existsSync(packagePath)) {
10118
10410
  notes.push("No package.json found, so npm scripts and the devDependency were not added.");
10119
10411
  return unchanged;
10120
10412
  }
10121
10413
  let raw;
10122
10414
  let parsed;
10123
10415
  try {
10124
- raw = fs15.readFileSync(packagePath, "utf8");
10416
+ raw = fs16.readFileSync(packagePath, "utf8");
10125
10417
  parsed = parsePackageJson(raw);
10126
10418
  } catch {
10127
10419
  notes.push("Could not parse package.json; npm scripts and the devDependency were not added.");
@@ -10196,8 +10488,8 @@ function gitignoreEntriesFor(cwd, outDir, tmpDir) {
10196
10488
  const entries = [];
10197
10489
  for (const directory of [outDir, tmpDir]) {
10198
10490
  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)) {
10491
+ const relative11 = path17.relative(cwd, path17.resolve(cwd, directory)).replace(/\\/g, "/");
10492
+ if (relative11 === "" || relative11 === "." || relative11.startsWith("..") || path17.isAbsolute(relative11)) {
10201
10493
  continue;
10202
10494
  }
10203
10495
  entries.push(`/${relative11}/`);
@@ -10449,7 +10741,7 @@ async function runInit(options) {
10449
10741
  const configText = renderConfig(answers);
10450
10742
  const preferredName = chooseConfigFileName(options.cwd);
10451
10743
  const presentConfigs = CONFIG_CANDIDATES.filter(
10452
- (name) => fs15.existsSync(path16.join(options.cwd, name))
10744
+ (name) => fs16.existsSync(path17.join(options.cwd, name))
10453
10745
  );
10454
10746
  const present = presentConfigs[0] ?? null;
10455
10747
  if (presentConfigs.length > 1) {
@@ -10458,7 +10750,7 @@ async function runInit(options) {
10458
10750
  );
10459
10751
  }
10460
10752
  const configName = present !== null && options.force ? present : preferredName;
10461
- const configPath = path16.join(options.cwd, configName);
10753
+ const configPath = path17.join(options.cwd, configName);
10462
10754
  const reused = present !== null && options.force !== true && options.reuseConfig === true;
10463
10755
  if (reused) notes.push(`Kept the existing ${present} instead of writing a new one.`);
10464
10756
  if (options.dryRun) {
@@ -10492,7 +10784,7 @@ async function runInit(options) {
10492
10784
  '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
10785
  );
10494
10786
  }
10495
- if (fs15.existsSync(configPath) && !options.force && !reused) {
10787
+ if (fs16.existsSync(configPath) && !options.force && !reused) {
10496
10788
  throw new Error(`${configName} already exists. Re-run with --force to replace it.`);
10497
10789
  }
10498
10790
  if (!reused) writeFileOrExplain(configPath, configText);
@@ -10518,9 +10810,9 @@ async function runInit(options) {
10518
10810
  };
10519
10811
  }
10520
10812
  function describeTarget(cwd) {
10521
- const relative11 = path16.relative(process.cwd(), cwd);
10813
+ const relative11 = path17.relative(process.cwd(), cwd);
10522
10814
  if (relative11 === "") return "this directory";
10523
- if (relative11.startsWith("..") || path16.isAbsolute(relative11)) return cwd;
10815
+ if (relative11.startsWith("..") || path17.isAbsolute(relative11)) return cwd;
10524
10816
  return relative11;
10525
10817
  }
10526
10818
  function firstRunMessage(reason, cwd) {
@@ -10544,7 +10836,7 @@ function planFirstRun(facts) {
10544
10836
  var NOT_CONTENT = /* @__PURE__ */ new Set([".git", ".hg", ".svn", ".bzr", ".DS_Store", "Thumbs.db"]);
10545
10837
  function isEffectivelyEmpty(cwd) {
10546
10838
  try {
10547
- return fs15.readdirSync(cwd).every((entry) => NOT_CONTENT.has(entry));
10839
+ return fs16.readdirSync(cwd).every((entry) => NOT_CONTENT.has(entry));
10548
10840
  } catch {
10549
10841
  return false;
10550
10842
  }
@@ -10552,7 +10844,7 @@ function isEffectivelyEmpty(cwd) {
10552
10844
  function hasPriorSnapshot(cwd, outDir) {
10553
10845
  let parsed;
10554
10846
  try {
10555
- parsed = JSON.parse(fs15.readFileSync(path16.join(cwd, outDir, ".codebase-snapshot"), "utf8"));
10847
+ parsed = JSON.parse(fs16.readFileSync(path17.join(cwd, outDir, ".codebase-snapshot"), "utf8"));
10556
10848
  } catch {
10557
10849
  return false;
10558
10850
  }
@@ -10600,36 +10892,36 @@ fi
10600
10892
  `;
10601
10893
  }
10602
10894
  function gitDirectory(cwd) {
10603
- const dotGit = path16.join(cwd, ".git");
10895
+ const dotGit = path17.join(cwd, ".git");
10604
10896
  let stats;
10605
10897
  try {
10606
- stats = fs15.statSync(dotGit);
10898
+ stats = fs16.statSync(dotGit);
10607
10899
  } catch {
10608
10900
  return null;
10609
10901
  }
10610
10902
  if (stats.isDirectory()) return dotGit;
10611
10903
  if (!stats.isFile()) return null;
10612
10904
  try {
10613
- const contents = fs15.readFileSync(dotGit, "utf8");
10905
+ const contents = fs16.readFileSync(dotGit, "utf8");
10614
10906
  const match = /^gitdir:\s*(.+)$/m.exec(contents);
10615
10907
  if (!match) return null;
10616
10908
  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;
10909
+ const resolved = path17.isAbsolute(target.trim()) ? target.trim() : path17.join(cwd, target.trim());
10910
+ if (!fs16.statSync(resolved).isDirectory()) return null;
10911
+ if (isInside2(path17.resolve(cwd), path17.resolve(resolved))) return resolved;
10912
+ return isRegisteredWorktree(path17.resolve(resolved), cwd) ? resolved : null;
10621
10913
  } catch {
10622
10914
  return null;
10623
10915
  }
10624
10916
  }
10625
10917
  function isInside2(parent, child) {
10626
- const relative11 = path16.relative(parent, child);
10627
- return relative11 === "" || !relative11.startsWith("..") && !path16.isAbsolute(relative11);
10918
+ const relative11 = path17.relative(parent, child);
10919
+ return relative11 === "" || !relative11.startsWith("..") && !path17.isAbsolute(relative11);
10628
10920
  }
10629
10921
  function isRegisteredWorktree(gitDir, cwd) {
10630
10922
  try {
10631
- const back = fs15.readFileSync(path16.join(gitDir, "gitdir"), "utf8").trim();
10632
- return path16.resolve(gitDir, back) === path16.join(path16.resolve(cwd), ".git");
10923
+ const back = fs16.readFileSync(path17.join(gitDir, "gitdir"), "utf8").trim();
10924
+ return path17.resolve(gitDir, back) === path17.join(path17.resolve(cwd), ".git");
10633
10925
  } catch {
10634
10926
  return false;
10635
10927
  }
@@ -10650,10 +10942,10 @@ function gitOutput(cwd, args) {
10650
10942
  function configuredHooksDirectory(cwd) {
10651
10943
  const hooks = gitOutput(cwd, ["rev-parse", "--git-path", "hooks"]);
10652
10944
  if (hooks === null) return null;
10653
- const resolved = path16.resolve(cwd, hooks);
10945
+ const resolved = path17.resolve(cwd, hooks);
10654
10946
  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 };
10947
+ const commonDir = common === null ? null : path17.resolve(cwd, common);
10948
+ if (isInside2(path17.resolve(cwd), resolved)) return { dir: resolved };
10657
10949
  if (commonDir !== null && isInside2(commonDir, resolved)) return { dir: resolved };
10658
10950
  return {
10659
10951
  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 +10966,10 @@ function installPreCommitHook(cwd, outDir = "snapshot") {
10674
10966
  ]
10675
10967
  };
10676
10968
  }
10677
- const hooksDir = configured === null ? path16.join(gitDir, "hooks") : configured.dir;
10678
- const hookPath = path16.join(hooksDir, "pre-commit");
10969
+ const hooksDir = configured === null ? path17.join(gitDir, "hooks") : configured.dir;
10970
+ const hookPath = path17.join(hooksDir, "pre-commit");
10679
10971
  try {
10680
- fs15.mkdirSync(hooksDir, { recursive: true });
10972
+ fs16.mkdirSync(hooksDir, { recursive: true });
10681
10973
  } catch (err) {
10682
10974
  return {
10683
10975
  path: hookPath,
@@ -10687,7 +10979,7 @@ function installPreCommitHook(cwd, outDir = "snapshot") {
10687
10979
  }
10688
10980
  let existing = null;
10689
10981
  try {
10690
- existing = fs15.readFileSync(hookPath, "utf8");
10982
+ existing = fs16.readFileSync(hookPath, "utf8");
10691
10983
  } catch {
10692
10984
  existing = null;
10693
10985
  }
@@ -10702,8 +10994,8 @@ function installPreCommitHook(cwd, outDir = "snapshot") {
10702
10994
  };
10703
10995
  }
10704
10996
  try {
10705
- fs15.writeFileSync(hookPath, hookScript(outDir), "utf8");
10706
- fs15.chmodSync(hookPath, 493);
10997
+ fs16.writeFileSync(hookPath, hookScript(outDir), "utf8");
10998
+ fs16.chmodSync(hookPath, 493);
10707
10999
  } catch (err) {
10708
11000
  return {
10709
11001
  path: hookPath,
@@ -10720,7 +11012,7 @@ function installPreCommitHook(cwd, outDir = "snapshot") {
10720
11012
  };
10721
11013
  }
10722
11014
  function workerEntry(directory, isCjs) {
10723
- const entry = path16.join(directory, isCjs ? "index.cjs" : "index.js");
11015
+ const entry = path17.join(directory, isCjs ? "index.cjs" : "index.js");
10724
11016
  return { path: entry, url: pathToFileURL(entry).href };
10725
11017
  }
10726
11018
  var WORKER_SOURCE = `
@@ -10787,7 +11079,7 @@ function generateInWorker(cwd, cliOptions, options = {}) {
10787
11079
  resolve8(result);
10788
11080
  };
10789
11081
  const isCjs = typeof __dirname !== "undefined";
10790
- const directory = isCjs ? __dirname : path16.dirname(fileURLToPath(import.meta.url));
11082
+ const directory = isCjs ? __dirname : path17.dirname(fileURLToPath(import.meta.url));
10791
11083
  try {
10792
11084
  worker = new Worker(WORKER_SOURCE, {
10793
11085
  eval: true,
@@ -10822,23 +11114,23 @@ var SUMMARY_MAX_SOURCE_BYTES2 = SUMMARY_MAX_SOURCE_BYTES;
10822
11114
  var FILE_DERIVATIONS = /* @__PURE__ */ new Map();
10823
11115
  var FILE_DERIVATION_LIMIT_BYTES = 64 * 1024 * 1024;
10824
11116
  var fileDerivationBytes = 0;
10825
- function takeDerivation(path17, hash, settings) {
10826
- const cached = FILE_DERIVATIONS.get(path17);
11117
+ function takeDerivation(path18, hash, settings) {
11118
+ const cached = FILE_DERIVATIONS.get(path18);
10827
11119
  if (cached === void 0 || cached.hash !== hash || cached.settings !== settings) return void 0;
10828
- FILE_DERIVATIONS.delete(path17);
10829
- FILE_DERIVATIONS.set(path17, cached);
11120
+ FILE_DERIVATIONS.delete(path18);
11121
+ FILE_DERIVATIONS.set(path18, cached);
10830
11122
  return cached;
10831
11123
  }
10832
- function rememberDerivation(path17, hash, settings, derivation) {
11124
+ function rememberDerivation(path18, hash, settings, derivation) {
10833
11125
  const bodyBytes = derivation.finalContent === derivation.redacted ? derivation.redacted.length : derivation.redacted.length + derivation.finalContent.length;
10834
11126
  const bytes = bodyBytes * 2 + 512;
10835
11127
  if (bytes > FILE_DERIVATION_LIMIT_BYTES / 4) return;
10836
- const previous = FILE_DERIVATIONS.get(path17);
11128
+ const previous = FILE_DERIVATIONS.get(path18);
10837
11129
  if (previous !== void 0) {
10838
- FILE_DERIVATIONS.delete(path17);
11130
+ FILE_DERIVATIONS.delete(path18);
10839
11131
  fileDerivationBytes -= previous.bytes;
10840
11132
  } else {
10841
- FILE_DERIVATIONS.delete(path17);
11133
+ FILE_DERIVATIONS.delete(path18);
10842
11134
  }
10843
11135
  while (fileDerivationBytes + bytes > FILE_DERIVATION_LIMIT_BYTES) {
10844
11136
  const oldest = FILE_DERIVATIONS.keys().next();
@@ -10847,7 +11139,7 @@ function rememberDerivation(path17, hash, settings, derivation) {
10847
11139
  FILE_DERIVATIONS.delete(oldest.value);
10848
11140
  if (evicted !== void 0) fileDerivationBytes -= evicted.bytes;
10849
11141
  }
10850
- FILE_DERIVATIONS.set(path17, { ...derivation, hash, settings, bytes });
11142
+ FILE_DERIVATIONS.set(path18, { ...derivation, hash, settings, bytes });
10851
11143
  fileDerivationBytes += bytes;
10852
11144
  }
10853
11145
  function derivationSettings(config) {
@@ -11098,11 +11390,11 @@ function verifyInMemory(files, parts, unaccounted) {
11098
11390
  return errors;
11099
11391
  }
11100
11392
  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}`);
11393
+ const cwd = path17.resolve(config.cwd);
11394
+ const outDir = path17.resolve(cwd, config.outDir);
11395
+ const tmpDir = path17.resolve(cwd, config.tmpDir);
11396
+ const root = path17.parse(cwd).root;
11397
+ const contains = (parent, child) => child === parent || child.startsWith(`${parent}${path17.sep}`);
11106
11398
  const reject = (reason) => {
11107
11399
  throw new Error(
11108
11400
  `Refusing to generate: ${reason}. outDir=${outDir} tmpDir=${tmpDir} cwd=${cwd}`
@@ -11142,6 +11434,28 @@ function maskSummaryStrings(value, secretRules) {
11142
11434
  function maskPathText(value, secretRules) {
11143
11435
  return findSecretInPath(value, secretRules)?.masked ?? value;
11144
11436
  }
11437
+ function maskOwnerBrief(brief, secretRules) {
11438
+ if (brief === void 0) return void 0;
11439
+ const mask = (value) => maskPathText(value, secretRules);
11440
+ return {
11441
+ ...brief,
11442
+ ...brief.stakes === void 0 ? {} : { stakes: mask(brief.stakes) },
11443
+ ...brief.system === void 0 ? {} : { system: mask(brief.system) },
11444
+ ...brief.history === void 0 ? {} : { history: mask(brief.history) },
11445
+ ...brief.bar === void 0 ? {} : { bar: mask(brief.bar) },
11446
+ ...brief.calibration === void 0 ? {} : { calibration: mask(brief.calibration) },
11447
+ ...brief.preamble === void 0 ? {} : { preamble: mask(brief.preamble) },
11448
+ notes: brief.notes.map((note) => ({ heading: note.heading, body: mask(note.body) }))
11449
+ };
11450
+ }
11451
+ function maskOverview(overview, secretRules) {
11452
+ const mask = (value) => maskPathText(value, secretRules);
11453
+ return {
11454
+ ...overview.description === void 0 ? {} : { description: mask(overview.description) },
11455
+ ...overview.summary === void 0 ? {} : { summary: mask(overview.summary) },
11456
+ releases: overview.releases.map(mask)
11457
+ };
11458
+ }
11145
11459
  function maskSkipRecords(records, secretRules) {
11146
11460
  return maskSkipPaths(records, secretRules);
11147
11461
  }
@@ -11162,14 +11476,14 @@ function listEntries(dir) {
11162
11476
  const walk = (absolute, prefix) => {
11163
11477
  let children;
11164
11478
  try {
11165
- children = fs15.readdirSync(absolute, { withFileTypes: true });
11479
+ children = fs16.readdirSync(absolute, { withFileTypes: true });
11166
11480
  } catch {
11167
11481
  return;
11168
11482
  }
11169
11483
  for (const child of children) {
11170
11484
  const relative11 = prefix === "" ? child.name : `${prefix}/${child.name}`;
11171
11485
  entries.push(relative11);
11172
- if (child.isDirectory()) walk(path16.join(absolute, child.name), relative11);
11486
+ if (child.isDirectory()) walk(path17.join(absolute, child.name), relative11);
11173
11487
  }
11174
11488
  };
11175
11489
  walk(dir, "");
@@ -11181,10 +11495,10 @@ function markerInventory(dir, written) {
11181
11495
  for (const entry of entries) {
11182
11496
  if (entry === OWNERSHIP_MARKER) continue;
11183
11497
  if (isIgnorableEntry(entry)) continue;
11184
- const full = path16.join(dir, ...entry.split("/"));
11498
+ const full = path17.join(dir, ...entry.split("/"));
11185
11499
  let stats;
11186
11500
  try {
11187
- stats = fs15.lstatSync(full);
11501
+ stats = fs16.lstatSync(full);
11188
11502
  } catch {
11189
11503
  continue;
11190
11504
  }
@@ -11196,7 +11510,7 @@ function markerInventory(dir, written) {
11196
11510
  }
11197
11511
  let digest;
11198
11512
  try {
11199
- digest = sha256Hex2(fs15.readFileSync(full));
11513
+ digest = sha256Hex2(fs16.readFileSync(full));
11200
11514
  } catch {
11201
11515
  continue;
11202
11516
  }
@@ -11217,15 +11531,15 @@ function markerPayload(dir, state, id, createdAt, written) {
11217
11531
  entries,
11218
11532
  files
11219
11533
  };
11220
- const manifestPath = path16.join(dir, "manifest.json");
11221
- if (fs15.existsSync(manifestPath)) {
11222
- marker2.manifestSha256 = sha256Hex2(fs15.readFileSync(manifestPath));
11534
+ const manifestPath = path17.join(dir, "manifest.json");
11535
+ if (fs16.existsSync(manifestPath)) {
11536
+ marker2.manifestSha256 = sha256Hex2(fs16.readFileSync(manifestPath));
11223
11537
  }
11224
11538
  return marker2;
11225
11539
  }
11226
11540
  function writeOwnershipMarker(dir, marker2) {
11227
- fs15.writeFileSync(
11228
- path16.join(dir, OWNERSHIP_MARKER),
11541
+ fs16.writeFileSync(
11542
+ path17.join(dir, OWNERSHIP_MARKER),
11229
11543
  `${JSON.stringify(marker2, null, 2)}
11230
11544
  `,
11231
11545
  "utf8"
@@ -11237,13 +11551,13 @@ function markerBelongsTo(dir, id) {
11237
11551
  return evidence.marker.id === id;
11238
11552
  }
11239
11553
  function readOwnershipMarker(dir) {
11240
- const markerPath = path16.join(dir, OWNERSHIP_MARKER);
11241
- if (!fs15.existsSync(markerPath)) {
11554
+ const markerPath = path17.join(dir, OWNERSHIP_MARKER);
11555
+ if (!fs16.existsSync(markerPath)) {
11242
11556
  return { marker: null, problem: "it holds no .codebase-snapshot marker" };
11243
11557
  }
11244
11558
  let raw;
11245
11559
  try {
11246
- raw = fs15.readFileSync(markerPath, "utf8");
11560
+ raw = fs16.readFileSync(markerPath, "utf8");
11247
11561
  } catch {
11248
11562
  return { marker: null, problem: "its .codebase-snapshot marker could not be read" };
11249
11563
  }
@@ -11343,10 +11657,10 @@ function verifyMarkerInventory(dir, entries, files) {
11343
11657
  for (const entry of entries) {
11344
11658
  if (entry === OWNERSHIP_MARKER) continue;
11345
11659
  if (IGNORABLE_ENTRIES.has(entry.slice(entry.lastIndexOf("/") + 1))) continue;
11346
- const full = path16.join(dir, ...entry.split("/"));
11660
+ const full = path17.join(dir, ...entry.split("/"));
11347
11661
  let stats;
11348
11662
  try {
11349
- stats = fs15.lstatSync(full);
11663
+ stats = fs16.lstatSync(full);
11350
11664
  } catch {
11351
11665
  return `its .codebase-snapshot inventory lists ${entry}, which cannot be read`;
11352
11666
  }
@@ -11371,7 +11685,7 @@ function verifyMarkerInventory(dir, entries, files) {
11371
11685
  }
11372
11686
  let digest;
11373
11687
  try {
11374
- digest = sha256Hex2(fs15.readFileSync(full));
11688
+ digest = sha256Hex2(fs16.readFileSync(full));
11375
11689
  } catch {
11376
11690
  return `its .codebase-snapshot inventory cannot verify ${entry}: the file could not be read`;
11377
11691
  }
@@ -11392,12 +11706,12 @@ function assessSnapshotDirectory(dir) {
11392
11706
  marker: marker2
11393
11707
  };
11394
11708
  }
11395
- const manifestPath = path16.join(dir, "manifest.json");
11396
- const hasManifest = fs15.existsSync(manifestPath);
11709
+ const manifestPath = path17.join(dir, "manifest.json");
11710
+ const hasManifest = fs16.existsSync(manifestPath);
11397
11711
  if (hasManifest) {
11398
11712
  let raw;
11399
11713
  try {
11400
- raw = fs15.readFileSync(manifestPath, "utf8");
11714
+ raw = fs16.readFileSync(manifestPath, "utf8");
11401
11715
  } catch {
11402
11716
  return {
11403
11717
  owned: false,
@@ -11492,13 +11806,13 @@ function containsNoFiles(dir) {
11492
11806
  const current = pending.pop();
11493
11807
  let entries;
11494
11808
  try {
11495
- entries = fs15.readdirSync(current, { withFileTypes: true });
11809
+ entries = fs16.readdirSync(current, { withFileTypes: true });
11496
11810
  } catch {
11497
11811
  return false;
11498
11812
  }
11499
11813
  for (const entry of entries) {
11500
11814
  if (entry.isDirectory()) {
11501
- pending.push(path16.join(current, entry.name));
11815
+ pending.push(path17.join(current, entry.name));
11502
11816
  } else if (!IGNORABLE_ENTRIES.has(entry.name)) {
11503
11817
  return false;
11504
11818
  }
@@ -11507,13 +11821,13 @@ function containsNoFiles(dir) {
11507
11821
  return true;
11508
11822
  }
11509
11823
  function assertReplaceable(target, label, secretRules) {
11510
- if (!fs15.existsSync(target)) return;
11511
- if (!fs15.statSync(target).isDirectory()) {
11824
+ if (!fs16.existsSync(target)) return;
11825
+ if (!fs16.statSync(target).isDirectory()) {
11512
11826
  throw new Error(
11513
11827
  `Refusing to write into ${label} ${target}: it exists but is not a directory.`
11514
11828
  );
11515
11829
  }
11516
- const entries = fs15.readdirSync(target);
11830
+ const entries = fs16.readdirSync(target);
11517
11831
  if (entries.length === 0) return;
11518
11832
  if (entries.every((name) => IGNORABLE_ENTRIES.has(name))) return;
11519
11833
  if (containsNoFiles(target)) return;
@@ -11533,18 +11847,18 @@ function assertReplaceable(target, label, secretRules) {
11533
11847
  );
11534
11848
  }
11535
11849
  function assertStagingRootUsable(tmpDir, secretRules) {
11536
- if (!fs15.existsSync(tmpDir)) return;
11537
- if (!fs15.statSync(tmpDir).isDirectory()) {
11850
+ if (!fs16.existsSync(tmpDir)) return;
11851
+ if (!fs16.statSync(tmpDir).isDirectory()) {
11538
11852
  throw new Error(`Refusing to write into tmpDir ${tmpDir}: it exists but is not a directory.`);
11539
11853
  }
11540
- const entries = fs15.readdirSync(tmpDir);
11854
+ const entries = fs16.readdirSync(tmpDir);
11541
11855
  if (entries.length === 0) return;
11542
11856
  const foreign = entries.filter((name) => {
11543
- const full = path16.join(tmpDir, name);
11857
+ const full = path17.join(tmpDir, name);
11544
11858
  if (!name.startsWith(RUN_DIR_PREFIX)) return true;
11545
11859
  let stats;
11546
11860
  try {
11547
- stats = fs15.statSync(full);
11861
+ stats = fs16.statSync(full);
11548
11862
  } catch {
11549
11863
  return true;
11550
11864
  }
@@ -11552,7 +11866,7 @@ function assertStagingRootUsable(tmpDir, secretRules) {
11552
11866
  const { marker: marker2 } = readOwnershipMarker(full);
11553
11867
  if (marker2) return false;
11554
11868
  try {
11555
- return fs15.readdirSync(full).length > 0;
11869
+ return fs16.readdirSync(full).length > 0;
11556
11870
  } catch {
11557
11871
  return true;
11558
11872
  }
@@ -11567,13 +11881,13 @@ function assertStagingRootUsable(tmpDir, secretRules) {
11567
11881
  function cleanStaleRunDirs(tmpDir) {
11568
11882
  let entries;
11569
11883
  try {
11570
- entries = fs15.readdirSync(tmpDir);
11884
+ entries = fs16.readdirSync(tmpDir);
11571
11885
  } catch {
11572
11886
  return;
11573
11887
  }
11574
11888
  for (const name of entries) {
11575
11889
  if (!name.startsWith(RUN_DIR_PREFIX)) continue;
11576
- const full = path16.join(tmpDir, name);
11890
+ const full = path17.join(tmpDir, name);
11577
11891
  const { marker: marker2 } = readOwnershipMarker(full);
11578
11892
  if (marker2) {
11579
11893
  const created = Date.parse(marker2.createdAt);
@@ -11581,33 +11895,33 @@ function cleanStaleRunDirs(tmpDir) {
11581
11895
  const abandoned = typeof marker2.pid === "number" && !isProcessAlive(marker2.pid);
11582
11896
  if (aged || abandoned) {
11583
11897
  try {
11584
- fs15.rmSync(full, { recursive: true, force: true });
11898
+ fs16.rmSync(full, { recursive: true, force: true });
11585
11899
  } catch {
11586
11900
  }
11587
11901
  }
11588
11902
  continue;
11589
11903
  }
11590
11904
  try {
11591
- if (fs15.readdirSync(full).length === 0) fs15.rmSync(full, { recursive: true, force: true });
11905
+ if (fs16.readdirSync(full).length === 0) fs16.rmSync(full, { recursive: true, force: true });
11592
11906
  } catch {
11593
11907
  }
11594
11908
  }
11595
11909
  }
11596
11910
  function removeIfEmpty(dir) {
11597
11911
  try {
11598
- if (fs15.readdirSync(dir).length === 0) fs15.rmSync(dir, { recursive: true, force: true });
11912
+ if (fs16.readdirSync(dir).length === 0) fs16.rmSync(dir, { recursive: true, force: true });
11599
11913
  } catch {
11600
11914
  }
11601
11915
  }
11602
11916
  function ensureParentDirectory(target, label) {
11603
- const parent = path16.dirname(target);
11604
- if (fs15.existsSync(parent) && !fs15.statSync(parent).isDirectory()) {
11917
+ const parent = path17.dirname(target);
11918
+ if (fs16.existsSync(parent) && !fs16.statSync(parent).isDirectory()) {
11605
11919
  throw new Error(
11606
11920
  `Refusing to create ${label} ${target}: ${parent} exists but is not a directory.`
11607
11921
  );
11608
11922
  }
11609
11923
  try {
11610
- fs15.mkdirSync(parent, { recursive: true });
11924
+ fs16.mkdirSync(parent, { recursive: true });
11611
11925
  } catch (err) {
11612
11926
  throw new Error(
11613
11927
  `Refusing to create ${label} ${target}: its parent ${parent} could not be created (${err.message}).`
@@ -11665,17 +11979,17 @@ function acquireRunLock(stagingRoot) {
11665
11979
  `;
11666
11980
  for (let attempt = 0; attempt < 2; attempt += 1) {
11667
11981
  try {
11668
- const handle = fs15.openSync(lockPath, "wx");
11982
+ const handle = fs16.openSync(lockPath, "wx");
11669
11983
  try {
11670
- fs15.writeSync(handle, payload);
11984
+ fs16.writeSync(handle, payload);
11671
11985
  } finally {
11672
- fs15.closeSync(handle);
11986
+ fs16.closeSync(handle);
11673
11987
  }
11674
11988
  const stopHeartbeat = startLockHeartbeat(lockPath);
11675
11989
  return () => {
11676
11990
  stopHeartbeat();
11677
11991
  try {
11678
- fs15.rmSync(lockPath, { force: true });
11992
+ fs16.rmSync(lockPath, { force: true });
11679
11993
  } catch {
11680
11994
  }
11681
11995
  };
@@ -11695,26 +12009,26 @@ function lockKeyFor(stagingRoot) {
11695
12009
  return sha256Hex2(key).slice(0, 16);
11696
12010
  }
11697
12011
  function canonicalLockTarget(targetPath) {
11698
- const resolved = path16.resolve(targetPath);
12012
+ const resolved = path17.resolve(targetPath);
11699
12013
  let existing = resolved;
11700
12014
  const tail = [];
11701
12015
  for (; ; ) {
11702
12016
  try {
11703
- return path16.join(fs15.realpathSync(existing), ...tail);
12017
+ return path17.join(fs16.realpathSync(existing), ...tail);
11704
12018
  } catch {
11705
- const parent = path16.dirname(existing);
12019
+ const parent = path17.dirname(existing);
11706
12020
  if (parent === existing) return resolved;
11707
- tail.unshift(path16.basename(existing));
12021
+ tail.unshift(path17.basename(existing));
11708
12022
  existing = parent;
11709
12023
  }
11710
12024
  }
11711
12025
  }
11712
12026
  function lockPathFor(stagingRoot) {
11713
- return path16.join(os.tmpdir(), `codebase-snapshot-${lockKeyFor(stagingRoot)}.lock`);
12027
+ return path17.join(os.tmpdir(), `codebase-snapshot-${lockKeyFor(stagingRoot)}.lock`);
11714
12028
  }
11715
12029
  function lockHeartbeatAgeMs(lockPath) {
11716
12030
  try {
11717
- return Date.now() - fs15.statSync(lockPath).mtimeMs;
12031
+ return Date.now() - fs16.statSync(lockPath).mtimeMs;
11718
12032
  } catch {
11719
12033
  return Number.POSITIVE_INFINITY;
11720
12034
  }
@@ -11722,7 +12036,7 @@ function lockHeartbeatAgeMs(lockPath) {
11722
12036
  function lockOwnerIsGone(lockPath) {
11723
12037
  let raw;
11724
12038
  try {
11725
- raw = fs15.readFileSync(lockPath, "utf8");
12039
+ raw = fs16.readFileSync(lockPath, "utf8");
11726
12040
  } catch {
11727
12041
  return false;
11728
12042
  }
@@ -11744,16 +12058,16 @@ function lockOwnerIsGone(lockPath) {
11744
12058
  function reclaimStaleLock(lockPath) {
11745
12059
  let before;
11746
12060
  try {
11747
- before = fs15.statSync(lockPath);
12061
+ before = fs16.statSync(lockPath);
11748
12062
  } catch {
11749
12063
  return true;
11750
12064
  }
11751
12065
  if (!lockOwnerIsGone(lockPath)) return false;
11752
12066
  try {
11753
- const current = fs15.statSync(lockPath);
12067
+ const current = fs16.statSync(lockPath);
11754
12068
  const sameFile = current.ino === before.ino && current.birthtimeMs === before.birthtimeMs && current.mtimeMs === before.mtimeMs;
11755
12069
  if (!sameFile) return false;
11756
- fs15.rmSync(lockPath, { force: true });
12070
+ fs16.rmSync(lockPath, { force: true });
11757
12071
  return true;
11758
12072
  } catch {
11759
12073
  return false;
@@ -11764,12 +12078,12 @@ function lockFileIsAncient(lockPath) {
11764
12078
  }
11765
12079
  function writeManifestAtomically(manifestPath, manifest) {
11766
12080
  const tempPath = `${manifestPath}.${process.pid}.tmp`;
11767
- fs15.writeFileSync(tempPath, JSON.stringify(manifest, null, 2), "utf8");
12081
+ fs16.writeFileSync(tempPath, JSON.stringify(manifest, null, 2), "utf8");
11768
12082
  try {
11769
- fs15.renameSync(tempPath, manifestPath);
12083
+ fs16.renameSync(tempPath, manifestPath);
11770
12084
  } catch (err) {
11771
12085
  try {
11772
- fs15.rmSync(tempPath, { force: true });
12086
+ fs16.rmSync(tempPath, { force: true });
11773
12087
  } catch {
11774
12088
  }
11775
12089
  throw err;
@@ -11794,21 +12108,21 @@ function swapIntoPlace(stagingDir, outDir, beforeSwap) {
11794
12108
  }
11795
12109
  }
11796
12110
  function recoverInterruptedPublish(outDir) {
11797
- if (fs15.existsSync(outDir)) return;
11798
- const parent = path16.dirname(outDir);
11799
- const base = path16.basename(outDir);
12111
+ if (fs16.existsSync(outDir)) return;
12112
+ const parent = path17.dirname(outDir);
12113
+ const base = path17.basename(outDir);
11800
12114
  let backups;
11801
12115
  try {
11802
- backups = fs15.readdirSync(parent).filter((name) => name.startsWith(`${base}.backup-`));
12116
+ backups = fs16.readdirSync(parent).filter((name) => name.startsWith(`${base}.backup-`));
11803
12117
  } catch {
11804
12118
  return;
11805
12119
  }
11806
12120
  if (backups.length !== 1) return;
11807
- const backupDir = path16.join(parent, backups[0]);
12121
+ const backupDir = path17.join(parent, backups[0]);
11808
12122
  const { marker: marker2, problem } = readOwnershipMarker(backupDir);
11809
12123
  if (problem !== null || marker2 === null || marker2.state !== "complete") return;
11810
12124
  try {
11811
- fs15.renameSync(backupDir, outDir);
12125
+ fs16.renameSync(backupDir, outDir);
11812
12126
  process.stderr.write(
11813
12127
  `\u26A0 Recovered ${outDir} from ${backupDir}, left by an interrupted run. That snapshot is the one from before the interrupted run.
11814
12128
  `
@@ -11818,16 +12132,16 @@ function recoverInterruptedPublish(outDir) {
11818
12132
  }
11819
12133
  function swapOnce(stagingDir, outDir, beforeSwap) {
11820
12134
  const backupDir = `${outDir}.backup-${process.pid}-${Date.now()}`;
11821
- const hadPrevious = fs15.existsSync(outDir);
12135
+ const hadPrevious = fs16.existsSync(outDir);
11822
12136
  if (hadPrevious) beforeSwap?.();
11823
12137
  let movedAside = false;
11824
12138
  if (hadPrevious) {
11825
12139
  try {
11826
- fs15.renameSync(outDir, backupDir);
12140
+ fs16.renameSync(outDir, backupDir);
11827
12141
  movedAside = true;
11828
12142
  } catch (err) {
11829
12143
  if (!isLockError(err)) throw err;
11830
- fs15.rmSync(outDir, { recursive: true, force: true, maxRetries: 5, retryDelay: 100 });
12144
+ fs16.rmSync(outDir, { recursive: true, force: true, maxRetries: 5, retryDelay: 100 });
11831
12145
  process.stderr.write(
11832
12146
  `\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
12147
  `
@@ -11836,26 +12150,26 @@ function swapOnce(stagingDir, outDir, beforeSwap) {
11836
12150
  }
11837
12151
  try {
11838
12152
  try {
11839
- fs15.renameSync(stagingDir, outDir);
12153
+ fs16.renameSync(stagingDir, outDir);
11840
12154
  } catch (err) {
11841
12155
  if (err.code !== "EXDEV") throw err;
11842
12156
  const partialDir = `${outDir}.partial-${process.pid}-${Date.now()}`;
11843
12157
  try {
11844
- fs15.cpSync(stagingDir, partialDir, { recursive: true });
11845
- fs15.renameSync(partialDir, outDir);
11846
- fs15.rmSync(stagingDir, { recursive: true, force: true });
12158
+ fs16.cpSync(stagingDir, partialDir, { recursive: true });
12159
+ fs16.renameSync(partialDir, outDir);
12160
+ fs16.rmSync(stagingDir, { recursive: true, force: true });
11847
12161
  } catch (copyErr) {
11848
12162
  try {
11849
- fs15.rmSync(partialDir, { recursive: true, force: true });
12163
+ fs16.rmSync(partialDir, { recursive: true, force: true });
11850
12164
  } catch {
11851
12165
  }
11852
12166
  throw copyErr;
11853
12167
  }
11854
12168
  }
11855
12169
  } 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);
12170
+ if (hadPrevious && movedAside && fs16.existsSync(backupDir)) {
12171
+ if (fs16.existsSync(outDir)) fs16.rmSync(outDir, { recursive: true, force: true });
12172
+ fs16.renameSync(backupDir, outDir);
11859
12173
  } else if (hadPrevious && !movedAside) {
11860
12174
  process.stderr.write(
11861
12175
  `\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 +12180,7 @@ function swapOnce(stagingDir, outDir, beforeSwap) {
11866
12180
  }
11867
12181
  if (hadPrevious) {
11868
12182
  try {
11869
- fs15.rmSync(backupDir, { recursive: true, force: true });
12183
+ fs16.rmSync(backupDir, { recursive: true, force: true });
11870
12184
  } catch (err) {
11871
12185
  process.stderr.write(
11872
12186
  `\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 +12338,7 @@ function generateSnapshot(configInput, options) {
12024
12338
  // first run cannot have marked them yet, so the name alone keeps a run from recording its own
12025
12339
  // output — but only at these exact paths, not at every directory that shares the name.
12026
12340
  toolOwnedPaths: [config.outDir, config.tmpDir].map(
12027
- (directory) => path16.relative(config.cwd, path16.resolve(config.cwd, directory)).replace(/\\/g, "/")
12341
+ (directory) => path17.relative(config.cwd, path17.resolve(config.cwd, directory)).replace(/\\/g, "/")
12028
12342
  ).filter((relative11) => relative11.length > 0 && !relative11.startsWith("..")),
12029
12343
  // A staged path can be absent from the working tree while its index blob exists. Discovery
12030
12344
  // lists the working tree, so those paths would never reach the scan at all.
@@ -12053,7 +12367,7 @@ function generateSnapshot(configInput, options) {
12053
12367
  let totalSizeBytes = 0;
12054
12368
  let largeFileCount = 0;
12055
12369
  for (const relativePath of candidateFiles) {
12056
- const absolutePath = path16.join(config.cwd, relativePath);
12370
+ const absolutePath = path17.join(config.cwd, relativePath);
12057
12371
  const fromIndex = stagedPaths.has(relativePath);
12058
12372
  let buffer;
12059
12373
  let sizeBytes;
@@ -12084,9 +12398,9 @@ function generateSnapshot(configInput, options) {
12084
12398
  } else {
12085
12399
  let stats;
12086
12400
  try {
12087
- stats = fs15.statSync(absolutePath);
12401
+ stats = fs16.statSync(absolutePath);
12088
12402
  if (!stats.isFile()) {
12089
- const nestedRepository = stats.isDirectory() && fs15.existsSync(path16.join(absolutePath, ".git"));
12403
+ const nestedRepository = stats.isDirectory() && fs16.existsSync(path17.join(absolutePath, ".git"));
12090
12404
  skipped.push(
12091
12405
  nestedRepository ? {
12092
12406
  path: relativePath,
@@ -12122,7 +12436,7 @@ function generateSnapshot(configInput, options) {
12122
12436
  continue;
12123
12437
  }
12124
12438
  try {
12125
- buffer = fs15.readFileSync(absolutePath);
12439
+ buffer = fs16.readFileSync(absolutePath);
12126
12440
  } catch (err) {
12127
12441
  const code = err.code;
12128
12442
  skipped.push({
@@ -12251,14 +12565,14 @@ function generateSnapshot(configInput, options) {
12251
12565
  (finding) => finding.path === void 0 || keep.has(finding.path)
12252
12566
  );
12253
12567
  retain(encodingNotes, (note) => keep.has(note.path));
12254
- retain(oversizeSummaryPaths, (path17) => keep.has(path17));
12255
- retain(previewSummaryPaths, (path17) => keep.has(path17));
12568
+ retain(oversizeSummaryPaths, (path18) => keep.has(path18));
12569
+ retain(previewSummaryPaths, (path18) => keep.has(path18));
12256
12570
  retain(fileWarnings, (warning) => keep.has(warning.path));
12257
- for (const path17 of [...monolithBodies.keys()]) {
12258
- if (!keep.has(path17)) monolithBodies.delete(path17);
12571
+ for (const path18 of [...monolithBodies.keys()]) {
12572
+ if (!keep.has(path18)) monolithBodies.delete(path18);
12259
12573
  }
12260
- for (const path17 of [...skippedSummaryImports.keys()]) {
12261
- if (!keep.has(path17)) skippedSummaryImports.delete(path17);
12574
+ for (const path18 of [...skippedSummaryImports.keys()]) {
12575
+ if (!keep.has(path18)) skippedSummaryImports.delete(path18);
12262
12576
  }
12263
12577
  }
12264
12578
  if (changedScope !== null) {
@@ -12397,6 +12711,8 @@ function generateSnapshot(configInput, options) {
12397
12711
  // omitted from `digest` when it is off so an existing snapshot does not start reporting
12398
12712
  // configuration drift.
12399
12713
  maxParts: config.maxParts ?? null,
12714
+ promptTask: config.promptTask,
12715
+ ...config.brief === void 0 ? {} : { brief: { path: config.brief.path, digest: config.brief.digest } },
12400
12716
  discovery: config.discovery ?? "auto",
12401
12717
  // A changed-files scope decides which files are in the snapshot, so the manifest that
12402
12718
  // describes the run has to name it.
@@ -12527,14 +12843,16 @@ function generateSnapshot(configInput, options) {
12527
12843
  if (auditText !== null) manifest.artifacts.audit = artifactRecord(auditText);
12528
12844
  const readmeText = artifacts.readme ? generateReadme(manifest, artifacts) : null;
12529
12845
  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;
12846
+ const promptText = artifacts.prompt ? generatePrompt(manifest, artifacts, {
12847
+ slots: config.attachmentSlots,
12848
+ task: config.promptTask,
12849
+ brief: maskOwnerBrief(config.brief, config.secretRules),
12850
+ history: recentCommits(config.cwd).map((commit) => ({
12851
+ subject: maskPathText(commit.subject, config.secretRules),
12852
+ body: maskPathText(commit.body, config.secretRules)
12853
+ })),
12854
+ overview: maskOverview(readProjectOverview(config.cwd), config.secretRules)
12855
+ }) : null;
12538
12856
  if (promptText !== null) manifest.artifacts.prompt = artifactRecord(promptText);
12539
12857
  if (projectTree !== null) manifest.artifacts.projectTree = artifactRecord(projectTree);
12540
12858
  let monolithJson = null;
@@ -12610,12 +12928,12 @@ function generateSnapshot(configInput, options) {
12610
12928
  let releaseDeferred = false;
12611
12929
  try {
12612
12930
  ensureParentDirectory(outDir, "outDir");
12613
- fs15.mkdirSync(tmpDir, { recursive: true });
12931
+ fs16.mkdirSync(tmpDir, { recursive: true });
12614
12932
  cleanStaleRunDirs(tmpDir);
12615
12933
  const snapshotId = crypto2.randomUUID();
12616
12934
  const createdAt = (/* @__PURE__ */ new Date()).toISOString();
12617
- stagingDir = path16.join(tmpDir, `${RUN_DIR_PREFIX}${process.pid}-${snapshotId.slice(0, 8)}`);
12618
- fs15.mkdirSync(stagingDir);
12935
+ stagingDir = path17.join(tmpDir, `${RUN_DIR_PREFIX}${process.pid}-${snapshotId.slice(0, 8)}`);
12936
+ fs16.mkdirSync(stagingDir);
12619
12937
  writeOwnershipMarker(stagingDir, {
12620
12938
  generator: GENERATOR_NAME,
12621
12939
  version: GENERATOR_VERSION,
@@ -12625,30 +12943,30 @@ function generateSnapshot(configInput, options) {
12625
12943
  id: snapshotId,
12626
12944
  pid: process.pid
12627
12945
  });
12628
- const partsDir = path16.join(stagingDir, "parts");
12629
- const reportsDir = path16.join(stagingDir, "reports");
12630
- if (artifacts.parts) fs15.mkdirSync(partsDir, { recursive: true });
12946
+ const partsDir = path17.join(stagingDir, "parts");
12947
+ const reportsDir = path17.join(stagingDir, "reports");
12948
+ if (artifacts.parts) fs16.mkdirSync(partsDir, { recursive: true });
12631
12949
  if (artifacts.navigation || artifacts.projectTree || artifacts.audit || config.sarif === true) {
12632
- fs15.mkdirSync(reportsDir, { recursive: true });
12950
+ fs16.mkdirSync(reportsDir, { recursive: true });
12633
12951
  }
12634
12952
  const writtenArtifacts = /* @__PURE__ */ new Map();
12635
12953
  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);
12954
+ const full = path17.join(targetDir, ...relativeEntry.split("/"));
12955
+ fs16.writeFileSync(full, data, "utf8");
12956
+ const stats = fs16.statSync(full);
12639
12957
  writtenArtifacts.set(relativeEntry, {
12640
12958
  digest: { path: relativeEntry, bytes: stats.size, sha256: sha256Hex2(data) },
12641
12959
  mtimeMs: stats.mtimeMs
12642
12960
  });
12643
12961
  };
12644
12962
  const recordArtifact = (targetDir, relativeEntry) => {
12645
- const full = path16.join(targetDir, ...relativeEntry.split("/"));
12646
- const stats = fs15.statSync(full);
12963
+ const full = path17.join(targetDir, ...relativeEntry.split("/"));
12964
+ const stats = fs16.statSync(full);
12647
12965
  writtenArtifacts.set(relativeEntry, {
12648
12966
  digest: {
12649
12967
  path: relativeEntry,
12650
12968
  bytes: stats.size,
12651
- sha256: sha256Hex2(fs15.readFileSync(full))
12969
+ sha256: sha256Hex2(fs16.readFileSync(full))
12652
12970
  },
12653
12971
  mtimeMs: stats.mtimeMs
12654
12972
  });
@@ -12696,7 +13014,7 @@ function generateSnapshot(configInput, options) {
12696
13014
  const shipHookState = () => {
12697
13015
  if (!markerBelongsTo(outDir, snapshotId)) return;
12698
13016
  if (artifacts.manifest && manifest.warnings.length !== warningsBeforeHook) {
12699
- writeManifestAtomically(path16.join(outDir, "manifest.json"), manifest);
13017
+ writeManifestAtomically(path17.join(outDir, "manifest.json"), manifest);
12700
13018
  recordArtifact(outDir, "manifest.json");
12701
13019
  }
12702
13020
  writeOwnershipMarker(
@@ -12739,7 +13057,7 @@ function generateSnapshot(configInput, options) {
12739
13057
  } catch (err) {
12740
13058
  if (stagingDir !== null) {
12741
13059
  try {
12742
- fs15.rmSync(stagingDir, { recursive: true, force: true });
13060
+ fs16.rmSync(stagingDir, { recursive: true, force: true });
12743
13061
  } catch {
12744
13062
  }
12745
13063
  }