codebase-snapshot 0.10.0 → 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 +99 -1
- package/README.md +3 -2
- package/dist/bin.js +603 -406
- package/dist/{chunk-EP7OCPUM.js → chunk-5AV7OR3J.js} +377 -184
- package/dist/{chunk-4H7MSW64.js → chunk-5EYBTBFY.js} +25 -29
- package/dist/cli.cjs +602 -406
- package/dist/cli.d.cts +11 -9
- package/dist/cli.d.ts +11 -9
- package/dist/cli.js +15 -7
- 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 +353 -177
- package/dist/index.d.cts +68 -23
- package/dist/index.d.ts +68 -23
- package/dist/index.js +1 -1
- package/dist/mcp.cjs +454 -2695
- 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 +16 -12
- package/docs/configuration.md +19 -3
- package/docs/how-to-context-budget.md +2 -1
- package/docs/how-to-feed-a-repo-to-claude.md +3 -2
- package/docs/mcp.md +4 -4
- package/docs/output.md +9 -6
- package/docs/stale-context-is-your-bug.md +14 -4
- package/docs/vs-code2prompt.md +4 -3
- package/docs/vs-gitingest.md +5 -4
- package/docs/vs-repomix.md +4 -3
- 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.10.
|
|
2194
|
+
var GENERATOR_VERSION = "0.10.2";
|
|
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") {
|
|
@@ -3046,6 +3087,178 @@ import { createRequire } from "module";
|
|
|
3046
3087
|
import * as path3 from "path";
|
|
3047
3088
|
import { pathToFileURL } from "url";
|
|
3048
3089
|
|
|
3090
|
+
// src/ast/structured.ts
|
|
3091
|
+
function stripJsonComments(content) {
|
|
3092
|
+
const text2 = content.replace(/^\uFEFF/, "");
|
|
3093
|
+
const withoutComments = stripComments(text2);
|
|
3094
|
+
return stripTrailingCommas(withoutComments);
|
|
3095
|
+
}
|
|
3096
|
+
function stripComments(text2) {
|
|
3097
|
+
let out = "";
|
|
3098
|
+
let inString = false;
|
|
3099
|
+
let escaped = false;
|
|
3100
|
+
for (let index = 0; index < text2.length; index += 1) {
|
|
3101
|
+
const char = text2[index];
|
|
3102
|
+
if (inString) {
|
|
3103
|
+
out += char;
|
|
3104
|
+
if (escaped) escaped = false;
|
|
3105
|
+
else if (char === "\\") escaped = true;
|
|
3106
|
+
else if (char === '"') inString = false;
|
|
3107
|
+
continue;
|
|
3108
|
+
}
|
|
3109
|
+
if (char === '"') {
|
|
3110
|
+
inString = true;
|
|
3111
|
+
out += char;
|
|
3112
|
+
continue;
|
|
3113
|
+
}
|
|
3114
|
+
if (char === "/" && text2[index + 1] === "/") {
|
|
3115
|
+
while (index < text2.length && text2[index] !== "\n" && text2[index] !== "\r") index += 1;
|
|
3116
|
+
index -= 1;
|
|
3117
|
+
continue;
|
|
3118
|
+
}
|
|
3119
|
+
if (char === "/" && text2[index + 1] === "*") {
|
|
3120
|
+
index += 2;
|
|
3121
|
+
while (index < text2.length && !(text2[index] === "*" && text2[index + 1] === "/")) {
|
|
3122
|
+
if (text2[index] === "\n" || text2[index] === "\r") out += text2[index];
|
|
3123
|
+
index += 1;
|
|
3124
|
+
}
|
|
3125
|
+
index += 1;
|
|
3126
|
+
continue;
|
|
3127
|
+
}
|
|
3128
|
+
out += char;
|
|
3129
|
+
}
|
|
3130
|
+
return out;
|
|
3131
|
+
}
|
|
3132
|
+
function stripTrailingCommas(text2) {
|
|
3133
|
+
let out = "";
|
|
3134
|
+
let inString = false;
|
|
3135
|
+
let escaped = false;
|
|
3136
|
+
for (let index = 0; index < text2.length; index += 1) {
|
|
3137
|
+
const char = text2[index];
|
|
3138
|
+
if (inString) {
|
|
3139
|
+
out += char;
|
|
3140
|
+
if (escaped) escaped = false;
|
|
3141
|
+
else if (char === "\\") escaped = true;
|
|
3142
|
+
else if (char === '"') inString = false;
|
|
3143
|
+
continue;
|
|
3144
|
+
}
|
|
3145
|
+
if (char === '"') {
|
|
3146
|
+
inString = true;
|
|
3147
|
+
out += char;
|
|
3148
|
+
continue;
|
|
3149
|
+
}
|
|
3150
|
+
if (char === ",") {
|
|
3151
|
+
let next = index + 1;
|
|
3152
|
+
while (next < text2.length && /\s/.test(text2[next])) next += 1;
|
|
3153
|
+
if (text2[next] === "}" || text2[next] === "]") continue;
|
|
3154
|
+
}
|
|
3155
|
+
out += char;
|
|
3156
|
+
}
|
|
3157
|
+
return out;
|
|
3158
|
+
}
|
|
3159
|
+
function summarizeJson(content) {
|
|
3160
|
+
try {
|
|
3161
|
+
const parsed = JSON.parse(stripJsonComments(content));
|
|
3162
|
+
if (Array.isArray(parsed)) {
|
|
3163
|
+
const sample = parsed[0];
|
|
3164
|
+
const sampleKeys = sample && typeof sample === "object" && !Array.isArray(sample) ? Object.keys(sample).slice(0, 10).sort() : [];
|
|
3165
|
+
return {
|
|
3166
|
+
shape: "array",
|
|
3167
|
+
itemCount: parsed.length,
|
|
3168
|
+
keys: [],
|
|
3169
|
+
sampleKeys
|
|
3170
|
+
};
|
|
3171
|
+
}
|
|
3172
|
+
if (parsed && typeof parsed === "object") {
|
|
3173
|
+
const keys = Object.keys(parsed).sort();
|
|
3174
|
+
return {
|
|
3175
|
+
shape: "object",
|
|
3176
|
+
itemCount: keys.length,
|
|
3177
|
+
keys: keys.slice(0, 30),
|
|
3178
|
+
sampleKeys: []
|
|
3179
|
+
};
|
|
3180
|
+
}
|
|
3181
|
+
return {
|
|
3182
|
+
shape: typeof parsed,
|
|
3183
|
+
itemCount: null,
|
|
3184
|
+
keys: [],
|
|
3185
|
+
sampleKeys: []
|
|
3186
|
+
};
|
|
3187
|
+
} catch {
|
|
3188
|
+
return {
|
|
3189
|
+
shape: "invalid-json",
|
|
3190
|
+
itemCount: null,
|
|
3191
|
+
keys: [],
|
|
3192
|
+
sampleKeys: []
|
|
3193
|
+
};
|
|
3194
|
+
}
|
|
3195
|
+
}
|
|
3196
|
+
function frontMatterEnd(lines) {
|
|
3197
|
+
if (lines.length < 3 || lines[0].trim() !== "---") return 0;
|
|
3198
|
+
for (let index = 1; index < lines.length; index += 1) {
|
|
3199
|
+
const line = lines[index];
|
|
3200
|
+
const candidate = line.trim();
|
|
3201
|
+
if (candidate === "---" || candidate === "...") {
|
|
3202
|
+
return index > 1 ? index : 0;
|
|
3203
|
+
}
|
|
3204
|
+
if (candidate === "") continue;
|
|
3205
|
+
if (/^#(\s|$)/.test(candidate)) continue;
|
|
3206
|
+
if (/^(`{3,}|~{3,})/.test(candidate)) return 0;
|
|
3207
|
+
if (/^#{1,6}\s+\S/.test(candidate)) return 0;
|
|
3208
|
+
const isYamlMapping = /^[A-Za-z0-9_.-]+\s*:(\s|$)/.test(candidate);
|
|
3209
|
+
const isListItem = /^-(?:(\s|$))/.test(candidate);
|
|
3210
|
+
const isIndented = /^[ \t]/.test(line);
|
|
3211
|
+
if (!isYamlMapping && !isListItem && !isIndented) return 0;
|
|
3212
|
+
}
|
|
3213
|
+
return 0;
|
|
3214
|
+
}
|
|
3215
|
+
function summarizeMarkdown(content) {
|
|
3216
|
+
const headings = [];
|
|
3217
|
+
const frontmatterKeys = [];
|
|
3218
|
+
const lines = content.replace(/^\uFEFF/, "").split(/\r\n|\n|\r/);
|
|
3219
|
+
let inFrontmatter = false;
|
|
3220
|
+
let fence = null;
|
|
3221
|
+
const frontMatterEndLine = frontMatterEnd(lines);
|
|
3222
|
+
for (let index = 0; index < lines.length; index++) {
|
|
3223
|
+
const line = lines[index];
|
|
3224
|
+
if (index === 0 && frontMatterEndLine > 0) {
|
|
3225
|
+
inFrontmatter = true;
|
|
3226
|
+
continue;
|
|
3227
|
+
}
|
|
3228
|
+
if (inFrontmatter) {
|
|
3229
|
+
const trimmedFrontmatter = line.trim();
|
|
3230
|
+
if (trimmedFrontmatter === "---" || trimmedFrontmatter === "...") {
|
|
3231
|
+
inFrontmatter = false;
|
|
3232
|
+
continue;
|
|
3233
|
+
}
|
|
3234
|
+
const match = /^([A-Za-z0-9_.-]+)\s*:/.exec(line);
|
|
3235
|
+
if (match) frontmatterKeys.push(match[1]);
|
|
3236
|
+
continue;
|
|
3237
|
+
}
|
|
3238
|
+
const trimmed = line.trim();
|
|
3239
|
+
const fenceMatch = /^(`{3,}|~{3,})(.*)$/.exec(trimmed);
|
|
3240
|
+
if (fenceMatch) {
|
|
3241
|
+
const run = fenceMatch[1];
|
|
3242
|
+
const rest = fenceMatch[2].trim();
|
|
3243
|
+
if (fence === null) {
|
|
3244
|
+
fence = { marker: run[0], length: run.length };
|
|
3245
|
+
} else if (run[0] === fence.marker && run.length >= fence.length && rest === "") {
|
|
3246
|
+
fence = null;
|
|
3247
|
+
}
|
|
3248
|
+
continue;
|
|
3249
|
+
}
|
|
3250
|
+
if (fence !== null) continue;
|
|
3251
|
+
const headingMatch = /^(#{1,6})\s+(.+)$/.exec(trimmed);
|
|
3252
|
+
if (headingMatch) {
|
|
3253
|
+
headings.push(`${headingMatch[1]} ${headingMatch[2].trim()}`);
|
|
3254
|
+
}
|
|
3255
|
+
}
|
|
3256
|
+
return {
|
|
3257
|
+
headings: headings.slice(0, 40),
|
|
3258
|
+
frontmatterKeys: Array.from(new Set(frontmatterKeys)).sort()
|
|
3259
|
+
};
|
|
3260
|
+
}
|
|
3261
|
+
|
|
3049
3262
|
// src/tokenize.ts
|
|
3050
3263
|
var WORD_RUN = /[A-Za-z0-9_]+/g;
|
|
3051
3264
|
var SINGLE_TOKEN = /[^\sA-Za-z0-9_]/g;
|
|
@@ -3202,70 +3415,6 @@ function supportsTypeScriptImports() {
|
|
|
3202
3415
|
if (!Number.isFinite(major)) return false;
|
|
3203
3416
|
return major > 22 || major === 22 && minor >= 6;
|
|
3204
3417
|
}
|
|
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
3418
|
function parseJsonish(raw, file) {
|
|
3270
3419
|
try {
|
|
3271
3420
|
return JSON.parse(stripJsonComments(raw));
|
|
@@ -3286,7 +3435,7 @@ function describeValue2(value) {
|
|
|
3286
3435
|
return `${typeof value} (${String(value)})`;
|
|
3287
3436
|
}
|
|
3288
3437
|
var isThenable = (value) => typeof value.then === "function";
|
|
3289
|
-
var
|
|
3438
|
+
var CONFIG_KEY_NAMES = [
|
|
3290
3439
|
"artifacts",
|
|
3291
3440
|
"branch",
|
|
3292
3441
|
"budgets",
|
|
@@ -3317,7 +3466,8 @@ var CONFIG_KEYS = /* @__PURE__ */ new Set([
|
|
|
3317
3466
|
"skeleton",
|
|
3318
3467
|
"tmpDir",
|
|
3319
3468
|
"withDependents"
|
|
3320
|
-
]
|
|
3469
|
+
];
|
|
3470
|
+
var CONFIG_KEYS = new Set(CONFIG_KEY_NAMES);
|
|
3321
3471
|
function assertKnownConfigKeys(value, file) {
|
|
3322
3472
|
const unknownKeys = Object.keys(value).filter((key) => !CONFIG_KEYS.has(key));
|
|
3323
3473
|
if (unknownKeys.length === 0) return;
|
|
@@ -3664,11 +3814,11 @@ function outputExcludePatterns(cwd, outDir, tmpDir) {
|
|
|
3664
3814
|
const patterns = [];
|
|
3665
3815
|
for (const dir of [outDir, tmpDir]) {
|
|
3666
3816
|
const absolute = path3.resolve(cwd, dir);
|
|
3667
|
-
const
|
|
3668
|
-
if (!
|
|
3817
|
+
const relative15 = path3.relative(cwd, absolute);
|
|
3818
|
+
if (!relative15 || relative15 === ".." || relative15.startsWith(`..${path3.sep}`) || path3.isAbsolute(relative15)) {
|
|
3669
3819
|
continue;
|
|
3670
3820
|
}
|
|
3671
|
-
patterns.push(`${
|
|
3821
|
+
patterns.push(`${relative15.replace(/\\/g, "/")}/**`);
|
|
3672
3822
|
}
|
|
3673
3823
|
return patterns;
|
|
3674
3824
|
}
|
|
@@ -4243,8 +4393,8 @@ function tsconfigPathsFor(cwd) {
|
|
|
4243
4393
|
return value;
|
|
4244
4394
|
}
|
|
4245
4395
|
function repositoryRelative(cwd, target) {
|
|
4246
|
-
const
|
|
4247
|
-
return
|
|
4396
|
+
const relative15 = path4.relative(cwd, target).replace(/\\/g, "/");
|
|
4397
|
+
return relative15.length === 0 || !relative15.startsWith("..") && !path4.isAbsolute(relative15) ? relative15 : null;
|
|
4248
4398
|
}
|
|
4249
4399
|
function rememberFirst(map, key, value) {
|
|
4250
4400
|
if (!map.has(key)) map.set(key, value);
|
|
@@ -4648,6 +4798,8 @@ function summarizeTypeScriptSource(relativePath, content) {
|
|
|
4648
4798
|
if (cjsExports.length > 0) {
|
|
4649
4799
|
summary.exportsKind = summary.exports.length > 0 ? "mixed" : "cjs";
|
|
4650
4800
|
summary.exports.push(...cjsExports);
|
|
4801
|
+
} else if (summary.exports.length > 0) {
|
|
4802
|
+
summary.exportsKind = "esm";
|
|
4651
4803
|
}
|
|
4652
4804
|
const dedupeSorted2 = (values) => Array.from(new Set(values)).sort((a, b) => a < b ? -1 : a > b ? 1 : 0);
|
|
4653
4805
|
summary.directives = dedupeSorted2(summary.directives);
|
|
@@ -5212,9 +5364,9 @@ var rubyProfile = {
|
|
|
5212
5364
|
eachLine(content, (line) => {
|
|
5213
5365
|
const trimmed = line.trim();
|
|
5214
5366
|
if (!trimmed || trimmed.startsWith("#")) return;
|
|
5215
|
-
const
|
|
5216
|
-
if (
|
|
5217
|
-
summary.imports.push(`./${
|
|
5367
|
+
const relative15 = REQUIRE_RELATIVE.exec(trimmed);
|
|
5368
|
+
if (relative15) {
|
|
5369
|
+
summary.imports.push(`./${relative15[1]}`);
|
|
5218
5370
|
return;
|
|
5219
5371
|
}
|
|
5220
5372
|
const required = REQUIRE.exec(trimmed);
|
|
@@ -5880,6 +6032,16 @@ function wouldNowBeIncluded(cwd, relativePath) {
|
|
|
5880
6032
|
return false;
|
|
5881
6033
|
}
|
|
5882
6034
|
}
|
|
6035
|
+
var TRUNCATION_REASONS = /* @__PURE__ */ new Set([
|
|
6036
|
+
"large-file-budget",
|
|
6037
|
+
"part-budget",
|
|
6038
|
+
"section-metadata"
|
|
6039
|
+
]);
|
|
6040
|
+
function isConfinedRelative(value) {
|
|
6041
|
+
if (value.length === 0 || value.includes("\0") || value.includes("\\")) return false;
|
|
6042
|
+
if (path6.isAbsolute(value)) return false;
|
|
6043
|
+
return !value.split("/").includes("..");
|
|
6044
|
+
}
|
|
5883
6045
|
function describeManifestShapeProblem(value) {
|
|
5884
6046
|
if (!value || typeof value !== "object" || Array.isArray(value)) return "not a JSON object";
|
|
5885
6047
|
const candidate = value;
|
|
@@ -5945,6 +6107,68 @@ function describeManifestShapeProblem(value) {
|
|
|
5945
6107
|
if (!candidate.kinds || typeof candidate.kinds !== "object" || Array.isArray(candidate.kinds)) {
|
|
5946
6108
|
return 'missing "kinds" object';
|
|
5947
6109
|
}
|
|
6110
|
+
const incompleteCount = counts.incompleteCount;
|
|
6111
|
+
if (typeof incompleteCount !== "number" || !Number.isSafeInteger(incompleteCount) || incompleteCount < 0) {
|
|
6112
|
+
return "missing numeric `counts.incompleteCount`";
|
|
6113
|
+
}
|
|
6114
|
+
const incomplete = candidate.incomplete;
|
|
6115
|
+
if (!Array.isArray(incomplete)) return 'missing "incomplete" array';
|
|
6116
|
+
if (incompleteCount !== incomplete.length) {
|
|
6117
|
+
return "`counts.incompleteCount` does not match the length of `incomplete`";
|
|
6118
|
+
}
|
|
6119
|
+
for (const entry of incomplete) {
|
|
6120
|
+
if (!entry || typeof entry !== "object" || Array.isArray(entry)) {
|
|
6121
|
+
return 'an "incomplete" entry is not an object';
|
|
6122
|
+
}
|
|
6123
|
+
const fields = entry;
|
|
6124
|
+
const relativePath = fields.relativePath;
|
|
6125
|
+
if (typeof relativePath !== "string" || relativePath.length === 0) {
|
|
6126
|
+
return 'an "incomplete" entry has no "relativePath"';
|
|
6127
|
+
}
|
|
6128
|
+
if (!isConfinedRelative(relativePath)) {
|
|
6129
|
+
return 'an "incomplete" entry "relativePath" must stay inside the repository';
|
|
6130
|
+
}
|
|
6131
|
+
if (typeof fields.part !== "string" || fields.part.trim() === "") {
|
|
6132
|
+
return 'an "incomplete" entry has no "part"';
|
|
6133
|
+
}
|
|
6134
|
+
if (typeof fields.reason !== "string" || !TRUNCATION_REASONS.has(fields.reason)) {
|
|
6135
|
+
return 'an "incomplete" entry has an unknown "reason"';
|
|
6136
|
+
}
|
|
6137
|
+
for (const key of ["omittedLines", "includedLines", "lines"]) {
|
|
6138
|
+
const value2 = fields[key];
|
|
6139
|
+
if (typeof value2 !== "number" || !Number.isSafeInteger(value2) || value2 < 0) {
|
|
6140
|
+
return `an "incomplete" entry "${key}" must be a non-negative integer`;
|
|
6141
|
+
}
|
|
6142
|
+
}
|
|
6143
|
+
const lines = fields.lines;
|
|
6144
|
+
if (fields.includedLines > lines) {
|
|
6145
|
+
return 'an "incomplete" entry "includedLines" exceeds its "lines"';
|
|
6146
|
+
}
|
|
6147
|
+
const ranges = fields.omittedRanges;
|
|
6148
|
+
if (!Array.isArray(ranges)) return 'an "incomplete" entry has no "omittedRanges" array';
|
|
6149
|
+
let previousEnd = 0;
|
|
6150
|
+
let omitted = 0;
|
|
6151
|
+
for (const range of ranges) {
|
|
6152
|
+
if (!Array.isArray(range) || range.length !== 2) {
|
|
6153
|
+
return 'an "incomplete" entry "omittedRanges" must hold [from, to] pairs';
|
|
6154
|
+
}
|
|
6155
|
+
const [from, to] = range;
|
|
6156
|
+
if (typeof from !== "number" || typeof to !== "number" || !Number.isSafeInteger(from) || !Number.isSafeInteger(to)) {
|
|
6157
|
+
return 'an "incomplete" entry "omittedRanges" must hold integer pairs';
|
|
6158
|
+
}
|
|
6159
|
+
if (from < 1 || to < from || to > lines) {
|
|
6160
|
+
return `an "incomplete" entry records an omitted range ${from}-${to}, outside 1-${lines}`;
|
|
6161
|
+
}
|
|
6162
|
+
if (from <= previousEnd) {
|
|
6163
|
+
return 'an "incomplete" entry "omittedRanges" must be sorted and non-overlapping';
|
|
6164
|
+
}
|
|
6165
|
+
previousEnd = to;
|
|
6166
|
+
omitted += to - from + 1;
|
|
6167
|
+
}
|
|
6168
|
+
if (omitted !== fields.omittedLines) {
|
|
6169
|
+
return "`omittedLines` does not match the ranges it records";
|
|
6170
|
+
}
|
|
6171
|
+
}
|
|
5948
6172
|
}
|
|
5949
6173
|
if (!Array.isArray(candidate.files)) return 'missing "files" array';
|
|
5950
6174
|
for (const entry of candidate.files) {
|
|
@@ -6057,11 +6281,57 @@ function validateSnapshot(configInput) {
|
|
|
6057
6281
|
"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."
|
|
6058
6282
|
);
|
|
6059
6283
|
}
|
|
6060
|
-
const manifestFileMap = /* @__PURE__ */ new Map();
|
|
6284
|
+
const manifestFileMap = /* @__PURE__ */ new Map();
|
|
6285
|
+
const manifestFilesByPath = /* @__PURE__ */ new Map();
|
|
6286
|
+
for (const file of manifest.files) {
|
|
6287
|
+
if (file && typeof file.relativePath === "string") {
|
|
6288
|
+
manifestFileMap.set(file.relativePath, file.hashSha256);
|
|
6289
|
+
manifestFilesByPath.set(file.relativePath, file);
|
|
6290
|
+
}
|
|
6291
|
+
}
|
|
6292
|
+
const incompleteRecords = manifest.incomplete ?? [];
|
|
6293
|
+
const incompleteness = /* @__PURE__ */ new Map();
|
|
6294
|
+
for (const record of incompleteRecords) {
|
|
6295
|
+
incompleteness.set(record.relativePath, record);
|
|
6296
|
+
const label = maskedPath(record.relativePath, config.secretRules);
|
|
6297
|
+
const file = manifestFilesByPath.get(record.relativePath);
|
|
6298
|
+
if (file === void 0) {
|
|
6299
|
+
drift.partIssues.push({
|
|
6300
|
+
part: "(manifest)",
|
|
6301
|
+
issue: `${label} is in incomplete[] but not in files[]`
|
|
6302
|
+
});
|
|
6303
|
+
continue;
|
|
6304
|
+
}
|
|
6305
|
+
if (file.part !== record.part) {
|
|
6306
|
+
drift.partIssues.push({
|
|
6307
|
+
part: "(manifest)",
|
|
6308
|
+
issue: `${label} is recorded in part ${String(record.part)} in incomplete[] and part ${String(file.part)} in files[]`
|
|
6309
|
+
});
|
|
6310
|
+
}
|
|
6311
|
+
if (file.truncationReason !== record.reason) {
|
|
6312
|
+
drift.partIssues.push({
|
|
6313
|
+
part: "(manifest)",
|
|
6314
|
+
issue: `${label} records truncationReason ${String(file.truncationReason)} in files[] and reason ${String(record.reason)} in incomplete[]`
|
|
6315
|
+
});
|
|
6316
|
+
}
|
|
6317
|
+
const recordedRanges = file.omittedRanges ?? [];
|
|
6318
|
+
const rangesAgree = recordedRanges.length === record.omittedRanges.length && recordedRanges.every(
|
|
6319
|
+
([from, to], index) => record.omittedRanges[index][0] === from && record.omittedRanges[index][1] === to
|
|
6320
|
+
);
|
|
6321
|
+
if (!rangesAgree || file.includedLines !== record.includedLines || file.lines !== record.lines) {
|
|
6322
|
+
drift.partIssues.push({
|
|
6323
|
+
part: "(manifest)",
|
|
6324
|
+
issue: `${label} records different omission numbers in files[] and incomplete[]`
|
|
6325
|
+
});
|
|
6326
|
+
}
|
|
6327
|
+
}
|
|
6061
6328
|
for (const file of manifest.files) {
|
|
6062
|
-
if (file
|
|
6063
|
-
|
|
6064
|
-
|
|
6329
|
+
if (file.truncationReason === void 0) continue;
|
|
6330
|
+
if (incompleteness.has(file.relativePath)) continue;
|
|
6331
|
+
drift.partIssues.push({
|
|
6332
|
+
part: "(manifest)",
|
|
6333
|
+
issue: `${maskedPath(file.relativePath, config.secretRules)} records a truncationReason but is missing from incomplete[]`
|
|
6334
|
+
});
|
|
6065
6335
|
}
|
|
6066
6336
|
const skippedReasons = /* @__PURE__ */ new Map();
|
|
6067
6337
|
for (const entry of manifest.skipped) {
|
|
@@ -6119,7 +6389,7 @@ function validateSnapshot(configInput) {
|
|
|
6119
6389
|
// snapshot was reported as drifting.
|
|
6120
6390
|
toolOwnedPaths: [config.outDir, config.tmpDir].map(
|
|
6121
6391
|
(directory) => path6.relative(config.cwd, path6.resolve(config.cwd, directory)).replace(/\\/g, "/")
|
|
6122
|
-
).filter((
|
|
6392
|
+
).filter((relative15) => relative15.length > 0 && !relative15.startsWith(".."))
|
|
6123
6393
|
});
|
|
6124
6394
|
for (const diskFile of collection.files) {
|
|
6125
6395
|
const snapshotHash = manifestFileMap.get(diskFile);
|
|
@@ -6575,8 +6845,8 @@ function validateSnapshot(configInput) {
|
|
|
6575
6845
|
const target = match[1].split("#")[0];
|
|
6576
6846
|
if (target.length === 0 || /^[a-z][a-z0-9+.-]*:/i.test(target)) continue;
|
|
6577
6847
|
const resolved = path6.resolve(snapshotDir, "reports", target);
|
|
6578
|
-
const
|
|
6579
|
-
if (
|
|
6848
|
+
const relative15 = path6.relative(snapshotDir, resolved);
|
|
6849
|
+
if (relative15.startsWith("..") || path6.isAbsolute(relative15) || !fs7.existsSync(resolved)) {
|
|
6580
6850
|
drift.partIssues.push({
|
|
6581
6851
|
part: key,
|
|
6582
6852
|
issue: `links to ${maskedPath(target, config.secretRules)}, which does not exist in the snapshot`
|
|
@@ -6672,19 +6942,19 @@ function side(manifest) {
|
|
|
6672
6942
|
function shortDigest(value) {
|
|
6673
6943
|
return value === null ? "not recorded" : `${value.slice(0, 12)}\u2026`;
|
|
6674
6944
|
}
|
|
6675
|
-
function describeLayerChanges(before, after) {
|
|
6945
|
+
function describeLayerChanges(before, after, secretRules) {
|
|
6676
6946
|
const names = Array.from(/* @__PURE__ */ new Set([...Object.keys(before), ...Object.keys(after)])).sort();
|
|
6677
6947
|
const changes = [];
|
|
6678
6948
|
for (const name of names) {
|
|
6679
6949
|
const was = before[name] ?? 0;
|
|
6680
6950
|
const now = after[name] ?? 0;
|
|
6681
6951
|
if (was === now) continue;
|
|
6682
|
-
const label = findSecretInPath(name)?.masked ?? name;
|
|
6952
|
+
const label = findSecretInPath(name, secretRules)?.masked ?? name;
|
|
6683
6953
|
changes.push(`layer "${label}": ${was} file(s) \u2192 ${now} file(s)`);
|
|
6684
6954
|
}
|
|
6685
6955
|
return changes;
|
|
6686
6956
|
}
|
|
6687
|
-
function describePartChanges(before, after) {
|
|
6957
|
+
function describePartChanges(before, after, secretRules) {
|
|
6688
6958
|
const index = (parts) => {
|
|
6689
6959
|
const map = /* @__PURE__ */ new Map();
|
|
6690
6960
|
for (const part of parts) {
|
|
@@ -6694,7 +6964,7 @@ function describePartChanges(before, after) {
|
|
|
6694
6964
|
};
|
|
6695
6965
|
const left = index(before);
|
|
6696
6966
|
const right = index(after);
|
|
6697
|
-
const label = (filename) => findSecretInPath(filename)?.masked ?? filename;
|
|
6967
|
+
const label = (filename) => findSecretInPath(filename, secretRules)?.masked ?? filename;
|
|
6698
6968
|
const changes = [];
|
|
6699
6969
|
for (const [filename, part] of right) {
|
|
6700
6970
|
const previous = left.get(filename);
|
|
@@ -6722,7 +6992,15 @@ function describePartChanges(before, after) {
|
|
|
6722
6992
|
}
|
|
6723
6993
|
return changes;
|
|
6724
6994
|
}
|
|
6725
|
-
function
|
|
6995
|
+
function maskLayerNames(layers, secretRules) {
|
|
6996
|
+
return Object.fromEntries(
|
|
6997
|
+
Object.entries(layers ?? {}).map(([name, count]) => [
|
|
6998
|
+
findSecretInPath(name, secretRules)?.masked ?? name,
|
|
6999
|
+
count
|
|
7000
|
+
])
|
|
7001
|
+
);
|
|
7002
|
+
}
|
|
7003
|
+
function describePayloadDiff(before, after, sourceFilesIdentical, secretRules) {
|
|
6726
7004
|
const generatorBefore = before.generator?.version ?? "unknown";
|
|
6727
7005
|
const generatorAfter = after.generator?.version ?? "unknown";
|
|
6728
7006
|
const digestBefore = typeof before.config?.digest === "string" ? before.config.digest : null;
|
|
@@ -6735,35 +7013,43 @@ function describePayloadDiff(before, after, sourceFilesIdentical) {
|
|
|
6735
7013
|
const configurationDiffers = generatorDiffers || digestDiffers || schemaDiffers;
|
|
6736
7014
|
const fingerprintDiffers = before.fingerprint !== after.fingerprint;
|
|
6737
7015
|
const partsDiffer = before.counts.partsCount !== after.counts.partsCount;
|
|
6738
|
-
const partChanges = describePartChanges(before.parts ?? [], after.parts ?? []);
|
|
6739
|
-
const layerChanges = describeLayerChanges(before.layers ?? {}, after.layers ?? {});
|
|
7016
|
+
const partChanges = describePartChanges(before.parts ?? [], after.parts ?? [], secretRules);
|
|
7017
|
+
const layerChanges = describeLayerChanges(before.layers ?? {}, after.layers ?? {}, secretRules);
|
|
6740
7018
|
const reasons = [];
|
|
7019
|
+
const codes = [];
|
|
6741
7020
|
if (schemaDiffers) {
|
|
7021
|
+
codes.push("schema-version");
|
|
6742
7022
|
reasons.push(
|
|
6743
7023
|
`schema version ${schemaBefore} \u2192 ${schemaAfter} (the two manifests describe different formats)`
|
|
6744
7024
|
);
|
|
6745
7025
|
}
|
|
6746
7026
|
if (digestDiffers) {
|
|
7027
|
+
codes.push("config-digest");
|
|
6747
7028
|
reasons.push(
|
|
6748
7029
|
`configuration digest ${shortDigest(digestBefore)} \u2192 ${shortDigest(digestAfter)} (budgets, preview thresholds, redaction rules and artifact selection all count)`
|
|
6749
7030
|
);
|
|
6750
7031
|
} else if (digestBefore === null || digestAfter === null) {
|
|
6751
7032
|
const missing = digestBefore === null && digestAfter !== null ? "before" : digestAfter === null && digestBefore !== null ? "after" : "both";
|
|
7033
|
+
codes.push("config-digest-missing");
|
|
6752
7034
|
reasons.push(
|
|
6753
7035
|
`configuration digest not recorded on the ${missing} side (manifest written before 4.0.5); compared the content fingerprint and part count instead`
|
|
6754
7036
|
);
|
|
6755
7037
|
}
|
|
6756
7038
|
if (generatorDiffers) {
|
|
7039
|
+
codes.push("generator");
|
|
6757
7040
|
reasons.push(`generator ${generatorBefore} \u2192 ${generatorAfter}`);
|
|
6758
7041
|
}
|
|
6759
7042
|
if (fingerprintDiffers && (sourceFilesIdentical || configurationDiffers)) {
|
|
7043
|
+
codes.push("fingerprint");
|
|
6760
7044
|
reasons.push(
|
|
6761
7045
|
`content fingerprint ${shortDigest(before.fingerprint)} \u2192 ${shortDigest(after.fingerprint)}` + (sourceFilesIdentical ? " (same source files, packed or configured differently)" : "")
|
|
6762
7046
|
);
|
|
6763
7047
|
}
|
|
6764
7048
|
if (partsDiffer) {
|
|
7049
|
+
codes.push("parts-count");
|
|
6765
7050
|
reasons.push(`${before.counts.partsCount} part(s) \u2192 ${after.counts.partsCount} part(s)`);
|
|
6766
7051
|
}
|
|
7052
|
+
for (let index = 0; index < layerChanges.length; index += 1) codes.push("layer-changed");
|
|
6767
7053
|
reasons.push(...layerChanges);
|
|
6768
7054
|
return {
|
|
6769
7055
|
sourceFilesIdentical,
|
|
@@ -6775,8 +7061,12 @@ function describePayloadDiff(before, after, sourceFilesIdentical) {
|
|
|
6775
7061
|
partsCount: { before: before.counts.partsCount, after: after.counts.partsCount },
|
|
6776
7062
|
schemaVersion: { before: schemaBefore, after: schemaAfter },
|
|
6777
7063
|
partsManifest: { differs: partChanges.length > 0, changes: partChanges },
|
|
6778
|
-
|
|
6779
|
-
|
|
7064
|
+
// The layer maps are printed and serialized, so a layer named after a project token leaks the
|
|
7065
|
+
// token here even though every reason line above is masked. Found while testing the rules
|
|
7066
|
+
// parameter: masking the prose and not the data it describes is the same bug one layer down.
|
|
7067
|
+
layers: { before: maskLayerNames(before.layers, secretRules), after: maskLayerNames(after.layers, secretRules) },
|
|
7068
|
+
reasons,
|
|
7069
|
+
codes
|
|
6780
7070
|
};
|
|
6781
7071
|
}
|
|
6782
7072
|
function hashMap(manifest) {
|
|
@@ -6815,10 +7105,10 @@ function comparableProblem(value) {
|
|
|
6815
7105
|
function assertUsableManifest(value, label) {
|
|
6816
7106
|
const problem = comparableProblem(value);
|
|
6817
7107
|
if (problem) {
|
|
6818
|
-
throw new Error(`The ${label} manifest is not a snapshot manifest
|
|
7108
|
+
throw new Error(`The ${label} manifest is not a snapshot manifest: ${problem}.`);
|
|
6819
7109
|
}
|
|
6820
7110
|
}
|
|
6821
|
-
function compareManifests(before, after) {
|
|
7111
|
+
function compareManifests(before, after, secretRules) {
|
|
6822
7112
|
assertUsableManifest(before, "before");
|
|
6823
7113
|
assertUsableManifest(after, "after");
|
|
6824
7114
|
const left = hashMap(before);
|
|
@@ -6838,8 +7128,8 @@ function compareManifests(before, after) {
|
|
|
6838
7128
|
}
|
|
6839
7129
|
const sort = (values) => values.sort((a, b) => a < b ? -1 : a > b ? 1 : 0);
|
|
6840
7130
|
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);
|
|
7131
|
+
const payload = describePayloadDiff(before, after, sourceFilesIdentical, secretRules);
|
|
7132
|
+
const mask = (values) => values.map((value) => findSecretInPath(value, secretRules)?.masked ?? value);
|
|
6843
7133
|
return {
|
|
6844
7134
|
before: side(before),
|
|
6845
7135
|
after: side(after),
|
|
@@ -6873,7 +7163,7 @@ function loadManifest(target) {
|
|
|
6873
7163
|
const problem = describeManifestShapeProblem(parsed);
|
|
6874
7164
|
if (problem) {
|
|
6875
7165
|
throw new Error(
|
|
6876
|
-
`${manifestPath} is not a
|
|
7166
|
+
`${manifestPath} is not a snapshot manifest: ${problem}. Point diff at a manifest.json written by \`generate\` (or at the directory that holds it).`
|
|
6877
7167
|
);
|
|
6878
7168
|
}
|
|
6879
7169
|
return parsed;
|
|
@@ -7150,23 +7440,23 @@ function describeMatcher(matcher) {
|
|
|
7150
7440
|
function normalizeTarget(cwd, target) {
|
|
7151
7441
|
const resolvedCwd = path9.resolve(cwd);
|
|
7152
7442
|
const absolute = path9.resolve(resolvedCwd, target);
|
|
7153
|
-
const
|
|
7154
|
-
if (
|
|
7443
|
+
const relative15 = path9.relative(resolvedCwd, absolute);
|
|
7444
|
+
if (relative15 === "" || relative15 === ".." || relative15.startsWith(`..${path9.sep}`) || path9.isAbsolute(relative15)) {
|
|
7155
7445
|
return { relative: target.replace(/\\/g, "/"), outsideRoot: true };
|
|
7156
7446
|
}
|
|
7157
|
-
return { relative:
|
|
7447
|
+
return { relative: relative15.split(path9.sep).join("/"), outsideRoot: false };
|
|
7158
7448
|
}
|
|
7159
7449
|
function findRuleMatch(rules, relativePath) {
|
|
7160
7450
|
return rules.find(
|
|
7161
7451
|
(rule) => matchRule(relativePath, rule.match)
|
|
7162
7452
|
);
|
|
7163
7453
|
}
|
|
7164
|
-
function findRecordedAncestor(skipped,
|
|
7454
|
+
function findRecordedAncestor(skipped, relative15, maskedPath2) {
|
|
7165
7455
|
let nearest;
|
|
7166
7456
|
for (const record of skipped) {
|
|
7167
7457
|
const ancestorPath = record.path;
|
|
7168
7458
|
if (ancestorPath.length === 0) continue;
|
|
7169
|
-
const isAncestor =
|
|
7459
|
+
const isAncestor = relative15.startsWith(`${ancestorPath}/`) || maskedPath2.startsWith(`${ancestorPath}/`);
|
|
7170
7460
|
if (!isAncestor) continue;
|
|
7171
7461
|
if (!nearest || ancestorPath.length > nearest.path.length) nearest = record;
|
|
7172
7462
|
}
|
|
@@ -7182,8 +7472,8 @@ function readManifest2(config) {
|
|
|
7182
7472
|
}
|
|
7183
7473
|
function explainPath(config, target) {
|
|
7184
7474
|
const normalized = normalizeTarget(config.cwd, target);
|
|
7185
|
-
const
|
|
7186
|
-
const maskedPath2 = findSecretInPath(
|
|
7475
|
+
const relative15 = normalized.relative;
|
|
7476
|
+
const maskedPath2 = findSecretInPath(relative15, config.secretRules)?.masked ?? relative15;
|
|
7187
7477
|
if (normalized.outsideRoot) {
|
|
7188
7478
|
return {
|
|
7189
7479
|
path: maskedPath2,
|
|
@@ -7193,7 +7483,7 @@ function explainPath(config, target) {
|
|
|
7193
7483
|
detail: "path resolves outside the configured repository root and was not inspected"
|
|
7194
7484
|
};
|
|
7195
7485
|
}
|
|
7196
|
-
const absolute = path9.join(config.cwd,
|
|
7486
|
+
const absolute = path9.join(config.cwd, relative15);
|
|
7197
7487
|
const result = {
|
|
7198
7488
|
path: maskedPath2,
|
|
7199
7489
|
exists: fs9.existsSync(absolute),
|
|
@@ -7211,11 +7501,11 @@ function explainPath(config, target) {
|
|
|
7211
7501
|
// that is only missing because the walker dropped the tool's own output directory.
|
|
7212
7502
|
toolOwnedPaths: [config.outDir, config.tmpDir].map(
|
|
7213
7503
|
(directory) => path9.relative(config.cwd, path9.resolve(config.cwd, directory)).replace(/\\/g, "/")
|
|
7214
|
-
).filter((
|
|
7504
|
+
).filter((relative16) => relative16.length > 0 && !relative16.startsWith(".."))
|
|
7215
7505
|
});
|
|
7216
|
-
if (!collection.files.includes(
|
|
7506
|
+
if (!collection.files.includes(relative15)) {
|
|
7217
7507
|
const record = collection.skipped.find(
|
|
7218
|
-
(entry2) => entry2.path ===
|
|
7508
|
+
(entry2) => entry2.path === relative15 || entry2.path === maskedPath2
|
|
7219
7509
|
);
|
|
7220
7510
|
if (record) {
|
|
7221
7511
|
result.reason = record.reason;
|
|
@@ -7224,7 +7514,7 @@ function explainPath(config, target) {
|
|
|
7224
7514
|
result.reason = "missing";
|
|
7225
7515
|
result.detail = "no such file or directory, relative to the configured cwd";
|
|
7226
7516
|
} else {
|
|
7227
|
-
const ancestor = findRecordedAncestor(collection.skipped,
|
|
7517
|
+
const ancestor = findRecordedAncestor(collection.skipped, relative15, maskedPath2);
|
|
7228
7518
|
if (ancestor) {
|
|
7229
7519
|
result.reason = ancestor.reason;
|
|
7230
7520
|
result.detail = ancestor.detail ? `${ancestor.detail} \u2014 inherited from the skipped directory \`${ancestor.path}\`` : `inside the skipped directory \`${ancestor.path}\``;
|
|
@@ -7244,11 +7534,11 @@ function explainPath(config, target) {
|
|
|
7244
7534
|
...config.changedSince === void 0 ? {} : { changedSince: config.changedSince },
|
|
7245
7535
|
...config.staged === true ? { staged: true } : {}
|
|
7246
7536
|
});
|
|
7247
|
-
inScope = scope.paths.has(
|
|
7537
|
+
inScope = scope.paths.has(relative15);
|
|
7248
7538
|
if (!inScope && config.withDependents === true) {
|
|
7249
7539
|
inScope = importsChangedFile(
|
|
7250
|
-
|
|
7251
|
-
importsOfFile(
|
|
7540
|
+
relative15,
|
|
7541
|
+
importsOfFile(relative15, absolute),
|
|
7252
7542
|
scope.paths,
|
|
7253
7543
|
buildImportResolver(collection.files.map((file) => ({ relativePath: file })))
|
|
7254
7544
|
);
|
|
@@ -7306,12 +7596,12 @@ function explainPath(config, target) {
|
|
|
7306
7596
|
result.bytes = buffer.length;
|
|
7307
7597
|
result.lines = countLines(text2);
|
|
7308
7598
|
if (decoded.encoding !== "utf-8") result.encoding = decoded.encoding;
|
|
7309
|
-
const { findings } = scanAndRedactSecrets(text2, config.secretRules,
|
|
7599
|
+
const { findings } = scanAndRedactSecrets(text2, config.secretRules, relative15);
|
|
7310
7600
|
result.secretCount = findings.length;
|
|
7311
7601
|
result.secrets = findings.slice(0, 20).map((finding) => ({ rules: finding.rules, line: finding.line }));
|
|
7312
7602
|
let inclusionMode = "full";
|
|
7313
|
-
if (config.skeleton === true && isSkeletonizable(
|
|
7314
|
-
const skeleton = skeletonizeTypeScript(text2,
|
|
7603
|
+
if (config.skeleton === true && isSkeletonizable(relative15)) {
|
|
7604
|
+
const skeleton = skeletonizeTypeScript(text2, relative15);
|
|
7315
7605
|
if (skeleton.collapsed > 0) inclusionMode = "signatures";
|
|
7316
7606
|
}
|
|
7317
7607
|
if (inclusionMode !== "signatures" && buffer.length > config.largeFileBytes) {
|
|
@@ -7320,15 +7610,15 @@ function explainPath(config, target) {
|
|
|
7320
7610
|
}
|
|
7321
7611
|
result.inclusionMode = inclusionMode;
|
|
7322
7612
|
}
|
|
7323
|
-
result.layer = classifyLayer(
|
|
7324
|
-
result.kind = classifyKind(
|
|
7325
|
-
result.language = detectLanguage(
|
|
7326
|
-
const layerRule = findRuleMatch(config.layers,
|
|
7613
|
+
result.layer = classifyLayer(relative15, config.layers);
|
|
7614
|
+
result.kind = classifyKind(relative15, config.kinds);
|
|
7615
|
+
result.language = detectLanguage(relative15);
|
|
7616
|
+
const layerRule = findRuleMatch(config.layers, relative15);
|
|
7327
7617
|
if (layerRule) result.layerMatch = describeMatcher(layerRule.match);
|
|
7328
|
-
const kindRule = findRuleMatch(config.kinds,
|
|
7618
|
+
const kindRule = findRuleMatch(config.kinds, relative15);
|
|
7329
7619
|
if (kindRule) result.kindMatch = describeMatcher(kindRule.match);
|
|
7330
7620
|
const manifest = readManifest2(config);
|
|
7331
|
-
const entry = Array.isArray(manifest?.files) ? manifest.files.find((file) => file.relativePath ===
|
|
7621
|
+
const entry = Array.isArray(manifest?.files) ? manifest.files.find((file) => file.relativePath === relative15) : void 0;
|
|
7332
7622
|
result.part = entry?.part ?? null;
|
|
7333
7623
|
return result;
|
|
7334
7624
|
}
|
|
@@ -7371,178 +7661,6 @@ function renderExplainText(result) {
|
|
|
7371
7661
|
import * as fs11 from "fs";
|
|
7372
7662
|
import * as path11 from "path";
|
|
7373
7663
|
|
|
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
|
-
};
|
|
7544
|
-
}
|
|
7545
|
-
|
|
7546
7664
|
// src/gitignore.ts
|
|
7547
7665
|
import * as fs10 from "fs";
|
|
7548
7666
|
import * as path10 from "path";
|
|
@@ -7643,7 +7761,7 @@ var DEFAULT_ANSWERS = {
|
|
|
7643
7761
|
branch: "main",
|
|
7644
7762
|
maxPartBytes: "300k",
|
|
7645
7763
|
maxPartTokens: null,
|
|
7646
|
-
largeFileBytes: "
|
|
7764
|
+
largeFileBytes: "300k",
|
|
7647
7765
|
maxMonolithBytes: null,
|
|
7648
7766
|
discovery: "auto",
|
|
7649
7767
|
skeleton: false,
|
|
@@ -7760,6 +7878,10 @@ function renderConfig(answers) {
|
|
|
7760
7878
|
// Set true to drop the built-in rules above and keep only customPatterns.
|
|
7761
7879
|
disableDefaultPatterns: false,
|
|
7762
7880
|
},
|
|
7881
|
+
// The library spelling of the same list, accepted here too so a config file can
|
|
7882
|
+
// express what a caller passes in code: an array of { rule, pattern } or a bare
|
|
7883
|
+
// RegExp. Use \`secrets.customPatterns\` above unless you are porting code.
|
|
7884
|
+
// secretRules: [],
|
|
7763
7885
|
|
|
7764
7886
|
// \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
7887
|
artifacts: {
|
|
@@ -7950,7 +8072,7 @@ function keyReader(input) {
|
|
|
7950
8072
|
next() {
|
|
7951
8073
|
const queued = queue.shift();
|
|
7952
8074
|
if (queued) return Promise.resolve(queued);
|
|
7953
|
-
return new Promise((
|
|
8075
|
+
return new Promise((resolve12) => waiters.push(resolve12));
|
|
7954
8076
|
},
|
|
7955
8077
|
close() {
|
|
7956
8078
|
input.off("keypress", onKey);
|
|
@@ -8168,7 +8290,7 @@ var CONFIG_CANDIDATES = [
|
|
|
8168
8290
|
".snapshotrc"
|
|
8169
8291
|
];
|
|
8170
8292
|
function parsePackageJson(raw) {
|
|
8171
|
-
const parsed = JSON.parse(
|
|
8293
|
+
const parsed = JSON.parse(stripJsonComments(raw));
|
|
8172
8294
|
if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) {
|
|
8173
8295
|
throw new Error("package.json is not a JSON object");
|
|
8174
8296
|
}
|
|
@@ -8379,7 +8501,18 @@ function updatePackageJson(cwd, notes) {
|
|
|
8379
8501
|
writeFileOrExplain(packagePath, serializePackageJson(raw, parsed));
|
|
8380
8502
|
return { scripts: added, dependency };
|
|
8381
8503
|
}
|
|
8382
|
-
|
|
8504
|
+
function gitignoreEntriesFor(cwd, outDir, tmpDir) {
|
|
8505
|
+
const entries = [];
|
|
8506
|
+
for (const directory of [outDir, tmpDir]) {
|
|
8507
|
+
if (directory === null) continue;
|
|
8508
|
+
const relative15 = path11.relative(cwd, path11.resolve(cwd, directory)).replace(/\\/g, "/");
|
|
8509
|
+
if (relative15 === "" || relative15 === "." || relative15.startsWith("..") || path11.isAbsolute(relative15)) {
|
|
8510
|
+
continue;
|
|
8511
|
+
}
|
|
8512
|
+
entries.push(`/${relative15}/`);
|
|
8513
|
+
}
|
|
8514
|
+
return [...new Set(entries)];
|
|
8515
|
+
}
|
|
8383
8516
|
function resolvePresetChoice(detectedName, presetName) {
|
|
8384
8517
|
return {
|
|
8385
8518
|
value: presetName,
|
|
@@ -8409,13 +8542,11 @@ async function runInit(options) {
|
|
|
8409
8542
|
// what the run used is drift the next `validate` reports, and `setup` is the one command
|
|
8410
8543
|
// that is supposed to leave a project in a consistent state.
|
|
8411
8544
|
maxPartTokens: options.maxPartTokens ?? DEFAULT_ANSWERS.maxPartTokens,
|
|
8412
|
-
|
|
8413
|
-
// cannot fit, so it is cut while the manifest
|
|
8414
|
-
// 200 KB beside `--max-part-tokens 32k` made
|
|
8415
|
-
|
|
8416
|
-
|
|
8417
|
-
effectiveBudgetBytes
|
|
8418
|
-
),
|
|
8545
|
+
// Follows the budget unless the caller named one. A threshold above the part budget is a
|
|
8546
|
+
// config error (a file between the two cannot fit a part, so it is cut while the manifest
|
|
8547
|
+
// calls it a preview); a fixed 200 KB beside `--max-part-tokens 32k` made setup's own output
|
|
8548
|
+
// fail its own validate, and a fixed 200 KB under a 300 KB budget previewed files that fit.
|
|
8549
|
+
largeFileBytes: options.largeFileBytes ?? effectiveBudgetBytes,
|
|
8419
8550
|
maxMonolithBytes: options.maxMonolithBytes ?? DEFAULT_ANSWERS.maxMonolithBytes,
|
|
8420
8551
|
discovery: options.discovery ?? DEFAULT_ANSWERS.discovery,
|
|
8421
8552
|
skeleton: options.skeleton ?? DEFAULT_ANSWERS.skeleton,
|
|
@@ -8674,7 +8805,10 @@ async function runInit(options) {
|
|
|
8674
8805
|
}
|
|
8675
8806
|
if (!reused) writeFileOrExplain(configPath, configText);
|
|
8676
8807
|
const { scripts, dependency } = updatePackageJson(options.cwd, notes);
|
|
8677
|
-
const ignore = appendGitignoreEntries(
|
|
8808
|
+
const ignore = appendGitignoreEntries(
|
|
8809
|
+
options.cwd,
|
|
8810
|
+
gitignoreEntriesFor(options.cwd, answers.outDir, options.tmpDir ?? (reused ? null : "snapshot.tmp"))
|
|
8811
|
+
);
|
|
8678
8812
|
if (ignore.note !== null) notes.push(ignore.note);
|
|
8679
8813
|
return {
|
|
8680
8814
|
configPath,
|
|
@@ -8696,10 +8830,10 @@ async function runInit(options) {
|
|
|
8696
8830
|
import * as fs12 from "fs";
|
|
8697
8831
|
import * as path12 from "path";
|
|
8698
8832
|
function describeTarget(cwd) {
|
|
8699
|
-
const
|
|
8700
|
-
if (
|
|
8701
|
-
if (
|
|
8702
|
-
return
|
|
8833
|
+
const relative15 = path12.relative(process.cwd(), cwd);
|
|
8834
|
+
if (relative15 === "") return "this directory";
|
|
8835
|
+
if (relative15.startsWith("..") || path12.isAbsolute(relative15)) return cwd;
|
|
8836
|
+
return relative15;
|
|
8703
8837
|
}
|
|
8704
8838
|
function firstRunMessage(reason, cwd) {
|
|
8705
8839
|
const where = describeTarget(cwd);
|
|
@@ -8906,7 +9040,7 @@ function generateAuditReport(manifest, secretFindings, secretRules) {
|
|
|
8906
9040
|
);
|
|
8907
9041
|
for (const file of affected) {
|
|
8908
9042
|
const status = file.isPreviewTruncated ? "Truncated" : "Full";
|
|
8909
|
-
const cutBy = file.truncationReason === "part-budget" ? "maxPartBytes" : "largeFileBytes";
|
|
9043
|
+
const cutBy = file.truncationReason === "part-budget" ? "part budget (maxPartBytes)" : "large-file budget (largeFileBytes)";
|
|
8910
9044
|
lines.push(
|
|
8911
9045
|
`| ${code(file.relativePath)} | ${file.sizeBytes} | ${file.lines} | ${file.includedBytes} | ${file.includedLines} | ${status} | ${cutBy} |`
|
|
8912
9046
|
);
|
|
@@ -9022,11 +9156,11 @@ function generateSarifReport(manifest, findings, rules, toolVersion) {
|
|
|
9022
9156
|
codebaseSnapshotFinding: `${findingPath}#L${line}#${finding.rules.join("+")}`
|
|
9023
9157
|
}
|
|
9024
9158
|
};
|
|
9025
|
-
}).sort(
|
|
9026
|
-
|
|
9027
|
-
|
|
9028
|
-
) || a.locations[0].physicalLocation.region.startLine - b.locations[0].physicalLocation.region.startLine
|
|
9029
|
-
);
|
|
9159
|
+
}).sort((a, b) => {
|
|
9160
|
+
const left = a.locations[0].physicalLocation.artifactLocation.uri;
|
|
9161
|
+
const right = b.locations[0].physicalLocation.artifactLocation.uri;
|
|
9162
|
+
return (left < right ? -1 : left > right ? 1 : 0) || a.locations[0].physicalLocation.region.startLine - b.locations[0].physicalLocation.region.startLine;
|
|
9163
|
+
});
|
|
9030
9164
|
const log = {
|
|
9031
9165
|
$schema: SARIF_SCHEMA,
|
|
9032
9166
|
version: SARIF_VERSION,
|
|
@@ -9058,6 +9192,7 @@ function generateSarifReport(manifest, findings, rules, toolVersion) {
|
|
|
9058
9192
|
import * as crypto3 from "crypto";
|
|
9059
9193
|
var HEADER_RESERVE_BYTES = 2048 + Buffer.byteLength(UNTRUSTED_CONTENT_NOTICE, "utf8") + 8;
|
|
9060
9194
|
var MIN_SECTION_BUDGET_BYTES = 512;
|
|
9195
|
+
var MIN_PART_BUDGET_BYTES = MIN_SECTION_BUDGET_BYTES + HEADER_RESERVE_BYTES;
|
|
9061
9196
|
var MAX_SPLIT_PASSES = 64;
|
|
9062
9197
|
var BUDGET_MARKER_RESERVE = 96;
|
|
9063
9198
|
function insertTokenLine(markdown, tokens) {
|
|
@@ -9096,10 +9231,17 @@ function partitionFilesForBuckets(buckets, contentFingerprint) {
|
|
|
9096
9231
|
const groups = [];
|
|
9097
9232
|
for (const bucket of buckets) {
|
|
9098
9233
|
if (bucket.files.length === 0) continue;
|
|
9099
|
-
|
|
9100
|
-
|
|
9101
|
-
|
|
9102
|
-
|
|
9234
|
+
if (!Number.isFinite(bucket.budgetBytes)) {
|
|
9235
|
+
throw new Error(
|
|
9236
|
+
`A part budget must be a finite number of bytes; received ${String(bucket.budgetBytes)}.`
|
|
9237
|
+
);
|
|
9238
|
+
}
|
|
9239
|
+
if (bucket.budgetBytes < MIN_PART_BUDGET_BYTES) {
|
|
9240
|
+
throw new Error(
|
|
9241
|
+
`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.`
|
|
9242
|
+
);
|
|
9243
|
+
}
|
|
9244
|
+
const budget = bucket.budgetBytes;
|
|
9103
9245
|
const sectionBudget = budget - HEADER_RESERVE_BYTES;
|
|
9104
9246
|
const prepared = bucket.files.map((file) => prepareSection(file, sectionBudget, budget));
|
|
9105
9247
|
for (const sections of greedyGroups(prepared, budget)) groups.push({ sections, budget });
|
|
@@ -9728,6 +9870,22 @@ function generateProjectTree(filePaths) {
|
|
|
9728
9870
|
const fence = fenceForText(lines.join("\n"), 3);
|
|
9729
9871
|
return ["# Project Tree", "", `${fence}text`, ...lines, fence, ""].join("\n");
|
|
9730
9872
|
}
|
|
9873
|
+
function treeTruncationWarnings(treeText) {
|
|
9874
|
+
const warnings = [];
|
|
9875
|
+
const depth = /\[tree truncated at (\d+) levels\]/.exec(treeText);
|
|
9876
|
+
if (depth) {
|
|
9877
|
+
warnings.push(
|
|
9878
|
+
`reports/project-tree.md was truncated at the ${depth[1]}-level depth cap: deeper directories are not listed there.`
|
|
9879
|
+
);
|
|
9880
|
+
}
|
|
9881
|
+
const lines = /\[tree truncated at (\d+) lines\]/.exec(treeText);
|
|
9882
|
+
if (lines) {
|
|
9883
|
+
warnings.push(
|
|
9884
|
+
`reports/project-tree.md was truncated at the ${lines[1]}-line cap: the rest of the tree is not listed there.`
|
|
9885
|
+
);
|
|
9886
|
+
}
|
|
9887
|
+
return warnings;
|
|
9888
|
+
}
|
|
9731
9889
|
|
|
9732
9890
|
// src/update-check.ts
|
|
9733
9891
|
import * as fs13 from "fs";
|
|
@@ -9847,14 +10005,14 @@ function writeCache(file, entry) {
|
|
|
9847
10005
|
}
|
|
9848
10006
|
}
|
|
9849
10007
|
function fetchLatestVersion(url = PACKAGE_LATEST_URL, timeoutMs = REQUEST_TIMEOUT_MS) {
|
|
9850
|
-
return new Promise((
|
|
10008
|
+
return new Promise((resolve12) => {
|
|
9851
10009
|
let settled = false;
|
|
9852
10010
|
let request = null;
|
|
9853
10011
|
const finish = (value) => {
|
|
9854
10012
|
if (settled) return;
|
|
9855
10013
|
settled = true;
|
|
9856
10014
|
clearTimeout(deadline);
|
|
9857
|
-
|
|
10015
|
+
resolve12(value);
|
|
9858
10016
|
};
|
|
9859
10017
|
const deadline = setTimeout(() => {
|
|
9860
10018
|
request?.destroy();
|
|
@@ -10000,8 +10158,8 @@ function gitDirectory(cwd) {
|
|
|
10000
10158
|
}
|
|
10001
10159
|
}
|
|
10002
10160
|
function isInside2(parent, child) {
|
|
10003
|
-
const
|
|
10004
|
-
return
|
|
10161
|
+
const relative15 = path14.relative(parent, child);
|
|
10162
|
+
return relative15 === "" || !relative15.startsWith("..") && !path14.isAbsolute(relative15);
|
|
10005
10163
|
}
|
|
10006
10164
|
function isRegisteredWorktree(gitDir, cwd) {
|
|
10007
10165
|
try {
|
|
@@ -10120,7 +10278,20 @@ const { parentPort, workerData } = require("node:worker_threads");
|
|
|
10120
10278
|
// so the run is the documented MCP run rather than the CLI run with one setting removed.
|
|
10121
10279
|
const base = loaded.config ? { ...loaded.config, hooks: {} } : null;
|
|
10122
10280
|
const config = mod.resolveConfig(base, workerData.cliOptions, workerData.cwd);
|
|
10123
|
-
const manifest = mod.generateSnapshot(config);
|
|
10281
|
+
const manifest = mod.generateSnapshot(config, { dryRun: workerData.dryRun === true });
|
|
10282
|
+
const skipCounts = new Map();
|
|
10283
|
+
for (const record of manifest.skipped) {
|
|
10284
|
+
skipCounts.set(record.reason, (skipCounts.get(record.reason) || 0) + 1);
|
|
10285
|
+
}
|
|
10286
|
+
const skipReasons = Array.from(skipCounts.entries())
|
|
10287
|
+
.sort(function (a, b) {
|
|
10288
|
+
if (b[1] !== a[1]) return b[1] - a[1];
|
|
10289
|
+
return a[0] < b[0] ? -1 : a[0] > b[0] ? 1 : 0;
|
|
10290
|
+
})
|
|
10291
|
+
.slice(0, 8)
|
|
10292
|
+
.map(function (entry) {
|
|
10293
|
+
return { reason: entry[0], count: entry[1] };
|
|
10294
|
+
});
|
|
10124
10295
|
parentPort.postMessage({
|
|
10125
10296
|
ok: true,
|
|
10126
10297
|
summary: {
|
|
@@ -10129,7 +10300,11 @@ const { parentPort, workerData } = require("node:worker_threads");
|
|
|
10129
10300
|
skippedCount: manifest.counts.skippedCount,
|
|
10130
10301
|
partsCount: manifest.counts.partsCount,
|
|
10131
10302
|
parts: manifest.parts.map((part) => ({ filename: part.filename, byteSize: part.byteSize })),
|
|
10303
|
+
totalSizeBytes: manifest.counts.totalSizeBytes,
|
|
10132
10304
|
totalContentBytes: manifest.totals.totalContentBytes,
|
|
10305
|
+
preset: manifest.config.preset,
|
|
10306
|
+
layers: manifest.layers,
|
|
10307
|
+
skipReasons: skipReasons,
|
|
10133
10308
|
warnings: manifest.warnings,
|
|
10134
10309
|
},
|
|
10135
10310
|
});
|
|
@@ -10141,15 +10316,15 @@ const { parentPort, workerData } = require("node:worker_threads");
|
|
|
10141
10316
|
}
|
|
10142
10317
|
})();
|
|
10143
10318
|
`;
|
|
10144
|
-
function generateInWorker(cwd, cliOptions) {
|
|
10145
|
-
return new Promise((
|
|
10319
|
+
function generateInWorker(cwd, cliOptions, options = {}) {
|
|
10320
|
+
return new Promise((resolve12) => {
|
|
10146
10321
|
let settled = false;
|
|
10147
10322
|
let worker = null;
|
|
10148
10323
|
const finish = (result) => {
|
|
10149
10324
|
if (settled) return;
|
|
10150
10325
|
settled = true;
|
|
10151
10326
|
if (worker !== null) void worker.terminate();
|
|
10152
|
-
|
|
10327
|
+
resolve12(result);
|
|
10153
10328
|
};
|
|
10154
10329
|
const isCjs = typeof __dirname !== "undefined";
|
|
10155
10330
|
const directory = isCjs ? __dirname : path15.dirname(fileURLToPath(import.meta.url));
|
|
@@ -10159,7 +10334,8 @@ function generateInWorker(cwd, cliOptions) {
|
|
|
10159
10334
|
workerData: {
|
|
10160
10335
|
entryUrl: workerEntry(directory, isCjs).url,
|
|
10161
10336
|
cwd,
|
|
10162
|
-
cliOptions
|
|
10337
|
+
cliOptions,
|
|
10338
|
+
dryRun: options.dryRun === true
|
|
10163
10339
|
}
|
|
10164
10340
|
});
|
|
10165
10341
|
} catch (error) {
|
|
@@ -10345,16 +10521,29 @@ function retain(items, keep) {
|
|
|
10345
10521
|
items.length = write;
|
|
10346
10522
|
}
|
|
10347
10523
|
var SKIP_PREVIEW_SUMMARIES = true;
|
|
10348
|
-
function buildIndexes(files, tsconfigPaths) {
|
|
10524
|
+
function buildIndexes(files, tsconfigPaths, skippedSummaryImports = /* @__PURE__ */ new Map()) {
|
|
10349
10525
|
const resolver = buildImportResolver(files, { tsconfig: tsconfigPaths });
|
|
10350
10526
|
const importerCounts = /* @__PURE__ */ new Map();
|
|
10351
|
-
const byFile = files.
|
|
10352
|
-
|
|
10353
|
-
|
|
10354
|
-
|
|
10355
|
-
|
|
10356
|
-
|
|
10357
|
-
|
|
10527
|
+
const byFile = files.flatMap((file) => {
|
|
10528
|
+
if (isSourceSummary(file.summary)) {
|
|
10529
|
+
return [
|
|
10530
|
+
{
|
|
10531
|
+
path: file.relativePath,
|
|
10532
|
+
imports: file.summary.imports,
|
|
10533
|
+
exports: file.summary.exports
|
|
10534
|
+
}
|
|
10535
|
+
];
|
|
10536
|
+
}
|
|
10537
|
+
const imports = skippedSummaryImports.get(file.relativePath);
|
|
10538
|
+
if (imports === void 0) return [];
|
|
10539
|
+
return [
|
|
10540
|
+
{
|
|
10541
|
+
path: file.relativePath,
|
|
10542
|
+
imports,
|
|
10543
|
+
exports: [],
|
|
10544
|
+
exportsOmitted: true
|
|
10545
|
+
}
|
|
10546
|
+
];
|
|
10358
10547
|
});
|
|
10359
10548
|
for (const entry of byFile) {
|
|
10360
10549
|
for (const specifier of entry.imports) {
|
|
@@ -10474,6 +10663,9 @@ function resolveSafeOutputDirs(config) {
|
|
|
10474
10663
|
return { outDir, tmpDir };
|
|
10475
10664
|
}
|
|
10476
10665
|
var IGNORABLE_ENTRIES = /* @__PURE__ */ new Set([".DS_Store"]);
|
|
10666
|
+
function isIgnorableEntry(entry) {
|
|
10667
|
+
return IGNORABLE_ENTRIES.has(entry.slice(entry.lastIndexOf("/") + 1));
|
|
10668
|
+
}
|
|
10477
10669
|
var RUN_DIR_PREFIX = "run-";
|
|
10478
10670
|
var STALE_RUN_MS = 60 * 60 * 1e3;
|
|
10479
10671
|
function maskSummaryStrings(value, secretRules) {
|
|
@@ -10516,9 +10708,9 @@ function listEntries(dir) {
|
|
|
10516
10708
|
return;
|
|
10517
10709
|
}
|
|
10518
10710
|
for (const child of children) {
|
|
10519
|
-
const
|
|
10520
|
-
entries.push(
|
|
10521
|
-
if (child.isDirectory()) walk(path16.join(absolute, child.name),
|
|
10711
|
+
const relative15 = prefix === "" ? child.name : `${prefix}/${child.name}`;
|
|
10712
|
+
entries.push(relative15);
|
|
10713
|
+
if (child.isDirectory()) walk(path16.join(absolute, child.name), relative15);
|
|
10522
10714
|
}
|
|
10523
10715
|
};
|
|
10524
10716
|
walk(dir, "");
|
|
@@ -10529,7 +10721,7 @@ function markerInventory(dir, written) {
|
|
|
10529
10721
|
const files = [];
|
|
10530
10722
|
for (const entry of entries) {
|
|
10531
10723
|
if (entry === OWNERSHIP_MARKER) continue;
|
|
10532
|
-
if (
|
|
10724
|
+
if (isIgnorableEntry(entry)) continue;
|
|
10533
10725
|
const full = path16.join(dir, ...entry.split("/"));
|
|
10534
10726
|
let stats;
|
|
10535
10727
|
try {
|
|
@@ -10818,7 +11010,7 @@ function assessSnapshotDirectory(dir) {
|
|
|
10818
11010
|
}
|
|
10819
11011
|
const entries = listEntries(dir);
|
|
10820
11012
|
const foreignEntries = entries.filter(
|
|
10821
|
-
(entry) => !recorded.has(entry) && !
|
|
11013
|
+
(entry) => !recorded.has(entry) && !isIgnorableEntry(entry)
|
|
10822
11014
|
);
|
|
10823
11015
|
if (foreignEntries.length > 0) {
|
|
10824
11016
|
return { owned: false, problem: null, foreignEntries, marker: marker2 };
|
|
@@ -11314,7 +11506,7 @@ function generateSnapshot(configInput, options) {
|
|
|
11314
11506
|
// output — but only at these exact paths, not at every directory that shares the name.
|
|
11315
11507
|
toolOwnedPaths: [config.outDir, config.tmpDir].map(
|
|
11316
11508
|
(directory) => path16.relative(config.cwd, path16.resolve(config.cwd, directory)).replace(/\\/g, "/")
|
|
11317
|
-
).filter((
|
|
11509
|
+
).filter((relative15) => relative15.length > 0 && !relative15.startsWith("..")),
|
|
11318
11510
|
// A staged path can be absent from the working tree while its index blob exists. Discovery
|
|
11319
11511
|
// lists the working tree, so those paths would never reach the scan at all.
|
|
11320
11512
|
...stagedPaths.size > 0 ? { extraPaths: [...stagedPaths] } : {}
|
|
@@ -11734,7 +11926,7 @@ function generateSnapshot(configInput, options) {
|
|
|
11734
11926
|
},
|
|
11735
11927
|
layers: layerCounts,
|
|
11736
11928
|
kinds: kindCounts,
|
|
11737
|
-
indexes: buildIndexes(files, tsconfigPathsFor(config.cwd)),
|
|
11929
|
+
indexes: buildIndexes(files, tsconfigPathsFor(config.cwd), skippedSummaryImports),
|
|
11738
11930
|
parts: parts.map((part) => part.metadata),
|
|
11739
11931
|
files: files.map((file) => {
|
|
11740
11932
|
const { content: _content, ...rest } = file;
|
|
@@ -11776,11 +11968,9 @@ function generateSnapshot(configInput, options) {
|
|
|
11776
11968
|
let projectTree = null;
|
|
11777
11969
|
if (config.artifacts.projectTree) {
|
|
11778
11970
|
projectTree = generateProjectTree(files.map((file) => file.relativePath));
|
|
11779
|
-
const
|
|
11780
|
-
if (
|
|
11781
|
-
manifest.warnings.push(
|
|
11782
|
-
`reports/project-tree.md was truncated at the ${depthMarker[1]}-level depth cap: deeper directories are not listed there.`
|
|
11783
|
-
);
|
|
11971
|
+
const truncations = treeTruncationWarnings(projectTree);
|
|
11972
|
+
if (truncations.length > 0) {
|
|
11973
|
+
manifest.warnings.push(...truncations);
|
|
11784
11974
|
manifest.totals.warningCount = manifest.warnings.length;
|
|
11785
11975
|
}
|
|
11786
11976
|
}
|
|
@@ -11808,7 +11998,7 @@ function generateSnapshot(configInput, options) {
|
|
|
11808
11998
|
if (config.includeMonolith) {
|
|
11809
11999
|
const fullFiles = files.map((file) => {
|
|
11810
12000
|
const content = fullContents.get(file.relativePath) ?? "";
|
|
11811
|
-
|
|
12001
|
+
const entry = {
|
|
11812
12002
|
...file,
|
|
11813
12003
|
content,
|
|
11814
12004
|
inclusionMode: "full",
|
|
@@ -11816,6 +12006,9 @@ function generateSnapshot(configInput, options) {
|
|
|
11816
12006
|
includedBytes: Buffer.byteLength(content, "utf8"),
|
|
11817
12007
|
includedLines: countLines(content)
|
|
11818
12008
|
};
|
|
12009
|
+
delete entry.truncationReason;
|
|
12010
|
+
delete entry.omittedRanges;
|
|
12011
|
+
return entry;
|
|
11819
12012
|
});
|
|
11820
12013
|
const bodyBytes = fullFiles.reduce((total, file) => total + file.includedBytes, 0);
|
|
11821
12014
|
const definitelyTooLarge = config.maxMonolithBytes !== null && bodyBytes > config.maxMonolithBytes;
|
|
@@ -12251,8 +12444,8 @@ function partPathFor(workspace, filename) {
|
|
|
12251
12444
|
if (filename.length === 0 || filename.includes("\0")) return null;
|
|
12252
12445
|
const partsDir = path17.resolve(workspace.root, workspace.config.outDir, "parts");
|
|
12253
12446
|
const resolved = path17.resolve(partsDir, filename);
|
|
12254
|
-
const
|
|
12255
|
-
if (
|
|
12447
|
+
const relative15 = path17.relative(partsDir, resolved);
|
|
12448
|
+
if (relative15.length === 0 || relative15.includes(path17.sep) || relative15.includes("/") || relative15.includes("\\") || path17.isAbsolute(relative15)) {
|
|
12256
12449
|
return null;
|
|
12257
12450
|
}
|
|
12258
12451
|
let stats;
|
|
@@ -12421,11 +12614,11 @@ function toRelativePath(root, value) {
|
|
|
12421
12614
|
if (cleaned.length === 0 || cleaned.includes("\0")) return null;
|
|
12422
12615
|
const resolvedRoot = path18.resolve(root);
|
|
12423
12616
|
const absolute = path18.resolve(resolvedRoot, cleaned);
|
|
12424
|
-
const
|
|
12425
|
-
if (
|
|
12617
|
+
const relative15 = path18.relative(resolvedRoot, absolute);
|
|
12618
|
+
if (relative15 === "" || relative15 === ".." || relative15.startsWith(`..${path18.sep}`) || path18.isAbsolute(relative15)) {
|
|
12426
12619
|
return null;
|
|
12427
12620
|
}
|
|
12428
|
-
return
|
|
12621
|
+
return relative15.split(path18.sep).join("/");
|
|
12429
12622
|
}
|
|
12430
12623
|
function symbolsOf(entry) {
|
|
12431
12624
|
const summary = entry.summary;
|
|
@@ -12583,45 +12776,38 @@ var planTool = {
|
|
|
12583
12776
|
const prepared = await prepare(args, context, workspaceOverrides(args));
|
|
12584
12777
|
if (!prepared.ok) return prepared.outcome;
|
|
12585
12778
|
const workspace = prepared.workspace;
|
|
12586
|
-
|
|
12587
|
-
|
|
12588
|
-
|
|
12589
|
-
|
|
12590
|
-
return failure(error instanceof Error ? error.message : String(error));
|
|
12591
|
-
}
|
|
12592
|
-
const reasons = /* @__PURE__ */ new Map();
|
|
12593
|
-
for (const record of manifest.skipped) {
|
|
12594
|
-
reasons.set(record.reason, (reasons.get(record.reason) ?? 0) + 1);
|
|
12595
|
-
}
|
|
12596
|
-
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 }));
|
|
12779
|
+
const result = await generateInWorker(workspace.root, workspace.cliOptions, { dryRun: true });
|
|
12780
|
+
if (!result.ok) return failure(result.message);
|
|
12781
|
+
const summary = result.summary;
|
|
12782
|
+
const topReasons = summary.skipReasons;
|
|
12597
12783
|
const lines = [
|
|
12598
12784
|
"Dry run \u2014 nothing was written.",
|
|
12599
|
-
`Preset: ${
|
|
12600
|
-
`Would include ${plural(
|
|
12601
|
-
`Would skip ${plural(
|
|
12785
|
+
`Preset: ${summary.preset}`,
|
|
12786
|
+
`Would include ${plural(summary.totalFiles, "file")} in ${plural(summary.partsCount, "part")} (${formatBytes(summary.totalSizeBytes)} of source, ${formatBytes(summary.totalContentBytes)} emitted).`,
|
|
12787
|
+
`Would skip ${plural(summary.skippedCount, "file")}.`
|
|
12602
12788
|
];
|
|
12603
12789
|
if (topReasons.length > 0) {
|
|
12604
12790
|
lines.push("Top skip reasons:");
|
|
12605
12791
|
for (const entry of topReasons) lines.push(` - ${entry.reason} (${entry.count})`);
|
|
12606
12792
|
}
|
|
12607
|
-
if (
|
|
12608
|
-
lines.push(`Warnings (${
|
|
12609
|
-
for (const warning of
|
|
12793
|
+
if (summary.warnings.length > 0) {
|
|
12794
|
+
lines.push(`Warnings (${summary.warnings.length}):`);
|
|
12795
|
+
for (const warning of summary.warnings.slice(0, 5)) lines.push(` - ${warning}`);
|
|
12610
12796
|
}
|
|
12611
12797
|
return {
|
|
12612
12798
|
text: lines.join("\n"),
|
|
12613
12799
|
structured: {
|
|
12614
|
-
files:
|
|
12615
|
-
skipped:
|
|
12616
|
-
parts:
|
|
12617
|
-
sourceBytes:
|
|
12618
|
-
emittedBytes:
|
|
12619
|
-
preset:
|
|
12620
|
-
maxPartBytes:
|
|
12621
|
-
layers:
|
|
12800
|
+
files: summary.totalFiles,
|
|
12801
|
+
skipped: summary.skippedCount,
|
|
12802
|
+
parts: summary.partsCount,
|
|
12803
|
+
sourceBytes: summary.totalSizeBytes,
|
|
12804
|
+
emittedBytes: summary.totalContentBytes,
|
|
12805
|
+
preset: summary.preset,
|
|
12806
|
+
maxPartBytes: workspace.config.maxPartBytes,
|
|
12807
|
+
layers: summary.layers,
|
|
12622
12808
|
skipReasons: topReasons,
|
|
12623
|
-
warnings:
|
|
12624
|
-
warningCount:
|
|
12809
|
+
warnings: summary.warnings.slice(0, 5),
|
|
12810
|
+
warningCount: summary.warnings.length
|
|
12625
12811
|
}
|
|
12626
12812
|
};
|
|
12627
12813
|
}
|
|
@@ -13692,7 +13878,7 @@ function buildAgentContract() {
|
|
|
13692
13878
|
id: "consume",
|
|
13693
13879
|
run: "read ./snapshot/parts/*.md, then ./snapshot/manifest.json, then ./snapshot/reports/audit.md",
|
|
13694
13880
|
expect: "the code, the index of what was included, and the risk findings",
|
|
13695
|
-
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."
|
|
13881
|
+
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."
|
|
13696
13882
|
}
|
|
13697
13883
|
],
|
|
13698
13884
|
commands: [
|
|
@@ -14049,6 +14235,7 @@ function buildAgentContract() {
|
|
|
14049
14235
|
{ key: "layers", type: "array", default: "preset layers", summary: "Custom layer rules (glob or RegExp)." },
|
|
14050
14236
|
{ key: "kinds", type: "array", default: "preset kinds", summary: "Custom kind rules." },
|
|
14051
14237
|
{ key: "secrets", type: "object", default: "{}", summary: "Custom secret patterns, or disable the defaults." },
|
|
14238
|
+
{ 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." },
|
|
14052
14239
|
{ key: "hooks", type: "object", default: "{}", summary: "afterGenerate(manifest) runs after a successful generate." }
|
|
14053
14240
|
]
|
|
14054
14241
|
},
|
|
@@ -14065,6 +14252,8 @@ function buildAgentContract() {
|
|
|
14065
14252
|
notes: [
|
|
14066
14253
|
"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.",
|
|
14067
14254
|
"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.",
|
|
14255
|
+
"indexes.imports.byFile includes previewed files (their import specifiers are still extracted); such an entry carries `exportsOmitted: true` instead of pretending it exports nothing.",
|
|
14256
|
+
"validate re-checks manifest.incomplete[] against files[] and refuses a manifest whose two statements of what is missing disagree.",
|
|
14068
14257
|
"manifest.skipped[] carries the path and the exact reason it was excluded.",
|
|
14069
14258
|
`The output directory is replaced atomically; ${MIN_MAX_PART_BYTES} bytes is the smallest legal budget.`
|
|
14070
14259
|
]
|
|
@@ -15068,11 +15257,11 @@ var MAX_LINE_BYTES = 32 * 1024 * 1024;
|
|
|
15068
15257
|
function createWriter(output) {
|
|
15069
15258
|
return {
|
|
15070
15259
|
write(value) {
|
|
15071
|
-
return new Promise((
|
|
15260
|
+
return new Promise((resolve12, reject) => {
|
|
15072
15261
|
output.write(`${JSON.stringify(value)}
|
|
15073
15262
|
`, (error) => {
|
|
15074
15263
|
if (error) reject(error);
|
|
15075
|
-
else
|
|
15264
|
+
else resolve12();
|
|
15076
15265
|
});
|
|
15077
15266
|
});
|
|
15078
15267
|
}
|
|
@@ -15209,8 +15398,8 @@ async function runStdioServer(options) {
|
|
|
15209
15398
|
let inFlight = 0;
|
|
15210
15399
|
let inputEnded = false;
|
|
15211
15400
|
let resolveDone = () => void 0;
|
|
15212
|
-
const finished = new Promise((
|
|
15213
|
-
resolveDone =
|
|
15401
|
+
const finished = new Promise((resolve12) => {
|
|
15402
|
+
resolveDone = resolve12;
|
|
15214
15403
|
});
|
|
15215
15404
|
const finishIfIdle = () => {
|
|
15216
15405
|
if (inputEnded && inFlight === 0) resolveDone(0);
|
|
@@ -15374,7 +15563,7 @@ Options:
|
|
|
15374
15563
|
--max-part-bytes <n> Maximum byte budget per markdown part (default: 307200).
|
|
15375
15564
|
Accepts units: 120k, 1.5mb
|
|
15376
15565
|
--max-part-tokens <n> Per-part budget in tokens; narrows --max-part-bytes
|
|
15377
|
-
--large-file-bytes <n>
|
|
15566
|
+
--large-file-bytes <n> Preview threshold (default: the part budget; never above it)
|
|
15378
15567
|
--changed-since <ref> Only files changed since this git ref, plus untracked ones
|
|
15379
15568
|
--staged Only files staged for the next commit
|
|
15380
15569
|
--with-dependents With the two above: also include their importers
|
|
@@ -15734,8 +15923,8 @@ function splitList(value) {
|
|
|
15734
15923
|
}
|
|
15735
15924
|
function displayOutPath(cwd, outDir, ...segments) {
|
|
15736
15925
|
const absolute = path21.resolve(cwd, outDir, ...segments);
|
|
15737
|
-
const
|
|
15738
|
-
if (
|
|
15926
|
+
const relative15 = path21.relative(cwd, absolute);
|
|
15927
|
+
if (relative15 && !relative15.startsWith("..") && !path21.isAbsolute(relative15)) return relative15;
|
|
15739
15928
|
return absolute;
|
|
15740
15929
|
}
|
|
15741
15930
|
function nextStepHint(cwd, scriptsAddedNow) {
|
|
@@ -15743,7 +15932,7 @@ function nextStepHint(cwd, scriptsAddedNow) {
|
|
|
15743
15932
|
if (!hasScript) {
|
|
15744
15933
|
try {
|
|
15745
15934
|
const parsed = JSON.parse(
|
|
15746
|
-
|
|
15935
|
+
stripJsonComments(fs20.readFileSync(path21.join(cwd, "package.json"), "utf8"))
|
|
15747
15936
|
);
|
|
15748
15937
|
hasScript = typeof parsed.scripts?.snapshot === "string";
|
|
15749
15938
|
} catch {
|
|
@@ -15810,7 +15999,9 @@ async function runInitCommand(invocation) {
|
|
|
15810
15999
|
}
|
|
15811
16000
|
function generatorOrigin(cwd) {
|
|
15812
16001
|
try {
|
|
15813
|
-
const pkg = JSON.parse(
|
|
16002
|
+
const pkg = JSON.parse(
|
|
16003
|
+
stripJsonComments(fs20.readFileSync(path21.join(cwd, "package.json"), "utf8"))
|
|
16004
|
+
);
|
|
15814
16005
|
const spec = pkg.dependencies?.["codebase-snapshot"] ?? pkg.devDependencies?.["codebase-snapshot"];
|
|
15815
16006
|
if (typeof spec === "string") return `project dependency ${spec}`;
|
|
15816
16007
|
} catch {
|
|
@@ -16107,6 +16298,8 @@ function runSkillCommand(invocation) {
|
|
|
16107
16298
|
function renderValidateText(result) {
|
|
16108
16299
|
if (result.valid) {
|
|
16109
16300
|
info("\u2705 Snapshot is valid and up to date with disk.");
|
|
16301
|
+
} else if (result.errors.length === 1 && result.errors[0].includes(" is not a snapshot manifest: ")) {
|
|
16302
|
+
warn(`\u274C ${result.errors[0]}`);
|
|
16110
16303
|
} else {
|
|
16111
16304
|
warn("\u274C Snapshot validation failed:");
|
|
16112
16305
|
for (const error of result.errors) warn(` - ${error}`);
|
|
@@ -16312,7 +16505,11 @@ ${USAGE}
|
|
|
16312
16505
|
if (invocation.command === "diff") {
|
|
16313
16506
|
try {
|
|
16314
16507
|
const [beforePath, afterPath] = invocation.args;
|
|
16315
|
-
const diff = compareManifests(
|
|
16508
|
+
const diff = compareManifests(
|
|
16509
|
+
loadManifest(beforePath),
|
|
16510
|
+
loadManifest(afterPath),
|
|
16511
|
+
resolved.secretRules
|
|
16512
|
+
);
|
|
16316
16513
|
emit(invocation.format, diff, () => info(renderDiffText(diff)));
|
|
16317
16514
|
return 0;
|
|
16318
16515
|
} catch (err) {
|
|
@@ -16367,7 +16564,7 @@ ${USAGE}
|
|
|
16367
16564
|
const reasons = skipBreakdown.length > shownReasons.length ? `${shownReasons.join(", ")}, +${skipBreakdown.length - shownReasons.length} more` : shownReasons.join(", ");
|
|
16368
16565
|
const candidates = manifest.counts.totalFiles + manifest.counts.skippedCount;
|
|
16369
16566
|
info(
|
|
16370
|
-
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")}`
|
|
16567
|
+
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")}`
|
|
16371
16568
|
);
|
|
16372
16569
|
info(` - Total lines: ${formatNumber(manifest.counts.totalLines)}`);
|
|
16373
16570
|
info(
|
|
@@ -16467,8 +16664,8 @@ function comparablePath(value) {
|
|
|
16467
16664
|
return process.platform === "win32" ? absolute.toLowerCase() : absolute;
|
|
16468
16665
|
}
|
|
16469
16666
|
function isSameOrInside(parent, candidate) {
|
|
16470
|
-
const
|
|
16471
|
-
return
|
|
16667
|
+
const relative15 = path21.relative(parent, candidate);
|
|
16668
|
+
return relative15 === "" || relative15 !== ".." && !relative15.startsWith(`..${path21.sep}`) && !path21.isAbsolute(relative15);
|
|
16472
16669
|
}
|
|
16473
16670
|
function isGeneratedWatchPath(candidate, paths) {
|
|
16474
16671
|
const absolute = comparablePath(path21.resolve(paths.cwd, candidate));
|
|
@@ -16614,12 +16811,12 @@ async function runWatchLoop(invocation, resolved, options) {
|
|
|
16614
16811
|
info(`\u26A0 Watch error: ${err.message}`);
|
|
16615
16812
|
info(" The watcher may have missed changes. Restart with Ctrl+C if they stop arriving.");
|
|
16616
16813
|
});
|
|
16617
|
-
await new Promise((
|
|
16814
|
+
await new Promise((resolve12) => {
|
|
16618
16815
|
const stop = () => {
|
|
16619
16816
|
stopped = true;
|
|
16620
16817
|
if (timer) clearTimeout(timer);
|
|
16621
16818
|
watcher.close();
|
|
16622
|
-
|
|
16819
|
+
resolve12();
|
|
16623
16820
|
};
|
|
16624
16821
|
process.once("SIGINT", stop);
|
|
16625
16822
|
process.once("SIGTERM", stop);
|