codebase-snapshot 0.22.0 → 0.22.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +27 -0
- package/README.md +28 -19
- package/dist/bin.js +2211 -1061
- package/dist/{chunk-NPCDJBE4.js → chunk-OVH6B3GV.js} +1738 -747
- package/dist/cli.cjs +2328 -1188
- package/dist/cli.js +333 -184
- package/dist/index.cjs +1717 -732
- package/dist/index.d.cts +3 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +1 -1
- package/dist/mcp.cjs +1118 -368
- package/dist/mcp.d.cts +5 -2
- package/dist/mcp.d.ts +5 -2
- package/dist/mcp.js +1 -1
- package/docs/about.md +3 -2
- package/docs/agent.md +5 -1
- package/docs/answer.md +40 -11
- package/docs/cli.md +17 -16
- package/docs/deploy.md +10 -4
- package/docs/guard.md +55 -8
- package/docs/impact.md +3 -2
- package/docs/mcp-server-for-codebase.md +2 -2
- package/docs/mcp.md +5 -5
- package/docs/security-review.md +8 -2
- package/docs/tools.md +18 -3
- package/docs/troubleshooting.md +2 -2
- package/package.json +1 -1
package/dist/mcp.d.cts
CHANGED
|
@@ -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
|
-
|
|
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
|
@@ -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
|
-
|
|
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-
|
|
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-OVH6B3GV.js';
|
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
|
|
18
|
-
file, symbol or impact report it needs
|
|
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
|
|
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
|
|
|
@@ -146,6 +147,9 @@ has an MCP connection, for two reasons that are properties of the design rather
|
|
|
146
147
|
instead.
|
|
147
148
|
- **Staleness is a first-class question.** `snapshot_validate` answers "has the code moved since
|
|
148
149
|
this was built", which an agent with only a filesystem tool has no way to ask.
|
|
150
|
+
- **Context is line-targeted.** `snapshot_context` uses an explicit symbol's declaration span or a
|
|
151
|
+
requested line range, not the file head. It removes hidden instructions and returns a receipt
|
|
152
|
+
that hashes exactly what was shown, so a reviewer can audit the context later.
|
|
149
153
|
|
|
150
154
|
The tools are listed in [the MCP guide](mcp.md) and in the `mcp` block of
|
|
151
155
|
`describe --format json`. A `root` argument may name a sub-directory of the directory the server was
|
package/docs/answer.md
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
# One question, one bounded context
|
|
2
2
|
|
|
3
3
|
An agent usually has one question and one budget, not a browsing session. `snapshot_context` is
|
|
4
|
-
the one-call answer: give it a question, files or
|
|
5
|
-
line-numbered context that fits the token ceiling. Every planned file that did
|
|
6
|
-
`omitted[]`, and the response carries the same
|
|
4
|
+
the one-call answer: give it a question, files, symbols or explicit line ranges, and it returns the
|
|
5
|
+
smallest redacted, line-numbered context that fits the token ceiling. Every planned file that did
|
|
6
|
+
not fit is named in `omitted[]`, hidden instructions are removed, and the response carries the same
|
|
7
|
+
`trust` envelope as every other read-only tool plus a verifiable context receipt.
|
|
7
8
|
|
|
8
9
|
```json
|
|
9
10
|
{
|
|
@@ -16,9 +17,10 @@ line-numbered context that fits the token ceiling. Every planned file that did n
|
|
|
16
17
|
```
|
|
17
18
|
|
|
18
19
|
`planOnly: true` returns the ranked reading plan without bodies. Use it when you want to choose
|
|
19
|
-
what to open yourself; use the default when you want the context in one call. With `files
|
|
20
|
-
`symbols`, the planner is skipped and those targets are assembled directly, still
|
|
21
|
-
budget and with the same omission list.
|
|
20
|
+
what to open yourself; use the default when you want the context in one call. With `files`,
|
|
21
|
+
`symbols` and `ranges`, the planner is skipped and those targets are assembled directly, still
|
|
22
|
+
under the same budget and with the same omission list. A symbol target starts at its declaration
|
|
23
|
+
span, not line 1; a range target is numbered from the requested start line.
|
|
22
24
|
|
|
23
25
|
The live index is used by default, so uncommitted edits and new files are visible without running
|
|
24
26
|
generate. live: false requires the persisted snapshot.
|
|
@@ -55,12 +57,17 @@ The structured response contains:
|
|
|
55
57
|
| :-- | :-- |
|
|
56
58
|
| budgetTokens | The ceiling the caller asked for. |
|
|
57
59
|
| usedTokens | The estimate actually spent on the returned bodies. |
|
|
58
|
-
| files | The chosen files, each with its part, layer, kind,
|
|
60
|
+
| files | The chosen files, each with its part, layer, kind, `fromLine`/`toLine`, symbol (if any) and why it was chosen. |
|
|
59
61
|
| omitted | Every planned file that did not fit, with the reason. |
|
|
62
|
+
| security | Hidden-instruction comments and invisible characters removed from the returned bodies. |
|
|
63
|
+
| receipt | SHA-256 digest of the canonical response chunks, omissions, security findings and trust. Optional Ed25519 signature. |
|
|
60
64
|
| trust | Index source, freshness, coverage, redaction count and named partial reasons. |
|
|
61
65
|
|
|
62
|
-
A file in files may be a window rather than the whole body. The window is line-numbered
|
|
63
|
-
whether more remains, so an agent can ask for the next page
|
|
66
|
+
A file in files may be a window rather than the whole body. The window is line-numbered with the
|
|
67
|
+
real source line numbers and states whether more remains, so an agent can ask for the next page
|
|
68
|
+
instead of assuming it has the file. Hidden HTML comments that look like instructions, zero-width
|
|
69
|
+
characters and bidi controls are removed before the body is returned; the security array names what
|
|
70
|
+
was removed without echoing the payload.
|
|
64
71
|
|
|
65
72
|
## A worked example
|
|
66
73
|
|
|
@@ -79,10 +86,32 @@ names the files that did not fit; if the redaction tests are omitted, the trust
|
|
|
79
86
|
coverage is complete for the plan, because the plan itself is what was bounded. Read omitted before
|
|
80
87
|
concluding that the answer is complete.
|
|
81
88
|
|
|
89
|
+
## Line targeting and receipts
|
|
90
|
+
|
|
91
|
+
Pass `symbols` when you know the declaration; the tool uses the parsed `declarationSpans` and
|
|
92
|
+
returns the span, with `fromLine`/`toLine` and `symbol`. Pass `ranges` when you already know the
|
|
93
|
+
lines:
|
|
94
|
+
|
|
95
|
+
```json
|
|
96
|
+
{
|
|
97
|
+
"name": "snapshot_context",
|
|
98
|
+
"arguments": {
|
|
99
|
+
"ranges": [{ "path": "src/mcp/retrieval.ts", "startLine": 96, "endLine": 135 }],
|
|
100
|
+
"maxTokens": 4000
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
The receipt is deterministic for the same index and inputs. `digest` covers the canonical chunk
|
|
106
|
+
metadata, omission list, security findings and trust envelope; each chunk also has its own
|
|
107
|
+
`sha256`. Set `signReceipt: true` with `SNAPSHOT_SIGNING_KEY` configured to add an Ed25519
|
|
108
|
+
signature over the same canonical payload. A receipt proves what was returned; it does not prove
|
|
109
|
+
the code was correct.
|
|
110
|
+
|
|
82
111
|
## Limits
|
|
83
112
|
|
|
84
|
-
- **Terms, not intent.** Synonyms the planner does not know are missed. Pass files
|
|
85
|
-
you know the target.
|
|
113
|
+
- **Terms, not intent.** Synonyms the planner does not know are missed. Pass files, symbols or
|
|
114
|
+
ranges when you know the target.
|
|
86
115
|
- **Token estimates, not tokenizer counts.** The estimate is useful for choosing a budget; it is not
|
|
87
116
|
a model's exact count.
|
|
88
117
|
- **No write access.** The tool never edits or runs code. It returns context.
|
package/docs/cli.md
CHANGED
|
@@ -104,7 +104,7 @@ Exit `0` when the snapshot passes its own integrity check, `1` when it does not.
|
|
|
104
104
|
|
|
105
105
|
```
|
|
106
106
|
📸 Generating snapshot for: /path/to/repo
|
|
107
|
-
Branch: main (fallback) | Part budget: 300 KB | Generator: 0.22.
|
|
107
|
+
Branch: main (fallback) | Part budget: 300 KB | Generator: 0.22.2 (project dependency ^0.22.2)
|
|
108
108
|
|
|
109
109
|
✅ Snapshot generated in 0.14s:
|
|
110
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
|
|
@@ -302,7 +302,7 @@ The whole first run in one command, with defaults and no prompts. This is the sa
|
|
|
302
302
|
🚀 Setup for: /path/to/repo
|
|
303
303
|
✅ Created snapshot.config.json (preset: nextjs)
|
|
304
304
|
Added npm scripts: snapshot, snapshot:validate
|
|
305
|
-
Added devDependency: codebase-snapshot ^0.22.
|
|
305
|
+
Added devDependency: codebase-snapshot ^0.22.2
|
|
306
306
|
Added to .gitignore: /snapshot/, /snapshot.tmp/
|
|
307
307
|
⏳ Installing dependencies…
|
|
308
308
|
✅ Installed dependencies (npm install, 2.1s)
|
|
@@ -354,7 +354,7 @@ It also has three side effects on files you own, and it says so when it does the
|
|
|
354
354
|
```
|
|
355
355
|
✅ Created snapshot.config.json (preset: node-lib)
|
|
356
356
|
Added npm scripts: snapshot, snapshot:validate
|
|
357
|
-
Added devDependency: codebase-snapshot ^0.22.
|
|
357
|
+
Added devDependency: codebase-snapshot ^0.22.2
|
|
358
358
|
Added to .gitignore: /snapshot/, /snapshot.tmp/
|
|
359
359
|
```
|
|
360
360
|
|
|
@@ -381,8 +381,8 @@ returns to *"How should I set this up?"*. Answering **No** at the review steps b
|
|
|
381
381
|
abandoning the run — Ctrl+C is how you abandon.
|
|
382
382
|
|
|
383
383
|
Nothing else in the repository is touched: no `AGENTS.md`, no `.claude/`, no `.cursor/`. In a
|
|
384
|
-
repository with a `package.json` and no config, `git status` shows the config
|
|
385
|
-
|
|
384
|
+
repository with a `package.json` and no config, `git status` shows the config and the
|
|
385
|
+
`BRIEF.md` scaffold as the new files.
|
|
386
386
|
|
|
387
387
|
Interactive by default; with `--yes` it accepts every default and never prompts, which is
|
|
388
388
|
what agents and release checks should use.
|
|
@@ -504,8 +504,8 @@ agent](agent.md).
|
|
|
504
504
|
Ask the npm registry whether a newer release exists, and print the version it compared against:
|
|
505
505
|
|
|
506
506
|
```bash
|
|
507
|
-
npx codebase-snapshot@0.22.
|
|
508
|
-
npx codebase-snapshot@0.22.
|
|
507
|
+
npx codebase-snapshot@0.22.2 update # is this build current? print the answer
|
|
508
|
+
npx codebase-snapshot@0.22.2 update --format json
|
|
509
509
|
```
|
|
510
510
|
|
|
511
511
|
```text
|
|
@@ -655,7 +655,7 @@ for the two install flags, and the init-and-setup flags list both commands.
|
|
|
655
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. |
|
|
656
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`). |
|
|
657
657
|
| `--no-install` | flag | off | setup, generate `--autopilot` | Skip the dependency install. Anywhere else it is a usage error, because it would change nothing. |
|
|
658
|
-
| `--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. |
|
|
659
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`. |
|
|
660
660
|
| `--preset <name>` | name | detected | init, setup | Force a preset instead of detecting one. |
|
|
661
661
|
| `--include <globs>` | list | unset | init, setup | Allow-list recorded in the generated config. |
|
|
@@ -701,12 +701,12 @@ same run. With `--mode`, the remaining positionals are that command's arguments,
|
|
|
701
701
|
`--mode explain src/server.ts` and `--mode diff old-snapshot snapshot` work the same way the
|
|
702
702
|
positional form does.
|
|
703
703
|
|
|
704
|
-
It accepts the
|
|
704
|
+
It accepts the sixteen commands plus the `check` alias — the seventeen names the error lists — and it is
|
|
705
705
|
deliberately strict: asking for two different commands is an error rather than a silent winner.
|
|
706
706
|
|
|
707
707
|
```
|
|
708
708
|
❌ --mode validate contradicts the command "generate". Pass one or the other.
|
|
709
|
-
❌ 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.
|
|
710
710
|
```
|
|
711
711
|
|
|
712
712
|
`describe` does list `--mode` in its option table (`appliesTo` names every command that accepts it),
|
|
@@ -730,12 +730,13 @@ wrong and retrying it unchanged will fail the same way.
|
|
|
730
730
|
- **stdout** carries the payload. With `--format json` it is pure JSON, safe to pipe into
|
|
731
731
|
`jq` or `JSON.parse`.
|
|
732
732
|
- **stderr** carries progress, the human summary, warnings and errors.
|
|
733
|
-
- **In text mode the human result is on stderr, and stdout is empty** — for
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
`skill` without `--install`
|
|
738
|
-
|
|
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.
|
|
739
740
|
|
|
740
741
|
A failing invocation still writes one JSON document to stdout, so an agent never has to parse an
|
|
741
742
|
empty string:
|
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
|
|
41
|
-
into the page if the snapshot needs to outlive
|
|
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.22.
|
|
65
|
-
ExecStartPost=/usr/bin/npx -y codebase-snapshot@0.22.
|
|
70
|
+
ExecStart=/usr/bin/npx -y codebase-snapshot@0.22.2 generate --cwd /srv/app
|
|
71
|
+
ExecStartPost=/usr/bin/npx -y codebase-snapshot@0.22.2 validate --cwd /srv/app
|
|
66
72
|
```
|
|
67
73
|
|
|
68
74
|
```ini
|
package/docs/guard.md
CHANGED
|
@@ -1,13 +1,52 @@
|
|
|
1
1
|
# Change Guard
|
|
2
2
|
|
|
3
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
|
|
5
|
-
nothing at all.
|
|
4
|
+
not in the change set?** It returns untouched consumers, candidate tests, affected routes and
|
|
5
|
+
public symbols that no documentation file mentions — or nothing at all.
|
|
6
6
|
|
|
7
7
|
It is the in-loop companion to [impact](impact.md) and [brief](brief.md). Impact is a report you
|
|
8
8
|
ask for; Change Guard is a check that can run on every edit and stay silent until it has something
|
|
9
9
|
useful to say.
|
|
10
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.2 --version
|
|
48
|
+
~~~
|
|
49
|
+
|
|
11
50
|
## Run it
|
|
12
51
|
|
|
13
52
|
~~~bash
|
|
@@ -19,13 +58,19 @@ codebase-snapshot guard --diff origin/main --format json
|
|
|
19
58
|
With no options it checks the working tree against `HEAD`. The output is small on purpose:
|
|
20
59
|
|
|
21
60
|
~~~text
|
|
22
|
-
Change Guard:
|
|
61
|
+
Change Guard: 3 gap(s) in this change
|
|
23
62
|
consumer src/api.ts (1 hop, relative-import, via src/auth.ts)
|
|
24
63
|
test tests/auth.test.ts (test: src/auth.ts)
|
|
25
|
-
|
|
64
|
+
docs src/public-api.ts (newApi)
|
|
65
|
+
coverage: complete · confidence: file-import
|
|
26
66
|
~~~
|
|
27
67
|
|
|
28
|
-
|
|
68
|
+
Consumer, test and route gaps name a path outside the change; a file the change already touched
|
|
69
|
+
is never reported again. A documentation gap names the changed public file and the exported symbols
|
|
70
|
+
that no Markdown/reStructuredText/AsciiDoc file mentions. Docs are checked only when the repository
|
|
71
|
+
has a documentation surface, and only exported symbols of at least three characters are considered,
|
|
72
|
+
so the signal stays small. `confidence` is `symbol-pruned` only when a diff seeded symbol-level
|
|
73
|
+
matches; a hook payload or `--paths` run is file-level (`file-import`).
|
|
29
74
|
|
|
30
75
|
## Hook mode
|
|
31
76
|
|
|
@@ -45,6 +90,8 @@ there is nothing wrong is a guard users disable.
|
|
|
45
90
|
|
|
46
91
|
### Claude Code
|
|
47
92
|
|
|
93
|
+
The plugin install above already wires this hook. Use this block only for a manual setup.
|
|
94
|
+
|
|
48
95
|
~~~json
|
|
49
96
|
{
|
|
50
97
|
"hooks": {
|
|
@@ -54,7 +101,7 @@ there is nothing wrong is a guard users disable.
|
|
|
54
101
|
"hooks": [
|
|
55
102
|
{
|
|
56
103
|
"type": "command",
|
|
57
|
-
"command": "npx -y codebase-snapshot@0.22.
|
|
104
|
+
"command": "npx -y codebase-snapshot@0.22.2 guard --hook claude",
|
|
58
105
|
"timeout": 10
|
|
59
106
|
}
|
|
60
107
|
]
|
|
@@ -73,7 +120,7 @@ there is nothing wrong is a guard users disable.
|
|
|
73
120
|
"postToolUse": [
|
|
74
121
|
{
|
|
75
122
|
"type": "command",
|
|
76
|
-
"command": "npx -y codebase-snapshot@0.22.
|
|
123
|
+
"command": "npx -y codebase-snapshot@0.22.2 guard --hook copilot",
|
|
77
124
|
"timeoutSec": 10
|
|
78
125
|
}
|
|
79
126
|
]
|
|
@@ -92,7 +139,7 @@ there is nothing wrong is a guard users disable.
|
|
|
92
139
|
"hooks": [
|
|
93
140
|
{
|
|
94
141
|
"type": "command",
|
|
95
|
-
"command": "npx -y codebase-snapshot@0.22.
|
|
142
|
+
"command": "npx -y codebase-snapshot@0.22.2 guard --hook codex",
|
|
96
143
|
"timeout": 10
|
|
97
144
|
}
|
|
98
145
|
]
|
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
|
|
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.
|
|
@@ -130,8 +130,8 @@ repository it serves.
|
|
|
130
130
|
|
|
131
131
|
## Security boundary
|
|
132
132
|
|
|
133
|
-
- The server reads only the
|
|
134
|
-
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.
|
|
135
135
|
- Sensitive paths are never readable through snapshot_read, even when they exist on disk.
|
|
136
136
|
- A snapshot generated with --include-sensitive-files is refused by the MCP transport and by serve.
|
|
137
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.22.
|
|
13
|
+
npx -y codebase-snapshot@0.22.2 mcp
|
|
14
14
|
```
|
|
15
15
|
|
|
16
16
|
The server serves the directory it was started in. `--cwd <path>` points it elsewhere, and that
|
|
@@ -25,7 +25,7 @@ Claude Desktop and Cursor:
|
|
|
25
25
|
"mcpServers": {
|
|
26
26
|
"codebase-snapshot": {
|
|
27
27
|
"command": "npx",
|
|
28
|
-
"args": ["-y", "codebase-snapshot@0.22.
|
|
28
|
+
"args": ["-y", "codebase-snapshot@0.22.2", "mcp", "--cwd", "/absolute/path/to/repo"]
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
31
|
}
|
|
@@ -34,7 +34,7 @@ Claude Desktop and Cursor:
|
|
|
34
34
|
Claude Code registers the same thing from a shell:
|
|
35
35
|
|
|
36
36
|
```bash
|
|
37
|
-
claude mcp add codebase-snapshot -- npx -y codebase-snapshot@0.22.
|
|
37
|
+
claude mcp add codebase-snapshot -- npx -y codebase-snapshot@0.22.2 mcp --cwd /absolute/path/to/repo
|
|
38
38
|
```
|
|
39
39
|
|
|
40
40
|
On Windows, wrap the command as `cmd /c npx` with the same arguments — `npx` is a `.cmd` shim
|
|
@@ -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.22.
|
|
46
|
+
npx -y codebase-snapshot@0.22.2 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
|
|
@@ -124,7 +124,7 @@ reads the index, `medium` reads a few bounded bodies, `expensive` runs a compile
|
|
|
124
124
|
| Tool | Answers | Writes |
|
|
125
125
|
| :-- | :-- | :-- |
|
|
126
126
|
| `snapshot_impact` | What does this change reach? Symbol-pruned callers, routes, import cycles, candidate tests and optional snippets. Omitting `paths` and `base` compares the working tree with `HEAD`. | no |
|
|
127
|
-
| `snapshot_context` | The minimum redacted, line-numbered context for a question, files or
|
|
127
|
+
| `snapshot_context` | The minimum redacted, line-numbered context for a question, files, symbols or explicit ranges inside a hard token budget. Symbol targets use declaration spans; hidden instructions are removed; a context receipt carries chunk hashes and an optional signature. `planOnly` returns the reading plan. | no |
|
|
128
128
|
| `snapshot_locate` | Paths, symbols, routes, entrypoints or bounded redacted text. Symbol mode can add compiler-resolved references. | no |
|
|
129
129
|
| `snapshot_read` | A bounded, redacted line window of one file. Sensitive paths are never readable. | no |
|
|
130
130
|
| `snapshot_validate` | `status` (presence, counts, fingerprint), `drift` (freshness), or `audit` (secret and integrity checks). Only drift claims `current`. | no |
|
package/docs/security-review.md
CHANGED
|
@@ -48,8 +48,9 @@ untrusted input can arrive.
|
|
|
48
48
|
|
|
49
49
|
A `snapshot.config.ts` is code. The CLI runs it because the user invoked the repository's own
|
|
50
50
|
command; the **MCP server and the web page refuse it** and say so. A repository fetched with
|
|
51
|
-
`--remote` is treated
|
|
52
|
-
|
|
51
|
+
`--remote` is treated more strictly still: **none of its configuration is applied** — not JSON,
|
|
52
|
+
not JavaScript — because a fetched repository is not a trusted one. Only the clone and the
|
|
53
|
+
built-in defaults decide what that run scans.
|
|
53
54
|
|
|
54
55
|
### MCP over HTTP
|
|
55
56
|
|
|
@@ -132,6 +133,11 @@ addition was reviewed with the same question — what new input arrives, and wha
|
|
|
132
133
|
now fails the audit; before, both passed. This turns a tampered snapshot into a detected one.
|
|
133
134
|
- **`snapshot_context`** (0.15.5) reads only `parts/` through the same parser, so redaction and
|
|
134
135
|
exclusions apply exactly as they do to `snapshot_read`; it adds no file-system surface.
|
|
136
|
+
- **Hidden instructions and context receipts** (0.22.2): context/read/locate remove HTML comments
|
|
137
|
+
that read like AI instructions, zero-width characters and bidi controls before a body is
|
|
138
|
+
returned, and report the removals without echoing the payload. The receipt hashes the returned
|
|
139
|
+
chunks and the sanitized omission/security/trust metadata; signing uses the existing Ed25519 key
|
|
140
|
+
path and fails closed when `signReceipt` is requested without a key.
|
|
135
141
|
- **`--only`/`--ignore`** (0.14.6, tightened 0.21.0) never widen the MCP surface: the CLI may
|
|
136
142
|
replace its own config's allow-list, but an MCP request that tries to replace a declared
|
|
137
143
|
`include` allow-list is refused. `--ignore` only adds excludes. Sensitive files stay excluded.
|
package/docs/tools.md
CHANGED
|
@@ -39,9 +39,12 @@ walk.
|
|
|
39
39
|
|
|
40
40
|
**Cost:** medium · **Read-only:** yes
|
|
41
41
|
|
|
42
|
-
The minimum redacted, line-numbered context for a question, file list
|
|
43
|
-
token budget.
|
|
44
|
-
|
|
42
|
+
The minimum redacted, line-numbered context for a question, file list, symbol list or explicit
|
|
43
|
+
line ranges inside a hard token budget. An explicit symbol starts at its parsed declaration span;
|
|
44
|
+
a range is numbered from its real start line. `planOnly` returns the ranked reading plan without
|
|
45
|
+
bodies. Every requested file that does not fit is named in `omitted[]`. Hidden instructions and
|
|
46
|
+
invisible characters are removed, and the response carries a `receipt` with chunk hashes and a
|
|
47
|
+
canonical digest; `signReceipt` adds an Ed25519 signature when a signing key is configured.
|
|
45
48
|
|
|
46
49
|
```json
|
|
47
50
|
{
|
|
@@ -54,6 +57,18 @@ does not fit is named in `omitted[]`.
|
|
|
54
57
|
}
|
|
55
58
|
```
|
|
56
59
|
|
|
60
|
+
A precise request uses the same tool:
|
|
61
|
+
|
|
62
|
+
```json
|
|
63
|
+
{
|
|
64
|
+
"name": "snapshot_context",
|
|
65
|
+
"arguments": {
|
|
66
|
+
"ranges": [{ "path": "src/impact.ts", "startLine": 180, "endLine": 240 }],
|
|
67
|
+
"maxTokens": 4000
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
```
|
|
71
|
+
|
|
57
72
|
- **`snapshot_locate`**
|
|
58
73
|
|
|
59
74
|
**Cost:** cheap · **Read-only:** yes
|
package/docs/troubleshooting.md
CHANGED
|
@@ -42,7 +42,7 @@ problem, and for an option the command does not take it also names the commands
|
|
|
42
42
|
❌ --watch does not apply to `report` and was not applied. It is accepted by: `generate`.
|
|
43
43
|
❌ --cwd does not apply to `describe` and was not applied. It is accepted by: `generate`, `validate`, `report`, `impact`, `brief`, `explain`, `init`, `setup`, `skill`, `mcp`, `health`, `serve`.
|
|
44
44
|
❌ --max-part-bytes does not apply to `report` and was not applied. It is accepted by: `generate`, `validate`, `init`, `setup`.
|
|
45
|
-
❌ Unknown --mode "bogus". Expected one of: generate, validate, check, report, impact, brief, init, setup, explain, diff, describe, skill, mcp, health, update, serve.
|
|
45
|
+
❌ Unknown --mode "bogus". Expected one of: generate, validate, check, report, impact, guard, brief, init, setup, explain, diff, describe, skill, mcp, health, update, serve.
|
|
46
46
|
```
|
|
47
47
|
|
|
48
48
|
Nothing is silently ignored — that is the point of the message. The per-option `Applies to`
|
|
@@ -62,7 +62,7 @@ there, as are `--skeleton`, `--sarif` and `--max-part-tokens`. `--mode` names th
|
|
|
62
62
|
| `--no-install only applies to \`setup\`, or to \`generate --autopilot\`.` | The install only happens during a setup. Drop the flag, or add `--autopilot`. |
|
|
63
63
|
| `--preset does not apply to \`generate\` and was not applied. It is accepted by: \`init\`, \`setup\`. To scope a run, set include/excludePatterns/preset in snapshot.config.ts (or run \`codebase-snapshot init\` to generate one).` | `--preset`, `--include`, `--exclude`, `--yes` and `--force` configure `init` and `setup`, which write them into the config. Set them at generation time in `snapshot.config.ts` instead. |
|
|
64
64
|
| `--skip-artifacts does not apply to \`report\` and was not applied. It is accepted by: \`generate\`, \`validate\`, \`init\`, \`setup\`.` | `report` reads the manifest and prints it, so the generation settings are rejected there. Run `generate` with the artifact selection you want. |
|
|
65
|
-
| `Unknown --mode "bogus". Expected one of: generate, validate, check, report, impact, brief, init, setup, explain, diff, describe, skill, mcp, health, update, serve.` | `--mode` names the command the run uses; every command is an accepted name. Pass the command positionally unless a wrapper builds the argument list. |
|
|
65
|
+
| `Unknown --mode "bogus". Expected one of: generate, validate, check, report, impact, guard, brief, init, setup, explain, diff, describe, skill, mcp, health, update, serve.` | `--mode` names the command the run uses; every command is an accepted name. Pass the command positionally unless a wrapper builds the argument list. |
|
|
66
66
|
| `--install does not apply to \`generate\` and was not applied. It is accepted by: \`skill\`.` | `--install` and `--target` configure `skill` only. |
|
|
67
67
|
| `--cwd directory does not exist: …` / `--cwd is not a directory: …` | Point `--cwd` at an existing repository directory. |
|
|
68
68
|
| `--out-dir requires a value (received an empty string).` | An unset shell variable expanded to nothing. Quote it or drop the flag. Every string option rejects `""` rather than silently using the default. |
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "codebase-snapshot",
|
|
3
|
-
"version": "0.22.
|
|
3
|
+
"version": "0.22.2",
|
|
4
4
|
"mcpName": "io.github.ankurhalder/codebase-snapshot",
|
|
5
5
|
"description": "LLM codebase context you can verify: turn a repository into budgeted Markdown with a manifest of every included and skipped file, secret redaction, drift validation, and 7 MCP tools for Claude, ChatGPT, Cursor and CI.",
|
|
6
6
|
"keywords": [
|