codebase-snapshot 0.10.1 → 0.10.2
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 +70 -0
- package/README.md +1 -1
- package/dist/bin.js +595 -396
- package/dist/{chunk-7DAW2LFZ.js → chunk-5AV7OR3J.js} +371 -176
- package/dist/{chunk-WDJ3O3R4.js → chunk-5EYBTBFY.js} +24 -28
- package/dist/cli.cjs +595 -396
- package/dist/cli.d.cts +11 -9
- package/dist/cli.d.ts +11 -9
- package/dist/cli.js +14 -6
- 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 +347 -169
- package/dist/index.d.cts +68 -23
- package/dist/index.d.ts +68 -23
- package/dist/index.js +1 -1
- package/dist/mcp.cjs +453 -2694
- 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-BoWneA7n.d.cts} +35 -4
- package/dist/{types-Z471HW65.d.ts → types-BoWneA7n.d.ts} +35 -4
- package/docs/cli.md +29 -8
- package/docs/codebase-token-budget.md +12 -9
- package/docs/configuration.md +18 -2
- package/docs/how-to-context-budget.md +1 -1
- package/docs/mcp.md +3 -3
- package/docs/output.md +8 -5
- 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/cli.cjs
CHANGED
|
@@ -196,8 +196,8 @@ function workspacePackageDirs(cwd, patterns) {
|
|
|
196
196
|
function scanWorkspacePackages(cwd, patterns) {
|
|
197
197
|
const files = /* @__PURE__ */ new Set();
|
|
198
198
|
const dependencies = /* @__PURE__ */ new Set();
|
|
199
|
-
for (const
|
|
200
|
-
const full = path16__namespace.join(cwd,
|
|
199
|
+
for (const relative15 of workspacePackageDirs(cwd, patterns)) {
|
|
200
|
+
const full = path16__namespace.join(cwd, relative15);
|
|
201
201
|
try {
|
|
202
202
|
for (const entry of fs15__namespace.readdirSync(full, { withFileTypes: true })) files.add(entry.name);
|
|
203
203
|
} catch {
|
|
@@ -1316,6 +1316,24 @@ var DEFAULT_SECRET_PATTERNS = [
|
|
|
1316
1316
|
),
|
|
1317
1317
|
valueGroup: 2
|
|
1318
1318
|
},
|
|
1319
|
+
{
|
|
1320
|
+
// A quoted assignment whose closing quote is **not on this line**.
|
|
1321
|
+
//
|
|
1322
|
+
// The rule above requires `\1`, so an unterminated literal never matched it and the
|
|
1323
|
+
// credential reached the artefact in clear with no finding at all. That is the shape a
|
|
1324
|
+
// truncated file, a hand-edited `.env` and a string that continues on the next line all
|
|
1325
|
+
// produce, and it was the only branch of the redaction pass that was silent.
|
|
1326
|
+
//
|
|
1327
|
+
// The value runs to the end of the line on purpose — there is no delimiter to stop at — and
|
|
1328
|
+
// a later quote of the same kind disables the rule (`(?!\1)`), so a balanced literal is
|
|
1329
|
+
// never matched here: `password: "abc" and "def"` belongs to the rule above.
|
|
1330
|
+
rule: "credential-assignment-unterminated",
|
|
1331
|
+
pattern: new RegExp(
|
|
1332
|
+
`(?:${QUOTED_CREDENTIAL_KEY}|${NOT_AFTER_QUOTE}(?<!id[-_])${STRONG_CREDENTIAL_NAME})\\s{0,8}${ASSIGN}\\s{0,8}(["'\`])((?:(?!\\1)[^\\\\\\n]|\\\\.){1,512})$`,
|
|
1333
|
+
"i"
|
|
1334
|
+
),
|
|
1335
|
+
valueGroup: 2
|
|
1336
|
+
},
|
|
1319
1337
|
{
|
|
1320
1338
|
// `pass` and `credentials` are ambiguous on their own, so they
|
|
1321
1339
|
// are accepted only against a quoted value long enough to be a credential.
|
|
@@ -1875,10 +1893,8 @@ function scanAndRedactSecrets(content, rules, filePath) {
|
|
|
1875
1893
|
}
|
|
1876
1894
|
if (spans.length > 0) {
|
|
1877
1895
|
const maskedLine = applySpans(line, spans);
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
|
-
segments[index] = maskedLine;
|
|
1881
|
-
}
|
|
1896
|
+
recordFinding(lineNumber, matchedRules);
|
|
1897
|
+
segments[index] = !quotesAreBalanced(line) || quotesAreBalanced(maskedLine) ? maskedLine : applySpansKeepingQuotes(line, spans);
|
|
1882
1898
|
}
|
|
1883
1899
|
}
|
|
1884
1900
|
if (index + 1 < segments.length) lineNumber += 1;
|
|
@@ -2156,6 +2172,17 @@ function isDeclaredBinding(line, matchIndex, filePath) {
|
|
|
2156
2172
|
return DECLARATION_KEYWORDS.test(line.slice(from, runStart));
|
|
2157
2173
|
}
|
|
2158
2174
|
function applySpans(line, spans) {
|
|
2175
|
+
let out = "";
|
|
2176
|
+
let cursor = 0;
|
|
2177
|
+
for (const span of mergedSpans(line, spans)) {
|
|
2178
|
+
out += line.slice(cursor, span.start);
|
|
2179
|
+
out += REDACTION_MARKER;
|
|
2180
|
+
cursor = span.end;
|
|
2181
|
+
}
|
|
2182
|
+
out += line.slice(cursor);
|
|
2183
|
+
return out;
|
|
2184
|
+
}
|
|
2185
|
+
function mergedSpans(line, spans) {
|
|
2159
2186
|
const ordered = [...spans].sort((a, b) => a.start - b.start || a.end - b.end);
|
|
2160
2187
|
const merged = [];
|
|
2161
2188
|
for (const span of ordered) {
|
|
@@ -2166,11 +2193,25 @@ function applySpans(line, spans) {
|
|
|
2166
2193
|
if (last && start <= last.end) last.end = Math.max(last.end, end);
|
|
2167
2194
|
else merged.push({ start, end });
|
|
2168
2195
|
}
|
|
2196
|
+
return merged;
|
|
2197
|
+
}
|
|
2198
|
+
function applySpansKeepingQuotes(line, spans) {
|
|
2169
2199
|
let out = "";
|
|
2170
2200
|
let cursor = 0;
|
|
2171
|
-
for (const span of
|
|
2201
|
+
for (const span of mergedSpans(line, spans)) {
|
|
2172
2202
|
out += line.slice(cursor, span.start);
|
|
2173
|
-
|
|
2203
|
+
let run = false;
|
|
2204
|
+
for (let index = span.start; index < span.end; index += 1) {
|
|
2205
|
+
const char = line[index];
|
|
2206
|
+
if (char === '"' || char === "'" || char === "`" || char === "\\") {
|
|
2207
|
+
if (run) out += REDACTION_MARKER;
|
|
2208
|
+
run = false;
|
|
2209
|
+
out += char;
|
|
2210
|
+
continue;
|
|
2211
|
+
}
|
|
2212
|
+
run = true;
|
|
2213
|
+
}
|
|
2214
|
+
if (run) out += REDACTION_MARKER;
|
|
2174
2215
|
cursor = span.end;
|
|
2175
2216
|
}
|
|
2176
2217
|
out += line.slice(cursor);
|
|
@@ -2179,7 +2220,7 @@ function applySpans(line, spans) {
|
|
|
2179
2220
|
|
|
2180
2221
|
// src/version.ts
|
|
2181
2222
|
var GENERATOR_NAME = "codebase-snapshot";
|
|
2182
|
-
var GENERATOR_VERSION = "0.10.
|
|
2223
|
+
var GENERATOR_VERSION = "0.10.2";
|
|
2183
2224
|
var SCHEMA_VERSION = "3.0.0";
|
|
2184
2225
|
var LEGACY_GENERATOR_NAMES = ["@ankurhalder/codebase-snapshot"];
|
|
2185
2226
|
function isOurGeneratorName(name) {
|
|
@@ -2211,8 +2252,8 @@ function brokenLinkRecord(linkPath, relativePath, rootReal) {
|
|
|
2211
2252
|
};
|
|
2212
2253
|
}
|
|
2213
2254
|
function isInside(root, candidate) {
|
|
2214
|
-
const
|
|
2215
|
-
return
|
|
2255
|
+
const relative15 = path16__namespace.relative(root, candidate);
|
|
2256
|
+
return relative15 === "" || !relative15.startsWith(`..${path16__namespace.sep}`) && relative15 !== ".." && !path16__namespace.isAbsolute(relative15);
|
|
2216
2257
|
}
|
|
2217
2258
|
var GIT_OUTPUT_LIMIT = 68157440;
|
|
2218
2259
|
function getGitInfo(cwd, fallbackBranch = "main") {
|
|
@@ -3063,6 +3104,178 @@ function walkDirectory(dir, baseDir, rootReal, visited, reservedPaths = /* @__PU
|
|
|
3063
3104
|
return results;
|
|
3064
3105
|
}
|
|
3065
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
|
+
|
|
3066
3279
|
// src/tokenize.ts
|
|
3067
3280
|
var WORD_RUN = /[A-Za-z0-9_]+/g;
|
|
3068
3281
|
var SINGLE_TOKEN = /[^\sA-Za-z0-9_]/g;
|
|
@@ -3219,70 +3432,6 @@ function supportsTypeScriptImports() {
|
|
|
3219
3432
|
if (!Number.isFinite(major)) return false;
|
|
3220
3433
|
return major > 22 || major === 22 && minor >= 6;
|
|
3221
3434
|
}
|
|
3222
|
-
function stripJsonComments(raw) {
|
|
3223
|
-
const text2 = raw.replace(/^\uFEFF/, "");
|
|
3224
|
-
let out = "";
|
|
3225
|
-
let inString = false;
|
|
3226
|
-
let escaped = false;
|
|
3227
|
-
for (let index = 0; index < text2.length; index += 1) {
|
|
3228
|
-
const char = text2[index];
|
|
3229
|
-
if (inString) {
|
|
3230
|
-
out += char;
|
|
3231
|
-
if (escaped) escaped = false;
|
|
3232
|
-
else if (char === "\\") escaped = true;
|
|
3233
|
-
else if (char === '"') inString = false;
|
|
3234
|
-
continue;
|
|
3235
|
-
}
|
|
3236
|
-
if (char === '"') {
|
|
3237
|
-
inString = true;
|
|
3238
|
-
out += char;
|
|
3239
|
-
continue;
|
|
3240
|
-
}
|
|
3241
|
-
if (char === "/" && text2[index + 1] === "/") {
|
|
3242
|
-
while (index < text2.length && text2[index] !== "\n" && text2[index] !== "\r") index += 1;
|
|
3243
|
-
index -= 1;
|
|
3244
|
-
continue;
|
|
3245
|
-
}
|
|
3246
|
-
if (char === "/" && text2[index + 1] === "*") {
|
|
3247
|
-
index += 2;
|
|
3248
|
-
while (index < text2.length && !(text2[index] === "*" && text2[index + 1] === "/")) {
|
|
3249
|
-
if (text2[index] === "\n" || text2[index] === "\r") out += text2[index];
|
|
3250
|
-
index += 1;
|
|
3251
|
-
}
|
|
3252
|
-
index += 1;
|
|
3253
|
-
continue;
|
|
3254
|
-
}
|
|
3255
|
-
out += char;
|
|
3256
|
-
}
|
|
3257
|
-
return stripTrailingCommas(out);
|
|
3258
|
-
}
|
|
3259
|
-
function stripTrailingCommas(text2) {
|
|
3260
|
-
let out = "";
|
|
3261
|
-
let inString = false;
|
|
3262
|
-
let escaped = false;
|
|
3263
|
-
for (let index = 0; index < text2.length; index += 1) {
|
|
3264
|
-
const char = text2[index];
|
|
3265
|
-
if (inString) {
|
|
3266
|
-
out += char;
|
|
3267
|
-
if (escaped) escaped = false;
|
|
3268
|
-
else if (char === "\\") escaped = true;
|
|
3269
|
-
else if (char === '"') inString = false;
|
|
3270
|
-
continue;
|
|
3271
|
-
}
|
|
3272
|
-
if (char === '"') {
|
|
3273
|
-
inString = true;
|
|
3274
|
-
out += char;
|
|
3275
|
-
continue;
|
|
3276
|
-
}
|
|
3277
|
-
if (char === ",") {
|
|
3278
|
-
let next = index + 1;
|
|
3279
|
-
while (next < text2.length && /\s/.test(text2[next])) next += 1;
|
|
3280
|
-
if (text2[next] === "}" || text2[next] === "]") continue;
|
|
3281
|
-
}
|
|
3282
|
-
out += char;
|
|
3283
|
-
}
|
|
3284
|
-
return out;
|
|
3285
|
-
}
|
|
3286
3435
|
function parseJsonish(raw, file) {
|
|
3287
3436
|
try {
|
|
3288
3437
|
return JSON.parse(stripJsonComments(raw));
|
|
@@ -3303,7 +3452,7 @@ function describeValue2(value) {
|
|
|
3303
3452
|
return `${typeof value} (${String(value)})`;
|
|
3304
3453
|
}
|
|
3305
3454
|
var isThenable = (value) => typeof value.then === "function";
|
|
3306
|
-
var
|
|
3455
|
+
var CONFIG_KEY_NAMES = [
|
|
3307
3456
|
"artifacts",
|
|
3308
3457
|
"branch",
|
|
3309
3458
|
"budgets",
|
|
@@ -3334,7 +3483,8 @@ var CONFIG_KEYS = /* @__PURE__ */ new Set([
|
|
|
3334
3483
|
"skeleton",
|
|
3335
3484
|
"tmpDir",
|
|
3336
3485
|
"withDependents"
|
|
3337
|
-
]
|
|
3486
|
+
];
|
|
3487
|
+
var CONFIG_KEYS = new Set(CONFIG_KEY_NAMES);
|
|
3338
3488
|
function assertKnownConfigKeys(value, file) {
|
|
3339
3489
|
const unknownKeys = Object.keys(value).filter((key) => !CONFIG_KEYS.has(key));
|
|
3340
3490
|
if (unknownKeys.length === 0) return;
|
|
@@ -3681,11 +3831,11 @@ function outputExcludePatterns(cwd, outDir, tmpDir) {
|
|
|
3681
3831
|
const patterns = [];
|
|
3682
3832
|
for (const dir of [outDir, tmpDir]) {
|
|
3683
3833
|
const absolute = path16__namespace.resolve(cwd, dir);
|
|
3684
|
-
const
|
|
3685
|
-
if (!
|
|
3834
|
+
const relative15 = path16__namespace.relative(cwd, absolute);
|
|
3835
|
+
if (!relative15 || relative15 === ".." || relative15.startsWith(`..${path16__namespace.sep}`) || path16__namespace.isAbsolute(relative15)) {
|
|
3686
3836
|
continue;
|
|
3687
3837
|
}
|
|
3688
|
-
patterns.push(`${
|
|
3838
|
+
patterns.push(`${relative15.replace(/\\/g, "/")}/**`);
|
|
3689
3839
|
}
|
|
3690
3840
|
return patterns;
|
|
3691
3841
|
}
|
|
@@ -4252,8 +4402,8 @@ function tsconfigPathsFor(cwd) {
|
|
|
4252
4402
|
return value;
|
|
4253
4403
|
}
|
|
4254
4404
|
function repositoryRelative(cwd, target) {
|
|
4255
|
-
const
|
|
4256
|
-
return
|
|
4405
|
+
const relative15 = path16__namespace.relative(cwd, target).replace(/\\/g, "/");
|
|
4406
|
+
return relative15.length === 0 || !relative15.startsWith("..") && !path16__namespace.isAbsolute(relative15) ? relative15 : null;
|
|
4257
4407
|
}
|
|
4258
4408
|
function rememberFirst(map, key, value) {
|
|
4259
4409
|
if (!map.has(key)) map.set(key, value);
|
|
@@ -4651,6 +4801,8 @@ function summarizeTypeScriptSource(relativePath, content) {
|
|
|
4651
4801
|
if (cjsExports.length > 0) {
|
|
4652
4802
|
summary.exportsKind = summary.exports.length > 0 ? "mixed" : "cjs";
|
|
4653
4803
|
summary.exports.push(...cjsExports);
|
|
4804
|
+
} else if (summary.exports.length > 0) {
|
|
4805
|
+
summary.exportsKind = "esm";
|
|
4654
4806
|
}
|
|
4655
4807
|
const dedupeSorted2 = (values) => Array.from(new Set(values)).sort((a, b) => a < b ? -1 : a > b ? 1 : 0);
|
|
4656
4808
|
summary.directives = dedupeSorted2(summary.directives);
|
|
@@ -5215,9 +5367,9 @@ var rubyProfile = {
|
|
|
5215
5367
|
eachLine(content, (line) => {
|
|
5216
5368
|
const trimmed = line.trim();
|
|
5217
5369
|
if (!trimmed || trimmed.startsWith("#")) return;
|
|
5218
|
-
const
|
|
5219
|
-
if (
|
|
5220
|
-
summary.imports.push(`./${
|
|
5370
|
+
const relative15 = REQUIRE_RELATIVE.exec(trimmed);
|
|
5371
|
+
if (relative15) {
|
|
5372
|
+
summary.imports.push(`./${relative15[1]}`);
|
|
5221
5373
|
return;
|
|
5222
5374
|
}
|
|
5223
5375
|
const required = REQUIRE.exec(trimmed);
|
|
@@ -5879,6 +6031,16 @@ function wouldNowBeIncluded(cwd, relativePath) {
|
|
|
5879
6031
|
return false;
|
|
5880
6032
|
}
|
|
5881
6033
|
}
|
|
6034
|
+
var TRUNCATION_REASONS = /* @__PURE__ */ new Set([
|
|
6035
|
+
"large-file-budget",
|
|
6036
|
+
"part-budget",
|
|
6037
|
+
"section-metadata"
|
|
6038
|
+
]);
|
|
6039
|
+
function isConfinedRelative(value) {
|
|
6040
|
+
if (value.length === 0 || value.includes("\0") || value.includes("\\")) return false;
|
|
6041
|
+
if (path16__namespace.isAbsolute(value)) return false;
|
|
6042
|
+
return !value.split("/").includes("..");
|
|
6043
|
+
}
|
|
5882
6044
|
function describeManifestShapeProblem(value) {
|
|
5883
6045
|
if (!value || typeof value !== "object" || Array.isArray(value)) return "not a JSON object";
|
|
5884
6046
|
const candidate = value;
|
|
@@ -5944,6 +6106,68 @@ function describeManifestShapeProblem(value) {
|
|
|
5944
6106
|
if (!candidate.kinds || typeof candidate.kinds !== "object" || Array.isArray(candidate.kinds)) {
|
|
5945
6107
|
return 'missing "kinds" object';
|
|
5946
6108
|
}
|
|
6109
|
+
const incompleteCount = counts.incompleteCount;
|
|
6110
|
+
if (typeof incompleteCount !== "number" || !Number.isSafeInteger(incompleteCount) || incompleteCount < 0) {
|
|
6111
|
+
return "missing numeric `counts.incompleteCount`";
|
|
6112
|
+
}
|
|
6113
|
+
const incomplete = candidate.incomplete;
|
|
6114
|
+
if (!Array.isArray(incomplete)) return 'missing "incomplete" array';
|
|
6115
|
+
if (incompleteCount !== incomplete.length) {
|
|
6116
|
+
return "`counts.incompleteCount` does not match the length of `incomplete`";
|
|
6117
|
+
}
|
|
6118
|
+
for (const entry of incomplete) {
|
|
6119
|
+
if (!entry || typeof entry !== "object" || Array.isArray(entry)) {
|
|
6120
|
+
return 'an "incomplete" entry is not an object';
|
|
6121
|
+
}
|
|
6122
|
+
const fields = entry;
|
|
6123
|
+
const relativePath = fields.relativePath;
|
|
6124
|
+
if (typeof relativePath !== "string" || relativePath.length === 0) {
|
|
6125
|
+
return 'an "incomplete" entry has no "relativePath"';
|
|
6126
|
+
}
|
|
6127
|
+
if (!isConfinedRelative(relativePath)) {
|
|
6128
|
+
return 'an "incomplete" entry "relativePath" must stay inside the repository';
|
|
6129
|
+
}
|
|
6130
|
+
if (typeof fields.part !== "string" || fields.part.trim() === "") {
|
|
6131
|
+
return 'an "incomplete" entry has no "part"';
|
|
6132
|
+
}
|
|
6133
|
+
if (typeof fields.reason !== "string" || !TRUNCATION_REASONS.has(fields.reason)) {
|
|
6134
|
+
return 'an "incomplete" entry has an unknown "reason"';
|
|
6135
|
+
}
|
|
6136
|
+
for (const key of ["omittedLines", "includedLines", "lines"]) {
|
|
6137
|
+
const value2 = fields[key];
|
|
6138
|
+
if (typeof value2 !== "number" || !Number.isSafeInteger(value2) || value2 < 0) {
|
|
6139
|
+
return `an "incomplete" entry "${key}" must be a non-negative integer`;
|
|
6140
|
+
}
|
|
6141
|
+
}
|
|
6142
|
+
const lines = fields.lines;
|
|
6143
|
+
if (fields.includedLines > lines) {
|
|
6144
|
+
return 'an "incomplete" entry "includedLines" exceeds its "lines"';
|
|
6145
|
+
}
|
|
6146
|
+
const ranges = fields.omittedRanges;
|
|
6147
|
+
if (!Array.isArray(ranges)) return 'an "incomplete" entry has no "omittedRanges" array';
|
|
6148
|
+
let previousEnd = 0;
|
|
6149
|
+
let omitted = 0;
|
|
6150
|
+
for (const range of ranges) {
|
|
6151
|
+
if (!Array.isArray(range) || range.length !== 2) {
|
|
6152
|
+
return 'an "incomplete" entry "omittedRanges" must hold [from, to] pairs';
|
|
6153
|
+
}
|
|
6154
|
+
const [from, to] = range;
|
|
6155
|
+
if (typeof from !== "number" || typeof to !== "number" || !Number.isSafeInteger(from) || !Number.isSafeInteger(to)) {
|
|
6156
|
+
return 'an "incomplete" entry "omittedRanges" must hold integer pairs';
|
|
6157
|
+
}
|
|
6158
|
+
if (from < 1 || to < from || to > lines) {
|
|
6159
|
+
return `an "incomplete" entry records an omitted range ${from}-${to}, outside 1-${lines}`;
|
|
6160
|
+
}
|
|
6161
|
+
if (from <= previousEnd) {
|
|
6162
|
+
return 'an "incomplete" entry "omittedRanges" must be sorted and non-overlapping';
|
|
6163
|
+
}
|
|
6164
|
+
previousEnd = to;
|
|
6165
|
+
omitted += to - from + 1;
|
|
6166
|
+
}
|
|
6167
|
+
if (omitted !== fields.omittedLines) {
|
|
6168
|
+
return "`omittedLines` does not match the ranges it records";
|
|
6169
|
+
}
|
|
6170
|
+
}
|
|
5947
6171
|
}
|
|
5948
6172
|
if (!Array.isArray(candidate.files)) return 'missing "files" array';
|
|
5949
6173
|
for (const entry of candidate.files) {
|
|
@@ -6056,11 +6280,57 @@ function validateSnapshot(configInput) {
|
|
|
6056
6280
|
"The configuration uses executable (function) matchers; the recorded digest covers their source text, not the values they capture, so it cannot prove their classification is unchanged."
|
|
6057
6281
|
);
|
|
6058
6282
|
}
|
|
6059
|
-
const manifestFileMap = /* @__PURE__ */ new Map();
|
|
6283
|
+
const manifestFileMap = /* @__PURE__ */ new Map();
|
|
6284
|
+
const manifestFilesByPath = /* @__PURE__ */ new Map();
|
|
6285
|
+
for (const file of manifest.files) {
|
|
6286
|
+
if (file && typeof file.relativePath === "string") {
|
|
6287
|
+
manifestFileMap.set(file.relativePath, file.hashSha256);
|
|
6288
|
+
manifestFilesByPath.set(file.relativePath, file);
|
|
6289
|
+
}
|
|
6290
|
+
}
|
|
6291
|
+
const incompleteRecords = manifest.incomplete ?? [];
|
|
6292
|
+
const incompleteness = /* @__PURE__ */ new Map();
|
|
6293
|
+
for (const record of incompleteRecords) {
|
|
6294
|
+
incompleteness.set(record.relativePath, record);
|
|
6295
|
+
const label = maskedPath(record.relativePath, config.secretRules);
|
|
6296
|
+
const file = manifestFilesByPath.get(record.relativePath);
|
|
6297
|
+
if (file === void 0) {
|
|
6298
|
+
drift.partIssues.push({
|
|
6299
|
+
part: "(manifest)",
|
|
6300
|
+
issue: `${label} is in incomplete[] but not in files[]`
|
|
6301
|
+
});
|
|
6302
|
+
continue;
|
|
6303
|
+
}
|
|
6304
|
+
if (file.part !== record.part) {
|
|
6305
|
+
drift.partIssues.push({
|
|
6306
|
+
part: "(manifest)",
|
|
6307
|
+
issue: `${label} is recorded in part ${String(record.part)} in incomplete[] and part ${String(file.part)} in files[]`
|
|
6308
|
+
});
|
|
6309
|
+
}
|
|
6310
|
+
if (file.truncationReason !== record.reason) {
|
|
6311
|
+
drift.partIssues.push({
|
|
6312
|
+
part: "(manifest)",
|
|
6313
|
+
issue: `${label} records truncationReason ${String(file.truncationReason)} in files[] and reason ${String(record.reason)} in incomplete[]`
|
|
6314
|
+
});
|
|
6315
|
+
}
|
|
6316
|
+
const recordedRanges = file.omittedRanges ?? [];
|
|
6317
|
+
const rangesAgree = recordedRanges.length === record.omittedRanges.length && recordedRanges.every(
|
|
6318
|
+
([from, to], index) => record.omittedRanges[index][0] === from && record.omittedRanges[index][1] === to
|
|
6319
|
+
);
|
|
6320
|
+
if (!rangesAgree || file.includedLines !== record.includedLines || file.lines !== record.lines) {
|
|
6321
|
+
drift.partIssues.push({
|
|
6322
|
+
part: "(manifest)",
|
|
6323
|
+
issue: `${label} records different omission numbers in files[] and incomplete[]`
|
|
6324
|
+
});
|
|
6325
|
+
}
|
|
6326
|
+
}
|
|
6060
6327
|
for (const file of manifest.files) {
|
|
6061
|
-
if (file
|
|
6062
|
-
|
|
6063
|
-
|
|
6328
|
+
if (file.truncationReason === void 0) continue;
|
|
6329
|
+
if (incompleteness.has(file.relativePath)) continue;
|
|
6330
|
+
drift.partIssues.push({
|
|
6331
|
+
part: "(manifest)",
|
|
6332
|
+
issue: `${maskedPath(file.relativePath, config.secretRules)} records a truncationReason but is missing from incomplete[]`
|
|
6333
|
+
});
|
|
6064
6334
|
}
|
|
6065
6335
|
const skippedReasons = /* @__PURE__ */ new Map();
|
|
6066
6336
|
for (const entry of manifest.skipped) {
|
|
@@ -6118,7 +6388,7 @@ function validateSnapshot(configInput) {
|
|
|
6118
6388
|
// snapshot was reported as drifting.
|
|
6119
6389
|
toolOwnedPaths: [config.outDir, config.tmpDir].map(
|
|
6120
6390
|
(directory) => path16__namespace.relative(config.cwd, path16__namespace.resolve(config.cwd, directory)).replace(/\\/g, "/")
|
|
6121
|
-
).filter((
|
|
6391
|
+
).filter((relative15) => relative15.length > 0 && !relative15.startsWith(".."))
|
|
6122
6392
|
});
|
|
6123
6393
|
for (const diskFile of collection.files) {
|
|
6124
6394
|
const snapshotHash = manifestFileMap.get(diskFile);
|
|
@@ -6574,8 +6844,8 @@ function validateSnapshot(configInput) {
|
|
|
6574
6844
|
const target = match[1].split("#")[0];
|
|
6575
6845
|
if (target.length === 0 || /^[a-z][a-z0-9+.-]*:/i.test(target)) continue;
|
|
6576
6846
|
const resolved = path16__namespace.resolve(snapshotDir, "reports", target);
|
|
6577
|
-
const
|
|
6578
|
-
if (
|
|
6847
|
+
const relative15 = path16__namespace.relative(snapshotDir, resolved);
|
|
6848
|
+
if (relative15.startsWith("..") || path16__namespace.isAbsolute(relative15) || !fs15__namespace.existsSync(resolved)) {
|
|
6579
6849
|
drift.partIssues.push({
|
|
6580
6850
|
part: key,
|
|
6581
6851
|
issue: `links to ${maskedPath(target, config.secretRules)}, which does not exist in the snapshot`
|
|
@@ -6671,19 +6941,19 @@ function side(manifest) {
|
|
|
6671
6941
|
function shortDigest(value) {
|
|
6672
6942
|
return value === null ? "not recorded" : `${value.slice(0, 12)}\u2026`;
|
|
6673
6943
|
}
|
|
6674
|
-
function describeLayerChanges(before, after) {
|
|
6944
|
+
function describeLayerChanges(before, after, secretRules) {
|
|
6675
6945
|
const names = Array.from(/* @__PURE__ */ new Set([...Object.keys(before), ...Object.keys(after)])).sort();
|
|
6676
6946
|
const changes = [];
|
|
6677
6947
|
for (const name of names) {
|
|
6678
6948
|
const was = before[name] ?? 0;
|
|
6679
6949
|
const now = after[name] ?? 0;
|
|
6680
6950
|
if (was === now) continue;
|
|
6681
|
-
const label = findSecretInPath(name)?.masked ?? name;
|
|
6951
|
+
const label = findSecretInPath(name, secretRules)?.masked ?? name;
|
|
6682
6952
|
changes.push(`layer "${label}": ${was} file(s) \u2192 ${now} file(s)`);
|
|
6683
6953
|
}
|
|
6684
6954
|
return changes;
|
|
6685
6955
|
}
|
|
6686
|
-
function describePartChanges(before, after) {
|
|
6956
|
+
function describePartChanges(before, after, secretRules) {
|
|
6687
6957
|
const index = (parts) => {
|
|
6688
6958
|
const map = /* @__PURE__ */ new Map();
|
|
6689
6959
|
for (const part of parts) {
|
|
@@ -6693,7 +6963,7 @@ function describePartChanges(before, after) {
|
|
|
6693
6963
|
};
|
|
6694
6964
|
const left = index(before);
|
|
6695
6965
|
const right = index(after);
|
|
6696
|
-
const label = (filename) => findSecretInPath(filename)?.masked ?? filename;
|
|
6966
|
+
const label = (filename) => findSecretInPath(filename, secretRules)?.masked ?? filename;
|
|
6697
6967
|
const changes = [];
|
|
6698
6968
|
for (const [filename, part] of right) {
|
|
6699
6969
|
const previous = left.get(filename);
|
|
@@ -6721,7 +6991,15 @@ function describePartChanges(before, after) {
|
|
|
6721
6991
|
}
|
|
6722
6992
|
return changes;
|
|
6723
6993
|
}
|
|
6724
|
-
function
|
|
6994
|
+
function maskLayerNames(layers, secretRules) {
|
|
6995
|
+
return Object.fromEntries(
|
|
6996
|
+
Object.entries(layers ?? {}).map(([name, count]) => [
|
|
6997
|
+
findSecretInPath(name, secretRules)?.masked ?? name,
|
|
6998
|
+
count
|
|
6999
|
+
])
|
|
7000
|
+
);
|
|
7001
|
+
}
|
|
7002
|
+
function describePayloadDiff(before, after, sourceFilesIdentical, secretRules) {
|
|
6725
7003
|
const generatorBefore = before.generator?.version ?? "unknown";
|
|
6726
7004
|
const generatorAfter = after.generator?.version ?? "unknown";
|
|
6727
7005
|
const digestBefore = typeof before.config?.digest === "string" ? before.config.digest : null;
|
|
@@ -6734,35 +7012,43 @@ function describePayloadDiff(before, after, sourceFilesIdentical) {
|
|
|
6734
7012
|
const configurationDiffers = generatorDiffers || digestDiffers || schemaDiffers;
|
|
6735
7013
|
const fingerprintDiffers = before.fingerprint !== after.fingerprint;
|
|
6736
7014
|
const partsDiffer = before.counts.partsCount !== after.counts.partsCount;
|
|
6737
|
-
const partChanges = describePartChanges(before.parts ?? [], after.parts ?? []);
|
|
6738
|
-
const layerChanges = describeLayerChanges(before.layers ?? {}, after.layers ?? {});
|
|
7015
|
+
const partChanges = describePartChanges(before.parts ?? [], after.parts ?? [], secretRules);
|
|
7016
|
+
const layerChanges = describeLayerChanges(before.layers ?? {}, after.layers ?? {}, secretRules);
|
|
6739
7017
|
const reasons = [];
|
|
7018
|
+
const codes = [];
|
|
6740
7019
|
if (schemaDiffers) {
|
|
7020
|
+
codes.push("schema-version");
|
|
6741
7021
|
reasons.push(
|
|
6742
7022
|
`schema version ${schemaBefore} \u2192 ${schemaAfter} (the two manifests describe different formats)`
|
|
6743
7023
|
);
|
|
6744
7024
|
}
|
|
6745
7025
|
if (digestDiffers) {
|
|
7026
|
+
codes.push("config-digest");
|
|
6746
7027
|
reasons.push(
|
|
6747
7028
|
`configuration digest ${shortDigest(digestBefore)} \u2192 ${shortDigest(digestAfter)} (budgets, preview thresholds, redaction rules and artifact selection all count)`
|
|
6748
7029
|
);
|
|
6749
7030
|
} else if (digestBefore === null || digestAfter === null) {
|
|
6750
7031
|
const missing = digestBefore === null && digestAfter !== null ? "before" : digestAfter === null && digestBefore !== null ? "after" : "both";
|
|
7032
|
+
codes.push("config-digest-missing");
|
|
6751
7033
|
reasons.push(
|
|
6752
7034
|
`configuration digest not recorded on the ${missing} side (manifest written before 4.0.5); compared the content fingerprint and part count instead`
|
|
6753
7035
|
);
|
|
6754
7036
|
}
|
|
6755
7037
|
if (generatorDiffers) {
|
|
7038
|
+
codes.push("generator");
|
|
6756
7039
|
reasons.push(`generator ${generatorBefore} \u2192 ${generatorAfter}`);
|
|
6757
7040
|
}
|
|
6758
7041
|
if (fingerprintDiffers && (sourceFilesIdentical || configurationDiffers)) {
|
|
7042
|
+
codes.push("fingerprint");
|
|
6759
7043
|
reasons.push(
|
|
6760
7044
|
`content fingerprint ${shortDigest(before.fingerprint)} \u2192 ${shortDigest(after.fingerprint)}` + (sourceFilesIdentical ? " (same source files, packed or configured differently)" : "")
|
|
6761
7045
|
);
|
|
6762
7046
|
}
|
|
6763
7047
|
if (partsDiffer) {
|
|
7048
|
+
codes.push("parts-count");
|
|
6764
7049
|
reasons.push(`${before.counts.partsCount} part(s) \u2192 ${after.counts.partsCount} part(s)`);
|
|
6765
7050
|
}
|
|
7051
|
+
for (let index = 0; index < layerChanges.length; index += 1) codes.push("layer-changed");
|
|
6766
7052
|
reasons.push(...layerChanges);
|
|
6767
7053
|
return {
|
|
6768
7054
|
sourceFilesIdentical,
|
|
@@ -6774,8 +7060,12 @@ function describePayloadDiff(before, after, sourceFilesIdentical) {
|
|
|
6774
7060
|
partsCount: { before: before.counts.partsCount, after: after.counts.partsCount },
|
|
6775
7061
|
schemaVersion: { before: schemaBefore, after: schemaAfter },
|
|
6776
7062
|
partsManifest: { differs: partChanges.length > 0, changes: partChanges },
|
|
6777
|
-
|
|
6778
|
-
|
|
7063
|
+
// The layer maps are printed and serialized, so a layer named after a project token leaks the
|
|
7064
|
+
// token here even though every reason line above is masked. Found while testing the rules
|
|
7065
|
+
// parameter: masking the prose and not the data it describes is the same bug one layer down.
|
|
7066
|
+
layers: { before: maskLayerNames(before.layers, secretRules), after: maskLayerNames(after.layers, secretRules) },
|
|
7067
|
+
reasons,
|
|
7068
|
+
codes
|
|
6779
7069
|
};
|
|
6780
7070
|
}
|
|
6781
7071
|
function hashMap(manifest) {
|
|
@@ -6814,10 +7104,10 @@ function comparableProblem(value) {
|
|
|
6814
7104
|
function assertUsableManifest(value, label) {
|
|
6815
7105
|
const problem = comparableProblem(value);
|
|
6816
7106
|
if (problem) {
|
|
6817
|
-
throw new Error(`The ${label} manifest is not a snapshot manifest
|
|
7107
|
+
throw new Error(`The ${label} manifest is not a snapshot manifest: ${problem}.`);
|
|
6818
7108
|
}
|
|
6819
7109
|
}
|
|
6820
|
-
function compareManifests(before, after) {
|
|
7110
|
+
function compareManifests(before, after, secretRules) {
|
|
6821
7111
|
assertUsableManifest(before, "before");
|
|
6822
7112
|
assertUsableManifest(after, "after");
|
|
6823
7113
|
const left = hashMap(before);
|
|
@@ -6837,8 +7127,8 @@ function compareManifests(before, after) {
|
|
|
6837
7127
|
}
|
|
6838
7128
|
const sort = (values) => values.sort((a, b) => a < b ? -1 : a > b ? 1 : 0);
|
|
6839
7129
|
const sourceFilesIdentical = added.length === 0 && removed.length === 0 && changed.length === 0;
|
|
6840
|
-
const payload = describePayloadDiff(before, after, sourceFilesIdentical);
|
|
6841
|
-
const mask = (values) => values.map((value) => findSecretInPath(value)?.masked ?? value);
|
|
7130
|
+
const payload = describePayloadDiff(before, after, sourceFilesIdentical, secretRules);
|
|
7131
|
+
const mask = (values) => values.map((value) => findSecretInPath(value, secretRules)?.masked ?? value);
|
|
6842
7132
|
return {
|
|
6843
7133
|
before: side(before),
|
|
6844
7134
|
after: side(after),
|
|
@@ -6872,7 +7162,7 @@ function loadManifest(target) {
|
|
|
6872
7162
|
const problem = describeManifestShapeProblem(parsed);
|
|
6873
7163
|
if (problem) {
|
|
6874
7164
|
throw new Error(
|
|
6875
|
-
`${manifestPath} is not a
|
|
7165
|
+
`${manifestPath} is not a snapshot manifest: ${problem}. Point diff at a manifest.json written by \`generate\` (or at the directory that holds it).`
|
|
6876
7166
|
);
|
|
6877
7167
|
}
|
|
6878
7168
|
return parsed;
|
|
@@ -7139,23 +7429,23 @@ function describeMatcher(matcher) {
|
|
|
7139
7429
|
function normalizeTarget(cwd, target) {
|
|
7140
7430
|
const resolvedCwd = path16__namespace.resolve(cwd);
|
|
7141
7431
|
const absolute = path16__namespace.resolve(resolvedCwd, target);
|
|
7142
|
-
const
|
|
7143
|
-
if (
|
|
7432
|
+
const relative15 = path16__namespace.relative(resolvedCwd, absolute);
|
|
7433
|
+
if (relative15 === "" || relative15 === ".." || relative15.startsWith(`..${path16__namespace.sep}`) || path16__namespace.isAbsolute(relative15)) {
|
|
7144
7434
|
return { relative: target.replace(/\\/g, "/"), outsideRoot: true };
|
|
7145
7435
|
}
|
|
7146
|
-
return { relative:
|
|
7436
|
+
return { relative: relative15.split(path16__namespace.sep).join("/"), outsideRoot: false };
|
|
7147
7437
|
}
|
|
7148
7438
|
function findRuleMatch(rules, relativePath) {
|
|
7149
7439
|
return rules.find(
|
|
7150
7440
|
(rule) => matchRule(relativePath, rule.match)
|
|
7151
7441
|
);
|
|
7152
7442
|
}
|
|
7153
|
-
function findRecordedAncestor(skipped,
|
|
7443
|
+
function findRecordedAncestor(skipped, relative15, maskedPath2) {
|
|
7154
7444
|
let nearest;
|
|
7155
7445
|
for (const record of skipped) {
|
|
7156
7446
|
const ancestorPath = record.path;
|
|
7157
7447
|
if (ancestorPath.length === 0) continue;
|
|
7158
|
-
const isAncestor =
|
|
7448
|
+
const isAncestor = relative15.startsWith(`${ancestorPath}/`) || maskedPath2.startsWith(`${ancestorPath}/`);
|
|
7159
7449
|
if (!isAncestor) continue;
|
|
7160
7450
|
if (!nearest || ancestorPath.length > nearest.path.length) nearest = record;
|
|
7161
7451
|
}
|
|
@@ -7171,8 +7461,8 @@ function readManifest2(config) {
|
|
|
7171
7461
|
}
|
|
7172
7462
|
function explainPath(config, target) {
|
|
7173
7463
|
const normalized = normalizeTarget(config.cwd, target);
|
|
7174
|
-
const
|
|
7175
|
-
const maskedPath2 = findSecretInPath(
|
|
7464
|
+
const relative15 = normalized.relative;
|
|
7465
|
+
const maskedPath2 = findSecretInPath(relative15, config.secretRules)?.masked ?? relative15;
|
|
7176
7466
|
if (normalized.outsideRoot) {
|
|
7177
7467
|
return {
|
|
7178
7468
|
path: maskedPath2,
|
|
@@ -7182,7 +7472,7 @@ function explainPath(config, target) {
|
|
|
7182
7472
|
detail: "path resolves outside the configured repository root and was not inspected"
|
|
7183
7473
|
};
|
|
7184
7474
|
}
|
|
7185
|
-
const absolute = path16__namespace.join(config.cwd,
|
|
7475
|
+
const absolute = path16__namespace.join(config.cwd, relative15);
|
|
7186
7476
|
const result = {
|
|
7187
7477
|
path: maskedPath2,
|
|
7188
7478
|
exists: fs15__namespace.existsSync(absolute),
|
|
@@ -7200,11 +7490,11 @@ function explainPath(config, target) {
|
|
|
7200
7490
|
// that is only missing because the walker dropped the tool's own output directory.
|
|
7201
7491
|
toolOwnedPaths: [config.outDir, config.tmpDir].map(
|
|
7202
7492
|
(directory) => path16__namespace.relative(config.cwd, path16__namespace.resolve(config.cwd, directory)).replace(/\\/g, "/")
|
|
7203
|
-
).filter((
|
|
7493
|
+
).filter((relative16) => relative16.length > 0 && !relative16.startsWith(".."))
|
|
7204
7494
|
});
|
|
7205
|
-
if (!collection.files.includes(
|
|
7495
|
+
if (!collection.files.includes(relative15)) {
|
|
7206
7496
|
const record = collection.skipped.find(
|
|
7207
|
-
(entry2) => entry2.path ===
|
|
7497
|
+
(entry2) => entry2.path === relative15 || entry2.path === maskedPath2
|
|
7208
7498
|
);
|
|
7209
7499
|
if (record) {
|
|
7210
7500
|
result.reason = record.reason;
|
|
@@ -7213,7 +7503,7 @@ function explainPath(config, target) {
|
|
|
7213
7503
|
result.reason = "missing";
|
|
7214
7504
|
result.detail = "no such file or directory, relative to the configured cwd";
|
|
7215
7505
|
} else {
|
|
7216
|
-
const ancestor = findRecordedAncestor(collection.skipped,
|
|
7506
|
+
const ancestor = findRecordedAncestor(collection.skipped, relative15, maskedPath2);
|
|
7217
7507
|
if (ancestor) {
|
|
7218
7508
|
result.reason = ancestor.reason;
|
|
7219
7509
|
result.detail = ancestor.detail ? `${ancestor.detail} \u2014 inherited from the skipped directory \`${ancestor.path}\`` : `inside the skipped directory \`${ancestor.path}\``;
|
|
@@ -7233,11 +7523,11 @@ function explainPath(config, target) {
|
|
|
7233
7523
|
...config.changedSince === void 0 ? {} : { changedSince: config.changedSince },
|
|
7234
7524
|
...config.staged === true ? { staged: true } : {}
|
|
7235
7525
|
});
|
|
7236
|
-
inScope = scope.paths.has(
|
|
7526
|
+
inScope = scope.paths.has(relative15);
|
|
7237
7527
|
if (!inScope && config.withDependents === true) {
|
|
7238
7528
|
inScope = importsChangedFile(
|
|
7239
|
-
|
|
7240
|
-
importsOfFile(
|
|
7529
|
+
relative15,
|
|
7530
|
+
importsOfFile(relative15, absolute),
|
|
7241
7531
|
scope.paths,
|
|
7242
7532
|
buildImportResolver(collection.files.map((file) => ({ relativePath: file })))
|
|
7243
7533
|
);
|
|
@@ -7295,12 +7585,12 @@ function explainPath(config, target) {
|
|
|
7295
7585
|
result.bytes = buffer.length;
|
|
7296
7586
|
result.lines = countLines(text2);
|
|
7297
7587
|
if (decoded.encoding !== "utf-8") result.encoding = decoded.encoding;
|
|
7298
|
-
const { findings } = scanAndRedactSecrets(text2, config.secretRules,
|
|
7588
|
+
const { findings } = scanAndRedactSecrets(text2, config.secretRules, relative15);
|
|
7299
7589
|
result.secretCount = findings.length;
|
|
7300
7590
|
result.secrets = findings.slice(0, 20).map((finding) => ({ rules: finding.rules, line: finding.line }));
|
|
7301
7591
|
let inclusionMode = "full";
|
|
7302
|
-
if (config.skeleton === true && isSkeletonizable(
|
|
7303
|
-
const skeleton = skeletonizeTypeScript(text2,
|
|
7592
|
+
if (config.skeleton === true && isSkeletonizable(relative15)) {
|
|
7593
|
+
const skeleton = skeletonizeTypeScript(text2, relative15);
|
|
7304
7594
|
if (skeleton.collapsed > 0) inclusionMode = "signatures";
|
|
7305
7595
|
}
|
|
7306
7596
|
if (inclusionMode !== "signatures" && buffer.length > config.largeFileBytes) {
|
|
@@ -7309,15 +7599,15 @@ function explainPath(config, target) {
|
|
|
7309
7599
|
}
|
|
7310
7600
|
result.inclusionMode = inclusionMode;
|
|
7311
7601
|
}
|
|
7312
|
-
result.layer = classifyLayer(
|
|
7313
|
-
result.kind = classifyKind(
|
|
7314
|
-
result.language = detectLanguage(
|
|
7315
|
-
const layerRule = findRuleMatch(config.layers,
|
|
7602
|
+
result.layer = classifyLayer(relative15, config.layers);
|
|
7603
|
+
result.kind = classifyKind(relative15, config.kinds);
|
|
7604
|
+
result.language = detectLanguage(relative15);
|
|
7605
|
+
const layerRule = findRuleMatch(config.layers, relative15);
|
|
7316
7606
|
if (layerRule) result.layerMatch = describeMatcher(layerRule.match);
|
|
7317
|
-
const kindRule = findRuleMatch(config.kinds,
|
|
7607
|
+
const kindRule = findRuleMatch(config.kinds, relative15);
|
|
7318
7608
|
if (kindRule) result.kindMatch = describeMatcher(kindRule.match);
|
|
7319
7609
|
const manifest = readManifest2(config);
|
|
7320
|
-
const entry = Array.isArray(manifest?.files) ? manifest.files.find((file) => file.relativePath ===
|
|
7610
|
+
const entry = Array.isArray(manifest?.files) ? manifest.files.find((file) => file.relativePath === relative15) : void 0;
|
|
7321
7611
|
result.part = entry?.part ?? null;
|
|
7322
7612
|
return result;
|
|
7323
7613
|
}
|
|
@@ -7355,178 +7645,6 @@ function renderExplainText(result) {
|
|
|
7355
7645
|
);
|
|
7356
7646
|
return lines.join("\n");
|
|
7357
7647
|
}
|
|
7358
|
-
|
|
7359
|
-
// src/ast/structured.ts
|
|
7360
|
-
function stripJsonComments2(content) {
|
|
7361
|
-
const text2 = content.replace(/^\uFEFF/, "");
|
|
7362
|
-
const withoutComments = stripComments(text2);
|
|
7363
|
-
return stripTrailingCommas2(withoutComments);
|
|
7364
|
-
}
|
|
7365
|
-
function stripComments(text2) {
|
|
7366
|
-
let out = "";
|
|
7367
|
-
let inString = false;
|
|
7368
|
-
let escaped = false;
|
|
7369
|
-
for (let index = 0; index < text2.length; index += 1) {
|
|
7370
|
-
const char = text2[index];
|
|
7371
|
-
if (inString) {
|
|
7372
|
-
out += char;
|
|
7373
|
-
if (escaped) escaped = false;
|
|
7374
|
-
else if (char === "\\") escaped = true;
|
|
7375
|
-
else if (char === '"') inString = false;
|
|
7376
|
-
continue;
|
|
7377
|
-
}
|
|
7378
|
-
if (char === '"') {
|
|
7379
|
-
inString = true;
|
|
7380
|
-
out += char;
|
|
7381
|
-
continue;
|
|
7382
|
-
}
|
|
7383
|
-
if (char === "/" && text2[index + 1] === "/") {
|
|
7384
|
-
while (index < text2.length && text2[index] !== "\n" && text2[index] !== "\r") index += 1;
|
|
7385
|
-
index -= 1;
|
|
7386
|
-
continue;
|
|
7387
|
-
}
|
|
7388
|
-
if (char === "/" && text2[index + 1] === "*") {
|
|
7389
|
-
index += 2;
|
|
7390
|
-
while (index < text2.length && !(text2[index] === "*" && text2[index + 1] === "/")) {
|
|
7391
|
-
if (text2[index] === "\n" || text2[index] === "\r") out += text2[index];
|
|
7392
|
-
index += 1;
|
|
7393
|
-
}
|
|
7394
|
-
index += 1;
|
|
7395
|
-
continue;
|
|
7396
|
-
}
|
|
7397
|
-
out += char;
|
|
7398
|
-
}
|
|
7399
|
-
return out;
|
|
7400
|
-
}
|
|
7401
|
-
function stripTrailingCommas2(text2) {
|
|
7402
|
-
let out = "";
|
|
7403
|
-
let inString = false;
|
|
7404
|
-
let escaped = false;
|
|
7405
|
-
for (let index = 0; index < text2.length; index += 1) {
|
|
7406
|
-
const char = text2[index];
|
|
7407
|
-
if (inString) {
|
|
7408
|
-
out += char;
|
|
7409
|
-
if (escaped) escaped = false;
|
|
7410
|
-
else if (char === "\\") escaped = true;
|
|
7411
|
-
else if (char === '"') inString = false;
|
|
7412
|
-
continue;
|
|
7413
|
-
}
|
|
7414
|
-
if (char === '"') {
|
|
7415
|
-
inString = true;
|
|
7416
|
-
out += char;
|
|
7417
|
-
continue;
|
|
7418
|
-
}
|
|
7419
|
-
if (char === ",") {
|
|
7420
|
-
let next = index + 1;
|
|
7421
|
-
while (next < text2.length && /\s/.test(text2[next])) next += 1;
|
|
7422
|
-
if (text2[next] === "}" || text2[next] === "]") continue;
|
|
7423
|
-
}
|
|
7424
|
-
out += char;
|
|
7425
|
-
}
|
|
7426
|
-
return out;
|
|
7427
|
-
}
|
|
7428
|
-
function summarizeJson(content) {
|
|
7429
|
-
try {
|
|
7430
|
-
const parsed = JSON.parse(stripJsonComments2(content));
|
|
7431
|
-
if (Array.isArray(parsed)) {
|
|
7432
|
-
const sample = parsed[0];
|
|
7433
|
-
const sampleKeys = sample && typeof sample === "object" && !Array.isArray(sample) ? Object.keys(sample).slice(0, 10).sort() : [];
|
|
7434
|
-
return {
|
|
7435
|
-
shape: "array",
|
|
7436
|
-
itemCount: parsed.length,
|
|
7437
|
-
keys: [],
|
|
7438
|
-
sampleKeys
|
|
7439
|
-
};
|
|
7440
|
-
}
|
|
7441
|
-
if (parsed && typeof parsed === "object") {
|
|
7442
|
-
const keys = Object.keys(parsed).sort();
|
|
7443
|
-
return {
|
|
7444
|
-
shape: "object",
|
|
7445
|
-
itemCount: keys.length,
|
|
7446
|
-
keys: keys.slice(0, 30),
|
|
7447
|
-
sampleKeys: []
|
|
7448
|
-
};
|
|
7449
|
-
}
|
|
7450
|
-
return {
|
|
7451
|
-
shape: typeof parsed,
|
|
7452
|
-
itemCount: null,
|
|
7453
|
-
keys: [],
|
|
7454
|
-
sampleKeys: []
|
|
7455
|
-
};
|
|
7456
|
-
} catch {
|
|
7457
|
-
return {
|
|
7458
|
-
shape: "invalid-json",
|
|
7459
|
-
itemCount: null,
|
|
7460
|
-
keys: [],
|
|
7461
|
-
sampleKeys: []
|
|
7462
|
-
};
|
|
7463
|
-
}
|
|
7464
|
-
}
|
|
7465
|
-
function frontMatterEnd(lines) {
|
|
7466
|
-
if (lines.length < 3 || lines[0].trim() !== "---") return 0;
|
|
7467
|
-
for (let index = 1; index < lines.length; index += 1) {
|
|
7468
|
-
const line = lines[index];
|
|
7469
|
-
const candidate = line.trim();
|
|
7470
|
-
if (candidate === "---" || candidate === "...") {
|
|
7471
|
-
return index > 1 ? index : 0;
|
|
7472
|
-
}
|
|
7473
|
-
if (candidate === "") continue;
|
|
7474
|
-
if (/^#(\s|$)/.test(candidate)) continue;
|
|
7475
|
-
if (/^(`{3,}|~{3,})/.test(candidate)) return 0;
|
|
7476
|
-
if (/^#{1,6}\s+\S/.test(candidate)) return 0;
|
|
7477
|
-
const isYamlMapping = /^[A-Za-z0-9_.-]+\s*:(\s|$)/.test(candidate);
|
|
7478
|
-
const isListItem = /^-(?:(\s|$))/.test(candidate);
|
|
7479
|
-
const isIndented = /^[ \t]/.test(line);
|
|
7480
|
-
if (!isYamlMapping && !isListItem && !isIndented) return 0;
|
|
7481
|
-
}
|
|
7482
|
-
return 0;
|
|
7483
|
-
}
|
|
7484
|
-
function summarizeMarkdown(content) {
|
|
7485
|
-
const headings = [];
|
|
7486
|
-
const frontmatterKeys = [];
|
|
7487
|
-
const lines = content.replace(/^\uFEFF/, "").split(/\r\n|\n|\r/);
|
|
7488
|
-
let inFrontmatter = false;
|
|
7489
|
-
let fence = null;
|
|
7490
|
-
const frontMatterEndLine = frontMatterEnd(lines);
|
|
7491
|
-
for (let index = 0; index < lines.length; index++) {
|
|
7492
|
-
const line = lines[index];
|
|
7493
|
-
if (index === 0 && frontMatterEndLine > 0) {
|
|
7494
|
-
inFrontmatter = true;
|
|
7495
|
-
continue;
|
|
7496
|
-
}
|
|
7497
|
-
if (inFrontmatter) {
|
|
7498
|
-
const trimmedFrontmatter = line.trim();
|
|
7499
|
-
if (trimmedFrontmatter === "---" || trimmedFrontmatter === "...") {
|
|
7500
|
-
inFrontmatter = false;
|
|
7501
|
-
continue;
|
|
7502
|
-
}
|
|
7503
|
-
const match = /^([A-Za-z0-9_.-]+)\s*:/.exec(line);
|
|
7504
|
-
if (match) frontmatterKeys.push(match[1]);
|
|
7505
|
-
continue;
|
|
7506
|
-
}
|
|
7507
|
-
const trimmed = line.trim();
|
|
7508
|
-
const fenceMatch = /^(`{3,}|~{3,})(.*)$/.exec(trimmed);
|
|
7509
|
-
if (fenceMatch) {
|
|
7510
|
-
const run = fenceMatch[1];
|
|
7511
|
-
const rest = fenceMatch[2].trim();
|
|
7512
|
-
if (fence === null) {
|
|
7513
|
-
fence = { marker: run[0], length: run.length };
|
|
7514
|
-
} else if (run[0] === fence.marker && run.length >= fence.length && rest === "") {
|
|
7515
|
-
fence = null;
|
|
7516
|
-
}
|
|
7517
|
-
continue;
|
|
7518
|
-
}
|
|
7519
|
-
if (fence !== null) continue;
|
|
7520
|
-
const headingMatch = /^(#{1,6})\s+(.+)$/.exec(trimmed);
|
|
7521
|
-
if (headingMatch) {
|
|
7522
|
-
headings.push(`${headingMatch[1]} ${headingMatch[2].trim()}`);
|
|
7523
|
-
}
|
|
7524
|
-
}
|
|
7525
|
-
return {
|
|
7526
|
-
headings: headings.slice(0, 40),
|
|
7527
|
-
frontmatterKeys: Array.from(new Set(frontmatterKeys)).sort()
|
|
7528
|
-
};
|
|
7529
|
-
}
|
|
7530
7648
|
function decodeGitignore(buffer) {
|
|
7531
7649
|
const startsWith = (...bytes) => buffer.length >= bytes.length && bytes.every((byte, index) => buffer[index] === byte);
|
|
7532
7650
|
if (startsWith(239, 187, 191)) {
|
|
@@ -7736,6 +7854,10 @@ function renderConfig(answers) {
|
|
|
7736
7854
|
// Set true to drop the built-in rules above and keep only customPatterns.
|
|
7737
7855
|
disableDefaultPatterns: false,
|
|
7738
7856
|
},
|
|
7857
|
+
// The library spelling of the same list, accepted here too so a config file can
|
|
7858
|
+
// express what a caller passes in code: an array of { rule, pattern } or a bare
|
|
7859
|
+
// RegExp. Use \`secrets.customPatterns\` above unless you are porting code.
|
|
7860
|
+
// secretRules: [],
|
|
7739
7861
|
|
|
7740
7862
|
// \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
|
|
7741
7863
|
artifacts: {
|
|
@@ -7923,7 +8045,7 @@ function keyReader(input) {
|
|
|
7923
8045
|
next() {
|
|
7924
8046
|
const queued = queue.shift();
|
|
7925
8047
|
if (queued) return Promise.resolve(queued);
|
|
7926
|
-
return new Promise((
|
|
8048
|
+
return new Promise((resolve12) => waiters.push(resolve12));
|
|
7927
8049
|
},
|
|
7928
8050
|
close() {
|
|
7929
8051
|
input.off("keypress", onKey);
|
|
@@ -8141,7 +8263,7 @@ var CONFIG_CANDIDATES = [
|
|
|
8141
8263
|
".snapshotrc"
|
|
8142
8264
|
];
|
|
8143
8265
|
function parsePackageJson(raw) {
|
|
8144
|
-
const parsed = JSON.parse(
|
|
8266
|
+
const parsed = JSON.parse(stripJsonComments(raw));
|
|
8145
8267
|
if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) {
|
|
8146
8268
|
throw new Error("package.json is not a JSON object");
|
|
8147
8269
|
}
|
|
@@ -8352,7 +8474,18 @@ function updatePackageJson(cwd, notes) {
|
|
|
8352
8474
|
writeFileOrExplain(packagePath, serializePackageJson(raw, parsed));
|
|
8353
8475
|
return { scripts: added, dependency };
|
|
8354
8476
|
}
|
|
8355
|
-
|
|
8477
|
+
function gitignoreEntriesFor(cwd, outDir, tmpDir) {
|
|
8478
|
+
const entries = [];
|
|
8479
|
+
for (const directory of [outDir, tmpDir]) {
|
|
8480
|
+
if (directory === null) continue;
|
|
8481
|
+
const relative15 = path16__namespace.relative(cwd, path16__namespace.resolve(cwd, directory)).replace(/\\/g, "/");
|
|
8482
|
+
if (relative15 === "" || relative15 === "." || relative15.startsWith("..") || path16__namespace.isAbsolute(relative15)) {
|
|
8483
|
+
continue;
|
|
8484
|
+
}
|
|
8485
|
+
entries.push(`/${relative15}/`);
|
|
8486
|
+
}
|
|
8487
|
+
return [...new Set(entries)];
|
|
8488
|
+
}
|
|
8356
8489
|
function resolvePresetChoice(detectedName, presetName) {
|
|
8357
8490
|
return {
|
|
8358
8491
|
value: presetName,
|
|
@@ -8645,7 +8778,10 @@ async function runInit(options) {
|
|
|
8645
8778
|
}
|
|
8646
8779
|
if (!reused) writeFileOrExplain(configPath, configText);
|
|
8647
8780
|
const { scripts, dependency } = updatePackageJson(options.cwd, notes);
|
|
8648
|
-
const ignore = appendGitignoreEntries(
|
|
8781
|
+
const ignore = appendGitignoreEntries(
|
|
8782
|
+
options.cwd,
|
|
8783
|
+
gitignoreEntriesFor(options.cwd, answers.outDir, options.tmpDir ?? (reused ? null : "snapshot.tmp"))
|
|
8784
|
+
);
|
|
8649
8785
|
if (ignore.note !== null) notes.push(ignore.note);
|
|
8650
8786
|
return {
|
|
8651
8787
|
configPath,
|
|
@@ -8663,10 +8799,10 @@ async function runInit(options) {
|
|
|
8663
8799
|
};
|
|
8664
8800
|
}
|
|
8665
8801
|
function describeTarget(cwd) {
|
|
8666
|
-
const
|
|
8667
|
-
if (
|
|
8668
|
-
if (
|
|
8669
|
-
return
|
|
8802
|
+
const relative15 = path16__namespace.relative(process.cwd(), cwd);
|
|
8803
|
+
if (relative15 === "") return "this directory";
|
|
8804
|
+
if (relative15.startsWith("..") || path16__namespace.isAbsolute(relative15)) return cwd;
|
|
8805
|
+
return relative15;
|
|
8670
8806
|
}
|
|
8671
8807
|
function firstRunMessage(reason, cwd) {
|
|
8672
8808
|
const where = describeTarget(cwd);
|
|
@@ -8861,7 +8997,7 @@ function generateAuditReport(manifest, secretFindings, secretRules) {
|
|
|
8861
8997
|
);
|
|
8862
8998
|
for (const file of affected) {
|
|
8863
8999
|
const status = file.isPreviewTruncated ? "Truncated" : "Full";
|
|
8864
|
-
const cutBy = file.truncationReason === "part-budget" ? "maxPartBytes" : "largeFileBytes";
|
|
9000
|
+
const cutBy = file.truncationReason === "part-budget" ? "part budget (maxPartBytes)" : "large-file budget (largeFileBytes)";
|
|
8865
9001
|
lines.push(
|
|
8866
9002
|
`| ${code(file.relativePath)} | ${file.sizeBytes} | ${file.lines} | ${file.includedBytes} | ${file.includedLines} | ${status} | ${cutBy} |`
|
|
8867
9003
|
);
|
|
@@ -8974,11 +9110,11 @@ function generateSarifReport(manifest, findings, rules, toolVersion) {
|
|
|
8974
9110
|
codebaseSnapshotFinding: `${findingPath}#L${line}#${finding.rules.join("+")}`
|
|
8975
9111
|
}
|
|
8976
9112
|
};
|
|
8977
|
-
}).sort(
|
|
8978
|
-
|
|
8979
|
-
|
|
8980
|
-
) || a.locations[0].physicalLocation.region.startLine - b.locations[0].physicalLocation.region.startLine
|
|
8981
|
-
);
|
|
9113
|
+
}).sort((a, b) => {
|
|
9114
|
+
const left = a.locations[0].physicalLocation.artifactLocation.uri;
|
|
9115
|
+
const right = b.locations[0].physicalLocation.artifactLocation.uri;
|
|
9116
|
+
return (left < right ? -1 : left > right ? 1 : 0) || a.locations[0].physicalLocation.region.startLine - b.locations[0].physicalLocation.region.startLine;
|
|
9117
|
+
});
|
|
8982
9118
|
const log = {
|
|
8983
9119
|
$schema: SARIF_SCHEMA,
|
|
8984
9120
|
version: SARIF_VERSION,
|
|
@@ -9007,6 +9143,7 @@ function generateSarifReport(manifest, findings, rules, toolVersion) {
|
|
|
9007
9143
|
}
|
|
9008
9144
|
var HEADER_RESERVE_BYTES = 2048 + Buffer.byteLength(UNTRUSTED_CONTENT_NOTICE, "utf8") + 8;
|
|
9009
9145
|
var MIN_SECTION_BUDGET_BYTES = 512;
|
|
9146
|
+
var MIN_PART_BUDGET_BYTES = MIN_SECTION_BUDGET_BYTES + HEADER_RESERVE_BYTES;
|
|
9010
9147
|
var MAX_SPLIT_PASSES = 64;
|
|
9011
9148
|
var BUDGET_MARKER_RESERVE = 96;
|
|
9012
9149
|
function insertTokenLine(markdown, tokens) {
|
|
@@ -9045,10 +9182,17 @@ function partitionFilesForBuckets(buckets, contentFingerprint) {
|
|
|
9045
9182
|
const groups = [];
|
|
9046
9183
|
for (const bucket of buckets) {
|
|
9047
9184
|
if (bucket.files.length === 0) continue;
|
|
9048
|
-
|
|
9049
|
-
|
|
9050
|
-
|
|
9051
|
-
|
|
9185
|
+
if (!Number.isFinite(bucket.budgetBytes)) {
|
|
9186
|
+
throw new Error(
|
|
9187
|
+
`A part budget must be a finite number of bytes; received ${String(bucket.budgetBytes)}.`
|
|
9188
|
+
);
|
|
9189
|
+
}
|
|
9190
|
+
if (bucket.budgetBytes < MIN_PART_BUDGET_BYTES) {
|
|
9191
|
+
throw new Error(
|
|
9192
|
+
`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.`
|
|
9193
|
+
);
|
|
9194
|
+
}
|
|
9195
|
+
const budget = bucket.budgetBytes;
|
|
9052
9196
|
const sectionBudget = budget - HEADER_RESERVE_BYTES;
|
|
9053
9197
|
const prepared = bucket.files.map((file) => prepareSection(file, sectionBudget, budget));
|
|
9054
9198
|
for (const sections of greedyGroups(prepared, budget)) groups.push({ sections, budget });
|
|
@@ -9677,6 +9821,22 @@ function generateProjectTree(filePaths) {
|
|
|
9677
9821
|
const fence = fenceForText(lines.join("\n"), 3);
|
|
9678
9822
|
return ["# Project Tree", "", `${fence}text`, ...lines, fence, ""].join("\n");
|
|
9679
9823
|
}
|
|
9824
|
+
function treeTruncationWarnings(treeText) {
|
|
9825
|
+
const warnings = [];
|
|
9826
|
+
const depth = /\[tree truncated at (\d+) levels\]/.exec(treeText);
|
|
9827
|
+
if (depth) {
|
|
9828
|
+
warnings.push(
|
|
9829
|
+
`reports/project-tree.md was truncated at the ${depth[1]}-level depth cap: deeper directories are not listed there.`
|
|
9830
|
+
);
|
|
9831
|
+
}
|
|
9832
|
+
const lines = /\[tree truncated at (\d+) lines\]/.exec(treeText);
|
|
9833
|
+
if (lines) {
|
|
9834
|
+
warnings.push(
|
|
9835
|
+
`reports/project-tree.md was truncated at the ${lines[1]}-line cap: the rest of the tree is not listed there.`
|
|
9836
|
+
);
|
|
9837
|
+
}
|
|
9838
|
+
return warnings;
|
|
9839
|
+
}
|
|
9680
9840
|
var PACKAGE_LATEST_URL = "https://registry.npmjs.org/codebase-snapshot/latest";
|
|
9681
9841
|
var CHECK_INTERVAL_MS = 24 * 60 * 60 * 1e3;
|
|
9682
9842
|
var UP_TO_DATE_INTERVAL_MS = 60 * 60 * 1e3;
|
|
@@ -9789,14 +9949,14 @@ function writeCache(file, entry) {
|
|
|
9789
9949
|
}
|
|
9790
9950
|
}
|
|
9791
9951
|
function fetchLatestVersion(url = PACKAGE_LATEST_URL, timeoutMs = REQUEST_TIMEOUT_MS) {
|
|
9792
|
-
return new Promise((
|
|
9952
|
+
return new Promise((resolve12) => {
|
|
9793
9953
|
let settled = false;
|
|
9794
9954
|
let request = null;
|
|
9795
9955
|
const finish = (value) => {
|
|
9796
9956
|
if (settled) return;
|
|
9797
9957
|
settled = true;
|
|
9798
9958
|
clearTimeout(deadline);
|
|
9799
|
-
|
|
9959
|
+
resolve12(value);
|
|
9800
9960
|
};
|
|
9801
9961
|
const deadline = setTimeout(() => {
|
|
9802
9962
|
request?.destroy();
|
|
@@ -9937,8 +10097,8 @@ function gitDirectory(cwd) {
|
|
|
9937
10097
|
}
|
|
9938
10098
|
}
|
|
9939
10099
|
function isInside2(parent, child) {
|
|
9940
|
-
const
|
|
9941
|
-
return
|
|
10100
|
+
const relative15 = path16__namespace.relative(parent, child);
|
|
10101
|
+
return relative15 === "" || !relative15.startsWith("..") && !path16__namespace.isAbsolute(relative15);
|
|
9942
10102
|
}
|
|
9943
10103
|
function isRegisteredWorktree(gitDir, cwd) {
|
|
9944
10104
|
try {
|
|
@@ -10052,7 +10212,20 @@ const { parentPort, workerData } = require("node:worker_threads");
|
|
|
10052
10212
|
// so the run is the documented MCP run rather than the CLI run with one setting removed.
|
|
10053
10213
|
const base = loaded.config ? { ...loaded.config, hooks: {} } : null;
|
|
10054
10214
|
const config = mod.resolveConfig(base, workerData.cliOptions, workerData.cwd);
|
|
10055
|
-
const manifest = mod.generateSnapshot(config);
|
|
10215
|
+
const manifest = mod.generateSnapshot(config, { dryRun: workerData.dryRun === true });
|
|
10216
|
+
const skipCounts = new Map();
|
|
10217
|
+
for (const record of manifest.skipped) {
|
|
10218
|
+
skipCounts.set(record.reason, (skipCounts.get(record.reason) || 0) + 1);
|
|
10219
|
+
}
|
|
10220
|
+
const skipReasons = Array.from(skipCounts.entries())
|
|
10221
|
+
.sort(function (a, b) {
|
|
10222
|
+
if (b[1] !== a[1]) return b[1] - a[1];
|
|
10223
|
+
return a[0] < b[0] ? -1 : a[0] > b[0] ? 1 : 0;
|
|
10224
|
+
})
|
|
10225
|
+
.slice(0, 8)
|
|
10226
|
+
.map(function (entry) {
|
|
10227
|
+
return { reason: entry[0], count: entry[1] };
|
|
10228
|
+
});
|
|
10056
10229
|
parentPort.postMessage({
|
|
10057
10230
|
ok: true,
|
|
10058
10231
|
summary: {
|
|
@@ -10061,7 +10234,11 @@ const { parentPort, workerData } = require("node:worker_threads");
|
|
|
10061
10234
|
skippedCount: manifest.counts.skippedCount,
|
|
10062
10235
|
partsCount: manifest.counts.partsCount,
|
|
10063
10236
|
parts: manifest.parts.map((part) => ({ filename: part.filename, byteSize: part.byteSize })),
|
|
10237
|
+
totalSizeBytes: manifest.counts.totalSizeBytes,
|
|
10064
10238
|
totalContentBytes: manifest.totals.totalContentBytes,
|
|
10239
|
+
preset: manifest.config.preset,
|
|
10240
|
+
layers: manifest.layers,
|
|
10241
|
+
skipReasons: skipReasons,
|
|
10065
10242
|
warnings: manifest.warnings,
|
|
10066
10243
|
},
|
|
10067
10244
|
});
|
|
@@ -10073,15 +10250,15 @@ const { parentPort, workerData } = require("node:worker_threads");
|
|
|
10073
10250
|
}
|
|
10074
10251
|
})();
|
|
10075
10252
|
`;
|
|
10076
|
-
function generateInWorker(cwd, cliOptions) {
|
|
10077
|
-
return new Promise((
|
|
10253
|
+
function generateInWorker(cwd, cliOptions, options = {}) {
|
|
10254
|
+
return new Promise((resolve12) => {
|
|
10078
10255
|
let settled = false;
|
|
10079
10256
|
let worker = null;
|
|
10080
10257
|
const finish = (result) => {
|
|
10081
10258
|
if (settled) return;
|
|
10082
10259
|
settled = true;
|
|
10083
10260
|
if (worker !== null) void worker.terminate();
|
|
10084
|
-
|
|
10261
|
+
resolve12(result);
|
|
10085
10262
|
};
|
|
10086
10263
|
const isCjs = typeof __dirname !== "undefined";
|
|
10087
10264
|
const directory = isCjs ? __dirname : path16__namespace.dirname(url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('cli.cjs', document.baseURI).href))));
|
|
@@ -10091,7 +10268,8 @@ function generateInWorker(cwd, cliOptions) {
|
|
|
10091
10268
|
workerData: {
|
|
10092
10269
|
entryUrl: workerEntry(directory, isCjs).url,
|
|
10093
10270
|
cwd,
|
|
10094
|
-
cliOptions
|
|
10271
|
+
cliOptions,
|
|
10272
|
+
dryRun: options.dryRun === true
|
|
10095
10273
|
}
|
|
10096
10274
|
});
|
|
10097
10275
|
} catch (error) {
|
|
@@ -10276,16 +10454,29 @@ function retain(items, keep) {
|
|
|
10276
10454
|
}
|
|
10277
10455
|
items.length = write;
|
|
10278
10456
|
}
|
|
10279
|
-
function buildIndexes(files, tsconfigPaths) {
|
|
10457
|
+
function buildIndexes(files, tsconfigPaths, skippedSummaryImports = /* @__PURE__ */ new Map()) {
|
|
10280
10458
|
const resolver = buildImportResolver(files, { tsconfig: tsconfigPaths });
|
|
10281
10459
|
const importerCounts = /* @__PURE__ */ new Map();
|
|
10282
|
-
const byFile = files.
|
|
10283
|
-
|
|
10284
|
-
|
|
10285
|
-
|
|
10286
|
-
|
|
10287
|
-
|
|
10288
|
-
|
|
10460
|
+
const byFile = files.flatMap((file) => {
|
|
10461
|
+
if (isSourceSummary(file.summary)) {
|
|
10462
|
+
return [
|
|
10463
|
+
{
|
|
10464
|
+
path: file.relativePath,
|
|
10465
|
+
imports: file.summary.imports,
|
|
10466
|
+
exports: file.summary.exports
|
|
10467
|
+
}
|
|
10468
|
+
];
|
|
10469
|
+
}
|
|
10470
|
+
const imports = skippedSummaryImports.get(file.relativePath);
|
|
10471
|
+
if (imports === void 0) return [];
|
|
10472
|
+
return [
|
|
10473
|
+
{
|
|
10474
|
+
path: file.relativePath,
|
|
10475
|
+
imports,
|
|
10476
|
+
exports: [],
|
|
10477
|
+
exportsOmitted: true
|
|
10478
|
+
}
|
|
10479
|
+
];
|
|
10289
10480
|
});
|
|
10290
10481
|
for (const entry of byFile) {
|
|
10291
10482
|
for (const specifier of entry.imports) {
|
|
@@ -10405,6 +10596,9 @@ function resolveSafeOutputDirs(config) {
|
|
|
10405
10596
|
return { outDir, tmpDir };
|
|
10406
10597
|
}
|
|
10407
10598
|
var IGNORABLE_ENTRIES = /* @__PURE__ */ new Set([".DS_Store"]);
|
|
10599
|
+
function isIgnorableEntry(entry) {
|
|
10600
|
+
return IGNORABLE_ENTRIES.has(entry.slice(entry.lastIndexOf("/") + 1));
|
|
10601
|
+
}
|
|
10408
10602
|
var RUN_DIR_PREFIX = "run-";
|
|
10409
10603
|
var STALE_RUN_MS = 60 * 60 * 1e3;
|
|
10410
10604
|
function maskSummaryStrings(value, secretRules) {
|
|
@@ -10447,9 +10641,9 @@ function listEntries(dir) {
|
|
|
10447
10641
|
return;
|
|
10448
10642
|
}
|
|
10449
10643
|
for (const child of children) {
|
|
10450
|
-
const
|
|
10451
|
-
entries.push(
|
|
10452
|
-
if (child.isDirectory()) walk(path16__namespace.join(absolute, child.name),
|
|
10644
|
+
const relative15 = prefix === "" ? child.name : `${prefix}/${child.name}`;
|
|
10645
|
+
entries.push(relative15);
|
|
10646
|
+
if (child.isDirectory()) walk(path16__namespace.join(absolute, child.name), relative15);
|
|
10453
10647
|
}
|
|
10454
10648
|
};
|
|
10455
10649
|
walk(dir, "");
|
|
@@ -10460,7 +10654,7 @@ function markerInventory(dir, written) {
|
|
|
10460
10654
|
const files = [];
|
|
10461
10655
|
for (const entry of entries) {
|
|
10462
10656
|
if (entry === OWNERSHIP_MARKER) continue;
|
|
10463
|
-
if (
|
|
10657
|
+
if (isIgnorableEntry(entry)) continue;
|
|
10464
10658
|
const full = path16__namespace.join(dir, ...entry.split("/"));
|
|
10465
10659
|
let stats;
|
|
10466
10660
|
try {
|
|
@@ -10749,7 +10943,7 @@ function assessSnapshotDirectory(dir) {
|
|
|
10749
10943
|
}
|
|
10750
10944
|
const entries = listEntries(dir);
|
|
10751
10945
|
const foreignEntries = entries.filter(
|
|
10752
|
-
(entry) => !recorded.has(entry) && !
|
|
10946
|
+
(entry) => !recorded.has(entry) && !isIgnorableEntry(entry)
|
|
10753
10947
|
);
|
|
10754
10948
|
if (foreignEntries.length > 0) {
|
|
10755
10949
|
return { owned: false, problem: null, foreignEntries, marker: marker2 };
|
|
@@ -11245,7 +11439,7 @@ function generateSnapshot(configInput, options) {
|
|
|
11245
11439
|
// output — but only at these exact paths, not at every directory that shares the name.
|
|
11246
11440
|
toolOwnedPaths: [config.outDir, config.tmpDir].map(
|
|
11247
11441
|
(directory) => path16__namespace.relative(config.cwd, path16__namespace.resolve(config.cwd, directory)).replace(/\\/g, "/")
|
|
11248
|
-
).filter((
|
|
11442
|
+
).filter((relative15) => relative15.length > 0 && !relative15.startsWith("..")),
|
|
11249
11443
|
// A staged path can be absent from the working tree while its index blob exists. Discovery
|
|
11250
11444
|
// lists the working tree, so those paths would never reach the scan at all.
|
|
11251
11445
|
...stagedPaths.size > 0 ? { extraPaths: [...stagedPaths] } : {}
|
|
@@ -11665,7 +11859,7 @@ function generateSnapshot(configInput, options) {
|
|
|
11665
11859
|
},
|
|
11666
11860
|
layers: layerCounts,
|
|
11667
11861
|
kinds: kindCounts,
|
|
11668
|
-
indexes: buildIndexes(files, tsconfigPathsFor(config.cwd)),
|
|
11862
|
+
indexes: buildIndexes(files, tsconfigPathsFor(config.cwd), skippedSummaryImports),
|
|
11669
11863
|
parts: parts.map((part) => part.metadata),
|
|
11670
11864
|
files: files.map((file) => {
|
|
11671
11865
|
const { content: _content, ...rest } = file;
|
|
@@ -11707,11 +11901,9 @@ function generateSnapshot(configInput, options) {
|
|
|
11707
11901
|
let projectTree = null;
|
|
11708
11902
|
if (config.artifacts.projectTree) {
|
|
11709
11903
|
projectTree = generateProjectTree(files.map((file) => file.relativePath));
|
|
11710
|
-
const
|
|
11711
|
-
if (
|
|
11712
|
-
manifest.warnings.push(
|
|
11713
|
-
`reports/project-tree.md was truncated at the ${depthMarker[1]}-level depth cap: deeper directories are not listed there.`
|
|
11714
|
-
);
|
|
11904
|
+
const truncations = treeTruncationWarnings(projectTree);
|
|
11905
|
+
if (truncations.length > 0) {
|
|
11906
|
+
manifest.warnings.push(...truncations);
|
|
11715
11907
|
manifest.totals.warningCount = manifest.warnings.length;
|
|
11716
11908
|
}
|
|
11717
11909
|
}
|
|
@@ -11739,7 +11931,7 @@ function generateSnapshot(configInput, options) {
|
|
|
11739
11931
|
if (config.includeMonolith) {
|
|
11740
11932
|
const fullFiles = files.map((file) => {
|
|
11741
11933
|
const content = fullContents.get(file.relativePath) ?? "";
|
|
11742
|
-
|
|
11934
|
+
const entry = {
|
|
11743
11935
|
...file,
|
|
11744
11936
|
content,
|
|
11745
11937
|
inclusionMode: "full",
|
|
@@ -11747,6 +11939,9 @@ function generateSnapshot(configInput, options) {
|
|
|
11747
11939
|
includedBytes: Buffer.byteLength(content, "utf8"),
|
|
11748
11940
|
includedLines: countLines(content)
|
|
11749
11941
|
};
|
|
11942
|
+
delete entry.truncationReason;
|
|
11943
|
+
delete entry.omittedRanges;
|
|
11944
|
+
return entry;
|
|
11750
11945
|
});
|
|
11751
11946
|
const bodyBytes = fullFiles.reduce((total, file) => total + file.includedBytes, 0);
|
|
11752
11947
|
const definitelyTooLarge = config.maxMonolithBytes !== null && bodyBytes > config.maxMonolithBytes;
|
|
@@ -12174,8 +12369,8 @@ function partPathFor(workspace, filename) {
|
|
|
12174
12369
|
if (filename.length === 0 || filename.includes("\0")) return null;
|
|
12175
12370
|
const partsDir = path16__namespace.resolve(workspace.root, workspace.config.outDir, "parts");
|
|
12176
12371
|
const resolved = path16__namespace.resolve(partsDir, filename);
|
|
12177
|
-
const
|
|
12178
|
-
if (
|
|
12372
|
+
const relative15 = path16__namespace.relative(partsDir, resolved);
|
|
12373
|
+
if (relative15.length === 0 || relative15.includes(path16__namespace.sep) || relative15.includes("/") || relative15.includes("\\") || path16__namespace.isAbsolute(relative15)) {
|
|
12179
12374
|
return null;
|
|
12180
12375
|
}
|
|
12181
12376
|
let stats;
|
|
@@ -12344,11 +12539,11 @@ function toRelativePath(root, value) {
|
|
|
12344
12539
|
if (cleaned.length === 0 || cleaned.includes("\0")) return null;
|
|
12345
12540
|
const resolvedRoot = path16__namespace.resolve(root);
|
|
12346
12541
|
const absolute = path16__namespace.resolve(resolvedRoot, cleaned);
|
|
12347
|
-
const
|
|
12348
|
-
if (
|
|
12542
|
+
const relative15 = path16__namespace.relative(resolvedRoot, absolute);
|
|
12543
|
+
if (relative15 === "" || relative15 === ".." || relative15.startsWith(`..${path16__namespace.sep}`) || path16__namespace.isAbsolute(relative15)) {
|
|
12349
12544
|
return null;
|
|
12350
12545
|
}
|
|
12351
|
-
return
|
|
12546
|
+
return relative15.split(path16__namespace.sep).join("/");
|
|
12352
12547
|
}
|
|
12353
12548
|
function symbolsOf(entry) {
|
|
12354
12549
|
const summary = entry.summary;
|
|
@@ -12506,45 +12701,38 @@ var planTool = {
|
|
|
12506
12701
|
const prepared = await prepare(args, context, workspaceOverrides(args));
|
|
12507
12702
|
if (!prepared.ok) return prepared.outcome;
|
|
12508
12703
|
const workspace = prepared.workspace;
|
|
12509
|
-
|
|
12510
|
-
|
|
12511
|
-
|
|
12512
|
-
|
|
12513
|
-
return failure(error instanceof Error ? error.message : String(error));
|
|
12514
|
-
}
|
|
12515
|
-
const reasons = /* @__PURE__ */ new Map();
|
|
12516
|
-
for (const record of manifest.skipped) {
|
|
12517
|
-
reasons.set(record.reason, (reasons.get(record.reason) ?? 0) + 1);
|
|
12518
|
-
}
|
|
12519
|
-
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 }));
|
|
12704
|
+
const result = await generateInWorker(workspace.root, workspace.cliOptions, { dryRun: true });
|
|
12705
|
+
if (!result.ok) return failure(result.message);
|
|
12706
|
+
const summary = result.summary;
|
|
12707
|
+
const topReasons = summary.skipReasons;
|
|
12520
12708
|
const lines = [
|
|
12521
12709
|
"Dry run \u2014 nothing was written.",
|
|
12522
|
-
`Preset: ${
|
|
12523
|
-
`Would include ${plural(
|
|
12524
|
-
`Would skip ${plural(
|
|
12710
|
+
`Preset: ${summary.preset}`,
|
|
12711
|
+
`Would include ${plural(summary.totalFiles, "file")} in ${plural(summary.partsCount, "part")} (${formatBytes(summary.totalSizeBytes)} of source, ${formatBytes(summary.totalContentBytes)} emitted).`,
|
|
12712
|
+
`Would skip ${plural(summary.skippedCount, "file")}.`
|
|
12525
12713
|
];
|
|
12526
12714
|
if (topReasons.length > 0) {
|
|
12527
12715
|
lines.push("Top skip reasons:");
|
|
12528
12716
|
for (const entry of topReasons) lines.push(` - ${entry.reason} (${entry.count})`);
|
|
12529
12717
|
}
|
|
12530
|
-
if (
|
|
12531
|
-
lines.push(`Warnings (${
|
|
12532
|
-
for (const warning of
|
|
12718
|
+
if (summary.warnings.length > 0) {
|
|
12719
|
+
lines.push(`Warnings (${summary.warnings.length}):`);
|
|
12720
|
+
for (const warning of summary.warnings.slice(0, 5)) lines.push(` - ${warning}`);
|
|
12533
12721
|
}
|
|
12534
12722
|
return {
|
|
12535
12723
|
text: lines.join("\n"),
|
|
12536
12724
|
structured: {
|
|
12537
|
-
files:
|
|
12538
|
-
skipped:
|
|
12539
|
-
parts:
|
|
12540
|
-
sourceBytes:
|
|
12541
|
-
emittedBytes:
|
|
12542
|
-
preset:
|
|
12543
|
-
maxPartBytes:
|
|
12544
|
-
layers:
|
|
12725
|
+
files: summary.totalFiles,
|
|
12726
|
+
skipped: summary.skippedCount,
|
|
12727
|
+
parts: summary.partsCount,
|
|
12728
|
+
sourceBytes: summary.totalSizeBytes,
|
|
12729
|
+
emittedBytes: summary.totalContentBytes,
|
|
12730
|
+
preset: summary.preset,
|
|
12731
|
+
maxPartBytes: workspace.config.maxPartBytes,
|
|
12732
|
+
layers: summary.layers,
|
|
12545
12733
|
skipReasons: topReasons,
|
|
12546
|
-
warnings:
|
|
12547
|
-
warningCount:
|
|
12734
|
+
warnings: summary.warnings.slice(0, 5),
|
|
12735
|
+
warningCount: summary.warnings.length
|
|
12548
12736
|
}
|
|
12549
12737
|
};
|
|
12550
12738
|
}
|
|
@@ -13968,6 +14156,7 @@ function buildAgentContract() {
|
|
|
13968
14156
|
{ key: "layers", type: "array", default: "preset layers", summary: "Custom layer rules (glob or RegExp)." },
|
|
13969
14157
|
{ key: "kinds", type: "array", default: "preset kinds", summary: "Custom kind rules." },
|
|
13970
14158
|
{ key: "secrets", type: "object", default: "{}", summary: "Custom secret patterns, or disable the defaults." },
|
|
14159
|
+
{ 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." },
|
|
13971
14160
|
{ key: "hooks", type: "object", default: "{}", summary: "afterGenerate(manifest) runs after a successful generate." }
|
|
13972
14161
|
]
|
|
13973
14162
|
},
|
|
@@ -13984,6 +14173,8 @@ function buildAgentContract() {
|
|
|
13984
14173
|
notes: [
|
|
13985
14174
|
"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.",
|
|
13986
14175
|
"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.",
|
|
14176
|
+
"indexes.imports.byFile includes previewed files (their import specifiers are still extracted); such an entry carries `exportsOmitted: true` instead of pretending it exports nothing.",
|
|
14177
|
+
"validate re-checks manifest.incomplete[] against files[] and refuses a manifest whose two statements of what is missing disagree.",
|
|
13987
14178
|
"manifest.skipped[] carries the path and the exact reason it was excluded.",
|
|
13988
14179
|
`The output directory is replaced atomically; ${MIN_MAX_PART_BYTES} bytes is the smallest legal budget.`
|
|
13989
14180
|
]
|
|
@@ -14977,11 +15168,11 @@ var MAX_LINE_BYTES = 32 * 1024 * 1024;
|
|
|
14977
15168
|
function createWriter(output) {
|
|
14978
15169
|
return {
|
|
14979
15170
|
write(value) {
|
|
14980
|
-
return new Promise((
|
|
15171
|
+
return new Promise((resolve12, reject) => {
|
|
14981
15172
|
output.write(`${JSON.stringify(value)}
|
|
14982
15173
|
`, (error) => {
|
|
14983
15174
|
if (error) reject(error);
|
|
14984
|
-
else
|
|
15175
|
+
else resolve12();
|
|
14985
15176
|
});
|
|
14986
15177
|
});
|
|
14987
15178
|
}
|
|
@@ -15118,8 +15309,8 @@ async function runStdioServer(options) {
|
|
|
15118
15309
|
let inFlight = 0;
|
|
15119
15310
|
let inputEnded = false;
|
|
15120
15311
|
let resolveDone = () => void 0;
|
|
15121
|
-
const finished = new Promise((
|
|
15122
|
-
resolveDone =
|
|
15312
|
+
const finished = new Promise((resolve12) => {
|
|
15313
|
+
resolveDone = resolve12;
|
|
15123
15314
|
});
|
|
15124
15315
|
const finishIfIdle = () => {
|
|
15125
15316
|
if (inputEnded && inFlight === 0) resolveDone(0);
|
|
@@ -15655,8 +15846,8 @@ function splitList(value) {
|
|
|
15655
15846
|
}
|
|
15656
15847
|
function displayOutPath(cwd, outDir, ...segments) {
|
|
15657
15848
|
const absolute = path16__namespace.resolve(cwd, outDir, ...segments);
|
|
15658
|
-
const
|
|
15659
|
-
if (
|
|
15849
|
+
const relative15 = path16__namespace.relative(cwd, absolute);
|
|
15850
|
+
if (relative15 && !relative15.startsWith("..") && !path16__namespace.isAbsolute(relative15)) return relative15;
|
|
15660
15851
|
return absolute;
|
|
15661
15852
|
}
|
|
15662
15853
|
function nextStepHint(cwd, scriptsAddedNow) {
|
|
@@ -15664,7 +15855,7 @@ function nextStepHint(cwd, scriptsAddedNow) {
|
|
|
15664
15855
|
if (!hasScript) {
|
|
15665
15856
|
try {
|
|
15666
15857
|
const parsed = JSON.parse(
|
|
15667
|
-
|
|
15858
|
+
stripJsonComments(fs15__namespace.readFileSync(path16__namespace.join(cwd, "package.json"), "utf8"))
|
|
15668
15859
|
);
|
|
15669
15860
|
hasScript = typeof parsed.scripts?.snapshot === "string";
|
|
15670
15861
|
} catch {
|
|
@@ -15731,7 +15922,9 @@ async function runInitCommand(invocation) {
|
|
|
15731
15922
|
}
|
|
15732
15923
|
function generatorOrigin(cwd) {
|
|
15733
15924
|
try {
|
|
15734
|
-
const pkg = JSON.parse(
|
|
15925
|
+
const pkg = JSON.parse(
|
|
15926
|
+
stripJsonComments(fs15__namespace.readFileSync(path16__namespace.join(cwd, "package.json"), "utf8"))
|
|
15927
|
+
);
|
|
15735
15928
|
const spec = pkg.dependencies?.["codebase-snapshot"] ?? pkg.devDependencies?.["codebase-snapshot"];
|
|
15736
15929
|
if (typeof spec === "string") return `project dependency ${spec}`;
|
|
15737
15930
|
} catch {
|
|
@@ -16028,6 +16221,8 @@ function runSkillCommand(invocation) {
|
|
|
16028
16221
|
function renderValidateText(result) {
|
|
16029
16222
|
if (result.valid) {
|
|
16030
16223
|
info("\u2705 Snapshot is valid and up to date with disk.");
|
|
16224
|
+
} else if (result.errors.length === 1 && result.errors[0].includes(" is not a snapshot manifest: ")) {
|
|
16225
|
+
warn(`\u274C ${result.errors[0]}`);
|
|
16031
16226
|
} else {
|
|
16032
16227
|
warn("\u274C Snapshot validation failed:");
|
|
16033
16228
|
for (const error of result.errors) warn(` - ${error}`);
|
|
@@ -16233,7 +16428,11 @@ ${USAGE}
|
|
|
16233
16428
|
if (invocation.command === "diff") {
|
|
16234
16429
|
try {
|
|
16235
16430
|
const [beforePath, afterPath] = invocation.args;
|
|
16236
|
-
const diff = compareManifests(
|
|
16431
|
+
const diff = compareManifests(
|
|
16432
|
+
loadManifest(beforePath),
|
|
16433
|
+
loadManifest(afterPath),
|
|
16434
|
+
resolved.secretRules
|
|
16435
|
+
);
|
|
16237
16436
|
emit(invocation.format, diff, () => info(renderDiffText(diff)));
|
|
16238
16437
|
return 0;
|
|
16239
16438
|
} catch (err) {
|
|
@@ -16288,7 +16487,7 @@ ${USAGE}
|
|
|
16288
16487
|
const reasons = skipBreakdown.length > shownReasons.length ? `${shownReasons.join(", ")}, +${skipBreakdown.length - shownReasons.length} more` : shownReasons.join(", ");
|
|
16289
16488
|
const candidates = manifest.counts.totalFiles + manifest.counts.skippedCount;
|
|
16290
16489
|
info(
|
|
16291
|
-
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")}`
|
|
16490
|
+
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")}`
|
|
16292
16491
|
);
|
|
16293
16492
|
info(` - Total lines: ${formatNumber(manifest.counts.totalLines)}`);
|
|
16294
16493
|
info(
|
|
@@ -16388,8 +16587,8 @@ function comparablePath(value) {
|
|
|
16388
16587
|
return process.platform === "win32" ? absolute.toLowerCase() : absolute;
|
|
16389
16588
|
}
|
|
16390
16589
|
function isSameOrInside(parent, candidate) {
|
|
16391
|
-
const
|
|
16392
|
-
return
|
|
16590
|
+
const relative15 = path16__namespace.relative(parent, candidate);
|
|
16591
|
+
return relative15 === "" || relative15 !== ".." && !relative15.startsWith(`..${path16__namespace.sep}`) && !path16__namespace.isAbsolute(relative15);
|
|
16393
16592
|
}
|
|
16394
16593
|
function isGeneratedWatchPath(candidate, paths) {
|
|
16395
16594
|
const absolute = comparablePath(path16__namespace.resolve(paths.cwd, candidate));
|
|
@@ -16534,12 +16733,12 @@ async function runWatchLoop(invocation, resolved, options) {
|
|
|
16534
16733
|
info(`\u26A0 Watch error: ${err.message}`);
|
|
16535
16734
|
info(" The watcher may have missed changes. Restart with Ctrl+C if they stop arriving.");
|
|
16536
16735
|
});
|
|
16537
|
-
await new Promise((
|
|
16736
|
+
await new Promise((resolve12) => {
|
|
16538
16737
|
const stop = () => {
|
|
16539
16738
|
stopped = true;
|
|
16540
16739
|
if (timer) clearTimeout(timer);
|
|
16541
16740
|
watcher.close();
|
|
16542
|
-
|
|
16741
|
+
resolve12();
|
|
16543
16742
|
};
|
|
16544
16743
|
process.once("SIGINT", stop);
|
|
16545
16744
|
process.once("SIGTERM", stop);
|