@ankurhalder/codebase-snapshot 2.1.1 → 3.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/dist/index.cjs CHANGED
@@ -3943,11 +3943,12 @@ var PRESET_NAMES = [
3943
3943
  "java-spring \xB7 dotnet \xB7 php-laravel \xB7 ruby-rails",
3944
3944
  "monorepo \xB7 docs \xB7 infra \xB7 generic"
3945
3945
  ];
3946
+ var CONFIG_HEADER = `// Generated by codebase-snapshot. A plain object on purpose: this file must load
3947
+ // even when the package itself is only run through npx.
3948
+ `;
3946
3949
  function renderConfig(answers) {
3947
3950
  const { artifacts } = answers;
3948
- return `import { defineConfig } from "@ankurhalder/codebase-snapshot";
3949
-
3950
- export default defineConfig({
3951
+ return `${CONFIG_HEADER}export default {
3951
3952
  // \u2500\u2500 Project \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500
3952
3953
  // Which project shape to use. Detected from the repo when omitted.
3953
3954
  // ${PRESET_NAMES.join("\n // ")}
@@ -4016,7 +4017,7 @@ export default defineConfig({
4016
4017
  // \u2500\u2500 Advanced \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500
4017
4018
  // afterGenerate: (manifest) => { /* write your own artifact */ }
4018
4019
  hooks: {},
4019
- });
4020
+ };
4020
4021
  `;
4021
4022
  }
4022
4023
  function renderMinimalConfig(answers) {
@@ -4044,16 +4045,12 @@ ${entries},
4044
4045
  },`);
4045
4046
  }
4046
4047
  if (lines.length === 0) {
4047
- return `import { defineConfig } from "@ankurhalder/codebase-snapshot";
4048
-
4049
- export default defineConfig({});
4048
+ return `${CONFIG_HEADER}export default {};
4050
4049
  `;
4051
4050
  }
4052
- return `import { defineConfig } from "@ankurhalder/codebase-snapshot";
4053
-
4054
- export default defineConfig({
4051
+ return `${CONFIG_HEADER}export default {
4055
4052
  ${lines.join("\n")}
4056
- });
4053
+ };
4057
4054
  `;
4058
4055
  }
4059
4056
  var PromptCancelled = class extends Error {
@@ -4314,6 +4311,17 @@ var CONFIG_CANDIDATES = [
4314
4311
  ".snapshotrc.json",
4315
4312
  ".snapshotrc"
4316
4313
  ];
4314
+ function chooseConfigFileName(cwd) {
4315
+ if (!supportsTypeScriptImports()) return "snapshot.config.mjs";
4316
+ const pkgPath = path10__namespace.join(cwd, "package.json");
4317
+ if (!fs9__namespace.existsSync(pkgPath)) return "snapshot.config.mjs";
4318
+ try {
4319
+ const parsed = JSON.parse(fs9__namespace.readFileSync(pkgPath, "utf8"));
4320
+ return parsed.type === "module" ? "snapshot.config.ts" : "snapshot.config.mjs";
4321
+ } catch {
4322
+ return "snapshot.config.mjs";
4323
+ }
4324
+ }
4317
4325
  var SIZE_CHOICES = [
4318
4326
  { value: "60k", label: "Small", hint: "60 KB \xB7 ~15k tokens \xB7 tight context windows" },
4319
4327
  { value: "120k", label: "Medium", hint: "120 KB \xB7 ~30k tokens \xB7 recommended" },
@@ -4519,7 +4527,7 @@ async function runInit(options) {
4519
4527
  if (!proceed) throw new PromptCancelled();
4520
4528
  }
4521
4529
  const configText = options.minimal ? renderMinimalConfig(answers) : renderConfig(answers);
4522
- const configName = supportsTypeScriptImports() ? "snapshot.config.ts" : "snapshot.config.mjs";
4530
+ const configName = chooseConfigFileName(options.cwd);
4523
4531
  const configPath = path10__namespace.join(options.cwd, configName);
4524
4532
  if (options.dryRun) {
4525
4533
  return {
@@ -4557,7 +4565,7 @@ async function runInit(options) {
4557
4565
 
4558
4566
  // src/index.ts
4559
4567
  var GENERATOR_NAME = "@ankurhalder/codebase-snapshot";
4560
- var GENERATOR_VERSION = "2.1.1";
4568
+ var GENERATOR_VERSION = "3.0.0";
4561
4569
  var SCHEMA_VERSION = "3.0.0";
4562
4570
  function sha256Hex2(input) {
4563
4571
  return crypto__namespace.createHash("sha256").update(input).digest("hex");
package/dist/index.d.cts CHANGED
@@ -497,7 +497,7 @@ declare function matchesExclude(relativePath: string, pattern: string): boolean;
497
497
  declare function collectFiles(cwd: string, options?: CollectOptions): CollectResult;
498
498
 
499
499
  declare const GENERATOR_NAME = "@ankurhalder/codebase-snapshot";
500
- declare const GENERATOR_VERSION = "2.1.1";
500
+ declare const GENERATOR_VERSION = "3.0.0";
501
501
  declare const SCHEMA_VERSION = "3.0.0";
502
502
  interface GenerateOptions {
503
503
  /** Compute the full manifest but write nothing to disk. */
package/dist/index.d.ts CHANGED
@@ -497,7 +497,7 @@ declare function matchesExclude(relativePath: string, pattern: string): boolean;
497
497
  declare function collectFiles(cwd: string, options?: CollectOptions): CollectResult;
498
498
 
499
499
  declare const GENERATOR_NAME = "@ankurhalder/codebase-snapshot";
500
- declare const GENERATOR_VERSION = "2.1.1";
500
+ declare const GENERATOR_VERSION = "3.0.0";
501
501
  declare const SCHEMA_VERSION = "3.0.0";
502
502
  interface GenerateOptions {
503
503
  /** Compute the full manifest but write nothing to disk. */
package/dist/index.js CHANGED
@@ -1,3 +1,3 @@
1
- export { ARTIFACT_NAMES, DEFAULT_ANSWERS, DEFAULT_SECRET_PATTERNS, GENERATOR_NAME, GENERATOR_VERSION, LANGUAGE_PROFILES, MIN_MAX_PART_BYTES, PRESETS, PromptCancelled, SCHEMA_VERSION, anchorForPath, assertReplaceable, assertUsableConfigInput, collectFiles, compareManifests, countLines, defineConfig, detectLanguage, detectPreset, explainPath, fenceForContent, generateProjectTree, generateSnapshot, generateSnapshotAsync, getPreset, globToRegExp, isBinaryBuffer, isBinaryExtension, isBinaryFile, isInteractive, isResolvedConfig, isSensitivePath, listPresetNames, loadConfigFile, loadConfigFileDetailed, loadManifest, markResolvedConfig, matchRule, matchesExclude, normalizeResolvedConfig, parseByteSize, partitionFiles, profileForPath, renderConfig, renderDiffText, renderExplainText, renderMinimalConfig, renumberParts, resolveConfig, resolveSafeOutputDirs, runInit, scanAndRedactSecrets, stripJsonComments, summarizeJson, summarizeMarkdown, summarizeTypeScriptSource, summarizeWithProfile, supportsTypeScriptImports, truncatePreview, truncateToBytes, validateSnapshot } from './chunk-SUOJL5EX.js';
1
+ export { ARTIFACT_NAMES, DEFAULT_ANSWERS, DEFAULT_SECRET_PATTERNS, GENERATOR_NAME, GENERATOR_VERSION, LANGUAGE_PROFILES, MIN_MAX_PART_BYTES, PRESETS, PromptCancelled, SCHEMA_VERSION, anchorForPath, assertReplaceable, assertUsableConfigInput, collectFiles, compareManifests, countLines, defineConfig, detectLanguage, detectPreset, explainPath, fenceForContent, generateProjectTree, generateSnapshot, generateSnapshotAsync, getPreset, globToRegExp, isBinaryBuffer, isBinaryExtension, isBinaryFile, isInteractive, isResolvedConfig, isSensitivePath, listPresetNames, loadConfigFile, loadConfigFileDetailed, loadManifest, markResolvedConfig, matchRule, matchesExclude, normalizeResolvedConfig, parseByteSize, partitionFiles, profileForPath, renderConfig, renderDiffText, renderExplainText, renderMinimalConfig, renumberParts, resolveConfig, resolveSafeOutputDirs, runInit, scanAndRedactSecrets, stripJsonComments, summarizeJson, summarizeMarkdown, summarizeTypeScriptSource, summarizeWithProfile, supportsTypeScriptImports, truncatePreview, truncateToBytes, validateSnapshot } from './chunk-5B4UVQLR.js';
2
2
  //# sourceMappingURL=index.js.map
3
3
  //# sourceMappingURL=index.js.map
package/docs/agent.md ADDED
@@ -0,0 +1,80 @@
1
+ # Using this with an AI agent
2
+
3
+ The package ships two things that make it usable by an agent that has never heard of it:
4
+ a **machine-readable contract** and a **bundled skill**.
5
+
6
+ Nothing here needs to be installed globally, and no prior knowledge of the tool is
7
+ required.
8
+
9
+ ## The three commands an agent needs
10
+
11
+ ```bash
12
+ # 1. Read the contract. This is the machine-readable replacement for --help.
13
+ npx @ankurhalder/codebase-snapshot@latest describe --format json
14
+
15
+ # 2. Write a commented config that lists every setting (non-interactive).
16
+ npx @ankurhalder/codebase-snapshot@latest init --yes
17
+
18
+ # 3. Generate and verify.
19
+ npx @ankurhalder/codebase-snapshot@latest generate
20
+ npx @ankurhalder/codebase-snapshot@latest validate
21
+ ```
22
+
23
+ `describe` returns the invocation that works, an ordered `workflow` array, every command,
24
+ every option with its default, the exit-code contract, all 25 presets, the artifact list,
25
+ the config file names, the output layout, safety rules and a troubleshooting table — all
26
+ as JSON on stdout.
27
+
28
+ **Always pin the tag** (`@latest` or `@2`). A bare scoped spec can resolve to a bin-less
29
+ placeholder manifest on some npm builds and exit 0 printing nothing; the pinned form
30
+ cannot.
31
+
32
+ ## The skill
33
+
34
+ ```bash
35
+ npx @ankurhalder/codebase-snapshot@latest skill # print it (stdout)
36
+ npx @ankurhalder/codebase-snapshot@latest skill --install # write it into the repo
37
+ ```
38
+
39
+ Printing goes to stdout deliberately, so it can be redirected:
40
+
41
+ ```bash
42
+ npx @ankurhalder/codebase-snapshot@latest skill > SKILL.md
43
+ ```
44
+
45
+ `--install` writes the same skill to every location agents look at by default:
46
+
47
+ | Target | Path | Read by |
48
+ | :--- | :--- | :--- |
49
+ | `agents` | `AGENTS.md` (a marked section) | most tools, by convention |
50
+ | `claude` | `.claude/skills/codebase-snapshot/SKILL.md` | Claude Code auto-discovery |
51
+ | `cursor` | `.cursor/rules/codebase-snapshot.mdc` | Cursor rules |
52
+
53
+ ```bash
54
+ skill --install --target claude # one location
55
+ skill --install # all three (default)
56
+ ```
57
+
58
+ The install is **idempotent and non-destructive**: re-running replaces only the block
59
+ between `<!-- codebase-snapshot:skill:start -->` and
60
+ `<!-- codebase-snapshot:skill:end -->`, so an `AGENTS.md` that already documents your
61
+ conventions keeps them. `--format json` reports what was created, updated or unchanged.
62
+
63
+ `codebase-snapshot init` prints a reminder about this; it never installs the skill on its own.
64
+
65
+ ## Why both a contract and a skill
66
+
67
+ The contract is for **doing** — it is the data an agent needs to pick correct commands and
68
+ options, and it is asserted against the real defaults in the test suite so it cannot drift
69
+ into lying.
70
+
71
+ The skill is for **knowing when to act** — it carries the trigger conditions, the ordered
72
+ workflow, and the surprises (sensitive files excluded by default, secrets redacted, the
73
+ output directory being tool-owned) that an agent cannot infer from a schema.
74
+
75
+ ## Keeping the contract honest
76
+
77
+ `describe` is generated from the same code the CLI runs — the preset list, artifact names,
78
+ schema version and generator version are read directly, and a test compares its documented
79
+ defaults against a real `generate --dry-run` manifest. If a default changes, the test fails
80
+ rather than the contract silently misleading an agent.
@@ -256,7 +256,7 @@ marker written before any artifact, not by the set of filenames present, so
256
256
  custom artifacts never look like someone else's data.
257
257
 
258
258
  Note that a hook runs in the **process** working directory, so with
259
- `snap --cwd elsewhere` a relative path resolves against your shell's directory,
259
+ `codebase-snapshot --cwd elsewhere` a relative path resolves against your shell's directory,
260
260
  not the target repo. Use the absolute paths on `manifest` (or resolve against
261
261
  `outDir` yourself) when passing `--cwd`.
262
262
 
@@ -276,7 +276,7 @@ not the target repo. Use the absolute paths on `manifest` (or resolve against
276
276
  ## `explain`
277
277
 
278
278
  ```
279
- $ snap explain src/app/page.tsx
279
+ $ codebase-snapshot explain src/app/page.tsx
280
280
 
281
281
  src/app/page.tsx
282
282
 
@@ -293,7 +293,7 @@ src/app/page.tsx
293
293
  Excluded paths say why:
294
294
 
295
295
  ```
296
- $ snap explain .env
296
+ $ codebase-snapshot explain .env
297
297
 
298
298
  .env
299
299
 
@@ -308,7 +308,7 @@ same data as an object.
308
308
  ## `diff`
309
309
 
310
310
  ```
311
- $ snap diff old-snapshot new-snapshot
311
+ $ codebase-snapshot diff old-snapshot new-snapshot
312
312
 
313
313
  before 2026-11-03T10:00:00.000Z 812 file(s), 4 part(s)
314
314
  after 2026-11-03T11:30:00.000Z 820 file(s), 4 part(s)
package/docs/install.md CHANGED
@@ -12,24 +12,27 @@ Requires **Node.js 18 or newer**.
12
12
  npx @ankurhalder/codebase-snapshot generate
13
13
  ```
14
14
 
15
- If that exits with **no output and no error** instead of generating, your npm has
16
- resolved the bare spec to a placeholder manifest that carries no executable — npm creates
17
- a `0.0.0-stage` placeholder version during staged publishing, and some npm builds pick it
18
- when no version is given. Pin the version or the tag and it works:
15
+ Pin the version when you need the same build on every machine:
19
16
 
20
17
  ```bash
21
18
  npx @ankurhalder/codebase-snapshot@latest generate
22
- npx @ankurhalder/codebase-snapshot@2 generate
19
+ npx @ankurhalder/codebase-snapshot@3 generate
23
20
  ```
24
21
 
22
+ The bare form works because this package ships **exactly one executable**
23
+ (`codebase-snapshot`). That is deliberate: npm resolves which binary to run by matching the
24
+ typed command against the package's `bin` keys, and no key can contain an `@scope/`, so a
25
+ scoped package with several executables cannot be run by its bare name. If a command ever
26
+ exits with no output, clear the npm cache and retry — see troubleshooting.
27
+
25
28
  `npx -p @ankurhalder/codebase-snapshot codebase-snapshot generate`, `pnpm dlx`,
26
- `yarn dlx` and `bunx` are unaffected. A normal `npm install -D` followed by `npx snap`
27
- is unaffected too, and is the more reproducible choice for a project.
29
+ `yarn dlx` and `bunx` are equivalent. A normal `npm install -D` followed by
30
+ `npx codebase-snapshot` is the more reproducible choice for a project.
28
31
 
29
32
  Equivalent one-liners for other clients:
30
33
 
31
34
  ```bash
32
- yarn dlx -p @ankurhalder/codebase-snapshot snap generate # yarn Berry
35
+ yarn dlx -p @ankurhalder/codebase-snapshot codebase-snapshot generate # yarn Berry
33
36
  yarn global add @ankurhalder/codebase-snapshot # yarn classic (installs globally)
34
37
  pnpm dlx @ankurhalder/codebase-snapshot generate
35
38
  bunx @ankurhalder/codebase-snapshot generate
@@ -47,13 +50,13 @@ bun add -d @ankurhalder/codebase-snapshot
47
50
  Then run it through your client so it resolves from the project's `node_modules`:
48
51
 
49
52
  ```bash
50
- npx snap generate
51
- yarn snap generate
52
- pnpm exec snap generate
53
- bun run snap generate
53
+ npx codebase-snapshot generate
54
+ yarn codebase-snapshot generate
55
+ pnpm exec codebase-snapshot generate
56
+ bun run codebase-snapshot generate
54
57
  ```
55
58
 
56
- Both `snap` and `codebase-snapshot` are exposed as binaries — pick whichever you prefer.
59
+ Both `codebase-snapshot` and `codebase-snapshot` are exposed as binaries — pick whichever you prefer.
57
60
 
58
61
  Adding it to `package.json` scripts works the same everywhere:
59
62
 
@@ -82,23 +85,23 @@ if the generator version is reproducible.
82
85
 
83
86
  ```bash
84
87
  npx @ankurhalder/codebase-snapshot@2 generate
85
- pnpm dlx @ankurhalder/codebase-snapshot@2.1.1 generate
88
+ pnpm dlx @ankurhalder/codebase-snapshot@3.0.0 generate
86
89
  ```
87
90
 
88
91
  ## Verified clients
89
92
 
90
93
  Every client below was used to install the published package and run
91
- `snap --version` successfully. This matrix is enforced in CI
94
+ `codebase-snapshot --version` successfully. This matrix is enforced in CI
92
95
  (`.github/workflows/ci.yml` → `client-install`), so a change that breaks a client fails
93
96
  the build rather than a user's terminal.
94
97
 
95
98
  | Client | Version tested | Run installed binary with |
96
99
  | :--- | :--- | :--- |
97
- | npm | 10.x | `npx snap` |
98
- | yarn (classic) | 1.22.22 | `yarn snap` |
99
- | yarn (Berry, `nodeLinker: pnp`) | 4.6.0 | `yarn snap` |
100
- | pnpm | 10.28.0 | `pnpm exec snap` |
101
- | bun | 1.4.4 | `bun run snap` |
100
+ | npm | 10.x | `npx codebase-snapshot` |
101
+ | yarn (classic) | 1.22.22 | `yarn codebase-snapshot` |
102
+ | yarn (Berry, `nodeLinker: pnp`) | 4.6.0 | `yarn codebase-snapshot` |
103
+ | pnpm | 10.28.0 | `pnpm exec codebase-snapshot` |
104
+ | bun | 1.4.4 | `bun run codebase-snapshot` |
102
105
 
103
106
  Yarn Berry's default **strict PnP** mode works: there is no `node_modules` directory, and
104
107
  the runtime `typescript` dependency still resolves through yarn's `.pnp.cjs` loader.
@@ -125,9 +128,9 @@ Snapshots already written to `snapshot/` are ordinary files and are left alone.
125
128
 
126
129
  ## Troubleshooting
127
130
 
128
- **`snap: command not found`** — when installed locally (not globally), the binary lives
131
+ **`codebase-snapshot: command not found`** — when installed locally (not globally), the binary lives
129
132
  in `node_modules/.bin` and is only on your `PATH` inside a package script or a client
130
- runner. Use `npx snap`, `pnpm exec snap`, `yarn snap`, or `bun run snap`.
133
+ runner. Use `npx codebase-snapshot`, `pnpm exec codebase-snapshot`, `yarn codebase-snapshot`, or `bun run codebase-snapshot`.
131
134
 
132
135
  **`Cannot find module 'typescript'`** — the package declares `typescript` as a runtime
133
136
  dependency for AST analysis. If your client prunes or externalizes it (some bundlers and
@@ -136,14 +139,14 @@ dependency for AST analysis. If your client prunes or externalizes it (some bund
136
139
  **CI has no Node** — that is not supported yet; this package is JavaScript and needs a
137
140
  Node runtime. See the future-work note above.
138
141
 
139
- **`yarn snap` prints extra lines, or breaks a script that parses output** — yarn classic
142
+ **`yarn codebase-snapshot` prints extra lines, or breaks a script that parses output** — yarn classic
140
143
  wraps everything: it echoes `yarn run 1.22.22`, the resolved command, your tool's output,
141
144
  and a `Done in 0.37s.` trailer. For a human that is harmless; for anything that parses
142
- `snap`'s stdout it is not. In scripts and CI, call the binary directly:
145
+ `codebase-snapshot`'s stdout it is not. In scripts and CI, call the binary directly:
143
146
 
144
147
  ```bash
145
- ./node_modules/.bin/snap generate
146
- npx snap generate # same, without the yarn wrapper
148
+ ./node_modules/.bin/codebase-snapshot generate
149
+ npx codebase-snapshot generate # same, without the yarn wrapper
147
150
  ```
148
151
 
149
152
  This is why the CI job in this repository reads the version from a line that *is* the
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ankurhalder/codebase-snapshot",
3
- "version": "2.1.1",
3
+ "version": "3.0.0",
4
4
  "description": "Production-grade LLM codebase snapshot generator, auditor, and AST partitioner",
5
5
  "keywords": [
6
6
  "codebase",
@@ -32,8 +32,7 @@
32
32
  "types": "./dist/index.d.ts",
33
33
  "sideEffects": false,
34
34
  "bin": {
35
- "codebase-snapshot": "./dist/bin.js",
36
- "snap": "./dist/bin.js"
35
+ "codebase-snapshot": "./dist/bin.js"
37
36
  },
38
37
  "exports": {
39
38
  ".": {