codebase-snapshot 0.21.0 → 0.22.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/mcp.d.cts CHANGED
@@ -1,6 +1,6 @@
1
- export { G as GenerateSummary, W as WorkerResults, g as generateInWorker } from './generate-worker-D56JeXwx.cjs';
1
+ export { G as GenerateSummary, W as WorkerResults, g as generateInWorker } from './generate-worker-BUNhTXkj.cjs';
2
2
  import { Readable, Writable } from 'node:stream';
3
- import './types-D5XYzksd.cjs';
3
+ import './types-DQXKiaXk.cjs';
4
4
 
5
5
  /**
6
6
  * JSON-RPC 2.0 envelopes and the Model Context Protocol revisions this server speaks.
@@ -361,7 +361,10 @@ interface McpServerOptions {
361
361
  /** Writes a JSON-RPC notification. Present on transports that can carry one mid-call. */
362
362
  notify?: (message: JsonObject) => void;
363
363
  /** Shared registry so stateless modern HTTP requests can cancel an earlier request. */
364
- cancellations?: Map<JsonRpcId, () => void>;
364
+ /** In-flight cancellation hooks, keyed by the JSON-RPC id a client may quote. A set because a
365
+ * stateless transport can legitimately see two concurrent clients use `id: 1`; one finishing
366
+ * must not remove the other's hook. */
367
+ cancellations?: Map<JsonRpcId, Set<() => void>>;
365
368
  }
366
369
  interface McpServer {
367
370
  /** Handles one already-parsed message. Returns null when no response is due. */
@@ -479,7 +482,7 @@ interface ServerOptions {
479
482
  /** Where operational notes go. Never stdout, which carries protocol messages only. */
480
483
  log?: (line: string) => void;
481
484
  /** Optional map for a caller that owns one server's request ids; the default is per server. */
482
- cancellations?: Map<JsonRpcId, () => void>;
485
+ cancellations?: Map<JsonRpcId, Set<() => void>>;
483
486
  }
484
487
  /** Builds a server with every capability this package implements. */
485
488
  declare function createServer(options: ServerOptions): McpServer;
package/dist/mcp.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- export { G as GenerateSummary, W as WorkerResults, g as generateInWorker } from './generate-worker-DakxZs-l.js';
1
+ export { G as GenerateSummary, W as WorkerResults, g as generateInWorker } from './generate-worker-TUMvHlgz.js';
2
2
  import { Readable, Writable } from 'node:stream';
3
- import './types-D5XYzksd.js';
3
+ import './types-DQXKiaXk.js';
4
4
 
5
5
  /**
6
6
  * JSON-RPC 2.0 envelopes and the Model Context Protocol revisions this server speaks.
@@ -361,7 +361,10 @@ interface McpServerOptions {
361
361
  /** Writes a JSON-RPC notification. Present on transports that can carry one mid-call. */
362
362
  notify?: (message: JsonObject) => void;
363
363
  /** Shared registry so stateless modern HTTP requests can cancel an earlier request. */
364
- cancellations?: Map<JsonRpcId, () => void>;
364
+ /** In-flight cancellation hooks, keyed by the JSON-RPC id a client may quote. A set because a
365
+ * stateless transport can legitimately see two concurrent clients use `id: 1`; one finishing
366
+ * must not remove the other's hook. */
367
+ cancellations?: Map<JsonRpcId, Set<() => void>>;
365
368
  }
366
369
  interface McpServer {
367
370
  /** Handles one already-parsed message. Returns null when no response is due. */
@@ -479,7 +482,7 @@ interface ServerOptions {
479
482
  /** Where operational notes go. Never stdout, which carries protocol messages only. */
480
483
  log?: (line: string) => void;
481
484
  /** Optional map for a caller that owns one server's request ids; the default is per server. */
482
- cancellations?: Map<JsonRpcId, () => void>;
485
+ cancellations?: Map<JsonRpcId, Set<() => void>>;
483
486
  }
484
487
  /** Builds a server with every capability this package implements. */
485
488
  declare function createServer(options: ServerOptions): McpServer;
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-TDPYLX7X.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-7AAXOTKS.js';
@@ -1057,4 +1057,4 @@ interface ValidationResult {
1057
1057
  warnings: string[];
1058
1058
  }
1059
1059
 
1060
- export type { ArtifactSelection as A, ByteSize as B, CliOptions as C, DiscoveryMode as D, EdgeProvenance as E, FileEntry as F, SummaryQuality as G, HooksConfig as H, ImportBinding as I, JsonSummary as J, KindRule as K, LayerRule as L, MarkdownSummary as M, TruncationReason as N, OutputFormat as O, PromptTask as P, ValidationDrift as Q, ResolvedSnapshotConfig as R, SecretRule as S, TextEncoding as T, ValidationResult as V, SkipRecord as a, SourceSummary as b, SnapshotConfig as c, PartMetadata as d, SecretFinding as e, Manifest as f, TrustEnvelope as g, BudgetConfig as h, CoverageStatus as i, DeclarationSpan as j, FreshnessStatus as k, InclusionMode as l, IncompleteFile as m, IndexSourceKind as n, ManifestArtifact as o, ManifestConfigSnapshot as p, ManifestIndexes as q, ManifestTotals as r, Mode as s, OwnerBrief as t, PartFileEntry as u, ReExportBinding as v, ResolvedArtifacts as w, ResolvedBudgets as x, SecretRuleInput as y, SkipReason as z };
1060
+ export type { ArtifactSelection as A, ByteSize as B, CliOptions as C, DiscoveryMode as D, EdgeProvenance as E, FileEntry as F, SummaryQuality as G, HooksConfig as H, ImportBinding as I, JsonSummary as J, KindRule as K, LayerRule as L, Manifest as M, TruncationReason as N, OutputFormat as O, PromptTask as P, ValidationDrift as Q, ResolvedSnapshotConfig as R, SecretRule as S, TrustEnvelope as T, ValidationResult as V, SkipRecord as a, MarkdownSummary as b, SourceSummary as c, SnapshotConfig as d, PartMetadata as e, TextEncoding as f, SecretFinding as g, BudgetConfig as h, CoverageStatus as i, DeclarationSpan as j, FreshnessStatus as k, InclusionMode as l, IncompleteFile as m, IndexSourceKind as n, ManifestArtifact as o, ManifestConfigSnapshot as p, ManifestIndexes as q, ManifestTotals as r, Mode as s, OwnerBrief as t, PartFileEntry as u, ReExportBinding as v, ResolvedArtifacts as w, ResolvedBudgets as x, SecretRuleInput as y, SkipReason as z };
@@ -1057,4 +1057,4 @@ interface ValidationResult {
1057
1057
  warnings: string[];
1058
1058
  }
1059
1059
 
1060
- export type { ArtifactSelection as A, ByteSize as B, CliOptions as C, DiscoveryMode as D, EdgeProvenance as E, FileEntry as F, SummaryQuality as G, HooksConfig as H, ImportBinding as I, JsonSummary as J, KindRule as K, LayerRule as L, MarkdownSummary as M, TruncationReason as N, OutputFormat as O, PromptTask as P, ValidationDrift as Q, ResolvedSnapshotConfig as R, SecretRule as S, TextEncoding as T, ValidationResult as V, SkipRecord as a, SourceSummary as b, SnapshotConfig as c, PartMetadata as d, SecretFinding as e, Manifest as f, TrustEnvelope as g, BudgetConfig as h, CoverageStatus as i, DeclarationSpan as j, FreshnessStatus as k, InclusionMode as l, IncompleteFile as m, IndexSourceKind as n, ManifestArtifact as o, ManifestConfigSnapshot as p, ManifestIndexes as q, ManifestTotals as r, Mode as s, OwnerBrief as t, PartFileEntry as u, ReExportBinding as v, ResolvedArtifacts as w, ResolvedBudgets as x, SecretRuleInput as y, SkipReason as z };
1060
+ export type { ArtifactSelection as A, ByteSize as B, CliOptions as C, DiscoveryMode as D, EdgeProvenance as E, FileEntry as F, SummaryQuality as G, HooksConfig as H, ImportBinding as I, JsonSummary as J, KindRule as K, LayerRule as L, Manifest as M, TruncationReason as N, OutputFormat as O, PromptTask as P, ValidationDrift as Q, ResolvedSnapshotConfig as R, SecretRule as S, TrustEnvelope as T, ValidationResult as V, SkipRecord as a, MarkdownSummary as b, SourceSummary as c, SnapshotConfig as d, PartMetadata as e, TextEncoding as f, SecretFinding as g, BudgetConfig as h, CoverageStatus as i, DeclarationSpan as j, FreshnessStatus as k, InclusionMode as l, IncompleteFile as m, IndexSourceKind as n, ManifestArtifact as o, ManifestConfigSnapshot as p, ManifestIndexes as q, ManifestTotals as r, Mode as s, OwnerBrief as t, PartFileEntry as u, ReExportBinding as v, ResolvedArtifacts as w, ResolvedBudgets as x, SecretRuleInput as y, SkipReason as z };
package/docs/about.md CHANGED
@@ -14,8 +14,9 @@ easier to trust when you can see who made it, how it was tested, and how to corr
14
14
  whose body was shortened, with the missing line ranges.
15
15
  - A secret redactor that masks matched values in place, and an audit that re-scans the result.
16
16
  - A validator that re-hashes the tree and exits non-zero when the snapshot no longer matches it.
17
- - A live index and an MCP server with seven read-only tools, so an agent can ask for the one
18
- file, symbol or impact report it needs instead of reading the whole repository.
17
+ - A live index and an MCP server with seven tools — six read-only and one writable
18
+ (`snapshot_generate`) — so an agent can ask for the one file, symbol or impact report it needs
19
+ instead of reading the whole repository.
19
20
  - A small, dependency-light TypeScript package: one runtime dependency, no native binary.
20
21
 
21
22
  ## What this project is not
package/docs/agent.md CHANGED
@@ -132,7 +132,8 @@ turn that into a decision about what to commit. A file that already existed is n
132
132
  added.
133
133
 
134
134
  `codebase-snapshot init` does none of this: it writes the config, the npm scripts, the
135
- devDependency and the `.gitignore` entries for the snapshot directory, and nothing else.
135
+ devDependency, the `.gitignore` entries for the snapshot directory, and a `BRIEF.md` scaffold
136
+ when the repository does not already have one.
136
137
 
137
138
  ## When the client speaks MCP
138
139
 
package/docs/cli.md CHANGED
@@ -61,6 +61,7 @@ as it makes it.
61
61
  - [`health`](#health)
62
62
  - [`report`](#report)
63
63
  - [`impact`](#impact)
64
+ - [`guard`](#guard)
64
65
  - [`brief`](#brief)
65
66
  - [`setup`](#setup)
66
67
  - [`init`](#init)
@@ -103,7 +104,7 @@ Exit `0` when the snapshot passes its own integrity check, `1` when it does not.
103
104
 
104
105
  ```
105
106
  📸 Generating snapshot for: /path/to/repo
106
- Branch: main (fallback) | Part budget: 300 KB | Generator: 0.21.0 (project dependency ^0.21.0)
107
+ Branch: main (fallback) | Part budget: 300 KB | Generator: 0.22.1 (project dependency ^0.22.1)
107
108
 
108
109
  ✅ Snapshot generated in 0.14s:
109
110
  - 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
@@ -239,6 +240,28 @@ human report to stderr, like every other human-facing command.
239
240
 
240
241
  → [Impact reports](impact.md): the field contract, resolution rules and what the report does not claim.
241
242
 
243
+ ### `guard`
244
+
245
+ ~~~bash
246
+ codebase-snapshot guard --changed
247
+ codebase-snapshot guard --paths src/auth.ts --format json
248
+ codebase-snapshot guard --hook claude < payload.json
249
+ ~~~
250
+
251
+ Checks whether a change is complete: untouched consumers, candidate tests and affected routes,
252
+ minus everything the change already touched. It uses the same live index and import resolver as
253
+ `impact`, so no `generate` run is required. The report is bounded to 10 consumers, 5 tests and
254
+ 5 routes; when it is cut, `truncated` is true and `omitted` records the counts.
255
+
256
+ `--hook <claude|copilot|codex|raw>` reads one JSON payload from stdin and writes the host-shaped
257
+ `additionalContext` to stdout, or `{}` when there is nothing to report. It is fail-open: an error
258
+ returns `{}` and a note on stderr, so a broken guard cannot fail an agent turn.
259
+
260
+ Exit `0` when the check ran (including a clean report and a hook returning `{}`), `1` when the
261
+ live index cannot be built or `--no-live` has no manifest, and `2` for a usage error.
262
+
263
+ → [Change Guard](guard.md): hook setup for Claude Code, Copilot and Codex, and what it does not claim.
264
+
242
265
  ### `brief`
243
266
 
244
267
  ```bash
@@ -279,7 +302,7 @@ The whole first run in one command, with defaults and no prompts. This is the sa
279
302
  🚀 Setup for: /path/to/repo
280
303
  ✅ Created snapshot.config.json (preset: nextjs)
281
304
  Added npm scripts: snapshot, snapshot:validate
282
- Added devDependency: codebase-snapshot ^0.21.0
305
+ Added devDependency: codebase-snapshot ^0.22.1
283
306
  Added to .gitignore: /snapshot/, /snapshot.tmp/
284
307
  ⏳ Installing dependencies…
285
308
  ✅ Installed dependencies (npm install, 2.1s)
@@ -331,7 +354,7 @@ It also has three side effects on files you own, and it says so when it does the
331
354
  ```
332
355
  ✅ Created snapshot.config.json (preset: node-lib)
333
356
  Added npm scripts: snapshot, snapshot:validate
334
- Added devDependency: codebase-snapshot ^0.21.0
357
+ Added devDependency: codebase-snapshot ^0.22.1
335
358
  Added to .gitignore: /snapshot/, /snapshot.tmp/
336
359
  ```
337
360
 
@@ -358,8 +381,8 @@ returns to *"How should I set this up?"*. Answering **No** at the review steps b
358
381
  abandoning the run — Ctrl+C is how you abandon.
359
382
 
360
383
  Nothing else in the repository is touched: no `AGENTS.md`, no `.claude/`, no `.cursor/`. In a
361
- repository with a `package.json` and no config, `git status` shows the config as the only new
362
- file.
384
+ repository with a `package.json` and no config, `git status` shows the config and the
385
+ `BRIEF.md` scaffold as the new files.
363
386
 
364
387
  Interactive by default; with `--yes` it accepts every default and never prompts, which is
365
388
  what agents and release checks should use.
@@ -481,8 +504,8 @@ agent](agent.md).
481
504
  Ask the npm registry whether a newer release exists, and print the version it compared against:
482
505
 
483
506
  ```bash
484
- npx codebase-snapshot@0.21.0 update # is this build current? print the answer
485
- npx codebase-snapshot@0.21.0 update --format json
507
+ npx codebase-snapshot@0.22.1 update # is this build current? print the answer
508
+ npx codebase-snapshot@0.22.1 update --format json
486
509
  ```
487
510
 
488
511
  ```text
@@ -558,8 +581,8 @@ for the two install flags, and the init-and-setup flags list both commands.
558
581
 
559
582
  | Option | Type | Default | Applies to | Meaning |
560
583
  | :--- | :--- | :--- | :--- | :--- |
561
- | `--cwd <path>` | path | current directory | generate, validate, report, impact, brief, explain, init, setup, skill, mcp, health, serve | Repository to operate on. Must exist and be a directory. `diff` and `describe` take no `--cwd`; for `mcp` it chooses the one repository the server serves. |
562
- | `--out-dir <path>` | path | `snapshot` | generate, validate, report, impact, brief, explain, init, setup, health | Where the snapshot is written or read. May be absolute. |
584
+ | `--cwd <path>` | path | current directory | generate, validate, report, impact, guard, brief, explain, init, setup, skill, mcp, health, serve | Repository to operate on. Must exist and be a directory. `diff` and `describe` take no `--cwd`; for `mcp` it chooses the one repository the server serves. |
585
+ | `--out-dir <path>` | path | `snapshot` | generate, validate, report, impact, guard, brief, explain, init, setup, health | Where the snapshot is written or read. May be absolute. |
563
586
  | `--max-part-bytes <n>` | size | `307200` (300 KB) | generate, validate, init, setup | Hard ceiling per markdown part. Accepts `120k`, `1.5mb`. Minimum 4096. |
564
587
  | `--max-part-tokens <n>` | size | unset | generate, validate, setup | A per-part ceiling in **tokens**, for a context window rather than a disk. Narrows `--max-part-bytes` to the equivalent byte count (`tokens × 4`); the smaller of the two ceilings always wins, and both are recorded in the manifest. Accepts `32k`. Minimum 1024 — below that it is a usage error, not a value quietly raised to the floor. The byte ceiling is what is enforced: `estimatedTokens` is an estimate, and a part whose estimate exceeds the token ceiling is named in a warning rather than silently accepted. |
565
588
  | `--large-file-bytes <n>` | size | the part budget (307200) | generate, validate, explain, setup | Above this, a file becomes a head/tail preview. It may not exceed `--max-part-bytes`: a file between the two could not fit a part. |
@@ -578,7 +601,7 @@ for the two install flags, and the init-and-setup flags list both commands.
578
601
  | `--all-members` | flag | off | health | Audit every snapshot a `--workspace` run wrote, not only the one at `outDir`. The combined score is the weakest member. |
579
602
  | `--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. |
580
603
  | `--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. |
581
- | `--mode <command>` | string | unset | generate, validate, report, impact, brief, explain, init, setup, diff, describe, skill, mcp, health, update, serve | 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). |
604
+ | `--mode <command>` | string | unset | generate, validate, report, impact, guard, brief, explain, init, setup, diff, describe, skill, mcp, health, update, serve | 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). |
582
605
  | `--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. |
583
606
  | `--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. |
584
607
  | `--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). |
@@ -601,21 +624,24 @@ for the two install flags, and the init-and-setup flags list both commands.
601
624
  | `--include-sensitive-files` | flag | off | generate, validate, explain, init, setup | Emit `.env`, `*.pem`, `.npmrc` and similar. Off by default; they are reported as skipped. |
602
625
  | `--skip-artifacts <names>` | list | unset | generate, validate, init, setup | Comma-separated artifacts to omit. |
603
626
  | `--only-artifacts <names>` | list | unset | generate, validate, init, setup | Write *only* these, and **turn on** any this names: a config with `artifacts: { audit: false }` still gets `reports/audit.md` from `--only-artifacts audit`, because "only these" is a statement about the whole selection rather than a suppression list. Cannot be combined with `--skip-artifacts`. |
604
- | `--format <text\|json\|markdown\|pr-comment>` | enum | `text` | generate, validate, report, impact, brief, explain, init, setup, diff, describe, skill, health, update | `json` writes a pure JSON payload to stdout. `impact` and `brief` also accept `markdown`; `pr-comment` renders the same brief with collapsible sections. Every command except `mcp` and `serve` honours `--format` — stdout there is the JSON-RPC protocol stream. |
627
+ | `--format <text\|json\|markdown\|pr-comment>` | enum | `text` | generate, validate, report, impact, guard, brief, explain, init, setup, diff, describe, skill, health, update | `json` writes a pure JSON payload to stdout. `impact` and `brief` also accept `markdown`; `pr-comment` renders the same brief with collapsible sections. Every command except `mcp` and `serve` honours `--format` — stdout there is the JSON-RPC protocol stream. |
605
628
  | `--sarif` | flag | off | generate, validate, setup | Also write `reports/audit.sarif`: the redaction findings as SARIF 2.1.0, for upload to GitHub Code Scanning. The artefact carries the path, the line and the rule — never the value. Works with `--skip-artifacts audit`, because a CI gate does not read markdown. Rule ids are fixed per rule name, so adding a custom rule never re-points an existing alert. |
606
629
  | `--skeleton` | flag | off | generate, validate, setup | Emit signatures instead of bodies: each function or method body becomes `{ /* ... */ }` in place, so formatting and comments around it are untouched. Covers `.ts`, `.tsx`, `.mts`, `.cts`, `.js`, `.jsx`, `.mjs` and `.cjs`; `.d.ts` files are left alone because they are already declarations. The summary still describes the whole file, and affected entries carry `inclusionMode: "signatures"`. `--include-monolith` still writes the whole body, so the monolith's `inclusionMode: "full"` stays true. |
607
630
  | `--changed-since <ref>` | git ref | unset | generate, validate, explain | Include only files changed since this ref, plus untracked ones. Every other file is recorded in `manifest.skipped[]` with reason `unchanged` and is never opened. `validate` re-resolves the scope: a skipped file that has changed since is reported as drift, and one that has not is left alone — and with `--with-dependents`, so is a file that now imports one that changed. `explain` answers with the same rule. A ref beginning with `-` is refused. |
608
- | `--diff <ref>` | git ref | unset | impact, brief | Compare the working tree against this ref for the impact report or change brief. Includes committed, staged, unstaged and untracked changes relative to it. Mutually exclusive with `--paths`; a ref beginning with `-` is refused. |
609
- | `--paths <a,b>` | list | unset | impact, brief | Comma-separated repository-relative paths to treat as the change. Absolute paths and `..` segments are refused. Mutually exclusive with `--diff`. |
610
- | `--depth <n>` | count | `3` | impact, brief | Reverse-import hops to follow for the impact report or change brief. Minimum 1, maximum 8. |
611
- | `--max-results <n>` | count | `200` | impact, brief | Maximum files in `affected[]`. Minimum 1, maximum 1000; a hit sets `truncated` and adds a warning. |
612
- | `--no-cache` | flag | off | impact, brief | Bypass the optional OS live-index summary cache. No cache file is written, and nothing is ever written inside the repository. |
613
- | `--no-live` | flag | off | impact, brief | Require the generated snapshot instead of building or overlaying the live index. |
631
+ | `--diff <ref>` | git ref | unset | impact, guard, brief | Compare the working tree against this ref for the impact report or change brief. Includes committed, staged, unstaged and untracked changes relative to it. Mutually exclusive with `--paths`; a ref beginning with `-` is refused. |
632
+ | `--paths <a,b>` | list | unset | impact, guard, brief | Comma-separated repository-relative paths to treat as the change. Absolute paths and `..` segments are refused. Mutually exclusive with `--diff`. |
633
+ | `--depth <n>` | count | `3` | impact, guard, brief | Reverse-import hops to follow for the impact report or change brief. Minimum 1, maximum 8. |
634
+ | `--max-results <n>` | count | `200` | impact, guard, brief | Maximum files in `affected[]`. Minimum 1, maximum 1000; a hit sets `truncated` and adds a warning. |
635
+ | `--no-cache` | flag | off | impact, guard, brief | Bypass the optional OS live-index summary cache. No cache file is written, and nothing is ever written inside the repository. |
636
+ | `--no-live` | flag | off | impact, guard, brief | Require the generated snapshot instead of building or overlaying the live index. |
614
637
  | `--tests-paths` | flag | off | impact | Print candidate test paths, one per line, instead of the report. |
615
638
  | `--run` | flag | off | impact | Run the repository's own Vitest, Jest or `node --test` entry against the candidate tests. Uses `shell: false`; a build or test configuration change adds a full-suite warning. |
616
639
  | `--precise` | flag | off | impact | Add compiler-resolved symbol references to the report. Requires the live index. |
617
640
  | `--include-imports` | flag | off | impact | Add outgoing dependencies of every changed file. |
618
641
  | `--include-cycles` | flag | off | impact | Add import cycles in the impacted subgraph. |
642
+ | `--hook <client>` | enum | unset | guard | Read one hook payload from stdin and shape the response for `claude`, `copilot`, `codex` or `raw`. Fail-open: an error returns `{}` and a stderr note. |
643
+ | `--changed` | flag | off | guard | Check the working tree against `HEAD`. This is the default when `--hook` is not given. |
644
+ | `--max-chars <n>` | count | `1200` | guard | Cap the model-facing hook text. Minimum 200, maximum 10000. |
619
645
  | `--copy` | flag | off | brief | Copy the finished brief to the platform clipboard. |
620
646
  | `--out <path>` | path | unset | brief | Write the brief to this repository-relative path. A path that resolves outside the repository is refused. |
621
647
  | `--max-tokens <n>` | count | `12000` | brief | Token budget for the assembled brief. |
@@ -629,7 +655,7 @@ for the two install flags, and the init-and-setup flags list both commands.
629
655
  | `--watch` | flag | off | generate | Regenerate on every change until interrupted. Redaction and parsing are cached per file across runs in the same process, keyed on the content hash, so a one-file edit regenerates from that one file instead of from the whole repository. The cache is memory only and is dropped when the process exits. |
630
656
  | `--autopilot` | flag | off | generate | Set the project up without asking — config, `.gitignore`, npm scripts, devDependency, install — then generate. Never overwrites an existing config; refuses an empty directory (exit `1`); contradicts `--no-config` (exit `2`). |
631
657
  | `--no-install` | flag | off | setup, generate `--autopilot` | Skip the dependency install. Anywhere else it is a usage error, because it would change nothing. |
632
- | `--no-config` | flag | off | generate, validate, report, impact, brief, explain, diff, mcp | Ignore every `snapshot.config.*` file and run on the built-in defaults. `diff` never loads a config anyway and accepts the flag for consistency; `mcp` uses it when a repository config cannot be read or should not be trusted. |
658
+ | `--no-config` | flag | off | generate, validate, report, impact, guard, brief, explain, diff, health, mcp | Ignore every `snapshot.config.*` file and run on the built-in defaults. `diff` never loads a config anyway and accepts the flag for consistency; `mcp` uses it when a repository config cannot be read or should not be trusted. |
633
659
  | `--discovery <mode>` | enum | `auto` | generate, validate, explain, setup | How files are found: `auto` lists through git when git works and refuses when a `.git` directory cannot be listed; `git` requires git; `walk` scans the tree and reads `.gitignore` files directly. The escape hatch for a broken `.git`. |
634
660
  | `--preset <name>` | name | detected | init, setup | Force a preset instead of detecting one. |
635
661
  | `--include <globs>` | list | unset | init, setup | Allow-list recorded in the generated config. |
@@ -675,12 +701,12 @@ same run. With `--mode`, the remaining positionals are that command's arguments,
675
701
  `--mode explain src/server.ts` and `--mode diff old-snapshot snapshot` work the same way the
676
702
  positional form does.
677
703
 
678
- It accepts the fifteen commands plus the `check` alias — the sixteen names the error lists — and it is
704
+ It accepts the sixteen commands plus the `check` alias — the seventeen names the error lists — and it is
679
705
  deliberately strict: asking for two different commands is an error rather than a silent winner.
680
706
 
681
707
  ```
682
708
  ❌ --mode validate contradicts the command "generate". Pass one or the other.
683
- ❌ Unknown --mode "bogus". Expected one of: generate, validate, check, report, impact, brief, init, setup, explain, diff, describe, skill, mcp, health, update, serve.
709
+ ❌ Unknown --mode "bogus". Expected one of: generate, validate, check, report, impact, guard, brief, init, setup, explain, diff, describe, skill, mcp, health, update, serve.
684
710
  ```
685
711
 
686
712
  `describe` does list `--mode` in its option table (`appliesTo` names every command that accepts it),
@@ -704,12 +730,13 @@ wrong and retrying it unchanged will fail the same way.
704
730
  - **stdout** carries the payload. With `--format json` it is pure JSON, safe to pipe into
705
731
  `jq` or `JSON.parse`.
706
732
  - **stderr** carries progress, the human summary, warnings and errors.
707
- - **In text mode the human result is on stderr, and stdout is empty** — for every command
708
- except `skill`. `report`, `explain`, `diff`, `validate`, `describe`, `setup` and
709
- `generate` print their answer and progress to stderr, so redirecting `command > file.txt`
710
- writes an empty file in text mode; use `--format json` when you want the output on stdout.
711
- `skill` without `--install` prints the skill to stdout so it can be redirected, and the
712
- `--help` / `--version` print paths do the same. `mcp` uses stdout for the JSON-RPC protocol.
733
+ - **In text mode the human result is on stderr, and stdout is empty** — for most commands.
734
+ `report`, `explain`, `diff`, `validate`, `describe`, `setup` and `generate` print their
735
+ answer and progress to stderr, so redirecting `command > file.txt` writes an empty file in
736
+ text mode; use `--format json` when you want the output on stdout. The exceptions are
737
+ `skill` without `--install` (the skill itself), `brief` (its Markdown review pack),
738
+ `impact` with `--tests-paths` or `--format markdown`, and the `--help` / `--version`
739
+ paths. `mcp` uses stdout for the JSON-RPC protocol.
713
740
 
714
741
  A failing invocation still writes one JSON document to stdout, so an agent never has to parse an
715
742
  empty string:
package/docs/contents.md CHANGED
@@ -16,6 +16,8 @@ Every page on this site, grouped by the job you are doing. If you are new, start
16
16
  ## Core workflows
17
17
 
18
18
  - [Impact reports](impact.md) — what a change reaches and which tests to run.
19
+ - [Change Guard](guard.md) — the untouched consumers, tests and routes after an edit, with a
20
+ hook mode for Claude Code, Copilot and Codex.
19
21
  - [Briefs](brief.md) — one redacted, bounded review pack.
20
22
  - [MCP server](mcp.md) — transports, sessions, resources and protocol details.
21
23
  - [MCP server for a codebase](mcp-server-for-codebase.md) — setup for Claude, Cursor and generic
package/docs/deploy.md CHANGED
@@ -37,13 +37,19 @@ services:
37
37
  security_opt: ["no-new-privileges:true"]
38
38
  ```
39
39
 
40
- The page generates **into the container**, which is ephemeral. Mount a volume and paste that path
41
- into the page if the snapshot needs to outlive the container:
40
+ The page generates **into the container**, which is ephemeral. Mount a volume, point the server's
41
+ root at it with `SNAPSHOT_CWD`, and paste that path into the page if the snapshot needs to outlive
42
+ the container:
42
43
 
43
44
  ```yaml
44
45
  volumes: ["snapshot-data:/data"]
46
+ environment:
47
+ SNAPSHOT_CWD: /data
45
48
  ```
46
49
 
50
+ The entrypoint passes `SNAPSHOT_CWD` to `serve --cwd`, so `/data` is inside the served root. Without
51
+ it, `serve` starts in `/app` and correctly refuses `/data` with HTTP 403.
52
+
47
53
  ### What the image is not
48
54
 
49
55
  - It is not published to a registry by this repository. Build it where you need it; a public image
@@ -61,8 +67,8 @@ After=network.target
61
67
  Type=oneshot
62
68
  User=deploy
63
69
  WorkingDirectory=/srv/app
64
- ExecStart=/usr/bin/npx -y codebase-snapshot@0.21.0 generate --cwd /srv/app
65
- ExecStartPost=/usr/bin/npx -y codebase-snapshot@0.21.0 validate --cwd /srv/app
70
+ ExecStart=/usr/bin/npx -y codebase-snapshot@0.22.1 generate --cwd /srv/app
71
+ ExecStartPost=/usr/bin/npx -y codebase-snapshot@0.22.1 validate --cwd /srv/app
66
72
  ```
67
73
 
68
74
  ```ini
package/docs/guard.md ADDED
@@ -0,0 +1,197 @@
1
+ # Change Guard
2
+
3
+ `guard` answers one question after an agent edits code: **what does this change reach that is
4
+ not in the change set?** It returns untouched consumers, candidate tests and affected routes — or
5
+ nothing at all.
6
+
7
+ It is the in-loop companion to [impact](impact.md) and [brief](brief.md). Impact is a report you
8
+ ask for; Change Guard is a check that can run on every edit and stay silent until it has something
9
+ useful to say.
10
+
11
+ ## Install
12
+
13
+ If your agent has a plugin marketplace, install Change Guard from this repository. There is no
14
+ JSON to merge and no file to copy.
15
+
16
+ **Claude Code**
17
+
18
+ ~~~text
19
+ /plugin marketplace add ankurhalder/codebase-snapshot
20
+ /plugin install codebase-snapshot-change-guard@codebase-snapshot
21
+ ~~~
22
+
23
+ **Codex**
24
+
25
+ ~~~bash
26
+ codex plugin marketplace add ankurhalder/codebase-snapshot
27
+ codex plugin add codebase-snapshot-change-guard@codebase-snapshot
28
+ ~~~
29
+
30
+ **Copilot CLI, Devin and Qoder**
31
+
32
+ ~~~bash
33
+ copilot plugin install ankurhalder/codebase-snapshot:agent-plugin
34
+ devin plugins install ankurhalder/codebase-snapshot#agent-plugin
35
+ qoder plugins marketplace add ankurhalder/codebase-snapshot
36
+ qoder plugins install codebase-snapshot-change-guard
37
+ ~~~
38
+
39
+ Claude Code and Qoder install the `PostToolUse` hook together with the plugin; Copilot uses
40
+ `com.github.copilot/hooks.json`; Codex and Devin install the skill, which calls the guard
41
+ when the policy says to. A host without a marketplace can copy `~/.agents/skills/change-guard`
42
+ and use the hook block below.
43
+
44
+ The hook runs a pinned CLI, so the machine needs Node.js 18+ and `npx`:
45
+
46
+ ~~~bash
47
+ npx -y codebase-snapshot@0.22.1 --version
48
+ ~~~
49
+
50
+ ## Run it
51
+
52
+ ~~~bash
53
+ codebase-snapshot guard --changed
54
+ codebase-snapshot guard --paths src/auth.ts --format json
55
+ codebase-snapshot guard --diff origin/main --format json
56
+ ~~~
57
+
58
+ With no options it checks the working tree against `HEAD`. The output is small on purpose:
59
+
60
+ ~~~text
61
+ Change Guard: 2 gap(s) in this change
62
+ consumer src/api.ts (1 hop, relative-import, via src/auth.ts)
63
+ test tests/auth.test.ts (test: src/auth.ts)
64
+ coverage: complete · confidence: file-import
65
+ ~~~
66
+
67
+ Every gap is a path outside the change. A file the change already touched is never reported again.
68
+ `confidence` is `symbol-pruned` only when a diff seeded symbol-level matches; a hook payload or
69
+ `--paths` run is file-level (`file-import`).
70
+
71
+ ## Hook mode
72
+
73
+ `--hook <client>` reads one JSON payload from stdin and writes the host-shaped response to stdout.
74
+ It never fails the agent's turn: a malformed payload or a missing manifest produces an empty object
75
+ and a note on stderr.
76
+
77
+ | Client | Flag | Response |
78
+ | :-- | :-- | :-- |
79
+ | Claude Code | `--hook claude` | `hookSpecificOutput.additionalContext` with `hookEventName` |
80
+ | Copilot | `--hook copilot` | top-level `additionalContext` |
81
+ | Codex | `--hook codex` | top-level `additionalContext` |
82
+ | Other | `--hook raw` | top-level `additionalContext` |
83
+
84
+ When there is nothing to report, the response is `{}`. That is the point: a guard that speaks when
85
+ there is nothing wrong is a guard users disable.
86
+
87
+ ### Claude Code
88
+
89
+ The plugin install above already wires this hook. Use this block only for a manual setup.
90
+
91
+ ~~~json
92
+ {
93
+ "hooks": {
94
+ "PostToolUse": [
95
+ {
96
+ "matcher": "Edit|Write",
97
+ "hooks": [
98
+ {
99
+ "type": "command",
100
+ "command": "npx -y codebase-snapshot@0.22.1 guard --hook claude",
101
+ "timeout": 10
102
+ }
103
+ ]
104
+ }
105
+ ]
106
+ }
107
+ }
108
+ ~~~
109
+
110
+ ### Copilot in VS Code
111
+
112
+ ~~~json
113
+ {
114
+ "version": 1,
115
+ "hooks": {
116
+ "postToolUse": [
117
+ {
118
+ "type": "command",
119
+ "command": "npx -y codebase-snapshot@0.22.1 guard --hook copilot",
120
+ "timeoutSec": 10
121
+ }
122
+ ]
123
+ }
124
+ }
125
+ ~~~
126
+
127
+ ### Codex CLI
128
+
129
+ ~~~json
130
+ {
131
+ "hooks": {
132
+ "PostToolUse": [
133
+ {
134
+ "matcher": "Edit|Write",
135
+ "hooks": [
136
+ {
137
+ "type": "command",
138
+ "command": "npx -y codebase-snapshot@0.22.1 guard --hook codex",
139
+ "timeout": 10
140
+ }
141
+ ]
142
+ }
143
+ ]
144
+ }
145
+ }
146
+ ~~~
147
+
148
+ The exact file location is the host's: `.claude/settings.json`, `.github/hooks/*.json`,
149
+ `.codex/hooks.json`, or the plugin's own `hooks/hooks.json`. The command is the same.
150
+
151
+ ## What it reads
152
+
153
+ The guard reuses the live index: the working tree is scanned in memory and uncommitted edits are
154
+ overlaid, so no `generate` run is required. `--no-live` requires a persisted manifest instead.
155
+
156
+ It reads the same manifest and import resolver as [impact](impact.md). It never writes into the
157
+ repository and never reads a sensitive file: `.env`, `*.pem` and the rest stay out.
158
+
159
+ ## What it does not claim
160
+
161
+ - **Candidate tests, not coverage.** A test that imports a changed file is a candidate; it may not
162
+ exercise the changed behavior.
163
+ - **Static reach, not runtime reach.** A dynamic import the parser cannot evaluate is absent rather
164
+ than guessed; the trust envelope says when coverage is partial.
165
+ - **No proof.** A clean report means no gap was found within the bounds, not that the change is
166
+ correct.
167
+ - **No model call.** The guard is deterministic. It does not ask another model to review the diff.
168
+
169
+ ## Bounds
170
+
171
+ | Limit | Default | Why |
172
+ | :-- | --: | :-- |
173
+ | Consumers in one report | 10 | Keep the model-facing note under a token budget |
174
+ | Candidate tests | 5 | The agent can run the highest-value ones first |
175
+ | Routes | 5 | Same |
176
+ | Hook text | 1200 chars | `--max-chars` changes it (200-10000) |
177
+
178
+ When the list is cut, `truncated` is true and the omitted counts are recorded. Nothing disappears
179
+ without a number.
180
+
181
+ ## Exit codes
182
+
183
+ | Code | Meaning |
184
+ | :-- | :-- |
185
+ | 0 | The check ran. This includes a clean report and a hook that returned `{}`. |
186
+ | 1 | The live index could not be built, or `--no-live` was given without a manifest. |
187
+ | 2 | A usage error: an unknown client, `--max-chars` out of range, or `--hook` combined with `--paths`. |
188
+
189
+ In hook mode a failure is fail-open: stdout is `{}` and the reason is on stderr, so a broken guard
190
+ cannot break the agent's turn.
191
+
192
+ ## Related
193
+
194
+ - [Impact reports](impact.md) — the analysis the guard summarizes.
195
+ - [Briefs](brief.md) — the reviewer-facing pack.
196
+ - [MCP tools](tools.md) — the same analysis over MCP.
197
+ - [Stale context is your bug](stale-context-is-your-bug.md) — why freshness is a separate check.
package/docs/impact.md CHANGED
@@ -78,8 +78,9 @@ adds a warning that the selective run may be incomplete; run the full suite too.
78
78
  ## Output
79
79
 
80
80
  `--format json` is the stable contract and writes one JSON document to stdout. Text goes to stderr,
81
- as every human-facing command does. `--format markdown` writes a PR-ready report to stdout;
82
- `--format pr-comment` is accepted by `brief`, which is the page-oriented command.
81
+ as every human-facing command does. `--format markdown` writes a PR-ready report to stdout.
82
+ `--format pr-comment` is accepted here and by `brief`: `impact` renders the same Markdown
83
+ report, while `brief` writes the page-oriented PR comment.
83
84
 
84
85
  Exit `0` when the report was produced, `1` when the live index cannot be built or an explicit
85
86
  `--no-live` manifest is missing, and `2` for a usage error.
@@ -5,8 +5,16 @@ impact facts a question needs, instead of attaching the whole repository.** code
5
5
  one: seven tools (six read-only) over stdio or Streamable HTTP, a live index that sees uncommitted
6
6
  edits, and a persistent snapshot when you need a shared artefact.
7
7
 
8
- This guide covers what the server exposes, how to wire it into Claude, Cursor, Claude Code or any
9
- generic MCP client, what it can read, and where its limits are.
8
+ The server is listed in the official MCP Registry as
9
+ [`io.github.ankurhalder/codebase-snapshot`](https://registry.modelcontextprotocol.io/v0.1/servers?search=io.github.ankurhalder%2Fcodebase-snapshot).
10
+ This guide covers what it exposes, how to wire it into Claude, Cursor, Claude Code or any generic
11
+ MCP client, what it can read, and where its limits are.
12
+
13
+ <p align="center">
14
+ <a href="https://mcprush.com/to/codebase-snapshot-mcp?ref=badge">
15
+ <img width="380" height="200" src="https://mcprush.com/badge/codebase-snapshot-mcp/card.svg" alt="Codebase Snapshot MCP server on mcprush">
16
+ </a>
17
+ </p>
10
18
 
11
19
  ## Why a local MCP server instead of a packed file
12
20
 
@@ -122,8 +130,8 @@ repository it serves.
122
130
 
123
131
  ## Security boundary
124
132
 
125
- - The server reads only the served root. --root can add directories explicitly; a path outside them
126
- is refused.
133
+ - The server reads only the directories it was started with. The `root` tool argument selects one
134
+ of them; a path outside them is refused. There is no CLI `--root` flag.
127
135
  - Sensitive paths are never readable through snapshot_read, even when they exist on disk.
128
136
  - A snapshot generated with --include-sensitive-files is refused by the MCP transport and by serve.
129
137
  - HTTP binds loopback by default, requires a bearer token for /api and generates one on first run.
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.21.0 mcp
13
+ npx -y codebase-snapshot@0.22.1 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.21.0", "mcp", "--cwd", "/absolute/path/to/repo"]
28
+ "args": ["-y", "codebase-snapshot@0.22.1", "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.21.0 mcp --cwd /absolute/path/to/repo
37
+ claude mcp add codebase-snapshot -- npx -y codebase-snapshot@0.22.1 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,7 +43,7 @@ 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.21.0 mcp --http --port 4789
46
+ npx -y codebase-snapshot@0.22.1 mcp --http --port 4789
47
47
  ```
48
48
 
49
49
  This is the Streamable HTTP shape: POST one JSON-RPC message to `/mcp` and read the JSON-RPC
@@ -51,7 +51,11 @@ answer from the response body. Modern (`2026-07-28`) requests must also carry
51
51
  `MCP-Protocol-Version`, `Mcp-Method` and — for `tools/call`, `resources/read` and
52
52
  `prompts/get` — `Mcp-Name`. A missing header, or one that disagrees with the body, is refused
53
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
54
+ names. Modern cacheable results (`server/discover`, `tools/list`, `prompts/list`,
55
+ `resources/list`, `resources/read`, `resources/templates/list`) also carry `ttlMs` and
56
+ `cacheScope`; this server sets `ttlMs` to `0` and `cacheScope` to `private`, so a regenerated
57
+ snapshot is never served from a stale shared cache. Legacy requests keep the session behaviour
58
+ below. `GET /healthz` answers
55
59
  `{ ok, name, version, tools, uptimeSeconds }` without a token, and `GET /metrics` answers Prometheus
56
60
  text: `snapshot_requests_total`, `snapshot_requests_by_method_total{method="…"}` (fixed labels,
57
61
  never a path or a credential), `snapshot_requests_refused_total` (every 4xx except 429: an