codebase-snapshot 0.12.14 → 0.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/CHANGELOG.md +950 -3
  2. package/README.md +15 -3
  3. package/SECURITY.md +2 -2
  4. package/dist/bin.js +9848 -5460
  5. package/dist/{chunk-UQHIG2KN.js → chunk-BOJYZQFB.js} +7651 -747
  6. package/dist/chunk-NESEHOPU.js +266 -0
  7. package/dist/cli.cjs +9954 -5619
  8. package/dist/cli.d.cts +120 -2
  9. package/dist/cli.d.ts +120 -2
  10. package/dist/cli.js +422 -8
  11. package/dist/{generate-worker-BK4uJx7Z.d.cts → generate-worker-B79yGkQO.d.cts} +16 -0
  12. package/dist/{generate-worker-BK4uJx7Z.d.ts → generate-worker-B79yGkQO.d.ts} +16 -0
  13. package/dist/index.cjs +7389 -680
  14. package/dist/index.d.cts +145 -6
  15. package/dist/index.d.ts +145 -6
  16. package/dist/index.js +1 -1
  17. package/dist/mcp.cjs +3830 -1057
  18. package/dist/mcp.d.cts +86 -4
  19. package/dist/mcp.d.ts +86 -4
  20. package/dist/mcp.js +2 -2
  21. package/dist/{types-c0tLF2WC.d.cts → types-CbD8yQRZ.d.cts} +145 -1
  22. package/dist/{types-c0tLF2WC.d.ts → types-CbD8yQRZ.d.ts} +145 -1
  23. package/docs/agent.md +1 -1
  24. package/docs/benchmarks.md +80 -0
  25. package/docs/budget.md +59 -0
  26. package/docs/cli.md +56 -4
  27. package/docs/configuration.md +27 -0
  28. package/docs/delta.md +50 -0
  29. package/docs/deploy.md +75 -0
  30. package/docs/health.md +75 -0
  31. package/docs/mcp.md +112 -10
  32. package/docs/migration.md +68 -0
  33. package/docs/output.md +9 -3
  34. package/docs/remote.md +60 -0
  35. package/docs/security-review.md +117 -0
  36. package/docs/serve.md +66 -0
  37. package/docs/signing.md +61 -0
  38. package/docs/slice.md +57 -0
  39. package/docs/tools.md +161 -0
  40. package/docs/troubleshooting.md +63 -0
  41. package/docs/vs-repomix.md +1 -1
  42. package/docs/workspace.md +93 -0
  43. package/package.json +1 -1
  44. package/dist/chunk-6EGIFYWK.js +0 -3248
package/docs/health.md ADDED
@@ -0,0 +1,75 @@
1
+ # Health: an audit of the snapshot itself
2
+
3
+ `validate` answers one question: has the code moved since this snapshot was generated? That is
4
+ necessary and not sufficient. Before a snapshot is pasted into a model you want to know four more
5
+ things, and `snapshot health` answers them:
6
+
7
+ ```bash
8
+ npx codebase-snapshot health # the snapshot in ./snapshot
9
+ npx codebase-snapshot health --strict # exit 2 when a critical check fails
10
+ npx codebase-snapshot health --format json # the report, for a dashboard
11
+ ```
12
+
13
+ ## What it checks
14
+
15
+ | Check | Severity | What it proves |
16
+ | :--- | :--- | :--- |
17
+ | Manifest present and well-formed | critical | The file parses and has the snapshot shape. |
18
+ | Every part on disk | critical | Every part the manifest names exists. |
19
+ | Every part matches its size and hash | critical | The bytes on disk are the bytes recorded. |
20
+ | Every file in exactly one part | critical | No file was silently dropped from the layout. |
21
+ | Every recorded artifact present and unchanged | critical | `README.md`, `PROMPT.md`, reports and monolith still match their digests. |
22
+ | Nothing unexpected in the directory | warning | No stale file from an earlier run is sitting in the payload. |
23
+ | No unmasked secret in any artifact | critical | Every written text file is re-scanned with the secret rules. |
24
+ | No value from an excluded sensitive file appears | critical | Values from `.env`, keys and similar files are compared byte-for-byte against the artifacts. |
25
+ | No host path or machine identity | warning | `/home/…`, `/Users/…`, `C:\Users\…` and the repository's absolute path are searched for. |
26
+ | Token estimate is plausible | warning | The recorded estimate is compared with one recomputed from the parts. |
27
+ | Every part honours the published budget | warning | A part larger than the ceiling the manifest advertises is reported. |
28
+ | Every excluded path has a reason | critical | `skipped[]` is complete and the totals agree. |
29
+ | The snapshot still describes the repository | warning | HEAD is compared with the recorded commit. |
30
+ | The manifest signature verifies | critical | When `signature.json` exists: the manifest bytes match `manifestSha256` and the Ed25519 signature checks out. Absent signature is a skip, not a failure. |
31
+
32
+ ## Reading the result
33
+
34
+ ```text
35
+ 🩺 Snapshot health: 100/100
36
+ 13 passed, 0 warning(s), 0 failed, 0 skipped
37
+ ```
38
+
39
+ A **failed** check (critical) means the snapshot is not safe to hand to a model as it stands; the
40
+ command exits 1, or 2 with `--strict`. A **warning** is a judgement call: a host path is not a
41
+ secret, but you may not want it in the payload either.
42
+
43
+ The score starts at 100; each failure costs 25 and each warning 5, with a floor of zero. It is a
44
+ summary, not a substitute for the checks — the report always lists every one.
45
+
46
+ ## A workspace, all at once
47
+
48
+ `health --all-members` reads `WORKSPACE.json` and audits every snapshot a `--workspace` run wrote,
49
+ printing one row per member. The combined score is the **weakest member**, because a workspace is
50
+ only as trustworthy as its worst part; a missing member snapshot is an error row, not a skip.
51
+
52
+ ```bash
53
+ codebase-snapshot health --all-members --cwd /repo
54
+ ```
55
+
56
+ `--format json` returns the members with their counts and failed check ids.
57
+
58
+ ## What it never does
59
+
60
+ - It does not regenerate, repair or delete anything. The report is evidence; evidence that mutates
61
+ is not evidence.
62
+ - It never prints a secret it found. Findings name the artifact and the line count, never the value.
63
+ - It does not need the network. Everything it compares is on disk.
64
+
65
+ ## In the MCP server
66
+
67
+ `snapshot_health` returns the same report as structured output, so an agent can call it before
68
+ trusting a snapshot it was handed:
69
+
70
+ ```json
71
+ { "score": 95, "counts": { "pass": 12, "warn": 1, "fail": 0, "skip": 0 }, "checks": [ … ] }
72
+ ```
73
+
74
+ The cheap subset — manifest, parts, artifacts, skips — also runs inside `validate`, so a normal
75
+ drift check catches structural dishonesty without paying for the leak scan on every CI 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.12.14 mcp
13
+ npx -y codebase-snapshot@0.13.0 mcp
14
14
  ```
15
15
 
16
16
  The server serves the directory it was started in. `--cwd <path>` points it elsewhere, and that
@@ -25,7 +25,7 @@ Claude Desktop and Cursor:
25
25
  "mcpServers": {
26
26
  "codebase-snapshot": {
27
27
  "command": "npx",
28
- "args": ["-y", "codebase-snapshot@0.12.14", "mcp", "--cwd", "/absolute/path/to/repo"]
28
+ "args": ["-y", "codebase-snapshot@0.13.0", "mcp", "--cwd", "/absolute/path/to/repo"]
29
29
  }
30
30
  }
31
31
  }
@@ -34,19 +34,91 @@ Claude Desktop and Cursor:
34
34
  Claude Code registers the same thing from a shell:
35
35
 
36
36
  ```bash
37
- claude mcp add codebase-snapshot -- npx -y codebase-snapshot@0.12.14 mcp --cwd /absolute/path/to/repo
37
+ claude mcp add codebase-snapshot -- npx -y codebase-snapshot@0.13.0 mcp --cwd /absolute/path/to/repo
38
38
  ```
39
39
 
40
40
  On Windows, wrap the command as `cmd /c npx` with the same arguments — `npx` is a `.cmd` shim
41
41
  there, and clients that spawn without a shell cannot execute it directly.
42
42
 
43
- ## The eight tools
43
+ ## Over HTTP, for clients that cannot spawn a process
44
+
45
+ ```bash
46
+ npx -y codebase-snapshot@0.13.0 mcp --http --port 4789
47
+ ```
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 `{ ok, name, version, tools, uptimeSeconds }`, without a token.
51
+
52
+ The first run prints the URL and a generated bearer token:
53
+
54
+ ```text
55
+ MCP over HTTP: http://127.0.0.1:4789/mcp
56
+ Authorization: Bearer <generated>
57
+ ```
58
+
59
+ Send `Authorization: Bearer <token>` with every request. `--token` picks your own; `--no-auth`
60
+ turns the requirement off and is **refused** on a non-loopback bind, because a repository
61
+ reachable from the network must not be readable by any page that guesses the port.
62
+
63
+ | Flag | Default | What it does |
64
+ | :--- | :--- | :--- |
65
+ | `--http` | off | HTTP instead of stdio |
66
+ | `--port <n>` | `4789` | Port; `0` picks a free one and prints it |
67
+ | `--host <addr>` | `127.0.0.1` | Bind address |
68
+ | `--token <value>` | generated | Bearer token |
69
+ | `--no-auth` | off | Unauthenticated; loopback only |
70
+ | `--allow-origin <list>` | unset | Extra CORS origins, comma separated |
71
+
72
+ CORS is granted to loopback origins (`localhost`, `127.0.0.1`, `[::1]`, any port) and to the
73
+ origins you list. Any other `Origin` gets `403`.
74
+
75
+ ### Legacy SSE, for clients that cannot send a header
76
+
77
+ `GET /sse` opens an event stream and announces its message endpoint:
78
+
79
+ ```text
80
+ event: endpoint
81
+ data: /messages?sessionId=<id>
82
+ ```
83
+
84
+ The client POSTs JSON-RPC to that path, receives `202`, and reads the answer as a `message`
85
+ event on the open stream. This exists for browsers and older clients where `EventSource` cannot
86
+ set `Authorization`; the token may travel as `?token=` **on this path only**, which is a leak
87
+ into logs and is documented as such. A heartbeat every 15 s keeps the connection alive, and
88
+ shutdown ends the streams rather than waiting on them. Request bodies are capped at 2 MB, the rate is
89
+ capped at 60 requests per 10 seconds per address, and every response is one bounded JSON document.
90
+
91
+ ## The 24 tools
92
+
93
+ Each tool has an entry with a ready-to-send call in the [tool reference](tools.md).
94
+
95
+
96
+ Every tool states its cost class in `tools/list` as `_meta["codebase-snapshot/cost"]`: `cheap`
97
+ reads the manifest, `medium` reads one or a few parts, `expensive` reads the repository or writes.
98
+ Two tools that answer the same question can differ by an order of magnitude, and a client choosing
99
+ between them should not have to guess.
44
100
 
45
101
  | Tool | Answers | Writes |
46
102
  | :-- | :-- | :-- |
47
103
  | `snapshot_status` | Is there a snapshot, when was it built, what does it cover? | no |
104
+ | `snapshot_health` | Does the written snapshot match its manifest, carry any secret or host path, and cost what it claims? `maxScanBytes` bounds the text scan. | no |
105
+ | `snapshot_query` | Filter the index by layer, kind, path pattern or symbol | no |
106
+ | `snapshot_history` | The commits the snapshot was built from (reads `reports/log.md`) | no |
107
+ | `snapshot_tests` | The tests that import a file (or every test and what it covers) | no |
108
+ | `snapshot_workspace` | The members of a multi-repository workspace and the imports that cross between them | no |
109
+ | `snapshot_entrypoints` | The files a reader should start from, manifests first | no |
110
+ | `snapshot_neighbors` | Both import directions for one path | no |
111
+ | `snapshot_routes` | Route handlers recorded by the summaries, with their files | no |
112
+ | `snapshot_cycles` | Strongly connected components in the import graph | no |
113
+ | `snapshot_stats` | Files by layer and kind, part sizes, token estimate, heaviest files | no |
114
+ | `snapshot_search` | Case-insensitive text search across the emitted parts, bounded and redaction-safe | no |
115
+ | `snapshot_review` | Currency, health and bounded bodies in one call, so a review can start | no |
116
+ | `snapshot_symbol` | Where a function, class or constant is defined, with a window and a line number | no |
117
+ | `snapshot_diff_context` | Bodies of the changed files plus the files that import them | no |
118
+ | `snapshot_context` | One bounded context block from named files or symbols, read from the snapshot | no |
119
+ | `snapshot_plan_for` | Given a question and a token budget, the smallest set of files that answer it, in reading order | no |
48
120
  | `snapshot_plan` | What would a generate at this budget include, and what would it leave out? | no |
49
- | `snapshot_generate` | Build it. | yes |
121
+ | `snapshot_generate` | Build it. Accepts `includeDiffs`, `includeLogs`, `tokenTree` and `stripComments`, so a client can ask for the opt-in reports the CLI has. | yes |
50
122
  | `snapshot_validate` | Is the context the agent was given still current? | no |
51
123
  | `snapshot_locate` | Which part holds this symbol, route or file? | no |
52
124
  | `snapshot_dependents` | What does this file import, and what imports it? | no |
@@ -99,6 +171,10 @@ stays responsive.
99
171
 
100
172
  Resources are the browse surface; tools are the act surface.
101
173
 
174
+ The first four rows are always listed. The report resources are listed only when the run wrote
175
+ the file — a resource in `resources/list` has to be readable — and `describe --format json`
176
+ publishes them separately as `reportResources`.
177
+
102
178
  | URI | Contents |
103
179
  | :-- | :-- |
104
180
  | `snapshot://manifest` | Every included file with layer, kind, part and hash, every skip reason, and `incomplete[]` — the files whose body is not the whole file, with their missing line ranges |
@@ -106,6 +182,9 @@ Resources are the browse surface; tools are the act surface.
106
182
  | `snapshot://reports/audit` | Secret findings, large files, parse diagnostics |
107
183
  | `snapshot://reports/tree` | The directory tree of included files |
108
184
  | `snapshot://reports/navigation` | File-to-part lookup |
185
+ | `snapshot://reports/diff` | `reports/diff.md`, when the snapshot was generated with `--include-diffs` |
186
+ | `snapshot://reports/log` | `reports/log.md`, when generated with `--include-logs` |
187
+ | `snapshot://reports/tokens` | `reports/tokens.md`, when generated with `--token-tree` |
109
188
  | `snapshot://prompt` | `PROMPT.md` — the brief: the job, what the snapshot contains and omits, the history it was built from, and the owner half when a `brief` is configured |
110
189
  | `snapshot://contract` | The machine-readable CLI contract |
111
190
  | `snapshot://skill` | The agent skill, as one read |
@@ -130,9 +209,32 @@ refused rather than truncated.
130
209
 
131
210
  ## Prompts
132
211
 
133
- Two, both about order of operations rather than features: `orient` maps the repository before
134
- anything is read, and `keep-current` validates before trusting earlier context and again after
135
- making changes.
212
+ Seven. Two are about order of operations, five are a job:
213
+
214
+ | Prompt | What it does |
215
+ | :--- | :--- |
216
+ | `orient` | Map the repository before anything is read. |
217
+ | `keep-current` | Validate before trusting earlier context, and again after changes. |
218
+ | `audit` | Health, drift, exclusions, and the findings that matter — evidence, not impressions. |
219
+ | `review` | Plan the reading for a change, read it, name the dependents and risks. |
220
+ | `explain` | Why a path is in the snapshot, what it does, who depends on it. |
221
+ | `onboard` | A guided tour with a reading order for someone who has never seen the repository. |
222
+ | `security-review` | Authentication, authorization, secrets and injection, plus what the snapshot cannot see. |
223
+
224
+ Every tool a prompt names is a tool the server serves; a test holds the two lists together.
225
+
226
+ ## Progress, and what cancellation does not do
227
+
228
+ A client that sends `progressToken` in `tools/call` `_meta` receives `notifications/progress` while
229
+ a long call runs — `snapshot_generate` reports "generating" and "writing the snapshot" with a
230
+ 2-step total. The notifications are coarse by design: the worker that does the generation posts a
231
+ summary, not a stream of phases, and inventing finer numbers would be a progress bar that lies.
232
+
233
+ `notifications/cancelled` now stops the work that can be stopped. `snapshot_generate` terminates
234
+ its worker and answers with "The generation was cancelled."; the partially written directory is
235
+ removed by the generator's own staging rules, so a cancelled run leaves no snapshot claiming to be
236
+ complete. Other tools finish before they can notice — they are bounded and fast — and the response
237
+ says what happened rather than pretending the call never ran.
136
238
 
137
239
  ## What it will not do
138
240
 
@@ -146,8 +248,8 @@ making changes.
146
248
  redaction applies to everything the client sees.
147
249
  - **Install or configure.** `snapshot_generate` writes the snapshot directory and nothing else. It
148
250
  never runs a package manager and never writes a config file.
149
- - **Touch the network.** The server itself makes no outbound connection, and there is no HTTP
150
- transport. Module configs (`.mjs`, `.cjs`, `.ts`) are refused: importing one would run repository
251
+ - **Touch the network.** The stdio server makes no outbound connection. `--http` binds a loopback
252
+ port and answers requests; it still contacts nothing. Module configs (`.mjs`, `.cjs`, `.ts`) are refused: importing one would run repository
151
253
  code with the user's privileges, so the server accepts only JSON configuration. The CLI still
152
254
  loads a module config, because there the user invoked the repository's own command.
153
255
 
@@ -0,0 +1,68 @@
1
+ # Migrating from 0.12.14 to 0.17.0
2
+
3
+ Nothing was removed. Every command, flag, config key and MCP tool that existed in 0.12.14 still
4
+ works, with two deliberate behaviour changes listed at the bottom. This page is the map of what was
5
+ added, so a reader can find the feature they need without reading a hundred changelog entries.
6
+
7
+ ## New commands
8
+
9
+ | Command | Since | What it does |
10
+ | :--- | :--- | :--- |
11
+ | `snapshot health` | 0.12.15 | Audits the written snapshot: hashes, artifacts, secrets, host paths, tokens, freshness, signature. `--strict`, `--format json`. |
12
+ | `snapshot serve` | 0.12.19 | A browser page to generate, preview and download a snapshot; MCP on the same port. |
13
+ | `snapshot mcp --http` | 0.12.18 | MCP over Streamable HTTP instead of stdio; `GET /sse` for legacy clients since 0.12.29. |
14
+
15
+ ## New `generate` flags
16
+
17
+ | Flag | Since | What it does |
18
+ | :--- | :--- | :--- |
19
+ | `--remote <url>` | 0.12.20 | Shallow, SSRF-safe clone of a public repository; provenance in the manifest. |
20
+ | `--ref <branch>` | 0.12.20 | Branch or tag for `--remote`. |
21
+ | `--allow-private` | 0.12.20 | The explicit override for private addresses and `file:` URLs. |
22
+ | `--keep-clone` | 0.12.20 | Keep the temporary clone. |
23
+ | `--include-diffs` | 0.12.24 | `reports/diff.md` from the uncommitted diff. |
24
+ | `--include-logs <n>` | 0.12.24 | `reports/log.md` with the last n commits. |
25
+ | `--token-tree` | 0.12.24 | `reports/tokens.md` with per-file estimates. |
26
+ | `--delta <path>` | 0.12.25 | Only what changed since a base snapshot, plus its importers. |
27
+ | `--slice "<question>"` | 0.12.26 | Only what the retrieval planner picks for a question. |
28
+ | `--slice-tokens <n>` | 0.12.26 | The slice budget (default 30000). |
29
+ | `--pack single\|xml\|json` | 0.12.31 | One full-repository file in the chosen shape. |
30
+ | `--sign` | 0.12.32 | Ed25519 signature over the manifest. |
31
+ | `--budget-tokens <n>` | 0.12.33 | Fit the repository into a token budget by selecting whole files. |
32
+
33
+ ## New config keys
34
+
35
+ | Key | Since | Notes |
36
+ | :--- | :--- | :--- |
37
+ | `artifacts.diff`, `artifacts.log`, `artifacts.tokenTree` | 0.12.24 | Default `false`. `--skip-artifacts` still wins. |
38
+ | `logCount` | 0.12.24 | 1–500, default 20. |
39
+ | `pack` | 0.12.31 | `single`, `xml` or `json`; unset keeps the monolith pair. |
40
+
41
+ ## MCP
42
+
43
+ Tools went from eight to fifteen: `snapshot_health`, `snapshot_plan_for`, `snapshot_query`,
44
+ `snapshot_context`, `snapshot_symbol`, `snapshot_diff_context`, `snapshot_review` joined the original
45
+ eight. Prompts went from two (`orient`, `keep-current`) to seven (`audit`, `review`, `explain`,
46
+ `onboard`, `security-review` were added). Resources gained `snapshot://prompt` and the three opt-in
47
+ reports.
48
+
49
+ Transports: stdio is still the default. `--http` adds Streamable HTTP with a bearer token and a
50
+ loopback bind; `--no-auth` is refused on a non-loopback bind. The page and the MCP endpoint can share
51
+ one port with `serve`.
52
+
53
+ ## Two behaviour changes
54
+
55
+ 1. **`validate` accepts `--include-diffs`, `--include-logs` and `--token-tree`** (0.12.28). Those
56
+ flags change the artifact selection the manifest records, so passing them is required to compare
57
+ like with like. Before, a snapshot generated with one of them reported a selection mismatch.
58
+ 2. **npm publishes only at `x.y.0`** (0.12.16 onward). Every patch is committed, tagged and pushed;
59
+ the registry carries `0.13.0`, `0.14.0`, … so `latest` stays a milestone rather than a patch. If
60
+ you pin an exact patch version, install from the git tag or build from source until the next
61
+ minor.
62
+
63
+ ## If you are on an older 0.12.x
64
+
65
+ Upgrade to the latest 0.12.x first; every change since 0.12.14 is a patch on the same line, and the
66
+ configuration file format has not changed. Run `snapshot health` after the first generate on the new
67
+ version — it is the fastest way to see whether an old snapshot carries anything the newer checks
68
+ would refuse.
package/docs/output.md CHANGED
@@ -19,11 +19,15 @@ snapshot/
19
19
  └── reports/
20
20
  ├── project-tree.md directory tree of included files
21
21
  ├── navigation.md links between layers, kinds and parts
22
- └── audit.md secrets, large files, parse diagnostics, git state
22
+ ├── audit.md secrets, large files, parse diagnostics, git state
23
+ ├── diff.md uncommitted changes (--include-diffs)
24
+ ├── log.md recent commits (--include-logs <n>)
25
+ └── tokens.md per-file token estimates (--token-tree)
23
26
  ```
24
27
 
25
28
  With `--include-monolith` you also get `full-codebase.json` and `full-codebase.md` — the
26
- whole repository in one file. They are off by default because they grow without bound;
29
+ whole repository in one file. `--pack xml` writes `full-codebase.xml` instead, one `<file>` element
30
+ per source with the body in CDATA; `--pack single` and `--pack json` write just the other one. They are off by default because they grow without bound;
27
31
  `--max-monolith-bytes` skips them when they would exceed a size you set.
28
32
 
29
33
  `full-codebase.json` embeds its own `files[]` array, and its `includedBytes` / `includedLines`
@@ -257,7 +261,9 @@ has several at once, and "within budget" cannot be answered without knowing whic
257
261
  line — the block as written. It is not a count of surviving source content, which is why
258
262
  `includedLines + omittedLines` is one more than `lines` for a preview and never a sum a reader
259
263
  should reconcile.
260
- - `inclusionMode` is `preview` exactly when `isPreviewTruncated` is `true`. There used to be two
264
+ - `inclusionMode` is `preview` exactly when `isPreviewTruncated` is `true`. It is
265
+ `comments-stripped` when `--strip-comments` removed comment text from a JavaScript/TypeScript
266
+ body: the body is not the file verbatim, and the manifest says so instead of reporting `full`. There used to be two
261
267
  routes to it, and the second — a file *under* `largeFileBytes` but too big for its part, cut
262
268
  by the partitioner with `isLarge: false` — is what made the manifest unreadable: it looked
263
269
  like a preview chosen by policy while 57 % of the file was gone. That configuration is now a
package/docs/remote.md ADDED
@@ -0,0 +1,60 @@
1
+ # Remote repositories
2
+
3
+ ```bash
4
+ npx -y codebase-snapshot generate --remote https://github.com/owner/repo
5
+ npx -y codebase-snapshot generate --remote https://github.com/owner/repo --ref v2.1.0
6
+ GITHUB_TOKEN=... npx -y codebase-snapshot generate --remote https://github.com/owner/private
7
+ ```
8
+
9
+ The snapshot is written where you ran the command, not inside the clone. The manifest records where
10
+ the tree came from:
11
+
12
+ ```json
13
+ "source": {
14
+ "url": "https://github.com/owner/repo",
15
+ "host": "github.com",
16
+ "owner": "owner",
17
+ "repo": "repo",
18
+ "ref": "main",
19
+ "commit": "9f2c…",
20
+ "fetchedAt": "2026-11-18T04:12:09.144Z"
21
+ }
22
+ ```
23
+
24
+ The **commit** is the one that was cloned, not the one the URL points at today. A snapshot that names
25
+ a moving branch and no commit describes a tree nobody can fetch again; this one can be traced back.
26
+
27
+ ## What it fetches
28
+
29
+ A shallow clone: `--depth 1`, one branch, no tags, no submodules, no Git LFS. A snapshot needs the
30
+ tree a reader would see, not the history. The clone lives in a temporary directory that is removed
31
+ when the command exits; `--keep-clone` keeps it and prints the path.
32
+
33
+ ## What it refuses
34
+
35
+ | Refused | Why |
36
+ | :--- | :--- |
37
+ | `http://` and other schemes | The URL decides which machine this process talks to. |
38
+ | URLs with a username or password | Credentials in a URL end up in argv, shell history and logs. Use `GITHUB_TOKEN`. |
39
+ | Loopback, `10/8`, `172.16/12`, `192.168/16`, `169.254/16` (cloud metadata), CGNAT, `fe80::/10`, `fc00::/7` | A repository URL must not become a way to read the local network. |
40
+ | A host that resolves to any private address | DNS is checked after the literal check, because `repo.example.com` can point at 127.0.0.1. |
41
+ | A clone larger than 1 GB | The scan is text; a checkout that large is not a snapshot anyone reads. |
42
+ | `file:` URLs | A local directory is not a remote. `--allow-private` is the explicit override, for air-gapped mirrors and tests. |
43
+
44
+ `--allow-private` exists because "I know what I am doing" is a real answer. It is not a default.
45
+
46
+ The same path backs the **browser page**: paste a URL into `serve` and it clones with these rules,
47
+ generates into a temporary snapshot, and shows it. The clone is removed when the server exits.
48
+
49
+ ## Private repositories
50
+
51
+ Set `GITHUB_TOKEN` (or `GH_TOKEN`). The token is passed to git through the environment as an HTTP
52
+ header, never on the command line, and it never appears in the manifest, the reports or the brief.
53
+ The clone is shallow, so a token with `contents: read` is enough.
54
+
55
+ ## The configuration of a fetched repository is not loaded
56
+
57
+ A clone may contain `snapshot.config.ts`, and a config can run code. A repository you just fetched
58
+ is not a repository you trust, so `--remote` always runs on the defaults — the same rule the MCP
59
+ server and the web UI follow. If you want the fetched project's config applied, clone it yourself,
60
+ read the config, and run the CLI there.
@@ -0,0 +1,117 @@
1
+ # Security review
2
+
3
+ Written for this release, about this release. It states the threat model, the controls, what is
4
+ tested, and the residual risks — including the ones that are deliberately not solved.
5
+
6
+ ## What the tool is
7
+
8
+ A local process that reads a repository and writes a directory of text. Since 0.12.15 it also runs an
9
+ HTTP server, fetches repositories from URLs, and signs manifests. Each of those is a new place where
10
+ untrusted input can arrive.
11
+
12
+ ## Threat model
13
+
14
+ | Adversary | Can reach | Cannot reach |
15
+ | :--- | :--- | :--- |
16
+ | **A malicious repository** (its files, config, filenames) | The snapshot's text, the brief, the audit report, the planner's ranking | The filesystem outside the repository, the network, the process environment |
17
+ | **A malicious URL** given to `--remote` or the browser page | The clone path and the SSRF guard | Any private address, any credential, any local file |
18
+ | **A malicious web page** in the same browser | `GET /` on `serve` (HTML only), CORS preflights | Anything behind the bearer token, any API response |
19
+ | **A malicious MCP client** | The tool list and the snapshot's contents | The working tree outside the snapshot, sensitive files, the network |
20
+ | **A shoulder-surfer / log reader** | Nothing new | Secrets (masked), paths (masked), tokens (never logged) |
21
+
22
+ ## Controls
23
+
24
+ ### Content leaving the repository
25
+
26
+ - **Sensitive files stay out.** `.env`, keys, `.npmrc` and the rest are skipped unless
27
+ `includeSensitiveFiles` is explicitly set, and every skip is recorded with its reason.
28
+ - **Redaction masks the span, not the line.** A matched credential becomes `[REDACTED:rule]`; no
29
+ excerpt of the matched line reaches an artifact, the audit report or the SARIF file.
30
+ - **Paths are masked too.** A path that itself matches a secret rule is recorded masked.
31
+ - **The health audit re-scans every written text file** for unmasked secrets and compares values
32
+ from excluded sensitive files byte for byte against the artifacts (`snapshot health`).
33
+
34
+ ### Executable configuration
35
+
36
+ A `snapshot.config.ts` is code. The CLI runs it because the user invoked the repository's own
37
+ command; the **MCP server and the web page refuse it** and say so. A repository fetched with
38
+ `--remote` is generated on the defaults for the same reason: a fetched repository is not a trusted
39
+ one.
40
+
41
+ ### MCP over HTTP
42
+
43
+ - **Loopback by default**, and a bearer token **always** unless `--no-auth` is passed explicitly.
44
+ `--no-auth` is refused on a non-loopback bind.
45
+ - **Constant-time** token comparison; the token is generated with `crypto.randomBytes`.
46
+ - **CORS only for loopback origins** and explicit `--allow-origin` values; everything else is 403.
47
+ - **Bounded work**: 2 MiB bodies, 60 requests per 10 s per address, one JSON document per response.
48
+ - **Errors are JSON-RPC error objects**, never stack traces.
49
+
50
+ ### The browser page
51
+
52
+ - The page is HTML and is served without a token; **every API call requires one**. The token is not
53
+ baked into the HTML, so serving `/` cannot leak it.
54
+ - A request with a cross-origin `Origin` is refused before any auth check.
55
+ - `api/snapshot.zip` only zips a directory that contains a manifest or an ownership marker.
56
+
57
+ ### Remote ingestion
58
+
59
+ - **https only**, no credentials in the URL, and the host must resolve to public addresses. Loopback,
60
+ RFC1918, link-local (including `169.254.169.254`), CGNAT and their v6 equivalents are refused
61
+ unless `--allow-private` is given.
62
+ - **Checked twice**: the literal host before DNS, and every resolved address after.
63
+ - **Shallow clone** into a temp directory removed on exit; `GITHUB_TOKEN` reaches git through the
64
+ environment (`http.extraheader` via `GIT_CONFIG_*`), never argv, and never enters the manifest.
65
+ - A clone larger than 1 GB is refused before scanning.
66
+
67
+ ### Signing
68
+
69
+ - Ed25519 over the exact manifest bytes; the record carries the public key and the manifest sha256.
70
+ - `health` fails when the manifest changed after signing; an unsigned snapshot is a skip, because
71
+ absence is not tampering.
72
+ - The private key never reaches an artifact. `SNAPSHOT_SIGNING_KEY` is read from the environment.
73
+
74
+ ### Prompt injection
75
+
76
+ A repository can contain text that tells a model to ignore its instructions. The snapshot preserves
77
+ file content faithfully, and **this tool cannot sanitise prose without changing the code it exists to
78
+ carry**. The brief says what the snapshot is and what it omits, and the security prompt tells an agent
79
+ to treat file content as data. This is a real, documented limitation, not a solved problem.
80
+
81
+ ## What the test suite pins
82
+
83
+ | Property | Test |
84
+ | :--- | :--- |
85
+ | Sensitive files stay out; skips are recorded | `tests/security-*.test.js`, hygiene suites |
86
+ | Redaction masks the span only | redaction suite (hundreds of cases) |
87
+ | Health catches a leaked secret and never echoes it | `tests/health.test.js` |
88
+ | HTTP: 401 without token, 403 cross-origin, 413 oversize, 400 bad JSON | `tests/mcp-http.test.js` |
89
+ | SSE: token required, unknown session 404, shutdown does not hang | `tests/mcp-http.test.js` |
90
+ | Remote: private addresses refused, credentials in URL refused, `file:` gated | `tests/remote-source.test.js` |
91
+ | Serve: page without token, API with token, zip restricted | `tests/web-serve.test.js` |
92
+ | Signature: tamper detected | `tests/signing.test.js` |
93
+
94
+ ## Residual risks, stated
95
+
96
+ 1. **`?token=` on the legacy SSE paths.** `EventSource` cannot set headers, so the token may travel
97
+ in the URL on `/sse` and `/messages` only. URLs reach proxy logs and shell history. Use the
98
+ Streamable HTTP endpoint with a header where the client supports it.
99
+ 2. **`--no-auth` on loopback.** Any local process (or a browser page that guesses the port, though
100
+ CORS and the token requirement normally stop it) can then read the repository. It is a deliberate
101
+ opt-out, printed as a warning.
102
+ 3. **DNS rebinding.** The private-address check resolves once before the clone; a hostile DNS server
103
+ could change the answer between the check and git's own resolution. Mitigating it fully requires
104
+ pinning the resolved IP for the connection, which git does not expose. The window is small, the
105
+ target must be public at check time, and `--allow-private` is the only way to reach a private
106
+ address deliberately.
107
+ 4. **Prompt injection in repository content**, as above.
108
+ 5. **A signing key in the environment** is visible to the process's own children and to anyone who
109
+ can read `/proc`. Use a key file with restrictive permissions if that matters.
110
+ 6. **No sandbox.** The tool reads what the user can read and writes where the user says. It does not
111
+ drop privileges, and it is not designed to run against hostile filesystems.
112
+
113
+ ## Reporting a vulnerability
114
+
115
+ Open a private security advisory on the repository, or email the address in `package.json`. Please
116
+ include the version, a reproduction, and whether secret material was exposed. Fixes ship as patches
117
+ on the current line; there is no long-term support branch yet.
package/docs/serve.md ADDED
@@ -0,0 +1,66 @@
1
+ # In the browser: `serve`
2
+
3
+ ```bash
4
+ npx -y codebase-snapshot serve
5
+ ```
6
+
7
+ Open the printed URL. The page has one job: take a repository, show you the snapshot it produced,
8
+ and hand you the zip.
9
+
10
+ ```text
11
+ Serving http://127.0.0.1:4788/
12
+ MCP endpoint: http://127.0.0.1:4788/mcp
13
+ Token: <generated>
14
+ Open the page and paste the token once; it is kept in this browser only.
15
+ ```
16
+
17
+ ## What it does
18
+
19
+ 1. **Choose a mode.** *Whole repository* is the default. *A slice for a question* runs the
20
+ retrieval planner at generate time and asks for the question. *Fit a token budget* selects whole
21
+ files to fit the number you give. The result line reports how many paths were not selected.
22
+ 2. **Generate.** Paste an absolute path or a public repository URL and press Generate. A URL is
23
+ cloned shallowly into a temporary directory (removed when the server exits) with the same
24
+ provenance record the CLI writes. The page calls the same
25
+ `generateSnapshot` the CLI calls, with the default settings — the defaults are what a browser
26
+ session can honestly promise, because a config file can run code and this process will not run
27
+ repository code on a page's request. For a project config, use the CLI.
28
+ 3. **Preview.** The brief (`PROMPT.md`) and the file list come back from the written snapshot, not
29
+ from the working tree. If the snapshot is wrong, the page shows the wrongness.
30
+ 4. **See the health score.** The page audits what it just wrote and shows the score, with the
31
+ failed checks named. `GET /api/health?path=…` re-runs the audit for the snapshot on screen.
32
+ 5. **Download.** The zip is the snapshot directory, stored entries, no compression — the same bytes
33
+ the agent would read.
34
+
35
+ ## What the API may read
36
+
37
+ `/api/snapshot`, `/api/snapshot.zip` and `/api/health` take a `path`. The server answers `403` for
38
+ a path outside the directory it was started for, or outside a clone it created itself. The token
39
+ decides who may ask; this decides what may be asked about — otherwise a leaked token would be an
40
+ arbitrary-file-read primitive over the whole disk.
41
+
42
+ ## The token
43
+
44
+ The page is HTML and is served without a token; everything that reads or writes a repository needs
45
+ `Authorization: Bearer <token>`. The page asks for the token and keeps it in `localStorage`, so
46
+ serving `/` can never leak the credential. `--token` chooses one; `--no-auth` turns the requirement
47
+ off and is refused on a non-loopback bind.
48
+
49
+ ## The same process serves MCP
50
+
51
+ `POST /mcp` on the same port is the MCP endpoint from [MCP](mcp.md), with the same token. A browser
52
+ agent and a human look at the same snapshot.
53
+
54
+ ## Limits, stated
55
+
56
+ | Limit | Value | Why |
57
+ | :--- | :--- | :--- |
58
+ | Bind | `127.0.0.1` | A repository on the network is a decision, not a default. |
59
+ | Request body | 64 KiB (API), 2 MiB (MCP) | A page cannot post a file at the server. |
60
+ | Brief preview | first 64 KiB of `PROMPT.md` | Bounded response, always. |
61
+ | File list | first 400 files in the page | The JSON carries every file; the page renders a window. |
62
+ | CORS | loopback origins only | A page on another origin cannot read the repository. |
63
+ | Remote URLs | https, public addresses only | The same shallow clone and SSRF guard as `generate --remote`; `serve --allow-private` opts out deliberately. |
64
+
65
+ It writes nothing except the snapshot the Generate button asks for, and it never reads outside the
66
+ path you typed.
@@ -0,0 +1,61 @@
1
+ # Signed snapshots
2
+
3
+ ```bash
4
+ codebase-snapshot generate --sign
5
+ SNAPSHOT_SIGNING_KEY="$(cat team-key.pem)" codebase-snapshot generate --sign
6
+ ```
7
+
8
+ A digest proves the bytes did not change in transit only if the digest itself is trusted. A
9
+ signature over the manifest proves two more things: who produced the snapshot, and that the
10
+ manifest you are reading is the one that was signed.
11
+
12
+ ## What is signed
13
+
14
+ The exact bytes of `manifest.json`. The manifest records a digest for every part and every
15
+ artifact, so one signature transitively covers the whole snapshot — provided the verifier checks it
16
+ against the manifest they are actually reading.
17
+
18
+ ```json
19
+ {
20
+ "algorithm": "ed25519",
21
+ "signedAt": "2026-11-18T04:44:12.812Z",
22
+ "fingerprint": "9f2c…",
23
+ "manifestSha256": "…",
24
+ "publicKey": "MCowBQYDK2VwAyEA…",
25
+ "signature": "…",
26
+ "keyOrigin": "configured"
27
+ }
28
+ ```
29
+
30
+ ## The key
31
+
32
+ | Where | Behaviour |
33
+ | :--- | :--- |
34
+ | `SNAPSHOT_SIGNING_KEY` (PEM) | `keyOrigin: "configured"`. Publish the public half; every snapshot from the team verifies against it. |
35
+ | No key | A fresh Ed25519 key is generated, `keyOrigin: "generated"`, and its public half goes in the record. That is trust on first use, and the field says so — it proves the manifest was not changed after signing, not who signed it. |
36
+
37
+ The private key never reaches the manifest, the brief or any report. The record carries only the
38
+ public half.
39
+
40
+ ## Verifying
41
+
42
+ `snapshot health` verifies the signature when `signature.json` exists:
43
+
44
+ - **critical failure** when the manifest changed after signing, the record is malformed, or the
45
+ signature does not match;
46
+ - **skip** (not a failure) when there is no signature, because most snapshots are not signed and
47
+ absence is not tampering.
48
+
49
+ ```text
50
+ ✅ The manifest signature verifies
51
+ signed 2026-11-18T04:44:12.812Z (key: configured, 9f2c5a1b7d3e)
52
+ ```
53
+
54
+ ## What it does not do
55
+
56
+ - It does not sign the parts individually; the manifest's digests do that, and signing every part
57
+ would only make the record larger.
58
+ - It does not manage keys. Generation, rotation and distribution are the caller's problem, and the
59
+ tool says so rather than pretending a key store exists.
60
+ - It does not verify the signer's identity. A signature proves possession of a key; which key is
61
+ trusted is a decision the reader makes.