codebase-snapshot 0.10.1 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +130 -0
- package/README.md +9 -1
- package/SECURITY.md +2 -2
- package/dist/bin.js +1247 -413
- package/dist/{chunk-WDJ3O3R4.js → chunk-5ZOXHBTW.js} +53 -30
- package/dist/{chunk-7DAW2LFZ.js → chunk-NJ75RVHO.js} +939 -180
- package/dist/cli.cjs +1246 -411
- package/dist/cli.d.cts +36 -11
- package/dist/cli.d.ts +36 -11
- package/dist/cli.js +60 -8
- package/dist/{generate-worker-D_mUjgXw.d.cts → generate-worker-BK4uJx7Z.d.cts} +17 -8
- package/dist/{generate-worker-D_mUjgXw.d.ts → generate-worker-BK4uJx7Z.d.ts} +17 -8
- package/dist/index.cjs +915 -173
- package/dist/index.d.cts +69 -24
- package/dist/index.d.ts +69 -24
- package/dist/index.js +1 -1
- package/dist/mcp.cjs +745 -2923
- package/dist/mcp.d.cts +1 -1
- package/dist/mcp.d.ts +1 -1
- package/dist/mcp.js +2 -2
- package/dist/{types-Z471HW65.d.cts → types-DGWw3SH2.d.cts} +75 -4
- package/dist/{types-Z471HW65.d.ts → types-DGWw3SH2.d.ts} +75 -4
- package/docs/cli.md +32 -8
- package/docs/codebase-token-budget.md +12 -9
- package/docs/configuration.md +71 -2
- package/docs/how-to-context-budget.md +1 -1
- package/docs/how-to-feed-a-repo-to-claude.md +40 -9
- package/docs/mcp.md +3 -3
- package/docs/output.md +60 -7
- package/docs/stale-context-is-your-bug.md +8 -4
- package/docs/vs-code2prompt.md +1 -1
- package/docs/vs-gitingest.md +1 -1
- package/docs/vs-repomix.md +1 -1
- package/package.json +1 -1
package/dist/bin.js
CHANGED
|
@@ -167,8 +167,8 @@ function workspacePackageDirs(cwd, patterns) {
|
|
|
167
167
|
function scanWorkspacePackages(cwd, patterns) {
|
|
168
168
|
const files = /* @__PURE__ */ new Set();
|
|
169
169
|
const dependencies = /* @__PURE__ */ new Set();
|
|
170
|
-
for (const
|
|
171
|
-
const full = path.join(cwd,
|
|
170
|
+
for (const relative15 of workspacePackageDirs(cwd, patterns)) {
|
|
171
|
+
const full = path.join(cwd, relative15);
|
|
172
172
|
try {
|
|
173
173
|
for (const entry of fs.readdirSync(full, { withFileTypes: true })) files.add(entry.name);
|
|
174
174
|
} catch {
|
|
@@ -1287,6 +1287,24 @@ var DEFAULT_SECRET_PATTERNS = [
|
|
|
1287
1287
|
),
|
|
1288
1288
|
valueGroup: 2
|
|
1289
1289
|
},
|
|
1290
|
+
{
|
|
1291
|
+
// A quoted assignment whose closing quote is **not on this line**.
|
|
1292
|
+
//
|
|
1293
|
+
// The rule above requires `\1`, so an unterminated literal never matched it and the
|
|
1294
|
+
// credential reached the artefact in clear with no finding at all. That is the shape a
|
|
1295
|
+
// truncated file, a hand-edited `.env` and a string that continues on the next line all
|
|
1296
|
+
// produce, and it was the only branch of the redaction pass that was silent.
|
|
1297
|
+
//
|
|
1298
|
+
// The value runs to the end of the line on purpose — there is no delimiter to stop at — and
|
|
1299
|
+
// a later quote of the same kind disables the rule (`(?!\1)`), so a balanced literal is
|
|
1300
|
+
// never matched here: `password: "abc" and "def"` belongs to the rule above.
|
|
1301
|
+
rule: "credential-assignment-unterminated",
|
|
1302
|
+
pattern: new RegExp(
|
|
1303
|
+
`(?:${QUOTED_CREDENTIAL_KEY}|${NOT_AFTER_QUOTE}(?<!id[-_])${STRONG_CREDENTIAL_NAME})\\s{0,8}${ASSIGN}\\s{0,8}(["'\`])((?:(?!\\1)[^\\\\\\n]|\\\\.){1,512})$`,
|
|
1304
|
+
"i"
|
|
1305
|
+
),
|
|
1306
|
+
valueGroup: 2
|
|
1307
|
+
},
|
|
1290
1308
|
{
|
|
1291
1309
|
// `pass` and `credentials` are ambiguous on their own, so they
|
|
1292
1310
|
// are accepted only against a quoted value long enough to be a credential.
|
|
@@ -1846,10 +1864,8 @@ function scanAndRedactSecrets(content, rules, filePath) {
|
|
|
1846
1864
|
}
|
|
1847
1865
|
if (spans.length > 0) {
|
|
1848
1866
|
const maskedLine = applySpans(line, spans);
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
segments[index] = maskedLine;
|
|
1852
|
-
}
|
|
1867
|
+
recordFinding(lineNumber, matchedRules);
|
|
1868
|
+
segments[index] = !quotesAreBalanced(line) || quotesAreBalanced(maskedLine) ? maskedLine : applySpansKeepingQuotes(line, spans);
|
|
1853
1869
|
}
|
|
1854
1870
|
}
|
|
1855
1871
|
if (index + 1 < segments.length) lineNumber += 1;
|
|
@@ -2127,6 +2143,17 @@ function isDeclaredBinding(line, matchIndex, filePath) {
|
|
|
2127
2143
|
return DECLARATION_KEYWORDS.test(line.slice(from, runStart));
|
|
2128
2144
|
}
|
|
2129
2145
|
function applySpans(line, spans) {
|
|
2146
|
+
let out = "";
|
|
2147
|
+
let cursor = 0;
|
|
2148
|
+
for (const span of mergedSpans(line, spans)) {
|
|
2149
|
+
out += line.slice(cursor, span.start);
|
|
2150
|
+
out += REDACTION_MARKER;
|
|
2151
|
+
cursor = span.end;
|
|
2152
|
+
}
|
|
2153
|
+
out += line.slice(cursor);
|
|
2154
|
+
return out;
|
|
2155
|
+
}
|
|
2156
|
+
function mergedSpans(line, spans) {
|
|
2130
2157
|
const ordered = [...spans].sort((a, b) => a.start - b.start || a.end - b.end);
|
|
2131
2158
|
const merged = [];
|
|
2132
2159
|
for (const span of ordered) {
|
|
@@ -2137,11 +2164,25 @@ function applySpans(line, spans) {
|
|
|
2137
2164
|
if (last && start <= last.end) last.end = Math.max(last.end, end);
|
|
2138
2165
|
else merged.push({ start, end });
|
|
2139
2166
|
}
|
|
2167
|
+
return merged;
|
|
2168
|
+
}
|
|
2169
|
+
function applySpansKeepingQuotes(line, spans) {
|
|
2140
2170
|
let out = "";
|
|
2141
2171
|
let cursor = 0;
|
|
2142
|
-
for (const span of
|
|
2172
|
+
for (const span of mergedSpans(line, spans)) {
|
|
2143
2173
|
out += line.slice(cursor, span.start);
|
|
2144
|
-
|
|
2174
|
+
let run = false;
|
|
2175
|
+
for (let index = span.start; index < span.end; index += 1) {
|
|
2176
|
+
const char = line[index];
|
|
2177
|
+
if (char === '"' || char === "'" || char === "`" || char === "\\") {
|
|
2178
|
+
if (run) out += REDACTION_MARKER;
|
|
2179
|
+
run = false;
|
|
2180
|
+
out += char;
|
|
2181
|
+
continue;
|
|
2182
|
+
}
|
|
2183
|
+
run = true;
|
|
2184
|
+
}
|
|
2185
|
+
if (run) out += REDACTION_MARKER;
|
|
2145
2186
|
cursor = span.end;
|
|
2146
2187
|
}
|
|
2147
2188
|
out += line.slice(cursor);
|
|
@@ -2150,7 +2191,7 @@ function applySpans(line, spans) {
|
|
|
2150
2191
|
|
|
2151
2192
|
// src/version.ts
|
|
2152
2193
|
var GENERATOR_NAME = "codebase-snapshot";
|
|
2153
|
-
var GENERATOR_VERSION = "0.
|
|
2194
|
+
var GENERATOR_VERSION = "0.11.0";
|
|
2154
2195
|
var SCHEMA_VERSION = "3.0.0";
|
|
2155
2196
|
var LEGACY_GENERATOR_NAMES = ["@ankurhalder/codebase-snapshot"];
|
|
2156
2197
|
function isOurGeneratorName(name) {
|
|
@@ -2182,8 +2223,8 @@ function brokenLinkRecord(linkPath, relativePath, rootReal) {
|
|
|
2182
2223
|
};
|
|
2183
2224
|
}
|
|
2184
2225
|
function isInside(root, candidate) {
|
|
2185
|
-
const
|
|
2186
|
-
return
|
|
2226
|
+
const relative15 = path2.relative(root, candidate);
|
|
2227
|
+
return relative15 === "" || !relative15.startsWith(`..${path2.sep}`) && relative15 !== ".." && !path2.isAbsolute(relative15);
|
|
2187
2228
|
}
|
|
2188
2229
|
var GIT_OUTPUT_LIMIT = 68157440;
|
|
2189
2230
|
function getGitInfo(cwd, fallbackBranch = "main") {
|
|
@@ -2598,6 +2639,23 @@ function defaultIgnoreReason(relativePath, toolDirNames = DEFAULT_TOOL_DIR_NAMES
|
|
|
2598
2639
|
}
|
|
2599
2640
|
return null;
|
|
2600
2641
|
}
|
|
2642
|
+
function recentCommitSubjects(cwd, limit = 10) {
|
|
2643
|
+
try {
|
|
2644
|
+
const stdout = childProcess.execFileSync(
|
|
2645
|
+
"git",
|
|
2646
|
+
["log", "-n", String(limit), "--pretty=%s", "--no-color"],
|
|
2647
|
+
{
|
|
2648
|
+
cwd,
|
|
2649
|
+
stdio: ["ignore", "pipe", "ignore"],
|
|
2650
|
+
encoding: "utf8",
|
|
2651
|
+
maxBuffer: GIT_OUTPUT_LIMIT
|
|
2652
|
+
}
|
|
2653
|
+
);
|
|
2654
|
+
return stdout.split("\n").map((line) => line.trim()).filter((line) => line.length > 0);
|
|
2655
|
+
} catch {
|
|
2656
|
+
return [];
|
|
2657
|
+
}
|
|
2658
|
+
}
|
|
2601
2659
|
function listIgnoredPaths(cwd) {
|
|
2602
2660
|
try {
|
|
2603
2661
|
const stdout = childProcess.execFileSync(
|
|
@@ -3046,6 +3104,178 @@ import { createRequire } from "module";
|
|
|
3046
3104
|
import * as path3 from "path";
|
|
3047
3105
|
import { pathToFileURL } from "url";
|
|
3048
3106
|
|
|
3107
|
+
// src/ast/structured.ts
|
|
3108
|
+
function stripJsonComments(content) {
|
|
3109
|
+
const text2 = content.replace(/^\uFEFF/, "");
|
|
3110
|
+
const withoutComments = stripComments(text2);
|
|
3111
|
+
return stripTrailingCommas(withoutComments);
|
|
3112
|
+
}
|
|
3113
|
+
function stripComments(text2) {
|
|
3114
|
+
let out = "";
|
|
3115
|
+
let inString = false;
|
|
3116
|
+
let escaped = false;
|
|
3117
|
+
for (let index = 0; index < text2.length; index += 1) {
|
|
3118
|
+
const char = text2[index];
|
|
3119
|
+
if (inString) {
|
|
3120
|
+
out += char;
|
|
3121
|
+
if (escaped) escaped = false;
|
|
3122
|
+
else if (char === "\\") escaped = true;
|
|
3123
|
+
else if (char === '"') inString = false;
|
|
3124
|
+
continue;
|
|
3125
|
+
}
|
|
3126
|
+
if (char === '"') {
|
|
3127
|
+
inString = true;
|
|
3128
|
+
out += char;
|
|
3129
|
+
continue;
|
|
3130
|
+
}
|
|
3131
|
+
if (char === "/" && text2[index + 1] === "/") {
|
|
3132
|
+
while (index < text2.length && text2[index] !== "\n" && text2[index] !== "\r") index += 1;
|
|
3133
|
+
index -= 1;
|
|
3134
|
+
continue;
|
|
3135
|
+
}
|
|
3136
|
+
if (char === "/" && text2[index + 1] === "*") {
|
|
3137
|
+
index += 2;
|
|
3138
|
+
while (index < text2.length && !(text2[index] === "*" && text2[index + 1] === "/")) {
|
|
3139
|
+
if (text2[index] === "\n" || text2[index] === "\r") out += text2[index];
|
|
3140
|
+
index += 1;
|
|
3141
|
+
}
|
|
3142
|
+
index += 1;
|
|
3143
|
+
continue;
|
|
3144
|
+
}
|
|
3145
|
+
out += char;
|
|
3146
|
+
}
|
|
3147
|
+
return out;
|
|
3148
|
+
}
|
|
3149
|
+
function stripTrailingCommas(text2) {
|
|
3150
|
+
let out = "";
|
|
3151
|
+
let inString = false;
|
|
3152
|
+
let escaped = false;
|
|
3153
|
+
for (let index = 0; index < text2.length; index += 1) {
|
|
3154
|
+
const char = text2[index];
|
|
3155
|
+
if (inString) {
|
|
3156
|
+
out += char;
|
|
3157
|
+
if (escaped) escaped = false;
|
|
3158
|
+
else if (char === "\\") escaped = true;
|
|
3159
|
+
else if (char === '"') inString = false;
|
|
3160
|
+
continue;
|
|
3161
|
+
}
|
|
3162
|
+
if (char === '"') {
|
|
3163
|
+
inString = true;
|
|
3164
|
+
out += char;
|
|
3165
|
+
continue;
|
|
3166
|
+
}
|
|
3167
|
+
if (char === ",") {
|
|
3168
|
+
let next = index + 1;
|
|
3169
|
+
while (next < text2.length && /\s/.test(text2[next])) next += 1;
|
|
3170
|
+
if (text2[next] === "}" || text2[next] === "]") continue;
|
|
3171
|
+
}
|
|
3172
|
+
out += char;
|
|
3173
|
+
}
|
|
3174
|
+
return out;
|
|
3175
|
+
}
|
|
3176
|
+
function summarizeJson(content) {
|
|
3177
|
+
try {
|
|
3178
|
+
const parsed = JSON.parse(stripJsonComments(content));
|
|
3179
|
+
if (Array.isArray(parsed)) {
|
|
3180
|
+
const sample = parsed[0];
|
|
3181
|
+
const sampleKeys = sample && typeof sample === "object" && !Array.isArray(sample) ? Object.keys(sample).slice(0, 10).sort() : [];
|
|
3182
|
+
return {
|
|
3183
|
+
shape: "array",
|
|
3184
|
+
itemCount: parsed.length,
|
|
3185
|
+
keys: [],
|
|
3186
|
+
sampleKeys
|
|
3187
|
+
};
|
|
3188
|
+
}
|
|
3189
|
+
if (parsed && typeof parsed === "object") {
|
|
3190
|
+
const keys = Object.keys(parsed).sort();
|
|
3191
|
+
return {
|
|
3192
|
+
shape: "object",
|
|
3193
|
+
itemCount: keys.length,
|
|
3194
|
+
keys: keys.slice(0, 30),
|
|
3195
|
+
sampleKeys: []
|
|
3196
|
+
};
|
|
3197
|
+
}
|
|
3198
|
+
return {
|
|
3199
|
+
shape: typeof parsed,
|
|
3200
|
+
itemCount: null,
|
|
3201
|
+
keys: [],
|
|
3202
|
+
sampleKeys: []
|
|
3203
|
+
};
|
|
3204
|
+
} catch {
|
|
3205
|
+
return {
|
|
3206
|
+
shape: "invalid-json",
|
|
3207
|
+
itemCount: null,
|
|
3208
|
+
keys: [],
|
|
3209
|
+
sampleKeys: []
|
|
3210
|
+
};
|
|
3211
|
+
}
|
|
3212
|
+
}
|
|
3213
|
+
function frontMatterEnd(lines) {
|
|
3214
|
+
if (lines.length < 3 || lines[0].trim() !== "---") return 0;
|
|
3215
|
+
for (let index = 1; index < lines.length; index += 1) {
|
|
3216
|
+
const line = lines[index];
|
|
3217
|
+
const candidate = line.trim();
|
|
3218
|
+
if (candidate === "---" || candidate === "...") {
|
|
3219
|
+
return index > 1 ? index : 0;
|
|
3220
|
+
}
|
|
3221
|
+
if (candidate === "") continue;
|
|
3222
|
+
if (/^#(\s|$)/.test(candidate)) continue;
|
|
3223
|
+
if (/^(`{3,}|~{3,})/.test(candidate)) return 0;
|
|
3224
|
+
if (/^#{1,6}\s+\S/.test(candidate)) return 0;
|
|
3225
|
+
const isYamlMapping = /^[A-Za-z0-9_.-]+\s*:(\s|$)/.test(candidate);
|
|
3226
|
+
const isListItem = /^-(?:(\s|$))/.test(candidate);
|
|
3227
|
+
const isIndented = /^[ \t]/.test(line);
|
|
3228
|
+
if (!isYamlMapping && !isListItem && !isIndented) return 0;
|
|
3229
|
+
}
|
|
3230
|
+
return 0;
|
|
3231
|
+
}
|
|
3232
|
+
function summarizeMarkdown(content) {
|
|
3233
|
+
const headings = [];
|
|
3234
|
+
const frontmatterKeys = [];
|
|
3235
|
+
const lines = content.replace(/^\uFEFF/, "").split(/\r\n|\n|\r/);
|
|
3236
|
+
let inFrontmatter = false;
|
|
3237
|
+
let fence = null;
|
|
3238
|
+
const frontMatterEndLine = frontMatterEnd(lines);
|
|
3239
|
+
for (let index = 0; index < lines.length; index++) {
|
|
3240
|
+
const line = lines[index];
|
|
3241
|
+
if (index === 0 && frontMatterEndLine > 0) {
|
|
3242
|
+
inFrontmatter = true;
|
|
3243
|
+
continue;
|
|
3244
|
+
}
|
|
3245
|
+
if (inFrontmatter) {
|
|
3246
|
+
const trimmedFrontmatter = line.trim();
|
|
3247
|
+
if (trimmedFrontmatter === "---" || trimmedFrontmatter === "...") {
|
|
3248
|
+
inFrontmatter = false;
|
|
3249
|
+
continue;
|
|
3250
|
+
}
|
|
3251
|
+
const match = /^([A-Za-z0-9_.-]+)\s*:/.exec(line);
|
|
3252
|
+
if (match) frontmatterKeys.push(match[1]);
|
|
3253
|
+
continue;
|
|
3254
|
+
}
|
|
3255
|
+
const trimmed = line.trim();
|
|
3256
|
+
const fenceMatch = /^(`{3,}|~{3,})(.*)$/.exec(trimmed);
|
|
3257
|
+
if (fenceMatch) {
|
|
3258
|
+
const run = fenceMatch[1];
|
|
3259
|
+
const rest = fenceMatch[2].trim();
|
|
3260
|
+
if (fence === null) {
|
|
3261
|
+
fence = { marker: run[0], length: run.length };
|
|
3262
|
+
} else if (run[0] === fence.marker && run.length >= fence.length && rest === "") {
|
|
3263
|
+
fence = null;
|
|
3264
|
+
}
|
|
3265
|
+
continue;
|
|
3266
|
+
}
|
|
3267
|
+
if (fence !== null) continue;
|
|
3268
|
+
const headingMatch = /^(#{1,6})\s+(.+)$/.exec(trimmed);
|
|
3269
|
+
if (headingMatch) {
|
|
3270
|
+
headings.push(`${headingMatch[1]} ${headingMatch[2].trim()}`);
|
|
3271
|
+
}
|
|
3272
|
+
}
|
|
3273
|
+
return {
|
|
3274
|
+
headings: headings.slice(0, 40),
|
|
3275
|
+
frontmatterKeys: Array.from(new Set(frontmatterKeys)).sort()
|
|
3276
|
+
};
|
|
3277
|
+
}
|
|
3278
|
+
|
|
3049
3279
|
// src/tokenize.ts
|
|
3050
3280
|
var WORD_RUN = /[A-Za-z0-9_]+/g;
|
|
3051
3281
|
var SINGLE_TOKEN = /[^\sA-Za-z0-9_]/g;
|
|
@@ -3156,6 +3386,10 @@ function normalizeResolvedConfig(config) {
|
|
|
3156
3386
|
return markResolvedConfig({
|
|
3157
3387
|
...config,
|
|
3158
3388
|
discovery,
|
|
3389
|
+
// A spread copy built before the field existed carries no value; the default applies, and it
|
|
3390
|
+
// is re-validated because the number reaches a rendered artifact.
|
|
3391
|
+
attachmentSlots: resolveAttachmentSlots(config.attachmentSlots),
|
|
3392
|
+
maxParts: resolveMaxParts(config.maxParts),
|
|
3159
3393
|
includeMonolith: artifacts.monolith,
|
|
3160
3394
|
secretRules: compileSecretRules(config.secretRules),
|
|
3161
3395
|
artifacts,
|
|
@@ -3202,70 +3436,6 @@ function supportsTypeScriptImports() {
|
|
|
3202
3436
|
if (!Number.isFinite(major)) return false;
|
|
3203
3437
|
return major > 22 || major === 22 && minor >= 6;
|
|
3204
3438
|
}
|
|
3205
|
-
function stripJsonComments(raw) {
|
|
3206
|
-
const text2 = raw.replace(/^\uFEFF/, "");
|
|
3207
|
-
let out = "";
|
|
3208
|
-
let inString = false;
|
|
3209
|
-
let escaped = false;
|
|
3210
|
-
for (let index = 0; index < text2.length; index += 1) {
|
|
3211
|
-
const char = text2[index];
|
|
3212
|
-
if (inString) {
|
|
3213
|
-
out += char;
|
|
3214
|
-
if (escaped) escaped = false;
|
|
3215
|
-
else if (char === "\\") escaped = true;
|
|
3216
|
-
else if (char === '"') inString = false;
|
|
3217
|
-
continue;
|
|
3218
|
-
}
|
|
3219
|
-
if (char === '"') {
|
|
3220
|
-
inString = true;
|
|
3221
|
-
out += char;
|
|
3222
|
-
continue;
|
|
3223
|
-
}
|
|
3224
|
-
if (char === "/" && text2[index + 1] === "/") {
|
|
3225
|
-
while (index < text2.length && text2[index] !== "\n" && text2[index] !== "\r") index += 1;
|
|
3226
|
-
index -= 1;
|
|
3227
|
-
continue;
|
|
3228
|
-
}
|
|
3229
|
-
if (char === "/" && text2[index + 1] === "*") {
|
|
3230
|
-
index += 2;
|
|
3231
|
-
while (index < text2.length && !(text2[index] === "*" && text2[index + 1] === "/")) {
|
|
3232
|
-
if (text2[index] === "\n" || text2[index] === "\r") out += text2[index];
|
|
3233
|
-
index += 1;
|
|
3234
|
-
}
|
|
3235
|
-
index += 1;
|
|
3236
|
-
continue;
|
|
3237
|
-
}
|
|
3238
|
-
out += char;
|
|
3239
|
-
}
|
|
3240
|
-
return stripTrailingCommas(out);
|
|
3241
|
-
}
|
|
3242
|
-
function stripTrailingCommas(text2) {
|
|
3243
|
-
let out = "";
|
|
3244
|
-
let inString = false;
|
|
3245
|
-
let escaped = false;
|
|
3246
|
-
for (let index = 0; index < text2.length; index += 1) {
|
|
3247
|
-
const char = text2[index];
|
|
3248
|
-
if (inString) {
|
|
3249
|
-
out += char;
|
|
3250
|
-
if (escaped) escaped = false;
|
|
3251
|
-
else if (char === "\\") escaped = true;
|
|
3252
|
-
else if (char === '"') inString = false;
|
|
3253
|
-
continue;
|
|
3254
|
-
}
|
|
3255
|
-
if (char === '"') {
|
|
3256
|
-
inString = true;
|
|
3257
|
-
out += char;
|
|
3258
|
-
continue;
|
|
3259
|
-
}
|
|
3260
|
-
if (char === ",") {
|
|
3261
|
-
let next = index + 1;
|
|
3262
|
-
while (next < text2.length && /\s/.test(text2[next])) next += 1;
|
|
3263
|
-
if (text2[next] === "}" || text2[next] === "]") continue;
|
|
3264
|
-
}
|
|
3265
|
-
out += char;
|
|
3266
|
-
}
|
|
3267
|
-
return out;
|
|
3268
|
-
}
|
|
3269
3439
|
function parseJsonish(raw, file) {
|
|
3270
3440
|
try {
|
|
3271
3441
|
return JSON.parse(stripJsonComments(raw));
|
|
@@ -3286,8 +3456,9 @@ function describeValue2(value) {
|
|
|
3286
3456
|
return `${typeof value} (${String(value)})`;
|
|
3287
3457
|
}
|
|
3288
3458
|
var isThenable = (value) => typeof value.then === "function";
|
|
3289
|
-
var
|
|
3459
|
+
var CONFIG_KEY_NAMES = [
|
|
3290
3460
|
"artifacts",
|
|
3461
|
+
"attachmentSlots",
|
|
3291
3462
|
"branch",
|
|
3292
3463
|
"budgets",
|
|
3293
3464
|
"changedSince",
|
|
@@ -3305,6 +3476,7 @@ var CONFIG_KEYS = /* @__PURE__ */ new Set([
|
|
|
3305
3476
|
"layersMode",
|
|
3306
3477
|
"maxMonolithBytes",
|
|
3307
3478
|
"maxPartBytes",
|
|
3479
|
+
"maxParts",
|
|
3308
3480
|
"maxPartTokens",
|
|
3309
3481
|
"outDir",
|
|
3310
3482
|
"preset",
|
|
@@ -3317,7 +3489,8 @@ var CONFIG_KEYS = /* @__PURE__ */ new Set([
|
|
|
3317
3489
|
"skeleton",
|
|
3318
3490
|
"tmpDir",
|
|
3319
3491
|
"withDependents"
|
|
3320
|
-
]
|
|
3492
|
+
];
|
|
3493
|
+
var CONFIG_KEYS = new Set(CONFIG_KEY_NAMES);
|
|
3321
3494
|
function assertKnownConfigKeys(value, file) {
|
|
3322
3495
|
const unknownKeys = Object.keys(value).filter((key) => !CONFIG_KEYS.has(key));
|
|
3323
3496
|
if (unknownKeys.length === 0) return;
|
|
@@ -3502,6 +3675,7 @@ var MIN_MAX_PART_BYTES = 4096;
|
|
|
3502
3675
|
var MIN_MAX_PART_TOKENS = MIN_MAX_PART_BYTES / 4;
|
|
3503
3676
|
var ARTIFACT_NAMES = [
|
|
3504
3677
|
"readme",
|
|
3678
|
+
"prompt",
|
|
3505
3679
|
"manifest",
|
|
3506
3680
|
"parts",
|
|
3507
3681
|
"navigation",
|
|
@@ -3511,6 +3685,7 @@ var ARTIFACT_NAMES = [
|
|
|
3511
3685
|
];
|
|
3512
3686
|
var DEFAULT_ARTIFACTS = {
|
|
3513
3687
|
readme: true,
|
|
3688
|
+
prompt: true,
|
|
3514
3689
|
manifest: true,
|
|
3515
3690
|
parts: true,
|
|
3516
3691
|
navigation: true,
|
|
@@ -3571,6 +3746,25 @@ function resolveArtifacts(requested, skipped, includeMonolith, monolithOverride,
|
|
|
3571
3746
|
}
|
|
3572
3747
|
return artifacts;
|
|
3573
3748
|
}
|
|
3749
|
+
var DEFAULT_ATTACHMENT_SLOTS = 10;
|
|
3750
|
+
function resolveAttachmentSlots(value) {
|
|
3751
|
+
if (value === void 0 || value === null) return DEFAULT_ATTACHMENT_SLOTS;
|
|
3752
|
+
if (typeof value !== "number" || !Number.isInteger(value) || value < 0) {
|
|
3753
|
+
throw new Error(
|
|
3754
|
+
"attachmentSlots must be a whole number, with 0 meaning no limit (received " + describeValue2(value) + ")."
|
|
3755
|
+
);
|
|
3756
|
+
}
|
|
3757
|
+
return value;
|
|
3758
|
+
}
|
|
3759
|
+
function resolveMaxParts(value) {
|
|
3760
|
+
if (value === void 0 || value === null) return null;
|
|
3761
|
+
if (typeof value !== "number" || !Number.isInteger(value) || value < 1) {
|
|
3762
|
+
throw new Error(
|
|
3763
|
+
"maxParts must be a whole number of parts, or null to disable it (received " + describeValue2(value) + ")."
|
|
3764
|
+
);
|
|
3765
|
+
}
|
|
3766
|
+
return value;
|
|
3767
|
+
}
|
|
3574
3768
|
function strictPositiveInteger(value, fallback, label) {
|
|
3575
3769
|
if (value === void 0) return fallback;
|
|
3576
3770
|
if (typeof value !== "number" || !Number.isInteger(value) || value <= 0) {
|
|
@@ -3664,11 +3858,11 @@ function outputExcludePatterns(cwd, outDir, tmpDir) {
|
|
|
3664
3858
|
const patterns = [];
|
|
3665
3859
|
for (const dir of [outDir, tmpDir]) {
|
|
3666
3860
|
const absolute = path3.resolve(cwd, dir);
|
|
3667
|
-
const
|
|
3668
|
-
if (!
|
|
3861
|
+
const relative15 = path3.relative(cwd, absolute);
|
|
3862
|
+
if (!relative15 || relative15 === ".." || relative15.startsWith(`..${path3.sep}`) || path3.isAbsolute(relative15)) {
|
|
3669
3863
|
continue;
|
|
3670
3864
|
}
|
|
3671
|
-
patterns.push(`${
|
|
3865
|
+
patterns.push(`${relative15.replace(/\\/g, "/")}/**`);
|
|
3672
3866
|
}
|
|
3673
3867
|
return patterns;
|
|
3674
3868
|
}
|
|
@@ -3949,6 +4143,10 @@ function resolveConfig(userConfig, cliOptions, baseDir) {
|
|
|
3949
4143
|
"maxMonolithBytes"
|
|
3950
4144
|
),
|
|
3951
4145
|
includeSensitiveFiles,
|
|
4146
|
+
attachmentSlots: resolveAttachmentSlots(
|
|
4147
|
+
cliOptions?.attachmentSlots ?? userConfig?.attachmentSlots
|
|
4148
|
+
),
|
|
4149
|
+
maxParts: resolveMaxParts(cliOptions?.maxParts ?? userConfig?.maxParts),
|
|
3952
4150
|
...changedSince === void 0 ? {} : { changedSince },
|
|
3953
4151
|
...staged ? { staged } : {},
|
|
3954
4152
|
...withDependents ? { withDependents } : {},
|
|
@@ -4031,6 +4229,9 @@ function configDigest(config) {
|
|
|
4031
4229
|
includeMonolith: config.includeMonolith,
|
|
4032
4230
|
maxMonolithBytes: config.maxMonolithBytes ?? null,
|
|
4033
4231
|
includeSensitiveFiles: config.includeSensitiveFiles,
|
|
4232
|
+
// Only when the experimental mode is on: `null` is the off switch, and writing it into the
|
|
4233
|
+
// material would change the digest of every snapshot taken before the setting existed.
|
|
4234
|
+
...config.maxParts === null ? {} : { maxParts: config.maxParts },
|
|
4034
4235
|
artifacts: config.artifacts,
|
|
4035
4236
|
include: config.include,
|
|
4036
4237
|
excludePatterns: config.excludePatterns,
|
|
@@ -4243,8 +4444,8 @@ function tsconfigPathsFor(cwd) {
|
|
|
4243
4444
|
return value;
|
|
4244
4445
|
}
|
|
4245
4446
|
function repositoryRelative(cwd, target) {
|
|
4246
|
-
const
|
|
4247
|
-
return
|
|
4447
|
+
const relative15 = path4.relative(cwd, target).replace(/\\/g, "/");
|
|
4448
|
+
return relative15.length === 0 || !relative15.startsWith("..") && !path4.isAbsolute(relative15) ? relative15 : null;
|
|
4248
4449
|
}
|
|
4249
4450
|
function rememberFirst(map, key, value) {
|
|
4250
4451
|
if (!map.has(key)) map.set(key, value);
|
|
@@ -4648,6 +4849,8 @@ function summarizeTypeScriptSource(relativePath, content) {
|
|
|
4648
4849
|
if (cjsExports.length > 0) {
|
|
4649
4850
|
summary.exportsKind = summary.exports.length > 0 ? "mixed" : "cjs";
|
|
4650
4851
|
summary.exports.push(...cjsExports);
|
|
4852
|
+
} else if (summary.exports.length > 0) {
|
|
4853
|
+
summary.exportsKind = "esm";
|
|
4651
4854
|
}
|
|
4652
4855
|
const dedupeSorted2 = (values) => Array.from(new Set(values)).sort((a, b) => a < b ? -1 : a > b ? 1 : 0);
|
|
4653
4856
|
summary.directives = dedupeSorted2(summary.directives);
|
|
@@ -5212,9 +5415,9 @@ var rubyProfile = {
|
|
|
5212
5415
|
eachLine(content, (line) => {
|
|
5213
5416
|
const trimmed = line.trim();
|
|
5214
5417
|
if (!trimmed || trimmed.startsWith("#")) return;
|
|
5215
|
-
const
|
|
5216
|
-
if (
|
|
5217
|
-
summary.imports.push(`./${
|
|
5418
|
+
const relative15 = REQUIRE_RELATIVE.exec(trimmed);
|
|
5419
|
+
if (relative15) {
|
|
5420
|
+
summary.imports.push(`./${relative15[1]}`);
|
|
5218
5421
|
return;
|
|
5219
5422
|
}
|
|
5220
5423
|
const required = REQUIRE.exec(trimmed);
|
|
@@ -5880,6 +6083,16 @@ function wouldNowBeIncluded(cwd, relativePath) {
|
|
|
5880
6083
|
return false;
|
|
5881
6084
|
}
|
|
5882
6085
|
}
|
|
6086
|
+
var TRUNCATION_REASONS = /* @__PURE__ */ new Set([
|
|
6087
|
+
"large-file-budget",
|
|
6088
|
+
"part-budget",
|
|
6089
|
+
"section-metadata"
|
|
6090
|
+
]);
|
|
6091
|
+
function isConfinedRelative(value) {
|
|
6092
|
+
if (value.length === 0 || value.includes("\0") || value.includes("\\")) return false;
|
|
6093
|
+
if (path6.isAbsolute(value)) return false;
|
|
6094
|
+
return !value.split("/").includes("..");
|
|
6095
|
+
}
|
|
5883
6096
|
function describeManifestShapeProblem(value) {
|
|
5884
6097
|
if (!value || typeof value !== "object" || Array.isArray(value)) return "not a JSON object";
|
|
5885
6098
|
const candidate = value;
|
|
@@ -5945,6 +6158,68 @@ function describeManifestShapeProblem(value) {
|
|
|
5945
6158
|
if (!candidate.kinds || typeof candidate.kinds !== "object" || Array.isArray(candidate.kinds)) {
|
|
5946
6159
|
return 'missing "kinds" object';
|
|
5947
6160
|
}
|
|
6161
|
+
const incompleteCount = counts.incompleteCount;
|
|
6162
|
+
if (typeof incompleteCount !== "number" || !Number.isSafeInteger(incompleteCount) || incompleteCount < 0) {
|
|
6163
|
+
return "missing numeric `counts.incompleteCount`";
|
|
6164
|
+
}
|
|
6165
|
+
const incomplete = candidate.incomplete;
|
|
6166
|
+
if (!Array.isArray(incomplete)) return 'missing "incomplete" array';
|
|
6167
|
+
if (incompleteCount !== incomplete.length) {
|
|
6168
|
+
return "`counts.incompleteCount` does not match the length of `incomplete`";
|
|
6169
|
+
}
|
|
6170
|
+
for (const entry of incomplete) {
|
|
6171
|
+
if (!entry || typeof entry !== "object" || Array.isArray(entry)) {
|
|
6172
|
+
return 'an "incomplete" entry is not an object';
|
|
6173
|
+
}
|
|
6174
|
+
const fields = entry;
|
|
6175
|
+
const relativePath = fields.relativePath;
|
|
6176
|
+
if (typeof relativePath !== "string" || relativePath.length === 0) {
|
|
6177
|
+
return 'an "incomplete" entry has no "relativePath"';
|
|
6178
|
+
}
|
|
6179
|
+
if (!isConfinedRelative(relativePath)) {
|
|
6180
|
+
return 'an "incomplete" entry "relativePath" must stay inside the repository';
|
|
6181
|
+
}
|
|
6182
|
+
if (typeof fields.part !== "string" || fields.part.trim() === "") {
|
|
6183
|
+
return 'an "incomplete" entry has no "part"';
|
|
6184
|
+
}
|
|
6185
|
+
if (typeof fields.reason !== "string" || !TRUNCATION_REASONS.has(fields.reason)) {
|
|
6186
|
+
return 'an "incomplete" entry has an unknown "reason"';
|
|
6187
|
+
}
|
|
6188
|
+
for (const key of ["omittedLines", "includedLines", "lines"]) {
|
|
6189
|
+
const value2 = fields[key];
|
|
6190
|
+
if (typeof value2 !== "number" || !Number.isSafeInteger(value2) || value2 < 0) {
|
|
6191
|
+
return `an "incomplete" entry "${key}" must be a non-negative integer`;
|
|
6192
|
+
}
|
|
6193
|
+
}
|
|
6194
|
+
const lines = fields.lines;
|
|
6195
|
+
if (fields.includedLines > lines) {
|
|
6196
|
+
return 'an "incomplete" entry "includedLines" exceeds its "lines"';
|
|
6197
|
+
}
|
|
6198
|
+
const ranges = fields.omittedRanges;
|
|
6199
|
+
if (!Array.isArray(ranges)) return 'an "incomplete" entry has no "omittedRanges" array';
|
|
6200
|
+
let previousEnd = 0;
|
|
6201
|
+
let omitted = 0;
|
|
6202
|
+
for (const range of ranges) {
|
|
6203
|
+
if (!Array.isArray(range) || range.length !== 2) {
|
|
6204
|
+
return 'an "incomplete" entry "omittedRanges" must hold [from, to] pairs';
|
|
6205
|
+
}
|
|
6206
|
+
const [from, to] = range;
|
|
6207
|
+
if (typeof from !== "number" || typeof to !== "number" || !Number.isSafeInteger(from) || !Number.isSafeInteger(to)) {
|
|
6208
|
+
return 'an "incomplete" entry "omittedRanges" must hold integer pairs';
|
|
6209
|
+
}
|
|
6210
|
+
if (from < 1 || to < from || to > lines) {
|
|
6211
|
+
return `an "incomplete" entry records an omitted range ${from}-${to}, outside 1-${lines}`;
|
|
6212
|
+
}
|
|
6213
|
+
if (from <= previousEnd) {
|
|
6214
|
+
return 'an "incomplete" entry "omittedRanges" must be sorted and non-overlapping';
|
|
6215
|
+
}
|
|
6216
|
+
previousEnd = to;
|
|
6217
|
+
omitted += to - from + 1;
|
|
6218
|
+
}
|
|
6219
|
+
if (omitted !== fields.omittedLines) {
|
|
6220
|
+
return "`omittedLines` does not match the ranges it records";
|
|
6221
|
+
}
|
|
6222
|
+
}
|
|
5948
6223
|
}
|
|
5949
6224
|
if (!Array.isArray(candidate.files)) return 'missing "files" array';
|
|
5950
6225
|
for (const entry of candidate.files) {
|
|
@@ -6058,11 +6333,57 @@ function validateSnapshot(configInput) {
|
|
|
6058
6333
|
);
|
|
6059
6334
|
}
|
|
6060
6335
|
const manifestFileMap = /* @__PURE__ */ new Map();
|
|
6336
|
+
const manifestFilesByPath = /* @__PURE__ */ new Map();
|
|
6061
6337
|
for (const file of manifest.files) {
|
|
6062
6338
|
if (file && typeof file.relativePath === "string") {
|
|
6063
6339
|
manifestFileMap.set(file.relativePath, file.hashSha256);
|
|
6340
|
+
manifestFilesByPath.set(file.relativePath, file);
|
|
6064
6341
|
}
|
|
6065
6342
|
}
|
|
6343
|
+
const incompleteRecords = manifest.incomplete ?? [];
|
|
6344
|
+
const incompleteness = /* @__PURE__ */ new Map();
|
|
6345
|
+
for (const record of incompleteRecords) {
|
|
6346
|
+
incompleteness.set(record.relativePath, record);
|
|
6347
|
+
const label = maskedPath(record.relativePath, config.secretRules);
|
|
6348
|
+
const file = manifestFilesByPath.get(record.relativePath);
|
|
6349
|
+
if (file === void 0) {
|
|
6350
|
+
drift.partIssues.push({
|
|
6351
|
+
part: "(manifest)",
|
|
6352
|
+
issue: `${label} is in incomplete[] but not in files[]`
|
|
6353
|
+
});
|
|
6354
|
+
continue;
|
|
6355
|
+
}
|
|
6356
|
+
if (file.part !== record.part) {
|
|
6357
|
+
drift.partIssues.push({
|
|
6358
|
+
part: "(manifest)",
|
|
6359
|
+
issue: `${label} is recorded in part ${String(record.part)} in incomplete[] and part ${String(file.part)} in files[]`
|
|
6360
|
+
});
|
|
6361
|
+
}
|
|
6362
|
+
if (file.truncationReason !== record.reason) {
|
|
6363
|
+
drift.partIssues.push({
|
|
6364
|
+
part: "(manifest)",
|
|
6365
|
+
issue: `${label} records truncationReason ${String(file.truncationReason)} in files[] and reason ${String(record.reason)} in incomplete[]`
|
|
6366
|
+
});
|
|
6367
|
+
}
|
|
6368
|
+
const recordedRanges = file.omittedRanges ?? [];
|
|
6369
|
+
const rangesAgree = recordedRanges.length === record.omittedRanges.length && recordedRanges.every(
|
|
6370
|
+
([from, to], index) => record.omittedRanges[index][0] === from && record.omittedRanges[index][1] === to
|
|
6371
|
+
);
|
|
6372
|
+
if (!rangesAgree || file.includedLines !== record.includedLines || file.lines !== record.lines) {
|
|
6373
|
+
drift.partIssues.push({
|
|
6374
|
+
part: "(manifest)",
|
|
6375
|
+
issue: `${label} records different omission numbers in files[] and incomplete[]`
|
|
6376
|
+
});
|
|
6377
|
+
}
|
|
6378
|
+
}
|
|
6379
|
+
for (const file of manifest.files) {
|
|
6380
|
+
if (file.truncationReason === void 0) continue;
|
|
6381
|
+
if (incompleteness.has(file.relativePath)) continue;
|
|
6382
|
+
drift.partIssues.push({
|
|
6383
|
+
part: "(manifest)",
|
|
6384
|
+
issue: `${maskedPath(file.relativePath, config.secretRules)} records a truncationReason but is missing from incomplete[]`
|
|
6385
|
+
});
|
|
6386
|
+
}
|
|
6066
6387
|
const skippedReasons = /* @__PURE__ */ new Map();
|
|
6067
6388
|
for (const entry of manifest.skipped) {
|
|
6068
6389
|
if (entry && typeof entry.path === "string" && typeof entry.reason === "string") {
|
|
@@ -6119,7 +6440,7 @@ function validateSnapshot(configInput) {
|
|
|
6119
6440
|
// snapshot was reported as drifting.
|
|
6120
6441
|
toolOwnedPaths: [config.outDir, config.tmpDir].map(
|
|
6121
6442
|
(directory) => path6.relative(config.cwd, path6.resolve(config.cwd, directory)).replace(/\\/g, "/")
|
|
6122
|
-
).filter((
|
|
6443
|
+
).filter((relative15) => relative15.length > 0 && !relative15.startsWith(".."))
|
|
6123
6444
|
});
|
|
6124
6445
|
for (const diskFile of collection.files) {
|
|
6125
6446
|
const snapshotHash = manifestFileMap.get(diskFile);
|
|
@@ -6520,7 +6841,8 @@ function validateSnapshot(configInput) {
|
|
|
6520
6841
|
);
|
|
6521
6842
|
}
|
|
6522
6843
|
}
|
|
6523
|
-
|
|
6844
|
+
const ceilingDerivedByMaxParts = (manifest.config?.maxParts ?? null) !== null;
|
|
6845
|
+
if (!ceilingDerivedByMaxParts && manifest.budgets && manifest.budgets.maxPartBytes !== config.maxPartBytes) {
|
|
6524
6846
|
totalsMismatches.push(
|
|
6525
6847
|
`budgets.maxPartBytes: manifest ${manifest.budgets.maxPartBytes} vs current ${config.maxPartBytes}`
|
|
6526
6848
|
);
|
|
@@ -6549,6 +6871,7 @@ function validateSnapshot(configInput) {
|
|
|
6549
6871
|
}
|
|
6550
6872
|
const declaredArtifacts = [
|
|
6551
6873
|
["README.md", manifest.artifacts?.readme],
|
|
6874
|
+
["PROMPT.md", manifest.artifacts?.prompt],
|
|
6552
6875
|
["reports/navigation.md", manifest.artifacts?.navigation],
|
|
6553
6876
|
["reports/project-tree.md", manifest.artifacts?.projectTree],
|
|
6554
6877
|
["reports/audit.md", manifest.artifacts?.audit],
|
|
@@ -6575,8 +6898,8 @@ function validateSnapshot(configInput) {
|
|
|
6575
6898
|
const target = match[1].split("#")[0];
|
|
6576
6899
|
if (target.length === 0 || /^[a-z][a-z0-9+.-]*:/i.test(target)) continue;
|
|
6577
6900
|
const resolved = path6.resolve(snapshotDir, "reports", target);
|
|
6578
|
-
const
|
|
6579
|
-
if (
|
|
6901
|
+
const relative15 = path6.relative(snapshotDir, resolved);
|
|
6902
|
+
if (relative15.startsWith("..") || path6.isAbsolute(relative15) || !fs7.existsSync(resolved)) {
|
|
6580
6903
|
drift.partIssues.push({
|
|
6581
6904
|
part: key,
|
|
6582
6905
|
issue: `links to ${maskedPath(target, config.secretRules)}, which does not exist in the snapshot`
|
|
@@ -6672,19 +6995,19 @@ function side(manifest) {
|
|
|
6672
6995
|
function shortDigest(value) {
|
|
6673
6996
|
return value === null ? "not recorded" : `${value.slice(0, 12)}\u2026`;
|
|
6674
6997
|
}
|
|
6675
|
-
function describeLayerChanges(before, after) {
|
|
6998
|
+
function describeLayerChanges(before, after, secretRules) {
|
|
6676
6999
|
const names = Array.from(/* @__PURE__ */ new Set([...Object.keys(before), ...Object.keys(after)])).sort();
|
|
6677
7000
|
const changes = [];
|
|
6678
7001
|
for (const name of names) {
|
|
6679
7002
|
const was = before[name] ?? 0;
|
|
6680
7003
|
const now = after[name] ?? 0;
|
|
6681
7004
|
if (was === now) continue;
|
|
6682
|
-
const label = findSecretInPath(name)?.masked ?? name;
|
|
7005
|
+
const label = findSecretInPath(name, secretRules)?.masked ?? name;
|
|
6683
7006
|
changes.push(`layer "${label}": ${was} file(s) \u2192 ${now} file(s)`);
|
|
6684
7007
|
}
|
|
6685
7008
|
return changes;
|
|
6686
7009
|
}
|
|
6687
|
-
function describePartChanges(before, after) {
|
|
7010
|
+
function describePartChanges(before, after, secretRules) {
|
|
6688
7011
|
const index = (parts) => {
|
|
6689
7012
|
const map = /* @__PURE__ */ new Map();
|
|
6690
7013
|
for (const part of parts) {
|
|
@@ -6694,7 +7017,7 @@ function describePartChanges(before, after) {
|
|
|
6694
7017
|
};
|
|
6695
7018
|
const left = index(before);
|
|
6696
7019
|
const right = index(after);
|
|
6697
|
-
const label = (filename) => findSecretInPath(filename)?.masked ?? filename;
|
|
7020
|
+
const label = (filename) => findSecretInPath(filename, secretRules)?.masked ?? filename;
|
|
6698
7021
|
const changes = [];
|
|
6699
7022
|
for (const [filename, part] of right) {
|
|
6700
7023
|
const previous = left.get(filename);
|
|
@@ -6722,7 +7045,15 @@ function describePartChanges(before, after) {
|
|
|
6722
7045
|
}
|
|
6723
7046
|
return changes;
|
|
6724
7047
|
}
|
|
6725
|
-
function
|
|
7048
|
+
function maskLayerNames(layers, secretRules) {
|
|
7049
|
+
return Object.fromEntries(
|
|
7050
|
+
Object.entries(layers ?? {}).map(([name, count]) => [
|
|
7051
|
+
findSecretInPath(name, secretRules)?.masked ?? name,
|
|
7052
|
+
count
|
|
7053
|
+
])
|
|
7054
|
+
);
|
|
7055
|
+
}
|
|
7056
|
+
function describePayloadDiff(before, after, sourceFilesIdentical, secretRules) {
|
|
6726
7057
|
const generatorBefore = before.generator?.version ?? "unknown";
|
|
6727
7058
|
const generatorAfter = after.generator?.version ?? "unknown";
|
|
6728
7059
|
const digestBefore = typeof before.config?.digest === "string" ? before.config.digest : null;
|
|
@@ -6735,35 +7066,43 @@ function describePayloadDiff(before, after, sourceFilesIdentical) {
|
|
|
6735
7066
|
const configurationDiffers = generatorDiffers || digestDiffers || schemaDiffers;
|
|
6736
7067
|
const fingerprintDiffers = before.fingerprint !== after.fingerprint;
|
|
6737
7068
|
const partsDiffer = before.counts.partsCount !== after.counts.partsCount;
|
|
6738
|
-
const partChanges = describePartChanges(before.parts ?? [], after.parts ?? []);
|
|
6739
|
-
const layerChanges = describeLayerChanges(before.layers ?? {}, after.layers ?? {});
|
|
7069
|
+
const partChanges = describePartChanges(before.parts ?? [], after.parts ?? [], secretRules);
|
|
7070
|
+
const layerChanges = describeLayerChanges(before.layers ?? {}, after.layers ?? {}, secretRules);
|
|
6740
7071
|
const reasons = [];
|
|
7072
|
+
const codes = [];
|
|
6741
7073
|
if (schemaDiffers) {
|
|
7074
|
+
codes.push("schema-version");
|
|
6742
7075
|
reasons.push(
|
|
6743
7076
|
`schema version ${schemaBefore} \u2192 ${schemaAfter} (the two manifests describe different formats)`
|
|
6744
7077
|
);
|
|
6745
7078
|
}
|
|
6746
7079
|
if (digestDiffers) {
|
|
7080
|
+
codes.push("config-digest");
|
|
6747
7081
|
reasons.push(
|
|
6748
7082
|
`configuration digest ${shortDigest(digestBefore)} \u2192 ${shortDigest(digestAfter)} (budgets, preview thresholds, redaction rules and artifact selection all count)`
|
|
6749
7083
|
);
|
|
6750
7084
|
} else if (digestBefore === null || digestAfter === null) {
|
|
6751
7085
|
const missing = digestBefore === null && digestAfter !== null ? "before" : digestAfter === null && digestBefore !== null ? "after" : "both";
|
|
7086
|
+
codes.push("config-digest-missing");
|
|
6752
7087
|
reasons.push(
|
|
6753
7088
|
`configuration digest not recorded on the ${missing} side (manifest written before 4.0.5); compared the content fingerprint and part count instead`
|
|
6754
7089
|
);
|
|
6755
7090
|
}
|
|
6756
7091
|
if (generatorDiffers) {
|
|
7092
|
+
codes.push("generator");
|
|
6757
7093
|
reasons.push(`generator ${generatorBefore} \u2192 ${generatorAfter}`);
|
|
6758
7094
|
}
|
|
6759
7095
|
if (fingerprintDiffers && (sourceFilesIdentical || configurationDiffers)) {
|
|
7096
|
+
codes.push("fingerprint");
|
|
6760
7097
|
reasons.push(
|
|
6761
7098
|
`content fingerprint ${shortDigest(before.fingerprint)} \u2192 ${shortDigest(after.fingerprint)}` + (sourceFilesIdentical ? " (same source files, packed or configured differently)" : "")
|
|
6762
7099
|
);
|
|
6763
7100
|
}
|
|
6764
7101
|
if (partsDiffer) {
|
|
7102
|
+
codes.push("parts-count");
|
|
6765
7103
|
reasons.push(`${before.counts.partsCount} part(s) \u2192 ${after.counts.partsCount} part(s)`);
|
|
6766
7104
|
}
|
|
7105
|
+
for (let index = 0; index < layerChanges.length; index += 1) codes.push("layer-changed");
|
|
6767
7106
|
reasons.push(...layerChanges);
|
|
6768
7107
|
return {
|
|
6769
7108
|
sourceFilesIdentical,
|
|
@@ -6775,8 +7114,12 @@ function describePayloadDiff(before, after, sourceFilesIdentical) {
|
|
|
6775
7114
|
partsCount: { before: before.counts.partsCount, after: after.counts.partsCount },
|
|
6776
7115
|
schemaVersion: { before: schemaBefore, after: schemaAfter },
|
|
6777
7116
|
partsManifest: { differs: partChanges.length > 0, changes: partChanges },
|
|
6778
|
-
|
|
6779
|
-
|
|
7117
|
+
// The layer maps are printed and serialized, so a layer named after a project token leaks the
|
|
7118
|
+
// token here even though every reason line above is masked. Found while testing the rules
|
|
7119
|
+
// parameter: masking the prose and not the data it describes is the same bug one layer down.
|
|
7120
|
+
layers: { before: maskLayerNames(before.layers, secretRules), after: maskLayerNames(after.layers, secretRules) },
|
|
7121
|
+
reasons,
|
|
7122
|
+
codes
|
|
6780
7123
|
};
|
|
6781
7124
|
}
|
|
6782
7125
|
function hashMap(manifest) {
|
|
@@ -6815,10 +7158,10 @@ function comparableProblem(value) {
|
|
|
6815
7158
|
function assertUsableManifest(value, label) {
|
|
6816
7159
|
const problem = comparableProblem(value);
|
|
6817
7160
|
if (problem) {
|
|
6818
|
-
throw new Error(`The ${label} manifest is not a snapshot manifest
|
|
7161
|
+
throw new Error(`The ${label} manifest is not a snapshot manifest: ${problem}.`);
|
|
6819
7162
|
}
|
|
6820
7163
|
}
|
|
6821
|
-
function compareManifests(before, after) {
|
|
7164
|
+
function compareManifests(before, after, secretRules) {
|
|
6822
7165
|
assertUsableManifest(before, "before");
|
|
6823
7166
|
assertUsableManifest(after, "after");
|
|
6824
7167
|
const left = hashMap(before);
|
|
@@ -6838,8 +7181,8 @@ function compareManifests(before, after) {
|
|
|
6838
7181
|
}
|
|
6839
7182
|
const sort = (values) => values.sort((a, b) => a < b ? -1 : a > b ? 1 : 0);
|
|
6840
7183
|
const sourceFilesIdentical = added.length === 0 && removed.length === 0 && changed.length === 0;
|
|
6841
|
-
const payload = describePayloadDiff(before, after, sourceFilesIdentical);
|
|
6842
|
-
const mask = (values) => values.map((value) => findSecretInPath(value)?.masked ?? value);
|
|
7184
|
+
const payload = describePayloadDiff(before, after, sourceFilesIdentical, secretRules);
|
|
7185
|
+
const mask = (values) => values.map((value) => findSecretInPath(value, secretRules)?.masked ?? value);
|
|
6843
7186
|
return {
|
|
6844
7187
|
before: side(before),
|
|
6845
7188
|
after: side(after),
|
|
@@ -6873,7 +7216,7 @@ function loadManifest(target) {
|
|
|
6873
7216
|
const problem = describeManifestShapeProblem(parsed);
|
|
6874
7217
|
if (problem) {
|
|
6875
7218
|
throw new Error(
|
|
6876
|
-
`${manifestPath} is not a
|
|
7219
|
+
`${manifestPath} is not a snapshot manifest: ${problem}. Point diff at a manifest.json written by \`generate\` (or at the directory that holds it).`
|
|
6877
7220
|
);
|
|
6878
7221
|
}
|
|
6879
7222
|
return parsed;
|
|
@@ -7150,23 +7493,23 @@ function describeMatcher(matcher) {
|
|
|
7150
7493
|
function normalizeTarget(cwd, target) {
|
|
7151
7494
|
const resolvedCwd = path9.resolve(cwd);
|
|
7152
7495
|
const absolute = path9.resolve(resolvedCwd, target);
|
|
7153
|
-
const
|
|
7154
|
-
if (
|
|
7496
|
+
const relative15 = path9.relative(resolvedCwd, absolute);
|
|
7497
|
+
if (relative15 === "" || relative15 === ".." || relative15.startsWith(`..${path9.sep}`) || path9.isAbsolute(relative15)) {
|
|
7155
7498
|
return { relative: target.replace(/\\/g, "/"), outsideRoot: true };
|
|
7156
7499
|
}
|
|
7157
|
-
return { relative:
|
|
7500
|
+
return { relative: relative15.split(path9.sep).join("/"), outsideRoot: false };
|
|
7158
7501
|
}
|
|
7159
7502
|
function findRuleMatch(rules, relativePath) {
|
|
7160
7503
|
return rules.find(
|
|
7161
7504
|
(rule) => matchRule(relativePath, rule.match)
|
|
7162
7505
|
);
|
|
7163
7506
|
}
|
|
7164
|
-
function findRecordedAncestor(skipped,
|
|
7507
|
+
function findRecordedAncestor(skipped, relative15, maskedPath2) {
|
|
7165
7508
|
let nearest;
|
|
7166
7509
|
for (const record of skipped) {
|
|
7167
7510
|
const ancestorPath = record.path;
|
|
7168
7511
|
if (ancestorPath.length === 0) continue;
|
|
7169
|
-
const isAncestor =
|
|
7512
|
+
const isAncestor = relative15.startsWith(`${ancestorPath}/`) || maskedPath2.startsWith(`${ancestorPath}/`);
|
|
7170
7513
|
if (!isAncestor) continue;
|
|
7171
7514
|
if (!nearest || ancestorPath.length > nearest.path.length) nearest = record;
|
|
7172
7515
|
}
|
|
@@ -7182,8 +7525,8 @@ function readManifest2(config) {
|
|
|
7182
7525
|
}
|
|
7183
7526
|
function explainPath(config, target) {
|
|
7184
7527
|
const normalized = normalizeTarget(config.cwd, target);
|
|
7185
|
-
const
|
|
7186
|
-
const maskedPath2 = findSecretInPath(
|
|
7528
|
+
const relative15 = normalized.relative;
|
|
7529
|
+
const maskedPath2 = findSecretInPath(relative15, config.secretRules)?.masked ?? relative15;
|
|
7187
7530
|
if (normalized.outsideRoot) {
|
|
7188
7531
|
return {
|
|
7189
7532
|
path: maskedPath2,
|
|
@@ -7193,7 +7536,7 @@ function explainPath(config, target) {
|
|
|
7193
7536
|
detail: "path resolves outside the configured repository root and was not inspected"
|
|
7194
7537
|
};
|
|
7195
7538
|
}
|
|
7196
|
-
const absolute = path9.join(config.cwd,
|
|
7539
|
+
const absolute = path9.join(config.cwd, relative15);
|
|
7197
7540
|
const result = {
|
|
7198
7541
|
path: maskedPath2,
|
|
7199
7542
|
exists: fs9.existsSync(absolute),
|
|
@@ -7211,11 +7554,11 @@ function explainPath(config, target) {
|
|
|
7211
7554
|
// that is only missing because the walker dropped the tool's own output directory.
|
|
7212
7555
|
toolOwnedPaths: [config.outDir, config.tmpDir].map(
|
|
7213
7556
|
(directory) => path9.relative(config.cwd, path9.resolve(config.cwd, directory)).replace(/\\/g, "/")
|
|
7214
|
-
).filter((
|
|
7557
|
+
).filter((relative16) => relative16.length > 0 && !relative16.startsWith(".."))
|
|
7215
7558
|
});
|
|
7216
|
-
if (!collection.files.includes(
|
|
7559
|
+
if (!collection.files.includes(relative15)) {
|
|
7217
7560
|
const record = collection.skipped.find(
|
|
7218
|
-
(entry2) => entry2.path ===
|
|
7561
|
+
(entry2) => entry2.path === relative15 || entry2.path === maskedPath2
|
|
7219
7562
|
);
|
|
7220
7563
|
if (record) {
|
|
7221
7564
|
result.reason = record.reason;
|
|
@@ -7224,7 +7567,7 @@ function explainPath(config, target) {
|
|
|
7224
7567
|
result.reason = "missing";
|
|
7225
7568
|
result.detail = "no such file or directory, relative to the configured cwd";
|
|
7226
7569
|
} else {
|
|
7227
|
-
const ancestor = findRecordedAncestor(collection.skipped,
|
|
7570
|
+
const ancestor = findRecordedAncestor(collection.skipped, relative15, maskedPath2);
|
|
7228
7571
|
if (ancestor) {
|
|
7229
7572
|
result.reason = ancestor.reason;
|
|
7230
7573
|
result.detail = ancestor.detail ? `${ancestor.detail} \u2014 inherited from the skipped directory \`${ancestor.path}\`` : `inside the skipped directory \`${ancestor.path}\``;
|
|
@@ -7244,11 +7587,11 @@ function explainPath(config, target) {
|
|
|
7244
7587
|
...config.changedSince === void 0 ? {} : { changedSince: config.changedSince },
|
|
7245
7588
|
...config.staged === true ? { staged: true } : {}
|
|
7246
7589
|
});
|
|
7247
|
-
inScope = scope.paths.has(
|
|
7590
|
+
inScope = scope.paths.has(relative15);
|
|
7248
7591
|
if (!inScope && config.withDependents === true) {
|
|
7249
7592
|
inScope = importsChangedFile(
|
|
7250
|
-
|
|
7251
|
-
importsOfFile(
|
|
7593
|
+
relative15,
|
|
7594
|
+
importsOfFile(relative15, absolute),
|
|
7252
7595
|
scope.paths,
|
|
7253
7596
|
buildImportResolver(collection.files.map((file) => ({ relativePath: file })))
|
|
7254
7597
|
);
|
|
@@ -7306,12 +7649,12 @@ function explainPath(config, target) {
|
|
|
7306
7649
|
result.bytes = buffer.length;
|
|
7307
7650
|
result.lines = countLines(text2);
|
|
7308
7651
|
if (decoded.encoding !== "utf-8") result.encoding = decoded.encoding;
|
|
7309
|
-
const { findings } = scanAndRedactSecrets(text2, config.secretRules,
|
|
7652
|
+
const { findings } = scanAndRedactSecrets(text2, config.secretRules, relative15);
|
|
7310
7653
|
result.secretCount = findings.length;
|
|
7311
7654
|
result.secrets = findings.slice(0, 20).map((finding) => ({ rules: finding.rules, line: finding.line }));
|
|
7312
7655
|
let inclusionMode = "full";
|
|
7313
|
-
if (config.skeleton === true && isSkeletonizable(
|
|
7314
|
-
const skeleton = skeletonizeTypeScript(text2,
|
|
7656
|
+
if (config.skeleton === true && isSkeletonizable(relative15)) {
|
|
7657
|
+
const skeleton = skeletonizeTypeScript(text2, relative15);
|
|
7315
7658
|
if (skeleton.collapsed > 0) inclusionMode = "signatures";
|
|
7316
7659
|
}
|
|
7317
7660
|
if (inclusionMode !== "signatures" && buffer.length > config.largeFileBytes) {
|
|
@@ -7320,15 +7663,15 @@ function explainPath(config, target) {
|
|
|
7320
7663
|
}
|
|
7321
7664
|
result.inclusionMode = inclusionMode;
|
|
7322
7665
|
}
|
|
7323
|
-
result.layer = classifyLayer(
|
|
7324
|
-
result.kind = classifyKind(
|
|
7325
|
-
result.language = detectLanguage(
|
|
7326
|
-
const layerRule = findRuleMatch(config.layers,
|
|
7666
|
+
result.layer = classifyLayer(relative15, config.layers);
|
|
7667
|
+
result.kind = classifyKind(relative15, config.kinds);
|
|
7668
|
+
result.language = detectLanguage(relative15);
|
|
7669
|
+
const layerRule = findRuleMatch(config.layers, relative15);
|
|
7327
7670
|
if (layerRule) result.layerMatch = describeMatcher(layerRule.match);
|
|
7328
|
-
const kindRule = findRuleMatch(config.kinds,
|
|
7671
|
+
const kindRule = findRuleMatch(config.kinds, relative15);
|
|
7329
7672
|
if (kindRule) result.kindMatch = describeMatcher(kindRule.match);
|
|
7330
7673
|
const manifest = readManifest2(config);
|
|
7331
|
-
const entry = Array.isArray(manifest?.files) ? manifest.files.find((file) => file.relativePath ===
|
|
7674
|
+
const entry = Array.isArray(manifest?.files) ? manifest.files.find((file) => file.relativePath === relative15) : void 0;
|
|
7332
7675
|
result.part = entry?.part ?? null;
|
|
7333
7676
|
return result;
|
|
7334
7677
|
}
|
|
@@ -7355,194 +7698,22 @@ function renderExplainText(result) {
|
|
|
7355
7698
|
)
|
|
7356
7699
|
);
|
|
7357
7700
|
if (result.inclusionMode) lines.push(row("inclusion", result.inclusionMode));
|
|
7358
|
-
if (result.encoding) lines.push(row("encoding", result.encoding));
|
|
7359
|
-
lines.push(
|
|
7360
|
-
row(
|
|
7361
|
-
"secrets",
|
|
7362
|
-
result.secretCount ? `${result.secretCount} finding(s): ${Array.from(
|
|
7363
|
-
new Set((result.secrets ?? []).flatMap((secret) => secret.rules))
|
|
7364
|
-
).join(", ")}` : "none"
|
|
7365
|
-
)
|
|
7366
|
-
);
|
|
7367
|
-
return lines.join("\n");
|
|
7368
|
-
}
|
|
7369
|
-
|
|
7370
|
-
// src/wizard/init.ts
|
|
7371
|
-
import * as fs11 from "fs";
|
|
7372
|
-
import * as path11 from "path";
|
|
7373
|
-
|
|
7374
|
-
// src/ast/structured.ts
|
|
7375
|
-
function stripJsonComments2(content) {
|
|
7376
|
-
const text2 = content.replace(/^\uFEFF/, "");
|
|
7377
|
-
const withoutComments = stripComments(text2);
|
|
7378
|
-
return stripTrailingCommas2(withoutComments);
|
|
7379
|
-
}
|
|
7380
|
-
function stripComments(text2) {
|
|
7381
|
-
let out = "";
|
|
7382
|
-
let inString = false;
|
|
7383
|
-
let escaped = false;
|
|
7384
|
-
for (let index = 0; index < text2.length; index += 1) {
|
|
7385
|
-
const char = text2[index];
|
|
7386
|
-
if (inString) {
|
|
7387
|
-
out += char;
|
|
7388
|
-
if (escaped) escaped = false;
|
|
7389
|
-
else if (char === "\\") escaped = true;
|
|
7390
|
-
else if (char === '"') inString = false;
|
|
7391
|
-
continue;
|
|
7392
|
-
}
|
|
7393
|
-
if (char === '"') {
|
|
7394
|
-
inString = true;
|
|
7395
|
-
out += char;
|
|
7396
|
-
continue;
|
|
7397
|
-
}
|
|
7398
|
-
if (char === "/" && text2[index + 1] === "/") {
|
|
7399
|
-
while (index < text2.length && text2[index] !== "\n" && text2[index] !== "\r") index += 1;
|
|
7400
|
-
index -= 1;
|
|
7401
|
-
continue;
|
|
7402
|
-
}
|
|
7403
|
-
if (char === "/" && text2[index + 1] === "*") {
|
|
7404
|
-
index += 2;
|
|
7405
|
-
while (index < text2.length && !(text2[index] === "*" && text2[index + 1] === "/")) {
|
|
7406
|
-
if (text2[index] === "\n" || text2[index] === "\r") out += text2[index];
|
|
7407
|
-
index += 1;
|
|
7408
|
-
}
|
|
7409
|
-
index += 1;
|
|
7410
|
-
continue;
|
|
7411
|
-
}
|
|
7412
|
-
out += char;
|
|
7413
|
-
}
|
|
7414
|
-
return out;
|
|
7415
|
-
}
|
|
7416
|
-
function stripTrailingCommas2(text2) {
|
|
7417
|
-
let out = "";
|
|
7418
|
-
let inString = false;
|
|
7419
|
-
let escaped = false;
|
|
7420
|
-
for (let index = 0; index < text2.length; index += 1) {
|
|
7421
|
-
const char = text2[index];
|
|
7422
|
-
if (inString) {
|
|
7423
|
-
out += char;
|
|
7424
|
-
if (escaped) escaped = false;
|
|
7425
|
-
else if (char === "\\") escaped = true;
|
|
7426
|
-
else if (char === '"') inString = false;
|
|
7427
|
-
continue;
|
|
7428
|
-
}
|
|
7429
|
-
if (char === '"') {
|
|
7430
|
-
inString = true;
|
|
7431
|
-
out += char;
|
|
7432
|
-
continue;
|
|
7433
|
-
}
|
|
7434
|
-
if (char === ",") {
|
|
7435
|
-
let next = index + 1;
|
|
7436
|
-
while (next < text2.length && /\s/.test(text2[next])) next += 1;
|
|
7437
|
-
if (text2[next] === "}" || text2[next] === "]") continue;
|
|
7438
|
-
}
|
|
7439
|
-
out += char;
|
|
7440
|
-
}
|
|
7441
|
-
return out;
|
|
7442
|
-
}
|
|
7443
|
-
function summarizeJson(content) {
|
|
7444
|
-
try {
|
|
7445
|
-
const parsed = JSON.parse(stripJsonComments2(content));
|
|
7446
|
-
if (Array.isArray(parsed)) {
|
|
7447
|
-
const sample = parsed[0];
|
|
7448
|
-
const sampleKeys = sample && typeof sample === "object" && !Array.isArray(sample) ? Object.keys(sample).slice(0, 10).sort() : [];
|
|
7449
|
-
return {
|
|
7450
|
-
shape: "array",
|
|
7451
|
-
itemCount: parsed.length,
|
|
7452
|
-
keys: [],
|
|
7453
|
-
sampleKeys
|
|
7454
|
-
};
|
|
7455
|
-
}
|
|
7456
|
-
if (parsed && typeof parsed === "object") {
|
|
7457
|
-
const keys = Object.keys(parsed).sort();
|
|
7458
|
-
return {
|
|
7459
|
-
shape: "object",
|
|
7460
|
-
itemCount: keys.length,
|
|
7461
|
-
keys: keys.slice(0, 30),
|
|
7462
|
-
sampleKeys: []
|
|
7463
|
-
};
|
|
7464
|
-
}
|
|
7465
|
-
return {
|
|
7466
|
-
shape: typeof parsed,
|
|
7467
|
-
itemCount: null,
|
|
7468
|
-
keys: [],
|
|
7469
|
-
sampleKeys: []
|
|
7470
|
-
};
|
|
7471
|
-
} catch {
|
|
7472
|
-
return {
|
|
7473
|
-
shape: "invalid-json",
|
|
7474
|
-
itemCount: null,
|
|
7475
|
-
keys: [],
|
|
7476
|
-
sampleKeys: []
|
|
7477
|
-
};
|
|
7478
|
-
}
|
|
7479
|
-
}
|
|
7480
|
-
function frontMatterEnd(lines) {
|
|
7481
|
-
if (lines.length < 3 || lines[0].trim() !== "---") return 0;
|
|
7482
|
-
for (let index = 1; index < lines.length; index += 1) {
|
|
7483
|
-
const line = lines[index];
|
|
7484
|
-
const candidate = line.trim();
|
|
7485
|
-
if (candidate === "---" || candidate === "...") {
|
|
7486
|
-
return index > 1 ? index : 0;
|
|
7487
|
-
}
|
|
7488
|
-
if (candidate === "") continue;
|
|
7489
|
-
if (/^#(\s|$)/.test(candidate)) continue;
|
|
7490
|
-
if (/^(`{3,}|~{3,})/.test(candidate)) return 0;
|
|
7491
|
-
if (/^#{1,6}\s+\S/.test(candidate)) return 0;
|
|
7492
|
-
const isYamlMapping = /^[A-Za-z0-9_.-]+\s*:(\s|$)/.test(candidate);
|
|
7493
|
-
const isListItem = /^-(?:(\s|$))/.test(candidate);
|
|
7494
|
-
const isIndented = /^[ \t]/.test(line);
|
|
7495
|
-
if (!isYamlMapping && !isListItem && !isIndented) return 0;
|
|
7496
|
-
}
|
|
7497
|
-
return 0;
|
|
7498
|
-
}
|
|
7499
|
-
function summarizeMarkdown(content) {
|
|
7500
|
-
const headings = [];
|
|
7501
|
-
const frontmatterKeys = [];
|
|
7502
|
-
const lines = content.replace(/^\uFEFF/, "").split(/\r\n|\n|\r/);
|
|
7503
|
-
let inFrontmatter = false;
|
|
7504
|
-
let fence = null;
|
|
7505
|
-
const frontMatterEndLine = frontMatterEnd(lines);
|
|
7506
|
-
for (let index = 0; index < lines.length; index++) {
|
|
7507
|
-
const line = lines[index];
|
|
7508
|
-
if (index === 0 && frontMatterEndLine > 0) {
|
|
7509
|
-
inFrontmatter = true;
|
|
7510
|
-
continue;
|
|
7511
|
-
}
|
|
7512
|
-
if (inFrontmatter) {
|
|
7513
|
-
const trimmedFrontmatter = line.trim();
|
|
7514
|
-
if (trimmedFrontmatter === "---" || trimmedFrontmatter === "...") {
|
|
7515
|
-
inFrontmatter = false;
|
|
7516
|
-
continue;
|
|
7517
|
-
}
|
|
7518
|
-
const match = /^([A-Za-z0-9_.-]+)\s*:/.exec(line);
|
|
7519
|
-
if (match) frontmatterKeys.push(match[1]);
|
|
7520
|
-
continue;
|
|
7521
|
-
}
|
|
7522
|
-
const trimmed = line.trim();
|
|
7523
|
-
const fenceMatch = /^(`{3,}|~{3,})(.*)$/.exec(trimmed);
|
|
7524
|
-
if (fenceMatch) {
|
|
7525
|
-
const run = fenceMatch[1];
|
|
7526
|
-
const rest = fenceMatch[2].trim();
|
|
7527
|
-
if (fence === null) {
|
|
7528
|
-
fence = { marker: run[0], length: run.length };
|
|
7529
|
-
} else if (run[0] === fence.marker && run.length >= fence.length && rest === "") {
|
|
7530
|
-
fence = null;
|
|
7531
|
-
}
|
|
7532
|
-
continue;
|
|
7533
|
-
}
|
|
7534
|
-
if (fence !== null) continue;
|
|
7535
|
-
const headingMatch = /^(#{1,6})\s+(.+)$/.exec(trimmed);
|
|
7536
|
-
if (headingMatch) {
|
|
7537
|
-
headings.push(`${headingMatch[1]} ${headingMatch[2].trim()}`);
|
|
7538
|
-
}
|
|
7539
|
-
}
|
|
7540
|
-
return {
|
|
7541
|
-
headings: headings.slice(0, 40),
|
|
7542
|
-
frontmatterKeys: Array.from(new Set(frontmatterKeys)).sort()
|
|
7543
|
-
};
|
|
7701
|
+
if (result.encoding) lines.push(row("encoding", result.encoding));
|
|
7702
|
+
lines.push(
|
|
7703
|
+
row(
|
|
7704
|
+
"secrets",
|
|
7705
|
+
result.secretCount ? `${result.secretCount} finding(s): ${Array.from(
|
|
7706
|
+
new Set((result.secrets ?? []).flatMap((secret) => secret.rules))
|
|
7707
|
+
).join(", ")}` : "none"
|
|
7708
|
+
)
|
|
7709
|
+
);
|
|
7710
|
+
return lines.join("\n");
|
|
7544
7711
|
}
|
|
7545
7712
|
|
|
7713
|
+
// src/wizard/init.ts
|
|
7714
|
+
import * as fs11 from "fs";
|
|
7715
|
+
import * as path11 from "path";
|
|
7716
|
+
|
|
7546
7717
|
// src/gitignore.ts
|
|
7547
7718
|
import * as fs10 from "fs";
|
|
7548
7719
|
import * as path10 from "path";
|
|
@@ -7652,6 +7823,7 @@ var DEFAULT_ANSWERS = {
|
|
|
7652
7823
|
excludePatterns: [],
|
|
7653
7824
|
artifacts: {
|
|
7654
7825
|
readme: true,
|
|
7826
|
+
prompt: true,
|
|
7655
7827
|
manifest: true,
|
|
7656
7828
|
parts: true,
|
|
7657
7829
|
navigation: true,
|
|
@@ -7760,10 +7932,15 @@ function renderConfig(answers) {
|
|
|
7760
7932
|
// Set true to drop the built-in rules above and keep only customPatterns.
|
|
7761
7933
|
disableDefaultPatterns: false,
|
|
7762
7934
|
},
|
|
7935
|
+
// The library spelling of the same list, accepted here too so a config file can
|
|
7936
|
+
// express what a caller passes in code: an array of { rule, pattern } or a bare
|
|
7937
|
+
// RegExp. Use \`secrets.customPatterns\` above unless you are porting code.
|
|
7938
|
+
// secretRules: [],
|
|
7763
7939
|
|
|
7764
7940
|
// \u2500\u2500 Artifacts \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500
|
|
7765
7941
|
artifacts: {
|
|
7766
7942
|
readme: ${artifacts.readme}, // README.md
|
|
7943
|
+
prompt: ${artifacts.prompt}, // PROMPT.md \u2014 the instruction sheet a model is given
|
|
7767
7944
|
manifest: ${artifacts.manifest}, // manifest.json \u2014 required by validate and report
|
|
7768
7945
|
parts: ${artifacts.parts}, // parts/part-XXX.md
|
|
7769
7946
|
navigation: ${artifacts.navigation}, // reports/navigation.md
|
|
@@ -7779,6 +7956,11 @@ function renderConfig(answers) {
|
|
|
7779
7956
|
includeMonolith: ${artifacts.monolith},
|
|
7780
7957
|
|
|
7781
7958
|
// \u2500\u2500 Advanced \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500
|
|
7959
|
+
// Files your destination accepts in one message, used by PROMPT.md to plan the delivery.
|
|
7960
|
+
// attachmentSlots: 10,
|
|
7961
|
+
// Experimental: grow the per-part budget until the snapshot fits this many parts, instead of
|
|
7962
|
+
// adding a part as the code grows. The plan in PROMPT.md becomes a fixed-length attachment list.
|
|
7963
|
+
// maxParts: 10,
|
|
7782
7964
|
// afterGenerate: (manifest) => { /* write your own artifact */ }
|
|
7783
7965
|
hooks: {},
|
|
7784
7966
|
};
|
|
@@ -7950,7 +8132,7 @@ function keyReader(input) {
|
|
|
7950
8132
|
next() {
|
|
7951
8133
|
const queued = queue.shift();
|
|
7952
8134
|
if (queued) return Promise.resolve(queued);
|
|
7953
|
-
return new Promise((
|
|
8135
|
+
return new Promise((resolve12) => waiters.push(resolve12));
|
|
7954
8136
|
},
|
|
7955
8137
|
close() {
|
|
7956
8138
|
input.off("keypress", onKey);
|
|
@@ -8168,7 +8350,7 @@ var CONFIG_CANDIDATES = [
|
|
|
8168
8350
|
".snapshotrc"
|
|
8169
8351
|
];
|
|
8170
8352
|
function parsePackageJson(raw) {
|
|
8171
|
-
const parsed = JSON.parse(
|
|
8353
|
+
const parsed = JSON.parse(stripJsonComments(raw));
|
|
8172
8354
|
if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) {
|
|
8173
8355
|
throw new Error("package.json is not a JSON object");
|
|
8174
8356
|
}
|
|
@@ -8379,7 +8561,18 @@ function updatePackageJson(cwd, notes) {
|
|
|
8379
8561
|
writeFileOrExplain(packagePath, serializePackageJson(raw, parsed));
|
|
8380
8562
|
return { scripts: added, dependency };
|
|
8381
8563
|
}
|
|
8382
|
-
|
|
8564
|
+
function gitignoreEntriesFor(cwd, outDir, tmpDir) {
|
|
8565
|
+
const entries = [];
|
|
8566
|
+
for (const directory of [outDir, tmpDir]) {
|
|
8567
|
+
if (directory === null) continue;
|
|
8568
|
+
const relative15 = path11.relative(cwd, path11.resolve(cwd, directory)).replace(/\\/g, "/");
|
|
8569
|
+
if (relative15 === "" || relative15 === "." || relative15.startsWith("..") || path11.isAbsolute(relative15)) {
|
|
8570
|
+
continue;
|
|
8571
|
+
}
|
|
8572
|
+
entries.push(`/${relative15}/`);
|
|
8573
|
+
}
|
|
8574
|
+
return [...new Set(entries)];
|
|
8575
|
+
}
|
|
8383
8576
|
function resolvePresetChoice(detectedName, presetName) {
|
|
8384
8577
|
return {
|
|
8385
8578
|
value: presetName,
|
|
@@ -8461,6 +8654,7 @@ async function runInit(options) {
|
|
|
8461
8654
|
let lastScope = "all";
|
|
8462
8655
|
const artifactChoices = [
|
|
8463
8656
|
{ value: "readme", label: "README.md", hint: "orientation page" },
|
|
8657
|
+
{ value: "prompt", label: "PROMPT.md", hint: "instruction sheet for the model" },
|
|
8464
8658
|
{ value: "manifest", label: "manifest.json", hint: "required by validate and report" },
|
|
8465
8659
|
{ value: "parts", label: "parts/", hint: "the code payload" },
|
|
8466
8660
|
{ value: "navigation", label: "reports/navigation.md", hint: "file \u2192 part index" },
|
|
@@ -8672,7 +8866,10 @@ async function runInit(options) {
|
|
|
8672
8866
|
}
|
|
8673
8867
|
if (!reused) writeFileOrExplain(configPath, configText);
|
|
8674
8868
|
const { scripts, dependency } = updatePackageJson(options.cwd, notes);
|
|
8675
|
-
const ignore = appendGitignoreEntries(
|
|
8869
|
+
const ignore = appendGitignoreEntries(
|
|
8870
|
+
options.cwd,
|
|
8871
|
+
gitignoreEntriesFor(options.cwd, answers.outDir, options.tmpDir ?? (reused ? null : "snapshot.tmp"))
|
|
8872
|
+
);
|
|
8676
8873
|
if (ignore.note !== null) notes.push(ignore.note);
|
|
8677
8874
|
return {
|
|
8678
8875
|
configPath,
|
|
@@ -8694,10 +8891,10 @@ async function runInit(options) {
|
|
|
8694
8891
|
import * as fs12 from "fs";
|
|
8695
8892
|
import * as path12 from "path";
|
|
8696
8893
|
function describeTarget(cwd) {
|
|
8697
|
-
const
|
|
8698
|
-
if (
|
|
8699
|
-
if (
|
|
8700
|
-
return
|
|
8894
|
+
const relative15 = path12.relative(process.cwd(), cwd);
|
|
8895
|
+
if (relative15 === "") return "this directory";
|
|
8896
|
+
if (relative15.startsWith("..") || path12.isAbsolute(relative15)) return cwd;
|
|
8897
|
+
return relative15;
|
|
8701
8898
|
}
|
|
8702
8899
|
function firstRunMessage(reason, cwd) {
|
|
8703
8900
|
const where = describeTarget(cwd);
|
|
@@ -8904,7 +9101,7 @@ function generateAuditReport(manifest, secretFindings, secretRules) {
|
|
|
8904
9101
|
);
|
|
8905
9102
|
for (const file of affected) {
|
|
8906
9103
|
const status = file.isPreviewTruncated ? "Truncated" : "Full";
|
|
8907
|
-
const cutBy = file.truncationReason === "part-budget" ? "maxPartBytes" : "largeFileBytes";
|
|
9104
|
+
const cutBy = file.truncationReason === "part-budget" ? "part budget (maxPartBytes)" : "large-file budget (largeFileBytes)";
|
|
8908
9105
|
lines.push(
|
|
8909
9106
|
`| ${code(file.relativePath)} | ${file.sizeBytes} | ${file.lines} | ${file.includedBytes} | ${file.includedLines} | ${status} | ${cutBy} |`
|
|
8910
9107
|
);
|
|
@@ -9020,11 +9217,11 @@ function generateSarifReport(manifest, findings, rules, toolVersion) {
|
|
|
9020
9217
|
codebaseSnapshotFinding: `${findingPath}#L${line}#${finding.rules.join("+")}`
|
|
9021
9218
|
}
|
|
9022
9219
|
};
|
|
9023
|
-
}).sort(
|
|
9024
|
-
|
|
9025
|
-
|
|
9026
|
-
) || a.locations[0].physicalLocation.region.startLine - b.locations[0].physicalLocation.region.startLine
|
|
9027
|
-
);
|
|
9220
|
+
}).sort((a, b) => {
|
|
9221
|
+
const left = a.locations[0].physicalLocation.artifactLocation.uri;
|
|
9222
|
+
const right = b.locations[0].physicalLocation.artifactLocation.uri;
|
|
9223
|
+
return (left < right ? -1 : left > right ? 1 : 0) || a.locations[0].physicalLocation.region.startLine - b.locations[0].physicalLocation.region.startLine;
|
|
9224
|
+
});
|
|
9028
9225
|
const log = {
|
|
9029
9226
|
$schema: SARIF_SCHEMA,
|
|
9030
9227
|
version: SARIF_VERSION,
|
|
@@ -9056,6 +9253,7 @@ function generateSarifReport(manifest, findings, rules, toolVersion) {
|
|
|
9056
9253
|
import * as crypto3 from "crypto";
|
|
9057
9254
|
var HEADER_RESERVE_BYTES = 2048 + Buffer.byteLength(UNTRUSTED_CONTENT_NOTICE, "utf8") + 8;
|
|
9058
9255
|
var MIN_SECTION_BUDGET_BYTES = 512;
|
|
9256
|
+
var MIN_PART_BUDGET_BYTES = MIN_SECTION_BUDGET_BYTES + HEADER_RESERVE_BYTES;
|
|
9059
9257
|
var MAX_SPLIT_PASSES = 64;
|
|
9060
9258
|
var BUDGET_MARKER_RESERVE = 96;
|
|
9061
9259
|
function insertTokenLine(markdown, tokens) {
|
|
@@ -9094,10 +9292,17 @@ function partitionFilesForBuckets(buckets, contentFingerprint) {
|
|
|
9094
9292
|
const groups = [];
|
|
9095
9293
|
for (const bucket of buckets) {
|
|
9096
9294
|
if (bucket.files.length === 0) continue;
|
|
9097
|
-
|
|
9098
|
-
|
|
9099
|
-
|
|
9100
|
-
|
|
9295
|
+
if (!Number.isFinite(bucket.budgetBytes)) {
|
|
9296
|
+
throw new Error(
|
|
9297
|
+
`A part budget must be a finite number of bytes; received ${String(bucket.budgetBytes)}.`
|
|
9298
|
+
);
|
|
9299
|
+
}
|
|
9300
|
+
if (bucket.budgetBytes < MIN_PART_BUDGET_BYTES) {
|
|
9301
|
+
throw new Error(
|
|
9302
|
+
`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.`
|
|
9303
|
+
);
|
|
9304
|
+
}
|
|
9305
|
+
const budget = bucket.budgetBytes;
|
|
9101
9306
|
const sectionBudget = budget - HEADER_RESERVE_BYTES;
|
|
9102
9307
|
const prepared = bucket.files.map((file) => prepareSection(file, sectionBudget, budget));
|
|
9103
9308
|
for (const sections of greedyGroups(prepared, budget)) groups.push({ sections, budget });
|
|
@@ -9565,10 +9770,420 @@ function generateNavigation(manifest) {
|
|
|
9565
9770
|
return lines.join("\n");
|
|
9566
9771
|
}
|
|
9567
9772
|
|
|
9773
|
+
// src/generator/prompt.ts
|
|
9774
|
+
var MAX_PART_ROWS = 16;
|
|
9775
|
+
var MAX_LAYER_ROWS = 8;
|
|
9776
|
+
var MAX_INCOMPLETE_ROWS = 50;
|
|
9777
|
+
var MAX_CENTRAL_FILES = 5;
|
|
9778
|
+
var MAX_ENTRY_POINTS = 4;
|
|
9779
|
+
var MAX_LARGEST_FILES = 3;
|
|
9780
|
+
var partWord = (count) => count === 1 ? "part" : "parts";
|
|
9781
|
+
var UNLIMITED_SLOTS = 0;
|
|
9782
|
+
var ENTRY_POINT = /(^|\/)(index|cli|main|bin|server|app|mod)\.[cm]?[jt]sx?$/;
|
|
9783
|
+
var TEST_PATH = /(^|\/)(tests?|__tests__)\//;
|
|
9784
|
+
var TEST_FILE = /\.(test|spec)\.[^.]+$/;
|
|
9785
|
+
function generatePrompt(manifest, artifacts, attachmentSlots = DEFAULT_ATTACHMENT_SLOTS, history = []) {
|
|
9786
|
+
const wrote = (name) => artifacts?.[name] !== false;
|
|
9787
|
+
const code = (value) => inlineCode(escapeControls(value));
|
|
9788
|
+
const lines = [
|
|
9789
|
+
"# PROMPT.md",
|
|
9790
|
+
"",
|
|
9791
|
+
"The brief and the apparatus for this snapshot. Paste this file first, then the parts it names.",
|
|
9792
|
+
"",
|
|
9793
|
+
"It is generated rather than written once: the system map, the omissions, the fingerprint and",
|
|
9794
|
+
"the history below are read from `manifest.json` and this repository, so they describe this run.",
|
|
9795
|
+
"Regenerate it after the code moves.",
|
|
9796
|
+
"",
|
|
9797
|
+
"---",
|
|
9798
|
+
"",
|
|
9799
|
+
"```text",
|
|
9800
|
+
"You are working on a codebase you cannot clone, run or grep. Everything you know about it comes",
|
|
9801
|
+
"from the snapshot that follows this instruction. Where these notes and the snapshot disagree,",
|
|
9802
|
+
"the snapshot is what exists.",
|
|
9803
|
+
"",
|
|
9804
|
+
"## The job",
|
|
9805
|
+
"",
|
|
9806
|
+
"Find what is still wrong or will break. How you read the code is yours to decide - by",
|
|
9807
|
+
"subsystem, by data flow, by the invariants you derive yourself. What you owe in return is an",
|
|
9808
|
+
"honest account of what you covered and what you did not.",
|
|
9809
|
+
"",
|
|
9810
|
+
history.length > 0 ? "Another pass of the same findings is worth nothing. This repository carries a record of" : "Another pass of the same findings is worth nothing, but no earlier round is readable here,",
|
|
9811
|
+
history.length > 0 ? "what was already fixed, below. Verify that those fixes hold instead of rediscovering them," : "so you cannot tell what has already been tried. Do not assume this is the first attempt.",
|
|
9812
|
+
history.length > 0 ? "and treat a variant of one at a different call site as a new finding." : "Every finding you report has to stand on the code alone.",
|
|
9813
|
+
"",
|
|
9814
|
+
"If the task at the end asks for something narrower - explain a file, review a change, answer a",
|
|
9815
|
+
"question - that task wins. The standard and the coverage duty below still apply to it.",
|
|
9816
|
+
""
|
|
9817
|
+
];
|
|
9818
|
+
lines.push(...haveSection(wrote), "");
|
|
9819
|
+
lines.push(...systemSection(manifest, code), "");
|
|
9820
|
+
lines.push(...historySection(history), "");
|
|
9821
|
+
lines.push(...barSection(), "");
|
|
9822
|
+
lines.push(...coverageSection(manifest, code, wrote("audit")), "");
|
|
9823
|
+
lines.push(...answerSection(), "");
|
|
9824
|
+
lines.push(...calibrationSection(), "");
|
|
9825
|
+
lines.push(...snapshotSection(manifest, code), "");
|
|
9826
|
+
lines.push(...deliverySection(manifest, wrote("parts"), attachmentSlots));
|
|
9827
|
+
lines.push(
|
|
9828
|
+
"## Your task",
|
|
9829
|
+
"",
|
|
9830
|
+
"<replace with the question, the area to review, or the subsystem to audit>",
|
|
9831
|
+
"```"
|
|
9832
|
+
);
|
|
9833
|
+
lines.push(
|
|
9834
|
+
"",
|
|
9835
|
+
"---",
|
|
9836
|
+
"",
|
|
9837
|
+
"## Why this file exists",
|
|
9838
|
+
"",
|
|
9839
|
+
"Parts on their own are a dump: the model receives text, has no idea what was left out of it,",
|
|
9840
|
+
"and fills the gap by invention. A brief on its own is a wish list: it cannot say which files",
|
|
9841
|
+
"are present, which are partial or which part holds what. This file is both halves, and the",
|
|
9842
|
+
"facts in it move with the snapshot.",
|
|
9843
|
+
"",
|
|
9844
|
+
"## Keeping it true",
|
|
9845
|
+
"",
|
|
9846
|
+
"- It is one of the artifacts recorded in `manifest.json` under `artifacts.prompt`, so deleting",
|
|
9847
|
+
" or editing `PROMPT.md` makes `snapshot validate` fail.",
|
|
9848
|
+
"- `--skip-artifacts prompt`, or `artifacts: { prompt: false }` in the config, turns it off.",
|
|
9849
|
+
"- The history section disappears when git cannot be read, rather than being invented.",
|
|
9850
|
+
"- If the code moves, regenerate. A brief naming the previous run parts is worse than no",
|
|
9851
|
+
" brief, because it reads as current.",
|
|
9852
|
+
""
|
|
9853
|
+
);
|
|
9854
|
+
return lines.join("\n");
|
|
9855
|
+
}
|
|
9856
|
+
function haveSection(wrote) {
|
|
9857
|
+
const out = ["## What you have", ""];
|
|
9858
|
+
const bullets = [];
|
|
9859
|
+
if (wrote("readme")) {
|
|
9860
|
+
bullets.push("- `README.md` - orientation: metrics, the part table, and the fingerprint.");
|
|
9861
|
+
}
|
|
9862
|
+
if (wrote("manifest")) {
|
|
9863
|
+
bullets.push(
|
|
9864
|
+
"- `manifest.json` - the index. Per file: `relativePath`, `layer`, `kind`, `language`,",
|
|
9865
|
+
" `part`, `sha256`, `inclusionMode`, `truncationReason`, `omittedRanges`. It also carries",
|
|
9866
|
+
" every excluded path under `skipped[]` with its reason, and `incomplete[]`, which names",
|
|
9867
|
+
" every included file whose emitted body is not the whole file."
|
|
9868
|
+
);
|
|
9869
|
+
}
|
|
9870
|
+
if (wrote("navigation")) {
|
|
9871
|
+
bullets.push("- `reports/navigation.md` - file to part. Locate here before you read anything.");
|
|
9872
|
+
}
|
|
9873
|
+
if (wrote("projectTree")) {
|
|
9874
|
+
bullets.push("- `reports/project-tree.md` - the directory shape of what was included.");
|
|
9875
|
+
}
|
|
9876
|
+
if (wrote("audit")) {
|
|
9877
|
+
bullets.push(
|
|
9878
|
+
"- `reports/audit.md` - secret findings, the files whose lines were redacted, large files,",
|
|
9879
|
+
" parse diagnostics and the git state the snapshot was taken from."
|
|
9880
|
+
);
|
|
9881
|
+
}
|
|
9882
|
+
if (wrote("parts")) {
|
|
9883
|
+
bullets.push(
|
|
9884
|
+
"- `parts/part-NNN.md` - the code itself, split to a fixed byte budget. Each part states its",
|
|
9885
|
+
" own number, the files it contains, and the fingerprint it was built from."
|
|
9886
|
+
);
|
|
9887
|
+
}
|
|
9888
|
+
if (wrote("monolith")) {
|
|
9889
|
+
bullets.push(
|
|
9890
|
+
"- `full-codebase.json` and `full-codebase.md` - the entire payload in one file each.",
|
|
9891
|
+
" Where they are present, they supersede the parts: nothing was left out of them."
|
|
9892
|
+
);
|
|
9893
|
+
}
|
|
9894
|
+
if (bullets.length === 0) {
|
|
9895
|
+
bullets.push(
|
|
9896
|
+
"- Nothing but this brief: every code artifact was disabled for this run. Ask for a snapshot",
|
|
9897
|
+
" generated with the artifacts you need, and do not answer from memory."
|
|
9898
|
+
);
|
|
9899
|
+
}
|
|
9900
|
+
out.push(...bullets);
|
|
9901
|
+
return out;
|
|
9902
|
+
}
|
|
9903
|
+
function systemSection(manifest, code) {
|
|
9904
|
+
const out = ["## The system", ""];
|
|
9905
|
+
const layers = Object.entries(manifest.layers).sort((a, b) => b[1] - a[1] || a[0].localeCompare(b[0]));
|
|
9906
|
+
if (layers.length > 0) {
|
|
9907
|
+
const shown = layers.slice(0, MAX_LAYER_ROWS).map(([name, count]) => code(name) + " " + formatNumber(count));
|
|
9908
|
+
const rest = layers.length > MAX_LAYER_ROWS ? ", and " + formatNumber(layers.length - MAX_LAYER_ROWS) + " more" : "";
|
|
9909
|
+
out.push("- Layers, by file count: " + shown.join(", ") + rest + ".");
|
|
9910
|
+
}
|
|
9911
|
+
const central = manifest.indexes.imports.centralFiles;
|
|
9912
|
+
if (central.length > 0) {
|
|
9913
|
+
const shown = central.slice(0, MAX_CENTRAL_FILES).map((entry) => code(entry.path) + " (" + formatNumber(entry.importedByCount) + ")").join(", ");
|
|
9914
|
+
out.push(
|
|
9915
|
+
"- Load-bearing modules, by how many files import them: " + shown + ".",
|
|
9916
|
+
" A change here reaches the most call sites; read it before judging anything that uses it."
|
|
9917
|
+
);
|
|
9918
|
+
}
|
|
9919
|
+
const entryPoints = manifest.files.map((file) => file.relativePath).filter((path22) => ENTRY_POINT.test(path22)).sort((a, b) => a.split("/").length - b.split("/").length || a.length - b.length).slice(0, MAX_ENTRY_POINTS);
|
|
9920
|
+
out.push(
|
|
9921
|
+
entryPoints.length > 0 ? "- Entry points by convention: " + entryPoints.map(code).join(", ") + "." : "- No entry point was identifiable by name. The largest files below are where execution"
|
|
9922
|
+
);
|
|
9923
|
+
if (entryPoints.length === 0) out.push(" starts, and the call graph in `manifest.json` is the map.");
|
|
9924
|
+
const routes = manifest.indexes.routes.length;
|
|
9925
|
+
const handlers = manifest.indexes.handlers.length;
|
|
9926
|
+
const components = manifest.indexes.components.length;
|
|
9927
|
+
const routesShown = manifest.indexes.routes.slice(0, 4).map((route) => code(route.path));
|
|
9928
|
+
const componentsShown = manifest.indexes.components.slice(0, 4).map((entry) => code(entry.path));
|
|
9929
|
+
if (routes + handlers + components === 0) {
|
|
9930
|
+
out.push(
|
|
9931
|
+
"- No routes, handlers or UI components were recorded: this snapshot indexes no HTTP or",
|
|
9932
|
+
" component surface. Do not go looking for one, and do not infer one from a file name."
|
|
9933
|
+
);
|
|
9934
|
+
} else {
|
|
9935
|
+
const parts = [];
|
|
9936
|
+
if (routes > 0) parts.push(formatNumber(routes) + " route(s), e.g. " + routesShown.join(", "));
|
|
9937
|
+
if (handlers > 0) parts.push(formatNumber(handlers) + " handler(s)");
|
|
9938
|
+
if (components > 0) parts.push(formatNumber(components) + " component(s), e.g. " + componentsShown.join(", "));
|
|
9939
|
+
out.push("- Surfaces the index found: " + parts.join("; ") + ".");
|
|
9940
|
+
}
|
|
9941
|
+
const largest = [...manifest.files].sort((a, b) => b.includedBytes - a.includedBytes).slice(0, MAX_LARGEST_FILES);
|
|
9942
|
+
if (largest.length > 0) {
|
|
9943
|
+
out.push(
|
|
9944
|
+
"- Largest files: " + largest.map((file) => code(file.relativePath) + " (" + formatNumber(Math.round(file.includedBytes / 1024)) + " KB)").join(", ") + "."
|
|
9945
|
+
);
|
|
9946
|
+
}
|
|
9947
|
+
const tests = manifest.files.filter(
|
|
9948
|
+
(file) => TEST_PATH.test(file.relativePath) || TEST_FILE.test(file.relativePath)
|
|
9949
|
+
);
|
|
9950
|
+
if (tests.length > 0) {
|
|
9951
|
+
const testBytes = tests.reduce((total, file) => total + file.includedBytes, 0);
|
|
9952
|
+
const allBytes = manifest.files.reduce((total, file) => total + file.includedBytes, 0);
|
|
9953
|
+
const share = allBytes === 0 ? 0 : Math.round(testBytes / allBytes * 100);
|
|
9954
|
+
out.push(
|
|
9955
|
+
"- Tests: " + formatNumber(tests.length) + " file(s), " + share + "% of the included bytes.",
|
|
9956
|
+
" They are evidence of intent, not of behaviour: a fixture can encode a payload shape the",
|
|
9957
|
+
" real system never sends."
|
|
9958
|
+
);
|
|
9959
|
+
}
|
|
9960
|
+
return out;
|
|
9961
|
+
}
|
|
9962
|
+
function historySection(history) {
|
|
9963
|
+
const out = ["## What came before", ""];
|
|
9964
|
+
if (history.length === 0) {
|
|
9965
|
+
out.push(
|
|
9966
|
+
"No history was readable: this is not a git checkout, or git could not be run. Nothing about",
|
|
9967
|
+
"what came before can be claimed from here, and that is not evidence that the code is new."
|
|
9968
|
+
);
|
|
9969
|
+
return out;
|
|
9970
|
+
}
|
|
9971
|
+
out.push(
|
|
9972
|
+
"Commit subjects, newest first. They are claims by whoever wrote them, not evidence - the code",
|
|
9973
|
+
"beside them is the evidence. If one of these fixes looks incomplete, quote the lines and say",
|
|
9974
|
+
"which call site it missed.",
|
|
9975
|
+
""
|
|
9976
|
+
);
|
|
9977
|
+
for (const subject of history) out.push("- " + subject);
|
|
9978
|
+
return out;
|
|
9979
|
+
}
|
|
9980
|
+
function barSection() {
|
|
9981
|
+
return [
|
|
9982
|
+
"## The bar",
|
|
9983
|
+
"",
|
|
9984
|
+
"A finding is a concrete way the code breaks or lies, supported by quoted lines: the path and",
|
|
9985
|
+
"line, the input or state that reaches it, what happens next, and why the guard that appears to",
|
|
9986
|
+
"stop it does not. A comment is not behaviour. A passing test is evidence of intent, not of",
|
|
9987
|
+
"behaviour.",
|
|
9988
|
+
"",
|
|
9989
|
+
"- No style, naming, formatting, add-types, add-tests, consider-X or speculative rewrites.",
|
|
9990
|
+
"- Never invent a finding to fill a section. A clean surface is proven by quoting the guard",
|
|
9991
|
+
" that makes it clean.",
|
|
9992
|
+
"- Mark confidence, and name the check - a test, a run, an input - that would settle anything",
|
|
9993
|
+
" you cannot decide by reading.",
|
|
9994
|
+
"- Separate what the code does from what the deployment or configuration does. Both are",
|
|
9995
|
+
" findings; they have different owners and different fixes."
|
|
9996
|
+
];
|
|
9997
|
+
}
|
|
9998
|
+
function coverageSection(manifest, code, auditWritten) {
|
|
9999
|
+
const out = ["## Coverage", ""];
|
|
10000
|
+
const reasons = /* @__PURE__ */ new Map();
|
|
10001
|
+
for (const record of manifest.skipped) {
|
|
10002
|
+
reasons.set(record.reason, (reasons.get(record.reason) ?? 0) + 1);
|
|
10003
|
+
}
|
|
10004
|
+
const tally = [...reasons.entries()].sort((a, b) => b[1] - a[1] || a[0].localeCompare(b[0])).map(([reason, count]) => code(reason) + " " + formatNumber(count)).join(", ");
|
|
10005
|
+
out.push(
|
|
10006
|
+
"- " + formatNumber(manifest.totals.candidateFiles) + " path(s) were found; " + formatNumber(manifest.totals.includedFiles) + " are in the parts and " + formatNumber(manifest.counts.skippedCount) + " were skipped" + (tally.length > 0 ? " (" + tally + ")" : "") + ".",
|
|
10007
|
+
" `manifest.skipped[]` names each one and why. An absent path is not a clean path."
|
|
10008
|
+
);
|
|
10009
|
+
out.push(...incompleteSection(manifest, code));
|
|
10010
|
+
out.push(...redactionSection(manifest, auditWritten));
|
|
10011
|
+
out.push(
|
|
10012
|
+
"- Everything unseen is unread, never clean. If you were given only some of the parts, say",
|
|
10013
|
+
" which ones are missing before you answer. A file the index names but the parts do not carry",
|
|
10014
|
+
" is an input defect, not a code finding - report it as one."
|
|
10015
|
+
);
|
|
10016
|
+
return out;
|
|
10017
|
+
}
|
|
10018
|
+
function answerSection() {
|
|
10019
|
+
return [
|
|
10020
|
+
"## What a useful answer contains",
|
|
10021
|
+
"",
|
|
10022
|
+
"- An opening line, filled from This snapshot below:",
|
|
10023
|
+
"",
|
|
10024
|
+
" snapshot <fingerprint> generated <generatedAt>",
|
|
10025
|
+
"",
|
|
10026
|
+
"- What you read and what you did not, named by path or by part.",
|
|
10027
|
+
"- Findings ordered by consequence, each with the lines quoted.",
|
|
10028
|
+
"- The checks or attacks that failed, and the line or guard that blocked them. A failed attack",
|
|
10029
|
+
" is how anyone knows an invariant is real rather than asserted.",
|
|
10030
|
+
"- What you retracted after re-reading.",
|
|
10031
|
+
"- What only a run, a test or a host can settle, and the check that would settle each.",
|
|
10032
|
+
"- One paragraph on the failure you would bet on next.",
|
|
10033
|
+
"- A closing line: Needed but not received: <paths>, or none. That line is not decoration -",
|
|
10034
|
+
" an invented function is indistinguishable from a real one, and this is where you name",
|
|
10035
|
+
" the gap you filled by asking instead of guessing."
|
|
10036
|
+
];
|
|
10037
|
+
}
|
|
10038
|
+
function calibrationSection() {
|
|
10039
|
+
return [
|
|
10040
|
+
"## Calibration",
|
|
10041
|
+
"",
|
|
10042
|
+
"The findings that matter here do not crash. They look like:",
|
|
10043
|
+
"",
|
|
10044
|
+
"- a guard applied at one call site and not its twin - the route checks, the timer does not;",
|
|
10045
|
+
"- a budget shorter than the work it guards, so the caller gives up while the work continues;",
|
|
10046
|
+
"- a success flag that means the call returned, consumed as the change happened;",
|
|
10047
|
+
"- a document that describes a different run than the one beside it;",
|
|
10048
|
+
"- a default that fabricates a number when the measurement failed.",
|
|
10049
|
+
"",
|
|
10050
|
+
"None of these throw. All are invisible in a summary."
|
|
10051
|
+
];
|
|
10052
|
+
}
|
|
10053
|
+
function snapshotSection(manifest, code) {
|
|
10054
|
+
const out = ["## This snapshot", ""];
|
|
10055
|
+
out.push("- Fingerprint: " + code(manifest.fingerprint) + " - quote it verbatim in your answer.");
|
|
10056
|
+
out.push(
|
|
10057
|
+
"- Generated: " + code(manifest.generatedAt) + " from branch " + code(manifest.git.branch) + " at commit " + code(manifest.git.commit.slice(0, 8)) + "."
|
|
10058
|
+
);
|
|
10059
|
+
out.push(
|
|
10060
|
+
manifest.git.isDirty ? " The working tree had uncommitted changes at generation time." : " The working tree was clean at generation time."
|
|
10061
|
+
);
|
|
10062
|
+
out.push(
|
|
10063
|
+
"- Validation: `manifest.validation.status` was " + code(manifest.validation.status) + " at generation time.",
|
|
10064
|
+
" That describes the run, not now: if the tree may have moved since, the snapshot is a",
|
|
10065
|
+
" claim that needs re-checking, not a fact."
|
|
10066
|
+
);
|
|
10067
|
+
if (manifest.parts.length > 0) {
|
|
10068
|
+
out.push(
|
|
10069
|
+
"- Parts: " + formatNumber(manifest.parts.length) + " at a " + formatNumber(Math.round(manifest.budgets.maxPartBytes / 1024)) + " KB ceiling" + (manifest.parts.length === 1 ? ":" : " each:")
|
|
10070
|
+
);
|
|
10071
|
+
for (const part of manifest.parts.slice(0, MAX_PART_ROWS)) {
|
|
10072
|
+
out.push(" - " + code(part.filename) + " - " + formatNumber(part.fileCount) + " file(s)");
|
|
10073
|
+
}
|
|
10074
|
+
if (manifest.parts.length > MAX_PART_ROWS) {
|
|
10075
|
+
out.push(
|
|
10076
|
+
" - and " + formatNumber(manifest.parts.length - MAX_PART_ROWS) + " more, tabled in `README.md`"
|
|
10077
|
+
);
|
|
10078
|
+
}
|
|
10079
|
+
}
|
|
10080
|
+
return out;
|
|
10081
|
+
}
|
|
10082
|
+
function incompleteSection(manifest, code) {
|
|
10083
|
+
const out = [];
|
|
10084
|
+
const list2 = manifest.incomplete;
|
|
10085
|
+
if (list2.length === 0) {
|
|
10086
|
+
out.push("- Partial files: none. Every included file is present in full.");
|
|
10087
|
+
return out;
|
|
10088
|
+
}
|
|
10089
|
+
out.push(
|
|
10090
|
+
"- Partial files: " + formatNumber(list2.length) + ". These are present only in part, and the",
|
|
10091
|
+
" missing lines are named, not implied:"
|
|
10092
|
+
);
|
|
10093
|
+
for (const entry of list2.slice(0, MAX_INCOMPLETE_ROWS)) {
|
|
10094
|
+
const ranges = entry.omittedRanges.map(([start, end]) => start === end ? String(start) : start + "-" + end).join(", ");
|
|
10095
|
+
out.push(
|
|
10096
|
+
" - " + code(entry.relativePath) + " in " + code(entry.part) + " - " + entry.reason + ", lines " + ranges + " (" + formatNumber(entry.omittedLines) + " of " + formatNumber(entry.lines) + " missing)"
|
|
10097
|
+
);
|
|
10098
|
+
}
|
|
10099
|
+
if (list2.length > MAX_INCOMPLETE_ROWS) {
|
|
10100
|
+
out.push(
|
|
10101
|
+
" - and " + formatNumber(list2.length - MAX_INCOMPLETE_ROWS) + " more, all named in `manifest.json` under `incomplete[]`"
|
|
10102
|
+
);
|
|
10103
|
+
}
|
|
10104
|
+
return out;
|
|
10105
|
+
}
|
|
10106
|
+
function redactionSection(manifest, auditWritten) {
|
|
10107
|
+
const redacted = manifest.totals.redactedLines;
|
|
10108
|
+
if (redacted === 0) {
|
|
10109
|
+
return ["- Redacted: no line matched a secret rule."];
|
|
10110
|
+
}
|
|
10111
|
+
const where = auditWritten ? "`reports/audit.md` names the files; the values are not recoverable from it." : "`reports/audit.md` was disabled for this run, so only the count is available.";
|
|
10112
|
+
return [
|
|
10113
|
+
"- Redacted: " + formatNumber(redacted) + " line(s) had values masked before you received them.",
|
|
10114
|
+
" A masked span is a deliberate redaction, not an empty value.",
|
|
10115
|
+
" " + where
|
|
10116
|
+
];
|
|
10117
|
+
}
|
|
10118
|
+
function deliverySection(manifest, partsWritten, slots) {
|
|
10119
|
+
if (!partsWritten || manifest.parts.length === 0) return [];
|
|
10120
|
+
const parts = manifest.parts.length;
|
|
10121
|
+
const wholeSet = parts + 5;
|
|
10122
|
+
const unlimited = slots <= UNLIMITED_SLOTS;
|
|
10123
|
+
const out = ["## Attaching this", ""];
|
|
10124
|
+
out.push(
|
|
10125
|
+
"Paste this file as text: instructions cost no attachment slot. Attach the files it names.",
|
|
10126
|
+
"",
|
|
10127
|
+
"- Every part opens with `# Codebase Snapshot Part NNN of MMM` and repeats the fingerprint",
|
|
10128
|
+
" above, so check both before relying on one. A part you were not given is not an empty part."
|
|
10129
|
+
);
|
|
10130
|
+
if (unlimited) {
|
|
10131
|
+
out.push(
|
|
10132
|
+
"- No attachment limit is configured, so every file can travel: " + parts + " " + partWord(parts) + " plus `manifest.json`, `README.md` and the three reports (" + wholeSet + " files)."
|
|
10133
|
+
);
|
|
10134
|
+
} else if (wholeSet <= slots) {
|
|
10135
|
+
out.push(
|
|
10136
|
+
"- A " + slots + "-file destination carries the whole set: " + parts + " " + partWord(parts) + " plus `manifest.json`, `README.md` and the three reports - " + wholeSet + " of " + slots + "."
|
|
10137
|
+
);
|
|
10138
|
+
} else if (parts + 1 <= slots) {
|
|
10139
|
+
out.push(
|
|
10140
|
+
"- A " + slots + "-file destination carries " + parts + " " + partWord(parts) + " and",
|
|
10141
|
+
" `manifest.json` (" + (parts + 1) + " of " + slots + "); `README.md` and",
|
|
10142
|
+
" `reports/` stay behind - the brief above carries what they add."
|
|
10143
|
+
);
|
|
10144
|
+
} else if (parts <= slots) {
|
|
10145
|
+
out.push(
|
|
10146
|
+
parts === 1 ? "- The only part fills a " + slots + "-file destination, so `manifest.json` and" : "- The " + parts + " parts fill a " + slots + "-file destination, so `manifest.json` and",
|
|
10147
|
+
" `reports/` stay behind. The brief above carries what they add."
|
|
10148
|
+
);
|
|
10149
|
+
if (parts > 1) {
|
|
10150
|
+
out.push(
|
|
10151
|
+
" Either raise `--max-part-bytes` to merge the parts, or set `--max-parts " + slots + "` and let the parts grow to the count instead."
|
|
10152
|
+
);
|
|
10153
|
+
}
|
|
10154
|
+
} else {
|
|
10155
|
+
out.push(
|
|
10156
|
+
"- The " + parts + " parts do not fit a " + slots + "-file destination: at most " + slots + " can be attached.",
|
|
10157
|
+
" Choose by task - `reports/navigation.md` maps a file to its part - and name the parts",
|
|
10158
|
+
" you left out, or regenerate with `--max-part-bytes " + suggestBudgetBytes(manifest, slots) + "` for about " + (slots - 1) + " parts. `--max-parts " + slots + "` grows the parts until",
|
|
10159
|
+
" they fit instead, and says so when they end up larger than maxPartBytes."
|
|
10160
|
+
);
|
|
10161
|
+
}
|
|
10162
|
+
out.push(
|
|
10163
|
+
"- If you were given only some of them, say which parts are missing before you answer, and",
|
|
10164
|
+
" name the files you needed. Do not infer the contents of a part you did not receive.",
|
|
10165
|
+
""
|
|
10166
|
+
);
|
|
10167
|
+
return out;
|
|
10168
|
+
}
|
|
10169
|
+
function suggestBudgetBytes(manifest, slots) {
|
|
10170
|
+
const total = manifest.parts.reduce((sum, part) => sum + part.byteSize, 0);
|
|
10171
|
+
const target = Math.max(1, slots - 1);
|
|
10172
|
+
const estimated = Math.ceil(total / target * 1.15);
|
|
10173
|
+
const rounded = Math.ceil(estimated / 16384) * 16384;
|
|
10174
|
+
const budget = Math.max(rounded, manifest.budgets.maxPartBytes);
|
|
10175
|
+
return Math.round(budget / 1024) + "k";
|
|
10176
|
+
}
|
|
10177
|
+
|
|
9568
10178
|
// src/generator/readme.ts
|
|
9569
10179
|
function generateReadme(manifest, artifacts) {
|
|
9570
10180
|
const wrote = (name) => artifacts?.[name] !== false;
|
|
9571
10181
|
const reportLinks = [];
|
|
10182
|
+
if (wrote("prompt")) {
|
|
10183
|
+
reportLinks.push(
|
|
10184
|
+
"- [PROMPT.md](PROMPT.md) \u2014 The instruction sheet to paste with this snapshot: what it contains, what it left out, and the rules for citing it."
|
|
10185
|
+
);
|
|
10186
|
+
}
|
|
9572
10187
|
if (wrote("navigation")) {
|
|
9573
10188
|
reportLinks.push(
|
|
9574
10189
|
"- [reports/navigation.md](reports/navigation.md) \u2014 Comprehensive file directory mapping files to chunk files."
|
|
@@ -9638,6 +10253,11 @@ function generateReadme(manifest, artifacts) {
|
|
|
9638
10253
|
lines.push("", "## Snapshot Parts", "", "No parts were written for this run.");
|
|
9639
10254
|
}
|
|
9640
10255
|
const readOrder = [];
|
|
10256
|
+
if (wrote("prompt")) {
|
|
10257
|
+
readOrder.push(
|
|
10258
|
+
"1. Hand `PROMPT.md` to the model that receives this snapshot: it names the parts, the partial files and the fingerprint of this run."
|
|
10259
|
+
);
|
|
10260
|
+
}
|
|
9641
10261
|
if (wrote("navigation") || wrote("projectTree")) {
|
|
9642
10262
|
const first = [wrote("navigation") ? "`reports/navigation.md`" : null, wrote("projectTree") ? "`reports/project-tree.md`" : null].filter(Boolean).join(" or ");
|
|
9643
10263
|
readOrder.push(`1. Read ${first} first to locate target features or files.`);
|
|
@@ -9726,6 +10346,22 @@ function generateProjectTree(filePaths) {
|
|
|
9726
10346
|
const fence = fenceForText(lines.join("\n"), 3);
|
|
9727
10347
|
return ["# Project Tree", "", `${fence}text`, ...lines, fence, ""].join("\n");
|
|
9728
10348
|
}
|
|
10349
|
+
function treeTruncationWarnings(treeText) {
|
|
10350
|
+
const warnings = [];
|
|
10351
|
+
const depth = /\[tree truncated at (\d+) levels\]/.exec(treeText);
|
|
10352
|
+
if (depth) {
|
|
10353
|
+
warnings.push(
|
|
10354
|
+
`reports/project-tree.md was truncated at the ${depth[1]}-level depth cap: deeper directories are not listed there.`
|
|
10355
|
+
);
|
|
10356
|
+
}
|
|
10357
|
+
const lines = /\[tree truncated at (\d+) lines\]/.exec(treeText);
|
|
10358
|
+
if (lines) {
|
|
10359
|
+
warnings.push(
|
|
10360
|
+
`reports/project-tree.md was truncated at the ${lines[1]}-line cap: the rest of the tree is not listed there.`
|
|
10361
|
+
);
|
|
10362
|
+
}
|
|
10363
|
+
return warnings;
|
|
10364
|
+
}
|
|
9729
10365
|
|
|
9730
10366
|
// src/update-check.ts
|
|
9731
10367
|
import * as fs13 from "fs";
|
|
@@ -9845,14 +10481,14 @@ function writeCache(file, entry) {
|
|
|
9845
10481
|
}
|
|
9846
10482
|
}
|
|
9847
10483
|
function fetchLatestVersion(url = PACKAGE_LATEST_URL, timeoutMs = REQUEST_TIMEOUT_MS) {
|
|
9848
|
-
return new Promise((
|
|
10484
|
+
return new Promise((resolve12) => {
|
|
9849
10485
|
let settled = false;
|
|
9850
10486
|
let request = null;
|
|
9851
10487
|
const finish = (value) => {
|
|
9852
10488
|
if (settled) return;
|
|
9853
10489
|
settled = true;
|
|
9854
10490
|
clearTimeout(deadline);
|
|
9855
|
-
|
|
10491
|
+
resolve12(value);
|
|
9856
10492
|
};
|
|
9857
10493
|
const deadline = setTimeout(() => {
|
|
9858
10494
|
request?.destroy();
|
|
@@ -9998,8 +10634,8 @@ function gitDirectory(cwd) {
|
|
|
9998
10634
|
}
|
|
9999
10635
|
}
|
|
10000
10636
|
function isInside2(parent, child) {
|
|
10001
|
-
const
|
|
10002
|
-
return
|
|
10637
|
+
const relative15 = path14.relative(parent, child);
|
|
10638
|
+
return relative15 === "" || !relative15.startsWith("..") && !path14.isAbsolute(relative15);
|
|
10003
10639
|
}
|
|
10004
10640
|
function isRegisteredWorktree(gitDir, cwd) {
|
|
10005
10641
|
try {
|
|
@@ -10118,7 +10754,20 @@ const { parentPort, workerData } = require("node:worker_threads");
|
|
|
10118
10754
|
// so the run is the documented MCP run rather than the CLI run with one setting removed.
|
|
10119
10755
|
const base = loaded.config ? { ...loaded.config, hooks: {} } : null;
|
|
10120
10756
|
const config = mod.resolveConfig(base, workerData.cliOptions, workerData.cwd);
|
|
10121
|
-
const manifest = mod.generateSnapshot(config);
|
|
10757
|
+
const manifest = mod.generateSnapshot(config, { dryRun: workerData.dryRun === true });
|
|
10758
|
+
const skipCounts = new Map();
|
|
10759
|
+
for (const record of manifest.skipped) {
|
|
10760
|
+
skipCounts.set(record.reason, (skipCounts.get(record.reason) || 0) + 1);
|
|
10761
|
+
}
|
|
10762
|
+
const skipReasons = Array.from(skipCounts.entries())
|
|
10763
|
+
.sort(function (a, b) {
|
|
10764
|
+
if (b[1] !== a[1]) return b[1] - a[1];
|
|
10765
|
+
return a[0] < b[0] ? -1 : a[0] > b[0] ? 1 : 0;
|
|
10766
|
+
})
|
|
10767
|
+
.slice(0, 8)
|
|
10768
|
+
.map(function (entry) {
|
|
10769
|
+
return { reason: entry[0], count: entry[1] };
|
|
10770
|
+
});
|
|
10122
10771
|
parentPort.postMessage({
|
|
10123
10772
|
ok: true,
|
|
10124
10773
|
summary: {
|
|
@@ -10127,7 +10776,11 @@ const { parentPort, workerData } = require("node:worker_threads");
|
|
|
10127
10776
|
skippedCount: manifest.counts.skippedCount,
|
|
10128
10777
|
partsCount: manifest.counts.partsCount,
|
|
10129
10778
|
parts: manifest.parts.map((part) => ({ filename: part.filename, byteSize: part.byteSize })),
|
|
10779
|
+
totalSizeBytes: manifest.counts.totalSizeBytes,
|
|
10130
10780
|
totalContentBytes: manifest.totals.totalContentBytes,
|
|
10781
|
+
preset: manifest.config.preset,
|
|
10782
|
+
layers: manifest.layers,
|
|
10783
|
+
skipReasons: skipReasons,
|
|
10131
10784
|
warnings: manifest.warnings,
|
|
10132
10785
|
},
|
|
10133
10786
|
});
|
|
@@ -10139,15 +10792,15 @@ const { parentPort, workerData } = require("node:worker_threads");
|
|
|
10139
10792
|
}
|
|
10140
10793
|
})();
|
|
10141
10794
|
`;
|
|
10142
|
-
function generateInWorker(cwd, cliOptions) {
|
|
10143
|
-
return new Promise((
|
|
10795
|
+
function generateInWorker(cwd, cliOptions, options = {}) {
|
|
10796
|
+
return new Promise((resolve12) => {
|
|
10144
10797
|
let settled = false;
|
|
10145
10798
|
let worker = null;
|
|
10146
10799
|
const finish = (result) => {
|
|
10147
10800
|
if (settled) return;
|
|
10148
10801
|
settled = true;
|
|
10149
10802
|
if (worker !== null) void worker.terminate();
|
|
10150
|
-
|
|
10803
|
+
resolve12(result);
|
|
10151
10804
|
};
|
|
10152
10805
|
const isCjs = typeof __dirname !== "undefined";
|
|
10153
10806
|
const directory = isCjs ? __dirname : path15.dirname(fileURLToPath(import.meta.url));
|
|
@@ -10157,7 +10810,8 @@ function generateInWorker(cwd, cliOptions) {
|
|
|
10157
10810
|
workerData: {
|
|
10158
10811
|
entryUrl: workerEntry(directory, isCjs).url,
|
|
10159
10812
|
cwd,
|
|
10160
|
-
cliOptions
|
|
10813
|
+
cliOptions,
|
|
10814
|
+
dryRun: options.dryRun === true
|
|
10161
10815
|
}
|
|
10162
10816
|
});
|
|
10163
10817
|
} catch (error) {
|
|
@@ -10343,16 +10997,29 @@ function retain(items, keep) {
|
|
|
10343
10997
|
items.length = write;
|
|
10344
10998
|
}
|
|
10345
10999
|
var SKIP_PREVIEW_SUMMARIES = true;
|
|
10346
|
-
function buildIndexes(files, tsconfigPaths) {
|
|
11000
|
+
function buildIndexes(files, tsconfigPaths, skippedSummaryImports = /* @__PURE__ */ new Map()) {
|
|
10347
11001
|
const resolver = buildImportResolver(files, { tsconfig: tsconfigPaths });
|
|
10348
11002
|
const importerCounts = /* @__PURE__ */ new Map();
|
|
10349
|
-
const byFile = files.
|
|
10350
|
-
|
|
10351
|
-
|
|
10352
|
-
|
|
10353
|
-
|
|
10354
|
-
|
|
10355
|
-
|
|
11003
|
+
const byFile = files.flatMap((file) => {
|
|
11004
|
+
if (isSourceSummary(file.summary)) {
|
|
11005
|
+
return [
|
|
11006
|
+
{
|
|
11007
|
+
path: file.relativePath,
|
|
11008
|
+
imports: file.summary.imports,
|
|
11009
|
+
exports: file.summary.exports
|
|
11010
|
+
}
|
|
11011
|
+
];
|
|
11012
|
+
}
|
|
11013
|
+
const imports = skippedSummaryImports.get(file.relativePath);
|
|
11014
|
+
if (imports === void 0) return [];
|
|
11015
|
+
return [
|
|
11016
|
+
{
|
|
11017
|
+
path: file.relativePath,
|
|
11018
|
+
imports,
|
|
11019
|
+
exports: [],
|
|
11020
|
+
exportsOmitted: true
|
|
11021
|
+
}
|
|
11022
|
+
];
|
|
10356
11023
|
});
|
|
10357
11024
|
for (const entry of byFile) {
|
|
10358
11025
|
for (const specifier of entry.imports) {
|
|
@@ -10472,6 +11139,9 @@ function resolveSafeOutputDirs(config) {
|
|
|
10472
11139
|
return { outDir, tmpDir };
|
|
10473
11140
|
}
|
|
10474
11141
|
var IGNORABLE_ENTRIES = /* @__PURE__ */ new Set([".DS_Store"]);
|
|
11142
|
+
function isIgnorableEntry(entry) {
|
|
11143
|
+
return IGNORABLE_ENTRIES.has(entry.slice(entry.lastIndexOf("/") + 1));
|
|
11144
|
+
}
|
|
10475
11145
|
var RUN_DIR_PREFIX = "run-";
|
|
10476
11146
|
var STALE_RUN_MS = 60 * 60 * 1e3;
|
|
10477
11147
|
function maskSummaryStrings(value, secretRules) {
|
|
@@ -10514,9 +11184,9 @@ function listEntries(dir) {
|
|
|
10514
11184
|
return;
|
|
10515
11185
|
}
|
|
10516
11186
|
for (const child of children) {
|
|
10517
|
-
const
|
|
10518
|
-
entries.push(
|
|
10519
|
-
if (child.isDirectory()) walk(path16.join(absolute, child.name),
|
|
11187
|
+
const relative15 = prefix === "" ? child.name : `${prefix}/${child.name}`;
|
|
11188
|
+
entries.push(relative15);
|
|
11189
|
+
if (child.isDirectory()) walk(path16.join(absolute, child.name), relative15);
|
|
10520
11190
|
}
|
|
10521
11191
|
};
|
|
10522
11192
|
walk(dir, "");
|
|
@@ -10527,7 +11197,7 @@ function markerInventory(dir, written) {
|
|
|
10527
11197
|
const files = [];
|
|
10528
11198
|
for (const entry of entries) {
|
|
10529
11199
|
if (entry === OWNERSHIP_MARKER) continue;
|
|
10530
|
-
if (
|
|
11200
|
+
if (isIgnorableEntry(entry)) continue;
|
|
10531
11201
|
const full = path16.join(dir, ...entry.split("/"));
|
|
10532
11202
|
let stats;
|
|
10533
11203
|
try {
|
|
@@ -10816,7 +11486,7 @@ function assessSnapshotDirectory(dir) {
|
|
|
10816
11486
|
}
|
|
10817
11487
|
const entries = listEntries(dir);
|
|
10818
11488
|
const foreignEntries = entries.filter(
|
|
10819
|
-
(entry) => !recorded.has(entry) && !
|
|
11489
|
+
(entry) => !recorded.has(entry) && !isIgnorableEntry(entry)
|
|
10820
11490
|
);
|
|
10821
11491
|
if (foreignEntries.length > 0) {
|
|
10822
11492
|
return { owned: false, problem: null, foreignEntries, marker: marker2 };
|
|
@@ -11272,7 +11942,55 @@ function runAfterGenerate(config, manifest) {
|
|
|
11272
11942
|
return Promise.resolve(returned).finally(releaseRedirect);
|
|
11273
11943
|
}
|
|
11274
11944
|
function partitionByBudget(files, config, fingerprint) {
|
|
11275
|
-
const
|
|
11945
|
+
const configured = {
|
|
11946
|
+
parts: partitionWithBudgets(files, config.budgets, fingerprint),
|
|
11947
|
+
budgets: config.budgets,
|
|
11948
|
+
maxPartBytes: config.maxPartBytes,
|
|
11949
|
+
warnings: []
|
|
11950
|
+
};
|
|
11951
|
+
const limit = config.maxParts;
|
|
11952
|
+
if (limit === null || !config.artifacts.parts || configured.parts.length <= limit) return configured;
|
|
11953
|
+
const totalBytes = files.reduce((total, file) => total + file.includedBytes, 0);
|
|
11954
|
+
let target = Math.max(config.budgets.default, Math.ceil(totalBytes * 1.15 / limit));
|
|
11955
|
+
const seen = [];
|
|
11956
|
+
let low = config.budgets.default;
|
|
11957
|
+
let fitting = null;
|
|
11958
|
+
for (let pass = 0; pass < 6; pass += 1) {
|
|
11959
|
+
const parts2 = partitionWithBudgets(files, scaleBudgets(config.budgets, target), fingerprint);
|
|
11960
|
+
if (parts2.length <= limit) {
|
|
11961
|
+
fitting = { target, parts: parts2 };
|
|
11962
|
+
break;
|
|
11963
|
+
}
|
|
11964
|
+
seen.push(parts2.length);
|
|
11965
|
+
low = target;
|
|
11966
|
+
target = Math.ceil(target * 1.3);
|
|
11967
|
+
}
|
|
11968
|
+
if (fitting === null) {
|
|
11969
|
+
throw new Error(
|
|
11970
|
+
`maxParts ${limit} could not be met: ${seen.join(", ")} part(s) at budgets up to ${formatNumber(target)} B. Raise maxParts, include fewer files, or drop the setting.`
|
|
11971
|
+
);
|
|
11972
|
+
}
|
|
11973
|
+
for (let step = 0; step < 3 && fitting.target - low > 8192; step += 1) {
|
|
11974
|
+
const middle = Math.round((low + fitting.target) / 2);
|
|
11975
|
+
const parts2 = partitionWithBudgets(files, scaleBudgets(config.budgets, middle), fingerprint);
|
|
11976
|
+
if (parts2.length <= limit) fitting = { target: middle, parts: parts2 };
|
|
11977
|
+
else low = middle;
|
|
11978
|
+
}
|
|
11979
|
+
const { target: chosen, parts } = fitting;
|
|
11980
|
+
const budgets = scaleBudgets(config.budgets, chosen);
|
|
11981
|
+
const maxPartBytes = Math.max(config.maxPartBytes, chosen);
|
|
11982
|
+
const warnings = [
|
|
11983
|
+
`maxParts ${limit}: the part budget grew from ${formatNumber(config.maxPartBytes)} B to ${formatNumber(maxPartBytes)} B, and the snapshot now has ${formatNumber(parts.length)} part(s).`
|
|
11984
|
+
];
|
|
11985
|
+
if (maxPartBytes > config.maxPartBytes) {
|
|
11986
|
+
warnings.push(
|
|
11987
|
+
`maxParts ${limit}: parts are now above the configured maxPartBytes (${formatNumber(config.maxPartBytes)} B). A larger part is more tokens for the destination to take at once, and some destinations cap a single file.`
|
|
11988
|
+
);
|
|
11989
|
+
}
|
|
11990
|
+
return { parts, budgets, maxPartBytes, warnings };
|
|
11991
|
+
}
|
|
11992
|
+
function partitionWithBudgets(files, budgets, fingerprint) {
|
|
11993
|
+
const budgetFor = (file) => budgets.byLayer[file.layer] ?? budgets.default;
|
|
11276
11994
|
const buckets = /* @__PURE__ */ new Map();
|
|
11277
11995
|
for (const file of files) {
|
|
11278
11996
|
const budget = budgetFor(file);
|
|
@@ -11289,6 +12007,18 @@ function partitionByBudget(files, config, fingerprint) {
|
|
|
11289
12007
|
fingerprint
|
|
11290
12008
|
);
|
|
11291
12009
|
}
|
|
12010
|
+
function scaleBudgets(budgets, targetDefault) {
|
|
12011
|
+
const factor = targetDefault / budgets.default;
|
|
12012
|
+
return {
|
|
12013
|
+
default: Math.max(budgets.default, Math.round(targetDefault)),
|
|
12014
|
+
byLayer: Object.fromEntries(
|
|
12015
|
+
Object.entries(budgets.byLayer).map(([name, bytes]) => [
|
|
12016
|
+
name,
|
|
12017
|
+
Math.max(bytes, Math.round(bytes * factor))
|
|
12018
|
+
])
|
|
12019
|
+
)
|
|
12020
|
+
};
|
|
12021
|
+
}
|
|
11292
12022
|
function generateSnapshot(configInput, options) {
|
|
11293
12023
|
assertUsableConfigInput(configInput);
|
|
11294
12024
|
const config = isResolvedConfig(configInput) ? normalizeResolvedConfig(configInput) : resolveConfig(configInput ?? null);
|
|
@@ -11312,7 +12042,7 @@ function generateSnapshot(configInput, options) {
|
|
|
11312
12042
|
// output — but only at these exact paths, not at every directory that shares the name.
|
|
11313
12043
|
toolOwnedPaths: [config.outDir, config.tmpDir].map(
|
|
11314
12044
|
(directory) => path16.relative(config.cwd, path16.resolve(config.cwd, directory)).replace(/\\/g, "/")
|
|
11315
|
-
).filter((
|
|
12045
|
+
).filter((relative15) => relative15.length > 0 && !relative15.startsWith("..")),
|
|
11316
12046
|
// A staged path can be absent from the working tree while its index blob exists. Discovery
|
|
11317
12047
|
// lists the working tree, so those paths would never reach the scan at all.
|
|
11318
12048
|
...stagedPaths.size > 0 ? { extraPaths: [...stagedPaths] } : {}
|
|
@@ -11617,7 +12347,8 @@ function generateSnapshot(configInput, options) {
|
|
|
11617
12347
|
);
|
|
11618
12348
|
}
|
|
11619
12349
|
}
|
|
11620
|
-
const
|
|
12350
|
+
const partitioned = partitionByBudget(files, config, fingerprint);
|
|
12351
|
+
const parts = partitioned.parts;
|
|
11621
12352
|
const truncatedPreviewCount = files.filter((file) => file.isPreviewTruncated).length;
|
|
11622
12353
|
const incomplete = files.flatMap((file) => {
|
|
11623
12354
|
if (file.truncationReason === void 0) return [];
|
|
@@ -11654,7 +12385,10 @@ function generateSnapshot(configInput, options) {
|
|
|
11654
12385
|
// the README and the audit report.
|
|
11655
12386
|
git: { ...gitInfo, branch: maskPathText(gitInfo.branch, config.secretRules) },
|
|
11656
12387
|
budgets: {
|
|
11657
|
-
|
|
12388
|
+
// The ceiling the parts actually honour. It equals the configured one unless `maxParts`
|
|
12389
|
+
// grew it; `config.maxPartBytes` below keeps the configured value, because that is what
|
|
12390
|
+
// `validate` compares against the config on disk.
|
|
12391
|
+
maxPartBytes: partitioned.maxPartBytes,
|
|
11658
12392
|
largeFileBytes: config.largeFileBytes
|
|
11659
12393
|
},
|
|
11660
12394
|
config: {
|
|
@@ -11672,6 +12406,14 @@ function generateSnapshot(configInput, options) {
|
|
|
11672
12406
|
// invisible in the manifest that is supposed to describe the run.
|
|
11673
12407
|
maxMonolithBytes: config.maxMonolithBytes ?? null,
|
|
11674
12408
|
includeSensitiveFiles: config.includeSensitiveFiles,
|
|
12409
|
+
// The destination the instructions were written for. Not part of `digest`: the payload is
|
|
12410
|
+
// identical whatever this says, and a new delivery preference must not make an existing
|
|
12411
|
+
// snapshot fail `validate` as configuration drift.
|
|
12412
|
+
attachmentSlots: config.attachmentSlots,
|
|
12413
|
+
// The part-count ceiling the run enforced. Recorded because it decided the part sizes, and
|
|
12414
|
+
// omitted from `digest` when it is off so an existing snapshot does not start reporting
|
|
12415
|
+
// configuration drift.
|
|
12416
|
+
maxParts: config.maxParts ?? null,
|
|
11675
12417
|
discovery: config.discovery ?? "auto",
|
|
11676
12418
|
// A changed-files scope decides which files are in the snapshot, so the manifest that
|
|
11677
12419
|
// describes the run has to name it.
|
|
@@ -11732,7 +12474,7 @@ function generateSnapshot(configInput, options) {
|
|
|
11732
12474
|
},
|
|
11733
12475
|
layers: layerCounts,
|
|
11734
12476
|
kinds: kindCounts,
|
|
11735
|
-
indexes: buildIndexes(files, tsconfigPathsFor(config.cwd)),
|
|
12477
|
+
indexes: buildIndexes(files, tsconfigPathsFor(config.cwd), skippedSummaryImports),
|
|
11736
12478
|
parts: parts.map((part) => part.metadata),
|
|
11737
12479
|
files: files.map((file) => {
|
|
11738
12480
|
const { content: _content, ...rest } = file;
|
|
@@ -11742,6 +12484,10 @@ function generateSnapshot(configInput, options) {
|
|
|
11742
12484
|
incomplete,
|
|
11743
12485
|
warnings
|
|
11744
12486
|
};
|
|
12487
|
+
if (partitioned.warnings.length > 0) {
|
|
12488
|
+
manifest.warnings.push(...partitioned.warnings);
|
|
12489
|
+
manifest.totals.warningCount = manifest.warnings.length;
|
|
12490
|
+
}
|
|
11745
12491
|
manifest.totals.redactedLines = secretFindings.length;
|
|
11746
12492
|
manifest.totals.warningCount = manifest.warnings.length;
|
|
11747
12493
|
if (files.some((file) => file.isPreviewTruncated) && config.largeFileBytes < config.maxPartBytes) {
|
|
@@ -11774,11 +12520,9 @@ function generateSnapshot(configInput, options) {
|
|
|
11774
12520
|
let projectTree = null;
|
|
11775
12521
|
if (config.artifacts.projectTree) {
|
|
11776
12522
|
projectTree = generateProjectTree(files.map((file) => file.relativePath));
|
|
11777
|
-
const
|
|
11778
|
-
if (
|
|
11779
|
-
manifest.warnings.push(
|
|
11780
|
-
`reports/project-tree.md was truncated at the ${depthMarker[1]}-level depth cap: deeper directories are not listed there.`
|
|
11781
|
-
);
|
|
12523
|
+
const truncations = treeTruncationWarnings(projectTree);
|
|
12524
|
+
if (truncations.length > 0) {
|
|
12525
|
+
manifest.warnings.push(...truncations);
|
|
11782
12526
|
manifest.totals.warningCount = manifest.warnings.length;
|
|
11783
12527
|
}
|
|
11784
12528
|
}
|
|
@@ -11800,13 +12544,22 @@ function generateSnapshot(configInput, options) {
|
|
|
11800
12544
|
if (auditText !== null) manifest.artifacts.audit = artifactRecord(auditText);
|
|
11801
12545
|
const readmeText = artifacts.readme ? generateReadme(manifest, artifacts) : null;
|
|
11802
12546
|
if (readmeText !== null) manifest.artifacts.readme = artifactRecord(readmeText);
|
|
12547
|
+
const promptText = artifacts.prompt ? generatePrompt(
|
|
12548
|
+
manifest,
|
|
12549
|
+
artifacts,
|
|
12550
|
+
config.attachmentSlots,
|
|
12551
|
+
// Commit subjects are user input and reach an artifact, so they go through the same
|
|
12552
|
+
// masking as every other name the run reproduces.
|
|
12553
|
+
recentCommitSubjects(config.cwd).map((subject) => maskPathText(subject, config.secretRules))
|
|
12554
|
+
) : null;
|
|
12555
|
+
if (promptText !== null) manifest.artifacts.prompt = artifactRecord(promptText);
|
|
11803
12556
|
if (projectTree !== null) manifest.artifacts.projectTree = artifactRecord(projectTree);
|
|
11804
12557
|
let monolithJson = null;
|
|
11805
12558
|
let monolithMarkdown = null;
|
|
11806
12559
|
if (config.includeMonolith) {
|
|
11807
12560
|
const fullFiles = files.map((file) => {
|
|
11808
12561
|
const content = fullContents.get(file.relativePath) ?? "";
|
|
11809
|
-
|
|
12562
|
+
const entry = {
|
|
11810
12563
|
...file,
|
|
11811
12564
|
content,
|
|
11812
12565
|
inclusionMode: "full",
|
|
@@ -11814,6 +12567,9 @@ function generateSnapshot(configInput, options) {
|
|
|
11814
12567
|
includedBytes: Buffer.byteLength(content, "utf8"),
|
|
11815
12568
|
includedLines: countLines(content)
|
|
11816
12569
|
};
|
|
12570
|
+
delete entry.truncationReason;
|
|
12571
|
+
delete entry.omittedRanges;
|
|
12572
|
+
return entry;
|
|
11817
12573
|
});
|
|
11818
12574
|
const bodyBytes = fullFiles.reduce((total, file) => total + file.includedBytes, 0);
|
|
11819
12575
|
const definitelyTooLarge = config.maxMonolithBytes !== null && bodyBytes > config.maxMonolithBytes;
|
|
@@ -11934,6 +12690,9 @@ function generateSnapshot(configInput, options) {
|
|
|
11934
12690
|
if (readmeText !== null) {
|
|
11935
12691
|
writeArtifact(stagingDir, "README.md", readmeText);
|
|
11936
12692
|
}
|
|
12693
|
+
if (promptText !== null) {
|
|
12694
|
+
writeArtifact(stagingDir, "PROMPT.md", promptText);
|
|
12695
|
+
}
|
|
11937
12696
|
if (artifacts.manifest) {
|
|
11938
12697
|
writeArtifact(stagingDir, "manifest.json", JSON.stringify(manifest, null, 2));
|
|
11939
12698
|
}
|
|
@@ -12249,8 +13008,8 @@ function partPathFor(workspace, filename) {
|
|
|
12249
13008
|
if (filename.length === 0 || filename.includes("\0")) return null;
|
|
12250
13009
|
const partsDir = path17.resolve(workspace.root, workspace.config.outDir, "parts");
|
|
12251
13010
|
const resolved = path17.resolve(partsDir, filename);
|
|
12252
|
-
const
|
|
12253
|
-
if (
|
|
13011
|
+
const relative15 = path17.relative(partsDir, resolved);
|
|
13012
|
+
if (relative15.length === 0 || relative15.includes(path17.sep) || relative15.includes("/") || relative15.includes("\\") || path17.isAbsolute(relative15)) {
|
|
12254
13013
|
return null;
|
|
12255
13014
|
}
|
|
12256
13015
|
let stats;
|
|
@@ -12419,11 +13178,11 @@ function toRelativePath(root, value) {
|
|
|
12419
13178
|
if (cleaned.length === 0 || cleaned.includes("\0")) return null;
|
|
12420
13179
|
const resolvedRoot = path18.resolve(root);
|
|
12421
13180
|
const absolute = path18.resolve(resolvedRoot, cleaned);
|
|
12422
|
-
const
|
|
12423
|
-
if (
|
|
13181
|
+
const relative15 = path18.relative(resolvedRoot, absolute);
|
|
13182
|
+
if (relative15 === "" || relative15 === ".." || relative15.startsWith(`..${path18.sep}`) || path18.isAbsolute(relative15)) {
|
|
12424
13183
|
return null;
|
|
12425
13184
|
}
|
|
12426
|
-
return
|
|
13185
|
+
return relative15.split(path18.sep).join("/");
|
|
12427
13186
|
}
|
|
12428
13187
|
function symbolsOf(entry) {
|
|
12429
13188
|
const summary = entry.summary;
|
|
@@ -12581,45 +13340,38 @@ var planTool = {
|
|
|
12581
13340
|
const prepared = await prepare(args, context, workspaceOverrides(args));
|
|
12582
13341
|
if (!prepared.ok) return prepared.outcome;
|
|
12583
13342
|
const workspace = prepared.workspace;
|
|
12584
|
-
|
|
12585
|
-
|
|
12586
|
-
|
|
12587
|
-
|
|
12588
|
-
return failure(error instanceof Error ? error.message : String(error));
|
|
12589
|
-
}
|
|
12590
|
-
const reasons = /* @__PURE__ */ new Map();
|
|
12591
|
-
for (const record of manifest.skipped) {
|
|
12592
|
-
reasons.set(record.reason, (reasons.get(record.reason) ?? 0) + 1);
|
|
12593
|
-
}
|
|
12594
|
-
const topReasons = [...reasons.entries()].sort((a, b) => b[1] - a[1] || (a[0] < b[0] ? -1 : 1)).slice(0, 8).map(([reason, count]) => ({ reason, count }));
|
|
13343
|
+
const result = await generateInWorker(workspace.root, workspace.cliOptions, { dryRun: true });
|
|
13344
|
+
if (!result.ok) return failure(result.message);
|
|
13345
|
+
const summary = result.summary;
|
|
13346
|
+
const topReasons = summary.skipReasons;
|
|
12595
13347
|
const lines = [
|
|
12596
13348
|
"Dry run \u2014 nothing was written.",
|
|
12597
|
-
`Preset: ${
|
|
12598
|
-
`Would include ${plural(
|
|
12599
|
-
`Would skip ${plural(
|
|
13349
|
+
`Preset: ${summary.preset}`,
|
|
13350
|
+
`Would include ${plural(summary.totalFiles, "file")} in ${plural(summary.partsCount, "part")} (${formatBytes(summary.totalSizeBytes)} of source, ${formatBytes(summary.totalContentBytes)} emitted).`,
|
|
13351
|
+
`Would skip ${plural(summary.skippedCount, "file")}.`
|
|
12600
13352
|
];
|
|
12601
13353
|
if (topReasons.length > 0) {
|
|
12602
13354
|
lines.push("Top skip reasons:");
|
|
12603
13355
|
for (const entry of topReasons) lines.push(` - ${entry.reason} (${entry.count})`);
|
|
12604
13356
|
}
|
|
12605
|
-
if (
|
|
12606
|
-
lines.push(`Warnings (${
|
|
12607
|
-
for (const warning of
|
|
13357
|
+
if (summary.warnings.length > 0) {
|
|
13358
|
+
lines.push(`Warnings (${summary.warnings.length}):`);
|
|
13359
|
+
for (const warning of summary.warnings.slice(0, 5)) lines.push(` - ${warning}`);
|
|
12608
13360
|
}
|
|
12609
13361
|
return {
|
|
12610
13362
|
text: lines.join("\n"),
|
|
12611
13363
|
structured: {
|
|
12612
|
-
files:
|
|
12613
|
-
skipped:
|
|
12614
|
-
parts:
|
|
12615
|
-
sourceBytes:
|
|
12616
|
-
emittedBytes:
|
|
12617
|
-
preset:
|
|
12618
|
-
maxPartBytes:
|
|
12619
|
-
layers:
|
|
13364
|
+
files: summary.totalFiles,
|
|
13365
|
+
skipped: summary.skippedCount,
|
|
13366
|
+
parts: summary.partsCount,
|
|
13367
|
+
sourceBytes: summary.totalSizeBytes,
|
|
13368
|
+
emittedBytes: summary.totalContentBytes,
|
|
13369
|
+
preset: summary.preset,
|
|
13370
|
+
maxPartBytes: workspace.config.maxPartBytes,
|
|
13371
|
+
layers: summary.layers,
|
|
12620
13372
|
skipReasons: topReasons,
|
|
12621
|
-
warnings:
|
|
12622
|
-
warningCount:
|
|
13373
|
+
warnings: summary.warnings.slice(0, 5),
|
|
13374
|
+
warningCount: summary.warnings.length
|
|
12623
13375
|
}
|
|
12624
13376
|
};
|
|
12625
13377
|
}
|
|
@@ -13369,6 +14121,7 @@ var VALIDATE_OPTIONS = [
|
|
|
13369
14121
|
"max-part-tokens",
|
|
13370
14122
|
"large-file-bytes",
|
|
13371
14123
|
"max-monolith-bytes",
|
|
14124
|
+
"max-parts",
|
|
13372
14125
|
"include-monolith",
|
|
13373
14126
|
"include-sensitive-files",
|
|
13374
14127
|
"skip-artifacts",
|
|
@@ -13394,6 +14147,8 @@ var COMMAND_OPTION_SCOPE = {
|
|
|
13394
14147
|
"max-part-tokens",
|
|
13395
14148
|
"large-file-bytes",
|
|
13396
14149
|
"max-monolith-bytes",
|
|
14150
|
+
"attachment-slots",
|
|
14151
|
+
"max-parts",
|
|
13397
14152
|
"include-monolith",
|
|
13398
14153
|
"include-sensitive-files",
|
|
13399
14154
|
"skip-artifacts",
|
|
@@ -13539,6 +14294,7 @@ var PACKAGE_NAME = "codebase-snapshot";
|
|
|
13539
14294
|
var MAJOR_VERSION = GENERATOR_VERSION.split(".")[0];
|
|
13540
14295
|
var ARTIFACT_SUMMARY = {
|
|
13541
14296
|
readme: "README.md describing the snapshot at the output root.",
|
|
14297
|
+
prompt: "PROMPT.md: the instruction sheet to paste with the snapshot, rendered from its manifest.",
|
|
13542
14298
|
manifest: "manifest.json: machine-readable index of every file, part, hash and config.",
|
|
13543
14299
|
parts: "parts/*.md: the packed, budget-limited markdown parts that carry the code.",
|
|
13544
14300
|
navigation: "reports/navigation.md: links between parts and layers.",
|
|
@@ -13548,6 +14304,7 @@ var ARTIFACT_SUMMARY = {
|
|
|
13548
14304
|
};
|
|
13549
14305
|
var ARTIFACT_DEFAULTS = {
|
|
13550
14306
|
readme: true,
|
|
14307
|
+
prompt: true,
|
|
13551
14308
|
manifest: true,
|
|
13552
14309
|
parts: true,
|
|
13553
14310
|
navigation: true,
|
|
@@ -13688,9 +14445,9 @@ function buildAgentContract() {
|
|
|
13688
14445
|
{
|
|
13689
14446
|
step: 6,
|
|
13690
14447
|
id: "consume",
|
|
13691
|
-
run: "read ./snapshot/
|
|
14448
|
+
run: "read ./snapshot/PROMPT.md first, then ./snapshot/parts/*.md, ./snapshot/manifest.json and ./snapshot/reports/audit.md",
|
|
13692
14449
|
expect: "the code, the index of what was included, and the risk findings",
|
|
13693
|
-
notes: "manifest.json.files[] lists every included file with layer, kind, language, part and summary. manifest.skipped[] explains every file that was left out and why; manifest.incomplete[] lists every included file that is not present in full, with its missing line ranges."
|
|
14450
|
+
notes: "manifest.json.files[] lists every included file with layer, kind, language, part and summary. manifest.skipped[] explains every file that was left out and why; manifest.incomplete[] lists every included file that is not present in full, with its missing line ranges. PROMPT.md is the instruction sheet for whoever reads the snapshot; it is rendered from the manifest, so it names this run's omissions rather than describing snapshots in general."
|
|
13694
14451
|
}
|
|
13695
14452
|
],
|
|
13696
14453
|
commands: [
|
|
@@ -13827,6 +14584,20 @@ function buildAgentContract() {
|
|
|
13827
14584
|
appliesTo: optionAppliesTo("discovery"),
|
|
13828
14585
|
summary: "How files are discovered: auto (git when usable), git (require git), walk (read .gitignore files directly, including nested ones; the escape hatch for a .git that cannot be listed)."
|
|
13829
14586
|
},
|
|
14587
|
+
{
|
|
14588
|
+
flag: "--attachment-slots",
|
|
14589
|
+
type: "number",
|
|
14590
|
+
default: "10",
|
|
14591
|
+
appliesTo: optionAppliesTo("attachment-slots"),
|
|
14592
|
+
summary: "Files the destination accepts in one message (0 = no limit). PROMPT.md plans the delivery against it: which parts to attach, what to leave behind, and the part budget that would merge them. It does not change the payload."
|
|
14593
|
+
},
|
|
14594
|
+
{
|
|
14595
|
+
flag: "--max-parts",
|
|
14596
|
+
type: "number",
|
|
14597
|
+
default: "unset",
|
|
14598
|
+
appliesTo: optionAppliesTo("max-parts"),
|
|
14599
|
+
summary: "Experimental: grow the per-part budget until the snapshot has at most this many parts. The budget it settles on is recorded in manifest.budgets.maxPartBytes and may exceed maxPartBytes; a warning says so."
|
|
14600
|
+
},
|
|
13830
14601
|
{
|
|
13831
14602
|
flag: "--skip-artifacts",
|
|
13832
14603
|
type: "string",
|
|
@@ -14040,6 +14811,8 @@ function buildAgentContract() {
|
|
|
14040
14811
|
{ key: "includeSensitiveFiles", type: "boolean", default: false, summary: "Emit .env / *.pem / credential files." },
|
|
14041
14812
|
{ key: "include", type: "string[]", default: "[]", summary: "Allow-list of globs; empty means everything." },
|
|
14042
14813
|
{ key: "excludePatterns", type: "string[]", default: "[]", summary: "Extra exclude globs." },
|
|
14814
|
+
{ key: "maxParts", type: "number | null", default: null, summary: "Experimental: the most parts a snapshot may have. The per-part budget grows to fit, up to the run's own needs; the effective ceiling is recorded in manifest.budgets.maxPartBytes and may exceed maxPartBytes." },
|
|
14815
|
+
{ key: "attachmentSlots", type: "number", default: 10, summary: "Files the destination accepts in one message (0 = no limit); PROMPT.md plans the delivery to fit. It does not change the payload, and it is not part of the config digest." },
|
|
14043
14816
|
{ key: "discovery", type: '"auto" | "git" | "walk"', default: "auto", summary: "How files are discovered; `walk` scans the tree and reads .gitignore directly when a .git directory cannot be listed." },
|
|
14044
14817
|
{ key: "artifacts", type: "object", default: "all on except monolith", summary: "Per-artifact opt-out." },
|
|
14045
14818
|
{ key: "budgets", type: "object", default: "{ default, byLayer }", summary: "Per-layer byte budgets." },
|
|
@@ -14047,12 +14820,14 @@ function buildAgentContract() {
|
|
|
14047
14820
|
{ key: "layers", type: "array", default: "preset layers", summary: "Custom layer rules (glob or RegExp)." },
|
|
14048
14821
|
{ key: "kinds", type: "array", default: "preset kinds", summary: "Custom kind rules." },
|
|
14049
14822
|
{ key: "secrets", type: "object", default: "{}", summary: "Custom secret patterns, or disable the defaults." },
|
|
14823
|
+
{ key: "secretRules", type: "array", default: "[]", summary: "Full secret-rule list: the library spelling of secrets.customPatterns. The built-ins are prepended unless secrets.disableDefaultPatterns is set." },
|
|
14050
14824
|
{ key: "hooks", type: "object", default: "{}", summary: "afterGenerate(manifest) runs after a successful generate." }
|
|
14051
14825
|
]
|
|
14052
14826
|
},
|
|
14053
14827
|
output: {
|
|
14054
14828
|
layout: [
|
|
14055
14829
|
"<outDir>/README.md",
|
|
14830
|
+
"<outDir>/PROMPT.md",
|
|
14056
14831
|
"<outDir>/manifest.json",
|
|
14057
14832
|
"<outDir>/parts/part-NNN.md",
|
|
14058
14833
|
"<outDir>/reports/project-tree.md",
|
|
@@ -14063,7 +14838,10 @@ function buildAgentContract() {
|
|
|
14063
14838
|
notes: [
|
|
14064
14839
|
"Parts are ordered and budget-limited; a file that cannot fit one part is emitted as a head/tail preview, and every file not present in full is listed in manifest.json incomplete[] with the missing line ranges.",
|
|
14065
14840
|
"manifest.json.files[] carries relativePath, layer, kind, language, part, inclusionMode, truncationReason, omittedRanges and hash; manifest.json.incomplete[] lists every file not present in full; `summary` is conditional \u2014 it is absent for languages with no structural summary, and `summaryOmitted: true` marks a summary dropped to fit the part budget; encoding appears when the file was not plain UTF-8.",
|
|
14841
|
+
"indexes.imports.byFile includes previewed files (their import specifiers are still extracted); such an entry carries `exportsOmitted: true` instead of pretending it exports nothing.",
|
|
14842
|
+
"validate re-checks manifest.incomplete[] against files[] and refuses a manifest whose two statements of what is missing disagree.",
|
|
14066
14843
|
"manifest.skipped[] carries the path and the exact reason it was excluded.",
|
|
14844
|
+
"PROMPT.md is rendered from the manifest of the run that wrote it \u2014 its parts, partial files, skip tallies and fingerprint are that run's \u2014 and manifest.artifacts.prompt records its digest, so an edited prompt fails validate.",
|
|
14067
14845
|
`The output directory is replaced atomically; ${MIN_MAX_PART_BYTES} bytes is the smallest legal budget.`
|
|
14068
14846
|
]
|
|
14069
14847
|
},
|
|
@@ -14238,6 +15016,10 @@ do not assume the repository is broken.
|
|
|
14238
15016
|
- \`snapshot/reports/audit.md\` \u2014 secrets found, large files, parse diagnostics, git
|
|
14239
15017
|
state. Read this before you quote code back to a user.
|
|
14240
15018
|
- \`snapshot/reports/project-tree.md\` and \`navigation.md\` \u2014 structure and cross-links.
|
|
15019
|
+
- \`snapshot/PROMPT.md\` \u2014 the instruction sheet to hand to the model that receives the
|
|
15020
|
+
snapshot: paste it with the parts. It is rendered from this run's manifest and names the
|
|
15021
|
+
parts, the partial files and the fingerprint, so do not rewrite it by hand \u2014 \`validate\`
|
|
15022
|
+
fails when it was edited.
|
|
14241
15023
|
|
|
14242
15024
|
## Project types
|
|
14243
15025
|
|
|
@@ -15066,11 +15848,11 @@ var MAX_LINE_BYTES = 32 * 1024 * 1024;
|
|
|
15066
15848
|
function createWriter(output) {
|
|
15067
15849
|
return {
|
|
15068
15850
|
write(value) {
|
|
15069
|
-
return new Promise((
|
|
15851
|
+
return new Promise((resolve12, reject) => {
|
|
15070
15852
|
output.write(`${JSON.stringify(value)}
|
|
15071
15853
|
`, (error) => {
|
|
15072
15854
|
if (error) reject(error);
|
|
15073
|
-
else
|
|
15855
|
+
else resolve12();
|
|
15074
15856
|
});
|
|
15075
15857
|
});
|
|
15076
15858
|
}
|
|
@@ -15207,8 +15989,8 @@ async function runStdioServer(options) {
|
|
|
15207
15989
|
let inFlight = 0;
|
|
15208
15990
|
let inputEnded = false;
|
|
15209
15991
|
let resolveDone = () => void 0;
|
|
15210
|
-
const finished = new Promise((
|
|
15211
|
-
resolveDone =
|
|
15992
|
+
const finished = new Promise((resolve12) => {
|
|
15993
|
+
resolveDone = resolve12;
|
|
15212
15994
|
});
|
|
15213
15995
|
const finishIfIdle = () => {
|
|
15214
15996
|
if (inputEnded && inFlight === 0) resolveDone(0);
|
|
@@ -15305,6 +16087,8 @@ var CLI_OPTIONS = {
|
|
|
15305
16087
|
"max-part-bytes": { type: "string" },
|
|
15306
16088
|
"large-file-bytes": { type: "string" },
|
|
15307
16089
|
"max-monolith-bytes": { type: "string" },
|
|
16090
|
+
"attachment-slots": { type: "string" },
|
|
16091
|
+
"max-parts": { type: "string" },
|
|
15308
16092
|
"include-monolith": { type: "boolean" },
|
|
15309
16093
|
"include-sensitive-files": { type: "boolean" },
|
|
15310
16094
|
"skip-artifacts": { type: "string" },
|
|
@@ -15379,6 +16163,10 @@ Options:
|
|
|
15379
16163
|
--skeleton Emit TypeScript signatures instead of bodies
|
|
15380
16164
|
--sarif Also write reports/audit.sarif for GitHub Code Scanning
|
|
15381
16165
|
--include-sensitive-files Emit .env / *.pem / .npmrc / credential files
|
|
16166
|
+
--attachment-slots <n> Files the destination takes in one message (default: 10,
|
|
16167
|
+
0 = no limit); PROMPT.md plans the delivery to fit
|
|
16168
|
+
--max-parts <n> Experimental: grow the part budget until the snapshot has at
|
|
16169
|
+
most n parts, instead of adding parts as the code grows
|
|
15382
16170
|
--skip-artifacts <names> Comma-separated artifacts to omit
|
|
15383
16171
|
(readme, manifest, parts, navigation,
|
|
15384
16172
|
projectTree, audit, monolith)
|
|
@@ -15437,6 +16225,20 @@ function parseByteOption(raw, optionName, minimum, unit = "byte count") {
|
|
|
15437
16225
|
}
|
|
15438
16226
|
return value;
|
|
15439
16227
|
}
|
|
16228
|
+
function parseCountOption(raw, optionName, minimum = 0) {
|
|
16229
|
+
if (raw === void 0) return void 0;
|
|
16230
|
+
const trimmed = raw.trim();
|
|
16231
|
+
if (!/^\d+$/.test(trimmed) || !Number.isSafeInteger(Number(trimmed))) {
|
|
16232
|
+
throw new UsageError(
|
|
16233
|
+
`--${optionName} expects a whole number such as 10 or 20, received "${raw}".`
|
|
16234
|
+
);
|
|
16235
|
+
}
|
|
16236
|
+
const value = Number(trimmed);
|
|
16237
|
+
if (value < minimum) {
|
|
16238
|
+
throw new UsageError(`--${optionName} must be at least ${minimum}, received "${raw}".`);
|
|
16239
|
+
}
|
|
16240
|
+
return value;
|
|
16241
|
+
}
|
|
15440
16242
|
function parseArtifactList(raw, flag) {
|
|
15441
16243
|
const names = raw.split(",").map((name) => name.trim()).filter(Boolean);
|
|
15442
16244
|
if (names.length === 0) {
|
|
@@ -15678,6 +16480,11 @@ function parseCliArgs(argv) {
|
|
|
15678
16480
|
"max-monolith-bytes",
|
|
15679
16481
|
1
|
|
15680
16482
|
),
|
|
16483
|
+
attachmentSlots: parseCountOption(
|
|
16484
|
+
values["attachment-slots"],
|
|
16485
|
+
"attachment-slots"
|
|
16486
|
+
),
|
|
16487
|
+
maxParts: parseCountOption(values["max-parts"], "max-parts", 1),
|
|
15681
16488
|
skipArtifacts,
|
|
15682
16489
|
onlyArtifacts,
|
|
15683
16490
|
discovery: isDiscoveryMode(rawDiscovery) ? rawDiscovery : void 0,
|
|
@@ -15732,8 +16539,8 @@ function splitList(value) {
|
|
|
15732
16539
|
}
|
|
15733
16540
|
function displayOutPath(cwd, outDir, ...segments) {
|
|
15734
16541
|
const absolute = path21.resolve(cwd, outDir, ...segments);
|
|
15735
|
-
const
|
|
15736
|
-
if (
|
|
16542
|
+
const relative15 = path21.relative(cwd, absolute);
|
|
16543
|
+
if (relative15 && !relative15.startsWith("..") && !path21.isAbsolute(relative15)) return relative15;
|
|
15737
16544
|
return absolute;
|
|
15738
16545
|
}
|
|
15739
16546
|
function nextStepHint(cwd, scriptsAddedNow) {
|
|
@@ -15741,7 +16548,7 @@ function nextStepHint(cwd, scriptsAddedNow) {
|
|
|
15741
16548
|
if (!hasScript) {
|
|
15742
16549
|
try {
|
|
15743
16550
|
const parsed = JSON.parse(
|
|
15744
|
-
|
|
16551
|
+
stripJsonComments(fs20.readFileSync(path21.join(cwd, "package.json"), "utf8"))
|
|
15745
16552
|
);
|
|
15746
16553
|
hasScript = typeof parsed.scripts?.snapshot === "string";
|
|
15747
16554
|
} catch {
|
|
@@ -15808,7 +16615,9 @@ async function runInitCommand(invocation) {
|
|
|
15808
16615
|
}
|
|
15809
16616
|
function generatorOrigin(cwd) {
|
|
15810
16617
|
try {
|
|
15811
|
-
const pkg = JSON.parse(
|
|
16618
|
+
const pkg = JSON.parse(
|
|
16619
|
+
stripJsonComments(fs20.readFileSync(path21.join(cwd, "package.json"), "utf8"))
|
|
16620
|
+
);
|
|
15812
16621
|
const spec = pkg.dependencies?.["codebase-snapshot"] ?? pkg.devDependencies?.["codebase-snapshot"];
|
|
15813
16622
|
if (typeof spec === "string") return `project dependency ${spec}`;
|
|
15814
16623
|
} catch {
|
|
@@ -16001,6 +16810,12 @@ async function runSetupCommand(invocation, options = {}) {
|
|
|
16001
16810
|
if (invocation.maxPartTokens !== void 0) {
|
|
16002
16811
|
generateArgs.push("--max-part-tokens", String(invocation.maxPartTokens));
|
|
16003
16812
|
}
|
|
16813
|
+
if (invocation.attachmentSlots !== void 0) {
|
|
16814
|
+
generateArgs.push("--attachment-slots", String(invocation.attachmentSlots));
|
|
16815
|
+
}
|
|
16816
|
+
if (invocation.maxParts !== void 0) {
|
|
16817
|
+
generateArgs.push("--max-parts", String(invocation.maxParts));
|
|
16818
|
+
}
|
|
16004
16819
|
if (invocation.skeleton === true) generateArgs.push("--skeleton");
|
|
16005
16820
|
if (invocation.sarif === true) generateArgs.push("--sarif");
|
|
16006
16821
|
if (invocation.noUpdateCheck) generateArgs.push("--no-update-check");
|
|
@@ -16105,6 +16920,8 @@ function runSkillCommand(invocation) {
|
|
|
16105
16920
|
function renderValidateText(result) {
|
|
16106
16921
|
if (result.valid) {
|
|
16107
16922
|
info("\u2705 Snapshot is valid and up to date with disk.");
|
|
16923
|
+
} else if (result.errors.length === 1 && result.errors[0].includes(" is not a snapshot manifest: ")) {
|
|
16924
|
+
warn(`\u274C ${result.errors[0]}`);
|
|
16108
16925
|
} else {
|
|
16109
16926
|
warn("\u274C Snapshot validation failed:");
|
|
16110
16927
|
for (const error of result.errors) warn(` - ${error}`);
|
|
@@ -16241,6 +17058,8 @@ ${USAGE}
|
|
|
16241
17058
|
maxPartTokens: invocation.maxPartTokens,
|
|
16242
17059
|
largeFileBytes: invocation.largeFileBytes,
|
|
16243
17060
|
maxMonolithBytes: invocation.maxMonolithBytes,
|
|
17061
|
+
attachmentSlots: invocation.attachmentSlots,
|
|
17062
|
+
maxParts: invocation.maxParts,
|
|
16244
17063
|
skipArtifacts: invocation.skipArtifacts,
|
|
16245
17064
|
// `--only-artifacts` is forwarded as itself, not only as the derived suppression list:
|
|
16246
17065
|
// suppression cannot switch an artifact *on*, so a config that had turned one of the
|
|
@@ -16310,7 +17129,11 @@ ${USAGE}
|
|
|
16310
17129
|
if (invocation.command === "diff") {
|
|
16311
17130
|
try {
|
|
16312
17131
|
const [beforePath, afterPath] = invocation.args;
|
|
16313
|
-
const diff = compareManifests(
|
|
17132
|
+
const diff = compareManifests(
|
|
17133
|
+
loadManifest(beforePath),
|
|
17134
|
+
loadManifest(afterPath),
|
|
17135
|
+
resolved.secretRules
|
|
17136
|
+
);
|
|
16314
17137
|
emit(invocation.format, diff, () => info(renderDiffText(diff)));
|
|
16315
17138
|
return 0;
|
|
16316
17139
|
} catch (err) {
|
|
@@ -16365,7 +17188,7 @@ ${USAGE}
|
|
|
16365
17188
|
const reasons = skipBreakdown.length > shownReasons.length ? `${shownReasons.join(", ")}, +${skipBreakdown.length - shownReasons.length} more` : shownReasons.join(", ");
|
|
16366
17189
|
const candidates = manifest.counts.totalFiles + manifest.counts.skippedCount;
|
|
16367
17190
|
info(
|
|
16368
|
-
manifest.counts.skippedCount === 0 ? ` - Tracked files: ${formatNumber(manifest.counts.totalFiles)}` : ` - Tracked files: ${formatNumber(manifest.counts.totalFiles)} included of ${formatNumber(candidates)} found \u2014 ${formatNumber(manifest.counts.skippedCount)} skipped (${reasons}); every one is listed in ${displayOutPath(resolved.cwd, resolved.outDir, "reports/audit.md")}`
|
|
17191
|
+
manifest.counts.skippedCount === 0 ? ` - Tracked files: ${formatNumber(manifest.counts.totalFiles)}` : ` - Tracked files: ${formatNumber(manifest.counts.totalFiles)} included of ${formatNumber(candidates)} paths found \u2014 ${formatNumber(manifest.counts.skippedCount)} skipped (${reasons}); every one is listed in ${displayOutPath(resolved.cwd, resolved.outDir, "reports/audit.md")}`
|
|
16369
17192
|
);
|
|
16370
17193
|
info(` - Total lines: ${formatNumber(manifest.counts.totalLines)}`);
|
|
16371
17194
|
info(
|
|
@@ -16409,7 +17232,16 @@ ${USAGE}
|
|
|
16409
17232
|
);
|
|
16410
17233
|
}
|
|
16411
17234
|
}
|
|
16412
|
-
|
|
17235
|
+
const orientation = [
|
|
17236
|
+
artifacts.readme ? "README.md" : null,
|
|
17237
|
+
artifacts.prompt ? "PROMPT.md" : null
|
|
17238
|
+
].filter((name) => name !== null);
|
|
17239
|
+
if (orientation.length > 0) {
|
|
17240
|
+
info(
|
|
17241
|
+
` - Orientation: ${orientation.map((name) => displayOutPath(resolved.cwd, resolved.outDir, name)).join(", ")}`
|
|
17242
|
+
);
|
|
17243
|
+
}
|
|
17244
|
+
if (reports.length === 0 && !artifacts.parts && !artifacts.manifest && !artifacts.monolith && orientation.length === 0) {
|
|
16413
17245
|
info(` - Artifacts: all disabled (only the ownership marker was written)`);
|
|
16414
17246
|
}
|
|
16415
17247
|
info(` - Fingerprint: ${manifest.fingerprint}`);
|
|
@@ -16465,8 +17297,8 @@ function comparablePath(value) {
|
|
|
16465
17297
|
return process.platform === "win32" ? absolute.toLowerCase() : absolute;
|
|
16466
17298
|
}
|
|
16467
17299
|
function isSameOrInside(parent, candidate) {
|
|
16468
|
-
const
|
|
16469
|
-
return
|
|
17300
|
+
const relative15 = path21.relative(parent, candidate);
|
|
17301
|
+
return relative15 === "" || relative15 !== ".." && !relative15.startsWith(`..${path21.sep}`) && !path21.isAbsolute(relative15);
|
|
16470
17302
|
}
|
|
16471
17303
|
function isGeneratedWatchPath(candidate, paths) {
|
|
16472
17304
|
const absolute = comparablePath(path21.resolve(paths.cwd, candidate));
|
|
@@ -16553,6 +17385,8 @@ async function runWatchLoop(invocation, resolved, options) {
|
|
|
16553
17385
|
maxPartTokens: invocation.maxPartTokens,
|
|
16554
17386
|
largeFileBytes: invocation.largeFileBytes,
|
|
16555
17387
|
maxMonolithBytes: invocation.maxMonolithBytes,
|
|
17388
|
+
attachmentSlots: invocation.attachmentSlots,
|
|
17389
|
+
maxParts: invocation.maxParts,
|
|
16556
17390
|
skipArtifacts: invocation.skipArtifacts,
|
|
16557
17391
|
onlyArtifacts: invocation.onlyArtifacts,
|
|
16558
17392
|
discovery: invocation.discovery,
|
|
@@ -16612,12 +17446,12 @@ async function runWatchLoop(invocation, resolved, options) {
|
|
|
16612
17446
|
info(`\u26A0 Watch error: ${err.message}`);
|
|
16613
17447
|
info(" The watcher may have missed changes. Restart with Ctrl+C if they stop arriving.");
|
|
16614
17448
|
});
|
|
16615
|
-
await new Promise((
|
|
17449
|
+
await new Promise((resolve12) => {
|
|
16616
17450
|
const stop = () => {
|
|
16617
17451
|
stopped = true;
|
|
16618
17452
|
if (timer) clearTimeout(timer);
|
|
16619
17453
|
watcher.close();
|
|
16620
|
-
|
|
17454
|
+
resolve12();
|
|
16621
17455
|
};
|
|
16622
17456
|
process.once("SIGINT", stop);
|
|
16623
17457
|
process.once("SIGTERM", stop);
|