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
|
@@ -620,9 +620,9 @@ var rubyProfile = {
|
|
|
620
620
|
eachLine(content, (line) => {
|
|
621
621
|
const trimmed = line.trim();
|
|
622
622
|
if (!trimmed || trimmed.startsWith("#")) return;
|
|
623
|
-
const
|
|
624
|
-
if (
|
|
625
|
-
summary.imports.push(`./${
|
|
623
|
+
const relative11 = REQUIRE_RELATIVE.exec(trimmed);
|
|
624
|
+
if (relative11) {
|
|
625
|
+
summary.imports.push(`./${relative11[1]}`);
|
|
626
626
|
return;
|
|
627
627
|
}
|
|
628
628
|
const required = REQUIRE.exec(trimmed);
|
|
@@ -981,6 +981,8 @@ function summarizeTypeScriptSource(relativePath, content) {
|
|
|
981
981
|
if (cjsExports.length > 0) {
|
|
982
982
|
summary.exportsKind = summary.exports.length > 0 ? "mixed" : "cjs";
|
|
983
983
|
summary.exports.push(...cjsExports);
|
|
984
|
+
} else if (summary.exports.length > 0) {
|
|
985
|
+
summary.exportsKind = "esm";
|
|
984
986
|
}
|
|
985
987
|
const dedupeSorted2 = (values) => Array.from(new Set(values)).sort((a, b) => a < b ? -1 : a > b ? 1 : 0);
|
|
986
988
|
summary.directives = dedupeSorted2(summary.directives);
|
|
@@ -1880,8 +1882,8 @@ function workspacePackageDirs(cwd, patterns) {
|
|
|
1880
1882
|
function scanWorkspacePackages(cwd, patterns) {
|
|
1881
1883
|
const files = /* @__PURE__ */ new Set();
|
|
1882
1884
|
const dependencies = /* @__PURE__ */ new Set();
|
|
1883
|
-
for (const
|
|
1884
|
-
const full = path16.join(cwd,
|
|
1885
|
+
for (const relative11 of workspacePackageDirs(cwd, patterns)) {
|
|
1886
|
+
const full = path16.join(cwd, relative11);
|
|
1885
1887
|
try {
|
|
1886
1888
|
for (const entry of fs15.readdirSync(full, { withFileTypes: true })) files.add(entry.name);
|
|
1887
1889
|
} catch {
|
|
@@ -3000,6 +3002,24 @@ var DEFAULT_SECRET_PATTERNS = [
|
|
|
3000
3002
|
),
|
|
3001
3003
|
valueGroup: 2
|
|
3002
3004
|
},
|
|
3005
|
+
{
|
|
3006
|
+
// A quoted assignment whose closing quote is **not on this line**.
|
|
3007
|
+
//
|
|
3008
|
+
// The rule above requires `\1`, so an unterminated literal never matched it and the
|
|
3009
|
+
// credential reached the artefact in clear with no finding at all. That is the shape a
|
|
3010
|
+
// truncated file, a hand-edited `.env` and a string that continues on the next line all
|
|
3011
|
+
// produce, and it was the only branch of the redaction pass that was silent.
|
|
3012
|
+
//
|
|
3013
|
+
// The value runs to the end of the line on purpose — there is no delimiter to stop at — and
|
|
3014
|
+
// a later quote of the same kind disables the rule (`(?!\1)`), so a balanced literal is
|
|
3015
|
+
// never matched here: `password: "abc" and "def"` belongs to the rule above.
|
|
3016
|
+
rule: "credential-assignment-unterminated",
|
|
3017
|
+
pattern: new RegExp(
|
|
3018
|
+
`(?:${QUOTED_CREDENTIAL_KEY}|${NOT_AFTER_QUOTE}(?<!id[-_])${STRONG_CREDENTIAL_NAME})\\s{0,8}${ASSIGN}\\s{0,8}(["'\`])((?:(?!\\1)[^\\\\\\n]|\\\\.){1,512})$`,
|
|
3019
|
+
"i"
|
|
3020
|
+
),
|
|
3021
|
+
valueGroup: 2
|
|
3022
|
+
},
|
|
3003
3023
|
{
|
|
3004
3024
|
// `pass` and `credentials` are ambiguous on their own, so they
|
|
3005
3025
|
// are accepted only against a quoted value long enough to be a credential.
|
|
@@ -3559,10 +3579,8 @@ function scanAndRedactSecrets(content, rules, filePath) {
|
|
|
3559
3579
|
}
|
|
3560
3580
|
if (spans.length > 0) {
|
|
3561
3581
|
const maskedLine = applySpans(line, spans);
|
|
3562
|
-
|
|
3563
|
-
|
|
3564
|
-
segments[index] = maskedLine;
|
|
3565
|
-
}
|
|
3582
|
+
recordFinding(lineNumber, matchedRules);
|
|
3583
|
+
segments[index] = !quotesAreBalanced(line) || quotesAreBalanced(maskedLine) ? maskedLine : applySpansKeepingQuotes(line, spans);
|
|
3566
3584
|
}
|
|
3567
3585
|
}
|
|
3568
3586
|
if (index + 1 < segments.length) lineNumber += 1;
|
|
@@ -3840,6 +3858,17 @@ function isDeclaredBinding(line, matchIndex, filePath) {
|
|
|
3840
3858
|
return DECLARATION_KEYWORDS.test(line.slice(from, runStart));
|
|
3841
3859
|
}
|
|
3842
3860
|
function applySpans(line, spans) {
|
|
3861
|
+
let out = "";
|
|
3862
|
+
let cursor = 0;
|
|
3863
|
+
for (const span of mergedSpans(line, spans)) {
|
|
3864
|
+
out += line.slice(cursor, span.start);
|
|
3865
|
+
out += REDACTION_MARKER;
|
|
3866
|
+
cursor = span.end;
|
|
3867
|
+
}
|
|
3868
|
+
out += line.slice(cursor);
|
|
3869
|
+
return out;
|
|
3870
|
+
}
|
|
3871
|
+
function mergedSpans(line, spans) {
|
|
3843
3872
|
const ordered = [...spans].sort((a, b) => a.start - b.start || a.end - b.end);
|
|
3844
3873
|
const merged = [];
|
|
3845
3874
|
for (const span of ordered) {
|
|
@@ -3850,11 +3879,25 @@ function applySpans(line, spans) {
|
|
|
3850
3879
|
if (last && start <= last.end) last.end = Math.max(last.end, end);
|
|
3851
3880
|
else merged.push({ start, end });
|
|
3852
3881
|
}
|
|
3882
|
+
return merged;
|
|
3883
|
+
}
|
|
3884
|
+
function applySpansKeepingQuotes(line, spans) {
|
|
3853
3885
|
let out = "";
|
|
3854
3886
|
let cursor = 0;
|
|
3855
|
-
for (const span of
|
|
3887
|
+
for (const span of mergedSpans(line, spans)) {
|
|
3856
3888
|
out += line.slice(cursor, span.start);
|
|
3857
|
-
|
|
3889
|
+
let run = false;
|
|
3890
|
+
for (let index = span.start; index < span.end; index += 1) {
|
|
3891
|
+
const char = line[index];
|
|
3892
|
+
if (char === '"' || char === "'" || char === "`" || char === "\\") {
|
|
3893
|
+
if (run) out += REDACTION_MARKER;
|
|
3894
|
+
run = false;
|
|
3895
|
+
out += char;
|
|
3896
|
+
continue;
|
|
3897
|
+
}
|
|
3898
|
+
run = true;
|
|
3899
|
+
}
|
|
3900
|
+
if (run) out += REDACTION_MARKER;
|
|
3858
3901
|
cursor = span.end;
|
|
3859
3902
|
}
|
|
3860
3903
|
out += line.slice(cursor);
|
|
@@ -3863,7 +3906,7 @@ function applySpans(line, spans) {
|
|
|
3863
3906
|
|
|
3864
3907
|
// src/version.ts
|
|
3865
3908
|
var GENERATOR_NAME = "codebase-snapshot";
|
|
3866
|
-
var GENERATOR_VERSION = "0.
|
|
3909
|
+
var GENERATOR_VERSION = "0.11.0";
|
|
3867
3910
|
var SCHEMA_VERSION = "3.0.0";
|
|
3868
3911
|
var LEGACY_GENERATOR_NAMES = ["@ankurhalder/codebase-snapshot"];
|
|
3869
3912
|
function isOurGeneratorName(name) {
|
|
@@ -3895,8 +3938,8 @@ function brokenLinkRecord(linkPath, relativePath, rootReal) {
|
|
|
3895
3938
|
};
|
|
3896
3939
|
}
|
|
3897
3940
|
function isInside(root, candidate) {
|
|
3898
|
-
const
|
|
3899
|
-
return
|
|
3941
|
+
const relative11 = path16.relative(root, candidate);
|
|
3942
|
+
return relative11 === "" || !relative11.startsWith(`..${path16.sep}`) && relative11 !== ".." && !path16.isAbsolute(relative11);
|
|
3900
3943
|
}
|
|
3901
3944
|
var GIT_OUTPUT_LIMIT = 68157440;
|
|
3902
3945
|
function getGitInfo(cwd, fallbackBranch = "main") {
|
|
@@ -4311,6 +4354,23 @@ function defaultIgnoreReason(relativePath, toolDirNames = DEFAULT_TOOL_DIR_NAMES
|
|
|
4311
4354
|
}
|
|
4312
4355
|
return null;
|
|
4313
4356
|
}
|
|
4357
|
+
function recentCommitSubjects(cwd, limit = 10) {
|
|
4358
|
+
try {
|
|
4359
|
+
const stdout = childProcess.execFileSync(
|
|
4360
|
+
"git",
|
|
4361
|
+
["log", "-n", String(limit), "--pretty=%s", "--no-color"],
|
|
4362
|
+
{
|
|
4363
|
+
cwd,
|
|
4364
|
+
stdio: ["ignore", "pipe", "ignore"],
|
|
4365
|
+
encoding: "utf8",
|
|
4366
|
+
maxBuffer: GIT_OUTPUT_LIMIT
|
|
4367
|
+
}
|
|
4368
|
+
);
|
|
4369
|
+
return stdout.split("\n").map((line) => line.trim()).filter((line) => line.length > 0);
|
|
4370
|
+
} catch {
|
|
4371
|
+
return [];
|
|
4372
|
+
}
|
|
4373
|
+
}
|
|
4314
4374
|
function listIgnoredPaths(cwd) {
|
|
4315
4375
|
try {
|
|
4316
4376
|
const stdout = childProcess.execFileSync(
|
|
@@ -4795,7 +4855,7 @@ function findConfigFile(cwd) {
|
|
|
4795
4855
|
const pkgJsonPath = path16.join(cwd, "package.json");
|
|
4796
4856
|
if (!fs15.existsSync(pkgJsonPath)) return null;
|
|
4797
4857
|
try {
|
|
4798
|
-
const parsed = JSON.parse(
|
|
4858
|
+
const parsed = JSON.parse(stripJsonComments(fs15.readFileSync(pkgJsonPath, "utf8")));
|
|
4799
4859
|
const snapshot = parsed?.snapshot;
|
|
4800
4860
|
return typeof snapshot === "object" && snapshot !== null && !Array.isArray(snapshot) ? pkgJsonPath : null;
|
|
4801
4861
|
} catch {
|
|
@@ -4857,6 +4917,10 @@ function normalizeResolvedConfig(config) {
|
|
|
4857
4917
|
return markResolvedConfig({
|
|
4858
4918
|
...config,
|
|
4859
4919
|
discovery,
|
|
4920
|
+
// A spread copy built before the field existed carries no value; the default applies, and it
|
|
4921
|
+
// is re-validated because the number reaches a rendered artifact.
|
|
4922
|
+
attachmentSlots: resolveAttachmentSlots(config.attachmentSlots),
|
|
4923
|
+
maxParts: resolveMaxParts(config.maxParts),
|
|
4860
4924
|
includeMonolith: artifacts.monolith,
|
|
4861
4925
|
secretRules: compileSecretRules(config.secretRules),
|
|
4862
4926
|
artifacts,
|
|
@@ -4903,73 +4967,9 @@ function supportsTypeScriptImports() {
|
|
|
4903
4967
|
if (!Number.isFinite(major)) return false;
|
|
4904
4968
|
return major > 22 || major === 22 && minor >= 6;
|
|
4905
4969
|
}
|
|
4906
|
-
function stripJsonComments2(raw) {
|
|
4907
|
-
const text2 = raw.replace(/^\uFEFF/, "");
|
|
4908
|
-
let out = "";
|
|
4909
|
-
let inString = false;
|
|
4910
|
-
let escaped = false;
|
|
4911
|
-
for (let index = 0; index < text2.length; index += 1) {
|
|
4912
|
-
const char = text2[index];
|
|
4913
|
-
if (inString) {
|
|
4914
|
-
out += char;
|
|
4915
|
-
if (escaped) escaped = false;
|
|
4916
|
-
else if (char === "\\") escaped = true;
|
|
4917
|
-
else if (char === '"') inString = false;
|
|
4918
|
-
continue;
|
|
4919
|
-
}
|
|
4920
|
-
if (char === '"') {
|
|
4921
|
-
inString = true;
|
|
4922
|
-
out += char;
|
|
4923
|
-
continue;
|
|
4924
|
-
}
|
|
4925
|
-
if (char === "/" && text2[index + 1] === "/") {
|
|
4926
|
-
while (index < text2.length && text2[index] !== "\n" && text2[index] !== "\r") index += 1;
|
|
4927
|
-
index -= 1;
|
|
4928
|
-
continue;
|
|
4929
|
-
}
|
|
4930
|
-
if (char === "/" && text2[index + 1] === "*") {
|
|
4931
|
-
index += 2;
|
|
4932
|
-
while (index < text2.length && !(text2[index] === "*" && text2[index + 1] === "/")) {
|
|
4933
|
-
if (text2[index] === "\n" || text2[index] === "\r") out += text2[index];
|
|
4934
|
-
index += 1;
|
|
4935
|
-
}
|
|
4936
|
-
index += 1;
|
|
4937
|
-
continue;
|
|
4938
|
-
}
|
|
4939
|
-
out += char;
|
|
4940
|
-
}
|
|
4941
|
-
return stripTrailingCommas2(out);
|
|
4942
|
-
}
|
|
4943
|
-
function stripTrailingCommas2(text2) {
|
|
4944
|
-
let out = "";
|
|
4945
|
-
let inString = false;
|
|
4946
|
-
let escaped = false;
|
|
4947
|
-
for (let index = 0; index < text2.length; index += 1) {
|
|
4948
|
-
const char = text2[index];
|
|
4949
|
-
if (inString) {
|
|
4950
|
-
out += char;
|
|
4951
|
-
if (escaped) escaped = false;
|
|
4952
|
-
else if (char === "\\") escaped = true;
|
|
4953
|
-
else if (char === '"') inString = false;
|
|
4954
|
-
continue;
|
|
4955
|
-
}
|
|
4956
|
-
if (char === '"') {
|
|
4957
|
-
inString = true;
|
|
4958
|
-
out += char;
|
|
4959
|
-
continue;
|
|
4960
|
-
}
|
|
4961
|
-
if (char === ",") {
|
|
4962
|
-
let next = index + 1;
|
|
4963
|
-
while (next < text2.length && /\s/.test(text2[next])) next += 1;
|
|
4964
|
-
if (text2[next] === "}" || text2[next] === "]") continue;
|
|
4965
|
-
}
|
|
4966
|
-
out += char;
|
|
4967
|
-
}
|
|
4968
|
-
return out;
|
|
4969
|
-
}
|
|
4970
4970
|
function parseJsonish(raw, file) {
|
|
4971
4971
|
try {
|
|
4972
|
-
return JSON.parse(
|
|
4972
|
+
return JSON.parse(stripJsonComments(raw));
|
|
4973
4973
|
} catch (err) {
|
|
4974
4974
|
throw new Error(`Could not parse ${file}: ${err.message}`);
|
|
4975
4975
|
}
|
|
@@ -4987,8 +4987,9 @@ function describeValue2(value) {
|
|
|
4987
4987
|
return `${typeof value} (${String(value)})`;
|
|
4988
4988
|
}
|
|
4989
4989
|
var isThenable = (value) => typeof value.then === "function";
|
|
4990
|
-
var
|
|
4990
|
+
var CONFIG_KEY_NAMES = [
|
|
4991
4991
|
"artifacts",
|
|
4992
|
+
"attachmentSlots",
|
|
4992
4993
|
"branch",
|
|
4993
4994
|
"budgets",
|
|
4994
4995
|
"changedSince",
|
|
@@ -5006,6 +5007,7 @@ var CONFIG_KEYS = /* @__PURE__ */ new Set([
|
|
|
5006
5007
|
"layersMode",
|
|
5007
5008
|
"maxMonolithBytes",
|
|
5008
5009
|
"maxPartBytes",
|
|
5010
|
+
"maxParts",
|
|
5009
5011
|
"maxPartTokens",
|
|
5010
5012
|
"outDir",
|
|
5011
5013
|
"preset",
|
|
@@ -5018,7 +5020,8 @@ var CONFIG_KEYS = /* @__PURE__ */ new Set([
|
|
|
5018
5020
|
"skeleton",
|
|
5019
5021
|
"tmpDir",
|
|
5020
5022
|
"withDependents"
|
|
5021
|
-
]
|
|
5023
|
+
];
|
|
5024
|
+
var CONFIG_KEYS = new Set(CONFIG_KEY_NAMES);
|
|
5022
5025
|
function assertKnownConfigKeys(value, file) {
|
|
5023
5026
|
const unknownKeys = Object.keys(value).filter((key) => !CONFIG_KEYS.has(key));
|
|
5024
5027
|
if (unknownKeys.length === 0) return;
|
|
@@ -5210,6 +5213,7 @@ var MIN_MAX_PART_BYTES = 4096;
|
|
|
5210
5213
|
var MIN_MAX_PART_TOKENS = MIN_MAX_PART_BYTES / 4;
|
|
5211
5214
|
var ARTIFACT_NAMES = [
|
|
5212
5215
|
"readme",
|
|
5216
|
+
"prompt",
|
|
5213
5217
|
"manifest",
|
|
5214
5218
|
"parts",
|
|
5215
5219
|
"navigation",
|
|
@@ -5219,6 +5223,7 @@ var ARTIFACT_NAMES = [
|
|
|
5219
5223
|
];
|
|
5220
5224
|
var DEFAULT_ARTIFACTS = {
|
|
5221
5225
|
readme: true,
|
|
5226
|
+
prompt: true,
|
|
5222
5227
|
manifest: true,
|
|
5223
5228
|
parts: true,
|
|
5224
5229
|
navigation: true,
|
|
@@ -5279,6 +5284,25 @@ function resolveArtifacts(requested, skipped, includeMonolith, monolithOverride,
|
|
|
5279
5284
|
}
|
|
5280
5285
|
return artifacts;
|
|
5281
5286
|
}
|
|
5287
|
+
var DEFAULT_ATTACHMENT_SLOTS = 10;
|
|
5288
|
+
function resolveAttachmentSlots(value) {
|
|
5289
|
+
if (value === void 0 || value === null) return DEFAULT_ATTACHMENT_SLOTS;
|
|
5290
|
+
if (typeof value !== "number" || !Number.isInteger(value) || value < 0) {
|
|
5291
|
+
throw new Error(
|
|
5292
|
+
"attachmentSlots must be a whole number, with 0 meaning no limit (received " + describeValue2(value) + ")."
|
|
5293
|
+
);
|
|
5294
|
+
}
|
|
5295
|
+
return value;
|
|
5296
|
+
}
|
|
5297
|
+
function resolveMaxParts(value) {
|
|
5298
|
+
if (value === void 0 || value === null) return null;
|
|
5299
|
+
if (typeof value !== "number" || !Number.isInteger(value) || value < 1) {
|
|
5300
|
+
throw new Error(
|
|
5301
|
+
"maxParts must be a whole number of parts, or null to disable it (received " + describeValue2(value) + ")."
|
|
5302
|
+
);
|
|
5303
|
+
}
|
|
5304
|
+
return value;
|
|
5305
|
+
}
|
|
5282
5306
|
function strictPositiveInteger(value, fallback, label) {
|
|
5283
5307
|
if (value === void 0) return fallback;
|
|
5284
5308
|
if (typeof value !== "number" || !Number.isInteger(value) || value <= 0) {
|
|
@@ -5372,11 +5396,11 @@ function outputExcludePatterns(cwd, outDir, tmpDir) {
|
|
|
5372
5396
|
const patterns = [];
|
|
5373
5397
|
for (const dir of [outDir, tmpDir]) {
|
|
5374
5398
|
const absolute = path16.resolve(cwd, dir);
|
|
5375
|
-
const
|
|
5376
|
-
if (!
|
|
5399
|
+
const relative11 = path16.relative(cwd, absolute);
|
|
5400
|
+
if (!relative11 || relative11 === ".." || relative11.startsWith(`..${path16.sep}`) || path16.isAbsolute(relative11)) {
|
|
5377
5401
|
continue;
|
|
5378
5402
|
}
|
|
5379
|
-
patterns.push(`${
|
|
5403
|
+
patterns.push(`${relative11.replace(/\\/g, "/")}/**`);
|
|
5380
5404
|
}
|
|
5381
5405
|
return patterns;
|
|
5382
5406
|
}
|
|
@@ -5657,6 +5681,10 @@ function resolveConfig(userConfig, cliOptions, baseDir) {
|
|
|
5657
5681
|
"maxMonolithBytes"
|
|
5658
5682
|
),
|
|
5659
5683
|
includeSensitiveFiles,
|
|
5684
|
+
attachmentSlots: resolveAttachmentSlots(
|
|
5685
|
+
cliOptions?.attachmentSlots ?? userConfig?.attachmentSlots
|
|
5686
|
+
),
|
|
5687
|
+
maxParts: resolveMaxParts(cliOptions?.maxParts ?? userConfig?.maxParts),
|
|
5660
5688
|
...changedSince === void 0 ? {} : { changedSince },
|
|
5661
5689
|
...staged ? { staged } : {},
|
|
5662
5690
|
...withDependents ? { withDependents } : {},
|
|
@@ -5739,6 +5767,9 @@ function configDigest(config) {
|
|
|
5739
5767
|
includeMonolith: config.includeMonolith,
|
|
5740
5768
|
maxMonolithBytes: config.maxMonolithBytes ?? null,
|
|
5741
5769
|
includeSensitiveFiles: config.includeSensitiveFiles,
|
|
5770
|
+
// Only when the experimental mode is on: `null` is the off switch, and writing it into the
|
|
5771
|
+
// material would change the digest of every snapshot taken before the setting existed.
|
|
5772
|
+
...config.maxParts === null ? {} : { maxParts: config.maxParts },
|
|
5742
5773
|
artifacts: config.artifacts,
|
|
5743
5774
|
include: config.include,
|
|
5744
5775
|
excludePatterns: config.excludePatterns,
|
|
@@ -5911,7 +5942,7 @@ function generateAuditReport(manifest, secretFindings, secretRules) {
|
|
|
5911
5942
|
);
|
|
5912
5943
|
for (const file of affected) {
|
|
5913
5944
|
const status = file.isPreviewTruncated ? "Truncated" : "Full";
|
|
5914
|
-
const cutBy = file.truncationReason === "part-budget" ? "maxPartBytes" : "largeFileBytes";
|
|
5945
|
+
const cutBy = file.truncationReason === "part-budget" ? "part budget (maxPartBytes)" : "large-file budget (largeFileBytes)";
|
|
5915
5946
|
lines.push(
|
|
5916
5947
|
`| ${code(file.relativePath)} | ${file.sizeBytes} | ${file.lines} | ${file.includedBytes} | ${file.includedLines} | ${status} | ${cutBy} |`
|
|
5917
5948
|
);
|
|
@@ -6024,11 +6055,11 @@ function generateSarifReport(manifest, findings, rules, toolVersion) {
|
|
|
6024
6055
|
codebaseSnapshotFinding: `${findingPath}#L${line}#${finding.rules.join("+")}`
|
|
6025
6056
|
}
|
|
6026
6057
|
};
|
|
6027
|
-
}).sort(
|
|
6028
|
-
|
|
6029
|
-
|
|
6030
|
-
) || a.locations[0].physicalLocation.region.startLine - b.locations[0].physicalLocation.region.startLine
|
|
6031
|
-
);
|
|
6058
|
+
}).sort((a, b) => {
|
|
6059
|
+
const left = a.locations[0].physicalLocation.artifactLocation.uri;
|
|
6060
|
+
const right = b.locations[0].physicalLocation.artifactLocation.uri;
|
|
6061
|
+
return (left < right ? -1 : left > right ? 1 : 0) || a.locations[0].physicalLocation.region.startLine - b.locations[0].physicalLocation.region.startLine;
|
|
6062
|
+
});
|
|
6032
6063
|
const log = {
|
|
6033
6064
|
$schema: SARIF_SCHEMA,
|
|
6034
6065
|
version: SARIF_VERSION,
|
|
@@ -6119,6 +6150,7 @@ function truncatePreview(content, headLines, tailLines) {
|
|
|
6119
6150
|
// src/partitioner/chunker.ts
|
|
6120
6151
|
var HEADER_RESERVE_BYTES = 2048 + Buffer.byteLength(UNTRUSTED_CONTENT_NOTICE, "utf8") + 8;
|
|
6121
6152
|
var MIN_SECTION_BUDGET_BYTES = 512;
|
|
6153
|
+
var MIN_PART_BUDGET_BYTES = MIN_SECTION_BUDGET_BYTES + HEADER_RESERVE_BYTES;
|
|
6122
6154
|
var MAX_SPLIT_PASSES = 64;
|
|
6123
6155
|
var BUDGET_MARKER_RESERVE = 96;
|
|
6124
6156
|
function insertTokenLine(markdown, tokens) {
|
|
@@ -6157,10 +6189,17 @@ function partitionFilesForBuckets(buckets, contentFingerprint) {
|
|
|
6157
6189
|
const groups = [];
|
|
6158
6190
|
for (const bucket of buckets) {
|
|
6159
6191
|
if (bucket.files.length === 0) continue;
|
|
6160
|
-
|
|
6161
|
-
|
|
6162
|
-
|
|
6163
|
-
|
|
6192
|
+
if (!Number.isFinite(bucket.budgetBytes)) {
|
|
6193
|
+
throw new Error(
|
|
6194
|
+
`A part budget must be a finite number of bytes; received ${String(bucket.budgetBytes)}.`
|
|
6195
|
+
);
|
|
6196
|
+
}
|
|
6197
|
+
if (bucket.budgetBytes < MIN_PART_BUDGET_BYTES) {
|
|
6198
|
+
throw new Error(
|
|
6199
|
+
`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.`
|
|
6200
|
+
);
|
|
6201
|
+
}
|
|
6202
|
+
const budget = bucket.budgetBytes;
|
|
6164
6203
|
const sectionBudget = budget - HEADER_RESERVE_BYTES;
|
|
6165
6204
|
const prepared = bucket.files.map((file) => prepareSection(file, sectionBudget, budget));
|
|
6166
6205
|
for (const sections of greedyGroups(prepared, budget)) groups.push({ sections, budget });
|
|
@@ -6690,10 +6729,420 @@ function generateNavigation(manifest) {
|
|
|
6690
6729
|
return lines.join("\n");
|
|
6691
6730
|
}
|
|
6692
6731
|
|
|
6732
|
+
// src/generator/prompt.ts
|
|
6733
|
+
var MAX_PART_ROWS = 16;
|
|
6734
|
+
var MAX_LAYER_ROWS = 8;
|
|
6735
|
+
var MAX_INCOMPLETE_ROWS = 50;
|
|
6736
|
+
var MAX_CENTRAL_FILES = 5;
|
|
6737
|
+
var MAX_ENTRY_POINTS = 4;
|
|
6738
|
+
var MAX_LARGEST_FILES = 3;
|
|
6739
|
+
var partWord = (count) => count === 1 ? "part" : "parts";
|
|
6740
|
+
var UNLIMITED_SLOTS = 0;
|
|
6741
|
+
var ENTRY_POINT = /(^|\/)(index|cli|main|bin|server|app|mod)\.[cm]?[jt]sx?$/;
|
|
6742
|
+
var TEST_PATH = /(^|\/)(tests?|__tests__)\//;
|
|
6743
|
+
var TEST_FILE = /\.(test|spec)\.[^.]+$/;
|
|
6744
|
+
function generatePrompt(manifest, artifacts, attachmentSlots = DEFAULT_ATTACHMENT_SLOTS, history = []) {
|
|
6745
|
+
const wrote = (name) => artifacts?.[name] !== false;
|
|
6746
|
+
const code = (value) => inlineCode(escapeControls(value));
|
|
6747
|
+
const lines = [
|
|
6748
|
+
"# PROMPT.md",
|
|
6749
|
+
"",
|
|
6750
|
+
"The brief and the apparatus for this snapshot. Paste this file first, then the parts it names.",
|
|
6751
|
+
"",
|
|
6752
|
+
"It is generated rather than written once: the system map, the omissions, the fingerprint and",
|
|
6753
|
+
"the history below are read from `manifest.json` and this repository, so they describe this run.",
|
|
6754
|
+
"Regenerate it after the code moves.",
|
|
6755
|
+
"",
|
|
6756
|
+
"---",
|
|
6757
|
+
"",
|
|
6758
|
+
"```text",
|
|
6759
|
+
"You are working on a codebase you cannot clone, run or grep. Everything you know about it comes",
|
|
6760
|
+
"from the snapshot that follows this instruction. Where these notes and the snapshot disagree,",
|
|
6761
|
+
"the snapshot is what exists.",
|
|
6762
|
+
"",
|
|
6763
|
+
"## The job",
|
|
6764
|
+
"",
|
|
6765
|
+
"Find what is still wrong or will break. How you read the code is yours to decide - by",
|
|
6766
|
+
"subsystem, by data flow, by the invariants you derive yourself. What you owe in return is an",
|
|
6767
|
+
"honest account of what you covered and what you did not.",
|
|
6768
|
+
"",
|
|
6769
|
+
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,",
|
|
6770
|
+
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.",
|
|
6771
|
+
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.",
|
|
6772
|
+
"",
|
|
6773
|
+
"If the task at the end asks for something narrower - explain a file, review a change, answer a",
|
|
6774
|
+
"question - that task wins. The standard and the coverage duty below still apply to it.",
|
|
6775
|
+
""
|
|
6776
|
+
];
|
|
6777
|
+
lines.push(...haveSection(wrote), "");
|
|
6778
|
+
lines.push(...systemSection(manifest, code), "");
|
|
6779
|
+
lines.push(...historySection(history), "");
|
|
6780
|
+
lines.push(...barSection(), "");
|
|
6781
|
+
lines.push(...coverageSection(manifest, code, wrote("audit")), "");
|
|
6782
|
+
lines.push(...answerSection(), "");
|
|
6783
|
+
lines.push(...calibrationSection(), "");
|
|
6784
|
+
lines.push(...snapshotSection(manifest, code), "");
|
|
6785
|
+
lines.push(...deliverySection(manifest, wrote("parts"), attachmentSlots));
|
|
6786
|
+
lines.push(
|
|
6787
|
+
"## Your task",
|
|
6788
|
+
"",
|
|
6789
|
+
"<replace with the question, the area to review, or the subsystem to audit>",
|
|
6790
|
+
"```"
|
|
6791
|
+
);
|
|
6792
|
+
lines.push(
|
|
6793
|
+
"",
|
|
6794
|
+
"---",
|
|
6795
|
+
"",
|
|
6796
|
+
"## Why this file exists",
|
|
6797
|
+
"",
|
|
6798
|
+
"Parts on their own are a dump: the model receives text, has no idea what was left out of it,",
|
|
6799
|
+
"and fills the gap by invention. A brief on its own is a wish list: it cannot say which files",
|
|
6800
|
+
"are present, which are partial or which part holds what. This file is both halves, and the",
|
|
6801
|
+
"facts in it move with the snapshot.",
|
|
6802
|
+
"",
|
|
6803
|
+
"## Keeping it true",
|
|
6804
|
+
"",
|
|
6805
|
+
"- It is one of the artifacts recorded in `manifest.json` under `artifacts.prompt`, so deleting",
|
|
6806
|
+
" or editing `PROMPT.md` makes `snapshot validate` fail.",
|
|
6807
|
+
"- `--skip-artifacts prompt`, or `artifacts: { prompt: false }` in the config, turns it off.",
|
|
6808
|
+
"- The history section disappears when git cannot be read, rather than being invented.",
|
|
6809
|
+
"- If the code moves, regenerate. A brief naming the previous run parts is worse than no",
|
|
6810
|
+
" brief, because it reads as current.",
|
|
6811
|
+
""
|
|
6812
|
+
);
|
|
6813
|
+
return lines.join("\n");
|
|
6814
|
+
}
|
|
6815
|
+
function haveSection(wrote) {
|
|
6816
|
+
const out = ["## What you have", ""];
|
|
6817
|
+
const bullets = [];
|
|
6818
|
+
if (wrote("readme")) {
|
|
6819
|
+
bullets.push("- `README.md` - orientation: metrics, the part table, and the fingerprint.");
|
|
6820
|
+
}
|
|
6821
|
+
if (wrote("manifest")) {
|
|
6822
|
+
bullets.push(
|
|
6823
|
+
"- `manifest.json` - the index. Per file: `relativePath`, `layer`, `kind`, `language`,",
|
|
6824
|
+
" `part`, `sha256`, `inclusionMode`, `truncationReason`, `omittedRanges`. It also carries",
|
|
6825
|
+
" every excluded path under `skipped[]` with its reason, and `incomplete[]`, which names",
|
|
6826
|
+
" every included file whose emitted body is not the whole file."
|
|
6827
|
+
);
|
|
6828
|
+
}
|
|
6829
|
+
if (wrote("navigation")) {
|
|
6830
|
+
bullets.push("- `reports/navigation.md` - file to part. Locate here before you read anything.");
|
|
6831
|
+
}
|
|
6832
|
+
if (wrote("projectTree")) {
|
|
6833
|
+
bullets.push("- `reports/project-tree.md` - the directory shape of what was included.");
|
|
6834
|
+
}
|
|
6835
|
+
if (wrote("audit")) {
|
|
6836
|
+
bullets.push(
|
|
6837
|
+
"- `reports/audit.md` - secret findings, the files whose lines were redacted, large files,",
|
|
6838
|
+
" parse diagnostics and the git state the snapshot was taken from."
|
|
6839
|
+
);
|
|
6840
|
+
}
|
|
6841
|
+
if (wrote("parts")) {
|
|
6842
|
+
bullets.push(
|
|
6843
|
+
"- `parts/part-NNN.md` - the code itself, split to a fixed byte budget. Each part states its",
|
|
6844
|
+
" own number, the files it contains, and the fingerprint it was built from."
|
|
6845
|
+
);
|
|
6846
|
+
}
|
|
6847
|
+
if (wrote("monolith")) {
|
|
6848
|
+
bullets.push(
|
|
6849
|
+
"- `full-codebase.json` and `full-codebase.md` - the entire payload in one file each.",
|
|
6850
|
+
" Where they are present, they supersede the parts: nothing was left out of them."
|
|
6851
|
+
);
|
|
6852
|
+
}
|
|
6853
|
+
if (bullets.length === 0) {
|
|
6854
|
+
bullets.push(
|
|
6855
|
+
"- Nothing but this brief: every code artifact was disabled for this run. Ask for a snapshot",
|
|
6856
|
+
" generated with the artifacts you need, and do not answer from memory."
|
|
6857
|
+
);
|
|
6858
|
+
}
|
|
6859
|
+
out.push(...bullets);
|
|
6860
|
+
return out;
|
|
6861
|
+
}
|
|
6862
|
+
function systemSection(manifest, code) {
|
|
6863
|
+
const out = ["## The system", ""];
|
|
6864
|
+
const layers = Object.entries(manifest.layers).sort((a, b) => b[1] - a[1] || a[0].localeCompare(b[0]));
|
|
6865
|
+
if (layers.length > 0) {
|
|
6866
|
+
const shown = layers.slice(0, MAX_LAYER_ROWS).map(([name, count]) => code(name) + " " + formatNumber(count));
|
|
6867
|
+
const rest = layers.length > MAX_LAYER_ROWS ? ", and " + formatNumber(layers.length - MAX_LAYER_ROWS) + " more" : "";
|
|
6868
|
+
out.push("- Layers, by file count: " + shown.join(", ") + rest + ".");
|
|
6869
|
+
}
|
|
6870
|
+
const central = manifest.indexes.imports.centralFiles;
|
|
6871
|
+
if (central.length > 0) {
|
|
6872
|
+
const shown = central.slice(0, MAX_CENTRAL_FILES).map((entry) => code(entry.path) + " (" + formatNumber(entry.importedByCount) + ")").join(", ");
|
|
6873
|
+
out.push(
|
|
6874
|
+
"- Load-bearing modules, by how many files import them: " + shown + ".",
|
|
6875
|
+
" A change here reaches the most call sites; read it before judging anything that uses it."
|
|
6876
|
+
);
|
|
6877
|
+
}
|
|
6878
|
+
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);
|
|
6879
|
+
out.push(
|
|
6880
|
+
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"
|
|
6881
|
+
);
|
|
6882
|
+
if (entryPoints.length === 0) out.push(" starts, and the call graph in `manifest.json` is the map.");
|
|
6883
|
+
const routes = manifest.indexes.routes.length;
|
|
6884
|
+
const handlers = manifest.indexes.handlers.length;
|
|
6885
|
+
const components = manifest.indexes.components.length;
|
|
6886
|
+
const routesShown = manifest.indexes.routes.slice(0, 4).map((route) => code(route.path));
|
|
6887
|
+
const componentsShown = manifest.indexes.components.slice(0, 4).map((entry) => code(entry.path));
|
|
6888
|
+
if (routes + handlers + components === 0) {
|
|
6889
|
+
out.push(
|
|
6890
|
+
"- No routes, handlers or UI components were recorded: this snapshot indexes no HTTP or",
|
|
6891
|
+
" component surface. Do not go looking for one, and do not infer one from a file name."
|
|
6892
|
+
);
|
|
6893
|
+
} else {
|
|
6894
|
+
const parts = [];
|
|
6895
|
+
if (routes > 0) parts.push(formatNumber(routes) + " route(s), e.g. " + routesShown.join(", "));
|
|
6896
|
+
if (handlers > 0) parts.push(formatNumber(handlers) + " handler(s)");
|
|
6897
|
+
if (components > 0) parts.push(formatNumber(components) + " component(s), e.g. " + componentsShown.join(", "));
|
|
6898
|
+
out.push("- Surfaces the index found: " + parts.join("; ") + ".");
|
|
6899
|
+
}
|
|
6900
|
+
const largest = [...manifest.files].sort((a, b) => b.includedBytes - a.includedBytes).slice(0, MAX_LARGEST_FILES);
|
|
6901
|
+
if (largest.length > 0) {
|
|
6902
|
+
out.push(
|
|
6903
|
+
"- Largest files: " + largest.map((file) => code(file.relativePath) + " (" + formatNumber(Math.round(file.includedBytes / 1024)) + " KB)").join(", ") + "."
|
|
6904
|
+
);
|
|
6905
|
+
}
|
|
6906
|
+
const tests = manifest.files.filter(
|
|
6907
|
+
(file) => TEST_PATH.test(file.relativePath) || TEST_FILE.test(file.relativePath)
|
|
6908
|
+
);
|
|
6909
|
+
if (tests.length > 0) {
|
|
6910
|
+
const testBytes = tests.reduce((total, file) => total + file.includedBytes, 0);
|
|
6911
|
+
const allBytes = manifest.files.reduce((total, file) => total + file.includedBytes, 0);
|
|
6912
|
+
const share = allBytes === 0 ? 0 : Math.round(testBytes / allBytes * 100);
|
|
6913
|
+
out.push(
|
|
6914
|
+
"- Tests: " + formatNumber(tests.length) + " file(s), " + share + "% of the included bytes.",
|
|
6915
|
+
" They are evidence of intent, not of behaviour: a fixture can encode a payload shape the",
|
|
6916
|
+
" real system never sends."
|
|
6917
|
+
);
|
|
6918
|
+
}
|
|
6919
|
+
return out;
|
|
6920
|
+
}
|
|
6921
|
+
function historySection(history) {
|
|
6922
|
+
const out = ["## What came before", ""];
|
|
6923
|
+
if (history.length === 0) {
|
|
6924
|
+
out.push(
|
|
6925
|
+
"No history was readable: this is not a git checkout, or git could not be run. Nothing about",
|
|
6926
|
+
"what came before can be claimed from here, and that is not evidence that the code is new."
|
|
6927
|
+
);
|
|
6928
|
+
return out;
|
|
6929
|
+
}
|
|
6930
|
+
out.push(
|
|
6931
|
+
"Commit subjects, newest first. They are claims by whoever wrote them, not evidence - the code",
|
|
6932
|
+
"beside them is the evidence. If one of these fixes looks incomplete, quote the lines and say",
|
|
6933
|
+
"which call site it missed.",
|
|
6934
|
+
""
|
|
6935
|
+
);
|
|
6936
|
+
for (const subject of history) out.push("- " + subject);
|
|
6937
|
+
return out;
|
|
6938
|
+
}
|
|
6939
|
+
function barSection() {
|
|
6940
|
+
return [
|
|
6941
|
+
"## The bar",
|
|
6942
|
+
"",
|
|
6943
|
+
"A finding is a concrete way the code breaks or lies, supported by quoted lines: the path and",
|
|
6944
|
+
"line, the input or state that reaches it, what happens next, and why the guard that appears to",
|
|
6945
|
+
"stop it does not. A comment is not behaviour. A passing test is evidence of intent, not of",
|
|
6946
|
+
"behaviour.",
|
|
6947
|
+
"",
|
|
6948
|
+
"- No style, naming, formatting, add-types, add-tests, consider-X or speculative rewrites.",
|
|
6949
|
+
"- Never invent a finding to fill a section. A clean surface is proven by quoting the guard",
|
|
6950
|
+
" that makes it clean.",
|
|
6951
|
+
"- Mark confidence, and name the check - a test, a run, an input - that would settle anything",
|
|
6952
|
+
" you cannot decide by reading.",
|
|
6953
|
+
"- Separate what the code does from what the deployment or configuration does. Both are",
|
|
6954
|
+
" findings; they have different owners and different fixes."
|
|
6955
|
+
];
|
|
6956
|
+
}
|
|
6957
|
+
function coverageSection(manifest, code, auditWritten) {
|
|
6958
|
+
const out = ["## Coverage", ""];
|
|
6959
|
+
const reasons = /* @__PURE__ */ new Map();
|
|
6960
|
+
for (const record of manifest.skipped) {
|
|
6961
|
+
reasons.set(record.reason, (reasons.get(record.reason) ?? 0) + 1);
|
|
6962
|
+
}
|
|
6963
|
+
const tally = [...reasons.entries()].sort((a, b) => b[1] - a[1] || a[0].localeCompare(b[0])).map(([reason, count]) => code(reason) + " " + formatNumber(count)).join(", ");
|
|
6964
|
+
out.push(
|
|
6965
|
+
"- " + 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 + ")" : "") + ".",
|
|
6966
|
+
" `manifest.skipped[]` names each one and why. An absent path is not a clean path."
|
|
6967
|
+
);
|
|
6968
|
+
out.push(...incompleteSection(manifest, code));
|
|
6969
|
+
out.push(...redactionSection(manifest, auditWritten));
|
|
6970
|
+
out.push(
|
|
6971
|
+
"- Everything unseen is unread, never clean. If you were given only some of the parts, say",
|
|
6972
|
+
" which ones are missing before you answer. A file the index names but the parts do not carry",
|
|
6973
|
+
" is an input defect, not a code finding - report it as one."
|
|
6974
|
+
);
|
|
6975
|
+
return out;
|
|
6976
|
+
}
|
|
6977
|
+
function answerSection() {
|
|
6978
|
+
return [
|
|
6979
|
+
"## What a useful answer contains",
|
|
6980
|
+
"",
|
|
6981
|
+
"- An opening line, filled from This snapshot below:",
|
|
6982
|
+
"",
|
|
6983
|
+
" snapshot <fingerprint> generated <generatedAt>",
|
|
6984
|
+
"",
|
|
6985
|
+
"- What you read and what you did not, named by path or by part.",
|
|
6986
|
+
"- Findings ordered by consequence, each with the lines quoted.",
|
|
6987
|
+
"- The checks or attacks that failed, and the line or guard that blocked them. A failed attack",
|
|
6988
|
+
" is how anyone knows an invariant is real rather than asserted.",
|
|
6989
|
+
"- What you retracted after re-reading.",
|
|
6990
|
+
"- What only a run, a test or a host can settle, and the check that would settle each.",
|
|
6991
|
+
"- One paragraph on the failure you would bet on next.",
|
|
6992
|
+
"- A closing line: Needed but not received: <paths>, or none. That line is not decoration -",
|
|
6993
|
+
" an invented function is indistinguishable from a real one, and this is where you name",
|
|
6994
|
+
" the gap you filled by asking instead of guessing."
|
|
6995
|
+
];
|
|
6996
|
+
}
|
|
6997
|
+
function calibrationSection() {
|
|
6998
|
+
return [
|
|
6999
|
+
"## Calibration",
|
|
7000
|
+
"",
|
|
7001
|
+
"The findings that matter here do not crash. They look like:",
|
|
7002
|
+
"",
|
|
7003
|
+
"- a guard applied at one call site and not its twin - the route checks, the timer does not;",
|
|
7004
|
+
"- a budget shorter than the work it guards, so the caller gives up while the work continues;",
|
|
7005
|
+
"- a success flag that means the call returned, consumed as the change happened;",
|
|
7006
|
+
"- a document that describes a different run than the one beside it;",
|
|
7007
|
+
"- a default that fabricates a number when the measurement failed.",
|
|
7008
|
+
"",
|
|
7009
|
+
"None of these throw. All are invisible in a summary."
|
|
7010
|
+
];
|
|
7011
|
+
}
|
|
7012
|
+
function snapshotSection(manifest, code) {
|
|
7013
|
+
const out = ["## This snapshot", ""];
|
|
7014
|
+
out.push("- Fingerprint: " + code(manifest.fingerprint) + " - quote it verbatim in your answer.");
|
|
7015
|
+
out.push(
|
|
7016
|
+
"- Generated: " + code(manifest.generatedAt) + " from branch " + code(manifest.git.branch) + " at commit " + code(manifest.git.commit.slice(0, 8)) + "."
|
|
7017
|
+
);
|
|
7018
|
+
out.push(
|
|
7019
|
+
manifest.git.isDirty ? " The working tree had uncommitted changes at generation time." : " The working tree was clean at generation time."
|
|
7020
|
+
);
|
|
7021
|
+
out.push(
|
|
7022
|
+
"- Validation: `manifest.validation.status` was " + code(manifest.validation.status) + " at generation time.",
|
|
7023
|
+
" That describes the run, not now: if the tree may have moved since, the snapshot is a",
|
|
7024
|
+
" claim that needs re-checking, not a fact."
|
|
7025
|
+
);
|
|
7026
|
+
if (manifest.parts.length > 0) {
|
|
7027
|
+
out.push(
|
|
7028
|
+
"- Parts: " + formatNumber(manifest.parts.length) + " at a " + formatNumber(Math.round(manifest.budgets.maxPartBytes / 1024)) + " KB ceiling" + (manifest.parts.length === 1 ? ":" : " each:")
|
|
7029
|
+
);
|
|
7030
|
+
for (const part of manifest.parts.slice(0, MAX_PART_ROWS)) {
|
|
7031
|
+
out.push(" - " + code(part.filename) + " - " + formatNumber(part.fileCount) + " file(s)");
|
|
7032
|
+
}
|
|
7033
|
+
if (manifest.parts.length > MAX_PART_ROWS) {
|
|
7034
|
+
out.push(
|
|
7035
|
+
" - and " + formatNumber(manifest.parts.length - MAX_PART_ROWS) + " more, tabled in `README.md`"
|
|
7036
|
+
);
|
|
7037
|
+
}
|
|
7038
|
+
}
|
|
7039
|
+
return out;
|
|
7040
|
+
}
|
|
7041
|
+
function incompleteSection(manifest, code) {
|
|
7042
|
+
const out = [];
|
|
7043
|
+
const list2 = manifest.incomplete;
|
|
7044
|
+
if (list2.length === 0) {
|
|
7045
|
+
out.push("- Partial files: none. Every included file is present in full.");
|
|
7046
|
+
return out;
|
|
7047
|
+
}
|
|
7048
|
+
out.push(
|
|
7049
|
+
"- Partial files: " + formatNumber(list2.length) + ". These are present only in part, and the",
|
|
7050
|
+
" missing lines are named, not implied:"
|
|
7051
|
+
);
|
|
7052
|
+
for (const entry of list2.slice(0, MAX_INCOMPLETE_ROWS)) {
|
|
7053
|
+
const ranges = entry.omittedRanges.map(([start, end]) => start === end ? String(start) : start + "-" + end).join(", ");
|
|
7054
|
+
out.push(
|
|
7055
|
+
" - " + code(entry.relativePath) + " in " + code(entry.part) + " - " + entry.reason + ", lines " + ranges + " (" + formatNumber(entry.omittedLines) + " of " + formatNumber(entry.lines) + " missing)"
|
|
7056
|
+
);
|
|
7057
|
+
}
|
|
7058
|
+
if (list2.length > MAX_INCOMPLETE_ROWS) {
|
|
7059
|
+
out.push(
|
|
7060
|
+
" - and " + formatNumber(list2.length - MAX_INCOMPLETE_ROWS) + " more, all named in `manifest.json` under `incomplete[]`"
|
|
7061
|
+
);
|
|
7062
|
+
}
|
|
7063
|
+
return out;
|
|
7064
|
+
}
|
|
7065
|
+
function redactionSection(manifest, auditWritten) {
|
|
7066
|
+
const redacted = manifest.totals.redactedLines;
|
|
7067
|
+
if (redacted === 0) {
|
|
7068
|
+
return ["- Redacted: no line matched a secret rule."];
|
|
7069
|
+
}
|
|
7070
|
+
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.";
|
|
7071
|
+
return [
|
|
7072
|
+
"- Redacted: " + formatNumber(redacted) + " line(s) had values masked before you received them.",
|
|
7073
|
+
" A masked span is a deliberate redaction, not an empty value.",
|
|
7074
|
+
" " + where
|
|
7075
|
+
];
|
|
7076
|
+
}
|
|
7077
|
+
function deliverySection(manifest, partsWritten, slots) {
|
|
7078
|
+
if (!partsWritten || manifest.parts.length === 0) return [];
|
|
7079
|
+
const parts = manifest.parts.length;
|
|
7080
|
+
const wholeSet = parts + 5;
|
|
7081
|
+
const unlimited = slots <= UNLIMITED_SLOTS;
|
|
7082
|
+
const out = ["## Attaching this", ""];
|
|
7083
|
+
out.push(
|
|
7084
|
+
"Paste this file as text: instructions cost no attachment slot. Attach the files it names.",
|
|
7085
|
+
"",
|
|
7086
|
+
"- Every part opens with `# Codebase Snapshot Part NNN of MMM` and repeats the fingerprint",
|
|
7087
|
+
" above, so check both before relying on one. A part you were not given is not an empty part."
|
|
7088
|
+
);
|
|
7089
|
+
if (unlimited) {
|
|
7090
|
+
out.push(
|
|
7091
|
+
"- No attachment limit is configured, so every file can travel: " + parts + " " + partWord(parts) + " plus `manifest.json`, `README.md` and the three reports (" + wholeSet + " files)."
|
|
7092
|
+
);
|
|
7093
|
+
} else if (wholeSet <= slots) {
|
|
7094
|
+
out.push(
|
|
7095
|
+
"- A " + slots + "-file destination carries the whole set: " + parts + " " + partWord(parts) + " plus `manifest.json`, `README.md` and the three reports - " + wholeSet + " of " + slots + "."
|
|
7096
|
+
);
|
|
7097
|
+
} else if (parts + 1 <= slots) {
|
|
7098
|
+
out.push(
|
|
7099
|
+
"- A " + slots + "-file destination carries " + parts + " " + partWord(parts) + " and",
|
|
7100
|
+
" `manifest.json` (" + (parts + 1) + " of " + slots + "); `README.md` and",
|
|
7101
|
+
" `reports/` stay behind - the brief above carries what they add."
|
|
7102
|
+
);
|
|
7103
|
+
} else if (parts <= slots) {
|
|
7104
|
+
out.push(
|
|
7105
|
+
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",
|
|
7106
|
+
" `reports/` stay behind. The brief above carries what they add."
|
|
7107
|
+
);
|
|
7108
|
+
if (parts > 1) {
|
|
7109
|
+
out.push(
|
|
7110
|
+
" Either raise `--max-part-bytes` to merge the parts, or set `--max-parts " + slots + "` and let the parts grow to the count instead."
|
|
7111
|
+
);
|
|
7112
|
+
}
|
|
7113
|
+
} else {
|
|
7114
|
+
out.push(
|
|
7115
|
+
"- The " + parts + " parts do not fit a " + slots + "-file destination: at most " + slots + " can be attached.",
|
|
7116
|
+
" Choose by task - `reports/navigation.md` maps a file to its part - and name the parts",
|
|
7117
|
+
" you left out, or regenerate with `--max-part-bytes " + suggestBudgetBytes(manifest, slots) + "` for about " + (slots - 1) + " parts. `--max-parts " + slots + "` grows the parts until",
|
|
7118
|
+
" they fit instead, and says so when they end up larger than maxPartBytes."
|
|
7119
|
+
);
|
|
7120
|
+
}
|
|
7121
|
+
out.push(
|
|
7122
|
+
"- If you were given only some of them, say which parts are missing before you answer, and",
|
|
7123
|
+
" name the files you needed. Do not infer the contents of a part you did not receive.",
|
|
7124
|
+
""
|
|
7125
|
+
);
|
|
7126
|
+
return out;
|
|
7127
|
+
}
|
|
7128
|
+
function suggestBudgetBytes(manifest, slots) {
|
|
7129
|
+
const total = manifest.parts.reduce((sum, part) => sum + part.byteSize, 0);
|
|
7130
|
+
const target = Math.max(1, slots - 1);
|
|
7131
|
+
const estimated = Math.ceil(total / target * 1.15);
|
|
7132
|
+
const rounded = Math.ceil(estimated / 16384) * 16384;
|
|
7133
|
+
const budget = Math.max(rounded, manifest.budgets.maxPartBytes);
|
|
7134
|
+
return Math.round(budget / 1024) + "k";
|
|
7135
|
+
}
|
|
7136
|
+
|
|
6693
7137
|
// src/generator/readme.ts
|
|
6694
7138
|
function generateReadme(manifest, artifacts) {
|
|
6695
7139
|
const wrote = (name) => artifacts?.[name] !== false;
|
|
6696
7140
|
const reportLinks = [];
|
|
7141
|
+
if (wrote("prompt")) {
|
|
7142
|
+
reportLinks.push(
|
|
7143
|
+
"- [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."
|
|
7144
|
+
);
|
|
7145
|
+
}
|
|
6697
7146
|
if (wrote("navigation")) {
|
|
6698
7147
|
reportLinks.push(
|
|
6699
7148
|
"- [reports/navigation.md](reports/navigation.md) \u2014 Comprehensive file directory mapping files to chunk files."
|
|
@@ -6763,6 +7212,11 @@ function generateReadme(manifest, artifacts) {
|
|
|
6763
7212
|
lines.push("", "## Snapshot Parts", "", "No parts were written for this run.");
|
|
6764
7213
|
}
|
|
6765
7214
|
const readOrder = [];
|
|
7215
|
+
if (wrote("prompt")) {
|
|
7216
|
+
readOrder.push(
|
|
7217
|
+
"1. Hand `PROMPT.md` to the model that receives this snapshot: it names the parts, the partial files and the fingerprint of this run."
|
|
7218
|
+
);
|
|
7219
|
+
}
|
|
6766
7220
|
if (wrote("navigation") || wrote("projectTree")) {
|
|
6767
7221
|
const first = [wrote("navigation") ? "`reports/navigation.md`" : null, wrote("projectTree") ? "`reports/project-tree.md`" : null].filter(Boolean).join(" or ");
|
|
6768
7222
|
readOrder.push(`1. Read ${first} first to locate target features or files.`);
|
|
@@ -6851,6 +7305,22 @@ function generateProjectTree(filePaths) {
|
|
|
6851
7305
|
const fence = fenceForText(lines.join("\n"), 3);
|
|
6852
7306
|
return ["# Project Tree", "", `${fence}text`, ...lines, fence, ""].join("\n");
|
|
6853
7307
|
}
|
|
7308
|
+
function treeTruncationWarnings(treeText) {
|
|
7309
|
+
const warnings = [];
|
|
7310
|
+
const depth = /\[tree truncated at (\d+) levels\]/.exec(treeText);
|
|
7311
|
+
if (depth) {
|
|
7312
|
+
warnings.push(
|
|
7313
|
+
`reports/project-tree.md was truncated at the ${depth[1]}-level depth cap: deeper directories are not listed there.`
|
|
7314
|
+
);
|
|
7315
|
+
}
|
|
7316
|
+
const lines = /\[tree truncated at (\d+) lines\]/.exec(treeText);
|
|
7317
|
+
if (lines) {
|
|
7318
|
+
warnings.push(
|
|
7319
|
+
`reports/project-tree.md was truncated at the ${lines[1]}-line cap: the rest of the tree is not listed there.`
|
|
7320
|
+
);
|
|
7321
|
+
}
|
|
7322
|
+
return warnings;
|
|
7323
|
+
}
|
|
6854
7324
|
function gitPaths(cwd, args) {
|
|
6855
7325
|
let output;
|
|
6856
7326
|
try {
|
|
@@ -7015,8 +7485,8 @@ function tsconfigPathsFor(cwd) {
|
|
|
7015
7485
|
return value;
|
|
7016
7486
|
}
|
|
7017
7487
|
function repositoryRelative(cwd, target) {
|
|
7018
|
-
const
|
|
7019
|
-
return
|
|
7488
|
+
const relative11 = path16.relative(cwd, target).replace(/\\/g, "/");
|
|
7489
|
+
return relative11.length === 0 || !relative11.startsWith("..") && !path16.isAbsolute(relative11) ? relative11 : null;
|
|
7020
7490
|
}
|
|
7021
7491
|
function rememberFirst(map, key, value) {
|
|
7022
7492
|
if (!map.has(key)) map.set(key, value);
|
|
@@ -7286,6 +7756,16 @@ function wouldNowBeIncluded(cwd, relativePath) {
|
|
|
7286
7756
|
return false;
|
|
7287
7757
|
}
|
|
7288
7758
|
}
|
|
7759
|
+
var TRUNCATION_REASONS = /* @__PURE__ */ new Set([
|
|
7760
|
+
"large-file-budget",
|
|
7761
|
+
"part-budget",
|
|
7762
|
+
"section-metadata"
|
|
7763
|
+
]);
|
|
7764
|
+
function isConfinedRelative(value) {
|
|
7765
|
+
if (value.length === 0 || value.includes("\0") || value.includes("\\")) return false;
|
|
7766
|
+
if (path16.isAbsolute(value)) return false;
|
|
7767
|
+
return !value.split("/").includes("..");
|
|
7768
|
+
}
|
|
7289
7769
|
function describeManifestShapeProblem(value) {
|
|
7290
7770
|
if (!value || typeof value !== "object" || Array.isArray(value)) return "not a JSON object";
|
|
7291
7771
|
const candidate = value;
|
|
@@ -7351,6 +7831,68 @@ function describeManifestShapeProblem(value) {
|
|
|
7351
7831
|
if (!candidate.kinds || typeof candidate.kinds !== "object" || Array.isArray(candidate.kinds)) {
|
|
7352
7832
|
return 'missing "kinds" object';
|
|
7353
7833
|
}
|
|
7834
|
+
const incompleteCount = counts.incompleteCount;
|
|
7835
|
+
if (typeof incompleteCount !== "number" || !Number.isSafeInteger(incompleteCount) || incompleteCount < 0) {
|
|
7836
|
+
return "missing numeric `counts.incompleteCount`";
|
|
7837
|
+
}
|
|
7838
|
+
const incomplete = candidate.incomplete;
|
|
7839
|
+
if (!Array.isArray(incomplete)) return 'missing "incomplete" array';
|
|
7840
|
+
if (incompleteCount !== incomplete.length) {
|
|
7841
|
+
return "`counts.incompleteCount` does not match the length of `incomplete`";
|
|
7842
|
+
}
|
|
7843
|
+
for (const entry of incomplete) {
|
|
7844
|
+
if (!entry || typeof entry !== "object" || Array.isArray(entry)) {
|
|
7845
|
+
return 'an "incomplete" entry is not an object';
|
|
7846
|
+
}
|
|
7847
|
+
const fields = entry;
|
|
7848
|
+
const relativePath = fields.relativePath;
|
|
7849
|
+
if (typeof relativePath !== "string" || relativePath.length === 0) {
|
|
7850
|
+
return 'an "incomplete" entry has no "relativePath"';
|
|
7851
|
+
}
|
|
7852
|
+
if (!isConfinedRelative(relativePath)) {
|
|
7853
|
+
return 'an "incomplete" entry "relativePath" must stay inside the repository';
|
|
7854
|
+
}
|
|
7855
|
+
if (typeof fields.part !== "string" || fields.part.trim() === "") {
|
|
7856
|
+
return 'an "incomplete" entry has no "part"';
|
|
7857
|
+
}
|
|
7858
|
+
if (typeof fields.reason !== "string" || !TRUNCATION_REASONS.has(fields.reason)) {
|
|
7859
|
+
return 'an "incomplete" entry has an unknown "reason"';
|
|
7860
|
+
}
|
|
7861
|
+
for (const key of ["omittedLines", "includedLines", "lines"]) {
|
|
7862
|
+
const value2 = fields[key];
|
|
7863
|
+
if (typeof value2 !== "number" || !Number.isSafeInteger(value2) || value2 < 0) {
|
|
7864
|
+
return `an "incomplete" entry "${key}" must be a non-negative integer`;
|
|
7865
|
+
}
|
|
7866
|
+
}
|
|
7867
|
+
const lines = fields.lines;
|
|
7868
|
+
if (fields.includedLines > lines) {
|
|
7869
|
+
return 'an "incomplete" entry "includedLines" exceeds its "lines"';
|
|
7870
|
+
}
|
|
7871
|
+
const ranges = fields.omittedRanges;
|
|
7872
|
+
if (!Array.isArray(ranges)) return 'an "incomplete" entry has no "omittedRanges" array';
|
|
7873
|
+
let previousEnd = 0;
|
|
7874
|
+
let omitted = 0;
|
|
7875
|
+
for (const range of ranges) {
|
|
7876
|
+
if (!Array.isArray(range) || range.length !== 2) {
|
|
7877
|
+
return 'an "incomplete" entry "omittedRanges" must hold [from, to] pairs';
|
|
7878
|
+
}
|
|
7879
|
+
const [from, to] = range;
|
|
7880
|
+
if (typeof from !== "number" || typeof to !== "number" || !Number.isSafeInteger(from) || !Number.isSafeInteger(to)) {
|
|
7881
|
+
return 'an "incomplete" entry "omittedRanges" must hold integer pairs';
|
|
7882
|
+
}
|
|
7883
|
+
if (from < 1 || to < from || to > lines) {
|
|
7884
|
+
return `an "incomplete" entry records an omitted range ${from}-${to}, outside 1-${lines}`;
|
|
7885
|
+
}
|
|
7886
|
+
if (from <= previousEnd) {
|
|
7887
|
+
return 'an "incomplete" entry "omittedRanges" must be sorted and non-overlapping';
|
|
7888
|
+
}
|
|
7889
|
+
previousEnd = to;
|
|
7890
|
+
omitted += to - from + 1;
|
|
7891
|
+
}
|
|
7892
|
+
if (omitted !== fields.omittedLines) {
|
|
7893
|
+
return "`omittedLines` does not match the ranges it records";
|
|
7894
|
+
}
|
|
7895
|
+
}
|
|
7354
7896
|
}
|
|
7355
7897
|
if (!Array.isArray(candidate.files)) return 'missing "files" array';
|
|
7356
7898
|
for (const entry of candidate.files) {
|
|
@@ -7464,11 +8006,57 @@ function validateSnapshot(configInput) {
|
|
|
7464
8006
|
);
|
|
7465
8007
|
}
|
|
7466
8008
|
const manifestFileMap = /* @__PURE__ */ new Map();
|
|
8009
|
+
const manifestFilesByPath = /* @__PURE__ */ new Map();
|
|
7467
8010
|
for (const file of manifest.files) {
|
|
7468
8011
|
if (file && typeof file.relativePath === "string") {
|
|
7469
8012
|
manifestFileMap.set(file.relativePath, file.hashSha256);
|
|
8013
|
+
manifestFilesByPath.set(file.relativePath, file);
|
|
8014
|
+
}
|
|
8015
|
+
}
|
|
8016
|
+
const incompleteRecords = manifest.incomplete ?? [];
|
|
8017
|
+
const incompleteness = /* @__PURE__ */ new Map();
|
|
8018
|
+
for (const record of incompleteRecords) {
|
|
8019
|
+
incompleteness.set(record.relativePath, record);
|
|
8020
|
+
const label = maskedPath(record.relativePath, config.secretRules);
|
|
8021
|
+
const file = manifestFilesByPath.get(record.relativePath);
|
|
8022
|
+
if (file === void 0) {
|
|
8023
|
+
drift.partIssues.push({
|
|
8024
|
+
part: "(manifest)",
|
|
8025
|
+
issue: `${label} is in incomplete[] but not in files[]`
|
|
8026
|
+
});
|
|
8027
|
+
continue;
|
|
8028
|
+
}
|
|
8029
|
+
if (file.part !== record.part) {
|
|
8030
|
+
drift.partIssues.push({
|
|
8031
|
+
part: "(manifest)",
|
|
8032
|
+
issue: `${label} is recorded in part ${String(record.part)} in incomplete[] and part ${String(file.part)} in files[]`
|
|
8033
|
+
});
|
|
8034
|
+
}
|
|
8035
|
+
if (file.truncationReason !== record.reason) {
|
|
8036
|
+
drift.partIssues.push({
|
|
8037
|
+
part: "(manifest)",
|
|
8038
|
+
issue: `${label} records truncationReason ${String(file.truncationReason)} in files[] and reason ${String(record.reason)} in incomplete[]`
|
|
8039
|
+
});
|
|
8040
|
+
}
|
|
8041
|
+
const recordedRanges = file.omittedRanges ?? [];
|
|
8042
|
+
const rangesAgree = recordedRanges.length === record.omittedRanges.length && recordedRanges.every(
|
|
8043
|
+
([from, to], index) => record.omittedRanges[index][0] === from && record.omittedRanges[index][1] === to
|
|
8044
|
+
);
|
|
8045
|
+
if (!rangesAgree || file.includedLines !== record.includedLines || file.lines !== record.lines) {
|
|
8046
|
+
drift.partIssues.push({
|
|
8047
|
+
part: "(manifest)",
|
|
8048
|
+
issue: `${label} records different omission numbers in files[] and incomplete[]`
|
|
8049
|
+
});
|
|
7470
8050
|
}
|
|
7471
8051
|
}
|
|
8052
|
+
for (const file of manifest.files) {
|
|
8053
|
+
if (file.truncationReason === void 0) continue;
|
|
8054
|
+
if (incompleteness.has(file.relativePath)) continue;
|
|
8055
|
+
drift.partIssues.push({
|
|
8056
|
+
part: "(manifest)",
|
|
8057
|
+
issue: `${maskedPath(file.relativePath, config.secretRules)} records a truncationReason but is missing from incomplete[]`
|
|
8058
|
+
});
|
|
8059
|
+
}
|
|
7472
8060
|
const skippedReasons = /* @__PURE__ */ new Map();
|
|
7473
8061
|
for (const entry of manifest.skipped) {
|
|
7474
8062
|
if (entry && typeof entry.path === "string" && typeof entry.reason === "string") {
|
|
@@ -7525,7 +8113,7 @@ function validateSnapshot(configInput) {
|
|
|
7525
8113
|
// snapshot was reported as drifting.
|
|
7526
8114
|
toolOwnedPaths: [config.outDir, config.tmpDir].map(
|
|
7527
8115
|
(directory) => path16.relative(config.cwd, path16.resolve(config.cwd, directory)).replace(/\\/g, "/")
|
|
7528
|
-
).filter((
|
|
8116
|
+
).filter((relative11) => relative11.length > 0 && !relative11.startsWith(".."))
|
|
7529
8117
|
});
|
|
7530
8118
|
for (const diskFile of collection.files) {
|
|
7531
8119
|
const snapshotHash = manifestFileMap.get(diskFile);
|
|
@@ -7926,7 +8514,8 @@ function validateSnapshot(configInput) {
|
|
|
7926
8514
|
);
|
|
7927
8515
|
}
|
|
7928
8516
|
}
|
|
7929
|
-
|
|
8517
|
+
const ceilingDerivedByMaxParts = (manifest.config?.maxParts ?? null) !== null;
|
|
8518
|
+
if (!ceilingDerivedByMaxParts && manifest.budgets && manifest.budgets.maxPartBytes !== config.maxPartBytes) {
|
|
7930
8519
|
totalsMismatches.push(
|
|
7931
8520
|
`budgets.maxPartBytes: manifest ${manifest.budgets.maxPartBytes} vs current ${config.maxPartBytes}`
|
|
7932
8521
|
);
|
|
@@ -7955,6 +8544,7 @@ function validateSnapshot(configInput) {
|
|
|
7955
8544
|
}
|
|
7956
8545
|
const declaredArtifacts = [
|
|
7957
8546
|
["README.md", manifest.artifacts?.readme],
|
|
8547
|
+
["PROMPT.md", manifest.artifacts?.prompt],
|
|
7958
8548
|
["reports/navigation.md", manifest.artifacts?.navigation],
|
|
7959
8549
|
["reports/project-tree.md", manifest.artifacts?.projectTree],
|
|
7960
8550
|
["reports/audit.md", manifest.artifacts?.audit],
|
|
@@ -7981,8 +8571,8 @@ function validateSnapshot(configInput) {
|
|
|
7981
8571
|
const target = match[1].split("#")[0];
|
|
7982
8572
|
if (target.length === 0 || /^[a-z][a-z0-9+.-]*:/i.test(target)) continue;
|
|
7983
8573
|
const resolved = path16.resolve(snapshotDir, "reports", target);
|
|
7984
|
-
const
|
|
7985
|
-
if (
|
|
8574
|
+
const relative11 = path16.relative(snapshotDir, resolved);
|
|
8575
|
+
if (relative11.startsWith("..") || path16.isAbsolute(relative11) || !fs15.existsSync(resolved)) {
|
|
7986
8576
|
drift.partIssues.push({
|
|
7987
8577
|
part: key,
|
|
7988
8578
|
issue: `links to ${maskedPath(target, config.secretRules)}, which does not exist in the snapshot`
|
|
@@ -8177,14 +8767,14 @@ function writeCache(file, entry) {
|
|
|
8177
8767
|
}
|
|
8178
8768
|
}
|
|
8179
8769
|
function fetchLatestVersion(url = PACKAGE_LATEST_URL, timeoutMs = REQUEST_TIMEOUT_MS) {
|
|
8180
|
-
return new Promise((
|
|
8770
|
+
return new Promise((resolve8) => {
|
|
8181
8771
|
let settled = false;
|
|
8182
8772
|
let request = null;
|
|
8183
8773
|
const finish = (value) => {
|
|
8184
8774
|
if (settled) return;
|
|
8185
8775
|
settled = true;
|
|
8186
8776
|
clearTimeout(deadline);
|
|
8187
|
-
|
|
8777
|
+
resolve8(value);
|
|
8188
8778
|
};
|
|
8189
8779
|
const deadline = setTimeout(() => {
|
|
8190
8780
|
request?.destroy();
|
|
@@ -8272,23 +8862,23 @@ function describeMatcher(matcher) {
|
|
|
8272
8862
|
function normalizeTarget(cwd, target) {
|
|
8273
8863
|
const resolvedCwd = path16.resolve(cwd);
|
|
8274
8864
|
const absolute = path16.resolve(resolvedCwd, target);
|
|
8275
|
-
const
|
|
8276
|
-
if (
|
|
8865
|
+
const relative11 = path16.relative(resolvedCwd, absolute);
|
|
8866
|
+
if (relative11 === "" || relative11 === ".." || relative11.startsWith(`..${path16.sep}`) || path16.isAbsolute(relative11)) {
|
|
8277
8867
|
return { relative: target.replace(/\\/g, "/"), outsideRoot: true };
|
|
8278
8868
|
}
|
|
8279
|
-
return { relative:
|
|
8869
|
+
return { relative: relative11.split(path16.sep).join("/"), outsideRoot: false };
|
|
8280
8870
|
}
|
|
8281
8871
|
function findRuleMatch(rules, relativePath) {
|
|
8282
8872
|
return rules.find(
|
|
8283
8873
|
(rule) => matchRule(relativePath, rule.match)
|
|
8284
8874
|
);
|
|
8285
8875
|
}
|
|
8286
|
-
function findRecordedAncestor(skipped,
|
|
8876
|
+
function findRecordedAncestor(skipped, relative11, maskedPath2) {
|
|
8287
8877
|
let nearest;
|
|
8288
8878
|
for (const record of skipped) {
|
|
8289
8879
|
const ancestorPath = record.path;
|
|
8290
8880
|
if (ancestorPath.length === 0) continue;
|
|
8291
|
-
const isAncestor =
|
|
8881
|
+
const isAncestor = relative11.startsWith(`${ancestorPath}/`) || maskedPath2.startsWith(`${ancestorPath}/`);
|
|
8292
8882
|
if (!isAncestor) continue;
|
|
8293
8883
|
if (!nearest || ancestorPath.length > nearest.path.length) nearest = record;
|
|
8294
8884
|
}
|
|
@@ -8304,8 +8894,8 @@ function readManifest2(config) {
|
|
|
8304
8894
|
}
|
|
8305
8895
|
function explainPath(config, target) {
|
|
8306
8896
|
const normalized = normalizeTarget(config.cwd, target);
|
|
8307
|
-
const
|
|
8308
|
-
const maskedPath2 = findSecretInPath(
|
|
8897
|
+
const relative11 = normalized.relative;
|
|
8898
|
+
const maskedPath2 = findSecretInPath(relative11, config.secretRules)?.masked ?? relative11;
|
|
8309
8899
|
if (normalized.outsideRoot) {
|
|
8310
8900
|
return {
|
|
8311
8901
|
path: maskedPath2,
|
|
@@ -8315,7 +8905,7 @@ function explainPath(config, target) {
|
|
|
8315
8905
|
detail: "path resolves outside the configured repository root and was not inspected"
|
|
8316
8906
|
};
|
|
8317
8907
|
}
|
|
8318
|
-
const absolute = path16.join(config.cwd,
|
|
8908
|
+
const absolute = path16.join(config.cwd, relative11);
|
|
8319
8909
|
const result = {
|
|
8320
8910
|
path: maskedPath2,
|
|
8321
8911
|
exists: fs15.existsSync(absolute),
|
|
@@ -8333,11 +8923,11 @@ function explainPath(config, target) {
|
|
|
8333
8923
|
// that is only missing because the walker dropped the tool's own output directory.
|
|
8334
8924
|
toolOwnedPaths: [config.outDir, config.tmpDir].map(
|
|
8335
8925
|
(directory) => path16.relative(config.cwd, path16.resolve(config.cwd, directory)).replace(/\\/g, "/")
|
|
8336
|
-
).filter((
|
|
8926
|
+
).filter((relative12) => relative12.length > 0 && !relative12.startsWith(".."))
|
|
8337
8927
|
});
|
|
8338
|
-
if (!collection.files.includes(
|
|
8928
|
+
if (!collection.files.includes(relative11)) {
|
|
8339
8929
|
const record = collection.skipped.find(
|
|
8340
|
-
(entry2) => entry2.path ===
|
|
8930
|
+
(entry2) => entry2.path === relative11 || entry2.path === maskedPath2
|
|
8341
8931
|
);
|
|
8342
8932
|
if (record) {
|
|
8343
8933
|
result.reason = record.reason;
|
|
@@ -8346,7 +8936,7 @@ function explainPath(config, target) {
|
|
|
8346
8936
|
result.reason = "missing";
|
|
8347
8937
|
result.detail = "no such file or directory, relative to the configured cwd";
|
|
8348
8938
|
} else {
|
|
8349
|
-
const ancestor = findRecordedAncestor(collection.skipped,
|
|
8939
|
+
const ancestor = findRecordedAncestor(collection.skipped, relative11, maskedPath2);
|
|
8350
8940
|
if (ancestor) {
|
|
8351
8941
|
result.reason = ancestor.reason;
|
|
8352
8942
|
result.detail = ancestor.detail ? `${ancestor.detail} \u2014 inherited from the skipped directory \`${ancestor.path}\`` : `inside the skipped directory \`${ancestor.path}\``;
|
|
@@ -8366,11 +8956,11 @@ function explainPath(config, target) {
|
|
|
8366
8956
|
...config.changedSince === void 0 ? {} : { changedSince: config.changedSince },
|
|
8367
8957
|
...config.staged === true ? { staged: true } : {}
|
|
8368
8958
|
});
|
|
8369
|
-
inScope = scope.paths.has(
|
|
8959
|
+
inScope = scope.paths.has(relative11);
|
|
8370
8960
|
if (!inScope && config.withDependents === true) {
|
|
8371
8961
|
inScope = importsChangedFile(
|
|
8372
|
-
|
|
8373
|
-
importsOfFile(
|
|
8962
|
+
relative11,
|
|
8963
|
+
importsOfFile(relative11, absolute),
|
|
8374
8964
|
scope.paths,
|
|
8375
8965
|
buildImportResolver(collection.files.map((file) => ({ relativePath: file })))
|
|
8376
8966
|
);
|
|
@@ -8428,12 +9018,12 @@ function explainPath(config, target) {
|
|
|
8428
9018
|
result.bytes = buffer.length;
|
|
8429
9019
|
result.lines = countLines(text2);
|
|
8430
9020
|
if (decoded.encoding !== "utf-8") result.encoding = decoded.encoding;
|
|
8431
|
-
const { findings } = scanAndRedactSecrets(text2, config.secretRules,
|
|
9021
|
+
const { findings } = scanAndRedactSecrets(text2, config.secretRules, relative11);
|
|
8432
9022
|
result.secretCount = findings.length;
|
|
8433
9023
|
result.secrets = findings.slice(0, 20).map((finding) => ({ rules: finding.rules, line: finding.line }));
|
|
8434
9024
|
let inclusionMode = "full";
|
|
8435
|
-
if (config.skeleton === true && isSkeletonizable(
|
|
8436
|
-
const skeleton = skeletonizeTypeScript(text2,
|
|
9025
|
+
if (config.skeleton === true && isSkeletonizable(relative11)) {
|
|
9026
|
+
const skeleton = skeletonizeTypeScript(text2, relative11);
|
|
8437
9027
|
if (skeleton.collapsed > 0) inclusionMode = "signatures";
|
|
8438
9028
|
}
|
|
8439
9029
|
if (inclusionMode !== "signatures" && buffer.length > config.largeFileBytes) {
|
|
@@ -8442,15 +9032,15 @@ function explainPath(config, target) {
|
|
|
8442
9032
|
}
|
|
8443
9033
|
result.inclusionMode = inclusionMode;
|
|
8444
9034
|
}
|
|
8445
|
-
result.layer = classifyLayer(
|
|
8446
|
-
result.kind = classifyKind(
|
|
8447
|
-
result.language = detectLanguage(
|
|
8448
|
-
const layerRule = findRuleMatch(config.layers,
|
|
9035
|
+
result.layer = classifyLayer(relative11, config.layers);
|
|
9036
|
+
result.kind = classifyKind(relative11, config.kinds);
|
|
9037
|
+
result.language = detectLanguage(relative11);
|
|
9038
|
+
const layerRule = findRuleMatch(config.layers, relative11);
|
|
8449
9039
|
if (layerRule) result.layerMatch = describeMatcher(layerRule.match);
|
|
8450
|
-
const kindRule = findRuleMatch(config.kinds,
|
|
9040
|
+
const kindRule = findRuleMatch(config.kinds, relative11);
|
|
8451
9041
|
if (kindRule) result.kindMatch = describeMatcher(kindRule.match);
|
|
8452
9042
|
const manifest = readManifest2(config);
|
|
8453
|
-
const entry = Array.isArray(manifest?.files) ? manifest.files.find((file) => file.relativePath ===
|
|
9043
|
+
const entry = Array.isArray(manifest?.files) ? manifest.files.find((file) => file.relativePath === relative11) : void 0;
|
|
8454
9044
|
result.part = entry?.part ?? null;
|
|
8455
9045
|
return result;
|
|
8456
9046
|
}
|
|
@@ -8499,19 +9089,19 @@ function side(manifest) {
|
|
|
8499
9089
|
function shortDigest(value) {
|
|
8500
9090
|
return value === null ? "not recorded" : `${value.slice(0, 12)}\u2026`;
|
|
8501
9091
|
}
|
|
8502
|
-
function describeLayerChanges(before, after) {
|
|
9092
|
+
function describeLayerChanges(before, after, secretRules) {
|
|
8503
9093
|
const names = Array.from(/* @__PURE__ */ new Set([...Object.keys(before), ...Object.keys(after)])).sort();
|
|
8504
9094
|
const changes = [];
|
|
8505
9095
|
for (const name of names) {
|
|
8506
9096
|
const was = before[name] ?? 0;
|
|
8507
9097
|
const now = after[name] ?? 0;
|
|
8508
9098
|
if (was === now) continue;
|
|
8509
|
-
const label = findSecretInPath(name)?.masked ?? name;
|
|
9099
|
+
const label = findSecretInPath(name, secretRules)?.masked ?? name;
|
|
8510
9100
|
changes.push(`layer "${label}": ${was} file(s) \u2192 ${now} file(s)`);
|
|
8511
9101
|
}
|
|
8512
9102
|
return changes;
|
|
8513
9103
|
}
|
|
8514
|
-
function describePartChanges(before, after) {
|
|
9104
|
+
function describePartChanges(before, after, secretRules) {
|
|
8515
9105
|
const index = (parts) => {
|
|
8516
9106
|
const map = /* @__PURE__ */ new Map();
|
|
8517
9107
|
for (const part of parts) {
|
|
@@ -8521,7 +9111,7 @@ function describePartChanges(before, after) {
|
|
|
8521
9111
|
};
|
|
8522
9112
|
const left = index(before);
|
|
8523
9113
|
const right = index(after);
|
|
8524
|
-
const label = (filename) => findSecretInPath(filename)?.masked ?? filename;
|
|
9114
|
+
const label = (filename) => findSecretInPath(filename, secretRules)?.masked ?? filename;
|
|
8525
9115
|
const changes = [];
|
|
8526
9116
|
for (const [filename, part] of right) {
|
|
8527
9117
|
const previous = left.get(filename);
|
|
@@ -8549,7 +9139,15 @@ function describePartChanges(before, after) {
|
|
|
8549
9139
|
}
|
|
8550
9140
|
return changes;
|
|
8551
9141
|
}
|
|
8552
|
-
function
|
|
9142
|
+
function maskLayerNames(layers, secretRules) {
|
|
9143
|
+
return Object.fromEntries(
|
|
9144
|
+
Object.entries(layers ?? {}).map(([name, count]) => [
|
|
9145
|
+
findSecretInPath(name, secretRules)?.masked ?? name,
|
|
9146
|
+
count
|
|
9147
|
+
])
|
|
9148
|
+
);
|
|
9149
|
+
}
|
|
9150
|
+
function describePayloadDiff(before, after, sourceFilesIdentical, secretRules) {
|
|
8553
9151
|
const generatorBefore = before.generator?.version ?? "unknown";
|
|
8554
9152
|
const generatorAfter = after.generator?.version ?? "unknown";
|
|
8555
9153
|
const digestBefore = typeof before.config?.digest === "string" ? before.config.digest : null;
|
|
@@ -8562,35 +9160,43 @@ function describePayloadDiff(before, after, sourceFilesIdentical) {
|
|
|
8562
9160
|
const configurationDiffers = generatorDiffers || digestDiffers || schemaDiffers;
|
|
8563
9161
|
const fingerprintDiffers = before.fingerprint !== after.fingerprint;
|
|
8564
9162
|
const partsDiffer = before.counts.partsCount !== after.counts.partsCount;
|
|
8565
|
-
const partChanges = describePartChanges(before.parts ?? [], after.parts ?? []);
|
|
8566
|
-
const layerChanges = describeLayerChanges(before.layers ?? {}, after.layers ?? {});
|
|
9163
|
+
const partChanges = describePartChanges(before.parts ?? [], after.parts ?? [], secretRules);
|
|
9164
|
+
const layerChanges = describeLayerChanges(before.layers ?? {}, after.layers ?? {}, secretRules);
|
|
8567
9165
|
const reasons = [];
|
|
9166
|
+
const codes = [];
|
|
8568
9167
|
if (schemaDiffers) {
|
|
9168
|
+
codes.push("schema-version");
|
|
8569
9169
|
reasons.push(
|
|
8570
9170
|
`schema version ${schemaBefore} \u2192 ${schemaAfter} (the two manifests describe different formats)`
|
|
8571
9171
|
);
|
|
8572
9172
|
}
|
|
8573
9173
|
if (digestDiffers) {
|
|
9174
|
+
codes.push("config-digest");
|
|
8574
9175
|
reasons.push(
|
|
8575
9176
|
`configuration digest ${shortDigest(digestBefore)} \u2192 ${shortDigest(digestAfter)} (budgets, preview thresholds, redaction rules and artifact selection all count)`
|
|
8576
9177
|
);
|
|
8577
9178
|
} else if (digestBefore === null || digestAfter === null) {
|
|
8578
9179
|
const missing = digestBefore === null && digestAfter !== null ? "before" : digestAfter === null && digestBefore !== null ? "after" : "both";
|
|
9180
|
+
codes.push("config-digest-missing");
|
|
8579
9181
|
reasons.push(
|
|
8580
9182
|
`configuration digest not recorded on the ${missing} side (manifest written before 4.0.5); compared the content fingerprint and part count instead`
|
|
8581
9183
|
);
|
|
8582
9184
|
}
|
|
8583
9185
|
if (generatorDiffers) {
|
|
9186
|
+
codes.push("generator");
|
|
8584
9187
|
reasons.push(`generator ${generatorBefore} \u2192 ${generatorAfter}`);
|
|
8585
9188
|
}
|
|
8586
9189
|
if (fingerprintDiffers && (sourceFilesIdentical || configurationDiffers)) {
|
|
9190
|
+
codes.push("fingerprint");
|
|
8587
9191
|
reasons.push(
|
|
8588
9192
|
`content fingerprint ${shortDigest(before.fingerprint)} \u2192 ${shortDigest(after.fingerprint)}` + (sourceFilesIdentical ? " (same source files, packed or configured differently)" : "")
|
|
8589
9193
|
);
|
|
8590
9194
|
}
|
|
8591
9195
|
if (partsDiffer) {
|
|
9196
|
+
codes.push("parts-count");
|
|
8592
9197
|
reasons.push(`${before.counts.partsCount} part(s) \u2192 ${after.counts.partsCount} part(s)`);
|
|
8593
9198
|
}
|
|
9199
|
+
for (let index = 0; index < layerChanges.length; index += 1) codes.push("layer-changed");
|
|
8594
9200
|
reasons.push(...layerChanges);
|
|
8595
9201
|
return {
|
|
8596
9202
|
sourceFilesIdentical,
|
|
@@ -8602,8 +9208,12 @@ function describePayloadDiff(before, after, sourceFilesIdentical) {
|
|
|
8602
9208
|
partsCount: { before: before.counts.partsCount, after: after.counts.partsCount },
|
|
8603
9209
|
schemaVersion: { before: schemaBefore, after: schemaAfter },
|
|
8604
9210
|
partsManifest: { differs: partChanges.length > 0, changes: partChanges },
|
|
8605
|
-
|
|
8606
|
-
|
|
9211
|
+
// The layer maps are printed and serialized, so a layer named after a project token leaks the
|
|
9212
|
+
// token here even though every reason line above is masked. Found while testing the rules
|
|
9213
|
+
// parameter: masking the prose and not the data it describes is the same bug one layer down.
|
|
9214
|
+
layers: { before: maskLayerNames(before.layers, secretRules), after: maskLayerNames(after.layers, secretRules) },
|
|
9215
|
+
reasons,
|
|
9216
|
+
codes
|
|
8607
9217
|
};
|
|
8608
9218
|
}
|
|
8609
9219
|
function hashMap(manifest) {
|
|
@@ -8642,10 +9252,10 @@ function comparableProblem(value) {
|
|
|
8642
9252
|
function assertUsableManifest(value, label) {
|
|
8643
9253
|
const problem = comparableProblem(value);
|
|
8644
9254
|
if (problem) {
|
|
8645
|
-
throw new Error(`The ${label} manifest is not a snapshot manifest
|
|
9255
|
+
throw new Error(`The ${label} manifest is not a snapshot manifest: ${problem}.`);
|
|
8646
9256
|
}
|
|
8647
9257
|
}
|
|
8648
|
-
function compareManifests(before, after) {
|
|
9258
|
+
function compareManifests(before, after, secretRules) {
|
|
8649
9259
|
assertUsableManifest(before, "before");
|
|
8650
9260
|
assertUsableManifest(after, "after");
|
|
8651
9261
|
const left = hashMap(before);
|
|
@@ -8665,8 +9275,8 @@ function compareManifests(before, after) {
|
|
|
8665
9275
|
}
|
|
8666
9276
|
const sort = (values) => values.sort((a, b) => a < b ? -1 : a > b ? 1 : 0);
|
|
8667
9277
|
const sourceFilesIdentical = added.length === 0 && removed.length === 0 && changed.length === 0;
|
|
8668
|
-
const payload = describePayloadDiff(before, after, sourceFilesIdentical);
|
|
8669
|
-
const mask = (values) => values.map((value) => findSecretInPath(value)?.masked ?? value);
|
|
9278
|
+
const payload = describePayloadDiff(before, after, sourceFilesIdentical, secretRules);
|
|
9279
|
+
const mask = (values) => values.map((value) => findSecretInPath(value, secretRules)?.masked ?? value);
|
|
8670
9280
|
return {
|
|
8671
9281
|
before: side(before),
|
|
8672
9282
|
after: side(after),
|
|
@@ -8700,7 +9310,7 @@ function loadManifest(target) {
|
|
|
8700
9310
|
const problem = describeManifestShapeProblem(parsed);
|
|
8701
9311
|
if (problem) {
|
|
8702
9312
|
throw new Error(
|
|
8703
|
-
`${manifestPath} is not a
|
|
9313
|
+
`${manifestPath} is not a snapshot manifest: ${problem}. Point diff at a manifest.json written by \`generate\` (or at the directory that holds it).`
|
|
8704
9314
|
);
|
|
8705
9315
|
}
|
|
8706
9316
|
return parsed;
|
|
@@ -8847,6 +9457,7 @@ var DEFAULT_ANSWERS = {
|
|
|
8847
9457
|
excludePatterns: [],
|
|
8848
9458
|
artifacts: {
|
|
8849
9459
|
readme: true,
|
|
9460
|
+
prompt: true,
|
|
8850
9461
|
manifest: true,
|
|
8851
9462
|
parts: true,
|
|
8852
9463
|
navigation: true,
|
|
@@ -8955,10 +9566,15 @@ function renderConfig(answers) {
|
|
|
8955
9566
|
// Set true to drop the built-in rules above and keep only customPatterns.
|
|
8956
9567
|
disableDefaultPatterns: false,
|
|
8957
9568
|
},
|
|
9569
|
+
// The library spelling of the same list, accepted here too so a config file can
|
|
9570
|
+
// express what a caller passes in code: an array of { rule, pattern } or a bare
|
|
9571
|
+
// RegExp. Use \`secrets.customPatterns\` above unless you are porting code.
|
|
9572
|
+
// secretRules: [],
|
|
8958
9573
|
|
|
8959
9574
|
// \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
|
|
8960
9575
|
artifacts: {
|
|
8961
9576
|
readme: ${artifacts.readme}, // README.md
|
|
9577
|
+
prompt: ${artifacts.prompt}, // PROMPT.md \u2014 the instruction sheet a model is given
|
|
8962
9578
|
manifest: ${artifacts.manifest}, // manifest.json \u2014 required by validate and report
|
|
8963
9579
|
parts: ${artifacts.parts}, // parts/part-XXX.md
|
|
8964
9580
|
navigation: ${artifacts.navigation}, // reports/navigation.md
|
|
@@ -8974,6 +9590,11 @@ function renderConfig(answers) {
|
|
|
8974
9590
|
includeMonolith: ${artifacts.monolith},
|
|
8975
9591
|
|
|
8976
9592
|
// \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
|
|
9593
|
+
// Files your destination accepts in one message, used by PROMPT.md to plan the delivery.
|
|
9594
|
+
// attachmentSlots: 10,
|
|
9595
|
+
// Experimental: grow the per-part budget until the snapshot fits this many parts, instead of
|
|
9596
|
+
// adding a part as the code grows. The plan in PROMPT.md becomes a fixed-length attachment list.
|
|
9597
|
+
// maxParts: 10,
|
|
8977
9598
|
// afterGenerate: (manifest) => { /* write your own artifact */ }
|
|
8978
9599
|
hooks: {},
|
|
8979
9600
|
};
|
|
@@ -9142,7 +9763,7 @@ function keyReader(input) {
|
|
|
9142
9763
|
next() {
|
|
9143
9764
|
const queued = queue.shift();
|
|
9144
9765
|
if (queued) return Promise.resolve(queued);
|
|
9145
|
-
return new Promise((
|
|
9766
|
+
return new Promise((resolve8) => waiters.push(resolve8));
|
|
9146
9767
|
},
|
|
9147
9768
|
close() {
|
|
9148
9769
|
input.off("keypress", onKey);
|
|
@@ -9571,7 +10192,18 @@ function updatePackageJson(cwd, notes) {
|
|
|
9571
10192
|
writeFileOrExplain(packagePath, serializePackageJson(raw, parsed));
|
|
9572
10193
|
return { scripts: added, dependency };
|
|
9573
10194
|
}
|
|
9574
|
-
|
|
10195
|
+
function gitignoreEntriesFor(cwd, outDir, tmpDir) {
|
|
10196
|
+
const entries = [];
|
|
10197
|
+
for (const directory of [outDir, tmpDir]) {
|
|
10198
|
+
if (directory === null) continue;
|
|
10199
|
+
const relative11 = path16.relative(cwd, path16.resolve(cwd, directory)).replace(/\\/g, "/");
|
|
10200
|
+
if (relative11 === "" || relative11 === "." || relative11.startsWith("..") || path16.isAbsolute(relative11)) {
|
|
10201
|
+
continue;
|
|
10202
|
+
}
|
|
10203
|
+
entries.push(`/${relative11}/`);
|
|
10204
|
+
}
|
|
10205
|
+
return [...new Set(entries)];
|
|
10206
|
+
}
|
|
9575
10207
|
function resolvePresetChoice(detectedName, presetName) {
|
|
9576
10208
|
return {
|
|
9577
10209
|
value: presetName,
|
|
@@ -9653,6 +10285,7 @@ async function runInit(options) {
|
|
|
9653
10285
|
let lastScope = "all";
|
|
9654
10286
|
const artifactChoices = [
|
|
9655
10287
|
{ value: "readme", label: "README.md", hint: "orientation page" },
|
|
10288
|
+
{ value: "prompt", label: "PROMPT.md", hint: "instruction sheet for the model" },
|
|
9656
10289
|
{ value: "manifest", label: "manifest.json", hint: "required by validate and report" },
|
|
9657
10290
|
{ value: "parts", label: "parts/", hint: "the code payload" },
|
|
9658
10291
|
{ value: "navigation", label: "reports/navigation.md", hint: "file \u2192 part index" },
|
|
@@ -9864,7 +10497,10 @@ async function runInit(options) {
|
|
|
9864
10497
|
}
|
|
9865
10498
|
if (!reused) writeFileOrExplain(configPath, configText);
|
|
9866
10499
|
const { scripts, dependency } = updatePackageJson(options.cwd, notes);
|
|
9867
|
-
const ignore = appendGitignoreEntries(
|
|
10500
|
+
const ignore = appendGitignoreEntries(
|
|
10501
|
+
options.cwd,
|
|
10502
|
+
gitignoreEntriesFor(options.cwd, answers.outDir, options.tmpDir ?? (reused ? null : "snapshot.tmp"))
|
|
10503
|
+
);
|
|
9868
10504
|
if (ignore.note !== null) notes.push(ignore.note);
|
|
9869
10505
|
return {
|
|
9870
10506
|
configPath,
|
|
@@ -9882,10 +10518,10 @@ async function runInit(options) {
|
|
|
9882
10518
|
};
|
|
9883
10519
|
}
|
|
9884
10520
|
function describeTarget(cwd) {
|
|
9885
|
-
const
|
|
9886
|
-
if (
|
|
9887
|
-
if (
|
|
9888
|
-
return
|
|
10521
|
+
const relative11 = path16.relative(process.cwd(), cwd);
|
|
10522
|
+
if (relative11 === "") return "this directory";
|
|
10523
|
+
if (relative11.startsWith("..") || path16.isAbsolute(relative11)) return cwd;
|
|
10524
|
+
return relative11;
|
|
9889
10525
|
}
|
|
9890
10526
|
function firstRunMessage(reason, cwd) {
|
|
9891
10527
|
const where = describeTarget(cwd);
|
|
@@ -9987,8 +10623,8 @@ function gitDirectory(cwd) {
|
|
|
9987
10623
|
}
|
|
9988
10624
|
}
|
|
9989
10625
|
function isInside2(parent, child) {
|
|
9990
|
-
const
|
|
9991
|
-
return
|
|
10626
|
+
const relative11 = path16.relative(parent, child);
|
|
10627
|
+
return relative11 === "" || !relative11.startsWith("..") && !path16.isAbsolute(relative11);
|
|
9992
10628
|
}
|
|
9993
10629
|
function isRegisteredWorktree(gitDir, cwd) {
|
|
9994
10630
|
try {
|
|
@@ -10102,7 +10738,20 @@ const { parentPort, workerData } = require("node:worker_threads");
|
|
|
10102
10738
|
// so the run is the documented MCP run rather than the CLI run with one setting removed.
|
|
10103
10739
|
const base = loaded.config ? { ...loaded.config, hooks: {} } : null;
|
|
10104
10740
|
const config = mod.resolveConfig(base, workerData.cliOptions, workerData.cwd);
|
|
10105
|
-
const manifest = mod.generateSnapshot(config);
|
|
10741
|
+
const manifest = mod.generateSnapshot(config, { dryRun: workerData.dryRun === true });
|
|
10742
|
+
const skipCounts = new Map();
|
|
10743
|
+
for (const record of manifest.skipped) {
|
|
10744
|
+
skipCounts.set(record.reason, (skipCounts.get(record.reason) || 0) + 1);
|
|
10745
|
+
}
|
|
10746
|
+
const skipReasons = Array.from(skipCounts.entries())
|
|
10747
|
+
.sort(function (a, b) {
|
|
10748
|
+
if (b[1] !== a[1]) return b[1] - a[1];
|
|
10749
|
+
return a[0] < b[0] ? -1 : a[0] > b[0] ? 1 : 0;
|
|
10750
|
+
})
|
|
10751
|
+
.slice(0, 8)
|
|
10752
|
+
.map(function (entry) {
|
|
10753
|
+
return { reason: entry[0], count: entry[1] };
|
|
10754
|
+
});
|
|
10106
10755
|
parentPort.postMessage({
|
|
10107
10756
|
ok: true,
|
|
10108
10757
|
summary: {
|
|
@@ -10111,7 +10760,11 @@ const { parentPort, workerData } = require("node:worker_threads");
|
|
|
10111
10760
|
skippedCount: manifest.counts.skippedCount,
|
|
10112
10761
|
partsCount: manifest.counts.partsCount,
|
|
10113
10762
|
parts: manifest.parts.map((part) => ({ filename: part.filename, byteSize: part.byteSize })),
|
|
10763
|
+
totalSizeBytes: manifest.counts.totalSizeBytes,
|
|
10114
10764
|
totalContentBytes: manifest.totals.totalContentBytes,
|
|
10765
|
+
preset: manifest.config.preset,
|
|
10766
|
+
layers: manifest.layers,
|
|
10767
|
+
skipReasons: skipReasons,
|
|
10115
10768
|
warnings: manifest.warnings,
|
|
10116
10769
|
},
|
|
10117
10770
|
});
|
|
@@ -10123,15 +10776,15 @@ const { parentPort, workerData } = require("node:worker_threads");
|
|
|
10123
10776
|
}
|
|
10124
10777
|
})();
|
|
10125
10778
|
`;
|
|
10126
|
-
function generateInWorker(cwd, cliOptions) {
|
|
10127
|
-
return new Promise((
|
|
10779
|
+
function generateInWorker(cwd, cliOptions, options = {}) {
|
|
10780
|
+
return new Promise((resolve8) => {
|
|
10128
10781
|
let settled = false;
|
|
10129
10782
|
let worker = null;
|
|
10130
10783
|
const finish = (result) => {
|
|
10131
10784
|
if (settled) return;
|
|
10132
10785
|
settled = true;
|
|
10133
10786
|
if (worker !== null) void worker.terminate();
|
|
10134
|
-
|
|
10787
|
+
resolve8(result);
|
|
10135
10788
|
};
|
|
10136
10789
|
const isCjs = typeof __dirname !== "undefined";
|
|
10137
10790
|
const directory = isCjs ? __dirname : path16.dirname(fileURLToPath(import.meta.url));
|
|
@@ -10141,7 +10794,8 @@ function generateInWorker(cwd, cliOptions) {
|
|
|
10141
10794
|
workerData: {
|
|
10142
10795
|
entryUrl: workerEntry(directory, isCjs).url,
|
|
10143
10796
|
cwd,
|
|
10144
|
-
cliOptions
|
|
10797
|
+
cliOptions,
|
|
10798
|
+
dryRun: options.dryRun === true
|
|
10145
10799
|
}
|
|
10146
10800
|
});
|
|
10147
10801
|
} catch (error) {
|
|
@@ -10326,16 +10980,29 @@ function retain(items, keep) {
|
|
|
10326
10980
|
}
|
|
10327
10981
|
items.length = write;
|
|
10328
10982
|
}
|
|
10329
|
-
function buildIndexes(files, tsconfigPaths) {
|
|
10983
|
+
function buildIndexes(files, tsconfigPaths, skippedSummaryImports = /* @__PURE__ */ new Map()) {
|
|
10330
10984
|
const resolver = buildImportResolver(files, { tsconfig: tsconfigPaths });
|
|
10331
10985
|
const importerCounts = /* @__PURE__ */ new Map();
|
|
10332
|
-
const byFile = files.
|
|
10333
|
-
|
|
10334
|
-
|
|
10335
|
-
|
|
10336
|
-
|
|
10337
|
-
|
|
10338
|
-
|
|
10986
|
+
const byFile = files.flatMap((file) => {
|
|
10987
|
+
if (isSourceSummary(file.summary)) {
|
|
10988
|
+
return [
|
|
10989
|
+
{
|
|
10990
|
+
path: file.relativePath,
|
|
10991
|
+
imports: file.summary.imports,
|
|
10992
|
+
exports: file.summary.exports
|
|
10993
|
+
}
|
|
10994
|
+
];
|
|
10995
|
+
}
|
|
10996
|
+
const imports = skippedSummaryImports.get(file.relativePath);
|
|
10997
|
+
if (imports === void 0) return [];
|
|
10998
|
+
return [
|
|
10999
|
+
{
|
|
11000
|
+
path: file.relativePath,
|
|
11001
|
+
imports,
|
|
11002
|
+
exports: [],
|
|
11003
|
+
exportsOmitted: true
|
|
11004
|
+
}
|
|
11005
|
+
];
|
|
10339
11006
|
});
|
|
10340
11007
|
for (const entry of byFile) {
|
|
10341
11008
|
for (const specifier of entry.imports) {
|
|
@@ -10455,6 +11122,9 @@ function resolveSafeOutputDirs(config) {
|
|
|
10455
11122
|
return { outDir, tmpDir };
|
|
10456
11123
|
}
|
|
10457
11124
|
var IGNORABLE_ENTRIES = /* @__PURE__ */ new Set([".DS_Store"]);
|
|
11125
|
+
function isIgnorableEntry(entry) {
|
|
11126
|
+
return IGNORABLE_ENTRIES.has(entry.slice(entry.lastIndexOf("/") + 1));
|
|
11127
|
+
}
|
|
10458
11128
|
var RUN_DIR_PREFIX = "run-";
|
|
10459
11129
|
var STALE_RUN_MS = 60 * 60 * 1e3;
|
|
10460
11130
|
function maskSummaryStrings(value, secretRules) {
|
|
@@ -10497,9 +11167,9 @@ function listEntries(dir) {
|
|
|
10497
11167
|
return;
|
|
10498
11168
|
}
|
|
10499
11169
|
for (const child of children) {
|
|
10500
|
-
const
|
|
10501
|
-
entries.push(
|
|
10502
|
-
if (child.isDirectory()) walk(path16.join(absolute, child.name),
|
|
11170
|
+
const relative11 = prefix === "" ? child.name : `${prefix}/${child.name}`;
|
|
11171
|
+
entries.push(relative11);
|
|
11172
|
+
if (child.isDirectory()) walk(path16.join(absolute, child.name), relative11);
|
|
10503
11173
|
}
|
|
10504
11174
|
};
|
|
10505
11175
|
walk(dir, "");
|
|
@@ -10510,7 +11180,7 @@ function markerInventory(dir, written) {
|
|
|
10510
11180
|
const files = [];
|
|
10511
11181
|
for (const entry of entries) {
|
|
10512
11182
|
if (entry === OWNERSHIP_MARKER) continue;
|
|
10513
|
-
if (
|
|
11183
|
+
if (isIgnorableEntry(entry)) continue;
|
|
10514
11184
|
const full = path16.join(dir, ...entry.split("/"));
|
|
10515
11185
|
let stats;
|
|
10516
11186
|
try {
|
|
@@ -10799,7 +11469,7 @@ function assessSnapshotDirectory(dir) {
|
|
|
10799
11469
|
}
|
|
10800
11470
|
const entries = listEntries(dir);
|
|
10801
11471
|
const foreignEntries = entries.filter(
|
|
10802
|
-
(entry) => !recorded.has(entry) && !
|
|
11472
|
+
(entry) => !recorded.has(entry) && !isIgnorableEntry(entry)
|
|
10803
11473
|
);
|
|
10804
11474
|
if (foreignEntries.length > 0) {
|
|
10805
11475
|
return { owned: false, problem: null, foreignEntries, marker: marker2 };
|
|
@@ -11255,7 +11925,55 @@ function runAfterGenerate(config, manifest) {
|
|
|
11255
11925
|
return Promise.resolve(returned).finally(releaseRedirect);
|
|
11256
11926
|
}
|
|
11257
11927
|
function partitionByBudget(files, config, fingerprint) {
|
|
11258
|
-
const
|
|
11928
|
+
const configured = {
|
|
11929
|
+
parts: partitionWithBudgets(files, config.budgets, fingerprint),
|
|
11930
|
+
budgets: config.budgets,
|
|
11931
|
+
maxPartBytes: config.maxPartBytes,
|
|
11932
|
+
warnings: []
|
|
11933
|
+
};
|
|
11934
|
+
const limit = config.maxParts;
|
|
11935
|
+
if (limit === null || !config.artifacts.parts || configured.parts.length <= limit) return configured;
|
|
11936
|
+
const totalBytes = files.reduce((total, file) => total + file.includedBytes, 0);
|
|
11937
|
+
let target = Math.max(config.budgets.default, Math.ceil(totalBytes * 1.15 / limit));
|
|
11938
|
+
const seen = [];
|
|
11939
|
+
let low = config.budgets.default;
|
|
11940
|
+
let fitting = null;
|
|
11941
|
+
for (let pass = 0; pass < 6; pass += 1) {
|
|
11942
|
+
const parts2 = partitionWithBudgets(files, scaleBudgets(config.budgets, target), fingerprint);
|
|
11943
|
+
if (parts2.length <= limit) {
|
|
11944
|
+
fitting = { target, parts: parts2 };
|
|
11945
|
+
break;
|
|
11946
|
+
}
|
|
11947
|
+
seen.push(parts2.length);
|
|
11948
|
+
low = target;
|
|
11949
|
+
target = Math.ceil(target * 1.3);
|
|
11950
|
+
}
|
|
11951
|
+
if (fitting === null) {
|
|
11952
|
+
throw new Error(
|
|
11953
|
+
`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.`
|
|
11954
|
+
);
|
|
11955
|
+
}
|
|
11956
|
+
for (let step = 0; step < 3 && fitting.target - low > 8192; step += 1) {
|
|
11957
|
+
const middle = Math.round((low + fitting.target) / 2);
|
|
11958
|
+
const parts2 = partitionWithBudgets(files, scaleBudgets(config.budgets, middle), fingerprint);
|
|
11959
|
+
if (parts2.length <= limit) fitting = { target: middle, parts: parts2 };
|
|
11960
|
+
else low = middle;
|
|
11961
|
+
}
|
|
11962
|
+
const { target: chosen, parts } = fitting;
|
|
11963
|
+
const budgets = scaleBudgets(config.budgets, chosen);
|
|
11964
|
+
const maxPartBytes = Math.max(config.maxPartBytes, chosen);
|
|
11965
|
+
const warnings = [
|
|
11966
|
+
`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).`
|
|
11967
|
+
];
|
|
11968
|
+
if (maxPartBytes > config.maxPartBytes) {
|
|
11969
|
+
warnings.push(
|
|
11970
|
+
`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.`
|
|
11971
|
+
);
|
|
11972
|
+
}
|
|
11973
|
+
return { parts, budgets, maxPartBytes, warnings };
|
|
11974
|
+
}
|
|
11975
|
+
function partitionWithBudgets(files, budgets, fingerprint) {
|
|
11976
|
+
const budgetFor = (file) => budgets.byLayer[file.layer] ?? budgets.default;
|
|
11259
11977
|
const buckets = /* @__PURE__ */ new Map();
|
|
11260
11978
|
for (const file of files) {
|
|
11261
11979
|
const budget = budgetFor(file);
|
|
@@ -11272,6 +11990,18 @@ function partitionByBudget(files, config, fingerprint) {
|
|
|
11272
11990
|
fingerprint
|
|
11273
11991
|
);
|
|
11274
11992
|
}
|
|
11993
|
+
function scaleBudgets(budgets, targetDefault) {
|
|
11994
|
+
const factor = targetDefault / budgets.default;
|
|
11995
|
+
return {
|
|
11996
|
+
default: Math.max(budgets.default, Math.round(targetDefault)),
|
|
11997
|
+
byLayer: Object.fromEntries(
|
|
11998
|
+
Object.entries(budgets.byLayer).map(([name, bytes]) => [
|
|
11999
|
+
name,
|
|
12000
|
+
Math.max(bytes, Math.round(bytes * factor))
|
|
12001
|
+
])
|
|
12002
|
+
)
|
|
12003
|
+
};
|
|
12004
|
+
}
|
|
11275
12005
|
function generateSnapshot(configInput, options) {
|
|
11276
12006
|
assertUsableConfigInput(configInput);
|
|
11277
12007
|
const config = isResolvedConfig(configInput) ? normalizeResolvedConfig(configInput) : resolveConfig(configInput ?? null);
|
|
@@ -11295,7 +12025,7 @@ function generateSnapshot(configInput, options) {
|
|
|
11295
12025
|
// output — but only at these exact paths, not at every directory that shares the name.
|
|
11296
12026
|
toolOwnedPaths: [config.outDir, config.tmpDir].map(
|
|
11297
12027
|
(directory) => path16.relative(config.cwd, path16.resolve(config.cwd, directory)).replace(/\\/g, "/")
|
|
11298
|
-
).filter((
|
|
12028
|
+
).filter((relative11) => relative11.length > 0 && !relative11.startsWith("..")),
|
|
11299
12029
|
// A staged path can be absent from the working tree while its index blob exists. Discovery
|
|
11300
12030
|
// lists the working tree, so those paths would never reach the scan at all.
|
|
11301
12031
|
...stagedPaths.size > 0 ? { extraPaths: [...stagedPaths] } : {}
|
|
@@ -11600,7 +12330,8 @@ function generateSnapshot(configInput, options) {
|
|
|
11600
12330
|
);
|
|
11601
12331
|
}
|
|
11602
12332
|
}
|
|
11603
|
-
const
|
|
12333
|
+
const partitioned = partitionByBudget(files, config, fingerprint);
|
|
12334
|
+
const parts = partitioned.parts;
|
|
11604
12335
|
const truncatedPreviewCount = files.filter((file) => file.isPreviewTruncated).length;
|
|
11605
12336
|
const incomplete = files.flatMap((file) => {
|
|
11606
12337
|
if (file.truncationReason === void 0) return [];
|
|
@@ -11637,7 +12368,10 @@ function generateSnapshot(configInput, options) {
|
|
|
11637
12368
|
// the README and the audit report.
|
|
11638
12369
|
git: { ...gitInfo, branch: maskPathText(gitInfo.branch, config.secretRules) },
|
|
11639
12370
|
budgets: {
|
|
11640
|
-
|
|
12371
|
+
// The ceiling the parts actually honour. It equals the configured one unless `maxParts`
|
|
12372
|
+
// grew it; `config.maxPartBytes` below keeps the configured value, because that is what
|
|
12373
|
+
// `validate` compares against the config on disk.
|
|
12374
|
+
maxPartBytes: partitioned.maxPartBytes,
|
|
11641
12375
|
largeFileBytes: config.largeFileBytes
|
|
11642
12376
|
},
|
|
11643
12377
|
config: {
|
|
@@ -11655,6 +12389,14 @@ function generateSnapshot(configInput, options) {
|
|
|
11655
12389
|
// invisible in the manifest that is supposed to describe the run.
|
|
11656
12390
|
maxMonolithBytes: config.maxMonolithBytes ?? null,
|
|
11657
12391
|
includeSensitiveFiles: config.includeSensitiveFiles,
|
|
12392
|
+
// The destination the instructions were written for. Not part of `digest`: the payload is
|
|
12393
|
+
// identical whatever this says, and a new delivery preference must not make an existing
|
|
12394
|
+
// snapshot fail `validate` as configuration drift.
|
|
12395
|
+
attachmentSlots: config.attachmentSlots,
|
|
12396
|
+
// The part-count ceiling the run enforced. Recorded because it decided the part sizes, and
|
|
12397
|
+
// omitted from `digest` when it is off so an existing snapshot does not start reporting
|
|
12398
|
+
// configuration drift.
|
|
12399
|
+
maxParts: config.maxParts ?? null,
|
|
11658
12400
|
discovery: config.discovery ?? "auto",
|
|
11659
12401
|
// A changed-files scope decides which files are in the snapshot, so the manifest that
|
|
11660
12402
|
// describes the run has to name it.
|
|
@@ -11715,7 +12457,7 @@ function generateSnapshot(configInput, options) {
|
|
|
11715
12457
|
},
|
|
11716
12458
|
layers: layerCounts,
|
|
11717
12459
|
kinds: kindCounts,
|
|
11718
|
-
indexes: buildIndexes(files, tsconfigPathsFor(config.cwd)),
|
|
12460
|
+
indexes: buildIndexes(files, tsconfigPathsFor(config.cwd), skippedSummaryImports),
|
|
11719
12461
|
parts: parts.map((part) => part.metadata),
|
|
11720
12462
|
files: files.map((file) => {
|
|
11721
12463
|
const { content: _content, ...rest } = file;
|
|
@@ -11725,6 +12467,10 @@ function generateSnapshot(configInput, options) {
|
|
|
11725
12467
|
incomplete,
|
|
11726
12468
|
warnings
|
|
11727
12469
|
};
|
|
12470
|
+
if (partitioned.warnings.length > 0) {
|
|
12471
|
+
manifest.warnings.push(...partitioned.warnings);
|
|
12472
|
+
manifest.totals.warningCount = manifest.warnings.length;
|
|
12473
|
+
}
|
|
11728
12474
|
manifest.totals.redactedLines = secretFindings.length;
|
|
11729
12475
|
manifest.totals.warningCount = manifest.warnings.length;
|
|
11730
12476
|
if (files.some((file) => file.isPreviewTruncated) && config.largeFileBytes < config.maxPartBytes) {
|
|
@@ -11757,11 +12503,9 @@ function generateSnapshot(configInput, options) {
|
|
|
11757
12503
|
let projectTree = null;
|
|
11758
12504
|
if (config.artifacts.projectTree) {
|
|
11759
12505
|
projectTree = generateProjectTree(files.map((file) => file.relativePath));
|
|
11760
|
-
const
|
|
11761
|
-
if (
|
|
11762
|
-
manifest.warnings.push(
|
|
11763
|
-
`reports/project-tree.md was truncated at the ${depthMarker[1]}-level depth cap: deeper directories are not listed there.`
|
|
11764
|
-
);
|
|
12506
|
+
const truncations = treeTruncationWarnings(projectTree);
|
|
12507
|
+
if (truncations.length > 0) {
|
|
12508
|
+
manifest.warnings.push(...truncations);
|
|
11765
12509
|
manifest.totals.warningCount = manifest.warnings.length;
|
|
11766
12510
|
}
|
|
11767
12511
|
}
|
|
@@ -11783,13 +12527,22 @@ function generateSnapshot(configInput, options) {
|
|
|
11783
12527
|
if (auditText !== null) manifest.artifacts.audit = artifactRecord(auditText);
|
|
11784
12528
|
const readmeText = artifacts.readme ? generateReadme(manifest, artifacts) : null;
|
|
11785
12529
|
if (readmeText !== null) manifest.artifacts.readme = artifactRecord(readmeText);
|
|
12530
|
+
const promptText = artifacts.prompt ? generatePrompt(
|
|
12531
|
+
manifest,
|
|
12532
|
+
artifacts,
|
|
12533
|
+
config.attachmentSlots,
|
|
12534
|
+
// Commit subjects are user input and reach an artifact, so they go through the same
|
|
12535
|
+
// masking as every other name the run reproduces.
|
|
12536
|
+
recentCommitSubjects(config.cwd).map((subject) => maskPathText(subject, config.secretRules))
|
|
12537
|
+
) : null;
|
|
12538
|
+
if (promptText !== null) manifest.artifacts.prompt = artifactRecord(promptText);
|
|
11786
12539
|
if (projectTree !== null) manifest.artifacts.projectTree = artifactRecord(projectTree);
|
|
11787
12540
|
let monolithJson = null;
|
|
11788
12541
|
let monolithMarkdown = null;
|
|
11789
12542
|
if (config.includeMonolith) {
|
|
11790
12543
|
const fullFiles = files.map((file) => {
|
|
11791
12544
|
const content = fullContents.get(file.relativePath) ?? "";
|
|
11792
|
-
|
|
12545
|
+
const entry = {
|
|
11793
12546
|
...file,
|
|
11794
12547
|
content,
|
|
11795
12548
|
inclusionMode: "full",
|
|
@@ -11797,6 +12550,9 @@ function generateSnapshot(configInput, options) {
|
|
|
11797
12550
|
includedBytes: Buffer.byteLength(content, "utf8"),
|
|
11798
12551
|
includedLines: countLines(content)
|
|
11799
12552
|
};
|
|
12553
|
+
delete entry.truncationReason;
|
|
12554
|
+
delete entry.omittedRanges;
|
|
12555
|
+
return entry;
|
|
11800
12556
|
});
|
|
11801
12557
|
const bodyBytes = fullFiles.reduce((total, file) => total + file.includedBytes, 0);
|
|
11802
12558
|
const definitelyTooLarge = config.maxMonolithBytes !== null && bodyBytes > config.maxMonolithBytes;
|
|
@@ -11917,6 +12673,9 @@ function generateSnapshot(configInput, options) {
|
|
|
11917
12673
|
if (readmeText !== null) {
|
|
11918
12674
|
writeArtifact(stagingDir, "README.md", readmeText);
|
|
11919
12675
|
}
|
|
12676
|
+
if (promptText !== null) {
|
|
12677
|
+
writeArtifact(stagingDir, "PROMPT.md", promptText);
|
|
12678
|
+
}
|
|
11920
12679
|
if (artifacts.manifest) {
|
|
11921
12680
|
writeArtifact(stagingDir, "manifest.json", JSON.stringify(manifest, null, 2));
|
|
11922
12681
|
}
|
|
@@ -12005,4 +12764,4 @@ async function generateSnapshotAsync(configInput, options) {
|
|
|
12005
12764
|
return manifest;
|
|
12006
12765
|
}
|
|
12007
12766
|
|
|
12008
|
-
export { ARTIFACT_NAMES, CHECK_INTERVAL_MS, CONFIG_KEYS, DEFAULT_ANSWERS, DEFAULT_SECRET_PATTERNS, FAILURE_INTERVAL_MS, GENERATOR_NAME, GENERATOR_VERSION, HOOK_MARKER, LANGUAGE_PROFILES, MIN_MAX_PART_BYTES, MIN_MAX_PART_TOKENS, PACKAGE_LATEST_URL, PRESETS, PromptBack, PromptCancelled, REQUEST_TIMEOUT_MS, SCHEMA_VERSION, UP_TO_DATE_INTERVAL_MS, anchorForPath, appendGitignoreEntries, assertReplaceable, assertUsableConfigInput, buildImportResolver, bytesForTokens, cacheDirectory, cacheFilePath, checkForUpdate, classifyKind, classifyLayer, collectFiles, compareManifests, configDigest, countInvalidUtf8Bytes, countLines, decodeText, defaultIO, defineConfig, describeManifestShapeProblem, detectLanguage, detectPreset, displayPath, displayWidth, enforceBudget, escapeControls, estimateTokens, explainPath, fenceForContent, fenceForText, fetchLatestVersion, findConfigFile, findSecretInPath, firstRunMessage, formatNumber, formatTokens, formatUpdateNotice, generateInWorker, generateProjectTree, generateSarifReport, generateSnapshot, generateSnapshotAsync, getGitInfo, getPreset, gitignorePath, globToRegExp, hasPriorSnapshot, importsChangedFile, importsOfFile, importsOfText, installKind, installPreCommitHook, isBinaryBuffer, isBinaryExtension, isBinaryFile, isDiscoveryMode, isEffectivelyEmpty, isInteractive, isNewer, isResolvedConfig, isSensitivePath, isSkeletonizable, isTsxFileName, listPresetNames, loadConfigFile, loadConfigFileDetailed, loadManifest, lockPathFor, markResolvedConfig, matchRule, matchesExclude, normalizeResolvedConfig, parseByteSize, partitionFiles, planFirstRun, profileForPath, renderConfig, renderDiffText, renderExplainText, renumberParts, resolveChangedScope, resolveConfig, resolveSafeOutputDirs, resolveSpecifier, runInit, runWithStdoutCapture, scanAndRedactSecrets, shouldCheck, skeletonizeTypeScript, stripJsonComments, summarizeJson, summarizeMarkdown, summarizeTypeScriptSource, summarizeWithProfile, supportsTypeScriptImports, truncatePreview, truncateToBytes, tsconfigPathsFor, unknownPresetMessage, updateCommand, validateSnapshot, workerEntry, wrapLines };
|
|
12767
|
+
export { ARTIFACT_NAMES, CHECK_INTERVAL_MS, CONFIG_KEYS, DEFAULT_ANSWERS, DEFAULT_SECRET_PATTERNS, FAILURE_INTERVAL_MS, GENERATOR_NAME, GENERATOR_VERSION, HOOK_MARKER, LANGUAGE_PROFILES, MIN_MAX_PART_BYTES, MIN_MAX_PART_TOKENS, PACKAGE_LATEST_URL, PRESETS, PromptBack, PromptCancelled, REQUEST_TIMEOUT_MS, SCHEMA_VERSION, UP_TO_DATE_INTERVAL_MS, anchorForPath, appendGitignoreEntries, assertReplaceable, assertUsableConfigInput, buildImportResolver, bytesForTokens, cacheDirectory, cacheFilePath, checkForUpdate, classifyKind, classifyLayer, collectFiles, compareManifests, configDigest, countInvalidUtf8Bytes, countLines, decodeText, defaultIO, defineConfig, describeManifestShapeProblem, detectLanguage, detectPreset, displayPath, displayWidth, enforceBudget, escapeControls, estimateTokens, explainPath, fenceForContent, fenceForText, fetchLatestVersion, findConfigFile, findSecretInPath, firstRunMessage, formatNumber, formatTokens, formatUpdateNotice, generateInWorker, generateProjectTree, generateSarifReport, generateSnapshot, generateSnapshotAsync, getGitInfo, getPreset, gitignorePath, globToRegExp, hasPriorSnapshot, importsChangedFile, importsOfFile, importsOfText, installKind, installPreCommitHook, isBinaryBuffer, isBinaryExtension, isBinaryFile, isDiscoveryMode, isEffectivelyEmpty, isInteractive, isNewer, isResolvedConfig, isSensitivePath, isSkeletonizable, isTsxFileName, listPresetNames, loadConfigFile, loadConfigFileDetailed, loadManifest, lockPathFor, markResolvedConfig, matchRule, matchesExclude, normalizeResolvedConfig, parseByteSize, partitionFiles, planFirstRun, profileForPath, renderConfig, renderDiffText, renderExplainText, renumberParts, resolveChangedScope, resolveConfig, resolveSafeOutputDirs, resolveSpecifier, runInit, runWithStdoutCapture, scanAndRedactSecrets, shouldCheck, skeletonizeTypeScript, stripJsonComments, summarizeJson, summarizeMarkdown, summarizeTypeScriptSource, summarizeWithProfile, supportsTypeScriptImports, treeTruncationWarnings, truncatePreview, truncateToBytes, tsconfigPathsFor, unknownPresetMessage, updateCommand, validateSnapshot, workerEntry, wrapLines };
|