codebase-snapshot 0.13.0 → 0.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/mcp.cjs CHANGED
@@ -2548,7 +2548,7 @@ function applySpansKeepingQuotes(line, spans) {
2548
2548
 
2549
2549
  // src/version.ts
2550
2550
  var GENERATOR_NAME = "codebase-snapshot";
2551
- var GENERATOR_VERSION = "0.13.0";
2551
+ var GENERATOR_VERSION = "0.14.0";
2552
2552
  var SCHEMA_VERSION = "3.0.0";
2553
2553
  var LEGACY_GENERATOR_NAMES = ["@ankurhalder/codebase-snapshot"];
2554
2554
  function isOurGeneratorName(name) {
@@ -8029,6 +8029,92 @@ function verifySnapshotSignature(snapshotDir) {
8029
8029
  return verified ? { ok: true, record } : { ok: false, reason: "the signature does not match the manifest" };
8030
8030
  }
8031
8031
 
8032
+ // src/partitioner/part-format.ts
8033
+ var FILE_HEADING = "### FILE: ";
8034
+ var CONTENT_MARKERS = /* @__PURE__ */ new Set(["#### Content", "#### Bounded Preview"]);
8035
+ var ANCHOR_LINE = /^<a id="([^"]+)"><\/a>$/;
8036
+ var META_PREFIX = "- Meta: ";
8037
+ var LEGACY_INCLUSION_PREFIX = "- Inclusion: ";
8038
+ var LEGACY_INCLUDED_LINES_PREFIX = "- Included Lines: ";
8039
+ var INCLUSION_MODES = /* @__PURE__ */ new Set(["full", "preview", "signatures"]);
8040
+ var COMPACT_COUNTS = /^(\d+)\s+lines?(?:\s+of\s+\d+\s+lines?)?/;
8041
+ function readIncludedLines(fields) {
8042
+ const last = fields[fields.length - 1];
8043
+ if (last === void 0) return null;
8044
+ const counts = COMPACT_COUNTS.exec(last.trim());
8045
+ return counts === null ? null : Number(counts[1]);
8046
+ }
8047
+ function parsePartSections(partText) {
8048
+ const lines = partText.split("\n");
8049
+ const sections = [];
8050
+ let index = 0;
8051
+ while (index < lines.length) {
8052
+ if (!lines[index].startsWith(FILE_HEADING)) {
8053
+ index += 1;
8054
+ continue;
8055
+ }
8056
+ const heading = lines[index].slice(FILE_HEADING.length);
8057
+ const anchorMatch = index > 0 ? ANCHOR_LINE.exec(lines[index - 1]) : null;
8058
+ let cursor = index + 1;
8059
+ let inclusion = null;
8060
+ let includedLines = null;
8061
+ while (cursor < lines.length && !CONTENT_MARKERS.has(lines[cursor])) {
8062
+ const line = lines[cursor];
8063
+ if (line.startsWith(FILE_HEADING)) break;
8064
+ if (line.startsWith(META_PREFIX)) {
8065
+ const fields = line.slice(META_PREFIX.length).split("|");
8066
+ for (const field of fields) {
8067
+ const value = field.trim();
8068
+ if (INCLUSION_MODES.has(value)) inclusion = value;
8069
+ }
8070
+ includedLines = readIncludedLines(fields);
8071
+ } else if (line.startsWith(LEGACY_INCLUSION_PREFIX)) {
8072
+ inclusion = line.slice(LEGACY_INCLUSION_PREFIX.length).trim();
8073
+ } else if (line.startsWith(LEGACY_INCLUDED_LINES_PREFIX)) {
8074
+ const value = Number(line.slice(LEGACY_INCLUDED_LINES_PREFIX.length).trim());
8075
+ includedLines = Number.isFinite(value) ? value : null;
8076
+ }
8077
+ cursor += 1;
8078
+ }
8079
+ if (cursor >= lines.length || !CONTENT_MARKERS.has(lines[cursor])) {
8080
+ index = cursor + 1;
8081
+ continue;
8082
+ }
8083
+ let fenceLine = cursor + 1;
8084
+ while (fenceLine < lines.length && lines[fenceLine].trim().length === 0) fenceLine += 1;
8085
+ const fenceMatch = /^(`{4,})/.exec(lines[fenceLine] ?? "");
8086
+ if (!fenceMatch) {
8087
+ index = cursor + 1;
8088
+ continue;
8089
+ }
8090
+ const fence = fenceMatch[1];
8091
+ const body = [];
8092
+ let bodyLine = fenceLine + 1;
8093
+ while (bodyLine < lines.length && lines[bodyLine] !== fence) {
8094
+ body.push(lines[bodyLine]);
8095
+ bodyLine += 1;
8096
+ }
8097
+ sections.push({ path: heading, anchor: anchorMatch?.[1] ?? null, body: body.join("\n"), inclusion, includedLines });
8098
+ index = bodyLine + 1;
8099
+ }
8100
+ return sections;
8101
+ }
8102
+ function findSection(sections, relativePath) {
8103
+ const anchor = anchorForPath(relativePath);
8104
+ const byAnchor = sections.find((section) => section.anchor === anchor);
8105
+ if (byAnchor) return byAnchor;
8106
+ const rendered = displayPath(relativePath);
8107
+ const samePath = (section) => section.path === relativePath || section.path === rendered;
8108
+ const exact = sections.find(samePath);
8109
+ if (exact) return exact;
8110
+ const foldedPath = rendered.toLowerCase();
8111
+ const folded = sections.filter((section) => {
8112
+ const path16 = section.path.toLowerCase();
8113
+ return path16 === relativePath.toLowerCase() || path16 === foldedPath;
8114
+ });
8115
+ return folded.length === 1 ? folded[0] : null;
8116
+ }
8117
+
8032
8118
  // src/auditor/health.ts
8033
8119
  var ARTIFACT_FILES = {
8034
8120
  readme: "README.md",
@@ -8338,6 +8424,206 @@ function auditSnapshot(options) {
8338
8424
  )
8339
8425
  );
8340
8426
  }
8427
+ const bookkeeping = [];
8428
+ const expect = (name, recorded2, computed) => {
8429
+ if (recorded2 !== computed) bookkeeping.push(name + ": manifest says " + recorded2 + ", the data has " + computed);
8430
+ };
8431
+ expect("counts.totalFiles", manifest.counts.totalFiles, manifest.files.length);
8432
+ expect("counts.partsCount", manifest.counts.partsCount, manifest.parts.length);
8433
+ expect("counts.skippedCount", manifest.counts.skippedCount, manifest.skipped.length);
8434
+ if (typeof manifest.totals.includedFiles === "number") {
8435
+ expect("totals.includedFiles", manifest.totals.includedFiles, manifest.files.length);
8436
+ }
8437
+ const contentBytes = manifest.files.reduce((sum, file) => sum + file.includedBytes, 0);
8438
+ expect("totals.totalContentBytes", manifest.totals.totalContentBytes, contentBytes);
8439
+ const layerCounts = /* @__PURE__ */ new Map();
8440
+ for (const file of manifest.files) layerCounts.set(file.layer, (layerCounts.get(file.layer) ?? 0) + 1);
8441
+ for (const [layer2, count] of layerCounts) {
8442
+ expect("layers." + layer2, manifest.layers[layer2] ?? -1, count);
8443
+ }
8444
+ for (const layer2 of Object.keys(manifest.layers)) {
8445
+ if (!layerCounts.has(layer2)) expect("layers." + layer2, manifest.layers[layer2], 0);
8446
+ }
8447
+ checks.push(
8448
+ bookkeeping.length === 0 ? check(
8449
+ "bookkeeping",
8450
+ "The counts equal the data they summarise",
8451
+ "critical",
8452
+ "pass",
8453
+ "Files, parts, skips, content bytes and layer counts all agree."
8454
+ ) : check(
8455
+ "bookkeeping",
8456
+ "The counts equal the data they summarise",
8457
+ "critical",
8458
+ "fail",
8459
+ bookkeeping.length + " mismatch(es): " + sample(bookkeeping)
8460
+ )
8461
+ );
8462
+ const packReaders = [
8463
+ {
8464
+ key: "fullJson",
8465
+ file: "full-codebase.json",
8466
+ label: "JSON",
8467
+ paths: (text) => {
8468
+ try {
8469
+ const parsed = JSON.parse(text);
8470
+ if (!Array.isArray(parsed?.files)) return null;
8471
+ return new Set(parsed.files.map((entry) => String(entry?.relativePath)));
8472
+ } catch {
8473
+ return null;
8474
+ }
8475
+ }
8476
+ },
8477
+ {
8478
+ key: "fullXml",
8479
+ file: "full-codebase.xml",
8480
+ label: "XML",
8481
+ paths: (text) => {
8482
+ const found = [...text.matchAll(/<file path="([^"]+)"/g)].map((match) => match[1]);
8483
+ if (found.length === 0) return null;
8484
+ return new Set(found.map((value) => value.replace(/&quot;/g, '"').replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&amp;/g, "&")));
8485
+ }
8486
+ },
8487
+ {
8488
+ key: "fullMarkdown",
8489
+ file: "full-codebase.md",
8490
+ label: "markdown",
8491
+ paths: (text) => {
8492
+ const found = [...text.matchAll(/^## File: (.+)$/gm)].map((match) => match[1].trim());
8493
+ if (found.length === 0) return null;
8494
+ return new Set(found);
8495
+ }
8496
+ }
8497
+ ];
8498
+ for (const reader of packReaders) {
8499
+ if (manifest.artifacts?.[reader.key] == null) continue;
8500
+ const packText = readText(path5__namespace.join(snapshotDir, reader.file));
8501
+ const problems = [];
8502
+ if (packText === null) {
8503
+ problems.push(reader.file + " is recorded but unreadable");
8504
+ } else {
8505
+ const packed = reader.paths(packText);
8506
+ if (packed === null) {
8507
+ problems.push(reader.file + " could not be parsed for its file list");
8508
+ } else {
8509
+ const known2 = new Set(manifest.files.map((file) => file.relativePath));
8510
+ for (const file of manifest.files) {
8511
+ if (!packed.has(file.relativePath)) problems.push(file.relativePath + " is in the manifest but not the pack");
8512
+ }
8513
+ for (const path16 of packed) {
8514
+ if (!known2.has(path16)) problems.push(path16 + " is in the pack but not the manifest");
8515
+ }
8516
+ }
8517
+ }
8518
+ const title = "The " + reader.label + " pack holds every file the manifest lists";
8519
+ checks.push(
8520
+ problems.length === 0 ? check(
8521
+ "pipeline.monolith",
8522
+ title,
8523
+ "critical",
8524
+ "pass",
8525
+ manifest.files.length + " file(s) present in " + reader.file + ", and nothing extra."
8526
+ ) : check(
8527
+ "pipeline.monolith",
8528
+ title,
8529
+ "critical",
8530
+ "fail",
8531
+ problems.length + " problem(s): " + sample(problems)
8532
+ )
8533
+ );
8534
+ }
8535
+ const bodyProblems = [];
8536
+ let bodiesChecked = 0;
8537
+ for (const part of manifest.parts) {
8538
+ const partText = readText(path5__namespace.join(snapshotDir, "parts", part.filename));
8539
+ if (partText === null) continue;
8540
+ const sections = parsePartSections(partText);
8541
+ for (const file of manifest.files) {
8542
+ if (file.part !== part.filename) continue;
8543
+ const section = findSection(sections, file.relativePath);
8544
+ if (section === null) {
8545
+ bodyProblems.push(file.relativePath + " has no section in " + part.filename);
8546
+ continue;
8547
+ }
8548
+ bodiesChecked += 1;
8549
+ const bytes = Buffer.byteLength(section.body, "utf8");
8550
+ const bodyLines = section.body === "" ? 0 : section.body.split("\n").length - (section.body.endsWith("\n") ? 1 : 0);
8551
+ if (bytes !== file.includedBytes) {
8552
+ bodyProblems.push(file.relativePath + ": manifest says " + file.includedBytes + " B, part holds " + bytes + " B");
8553
+ } else if (bodyLines !== file.includedLines) {
8554
+ bodyProblems.push(file.relativePath + ": manifest says " + file.includedLines + " line(s), part holds " + bodyLines);
8555
+ }
8556
+ }
8557
+ }
8558
+ checks.push(
8559
+ bodyProblems.length === 0 ? check(
8560
+ "pipeline.bodies",
8561
+ "Every file body matches the manifest accounting",
8562
+ "critical",
8563
+ "pass",
8564
+ bodiesChecked + " file body/bodies match their recorded bytes and lines."
8565
+ ) : check(
8566
+ "pipeline.bodies",
8567
+ "Every file body matches the manifest accounting",
8568
+ "critical",
8569
+ "fail",
8570
+ bodyProblems.length + " file(s) disagree: " + sample(bodyProblems)
8571
+ )
8572
+ );
8573
+ const indexParent = path5__namespace.dirname(snapshotDir);
8574
+ const indexPath = path5__namespace.join(indexParent, "WORKSPACE.json");
8575
+ if (fs2__namespace.existsSync(indexPath)) {
8576
+ const indexText = readText(indexPath);
8577
+ let members = [];
8578
+ let problem2 = null;
8579
+ try {
8580
+ const parsed = JSON.parse(indexText ?? "null");
8581
+ if (!Array.isArray(parsed?.members)) problem2 = "its members field is not an array";
8582
+ else members = parsed.members;
8583
+ } catch (error) {
8584
+ problem2 = error.message;
8585
+ }
8586
+ const memberName = path5__namespace.basename(snapshotDir);
8587
+ const member = members.find((entry) => entry.name === memberName);
8588
+ if (problem2 !== null) {
8589
+ checks.push(check(
8590
+ "workspace.index",
8591
+ "The workspace index agrees with this member",
8592
+ "warning",
8593
+ "warn",
8594
+ "WORKSPACE.json could not be read: " + problem2
8595
+ ));
8596
+ } else if (member === void 0) {
8597
+ checks.push(check(
8598
+ "workspace.index",
8599
+ "The workspace index agrees with this member",
8600
+ "warning",
8601
+ "skip",
8602
+ "WORKSPACE.json lists no member named " + memberName + "."
8603
+ ));
8604
+ } else {
8605
+ const disagreements = [];
8606
+ if (member.fingerprint !== manifest.fingerprint) disagreements.push("fingerprint");
8607
+ if (typeof member.files === "number" && member.files !== manifest.counts.totalFiles) {
8608
+ disagreements.push("file count");
8609
+ }
8610
+ checks.push(
8611
+ disagreements.length === 0 ? check(
8612
+ "workspace.index",
8613
+ "The workspace index agrees with this member",
8614
+ "warning",
8615
+ "pass",
8616
+ "Member " + memberName + " matches the index fingerprint and file count."
8617
+ ) : check(
8618
+ "workspace.index",
8619
+ "The workspace index agrees with this member",
8620
+ "warning",
8621
+ "warn",
8622
+ "The index disagrees with this member on: " + disagreements.join(", ") + ". Regenerate the workspace."
8623
+ )
8624
+ );
8625
+ }
8626
+ }
8341
8627
  const rules = [...compileSecretRules(DEFAULT_SECRET_PATTERNS), ...options.secretRules ?? []];
8342
8628
  const scanBudget = options.maxScanBytes ?? 32 * 1024 * 1024;
8343
8629
  const leakHits = [];
@@ -8849,90 +9135,6 @@ function generateInWorker(cwd, cliOptions, options = {}) {
8849
9135
  }
8850
9136
 
8851
9137
  // src/mcp/part.ts
8852
- var FILE_HEADING = "### FILE: ";
8853
- var CONTENT_MARKERS = /* @__PURE__ */ new Set(["#### Content", "#### Bounded Preview"]);
8854
- var ANCHOR_LINE = /^<a id="([^"]+)"><\/a>$/;
8855
- var META_PREFIX = "- Meta: ";
8856
- var LEGACY_INCLUSION_PREFIX = "- Inclusion: ";
8857
- var LEGACY_INCLUDED_LINES_PREFIX = "- Included Lines: ";
8858
- var INCLUSION_MODES = /* @__PURE__ */ new Set(["full", "preview", "signatures"]);
8859
- var COMPACT_COUNTS = /^(\d+)\s+lines?(?:\s+of\s+\d+\s+lines?)?/;
8860
- function readIncludedLines(fields) {
8861
- const last = fields[fields.length - 1];
8862
- if (last === void 0) return null;
8863
- const counts = COMPACT_COUNTS.exec(last.trim());
8864
- return counts === null ? null : Number(counts[1]);
8865
- }
8866
- function parsePartSections(partText) {
8867
- const lines = partText.split("\n");
8868
- const sections = [];
8869
- let index = 0;
8870
- while (index < lines.length) {
8871
- if (!lines[index].startsWith(FILE_HEADING)) {
8872
- index += 1;
8873
- continue;
8874
- }
8875
- const heading = lines[index].slice(FILE_HEADING.length);
8876
- const anchorMatch = index > 0 ? ANCHOR_LINE.exec(lines[index - 1]) : null;
8877
- let cursor = index + 1;
8878
- let inclusion = null;
8879
- let includedLines = null;
8880
- while (cursor < lines.length && !CONTENT_MARKERS.has(lines[cursor])) {
8881
- const line = lines[cursor];
8882
- if (line.startsWith(FILE_HEADING)) break;
8883
- if (line.startsWith(META_PREFIX)) {
8884
- const fields = line.slice(META_PREFIX.length).split("|");
8885
- for (const field of fields) {
8886
- const value = field.trim();
8887
- if (INCLUSION_MODES.has(value)) inclusion = value;
8888
- }
8889
- includedLines = readIncludedLines(fields);
8890
- } else if (line.startsWith(LEGACY_INCLUSION_PREFIX)) {
8891
- inclusion = line.slice(LEGACY_INCLUSION_PREFIX.length).trim();
8892
- } else if (line.startsWith(LEGACY_INCLUDED_LINES_PREFIX)) {
8893
- const value = Number(line.slice(LEGACY_INCLUDED_LINES_PREFIX.length).trim());
8894
- includedLines = Number.isFinite(value) ? value : null;
8895
- }
8896
- cursor += 1;
8897
- }
8898
- if (cursor >= lines.length || !CONTENT_MARKERS.has(lines[cursor])) {
8899
- index = cursor + 1;
8900
- continue;
8901
- }
8902
- let fenceLine = cursor + 1;
8903
- while (fenceLine < lines.length && lines[fenceLine].trim().length === 0) fenceLine += 1;
8904
- const fenceMatch = /^(`{4,})/.exec(lines[fenceLine] ?? "");
8905
- if (!fenceMatch) {
8906
- index = cursor + 1;
8907
- continue;
8908
- }
8909
- const fence = fenceMatch[1];
8910
- const body = [];
8911
- let bodyLine = fenceLine + 1;
8912
- while (bodyLine < lines.length && lines[bodyLine] !== fence) {
8913
- body.push(lines[bodyLine]);
8914
- bodyLine += 1;
8915
- }
8916
- sections.push({ path: heading, anchor: anchorMatch?.[1] ?? null, body: body.join("\n"), inclusion, includedLines });
8917
- index = bodyLine + 1;
8918
- }
8919
- return sections;
8920
- }
8921
- function findSection(sections, relativePath) {
8922
- const anchor = anchorForPath(relativePath);
8923
- const byAnchor = sections.find((section) => section.anchor === anchor);
8924
- if (byAnchor) return byAnchor;
8925
- const rendered = displayPath(relativePath);
8926
- const samePath = (section) => section.path === relativePath || section.path === rendered;
8927
- const exact = sections.find(samePath);
8928
- if (exact) return exact;
8929
- const foldedPath = rendered.toLowerCase();
8930
- const folded = sections.filter((section) => {
8931
- const path16 = section.path.toLowerCase();
8932
- return path16 === relativePath.toLowerCase() || path16 === foldedPath;
8933
- });
8934
- return folded.length === 1 ? folded[0] : null;
8935
- }
8936
9138
  function windowText(body, fromLine, lineCount) {
8937
9139
  const lines = body.split("\n");
8938
9140
  const total = body.length === 0 ? 0 : lines.length;
@@ -13203,12 +13405,23 @@ async function startHttpTransport(options) {
13203
13405
  return fromQuery !== null && timingSafeEqual2(fromQuery, token);
13204
13406
  };
13205
13407
  const sessions = /* @__PURE__ */ new Map();
13408
+ const metrics = {
13409
+ requests: 0,
13410
+ byMethod: /* @__PURE__ */ new Map(),
13411
+ refused: 0,
13412
+ rateLimited: 0};
13413
+ const noteRequest = (request) => {
13414
+ metrics.requests += 1;
13415
+ const method = request.method ?? "UNKNOWN";
13416
+ metrics.byMethod.set(method, (metrics.byMethod.get(method) ?? 0) + 1);
13417
+ };
13206
13418
  const allowedOrigin = (origin) => {
13207
13419
  if (origin === void 0) return null;
13208
13420
  if (isLoopbackOrigin(origin)) return origin;
13209
13421
  return extraOrigins.includes(origin) ? origin : null;
13210
13422
  };
13211
13423
  const httpServer = http__namespace.createServer((request, response) => {
13424
+ noteRequest(request);
13212
13425
  const send = (status, body, extra = {}) => {
13213
13426
  const text = typeof body === "string" ? body : JSON.stringify(body);
13214
13427
  response.writeHead(status, {
@@ -13222,6 +13435,7 @@ async function startHttpTransport(options) {
13222
13435
  const origin = typeof request.headers.origin === "string" ? request.headers.origin : void 0;
13223
13436
  const allowed = allowedOrigin(origin);
13224
13437
  if (origin !== void 0 && allowed === null) {
13438
+ metrics.refused += 1;
13225
13439
  send(403, { error: "origin not allowed" });
13226
13440
  return;
13227
13441
  }
@@ -13251,6 +13465,33 @@ async function startHttpTransport(options) {
13251
13465
  );
13252
13466
  return;
13253
13467
  }
13468
+ if (request.method === "GET" && request.url === "/metrics") {
13469
+ const lines = [
13470
+ "# HELP snapshot_uptime_seconds Seconds since the process started.",
13471
+ "# TYPE snapshot_uptime_seconds gauge",
13472
+ "snapshot_uptime_seconds " + Math.round(process.uptime()),
13473
+ "# HELP snapshot_requests_total HTTP requests received.",
13474
+ "# TYPE snapshot_requests_total counter",
13475
+ "snapshot_requests_total " + metrics.requests,
13476
+ "# HELP snapshot_requests_refused_total Requests refused before dispatch.",
13477
+ "# TYPE snapshot_requests_refused_total counter",
13478
+ "snapshot_requests_refused_total " + metrics.refused,
13479
+ "# HELP snapshot_requests_rate_limited_total Requests rejected by the rate limit.",
13480
+ "# TYPE snapshot_requests_rate_limited_total counter",
13481
+ "snapshot_requests_rate_limited_total " + metrics.rateLimited,
13482
+ "# HELP snapshot_tools Number of tools this server serves.",
13483
+ "# TYPE snapshot_tools gauge",
13484
+ "snapshot_tools " + toolCount
13485
+ ];
13486
+ for (const [method, count] of metrics.byMethod) {
13487
+ lines.push('snapshot_requests_by_method_total{method="' + method + '"} ' + count);
13488
+ }
13489
+ send(200, lines.join("\n") + "\n", {
13490
+ ...cors,
13491
+ "content-type": "text/plain; version=0.0.4; charset=utf-8"
13492
+ });
13493
+ return;
13494
+ }
13254
13495
  const url = new URL(request.url ?? "/", "http://localhost");
13255
13496
  if (request.method === "GET" && url.pathname === "/sse") {
13256
13497
  if (!tokenAccepted(request, url)) {
@@ -13342,6 +13583,7 @@ async function startHttpTransport(options) {
13342
13583
  const window = sessions.get(remote);
13343
13584
  if (window === void 0 || window.resetAt <= now) sessions.set(remote, { count: 1, resetAt: now + RATE_WINDOW_MS });
13344
13585
  else if (window.count >= RATE_LIMIT) {
13586
+ metrics.rateLimited += 1;
13345
13587
  send(429, { error: "too many requests" }, { ...cors, "retry-after": "10" });
13346
13588
  return;
13347
13589
  } else window.count += 1;
package/dist/mcp.d.cts CHANGED
@@ -361,21 +361,6 @@ interface StripResult {
361
361
  }
362
362
  declare function stripComments(text: string, relativePath: string): StripResult;
363
363
 
364
- /**
365
- * Reads one file's section back out of a rendered part.
366
- *
367
- * `snapshot_read` must not open the working tree. The snapshot is the contract: sensitive files
368
- * are excluded from it, secret-shaped strings inside ordinary files are redacted on the way in,
369
- * and a large file is emitted as a bounded preview. Reading the source directly would hand the
370
- * model the `.env` the snapshot deliberately skipped and the credential it masked — so the read
371
- * goes through the artifact instead.
372
- *
373
- * The format it parses is written by `renderFileSection`, and the parser is deliberately tied to
374
- * that shape rather than to a regex over the whole document: a file's *content* may legitimately
375
- * contain a line that looks like `### FILE: something`, and only fence tracking tells the two
376
- * apart. Content fences are four or more backticks (`fenceForContent` never emits three), which
377
- * is what makes "the next line equal to this exact fence" an unambiguous terminator.
378
- */
379
364
  interface PartSection {
380
365
  /** The path as rendered in the `### FILE:` heading. */
381
366
  path: string;
@@ -403,6 +388,12 @@ declare function parsePartSections(partText: string): PartSection[];
403
388
  * was read, or a part whose anchor line was edited by hand.
404
389
  */
405
390
  declare function findSection(sections: readonly PartSection[], relativePath: string): PartSection | null;
391
+
392
+ /**
393
+ * The MCP reader's view of a part: parsing lives in `partitioner/part-format.ts` so the auditor
394
+ * can use the same parser, and this module adds the windowing the tools need.
395
+ */
396
+
406
397
  interface Window {
407
398
  text: string;
408
399
  fromLine: number;
package/dist/mcp.d.ts CHANGED
@@ -361,21 +361,6 @@ interface StripResult {
361
361
  }
362
362
  declare function stripComments(text: string, relativePath: string): StripResult;
363
363
 
364
- /**
365
- * Reads one file's section back out of a rendered part.
366
- *
367
- * `snapshot_read` must not open the working tree. The snapshot is the contract: sensitive files
368
- * are excluded from it, secret-shaped strings inside ordinary files are redacted on the way in,
369
- * and a large file is emitted as a bounded preview. Reading the source directly would hand the
370
- * model the `.env` the snapshot deliberately skipped and the credential it masked — so the read
371
- * goes through the artifact instead.
372
- *
373
- * The format it parses is written by `renderFileSection`, and the parser is deliberately tied to
374
- * that shape rather than to a regex over the whole document: a file's *content* may legitimately
375
- * contain a line that looks like `### FILE: something`, and only fence tracking tells the two
376
- * apart. Content fences are four or more backticks (`fenceForContent` never emits three), which
377
- * is what makes "the next line equal to this exact fence" an unambiguous terminator.
378
- */
379
364
  interface PartSection {
380
365
  /** The path as rendered in the `### FILE:` heading. */
381
366
  path: string;
@@ -403,6 +388,12 @@ declare function parsePartSections(partText: string): PartSection[];
403
388
  * was read, or a part whose anchor line was edited by hand.
404
389
  */
405
390
  declare function findSection(sections: readonly PartSection[], relativePath: string): PartSection | null;
391
+
392
+ /**
393
+ * The MCP reader's view of a part: parsing lives in `partitioner/part-format.ts` so the auditor
394
+ * can use the same parser, and this module adds the windowing the tools need.
395
+ */
396
+
406
397
  interface Window {
407
398
  text: string;
408
399
  fromLine: number;
package/dist/mcp.js CHANGED
@@ -1,2 +1,2 @@
1
- export { generateToken, startHttpTransport } from './chunk-NESEHOPU.js';
2
- 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, generateInWorker, inspectModernMeta, isCommentStrippable, negotiateLegacyVersion, parsePartSections, runStdioServer, stripComments, validateArguments, windowText } from './chunk-BOJYZQFB.js';
1
+ export { generateToken, startHttpTransport } from './chunk-7WSZUMT6.js';
2
+ 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, generateInWorker, inspectModernMeta, isCommentStrippable, negotiateLegacyVersion, parsePartSections, runStdioServer, stripComments, validateArguments, windowText } from './chunk-2YNQ42B3.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.13.0 (project dependency ^0.13.0)
100
+ Branch: main | Part budget: 300 KB | Generator: 0.14.0 (project dependency ^0.14.0)
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
@@ -218,7 +218,7 @@ The whole first run in one command, with defaults and no prompts. This is the sa
218
218
  🚀 Setup for: /path/to/repo
219
219
  ✅ Created snapshot.config.ts (preset: nextjs)
220
220
  Added npm scripts: snapshot, snapshot:validate
221
- Added devDependency: codebase-snapshot ^0.13.0
221
+ Added devDependency: codebase-snapshot ^0.14.0
222
222
  Added to .gitignore: /snapshot/, /snapshot.tmp/
223
223
  ⏳ Installing dependencies…
224
224
  ✅ Installed dependencies (npm install, 2.1s)
@@ -270,7 +270,7 @@ It also has three side effects on files you own, and it says so when it does the
270
270
  ```
271
271
  ✅ Created snapshot.config.ts (preset: node-lib)
272
272
  Added npm scripts: snapshot, snapshot:validate
273
- Added devDependency: codebase-snapshot ^0.13.0
273
+ Added devDependency: codebase-snapshot ^0.14.0
274
274
  Added to .gitignore: /snapshot/, /snapshot.tmp/
275
275
  ```
276
276
 
package/docs/deploy.md CHANGED
@@ -61,8 +61,8 @@ After=network.target
61
61
  Type=oneshot
62
62
  User=deploy
63
63
  WorkingDirectory=/srv/app
64
- ExecStart=/usr/bin/npx -y codebase-snapshot@0.13.0 generate --cwd /srv/app
65
- ExecStartPost=/usr/bin/npx -y codebase-snapshot@0.13.0 validate --cwd /srv/app
64
+ ExecStart=/usr/bin/npx -y codebase-snapshot@0.14.0 generate --cwd /srv/app
65
+ ExecStartPost=/usr/bin/npx -y codebase-snapshot@0.14.0 validate --cwd /srv/app
66
66
  ```
67
67
 
68
68
  ```ini
package/docs/health.md CHANGED
@@ -43,6 +43,37 @@ secret, but you may not want it in the payload either.
43
43
  The score starts at 100; each failure costs 25 and each warning 5, with a floor of zero. It is a
44
44
  summary, not a substitute for the checks — the report always lists every one.
45
45
 
46
+ ### The JSON pack against the manifest
47
+
48
+ When the run wrote `full-codebase.json`, the audit parses it and compares its file set with
49
+ `manifest.files` in both directions. The artifact digest proves the pack is the file the manifest
50
+ recorded; it does not prove the manifest recorded a pack holding every file. An entry removed and
51
+ the digest updated would otherwise be invisible.
52
+
53
+ ### The counts against the data
54
+
55
+ A manifest edited to claim more files, parts, skips or content bytes than it holds used to pass
56
+ every check: each part hashed correctly, the artifacts were present, and the numbers a summary
57
+ quotes were never compared with the arrays they summarise. The audit now recomputes
58
+ `counts.totalFiles`, `counts.partsCount`, `counts.skippedCount`, `totals.totalContentBytes` and the
59
+ per-layer counts from the manifest's own arrays; any disagreement is a critical failure naming the
60
+ field and both numbers.
61
+
62
+ ### Every body against the accounting
63
+
64
+ The manifest says how many bytes and lines each file contributed. The audit now checks that
65
+ claim against the part: each section is parsed out (by anchor, not by heading) and its body must
66
+ match `includedBytes` and `includedLines` exactly. A truncated body, a missing section or a
67
+ hand-edited part that still hashes correctly fails the audit, because the manifest would be
68
+ describing a file the reader does not receive.
69
+
70
+ ### A member of a workspace
71
+
72
+ When a snapshot sits beside a `WORKSPACE.json`, the audit compares that member's record with the
73
+ snapshot: fingerprint and file count must agree. A workspace index that describes a different
74
+ snapshot than the one beside it is a warning, not a failure — the member itself is intact — and
75
+ `--strict` makes it exit 1.
76
+
46
77
  ## A workspace, all at once
47
78
 
48
79
  `health --all-members` reads `WORKSPACE.json` and audits every snapshot a `--workspace` run wrote,
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.13.0 mcp
13
+ npx -y codebase-snapshot@0.14.0 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.13.0", "mcp", "--cwd", "/absolute/path/to/repo"]
28
+ "args": ["-y", "codebase-snapshot@0.14.0", "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.13.0 mcp --cwd /absolute/path/to/repo
37
+ claude mcp add codebase-snapshot -- npx -y codebase-snapshot@0.14.0 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
@@ -43,11 +43,15 @@ there, and clients that spawn without a shell cannot execute it directly.
43
43
  ## Over HTTP, for clients that cannot spawn a process
44
44
 
45
45
  ```bash
46
- npx -y codebase-snapshot@0.13.0 mcp --http --port 4789
46
+ npx -y codebase-snapshot@0.14.0 mcp --http --port 4789
47
47
  ```
48
48
 
49
49
  This is the Streamable HTTP shape: POST one JSON-RPC message (or an array) to `/mcp` and read
50
- the JSON-RPC answer from the response body. `GET /healthz` answers `{ ok, name, version, tools, uptimeSeconds }`, without a token.
50
+ the JSON-RPC answer from the response body. `GET /healthz` answers
51
+ `{ ok, name, version, tools, uptimeSeconds }` without a token, and `GET /metrics` answers Prometheus
52
+ text: `snapshot_requests_total`, `snapshot_requests_by_method_total{method="…"}` (fixed labels,
53
+ never a path or a credential), `snapshot_requests_refused_total`,
54
+ `snapshot_requests_rate_limited_total`, `snapshot_tools`, `snapshot_uptime_seconds`.
51
55
 
52
56
  The first run prints the URL and a generated bearer token:
53
57
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codebase-snapshot",
3
- "version": "0.13.0",
3
+ "version": "0.14.0",
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",