codebase-snapshot 0.20.9 → 0.20.13

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.d.cts CHANGED
@@ -1,6 +1,6 @@
1
- export { G as GenerateSummary, W as WorkerResults, g as generateInWorker } from './generate-worker-DfNd8f67.cjs';
1
+ export { G as GenerateSummary, W as WorkerResults, g as generateInWorker } from './generate-worker-DMzNbsAW.cjs';
2
2
  import { Readable, Writable } from 'node:stream';
3
- import './types-D2_K7jfI.cjs';
3
+ import './types-C5ytHMYz.cjs';
4
4
 
5
5
  /**
6
6
  * JSON-RPC 2.0 envelopes and the Model Context Protocol revisions this server speaks.
@@ -70,13 +70,22 @@ declare const ERROR_CODES: {
70
70
  */
71
71
  readonly resourceTooLarge: -32000;
72
72
  /**
73
- * A known resource that this snapshot does not contain.
73
+ * A known resource that this snapshot does not contain, under a legacy revision.
74
74
  *
75
- * `-32002` is the MCP code for "resource not found". Answering `-32602` ("Unknown resource")
76
- * for `snapshot://prompt` in a snapshot generated with `--skip-artifacts prompt` told the
77
- * client its URI was wrong when the artifact had simply been left out.
75
+ * `-32002` was the resource-not-found code through protocol revision `2025-11-25`. The
76
+ * `2026-07-28` revision assigns missing resources to `-32602` and says clients SHOULD still
77
+ * accept `-32002` from older servers. The dispatcher therefore chooses by era: `-32602` for
78
+ * modern requests and this code for legacy ones. Answering `-32602` for `snapshot://prompt`
79
+ * in a snapshot generated with `--skip-artifacts prompt` would tell a legacy client its URI
80
+ * was wrong when the artifact had simply been left out.
78
81
  */
79
82
  readonly resourceNotFound: -32002;
83
+ /**
84
+ * Streamable HTTP headers that are missing, malformed or disagree with the request body.
85
+ *
86
+ * Protocol revision `2026-07-28` reserves `-32020` for this. The HTTP status is `400`.
87
+ */
88
+ readonly headerMismatch: -32020;
80
89
  /**
81
90
  * The server is at its concurrency limit.
82
91
  *
@@ -175,8 +184,8 @@ interface ToolContext {
175
184
  * Client-facing hints.
176
185
  *
177
186
  * `readOnlyHint` is the one that changes behaviour rather than appearance: clients use it to
178
- * auto-approve a call. Seven of the 26 tools never touch the filesystem, so they are marked
179
- * read-only and only `snapshot_generate` prompts.
187
+ * auto-approve a call. Twenty-five of the 26 tools never write, so they are marked read-only;
188
+ * only `snapshot_generate` writes.
180
189
  */
181
190
  interface ToolAnnotations {
182
191
  readOnlyHint: boolean;
package/dist/mcp.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- export { G as GenerateSummary, W as WorkerResults, g as generateInWorker } from './generate-worker--m4IM5zj.js';
1
+ export { G as GenerateSummary, W as WorkerResults, g as generateInWorker } from './generate-worker-CRMESc0b.js';
2
2
  import { Readable, Writable } from 'node:stream';
3
- import './types-D2_K7jfI.js';
3
+ import './types-C5ytHMYz.js';
4
4
 
5
5
  /**
6
6
  * JSON-RPC 2.0 envelopes and the Model Context Protocol revisions this server speaks.
@@ -70,13 +70,22 @@ declare const ERROR_CODES: {
70
70
  */
71
71
  readonly resourceTooLarge: -32000;
72
72
  /**
73
- * A known resource that this snapshot does not contain.
73
+ * A known resource that this snapshot does not contain, under a legacy revision.
74
74
  *
75
- * `-32002` is the MCP code for "resource not found". Answering `-32602` ("Unknown resource")
76
- * for `snapshot://prompt` in a snapshot generated with `--skip-artifacts prompt` told the
77
- * client its URI was wrong when the artifact had simply been left out.
75
+ * `-32002` was the resource-not-found code through protocol revision `2025-11-25`. The
76
+ * `2026-07-28` revision assigns missing resources to `-32602` and says clients SHOULD still
77
+ * accept `-32002` from older servers. The dispatcher therefore chooses by era: `-32602` for
78
+ * modern requests and this code for legacy ones. Answering `-32602` for `snapshot://prompt`
79
+ * in a snapshot generated with `--skip-artifacts prompt` would tell a legacy client its URI
80
+ * was wrong when the artifact had simply been left out.
78
81
  */
79
82
  readonly resourceNotFound: -32002;
83
+ /**
84
+ * Streamable HTTP headers that are missing, malformed or disagree with the request body.
85
+ *
86
+ * Protocol revision `2026-07-28` reserves `-32020` for this. The HTTP status is `400`.
87
+ */
88
+ readonly headerMismatch: -32020;
80
89
  /**
81
90
  * The server is at its concurrency limit.
82
91
  *
@@ -175,8 +184,8 @@ interface ToolContext {
175
184
  * Client-facing hints.
176
185
  *
177
186
  * `readOnlyHint` is the one that changes behaviour rather than appearance: clients use it to
178
- * auto-approve a call. Seven of the 26 tools never touch the filesystem, so they are marked
179
- * read-only and only `snapshot_generate` prompts.
187
+ * auto-approve a call. Twenty-five of the 26 tools never write, so they are marked read-only;
188
+ * only `snapshot_generate` writes.
180
189
  */
181
190
  interface ToolAnnotations {
182
191
  readOnlyHint: boolean;
package/dist/mcp.js CHANGED
@@ -1,2 +1,2 @@
1
1
  import './chunk-WMEZFLUT.js';
2
- export { ERROR_CODES, LEGACY_PROTOCOL_VERSIONS, MAX_LINE_BYTES, METHOD, MODERN_PROTOCOL_VERSIONS, REPORT_RESOURCE_URIS, RESOURCE_TEMPLATE_URIS, SERVER_INSTRUCTIONS, STATIC_RESOURCE_URIS, SUPPORTED_PROTOCOL_VERSIONS, buildPrompts, buildResourceProvider, buildTools, classifyRequest, coerceNumericStrings, createLineReader, createMcpServer, createServer, createSession, createWriter, findSection, generateInWorker, generateToken, inspectModernMeta, isCommentStrippable, negotiateLegacyVersion, parsePartSections, runStdioServer, startHttpTransport, stripComments, validateArguments, windowText } from './chunk-SU6YGIQT.js';
2
+ export { ERROR_CODES, LEGACY_PROTOCOL_VERSIONS, MAX_LINE_BYTES, METHOD, MODERN_PROTOCOL_VERSIONS, REPORT_RESOURCE_URIS, RESOURCE_TEMPLATE_URIS, SERVER_INSTRUCTIONS, STATIC_RESOURCE_URIS, SUPPORTED_PROTOCOL_VERSIONS, buildPrompts, buildResourceProvider, buildTools, classifyRequest, coerceNumericStrings, createLineReader, createMcpServer, createServer, createSession, createWriter, findSection, generateInWorker, generateToken, inspectModernMeta, isCommentStrippable, negotiateLegacyVersion, parsePartSections, runStdioServer, startHttpTransport, stripComments, validateArguments, windowText } from './chunk-GNVRD7XS.js';
@@ -99,6 +99,8 @@ type SkipReason = "binary" | "read-error" | "not-file"
99
99
  | "gitignore"
100
100
  /** Excluded by a built-in rule: the ignore list, a preset, or an output dir. */
101
101
  | "default-ignore"
102
+ /** A directory with a .codebase-snapshot marker, recorded instead of silently dropped. */
103
+ | "tool-output"
102
104
  /** Excluded by the user's own `excludePatterns` or `include` allow-list. */
103
105
  | "excluded"
104
106
  /**
@@ -99,6 +99,8 @@ type SkipReason = "binary" | "read-error" | "not-file"
99
99
  | "gitignore"
100
100
  /** Excluded by a built-in rule: the ignore list, a preset, or an output dir. */
101
101
  | "default-ignore"
102
+ /** A directory with a .codebase-snapshot marker, recorded instead of silently dropped. */
103
+ | "tool-output"
102
104
  /** Excluded by the user's own `excludePatterns` or `include` allow-list. */
103
105
  | "excluded"
104
106
  /**
@@ -21,8 +21,9 @@ tokens in full.
21
21
 
22
22
  - **Files** — entries in `manifest.files`, i.e. what the parts actually carry.
23
23
  - **Parts** — part files written. A budget/slice snapshot tends to be one part because it fits.
24
- - **Tokens** — `manifest.totals.estimatedTokens`, the same estimate the product reports. It is one
25
- token per four bytes of emitted body, not a tokenizer count; every model tokenizes differently.
24
+ - **Tokens** — `manifest.totals.estimatedTokens`, the structural estimate the product reports.
25
+ `estimateTokens` counts word runs, punctuation and newline runs; it is neither bytes/4 nor a
26
+ tokenizer count, and every model tokenizes differently.
26
27
  - **vs full** — token share of the full snapshot.
27
28
  - **Time** — wall clock for the whole `generate` process, including scan, parse, partition and write.
28
29
 
@@ -66,9 +67,10 @@ identical, which is what a deterministic scanner should do.
66
67
 
67
68
  Read it carefully:
68
69
 
69
- - **The ratio is not a contest.** Our estimate is one token per four bytes of emitted body; repomix
70
- uses a tokenizer. Across nine repositories the two land within about plus or minus 30%, which is
71
- what two reasonable estimates of the same text do.
70
+ - **The ratio is not a contest.** Our manifest estimate weighs word runs, punctuation and
71
+ newlines; the byte-based budget planner uses one token per four bytes; repomix uses a tokenizer.
72
+ Across nine repositories the two land within about plus or minus 30%, which is what two
73
+ reasonable estimates of the same text do.
72
74
  - **minimatch is the exception, and it is a policy difference, not an estimate.** That repository
73
75
  carries five benchmark fixtures of 20 to 25 MB of JSON. repomix emits them (64.8M tokens); our
74
76
  large-file rule emits a bounded preview and records the omission, so the pack stays 319,879 tokens.
@@ -110,7 +112,8 @@ gitingest from PyPI, same machine:
110
112
  Read that honestly:
111
113
 
112
114
  - **repomix reports fewer tokens for a similar pack** (854k against our 1.03M, 83%). The cause is
113
- the estimator, not the content: we count one token per four bytes, repomix uses a tokenizer.
115
+ the estimator, not the content: our manifest counts word runs, punctuation and newlines (the
116
+ budget planner uses bytes/4), while repomix uses a tokenizer.
114
117
  Our number is conservative, which is the right direction for a budget — a plan that fits
115
118
  1,027,911 tokens fits a tokenizer count of 854,178 far more often than the reverse.
116
119
  - **Our pack is smaller in bytes** (3.20 MB of file content against repomix's 3.39 MB of output,
package/docs/budget.md CHANGED
@@ -22,8 +22,9 @@ Every scanned file is scored once:
22
22
  | Cost | up to −40 | A cheap file that matters beats an expensive one that barely does. |
23
23
 
24
24
  Files are taken in score order while the running token estimate fits; a file that would exceed the
25
- budget is skipped whole, not cut. The estimate is one token per four bytes of emitted body — the
26
- same estimate the manifest reports.
25
+ budget is skipped whole, not cut. This planner uses one token per four bytes of emitted body. The
26
+ manifest's `estimatedTokens` is the structural `estimateTokens` result instead, so the two differ
27
+ by construction and neither is a tokenizer count.
27
28
 
28
29
  ## What it records
29
30
 
package/docs/cli.md CHANGED
@@ -98,7 +98,7 @@ Exit `0` when the snapshot passes its own integrity check, `1` when it does not.
98
98
 
99
99
  ```
100
100
  📸 Generating snapshot for: /path/to/repo
101
- Branch: main (fallback) | Part budget: 300 KB | Generator: 0.20.9 (project dependency ^0.20.9)
101
+ Branch: main (fallback) | Part budget: 300 KB | Generator: 0.20.13 (project dependency ^0.20.13)
102
102
 
103
103
  ✅ Snapshot generated in 0.14s:
104
104
  - 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
@@ -209,8 +209,9 @@ The whole first run in one command, with defaults and no prompts. This is the sa
209
209
  `--autopilot` uses, spelled as a command word:
210
210
 
211
211
  1. Detects the project preset.
212
- 2. Writes `snapshot.config.ts` (or `.mjs`) — **only when the repository has none**. An existing
213
- config is kept byte for byte and the output says `Keeping …`.
212
+ 2. Writes `snapshot.config.json` — **only when the repository has none**. An existing config is
213
+ kept byte for byte and the output says `Keeping …`. A data-only config is intentional: the MCP
214
+ server and `serve` refuse executable repository code.
214
215
  3. Adds `scripts.snapshot`, `scripts.snapshot:validate`, the `devDependencies` entry and the
215
216
  `.gitignore` entries, exactly as `init` does.
216
217
  4. Installs dependencies with the package manager the repository already uses — a lockfile
@@ -221,9 +222,9 @@ The whole first run in one command, with defaults and no prompts. This is the sa
221
222
 
222
223
  ```
223
224
  🚀 Setup for: /path/to/repo
224
- ✅ Created snapshot.config.ts (preset: nextjs)
225
+ ✅ Created snapshot.config.json (preset: nextjs)
225
226
  Added npm scripts: snapshot, snapshot:validate
226
- Added devDependency: codebase-snapshot ^0.20.9
227
+ Added devDependency: codebase-snapshot ^0.20.13
227
228
  Added to .gitignore: /snapshot/, /snapshot.tmp/
228
229
  ⏳ Installing dependencies…
229
230
  ✅ Installed dependencies (npm install, 2.1s)
@@ -265,17 +266,17 @@ The whole first run in one command, with defaults and no prompts. This is the sa
265
266
  codebase-snapshot init [options]
266
267
  ```
267
268
 
268
- Detects the project and writes `snapshot.config.ts` (or `.mjs`, see below) containing
269
- **every** setting at its current value, commented and grouped. It is a reference you can
270
- keep, not just a diff — there is no shorter variant, because the file that documents the
271
- settings is the file you edit.
269
+ Detects the project and writes `snapshot.config.json` containing **every** setting at its
270
+ current value. It is a reference you can keep, not just a diff — there is no shorter variant,
271
+ because the file that documents the settings is the file you edit. JSON is deliberate: the MCP
272
+ server and `serve` refuse executable repository configs, so `init` never writes one.
272
273
 
273
274
  It also has three side effects on files you own, and it says so when it does them:
274
275
 
275
276
  ```
276
- ✅ Created snapshot.config.ts (preset: node-lib)
277
+ ✅ Created snapshot.config.json (preset: node-lib)
277
278
  Added npm scripts: snapshot, snapshot:validate
278
- Added devDependency: codebase-snapshot ^0.20.9
279
+ Added devDependency: codebase-snapshot ^0.20.13
279
280
  Added to .gitignore: /snapshot/, /snapshot.tmp/
280
281
  ```
281
282
 
@@ -308,10 +309,10 @@ file.
308
309
  Interactive by default; with `--yes` it accepts every default and never prompts, which is
309
310
  what agents and release checks should use.
310
311
 
311
- The filename adapts to the project: `.ts` only when the running Node can strip types
312
- (≥ 22.6) **and** the project is an ES module; otherwise `.mjs`, which loads everywhere. The
313
- generated file is a plain object with no imports, so it works even when the package is only
314
- run through `npx` and never installed.
312
+ A new configuration is always `snapshot.config.json`, a plain JSON object with no imports. JSON
313
+ is the shape `mcp` and `serve` accept without executing repository code; request an executable
314
+ `.ts`/`.js`/`.mjs` file yourself only if you need function matchers. The file works even when
315
+ the package is only run through `npx` and never installed.
315
316
 
316
317
  Related options: `--preset`, `--include`, `--exclude`, `--yes` and `--force`
317
318
  apply to `init` and `setup` only. `init` also accepts `--dry-run`, `--max-part-bytes`, `--out-dir`,
@@ -425,13 +426,12 @@ agent](agent.md).
425
426
  Ask the npm registry whether a newer release exists, and print the version it compared against:
426
427
 
427
428
  ```bash
428
- npx codebase-snapshot@0.20.9 update # is 0.17.0 still current? print the answer
429
- npx codebase-snapshot@0.20.9 update --format json
429
+ npx codebase-snapshot@0.20.12 update # is this build current? print the answer
430
+ npx codebase-snapshot@0.20.12 update --format json
430
431
  ```
431
432
 
432
433
  ```text
433
- ↑ codebase-snapshot 0.18.0 is available — you have 0.17.0.
434
- npm install -g codebase-snapshot
434
+ You are on codebase-snapshot 0.20.12, and the registry publishes 0.20.12. No update is available.
435
435
  ```
436
436
 
437
437
  Exit `0` when the installed version is current, `1` when a newer release exists, `2` when the
@@ -481,7 +481,9 @@ codebase-snapshot mcp --cwd <path> # serve another repository
481
481
  Serves the repository to a Model Context Protocol client over stdio: 26 tools, `snapshot://`
482
482
  resources and seven prompts. Stdout carries JSON-RPC messages and nothing else; every note goes to
483
483
  stderr. It speaks both protocol eras — the legacy `initialize` handshake and the stateless
484
- `2026-07-28` revision — and answers whichever the client starts with.
484
+ `2026-07-28` revision — and answers whichever the client starts with. With `--http`, modern
485
+ requests carry `MCP-Protocol-Version`, `Mcp-Method` and (for named calls) `Mcp-Name`;
486
+ mismatches are refused with `-32020` before dispatch.
485
487
 
486
488
  `--cwd` is the only directory it will read. A tool's `root` argument can name a sub-directory of it
487
489
  and nothing outside, symlinks included. It never installs packages and never writes a config file.
@@ -519,7 +521,7 @@ for the two install flags, and the init-and-setup flags list both commands.
519
521
  | `--deep` | flag | off | health | Replay every full body from the source bytes on disk and compare it with the part. The only allowed difference is a redaction marker. Off by default because it re-reads the repository. |
520
522
  | `--strict` | flag | off | health | `health` only: exit 2 when a critical check fails, and 1 when a warning is the only thing left. Without it a critical check exits 1 and warnings exit 0. |
521
523
  | `--mode <command>` | string | unset | generate, validate, report, explain, init, setup, diff, describe, skill | Select the command when no command word is given. A command word and `--mode` must name the same command; a contradiction is a usage error (exit 2). |
522
- | `--no-update-check` | flag | off | all commands | Skip the check for a newer published version. Already skipped when stdout is not a terminal, in CI, in a JSON invocation, and in `mcp`, which makes no network requests. |
524
+ | `--no-update-check` | flag | off | all commands except `update` | Skip the check for a newer published version. Already skipped when stdout is not a terminal, in CI, in a JSON invocation, and in `mcp`, which makes no network requests. `update` exists to contact the registry, so it has no check to skip. |
523
525
  | `--prompt-task <task>` | string | `audit` | generate, validate | `audit`, `review` or `explain` — which job the brief is written for. Changes the opening section, not the standard. |
524
526
  | `--budget-tokens <n>` | count | unset | generate | Fit the snapshot into n tokens by selecting whole files (entry points, then the most-imported). Records a `budget` block; the rest are `not-selected`. See [budget](budget.md). |
525
527
  | `--sign` | flag | off | generate | Sign `manifest.json` with Ed25519 and write `signature.json`. Key from `SNAPSHOT_SIGNING_KEY`, else generated (trust on first use). See [signing](signing.md). |
@@ -558,7 +560,7 @@ for the two install flags, and the init-and-setup flags list both commands.
558
560
  | `--include <globs>` | list | unset | init, setup | Allow-list recorded in the generated config. |
559
561
  | `--exclude <globs>` | list | unset | init, setup | Exclude globs recorded in the generated config. |
560
562
  | `--yes` | flag | off | init, setup | Never prompt; accept every default. |
561
- | `--force` | flag | off | init, setup | Replace an existing `.ts`/`.js`/`.mjs` config in place. A JSON-family config is refused, naming the file to remove. |
563
+ | `--force` | flag | off | init, setup | Replace an existing JSON-family config in place. An executable `.ts`/`.js`/`.mjs` config is refused, naming the file to remove. |
562
564
  | `--install` | flag | off | *skill only* | Write the skill into the repository instead of printing it. |
563
565
  | `--target <name>` | enum | `all` | *skill only* | `claude`, `cursor` or `all`. |
564
566
  | `-h`, `--help` | flag | — | every command | Print usage. |
@@ -49,14 +49,15 @@ A config file that exists but cannot be parsed is a **hard error** (exit `1`, no
49
49
  written). Silently ignoring it would produce a snapshot with none of your settings.
50
50
 
51
51
  A `.ts` config needs Node ≥ 22.6 **and** an ES-module project, because Node applies the
52
- package's `type` field to a `.ts` file. `codebase-snapshot init` picks the right filename for
53
- the project — `.ts` when both conditions hold, `.mjs` otherwise — and writes a plain object
54
- with no imports so it loads even when the package is only used through `npx`.
52
+ package's `type` field to a `.ts` file. `codebase-snapshot init` writes `snapshot.config.json`
53
+ for a new project: data only, no imports, and accepted by `mcp` and `serve` without executing
54
+ repository code. An executable `.ts`/`.js`/`.mjs` config is something you create yourself and
55
+ can use with the CLI; those surfaces refuse to run it.
55
56
 
56
- The snippets below show an `export default { … }` object for brevity. `init` writes it as
57
- `const config = { … }; export default config;` because the anonymous form is reported by
58
- `import/no-anonymous-default-export`, which `eslint-config-next` enables by default — both load
59
- identically, so use whichever keeps your linter quiet.
57
+ The snippets below show an `export default { … }` object because that is the executable form.
58
+ A JSON config uses the same keys without the export wrapper. Both load identically for the CLI.
59
+ For an executable config, prefer `const config = { … }; export default config;` over the
60
+ anonymous form, which `eslint-config-next` reports via `import/no-anonymous-default-export`.
60
61
 
61
62
  CLI flags override the config for a single run (`--max-part-bytes`, `--out-dir`, …).
62
63
  `--no-config` goes further and ignores every config file, so the run uses the built-in
@@ -468,7 +469,7 @@ either.
468
469
  A credential assigned to a name inside a string is also masked — a connection string is a string:
469
470
 
470
471
  ```js
471
- const dsn = "password=MySuperSecret123;host=db.internal";
472
+ const dsn = "password=<redacted-example>;host=db.internal";
472
473
  ```
473
474
 
474
475
  What is left alone is a credential *name* in a literal, with nothing assigned to it:
@@ -674,13 +675,13 @@ npx codebase-snapshot init --preset go --max-part-bytes 200k \
674
675
  --include "cmd/**,internal/**" --exclude "**/*_test.go" --yes
675
676
  ```
676
677
 
677
- `--dry-run` prints the config and writes nothing. `--force` replaces an existing ES-module
678
- config (`.ts`, `.js`, `.mjs`) in place; without it, an existing config is left alone and the
679
- command exits `1`.
678
+ `--dry-run` prints the config and writes nothing. A new configuration is
679
+ `snapshot.config.json`, the data-only form MCP and serve accept. `--force` rewrites an existing
680
+ configuration in place: a JSON-family file keeps JSON; an ES-module `.ts`, ESM `.js`, or `.mjs`
681
+ file keeps its executable format. A CommonJS `.js` or `.cjs` file is refused, because this
682
+ wizard cannot write that format, and a new file beside it would silently shadow the old one.
683
+ Without `--force`, an existing config is left alone and the command exits `1`.
680
684
 
681
- It will not replace a JSON-family config — `snapshot.config.json`, `.snapshotrc`,
682
- `.snapshotrc.json`, or the `"snapshot"` key in `package.json` — because this wizard writes an
683
- ES-module file and a new file beside the old one would silently shadow it. Those cases exit `1`
684
- with a message naming the file to delete or rename. Note that this means `--force` writing
685
- `snapshot.config.ts` does shadow a `"snapshot"` key in `package.json`, since a dedicated config
686
- file always wins.
685
+ A `"snapshot"` key in `package.json` is handled the same way: without `--force` the command
686
+ exits `1` and names the key; with `--force` it writes `snapshot.config.json`, and that file then
687
+ takes precedence over the key. The key itself is not edited.
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.20.9 generate --cwd /srv/app
65
- ExecStartPost=/usr/bin/npx -y codebase-snapshot@0.20.9 validate --cwd /srv/app
64
+ ExecStart=/usr/bin/npx -y codebase-snapshot@0.20.12 generate --cwd /srv/app
65
+ ExecStartPost=/usr/bin/npx -y codebase-snapshot@0.20.12 validate --cwd /srv/app
66
66
  ```
67
67
 
68
68
  ```ini
package/docs/health.md CHANGED
@@ -32,7 +32,7 @@ npx codebase-snapshot health --deep # also replay every full body from t
32
32
  | Every pack body is the part body | `packs.bodies` | critical | For full files, the bytes in the pack equal the bytes in the part; previews and signatures are whole-file by design. |
33
33
  | Every full body replays from the source | `fidelity.bodies` | critical | With `--deep`: each full body is rebuilt from the bytes on disk (redaction allowed) and compared. Skipped without `--deep`. |
34
34
  | A member matches its workspace index | `workspace.index` | warning | Fingerprint and file count equal `WORKSPACE.json`, and a member whose source directory is gone warns. |
35
- | No unmasked secret in any artifact | `secrets.artifacts` | critical | Every written text file is re-scanned with the secret rules; a signature record is scanned without its random key material. |
35
+ | No unmasked secret in any artifact | `secrets.artifacts` | critical | Every written text file is re-scanned with the secret rules; a signature record is scanned without its random key material. If `maxScanBytes` truncates the scan, the check is a warning, never a pass. |
36
36
  | No value from an excluded sensitive file appears | `secrets.skipped` | critical | Values from `.env`, keys and similar files are compared byte-for-byte against the artifacts. |
37
37
  | No host path or machine identity | `pii.paths` | warning | `/home/…`, `/Users/…`, `C:\Users\…` and the repository's absolute path are searched for. |
38
38
  | Token estimate is plausible | `tokens.count` | warning | The recorded estimate is compared with one recomputed from the parts. |
@@ -31,9 +31,9 @@ snapshot # installed globally: one word, and it asks once
31
31
  npx codebase-snapshot setup # or from a checkout with no global install
32
32
  ```
33
33
 
34
- `setup` detects the project type from the repository, writes a commented `snapshot.config.mjs`, adds
35
- the npm scripts and the devDependency, installs it, and generates. It does not overwrite a config you
36
- already have. Use `--no-install` if you would rather not touch the lockfile. `npx codebase-snapshot
34
+ `setup` detects the project type from the repository, writes a data-only `snapshot.config.json`,
35
+ adds the npm scripts and the devDependency, installs it, and generates. It does not overwrite a
36
+ config you already have. Use `--no-install` if you would rather not touch the lockfile. `npx codebase-snapshot
37
37
  --autopilot` does the same thing with no questions at all, which is what you want in CI.
38
38
 
39
39
  If you prefer to see each stage:
@@ -56,14 +56,11 @@ destination, not from taste:
56
56
  | A RAG index | 120–300 KB per part, chunked by heading |
57
57
  | An agent's context | 60–150 KB; smaller parts leave room to reason |
58
58
 
59
- ```js
60
- // snapshot.config.mjs
61
- const config = {
62
- maxPartBytes: "120k",
63
- // Per-layer ceilings, when docs and code deserve different treatment.
64
- budgets: { default: "120k", byLayer: { docs: 40_000 } },
65
- };
66
- export default config;
59
+ ```json
60
+ {
61
+ "maxPartBytes": "120k",
62
+ "budgets": { "default": "120k", "byLayer": { "docs": 40000 } }
63
+ }
67
64
  ```
68
65
 
69
66
  A file is never cut down to make a part fit. A file above `largeFileBytes` — which defaults to the
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.20.9 mcp
13
+ npx -y codebase-snapshot@0.20.12 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.20.9", "mcp", "--cwd", "/absolute/path/to/repo"]
28
+ "args": ["-y", "codebase-snapshot@0.20.12", "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.20.9 mcp --cwd /absolute/path/to/repo
37
+ claude mcp add codebase-snapshot -- npx -y codebase-snapshot@0.20.12 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.20.9 mcp --http --port 4789
46
+ npx -y codebase-snapshot@0.20.12 mcp --http --port 4789
47
47
  ```
48
48
 
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
49
+ This is the Streamable HTTP shape: POST one JSON-RPC message to `/mcp` and read the JSON-RPC
50
+ answer from the response body. Modern (`2026-07-28`) requests must also carry
51
+ `MCP-Protocol-Version`, `Mcp-Method` and — for `tools/call`, `resources/read` and
52
+ `prompts/get` — `Mcp-Name`. A missing header, or one that disagrees with the body, is refused
53
+ with HTTP `400` and JSON-RPC `-32020` before dispatch; the CORS preflight allows all three
54
+ names. Legacy requests keep the session behaviour below. `GET /healthz` answers
51
55
  `{ ok, name, version, tools, uptimeSeconds }` without a token, and `GET /metrics` answers Prometheus
52
56
  text: `snapshot_requests_total`, `snapshot_requests_by_method_total{method="…"}` (fixed labels,
53
57
  never a path or a credential), `snapshot_requests_refused_total` (every 4xx except 429: an
@@ -78,14 +82,16 @@ reachable from the network must not be readable by any page that guesses the por
78
82
  CORS is granted to loopback origins (`localhost`, `127.0.0.1`, `[::1]`, any port) and to the
79
83
  origins you list. Any other `Origin` gets `403`.
80
84
 
81
- The first `initialize` response carries an `mcp-session-id` header. Send it on every later
82
- request: era and cancellation state belong to that session, so one client's
83
- `server/discover` cannot reject another client's legacy handshake. A client that ignores the
84
- header falls back to a per-address server; two such clients on one host with the same user agent
85
- share state, which is why forwarding the header matters. An unknown `mcp-session-id` is answered
86
- with `404`, never used to mint state; sessions expire after 30 minutes idle, the oldest is evicted
87
- when the table is full, and `DELETE /mcp` closes one explicitly. JSON-RPC batches are capped at
88
- 100 messages, and the body cap applies before parsing.
85
+ Modern requests are stateless: `mcp-session-id` is ignored, never minted and never echoed. The
86
+ legacy era still opens with `initialize`, whose response carries an `mcp-session-id` header;
87
+ send it on every later legacy request. Era and cancellation state belong to that session, so one
88
+ client's `server/discover` cannot reject another client's legacy handshake. A legacy client that
89
+ ignores the header falls back to a per-address server; two such clients on one host with the same
90
+ user agent share state, which is why forwarding the header matters. An unknown `mcp-session-id`
91
+ is answered with `404`, never used to mint state; sessions expire after 30 minutes idle, the
92
+ oldest is evicted when the table is full, and `DELETE /mcp` closes one explicitly. Legacy
93
+ JSON-RPC batches are capped at 100 messages; a modern request is one message, and a modern batch
94
+ is refused. The body cap applies before parsing.
89
95
 
90
96
  ### Legacy SSE, for clients that cannot send a header
91
97
 
@@ -114,6 +120,11 @@ reads the manifest, `medium` reads one or a few parts, `expensive` reads the rep
114
120
  Two tools that answer the same question can differ by an order of magnitude, and a client choosing
115
121
  between them should not have to guess.
116
122
 
123
+ Modern cacheable results — `server/discover`, `tools/list`, `prompts/list`, `resources/list`,
124
+ `resources/read` and `resources/templates/list` — carry `ttlMs: 0` and
125
+ `cacheScope: "private"`. The snapshot is private to the caller and a regeneration can replace any
126
+ part of it between two reads, so a positive TTL would invite a client to serve stale bytes.
127
+
117
128
  | Tool | Answers | Writes |
118
129
  | :-- | :-- | :-- |
119
130
  | `snapshot_status` | Is there a snapshot, when was it built, what does it cover? | no |
@@ -143,26 +154,26 @@ between them should not have to guess.
143
154
  | `snapshot_read` | A window of one file, as the snapshot contains it. | no |
144
155
  | `snapshot_explain` | Why is this path not in the snapshot? | no |
145
156
 
146
- Seven are declared `readOnlyHint`, which most clients use to run them without asking. Only
147
- `snapshot_generate` prompts.
157
+ Twenty-five are declared `readOnlyHint`, which most clients use to run them without asking. Only
158
+ `snapshot_generate` writes.
148
159
 
149
- All eight take `outDir`, so a snapshot generated into a directory other than the configured one is
160
+ All 26 take `outDir`, so a snapshot generated into a directory other than the configured one is
150
161
  still reachable: pass the same value to the read side that you passed to `snapshot_generate`. Before
151
162
  that, only `snapshot_generate` honoured it and every other tool looked in the configured directory
152
163
  and reported "there is no snapshot manifest here".
153
164
 
154
165
  An `outDir` **tool argument** must resolve inside the repository the server serves: a prompt cannot
155
- drop a snapshot tree anywhere the process is able to write. The project's *configured* `outDir` is
156
- not confined the same way — that is the repository's own decision, and a config may legitimately
157
- point one directory up. If the argument escapes, the tool refuses and the message says to restart
158
- the server with `--cwd` pointing at the repository you want to write.
166
+ drop a snapshot tree anywhere the process is able to write. The project's *configured* `outDir`
167
+ and `tmpDir` are confined the same way. If either escapes, the tool refuses and the message says
168
+ to move the directory inside the served root, or start the server with `--cwd` at the parent
169
+ repository.
159
170
 
160
171
  `snapshot_plan`, `snapshot_generate`, `snapshot_validate` and `snapshot_explain` also take the
161
172
  **scope and compression** switches `generate` accepts: `maxPartTokens`, `skeleton`, `sarif`,
162
173
  `changedSince`, `staged` and `withDependents`. They have to: `manifest.config.digest` covers those
163
174
  settings, so a snapshot generated with `--skeleton` was not merely un-inspectable over MCP, it was
164
175
  reported as configuration drift on every `snapshot_validate`. Pass the same switches you generated
165
- with, exactly as you would on the command line. The four remaining tools do not take them, because
176
+ with, exactly as you would on the command line. The other tools do not take them, because
166
177
  none of them re-derives the configuration and a flag that changes nothing is the command-line form
167
178
  of a silent fallback.
168
179
 
@@ -217,9 +228,11 @@ resource — `snapshot://manifest`, each `snapshot://parts/{index}`, the report
217
228
  `snapshot://prompt`, `snapshot://contract` and `snapshot://skill`.
218
229
 
219
230
  A URI this build serves but this snapshot does not contain — `snapshot://prompt` when the prompt
220
- artifact was disabled, a report when that artifact was — is answered with `-32002` (resource not
221
- found) and a message naming the artifact and the cause. An unknown URI is still "Unknown resource":
222
- the two are different mistakes and a client should be able to tell them apart.
231
+ artifact was disabled, a report when that artifact was — is answered with `-32602` (Invalid
232
+ Params) under the modern revision, and with the legacy `-32002` for a legacy client. The message
233
+ names the artifact and the cause. Modern clients also accept `-32002` from older servers, but this
234
+ server does not make a modern client guess. An unknown URI is still "Unknown resource": the two
235
+ are different mistakes and a client should be able to tell them apart.
223
236
 
224
237
  Part resources carry their size in the description, so a client choosing between them can see that
225
238
  one is 300 kB before attaching it; a part above the limit says in its description that it will be
@@ -276,25 +289,34 @@ says what happened rather than pretending the call never ran.
276
289
 
277
290
  ## Both protocol eras
278
291
 
279
- Revision `2026-07-28` removed the handshake that every client in use today still performs. The
280
- server speaks both and answers whichever arrives first.
292
+ Revision `2026-07-28` removed the handshake most deployed clients still perform. The server speaks
293
+ both and answers whichever arrives first.
281
294
 
282
295
  | Era | Revisions | Opening move |
283
296
  | :-- | :-- | :-- |
284
297
  | Legacy | `2025-11-25`, `2025-06-18` | `initialize`, then `notifications/initialized` |
285
298
  | Modern | `2026-07-28` | `server/discover`, or `_meta` on every request; a stateless request with valid `_meta` is complete on its own |
286
299
 
287
- The two disagree about an unsupported version, and the difference is observable: a legacy client is
288
- negotiated *down* to a revision the server speaks, while a modern client receives `-32022` with the
289
- list of supported revisions so it can retry.
300
+ A modern request over HTTP is complete only when its mirroring headers agree with its body, and its
301
+ cacheable results carry the fields the revision requires. Those rules are enforced in
302
+ `src/mcp/http-headers.ts` and `src/mcp/server.ts`, not just documented.
303
+
304
+ The two eras disagree about an unsupported version, and the difference is observable: a legacy
305
+ client is negotiated *down* to a revision the server speaks, while a modern client receives
306
+ `-32022` with the list of supported revisions so it can retry.
290
307
 
291
- ## Why there is no SDK
308
+ ## Why there is no runtime SDK
292
309
 
293
310
  `@modelcontextprotocol/sdk` is 4.5 MB unpacked and brings Express, Hono, Ajv, JOSE and Zod with it.
294
311
  The transport here is newline-delimited JSON-RPC, which is roughly 400 lines of readable code, and
295
312
  the package's only runtime dependency remains `typescript`. The parity test — a live `tools/list`
296
- compared against `describe --format json` — is what keeps the protocol implementation honest, not
297
- the presence of a library.
313
+ compared against `describe --format json` — is what keeps the protocol contract honest, not the
314
+ presence of a library.
315
+
316
+ The official v2 client (`@modelcontextprotocol/client`) is a **dev-only** dependency. Two
317
+ interoperability tests drive this server through it over modern stdio and modern HTTP, including
318
+ `server/discover`, `tools/list`, `tools/call`, `resources/read` and the cache fields. It is not
319
+ shipped, and it does not make the runtime depend on the SDK.
298
320
 
299
321
  ## Performance
300
322