@ankurhalder/codebase-snapshot 2.2.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 CHANGED
@@ -1,368 +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** — `snap describe --format json` returns a machine-readable
58
- contract (workflow, every option and default, exit codes, presets, safety rules), and
59
- `snap 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
- Pin the tag (`@latest` or `@2`): a bare scoped spec can resolve to a placeholder manifest
126
- with no executable on some npm builds and exit 0 printing nothing.
127
-
128
- Details, including the contract schema and the skill's install targets, are in
129
- [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
+ ```
130
79
 
131
- ---
80
+ The fingerprint is printed in full — all 64 hex characters, never elided — and it is the same
81
+ value as `manifest.fingerprint`.
132
82
 
133
- ## 🛠️ CLI
83
+ ## What you get
134
84
 
135
- ```bash
136
- codebase-snapshot [command] [options]
137
- snap [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
138
94
  ```
139
95
 
140
- Every option accepts both `--opt value` and `--opt=value`. Human-readable progress goes to **stderr**;
141
- 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).
142
97
 
143
- ### Commands
98
+ → [Snapshot output and manifest schema](docs/output.md)
144
99
 
145
- | Command | Description |
146
- | :--- | :--- |
147
- | `generate` *(default)* | Generates snapshot parts, reports, tree, and manifest |
148
- | `validate`, `check` | Verifies snapshot integrity against disk and against the recorded config |
149
- | `init` | Creates a starter `snapshot.config.ts` (or `.mjs` on Node < 22.6) |
150
- | `report` | Prints metrics and health audits |
151
- | `explain <path>` | Explains how one path is treated: layer, kind, part, or why it was skipped |
152
- | `diff <a> <b>` | Compares two snapshots file by file |
153
-
154
- See [docs/configuration.md](docs/configuration.md) for the full option reference.
155
-
156
- ### Options
157
-
158
- | Option | Description | Default |
159
- | :--- | :--- | :--- |
160
- | `--cwd <path>` | Target repository directory | `process.cwd()` |
161
- | `--out-dir <path>` | Snapshot output directory | `snapshot` |
162
- | `--include-monolith` | Also write `full-codebase.json` & `full-codebase.md` | `false` |
163
- | `--max-monolith-bytes <n>` | Skip monolith artifacts above this size | unlimited |
164
- | `--max-part-bytes <n>` | Hard byte budget per markdown part (min `4096`). Accepts units: `120k`, `1.5mb` | `307200` (300 KB) |
165
- | `--large-file-bytes <n>` | Threshold for head/tail preview truncation. Accepts units | `204800` (200 KB) |
166
- | `--include-sensitive-files` | Emit credential-bearing files (skipped by default) | `false` |
167
- | `--skip-artifacts <names>` | Omit artifacts, comma-separated: `readme`, `manifest`, `parts`, `navigation`, `projectTree`, `audit`, `monolith` | everything on |
168
- | `--only-artifacts <names>` | Write *only* the named artifacts. Cannot be combined with `--skip-artifacts` | — |
169
- | `--format <text\|json>` | Output format | `text` |
170
- | `--dry-run` | Compute the snapshot and print the plan without writing | `false` |
171
- | `--watch` | Re-generate whenever the repository changes | `false` |
172
-
173
- ### Exit codes
174
-
175
- `0` success · `1` drift detected or generation failed · `2` usage error (unknown flag, bad number, …).
176
-
177
- Unknown flags and unknown commands are **rejected**; they do not fall through to `generate`.
100
+ ## Supported projects
178
101
 
179
- ---
102
+ 25 presets, detected automatically from the repository — each contributing layers, kinds,
103
+ ecosystem ignore patterns and a recommended part budget.
180
104
 
181
- ## ⚙️ Configuration
182
-
183
- Run `npx @ankurhalder/codebase-snapshot init`. Supported filenames, in order:
184
- `snapshot.config.ts`, `.js`, `.mjs`, `.cjs`, `.json`, `.snapshotrc.json`, `.snapshotrc`, and a `"snapshot"`
185
- key in `package.json`.
186
-
187
- > **Node note:** a `.ts` config is only importable natively from Node **22.6+**. `init` writes `.mjs`
188
- > instead on older Node versions, and a config that cannot be loaded is reported on stderr rather than
189
- > being silently ignored.
190
-
191
- ```typescript
192
- import { defineConfig } from "@ankurhalder/codebase-snapshot";
193
-
194
- export default defineConfig({
195
- branch: "main",
196
- outDir: "snapshot",
197
- maxPartBytes: 300 * 1024,
198
- largeFileBytes: 200 * 1024,
199
- previewHeadLines: 80,
200
- previewTailLines: 40,
201
-
202
- // Credential files are excluded unless you opt in:
203
- includeSensitiveFiles: false,
204
-
205
- // Every artifact is generated by default; switch individual ones off here.
206
- artifacts: {
207
- audit: false, // skip reports/audit.md
208
- projectTree: false, // skip reports/project-tree.md
209
- },
210
-
211
- // Allow-list: when non-empty, only matching files are candidates.
212
- include: ["src/**", "packages/*/src/**"],
213
-
214
- // Plain strings match a whole path segment sequence; globs are supported.
215
- excludePatterns: ["tests/fixtures", "**/*.lock", "**/__snapshots__/**"],
216
-
217
- // "src/app/**" matches src/app and below — not src/apple or src/application.
218
- layers: [
219
- { name: "app", match: "src/app/**" },
220
- { name: "features", match: "src/features/**" },
221
- { name: "shared", match: "src/shared/**" },
222
- { name: "scripts", match: "scripts/**" },
223
- ],
224
- kinds: [
225
- { kind: "route", match: (p) => p.includes("/api/") || p.endsWith("route.ts") },
226
- { kind: "component", match: (p) => p.endsWith(".tsx") },
227
- { kind: "hook", match: (p) => p.includes("/hooks/") },
228
- ],
229
- secrets: {
230
- // Strings are accepted here too (JSON configs can only express strings).
231
- customPatterns: [{ rule: "internal-corp-token", pattern: /CORP-[A-Z0-9]{32}/ }],
232
- },
233
- });
234
- ```
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 | | | |
235
114
 
236
- ### 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.
237
120
 
238
- `include` is an allow-list: when it is non-empty, a file must match at least one
239
- pattern to enter the snapshot. `excludePatterns` then narrows what survived.
121
+ → [Preset table and detection rules](docs/configuration.md#project-presets)
240
122
 
241
- ```typescript
242
- export default defineConfig({
243
- include: ["src/**"], // only src/, everything else is out
244
- excludePatterns: ["**/*.test.ts"], // …minus tests
245
- });
246
- ```
123
+ ## Commands
247
124
 
248
- Both accept globs (`**`, `*`, `?`) or plain strings, where a plain string matches
249
- a whole path segment sequence — `"docs"` matches `docs/a.md` and `src/docs/b.md`
250
- but not `docsite/c.md`.
251
-
252
- Files dropped by either list are recorded in `manifest.skipped` with
253
- `reason: "excluded"` and the pattern that removed them, so an omission is always
254
- explicable. The effective `include` list is written into
255
- `manifest.config.include`, so changing it later is reported as configuration
256
- drift by `validate`.
257
-
258
- ### Choosing which artifacts to emit
259
-
260
- Everything is written by default. Each artifact can be switched off without
261
- affecting the others, from a config file (`artifacts`) or the CLI
262
- (`--skip-artifacts audit,navigation`):
263
-
264
- | Artifact | Default | Notes |
265
- | :--- | :--- | :--- |
266
- | `readme` | on | `README.md` orientation page |
267
- | `manifest` | on | `manifest.json` — **off breaks `validate` and `report`** |
268
- | `parts` | on | `parts/part-XXX.md`, the code payload itself |
269
- | `navigation` | on | `reports/navigation.md` — dangles if `parts` is off |
270
- | `projectTree` | on | `reports/project-tree.md` |
271
- | `audit` | on | `reports/audit.md` |
272
- | `monolith` | off | `full-codebase.{json,md}`; also set by `includeMonolith` |
273
-
274
- ```typescript
275
- export default defineConfig({
276
- // Reports only — a security/health pass with no code payload:
277
- artifacts: { parts: false, navigation: false },
278
- });
279
- ```
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. |
280
135
 
281
- Unknown artifact names are **rejected**, not ignored, so a typo cannot quietly
282
- leave something enabled. Combinations that produce an unusable snapshot (a
283
- disabled manifest, or navigation without parts) are recorded in
284
- `manifest.warnings`. The selection is written into `manifest.config.artifacts`,
285
- so changing it later is reported as configuration drift by `validate`.
136
+ Exit codes: `0` success · `1` drift or refused generation · `2` usage error.
286
137
 
287
- ### Redaction behaviour
138
+ → [Full CLI reference](docs/cli.md)
288
139
 
289
- - Only the matched substring is replaced; the rest of the line survives.
290
- - Multi-line `-----BEGIN … PRIVATE KEY-----` blocks are masked as a whole, including keys that were
291
- cut off before their `END` marker.
292
- - A rule supplied with the `/g` flag is compiled without it, so it cannot skip every other line.
293
- - `reports/audit.md` lists *where* secrets were found (file, line, rule) and never reproduces the value.
140
+ ## For AI agents
294
141
 
295
- ---
142
+ Everything an agent needs is available as data, and the tool can install its own skill:
296
143
 
297
- ## 📦 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
298
147
 
299
- ```typescript
300
- 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
+ ```
301
151
 
302
- // `generateSnapshot` is synchronous — it does blocking file I/O by design.
303
- // (`generateSnapshotAsync` is provided if you prefer an async call site.)
304
- const config = resolveConfig({ cwd: process.cwd() }, { maxPartBytes: 300 * 1024 });
305
- 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.
306
154
 
307
- console.log(`Generated ${manifest.counts.partsCount} parts for ${manifest.counts.totalFiles} files.`);
308
- console.log(`Integrity: ${manifest.validation.status}`);
155
+ → [Using this with an AI agent](docs/agent.md) · [AGENTS.md](AGENTS.md) · [llms.txt](llms.txt)
309
156
 
310
- // Dry run: compute everything, write nothing.
311
- const plan = generateSnapshot(config, { dryRun: true });
157
+ ## Configuration
312
158
 
313
- // Validate against disk
314
- const validation = validateSnapshot(config);
315
- if (!validation.valid) {
316
- console.error("Drift detected:", validation.errors);
317
- console.error(validation.drift); // hashMismatches, partIssues, configMismatches, …
318
- }
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
+ };
319
171
  ```
320
172
 
321
- `resolveConfig(userConfig, cliOptions?, baseDir?)` brands its result; `isResolvedConfig(value)` lets you
322
- check for it, and `generateSnapshot`/`validateSnapshot` accept either a resolved config or a plain
323
- `SnapshotConfig`.
173
+ → [Configuration reference](docs/configuration.md)
324
174
 
325
- ---
175
+ ## Programmatic API
326
176
 
327
- ## 📁 Snapshot Output
177
+ ```js
178
+ import { generateSnapshot, resolveConfig, validateSnapshot, loadConfigFile } from "@ankurhalder/codebase-snapshot";
328
179
 
329
- ```text
330
- snapshot/
331
- ├── README.md # Overview for LLMs and developers
332
- ├── manifest.json # Machine-readable metadata and AST registry
333
- ├── parts/
334
- │ ├── part-001.md # Byte-bounded chunks with anchored code blocks
335
- │ └── ...
336
- └── reports/
337
- ├── navigation.md # File-to-part lookup index (anchors resolve)
338
- ├── project-tree.md # ASCII repository hierarchy
339
- └── 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);
340
183
  ```
341
184
 
342
- `manifest.json` records the effective configuration (budgets, preview sizes, excludes,
343
- `includeSensitiveFiles`), so `validate` can detect configuration drift as well as code drift.
344
- `manifest.validation.status` is computed from a real pre-write integrity pass (part digests, byte
345
- 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.
346
187
 
347
- ---
188
+ ## Documentation
348
189
 
349
- ## 🔄 Upgrading from 1.x
350
-
351
- Version 2.0.0 contains breaking changes, all in service of correctness:
352
-
353
- | Change | Reason |
190
+ | | |
354
191
  | :--- | :--- |
355
- | `generateSnapshot()` is synchronous | It never awaited anything; the `async` signature only promised concurrency it did not have. `await generateSnapshot(...)` still works; `generateSnapshotAsync` is available. |
356
- | Manifest `schemaVersion` is `3.0.0` | The shape changed materially (below). |
357
- | 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`. |
358
- | `totals.summaryOnlyFiles` → `totals.previewFiles` | The old name claimed more than the value meant. |
359
- | `SecretFinding.snippet` removed | It carried the raw matched source line — the vector that leaked secrets into `reports/audit.md`. |
360
- | Credential files skipped by default | A private key or registry token cannot be reliably masked by a regex; opt in with `includeSensitiveFiles`. |
361
- | `monolithContent` option removed, `--force` removed | Never implemented / never read. |
362
- | `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. |
363
-
364
- ---
365
-
366
- ## 📄 License
367
-
368
- 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