codebase-snapshot 0.12.0 → 0.12.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1766,7 +1766,23 @@ function parseOwnerBrief(filePath, text2) {
1766
1766
  const preamble = [];
1767
1767
  const sections = [];
1768
1768
  let current = null;
1769
+ let fence = null;
1769
1770
  for (const line of source.split(/\r?\n/)) {
1771
+ const fenceLine = /^ {0,3}(`{3,}|~{3,})/.exec(line);
1772
+ if (fenceLine) {
1773
+ const marker2 = fenceLine[1];
1774
+ const char = marker2[0];
1775
+ if (fence === null) fence = { char, length: marker2.length };
1776
+ else if (char === fence.char && marker2.length >= fence.length) fence = null;
1777
+ if (current) current.body.push(line);
1778
+ else preamble.push(line);
1779
+ continue;
1780
+ }
1781
+ if (fence !== null) {
1782
+ if (current) current.body.push(line);
1783
+ else preamble.push(line);
1784
+ continue;
1785
+ }
1770
1786
  const heading = /^##\s+(.+?)\s*$/.exec(line);
1771
1787
  if (heading) {
1772
1788
  current = { heading: heading[1], body: [] };
@@ -1778,7 +1794,7 @@ function parseOwnerBrief(filePath, text2) {
1778
1794
  }
1779
1795
  const recognised = {};
1780
1796
  const notes = [];
1781
- const canonical = (heading) => heading.trim().toLowerCase().replace(/\s+/g, " ");
1797
+ const canonical = (heading) => heading.trim().replace(/[:.]+$/, "").trim().toLowerCase().replace(/\s+/g, " ");
1782
1798
  const canonicalOwner = new Map(OWNER_SECTIONS.map((name) => [canonical(name), name]));
1783
1799
  const canonicalReserved = new Set(RESERVED_SECTIONS.map(canonical));
1784
1800
  const seen = /* @__PURE__ */ new Set();
@@ -3994,7 +4010,7 @@ function applySpansKeepingQuotes(line, spans) {
3994
4010
 
3995
4011
  // src/version.ts
3996
4012
  var GENERATOR_NAME = "codebase-snapshot";
3997
- var GENERATOR_VERSION = "0.12.0";
4013
+ var GENERATOR_VERSION = "0.12.2";
3998
4014
  var SCHEMA_VERSION = "3.0.0";
3999
4015
  var LEGACY_GENERATOR_NAMES = ["@ankurhalder/codebase-snapshot"];
4000
4016
  function isOurGeneratorName(name) {
@@ -4443,6 +4459,15 @@ function defaultIgnoreReason(relativePath, toolDirNames = DEFAULT_TOOL_DIR_NAMES
4443
4459
  return null;
4444
4460
  }
4445
4461
  var COMMIT_BODY_LIMIT = 400;
4462
+ function truncateAtSentence(text2, limit) {
4463
+ if (text2.length <= limit) return text2;
4464
+ const window = text2.slice(0, limit);
4465
+ const sentence = Math.max(window.lastIndexOf(". "), window.lastIndexOf("; "));
4466
+ if (sentence > limit / 3) return window.slice(0, sentence + 1).trim();
4467
+ const space = window.lastIndexOf(" ");
4468
+ if (space > limit / 3) return window.slice(0, space).trim() + "\u2026";
4469
+ return window.trim() + "\u2026";
4470
+ }
4446
4471
  function recentCommits(cwd, limit = 10) {
4447
4472
  try {
4448
4473
  const stdout = childProcess__namespace.execFileSync(
@@ -4461,10 +4486,10 @@ function recentCommits(cwd, limit = 10) {
4461
4486
  const separator = record.indexOf("");
4462
4487
  const subject = separator === -1 ? record : record.slice(0, separator);
4463
4488
  const rawBody = separator === -1 ? "" : record.slice(separator + 1);
4464
- const body = rawBody.split("\n").map((line) => line.trim()).filter((line) => line.length > 0).join(" ");
4489
+ const body = rawBody.split("\n").map((line) => line.trim()).filter((line) => line.length > 0).join(" ").replace(/\s*\|\s*/g, " ").replace(/\s+/g, " ").trim();
4465
4490
  return {
4466
4491
  subject: subject.trim(),
4467
- body: body.length > COMMIT_BODY_LIMIT ? body.slice(0, COMMIT_BODY_LIMIT - 1) + "\u2026" : body
4492
+ body: truncateAtSentence(body, COMMIT_BODY_LIMIT)
4468
4493
  };
4469
4494
  }).filter((commit) => commit.subject.length > 0);
4470
4495
  } catch {
@@ -5392,6 +5417,7 @@ function resolvePromptTask(value) {
5392
5417
  'promptTask must be one of "audit", "review" or "explain" (received ' + describeValue2(value) + ")."
5393
5418
  );
5394
5419
  }
5420
+ var MAX_BRIEF_BYTES = 64 * 1024;
5395
5421
  function readConfiguredBrief(cwd, value) {
5396
5422
  if (value === void 0 || value === null) return void 0;
5397
5423
  if (typeof value !== "string" || value.trim().length === 0) {
@@ -5409,6 +5435,12 @@ function readConfiguredBrief(cwd, value) {
5409
5435
  'brief "' + value + '" could not be read as a file; a snapshot must not ship without the half of the brief the owner wrote.'
5410
5436
  );
5411
5437
  }
5438
+ const bytes = Buffer.byteLength(text2, "utf8");
5439
+ if (bytes > MAX_BRIEF_BYTES) {
5440
+ throw new Error(
5441
+ 'brief "' + value + '" is ' + bytes + " bytes; the limit is " + MAX_BRIEF_BYTES + ". Keep it to what a reader can act on, or move the detail into a document the snapshot carries."
5442
+ );
5443
+ }
5412
5444
  const parsed = parseOwnerBrief(value, text2);
5413
5445
  if (parsed.problems.length > 0) {
5414
5446
  throw new Error(
@@ -6875,6 +6907,7 @@ function generatePrompt(manifest, artifacts, context = {}) {
6875
6907
  const brief = context.brief;
6876
6908
  const wrote = (name) => artifacts?.[name] !== false;
6877
6909
  const code = (value) => inlineCode(escapeControls(value));
6910
+ const text2 = (value) => escapeControls(value);
6878
6911
  const hasOwnerHistory = (brief?.history ?? "").trim().length > 0;
6879
6912
  const lines = [
6880
6913
  "# PROMPT.md",
@@ -6893,18 +6926,18 @@ function generatePrompt(manifest, artifacts, context = {}) {
6893
6926
  "the snapshot is what exists.",
6894
6927
  ""
6895
6928
  ];
6896
- if (brief?.preamble !== void 0) lines.push(brief.preamble, "");
6929
+ if (brief?.preamble !== void 0) lines.push(text2(brief.preamble), "");
6897
6930
  lines.push(...jobSection(task, history.length > 0 || hasOwnerHistory), "");
6898
- lines.push(...stakesSection(brief, code));
6931
+ lines.push(...stakesSection(brief, code, text2));
6899
6932
  lines.push(...haveSection(wrote), "");
6900
- lines.push(...whatThisIsSection(overview), "");
6901
- lines.push(...systemSection(manifest, code, brief), "");
6902
- lines.push(...historySection(history, brief, code), "");
6903
- lines.push(...barSection(brief, code), "");
6933
+ lines.push(...whatThisIsSection(overview, text2), "");
6934
+ lines.push(...systemSection(manifest, code, brief, text2), "");
6935
+ lines.push(...historySection(history, brief, code, text2), "");
6936
+ lines.push(...barSection(brief, code, text2), "");
6904
6937
  lines.push(...coverageSection(manifest, code, wrote("audit")), "");
6905
6938
  lines.push(...answerSection(), "");
6906
- lines.push(...calibrationSection(brief, code), "");
6907
- lines.push(...ownerNotesSection(brief, code));
6939
+ lines.push(...calibrationSection(brief, code, text2), "");
6940
+ lines.push(...ownerNotesSection(brief, code, text2));
6908
6941
  lines.push(...snapshotSection(manifest, code), "");
6909
6942
  lines.push(...deliverySection(manifest, wrote("parts"), slots));
6910
6943
  lines.push(
@@ -6983,10 +7016,10 @@ function haveSection(wrote) {
6983
7016
  out.push(...bullets);
6984
7017
  return out;
6985
7018
  }
6986
- function systemSection(manifest, code, brief) {
7019
+ function systemSection(manifest, code, brief, escape) {
6987
7020
  const out = ["## The system", ""];
6988
7021
  if (brief?.system !== void 0) {
6989
- out.push(...ownerBlock(brief.system, brief.path, code), "", "What the index records:", "");
7022
+ out.push(...ownerBlock(brief.system, brief.path, code, escape), "", "What the index records:", "");
6990
7023
  }
6991
7024
  const layers = Object.entries(manifest.layers).sort((a, b) => b[1] - a[1] || a[0].localeCompare(b[0]));
6992
7025
  if (layers.length > 0) {
@@ -7045,9 +7078,9 @@ function systemSection(manifest, code, brief) {
7045
7078
  }
7046
7079
  return out;
7047
7080
  }
7048
- function historySection(history, brief, code) {
7081
+ function historySection(history, brief, code, escape) {
7049
7082
  const out = ["## What came before", ""];
7050
- if (brief?.history !== void 0) out.push(...ownerBlock(brief.history, brief.path, code), "");
7083
+ if (brief?.history !== void 0) out.push(...ownerBlock(brief.history, brief.path, code, escape), "");
7051
7084
  if (history.length === 0) {
7052
7085
  out.push(
7053
7086
  "No history was readable: this is not a git checkout, or git could not be run. Nothing about",
@@ -7056,20 +7089,20 @@ function historySection(history, brief, code) {
7056
7089
  return out;
7057
7090
  }
7058
7091
  out.push(
7059
- "The last " + formatNumber(history.length) + " commit(s), newest first. Subjects and bodies are",
7060
- "claims by whoever wrote them, not evidence - the code beside them is the evidence. If one of",
7061
- "these fixes looks incomplete, quote the lines and say which call site it missed.",
7092
+ "The last " + formatNumber(history.length) + " " + (history.length === 1 ? "commit" : "commits") + ", newest first. Subjects and bodies are claims",
7093
+ "by whoever wrote them, not evidence - the code beside them is the evidence. If one of these",
7094
+ "fixes looks incomplete, quote the lines and say which call site it missed.",
7062
7095
  ""
7063
7096
  );
7064
7097
  for (const commit of history) {
7065
- out.push("- " + commit.subject);
7066
- if (commit.body.length > 0) out.push(" " + commit.body);
7098
+ out.push("- " + escape(commit.subject));
7099
+ if (commit.body.length > 0) out.push(" " + escape(commit.body));
7067
7100
  }
7068
7101
  return out;
7069
7102
  }
7070
- function barSection(brief, code) {
7103
+ function barSection(brief, code, text2) {
7071
7104
  if (brief?.bar !== void 0) {
7072
- return ["## The bar", "", ...ownerBlock(brief.bar, brief.path, code), ""];
7105
+ return ["## The bar", "", ...ownerBlock(brief.bar, brief.path, code, text2), ""];
7073
7106
  }
7074
7107
  return [
7075
7108
  "## The bar",
@@ -7128,9 +7161,9 @@ function answerSection() {
7128
7161
  " the gap you filled by asking instead of guessing."
7129
7162
  ];
7130
7163
  }
7131
- function calibrationSection(brief, code) {
7164
+ function calibrationSection(brief, code, text2) {
7132
7165
  if (brief?.calibration !== void 0) {
7133
- return ["## Calibration", "", ...ownerBlock(brief.calibration, brief.path, code), ""];
7166
+ return ["## Calibration", "", ...ownerBlock(brief.calibration, brief.path, code, text2), ""];
7134
7167
  }
7135
7168
  return [
7136
7169
  "## Calibration",
@@ -7188,20 +7221,20 @@ function jobSection(task, hasHistory) {
7188
7221
  }
7189
7222
  return out;
7190
7223
  }
7191
- function stakesSection(brief, code) {
7224
+ function stakesSection(brief, code, text2) {
7192
7225
  if (brief?.stakes === void 0) return [];
7193
- return ["## Stakes", "", ...ownerBlock(brief.stakes, brief.path, code), ""];
7226
+ return ["## Stakes", "", ...ownerBlock(brief.stakes, brief.path, code, text2), ""];
7194
7227
  }
7195
- function whatThisIsSection(overview) {
7228
+ function whatThisIsSection(overview, escape) {
7196
7229
  const body = [];
7197
7230
  if (overview.description !== void 0) {
7198
- body.push("- Declared in `package.json`: " + overview.description);
7231
+ body.push("- Declared in `package.json`: " + escape(overview.description));
7199
7232
  }
7200
7233
  if (overview.summary !== void 0) {
7201
- body.push("- From the `README.md` first paragraph: " + overview.summary);
7234
+ body.push("- From the `README.md` first paragraph: " + escape(overview.summary));
7202
7235
  }
7203
7236
  if (overview.releases.length > 0) {
7204
- body.push("- Most recent releases: " + overview.releases.join("; ") + ".");
7237
+ body.push("- Most recent releases: " + overview.releases.map(escape).join("; ") + ".");
7205
7238
  }
7206
7239
  if (body.length === 0) return [];
7207
7240
  return [
@@ -7213,16 +7246,16 @@ function whatThisIsSection(overview) {
7213
7246
  ""
7214
7247
  ];
7215
7248
  }
7216
- function ownerNotesSection(brief, code) {
7249
+ function ownerNotesSection(brief, code, text2) {
7217
7250
  if (brief === void 0 || brief.notes.length === 0) return [];
7218
7251
  const out = ["## Owner notes", ""];
7219
7252
  for (const note of brief.notes) {
7220
- out.push("### " + note.heading, "", ...ownerBlock(note.body, brief.path, code), "");
7253
+ out.push("### " + note.heading, "", ...ownerBlock(note.body, brief.path, code, text2), "");
7221
7254
  }
7222
7255
  return out;
7223
7256
  }
7224
- function ownerBlock(text2, path18, code) {
7225
- return ["> Written by the project owner in " + code(path18) + ", not generated.", "", text2];
7257
+ function ownerBlock(body, path18, code, escape) {
7258
+ return ["> Written by the project owner in " + code(path18) + ", not generated.", "", escape(body)];
7226
7259
  }
7227
7260
  function snapshotSection(manifest, code) {
7228
7261
  const out = ["## This snapshot", ""];
@@ -7322,7 +7355,8 @@ function deliverySection(manifest, partsWritten, slots) {
7322
7355
  );
7323
7356
  if (parts > 1) {
7324
7357
  out.push(
7325
- " Either raise `--max-part-bytes` to merge the parts, or set `--max-parts " + slots + "` and let the parts grow to the count instead."
7358
+ " Either raise `--max-part-bytes` to merge the parts, or set",
7359
+ " `--max-parts " + slots + "` and let the parts grow to the count instead."
7326
7360
  );
7327
7361
  }
7328
7362
  } else {
@@ -7860,13 +7894,13 @@ function readDescription(cwd) {
7860
7894
  function readSummary(cwd) {
7861
7895
  const raw = readText(path17__namespace.join(cwd, "README.md"));
7862
7896
  if (raw === null) return {};
7863
- const lines = raw.split(/\r?\n/);
7897
+ 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, "'");
7864
7898
  const paragraph = [];
7865
- for (const line of lines) {
7899
+ for (const line of text2.split(/\r?\n/)) {
7866
7900
  const trimmed = line.trim();
7867
7901
  if (paragraph.length === 0) {
7868
7902
  if (trimmed.length === 0) continue;
7869
- if (/^#/.test(trimmed) || /^!\[/.test(trimmed) || /^</.test(trimmed) || /^[-*|]/.test(trimmed)) continue;
7903
+ if (/^#/.test(trimmed) || /^!\[/.test(trimmed) || /^[-*|]/.test(trimmed)) continue;
7870
7904
  if (/^\[[^\]]+\]:/.test(trimmed)) continue;
7871
7905
  } else if (trimmed.length === 0 || /^#/.test(trimmed)) {
7872
7906
  break;
@@ -7875,12 +7909,18 @@ function readSummary(cwd) {
7875
7909
  }
7876
7910
  const summary = paragraph.join(" ").replace(/\s+/g, " ").trim();
7877
7911
  if (summary.length === 0) return {};
7878
- return { summary: summary.length > SUMMARY_LIMIT ? summary.slice(0, SUMMARY_LIMIT - 1) + "\u2026" : summary };
7912
+ return { summary: truncate(summary, SUMMARY_LIMIT) };
7913
+ }
7914
+ function truncate(text2, limit) {
7915
+ if (text2.length <= limit) return text2;
7916
+ const window = text2.slice(0, limit);
7917
+ const space = window.lastIndexOf(" ");
7918
+ return (space > limit / 2 ? window.slice(0, space) : window).trim() + "\u2026";
7879
7919
  }
7880
7920
  function readReleases(cwd) {
7881
7921
  const raw = readText(path17__namespace.join(cwd, "CHANGELOG.md"));
7882
7922
  if (raw === null) return [];
7883
- const headings = raw.split(/\r?\n/).filter((line) => /^##\s+\S/.test(line)).map((line) => line.replace(/^##\s+/, "").trim());
7923
+ const headings = raw.split(/\r?\n/).map((line) => /^##\s+(.+?)\s*$/.exec(line)?.[1]?.trim()).filter((heading) => heading !== void 0 && /^v?\d+\.\d+/.test(heading));
7884
7924
  return headings.slice(0, MAX_RELEASES);
7885
7925
  }
7886
7926
  var LANGUAGE_BY_EXTENSION = {
@@ -8082,6 +8122,32 @@ function describeManifestShapeProblem(value) {
8082
8122
  if (!config || typeof config !== "object" || Array.isArray(config)) {
8083
8123
  return 'missing "config" object';
8084
8124
  }
8125
+ const recordedConfig = config;
8126
+ const promptTask = recordedConfig.promptTask;
8127
+ if (promptTask !== void 0 && promptTask !== "audit" && promptTask !== "review" && promptTask !== "explain") {
8128
+ return '`config.promptTask` must be "audit", "review" or "explain"';
8129
+ }
8130
+ const recordedBrief = recordedConfig.brief;
8131
+ if (recordedBrief !== void 0) {
8132
+ if (!recordedBrief || typeof recordedBrief !== "object" || Array.isArray(recordedBrief)) {
8133
+ return "`config.brief` must be an object";
8134
+ }
8135
+ const briefRecord = recordedBrief;
8136
+ if (typeof briefRecord.path !== "string" || briefRecord.path.length === 0) {
8137
+ return "`config.brief.path` must be a non-empty string";
8138
+ }
8139
+ if (typeof briefRecord.digest !== "string" || !/^[0-9a-f]{64}$/.test(briefRecord.digest)) {
8140
+ return "`config.brief.digest` must be a sha256 hex digest";
8141
+ }
8142
+ }
8143
+ const recordedSlots = recordedConfig.attachmentSlots;
8144
+ if (recordedSlots !== void 0 && (typeof recordedSlots !== "number" || !Number.isSafeInteger(recordedSlots) || recordedSlots < 0)) {
8145
+ return "`config.attachmentSlots` must be a non-negative integer";
8146
+ }
8147
+ const recordedMaxParts = recordedConfig.maxParts;
8148
+ if (recordedMaxParts !== void 0 && recordedMaxParts !== null && (typeof recordedMaxParts !== "number" || !Number.isSafeInteger(recordedMaxParts) || recordedMaxParts < 1)) {
8149
+ return "`config.maxParts` must be a positive integer or null";
8150
+ }
8085
8151
  const budgets = candidate.budgets;
8086
8152
  if (!budgets || typeof budgets !== "object" || Array.isArray(budgets)) {
8087
8153
  return 'missing "budgets" object';
@@ -11325,6 +11391,7 @@ function maskOwnerBrief(brief, secretRules) {
11325
11391
  const mask = (value) => maskPathText(value, secretRules);
11326
11392
  return {
11327
11393
  ...brief,
11394
+ path: mask(brief.path),
11328
11395
  ...brief.stakes === void 0 ? {} : { stakes: mask(brief.stakes) },
11329
11396
  ...brief.system === void 0 ? {} : { system: mask(brief.system) },
11330
11397
  ...brief.history === void 0 ? {} : { history: mask(brief.history) },
@@ -12598,7 +12665,9 @@ function generateSnapshot(configInput, options) {
12598
12665
  // configuration drift.
12599
12666
  maxParts: config.maxParts ?? null,
12600
12667
  promptTask: config.promptTask,
12601
- ...config.brief === void 0 ? {} : { brief: { path: config.brief.path, digest: config.brief.digest } },
12668
+ // The path is user input like every other name in this block: a credential-shaped
12669
+ // directory in it would otherwise be echoed into the manifest and PROMPT.md unmasked.
12670
+ ...config.brief === void 0 ? {} : { brief: { path: maskName(config.brief.path), digest: config.brief.digest } },
12602
12671
  discovery: config.discovery ?? "auto",
12603
12672
  // A changed-files scope decides which files are in the snapshot, so the manifest that
12604
12673
  // describes the run has to name it.
package/dist/index.d.cts CHANGED
@@ -548,7 +548,7 @@ declare function validateSnapshot(configInput: ResolvedSnapshotConfig | Snapshot
548
548
  * `package.json` carries the same version; `npm run verify` compares the two.
549
549
  */
550
550
  declare const GENERATOR_NAME = "codebase-snapshot";
551
- declare const GENERATOR_VERSION = "0.12.0";
551
+ declare const GENERATOR_VERSION = "0.12.2";
552
552
  /**
553
553
  * The manifest and ownership-marker schema this build writes and understands.
554
554
  *
package/dist/index.d.ts CHANGED
@@ -548,7 +548,7 @@ declare function validateSnapshot(configInput: ResolvedSnapshotConfig | Snapshot
548
548
  * `package.json` carries the same version; `npm run verify` compares the two.
549
549
  */
550
550
  declare const GENERATOR_NAME = "codebase-snapshot";
551
- declare const GENERATOR_VERSION = "0.12.0";
551
+ declare const GENERATOR_VERSION = "0.12.2";
552
552
  /**
553
553
  * The manifest and ownership-marker schema this build writes and understands.
554
554
  *
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- export { ARTIFACT_NAMES, CHECK_INTERVAL_MS, CONFIG_KEYS, DEFAULT_ANSWERS, DEFAULT_SECRET_PATTERNS, FAILURE_INTERVAL_MS, GENERATOR_NAME, GENERATOR_VERSION, HOOK_MARKER, LANGUAGE_PROFILES, MIN_MAX_PART_BYTES, MIN_MAX_PART_TOKENS, PACKAGE_LATEST_URL, PRESETS, PromptBack, PromptCancelled, REQUEST_TIMEOUT_MS, SCHEMA_VERSION, UP_TO_DATE_INTERVAL_MS, anchorForPath, appendGitignoreEntries, assertReplaceable, assertUsableConfigInput, buildImportResolver, bytesForTokens, cacheDirectory, cacheFilePath, checkForUpdate, classifyKind, classifyLayer, collectFiles, compareManifests, configDigest, countInvalidUtf8Bytes, countLines, decodeText, defineConfig, detectLanguage, detectPreset, displayPath, displayWidth, enforceBudget, estimateTokens, explainPath, fenceForContent, fenceForText, fetchLatestVersion, findSecretInPath, firstRunMessage, formatTokens, formatUpdateNotice, generateProjectTree, generateSarifReport, generateSnapshot, generateSnapshotAsync, getGitInfo, getPreset, gitignorePath, globToRegExp, hasPriorSnapshot, importsChangedFile, importsOfFile, importsOfText, installKind, installPreCommitHook, isBinaryBuffer, isBinaryExtension, isBinaryFile, isEffectivelyEmpty, isInteractive, isNewer, isResolvedConfig, isSensitivePath, isSkeletonizable, isTsxFileName, listPresetNames, loadConfigFile, loadConfigFileDetailed, loadManifest, lockPathFor, markResolvedConfig, matchRule, matchesExclude, normalizeResolvedConfig, parseByteSize, partitionFiles, planFirstRun, profileForPath, renderConfig, renderDiffText, renderExplainText, renumberParts, resolveChangedScope, resolveConfig, resolveSafeOutputDirs, resolveSpecifier, runInit, scanAndRedactSecrets, shouldCheck, skeletonizeTypeScript, stripJsonComments, summarizeJson, summarizeMarkdown, summarizeTypeScriptSource, summarizeWithProfile, supportsTypeScriptImports, treeTruncationWarnings, truncatePreview, truncateToBytes, tsconfigPathsFor, updateCommand, validateSnapshot, workerEntry, wrapLines } from './chunk-6HXDYIJS.js';
1
+ export { ARTIFACT_NAMES, CHECK_INTERVAL_MS, CONFIG_KEYS, DEFAULT_ANSWERS, DEFAULT_SECRET_PATTERNS, FAILURE_INTERVAL_MS, GENERATOR_NAME, GENERATOR_VERSION, HOOK_MARKER, LANGUAGE_PROFILES, MIN_MAX_PART_BYTES, MIN_MAX_PART_TOKENS, PACKAGE_LATEST_URL, PRESETS, PromptBack, PromptCancelled, REQUEST_TIMEOUT_MS, SCHEMA_VERSION, UP_TO_DATE_INTERVAL_MS, anchorForPath, appendGitignoreEntries, assertReplaceable, assertUsableConfigInput, buildImportResolver, bytesForTokens, cacheDirectory, cacheFilePath, checkForUpdate, classifyKind, classifyLayer, collectFiles, compareManifests, configDigest, countInvalidUtf8Bytes, countLines, decodeText, defineConfig, detectLanguage, detectPreset, displayPath, displayWidth, enforceBudget, estimateTokens, explainPath, fenceForContent, fenceForText, fetchLatestVersion, findSecretInPath, firstRunMessage, formatTokens, formatUpdateNotice, generateProjectTree, generateSarifReport, generateSnapshot, generateSnapshotAsync, getGitInfo, getPreset, gitignorePath, globToRegExp, hasPriorSnapshot, importsChangedFile, importsOfFile, importsOfText, installKind, installPreCommitHook, isBinaryBuffer, isBinaryExtension, isBinaryFile, isEffectivelyEmpty, isInteractive, isNewer, isResolvedConfig, isSensitivePath, isSkeletonizable, isTsxFileName, listPresetNames, loadConfigFile, loadConfigFileDetailed, loadManifest, lockPathFor, markResolvedConfig, matchRule, matchesExclude, normalizeResolvedConfig, parseByteSize, partitionFiles, planFirstRun, profileForPath, renderConfig, renderDiffText, renderExplainText, renumberParts, resolveChangedScope, resolveConfig, resolveSafeOutputDirs, resolveSpecifier, runInit, scanAndRedactSecrets, shouldCheck, skeletonizeTypeScript, stripJsonComments, summarizeJson, summarizeMarkdown, summarizeTypeScriptSource, summarizeWithProfile, supportsTypeScriptImports, treeTruncationWarnings, truncatePreview, truncateToBytes, tsconfigPathsFor, updateCommand, validateSnapshot, workerEntry, wrapLines } from './chunk-74ZAF64D.js';
package/dist/mcp.cjs CHANGED
@@ -294,7 +294,23 @@ function parseOwnerBrief(filePath, text) {
294
294
  const preamble = [];
295
295
  const sections = [];
296
296
  let current = null;
297
+ let fence = null;
297
298
  for (const line of source.split(/\r?\n/)) {
299
+ const fenceLine = /^ {0,3}(`{3,}|~{3,})/.exec(line);
300
+ if (fenceLine) {
301
+ const marker = fenceLine[1];
302
+ const char = marker[0];
303
+ if (fence === null) fence = { char, length: marker.length };
304
+ else if (char === fence.char && marker.length >= fence.length) fence = null;
305
+ if (current) current.body.push(line);
306
+ else preamble.push(line);
307
+ continue;
308
+ }
309
+ if (fence !== null) {
310
+ if (current) current.body.push(line);
311
+ else preamble.push(line);
312
+ continue;
313
+ }
298
314
  const heading = /^##\s+(.+?)\s*$/.exec(line);
299
315
  if (heading) {
300
316
  current = { heading: heading[1], body: [] };
@@ -306,7 +322,7 @@ function parseOwnerBrief(filePath, text) {
306
322
  }
307
323
  const recognised = {};
308
324
  const notes = [];
309
- const canonical = (heading) => heading.trim().toLowerCase().replace(/\s+/g, " ");
325
+ const canonical = (heading) => heading.trim().replace(/[:.]+$/, "").trim().toLowerCase().replace(/\s+/g, " ");
310
326
  const canonicalOwner = new Map(OWNER_SECTIONS.map((name) => [canonical(name), name]));
311
327
  const canonicalReserved = new Set(RESERVED_SECTIONS.map(canonical));
312
328
  const seen = /* @__PURE__ */ new Set();
@@ -2522,7 +2538,7 @@ function applySpansKeepingQuotes(line, spans) {
2522
2538
 
2523
2539
  // src/version.ts
2524
2540
  var GENERATOR_NAME = "codebase-snapshot";
2525
- var GENERATOR_VERSION = "0.12.0";
2541
+ var GENERATOR_VERSION = "0.12.2";
2526
2542
  var SCHEMA_VERSION = "3.0.0";
2527
2543
  var LEGACY_GENERATOR_NAMES = ["@ankurhalder/codebase-snapshot"];
2528
2544
  function isOurGeneratorName(name) {
@@ -3867,6 +3883,7 @@ function resolvePromptTask(value) {
3867
3883
  'promptTask must be one of "audit", "review" or "explain" (received ' + describeValue2(value) + ")."
3868
3884
  );
3869
3885
  }
3886
+ var MAX_BRIEF_BYTES = 64 * 1024;
3870
3887
  function readConfiguredBrief(cwd, value) {
3871
3888
  if (value === void 0 || value === null) return void 0;
3872
3889
  if (typeof value !== "string" || value.trim().length === 0) {
@@ -3884,6 +3901,12 @@ function readConfiguredBrief(cwd, value) {
3884
3901
  'brief "' + value + '" could not be read as a file; a snapshot must not ship without the half of the brief the owner wrote.'
3885
3902
  );
3886
3903
  }
3904
+ const bytes = Buffer.byteLength(text, "utf8");
3905
+ if (bytes > MAX_BRIEF_BYTES) {
3906
+ throw new Error(
3907
+ 'brief "' + value + '" is ' + bytes + " bytes; the limit is " + MAX_BRIEF_BYTES + ". Keep it to what a reader can act on, or move the detail into a document the snapshot carries."
3908
+ );
3909
+ }
3887
3910
  const parsed = parseOwnerBrief(value, text);
3888
3911
  if (parsed.problems.length > 0) {
3889
3912
  throw new Error(
@@ -6418,6 +6441,32 @@ function describeManifestShapeProblem(value) {
6418
6441
  if (!config || typeof config !== "object" || Array.isArray(config)) {
6419
6442
  return 'missing "config" object';
6420
6443
  }
6444
+ const recordedConfig = config;
6445
+ const promptTask = recordedConfig.promptTask;
6446
+ if (promptTask !== void 0 && promptTask !== "audit" && promptTask !== "review" && promptTask !== "explain") {
6447
+ return '`config.promptTask` must be "audit", "review" or "explain"';
6448
+ }
6449
+ const recordedBrief = recordedConfig.brief;
6450
+ if (recordedBrief !== void 0) {
6451
+ if (!recordedBrief || typeof recordedBrief !== "object" || Array.isArray(recordedBrief)) {
6452
+ return "`config.brief` must be an object";
6453
+ }
6454
+ const briefRecord = recordedBrief;
6455
+ if (typeof briefRecord.path !== "string" || briefRecord.path.length === 0) {
6456
+ return "`config.brief.path` must be a non-empty string";
6457
+ }
6458
+ if (typeof briefRecord.digest !== "string" || !/^[0-9a-f]{64}$/.test(briefRecord.digest)) {
6459
+ return "`config.brief.digest` must be a sha256 hex digest";
6460
+ }
6461
+ }
6462
+ const recordedSlots = recordedConfig.attachmentSlots;
6463
+ if (recordedSlots !== void 0 && (typeof recordedSlots !== "number" || !Number.isSafeInteger(recordedSlots) || recordedSlots < 0)) {
6464
+ return "`config.attachmentSlots` must be a non-negative integer";
6465
+ }
6466
+ const recordedMaxParts = recordedConfig.maxParts;
6467
+ if (recordedMaxParts !== void 0 && recordedMaxParts !== null && (typeof recordedMaxParts !== "number" || !Number.isSafeInteger(recordedMaxParts) || recordedMaxParts < 1)) {
6468
+ return "`config.maxParts` must be a positive integer or null";
6469
+ }
6421
6470
  const budgets = candidate.budgets;
6422
6471
  if (!budgets || typeof budgets !== "object" || Array.isArray(budgets)) {
6423
6472
  return 'missing "budgets" object';
@@ -9259,7 +9308,7 @@ function buildAgentContract() {
9259
9308
  type: "string",
9260
9309
  default: "unset",
9261
9310
  appliesTo: optionAppliesTo("brief"),
9262
- summary: "Path to the owner-written half of PROMPT.md: Stakes, The system, What came before, The bar and Calibration replace or extend the generated prose; any other heading is kept as Owner notes. The measured headings cannot be redefined. A missing file is an error and an edited file is config drift."
9311
+ summary: "Path to the owner-written half of PROMPT.md: Stakes, The system, What came before, The bar and Calibration replace or extend the generated prose; any other heading is kept as Owner notes. The measured headings cannot be redefined; fenced code is content, not headings. The file is capped at 64 KiB. A missing file is an error and an edited file is config drift."
9263
9312
  },
9264
9313
  {
9265
9314
  flag: "--prompt-task",
@@ -9779,6 +9828,8 @@ function ensureSingleRead(uri, text, advice) {
9779
9828
  }
9780
9829
  var MANIFEST_ADVICE = "Cutting a JSON document at the limit leaves invalid JSON, so this resource is never truncated. Use the snapshot_locate, snapshot_read and snapshot_status tools instead \u2014 they read the manifest directly \u2014 or read manifest.json from the snapshot directory.";
9781
9830
  var PART_ADVICE = "A part cut at the limit is a fragment of a file, not the file. Use snapshot_locate to find the file inside this part that you need, then snapshot_read for a bounded window of it.";
9831
+ var PROMPT_URI = "snapshot://prompt";
9832
+ var PROMPT_ADVICE = "PROMPT.md is written whole and never truncated; regenerate it with snapshot_generate, then read it from the snapshot directory.";
9782
9833
  var REPORT_ADVICE = "A report cut at the limit would look complete and would not be. Read it from the snapshot directory instead: the file on disk is complete.";
9783
9834
  var PART_URI = /^snapshot:\/\/parts\/(\d+)$/;
9784
9835
  var REPORT_URIS = /* @__PURE__ */ new Map([
@@ -9829,6 +9880,13 @@ function buildResourceProvider() {
9829
9880
  title: "Agent skill",
9830
9881
  description: "Usage guidance for an agent working with this tool.",
9831
9882
  mimeType: "text/markdown"
9883
+ },
9884
+ {
9885
+ uri: PROMPT_URI,
9886
+ name: "prompt",
9887
+ title: "Snapshot brief",
9888
+ description: "The brief for this snapshot: the job, what the snapshot contains, what it omits, the history it was built from and the standard the answer is held to. Read this before the parts; it names which part holds which file.",
9889
+ mimeType: "text/markdown"
9832
9890
  }
9833
9891
  ];
9834
9892
  for (const [uri, report] of REPORT_URIS) {
@@ -9893,6 +9951,13 @@ function buildResourceProvider() {
9893
9951
  }
9894
9952
  const workspace = await workspaceFor(context);
9895
9953
  if ("error" in workspace) return null;
9954
+ if (uri === PROMPT_URI) {
9955
+ const text = readFileIfPresent(
9956
+ path5__namespace.resolve(workspace.root, workspace.config.outDir, "PROMPT.md")
9957
+ );
9958
+ if (text === null) return null;
9959
+ return { uri, mimeType: "text/markdown", text: ensureSingleRead(uri, text, PROMPT_ADVICE) };
9960
+ }
9896
9961
  const report = REPORT_URIS.get(uri);
9897
9962
  if (report) {
9898
9963
  const text = readFileIfPresent(
package/dist/mcp.js CHANGED
@@ -1,2 +1,2 @@
1
- export { ERROR_CODES, LEGACY_PROTOCOL_VERSIONS, MAX_LINE_BYTES, METHOD, MODERN_PROTOCOL_VERSIONS, SERVER_INSTRUCTIONS, SUPPORTED_PROTOCOL_VERSIONS, buildPrompts, buildResourceProvider, buildTools, classifyRequest, coerceNumericStrings, createLineReader, createMcpServer, createServer, createSession, createWriter, findSection, inspectModernMeta, negotiateLegacyVersion, parsePartSections, runStdioServer, validateArguments, windowText } from './chunk-5FPYVWP3.js';
2
- export { generateInWorker } from './chunk-6HXDYIJS.js';
1
+ export { ERROR_CODES, LEGACY_PROTOCOL_VERSIONS, MAX_LINE_BYTES, METHOD, MODERN_PROTOCOL_VERSIONS, SERVER_INSTRUCTIONS, SUPPORTED_PROTOCOL_VERSIONS, buildPrompts, buildResourceProvider, buildTools, classifyRequest, coerceNumericStrings, createLineReader, createMcpServer, createServer, createSession, createWriter, findSection, inspectModernMeta, negotiateLegacyVersion, parsePartSections, runStdioServer, validateArguments, windowText } from './chunk-BITMWXYS.js';
2
+ export { generateInWorker } from './chunk-74ZAF64D.js';
package/docs/cli.md CHANGED
@@ -97,7 +97,7 @@ Exit `0` when the snapshot passes its own integrity check, `1` when it does not.
97
97
 
98
98
  ```
99
99
  📸 Generating snapshot for: /path/to/repo
100
- Branch: main | Part budget: 300 KB | Generator: 0.12.0 (project dependency ^0.12.0)
100
+ Branch: main | Part budget: 300 KB | Generator: 0.12.2 (project dependency ^0.12.2)
101
101
 
102
102
  ✅ Snapshot generated in 0.14s:
103
103
  - Tracked files: 121 included of 128 paths found — 7 skipped (default-ignore 5, binary 1, sensitive-file 1); every one is listed in snapshot/reports/audit.md
@@ -192,7 +192,7 @@ The whole first run in one command, with defaults and no prompts. This is the sa
192
192
  🚀 Setup for: /path/to/repo
193
193
  ✅ Created snapshot.config.ts (preset: nextjs)
194
194
  Added npm scripts: snapshot, snapshot:validate
195
- Added devDependency: codebase-snapshot ^0.12.0
195
+ Added devDependency: codebase-snapshot ^0.12.2
196
196
  Added to .gitignore: /snapshot/, /snapshot.tmp/
197
197
  ⏳ Installing dependencies…
198
198
  ✅ Installed dependencies (npm install, 2.1s)
@@ -244,7 +244,7 @@ It also has three side effects on files you own, and it says so when it does the
244
244
  ```
245
245
  ✅ Created snapshot.config.ts (preset: node-lib)
246
246
  Added npm scripts: snapshot, snapshot:validate
247
- Added devDependency: codebase-snapshot ^0.12.0
247
+ Added devDependency: codebase-snapshot ^0.12.2
248
248
  Added to .gitignore: /snapshot/, /snapshot.tmp/
249
249
  ```
250
250
 
@@ -336,6 +336,11 @@ Any other `##` heading is kept, verbatim, under **Owner notes** — nothing is d
336
336
  merge did not recognise it. Every owner section is marked in the output as written by the project
337
337
  owner, so a reader can tell an assertion from a measurement.
338
338
 
339
+ A brief is capped at 64 KiB: past that it is a second codebase rather than instruction, and
340
+ the error names the size. Text inside a fenced code block is content — a sample `## Coverage` in a
341
+ documentation example is not a section — and `## Stakes:` is read as `## Stakes`, because the
342
+ colon is a typo rather than a different heading.
343
+
339
344
  Three things are refused because they would make the document lie:
340
345
 
341
346
  - a heading that redefines a **measured** section (`Coverage`, `This snapshot`, `Attaching this`,
package/docs/mcp.md CHANGED
@@ -10,7 +10,7 @@ walk — that the client sees.
10
10
  ## Start it
11
11
 
12
12
  ```bash
13
- npx -y codebase-snapshot@0.12.0 mcp
13
+ npx -y codebase-snapshot@0.12.2 mcp
14
14
  ```
15
15
 
16
16
  The server serves the directory it was started in. `--cwd <path>` points it elsewhere, and that
@@ -25,7 +25,7 @@ Claude Desktop and Cursor:
25
25
  "mcpServers": {
26
26
  "codebase-snapshot": {
27
27
  "command": "npx",
28
- "args": ["-y", "codebase-snapshot@0.12.0", "mcp", "--cwd", "/absolute/path/to/repo"]
28
+ "args": ["-y", "codebase-snapshot@0.12.2", "mcp", "--cwd", "/absolute/path/to/repo"]
29
29
  }
30
30
  }
31
31
  }
@@ -34,7 +34,7 @@ Claude Desktop and Cursor:
34
34
  Claude Code registers the same thing from a shell:
35
35
 
36
36
  ```bash
37
- claude mcp add codebase-snapshot -- npx -y codebase-snapshot@0.12.0 mcp --cwd /absolute/path/to/repo
37
+ claude mcp add codebase-snapshot -- npx -y codebase-snapshot@0.12.2 mcp --cwd /absolute/path/to/repo
38
38
  ```
39
39
 
40
40
  On Windows, wrap the command as `cmd /c npx` with the same arguments — `npx` is a `.cmd` shim
@@ -106,6 +106,7 @@ Resources are the browse surface; tools are the act surface.
106
106
  | `snapshot://reports/audit` | Secret findings, large files, parse diagnostics |
107
107
  | `snapshot://reports/tree` | The directory tree of included files |
108
108
  | `snapshot://reports/navigation` | File-to-part lookup |
109
+ | `snapshot://prompt` | `PROMPT.md` — the brief: the job, what the snapshot contains and omits, the history it was built from, and the owner half when a `brief` is configured |
109
110
  | `snapshot://contract` | The machine-readable CLI contract |
110
111
  | `snapshot://skill` | The agent skill, as one read |
111
112
 
@@ -116,7 +117,7 @@ JSON-RPC error `-32000` (the implementation-defined server-error range) and
116
117
  the CLI for the contract or the skill. It never returns a truncated document: half a JSON manifest
117
118
  does not parse, and half a part is a fragment that looks complete. The rule applies to every
118
119
  resource — `snapshot://manifest`, each `snapshot://parts/{index}`, the three reports,
119
- `snapshot://contract` and `snapshot://skill`.
120
+ `snapshot://prompt`, `snapshot://contract` and `snapshot://skill`.
120
121
 
121
122
  Part resources carry their size in the description, so a client choosing between them can see that
122
123
  one is 300 kB before attaching it; a part above the limit says in its description that it will be
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codebase-snapshot",
3
- "version": "0.12.0",
3
+ "version": "0.12.2",
4
4
  "description": "Create a codebase snapshot an LLM can read: budgeted Markdown parts for Claude, ChatGPT and Cursor, a manifest of every included and skipped file, secret redaction, and validate, which fails when the snapshot drifts. Local CLI and MCP server.",
5
5
  "keywords": [
6
6
  "codebase-snapshot",