codebase-snapshot 0.10.2 → 0.11.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 +60 -0
- package/README.md +9 -1
- package/SECURITY.md +2 -2
- package/dist/bin.js +643 -8
- package/dist/{chunk-5EYBTBFY.js → chunk-5ZOXHBTW.js} +30 -3
- package/dist/{chunk-5AV7OR3J.js → chunk-NJ75RVHO.js} +569 -5
- package/dist/cli.cjs +644 -8
- package/dist/cli.d.cts +26 -3
- package/dist/cli.d.ts +26 -3
- package/dist/cli.js +49 -5
- package/dist/index.cjs +569 -5
- package/dist/index.d.cts +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.js +1 -1
- package/dist/mcp.cjs +67 -4
- package/dist/mcp.js +2 -2
- package/dist/{types-BoWneA7n.d.cts → types-DGWw3SH2.d.cts} +40 -0
- package/dist/{types-BoWneA7n.d.ts → types-DGWw3SH2.d.ts} +40 -0
- package/docs/cli.md +6 -3
- package/docs/configuration.md +53 -0
- package/docs/how-to-feed-a-repo-to-claude.md +40 -9
- package/docs/mcp.md +3 -3
- package/docs/output.md +52 -2
- package/package.json +1 -1
package/dist/bin.js
CHANGED
|
@@ -2191,7 +2191,7 @@ function applySpansKeepingQuotes(line, spans) {
|
|
|
2191
2191
|
|
|
2192
2192
|
// src/version.ts
|
|
2193
2193
|
var GENERATOR_NAME = "codebase-snapshot";
|
|
2194
|
-
var GENERATOR_VERSION = "0.
|
|
2194
|
+
var GENERATOR_VERSION = "0.11.0";
|
|
2195
2195
|
var SCHEMA_VERSION = "3.0.0";
|
|
2196
2196
|
var LEGACY_GENERATOR_NAMES = ["@ankurhalder/codebase-snapshot"];
|
|
2197
2197
|
function isOurGeneratorName(name) {
|
|
@@ -2639,6 +2639,23 @@ function defaultIgnoreReason(relativePath, toolDirNames = DEFAULT_TOOL_DIR_NAMES
|
|
|
2639
2639
|
}
|
|
2640
2640
|
return null;
|
|
2641
2641
|
}
|
|
2642
|
+
function recentCommitSubjects(cwd, limit = 10) {
|
|
2643
|
+
try {
|
|
2644
|
+
const stdout = childProcess.execFileSync(
|
|
2645
|
+
"git",
|
|
2646
|
+
["log", "-n", String(limit), "--pretty=%s", "--no-color"],
|
|
2647
|
+
{
|
|
2648
|
+
cwd,
|
|
2649
|
+
stdio: ["ignore", "pipe", "ignore"],
|
|
2650
|
+
encoding: "utf8",
|
|
2651
|
+
maxBuffer: GIT_OUTPUT_LIMIT
|
|
2652
|
+
}
|
|
2653
|
+
);
|
|
2654
|
+
return stdout.split("\n").map((line) => line.trim()).filter((line) => line.length > 0);
|
|
2655
|
+
} catch {
|
|
2656
|
+
return [];
|
|
2657
|
+
}
|
|
2658
|
+
}
|
|
2642
2659
|
function listIgnoredPaths(cwd) {
|
|
2643
2660
|
try {
|
|
2644
2661
|
const stdout = childProcess.execFileSync(
|
|
@@ -3369,6 +3386,10 @@ function normalizeResolvedConfig(config) {
|
|
|
3369
3386
|
return markResolvedConfig({
|
|
3370
3387
|
...config,
|
|
3371
3388
|
discovery,
|
|
3389
|
+
// A spread copy built before the field existed carries no value; the default applies, and it
|
|
3390
|
+
// is re-validated because the number reaches a rendered artifact.
|
|
3391
|
+
attachmentSlots: resolveAttachmentSlots(config.attachmentSlots),
|
|
3392
|
+
maxParts: resolveMaxParts(config.maxParts),
|
|
3372
3393
|
includeMonolith: artifacts.monolith,
|
|
3373
3394
|
secretRules: compileSecretRules(config.secretRules),
|
|
3374
3395
|
artifacts,
|
|
@@ -3437,6 +3458,7 @@ function describeValue2(value) {
|
|
|
3437
3458
|
var isThenable = (value) => typeof value.then === "function";
|
|
3438
3459
|
var CONFIG_KEY_NAMES = [
|
|
3439
3460
|
"artifacts",
|
|
3461
|
+
"attachmentSlots",
|
|
3440
3462
|
"branch",
|
|
3441
3463
|
"budgets",
|
|
3442
3464
|
"changedSince",
|
|
@@ -3454,6 +3476,7 @@ var CONFIG_KEY_NAMES = [
|
|
|
3454
3476
|
"layersMode",
|
|
3455
3477
|
"maxMonolithBytes",
|
|
3456
3478
|
"maxPartBytes",
|
|
3479
|
+
"maxParts",
|
|
3457
3480
|
"maxPartTokens",
|
|
3458
3481
|
"outDir",
|
|
3459
3482
|
"preset",
|
|
@@ -3652,6 +3675,7 @@ var MIN_MAX_PART_BYTES = 4096;
|
|
|
3652
3675
|
var MIN_MAX_PART_TOKENS = MIN_MAX_PART_BYTES / 4;
|
|
3653
3676
|
var ARTIFACT_NAMES = [
|
|
3654
3677
|
"readme",
|
|
3678
|
+
"prompt",
|
|
3655
3679
|
"manifest",
|
|
3656
3680
|
"parts",
|
|
3657
3681
|
"navigation",
|
|
@@ -3661,6 +3685,7 @@ var ARTIFACT_NAMES = [
|
|
|
3661
3685
|
];
|
|
3662
3686
|
var DEFAULT_ARTIFACTS = {
|
|
3663
3687
|
readme: true,
|
|
3688
|
+
prompt: true,
|
|
3664
3689
|
manifest: true,
|
|
3665
3690
|
parts: true,
|
|
3666
3691
|
navigation: true,
|
|
@@ -3721,6 +3746,25 @@ function resolveArtifacts(requested, skipped, includeMonolith, monolithOverride,
|
|
|
3721
3746
|
}
|
|
3722
3747
|
return artifacts;
|
|
3723
3748
|
}
|
|
3749
|
+
var DEFAULT_ATTACHMENT_SLOTS = 10;
|
|
3750
|
+
function resolveAttachmentSlots(value) {
|
|
3751
|
+
if (value === void 0 || value === null) return DEFAULT_ATTACHMENT_SLOTS;
|
|
3752
|
+
if (typeof value !== "number" || !Number.isInteger(value) || value < 0) {
|
|
3753
|
+
throw new Error(
|
|
3754
|
+
"attachmentSlots must be a whole number, with 0 meaning no limit (received " + describeValue2(value) + ")."
|
|
3755
|
+
);
|
|
3756
|
+
}
|
|
3757
|
+
return value;
|
|
3758
|
+
}
|
|
3759
|
+
function resolveMaxParts(value) {
|
|
3760
|
+
if (value === void 0 || value === null) return null;
|
|
3761
|
+
if (typeof value !== "number" || !Number.isInteger(value) || value < 1) {
|
|
3762
|
+
throw new Error(
|
|
3763
|
+
"maxParts must be a whole number of parts, or null to disable it (received " + describeValue2(value) + ")."
|
|
3764
|
+
);
|
|
3765
|
+
}
|
|
3766
|
+
return value;
|
|
3767
|
+
}
|
|
3724
3768
|
function strictPositiveInteger(value, fallback, label) {
|
|
3725
3769
|
if (value === void 0) return fallback;
|
|
3726
3770
|
if (typeof value !== "number" || !Number.isInteger(value) || value <= 0) {
|
|
@@ -4099,6 +4143,10 @@ function resolveConfig(userConfig, cliOptions, baseDir) {
|
|
|
4099
4143
|
"maxMonolithBytes"
|
|
4100
4144
|
),
|
|
4101
4145
|
includeSensitiveFiles,
|
|
4146
|
+
attachmentSlots: resolveAttachmentSlots(
|
|
4147
|
+
cliOptions?.attachmentSlots ?? userConfig?.attachmentSlots
|
|
4148
|
+
),
|
|
4149
|
+
maxParts: resolveMaxParts(cliOptions?.maxParts ?? userConfig?.maxParts),
|
|
4102
4150
|
...changedSince === void 0 ? {} : { changedSince },
|
|
4103
4151
|
...staged ? { staged } : {},
|
|
4104
4152
|
...withDependents ? { withDependents } : {},
|
|
@@ -4181,6 +4229,9 @@ function configDigest(config) {
|
|
|
4181
4229
|
includeMonolith: config.includeMonolith,
|
|
4182
4230
|
maxMonolithBytes: config.maxMonolithBytes ?? null,
|
|
4183
4231
|
includeSensitiveFiles: config.includeSensitiveFiles,
|
|
4232
|
+
// Only when the experimental mode is on: `null` is the off switch, and writing it into the
|
|
4233
|
+
// material would change the digest of every snapshot taken before the setting existed.
|
|
4234
|
+
...config.maxParts === null ? {} : { maxParts: config.maxParts },
|
|
4184
4235
|
artifacts: config.artifacts,
|
|
4185
4236
|
include: config.include,
|
|
4186
4237
|
excludePatterns: config.excludePatterns,
|
|
@@ -6790,7 +6841,8 @@ function validateSnapshot(configInput) {
|
|
|
6790
6841
|
);
|
|
6791
6842
|
}
|
|
6792
6843
|
}
|
|
6793
|
-
|
|
6844
|
+
const ceilingDerivedByMaxParts = (manifest.config?.maxParts ?? null) !== null;
|
|
6845
|
+
if (!ceilingDerivedByMaxParts && manifest.budgets && manifest.budgets.maxPartBytes !== config.maxPartBytes) {
|
|
6794
6846
|
totalsMismatches.push(
|
|
6795
6847
|
`budgets.maxPartBytes: manifest ${manifest.budgets.maxPartBytes} vs current ${config.maxPartBytes}`
|
|
6796
6848
|
);
|
|
@@ -6819,6 +6871,7 @@ function validateSnapshot(configInput) {
|
|
|
6819
6871
|
}
|
|
6820
6872
|
const declaredArtifacts = [
|
|
6821
6873
|
["README.md", manifest.artifacts?.readme],
|
|
6874
|
+
["PROMPT.md", manifest.artifacts?.prompt],
|
|
6822
6875
|
["reports/navigation.md", manifest.artifacts?.navigation],
|
|
6823
6876
|
["reports/project-tree.md", manifest.artifacts?.projectTree],
|
|
6824
6877
|
["reports/audit.md", manifest.artifacts?.audit],
|
|
@@ -7770,6 +7823,7 @@ var DEFAULT_ANSWERS = {
|
|
|
7770
7823
|
excludePatterns: [],
|
|
7771
7824
|
artifacts: {
|
|
7772
7825
|
readme: true,
|
|
7826
|
+
prompt: true,
|
|
7773
7827
|
manifest: true,
|
|
7774
7828
|
parts: true,
|
|
7775
7829
|
navigation: true,
|
|
@@ -7886,6 +7940,7 @@ function renderConfig(answers) {
|
|
|
7886
7940
|
// \u2500\u2500 Artifacts \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
|
|
7887
7941
|
artifacts: {
|
|
7888
7942
|
readme: ${artifacts.readme}, // README.md
|
|
7943
|
+
prompt: ${artifacts.prompt}, // PROMPT.md \u2014 the instruction sheet a model is given
|
|
7889
7944
|
manifest: ${artifacts.manifest}, // manifest.json \u2014 required by validate and report
|
|
7890
7945
|
parts: ${artifacts.parts}, // parts/part-XXX.md
|
|
7891
7946
|
navigation: ${artifacts.navigation}, // reports/navigation.md
|
|
@@ -7901,6 +7956,11 @@ function renderConfig(answers) {
|
|
|
7901
7956
|
includeMonolith: ${artifacts.monolith},
|
|
7902
7957
|
|
|
7903
7958
|
// \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
|
|
7959
|
+
// Files your destination accepts in one message, used by PROMPT.md to plan the delivery.
|
|
7960
|
+
// attachmentSlots: 10,
|
|
7961
|
+
// Experimental: grow the per-part budget until the snapshot fits this many parts, instead of
|
|
7962
|
+
// adding a part as the code grows. The plan in PROMPT.md becomes a fixed-length attachment list.
|
|
7963
|
+
// maxParts: 10,
|
|
7904
7964
|
// afterGenerate: (manifest) => { /* write your own artifact */ }
|
|
7905
7965
|
hooks: {},
|
|
7906
7966
|
};
|
|
@@ -8594,6 +8654,7 @@ async function runInit(options) {
|
|
|
8594
8654
|
let lastScope = "all";
|
|
8595
8655
|
const artifactChoices = [
|
|
8596
8656
|
{ value: "readme", label: "README.md", hint: "orientation page" },
|
|
8657
|
+
{ value: "prompt", label: "PROMPT.md", hint: "instruction sheet for the model" },
|
|
8597
8658
|
{ value: "manifest", label: "manifest.json", hint: "required by validate and report" },
|
|
8598
8659
|
{ value: "parts", label: "parts/", hint: "the code payload" },
|
|
8599
8660
|
{ value: "navigation", label: "reports/navigation.md", hint: "file \u2192 part index" },
|
|
@@ -9709,10 +9770,420 @@ function generateNavigation(manifest) {
|
|
|
9709
9770
|
return lines.join("\n");
|
|
9710
9771
|
}
|
|
9711
9772
|
|
|
9773
|
+
// src/generator/prompt.ts
|
|
9774
|
+
var MAX_PART_ROWS = 16;
|
|
9775
|
+
var MAX_LAYER_ROWS = 8;
|
|
9776
|
+
var MAX_INCOMPLETE_ROWS = 50;
|
|
9777
|
+
var MAX_CENTRAL_FILES = 5;
|
|
9778
|
+
var MAX_ENTRY_POINTS = 4;
|
|
9779
|
+
var MAX_LARGEST_FILES = 3;
|
|
9780
|
+
var partWord = (count) => count === 1 ? "part" : "parts";
|
|
9781
|
+
var UNLIMITED_SLOTS = 0;
|
|
9782
|
+
var ENTRY_POINT = /(^|\/)(index|cli|main|bin|server|app|mod)\.[cm]?[jt]sx?$/;
|
|
9783
|
+
var TEST_PATH = /(^|\/)(tests?|__tests__)\//;
|
|
9784
|
+
var TEST_FILE = /\.(test|spec)\.[^.]+$/;
|
|
9785
|
+
function generatePrompt(manifest, artifacts, attachmentSlots = DEFAULT_ATTACHMENT_SLOTS, history = []) {
|
|
9786
|
+
const wrote = (name) => artifacts?.[name] !== false;
|
|
9787
|
+
const code = (value) => inlineCode(escapeControls(value));
|
|
9788
|
+
const lines = [
|
|
9789
|
+
"# PROMPT.md",
|
|
9790
|
+
"",
|
|
9791
|
+
"The brief and the apparatus for this snapshot. Paste this file first, then the parts it names.",
|
|
9792
|
+
"",
|
|
9793
|
+
"It is generated rather than written once: the system map, the omissions, the fingerprint and",
|
|
9794
|
+
"the history below are read from `manifest.json` and this repository, so they describe this run.",
|
|
9795
|
+
"Regenerate it after the code moves.",
|
|
9796
|
+
"",
|
|
9797
|
+
"---",
|
|
9798
|
+
"",
|
|
9799
|
+
"```text",
|
|
9800
|
+
"You are working on a codebase you cannot clone, run or grep. Everything you know about it comes",
|
|
9801
|
+
"from the snapshot that follows this instruction. Where these notes and the snapshot disagree,",
|
|
9802
|
+
"the snapshot is what exists.",
|
|
9803
|
+
"",
|
|
9804
|
+
"## The job",
|
|
9805
|
+
"",
|
|
9806
|
+
"Find what is still wrong or will break. How you read the code is yours to decide - by",
|
|
9807
|
+
"subsystem, by data flow, by the invariants you derive yourself. What you owe in return is an",
|
|
9808
|
+
"honest account of what you covered and what you did not.",
|
|
9809
|
+
"",
|
|
9810
|
+
history.length > 0 ? "Another pass of the same findings is worth nothing. This repository carries a record of" : "Another pass of the same findings is worth nothing, but no earlier round is readable here,",
|
|
9811
|
+
history.length > 0 ? "what was already fixed, below. Verify that those fixes hold instead of rediscovering them," : "so you cannot tell what has already been tried. Do not assume this is the first attempt.",
|
|
9812
|
+
history.length > 0 ? "and treat a variant of one at a different call site as a new finding." : "Every finding you report has to stand on the code alone.",
|
|
9813
|
+
"",
|
|
9814
|
+
"If the task at the end asks for something narrower - explain a file, review a change, answer a",
|
|
9815
|
+
"question - that task wins. The standard and the coverage duty below still apply to it.",
|
|
9816
|
+
""
|
|
9817
|
+
];
|
|
9818
|
+
lines.push(...haveSection(wrote), "");
|
|
9819
|
+
lines.push(...systemSection(manifest, code), "");
|
|
9820
|
+
lines.push(...historySection(history), "");
|
|
9821
|
+
lines.push(...barSection(), "");
|
|
9822
|
+
lines.push(...coverageSection(manifest, code, wrote("audit")), "");
|
|
9823
|
+
lines.push(...answerSection(), "");
|
|
9824
|
+
lines.push(...calibrationSection(), "");
|
|
9825
|
+
lines.push(...snapshotSection(manifest, code), "");
|
|
9826
|
+
lines.push(...deliverySection(manifest, wrote("parts"), attachmentSlots));
|
|
9827
|
+
lines.push(
|
|
9828
|
+
"## Your task",
|
|
9829
|
+
"",
|
|
9830
|
+
"<replace with the question, the area to review, or the subsystem to audit>",
|
|
9831
|
+
"```"
|
|
9832
|
+
);
|
|
9833
|
+
lines.push(
|
|
9834
|
+
"",
|
|
9835
|
+
"---",
|
|
9836
|
+
"",
|
|
9837
|
+
"## Why this file exists",
|
|
9838
|
+
"",
|
|
9839
|
+
"Parts on their own are a dump: the model receives text, has no idea what was left out of it,",
|
|
9840
|
+
"and fills the gap by invention. A brief on its own is a wish list: it cannot say which files",
|
|
9841
|
+
"are present, which are partial or which part holds what. This file is both halves, and the",
|
|
9842
|
+
"facts in it move with the snapshot.",
|
|
9843
|
+
"",
|
|
9844
|
+
"## Keeping it true",
|
|
9845
|
+
"",
|
|
9846
|
+
"- It is one of the artifacts recorded in `manifest.json` under `artifacts.prompt`, so deleting",
|
|
9847
|
+
" or editing `PROMPT.md` makes `snapshot validate` fail.",
|
|
9848
|
+
"- `--skip-artifacts prompt`, or `artifacts: { prompt: false }` in the config, turns it off.",
|
|
9849
|
+
"- The history section disappears when git cannot be read, rather than being invented.",
|
|
9850
|
+
"- If the code moves, regenerate. A brief naming the previous run parts is worse than no",
|
|
9851
|
+
" brief, because it reads as current.",
|
|
9852
|
+
""
|
|
9853
|
+
);
|
|
9854
|
+
return lines.join("\n");
|
|
9855
|
+
}
|
|
9856
|
+
function haveSection(wrote) {
|
|
9857
|
+
const out = ["## What you have", ""];
|
|
9858
|
+
const bullets = [];
|
|
9859
|
+
if (wrote("readme")) {
|
|
9860
|
+
bullets.push("- `README.md` - orientation: metrics, the part table, and the fingerprint.");
|
|
9861
|
+
}
|
|
9862
|
+
if (wrote("manifest")) {
|
|
9863
|
+
bullets.push(
|
|
9864
|
+
"- `manifest.json` - the index. Per file: `relativePath`, `layer`, `kind`, `language`,",
|
|
9865
|
+
" `part`, `sha256`, `inclusionMode`, `truncationReason`, `omittedRanges`. It also carries",
|
|
9866
|
+
" every excluded path under `skipped[]` with its reason, and `incomplete[]`, which names",
|
|
9867
|
+
" every included file whose emitted body is not the whole file."
|
|
9868
|
+
);
|
|
9869
|
+
}
|
|
9870
|
+
if (wrote("navigation")) {
|
|
9871
|
+
bullets.push("- `reports/navigation.md` - file to part. Locate here before you read anything.");
|
|
9872
|
+
}
|
|
9873
|
+
if (wrote("projectTree")) {
|
|
9874
|
+
bullets.push("- `reports/project-tree.md` - the directory shape of what was included.");
|
|
9875
|
+
}
|
|
9876
|
+
if (wrote("audit")) {
|
|
9877
|
+
bullets.push(
|
|
9878
|
+
"- `reports/audit.md` - secret findings, the files whose lines were redacted, large files,",
|
|
9879
|
+
" parse diagnostics and the git state the snapshot was taken from."
|
|
9880
|
+
);
|
|
9881
|
+
}
|
|
9882
|
+
if (wrote("parts")) {
|
|
9883
|
+
bullets.push(
|
|
9884
|
+
"- `parts/part-NNN.md` - the code itself, split to a fixed byte budget. Each part states its",
|
|
9885
|
+
" own number, the files it contains, and the fingerprint it was built from."
|
|
9886
|
+
);
|
|
9887
|
+
}
|
|
9888
|
+
if (wrote("monolith")) {
|
|
9889
|
+
bullets.push(
|
|
9890
|
+
"- `full-codebase.json` and `full-codebase.md` - the entire payload in one file each.",
|
|
9891
|
+
" Where they are present, they supersede the parts: nothing was left out of them."
|
|
9892
|
+
);
|
|
9893
|
+
}
|
|
9894
|
+
if (bullets.length === 0) {
|
|
9895
|
+
bullets.push(
|
|
9896
|
+
"- Nothing but this brief: every code artifact was disabled for this run. Ask for a snapshot",
|
|
9897
|
+
" generated with the artifacts you need, and do not answer from memory."
|
|
9898
|
+
);
|
|
9899
|
+
}
|
|
9900
|
+
out.push(...bullets);
|
|
9901
|
+
return out;
|
|
9902
|
+
}
|
|
9903
|
+
function systemSection(manifest, code) {
|
|
9904
|
+
const out = ["## The system", ""];
|
|
9905
|
+
const layers = Object.entries(manifest.layers).sort((a, b) => b[1] - a[1] || a[0].localeCompare(b[0]));
|
|
9906
|
+
if (layers.length > 0) {
|
|
9907
|
+
const shown = layers.slice(0, MAX_LAYER_ROWS).map(([name, count]) => code(name) + " " + formatNumber(count));
|
|
9908
|
+
const rest = layers.length > MAX_LAYER_ROWS ? ", and " + formatNumber(layers.length - MAX_LAYER_ROWS) + " more" : "";
|
|
9909
|
+
out.push("- Layers, by file count: " + shown.join(", ") + rest + ".");
|
|
9910
|
+
}
|
|
9911
|
+
const central = manifest.indexes.imports.centralFiles;
|
|
9912
|
+
if (central.length > 0) {
|
|
9913
|
+
const shown = central.slice(0, MAX_CENTRAL_FILES).map((entry) => code(entry.path) + " (" + formatNumber(entry.importedByCount) + ")").join(", ");
|
|
9914
|
+
out.push(
|
|
9915
|
+
"- Load-bearing modules, by how many files import them: " + shown + ".",
|
|
9916
|
+
" A change here reaches the most call sites; read it before judging anything that uses it."
|
|
9917
|
+
);
|
|
9918
|
+
}
|
|
9919
|
+
const entryPoints = manifest.files.map((file) => file.relativePath).filter((path22) => ENTRY_POINT.test(path22)).sort((a, b) => a.split("/").length - b.split("/").length || a.length - b.length).slice(0, MAX_ENTRY_POINTS);
|
|
9920
|
+
out.push(
|
|
9921
|
+
entryPoints.length > 0 ? "- Entry points by convention: " + entryPoints.map(code).join(", ") + "." : "- No entry point was identifiable by name. The largest files below are where execution"
|
|
9922
|
+
);
|
|
9923
|
+
if (entryPoints.length === 0) out.push(" starts, and the call graph in `manifest.json` is the map.");
|
|
9924
|
+
const routes = manifest.indexes.routes.length;
|
|
9925
|
+
const handlers = manifest.indexes.handlers.length;
|
|
9926
|
+
const components = manifest.indexes.components.length;
|
|
9927
|
+
const routesShown = manifest.indexes.routes.slice(0, 4).map((route) => code(route.path));
|
|
9928
|
+
const componentsShown = manifest.indexes.components.slice(0, 4).map((entry) => code(entry.path));
|
|
9929
|
+
if (routes + handlers + components === 0) {
|
|
9930
|
+
out.push(
|
|
9931
|
+
"- No routes, handlers or UI components were recorded: this snapshot indexes no HTTP or",
|
|
9932
|
+
" component surface. Do not go looking for one, and do not infer one from a file name."
|
|
9933
|
+
);
|
|
9934
|
+
} else {
|
|
9935
|
+
const parts = [];
|
|
9936
|
+
if (routes > 0) parts.push(formatNumber(routes) + " route(s), e.g. " + routesShown.join(", "));
|
|
9937
|
+
if (handlers > 0) parts.push(formatNumber(handlers) + " handler(s)");
|
|
9938
|
+
if (components > 0) parts.push(formatNumber(components) + " component(s), e.g. " + componentsShown.join(", "));
|
|
9939
|
+
out.push("- Surfaces the index found: " + parts.join("; ") + ".");
|
|
9940
|
+
}
|
|
9941
|
+
const largest = [...manifest.files].sort((a, b) => b.includedBytes - a.includedBytes).slice(0, MAX_LARGEST_FILES);
|
|
9942
|
+
if (largest.length > 0) {
|
|
9943
|
+
out.push(
|
|
9944
|
+
"- Largest files: " + largest.map((file) => code(file.relativePath) + " (" + formatNumber(Math.round(file.includedBytes / 1024)) + " KB)").join(", ") + "."
|
|
9945
|
+
);
|
|
9946
|
+
}
|
|
9947
|
+
const tests = manifest.files.filter(
|
|
9948
|
+
(file) => TEST_PATH.test(file.relativePath) || TEST_FILE.test(file.relativePath)
|
|
9949
|
+
);
|
|
9950
|
+
if (tests.length > 0) {
|
|
9951
|
+
const testBytes = tests.reduce((total, file) => total + file.includedBytes, 0);
|
|
9952
|
+
const allBytes = manifest.files.reduce((total, file) => total + file.includedBytes, 0);
|
|
9953
|
+
const share = allBytes === 0 ? 0 : Math.round(testBytes / allBytes * 100);
|
|
9954
|
+
out.push(
|
|
9955
|
+
"- Tests: " + formatNumber(tests.length) + " file(s), " + share + "% of the included bytes.",
|
|
9956
|
+
" They are evidence of intent, not of behaviour: a fixture can encode a payload shape the",
|
|
9957
|
+
" real system never sends."
|
|
9958
|
+
);
|
|
9959
|
+
}
|
|
9960
|
+
return out;
|
|
9961
|
+
}
|
|
9962
|
+
function historySection(history) {
|
|
9963
|
+
const out = ["## What came before", ""];
|
|
9964
|
+
if (history.length === 0) {
|
|
9965
|
+
out.push(
|
|
9966
|
+
"No history was readable: this is not a git checkout, or git could not be run. Nothing about",
|
|
9967
|
+
"what came before can be claimed from here, and that is not evidence that the code is new."
|
|
9968
|
+
);
|
|
9969
|
+
return out;
|
|
9970
|
+
}
|
|
9971
|
+
out.push(
|
|
9972
|
+
"Commit subjects, newest first. They are claims by whoever wrote them, not evidence - the code",
|
|
9973
|
+
"beside them is the evidence. If one of these fixes looks incomplete, quote the lines and say",
|
|
9974
|
+
"which call site it missed.",
|
|
9975
|
+
""
|
|
9976
|
+
);
|
|
9977
|
+
for (const subject of history) out.push("- " + subject);
|
|
9978
|
+
return out;
|
|
9979
|
+
}
|
|
9980
|
+
function barSection() {
|
|
9981
|
+
return [
|
|
9982
|
+
"## The bar",
|
|
9983
|
+
"",
|
|
9984
|
+
"A finding is a concrete way the code breaks or lies, supported by quoted lines: the path and",
|
|
9985
|
+
"line, the input or state that reaches it, what happens next, and why the guard that appears to",
|
|
9986
|
+
"stop it does not. A comment is not behaviour. A passing test is evidence of intent, not of",
|
|
9987
|
+
"behaviour.",
|
|
9988
|
+
"",
|
|
9989
|
+
"- No style, naming, formatting, add-types, add-tests, consider-X or speculative rewrites.",
|
|
9990
|
+
"- Never invent a finding to fill a section. A clean surface is proven by quoting the guard",
|
|
9991
|
+
" that makes it clean.",
|
|
9992
|
+
"- Mark confidence, and name the check - a test, a run, an input - that would settle anything",
|
|
9993
|
+
" you cannot decide by reading.",
|
|
9994
|
+
"- Separate what the code does from what the deployment or configuration does. Both are",
|
|
9995
|
+
" findings; they have different owners and different fixes."
|
|
9996
|
+
];
|
|
9997
|
+
}
|
|
9998
|
+
function coverageSection(manifest, code, auditWritten) {
|
|
9999
|
+
const out = ["## Coverage", ""];
|
|
10000
|
+
const reasons = /* @__PURE__ */ new Map();
|
|
10001
|
+
for (const record of manifest.skipped) {
|
|
10002
|
+
reasons.set(record.reason, (reasons.get(record.reason) ?? 0) + 1);
|
|
10003
|
+
}
|
|
10004
|
+
const tally = [...reasons.entries()].sort((a, b) => b[1] - a[1] || a[0].localeCompare(b[0])).map(([reason, count]) => code(reason) + " " + formatNumber(count)).join(", ");
|
|
10005
|
+
out.push(
|
|
10006
|
+
"- " + formatNumber(manifest.totals.candidateFiles) + " path(s) were found; " + formatNumber(manifest.totals.includedFiles) + " are in the parts and " + formatNumber(manifest.counts.skippedCount) + " were skipped" + (tally.length > 0 ? " (" + tally + ")" : "") + ".",
|
|
10007
|
+
" `manifest.skipped[]` names each one and why. An absent path is not a clean path."
|
|
10008
|
+
);
|
|
10009
|
+
out.push(...incompleteSection(manifest, code));
|
|
10010
|
+
out.push(...redactionSection(manifest, auditWritten));
|
|
10011
|
+
out.push(
|
|
10012
|
+
"- Everything unseen is unread, never clean. If you were given only some of the parts, say",
|
|
10013
|
+
" which ones are missing before you answer. A file the index names but the parts do not carry",
|
|
10014
|
+
" is an input defect, not a code finding - report it as one."
|
|
10015
|
+
);
|
|
10016
|
+
return out;
|
|
10017
|
+
}
|
|
10018
|
+
function answerSection() {
|
|
10019
|
+
return [
|
|
10020
|
+
"## What a useful answer contains",
|
|
10021
|
+
"",
|
|
10022
|
+
"- An opening line, filled from This snapshot below:",
|
|
10023
|
+
"",
|
|
10024
|
+
" snapshot <fingerprint> generated <generatedAt>",
|
|
10025
|
+
"",
|
|
10026
|
+
"- What you read and what you did not, named by path or by part.",
|
|
10027
|
+
"- Findings ordered by consequence, each with the lines quoted.",
|
|
10028
|
+
"- The checks or attacks that failed, and the line or guard that blocked them. A failed attack",
|
|
10029
|
+
" is how anyone knows an invariant is real rather than asserted.",
|
|
10030
|
+
"- What you retracted after re-reading.",
|
|
10031
|
+
"- What only a run, a test or a host can settle, and the check that would settle each.",
|
|
10032
|
+
"- One paragraph on the failure you would bet on next.",
|
|
10033
|
+
"- A closing line: Needed but not received: <paths>, or none. That line is not decoration -",
|
|
10034
|
+
" an invented function is indistinguishable from a real one, and this is where you name",
|
|
10035
|
+
" the gap you filled by asking instead of guessing."
|
|
10036
|
+
];
|
|
10037
|
+
}
|
|
10038
|
+
function calibrationSection() {
|
|
10039
|
+
return [
|
|
10040
|
+
"## Calibration",
|
|
10041
|
+
"",
|
|
10042
|
+
"The findings that matter here do not crash. They look like:",
|
|
10043
|
+
"",
|
|
10044
|
+
"- a guard applied at one call site and not its twin - the route checks, the timer does not;",
|
|
10045
|
+
"- a budget shorter than the work it guards, so the caller gives up while the work continues;",
|
|
10046
|
+
"- a success flag that means the call returned, consumed as the change happened;",
|
|
10047
|
+
"- a document that describes a different run than the one beside it;",
|
|
10048
|
+
"- a default that fabricates a number when the measurement failed.",
|
|
10049
|
+
"",
|
|
10050
|
+
"None of these throw. All are invisible in a summary."
|
|
10051
|
+
];
|
|
10052
|
+
}
|
|
10053
|
+
function snapshotSection(manifest, code) {
|
|
10054
|
+
const out = ["## This snapshot", ""];
|
|
10055
|
+
out.push("- Fingerprint: " + code(manifest.fingerprint) + " - quote it verbatim in your answer.");
|
|
10056
|
+
out.push(
|
|
10057
|
+
"- Generated: " + code(manifest.generatedAt) + " from branch " + code(manifest.git.branch) + " at commit " + code(manifest.git.commit.slice(0, 8)) + "."
|
|
10058
|
+
);
|
|
10059
|
+
out.push(
|
|
10060
|
+
manifest.git.isDirty ? " The working tree had uncommitted changes at generation time." : " The working tree was clean at generation time."
|
|
10061
|
+
);
|
|
10062
|
+
out.push(
|
|
10063
|
+
"- Validation: `manifest.validation.status` was " + code(manifest.validation.status) + " at generation time.",
|
|
10064
|
+
" That describes the run, not now: if the tree may have moved since, the snapshot is a",
|
|
10065
|
+
" claim that needs re-checking, not a fact."
|
|
10066
|
+
);
|
|
10067
|
+
if (manifest.parts.length > 0) {
|
|
10068
|
+
out.push(
|
|
10069
|
+
"- Parts: " + formatNumber(manifest.parts.length) + " at a " + formatNumber(Math.round(manifest.budgets.maxPartBytes / 1024)) + " KB ceiling" + (manifest.parts.length === 1 ? ":" : " each:")
|
|
10070
|
+
);
|
|
10071
|
+
for (const part of manifest.parts.slice(0, MAX_PART_ROWS)) {
|
|
10072
|
+
out.push(" - " + code(part.filename) + " - " + formatNumber(part.fileCount) + " file(s)");
|
|
10073
|
+
}
|
|
10074
|
+
if (manifest.parts.length > MAX_PART_ROWS) {
|
|
10075
|
+
out.push(
|
|
10076
|
+
" - and " + formatNumber(manifest.parts.length - MAX_PART_ROWS) + " more, tabled in `README.md`"
|
|
10077
|
+
);
|
|
10078
|
+
}
|
|
10079
|
+
}
|
|
10080
|
+
return out;
|
|
10081
|
+
}
|
|
10082
|
+
function incompleteSection(manifest, code) {
|
|
10083
|
+
const out = [];
|
|
10084
|
+
const list2 = manifest.incomplete;
|
|
10085
|
+
if (list2.length === 0) {
|
|
10086
|
+
out.push("- Partial files: none. Every included file is present in full.");
|
|
10087
|
+
return out;
|
|
10088
|
+
}
|
|
10089
|
+
out.push(
|
|
10090
|
+
"- Partial files: " + formatNumber(list2.length) + ". These are present only in part, and the",
|
|
10091
|
+
" missing lines are named, not implied:"
|
|
10092
|
+
);
|
|
10093
|
+
for (const entry of list2.slice(0, MAX_INCOMPLETE_ROWS)) {
|
|
10094
|
+
const ranges = entry.omittedRanges.map(([start, end]) => start === end ? String(start) : start + "-" + end).join(", ");
|
|
10095
|
+
out.push(
|
|
10096
|
+
" - " + code(entry.relativePath) + " in " + code(entry.part) + " - " + entry.reason + ", lines " + ranges + " (" + formatNumber(entry.omittedLines) + " of " + formatNumber(entry.lines) + " missing)"
|
|
10097
|
+
);
|
|
10098
|
+
}
|
|
10099
|
+
if (list2.length > MAX_INCOMPLETE_ROWS) {
|
|
10100
|
+
out.push(
|
|
10101
|
+
" - and " + formatNumber(list2.length - MAX_INCOMPLETE_ROWS) + " more, all named in `manifest.json` under `incomplete[]`"
|
|
10102
|
+
);
|
|
10103
|
+
}
|
|
10104
|
+
return out;
|
|
10105
|
+
}
|
|
10106
|
+
function redactionSection(manifest, auditWritten) {
|
|
10107
|
+
const redacted = manifest.totals.redactedLines;
|
|
10108
|
+
if (redacted === 0) {
|
|
10109
|
+
return ["- Redacted: no line matched a secret rule."];
|
|
10110
|
+
}
|
|
10111
|
+
const where = auditWritten ? "`reports/audit.md` names the files; the values are not recoverable from it." : "`reports/audit.md` was disabled for this run, so only the count is available.";
|
|
10112
|
+
return [
|
|
10113
|
+
"- Redacted: " + formatNumber(redacted) + " line(s) had values masked before you received them.",
|
|
10114
|
+
" A masked span is a deliberate redaction, not an empty value.",
|
|
10115
|
+
" " + where
|
|
10116
|
+
];
|
|
10117
|
+
}
|
|
10118
|
+
function deliverySection(manifest, partsWritten, slots) {
|
|
10119
|
+
if (!partsWritten || manifest.parts.length === 0) return [];
|
|
10120
|
+
const parts = manifest.parts.length;
|
|
10121
|
+
const wholeSet = parts + 5;
|
|
10122
|
+
const unlimited = slots <= UNLIMITED_SLOTS;
|
|
10123
|
+
const out = ["## Attaching this", ""];
|
|
10124
|
+
out.push(
|
|
10125
|
+
"Paste this file as text: instructions cost no attachment slot. Attach the files it names.",
|
|
10126
|
+
"",
|
|
10127
|
+
"- Every part opens with `# Codebase Snapshot Part NNN of MMM` and repeats the fingerprint",
|
|
10128
|
+
" above, so check both before relying on one. A part you were not given is not an empty part."
|
|
10129
|
+
);
|
|
10130
|
+
if (unlimited) {
|
|
10131
|
+
out.push(
|
|
10132
|
+
"- No attachment limit is configured, so every file can travel: " + parts + " " + partWord(parts) + " plus `manifest.json`, `README.md` and the three reports (" + wholeSet + " files)."
|
|
10133
|
+
);
|
|
10134
|
+
} else if (wholeSet <= slots) {
|
|
10135
|
+
out.push(
|
|
10136
|
+
"- A " + slots + "-file destination carries the whole set: " + parts + " " + partWord(parts) + " plus `manifest.json`, `README.md` and the three reports - " + wholeSet + " of " + slots + "."
|
|
10137
|
+
);
|
|
10138
|
+
} else if (parts + 1 <= slots) {
|
|
10139
|
+
out.push(
|
|
10140
|
+
"- A " + slots + "-file destination carries " + parts + " " + partWord(parts) + " and",
|
|
10141
|
+
" `manifest.json` (" + (parts + 1) + " of " + slots + "); `README.md` and",
|
|
10142
|
+
" `reports/` stay behind - the brief above carries what they add."
|
|
10143
|
+
);
|
|
10144
|
+
} else if (parts <= slots) {
|
|
10145
|
+
out.push(
|
|
10146
|
+
parts === 1 ? "- The only part fills a " + slots + "-file destination, so `manifest.json` and" : "- The " + parts + " parts fill a " + slots + "-file destination, so `manifest.json` and",
|
|
10147
|
+
" `reports/` stay behind. The brief above carries what they add."
|
|
10148
|
+
);
|
|
10149
|
+
if (parts > 1) {
|
|
10150
|
+
out.push(
|
|
10151
|
+
" Either raise `--max-part-bytes` to merge the parts, or set `--max-parts " + slots + "` and let the parts grow to the count instead."
|
|
10152
|
+
);
|
|
10153
|
+
}
|
|
10154
|
+
} else {
|
|
10155
|
+
out.push(
|
|
10156
|
+
"- The " + parts + " parts do not fit a " + slots + "-file destination: at most " + slots + " can be attached.",
|
|
10157
|
+
" Choose by task - `reports/navigation.md` maps a file to its part - and name the parts",
|
|
10158
|
+
" you left out, or regenerate with `--max-part-bytes " + suggestBudgetBytes(manifest, slots) + "` for about " + (slots - 1) + " parts. `--max-parts " + slots + "` grows the parts until",
|
|
10159
|
+
" they fit instead, and says so when they end up larger than maxPartBytes."
|
|
10160
|
+
);
|
|
10161
|
+
}
|
|
10162
|
+
out.push(
|
|
10163
|
+
"- If you were given only some of them, say which parts are missing before you answer, and",
|
|
10164
|
+
" name the files you needed. Do not infer the contents of a part you did not receive.",
|
|
10165
|
+
""
|
|
10166
|
+
);
|
|
10167
|
+
return out;
|
|
10168
|
+
}
|
|
10169
|
+
function suggestBudgetBytes(manifest, slots) {
|
|
10170
|
+
const total = manifest.parts.reduce((sum, part) => sum + part.byteSize, 0);
|
|
10171
|
+
const target = Math.max(1, slots - 1);
|
|
10172
|
+
const estimated = Math.ceil(total / target * 1.15);
|
|
10173
|
+
const rounded = Math.ceil(estimated / 16384) * 16384;
|
|
10174
|
+
const budget = Math.max(rounded, manifest.budgets.maxPartBytes);
|
|
10175
|
+
return Math.round(budget / 1024) + "k";
|
|
10176
|
+
}
|
|
10177
|
+
|
|
9712
10178
|
// src/generator/readme.ts
|
|
9713
10179
|
function generateReadme(manifest, artifacts) {
|
|
9714
10180
|
const wrote = (name) => artifacts?.[name] !== false;
|
|
9715
10181
|
const reportLinks = [];
|
|
10182
|
+
if (wrote("prompt")) {
|
|
10183
|
+
reportLinks.push(
|
|
10184
|
+
"- [PROMPT.md](PROMPT.md) \u2014 The instruction sheet to paste with this snapshot: what it contains, what it left out, and the rules for citing it."
|
|
10185
|
+
);
|
|
10186
|
+
}
|
|
9716
10187
|
if (wrote("navigation")) {
|
|
9717
10188
|
reportLinks.push(
|
|
9718
10189
|
"- [reports/navigation.md](reports/navigation.md) \u2014 Comprehensive file directory mapping files to chunk files."
|
|
@@ -9782,6 +10253,11 @@ function generateReadme(manifest, artifacts) {
|
|
|
9782
10253
|
lines.push("", "## Snapshot Parts", "", "No parts were written for this run.");
|
|
9783
10254
|
}
|
|
9784
10255
|
const readOrder = [];
|
|
10256
|
+
if (wrote("prompt")) {
|
|
10257
|
+
readOrder.push(
|
|
10258
|
+
"1. Hand `PROMPT.md` to the model that receives this snapshot: it names the parts, the partial files and the fingerprint of this run."
|
|
10259
|
+
);
|
|
10260
|
+
}
|
|
9785
10261
|
if (wrote("navigation") || wrote("projectTree")) {
|
|
9786
10262
|
const first = [wrote("navigation") ? "`reports/navigation.md`" : null, wrote("projectTree") ? "`reports/project-tree.md`" : null].filter(Boolean).join(" or ");
|
|
9787
10263
|
readOrder.push(`1. Read ${first} first to locate target features or files.`);
|
|
@@ -11466,7 +11942,55 @@ function runAfterGenerate(config, manifest) {
|
|
|
11466
11942
|
return Promise.resolve(returned).finally(releaseRedirect);
|
|
11467
11943
|
}
|
|
11468
11944
|
function partitionByBudget(files, config, fingerprint) {
|
|
11469
|
-
const
|
|
11945
|
+
const configured = {
|
|
11946
|
+
parts: partitionWithBudgets(files, config.budgets, fingerprint),
|
|
11947
|
+
budgets: config.budgets,
|
|
11948
|
+
maxPartBytes: config.maxPartBytes,
|
|
11949
|
+
warnings: []
|
|
11950
|
+
};
|
|
11951
|
+
const limit = config.maxParts;
|
|
11952
|
+
if (limit === null || !config.artifacts.parts || configured.parts.length <= limit) return configured;
|
|
11953
|
+
const totalBytes = files.reduce((total, file) => total + file.includedBytes, 0);
|
|
11954
|
+
let target = Math.max(config.budgets.default, Math.ceil(totalBytes * 1.15 / limit));
|
|
11955
|
+
const seen = [];
|
|
11956
|
+
let low = config.budgets.default;
|
|
11957
|
+
let fitting = null;
|
|
11958
|
+
for (let pass = 0; pass < 6; pass += 1) {
|
|
11959
|
+
const parts2 = partitionWithBudgets(files, scaleBudgets(config.budgets, target), fingerprint);
|
|
11960
|
+
if (parts2.length <= limit) {
|
|
11961
|
+
fitting = { target, parts: parts2 };
|
|
11962
|
+
break;
|
|
11963
|
+
}
|
|
11964
|
+
seen.push(parts2.length);
|
|
11965
|
+
low = target;
|
|
11966
|
+
target = Math.ceil(target * 1.3);
|
|
11967
|
+
}
|
|
11968
|
+
if (fitting === null) {
|
|
11969
|
+
throw new Error(
|
|
11970
|
+
`maxParts ${limit} could not be met: ${seen.join(", ")} part(s) at budgets up to ${formatNumber(target)} B. Raise maxParts, include fewer files, or drop the setting.`
|
|
11971
|
+
);
|
|
11972
|
+
}
|
|
11973
|
+
for (let step = 0; step < 3 && fitting.target - low > 8192; step += 1) {
|
|
11974
|
+
const middle = Math.round((low + fitting.target) / 2);
|
|
11975
|
+
const parts2 = partitionWithBudgets(files, scaleBudgets(config.budgets, middle), fingerprint);
|
|
11976
|
+
if (parts2.length <= limit) fitting = { target: middle, parts: parts2 };
|
|
11977
|
+
else low = middle;
|
|
11978
|
+
}
|
|
11979
|
+
const { target: chosen, parts } = fitting;
|
|
11980
|
+
const budgets = scaleBudgets(config.budgets, chosen);
|
|
11981
|
+
const maxPartBytes = Math.max(config.maxPartBytes, chosen);
|
|
11982
|
+
const warnings = [
|
|
11983
|
+
`maxParts ${limit}: the part budget grew from ${formatNumber(config.maxPartBytes)} B to ${formatNumber(maxPartBytes)} B, and the snapshot now has ${formatNumber(parts.length)} part(s).`
|
|
11984
|
+
];
|
|
11985
|
+
if (maxPartBytes > config.maxPartBytes) {
|
|
11986
|
+
warnings.push(
|
|
11987
|
+
`maxParts ${limit}: parts are now above the configured maxPartBytes (${formatNumber(config.maxPartBytes)} B). A larger part is more tokens for the destination to take at once, and some destinations cap a single file.`
|
|
11988
|
+
);
|
|
11989
|
+
}
|
|
11990
|
+
return { parts, budgets, maxPartBytes, warnings };
|
|
11991
|
+
}
|
|
11992
|
+
function partitionWithBudgets(files, budgets, fingerprint) {
|
|
11993
|
+
const budgetFor = (file) => budgets.byLayer[file.layer] ?? budgets.default;
|
|
11470
11994
|
const buckets = /* @__PURE__ */ new Map();
|
|
11471
11995
|
for (const file of files) {
|
|
11472
11996
|
const budget = budgetFor(file);
|
|
@@ -11483,6 +12007,18 @@ function partitionByBudget(files, config, fingerprint) {
|
|
|
11483
12007
|
fingerprint
|
|
11484
12008
|
);
|
|
11485
12009
|
}
|
|
12010
|
+
function scaleBudgets(budgets, targetDefault) {
|
|
12011
|
+
const factor = targetDefault / budgets.default;
|
|
12012
|
+
return {
|
|
12013
|
+
default: Math.max(budgets.default, Math.round(targetDefault)),
|
|
12014
|
+
byLayer: Object.fromEntries(
|
|
12015
|
+
Object.entries(budgets.byLayer).map(([name, bytes]) => [
|
|
12016
|
+
name,
|
|
12017
|
+
Math.max(bytes, Math.round(bytes * factor))
|
|
12018
|
+
])
|
|
12019
|
+
)
|
|
12020
|
+
};
|
|
12021
|
+
}
|
|
11486
12022
|
function generateSnapshot(configInput, options) {
|
|
11487
12023
|
assertUsableConfigInput(configInput);
|
|
11488
12024
|
const config = isResolvedConfig(configInput) ? normalizeResolvedConfig(configInput) : resolveConfig(configInput ?? null);
|
|
@@ -11811,7 +12347,8 @@ function generateSnapshot(configInput, options) {
|
|
|
11811
12347
|
);
|
|
11812
12348
|
}
|
|
11813
12349
|
}
|
|
11814
|
-
const
|
|
12350
|
+
const partitioned = partitionByBudget(files, config, fingerprint);
|
|
12351
|
+
const parts = partitioned.parts;
|
|
11815
12352
|
const truncatedPreviewCount = files.filter((file) => file.isPreviewTruncated).length;
|
|
11816
12353
|
const incomplete = files.flatMap((file) => {
|
|
11817
12354
|
if (file.truncationReason === void 0) return [];
|
|
@@ -11848,7 +12385,10 @@ function generateSnapshot(configInput, options) {
|
|
|
11848
12385
|
// the README and the audit report.
|
|
11849
12386
|
git: { ...gitInfo, branch: maskPathText(gitInfo.branch, config.secretRules) },
|
|
11850
12387
|
budgets: {
|
|
11851
|
-
|
|
12388
|
+
// The ceiling the parts actually honour. It equals the configured one unless `maxParts`
|
|
12389
|
+
// grew it; `config.maxPartBytes` below keeps the configured value, because that is what
|
|
12390
|
+
// `validate` compares against the config on disk.
|
|
12391
|
+
maxPartBytes: partitioned.maxPartBytes,
|
|
11852
12392
|
largeFileBytes: config.largeFileBytes
|
|
11853
12393
|
},
|
|
11854
12394
|
config: {
|
|
@@ -11866,6 +12406,14 @@ function generateSnapshot(configInput, options) {
|
|
|
11866
12406
|
// invisible in the manifest that is supposed to describe the run.
|
|
11867
12407
|
maxMonolithBytes: config.maxMonolithBytes ?? null,
|
|
11868
12408
|
includeSensitiveFiles: config.includeSensitiveFiles,
|
|
12409
|
+
// The destination the instructions were written for. Not part of `digest`: the payload is
|
|
12410
|
+
// identical whatever this says, and a new delivery preference must not make an existing
|
|
12411
|
+
// snapshot fail `validate` as configuration drift.
|
|
12412
|
+
attachmentSlots: config.attachmentSlots,
|
|
12413
|
+
// The part-count ceiling the run enforced. Recorded because it decided the part sizes, and
|
|
12414
|
+
// omitted from `digest` when it is off so an existing snapshot does not start reporting
|
|
12415
|
+
// configuration drift.
|
|
12416
|
+
maxParts: config.maxParts ?? null,
|
|
11869
12417
|
discovery: config.discovery ?? "auto",
|
|
11870
12418
|
// A changed-files scope decides which files are in the snapshot, so the manifest that
|
|
11871
12419
|
// describes the run has to name it.
|
|
@@ -11936,6 +12484,10 @@ function generateSnapshot(configInput, options) {
|
|
|
11936
12484
|
incomplete,
|
|
11937
12485
|
warnings
|
|
11938
12486
|
};
|
|
12487
|
+
if (partitioned.warnings.length > 0) {
|
|
12488
|
+
manifest.warnings.push(...partitioned.warnings);
|
|
12489
|
+
manifest.totals.warningCount = manifest.warnings.length;
|
|
12490
|
+
}
|
|
11939
12491
|
manifest.totals.redactedLines = secretFindings.length;
|
|
11940
12492
|
manifest.totals.warningCount = manifest.warnings.length;
|
|
11941
12493
|
if (files.some((file) => file.isPreviewTruncated) && config.largeFileBytes < config.maxPartBytes) {
|
|
@@ -11992,6 +12544,15 @@ function generateSnapshot(configInput, options) {
|
|
|
11992
12544
|
if (auditText !== null) manifest.artifacts.audit = artifactRecord(auditText);
|
|
11993
12545
|
const readmeText = artifacts.readme ? generateReadme(manifest, artifacts) : null;
|
|
11994
12546
|
if (readmeText !== null) manifest.artifacts.readme = artifactRecord(readmeText);
|
|
12547
|
+
const promptText = artifacts.prompt ? generatePrompt(
|
|
12548
|
+
manifest,
|
|
12549
|
+
artifacts,
|
|
12550
|
+
config.attachmentSlots,
|
|
12551
|
+
// Commit subjects are user input and reach an artifact, so they go through the same
|
|
12552
|
+
// masking as every other name the run reproduces.
|
|
12553
|
+
recentCommitSubjects(config.cwd).map((subject) => maskPathText(subject, config.secretRules))
|
|
12554
|
+
) : null;
|
|
12555
|
+
if (promptText !== null) manifest.artifacts.prompt = artifactRecord(promptText);
|
|
11995
12556
|
if (projectTree !== null) manifest.artifacts.projectTree = artifactRecord(projectTree);
|
|
11996
12557
|
let monolithJson = null;
|
|
11997
12558
|
let monolithMarkdown = null;
|
|
@@ -12129,6 +12690,9 @@ function generateSnapshot(configInput, options) {
|
|
|
12129
12690
|
if (readmeText !== null) {
|
|
12130
12691
|
writeArtifact(stagingDir, "README.md", readmeText);
|
|
12131
12692
|
}
|
|
12693
|
+
if (promptText !== null) {
|
|
12694
|
+
writeArtifact(stagingDir, "PROMPT.md", promptText);
|
|
12695
|
+
}
|
|
12132
12696
|
if (artifacts.manifest) {
|
|
12133
12697
|
writeArtifact(stagingDir, "manifest.json", JSON.stringify(manifest, null, 2));
|
|
12134
12698
|
}
|
|
@@ -13557,6 +14121,7 @@ var VALIDATE_OPTIONS = [
|
|
|
13557
14121
|
"max-part-tokens",
|
|
13558
14122
|
"large-file-bytes",
|
|
13559
14123
|
"max-monolith-bytes",
|
|
14124
|
+
"max-parts",
|
|
13560
14125
|
"include-monolith",
|
|
13561
14126
|
"include-sensitive-files",
|
|
13562
14127
|
"skip-artifacts",
|
|
@@ -13582,6 +14147,8 @@ var COMMAND_OPTION_SCOPE = {
|
|
|
13582
14147
|
"max-part-tokens",
|
|
13583
14148
|
"large-file-bytes",
|
|
13584
14149
|
"max-monolith-bytes",
|
|
14150
|
+
"attachment-slots",
|
|
14151
|
+
"max-parts",
|
|
13585
14152
|
"include-monolith",
|
|
13586
14153
|
"include-sensitive-files",
|
|
13587
14154
|
"skip-artifacts",
|
|
@@ -13727,6 +14294,7 @@ var PACKAGE_NAME = "codebase-snapshot";
|
|
|
13727
14294
|
var MAJOR_VERSION = GENERATOR_VERSION.split(".")[0];
|
|
13728
14295
|
var ARTIFACT_SUMMARY = {
|
|
13729
14296
|
readme: "README.md describing the snapshot at the output root.",
|
|
14297
|
+
prompt: "PROMPT.md: the instruction sheet to paste with the snapshot, rendered from its manifest.",
|
|
13730
14298
|
manifest: "manifest.json: machine-readable index of every file, part, hash and config.",
|
|
13731
14299
|
parts: "parts/*.md: the packed, budget-limited markdown parts that carry the code.",
|
|
13732
14300
|
navigation: "reports/navigation.md: links between parts and layers.",
|
|
@@ -13736,6 +14304,7 @@ var ARTIFACT_SUMMARY = {
|
|
|
13736
14304
|
};
|
|
13737
14305
|
var ARTIFACT_DEFAULTS = {
|
|
13738
14306
|
readme: true,
|
|
14307
|
+
prompt: true,
|
|
13739
14308
|
manifest: true,
|
|
13740
14309
|
parts: true,
|
|
13741
14310
|
navigation: true,
|
|
@@ -13876,9 +14445,9 @@ function buildAgentContract() {
|
|
|
13876
14445
|
{
|
|
13877
14446
|
step: 6,
|
|
13878
14447
|
id: "consume",
|
|
13879
|
-
run: "read ./snapshot/
|
|
14448
|
+
run: "read ./snapshot/PROMPT.md first, then ./snapshot/parts/*.md, ./snapshot/manifest.json and ./snapshot/reports/audit.md",
|
|
13880
14449
|
expect: "the code, the index of what was included, and the risk findings",
|
|
13881
|
-
notes: "manifest.json.files[] lists every included file with layer, kind, language, part and summary. manifest.skipped[] explains every file that was left out and why; manifest.incomplete[] lists every included file that is not present in full, with its missing line ranges."
|
|
14450
|
+
notes: "manifest.json.files[] lists every included file with layer, kind, language, part and summary. manifest.skipped[] explains every file that was left out and why; manifest.incomplete[] lists every included file that is not present in full, with its missing line ranges. PROMPT.md is the instruction sheet for whoever reads the snapshot; it is rendered from the manifest, so it names this run's omissions rather than describing snapshots in general."
|
|
13882
14451
|
}
|
|
13883
14452
|
],
|
|
13884
14453
|
commands: [
|
|
@@ -14015,6 +14584,20 @@ function buildAgentContract() {
|
|
|
14015
14584
|
appliesTo: optionAppliesTo("discovery"),
|
|
14016
14585
|
summary: "How files are discovered: auto (git when usable), git (require git), walk (read .gitignore files directly, including nested ones; the escape hatch for a .git that cannot be listed)."
|
|
14017
14586
|
},
|
|
14587
|
+
{
|
|
14588
|
+
flag: "--attachment-slots",
|
|
14589
|
+
type: "number",
|
|
14590
|
+
default: "10",
|
|
14591
|
+
appliesTo: optionAppliesTo("attachment-slots"),
|
|
14592
|
+
summary: "Files the destination accepts in one message (0 = no limit). PROMPT.md plans the delivery against it: which parts to attach, what to leave behind, and the part budget that would merge them. It does not change the payload."
|
|
14593
|
+
},
|
|
14594
|
+
{
|
|
14595
|
+
flag: "--max-parts",
|
|
14596
|
+
type: "number",
|
|
14597
|
+
default: "unset",
|
|
14598
|
+
appliesTo: optionAppliesTo("max-parts"),
|
|
14599
|
+
summary: "Experimental: grow the per-part budget until the snapshot has at most this many parts. The budget it settles on is recorded in manifest.budgets.maxPartBytes and may exceed maxPartBytes; a warning says so."
|
|
14600
|
+
},
|
|
14018
14601
|
{
|
|
14019
14602
|
flag: "--skip-artifacts",
|
|
14020
14603
|
type: "string",
|
|
@@ -14228,6 +14811,8 @@ function buildAgentContract() {
|
|
|
14228
14811
|
{ key: "includeSensitiveFiles", type: "boolean", default: false, summary: "Emit .env / *.pem / credential files." },
|
|
14229
14812
|
{ key: "include", type: "string[]", default: "[]", summary: "Allow-list of globs; empty means everything." },
|
|
14230
14813
|
{ key: "excludePatterns", type: "string[]", default: "[]", summary: "Extra exclude globs." },
|
|
14814
|
+
{ key: "maxParts", type: "number | null", default: null, summary: "Experimental: the most parts a snapshot may have. The per-part budget grows to fit, up to the run's own needs; the effective ceiling is recorded in manifest.budgets.maxPartBytes and may exceed maxPartBytes." },
|
|
14815
|
+
{ key: "attachmentSlots", type: "number", default: 10, summary: "Files the destination accepts in one message (0 = no limit); PROMPT.md plans the delivery to fit. It does not change the payload, and it is not part of the config digest." },
|
|
14231
14816
|
{ key: "discovery", type: '"auto" | "git" | "walk"', default: "auto", summary: "How files are discovered; `walk` scans the tree and reads .gitignore directly when a .git directory cannot be listed." },
|
|
14232
14817
|
{ key: "artifacts", type: "object", default: "all on except monolith", summary: "Per-artifact opt-out." },
|
|
14233
14818
|
{ key: "budgets", type: "object", default: "{ default, byLayer }", summary: "Per-layer byte budgets." },
|
|
@@ -14242,6 +14827,7 @@ function buildAgentContract() {
|
|
|
14242
14827
|
output: {
|
|
14243
14828
|
layout: [
|
|
14244
14829
|
"<outDir>/README.md",
|
|
14830
|
+
"<outDir>/PROMPT.md",
|
|
14245
14831
|
"<outDir>/manifest.json",
|
|
14246
14832
|
"<outDir>/parts/part-NNN.md",
|
|
14247
14833
|
"<outDir>/reports/project-tree.md",
|
|
@@ -14255,6 +14841,7 @@ function buildAgentContract() {
|
|
|
14255
14841
|
"indexes.imports.byFile includes previewed files (their import specifiers are still extracted); such an entry carries `exportsOmitted: true` instead of pretending it exports nothing.",
|
|
14256
14842
|
"validate re-checks manifest.incomplete[] against files[] and refuses a manifest whose two statements of what is missing disagree.",
|
|
14257
14843
|
"manifest.skipped[] carries the path and the exact reason it was excluded.",
|
|
14844
|
+
"PROMPT.md is rendered from the manifest of the run that wrote it \u2014 its parts, partial files, skip tallies and fingerprint are that run's \u2014 and manifest.artifacts.prompt records its digest, so an edited prompt fails validate.",
|
|
14258
14845
|
`The output directory is replaced atomically; ${MIN_MAX_PART_BYTES} bytes is the smallest legal budget.`
|
|
14259
14846
|
]
|
|
14260
14847
|
},
|
|
@@ -14429,6 +15016,10 @@ do not assume the repository is broken.
|
|
|
14429
15016
|
- \`snapshot/reports/audit.md\` \u2014 secrets found, large files, parse diagnostics, git
|
|
14430
15017
|
state. Read this before you quote code back to a user.
|
|
14431
15018
|
- \`snapshot/reports/project-tree.md\` and \`navigation.md\` \u2014 structure and cross-links.
|
|
15019
|
+
- \`snapshot/PROMPT.md\` \u2014 the instruction sheet to hand to the model that receives the
|
|
15020
|
+
snapshot: paste it with the parts. It is rendered from this run's manifest and names the
|
|
15021
|
+
parts, the partial files and the fingerprint, so do not rewrite it by hand \u2014 \`validate\`
|
|
15022
|
+
fails when it was edited.
|
|
14432
15023
|
|
|
14433
15024
|
## Project types
|
|
14434
15025
|
|
|
@@ -15496,6 +16087,8 @@ var CLI_OPTIONS = {
|
|
|
15496
16087
|
"max-part-bytes": { type: "string" },
|
|
15497
16088
|
"large-file-bytes": { type: "string" },
|
|
15498
16089
|
"max-monolith-bytes": { type: "string" },
|
|
16090
|
+
"attachment-slots": { type: "string" },
|
|
16091
|
+
"max-parts": { type: "string" },
|
|
15499
16092
|
"include-monolith": { type: "boolean" },
|
|
15500
16093
|
"include-sensitive-files": { type: "boolean" },
|
|
15501
16094
|
"skip-artifacts": { type: "string" },
|
|
@@ -15570,6 +16163,10 @@ Options:
|
|
|
15570
16163
|
--skeleton Emit TypeScript signatures instead of bodies
|
|
15571
16164
|
--sarif Also write reports/audit.sarif for GitHub Code Scanning
|
|
15572
16165
|
--include-sensitive-files Emit .env / *.pem / .npmrc / credential files
|
|
16166
|
+
--attachment-slots <n> Files the destination takes in one message (default: 10,
|
|
16167
|
+
0 = no limit); PROMPT.md plans the delivery to fit
|
|
16168
|
+
--max-parts <n> Experimental: grow the part budget until the snapshot has at
|
|
16169
|
+
most n parts, instead of adding parts as the code grows
|
|
15573
16170
|
--skip-artifacts <names> Comma-separated artifacts to omit
|
|
15574
16171
|
(readme, manifest, parts, navigation,
|
|
15575
16172
|
projectTree, audit, monolith)
|
|
@@ -15628,6 +16225,20 @@ function parseByteOption(raw, optionName, minimum, unit = "byte count") {
|
|
|
15628
16225
|
}
|
|
15629
16226
|
return value;
|
|
15630
16227
|
}
|
|
16228
|
+
function parseCountOption(raw, optionName, minimum = 0) {
|
|
16229
|
+
if (raw === void 0) return void 0;
|
|
16230
|
+
const trimmed = raw.trim();
|
|
16231
|
+
if (!/^\d+$/.test(trimmed) || !Number.isSafeInteger(Number(trimmed))) {
|
|
16232
|
+
throw new UsageError(
|
|
16233
|
+
`--${optionName} expects a whole number such as 10 or 20, received "${raw}".`
|
|
16234
|
+
);
|
|
16235
|
+
}
|
|
16236
|
+
const value = Number(trimmed);
|
|
16237
|
+
if (value < minimum) {
|
|
16238
|
+
throw new UsageError(`--${optionName} must be at least ${minimum}, received "${raw}".`);
|
|
16239
|
+
}
|
|
16240
|
+
return value;
|
|
16241
|
+
}
|
|
15631
16242
|
function parseArtifactList(raw, flag) {
|
|
15632
16243
|
const names = raw.split(",").map((name) => name.trim()).filter(Boolean);
|
|
15633
16244
|
if (names.length === 0) {
|
|
@@ -15869,6 +16480,11 @@ function parseCliArgs(argv) {
|
|
|
15869
16480
|
"max-monolith-bytes",
|
|
15870
16481
|
1
|
|
15871
16482
|
),
|
|
16483
|
+
attachmentSlots: parseCountOption(
|
|
16484
|
+
values["attachment-slots"],
|
|
16485
|
+
"attachment-slots"
|
|
16486
|
+
),
|
|
16487
|
+
maxParts: parseCountOption(values["max-parts"], "max-parts", 1),
|
|
15872
16488
|
skipArtifacts,
|
|
15873
16489
|
onlyArtifacts,
|
|
15874
16490
|
discovery: isDiscoveryMode(rawDiscovery) ? rawDiscovery : void 0,
|
|
@@ -16194,6 +16810,12 @@ async function runSetupCommand(invocation, options = {}) {
|
|
|
16194
16810
|
if (invocation.maxPartTokens !== void 0) {
|
|
16195
16811
|
generateArgs.push("--max-part-tokens", String(invocation.maxPartTokens));
|
|
16196
16812
|
}
|
|
16813
|
+
if (invocation.attachmentSlots !== void 0) {
|
|
16814
|
+
generateArgs.push("--attachment-slots", String(invocation.attachmentSlots));
|
|
16815
|
+
}
|
|
16816
|
+
if (invocation.maxParts !== void 0) {
|
|
16817
|
+
generateArgs.push("--max-parts", String(invocation.maxParts));
|
|
16818
|
+
}
|
|
16197
16819
|
if (invocation.skeleton === true) generateArgs.push("--skeleton");
|
|
16198
16820
|
if (invocation.sarif === true) generateArgs.push("--sarif");
|
|
16199
16821
|
if (invocation.noUpdateCheck) generateArgs.push("--no-update-check");
|
|
@@ -16436,6 +17058,8 @@ ${USAGE}
|
|
|
16436
17058
|
maxPartTokens: invocation.maxPartTokens,
|
|
16437
17059
|
largeFileBytes: invocation.largeFileBytes,
|
|
16438
17060
|
maxMonolithBytes: invocation.maxMonolithBytes,
|
|
17061
|
+
attachmentSlots: invocation.attachmentSlots,
|
|
17062
|
+
maxParts: invocation.maxParts,
|
|
16439
17063
|
skipArtifacts: invocation.skipArtifacts,
|
|
16440
17064
|
// `--only-artifacts` is forwarded as itself, not only as the derived suppression list:
|
|
16441
17065
|
// suppression cannot switch an artifact *on*, so a config that had turned one of the
|
|
@@ -16608,7 +17232,16 @@ ${USAGE}
|
|
|
16608
17232
|
);
|
|
16609
17233
|
}
|
|
16610
17234
|
}
|
|
16611
|
-
|
|
17235
|
+
const orientation = [
|
|
17236
|
+
artifacts.readme ? "README.md" : null,
|
|
17237
|
+
artifacts.prompt ? "PROMPT.md" : null
|
|
17238
|
+
].filter((name) => name !== null);
|
|
17239
|
+
if (orientation.length > 0) {
|
|
17240
|
+
info(
|
|
17241
|
+
` - Orientation: ${orientation.map((name) => displayOutPath(resolved.cwd, resolved.outDir, name)).join(", ")}`
|
|
17242
|
+
);
|
|
17243
|
+
}
|
|
17244
|
+
if (reports.length === 0 && !artifacts.parts && !artifacts.manifest && !artifacts.monolith && orientation.length === 0) {
|
|
16612
17245
|
info(` - Artifacts: all disabled (only the ownership marker was written)`);
|
|
16613
17246
|
}
|
|
16614
17247
|
info(` - Fingerprint: ${manifest.fingerprint}`);
|
|
@@ -16752,6 +17385,8 @@ async function runWatchLoop(invocation, resolved, options) {
|
|
|
16752
17385
|
maxPartTokens: invocation.maxPartTokens,
|
|
16753
17386
|
largeFileBytes: invocation.largeFileBytes,
|
|
16754
17387
|
maxMonolithBytes: invocation.maxMonolithBytes,
|
|
17388
|
+
attachmentSlots: invocation.attachmentSlots,
|
|
17389
|
+
maxParts: invocation.maxParts,
|
|
16755
17390
|
skipArtifacts: invocation.skipArtifacts,
|
|
16756
17391
|
onlyArtifacts: invocation.onlyArtifacts,
|
|
16757
17392
|
discovery: invocation.discovery,
|