codebase-snapshot 0.22.1 → 0.22.3
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 +25 -0
- package/README.md +9 -7
- package/dist/bin.js +1200 -861
- package/dist/{chunk-7AAXOTKS.js → chunk-7QUBMV3X.js} +299 -35
- package/dist/cli.cjs +1330 -998
- package/dist/cli.js +231 -163
- package/dist/index.cjs +303 -34
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/mcp.cjs +303 -34
- package/dist/mcp.js +1 -1
- package/docs/agent.md +3 -0
- package/docs/answer.md +40 -11
- package/docs/cli.md +5 -5
- package/docs/codebase-prompt.md +97 -0
- package/docs/codebase-to-markdown.md +80 -0
- package/docs/contents.md +5 -0
- package/docs/deploy.md +2 -2
- package/docs/guard.md +14 -10
- package/docs/how-to-feed-a-repo-to-claude.md +3 -0
- package/docs/llm-codebase-context.md +3 -0
- package/docs/mcp.md +5 -5
- package/docs/repo-to-llm.md +72 -0
- package/docs/security-review.md +5 -0
- package/docs/tools.md +18 -3
- package/package.json +6 -3
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.3 (project dependency ^0.22.3)
|
|
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.3
|
|
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.3
|
|
358
358
|
Added to .gitignore: /snapshot/, /snapshot.tmp/
|
|
359
359
|
```
|
|
360
360
|
|
|
@@ -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.3 update # is this build current? print the answer
|
|
508
|
+
npx codebase-snapshot@0.22.3 update --format json
|
|
509
509
|
```
|
|
510
510
|
|
|
511
511
|
```text
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
# Codebase prompt
|
|
2
|
+
|
|
3
|
+
A **codebase prompt** is the instruction and evidence you give a model about a repository. Most “bad model answers” are bad codebase prompts: the task is vague, the evidence is missing, or the context is so large that the important lines lose attention.
|
|
4
|
+
|
|
5
|
+
A good codebase prompt has four parts:
|
|
6
|
+
|
|
7
|
+
1. **Task** — what to change, answer or review.
|
|
8
|
+
2. **Constraints** — compatibility, style, files to avoid, acceptance criteria.
|
|
9
|
+
3. **Evidence** — the smallest set of code, tests, routes and docs that answers the task.
|
|
10
|
+
4. **Output contract** — what the answer must contain and how it will be checked.
|
|
11
|
+
|
|
12
|
+
The repository dump is not the prompt. It is one input to it.
|
|
13
|
+
|
|
14
|
+
## A skeleton that works
|
|
15
|
+
|
|
16
|
+
```text
|
|
17
|
+
Task
|
|
18
|
+
Add rate limiting to the login endpoint.
|
|
19
|
+
|
|
20
|
+
Constraints
|
|
21
|
+
- Keep the existing response shape.
|
|
22
|
+
- Do not change the public auth API.
|
|
23
|
+
- Add a regression test.
|
|
24
|
+
|
|
25
|
+
Evidence
|
|
26
|
+
- src/auth/login.ts:40-96
|
|
27
|
+
- src/middleware/rate-limit.ts:1-120
|
|
28
|
+
- tests/auth/login.test.ts:1-80
|
|
29
|
+
- docs/auth.md (status codes and retry headers)
|
|
30
|
+
|
|
31
|
+
Acceptance
|
|
32
|
+
- 429 after the configured limit.
|
|
33
|
+
- Retry-After is present.
|
|
34
|
+
- Existing tests pass.
|
|
35
|
+
|
|
36
|
+
Output
|
|
37
|
+
- Patch or exact changes.
|
|
38
|
+
- Tests to run.
|
|
39
|
+
- Anything you could not verify.
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
The evidence section is where a snapshot or context tool earns its place. It should name **files and line ranges**, not “the auth code.”
|
|
43
|
+
|
|
44
|
+
## Build the evidence
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
# A task-scoped snapshot
|
|
48
|
+
npx codebase-snapshot generate --slice "add rate limiting to login" --slice-tokens 12000
|
|
49
|
+
|
|
50
|
+
# A portable brief with the change, callers and tests
|
|
51
|
+
npx codebase-snapshot brief "add rate limiting to login" --out notes/task.md
|
|
52
|
+
|
|
53
|
+
# Inside an MCP client
|
|
54
|
+
snapshot_context { "question": "add rate limiting to login", "maxTokens": 8000 }
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
The brief and `snapshot_context` return bounded, numbered windows. If a file does not fit, the response names it; add that file deliberately or narrow the task. Do not silently grow the prompt.
|
|
58
|
+
|
|
59
|
+
## Keep the prompt small enough to use
|
|
60
|
+
|
|
61
|
+
Three budgets matter:
|
|
62
|
+
|
|
63
|
+
- **Repository budget** — how much of the repo enters the prompt.
|
|
64
|
+
- **Task budget** — how much of the prompt is instructions versus evidence.
|
|
65
|
+
- **Output budget** — how much room the model has to answer.
|
|
66
|
+
|
|
67
|
+
A 100k-token repository prompt leaves little room for reasoning and often performs worse than a 6k-token evidence pack. See [token budgets](budget.md) and [how to size a context budget](how-to-context-budget.md).
|
|
68
|
+
|
|
69
|
+
## What to leave out
|
|
70
|
+
|
|
71
|
+
- Generated files and lockfiles.
|
|
72
|
+
- Vendored dependencies.
|
|
73
|
+
- Unrelated modules “for context.”
|
|
74
|
+
- Full files when a range answers the question.
|
|
75
|
+
- Secrets and credential-bearing files. Sensitive names are excluded by default; redaction is not a substitute for exclusion.
|
|
76
|
+
|
|
77
|
+
## Make it checkable
|
|
78
|
+
|
|
79
|
+
A codebase prompt should end with verification:
|
|
80
|
+
|
|
81
|
+
- the tests that should pass;
|
|
82
|
+
- the type check or build command;
|
|
83
|
+
- the callers or routes that must not change;
|
|
84
|
+
- the files the answer must cite;
|
|
85
|
+
- what the model should say if the evidence is insufficient.
|
|
86
|
+
|
|
87
|
+
That last point matters. A model that says “I did not see the route definition” is more useful than one that invents it.
|
|
88
|
+
|
|
89
|
+
## Common mistakes
|
|
90
|
+
|
|
91
|
+
1. **Task ambiguity.** “Fix auth” is not a task.
|
|
92
|
+
2. **Evidence by filename.** The answer is often in a caller or test.
|
|
93
|
+
3. **No line ranges.** The model cannot cite what it used.
|
|
94
|
+
4. **No acceptance criteria.** “Done” is not defined.
|
|
95
|
+
5. **No verification step.** The change is plausible, not checked.
|
|
96
|
+
|
|
97
|
+
→ [Repo to LLM](repo-to-llm.md) · [Codebase to Markdown](codebase-to-markdown.md) · [Briefs](brief.md) · [snapshot_context](answer.md) · [How to feed a repo to Claude](how-to-feed-a-repo-to-claude.md)
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
# Codebase to Markdown
|
|
2
|
+
|
|
3
|
+
**Codebase to Markdown** means turning a repository into one or more Markdown files a language model can read without cloning the repo. The hard part is not the conversion. It is deciding what to include, what to leave out, and how to keep line numbers and file boundaries truthful.
|
|
4
|
+
|
|
5
|
+
A raw `tree` piped into a `.md` file is not enough. Large repositories overflow the context window, irrelevant files crowd out the files that matter, and a truncated file can look complete. A useful conversion is **bounded, indexed and checkable**.
|
|
6
|
+
|
|
7
|
+
## Three useful formats
|
|
8
|
+
|
|
9
|
+
| Format | Best for | Trade-off |
|
|
10
|
+
| :-- | :-- | :-- |
|
|
11
|
+
| One Markdown file | Small repos, a single chat, a quick review | No budget; the model may silently lose the middle |
|
|
12
|
+
| Budgeted parts + manifest | Whole-repo handoff, RAG ingestion, offline review | More files; the reader must respect the manifest |
|
|
13
|
+
| Task slice | One question or change | Narrow by design; not a repository archive |
|
|
14
|
+
|
|
15
|
+
`codebase-snapshot` supports all three.
|
|
16
|
+
|
|
17
|
+
## Convert a repository
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
# One snapshot, split into parts under a byte budget
|
|
21
|
+
npx codebase-snapshot generate
|
|
22
|
+
|
|
23
|
+
# Fit a token budget, choosing the highest-value files first
|
|
24
|
+
npx codebase-snapshot generate --budget-tokens 60000
|
|
25
|
+
|
|
26
|
+
# Only what a question needs
|
|
27
|
+
npx codebase-snapshot generate --slice "how does authentication work?" --slice-tokens 12000
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
The default output is a directory:
|
|
31
|
+
|
|
32
|
+
```text
|
|
33
|
+
snapshot/
|
|
34
|
+
README.md orientation and manifest summary
|
|
35
|
+
PROMPT.md instructions for the model reading the snapshot
|
|
36
|
+
manifest.json every file, skip and truncation
|
|
37
|
+
parts/*.md the code, under the part budget
|
|
38
|
+
reports/ project tree, navigation and audit
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
The manifest is the difference between a dump and a context artefact. It records the files that were included, the ones that were skipped and why, and the exact ranges missing from any previewed file. If a file did not fit, it is named in `incomplete[]`; nothing is silently dropped.
|
|
42
|
+
|
|
43
|
+
## What to include
|
|
44
|
+
|
|
45
|
+
- Source files that implement the task.
|
|
46
|
+
- Tests that exercise the changed behaviour.
|
|
47
|
+
- Routes, configuration and entry points that connect them.
|
|
48
|
+
- A small amount of documentation for conventions the code does not state.
|
|
49
|
+
|
|
50
|
+
## What to leave out
|
|
51
|
+
|
|
52
|
+
- Generated output, lockfiles, vendored dependencies and build caches.
|
|
53
|
+
- Binary and credential-bearing files; sensitive names are excluded by default.
|
|
54
|
+
- Files that do not fit the budget — but they must be recorded, not forgotten.
|
|
55
|
+
|
|
56
|
+
## Token budgets are not byte budgets
|
|
57
|
+
|
|
58
|
+
A 300 KB part is not a safe context window. `--max-part-bytes` controls the artefact; `--budget-tokens` controls how much repository fits a model. The two are related but not interchangeable, and models tokenize differently. Read [token budgets](budget.md) before choosing a number.
|
|
59
|
+
|
|
60
|
+
For a single question, prefer [a slice](slice.md) or the live [snapshot_context](answer.md) over the whole snapshot. For a whole-repo handoff, the parts and manifest are the point.
|
|
61
|
+
|
|
62
|
+
## Common mistakes
|
|
63
|
+
|
|
64
|
+
1. **No budget.** The output fits the disk, not the model.
|
|
65
|
+
2. **No manifest.** A reader cannot tell a complete file from a preview.
|
|
66
|
+
3. **No task.** The model gets everything and still has to find the answer.
|
|
67
|
+
4. **No line numbers.** A citation cannot be checked.
|
|
68
|
+
5. **Stale output.** The tree moved; the Markdown did not.
|
|
69
|
+
|
|
70
|
+
`validate` checks the last one: it re-hashes the tree and fails when the snapshot no longer matches.
|
|
71
|
+
|
|
72
|
+
## Checklist
|
|
73
|
+
|
|
74
|
+
- [ ] Choose one file, budgeted parts, or a task slice.
|
|
75
|
+
- [ ] Set a token budget, not only a byte budget.
|
|
76
|
+
- [ ] Keep the manifest with the Markdown.
|
|
77
|
+
- [ ] Read `incomplete[]` before trusting a file.
|
|
78
|
+
- [ ] Validate before handing the snapshot to another model.
|
|
79
|
+
|
|
80
|
+
→ [Generate a snapshot](cli.md) · [Token budgets](budget.md) · [Slices](slice.md) · [Compare with repomix](vs-repomix.md) · [Repo to LLM](repo-to-llm.md)
|
package/docs/contents.md
CHANGED
|
@@ -36,6 +36,11 @@ Every page on this site, grouped by the job you are doing. If you are new, start
|
|
|
36
36
|
|
|
37
37
|
## Guides and concepts
|
|
38
38
|
|
|
39
|
+
- [Repo to LLM](repo-to-llm.md) — five ways to give a model a repository, and when each one fits.
|
|
40
|
+
- [Codebase to Markdown](codebase-to-markdown.md) — convert a repo without silent truncation or a
|
|
41
|
+
missing manifest.
|
|
42
|
+
- [Codebase prompt](codebase-prompt.md) — task, constraints, line-numbered evidence and a
|
|
43
|
+
verification contract.
|
|
39
44
|
- [LLM codebase context](llm-codebase-context.md) — what it is, why raw dumps fail, and the four
|
|
40
45
|
practical approaches.
|
|
41
46
|
- [How to feed a repository to Claude or ChatGPT](how-to-feed-a-repo-to-claude.md) — the end-to-end
|
package/docs/deploy.md
CHANGED
|
@@ -67,8 +67,8 @@ After=network.target
|
|
|
67
67
|
Type=oneshot
|
|
68
68
|
User=deploy
|
|
69
69
|
WorkingDirectory=/srv/app
|
|
70
|
-
ExecStart=/usr/bin/npx -y codebase-snapshot@0.22.
|
|
71
|
-
ExecStartPost=/usr/bin/npx -y codebase-snapshot@0.22.
|
|
70
|
+
ExecStart=/usr/bin/npx -y codebase-snapshot@0.22.3 generate --cwd /srv/app
|
|
71
|
+
ExecStartPost=/usr/bin/npx -y codebase-snapshot@0.22.3 validate --cwd /srv/app
|
|
72
72
|
```
|
|
73
73
|
|
|
74
74
|
```ini
|
package/docs/guard.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
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
|
|
@@ -44,7 +44,7 @@ and use the hook block below.
|
|
|
44
44
|
The hook runs a pinned CLI, so the machine needs Node.js 18+ and `npx`:
|
|
45
45
|
|
|
46
46
|
~~~bash
|
|
47
|
-
npx -y codebase-snapshot@0.22.
|
|
47
|
+
npx -y codebase-snapshot@0.22.3 --version
|
|
48
48
|
~~~
|
|
49
49
|
|
|
50
50
|
## Run it
|
|
@@ -58,15 +58,19 @@ codebase-snapshot guard --diff origin/main --format json
|
|
|
58
58
|
With no options it checks the working tree against `HEAD`. The output is small on purpose:
|
|
59
59
|
|
|
60
60
|
~~~text
|
|
61
|
-
Change Guard:
|
|
61
|
+
Change Guard: 3 gap(s) in this change
|
|
62
62
|
consumer src/api.ts (1 hop, relative-import, via src/auth.ts)
|
|
63
63
|
test tests/auth.test.ts (test: src/auth.ts)
|
|
64
|
+
docs src/public-api.ts (newApi)
|
|
64
65
|
coverage: complete · confidence: file-import
|
|
65
66
|
~~~
|
|
66
67
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
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`).
|
|
70
74
|
|
|
71
75
|
## Hook mode
|
|
72
76
|
|
|
@@ -97,7 +101,7 @@ The plugin install above already wires this hook. Use this block only for a manu
|
|
|
97
101
|
"hooks": [
|
|
98
102
|
{
|
|
99
103
|
"type": "command",
|
|
100
|
-
"command": "npx -y codebase-snapshot@0.22.
|
|
104
|
+
"command": "npx -y codebase-snapshot@0.22.3 guard --hook claude",
|
|
101
105
|
"timeout": 10
|
|
102
106
|
}
|
|
103
107
|
]
|
|
@@ -116,7 +120,7 @@ The plugin install above already wires this hook. Use this block only for a manu
|
|
|
116
120
|
"postToolUse": [
|
|
117
121
|
{
|
|
118
122
|
"type": "command",
|
|
119
|
-
"command": "npx -y codebase-snapshot@0.22.
|
|
123
|
+
"command": "npx -y codebase-snapshot@0.22.3 guard --hook copilot",
|
|
120
124
|
"timeoutSec": 10
|
|
121
125
|
}
|
|
122
126
|
]
|
|
@@ -135,7 +139,7 @@ The plugin install above already wires this hook. Use this block only for a manu
|
|
|
135
139
|
"hooks": [
|
|
136
140
|
{
|
|
137
141
|
"type": "command",
|
|
138
|
-
"command": "npx -y codebase-snapshot@0.22.
|
|
142
|
+
"command": "npx -y codebase-snapshot@0.22.3 guard --hook codex",
|
|
139
143
|
"timeout": 10
|
|
140
144
|
}
|
|
141
145
|
]
|
|
@@ -217,6 +217,9 @@ context for the code that is being asked about.
|
|
|
217
217
|
|
|
218
218
|
## Related
|
|
219
219
|
|
|
220
|
+
- [Repo to LLM](repo-to-llm.md) — the approach comparison behind this recipe.
|
|
221
|
+
- [Codebase to Markdown](codebase-to-markdown.md) — the conversion and budget choices.
|
|
222
|
+
- [Codebase prompt](codebase-prompt.md) — how to phrase the task and evidence.
|
|
220
223
|
- [LLM codebase context](llm-codebase-context.md) — what context is and why a raw dump fails.
|
|
221
224
|
- [MCP server for a codebase](mcp-server-for-codebase.md) — the live alternative when the client supports MCP.
|
|
222
225
|
- [All documentation](contents.md) — every guide and reference.
|
|
@@ -160,6 +160,9 @@ same questions honestly.
|
|
|
160
160
|
|
|
161
161
|
## Related
|
|
162
162
|
|
|
163
|
+
- [Repo to LLM](repo-to-llm.md) — five approaches and when each fits.
|
|
164
|
+
- [Codebase to Markdown](codebase-to-markdown.md) — conversion without silent truncation.
|
|
165
|
+
- [Codebase prompt](codebase-prompt.md) — the instruction and evidence contract.
|
|
163
166
|
- [How to feed a repository to Claude or ChatGPT](how-to-feed-a-repo-to-claude.md)
|
|
164
167
|
- [How many tokens is a codebase?](codebase-token-budget.md)
|
|
165
168
|
- [Budgeting LLM context](how-to-context-budget.md)
|
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.3 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.3", "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.3 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.3 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 |
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
# Repo to LLM
|
|
2
|
+
|
|
3
|
+
**Repo to LLM** means giving a language model enough of a repository to answer a question or make a change — without pasting the entire checkout into the prompt.
|
|
4
|
+
|
|
5
|
+
There are five common approaches. They are not interchangeable.
|
|
6
|
+
|
|
7
|
+
| Approach | What the model gets | Good for | Weakness |
|
|
8
|
+
| :-- | :-- | :-- | :-- |
|
|
9
|
+
| Raw paste | The files someone remembered to select | A tiny repo or one file | Incomplete; no budget; no citation |
|
|
10
|
+
| Repository dump | Every file, usually one Markdown file | Small repos, offline reading | Overflows; irrelevant files; silent truncation |
|
|
11
|
+
| RAG / embeddings | Chunks chosen by similarity | Large corpora, fuzzy questions | Chunk boundaries; stale index; weak structure |
|
|
12
|
+
| Repo map | Symbols, imports and call paths | Orientation and navigation | Usually no full code evidence |
|
|
13
|
+
| Snapshot + live reads | Budgeted parts, manifest, line ranges | Whole-repo handoff and agent work | Requires discipline about budgets and freshness |
|
|
14
|
+
|
|
15
|
+
`codebase-snapshot` is the last category: a **portable snapshot** for whole-repo context, and a live MCP server for line-level follow-up.
|
|
16
|
+
|
|
17
|
+
## The token question comes first
|
|
18
|
+
|
|
19
|
+
A repository that is 40 MB on disk is not 40 MB of prompt. The practical question is:
|
|
20
|
+
|
|
21
|
+
1. How many tokens does the destination model accept?
|
|
22
|
+
2. How much of that window should the repository take?
|
|
23
|
+
3. Which files earn their tokens?
|
|
24
|
+
|
|
25
|
+
For arithmetic and a budget table, see [how many tokens is a codebase](codebase-token-budget.md). For choosing the budget, see [how to size an LLM context budget](how-to-context-budget.md).
|
|
26
|
+
|
|
27
|
+
## Start with a snapshot when the task is “understand this repo”
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
npx codebase-snapshot setup # config, install, generate
|
|
31
|
+
npx codebase-snapshot generate # or regenerate
|
|
32
|
+
npx codebase-snapshot validate # has the tree moved?
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
The snapshot contains budgeted Markdown parts and a manifest. The manifest is what makes it usable as evidence: every included file, every skipped file and every missing range has a record.
|
|
36
|
+
|
|
37
|
+
## Start with a slice or live context when the task is “answer this question”
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
npx codebase-snapshot generate --slice "where is the theme switcher?" --slice-tokens 8000
|
|
41
|
+
npx codebase-snapshot brief "where is the theme switcher?" --copy
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
Inside an MCP client, `snapshot_context` returns line-numbered evidence and `snapshot_read` lets the agent ask for the next range. That is usually better than handing over a 60k-token dump for one question.
|
|
45
|
+
|
|
46
|
+
## What makes repo-to-LLM context useful
|
|
47
|
+
|
|
48
|
+
- **A task.** “Explain the repository” and “add rate limiting to login” need different evidence.
|
|
49
|
+
- **A budget.** The output should fit the model, not the disk.
|
|
50
|
+
- **Line evidence.** The model should be able to cite a file and a range.
|
|
51
|
+
- **Completeness accounting.** Omitted files must be named.
|
|
52
|
+
- **Freshness.** A snapshot from three commits ago is a different repository.
|
|
53
|
+
- **A verification path.** Tests, type checks and a change guard turn context into a checked change.
|
|
54
|
+
|
|
55
|
+
## Common failure modes
|
|
56
|
+
|
|
57
|
+
1. **Dumping everything and hoping.** The model reads the first and last parts and loses the middle.
|
|
58
|
+
2. **Selecting by filename only.** The answer is often in a caller, a route or a test.
|
|
59
|
+
3. **No omission list.** Nobody can tell whether the answer was possible from the context provided.
|
|
60
|
+
4. **No line numbers.** Citations cannot be verified.
|
|
61
|
+
5. **No follow-up tool.** When the model needs one more function, it has to ask for the whole file.
|
|
62
|
+
|
|
63
|
+
## A practical sequence
|
|
64
|
+
|
|
65
|
+
1. Generate a budgeted snapshot for orientation.
|
|
66
|
+
2. Ask a narrow question.
|
|
67
|
+
3. Use a slice, brief or `snapshot_context` for the task.
|
|
68
|
+
4. Read exact ranges with `snapshot_read`.
|
|
69
|
+
5. Run the tests the impact report names.
|
|
70
|
+
6. Validate or regenerate before the next task.
|
|
71
|
+
|
|
72
|
+
→ [Codebase to Markdown](codebase-to-markdown.md) · [Codebase prompt](codebase-prompt.md) · [LLM codebase context](llm-codebase-context.md) · [MCP server for a codebase](mcp-server-for-codebase.md) · [Briefs](brief.md)
|
package/docs/security-review.md
CHANGED
|
@@ -133,6 +133,11 @@ addition was reviewed with the same question — what new input arrives, and wha
|
|
|
133
133
|
now fails the audit; before, both passed. This turns a tampered snapshot into a detected one.
|
|
134
134
|
- **`snapshot_context`** (0.15.5) reads only `parts/` through the same parser, so redaction and
|
|
135
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.
|
|
136
141
|
- **`--only`/`--ignore`** (0.14.6, tightened 0.21.0) never widen the MCP surface: the CLI may
|
|
137
142
|
replace its own config's allow-list, but an MCP request that tries to replace a declared
|
|
138
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/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "codebase-snapshot",
|
|
3
|
-
"version": "0.22.
|
|
3
|
+
"version": "0.22.3",
|
|
4
4
|
"mcpName": "io.github.ankurhalder/codebase-snapshot",
|
|
5
|
-
"description": "
|
|
5
|
+
"description": "Codebase snapshot for AI agents: turn a repo into token-budgeted Markdown, a manifest and line-numbered context; 7 MCP tools for Claude, ChatGPT, Cursor and CI.",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"codebase-snapshot",
|
|
8
8
|
"codebase",
|
|
@@ -30,7 +30,10 @@
|
|
|
30
30
|
"cursor",
|
|
31
31
|
"chatgpt",
|
|
32
32
|
"secret-redaction",
|
|
33
|
-
"drift-detection"
|
|
33
|
+
"drift-detection",
|
|
34
|
+
"codebase-prompt",
|
|
35
|
+
"codebase-snapshot-for-ai-agents",
|
|
36
|
+
"mcp-codebase-context"
|
|
34
37
|
],
|
|
35
38
|
"author": "Ankur Halder <ankur.halder12345@gmail.com>",
|
|
36
39
|
"license": "MIT",
|