codebase-snapshot 0.10.2 → 0.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +102 -0
- package/README.md +10 -1
- package/SECURITY.md +2 -2
- package/dist/bin.js +1282 -296
- package/dist/{chunk-5EYBTBFY.js → chunk-5FPYVWP3.js} +50 -3
- package/dist/{chunk-5AV7OR3J.js → chunk-6HXDYIJS.js} +1204 -338
- package/dist/cli.cjs +1423 -443
- package/dist/cli.d.cts +36 -3
- package/dist/cli.d.ts +36 -3
- package/dist/cli.js +71 -5
- package/dist/index.cjs +1199 -333
- package/dist/index.d.cts +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.js +1 -1
- package/dist/mcp.cjs +206 -4
- package/dist/mcp.js +2 -2
- package/dist/{types-BoWneA7n.d.cts → types-c0tLF2WC.d.cts} +91 -1
- package/dist/{types-BoWneA7n.d.ts → types-c0tLF2WC.d.ts} +91 -1
- package/docs/cli.md +8 -3
- package/docs/configuration.md +108 -0
- package/docs/how-to-feed-a-repo-to-claude.md +40 -9
- package/docs/mcp.md +3 -3
- package/docs/output.md +58 -2
- package/package.json +1 -1
|
@@ -374,6 +374,24 @@ interface ManifestConfigSnapshot {
|
|
|
374
374
|
*/
|
|
375
375
|
maxMonolithBytes?: number | null;
|
|
376
376
|
includeSensitiveFiles: boolean;
|
|
377
|
+
/**
|
|
378
|
+
* The file-slot ceiling `PROMPT.md` was planned for; `0` for no limit.
|
|
379
|
+
*
|
|
380
|
+
* Recorded so the manifest states the destination the instructions were written for, and
|
|
381
|
+
* optional because a manifest written before this was recorded has no such key. It is not part
|
|
382
|
+
* of `configDigest`: the payload is identical either way, and a new delivery preference must not
|
|
383
|
+
* make an existing snapshot fail `validate` as configuration drift.
|
|
384
|
+
*/
|
|
385
|
+
attachmentSlots?: number;
|
|
386
|
+
/** The part-count ceiling the run enforced, `null` when the experimental mode was off. */
|
|
387
|
+
maxParts?: number | null;
|
|
388
|
+
/** Which job the brief was written for. */
|
|
389
|
+
promptTask?: PromptTask;
|
|
390
|
+
/** The owner brief this run was given, by path and digest. */
|
|
391
|
+
brief?: {
|
|
392
|
+
path: string;
|
|
393
|
+
digest: string;
|
|
394
|
+
};
|
|
377
395
|
/** How files were discovered; `undefined` on manifests written before this was recorded. */
|
|
378
396
|
discovery?: DiscoveryMode;
|
|
379
397
|
/** The changed-files scope the snapshot was taken over, when one was used. */
|
|
@@ -467,6 +485,7 @@ interface Manifest {
|
|
|
467
485
|
* recorded has no key; a current manifest records every artifact it wrote.
|
|
468
486
|
*/
|
|
469
487
|
readme?: ManifestArtifact;
|
|
488
|
+
prompt?: ManifestArtifact;
|
|
470
489
|
navigation?: ManifestArtifact;
|
|
471
490
|
projectTree?: ManifestArtifact;
|
|
472
491
|
audit?: ManifestArtifact;
|
|
@@ -510,9 +529,37 @@ interface LayerRule {
|
|
|
510
529
|
* is the one exception, because it duplicates the entire payload: it follows
|
|
511
530
|
* `includeMonolith` (off by default) unless set here explicitly.
|
|
512
531
|
*/
|
|
532
|
+
/**
|
|
533
|
+
* The job the brief is written for.
|
|
534
|
+
*
|
|
535
|
+
* The standard and the coverage duty are the same in all three; what changes is what the
|
|
536
|
+
* reader is asked to produce, in the opening section of the brief.
|
|
537
|
+
*/
|
|
538
|
+
type PromptTask = "audit" | "review" | "explain";
|
|
539
|
+
/** The owner-written half of the brief, parsed and hashed. */
|
|
540
|
+
interface OwnerBrief {
|
|
541
|
+
/** Path as the user wrote it, for provenance. */
|
|
542
|
+
path: string;
|
|
543
|
+
/** sha256 of the file as read, so changing it is configuration drift. */
|
|
544
|
+
digest: string;
|
|
545
|
+
stakes?: string;
|
|
546
|
+
system?: string;
|
|
547
|
+
history?: string;
|
|
548
|
+
bar?: string;
|
|
549
|
+
calibration?: string;
|
|
550
|
+
/** Headings the merge did not recognise, kept rather than dropped. */
|
|
551
|
+
notes: Array<{
|
|
552
|
+
heading: string;
|
|
553
|
+
body: string;
|
|
554
|
+
}>;
|
|
555
|
+
/** Text before the first heading, when there is any. */
|
|
556
|
+
preamble?: string;
|
|
557
|
+
}
|
|
513
558
|
interface ArtifactSelection {
|
|
514
559
|
/** `README.md` — the orientation page for humans and models. */
|
|
515
560
|
readme?: boolean;
|
|
561
|
+
/** `PROMPT.md` — the instruction sheet a snapshot is pasted with. */
|
|
562
|
+
prompt?: boolean;
|
|
516
563
|
/** `manifest.json` — the registry `validate` and `report` read. */
|
|
517
564
|
manifest?: boolean;
|
|
518
565
|
/** `parts/part-XXX.md` — the partitioned code payload. */
|
|
@@ -572,6 +619,33 @@ interface SnapshotConfig {
|
|
|
572
619
|
maxMonolithBytes?: ByteSize | null;
|
|
573
620
|
/** Opt in to emitting `.env`/`*.pem`/`.npmrc`/`credential files. Default false. */
|
|
574
621
|
includeSensitiveFiles?: boolean;
|
|
622
|
+
/**
|
|
623
|
+
* Files the destination accepts in one message; 10 by default, `0` for no limit.
|
|
624
|
+
*
|
|
625
|
+
* `PROMPT.md` plans the delivery to fit: which parts to attach, what to leave behind, and the
|
|
626
|
+
* part budget that would merge them. The payload is unchanged by this setting — only the
|
|
627
|
+
* instructions and the plan that ships with it.
|
|
628
|
+
*/
|
|
629
|
+
attachmentSlots?: number;
|
|
630
|
+
/**
|
|
631
|
+
* Experimental: the most parts a snapshot may have.
|
|
632
|
+
*
|
|
633
|
+
* Off by default. When set, the partitioner grows the per-part budget until the run fits this
|
|
634
|
+
* many parts, which is how a repository that keeps growing keeps its shape instead of adding a
|
|
635
|
+
* twelfth file to a chat that takes ten. The budget it settles on is recorded in
|
|
636
|
+
* `manifest.budgets.maxPartBytes` and may exceed the configured `maxPartBytes`; a warning says
|
|
637
|
+
* so, because a larger part is more tokens for the destination to swallow at once.
|
|
638
|
+
*/
|
|
639
|
+
maxParts?: number | null;
|
|
640
|
+
/**
|
|
641
|
+
* Path to the owner-written half of the brief, relative to `cwd`.
|
|
642
|
+
*
|
|
643
|
+
* The generated brief can state the job, the map and the standard; it cannot say what the
|
|
644
|
+
* software is for or what has already gone wrong. That is judgement, and it is supplied here.
|
|
645
|
+
*/
|
|
646
|
+
brief?: string;
|
|
647
|
+
/** Which job the brief is written for. Defaults to `audit`. */
|
|
648
|
+
promptTask?: PromptTask;
|
|
575
649
|
/**
|
|
576
650
|
* How files are discovered; `auto` picks git when it can list files and walks the tree
|
|
577
651
|
* otherwise.
|
|
@@ -644,6 +718,14 @@ interface ResolvedSnapshotConfig {
|
|
|
644
718
|
includeMonolith: boolean;
|
|
645
719
|
maxMonolithBytes: number | null;
|
|
646
720
|
includeSensitiveFiles: boolean;
|
|
721
|
+
/** Files the destination accepts in one message; `0` means no limit. */
|
|
722
|
+
attachmentSlots: number;
|
|
723
|
+
/** The part-count ceiling, or `null` when the experimental mode is off. */
|
|
724
|
+
maxParts: number | null;
|
|
725
|
+
/** The job the brief is written for. */
|
|
726
|
+
promptTask: PromptTask;
|
|
727
|
+
/** The parsed owner brief, when one was configured. */
|
|
728
|
+
brief?: OwnerBrief;
|
|
647
729
|
/**
|
|
648
730
|
* How files are discovered; `auto` picks git when it can list files and walks the tree otherwise.
|
|
649
731
|
* Optional because a resolved config can arrive from an older caller that never named it — every
|
|
@@ -689,6 +771,14 @@ interface CliOptions {
|
|
|
689
771
|
includeMonolith?: boolean;
|
|
690
772
|
includeSensitiveFiles?: boolean;
|
|
691
773
|
maxMonolithBytes?: number | null;
|
|
774
|
+
/** `--attachment-slots`: how many files the destination accepts. */
|
|
775
|
+
attachmentSlots?: number;
|
|
776
|
+
/** `--max-parts`: the experimental part-count ceiling. */
|
|
777
|
+
maxParts?: number | null;
|
|
778
|
+
/** `--brief`: path to the owner-written half of the brief. */
|
|
779
|
+
brief?: string;
|
|
780
|
+
/** `--prompt-task`: which job the brief is written for. */
|
|
781
|
+
promptTask?: PromptTask;
|
|
692
782
|
maxPartBytes?: number;
|
|
693
783
|
maxPartTokens?: ByteSize | null;
|
|
694
784
|
largeFileBytes?: number;
|
|
@@ -738,4 +828,4 @@ interface ValidationResult {
|
|
|
738
828
|
warnings: string[];
|
|
739
829
|
}
|
|
740
830
|
|
|
741
|
-
export type { ArtifactSelection as A, ByteSize as B, CliOptions as C, DiscoveryMode as D, FileEntry as F, HooksConfig as H, InclusionMode as I, JsonSummary as J, KindRule as K, LayerRule as L, MarkdownSummary as M, OutputFormat as O,
|
|
831
|
+
export type { ArtifactSelection as A, ByteSize as B, CliOptions as C, DiscoveryMode as D, FileEntry as F, HooksConfig as H, InclusionMode as I, JsonSummary as J, KindRule as K, LayerRule as L, MarkdownSummary as M, OutputFormat as O, PromptTask as P, ResolvedSnapshotConfig as R, SecretRule as S, TextEncoding as T, ValidationResult as V, SkipRecord as a, SourceSummary as b, SnapshotConfig as c, PartMetadata as d, SecretFinding as e, Manifest as f, BudgetConfig as g, IncompleteFile as h, ManifestArtifact as i, ManifestConfigSnapshot as j, ManifestIndexes as k, ManifestTotals as l, Mode as m, OwnerBrief as n, PartFileEntry as o, ResolvedArtifacts as p, ResolvedBudgets as q, SecretRuleInput as r, SkipReason as s, SummaryQuality as t, TruncationReason as u, ValidationDrift as v };
|
package/docs/cli.md
CHANGED
|
@@ -97,7 +97,7 @@ Exit `0` when the snapshot passes its own integrity check, `1` when it does not.
|
|
|
97
97
|
|
|
98
98
|
```
|
|
99
99
|
📸 Generating snapshot for: /path/to/repo
|
|
100
|
-
Branch: main | Part budget: 300 KB | Generator: 0.
|
|
100
|
+
Branch: main | Part budget: 300 KB | Generator: 0.12.0 (project dependency ^0.12.0)
|
|
101
101
|
|
|
102
102
|
✅ Snapshot generated in 0.14s:
|
|
103
103
|
- Tracked files: 121 included of 128 paths found — 7 skipped (default-ignore 5, binary 1, sensitive-file 1); every one is listed in snapshot/reports/audit.md
|
|
@@ -106,6 +106,7 @@ Exit `0` when the snapshot passes its own integrity check, `1` when it does not.
|
|
|
106
106
|
- Parts written: 3 under snapshot/parts/
|
|
107
107
|
- Reports: snapshot/reports/ (project-tree, navigation, audit)
|
|
108
108
|
- Manifest: snapshot/manifest.json
|
|
109
|
+
- Orientation: snapshot/README.md, snapshot/PROMPT.md
|
|
109
110
|
- Fingerprint: e4607b570268c8def0911babbace97e4a0196d9eaf2cac22c8847500883d70aa
|
|
110
111
|
- Integrity: passed
|
|
111
112
|
- Redacted: 2 line(s) — values masked; see snapshot/reports/audit.md
|
|
@@ -191,7 +192,7 @@ The whole first run in one command, with defaults and no prompts. This is the sa
|
|
|
191
192
|
🚀 Setup for: /path/to/repo
|
|
192
193
|
✅ Created snapshot.config.ts (preset: nextjs)
|
|
193
194
|
Added npm scripts: snapshot, snapshot:validate
|
|
194
|
-
Added devDependency: codebase-snapshot ^0.
|
|
195
|
+
Added devDependency: codebase-snapshot ^0.12.0
|
|
195
196
|
Added to .gitignore: /snapshot/, /snapshot.tmp/
|
|
196
197
|
⏳ Installing dependencies…
|
|
197
198
|
✅ Installed dependencies (npm install, 2.1s)
|
|
@@ -243,7 +244,7 @@ It also has three side effects on files you own, and it says so when it does the
|
|
|
243
244
|
```
|
|
244
245
|
✅ Created snapshot.config.ts (preset: node-lib)
|
|
245
246
|
Added npm scripts: snapshot, snapshot:validate
|
|
246
|
-
Added devDependency: codebase-snapshot ^0.
|
|
247
|
+
Added devDependency: codebase-snapshot ^0.12.0
|
|
247
248
|
Added to .gitignore: /snapshot/, /snapshot.tmp/
|
|
248
249
|
```
|
|
249
250
|
|
|
@@ -449,6 +450,10 @@ for the two install flags, and the init-and-setup flags list both commands.
|
|
|
449
450
|
| `--max-part-tokens <n>` | size | unset | generate, validate, setup | A per-part ceiling in **tokens**, for a context window rather than a disk. Narrows `--max-part-bytes` to the equivalent byte count (`tokens × 4`); the smaller of the two ceilings always wins, and both are recorded in the manifest. Accepts `32k`. Minimum 1024 — below that it is a usage error, not a value quietly raised to the floor. The byte ceiling is what is enforced: `estimatedTokens` is an estimate, and a part whose estimate exceeds the token ceiling is named in a warning rather than silently accepted. |
|
|
450
451
|
| `--large-file-bytes <n>` | size | the part budget (307200) | generate, validate, explain, setup | Above this, a file becomes a head/tail preview. It may not exceed `--max-part-bytes`: a file between the two could not fit a part. |
|
|
451
452
|
| `--max-monolith-bytes <n>` | size | unset | generate, validate, setup | Skip the single-file monolith when it would exceed this. |
|
|
453
|
+
| `--brief <path>` | path | unset | generate, validate | The owner-written half of `PROMPT.md`: `Stakes`, `The system`, `What came before`, `The bar`, `Calibration`. Unknown headings are kept as Owner notes; measured headings cannot be redefined; the file is digested, so editing it is drift. |
|
|
454
|
+
| `--prompt-task <task>` | string | `audit` | generate, validate | `audit`, `review` or `explain` — which job the brief is written for. Changes the opening section, not the standard. |
|
|
455
|
+
| `--max-parts <n>` | count | unset | generate, validate | **Experimental.** Grow the per-part budget until the snapshot has at most `n` parts, so the file count stays fixed as the code grows. The budget it settles on is recorded in `manifest.budgets.maxPartBytes` and may exceed `--max-part-bytes`; a warning says so. `0` is a usage error. |
|
|
456
|
+
| `--attachment-slots <n>` | count | `10` | generate | Files the destination accepts in one message; `0` means no limit. `PROMPT.md` plans the delivery against it — which parts to attach, what to leave behind, and the `--max-part-bytes` value that would merge them. It changes no part and no file, so it is recorded in the manifest but is not part of the config digest. |
|
|
452
457
|
| `--include-monolith` | flag | off | generate, validate, setup | Also write `full-codebase.json` and `full-codebase.md`. |
|
|
453
458
|
| `--include-sensitive-files` | flag | off | generate, validate, explain, init, setup | Emit `.env`, `*.pem`, `.npmrc` and similar. Off by default; they are reported as skipped. |
|
|
454
459
|
| `--skip-artifacts <names>` | list | unset | generate, validate, init, setup | Comma-separated artifacts to omit. |
|
package/docs/configuration.md
CHANGED
|
@@ -225,6 +225,7 @@ the manifest called it a preview by policy. That combination is a config error.
|
|
|
225
225
|
export default {
|
|
226
226
|
artifacts: {
|
|
227
227
|
readme: true, // snapshot/README.md
|
|
228
|
+
prompt: true, // snapshot/PROMPT.md — the instruction sheet a model is given
|
|
228
229
|
manifest: true, // snapshot/manifest.json
|
|
229
230
|
parts: true, // snapshot/parts/*.md
|
|
230
231
|
navigation: true, // snapshot/reports/navigation.md
|
|
@@ -246,6 +247,109 @@ on leaves links pointing at files that were never written. Both are allowed.
|
|
|
246
247
|
|
|
247
248
|
The `.codebase-snapshot` ownership marker is always written, whatever the selection.
|
|
248
249
|
|
|
250
|
+
## Delivering it: how many files the destination takes
|
|
251
|
+
|
|
252
|
+
```js
|
|
253
|
+
export default {
|
|
254
|
+
attachmentSlots: 10, // files your chat accepts per message; 0 = no limit
|
|
255
|
+
};
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
Hosted assistants take a fixed number of files per message — 10 is the common cap — and every part
|
|
259
|
+
is one of them. `PROMPT.md` plans the delivery against this number: which parts to attach, what to
|
|
260
|
+
leave behind when they do not all fit, and the `--max-part-bytes` value that would merge them.
|
|
261
|
+
|
|
262
|
+
- Default `10`; `0` means the destination imposes no limit and the plan says to attach everything.
|
|
263
|
+
- It changes **no part and no file**: the payload is byte-identical either way. Only the delivery
|
|
264
|
+
section of `PROMPT.md` moves, which is why it is recorded in `manifest.config` but is not part of
|
|
265
|
+
the config digest — a new delivery preference must not make an existing snapshot fail `validate`.
|
|
266
|
+
- Instructions are pasted as text and cost no slot, so the budget is always spent on files.
|
|
267
|
+
|
|
268
|
+
The one thing it cannot do is make a snapshot fit: a 12-part snapshot does not go into a 10-file
|
|
269
|
+
message at any setting. Raise `maxPartBytes` to merge the parts, or narrow the scope — the plan in
|
|
270
|
+
`PROMPT.md` names the number.
|
|
271
|
+
|
|
272
|
+
### Experimental: a fixed number of parts
|
|
273
|
+
|
|
274
|
+
```js
|
|
275
|
+
export default {
|
|
276
|
+
maxParts: 10, // grow the parts until the snapshot has at most ten; off by default
|
|
277
|
+
};
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
The opposite trade to everything above: the **count** is fixed and the **size** gives way. As the
|
|
281
|
+
repository grows, `maxParts` grows the per-part budget instead of adding a part, which is what a
|
|
282
|
+
destination with a hard file limit wants — the snapshot keeps its shape instead of turning into
|
|
283
|
+
eleven parts next month.
|
|
284
|
+
|
|
285
|
+
- Off by default (`null`). Opt in per run with `--max-parts <n>`, or in the config.
|
|
286
|
+
- The budget it settles on is recorded in `manifest.budgets.maxPartBytes` — the number the parts
|
|
287
|
+
actually honour — while `manifest.config.maxPartBytes` keeps the configured value, so
|
|
288
|
+
`validate` still compares like with like.
|
|
289
|
+
- It may exceed `maxPartBytes`, and that is the point: a part bigger than the configured ceiling is
|
|
290
|
+
more tokens at once, and some destinations cap a single file. Both facts land in
|
|
291
|
+
`manifest.warnings`, so the run says what it did rather than quietly changing the shape.
|
|
292
|
+
- If it cannot converge, generation fails with the counts it tried rather than writing something
|
|
293
|
+
the setting did not ask for.
|
|
294
|
+
|
|
295
|
+
Treat it as experimental: `maxPartBytes` stays the honest control, and this is the knob for the
|
|
296
|
+
case where the file count, not the byte count, is the binding constraint.
|
|
297
|
+
|
|
298
|
+
## The brief: what only you can write
|
|
299
|
+
|
|
300
|
+
`PROMPT.md` is generated, and half of it cannot be: what the software is *for*, what has already
|
|
301
|
+
gone wrong, and which failures you would recognise. That is judgement, so it is supplied as a
|
|
302
|
+
file and merged at fixed slots.
|
|
303
|
+
|
|
304
|
+
```js
|
|
305
|
+
export default {
|
|
306
|
+
brief: "docs/brief.md", // relative to cwd; a missing file is an error
|
|
307
|
+
promptTask: "audit", // audit | review | explain
|
|
308
|
+
};
|
|
309
|
+
```
|
|
310
|
+
|
|
311
|
+
The file is plain markdown with five recognised headings:
|
|
312
|
+
|
|
313
|
+
| Heading | What happens |
|
|
314
|
+
| :--- | :--- |
|
|
315
|
+
| `## Stakes` | rendered as its own section, right after the job |
|
|
316
|
+
| `## The system` | replaces the generated narrative, and the index facts follow under "What the index records" |
|
|
317
|
+
| `## What came before` | rendered above the generated commit ledger |
|
|
318
|
+
| `## The bar` | replaces the standard |
|
|
319
|
+
| `## Calibration` | replaces the example failures |
|
|
320
|
+
|
|
321
|
+
```markdown
|
|
322
|
+
<!-- docs/brief.md -->
|
|
323
|
+
## Stakes
|
|
324
|
+
Runs live production for one owner. A wrong cleanup deletes their data.
|
|
325
|
+
|
|
326
|
+
## What came before
|
|
327
|
+
Four rounds, 23 defects. The recurring shapes are a guard at the route but not the timer, and
|
|
328
|
+
an ok flag that means the call returned.
|
|
329
|
+
|
|
330
|
+
## Calibration
|
|
331
|
+
- a grant signed for one recipe executing another recipe's deletions
|
|
332
|
+
- a recipe that never worked, because its test supplied a number where the daemon sends a string
|
|
333
|
+
```
|
|
334
|
+
|
|
335
|
+
Any other `##` heading is kept, verbatim, under **Owner notes** — nothing is dropped because the
|
|
336
|
+
merge did not recognise it. Every owner section is marked in the output as written by the project
|
|
337
|
+
owner, so a reader can tell an assertion from a measurement.
|
|
338
|
+
|
|
339
|
+
Three things are refused because they would make the document lie:
|
|
340
|
+
|
|
341
|
+
- a heading that redefines a **measured** section (`Coverage`, `This snapshot`, `Attaching this`,
|
|
342
|
+
`The job`, `What you have`, `What a useful answer contains`, `Your task`) is a configuration
|
|
343
|
+
error, not an override;
|
|
344
|
+
- a `brief` path that cannot be read is an error — a snapshot must not silently ship without the
|
|
345
|
+
half you wrote;
|
|
346
|
+
- and the file is digested into the config digest, so editing the brief after generating makes
|
|
347
|
+
`validate` report drift. A stale brief is the same failure as a stale snapshot.
|
|
348
|
+
|
|
349
|
+
`promptTask` changes only the opening section: `audit` (the default) asks for what is wrong or
|
|
350
|
+
will break, `review` for what a change breaks, `explain` for how a subsystem works. The standard
|
|
351
|
+
and the coverage duty are the same in all three.
|
|
352
|
+
|
|
249
353
|
See [Snapshot output](output.md) for the layout and the manifest schema.
|
|
250
354
|
|
|
251
355
|
## Secrets: redaction
|
|
@@ -464,6 +568,9 @@ const config = {
|
|
|
464
568
|
excludePatterns: [],
|
|
465
569
|
discovery: "auto", // "auto" | "git" | "walk"
|
|
466
570
|
|
|
571
|
+
// ── Delivery ─────────────────────────────────────────────
|
|
572
|
+
attachmentSlots: 10, // files your destination takes per message; 0 = no limit
|
|
573
|
+
|
|
467
574
|
// ── Classification ───────────────────────────────────────
|
|
468
575
|
layersMode: "merge",
|
|
469
576
|
layers: [],
|
|
@@ -476,6 +583,7 @@ const config = {
|
|
|
476
583
|
// ── Artifacts ────────────────────────────────────────────
|
|
477
584
|
artifacts: {
|
|
478
585
|
readme: true,
|
|
586
|
+
prompt: true,
|
|
479
587
|
manifest: true,
|
|
480
588
|
parts: true,
|
|
481
589
|
navigation: true,
|
|
@@ -70,17 +70,36 @@ A file is never cut down to make a part fit. A file above `largeFileBytes` — w
|
|
|
70
70
|
budget — becomes a head/tail excerpt with an explicit marker, and `manifest.json` lists it in
|
|
71
71
|
`incomplete[]` with the line ranges it lost.
|
|
72
72
|
|
|
73
|
+
### 2b. Count the attachment slots, not just the bytes
|
|
74
|
+
|
|
75
|
+
Hosted chats take a fixed number of files per message — 10 is the common cap — and every part is
|
|
76
|
+
one file. A 12-part snapshot cannot be delivered to a 10-file chat at all, and no amount of
|
|
77
|
+
compression changes that: the payload is twelve files.
|
|
78
|
+
|
|
79
|
+
Three things follow:
|
|
80
|
+
|
|
81
|
+
- **Instructions are text, not a file.** Paste `PROMPT.md` into the message and attach only code.
|
|
82
|
+
A prompt that costs a slot is a part you do not get.
|
|
83
|
+
- **Parts before reports.** When the parts leave no room, skip `manifest.json` and `reports/`:
|
|
84
|
+
`PROMPT.md` already names the parts, the counts and the omissions.
|
|
85
|
+
- **Fewer parts, or fewer files.** Raise `maxPartBytes` to merge the parts into fewer, larger
|
|
86
|
+
files, or narrow the scope with `--include` and `excludePatterns` so the code that matters fits.
|
|
87
|
+
|
|
88
|
+
`PROMPT.md` does this arithmetic for the snapshot you have: how many parts fit, which to leave out
|
|
89
|
+
when they do not, and the `--max-part-bytes` value that would fit the whole repository.
|
|
90
|
+
|
|
73
91
|
### 3. Tell the model what it is looking at
|
|
74
92
|
|
|
75
|
-
|
|
93
|
+
`generate` writes `snapshot/PROMPT.md` for exactly this. Paste it before the parts.
|
|
76
94
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
95
|
+
It is rendered from the manifest rather than written once, so it is about *this* snapshot: the
|
|
96
|
+
parts by name, every file that is only partly present with the line ranges it lost, the skip
|
|
97
|
+
reasons with counts, the fingerprint to quote back, and the commit it was taken from. Regenerate
|
|
98
|
+
the snapshot and those numbers move with the code.
|
|
81
99
|
|
|
82
|
-
|
|
83
|
-
|
|
100
|
+
The sentence it exists to say is the one models otherwise fill by invention — *a file may be
|
|
101
|
+
missing, and the reason is recorded, so ask instead of assuming*. That is what turns a
|
|
102
|
+
hallucination into a question you can answer with `explain <path>`.
|
|
84
103
|
|
|
85
104
|
### 4. Include the index, always
|
|
86
105
|
|
|
@@ -98,10 +117,22 @@ npm run snapshot:validate || npm run snapshot
|
|
|
98
117
|
changed budget, layer rule or secret pattern is drift, not silence — so the check catches both code
|
|
99
118
|
changes and configuration changes.
|
|
100
119
|
|
|
101
|
-
## The prompt
|
|
120
|
+
## The prompt
|
|
102
121
|
|
|
103
122
|
Everything above is about producing the snapshot. This is the other half: what to say to the model
|
|
104
|
-
that receives it.
|
|
123
|
+
that receives it.
|
|
124
|
+
|
|
125
|
+
You do not have to write it. `snapshot/PROMPT.md` is the prompt, and being generated is what makes
|
|
126
|
+
it worth pasting: it describes the snapshot you are actually sending. It is a brief, not a packing
|
|
127
|
+
slip — the job, the system map the manifest can prove (layers, the modules with the most
|
|
128
|
+
importers, entry points, which surfaces were indexed), the last ten commit subjects as claims to
|
|
129
|
+
verify rather than rediscover, the evidence bar, the coverage owed, and calibration examples of
|
|
130
|
+
the defects that do not crash. Then the per-run apparatus: fingerprint, part inventory, partial
|
|
131
|
+
files, skip tallies and the attachment arithmetic.
|
|
132
|
+
|
|
133
|
+
If you are assembling the message by hand instead — a chat window that takes one file at a time, a
|
|
134
|
+
wrapper that cannot include a directory — this is the minimum that keeps the properties. Replace
|
|
135
|
+
the task section with your question.
|
|
105
136
|
|
|
106
137
|
```text
|
|
107
138
|
You are working on a codebase you cannot clone, run or grep. What you have is a generated snapshot of
|
package/docs/mcp.md
CHANGED
|
@@ -10,7 +10,7 @@ walk — that the client sees.
|
|
|
10
10
|
## Start it
|
|
11
11
|
|
|
12
12
|
```bash
|
|
13
|
-
npx -y codebase-snapshot@0.
|
|
13
|
+
npx -y codebase-snapshot@0.12.0 mcp
|
|
14
14
|
```
|
|
15
15
|
|
|
16
16
|
The server serves the directory it was started in. `--cwd <path>` points it elsewhere, and that
|
|
@@ -25,7 +25,7 @@ Claude Desktop and Cursor:
|
|
|
25
25
|
"mcpServers": {
|
|
26
26
|
"codebase-snapshot": {
|
|
27
27
|
"command": "npx",
|
|
28
|
-
"args": ["-y", "codebase-snapshot@0.
|
|
28
|
+
"args": ["-y", "codebase-snapshot@0.12.0", "mcp", "--cwd", "/absolute/path/to/repo"]
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
31
|
}
|
|
@@ -34,7 +34,7 @@ Claude Desktop and Cursor:
|
|
|
34
34
|
Claude Code registers the same thing from a shell:
|
|
35
35
|
|
|
36
36
|
```bash
|
|
37
|
-
claude mcp add codebase-snapshot -- npx -y codebase-snapshot@0.
|
|
37
|
+
claude mcp add codebase-snapshot -- npx -y codebase-snapshot@0.12.0 mcp --cwd /absolute/path/to/repo
|
|
38
38
|
```
|
|
39
39
|
|
|
40
40
|
On Windows, wrap the command as `cmd /c npx` with the same arguments — `npx` is a `.cmd` shim
|
package/docs/output.md
CHANGED
|
@@ -10,6 +10,7 @@ explains everything they omit.
|
|
|
10
10
|
snapshot/
|
|
11
11
|
├── .codebase-snapshot ownership marker (see Safety)
|
|
12
12
|
├── README.md human summary of this snapshot
|
|
13
|
+
├── PROMPT.md the instruction sheet to paste with it
|
|
13
14
|
├── manifest.json machine index: files, parts, config, hashes, skips
|
|
14
15
|
├── parts/
|
|
15
16
|
│ ├── part-001.md the code, grouped and size-budgeted
|
|
@@ -42,6 +43,61 @@ impossible field: a file cannot record its own sha256, so `artifacts.fullJson` i
|
|
|
42
43
|
embedded copy and a `selfReference` sentence points at `manifest.json`, which carries the real
|
|
43
44
|
`byteSize` and `sha256` for that file.
|
|
44
45
|
|
|
46
|
+
## PROMPT.md
|
|
47
|
+
|
|
48
|
+
The one artifact written for the model rather than for you, and the only one that is a *brief*
|
|
49
|
+
rather than an index. Paste it with the payload. It has two halves:
|
|
50
|
+
|
|
51
|
+
**The brief** — what to do and how to be believed:
|
|
52
|
+
|
|
53
|
+
- **The job**: find what is still wrong or will break, with the method left to the reader and an
|
|
54
|
+
honest account of coverage owed in return. A narrower task in the closing slot wins, and the
|
|
55
|
+
standard still applies to it.
|
|
56
|
+
- **The system**, from the manifest: layers and their file counts, the modules with the most
|
|
57
|
+
importers (so a reader knows what a change reaches), entry points by convention, the routes,
|
|
58
|
+
handlers and components the index found — or a plain statement that none were recorded, so a
|
|
59
|
+
model does not go looking for a surface that is not there — the largest files, and the share of
|
|
60
|
+
bytes that is tests.
|
|
61
|
+
- **What came before**: the last ten commit subjects, labelled as claims rather than evidence,
|
|
62
|
+
with the instruction to verify a recorded fix holds instead of rediscovering it. When git
|
|
63
|
+
cannot be read the section says so; it is never invented.
|
|
64
|
+
- **The bar**: quoted lines, the state that reaches them, why the apparent guard does not stop it;
|
|
65
|
+
no style findings, no invented findings, a clean surface proven by quoting the guard.
|
|
66
|
+
- **Coverage**: paths found, included and skipped with reasons, partial files with their missing
|
|
67
|
+
line ranges, redactions, and "everything unseen is unread, never clean".
|
|
68
|
+
- **Calibration**: the classes of defect that do not crash — a guard at one call site and not its
|
|
69
|
+
twin, a budget shorter than the work it guards, a success flag that means the call returned.
|
|
70
|
+
|
|
71
|
+
**The owner half** — when `brief` is configured (see [configuration](configuration.md#the-brief-what-only-you-can-write)),
|
|
72
|
+
the five judgement sections come from that file instead of the generic prose: what is at stake, the
|
|
73
|
+
system in the owner`s words (with the measured facts still following under "What the index
|
|
74
|
+
records"), the history the owner has lived through, the bar this team applies, and the calibration
|
|
75
|
+
examples from its own incidents. Each is marked as written by the project owner.
|
|
76
|
+
|
|
77
|
+
**The apparatus** — this run only:
|
|
78
|
+
|
|
79
|
+
- the fingerprint to quote back, the timestamp, the commit, whether the tree was dirty, and the
|
|
80
|
+
validation status with the warning that it describes the run and not the tree now;
|
|
81
|
+
- every part by name, and every file not present in full with its reason and missing ranges;
|
|
82
|
+
- the delivery arithmetic below.
|
|
83
|
+
|
|
84
|
+
Everything factual is rendered from the manifest and the repository, so the brief cannot describe
|
|
85
|
+
a different run. It only names artifacts that were actually written: `--skip-artifacts
|
|
86
|
+
parts,audit` produces a brief that does not tell a model to read parts, and says the per-file
|
|
87
|
+
redaction detail is unavailable rather than pointing at a file that is not there.
|
|
88
|
+
|
|
89
|
+
It also does the arithmetic of sending it. Hosted chats take a fixed number of files — 10 is the
|
|
90
|
+
common cap — and every part is one file, so a 12-part snapshot cannot be delivered whole. The
|
|
91
|
+
`## Attaching this` section states which files fit, what to leave behind, and the `--max-part-bytes`
|
|
92
|
+
value that would merge the parts into a number the destination accepts. The instructions themselves
|
|
93
|
+
are pasted as text, so they cost no attachment slot.
|
|
94
|
+
|
|
95
|
+
It only names artifacts that were actually written: `--skip-artifacts parts,audit` produces a
|
|
96
|
+
prompt that does not tell a model to read parts, and says the per-file redaction detail is
|
|
97
|
+
unavailable rather than pointing at a file that is not there. Its digest is recorded under
|
|
98
|
+
`artifacts.prompt`, so editing it by hand makes `validate` fail — a prompt that names a previous
|
|
99
|
+
run's parts is worse than no prompt, because it reads as current.
|
|
100
|
+
|
|
45
101
|
Every artifact can be turned off. `--skip-artifacts parts` omits the parts,
|
|
46
102
|
`--only-artifacts manifest` writes nothing but the manifest, and `config.artifacts` does the
|
|
47
103
|
same persistently. The ownership marker is always written.
|
|
@@ -104,13 +160,13 @@ diff the manifest only when you need to know that a run happened.
|
|
|
104
160
|
| `generatedAt` | ISO timestamp of the run. |
|
|
105
161
|
| `generator` | `{ name, version }` of the tool that wrote it. |
|
|
106
162
|
| `git` | `{ branch, commit, isDirty }`. `branch` falls back to the configured branch on a detached HEAD and outside a repository; `commit` is `"unknown"` and `isDirty` is `false` when git cannot report. A `false` there means "not known to be dirty", not "clean tree" — check `commit` to tell the two apart. |
|
|
107
|
-
| `budgets` | The effective byte limits for the run: `{ maxPartBytes, largeFileBytes }`. The per-layer overrides live at `config.budgets`, which is `{ default, byLayer }`. |
|
|
163
|
+
| `budgets` | The effective byte limits for the run: `{ maxPartBytes, largeFileBytes }`. The per-layer overrides live at `config.budgets`, which is `{ default, byLayer }`. With the experimental `maxParts`, `maxPartBytes` here is the budget the run grew to and `config.maxPartBytes` keeps the configured ceiling. |
|
|
108
164
|
| `config` | The resolved configuration actually used (preset, artifacts, sizing, scoping). |
|
|
109
165
|
| `counts` | `{ totalFiles, totalSizeBytes, totalLines, partsCount, skippedCount, largeFileCount, truncatedPreviewCount, incompleteCount }`. |
|
|
110
166
|
| `totals` | Bookkeeping: `{ candidateFiles, includedFiles, fullFiles, previewFiles, skippedFiles, totalSourceBytes, totalContentBytes, sourceLines, emittedLines, estimatedTokens, partCount, warningCount, redactedLines }`. `sourceLines` is the source line count before previews and part budgets; `emittedLines` is what the parts actually carry. `redactedLines` counts the lines whose values were masked — one per line, not one per matching rule — and is what the summary's `Redacted:` line prints. |
|
|
111
167
|
| `fingerprint` | Stable hash of the snapshot content **and** the settings that shaped it. Two runs over unchanged input and unchanged settings produce the same value; changing the budget, a preset, a layer rule or the secret rules moves it, because the parts move too. It is recomputed by `validate` from `files[]` and `config.digest`, so an edited file list cannot keep the recorded value — and because the partitioner may change a file's `inclusionMode` after the fingerprint is taken, the mode is not part of the hash. |
|
|
112
168
|
| `validation` | `{ status: "passed" \| "failed", errors: [] }` for the run's own integrity check. |
|
|
113
|
-
| `artifacts` | A digest of every artifact the run wrote: `readme`, `navigation`, `projectTree`, `audit`, `fullJson`, `fullMarkdown` and `sarif` when present, each `{ byteSize, sha256 }`. `validate` requires each recorded file to exist and match, so deleting the README or the navigation index is a failure rather than a silent omission. Monolith entries are `null` when the file was not written; a key absent for an older manifest is not drift. |
|
|
169
|
+
| `artifacts` | A digest of every artifact the run wrote: `readme`, `prompt`, `navigation`, `projectTree`, `audit`, `fullJson`, `fullMarkdown` and `sarif` when present, each `{ byteSize, sha256 }`. `validate` requires each recorded file to exist and match, so deleting the README or the navigation index is a failure rather than a silent omission. Monolith entries are `null` when the file was not written; a key absent for an older manifest is not drift. |
|
|
114
170
|
| `layers`, `kinds` | File counts per layer and per kind. |
|
|
115
171
|
| `indexes` | Cross-references: `routes`, `components`, `handlers`, `features`, `imports`, `directives`. `imports.byFile` holds one entry per file whose import edges are known — including a previewed or oversized file, whose specifiers are still extracted because they are what makes it a dependent. Such an entry has `exportsOmitted: true`: its `exports` list was never read, and an empty array there would claim "no exports". |
|
|
116
172
|
| `parts` | One entry per part (below). |
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "codebase-snapshot",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.12.0",
|
|
4
4
|
"description": "Create a codebase snapshot an LLM can read: budgeted Markdown parts for Claude, ChatGPT and Cursor, a manifest of every included and skipped file, secret redaction, and validate, which fails when the snapshot drifts. Local CLI and MCP server.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"codebase-snapshot",
|