codebase-snapshot 0.10.1 → 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 +130 -0
- package/README.md +9 -1
- package/SECURITY.md +2 -2
- package/dist/bin.js +1247 -413
- package/dist/{chunk-WDJ3O3R4.js → chunk-5ZOXHBTW.js} +53 -30
- package/dist/{chunk-7DAW2LFZ.js → chunk-NJ75RVHO.js} +939 -180
- package/dist/cli.cjs +1246 -411
- package/dist/cli.d.cts +36 -11
- package/dist/cli.d.ts +36 -11
- package/dist/cli.js +60 -8
- package/dist/{generate-worker-D_mUjgXw.d.cts → generate-worker-BK4uJx7Z.d.cts} +17 -8
- package/dist/{generate-worker-D_mUjgXw.d.ts → generate-worker-BK4uJx7Z.d.ts} +17 -8
- package/dist/index.cjs +915 -173
- package/dist/index.d.cts +69 -24
- package/dist/index.d.ts +69 -24
- package/dist/index.js +1 -1
- package/dist/mcp.cjs +745 -2923
- package/dist/mcp.d.cts +1 -1
- package/dist/mcp.d.ts +1 -1
- package/dist/mcp.js +2 -2
- package/dist/{types-Z471HW65.d.cts → types-DGWw3SH2.d.cts} +75 -4
- package/dist/{types-Z471HW65.d.ts → types-DGWw3SH2.d.ts} +75 -4
- package/docs/cli.md +32 -8
- package/docs/codebase-token-budget.md +12 -9
- package/docs/configuration.md +71 -2
- package/docs/how-to-context-budget.md +1 -1
- package/docs/how-to-feed-a-repo-to-claude.md +40 -9
- package/docs/mcp.md +3 -3
- package/docs/output.md +60 -7
- package/docs/stale-context-is-your-bug.md +8 -4
- package/docs/vs-code2prompt.md +1 -1
- package/docs/vs-gitingest.md +1 -1
- package/docs/vs-repomix.md +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -637,9 +637,9 @@ var rubyProfile = {
|
|
|
637
637
|
eachLine(content, (line) => {
|
|
638
638
|
const trimmed = line.trim();
|
|
639
639
|
if (!trimmed || trimmed.startsWith("#")) return;
|
|
640
|
-
const
|
|
641
|
-
if (
|
|
642
|
-
summary.imports.push(`./${
|
|
640
|
+
const relative11 = REQUIRE_RELATIVE.exec(trimmed);
|
|
641
|
+
if (relative11) {
|
|
642
|
+
summary.imports.push(`./${relative11[1]}`);
|
|
643
643
|
return;
|
|
644
644
|
}
|
|
645
645
|
const required = REQUIRE.exec(trimmed);
|
|
@@ -998,6 +998,8 @@ function summarizeTypeScriptSource(relativePath, content) {
|
|
|
998
998
|
if (cjsExports.length > 0) {
|
|
999
999
|
summary.exportsKind = summary.exports.length > 0 ? "mixed" : "cjs";
|
|
1000
1000
|
summary.exports.push(...cjsExports);
|
|
1001
|
+
} else if (summary.exports.length > 0) {
|
|
1002
|
+
summary.exportsKind = "esm";
|
|
1001
1003
|
}
|
|
1002
1004
|
const dedupeSorted2 = (values) => Array.from(new Set(values)).sort((a, b) => a < b ? -1 : a > b ? 1 : 0);
|
|
1003
1005
|
summary.directives = dedupeSorted2(summary.directives);
|
|
@@ -1897,8 +1899,8 @@ function workspacePackageDirs(cwd, patterns) {
|
|
|
1897
1899
|
function scanWorkspacePackages(cwd, patterns) {
|
|
1898
1900
|
const files = /* @__PURE__ */ new Set();
|
|
1899
1901
|
const dependencies = /* @__PURE__ */ new Set();
|
|
1900
|
-
for (const
|
|
1901
|
-
const full = path16__namespace.join(cwd,
|
|
1902
|
+
for (const relative11 of workspacePackageDirs(cwd, patterns)) {
|
|
1903
|
+
const full = path16__namespace.join(cwd, relative11);
|
|
1902
1904
|
try {
|
|
1903
1905
|
for (const entry of fs15__namespace.readdirSync(full, { withFileTypes: true })) files.add(entry.name);
|
|
1904
1906
|
} catch {
|
|
@@ -3017,6 +3019,24 @@ var DEFAULT_SECRET_PATTERNS = [
|
|
|
3017
3019
|
),
|
|
3018
3020
|
valueGroup: 2
|
|
3019
3021
|
},
|
|
3022
|
+
{
|
|
3023
|
+
// A quoted assignment whose closing quote is **not on this line**.
|
|
3024
|
+
//
|
|
3025
|
+
// The rule above requires `\1`, so an unterminated literal never matched it and the
|
|
3026
|
+
// credential reached the artefact in clear with no finding at all. That is the shape a
|
|
3027
|
+
// truncated file, a hand-edited `.env` and a string that continues on the next line all
|
|
3028
|
+
// produce, and it was the only branch of the redaction pass that was silent.
|
|
3029
|
+
//
|
|
3030
|
+
// The value runs to the end of the line on purpose — there is no delimiter to stop at — and
|
|
3031
|
+
// a later quote of the same kind disables the rule (`(?!\1)`), so a balanced literal is
|
|
3032
|
+
// never matched here: `password: "abc" and "def"` belongs to the rule above.
|
|
3033
|
+
rule: "credential-assignment-unterminated",
|
|
3034
|
+
pattern: new RegExp(
|
|
3035
|
+
`(?:${QUOTED_CREDENTIAL_KEY}|${NOT_AFTER_QUOTE}(?<!id[-_])${STRONG_CREDENTIAL_NAME})\\s{0,8}${ASSIGN}\\s{0,8}(["'\`])((?:(?!\\1)[^\\\\\\n]|\\\\.){1,512})$`,
|
|
3036
|
+
"i"
|
|
3037
|
+
),
|
|
3038
|
+
valueGroup: 2
|
|
3039
|
+
},
|
|
3020
3040
|
{
|
|
3021
3041
|
// `pass` and `credentials` are ambiguous on their own, so they
|
|
3022
3042
|
// are accepted only against a quoted value long enough to be a credential.
|
|
@@ -3576,10 +3596,8 @@ function scanAndRedactSecrets(content, rules, filePath) {
|
|
|
3576
3596
|
}
|
|
3577
3597
|
if (spans.length > 0) {
|
|
3578
3598
|
const maskedLine = applySpans(line, spans);
|
|
3579
|
-
|
|
3580
|
-
|
|
3581
|
-
segments[index] = maskedLine;
|
|
3582
|
-
}
|
|
3599
|
+
recordFinding(lineNumber, matchedRules);
|
|
3600
|
+
segments[index] = !quotesAreBalanced(line) || quotesAreBalanced(maskedLine) ? maskedLine : applySpansKeepingQuotes(line, spans);
|
|
3583
3601
|
}
|
|
3584
3602
|
}
|
|
3585
3603
|
if (index + 1 < segments.length) lineNumber += 1;
|
|
@@ -3857,6 +3875,17 @@ function isDeclaredBinding(line, matchIndex, filePath) {
|
|
|
3857
3875
|
return DECLARATION_KEYWORDS.test(line.slice(from, runStart));
|
|
3858
3876
|
}
|
|
3859
3877
|
function applySpans(line, spans) {
|
|
3878
|
+
let out = "";
|
|
3879
|
+
let cursor = 0;
|
|
3880
|
+
for (const span of mergedSpans(line, spans)) {
|
|
3881
|
+
out += line.slice(cursor, span.start);
|
|
3882
|
+
out += REDACTION_MARKER;
|
|
3883
|
+
cursor = span.end;
|
|
3884
|
+
}
|
|
3885
|
+
out += line.slice(cursor);
|
|
3886
|
+
return out;
|
|
3887
|
+
}
|
|
3888
|
+
function mergedSpans(line, spans) {
|
|
3860
3889
|
const ordered = [...spans].sort((a, b) => a.start - b.start || a.end - b.end);
|
|
3861
3890
|
const merged = [];
|
|
3862
3891
|
for (const span of ordered) {
|
|
@@ -3867,11 +3896,25 @@ function applySpans(line, spans) {
|
|
|
3867
3896
|
if (last && start <= last.end) last.end = Math.max(last.end, end);
|
|
3868
3897
|
else merged.push({ start, end });
|
|
3869
3898
|
}
|
|
3899
|
+
return merged;
|
|
3900
|
+
}
|
|
3901
|
+
function applySpansKeepingQuotes(line, spans) {
|
|
3870
3902
|
let out = "";
|
|
3871
3903
|
let cursor = 0;
|
|
3872
|
-
for (const span of
|
|
3904
|
+
for (const span of mergedSpans(line, spans)) {
|
|
3873
3905
|
out += line.slice(cursor, span.start);
|
|
3874
|
-
|
|
3906
|
+
let run = false;
|
|
3907
|
+
for (let index = span.start; index < span.end; index += 1) {
|
|
3908
|
+
const char = line[index];
|
|
3909
|
+
if (char === '"' || char === "'" || char === "`" || char === "\\") {
|
|
3910
|
+
if (run) out += REDACTION_MARKER;
|
|
3911
|
+
run = false;
|
|
3912
|
+
out += char;
|
|
3913
|
+
continue;
|
|
3914
|
+
}
|
|
3915
|
+
run = true;
|
|
3916
|
+
}
|
|
3917
|
+
if (run) out += REDACTION_MARKER;
|
|
3875
3918
|
cursor = span.end;
|
|
3876
3919
|
}
|
|
3877
3920
|
out += line.slice(cursor);
|
|
@@ -3880,7 +3923,7 @@ function applySpans(line, spans) {
|
|
|
3880
3923
|
|
|
3881
3924
|
// src/version.ts
|
|
3882
3925
|
var GENERATOR_NAME = "codebase-snapshot";
|
|
3883
|
-
var GENERATOR_VERSION = "0.
|
|
3926
|
+
var GENERATOR_VERSION = "0.11.0";
|
|
3884
3927
|
var SCHEMA_VERSION = "3.0.0";
|
|
3885
3928
|
var LEGACY_GENERATOR_NAMES = ["@ankurhalder/codebase-snapshot"];
|
|
3886
3929
|
function isOurGeneratorName(name) {
|
|
@@ -3912,8 +3955,8 @@ function brokenLinkRecord(linkPath, relativePath, rootReal) {
|
|
|
3912
3955
|
};
|
|
3913
3956
|
}
|
|
3914
3957
|
function isInside(root, candidate) {
|
|
3915
|
-
const
|
|
3916
|
-
return
|
|
3958
|
+
const relative11 = path16__namespace.relative(root, candidate);
|
|
3959
|
+
return relative11 === "" || !relative11.startsWith(`..${path16__namespace.sep}`) && relative11 !== ".." && !path16__namespace.isAbsolute(relative11);
|
|
3917
3960
|
}
|
|
3918
3961
|
var GIT_OUTPUT_LIMIT = 68157440;
|
|
3919
3962
|
function getGitInfo(cwd, fallbackBranch = "main") {
|
|
@@ -4328,6 +4371,23 @@ function defaultIgnoreReason(relativePath, toolDirNames = DEFAULT_TOOL_DIR_NAMES
|
|
|
4328
4371
|
}
|
|
4329
4372
|
return null;
|
|
4330
4373
|
}
|
|
4374
|
+
function recentCommitSubjects(cwd, limit = 10) {
|
|
4375
|
+
try {
|
|
4376
|
+
const stdout = childProcess__namespace.execFileSync(
|
|
4377
|
+
"git",
|
|
4378
|
+
["log", "-n", String(limit), "--pretty=%s", "--no-color"],
|
|
4379
|
+
{
|
|
4380
|
+
cwd,
|
|
4381
|
+
stdio: ["ignore", "pipe", "ignore"],
|
|
4382
|
+
encoding: "utf8",
|
|
4383
|
+
maxBuffer: GIT_OUTPUT_LIMIT
|
|
4384
|
+
}
|
|
4385
|
+
);
|
|
4386
|
+
return stdout.split("\n").map((line) => line.trim()).filter((line) => line.length > 0);
|
|
4387
|
+
} catch {
|
|
4388
|
+
return [];
|
|
4389
|
+
}
|
|
4390
|
+
}
|
|
4331
4391
|
function listIgnoredPaths(cwd) {
|
|
4332
4392
|
try {
|
|
4333
4393
|
const stdout = childProcess__namespace.execFileSync(
|
|
@@ -4852,6 +4912,10 @@ function normalizeResolvedConfig(config) {
|
|
|
4852
4912
|
return markResolvedConfig({
|
|
4853
4913
|
...config,
|
|
4854
4914
|
discovery,
|
|
4915
|
+
// A spread copy built before the field existed carries no value; the default applies, and it
|
|
4916
|
+
// is re-validated because the number reaches a rendered artifact.
|
|
4917
|
+
attachmentSlots: resolveAttachmentSlots(config.attachmentSlots),
|
|
4918
|
+
maxParts: resolveMaxParts(config.maxParts),
|
|
4855
4919
|
includeMonolith: artifacts.monolith,
|
|
4856
4920
|
secretRules: compileSecretRules(config.secretRules),
|
|
4857
4921
|
artifacts,
|
|
@@ -4898,73 +4962,9 @@ function supportsTypeScriptImports() {
|
|
|
4898
4962
|
if (!Number.isFinite(major)) return false;
|
|
4899
4963
|
return major > 22 || major === 22 && minor >= 6;
|
|
4900
4964
|
}
|
|
4901
|
-
function stripJsonComments2(raw) {
|
|
4902
|
-
const text2 = raw.replace(/^\uFEFF/, "");
|
|
4903
|
-
let out = "";
|
|
4904
|
-
let inString = false;
|
|
4905
|
-
let escaped = false;
|
|
4906
|
-
for (let index = 0; index < text2.length; index += 1) {
|
|
4907
|
-
const char = text2[index];
|
|
4908
|
-
if (inString) {
|
|
4909
|
-
out += char;
|
|
4910
|
-
if (escaped) escaped = false;
|
|
4911
|
-
else if (char === "\\") escaped = true;
|
|
4912
|
-
else if (char === '"') inString = false;
|
|
4913
|
-
continue;
|
|
4914
|
-
}
|
|
4915
|
-
if (char === '"') {
|
|
4916
|
-
inString = true;
|
|
4917
|
-
out += char;
|
|
4918
|
-
continue;
|
|
4919
|
-
}
|
|
4920
|
-
if (char === "/" && text2[index + 1] === "/") {
|
|
4921
|
-
while (index < text2.length && text2[index] !== "\n" && text2[index] !== "\r") index += 1;
|
|
4922
|
-
index -= 1;
|
|
4923
|
-
continue;
|
|
4924
|
-
}
|
|
4925
|
-
if (char === "/" && text2[index + 1] === "*") {
|
|
4926
|
-
index += 2;
|
|
4927
|
-
while (index < text2.length && !(text2[index] === "*" && text2[index + 1] === "/")) {
|
|
4928
|
-
if (text2[index] === "\n" || text2[index] === "\r") out += text2[index];
|
|
4929
|
-
index += 1;
|
|
4930
|
-
}
|
|
4931
|
-
index += 1;
|
|
4932
|
-
continue;
|
|
4933
|
-
}
|
|
4934
|
-
out += char;
|
|
4935
|
-
}
|
|
4936
|
-
return stripTrailingCommas2(out);
|
|
4937
|
-
}
|
|
4938
|
-
function stripTrailingCommas2(text2) {
|
|
4939
|
-
let out = "";
|
|
4940
|
-
let inString = false;
|
|
4941
|
-
let escaped = false;
|
|
4942
|
-
for (let index = 0; index < text2.length; index += 1) {
|
|
4943
|
-
const char = text2[index];
|
|
4944
|
-
if (inString) {
|
|
4945
|
-
out += char;
|
|
4946
|
-
if (escaped) escaped = false;
|
|
4947
|
-
else if (char === "\\") escaped = true;
|
|
4948
|
-
else if (char === '"') inString = false;
|
|
4949
|
-
continue;
|
|
4950
|
-
}
|
|
4951
|
-
if (char === '"') {
|
|
4952
|
-
inString = true;
|
|
4953
|
-
out += char;
|
|
4954
|
-
continue;
|
|
4955
|
-
}
|
|
4956
|
-
if (char === ",") {
|
|
4957
|
-
let next = index + 1;
|
|
4958
|
-
while (next < text2.length && /\s/.test(text2[next])) next += 1;
|
|
4959
|
-
if (text2[next] === "}" || text2[next] === "]") continue;
|
|
4960
|
-
}
|
|
4961
|
-
out += char;
|
|
4962
|
-
}
|
|
4963
|
-
return out;
|
|
4964
|
-
}
|
|
4965
4965
|
function parseJsonish(raw, file) {
|
|
4966
4966
|
try {
|
|
4967
|
-
return JSON.parse(
|
|
4967
|
+
return JSON.parse(stripJsonComments(raw));
|
|
4968
4968
|
} catch (err) {
|
|
4969
4969
|
throw new Error(`Could not parse ${file}: ${err.message}`);
|
|
4970
4970
|
}
|
|
@@ -4982,8 +4982,9 @@ function describeValue2(value) {
|
|
|
4982
4982
|
return `${typeof value} (${String(value)})`;
|
|
4983
4983
|
}
|
|
4984
4984
|
var isThenable = (value) => typeof value.then === "function";
|
|
4985
|
-
var
|
|
4985
|
+
var CONFIG_KEY_NAMES = [
|
|
4986
4986
|
"artifacts",
|
|
4987
|
+
"attachmentSlots",
|
|
4987
4988
|
"branch",
|
|
4988
4989
|
"budgets",
|
|
4989
4990
|
"changedSince",
|
|
@@ -5001,6 +5002,7 @@ var CONFIG_KEYS = /* @__PURE__ */ new Set([
|
|
|
5001
5002
|
"layersMode",
|
|
5002
5003
|
"maxMonolithBytes",
|
|
5003
5004
|
"maxPartBytes",
|
|
5005
|
+
"maxParts",
|
|
5004
5006
|
"maxPartTokens",
|
|
5005
5007
|
"outDir",
|
|
5006
5008
|
"preset",
|
|
@@ -5013,7 +5015,8 @@ var CONFIG_KEYS = /* @__PURE__ */ new Set([
|
|
|
5013
5015
|
"skeleton",
|
|
5014
5016
|
"tmpDir",
|
|
5015
5017
|
"withDependents"
|
|
5016
|
-
]
|
|
5018
|
+
];
|
|
5019
|
+
var CONFIG_KEYS = new Set(CONFIG_KEY_NAMES);
|
|
5017
5020
|
function assertKnownConfigKeys(value, file) {
|
|
5018
5021
|
const unknownKeys = Object.keys(value).filter((key) => !CONFIG_KEYS.has(key));
|
|
5019
5022
|
if (unknownKeys.length === 0) return;
|
|
@@ -5205,6 +5208,7 @@ var MIN_MAX_PART_BYTES = 4096;
|
|
|
5205
5208
|
var MIN_MAX_PART_TOKENS = MIN_MAX_PART_BYTES / 4;
|
|
5206
5209
|
var ARTIFACT_NAMES = [
|
|
5207
5210
|
"readme",
|
|
5211
|
+
"prompt",
|
|
5208
5212
|
"manifest",
|
|
5209
5213
|
"parts",
|
|
5210
5214
|
"navigation",
|
|
@@ -5214,6 +5218,7 @@ var ARTIFACT_NAMES = [
|
|
|
5214
5218
|
];
|
|
5215
5219
|
var DEFAULT_ARTIFACTS = {
|
|
5216
5220
|
readme: true,
|
|
5221
|
+
prompt: true,
|
|
5217
5222
|
manifest: true,
|
|
5218
5223
|
parts: true,
|
|
5219
5224
|
navigation: true,
|
|
@@ -5274,6 +5279,25 @@ function resolveArtifacts(requested, skipped, includeMonolith, monolithOverride,
|
|
|
5274
5279
|
}
|
|
5275
5280
|
return artifacts;
|
|
5276
5281
|
}
|
|
5282
|
+
var DEFAULT_ATTACHMENT_SLOTS = 10;
|
|
5283
|
+
function resolveAttachmentSlots(value) {
|
|
5284
|
+
if (value === void 0 || value === null) return DEFAULT_ATTACHMENT_SLOTS;
|
|
5285
|
+
if (typeof value !== "number" || !Number.isInteger(value) || value < 0) {
|
|
5286
|
+
throw new Error(
|
|
5287
|
+
"attachmentSlots must be a whole number, with 0 meaning no limit (received " + describeValue2(value) + ")."
|
|
5288
|
+
);
|
|
5289
|
+
}
|
|
5290
|
+
return value;
|
|
5291
|
+
}
|
|
5292
|
+
function resolveMaxParts(value) {
|
|
5293
|
+
if (value === void 0 || value === null) return null;
|
|
5294
|
+
if (typeof value !== "number" || !Number.isInteger(value) || value < 1) {
|
|
5295
|
+
throw new Error(
|
|
5296
|
+
"maxParts must be a whole number of parts, or null to disable it (received " + describeValue2(value) + ")."
|
|
5297
|
+
);
|
|
5298
|
+
}
|
|
5299
|
+
return value;
|
|
5300
|
+
}
|
|
5277
5301
|
function strictPositiveInteger(value, fallback, label) {
|
|
5278
5302
|
if (value === void 0) return fallback;
|
|
5279
5303
|
if (typeof value !== "number" || !Number.isInteger(value) || value <= 0) {
|
|
@@ -5367,11 +5391,11 @@ function outputExcludePatterns(cwd, outDir, tmpDir) {
|
|
|
5367
5391
|
const patterns = [];
|
|
5368
5392
|
for (const dir of [outDir, tmpDir]) {
|
|
5369
5393
|
const absolute = path16__namespace.resolve(cwd, dir);
|
|
5370
|
-
const
|
|
5371
|
-
if (!
|
|
5394
|
+
const relative11 = path16__namespace.relative(cwd, absolute);
|
|
5395
|
+
if (!relative11 || relative11 === ".." || relative11.startsWith(`..${path16__namespace.sep}`) || path16__namespace.isAbsolute(relative11)) {
|
|
5372
5396
|
continue;
|
|
5373
5397
|
}
|
|
5374
|
-
patterns.push(`${
|
|
5398
|
+
patterns.push(`${relative11.replace(/\\/g, "/")}/**`);
|
|
5375
5399
|
}
|
|
5376
5400
|
return patterns;
|
|
5377
5401
|
}
|
|
@@ -5652,6 +5676,10 @@ function resolveConfig(userConfig, cliOptions, baseDir) {
|
|
|
5652
5676
|
"maxMonolithBytes"
|
|
5653
5677
|
),
|
|
5654
5678
|
includeSensitiveFiles,
|
|
5679
|
+
attachmentSlots: resolveAttachmentSlots(
|
|
5680
|
+
cliOptions?.attachmentSlots ?? userConfig?.attachmentSlots
|
|
5681
|
+
),
|
|
5682
|
+
maxParts: resolveMaxParts(cliOptions?.maxParts ?? userConfig?.maxParts),
|
|
5655
5683
|
...changedSince === void 0 ? {} : { changedSince },
|
|
5656
5684
|
...staged ? { staged } : {},
|
|
5657
5685
|
...withDependents ? { withDependents } : {},
|
|
@@ -5734,6 +5762,9 @@ function configDigest(config) {
|
|
|
5734
5762
|
includeMonolith: config.includeMonolith,
|
|
5735
5763
|
maxMonolithBytes: config.maxMonolithBytes ?? null,
|
|
5736
5764
|
includeSensitiveFiles: config.includeSensitiveFiles,
|
|
5765
|
+
// Only when the experimental mode is on: `null` is the off switch, and writing it into the
|
|
5766
|
+
// material would change the digest of every snapshot taken before the setting existed.
|
|
5767
|
+
...config.maxParts === null ? {} : { maxParts: config.maxParts },
|
|
5737
5768
|
artifacts: config.artifacts,
|
|
5738
5769
|
include: config.include,
|
|
5739
5770
|
excludePatterns: config.excludePatterns,
|
|
@@ -5906,7 +5937,7 @@ function generateAuditReport(manifest, secretFindings, secretRules) {
|
|
|
5906
5937
|
);
|
|
5907
5938
|
for (const file of affected) {
|
|
5908
5939
|
const status = file.isPreviewTruncated ? "Truncated" : "Full";
|
|
5909
|
-
const cutBy = file.truncationReason === "part-budget" ? "maxPartBytes" : "largeFileBytes";
|
|
5940
|
+
const cutBy = file.truncationReason === "part-budget" ? "part budget (maxPartBytes)" : "large-file budget (largeFileBytes)";
|
|
5910
5941
|
lines.push(
|
|
5911
5942
|
`| ${code(file.relativePath)} | ${file.sizeBytes} | ${file.lines} | ${file.includedBytes} | ${file.includedLines} | ${status} | ${cutBy} |`
|
|
5912
5943
|
);
|
|
@@ -6019,11 +6050,11 @@ function generateSarifReport(manifest, findings, rules, toolVersion) {
|
|
|
6019
6050
|
codebaseSnapshotFinding: `${findingPath}#L${line}#${finding.rules.join("+")}`
|
|
6020
6051
|
}
|
|
6021
6052
|
};
|
|
6022
|
-
}).sort(
|
|
6023
|
-
|
|
6024
|
-
|
|
6025
|
-
) || a.locations[0].physicalLocation.region.startLine - b.locations[0].physicalLocation.region.startLine
|
|
6026
|
-
);
|
|
6053
|
+
}).sort((a, b) => {
|
|
6054
|
+
const left = a.locations[0].physicalLocation.artifactLocation.uri;
|
|
6055
|
+
const right = b.locations[0].physicalLocation.artifactLocation.uri;
|
|
6056
|
+
return (left < right ? -1 : left > right ? 1 : 0) || a.locations[0].physicalLocation.region.startLine - b.locations[0].physicalLocation.region.startLine;
|
|
6057
|
+
});
|
|
6027
6058
|
const log = {
|
|
6028
6059
|
$schema: SARIF_SCHEMA,
|
|
6029
6060
|
version: SARIF_VERSION,
|
|
@@ -6114,6 +6145,7 @@ function truncatePreview(content, headLines, tailLines) {
|
|
|
6114
6145
|
// src/partitioner/chunker.ts
|
|
6115
6146
|
var HEADER_RESERVE_BYTES = 2048 + Buffer.byteLength(UNTRUSTED_CONTENT_NOTICE, "utf8") + 8;
|
|
6116
6147
|
var MIN_SECTION_BUDGET_BYTES = 512;
|
|
6148
|
+
var MIN_PART_BUDGET_BYTES = MIN_SECTION_BUDGET_BYTES + HEADER_RESERVE_BYTES;
|
|
6117
6149
|
var MAX_SPLIT_PASSES = 64;
|
|
6118
6150
|
var BUDGET_MARKER_RESERVE = 96;
|
|
6119
6151
|
function insertTokenLine(markdown, tokens) {
|
|
@@ -6152,10 +6184,17 @@ function partitionFilesForBuckets(buckets, contentFingerprint) {
|
|
|
6152
6184
|
const groups = [];
|
|
6153
6185
|
for (const bucket of buckets) {
|
|
6154
6186
|
if (bucket.files.length === 0) continue;
|
|
6155
|
-
|
|
6156
|
-
|
|
6157
|
-
|
|
6158
|
-
|
|
6187
|
+
if (!Number.isFinite(bucket.budgetBytes)) {
|
|
6188
|
+
throw new Error(
|
|
6189
|
+
`A part budget must be a finite number of bytes; received ${String(bucket.budgetBytes)}.`
|
|
6190
|
+
);
|
|
6191
|
+
}
|
|
6192
|
+
if (bucket.budgetBytes < MIN_PART_BUDGET_BYTES) {
|
|
6193
|
+
throw new Error(
|
|
6194
|
+
`A part budget of ${bucket.budgetBytes} B is below the ${MIN_PART_BUDGET_BYTES} B minimum: the header every part must carry is larger than that, so the budget could not be honoured. Use a budget of at least 4096 B.`
|
|
6195
|
+
);
|
|
6196
|
+
}
|
|
6197
|
+
const budget = bucket.budgetBytes;
|
|
6159
6198
|
const sectionBudget = budget - HEADER_RESERVE_BYTES;
|
|
6160
6199
|
const prepared = bucket.files.map((file) => prepareSection(file, sectionBudget, budget));
|
|
6161
6200
|
for (const sections of greedyGroups(prepared, budget)) groups.push({ sections, budget });
|
|
@@ -6685,10 +6724,420 @@ function generateNavigation(manifest) {
|
|
|
6685
6724
|
return lines.join("\n");
|
|
6686
6725
|
}
|
|
6687
6726
|
|
|
6727
|
+
// src/generator/prompt.ts
|
|
6728
|
+
var MAX_PART_ROWS = 16;
|
|
6729
|
+
var MAX_LAYER_ROWS = 8;
|
|
6730
|
+
var MAX_INCOMPLETE_ROWS = 50;
|
|
6731
|
+
var MAX_CENTRAL_FILES = 5;
|
|
6732
|
+
var MAX_ENTRY_POINTS = 4;
|
|
6733
|
+
var MAX_LARGEST_FILES = 3;
|
|
6734
|
+
var partWord = (count) => count === 1 ? "part" : "parts";
|
|
6735
|
+
var UNLIMITED_SLOTS = 0;
|
|
6736
|
+
var ENTRY_POINT = /(^|\/)(index|cli|main|bin|server|app|mod)\.[cm]?[jt]sx?$/;
|
|
6737
|
+
var TEST_PATH = /(^|\/)(tests?|__tests__)\//;
|
|
6738
|
+
var TEST_FILE = /\.(test|spec)\.[^.]+$/;
|
|
6739
|
+
function generatePrompt(manifest, artifacts, attachmentSlots = DEFAULT_ATTACHMENT_SLOTS, history = []) {
|
|
6740
|
+
const wrote = (name) => artifacts?.[name] !== false;
|
|
6741
|
+
const code = (value) => inlineCode(escapeControls(value));
|
|
6742
|
+
const lines = [
|
|
6743
|
+
"# PROMPT.md",
|
|
6744
|
+
"",
|
|
6745
|
+
"The brief and the apparatus for this snapshot. Paste this file first, then the parts it names.",
|
|
6746
|
+
"",
|
|
6747
|
+
"It is generated rather than written once: the system map, the omissions, the fingerprint and",
|
|
6748
|
+
"the history below are read from `manifest.json` and this repository, so they describe this run.",
|
|
6749
|
+
"Regenerate it after the code moves.",
|
|
6750
|
+
"",
|
|
6751
|
+
"---",
|
|
6752
|
+
"",
|
|
6753
|
+
"```text",
|
|
6754
|
+
"You are working on a codebase you cannot clone, run or grep. Everything you know about it comes",
|
|
6755
|
+
"from the snapshot that follows this instruction. Where these notes and the snapshot disagree,",
|
|
6756
|
+
"the snapshot is what exists.",
|
|
6757
|
+
"",
|
|
6758
|
+
"## The job",
|
|
6759
|
+
"",
|
|
6760
|
+
"Find what is still wrong or will break. How you read the code is yours to decide - by",
|
|
6761
|
+
"subsystem, by data flow, by the invariants you derive yourself. What you owe in return is an",
|
|
6762
|
+
"honest account of what you covered and what you did not.",
|
|
6763
|
+
"",
|
|
6764
|
+
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,",
|
|
6765
|
+
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.",
|
|
6766
|
+
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.",
|
|
6767
|
+
"",
|
|
6768
|
+
"If the task at the end asks for something narrower - explain a file, review a change, answer a",
|
|
6769
|
+
"question - that task wins. The standard and the coverage duty below still apply to it.",
|
|
6770
|
+
""
|
|
6771
|
+
];
|
|
6772
|
+
lines.push(...haveSection(wrote), "");
|
|
6773
|
+
lines.push(...systemSection(manifest, code), "");
|
|
6774
|
+
lines.push(...historySection(history), "");
|
|
6775
|
+
lines.push(...barSection(), "");
|
|
6776
|
+
lines.push(...coverageSection(manifest, code, wrote("audit")), "");
|
|
6777
|
+
lines.push(...answerSection(), "");
|
|
6778
|
+
lines.push(...calibrationSection(), "");
|
|
6779
|
+
lines.push(...snapshotSection(manifest, code), "");
|
|
6780
|
+
lines.push(...deliverySection(manifest, wrote("parts"), attachmentSlots));
|
|
6781
|
+
lines.push(
|
|
6782
|
+
"## Your task",
|
|
6783
|
+
"",
|
|
6784
|
+
"<replace with the question, the area to review, or the subsystem to audit>",
|
|
6785
|
+
"```"
|
|
6786
|
+
);
|
|
6787
|
+
lines.push(
|
|
6788
|
+
"",
|
|
6789
|
+
"---",
|
|
6790
|
+
"",
|
|
6791
|
+
"## Why this file exists",
|
|
6792
|
+
"",
|
|
6793
|
+
"Parts on their own are a dump: the model receives text, has no idea what was left out of it,",
|
|
6794
|
+
"and fills the gap by invention. A brief on its own is a wish list: it cannot say which files",
|
|
6795
|
+
"are present, which are partial or which part holds what. This file is both halves, and the",
|
|
6796
|
+
"facts in it move with the snapshot.",
|
|
6797
|
+
"",
|
|
6798
|
+
"## Keeping it true",
|
|
6799
|
+
"",
|
|
6800
|
+
"- It is one of the artifacts recorded in `manifest.json` under `artifacts.prompt`, so deleting",
|
|
6801
|
+
" or editing `PROMPT.md` makes `snapshot validate` fail.",
|
|
6802
|
+
"- `--skip-artifacts prompt`, or `artifacts: { prompt: false }` in the config, turns it off.",
|
|
6803
|
+
"- The history section disappears when git cannot be read, rather than being invented.",
|
|
6804
|
+
"- If the code moves, regenerate. A brief naming the previous run parts is worse than no",
|
|
6805
|
+
" brief, because it reads as current.",
|
|
6806
|
+
""
|
|
6807
|
+
);
|
|
6808
|
+
return lines.join("\n");
|
|
6809
|
+
}
|
|
6810
|
+
function haveSection(wrote) {
|
|
6811
|
+
const out = ["## What you have", ""];
|
|
6812
|
+
const bullets = [];
|
|
6813
|
+
if (wrote("readme")) {
|
|
6814
|
+
bullets.push("- `README.md` - orientation: metrics, the part table, and the fingerprint.");
|
|
6815
|
+
}
|
|
6816
|
+
if (wrote("manifest")) {
|
|
6817
|
+
bullets.push(
|
|
6818
|
+
"- `manifest.json` - the index. Per file: `relativePath`, `layer`, `kind`, `language`,",
|
|
6819
|
+
" `part`, `sha256`, `inclusionMode`, `truncationReason`, `omittedRanges`. It also carries",
|
|
6820
|
+
" every excluded path under `skipped[]` with its reason, and `incomplete[]`, which names",
|
|
6821
|
+
" every included file whose emitted body is not the whole file."
|
|
6822
|
+
);
|
|
6823
|
+
}
|
|
6824
|
+
if (wrote("navigation")) {
|
|
6825
|
+
bullets.push("- `reports/navigation.md` - file to part. Locate here before you read anything.");
|
|
6826
|
+
}
|
|
6827
|
+
if (wrote("projectTree")) {
|
|
6828
|
+
bullets.push("- `reports/project-tree.md` - the directory shape of what was included.");
|
|
6829
|
+
}
|
|
6830
|
+
if (wrote("audit")) {
|
|
6831
|
+
bullets.push(
|
|
6832
|
+
"- `reports/audit.md` - secret findings, the files whose lines were redacted, large files,",
|
|
6833
|
+
" parse diagnostics and the git state the snapshot was taken from."
|
|
6834
|
+
);
|
|
6835
|
+
}
|
|
6836
|
+
if (wrote("parts")) {
|
|
6837
|
+
bullets.push(
|
|
6838
|
+
"- `parts/part-NNN.md` - the code itself, split to a fixed byte budget. Each part states its",
|
|
6839
|
+
" own number, the files it contains, and the fingerprint it was built from."
|
|
6840
|
+
);
|
|
6841
|
+
}
|
|
6842
|
+
if (wrote("monolith")) {
|
|
6843
|
+
bullets.push(
|
|
6844
|
+
"- `full-codebase.json` and `full-codebase.md` - the entire payload in one file each.",
|
|
6845
|
+
" Where they are present, they supersede the parts: nothing was left out of them."
|
|
6846
|
+
);
|
|
6847
|
+
}
|
|
6848
|
+
if (bullets.length === 0) {
|
|
6849
|
+
bullets.push(
|
|
6850
|
+
"- Nothing but this brief: every code artifact was disabled for this run. Ask for a snapshot",
|
|
6851
|
+
" generated with the artifacts you need, and do not answer from memory."
|
|
6852
|
+
);
|
|
6853
|
+
}
|
|
6854
|
+
out.push(...bullets);
|
|
6855
|
+
return out;
|
|
6856
|
+
}
|
|
6857
|
+
function systemSection(manifest, code) {
|
|
6858
|
+
const out = ["## The system", ""];
|
|
6859
|
+
const layers = Object.entries(manifest.layers).sort((a, b) => b[1] - a[1] || a[0].localeCompare(b[0]));
|
|
6860
|
+
if (layers.length > 0) {
|
|
6861
|
+
const shown = layers.slice(0, MAX_LAYER_ROWS).map(([name, count]) => code(name) + " " + formatNumber(count));
|
|
6862
|
+
const rest = layers.length > MAX_LAYER_ROWS ? ", and " + formatNumber(layers.length - MAX_LAYER_ROWS) + " more" : "";
|
|
6863
|
+
out.push("- Layers, by file count: " + shown.join(", ") + rest + ".");
|
|
6864
|
+
}
|
|
6865
|
+
const central = manifest.indexes.imports.centralFiles;
|
|
6866
|
+
if (central.length > 0) {
|
|
6867
|
+
const shown = central.slice(0, MAX_CENTRAL_FILES).map((entry) => code(entry.path) + " (" + formatNumber(entry.importedByCount) + ")").join(", ");
|
|
6868
|
+
out.push(
|
|
6869
|
+
"- Load-bearing modules, by how many files import them: " + shown + ".",
|
|
6870
|
+
" A change here reaches the most call sites; read it before judging anything that uses it."
|
|
6871
|
+
);
|
|
6872
|
+
}
|
|
6873
|
+
const entryPoints = manifest.files.map((file) => file.relativePath).filter((path17) => ENTRY_POINT.test(path17)).sort((a, b) => a.split("/").length - b.split("/").length || a.length - b.length).slice(0, MAX_ENTRY_POINTS);
|
|
6874
|
+
out.push(
|
|
6875
|
+
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"
|
|
6876
|
+
);
|
|
6877
|
+
if (entryPoints.length === 0) out.push(" starts, and the call graph in `manifest.json` is the map.");
|
|
6878
|
+
const routes = manifest.indexes.routes.length;
|
|
6879
|
+
const handlers = manifest.indexes.handlers.length;
|
|
6880
|
+
const components = manifest.indexes.components.length;
|
|
6881
|
+
const routesShown = manifest.indexes.routes.slice(0, 4).map((route) => code(route.path));
|
|
6882
|
+
const componentsShown = manifest.indexes.components.slice(0, 4).map((entry) => code(entry.path));
|
|
6883
|
+
if (routes + handlers + components === 0) {
|
|
6884
|
+
out.push(
|
|
6885
|
+
"- No routes, handlers or UI components were recorded: this snapshot indexes no HTTP or",
|
|
6886
|
+
" component surface. Do not go looking for one, and do not infer one from a file name."
|
|
6887
|
+
);
|
|
6888
|
+
} else {
|
|
6889
|
+
const parts = [];
|
|
6890
|
+
if (routes > 0) parts.push(formatNumber(routes) + " route(s), e.g. " + routesShown.join(", "));
|
|
6891
|
+
if (handlers > 0) parts.push(formatNumber(handlers) + " handler(s)");
|
|
6892
|
+
if (components > 0) parts.push(formatNumber(components) + " component(s), e.g. " + componentsShown.join(", "));
|
|
6893
|
+
out.push("- Surfaces the index found: " + parts.join("; ") + ".");
|
|
6894
|
+
}
|
|
6895
|
+
const largest = [...manifest.files].sort((a, b) => b.includedBytes - a.includedBytes).slice(0, MAX_LARGEST_FILES);
|
|
6896
|
+
if (largest.length > 0) {
|
|
6897
|
+
out.push(
|
|
6898
|
+
"- Largest files: " + largest.map((file) => code(file.relativePath) + " (" + formatNumber(Math.round(file.includedBytes / 1024)) + " KB)").join(", ") + "."
|
|
6899
|
+
);
|
|
6900
|
+
}
|
|
6901
|
+
const tests = manifest.files.filter(
|
|
6902
|
+
(file) => TEST_PATH.test(file.relativePath) || TEST_FILE.test(file.relativePath)
|
|
6903
|
+
);
|
|
6904
|
+
if (tests.length > 0) {
|
|
6905
|
+
const testBytes = tests.reduce((total, file) => total + file.includedBytes, 0);
|
|
6906
|
+
const allBytes = manifest.files.reduce((total, file) => total + file.includedBytes, 0);
|
|
6907
|
+
const share = allBytes === 0 ? 0 : Math.round(testBytes / allBytes * 100);
|
|
6908
|
+
out.push(
|
|
6909
|
+
"- Tests: " + formatNumber(tests.length) + " file(s), " + share + "% of the included bytes.",
|
|
6910
|
+
" They are evidence of intent, not of behaviour: a fixture can encode a payload shape the",
|
|
6911
|
+
" real system never sends."
|
|
6912
|
+
);
|
|
6913
|
+
}
|
|
6914
|
+
return out;
|
|
6915
|
+
}
|
|
6916
|
+
function historySection(history) {
|
|
6917
|
+
const out = ["## What came before", ""];
|
|
6918
|
+
if (history.length === 0) {
|
|
6919
|
+
out.push(
|
|
6920
|
+
"No history was readable: this is not a git checkout, or git could not be run. Nothing about",
|
|
6921
|
+
"what came before can be claimed from here, and that is not evidence that the code is new."
|
|
6922
|
+
);
|
|
6923
|
+
return out;
|
|
6924
|
+
}
|
|
6925
|
+
out.push(
|
|
6926
|
+
"Commit subjects, newest first. They are claims by whoever wrote them, not evidence - the code",
|
|
6927
|
+
"beside them is the evidence. If one of these fixes looks incomplete, quote the lines and say",
|
|
6928
|
+
"which call site it missed.",
|
|
6929
|
+
""
|
|
6930
|
+
);
|
|
6931
|
+
for (const subject of history) out.push("- " + subject);
|
|
6932
|
+
return out;
|
|
6933
|
+
}
|
|
6934
|
+
function barSection() {
|
|
6935
|
+
return [
|
|
6936
|
+
"## The bar",
|
|
6937
|
+
"",
|
|
6938
|
+
"A finding is a concrete way the code breaks or lies, supported by quoted lines: the path and",
|
|
6939
|
+
"line, the input or state that reaches it, what happens next, and why the guard that appears to",
|
|
6940
|
+
"stop it does not. A comment is not behaviour. A passing test is evidence of intent, not of",
|
|
6941
|
+
"behaviour.",
|
|
6942
|
+
"",
|
|
6943
|
+
"- No style, naming, formatting, add-types, add-tests, consider-X or speculative rewrites.",
|
|
6944
|
+
"- Never invent a finding to fill a section. A clean surface is proven by quoting the guard",
|
|
6945
|
+
" that makes it clean.",
|
|
6946
|
+
"- Mark confidence, and name the check - a test, a run, an input - that would settle anything",
|
|
6947
|
+
" you cannot decide by reading.",
|
|
6948
|
+
"- Separate what the code does from what the deployment or configuration does. Both are",
|
|
6949
|
+
" findings; they have different owners and different fixes."
|
|
6950
|
+
];
|
|
6951
|
+
}
|
|
6952
|
+
function coverageSection(manifest, code, auditWritten) {
|
|
6953
|
+
const out = ["## Coverage", ""];
|
|
6954
|
+
const reasons = /* @__PURE__ */ new Map();
|
|
6955
|
+
for (const record of manifest.skipped) {
|
|
6956
|
+
reasons.set(record.reason, (reasons.get(record.reason) ?? 0) + 1);
|
|
6957
|
+
}
|
|
6958
|
+
const tally = [...reasons.entries()].sort((a, b) => b[1] - a[1] || a[0].localeCompare(b[0])).map(([reason, count]) => code(reason) + " " + formatNumber(count)).join(", ");
|
|
6959
|
+
out.push(
|
|
6960
|
+
"- " + 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 + ")" : "") + ".",
|
|
6961
|
+
" `manifest.skipped[]` names each one and why. An absent path is not a clean path."
|
|
6962
|
+
);
|
|
6963
|
+
out.push(...incompleteSection(manifest, code));
|
|
6964
|
+
out.push(...redactionSection(manifest, auditWritten));
|
|
6965
|
+
out.push(
|
|
6966
|
+
"- Everything unseen is unread, never clean. If you were given only some of the parts, say",
|
|
6967
|
+
" which ones are missing before you answer. A file the index names but the parts do not carry",
|
|
6968
|
+
" is an input defect, not a code finding - report it as one."
|
|
6969
|
+
);
|
|
6970
|
+
return out;
|
|
6971
|
+
}
|
|
6972
|
+
function answerSection() {
|
|
6973
|
+
return [
|
|
6974
|
+
"## What a useful answer contains",
|
|
6975
|
+
"",
|
|
6976
|
+
"- An opening line, filled from This snapshot below:",
|
|
6977
|
+
"",
|
|
6978
|
+
" snapshot <fingerprint> generated <generatedAt>",
|
|
6979
|
+
"",
|
|
6980
|
+
"- What you read and what you did not, named by path or by part.",
|
|
6981
|
+
"- Findings ordered by consequence, each with the lines quoted.",
|
|
6982
|
+
"- The checks or attacks that failed, and the line or guard that blocked them. A failed attack",
|
|
6983
|
+
" is how anyone knows an invariant is real rather than asserted.",
|
|
6984
|
+
"- What you retracted after re-reading.",
|
|
6985
|
+
"- What only a run, a test or a host can settle, and the check that would settle each.",
|
|
6986
|
+
"- One paragraph on the failure you would bet on next.",
|
|
6987
|
+
"- A closing line: Needed but not received: <paths>, or none. That line is not decoration -",
|
|
6988
|
+
" an invented function is indistinguishable from a real one, and this is where you name",
|
|
6989
|
+
" the gap you filled by asking instead of guessing."
|
|
6990
|
+
];
|
|
6991
|
+
}
|
|
6992
|
+
function calibrationSection() {
|
|
6993
|
+
return [
|
|
6994
|
+
"## Calibration",
|
|
6995
|
+
"",
|
|
6996
|
+
"The findings that matter here do not crash. They look like:",
|
|
6997
|
+
"",
|
|
6998
|
+
"- a guard applied at one call site and not its twin - the route checks, the timer does not;",
|
|
6999
|
+
"- a budget shorter than the work it guards, so the caller gives up while the work continues;",
|
|
7000
|
+
"- a success flag that means the call returned, consumed as the change happened;",
|
|
7001
|
+
"- a document that describes a different run than the one beside it;",
|
|
7002
|
+
"- a default that fabricates a number when the measurement failed.",
|
|
7003
|
+
"",
|
|
7004
|
+
"None of these throw. All are invisible in a summary."
|
|
7005
|
+
];
|
|
7006
|
+
}
|
|
7007
|
+
function snapshotSection(manifest, code) {
|
|
7008
|
+
const out = ["## This snapshot", ""];
|
|
7009
|
+
out.push("- Fingerprint: " + code(manifest.fingerprint) + " - quote it verbatim in your answer.");
|
|
7010
|
+
out.push(
|
|
7011
|
+
"- Generated: " + code(manifest.generatedAt) + " from branch " + code(manifest.git.branch) + " at commit " + code(manifest.git.commit.slice(0, 8)) + "."
|
|
7012
|
+
);
|
|
7013
|
+
out.push(
|
|
7014
|
+
manifest.git.isDirty ? " The working tree had uncommitted changes at generation time." : " The working tree was clean at generation time."
|
|
7015
|
+
);
|
|
7016
|
+
out.push(
|
|
7017
|
+
"- Validation: `manifest.validation.status` was " + code(manifest.validation.status) + " at generation time.",
|
|
7018
|
+
" That describes the run, not now: if the tree may have moved since, the snapshot is a",
|
|
7019
|
+
" claim that needs re-checking, not a fact."
|
|
7020
|
+
);
|
|
7021
|
+
if (manifest.parts.length > 0) {
|
|
7022
|
+
out.push(
|
|
7023
|
+
"- Parts: " + formatNumber(manifest.parts.length) + " at a " + formatNumber(Math.round(manifest.budgets.maxPartBytes / 1024)) + " KB ceiling" + (manifest.parts.length === 1 ? ":" : " each:")
|
|
7024
|
+
);
|
|
7025
|
+
for (const part of manifest.parts.slice(0, MAX_PART_ROWS)) {
|
|
7026
|
+
out.push(" - " + code(part.filename) + " - " + formatNumber(part.fileCount) + " file(s)");
|
|
7027
|
+
}
|
|
7028
|
+
if (manifest.parts.length > MAX_PART_ROWS) {
|
|
7029
|
+
out.push(
|
|
7030
|
+
" - and " + formatNumber(manifest.parts.length - MAX_PART_ROWS) + " more, tabled in `README.md`"
|
|
7031
|
+
);
|
|
7032
|
+
}
|
|
7033
|
+
}
|
|
7034
|
+
return out;
|
|
7035
|
+
}
|
|
7036
|
+
function incompleteSection(manifest, code) {
|
|
7037
|
+
const out = [];
|
|
7038
|
+
const list2 = manifest.incomplete;
|
|
7039
|
+
if (list2.length === 0) {
|
|
7040
|
+
out.push("- Partial files: none. Every included file is present in full.");
|
|
7041
|
+
return out;
|
|
7042
|
+
}
|
|
7043
|
+
out.push(
|
|
7044
|
+
"- Partial files: " + formatNumber(list2.length) + ". These are present only in part, and the",
|
|
7045
|
+
" missing lines are named, not implied:"
|
|
7046
|
+
);
|
|
7047
|
+
for (const entry of list2.slice(0, MAX_INCOMPLETE_ROWS)) {
|
|
7048
|
+
const ranges = entry.omittedRanges.map(([start, end]) => start === end ? String(start) : start + "-" + end).join(", ");
|
|
7049
|
+
out.push(
|
|
7050
|
+
" - " + code(entry.relativePath) + " in " + code(entry.part) + " - " + entry.reason + ", lines " + ranges + " (" + formatNumber(entry.omittedLines) + " of " + formatNumber(entry.lines) + " missing)"
|
|
7051
|
+
);
|
|
7052
|
+
}
|
|
7053
|
+
if (list2.length > MAX_INCOMPLETE_ROWS) {
|
|
7054
|
+
out.push(
|
|
7055
|
+
" - and " + formatNumber(list2.length - MAX_INCOMPLETE_ROWS) + " more, all named in `manifest.json` under `incomplete[]`"
|
|
7056
|
+
);
|
|
7057
|
+
}
|
|
7058
|
+
return out;
|
|
7059
|
+
}
|
|
7060
|
+
function redactionSection(manifest, auditWritten) {
|
|
7061
|
+
const redacted = manifest.totals.redactedLines;
|
|
7062
|
+
if (redacted === 0) {
|
|
7063
|
+
return ["- Redacted: no line matched a secret rule."];
|
|
7064
|
+
}
|
|
7065
|
+
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.";
|
|
7066
|
+
return [
|
|
7067
|
+
"- Redacted: " + formatNumber(redacted) + " line(s) had values masked before you received them.",
|
|
7068
|
+
" A masked span is a deliberate redaction, not an empty value.",
|
|
7069
|
+
" " + where
|
|
7070
|
+
];
|
|
7071
|
+
}
|
|
7072
|
+
function deliverySection(manifest, partsWritten, slots) {
|
|
7073
|
+
if (!partsWritten || manifest.parts.length === 0) return [];
|
|
7074
|
+
const parts = manifest.parts.length;
|
|
7075
|
+
const wholeSet = parts + 5;
|
|
7076
|
+
const unlimited = slots <= UNLIMITED_SLOTS;
|
|
7077
|
+
const out = ["## Attaching this", ""];
|
|
7078
|
+
out.push(
|
|
7079
|
+
"Paste this file as text: instructions cost no attachment slot. Attach the files it names.",
|
|
7080
|
+
"",
|
|
7081
|
+
"- Every part opens with `# Codebase Snapshot Part NNN of MMM` and repeats the fingerprint",
|
|
7082
|
+
" above, so check both before relying on one. A part you were not given is not an empty part."
|
|
7083
|
+
);
|
|
7084
|
+
if (unlimited) {
|
|
7085
|
+
out.push(
|
|
7086
|
+
"- No attachment limit is configured, so every file can travel: " + parts + " " + partWord(parts) + " plus `manifest.json`, `README.md` and the three reports (" + wholeSet + " files)."
|
|
7087
|
+
);
|
|
7088
|
+
} else if (wholeSet <= slots) {
|
|
7089
|
+
out.push(
|
|
7090
|
+
"- A " + slots + "-file destination carries the whole set: " + parts + " " + partWord(parts) + " plus `manifest.json`, `README.md` and the three reports - " + wholeSet + " of " + slots + "."
|
|
7091
|
+
);
|
|
7092
|
+
} else if (parts + 1 <= slots) {
|
|
7093
|
+
out.push(
|
|
7094
|
+
"- A " + slots + "-file destination carries " + parts + " " + partWord(parts) + " and",
|
|
7095
|
+
" `manifest.json` (" + (parts + 1) + " of " + slots + "); `README.md` and",
|
|
7096
|
+
" `reports/` stay behind - the brief above carries what they add."
|
|
7097
|
+
);
|
|
7098
|
+
} else if (parts <= slots) {
|
|
7099
|
+
out.push(
|
|
7100
|
+
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",
|
|
7101
|
+
" `reports/` stay behind. The brief above carries what they add."
|
|
7102
|
+
);
|
|
7103
|
+
if (parts > 1) {
|
|
7104
|
+
out.push(
|
|
7105
|
+
" Either raise `--max-part-bytes` to merge the parts, or set `--max-parts " + slots + "` and let the parts grow to the count instead."
|
|
7106
|
+
);
|
|
7107
|
+
}
|
|
7108
|
+
} else {
|
|
7109
|
+
out.push(
|
|
7110
|
+
"- The " + parts + " parts do not fit a " + slots + "-file destination: at most " + slots + " can be attached.",
|
|
7111
|
+
" Choose by task - `reports/navigation.md` maps a file to its part - and name the parts",
|
|
7112
|
+
" you left out, or regenerate with `--max-part-bytes " + suggestBudgetBytes(manifest, slots) + "` for about " + (slots - 1) + " parts. `--max-parts " + slots + "` grows the parts until",
|
|
7113
|
+
" they fit instead, and says so when they end up larger than maxPartBytes."
|
|
7114
|
+
);
|
|
7115
|
+
}
|
|
7116
|
+
out.push(
|
|
7117
|
+
"- If you were given only some of them, say which parts are missing before you answer, and",
|
|
7118
|
+
" name the files you needed. Do not infer the contents of a part you did not receive.",
|
|
7119
|
+
""
|
|
7120
|
+
);
|
|
7121
|
+
return out;
|
|
7122
|
+
}
|
|
7123
|
+
function suggestBudgetBytes(manifest, slots) {
|
|
7124
|
+
const total = manifest.parts.reduce((sum, part) => sum + part.byteSize, 0);
|
|
7125
|
+
const target = Math.max(1, slots - 1);
|
|
7126
|
+
const estimated = Math.ceil(total / target * 1.15);
|
|
7127
|
+
const rounded = Math.ceil(estimated / 16384) * 16384;
|
|
7128
|
+
const budget = Math.max(rounded, manifest.budgets.maxPartBytes);
|
|
7129
|
+
return Math.round(budget / 1024) + "k";
|
|
7130
|
+
}
|
|
7131
|
+
|
|
6688
7132
|
// src/generator/readme.ts
|
|
6689
7133
|
function generateReadme(manifest, artifacts) {
|
|
6690
7134
|
const wrote = (name) => artifacts?.[name] !== false;
|
|
6691
7135
|
const reportLinks = [];
|
|
7136
|
+
if (wrote("prompt")) {
|
|
7137
|
+
reportLinks.push(
|
|
7138
|
+
"- [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."
|
|
7139
|
+
);
|
|
7140
|
+
}
|
|
6692
7141
|
if (wrote("navigation")) {
|
|
6693
7142
|
reportLinks.push(
|
|
6694
7143
|
"- [reports/navigation.md](reports/navigation.md) \u2014 Comprehensive file directory mapping files to chunk files."
|
|
@@ -6758,6 +7207,11 @@ function generateReadme(manifest, artifacts) {
|
|
|
6758
7207
|
lines.push("", "## Snapshot Parts", "", "No parts were written for this run.");
|
|
6759
7208
|
}
|
|
6760
7209
|
const readOrder = [];
|
|
7210
|
+
if (wrote("prompt")) {
|
|
7211
|
+
readOrder.push(
|
|
7212
|
+
"1. Hand `PROMPT.md` to the model that receives this snapshot: it names the parts, the partial files and the fingerprint of this run."
|
|
7213
|
+
);
|
|
7214
|
+
}
|
|
6761
7215
|
if (wrote("navigation") || wrote("projectTree")) {
|
|
6762
7216
|
const first = [wrote("navigation") ? "`reports/navigation.md`" : null, wrote("projectTree") ? "`reports/project-tree.md`" : null].filter(Boolean).join(" or ");
|
|
6763
7217
|
readOrder.push(`1. Read ${first} first to locate target features or files.`);
|
|
@@ -6846,6 +7300,22 @@ function generateProjectTree(filePaths) {
|
|
|
6846
7300
|
const fence = fenceForText(lines.join("\n"), 3);
|
|
6847
7301
|
return ["# Project Tree", "", `${fence}text`, ...lines, fence, ""].join("\n");
|
|
6848
7302
|
}
|
|
7303
|
+
function treeTruncationWarnings(treeText) {
|
|
7304
|
+
const warnings = [];
|
|
7305
|
+
const depth = /\[tree truncated at (\d+) levels\]/.exec(treeText);
|
|
7306
|
+
if (depth) {
|
|
7307
|
+
warnings.push(
|
|
7308
|
+
`reports/project-tree.md was truncated at the ${depth[1]}-level depth cap: deeper directories are not listed there.`
|
|
7309
|
+
);
|
|
7310
|
+
}
|
|
7311
|
+
const lines = /\[tree truncated at (\d+) lines\]/.exec(treeText);
|
|
7312
|
+
if (lines) {
|
|
7313
|
+
warnings.push(
|
|
7314
|
+
`reports/project-tree.md was truncated at the ${lines[1]}-line cap: the rest of the tree is not listed there.`
|
|
7315
|
+
);
|
|
7316
|
+
}
|
|
7317
|
+
return warnings;
|
|
7318
|
+
}
|
|
6849
7319
|
function gitPaths(cwd, args) {
|
|
6850
7320
|
let output;
|
|
6851
7321
|
try {
|
|
@@ -7010,8 +7480,8 @@ function tsconfigPathsFor(cwd) {
|
|
|
7010
7480
|
return value;
|
|
7011
7481
|
}
|
|
7012
7482
|
function repositoryRelative(cwd, target) {
|
|
7013
|
-
const
|
|
7014
|
-
return
|
|
7483
|
+
const relative11 = path16__namespace.relative(cwd, target).replace(/\\/g, "/");
|
|
7484
|
+
return relative11.length === 0 || !relative11.startsWith("..") && !path16__namespace.isAbsolute(relative11) ? relative11 : null;
|
|
7015
7485
|
}
|
|
7016
7486
|
function rememberFirst(map, key, value) {
|
|
7017
7487
|
if (!map.has(key)) map.set(key, value);
|
|
@@ -7281,6 +7751,16 @@ function wouldNowBeIncluded(cwd, relativePath) {
|
|
|
7281
7751
|
return false;
|
|
7282
7752
|
}
|
|
7283
7753
|
}
|
|
7754
|
+
var TRUNCATION_REASONS = /* @__PURE__ */ new Set([
|
|
7755
|
+
"large-file-budget",
|
|
7756
|
+
"part-budget",
|
|
7757
|
+
"section-metadata"
|
|
7758
|
+
]);
|
|
7759
|
+
function isConfinedRelative(value) {
|
|
7760
|
+
if (value.length === 0 || value.includes("\0") || value.includes("\\")) return false;
|
|
7761
|
+
if (path16__namespace.isAbsolute(value)) return false;
|
|
7762
|
+
return !value.split("/").includes("..");
|
|
7763
|
+
}
|
|
7284
7764
|
function describeManifestShapeProblem(value) {
|
|
7285
7765
|
if (!value || typeof value !== "object" || Array.isArray(value)) return "not a JSON object";
|
|
7286
7766
|
const candidate = value;
|
|
@@ -7346,6 +7826,68 @@ function describeManifestShapeProblem(value) {
|
|
|
7346
7826
|
if (!candidate.kinds || typeof candidate.kinds !== "object" || Array.isArray(candidate.kinds)) {
|
|
7347
7827
|
return 'missing "kinds" object';
|
|
7348
7828
|
}
|
|
7829
|
+
const incompleteCount = counts.incompleteCount;
|
|
7830
|
+
if (typeof incompleteCount !== "number" || !Number.isSafeInteger(incompleteCount) || incompleteCount < 0) {
|
|
7831
|
+
return "missing numeric `counts.incompleteCount`";
|
|
7832
|
+
}
|
|
7833
|
+
const incomplete = candidate.incomplete;
|
|
7834
|
+
if (!Array.isArray(incomplete)) return 'missing "incomplete" array';
|
|
7835
|
+
if (incompleteCount !== incomplete.length) {
|
|
7836
|
+
return "`counts.incompleteCount` does not match the length of `incomplete`";
|
|
7837
|
+
}
|
|
7838
|
+
for (const entry of incomplete) {
|
|
7839
|
+
if (!entry || typeof entry !== "object" || Array.isArray(entry)) {
|
|
7840
|
+
return 'an "incomplete" entry is not an object';
|
|
7841
|
+
}
|
|
7842
|
+
const fields = entry;
|
|
7843
|
+
const relativePath = fields.relativePath;
|
|
7844
|
+
if (typeof relativePath !== "string" || relativePath.length === 0) {
|
|
7845
|
+
return 'an "incomplete" entry has no "relativePath"';
|
|
7846
|
+
}
|
|
7847
|
+
if (!isConfinedRelative(relativePath)) {
|
|
7848
|
+
return 'an "incomplete" entry "relativePath" must stay inside the repository';
|
|
7849
|
+
}
|
|
7850
|
+
if (typeof fields.part !== "string" || fields.part.trim() === "") {
|
|
7851
|
+
return 'an "incomplete" entry has no "part"';
|
|
7852
|
+
}
|
|
7853
|
+
if (typeof fields.reason !== "string" || !TRUNCATION_REASONS.has(fields.reason)) {
|
|
7854
|
+
return 'an "incomplete" entry has an unknown "reason"';
|
|
7855
|
+
}
|
|
7856
|
+
for (const key of ["omittedLines", "includedLines", "lines"]) {
|
|
7857
|
+
const value2 = fields[key];
|
|
7858
|
+
if (typeof value2 !== "number" || !Number.isSafeInteger(value2) || value2 < 0) {
|
|
7859
|
+
return `an "incomplete" entry "${key}" must be a non-negative integer`;
|
|
7860
|
+
}
|
|
7861
|
+
}
|
|
7862
|
+
const lines = fields.lines;
|
|
7863
|
+
if (fields.includedLines > lines) {
|
|
7864
|
+
return 'an "incomplete" entry "includedLines" exceeds its "lines"';
|
|
7865
|
+
}
|
|
7866
|
+
const ranges = fields.omittedRanges;
|
|
7867
|
+
if (!Array.isArray(ranges)) return 'an "incomplete" entry has no "omittedRanges" array';
|
|
7868
|
+
let previousEnd = 0;
|
|
7869
|
+
let omitted = 0;
|
|
7870
|
+
for (const range of ranges) {
|
|
7871
|
+
if (!Array.isArray(range) || range.length !== 2) {
|
|
7872
|
+
return 'an "incomplete" entry "omittedRanges" must hold [from, to] pairs';
|
|
7873
|
+
}
|
|
7874
|
+
const [from, to] = range;
|
|
7875
|
+
if (typeof from !== "number" || typeof to !== "number" || !Number.isSafeInteger(from) || !Number.isSafeInteger(to)) {
|
|
7876
|
+
return 'an "incomplete" entry "omittedRanges" must hold integer pairs';
|
|
7877
|
+
}
|
|
7878
|
+
if (from < 1 || to < from || to > lines) {
|
|
7879
|
+
return `an "incomplete" entry records an omitted range ${from}-${to}, outside 1-${lines}`;
|
|
7880
|
+
}
|
|
7881
|
+
if (from <= previousEnd) {
|
|
7882
|
+
return 'an "incomplete" entry "omittedRanges" must be sorted and non-overlapping';
|
|
7883
|
+
}
|
|
7884
|
+
previousEnd = to;
|
|
7885
|
+
omitted += to - from + 1;
|
|
7886
|
+
}
|
|
7887
|
+
if (omitted !== fields.omittedLines) {
|
|
7888
|
+
return "`omittedLines` does not match the ranges it records";
|
|
7889
|
+
}
|
|
7890
|
+
}
|
|
7349
7891
|
}
|
|
7350
7892
|
if (!Array.isArray(candidate.files)) return 'missing "files" array';
|
|
7351
7893
|
for (const entry of candidate.files) {
|
|
@@ -7459,11 +8001,57 @@ function validateSnapshot(configInput) {
|
|
|
7459
8001
|
);
|
|
7460
8002
|
}
|
|
7461
8003
|
const manifestFileMap = /* @__PURE__ */ new Map();
|
|
8004
|
+
const manifestFilesByPath = /* @__PURE__ */ new Map();
|
|
7462
8005
|
for (const file of manifest.files) {
|
|
7463
8006
|
if (file && typeof file.relativePath === "string") {
|
|
7464
8007
|
manifestFileMap.set(file.relativePath, file.hashSha256);
|
|
8008
|
+
manifestFilesByPath.set(file.relativePath, file);
|
|
8009
|
+
}
|
|
8010
|
+
}
|
|
8011
|
+
const incompleteRecords = manifest.incomplete ?? [];
|
|
8012
|
+
const incompleteness = /* @__PURE__ */ new Map();
|
|
8013
|
+
for (const record of incompleteRecords) {
|
|
8014
|
+
incompleteness.set(record.relativePath, record);
|
|
8015
|
+
const label = maskedPath(record.relativePath, config.secretRules);
|
|
8016
|
+
const file = manifestFilesByPath.get(record.relativePath);
|
|
8017
|
+
if (file === void 0) {
|
|
8018
|
+
drift.partIssues.push({
|
|
8019
|
+
part: "(manifest)",
|
|
8020
|
+
issue: `${label} is in incomplete[] but not in files[]`
|
|
8021
|
+
});
|
|
8022
|
+
continue;
|
|
8023
|
+
}
|
|
8024
|
+
if (file.part !== record.part) {
|
|
8025
|
+
drift.partIssues.push({
|
|
8026
|
+
part: "(manifest)",
|
|
8027
|
+
issue: `${label} is recorded in part ${String(record.part)} in incomplete[] and part ${String(file.part)} in files[]`
|
|
8028
|
+
});
|
|
8029
|
+
}
|
|
8030
|
+
if (file.truncationReason !== record.reason) {
|
|
8031
|
+
drift.partIssues.push({
|
|
8032
|
+
part: "(manifest)",
|
|
8033
|
+
issue: `${label} records truncationReason ${String(file.truncationReason)} in files[] and reason ${String(record.reason)} in incomplete[]`
|
|
8034
|
+
});
|
|
8035
|
+
}
|
|
8036
|
+
const recordedRanges = file.omittedRanges ?? [];
|
|
8037
|
+
const rangesAgree = recordedRanges.length === record.omittedRanges.length && recordedRanges.every(
|
|
8038
|
+
([from, to], index) => record.omittedRanges[index][0] === from && record.omittedRanges[index][1] === to
|
|
8039
|
+
);
|
|
8040
|
+
if (!rangesAgree || file.includedLines !== record.includedLines || file.lines !== record.lines) {
|
|
8041
|
+
drift.partIssues.push({
|
|
8042
|
+
part: "(manifest)",
|
|
8043
|
+
issue: `${label} records different omission numbers in files[] and incomplete[]`
|
|
8044
|
+
});
|
|
7465
8045
|
}
|
|
7466
8046
|
}
|
|
8047
|
+
for (const file of manifest.files) {
|
|
8048
|
+
if (file.truncationReason === void 0) continue;
|
|
8049
|
+
if (incompleteness.has(file.relativePath)) continue;
|
|
8050
|
+
drift.partIssues.push({
|
|
8051
|
+
part: "(manifest)",
|
|
8052
|
+
issue: `${maskedPath(file.relativePath, config.secretRules)} records a truncationReason but is missing from incomplete[]`
|
|
8053
|
+
});
|
|
8054
|
+
}
|
|
7467
8055
|
const skippedReasons = /* @__PURE__ */ new Map();
|
|
7468
8056
|
for (const entry of manifest.skipped) {
|
|
7469
8057
|
if (entry && typeof entry.path === "string" && typeof entry.reason === "string") {
|
|
@@ -7520,7 +8108,7 @@ function validateSnapshot(configInput) {
|
|
|
7520
8108
|
// snapshot was reported as drifting.
|
|
7521
8109
|
toolOwnedPaths: [config.outDir, config.tmpDir].map(
|
|
7522
8110
|
(directory) => path16__namespace.relative(config.cwd, path16__namespace.resolve(config.cwd, directory)).replace(/\\/g, "/")
|
|
7523
|
-
).filter((
|
|
8111
|
+
).filter((relative11) => relative11.length > 0 && !relative11.startsWith(".."))
|
|
7524
8112
|
});
|
|
7525
8113
|
for (const diskFile of collection.files) {
|
|
7526
8114
|
const snapshotHash = manifestFileMap.get(diskFile);
|
|
@@ -7921,7 +8509,8 @@ function validateSnapshot(configInput) {
|
|
|
7921
8509
|
);
|
|
7922
8510
|
}
|
|
7923
8511
|
}
|
|
7924
|
-
|
|
8512
|
+
const ceilingDerivedByMaxParts = (manifest.config?.maxParts ?? null) !== null;
|
|
8513
|
+
if (!ceilingDerivedByMaxParts && manifest.budgets && manifest.budgets.maxPartBytes !== config.maxPartBytes) {
|
|
7925
8514
|
totalsMismatches.push(
|
|
7926
8515
|
`budgets.maxPartBytes: manifest ${manifest.budgets.maxPartBytes} vs current ${config.maxPartBytes}`
|
|
7927
8516
|
);
|
|
@@ -7950,6 +8539,7 @@ function validateSnapshot(configInput) {
|
|
|
7950
8539
|
}
|
|
7951
8540
|
const declaredArtifacts = [
|
|
7952
8541
|
["README.md", manifest.artifacts?.readme],
|
|
8542
|
+
["PROMPT.md", manifest.artifacts?.prompt],
|
|
7953
8543
|
["reports/navigation.md", manifest.artifacts?.navigation],
|
|
7954
8544
|
["reports/project-tree.md", manifest.artifacts?.projectTree],
|
|
7955
8545
|
["reports/audit.md", manifest.artifacts?.audit],
|
|
@@ -7976,8 +8566,8 @@ function validateSnapshot(configInput) {
|
|
|
7976
8566
|
const target = match[1].split("#")[0];
|
|
7977
8567
|
if (target.length === 0 || /^[a-z][a-z0-9+.-]*:/i.test(target)) continue;
|
|
7978
8568
|
const resolved = path16__namespace.resolve(snapshotDir, "reports", target);
|
|
7979
|
-
const
|
|
7980
|
-
if (
|
|
8569
|
+
const relative11 = path16__namespace.relative(snapshotDir, resolved);
|
|
8570
|
+
if (relative11.startsWith("..") || path16__namespace.isAbsolute(relative11) || !fs15__namespace.existsSync(resolved)) {
|
|
7981
8571
|
drift.partIssues.push({
|
|
7982
8572
|
part: key,
|
|
7983
8573
|
issue: `links to ${maskedPath(target, config.secretRules)}, which does not exist in the snapshot`
|
|
@@ -8172,14 +8762,14 @@ function writeCache(file, entry) {
|
|
|
8172
8762
|
}
|
|
8173
8763
|
}
|
|
8174
8764
|
function fetchLatestVersion(url = PACKAGE_LATEST_URL, timeoutMs = REQUEST_TIMEOUT_MS) {
|
|
8175
|
-
return new Promise((
|
|
8765
|
+
return new Promise((resolve8) => {
|
|
8176
8766
|
let settled = false;
|
|
8177
8767
|
let request = null;
|
|
8178
8768
|
const finish = (value) => {
|
|
8179
8769
|
if (settled) return;
|
|
8180
8770
|
settled = true;
|
|
8181
8771
|
clearTimeout(deadline);
|
|
8182
|
-
|
|
8772
|
+
resolve8(value);
|
|
8183
8773
|
};
|
|
8184
8774
|
const deadline = setTimeout(() => {
|
|
8185
8775
|
request?.destroy();
|
|
@@ -8267,23 +8857,23 @@ function describeMatcher(matcher) {
|
|
|
8267
8857
|
function normalizeTarget(cwd, target) {
|
|
8268
8858
|
const resolvedCwd = path16__namespace.resolve(cwd);
|
|
8269
8859
|
const absolute = path16__namespace.resolve(resolvedCwd, target);
|
|
8270
|
-
const
|
|
8271
|
-
if (
|
|
8860
|
+
const relative11 = path16__namespace.relative(resolvedCwd, absolute);
|
|
8861
|
+
if (relative11 === "" || relative11 === ".." || relative11.startsWith(`..${path16__namespace.sep}`) || path16__namespace.isAbsolute(relative11)) {
|
|
8272
8862
|
return { relative: target.replace(/\\/g, "/"), outsideRoot: true };
|
|
8273
8863
|
}
|
|
8274
|
-
return { relative:
|
|
8864
|
+
return { relative: relative11.split(path16__namespace.sep).join("/"), outsideRoot: false };
|
|
8275
8865
|
}
|
|
8276
8866
|
function findRuleMatch(rules, relativePath) {
|
|
8277
8867
|
return rules.find(
|
|
8278
8868
|
(rule) => matchRule(relativePath, rule.match)
|
|
8279
8869
|
);
|
|
8280
8870
|
}
|
|
8281
|
-
function findRecordedAncestor(skipped,
|
|
8871
|
+
function findRecordedAncestor(skipped, relative11, maskedPath2) {
|
|
8282
8872
|
let nearest;
|
|
8283
8873
|
for (const record of skipped) {
|
|
8284
8874
|
const ancestorPath = record.path;
|
|
8285
8875
|
if (ancestorPath.length === 0) continue;
|
|
8286
|
-
const isAncestor =
|
|
8876
|
+
const isAncestor = relative11.startsWith(`${ancestorPath}/`) || maskedPath2.startsWith(`${ancestorPath}/`);
|
|
8287
8877
|
if (!isAncestor) continue;
|
|
8288
8878
|
if (!nearest || ancestorPath.length > nearest.path.length) nearest = record;
|
|
8289
8879
|
}
|
|
@@ -8299,8 +8889,8 @@ function readManifest2(config) {
|
|
|
8299
8889
|
}
|
|
8300
8890
|
function explainPath(config, target) {
|
|
8301
8891
|
const normalized = normalizeTarget(config.cwd, target);
|
|
8302
|
-
const
|
|
8303
|
-
const maskedPath2 = findSecretInPath(
|
|
8892
|
+
const relative11 = normalized.relative;
|
|
8893
|
+
const maskedPath2 = findSecretInPath(relative11, config.secretRules)?.masked ?? relative11;
|
|
8304
8894
|
if (normalized.outsideRoot) {
|
|
8305
8895
|
return {
|
|
8306
8896
|
path: maskedPath2,
|
|
@@ -8310,7 +8900,7 @@ function explainPath(config, target) {
|
|
|
8310
8900
|
detail: "path resolves outside the configured repository root and was not inspected"
|
|
8311
8901
|
};
|
|
8312
8902
|
}
|
|
8313
|
-
const absolute = path16__namespace.join(config.cwd,
|
|
8903
|
+
const absolute = path16__namespace.join(config.cwd, relative11);
|
|
8314
8904
|
const result = {
|
|
8315
8905
|
path: maskedPath2,
|
|
8316
8906
|
exists: fs15__namespace.existsSync(absolute),
|
|
@@ -8328,11 +8918,11 @@ function explainPath(config, target) {
|
|
|
8328
8918
|
// that is only missing because the walker dropped the tool's own output directory.
|
|
8329
8919
|
toolOwnedPaths: [config.outDir, config.tmpDir].map(
|
|
8330
8920
|
(directory) => path16__namespace.relative(config.cwd, path16__namespace.resolve(config.cwd, directory)).replace(/\\/g, "/")
|
|
8331
|
-
).filter((
|
|
8921
|
+
).filter((relative12) => relative12.length > 0 && !relative12.startsWith(".."))
|
|
8332
8922
|
});
|
|
8333
|
-
if (!collection.files.includes(
|
|
8923
|
+
if (!collection.files.includes(relative11)) {
|
|
8334
8924
|
const record = collection.skipped.find(
|
|
8335
|
-
(entry2) => entry2.path ===
|
|
8925
|
+
(entry2) => entry2.path === relative11 || entry2.path === maskedPath2
|
|
8336
8926
|
);
|
|
8337
8927
|
if (record) {
|
|
8338
8928
|
result.reason = record.reason;
|
|
@@ -8341,7 +8931,7 @@ function explainPath(config, target) {
|
|
|
8341
8931
|
result.reason = "missing";
|
|
8342
8932
|
result.detail = "no such file or directory, relative to the configured cwd";
|
|
8343
8933
|
} else {
|
|
8344
|
-
const ancestor = findRecordedAncestor(collection.skipped,
|
|
8934
|
+
const ancestor = findRecordedAncestor(collection.skipped, relative11, maskedPath2);
|
|
8345
8935
|
if (ancestor) {
|
|
8346
8936
|
result.reason = ancestor.reason;
|
|
8347
8937
|
result.detail = ancestor.detail ? `${ancestor.detail} \u2014 inherited from the skipped directory \`${ancestor.path}\`` : `inside the skipped directory \`${ancestor.path}\``;
|
|
@@ -8361,11 +8951,11 @@ function explainPath(config, target) {
|
|
|
8361
8951
|
...config.changedSince === void 0 ? {} : { changedSince: config.changedSince },
|
|
8362
8952
|
...config.staged === true ? { staged: true } : {}
|
|
8363
8953
|
});
|
|
8364
|
-
inScope = scope.paths.has(
|
|
8954
|
+
inScope = scope.paths.has(relative11);
|
|
8365
8955
|
if (!inScope && config.withDependents === true) {
|
|
8366
8956
|
inScope = importsChangedFile(
|
|
8367
|
-
|
|
8368
|
-
importsOfFile(
|
|
8957
|
+
relative11,
|
|
8958
|
+
importsOfFile(relative11, absolute),
|
|
8369
8959
|
scope.paths,
|
|
8370
8960
|
buildImportResolver(collection.files.map((file) => ({ relativePath: file })))
|
|
8371
8961
|
);
|
|
@@ -8423,12 +9013,12 @@ function explainPath(config, target) {
|
|
|
8423
9013
|
result.bytes = buffer.length;
|
|
8424
9014
|
result.lines = countLines(text2);
|
|
8425
9015
|
if (decoded.encoding !== "utf-8") result.encoding = decoded.encoding;
|
|
8426
|
-
const { findings } = scanAndRedactSecrets(text2, config.secretRules,
|
|
9016
|
+
const { findings } = scanAndRedactSecrets(text2, config.secretRules, relative11);
|
|
8427
9017
|
result.secretCount = findings.length;
|
|
8428
9018
|
result.secrets = findings.slice(0, 20).map((finding) => ({ rules: finding.rules, line: finding.line }));
|
|
8429
9019
|
let inclusionMode = "full";
|
|
8430
|
-
if (config.skeleton === true && isSkeletonizable(
|
|
8431
|
-
const skeleton = skeletonizeTypeScript(text2,
|
|
9020
|
+
if (config.skeleton === true && isSkeletonizable(relative11)) {
|
|
9021
|
+
const skeleton = skeletonizeTypeScript(text2, relative11);
|
|
8432
9022
|
if (skeleton.collapsed > 0) inclusionMode = "signatures";
|
|
8433
9023
|
}
|
|
8434
9024
|
if (inclusionMode !== "signatures" && buffer.length > config.largeFileBytes) {
|
|
@@ -8437,15 +9027,15 @@ function explainPath(config, target) {
|
|
|
8437
9027
|
}
|
|
8438
9028
|
result.inclusionMode = inclusionMode;
|
|
8439
9029
|
}
|
|
8440
|
-
result.layer = classifyLayer(
|
|
8441
|
-
result.kind = classifyKind(
|
|
8442
|
-
result.language = detectLanguage(
|
|
8443
|
-
const layerRule = findRuleMatch(config.layers,
|
|
9030
|
+
result.layer = classifyLayer(relative11, config.layers);
|
|
9031
|
+
result.kind = classifyKind(relative11, config.kinds);
|
|
9032
|
+
result.language = detectLanguage(relative11);
|
|
9033
|
+
const layerRule = findRuleMatch(config.layers, relative11);
|
|
8444
9034
|
if (layerRule) result.layerMatch = describeMatcher(layerRule.match);
|
|
8445
|
-
const kindRule = findRuleMatch(config.kinds,
|
|
9035
|
+
const kindRule = findRuleMatch(config.kinds, relative11);
|
|
8446
9036
|
if (kindRule) result.kindMatch = describeMatcher(kindRule.match);
|
|
8447
9037
|
const manifest = readManifest2(config);
|
|
8448
|
-
const entry = Array.isArray(manifest?.files) ? manifest.files.find((file) => file.relativePath ===
|
|
9038
|
+
const entry = Array.isArray(manifest?.files) ? manifest.files.find((file) => file.relativePath === relative11) : void 0;
|
|
8449
9039
|
result.part = entry?.part ?? null;
|
|
8450
9040
|
return result;
|
|
8451
9041
|
}
|
|
@@ -8494,19 +9084,19 @@ function side(manifest) {
|
|
|
8494
9084
|
function shortDigest(value) {
|
|
8495
9085
|
return value === null ? "not recorded" : `${value.slice(0, 12)}\u2026`;
|
|
8496
9086
|
}
|
|
8497
|
-
function describeLayerChanges(before, after) {
|
|
9087
|
+
function describeLayerChanges(before, after, secretRules) {
|
|
8498
9088
|
const names = Array.from(/* @__PURE__ */ new Set([...Object.keys(before), ...Object.keys(after)])).sort();
|
|
8499
9089
|
const changes = [];
|
|
8500
9090
|
for (const name of names) {
|
|
8501
9091
|
const was = before[name] ?? 0;
|
|
8502
9092
|
const now = after[name] ?? 0;
|
|
8503
9093
|
if (was === now) continue;
|
|
8504
|
-
const label = findSecretInPath(name)?.masked ?? name;
|
|
9094
|
+
const label = findSecretInPath(name, secretRules)?.masked ?? name;
|
|
8505
9095
|
changes.push(`layer "${label}": ${was} file(s) \u2192 ${now} file(s)`);
|
|
8506
9096
|
}
|
|
8507
9097
|
return changes;
|
|
8508
9098
|
}
|
|
8509
|
-
function describePartChanges(before, after) {
|
|
9099
|
+
function describePartChanges(before, after, secretRules) {
|
|
8510
9100
|
const index = (parts) => {
|
|
8511
9101
|
const map = /* @__PURE__ */ new Map();
|
|
8512
9102
|
for (const part of parts) {
|
|
@@ -8516,7 +9106,7 @@ function describePartChanges(before, after) {
|
|
|
8516
9106
|
};
|
|
8517
9107
|
const left = index(before);
|
|
8518
9108
|
const right = index(after);
|
|
8519
|
-
const label = (filename) => findSecretInPath(filename)?.masked ?? filename;
|
|
9109
|
+
const label = (filename) => findSecretInPath(filename, secretRules)?.masked ?? filename;
|
|
8520
9110
|
const changes = [];
|
|
8521
9111
|
for (const [filename, part] of right) {
|
|
8522
9112
|
const previous = left.get(filename);
|
|
@@ -8544,7 +9134,15 @@ function describePartChanges(before, after) {
|
|
|
8544
9134
|
}
|
|
8545
9135
|
return changes;
|
|
8546
9136
|
}
|
|
8547
|
-
function
|
|
9137
|
+
function maskLayerNames(layers, secretRules) {
|
|
9138
|
+
return Object.fromEntries(
|
|
9139
|
+
Object.entries(layers ?? {}).map(([name, count]) => [
|
|
9140
|
+
findSecretInPath(name, secretRules)?.masked ?? name,
|
|
9141
|
+
count
|
|
9142
|
+
])
|
|
9143
|
+
);
|
|
9144
|
+
}
|
|
9145
|
+
function describePayloadDiff(before, after, sourceFilesIdentical, secretRules) {
|
|
8548
9146
|
const generatorBefore = before.generator?.version ?? "unknown";
|
|
8549
9147
|
const generatorAfter = after.generator?.version ?? "unknown";
|
|
8550
9148
|
const digestBefore = typeof before.config?.digest === "string" ? before.config.digest : null;
|
|
@@ -8557,35 +9155,43 @@ function describePayloadDiff(before, after, sourceFilesIdentical) {
|
|
|
8557
9155
|
const configurationDiffers = generatorDiffers || digestDiffers || schemaDiffers;
|
|
8558
9156
|
const fingerprintDiffers = before.fingerprint !== after.fingerprint;
|
|
8559
9157
|
const partsDiffer = before.counts.partsCount !== after.counts.partsCount;
|
|
8560
|
-
const partChanges = describePartChanges(before.parts ?? [], after.parts ?? []);
|
|
8561
|
-
const layerChanges = describeLayerChanges(before.layers ?? {}, after.layers ?? {});
|
|
9158
|
+
const partChanges = describePartChanges(before.parts ?? [], after.parts ?? [], secretRules);
|
|
9159
|
+
const layerChanges = describeLayerChanges(before.layers ?? {}, after.layers ?? {}, secretRules);
|
|
8562
9160
|
const reasons = [];
|
|
9161
|
+
const codes = [];
|
|
8563
9162
|
if (schemaDiffers) {
|
|
9163
|
+
codes.push("schema-version");
|
|
8564
9164
|
reasons.push(
|
|
8565
9165
|
`schema version ${schemaBefore} \u2192 ${schemaAfter} (the two manifests describe different formats)`
|
|
8566
9166
|
);
|
|
8567
9167
|
}
|
|
8568
9168
|
if (digestDiffers) {
|
|
9169
|
+
codes.push("config-digest");
|
|
8569
9170
|
reasons.push(
|
|
8570
9171
|
`configuration digest ${shortDigest(digestBefore)} \u2192 ${shortDigest(digestAfter)} (budgets, preview thresholds, redaction rules and artifact selection all count)`
|
|
8571
9172
|
);
|
|
8572
9173
|
} else if (digestBefore === null || digestAfter === null) {
|
|
8573
9174
|
const missing = digestBefore === null && digestAfter !== null ? "before" : digestAfter === null && digestBefore !== null ? "after" : "both";
|
|
9175
|
+
codes.push("config-digest-missing");
|
|
8574
9176
|
reasons.push(
|
|
8575
9177
|
`configuration digest not recorded on the ${missing} side (manifest written before 4.0.5); compared the content fingerprint and part count instead`
|
|
8576
9178
|
);
|
|
8577
9179
|
}
|
|
8578
9180
|
if (generatorDiffers) {
|
|
9181
|
+
codes.push("generator");
|
|
8579
9182
|
reasons.push(`generator ${generatorBefore} \u2192 ${generatorAfter}`);
|
|
8580
9183
|
}
|
|
8581
9184
|
if (fingerprintDiffers && (sourceFilesIdentical || configurationDiffers)) {
|
|
9185
|
+
codes.push("fingerprint");
|
|
8582
9186
|
reasons.push(
|
|
8583
9187
|
`content fingerprint ${shortDigest(before.fingerprint)} \u2192 ${shortDigest(after.fingerprint)}` + (sourceFilesIdentical ? " (same source files, packed or configured differently)" : "")
|
|
8584
9188
|
);
|
|
8585
9189
|
}
|
|
8586
9190
|
if (partsDiffer) {
|
|
9191
|
+
codes.push("parts-count");
|
|
8587
9192
|
reasons.push(`${before.counts.partsCount} part(s) \u2192 ${after.counts.partsCount} part(s)`);
|
|
8588
9193
|
}
|
|
9194
|
+
for (let index = 0; index < layerChanges.length; index += 1) codes.push("layer-changed");
|
|
8589
9195
|
reasons.push(...layerChanges);
|
|
8590
9196
|
return {
|
|
8591
9197
|
sourceFilesIdentical,
|
|
@@ -8597,8 +9203,12 @@ function describePayloadDiff(before, after, sourceFilesIdentical) {
|
|
|
8597
9203
|
partsCount: { before: before.counts.partsCount, after: after.counts.partsCount },
|
|
8598
9204
|
schemaVersion: { before: schemaBefore, after: schemaAfter },
|
|
8599
9205
|
partsManifest: { differs: partChanges.length > 0, changes: partChanges },
|
|
8600
|
-
|
|
8601
|
-
|
|
9206
|
+
// The layer maps are printed and serialized, so a layer named after a project token leaks the
|
|
9207
|
+
// token here even though every reason line above is masked. Found while testing the rules
|
|
9208
|
+
// parameter: masking the prose and not the data it describes is the same bug one layer down.
|
|
9209
|
+
layers: { before: maskLayerNames(before.layers, secretRules), after: maskLayerNames(after.layers, secretRules) },
|
|
9210
|
+
reasons,
|
|
9211
|
+
codes
|
|
8602
9212
|
};
|
|
8603
9213
|
}
|
|
8604
9214
|
function hashMap(manifest) {
|
|
@@ -8637,10 +9247,10 @@ function comparableProblem(value) {
|
|
|
8637
9247
|
function assertUsableManifest(value, label) {
|
|
8638
9248
|
const problem = comparableProblem(value);
|
|
8639
9249
|
if (problem) {
|
|
8640
|
-
throw new Error(`The ${label} manifest is not a snapshot manifest
|
|
9250
|
+
throw new Error(`The ${label} manifest is not a snapshot manifest: ${problem}.`);
|
|
8641
9251
|
}
|
|
8642
9252
|
}
|
|
8643
|
-
function compareManifests(before, after) {
|
|
9253
|
+
function compareManifests(before, after, secretRules) {
|
|
8644
9254
|
assertUsableManifest(before, "before");
|
|
8645
9255
|
assertUsableManifest(after, "after");
|
|
8646
9256
|
const left = hashMap(before);
|
|
@@ -8660,8 +9270,8 @@ function compareManifests(before, after) {
|
|
|
8660
9270
|
}
|
|
8661
9271
|
const sort = (values) => values.sort((a, b) => a < b ? -1 : a > b ? 1 : 0);
|
|
8662
9272
|
const sourceFilesIdentical = added.length === 0 && removed.length === 0 && changed.length === 0;
|
|
8663
|
-
const payload = describePayloadDiff(before, after, sourceFilesIdentical);
|
|
8664
|
-
const mask = (values) => values.map((value) => findSecretInPath(value)?.masked ?? value);
|
|
9273
|
+
const payload = describePayloadDiff(before, after, sourceFilesIdentical, secretRules);
|
|
9274
|
+
const mask = (values) => values.map((value) => findSecretInPath(value, secretRules)?.masked ?? value);
|
|
8665
9275
|
return {
|
|
8666
9276
|
before: side(before),
|
|
8667
9277
|
after: side(after),
|
|
@@ -8695,7 +9305,7 @@ function loadManifest(target) {
|
|
|
8695
9305
|
const problem = describeManifestShapeProblem(parsed);
|
|
8696
9306
|
if (problem) {
|
|
8697
9307
|
throw new Error(
|
|
8698
|
-
`${manifestPath} is not a
|
|
9308
|
+
`${manifestPath} is not a snapshot manifest: ${problem}. Point diff at a manifest.json written by \`generate\` (or at the directory that holds it).`
|
|
8699
9309
|
);
|
|
8700
9310
|
}
|
|
8701
9311
|
return parsed;
|
|
@@ -8842,6 +9452,7 @@ var DEFAULT_ANSWERS = {
|
|
|
8842
9452
|
excludePatterns: [],
|
|
8843
9453
|
artifacts: {
|
|
8844
9454
|
readme: true,
|
|
9455
|
+
prompt: true,
|
|
8845
9456
|
manifest: true,
|
|
8846
9457
|
parts: true,
|
|
8847
9458
|
navigation: true,
|
|
@@ -8950,10 +9561,15 @@ function renderConfig(answers) {
|
|
|
8950
9561
|
// Set true to drop the built-in rules above and keep only customPatterns.
|
|
8951
9562
|
disableDefaultPatterns: false,
|
|
8952
9563
|
},
|
|
9564
|
+
// The library spelling of the same list, accepted here too so a config file can
|
|
9565
|
+
// express what a caller passes in code: an array of { rule, pattern } or a bare
|
|
9566
|
+
// RegExp. Use \`secrets.customPatterns\` above unless you are porting code.
|
|
9567
|
+
// secretRules: [],
|
|
8953
9568
|
|
|
8954
9569
|
// \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
|
|
8955
9570
|
artifacts: {
|
|
8956
9571
|
readme: ${artifacts.readme}, // README.md
|
|
9572
|
+
prompt: ${artifacts.prompt}, // PROMPT.md \u2014 the instruction sheet a model is given
|
|
8957
9573
|
manifest: ${artifacts.manifest}, // manifest.json \u2014 required by validate and report
|
|
8958
9574
|
parts: ${artifacts.parts}, // parts/part-XXX.md
|
|
8959
9575
|
navigation: ${artifacts.navigation}, // reports/navigation.md
|
|
@@ -8969,6 +9585,11 @@ function renderConfig(answers) {
|
|
|
8969
9585
|
includeMonolith: ${artifacts.monolith},
|
|
8970
9586
|
|
|
8971
9587
|
// \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
|
|
9588
|
+
// Files your destination accepts in one message, used by PROMPT.md to plan the delivery.
|
|
9589
|
+
// attachmentSlots: 10,
|
|
9590
|
+
// Experimental: grow the per-part budget until the snapshot fits this many parts, instead of
|
|
9591
|
+
// adding a part as the code grows. The plan in PROMPT.md becomes a fixed-length attachment list.
|
|
9592
|
+
// maxParts: 10,
|
|
8972
9593
|
// afterGenerate: (manifest) => { /* write your own artifact */ }
|
|
8973
9594
|
hooks: {},
|
|
8974
9595
|
};
|
|
@@ -9137,7 +9758,7 @@ function keyReader(input) {
|
|
|
9137
9758
|
next() {
|
|
9138
9759
|
const queued = queue.shift();
|
|
9139
9760
|
if (queued) return Promise.resolve(queued);
|
|
9140
|
-
return new Promise((
|
|
9761
|
+
return new Promise((resolve8) => waiters.push(resolve8));
|
|
9141
9762
|
},
|
|
9142
9763
|
close() {
|
|
9143
9764
|
input.off("keypress", onKey);
|
|
@@ -9566,7 +10187,18 @@ function updatePackageJson(cwd, notes) {
|
|
|
9566
10187
|
writeFileOrExplain(packagePath, serializePackageJson(raw, parsed));
|
|
9567
10188
|
return { scripts: added, dependency };
|
|
9568
10189
|
}
|
|
9569
|
-
|
|
10190
|
+
function gitignoreEntriesFor(cwd, outDir, tmpDir) {
|
|
10191
|
+
const entries = [];
|
|
10192
|
+
for (const directory of [outDir, tmpDir]) {
|
|
10193
|
+
if (directory === null) continue;
|
|
10194
|
+
const relative11 = path16__namespace.relative(cwd, path16__namespace.resolve(cwd, directory)).replace(/\\/g, "/");
|
|
10195
|
+
if (relative11 === "" || relative11 === "." || relative11.startsWith("..") || path16__namespace.isAbsolute(relative11)) {
|
|
10196
|
+
continue;
|
|
10197
|
+
}
|
|
10198
|
+
entries.push(`/${relative11}/`);
|
|
10199
|
+
}
|
|
10200
|
+
return [...new Set(entries)];
|
|
10201
|
+
}
|
|
9570
10202
|
function resolvePresetChoice(detectedName, presetName) {
|
|
9571
10203
|
return {
|
|
9572
10204
|
value: presetName,
|
|
@@ -9648,6 +10280,7 @@ async function runInit(options) {
|
|
|
9648
10280
|
let lastScope = "all";
|
|
9649
10281
|
const artifactChoices = [
|
|
9650
10282
|
{ value: "readme", label: "README.md", hint: "orientation page" },
|
|
10283
|
+
{ value: "prompt", label: "PROMPT.md", hint: "instruction sheet for the model" },
|
|
9651
10284
|
{ value: "manifest", label: "manifest.json", hint: "required by validate and report" },
|
|
9652
10285
|
{ value: "parts", label: "parts/", hint: "the code payload" },
|
|
9653
10286
|
{ value: "navigation", label: "reports/navigation.md", hint: "file \u2192 part index" },
|
|
@@ -9859,7 +10492,10 @@ async function runInit(options) {
|
|
|
9859
10492
|
}
|
|
9860
10493
|
if (!reused) writeFileOrExplain(configPath, configText);
|
|
9861
10494
|
const { scripts, dependency } = updatePackageJson(options.cwd, notes);
|
|
9862
|
-
const ignore = appendGitignoreEntries(
|
|
10495
|
+
const ignore = appendGitignoreEntries(
|
|
10496
|
+
options.cwd,
|
|
10497
|
+
gitignoreEntriesFor(options.cwd, answers.outDir, options.tmpDir ?? (reused ? null : "snapshot.tmp"))
|
|
10498
|
+
);
|
|
9863
10499
|
if (ignore.note !== null) notes.push(ignore.note);
|
|
9864
10500
|
return {
|
|
9865
10501
|
configPath,
|
|
@@ -9877,10 +10513,10 @@ async function runInit(options) {
|
|
|
9877
10513
|
};
|
|
9878
10514
|
}
|
|
9879
10515
|
function describeTarget(cwd) {
|
|
9880
|
-
const
|
|
9881
|
-
if (
|
|
9882
|
-
if (
|
|
9883
|
-
return
|
|
10516
|
+
const relative11 = path16__namespace.relative(process.cwd(), cwd);
|
|
10517
|
+
if (relative11 === "") return "this directory";
|
|
10518
|
+
if (relative11.startsWith("..") || path16__namespace.isAbsolute(relative11)) return cwd;
|
|
10519
|
+
return relative11;
|
|
9884
10520
|
}
|
|
9885
10521
|
function firstRunMessage(reason, cwd) {
|
|
9886
10522
|
const where = describeTarget(cwd);
|
|
@@ -9982,8 +10618,8 @@ function gitDirectory(cwd) {
|
|
|
9982
10618
|
}
|
|
9983
10619
|
}
|
|
9984
10620
|
function isInside2(parent, child) {
|
|
9985
|
-
const
|
|
9986
|
-
return
|
|
10621
|
+
const relative11 = path16__namespace.relative(parent, child);
|
|
10622
|
+
return relative11 === "" || !relative11.startsWith("..") && !path16__namespace.isAbsolute(relative11);
|
|
9987
10623
|
}
|
|
9988
10624
|
function isRegisteredWorktree(gitDir, cwd) {
|
|
9989
10625
|
try {
|
|
@@ -10246,16 +10882,29 @@ function retain(items, keep) {
|
|
|
10246
10882
|
}
|
|
10247
10883
|
items.length = write;
|
|
10248
10884
|
}
|
|
10249
|
-
function buildIndexes(files, tsconfigPaths) {
|
|
10885
|
+
function buildIndexes(files, tsconfigPaths, skippedSummaryImports = /* @__PURE__ */ new Map()) {
|
|
10250
10886
|
const resolver = buildImportResolver(files, { tsconfig: tsconfigPaths });
|
|
10251
10887
|
const importerCounts = /* @__PURE__ */ new Map();
|
|
10252
|
-
const byFile = files.
|
|
10253
|
-
|
|
10254
|
-
|
|
10255
|
-
|
|
10256
|
-
|
|
10257
|
-
|
|
10258
|
-
|
|
10888
|
+
const byFile = files.flatMap((file) => {
|
|
10889
|
+
if (isSourceSummary(file.summary)) {
|
|
10890
|
+
return [
|
|
10891
|
+
{
|
|
10892
|
+
path: file.relativePath,
|
|
10893
|
+
imports: file.summary.imports,
|
|
10894
|
+
exports: file.summary.exports
|
|
10895
|
+
}
|
|
10896
|
+
];
|
|
10897
|
+
}
|
|
10898
|
+
const imports = skippedSummaryImports.get(file.relativePath);
|
|
10899
|
+
if (imports === void 0) return [];
|
|
10900
|
+
return [
|
|
10901
|
+
{
|
|
10902
|
+
path: file.relativePath,
|
|
10903
|
+
imports,
|
|
10904
|
+
exports: [],
|
|
10905
|
+
exportsOmitted: true
|
|
10906
|
+
}
|
|
10907
|
+
];
|
|
10259
10908
|
});
|
|
10260
10909
|
for (const entry of byFile) {
|
|
10261
10910
|
for (const specifier of entry.imports) {
|
|
@@ -10375,6 +11024,9 @@ function resolveSafeOutputDirs(config) {
|
|
|
10375
11024
|
return { outDir, tmpDir };
|
|
10376
11025
|
}
|
|
10377
11026
|
var IGNORABLE_ENTRIES = /* @__PURE__ */ new Set([".DS_Store"]);
|
|
11027
|
+
function isIgnorableEntry(entry) {
|
|
11028
|
+
return IGNORABLE_ENTRIES.has(entry.slice(entry.lastIndexOf("/") + 1));
|
|
11029
|
+
}
|
|
10378
11030
|
var RUN_DIR_PREFIX = "run-";
|
|
10379
11031
|
var STALE_RUN_MS = 60 * 60 * 1e3;
|
|
10380
11032
|
function maskSummaryStrings(value, secretRules) {
|
|
@@ -10417,9 +11069,9 @@ function listEntries(dir) {
|
|
|
10417
11069
|
return;
|
|
10418
11070
|
}
|
|
10419
11071
|
for (const child of children) {
|
|
10420
|
-
const
|
|
10421
|
-
entries.push(
|
|
10422
|
-
if (child.isDirectory()) walk(path16__namespace.join(absolute, child.name),
|
|
11072
|
+
const relative11 = prefix === "" ? child.name : `${prefix}/${child.name}`;
|
|
11073
|
+
entries.push(relative11);
|
|
11074
|
+
if (child.isDirectory()) walk(path16__namespace.join(absolute, child.name), relative11);
|
|
10423
11075
|
}
|
|
10424
11076
|
};
|
|
10425
11077
|
walk(dir, "");
|
|
@@ -10430,7 +11082,7 @@ function markerInventory(dir, written) {
|
|
|
10430
11082
|
const files = [];
|
|
10431
11083
|
for (const entry of entries) {
|
|
10432
11084
|
if (entry === OWNERSHIP_MARKER) continue;
|
|
10433
|
-
if (
|
|
11085
|
+
if (isIgnorableEntry(entry)) continue;
|
|
10434
11086
|
const full = path16__namespace.join(dir, ...entry.split("/"));
|
|
10435
11087
|
let stats;
|
|
10436
11088
|
try {
|
|
@@ -10719,7 +11371,7 @@ function assessSnapshotDirectory(dir) {
|
|
|
10719
11371
|
}
|
|
10720
11372
|
const entries = listEntries(dir);
|
|
10721
11373
|
const foreignEntries = entries.filter(
|
|
10722
|
-
(entry) => !recorded.has(entry) && !
|
|
11374
|
+
(entry) => !recorded.has(entry) && !isIgnorableEntry(entry)
|
|
10723
11375
|
);
|
|
10724
11376
|
if (foreignEntries.length > 0) {
|
|
10725
11377
|
return { owned: false, problem: null, foreignEntries, marker: marker2 };
|
|
@@ -11175,7 +11827,55 @@ function runAfterGenerate(config, manifest) {
|
|
|
11175
11827
|
return Promise.resolve(returned).finally(releaseRedirect);
|
|
11176
11828
|
}
|
|
11177
11829
|
function partitionByBudget(files, config, fingerprint) {
|
|
11178
|
-
const
|
|
11830
|
+
const configured = {
|
|
11831
|
+
parts: partitionWithBudgets(files, config.budgets, fingerprint),
|
|
11832
|
+
budgets: config.budgets,
|
|
11833
|
+
maxPartBytes: config.maxPartBytes,
|
|
11834
|
+
warnings: []
|
|
11835
|
+
};
|
|
11836
|
+
const limit = config.maxParts;
|
|
11837
|
+
if (limit === null || !config.artifacts.parts || configured.parts.length <= limit) return configured;
|
|
11838
|
+
const totalBytes = files.reduce((total, file) => total + file.includedBytes, 0);
|
|
11839
|
+
let target = Math.max(config.budgets.default, Math.ceil(totalBytes * 1.15 / limit));
|
|
11840
|
+
const seen = [];
|
|
11841
|
+
let low = config.budgets.default;
|
|
11842
|
+
let fitting = null;
|
|
11843
|
+
for (let pass = 0; pass < 6; pass += 1) {
|
|
11844
|
+
const parts2 = partitionWithBudgets(files, scaleBudgets(config.budgets, target), fingerprint);
|
|
11845
|
+
if (parts2.length <= limit) {
|
|
11846
|
+
fitting = { target, parts: parts2 };
|
|
11847
|
+
break;
|
|
11848
|
+
}
|
|
11849
|
+
seen.push(parts2.length);
|
|
11850
|
+
low = target;
|
|
11851
|
+
target = Math.ceil(target * 1.3);
|
|
11852
|
+
}
|
|
11853
|
+
if (fitting === null) {
|
|
11854
|
+
throw new Error(
|
|
11855
|
+
`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.`
|
|
11856
|
+
);
|
|
11857
|
+
}
|
|
11858
|
+
for (let step = 0; step < 3 && fitting.target - low > 8192; step += 1) {
|
|
11859
|
+
const middle = Math.round((low + fitting.target) / 2);
|
|
11860
|
+
const parts2 = partitionWithBudgets(files, scaleBudgets(config.budgets, middle), fingerprint);
|
|
11861
|
+
if (parts2.length <= limit) fitting = { target: middle, parts: parts2 };
|
|
11862
|
+
else low = middle;
|
|
11863
|
+
}
|
|
11864
|
+
const { target: chosen, parts } = fitting;
|
|
11865
|
+
const budgets = scaleBudgets(config.budgets, chosen);
|
|
11866
|
+
const maxPartBytes = Math.max(config.maxPartBytes, chosen);
|
|
11867
|
+
const warnings = [
|
|
11868
|
+
`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).`
|
|
11869
|
+
];
|
|
11870
|
+
if (maxPartBytes > config.maxPartBytes) {
|
|
11871
|
+
warnings.push(
|
|
11872
|
+
`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.`
|
|
11873
|
+
);
|
|
11874
|
+
}
|
|
11875
|
+
return { parts, budgets, maxPartBytes, warnings };
|
|
11876
|
+
}
|
|
11877
|
+
function partitionWithBudgets(files, budgets, fingerprint) {
|
|
11878
|
+
const budgetFor = (file) => budgets.byLayer[file.layer] ?? budgets.default;
|
|
11179
11879
|
const buckets = /* @__PURE__ */ new Map();
|
|
11180
11880
|
for (const file of files) {
|
|
11181
11881
|
const budget = budgetFor(file);
|
|
@@ -11192,6 +11892,18 @@ function partitionByBudget(files, config, fingerprint) {
|
|
|
11192
11892
|
fingerprint
|
|
11193
11893
|
);
|
|
11194
11894
|
}
|
|
11895
|
+
function scaleBudgets(budgets, targetDefault) {
|
|
11896
|
+
const factor = targetDefault / budgets.default;
|
|
11897
|
+
return {
|
|
11898
|
+
default: Math.max(budgets.default, Math.round(targetDefault)),
|
|
11899
|
+
byLayer: Object.fromEntries(
|
|
11900
|
+
Object.entries(budgets.byLayer).map(([name, bytes]) => [
|
|
11901
|
+
name,
|
|
11902
|
+
Math.max(bytes, Math.round(bytes * factor))
|
|
11903
|
+
])
|
|
11904
|
+
)
|
|
11905
|
+
};
|
|
11906
|
+
}
|
|
11195
11907
|
function generateSnapshot(configInput, options) {
|
|
11196
11908
|
assertUsableConfigInput(configInput);
|
|
11197
11909
|
const config = isResolvedConfig(configInput) ? normalizeResolvedConfig(configInput) : resolveConfig(configInput ?? null);
|
|
@@ -11215,7 +11927,7 @@ function generateSnapshot(configInput, options) {
|
|
|
11215
11927
|
// output — but only at these exact paths, not at every directory that shares the name.
|
|
11216
11928
|
toolOwnedPaths: [config.outDir, config.tmpDir].map(
|
|
11217
11929
|
(directory) => path16__namespace.relative(config.cwd, path16__namespace.resolve(config.cwd, directory)).replace(/\\/g, "/")
|
|
11218
|
-
).filter((
|
|
11930
|
+
).filter((relative11) => relative11.length > 0 && !relative11.startsWith("..")),
|
|
11219
11931
|
// A staged path can be absent from the working tree while its index blob exists. Discovery
|
|
11220
11932
|
// lists the working tree, so those paths would never reach the scan at all.
|
|
11221
11933
|
...stagedPaths.size > 0 ? { extraPaths: [...stagedPaths] } : {}
|
|
@@ -11520,7 +12232,8 @@ function generateSnapshot(configInput, options) {
|
|
|
11520
12232
|
);
|
|
11521
12233
|
}
|
|
11522
12234
|
}
|
|
11523
|
-
const
|
|
12235
|
+
const partitioned = partitionByBudget(files, config, fingerprint);
|
|
12236
|
+
const parts = partitioned.parts;
|
|
11524
12237
|
const truncatedPreviewCount = files.filter((file) => file.isPreviewTruncated).length;
|
|
11525
12238
|
const incomplete = files.flatMap((file) => {
|
|
11526
12239
|
if (file.truncationReason === void 0) return [];
|
|
@@ -11557,7 +12270,10 @@ function generateSnapshot(configInput, options) {
|
|
|
11557
12270
|
// the README and the audit report.
|
|
11558
12271
|
git: { ...gitInfo, branch: maskPathText(gitInfo.branch, config.secretRules) },
|
|
11559
12272
|
budgets: {
|
|
11560
|
-
|
|
12273
|
+
// The ceiling the parts actually honour. It equals the configured one unless `maxParts`
|
|
12274
|
+
// grew it; `config.maxPartBytes` below keeps the configured value, because that is what
|
|
12275
|
+
// `validate` compares against the config on disk.
|
|
12276
|
+
maxPartBytes: partitioned.maxPartBytes,
|
|
11561
12277
|
largeFileBytes: config.largeFileBytes
|
|
11562
12278
|
},
|
|
11563
12279
|
config: {
|
|
@@ -11575,6 +12291,14 @@ function generateSnapshot(configInput, options) {
|
|
|
11575
12291
|
// invisible in the manifest that is supposed to describe the run.
|
|
11576
12292
|
maxMonolithBytes: config.maxMonolithBytes ?? null,
|
|
11577
12293
|
includeSensitiveFiles: config.includeSensitiveFiles,
|
|
12294
|
+
// The destination the instructions were written for. Not part of `digest`: the payload is
|
|
12295
|
+
// identical whatever this says, and a new delivery preference must not make an existing
|
|
12296
|
+
// snapshot fail `validate` as configuration drift.
|
|
12297
|
+
attachmentSlots: config.attachmentSlots,
|
|
12298
|
+
// The part-count ceiling the run enforced. Recorded because it decided the part sizes, and
|
|
12299
|
+
// omitted from `digest` when it is off so an existing snapshot does not start reporting
|
|
12300
|
+
// configuration drift.
|
|
12301
|
+
maxParts: config.maxParts ?? null,
|
|
11578
12302
|
discovery: config.discovery ?? "auto",
|
|
11579
12303
|
// A changed-files scope decides which files are in the snapshot, so the manifest that
|
|
11580
12304
|
// describes the run has to name it.
|
|
@@ -11635,7 +12359,7 @@ function generateSnapshot(configInput, options) {
|
|
|
11635
12359
|
},
|
|
11636
12360
|
layers: layerCounts,
|
|
11637
12361
|
kinds: kindCounts,
|
|
11638
|
-
indexes: buildIndexes(files, tsconfigPathsFor(config.cwd)),
|
|
12362
|
+
indexes: buildIndexes(files, tsconfigPathsFor(config.cwd), skippedSummaryImports),
|
|
11639
12363
|
parts: parts.map((part) => part.metadata),
|
|
11640
12364
|
files: files.map((file) => {
|
|
11641
12365
|
const { content: _content, ...rest } = file;
|
|
@@ -11645,6 +12369,10 @@ function generateSnapshot(configInput, options) {
|
|
|
11645
12369
|
incomplete,
|
|
11646
12370
|
warnings
|
|
11647
12371
|
};
|
|
12372
|
+
if (partitioned.warnings.length > 0) {
|
|
12373
|
+
manifest.warnings.push(...partitioned.warnings);
|
|
12374
|
+
manifest.totals.warningCount = manifest.warnings.length;
|
|
12375
|
+
}
|
|
11648
12376
|
manifest.totals.redactedLines = secretFindings.length;
|
|
11649
12377
|
manifest.totals.warningCount = manifest.warnings.length;
|
|
11650
12378
|
if (files.some((file) => file.isPreviewTruncated) && config.largeFileBytes < config.maxPartBytes) {
|
|
@@ -11677,11 +12405,9 @@ function generateSnapshot(configInput, options) {
|
|
|
11677
12405
|
let projectTree = null;
|
|
11678
12406
|
if (config.artifacts.projectTree) {
|
|
11679
12407
|
projectTree = generateProjectTree(files.map((file) => file.relativePath));
|
|
11680
|
-
const
|
|
11681
|
-
if (
|
|
11682
|
-
manifest.warnings.push(
|
|
11683
|
-
`reports/project-tree.md was truncated at the ${depthMarker[1]}-level depth cap: deeper directories are not listed there.`
|
|
11684
|
-
);
|
|
12408
|
+
const truncations = treeTruncationWarnings(projectTree);
|
|
12409
|
+
if (truncations.length > 0) {
|
|
12410
|
+
manifest.warnings.push(...truncations);
|
|
11685
12411
|
manifest.totals.warningCount = manifest.warnings.length;
|
|
11686
12412
|
}
|
|
11687
12413
|
}
|
|
@@ -11703,13 +12429,22 @@ function generateSnapshot(configInput, options) {
|
|
|
11703
12429
|
if (auditText !== null) manifest.artifacts.audit = artifactRecord(auditText);
|
|
11704
12430
|
const readmeText = artifacts.readme ? generateReadme(manifest, artifacts) : null;
|
|
11705
12431
|
if (readmeText !== null) manifest.artifacts.readme = artifactRecord(readmeText);
|
|
12432
|
+
const promptText = artifacts.prompt ? generatePrompt(
|
|
12433
|
+
manifest,
|
|
12434
|
+
artifacts,
|
|
12435
|
+
config.attachmentSlots,
|
|
12436
|
+
// Commit subjects are user input and reach an artifact, so they go through the same
|
|
12437
|
+
// masking as every other name the run reproduces.
|
|
12438
|
+
recentCommitSubjects(config.cwd).map((subject) => maskPathText(subject, config.secretRules))
|
|
12439
|
+
) : null;
|
|
12440
|
+
if (promptText !== null) manifest.artifacts.prompt = artifactRecord(promptText);
|
|
11706
12441
|
if (projectTree !== null) manifest.artifacts.projectTree = artifactRecord(projectTree);
|
|
11707
12442
|
let monolithJson = null;
|
|
11708
12443
|
let monolithMarkdown = null;
|
|
11709
12444
|
if (config.includeMonolith) {
|
|
11710
12445
|
const fullFiles = files.map((file) => {
|
|
11711
12446
|
const content = fullContents.get(file.relativePath) ?? "";
|
|
11712
|
-
|
|
12447
|
+
const entry = {
|
|
11713
12448
|
...file,
|
|
11714
12449
|
content,
|
|
11715
12450
|
inclusionMode: "full",
|
|
@@ -11717,6 +12452,9 @@ function generateSnapshot(configInput, options) {
|
|
|
11717
12452
|
includedBytes: Buffer.byteLength(content, "utf8"),
|
|
11718
12453
|
includedLines: countLines(content)
|
|
11719
12454
|
};
|
|
12455
|
+
delete entry.truncationReason;
|
|
12456
|
+
delete entry.omittedRanges;
|
|
12457
|
+
return entry;
|
|
11720
12458
|
});
|
|
11721
12459
|
const bodyBytes = fullFiles.reduce((total, file) => total + file.includedBytes, 0);
|
|
11722
12460
|
const definitelyTooLarge = config.maxMonolithBytes !== null && bodyBytes > config.maxMonolithBytes;
|
|
@@ -11837,6 +12575,9 @@ function generateSnapshot(configInput, options) {
|
|
|
11837
12575
|
if (readmeText !== null) {
|
|
11838
12576
|
writeArtifact(stagingDir, "README.md", readmeText);
|
|
11839
12577
|
}
|
|
12578
|
+
if (promptText !== null) {
|
|
12579
|
+
writeArtifact(stagingDir, "PROMPT.md", promptText);
|
|
12580
|
+
}
|
|
11840
12581
|
if (artifacts.manifest) {
|
|
11841
12582
|
writeArtifact(stagingDir, "manifest.json", JSON.stringify(manifest, null, 2));
|
|
11842
12583
|
}
|
|
@@ -12031,6 +12772,7 @@ exports.summarizeMarkdown = summarizeMarkdown;
|
|
|
12031
12772
|
exports.summarizeTypeScriptSource = summarizeTypeScriptSource;
|
|
12032
12773
|
exports.summarizeWithProfile = summarizeWithProfile;
|
|
12033
12774
|
exports.supportsTypeScriptImports = supportsTypeScriptImports;
|
|
12775
|
+
exports.treeTruncationWarnings = treeTruncationWarnings;
|
|
12034
12776
|
exports.truncatePreview = truncatePreview;
|
|
12035
12777
|
exports.truncateToBytes = truncateToBytes;
|
|
12036
12778
|
exports.tsconfigPathsFor = tsconfigPathsFor;
|