codebase-snapshot 0.20.13 → 0.22.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.
- package/CHANGELOG.md +45 -6
- package/README.md +46 -19
- package/SECURITY.md +2 -2
- package/dist/bin.js +14535 -12036
- package/dist/{chunk-GNVRD7XS.js → chunk-NPCDJBE4.js} +6097 -4425
- package/dist/cli.cjs +11184 -8708
- package/dist/cli.d.cts +94 -2
- package/dist/cli.d.ts +94 -2
- package/dist/cli.js +944 -95
- package/dist/{generate-worker-DMzNbsAW.d.cts → generate-worker-BUNhTXkj.d.cts} +2 -2
- package/dist/{generate-worker-CRMESc0b.d.ts → generate-worker-TUMvHlgz.d.ts} +2 -2
- package/dist/index.cjs +6073 -4423
- package/dist/index.d.cts +281 -63
- package/dist/index.d.ts +281 -63
- package/dist/index.js +1 -1
- package/dist/mcp.cjs +10240 -4315
- package/dist/mcp.d.cts +13 -7
- package/dist/mcp.d.ts +13 -7
- package/dist/mcp.js +1 -1
- package/dist/{types-C5ytHMYz.d.ts → types-DQXKiaXk.d.cts} +50 -2
- package/dist/{types-C5ytHMYz.d.cts → types-DQXKiaXk.d.ts} +50 -2
- package/docs/about.md +86 -0
- package/docs/agent.md +28 -6
- package/docs/answer.md +99 -48
- package/docs/benchmarks.md +34 -34
- package/docs/brief.md +80 -81
- package/docs/cli.md +126 -25
- package/docs/codebase-token-budget.md +14 -13
- package/docs/contents.md +68 -0
- package/docs/deploy.md +2 -2
- package/docs/faq.md +112 -0
- package/docs/glossary.md +152 -0
- package/docs/guard.md +154 -0
- package/docs/health.md +1 -1
- package/docs/how-to-feed-a-repo-to-claude.md +6 -0
- package/docs/impact.md +102 -0
- package/docs/install.md +4 -3
- package/docs/llm-codebase-context.md +166 -0
- package/docs/mcp-server-for-codebase.md +163 -0
- package/docs/mcp.md +48 -67
- package/docs/migration.md +83 -90
- package/docs/output.md +1 -3
- package/docs/security-review.md +8 -8
- package/docs/slice.md +1 -1
- package/docs/tools.md +159 -185
- package/docs/troubleshooting.md +11 -11
- package/docs/vs-code2prompt.md +7 -0
- package/docs/vs-gitingest.md +7 -0
- package/docs/vs-repomix.md +10 -1
- package/docs/workspace.md +1 -1
- package/package.json +8 -2
|
@@ -16,17 +16,17 @@ This repository, measured rather than estimated:
|
|
|
16
16
|
|
|
17
17
|
| | |
|
|
18
18
|
| :--- | ---: |
|
|
19
|
-
|
|
|
20
|
-
| Lines |
|
|
21
|
-
|
|
|
22
|
-
| **Estimated tokens** | **≈
|
|
23
|
-
|
|
24
|
-
That single number decides the whole conversation.
|
|
25
|
-
does not fit a 200k window at all
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
order of magnitude does not, which is what the number is for; run
|
|
29
|
-
snapshot of this repository to re-measure a checkout.
|
|
19
|
+
| Included files | 221 |
|
|
20
|
+
| Lines | ≈59,000 |
|
|
21
|
+
| Source bytes | ≈2.5 MB |
|
|
22
|
+
| **Estimated tokens** | **≈764,000** |
|
|
23
|
+
|
|
24
|
+
That single number decides the whole conversation. 764k tokens does not fit in an 8k window, it
|
|
25
|
+
does not fit a 200k window at all, and it is three quarters of a 1M window before the question is
|
|
26
|
+
asked. Measured on 2026-11-30 at 0.21.0, from `snapshot/manifest.json`; the source-only part (116
|
|
27
|
+
TypeScript files under `src/`) is smaller, and the documentation is the rest. The count moves with
|
|
28
|
+
every commit — the order of magnitude does not, which is what the number is for; run
|
|
29
|
+
`codebase-snapshot report` on a snapshot of this repository to re-measure a checkout.
|
|
30
30
|
|
|
31
31
|
## What the default part budget means
|
|
32
32
|
|
|
@@ -64,8 +64,8 @@ budget of any single part.
|
|
|
64
64
|
|
|
65
65
|
## When the repository does not fit
|
|
66
66
|
|
|
67
|
-
It usually does not.
|
|
68
|
-
that. In order of preference:
|
|
67
|
+
It usually does not. 763k tokens is a documentation-heavy repository; a real application is
|
|
68
|
+
several times that, and a large monorepo more still. In order of preference:
|
|
69
69
|
|
|
70
70
|
1. **Scope the run, not the budget.** `include`/`exclude` patterns, or the wizard's "only
|
|
71
71
|
specific folders" option, cut more than any budget change. Packing the thing you are asking
|
|
@@ -100,3 +100,4 @@ intended to fill, the budget was not the problem — the selection was.
|
|
|
100
100
|
- [Budgeting LLM context](how-to-context-budget.md) — choosing ceilings per layer
|
|
101
101
|
- [Feeding a repo to an LLM](how-to-feed-a-repo-to-claude.md) — the end-to-end recipe
|
|
102
102
|
- [Configuration](configuration.md) — `maxPartBytes`, `largeFileBytes`, `maxMonolithBytes`
|
|
103
|
+
- [Glossary](glossary.md) — token, context window, byte budget and the other terms
|
package/docs/contents.md
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
# All codebase-snapshot documentation
|
|
2
|
+
|
|
3
|
+
Every page on this site, grouped by the job you are doing. If you are new, start with the
|
|
4
|
+
[overview](../README.md), then [installation](install.md), then the [CLI reference](cli.md).
|
|
5
|
+
|
|
6
|
+
## Start here
|
|
7
|
+
|
|
8
|
+
- [Overview and quick start](../README.md) — what the tool does, install, first run and the shape
|
|
9
|
+
of the output.
|
|
10
|
+
- [Installation](install.md) — npm, yarn, pnpm, bun, npx, version pinning and a shadowed npx.
|
|
11
|
+
- [CLI reference](cli.md) — every command, option, default and exit code.
|
|
12
|
+
- [Configuration](configuration.md) — every setting, the 25 project presets, budgets and hooks.
|
|
13
|
+
- [Snapshot output](output.md) — parts, manifest, reports and the schema.
|
|
14
|
+
- [AI agents](agent.md) — the machine-readable contract and the installable skill.
|
|
15
|
+
|
|
16
|
+
## Core workflows
|
|
17
|
+
|
|
18
|
+
- [Impact reports](impact.md) — what a change reaches and which tests to run.
|
|
19
|
+
- [Change Guard](guard.md) — the untouched consumers, tests and routes after an edit, with a
|
|
20
|
+
hook mode for Claude Code, Copilot and Codex.
|
|
21
|
+
- [Briefs](brief.md) — one redacted, bounded review pack.
|
|
22
|
+
- [MCP server](mcp.md) — transports, sessions, resources and protocol details.
|
|
23
|
+
- [MCP server for a codebase](mcp-server-for-codebase.md) — setup for Claude, Cursor and generic
|
|
24
|
+
clients, the seven tools, security and limits.
|
|
25
|
+
- [MCP tools](tools.md) — every tool schema and an example call.
|
|
26
|
+
- [snapshot_context](answer.md) — cited, line-numbered context in one call.
|
|
27
|
+
- [Health](health.md) — hashes, secrets, host paths, accounting and freshness.
|
|
28
|
+
- [Serve](serve.md) — the browser page and the MCP endpoint on one local port.
|
|
29
|
+
- [Remote sources](remote.md) — shallow, SSRF-safe cloning.
|
|
30
|
+
- [Delta snapshots](delta.md) — send only what changed since a base.
|
|
31
|
+
- [Slices](slice.md) — a snapshot for one question.
|
|
32
|
+
- [Token budgets](budget.md) — fit a repository into a window by selecting whole files.
|
|
33
|
+
- [Benchmarks](benchmarks.md) — measured tokens and time on ten public repositories.
|
|
34
|
+
- [Workspaces](workspace.md) — one snapshot per member, plus an index.
|
|
35
|
+
- [Signing](signing.md) — Ed25519 signatures and verification.
|
|
36
|
+
|
|
37
|
+
## Guides and concepts
|
|
38
|
+
|
|
39
|
+
- [LLM codebase context](llm-codebase-context.md) — what it is, why raw dumps fail, and the four
|
|
40
|
+
practical approaches.
|
|
41
|
+
- [How to feed a repository to Claude or ChatGPT](how-to-feed-a-repo-to-claude.md) — the end-to-end
|
|
42
|
+
recipe.
|
|
43
|
+
- [Budgeting LLM context](how-to-context-budget.md) — choose maxPartBytes from the destination.
|
|
44
|
+
- [How many tokens is a codebase?](codebase-token-budget.md) — the arithmetic and a budget table.
|
|
45
|
+
- [Stale context is your bug](stale-context-is-your-bug.md) — detect drift and gate it in CI.
|
|
46
|
+
- [Glossary](glossary.md) — codebase snapshot, token budget, manifest, drift, MCP, AX and more.
|
|
47
|
+
- [FAQ](faq.md) — direct answers about MCP, tokens, secrets, CI and comparisons.
|
|
48
|
+
|
|
49
|
+
## Comparisons
|
|
50
|
+
|
|
51
|
+
- [vs repomix](vs-repomix.md) — two ways to pack a repository, and when repomix is the better fit.
|
|
52
|
+
- [vs gitingest](vs-gitingest.md) — a CLI artefact versus a URL-to-text trick.
|
|
53
|
+
- [vs code2prompt](vs-code2prompt.md) — a prompt versus an indexed artefact.
|
|
54
|
+
|
|
55
|
+
## Operations and trust
|
|
56
|
+
|
|
57
|
+
- [Migration to 0.21](migration.md) — the seven-tool MCP surface, live impact and every breaking
|
|
58
|
+
change.
|
|
59
|
+
- [Deploy](deploy.md) — a container, compose file and systemd timer.
|
|
60
|
+
- [Security review](security-review.md) — the threat model, controls and residual risks.
|
|
61
|
+
- [Troubleshooting](troubleshooting.md) — every message and its one-line fix.
|
|
62
|
+
- [About this project](about.md) — who maintains it, how claims are tested and the editorial policy.
|
|
63
|
+
|
|
64
|
+
## Machine-readable
|
|
65
|
+
|
|
66
|
+
- [llms.txt](https://ankurhalder.github.io/codebase-snapshot/llms.txt) — a compact index for agents.
|
|
67
|
+
- [llms-full.txt](https://ankurhalder.github.io/codebase-snapshot/llms-full.txt) — every page in one file.
|
|
68
|
+
- [Sitemap](https://ankurhalder.github.io/codebase-snapshot/sitemap.xml) — every canonical URL.
|
package/docs/deploy.md
CHANGED
|
@@ -61,8 +61,8 @@ After=network.target
|
|
|
61
61
|
Type=oneshot
|
|
62
62
|
User=deploy
|
|
63
63
|
WorkingDirectory=/srv/app
|
|
64
|
-
ExecStart=/usr/bin/npx -y codebase-snapshot@0.
|
|
65
|
-
ExecStartPost=/usr/bin/npx -y codebase-snapshot@0.
|
|
64
|
+
ExecStart=/usr/bin/npx -y codebase-snapshot@0.22.0 generate --cwd /srv/app
|
|
65
|
+
ExecStartPost=/usr/bin/npx -y codebase-snapshot@0.22.0 validate --cwd /srv/app
|
|
66
66
|
```
|
|
67
67
|
|
|
68
68
|
```ini
|
package/docs/faq.md
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
# Codebase snapshot FAQ
|
|
2
|
+
|
|
3
|
+
Short answers to the questions people ask before using codebase-snapshot. Each answer links to
|
|
4
|
+
the page with the full detail.
|
|
5
|
+
|
|
6
|
+
## What is a codebase snapshot?
|
|
7
|
+
|
|
8
|
+
A codebase snapshot is a bounded, indexed copy of a repository prepared for a language model:
|
|
9
|
+
source files are packed into Markdown parts under a byte budget, and a manifest records every
|
|
10
|
+
included file, every skipped path with the reason, and every file that had to be shortened. The
|
|
11
|
+
point is not to copy the repository; it is to produce context a reader can inspect and a pipeline
|
|
12
|
+
can validate.
|
|
13
|
+
|
|
14
|
+
## How is this different from repomix or gitingest?
|
|
15
|
+
|
|
16
|
+
repomix and gitingest pack a repository into one AI-readable document. codebase-snapshot also
|
|
17
|
+
partitions the output, records why each path was included or skipped, redacts secret-shaped values,
|
|
18
|
+
and can prove the snapshot still matches the tree. That last property is the main difference: a
|
|
19
|
+
packed file cannot tell you it is stale. See the honest comparisons with
|
|
20
|
+
[repomix](vs-repomix.md), [gitingest](vs-gitingest.md) and [code2prompt](vs-code2prompt.md).
|
|
21
|
+
|
|
22
|
+
## Does codebase-snapshot send my code anywhere?
|
|
23
|
+
|
|
24
|
+
No. The CLI and the MCP server run locally. They read a directory you name and write a directory
|
|
25
|
+
you name. There is no account, no upload and no telemetry. A remote source is fetched only when you
|
|
26
|
+
explicitly pass a URL with --remote, and that path is documented in
|
|
27
|
+
[remote sources](remote.md).
|
|
28
|
+
|
|
29
|
+
## Which languages are supported?
|
|
30
|
+
|
|
31
|
+
TypeScript and JavaScript get the deepest parser and symbol support. Python, Go, Rust, Java/Kotlin,
|
|
32
|
+
C#/.NET, PHP, Ruby, C/C++, Vue, Svelte and Astro have language profiles for classification, imports
|
|
33
|
+
and previews. Every file type can still be included as text when the profile has nothing to add.
|
|
34
|
+
See [configuration](configuration.md) for the preset and layer rules.
|
|
35
|
+
|
|
36
|
+
## How do I feed a whole repository to Claude or ChatGPT?
|
|
37
|
+
|
|
38
|
+
Generate a snapshot, attach the parts the prompt tells you to attach, and paste the instructions
|
|
39
|
+
from PROMPT.md. If the repository does not fit the destination's file limit, increase the part
|
|
40
|
+
budget or scope the run to the folders you are asking about. The end-to-end recipe is
|
|
41
|
+
[Feeding a codebase to an LLM](how-to-feed-a-repo-to-claude.md).
|
|
42
|
+
|
|
43
|
+
## How many tokens is my codebase?
|
|
44
|
+
|
|
45
|
+
A rough estimate is bytes divided by 3.5, or lines multiplied by 11. Source code is denser than
|
|
46
|
+
English prose, so a 1 MB repository is usually around 285,000 tokens, not 250,000. The tool reports
|
|
47
|
+
the estimate it actually used in manifest.totals.estimatedTokens. The arithmetic and a table of
|
|
48
|
+
budgets are in [How many tokens is a codebase?](codebase-token-budget.md).
|
|
49
|
+
|
|
50
|
+
## What is the MCP server for?
|
|
51
|
+
|
|
52
|
+
The MCP server exposes the repository to an MCP client as seven tools (six read-only): impact, context,
|
|
53
|
+
locate, read, validate, explain and generate. Instead of attaching a 12-part snapshot, an agent can
|
|
54
|
+
ask for the one part, symbol or changed-file report it needs. Setup, tool schemas and the security
|
|
55
|
+
boundary are in [MCP server for a codebase](mcp-server-for-codebase.md).
|
|
56
|
+
|
|
57
|
+
## How do I keep a snapshot from going stale?
|
|
58
|
+
|
|
59
|
+
Run validate after the code changes. It re-hashes the files and exits non-zero when the snapshot no
|
|
60
|
+
longer matches the tree, so a CI job or a pre-commit hook can refuse stale context. The MCP read
|
|
61
|
+
tools use the live tree by default, so an agent sees uncommitted edits without regenerating. See
|
|
62
|
+
[Stale context is your bug](stale-context-is-your-bug.md).
|
|
63
|
+
|
|
64
|
+
## Does it include .env files or secrets?
|
|
65
|
+
|
|
66
|
+
Credential files such as .env, .pem, .npmrc, .ssh and .tfstate are excluded by default and recorded
|
|
67
|
+
as skipped. Secret-shaped values inside ordinary files are replaced with a marker; the audit
|
|
68
|
+
artifact names the file and line but never the value. If you explicitly pass
|
|
69
|
+
--include-sensitive-files, the MCP and serve transports refuse to serve that snapshot. Read the
|
|
70
|
+
[security review](security-review.md) for the exact guarantees and residual risks.
|
|
71
|
+
|
|
72
|
+
## Can I use it in CI?
|
|
73
|
+
|
|
74
|
+
Yes. generate writes the snapshot, validate exits non-zero on drift, and health --strict fails on a
|
|
75
|
+
critical integrity or secret finding. The CLI keeps progress on stderr and JSON on stdout, so a
|
|
76
|
+
pipeline can parse it. A typical job is: generate once on the base branch, validate on every pull
|
|
77
|
+
request, and upload the parts as an artifact only when they are current.
|
|
78
|
+
|
|
79
|
+
## Does it work with monorepos and Windows?
|
|
80
|
+
|
|
81
|
+
Yes. A workspace run writes one snapshot per member plus a WORKSPACE.json index; Windows paths,
|
|
82
|
+
junctions and OneDrive rename failures are handled explicitly. The output directory is only
|
|
83
|
+
replaced when the tool can prove it wrote it. See [workspaces](workspace.md) and the
|
|
84
|
+
[troubleshooting guide](troubleshooting.md).
|
|
85
|
+
|
|
86
|
+
## Is it free, and how is it maintained?
|
|
87
|
+
|
|
88
|
+
MIT licensed, with no paid tier and no hosted service. The project is maintained in public; the
|
|
89
|
+
test suite, security review, changelog and source are all in the repository. If you need a
|
|
90
|
+
guarantee for a regulated environment, commission your own review rather than treating a README
|
|
91
|
+
as one.
|
|
92
|
+
|
|
93
|
+
## What is a token budget?
|
|
94
|
+
|
|
95
|
+
A token budget is the number of model tokens a run is allowed to spend on context. In this tool it
|
|
96
|
+
is expressed as a byte ceiling per part (maxPartBytes), because the partitioner enforces bytes and
|
|
97
|
+
estimates tokens. The budget is a hard ceiling: a file that does not fit is shortened with an
|
|
98
|
+
explicit omission record, never silently overflowed. See
|
|
99
|
+
[Budgeting LLM context](how-to-context-budget.md).
|
|
100
|
+
|
|
101
|
+
## What is agent experience?
|
|
102
|
+
|
|
103
|
+
Agent experience (AX) is whether an agent can fetch, read and act on a site or tool without a human
|
|
104
|
+
translating for it. For documentation that means static HTML, clear headings, stable URLs, a
|
|
105
|
+
machine-readable contract and bounded responses. The evidence behind that claim is summarised in
|
|
106
|
+
[AX is the New AEO](https://arxiv.org/abs/2609.34951) and [What Drives AI Citations?](https://arxiv.org/abs/2610.15033).
|
|
107
|
+
|
|
108
|
+
## Related
|
|
109
|
+
|
|
110
|
+
- [About this project](about.md)
|
|
111
|
+
- [All documentation](contents.md)
|
|
112
|
+
- [Glossary](glossary.md)
|
package/docs/glossary.md
ADDED
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
# Codebase snapshot and LLM context glossary
|
|
2
|
+
|
|
3
|
+
The words this project uses, defined plainly. Where a term has a narrower meaning in the code, the
|
|
4
|
+
narrower meaning is the one that applies.
|
|
5
|
+
|
|
6
|
+
### Codebase snapshot
|
|
7
|
+
|
|
8
|
+
A bounded, indexed copy of a repository prepared for a language model: Markdown parts containing
|
|
9
|
+
the source, plus a manifest that records every included file, every skipped path, and every file
|
|
10
|
+
whose body was shortened. A snapshot is not a git commit and not a backup; it is context with an
|
|
11
|
+
audit trail.
|
|
12
|
+
|
|
13
|
+
### Context window
|
|
14
|
+
|
|
15
|
+
The maximum number of tokens a model can read and generate in one request. A 128k context window
|
|
16
|
+
does not mean 128,000 tokens of source code: the system prompt, the question, the snapshot and the
|
|
17
|
+
reply all share the same budget.
|
|
18
|
+
|
|
19
|
+
### Token
|
|
20
|
+
|
|
21
|
+
A unit of text a model processes. Tokens are not words or characters. English prose is often around
|
|
22
|
+
four characters per token; source code is denser because identifiers, punctuation and indentation
|
|
23
|
+
tokenise less efficiently. A token count is therefore model-specific, which is why this tool
|
|
24
|
+
reports an estimate and enforces a byte ceiling rather than pretending to know a tokenizer's exact
|
|
25
|
+
answer.
|
|
26
|
+
|
|
27
|
+
### Token budget
|
|
28
|
+
|
|
29
|
+
The amount of context a run is allowed to produce. codebase-snapshot expresses it as maxPartBytes
|
|
30
|
+
because the partitioner writes bytes, and reports the estimated tokens beside it. The budget is a
|
|
31
|
+
ceiling, not a target.
|
|
32
|
+
|
|
33
|
+
### Part
|
|
34
|
+
|
|
35
|
+
One Markdown file written by the partitioner. A part contains a fixed header, a file listing and
|
|
36
|
+
one or more file sections, and never exceeds its byte budget. Parts are the unit a chat destination
|
|
37
|
+
attaches, which is why the prompt does delivery arithmetic instead of asking a model to read a
|
|
38
|
+
single enormous file.
|
|
39
|
+
|
|
40
|
+
### Manifest
|
|
41
|
+
|
|
42
|
+
The JSON index at the root of a snapshot. It records the configuration digest, file entries with
|
|
43
|
+
layer, kind, language, part and hash, skipped paths with reasons, part hashes, artifact hashes, git
|
|
44
|
+
state and counts. The manifest is the contract every reader trusts; validate compares it with the
|
|
45
|
+
tree.
|
|
46
|
+
|
|
47
|
+
### Drift
|
|
48
|
+
|
|
49
|
+
The difference between what a snapshot records and what the repository contains now. Drift includes
|
|
50
|
+
changed bytes, added and deleted files, changed ignore or configuration rules, damaged parts and
|
|
51
|
+
stale reports. validate reports drift and exits non-zero.
|
|
52
|
+
|
|
53
|
+
### Fingerprint
|
|
54
|
+
|
|
55
|
+
A hash of the snapshot's content and configuration, recorded in the manifest and printed by the
|
|
56
|
+
CLI. Two runs over unchanged input produce the same fingerprint. It is a summary, not a signature;
|
|
57
|
+
signing is a separate operation.
|
|
58
|
+
|
|
59
|
+
### MCP
|
|
60
|
+
|
|
61
|
+
Model Context Protocol: a standard way for an AI client to discover and call tools and read
|
|
62
|
+
resources exposed by a local or remote server. codebase-snapshot serves seven tools; six are
|
|
63
|
+
read-only and one writes a snapshot. See [MCP server for a codebase](mcp-server-for-codebase.md).
|
|
64
|
+
|
|
65
|
+
### Tool
|
|
66
|
+
|
|
67
|
+
A callable operation with a JSON Schema input and structured output. Tools are listed by the MCP
|
|
68
|
+
server, have a cost class, and are the unit an agent decides to call. Resources are the other half
|
|
69
|
+
of the protocol: URI-addressed content such as snapshot://manifest.
|
|
70
|
+
|
|
71
|
+
### Resource
|
|
72
|
+
|
|
73
|
+
A URI-addressed, read-only document exposed over MCP. This server publishes the manifest, the
|
|
74
|
+
prompt, the parts, reports, the contract and the skill. Resources are listed before they are read,
|
|
75
|
+
so a missing artifact is not advertised as if it existed.
|
|
76
|
+
|
|
77
|
+
### LLM context
|
|
78
|
+
|
|
79
|
+
The information a model is given before it answers. Good context is relevant, bounded, attributable
|
|
80
|
+
and current. More context is not automatically better: a 1M-token dump can bury the one file that
|
|
81
|
+
matters and leave no room for the answer.
|
|
82
|
+
|
|
83
|
+
### Repository packing
|
|
84
|
+
|
|
85
|
+
Collecting a repository into one document or a small set of documents for a model. Packing is a
|
|
86
|
+
transport decision; it says nothing about whether the content is current, complete or safe to
|
|
87
|
+
share. Those properties have to be added deliberately.
|
|
88
|
+
|
|
89
|
+
### Retrieval-augmented generation (RAG)
|
|
90
|
+
|
|
91
|
+
A pattern where a system retrieves relevant passages from an index and puts them in the model's
|
|
92
|
+
context at question time. Repository packing is the opposite trade-off: it prepares a stable,
|
|
93
|
+
inspectable artefact ahead of time. The two can be combined; codebase-snapshot's MCP tools are
|
|
94
|
+
closer to bounded retrieval over a local index.
|
|
95
|
+
|
|
96
|
+
### Agent experience (AX)
|
|
97
|
+
|
|
98
|
+
Whether an agent can fetch, read and act on a site or tool without a human translating for it.
|
|
99
|
+
Static HTML, stable URLs, a machine-readable contract, bounded responses and explicit errors are
|
|
100
|
+
AX. The [AX is the New AEO](https://arxiv.org/abs/2609.34951) study finds that agent-ready sites are
|
|
101
|
+
recommended more often and answered from their own pages more often.
|
|
102
|
+
|
|
103
|
+
### Generative engine optimization (GEO) and answer engine optimization (AEO)
|
|
104
|
+
|
|
105
|
+
The practice of making content discoverable, citable and useful in AI-generated answers. The
|
|
106
|
+
credible parts are the old parts: unique first-hand content, clear structure, verifiable facts and
|
|
107
|
+
a readable site. The unreliable parts are paid placements, synthetic listicles and claims that a
|
|
108
|
+
special file guarantees inclusion.
|
|
109
|
+
|
|
110
|
+
### llms.txt
|
|
111
|
+
|
|
112
|
+
A proposed Markdown index for language models, with a short summary and links to the pages an agent
|
|
113
|
+
should read. It is useful as an agent-facing table of contents. Google has said that special AI
|
|
114
|
+
text files are not required for its AI features, so this project treats llms.txt as documentation
|
|
115
|
+
infrastructure, not as a ranking switch.
|
|
116
|
+
|
|
117
|
+
### Secret redaction
|
|
118
|
+
|
|
119
|
+
Replacing a matched credential-shaped value with a marker before it reaches an artifact. Redaction
|
|
120
|
+
is span-based: the surrounding line and the file's structure stay readable, while the value does
|
|
121
|
+
not. It is defence in depth, not a guarantee that every possible secret shape is known.
|
|
122
|
+
|
|
123
|
+
### Byte budget
|
|
124
|
+
|
|
125
|
+
A hard ceiling on the bytes a part or artifact may contain. Bytes are what the writer controls, so
|
|
126
|
+
the budget is enforceable without a tokenizer. The tool estimates tokens from bytes for planning,
|
|
127
|
+
but the ceiling that can fail a run is the byte ceiling.
|
|
128
|
+
|
|
129
|
+
### Preview and omission
|
|
130
|
+
|
|
131
|
+
A preview is a bounded head and tail of a file that did not fit. An omission range records the
|
|
132
|
+
lines that were not emitted. The rule is that nothing disappears without a reason: a shortened file
|
|
133
|
+
is listed in incomplete[], with its reason and ranges, and verifyInMemory fails the run if the
|
|
134
|
+
accounting does not add up.
|
|
135
|
+
|
|
136
|
+
### Symbol-pruned impact
|
|
137
|
+
|
|
138
|
+
A reverse-import analysis that follows the exported symbol a change actually touches, rather than
|
|
139
|
+
every file that imports the module. It is conservative where the symbol cannot be determined and
|
|
140
|
+
reports the limits of its answer. See [impact reports](impact.md).
|
|
141
|
+
|
|
142
|
+
### Workspace
|
|
143
|
+
|
|
144
|
+
A repository whose packages are snapshotted separately but recorded in one WORKSPACE.json index.
|
|
145
|
+
A workspace run preserves each member's real path and local budget, and reports a missing member
|
|
146
|
+
rather than silently skipping it.
|
|
147
|
+
|
|
148
|
+
## Related
|
|
149
|
+
|
|
150
|
+
- [All documentation](contents.md)
|
|
151
|
+
- [FAQ](faq.md)
|
|
152
|
+
- [How many tokens is a codebase?](codebase-token-budget.md)
|
package/docs/guard.md
ADDED
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
# Change Guard
|
|
2
|
+
|
|
3
|
+
`guard` answers one question after an agent edits code: **what does this change reach that is
|
|
4
|
+
not in the change set?** It returns untouched consumers, candidate tests and affected routes — or
|
|
5
|
+
nothing at all.
|
|
6
|
+
|
|
7
|
+
It is the in-loop companion to [impact](impact.md) and [brief](brief.md). Impact is a report you
|
|
8
|
+
ask for; Change Guard is a check that can run on every edit and stay silent until it has something
|
|
9
|
+
useful to say.
|
|
10
|
+
|
|
11
|
+
## Run it
|
|
12
|
+
|
|
13
|
+
~~~bash
|
|
14
|
+
codebase-snapshot guard --changed
|
|
15
|
+
codebase-snapshot guard --paths src/auth.ts --format json
|
|
16
|
+
codebase-snapshot guard --diff origin/main --format json
|
|
17
|
+
~~~
|
|
18
|
+
|
|
19
|
+
With no options it checks the working tree against `HEAD`. The output is small on purpose:
|
|
20
|
+
|
|
21
|
+
~~~text
|
|
22
|
+
Change Guard: 2 gap(s) in this change
|
|
23
|
+
consumer src/api.ts (1 hop, relative-import, via src/auth.ts)
|
|
24
|
+
test tests/auth.test.ts (test: src/auth.ts)
|
|
25
|
+
coverage: complete · confidence: symbol-pruned
|
|
26
|
+
~~~
|
|
27
|
+
|
|
28
|
+
Every gap is a path outside the change. A file the change already touched is never reported again.
|
|
29
|
+
|
|
30
|
+
## Hook mode
|
|
31
|
+
|
|
32
|
+
`--hook <client>` reads one JSON payload from stdin and writes the host-shaped response to stdout.
|
|
33
|
+
It never fails the agent's turn: a malformed payload or a missing manifest produces an empty object
|
|
34
|
+
and a note on stderr.
|
|
35
|
+
|
|
36
|
+
| Client | Flag | Response |
|
|
37
|
+
| :-- | :-- | :-- |
|
|
38
|
+
| Claude Code | `--hook claude` | `hookSpecificOutput.additionalContext` with `hookEventName` |
|
|
39
|
+
| Copilot | `--hook copilot` | top-level `additionalContext` |
|
|
40
|
+
| Codex | `--hook codex` | top-level `additionalContext` |
|
|
41
|
+
| Other | `--hook raw` | top-level `additionalContext` |
|
|
42
|
+
|
|
43
|
+
When there is nothing to report, the response is `{}`. That is the point: a guard that speaks when
|
|
44
|
+
there is nothing wrong is a guard users disable.
|
|
45
|
+
|
|
46
|
+
### Claude Code
|
|
47
|
+
|
|
48
|
+
~~~json
|
|
49
|
+
{
|
|
50
|
+
"hooks": {
|
|
51
|
+
"PostToolUse": [
|
|
52
|
+
{
|
|
53
|
+
"matcher": "Edit|Write",
|
|
54
|
+
"hooks": [
|
|
55
|
+
{
|
|
56
|
+
"type": "command",
|
|
57
|
+
"command": "npx -y codebase-snapshot@0.22.0 guard --hook claude",
|
|
58
|
+
"timeout": 10
|
|
59
|
+
}
|
|
60
|
+
]
|
|
61
|
+
}
|
|
62
|
+
]
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
~~~
|
|
66
|
+
|
|
67
|
+
### Copilot in VS Code
|
|
68
|
+
|
|
69
|
+
~~~json
|
|
70
|
+
{
|
|
71
|
+
"version": 1,
|
|
72
|
+
"hooks": {
|
|
73
|
+
"postToolUse": [
|
|
74
|
+
{
|
|
75
|
+
"type": "command",
|
|
76
|
+
"command": "npx -y codebase-snapshot@0.22.0 guard --hook copilot",
|
|
77
|
+
"timeoutSec": 10
|
|
78
|
+
}
|
|
79
|
+
]
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
~~~
|
|
83
|
+
|
|
84
|
+
### Codex CLI
|
|
85
|
+
|
|
86
|
+
~~~json
|
|
87
|
+
{
|
|
88
|
+
"hooks": {
|
|
89
|
+
"PostToolUse": [
|
|
90
|
+
{
|
|
91
|
+
"matcher": "Edit|Write",
|
|
92
|
+
"hooks": [
|
|
93
|
+
{
|
|
94
|
+
"type": "command",
|
|
95
|
+
"command": "npx -y codebase-snapshot@0.22.0 guard --hook codex",
|
|
96
|
+
"timeout": 10
|
|
97
|
+
}
|
|
98
|
+
]
|
|
99
|
+
}
|
|
100
|
+
]
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
~~~
|
|
104
|
+
|
|
105
|
+
The exact file location is the host's: `.claude/settings.json`, `.github/hooks/*.json`,
|
|
106
|
+
`.codex/hooks.json`, or the plugin's own `hooks/hooks.json`. The command is the same.
|
|
107
|
+
|
|
108
|
+
## What it reads
|
|
109
|
+
|
|
110
|
+
The guard reuses the live index: the working tree is scanned in memory and uncommitted edits are
|
|
111
|
+
overlaid, so no `generate` run is required. `--no-live` requires a persisted manifest instead.
|
|
112
|
+
|
|
113
|
+
It reads the same manifest and import resolver as [impact](impact.md). It never writes into the
|
|
114
|
+
repository and never reads a sensitive file: `.env`, `*.pem` and the rest stay out.
|
|
115
|
+
|
|
116
|
+
## What it does not claim
|
|
117
|
+
|
|
118
|
+
- **Candidate tests, not coverage.** A test that imports a changed file is a candidate; it may not
|
|
119
|
+
exercise the changed behavior.
|
|
120
|
+
- **Static reach, not runtime reach.** A dynamic import the parser cannot evaluate is absent rather
|
|
121
|
+
than guessed; the trust envelope says when coverage is partial.
|
|
122
|
+
- **No proof.** A clean report means no gap was found within the bounds, not that the change is
|
|
123
|
+
correct.
|
|
124
|
+
- **No model call.** The guard is deterministic. It does not ask another model to review the diff.
|
|
125
|
+
|
|
126
|
+
## Bounds
|
|
127
|
+
|
|
128
|
+
| Limit | Default | Why |
|
|
129
|
+
| :-- | --: | :-- |
|
|
130
|
+
| Consumers in one report | 10 | Keep the model-facing note under a token budget |
|
|
131
|
+
| Candidate tests | 5 | The agent can run the highest-value ones first |
|
|
132
|
+
| Routes | 5 | Same |
|
|
133
|
+
| Hook text | 1200 chars | `--max-chars` changes it (200-10000) |
|
|
134
|
+
|
|
135
|
+
When the list is cut, `truncated` is true and the omitted counts are recorded. Nothing disappears
|
|
136
|
+
without a number.
|
|
137
|
+
|
|
138
|
+
## Exit codes
|
|
139
|
+
|
|
140
|
+
| Code | Meaning |
|
|
141
|
+
| :-- | :-- |
|
|
142
|
+
| 0 | The check ran. This includes a clean report and a hook that returned `{}`. |
|
|
143
|
+
| 1 | The live index could not be built, or `--no-live` was given without a manifest. |
|
|
144
|
+
| 2 | A usage error: an unknown client, `--max-chars` out of range, or `--hook` combined with `--paths`. |
|
|
145
|
+
|
|
146
|
+
In hook mode a failure is fail-open: stdout is `{}` and the reason is on stderr, so a broken guard
|
|
147
|
+
cannot break the agent's turn.
|
|
148
|
+
|
|
149
|
+
## Related
|
|
150
|
+
|
|
151
|
+
- [Impact reports](impact.md) — the analysis the guard summarizes.
|
|
152
|
+
- [Briefs](brief.md) — the reviewer-facing pack.
|
|
153
|
+
- [MCP tools](tools.md) — the same analysis over MCP.
|
|
154
|
+
- [Stale context is your bug](stale-context-is-your-bug.md) — why freshness is a separate check.
|
package/docs/health.md
CHANGED
|
@@ -152,7 +152,7 @@ codebase-snapshot health --all-members --cwd /repo
|
|
|
152
152
|
|
|
153
153
|
## In the MCP server
|
|
154
154
|
|
|
155
|
-
`
|
|
155
|
+
`snapshot_validate` with `mode: "audit"` returns the same report as structured output, so an agent can call it before
|
|
156
156
|
trusting a snapshot it was handed. Pass `deep: true` for the source replay:
|
|
157
157
|
|
|
158
158
|
```json
|
|
@@ -214,3 +214,9 @@ context for the code that is being asked about.
|
|
|
214
214
|
- [Configuration](configuration.md) — every setting and its default
|
|
215
215
|
- [Snapshot output](output.md) — what each artifact contains
|
|
216
216
|
- [Comparing with other tools](vs-repomix.md)
|
|
217
|
+
|
|
218
|
+
## Related
|
|
219
|
+
|
|
220
|
+
- [LLM codebase context](llm-codebase-context.md) — what context is and why a raw dump fails.
|
|
221
|
+
- [MCP server for a codebase](mcp-server-for-codebase.md) — the live alternative when the client supports MCP.
|
|
222
|
+
- [All documentation](contents.md) — every guide and reference.
|
package/docs/impact.md
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
# Impact reports
|
|
2
|
+
|
|
3
|
+
`codebase-snapshot impact` answers one question before a change is opened for review: **what does
|
|
4
|
+
this change reach, and which tests are candidates?** It is not a code graph for browsing. It is a
|
|
5
|
+
bounded, evidence-carrying report built from the same import resolver the generator uses, with a
|
|
6
|
+
`trust` envelope that says how fresh and complete the answer is.
|
|
7
|
+
|
|
8
|
+
## Run it
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
codebase-snapshot impact --diff HEAD
|
|
12
|
+
codebase-snapshot impact --paths src/impact.ts,src/cli.ts --format markdown
|
|
13
|
+
codebase-snapshot impact --diff origin/main --tests-paths
|
|
14
|
+
codebase-snapshot impact --diff HEAD --run
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
With neither `--diff` nor `--paths`, the base is `HEAD`. The change set includes committed,
|
|
18
|
+
staged, unstaged and untracked changes relative to the ref. A ref beginning with `-` is refused;
|
|
19
|
+
`shell: false` is used for every git invocation.
|
|
20
|
+
|
|
21
|
+
The report works without a generated snapshot. A current `manifest.json` is reused, changed and
|
|
22
|
+
new files are overlaid in memory, and a repository with no snapshot is scanned in memory. Nothing
|
|
23
|
+
is written into the repository. `--no-live` requires the persisted snapshot instead.
|
|
24
|
+
|
|
25
|
+
## What is in the report
|
|
26
|
+
|
|
27
|
+
| Field | Meaning |
|
|
28
|
+
| :-- | :-- |
|
|
29
|
+
| `changed[]` | Path, whether it is in the snapshot, whether it is deleted, and why it is absent when it is. |
|
|
30
|
+
| `affected[]` | One entry per impacted file: `distance`, `via`, the exact `specifier`, `confidence` (how the edge resolved), `impactKind` and `matchedSymbols`. |
|
|
31
|
+
| `tests[]` | Candidate tests, with the files they cover. These are import relationships, never runtime coverage. |
|
|
32
|
+
| `unresolved[]` | Repository-internal imports that did not resolve. Bare packages and Node built-ins are outside the repository and are not listed. |
|
|
33
|
+
| `routesAffected[]` | Route files in the changed or affected set, with the methods their summaries recorded. |
|
|
34
|
+
| `prunedByBarrel` | Barrel edges rejected because they do not consume the changed symbol. |
|
|
35
|
+
| `cycles` | Import cycles in the impacted subgraph, with `--include-cycles`. |
|
|
36
|
+
| `imports` | Outgoing dependencies of changed files, with `--include-imports`. |
|
|
37
|
+
| `trust` | Index source, freshness, coverage, redaction and omission counts, and named partial reasons. |
|
|
38
|
+
| `truncated` / `limits` | Whether `--max-results` cut the list, and the bounds that applied. |
|
|
39
|
+
|
|
40
|
+
Test files are excluded from `affected[]` and listed in `tests[]`. A file that changed from full to
|
|
41
|
+
preview is still a file: the node is present, the body may not be.
|
|
42
|
+
|
|
43
|
+
## How an edge is decided
|
|
44
|
+
|
|
45
|
+
1. The changed file is resolved against the manifest. A deleted path, an unknown path, a non-TypeScript
|
|
46
|
+
file and a paths-only run seed a wildcard. A `--diff` run maps the new-side hunks to the exported
|
|
47
|
+
declarations whose line spans they overlap; an edit outside every declaration widens to a wildcard.
|
|
48
|
+
2. Reverse importers are walked. The walk reads the importing file's `importBindings` and
|
|
49
|
+
`reExportBindings`, not just the specifier:
|
|
50
|
+
- `import { foo as f }` matches the original `foo`;
|
|
51
|
+
- `export * from "./a"` propagates the symbol set;
|
|
52
|
+
- `export { foo as publicFoo }` maps `foo` to `publicFoo`;
|
|
53
|
+
- `export * as ns` propagates `ns`;
|
|
54
|
+
- CommonJS destructured `require()` and dynamic `import()` are file-level edges;
|
|
55
|
+
- a pure barrel is traversed but not reported as an affected consumer.
|
|
56
|
+
3. If a barrel edge matches nothing in the incoming symbol set, it is pruned and counted. A consumer
|
|
57
|
+
of a *different* export is not reported.
|
|
58
|
+
4. Direct or transitive importers are reported with the exact hop that reached them. Tests are collected
|
|
59
|
+
when their import consumes the impacted symbol set.
|
|
60
|
+
|
|
61
|
+
The compiler pass behind `--precise` is bounded to 2,500 files and four seconds. It follows
|
|
62
|
+
`getAliasedSymbol` through aliases and returns only path/line/name references, never source text. Above
|
|
63
|
+
the cap or past the deadline the report stays partial and says why; it never silently falls back.
|
|
64
|
+
|
|
65
|
+
## Tests
|
|
66
|
+
|
|
67
|
+
`tests[]` is a **candidate list**. A candidate test imports a changed or affected file. It may not
|
|
68
|
+
exercise the changed behaviour, and no coverage claim is made. `--tests-paths` prints one path per
|
|
69
|
+
line for a CI step. `--run` invokes the repository's own runner:
|
|
70
|
+
|
|
71
|
+
- Vitest: `node node_modules/vitest/vitest.mjs related <changed...> --run`
|
|
72
|
+
- Jest: `node node_modules/jest/bin/jest.js --findRelatedTests <changed...> --runInBand`
|
|
73
|
+
- node:test: `node --test <candidate tests>`
|
|
74
|
+
|
|
75
|
+
No package manager, shell or network is used. A change to a build, test or workspace configuration
|
|
76
|
+
adds a warning that the selective run may be incomplete; run the full suite too.
|
|
77
|
+
|
|
78
|
+
## Output
|
|
79
|
+
|
|
80
|
+
`--format json` is the stable contract and writes one JSON document to stdout. Text goes to stderr,
|
|
81
|
+
as every human-facing command does. `--format markdown` writes a PR-ready report to stdout;
|
|
82
|
+
`--format pr-comment` is accepted by `brief`, which is the page-oriented command.
|
|
83
|
+
|
|
84
|
+
Exit `0` when the report was produced, `1` when the live index cannot be built or an explicit
|
|
85
|
+
`--no-live` manifest is missing, and `2` for a usage error.
|
|
86
|
+
|
|
87
|
+
## What it does not claim
|
|
88
|
+
|
|
89
|
+
- It is not runtime coverage, a call graph, or a security review.
|
|
90
|
+
- It does not resolve bare package specifiers to `node_modules`, or Node built-ins.
|
|
91
|
+
- It does not see a dependency created through a dynamic string the parser cannot evaluate; such a
|
|
92
|
+
path is absent rather than guessed.
|
|
93
|
+
- A manifest generated from a dirty tree may describe bytes that have already moved. The `trust`
|
|
94
|
+
envelope names that condition; `validate` is the separate proof.
|
|
95
|
+
|
|
96
|
+
→ [CLI reference](cli.md) · [Impact in MCP](tools.md) · [Brief](brief.md)
|
|
97
|
+
|
|
98
|
+
## Related
|
|
99
|
+
|
|
100
|
+
- [Briefs](brief.md) — turn an impact report into a review pack.
|
|
101
|
+
- [LLM codebase context](llm-codebase-context.md) — why symbol-pruned context beats a repository dump.
|
|
102
|
+
- [All documentation](contents.md) — every guide and reference.
|