@ankurhalder/codebase-snapshot 3.0.0 → 4.0.1

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 CHANGED
@@ -1,369 +1,220 @@
1
- # @ankurhalder/codebase-snapshot
1
+ # codebase-snapshot
2
2
 
3
- > LLM codebase snapshot generator, auditor, and AST partitioner for modern full-stack repositories.
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
  [![npm version](https://img.shields.io/npm/v/@ankurhalder/codebase-snapshot.svg)](https://www.npmjs.com/package/@ankurhalder/codebase-snapshot)
6
- [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
7
-
8
- `@ankurhalder/codebase-snapshot` inspects your codebase, redacts sensitive credentials, parses TypeScript
9
- AST structures, and partitions your repository into **hard byte-bounded**, LLM-ready markdown chunks
10
- (`parts/part-XXX.md`) accompanied by navigation indexes, a directory tree, and a health audit.
11
-
12
- ---
13
-
14
- ## ⚡ Set up a repository
7
+ [![npm downloads](https://img.shields.io/npm/dw/@ankurhalder/codebase-snapshot.svg)](https://www.npmjs.com/package/@ankurhalder/codebase-snapshot)
8
+ [![license](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
9
+ [![node](https://img.shields.io/badge/node-%3E%3D18-brightgreen.svg)](https://nodejs.org)
15
10
 
16
11
  ```bash
17
- npm create codebase-snapshot
12
+ npx @ankurhalder/codebase-snapshot generate
18
13
  ```
19
14
 
20
- Detects the project type, asks a handful of questions with real defaults, and
21
- writes a `snapshot.config.mjs` that lists **every setting at its default** — so
22
- the config doubles as the documentation. Works for 25 project shapes including
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
- ```bash
29
- npx @ankurhalder/codebase-snapshot init --preset react-vite --max-part-bytes 120k --yes
30
- ```
19
+ ![How it works](https://raw.githubusercontent.com/ankurhalder/codebase-snapshot/main/docs/how-it-works.svg)
31
20
 
32
21
  ---
33
22
 
34
- ## ✨ Features
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
- ## 🚀 Quick Start
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
- ```bash
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
- npm install -D @ankurhalder/codebase-snapshot
82
- yarn add -D @ankurhalder/codebase-snapshot
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
- ```json
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
- Requires **Node.js 18+**. Every client above is verified in CI, including yarn Berry with
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
- # Machine-readable contract: workflow, every option + default, exit codes,
109
- # presets, safety rules and troubleshooting — as JSON on stdout.
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
- # Write the bundled agent skill where agents look for it:
113
- # AGENTS.md, .claude/skills/codebase-snapshot/SKILL.md, .cursor/rules/
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
- ```bash
120
- npx @ankurhalder/codebase-snapshot@latest init --yes # detect the project, write config
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
- The bare form works too — `npx @ankurhalder/codebase-snapshot generate` — because the
126
- package ships exactly one executable, which is what lets npm resolve it. Pin `@latest`
127
- (or `@3`) when you need the same build on every machine.
128
-
129
- Details, including the contract schema and the skill's install targets, are in
130
- [docs/agent.md](docs/agent.md).
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
- ## 🛠️ CLI
83
+ ## What you get
135
84
 
136
- ```bash
137
- codebase-snapshot [command] [options]
138
- codebase-snapshot [command] [options]
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 option accepts both `--opt value` and `--opt=value`. Human-readable progress goes to **stderr**;
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
- ### Commands
98
+ → [Snapshot output and manifest schema](docs/output.md)
145
99
 
146
- | Command | Description |
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
- ## ⚙️ Configuration
183
-
184
- Run `npx @ankurhalder/codebase-snapshot init`. Supported filenames, in order:
185
- `snapshot.config.ts`, `.js`, `.mjs`, `.cjs`, `.json`, `.snapshotrc.json`, `.snapshotrc`, and a `"snapshot"`
186
- key in `package.json`.
187
-
188
- > **Node note:** a `.ts` config is only importable natively from Node **22.6+**. `init` writes `.mjs`
189
- > instead on older Node versions, and a config that cannot be loaded is reported on stderr rather than
190
- > being silently ignored.
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
- ### Scoping with `include` / `excludePatterns`
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
- `include` is an allow-list: when it is non-empty, a file must match at least one
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
- ```typescript
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
- Both accept globs (`**`, `*`, `?`) or plain strings, where a plain string matches
250
- a whole path segment sequence — `"docs"` matches `docs/a.md` and `src/docs/b.md`
251
- but not `docsite/c.md`.
252
-
253
- Files dropped by either list are recorded in `manifest.skipped` with
254
- `reason: "excluded"` and the pattern that removed them, so an omission is always
255
- explicable. The effective `include` list is written into
256
- `manifest.config.include`, so changing it later is reported as configuration
257
- drift by `validate`.
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
- Unknown artifact names are **rejected**, not ignored, so a typo cannot quietly
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
- ### Redaction behaviour
138
+ → [Full CLI reference](docs/cli.md)
289
139
 
290
- - Only the matched substring is replaced; the rest of the line survives.
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
- ## 📦 Programmatic API
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
- ```typescript
301
- import { generateSnapshot, resolveConfig, validateSnapshot } from "@ankurhalder/codebase-snapshot";
148
+ # Write the skill where agents look: AGENTS.md, .claude/skills/, .cursor/rules/
149
+ npx @ankurhalder/codebase-snapshot skill --install
150
+ ```
302
151
 
303
- // `generateSnapshot` is synchronous — it does blocking file I/O by design.
304
- // (`generateSnapshotAsync` is provided if you prefer an async call site.)
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
- console.log(`Generated ${manifest.counts.partsCount} parts for ${manifest.counts.totalFiles} files.`);
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
- // Dry run: compute everything, write nothing.
312
- const plan = generateSnapshot(config, { dryRun: true });
157
+ ## Configuration
313
158
 
314
- // Validate against disk
315
- const validation = validateSnapshot(config);
316
- if (!validation.valid) {
317
- console.error("Drift detected:", validation.errors);
318
- console.error(validation.drift); // hashMismatches, partIssues, configMismatches, …
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
- `resolveConfig(userConfig, cliOptions?, baseDir?)` brands its result; `isResolvedConfig(value)` lets you
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
- ## 📁 Snapshot Output
177
+ ```js
178
+ import { generateSnapshot, resolveConfig, validateSnapshot, loadConfigFile } from "@ankurhalder/codebase-snapshot";
329
179
 
330
- ```text
331
- snapshot/
332
- ├── README.md # Overview for LLMs and developers
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
- `manifest.json` records the effective configuration (budgets, preview sizes, excludes,
344
- `includeSensitiveFiles`), so `validate` can detect configuration drift as well as code drift.
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
- ## 🔄 Upgrading from 1.x
351
-
352
- Version 2.0.0 contains breaking changes, all in service of correctness:
353
-
354
- | Change | Reason |
190
+ | | |
355
191
  | :--- | :--- |
356
- | `generateSnapshot()` is synchronous | It never awaited anything; the `async` signature only promised concurrency it did not have. `await generateSnapshot(...)` still works; `generateSnapshotAsync` is available. |
357
- | Manifest `schemaVersion` is `3.0.0` | The shape changed materially (below). |
358
- | Removed duplicate fields: `path`, `bytes`, `sha256` (on entries), `PartMetadata.bytes`, `PartMetadata.files`, `contentFingerprint`, `generator.script` | Each was a permanent alias of a canonical field that could only ever agree. Use `relativePath`, `sizeBytes`, `hashSha256`, `byteSize`, `includedFiles[].relativePath`. |
359
- | `totals.summaryOnlyFiles` → `totals.previewFiles` | The old name claimed more than the value meant. |
360
- | `SecretFinding.snippet` removed | It carried the raw matched source line — the vector that leaked secrets into `reports/audit.md`. |
361
- | Credential files skipped by default | A private key or registry token cannot be reliably masked by a regex; opt in with `includeSensitiveFiles`. |
362
- | `monolithContent` option removed, `--force` removed | Never implemented / never read. |
363
- | `dist/cli.js` is no longer the executable | The bin is now `dist/bin.js`; `./cli` is a side-effect-free module usable from both ESM and CJS. |
364
-
365
- ---
366
-
367
- ## 📄 License
368
-
369
- MIT © [Ankur Halder](https://github.com/ankurhalder)
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