@ankurhalder/codebase-snapshot 3.0.0 → 4.0.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/README.md +161 -310
- package/dist/bin.js +1939 -570
- package/dist/{chunk-5B4UVQLR.js → chunk-FM4OOQPF.js} +1558 -390
- package/dist/cli.cjs +1907 -537
- package/dist/cli.d.cts +3 -1
- package/dist/cli.d.ts +3 -1
- package/dist/cli.js +265 -64
- package/dist/index.cjs +1557 -387
- package/dist/index.d.cts +22 -28
- package/dist/index.d.ts +22 -28
- package/dist/index.js +1 -1
- package/dist/{types-CJqkePM4.d.cts → types-BdpT_4b8.d.cts} +37 -4
- package/dist/{types-CJqkePM4.d.ts → types-BdpT_4b8.d.ts} +37 -4
- package/docs/agent.md +77 -37
- package/docs/cli.md +315 -0
- package/docs/configuration.md +254 -226
- package/docs/install.md +114 -86
- package/docs/output.md +213 -0
- package/docs/troubleshooting.md +277 -0
- package/package.json +7 -4
package/README.md
CHANGED
|
@@ -1,369 +1,220 @@
|
|
|
1
|
-
#
|
|
1
|
+
# codebase-snapshot
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
**Turn any repository into an LLM-ready snapshot: code packed into size-budgeted markdown
|
|
4
|
+
parts, indexed by a JSON manifest, with a secret audit — in one command.**
|
|
4
5
|
|
|
5
6
|
[](https://www.npmjs.com/package/@ankurhalder/codebase-snapshot)
|
|
6
|
-
[](https://www.npmjs.com/package/@ankurhalder/codebase-snapshot)
|
|
8
|
+
[](LICENSE)
|
|
9
|
+
[](https://nodejs.org)
|
|
15
10
|
|
|
16
11
|
```bash
|
|
17
|
-
|
|
12
|
+
npx @ankurhalder/codebase-snapshot generate
|
|
18
13
|
```
|
|
19
14
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
Next.js, Nuxt, SvelteKit, Astro, Vue, React, NestJS, Django, FastAPI, Go, Rust,
|
|
24
|
-
Java, .NET, PHP, Ruby, monorepos and infra repos.
|
|
25
|
-
|
|
26
|
-
Non-interactive, with every answer as a flag:
|
|
15
|
+
That writes `./snapshot/` — a directory you can drop into a chat, a prompt, a RAG pipeline or
|
|
16
|
+
a repository review. It works on TypeScript and JavaScript projects, and on Python, Go, Rust,
|
|
17
|
+
Java/Kotlin, C#/.NET, PHP, Ruby, C/C++, Vue, Svelte and Astro, without configuration.
|
|
27
18
|
|
|
28
|
-
|
|
29
|
-
npx @ankurhalder/codebase-snapshot init --preset react-vite --max-part-bytes 120k --yes
|
|
30
|
-
```
|
|
19
|
+

|
|
31
20
|
|
|
32
21
|
---
|
|
33
22
|
|
|
34
|
-
##
|
|
35
|
-
|
|
36
|
-
- **25 project presets** — detection reads the repository once and picks the most
|
|
37
|
-
specific match: Next.js, Nuxt, SvelteKit, Remix, Astro, Angular, Solid, Vue,
|
|
38
|
-
React, NestJS, Express/ Fastify, Python (Django / FastAPI / library), Go, Rust,
|
|
39
|
-
Java/Spring, .NET, Laravel, Rails, monorepos, infra and docs.
|
|
40
|
-
- **Structural summaries beyond TypeScript** — imports, declarations and exports
|
|
41
|
-
for Python, Go, Rust, Java/Kotlin/Scala, C#, PHP, Ruby and C/C++, plus the
|
|
42
|
-
script block of Vue/Svelte/Astro components through the real TypeScript
|
|
43
|
-
compiler. Every summary is labelled `ast`, `structural` or `heuristic`.
|
|
44
|
-
- **Interactive setup** — `npm create codebase-snapshot` walks every tunable
|
|
45
|
-
parameter and writes a self-documenting config.
|
|
46
|
-
- **Per-ecosystem ignores** — `__pycache__`, `.venv`, `target`, `.gradle`,
|
|
47
|
-
`bin`/`obj`, `vendor`, `.svelte-kit` and friends are recognised per preset.
|
|
48
|
-
- **Hard byte budgeting** — every `part-XXX.md` is guaranteed to stay under `maxPartBytes`. A single
|
|
49
|
-
oversized file is byte-truncated and marked rather than emitted whole.
|
|
50
|
-
- **Bounded redaction** — masks only the matched span (not the whole line), and masks multi-line PEM
|
|
51
|
-
private keys as a block. **No excerpt of a matched line is ever written to any artifact.**
|
|
52
|
-
- **Credential files are skipped by default** — `.env`, `*.pem`, `*.key`, `.npmrc`, `.netrc`,
|
|
53
|
-
`.git-credentials`, `id_rsa`, `.kube/config`, `*.tfstate`, … Opt back in with `includeSensitiveFiles`.
|
|
54
|
-
- **TypeScript AST extraction** — directives, imports, exports (including `export *` and anonymous
|
|
55
|
-
defaults), functions, classes, interfaces, types, enums, components, hooks, and route handlers.
|
|
56
|
-
- **Structured summaries** — JSON key shapes and Markdown headings, computed from redacted text.
|
|
57
|
-
- **Built for AI agents** — `codebase-snapshot describe --format json` returns a machine-readable
|
|
58
|
-
contract (workflow, every option and default, exit codes, presets, safety rules), and
|
|
59
|
-
`codebase-snapshot skill --install` writes the bundled agent skill into `AGENTS.md`,
|
|
60
|
-
`.claude/skills/` and `.cursor/rules/` so a zero-context agent discovers the tool
|
|
61
|
-
automatically. See [docs/agent.md](docs/agent.md).
|
|
62
|
-
- **Zero-config presets** — auto-detects Next.js, Vite, Node/Express/Nest, and plain TypeScript.
|
|
63
|
-
- **Real integrity validation** — verifies source hashes, every emitted `parts/*.md` against its recorded
|
|
64
|
-
`byteSize`/`sha256`, monolith artifacts, and the recorded configuration.
|
|
65
|
-
- **Safe output swapping** — the previous snapshot survives until the new one is fully in place, and
|
|
66
|
-
destructive `outDir`/`tmpDir` combinations are refused.
|
|
67
|
-
- **CLI & programmatic API** — `npx`, ESM, and CJS.
|
|
23
|
+
## Why
|
|
68
24
|
|
|
69
|
-
|
|
25
|
+
Feeding a real repository to a model is awkward: files are too big, context windows are too
|
|
26
|
+
small, and picking what matters by hand does not scale or repeat. `codebase-snapshot` does it
|
|
27
|
+
deterministically:
|
|
70
28
|
|
|
71
|
-
|
|
29
|
+
- **One file per part, never over budget.** `maxPartBytes` is a hard ceiling. A file bigger
|
|
30
|
+
than the budget becomes a head/tail preview rather than blowing the limit.
|
|
31
|
+
- **An index, not just text.** `manifest.json` lists every included file with its layer, kind,
|
|
32
|
+
language, part, hash and a structural summary — and every *excluded* file with the reason.
|
|
33
|
+
- **Provably current.** `validate` re-hashes the repository against the snapshot and exits
|
|
34
|
+
non-zero on any drift, so a pipeline can gate on context being fresh.
|
|
35
|
+
- **Safe by default.** Credential files are skipped unless asked for, secret-shaped strings are
|
|
36
|
+
redacted, and a mistyped output directory cannot delete source code.
|
|
37
|
+
- **Usable by agents, not just humans.** A machine-readable contract and an installable skill
|
|
38
|
+
let an agent with no prior knowledge drive the whole thing.
|
|
72
39
|
|
|
73
|
-
|
|
74
|
-
npx @ankurhalder/codebase-snapshot generate
|
|
75
|
-
```
|
|
76
|
-
|
|
77
|
-
Or install it in your project. Any npm-compatible client works — they all resolve the
|
|
78
|
-
same published package:
|
|
40
|
+
## Install
|
|
79
41
|
|
|
80
42
|
```bash
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
pnpm add -D @ankurhalder/codebase-snapshot
|
|
84
|
-
bun add -d @ankurhalder/codebase-snapshot
|
|
43
|
+
npx @ankurhalder/codebase-snapshot generate # no install, one-off
|
|
44
|
+
npm install -D @ankurhalder/codebase-snapshot # or add it to a project
|
|
85
45
|
```
|
|
86
46
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
"scripts": {
|
|
90
|
-
"snapshot": "codebase-snapshot generate",
|
|
91
|
-
"snapshot:validate": "codebase-snapshot validate"
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
```
|
|
47
|
+
Any npm-compatible client works — npm, yarn (classic and Berry with strict PnP), pnpm and bun —
|
|
48
|
+
each verified against the packed tarball before release. Requires **Node.js 18+**.
|
|
95
49
|
|
|
96
|
-
|
|
97
|
-
strict PnP. See [docs/install.md](docs/install.md) for global installs, version pinning,
|
|
98
|
-
and troubleshooting.
|
|
50
|
+
→ [Installation guide](docs/install.md)
|
|
99
51
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
## 🤖 For AI agents
|
|
103
|
-
|
|
104
|
-
An agent with **no prior knowledge** of this tool can drive it end to end. Two commands
|
|
105
|
-
exist for exactly that:
|
|
52
|
+
## Quick start
|
|
106
53
|
|
|
107
54
|
```bash
|
|
108
|
-
#
|
|
109
|
-
|
|
110
|
-
npx @ankurhalder/codebase-snapshot@latest describe --format json
|
|
55
|
+
# 1. Optional but recommended: detect the project and write a commented config
|
|
56
|
+
npx @ankurhalder/codebase-snapshot init --yes
|
|
111
57
|
|
|
112
|
-
#
|
|
113
|
-
|
|
114
|
-
npx @ankurhalder/codebase-snapshot@latest skill --install
|
|
115
|
-
```
|
|
116
|
-
|
|
117
|
-
The typical agent flow, once the contract is read:
|
|
58
|
+
# 2. Generate
|
|
59
|
+
npx @ankurhalder/codebase-snapshot generate
|
|
118
60
|
|
|
119
|
-
|
|
120
|
-
npx @ankurhalder/codebase-snapshot
|
|
121
|
-
npx @ankurhalder/codebase-snapshot@latest generate # write ./snapshot/
|
|
122
|
-
npx @ankurhalder/codebase-snapshot@latest validate # exit 0 = matches disk
|
|
61
|
+
# 3. Check it matches the files on disk (exit 0 = current)
|
|
62
|
+
npx @ankurhalder/codebase-snapshot validate
|
|
123
63
|
```
|
|
124
64
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
65
|
+
```
|
|
66
|
+
📸 Generating snapshot for: /Users/you/project
|
|
67
|
+
Branch: main | Part budget: 300 KB
|
|
68
|
+
|
|
69
|
+
✅ Snapshot generated in 0.14s:
|
|
70
|
+
- Tracked files: 128
|
|
71
|
+
- Total lines: 9,431
|
|
72
|
+
- Total size: 0.41 MB
|
|
73
|
+
- Parts written: 3 under snapshot/parts/
|
|
74
|
+
- Reports: snapshot/reports/ (project-tree, navigation, audit)
|
|
75
|
+
- Manifest: snapshot/manifest.json
|
|
76
|
+
- Fingerprint: e4607b570268c8def0911babbace97e4a0196d9eaf2cac22c8847500883d70aa
|
|
77
|
+
- Integrity: passed
|
|
78
|
+
```
|
|
131
79
|
|
|
132
|
-
|
|
80
|
+
The fingerprint is printed in full — all 64 hex characters, never elided — and it is the same
|
|
81
|
+
value as `manifest.fingerprint`.
|
|
133
82
|
|
|
134
|
-
##
|
|
83
|
+
## What you get
|
|
135
84
|
|
|
136
|
-
```
|
|
137
|
-
|
|
138
|
-
|
|
85
|
+
```
|
|
86
|
+
snapshot/
|
|
87
|
+
├── README.md human summary of this snapshot
|
|
88
|
+
├── manifest.json machine index: files, parts, hashes, config, skips
|
|
89
|
+
├── parts/part-001.md … the code, grouped and size-budgeted
|
|
90
|
+
└── reports/
|
|
91
|
+
├── project-tree.md directory tree of included files
|
|
92
|
+
├── navigation.md links between layers, kinds and parts
|
|
93
|
+
└── audit.md secrets, large files, parse diagnostics, git state
|
|
139
94
|
```
|
|
140
95
|
|
|
141
|
-
Every
|
|
142
|
-
payloads (`--format json`) go to **stdout**, so the output is safe to pipe into `jq`.
|
|
96
|
+
Every artifact can be turned off (`--skip-artifacts`, `--only-artifacts`, or the config).
|
|
143
97
|
|
|
144
|
-
|
|
98
|
+
→ [Snapshot output and manifest schema](docs/output.md)
|
|
145
99
|
|
|
146
|
-
|
|
147
|
-
| :--- | :--- |
|
|
148
|
-
| `generate` *(default)* | Generates snapshot parts, reports, tree, and manifest |
|
|
149
|
-
| `validate`, `check` | Verifies snapshot integrity against disk and against the recorded config |
|
|
150
|
-
| `init` | Creates a starter `snapshot.config.ts` (or `.mjs` on Node < 22.6) |
|
|
151
|
-
| `report` | Prints metrics and health audits |
|
|
152
|
-
| `explain <path>` | Explains how one path is treated: layer, kind, part, or why it was skipped |
|
|
153
|
-
| `diff <a> <b>` | Compares two snapshots file by file |
|
|
154
|
-
|
|
155
|
-
See [docs/configuration.md](docs/configuration.md) for the full option reference.
|
|
156
|
-
|
|
157
|
-
### Options
|
|
158
|
-
|
|
159
|
-
| Option | Description | Default |
|
|
160
|
-
| :--- | :--- | :--- |
|
|
161
|
-
| `--cwd <path>` | Target repository directory | `process.cwd()` |
|
|
162
|
-
| `--out-dir <path>` | Snapshot output directory | `snapshot` |
|
|
163
|
-
| `--include-monolith` | Also write `full-codebase.json` & `full-codebase.md` | `false` |
|
|
164
|
-
| `--max-monolith-bytes <n>` | Skip monolith artifacts above this size | unlimited |
|
|
165
|
-
| `--max-part-bytes <n>` | Hard byte budget per markdown part (min `4096`). Accepts units: `120k`, `1.5mb` | `307200` (300 KB) |
|
|
166
|
-
| `--large-file-bytes <n>` | Threshold for head/tail preview truncation. Accepts units | `204800` (200 KB) |
|
|
167
|
-
| `--include-sensitive-files` | Emit credential-bearing files (skipped by default) | `false` |
|
|
168
|
-
| `--skip-artifacts <names>` | Omit artifacts, comma-separated: `readme`, `manifest`, `parts`, `navigation`, `projectTree`, `audit`, `monolith` | everything on |
|
|
169
|
-
| `--only-artifacts <names>` | Write *only* the named artifacts. Cannot be combined with `--skip-artifacts` | — |
|
|
170
|
-
| `--format <text\|json>` | Output format | `text` |
|
|
171
|
-
| `--dry-run` | Compute the snapshot and print the plan without writing | `false` |
|
|
172
|
-
| `--watch` | Re-generate whenever the repository changes | `false` |
|
|
173
|
-
|
|
174
|
-
### Exit codes
|
|
175
|
-
|
|
176
|
-
`0` success · `1` drift detected or generation failed · `2` usage error (unknown flag, bad number, …).
|
|
177
|
-
|
|
178
|
-
Unknown flags and unknown commands are **rejected**; they do not fall through to `generate`.
|
|
100
|
+
## Supported projects
|
|
179
101
|
|
|
180
|
-
|
|
102
|
+
25 presets, detected automatically from the repository — each contributing layers, kinds,
|
|
103
|
+
ecosystem ignore patterns and a recommended part budget.
|
|
181
104
|
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
```typescript
|
|
193
|
-
import { defineConfig } from "@ankurhalder/codebase-snapshot";
|
|
194
|
-
|
|
195
|
-
export default defineConfig({
|
|
196
|
-
branch: "main",
|
|
197
|
-
outDir: "snapshot",
|
|
198
|
-
maxPartBytes: 300 * 1024,
|
|
199
|
-
largeFileBytes: 200 * 1024,
|
|
200
|
-
previewHeadLines: 80,
|
|
201
|
-
previewTailLines: 40,
|
|
202
|
-
|
|
203
|
-
// Credential files are excluded unless you opt in:
|
|
204
|
-
includeSensitiveFiles: false,
|
|
205
|
-
|
|
206
|
-
// Every artifact is generated by default; switch individual ones off here.
|
|
207
|
-
artifacts: {
|
|
208
|
-
audit: false, // skip reports/audit.md
|
|
209
|
-
projectTree: false, // skip reports/project-tree.md
|
|
210
|
-
},
|
|
211
|
-
|
|
212
|
-
// Allow-list: when non-empty, only matching files are candidates.
|
|
213
|
-
include: ["src/**", "packages/*/src/**"],
|
|
214
|
-
|
|
215
|
-
// Plain strings match a whole path segment sequence; globs are supported.
|
|
216
|
-
excludePatterns: ["tests/fixtures", "**/*.lock", "**/__snapshots__/**"],
|
|
217
|
-
|
|
218
|
-
// "src/app/**" matches src/app and below — not src/apple or src/application.
|
|
219
|
-
layers: [
|
|
220
|
-
{ name: "app", match: "src/app/**" },
|
|
221
|
-
{ name: "features", match: "src/features/**" },
|
|
222
|
-
{ name: "shared", match: "src/shared/**" },
|
|
223
|
-
{ name: "scripts", match: "scripts/**" },
|
|
224
|
-
],
|
|
225
|
-
kinds: [
|
|
226
|
-
{ kind: "route", match: (p) => p.includes("/api/") || p.endsWith("route.ts") },
|
|
227
|
-
{ kind: "component", match: (p) => p.endsWith(".tsx") },
|
|
228
|
-
{ kind: "hook", match: (p) => p.includes("/hooks/") },
|
|
229
|
-
],
|
|
230
|
-
secrets: {
|
|
231
|
-
// Strings are accepted here too (JSON configs can only express strings).
|
|
232
|
-
customPatterns: [{ rule: "internal-corp-token", pattern: /CORP-[A-Z0-9]{32}/ }],
|
|
233
|
-
},
|
|
234
|
-
});
|
|
235
|
-
```
|
|
105
|
+
| | | | |
|
|
106
|
+
| :--- | :--- | :--- | :--- |
|
|
107
|
+
| Next.js | Nuxt | SvelteKit | Remix |
|
|
108
|
+
| Astro | Angular | Solid | Vue + Vite |
|
|
109
|
+
| React + Vite | NestJS | Express / Fastify / Koa | Node library |
|
|
110
|
+
| Monorepo | Django | FastAPI / Flask | Python library |
|
|
111
|
+
| Go | Rust | Java / Spring | .NET |
|
|
112
|
+
| Laravel (PHP) | Rails (Ruby) | Terraform / Docker infra | Docs-only |
|
|
113
|
+
| generic fallback | | | |
|
|
236
114
|
|
|
237
|
-
|
|
115
|
+
Non-TypeScript languages get import/export/class/function summaries rather than being treated
|
|
116
|
+
as opaque text. Vue, Svelte and Astro script blocks go through the real TypeScript compiler.
|
|
117
|
+
Every summary is labelled `ast`, `structural` or `heuristic` so you know how much to trust it —
|
|
118
|
+
Python, for example, is a line-scan `heuristic`, while JSON and Markdown get `structural`
|
|
119
|
+
shapes.
|
|
238
120
|
|
|
239
|
-
|
|
240
|
-
pattern to enter the snapshot. `excludePatterns` then narrows what survived.
|
|
121
|
+
→ [Preset table and detection rules](docs/configuration.md#project-presets)
|
|
241
122
|
|
|
242
|
-
|
|
243
|
-
export default defineConfig({
|
|
244
|
-
include: ["src/**"], // only src/, everything else is out
|
|
245
|
-
excludePatterns: ["**/*.test.ts"], // …minus tests
|
|
246
|
-
});
|
|
247
|
-
```
|
|
123
|
+
## Commands
|
|
248
124
|
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
`
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
### Choosing which artifacts to emit
|
|
260
|
-
|
|
261
|
-
Everything is written by default. Each artifact can be switched off without
|
|
262
|
-
affecting the others, from a config file (`artifacts`) or the CLI
|
|
263
|
-
(`--skip-artifacts audit,navigation`):
|
|
264
|
-
|
|
265
|
-
| Artifact | Default | Notes |
|
|
266
|
-
| :--- | :--- | :--- |
|
|
267
|
-
| `readme` | on | `README.md` orientation page |
|
|
268
|
-
| `manifest` | on | `manifest.json` — **off breaks `validate` and `report`** |
|
|
269
|
-
| `parts` | on | `parts/part-XXX.md`, the code payload itself |
|
|
270
|
-
| `navigation` | on | `reports/navigation.md` — dangles if `parts` is off |
|
|
271
|
-
| `projectTree` | on | `reports/project-tree.md` |
|
|
272
|
-
| `audit` | on | `reports/audit.md` |
|
|
273
|
-
| `monolith` | off | `full-codebase.{json,md}`; also set by `includeMonolith` |
|
|
274
|
-
|
|
275
|
-
```typescript
|
|
276
|
-
export default defineConfig({
|
|
277
|
-
// Reports only — a security/health pass with no code payload:
|
|
278
|
-
artifacts: { parts: false, navigation: false },
|
|
279
|
-
});
|
|
280
|
-
```
|
|
125
|
+
| Command | Does |
|
|
126
|
+
| :--- | :--- |
|
|
127
|
+
| `generate` *(default)* | Write the snapshot. |
|
|
128
|
+
| `validate` / `check` | Compare the snapshot with the repository; exit `1` on drift. |
|
|
129
|
+
| `report` | Snapshot health, layer metrics, secret audit. |
|
|
130
|
+
| `init` | Interactive (or `--yes`) setup that writes a self-documenting config. |
|
|
131
|
+
| `explain <path>` | Why one path is included, which part it lands in, or why it was skipped. |
|
|
132
|
+
| `diff <a> <b>` | Compare two snapshots. |
|
|
133
|
+
| `describe` | The machine-readable contract (`--format json`). |
|
|
134
|
+
| `skill` | Print or install the agent skill. |
|
|
281
135
|
|
|
282
|
-
|
|
283
|
-
leave something enabled. Combinations that produce an unusable snapshot (a
|
|
284
|
-
disabled manifest, or navigation without parts) are recorded in
|
|
285
|
-
`manifest.warnings`. The selection is written into `manifest.config.artifacts`,
|
|
286
|
-
so changing it later is reported as configuration drift by `validate`.
|
|
136
|
+
Exit codes: `0` success · `1` drift or refused generation · `2` usage error.
|
|
287
137
|
|
|
288
|
-
|
|
138
|
+
→ [Full CLI reference](docs/cli.md)
|
|
289
139
|
|
|
290
|
-
|
|
291
|
-
- Multi-line `-----BEGIN … PRIVATE KEY-----` blocks are masked as a whole, including keys that were
|
|
292
|
-
cut off before their `END` marker.
|
|
293
|
-
- A rule supplied with the `/g` flag is compiled without it, so it cannot skip every other line.
|
|
294
|
-
- `reports/audit.md` lists *where* secrets were found (file, line, rule) and never reproduces the value.
|
|
140
|
+
## For AI agents
|
|
295
141
|
|
|
296
|
-
|
|
142
|
+
Everything an agent needs is available as data, and the tool can install its own skill:
|
|
297
143
|
|
|
298
|
-
|
|
144
|
+
```bash
|
|
145
|
+
# The contract: workflow, every option and default, exit codes, presets, safety rules
|
|
146
|
+
npx @ankurhalder/codebase-snapshot describe --format json
|
|
299
147
|
|
|
300
|
-
|
|
301
|
-
|
|
148
|
+
# Write the skill where agents look: AGENTS.md, .claude/skills/, .cursor/rules/
|
|
149
|
+
npx @ankurhalder/codebase-snapshot skill --install
|
|
150
|
+
```
|
|
302
151
|
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
const config = resolveConfig({ cwd: process.cwd() }, { maxPartBytes: 300 * 1024 });
|
|
306
|
-
const manifest = generateSnapshot(config);
|
|
152
|
+
An agent told only "use `npx @ankurhalder/codebase-snapshot`" can read the contract, follow its
|
|
153
|
+
ordered workflow, and produce a validated snapshot unaided — that path is covered by a test.
|
|
307
154
|
|
|
308
|
-
|
|
309
|
-
console.log(`Integrity: ${manifest.validation.status}`);
|
|
155
|
+
→ [Using this with an AI agent](docs/agent.md) · [AGENTS.md](AGENTS.md) · [llms.txt](llms.txt)
|
|
310
156
|
|
|
311
|
-
|
|
312
|
-
const plan = generateSnapshot(config, { dryRun: true });
|
|
157
|
+
## Configuration
|
|
313
158
|
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
159
|
+
`snapshot.config.ts` (or `.mjs`) is written by `init` with **every** setting at its current
|
|
160
|
+
value, commented and grouped, so it doubles as the reference. Deleting any line is safe: the
|
|
161
|
+
defaults are real.
|
|
162
|
+
|
|
163
|
+
```js
|
|
164
|
+
export default {
|
|
165
|
+
maxPartBytes: "120k", // hard budget per part
|
|
166
|
+
excludePatterns: ["vendor/**", "**/*.min.js"],
|
|
167
|
+
artifacts: { monolith: false }, // single-file output stays off
|
|
168
|
+
budgets: { default: "120k", byLayer: { docs: 40_000 } },
|
|
169
|
+
includeSensitiveFiles: false, // .env, *.pem … stay out
|
|
170
|
+
};
|
|
320
171
|
```
|
|
321
172
|
|
|
322
|
-
|
|
323
|
-
check for it, and `generateSnapshot`/`validateSnapshot` accept either a resolved config or a plain
|
|
324
|
-
`SnapshotConfig`.
|
|
173
|
+
→ [Configuration reference](docs/configuration.md)
|
|
325
174
|
|
|
326
|
-
|
|
175
|
+
## Programmatic API
|
|
327
176
|
|
|
328
|
-
|
|
177
|
+
```js
|
|
178
|
+
import { generateSnapshot, resolveConfig, validateSnapshot, loadConfigFile } from "@ankurhalder/codebase-snapshot";
|
|
329
179
|
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
├── manifest.json # Machine-readable metadata and AST registry
|
|
334
|
-
├── parts/
|
|
335
|
-
│ ├── part-001.md # Byte-bounded chunks with anchored code blocks
|
|
336
|
-
│ └── ...
|
|
337
|
-
└── reports/
|
|
338
|
-
├── navigation.md # File-to-part lookup index (anchors resolve)
|
|
339
|
-
├── project-tree.md # ASCII repository hierarchy
|
|
340
|
-
└── audit.md # Security findings, layer distributions, large files
|
|
180
|
+
const config = resolveConfig(await loadConfigFile(process.cwd()));
|
|
181
|
+
const manifest = generateSnapshot(config);
|
|
182
|
+
const validation = validateSnapshot(config);
|
|
341
183
|
```
|
|
342
184
|
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
`manifest.validation.status` is computed from a real pre-write integrity pass (part digests, byte
|
|
346
|
-
budgets, file-to-part assignment) — it is not a constant.
|
|
185
|
+
CommonJS works too (`require("@ankurhalder/codebase-snapshot")`), with type definitions for
|
|
186
|
+
both. The CLI and the API share one implementation, so anything the CLI does is available here.
|
|
347
187
|
|
|
348
|
-
|
|
188
|
+
## Documentation
|
|
349
189
|
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
Version 2.0.0 contains breaking changes, all in service of correctness:
|
|
353
|
-
|
|
354
|
-
| Change | Reason |
|
|
190
|
+
| | |
|
|
355
191
|
| :--- | :--- |
|
|
356
|
-
|
|
|
357
|
-
|
|
|
358
|
-
|
|
|
359
|
-
|
|
|
360
|
-
|
|
|
361
|
-
|
|
|
362
|
-
|
|
|
363
|
-
|
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
192
|
+
| [Installation](docs/install.md) | Every client, version pinning, agent skill install |
|
|
193
|
+
| [CLI reference](docs/cli.md) | Commands, options, exit codes, examples |
|
|
194
|
+
| [Configuration](docs/configuration.md) | Every setting, all 25 presets, budgets, hooks, secrets |
|
|
195
|
+
| [Snapshot output](docs/output.md) | Directory layout and the full manifest schema |
|
|
196
|
+
| [AI agents](docs/agent.md) | The contract, the skill, what an agent should avoid |
|
|
197
|
+
| [Troubleshooting](docs/troubleshooting.md) | Every message and what to do about it |
|
|
198
|
+
| [Changelog](CHANGELOG.md) | Release history and breaking changes |
|
|
199
|
+
| [Wiki](https://github.com/ankurhalder/codebase-snapshot/wiki) | Guides, recipes, FAQ |
|
|
200
|
+
|
|
201
|
+
## Safety
|
|
202
|
+
|
|
203
|
+
- **Credential files are excluded by default** — `.env`, `*.pem`, `*.key`, `.npmrc`, `.netrc`,
|
|
204
|
+
`.git-credentials`, `id_rsa`, `.kube/config`, `*.tfstate` — and listed in
|
|
205
|
+
`manifest.skipped[]` with the reason.
|
|
206
|
+
- **Secrets are redacted** inside ordinary files: only the matched span is masked, never the
|
|
207
|
+
whole line, and no excerpt reaches any artifact.
|
|
208
|
+
- **The output directory is owned by the tool.** Each run is written to a scratch directory and
|
|
209
|
+
swapped in atomically; the previous snapshot survives a failure.
|
|
210
|
+
- **It refuses to replace a directory it did not create**, so `--out-dir src` cannot destroy
|
|
211
|
+
source code.
|
|
212
|
+
|
|
213
|
+
## Contributing
|
|
214
|
+
|
|
215
|
+
Issues and pull requests are welcome — see [CONTRIBUTING.md](CONTRIBUTING.md) and the
|
|
216
|
+
[code of conduct](CODE_OF_CONDUCT.md). Security reports: [SECURITY.md](SECURITY.md).
|
|
217
|
+
|
|
218
|
+
## License
|
|
219
|
+
|
|
220
|
+
[MIT](LICENSE) © Ankur Halder
|