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/cli.cjs
CHANGED
|
@@ -2220,7 +2220,7 @@ function applySpansKeepingQuotes(line, spans) {
|
|
|
2220
2220
|
|
|
2221
2221
|
// src/version.ts
|
|
2222
2222
|
var GENERATOR_NAME = "codebase-snapshot";
|
|
2223
|
-
var GENERATOR_VERSION = "0.
|
|
2223
|
+
var GENERATOR_VERSION = "0.11.0";
|
|
2224
2224
|
var SCHEMA_VERSION = "3.0.0";
|
|
2225
2225
|
var LEGACY_GENERATOR_NAMES = ["@ankurhalder/codebase-snapshot"];
|
|
2226
2226
|
function isOurGeneratorName(name) {
|
|
@@ -2668,6 +2668,23 @@ function defaultIgnoreReason(relativePath, toolDirNames = DEFAULT_TOOL_DIR_NAMES
|
|
|
2668
2668
|
}
|
|
2669
2669
|
return null;
|
|
2670
2670
|
}
|
|
2671
|
+
function recentCommitSubjects(cwd, limit = 10) {
|
|
2672
|
+
try {
|
|
2673
|
+
const stdout = childProcess__namespace.execFileSync(
|
|
2674
|
+
"git",
|
|
2675
|
+
["log", "-n", String(limit), "--pretty=%s", "--no-color"],
|
|
2676
|
+
{
|
|
2677
|
+
cwd,
|
|
2678
|
+
stdio: ["ignore", "pipe", "ignore"],
|
|
2679
|
+
encoding: "utf8",
|
|
2680
|
+
maxBuffer: GIT_OUTPUT_LIMIT
|
|
2681
|
+
}
|
|
2682
|
+
);
|
|
2683
|
+
return stdout.split("\n").map((line) => line.trim()).filter((line) => line.length > 0);
|
|
2684
|
+
} catch {
|
|
2685
|
+
return [];
|
|
2686
|
+
}
|
|
2687
|
+
}
|
|
2671
2688
|
function listIgnoredPaths(cwd) {
|
|
2672
2689
|
try {
|
|
2673
2690
|
const stdout = childProcess__namespace.execFileSync(
|
|
@@ -3386,6 +3403,10 @@ function normalizeResolvedConfig(config) {
|
|
|
3386
3403
|
return markResolvedConfig({
|
|
3387
3404
|
...config,
|
|
3388
3405
|
discovery,
|
|
3406
|
+
// A spread copy built before the field existed carries no value; the default applies, and it
|
|
3407
|
+
// is re-validated because the number reaches a rendered artifact.
|
|
3408
|
+
attachmentSlots: resolveAttachmentSlots(config.attachmentSlots),
|
|
3409
|
+
maxParts: resolveMaxParts(config.maxParts),
|
|
3389
3410
|
includeMonolith: artifacts.monolith,
|
|
3390
3411
|
secretRules: compileSecretRules(config.secretRules),
|
|
3391
3412
|
artifacts,
|
|
@@ -3454,6 +3475,7 @@ function describeValue2(value) {
|
|
|
3454
3475
|
var isThenable = (value) => typeof value.then === "function";
|
|
3455
3476
|
var CONFIG_KEY_NAMES = [
|
|
3456
3477
|
"artifacts",
|
|
3478
|
+
"attachmentSlots",
|
|
3457
3479
|
"branch",
|
|
3458
3480
|
"budgets",
|
|
3459
3481
|
"changedSince",
|
|
@@ -3471,6 +3493,7 @@ var CONFIG_KEY_NAMES = [
|
|
|
3471
3493
|
"layersMode",
|
|
3472
3494
|
"maxMonolithBytes",
|
|
3473
3495
|
"maxPartBytes",
|
|
3496
|
+
"maxParts",
|
|
3474
3497
|
"maxPartTokens",
|
|
3475
3498
|
"outDir",
|
|
3476
3499
|
"preset",
|
|
@@ -3669,6 +3692,7 @@ var MIN_MAX_PART_BYTES = 4096;
|
|
|
3669
3692
|
var MIN_MAX_PART_TOKENS = MIN_MAX_PART_BYTES / 4;
|
|
3670
3693
|
var ARTIFACT_NAMES = [
|
|
3671
3694
|
"readme",
|
|
3695
|
+
"prompt",
|
|
3672
3696
|
"manifest",
|
|
3673
3697
|
"parts",
|
|
3674
3698
|
"navigation",
|
|
@@ -3678,6 +3702,7 @@ var ARTIFACT_NAMES = [
|
|
|
3678
3702
|
];
|
|
3679
3703
|
var DEFAULT_ARTIFACTS = {
|
|
3680
3704
|
readme: true,
|
|
3705
|
+
prompt: true,
|
|
3681
3706
|
manifest: true,
|
|
3682
3707
|
parts: true,
|
|
3683
3708
|
navigation: true,
|
|
@@ -3738,6 +3763,25 @@ function resolveArtifacts(requested, skipped, includeMonolith, monolithOverride,
|
|
|
3738
3763
|
}
|
|
3739
3764
|
return artifacts;
|
|
3740
3765
|
}
|
|
3766
|
+
var DEFAULT_ATTACHMENT_SLOTS = 10;
|
|
3767
|
+
function resolveAttachmentSlots(value) {
|
|
3768
|
+
if (value === void 0 || value === null) return DEFAULT_ATTACHMENT_SLOTS;
|
|
3769
|
+
if (typeof value !== "number" || !Number.isInteger(value) || value < 0) {
|
|
3770
|
+
throw new Error(
|
|
3771
|
+
"attachmentSlots must be a whole number, with 0 meaning no limit (received " + describeValue2(value) + ")."
|
|
3772
|
+
);
|
|
3773
|
+
}
|
|
3774
|
+
return value;
|
|
3775
|
+
}
|
|
3776
|
+
function resolveMaxParts(value) {
|
|
3777
|
+
if (value === void 0 || value === null) return null;
|
|
3778
|
+
if (typeof value !== "number" || !Number.isInteger(value) || value < 1) {
|
|
3779
|
+
throw new Error(
|
|
3780
|
+
"maxParts must be a whole number of parts, or null to disable it (received " + describeValue2(value) + ")."
|
|
3781
|
+
);
|
|
3782
|
+
}
|
|
3783
|
+
return value;
|
|
3784
|
+
}
|
|
3741
3785
|
function strictPositiveInteger(value, fallback, label) {
|
|
3742
3786
|
if (value === void 0) return fallback;
|
|
3743
3787
|
if (typeof value !== "number" || !Number.isInteger(value) || value <= 0) {
|
|
@@ -4116,6 +4160,10 @@ function resolveConfig(userConfig, cliOptions, baseDir) {
|
|
|
4116
4160
|
"maxMonolithBytes"
|
|
4117
4161
|
),
|
|
4118
4162
|
includeSensitiveFiles,
|
|
4163
|
+
attachmentSlots: resolveAttachmentSlots(
|
|
4164
|
+
cliOptions?.attachmentSlots ?? userConfig?.attachmentSlots
|
|
4165
|
+
),
|
|
4166
|
+
maxParts: resolveMaxParts(cliOptions?.maxParts ?? userConfig?.maxParts),
|
|
4119
4167
|
...changedSince === void 0 ? {} : { changedSince },
|
|
4120
4168
|
...staged ? { staged } : {},
|
|
4121
4169
|
...withDependents ? { withDependents } : {},
|
|
@@ -4198,6 +4246,9 @@ function configDigest(config) {
|
|
|
4198
4246
|
includeMonolith: config.includeMonolith,
|
|
4199
4247
|
maxMonolithBytes: config.maxMonolithBytes ?? null,
|
|
4200
4248
|
includeSensitiveFiles: config.includeSensitiveFiles,
|
|
4249
|
+
// Only when the experimental mode is on: `null` is the off switch, and writing it into the
|
|
4250
|
+
// material would change the digest of every snapshot taken before the setting existed.
|
|
4251
|
+
...config.maxParts === null ? {} : { maxParts: config.maxParts },
|
|
4201
4252
|
artifacts: config.artifacts,
|
|
4202
4253
|
include: config.include,
|
|
4203
4254
|
excludePatterns: config.excludePatterns,
|
|
@@ -6789,7 +6840,8 @@ function validateSnapshot(configInput) {
|
|
|
6789
6840
|
);
|
|
6790
6841
|
}
|
|
6791
6842
|
}
|
|
6792
|
-
|
|
6843
|
+
const ceilingDerivedByMaxParts = (manifest.config?.maxParts ?? null) !== null;
|
|
6844
|
+
if (!ceilingDerivedByMaxParts && manifest.budgets && manifest.budgets.maxPartBytes !== config.maxPartBytes) {
|
|
6793
6845
|
totalsMismatches.push(
|
|
6794
6846
|
`budgets.maxPartBytes: manifest ${manifest.budgets.maxPartBytes} vs current ${config.maxPartBytes}`
|
|
6795
6847
|
);
|
|
@@ -6818,6 +6870,7 @@ function validateSnapshot(configInput) {
|
|
|
6818
6870
|
}
|
|
6819
6871
|
const declaredArtifacts = [
|
|
6820
6872
|
["README.md", manifest.artifacts?.readme],
|
|
6873
|
+
["PROMPT.md", manifest.artifacts?.prompt],
|
|
6821
6874
|
["reports/navigation.md", manifest.artifacts?.navigation],
|
|
6822
6875
|
["reports/project-tree.md", manifest.artifacts?.projectTree],
|
|
6823
6876
|
["reports/audit.md", manifest.artifacts?.audit],
|
|
@@ -7746,6 +7799,7 @@ var DEFAULT_ANSWERS = {
|
|
|
7746
7799
|
sarif: false,
|
|
7747
7800
|
artifacts: {
|
|
7748
7801
|
readme: true,
|
|
7802
|
+
prompt: true,
|
|
7749
7803
|
manifest: true,
|
|
7750
7804
|
parts: true,
|
|
7751
7805
|
navigation: true,
|
|
@@ -7862,6 +7916,7 @@ function renderConfig(answers) {
|
|
|
7862
7916
|
// \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
|
|
7863
7917
|
artifacts: {
|
|
7864
7918
|
readme: ${artifacts.readme}, // README.md
|
|
7919
|
+
prompt: ${artifacts.prompt}, // PROMPT.md \u2014 the instruction sheet a model is given
|
|
7865
7920
|
manifest: ${artifacts.manifest}, // manifest.json \u2014 required by validate and report
|
|
7866
7921
|
parts: ${artifacts.parts}, // parts/part-XXX.md
|
|
7867
7922
|
navigation: ${artifacts.navigation}, // reports/navigation.md
|
|
@@ -7877,6 +7932,11 @@ function renderConfig(answers) {
|
|
|
7877
7932
|
includeMonolith: ${artifacts.monolith},
|
|
7878
7933
|
|
|
7879
7934
|
// \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
|
|
7935
|
+
// Files your destination accepts in one message, used by PROMPT.md to plan the delivery.
|
|
7936
|
+
// attachmentSlots: 10,
|
|
7937
|
+
// Experimental: grow the per-part budget until the snapshot fits this many parts, instead of
|
|
7938
|
+
// adding a part as the code grows. The plan in PROMPT.md becomes a fixed-length attachment list.
|
|
7939
|
+
// maxParts: 10,
|
|
7880
7940
|
// afterGenerate: (manifest) => { /* write your own artifact */ }
|
|
7881
7941
|
hooks: {},
|
|
7882
7942
|
};
|
|
@@ -8567,6 +8627,7 @@ async function runInit(options) {
|
|
|
8567
8627
|
let lastScope = "all";
|
|
8568
8628
|
const artifactChoices = [
|
|
8569
8629
|
{ value: "readme", label: "README.md", hint: "orientation page" },
|
|
8630
|
+
{ value: "prompt", label: "PROMPT.md", hint: "instruction sheet for the model" },
|
|
8570
8631
|
{ value: "manifest", label: "manifest.json", hint: "required by validate and report" },
|
|
8571
8632
|
{ value: "parts", label: "parts/", hint: "the code payload" },
|
|
8572
8633
|
{ value: "navigation", label: "reports/navigation.md", hint: "file \u2192 part index" },
|
|
@@ -9660,10 +9721,420 @@ function generateNavigation(manifest) {
|
|
|
9660
9721
|
return lines.join("\n");
|
|
9661
9722
|
}
|
|
9662
9723
|
|
|
9724
|
+
// src/generator/prompt.ts
|
|
9725
|
+
var MAX_PART_ROWS = 16;
|
|
9726
|
+
var MAX_LAYER_ROWS = 8;
|
|
9727
|
+
var MAX_INCOMPLETE_ROWS = 50;
|
|
9728
|
+
var MAX_CENTRAL_FILES = 5;
|
|
9729
|
+
var MAX_ENTRY_POINTS = 4;
|
|
9730
|
+
var MAX_LARGEST_FILES = 3;
|
|
9731
|
+
var partWord = (count) => count === 1 ? "part" : "parts";
|
|
9732
|
+
var UNLIMITED_SLOTS = 0;
|
|
9733
|
+
var ENTRY_POINT = /(^|\/)(index|cli|main|bin|server|app|mod)\.[cm]?[jt]sx?$/;
|
|
9734
|
+
var TEST_PATH = /(^|\/)(tests?|__tests__)\//;
|
|
9735
|
+
var TEST_FILE = /\.(test|spec)\.[^.]+$/;
|
|
9736
|
+
function generatePrompt(manifest, artifacts, attachmentSlots = DEFAULT_ATTACHMENT_SLOTS, history = []) {
|
|
9737
|
+
const wrote = (name) => artifacts?.[name] !== false;
|
|
9738
|
+
const code = (value) => inlineCode(escapeControls(value));
|
|
9739
|
+
const lines = [
|
|
9740
|
+
"# PROMPT.md",
|
|
9741
|
+
"",
|
|
9742
|
+
"The brief and the apparatus for this snapshot. Paste this file first, then the parts it names.",
|
|
9743
|
+
"",
|
|
9744
|
+
"It is generated rather than written once: the system map, the omissions, the fingerprint and",
|
|
9745
|
+
"the history below are read from `manifest.json` and this repository, so they describe this run.",
|
|
9746
|
+
"Regenerate it after the code moves.",
|
|
9747
|
+
"",
|
|
9748
|
+
"---",
|
|
9749
|
+
"",
|
|
9750
|
+
"```text",
|
|
9751
|
+
"You are working on a codebase you cannot clone, run or grep. Everything you know about it comes",
|
|
9752
|
+
"from the snapshot that follows this instruction. Where these notes and the snapshot disagree,",
|
|
9753
|
+
"the snapshot is what exists.",
|
|
9754
|
+
"",
|
|
9755
|
+
"## The job",
|
|
9756
|
+
"",
|
|
9757
|
+
"Find what is still wrong or will break. How you read the code is yours to decide - by",
|
|
9758
|
+
"subsystem, by data flow, by the invariants you derive yourself. What you owe in return is an",
|
|
9759
|
+
"honest account of what you covered and what you did not.",
|
|
9760
|
+
"",
|
|
9761
|
+
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,",
|
|
9762
|
+
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.",
|
|
9763
|
+
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.",
|
|
9764
|
+
"",
|
|
9765
|
+
"If the task at the end asks for something narrower - explain a file, review a change, answer a",
|
|
9766
|
+
"question - that task wins. The standard and the coverage duty below still apply to it.",
|
|
9767
|
+
""
|
|
9768
|
+
];
|
|
9769
|
+
lines.push(...haveSection(wrote), "");
|
|
9770
|
+
lines.push(...systemSection(manifest, code), "");
|
|
9771
|
+
lines.push(...historySection(history), "");
|
|
9772
|
+
lines.push(...barSection(), "");
|
|
9773
|
+
lines.push(...coverageSection(manifest, code, wrote("audit")), "");
|
|
9774
|
+
lines.push(...answerSection(), "");
|
|
9775
|
+
lines.push(...calibrationSection(), "");
|
|
9776
|
+
lines.push(...snapshotSection(manifest, code), "");
|
|
9777
|
+
lines.push(...deliverySection(manifest, wrote("parts"), attachmentSlots));
|
|
9778
|
+
lines.push(
|
|
9779
|
+
"## Your task",
|
|
9780
|
+
"",
|
|
9781
|
+
"<replace with the question, the area to review, or the subsystem to audit>",
|
|
9782
|
+
"```"
|
|
9783
|
+
);
|
|
9784
|
+
lines.push(
|
|
9785
|
+
"",
|
|
9786
|
+
"---",
|
|
9787
|
+
"",
|
|
9788
|
+
"## Why this file exists",
|
|
9789
|
+
"",
|
|
9790
|
+
"Parts on their own are a dump: the model receives text, has no idea what was left out of it,",
|
|
9791
|
+
"and fills the gap by invention. A brief on its own is a wish list: it cannot say which files",
|
|
9792
|
+
"are present, which are partial or which part holds what. This file is both halves, and the",
|
|
9793
|
+
"facts in it move with the snapshot.",
|
|
9794
|
+
"",
|
|
9795
|
+
"## Keeping it true",
|
|
9796
|
+
"",
|
|
9797
|
+
"- It is one of the artifacts recorded in `manifest.json` under `artifacts.prompt`, so deleting",
|
|
9798
|
+
" or editing `PROMPT.md` makes `snapshot validate` fail.",
|
|
9799
|
+
"- `--skip-artifacts prompt`, or `artifacts: { prompt: false }` in the config, turns it off.",
|
|
9800
|
+
"- The history section disappears when git cannot be read, rather than being invented.",
|
|
9801
|
+
"- If the code moves, regenerate. A brief naming the previous run parts is worse than no",
|
|
9802
|
+
" brief, because it reads as current.",
|
|
9803
|
+
""
|
|
9804
|
+
);
|
|
9805
|
+
return lines.join("\n");
|
|
9806
|
+
}
|
|
9807
|
+
function haveSection(wrote) {
|
|
9808
|
+
const out = ["## What you have", ""];
|
|
9809
|
+
const bullets = [];
|
|
9810
|
+
if (wrote("readme")) {
|
|
9811
|
+
bullets.push("- `README.md` - orientation: metrics, the part table, and the fingerprint.");
|
|
9812
|
+
}
|
|
9813
|
+
if (wrote("manifest")) {
|
|
9814
|
+
bullets.push(
|
|
9815
|
+
"- `manifest.json` - the index. Per file: `relativePath`, `layer`, `kind`, `language`,",
|
|
9816
|
+
" `part`, `sha256`, `inclusionMode`, `truncationReason`, `omittedRanges`. It also carries",
|
|
9817
|
+
" every excluded path under `skipped[]` with its reason, and `incomplete[]`, which names",
|
|
9818
|
+
" every included file whose emitted body is not the whole file."
|
|
9819
|
+
);
|
|
9820
|
+
}
|
|
9821
|
+
if (wrote("navigation")) {
|
|
9822
|
+
bullets.push("- `reports/navigation.md` - file to part. Locate here before you read anything.");
|
|
9823
|
+
}
|
|
9824
|
+
if (wrote("projectTree")) {
|
|
9825
|
+
bullets.push("- `reports/project-tree.md` - the directory shape of what was included.");
|
|
9826
|
+
}
|
|
9827
|
+
if (wrote("audit")) {
|
|
9828
|
+
bullets.push(
|
|
9829
|
+
"- `reports/audit.md` - secret findings, the files whose lines were redacted, large files,",
|
|
9830
|
+
" parse diagnostics and the git state the snapshot was taken from."
|
|
9831
|
+
);
|
|
9832
|
+
}
|
|
9833
|
+
if (wrote("parts")) {
|
|
9834
|
+
bullets.push(
|
|
9835
|
+
"- `parts/part-NNN.md` - the code itself, split to a fixed byte budget. Each part states its",
|
|
9836
|
+
" own number, the files it contains, and the fingerprint it was built from."
|
|
9837
|
+
);
|
|
9838
|
+
}
|
|
9839
|
+
if (wrote("monolith")) {
|
|
9840
|
+
bullets.push(
|
|
9841
|
+
"- `full-codebase.json` and `full-codebase.md` - the entire payload in one file each.",
|
|
9842
|
+
" Where they are present, they supersede the parts: nothing was left out of them."
|
|
9843
|
+
);
|
|
9844
|
+
}
|
|
9845
|
+
if (bullets.length === 0) {
|
|
9846
|
+
bullets.push(
|
|
9847
|
+
"- Nothing but this brief: every code artifact was disabled for this run. Ask for a snapshot",
|
|
9848
|
+
" generated with the artifacts you need, and do not answer from memory."
|
|
9849
|
+
);
|
|
9850
|
+
}
|
|
9851
|
+
out.push(...bullets);
|
|
9852
|
+
return out;
|
|
9853
|
+
}
|
|
9854
|
+
function systemSection(manifest, code) {
|
|
9855
|
+
const out = ["## The system", ""];
|
|
9856
|
+
const layers = Object.entries(manifest.layers).sort((a, b) => b[1] - a[1] || a[0].localeCompare(b[0]));
|
|
9857
|
+
if (layers.length > 0) {
|
|
9858
|
+
const shown = layers.slice(0, MAX_LAYER_ROWS).map(([name, count]) => code(name) + " " + formatNumber(count));
|
|
9859
|
+
const rest = layers.length > MAX_LAYER_ROWS ? ", and " + formatNumber(layers.length - MAX_LAYER_ROWS) + " more" : "";
|
|
9860
|
+
out.push("- Layers, by file count: " + shown.join(", ") + rest + ".");
|
|
9861
|
+
}
|
|
9862
|
+
const central = manifest.indexes.imports.centralFiles;
|
|
9863
|
+
if (central.length > 0) {
|
|
9864
|
+
const shown = central.slice(0, MAX_CENTRAL_FILES).map((entry) => code(entry.path) + " (" + formatNumber(entry.importedByCount) + ")").join(", ");
|
|
9865
|
+
out.push(
|
|
9866
|
+
"- Load-bearing modules, by how many files import them: " + shown + ".",
|
|
9867
|
+
" A change here reaches the most call sites; read it before judging anything that uses it."
|
|
9868
|
+
);
|
|
9869
|
+
}
|
|
9870
|
+
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);
|
|
9871
|
+
out.push(
|
|
9872
|
+
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"
|
|
9873
|
+
);
|
|
9874
|
+
if (entryPoints.length === 0) out.push(" starts, and the call graph in `manifest.json` is the map.");
|
|
9875
|
+
const routes = manifest.indexes.routes.length;
|
|
9876
|
+
const handlers = manifest.indexes.handlers.length;
|
|
9877
|
+
const components = manifest.indexes.components.length;
|
|
9878
|
+
const routesShown = manifest.indexes.routes.slice(0, 4).map((route) => code(route.path));
|
|
9879
|
+
const componentsShown = manifest.indexes.components.slice(0, 4).map((entry) => code(entry.path));
|
|
9880
|
+
if (routes + handlers + components === 0) {
|
|
9881
|
+
out.push(
|
|
9882
|
+
"- No routes, handlers or UI components were recorded: this snapshot indexes no HTTP or",
|
|
9883
|
+
" component surface. Do not go looking for one, and do not infer one from a file name."
|
|
9884
|
+
);
|
|
9885
|
+
} else {
|
|
9886
|
+
const parts = [];
|
|
9887
|
+
if (routes > 0) parts.push(formatNumber(routes) + " route(s), e.g. " + routesShown.join(", "));
|
|
9888
|
+
if (handlers > 0) parts.push(formatNumber(handlers) + " handler(s)");
|
|
9889
|
+
if (components > 0) parts.push(formatNumber(components) + " component(s), e.g. " + componentsShown.join(", "));
|
|
9890
|
+
out.push("- Surfaces the index found: " + parts.join("; ") + ".");
|
|
9891
|
+
}
|
|
9892
|
+
const largest = [...manifest.files].sort((a, b) => b.includedBytes - a.includedBytes).slice(0, MAX_LARGEST_FILES);
|
|
9893
|
+
if (largest.length > 0) {
|
|
9894
|
+
out.push(
|
|
9895
|
+
"- Largest files: " + largest.map((file) => code(file.relativePath) + " (" + formatNumber(Math.round(file.includedBytes / 1024)) + " KB)").join(", ") + "."
|
|
9896
|
+
);
|
|
9897
|
+
}
|
|
9898
|
+
const tests = manifest.files.filter(
|
|
9899
|
+
(file) => TEST_PATH.test(file.relativePath) || TEST_FILE.test(file.relativePath)
|
|
9900
|
+
);
|
|
9901
|
+
if (tests.length > 0) {
|
|
9902
|
+
const testBytes = tests.reduce((total, file) => total + file.includedBytes, 0);
|
|
9903
|
+
const allBytes = manifest.files.reduce((total, file) => total + file.includedBytes, 0);
|
|
9904
|
+
const share = allBytes === 0 ? 0 : Math.round(testBytes / allBytes * 100);
|
|
9905
|
+
out.push(
|
|
9906
|
+
"- Tests: " + formatNumber(tests.length) + " file(s), " + share + "% of the included bytes.",
|
|
9907
|
+
" They are evidence of intent, not of behaviour: a fixture can encode a payload shape the",
|
|
9908
|
+
" real system never sends."
|
|
9909
|
+
);
|
|
9910
|
+
}
|
|
9911
|
+
return out;
|
|
9912
|
+
}
|
|
9913
|
+
function historySection(history) {
|
|
9914
|
+
const out = ["## What came before", ""];
|
|
9915
|
+
if (history.length === 0) {
|
|
9916
|
+
out.push(
|
|
9917
|
+
"No history was readable: this is not a git checkout, or git could not be run. Nothing about",
|
|
9918
|
+
"what came before can be claimed from here, and that is not evidence that the code is new."
|
|
9919
|
+
);
|
|
9920
|
+
return out;
|
|
9921
|
+
}
|
|
9922
|
+
out.push(
|
|
9923
|
+
"Commit subjects, newest first. They are claims by whoever wrote them, not evidence - the code",
|
|
9924
|
+
"beside them is the evidence. If one of these fixes looks incomplete, quote the lines and say",
|
|
9925
|
+
"which call site it missed.",
|
|
9926
|
+
""
|
|
9927
|
+
);
|
|
9928
|
+
for (const subject of history) out.push("- " + subject);
|
|
9929
|
+
return out;
|
|
9930
|
+
}
|
|
9931
|
+
function barSection() {
|
|
9932
|
+
return [
|
|
9933
|
+
"## The bar",
|
|
9934
|
+
"",
|
|
9935
|
+
"A finding is a concrete way the code breaks or lies, supported by quoted lines: the path and",
|
|
9936
|
+
"line, the input or state that reaches it, what happens next, and why the guard that appears to",
|
|
9937
|
+
"stop it does not. A comment is not behaviour. A passing test is evidence of intent, not of",
|
|
9938
|
+
"behaviour.",
|
|
9939
|
+
"",
|
|
9940
|
+
"- No style, naming, formatting, add-types, add-tests, consider-X or speculative rewrites.",
|
|
9941
|
+
"- Never invent a finding to fill a section. A clean surface is proven by quoting the guard",
|
|
9942
|
+
" that makes it clean.",
|
|
9943
|
+
"- Mark confidence, and name the check - a test, a run, an input - that would settle anything",
|
|
9944
|
+
" you cannot decide by reading.",
|
|
9945
|
+
"- Separate what the code does from what the deployment or configuration does. Both are",
|
|
9946
|
+
" findings; they have different owners and different fixes."
|
|
9947
|
+
];
|
|
9948
|
+
}
|
|
9949
|
+
function coverageSection(manifest, code, auditWritten) {
|
|
9950
|
+
const out = ["## Coverage", ""];
|
|
9951
|
+
const reasons = /* @__PURE__ */ new Map();
|
|
9952
|
+
for (const record of manifest.skipped) {
|
|
9953
|
+
reasons.set(record.reason, (reasons.get(record.reason) ?? 0) + 1);
|
|
9954
|
+
}
|
|
9955
|
+
const tally = [...reasons.entries()].sort((a, b) => b[1] - a[1] || a[0].localeCompare(b[0])).map(([reason, count]) => code(reason) + " " + formatNumber(count)).join(", ");
|
|
9956
|
+
out.push(
|
|
9957
|
+
"- " + 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 + ")" : "") + ".",
|
|
9958
|
+
" `manifest.skipped[]` names each one and why. An absent path is not a clean path."
|
|
9959
|
+
);
|
|
9960
|
+
out.push(...incompleteSection(manifest, code));
|
|
9961
|
+
out.push(...redactionSection(manifest, auditWritten));
|
|
9962
|
+
out.push(
|
|
9963
|
+
"- Everything unseen is unread, never clean. If you were given only some of the parts, say",
|
|
9964
|
+
" which ones are missing before you answer. A file the index names but the parts do not carry",
|
|
9965
|
+
" is an input defect, not a code finding - report it as one."
|
|
9966
|
+
);
|
|
9967
|
+
return out;
|
|
9968
|
+
}
|
|
9969
|
+
function answerSection() {
|
|
9970
|
+
return [
|
|
9971
|
+
"## What a useful answer contains",
|
|
9972
|
+
"",
|
|
9973
|
+
"- An opening line, filled from This snapshot below:",
|
|
9974
|
+
"",
|
|
9975
|
+
" snapshot <fingerprint> generated <generatedAt>",
|
|
9976
|
+
"",
|
|
9977
|
+
"- What you read and what you did not, named by path or by part.",
|
|
9978
|
+
"- Findings ordered by consequence, each with the lines quoted.",
|
|
9979
|
+
"- The checks or attacks that failed, and the line or guard that blocked them. A failed attack",
|
|
9980
|
+
" is how anyone knows an invariant is real rather than asserted.",
|
|
9981
|
+
"- What you retracted after re-reading.",
|
|
9982
|
+
"- What only a run, a test or a host can settle, and the check that would settle each.",
|
|
9983
|
+
"- One paragraph on the failure you would bet on next.",
|
|
9984
|
+
"- A closing line: Needed but not received: <paths>, or none. That line is not decoration -",
|
|
9985
|
+
" an invented function is indistinguishable from a real one, and this is where you name",
|
|
9986
|
+
" the gap you filled by asking instead of guessing."
|
|
9987
|
+
];
|
|
9988
|
+
}
|
|
9989
|
+
function calibrationSection() {
|
|
9990
|
+
return [
|
|
9991
|
+
"## Calibration",
|
|
9992
|
+
"",
|
|
9993
|
+
"The findings that matter here do not crash. They look like:",
|
|
9994
|
+
"",
|
|
9995
|
+
"- a guard applied at one call site and not its twin - the route checks, the timer does not;",
|
|
9996
|
+
"- a budget shorter than the work it guards, so the caller gives up while the work continues;",
|
|
9997
|
+
"- a success flag that means the call returned, consumed as the change happened;",
|
|
9998
|
+
"- a document that describes a different run than the one beside it;",
|
|
9999
|
+
"- a default that fabricates a number when the measurement failed.",
|
|
10000
|
+
"",
|
|
10001
|
+
"None of these throw. All are invisible in a summary."
|
|
10002
|
+
];
|
|
10003
|
+
}
|
|
10004
|
+
function snapshotSection(manifest, code) {
|
|
10005
|
+
const out = ["## This snapshot", ""];
|
|
10006
|
+
out.push("- Fingerprint: " + code(manifest.fingerprint) + " - quote it verbatim in your answer.");
|
|
10007
|
+
out.push(
|
|
10008
|
+
"- Generated: " + code(manifest.generatedAt) + " from branch " + code(manifest.git.branch) + " at commit " + code(manifest.git.commit.slice(0, 8)) + "."
|
|
10009
|
+
);
|
|
10010
|
+
out.push(
|
|
10011
|
+
manifest.git.isDirty ? " The working tree had uncommitted changes at generation time." : " The working tree was clean at generation time."
|
|
10012
|
+
);
|
|
10013
|
+
out.push(
|
|
10014
|
+
"- Validation: `manifest.validation.status` was " + code(manifest.validation.status) + " at generation time.",
|
|
10015
|
+
" That describes the run, not now: if the tree may have moved since, the snapshot is a",
|
|
10016
|
+
" claim that needs re-checking, not a fact."
|
|
10017
|
+
);
|
|
10018
|
+
if (manifest.parts.length > 0) {
|
|
10019
|
+
out.push(
|
|
10020
|
+
"- Parts: " + formatNumber(manifest.parts.length) + " at a " + formatNumber(Math.round(manifest.budgets.maxPartBytes / 1024)) + " KB ceiling" + (manifest.parts.length === 1 ? ":" : " each:")
|
|
10021
|
+
);
|
|
10022
|
+
for (const part of manifest.parts.slice(0, MAX_PART_ROWS)) {
|
|
10023
|
+
out.push(" - " + code(part.filename) + " - " + formatNumber(part.fileCount) + " file(s)");
|
|
10024
|
+
}
|
|
10025
|
+
if (manifest.parts.length > MAX_PART_ROWS) {
|
|
10026
|
+
out.push(
|
|
10027
|
+
" - and " + formatNumber(manifest.parts.length - MAX_PART_ROWS) + " more, tabled in `README.md`"
|
|
10028
|
+
);
|
|
10029
|
+
}
|
|
10030
|
+
}
|
|
10031
|
+
return out;
|
|
10032
|
+
}
|
|
10033
|
+
function incompleteSection(manifest, code) {
|
|
10034
|
+
const out = [];
|
|
10035
|
+
const list2 = manifest.incomplete;
|
|
10036
|
+
if (list2.length === 0) {
|
|
10037
|
+
out.push("- Partial files: none. Every included file is present in full.");
|
|
10038
|
+
return out;
|
|
10039
|
+
}
|
|
10040
|
+
out.push(
|
|
10041
|
+
"- Partial files: " + formatNumber(list2.length) + ". These are present only in part, and the",
|
|
10042
|
+
" missing lines are named, not implied:"
|
|
10043
|
+
);
|
|
10044
|
+
for (const entry of list2.slice(0, MAX_INCOMPLETE_ROWS)) {
|
|
10045
|
+
const ranges = entry.omittedRanges.map(([start, end]) => start === end ? String(start) : start + "-" + end).join(", ");
|
|
10046
|
+
out.push(
|
|
10047
|
+
" - " + code(entry.relativePath) + " in " + code(entry.part) + " - " + entry.reason + ", lines " + ranges + " (" + formatNumber(entry.omittedLines) + " of " + formatNumber(entry.lines) + " missing)"
|
|
10048
|
+
);
|
|
10049
|
+
}
|
|
10050
|
+
if (list2.length > MAX_INCOMPLETE_ROWS) {
|
|
10051
|
+
out.push(
|
|
10052
|
+
" - and " + formatNumber(list2.length - MAX_INCOMPLETE_ROWS) + " more, all named in `manifest.json` under `incomplete[]`"
|
|
10053
|
+
);
|
|
10054
|
+
}
|
|
10055
|
+
return out;
|
|
10056
|
+
}
|
|
10057
|
+
function redactionSection(manifest, auditWritten) {
|
|
10058
|
+
const redacted = manifest.totals.redactedLines;
|
|
10059
|
+
if (redacted === 0) {
|
|
10060
|
+
return ["- Redacted: no line matched a secret rule."];
|
|
10061
|
+
}
|
|
10062
|
+
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.";
|
|
10063
|
+
return [
|
|
10064
|
+
"- Redacted: " + formatNumber(redacted) + " line(s) had values masked before you received them.",
|
|
10065
|
+
" A masked span is a deliberate redaction, not an empty value.",
|
|
10066
|
+
" " + where
|
|
10067
|
+
];
|
|
10068
|
+
}
|
|
10069
|
+
function deliverySection(manifest, partsWritten, slots) {
|
|
10070
|
+
if (!partsWritten || manifest.parts.length === 0) return [];
|
|
10071
|
+
const parts = manifest.parts.length;
|
|
10072
|
+
const wholeSet = parts + 5;
|
|
10073
|
+
const unlimited = slots <= UNLIMITED_SLOTS;
|
|
10074
|
+
const out = ["## Attaching this", ""];
|
|
10075
|
+
out.push(
|
|
10076
|
+
"Paste this file as text: instructions cost no attachment slot. Attach the files it names.",
|
|
10077
|
+
"",
|
|
10078
|
+
"- Every part opens with `# Codebase Snapshot Part NNN of MMM` and repeats the fingerprint",
|
|
10079
|
+
" above, so check both before relying on one. A part you were not given is not an empty part."
|
|
10080
|
+
);
|
|
10081
|
+
if (unlimited) {
|
|
10082
|
+
out.push(
|
|
10083
|
+
"- No attachment limit is configured, so every file can travel: " + parts + " " + partWord(parts) + " plus `manifest.json`, `README.md` and the three reports (" + wholeSet + " files)."
|
|
10084
|
+
);
|
|
10085
|
+
} else if (wholeSet <= slots) {
|
|
10086
|
+
out.push(
|
|
10087
|
+
"- A " + slots + "-file destination carries the whole set: " + parts + " " + partWord(parts) + " plus `manifest.json`, `README.md` and the three reports - " + wholeSet + " of " + slots + "."
|
|
10088
|
+
);
|
|
10089
|
+
} else if (parts + 1 <= slots) {
|
|
10090
|
+
out.push(
|
|
10091
|
+
"- A " + slots + "-file destination carries " + parts + " " + partWord(parts) + " and",
|
|
10092
|
+
" `manifest.json` (" + (parts + 1) + " of " + slots + "); `README.md` and",
|
|
10093
|
+
" `reports/` stay behind - the brief above carries what they add."
|
|
10094
|
+
);
|
|
10095
|
+
} else if (parts <= slots) {
|
|
10096
|
+
out.push(
|
|
10097
|
+
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",
|
|
10098
|
+
" `reports/` stay behind. The brief above carries what they add."
|
|
10099
|
+
);
|
|
10100
|
+
if (parts > 1) {
|
|
10101
|
+
out.push(
|
|
10102
|
+
" Either raise `--max-part-bytes` to merge the parts, or set `--max-parts " + slots + "` and let the parts grow to the count instead."
|
|
10103
|
+
);
|
|
10104
|
+
}
|
|
10105
|
+
} else {
|
|
10106
|
+
out.push(
|
|
10107
|
+
"- The " + parts + " parts do not fit a " + slots + "-file destination: at most " + slots + " can be attached.",
|
|
10108
|
+
" Choose by task - `reports/navigation.md` maps a file to its part - and name the parts",
|
|
10109
|
+
" you left out, or regenerate with `--max-part-bytes " + suggestBudgetBytes(manifest, slots) + "` for about " + (slots - 1) + " parts. `--max-parts " + slots + "` grows the parts until",
|
|
10110
|
+
" they fit instead, and says so when they end up larger than maxPartBytes."
|
|
10111
|
+
);
|
|
10112
|
+
}
|
|
10113
|
+
out.push(
|
|
10114
|
+
"- If you were given only some of them, say which parts are missing before you answer, and",
|
|
10115
|
+
" name the files you needed. Do not infer the contents of a part you did not receive.",
|
|
10116
|
+
""
|
|
10117
|
+
);
|
|
10118
|
+
return out;
|
|
10119
|
+
}
|
|
10120
|
+
function suggestBudgetBytes(manifest, slots) {
|
|
10121
|
+
const total = manifest.parts.reduce((sum, part) => sum + part.byteSize, 0);
|
|
10122
|
+
const target = Math.max(1, slots - 1);
|
|
10123
|
+
const estimated = Math.ceil(total / target * 1.15);
|
|
10124
|
+
const rounded = Math.ceil(estimated / 16384) * 16384;
|
|
10125
|
+
const budget = Math.max(rounded, manifest.budgets.maxPartBytes);
|
|
10126
|
+
return Math.round(budget / 1024) + "k";
|
|
10127
|
+
}
|
|
10128
|
+
|
|
9663
10129
|
// src/generator/readme.ts
|
|
9664
10130
|
function generateReadme(manifest, artifacts) {
|
|
9665
10131
|
const wrote = (name) => artifacts?.[name] !== false;
|
|
9666
10132
|
const reportLinks = [];
|
|
10133
|
+
if (wrote("prompt")) {
|
|
10134
|
+
reportLinks.push(
|
|
10135
|
+
"- [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."
|
|
10136
|
+
);
|
|
10137
|
+
}
|
|
9667
10138
|
if (wrote("navigation")) {
|
|
9668
10139
|
reportLinks.push(
|
|
9669
10140
|
"- [reports/navigation.md](reports/navigation.md) \u2014 Comprehensive file directory mapping files to chunk files."
|
|
@@ -9733,6 +10204,11 @@ function generateReadme(manifest, artifacts) {
|
|
|
9733
10204
|
lines.push("", "## Snapshot Parts", "", "No parts were written for this run.");
|
|
9734
10205
|
}
|
|
9735
10206
|
const readOrder = [];
|
|
10207
|
+
if (wrote("prompt")) {
|
|
10208
|
+
readOrder.push(
|
|
10209
|
+
"1. Hand `PROMPT.md` to the model that receives this snapshot: it names the parts, the partial files and the fingerprint of this run."
|
|
10210
|
+
);
|
|
10211
|
+
}
|
|
9736
10212
|
if (wrote("navigation") || wrote("projectTree")) {
|
|
9737
10213
|
const first = [wrote("navigation") ? "`reports/navigation.md`" : null, wrote("projectTree") ? "`reports/project-tree.md`" : null].filter(Boolean).join(" or ");
|
|
9738
10214
|
readOrder.push(`1. Read ${first} first to locate target features or files.`);
|
|
@@ -11399,7 +11875,55 @@ function runAfterGenerate(config, manifest) {
|
|
|
11399
11875
|
return Promise.resolve(returned).finally(releaseRedirect);
|
|
11400
11876
|
}
|
|
11401
11877
|
function partitionByBudget(files, config, fingerprint) {
|
|
11402
|
-
const
|
|
11878
|
+
const configured = {
|
|
11879
|
+
parts: partitionWithBudgets(files, config.budgets, fingerprint),
|
|
11880
|
+
budgets: config.budgets,
|
|
11881
|
+
maxPartBytes: config.maxPartBytes,
|
|
11882
|
+
warnings: []
|
|
11883
|
+
};
|
|
11884
|
+
const limit = config.maxParts;
|
|
11885
|
+
if (limit === null || !config.artifacts.parts || configured.parts.length <= limit) return configured;
|
|
11886
|
+
const totalBytes = files.reduce((total, file) => total + file.includedBytes, 0);
|
|
11887
|
+
let target = Math.max(config.budgets.default, Math.ceil(totalBytes * 1.15 / limit));
|
|
11888
|
+
const seen = [];
|
|
11889
|
+
let low = config.budgets.default;
|
|
11890
|
+
let fitting = null;
|
|
11891
|
+
for (let pass = 0; pass < 6; pass += 1) {
|
|
11892
|
+
const parts2 = partitionWithBudgets(files, scaleBudgets(config.budgets, target), fingerprint);
|
|
11893
|
+
if (parts2.length <= limit) {
|
|
11894
|
+
fitting = { target, parts: parts2 };
|
|
11895
|
+
break;
|
|
11896
|
+
}
|
|
11897
|
+
seen.push(parts2.length);
|
|
11898
|
+
low = target;
|
|
11899
|
+
target = Math.ceil(target * 1.3);
|
|
11900
|
+
}
|
|
11901
|
+
if (fitting === null) {
|
|
11902
|
+
throw new Error(
|
|
11903
|
+
`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.`
|
|
11904
|
+
);
|
|
11905
|
+
}
|
|
11906
|
+
for (let step = 0; step < 3 && fitting.target - low > 8192; step += 1) {
|
|
11907
|
+
const middle = Math.round((low + fitting.target) / 2);
|
|
11908
|
+
const parts2 = partitionWithBudgets(files, scaleBudgets(config.budgets, middle), fingerprint);
|
|
11909
|
+
if (parts2.length <= limit) fitting = { target: middle, parts: parts2 };
|
|
11910
|
+
else low = middle;
|
|
11911
|
+
}
|
|
11912
|
+
const { target: chosen, parts } = fitting;
|
|
11913
|
+
const budgets = scaleBudgets(config.budgets, chosen);
|
|
11914
|
+
const maxPartBytes = Math.max(config.maxPartBytes, chosen);
|
|
11915
|
+
const warnings = [
|
|
11916
|
+
`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).`
|
|
11917
|
+
];
|
|
11918
|
+
if (maxPartBytes > config.maxPartBytes) {
|
|
11919
|
+
warnings.push(
|
|
11920
|
+
`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.`
|
|
11921
|
+
);
|
|
11922
|
+
}
|
|
11923
|
+
return { parts, budgets, maxPartBytes, warnings };
|
|
11924
|
+
}
|
|
11925
|
+
function partitionWithBudgets(files, budgets, fingerprint) {
|
|
11926
|
+
const budgetFor = (file) => budgets.byLayer[file.layer] ?? budgets.default;
|
|
11403
11927
|
const buckets = /* @__PURE__ */ new Map();
|
|
11404
11928
|
for (const file of files) {
|
|
11405
11929
|
const budget = budgetFor(file);
|
|
@@ -11416,6 +11940,18 @@ function partitionByBudget(files, config, fingerprint) {
|
|
|
11416
11940
|
fingerprint
|
|
11417
11941
|
);
|
|
11418
11942
|
}
|
|
11943
|
+
function scaleBudgets(budgets, targetDefault) {
|
|
11944
|
+
const factor = targetDefault / budgets.default;
|
|
11945
|
+
return {
|
|
11946
|
+
default: Math.max(budgets.default, Math.round(targetDefault)),
|
|
11947
|
+
byLayer: Object.fromEntries(
|
|
11948
|
+
Object.entries(budgets.byLayer).map(([name, bytes]) => [
|
|
11949
|
+
name,
|
|
11950
|
+
Math.max(bytes, Math.round(bytes * factor))
|
|
11951
|
+
])
|
|
11952
|
+
)
|
|
11953
|
+
};
|
|
11954
|
+
}
|
|
11419
11955
|
function generateSnapshot(configInput, options) {
|
|
11420
11956
|
assertUsableConfigInput(configInput);
|
|
11421
11957
|
const config = isResolvedConfig(configInput) ? normalizeResolvedConfig(configInput) : resolveConfig(configInput ?? null);
|
|
@@ -11744,7 +12280,8 @@ function generateSnapshot(configInput, options) {
|
|
|
11744
12280
|
);
|
|
11745
12281
|
}
|
|
11746
12282
|
}
|
|
11747
|
-
const
|
|
12283
|
+
const partitioned = partitionByBudget(files, config, fingerprint);
|
|
12284
|
+
const parts = partitioned.parts;
|
|
11748
12285
|
const truncatedPreviewCount = files.filter((file) => file.isPreviewTruncated).length;
|
|
11749
12286
|
const incomplete = files.flatMap((file) => {
|
|
11750
12287
|
if (file.truncationReason === void 0) return [];
|
|
@@ -11781,7 +12318,10 @@ function generateSnapshot(configInput, options) {
|
|
|
11781
12318
|
// the README and the audit report.
|
|
11782
12319
|
git: { ...gitInfo, branch: maskPathText(gitInfo.branch, config.secretRules) },
|
|
11783
12320
|
budgets: {
|
|
11784
|
-
|
|
12321
|
+
// The ceiling the parts actually honour. It equals the configured one unless `maxParts`
|
|
12322
|
+
// grew it; `config.maxPartBytes` below keeps the configured value, because that is what
|
|
12323
|
+
// `validate` compares against the config on disk.
|
|
12324
|
+
maxPartBytes: partitioned.maxPartBytes,
|
|
11785
12325
|
largeFileBytes: config.largeFileBytes
|
|
11786
12326
|
},
|
|
11787
12327
|
config: {
|
|
@@ -11799,6 +12339,14 @@ function generateSnapshot(configInput, options) {
|
|
|
11799
12339
|
// invisible in the manifest that is supposed to describe the run.
|
|
11800
12340
|
maxMonolithBytes: config.maxMonolithBytes ?? null,
|
|
11801
12341
|
includeSensitiveFiles: config.includeSensitiveFiles,
|
|
12342
|
+
// The destination the instructions were written for. Not part of `digest`: the payload is
|
|
12343
|
+
// identical whatever this says, and a new delivery preference must not make an existing
|
|
12344
|
+
// snapshot fail `validate` as configuration drift.
|
|
12345
|
+
attachmentSlots: config.attachmentSlots,
|
|
12346
|
+
// The part-count ceiling the run enforced. Recorded because it decided the part sizes, and
|
|
12347
|
+
// omitted from `digest` when it is off so an existing snapshot does not start reporting
|
|
12348
|
+
// configuration drift.
|
|
12349
|
+
maxParts: config.maxParts ?? null,
|
|
11802
12350
|
discovery: config.discovery ?? "auto",
|
|
11803
12351
|
// A changed-files scope decides which files are in the snapshot, so the manifest that
|
|
11804
12352
|
// describes the run has to name it.
|
|
@@ -11869,6 +12417,10 @@ function generateSnapshot(configInput, options) {
|
|
|
11869
12417
|
incomplete,
|
|
11870
12418
|
warnings
|
|
11871
12419
|
};
|
|
12420
|
+
if (partitioned.warnings.length > 0) {
|
|
12421
|
+
manifest.warnings.push(...partitioned.warnings);
|
|
12422
|
+
manifest.totals.warningCount = manifest.warnings.length;
|
|
12423
|
+
}
|
|
11872
12424
|
manifest.totals.redactedLines = secretFindings.length;
|
|
11873
12425
|
manifest.totals.warningCount = manifest.warnings.length;
|
|
11874
12426
|
if (files.some((file) => file.isPreviewTruncated) && config.largeFileBytes < config.maxPartBytes) {
|
|
@@ -11925,6 +12477,15 @@ function generateSnapshot(configInput, options) {
|
|
|
11925
12477
|
if (auditText !== null) manifest.artifacts.audit = artifactRecord(auditText);
|
|
11926
12478
|
const readmeText = artifacts.readme ? generateReadme(manifest, artifacts) : null;
|
|
11927
12479
|
if (readmeText !== null) manifest.artifacts.readme = artifactRecord(readmeText);
|
|
12480
|
+
const promptText = artifacts.prompt ? generatePrompt(
|
|
12481
|
+
manifest,
|
|
12482
|
+
artifacts,
|
|
12483
|
+
config.attachmentSlots,
|
|
12484
|
+
// Commit subjects are user input and reach an artifact, so they go through the same
|
|
12485
|
+
// masking as every other name the run reproduces.
|
|
12486
|
+
recentCommitSubjects(config.cwd).map((subject) => maskPathText(subject, config.secretRules))
|
|
12487
|
+
) : null;
|
|
12488
|
+
if (promptText !== null) manifest.artifacts.prompt = artifactRecord(promptText);
|
|
11928
12489
|
if (projectTree !== null) manifest.artifacts.projectTree = artifactRecord(projectTree);
|
|
11929
12490
|
let monolithJson = null;
|
|
11930
12491
|
let monolithMarkdown = null;
|
|
@@ -12062,6 +12623,9 @@ function generateSnapshot(configInput, options) {
|
|
|
12062
12623
|
if (readmeText !== null) {
|
|
12063
12624
|
writeArtifact(stagingDir, "README.md", readmeText);
|
|
12064
12625
|
}
|
|
12626
|
+
if (promptText !== null) {
|
|
12627
|
+
writeArtifact(stagingDir, "PROMPT.md", promptText);
|
|
12628
|
+
}
|
|
12065
12629
|
if (artifacts.manifest) {
|
|
12066
12630
|
writeArtifact(stagingDir, "manifest.json", JSON.stringify(manifest, null, 2));
|
|
12067
12631
|
}
|
|
@@ -13478,6 +14042,7 @@ var VALIDATE_OPTIONS = [
|
|
|
13478
14042
|
"max-part-tokens",
|
|
13479
14043
|
"large-file-bytes",
|
|
13480
14044
|
"max-monolith-bytes",
|
|
14045
|
+
"max-parts",
|
|
13481
14046
|
"include-monolith",
|
|
13482
14047
|
"include-sensitive-files",
|
|
13483
14048
|
"skip-artifacts",
|
|
@@ -13503,6 +14068,8 @@ var COMMAND_OPTION_SCOPE = {
|
|
|
13503
14068
|
"max-part-tokens",
|
|
13504
14069
|
"large-file-bytes",
|
|
13505
14070
|
"max-monolith-bytes",
|
|
14071
|
+
"attachment-slots",
|
|
14072
|
+
"max-parts",
|
|
13506
14073
|
"include-monolith",
|
|
13507
14074
|
"include-sensitive-files",
|
|
13508
14075
|
"skip-artifacts",
|
|
@@ -13648,6 +14215,7 @@ var PACKAGE_NAME = "codebase-snapshot";
|
|
|
13648
14215
|
var MAJOR_VERSION = GENERATOR_VERSION.split(".")[0];
|
|
13649
14216
|
var ARTIFACT_SUMMARY = {
|
|
13650
14217
|
readme: "README.md describing the snapshot at the output root.",
|
|
14218
|
+
prompt: "PROMPT.md: the instruction sheet to paste with the snapshot, rendered from its manifest.",
|
|
13651
14219
|
manifest: "manifest.json: machine-readable index of every file, part, hash and config.",
|
|
13652
14220
|
parts: "parts/*.md: the packed, budget-limited markdown parts that carry the code.",
|
|
13653
14221
|
navigation: "reports/navigation.md: links between parts and layers.",
|
|
@@ -13657,6 +14225,7 @@ var ARTIFACT_SUMMARY = {
|
|
|
13657
14225
|
};
|
|
13658
14226
|
var ARTIFACT_DEFAULTS = {
|
|
13659
14227
|
readme: true,
|
|
14228
|
+
prompt: true,
|
|
13660
14229
|
manifest: true,
|
|
13661
14230
|
parts: true,
|
|
13662
14231
|
navigation: true,
|
|
@@ -13797,9 +14366,9 @@ function buildAgentContract() {
|
|
|
13797
14366
|
{
|
|
13798
14367
|
step: 6,
|
|
13799
14368
|
id: "consume",
|
|
13800
|
-
run: "read ./snapshot/
|
|
14369
|
+
run: "read ./snapshot/PROMPT.md first, then ./snapshot/parts/*.md, ./snapshot/manifest.json and ./snapshot/reports/audit.md",
|
|
13801
14370
|
expect: "the code, the index of what was included, and the risk findings",
|
|
13802
|
-
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."
|
|
14371
|
+
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."
|
|
13803
14372
|
}
|
|
13804
14373
|
],
|
|
13805
14374
|
commands: [
|
|
@@ -13936,6 +14505,20 @@ function buildAgentContract() {
|
|
|
13936
14505
|
appliesTo: optionAppliesTo("discovery"),
|
|
13937
14506
|
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)."
|
|
13938
14507
|
},
|
|
14508
|
+
{
|
|
14509
|
+
flag: "--attachment-slots",
|
|
14510
|
+
type: "number",
|
|
14511
|
+
default: "10",
|
|
14512
|
+
appliesTo: optionAppliesTo("attachment-slots"),
|
|
14513
|
+
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."
|
|
14514
|
+
},
|
|
14515
|
+
{
|
|
14516
|
+
flag: "--max-parts",
|
|
14517
|
+
type: "number",
|
|
14518
|
+
default: "unset",
|
|
14519
|
+
appliesTo: optionAppliesTo("max-parts"),
|
|
14520
|
+
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."
|
|
14521
|
+
},
|
|
13939
14522
|
{
|
|
13940
14523
|
flag: "--skip-artifacts",
|
|
13941
14524
|
type: "string",
|
|
@@ -14149,6 +14732,8 @@ function buildAgentContract() {
|
|
|
14149
14732
|
{ key: "includeSensitiveFiles", type: "boolean", default: false, summary: "Emit .env / *.pem / credential files." },
|
|
14150
14733
|
{ key: "include", type: "string[]", default: "[]", summary: "Allow-list of globs; empty means everything." },
|
|
14151
14734
|
{ key: "excludePatterns", type: "string[]", default: "[]", summary: "Extra exclude globs." },
|
|
14735
|
+
{ 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." },
|
|
14736
|
+
{ 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." },
|
|
14152
14737
|
{ 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." },
|
|
14153
14738
|
{ key: "artifacts", type: "object", default: "all on except monolith", summary: "Per-artifact opt-out." },
|
|
14154
14739
|
{ key: "budgets", type: "object", default: "{ default, byLayer }", summary: "Per-layer byte budgets." },
|
|
@@ -14163,6 +14748,7 @@ function buildAgentContract() {
|
|
|
14163
14748
|
output: {
|
|
14164
14749
|
layout: [
|
|
14165
14750
|
"<outDir>/README.md",
|
|
14751
|
+
"<outDir>/PROMPT.md",
|
|
14166
14752
|
"<outDir>/manifest.json",
|
|
14167
14753
|
"<outDir>/parts/part-NNN.md",
|
|
14168
14754
|
"<outDir>/reports/project-tree.md",
|
|
@@ -14176,6 +14762,7 @@ function buildAgentContract() {
|
|
|
14176
14762
|
"indexes.imports.byFile includes previewed files (their import specifiers are still extracted); such an entry carries `exportsOmitted: true` instead of pretending it exports nothing.",
|
|
14177
14763
|
"validate re-checks manifest.incomplete[] against files[] and refuses a manifest whose two statements of what is missing disagree.",
|
|
14178
14764
|
"manifest.skipped[] carries the path and the exact reason it was excluded.",
|
|
14765
|
+
"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.",
|
|
14179
14766
|
`The output directory is replaced atomically; ${MIN_MAX_PART_BYTES} bytes is the smallest legal budget.`
|
|
14180
14767
|
]
|
|
14181
14768
|
},
|
|
@@ -14346,6 +14933,10 @@ do not assume the repository is broken.
|
|
|
14346
14933
|
- \`snapshot/reports/audit.md\` \u2014 secrets found, large files, parse diagnostics, git
|
|
14347
14934
|
state. Read this before you quote code back to a user.
|
|
14348
14935
|
- \`snapshot/reports/project-tree.md\` and \`navigation.md\` \u2014 structure and cross-links.
|
|
14936
|
+
- \`snapshot/PROMPT.md\` \u2014 the instruction sheet to hand to the model that receives the
|
|
14937
|
+
snapshot: paste it with the parts. It is rendered from this run's manifest and names the
|
|
14938
|
+
parts, the partial files and the fingerprint, so do not rewrite it by hand \u2014 \`validate\`
|
|
14939
|
+
fails when it was edited.
|
|
14349
14940
|
|
|
14350
14941
|
## Project types
|
|
14351
14942
|
|
|
@@ -15407,6 +15998,8 @@ var CLI_OPTIONS = {
|
|
|
15407
15998
|
"max-part-bytes": { type: "string" },
|
|
15408
15999
|
"large-file-bytes": { type: "string" },
|
|
15409
16000
|
"max-monolith-bytes": { type: "string" },
|
|
16001
|
+
"attachment-slots": { type: "string" },
|
|
16002
|
+
"max-parts": { type: "string" },
|
|
15410
16003
|
"include-monolith": { type: "boolean" },
|
|
15411
16004
|
"include-sensitive-files": { type: "boolean" },
|
|
15412
16005
|
"skip-artifacts": { type: "string" },
|
|
@@ -15481,6 +16074,10 @@ Options:
|
|
|
15481
16074
|
--skeleton Emit TypeScript signatures instead of bodies
|
|
15482
16075
|
--sarif Also write reports/audit.sarif for GitHub Code Scanning
|
|
15483
16076
|
--include-sensitive-files Emit .env / *.pem / .npmrc / credential files
|
|
16077
|
+
--attachment-slots <n> Files the destination takes in one message (default: 10,
|
|
16078
|
+
0 = no limit); PROMPT.md plans the delivery to fit
|
|
16079
|
+
--max-parts <n> Experimental: grow the part budget until the snapshot has at
|
|
16080
|
+
most n parts, instead of adding parts as the code grows
|
|
15484
16081
|
--skip-artifacts <names> Comma-separated artifacts to omit
|
|
15485
16082
|
(readme, manifest, parts, navigation,
|
|
15486
16083
|
projectTree, audit, monolith)
|
|
@@ -15551,6 +16148,20 @@ function parseByteOption(raw, optionName, minimum, unit = "byte count") {
|
|
|
15551
16148
|
}
|
|
15552
16149
|
return value;
|
|
15553
16150
|
}
|
|
16151
|
+
function parseCountOption(raw, optionName, minimum = 0) {
|
|
16152
|
+
if (raw === void 0) return void 0;
|
|
16153
|
+
const trimmed = raw.trim();
|
|
16154
|
+
if (!/^\d+$/.test(trimmed) || !Number.isSafeInteger(Number(trimmed))) {
|
|
16155
|
+
throw new UsageError(
|
|
16156
|
+
`--${optionName} expects a whole number such as 10 or 20, received "${raw}".`
|
|
16157
|
+
);
|
|
16158
|
+
}
|
|
16159
|
+
const value = Number(trimmed);
|
|
16160
|
+
if (value < minimum) {
|
|
16161
|
+
throw new UsageError(`--${optionName} must be at least ${minimum}, received "${raw}".`);
|
|
16162
|
+
}
|
|
16163
|
+
return value;
|
|
16164
|
+
}
|
|
15554
16165
|
function parseArtifactList(raw, flag) {
|
|
15555
16166
|
const names = raw.split(",").map((name) => name.trim()).filter(Boolean);
|
|
15556
16167
|
if (names.length === 0) {
|
|
@@ -15792,6 +16403,11 @@ function parseCliArgs(argv) {
|
|
|
15792
16403
|
"max-monolith-bytes",
|
|
15793
16404
|
1
|
|
15794
16405
|
),
|
|
16406
|
+
attachmentSlots: parseCountOption(
|
|
16407
|
+
values["attachment-slots"],
|
|
16408
|
+
"attachment-slots"
|
|
16409
|
+
),
|
|
16410
|
+
maxParts: parseCountOption(values["max-parts"], "max-parts", 1),
|
|
15795
16411
|
skipArtifacts,
|
|
15796
16412
|
onlyArtifacts,
|
|
15797
16413
|
discovery: isDiscoveryMode(rawDiscovery) ? rawDiscovery : void 0,
|
|
@@ -16117,6 +16733,12 @@ async function runSetupCommand(invocation, options = {}) {
|
|
|
16117
16733
|
if (invocation.maxPartTokens !== void 0) {
|
|
16118
16734
|
generateArgs.push("--max-part-tokens", String(invocation.maxPartTokens));
|
|
16119
16735
|
}
|
|
16736
|
+
if (invocation.attachmentSlots !== void 0) {
|
|
16737
|
+
generateArgs.push("--attachment-slots", String(invocation.attachmentSlots));
|
|
16738
|
+
}
|
|
16739
|
+
if (invocation.maxParts !== void 0) {
|
|
16740
|
+
generateArgs.push("--max-parts", String(invocation.maxParts));
|
|
16741
|
+
}
|
|
16120
16742
|
if (invocation.skeleton === true) generateArgs.push("--skeleton");
|
|
16121
16743
|
if (invocation.sarif === true) generateArgs.push("--sarif");
|
|
16122
16744
|
if (invocation.noUpdateCheck) generateArgs.push("--no-update-check");
|
|
@@ -16359,6 +16981,8 @@ ${USAGE}
|
|
|
16359
16981
|
maxPartTokens: invocation.maxPartTokens,
|
|
16360
16982
|
largeFileBytes: invocation.largeFileBytes,
|
|
16361
16983
|
maxMonolithBytes: invocation.maxMonolithBytes,
|
|
16984
|
+
attachmentSlots: invocation.attachmentSlots,
|
|
16985
|
+
maxParts: invocation.maxParts,
|
|
16362
16986
|
skipArtifacts: invocation.skipArtifacts,
|
|
16363
16987
|
// `--only-artifacts` is forwarded as itself, not only as the derived suppression list:
|
|
16364
16988
|
// suppression cannot switch an artifact *on*, so a config that had turned one of the
|
|
@@ -16531,7 +17155,16 @@ ${USAGE}
|
|
|
16531
17155
|
);
|
|
16532
17156
|
}
|
|
16533
17157
|
}
|
|
16534
|
-
|
|
17158
|
+
const orientation = [
|
|
17159
|
+
artifacts.readme ? "README.md" : null,
|
|
17160
|
+
artifacts.prompt ? "PROMPT.md" : null
|
|
17161
|
+
].filter((name) => name !== null);
|
|
17162
|
+
if (orientation.length > 0) {
|
|
17163
|
+
info(
|
|
17164
|
+
` - Orientation: ${orientation.map((name) => displayOutPath(resolved.cwd, resolved.outDir, name)).join(", ")}`
|
|
17165
|
+
);
|
|
17166
|
+
}
|
|
17167
|
+
if (reports.length === 0 && !artifacts.parts && !artifacts.manifest && !artifacts.monolith && orientation.length === 0) {
|
|
16535
17168
|
info(` - Artifacts: all disabled (only the ownership marker was written)`);
|
|
16536
17169
|
}
|
|
16537
17170
|
info(` - Fingerprint: ${manifest.fingerprint}`);
|
|
@@ -16675,6 +17308,8 @@ async function runWatchLoop(invocation, resolved, options) {
|
|
|
16675
17308
|
maxPartTokens: invocation.maxPartTokens,
|
|
16676
17309
|
largeFileBytes: invocation.largeFileBytes,
|
|
16677
17310
|
maxMonolithBytes: invocation.maxMonolithBytes,
|
|
17311
|
+
attachmentSlots: invocation.attachmentSlots,
|
|
17312
|
+
maxParts: invocation.maxParts,
|
|
16678
17313
|
skipArtifacts: invocation.skipArtifacts,
|
|
16679
17314
|
onlyArtifacts: invocation.onlyArtifacts,
|
|
16680
17315
|
discovery: invocation.discovery,
|
|
@@ -16775,6 +17410,7 @@ exports.isGeneratedWatchPath = isGeneratedWatchPath;
|
|
|
16775
17410
|
exports.main = main;
|
|
16776
17411
|
exports.parseByteOption = parseByteOption;
|
|
16777
17412
|
exports.parseCliArgs = parseCliArgs;
|
|
17413
|
+
exports.parseCountOption = parseCountOption;
|
|
16778
17414
|
exports.parsePositiveInteger = parsePositiveInteger;
|
|
16779
17415
|
exports.watchPathsFor = watchPathsFor;
|
|
16780
17416
|
exports.watchSupportProblem = watchSupportProblem;
|