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/slice.md ADDED
@@ -0,0 +1,57 @@
1
+ # Task slices
2
+
3
+ ```bash
4
+ codebase-snapshot generate --slice "how does checkout retry a failed payment" --slice-tokens 20000
5
+ ```
6
+
7
+ A slice is a snapshot built for a question. The retrieval planner that powers
8
+ [`snapshot_plan_for`](mcp.md) runs at generate time, and only the files it chooses are written. The
9
+ result is a snapshot small enough to paste, with the selection and the omissions recorded.
10
+
11
+ ## What it keeps
12
+
13
+ The planner ranks every scanned file by:
14
+
15
+ 1. path terms — `checkout` matches `src/checkout.ts` and `checkout.test.ts`;
16
+ 2. symbol names from the parsed summary — `charge` matches `chargeCard`, `authenticated` matches `auth`;
17
+ 3. layer and kind names named in the question;
18
+ 4. how many files import it (centrality);
19
+ 5. the imports of the strongest matches, pulled in as context.
20
+
21
+ Tests are excluded unless the question names them. Then files are packed in rank order until the
22
+ budget is reached; a file too large for what remains is offered as a head read, and a file that
23
+ still does not fit is skipped with a reason.
24
+
25
+ ## What it records
26
+
27
+ ```json
28
+ "slice": {
29
+ "question": "how does checkout retry a failed payment",
30
+ "budgetTokens": 20000,
31
+ "usedTokens": 18422,
32
+ "files": ["src/checkout.ts", "src/payments/retry.ts", "..."],
33
+ "dropped": 1431
34
+ }
35
+ ```
36
+
37
+ Every path that was scanned and not chosen is in `skipped[]` with reason `not-selected` — not
38
+ `unchanged`, which would be a different and untrue statement. The brief says at the top that the
39
+ snapshot is a slice, quotes the question, and warns that unselected paths are not in the parts.
40
+
41
+ ## What it does not do
42
+
43
+ - It does not read files that were excluded: sensitive files stay out, so a question about them
44
+ cannot make them selected.
45
+ - It does not promise the answer is complete. A slice is a budgeted guess at what a reader needs,
46
+ and the brief says so.
47
+ - It does not combine with `--delta` or `--budget-tokens`; all three narrow the selection and the
48
+ CLI refuses a pair rather than guessing which should win. Use `--slice-tokens` for the slice's own
49
+ budget.
50
+
51
+ ## When to use it
52
+
53
+ | Situation | Use |
54
+ | :--- | :--- |
55
+ | A focused question about one subsystem | `--slice` |
56
+ | A review of a change set | `--delta` |
57
+ | The whole repository for an audit | neither |
package/docs/tools.md ADDED
@@ -0,0 +1,161 @@
1
+ # MCP tools
2
+
3
+ The server exposes 24 tools. This page is the reference: what each answers, what it costs, and one
4
+ call you can send as it stands. [MCP](mcp.md) covers the transports and the protocol; this page is
5
+ the catalogue.
6
+
7
+ Every tool is read-only unless it says **writes**. Cost is the class `tools/list` publishes as
8
+ `_meta["codebase-snapshot/cost"]`: **cheap** reads the manifest, **medium** reads one or a few parts,
9
+ **expensive** reads the repository or writes it.
10
+
11
+ ## Orientation
12
+
13
+ - **`snapshot_status`** — cheap, read-only. Is there a snapshot, when was it built, what does it
14
+ cover, what is stale?
15
+ ```json
16
+ { "name": "snapshot_status", "arguments": {} }
17
+ ```
18
+ - **`snapshot_explain`** — cheap, read-only. Why is a path in or out of the snapshot? Reads the
19
+ manifest, so a `--slice` drop is reported as `not-selected` with the run's detail.
20
+ ```json
21
+ { "name": "snapshot_explain", "arguments": { "path": "src/index.ts" } }
22
+ ```
23
+ - **`snapshot_entrypoints`** — cheap, read-only. The files a reader should start from: manifests
24
+ first, then `index`/`main`/`app`/`server`/`cli`, with importer counts.
25
+ ```json
26
+ { "name": "snapshot_entrypoints", "arguments": {} }
27
+ ```
28
+ - **`snapshot_stats`** — cheap, read-only. Files by layer and kind, part sizes, token estimate,
29
+ heaviest files.
30
+ ```json
31
+ { "name": "snapshot_stats", "arguments": {} }
32
+ ```
33
+ - **`snapshot_workspace`** — cheap, read-only. Members of a multi-repository workspace and the
34
+ imports that cross between them, from `WORKSPACE.json`.
35
+ ```json
36
+ { "name": "snapshot_workspace", "arguments": {} }
37
+ ```
38
+
39
+ ## Finding things
40
+
41
+ - **`snapshot_search`** — medium, read-only. Literal or regular-expression search over every part,
42
+ with the file and part for each hit. Stops at 4 MB of text and says so.
43
+ ```json
44
+ { "name": "snapshot_search", "arguments": { "query": "partitionFiles", "regex": false } }
45
+ ```
46
+ - **`snapshot_query`** — cheap, read-only. Filter the index by layer, kind, path pattern, symbol or
47
+ test status; no part is read.
48
+ ```json
49
+ { "name": "snapshot_query", "arguments": { "layer": "src", "symbol": "plan" } }
50
+ ```
51
+ - **`snapshot_locate`** — cheap, read-only. Which part holds a path or symbol, and where in it.
52
+ ```json
53
+ { "name": "snapshot_locate", "arguments": { "query": "src/mcp/tools.ts", "by": "path" } }
54
+ ```
55
+ - **`snapshot_symbol`** — medium, read-only. A symbol by name: defining file, kind, signature and
56
+ the exports that reference it.
57
+ ```json
58
+ { "name": "snapshot_symbol", "arguments": { "name": "generateSnapshot" } }
59
+ ```
60
+ - **`snapshot_routes`** — cheap, read-only. Every route the summaries recorded, with file and part.
61
+ ```json
62
+ { "name": "snapshot_routes", "arguments": { "pattern": "users" } }
63
+ ```
64
+
65
+ ## Reading
66
+
67
+ - **`snapshot_history`** — cheap, read-only. The commits behind the snapshot, from
68
+ `reports/log.md`; says how to generate the report when it is absent.
69
+ ```json
70
+ { "name": "snapshot_history", "arguments": { "limit": 10 } }
71
+ ```
72
+ - **`snapshot_tests`** — cheap, read-only. The test side of the graph: given a path, the tests
73
+ that import it or are named after it; with no path, every test file and what it covers.
74
+ ```json
75
+ { "name": "snapshot_tests", "arguments": { "path": "src/mcp/tools.ts" } }
76
+ ```
77
+ - **`snapshot_read`** — medium, read-only. A bounded window of one file: line range, or the whole
78
+ body when it is small.
79
+ ```json
80
+ { "name": "snapshot_read", "arguments": { "path": "src/index.ts", "fromLine": 1, "lines": 80 } }
81
+ ```
82
+ - **`snapshot_context`** — medium, read-only. Whole bodies for the files that fit a token budget, in
83
+ the order the planner ranks them.
84
+ ```json
85
+ { "name": "snapshot_context", "arguments": { "files": ["src/mcp/retrieval.ts"], "maxTokens": 12000 } }
86
+ ```
87
+
88
+ ## The planner
89
+
90
+ - **`snapshot_plan_for`** — cheap, read-only. The plan for a question: which files fit a budget, why
91
+ each was chosen, what did not fit. Matches stems (`charge`/`chargeCard`), follows imports and
92
+ callers, prefers entry points.
93
+ ```json
94
+ { "name": "snapshot_plan_for", "arguments": { "question": "how does a snapshot get partitioned", "maxTokens": 20000 } }
95
+ ```
96
+ - **`snapshot_plan`** — expensive, read-only. Would a generate succeed, and what would it include?
97
+ Runs the real pipeline in a worker with nothing written.
98
+ ```json
99
+ { "name": "snapshot_plan", "arguments": {} }
100
+ ```
101
+
102
+ ## Reviewing a change
103
+
104
+ - **`snapshot_review`** — expensive, read-only. Is the snapshot current, what does the health audit
105
+ say, what do the given paths contain, and which route methods do they touch?
106
+ ```json
107
+ { "name": "snapshot_review", "arguments": { "paths": ["src/mcp/tools.ts"] } }
108
+ ```
109
+ - **`snapshot_diff_context`** — medium, read-only. A changed file's head plus the files that import
110
+ it, within a token budget.
111
+ ```json
112
+ { "name": "snapshot_diff_context", "arguments": { "paths": ["src/mcp/tools.ts"], "maxTokens": 15000 } }
113
+ ```
114
+ - **`snapshot_dependents`** — cheap, read-only. What imports this path, one or more hops out.
115
+ ```json
116
+ { "name": "snapshot_dependents", "arguments": { "path": "src/mcp/server.ts", "direction": "imported-by", "limit": 50 } }
117
+ ```
118
+ - **`snapshot_neighbors`** — medium, read-only. Both directions of the import graph for one path.
119
+ ```json
120
+ { "name": "snapshot_neighbors", "arguments": { "path": "src/mcp/retrieval.ts" } }
121
+ ```
122
+ - **`snapshot_cycles`** — medium, read-only. Strongly connected components: files that import each
123
+ other in a loop.
124
+ ```json
125
+ { "name": "snapshot_cycles", "arguments": { "maxComponents": 10 } }
126
+ ```
127
+
128
+ ## Health and writing
129
+
130
+ - **`snapshot_health`** — expensive, read-only. The full audit: hashes, missing parts, secrets, host
131
+ paths, token accounting, freshness, signature. Score out of 100, severities, failed check ids.
132
+ ```json
133
+ { "name": "snapshot_health", "arguments": { "maxScanBytes": 2000000 } }
134
+ ```
135
+ - **`snapshot_generate`** — expensive, **writes**. Builds the snapshot in a worker. Accepts
136
+ `includeDiffs`, `includeLogs`, `tokenTree`, `stripComments`, and reports progress and cancellation.
137
+ ```json
138
+ { "name": "snapshot_generate", "arguments": { "tokenTree": true, "pack": "xml" } }
139
+ ```
140
+ It can also narrow: `slice` with `sliceTokens`, or `budgetTokens` (not both — the tool refuses
141
+ the pair, as the CLI does).
142
+ ```json
143
+ { "name": "snapshot_generate", "arguments": { "slice": "how is auth done", "sliceTokens": 20000 } }
144
+ ```
145
+ - **`snapshot_validate`** — medium, read-only. Drift check: files changed or deleted since the
146
+ snapshot, part hashes, bookkeeping. A selection snapshot is not second-guessed, and says so.
147
+ ```json
148
+ { "name": "snapshot_validate", "arguments": {} }
149
+ ```
150
+
151
+ ## Conventions these tools share
152
+
153
+ - Relative paths resolve against the repository the server was started for; `root` moves that for one
154
+ call and is bounded by the roots the server allows.
155
+ - `outDir` names a snapshot directory other than the configured one; absent means the configured
156
+ one.
157
+ - A tool that cannot answer says why in `text` and sets `isError`. It does not return an empty list
158
+ that looks like a true negative — `snapshot_workspace` without a workspace index tells you to make
159
+ one.
160
+ - Structured results are returned as `structuredContent` alongside the text, so a client can read
161
+ the same answer either way.
@@ -344,6 +344,69 @@ path rather than about a candidate file:
344
344
  Also check `include`: if it is non-empty it acts as an allow-list, and everything else is
345
345
  excluded.
346
346
 
347
+ ## Selections, workspaces and signatures
348
+
349
+ The features added since 0.12.15 each have a failure mode that is working as intended. This section is
350
+ the map.
351
+
352
+ ### `--slice and --delta narrow in two different directions; pass one.`
353
+
354
+ A delta asks "what changed", a slice asks "what does this question need". Both narrow the same
355
+ selection and the CLI refuses to guess which you meant. Run one, or run two generates.
356
+
357
+ ### `--slice and --budget-tokens both narrow the selection; pass one, or use --slice-tokens`
358
+
359
+ Same reason. The slice has its own budget: `--slice "question" --slice-tokens 30000`.
360
+
361
+ ### `validate` warns `This snapshot is a selection (…)`
362
+
363
+ Not a failure. Files the selection left out are recorded as `not-selected`, and `validate` does not
364
+ re-run the planner — it cannot, the question and the budget are not in the manifest. It checks that
365
+ what *is* in the snapshot still matches disk. A changed selected file still fails, with its path.
366
+
367
+ ### `explain` answers `reason not-selected`
368
+
369
+ That is the answer, not an error: the file passes every per-file rule and was left out by the
370
+ selection. The detail names it.
371
+
372
+ ### `No workspace index at …`
373
+
374
+ `health --all-members` needs the `WORKSPACE.json` a `--workspace` run writes. Generate the workspace
375
+ first, or drop the flag to audit the single snapshot at `outDir`.
376
+
377
+ ### `⚠ Workspace member missing: api` — and exit 1
378
+
379
+ One member path does not exist or is not a directory. The other members are still written, the index
380
+ still lists the ones that succeeded, and the run exits 1 so a script cannot mistake a partial
381
+ workspace for a complete one.
382
+
383
+ ### A member scores lower than the rest
384
+
385
+ `health --all-members` reports the **weakest member** as the combined score. A workspace is only as
386
+ trustworthy as its worst part, and an average would hide a failed member.
387
+
388
+ ### `signature does not verify`
389
+
390
+ The manifest was signed with a key this environment does not have, or the manifest changed after
391
+ signing. Set `SNAPSHOT_SIGNING_KEY` to the key that signed it, or regenerate and sign again with
392
+ `--sign`. A key generated on first use lives in the environment only for that run; the snapshot
393
+ records its fingerprint, not the key.
394
+
395
+ ### `only https URLs are accepted`
396
+
397
+ `--remote` and the serve page refuse `http:`, `file:` and `git:` URLs. Use an `https://` repository
398
+ URL. Private repositories are reached with `GITHUB_TOKEN` in the environment, never a URL credential.
399
+
400
+ ### `the clone is larger than 1 GB (…)`
401
+
402
+ The shallow clone passed the 1 GB cap and was discarded rather than scanned. Point at a smaller
403
+ repository, or scan a local checkout.
404
+
405
+ ### `This snapshot has no reports/log.md`
406
+
407
+ `snapshot_history` reads an opt-in report. Generate with `includeLogs` (MCP) or
408
+ `--include-logs <n>` (CLI); the commit subjects are repository content, so the report is not written
409
+ unless asked for.
347
410
  ## The snapshot is too big
348
411
 
349
412
  - Lower the budget: `--max-part-bytes 120k`.
@@ -29,7 +29,7 @@ If you want the most popular, most integrated tool: **use repomix.**
29
29
  | Reproducible output | Parts are byte-identical across runs; a fingerprint covers them | Content is stable; no published determinism guarantee |
30
30
  | Staleness check | `validate` re-hashes the repository and exits non-zero on drift | Not a feature |
31
31
  | Remote repositories | No — operates on a local checkout | **Yes** — packs a GitHub URL directly |
32
- | MCP server | **Yes** — eight tools over stdio, and it serves the validated snapshot rather than the working tree | **Yes** — packs a repository, including by URL |
32
+ | MCP server | **Yes** — 24 tools over stdio, and it serves the validated snapshot rather than the working tree | **Yes** — packs a repository, including by URL |
33
33
  | Secret handling | 32 default rules, value-span masking, per-line audit table | Secretlint integration |
34
34
  | Language awareness | 25 presets, AST or structural summaries labelled by confidence | Tree-sitter parsing with a compression mode |
35
35
  | Adoption | New | **Mature** — large user base, many integrations |
@@ -0,0 +1,93 @@
1
+ # Workspaces: many repos, one pack
2
+
3
+ ```bash
4
+ codebase-snapshot generate --workspace api,web,shared --out-dir context
5
+ ```
6
+
7
+ A monorepo is rarely one repository in practice: `api`, `web` and `shared` have different
8
+ dependencies, different languages and different reasons to be read. This writes **one snapshot per
9
+ member** and an index that ties them together, so a reader gets the same guarantees per member
10
+ without one part budget stretched across everything.
11
+
12
+ ## The whole workflow
13
+
14
+ ```bash
15
+ # 1. One snapshot per member, plus the index
16
+ codebase-snapshot generate --workspace api,web,shared --out-dir context
17
+
18
+ # 2. Audit every member at once; the combined score is the weakest one
19
+ codebase-snapshot health --all-members --out-dir context --strict
20
+
21
+ # 3. Check one member against its repository
22
+ codebase-snapshot validate --cwd api --out-dir ../context/api
23
+
24
+ # 4. Serve the index to an agent
25
+ codebase-snapshot mcp --cwd . # snapshot_workspace reads context/WORKSPACE.json
26
+ ```
27
+
28
+ `health --all-members` fails the run when any member fails, so step 2 can gate a release the way a
29
+ single-snapshot audit does. The members are independent snapshots: validating `api` says nothing
30
+ about `web`, and that is deliberate — a shared failure is not evidence about either.
31
+
32
+ ## What it writes
33
+
34
+ ```text
35
+ context/
36
+ ├── WORKSPACE.json the index: one record per member
37
+ ├── api/ a complete snapshot of ./api
38
+ │ ├── manifest.json
39
+ │ ├── PROMPT.md
40
+ │ └── parts/…
41
+ ├── web/
42
+ └── shared/
43
+ ```
44
+
45
+ ```json
46
+ {
47
+ "generatedAt": "2026-11-18T05:02:11.402Z",
48
+ "generator": "0.12.38",
49
+ "members": [
50
+ { "name": "api", "path": "/repo/api", "fingerprint": "9f2c…", "files": 412, "parts": 6, "tokens": 184220 },
51
+ { "name": "web", "path": "/repo/web", "fingerprint": "1a77…", "files": 208, "parts": 3, "tokens": 96110 }
52
+ ],
53
+ "links": [
54
+ { "from": "web", "to": "shared", "specifiers": 14, "examples": ["src/api/client.ts"] }
55
+ ]
56
+ }
57
+ ```
58
+
59
+ Each member directory is a normal snapshot, but it lives under the workspace output directory, so
60
+ point the commands at it explicitly:
61
+
62
+ ```bash
63
+ codebase-snapshot validate --cwd api --out-dir ../context/api
64
+ codebase-snapshot health --cwd api --out-dir ../context/api
65
+ ```
66
+
67
+ The MCP server reads a repository and its own `outDir`; run it from `api` with that output
68
+ directory configured if the member should be served on its own.
69
+
70
+ ## Rules
71
+
72
+ - **Defaults, not member configs.** A member may contain a `snapshot.config.ts`, and a config can run
73
+ code. A workspace is a set of repositories the caller named, not one they configured, so members
74
+ are generated on the defaults. Run the member directly if its config should apply.
75
+ - **A failure is reported, not skipped.** A missing member prints its name and the run exits `1`
76
+ after writing the members that succeeded, so a partial workspace is never mistaken for a complete
77
+ one.
78
+ - **No combination.** `--workspace` is refused with `--remote`, `--delta`, `--slice`,
79
+ `--budget-tokens` and `--sign`: each of those narrows or signs *one* snapshot, and a workspace is
80
+ several.
81
+ - **Names come from the directories.** `--workspace a/api,b/api` would collide; use paths whose last
82
+ segment is unique.
83
+ - **Cross-member imports are recorded, not judged.** A relative import in one member that resolves
84
+ inside another is written as a link in `WORKSPACE.json` with the specifier count and a few
85
+ example paths. It is a static link from the specifier text: it says the members are coupled, not
86
+ that the target file is present in the other member's snapshot.
87
+
88
+ ## Why not one merged snapshot
89
+
90
+ A merged snapshot invents paths (`api/src/…`) that no file has, and one budget across members lets a
91
+ large member starve a small one. Per-member snapshots keep the paths real and the budgets local;
92
+ `WORKSPACE.json` is the only place that needs to know they belong together.
93
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codebase-snapshot",
3
- "version": "0.12.14",
3
+ "version": "0.13.0",
4
4
  "description": "Create a codebase snapshot an LLM can read: budgeted Markdown parts for Claude, ChatGPT and Cursor, a manifest of every included and skipped file, secret redaction, and validate, which fails when the snapshot drifts. Local CLI and MCP server.",
5
5
  "keywords": [
6
6
  "codebase-snapshot",